@andco/protocol 0.0.10 → 0.0.12

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/dist/api-errors.d.ts +5 -128
  2. package/dist/api-errors.d.ts.map +1 -1
  3. package/dist/api-errors.js +5 -131
  4. package/dist/authorization-preparation.d.ts +3 -3
  5. package/dist/authorization-preparation.d.ts.map +1 -1
  6. package/dist/authorization-preparation.js +4 -0
  7. package/dist/authorization.js +2 -2
  8. package/dist/errors.d.ts +60 -16
  9. package/dist/errors.d.ts.map +1 -1
  10. package/dist/errors.js +60 -12
  11. package/dist/index.d.ts +1 -0
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +1 -0
  14. package/dist/intent-input.d.ts +1791 -725
  15. package/dist/intent-input.d.ts.map +1 -1
  16. package/dist/intent-input.js +325 -157
  17. package/dist/issues.d.ts +61 -0
  18. package/dist/issues.d.ts.map +1 -0
  19. package/dist/issues.js +61 -0
  20. package/dist/messages/index.d.ts +2 -2
  21. package/dist/messages/index.d.ts.map +1 -1
  22. package/dist/messages/index.js +10 -3
  23. package/dist/messages/set-preferences.d.ts +13 -1
  24. package/dist/messages/set-preferences.d.ts.map +1 -1
  25. package/dist/messages/set-preferences.js +31 -9
  26. package/dist/miniapp-manifest.d.ts +2 -2
  27. package/dist/miniapp-manifest.d.ts.map +1 -1
  28. package/dist/miniapp-manifest.js +1 -1
  29. package/dist/native-intent.d.ts +48 -28
  30. package/dist/native-intent.d.ts.map +1 -1
  31. package/dist/native-intent.js +76 -24
  32. package/dist/pagination.d.ts +37 -31
  33. package/dist/pagination.d.ts.map +1 -1
  34. package/dist/pagination.js +72 -24
  35. package/dist/rar/account-matchers.d.ts +47 -240
  36. package/dist/rar/account-matchers.d.ts.map +1 -1
  37. package/dist/rar/account-matchers.js +52 -131
  38. package/dist/rar/bank.d.ts +280 -392
  39. package/dist/rar/bank.d.ts.map +1 -1
  40. package/dist/rar/bank.js +68 -137
  41. package/dist/rar/catalog.d.ts +305 -288
  42. package/dist/rar/catalog.d.ts.map +1 -1
  43. package/dist/rar/catalog.js +69 -29
  44. package/dist/rar/detail.d.ts +15 -32
  45. package/dist/rar/detail.d.ts.map +1 -1
  46. package/dist/rar/detail.js +14 -34
  47. package/dist/rar/index.d.ts +2 -1
  48. package/dist/rar/index.d.ts.map +1 -1
  49. package/dist/rar/index.js +2 -1
  50. package/dist/rar/json-schemas.generated.d.ts +4 -0
  51. package/dist/rar/json-schemas.generated.d.ts.map +1 -0
  52. package/dist/rar/json-schemas.generated.js +3570 -0
  53. package/dist/rar/money.d.ts +5 -5
  54. package/dist/rar/money.d.ts.map +1 -1
  55. package/dist/rar/money.js +5 -5
  56. package/dist/rar/project-users.d.ts +40 -14
  57. package/dist/rar/project-users.d.ts.map +1 -1
  58. package/dist/rar/project-users.js +20 -23
  59. package/dist/rar/subject-data.d.ts +96 -48
  60. package/dist/rar/subject-data.d.ts.map +1 -1
  61. package/dist/rar/subject-data.js +61 -34
  62. package/dist/rar/subject.d.ts +18 -85
  63. package/dist/rar/subject.d.ts.map +1 -1
  64. package/dist/rar/subject.js +23 -51
  65. package/dist/rest/accounts.d.ts +347 -0
  66. package/dist/rest/accounts.d.ts.map +1 -0
  67. package/dist/rest/accounts.js +108 -0
  68. package/dist/rest/addresses.d.ts +581 -0
  69. package/dist/rest/addresses.d.ts.map +1 -0
  70. package/dist/rest/addresses.js +190 -0
  71. package/dist/rest/api-error.d.ts +104 -0
  72. package/dist/rest/api-error.d.ts.map +1 -0
  73. package/dist/rest/api-error.js +103 -0
  74. package/dist/rest/authorization.d.ts +123 -0
  75. package/dist/rest/authorization.d.ts.map +1 -0
  76. package/dist/rest/authorization.js +62 -0
  77. package/dist/rest/catalog.d.ts +199 -0
  78. package/dist/rest/catalog.d.ts.map +1 -0
  79. package/dist/rest/catalog.js +63 -0
  80. package/dist/rest/common.d.ts +637 -0
  81. package/dist/rest/common.d.ts.map +1 -0
  82. package/dist/rest/common.js +172 -0
  83. package/dist/rest/contract.d.ts +3480 -0
  84. package/dist/rest/contract.d.ts.map +1 -0
  85. package/dist/rest/contract.js +120 -0
  86. package/dist/rest/events.d.ts +145 -0
  87. package/dist/rest/events.d.ts.map +1 -0
  88. package/dist/rest/events.js +42 -0
  89. package/dist/rest/http.d.ts +49 -0
  90. package/dist/rest/http.d.ts.map +1 -0
  91. package/dist/rest/http.js +25 -0
  92. package/dist/rest/identity.d.ts +627 -0
  93. package/dist/rest/identity.d.ts.map +1 -0
  94. package/dist/rest/identity.js +128 -0
  95. package/dist/rest/index.d.ts +14 -0
  96. package/dist/rest/index.d.ts.map +1 -0
  97. package/dist/rest/index.js +13 -0
  98. package/dist/rest/intents.d.ts +4556 -0
  99. package/dist/rest/intents.d.ts.map +1 -0
  100. package/dist/rest/intents.js +551 -0
  101. package/dist/rest/signatures.d.ts +110 -0
  102. package/dist/rest/signatures.d.ts.map +1 -0
  103. package/dist/rest/signatures.js +113 -0
  104. package/dist/rest/subjects.d.ts +14 -0
  105. package/dist/rest/subjects.d.ts.map +1 -0
  106. package/dist/rest/subjects.js +22 -0
  107. package/dist/service-grants.d.ts +2 -2
  108. package/dist/service-grants.d.ts.map +1 -1
  109. package/dist/service-grants.js +1 -1
  110. package/dist/transport/generated/oauth-api.d.ts +5547 -1448
  111. package/dist/transport/generated/oauth-api.d.ts.map +1 -1
  112. package/dist/transport/intents.d.ts +9 -134
  113. package/dist/transport/intents.d.ts.map +1 -1
  114. package/dist/transport/intents.js +21 -405
  115. package/dist/transport/rest.d.ts +15 -5
  116. package/dist/transport/rest.d.ts.map +1 -1
  117. package/dist/userinfo.d.ts +22 -9
  118. package/dist/userinfo.d.ts.map +1 -1
  119. package/dist/userinfo.js +17 -12
  120. package/package.json +13 -2
package/dist/errors.js CHANGED
@@ -3,8 +3,10 @@
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
  *
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.
6
+ * The backend never reports most of these -- it cannot see a blocked popup or a browser without Web
7
+ * Crypto -- which is why they live apart from the codes the API answers, which its OpenAPI document
8
+ * declares, each with its status and data. The two it shares, `invalid_identifier` and
9
+ * `invalid_request`, are here for the times the SDK refuses an argument before sending it.
8
10
  *
9
11
  * Compare against a member rather than a literal, and always leave a branch for a code you do not
10
12
  * recognise. This list grows, `AndcoError.code` is a plain `string` for that reason, and an
@@ -99,6 +101,14 @@ export const ANDCO_ERROR_CODES = {
99
101
  // -- Authorization lifecycle -----------------------------------------------------------------
100
102
  /** The person closed or rejected the authorization before it completed. Not a failure: a decision. */
101
103
  AUTHORIZATION_CANCELLED: "authorization_cancelled",
104
+ /**
105
+ * The factory handed to `andco.auth.present(factory, ...)` threw, so there was no authorization
106
+ * URL to present. What failed is the application's own server (or whatever the factory called),
107
+ * not the SDK's configuration: `cause` holds the original error, and an `AndcoError` the factory
108
+ * throws itself is passed through with its own code. The window is already open when the factory
109
+ * runs, so it closes without navigating.
110
+ */
111
+ AUTHORIZATION_FACTORY_FAILED: "authorization_factory_failed",
102
112
  /**
103
113
  * The authorization needs a bank account that is not open yet, because the bank is still
104
114
  * reviewing its opening. The Authorization Server ends the authorization with
@@ -116,6 +126,15 @@ export const ANDCO_ERROR_CODES = {
116
126
  * Not a cancellation. Start a new authorization; the progress made on the bank side is kept.
117
127
  */
118
128
  AUTHORIZATION_EXPIRED: "authorization_expired",
129
+ /**
130
+ * The authorization asked for an Organization, and the person who signed in belongs to none where
131
+ * they may authorize applications. The Authorization Server ends it with
132
+ * `error=access_denied&error_description=organization_required` when they choose to go back.
133
+ *
134
+ * Not a cancellation. The consent screen offers to create an Empresa first; a new authorization
135
+ * after that lets them pick it.
136
+ */
137
+ ORGANIZATION_REQUIRED: "organization_required",
119
138
  /** The authorization did not complete before its timeout elapsed. */
120
139
  AUTHORIZATION_TIMEOUT: "authorization_timeout",
121
140
  /** Building or pushing (RFC 9126 PAR) an authorization request failed. */
@@ -156,6 +175,18 @@ export const ANDCO_ERROR_CODES = {
156
175
  /** The pushed authorization request (RFC 9126) answered without a usable `request_uri`. */
157
176
  INVALID_PAR_RESPONSE: "invalid_par_response",
158
177
  // -- Operations ------------------------------------------------------------------------------
178
+ /**
179
+ * An identifier the caller passed (an Intent's, an account's) is not well formed, so no request was
180
+ * made. The API answers the same code when the malformed identifier reaches it; here the SDK caught
181
+ * it first. Not retryable: fix the identifier.
182
+ */
183
+ INVALID_IDENTIFIER: "invalid_identifier",
184
+ /**
185
+ * An argument the caller passed, such as pagination that mixes cursor and offset families or asks
186
+ * for zero items, is not one the operation takes, so no request was made. `details.issues` names
187
+ * each problem as `{ type, path }`. The API answers the same code for the same request.
188
+ */
189
+ INVALID_REQUEST: "invalid_request",
159
190
  /**
160
191
  * An Intent watch was stopped, by `stop()` or its signal, before the Intent reached a terminal
161
192
  * status. A decision of the caller, not a failure; the watch's `intent` still holds the last read.
@@ -167,6 +198,14 @@ export const ANDCO_ERROR_CODES = {
167
198
  * window. `details.intent` holds the Intent, whose `status` says which end it reached.
168
199
  */
169
200
  INTENT_ENDED: "intent_ended",
201
+ /**
202
+ * The factory handed to `andco.intents.present(factory, ...)` threw, so there was no Intent to
203
+ * present. What failed is the application's own server (or whatever the factory called), not the
204
+ * SDK's configuration: `cause` holds the original error, and an `AndcoError` the factory throws
205
+ * itself is passed through with its own code. The window is already open when the factory runs, so
206
+ * it closes without navigating.
207
+ */
208
+ INTENT_FACTORY_FAILED: "intent_factory_failed",
170
209
  /**
171
210
  * The API answered a failure with no code the SDK could read. Distinct from `invalid_response`,
172
211
  * which is a success whose shape is unusable: here the request failed and said so, just not in a
@@ -213,6 +252,7 @@ export const ANDCO_BRIDGE_ERROR_CODES = [
213
252
  export const ANDCO_ACCESS_DENIED_WITHOUT_DECISION = [
214
253
  ANDCO_ERROR_CODES.BANK_ACCOUNT_PENDING_REVIEW,
215
254
  ANDCO_ERROR_CODES.AUTHORIZATION_EXPIRED,
255
+ ANDCO_ERROR_CODES.ORGANIZATION_REQUIRED,
216
256
  ];
217
257
  /**
218
258
  * Whether an authorization redirect's error is `access_denied` with a description that names a
@@ -251,15 +291,20 @@ export class ErrorExtendable extends Error {
251
291
  * The single error type every Andco operation reports.
252
292
  *
253
293
  * An integrator writes one `catch`-equivalent branch and compares one `code`, whether the failure
254
- * came from authentication, an Intent, the resource API or the SDK itself. `code` is a plain string
255
- * because it also carries codes this package does not own, such as the Authorization Server's OAuth
256
- * error identifiers, and the same string identifies the same condition in the Python SDK.
294
+ * came from authentication, an Intent, the resource API or the SDK itself. A failure the API answered
295
+ * is an `AndcoResponseError` (`@andco/sdk`), a subclass whose `code` is the API's `error` and whose
296
+ * `data` carries the error's own fields.
297
+ *
298
+ * `Code` narrows `code` where the set is known, so a union of errors is discriminated by it: an
299
+ * operation's error is one member per code it can answer. It defaults to a plain string because
300
+ * `code` also carries codes this package does not own, such as the Authorization Server's OAuth error
301
+ * identifiers, and the same string identifies the same condition in the Python SDK.
257
302
  *
258
303
  * @example
259
304
  * ```ts
260
305
  * const { data, error } = await andco.intents.get(intentId);
261
306
  * if (error) {
262
- * if (error.code === "insufficient_authorization") return reconnect();
307
+ * if (error.code === "not_found") return showUnknownOrder();
263
308
  * throw error;
264
309
  * }
265
310
  * ```
@@ -270,16 +315,15 @@ export class AndcoError extends Error {
270
315
  /** HTTP status when the error came from a response. */
271
316
  status;
272
317
  /**
273
- * The remaining fields of the error body.
274
- *
275
- * Andco reports more than a code — `required_scope` on an authorization failure, per-field notes
276
- * on a rejected input. Branch on `code`, but surface these: without them an integrator can only
277
- * tell a user that something failed, not which permission is missing.
318
+ * What the SDK learned about a failure it detected itself, beyond its code: the Intent of
319
+ * `intent_ended`, the problems of a refused argument (`issues`).
278
320
  *
279
321
  * When the Authorization Server refused an exchange (a refresh, a code or device exchange, a
280
322
  * revocation) with an RFC 6749 error body, it carries two keys of its own: `oauth_error`, the
281
323
  * answer's `error` (`"invalid_grant"`, `"temporarily_unavailable"`, ...), and, when the server sent
282
324
  * one, `oauth_error_description`. They are absent when the server answered nothing OAuth-shaped.
325
+ *
326
+ * The fields of an error the API answered are not here: they are an `AndcoResponseError`'s `data`.
283
327
  */
284
328
  details;
285
329
  constructor(code, options = {}) {
@@ -304,7 +348,8 @@ export class AndcoError extends Error {
304
348
  * Whether the Grant or session behind a failure no longer works, so the only way out is for the
305
349
  * person to authorize again. It is `true` for:
306
350
  *
307
- * - a `401` from the Resource API,
351
+ * - a `401` from the Resource API (`invalid_token`, the only error the API answers with 401 for a
352
+ * bad token), as an `AndcoError` or as the raw error body `rest.raw` hands through,
308
353
  * - `session_missing`,
309
354
  * - `no_token_for_resource`,
310
355
  * - `refresh_failed` whose `details.oauth_error` is `invalid_grant` or `invalid_token`.
@@ -323,6 +368,9 @@ export class AndcoError extends Error {
323
368
  * ```
324
369
  */
325
370
  static isAuthorizationEnded(cause) {
371
+ if (typeof cause === "object" && cause !== null && !AndcoError.is(cause)) {
372
+ return cause["error"] === "invalid_token";
373
+ }
326
374
  if (!AndcoError.is(cause))
327
375
  return false;
328
376
  if (cause.status === 401)
package/dist/index.d.ts CHANGED
@@ -8,6 +8,7 @@ export * from "./errors.js";
8
8
  export * from "./format-money.js";
9
9
  export * from "./intent-input.js";
10
10
  export * from "./intent-status.js";
11
+ export * from "./issues.js";
11
12
  export * from "./messages/base.js";
12
13
  export * from "./messages/click.js";
13
14
  export * from "./messages/error.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,cAA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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
@@ -8,6 +8,7 @@ export * from "./errors.js";
8
8
  export * from "./format-money.js";
9
9
  export * from "./intent-input.js";
10
10
  export * from "./intent-status.js";
11
+ export * from "./issues.js";
11
12
  export * from "./messages/base.js";
12
13
  export * from "./messages/click.js";
13
14
  export * from "./messages/error.js";