@andco/sdk 0.0.2 → 0.0.4

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 (83) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +96 -54
  3. package/dist/auth.d.ts +8 -3
  4. package/dist/auth.d.ts.map +1 -1
  5. package/dist/auth.js +32 -23
  6. package/dist/browser/controller.d.ts +55 -1
  7. package/dist/browser/controller.d.ts.map +1 -1
  8. package/dist/browser/controller.js +166 -9
  9. package/dist/browser/frame.d.ts +4 -3
  10. package/dist/browser/frame.d.ts.map +1 -1
  11. package/dist/browser/frame.js +12 -20
  12. package/dist/browser/index.d.ts +18 -6
  13. package/dist/browser/index.d.ts.map +1 -1
  14. package/dist/browser/index.js +64 -29
  15. package/dist/browser/popup.d.ts +6 -1
  16. package/dist/browser/popup.d.ts.map +1 -1
  17. package/dist/browser/popup.js +37 -8
  18. package/dist/cli/index.d.ts +4 -2
  19. package/dist/cli/index.d.ts.map +1 -1
  20. package/dist/cli/index.js +10 -3
  21. package/dist/cli/server.d.ts +5 -0
  22. package/dist/cli/server.d.ts.map +1 -1
  23. package/dist/cli/server.js +5 -0
  24. package/dist/client.d.ts +66 -19
  25. package/dist/client.d.ts.map +1 -1
  26. package/dist/client.js +125 -74
  27. package/dist/config.d.ts +2 -1
  28. package/dist/config.d.ts.map +1 -1
  29. package/dist/config.js +1 -0
  30. package/dist/credentials.d.ts +58 -4
  31. package/dist/credentials.d.ts.map +1 -1
  32. package/dist/credentials.js +0 -0
  33. package/dist/errors.d.ts +23 -21
  34. package/dist/errors.d.ts.map +1 -1
  35. package/dist/errors.js +18 -20
  36. package/dist/globals.d.ts +25 -0
  37. package/dist/globals.d.ts.map +1 -0
  38. package/dist/globals.js +15 -0
  39. package/dist/grants-api.d.ts +34 -0
  40. package/dist/grants-api.d.ts.map +1 -0
  41. package/dist/grants-api.js +48 -0
  42. package/dist/grants.d.ts +16 -0
  43. package/dist/grants.d.ts.map +1 -0
  44. package/dist/grants.js +13 -0
  45. package/dist/index.d.ts +12 -6
  46. package/dist/index.d.ts.map +1 -1
  47. package/dist/index.js +8 -2
  48. package/dist/inflight.d.ts +31 -0
  49. package/dist/inflight.d.ts.map +1 -0
  50. package/dist/inflight.js +26 -0
  51. package/dist/intents.d.ts +386 -40
  52. package/dist/intents.d.ts.map +1 -1
  53. package/dist/intents.js +712 -53
  54. package/dist/oauth.d.ts +55 -6
  55. package/dist/oauth.d.ts.map +1 -1
  56. package/dist/oauth.js +86 -57
  57. package/dist/presenter.d.ts +59 -11
  58. package/dist/presenter.d.ts.map +1 -1
  59. package/dist/presenter.js +40 -1
  60. package/dist/resource.d.ts +109 -0
  61. package/dist/resource.d.ts.map +1 -0
  62. package/dist/resource.js +151 -0
  63. package/dist/rest.d.ts +23 -4
  64. package/dist/rest.d.ts.map +1 -1
  65. package/dist/rest.js +46 -5
  66. package/dist/server/index.d.ts +3 -0
  67. package/dist/server/index.d.ts.map +1 -1
  68. package/dist/server/index.js +1 -0
  69. package/dist/server-metadata.generated.d.ts.map +1 -1
  70. package/dist/server-metadata.generated.js +8 -4
  71. package/dist/service.d.ts +109 -0
  72. package/dist/service.d.ts.map +1 -0
  73. package/dist/service.js +241 -0
  74. package/dist/session-store.d.ts +12 -4
  75. package/dist/session-store.d.ts.map +1 -1
  76. package/dist/session-store.js +64 -14
  77. package/dist/storage.d.ts +16 -23
  78. package/dist/storage.d.ts.map +1 -1
  79. package/dist/storage.js +27 -25
  80. package/dist/tokens.d.ts +46 -0
  81. package/dist/tokens.d.ts.map +1 -0
  82. package/dist/tokens.js +148 -0
  83. package/package.json +13 -3
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,UAAU,EACf,KAAK,cAAc,EAEpB,MAAM,iBAAiB,CAAC;AAGzB,wDAAwD;AACxD,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC;AA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AAE,MAAM,GAAG,OAAO;IAIjD,kGAAkG;IAC3F,MAAM,IAAI,gBAAgB;CAelC;AAED,mGAAmG;AACnG,wBAAgB,UAAU,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAQ5C"}
package/dist/config.js CHANGED
@@ -83,6 +83,7 @@ export class AndcoConfig {
83
83
  allowsPopupOrigin(origin) {
84
84
  return this.allowedPopupOrigins.has(origin);
85
85
  }
86
+ /** Serializes configuration to constructor input without credentials or runtime collaborators. */
86
87
  toJSON() {
87
88
  return {
88
89
  clientId: this.clientId,
@@ -1,9 +1,37 @@
1
+ import type { AndcoConfig } from "./config.js";
2
+ import type { GrantReference } from "./grants.js";
1
3
  /** The authenticated subject of a session, as far as the SDK is concerned. */
2
4
  export type AndcoUser = {
3
5
  id: string;
4
6
  name: string | null;
5
7
  email: string | null;
6
8
  avatarUrl: string | null;
9
+ /**
10
+ * Whether the Authorization Server has verified the email address.
11
+ *
12
+ * `true` and `false` are both affirmative claims the server made; `null` means the server said
13
+ * nothing about it. Absence must never be treated as verified, which is why this is required
14
+ * rather than optional: every constructor of an `AndcoUser` must say what it knows, instead of
15
+ * silently forgetting to say anything.
16
+ */
17
+ emailVerified: boolean | null;
18
+ /**
19
+ * The Profile's phone number, as UserInfo's `phone` claim carries it. `null` unless the `phone`
20
+ * scope was granted and the Profile has a number on file.
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * await andco.auth.signIn({ scopes: ["openid", "phone"] });
25
+ * andco.session.getSnapshot()?.user.phone; // "+56999999999"
26
+ * ```
27
+ */
28
+ phone: string | null;
29
+ /**
30
+ * `true` when the Authorization Server confirmed the phone number; `null` when it said nothing,
31
+ * which includes a number not yet confirmed and a session without the `phone` scope. Like
32
+ * `emailVerified`, absence never means verified.
33
+ */
34
+ phoneVerified: boolean | null;
7
35
  };
8
36
  /**
9
37
  * One set of credentials issued by Andco.
@@ -23,12 +51,23 @@ export type AndcoSession = {
23
51
  /** Access tokens keyed by exact Resource Indicator URI. Absent means `accessToken` serves all. */
24
52
  resourceAccessTokens?: Readonly<Record<string, string>>;
25
53
  };
54
+ /**
55
+ * Per-request authorization controls a transport hands to the credentials.
56
+ *
57
+ * Only an explicit `grant` exists: the Authorization Server selects the Grant from the client,
58
+ * the subject and the resource, so the SDK never inspects request paths or bodies to guess it.
59
+ */
60
+ export type AndcoCredentialRequest = {
61
+ /** Exact Grant to use for this request instead of the server's selection. */
62
+ readonly grant?: GrantReference;
63
+ };
26
64
  /**
27
65
  * The entire contract the Andco core knows about authorization.
28
66
  *
29
- * Keeping it to one resource-keyed method is what lets an application go on owning its sessions:
67
+ * Keeping one required resource-keyed method lets an application go on owning its sessions:
30
68
  * a Better Auth account, a Passport session, a row in your own table, or a plain closure all
31
- * satisfy it without adopting the SDK's persistence.
69
+ * satisfy it without adopting the SDK's persistence. Service credentials also receive the explicit
70
+ * `grant` control and may provide request-local authority through `forOperation()`.
32
71
  *
33
72
  * @example
34
73
  * ```ts
@@ -38,8 +77,23 @@ export type AndcoSession = {
38
77
  * ```
39
78
  */
40
79
  export interface AndcoCredentials {
41
- /** Resolves a token for one Resource Indicator, refreshing lazily when the current one is stale. */
42
- accessTokenFor(resource: string): Promise<string | null>;
80
+ /** Resolves a token for one audience, refreshing or reauthenticating lazily. */
81
+ accessTokenFor(resource: string, request?: AndcoCredentialRequest): Promise<string | null>;
82
+ /** Isolates and pins one operation's authority across pages, polling and retries. */
83
+ forOperation?(): AndcoCredentials;
84
+ /**
85
+ * The configuration of the client that issued these credentials, when there is one.
86
+ *
87
+ * `andco.with()`, `andco.authorized()` and `service.credentials()` carry it, so a Resource Server
88
+ * Definition bound to them reads the OAuth `client_id` and API endpoint from here instead of
89
+ * asking for them a second time. A hand-written resolver may omit it.
90
+ *
91
+ * @example
92
+ * ```ts
93
+ * const bank = new Bank(andco.with(accessToken)); // clientId and endpoint come from andco.config
94
+ * ```
95
+ */
96
+ readonly config?: AndcoConfig;
43
97
  }
44
98
  /** Seconds of remaining lifetime under which a token is treated as stale and refreshed. */
45
99
  export declare const ANDCO_REFRESH_SKEW_SECONDS = 30;
@@ -1 +1 @@
1
- {"version":3,"file":"credentials.d.ts","sourceRoot":"","sources":["../src/credentials.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,MAAM,MAAM,SAAS,GAAG;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,uDAAuD;IACvD,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1B,IAAI,EAAE,SAAS,CAAC;IAChB,kGAAkG;IAClG,oBAAoB,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACzD,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,gBAAgB;IAC/B,oGAAoG;IACpG,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;CAC1D;AAED,2FAA2F;AAC3F,eAAO,MAAM,0BAA0B,KAAK,CAAC;AAE7C,4EAA4E;AAC5E,wBAAgB,SAAS,CAAC,OAAO,EAAE,YAAY,EAAE,UAAU,SAAgC,GAAG,OAAO,CAEpG;AAED,sFAAsF;AACtF,wBAAgB,QAAQ,CAAC,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAY/E;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,YAAY,GAAG,g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AsB,GAAG;IACnC,6EAA6E;IAC7E,QAAQ,CAAC,KAAK,CAAC,EAAE,cAAc,CAAC;CACjC,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,MAAM,WAAW,gBAAgB;IAC/B,gFAAgF;IAChF,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,sBAAsB,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAC3F,qFAAqF;IACrF,YAAY,CAAC,IAAI,gBAAgB,CAAC;IAClC;;;;;;;;;;;OAWG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;CAC/B;AAED,2FAA2F;AAC3F,eAAO,MAAM,0BAA0B,KAAK,CAAC;AAE7C,4EAA4E;AAC5E,wBAAgB,SAAS,CAAC,OAAO,EAAE,YAAY,EAAE,UAAU,SAAgC,GAAG,OAAO,CAEpG;AAED,sFAAsF;AACtF,wBAAgB,QAAQ,CAAC,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAY/E;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,YAAY,GAAG,gBAAgB,CAE9E;AAED,iEAAiE;AACjE,wBAAgB,aAAa,CAAC,KAAK,EAAE,gBAAgB,GAAG,YAAY,GAAG,KAAK,IAAI,gBAAgB,CAE/F;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAWnF"}
Binary file
package/dist/errors.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { type AndcoErrorCode } from "@andco/protocol";
1
2
  /**
2
3
  * The single error type every Andco operation reports.
3
4
  *
@@ -34,7 +35,7 @@ export declare class AndcoError extends Error {
34
35
  details?: Readonly<Record<string, unknown>>;
35
36
  });
36
37
  /** Normalizes anything thrown by a dependency into an `AndcoError`. */
37
- static from(cause: unknown, fallbackCode: string): AndcoError;
38
+ static from(cause: unknown, fallbackCode: SdkErrorCode): AndcoError;
38
39
  /** Whether a value is an `AndcoError`. */
39
40
  static is(cause: unknown): cause is AndcoError;
40
41
  }
@@ -137,29 +138,30 @@ export declare const Result: {
137
138
  /** Wraps a value as a successful result. */
138
139
  ok<T>(data: T): Result<T>;
139
140
  /** Wraps a failure as a result, accepting either a code or an existing error. */
140
- fail<T = never>(error: AndcoError | string, options?: {
141
+ fail<T = never>(error: AndcoError | SdkErrorCode, options?: {
141
142
  message?: string;
142
143
  status?: number;
143
144
  cause?: unknown;
144
145
  }): Result<T>;
145
146
  };
146
- /** Error codes the SDK itself raises, as opposed to those relayed from the Authorization Server. */
147
- export declare const ANDCO_ERROR_CODES: {
148
- readonly BROWSER_REQUIRED: "browser_required";
149
- readonly BROWSER_UNAVAILABLE: "browser_unavailable";
150
- readonly BROWSER_FORBIDDEN: "browser_forbidden";
151
- readonly INVALID_CALLBACK: "invalid_callback";
152
- readonly INVALID_CONFIGURATION: "invalid_configuration";
153
- readonly HANDSHAKE_TIMEOUT: "handshake_timeout";
154
- readonly INVALID_IFRAME: "invalid_iframe";
155
- readonly INVALID_INTENT_ID: "invalid_intent_id";
156
- readonly INVALID_RESPONSE: "invalid_response";
157
- readonly POPUP_BLOCKED: "popup_blocked";
158
- readonly POPUP_TIMEOUT: "popup_timeout";
159
- readonly PRESENTATION_UNSUPPORTED: "presentation_unsupported";
160
- readonly SAME_ORIGIN_ENDPOINT: "same_origin_endpoint";
161
- readonly SESSION_MISSING: "session_missing";
162
- readonly STORAGE_FAILED: "storage_failed";
163
- readonly UNTRUSTED_ORIGIN: "untrusted_origin";
164
- };
147
+ /**
148
+ * Re-exported so `@andco/sdk` consumers reach the one vocabulary without importing `@andco/protocol`
149
+ * directly. It used to be a second catalogue declared here, with the same public name as the one in
150
+ * protocol and different values for the eight conditions both named -- a comparison against the
151
+ * wrong import never matched, and nothing said which was which.
152
+ */
153
+ export { ANDCO_ERROR_CODES, type AndcoErrorCode } from "@andco/protocol";
154
+ /**
155
+ * The vocabulary of codes the SDK may write to `AndcoError.code` on its own initiative — every
156
+ * member of {@link ANDCO_ERROR_CODES}, derived rather than duplicated.
157
+ *
158
+ * This closes the entry points the SDK alone uses to raise its own errors — `AndcoError.from`'s
159
+ * `fallbackCode` and `Result.fail`'s string shorthand — so a typo or an ad hoc string can no longer
160
+ * slip in unnoticed. It does not close `AndcoError.code` itself, nor the `AndcoError` constructor:
161
+ * both must keep accepting a plain `string`, because `AndcoError` is the one error type every Andco
162
+ * operation reports, including codes this repository does not own — the Authorization Server's own
163
+ * OAuth error identifiers (RFC 6749) foremost among them — and integrators are expected to construct
164
+ * one directly for their own domain errors, as `apps/example-oauth-nextjs` already does.
165
+ */
166
+ export type SdkErrorCode = AndcoErrorCode;
165
167
  //# sourceMappingURL=errors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,UAAW,SAAQ,KAAK;IACnC,6DAA6D;IAC7D,SAAgB,IAAI,EAAE,MAAM,CAAC;IAC7B,uDAAuD;IACvD,SAAgB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3C;;;;;;OAMG;IACH,SAAgB,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;gBAGrE,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,CAAC;QAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;KAAO;IASnH,uEAAuE;WACzD,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAA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OAAO,EAAE,iBAAiB,EAAE,KAAK,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEzE;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,YAAY,GAAG,cAAc,CAAC"}
package/dist/errors.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { ANDCO_ERROR_CODES } from "@andco/protocol";
1
2
  /**
2
3
  * The single error type every Andco operation reports.
3
4
  *
@@ -93,6 +94,15 @@ export class AndcoAPIError extends AndcoError {
93
94
  * ```
94
95
  */
95
96
  static fromOpenAPIFetch(payload, response) {
97
+ if (payload instanceof AndcoError) {
98
+ return new AndcoAPIError(payload.code, {
99
+ response,
100
+ status: payload.status,
101
+ message: payload.message,
102
+ details: payload.details,
103
+ cause: payload,
104
+ });
105
+ }
96
106
  const { message, details } = AndcoAPIError.bodyOf(payload);
97
107
  const error = new AndcoAPIError(AndcoAPIError.codeOf(payload), {
98
108
  response,
@@ -132,7 +142,7 @@ export class AndcoAPIError extends AndcoError {
132
142
  return error;
133
143
  }
134
144
  }
135
- return "request_failed";
145
+ return ANDCO_ERROR_CODES.REQUEST_FAILED;
136
146
  }
137
147
  /** Keeps the rest of the error body, and promotes `message` so it reaches `error.message`. */
138
148
  static bodyOf(payload) {
@@ -176,22 +186,10 @@ export const Result = {
176
186
  return { data: null, error: typeof error === "string" ? new AndcoError(error, options) : error };
177
187
  },
178
188
  };
179
- /** Error codes the SDK itself raises, as opposed to those relayed from the Authorization Server. */
180
- export const ANDCO_ERROR_CODES = {
181
- BROWSER_REQUIRED: "browser_required",
182
- BROWSER_UNAVAILABLE: "browser_unavailable",
183
- BROWSER_FORBIDDEN: "browser_forbidden",
184
- INVALID_CALLBACK: "invalid_callback",
185
- INVALID_CONFIGURATION: "invalid_configuration",
186
- HANDSHAKE_TIMEOUT: "handshake_timeout",
187
- INVALID_IFRAME: "invalid_iframe",
188
- INVALID_INTENT_ID: "invalid_intent_id",
189
- INVALID_RESPONSE: "invalid_response",
190
- POPUP_BLOCKED: "popup_blocked",
191
- POPUP_TIMEOUT: "popup_timeout",
192
- PRESENTATION_UNSUPPORTED: "presentation_unsupported",
193
- SAME_ORIGIN_ENDPOINT: "same_origin_endpoint",
194
- SESSION_MISSING: "session_missing",
195
- STORAGE_FAILED: "storage_failed",
196
- UNTRUSTED_ORIGIN: "untrusted_origin",
197
- };
189
+ /**
190
+ * Re-exported so `@andco/sdk` consumers reach the one vocabulary without importing `@andco/protocol`
191
+ * directly. It used to be a second catalogue declared here, with the same public name as the one in
192
+ * protocol and different values for the eight conditions both named -- a comparison against the
193
+ * wrong import never matched, and nothing said which was which.
194
+ */
195
+ export { ANDCO_ERROR_CODES } from "@andco/protocol";
@@ -0,0 +1,25 @@
1
+ import type { AndCoRandomSource } from "@andco/protocol";
2
+ /**
3
+ * Platform capabilities the SDK reads off the runtime, grouped so a future addition is not a
4
+ * breaking change.
5
+ *
6
+ * Every collaborator takes the whole group rather than the one capability it happens to use today,
7
+ * which is what makes that promise real: adding a capability here reaches `rest`, `oauth`, `auth`,
8
+ * and `intents` without touching a single constructor signature.
9
+ */
10
+ export type AndcoGlobals = {
11
+ fetch: typeof globalThis.fetch;
12
+ /** Threaded into the Protocol Contract's `RANDOM_UUID`, so a runtime without Web Crypto can supply its own. */
13
+ crypto: AndCoRandomSource;
14
+ };
15
+ /**
16
+ * Fills a partial runtime out with the platform's own, so a collaborator always receives a resolved
17
+ * group and never has to know what the default for a missing capability is.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * const rest = new AndcoRest({ config, credentials, globals: resolveGlobals({ fetch: tracedFetch }) });
22
+ * ```
23
+ */
24
+ export declare function resolveGlobals(globals?: Partial<AndcoGlobals>): AndcoGlobals;
25
+ //# sourceMappingURL=globals.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"globals.d.ts","sourceRoot":"","sources":["../src/globals.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEzD;;;;;;;GAOG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,KAAK,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IAC/B,+GAA+G;IAC/G,MAAM,EAAE,iBAAiB,CAAC;CAC3B,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,OAAO,GAAE,OAAO,CAAC,YAAY,CAAM,GAAG,YAAY,CAKhF"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Fills a partial runtime out with the platform's own, so a collaborator always receives a resolved
3
+ * group and never has to know what the default for a missing capability is.
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * const rest = new AndcoRest({ config, credentials, globals: resolveGlobals({ fetch: tracedFetch }) });
8
+ * ```
9
+ */
10
+ export function resolveGlobals(globals = {}) {
11
+ return {
12
+ fetch: globals.fetch ?? globalThis.fetch.bind(globalThis),
13
+ crypto: globals.crypto ?? globalThis.crypto,
14
+ };
15
+ }
@@ -0,0 +1,34 @@
1
+ import type { AndCoRestPaths } from "@andco/protocol/transport";
2
+ import type { AndcoConfig } from "./config.js";
3
+ import { Result } from "./errors.js";
4
+ import type { AndcoGlobals } from "./globals.js";
5
+ /** The live Grant a bearer token carries, as `GET /authorization` reports it. */
6
+ export type AndcoGrantAuthorization = AndCoRestPaths["/authorization"]["get"]["responses"][200]["content"]["application/json"];
7
+ /**
8
+ * Looks up the live Grant behind a token.
9
+ *
10
+ * A token proves who signed it; only the Authorization Server knows whether the Grant is still
11
+ * active and which RAR details were consented. This is what a Resource Server calls when scopes in
12
+ * the token are not enough.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * const { data: grant, error } = await andco.grants.get(accessToken);
17
+ * const orders = grant?.authorizationDetails.find((detail) => detail.type === "orders");
18
+ * ```
19
+ */
20
+ export declare class AndcoGrants {
21
+ #private;
22
+ constructor(options: {
23
+ config: AndcoConfig;
24
+ globals: AndcoGlobals;
25
+ });
26
+ /**
27
+ * Fetches the Grant carried by a bearer token with `GET /authorization`.
28
+ *
29
+ * Only the token overload exists: the API has no endpoint that reads a Grant by id, so a Grant id
30
+ * fails with `not_implemented` instead of guessing one.
31
+ */
32
+ get(token: string): Promise<Result<AndcoGrantAuthorization>>;
33
+ }
34
+ //# sourceMappingURL=grants-api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grants-api.d.ts","sourceRoot":"","sources":["../src/grants-api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAc,MAAM,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAGjD,iFAAiF;AACjF,MAAM,MAAM,uBAAuB,GACjC,cAAc,CAAC,gBAAgB,CAAC,CAAC,KAAK,CAAC,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,kBAAkB,CAAC,CAAC;AAI3F;;;;;;;;;;;;GAYG;AACH,qBAAa,WAAW;;gBAIH,OAAO,EAAE;QAAE,MAAM,EAAE,WAAW,CAAC;QAAC,OAAO,EAAE,YAAY,CAAA;KAAE;IAK1E;;;;;OAKG;IACU,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,uBAAuB,CAAC,CAAC;CAoB1E"}
@@ -0,0 +1,48 @@
1
+ import { AndcoError, Result } from "./errors.js";
2
+ import { AndcoRest } from "./rest.js";
3
+ const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
4
+ /**
5
+ * Looks up the live Grant behind a token.
6
+ *
7
+ * A token proves who signed it; only the Authorization Server knows whether the Grant is still
8
+ * active and which RAR details were consented. This is what a Resource Server calls when scopes in
9
+ * the token are not enough.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * const { data: grant, error } = await andco.grants.get(accessToken);
14
+ * const orders = grant?.authorizationDetails.find((detail) => detail.type === "orders");
15
+ * ```
16
+ */
17
+ export class AndcoGrants {
18
+ #config;
19
+ #globals;
20
+ constructor(options) {
21
+ this.#config = options.config;
22
+ this.#globals = options.globals;
23
+ }
24
+ /**
25
+ * Fetches the Grant carried by a bearer token with `GET /authorization`.
26
+ *
27
+ * Only the token overload exists: the API has no endpoint that reads a Grant by id, so a Grant id
28
+ * fails with `not_implemented` instead of guessing one.
29
+ */
30
+ async get(token) {
31
+ if (UUID.test(token)) {
32
+ console.debug("[grants.get] a grant id was given, but no endpoint reads a Grant by id");
33
+ return Result.fail(new AndcoError("not_implemented", { message: "Grants can only be read with the token that carries them" }));
34
+ }
35
+ const rest = new AndcoRest({
36
+ config: this.#config,
37
+ globals: this.#globals,
38
+ credentials: { accessTokenFor: async () => token },
39
+ });
40
+ const { data, error } = await rest.http.GET("/authorization");
41
+ if (error || !data) {
42
+ console.debug("[grants.get] lookup failed status=%s code=%s", error?.status, error?.code);
43
+ return Result.fail(error ?? new AndcoError("invalid_response"));
44
+ }
45
+ console.debug("[grants.get] grant %s active=%s", data.grantId, data.active);
46
+ return Result.ok(data);
47
+ }
48
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Metadata of a Grant an Organization approved for a Service; never a bearer credential or proof
3
+ * of live consent. `service.listGrants()` returns these.
4
+ */
5
+ export type Grant = import("@andco/protocol").ServiceGrant;
6
+ /** A Grant or its id, for the explicit `grant` override. */
7
+ export type GrantReference = string | Grant;
8
+ /**
9
+ * Reads the id of a Grant reference, refusing anything that is not a UUID.
10
+ *
11
+ * @example
12
+ * grantId("0190f3a2-6f1c-7c4e-9a51-3b2d1e0f4a5b"); // the same string
13
+ * grantId(grant); // grant.id
14
+ */
15
+ export declare function grantId(grant: GrantReference): string;
16
+ //# sourceMappingURL=grants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grants.d.ts","sourceRoot":"","sources":["../src/grants.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,MAAM,KAAK,GAAG,OAAO,iBAAiB,EAAE,YAAY,CAAC;AAC3D,4DAA4D;AAC5D,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,KAAK,CAAC;AAE5C;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,cAAc,GAAG,MAAM,CAKrD"}
package/dist/grants.js ADDED
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Reads the id of a Grant reference, refusing anything that is not a UUID.
3
+ *
4
+ * @example
5
+ * grantId("0190f3a2-6f1c-7c4e-9a51-3b2d1e0f4a5b"); // the same string
6
+ * grantId(grant); // grant.id
7
+ */
8
+ export function grantId(grant) {
9
+ const id = typeof grant === "string" ? grant : grant.id;
10
+ if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(id))
11
+ throw new TypeError("Grant ID must be a UUID");
12
+ return id;
13
+ }
package/dist/index.d.ts CHANGED
@@ -1,13 +1,19 @@
1
1
  export { RANDOM_UUID } from "@andco/protocol";
2
2
  export { AndcoAuth, type AndcoAuthOptions, type AndcoSignInOptions } from "./auth.js";
3
- export { AndcoClient, type AndcoClientAuthed, type AndcoClientOptions, type AndcoGlobals, type AndcoResourceServer, } from "./client.js";
3
+ export { AndcoClient, type AndcoClientAuthed, type AndcoClientOptions, type AndcoResourceServer } from "./client.js";
4
4
  export { AndcoConfig, type AndcoConfigInput, type AndcoScope, type AndcoTheme, isLoopback, } from "./config.js";
5
- export { ANDCO_REFRESH_SKEW_SECONDS, type AndcoCredentials, type AndcoSession, type AndcoUser, credentialsFromSession, isCredentials, isExpired, sessionIdentityKey, tokenFor, } from "./credentials.js";
5
+ export { ANDCO_REFRESH_SKEW_SECONDS, type AndcoCredentialRequest, type AndcoCredentials, type AndcoSession, type AndcoUser, credentialsFromSession, isCredentials, isExpired, sessionIdentityKey, tokenFor, } from "./credentials.js";
6
6
  export { ANDCO_ERROR_CODES, AndcoAPIError, AndcoError, Result } from "./errors.js";
7
- export { type AndcoEventPage, type AndcoEventSubscriptionOptions, type AndcoFinancialEvent, type AndcoIntent, type AndcoIntentCreateOptions, type AndcoIntentId, AndcoIntents, } from "./intents.js";
7
+ export { type AndcoGlobals, resolveGlobals } from "./globals.js";
8
+ export type { Grant, GrantReference } from "./grants.js";
9
+ export { type AndcoGrantAuthorization, AndcoGrants } from "./grants-api.js";
10
+ export { type AndcoInflight, MemoryInflight } from "./inflight.js";
11
+ export { type AndcoEventPage, type AndcoEventSubscriptionOptions, type AndcoFinancialEvent, type AndcoIntent, type AndcoIntentApproveOptions, type AndcoIntentCancelOptions, type AndcoIntentCreateOptions, type AndcoIntentId, type AndcoIntentPresentationController, type AndcoIntentPresentationStatus, type AndcoIntentPresentOptions, type AndcoIntentPresentSource, type AndcoIntentReference, type AndcoIntentRejectOptions, type AndcoIntentSubscribeOptions, AndcoIntents, type AndcoIntentsOptions, type AndcoIntentURLOptions, type AndcoIntentWatch, type AndcoIntentWatchOptions, type AndcoIntentWatchStatus, type AndcoPresentationResult, type AndcoPresentationStorage, } from "./intents.js";
8
12
  export { type AndcoAuthorizationDetail, type AndcoAuthorizationOptions, type AndcoAuthorizationRequest, type AndcoDeviceAuthorization, AndcoOAuth, type AndcoOAuthOptions, type AndcoResourceAuthorization, type AndcoTransportMode, } from "./oauth.js";
9
- export type { AndcoPresentation, AndcoPresenter, AndcoPresentOptions } from "./presenter.js";
10
- export { type AndcoHttpClient, type AndcoPageOptions, type AndcoRequestOptions, AndcoRest, type AndcoRestOptions, } from "./rest.js";
13
+ export { type AndcoIntentPresentation, type AndcoPresentation, AndcoPresenter, type AndcoPresentIntent, type AndcoPresentOAuth, type AndcoPresentOptions, type AndcoPresentTarget, } from "./presenter.js";
14
+ export { type AndcoDetailRequirement, type AndcoProtection, type AndcoProtectOptions, type AndcoProtectOutcome, AndcoResource, } from "./resource.js";
15
+ export { type AndcoGrantOptions, type AndcoHttpClient, type AndcoPageOptions, type AndcoRequestOptions, AndcoRest, type AndcoRestOptions, } from "./rest.js";
11
16
  export { type AndcoSessionSource, AndcoSessionStore, type AndcoSessionStoreOptions } from "./session-store.js";
12
- export { type AndcoLock, type AndcoStorage, InProcessLock, MemoryStorage, WebStorage, } from "./storage.js";
17
+ export { type AndcoStorage, LocalStorage, MemoryStorage, SessionStorage, } from "./storage.js";
18
+ export { type AndcoTokenClaims, AndcoTokens, type AndcoTokenVerifyOptions, } from "./tokens.js";
13
19
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,KAAK,gBAAgB,EAAE,KAAK,kBAAkB,EAAE,MAAM,WAAW,CAAC;AACtF,OAAO,EACL,WAAW,EACX,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,KAAK,YAAY,EACjB,KAAK,mBAAmB,GACzB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,WAAW,EACX,KAAK,gBAAgB,EACrB,KAAK,UAAU,EACf,KAAK,UAAU,EACf,UAAU,GACX,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,0BAA0B,EAC1B,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,KAAK,SAAS,EACd,sBAAsB,EACtB,aAAa,EACb,SAAS,EACT,kBAAkB,EAClB,QAAQ,GACT,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACnF,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,6BAA6B,EAClC,KAAK,mBAAmB,EACxB,KAAK,WAAW,EAChB,KAAK,wBAAwB,EAC7B,KAAK,aAAa,EAClB,YAAY,GACb,MAAM,cAAc,CAAC;A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BAAsB,EAC3B,KAAK,eAAe,EACpB,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,aAAa,GACd,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EACxB,SAAS,EACT,KAAK,gBAAgB,GACtB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,KAAK,kBAAkB,EAAE,iBAAiB,EAAE,KAAK,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAC/G,OAAO,EACL,KAAK,YAAY,EACjB,YAAY,EACZ,aAAa,EACb,cAAc,GACf,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,KAAK,gBAAgB,EACrB,WAAW,EACX,KAAK,uBAAuB,GAC7B,MAAM,aAAa,CAAC"}
package/dist/index.js CHANGED
@@ -1,11 +1,17 @@
1
1
  export { RANDOM_UUID } from "@andco/protocol";
2
2
  export { AndcoAuth } from "./auth.js";
3
- export { AndcoClient, } from "./client.js";
3
+ export { AndcoClient } from "./client.js";
4
4
  export { AndcoConfig, isLoopback, } from "./config.js";
5
5
  export { ANDCO_REFRESH_SKEW_SECONDS, credentialsFromSession, isCredentials, isExpired, sessionIdentityKey, tokenFor, } from "./credentials.js";
6
6
  export { ANDCO_ERROR_CODES, AndcoAPIError, AndcoError, Result } from "./errors.js";
7
+ export { resolveGlobals } from "./globals.js";
8
+ export { AndcoGrants } from "./grants-api.js";
9
+ export { MemoryInflight } from "./inflight.js";
7
10
  export { AndcoIntents, } from "./intents.js";
8
11
  export { AndcoOAuth, } from "./oauth.js";
12
+ export { AndcoPresenter, } from "./presenter.js";
13
+ export { AndcoResource, } from "./resource.js";
9
14
  export { AndcoRest, } from "./rest.js";
10
15
  export { AndcoSessionStore } from "./session-store.js";
11
- export { InProcessLock, MemoryStorage, WebStorage, } from "./storage.js";
16
+ export { LocalStorage, MemoryStorage, SessionStorage, } from "./storage.js";
17
+ export { AndcoTokens, } from "./tokens.js";
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Shares one running operation among every caller that asks for the same key.
3
+ *
4
+ * The first caller for a key starts the operation; callers arriving while it runs receive the same
5
+ * promise instead of starting another. Whatever the operation settles with, resolution or
6
+ * rejection, reaches every waiter, and the key is cleared so the next call starts fresh.
7
+ *
8
+ * Unlike a lock this never queues: N concurrent refreshes cost one token request, not N in a row.
9
+ * The default shares within one runtime only. Supply your own to share across processes, for
10
+ * example by claiming the key in a store that every instance reads.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * const inflight: AndcoInflight = {
15
+ * run: (key, operation) => coordinator.singleFlight(`andco:${key}`, operation),
16
+ * };
17
+ * ```
18
+ */
19
+ export interface AndcoInflight {
20
+ run<T>(key: string, operation: () => Promise<T>): Promise<T>;
21
+ }
22
+ /**
23
+ * Shares in-flight operations within one runtime, as DataLoader's promise cache does: the promise
24
+ * is stored on start and deleted on settle, so nothing is cached beyond the operation's lifetime.
25
+ * The default.
26
+ */
27
+ export declare class MemoryInflight implements AndcoInflight {
28
+ #private;
29
+ run<T>(key: string, operation: () => Promise<T>): Promise<T>;
30
+ }
31
+ //# sourceMappingURL=inflight.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inflight.d.ts","sourceRoot":"","sources":["../src/inflight.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,WAAW,aAAa;IAC5B,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CAC9D;AAED;;;;GAIG;AACH,qBAAa,cAAe,YAAW,aAAa;;IAG3C,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;CAqBpE"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Shares in-flight operations within one runtime, as DataLoader's promise cache does: the promise
3
+ * is stored on start and deleted on settle, so nothing is cached beyond the operation's lifetime.
4
+ * The default.
5
+ */
6
+ export class MemoryInflight {
7
+ #running = new Map();
8
+ run(key, operation) {
9
+ const shared = this.#running.get(key);
10
+ if (shared) {
11
+ console.debug("[AndcoInflight] sharing the running operation for %s", key);
12
+ return shared;
13
+ }
14
+ console.debug("[AndcoInflight] starting %s", key);
15
+ // Wrapped so a synchronous throw becomes a rejection that is also cleared on settle.
16
+ const started = (async () => operation())();
17
+ this.#running.set(key, started);
18
+ const settle = (outcome) => {
19
+ if (this.#running.get(key) === started)
20
+ this.#running.delete(key);
21
+ console.debug("[AndcoInflight] %s %s", outcome, key);
22
+ };
23
+ started.then(() => settle("settled"), () => settle("failed"));
24
+ return started;
25
+ }
26
+ }