@q9labsai/chalk-client 5.3.0 → 5.4.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 (36) hide show
  1. package/dist/access/grant.d.ts +2 -0
  2. package/dist/{chunk-GOSWSXTH.js → chunk-MHJ4UPM3.js} +162 -5
  3. package/dist/chunk-N4IPKRS6.js +76 -0
  4. package/dist/{chunk-DHUHTIU7.js → chunk-TA2BJXI7.js} +243 -45
  5. package/dist/{chunk-3TGVTP6Z.js → chunk-UVWRTXNO.js} +894 -72
  6. package/dist/{chunk-O26BHHMI.js → chunk-VAJ6XNAA.js} +1 -1
  7. package/dist/{chunk-XSB2GDRW.js → chunk-XF567GPH.js} +198 -26
  8. package/dist/client.d.ts +180 -0
  9. package/dist/connection/dependencies.d.ts +5 -0
  10. package/dist/connection/production.d.ts +1 -1
  11. package/dist/effect.js +29 -4
  12. package/dist/generated/http-api.d.ts +178 -0
  13. package/dist/generated/schemas.d.ts +287 -0
  14. package/dist/generated/sync.d.ts +53 -1
  15. package/dist/index.d.ts +1 -0
  16. package/dist/index.js +33 -15
  17. package/dist/media/call-stats.d.ts +27 -0
  18. package/dist/media/client.d.ts +1 -0
  19. package/dist/media/ice-servers.d.ts +3 -0
  20. package/dist/media/index.d.ts +2 -0
  21. package/dist/media/index.js +4 -1
  22. package/dist/media/plane.d.ts +1 -0
  23. package/dist/media/receive-stall.d.ts +11 -2
  24. package/dist/media/types.d.ts +19 -0
  25. package/dist/media/video-render-size.d.ts +7 -0
  26. package/dist/media/viewer-layer.d.ts +48 -0
  27. package/dist/public-invites/index.js +3 -2
  28. package/dist/server/index.cjs +18 -4
  29. package/dist/server/index.js +18 -4
  30. package/dist/session/index.d.ts +18 -0
  31. package/dist/sync/index.js +2 -1
  32. package/dist/sync/link-watch.d.ts +67 -0
  33. package/dist/sync/v1-client.d.ts +5 -0
  34. package/dist/sync/v1-command-scheduler.d.ts +4 -0
  35. package/dist/sync/v1-types.d.ts +12 -1
  36. package/package.json +2 -1
@@ -1,3 +1,4 @@
1
+ import type { CloudflareSFUIceServer } from "../media/types";
1
2
  declare const syncCredentialBrand: unique symbol;
2
3
  declare const mediaCredentialBrand: unique symbol;
3
4
  declare const accessGrantBrand: unique symbol;
@@ -25,6 +26,7 @@ export type ParticipantMediaAccess = {
25
26
  readonly clientPayload: {
26
27
  readonly connectionId: string;
27
28
  readonly stunServer: string;
29
+ readonly iceServers?: readonly CloudflareSFUIceServer[];
28
30
  };
29
31
  };
30
32
  export type ParsedAccessGrant = {
@@ -1,3 +1,7 @@
1
+ import {
2
+ withRequestContext
3
+ } from "./chunk-N4IPKRS6.js";
4
+
1
5
  // src/generated/schemas.ts
2
6
  import { Schema, SchemaGetter } from "effect";
3
7
  var ChalkCodePointLimits = {
@@ -92,6 +96,30 @@ var AdmitEpisodeParticipantRequestSchema = Schema.Struct({
92
96
  role: Schema.String.check(Schema.isMinLength(1))
93
97
  });
94
98
  var AuditLogIdSchema = Schema.String.check(Schema.isMinLength(36), Schema.isMaxLength(36), Schema.isPattern(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i)).pipe(Schema.brand("AuditLogId"));
99
+ var CallStatsRequestSchema = Schema.Struct({
100
+ samples: Schema.Array(
101
+ Schema.Struct({
102
+ connection_type: Schema.Literals(["udp", "tcp", "turn", "unknown"]),
103
+ elapsed_ms: Schema.Number,
104
+ freeze_count: Schema.optional(Schema.NullOr(Schema.Number)),
105
+ freeze_ms: Schema.optional(Schema.NullOr(Schema.Number)),
106
+ local_candidate_type: Schema.optional(Schema.Literals(["host", "srflx", "prflx", "relay"])),
107
+ recv_bitrate_kbps: Schema.optional(Schema.NullOr(Schema.Number)),
108
+ recv_height: Schema.optional(Schema.NullOr(Schema.Number)),
109
+ recv_jitter_ms: Schema.optional(Schema.NullOr(Schema.Number)),
110
+ recv_loss_pct: Schema.optional(Schema.NullOr(Schema.Number)),
111
+ relay_protocol: Schema.optional(Schema.Literals(["udp", "tcp", "tls"])),
112
+ remote_candidate_type: Schema.optional(Schema.Literals(["host", "srflx", "prflx", "relay"])),
113
+ rtt_ms: Schema.optional(Schema.NullOr(Schema.Number)),
114
+ send_bitrate_kbps: Schema.optional(Schema.NullOr(Schema.Number)),
115
+ send_jitter_ms: Schema.optional(Schema.NullOr(Schema.Number)),
116
+ send_layer: Schema.optional(Schema.Literals(["h", "m", "l"])),
117
+ send_loss_pct: Schema.optional(Schema.NullOr(Schema.Number)),
118
+ window_ms: Schema.Number
119
+ })
120
+ ).check(Schema.isMinLength(1), Schema.isMaxLength(30)),
121
+ version: Schema.Literal(1)
122
+ });
95
123
  var CancelRecordingPreparationRequestSchema = Schema.Struct({
96
124
  expected_revision: Schema.Number
97
125
  });
@@ -136,6 +164,7 @@ var CloudflareSFUCloseTracksAPIResponseSchema = Schema.Struct({
136
164
  var CloudflareSFUCloseTracksRequestSchema = Schema.Struct({
137
165
  connection_id: Schema.String.check(Schema.isMinLength(1)),
138
166
  force: Schema.Boolean,
167
+ receive_only: Schema.optional(Schema.Boolean),
139
168
  session_description: Schema.optional(
140
169
  Schema.NullOr(
141
170
  Schema.Struct({
@@ -173,7 +202,7 @@ var CloudflareSFURenegotiateRequestSchema = Schema.Struct({
173
202
  var CloudflareSFURenegotiateResponseSchema = Schema.Struct({
174
203
  accepted: Schema.Boolean
175
204
  });
176
- var CloudflareSFUTracksAPIResponseSchema = Schema.Struct({
205
+ var CloudflareSFUUpdateTracksAPIResponseSchema = Schema.Struct({
177
206
  requiresImmediateRenegotiation: Schema.optional(Schema.Boolean),
178
207
  sessionDescription: Schema.optional(
179
208
  Schema.NullOr(
@@ -214,6 +243,7 @@ var CloudflareSFUTracksAPIResponseSchema = Schema.Struct({
214
243
  )
215
244
  )
216
245
  });
246
+ var CloudflareSFUTracksAPIResponseSchema = CloudflareSFUUpdateTracksAPIResponseSchema;
217
247
  var CloudflareSFUTracksRequestSchema = Schema.Struct({
218
248
  connection_id: Schema.String.check(Schema.isMinLength(1)),
219
249
  session_description: Schema.optional(
@@ -244,6 +274,28 @@ var CloudflareSFUTracksRequestSchema = Schema.Struct({
244
274
  })
245
275
  )
246
276
  });
277
+ var CloudflareSFUUpdateTracksRequestSchema = Schema.Struct({
278
+ connection_id: Schema.String.check(Schema.isMinLength(1)),
279
+ tracks: Schema.Array(
280
+ Schema.Struct({
281
+ location: Schema.String.check(Schema.isMinLength(1)),
282
+ mid: Schema.optional(Schema.String.check(Schema.isMinLength(1))),
283
+ publication_id: Schema.optional(Schema.String.check(Schema.isMinLength(1))),
284
+ sessionId: Schema.optional(Schema.String.check(Schema.isMinLength(1))),
285
+ simulcast: Schema.optional(
286
+ Schema.NullOr(
287
+ Schema.Struct({
288
+ preferredRid: Schema.String.check(Schema.isMinLength(1)),
289
+ priorityOrdering: Schema.String.check(Schema.isMinLength(1)),
290
+ ridNotAvailable: Schema.String.check(Schema.isMinLength(1))
291
+ })
292
+ )
293
+ ),
294
+ source: Schema.optional(Schema.String.check(Schema.isMinLength(1))),
295
+ trackName: Schema.String.check(Schema.isMinLength(1))
296
+ })
297
+ )
298
+ });
247
299
  var ConnectionReportRequestSchema = Schema.Struct({
248
300
  events: Schema.Array(
249
301
  Schema.Struct({
@@ -1925,6 +1977,19 @@ var TestWebhookEndpoint429ResponseHeadersSchema = Schema.Struct({
1925
1977
  "X-RateLimit-Limit": RateLimitLimitHeaderSchema,
1926
1978
  "X-RateLimit-Remaining": RateLimitRemainingHeaderSchema
1927
1979
  });
1980
+ var UpdateCloudflareSFUTracksPathParamsSchema = Schema.Struct({
1981
+ episode_id: EpisodeIdSchema,
1982
+ participant_id: ParticipantIdSchema,
1983
+ space_id: SpaceIdSchema,
1984
+ tenant_id: TenantIdSchema
1985
+ });
1986
+ var UpdateCloudflareSFUTracksRequestBodySchema = CloudflareSFUUpdateTracksRequestSchema;
1987
+ var UpdateCloudflareSFUTracksResponseSchema = CloudflareSFUUpdateTracksAPIResponseSchema;
1988
+ var UpdateCloudflareSFUTracks429ResponseHeadersSchema = Schema.Struct({
1989
+ "Retry-After": RetryAfterHeaderSchema,
1990
+ "X-RateLimit-Limit": RateLimitLimitHeaderSchema,
1991
+ "X-RateLimit-Remaining": RateLimitRemainingHeaderSchema
1992
+ });
1928
1993
  var UpdateMembershipPathParamsSchema = Schema.Struct({
1929
1994
  membership_id: MembershipIdSchema,
1930
1995
  tenant_id: TenantIdSchema
@@ -1983,6 +2048,15 @@ var UpdateWebhookEndpoint429ResponseHeadersSchema = Schema.Struct({
1983
2048
  "X-RateLimit-Limit": RateLimitLimitHeaderSchema,
1984
2049
  "X-RateLimit-Remaining": RateLimitRemainingHeaderSchema
1985
2050
  });
2051
+ var UploadCallStatsPathParamsSchema = Schema.Struct({
2052
+ tenant_id: TenantIdSchema
2053
+ });
2054
+ var UploadCallStatsRequestBodySchema = CallStatsRequestSchema;
2055
+ var UploadCallStats429ResponseHeadersSchema = Schema.Struct({
2056
+ "Retry-After": RetryAfterHeaderSchema,
2057
+ "X-RateLimit-Limit": RateLimitLimitHeaderSchema,
2058
+ "X-RateLimit-Remaining": RateLimitRemainingHeaderSchema
2059
+ });
1986
2060
  var AccessForbiddenError = class extends Schema.TaggedErrorClass()("AccessForbiddenError", {
1987
2061
  error: Schema.Struct({
1988
2062
  code: Schema.Literal("access.forbidden"),
@@ -5110,6 +5184,22 @@ var TestWebhookEndpointErrorSchema = Schema.Union([
5110
5184
  WebhookInvalidUrlErrorSchema,
5111
5185
  WebhookUnsafeUrlErrorSchema
5112
5186
  ]);
5187
+ var UpdateCloudflareSFUTracksErrorSchema = Schema.Union([
5188
+ AccessForbiddenErrorSchema,
5189
+ AccessUnauthenticatedErrorSchema,
5190
+ EpisodeInvalidIdErrorSchema,
5191
+ EpisodeNotFoundErrorSchema,
5192
+ MediaConnectionNotFoundErrorSchema,
5193
+ MediaUnavailableErrorSchema,
5194
+ ParticipantInvalidIdErrorSchema,
5195
+ RequestInvalidErrorSchema,
5196
+ RequestPayloadTooLargeErrorSchema,
5197
+ RequestRateLimitedErrorSchema,
5198
+ ServiceInternalErrorSchema,
5199
+ ServiceUnavailableErrorSchema,
5200
+ SpaceInvalidIdErrorSchema,
5201
+ TenantInvalidIdErrorSchema
5202
+ ]);
5113
5203
  var UpdateMembershipErrorSchema = Schema.Union([
5114
5204
  AccessForbiddenErrorSchema,
5115
5205
  AccessUnauthenticatedErrorSchema,
@@ -5198,6 +5288,7 @@ var UpdateWebhookEndpointErrorSchema = Schema.Union([
5198
5288
  WebhookInvalidUrlErrorSchema,
5199
5289
  WebhookUnsafeUrlErrorSchema
5200
5290
  ]);
5291
+ var UploadCallStatsErrorSchema = Schema.Union([AccessForbiddenErrorSchema, AccessUnauthenticatedErrorSchema, RequestInvalidErrorSchema, RequestPayloadTooLargeErrorSchema, RequestRateLimitedErrorSchema, ServiceInternalErrorSchema, ServiceUnavailableErrorSchema, TenantInvalidIdErrorSchema]);
5201
5292
  var ChalkOperationPolicies = {
5202
5293
  addCloudflareSFUTracks: { maxBodyBytes: 1048576, rateLimit: { limit: 60, policy: "v1.authenticated.write", windowSeconds: 60 } },
5203
5294
  admitEpisodeParticipant: { maxBodyBytes: 1048576, rateLimit: { limit: 60, policy: "v1.authenticated.write", windowSeconds: 60 } },
@@ -5259,11 +5350,13 @@ var ChalkOperationPolicies = {
5259
5350
  sendProblemReport: { maxBodyBytes: 37024, rateLimit: { limit: 3, policy: "problem_reports.participant", windowSeconds: 3600 } },
5260
5351
  setEpisodeDeadline: { maxBodyBytes: 1048576, rateLimit: { limit: 60, policy: "v1.authenticated.write", windowSeconds: 60 } },
5261
5352
  testWebhookEndpoint: { rateLimit: { limit: 60, policy: "v1.authenticated.write", windowSeconds: 60 } },
5353
+ updateCloudflareSFUTracks: { maxBodyBytes: 1048576, rateLimit: { limit: 60, policy: "v1.authenticated.write", windowSeconds: 60 } },
5262
5354
  updateMembership: { maxBodyBytes: 1048576, rateLimit: { limit: 60, policy: "v1.authenticated.write", windowSeconds: 60 } },
5263
5355
  updateSpace: { maxBodyBytes: 1048576, rateLimit: { limit: 60, policy: "v1.authenticated.write", windowSeconds: 60 } },
5264
5356
  updateSpacePublicInvite: { maxBodyBytes: 1048576, rateLimit: { limit: 60, policy: "v1.authenticated.write", windowSeconds: 60 } },
5265
5357
  updateTenant: { maxBodyBytes: 1048576, rateLimit: { limit: 60, policy: "v1.authenticated.write", windowSeconds: 60 } },
5266
- updateWebhookEndpoint: { maxBodyBytes: 1048576, rateLimit: { limit: 60, policy: "v1.authenticated.write", windowSeconds: 60 } }
5358
+ updateWebhookEndpoint: { maxBodyBytes: 1048576, rateLimit: { limit: 60, policy: "v1.authenticated.write", windowSeconds: 60 } },
5359
+ uploadCallStats: { maxBodyBytes: 32768, rateLimit: { limit: 30, policy: "call_stats.participant", windowSeconds: 600 } }
5267
5360
  };
5268
5361
 
5269
5362
  // src/generated/http-api.ts
@@ -5832,6 +5925,28 @@ var defaultGroup = HttpApiGroup.make("default").add(
5832
5925
  ServiceUnavailableErrorSchema.pipe(HttpApiSchema.status(503))
5833
5926
  ]
5834
5927
  })
5928
+ ).add(
5929
+ HttpApiEndpoint.put("updateCloudflareSFUTracks", "/v1/tenants/:tenant_id/spaces/:space_id/episodes/:episode_id/participants/:participant_id/media/sfu/tracks/update", {
5930
+ params: UpdateCloudflareSFUTracksPathParamsSchema,
5931
+ payload: UpdateCloudflareSFUTracksRequestBodySchema,
5932
+ success: UpdateCloudflareSFUTracksResponseSchema.pipe(HttpApiSchema.status(200)),
5933
+ error: [
5934
+ EpisodeInvalidIdErrorSchema.pipe(HttpApiSchema.status(400)),
5935
+ ParticipantInvalidIdErrorSchema.pipe(HttpApiSchema.status(400)),
5936
+ RequestInvalidErrorSchema.pipe(HttpApiSchema.status(400)),
5937
+ SpaceInvalidIdErrorSchema.pipe(HttpApiSchema.status(400)),
5938
+ TenantInvalidIdErrorSchema.pipe(HttpApiSchema.status(400)),
5939
+ AccessUnauthenticatedErrorSchema.pipe(HttpApiSchema.status(401)),
5940
+ AccessForbiddenErrorSchema.pipe(HttpApiSchema.status(403)),
5941
+ EpisodeNotFoundErrorSchema.pipe(HttpApiSchema.status(404)),
5942
+ MediaConnectionNotFoundErrorSchema.pipe(HttpApiSchema.status(404)),
5943
+ RequestPayloadTooLargeErrorSchema.pipe(HttpApiSchema.status(413)),
5944
+ RequestRateLimitedErrorSchema.pipe(HttpApiSchema.status(429)),
5945
+ ServiceInternalErrorSchema.pipe(HttpApiSchema.status(500)),
5946
+ MediaUnavailableErrorSchema.pipe(HttpApiSchema.status(503)),
5947
+ ServiceUnavailableErrorSchema.pipe(HttpApiSchema.status(503))
5948
+ ]
5949
+ })
5835
5950
  ).add(
5836
5951
  HttpApiEndpoint.patch("updateWebhookEndpoint", "/v1/tenants/:tenant_id/webhook-endpoints/:endpoint_id", {
5837
5952
  params: UpdateWebhookEndpointPathParamsSchema,
@@ -5867,6 +5982,22 @@ var defaultGroup = HttpApiGroup.make("default").add(
5867
5982
  ServiceUnavailableErrorSchema.pipe(HttpApiSchema.status(503))
5868
5983
  ]
5869
5984
  })
5985
+ ).add(
5986
+ HttpApiEndpoint.post("uploadCallStats", "/v1/tenants/:tenant_id/call-stats", {
5987
+ params: UploadCallStatsPathParamsSchema,
5988
+ payload: UploadCallStatsRequestBodySchema,
5989
+ success: HttpApiSchema.Empty(204).pipe(HttpApiSchema.status(204)),
5990
+ error: [
5991
+ RequestInvalidErrorSchema.pipe(HttpApiSchema.status(400)),
5992
+ TenantInvalidIdErrorSchema.pipe(HttpApiSchema.status(400)),
5993
+ AccessUnauthenticatedErrorSchema.pipe(HttpApiSchema.status(401)),
5994
+ AccessForbiddenErrorSchema.pipe(HttpApiSchema.status(403)),
5995
+ RequestPayloadTooLargeErrorSchema.pipe(HttpApiSchema.status(413)),
5996
+ RequestRateLimitedErrorSchema.pipe(HttpApiSchema.status(429)),
5997
+ ServiceInternalErrorSchema.pipe(HttpApiSchema.status(500)),
5998
+ ServiceUnavailableErrorSchema.pipe(HttpApiSchema.status(503))
5999
+ ]
6000
+ })
5870
6001
  );
5871
6002
  var episodesGroup = HttpApiGroup.make("episodes").add(
5872
6003
  HttpApiEndpoint.post("admitEpisodeParticipant", "/v1/tenants/:tenant_id/spaces/:space_id/episodes/:episode_id/participants", {
@@ -6864,7 +6995,7 @@ var createChalkEffectClient = (options) => {
6864
6995
  })
6865
6996
  }).pipe(Effect.provide(FetchHttpClient.layer));
6866
6997
  const configuredClient = options.credentials === void 0 ? client : client.pipe(Effect.provideService(FetchHttpClient.RequestInit, { credentials: options.credentials }));
6867
- return options.fetch ? configuredClient.pipe(Effect.provideService(FetchHttpClient.Fetch, options.fetch)) : configuredClient;
6998
+ return configuredClient.pipe(Effect.provideService(FetchHttpClient.Fetch, withRequestContext(options.fetch)));
6868
6999
  };
6869
7000
  function requestHeaders(options) {
6870
7001
  return {
@@ -7015,17 +7146,31 @@ function parseMediaAccess(value) {
7015
7146
  provider: value.provider,
7016
7147
  clientPayload: {
7017
7148
  connectionId: requireNonEmptyString(payload.connectionId),
7018
- stunServer: requireNonEmptyString(payload.stunServer)
7149
+ stunServer: requireNonEmptyString(payload.stunServer),
7150
+ ...payload.iceServers === void 0 || payload.iceServers === null ? {} : { iceServers: parseIceServers(payload.iceServers) }
7019
7151
  }
7020
7152
  };
7021
7153
  default:
7022
7154
  throw new AccessGrantError();
7023
7155
  }
7024
7156
  }
7157
+ function parseIceServers(value) {
7158
+ if (!Array.isArray(value)) throw new AccessGrantError();
7159
+ return value.map((entry) => {
7160
+ if (!isRecord(entry) || !Array.isArray(entry.urls) || entry.urls.length === 0) throw new AccessGrantError();
7161
+ const urls = entry.urls.map(requireNonEmptyString);
7162
+ if (entry.username === void 0 && entry.credential === void 0) return { urls };
7163
+ return { urls, username: requireNonEmptyString(entry.username), credential: requireNonEmptyString(entry.credential) };
7164
+ });
7165
+ }
7025
7166
  function mediaClientPayload(value) {
7026
7167
  switch (value.provider) {
7027
7168
  case "cloudflare_sfu":
7028
- return { connectionId: value.clientPayload.connectionId, stunServer: value.clientPayload.stunServer };
7169
+ return {
7170
+ connectionId: value.clientPayload.connectionId,
7171
+ stunServer: value.clientPayload.stunServer,
7172
+ ...value.clientPayload.iceServers ? { iceServers: value.clientPayload.iceServers } : {}
7173
+ };
7029
7174
  }
7030
7175
  }
7031
7176
  function requireCredential(value, audience) {
@@ -7073,6 +7218,7 @@ export {
7073
7218
  AccessGrantSchema,
7074
7219
  AdmitEpisodeParticipantRequestSchema,
7075
7220
  AuditLogIdSchema,
7221
+ CallStatsRequestSchema,
7076
7222
  CancelRecordingPreparationRequestSchema,
7077
7223
  ChatAttachmentSchema,
7078
7224
  ChatAttachmentDownloadSchema,
@@ -7082,8 +7228,10 @@ export {
7082
7228
  CloudflareSFUPublicationsResponseSchema,
7083
7229
  CloudflareSFURenegotiateRequestSchema,
7084
7230
  CloudflareSFURenegotiateResponseSchema,
7231
+ CloudflareSFUUpdateTracksAPIResponseSchema,
7085
7232
  CloudflareSFUTracksAPIResponseSchema,
7086
7233
  CloudflareSFUTracksRequestSchema,
7234
+ CloudflareSFUUpdateTracksRequestSchema,
7087
7235
  ConnectionReportRequestSchema,
7088
7236
  CreateAPIKeyRequestSchema,
7089
7237
  CreateEpisodeRequestSchema,
@@ -7429,6 +7577,10 @@ export {
7429
7577
  TestWebhookEndpointRequestHeadersSchema,
7430
7578
  TestWebhookEndpointResponseSchema,
7431
7579
  TestWebhookEndpoint429ResponseHeadersSchema,
7580
+ UpdateCloudflareSFUTracksPathParamsSchema,
7581
+ UpdateCloudflareSFUTracksRequestBodySchema,
7582
+ UpdateCloudflareSFUTracksResponseSchema,
7583
+ UpdateCloudflareSFUTracks429ResponseHeadersSchema,
7432
7584
  UpdateMembershipPathParamsSchema,
7433
7585
  UpdateMembershipRequestBodySchema,
7434
7586
  UpdateMembershipResponseSchema,
@@ -7450,6 +7602,9 @@ export {
7450
7602
  UpdateWebhookEndpointRequestBodySchema,
7451
7603
  UpdateWebhookEndpointResponseSchema,
7452
7604
  UpdateWebhookEndpoint429ResponseHeadersSchema,
7605
+ UploadCallStatsPathParamsSchema,
7606
+ UploadCallStatsRequestBodySchema,
7607
+ UploadCallStats429ResponseHeadersSchema,
7453
7608
  AccessForbiddenError,
7454
7609
  AccessForbiddenErrorWireSchema,
7455
7610
  AccessForbiddenErrorSchema,
@@ -7872,11 +8027,13 @@ export {
7872
8027
  SendProblemReportErrorSchema,
7873
8028
  SetEpisodeDeadlineErrorSchema,
7874
8029
  TestWebhookEndpointErrorSchema,
8030
+ UpdateCloudflareSFUTracksErrorSchema,
7875
8031
  UpdateMembershipErrorSchema,
7876
8032
  UpdateSpaceErrorSchema,
7877
8033
  UpdateSpacePublicInviteErrorSchema,
7878
8034
  UpdateTenantErrorSchema,
7879
8035
  UpdateWebhookEndpointErrorSchema,
8036
+ UploadCallStatsErrorSchema,
7880
8037
  ChalkOperationPolicies,
7881
8038
  ChalkApi,
7882
8039
  createChalkEffectClient,
@@ -0,0 +1,76 @@
1
+ // src/session/index.ts
2
+ var SESSION_ID_KEY = "session.id";
3
+ var STORAGE_KEY = "chalk.session.id";
4
+ var TAB_KEY = "chalk.session.tab";
5
+ var TAB_NAME_PREFIX = "chalk.tab:";
6
+ var SESSION_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
7
+ var source = browserSession;
8
+ var browserId;
9
+ function setSessionSource(next) {
10
+ source = next;
11
+ }
12
+ function currentSessionId() {
13
+ return source();
14
+ }
15
+ function newSessionId() {
16
+ const random = globalThis.crypto;
17
+ if (typeof random?.randomUUID === "function") return random.randomUUID();
18
+ return "10000000-1000-4000-8000-100000000000".replace(/[018]/g, (digit) => (Number(digit) ^ random.getRandomValues(new Uint8Array(1))[0] & 15 >> Number(digit) / 4).toString(16));
19
+ }
20
+ function browserSession() {
21
+ if (browserId) return browserId;
22
+ if (typeof globalThis.document === "undefined") return void 0;
23
+ const tab = tabToken();
24
+ browserId = newSessionId();
25
+ try {
26
+ const storage = globalThis.sessionStorage;
27
+ browserId = storedSession(storage, tab) ?? browserId;
28
+ storage.setItem(STORAGE_KEY, browserId);
29
+ if (tab !== void 0) storage.setItem(TAB_KEY, tab);
30
+ } catch {
31
+ }
32
+ return browserId;
33
+ }
34
+ function storedSession(storage, tab) {
35
+ const stored = storage.getItem(STORAGE_KEY) ?? void 0;
36
+ if (!stored || !SESSION_ID.test(stored)) return void 0;
37
+ return tab === void 0 || storage.getItem(TAB_KEY) === tab ? stored : void 0;
38
+ }
39
+ function tabToken() {
40
+ const win = globalThis.window;
41
+ if (!win) return void 0;
42
+ if (win.name.startsWith(TAB_NAME_PREFIX)) return win.name;
43
+ if (win.name !== "") return void 0;
44
+ win.name = `${TAB_NAME_PREFIX}${newSessionId()}`;
45
+ return win.name;
46
+ }
47
+ function sessionBaggage() {
48
+ const sessionId = currentSessionId();
49
+ return sessionId ? `${SESSION_ID_KEY}=${sessionId}` : void 0;
50
+ }
51
+ function requestContextHeaders() {
52
+ const baggage = sessionBaggage();
53
+ if (!baggage) return {};
54
+ const trace = newSessionId().replaceAll("-", "");
55
+ return { baggage, traceparent: `00-${trace}-${trace.slice(16)}-01` };
56
+ }
57
+ function withRequestContext(fetchImplementation) {
58
+ return (input, init) => {
59
+ const send = fetchImplementation ?? globalThis.fetch;
60
+ const context = requestContextHeaders();
61
+ if (Object.keys(context).length === 0) return send(input, init);
62
+ const headers = new Headers(init?.headers ?? (input instanceof Request ? input.headers : void 0));
63
+ for (const [name, value] of Object.entries(context)) if (!headers.has(name)) headers.set(name, value);
64
+ return send(input, { ...init, headers });
65
+ };
66
+ }
67
+
68
+ export {
69
+ SESSION_ID_KEY,
70
+ setSessionSource,
71
+ currentSessionId,
72
+ newSessionId,
73
+ sessionBaggage,
74
+ requestContextHeaders,
75
+ withRequestContext
76
+ };