@andco/protocol 0.0.13 → 0.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/README.md +2 -2
  2. package/dist/api-errors.d.ts +9 -9
  3. package/dist/api-errors.js +9 -9
  4. package/dist/authorization-preparation.js +2 -2
  5. package/dist/authorization.d.ts +1 -1
  6. package/dist/authorization.js +1 -1
  7. package/dist/consent.d.ts +2 -2
  8. package/dist/consent.js +2 -2
  9. package/dist/constants.d.ts +15 -2
  10. package/dist/constants.d.ts.map +1 -1
  11. package/dist/constants.js +17 -3
  12. package/dist/errors.d.ts +36 -9
  13. package/dist/errors.d.ts.map +1 -1
  14. package/dist/errors.js +49 -11
  15. package/dist/index.d.ts +1 -0
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +1 -0
  18. package/dist/intent-input.d.ts +431 -872
  19. package/dist/intent-input.d.ts.map +1 -1
  20. package/dist/intent-input.js +142 -121
  21. package/dist/miniapp-icon.js +1 -1
  22. package/dist/miniapp-manifest.d.ts +1 -1
  23. package/dist/native-intent.d.ts +82 -68
  24. package/dist/native-intent.d.ts.map +1 -1
  25. package/dist/native-intent.js +134 -84
  26. package/dist/native.d.ts +1 -1
  27. package/dist/rar/account-matchers.d.ts +35 -30
  28. package/dist/rar/account-matchers.d.ts.map +1 -1
  29. package/dist/rar/account-matchers.js +27 -21
  30. package/dist/rar/bank.d.ts +81 -81
  31. package/dist/rar/bank.js +1 -1
  32. package/dist/rar/catalog.d.ts +48 -48
  33. package/dist/rar/catalog.js +6 -6
  34. package/dist/rar/detail.d.ts +1 -1
  35. package/dist/rar/detail.js +1 -1
  36. package/dist/rar/json-schemas.generated.d.ts +1 -1
  37. package/dist/rar/json-schemas.generated.d.ts.map +1 -1
  38. package/dist/rar/json-schemas.generated.js +25 -21
  39. package/dist/rar/subject-data.d.ts +1 -1
  40. package/dist/rar/subject-data.js +1 -1
  41. package/dist/rar/subject.d.ts +1 -1
  42. package/dist/rar/subject.js +1 -1
  43. package/dist/rest/accounts.d.ts +28 -28
  44. package/dist/rest/accounts.d.ts.map +1 -1
  45. package/dist/rest/accounts.js +22 -22
  46. package/dist/rest/api-error.d.ts +1 -1
  47. package/dist/rest/api-error.js +1 -1
  48. package/dist/rest/catalog.d.ts +3 -3
  49. package/dist/rest/catalog.js +2 -2
  50. package/dist/rest/common.d.ts +3 -3
  51. package/dist/rest/common.js +3 -3
  52. package/dist/rest/contract.d.ts +905 -528
  53. package/dist/rest/contract.d.ts.map +1 -1
  54. package/dist/rest/contract.js +17 -5
  55. package/dist/rest/events.d.ts +1 -1
  56. package/dist/rest/events.d.ts.map +1 -1
  57. package/dist/rest/events.js +2 -2
  58. package/dist/rest/identity.d.ts +22 -22
  59. package/dist/rest/identity.js +5 -5
  60. package/dist/rest/index.d.ts +1 -0
  61. package/dist/rest/index.d.ts.map +1 -1
  62. package/dist/rest/index.js +1 -0
  63. package/dist/rest/intents.d.ts +787 -716
  64. package/dist/rest/intents.d.ts.map +1 -1
  65. package/dist/rest/intents.js +62 -53
  66. package/dist/rest/signatures.d.ts +11 -5
  67. package/dist/rest/signatures.d.ts.map +1 -1
  68. package/dist/rest/signatures.js +10 -0
  69. package/dist/rest/subjects.d.ts +1 -1
  70. package/dist/rest/subjects.d.ts.map +1 -1
  71. package/dist/rest/subjects.js +3 -2
  72. package/dist/rest/transfers.d.ts +612 -0
  73. package/dist/rest/transfers.d.ts.map +1 -0
  74. package/dist/rest/transfers.js +115 -0
  75. package/dist/scopes.d.ts +1 -1
  76. package/dist/signing.d.ts +13 -2
  77. package/dist/signing.d.ts.map +1 -1
  78. package/dist/signing.js +13 -0
  79. package/dist/transfer.d.ts +363 -0
  80. package/dist/transfer.d.ts.map +1 -0
  81. package/dist/transfer.js +287 -0
  82. package/dist/transport/financial-events.d.ts +21 -17
  83. package/dist/transport/financial-events.d.ts.map +1 -1
  84. package/dist/transport/generated/oauth-api.d.ts +1017 -194
  85. package/dist/transport/generated/oauth-api.d.ts.map +1 -1
  86. package/dist/transport/intents.d.ts +28 -12
  87. package/dist/transport/intents.d.ts.map +1 -1
  88. package/dist/transport/intents.js +1 -1
  89. package/dist/transport/rest.d.ts +4 -4
  90. package/dist/transport/rest.d.ts.map +1 -1
  91. package/dist/transport/rest.js +33 -4
  92. package/dist/urls.d.ts +25 -2
  93. package/dist/urls.d.ts.map +1 -1
  94. package/dist/urls.js +47 -4
  95. package/dist/userinfo.d.ts +2 -2
  96. package/dist/userinfo.js +2 -2
  97. package/dist/webhooks.d.ts +19 -15
  98. package/dist/webhooks.d.ts.map +1 -1
  99. package/dist/webhooks.js +17 -15
  100. package/dist/window-features.d.ts +2 -2
  101. package/dist/window-features.js +2 -2
  102. package/package.json +2 -2
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # `@andco/protocol`
2
2
 
3
- Shared protocol schemas, validators, OAuth helpers, message contracts, typed transport, and webhook verification used by the Andco SDK.
3
+ Shared protocol schemas, validators, OAuth helpers, message contracts, typed transport, and webhook verification used by the AndCo SDK.
4
4
 
5
5
  Developer preview: APIs may change before 1.0.
6
6
 
@@ -31,7 +31,7 @@ const detail = parseAndcoGrantRequest({
31
31
  - Compose resource-specific authorization and resolve GET/PAR transport.
32
32
  - Share hosted iframe and native authorization message contracts.
33
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.
34
+ - Use `@andco/protocol/webhooks` to verify AndCo's Ed25519 webhook signatures and parse lifecycle events.
35
35
 
36
36
  Schemas and helpers are runtime-neutral; portable crypto helpers use Web Crypto. The SDK wraps these contracts with sessions and operations.
37
37
 
@@ -1,6 +1,6 @@
1
1
  /**
2
- * Why a subject's connection with the bank needs the person back, sent as `code` next to
3
- * `interaction_required` (409), on a read, a bank command, and the release of an Intent (where
2
+ * Why a subject's connection with AndCo needs the person back, sent as `code` next to
3
+ * `interaction_required` (409), on a read, a command to AndCo, and the release of an Intent (where
4
4
  * `reason` carries it instead of `code`, and `intent_id` names the Intent). The Grant is intact in every
5
5
  * case: once the person does what the code names, at `interaction_url`, the same request
6
6
  * succeeds.
@@ -17,19 +17,19 @@
17
17
  */
18
18
  export declare const ANDCO_BANK_CONNECTION_ERROR_CODES: {
19
19
  /**
20
- * The bank ended the session Andco operates the account with, and the person brings it back by
21
- * typing their web PIN. Happens when nobody could keep the session alive for seven days, or when
22
- * the bank's answer to a renewal was lost.
20
+ * AndCo ended the session AndCo operates the account with, and the person brings it back by
21
+ * typing their web AndPass. Happens when nobody could keep the session alive for seven days, or when
22
+ * AndCo's answer to a renewal was lost.
23
23
  */
24
24
  readonly PIN_REQUIRED: "bank_connection_pin_required";
25
25
  /**
26
- * The account is no longer connected to the web: the person disconnected it, or the bank revoked
27
- * the web's access. The person has to connect the account again, identity validation included.
26
+ * The account is no longer connected to the web: the person disconnected it, or AndCo revoked
27
+ * the web's access. The person has to connect the account again, identity verification included.
28
28
  */
29
29
  readonly RECONNECT_REQUIRED: "bank_connection_reconnect_required";
30
30
  /**
31
- * The Organization's bank representative can no longer act for it. The Organization has to
32
- * connect another bank representative, and then the same request succeeds.
31
+ * The Organization's account representative can no longer act for it. The Organization has to
32
+ * connect another account representative, and then the same request succeeds.
33
33
  */
34
34
  readonly REPRESENTATIVE_REPLACEMENT_REQUIRED: "bank_representative_replacement_required";
35
35
  };
@@ -1,6 +1,6 @@
1
1
  /**
2
- * Why a subject's connection with the bank needs the person back, sent as `code` next to
3
- * `interaction_required` (409), on a read, a bank command, and the release of an Intent (where
2
+ * Why a subject's connection with AndCo needs the person back, sent as `code` next to
3
+ * `interaction_required` (409), on a read, a command to AndCo, and the release of an Intent (where
4
4
  * `reason` carries it instead of `code`, and `intent_id` names the Intent). The Grant is intact in every
5
5
  * case: once the person does what the code names, at `interaction_url`, the same request
6
6
  * succeeds.
@@ -17,19 +17,19 @@
17
17
  */
18
18
  export const ANDCO_BANK_CONNECTION_ERROR_CODES = {
19
19
  /**
20
- * The bank ended the session Andco operates the account with, and the person brings it back by
21
- * typing their web PIN. Happens when nobody could keep the session alive for seven days, or when
22
- * the bank's answer to a renewal was lost.
20
+ * AndCo ended the session AndCo operates the account with, and the person brings it back by
21
+ * typing their web AndPass. Happens when nobody could keep the session alive for seven days, or when
22
+ * AndCo's answer to a renewal was lost.
23
23
  */
24
24
  PIN_REQUIRED: "bank_connection_pin_required",
25
25
  /**
26
- * The account is no longer connected to the web: the person disconnected it, or the bank revoked
27
- * the web's access. The person has to connect the account again, identity validation included.
26
+ * The account is no longer connected to the web: the person disconnected it, or AndCo revoked
27
+ * the web's access. The person has to connect the account again, identity verification included.
28
28
  */
29
29
  RECONNECT_REQUIRED: "bank_connection_reconnect_required",
30
30
  /**
31
- * The Organization's bank representative can no longer act for it. The Organization has to
32
- * connect another bank representative, and then the same request succeeds.
31
+ * The Organization's account representative can no longer act for it. The Organization has to
32
+ * connect another account representative, and then the same request succeeds.
33
33
  */
34
34
  REPRESENTATIVE_REPLACEMENT_REQUIRED: "bank_representative_replacement_required",
35
35
  };
@@ -67,8 +67,8 @@ const AndCoAuthorizationClientSchema = /* @__PURE__ */ v.object({
67
67
  uri: v.string(),
68
68
  logoUri: v.string(),
69
69
  });
70
- // `identity_validation` is the Validación de identidad an `identity` detail asks for with
71
- // `validation: { required: true }`. Andco's authorization details are consented on the web only, so a
70
+ // `identity_validation` is the Verificación de identidad an `identity` detail asks for with
71
+ // `validation: { required: true }`. AndCo's authorization details are consented on the web only, so a
72
72
  // native Host never receives it.
73
73
  const OAuthPrerequisiteRequirementSchema = /* @__PURE__ */ v.picklist([
74
74
  "phone",
@@ -103,7 +103,7 @@ export declare const ANDCO_MAX_ORGANIZATION_ID = 2147483647;
103
103
  /**
104
104
  * Composes Resource Server contributions without losing their audience association.
105
105
  *
106
- * Every detail, Andco's or a third party's, names whose resources it asks for in its own `subject`
106
+ * Every detail, AndCo's or a third party's, names whose resources it asks for in its own `subject`
107
107
  * (`{ type: "profile" }`, `{ type: "organization", identifier? }`, or absent for the signed-in
108
108
  * Profile). The plan binds each detail to its Resource Server through `locations` and refuses, with
109
109
  * `not_implemented`, details that name different subjects: the Authorization Server answers the
@@ -67,7 +67,7 @@ const PushedAuthorizationResponseSchema = /* @__PURE__ */ v.object({
67
67
  /**
68
68
  * Composes Resource Server contributions without losing their audience association.
69
69
  *
70
- * Every detail, Andco's or a third party's, names whose resources it asks for in its own `subject`
70
+ * Every detail, AndCo's or a third party's, names whose resources it asks for in its own `subject`
71
71
  * (`{ type: "profile" }`, `{ type: "organization", identifier? }`, or absent for the signed-in
72
72
  * Profile). The plan binds each detail to its Resource Server through `locations` and refuses, with
73
73
  * `not_implemented`, details that name different subjects: the Authorization Server answers the
package/dist/consent.d.ts CHANGED
@@ -41,12 +41,12 @@ export declare function ANDCO_CONSENT_INITIAL_SCOPES(consent: Extract<AndCoAutho
41
41
  /**
42
42
  * Groups a consent by Resource Server, in the order of the request's `resource` parameters: each one
43
43
  * with its own scopes and, for a third party asked for details, its live decision. OpenID Connect
44
- * scopes come through the Andco API's policies but belong to the Identity Session, so the Andco API's
44
+ * scopes come through the AndCo API's policies but belong to the Identity Session, so the AndCo API's
45
45
  * group owns none of them; they stay in `consent.scopes` for the identity section.
46
46
  *
47
47
  * @example
48
48
  * const groups = ANDCO_CONSENT_RESOURCE_SERVER_GROUPS(consent);
49
- * groups.map((group) => group.server.resourceServerName); // ["Andco API", "Casa Norte Ecommerce"]
49
+ * groups.map((group) => group.server.resourceServerName); // ["AndCo API", "Casa Norte Ecommerce"]
50
50
  */
51
51
  export declare function ANDCO_CONSENT_RESOURCE_SERVER_GROUPS(consent: PreparedConsent): {
52
52
  server: {
package/dist/consent.js CHANGED
@@ -39,12 +39,12 @@ export function ANDCO_CONSENT_INITIAL_SCOPES(consent) {
39
39
  /**
40
40
  * Groups a consent by Resource Server, in the order of the request's `resource` parameters: each one
41
41
  * with its own scopes and, for a third party asked for details, its live decision. OpenID Connect
42
- * scopes come through the Andco API's policies but belong to the Identity Session, so the Andco API's
42
+ * scopes come through the AndCo API's policies but belong to the Identity Session, so the AndCo API's
43
43
  * group owns none of them; they stay in `consent.scopes` for the identity section.
44
44
  *
45
45
  * @example
46
46
  * const groups = ANDCO_CONSENT_RESOURCE_SERVER_GROUPS(consent);
47
- * groups.map((group) => group.server.resourceServerName); // ["Andco API", "Casa Norte Ecommerce"]
47
+ * groups.map((group) => group.server.resourceServerName); // ["AndCo API", "Casa Norte Ecommerce"]
48
48
  */
49
49
  export function ANDCO_CONSENT_RESOURCE_SERVER_GROUPS(consent) {
50
50
  return [...consent.resourceServers]
@@ -26,8 +26,21 @@ export declare const ANDCO_INTENT_PROPOSAL_MEDIA_TYPE: "application/json";
26
26
  * server answers `400 idempotency_key_not_allowed` when a second candidate arrives beside it.
27
27
  */
28
28
  export declare const ANDCO_SIGNED_INSTRUCTION_MEDIA_TYPE: "application/jwt";
29
- /** Returns the base URL for one OAuth resource API version. `_` resolves to the latest version. */
29
+ /**
30
+ * Returns the base URL for one OAuth resource API version under an API endpoint, which keeps its own
31
+ * path. `_` resolves to the latest version.
32
+ *
33
+ * @throws {TypeError} When `endpoint` is not an {@link EndpointURL}.
34
+ * @example
35
+ * ANDCO_OAUTH_API_URL("https://api.andco.com/prefix"); // "https://api.andco.com/prefix/oauth/api/versions/_"
36
+ */
30
37
  export declare function ANDCO_OAUTH_API_URL(endpoint: string | URL, version?: string | number): string;
31
- /** Returns the versioned OAuth UserInfo endpoint for an AndCo API origin. `_` resolves to the latest version. */
38
+ /** Returns the versioned OAuth UserInfo endpoint for an AndCo API endpoint. `_` resolves to the latest version. */
32
39
  export declare function ANDCO_OAUTH_USERINFO_URL(endpoint: string | URL, version?: string): string;
40
+ /**
41
+ * An Organization identifier as a path parameter: a positive integer, with no leading zero, up to
42
+ * `ANDCO_MAX_ORGANIZATION_ID` (2147483647). The bound is written digit by digit because JSON Schema
43
+ * cannot compare a string as a number (ADR 0037), and so the OpenAPI document carries it too.
44
+ */
45
+ export declare const ORGANIZATION_ID_PARAMETER_PATTERN = "^(?:[1-9][0-9]{0,8}|1[0-9]{9}|20[0-9]{8}|21[0-3][0-9]{7}|214[0-6][0-9]{6}|2147[0-3][0-9]{5}|21474[0-7][0-9]{4}|214748[0-2][0-9]{3}|2147483[0-5][0-9]{2}|21474836[0-3][0-9]|214748364[0-7])$";
33
46
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,oDAAoD;AACpD,eAAO,MAAM,kBAAkB,EAAG,WAAoB,CAAC;AACvD,qDAAqD;AACrD,eAAO,MAAM,sBAAsB,EAAG,CAAU,CAAC;AACjD,wDAAwD;AACxD,eAAO,MAAM,iBAAiB,EAAG,wBAAiC,CAAC;AACnE,mDAAmD;AACnD,eAAO,MAAM,gBAAgB,EAAG,uBAAgC,CAAC;AACjE,4EAA4E;AAC5E,eAAO,MAAM,mBAAmB,EAAG,2BAAoC,CAAC;AACxE,gEAAgE;AAChE,eAAO,MAAM,uBAAuB,EAAG,YAAqB,CAAC;AAC7D;;;;;;GAMG;AACH,eAAO,MAAM,gCAAgC,EAAG,kBAA2B,CAAC;AAC5E;;;;;;GAMG;AACH,eAAO,MAAM,mCAAmC,EAAG,iBAA0B,CAAC;AAC9E,mGAAmG;AACnG,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,EAAE,OAAO,GAAE,MAAM,GAAG,MAAY,GAAG,MAAM,CAElG;AACD,iHAAiH;AACjH,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,EAAE,OAAO,SAAM,GAAG,MAAM,CAEtF"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAEA,oDAAoD;AACpD,eAAO,MAAM,kBAAkB,EAAG,WAAoB,CAAC;AACvD,qDAAqD;AACrD,eAAO,MAAM,sBAAsB,EAAG,CAAU,CAAC;AACjD,wDAAwD;AACxD,eAAO,MAAM,iBAAiB,EAAG,wBAAiC,CAAC;AACnE,mDAAmD;AACnD,eAAO,MAAM,gBAAgB,EAAG,uBAAgC,CAAC;AACjE,4EAA4E;AAC5E,eAAO,MAAM,mBAAmB,EAAG,2BAAoC,CAAC;AACxE,gEAAgE;AAChE,eAAO,MAAM,uBAAuB,EAAG,YAAqB,CAAC;AAC7D;;;;;;GAMG;AACH,eAAO,MAAM,gCAAgC,EAAG,kBAA2B,CAAC;AAC5E;;;;;;GAMG;AACH,eAAO,MAAM,mCAAmC,EAAG,iBAA0B,CAAC;AAC9E;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,EAAE,OAAO,GAAE,MAAM,GAAG,MAAY,GAAG,MAAM,CAElG;AACD,mHAAmH;AACnH,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,EAAE,OAAO,SAAM,GAAG,MAAM,CAEtF;AAED;;;;GAIG;AACH,eAAO,MAAM,iCAAiC,gMACiJ,CAAC"}
package/dist/constants.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { EndpointURL } from "./urls.js";
1
2
  /** Protocol identifier used by the AndCo bridge. */
2
3
  export const ANDCO_SDK_PROTOCOL = "andco:sdk";
3
4
  /** Current version of the AndCo message protocol. */
@@ -26,11 +27,24 @@ export const ANDCO_INTENT_PROPOSAL_MEDIA_TYPE = "application/json";
26
27
  * server answers `400 idempotency_key_not_allowed` when a second candidate arrives beside it.
27
28
  */
28
29
  export const ANDCO_SIGNED_INSTRUCTION_MEDIA_TYPE = "application/jwt";
29
- /** Returns the base URL for one OAuth resource API version. `_` resolves to the latest version. */
30
+ /**
31
+ * Returns the base URL for one OAuth resource API version under an API endpoint, which keeps its own
32
+ * path. `_` resolves to the latest version.
33
+ *
34
+ * @throws {TypeError} When `endpoint` is not an {@link EndpointURL}.
35
+ * @example
36
+ * ANDCO_OAUTH_API_URL("https://api.andco.com/prefix"); // "https://api.andco.com/prefix/oauth/api/versions/_"
37
+ */
30
38
  export function ANDCO_OAUTH_API_URL(endpoint, version = "_") {
31
- return new URL(`/oauth/api/versions/${version}`, endpoint).href;
39
+ return new EndpointURL(endpoint).join(`oauth/api/versions/${version}`).href;
32
40
  }
33
- /** Returns the versioned OAuth UserInfo endpoint for an AndCo API origin. `_` resolves to the latest version. */
41
+ /** Returns the versioned OAuth UserInfo endpoint for an AndCo API endpoint. `_` resolves to the latest version. */
34
42
  export function ANDCO_OAUTH_USERINFO_URL(endpoint, version = "_") {
35
43
  return new URL(`${ANDCO_OAUTH_API_URL(endpoint, version)}/userinfo`).href;
36
44
  }
45
+ /**
46
+ * An Organization identifier as a path parameter: a positive integer, with no leading zero, up to
47
+ * `ANDCO_MAX_ORGANIZATION_ID` (2147483647). The bound is written digit by digit because JSON Schema
48
+ * cannot compare a string as a number (ADR 0037), and so the OpenAPI document carries it too.
49
+ */
50
+ export const ORGANIZATION_ID_PARAMETER_PATTERN = "^(?:[1-9][0-9]{0,8}|1[0-9]{9}|20[0-9]{8}|21[0-3][0-9]{7}|214[0-6][0-9]{6}|2147[0-3][0-9]{5}|21474[0-7][0-9]{4}|214748[0-2][0-9]{3}|2147483[0-5][0-9]{2}|21474836[0-3][0-9]|214748364[0-7])$";
package/dist/errors.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { GrantedOrganizationSubject } from "./rar/subject.js";
2
2
  /**
3
- * Conditions Andco's own client code detects, in the shape the Andco API already uses for the codes
3
+ * Conditions AndCo's own client code detects, in the shape the AndCo API already uses for the codes
4
4
  * it sends: lower snake_case, no prefix. Both vocabularies end up in the same `error.code` field, so
5
5
  * an integrator should not have to remember which half of a failure produced the string in hand.
6
6
  *
@@ -24,7 +24,7 @@ import type { GrantedOrganizationSubject } from "./rar/subject.js";
24
24
  * return "Tu sesión expiró. Vuelve a ingresar.";
25
25
  * default:
26
26
  * // A code this build does not know about: report it, never swallow it.
27
- * console.error("[messageFor] unhandled Andco error code: %s", error.code);
27
+ * console.error("[messageFor] unhandled AndCo error code: %s", error.code);
28
28
  * return "No pudimos completar la operación.";
29
29
  * }
30
30
  * }
@@ -46,7 +46,7 @@ export declare const ANDCO_ERROR_CODES: {
46
46
  readonly INVALID_CONFIGURATION: "invalid_configuration";
47
47
  /** The configured Authorization Server endpoint is not a usable URL. */
48
48
  readonly INVALID_ENDPOINT_AUTH: "invalid_endpoint_auth";
49
- /** The configured Andco API endpoint is not a usable URL. */
49
+ /** The configured AndCo API endpoint is not a usable URL. */
50
50
  readonly INVALID_ENDPOINT_API: "invalid_endpoint_api";
51
51
  /** The configured button endpoint is not a usable URL. */
52
52
  readonly INVALID_ENDPOINT_BUTTON: "invalid_endpoint_button";
@@ -56,7 +56,7 @@ export declare const ANDCO_ERROR_CODES: {
56
56
  readonly INVALID_REDIRECT_TO: "invalid_redirect_to";
57
57
  /** The requested authentication mode is not one the SDK offers. */
58
58
  readonly INVALID_AUTH_MODE: "invalid_auth_mode";
59
- /** At least one requested permission scope is not a scope Andco publishes. */
59
+ /** At least one requested permission scope is not a scope AndCo publishes. */
60
60
  readonly INVALID_SCOPE: "invalid_scope";
61
61
  /** The requested SDK protocol version is not one this build speaks. */
62
62
  readonly INVALID_VERSION: "invalid_version";
@@ -105,7 +105,7 @@ export declare const ANDCO_ERROR_CODES: {
105
105
  */
106
106
  readonly AUTHORIZATION_FACTORY_FAILED: "authorization_factory_failed";
107
107
  /**
108
- * The authorization needs a bank account that is not open yet, because the bank is still
108
+ * The authorization needs a digital account that is not open yet, because AndCo is still
109
109
  * reviewing its opening. The Authorization Server ends the authorization with
110
110
  * `error=access_denied&error_description=bank_account_pending_review`.
111
111
  *
@@ -118,7 +118,7 @@ export declare const ANDCO_ERROR_CODES: {
118
118
  * account. The Authorization Server ends it with
119
119
  * `error=access_denied&error_description=authorization_expired`.
120
120
  *
121
- * Not a cancellation. Start a new authorization; the progress made on the bank side is kept.
121
+ * Not a cancellation. Start a new authorization; the progress made on the AndCo side is kept.
122
122
  */
123
123
  readonly AUTHORIZATION_EXPIRED: "authorization_expired";
124
124
  /**
@@ -254,12 +254,39 @@ export declare const ANDCO_ACCESS_DENIED_WITHOUT_DECISION: readonly ["bank_accou
254
254
  * condition rather than a person's decision. Such a redirect is an error, never a dismissal.
255
255
  */
256
256
  export declare function isAuthorizationEndedWithoutDecision(error: string | null | undefined, description: string | null | undefined): description is (typeof ANDCO_ACCESS_DENIED_WITHOUT_DECISION)[number];
257
+ /**
258
+ * What an authorization callback's `error` must look like for the SDK to report it as the error's
259
+ * code: ASCII letters, digits, `_`, `.` and `-`, 1 to 128 of them. Any other value (empty, a
260
+ * character outside the set, or longer) is `invalid_callback`, and its message does not repeat the
261
+ * value, which the URL's author controls. Every AndCo SDK (JavaScript, Go, Python and Ruby) checks
262
+ * the callback's `error` against this same pattern; the shared cases are the `oauth_error_code`
263
+ * section of the conformance vectors.
264
+ *
265
+ * @see https://github.com/haulmer/andco-sdk-js/blob/main/docs/adr/0042-check-the-oauth-callback-error-code-against-one-pattern-in-every-sdk.md
266
+ */
267
+ export declare const OAUTH_ERROR_CODE_PATTERN = "^[A-Za-z0-9_.-]{1,128}$";
268
+ /**
269
+ * The authorization callback's parameters that carry one value: each appears at most once and, when
270
+ * it appears, is not empty. A callback that repeats one or leaves it empty is `invalid_callback`,
271
+ * whatever else it carries, since two readers of the same URL could otherwise act on different
272
+ * values. Every AndCo SDK (JavaScript, Go, Python and Ruby) refuses such a callback the same way;
273
+ * the shared cases are the `oauth_callback_parameters` section of the conformance vectors.
274
+ *
275
+ * @see https://github.com/haulmer/andco-sdk-js/blob/main/docs/adr/0044-reject-a-repeated-or-empty-oauth-callback-parameter-in-every-sdk.md
276
+ */
277
+ export declare const OAUTH_CALLBACK_SINGLE_VALUE_PARAMETERS: readonly ["state", "code", "error"];
278
+ /**
279
+ * Whether a callback's query repeats one of {@link OAUTH_CALLBACK_SINGLE_VALUE_PARAMETERS}, or of
280
+ * `names` when given, or leaves it empty.
281
+ */
282
+ export declare function hasRepeatedOrEmptyCallbackParameter(parameters: URLSearchParams, names?: readonly string[]): boolean;
257
283
  /**
258
284
  * Builds the error for an authorization redirect that carries `error`.
259
285
  *
260
286
  * `access_denied` with one of {@link ANDCO_ACCESS_DENIED_WITHOUT_DECISION} becomes the stable code
261
- * of the same name, keeping the OAuth error in `details.oauth_error`. Anything else keeps the
262
- * RFC 6749 error as its code and the description as its message.
287
+ * of the same name, keeping the OAuth error in `details.oauth_error`. An error that matches
288
+ * {@link OAUTH_ERROR_CODE_PATTERN} becomes the code, with the description, cut to 2048 characters,
289
+ * as its message. Any other error is `invalid_callback`.
263
290
  */
264
291
  export declare function andcoAuthorizationRedirectError(error: string, description: string | null | undefined): AndcoError;
265
292
  /** Error base class that preserves its prototype at runtime. */
@@ -269,7 +296,7 @@ export declare class ErrorExtendable extends Error {
269
296
  static is<T extends ErrorExtendable>(error: unknown, errorClass: new (...args: any[]) => T): error is T;
270
297
  }
271
298
  /**
272
- * The single error type every Andco operation reports.
299
+ * The single error type every AndCo operation reports.
273
300
  *
274
301
  * An integrator writes one `catch`-equivalent branch and compares one `code`, whether the failure
275
302
  * came from authentication, an Intent, the resource API or the SDK itself. A failure the API answered
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,kBAAkB,CAAC;AAEnE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;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;;IA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;;;;;;;;;;;;;;;;OAsBG;WACW,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO;CAkB5D;AAED;;;;;;;;;GASG;AACH,qBAAa,+BAAgC,SAAQ,UAAU,CAAC,wBAAwB,CAAC;aAErE,OAAO,EAAE,0BAA0B;aACnC,QAAQ,EAAE,MAAM;gBADhB,OAAO,EAAE,0BAA0B,EACnC,QAAQ,EAAE,MAAM;CAOnC;AAED;;;;;GAKG;AACH,MAAM,MAAM,qBAAqB,GAAG,UAAU,CAAC,yBAAyB,CAAC,GAAG,+BAA+B,CAAC"}
package/dist/errors.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Conditions Andco's own client code detects, in the shape the Andco API already uses for the codes
2
+ * Conditions AndCo's own client code detects, in the shape the AndCo API already uses for the codes
3
3
  * it sends: lower snake_case, no prefix. Both vocabularies end up in the same `error.code` field, so
4
4
  * an integrator should not have to remember which half of a failure produced the string in hand.
5
5
  *
@@ -23,7 +23,7 @@
23
23
  * return "Tu sesión expiró. Vuelve a ingresar.";
24
24
  * default:
25
25
  * // A code this build does not know about: report it, never swallow it.
26
- * console.error("[messageFor] unhandled Andco error code: %s", error.code);
26
+ * console.error("[messageFor] unhandled AndCo error code: %s", error.code);
27
27
  * return "No pudimos completar la operación.";
28
28
  * }
29
29
  * }
@@ -49,7 +49,7 @@ export const ANDCO_ERROR_CODES = {
49
49
  INVALID_CONFIGURATION: "invalid_configuration",
50
50
  /** The configured Authorization Server endpoint is not a usable URL. */
51
51
  INVALID_ENDPOINT_AUTH: "invalid_endpoint_auth",
52
- /** The configured Andco API endpoint is not a usable URL. */
52
+ /** The configured AndCo API endpoint is not a usable URL. */
53
53
  INVALID_ENDPOINT_API: "invalid_endpoint_api",
54
54
  /** The configured button endpoint is not a usable URL. */
55
55
  INVALID_ENDPOINT_BUTTON: "invalid_endpoint_button",
@@ -59,7 +59,7 @@ export const ANDCO_ERROR_CODES = {
59
59
  INVALID_REDIRECT_TO: "invalid_redirect_to",
60
60
  /** The requested authentication mode is not one the SDK offers. */
61
61
  INVALID_AUTH_MODE: "invalid_auth_mode",
62
- /** At least one requested permission scope is not a scope Andco publishes. */
62
+ /** At least one requested permission scope is not a scope AndCo publishes. */
63
63
  INVALID_SCOPE: "invalid_scope",
64
64
  /** The requested SDK protocol version is not one this build speaks. */
65
65
  INVALID_VERSION: "invalid_version",
@@ -110,7 +110,7 @@ export const ANDCO_ERROR_CODES = {
110
110
  */
111
111
  AUTHORIZATION_FACTORY_FAILED: "authorization_factory_failed",
112
112
  /**
113
- * The authorization needs a bank account that is not open yet, because the bank is still
113
+ * The authorization needs a digital account that is not open yet, because AndCo is still
114
114
  * reviewing its opening. The Authorization Server ends the authorization with
115
115
  * `error=access_denied&error_description=bank_account_pending_review`.
116
116
  *
@@ -123,7 +123,7 @@ export const ANDCO_ERROR_CODES = {
123
123
  * account. The Authorization Server ends it with
124
124
  * `error=access_denied&error_description=authorization_expired`.
125
125
  *
126
- * Not a cancellation. Start a new authorization; the progress made on the bank side is kept.
126
+ * Not a cancellation. Start a new authorization; the progress made on the AndCo side is kept.
127
127
  */
128
128
  AUTHORIZATION_EXPIRED: "authorization_expired",
129
129
  /**
@@ -290,18 +290,56 @@ export function isAuthorizationEndedWithoutDecision(error, description) {
290
290
  return (error === "access_denied" &&
291
291
  ANDCO_ACCESS_DENIED_WITHOUT_DECISION.includes(description));
292
292
  }
293
+ /**
294
+ * What an authorization callback's `error` must look like for the SDK to report it as the error's
295
+ * code: ASCII letters, digits, `_`, `.` and `-`, 1 to 128 of them. Any other value (empty, a
296
+ * character outside the set, or longer) is `invalid_callback`, and its message does not repeat the
297
+ * value, which the URL's author controls. Every AndCo SDK (JavaScript, Go, Python and Ruby) checks
298
+ * the callback's `error` against this same pattern; the shared cases are the `oauth_error_code`
299
+ * section of the conformance vectors.
300
+ *
301
+ * @see https://github.com/haulmer/andco-sdk-js/blob/main/docs/adr/0042-check-the-oauth-callback-error-code-against-one-pattern-in-every-sdk.md
302
+ */
303
+ export const OAUTH_ERROR_CODE_PATTERN = "^[A-Za-z0-9_.-]{1,128}$";
304
+ const OAUTH_ERROR_CODE = /* @__PURE__ */ new RegExp(OAUTH_ERROR_CODE_PATTERN);
305
+ /**
306
+ * The authorization callback's parameters that carry one value: each appears at most once and, when
307
+ * it appears, is not empty. A callback that repeats one or leaves it empty is `invalid_callback`,
308
+ * whatever else it carries, since two readers of the same URL could otherwise act on different
309
+ * values. Every AndCo SDK (JavaScript, Go, Python and Ruby) refuses such a callback the same way;
310
+ * the shared cases are the `oauth_callback_parameters` section of the conformance vectors.
311
+ *
312
+ * @see https://github.com/haulmer/andco-sdk-js/blob/main/docs/adr/0044-reject-a-repeated-or-empty-oauth-callback-parameter-in-every-sdk.md
313
+ */
314
+ export const OAUTH_CALLBACK_SINGLE_VALUE_PARAMETERS = ["state", "code", "error"];
315
+ /**
316
+ * Whether a callback's query repeats one of {@link OAUTH_CALLBACK_SINGLE_VALUE_PARAMETERS}, or of
317
+ * `names` when given, or leaves it empty.
318
+ */
319
+ export function hasRepeatedOrEmptyCallbackParameter(parameters, names = OAUTH_CALLBACK_SINGLE_VALUE_PARAMETERS) {
320
+ return names.some((name) => {
321
+ const values = parameters.getAll(name);
322
+ return values.length > 1 || values[0] === "";
323
+ });
324
+ }
293
325
  /**
294
326
  * Builds the error for an authorization redirect that carries `error`.
295
327
  *
296
328
  * `access_denied` with one of {@link ANDCO_ACCESS_DENIED_WITHOUT_DECISION} becomes the stable code
297
- * of the same name, keeping the OAuth error in `details.oauth_error`. Anything else keeps the
298
- * RFC 6749 error as its code and the description as its message.
329
+ * of the same name, keeping the OAuth error in `details.oauth_error`. An error that matches
330
+ * {@link OAUTH_ERROR_CODE_PATTERN} becomes the code, with the description, cut to 2048 characters,
331
+ * as its message. Any other error is `invalid_callback`.
299
332
  */
300
333
  export function andcoAuthorizationRedirectError(error, description) {
301
- if (isAuthorizationEndedWithoutDecision(error, description)) {
334
+ if (!OAUTH_ERROR_CODE.test(error)) {
335
+ return new AndcoError(ANDCO_ERROR_CODES.INVALID_CALLBACK, {
336
+ message: "the callback's error is not an OAuth error code",
337
+ });
338
+ }
339
+ else if (isAuthorizationEndedWithoutDecision(error, description)) {
302
340
  return new AndcoError(description, { message: description, details: { oauth_error: error } });
303
341
  }
304
- return new AndcoError(error.slice(0, 256), { message: description?.slice(0, 2_048) ?? error });
342
+ return new AndcoError(error, { message: description?.slice(0, 2_048) ?? error });
305
343
  }
306
344
  /** Error base class that preserves its prototype at runtime. */
307
345
  export class ErrorExtendable extends Error {
@@ -316,7 +354,7 @@ export class ErrorExtendable extends Error {
316
354
  }
317
355
  }
318
356
  /**
319
- * The single error type every Andco operation reports.
357
+ * The single error type every AndCo operation reports.
320
358
  *
321
359
  * An integrator writes one `catch`-equivalent branch and compares one `code`, whether the failure
322
360
  * came from authentication, an Intent, the resource API or the SDK itself. A failure the API answered
package/dist/index.d.ts CHANGED
@@ -29,6 +29,7 @@ export * from "./release.js";
29
29
  export * from "./scopes.js";
30
30
  export * from "./service-grants.js";
31
31
  export * from "./signing.js";
32
+ export * from "./transfer.js";
32
33
  export * from "./urls.js";
33
34
  export * from "./userinfo.js";
34
35
  export * from "./utils.js";
@@ -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,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oB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c,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,eAAe,CAAC;AAC9B,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
@@ -29,6 +29,7 @@ export * from "./release.js";
29
29
  export * from "./scopes.js";
30
30
  export * from "./service-grants.js";
31
31
  export * from "./signing.js";
32
+ export * from "./transfer.js";
32
33
  export * from "./urls.js";
33
34
  export * from "./userinfo.js";
34
35
  export * from "./utils.js";