@collective-intelligence/external-apps-client-sdk 0.1.38 → 0.1.39

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.
package/README.md CHANGED
@@ -346,13 +346,44 @@ const unsubscribe = realtime.subscribe(
346
346
  `lastEventId`; `close()` ends the connection and the page listeners.
347
347
  - `createRealtimeClient` runs on the realtime service of `./effect`, in a
348
348
  runtime of its own. Its listeners and callbacks run in the same call as the
349
- page event, stream event or timer that causes them. `access-changed` calls
349
+ page event, stream event or timer that causes them; with `revalidateUrl`, a
350
+ delivery calls them when the answer of its post arrives, or in the timer of
351
+ its 1-second wait. `access-changed` calls
350
352
  `onAccessChanged` only, never `onReset`.
351
353
  - A failed ticket request logs a warning, and a failed connection step logs an
352
354
  error, through the Effect logger (the console by default). The connection
353
355
  goes on: the backoff or the ping timeout reconnects. The warning shows a
354
356
  relative `ticketUrl` on the placeholder origin `realtime-ticket.invalid`;
355
357
  `fetch` gets `ticketUrl` as you wrote it.
358
+ - With `revalidateUrl` (the Revalidate Route of the server SDK BFF, for
359
+ example `/api/realtime/revalidate`), each delivery first posts its changes
360
+ there as `{ token, changes: { topic, id }[] }`, the latest change of each
361
+ record, so that the server revalidates its Next.js cache tags. The delivery
362
+ then waits for the answer, 1 second at most, and only after it calls the
363
+ listeners and `onReset`: a listener that reads through the server cache
364
+ (for example `router.refresh()`) reads the revalidated entry. A failed post
365
+ does not hold the listeners, and a slow one holds them for 1 second only.
366
+ A change that arrives during the wait goes to the next delivery. A delivery
367
+ of more than 100 changes posts bodies of 100 changes, because the route
368
+ takes no more; up to 4 bodies post at once, so a slow body does not hold
369
+ the others, and the 1-second wait covers them all. A `reset` or
370
+ `access-changed` event adds `reset: true` to the first body. The token is the `grantToken` of
371
+ the last ticket: the client keeps it in the memory of the tab, and each
372
+ ticket renews it. The token expires 10 minutes after the ticket, and a
373
+ stream can stay open longer: so 8 minutes after each token, while the
374
+ stream stays open, the client asks `ticketUrl` for a new ticket of the
375
+ same topics and keeps only its token. The stream stays open, and that
376
+ ticket goes unused. A failed renewal logs a warning, keeps the old token
377
+ and tries again after 15 seconds, 30 seconds, then every 60 seconds, and
378
+ at least after the `Retry-After` of the refusal; after a renewal that
379
+ succeeds, the 8-minute cycle goes on. A retry that would come after the
380
+ token expires does not run: the renewals stop until the next ticket, and
381
+ a delivery after the expiry posts nothing and calls the listeners at
382
+ once, because the Revalidate Route refuses an expired token. Without a
383
+ token in the ticket answer (a ticket route
384
+ without `secrets`) the client posts nothing. The resync after a cursorless
385
+ open posts nothing. A failed post logs a warning; `fetch` gets
386
+ `revalidateUrl` as you wrote it.
356
387
 
357
388
  ### Realtime on Effect
358
389
 
@@ -395,6 +426,9 @@ Effect.runFork(
395
426
  visible. Provide `FetchHttpClient.Fetch` to use a different `fetch`.
396
427
  - `HttpClient` resolves a relative `ticketUrl` against `location`. Outside a
397
428
  browser, give an absolute `ticketUrl`.
429
+ - `layerRealtimeClient({ ticketUrl, revalidateUrl })` posts to the Revalidate
430
+ Route as `createRealtimeClient` does; a relative `revalidateUrl` also
431
+ resolves against `location`.
398
432
  - Timers use `Clock` and the jitter uses `Random`, so a test can use `TestClock`
399
433
  and a fixed `Random`.
400
434
 
package/dist/effect.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { $t as layerFederated, Gt as ClientFetch, Qt as FederatedAuthValue, Zt as FederatedAuth, _ as layerLegacyConfig, a as LegacyResources, an as CiError, c as ResourceEntityClient, cn as FederatedAuthError, d as ResourcesLayerOptions, en as layerFederatedConfig, f as ResourcesValue, g as layerLegacy, h as layerFromEntityTransport, i as LegacyResourceClient, l as Resources, ln as FederatedAuthErrorCode, m as layerConfig$3, nn as layerServerSessionConfig, o as LegacyResourcesLayerOptions, on as CiErrorCode, p as layer$3, s as LegacyResourcesValue, sn as CiTransportError, tn as layerServerSession, u as ResourcesFromEntityTransportOptions } from "./resources-CftkAwlJ.js";
2
- import { $ as RealtimeTopicFilter, B as layerProxyConfig, D as RunsValue, E as Runs, F as ExecuteResult, I as layerDirect, L as layerDirectConfig, N as CiClient, O as layer$4, P as CiClientValue, Q as RealtimeTopic, R as layerFromExecutor, T as RunFollowOptions, Z as RealtimeChange, f as DelegatedApplicationRuntimeOptions, j as CiStreamPage$1, p as DelegatedRuntimeState, w as DEFAULT_FOLLOW_RUN_DEADLINE_MS, z as layerProxy } from "./index-D_Ctkuhr.js";
1
+ import { $t as FederatedAuthValue, Kt as ClientFetch, Qt as FederatedAuth, _ as layerLegacy, a as LegacyResourceClient, c as LegacyResourcesValue, cn as CiTransportError, d as ResourcesFromEntityTransportOptions, en as layerFederated, f as ResourcesLayerOptions, g as layerFromEntityTransport, h as layerConfig$3, i as makeEntityHttpExecute, l as ResourceEntityClient, ln as FederatedAuthError, m as layer$3, nn as layerServerSession, o as LegacyResources, on as CiError, p as ResourcesValue, rn as layerServerSessionConfig, s as LegacyResourcesLayerOptions, sn as CiErrorCode, tn as layerFederatedConfig, u as Resources, un as FederatedAuthErrorCode, v as layerLegacyConfig } from "./resources-Bz9fYAWz.js";
2
+ import { $ as RealtimeTopicFilter, B as layerProxyConfig, D as RunsValue, E as Runs, F as ExecuteResult, I as layerDirect, L as layerDirectConfig, N as CiClient, O as layer$4, P as CiClientValue, Q as RealtimeTopic, R as layerFromExecutor, T as RunFollowOptions, Z as RealtimeChange, f as DelegatedApplicationRuntimeOptions, j as CiStreamPage$1, p as DelegatedRuntimeState, w as DEFAULT_FOLLOW_RUN_DEADLINE_MS, z as layerProxy } from "./index-DdmAyX_o.js";
3
3
  import * as Schema from "effect/Schema";
4
4
  import * as Config from "effect/Config";
5
5
  import * as Context from "effect/Context";
@@ -54,6 +54,16 @@ declare class RealtimeClient extends RealtimeClient_base {}
54
54
  type RealtimeClientLayerOptions = Readonly<{
55
55
  /** The application's ticket route, e.g. `/api/realtime/ticket`. */
56
56
  ticketUrl: string;
57
+ /**
58
+ * The application's Revalidate Route, e.g. `/api/realtime/revalidate`. With
59
+ * it, each delivery first posts its changes there, and a `reset` or
60
+ * `access-changed` event posts `reset: true`, with the grant token of the
61
+ * last ticket, so that the server revalidates its cache tags. The delivery
62
+ * reaches the listeners when the post has its answer, or 1 s after the post
63
+ * at the latest. Without a grant token in the ticket answer nothing is
64
+ * posted.
65
+ */
66
+ revalidateUrl?: string;
57
67
  }>;
58
68
  /** `RealtimeClient` with the `fetch` of `FetchHttpClient.Fetch` and the page of this runtime. */
59
69
  declare const layer$2: (options: RealtimeClientLayerOptions) => Layer.Layer<RealtimeClient, never, never>;
@@ -129,4 +139,4 @@ declare class DelegatedRuntime extends DelegatedRuntime_base {}
129
139
  declare const layer: (options: DelegatedApplicationRuntimeOptions) => Layer.Layer<FederatedAuth | CiClient | Runs | DelegatedRuntime, FederatedAuthError, never>;
130
140
  /** `layer` with options that Effect `Config` reads. */
131
141
  declare const layerConfig: (config: Config.Wrap<DelegatedApplicationRuntimeOptions>) => Layer.Layer<FederatedAuth | CiClient | Runs | DelegatedRuntime, FederatedAuthError | Config.ConfigError, never>;
132
- export { CiClient, type CiClientValue, CiError, CiErrorCode, CiErrorEnvelope, CiResult, CiStreamPage, CiTransportError, DEFAULT_FOLLOW_RUN_DEADLINE_MS, DelegatedRuntime, type DelegatedRuntimeValue, type ExecuteResult, FederatedAuth, FederatedAuthError, FederatedAuthErrorCode, type FederatedAuthValue, type FixedWorkflowRequest, FixedWorkflows, type FixedWorkflowsLayerOptions, type FixedWorkflowsValue, type LegacyResourceClient, LegacyResources, type LegacyResourcesLayerOptions, type LegacyResourcesValue, type RealtimeChange, RealtimeClient, type RealtimeClientLayerOptions, type RealtimeResync, type RealtimeTopic, type RealtimeTopicFilter, type RealtimeUpdate, type ResourceEntityClient, Resources, type ResourcesFromEntityTransportOptions, type ResourcesLayerOptions, type ResourcesValue, type RunFollowOptions, Runs, type RunsValue, layerDirect as layerCiClientDirect, layerDirectConfig as layerCiClientDirectConfig, layerFromExecutor as layerCiClientFromExecutor, layerProxy as layerCiClientProxy, layerProxyConfig as layerCiClientProxyConfig, layer as layerDelegatedRuntime, layerConfig as layerDelegatedRuntimeConfig, layerFederated as layerFederatedAuth, layerFederatedConfig as layerFederatedAuthConfig, layer$1 as layerFixedWorkflows, layerConfig$1 as layerFixedWorkflowsConfig, layerLegacy as layerLegacyResources, layerLegacyConfig as layerLegacyResourcesConfig, layer$2 as layerRealtimeClient, layerConfig$2 as layerRealtimeClientConfig, layer$3 as layerResources, layerConfig$3 as layerResourcesConfig, layerFromEntityTransport as layerResourcesFromEntityTransport, layer$4 as layerRuns, layerServerSession as layerServerSessionAuth, layerServerSessionConfig as layerServerSessionAuthConfig, subscribe };
142
+ export { CiClient, type CiClientValue, CiError, CiErrorCode, CiErrorEnvelope, CiResult, CiStreamPage, CiTransportError, DEFAULT_FOLLOW_RUN_DEADLINE_MS, DelegatedRuntime, type DelegatedRuntimeValue, type ExecuteResult, FederatedAuth, FederatedAuthError, FederatedAuthErrorCode, type FederatedAuthValue, type FixedWorkflowRequest, FixedWorkflows, type FixedWorkflowsLayerOptions, type FixedWorkflowsValue, type LegacyResourceClient, LegacyResources, type LegacyResourcesLayerOptions, type LegacyResourcesValue, type RealtimeChange, RealtimeClient, type RealtimeClientLayerOptions, type RealtimeResync, type RealtimeTopic, type RealtimeTopicFilter, type RealtimeUpdate, type ResourceEntityClient, Resources, type ResourcesFromEntityTransportOptions, type ResourcesLayerOptions, type ResourcesValue, type RunFollowOptions, Runs, type RunsValue, layerDirect as layerCiClientDirect, layerDirectConfig as layerCiClientDirectConfig, layerFromExecutor as layerCiClientFromExecutor, layerProxy as layerCiClientProxy, layerProxyConfig as layerCiClientProxyConfig, layer as layerDelegatedRuntime, layerConfig as layerDelegatedRuntimeConfig, layerFederated as layerFederatedAuth, layerFederatedConfig as layerFederatedAuthConfig, layer$1 as layerFixedWorkflows, layerConfig$1 as layerFixedWorkflowsConfig, layerLegacy as layerLegacyResources, layerLegacyConfig as layerLegacyResourcesConfig, layer$2 as layerRealtimeClient, layerConfig$2 as layerRealtimeClientConfig, layer$3 as layerResources, layerConfig$3 as layerResourcesConfig, layerFromEntityTransport as layerResourcesFromEntityTransport, layer$4 as layerRuns, layerServerSession as layerServerSessionAuth, layerServerSessionConfig as layerServerSessionAuthConfig, makeEntityHttpExecute, subscribe };
package/dist/effect.js CHANGED
@@ -1,5 +1,5 @@
1
- import { C as CiError, D as FederatedAuthErrorCode, E as FederatedAuthError, T as CiTransportError, a as layerConfig$3, c as layerLegacyConfig, i as layer$3, n as Resources, o as layerFromEntityTransport, s as layerLegacy, t as LegacyResources, w as CiErrorCode } from "./service-D-18nBUU.js";
2
- import { C as RealtimeClient, D as subscribe, T as layerConfig$2, _ as layerDirect, a as layer$1, b as layerProxy, c as layerFederated, d as layerServerSessionConfig, f as DEFAULT_FOLLOW_RUN_DEADLINE_MS, g as CiClient, h as layer$4, i as FixedWorkflows, l as layerFederatedConfig, n as layer, o as layerConfig$1, p as Runs, r as layerConfig, s as FederatedAuth, t as DelegatedRuntime, u as layerServerSession, v as layerDirectConfig, w as layer$2, x as layerProxyConfig, y as layerFromExecutor } from "./service-DD58W3in.js";
1
+ import { D as FederatedAuthError, E as CiTransportError, O as FederatedAuthErrorCode, T as CiErrorCode, a as layerConfig$3, c as layerLegacyConfig, f as makeEntityHttpExecute, i as layer$3, n as Resources, o as layerFromEntityTransport, s as layerLegacy, t as LegacyResources, w as CiError } from "./service-BGqbpJD2.js";
2
+ import { C as RealtimeClient, D as subscribe, T as layerConfig$2, _ as layerDirect, a as layer$1, b as layerProxy, c as layerFederated, d as layerServerSessionConfig, f as DEFAULT_FOLLOW_RUN_DEADLINE_MS, g as CiClient, h as layer$4, i as FixedWorkflows, l as layerFederatedConfig, n as layer, o as layerConfig$1, p as Runs, r as layerConfig, s as FederatedAuth, t as DelegatedRuntime, u as layerServerSession, v as layerDirectConfig, w as layer$2, x as layerProxyConfig, y as layerFromExecutor } from "./service-DAM3rze2.js";
3
3
  import * as Schema from "effect/Schema";
4
4
  /**
5
5
  * The wire Schemas of the CI envelopes that `./effect` exports. The Type of
@@ -29,4 +29,4 @@ const CiStreamPage = Schema.Struct({
29
29
  events: Schema.mutableKey(Schema.mutable(Schema.Array(Schema.JsonObject))),
30
30
  nextCursor: Schema.mutableKey(Schema.NullOr(Schema.String))
31
31
  });
32
- export { CiClient, CiError, CiErrorCode, CiErrorEnvelope, CiResult, CiStreamPage, CiTransportError, DEFAULT_FOLLOW_RUN_DEADLINE_MS, DelegatedRuntime, FederatedAuth, FederatedAuthError, FederatedAuthErrorCode, FixedWorkflows, LegacyResources, RealtimeClient, Resources, Runs, layerDirect as layerCiClientDirect, layerDirectConfig as layerCiClientDirectConfig, layerFromExecutor as layerCiClientFromExecutor, layerProxy as layerCiClientProxy, layerProxyConfig as layerCiClientProxyConfig, layer as layerDelegatedRuntime, layerConfig as layerDelegatedRuntimeConfig, layerFederated as layerFederatedAuth, layerFederatedConfig as layerFederatedAuthConfig, layer$1 as layerFixedWorkflows, layerConfig$1 as layerFixedWorkflowsConfig, layerLegacy as layerLegacyResources, layerLegacyConfig as layerLegacyResourcesConfig, layer$2 as layerRealtimeClient, layerConfig$2 as layerRealtimeClientConfig, layer$3 as layerResources, layerConfig$3 as layerResourcesConfig, layerFromEntityTransport as layerResourcesFromEntityTransport, layer$4 as layerRuns, layerServerSession as layerServerSessionAuth, layerServerSessionConfig as layerServerSessionAuthConfig, subscribe };
32
+ export { CiClient, CiError, CiErrorCode, CiErrorEnvelope, CiResult, CiStreamPage, CiTransportError, DEFAULT_FOLLOW_RUN_DEADLINE_MS, DelegatedRuntime, FederatedAuth, FederatedAuthError, FederatedAuthErrorCode, FixedWorkflows, LegacyResources, RealtimeClient, Resources, Runs, layerDirect as layerCiClientDirect, layerDirectConfig as layerCiClientDirectConfig, layerFromExecutor as layerCiClientFromExecutor, layerProxy as layerCiClientProxy, layerProxyConfig as layerCiClientProxyConfig, layer as layerDelegatedRuntime, layerConfig as layerDelegatedRuntimeConfig, layerFederated as layerFederatedAuth, layerFederatedConfig as layerFederatedAuthConfig, layer$1 as layerFixedWorkflows, layerConfig$1 as layerFixedWorkflowsConfig, layerLegacy as layerLegacyResources, layerLegacyConfig as layerLegacyResourcesConfig, layer$2 as layerRealtimeClient, layerConfig$2 as layerRealtimeClientConfig, layer$3 as layerResources, layerConfig$3 as layerResourcesConfig, layerFromEntityTransport as layerResourcesFromEntityTransport, layer$4 as layerRuns, layerServerSession as layerServerSessionAuth, layerServerSessionConfig as layerServerSessionAuthConfig, makeEntityHttpExecute, subscribe };
@@ -1,10 +1,10 @@
1
- import { At as ClientOperationMap, Bt as JsonObject, Ct as CiResult, Dt as ClientOperationDefinition, Gt as ClientFetch, Ht as QueryFilter, It as AgentInvokeTarget, Jt as FederatedAuthState, Lt as ApplicationRole, Mt as OperationExecutionOptions, Nt as TypedOperationExecutor, Ot as ClientOperationId, Rt as ConversationContinueTarget, Ut as SearchQuery, Vt as KnowledgeQuery, Wt as WorkflowInvokeTarget, Yt as FederatedSessionIdentity, an as CiError$1, jt as ClientOperationOutput, kt as ClientOperationInput, sn as CiTransportError, wt as JsonValue, xt as CiError$2, yt as ProxyTransportOptions, zt as ConversationHistory } from "./resources-CftkAwlJ.js";
1
+ import { At as ClientOperationInput, Bt as ConversationHistory, Gt as WorkflowInvokeTarget, Ht as KnowledgeQuery, Kt as ClientFetch, Lt as AgentInvokeTarget, Mt as ClientOperationOutput, Nt as OperationExecutionOptions, Ot as ClientOperationDefinition, Pt as TypedOperationExecutor, Rt as ApplicationRole, St as CiError$2, Tt as JsonValue, Ut as QueryFilter, Vt as JsonObject, Wt as SearchQuery, Xt as FederatedSessionIdentity, Yt as FederatedAuthState, bt as ProxyTransportOptions, cn as CiTransportError, jt as ClientOperationMap, kt as ClientOperationId, on as CiError$1, wt as CiResult, zt as ConversationContinueTarget } from "./resources-Bz9fYAWz.js";
2
+ import "effect/Clock";
2
3
  import * as Config from "effect/Config";
3
4
  import * as Context from "effect/Context";
4
5
  import * as Effect from "effect/Effect";
5
6
  import * as Layer from "effect/Layer";
6
7
  import "effect/Stream";
7
- import "effect/Clock";
8
8
  import "effect/ManagedRuntime";
9
9
  /** One equality filter on a dotted data path of a topic's records. */
10
10
  type RealtimeTopicFilter = Readonly<{
@@ -969,6 +969,12 @@ type RealtimeTimers = Readonly<{
969
969
  type RealtimeClientOptions = Readonly<{
970
970
  /** The application's ticket route, e.g. `/api/realtime/ticket`. */
971
971
  ticketUrl: string;
972
+ /**
973
+ * The application's Revalidate Route, e.g. `/api/realtime/revalidate`. With
974
+ * it, each delivery also posts its changes there with the grant token of
975
+ * the last ticket, so that the server revalidates its cache tags.
976
+ */
977
+ revalidateUrl?: string;
972
978
  fetch?: ClientFetch;
973
979
  eventSourceFactory?: RealtimeEventSourceFactory;
974
980
  /** The page document; without it the page counts as always visible. */
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { $ as ResourceIdentityField, A as EntityOperationResult, At as ClientOperationMap, B as IdempotencyKey, Bt as JsonObject, C as EntityDeleteInput, Ct as CiResult, D as EntityListQuery, Dt as ClientOperationDefinition, E as EntityFileWrite, Et as OperationSuccess, F as EntityRestoreInput, Ft as isClientOperationId, G as ResourceCreateRequest, Gt as ClientFetch, H as ResourceCapabilities, Ht as QueryFilter, I as EntityTransport, J as ResourceError, Jt as FederatedAuthState, K as ResourceCursor, Kt as FederatedAuth, L as EntityUpdateInput, M as EntityProtocol, Mt as OperationExecutionOptions, N as EntityReadLimitDetails, Nt as TypedOperationExecutor, O as EntityMemberValue, Ot as ClientOperationId, P as EntityRequest, Pt as clientOperationIds, Q as ResourceId, R as EntityUploadInput, S as EntityCreateInput, St as CiErrorCode, T as EntityFileValue, Tt as OperationRequest, U as ResourceClient, Ut as SearchQuery, V as PortableResourceSchema, Vt as KnowledgeQuery, W as ResourceCreateInput, Wt as WorkflowInvokeTarget, X as ResourceFilter, Xt as createFederatedAuth, Y as ResourceErrorCode, Yt as FederatedSessionIdentity, Z as ResourceGetRequest, _t as ResourceUpdateRequest, at as ResourceListResult, b as createResourceClient, bt as createProxyTransport, cn as FederatedAuthError, ct as ResourcePaginationMode, dt as ResourceRequestOptions, et as ResourceJsonValue, ft as ResourceResult, gt as ResourceTransportRequest, ht as ResourceTransport, in as createServerSessionAuth, it as ResourceListRequest, j as EntityPage, jt as ClientOperationOutput, k as EntityOperation, kt as ClientOperationInput, ln as FederatedAuthErrorCode, lt as ResourceRecord, mt as ResourceSort, n as EntityHttpTransportOptions, nt as ResourceLifecycleRequest, ot as ResourceMutationInput, pt as ResourceRevision, q as ResourceDefinition, qt as FederatedAuthOptions, r as createEntityHttpTransport, rn as ServerSessionAuthOptions, rt as ResourceListQuery, sn as CiTransportError, st as ResourcePagination, t as EntityHttpDestination, tt as ResourceLifecycleInput, ut as ResourceRecordId, v as createEntityProtocol, vt as ProxyAuthentication, w as EntityFileFieldWrite, wt as JsonValue, x as EntityClient, y as isEntityReadLimitError, yt as ProxyTransportOptions, z as EntityUploadSlot } from "./resources-CftkAwlJ.js";
2
- import { $ as RealtimeTopicFilter, A as CiStreamEvent, C as followRun, G as RealtimeStreamEnd, H as createDirectTransport, J as createFetchEventSourceFactory, K as RealtimeStreamEvent, M as nextStreamCursor, Q as RealtimeTopic, S as FollowRunSource, U as RealtimeEventSource, V as DirectTransportOptions, W as RealtimeEventSourceFactory, X as RealtimeWindow, Y as RealtimeDocument, Z as RealtimeChange, _ as ClientSdkEntrypoint, a as RealtimeClientStatus, b as createClient, c as FixedWorkflowClient, d as DelegatedApplicationRuntime, et as realtimeTopicKey, f as DelegatedApplicationRuntimeOptions, g as ClientSdkClient, h as ClientDomains, i as RealtimeClientState, j as CiStreamPage, k as CiRunCancellation, l as FixedWorkflowClientOptions, m as createDelegatedApplicationRuntime, n as RealtimeClient, o as RealtimeTimers, p as DelegatedRuntimeState, q as RealtimeStreamHandlers, r as RealtimeClientOptions, s as createRealtimeClient, t as CiError, u as createFixedWorkflowClient, v as OrganizationClient, w as DEFAULT_FOLLOW_RUN_DEADLINE_MS, x as FollowRunOptions, y as clientSdkProtocolVersion } from "./index-D_Ctkuhr.js";
1
+ import { $ as ResourceId, A as EntityOperation, At as ClientOperationInput, B as EntityUploadSlot, C as EntityCreateInput, Ct as CiErrorCode, D as EntityFileWrite, Dt as OperationSuccess, E as EntityFileValue, Et as OperationRequest, F as EntityRequest, Ft as clientOperationIds, G as ResourceCreateInput, Gt as WorkflowInvokeTarget, H as PortableResourceSchema, Ht as KnowledgeQuery, I as EntityRestoreInput, It as isClientOperationId, J as ResourceDefinition, Jt as FederatedAuthOptions, K as ResourceCreateRequest, Kt as ClientFetch, L as EntityTransport, M as EntityPage, Mt as ClientOperationOutput, N as EntityProtocol, Nt as OperationExecutionOptions, O as EntityListQuery, Ot as ClientOperationDefinition, P as EntityReadLimitDetails, Pt as TypedOperationExecutor, Q as ResourceGetRequest, R as EntityUpdateInput, S as EntityClient, T as EntityFileFieldWrite, Tt as JsonValue, U as ResourceCapabilities, Ut as QueryFilter, V as IdempotencyKey, Vt as JsonObject, W as ResourceClient, Wt as SearchQuery, X as ResourceErrorCode, Xt as FederatedSessionIdentity, Y as ResourceError, Yt as FederatedAuthState, Z as ResourceFilter, Zt as createFederatedAuth, _t as ResourceTransportRequest, an as createServerSessionAuth, at as ResourceListRequest, b as isEntityReadLimitError, bt as ProxyTransportOptions, cn as CiTransportError, ct as ResourcePagination, dt as ResourceRecordId, et as ResourceIdentityField, ft as ResourceRequestOptions, gt as ResourceTransport, ht as ResourceSort, in as ServerSessionAuthOptions, it as ResourceListQuery, j as EntityOperationResult, jt as ClientOperationMap, k as EntityMemberValue, kt as ClientOperationId, ln as FederatedAuthError, lt as ResourcePaginationMode, mt as ResourceRevision, n as EntityHttpTransportOptions, nt as ResourceLifecycleInput, ot as ResourceListResult, pt as ResourceResult, q as ResourceCursor, qt as FederatedAuth, r as createEntityHttpTransport, rt as ResourceLifecycleRequest, st as ResourceMutationInput, t as EntityHttpDestination, tt as ResourceJsonValue, un as FederatedAuthErrorCode, ut as ResourceRecord, vt as ResourceUpdateRequest, w as EntityDeleteInput, wt as CiResult, x as createResourceClient, xt as createProxyTransport, y as createEntityProtocol, yt as ProxyAuthentication, z as EntityUploadInput } from "./resources-Bz9fYAWz.js";
2
+ import { $ as RealtimeTopicFilter, A as CiStreamEvent, C as followRun, G as RealtimeStreamEnd, H as createDirectTransport, J as createFetchEventSourceFactory, K as RealtimeStreamEvent, M as nextStreamCursor, Q as RealtimeTopic, S as FollowRunSource, U as RealtimeEventSource, V as DirectTransportOptions, W as RealtimeEventSourceFactory, X as RealtimeWindow, Y as RealtimeDocument, Z as RealtimeChange, _ as ClientSdkEntrypoint, a as RealtimeClientStatus, b as createClient, c as FixedWorkflowClient, d as DelegatedApplicationRuntime, et as realtimeTopicKey, f as DelegatedApplicationRuntimeOptions, g as ClientSdkClient, h as ClientDomains, i as RealtimeClientState, j as CiStreamPage, k as CiRunCancellation, l as FixedWorkflowClientOptions, m as createDelegatedApplicationRuntime, n as RealtimeClient, o as RealtimeTimers, p as DelegatedRuntimeState, q as RealtimeStreamHandlers, r as RealtimeClientOptions, s as createRealtimeClient, t as CiError, u as createFixedWorkflowClient, v as OrganizationClient, w as DEFAULT_FOLLOW_RUN_DEADLINE_MS, x as FollowRunOptions, y as clientSdkProtocolVersion } from "./index-DdmAyX_o.js";
3
3
  export { CiError, type CiErrorCode, type CiResult, type CiRunCancellation, type CiStreamEvent, type CiStreamPage, CiTransportError, type ClientDomains, type ClientFetch, type ClientOperationDefinition, type ClientOperationId, type ClientOperationInput, type ClientOperationMap, type ClientOperationOutput, type ClientSdkClient, type ClientSdkEntrypoint, DEFAULT_FOLLOW_RUN_DEADLINE_MS, type DelegatedApplicationRuntime, type DelegatedApplicationRuntimeOptions, type DelegatedRuntimeState, type DirectTransportOptions, type EntityClient, type EntityCreateInput, type EntityDeleteInput, type EntityFileFieldWrite, type EntityFileValue, type EntityFileWrite, type EntityHttpDestination, type EntityHttpTransportOptions, type EntityListQuery, type EntityMemberValue, type EntityOperation, type EntityOperationResult, type EntityPage, type EntityProtocol, type EntityReadLimitDetails, type EntityRequest, type EntityRestoreInput, type EntityTransport, type EntityUpdateInput, type EntityUploadInput, type EntityUploadSlot, type FederatedAuth, FederatedAuthError, type FederatedAuthErrorCode, type FederatedAuthOptions, type FederatedAuthState, type FederatedSessionIdentity, type FixedWorkflowClient, type FixedWorkflowClientOptions, type FollowRunOptions, type FollowRunSource, type IdempotencyKey, type JsonObject, type JsonValue, type KnowledgeQuery, type OperationExecutionOptions, type OperationRequest, type OperationSuccess, type OrganizationClient, type PortableResourceSchema, type ProxyAuthentication, type ProxyTransportOptions, type QueryFilter, type RealtimeChange, type RealtimeClient, type RealtimeClientOptions, type RealtimeClientState, type RealtimeClientStatus, type RealtimeDocument, type RealtimeEventSource, type RealtimeEventSourceFactory, type RealtimeStreamEnd, type RealtimeStreamEvent, type RealtimeStreamHandlers, type RealtimeTimers, type RealtimeTopic, type RealtimeTopicFilter, type RealtimeWindow, type ResourceCapabilities, type ResourceClient, type ResourceCreateInput, type ResourceCreateRequest, type ResourceCursor, type ResourceDefinition, type ResourceError, type ResourceErrorCode, type ResourceFilter, type ResourceGetRequest, type ResourceId, type ResourceIdentityField, type ResourceJsonValue, type ResourceLifecycleInput, type ResourceLifecycleRequest, type ResourceListQuery, type ResourceListRequest, type ResourceListResult, type ResourceMutationInput, type ResourcePagination, type ResourcePaginationMode, type ResourceRecord, type ResourceRecordId, type ResourceRequestOptions, type ResourceResult, type ResourceRevision, type ResourceSort, type ResourceTransport, type ResourceTransportRequest, type ResourceUpdateRequest, type SearchQuery, type ServerSessionAuthOptions, type TypedOperationExecutor, type WorkflowInvokeTarget, clientOperationIds, clientSdkProtocolVersion, createClient, createDelegatedApplicationRuntime, createDirectTransport, createEntityHttpTransport, createEntityProtocol, createFederatedAuth, createFetchEventSourceFactory, createFixedWorkflowClient, createProxyTransport, createRealtimeClient, createResourceClient, createServerSessionAuth, followRun, isClientOperationId, isEntityReadLimitError, nextStreamCursor, realtimeTopicKey };
package/dist/index.js CHANGED
@@ -1,15 +1,15 @@
1
- import { E as FederatedAuthError, O as errors_exports, S as toCiResult, T as CiTransportError, _ as makeHttpExecute, d as createEntityHttpTransport, g as directHttpOptions, m as isEntityReadLimitError, p as createEntityProtocol, v as proxyHttpOptions, x as isClientOperationId, y as clientOperationIds } from "./service-D-18nBUU.js";
2
- import { A as layerFromFactory, E as makeConnection, M as currentLink, N as createFetchEventSourceFactory, O as realtimeTopicKey, S as make, a as layer$2, c as layerFederated, f as DEFAULT_FOLLOW_RUN_DEADLINE_MS, g as CiClient, h as layer, i as FixedWorkflows, j as layerBrowser, k as layer$3, m as followSource, n as layer$1, p as Runs, s as FederatedAuth, t as DelegatedRuntime, u as layerServerSession, y as layerFromExecutor } from "./service-DD58W3in.js";
3
- import { t as createResourceClient } from "./resources-BhOgbxg5.js";
1
+ import { C as toCiResult, D as FederatedAuthError, E as CiTransportError, S as isClientOperationId, _ as directHttpOptions, b as clientOperationIds, d as createEntityHttpTransport, h as isEntityReadLimitError, k as errors_exports, m as createEntityProtocol, v as makeHttpExecute, y as proxyHttpOptions } from "./service-BGqbpJD2.js";
2
+ import { A as layerFromFactory, E as makeConnection, M as currentLink, N as createFetchEventSourceFactory, O as realtimeTopicKey, S as make, a as layer$2, c as layerFederated, f as DEFAULT_FOLLOW_RUN_DEADLINE_MS, g as CiClient, h as layer, i as FixedWorkflows, j as layerBrowser, k as layer$3, m as followSource, n as layer$1, p as Runs, s as FederatedAuth, t as DelegatedRuntime, u as layerServerSession, y as layerFromExecutor } from "./service-DAM3rze2.js";
3
+ import { t as createResourceClient } from "./resources-C87ZTpv3.js";
4
+ import * as Clock from "effect/Clock";
4
5
  import * as Context from "effect/Context";
6
+ import * as Duration from "effect/Duration";
5
7
  import * as Effect from "effect/Effect";
8
+ import * as Fiber from "effect/Fiber";
6
9
  import * as FetchHttpClient from "effect/http/FetchHttpClient";
7
10
  import * as Layer from "effect/Layer";
8
11
  import * as Random from "effect/Random";
9
- import * as Clock from "effect/Clock";
10
12
  import * as ManagedRuntime from "effect/ManagedRuntime";
11
- import * as Duration from "effect/Duration";
12
- import * as Fiber from "effect/Fiber";
13
13
  import { constVoid } from "effect/Function";
14
14
  /**
15
15
  * Internal; no entrypoint exports it. Runs one facade method:
@@ -382,33 +382,35 @@ const randomOf = (random) => ({
382
382
  nextIntUnsafe: () => Math.floor(random() * Number.MAX_SAFE_INTEGER)
383
383
  });
384
384
  /**
385
- * The origin on which the service requests the ticket. `HttpClient` resolves
386
- * a relative URL against `location`, and fails without one. But `fetch` got
387
- * `ticketUrl` as the app gave it before the service, and a custom `fetch` can
388
- * resolve it on a base of its own. So the service requests `ticketUrl` on this
389
- * origin, and `fetchOf` gives `fetch` the `ticketUrl` of the app in its place.
385
+ * The origin on which the service requests the ticket and posts to the
386
+ * Revalidate Route. `HttpClient` resolves a relative URL against `location`,
387
+ * and fails without one. But `fetch` got `ticketUrl` as the app gave it before
388
+ * the service, and a custom `fetch` can resolve it on a base of its own. So
389
+ * the service requests each app URL on this origin, and `fetchOf` gives
390
+ * `fetch` the URL of the app in its place.
390
391
  */
391
- const ticketOrigin = "http://realtime-ticket.invalid/";
392
- /** `ticketUrl` on `ticketOrigin`; `ticketOrigin` itself for a string that is not a URL. */
393
- const ticketRequestUrl = (ticketUrl) => {
392
+ const placeholderOrigin = "http://realtime-ticket.invalid/";
393
+ /** `url` on `placeholderOrigin`; `placeholderOrigin` itself for a string that is not a URL. */
394
+ const onPlaceholderOrigin = (url) => {
394
395
  try {
395
- return new URL(ticketUrl, ticketOrigin).href;
396
+ return new URL(url, placeholderOrigin).href;
396
397
  } catch {
397
- return ticketOrigin;
398
+ return placeholderOrigin;
398
399
  }
399
400
  };
400
401
  /**
401
402
  * The `fetch` of the client as `FetchHttpClient.Fetch`, called as before the
402
- * service: with a string URL, `ticketUrl` for the ticket request, and without
403
- * the `duplex: undefined` that `FetchHttpClient` adds for a body that is not
404
- * a stream. `preconnect` only completes the type of `fetch` under Bun's
405
- * types; nothing here preconnects.
403
+ * service: with a string URL, `ticketUrl` for the ticket request and
404
+ * `revalidateUrl` for a revalidate post, and without the `duplex: undefined`
405
+ * that `FetchHttpClient` adds for a body that is not a stream. `preconnect`
406
+ * only completes the type of `fetch` under Bun's types; nothing here
407
+ * preconnects.
406
408
  */
407
- const fetchOf = (fetch, ticketUrl) => {
408
- const requestUrl = ticketRequestUrl(ticketUrl);
409
+ const fetchOf = (fetch, appUrls) => {
410
+ const requestUrls = new Map(appUrls.map((url) => [onPlaceholderOrigin(url), url]));
409
411
  return Object.assign((input, init) => {
410
412
  const href = input instanceof URL ? input.href : input;
411
- const url = href === requestUrl ? ticketUrl : href;
413
+ const url = href instanceof Request ? href : requestUrls.get(href) ?? href;
412
414
  if (init === void 0 || !("duplex" in init)) return fetch(url, init);
413
415
  const { duplex, ...rest } = init;
414
416
  return duplex === void 0 ? fetch(url, rest) : fetch(url, init);
@@ -429,7 +431,8 @@ const createRealtimeClient = (options) => {
429
431
  const { flush, scheduler } = makeSyncScheduler();
430
432
  const runtime = ManagedRuntime.make(Layer.effect(FacadeConnection, makeConnection({
431
433
  resyncOnAccessChange: false,
432
- ticketUrl: ticketRequestUrl(options.ticketUrl)
434
+ ticketUrl: onPlaceholderOrigin(options.ticketUrl),
435
+ ...options.revalidateUrl !== void 0 && { revalidateUrl: onPlaceholderOrigin(options.revalidateUrl) }
433
436
  })).pipe(Layer.provide([
434
437
  FetchHttpClient.layer,
435
438
  layerBrowser({
@@ -438,7 +441,7 @@ const createRealtimeClient = (options) => {
438
441
  }),
439
442
  options.eventSourceFactory === void 0 ? layer$3 : layerFromFactory(options.eventSourceFactory)
440
443
  ]), Layer.provide([
441
- Layer.succeed(FetchHttpClient.Fetch, fetchOf(options.fetch ?? globalThis.fetch, options.ticketUrl)),
444
+ Layer.succeed(FetchHttpClient.Fetch, fetchOf(options.fetch ?? globalThis.fetch, [options.ticketUrl, options.revalidateUrl].filter((url) => url !== void 0))),
442
445
  Layer.succeed(Clock.Clock, clockOf(options.timers ?? defaultTimers, flush)),
443
446
  Layer.succeed(Random.Random, randomOf(options.random ?? Math.random))
444
447
  ])));
@@ -1065,6 +1065,8 @@ declare const isEntityReadLimitError: (error: ResourceError) => error is Resourc
1065
1065
  }>;
1066
1066
  /** Common entity wire codec; transport and persistence remain with their owners. */
1067
1067
  declare const createEntityProtocol: <Value, Create = Value, Patch = Partial<Value>>(definition: ResourceDefinition<Value, Create, Patch>) => EntityProtocol<Value, Create, Patch>;
1068
+ /** One entity request as its envelope; only a transport failure fails. */
1069
+ type EntityExecute = (request: EntityRequest, options: ResourceRequestOptions) => Effect.Effect<ResourceResult<unknown>, CiTransportError>;
1068
1070
  type ResourceFailure = CiError$1 | CiTransportError;
1069
1071
  /** The entity client of one Resource Definition for `./effect`. */
1070
1072
  type ResourceEntityClient<Value, Create, Patch> = Readonly<{
@@ -1160,6 +1162,16 @@ type EntityHttpTransportOptions = Readonly<{
1160
1162
  authentication: ProxyAuthentication;
1161
1163
  fetch?: ClientFetch;
1162
1164
  }>;
1165
+ /**
1166
+ * The entity HTTP adapter of one destination, the `./effect` form of
1167
+ * `createEntityHttpTransport`: each request is an Effect that runs in the
1168
+ * fiber of its caller. Early cancellation and a failed login stay envelopes,
1169
+ * as the request was not sent; a request that does not reach the server, or
1170
+ * an answer that cannot be read, fails with `CiTransportError`. A
1171
+ * destination without its CI selectors, or an endpoint with credentials,
1172
+ * query or fragment, throws `TypeError`.
1173
+ */
1174
+ declare const makeEntityHttpExecute: (options: EntityHttpTransportOptions) => EntityExecute;
1163
1175
  /**
1164
1176
  * The Vanilla Facade of the entity HTTP adapter, in a runtime of its own;
1165
1177
  * `close` disposes it.
@@ -1167,4 +1179,4 @@ type EntityHttpTransportOptions = Readonly<{
1167
1179
  declare const createEntityHttpTransport: (options: EntityHttpTransportOptions) => EntityTransport & Readonly<{
1168
1180
  close: () => Promise<void>;
1169
1181
  }>;
1170
- export { ResourceIdentityField as $, layerFederated as $t, EntityOperationResult as A, ClientOperationMap as At, IdempotencyKey as B, JsonObject as Bt, EntityDeleteInput as C, CiResult as Ct, EntityListQuery as D, ClientOperationDefinition as Dt, EntityFileWrite as E, OperationSuccess as Et, EntityRestoreInput as F, isClientOperationId as Ft, ResourceCreateRequest as G, ClientFetch as Gt, ResourceCapabilities as H, QueryFilter as Ht, EntityTransport as I, AgentInvokeTarget as It, ResourceError as J, FederatedAuthState as Jt, ResourceCursor as K, FederatedAuth as Kt, EntityUpdateInput as L, ApplicationRole as Lt, EntityProtocol as M, OperationExecutionOptions as Mt, EntityReadLimitDetails as N, TypedOperationExecutor as Nt, EntityMemberValue as O, ClientOperationId as Ot, EntityRequest as P, clientOperationIds as Pt, ResourceId as Q, FederatedAuthValue as Qt, EntityUploadInput as R, ConversationContinueTarget as Rt, EntityCreateInput as S, CiErrorCode as St, EntityFileValue as T, OperationRequest as Tt, ResourceClient as U, SearchQuery as Ut, PortableResourceSchema as V, KnowledgeQuery as Vt, ResourceCreateInput as W, WorkflowInvokeTarget as Wt, ResourceFilter as X, createFederatedAuth as Xt, ResourceErrorCode as Y, FederatedSessionIdentity as Yt, ResourceGetRequest as Z, FederatedAuth$1 as Zt, layerLegacyConfig as _, ResourceUpdateRequest as _t, LegacyResources as a, CiError$1 as an, ResourceListResult as at, createResourceClient as b, createProxyTransport as bt, ResourceEntityClient as c, FederatedAuthError as cn, ResourcePaginationMode as ct, ResourcesLayerOptions as d, ResourceRequestOptions as dt, layerFederatedConfig as en, ResourceJsonValue as et, ResourcesValue as f, ResourceResult as ft, layerLegacy as g, ResourceTransportRequest as gt, layerFromEntityTransport as h, ResourceTransport as ht, LegacyResourceClient as i, createServerSessionAuth as in, ResourceListRequest as it, EntityPage as j, ClientOperationOutput as jt, EntityOperation as k, ClientOperationInput as kt, Resources as l, FederatedAuthErrorCode as ln, ResourceRecord as lt, layerConfig as m, ResourceSort as mt, EntityHttpTransportOptions as n, layerServerSessionConfig as nn, ResourceLifecycleRequest as nt, LegacyResourcesLayerOptions as o, CiErrorCode$1 as on, ResourceMutationInput as ot, layer as p, ResourceRevision as pt, ResourceDefinition as q, FederatedAuthOptions as qt, createEntityHttpTransport as r, ServerSessionAuthOptions as rn, ResourceListQuery as rt, LegacyResourcesValue as s, CiTransportError as sn, ResourcePagination as st, EntityHttpDestination as t, layerServerSession as tn, ResourceLifecycleInput as tt, ResourcesFromEntityTransportOptions as u, ResourceRecordId as ut, createEntityProtocol as v, ProxyAuthentication as vt, EntityFileFieldWrite as w, JsonValue as wt, EntityClient as x, CiError as xt, isEntityReadLimitError as y, ProxyTransportOptions as yt, EntityUploadSlot as z, ConversationHistory as zt };
1182
+ export { ResourceId as $, FederatedAuthValue as $t, EntityOperation as A, ClientOperationInput as At, EntityUploadSlot as B, ConversationHistory as Bt, EntityCreateInput as C, CiErrorCode as Ct, EntityFileWrite as D, OperationSuccess as Dt, EntityFileValue as E, OperationRequest as Et, EntityRequest as F, clientOperationIds as Ft, ResourceCreateInput as G, WorkflowInvokeTarget as Gt, PortableResourceSchema as H, KnowledgeQuery as Ht, EntityRestoreInput as I, isClientOperationId as It, ResourceDefinition as J, FederatedAuthOptions as Jt, ResourceCreateRequest as K, ClientFetch as Kt, EntityTransport as L, AgentInvokeTarget as Lt, EntityPage as M, ClientOperationOutput as Mt, EntityProtocol as N, OperationExecutionOptions as Nt, EntityListQuery as O, ClientOperationDefinition as Ot, EntityReadLimitDetails as P, TypedOperationExecutor as Pt, ResourceGetRequest as Q, FederatedAuth$1 as Qt, EntityUpdateInput as R, ApplicationRole as Rt, EntityClient as S, CiError as St, EntityFileFieldWrite as T, JsonValue as Tt, ResourceCapabilities as U, QueryFilter as Ut, IdempotencyKey as V, JsonObject as Vt, ResourceClient as W, SearchQuery as Wt, ResourceErrorCode as X, FederatedSessionIdentity as Xt, ResourceError as Y, FederatedAuthState as Yt, ResourceFilter as Z, createFederatedAuth as Zt, layerLegacy as _, ResourceTransportRequest as _t, LegacyResourceClient as a, createServerSessionAuth as an, ResourceListRequest as at, isEntityReadLimitError as b, ProxyTransportOptions as bt, LegacyResourcesValue as c, CiTransportError as cn, ResourcePagination as ct, ResourcesFromEntityTransportOptions as d, ResourceRecordId as dt, layerFederated as en, ResourceIdentityField as et, ResourcesLayerOptions as f, ResourceRequestOptions as ft, layerFromEntityTransport as g, ResourceTransport as gt, layerConfig as h, ResourceSort as ht, makeEntityHttpExecute as i, ServerSessionAuthOptions as in, ResourceListQuery as it, EntityOperationResult as j, ClientOperationMap as jt, EntityMemberValue as k, ClientOperationId as kt, ResourceEntityClient as l, FederatedAuthError as ln, ResourcePaginationMode as lt, layer as m, ResourceRevision as mt, EntityHttpTransportOptions as n, layerServerSession as nn, ResourceLifecycleInput as nt, LegacyResources as o, CiError$1 as on, ResourceListResult as ot, ResourcesValue as p, ResourceResult as pt, ResourceCursor as q, FederatedAuth as qt, createEntityHttpTransport as r, layerServerSessionConfig as rn, ResourceLifecycleRequest as rt, LegacyResourcesLayerOptions as s, CiErrorCode$1 as sn, ResourceMutationInput as st, EntityHttpDestination as t, layerFederatedConfig as tn, ResourceJsonValue as tt, Resources as u, FederatedAuthErrorCode as un, ResourceRecord as ut, layerLegacyConfig as v, ResourceUpdateRequest as vt, EntityDeleteInput as w, CiResult as wt, createResourceClient as x, createProxyTransport as xt, createEntityProtocol as y, ProxyAuthentication as yt, EntityUploadInput as z, ConversationContinueTarget as zt };
@@ -1,4 +1,4 @@
1
- import { T as CiTransportError, f as runEntityRequest, l as makeEntityCore, r as fromEntityTransport, u as makeLegacyResourceCore } from "./service-D-18nBUU.js";
1
+ import { E as CiTransportError, l as makeEntityCore, p as runEntityRequest, r as fromEntityTransport, u as makeLegacyResourceCore } from "./service-BGqbpJD2.js";
2
2
  import * as Layer from "effect/Layer";
3
3
  import * as ManagedRuntime from "effect/ManagedRuntime";
4
4
  /**
@@ -1,2 +1,2 @@
1
- import { $ as ResourceIdentityField, A as EntityOperationResult, B as IdempotencyKey, C as EntityDeleteInput, D as EntityListQuery, E as EntityFileWrite, F as EntityRestoreInput, G as ResourceCreateRequest, H as ResourceCapabilities, I as EntityTransport, J as ResourceError, K as ResourceCursor, L as EntityUpdateInput, M as EntityProtocol, N as EntityReadLimitDetails, O as EntityMemberValue, P as EntityRequest, Q as ResourceId, R as EntityUploadInput, S as EntityCreateInput, T as EntityFileValue, U as ResourceClient, V as PortableResourceSchema, W as ResourceCreateInput, X as ResourceFilter, Y as ResourceErrorCode, Z as ResourceGetRequest, _t as ResourceUpdateRequest, at as ResourceListResult, b as createResourceClient, ct as ResourcePaginationMode, dt as ResourceRequestOptions, et as ResourceJsonValue, ft as ResourceResult, gt as ResourceTransportRequest, ht as ResourceTransport, it as ResourceListRequest, j as EntityPage, k as EntityOperation, lt as ResourceRecord, mt as ResourceSort, n as EntityHttpTransportOptions, nt as ResourceLifecycleRequest, ot as ResourceMutationInput, pt as ResourceRevision, q as ResourceDefinition, r as createEntityHttpTransport, rt as ResourceListQuery, st as ResourcePagination, t as EntityHttpDestination, tt as ResourceLifecycleInput, ut as ResourceRecordId, v as createEntityProtocol, w as EntityFileFieldWrite, x as EntityClient, y as isEntityReadLimitError, z as EntityUploadSlot } from "./resources-CftkAwlJ.js";
1
+ import { $ as ResourceId, A as EntityOperation, B as EntityUploadSlot, C as EntityCreateInput, D as EntityFileWrite, E as EntityFileValue, F as EntityRequest, G as ResourceCreateInput, H as PortableResourceSchema, I as EntityRestoreInput, J as ResourceDefinition, K as ResourceCreateRequest, L as EntityTransport, M as EntityPage, N as EntityProtocol, O as EntityListQuery, P as EntityReadLimitDetails, Q as ResourceGetRequest, R as EntityUpdateInput, S as EntityClient, T as EntityFileFieldWrite, U as ResourceCapabilities, V as IdempotencyKey, W as ResourceClient, X as ResourceErrorCode, Y as ResourceError, Z as ResourceFilter, _t as ResourceTransportRequest, at as ResourceListRequest, b as isEntityReadLimitError, ct as ResourcePagination, dt as ResourceRecordId, et as ResourceIdentityField, ft as ResourceRequestOptions, gt as ResourceTransport, ht as ResourceSort, it as ResourceListQuery, j as EntityOperationResult, k as EntityMemberValue, lt as ResourcePaginationMode, mt as ResourceRevision, n as EntityHttpTransportOptions, nt as ResourceLifecycleInput, ot as ResourceListResult, pt as ResourceResult, q as ResourceCursor, r as createEntityHttpTransport, rt as ResourceLifecycleRequest, st as ResourceMutationInput, t as EntityHttpDestination, tt as ResourceJsonValue, ut as ResourceRecord, vt as ResourceUpdateRequest, w as EntityDeleteInput, x as createResourceClient, y as createEntityProtocol, z as EntityUploadInput } from "./resources-Bz9fYAWz.js";
2
2
  export { type EntityClient, type EntityCreateInput, type EntityDeleteInput, type EntityFileFieldWrite, type EntityFileValue, type EntityFileWrite, type EntityHttpDestination, type EntityHttpTransportOptions, type EntityListQuery, type EntityMemberValue, type EntityOperation, type EntityOperationResult, type EntityPage, type EntityProtocol, type EntityReadLimitDetails, type EntityRequest, type EntityRestoreInput, type EntityTransport, type EntityUpdateInput, type EntityUploadInput, type EntityUploadSlot, type IdempotencyKey, type PortableResourceSchema, type ResourceCapabilities, type ResourceClient, type ResourceCreateInput, type ResourceCreateRequest, type ResourceCursor, type ResourceDefinition, type ResourceError, type ResourceErrorCode, type ResourceFilter, type ResourceGetRequest, type ResourceId, type ResourceIdentityField, type ResourceJsonValue, type ResourceLifecycleInput, type ResourceLifecycleRequest, type ResourceListQuery, type ResourceListRequest, type ResourceListResult, type ResourceMutationInput, type ResourcePagination, type ResourcePaginationMode, type ResourceRecord, type ResourceRecordId, type ResourceRequestOptions, type ResourceResult, type ResourceRevision, type ResourceSort, type ResourceTransport, type ResourceTransportRequest, type ResourceUpdateRequest, createEntityHttpTransport, createEntityProtocol, createResourceClient, isEntityReadLimitError };
package/dist/resources.js CHANGED
@@ -1,3 +1,3 @@
1
- import { d as createEntityHttpTransport, m as isEntityReadLimitError, p as createEntityProtocol } from "./service-D-18nBUU.js";
2
- import { t as createResourceClient } from "./resources-BhOgbxg5.js";
1
+ import { d as createEntityHttpTransport, h as isEntityReadLimitError, m as createEntityProtocol } from "./service-BGqbpJD2.js";
2
+ import { t as createResourceClient } from "./resources-C87ZTpv3.js";
3
3
  export { createEntityHttpTransport, createEntityProtocol, createResourceClient, isEntityReadLimitError };
@@ -8430,11 +8430,13 @@ const envelopeOf = (response, result) => {
8430
8430
  return result;
8431
8431
  };
8432
8432
  /**
8433
- * The entity HTTP adapter of one destination. Early cancellation and a
8434
- * failed login stay envelopes, as the request was not sent; a request that
8435
- * does not reach the server, or an answer that cannot be read, fails with
8436
- * `CiTransportError`. A destination without its CI selectors, or an
8437
- * endpoint with credentials, query or fragment, throws `TypeError`.
8433
+ * The entity HTTP adapter of one destination, the `./effect` form of
8434
+ * `createEntityHttpTransport`: each request is an Effect that runs in the
8435
+ * fiber of its caller. Early cancellation and a failed login stay envelopes,
8436
+ * as the request was not sent; a request that does not reach the server, or
8437
+ * an answer that cannot be read, fails with `CiTransportError`. A
8438
+ * destination without its CI selectors, or an endpoint with credentials,
8439
+ * query or fragment, throws `TypeError`.
8438
8440
  */
8439
8441
  const makeEntityHttpExecute = (options) => {
8440
8442
  const { destination, authentication } = options;
@@ -8808,4 +8810,4 @@ const makeLegacy = (options) => LegacyResources.of({ bind: (definition) => {
8808
8810
  const layerLegacy = (options) => Layer.succeed(LegacyResources, makeLegacy(options));
8809
8811
  /** `layerLegacy` with options that Effect `Config` reads. */
8810
8812
  const layerLegacyConfig = (config) => Layer.unwrap(Effect.map(Config.unwrap(config), layerLegacy));
8811
- export { CiError as C, FederatedAuthErrorCode as D, FederatedAuthError as E, errors_exports as O, toCiResult as S, CiTransportError as T, makeHttpExecute as _, layerConfig as a, fromCiResult as b, layerLegacyConfig as c, createEntityHttpTransport as d, runEntityRequest as f, directHttpOptions as g, backendErrorCode as h, layer as i, ciErrorCodes as k, makeEntityCore as l, isEntityReadLimitError as m, Resources as n, layerFromEntityTransport as o, createEntityProtocol as p, fromEntityTransport as r, layerLegacy as s, LegacyResources as t, makeLegacyResourceCore as u, proxyHttpOptions as v, CiErrorCode as w, isClientOperationId as x, clientOperationIds as y };
8813
+ export { ciErrorCodes as A, toCiResult as C, FederatedAuthError as D, CiTransportError as E, FederatedAuthErrorCode as O, isClientOperationId as S, CiErrorCode as T, directHttpOptions as _, layerConfig as a, clientOperationIds as b, layerLegacyConfig as c, createEntityHttpTransport as d, makeEntityHttpExecute as f, backendErrorCode as g, isEntityReadLimitError as h, layer as i, errors_exports as k, makeEntityCore as l, createEntityProtocol as m, Resources as n, layerFromEntityTransport as o, runEntityRequest as p, fromEntityTransport as r, layerLegacy as s, LegacyResources as t, makeLegacyResourceCore as u, makeHttpExecute as v, CiError as w, fromCiResult as x, proxyHttpOptions as y };
@@ -1,12 +1,17 @@
1
- import { C as CiError, E as FederatedAuthError, S as toCiResult, T as CiTransportError, _ as makeHttpExecute, b as fromCiResult, g as directHttpOptions, h as backendErrorCode, k as ciErrorCodes, v as proxyHttpOptions } from "./service-D-18nBUU.js";
1
+ import { A as ciErrorCodes, C as toCiResult, D as FederatedAuthError, E as CiTransportError, _ as directHttpOptions, g as backendErrorCode, v as makeHttpExecute, w as CiError, x as fromCiResult, y as proxyHttpOptions } from "./service-BGqbpJD2.js";
2
2
  import * as Predicate from "effect/Predicate";
3
3
  import * as Schema from "effect/Schema";
4
+ import * as Arr from "effect/Array";
4
5
  import * as Cause from "effect/Cause";
6
+ import * as Clock from "effect/Clock";
5
7
  import * as Config from "effect/Config";
6
8
  import * as Context from "effect/Context";
9
+ import * as Duration from "effect/Duration";
7
10
  import * as Effect from "effect/Effect";
11
+ import * as Fiber from "effect/Fiber";
8
12
  import * as FiberHandle from "effect/FiberHandle";
9
13
  import * as FiberMap from "effect/FiberMap";
14
+ import * as FiberSet from "effect/FiberSet";
10
15
  import * as FetchHttpClient from "effect/http/FetchHttpClient";
11
16
  import * as HttpBody from "effect/http/HttpBody";
12
17
  import * as HttpClient from "effect/http/HttpClient";
@@ -16,8 +21,8 @@ import * as Latch from "effect/Latch";
16
21
  import * as Layer from "effect/Layer";
17
22
  import * as Queue from "effect/Queue";
18
23
  import * as Random from "effect/Random";
24
+ import * as Schedule from "effect/Schedule";
19
25
  import * as Stream from "effect/Stream";
20
- import * as Clock from "effect/Clock";
21
26
  import * as Deferred from "effect/Deferred";
22
27
  import * as Exit from "effect/Exit";
23
28
  const emptyBlock = () => ({
@@ -443,7 +448,26 @@ const parseRealtimeChange = (data) => {
443
448
  };
444
449
  var RealtimeClient = class extends Context.Service()("@collective-intelligence/external-apps-client-sdk/RealtimeClient") {};
445
450
  /** The answer of the ticket route, as far as the client reads it. */
446
- const TicketAnswer = Schema.Struct({ streamUrl: Schema.String });
451
+ const TicketAnswer = Schema.Struct({
452
+ grantToken: Schema.optionalKey(Schema.String),
453
+ streamUrl: Schema.String
454
+ });
455
+ /** The most changes of one revalidate body: the Revalidate Route takes no more. */
456
+ const revalidateMaxChanges = 100;
457
+ /** The most revalidate bodies of one delivery that post at once: a slow body does not hold the others. */
458
+ const revalidateConcurrency = 4;
459
+ /** The longest wait of a delivery for its revalidate post before it calls the listeners (Q107). */
460
+ const revalidateWaitMilliseconds = 1e3;
461
+ /** The ticket route seals each grant token for 10 minutes (Q82). */
462
+ const grantLifetimeMilliseconds = 6e5;
463
+ /** The wait from a grant token to its renewal: the tab renews it 2 minutes before it expires (Q108). */
464
+ const grantRenewalMilliseconds = 48e4;
465
+ /**
466
+ * The waits after a failed renewal: 15 s, 30 s, then 60 s each time, and at
467
+ * least the `Retry-After` of the refusal. A retry that would come at or after
468
+ * the expiry of the token does not run (Q108).
469
+ */
470
+ const grantRetry = (current) => Schedule.min([Schedule.exponential("15 seconds"), Schedule.spaced("1 minute")]).pipe(Schedule.modifyDelay(({ duration, input }) => Effect.succeed(input._tag === "HttpClientError" ? Duration.max(duration, Duration.millis(retryAfterMilliseconds(input.response?.headers["retry-after"]) ?? 0)) : duration)), Schedule.while(({ duration, now }) => now + Duration.toMillis(duration) < (current()?.expiresAt ?? now)));
447
471
  /** The least wait before a delivery: a burst of changes joins one delivery. */
448
472
  const changeWindowMilliseconds = 250;
449
473
  /** The random extra wait, so that the tabs of many users refetch apart. */
@@ -483,6 +507,9 @@ const makeConnection = Effect.fn("RealtimeClient.makeConnection")(function* make
483
507
  const timers = yield* FiberMap.make();
484
508
  const links = yield* FiberMap.make();
485
509
  const delivery = yield* FiberHandle.make();
510
+ const revalidatePosts = yield* FiberSet.make();
511
+ /** The grant renewal of the current link. */
512
+ const renewal = yield* FiberHandle.make();
486
513
  const closed = yield* Latch.make();
487
514
  const registrations = /* @__PURE__ */ new Map();
488
515
  const resyncListeners = /* @__PURE__ */ new Set();
@@ -490,6 +517,11 @@ const makeConnection = Effect.fn("RealtimeClient.makeConnection")(function* make
490
517
  /** Per topic key, the latest change of each record, by last arrival. */
491
518
  const pending = /* @__PURE__ */ new Map();
492
519
  let resyncPending = false;
520
+ /** The grant of the last ticket: this tab's own token, in memory only. */
521
+ let grant;
522
+ /** Per topic key and record id, the changes to revalidate, by last arrival. */
523
+ const revalidations = /* @__PURE__ */ new Map();
524
+ let revalidateReset = false;
493
525
  let machine = initialMachineState(yield* page.visible);
494
526
  const send = (event) => Queue.offer(events, event);
495
527
  const topicsChanged = () => {
@@ -499,25 +531,64 @@ const makeConnection = Effect.fn("RealtimeClient.makeConnection")(function* make
499
531
  type: "topicsChanged"
500
532
  });
501
533
  };
502
- /** Delivers the pending changes, or the pending Resync, to the current listeners. */
503
- const deliver = Effect.sync(() => {
534
+ /**
535
+ * Posts the pending revalidation with the grant token, if the tab holds
536
+ * one that has not expired, and waits for the answers at most
537
+ * `revalidateWaitMilliseconds`. Its bodies post at once, and the wait
538
+ * covers all of them; a post that takes longer goes on after the wait.
539
+ * The Revalidate Route refuses an expired token, so the client does not
540
+ * post it, and the listeners do not wait.
541
+ */
542
+ const postRevalidation = Clock.clockWith((clock) => {
543
+ const now = clock.currentTimeMillisUnsafe();
544
+ const { revalidateUrl } = options;
545
+ const changes = [...revalidations.values()];
546
+ const reset = revalidateReset;
547
+ revalidations.clear();
548
+ revalidateReset = false;
549
+ if (revalidateUrl === void 0 || grant === void 0 || grant.expiresAt <= now || changes.length === 0 && !reset) return Effect.void;
550
+ const { token } = grant;
551
+ const parts = changes.length === 0 ? [changes] : Arr.chunksOf(changes, revalidateMaxChanges);
552
+ const post = (part, index) => http.execute(HttpClientRequest.post(revalidateUrl, { body: HttpBody.raw(JSON.stringify({
553
+ changes: part,
554
+ token,
555
+ ...reset && index === 0 && { reset }
556
+ }), { contentType: "application/json" }) })).pipe(Effect.flatMap(HttpClientResponse.filterStatusOk), Effect.catchTag("HttpClientError", (cause) => Effect.logWarning("The realtime revalidate post failed", cause)));
557
+ return FiberSet.run(revalidatePosts, Effect.forEach(parts, post, {
558
+ concurrency: revalidateConcurrency,
559
+ discard: true
560
+ }).pipe(Effect.provideService(FetchHttpClient.RequestInit, { credentials: "same-origin" }), Effect.provideService(HttpClient.TracerPropagationEnabled, false), surfaceDefects("The realtime revalidate post failed with a defect"))).pipe(Effect.flatMap((posts) => Effect.timeoutOption(Fiber.await(posts), revalidateWaitMilliseconds)), Effect.asVoid);
561
+ });
562
+ /**
563
+ * Delivers the pending changes, or the pending Resync, to the current
564
+ * listeners. With `revalidateUrl` it posts them first and calls the
565
+ * listeners after the answer, at most 1 s later (Q107): a listener that
566
+ * reads through the server cache then reads the revalidated entry.
567
+ */
568
+ const deliver = Effect.suspend(() => {
504
569
  const batches = [...pending];
570
+ const resynced = resyncPending;
505
571
  pending.clear();
506
- if (resyncPending) {
507
- resyncPending = false;
508
- for (const onResync of resyncListeners) onResync();
509
- return;
510
- }
511
- for (const [key, changes] of batches) {
512
- const batch = [...changes.values()];
513
- for (const onChanges of registrations.get(key)?.listeners ?? []) onChanges(batch);
514
- }
572
+ resyncPending = false;
573
+ return postRevalidation.pipe(Effect.andThen(Effect.sync(() => {
574
+ if (resynced) {
575
+ for (const onResync of resyncListeners) onResync();
576
+ return;
577
+ }
578
+ for (const [key, changes] of batches) {
579
+ const batch = [...changes.values()];
580
+ for (const onChanges of registrations.get(key)?.listeners ?? []) onChanges(batch);
581
+ }
582
+ })));
515
583
  });
584
+ /** Whether a change, a Resync or a revalidation waits for a delivery. */
585
+ const deliveryPending = () => pending.size > 0 || resyncPending || revalidations.size > 0 || revalidateReset;
516
586
  /**
517
587
  * The first change or Resync after a delivery schedules the next one; later
518
- * ones join it without delaying it.
588
+ * ones join it without delaying it. What arrives while a delivery waits
589
+ * for its post gets the next delivery, after this one.
519
590
  */
520
- const scheduleDelivery = FiberHandle.run(delivery, Random.nextIntBetween(0, changeJitterMilliseconds, { halfOpen: true }).pipe(Effect.flatMap((jitter) => Effect.sleep(changeWindowMilliseconds + jitter)), Effect.andThen(deliver), surfaceDefects("A realtime delivery failed with a defect")), { onlyIfMissing: true });
591
+ const scheduleDelivery = FiberHandle.run(delivery, Random.nextIntBetween(0, changeJitterMilliseconds, { halfOpen: true }).pipe(Effect.flatMap((jitter) => Effect.sleep(changeWindowMilliseconds + jitter)), Effect.andThen(deliver), Effect.repeat({ while: deliveryPending }), surfaceDefects("A realtime delivery failed with a defect")), { onlyIfMissing: true });
521
592
  /**
522
593
  * Replaces the pending changes with one Resync at the next delivery.
523
594
  * Without a Resync listener no refetch covers them, so they stay.
@@ -527,6 +598,12 @@ const makeConnection = Effect.fn("RealtimeClient.makeConnection")(function* make
527
598
  resyncPending = true;
528
599
  return scheduleDelivery;
529
600
  });
601
+ /** A `reset` or `access-changed` event: revalidate every topic of the token. */
602
+ const revalidateAll = Effect.suspend(() => {
603
+ if (options.revalidateUrl === void 0) return Effect.void;
604
+ revalidateReset = true;
605
+ return scheduleDelivery;
606
+ });
530
607
  const route = (change) => Effect.suspend(() => {
531
608
  const key = realtimeTopicKey(change.topic);
532
609
  if (!registrations.has(key)) return Effect.void;
@@ -534,6 +611,14 @@ const makeConnection = Effect.fn("RealtimeClient.makeConnection")(function* make
534
611
  changes.delete(change.id);
535
612
  changes.set(change.id, change);
536
613
  pending.set(key, changes);
614
+ if (options.revalidateUrl !== void 0) {
615
+ const revalidated = JSON.stringify([key, change.id]);
616
+ revalidations.delete(revalidated);
617
+ revalidations.set(revalidated, {
618
+ id: change.id,
619
+ topic: change.topic
620
+ });
621
+ }
537
622
  return scheduleDelivery;
538
623
  });
539
624
  const handle = (event) => {
@@ -542,10 +627,10 @@ const makeConnection = Effect.fn("RealtimeClient.makeConnection")(function* make
542
627
  const change = parseRealtimeChange(event.data);
543
628
  return change === void 0 ? Effect.void : route(change);
544
629
  }
545
- case "reset": return resync;
630
+ case "reset": return resync.pipe(Effect.andThen(revalidateAll));
546
631
  case "access-changed": return Effect.sync(() => {
547
632
  for (const onAccessChanged of accessListeners) onAccessChanged();
548
- }).pipe(Effect.andThen(options.resyncOnAccessChange ? resync : Effect.void));
633
+ }).pipe(Effect.andThen(options.resyncOnAccessChange ? resync : Effect.void), Effect.andThen(revalidateAll));
549
634
  default: return Effect.void;
550
635
  }
551
636
  };
@@ -573,14 +658,56 @@ const makeConnection = Effect.fn("RealtimeClient.makeConnection")(function* make
573
658
  default: return Effect.void;
574
659
  }
575
660
  };
576
- /** Mints the ticket of `link`; a failed ticket waits at least its `Retry-After`. */
577
- const ticket = Effect.fn("RealtimeClient.ticket")(function* ticket(link) {
661
+ /** The ticket answer for the topics of `link`, on the same origin. */
662
+ const requestTicket = (link) => Effect.suspend(() => {
578
663
  const topics = link.topics.flatMap((key) => {
579
664
  const registration = registrations.get(key);
580
665
  return registration === void 0 ? [] : [registration.topic];
581
666
  });
582
- const response = yield* http.execute(HttpClientRequest.post(options.ticketUrl, { body: HttpBody.raw(JSON.stringify({ topics }), { contentType: "application/json" }) }));
583
- const { streamUrl } = yield* HttpClientResponse.filterStatusOk(response).pipe(Effect.flatMap(HttpClientResponse.schemaBodyJson(TicketAnswer)));
667
+ return http.execute(HttpClientRequest.post(options.ticketUrl, { body: HttpBody.raw(JSON.stringify({ topics }), { contentType: "application/json" }) }));
668
+ }).pipe(Effect.flatMap(HttpClientResponse.filterStatusOk), Effect.flatMap(HttpClientResponse.schemaBodyJson(TicketAnswer)), Effect.provideService(FetchHttpClient.RequestInit, { credentials: "same-origin" }), Effect.provideService(HttpClient.TracerPropagationEnabled, false));
669
+ /**
670
+ * The stream URL of a ticket for `link`, and the grant of its token. The
671
+ * ticket route seals the token after the request starts, so the token is
672
+ * valid at least until 10 minutes after that start, on the clock of the
673
+ * tab.
674
+ */
675
+ const requestGrant = Effect.fnUntraced(function* requestGrant(link) {
676
+ const requestedAt = yield* Clock.currentTimeMillis;
677
+ const { grantToken, streamUrl } = yield* requestTicket(link);
678
+ return {
679
+ grant: grantToken === void 0 ? void 0 : {
680
+ expiresAt: requestedAt + grantLifetimeMilliseconds,
681
+ token: grantToken
682
+ },
683
+ streamUrl
684
+ };
685
+ });
686
+ /**
687
+ * Renews the grant token of `link` once: a new ticket for its topics
688
+ * brings a new token, which takes the place of the old one when it
689
+ * arrives (Q108). The stream stays open, and the ticket goes unused. A
690
+ * failed renewal keeps the old token.
691
+ */
692
+ const renewGrant = Effect.fn("RealtimeClient.renewGrant")(function* renewGrant(link) {
693
+ const { grant: renewed } = yield* requestGrant(link);
694
+ grant = renewed;
695
+ }, Effect.tapError((cause) => Effect.logWarning("The realtime grant renewal failed", cause)));
696
+ /**
697
+ * Renews the grant token of `link` 8 minutes after each token; a failed
698
+ * renewal tries again after the waits of `grantRetry`. When the token
699
+ * expires before the next try, the renewals of the link stop: its posts
700
+ * stop with the token, and the next ticket brings a new one.
701
+ */
702
+ const renewGrants = (link) => renewGrant(link).pipe(Effect.retry(grantRetry(() => grant)), Effect.delay(grantRenewalMilliseconds), Effect.forever, Effect.ignore({
703
+ log: "Warn",
704
+ message: "The realtime grant renewal stopped: the grant token expires before the next try"
705
+ }), surfaceDefects("The realtime grant renewal failed with a defect", { linkId: link.id }));
706
+ /** Mints the ticket of `link`; a failed ticket waits at least its `Retry-After`. */
707
+ const ticket = Effect.fn("RealtimeClient.ticket")(function* ticket(link) {
708
+ const { grant: renewed, streamUrl } = yield* requestGrant(link);
709
+ grant = renewed;
710
+ if (options.revalidateUrl !== void 0 && grant !== void 0) yield* FiberHandle.run(renewal, renewGrants(link));
584
711
  return {
585
712
  linkId: link.id,
586
713
  streamUrl,
@@ -589,7 +716,7 @@ const makeConnection = Effect.fn("RealtimeClient.makeConnection")(function* make
589
716
  }, (effect, link) => effect.pipe(Effect.catchTags({
590
717
  HttpClientError: (error) => failed(link, error, retryAfterMilliseconds(error.response?.headers["retry-after"])),
591
718
  SchemaError: (error) => failed(link, error)
592
- }), Effect.provideService(FetchHttpClient.RequestInit, { credentials: "same-origin" }), Effect.provideService(HttpClient.TracerPropagationEnabled, false)));
719
+ })));
593
720
  const schedule = (timer, milliseconds, event) => FiberMap.run(timers, timer, Effect.sleep(milliseconds).pipe(Effect.andThen(send(event)), surfaceDefects("A realtime timer failed with a defect", { timer })));
594
721
  const run = (command) => {
595
722
  switch (command.type) {
@@ -612,7 +739,7 @@ const makeConnection = Effect.fn("RealtimeClient.makeConnection")(function* make
612
739
  type: "streamEnded"
613
740
  }))));
614
741
  }
615
- case "disconnect": return FiberMap.remove(links, command.linkId);
742
+ case "disconnect": return FiberMap.remove(links, command.linkId).pipe(Effect.andThen(FiberHandle.clear(renewal)));
616
743
  case "resync": return resync;
617
744
  default: return Effect.void;
618
745
  }
@@ -638,6 +765,8 @@ const makeConnection = Effect.fn("RealtimeClient.makeConnection")(function* make
638
765
  machine = transition(machine, { type: "close" }).state;
639
766
  pending.clear();
640
767
  resyncPending = false;
768
+ revalidations.clear();
769
+ revalidateReset = false;
641
770
  }).pipe(Effect.andThen(closed.open)));
642
771
  return {
643
772
  closed: closed.await,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@collective-intelligence/external-apps-client-sdk",
3
- "version": "0.1.38",
3
+ "version": "0.1.39",
4
4
  "description": "Framework-neutral client for Collective Intelligence external applications.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -68,5 +68,5 @@
68
68
  "ultracite": "7.10.7",
69
69
  "vitest": "5.0.2"
70
70
  },
71
- "gitHead": "089c82bce0e7fb8319514787d67489aef7a0ee01"
71
+ "gitHead": "f94130c9ae9ded5a9ac66b2a2997fc992b6f3712"
72
72
  }