@owlmeans/client-iam 0.1.18-rc.61 → 0.1.18-rc.63

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.
Files changed (43) hide show
  1. package/README.md +1 -1
  2. package/agent-meta/manifest.json +2 -2
  3. package/agent-meta/skills/client-iam/SKILL.md +17 -15
  4. package/build/append.d.ts +2 -10
  5. package/build/append.d.ts.map +1 -1
  6. package/build/append.js.map +1 -1
  7. package/build/consent.d.ts +1 -7
  8. package/build/consent.d.ts.map +1 -1
  9. package/build/consent.js +1 -1
  10. package/build/consent.js.map +1 -1
  11. package/build/consts.d.ts +1 -0
  12. package/build/consts.d.ts.map +1 -1
  13. package/build/consts.js +1 -0
  14. package/build/consts.js.map +1 -1
  15. package/build/index.d.ts +2 -0
  16. package/build/index.d.ts.map +1 -1
  17. package/build/index.js.map +1 -1
  18. package/build/organization/types.d.ts +23 -0
  19. package/build/organization/types.d.ts.map +1 -0
  20. package/build/organization/types.js +2 -0
  21. package/build/organization/types.js.map +1 -0
  22. package/build/organization.d.ts +7 -17
  23. package/build/organization.d.ts.map +1 -1
  24. package/build/organization.js +14 -20
  25. package/build/organization.js.map +1 -1
  26. package/build/types.d.ts +11 -0
  27. package/build/types.d.ts.map +1 -0
  28. package/build/types.js +2 -0
  29. package/build/types.js.map +1 -0
  30. package/build/types.local.d.ts +6 -0
  31. package/build/types.local.d.ts.map +1 -0
  32. package/build/types.local.js +2 -0
  33. package/build/types.local.js.map +1 -0
  34. package/package.json +10 -10
  35. package/src/append.ts +2 -10
  36. package/src/consent.ts +2 -9
  37. package/src/consts.ts +2 -0
  38. package/src/index.ts +2 -0
  39. package/src/organization/types.ts +23 -0
  40. package/src/organization.ts +22 -22
  41. package/src/types.local.ts +6 -0
  42. package/src/types.ts +13 -0
  43. package/tests/organization.spec.ts +4 -4
package/README.md CHANGED
@@ -6,7 +6,7 @@ This package ships embedded agent skills under `agent-meta/`. After installing y
6
6
  your project's skill store (`.agents/skills/`):
7
7
 
8
8
  ```sh
9
- npx @owlmeans/agent-skills@^0.1.18-rc.47
9
+ npx @owlmeans/agent-skills@^0.1.18-rc.49
10
10
  ```
11
11
 
12
12
  The embedded files are version-matched to this package release. Do not edit them
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "schemaVersion": 2,
3
3
  "package": "@owlmeans/client-iam",
4
- "version": "0.1.18-rc.61",
5
- "generatedAt": "2026-10-03T20:05:07.603Z",
4
+ "version": "0.1.18-rc.63",
5
+ "generatedAt": "2026-10-05T21:03:06.406Z",
6
6
  "canonicalRepo": "https://github.com/owlmeans/common",
7
7
  "entries": [
8
8
  {
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: client-iam
3
- description: "How to use @owlmeans/client-iam — the browser half of the OwlMeans IAM in one import: appendIam (OIDC guard plus the consent-before-sign-in precondition), withIamGuard / iamEntrypoints, the re-exported sign-in surface (useLogin, useLogout), the session's organizations (listOrganizations) and the organization switch (switchOrganization, which adopts the re-signed token), hasPermission for showing or hiding a control, and the refusal reasons ORGANIZATION_REFUSAL / ORGANIZATION_OWNER_REFUSAL. Auto-invoked when wiring sign-in into a web app, rendering an organization switcher, or reading permissions in a screen."
3
+ description: "How to use @owlmeans/client-iam — the browser half of the OwlMeans IAM in one import: appendIam (OIDC guard plus the consent-before-sign-in precondition), withIamGuard / iamEntrypoints, the re-exported sign-in surface (useLogin, useLogout), the session's organizations (organizationSwitchOf(ctx).listOrganizations) and the organization switch (organizationSwitchOf(ctx).switchOrganization, which adopts the re-signed token), hasPermission for showing or hiding a control, and the refusal reasons ORGANIZATION_REFUSAL / ORGANIZATION_OWNER_REFUSAL. Auto-invoked when wiring sign-in into a web app, rendering an organization switcher, or reading permissions in a screen."
4
4
  user-invocable: false
5
5
  ---
6
6
  <!-- AUTO-GENERATED — do not edit. Regenerate via sync-agent-meta. -->
@@ -8,7 +8,7 @@ user-invocable: false
8
8
  # @owlmeans/client-iam
9
9
 
10
10
  **Layer:** Client (browser-only — it depends on `@owlmeans/web-client` and `@owlmeans/web-oidc-rp`)
11
- **Install:** `"@owlmeans/client-iam": "^0.1.18-rc.61"` in `dependencies`
11
+ **Install:** `"@owlmeans/client-iam": "^0.1.18-rc.63"` in `dependencies`
12
12
 
13
13
  The browser side of the IAM for an application that signs its people in through an OwlMeans OIDC
14
14
  provider. One import wires the relying party, puts the consent precondition in front of every
@@ -23,10 +23,10 @@ reads permissions only to show or hide a control.
23
23
  | `appendIam(context, opts?)` | `appendOidcGuard` of `@owlmeans/web-oidc-rp` plus `requireConsentForLogin`. `opts.consent` is `ConsentLoginOptions` — `{ disabled: true }` for an application that sets no cookie at all |
24
24
  | `withIamGuard(tree, coguards?)` | `withOidcGuard` of `@owlmeans/oidc`: a decorated copy of an immutable protocol tree with `OIDC_GUARD` ahead of each selected guard (default `DEFAULT_GUARD`) |
25
25
  | `iamEntrypoints(dispatcherProps?)` | `oidcEntrypoints` of `@owlmeans/web-oidc-rp`: the browser bindings of the four shared OIDC protocols (sign-in pair and organization switch) and the dispatcher screen |
26
- | `listOrganizations(ctx)` | `OidcOrganizationItem[]` of the session — `{ entitySlug, title?, owner, groups?, home?, acting }` |
27
- | `switchOrganization(ctx, entitySlug)` | Moves the session into another of its organizations and adopts the re-signed token with `adoptToken` |
26
+ | `organizationSwitchOf(ctx).listOrganizations()` | `OidcOrganizationItem[]` of the session — `{ entitySlug, title?, owner, groups?, home?, acting }` |
27
+ | `organizationSwitchOf(ctx).switchOrganization(entitySlug)` | Moves the session into another of its organizations and adopts the re-signed token with `loginTokenOf(ctx).adoptToken` |
28
28
  | `requireConsentForLogin(ctx, opts?)`, `CONSENT_LOGIN_PRECONDITION`, `ConsentLoginOptions` | The consent precondition on its own (`'consent-before-login'`, priority 100), for a context wired another way |
29
- | `useLogin` / `useLogout`, `LoginOutcome`, `LoginIntent` and the login types | Re-exported from `@owlmeans/client-auth/login`, so an application has one IAM import |
29
+ | `useLogin` / `useLogout`, `LoginOutcome`, `LoginIntent` and the login types | Re-exported from `@owlmeans/client-auth/login`, so an application has one IAM import. `useLogin(target)` signs in first and lands on `target` after, consent and other post-sign-in steps included (`client-auth`) |
30
30
  | `hasPermission(auth, permission, { scope?, resourceId?, entitySlug? }?)` | Re-exported from `@owlmeans/iam` — the same check the server gate runs |
31
31
  | `ORGANIZATION_REFUSAL`, `ORGANIZATION_OWNER_REFUSAL` | `'organization'` / `'organization:owner'` — the `AuthForbidden` reasons of a non-member and of a non-owner |
32
32
  | `OidcOrganizationItem` and every `@owlmeans/iam` type | Re-exported types |
@@ -65,11 +65,12 @@ of them at a time, and that is session state held by the application's server
65
65
  of a request:
66
66
 
67
67
  ```typescript
68
- import { listOrganizations, switchOrganization, ORGANIZATION_REFUSAL } from '@owlmeans/client-iam'
68
+ import { organizationSwitchOf, ORGANIZATION_REFUSAL } from '@owlmeans/client-iam'
69
69
 
70
- const items = await listOrganizations(context) // the acting one carries `acting: true`
70
+ const organizations = organizationSwitchOf(context)
71
+ const items = await organizations.listOrganizations() // the acting one carries `acting: true`
71
72
  try {
72
- await switchOrganization(context, 'hiking-club')
73
+ await organizations.switchOrganization('hiking-club')
73
74
  // every request from here on, and every screen reading `auth`, acts in hiking-club
74
75
  } catch (error) {
75
76
  // AuthForbidden(ORGANIZATION_REFUSAL): not one of the person's organizations — the token stays
@@ -83,12 +84,12 @@ try {
83
84
  - The re-signed token carries the new organization's `entitySlug`, its groups and only its
84
85
  permission sets. Re-read `auth` after a switch; nothing else needs resetting.
85
86
  - There is no per-request organization selector: a screen offering "act in another organization"
86
- calls `switchOrganization`. A client without the `organizations` scope lists none and refuses
87
- every switch.
87
+ calls `organizationSwitchOf(ctx).switchOrganization`. A client without the `organizations` scope
88
+ lists none and refuses every switch.
88
89
 
89
90
  Managing organizations — creating one, inviting members, granting in it — is the server's job
90
- through `iamRuntime` (`@owlmeans/server-iam`); the browser calls the application's own endpoints
91
- for it, never the provider.
91
+ through `makeIamRuntimeClient(context, request)` (`@owlmeans/server-iam`); the browser calls the
92
+ application's own endpoints for it, never the provider.
92
93
 
93
94
  ## Permissions in a screen
94
95
 
@@ -106,8 +107,9 @@ the answer to hide or show a control only — the server gate decides.
106
107
 
107
108
  - One IAM import: take sign-in, organizations and permission checks from here, not from
108
109
  `@owlmeans/web-oidc-rp`, `@owlmeans/client-auth/login` and `@owlmeans/iam` separately.
109
- - Adopt a token only through `adoptToken` / `context.login().adopt(token)` — `switchOrganization`
110
- already does; never write `auth` or the stored token by hand.
110
+ - Adopt a token only through `loginTokenOf(ctx).adoptToken` / `context.login().adopt(token)` —
111
+ `organizationSwitchOf(ctx).switchOrganization` already does; never write `auth` or the stored
112
+ token by hand.
111
113
  - Phrase `ORGANIZATION_REFUSAL` and `ORGANIZATION_OWNER_REFUSAL` as sentences for the person; they
112
114
  are reasons, not messages.
113
115
  - Never send an organization id from the browser: organizations travel by `entitySlug` only.
@@ -115,7 +117,7 @@ the answer to hide or show a control only — the server gate decides.
115
117
  ## Depends On
116
118
 
117
119
  - `@owlmeans/web-oidc-rp`, `@owlmeans/oidc` — the guard, the bindings and the switch protocols
118
- - `@owlmeans/client-auth` — the login host and `adoptToken`
120
+ - `@owlmeans/client-auth` — the login host and `loginTokenOf(ctx).adoptToken`
119
121
  - `@owlmeans/consent` — the consent store the precondition reads
120
122
  - `@owlmeans/iam` — types and `hasPermission`
121
123
  - `@owlmeans/context`, `@owlmeans/entrypoint`, `@owlmeans/web-client`
package/build/append.d.ts CHANGED
@@ -1,12 +1,5 @@
1
- import type { AppConfig, AppContext } from '@owlmeans/web-client';
2
- import type { WithSharedConfig } from '@owlmeans/oidc';
3
- import type { ConsentLoginOptions } from './consent.js';
4
- type IamClientConfig = AppConfig & WithSharedConfig;
5
- type IamClientContext<C extends IamClientConfig = IamClientConfig> = AppContext<C>;
6
- export interface AppendIamOptions {
7
- /** Consent required before a sign-in flow may start. `{ disabled: true }` turns it off. */
8
- consent?: ConsentLoginOptions;
9
- }
1
+ import type { IamClientConfig, IamClientContext } from './types.local.js';
2
+ import type { AppendIamOptions } from './types.js';
10
3
  /**
11
4
  * One-call OIDC RP setup for a web client context.
12
5
  *
@@ -21,5 +14,4 @@ export interface AppendIamOptions {
21
14
  * cookie at all passes `{ consent: { disabled: true } }`.
22
15
  */
23
16
  export declare const appendIam: <C extends IamClientConfig, T extends IamClientContext<C>>(context: T, opts?: AppendIamOptions) => T;
24
- export {};
25
17
  //# sourceMappingURL=append.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"append.d.ts","sourceRoot":"","sources":["../src/append.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACjE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAGtD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAA;AAEvD,KAAK,eAAe,GAAG,SAAS,GAAG,gBAAgB,CAAA;AACnD,KAAK,gBAAgB,CAAC,CAAC,SAAS,eAAe,GAAG,eAAe,IAAI,UAAU,CAAC,CAAC,CAAC,CAAA;AAElF,MAAM,WAAW,gBAAgB;IAC/B,2FAA2F;IAC3F,OAAO,CAAC,EAAE,mBAAmB,CAAA;CAC9B;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,SAAS,GAAI,CAAC,SAAS,eAAe,EAAE,CAAC,SAAS,gBAAgB,CAAC,CAAC,CAAC,WACvE,CAAC,SAAS,gBAAgB,KAClC,CAKF,CAAA"}
1
+ {"version":3,"file":"append.d.ts","sourceRoot":"","sources":["../src/append.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AACzE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAGlD;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,SAAS,GAAI,CAAC,SAAS,eAAe,EAAE,CAAC,SAAS,gBAAgB,CAAC,CAAC,CAAC,WACvE,CAAC,SAAS,gBAAgB,KAClC,CAKF,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"append.js","sourceRoot":"","sources":["../src/append.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AACvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAA;AAWrD;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CACvB,OAAU,EAAE,IAAuB,EAChC,EAAE;IACL,eAAe,CAAO,OAAO,CAAC,CAAA;IAC9B,sBAAsB,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;IAE9C,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA"}
1
+ {"version":3,"file":"append.js","sourceRoot":"","sources":["../src/append.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AACvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAA;AAKrD;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CACvB,OAAU,EAAE,IAAuB,EAChC,EAAE;IACL,eAAe,CAAO,OAAO,CAAC,CAAA;IAC9B,sBAAsB,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;IAE9C,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA"}
@@ -1,11 +1,5 @@
1
1
  import type { BasicContext } from '@owlmeans/context';
2
- export declare const CONSENT_LOGIN_PRECONDITION = "consent-before-login";
3
- export interface ConsentLoginOptions {
4
- /** The category that must be granted. Defaults to `essential`. */
5
- category?: string;
6
- /** Off switch, for an application that genuinely sets no cookie at all. */
7
- disabled?: boolean;
8
- }
2
+ import type { ConsentLoginOptions } from './types.js';
9
3
  /**
10
4
  * Refuse to start a sign-in flow until the required consent category is granted, and open the
11
5
  * consent dialog in the same gesture so the user can grant it.
@@ -1 +1 @@
1
- {"version":3,"file":"consent.d.ts","sourceRoot":"","sources":["../src/consent.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAErD,eAAO,MAAM,0BAA0B,yBAAyB,CAAA;AAEhE,MAAM,WAAW,mBAAmB;IAClC,kEAAkE;IAClE,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,sBAAsB,QAC5B,YAAY,CAAC,GAAG,CAAC,SAAS,mBAAmB,KACjD,IAoBF,CAAA"}
1
+ {"version":3,"file":"consent.d.ts","sourceRoot":"","sources":["../src/consent.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAErD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAErD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,sBAAsB,QAC5B,YAAY,CAAC,GAAG,CAAC,SAAS,mBAAmB,KACjD,IAoBF,CAAA"}
package/build/consent.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { CONSENT_ESSENTIAL, consentStore } from '@owlmeans/consent';
2
2
  import { ensureLoginService } from '@owlmeans/client-auth/login';
3
- export const CONSENT_LOGIN_PRECONDITION = 'consent-before-login';
3
+ import { CONSENT_LOGIN_PRECONDITION } from './consts.js';
4
4
  /**
5
5
  * Refuse to start a sign-in flow until the required consent category is granted, and open the
6
6
  * consent dialog in the same gesture so the user can grant it.
@@ -1 +1 @@
1
- {"version":3,"file":"consent.js","sourceRoot":"","sources":["../src/consent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAA;AAGhE,MAAM,CAAC,MAAM,0BAA0B,GAAG,sBAAsB,CAAA;AAShE;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CACpC,GAAsB,EAAE,IAA0B,EAC5C,EAAE;IACR,IAAI,IAAI,EAAE,QAAQ,KAAK,IAAI,EAAE,CAAC;QAC5B,OAAM;IACR,CAAC;IACD,MAAM,QAAQ,GAAG,IAAI,EAAE,QAAQ,IAAI,iBAAiB,CAAA;IAEpD,kBAAkB,CAAC,GAAG,CAAC,CAAC,oBAAoB,CAAC;QAC3C,KAAK,EAAE,0BAA0B;QACjC,0FAA0F;QAC1F,qFAAqF;QACrF,QAAQ,EAAE,GAAG;QACb,KAAK,EAAE,GAAG,EAAE;YACV,IAAI,YAAY,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,YAAY,CAAC,GAAG,EAAE,CAAC,MAAM,IAAI,IAAI,EAAE,CAAC;gBACxE,OAAO,IAAI,CAAA;YACb,CAAC;YACD,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;YAE1B,OAAO,KAAK,CAAA;QACd,CAAC;KACF,CAAC,CAAA;AACJ,CAAC,CAAA"}
1
+ {"version":3,"file":"consent.js","sourceRoot":"","sources":["../src/consent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAA;AAEhE,OAAO,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAA;AAGxD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CACpC,GAAsB,EAAE,IAA0B,EAC5C,EAAE;IACR,IAAI,IAAI,EAAE,QAAQ,KAAK,IAAI,EAAE,CAAC;QAC5B,OAAM;IACR,CAAC;IACD,MAAM,QAAQ,GAAG,IAAI,EAAE,QAAQ,IAAI,iBAAiB,CAAA;IAEpD,kBAAkB,CAAC,GAAG,CAAC,CAAC,oBAAoB,CAAC;QAC3C,KAAK,EAAE,0BAA0B;QACjC,0FAA0F;QAC1F,qFAAqF;QACrF,QAAQ,EAAE,GAAG;QACb,KAAK,EAAE,GAAG,EAAE;YACV,IAAI,YAAY,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,YAAY,CAAC,GAAG,EAAE,CAAC,MAAM,IAAI,IAAI,EAAE,CAAC;gBACxE,OAAO,IAAI,CAAA;YACb,CAAC;YACD,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;YAE1B,OAAO,KAAK,CAAA;QACd,CAAC;KACF,CAAC,CAAA;AACJ,CAAC,CAAA"}
package/build/consts.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export declare const CLIENT_IAM_SERVICE = "client-iam-service";
2
+ export declare const CONSENT_LOGIN_PRECONDITION = "consent-before-login";
2
3
  //# sourceMappingURL=consts.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kBAAkB,uBAAuB,CAAA"}
1
+ {"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kBAAkB,uBAAuB,CAAA;AAEtD,eAAO,MAAM,0BAA0B,yBAAyB,CAAA"}
package/build/consts.js CHANGED
@@ -1,2 +1,3 @@
1
1
  export const CLIENT_IAM_SERVICE = 'client-iam-service';
2
+ export const CONSENT_LOGIN_PRECONDITION = 'consent-before-login';
2
3
  //# sourceMappingURL=consts.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"consts.js","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,kBAAkB,GAAG,oBAAoB,CAAA"}
1
+ {"version":3,"file":"consts.js","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,kBAAkB,GAAG,oBAAoB,CAAA;AAEtD,MAAM,CAAC,MAAM,0BAA0B,GAAG,sBAAsB,CAAA"}
package/build/index.d.ts CHANGED
@@ -4,6 +4,8 @@ export { ORGANIZATION_REFUSAL, ORGANIZATION_OWNER_REFUSAL } from '@owlmeans/oidc
4
4
  export type { OidcOrganizationItem } from '@owlmeans/oidc';
5
5
  export * from './consts.js';
6
6
  export * from './append.js';
7
+ export type * from './types.js';
8
+ export type * from './organization/types.js';
7
9
  export * from './consent.js';
8
10
  export * from './login.js';
9
11
  export * from './organization.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,eAAe,CAAA;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,EAAE,oBAAoB,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAA;AACjF,YAAY,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAA;AAC1D,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAC1B,cAAc,mBAAmB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,eAAe,CAAA;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,EAAE,oBAAoB,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAA;AACjF,YAAY,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAA;AAC1D,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,mBAAmB,YAAY,CAAA;AAC/B,mBAAmB,yBAAyB,CAAA;AAC5C,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAC1B,cAAc,mBAAmB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,EAAE,oBAAoB,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAA;AAEjF,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAC1B,cAAc,mBAAmB,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,EAAE,oBAAoB,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAA;AAEjF,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAG3B,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAC1B,cAAc,mBAAmB,CAAA"}
@@ -0,0 +1,23 @@
1
+ import type { OidcOrganizationItem } from '@owlmeans/oidc';
2
+ /** The organizations of the signed-in subject, and the move between them, from the browser's side. */
3
+ export interface OrganizationSwitchHelper {
4
+ /**
5
+ * The organizations of the signed-in subject, the one the session acts in marked `acting`.
6
+ *
7
+ * Answered by the application's own server from the session it holds — refreshed against the
8
+ * provider by the guard first — so a person just removed from an organization no longer sees it.
9
+ * A session of a client without the organizations scope has none. Needs the bindings of
10
+ * `iamEntrypoints()`.
11
+ */
12
+ listOrganizations: () => Promise<OidcOrganizationItem[]>;
13
+ /**
14
+ * Moves the session into another organization of its subject and adopts the re-signed token, so
15
+ * every request after it — and every screen reading `auth` — acts in that organization.
16
+ *
17
+ * There is no per-request organization selector: the session, not the request, decides where a
18
+ * request acts. An organization the subject is not in is refused (`ORGANIZATION_REFUSAL`) and the
19
+ * current token stays.
20
+ */
21
+ switchOrganization: (entitySlug: string) => Promise<void>;
22
+ }
23
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/organization/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAA;AAE1D,sGAAsG;AACtG,MAAM,WAAW,wBAAwB;IACvC;;;;;;;OAOG;IACH,iBAAiB,EAAE,MAAM,OAAO,CAAC,oBAAoB,EAAE,CAAC,CAAA;IACxD;;;;;;;OAOG;IACH,kBAAkB,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;CAC1D"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/organization/types.ts"],"names":[],"mappings":""}
@@ -1,21 +1,11 @@
1
- import type { BasicContext } from '@owlmeans/context';
1
+ import { type BasicContext } from '@owlmeans/context';
2
2
  import type { OidcOrganizationItem } from '@owlmeans/oidc';
3
- /**
4
- * The organizations of the signed-in subject, the one the session acts in marked `acting`.
5
- *
6
- * Answered by the application's own server from the session it holds — refreshed against the
7
- * provider by the guard first — so a person just removed from an organization no longer sees it.
8
- * A session of a client without the organizations scope has none. Needs the bindings of
9
- * `iamEntrypoints()`.
10
- */
3
+ import type { OrganizationSwitchHelper } from './organization/types.js';
4
+ export declare const makeOrganizationSwitchHelper: (ctx: BasicContext<any>) => OrganizationSwitchHelper;
5
+ /** The organization switch of a context — one per context. */
6
+ export declare const organizationSwitchOf: (target: BasicContext<any>) => OrganizationSwitchHelper;
7
+ /** @deprecated compat:factory-refactor — use `organizationSwitchOf(ctx).listOrganizations()` */
11
8
  export declare const listOrganizations: (ctx: BasicContext<any>) => Promise<OidcOrganizationItem[]>;
12
- /**
13
- * Moves the session into another organization of its subject and adopts the re-signed token, so
14
- * every request after it — and every screen reading `auth` — acts in that organization.
15
- *
16
- * There is no per-request organization selector: the session, not the request, decides where a
17
- * request acts. An organization the subject is not in is refused (`ORGANIZATION_REFUSAL`) and the
18
- * current token stays.
19
- */
9
+ /** @deprecated compat:factory-refactor — use `organizationSwitchOf(ctx).switchOrganization(…)` */
20
10
  export declare const switchOrganization: (ctx: BasicContext<any>, entitySlug: string) => Promise<void>;
21
11
  //# sourceMappingURL=organization.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"organization.d.ts","sourceRoot":"","sources":["../src/organization.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAErD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAA;AAG1D;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB,QAAe,YAAY,CAAC,GAAG,CAAC,KAAG,OAAO,CAAC,oBAAoB,EAAE,CAC7B,CAAA;AAElE;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,QAAe,YAAY,CAAC,GAAG,CAAC,cAAc,MAAM,KAAG,OAAO,CAAC,IAAI,CAIjG,CAAA"}
1
+ {"version":3,"file":"organization.d.ts","sourceRoot":"","sources":["../src/organization.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAEjE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAA;AAE1D,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAA;AAEvE,eAAO,MAAM,4BAA4B,QAAS,YAAY,CAAC,GAAG,CAAC,KAAG,wBAWrE,CAAA;AAED,8DAA8D;AAC9D,eAAO,MAAM,oBAAoB,yDAAmD,CAAA;AAEpF,gGAAgG;AAChG,eAAO,MAAM,iBAAiB,QAAe,YAAY,CAAC,GAAG,CAAC,KAAG,OAAO,CAAC,oBAAoB,EAAE,CAC1C,CAAA;AAErD,kGAAkG;AAClG,eAAO,MAAM,kBAAkB,QAAe,YAAY,CAAC,GAAG,CAAC,cAAc,MAAM,KAAG,OAAO,CAAC,IAAI,CAClC,CAAA"}
@@ -1,24 +1,18 @@
1
+ import { memoHelper } from '@owlmeans/context';
1
2
  import { oidcProtocols } from '@owlmeans/oidc';
2
3
  import { adoptToken } from '@owlmeans/client-auth/login';
3
- /**
4
- * The organizations of the signed-in subject, the one the session acts in marked `acting`.
5
- *
6
- * Answered by the application's own server from the session it holds — refreshed against the
7
- * provider by the guard first — so a person just removed from an organization no longer sees it.
8
- * A session of a client without the organizations scope has none. Needs the bindings of
9
- * `iamEntrypoints()`.
10
- */
11
- export const listOrganizations = async (ctx) => (await ctx.entrypoint(oidcProtocols.organizations).call()).items;
12
- /**
13
- * Moves the session into another organization of its subject and adopts the re-signed token, so
14
- * every request after it — and every screen reading `auth` — acts in that organization.
15
- *
16
- * There is no per-request organization selector: the session, not the request, decides where a
17
- * request acts. An organization the subject is not in is refused (`ORGANIZATION_REFUSAL`) and the
18
- * current token stays.
19
- */
20
- export const switchOrganization = async (ctx, entitySlug) => {
21
- const { token } = await ctx.entrypoint(oidcProtocols.organization).call({ body: { entitySlug } });
22
- await adoptToken(ctx, token);
4
+ export const makeOrganizationSwitchHelper = (ctx) => {
5
+ const listOrganizations = async () => (await ctx.entrypoint(oidcProtocols.organizations).call()).items;
6
+ const switchOrganization = async (entitySlug) => {
7
+ const { token } = await ctx.entrypoint(oidcProtocols.organization).call({ body: { entitySlug } });
8
+ await adoptToken(ctx, token);
9
+ };
10
+ return { listOrganizations, switchOrganization };
23
11
  };
12
+ /** The organization switch of a context — one per context. */
13
+ export const organizationSwitchOf = memoHelper.oncePer(makeOrganizationSwitchHelper);
14
+ /** @deprecated compat:factory-refactor — use `organizationSwitchOf(ctx).listOrganizations()` */
15
+ export const listOrganizations = async (ctx) => await organizationSwitchOf(ctx).listOrganizations();
16
+ /** @deprecated compat:factory-refactor — use `organizationSwitchOf(ctx).switchOrganization(…)` */
17
+ export const switchOrganization = async (ctx, entitySlug) => await organizationSwitchOf(ctx).switchOrganization(entitySlug);
24
18
  //# sourceMappingURL=organization.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"organization.js","sourceRoot":"","sources":["../src/organization.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAE9C,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAA;AAExD;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,EAAE,GAAsB,EAAmC,EAAE,CACjG,CAAC,MAAM,GAAG,CAAC,UAAU,CAAC,aAAa,CAAC,aAAa,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,KAAK,CAAA;AAElE;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,EAAE,GAAsB,EAAE,UAAkB,EAAiB,EAAE;IACpG,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,GAAG,CAAC,UAAU,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,EAAE,UAAU,EAAE,EAAE,CAAC,CAAA;IAEjG,MAAM,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;AAC9B,CAAC,CAAA"}
1
+ {"version":3,"file":"organization.js","sourceRoot":"","sources":["../src/organization.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAqB,MAAM,mBAAmB,CAAA;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAE9C,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAA;AAGxD,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAAC,GAAsB,EAA4B,EAAE;IAC/F,MAAM,iBAAiB,GAAG,KAAK,IAAqC,EAAE,CACpE,CAAC,MAAM,GAAG,CAAC,UAAU,CAAC,aAAa,CAAC,aAAa,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,KAAK,CAAA;IAElE,MAAM,kBAAkB,GAAG,KAAK,EAAE,UAAkB,EAAiB,EAAE;QACrE,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,GAAG,CAAC,UAAU,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,EAAE,UAAU,EAAE,EAAE,CAAC,CAAA;QAEjG,MAAM,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;IAC9B,CAAC,CAAA;IAED,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,CAAA;AAClD,CAAC,CAAA;AAED,8DAA8D;AAC9D,MAAM,CAAC,MAAM,oBAAoB,GAAG,UAAU,CAAC,OAAO,CAAC,4BAA4B,CAAC,CAAA;AAEpF,gGAAgG;AAChG,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,EAAE,GAAsB,EAAmC,EAAE,CACjG,MAAM,oBAAoB,CAAC,GAAG,CAAC,CAAC,iBAAiB,EAAE,CAAA;AAErD,kGAAkG;AAClG,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,EAAE,GAAsB,EAAE,UAAkB,EAAiB,EAAE,CACpG,MAAM,oBAAoB,CAAC,GAAG,CAAC,CAAC,kBAAkB,CAAC,UAAU,CAAC,CAAA"}
@@ -0,0 +1,11 @@
1
+ export interface ConsentLoginOptions {
2
+ /** The category that must be granted. Defaults to `essential`. */
3
+ category?: string;
4
+ /** Off switch, for an application that genuinely sets no cookie at all. */
5
+ disabled?: boolean;
6
+ }
7
+ export interface AppendIamOptions {
8
+ /** Consent required before a sign-in flow may start. `{ disabled: true }` turns it off. */
9
+ consent?: ConsentLoginOptions;
10
+ }
11
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,mBAAmB;IAClC,kEAAkE;IAClE,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB;AAED,MAAM,WAAW,gBAAgB;IAC/B,2FAA2F;IAC3F,OAAO,CAAC,EAAE,mBAAmB,CAAA;CAC9B"}
package/build/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ import type { AppConfig, AppContext } from '@owlmeans/web-client';
2
+ import type { WithSharedConfig } from '@owlmeans/oidc';
3
+ export interface IamClientConfig extends AppConfig, WithSharedConfig {
4
+ }
5
+ export type IamClientContext<C extends IamClientConfig = IamClientConfig> = AppContext<C>;
6
+ //# sourceMappingURL=types.local.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.local.d.ts","sourceRoot":"","sources":["../src/types.local.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACjE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAEtD,MAAM,WAAW,eAAgB,SAAQ,SAAS,EAAE,gBAAgB;CAAG;AAEvE,MAAM,MAAM,gBAAgB,CAAC,CAAC,SAAS,eAAe,GAAG,eAAe,IAAI,UAAU,CAAC,CAAC,CAAC,CAAA"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.local.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.local.js","sourceRoot":"","sources":["../src/types.local.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@owlmeans/client-iam",
3
- "version": "0.1.18-rc.61",
3
+ "version": "0.1.18-rc.63",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -22,18 +22,18 @@
22
22
  }
23
23
  },
24
24
  "dependencies": {
25
- "@owlmeans/client-auth": "^0.1.18-rc.56",
26
- "@owlmeans/consent": "^0.1.18-rc.9",
27
- "@owlmeans/context": "^0.1.18-rc.32",
28
- "@owlmeans/entrypoint": "^0.1.18-rc.39",
29
- "@owlmeans/iam": "^0.1.18-rc.48",
30
- "@owlmeans/oidc": "^0.1.18-rc.53",
31
- "@owlmeans/web-client": "^0.1.18-rc.59",
32
- "@owlmeans/web-oidc-rp": "^0.1.18-rc.62"
25
+ "@owlmeans/client-auth": "^0.1.18-rc.58",
26
+ "@owlmeans/consent": "^0.1.18-rc.11",
27
+ "@owlmeans/context": "^0.1.18-rc.34",
28
+ "@owlmeans/entrypoint": "^0.1.18-rc.41",
29
+ "@owlmeans/iam": "^0.1.18-rc.50",
30
+ "@owlmeans/oidc": "^0.1.18-rc.55",
31
+ "@owlmeans/web-client": "^0.1.18-rc.61",
32
+ "@owlmeans/web-oidc-rp": "^0.1.18-rc.64"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@owlmeans/dep-config": "workspace:*",
36
- "@types/bun": "^1.4.0",
36
+ "@types/bun": "^1.4.2",
37
37
  "nodemon": "^3.1.14",
38
38
  "typescript": "^7.0.2"
39
39
  },
package/src/append.ts CHANGED
@@ -1,16 +1,8 @@
1
- import type { AppConfig, AppContext } from '@owlmeans/web-client'
2
- import type { WithSharedConfig } from '@owlmeans/oidc'
3
1
  import { appendOidcGuard } from '@owlmeans/web-oidc-rp'
4
2
  import { requireConsentForLogin } from './consent.js'
5
- import type { ConsentLoginOptions } from './consent.js'
3
+ import type { IamClientConfig, IamClientContext } from './types.local.js'
4
+ import type { AppendIamOptions } from './types.js'
6
5
 
7
- type IamClientConfig = AppConfig & WithSharedConfig
8
- type IamClientContext<C extends IamClientConfig = IamClientConfig> = AppContext<C>
9
-
10
- export interface AppendIamOptions {
11
- /** Consent required before a sign-in flow may start. `{ disabled: true }` turns it off. */
12
- consent?: ConsentLoginOptions
13
- }
14
6
 
15
7
  /**
16
8
  * One-call OIDC RP setup for a web client context.
package/src/consent.ts CHANGED
@@ -1,15 +1,8 @@
1
1
  import { CONSENT_ESSENTIAL, consentStore } from '@owlmeans/consent'
2
2
  import { ensureLoginService } from '@owlmeans/client-auth/login'
3
3
  import type { BasicContext } from '@owlmeans/context'
4
-
5
- export const CONSENT_LOGIN_PRECONDITION = 'consent-before-login'
6
-
7
- export interface ConsentLoginOptions {
8
- /** The category that must be granted. Defaults to `essential`. */
9
- category?: string
10
- /** Off switch, for an application that genuinely sets no cookie at all. */
11
- disabled?: boolean
12
- }
4
+ import { CONSENT_LOGIN_PRECONDITION } from './consts.js'
5
+ import type { ConsentLoginOptions } from './types.js'
13
6
 
14
7
  /**
15
8
  * Refuse to start a sign-in flow until the required consent category is granted, and open the
package/src/consts.ts CHANGED
@@ -1 +1,3 @@
1
1
  export const CLIENT_IAM_SERVICE = 'client-iam-service'
2
+
3
+ export const CONSENT_LOGIN_PRECONDITION = 'consent-before-login'
package/src/index.ts CHANGED
@@ -4,6 +4,8 @@ export { ORGANIZATION_REFUSAL, ORGANIZATION_OWNER_REFUSAL } from '@owlmeans/oidc
4
4
  export type { OidcOrganizationItem } from '@owlmeans/oidc'
5
5
  export * from './consts.js'
6
6
  export * from './append.js'
7
+ export type * from './types.js'
8
+ export type * from './organization/types.js'
7
9
  export * from './consent.js'
8
10
  export * from './login.js'
9
11
  export * from './organization.js'
@@ -0,0 +1,23 @@
1
+ import type { OidcOrganizationItem } from '@owlmeans/oidc'
2
+
3
+ /** The organizations of the signed-in subject, and the move between them, from the browser's side. */
4
+ export interface OrganizationSwitchHelper {
5
+ /**
6
+ * The organizations of the signed-in subject, the one the session acts in marked `acting`.
7
+ *
8
+ * Answered by the application's own server from the session it holds — refreshed against the
9
+ * provider by the guard first — so a person just removed from an organization no longer sees it.
10
+ * A session of a client without the organizations scope has none. Needs the bindings of
11
+ * `iamEntrypoints()`.
12
+ */
13
+ listOrganizations: () => Promise<OidcOrganizationItem[]>
14
+ /**
15
+ * Moves the session into another organization of its subject and adopts the re-signed token, so
16
+ * every request after it — and every screen reading `auth` — acts in that organization.
17
+ *
18
+ * There is no per-request organization selector: the session, not the request, decides where a
19
+ * request acts. An organization the subject is not in is refused (`ORGANIZATION_REFUSAL`) and the
20
+ * current token stays.
21
+ */
22
+ switchOrganization: (entitySlug: string) => Promise<void>
23
+ }
@@ -1,29 +1,29 @@
1
- import type { BasicContext } from '@owlmeans/context'
1
+ import { memoHelper, type BasicContext } from '@owlmeans/context'
2
2
  import { oidcProtocols } from '@owlmeans/oidc'
3
3
  import type { OidcOrganizationItem } from '@owlmeans/oidc'
4
4
  import { adoptToken } from '@owlmeans/client-auth/login'
5
+ import type { OrganizationSwitchHelper } from './organization/types.js'
5
6
 
6
- /**
7
- * The organizations of the signed-in subject, the one the session acts in marked `acting`.
8
- *
9
- * Answered by the application's own server from the session it holds — refreshed against the
10
- * provider by the guard first — so a person just removed from an organization no longer sees it.
11
- * A session of a client without the organizations scope has none. Needs the bindings of
12
- * `iamEntrypoints()`.
13
- */
14
- export const listOrganizations = async (ctx: BasicContext<any>): Promise<OidcOrganizationItem[]> =>
15
- (await ctx.entrypoint(oidcProtocols.organizations).call()).items
7
+ export const makeOrganizationSwitchHelper = (ctx: BasicContext<any>): OrganizationSwitchHelper => {
8
+ const listOrganizations = async (): Promise<OidcOrganizationItem[]> =>
9
+ (await ctx.entrypoint(oidcProtocols.organizations).call()).items
10
+
11
+ const switchOrganization = async (entitySlug: string): Promise<void> => {
12
+ const { token } = await ctx.entrypoint(oidcProtocols.organization).call({ body: { entitySlug } })
16
13
 
17
- /**
18
- * Moves the session into another organization of its subject and adopts the re-signed token, so
19
- * every request after it — and every screen reading `auth` — acts in that organization.
20
- *
21
- * There is no per-request organization selector: the session, not the request, decides where a
22
- * request acts. An organization the subject is not in is refused (`ORGANIZATION_REFUSAL`) and the
23
- * current token stays.
24
- */
25
- export const switchOrganization = async (ctx: BasicContext<any>, entitySlug: string): Promise<void> => {
26
- const { token } = await ctx.entrypoint(oidcProtocols.organization).call({ body: { entitySlug } })
14
+ await adoptToken(ctx, token)
15
+ }
27
16
 
28
- await adoptToken(ctx, token)
17
+ return { listOrganizations, switchOrganization }
29
18
  }
19
+
20
+ /** The organization switch of a context — one per context. */
21
+ export const organizationSwitchOf = memoHelper.oncePer(makeOrganizationSwitchHelper)
22
+
23
+ /** @deprecated compat:factory-refactor — use `organizationSwitchOf(ctx).listOrganizations()` */
24
+ export const listOrganizations = async (ctx: BasicContext<any>): Promise<OidcOrganizationItem[]> =>
25
+ await organizationSwitchOf(ctx).listOrganizations()
26
+
27
+ /** @deprecated compat:factory-refactor — use `organizationSwitchOf(ctx).switchOrganization(…)` */
28
+ export const switchOrganization = async (ctx: BasicContext<any>, entitySlug: string): Promise<void> =>
29
+ await organizationSwitchOf(ctx).switchOrganization(entitySlug)
@@ -0,0 +1,6 @@
1
+ import type { AppConfig, AppContext } from '@owlmeans/web-client'
2
+ import type { WithSharedConfig } from '@owlmeans/oidc'
3
+
4
+ export interface IamClientConfig extends AppConfig, WithSharedConfig {}
5
+
6
+ export type IamClientContext<C extends IamClientConfig = IamClientConfig> = AppContext<C>
package/src/types.ts ADDED
@@ -0,0 +1,13 @@
1
+
2
+
3
+ export interface ConsentLoginOptions {
4
+ /** The category that must be granted. Defaults to `essential`. */
5
+ category?: string
6
+ /** Off switch, for an application that genuinely sets no cookie at all. */
7
+ disabled?: boolean
8
+ }
9
+
10
+ export interface AppendIamOptions {
11
+ /** Consent required before a sign-in flow may start. `{ disabled: true }` turns it off. */
12
+ consent?: ConsentLoginOptions
13
+ }
@@ -12,7 +12,7 @@ import { DEFAULT_ALIAS as AUTH_SERVICE } from '@owlmeans/client-auth'
12
12
  import { ORGANIZATION_REFUSAL, oidcProtocols } from '@owlmeans/oidc'
13
13
  import type { OidcOrganizationItem } from '@owlmeans/oidc'
14
14
  import { RouteProtocols } from '@owlmeans/route'
15
- import { listOrganizations, switchOrganization } from '../src/organization.js'
15
+ import { organizationSwitchOf } from '../src/organization.js'
16
16
 
17
17
  /**
18
18
  * The organization switch from the browser's side. The relying party's server is stood in for by
@@ -63,14 +63,14 @@ describe('@owlmeans/client-iam — organizations', () => {
63
63
  test('listOrganizations answers the items of the session', async () => {
64
64
  const { context, calls } = await start()
65
65
 
66
- expect(await listOrganizations(context)).toEqual(ITEMS)
66
+ expect(await organizationSwitchOf(context).listOrganizations()).toEqual(ITEMS)
67
67
  expect(calls.map(call => call.alias)).toEqual([oidcProtocols.organizations.alias])
68
68
  })
69
69
 
70
70
  test('switchOrganization posts the slug and adopts the re-signed token', async () => {
71
71
  const { context, calls, adopted } = await start()
72
72
 
73
- await switchOrganization(context, 'beta')
73
+ await organizationSwitchOf(context).switchOrganization('beta')
74
74
  expect(calls[0].alias).toBe(oidcProtocols.organization.alias)
75
75
  expect(calls[0].body).toEqual({ entitySlug: 'beta' })
76
76
  expect(adopted).toEqual(['wrapped-token-for-beta'])
@@ -79,7 +79,7 @@ describe('@owlmeans/client-iam — organizations', () => {
79
79
  test('a refused switch adopts nothing', async () => {
80
80
  const { context, adopted } = await start()
81
81
 
82
- await expect(switchOrganization(context, 'gamma')).rejects.toBeInstanceOf(AuthForbidden)
82
+ await expect(organizationSwitchOf(context).switchOrganization('gamma')).rejects.toBeInstanceOf(AuthForbidden)
83
83
  expect(adopted).toEqual([])
84
84
  })
85
85
  })