@andco/protocol 0.0.1 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +33 -3
  3. package/dist/api-errors.d.ts +109 -0
  4. package/dist/api-errors.d.ts.map +1 -0
  5. package/dist/api-errors.js +111 -0
  6. package/dist/authorization-preparation.d.ts +52 -543
  7. package/dist/authorization-preparation.d.ts.map +1 -1
  8. package/dist/authorization-preparation.js +19 -42
  9. package/dist/authorization.d.ts +64 -22
  10. package/dist/authorization.d.ts.map +1 -1
  11. package/dist/authorization.js +136 -55
  12. package/dist/consent.d.ts +5 -8
  13. package/dist/consent.d.ts.map +1 -1
  14. package/dist/consent.js +5 -62
  15. package/dist/constants.d.ts +19 -3
  16. package/dist/constants.d.ts.map +1 -1
  17. package/dist/constants.js +19 -3
  18. package/dist/errors.d.ts +156 -58
  19. package/dist/errors.d.ts.map +1 -1
  20. package/dist/errors.js +176 -57
  21. package/dist/index.d.ts +5 -5
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +5 -5
  24. package/dist/intent-input.d.ts +1010 -279
  25. package/dist/intent-input.d.ts.map +1 -1
  26. package/dist/intent-input.js +268 -40
  27. package/dist/messages/error.d.ts +1 -2
  28. package/dist/messages/error.d.ts.map +1 -1
  29. package/dist/messages/error.js +5 -2
  30. package/dist/messages/index.d.ts +3 -3
  31. package/dist/messages/index.js +2 -2
  32. package/dist/messages/presentation-response.d.ts +20 -0
  33. package/dist/messages/presentation-response.d.ts.map +1 -0
  34. package/dist/messages/presentation-response.js +17 -0
  35. package/dist/native-copy.d.ts +23 -2
  36. package/dist/native-copy.d.ts.map +1 -1
  37. package/dist/native-copy.js +42 -98
  38. package/dist/native-intent.d.ts +126 -75
  39. package/dist/native-intent.d.ts.map +1 -1
  40. package/dist/native-intent.js +140 -48
  41. package/dist/rar/account-matchers.d.ts +579 -0
  42. package/dist/rar/account-matchers.d.ts.map +1 -0
  43. package/dist/rar/account-matchers.js +480 -0
  44. package/dist/rar/bank.d.ts +1549 -0
  45. package/dist/rar/bank.d.ts.map +1 -0
  46. package/dist/rar/bank.js +379 -0
  47. package/dist/rar/catalog.d.ts +1155 -0
  48. package/dist/rar/catalog.d.ts.map +1 -0
  49. package/dist/rar/catalog.js +175 -0
  50. package/dist/rar/detail.d.ts +39 -0
  51. package/dist/rar/detail.d.ts.map +1 -0
  52. package/dist/rar/detail.js +44 -0
  53. package/dist/rar/index.d.ts +9 -0
  54. package/dist/rar/index.d.ts.map +1 -0
  55. package/dist/rar/index.js +8 -0
  56. package/dist/rar/money.d.ts +58 -0
  57. package/dist/rar/money.d.ts.map +1 -0
  58. package/dist/rar/money.js +61 -0
  59. package/dist/rar/project-users.d.ts +43 -0
  60. package/dist/rar/project-users.d.ts.map +1 -0
  61. package/dist/rar/project-users.js +63 -0
  62. package/dist/rar/subject-data.d.ts +170 -0
  63. package/dist/rar/subject-data.d.ts.map +1 -0
  64. package/dist/rar/subject-data.js +127 -0
  65. package/dist/rar/subject.d.ts +166 -0
  66. package/dist/rar/subject.d.ts.map +1 -0
  67. package/dist/rar/subject.js +119 -0
  68. package/dist/scopes.d.ts +5 -30
  69. package/dist/scopes.d.ts.map +1 -1
  70. package/dist/scopes.js +0 -13
  71. package/dist/service-grants.d.ts +44 -0
  72. package/dist/service-grants.d.ts.map +1 -0
  73. package/dist/service-grants.js +45 -0
  74. package/dist/signing.d.ts +56 -0
  75. package/dist/signing.d.ts.map +1 -0
  76. package/dist/signing.js +233 -0
  77. package/dist/transport/financial-events.d.ts +90 -35
  78. package/dist/transport/financial-events.d.ts.map +1 -1
  79. package/dist/transport/financial-events.js +7 -1
  80. package/dist/transport/generated/oauth-api.d.ts +908 -440
  81. package/dist/transport/generated/oauth-api.d.ts.map +1 -1
  82. package/dist/transport/index.d.ts +0 -1
  83. package/dist/transport/index.d.ts.map +1 -1
  84. package/dist/transport/index.js +0 -1
  85. package/dist/transport/intents.d.ts +155 -23
  86. package/dist/transport/intents.d.ts.map +1 -1
  87. package/dist/transport/intents.js +192 -59
  88. package/dist/transport/rest.d.ts +18 -8
  89. package/dist/transport/rest.d.ts.map +1 -1
  90. package/dist/transport/rest.js +1 -1
  91. package/dist/urls.d.ts.map +1 -1
  92. package/dist/urls.js +1 -1
  93. package/dist/userinfo.d.ts +10 -1
  94. package/dist/userinfo.d.ts.map +1 -1
  95. package/dist/userinfo.js +10 -1
  96. package/dist/utils.d.ts +15 -0
  97. package/dist/utils.d.ts.map +1 -1
  98. package/dist/utils.js +31 -0
  99. package/dist/webhooks.d.ts +154 -0
  100. package/dist/webhooks.d.ts.map +1 -0
  101. package/dist/webhooks.js +249 -0
  102. package/package.json +18 -1
  103. package/dist/automatic-charge.d.ts +0 -314
  104. package/dist/automatic-charge.d.ts.map +0 -1
  105. package/dist/automatic-charge.js +0 -126
  106. package/dist/bank-account-authorization.d.ts +0 -6
  107. package/dist/bank-account-authorization.d.ts.map +0 -1
  108. package/dist/bank-account-authorization.js +0 -13
  109. package/dist/messages/authorization-response.d.ts +0 -12
  110. package/dist/messages/authorization-response.d.ts.map +0 -1
  111. package/dist/messages/authorization-response.js +0 -9
  112. package/dist/transport/webhooks.d.ts +0 -27
  113. package/dist/transport/webhooks.d.ts.map +0 -1
  114. package/dist/transport/webhooks.js +0 -68
  115. package/dist/webhook-input.d.ts +0 -22
  116. package/dist/webhook-input.d.ts.map +0 -1
  117. package/dist/webhook-input.js +0 -11
  118. package/dist/webhook-signature.d.ts +0 -54
  119. package/dist/webhook-signature.d.ts.map +0 -1
  120. package/dist/webhook-signature.js +0 -74
package/dist/consent.js CHANGED
@@ -1,15 +1,10 @@
1
- import { ANDCO_NATIVE_MONEY, ANDCO_NATIVE_TEXT as t } from "./native-copy.js";
1
+ import { ANDCO_NATIVE_TEXT as t } from "./native-copy.js";
2
2
  const SCOPE_LABELS = {
3
3
  openid: "Identidad OpenID",
4
4
  email: "Correo electrónico",
5
5
  profile: "Nombre y avatar",
6
- "profile:write": "Actualizar nombre y avatar",
7
- "identities:read": "Leer identidades y documentos",
8
- "addresses:read": "Leer direcciones",
9
- "addresses:write": "Crear y actualizar direcciones",
10
- "organizations:list": "Listar los nombres e identificadores de mis organizaciones",
11
- "bank_accounts:read": "Leer cuentas bancarias",
12
- "bank_accounts.movements:read": "Leer movimientos de cuentas bancarias",
6
+ phone: "Número de teléfono",
7
+ offline_access: "Mantener el acceso sin conexión",
13
8
  };
14
9
  /**
15
10
  * Whether a Scope's checkbox may not be cleared: the Client's Scope Policy requires it, or an
@@ -50,61 +45,9 @@ export function ANDCO_CONSENT_INITIAL_SCOPES(consent) {
50
45
  .map((scope) => scope.scope));
51
46
  }
52
47
  /** Whether the in-progress selection is complete enough to submit; the server still authorizes on submit. */
53
- export function ANDCO_CONSENT_CAN_SUBMIT(consent, scopes, bankAccountId, chargeSourceIds = []) {
48
+ export function ANDCO_CONSENT_CAN_SUBMIT(consent, scopes) {
54
49
  return (!consent.organizationSelection &&
55
- (scopes.size > 0 || Boolean(consent.resourceAuthorization) || Boolean(consent.chargeAuthorization)) &&
50
+ (scopes.size > 0 || Boolean(consent.resourceAuthorization)) &&
56
51
  (!consent.resourceAuthorization || consent.resourceAuthorization.allowed) &&
57
- (!consent.bankAccountAuthorization ||
58
- consent.bankAccountAuthorization.accounts.some((a) => a.bankAccountId === bankAccountId)) &&
59
- (!consent.chargeAuthorization ||
60
- (chargeSourceIds.length >= (consent.chargeAuthorization.request.selection?.min ?? 1) &&
61
- chargeSourceIds.length <= (consent.chargeAuthorization.request.selection?.max ?? 1) &&
62
- new Set(chargeSourceIds).size === chargeSourceIds.length &&
63
- chargeSourceIds.every((id) => consent.chargeAuthorization?.accounts.some((account) => account.id === id)))) &&
64
52
  consent.scopes.every((scope) => scope.mode !== "required" || scopes.has(scope.scope)));
65
53
  }
66
- const INTERVAL_UNIT_LABELS = { days: "días", months: "meses", years: "años" };
67
- /** Presents the same charge restrictions in both native renderers. */
68
- export function ANDCO_CHARGE_SUMMARY(charge, locale = "es") {
69
- const d = charge.request;
70
- const money = (value) => ANDCO_NATIVE_MONEY(value, locale);
71
- const tt = (text, values) => t(text, values, locale);
72
- const budget = d.budget;
73
- return [
74
- { label: tt("Empresa seleccionada"), value: charge.companyName },
75
- {
76
- label: tt("Monto por cargo"),
77
- value: d.transaction.minimum === d.transaction.maximum
78
- ? `${money(d.transaction.minimum)} CLP`
79
- : tt("{{min}} a {{max}}", { min: money(d.transaction.minimum), max: money(d.transaction.maximum) }),
80
- },
81
- {
82
- label: tt("Empresa que recibe"),
83
- value: `${charge.operatorName}. ${d.beneficiaries?.length
84
- ? d.beneficiaries.join(", ")
85
- : tt("Cuentas actuales y futuras de esta empresa operadora.")}`,
86
- },
87
- {
88
- label: tt("Presupuesto acumulado configurado"),
89
- value: budget
90
- ? `${money(budget.amount)} / ${budget.interval.count} ${tt(INTERVAL_UNIT_LABELS[budget.interval.unit])} · ${budget.time_zone}`
91
- : tt("Sin límite acumulado"),
92
- },
93
- {
94
- label: tt("Permisos de cargos automáticos"),
95
- value: tt("La aplicación podrá iniciar cargos con estas condiciones, sin pedirte autorización en cada ocasión."),
96
- },
97
- {
98
- label: tt("Solicitante"),
99
- value: tt("Los fondos y la autorización pertenecen a {{company}}. Tu participación queda registrada como solicitante; no se usará tu cuenta personal.", { company: charge.companyName }),
100
- },
101
- {
102
- label: tt("Presupuesto acumulado configurado"),
103
- value: charge.budgetAnchor
104
- ? tt("Inicio conservado: {{date}}", {
105
- date: new Date(charge.budgetAnchor).toLocaleString(locale, { timeZone: budget?.time_zone }),
106
- })
107
- : tt("El período comienza al autorizar por primera vez, no al inicio del mes."),
108
- },
109
- ];
110
- }
@@ -3,13 +3,29 @@ export declare const ANDCO_SDK_PROTOCOL: "andco:sdk";
3
3
  /** Current version of the AndCo message protocol. */
4
4
  export declare const ANDCO_PROTOCOL_VERSION: 2;
5
5
  /** Default origin of the AndCo Authorization Server. */
6
- export declare const ANDCO_AUTH_ORIGIN: "https://auth.andco.cl";
6
+ export declare const ANDCO_AUTH_ORIGIN: "https://auth.andco.com";
7
7
  /** Default origin of the AndCo application API. */
8
- export declare const ANDCO_API_ORIGIN: "https://api.andco.cl";
8
+ export declare const ANDCO_API_ORIGIN: "https://api.andco.com";
9
9
  /** Default origin serving the hosted AndCo surfaces embedded by widgets. */
10
- export declare const ANDCO_WIDGET_ORIGIN: "https://widgets.andco.cl";
10
+ export declare const ANDCO_WIDGET_ORIGIN: "https://widgets.andco.com";
11
11
  /** Current explicit version of the AndCo OAuth resource API. */
12
12
  export declare const ANDCO_OAUTH_API_VERSION: "1788459778";
13
+ /**
14
+ * Content type of an Intent proposal: a creation born waiting for an Approval.
15
+ *
16
+ * `POST /intents` carries two representations of the same creation and picks between them by
17
+ * content type, never by looking for optional members inside one body. Sending this one explicitly
18
+ * is what says which of the two a request is, now that the endpoint answers to both.
19
+ */
20
+ export declare const ANDCO_INTENT_PROPOSAL_MEDIA_TYPE: "application/json";
21
+ /**
22
+ * Content type of one Signed Instruction: a compact JWS whose verified claims are the operation.
23
+ *
24
+ * The body is the serialized token itself, not a JSON object, and it carries no `Idempotency-Key`
25
+ * header: the idempotency key of a Signed Instruction is the `jti` inside its signature, and the
26
+ * server answers `400 idempotency_key_not_allowed` when a second candidate arrives beside it.
27
+ */
28
+ export declare const ANDCO_SIGNED_INSTRUCTION_MEDIA_TYPE: "application/jwt";
13
29
  /** Returns the base URL for one OAuth resource API version. `_` resolves to the latest version. */
14
30
  export declare function ANDCO_OAUTH_API_URL(endpoint: string | URL, version?: string | number): string;
15
31
  /** Returns the versioned OAuth UserInfo endpoint for an AndCo API origin. `_` resolves to the latest version. */
@@ -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,CA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,EAAE,MAAM,GAAG,GAAG,EAAE,OAAO,SAAM,GAAG,MAAM,CAEtF"}
package/dist/constants.js CHANGED
@@ -3,13 +3,29 @@ export const ANDCO_SDK_PROTOCOL = "andco:sdk";
3
3
  /** Current version of the AndCo message protocol. */
4
4
  export const ANDCO_PROTOCOL_VERSION = 2;
5
5
  /** Default origin of the AndCo Authorization Server. */
6
- export const ANDCO_AUTH_ORIGIN = "https://auth.andco.cl";
6
+ export const ANDCO_AUTH_ORIGIN = "https://auth.andco.com";
7
7
  /** Default origin of the AndCo application API. */
8
- export const ANDCO_API_ORIGIN = "https://api.andco.cl";
8
+ export const ANDCO_API_ORIGIN = "https://api.andco.com";
9
9
  /** Default origin serving the hosted AndCo surfaces embedded by widgets. */
10
- export const ANDCO_WIDGET_ORIGIN = "https://widgets.andco.cl";
10
+ export const ANDCO_WIDGET_ORIGIN = "https://widgets.andco.com";
11
11
  /** Current explicit version of the AndCo OAuth resource API. */
12
12
  export const ANDCO_OAUTH_API_VERSION = "1788459778";
13
+ /**
14
+ * Content type of an Intent proposal: a creation born waiting for an Approval.
15
+ *
16
+ * `POST /intents` carries two representations of the same creation and picks between them by
17
+ * content type, never by looking for optional members inside one body. Sending this one explicitly
18
+ * is what says which of the two a request is, now that the endpoint answers to both.
19
+ */
20
+ export const ANDCO_INTENT_PROPOSAL_MEDIA_TYPE = "application/json";
21
+ /**
22
+ * Content type of one Signed Instruction: a compact JWS whose verified claims are the operation.
23
+ *
24
+ * The body is the serialized token itself, not a JSON object, and it carries no `Idempotency-Key`
25
+ * header: the idempotency key of a Signed Instruction is the `jti` inside its signature, and the
26
+ * server answers `400 idempotency_key_not_allowed` when a second candidate arrives beside it.
27
+ */
28
+ export const ANDCO_SIGNED_INSTRUCTION_MEDIA_TYPE = "application/jwt";
13
29
  /** Returns the base URL for one OAuth resource API version. `_` resolves to the latest version. */
14
30
  export function ANDCO_OAUTH_API_URL(endpoint, version = "_") {
15
31
  return new URL(`/oauth/api/versions/${version}`, endpoint).href;
package/dist/errors.d.ts CHANGED
@@ -1,60 +1,158 @@
1
- /** Error codes produced by the SDK. */
2
- export declare enum ANDCO_ERROR_CODES {
3
- /** The current runtime does not provide the browser APIs required by the SDK. */
4
- BROWSER_UNAVAILABLE = "BROWSER_UNAVAILABLE",
5
- /** The user closed or cancelled the authorization flow before it completed. */
6
- AUTH_CANCELLED = "AUTH_CANCELLED",
7
- /** The authorization code could not be exchanged for a session. */
8
- AUTH_EXCHANGE_FAILED = "AUTH_EXCHANGE_FAILED",
9
- /** The authorization flow did not complete before its timeout elapsed. */
10
- AUTH_TIMEOUT = "AUTH_TIMEOUT",
11
- /** The configured authentication endpoint is invalid. */
12
- INVALID_ENDPOINT_AUTH = "INVALID_ENDPOINT_AUTH",
13
- /** The configured AndCo API endpoint is invalid. */
14
- INVALID_ENDPOINT_API = "INVALID_ENDPOINT_API",
15
- /** The configured button endpoint is invalid. */
16
- INVALID_ENDPOINT_BUTTON = "INVALID_ENDPOINT_BUTTON",
17
- /** The supplied iframe is missing or cannot be used by the SDK. */
18
- INVALID_IFRAME = "INVALID_IFRAME",
19
- /** The requested authentication mode is invalid. */
20
- INVALID_AUTH_MODE = "INVALID_AUTH_MODE",
21
- /** The configured public OAuth client identifier is invalid. */
22
- INVALID_CLIENT_ID = "INVALID_CLIENT_ID",
23
- /** The configured OAuth callback URL is invalid. */
24
- INVALID_REDIRECT_TO = "INVALID_REDIRECT_TO",
25
- /** A hosted-action callback could not be correlated with its original transaction. */
26
- INVALID_CALLBACK = "INVALID_CALLBACK",
27
- /** At least one requested permission scope is invalid. */
28
- INVALID_SCOPE = "INVALID_SCOPE",
29
- /** The configured SDK protocol version is invalid. */
30
- INVALID_VERSION = "INVALID_VERSION",
31
- /** The current runtime does not provide Fetch and none was configured. */
32
- FETCH_UNAVAILABLE = "FETCH_UNAVAILABLE",
33
- /** The browser prevented the SDK from opening the authorization popup. */
34
- POPUP_BLOCKED = "POPUP_BLOCKED",
35
- /** The SDK opened a popup but the browser refused to navigate it. */
36
- POPUP_NAVIGATION_FAILED = "POPUP_NAVIGATION_FAILED",
1
+ /**
2
+ * Conditions Andco's own client code detects, in the shape the Andco API already uses for the codes
3
+ * it sends: lower snake_case, no prefix. Both vocabularies end up in the same `error.code` field, so
4
+ * an integrator should not have to remember which half of a failure produced the string in hand.
5
+ *
6
+ * The backend never reports any of these -- it cannot see a blocked popup or a browser without Web
7
+ * Crypto -- which is why they live apart from {@link ANDCO_API_ERROR_CODES} rather than in one list.
8
+ *
9
+ * Compare against a member rather than a literal, and always leave a branch for a code you do not
10
+ * recognise. This list grows, `AndcoError.code` is a plain `string` for that reason, and an
11
+ * integration that only handles what existed when it was written should degrade rather than fall
12
+ * through in silence.
13
+ *
14
+ * @example
15
+ * // Typed by the shape the example needs, so it reads the same from `@andco/protocol`, whose
16
+ * // error is `AndCoSDKError`, and from `@andco/sdk`, whose error is `AndcoError`.
17
+ * function messageFor(error: { code: string }): string {
18
+ * switch (error.code) {
19
+ * case ANDCO_ERROR_CODES.POPUP_BLOCKED:
20
+ * return "Habilita las ventanas emergentes para continuar.";
21
+ * case ANDCO_ERROR_CODES.SESSION_MISSING:
22
+ * return "Tu sesión expiró. Vuelve a ingresar.";
23
+ * default:
24
+ * // A code this build does not know about: report it, never swallow it.
25
+ * console.error("[messageFor] unhandled Andco error code: %s", error.code);
26
+ * return "No pudimos completar la operación.";
27
+ * }
28
+ * }
29
+ *
30
+ * @see https://sdk.andco.com/docs/reference/error-codes
31
+ */
32
+ export declare const ANDCO_ERROR_CODES: {
33
+ /** An operation that needs a browser ran somewhere else. Not recoverable at runtime: move the call. */
34
+ readonly BROWSER_REQUIRED: "browser_required";
35
+ /** A browser ran the operation but does not provide an API the SDK needs. */
36
+ readonly BROWSER_UNAVAILABLE: "browser_unavailable";
37
+ /** An operation that must not run in a browser was attempted there, because it would leak a secret. */
38
+ readonly BROWSER_FORBIDDEN: "browser_forbidden";
39
+ /** The runtime provides no Fetch and none was configured. */
40
+ readonly FETCH_UNAVAILABLE: "fetch_unavailable";
41
+ /** The runtime provides no Web Crypto, so PKCE and state cannot be generated safely. */
42
+ readonly WEB_CRYPTO_UNAVAILABLE: "web_crypto_unavailable";
43
+ /** The SDK was constructed with something it cannot work with -- a missing client id, a malformed endpoint. */
44
+ readonly INVALID_CONFIGURATION: "invalid_configuration";
45
+ /** The configured Authorization Server endpoint is not a usable URL. */
46
+ readonly INVALID_ENDPOINT_AUTH: "invalid_endpoint_auth";
47
+ /** The configured Andco API endpoint is not a usable URL. */
48
+ readonly INVALID_ENDPOINT_API: "invalid_endpoint_api";
49
+ /** The configured button endpoint is not a usable URL. */
50
+ readonly INVALID_ENDPOINT_BUTTON: "invalid_endpoint_button";
51
+ /** The configured OAuth client identifier is not well formed. */
52
+ readonly INVALID_CLIENT_ID: "invalid_client_id";
53
+ /** The configured callback URL is not a usable URL, or uses a scheme that cannot receive a callback. */
54
+ readonly INVALID_REDIRECT_TO: "invalid_redirect_to";
55
+ /** The requested authentication mode is not one the SDK offers. */
56
+ readonly INVALID_AUTH_MODE: "invalid_auth_mode";
57
+ /** At least one requested permission scope is not a scope Andco publishes. */
58
+ readonly INVALID_SCOPE: "invalid_scope";
59
+ /** The requested SDK protocol version is not one this build speaks. */
60
+ readonly INVALID_VERSION: "invalid_version";
61
+ /** The requested button theme is not one the widget ships. */
62
+ readonly UNSUPPORTED_THEME: "unsupported_theme";
63
+ /** The requested colour-scheme mode is not one the chosen theme supports. */
64
+ readonly UNSUPPORTED_THEME_MODE: "unsupported_theme_mode";
65
+ /** The button endpoint shares the host application's origin, which would defeat the frame boundary. */
66
+ readonly SAME_ORIGIN_ENDPOINT: "same_origin_endpoint";
67
+ /**
68
+ * The browser refused to open the authorization window, almost always because it was not opened
69
+ * from a direct user gesture. Actionable: ask the person to allow popups, or present by redirect.
70
+ */
71
+ readonly POPUP_BLOCKED: "popup_blocked";
72
+ /** A popup opened but the browser refused to navigate it to the Authorization Server. */
73
+ readonly POPUP_NAVIGATION_FAILED: "popup_navigation_failed";
37
74
  /** A popup presentation did not settle before its bounded lifetime elapsed. */
38
- POPUP_TIMEOUT = "POPUP_TIMEOUT",
39
- /** A direct Intent popup requires an explicit callback URL. */
40
- INTENT_CALLBACK_REQUIRED = "INTENT_CALLBACK_REQUIRED",
41
- /** The button endpoint must not share the host application's origin. */
42
- SAME_ORIGIN_ENDPOINT = "SAME_ORIGIN_ENDPOINT",
43
- /** The requested authorization-flow presentation is not supported. */
44
- UNSUPPORTED_PRESENTATION = "UNSUPPORTED_PRESENTATION",
45
- /** The requested button theme is not supported. */
46
- UNSUPPORTED_THEME = "UNSUPPORTED_THEME",
47
- /** The requested color-scheme mode is not supported by the theme. */
48
- UNSUPPORTED_THEME_MODE = "UNSUPPORTED_THEME_MODE",
49
- /** An OAuth callback attempted to send credentials to an untrusted origin. */
50
- UNTRUSTED_ORIGIN = "UNTRUSTED_ORIGIN",
51
- /** The current runtime does not provide the Web Crypto capabilities required by the SDK. */
52
- WEB_CRYPTO_UNAVAILABLE = "WEB_CRYPTO_UNAVAILABLE",
53
- /** The iframe did not complete its secure handshake before the timeout elapsed. */
54
- HANDSHAKE_TIMEOUT = "HANDSHAKE_TIMEOUT",
55
- /** An unexpected error could not be mapped to a more specific SDK code. */
56
- UNKNOWN_ERROR = "UNKNOWN_ERROR"
57
- }
75
+ readonly POPUP_TIMEOUT: "popup_timeout";
76
+ /** The requested presentation is not one this surface supports. */
77
+ readonly PRESENTATION_UNSUPPORTED: "presentation_unsupported";
78
+ /** Resolving the URL to present failed before anything was shown. */
79
+ readonly PRESENTATION_TARGET_FAILED: "presentation_target_failed";
80
+ /** Presenting an Intent directly in a popup requires an explicit callback URL, and none was given. */
81
+ readonly INTENT_CALLBACK_REQUIRED: "intent_callback_required";
82
+ /** The supplied iframe is missing, detached, or cannot be used to host the widget. */
83
+ readonly INVALID_IFRAME: "invalid_iframe";
84
+ /**
85
+ * The widget in the iframe never completed its handshake with the host page. The SDK retries this
86
+ * one automatically, once; seeing it means the retry also failed.
87
+ */
88
+ readonly HANDSHAKE_TIMEOUT: "handshake_timeout";
89
+ /**
90
+ * A message reached the host from an origin the bridge does not trust. Not actionable by the
91
+ * person using the application: the embedding is misconfigured, or something is impersonating the
92
+ * widget.
93
+ */
94
+ readonly UNTRUSTED_ORIGIN: "untrusted_origin";
95
+ /** The person closed or rejected the authorization before it completed. Not a failure: a decision. */
96
+ readonly AUTHORIZATION_CANCELLED: "authorization_cancelled";
97
+ /** The authorization did not complete before its timeout elapsed. */
98
+ readonly AUTHORIZATION_TIMEOUT: "authorization_timeout";
99
+ /** Building or pushing (RFC 9126 PAR) an authorization request failed. */
100
+ readonly AUTHORIZATION_REQUEST_FAILED: "authorization_request_failed";
101
+ /** Exchanging an authorization code for a session failed. */
102
+ readonly AUTHORIZATION_EXCHANGE_FAILED: "authorization_exchange_failed";
103
+ /** Starting an RFC 8628 device authorization request failed. */
104
+ readonly DEVICE_AUTHORIZATION_FAILED: "device_authorization_failed";
105
+ /** Exchanging an approved device authorization grant for a session failed. */
106
+ readonly DEVICE_EXCHANGE_FAILED: "device_exchange_failed";
107
+ /** Exchanging a refresh token for a new session failed. The Grant may have been revoked. */
108
+ readonly REFRESH_FAILED: "refresh_failed";
109
+ /** Fetching the OpenID Connect UserInfo endpoint failed. */
110
+ readonly USERINFO_FAILED: "userinfo_failed";
111
+ /** A callback could not be correlated with the transaction that started it, so it is not trusted. */
112
+ readonly INVALID_CALLBACK: "invalid_callback";
113
+ /** The token endpoint answered without a field the session needs, or with an unusable value for one. */
114
+ readonly INVALID_TOKEN_RESPONSE: "invalid_token_response";
115
+ /** An operation that needs a session ran without one. Actionable: send the person to authorize. */
116
+ readonly SESSION_MISSING: "session_missing";
117
+ /** Reading or writing the session store failed -- private browsing, or storage the browser denied. */
118
+ readonly STORAGE_FAILED: "storage_failed";
119
+ /**
120
+ * The operation needs a confidential Client and this one is public. A public Client cannot keep a
121
+ * secret, so it may not perform it at all -- this is a registration question, not a runtime one.
122
+ */
123
+ readonly CONFIDENTIAL_CLIENT_REQUIRED: "confidential_client_required";
124
+ /** The pushed authorization request (RFC 9126) answered without a usable `request_uri`. */
125
+ readonly INVALID_PAR_RESPONSE: "invalid_par_response";
126
+ /** The given Intent identifier is not a well-formed one. */
127
+ readonly INVALID_INTENT_ID: "invalid_intent_id";
128
+ /**
129
+ * An Intent watch was stopped, by `stop()` or its signal, before the Intent reached a terminal
130
+ * status. A decision of the caller, not a failure; the watch's `intent` still holds the last read.
131
+ */
132
+ readonly WATCH_STOPPED: "watch_stopped";
133
+ /**
134
+ * The API answered a failure with no code the SDK could read. Distinct from `invalid_response`,
135
+ * which is a success whose shape is unusable: here the request failed and said so, just not in a
136
+ * vocabulary anybody shares.
137
+ */
138
+ readonly REQUEST_FAILED: "request_failed";
139
+ /** A response arrived in a shape the SDK cannot read. */
140
+ readonly INVALID_RESPONSE: "invalid_response";
141
+ /** A failure the SDK could not attribute to any condition above. Its cause carries what is known. */
142
+ readonly UNKNOWN_ERROR: "unknown_error";
143
+ };
144
+ /** One of the conditions {@link ANDCO_ERROR_CODES} names. */
145
+ export type AndcoErrorCode = (typeof ANDCO_ERROR_CODES)[keyof typeof ANDCO_ERROR_CODES];
146
+ /**
147
+ * The subset a widget may report to its host page over postMessage.
148
+ *
149
+ * Narrower than the vocabulary above on purpose. `session_missing` and `storage_failed` happen in
150
+ * the host page, and the iframe has no way to observe them, so accepting them here would widen a
151
+ * wire contract to admit messages nothing can send. Derived from what the widget actually produces:
152
+ * a new producer belongs in this list, and the message schema refusing its code is the intended way
153
+ * to find that out.
154
+ */
155
+ export declare const ANDCO_BRIDGE_ERROR_CODES: readonly ["invalid_endpoint_auth", "invalid_auth_mode", "invalid_client_id", "invalid_redirect_to", "invalid_scope", "invalid_version", "unsupported_theme", "unsupported_theme_mode", "presentation_unsupported", "popup_blocked", "popup_navigation_failed", "popup_timeout", "handshake_timeout", "untrusted_origin", "unknown_error"];
58
156
  /** Error base class that preserves its prototype at runtime. */
59
157
  export declare class ErrorExtendable extends Error {
60
158
  constructor(message?: string, options?: ErrorOptions);
@@ -63,8 +161,8 @@ export declare class ErrorExtendable extends Error {
63
161
  }
64
162
  /** SDK-specific error that includes a code and optional context. */
65
163
  export declare class AndCoSDKError extends ErrorExtendable {
66
- readonly code: ANDCO_ERROR_CODES;
164
+ readonly code: AndcoErrorCode;
67
165
  readonly payload: unknown;
68
- constructor(code: ANDCO_ERROR_CODES, payload?: unknown, options?: ErrorOptions);
166
+ constructor(code: AndcoErrorCode, payload?: unknown, options?: ErrorOptions);
69
167
  }
70
168
  //# sourceMappingURL=errors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,oBAAY,iBAAiB;IAC3B,iFAAiF;IACjF,mBAAmB,wBAAwB;IAC3C,+EAA+E;IAC/E,cAAc,mBAAmB;IACjC,mEAAmE;IACnE,oBAAoB,yBAAyB;IAC7C,0EAA0E;IAC1E,YAAY,iBAAiB;IAC7B,yDAAyD;IACzD,qBAAqB,0BAA0B;IAC/C,oDAAoD;IACpD,oBAAoB,yBAAyB;IAC7C,iDAAiD;IACjD,uBAAuB,4BAA4B;IACnD,mEAAmE;IACnE,cAAc,mBAAmB;IACjC,oDAAoD;IACpD,iBAAiB,sBAAsB;IACvC,gEAAgE;IAChE,iBAAiB,sBAAsB;IACvC,oDAAoD;IACpD,mBAAmB,wBAAwB;IAC3C,sFAAsF;IACtF,gBAAgB,qBAAqB;IACrC,0DAA0D;IAC1D,aAAa,kBAAkB;IAC/B,sDAAsD;IACtD,eAAe,oBAAoB;IACnC,0EAA0E;IAC1E,iBAAiB,sBAAsB;IACvC,0EAA0E;IAC1E,aAAa,kBAAkB;IAC/B,qEAAqE;IACrE,uBAAuB,4BAA4B;IACnD,+EAA+E;IAC/E,aAAa,kBAAkB;IAC/B,+DAA+D;IAC/D,wBAAwB,6BAA6B;IACrD,wEAAwE;IACxE,oBAAoB,yBAAyB;I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