@dxos/edge-client 0.8.4-main.937b3ca → 0.8.4-main.9be5663bfe

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 (33) hide show
  1. package/dist/lib/{browser → neutral}/index.mjs +136 -89
  2. package/dist/lib/neutral/index.mjs.map +7 -0
  3. package/dist/lib/neutral/meta.json +1 -0
  4. package/dist/types/src/edge-client.d.ts +5 -2
  5. package/dist/types/src/edge-client.d.ts.map +1 -1
  6. package/dist/types/src/edge-http-client.d.ts +39 -29
  7. package/dist/types/src/edge-http-client.d.ts.map +1 -1
  8. package/dist/types/src/edge-ws-connection.d.ts +1 -0
  9. package/dist/types/src/edge-ws-connection.d.ts.map +1 -1
  10. package/dist/types/tsconfig.tsbuildinfo +1 -1
  11. package/package.json +23 -24
  12. package/src/edge-client.test.ts +16 -11
  13. package/src/edge-client.ts +32 -3
  14. package/src/edge-http-client.test.ts +2 -1
  15. package/src/edge-http-client.ts +134 -51
  16. package/src/edge-ws-connection.ts +2 -1
  17. package/dist/lib/browser/index.mjs.map +0 -7
  18. package/dist/lib/browser/meta.json +0 -1
  19. package/dist/lib/node-esm/chunk-JTBFRYNM.mjs +0 -303
  20. package/dist/lib/node-esm/chunk-JTBFRYNM.mjs.map +0 -7
  21. package/dist/lib/node-esm/edge-ws-muxer.mjs +0 -12
  22. package/dist/lib/node-esm/edge-ws-muxer.mjs.map +0 -7
  23. package/dist/lib/node-esm/index.mjs +0 -1375
  24. package/dist/lib/node-esm/index.mjs.map +0 -7
  25. package/dist/lib/node-esm/meta.json +0 -1
  26. package/dist/lib/node-esm/testing/index.mjs +0 -186
  27. package/dist/lib/node-esm/testing/index.mjs.map +0 -7
  28. /package/dist/lib/{browser → neutral}/chunk-VESGVCLQ.mjs +0 -0
  29. /package/dist/lib/{browser → neutral}/chunk-VESGVCLQ.mjs.map +0 -0
  30. /package/dist/lib/{browser → neutral}/edge-ws-muxer.mjs +0 -0
  31. /package/dist/lib/{browser → neutral}/edge-ws-muxer.mjs.map +0 -0
  32. /package/dist/lib/{browser → neutral}/testing/index.mjs +0 -0
  33. /package/dist/lib/{browser → neutral}/testing/index.mjs.map +0 -0
@@ -4,6 +4,7 @@
4
4
 
5
5
  import * as FetchHttpClient from '@effect/platform/FetchHttpClient';
6
6
  import * as HttpClient from '@effect/platform/HttpClient';
7
+ import { type Context as OtelContext, propagation } from '@opentelemetry/api';
7
8
  import * as Effect from 'effect/Effect';
8
9
  import * as Function from 'effect/Function';
9
10
 
@@ -18,6 +19,7 @@ import {
18
19
  type CreateAgentResponseBody,
19
20
  type CreateSpaceRequest,
20
21
  type CreateSpaceResponseBody,
22
+ EDGE_CLIENT_TAG_HEADER,
21
23
  EdgeAuthChallengeError,
22
24
  EdgeCallFailedError,
23
25
  type EdgeFailure,
@@ -25,6 +27,7 @@ import {
25
27
  type ExecuteWorkflowResponseBody,
26
28
  type ExportBundleRequest,
27
29
  type ExportBundleResponse,
30
+ type FeedProtocol,
28
31
  type GetAgentStatusResponseBody,
29
32
  type GetNotarizationResponseBody,
30
33
  type ImportBundleRequest,
@@ -34,13 +37,16 @@ import {
34
37
  type JoinSpaceResponseBody,
35
38
  type ObjectId,
36
39
  type PostNotarizationRequestBody,
37
- type QueryResult,
38
- type QueueQuery,
39
40
  type RecoverIdentityRequest,
40
41
  type RecoverIdentityResponseBody,
41
42
  type UploadFunctionRequest,
42
43
  type UploadFunctionResponseBody,
43
44
  } from '@dxos/protocols';
45
+ import {
46
+ type QueryRequest as QueryRequestProto,
47
+ type QueryResponse as QueryResponseProto,
48
+ } from '@dxos/protocols/proto/dxos/echo/query';
49
+ import { TRACE_PROCESSOR, TRACE_SPAN_ATTRIBUTE } from '@dxos/tracing';
44
50
  import { createUrl } from '@dxos/util';
45
51
 
46
52
  import { type EdgeIdentity, handleAuthChallenge } from './edge-identity';
@@ -69,7 +75,6 @@ export type RetryConfig = {
69
75
 
70
76
  type EdgeHttpRequestArgs = {
71
77
  method: string;
72
- context?: Context;
73
78
  retry?: RetryConfig;
74
79
  body?: any;
75
80
  /**
@@ -85,15 +90,23 @@ type EdgeHttpRequestArgs = {
85
90
  auth?: boolean;
86
91
  };
87
92
 
88
- export type EdgeHttpGetArgs = Pick<EdgeHttpRequestArgs, 'context' | 'retry' | 'auth'>;
89
- export type EdgeHttpPostArgs = Pick<EdgeHttpRequestArgs, 'context' | 'retry' | 'body' | 'auth'>;
93
+ export type EdgeHttpCallArgs = Pick<EdgeHttpRequestArgs, 'retry' | 'auth'>;
90
94
 
91
95
  export type GetCronTriggersResponse = {
92
96
  cronIds: string[];
93
97
  };
94
98
 
99
+ export type EdgeHttpClientOptions = {
100
+ /**
101
+ * Tag included in the {@link EDGE_CLIENT_TAG_HEADER} header on every request.
102
+ * Used on Edge to classify traffic for metering (e.g. `ci-e2e`).
103
+ */
104
+ clientTag?: string;
105
+ };
106
+
95
107
  export class EdgeHttpClient {
96
108
  private readonly _baseUrl: string;
109
+ private readonly _clientTag: string | undefined;
97
110
 
98
111
  private _edgeIdentity: EdgeIdentity | undefined;
99
112
 
@@ -102,8 +115,9 @@ export class EdgeHttpClient {
102
115
  */
103
116
  private _authHeader: string | undefined;
104
117
 
105
- constructor(baseUrl: string) {
118
+ constructor(baseUrl: string, options?: EdgeHttpClientOptions) {
106
119
  this._baseUrl = getEdgeUrlWithProtocol(baseUrl, 'http');
120
+ this._clientTag = options?.clientTag;
107
121
  log('created', { url: this._baseUrl });
108
122
  }
109
123
 
@@ -122,23 +136,28 @@ export class EdgeHttpClient {
122
136
  // Status
123
137
  //
124
138
 
125
- public async getStatus(args?: EdgeHttpGetArgs): Promise<EdgeStatus> {
126
- return this._call(new URL('/status', this.baseUrl), { ...args, method: 'GET', auth: true });
139
+ public async getStatus(ctx: Context, args?: EdgeHttpCallArgs): Promise<EdgeStatus> {
140
+ return this._call(ctx, new URL('/status', this.baseUrl), { ...args, method: 'GET', auth: true });
127
141
  }
128
142
 
129
143
  //
130
144
  // Agents
131
145
  //
132
146
 
133
- public createAgent(body: CreateAgentRequestBody, args?: EdgeHttpGetArgs): Promise<CreateAgentResponseBody> {
134
- return this._call(new URL('/agents/create', this.baseUrl), { ...args, method: 'POST', body });
147
+ public createAgent(
148
+ ctx: Context,
149
+ body: CreateAgentRequestBody,
150
+ args?: EdgeHttpCallArgs,
151
+ ): Promise<CreateAgentResponseBody> {
152
+ return this._call(ctx, new URL('/agents/create', this.baseUrl), { ...args, method: 'POST', body });
135
153
  }
136
154
 
137
155
  public getAgentStatus(
156
+ ctx: Context,
138
157
  request: { ownerIdentityKey: PublicKey },
139
- args?: EdgeHttpGetArgs,
158
+ args?: EdgeHttpCallArgs,
140
159
  ): Promise<GetAgentStatusResponseBody> {
141
- return this._call(new URL(`/users/${request.ownerIdentityKey.toHex()}/agent/status`, this.baseUrl), {
160
+ return this._call(ctx, new URL(`/users/${request.ownerIdentityKey.toHex()}/agent/status`, this.baseUrl), {
142
161
  ...args,
143
162
  method: 'GET',
144
163
  });
@@ -148,16 +167,21 @@ export class EdgeHttpClient {
148
167
  // Credentials
149
168
  //
150
169
 
151
- public getCredentialsForNotarization(spaceId: SpaceId, args?: EdgeHttpGetArgs): Promise<GetNotarizationResponseBody> {
152
- return this._call(new URL(`/spaces/${spaceId}/notarization`, this.baseUrl), { ...args, method: 'GET' });
170
+ public getCredentialsForNotarization(
171
+ ctx: Context,
172
+ spaceId: SpaceId,
173
+ args?: EdgeHttpCallArgs,
174
+ ): Promise<GetNotarizationResponseBody> {
175
+ return this._call(ctx, new URL(`/spaces/${spaceId}/notarization`, this.baseUrl), { ...args, method: 'GET' });
153
176
  }
154
177
 
155
178
  public async notarizeCredentials(
179
+ ctx: Context,
156
180
  spaceId: SpaceId,
157
181
  body: PostNotarizationRequestBody,
158
- args?: EdgeHttpGetArgs,
182
+ args?: EdgeHttpCallArgs,
159
183
  ): Promise<void> {
160
- await this._call(new URL(`/spaces/${spaceId}/notarization`, this.baseUrl), { ...args, body, method: 'POST' });
184
+ await this._call(ctx, new URL(`/spaces/${spaceId}/notarization`, this.baseUrl), { ...args, body, method: 'POST' });
161
185
  }
162
186
 
163
187
  //
@@ -165,10 +189,11 @@ export class EdgeHttpClient {
165
189
  //
166
190
 
167
191
  public async recoverIdentity(
192
+ ctx: Context,
168
193
  body: RecoverIdentityRequest,
169
- args?: EdgeHttpGetArgs,
194
+ args?: EdgeHttpCallArgs,
170
195
  ): Promise<RecoverIdentityResponseBody> {
171
- return this._call(new URL('/identity/recover', this.baseUrl), { ...args, body, method: 'POST' });
196
+ return this._call(ctx, new URL('/identity/recover', this.baseUrl), { ...args, body, method: 'POST' });
172
197
  }
173
198
 
174
199
  //
@@ -176,11 +201,12 @@ export class EdgeHttpClient {
176
201
  //
177
202
 
178
203
  public async joinSpaceByInvitation(
204
+ ctx: Context,
179
205
  spaceId: SpaceId,
180
206
  body: JoinSpaceRequest,
181
- args?: EdgeHttpGetArgs,
207
+ args?: EdgeHttpCallArgs,
182
208
  ): Promise<JoinSpaceResponseBody> {
183
- return this._call(new URL(`/spaces/${spaceId}/join`, this.baseUrl), { ...args, body, method: 'POST' });
209
+ return this._call(ctx, new URL(`/spaces/${spaceId}/join`, this.baseUrl), { ...args, body, method: 'POST' });
184
210
  }
185
211
 
186
212
  //
@@ -188,18 +214,19 @@ export class EdgeHttpClient {
188
214
  //
189
215
 
190
216
  public async initiateOAuthFlow(
217
+ ctx: Context,
191
218
  body: InitiateOAuthFlowRequest,
192
- args?: EdgeHttpGetArgs,
219
+ args?: EdgeHttpCallArgs,
193
220
  ): Promise<InitiateOAuthFlowResponse> {
194
- return this._call(new URL('/oauth/initiate', this.baseUrl), { ...args, body, method: 'POST' });
221
+ return this._call(ctx, new URL('/oauth/initiate', this.baseUrl), { ...args, body, method: 'POST' });
195
222
  }
196
223
 
197
224
  //
198
225
  // Spaces
199
226
  //
200
227
 
201
- async createSpace(body: CreateSpaceRequest, args?: EdgeHttpGetArgs): Promise<CreateSpaceResponseBody> {
202
- return this._call(new URL('/spaces/create', this.baseUrl), { ...args, body, method: 'POST' });
228
+ async createSpace(ctx: Context, body: CreateSpaceRequest, args?: EdgeHttpCallArgs): Promise<CreateSpaceResponseBody> {
229
+ return this._call(ctx, new URL('/spaces/create', this.baseUrl), { ...args, body, method: 'POST' });
203
230
  }
204
231
 
205
232
  //
@@ -207,14 +234,16 @@ export class EdgeHttpClient {
207
234
  //
208
235
 
209
236
  public async queryQueue(
237
+ ctx: Context,
210
238
  subspaceTag: string,
211
239
  spaceId: SpaceId,
212
- query: QueueQuery,
213
- args?: EdgeHttpGetArgs,
214
- ): Promise<QueryResult> {
240
+ query: FeedProtocol.QueueQuery,
241
+ args?: EdgeHttpCallArgs,
242
+ ): Promise<FeedProtocol.QueryResult> {
215
243
  const queueId = query.queueIds?.[0];
216
244
  invariant(queueId, 'queueId required');
217
245
  return this._call(
246
+ ctx,
218
247
  createUrl(new URL(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}/query`, this.baseUrl), {
219
248
  after: query.after,
220
249
  before: query.before,
@@ -230,13 +259,14 @@ export class EdgeHttpClient {
230
259
  }
231
260
 
232
261
  public async insertIntoQueue(
262
+ ctx: Context,
233
263
  subspaceTag: string,
234
264
  spaceId: SpaceId,
235
265
  queueId: ObjectId,
236
266
  objects: unknown[],
237
- args?: EdgeHttpGetArgs,
267
+ args?: EdgeHttpCallArgs,
238
268
  ): Promise<void> {
239
- return this._call(new URL(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}`, this.baseUrl), {
269
+ return this._call(ctx, new URL(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}`, this.baseUrl), {
240
270
  ...args,
241
271
  body: { objects },
242
272
  method: 'POST',
@@ -244,13 +274,15 @@ export class EdgeHttpClient {
244
274
  }
245
275
 
246
276
  public async deleteFromQueue(
277
+ ctx: Context,
247
278
  subspaceTag: string,
248
279
  spaceId: SpaceId,
249
280
  queueId: ObjectId,
250
281
  objectIds: ObjectId[],
251
- args?: EdgeHttpGetArgs,
282
+ args?: EdgeHttpCallArgs,
252
283
  ): Promise<void> {
253
284
  return this._call(
285
+ ctx,
254
286
  createUrl(new URL(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}`, this.baseUrl), {
255
287
  ids: objectIds.join(','),
256
288
  }),
@@ -266,9 +298,10 @@ export class EdgeHttpClient {
266
298
  //
267
299
 
268
300
  public async uploadFunction(
301
+ ctx: Context,
269
302
  pathParts: { functionId?: string },
270
303
  body: UploadFunctionRequest,
271
- args?: EdgeHttpGetArgs,
304
+ args?: EdgeHttpCallArgs,
272
305
  ): Promise<UploadFunctionResponseBody> {
273
306
  const formData = new FormData();
274
307
  formData.append('name', body.name ?? '');
@@ -285,7 +318,7 @@ export class EdgeHttpClient {
285
318
  }
286
319
 
287
320
  const path = ['functions', ...(pathParts.functionId ? [pathParts.functionId] : [])].join('/');
288
- return this._call(new URL(path, this.baseUrl), {
321
+ return this._call(ctx, new URL(path, this.baseUrl), {
289
322
  ...args,
290
323
  body: formData,
291
324
  method: 'PUT',
@@ -293,11 +326,12 @@ export class EdgeHttpClient {
293
326
  });
294
327
  }
295
328
 
296
- public async listFunctions(args?: EdgeHttpGetArgs): Promise<any> {
297
- return this._call(new URL('/functions', this.baseUrl), { ...args, method: 'GET' });
329
+ public async listFunctions(ctx: Context, args?: EdgeHttpCallArgs): Promise<any> {
330
+ return this._call(ctx, new URL('/functions', this.baseUrl), { ...args, method: 'GET' });
298
331
  }
299
332
 
300
333
  public async invokeFunction(
334
+ ctx: Context,
301
335
  params: {
302
336
  functionId: string;
303
337
  version?: string;
@@ -306,7 +340,7 @@ export class EdgeHttpClient {
306
340
  subrequestsLimit?: number;
307
341
  },
308
342
  input: unknown,
309
- args?: EdgeHttpGetArgs,
343
+ args?: EdgeHttpCallArgs,
310
344
  ): Promise<any> {
311
345
  const url = new URL(`/functions/${params.functionId}`, this.baseUrl);
312
346
  if (params.version) {
@@ -322,7 +356,7 @@ export class EdgeHttpClient {
322
356
  url.searchParams.set('subrequestsLimit', params.subrequestsLimit.toString());
323
357
  }
324
358
 
325
- return this._call(url, {
359
+ return this._call(ctx, url, {
326
360
  ...args,
327
361
  body: input,
328
362
  method: 'POST',
@@ -334,12 +368,13 @@ export class EdgeHttpClient {
334
368
  //
335
369
 
336
370
  public async executeWorkflow(
371
+ ctx: Context,
337
372
  spaceId: SpaceId,
338
373
  graphId: ObjectId,
339
374
  input: any,
340
- args?: EdgeHttpGetArgs,
375
+ args?: EdgeHttpCallArgs,
341
376
  ): Promise<ExecuteWorkflowResponseBody> {
342
- return this._call(new URL(`/workflows/${spaceId}/${graphId}`, this.baseUrl), {
377
+ return this._call(ctx, new URL(`/workflows/${spaceId}/${graphId}`, this.baseUrl), {
343
378
  ...args,
344
379
  body: input,
345
380
  method: 'POST',
@@ -350,36 +385,54 @@ export class EdgeHttpClient {
350
385
  // Triggers
351
386
  //
352
387
 
353
- public async getCronTriggers(spaceId: SpaceId): Promise<GetCronTriggersResponse> {
354
- return this._call<GetCronTriggersResponse>(new URL(`/test/functions/${spaceId}/triggers/crons`, this.baseUrl), {
388
+ public async getCronTriggers(ctx: Context, spaceId: SpaceId): Promise<GetCronTriggersResponse> {
389
+ return this._call<GetCronTriggersResponse>(ctx, new URL(`/functions/${spaceId}/triggers/crons`, this.baseUrl), {
355
390
  method: 'GET',
356
391
  });
357
392
  }
358
393
 
359
- public async forceRunCronTrigger(spaceId: SpaceId, triggerId: ObjectId) {
360
- return this._call(new URL(`/test/functions/${spaceId}/triggers/crons/${triggerId}/run`, this.baseUrl), {
394
+ public async forceRunCronTrigger(ctx: Context, spaceId: SpaceId, triggerId: ObjectId) {
395
+ return this._call(ctx, new URL(`/functions/${spaceId}/triggers/crons/${triggerId}/run`, this.baseUrl), {
361
396
  method: 'POST',
362
397
  });
363
398
  }
364
399
 
400
+ //
401
+ // Query
402
+ //
403
+
404
+ /**
405
+ * Execute a QueryAST query against a space.
406
+ */
407
+ public async execQuery(
408
+ ctx: Context,
409
+ spaceId: SpaceId,
410
+ body: QueryRequestProto,
411
+ args?: EdgeHttpCallArgs,
412
+ ): Promise<QueryResponseProto> {
413
+ return this._call(ctx, new URL(`/spaces/${spaceId}/exec-query`, this.baseUrl), { ...args, body, method: 'POST' });
414
+ }
415
+
365
416
  //
366
417
  // Import/Export space.
367
418
  //
368
419
 
369
420
  public async importBundle(
370
- spaceId: SpaceId, //
421
+ ctx: Context,
422
+ spaceId: SpaceId,
371
423
  body: ImportBundleRequest,
372
- args?: EdgeHttpGetArgs,
424
+ args?: EdgeHttpCallArgs,
373
425
  ): Promise<void> {
374
- return this._call(new URL(`/spaces/${spaceId}/import`, this.baseUrl), { ...args, body, method: 'PUT' });
426
+ return this._call(ctx, new URL(`/spaces/${spaceId}/import`, this.baseUrl), { ...args, body, method: 'PUT' });
375
427
  }
376
428
 
377
429
  public async exportBundle(
430
+ ctx: Context,
378
431
  spaceId: SpaceId,
379
432
  body: ExportBundleRequest,
380
- args?: EdgeHttpGetArgs,
433
+ args?: EdgeHttpCallArgs,
381
434
  ): Promise<ExportBundleResponse> {
382
- return this._call(new URL(`/spaces/${spaceId}/export`, this.baseUrl), {
435
+ return this._call(ctx, new URL(`/spaces/${spaceId}/export`, this.baseUrl), {
383
436
  ...args,
384
437
  body,
385
438
  method: 'POST',
@@ -403,11 +456,12 @@ export class EdgeHttpClient {
403
456
  }
404
457
 
405
458
  // TODO(burdon): Refactor with effect (see edge-http-client.test.ts).
406
- private async _call<T>(url: URL, args: EdgeHttpRequestArgs): Promise<T> {
459
+ private async _call<T>(ctx: Context, url: URL, args: EdgeHttpRequestArgs): Promise<T> {
407
460
  const shouldRetry = createRetryHandler(args);
408
- const requestContext = args.context ?? Context.default();
409
461
  log('fetch', { url, request: args.body });
410
462
 
463
+ const traceHeaders = getTraceHeaders(ctx);
464
+
411
465
  let handledAuth = false;
412
466
  const tryCount = 1;
413
467
  while (true) {
@@ -420,7 +474,7 @@ export class EdgeHttpClient {
420
474
  }
421
475
  }
422
476
 
423
- const request = createRequest(args, this._authHeader);
477
+ const request = createRequest(args, this._authHeader, traceHeaders, this._clientTag);
424
478
  log('call edge', { url, tryCount, authHeader: !!this._authHeader });
425
479
  const response = await fetch(url, request);
426
480
 
@@ -456,7 +510,7 @@ export class EdgeHttpClient {
456
510
  processingError = EdgeCallFailedError.fromProcessingFailureCause(error);
457
511
  }
458
512
 
459
- if (processingError?.isRetryable && (await shouldRetry(requestContext, processingError.retryAfterMs))) {
513
+ if (processingError?.isRetryable && (await shouldRetry(ctx, processingError.retryAfterMs))) {
460
514
  log.verbose('retrying edge request', { url, processingError });
461
515
  } else {
462
516
  throw processingError!;
@@ -478,6 +532,8 @@ export class EdgeHttpClient {
478
532
  const createRequest = (
479
533
  { method, body, json = true }: EdgeHttpRequestArgs,
480
534
  authHeader: string | undefined,
535
+ traceHeaders?: Record<string, string>,
536
+ clientTag?: string,
481
537
  ): RequestInit => {
482
538
  let requestBody: BodyInit | undefined;
483
539
  const headers: HeadersInit = {};
@@ -497,6 +553,14 @@ const createRequest = (
497
553
  headers['Authorization'] = authHeader;
498
554
  }
499
555
 
556
+ if (traceHeaders) {
557
+ Object.assign(headers, traceHeaders);
558
+ }
559
+
560
+ if (clientTag) {
561
+ headers[EDGE_CLIENT_TAG_HEADER] = clientTag;
562
+ }
563
+
500
564
  return {
501
565
  method,
502
566
  body: requestBody,
@@ -504,6 +568,25 @@ const createRequest = (
504
568
  };
505
569
  };
506
570
 
571
+ /**
572
+ * Extract W3C Trace Context headers (traceparent/tracestate) from a DXOS Context.
573
+ */
574
+ const getTraceHeaders = (ctx: Context): Record<string, string> | undefined => {
575
+ const spanId = ctx.getAttribute(TRACE_SPAN_ATTRIBUTE);
576
+ const otlpContext =
577
+ typeof spanId === 'number'
578
+ ? (TRACE_PROCESSOR.remoteTracing.getSpanContext(spanId) as OtelContext | undefined)
579
+ : undefined;
580
+
581
+ if (!otlpContext) {
582
+ return undefined;
583
+ }
584
+
585
+ const headers: Record<string, string> = {};
586
+ propagation.inject(otlpContext, headers);
587
+ return Object.keys(headers).length > 0 ? headers : undefined;
588
+ };
589
+
507
590
  /**
508
591
  * @deprecated
509
592
  */
@@ -50,7 +50,7 @@ export class EdgeWsConnection extends Resource {
50
50
 
51
51
  constructor(
52
52
  private readonly _identity: EdgeIdentity,
53
- private readonly _connectionInfo: { url: URL; protocolHeader?: string },
53
+ private readonly _connectionInfo: { url: URL; protocolHeader?: string; headers?: Record<string, string> },
54
54
  private readonly _callbacks: EdgeWsConnectionCallbacks,
55
55
  ) {
56
56
  super();
@@ -121,6 +121,7 @@ export class EdgeWsConnection extends Resource {
121
121
  this._connectionInfo.protocolHeader
122
122
  ? [...baseProtocols, this._connectionInfo.protocolHeader]
123
123
  : [...baseProtocols],
124
+ this._connectionInfo.headers ? { headers: this._connectionInfo.headers } : undefined,
124
125
  );
125
126
  const muxer = new WebSocketMuxer(this._ws);
126
127
  this._wsMuxer = muxer;