MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / ownerFromApiKey

Function ownerFromApiKey

apps/cloud/src/auth/api-keys.ts:172–191  ·  view source on GitHub ↗
(apiKey: typeof ValidatedApiKey.Type)

Source from the content-addressed store, hash-verified

170const decodeCreateOrgApiKeyResponse = Schema.decodeUnknownOption(CreateOrgApiKeyResponse);
171
172const 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
193const ownerFromResponse = (value: unknown): ApiKeyOwner | null =>
194 Option.match(decodeValidateApiKeyResponse(value), {

Callers 1

ownerFromResponseFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected