@pairlobby/protocol 0.11.0

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 (55) hide show
  1. package/LICENSE +93 -0
  2. package/README.md +5 -0
  3. package/dist/auto-close.d.ts +34 -0
  4. package/dist/auto-close.d.ts.map +1 -0
  5. package/dist/auto-close.js +12 -0
  6. package/dist/auto-close.js.map +1 -0
  7. package/dist/credentials.d.ts +15 -0
  8. package/dist/credentials.d.ts.map +1 -0
  9. package/dist/credentials.js +48 -0
  10. package/dist/credentials.js.map +1 -0
  11. package/dist/errors.d.ts +23 -0
  12. package/dist/errors.d.ts.map +1 -0
  13. package/dist/errors.js +78 -0
  14. package/dist/errors.js.map +1 -0
  15. package/dist/events.d.ts +3177 -0
  16. package/dist/events.d.ts.map +1 -0
  17. package/dist/events.js +145 -0
  18. package/dist/events.js.map +1 -0
  19. package/dist/handover.d.ts +266 -0
  20. package/dist/handover.d.ts.map +1 -0
  21. package/dist/handover.js +37 -0
  22. package/dist/handover.js.map +1 -0
  23. package/dist/http.d.ts +8849 -0
  24. package/dist/http.d.ts.map +1 -0
  25. package/dist/http.js +157 -0
  26. package/dist/http.js.map +1 -0
  27. package/dist/ids.d.ts +26 -0
  28. package/dist/ids.d.ts.map +1 -0
  29. package/dist/ids.js +46 -0
  30. package/dist/ids.js.map +1 -0
  31. package/dist/index.d.ts +13 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +13 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/limits.d.ts +74 -0
  36. package/dist/limits.d.ts.map +1 -0
  37. package/dist/limits.js +56 -0
  38. package/dist/limits.js.map +1 -0
  39. package/dist/names.d.ts +16 -0
  40. package/dist/names.d.ts.map +1 -0
  41. package/dist/names.js +7 -0
  42. package/dist/names.js.map +1 -0
  43. package/dist/records.d.ts +1109 -0
  44. package/dist/records.d.ts.map +1 -0
  45. package/dist/records.js +169 -0
  46. package/dist/records.js.map +1 -0
  47. package/dist/requests.d.ts +71 -0
  48. package/dist/requests.d.ts.map +1 -0
  49. package/dist/requests.js +93 -0
  50. package/dist/requests.js.map +1 -0
  51. package/dist/wire.d.ts +4266 -0
  52. package/dist/wire.d.ts.map +1 -0
  53. package/dist/wire.js +24 -0
  54. package/dist/wire.js.map +1 -0
  55. package/package.json +35 -0
package/LICENSE ADDED
@@ -0,0 +1,93 @@
1
+ Elastic License 2.0
2
+
3
+ URL: https://www.elastic.co/licensing/elastic-license
4
+
5
+ ## Acceptance
6
+
7
+ By using the software, you agree to all of the terms and conditions below.
8
+
9
+ ## Copyright License
10
+
11
+ The licensor grants you a non-exclusive, royalty-free, worldwide,
12
+ non-sublicensable, non-transferable license to use, copy, distribute, make
13
+ available, and prepare derivative works of the software, in each case subject to
14
+ the limitations and conditions below.
15
+
16
+ ## Limitations
17
+
18
+ You may not provide the software to third parties as a hosted or managed
19
+ service, where the service provides users with access to any substantial set of
20
+ the features or functionality of the software.
21
+
22
+ You may not move, change, disable, or circumvent the license key functionality
23
+ in the software, and you may not remove or obscure any functionality in the
24
+ software that is protected by the license key.
25
+
26
+ You may not alter, remove, or obscure any licensing, copyright, or other notices
27
+ of the licensor in the software. Any use of the licensor’s trademarks is subject
28
+ to applicable law.
29
+
30
+ ## Patents
31
+
32
+ The licensor grants you a license, under any patent claims the licensor can
33
+ license, or becomes able to license, to make, have made, use, sell, offer for
34
+ sale, import and have imported the software, in each case subject to the
35
+ limitations and conditions in this license. This license does not cover any
36
+ patent claims that you cause to be infringed by modifications or additions to
37
+ the software. If you or your company make any written claim that the software
38
+ infringes or contributes to infringement of any patent, your patent license for
39
+ the software granted under these terms ends immediately. If your company makes
40
+ such a claim, your patent license ends immediately for work on behalf of your
41
+ company.
42
+
43
+ ## Notices
44
+
45
+ You must ensure that anyone who gets a copy of any part of the software from you
46
+ also gets a copy of these terms.
47
+
48
+ If you modify the software, you must include in any modified copies of the
49
+ software prominent notices stating that you have modified the software.
50
+
51
+ ## No Other Rights
52
+
53
+ These terms do not imply any licenses other than those expressly granted in
54
+ these terms.
55
+
56
+ ## Termination
57
+
58
+ If you use the software in violation of these terms, such use is not licensed,
59
+ and your licenses will automatically terminate. If the licensor provides you
60
+ with a notice of your violation, and you cease all violation of this license no
61
+ later than 30 days after you receive that notice, your licenses will be
62
+ reinstated retroactively. However, if you violate these terms after such
63
+ reinstatement, any additional violation of these terms will cause your licenses
64
+ to terminate automatically and permanently.
65
+
66
+ ## No Liability
67
+
68
+ *As far as the law allows, the software comes as is, without any warranty or
69
+ condition, and the licensor will not be liable to you for any damages arising
70
+ out of these terms or the use or nature of the software, under any kind of
71
+ legal claim.*
72
+
73
+ ## Definitions
74
+
75
+ The **licensor** is the entity offering these terms, and the **software** is the
76
+ software the licensor makes available under these terms, including any portion
77
+ of it.
78
+
79
+ **you** refers to the individual or entity agreeing to these terms.
80
+
81
+ **your company** is any legal entity, sole proprietorship, or other kind of
82
+ organization that you work for, plus all organizations that have control over,
83
+ are under the control of, or are under common control with that
84
+ organization. **control** means ownership of substantially all the assets of an
85
+ entity, or the power to direct its management and policies by vote, contract, or
86
+ otherwise. Control can be direct or indirect.
87
+
88
+ **your licenses** are all the licenses granted to you for the software under
89
+ these terms.
90
+
91
+ **use** means anything you do with the software requiring one of your licenses.
92
+
93
+ **trademark** means trademarks, service marks, and similar rights.
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # @pairlobby/protocol
2
+
3
+ Part of [PairLobby](https://github.com/PairLobby/app), built from `packages/protocol` at version 0.11.0. See that repository for documentation.
4
+
5
+ Licensed under the [Elastic License 2.0](LICENSE): you may use, copy, modify and distribute it, but may not offer it to others as a hosted or managed service.
@@ -0,0 +1,34 @@
1
+ import { z } from 'zod';
2
+ export declare const AutoClosePolicySchema: z.ZodDiscriminatedUnion<"mode", [z.ZodObject<{
3
+ mode: z.ZodLiteral<"off">;
4
+ }, "strip", z.ZodTypeAny, {
5
+ mode: "off";
6
+ }, {
7
+ mode: "off";
8
+ }>, z.ZodObject<{
9
+ mode: z.ZodLiteral<"inactivity">;
10
+ afterMs: z.ZodNumber;
11
+ }, "strip", z.ZodTypeAny, {
12
+ mode: "inactivity";
13
+ afterMs: number;
14
+ }, {
15
+ mode: "inactivity";
16
+ afterMs: number;
17
+ }>, z.ZodObject<{
18
+ mode: z.ZodLiteral<"age">;
19
+ afterMs: z.ZodNumber;
20
+ }, "strip", z.ZodTypeAny, {
21
+ mode: "age";
22
+ afterMs: number;
23
+ }, {
24
+ mode: "age";
25
+ afterMs: number;
26
+ }>, z.ZodObject<{
27
+ mode: z.ZodLiteral<"agents_and_guests_left">;
28
+ }, "strip", z.ZodTypeAny, {
29
+ mode: "agents_and_guests_left";
30
+ }, {
31
+ mode: "agents_and_guests_left";
32
+ }>]>;
33
+ export declare const CloseReasonSchema: z.ZodEnum<["manual", "inactivity", "age", "agents_and_guests_left"]>;
34
+ //# sourceMappingURL=auto-close.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auto-close.d.ts","sourceRoot":"","sources":["../src/auto-close.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAItB,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAKhC,CAAC;AAEH,eAAO,MAAM,iBAAiB,sEAAoE,CAAC"}
@@ -0,0 +1,12 @@
1
+ //! Schemas for rooms that close themselves. Kept apart so records, events and
2
+ //! requests can share them without importing each other.
3
+ import { z } from 'zod';
4
+ const durationMs = z.number().int().min(1000).max(10 * 365 * 24 * 3600_000);
5
+ export const AutoClosePolicySchema = z.discriminatedUnion('mode', [
6
+ z.object({ mode: z.literal('off') }),
7
+ z.object({ mode: z.literal('inactivity'), afterMs: durationMs }),
8
+ z.object({ mode: z.literal('age'), afterMs: durationMs }),
9
+ z.object({ mode: z.literal('agents_and_guests_left') })
10
+ ]);
11
+ export const CloseReasonSchema = z.enum(['manual', 'inactivity', 'age', 'agents_and_guests_left']);
12
+ //# sourceMappingURL=auto-close.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auto-close.js","sourceRoot":"","sources":["../src/auto-close.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,yDAAyD;AAEzD,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAEtB,MAAM,UAAU,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,EAAE,GAAG,GAAG,GAAG,EAAE,GAAG,QAAQ,CAAC,CAAC;AAE5E,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC,kBAAkB,CAAC,MAAM,EAAE;IAC9D,CAAC,CAAC,MAAM,CAAC,EAAC,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,EAAC,CAAC;IAClC,CAAC,CAAC,MAAM,CAAC,EAAC,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,OAAO,EAAE,UAAU,EAAC,CAAC;IAC9D,CAAC,CAAC,MAAM,CAAC,EAAC,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE,UAAU,EAAC,CAAC;IACvD,CAAC,CAAC,MAAM,CAAC,EAAC,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,wBAAwB,CAAC,EAAC,CAAC;CACxD,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,YAAY,EAAE,KAAK,EAAE,wBAAwB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,15 @@
1
+ export type CredentialKind = 'controller' | 'participant' | 'attempt' | 'connect';
2
+ export declare function newCredential(kind: CredentialKind): string;
3
+ export declare function credentialKindOf(credential: string): CredentialKind | null;
4
+ export declare function hashCredential(credential: string): Promise<string>;
5
+ /** Compares two hex digests without an early exit on the first differing byte. */
6
+ export declare function digestsEqual(a: string, b: string): boolean;
7
+ /**
8
+ * Hex digits of an invite's digest that a client sends when asking the relays it
9
+ * can see which one issued a code. Four digits reveal 16 of an 8-character code's
10
+ * 40 bits: enough to pick out the right relay, too few to rebuild the code.
11
+ */
12
+ export declare const INVITE_PROBE_LENGTH = 4;
13
+ /** The probe for an already normalized invite code. */
14
+ export declare function inviteProbe(normalizedCode: string): Promise<string>;
15
+ //# sourceMappingURL=credentials.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credentials.d.ts","sourceRoot":"","sources":["../src/credentials.ts"],"names":[],"mappings":"AAQA,MAAM,MAAM,cAAc,GAAG,YAAY,GAAG,aAAa,GAAG,SAAS,GAAG,SAAS,CAAC;AAWlF,wBAAgB,aAAa,CAAC,IAAI,EAAE,cAAc,GAAG,MAAM,CAI1D;AAED,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,cAAc,GAAG,IAAI,CAI1E;AAED,wBAAsB,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAGxE;AAED,kFAAkF;AAClF,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAO1D;AAED;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,IAAI,CAAC;AAErC,uDAAuD;AACvD,wBAAsB,WAAW,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAEzE"}
@@ -0,0 +1,48 @@
1
+ //! Bearer credential generation and hashing.
2
+ //!
3
+ //! Credentials are 256-bit random tokens, so a single SHA-256 is the correct
4
+ //! digest: there is no low-entropy secret for a slow KDF to protect, and room
5
+ //! authorization runs this on every request.
6
+ const CREDENTIAL_BYTES = 32;
7
+ const CREDENTIAL_PREFIXES = { controller: 'plc', participant: 'plp', attempt: 'pla', connect: 'plk' };
8
+ function toBase64Url(bytes) {
9
+ return btoa(String.fromCharCode(...bytes))
10
+ .replace(/\+/g, '-')
11
+ .replace(/\//g, '_')
12
+ .replace(/=+$/, '');
13
+ }
14
+ export function newCredential(kind) {
15
+ const bytes = new Uint8Array(CREDENTIAL_BYTES);
16
+ globalThis.crypto.getRandomValues(bytes);
17
+ return `${CREDENTIAL_PREFIXES[kind]}_${toBase64Url(bytes)}`;
18
+ }
19
+ export function credentialKindOf(credential) {
20
+ const prefix = credential.split('_', 1)[0];
21
+ const found = Object.entries(CREDENTIAL_PREFIXES).find(([, value]) => value === prefix);
22
+ return found ? found[0] : null;
23
+ }
24
+ export async function hashCredential(credential) {
25
+ const digest = await globalThis.crypto.subtle.digest('SHA-256', new TextEncoder().encode(credential));
26
+ return Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, '0')).join('');
27
+ }
28
+ /** Compares two hex digests without an early exit on the first differing byte. */
29
+ export function digestsEqual(a, b) {
30
+ if (a.length !== b.length) {
31
+ return false;
32
+ }
33
+ let difference = 0;
34
+ for (let index = 0; index < a.length; index += 1)
35
+ difference |= a.charCodeAt(index) ^ b.charCodeAt(index);
36
+ return difference === 0;
37
+ }
38
+ /**
39
+ * Hex digits of an invite's digest that a client sends when asking the relays it
40
+ * can see which one issued a code. Four digits reveal 16 of an 8-character code's
41
+ * 40 bits: enough to pick out the right relay, too few to rebuild the code.
42
+ */
43
+ export const INVITE_PROBE_LENGTH = 4;
44
+ /** The probe for an already normalized invite code. */
45
+ export async function inviteProbe(normalizedCode) {
46
+ return (await hashCredential(normalizedCode)).slice(0, INVITE_PROBE_LENGTH);
47
+ }
48
+ //# sourceMappingURL=credentials.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credentials.js","sourceRoot":"","sources":["../src/credentials.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,GAAG;AACH,6EAA6E;AAC7E,8EAA8E;AAC9E,6CAA6C;AAE7C,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAI5B,MAAM,mBAAmB,GAAmC,EAAC,UAAU,EAAE,KAA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AAI,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACrG,CAAC;AAED,kFAAkF;AAClF,MAAM,UAAU,YAAY,CAAC,CAAS,EAAE,CAAS;IAC7C,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC;QACxB,OAAO,KAAK,CAAC;IACjB,CAAC;IACD,IAAI,UAAU,GAAG,CAAC,CAAC;IACnB,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC,CAAC,MAAM,EAAE,KAAK,IAAI,CAAC;QAAE,UAAU,IAAI,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IAC1G,OAAO,UAAU,KAAK,CAAC,CAAC;AAC5B,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAErC,uDAAuD;AACvD,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,cAAsB;IACpD,OAAO,CAAC,MAAM,cAAc,CAAC,cAAc,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,mBAAmB,CAAC,CAAC;AAChF,CAAC"}
@@ -0,0 +1,23 @@
1
+ export declare const ERROR_CODES: readonly ["invite_expired", "invite_already_redeemed", "invite_unknown", "unauthorized", "participant_revoked", "room_expired", "room_closed", "room_locked", "participant_muted", "turn_conflict", "turn_required", "turn_expired", "room_not_found", "quota_exceeded", "cursor_gap", "stale_handover_revision", "handover_already_resolved", "idempotency_conflict", "participant_limit_reached", "payload_too_large", "unsupported_capability", "protocol_version_unsupported", "invalid_request", "server_unavailable"];
2
+ export type ErrorCode = (typeof ERROR_CODES)[number];
3
+ export interface ProtocolErrorBody {
4
+ code: ErrorCode;
5
+ message: string;
6
+ /** Milliseconds the caller should wait before retrying, when retrying can help. */
7
+ retryAfterMs?: number;
8
+ /** Set on `cursor_gap` so the client can resume from a sequence the server still holds. */
9
+ earliestAvailableSeq?: number;
10
+ /** Set on `stale_handover_revision` so the client can name the revision it must accept. */
11
+ currentRevision?: number;
12
+ }
13
+ export declare class ProtocolError extends Error {
14
+ readonly code: ErrorCode;
15
+ readonly details: Omit<ProtocolErrorBody, 'code' | 'message'>;
16
+ constructor(code: ErrorCode, message: string, details?: Omit<ProtocolErrorBody, 'code' | 'message'>);
17
+ get httpStatus(): number;
18
+ toBody(): ProtocolErrorBody;
19
+ }
20
+ export declare function httpStatusFor(code: ErrorCode): number;
21
+ /** True when the same request, unchanged, could succeed later. */
22
+ export declare function isRetryable(code: ErrorCode): boolean;
23
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,WAAW,6fAyBd,CAAC;AAEX,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAErD,MAAM,WAAW,iBAAiB;IAC9B,IAAI,EAAE,SAAS,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,mFAAmF;IACnF,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,2FAA2F;IAC3F,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,2FAA2F;IAC3F,eAAe,CAAC,EAAE,MAAM,CAAC;CAC5B;AA6BD,qBAAa,aAAc,SAAQ,KAAK;IACpC,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC,iBAAiB,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;gBAClD,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,IAAI,CAAC,iBAAiB,EAAE,MAAM,GAAG,SAAS,CAAM;IAMvG,IAAI,UAAU,IAAI,MAAM,CAEvB;IACD,MAAM,IAAI,iBAAiB;CAG9B;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM,CAErD;AAED,kEAAkE;AAClE,wBAAgB,WAAW,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,CAEpD"}
package/dist/errors.js ADDED
@@ -0,0 +1,78 @@
1
+ //! Typed protocol errors. Codes are stable wire values; messages are for humans
2
+ //! and must never carry a credential, an invite code, or transcript content.
3
+ export const ERROR_CODES = [
4
+ 'invite_expired',
5
+ 'invite_already_redeemed',
6
+ 'invite_unknown',
7
+ 'unauthorized',
8
+ 'participant_revoked',
9
+ 'room_expired',
10
+ 'room_closed',
11
+ 'room_locked',
12
+ 'participant_muted',
13
+ 'turn_conflict',
14
+ 'turn_required',
15
+ 'turn_expired',
16
+ 'room_not_found',
17
+ 'quota_exceeded',
18
+ 'cursor_gap',
19
+ 'stale_handover_revision',
20
+ 'handover_already_resolved',
21
+ 'idempotency_conflict',
22
+ 'participant_limit_reached',
23
+ 'payload_too_large',
24
+ 'unsupported_capability',
25
+ 'protocol_version_unsupported',
26
+ 'invalid_request',
27
+ 'server_unavailable'
28
+ ];
29
+ const STATUS_BY_CODE = {
30
+ invite_expired: 410,
31
+ invite_already_redeemed: 409,
32
+ invite_unknown: 404,
33
+ unauthorized: 401,
34
+ participant_revoked: 403,
35
+ room_expired: 410,
36
+ room_closed: 409,
37
+ room_locked: 403,
38
+ participant_muted: 403,
39
+ turn_conflict: 409,
40
+ turn_required: 409,
41
+ turn_expired: 409,
42
+ room_not_found: 404,
43
+ quota_exceeded: 429,
44
+ cursor_gap: 410,
45
+ stale_handover_revision: 409,
46
+ handover_already_resolved: 409,
47
+ idempotency_conflict: 409,
48
+ participant_limit_reached: 409,
49
+ payload_too_large: 413,
50
+ unsupported_capability: 501,
51
+ protocol_version_unsupported: 400,
52
+ invalid_request: 400,
53
+ server_unavailable: 503
54
+ };
55
+ export class ProtocolError extends Error {
56
+ code;
57
+ details;
58
+ constructor(code, message, details = {}) {
59
+ super(message);
60
+ this.name = 'ProtocolError';
61
+ this.code = code;
62
+ this.details = details;
63
+ }
64
+ get httpStatus() {
65
+ return STATUS_BY_CODE[this.code];
66
+ }
67
+ toBody() {
68
+ return { code: this.code, message: this.message, ...this.details };
69
+ }
70
+ }
71
+ export function httpStatusFor(code) {
72
+ return STATUS_BY_CODE[code];
73
+ }
74
+ /** True when the same request, unchanged, could succeed later. */
75
+ export function isRetryable(code) {
76
+ return code === 'server_unavailable' || code === 'quota_exceeded';
77
+ }
78
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,6EAA6E;AAE7E,MAAM,CAAC,MAAM,WAAW,GAAG;IACvB,gBAAgB;IAChB,yBAAyB;IACzB,gBAAgB;IAChB,cAAc;IACd,qBAAqB;IACrB,cAAc;IACd,aAAa;IACb,aAAa;IACb,mBAAmB;IACnB,eAAe;IACf,eAAe;IACf,cAAc;IACd,gBAAgB;IAChB,gBAAgB;IAChB,YAAY;IACZ,yBAAyB;IACzB,2BAA2B;IAC3B,sBAAsB;IACtB,2BAA2B;IAC3B,mBAAmB;IACnB,wBAAwB;IACxB,8BAA8B;IAC9B,iBAAiB;IACjB,oBAAoB;CACd,CAAC;AAeX,MAAM,cAAc,GAA8B;IAC9C,cAAc,EAAE,GAAG;IACnB,uBAAuB,EAAE,GAAG;IAC5B,cAAc,EAAE,GAAG;IACnB,YAAY,EAAE,GAAG;IACjB,mBAAmB,EAAE,GAAG;IACxB,YAAY,EAAE,GAAG;IACjB,WAAW,EAAE,GAAG;IAChB,WAAW,EAAE,GAAG;IAChB,iBAAiB,EAAE,GAAG;IACtB,aAAa,EAAE,GAAG;IAClB,aAAa,EAAE,GAAG;IAClB,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