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

Class ApiKeyService

apps/cloud/src/auth/api-keys.ts:280–385  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

278 });
279
280export class ApiKeyService extends Context.Service<
281 ApiKeyService,
282 {
283 readonly validate: (value: string) => Effect.Effect<ApiKeyOwner | null, ApiKeyValidationError>;
284 readonly listUserKeys: (input: {
285 readonly accountId: string;
286 readonly organizationId: string;
287 }) => Effect.Effect<readonly ApiKeySummary[], ApiKeyManagementError>;
288 readonly createUserKey: (input: {
289 readonly accountId: string;
290 readonly organizationId: string;
291 readonly name: string;
292 }) => Effect.Effect<CreatedApiKey, ApiKeyManagementError>;
293 readonly revokeUserKey: (input: {
294 readonly keyId: string;
295 }) => Effect.Effect<void, ApiKeyManagementError>;
296 /**
297 * The org-owned keys of an organization — the credentials that resolve to
298 * the read-only platform view. Privileged: callers gate on admin membership
299 * before reaching this.
300 */
301 readonly listOrgKeys: (input: {
302 readonly organizationId: string;
303 }) => Effect.Effect<readonly ApiKeySummary[], ApiKeyManagementError>;
304 readonly createOrgKey: (input: {
305 readonly organizationId: string;
306 readonly name: string;
307 }) => Effect.Effect<CreatedApiKey, ApiKeyManagementError>;
308 /**
309 * Revoke an org-owned key. Ownership is resolved against the ORG's own key
310 * listing — never the caller's personal keys — so a member's user key id
311 * (or another org's key id, since the WorkOS workspace key is
312 * workspace-wide) cannot be destroyed through this path.
313 */
314 readonly revokeOrgKey: (input: {
315 readonly organizationId: string;
316 readonly keyId: string;
317 }) => Effect.Effect<void, ApiKeyManagementError | OrgApiKeyNotFound>;
318 }
319>()("@executor-js/cloud/ApiKeyService") {
320 static WorkOS = Layer.effect(this)(
321 Effect.gen(function* () {
322 const workos = yield* WorkOSClient;
323 return {
324 validate: (value: string) =>
325 workos.validateApiKey(value).pipe(
326 Effect.map(ownerFromResponse),
327 Effect.mapError((cause) => new ApiKeyValidationError({ cause })),
328 ),
329 listUserKeys: ({ accountId, organizationId }) =>
330 workos.listUserApiKeys(accountId, organizationId).pipe(
331 Effect.map(listFromResponse),
332 Effect.mapError((cause) => new ApiKeyManagementError({ cause })),
333 ),
334 createUserKey: ({ accountId, organizationId, name }) =>
335 workos.createUserApiKey({ userId: accountId, organizationId, name }).pipe(
336 Effect.mapError((cause) => new ApiKeyManagementError({ cause })),
337 Effect.flatMap((response) => {

Callers

nothing calls this directly

Calls 3

createdFromResponseFunction · 0.85
orgListFromResponseFunction · 0.85
orgCreatedFromResponseFunction · 0.85

Tested by

no test coverage detected