@andco/protocol 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 +33 -3
- package/dist/api-errors.d.ts +109 -0
- package/dist/api-errors.d.ts.map +1 -0
- package/dist/api-errors.js +111 -0
- package/dist/authorization-preparation.d.ts +52 -543
- package/dist/authorization-preparation.d.ts.map +1 -1
- package/dist/authorization-preparation.js +19 -42
- package/dist/authorization.d.ts +64 -22
- package/dist/authorization.d.ts.map +1 -1
- package/dist/authorization.js +136 -55
- package/dist/consent.d.ts +5 -8
- package/dist/consent.d.ts.map +1 -1
- package/dist/consent.js +5 -62
- package/dist/constants.d.ts +19 -3
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +19 -3
- package/dist/errors.d.ts +156 -58
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +176 -57
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/intent-input.d.ts +1010 -279
- package/dist/intent-input.d.ts.map +1 -1
- package/dist/intent-input.js +268 -40
- package/dist/messages/error.d.ts +1 -2
- package/dist/messages/error.d.ts.map +1 -1
- package/dist/messages/error.js +5 -2
- package/dist/messages/index.d.ts +1 -1
- package/dist/native-copy.d.ts +23 -2
- package/dist/native-copy.d.ts.map +1 -1
- package/dist/native-copy.js +42 -98
- package/dist/native-intent.d.ts +126 -75
- package/dist/native-intent.d.ts.map +1 -1
- package/dist/native-intent.js +140 -48
- package/dist/rar/account-matchers.d.ts +579 -0
- package/dist/rar/account-matchers.d.ts.map +1 -0
- package/dist/rar/account-matchers.js +480 -0
- package/dist/rar/bank.d.ts +1549 -0
- package/dist/rar/bank.d.ts.map +1 -0
- package/dist/rar/bank.js +379 -0
- package/dist/rar/catalog.d.ts +1155 -0
- package/dist/rar/catalog.d.ts.map +1 -0
- package/dist/rar/catalog.js +175 -0
- package/dist/rar/detail.d.ts +39 -0
- package/dist/rar/detail.d.ts.map +1 -0
- package/dist/rar/detail.js +44 -0
- package/dist/rar/index.d.ts +9 -0
- package/dist/rar/index.d.ts.map +1 -0
- package/dist/rar/index.js +8 -0
- package/dist/rar/money.d.ts +58 -0
- package/dist/rar/money.d.ts.map +1 -0
- package/dist/rar/money.js +61 -0
- package/dist/rar/project-users.d.ts +43 -0
- package/dist/rar/project-users.d.ts.map +1 -0
- package/dist/rar/project-users.js +63 -0
- package/dist/rar/subject-data.d.ts +170 -0
- package/dist/rar/subject-data.d.ts.map +1 -0
- package/dist/rar/subject-data.js +127 -0
- package/dist/rar/subject.d.ts +166 -0
- package/dist/rar/subject.d.ts.map +1 -0
- package/dist/rar/subject.js +119 -0
- package/dist/scopes.d.ts +5 -30
- package/dist/scopes.d.ts.map +1 -1
- package/dist/scopes.js +0 -13
- package/dist/service-grants.d.ts +44 -0
- package/dist/service-grants.d.ts.map +1 -0
- package/dist/service-grants.js +45 -0
- package/dist/signing.d.ts +56 -0
- package/dist/signing.d.ts.map +1 -0
- package/dist/signing.js +233 -0
- package/dist/transport/financial-events.d.ts +90 -35
- package/dist/transport/financial-events.d.ts.map +1 -1
- package/dist/transport/financial-events.js +7 -1
- package/dist/transport/generated/oauth-api.d.ts +908 -440
- package/dist/transport/generated/oauth-api.d.ts.map +1 -1
- package/dist/transport/index.d.ts +0 -1
- package/dist/transport/index.d.ts.map +1 -1
- package/dist/transport/index.js +0 -1
- package/dist/transport/intents.d.ts +155 -23
- package/dist/transport/intents.d.ts.map +1 -1
- package/dist/transport/intents.js +192 -59
- package/dist/transport/rest.d.ts +18 -8
- package/dist/transport/rest.d.ts.map +1 -1
- package/dist/transport/rest.js +1 -1
- package/dist/urls.d.ts.map +1 -1
- package/dist/urls.js +1 -1
- package/dist/userinfo.d.ts +10 -1
- package/dist/userinfo.d.ts.map +1 -1
- package/dist/userinfo.js +10 -1
- package/dist/utils.d.ts +15 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +31 -0
- package/dist/webhooks.d.ts +154 -0
- package/dist/webhooks.d.ts.map +1 -0
- package/dist/webhooks.js +249 -0
- package/package.json +18 -1
- package/dist/automatic-charge.d.ts +0 -314
- package/dist/automatic-charge.d.ts.map +0 -1
- package/dist/automatic-charge.js +0 -126
- package/dist/bank-account-authorization.d.ts +0 -6
- package/dist/bank-account-authorization.d.ts.map +0 -1
- package/dist/bank-account-authorization.js +0 -13
- package/dist/transport/webhooks.d.ts +0 -27
- package/dist/transport/webhooks.d.ts.map +0 -1
- package/dist/transport/webhooks.js +0 -68
- package/dist/webhook-input.d.ts +0 -22
- package/dist/webhook-input.d.ts.map +0 -1
- package/dist/webhook-input.js +0 -11
- package/dist/webhook-signature.d.ts +0 -54
- package/dist/webhook-signature.d.ts.map +0 -1
- package/dist/webhook-signature.js +0 -74
package/dist/scopes.js
CHANGED
|
@@ -1,15 +1,2 @@
|
|
|
1
1
|
/** Valid OAuth scope token: printable ASCII except space, double quote, and backslash. */
|
|
2
2
|
export const ANDCO_SCOPE_REGEX = /^[\x21\x23-\x5b\x5d-\x7e]{1,128}$/;
|
|
3
|
-
/** Available modes for starting the authorization flow. */
|
|
4
|
-
export var ANDCO_AUTH_MODES;
|
|
5
|
-
(function (ANDCO_AUTH_MODES) {
|
|
6
|
-
ANDCO_AUTH_MODES["AUTO"] = "auto";
|
|
7
|
-
ANDCO_AUTH_MODES["SIGNUP"] = "signup";
|
|
8
|
-
ANDCO_AUTH_MODES["LOGIN"] = "login";
|
|
9
|
-
})(ANDCO_AUTH_MODES || (ANDCO_AUTH_MODES = {}));
|
|
10
|
-
/** Available presentations for the authorization flow. */
|
|
11
|
-
export var ANDCO_PRESENTATIONS;
|
|
12
|
-
(function (ANDCO_PRESENTATIONS) {
|
|
13
|
-
ANDCO_PRESENTATIONS["REDIRECT"] = "redirect";
|
|
14
|
-
ANDCO_PRESENTATIONS["POPUP"] = "popup";
|
|
15
|
-
})(ANDCO_PRESENTATIONS || (ANDCO_PRESENTATIONS = {}));
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
import { GrantedOrganizationSubjectSchema } from "./rar/subject.js";
|
|
3
|
+
/**
|
|
4
|
+
* Metadata of a Grant an Organization approved for a Service, as `POST /oauth/grants` lists it.
|
|
5
|
+
*
|
|
6
|
+
* The issuer selects the Grant from the Service's client, the subject and the resource; this
|
|
7
|
+
* metadata exists so a developer can see the candidates and pin one with `grant_id`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const [grant] = parseServiceGrants(await response.json());
|
|
11
|
+
* grant.subject; // { type: "organization", identifier: "42" }
|
|
12
|
+
*/
|
|
13
|
+
export declare const ServiceGrantSchema: v.ObjectSchema<{
|
|
14
|
+
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.UuidAction<string, undefined>]>;
|
|
15
|
+
readonly clientId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.UuidAction<string, undefined>]>;
|
|
16
|
+
readonly subject: v.StrictObjectSchema<{
|
|
17
|
+
readonly type: v.LiteralSchema<"organization", undefined>;
|
|
18
|
+
readonly identifier: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>, v.CheckAction<string, "identifier_exceeds_organization_id">]>;
|
|
19
|
+
}, undefined>;
|
|
20
|
+
readonly resource: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.UrlAction<string, undefined>]>;
|
|
21
|
+
readonly createdAt: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, undefined>]>;
|
|
22
|
+
readonly status: v.PicklistSchema<["active", "revoked"], undefined>;
|
|
23
|
+
readonly version: v.StringSchema<undefined>;
|
|
24
|
+
readonly scopes: v.ArraySchema<v.StringSchema<undefined>, undefined>;
|
|
25
|
+
readonly authorizationDetails: v.ArraySchema<v.RecordSchema<v.StringSchema<undefined>, v.UnknownSchema, undefined>, undefined>;
|
|
26
|
+
}, undefined>;
|
|
27
|
+
export type ServiceGrant = v.InferOutput<typeof ServiceGrantSchema>;
|
|
28
|
+
export declare function parseServiceGrants(input: unknown): readonly ServiceGrant[];
|
|
29
|
+
/**
|
|
30
|
+
* Validates the subject a Service acts for: an Organization with an exact identifier.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* parseServiceSubject({ type: "organization", identifier: "42" }); // ok
|
|
34
|
+
* parseServiceSubject({ type: "profile", identifier: "…" }); // throws
|
|
35
|
+
*/
|
|
36
|
+
export declare function parseServiceSubject(input: unknown): v.InferOutput<typeof GrantedOrganizationSubjectSchema>;
|
|
37
|
+
export declare const ServiceTokenSchema: v.ObjectSchema<{
|
|
38
|
+
readonly access_token: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
|
|
39
|
+
readonly token_type: v.LiteralSchema<"bearer", undefined>;
|
|
40
|
+
readonly expires_in: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>]>;
|
|
41
|
+
readonly authorization_grant_id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.UuidAction<string, undefined>]>;
|
|
42
|
+
}, undefined>;
|
|
43
|
+
export declare function parseServiceToken(input: unknown): v.InferOutput<typeof ServiceTokenSchema>;
|
|
44
|
+
//# sourceMappingURL=service-grants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service-grants.d.ts","sourceRoot":"","sources":["../src/service-grants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAC7B,OAAO,EAAE,gCAAgC,EAAE,MAAM,kBAAkB,CAAC;AAEpE;;;;;;;;;GASG;AACH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;aAa7B,CAAC;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,kBAAkB,CAAC,CAAC;AACpE,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS,YAAY,EAAE,CAE1E;AACD;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,gCAAgC,CAAC,CAE1G;AACD,eAAO,MAAM,kBAAkB;;;;;aAK7B,CAAC;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,kBAAkB,CAAC,CAE1F"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
import { GrantedOrganizationSubjectSchema } from "./rar/subject.js";
|
|
3
|
+
/**
|
|
4
|
+
* Metadata of a Grant an Organization approved for a Service, as `POST /oauth/grants` lists it.
|
|
5
|
+
*
|
|
6
|
+
* The issuer selects the Grant from the Service's client, the subject and the resource; this
|
|
7
|
+
* metadata exists so a developer can see the candidates and pin one with `grant_id`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const [grant] = parseServiceGrants(await response.json());
|
|
11
|
+
* grant.subject; // { type: "organization", identifier: "42" }
|
|
12
|
+
*/
|
|
13
|
+
export const ServiceGrantSchema = /* @__PURE__ */ v.object({
|
|
14
|
+
id: v.pipe(v.string(), v.uuid()),
|
|
15
|
+
clientId: v.pipe(v.string(), v.uuid()),
|
|
16
|
+
subject: GrantedOrganizationSubjectSchema,
|
|
17
|
+
resource: v.pipe(v.string(), v.url()),
|
|
18
|
+
createdAt: v.pipe(v.string(), v.check((date) => Number.isFinite(Date.parse(date)))),
|
|
19
|
+
status: v.picklist(["active", "revoked"]),
|
|
20
|
+
version: v.string(),
|
|
21
|
+
scopes: v.array(v.string()),
|
|
22
|
+
authorizationDetails: v.array(v.record(v.string(), v.unknown())),
|
|
23
|
+
});
|
|
24
|
+
export function parseServiceGrants(input) {
|
|
25
|
+
return v.parse(v.array(ServiceGrantSchema), input);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Validates the subject a Service acts for: an Organization with an exact identifier.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* parseServiceSubject({ type: "organization", identifier: "42" }); // ok
|
|
32
|
+
* parseServiceSubject({ type: "profile", identifier: "…" }); // throws
|
|
33
|
+
*/
|
|
34
|
+
export function parseServiceSubject(input) {
|
|
35
|
+
return v.parse(GrantedOrganizationSubjectSchema, input);
|
|
36
|
+
}
|
|
37
|
+
export const ServiceTokenSchema = /* @__PURE__ */ v.object({
|
|
38
|
+
access_token: v.pipe(v.string(), v.minLength(1)),
|
|
39
|
+
token_type: v.literal("bearer"),
|
|
40
|
+
expires_in: v.pipe(v.number(), v.integer(), v.minValue(1)),
|
|
41
|
+
authorization_grant_id: v.pipe(v.string(), v.uuid()),
|
|
42
|
+
});
|
|
43
|
+
export function parseServiceToken(input) {
|
|
44
|
+
return v.parse(ServiceTokenSchema, input);
|
|
45
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turns a PEM Signing Key into a compact-JWS signer, without a JOSE library.
|
|
3
|
+
*
|
|
4
|
+
* The whole point of {@link createAndCoSigner} is that whoever integrates types a PEM and nothing
|
|
5
|
+
* else: no `kid`, no algorithm name, no dependency that knows what a JWK thumbprint is. Everything
|
|
6
|
+
* this file does -- reading the PKCS8 structure to learn the key's own algorithm, exporting it as a
|
|
7
|
+
* JWK to compute its RFC 7638 thumbprint, and producing the compact JWS itself -- runs on
|
|
8
|
+
* `globalThis.crypto.subtle`, which every runtime the SDK targets (Node 18+, browsers, Bun) already
|
|
9
|
+
* carries.
|
|
10
|
+
*/
|
|
11
|
+
/** JWS `alg` values a Signing Key registered with an Andco OAuth Client may carry. */
|
|
12
|
+
export type AndCoSigningAlgorithm = "ES256" | "ES384" | "ES512" | "RS256" | "EdDSA";
|
|
13
|
+
/**
|
|
14
|
+
* A Signing Key bound once to its `kid` and algorithm, ready to sign any number of claim sets.
|
|
15
|
+
*
|
|
16
|
+
* Built with {@link createAndCoSigner} and passed by call, never constructed by hand: the only
|
|
17
|
+
* public surface is {@link AndCoSigner.sign}, so nothing here can produce a header a caller typed
|
|
18
|
+
* incorrectly.
|
|
19
|
+
*/
|
|
20
|
+
export type AndCoSigner = {
|
|
21
|
+
/** RFC 7638 JWK Thumbprint of the public key, computed once at construction. */
|
|
22
|
+
readonly kid: string;
|
|
23
|
+
/** JWS algorithm this key signs with, derived from the key's own DER structure. */
|
|
24
|
+
readonly alg: AndCoSigningAlgorithm;
|
|
25
|
+
/**
|
|
26
|
+
* Signs `claims` as a compact JWS: `base64url(header).base64url(claims).base64url(signature)`.
|
|
27
|
+
*
|
|
28
|
+
* `header` is always `{ alg, kid, typ: "JWT" }`; nothing about the header is negotiable per call,
|
|
29
|
+
* because the whole reason this type exists is that a caller never has to think about it.
|
|
30
|
+
*/
|
|
31
|
+
sign(claims: Record<string, unknown>): Promise<string>;
|
|
32
|
+
};
|
|
33
|
+
/** Input accepted by {@link createAndCoSigner}. */
|
|
34
|
+
export type AndCoSignerOptions = {
|
|
35
|
+
/** A PKCS#8 private key encoded as PEM. */
|
|
36
|
+
privateKey: string;
|
|
37
|
+
};
|
|
38
|
+
/** Raised when a PEM does not decode into a private key this signer recognizes. */
|
|
39
|
+
export declare class AndCoSignerError extends Error {
|
|
40
|
+
constructor(message: string);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Builds an {@link AndCoSigner} from a PEM PKCS8 private key.
|
|
44
|
+
*
|
|
45
|
+
* The algorithm is read from the key itself -- an EC key's curve OID selects `ES256`/`ES384`/
|
|
46
|
+
* `ES512`, an RSA key signs `RS256`, and Ed25519 signs `EdDSA` -- so passing the wrong key never
|
|
47
|
+
* produces a mismatched header, and there is nothing about the algorithm for a caller to get wrong.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* const signer = await createAndCoSigner({ privateKey: process.env["ANDCO_PRIVATE_KEY"]! });
|
|
52
|
+
* console.log(signer.kid, signer.alg); // both derived, never typed
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export declare function createAndCoSigner(options: AndCoSignerOptions): Promise<AndCoSigner>;
|
|
56
|
+
//# sourceMappingURL=signing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signing.d.ts","sourceRoot":"","sources":["../src/signing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,sFAAsF;AACtF,MAAM,MAAM,qBAAqB,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC;AAEpF;;;;;;GAMG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,gFAAgF;IAChF,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,mFAAmF;IACnF,QAAQ,CAAC,GAAG,EAAE,qBAAqB,CAAC;IACpC;;;;;OAKG;IACH,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CACxD,CAAC;AAEF,mDAAmD;AACnD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,2CAA2C;IAC3C,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,mFAAmF;AACnF,qBAAa,gBAAiB,SAAQ,KAAK;gBACtB,OAAO,EAAE,MAAM;CAInC;AAiBD;;;;;;;;;;;;GAYG;AACH,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,WAAW,CAAC,CAwCzF"}
|
package/dist/signing.js
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turns a PEM Signing Key into a compact-JWS signer, without a JOSE library.
|
|
3
|
+
*
|
|
4
|
+
* The whole point of {@link createAndCoSigner} is that whoever integrates types a PEM and nothing
|
|
5
|
+
* else: no `kid`, no algorithm name, no dependency that knows what a JWK thumbprint is. Everything
|
|
6
|
+
* this file does -- reading the PKCS8 structure to learn the key's own algorithm, exporting it as a
|
|
7
|
+
* JWK to compute its RFC 7638 thumbprint, and producing the compact JWS itself -- runs on
|
|
8
|
+
* `globalThis.crypto.subtle`, which every runtime the SDK targets (Node 18+, browsers, Bun) already
|
|
9
|
+
* carries.
|
|
10
|
+
*/
|
|
11
|
+
/** Raised when a PEM does not decode into a private key this signer recognizes. */
|
|
12
|
+
export class AndCoSignerError extends Error {
|
|
13
|
+
constructor(message) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.name = "AndCoSignerError";
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
const PEM_PATTERN = /-----BEGIN PRIVATE KEY-----([\s\S]+?)-----END PRIVATE KEY-----/;
|
|
19
|
+
/** OIDs this signer recognizes, dotted-decimal, as DER encodes them inside PKCS8. */
|
|
20
|
+
const RSA_ENCRYPTION_OID = "1.2.840.113549.1.1.1";
|
|
21
|
+
const EC_PUBLIC_KEY_OID = "1.2.840.10045.2.1";
|
|
22
|
+
const ED25519_OID = "1.3.101.112";
|
|
23
|
+
const CURVE_OIDS = {
|
|
24
|
+
"1.2.840.10045.3.1.7": { namedCurve: "P-256", alg: "ES256", hash: "SHA-256" },
|
|
25
|
+
"1.3.132.0.34": { namedCurve: "P-384", alg: "ES384", hash: "SHA-384" },
|
|
26
|
+
"1.3.132.0.35": { namedCurve: "P-521", alg: "ES512", hash: "SHA-512" },
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Builds an {@link AndCoSigner} from a PEM PKCS8 private key.
|
|
30
|
+
*
|
|
31
|
+
* The algorithm is read from the key itself -- an EC key's curve OID selects `ES256`/`ES384`/
|
|
32
|
+
* `ES512`, an RSA key signs `RS256`, and Ed25519 signs `EdDSA` -- so passing the wrong key never
|
|
33
|
+
* produces a mismatched header, and there is nothing about the algorithm for a caller to get wrong.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* const signer = await createAndCoSigner({ privateKey: process.env["ANDCO_PRIVATE_KEY"]! });
|
|
38
|
+
* console.log(signer.kid, signer.alg); // both derived, never typed
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export async function createAndCoSigner(options) {
|
|
42
|
+
const der = PKCS8_DER_FROM_PEM(options.privateKey);
|
|
43
|
+
const { algorithmOid, curveOid } = READ_PKCS8_ALGORITHM(der);
|
|
44
|
+
const subtle = SUBTLE_CRYPTO();
|
|
45
|
+
let alg;
|
|
46
|
+
let importAlgorithm;
|
|
47
|
+
let signAlgorithm;
|
|
48
|
+
if (algorithmOid === RSA_ENCRYPTION_OID) {
|
|
49
|
+
alg = "RS256";
|
|
50
|
+
importAlgorithm = { name: "RSASSA-PKCS1-v1_5", hash: "SHA-256" };
|
|
51
|
+
signAlgorithm = { name: "RSASSA-PKCS1-v1_5" };
|
|
52
|
+
}
|
|
53
|
+
else if (algorithmOid === EC_PUBLIC_KEY_OID) {
|
|
54
|
+
const curve = curveOid ? CURVE_OIDS[curveOid] : undefined;
|
|
55
|
+
if (!curve)
|
|
56
|
+
throw new AndCoSignerError(`unsupported EC curve: ${curveOid ?? "unknown"}`);
|
|
57
|
+
alg = curve.alg;
|
|
58
|
+
importAlgorithm = { name: "ECDSA", namedCurve: curve.namedCurve };
|
|
59
|
+
signAlgorithm = { name: "ECDSA", hash: curve.hash };
|
|
60
|
+
}
|
|
61
|
+
else if (algorithmOid === ED25519_OID) {
|
|
62
|
+
alg = "EdDSA";
|
|
63
|
+
importAlgorithm = { name: "Ed25519" };
|
|
64
|
+
signAlgorithm = { name: "Ed25519" };
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
throw new AndCoSignerError(`unsupported private key algorithm: ${algorithmOid}`);
|
|
68
|
+
}
|
|
69
|
+
const key = await subtle.importKey("pkcs8", der, importAlgorithm, true, ["sign"]);
|
|
70
|
+
const kid = await JWK_THUMBPRINT(subtle, key);
|
|
71
|
+
return {
|
|
72
|
+
kid,
|
|
73
|
+
alg,
|
|
74
|
+
async sign(claims) {
|
|
75
|
+
const header = { alg, kid, typ: "JWT" };
|
|
76
|
+
const signingInput = `${BASE64URL(JSON.stringify(header))}.${BASE64URL(JSON.stringify(claims))}`;
|
|
77
|
+
const signature = await subtle.sign(signAlgorithm, key, new TextEncoder().encode(signingInput));
|
|
78
|
+
return `${signingInput}.${BASE64URL_BYTES(new Uint8Array(signature))}`;
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function SUBTLE_CRYPTO() {
|
|
83
|
+
const subtle = globalThis.crypto?.subtle;
|
|
84
|
+
if (!subtle)
|
|
85
|
+
throw new AndCoSignerError("this runtime has no globalThis.crypto.subtle");
|
|
86
|
+
return subtle;
|
|
87
|
+
}
|
|
88
|
+
/** Strips PEM armor and decodes the base64 body into the raw PKCS8 DER bytes. */
|
|
89
|
+
function PKCS8_DER_FROM_PEM(pem) {
|
|
90
|
+
const match = PEM_PATTERN.exec(pem);
|
|
91
|
+
if (!match?.[1])
|
|
92
|
+
throw new AndCoSignerError("not a PKCS8 PEM private key");
|
|
93
|
+
const base64 = match[1].replace(/\s+/g, "");
|
|
94
|
+
const binary = BASE64_DECODE(base64);
|
|
95
|
+
const bytes = new Uint8Array(binary.length);
|
|
96
|
+
for (let i = 0; i < binary.length; i++)
|
|
97
|
+
bytes[i] = binary.charCodeAt(i);
|
|
98
|
+
return bytes.buffer;
|
|
99
|
+
}
|
|
100
|
+
function BASE64_DECODE(value) {
|
|
101
|
+
if (typeof atob !== "function") {
|
|
102
|
+
throw new AndCoSignerError("this runtime has no global atob to decode PEM base64");
|
|
103
|
+
}
|
|
104
|
+
return atob(value);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Reads just enough of the PKCS8 `PrivateKeyInfo` DER structure to learn its algorithm: the
|
|
108
|
+
* `version INTEGER`, then the `AlgorithmIdentifier SEQUENCE` holding the algorithm OID and, for an
|
|
109
|
+
* EC key, its named-curve OID as the algorithm's parameters. Nothing about the key material itself
|
|
110
|
+
* is read here -- `crypto.subtle.importKey` does that.
|
|
111
|
+
*/
|
|
112
|
+
function READ_PKCS8_ALGORITHM(der) {
|
|
113
|
+
const bytes = new Uint8Array(der);
|
|
114
|
+
let offset = 0;
|
|
115
|
+
const outer = DER_READ_TLV(bytes, offset);
|
|
116
|
+
if (outer.tag !== 0x30)
|
|
117
|
+
throw new AndCoSignerError("not a DER SEQUENCE");
|
|
118
|
+
offset = outer.valueStart;
|
|
119
|
+
const version = DER_READ_TLV(bytes, offset);
|
|
120
|
+
if (version.tag !== 0x02)
|
|
121
|
+
throw new AndCoSignerError("malformed PKCS8: expected version INTEGER");
|
|
122
|
+
offset = version.next;
|
|
123
|
+
const algorithmIdentifier = DER_READ_TLV(bytes, offset);
|
|
124
|
+
if (algorithmIdentifier.tag !== 0x30)
|
|
125
|
+
throw new AndCoSignerError("malformed PKCS8: expected AlgorithmIdentifier");
|
|
126
|
+
let inner = algorithmIdentifier.valueStart;
|
|
127
|
+
const algorithm = DER_READ_TLV(bytes, inner);
|
|
128
|
+
if (algorithm.tag !== 0x06)
|
|
129
|
+
throw new AndCoSignerError("malformed PKCS8: expected algorithm OID");
|
|
130
|
+
const algorithmOid = DER_DECODE_OID(bytes, algorithm.valueStart, algorithm.valueEnd);
|
|
131
|
+
inner = algorithm.next;
|
|
132
|
+
if (algorithmOid === EC_PUBLIC_KEY_OID && inner < algorithmIdentifier.valueEnd) {
|
|
133
|
+
const parameters = DER_READ_TLV(bytes, inner);
|
|
134
|
+
if (parameters.tag === 0x06) {
|
|
135
|
+
return { algorithmOid, curveOid: DER_DECODE_OID(bytes, parameters.valueStart, parameters.valueEnd) };
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return { algorithmOid };
|
|
139
|
+
}
|
|
140
|
+
/** Reads one DER tag-length-value at `offset`, supporting both short- and long-form lengths. */
|
|
141
|
+
function DER_READ_TLV(bytes, offset) {
|
|
142
|
+
const tag = bytes[offset];
|
|
143
|
+
if (tag === undefined)
|
|
144
|
+
throw new AndCoSignerError("truncated DER");
|
|
145
|
+
const lengthByte = bytes[offset + 1];
|
|
146
|
+
if (lengthByte === undefined)
|
|
147
|
+
throw new AndCoSignerError("truncated DER");
|
|
148
|
+
let length;
|
|
149
|
+
let valueStart;
|
|
150
|
+
if ((lengthByte & 0x80) === 0) {
|
|
151
|
+
length = lengthByte;
|
|
152
|
+
valueStart = offset + 2;
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
const octets = lengthByte & 0x7f;
|
|
156
|
+
length = 0;
|
|
157
|
+
for (let i = 0; i < octets; i++) {
|
|
158
|
+
const byte = bytes[offset + 2 + i];
|
|
159
|
+
if (byte === undefined)
|
|
160
|
+
throw new AndCoSignerError("truncated DER length");
|
|
161
|
+
length = length * 256 + byte;
|
|
162
|
+
}
|
|
163
|
+
valueStart = offset + 2 + octets;
|
|
164
|
+
}
|
|
165
|
+
const valueEnd = valueStart + length;
|
|
166
|
+
if (valueEnd > bytes.length)
|
|
167
|
+
throw new AndCoSignerError("truncated DER value");
|
|
168
|
+
return { tag: tag & 0xff, valueStart, valueEnd, next: valueEnd };
|
|
169
|
+
}
|
|
170
|
+
/** Decodes a DER OID's content octets into its dotted-decimal string. */
|
|
171
|
+
function DER_DECODE_OID(bytes, start, end) {
|
|
172
|
+
const parts = [];
|
|
173
|
+
const first = bytes[start];
|
|
174
|
+
if (first === undefined)
|
|
175
|
+
throw new AndCoSignerError("empty OID");
|
|
176
|
+
parts.push(Math.floor(first / 40), first % 40);
|
|
177
|
+
let value = 0;
|
|
178
|
+
for (let i = start + 1; i < end; i++) {
|
|
179
|
+
const byte = bytes[i];
|
|
180
|
+
if (byte === undefined)
|
|
181
|
+
throw new AndCoSignerError("truncated OID");
|
|
182
|
+
value = value * 128 + (byte & 0x7f);
|
|
183
|
+
if ((byte & 0x80) === 0) {
|
|
184
|
+
parts.push(value);
|
|
185
|
+
value = 0;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return parts.join(".");
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Computes the RFC 7638 JWK Thumbprint of a key's public members.
|
|
192
|
+
*
|
|
193
|
+
* `crypto.subtle.exportKey("jwk", key)` on an imported private key already carries its public
|
|
194
|
+
* members (`x`/`y` for EC, `n`/`e` for RSA, `x` for OKP), so nothing has to be derived separately
|
|
195
|
+
* for a public key. The thumbprint is the base64url SHA-256 digest of those members serialized as
|
|
196
|
+
* JSON with their keys in the exact lexicographic order RFC 7638 requires -- `crv, kty, x, y` for
|
|
197
|
+
* EC, `crv, kty, x` for OKP, `e, kty, n` for RSA -- and nothing else.
|
|
198
|
+
*/
|
|
199
|
+
async function JWK_THUMBPRINT(subtle, key) {
|
|
200
|
+
const jwk = (await subtle.exportKey("jwk", key));
|
|
201
|
+
let canonical;
|
|
202
|
+
if (jwk.kty === "EC") {
|
|
203
|
+
if (!jwk.crv || !jwk.x || !jwk.y)
|
|
204
|
+
throw new AndCoSignerError("incomplete EC JWK");
|
|
205
|
+
canonical = { crv: jwk.crv, kty: jwk.kty, x: jwk.x, y: jwk.y };
|
|
206
|
+
}
|
|
207
|
+
else if (jwk.kty === "OKP") {
|
|
208
|
+
if (!jwk.crv || !jwk.x)
|
|
209
|
+
throw new AndCoSignerError("incomplete OKP JWK");
|
|
210
|
+
canonical = { crv: jwk.crv, kty: jwk.kty, x: jwk.x };
|
|
211
|
+
}
|
|
212
|
+
else if (jwk.kty === "RSA") {
|
|
213
|
+
if (!jwk.e || !jwk.n)
|
|
214
|
+
throw new AndCoSignerError("incomplete RSA JWK");
|
|
215
|
+
canonical = { e: jwk.e, kty: jwk.kty, n: jwk.n };
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
throw new AndCoSignerError(`unsupported JWK key type: ${jwk.kty}`);
|
|
219
|
+
}
|
|
220
|
+
const digest = await subtle.digest("SHA-256", new TextEncoder().encode(JSON.stringify(canonical)));
|
|
221
|
+
return BASE64URL_BYTES(new Uint8Array(digest));
|
|
222
|
+
}
|
|
223
|
+
function BASE64URL(value) {
|
|
224
|
+
return BASE64URL_BYTES(new TextEncoder().encode(value));
|
|
225
|
+
}
|
|
226
|
+
function BASE64URL_BYTES(bytes) {
|
|
227
|
+
if (typeof btoa !== "function")
|
|
228
|
+
throw new AndCoSignerError("this runtime has no global btoa to encode base64url");
|
|
229
|
+
let binary = "";
|
|
230
|
+
for (const byte of bytes)
|
|
231
|
+
binary += String.fromCharCode(byte);
|
|
232
|
+
return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
233
|
+
}
|
|
@@ -7,14 +7,26 @@ export type AndCoFinancialEvent<T extends string = string, P = Record<string, un
|
|
|
7
7
|
occurred_at: string;
|
|
8
8
|
cursor: string;
|
|
9
9
|
};
|
|
10
|
+
/**
|
|
11
|
+
* An Andco account as an event names it: `{ type: "account", id }`, the same vocabulary a request
|
|
12
|
+
* uses to name an account by identifier.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* const account: AndCoEventAccount = { type: "account", id: "0198d482-82aa-7ef2-ae1b-0cfae7ea5d8a" };
|
|
16
|
+
*/
|
|
17
|
+
export type AndCoEventAccount = Extract<import("./intents.js").AndCoIntentAccount, {
|
|
18
|
+
type: "account";
|
|
19
|
+
}>;
|
|
20
|
+
/** Money in an event: `{ currency, value }`, the value an exact decimal string, never a number. */
|
|
21
|
+
export type AndCoEventAmount = import("./intents.js").AndCoSignedAmount;
|
|
22
|
+
/** Durable deposit lifecycle facts, distinct from presentation completion. */
|
|
10
23
|
export type AndCoIntentDepositEvent = AndCoFinancialEvent<"deposit.target_updated", {
|
|
11
24
|
intent_id: string;
|
|
12
|
-
target:
|
|
13
|
-
currency: "CLP";
|
|
25
|
+
target: AndCoEventAmount;
|
|
14
26
|
}> | AndCoFinancialEvent<"deposit.closed", {
|
|
15
27
|
intent_id: string;
|
|
16
28
|
status: "closed";
|
|
17
|
-
total:
|
|
29
|
+
total: AndCoEventAmount;
|
|
18
30
|
closed_at: string;
|
|
19
31
|
}> | AndCoFinancialEvent<"deposit.expired", {
|
|
20
32
|
intent_id: string;
|
|
@@ -24,108 +36,151 @@ export type AndCoIntentDepositEvent = AndCoFinancialEvent<"deposit.target_update
|
|
|
24
36
|
intent_id: string;
|
|
25
37
|
movement_id: string;
|
|
26
38
|
transaction_id: string;
|
|
27
|
-
amount:
|
|
28
|
-
currency: "CLP";
|
|
39
|
+
amount: AndCoEventAmount;
|
|
29
40
|
received_at: string;
|
|
30
41
|
note: string | null;
|
|
31
|
-
total:
|
|
42
|
+
total: AndCoEventAmount;
|
|
32
43
|
late: boolean;
|
|
33
44
|
}> | AndCoFinancialEvent<"deposit.unassigned", {
|
|
34
45
|
intent_id: string;
|
|
35
46
|
movement_id: string;
|
|
36
47
|
transaction_id: string;
|
|
37
|
-
amount:
|
|
38
|
-
|
|
39
|
-
total: string;
|
|
48
|
+
amount: AndCoEventAmount;
|
|
49
|
+
total: AndCoEventAmount;
|
|
40
50
|
}> | AndCoFinancialEvent<"deposit.completed", {
|
|
41
51
|
intent_id: string;
|
|
42
52
|
status: "completed";
|
|
43
|
-
total:
|
|
44
|
-
target:
|
|
53
|
+
total: AndCoEventAmount;
|
|
54
|
+
target: AndCoEventAmount;
|
|
45
55
|
completed_at: string;
|
|
46
56
|
}>;
|
|
47
|
-
/**
|
|
57
|
+
/**
|
|
58
|
+
* An account-wide bank fact, independent of application attribution.
|
|
59
|
+
*
|
|
60
|
+
* Account events keep saying `deposit` and `withdrawal` on purpose. Here the word names the
|
|
61
|
+
* direction of a Movement — the entry a Transaction leaves in one account — and not the kind of
|
|
62
|
+
* request that produced it. One transfer publishes `transfer.succeeded` on the Intent,
|
|
63
|
+
* `withdrawal.posted` on the account the money left, and `deposit.received` on the account it
|
|
64
|
+
* reached, and all three words are correct.
|
|
65
|
+
*/
|
|
48
66
|
export type AndCoDepositEvent = AndCoFinancialEvent<"deposit.received", {
|
|
49
|
-
|
|
67
|
+
account: AndCoEventAccount;
|
|
50
68
|
movement_id: string;
|
|
51
69
|
transaction_id: string;
|
|
52
|
-
amount:
|
|
53
|
-
currency: "CLP";
|
|
70
|
+
amount: AndCoEventAmount;
|
|
54
71
|
received_at: string;
|
|
55
72
|
note: string | null;
|
|
56
73
|
outcome: "credited";
|
|
57
74
|
}> | AndCoFinancialEvent<"deposit.reversed", {
|
|
58
|
-
|
|
75
|
+
account: AndCoEventAccount;
|
|
59
76
|
movement_id: string;
|
|
60
77
|
transaction_id: string;
|
|
61
|
-
amount:
|
|
62
|
-
currency: "CLP";
|
|
78
|
+
amount: AndCoEventAmount;
|
|
63
79
|
received_at: string;
|
|
64
80
|
note: string | null;
|
|
65
81
|
outcome: "reversed";
|
|
66
82
|
observed_at: string;
|
|
67
83
|
}>;
|
|
68
|
-
/**
|
|
84
|
+
/**
|
|
85
|
+
* A posted debit or bank reversal, independent of any application request.
|
|
86
|
+
*
|
|
87
|
+
* See {@link AndCoDepositEvent} for why an account event is still called a withdrawal once the
|
|
88
|
+
* request that caused it is a `transfer`.
|
|
89
|
+
*/
|
|
69
90
|
export type AndCoWithdrawalEvent = AndCoFinancialEvent<"withdrawal.posted", {
|
|
70
|
-
|
|
91
|
+
account: AndCoEventAccount;
|
|
71
92
|
movement_id: string;
|
|
72
93
|
transaction_id: string;
|
|
73
|
-
amount:
|
|
74
|
-
currency: "CLP";
|
|
94
|
+
amount: AndCoEventAmount;
|
|
75
95
|
posted_at: string;
|
|
76
96
|
note: string | null;
|
|
77
97
|
outcome: "posted";
|
|
78
98
|
}> | AndCoFinancialEvent<"withdrawal.reversed", {
|
|
79
|
-
|
|
99
|
+
account: AndCoEventAccount;
|
|
80
100
|
movement_id: string;
|
|
81
101
|
transaction_id: string;
|
|
82
|
-
amount:
|
|
83
|
-
currency: "CLP";
|
|
102
|
+
amount: AndCoEventAmount;
|
|
84
103
|
posted_at: string;
|
|
85
104
|
note: string | null;
|
|
86
105
|
outcome: "reversed";
|
|
87
106
|
observed_at: string;
|
|
88
107
|
}>;
|
|
89
|
-
/**
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
108
|
+
/**
|
|
109
|
+
* Frozen values of a confirmed transfer; these do not assert that a debit was posted.
|
|
110
|
+
*
|
|
111
|
+
* `destination` is whatever the money was aimed at: an Andco account by identifier, an Andco
|
|
112
|
+
* account by the Account Alias its holder chose, or an account at another Chilean bank. An Alias
|
|
113
|
+
* stays an Alias here because it resolves at execution, not at confirmation.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* const operation: AndCoConfirmedTransfer = {
|
|
117
|
+
* source: { type: "account", id: "0198d482-82aa-7ef2-ae1b-0cfae7ea5d8a" },
|
|
118
|
+
* destination: { type: "alias", alias: "proveedores" },
|
|
119
|
+
* amount: { currency: "CLP", value: "30000" },
|
|
120
|
+
* note: "Factura 42",
|
|
121
|
+
* };
|
|
122
|
+
*/
|
|
123
|
+
export type AndCoConfirmedTransfer = {
|
|
124
|
+
source: AndCoEventAccount;
|
|
125
|
+
destination: import("./intents.js").AndCoTransferDestination;
|
|
126
|
+
amount: AndCoEventAmount;
|
|
95
127
|
note: string;
|
|
96
128
|
};
|
|
97
|
-
|
|
129
|
+
/**
|
|
130
|
+
* The lifecycle of one transfer Intent, as its Project sees it.
|
|
131
|
+
*
|
|
132
|
+
* These are the Intent events; an account's own entries keep their direction-shaped names. A
|
|
133
|
+
* `transfer.approval_required` says the Intent is waiting on a person's Approval, so an integrator
|
|
134
|
+
* can notify its own people without standing up a separate webhook. A `transfer.confirmed` says a
|
|
135
|
+
* person or a Signed Instruction froze the operation's values, and a `transfer.succeeded` says the
|
|
136
|
+
* money moved.
|
|
137
|
+
*/
|
|
138
|
+
export type AndCoIntentTransferEvent = AndCoFinancialEvent<"transfer.expired", {
|
|
98
139
|
intent_id: string;
|
|
99
140
|
status: "expired";
|
|
100
141
|
expires_at: string;
|
|
101
|
-
}> | AndCoFinancialEvent
|
|
142
|
+
}> | AndCoFinancialEvent<`transfer.${"approval_required" | "confirmed" | "succeeded" | "failed" | "cancelled" | "rejected"}`, {
|
|
102
143
|
intent_id: string;
|
|
103
144
|
status: string;
|
|
104
145
|
detail: string | null;
|
|
105
|
-
operation:
|
|
146
|
+
operation: AndCoConfirmedTransfer | null;
|
|
106
147
|
transaction_id: string | null;
|
|
107
148
|
observed_at: string;
|
|
108
149
|
}>;
|
|
150
|
+
/** Durable events with an opaque continuation cursor and server observation time. */
|
|
109
151
|
export type AndCoEventPage = {
|
|
110
152
|
events: AndCoFinancialEvent[];
|
|
153
|
+
/** Opaque position after this page; persist only after every handler succeeds. */
|
|
111
154
|
next_cursor: string;
|
|
155
|
+
/** Whether another page is immediately available. */
|
|
112
156
|
has_more: boolean;
|
|
157
|
+
/** Server timestamp used to validate the event page. */
|
|
113
158
|
server_time: string;
|
|
114
159
|
};
|
|
160
|
+
/** Checkpoint recovery, polling frequency, and failure handling for one subscription. */
|
|
115
161
|
export type AndCoEventSubscriptionOptions = {
|
|
116
162
|
/** Resume after a checkpoint previously acknowledged by this subject's subscription. */
|
|
117
163
|
after?: string;
|
|
118
164
|
/** Receives transport, authorization, cursor, and handler failures. Throwing here stops the subscription. */
|
|
119
165
|
onError: (error: unknown) => void;
|
|
166
|
+
/** Delay between polls in milliseconds. Defaults to 1000; minimum 100. */
|
|
120
167
|
pollIntervalMs?: number;
|
|
121
168
|
};
|
|
169
|
+
/** Subscription cleanup and the last checkpoint acknowledged after successful handling. */
|
|
122
170
|
export type AndCoEventSubscription = {
|
|
171
|
+
/** Aborts pending reads and stops future polling. */
|
|
123
172
|
unsubscribe(): void;
|
|
124
173
|
/** Persist only acknowledged checkpoints; a failed handler leaves this value unchanged. */
|
|
125
174
|
readonly checkpoint: string | undefined;
|
|
126
175
|
};
|
|
127
176
|
/** Reconciles bounded durable pages; the SDK owns cursor decoding, while callers persist opaque values. */
|
|
128
|
-
export declare function subscribeFinancialEvents<E extends AndCoFinancialEvent>(
|
|
177
|
+
export declare function subscribeFinancialEvents<E extends AndCoFinancialEvent>(
|
|
178
|
+
/** Reads the next bounded page; honor the signal so unsubscribe can abort the request. */
|
|
179
|
+
read: (after: string | undefined, signal: AbortSignal) => Promise<AndCoEventPage>,
|
|
180
|
+
/** Maps a recognized event; returning `null` skips delivery to the handler. */
|
|
181
|
+
decode: (event: AndCoFinancialEvent) => E | null,
|
|
182
|
+
/** Process successfully before acknowledgement; failures leave the checkpoint unchanged. */
|
|
183
|
+
handler: (event: E) => void | Promise<void>, options: AndCoEventSubscriptionOptions,
|
|
129
184
|
/** Scopes the cursor namespace. Any caller-chosen `kind` works; only its consistency is checked. */
|
|
130
185
|
subject: {
|
|
131
186
|
kind: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"financial-events.d.ts","sourceRoot":"","sources":["../../src/transport/financial-events.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,MAAM,MAAM,mBAAmB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI;IACxF,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,CAAC,CAAC;IACR,OAAO,EAAE,CAAC,CAAC;IACX,OAAO,EAAE,CAAC,CAAC;IACX,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAC/B,mBAAmB,CACjB,wBAAwB,EACxB;IACE,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"financial-events.d.ts","sourceRoot":"","sources":["../../src/transport/financial-events.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,MAAM,MAAM,mBAAmB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI;IACxF,EAAE,EAAE,MAA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E,OAAO,CAAC;IAClB,wDAAwD;IACxD,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,yFAAyF;AACzF,MAAM,MAAM,6BAA6B,GAAG;IAC1C,wFAAwF;IACxF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,6GAA6G;IAC7G,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IAClC,0EAA0E;IAC1E,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,2FAA2F;AAC3F,MAAM,MAAM,sBAAsB,GAAG;IACnC,qDAAqD;IACrD,WAAW,IAAI,IAAI,CAAC;IACpB,2FAA2F;IAC3F,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;CACzC,CAAC;AAEF,2GAA2G;AAC3G,wBAAgB,wBAAwB,CAAC,CAAC,SAAS,mBAAmB;AACpE,0FAA0F;AAC1F,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,EAAE,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,cAAc,CAAC;AACjF,+EAA+E;AAC/E,MAAM,EAAE,CAAC,KAAK,EAAE,mBAAmB,KAAK,CAAC,GAAG,IAAI;AAChD,4FAA4F;AAC5F,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,EAC3C,OAAO,EAAE,6BAA6B;AACtC,oGAAoG;AACpG,OAAO,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,GACpC,sBAAsB,CAyGxB"}
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
/** Reconciles bounded durable pages; the SDK owns cursor decoding, while callers persist opaque values. */
|
|
2
|
-
export function subscribeFinancialEvents(
|
|
2
|
+
export function subscribeFinancialEvents(
|
|
3
|
+
/** Reads the next bounded page; honor the signal so unsubscribe can abort the request. */
|
|
4
|
+
read,
|
|
5
|
+
/** Maps a recognized event; returning `null` skips delivery to the handler. */
|
|
6
|
+
decode,
|
|
7
|
+
/** Process successfully before acknowledgement; failures leave the checkpoint unchanged. */
|
|
8
|
+
handler, options,
|
|
3
9
|
/** Scopes the cursor namespace. Any caller-chosen `kind` works; only its consistency is checked. */
|
|
4
10
|
subject) {
|
|
5
11
|
const interval = options.pollIntervalMs ?? 1000;
|