@willyim/idp 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -323,6 +323,55 @@ ingest token, say — identifies a site rather than a user, cannot be kept secre
323
323
  and must not pay a round trip per hit. Keep those in the app's own table and
324
324
  gate them on `Origin` plus rate limiting.
325
325
 
326
+ ## Linked identities
327
+
328
+ A user's ids on *other* systems — their Slack member id, their WhatsApp number,
329
+ a Telegram id — pinned to their IdP user. The point is that an app hearing from
330
+ someone on Slack asks the IdP "who is this, and what may they do here?" and gets
331
+ the same answer a browser session for that person would carry. The app keeps no
332
+ table of Slack ids: the one it would write is exactly the allowlist the IdP
333
+ exists to replace.
334
+
335
+ Linking is **superadmin-only** — a link asserts identity with nothing to prove
336
+ it, so no app and no member may do it:
337
+
338
+ ```sh
339
+ curl -X POST https://idp.willy.im/api/v1/users/<userId>/identities \
340
+ -H "authorization: Bearer wim_<admin key>" -H "content-type: application/json" \
341
+ -d '{"provider":"slack","externalId":"U0AAE7LAATD","label":"house workspace"}'
342
+ ```
343
+
344
+ Resolving is app-scoped and needs `identity:resolve` on the app's own key:
345
+
346
+ ```ts
347
+ import { createIdentities, grants } from "@willyim/idp"
348
+
349
+ const identities = createIdentities({
350
+ baseUrl: "https://idp.willy.im",
351
+ token: env.IDP_MANAGEMENT_KEY, // the app's wim_… key, with identity:resolve
352
+ app: "bender",
353
+ })
354
+
355
+ // On every inbound Slack message:
356
+ const who = await identities.resolve("slack", event.user)
357
+ if (!who.found) return // store it, do not answer
358
+ if (!grants(who.permissions, "chat:respond")) return // they exist, this app never granted them
359
+ who.userId // the IdP user — the same id a session or a wak_ key would carry
360
+ ```
361
+
362
+ `permissions` are the user's product permissions for **the asking app**,
363
+ computed by the same code the claims hook runs at token mint: an admin member
364
+ gets the whole catalog, a plain member gets their grants, a linked user with no
365
+ membership resolves as `found: true` with none. `found: false` is a miss, not an
366
+ error, and is the common case in any shared channel.
367
+
368
+ Verdicts are cached by `(provider, externalId)` — 60s for a hit and for a miss,
369
+ both tunable via `cache` — and concurrent lookups of the same pair share one
370
+ round trip. A failed round trip is never cached. The miss TTL bounds how fast a
371
+ *new* link takes effect; call `forget(provider, externalId)` after one you made
372
+ yourself. The provider is case-insensitive; the id is exact, as the other
373
+ system spells it.
374
+
326
375
  ## Management API types
327
376
 
328
377
  Endpoints without sugar of their own go through `createManagementApi`, whose
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Linked identities, from the consuming app's side: "someone just messaged me
3
+ * on Slack as U0AAE7LAATD — who is that, and what may they do here?"
4
+ *
5
+ * The IdP is the only place the answer lives. A user's ids on other systems
6
+ * are pinned to their IdP user by a superadmin (the management API's
7
+ * `/users/{userId}/identities`), and an app resolves them with its own scoped
8
+ * `wim_…` key. The app never keeps a table of Slack ids — the one it would
9
+ * write is exactly the allowlist the IdP exists to replace.
10
+ *
11
+ * `permissions` in the answer are the user's product permissions for THIS app,
12
+ * computed the same way the claims hook computes them at token mint, so a
13
+ * Slack message and a browser session from the same person carry the same
14
+ * grants. Enforcement stays the app's job, same as everywhere else; `grants()`
15
+ * from `./claims.js` is the matcher to use.
16
+ *
17
+ * Resolution is a network round trip on a hot path — every inbound chat
18
+ * message — so verdicts are cached by (provider, externalId) with a short TTL,
19
+ * and concurrent lookups of the same pair share one request. A miss is cached
20
+ * too (most messages in any shared channel are from people who are not
21
+ * linked), which bounds how quickly a NEW link takes effect: `cache.missTtlMs`.
22
+ * A failed round trip is never cached, so an IdP blip does not lock anyone out
23
+ * for the whole TTL. `forget()` after a link you performed yourself.
24
+ */
25
+ import type { z } from "zod";
26
+ import { type ManagementApiOptions } from "./api.js";
27
+ import type { IdentityResolutionSchema } from "./schemas/index.js";
28
+ /** The IdP's answer. `found: false` is data, not an error. */
29
+ export type IdentityResolution = z.output<typeof IdentityResolutionSchema>;
30
+ /** The `found: true` half. */
31
+ export type ResolvedIdentity = Extract<IdentityResolution, {
32
+ found: true;
33
+ }>;
34
+ export type IdentityCacheOptions = {
35
+ /** How long a `found: true` verdict is reused. Default 60s. */
36
+ ttlMs?: number;
37
+ /** How long a `found: false` verdict is reused. Default 60s — see the header. */
38
+ missTtlMs?: number;
39
+ /** Entry ceiling before the oldest are dropped. Default 1000. */
40
+ max?: number;
41
+ };
42
+ export type IdentitiesOptions = ManagementApiOptions & {
43
+ /** The app the permissions in each answer are scoped to. */
44
+ app: string;
45
+ /** `false` disables caching entirely (every resolve is a round trip). */
46
+ cache?: IdentityCacheOptions | false;
47
+ /** Clock seam, for tests. */
48
+ now?: () => number;
49
+ };
50
+ export declare function createIdentities(options: IdentitiesOptions): {
51
+ resolve: (provider: string, externalId: string, init?: {
52
+ signal?: AbortSignal;
53
+ fresh?: boolean;
54
+ }) => Promise<IdentityResolution>;
55
+ /** Drops one pair's cached verdict, or the whole cache when called bare. */
56
+ forget(provider?: string, externalId?: string): void;
57
+ };
58
+ export type Identities = ReturnType<typeof createIdentities>;
59
+ //# sourceMappingURL=identities.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identities.d.ts","sourceRoot":"","sources":["../../src/identities.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAE5B,OAAO,EAAuB,KAAK,oBAAoB,EAAE,MAAM,UAAU,CAAA;AACzE,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAA;AAElE,8DAA8D;AAC9D,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,wBAAwB,CAAC,CAAA;AAE1E,8BAA8B;AAC9B,MAAM,MAAM,gBAAgB,GAAG,OAAO,CAAC,kBAAkB,EAAE;IAAE,KAAK,EAAE,IAAI,CAAA;CAAE,CAAC,CAAA;AAE3E,MAAM,MAAM,oBAAoB,GAAG;IACjC,+DAA+D;IAC/D,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,iFAAiF;IACjF,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,iEAAiE;IACjE,GAAG,CAAC,EAAE,MAAM,CAAA;CACb,CAAA;AAED,MAAM,MAAM,iBAAiB,GAAG,oBAAoB,GAAG;IACrD,4DAA4D;IAC5D,GAAG,EAAE,MAAM,CAAA;IACX,yEAAyE;IACzE,KAAK,CAAC,EAAE,oBAAoB,GAAG,KAAK,CAAA;IACpC,6BAA6B;IAC7B,GAAG,CAAC,EAAE,MAAM,MAAM,CAAA;CACnB,CAAA;AAQD,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,iBAAiB;wBAiC7C,MAAM,cACJ,MAAM,SACZ;QAAE,MAAM,CAAC,EAAE,WAAW,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,KAC9C,OAAO,CAAC,kBAAkB,CAAC;IAgC5B,4EAA4E;sBAC1D,MAAM,eAAe,MAAM,GAAG,IAAI;EAQvD;AAED,MAAM,MAAM,UAAU,GAAG,UAAU,CAAC,OAAO,gBAAgB,CAAC,CAAA"}
Binary file
@@ -18,6 +18,7 @@ export { memorySessions, type MemorySessionStore, type SessionRecord, type Sessi
18
18
  export { grants, normalizeClaims, PERMISSIONS_CLAIM, WORKSPACES_CLAIM, type Actor, type Claims, type Workspace, } from "./claims.js";
19
19
  export { createManagementApi, type ManagementApi, type ManagementApiOptions, } from "./api.js";
20
20
  export { createUserKeys, readApiKey, type AuthenticatedKey, type AuthenticateOptions, type AuthenticateResult, type CreateUserApiKeyInput, type ListFilter, type MintedUserApiKey, type UserApiKey, type UserKeyCacheOptions, type UserKeys, type UserKeysOptions, type UserKeyValidation, } from "./user-keys.js";
21
+ export { createIdentities, type Identities, type IdentitiesOptions, type IdentityCacheOptions, type ResolvedIdentity, type IdentityResolution, } from "./identities.js";
21
22
  export { parseDuration, type Duration } from "./duration.js";
22
23
  export { clearCookie, parseCookies, readCookie, serializeCookie, type CookieOptions, } from "./cookie.js";
23
24
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EACL,eAAe,EACf,UAAU,EACV,cAAc,EACd,QAAQ,EACR,gBAAgB,EAChB,KAAK,qBAAqB,EAC1B,KAAK,SAAS,EACd,KAAK,SAAS,EACd,KAAK,gBAAgB,EACrB,KAAK,QAAQ,EACb,KAAK,MAAM,GACZ,MAAM,aAAa,CAAA;AAEpB,OAAO,EACL,SAAS,EACT,sBAAsB,EACtB,QAAQ,EACR,KAAK,GAAG,EACR,KAAK,UAAU,EACf,KAAK,OAAO,EACZ,KAAK,cAAc,GACpB,MAAM,cAAc,CAAA;AAErB,OAAO,EACL,cAAc,EACd,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAClB,KAAK,YAAY,GAClB,MAAM,YAAY,CAAA;AAEnB,OAAO,EACL,MAAM,EACN,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,KAAK,KAAK,EACV,KAAK,MAAM,EACX,KAAK,SAAS,GACf,MAAM,aAAa,CAAA;AAEpB,OAAO,EACL,mBAAmB,EACnB,KAAK,aAAa,EAClB,KAAK,oBAAoB,GAC1B,MAAM,UAAU,CAAA;AAEjB,OAAO,EACL,cAAc,EACd,UAAU,EACV,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,KAAK,qBAAqB,EAC1B,KAAK,UAAU,EACf,KAAK,gBAAgB,EACrB,KAAK,UAAU,EACf,KAAK,mBAAmB,EACxB,KAAK,QAAQ,EACb,KAAK,eAAe,EACpB,KAAK,iBAAiB,GACvB,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,aAAa,EAAE,KAAK,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC5D,OAAO,EACL,WAAW,EACX,YAAY,EACZ,UAAU,EACV,eAAe,EACf,KAAK,aAAa,GACnB,MAAM,aAAa,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EACL,eAAe,EACf,UAAU,EACV,cAAc,EACd,QAAQ,EACR,gBAAgB,EAChB,KAAK,qBAAqB,EAC1B,KAAK,SAAS,EACd,KAAK,SAAS,EACd,KAAK,gBAAgB,EACrB,KAAK,QAAQ,EACb,KAAK,MAAM,GACZ,MAAM,aAAa,CAAA;AAEpB,OAAO,EACL,SAAS,EACT,sBAAsB,EACtB,QAAQ,EACR,KAAK,GAAG,EACR,KAAK,UAAU,EACf,KAAK,OAAO,EACZ,KAAK,cAAc,GACpB,MAAM,cAAc,CAAA;AAErB,OAAO,EACL,cAAc,EACd,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAClB,KAAK,YAAY,GAClB,MAAM,YAAY,CAAA;AAEnB,OAAO,EACL,MAAM,EACN,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,KAAK,KAAK,EACV,KAAK,MAAM,EACX,KAAK,SAAS,GACf,MAAM,aAAa,CAAA;AAEpB,OAAO,EACL,mBAAmB,EACnB,KAAK,aAAa,EAClB,KAAK,oBAAoB,GAC1B,MAAM,UAAU,CAAA;AAEjB,OAAO,EACL,cAAc,EACd,UAAU,EACV,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,KAAK,qBAAqB,EAC1B,KAAK,UAAU,EACf,KAAK,gBAAgB,EACrB,KAAK,UAAU,EACf,KAAK,mBAAmB,EACxB,KAAK,QAAQ,EACb,KAAK,eAAe,EACpB,KAAK,iBAAiB,GACvB,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EACL,gBAAgB,EAChB,KAAK,UAAU,EACf,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,GACxB,MAAM,iBAAiB,CAAA;AAExB,OAAO,EAAE,aAAa,EAAE,KAAK,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC5D,OAAO,EACL,WAAW,EACX,YAAY,EACZ,UAAU,EACV,eAAe,EACf,KAAK,aAAa,GACnB,MAAM,aAAa,CAAA"}
package/dist/src/index.js CHANGED
@@ -18,5 +18,6 @@ export { memorySessions, } from "./store.js";
18
18
  export { grants, normalizeClaims, PERMISSIONS_CLAIM, WORKSPACES_CLAIM, } from "./claims.js";
19
19
  export { createManagementApi, } from "./api.js";
20
20
  export { createUserKeys, readApiKey, } from "./user-keys.js";
21
+ export { createIdentities, } from "./identities.js";
21
22
  export { parseDuration } from "./duration.js";
22
23
  export { clearCookie, parseCookies, readCookie, serializeCookie, } from "./cookie.js";
@@ -219,6 +219,42 @@ export declare const UserApiKeyValidationSchema: z.ZodUnion<readonly [z.ZodObjec
219
219
  not_found: "not_found";
220
220
  }>;
221
221
  }, z.core.$strip>]>;
222
+ export declare const LinkedIdentitySchema: z.ZodObject<{
223
+ id: z.ZodString;
224
+ userId: z.ZodString;
225
+ provider: z.ZodString;
226
+ externalId: z.ZodString;
227
+ label: z.ZodNullable<z.ZodString>;
228
+ createdAt: z.ZodString;
229
+ }, z.core.$strip>;
230
+ export declare const LinkedIdentityListSchema: z.ZodObject<{
231
+ identities: z.ZodArray<z.ZodObject<{
232
+ id: z.ZodString;
233
+ userId: z.ZodString;
234
+ provider: z.ZodString;
235
+ externalId: z.ZodString;
236
+ label: z.ZodNullable<z.ZodString>;
237
+ createdAt: z.ZodString;
238
+ }, z.core.$strip>>;
239
+ }, z.core.$strip>;
240
+ export declare const LinkIdentityInput: z.ZodObject<{
241
+ provider: z.ZodString;
242
+ externalId: z.ZodString;
243
+ label: z.ZodOptional<z.ZodString>;
244
+ }, z.core.$strip>;
245
+ export declare const LinkedIdentityCreatedSchema: z.ZodObject<{
246
+ id: z.ZodString;
247
+ created: z.ZodBoolean;
248
+ }, z.core.$strip>;
249
+ export declare const IdentityResolutionSchema: z.ZodUnion<readonly [z.ZodObject<{
250
+ found: z.ZodLiteral<true>;
251
+ userId: z.ZodString;
252
+ email: z.ZodString;
253
+ name: z.ZodNullable<z.ZodString>;
254
+ permissions: z.ZodArray<z.ZodString>;
255
+ }, z.core.$strip>, z.ZodObject<{
256
+ found: z.ZodLiteral<false>;
257
+ }, z.core.$strip>]>;
222
258
  export declare const AuditEntrySchema: z.ZodObject<{
223
259
  id: z.ZodNumber;
224
260
  tableName: z.ZodString;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/schemas/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,eAAO,MAAM,iBAAiB;;;;;;;;;iBAS5B,CAAA;AAEF,eAAO,MAAM,UAAU;;;;;;iBAMrB,CAAA;AAEF,eAAO,MAAM,eAAe;;;;;;iBAM1B,CAAA;AAEF,eAAO,MAAM,qBAAqB;;;;;;;;;;;iBAAyD,CAAA;AAE3F;;;GAGG;AACH,eAAO,MAAM,sBAAsB;;;;;iBAejC,CAAA;AACF,eAAO,MAAM,wBAAwB;;;;iBAInC,CAAA;AAEF,uEAAuE;AACvE,eAAO,MAAM,sBAAsB;;;;iBAIjC,CAAA;AAEF,eAAO,MAAM,kBAAkB;;iBAE7B,CAAA;AAEF,+DAA+D;AAC/D,eAAO,MAAM,sBAAsB;;iBAEjC,CAAA;AACF,eAAO,MAAM,oBAAoB;;iBAAiD,CAAA;AAClF,eAAO,MAAM,cAAc;;;;;;;;iBAA2C,CAAA;AACtE,eAAO,MAAM,mBAAmB;;;;;;;;iBAAqD,CAAA;AAIrF,eAAO,MAAM,UAAU;;;EAA8B,CAAA;AAErD,eAAO,MAAM,YAAY;;;;;;;;;iBAMvB,CAAA;AACF,eAAO,MAAM,gBAAgB;;;;;;;;;;;iBAA+C,CAAA;AAE5E,+DAA+D;AAC/D,eAAO,MAAM,iBAAiB;;;;;;;iBAI5B,CAA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0B;;;;;;;;;;;;;;mBAUrC,CAAA;AAIF,eAAO,MAAM,oBAAoB;;;;;;;iBAO/B,CAAA;AACF,eAAO,MAAM,wBAAwB;;;;;;;;;iBAA0D,CAAA;AAE/F,eAAO,MAAM,iBAAiB;;;;iBAI5B,CAAA;AACF,eAAO,MAAM,2BAA2B;;;iBAGtC,CAAA;AAEF,eAAO,MAAM,wBAAwB;;;;;;;;mBAWnC,CAAA;AAEF,eAAO,MAAM,gBAAgB;;;;;;;;iBAQ3B,CAAA;AACF,eAAO,MAAM,eAAe;;;;;;;;;;iBAAmD,CAAA;AAI/E,eAAO,MAAM,YAAY;;;;;;;;;;;;;;iBAUvB,CAAA;AACF,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;iBAA4C,CAAA;AAEzE,eAAO,MAAM,iBAAiB;;;;iBAM5B,CAAA;AACF,eAAO,MAAM,mBAAmB;;;;iBAI9B,CAAA;AAIF,eAAO,MAAM,cAAc;;;;;;;;;;;;;iBASzB,CAAA;AACF,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;iBAA8C,CAAA;AAE7E,eAAO,MAAM,mBAAmB;;;iBAG9B,CAAA;AACF,eAAO,MAAM,qBAAqB;;;;iBAIhC,CAAA"}
@@ -149,6 +149,37 @@ export const UserApiKeyValidationSchema = z.union([
149
149
  }),
150
150
  z.object({ valid: z.literal(false), reason: z.enum(["not_found", "revoked", "expired"]) }),
151
151
  ]);
152
+ // --- Linked identities (a user's ids on other systems) ---
153
+ export const LinkedIdentitySchema = z.object({
154
+ id: z.string(),
155
+ userId: z.string(),
156
+ provider: z.string().describe("The other system, lowercase — slack, whatsapp, telegram"),
157
+ externalId: z.string().describe("The id exactly as that system spells it"),
158
+ label: z.string().nullable(),
159
+ createdAt: z.string(),
160
+ });
161
+ export const LinkedIdentityListSchema = z.object({ identities: z.array(LinkedIdentitySchema) });
162
+ export const LinkIdentityInput = z.object({
163
+ provider: z.string().min(1).describe("slack, whatsapp, telegram… — normalised to lowercase"),
164
+ externalId: z.string().min(1).describe("The id as that system spells it, e.g. a Slack member id"),
165
+ label: z.string().optional().describe("A human label for the console"),
166
+ });
167
+ export const LinkedIdentityCreatedSchema = z.object({
168
+ id: z.string(),
169
+ created: z.boolean().describe("false when the same pair was already this user's"),
170
+ });
171
+ export const IdentityResolutionSchema = z.union([
172
+ z.object({
173
+ found: z.literal(true),
174
+ userId: z.string(),
175
+ email: z.string(),
176
+ name: z.string().nullable(),
177
+ permissions: z
178
+ .array(z.string())
179
+ .describe("The user's product permissions for the asking app; admins get the whole catalog"),
180
+ }),
181
+ z.object({ found: z.literal(false) }),
182
+ ]);
152
183
  export const AuditEntrySchema = z.object({
153
184
  id: z.number(),
154
185
  tableName: z.string(),
@@ -471,6 +471,73 @@ export declare const operations: {
471
471
  ok: z.ZodLiteral<true>;
472
472
  }, z.core.$strip>;
473
473
  };
474
+ readonly "get /api/v1/users/{userId}/identities": {
475
+ readonly summary: "List a user's linked identities (their ids on other systems)";
476
+ readonly description: "Requires an admin key. Identities are global to the user, not per app — a Slack id identifies a person regardless of who is asking.";
477
+ readonly params: {
478
+ readonly userId: "IdP user id.";
479
+ };
480
+ readonly successCode: "200";
481
+ readonly success: z.ZodObject<{
482
+ identities: z.ZodArray<z.ZodObject<{
483
+ id: z.ZodString;
484
+ userId: z.ZodString;
485
+ provider: z.ZodString;
486
+ externalId: z.ZodString;
487
+ label: z.ZodNullable<z.ZodString>;
488
+ createdAt: z.ZodString;
489
+ }, z.core.$strip>>;
490
+ }, z.core.$strip>;
491
+ };
492
+ readonly "post /api/v1/users/{userId}/identities": {
493
+ readonly summary: "Link an external id to a user";
494
+ readonly description: "Requires an admin key: a link asserts identity with nothing to prove it, so no app or member may do it. 201 on a new link, 200 when the same pair was already this user's, 409 `already_linked` when it belongs to someone else — an identity is never silently re-pointed.";
495
+ readonly params: {
496
+ readonly userId: "IdP user id.";
497
+ };
498
+ readonly input: z.ZodObject<{
499
+ provider: z.ZodString;
500
+ externalId: z.ZodString;
501
+ label: z.ZodOptional<z.ZodString>;
502
+ }, z.core.$strip>;
503
+ readonly successCode: "201";
504
+ readonly success: z.ZodObject<{
505
+ id: z.ZodString;
506
+ created: z.ZodBoolean;
507
+ }, z.core.$strip>;
508
+ };
509
+ readonly "delete /api/v1/users/{userId}/identities/{id}": {
510
+ readonly summary: "Unlink an external id (idempotent)";
511
+ readonly description: "Requires an admin key.";
512
+ readonly params: {
513
+ readonly userId: "IdP user id.";
514
+ readonly id: "Linked identity id.";
515
+ };
516
+ readonly successCode: "200";
517
+ readonly success: z.ZodObject<{
518
+ ok: z.ZodLiteral<true>;
519
+ }, z.core.$strip>;
520
+ };
521
+ readonly "get /api/v1/apps/{app}/identities/{provider}/{externalId}": {
522
+ readonly summary: "Resolve an external id to a user and their permissions in this app";
523
+ readonly description: "The hot path for an app that hears from someone on another system. Always 200 with a `found` discriminator — a miss is data, and the common case in any shared channel. `permissions` are the user's product permissions for THIS app, computed exactly as the claims hook computes them at token mint, so a Slack message and a browser session from the same person carry the same grants. A user with no membership resolves as found with no permissions.";
524
+ readonly permission: "identity:resolve";
525
+ readonly params: {
526
+ readonly provider: "The other system, e.g. slack.";
527
+ readonly externalId: "The id as that system spells it.";
528
+ readonly app: "Application key (oauth_client.metadata.app).";
529
+ };
530
+ readonly successCode: "200";
531
+ readonly success: z.ZodUnion<readonly [z.ZodObject<{
532
+ found: z.ZodLiteral<true>;
533
+ userId: z.ZodString;
534
+ email: z.ZodString;
535
+ name: z.ZodNullable<z.ZodString>;
536
+ permissions: z.ZodArray<z.ZodString>;
537
+ }, z.core.$strip>, z.ZodObject<{
538
+ found: z.ZodLiteral<false>;
539
+ }, z.core.$strip>]>;
540
+ };
474
541
  readonly "get /api/v1/apps/{app}/audit": {
475
542
  readonly summary: "List recent audit entries";
476
543
  readonly permission: "audit:read";
@@ -1 +1 @@
1
- {"version":3,"file":"operations.d.ts","sourceRoot":"","sources":["../../../src/schemas/operations.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQ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;;;;;;;;;;CA+O0B,CAAA;AAEjD,MAAM,MAAM,UAAU,GAAG,OAAO,UAAU,CAAA;AAC1C,MAAM,MAAM,YAAY,GAAG,MAAM,UAAU,CAAA;AAE3C,mEAAmE;AACnE,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,UAAU,IAAI,YAAY,SAAS,MAAM,CAAC,GACrE,CAAC,SAAS,GAAG,CAAC,IAAI,MAAM,CAAC,EAAE,GACzB,CAAC,GACD,KAAK,GACP,KAAK,CAAA;AAET,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,UAAU,EAAE,CAAC,SAAS,MAAM,IAAI,GAAG,CAAC,IAAI,CAAC,EAAE,SAAS,YAAY,GAC/F,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,GACvB,KAAK,CAAA;AAET,iFAAiF;AACjF,MAAM,MAAM,cAAc,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,SAAS,GAAG,MAAM,IAAI,MAAM,IAAI,IAAI,MAAM,IAAI,EAAE,GAC5F,IAAI,GAAG,cAAc,CAAC,IAAI,CAAC,GAC3B,KAAK,CAAA;AAET,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CAE7E"}
@@ -8,7 +8,7 @@
8
8
  * needs to learn about it.
9
9
  */
10
10
  import { z } from "zod";
11
- import { AdminKeyCreatedSchema, AdminKeyListSchema, ApiKeyCreatedSchema, ApiKeyListSchema, ApplicationCreatedSchema, ApplicationListSchema, ApplicationSchema, AppPermissionsSchema, AuditListSchema, ClientSecretSchema, CreateAdminKeyInput, CreateApiKeyInput, CreateApplicationInput, CreateUserApiKeyInput, CreateWorkspaceInput, InviteMemberInput, InviteMemberResult, MemberListSchema, OkSchema, SetAppPermissionsInput, UpdateApplicationInput, UpdateMemberInput, UserApiKeyCreatedSchema, UserApiKeyListSchema, UserApiKeyValidationSchema, UserListSchema, ValidateUserApiKeyInput, WorkspaceCreatedSchema, WorkspaceListSchema, } from "./index.js";
11
+ import { AdminKeyCreatedSchema, AdminKeyListSchema, ApiKeyCreatedSchema, ApiKeyListSchema, ApplicationCreatedSchema, ApplicationListSchema, ApplicationSchema, AppPermissionsSchema, AuditListSchema, ClientSecretSchema, CreateAdminKeyInput, CreateApiKeyInput, CreateApplicationInput, CreateUserApiKeyInput, CreateWorkspaceInput, InviteMemberInput, InviteMemberResult, MemberListSchema, OkSchema, SetAppPermissionsInput, UpdateApplicationInput, UpdateMemberInput, UserApiKeyCreatedSchema, UserApiKeyListSchema, UserApiKeyValidationSchema, LinkedIdentityListSchema, LinkIdentityInput, LinkedIdentityCreatedSchema, IdentityResolutionSchema, UserListSchema, ValidateUserApiKeyInput, WorkspaceCreatedSchema, WorkspaceListSchema, } from "./index.js";
12
12
  const APP_PARAM = { app: "Application key (oauth_client.metadata.app)." };
13
13
  const CLIENT_PARAM = { clientId: "OAuth client id of the application." };
14
14
  export const operations = {
@@ -200,6 +200,36 @@ export const operations = {
200
200
  successCode: "200",
201
201
  success: OkSchema,
202
202
  },
203
+ "get /api/v1/users/{userId}/identities": {
204
+ summary: "List a user's linked identities (their ids on other systems)",
205
+ description: "Requires an admin key. Identities are global to the user, not per app — a Slack id identifies a person regardless of who is asking.",
206
+ params: { userId: "IdP user id." },
207
+ successCode: "200",
208
+ success: LinkedIdentityListSchema,
209
+ },
210
+ "post /api/v1/users/{userId}/identities": {
211
+ summary: "Link an external id to a user",
212
+ description: "Requires an admin key: a link asserts identity with nothing to prove it, so no app or member may do it. 201 on a new link, 200 when the same pair was already this user's, 409 `already_linked` when it belongs to someone else — an identity is never silently re-pointed.",
213
+ params: { userId: "IdP user id." },
214
+ input: LinkIdentityInput,
215
+ successCode: "201",
216
+ success: LinkedIdentityCreatedSchema,
217
+ },
218
+ "delete /api/v1/users/{userId}/identities/{id}": {
219
+ summary: "Unlink an external id (idempotent)",
220
+ description: "Requires an admin key.",
221
+ params: { userId: "IdP user id.", id: "Linked identity id." },
222
+ successCode: "200",
223
+ success: OkSchema,
224
+ },
225
+ "get /api/v1/apps/{app}/identities/{provider}/{externalId}": {
226
+ summary: "Resolve an external id to a user and their permissions in this app",
227
+ description: "The hot path for an app that hears from someone on another system. Always 200 with a `found` discriminator — a miss is data, and the common case in any shared channel. `permissions` are the user's product permissions for THIS app, computed exactly as the claims hook computes them at token mint, so a Slack message and a browser session from the same person carry the same grants. A user with no membership resolves as found with no permissions.",
228
+ permission: "identity:resolve",
229
+ params: { ...APP_PARAM, provider: "The other system, e.g. slack.", externalId: "The id as that system spells it." },
230
+ successCode: "200",
231
+ success: IdentityResolutionSchema,
232
+ },
203
233
  "get /api/v1/apps/{app}/audit": {
204
234
  summary: "List recent audit entries",
205
235
  permission: "audit:read",
@@ -2326,6 +2326,360 @@
2326
2326
  }
2327
2327
  }
2328
2328
  },
2329
+ "/api/v1/users/{userId}/identities": {
2330
+ "get": {
2331
+ "summary": "List a user's linked identities (their ids on other systems)",
2332
+ "description": "Requires an admin key. Identities are global to the user, not per app — a Slack id identifies a person regardless of who is asking.",
2333
+ "security": [
2334
+ {
2335
+ "bearerAuth": []
2336
+ }
2337
+ ],
2338
+ "parameters": [
2339
+ {
2340
+ "name": "userId",
2341
+ "in": "path",
2342
+ "required": true,
2343
+ "description": "IdP user id.",
2344
+ "schema": {
2345
+ "type": "string"
2346
+ }
2347
+ }
2348
+ ],
2349
+ "responses": {
2350
+ "200": {
2351
+ "description": "OK",
2352
+ "content": {
2353
+ "application/json": {
2354
+ "schema": {
2355
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
2356
+ "type": "object",
2357
+ "properties": {
2358
+ "identities": {
2359
+ "type": "array",
2360
+ "items": {
2361
+ "type": "object",
2362
+ "properties": {
2363
+ "id": {
2364
+ "type": "string"
2365
+ },
2366
+ "userId": {
2367
+ "type": "string"
2368
+ },
2369
+ "provider": {
2370
+ "type": "string",
2371
+ "description": "The other system, lowercase — slack, whatsapp, telegram"
2372
+ },
2373
+ "externalId": {
2374
+ "type": "string",
2375
+ "description": "The id exactly as that system spells it"
2376
+ },
2377
+ "label": {
2378
+ "anyOf": [
2379
+ {
2380
+ "type": "string"
2381
+ },
2382
+ {
2383
+ "type": "null"
2384
+ }
2385
+ ]
2386
+ },
2387
+ "createdAt": {
2388
+ "type": "string"
2389
+ }
2390
+ },
2391
+ "required": [
2392
+ "id",
2393
+ "userId",
2394
+ "provider",
2395
+ "externalId",
2396
+ "label",
2397
+ "createdAt"
2398
+ ],
2399
+ "additionalProperties": false
2400
+ }
2401
+ }
2402
+ },
2403
+ "required": [
2404
+ "identities"
2405
+ ],
2406
+ "additionalProperties": false
2407
+ }
2408
+ }
2409
+ }
2410
+ },
2411
+ "401": {
2412
+ "description": "Missing or invalid bearer token"
2413
+ }
2414
+ }
2415
+ },
2416
+ "post": {
2417
+ "summary": "Link an external id to a user",
2418
+ "description": "Requires an admin key: a link asserts identity with nothing to prove it, so no app or member may do it. 201 on a new link, 200 when the same pair was already this user's, 409 `already_linked` when it belongs to someone else — an identity is never silently re-pointed.",
2419
+ "security": [
2420
+ {
2421
+ "bearerAuth": []
2422
+ }
2423
+ ],
2424
+ "parameters": [
2425
+ {
2426
+ "name": "userId",
2427
+ "in": "path",
2428
+ "required": true,
2429
+ "description": "IdP user id.",
2430
+ "schema": {
2431
+ "type": "string"
2432
+ }
2433
+ }
2434
+ ],
2435
+ "requestBody": {
2436
+ "required": true,
2437
+ "content": {
2438
+ "application/json": {
2439
+ "schema": {
2440
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
2441
+ "type": "object",
2442
+ "properties": {
2443
+ "provider": {
2444
+ "type": "string",
2445
+ "minLength": 1,
2446
+ "description": "slack, whatsapp, telegram… — normalised to lowercase"
2447
+ },
2448
+ "externalId": {
2449
+ "type": "string",
2450
+ "minLength": 1,
2451
+ "description": "The id as that system spells it, e.g. a Slack member id"
2452
+ },
2453
+ "label": {
2454
+ "description": "A human label for the console",
2455
+ "type": "string"
2456
+ }
2457
+ },
2458
+ "required": [
2459
+ "provider",
2460
+ "externalId"
2461
+ ]
2462
+ }
2463
+ }
2464
+ }
2465
+ },
2466
+ "responses": {
2467
+ "201": {
2468
+ "description": "OK",
2469
+ "content": {
2470
+ "application/json": {
2471
+ "schema": {
2472
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
2473
+ "type": "object",
2474
+ "properties": {
2475
+ "id": {
2476
+ "type": "string"
2477
+ },
2478
+ "created": {
2479
+ "type": "boolean",
2480
+ "description": "false when the same pair was already this user's"
2481
+ }
2482
+ },
2483
+ "required": [
2484
+ "id",
2485
+ "created"
2486
+ ],
2487
+ "additionalProperties": false
2488
+ }
2489
+ }
2490
+ }
2491
+ },
2492
+ "401": {
2493
+ "description": "Missing or invalid bearer token"
2494
+ },
2495
+ "405": {
2496
+ "description": "Method not allowed on this resource (see the `Allow` header)"
2497
+ },
2498
+ "409": {
2499
+ "description": "Conflict (already a member, last admin, slug taken, …)"
2500
+ },
2501
+ "422": {
2502
+ "description": "Body failed validation"
2503
+ }
2504
+ }
2505
+ }
2506
+ },
2507
+ "/api/v1/users/{userId}/identities/{id}": {
2508
+ "delete": {
2509
+ "summary": "Unlink an external id (idempotent)",
2510
+ "description": "Requires an admin key.",
2511
+ "security": [
2512
+ {
2513
+ "bearerAuth": []
2514
+ }
2515
+ ],
2516
+ "parameters": [
2517
+ {
2518
+ "name": "userId",
2519
+ "in": "path",
2520
+ "required": true,
2521
+ "description": "IdP user id.",
2522
+ "schema": {
2523
+ "type": "string"
2524
+ }
2525
+ },
2526
+ {
2527
+ "name": "id",
2528
+ "in": "path",
2529
+ "required": true,
2530
+ "description": "Linked identity id.",
2531
+ "schema": {
2532
+ "type": "string"
2533
+ }
2534
+ }
2535
+ ],
2536
+ "responses": {
2537
+ "200": {
2538
+ "description": "OK",
2539
+ "content": {
2540
+ "application/json": {
2541
+ "schema": {
2542
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
2543
+ "type": "object",
2544
+ "properties": {
2545
+ "ok": {
2546
+ "type": "boolean",
2547
+ "const": true
2548
+ }
2549
+ },
2550
+ "required": [
2551
+ "ok"
2552
+ ],
2553
+ "additionalProperties": false
2554
+ }
2555
+ }
2556
+ }
2557
+ },
2558
+ "401": {
2559
+ "description": "Missing or invalid bearer token"
2560
+ },
2561
+ "405": {
2562
+ "description": "Method not allowed on this resource (see the `Allow` header)"
2563
+ },
2564
+ "409": {
2565
+ "description": "Conflict (already a member, last admin, slug taken, …)"
2566
+ }
2567
+ }
2568
+ }
2569
+ },
2570
+ "/api/v1/apps/{app}/identities/{provider}/{externalId}": {
2571
+ "get": {
2572
+ "summary": "Resolve an external id to a user and their permissions in this app",
2573
+ "description": "The hot path for an app that hears from someone on another system. Always 200 with a `found` discriminator — a miss is data, and the common case in any shared channel. `permissions` are the user's product permissions for THIS app, computed exactly as the claims hook computes them at token mint, so a Slack message and a browser session from the same person carry the same grants. A user with no membership resolves as found with no permissions.",
2574
+ "security": [
2575
+ {
2576
+ "bearerAuth": []
2577
+ }
2578
+ ],
2579
+ "parameters": [
2580
+ {
2581
+ "name": "app",
2582
+ "in": "path",
2583
+ "required": true,
2584
+ "description": "Application key (oauth_client.metadata.app).",
2585
+ "schema": {
2586
+ "type": "string"
2587
+ }
2588
+ },
2589
+ {
2590
+ "name": "provider",
2591
+ "in": "path",
2592
+ "required": true,
2593
+ "description": "The other system, e.g. slack.",
2594
+ "schema": {
2595
+ "type": "string"
2596
+ }
2597
+ },
2598
+ {
2599
+ "name": "externalId",
2600
+ "in": "path",
2601
+ "required": true,
2602
+ "description": "The id as that system spells it.",
2603
+ "schema": {
2604
+ "type": "string"
2605
+ }
2606
+ }
2607
+ ],
2608
+ "responses": {
2609
+ "200": {
2610
+ "description": "OK",
2611
+ "content": {
2612
+ "application/json": {
2613
+ "schema": {
2614
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
2615
+ "anyOf": [
2616
+ {
2617
+ "type": "object",
2618
+ "properties": {
2619
+ "found": {
2620
+ "type": "boolean",
2621
+ "const": true
2622
+ },
2623
+ "userId": {
2624
+ "type": "string"
2625
+ },
2626
+ "email": {
2627
+ "type": "string"
2628
+ },
2629
+ "name": {
2630
+ "anyOf": [
2631
+ {
2632
+ "type": "string"
2633
+ },
2634
+ {
2635
+ "type": "null"
2636
+ }
2637
+ ]
2638
+ },
2639
+ "permissions": {
2640
+ "type": "array",
2641
+ "items": {
2642
+ "type": "string"
2643
+ },
2644
+ "description": "The user's product permissions for the asking app; admins get the whole catalog"
2645
+ }
2646
+ },
2647
+ "required": [
2648
+ "found",
2649
+ "userId",
2650
+ "email",
2651
+ "name",
2652
+ "permissions"
2653
+ ],
2654
+ "additionalProperties": false
2655
+ },
2656
+ {
2657
+ "type": "object",
2658
+ "properties": {
2659
+ "found": {
2660
+ "type": "boolean",
2661
+ "const": false
2662
+ }
2663
+ },
2664
+ "required": [
2665
+ "found"
2666
+ ],
2667
+ "additionalProperties": false
2668
+ }
2669
+ ]
2670
+ }
2671
+ }
2672
+ }
2673
+ },
2674
+ "401": {
2675
+ "description": "Missing or invalid bearer token"
2676
+ },
2677
+ "403": {
2678
+ "description": "Key lacks the permission / is bound to another app"
2679
+ }
2680
+ }
2681
+ }
2682
+ },
2329
2683
  "/api/v1/apps/{app}/audit": {
2330
2684
  "get": {
2331
2685
  "summary": "List recent audit entries",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willyim/idp",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "description": "Login for apps that don't own identity \u2014 OIDC client, server sessions, and react-router guards against the willy.im IdP",
5
5
  "type": "module",
6
6
  "main": "./dist/src/index.js",