| 170 | const decodeCreateOrgApiKeyResponse = Schema.decodeUnknownOption(CreateOrgApiKeyResponse); |
| 171 | |
| 172 | const ownerFromApiKey = (apiKey: typeof ValidatedApiKey.Type): ApiKeyOwner | null => { |
| 173 | if (apiKey.owner.type === "organization") { |
| 174 | // An org-owned key IS the org: `owner.id` is the organization, and there |
| 175 | // is no member to act as. This resolves to the platform view. |
| 176 | return { |
| 177 | scope: "org", |
| 178 | accountId: null, |
| 179 | organizationId: apiKey.owner.id, |
| 180 | keyId: apiKey.id, |
| 181 | }; |
| 182 | } |
| 183 | const organizationId = apiKey.owner.organizationId ?? apiKey.owner.organization_id; |
| 184 | if (!organizationId) return null; |
| 185 | return { |
| 186 | scope: "user", |
| 187 | accountId: apiKey.owner.id, |
| 188 | organizationId, |
| 189 | keyId: apiKey.id, |
| 190 | }; |
| 191 | }; |
| 192 | |
| 193 | const ownerFromResponse = (value: unknown): ApiKeyOwner | null => |
| 194 | Option.match(decodeValidateApiKeyResponse(value), { |