@collective-intelligence/external-apps-client-sdk 0.1.37 → 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 +49 -6
- package/dist/effect.d.ts +13 -3
- package/dist/effect.js +3 -3
- package/dist/{index-BqdhzpcZ.d.ts → index-DdmAyX_o.d.ts} +8 -2
- package/dist/index.d.ts +3 -3
- package/dist/index.js +28 -25
- package/dist/{resources-tBGn1Exi.d.ts → resources-Bz9fYAWz.d.ts} +33 -2
- package/dist/{resources-DT-KqPTd.js → resources-C87ZTpv3.js} +5 -1
- package/dist/resources.d.ts +2 -2
- package/dist/resources.js +2 -2
- package/dist/{service-C7kswu6e.js → service-BGqbpJD2.js} +34 -8
- package/dist/{service-CxUyG8yF.js → service-DAM3rze2.js} +153 -24
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -221,15 +221,24 @@ correlation IDs.
|
|
|
221
221
|
A File field holds files of a CI entity. The browser sends the file bytes
|
|
222
222
|
straight to storage; they never pass through CI or a BFF:
|
|
223
223
|
|
|
224
|
-
1. `upload({ field, filename, mimeType })` requests a File upload for
|
|
225
|
-
File field. The definition must
|
|
226
|
-
otherwise the call fails with
|
|
227
|
-
|
|
224
|
+
1. `upload({ field, filename, mimeType, size })` requests a File upload for
|
|
225
|
+
one File field; `size` is the file size in bytes. The definition must
|
|
226
|
+
declare `capabilities.upload: true`; otherwise the call fails with
|
|
227
|
+
`capability_not_supported` and sends nothing. CI refuses a `size` over the
|
|
228
|
+
field's `maxBytes` or the platform limit with `invalid_request` and
|
|
229
|
+
`details.reason: "file_too_large"`.
|
|
230
|
+
2. PUT the bytes to the returned `url` with the returned `headers`. Where the
|
|
231
|
+
storage can, the URL takes only a body of the declared size.
|
|
228
232
|
3. Write the entity with `{ upload: uploadId }` for that File field key.
|
|
229
233
|
|
|
230
234
|
```ts
|
|
231
235
|
const slot = await leads.upload(
|
|
232
|
-
{
|
|
236
|
+
{
|
|
237
|
+
field: "resume",
|
|
238
|
+
filename: file.name,
|
|
239
|
+
mimeType: file.type,
|
|
240
|
+
size: file.size
|
|
241
|
+
},
|
|
233
242
|
{ signal }
|
|
234
243
|
)
|
|
235
244
|
if (slot.ok) {
|
|
@@ -337,13 +346,44 @@ const unsubscribe = realtime.subscribe(
|
|
|
337
346
|
`lastEventId`; `close()` ends the connection and the page listeners.
|
|
338
347
|
- `createRealtimeClient` runs on the realtime service of `./effect`, in a
|
|
339
348
|
runtime of its own. Its listeners and callbacks run in the same call as the
|
|
340
|
-
page event, stream event or timer that causes them
|
|
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
|
|
341
352
|
`onAccessChanged` only, never `onReset`.
|
|
342
353
|
- A failed ticket request logs a warning, and a failed connection step logs an
|
|
343
354
|
error, through the Effect logger (the console by default). The connection
|
|
344
355
|
goes on: the backoff or the ping timeout reconnects. The warning shows a
|
|
345
356
|
relative `ticketUrl` on the placeholder origin `realtime-ticket.invalid`;
|
|
346
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.
|
|
347
387
|
|
|
348
388
|
### Realtime on Effect
|
|
349
389
|
|
|
@@ -386,6 +426,9 @@ Effect.runFork(
|
|
|
386
426
|
visible. Provide `FetchHttpClient.Fetch` to use a different `fetch`.
|
|
387
427
|
- `HttpClient` resolves a relative `ticketUrl` against `location`. Outside a
|
|
388
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`.
|
|
389
432
|
- Timers use `Clock` and the jitter uses `Random`, so a test can use `TestClock`
|
|
390
433
|
and a fixed `Random`.
|
|
391
434
|
|
package/dist/effect.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { $t as
|
|
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-
|
|
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 {
|
|
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-
|
|
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
|
|
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
|
|
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-
|
|
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 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 };
|
|
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
|
+
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 {
|
|
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-
|
|
3
|
-
import { t as createResourceClient } from "./resources-
|
|
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
|
|
386
|
-
* a relative URL against `location`,
|
|
387
|
-
* `ticketUrl` as the app gave it before
|
|
388
|
-
* resolve it on a base of its own. So
|
|
389
|
-
*
|
|
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
|
|
392
|
-
/** `
|
|
393
|
-
const
|
|
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(
|
|
396
|
+
return new URL(url, placeholderOrigin).href;
|
|
396
397
|
} catch {
|
|
397
|
-
return
|
|
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
|
|
403
|
-
*
|
|
404
|
-
*
|
|
405
|
-
* types; nothing here
|
|
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,
|
|
408
|
-
const
|
|
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
|
|
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:
|
|
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
|
])));
|
|
@@ -921,7 +921,7 @@ interface ResourceClient<Entity, Create = Entity, Update = Partial<Entity>> {
|
|
|
921
921
|
readonly update: (input: ResourceMutationInput<Update>, options?: ResourceRequestOptions) => Promise<ResourceResult<ResourceRecord<Entity>>>;
|
|
922
922
|
}
|
|
923
923
|
/** Common entity operations. Generic resource lifecycle/cursor APIs remain separate. */
|
|
924
|
-
type EntityOperation = "list_members" | "list" | "get" | "create" | "update" | "delete" | "upload";
|
|
924
|
+
type EntityOperation = "list_members" | "list" | "get" | "create" | "update" | "delete" | "restore" | "upload";
|
|
925
925
|
type EntityListQuery = Omit<ResourceListQuery, "pagination" | "includeDeleted"> & Readonly<{
|
|
926
926
|
pagination: Extract<ResourcePagination, {
|
|
927
927
|
mode: "page";
|
|
@@ -939,11 +939,20 @@ type EntityUpdateInput<Patch> = ResourceMutationInput<Patch> & Readonly<{
|
|
|
939
939
|
type EntityDeleteInput = ResourceLifecycleInput & Readonly<{
|
|
940
940
|
idempotencyKey: IdempotencyKey;
|
|
941
941
|
}>;
|
|
942
|
+
/** A restore of a soft-deleted record at the revision its delete gave. */
|
|
943
|
+
type EntityRestoreInput = EntityDeleteInput;
|
|
942
944
|
/** A File upload request for one File field of the entity schema. */
|
|
943
945
|
type EntityUploadInput = Readonly<{
|
|
944
946
|
field: string;
|
|
945
947
|
filename: string;
|
|
946
948
|
mimeType: string;
|
|
949
|
+
/**
|
|
950
|
+
* The file size in bytes, a non-negative integer such as `File.size`. CI
|
|
951
|
+
* refuses a slot over the field's limit with `invalid_request` and
|
|
952
|
+
* `details.reason: "file_too_large"`; storage may refuse a PUT of another
|
|
953
|
+
* size.
|
|
954
|
+
*/
|
|
955
|
+
size: number;
|
|
947
956
|
}>;
|
|
948
957
|
/** PUT the file bytes to `url` with `headers`; then write `{ upload: uploadId }`. */
|
|
949
958
|
type EntityUploadSlot = Readonly<{
|
|
@@ -998,6 +1007,8 @@ type EntityRequest<Create = unknown, Patch = unknown> = EntityRequestIdentity &
|
|
|
998
1007
|
}> & EntityUpdateInput<Patch>) | (Readonly<{
|
|
999
1008
|
operation: "delete";
|
|
1000
1009
|
}> & EntityDeleteInput) | (Readonly<{
|
|
1010
|
+
operation: "restore";
|
|
1011
|
+
}> & EntityRestoreInput) | (Readonly<{
|
|
1001
1012
|
operation: "upload";
|
|
1002
1013
|
}> & EntityUploadInput));
|
|
1003
1014
|
type EntityOperationResult<Value, Operation extends EntityOperation> = Operation extends "list_members" ? EntityPage<EntityMemberValue> : Operation extends "list" ? EntityPage<Value> : Operation extends "upload" ? EntityUploadSlot : ResourceRecord<Value>;
|
|
@@ -1022,6 +1033,13 @@ interface EntityClient<Value, Create = Value, Patch = Partial<Value>> {
|
|
|
1022
1033
|
readonly create: (input: EntityCreateInput<Create>) => Promise<ResourceResult<ResourceRecord<Value>>>;
|
|
1023
1034
|
readonly update: (input: EntityUpdateInput<Patch>) => Promise<ResourceResult<ResourceRecord<Value>>>;
|
|
1024
1035
|
readonly delete: (input: EntityDeleteInput) => Promise<ResourceResult<ResourceRecord<Value>>>;
|
|
1036
|
+
/**
|
|
1037
|
+
* Makes a soft-deleted record live again; requires the `restore`
|
|
1038
|
+
* capability. A stale revision answers `conflict`; a live record answers
|
|
1039
|
+
* itself unchanged. A connector record whose delete also removed its
|
|
1040
|
+
* remote ref answers `conflict` and stays deleted.
|
|
1041
|
+
*/
|
|
1042
|
+
readonly restore: (input: EntityRestoreInput) => Promise<ResourceResult<ResourceRecord<Value>>>;
|
|
1025
1043
|
/** A single-use File upload slot; requires the `upload` capability. */
|
|
1026
1044
|
readonly upload: (input: EntityUploadInput, options?: ResourceRequestOptions) => Promise<ResourceResult<EntityUploadSlot>>;
|
|
1027
1045
|
}
|
|
@@ -1047,6 +1065,8 @@ declare const isEntityReadLimitError: (error: ResourceError) => error is Resourc
|
|
|
1047
1065
|
}>;
|
|
1048
1066
|
/** Common entity wire codec; transport and persistence remain with their owners. */
|
|
1049
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>;
|
|
1050
1070
|
type ResourceFailure = CiError$1 | CiTransportError;
|
|
1051
1071
|
/** The entity client of one Resource Definition for `./effect`. */
|
|
1052
1072
|
type ResourceEntityClient<Value, Create, Patch> = Readonly<{
|
|
@@ -1060,6 +1080,7 @@ type ResourceEntityClient<Value, Create, Patch> = Readonly<{
|
|
|
1060
1080
|
create: (input: EntityCreateInput<Create>) => Effect.Effect<ResourceRecord<Value>, ResourceFailure>;
|
|
1061
1081
|
update: (input: EntityUpdateInput<Patch>) => Effect.Effect<ResourceRecord<Value>, ResourceFailure>;
|
|
1062
1082
|
delete: (input: EntityDeleteInput) => Effect.Effect<ResourceRecord<Value>, ResourceFailure>;
|
|
1083
|
+
restore: (input: EntityRestoreInput) => Effect.Effect<ResourceRecord<Value>, ResourceFailure>;
|
|
1063
1084
|
upload: (input: EntityUploadInput) => Effect.Effect<EntityUploadSlot, ResourceFailure>;
|
|
1064
1085
|
}>;
|
|
1065
1086
|
type ResourcesValue = Readonly<{
|
|
@@ -1141,6 +1162,16 @@ type EntityHttpTransportOptions = Readonly<{
|
|
|
1141
1162
|
authentication: ProxyAuthentication;
|
|
1142
1163
|
fetch?: ClientFetch;
|
|
1143
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;
|
|
1144
1175
|
/**
|
|
1145
1176
|
* The Vanilla Facade of the entity HTTP adapter, in a runtime of its own;
|
|
1146
1177
|
* `close` disposes it.
|
|
@@ -1148,4 +1179,4 @@ type EntityHttpTransportOptions = Readonly<{
|
|
|
1148
1179
|
declare const createEntityHttpTransport: (options: EntityHttpTransportOptions) => EntityTransport & Readonly<{
|
|
1149
1180
|
close: () => Promise<void>;
|
|
1150
1181
|
}>;
|
|
1151
|
-
export {
|
|
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 {
|
|
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
|
/**
|
|
@@ -48,6 +48,10 @@ const createCommonEntityClient = (options) => {
|
|
|
48
48
|
parentId,
|
|
49
49
|
query
|
|
50
50
|
}, requestOptions),
|
|
51
|
+
restore: (input) => execute({
|
|
52
|
+
...input,
|
|
53
|
+
operation: "restore"
|
|
54
|
+
}),
|
|
51
55
|
update: (input) => execute({
|
|
52
56
|
...input,
|
|
53
57
|
operation: "update"
|
package/dist/resources.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { $ as
|
|
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 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 };
|
|
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
|
+
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,
|
|
2
|
-
import { t as createResourceClient } from "./resources-
|
|
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 };
|
|
@@ -8124,10 +8124,19 @@ const createEntityProtocol = (definition) => {
|
|
|
8124
8124
|
id: identifier,
|
|
8125
8125
|
idempotencyKey: operationKey
|
|
8126
8126
|
}),
|
|
8127
|
+
requestSchema(definition, "restore", {
|
|
8128
|
+
expectedRevision: identifier,
|
|
8129
|
+
id: identifier,
|
|
8130
|
+
idempotencyKey: operationKey
|
|
8131
|
+
}),
|
|
8127
8132
|
requestSchema(definition, "upload", {
|
|
8128
8133
|
field: uploadText,
|
|
8129
8134
|
filename: uploadText,
|
|
8130
|
-
mimeType: uploadText
|
|
8135
|
+
mimeType: uploadText,
|
|
8136
|
+
size: {
|
|
8137
|
+
minimum: 0,
|
|
8138
|
+
type: "integer"
|
|
8139
|
+
}
|
|
8131
8140
|
})
|
|
8132
8141
|
]
|
|
8133
8142
|
});
|
|
@@ -8279,6 +8288,7 @@ const createEntityProtocol = (definition) => {
|
|
|
8279
8288
|
get: validateRecord,
|
|
8280
8289
|
list: coherentPage(validatePage),
|
|
8281
8290
|
list_members: coherentPage(validateMemberPage),
|
|
8291
|
+
restore: validateRecord,
|
|
8282
8292
|
update: validateRecord,
|
|
8283
8293
|
upload: validateUploadSlot
|
|
8284
8294
|
};
|
|
@@ -8371,11 +8381,20 @@ const encode = (request) => {
|
|
|
8371
8381
|
method: "POST",
|
|
8372
8382
|
path: `/records/${encodeURIComponent(request.id)}/soft-delete`
|
|
8373
8383
|
};
|
|
8384
|
+
case "restore": return {
|
|
8385
|
+
body: JSON.stringify({
|
|
8386
|
+
expectedRevision: request.expectedRevision,
|
|
8387
|
+
idempotencyKey: request.idempotencyKey
|
|
8388
|
+
}),
|
|
8389
|
+
method: "POST",
|
|
8390
|
+
path: `/records/${encodeURIComponent(request.id)}/restore`
|
|
8391
|
+
};
|
|
8374
8392
|
case "upload": return {
|
|
8375
8393
|
body: JSON.stringify({
|
|
8376
8394
|
field: request.field,
|
|
8377
8395
|
filename: request.filename,
|
|
8378
|
-
mimeType: request.mimeType
|
|
8396
|
+
mimeType: request.mimeType,
|
|
8397
|
+
size: request.size
|
|
8379
8398
|
}),
|
|
8380
8399
|
method: "POST",
|
|
8381
8400
|
path: "/uploads"
|
|
@@ -8411,11 +8430,13 @@ const envelopeOf = (response, result) => {
|
|
|
8411
8430
|
return result;
|
|
8412
8431
|
};
|
|
8413
8432
|
/**
|
|
8414
|
-
* The entity HTTP adapter of one destination
|
|
8415
|
-
*
|
|
8416
|
-
*
|
|
8417
|
-
*
|
|
8418
|
-
*
|
|
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`.
|
|
8419
8440
|
*/
|
|
8420
8441
|
const makeEntityHttpExecute = (options) => {
|
|
8421
8442
|
const { destination, authentication } = options;
|
|
@@ -8529,6 +8550,7 @@ const capabilityOf = {
|
|
|
8529
8550
|
get: "get",
|
|
8530
8551
|
list: "search",
|
|
8531
8552
|
list_members: "search",
|
|
8553
|
+
restore: "restore",
|
|
8532
8554
|
update: "update",
|
|
8533
8555
|
upload: "upload"
|
|
8534
8556
|
};
|
|
@@ -8736,6 +8758,10 @@ const makeResources = (executeOf, requestId) => Resources.of({ bind: (definition
|
|
|
8736
8758
|
parentId,
|
|
8737
8759
|
query
|
|
8738
8760
|
}, id)),
|
|
8761
|
+
restore: (input) => call((id) => core.execute({
|
|
8762
|
+
...input,
|
|
8763
|
+
operation: "restore"
|
|
8764
|
+
}, id)),
|
|
8739
8765
|
update: (input) => call((id) => core.execute({
|
|
8740
8766
|
...input,
|
|
8741
8767
|
operation: "update"
|
|
@@ -8784,4 +8810,4 @@ const makeLegacy = (options) => LegacyResources.of({ bind: (definition) => {
|
|
|
8784
8810
|
const layerLegacy = (options) => Layer.succeed(LegacyResources, makeLegacy(options));
|
|
8785
8811
|
/** `layerLegacy` with options that Effect `Config` reads. */
|
|
8786
8812
|
const layerLegacyConfig = (config) => Layer.unwrap(Effect.map(Config.unwrap(config), layerLegacy));
|
|
8787
|
-
export {
|
|
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 {
|
|
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({
|
|
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
|
-
/**
|
|
503
|
-
|
|
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
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
const
|
|
513
|
-
|
|
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
|
-
/**
|
|
577
|
-
const
|
|
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
|
-
|
|
583
|
-
|
|
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
|
-
})
|
|
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.
|
|
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": "
|
|
71
|
+
"gitHead": "f94130c9ae9ded5a9ac66b2a2997fc992b6f3712"
|
|
72
72
|
}
|