@dxos/protocols 0.8.4-main.5ad4a44 → 0.8.4-main.66e292d

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 (95) hide show
  1. package/dist/src/FunctionProtocol.d.ts +76 -0
  2. package/dist/src/FunctionProtocol.d.ts.map +1 -0
  3. package/dist/src/FunctionProtocol.js +4 -0
  4. package/dist/src/FunctionProtocol.js.map +1 -0
  5. package/dist/src/automerge.d.ts +8 -0
  6. package/dist/src/automerge.d.ts.map +1 -1
  7. package/dist/src/automerge.js.map +1 -1
  8. package/dist/src/buf/proto/gen/dxos/client/services_pb.d.ts +64 -18
  9. package/dist/src/buf/proto/gen/dxos/client/services_pb.d.ts.map +1 -1
  10. package/dist/src/buf/proto/gen/dxos/client/services_pb.js +27 -22
  11. package/dist/src/buf/proto/gen/dxos/client/services_pb.js.map +1 -1
  12. package/dist/src/edge/EdgeFunctionEnv.d.ts +95 -0
  13. package/dist/src/edge/EdgeFunctionEnv.d.ts.map +1 -0
  14. package/dist/src/edge/EdgeFunctionEnv.js +4 -0
  15. package/dist/src/edge/EdgeFunctionEnv.js.map +1 -0
  16. package/dist/src/{edge.d.ts → edge/edge.d.ts} +106 -10
  17. package/dist/src/edge/edge.d.ts.map +1 -0
  18. package/dist/src/edge/edge.js +155 -0
  19. package/dist/src/edge/edge.js.map +1 -0
  20. package/dist/src/edge/errors.d.ts +29 -0
  21. package/dist/src/edge/errors.d.ts.map +1 -0
  22. package/dist/src/edge/errors.js +69 -0
  23. package/dist/src/edge/errors.js.map +1 -0
  24. package/dist/src/edge/index.d.ts +4 -0
  25. package/dist/src/edge/index.d.ts.map +1 -0
  26. package/dist/src/edge/index.js +7 -0
  27. package/dist/src/edge/index.js.map +1 -0
  28. package/dist/src/errors/base-errors.d.ts +92 -8
  29. package/dist/src/errors/base-errors.d.ts.map +1 -1
  30. package/dist/src/errors/base-errors.js +4 -20
  31. package/dist/src/errors/base-errors.js.map +1 -1
  32. package/dist/src/errors/encoding.d.ts +1 -1
  33. package/dist/src/errors/encoding.d.ts.map +1 -1
  34. package/dist/src/errors/errors.d.ts +662 -41
  35. package/dist/src/errors/errors.d.ts.map +1 -1
  36. package/dist/src/errors/errors.js +29 -83
  37. package/dist/src/errors/errors.js.map +1 -1
  38. package/dist/src/errors/errors.test.js +1 -1
  39. package/dist/src/errors/errors.test.js.map +1 -1
  40. package/dist/src/errors/helpers.d.ts +8 -4
  41. package/dist/src/errors/helpers.d.ts.map +1 -1
  42. package/dist/src/errors/helpers.js +3 -3
  43. package/dist/src/errors/helpers.js.map +1 -1
  44. package/dist/src/feed-replication.d.ts.map +1 -1
  45. package/dist/src/index.d.ts +3 -2
  46. package/dist/src/index.d.ts.map +1 -1
  47. package/dist/src/index.js +4 -2
  48. package/dist/src/index.js.map +1 -1
  49. package/dist/src/messenger.d.ts +16 -0
  50. package/dist/src/messenger.d.ts.map +1 -0
  51. package/dist/src/messenger.js +4 -0
  52. package/dist/src/messenger.js.map +1 -0
  53. package/dist/src/proto/gen/dxos/client/services.d.ts +30 -3
  54. package/dist/src/proto/gen/dxos/client/services.d.ts.map +1 -1
  55. package/dist/src/proto/gen/dxos/client/services.js +9 -6
  56. package/dist/src/proto/gen/dxos/client/services.js.map +1 -1
  57. package/dist/src/proto/gen/google/protobuf.d.ts +4 -4
  58. package/dist/src/proto/gen/google/protobuf.d.ts.map +1 -1
  59. package/dist/src/proto/gen/index.d.ts +1 -0
  60. package/dist/src/proto/gen/index.d.ts.map +1 -1
  61. package/dist/src/proto/gen/index.js +1 -1
  62. package/dist/src/proto/gen/index.js.map +1 -1
  63. package/dist/src/queue.d.ts +9 -0
  64. package/dist/src/queue.d.ts.map +1 -1
  65. package/dist/src/queue.js.map +1 -1
  66. package/dist/tsconfig.tsbuildinfo +1 -1
  67. package/package.json +9 -9
  68. package/src/FunctionProtocol.ts +100 -0
  69. package/src/automerge.ts +8 -0
  70. package/src/buf/proto/gen/dxos/client/services_pb.ts +81 -26
  71. package/src/edge/EdgeFunctionEnv.ts +165 -0
  72. package/src/edge/edge.ts +488 -0
  73. package/src/edge/errors.ts +85 -0
  74. package/src/edge/index.ts +7 -0
  75. package/src/errors/base-errors.ts +4 -22
  76. package/src/errors/errors.test.ts +1 -1
  77. package/src/errors/errors.ts +35 -101
  78. package/src/errors/helpers.ts +5 -6
  79. package/src/feed-replication.ts +1 -0
  80. package/src/index.ts +5 -2
  81. package/src/messenger.ts +22 -0
  82. package/src/proto/dxos/client/services.proto +20 -3
  83. package/src/proto/gen/dxos/client/services.ts +30 -3
  84. package/src/proto/gen/google/protobuf.ts +4 -4
  85. package/src/proto/gen/index.ts +2 -1
  86. package/src/queue.ts +13 -0
  87. package/dist/src/edge-error.d.ts +0 -26
  88. package/dist/src/edge-error.d.ts.map +0 -1
  89. package/dist/src/edge-error.js +0 -102
  90. package/dist/src/edge-error.js.map +0 -1
  91. package/dist/src/edge.d.ts.map +0 -1
  92. package/dist/src/edge.js +0 -49
  93. package/dist/src/edge.js.map +0 -1
  94. package/src/edge-error.ts +0 -134
  95. package/src/edge.ts +0 -279
@@ -0,0 +1,95 @@
1
+ import { type SpaceId } from '@dxos/keys';
2
+ import { type QueryResult, type QueueQuery } from '../queue';
3
+ /**
4
+ * Environment available to the function running on Cloudflare.
5
+ */
6
+ export interface Env {
7
+ QUEUE_SERVICE: QueueService;
8
+ DATA_SERVICE: DataService;
9
+ }
10
+ /**
11
+ * Use to trace the execution across multiple services.
12
+ *
13
+ * NOTE: Currently unused in functions.
14
+ */
15
+ export interface ExecutionContext {
16
+ }
17
+ /**
18
+ * Database API for other CF services like functions.
19
+ */
20
+ export interface DataService {
21
+ getSpaceMeta(ctx: ExecutionContext, spaceId: SpaceId): Promise<SpaceMeta | undefined>;
22
+ getDocument(ctx: ExecutionContext, spaceId: SpaceId, documentId: string): Promise<RawDocument | undefined>;
23
+ query(ctx: ExecutionContext, request: QueryRequest): Promise<QueryResponse>;
24
+ queryDocuments(ctx: ExecutionContext, request: QueryRequest): Promise<QueryDocumentsResponse>;
25
+ queryReferences(ctx: ExecutionContext, request: QueryReferencesRequest): Promise<QueryReferencesResponse>;
26
+ changeDocument(ctx: ExecutionContext, spaceId: SpaceId, documentId: string, changes: Uint8Array): Promise<void>;
27
+ }
28
+ export interface QueueService {
29
+ query(ctx: ExecutionContext, queueDXN: string, query: Omit<QueueQuery, 'queueId'>): Promise<QueryResult>;
30
+ append(ctx: ExecutionContext, queueDXN: string, objects: unknown[]): Promise<void>;
31
+ }
32
+ export type ObjectDocumentJson = {
33
+ type?: string;
34
+ objectId: string;
35
+ documentId: string;
36
+ /** Base64 encoding of a document. */
37
+ document: string;
38
+ };
39
+ export type SpaceMeta = {
40
+ spaceKey: string;
41
+ rootDocumentId: string;
42
+ };
43
+ export type QueryRequest = {
44
+ spaceId: string;
45
+ type?: string;
46
+ where?: Record<string, any>;
47
+ objectIds?: string[];
48
+ cursor?: string;
49
+ limit?: number;
50
+ };
51
+ export type QueryResponse = {
52
+ results: ObjectSnapshot[];
53
+ cursor?: string;
54
+ };
55
+ /**
56
+ * TODO(yaroslav): make Indexer return EchoObject after create() can properly reconstruct an object
57
+ * from this structure (meta, id and type aren't handled properly)
58
+ */
59
+ export type ObjectSnapshot = {
60
+ type?: string;
61
+ documentId: string;
62
+ objectId: string;
63
+ object: unknown;
64
+ };
65
+ export type ObjectReference = {
66
+ fromId: string;
67
+ toId: string;
68
+ fieldName: string;
69
+ };
70
+ export type QueryDocumentsResponse = {
71
+ results: RawObject[];
72
+ cursor?: string;
73
+ };
74
+ export type RawDocument = {
75
+ documentId: string;
76
+ data: Uint8Array;
77
+ };
78
+ export type RawObject = {
79
+ type?: string;
80
+ objectId: string;
81
+ document: RawDocument;
82
+ };
83
+ export type QueryReferencesRequest = {
84
+ spaceId: string;
85
+ objectId: string;
86
+ referenceType: 'from' | 'to';
87
+ };
88
+ export type QueryReferencesResponse = {
89
+ references: ObjectReference[];
90
+ };
91
+ export type CreateDocumentResponse = {
92
+ /** Automerge document ID. */
93
+ documentId: string;
94
+ };
95
+ //# sourceMappingURL=EdgeFunctionEnv.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EdgeFunctionEnv.d.ts","sourceRoot":"","sources":["../../../src/edge/EdgeFunctionEnv.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,UAAU,EAAE,MAAM,UAAU,CAAC;AAiD7D;;GAEG;AACH,MAAM,WAAW,GAAG;IAClB,aAAa,EAAE,YAAY,CAAC;IAC5B,YAAY,EAAE,WAAW,CAAC;CAC3B;AAED;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;CAAG;AAEpC;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,YAAY,CAAC,GAAG,EAAE,gBAAgB,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC,CAAC;IACtF,WAAW,CAAC,GAAG,EAAE,gBAAgB,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC,CAAC;IAE3G,KAAK,CAAC,GAAG,EAAE,gBAAgB,EAAE,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;IAC5E,cAAc,CAAC,GAAG,EAAE,gBAAgB,EAAE,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAAC;IAC9F,eAAe,CAAC,GAAG,EAAE,gBAAgB,EAAE,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAC;IAG1G,cAAc,CAAC,GAAG,EAAE,gBAAgB,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACjH;AAED,MAAM,WAAW,YAAY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;IACf,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,OAAO,EAAE,SAAS,EAAE,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,UAAU,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,WAAW,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,UAAU,EAAE,eAAe,EAAE,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,6BAA6B;IAC7B,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC"}
@@ -0,0 +1,4 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+ //# sourceMappingURL=EdgeFunctionEnv.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EdgeFunctionEnv.js","sourceRoot":"","sources":["../../../src/edge/EdgeFunctionEnv.ts"],"names":[],"mappings":"AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE"}
@@ -7,19 +7,37 @@ export declare enum EdgeService {
7
7
  SIGNAL = "signal",
8
8
  STATUS = "status"
9
9
  }
10
- export type EdgeHttpSuccess<T> = {
10
+ export type EdgeSuccess<T> = {
11
11
  success: true;
12
12
  data: T;
13
13
  };
14
+ export type SerializedError = {
15
+ code?: string;
16
+ message?: string;
17
+ context?: Record<string, unknown>;
18
+ stack?: string;
19
+ cause?: SerializedError;
20
+ };
14
21
  export type EdgeErrorData = {
15
22
  type: string;
16
23
  } & Record<string, any>;
17
- export type EdgeHttpFailure = {
24
+ /**
25
+ * This is the shape of the error response from the Edge service,
26
+ * when the error is gracefully handled, the Response will be an object with this shape and have status code 200.
27
+ */
28
+ export type EdgeFailure = {
29
+ /**
30
+ * Branded Type.
31
+ */
18
32
  success: false;
19
33
  /**
20
34
  * An explanation of why the call failed. Used mostly for logging and monitoring.
21
35
  */
22
- reason: string;
36
+ message: string;
37
+ /**
38
+ * Cause Error captured on the EDGE service to aid debugging on the client.
39
+ */
40
+ error?: SerializedError;
23
41
  /**
24
42
  * Information that can be used to retry the request such that it will succeed, for example:
25
43
  * 1. { type: 'auth_required', challenge: string }
@@ -27,12 +45,62 @@ export type EdgeHttpFailure = {
27
45
  * 2. { type: 'user_confirmation_required', dialog: { title: string, message: string, confirmation_payload: string } }
28
46
  * Requires showing a confirmation dialog to a user and retrying the request with confirmation_payload included
29
47
  * if the user confirms.
30
- * When errorData is returned simply retrying the request won't have any effect.
31
- * EdgeHttpClient should parse well-known errorData into Error types and throw.
48
+ * When data is returned simply retrying the request won't have any effect.
49
+ * EdgeHttpClient should parse well-known data into Error types and throw.
32
50
  */
33
- errorData?: EdgeErrorData;
51
+ data?: EdgeErrorData;
34
52
  };
35
- export type EdgeHttpResponse<T> = EdgeHttpSuccess<T> | EdgeHttpFailure;
53
+ /**
54
+ * Represents a body response from the Edge service.
55
+ */
56
+ export type EdgeEnvelope<T> = EdgeSuccess<T> | EdgeFailure;
57
+ /**
58
+ * Use this to create a response from the Edge service.
59
+ */
60
+ export declare const EdgeResponse: Readonly<{
61
+ success: <T>(data: T, status?: number) => Response;
62
+ failure: ({ message, error, errorEncoded, data, shouldRetryAfter, status, }: {
63
+ /**
64
+ * An explanation of why the call failed. Used mostly for logging and monitoring.
65
+ */
66
+ message: string;
67
+ /**
68
+ * Error that caused the failure.
69
+ * Useful for debugging.
70
+ *
71
+ * Use only one of the fields `error` or `errorEncoded`.s
72
+ */
73
+ error?: Error;
74
+ /**
75
+ * Encoded Error that caused the failure.
76
+ * Useful for debugging.
77
+ *
78
+ * Use only one of the fields `error` or `errorEncoded`.
79
+ */
80
+ errorEncoded?: SerializedError;
81
+ /**
82
+ * Information that can be used to retry the request such that it will succeed, for example:
83
+ * 1. { type: 'auth_required', challenge: string }
84
+ * Requires retrying the request with challenge signature included.
85
+ * 2. { type: 'user_confirmation_required', dialog: { title: string, message: string, confirmation_payload: string } }
86
+ * Requires showing a confirmation dialog to a user and retrying the request with confirmation_payload included
87
+ * if the user confirms.
88
+ * When data is returned simply retrying the request won't have any effect.
89
+ * EdgeHttpClient should parse well-known data into Error types and throw.
90
+ */
91
+ data?: EdgeErrorData;
92
+ /**
93
+ * If provided, this request will be marked as retryable and the client will wait for the specified number of milliseconds before retrying.
94
+ * If not provided, the client will not retry the request.
95
+ */
96
+ shouldRetryAfter?: number;
97
+ /**
98
+ * Status code of the response.
99
+ * @default 500
100
+ */
101
+ status?: number;
102
+ }) => Response;
103
+ }>;
36
104
  export type GetNotarizationResponseBody = {
37
105
  awaitingNotarization: {
38
106
  credentials: string[];
@@ -98,7 +166,21 @@ export type UploadFunctionRequest = {
98
166
  ownerPublicKey: string;
99
167
  entryPoint: string;
100
168
  assets: Record<string, Uint8Array>;
169
+ /**
170
+ * Runtime in Edge that will be used to run the function.
171
+ * Runtime cannot be changed once the function was deployed.
172
+ * @default Runtime.WORKERS_FOR_PLATFORMS
173
+ */
174
+ runtime?: Runtime;
101
175
  };
176
+ /**
177
+ * Note: Do not change the values of these enums, this values are stored in the FunctionVersions database.
178
+ */
179
+ export declare enum Runtime {
180
+ WORKERS_FOR_PLATFORMS = "WORKERS_FOR_PLATFORMS",
181
+ WORKER_LOADER = "WORKER_LOADER",
182
+ TEST = "TEST"
183
+ }
102
184
  export type UploadFunctionResponseBody = {
103
185
  functionId: string;
104
186
  version: string;
@@ -147,7 +229,7 @@ export declare const InitiateOAuthFlowRequestSchema: Schema.Struct<{
147
229
  provider: Schema.Enums<typeof OAuthProvider>;
148
230
  spaceId: Schema.refine<string & {
149
231
  __SpaceId: true;
150
- }, Schema.Schema<string, string, never>>;
232
+ }, Schema.Schema<unknown, string, never>>;
151
233
  accessTokenId: typeof Schema.String;
152
234
  scopes: Schema.mutable<Schema.Array$<typeof Schema.String>>;
153
235
  noRefresh: Schema.optional<typeof Schema.Boolean>;
@@ -239,8 +321,22 @@ export type ExportBundleResponse = {
239
321
  mutation: string;
240
322
  }[];
241
323
  };
242
- export declare const DocumentCodec: {
324
+ export declare const DocumentCodec: Readonly<{
243
325
  encode: (doc: Uint8Array) => string;
244
326
  decode: (doc: string) => Uint8Array<ArrayBuffer>;
245
- };
327
+ }>;
328
+ /**
329
+ * Codec for serializing and deserializing Edge Errors.
330
+ */
331
+ export declare const ErrorCodec: Readonly<{
332
+ encode: (err: Error, depth?: number) => SerializedError;
333
+ decode: (serializedError: SerializedError, depth?: number) => Error;
334
+ }>;
335
+ /**
336
+ * Codec for serializing and deserializing Edge unhandled HTTP errors.
337
+ */
338
+ export declare const EdgeHttpErrorCodec: Readonly<{
339
+ encode: (err: Error) => Response;
340
+ decode: (response: Response) => Promise<Error | undefined>;
341
+ }>;
246
342
  //# sourceMappingURL=edge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"edge.d.ts","sourceRoot":"","sources":["../../../src/edge/edge.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAIxC,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAIrC,oBAAY,WAAW;IACrB,oBAAoB,yBAAyB;IAC7C,eAAe,oBAAoB;IACnC,KAAK,UAAU;IACf,MAAM,WAAW;IACjB,MAAM,WAAW;CAClB;AAED,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;IAC3B,OAAO,EAAE,IAAI,CAAC;IACd,IAAI,EAAE,CAAC,CAAC;CACT,CAAC;AAEF,MAAM,M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/errors';
6
+ import { invariant } from '@dxos/invariant';
7
+ import { SpaceId } from '@dxos/keys';
8
+ // TODO(burdon): Rename EdgerRouterEndpoint.
9
+ // If we would rename it, we need to be careful to not break composer production.
10
+ export var EdgeService;
11
+ (function (EdgeService) {
12
+ EdgeService["AUTOMERGE_REPLICATOR"] = "automerge-replicator";
13
+ EdgeService["FEED_REPLICATOR"] = "feed-replicator";
14
+ EdgeService["SWARM"] = "swarm";
15
+ EdgeService["SIGNAL"] = "signal";
16
+ EdgeService["STATUS"] = "status";
17
+ })(EdgeService || (EdgeService = {}));
18
+ /**
19
+ * Use this to create a response from the Edge service.
20
+ */
21
+ export const EdgeResponse = Object.freeze({
22
+ success: (data, status = 200) => {
23
+ invariant(status >= 200 && status < 300, 'Status code must be in the 2xx range');
24
+ const headers = new Headers({ 'Content-Type': 'application/json' });
25
+ return new Response(JSON.stringify({
26
+ success: true,
27
+ data,
28
+ }), {
29
+ status,
30
+ headers,
31
+ });
32
+ },
33
+ failure: ({ message, error, errorEncoded, data, shouldRetryAfter, status = 500, }) => {
34
+ const headers = new Headers({ 'Content-Type': 'application/json' });
35
+ if (shouldRetryAfter) {
36
+ headers.set('Retry-After', String(shouldRetryAfter));
37
+ }
38
+ return new Response(JSON.stringify({
39
+ success: false,
40
+ message,
41
+ data,
42
+ error: error ? ErrorCodec.encode(error) : errorEncoded,
43
+ }), {
44
+ status,
45
+ headers,
46
+ });
47
+ },
48
+ });
49
+ /**
50
+ * Note: Do not change the values of these enums, this values are stored in the FunctionVersions database.
51
+ */
52
+ export var Runtime;
53
+ (function (Runtime) {
54
+ // https://developers.cloudflare.com/cloudflare-for-platforms/workers-for-platforms/
55
+ Runtime["WORKERS_FOR_PLATFORMS"] = "WORKERS_FOR_PLATFORMS";
56
+ // https://developers.cloudflare.com/workers/runtime-apis/bindings/worker-loader/
57
+ Runtime["WORKER_LOADER"] = "WORKER_LOADER";
58
+ // Local worker dispatcher for testing.
59
+ Runtime["TEST"] = "TEST";
60
+ })(Runtime || (Runtime = {}));
61
+ export var EdgeAgentStatus;
62
+ (function (EdgeAgentStatus) {
63
+ EdgeAgentStatus["ACTIVE"] = "active";
64
+ EdgeAgentStatus["INACTIVE"] = "inactive";
65
+ EdgeAgentStatus["NOT_FOUND"] = "not_found";
66
+ })(EdgeAgentStatus || (EdgeAgentStatus = {}));
67
+ export var OAuthProvider;
68
+ (function (OAuthProvider) {
69
+ OAuthProvider["GOOGLE"] = "google";
70
+ OAuthProvider["BLUESKY"] = "bluesky";
71
+ })(OAuthProvider || (OAuthProvider = {}));
72
+ export const InitiateOAuthFlowRequestSchema = Schema.Struct({
73
+ provider: Schema.Enums(OAuthProvider),
74
+ spaceId: Schema.String.pipe(Schema.filter(SpaceId.isValid)), // TODO(burdon): Use SpaceId.
75
+ accessTokenId: Schema.String,
76
+ scopes: Schema.mutable(Schema.Array(Schema.String)),
77
+ // Set to true if we don't want periodic token refreshes in background, for cases like account connect
78
+ noRefresh: Schema.optional(Schema.Boolean),
79
+ // Provider-specific (user handle or did for bluesky) hint for auth server resolution
80
+ loginHint: Schema.optional(Schema.String),
81
+ });
82
+ export var EdgeWebsocketProtocol;
83
+ (function (EdgeWebsocketProtocol) {
84
+ EdgeWebsocketProtocol["V0"] = "edge-ws-v0";
85
+ /**
86
+ * Enables message framing and muxing by service-id.
87
+ */
88
+ EdgeWebsocketProtocol["V1"] = "edge-ws-v1";
89
+ })(EdgeWebsocketProtocol || (EdgeWebsocketProtocol = {}));
90
+ export const DocumentCodec = Object.freeze({
91
+ encode: (doc) => Buffer.from(doc).toString('base64'),
92
+ decode: (doc) => new Uint8Array(Buffer.from(doc, 'base64')),
93
+ });
94
+ const MAX_ERROR_DEPTH = 3;
95
+ /**
96
+ * Codec for serializing and deserializing Edge Errors.
97
+ */
98
+ export const ErrorCodec = Object.freeze({
99
+ encode: (err, depth = 0) => ({
100
+ code: 'code' in err ? err.code : undefined,
101
+ message: err.message,
102
+ stack: err.stack,
103
+ cause: err.cause instanceof Error && depth < MAX_ERROR_DEPTH ? ErrorCodec.encode(err.cause, depth + 1) : undefined,
104
+ }),
105
+ decode: (serializedError, depth = 0) => {
106
+ let err;
107
+ if (typeof serializedError.code === 'string') {
108
+ err = new BaseError(serializedError.code, {
109
+ message: serializedError.message ?? 'Unknown error',
110
+ cause: serializedError.cause && depth < MAX_ERROR_DEPTH
111
+ ? ErrorCodec.decode(serializedError.cause, depth + 1)
112
+ : undefined,
113
+ context: serializedError.context,
114
+ });
115
+ if (serializedError.stack) {
116
+ Object.defineProperty(err, 'stack', {
117
+ value: serializedError.stack,
118
+ });
119
+ }
120
+ }
121
+ else {
122
+ err = new Error(serializedError.message ?? 'Unknown error', {
123
+ cause: serializedError.cause && depth < MAX_ERROR_DEPTH
124
+ ? ErrorCodec.decode(serializedError.cause, depth + 1)
125
+ : undefined,
126
+ });
127
+ if (serializedError.stack) {
128
+ Object.defineProperty(err, 'stack', {
129
+ value: serializedError.stack,
130
+ });
131
+ }
132
+ }
133
+ return err;
134
+ },
135
+ });
136
+ /**
137
+ * Codec for serializing and deserializing Edge unhandled HTTP errors.
138
+ */
139
+ export const EdgeHttpErrorCodec = Object.freeze({
140
+ encode: (err) => new Response(JSON.stringify({
141
+ error: ErrorCodec.encode(err),
142
+ }), { status: 500 }),
143
+ decode: async (response) => {
144
+ if (response.headers.get('Content-Type') !== 'application/json') {
145
+ const body = await response.clone().text();
146
+ return new Error(body.slice(0, 256));
147
+ }
148
+ const body = await response.clone().json();
149
+ if (!('error' in body)) {
150
+ return undefined;
151
+ }
152
+ return ErrorCodec.decode(body.error);
153
+ },
154
+ });
155
+ //# sourceMappingURL=edge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"edge.js","sourceRoot":"","sources":["../../../src/edge/edge.ts"],"names":[],"mappings":"AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;AAEF,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC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IAEH,MAAM,EAAE,KAAK,EAAE,QAAkB,EAA8B,EAAE;QAC/D,IAAI,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,KAAK,kBAAkB,EAAE,CAAC;YAChE,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,CAAC;YAC3C,OAAO,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;QACvC,CAAC;QAED,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,CAAC;QAC3C,IAAI,CAAC,CAAC,OAAO,IAAI,IAAI,CAAC,EAAE,CAAC;YACvB,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,OAAO,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACvC,CAAC;CACF,CAAC,CAAC"}
@@ -0,0 +1,29 @@
1
+ import { type EdgeErrorData, type EdgeFailure } from './edge.js';
2
+ /**
3
+ * Error thrown when a call to the Edge service fails.
4
+ * There 3 possible sources of failure:
5
+ * 1. EdgeFailure (JSON body with { success: false }) -> Processing the request failed and was gracefully handled by EDGE service.
6
+ * 2. Http failure (non-ok code) -> The HTTP request failed (e.g. timeout, network error).
7
+ * -> Unhandled exception on EDGE side, EDGE would provide serialized error in the response body.
8
+ * 3. Processing failure -> Unhandled exception on client side while processing the response.
9
+ */
10
+ export declare class EdgeCallFailedError extends Error {
11
+ static fromUnsuccessfulResponse(response: Response, body: EdgeFailure): EdgeCallFailedError;
12
+ static fromHttpFailure(response: Response): Promise<EdgeCallFailedError>;
13
+ static fromProcessingFailureCause(cause: Error): EdgeCallFailedError;
14
+ readonly data?: EdgeErrorData;
15
+ readonly isRetryable?: boolean;
16
+ readonly retryAfterMs?: number;
17
+ constructor(args: {
18
+ message: string;
19
+ isRetryable?: boolean;
20
+ data?: EdgeErrorData;
21
+ retryAfterMs?: number;
22
+ cause?: Error;
23
+ });
24
+ }
25
+ export declare class EdgeAuthChallengeError extends EdgeCallFailedError {
26
+ readonly challenge: string;
27
+ constructor(challenge: string, data: EdgeErrorData);
28
+ }
29
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/edge/errors.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,WAAW,EAAkC,MAAM,WAAW,CAAC;AAGjG;;;;;;;GAOG;AACH,qBAAa,mBAAoB,SAAQ,KAAK;WAC9B,wBAAwB,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,GAAG,mBAAmB;WAY9E,eAAe,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,mBAAmB,CAAC;WASvE,0BAA0B,CAAC,KAAK,EAAE,KAAK,GAAG,mBAAmB;IAQ3E,QAAQ,CAAC,IAAI,CAAC,EAAE,aAAa,CAAC;IAC9B,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC;IAC/B,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;gBAEnB,IAAI,EAAE;QAChB,OAAO,EAAE,MAAM,CAAC;QAChB,WAAW,CAAC,EAAE,OAAO,CAAC;QACtB,IAAI,CAAC,EAAE,aAAa,CAAC;QACrB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,KAAK,CAAC,EAAE,KAAK,CAAC;KACf;CAOF;AAED,qBAAa,sBAAuB,SAAQ,mBAAmB;aAE3C,SAAS,EAAE,MAAM;gBAAjB,SAAS,EAAE,MAAM,EACjC,IAAI,EAAE,aAAa;CAItB"}
@@ -0,0 +1,69 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+ import { EdgeHttpErrorCodec, ErrorCodec } from './edge.js';
5
+ // TODO(burdon): Reconcile with @dxos/errors.
6
+ /**
7
+ * Error thrown when a call to the Edge service fails.
8
+ * There 3 possible sources of failure:
9
+ * 1. EdgeFailure (JSON body with { success: false }) -> Processing the request failed and was gracefully handled by EDGE service.
10
+ * 2. Http failure (non-ok code) -> The HTTP request failed (e.g. timeout, network error).
11
+ * -> Unhandled exception on EDGE side, EDGE would provide serialized error in the response body.
12
+ * 3. Processing failure -> Unhandled exception on client side while processing the response.
13
+ */
14
+ export class EdgeCallFailedError extends Error {
15
+ static fromUnsuccessfulResponse(response, body) {
16
+ const error = new EdgeCallFailedError({
17
+ message: body.message,
18
+ data: body.data,
19
+ isRetryable: body.data == null && response.headers.has('Retry-After'),
20
+ retryAfterMs: getRetryAfterMillis(response),
21
+ cause: body.error ? ErrorCodec.decode(body.error) : undefined,
22
+ });
23
+ return error;
24
+ }
25
+ static async fromHttpFailure(response) {
26
+ return new EdgeCallFailedError({
27
+ message: `HTTP code ${response.status}: ${response.statusText}.`,
28
+ isRetryable: isRetryableCode(response.status),
29
+ retryAfterMs: getRetryAfterMillis(response),
30
+ cause: await EdgeHttpErrorCodec.decode(response),
31
+ });
32
+ }
33
+ static fromProcessingFailureCause(cause) {
34
+ return new EdgeCallFailedError({
35
+ message: 'Error processing request.',
36
+ isRetryable: true,
37
+ cause,
38
+ });
39
+ }
40
+ data;
41
+ isRetryable;
42
+ retryAfterMs;
43
+ constructor(args) {
44
+ super(args.message, { cause: args.cause });
45
+ this.message = args.message;
46
+ this.data = args.data;
47
+ this.retryAfterMs = args.retryAfterMs;
48
+ this.isRetryable = Boolean(args.isRetryable);
49
+ }
50
+ }
51
+ export class EdgeAuthChallengeError extends EdgeCallFailedError {
52
+ challenge;
53
+ constructor(challenge, data) {
54
+ super({ message: 'Auth challenge.', data, isRetryable: false });
55
+ this.challenge = challenge;
56
+ }
57
+ }
58
+ const getRetryAfterMillis = (response) => {
59
+ const retryAfter = Number(response.headers.get('Retry-After'));
60
+ return Number.isNaN(retryAfter) || retryAfter === 0 ? undefined : retryAfter * 1000;
61
+ };
62
+ const isRetryableCode = (status) => {
63
+ if (status === 501) {
64
+ // Not Implemented
65
+ return false;
66
+ }
67
+ return !(status >= 400 && status < 500);
68
+ };
69
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/edge/errors.ts"],"names":[],"mappings":"AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;AAEF,OAAO,EAAwC,kBAAkB,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEjG,6CAA6C;AAC7C;;;;;;;GAOG;AACH,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IACrC,MAAM,CAAC,wBAAwB,CAAC,QAAkB,EAAE,IAAiB;QAC1E,MAAM,KAAK,GAAG,IAAI,mBAAmB,CAAC;YACpC,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,WAAW,EAAE,IAAI,CAAC,IAAI,IAAI,IAAI,IAAI,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC;YACrE,YAAY,EAAE,mBAAmB,CAAC,QAAQ,CAAC;YAC3C,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS;SAC9D,CAAC,CAAC;QAEH,OAAO,KAAK,CAAC;IACf,CAAC;IAEM,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,QAAkB;QACpD,OAAO,IAAI,mBAAmB,CAAC;YAC7B,OAAO,EAAE,aAAa,QAAQ,CAAC,MAAM,KAAK,QAAQ,CAAC,UAAU,GAAG;YAChE,WAAW,EAAE,eAAe,CAAC,QAAQ,CAAC,MAAM,CAAC;YAC7C,YAAY,EAAE,mBAAmB,CAAC,QAAQ,CAAC;YAC3C,KAAK,EAAE,MAAM,kBAAkB,CAAC,MAAM,CAAC,QAAQ,CAAC;SACjD,CAAC,CAAC;IACL,CAAC;IAEM,MAA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AAK,CAAC;IACf,CAAC;IACD,OAAO,CAAC,CAAC,MAAM,IAAI,GAAG,IAAI,MAAM,GAAG,GAAG,CAAC,CAAC;AAC1C,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from './edge.js';
2
+ export * as EdgeFunctionEnv from './EdgeFunctionEnv.js';
3
+ export * from './errors.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/edge/index.ts"],"names":[],"mappings":"AAIA,cAAc,WAAW,CAAC;AAC1B,OAAO,KAAK,eAAe,MAAM,sBAAsB,CAAC;AACxD,cAAc,aAAa,CAAC"}
@@ -0,0 +1,7 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+ export * from './edge.js';
5
+ export * as EdgeFunctionEnv from './EdgeFunctionEnv.js';
6
+ export * from './errors.js';
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/edge/index.ts"],"names":[],"mappings":"AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;AAEF,cAAc,WAAW,CAAC;AAC1B,OAAO,KAAK,eAAe,MAAM,sBAAsB,CAAC;AACxD,cAAc,aAAa,CAAC"}