@andco/sdk 0.0.3 → 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.
- package/LICENSE +1 -1
- package/README.md +93 -49
- package/dist/auth.d.ts +5 -3
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +10 -17
- package/dist/browser/controller.d.ts +46 -0
- package/dist/browser/controller.d.ts.map +1 -1
- package/dist/browser/controller.js +102 -12
- package/dist/browser/frame.d.ts.map +1 -1
- package/dist/browser/frame.js +6 -15
- package/dist/browser/index.d.ts +8 -2
- package/dist/browser/index.d.ts.map +1 -1
- package/dist/browser/index.js +48 -33
- package/dist/browser/popup.d.ts +4 -0
- package/dist/browser/popup.d.ts.map +1 -1
- package/dist/browser/popup.js +23 -7
- package/dist/cli/index.d.ts +4 -6
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +7 -13
- package/dist/cli/server.d.ts +5 -0
- package/dist/cli/server.d.ts.map +1 -1
- package/dist/cli/server.js +5 -0
- package/dist/client.d.ts +66 -19
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +117 -78
- package/dist/config.d.ts +2 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +1 -0
- package/dist/credentials.d.ts +58 -4
- package/dist/credentials.d.ts.map +1 -1
- package/dist/credentials.js +0 -0
- package/dist/errors.d.ts +23 -21
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +18 -20
- package/dist/globals.d.ts +25 -0
- package/dist/globals.d.ts.map +1 -0
- package/dist/globals.js +15 -0
- package/dist/grants-api.d.ts +34 -0
- package/dist/grants-api.d.ts.map +1 -0
- package/dist/grants-api.js +48 -0
- package/dist/grants.d.ts +16 -0
- package/dist/grants.d.ts.map +1 -0
- package/dist/grants.js +13 -0
- package/dist/index.d.ts +12 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -3
- package/dist/inflight.d.ts +31 -0
- package/dist/inflight.d.ts.map +1 -0
- package/dist/inflight.js +26 -0
- package/dist/intents.d.ts +346 -70
- package/dist/intents.d.ts.map +1 -1
- package/dist/intents.js +629 -112
- package/dist/oauth.d.ts +55 -6
- package/dist/oauth.d.ts.map +1 -1
- package/dist/oauth.js +86 -57
- package/dist/presenter.d.ts +25 -11
- package/dist/presenter.d.ts.map +1 -1
- package/dist/presenter.js +39 -6
- package/dist/resource.d.ts +109 -0
- package/dist/resource.d.ts.map +1 -0
- package/dist/resource.js +151 -0
- package/dist/rest.d.ts +23 -4
- package/dist/rest.d.ts.map +1 -1
- package/dist/rest.js +46 -5
- package/dist/server/index.d.ts +3 -0
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +1 -0
- package/dist/server-metadata.generated.d.ts.map +1 -1
- package/dist/server-metadata.generated.js +8 -4
- package/dist/service.d.ts +109 -0
- package/dist/service.d.ts.map +1 -0
- package/dist/service.js +241 -0
- package/dist/session-store.d.ts +12 -4
- package/dist/session-store.d.ts.map +1 -1
- package/dist/session-store.js +64 -14
- package/dist/storage.d.ts +16 -23
- package/dist/storage.d.ts.map +1 -1
- package/dist/storage.js +27 -25
- package/dist/tokens.d.ts +46 -0
- package/dist/tokens.d.ts.map +1 -0
- package/dist/tokens.js +148 -0
- package/package.json +13 -3
package/dist/errors.d.ts.map
CHANGED
|
@@ -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,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G;AACH,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
|
|
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
|
-
/**
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
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"}
|
package/dist/globals.js
ADDED
|
@@ -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
|
+
}
|
package/dist/grants.d.ts
ADDED
|
@@ -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
|
|
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
|
|
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
|
|
10
|
-
export { type
|
|
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
|
|
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
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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,
|
|
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,EAAE,WAAW,EAAE,KAAK,iBAAiB,EAAE,KAAK,kBAAkB,EAAE,KAAK,mBAAmB,EAAE,MAAM,aAAa,CAAC;AACrH,OAAO,EACL,WAAW,EACX,KAAK,gBAAgB,EACrB,KAAK,UAAU,EACf,KAAK,UAAU,EACf,UAAU,GACX,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,0BAA0B,EAC1B,KAAK,sBAAsB,EAC3B,KAAK,gBA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EACtB,cAAc,EACd,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,GACxB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,KAAK,sBAAsB,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,12 +1,17 @@
|
|
|
1
1
|
export { RANDOM_UUID } from "@andco/protocol";
|
|
2
2
|
export { AndcoAuth } from "./auth.js";
|
|
3
|
-
export { AndcoClient
|
|
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";
|
|
9
|
-
export {
|
|
12
|
+
export { AndcoPresenter, } from "./presenter.js";
|
|
13
|
+
export { AndcoResource, } from "./resource.js";
|
|
10
14
|
export { AndcoRest, } from "./rest.js";
|
|
11
15
|
export { AndcoSessionStore } from "./session-store.js";
|
|
12
|
-
export {
|
|
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"}
|
package/dist/inflight.js
ADDED
|
@@ -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
|
+
}
|