@andco/protocol 0.0.6 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -71
- package/dist/api-errors.d.ts +5 -5
- package/dist/api-errors.d.ts.map +1 -1
- package/dist/api-errors.js +5 -5
- package/dist/consent.d.ts +2 -2
- package/dist/consent.d.ts.map +1 -1
- package/dist/consent.js +10 -19
- package/dist/errors.d.ts +46 -7
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +51 -8
- package/dist/format-money.d.ts +3 -0
- package/dist/format-money.d.ts.map +1 -0
- package/dist/format-money.js +7 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/intent-input.d.ts +124 -124
- package/dist/intent-input.d.ts.map +1 -1
- package/dist/intent-input.js +14 -14
- package/dist/miniapp-icon.d.ts +2 -2
- package/dist/miniapp-icon.d.ts.map +1 -1
- package/dist/miniapp-icon.js +6 -58
- package/dist/native-intent.d.ts +20 -29
- package/dist/native-intent.d.ts.map +1 -1
- package/dist/native-intent.js +13 -56
- package/dist/pagination.d.ts +71 -0
- package/dist/pagination.d.ts.map +1 -0
- package/dist/pagination.js +63 -0
- package/dist/rar/account-matchers.d.ts +52 -52
- package/dist/rar/account-matchers.d.ts.map +1 -1
- package/dist/rar/account-matchers.js +81 -72
- package/dist/rar/bank.d.ts +86 -84
- package/dist/rar/bank.d.ts.map +1 -1
- package/dist/rar/bank.js +26 -24
- package/dist/rar/catalog.d.ts +57 -56
- package/dist/rar/catalog.d.ts.map +1 -1
- package/dist/rar/catalog.js +1 -0
- package/dist/rar/detail.d.ts +1 -1
- package/dist/rar/detail.d.ts.map +1 -1
- package/dist/rar/detail.js +1 -1
- package/dist/service-grants.d.ts +6 -3
- package/dist/service-grants.d.ts.map +1 -1
- package/dist/service-grants.js +17 -3
- package/dist/transport/financial-events.d.ts +10 -22
- package/dist/transport/financial-events.d.ts.map +1 -1
- package/dist/transport/financial-events.js +36 -62
- package/dist/transport/generated/oauth-api.d.ts +269 -96
- package/dist/transport/generated/oauth-api.d.ts.map +1 -1
- package/dist/transport/intents.d.ts +11 -10
- package/dist/transport/intents.d.ts.map +1 -1
- package/dist/transport/intents.js +20 -19
- package/dist/transport/rest.d.ts +3 -3
- package/dist/transport/rest.d.ts.map +1 -1
- package/dist/transport/rest.js +1 -1
- package/dist/transport/runtime.js +3 -3
- package/dist/utils.js +3 -3
- package/dist/webhooks.d.ts +92 -12
- package/dist/webhooks.d.ts.map +1 -1
- package/dist/webhooks.js +95 -20
- package/package.json +1 -1
- package/dist/native-copy.d.ts +0 -28
- package/dist/native-copy.d.ts.map +0 -1
- package/dist/native-copy.js +0 -400
package/README.md
CHANGED
|
@@ -1,92 +1,43 @@
|
|
|
1
1
|
# `@andco/protocol`
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
> **Pre-1.0 software.** Until version 1.0.0 is released, any new version may include breaking
|
|
5
|
-
> changes, including minor and patch releases. Expect any API incompatibility and data resets
|
|
6
|
-
> in the Andco environments without prior notice. Pin an exact version and review the release
|
|
7
|
-
> notes before upgrading.
|
|
3
|
+
Shared protocol schemas, validators, OAuth helpers, message contracts, typed transport, and webhook verification used by the Andco SDK.
|
|
8
4
|
|
|
9
|
-
|
|
10
|
-
and portable resource transport used by the AndCo JavaScript packages.
|
|
5
|
+
Developer preview: APIs may change before 1.0.
|
|
11
6
|
|
|
12
|
-
|
|
13
|
-
server, `/browser` in a browser). Import this package directly when
|
|
14
|
-
implementing a framework or runtime adapter.
|
|
7
|
+
## Install
|
|
15
8
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
The OAuth randomness helpers use the Web Crypto contract and never import `node:crypto`, install polyfills, or mutate
|
|
19
|
-
globalThis`. `RANDOM_UUID()` prefers `crypto.randomUUID()` and falls back to an RFC 4122 UUID v4 generated with
|
|
20
|
-
`crypto.getRandomValues()` when `randomUUID()` is unavailable.
|
|
21
|
-
|
|
22
|
-
An application may inject the secure random source exposed by its host runtime:
|
|
23
|
-
|
|
24
|
-
```ts
|
|
25
|
-
import { RANDOM_UUID, type AndCoRandomSource } from "@andco/protocol";
|
|
26
|
-
|
|
27
|
-
// Supplied by the host runtime or the application.
|
|
28
|
-
declare const runtimeCrypto: AndCoRandomSource;
|
|
29
|
-
|
|
30
|
-
const transactionId = RANDOM_UUID(runtimeCrypto);
|
|
9
|
+
```sh
|
|
10
|
+
pnpm add @andco/protocol
|
|
31
11
|
```
|
|
32
12
|
|
|
33
|
-
|
|
34
|
-
the `WEB_CRYPTO_UNAVAILABLE` code. A cryptographically insecure random-number generator must never be used as a fallback.
|
|
35
|
-
|
|
36
|
-
## Permissions
|
|
13
|
+
Use ES module imports in your application. This package has no client registration or login setup of its own. Most integrations start with `@andco/sdk` and `@andco/bank-sdk`; use it directly when validating a protocol document or implementing an adapter.
|
|
37
14
|
|
|
38
|
-
|
|
39
|
-
resource permission is a RAR with a `subject`. Each type has a valibot schema for its Grant Request
|
|
40
|
-
(what an application asks, with `editable` and `null`) and for its Grant (what was conceded):
|
|
41
|
-
`ANDCO_RAR_CATALOG`, `parseAndcoGrantRequest`, `parseAndcoGrant`, the account matchers and
|
|
42
|
-
`accountMatcherContains`. `decodeJwtPayload` reads a JWT payload without verifying it.
|
|
15
|
+
## Validate a Grant Request
|
|
43
16
|
|
|
44
17
|
```ts
|
|
45
18
|
import { parseAndcoGrantRequest } from "@andco/protocol";
|
|
46
19
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
subject: { type: "organization" },
|
|
52
|
-
destinations: [{ type: "alias", pattern: "cobros" }],
|
|
20
|
+
const detail = parseAndcoGrantRequest({
|
|
21
|
+
type: "bank_account",
|
|
22
|
+
actions: ["read"],
|
|
23
|
+
subject: { type: "profile" },
|
|
53
24
|
locations: ["https://api.andco.com"],
|
|
54
25
|
});
|
|
55
26
|
```
|
|
56
27
|
|
|
57
|
-
##
|
|
58
|
-
|
|
59
|
-
- `@andco/protocol` contains the runtime-neutral protocol and validation
|
|
60
|
-
contracts.
|
|
61
|
-
- `@andco/protocol/authorization` contains the GET/PAR authorization-request
|
|
62
|
-
transport helpers (`resolveAndCoAuthorization` and related types).
|
|
63
|
-
- `@andco/protocol/messages` contains the secure iframe message union.
|
|
64
|
-
- `@andco/protocol/transport` contains the generated REST client, the Financial
|
|
65
|
-
Intent client, resource types, and lazy Fetch adapter shared by server and
|
|
66
|
-
browser packages.
|
|
67
|
-
- `@andco/protocol/webhooks` contains `andcoWebhooks.verifier()`, which verifies
|
|
68
|
-
Andco's Ed25519-signed webhook deliveries against Andco's public JWKS (cached
|
|
69
|
-
by `kid`), and its header and error constants.
|
|
70
|
-
- `@andco/protocol/server` contains server-only helpers for a confidential
|
|
71
|
-
client authenticated with `client_secret_basic`.
|
|
28
|
+
## Capabilities
|
|
72
29
|
|
|
73
|
-
|
|
74
|
-
|
|
30
|
+
- Validate Grant Requests and resolved Grants, account matchers, Subjects, amounts, and signed claims.
|
|
31
|
+
- Compose resource-specific authorization and resolve GET/PAR transport.
|
|
32
|
+
- Share hosted iframe and native authorization message contracts.
|
|
33
|
+
- Use `@andco/protocol/transport` for the generated resource contract.
|
|
34
|
+
- Use `@andco/protocol/webhooks` to verify Andco's Ed25519 webhook signatures and parse lifecycle events.
|
|
75
35
|
|
|
76
|
-
|
|
36
|
+
Schemas and helpers are runtime-neutral; portable crypto helpers use Web Crypto. The SDK wraps these contracts with sessions and operations.
|
|
77
37
|
|
|
78
|
-
|
|
79
|
-
they test against vectors generated from it. `scripts/rar-fixture-cases.mjs`
|
|
80
|
-
(valid and invalid authorization details) and
|
|
81
|
-
`scripts/account-matcher-containment-cases.mjs` are the shared fixtures; this
|
|
82
|
-
package's vitest suite checks them, and
|
|
83
|
-
`scripts/generate-conformance-vectors.mjs` publishes them, with the money, alias,
|
|
84
|
-
Organization and identifier syntaxes and the members of each Signed Instruction
|
|
85
|
-
(read from `openapi/oauth-api.yaml`), as one JSON document:
|
|
38
|
+
## Learn more
|
|
86
39
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
pnpm --filter @andco/protocol run generate:conformance # writes into the three sibling SDK repos
|
|
90
|
-
```
|
|
40
|
+
- [Integration guide](https://github.com/haulmer/andco-sdk-js/blob/main/apps/sdk-landing/content/docs/protocol/overview.md)
|
|
41
|
+
- [API reference](https://github.com/haulmer/andco-sdk-js/blob/main/apps/sdk-landing/content/docs/reference/andco-protocol.md)
|
|
91
42
|
|
|
92
|
-
|
|
43
|
+
Method contracts, options, and lifecycle details are documented in the exported JSDoc and API reference.
|
package/dist/api-errors.d.ts
CHANGED
|
@@ -71,13 +71,13 @@ export declare const ANDCO_API_ERROR_CODES: {
|
|
|
71
71
|
* which leaves the Intent pending for another approver. Raised before anything is presented.
|
|
72
72
|
*/
|
|
73
73
|
readonly AMOUNT_OUT_OF_GRANT: "amount_out_of_grant";
|
|
74
|
-
/** The
|
|
75
|
-
readonly
|
|
74
|
+
/** The accountKey of an account to open does not match the `bank_account` Grant's accountKey patterns. */
|
|
75
|
+
readonly ACCOUNT_KEY_OUT_OF_GRANT: "account_key_out_of_grant";
|
|
76
76
|
/**
|
|
77
|
-
* The Account
|
|
78
|
-
* it belonged to an account that was closed:
|
|
77
|
+
* The Account Key is already in use by an account of this subject and `upsert` was not asked, or
|
|
78
|
+
* it belonged to an account that was closed: AccountKeys are never reused.
|
|
79
79
|
*/
|
|
80
|
-
readonly
|
|
80
|
+
readonly ACCOUNT_KEY_TAKEN: "account_key_taken";
|
|
81
81
|
/** The source of a transfer is not one the Grant's `sources` admit. */
|
|
82
82
|
readonly INVALID_SOURCE: "invalid_source";
|
|
83
83
|
/** The destination of a transfer, or the account a deposit names, is not one the Grant admits. */
|
package/dist/api-errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-errors.d.ts","sourceRoot":"","sources":["../src/api-errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,qBAAqB;IAEhC;;;OAGG;;IAEH;;;;OAIG;;IAEH;;;OAGG;;IAEH;;;OAGG;;IAEH,4EAA4E;;IAE5E;;;OAGG;;IAEH;;;OAGG;;IAIH,qGAAqG;;IAErG;;;OAGG;;IAEH,wFAAwF;;IAExF,+FAA+F;;IAE/F,2DAA2D;;IAE3D,qEAAqE;;IAIrE;;;;OAIG;;IAEH;;;;OAIG;;IAEH,
|
|
1
|
+
{"version":3,"file":"api-errors.d.ts","sourceRoot":"","sources":["../src/api-errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,qBAAqB;IAEhC;;;OAGG;;IAEH;;;;OAIG;;IAEH;;;OAGG;;IAEH;;;OAGG;;IAEH,4EAA4E;;IAE5E;;;OAGG;;IAEH;;;OAGG;;IAIH,qGAAqG;;IAErG;;;OAGG;;IAEH,wFAAwF;;IAExF,+FAA+F;;IAE/F,2DAA2D;;IAE3D,qEAAqE;;IAIrE;;;;OAIG;;IAEH;;;;OAIG;;IAEH,0GAA0G;;IAE1G;;;OAGG;;IAEH,uEAAuE;;IAEvE,kGAAkG;;IAElG;;;OAGG;;IAEH,iHAAiH;;IAEjH,uEAAuE;;IAEvE,sGAAsG;;IAEtG,gGAAgG;;IAEhG,gGAAgG;;IAIhG,0FAA0F;;IAE1F,0DAA0D;;IAE1D,qDAAqD;;IAIrD;;;OAGG;;CAEK,CAAC;AAEX,iEAAiE;AACjE,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,qBAAqB,CAAC,CAAC,MAAM,OAAO,qBAAqB,CAAC,CAAC"}
|
package/dist/api-errors.js
CHANGED
|
@@ -74,13 +74,13 @@ export const ANDCO_API_ERROR_CODES = {
|
|
|
74
74
|
* which leaves the Intent pending for another approver. Raised before anything is presented.
|
|
75
75
|
*/
|
|
76
76
|
AMOUNT_OUT_OF_GRANT: "amount_out_of_grant",
|
|
77
|
-
/** The
|
|
78
|
-
|
|
77
|
+
/** The accountKey of an account to open does not match the `bank_account` Grant's accountKey patterns. */
|
|
78
|
+
ACCOUNT_KEY_OUT_OF_GRANT: "account_key_out_of_grant",
|
|
79
79
|
/**
|
|
80
|
-
* The Account
|
|
81
|
-
* it belonged to an account that was closed:
|
|
80
|
+
* The Account Key is already in use by an account of this subject and `upsert` was not asked, or
|
|
81
|
+
* it belonged to an account that was closed: AccountKeys are never reused.
|
|
82
82
|
*/
|
|
83
|
-
|
|
83
|
+
ACCOUNT_KEY_TAKEN: "account_key_taken",
|
|
84
84
|
/** The source of a transfer is not one the Grant's `sources` admit. */
|
|
85
85
|
INVALID_SOURCE: "invalid_source",
|
|
86
86
|
/** The destination of a transfer, or the account a deposit names, is not one the Grant admits. */
|
package/dist/consent.d.ts
CHANGED
|
@@ -10,10 +10,10 @@ type PreparedConsentScope = PreparedConsent["scopes"][number];
|
|
|
10
10
|
* the three native Hosts -- reads the same fact instead of re-deriving it.
|
|
11
11
|
*/
|
|
12
12
|
export declare function ANDCO_CONSENT_SCOPE_IS_LOCKED(scope: Pick<PreparedConsentScope, "mode" | "grantedAt">): boolean;
|
|
13
|
-
/**
|
|
13
|
+
/** Consent policies with provider-owned labels and selection state. */
|
|
14
14
|
export declare function ANDCO_CONSENT_SCOPES(consent: Extract<AndCoAuthorizationPreparation, {
|
|
15
15
|
status: "consent_required";
|
|
16
|
-
}
|
|
16
|
+
}>): {
|
|
17
17
|
title: string;
|
|
18
18
|
description: string | undefined;
|
|
19
19
|
required: boolean;
|
package/dist/consent.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consent.d.ts","sourceRoot":"","sources":["../src/consent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,6BAA6B,EAAE,MAAM,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"consent.d.ts","sourceRoot":"","sources":["../src/consent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B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O,GAAE,WAAW,CAAC,MAAM,CAAa,GACvC,OAAO,CAAC,0BAA0B,EAAE;IAAE,QAAQ,EAAE,SAAS,CAAA;CAAE,CAAC,CAc9D"}
|
package/dist/consent.js
CHANGED
|
@@ -1,12 +1,4 @@
|
|
|
1
1
|
import { ANDCO_API_ORIGIN } from "./constants.js";
|
|
2
|
-
import { ANDCO_NATIVE_TEXT as t } from "./native-copy.js";
|
|
3
|
-
const SCOPE_LABELS = {
|
|
4
|
-
openid: "Identidad OpenID",
|
|
5
|
-
email: "Correo electrónico",
|
|
6
|
-
profile: "Nombre y avatar",
|
|
7
|
-
phone: "Número de teléfono",
|
|
8
|
-
offline_access: "Mantener el acceso sin conexión",
|
|
9
|
-
};
|
|
10
2
|
/**
|
|
11
3
|
* Whether a Scope's checkbox may not be cleared: the Client's Scope Policy requires it, or an
|
|
12
4
|
* active OAuth Grant on this Connection already covers it and clearing the box would promise a
|
|
@@ -16,14 +8,13 @@ const SCOPE_LABELS = {
|
|
|
16
8
|
export function ANDCO_CONSENT_SCOPE_IS_LOCKED(scope) {
|
|
17
9
|
return scope.mode === "required" || scope.grantedAt !== null;
|
|
18
10
|
}
|
|
19
|
-
/**
|
|
20
|
-
export function ANDCO_CONSENT_SCOPES(consent
|
|
11
|
+
/** Consent policies with provider-owned labels and selection state. */
|
|
12
|
+
export function ANDCO_CONSENT_SCOPES(consent) {
|
|
21
13
|
return consent.scopes.map((policy) => {
|
|
22
|
-
const label = SCOPE_LABELS[policy.scope];
|
|
23
14
|
return {
|
|
24
15
|
...policy,
|
|
25
|
-
title:
|
|
26
|
-
description:
|
|
16
|
+
title: policy.scopeDescription ?? policy.scope,
|
|
17
|
+
description: policy.resourceServerName,
|
|
27
18
|
required: policy.mode === "required",
|
|
28
19
|
default: policy.mode === "default",
|
|
29
20
|
// `optional` starts unchecked on a brand-new Connection (ADR 0040's "genuine consent"
|
|
@@ -58,13 +49,13 @@ export function ANDCO_CONSENT_INITIAL_SCOPES(consent) {
|
|
|
58
49
|
export function ANDCO_CONSENT_RESOURCE_SERVER_GROUPS(consent) {
|
|
59
50
|
return [...consent.resourceServers]
|
|
60
51
|
.sort((left, right) => left.resourcePosition - right.resourcePosition)
|
|
61
|
-
.map((server) =>
|
|
62
|
-
server
|
|
63
|
-
scopes: server.resource === ANDCO_API_ORIGIN
|
|
52
|
+
.map((server) => {
|
|
53
|
+
const scopes = server.resource === ANDCO_API_ORIGIN
|
|
64
54
|
? []
|
|
65
|
-
: consent.scopes.filter((scope) => scope.resourceServerId === server.resourceServerId)
|
|
66
|
-
resourceAuthorization
|
|
67
|
-
|
|
55
|
+
: consent.scopes.filter((scope) => scope.resourceServerId === server.resourceServerId);
|
|
56
|
+
const resourceAuthorization = consent.resourceAuthorizations.find((authorization) => authorization.resourceServerId === server.resourceServerId);
|
|
57
|
+
return { server, scopes, resourceAuthorization };
|
|
58
|
+
});
|
|
68
59
|
}
|
|
69
60
|
/** The scopes owned by the Resource Servers left out, which the decision never submits. */
|
|
70
61
|
function OMITTED_SCOPES(consent, omitted) {
|
package/dist/errors.d.ts
CHANGED
|
@@ -12,8 +12,7 @@
|
|
|
12
12
|
* through in silence.
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
15
|
-
* // Typed by the shape the example needs, so it reads the same
|
|
16
|
-
* // error is `AndCoSDKError`, and from `@andco/sdk`, whose error is `AndcoError`.
|
|
15
|
+
* // Typed by the shape the example needs, so it reads the same wherever the error comes from.
|
|
17
16
|
* function messageFor(error: { code: string }): string {
|
|
18
17
|
* switch (error.code) {
|
|
19
18
|
* case ANDCO_ERROR_CODES.POPUP_BLOCKED:
|
|
@@ -106,6 +105,11 @@ export declare const ANDCO_ERROR_CODES: {
|
|
|
106
105
|
readonly DEVICE_EXCHANGE_FAILED: "device_exchange_failed";
|
|
107
106
|
/** Exchanging a refresh token for a new session failed. The Grant may have been revoked. */
|
|
108
107
|
readonly REFRESH_FAILED: "refresh_failed";
|
|
108
|
+
/**
|
|
109
|
+
* `POST /oauth/revoke` (RFC 7009) did not answer 200: the token belongs to another client, the
|
|
110
|
+
* client could not authenticate, or the request never arrived. The token is kept, so retry.
|
|
111
|
+
*/
|
|
112
|
+
readonly REVOCATION_FAILED: "revocation_failed";
|
|
109
113
|
/** Fetching the OpenID Connect UserInfo endpoint failed. */
|
|
110
114
|
readonly USERINFO_FAILED: "userinfo_failed";
|
|
111
115
|
/** A callback could not be correlated with the transaction that started it, so it is not trusted. */
|
|
@@ -162,10 +166,45 @@ export declare class ErrorExtendable extends Error {
|
|
|
162
166
|
/** Checks whether a value is an instance of an error class. */
|
|
163
167
|
static is<T extends ErrorExtendable>(error: unknown, errorClass: new (...args: any[]) => T): error is T;
|
|
164
168
|
}
|
|
165
|
-
/**
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
169
|
+
/**
|
|
170
|
+
* The single error type every Andco operation reports.
|
|
171
|
+
*
|
|
172
|
+
* An integrator writes one `catch`-equivalent branch and compares one `code`, whether the failure
|
|
173
|
+
* came from authentication, an Intent, the resource API or the SDK itself. `code` is a plain string
|
|
174
|
+
* because it also carries codes this package does not own, such as the Authorization Server's OAuth
|
|
175
|
+
* error identifiers, and the same string identifies the same condition in the Python SDK.
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```ts
|
|
179
|
+
* const { data, error } = await andco.intents.get(intentId);
|
|
180
|
+
* if (error) {
|
|
181
|
+
* if (error.code === "insufficient_authorization") return reconnect();
|
|
182
|
+
* throw error;
|
|
183
|
+
* }
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
186
|
+
export declare class AndcoError extends Error {
|
|
187
|
+
/** Stable identifier. Branch on this, never on `message`. */
|
|
188
|
+
readonly code: string;
|
|
189
|
+
/** HTTP status when the error came from a response. */
|
|
190
|
+
readonly status: number | undefined;
|
|
191
|
+
/**
|
|
192
|
+
* The remaining fields of the error body.
|
|
193
|
+
*
|
|
194
|
+
* Andco reports more than a code — `required_scope` on an authorization failure, per-field notes
|
|
195
|
+
* on a rejected input. Branch on `code`, but surface these: without them an integrator can only
|
|
196
|
+
* tell a user that something failed, not which permission is missing.
|
|
197
|
+
*/
|
|
198
|
+
readonly details: Readonly<Record<string, unknown>> | undefined;
|
|
199
|
+
constructor(code: string, options?: {
|
|
200
|
+
message?: string;
|
|
201
|
+
status?: number;
|
|
202
|
+
cause?: unknown;
|
|
203
|
+
details?: Readonly<Record<string, unknown>>;
|
|
204
|
+
});
|
|
205
|
+
/** Normalizes anything thrown by a dependency into an `AndcoError`. */
|
|
206
|
+
static from(cause: unknown, fallbackCode: AndcoErrorCode): AndcoError;
|
|
207
|
+
/** Whether a value is an `AndcoError`. */
|
|
208
|
+
static is(cause: unknown): cause is AndcoError;
|
|
170
209
|
}
|
|
171
210
|
//# sourceMappingURL=errors.d.ts.map
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,eAAO,MAAM,iBAAiB;IAE5B,uGAAuG;;IAEvG,6EAA6E;;IAE7E,uGAAuG;;IAEvG,6DAA6D;;IAE7D,wFAAwF;;IAMxF,+GAA+G;;IAE/G,wEAAwE;;IAExE,6DAA6D;;IAE7D,0DAA0D;;IAE1D,iEAAiE;;IAEjE,wGAAwG;;IAExG,mEAAmE;;IAEnE,8EAA8E;;IAE9E,uEAAuE;;IAEvE,8DAA8D;;IAE9D,6EAA6E;;IAE7E,uGAAuG;;IAIvG;;;OAGG;;IAEH,yFAAyF;;IAEzF,+EAA+E;;IAE/E,mEAAmE;;IAEnE,qEAAqE;;IAErE,sGAAsG;;IAEtG,sFAAsF;;IAEtF;;;OAGG;;IAEH;;;;OAIG;;IAIH,sGAAsG;;IAEtG,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,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;KAAO;IASnH,uEAAuE;WACzD,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,cAAc,GAAG,UAAU;IAM5E,0CAA0C;WAC5B,EAAE,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,UAAU;CAGtD"}
|
package/dist/errors.js
CHANGED
|
@@ -12,8 +12,7 @@
|
|
|
12
12
|
* through in silence.
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
15
|
-
* // Typed by the shape the example needs, so it reads the same
|
|
16
|
-
* // error is `AndCoSDKError`, and from `@andco/sdk`, whose error is `AndcoError`.
|
|
15
|
+
* // Typed by the shape the example needs, so it reads the same wherever the error comes from.
|
|
17
16
|
* function messageFor(error: { code: string }): string {
|
|
18
17
|
* switch (error.code) {
|
|
19
18
|
* case ANDCO_ERROR_CODES.POPUP_BLOCKED:
|
|
@@ -112,6 +111,11 @@ export const ANDCO_ERROR_CODES = {
|
|
|
112
111
|
DEVICE_EXCHANGE_FAILED: "device_exchange_failed",
|
|
113
112
|
/** Exchanging a refresh token for a new session failed. The Grant may have been revoked. */
|
|
114
113
|
REFRESH_FAILED: "refresh_failed",
|
|
114
|
+
/**
|
|
115
|
+
* `POST /oauth/revoke` (RFC 7009) did not answer 200: the token belongs to another client, the
|
|
116
|
+
* client could not authenticate, or the request never arrived. The token is kept, so retry.
|
|
117
|
+
*/
|
|
118
|
+
REVOCATION_FAILED: "revocation_failed",
|
|
115
119
|
/** Fetching the OpenID Connect UserInfo endpoint failed. */
|
|
116
120
|
USERINFO_FAILED: "userinfo_failed",
|
|
117
121
|
/** A callback could not be correlated with the transaction that started it, so it is not trusted. */
|
|
@@ -190,13 +194,52 @@ export class ErrorExtendable extends Error {
|
|
|
190
194
|
return error instanceof errorClass;
|
|
191
195
|
}
|
|
192
196
|
}
|
|
193
|
-
/**
|
|
194
|
-
|
|
197
|
+
/**
|
|
198
|
+
* The single error type every Andco operation reports.
|
|
199
|
+
*
|
|
200
|
+
* An integrator writes one `catch`-equivalent branch and compares one `code`, whether the failure
|
|
201
|
+
* came from authentication, an Intent, the resource API or the SDK itself. `code` is a plain string
|
|
202
|
+
* because it also carries codes this package does not own, such as the Authorization Server's OAuth
|
|
203
|
+
* error identifiers, and the same string identifies the same condition in the Python SDK.
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```ts
|
|
207
|
+
* const { data, error } = await andco.intents.get(intentId);
|
|
208
|
+
* if (error) {
|
|
209
|
+
* if (error.code === "insufficient_authorization") return reconnect();
|
|
210
|
+
* throw error;
|
|
211
|
+
* }
|
|
212
|
+
* ```
|
|
213
|
+
*/
|
|
214
|
+
export class AndcoError extends Error {
|
|
215
|
+
/** Stable identifier. Branch on this, never on `message`. */
|
|
195
216
|
code;
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
217
|
+
/** HTTP status when the error came from a response. */
|
|
218
|
+
status;
|
|
219
|
+
/**
|
|
220
|
+
* The remaining fields of the error body.
|
|
221
|
+
*
|
|
222
|
+
* Andco reports more than a code — `required_scope` on an authorization failure, per-field notes
|
|
223
|
+
* on a rejected input. Branch on `code`, but surface these: without them an integrator can only
|
|
224
|
+
* tell a user that something failed, not which permission is missing.
|
|
225
|
+
*/
|
|
226
|
+
details;
|
|
227
|
+
constructor(code, options = {}) {
|
|
228
|
+
super(options.message ?? code, options.cause === undefined ? undefined : { cause: options.cause });
|
|
229
|
+
this.name = "AndcoError";
|
|
199
230
|
this.code = code;
|
|
200
|
-
this.
|
|
231
|
+
this.status = options.status;
|
|
232
|
+
this.details = options.details;
|
|
233
|
+
}
|
|
234
|
+
/** Normalizes anything thrown by a dependency into an `AndcoError`. */
|
|
235
|
+
static from(cause, fallbackCode) {
|
|
236
|
+
if (AndcoError.is(cause))
|
|
237
|
+
return cause;
|
|
238
|
+
const message = cause instanceof Error ? cause.message : undefined;
|
|
239
|
+
return new AndcoError(fallbackCode, { message, cause });
|
|
240
|
+
}
|
|
241
|
+
/** Whether a value is an `AndcoError`. */
|
|
242
|
+
static is(cause) {
|
|
243
|
+
return cause instanceof AndcoError;
|
|
201
244
|
}
|
|
202
245
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format-money.d.ts","sourceRoot":"","sources":["../src/format-money.ts"],"names":[],"mappings":"AAAA,iEAAiE;AACjE,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,SAAU,GAAG,MAAM,CAI5F"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Formats monetary strings without rounding unsafe integers. */
|
|
2
|
+
export function ANDCO_FORMAT_MONEY(value, currency, locale = "es-CL") {
|
|
3
|
+
const amount = Number(value);
|
|
4
|
+
if (!Number.isSafeInteger(amount))
|
|
5
|
+
return `${value} ${currency}`;
|
|
6
|
+
return new Intl.NumberFormat(locale, { style: "currency", currency, maximumFractionDigits: 0 }).format(amount);
|
|
7
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export * from "./callback-state.js";
|
|
|
5
5
|
export * from "./consent.js";
|
|
6
6
|
export * from "./constants.js";
|
|
7
7
|
export * from "./errors.js";
|
|
8
|
+
export * from "./format-money.js";
|
|
8
9
|
export * from "./intent-input.js";
|
|
9
10
|
export * from "./messages/base.js";
|
|
10
11
|
export * from "./messages/click.js";
|
|
@@ -18,9 +19,9 @@ export * from "./messages/set-preferences.js";
|
|
|
18
19
|
export * from "./miniapp-icon.js";
|
|
19
20
|
export * from "./miniapp-manifest.js";
|
|
20
21
|
export * from "./native.js";
|
|
21
|
-
export * from "./native-copy.js";
|
|
22
22
|
export * from "./native-intent.js";
|
|
23
23
|
export * from "./oauth.js";
|
|
24
|
+
export * from "./pagination.js";
|
|
24
25
|
export * from "./rar/index.js";
|
|
25
26
|
export * from "./release.js";
|
|
26
27
|
export * from "./scopes.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qCAAqC,CAAC;AACpD,cAAc,qBAAqB,CAAC;AACpC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qCAAqC,CAAC;AACpD,cAAc,qBAAqB,CAAC;AACpC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,OAAO,EACL,uBAAuB,EACvB,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,SAAS,EACT,kBAAkB,GACnB,MAAM,sBAAsB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -5,6 +5,7 @@ export * from "./callback-state.js";
|
|
|
5
5
|
export * from "./consent.js";
|
|
6
6
|
export * from "./constants.js";
|
|
7
7
|
export * from "./errors.js";
|
|
8
|
+
export * from "./format-money.js";
|
|
8
9
|
export * from "./intent-input.js";
|
|
9
10
|
export * from "./messages/base.js";
|
|
10
11
|
export * from "./messages/click.js";
|
|
@@ -18,9 +19,9 @@ export * from "./messages/set-preferences.js";
|
|
|
18
19
|
export * from "./miniapp-icon.js";
|
|
19
20
|
export * from "./miniapp-manifest.js";
|
|
20
21
|
export * from "./native.js";
|
|
21
|
-
export * from "./native-copy.js";
|
|
22
22
|
export * from "./native-intent.js";
|
|
23
23
|
export * from "./oauth.js";
|
|
24
|
+
export * from "./pagination.js";
|
|
24
25
|
export * from "./rar/index.js";
|
|
25
26
|
export * from "./release.js";
|
|
26
27
|
export * from "./scopes.js";
|