js-bao-wss-client 2.0.4 → 2.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/README.md +242 -39
  2. package/dist/JsBaoClient.d.ts +293 -41
  3. package/dist/JsBaoClient.d.ts.map +1 -1
  4. package/dist/JsBaoClient.js +241 -5
  5. package/dist/JsBaoClient.js.map +1 -1
  6. package/dist/api/blobBucketsApi.d.ts +29 -1
  7. package/dist/api/blobBucketsApi.d.ts.map +1 -1
  8. package/dist/api/blobBucketsApi.js +5 -3
  9. package/dist/api/blobBucketsApi.js.map +1 -1
  10. package/dist/api/collectionsApi.d.ts +9 -1
  11. package/dist/api/collectionsApi.d.ts.map +1 -1
  12. package/dist/api/collectionsApi.js.map +1 -1
  13. package/dist/api/cronTriggersApi.d.ts +19 -6
  14. package/dist/api/cronTriggersApi.d.ts.map +1 -1
  15. package/dist/api/cronTriggersApi.js.map +1 -1
  16. package/dist/api/databaseTypeConfigsApi.d.ts +6 -4
  17. package/dist/api/databaseTypeConfigsApi.d.ts.map +1 -1
  18. package/dist/api/databaseTypeConfigsApi.js.map +1 -1
  19. package/dist/api/databasesApi.d.ts +83 -69
  20. package/dist/api/databasesApi.d.ts.map +1 -1
  21. package/dist/api/databasesApi.js +10 -0
  22. package/dist/api/databasesApi.js.map +1 -1
  23. package/dist/api/documentsApi.d.ts +71 -12
  24. package/dist/api/documentsApi.d.ts.map +1 -1
  25. package/dist/api/documentsApi.js +56 -20
  26. package/dist/api/documentsApi.js.map +1 -1
  27. package/dist/api/geminiApi.d.ts.map +1 -1
  28. package/dist/api/geminiApi.js +11 -14
  29. package/dist/api/geminiApi.js.map +1 -1
  30. package/dist/api/groupsApi.d.ts +20 -4
  31. package/dist/api/groupsApi.d.ts.map +1 -1
  32. package/dist/api/groupsApi.js +9 -1
  33. package/dist/api/groupsApi.js.map +1 -1
  34. package/dist/api/notificationsApi.d.ts +134 -0
  35. package/dist/api/notificationsApi.d.ts.map +1 -0
  36. package/dist/api/notificationsApi.js +52 -0
  37. package/dist/api/notificationsApi.js.map +1 -0
  38. package/dist/api/operationDefinition.d.ts +279 -0
  39. package/dist/api/operationDefinition.d.ts.map +1 -0
  40. package/dist/api/operationDefinition.js +47 -0
  41. package/dist/api/operationDefinition.js.map +1 -0
  42. package/dist/api/resourceMetadataApi.d.ts +182 -0
  43. package/dist/api/resourceMetadataApi.d.ts.map +1 -0
  44. package/dist/api/resourceMetadataApi.js +56 -0
  45. package/dist/api/resourceMetadataApi.js.map +1 -0
  46. package/dist/browser.umd.js +554 -59
  47. package/dist/browser.umd.js.map +1 -1
  48. package/dist/errors.d.ts +34 -1
  49. package/dist/errors.d.ts.map +1 -1
  50. package/dist/errors.js +56 -0
  51. package/dist/errors.js.map +1 -1
  52. package/dist/internal/authController.d.ts +10 -0
  53. package/dist/internal/authController.d.ts.map +1 -1
  54. package/dist/internal/authController.js +14 -2
  55. package/dist/internal/authController.js.map +1 -1
  56. package/dist/internal/httpClient.d.ts +8 -0
  57. package/dist/internal/httpClient.d.ts.map +1 -1
  58. package/dist/internal/httpClient.js +34 -5
  59. package/dist/internal/httpClient.js.map +1 -1
  60. package/package.json +6 -2
@@ -20,6 +20,7 @@ import { UsersAPI } from "./api/usersApi";
20
20
  import { DatabasesAPI } from "./api/databasesApi";
21
21
  import { GroupsAPI } from "./api/groupsApi";
22
22
  import { CronTriggersAPI } from "./api/cronTriggersApi";
23
+ import { ResourceMetadataAPI } from "./api/resourceMetadataApi";
23
24
  import { RuleSetsAPI } from "./api/ruleSetsApi";
24
25
  import { BlobBucketsAPI } from "./api/blobBucketsApi";
25
26
  import { GroupTypeConfigsAPI } from "./api/groupTypeConfigsApi";
@@ -27,7 +28,8 @@ import { CollectionTypeConfigsAPI } from "./api/collectionTypeConfigsApi";
27
28
  import { DatabaseTypeConfigsAPI } from "./api/databaseTypeConfigsApi";
28
29
  import { CollectionsAPI } from "./api/collectionsApi";
29
30
  import { InvitationsAPI } from "./api/invitationsApi";
30
- export { JsBaoError, isJsBaoError } from "./errors";
31
+ import { NotificationsAPI } from "./api/notificationsApi";
32
+ export { JsBaoError, isJsBaoError, JsBaoApiError, isJsBaoApiError, JsBaoNetworkError, isJsBaoNetworkError, } from "./errors";
31
33
  export type { JsBaoErrorCode } from "./errors";
32
34
  export { AuthError, AUTH_CODES } from "./internal/authController";
33
35
  export type { AuthCode } from "./internal/authController";
@@ -35,7 +37,7 @@ export type { DocumentInfo, DocumentPermissionEntry, DocumentInvitation, Documen
35
37
  export type { UserProfile, SharedDocument, SharedDocumentListResult, SharedDocumentsOptions, OwnedDocumentsOptions, } from "./api/meApi";
36
38
  export type { SessionInfo } from "./api/sessionApi";
37
39
  export type { BasicUserInfo, BatchUserProfile } from "./api/usersApi";
38
- export type { DatabaseInfo, DatabasePermissionEntry, DatabaseGroupPermissionEntry, GrantDatabaseGroupPermissionParams, DatabaseOwnershipTransferResult, DatabaseOperationInfo, AddManagerParams, GrantPermissionParams, CsvImportOptions, CsvImportProgress, CsvImportResult, DatabaseChangeEvent, DatabaseChangePayload, DatabaseSubscribeOptions, ListDatabasesOptions, } from "./api/databasesApi";
40
+ export type { DatabaseInfo, DatabasePermissionEntry, DatabaseGroupPermissionEntry, GrantDatabaseGroupPermissionParams, DatabaseOwnershipTransferResult, DatabaseOperationInfo, AddManagerParams, GrantPermissionParams, CsvImportOptions, CsvImportProgress, CsvImportResult, CelContextResult, ExecuteOperationOptions, DatabaseChangeEvent, DatabaseChangePayload, DatabaseSubscribeOptions, ListDatabasesOptions, OperationType, OperationFilter, QueryDefinition, MutationOperation, MutationDefinition, CountDefinition, AggregateOperation, AggregateDefinition, PipelineStep, PipelineDefinition, ApplyToQuerySource, ApplyToQueryAction, ApplyToQueryDefinition, OperationDefinition, CreateOperationParams, UpdateOperationParams, } from "./api/databasesApi";
39
41
  export type { GroupInfo, GroupMemberInfo, GroupMembershipInfo, GroupDocumentInfo, GroupDatabaseInfo, ListUserMembershipsOptions, PaginatedResult, DirectGroupAdd, DeferredGroupAdd, GroupAddMemberResult, } from "./api/groupsApi";
40
42
  export type { CollectionInfo, CollectionDocumentInfo, CollectionGroupPermissionInfo, CollectionMemberInfo, CollectionAccessInfo, DocumentCollectionInfo, AddCollectionMemberParams, DirectCollectionAdd, DeferredCollectionAdd, CollectionAddMemberResult, PendingCollectionInvitationEntry, } from "./api/collectionsApi";
41
43
  export type { RuleSetInfo, RuleSetSchema, RuleSetTestResult, RuleSetDebugResult, TraceEntry, TriggerDefInfo, ModelRulesInfo, } from "./api/ruleSetsApi";
@@ -60,12 +62,15 @@ export type { SessionAPI } from "./api/sessionApi";
60
62
  export type { UsersAPI } from "./api/usersApi";
61
63
  export type { GroupsAPI } from "./api/groupsApi";
62
64
  export type { RuleSetsAPI } from "./api/ruleSetsApi";
63
- export type { BlobBucketsAPI, BlobBucketInfo, BlobBucketTtlTier, BlobBucketPreset, BlobBucketAccessPolicy, CreateBlobBucketParams, UpdateBlobBucketParams, BlobInfo, BlobUploadParams, BucketBlobUploadResult, BucketBlobListResult, BlobListOptions, BlobSignedUrlResult, } from "./api/blobBucketsApi";
65
+ export type { NotificationsAPI, NotificationInfo, NotificationListOptions, NotificationListResult, NotificationSendResult, SendNotificationParams, PushDeviceInfo, RegisterPushDeviceParams, } from "./api/notificationsApi";
66
+ export type { BlobBucketsAPI, BlobBucketInfo, BlobBucketTtlTier, BlobBucketPreset, BlobBucketAccessPolicy, CreateBlobBucketParams, UpdateBlobBucketParams, BlobInfo, BlobUploadParams, BucketBlobUploadResult, BucketBlobListResult, BlobListOptions, BlobSignedUrlResult, BatchBlobDeleteResult, } from "./api/blobBucketsApi";
64
67
  export type { GroupTypeConfigsAPI } from "./api/groupTypeConfigsApi";
65
68
  export type { CollectionTypeConfigsAPI } from "./api/collectionTypeConfigsApi";
66
69
  export type { DatabaseTypeConfigsAPI } from "./api/databaseTypeConfigsApi";
67
70
  export type { CronTriggersAPI } from "./api/cronTriggersApi";
68
71
  export type { CronTriggerInfo, CreateCronTriggerParams, UpdateCronTriggerParams, CronTriggerListResult, } from "./api/cronTriggersApi";
72
+ export type { ResourceMetadataAPI } from "./api/resourceMetadataApi";
73
+ export type { ResourceMetadataReadResult, ResourceMetadataWriteResult, ResourceMetadataBatchRequestItem, ResourceMetadataBatchParams, ResourceMetadataBatchCategoryResult, ResourceMetadataBatchResourceResult, ResourceMetadataBatchResult, ResourceMetadataListEntry, ResourceMetadataListResult, ResourceMetadataDeleteResult, } from "./api/resourceMetadataApi";
69
74
  export interface AnalyticsAutoEventsOptions {
70
75
  dailyAuth?: boolean;
71
76
  returnActive?: boolean;
@@ -92,13 +97,13 @@ export interface AnalyticsAutoEventsOptions {
92
97
  };
93
98
  }
94
99
  export type { GeminiRole, GeminiContentPart, GeminiMessage, GeminiPromptOptions, GeminiGenerateOptions, GeminiGenerateResult, GeminiModelSummary, GeminiStructuredOutput, GeminiGenerateRawOptions, } from "./api/geminiApi";
95
- export interface IntegrationCallRequest {
100
+ export interface IntegrationCallRequest<TReq = any> {
96
101
  integrationKey: string;
97
102
  method?: string;
98
103
  path?: string;
99
104
  query?: Record<string, any>;
100
105
  headers?: Record<string, string>;
101
- body?: any;
106
+ body?: TReq;
102
107
  }
103
108
  export interface IntegrationCallResponse<T = any> {
104
109
  status: number;
@@ -109,11 +114,29 @@ export interface IntegrationCallResponse<T = any> {
109
114
  errorCode?: string;
110
115
  }
111
116
  export interface IntegrationsAPI {
112
- call<T = any>(request: IntegrationCallRequest): Promise<IntegrationCallResponse<T>>;
117
+ /**
118
+ * Call an integration's proxy endpoint.
119
+ *
120
+ * The optional generics are additive (issue #1542). `TRes` types the response
121
+ * body and is **first** to preserve the meaning of existing single-arg
122
+ * `call<MyResponse>()` call sites; `TReq` types the request `body`. Both
123
+ * default to today's untyped `any`, so untyped callers are unaffected.
124
+ */
125
+ call<TRes = any, TReq = any>(request: IntegrationCallRequest<TReq>): Promise<IntegrationCallResponse<TRes>>;
113
126
  }
114
127
  export interface WorkflowsAPI {
115
- /** Start a workflow and return the run information */
116
- start(options: StartWorkflowOptions): Promise<StartWorkflowResult>;
128
+ /**
129
+ * Start a workflow and return the run information.
130
+ *
131
+ * The optional generic `I` types the `input` payload (issue #1442). It is
132
+ * additive and defaults to today's untyped `Record<string, any>`, so existing
133
+ * callers that pass no type argument are unaffected. The generated per-workflow
134
+ * `<key>(client)` factory (`primitive workflows codegen`) supplies it from the
135
+ * workflow's `inputSchema`.
136
+ */
137
+ start<I = Record<string, any>>(options: Omit<StartWorkflowOptions, "input"> & {
138
+ input?: I;
139
+ }): Promise<StartWorkflowResult>;
117
140
  /**
118
141
  * Synchronously invoke a workflow and wait for the final result.
119
142
  *
@@ -126,12 +149,57 @@ export interface WorkflowsAPI {
126
149
  * including engine failure and timeout — failure surfaces as
127
150
  * `status: "failed"` (or `"timeout"` / `"terminated"`), not a thrown
128
151
  * error. Network / transport errors still reject as usual.
152
+ *
153
+ * The optional generics `I` (input) and `O` (`output`) type the payload and
154
+ * the result envelope (issue #1442). Both are additive and default to today's
155
+ * untyped `Record<string, any>` / `any`, so existing callers are unaffected.
156
+ * The generated per-workflow `<key>(client)` factory supplies them from the
157
+ * workflow's `inputSchema`/`outputSchema`.
129
158
  */
130
- runSync(options: RunSyncWorkflowOptions): Promise<RunSyncWorkflowResult>;
131
- /** Get the status of a workflow run. If contextDocId is not provided, uses the user's root document. */
132
- getStatus(options: GetWorkflowStatusOptions): Promise<WorkflowStatusResult>;
133
- /** Terminate a running workflow. If contextDocId is not provided, uses the user's root document. */
134
- terminate(options: TerminateWorkflowOptions): Promise<WorkflowStatusResult>;
159
+ runSync<I = Record<string, any>, O = any>(options: Omit<RunSyncWorkflowOptions, "input"> & {
160
+ input?: I;
161
+ }): Promise<RunSyncWorkflowResult<O>>;
162
+ /**
163
+ * Get the status of a workflow run. If contextDocId is not provided, uses the
164
+ * user's root document.
165
+ *
166
+ * The optional generic `O` types the result envelope's `output` (issue #1512).
167
+ * It is additive and defaults to today's untyped `any`, so existing callers
168
+ * are unaffected. The generated per-workflow `<key>(client)` factory supplies
169
+ * it from the workflow's `outputSchema`.
170
+ */
171
+ getStatus<O = any>(options: GetWorkflowStatusOptions): Promise<WorkflowStatusResult<O>>;
172
+ /**
173
+ * Wait for an async workflow run to reach a terminal state, then resolve
174
+ * `{ status, output?, error? }` (#1443).
175
+ *
176
+ * Event-driven: it subscribes to the existing `workflowStatus` WebSocket
177
+ * frame and issues no polling. One reconcile fetch runs immediately after
178
+ * subscribing to close the started-before-subscribed race (the terminal
179
+ * frame is only delivered to live connections and is not replayed). On a WS
180
+ * reconnect it re-runs that single reconcile fetch — still no interval timer.
181
+ *
182
+ * Resolves on every terminal state, including workflow failure
183
+ * (`status: "failed"`) — a failing run does NOT reject. It also treats a run
184
+ * with `endedAt` set as terminal regardless of its `status`, so it is robust
185
+ * to the stale-status bug (#1388) rather than hanging on it.
186
+ *
187
+ * Rejects only on two conditions: the reconcile fetch 404s (unknown or
188
+ * not-owned `runId` → `NOT_FOUND`), or `timeoutMs` elapses
189
+ * (`WORKFLOW_WAIT_TIMEOUT`). Both paths remove the listener and clear the
190
+ * timer, so there is no leak.
191
+ */
192
+ waitFor(runId: string, options?: WaitForWorkflowOptions): Promise<WaitForWorkflowResult>;
193
+ /**
194
+ * Terminate a running workflow. If contextDocId is not provided, uses the
195
+ * user's root document.
196
+ *
197
+ * The optional generic `O` types the result envelope's `output` (issue #1512)
198
+ * — a terminated run can still carry partial output. Additive, defaults to
199
+ * `any`. The generated per-workflow factory emits a `terminate` member that
200
+ * binds this generic to the workflow's `<Key>Output` (issue #1543).
201
+ */
202
+ terminate<O = any>(options: TerminateWorkflowOptions): Promise<WorkflowStatusResult<O>>;
135
203
  /** List workflow runs for the current user */
136
204
  listRuns(options?: ListWorkflowRunsOptions): Promise<ListWorkflowRunsResult>;
137
205
  /** List step runs for a specific workflow run. The run must have been started by the current user. */
@@ -142,28 +210,48 @@ export interface WorkflowsAPI {
142
210
  confirmApply(options: ConfirmApplyOptions): Promise<ConfirmApplyResult>;
143
211
  /** Release a claimed workflow apply so another client can retry. Called automatically on apply handler failure. */
144
212
  releaseApply(options: ReleaseApplyOptions): Promise<ReleaseApplyResult>;
145
- /** Fetch pending workflow applies for a document. */
213
+ /**
214
+ * Fetch pending workflow applies for a document.
215
+ *
216
+ * Returns a concrete `PendingApply[]` (issue #1542) instead of the former
217
+ * `any[]`. The server element carries no `output`, so there is no output
218
+ * generic here — the apply output is typed on `define`/`onApply<O>`, where it
219
+ * is actually delivered.
220
+ */
146
221
  getPendingApplies(options: {
147
222
  contextDocId: string;
148
- }): Promise<any[]>;
149
- /** Define a workflow with its apply handler. Call once at app initialization so any client can handle apply. */
150
- define(workflowKey: string, options: WorkflowDefineOptions): void;
223
+ }): Promise<PendingApply[]>;
224
+ /**
225
+ * Define a workflow with its apply handler. Call once at app initialization
226
+ * so any client can handle apply.
227
+ *
228
+ * The optional generic `O` types the apply handler's `output` (issue #1542).
229
+ * It is additive and defaults to today's untyped `any`, so existing callers
230
+ * are unaffected.
231
+ */
232
+ define<O = any>(workflowKey: string, options: WorkflowDefineOptions<O>): void;
151
233
  }
152
234
  export interface PromptsAPI {
153
- /** Execute a prompt by key and return the result */
154
- execute(promptKey: string, options: ExecutePromptOptions): Promise<ExecutePromptResult>;
235
+ /**
236
+ * Execute a prompt by key and return the result.
237
+ *
238
+ * The optional generics are additive (issue #1542). `V` types the
239
+ * `variables` bag and `R` types `rawResponse`. Both default to today's
240
+ * untyped shapes, so existing callers are unaffected.
241
+ */
242
+ execute<V extends object = Record<string, any>, R = any>(promptKey: string, options: ExecutePromptOptions<V>): Promise<ExecutePromptResult<R>>;
155
243
  }
156
244
  /** Options for executing a prompt */
157
- export interface ExecutePromptOptions {
245
+ export interface ExecutePromptOptions<V extends object = Record<string, any>> {
158
246
  /** Variables to pass to the prompt template */
159
- variables: Record<string, any>;
247
+ variables: V;
160
248
  /** Override the model specified in the prompt config */
161
249
  modelOverride?: string;
162
250
  /** Specific config ID to use (defaults to activeConfigId) */
163
251
  configId?: string;
164
252
  }
165
253
  /** Result from executing a prompt */
166
- export interface ExecutePromptResult {
254
+ export interface ExecutePromptResult<R = any> {
167
255
  success: boolean;
168
256
  output: string;
169
257
  error?: string;
@@ -173,7 +261,7 @@ export interface ExecutePromptResult {
173
261
  outputTokens?: number;
174
262
  totalTokens?: number;
175
263
  };
176
- rawResponse: any;
264
+ rawResponse: R;
177
265
  configId: string;
178
266
  }
179
267
  export interface JsBaoClientOptions {
@@ -393,6 +481,24 @@ export interface BlobUploadFailedEvent {
393
481
  * events. See {@link InvitationEvent.action} for the full list and who
394
482
  * receives each.
395
483
  */
484
+ /**
485
+ * Real-time mirror of a durable in-app notification (#779).
486
+ *
487
+ * Emitted over the `notification` event channel
488
+ * (`client.on("notification", ...)`) when the signed-in user receives an
489
+ * in-app notification while connected. The durable inbox row is the source
490
+ * of truth — fetch it (and older rows) via `client.notifications.list()`.
491
+ */
492
+ export interface NotificationEvent {
493
+ type: "notification";
494
+ notificationId: string;
495
+ title: string;
496
+ body: string;
497
+ iconUrl?: string;
498
+ deepLink?: string;
499
+ sourceRef?: string;
500
+ createdAt: string;
501
+ }
396
502
  export interface InvitationEvent {
397
503
  type: "invitation";
398
504
  /**
@@ -497,7 +603,7 @@ export interface RunSyncWorkflowOptions {
497
603
  * resolve with this shape — promise rejection is reserved for
498
604
  * connectivity / abort-before-send errors.
499
605
  */
500
- export interface RunSyncWorkflowResult {
606
+ export interface RunSyncWorkflowResult<O = any> {
501
607
  runId: string;
502
608
  runKey: string;
503
609
  /**
@@ -510,7 +616,7 @@ export interface RunSyncWorkflowResult {
510
616
  */
511
617
  status: "completed" | "failed" | "terminated" | "timeout" | "apply_pending" | string;
512
618
  /** Final output of the workflow, when `status === "completed"`. */
513
- output?: any;
619
+ output?: O;
514
620
  /** Error message when `status === "failed"`. */
515
621
  error?: string;
516
622
  /** Persisted `WorkflowRun` row for the call (always present on success). */
@@ -557,6 +663,14 @@ export interface ListWorkflowRunsOptions {
557
663
  /** Sort direction: true for ascending (oldest first), false/undefined for descending (newest first) */
558
664
  forward?: boolean;
559
665
  }
666
+ /**
667
+ * Persisted status of a workflow run row. This is the model's documented set
668
+ * (`models.yaml` `WorkflowRun.status`) and is a superset of
669
+ * `WorkflowStatusValue` (it also includes `"queued"`). #1388 relies on it to
670
+ * distinguish terminal states — keep this union tied to the model's set so the
671
+ * two stay consistent.
672
+ */
673
+ export type WorkflowRunStatus = "queued" | "running" | "completed" | "failed" | "terminated" | "apply_pending" | "apply_claimed";
560
674
  /** A workflow run record */
561
675
  export interface WorkflowRun {
562
676
  runId: string;
@@ -566,9 +680,25 @@ export interface WorkflowRun {
566
680
  workflowKey: string;
567
681
  revisionId: string;
568
682
  contextDocId?: string;
569
- status: string;
570
- createdAt: string;
683
+ status: WorkflowRunStatus;
684
+ /** ISO timestamp stamped when the run started. Emitted by all run
685
+ * serializers (the model field is `required`); optional here only to
686
+ * tolerate hypothetical legacy records written before the field existed. */
687
+ startedAt?: string;
688
+ /** #1367 — ISO timestamp of the true execution start, stamped once Cloudflare
689
+ * actually schedules the instance. `null`/absent while the run is still
690
+ * queued. `startedAt` remains the request time. */
691
+ executionStartedAt?: string | null;
692
+ /** #1367 — derived queue delay in ms (`executionStartedAt − startedAt`), i.e.
693
+ * how long the run sat queued before executing. `null` while still queued. */
694
+ queueDelayMs?: number | null;
695
+ /** #1367 — wall-clock ms the `env.WORKFLOW_APP.create()` call itself took.
696
+ * `null` for runs started via a path that does not record it. */
697
+ createCallDurationMs?: number | null;
571
698
  endedAt?: string;
699
+ /** Error message when `status` is `"failed"`, `null` otherwise. Always
700
+ * present in run responses (the server sends `errorMessage || null`). */
701
+ errorMessage?: string | null;
572
702
  /** User-defined metadata (max 1KB) */
573
703
  meta?: Record<string, any>;
574
704
  }
@@ -645,10 +775,16 @@ export interface TerminateWorkflowOptions {
645
775
  * spelling is normalized client-side and is no longer surfaced.
646
776
  */
647
777
  export type WorkflowStatusValue = "completed" | "failed" | "terminated" | "running" | "apply_pending" | "apply_claimed";
648
- /** Workflow status response */
649
- export interface WorkflowStatusResult {
778
+ /**
779
+ * Workflow status response.
780
+ *
781
+ * The optional generic `O` types `output` (issue #1512). It defaults to `any`,
782
+ * so every existing bare reference to `WorkflowStatusResult` still compiles and
783
+ * the runtime is unchanged (the generic is erased).
784
+ */
785
+ export interface WorkflowStatusResult<O = any> {
650
786
  status: WorkflowStatusValue;
651
- output?: any;
787
+ output?: O;
652
788
  error?: string;
653
789
  run?: WorkflowRun;
654
790
  }
@@ -685,20 +821,61 @@ export interface ReleaseApplyResult {
685
821
  released: boolean;
686
822
  reason?: string;
687
823
  }
688
- /** Callback for applying a workflow result to a document */
689
- type WorkflowApplyHandler = (result: {
824
+ /**
825
+ * Callback for applying a workflow result to a document. `O` types the
826
+ * workflow's `output` (issue #1542); it is additive and defaults to today's
827
+ * untyped `any`.
828
+ */
829
+ type WorkflowApplyHandler<O = any> = (result: {
690
830
  workflowKey: string;
691
831
  runKey: string;
692
832
  runId: string;
693
833
  contextDocId?: string;
694
- output: any;
834
+ output: O;
695
835
  startedByUserId?: string;
696
836
  meta?: Record<string, any>;
697
837
  }) => void | Promise<void>;
838
+ /**
839
+ * One pending (or reclaimable) workflow apply, as returned by
840
+ * `workflows.getPendingApplies`. Concrete shape (issue #1542) mirroring the
841
+ * server element — it carries no `output`, so there is no output generic here.
842
+ */
843
+ export interface PendingApply {
844
+ runId: string;
845
+ runKey: string;
846
+ workflowKey: string;
847
+ workflowId: string;
848
+ instanceId: string;
849
+ contextDocId: string;
850
+ /** "apply_pending", or "apply_claimed" for a run whose apply lease expired. */
851
+ status: string;
852
+ startedByUserId: string;
853
+ /**
854
+ * ISO timestamp the apply was claimed, or null once claimed and released.
855
+ * Absent (the key is omitted) for a run that has never been claimed, so this
856
+ * property is optional.
857
+ */
858
+ claimedAt?: string | null;
859
+ /**
860
+ * Connection id that holds/held the apply claim, or null. Absent for a run
861
+ * that has never been claimed, so this property is optional.
862
+ */
863
+ claimedBy?: string | null;
864
+ /** Apply-lease timeout in milliseconds. */
865
+ applyLeaseTimeoutMs: number;
866
+ /**
867
+ * Parsed workflow run metadata, or `null` when none was set. Typed as
868
+ * `unknown` because the server accepts and round-trips any JSON value here:
869
+ * `normalizeMeta` stores whatever was passed (object, array, string, number,
870
+ * boolean) and `parseMeta` returns that same shape. Narrow before use — do
871
+ * not assume an object.
872
+ */
873
+ meta: unknown;
874
+ }
698
875
  /** Options for defining a workflow via `workflows.define()` */
699
- export interface WorkflowDefineOptions {
876
+ export interface WorkflowDefineOptions<O = any> {
700
877
  /** Handler to apply workflow results to the document. Called automatically when this workflow completes with needsApply. */
701
- onApply: WorkflowApplyHandler;
878
+ onApply: WorkflowApplyHandler<O>;
702
879
  }
703
880
  /** Options for {@link JsBaoClient.waitForUserId}. */
704
881
  export interface WaitForUserIdOptions {
@@ -710,6 +887,39 @@ export interface WaitForAuthReadyOptions {
710
887
  /** Maximum time to wait before rejecting (ms). */
711
888
  timeoutMs?: number;
712
889
  }
890
+ /**
891
+ * Terminal status reported by `workflows.waitFor()` (#1443). Narrower than
892
+ * {@link WorkflowStatusValue} — `waitFor` only resolves once the run is done,
893
+ * so `"running"` can never be reported. `apply_pending`/`apply_claimed` are
894
+ * terminal for the purpose of waiting: the workflow finished and its result is
895
+ * available for the client-side apply step.
896
+ */
897
+ export type WaitForWorkflowStatus = "completed" | "failed" | "terminated" | "apply_pending" | "apply_claimed";
898
+ /** Options for {@link WorkflowsAPI.waitFor} (#1443). */
899
+ export interface WaitForWorkflowOptions {
900
+ /**
901
+ * Maximum time to wait for the run to reach a terminal state before
902
+ * rejecting with a `WORKFLOW_WAIT_TIMEOUT` {@link JsBaoError}. Defaults to
903
+ * 15 minutes (900000 ms).
904
+ *
905
+ * Set to `0` or `Infinity` to disable the timeout entirely. WARNING: with no
906
+ * timeout the returned promise (and its `workflowStatus` listener) lives
907
+ * until the run terminates — only use this for runs you know will end.
908
+ */
909
+ timeoutMs?: number;
910
+ }
911
+ /**
912
+ * Result from {@link WorkflowsAPI.waitFor} (#1443). Resolved once the run
913
+ * reaches a terminal state.
914
+ */
915
+ export interface WaitForWorkflowResult {
916
+ /** Terminal status of the run. Never `"running"`. */
917
+ status: WaitForWorkflowStatus;
918
+ /** Final output of the run, when available. */
919
+ output?: any;
920
+ /** Error message when `status === "failed"`. */
921
+ error?: string;
922
+ }
713
923
  /** Options for {@link JsBaoClient.enableOfflineAccess}. */
714
924
  export interface EnableOfflineAccessOptions {
715
925
  /** If true, attempts passkey-based largeBlob storage before falling back to PIN. */
@@ -806,6 +1016,7 @@ export interface JsBaoEvents {
806
1016
  meUpdated: MeUpdatedEvent;
807
1017
  meUpdateFailed: MeUpdateFailedEvent;
808
1018
  invitation: InvitationEvent;
1019
+ notification: NotificationEvent;
809
1020
  workflowStatus: WorkflowStatusEvent;
810
1021
  workflowStarted: WorkflowStartedEvent;
811
1022
  syncPerf: {
@@ -997,9 +1208,15 @@ export declare class JsBaoClient extends Observable<any> {
997
1208
  /** Sub-API for managing cron triggers (workflow schedulers).
998
1209
  * @group Sub-APIs */
999
1210
  cronTriggers: CronTriggersAPI;
1211
+ /** Sub-API for reading and writing typed resource metadata (single + batch).
1212
+ * @group Sub-APIs */
1213
+ resourceMetadata: ResourceMetadataAPI;
1000
1214
  /** Sub-API for app-level invitations and deferred grants.
1001
1215
  * @group Sub-APIs */
1002
1216
  invitations: InvitationsAPI;
1217
+ /** Sub-API for the notification inbox (list, unread count, mark read, send).
1218
+ * @group Sub-APIs */
1219
+ notifications: NotificationsAPI;
1003
1220
  /** Sub-API for managing third-party integrations.
1004
1221
  * @group Sub-APIs */
1005
1222
  integrations: IntegrationsAPI;
@@ -1190,6 +1407,35 @@ export declare class JsBaoClient extends Observable<any> {
1190
1407
  */
1191
1408
  private runSyncWorkflow;
1192
1409
  private getWorkflowStatus;
1410
+ /**
1411
+ * Normalize a raw `{ status: rawStatus, run }` status response into a
1412
+ * {@link WorkflowStatusResult}. Shared by `getStatus` (workflowKey/runKey
1413
+ * route) and `waitFor`'s reconcile fetch (runId route) so both surfaces map
1414
+ * the Cloudflare status spellings and apply-flow states identically.
1415
+ */
1416
+ private normalizeWorkflowStatusResponse;
1417
+ /**
1418
+ * Fetch normalized run status keyed by `runId` via the #1443 endpoint
1419
+ * (`GET /workflows/runs/:runId/status`). Used by `waitFor`'s reconcile
1420
+ * fetch. A 404 surfaces as a `NOT_FOUND` {@link JsBaoError} (unknown or
1421
+ * not-owned run).
1422
+ */
1423
+ private getWorkflowStatusByRunId;
1424
+ /**
1425
+ * Implementation of {@link WorkflowsAPI.waitFor} (#1443). See the interface
1426
+ * doc for the contract. Cleanup mirrors `createUserIdWaiter` in
1427
+ * authController — a guarded `cleanup()` that clears the timer and removes
1428
+ * every listener, run on every exit path.
1429
+ */
1430
+ private waitForWorkflow;
1431
+ /**
1432
+ * Collapse a normalized {@link WorkflowStatusValue} into the narrower
1433
+ * {@link WaitForWorkflowStatus} for `waitFor`. Terminal statuses pass
1434
+ * through unchanged. A `"running"` status only reaches here when `endedAt`
1435
+ * is set (#1388): derive the real terminal state from the run row's error
1436
+ * (failed if an error message is present, otherwise completed).
1437
+ */
1438
+ private toTerminalWaitStatus;
1193
1439
  private terminateWorkflow;
1194
1440
  private listWorkflowRuns;
1195
1441
  private listWorkflowStepRuns;
@@ -1312,7 +1558,7 @@ export declare class JsBaoClient extends Observable<any> {
1312
1558
  * @param documentId - The document to set awareness for
1313
1559
  * @param state - Arbitrary awareness data (cursor, selection, user info) to broadcast to collaborators
1314
1560
  * @group Awareness */
1315
- setAwareness(documentId: string, state: any): void;
1561
+ setAwareness<S = any>(documentId: string, state: S): void;
1316
1562
  private getIndexedDbNames;
1317
1563
  private doesIndexedDbExist;
1318
1564
  /** Check if a document has IndexedDB persistence.
@@ -1382,6 +1628,7 @@ export declare class JsBaoClient extends Observable<any> {
1382
1628
  private handlePendingCreateFailed;
1383
1629
  private handleDocumentMetadataUpdate;
1384
1630
  private handleInvitationMessage;
1631
+ private handleNotificationMessage;
1385
1632
  private handleWorkflowStatusMessage;
1386
1633
  private handleWorkflowStartedMessage;
1387
1634
  private handleOfflineAuthMessage;
@@ -1419,11 +1666,11 @@ export declare class JsBaoClient extends Observable<any> {
1419
1666
  * Note: the server's wire field is named `metadata`; the local cache key is
1420
1667
  * `docMetadata` to avoid colliding with the cache envelope's `metadata` key.
1421
1668
  * @group Documents */
1422
- updateLocalMetadata(documentId: string, updates: {
1669
+ updateLocalMetadata<M = unknown>(documentId: string, updates: {
1423
1670
  title?: string;
1424
1671
  tags?: string[];
1425
1672
  thumbnailBlobId?: string | null;
1426
- docMetadata?: unknown | null;
1673
+ docMetadata?: M | null;
1427
1674
  }): Promise<void>;
1428
1675
  private _updateSynced;
1429
1676
  /** Open a document for real-time collaboration and sync.
@@ -1633,15 +1880,15 @@ export declare class JsBaoClient extends Observable<any> {
1633
1880
  * @param documentId - The document to set awareness for
1634
1881
  * @param state - Arbitrary awareness data (cursor, selection, user info) to broadcast to collaborators
1635
1882
  * @group Awareness */
1636
- setLocalAwarenessState(documentId: string, state: any): void;
1883
+ setLocalAwarenessState<S = any>(documentId: string, state: S): void;
1637
1884
  /** Get the local user's current awareness state for a document.
1638
1885
  * @param documentId - The document to get local awareness for
1639
1886
  * @group Awareness */
1640
- getLocalAwarenessState(documentId: string): any | null;
1887
+ getLocalAwarenessState<S = any>(documentId: string): S | null;
1641
1888
  /** Get all users' awareness states for a document.
1642
1889
  * @param documentId - The document to get awareness states for
1643
1890
  * @group Awareness */
1644
- getAwarenessStates(documentId: string): Map<string, any>;
1891
+ getAwarenessStates<S = any>(documentId: string): Map<string, S>;
1645
1892
  /** Remove awareness states for specific clients and broadcast the removal to the server.
1646
1893
  * @param documentId - The document to remove awareness from
1647
1894
  * @param clientIds - Array of client IDs whose awareness states should be removed
@@ -1883,9 +2130,14 @@ export declare class JsBaoClient extends Observable<any> {
1883
2130
  passkeyEnabled: boolean;
1884
2131
  passkeyRpId: string | null;
1885
2132
  passkeyRpName: string | null;
2133
+ passkeyRpConfig: Record<string, {
2134
+ name: string;
2135
+ }> | null;
1886
2136
  hasPasskey: boolean;
1887
2137
  magicLinkEnabled: boolean;
1888
2138
  otpEnabled: boolean;
2139
+ hasApple: boolean;
2140
+ appleSignInEnabled: boolean;
1889
2141
  }>;
1890
2142
  private checkAndStartAutoOAuth;
1891
2143
  private handleLogoutCleanup;