@sanity/workflow-engine 0.19.0 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -203,7 +203,7 @@ declare const ActionParamSchema: v.SchemaWithPipe<
203
203
  "doc.refs",
204
204
  "json",
205
205
  ],
206
- `Invalid option: expected one of ${string}`
206
+ string
207
207
  >;
208
208
  readonly name: v.SchemaWithPipe<
209
209
  readonly [
@@ -747,10 +747,7 @@ declare type AuthoringFieldRef = v.InferOutput<typeof AuthoringFieldRefSchema>;
747
747
  declare const AuthoringFieldRefSchema: v.StrictObjectSchema<
748
748
  {
749
749
  readonly scope: v.OptionalSchema<
750
- v.PicklistSchema<
751
- readonly ["workflow", "stage", "activity"],
752
- `Invalid option: expected one of ${string}`
753
- >,
750
+ v.PicklistSchema<readonly ["workflow", "stage", "activity"], string>,
754
751
  undefined
755
752
  >;
756
753
  readonly field: v.SchemaWithPipe<
@@ -916,7 +913,7 @@ declare const AuthoringGuardSchema: v.StrictObjectSchema<
916
913
  v.ArraySchema<
917
914
  v.PicklistSchema<
918
915
  readonly ["create", "update", "delete", "publish", "unpublish"],
919
- `Invalid option: expected one of ${string}`
916
+ string
920
917
  >,
921
918
  undefined
922
919
  >,
@@ -1091,7 +1088,7 @@ declare const AuthoringManualTargetSchema: v.VariantSchema<
1091
1088
  readonly scope: v.OptionalSchema<
1092
1089
  v.PicklistSchema<
1093
1090
  readonly ["workflow", "stage", "activity"],
1094
- `Invalid option: expected one of ${string}`
1091
+ string
1095
1092
  >,
1096
1093
  undefined
1097
1094
  >;
@@ -1127,7 +1124,7 @@ declare const AuthoringOpSchema: v.VariantSchema<
1127
1124
  readonly scope: v.OptionalSchema<
1128
1125
  v.PicklistSchema<
1129
1126
  readonly ["workflow", "stage", "activity"],
1130
- `Invalid option: expected one of ${string}`
1127
+ string
1131
1128
  >,
1132
1129
  undefined
1133
1130
  >;
@@ -1152,7 +1149,7 @@ declare const AuthoringOpSchema: v.VariantSchema<
1152
1149
  readonly scope: v.OptionalSchema<
1153
1150
  v.PicklistSchema<
1154
1151
  readonly ["workflow", "stage", "activity"],
1155
- `Invalid option: expected one of ${string}`
1152
+ string
1156
1153
  >,
1157
1154
  undefined
1158
1155
  >;
@@ -1176,7 +1173,7 @@ declare const AuthoringOpSchema: v.VariantSchema<
1176
1173
  readonly scope: v.OptionalSchema<
1177
1174
  v.PicklistSchema<
1178
1175
  readonly ["workflow", "stage", "activity"],
1179
- `Invalid option: expected one of ${string}`
1176
+ string
1180
1177
  >,
1181
1178
  undefined
1182
1179
  >;
@@ -1201,7 +1198,7 @@ declare const AuthoringOpSchema: v.VariantSchema<
1201
1198
  readonly scope: v.OptionalSchema<
1202
1199
  v.PicklistSchema<
1203
1200
  readonly ["workflow", "stage", "activity"],
1204
- `Invalid option: expected one of ${string}`
1201
+ string
1205
1202
  >,
1206
1203
  undefined
1207
1204
  >;
@@ -1232,7 +1229,7 @@ declare const AuthoringOpSchema: v.VariantSchema<
1232
1229
  readonly scope: v.OptionalSchema<
1233
1230
  v.PicklistSchema<
1234
1231
  readonly ["workflow", "stage", "activity"],
1235
- `Invalid option: expected one of ${string}`
1232
+ string
1236
1233
  >,
1237
1234
  undefined
1238
1235
  >;
@@ -1268,7 +1265,7 @@ declare const AuthoringOpSchema: v.VariantSchema<
1268
1265
  >;
1269
1266
  readonly status: v.PicklistSchema<
1270
1267
  readonly ["active", "done", "skipped", "failed"],
1271
- `Invalid option: expected one of ${string}`
1268
+ string
1272
1269
  >;
1273
1270
  },
1274
1271
  undefined
@@ -1281,7 +1278,7 @@ declare const AuthoringOpSchema: v.VariantSchema<
1281
1278
  readonly scope: v.OptionalSchema<
1282
1279
  v.PicklistSchema<
1283
1280
  readonly ["workflow", "stage", "activity"],
1284
- `Invalid option: expected one of ${string}`
1281
+ string
1285
1282
  >,
1286
1283
  undefined
1287
1284
  >;
@@ -1997,10 +1994,9 @@ export declare type ConditionVarBinding = "always" | "caller" | "spawn";
1997
1994
 
1998
1995
  /**
1999
1996
  * The one-doc read a reactive adapter subscribes with to observe a content doc
2000
- * under a perspective stack the same GROQ as the engine's own hydration read
2001
- * ({@link hydrateSnapshot}), so the adapter and the engine resolve identical
2002
- * content: draft/version content projected onto the published id, a doc that
2003
- * exists only as a draft (or only inside a release) still visible.
1997
+ * under a perspective stack. It uses the same perspective semantics as
1998
+ * {@link hydrateSnapshot}: draft/version content is projected onto the published
1999
+ * id, and a doc that exists only as a draft or release version remains visible.
2004
2000
  */
2005
2001
  export declare function contentDocQuery(documentId: string): CompiledQuery;
2006
2002
 
@@ -3457,11 +3453,13 @@ export declare type EffectHandler<
3457
3453
  */
3458
3454
  declare type EffectHandlerContext<Client extends WorkflowClient> = {
3459
3455
  /**
3460
- * The exact concrete client supplied to `createEngine`, bound to the
3461
- * workflow resource rather than an
3462
- * engine wrapper. Its class identity, namespaces, configuration, and
3463
- * credentials are preserved. Handler-owned requests are not automatically
3464
- * tagged by the engine.
3456
+ * A concrete sibling of the client supplied to `createEngine`, bound to the
3457
+ * workflow resource with the same namespaces and credentials. Untagged
3458
+ * handler requests on its workflow-client surface carry the `workflow.effect`
3459
+ * request tag by default. A concrete client's explicit tags compose beneath
3460
+ * that prefix. On the structural fallback for minimal clients, pass-through
3461
+ * namespaces are not stamped and core builders expose the engine's minimal
3462
+ * workflow-client surface.
3465
3463
  */
3466
3464
  client: Client;
3467
3465
  /**
@@ -3477,8 +3475,8 @@ declare type EffectHandlerContext<Client extends WorkflowClient> = {
3477
3475
  * {@link GlobalDocumentReference}. Returns the `resourceClients` client
3478
3476
  * for that resource when one is mapped, {@link client} for the workflow
3479
3477
  * resource itself, and a sibling derived from {@link client}'s
3480
- * credentials otherwise. Mapped clients are returned unchanged; an
3481
- * unmapped foreign resource necessarily returns a configured sibling.
3478
+ * credentials otherwise. Returned clients preserve their concrete APIs and
3479
+ * apply the same default effect request tag.
3482
3480
  * Throws if `ref` isn't a GDR — a bare id can't
3483
3481
  * be routed, so failing loud beats silently patching the wrong dataset.
3484
3482
  */
@@ -3845,10 +3843,10 @@ export declare interface Engine {
3845
3843
  * {@link WorkflowClient.withConfig}, and `resourceClients`-resolved clients
3846
3844
  * are rebound the same way. A caller's configured `apiVersion` therefore
3847
3845
  * never reaches engine-owned traffic (the caller's own client instance is
3848
- * untouched). Effect handlers are host traffic and deliberately receive the
3849
- * caller's configuration unchanged. The other exception is a client that lacks `withConfig` and so
3850
- * cannot be rebound — it must be built to serve this version; see
3851
- * {@link WorkflowClient.withConfig}.
3846
+ * untouched). Effect handlers keep the caller's `apiVersion`; their derived
3847
+ * clients change only the request-tag prefix. The other exception is a client
3848
+ * that lacks `withConfig` and so cannot be rebound — it must be built to serve
3849
+ * this version; see {@link WorkflowClient.withConfig}.
3852
3850
  */
3853
3851
  export declare const ENGINE_API_VERSION = "2026-04-29";
3854
3852
 
@@ -4826,7 +4824,7 @@ export declare type GuardAction = v.InferOutput<typeof GuardActionSchema>;
4826
4824
 
4827
4825
  declare const GuardActionSchema: v.PicklistSchema<
4828
4826
  readonly ["create", "update", "delete", "publish", "unpublish"],
4829
- `Invalid option: expected one of ${string}`
4827
+ string
4830
4828
  >;
4831
4829
 
4832
4830
  export declare type GuardMatch = Guard["match"];
@@ -4991,7 +4989,7 @@ declare const GuardSchema: v.StrictObjectSchema<
4991
4989
  v.ArraySchema<
4992
4990
  v.PicklistSchema<
4993
4991
  readonly ["create", "update", "delete", "publish", "unpublish"],
4994
- `Invalid option: expected one of ${string}`
4992
+ string
4995
4993
  >,
4996
4994
  undefined
4997
4995
  >,
@@ -5527,13 +5525,14 @@ export declare type InsightSite =
5527
5525
  export declare function instanceDocId(tag: string): string;
5528
5526
 
5529
5527
  /**
5530
- * The per-instance guard filter — the single definition of "this instance's
5531
- * guards in one datasource". The engine's verdict load
5532
- * ({@link verdictGuardsForInstance}) fetches it once against the engine
5533
- * datasource; the reactive adapters feed the same query/params to their
5534
- * stores as a live subscription; {@link guardsForInstance} unions it across
5535
- * datasources for housekeeping. Ordinary stage retraction deletes guards, so
5536
- * results represent active persisted guard documents.
5528
+ * The per-instance guard filter — "this instance's guards in one datasource".
5529
+ * The engine's verdict load ({@link verdictGuardsForInstance}) fetches it once
5530
+ * against the engine datasource, and {@link guardsForInstance} unions it
5531
+ * across datasources for housekeeping; the reactive adapters subscribe the
5532
+ * set-shaped {@link instancesGuardQuery} this delegates to (one shared
5533
+ * live query per resource, sliced per `sourceInstanceId`), so every path
5534
+ * reads through one filter definition. Ordinary stage retraction deletes
5535
+ * guards, so results represent active persisted guard documents.
5537
5536
  */
5538
5537
  export declare function instanceGuardQuery(instanceId: string): CompiledQuery;
5539
5538
 
@@ -5586,6 +5585,12 @@ export declare interface InstanceSession {
5586
5585
  * docs are processed), never from the commit itself — the commit's
5587
5586
  * outcome is never masked by a store echo's failure. */
5588
5587
  update(docs: LoadedDoc[]): void;
5588
+ /** Replace one held document without rebuilding the rest of the overlay.
5589
+ * Consumers with per-document streams use this after the initial
5590
+ * {@link InstanceSession.update} snapshot. Self-doc recency, commit-time
5591
+ * buffering, and deferred buffered-validation errors follow the same
5592
+ * contract as {@link InstanceSession.update}. */
5593
+ updateDocument(doc: LoadedDoc): void;
5589
5594
  /** Replace the held live guards (the consumer's guard stream,
5590
5595
  * last-write-wins). Guards are a separate stream from the watch-set:
5591
5596
  * {@link InstanceSession.evaluate} pre-flights the instance write against
@@ -5647,6 +5652,18 @@ export declare interface InstancesForDocumentArgs {
5647
5652
  document: GdrUri;
5648
5653
  }
5649
5654
 
5655
+ /**
5656
+ * The guard filter for a SET of instances in one datasource — the single
5657
+ * definition every per-instance read delegates to ({@link instanceGuardQuery}).
5658
+ * Reactive adapters subscribe it as ONE shared live query per resource for
5659
+ * every co-mounted session, fanning results back out per `sourceInstanceId`,
5660
+ * so a document's guard subscription count doesn't grow with its instance
5661
+ * count. Deterministically ordered, matching {@link guardsForResource}.
5662
+ */
5663
+ export declare function instancesGuardQuery(
5664
+ instanceIds: readonly string[],
5665
+ ): CompiledQuery;
5666
+
5650
5667
  /**
5651
5668
  * The instance-list GROQ for a {@link InstancesQueryFilter}, ordered by
5652
5669
  * `startedAt` ascending (descending + sliced under
@@ -5740,6 +5757,10 @@ export declare function isClaimExpired(
5740
5757
  now: string,
5741
5758
  ): boolean;
5742
5759
 
5760
+ export declare function isClientProjectUser(
5761
+ value: unknown,
5762
+ ): value is ClientProjectUser;
5763
+
5743
5764
  export { isComparisonOp };
5744
5765
 
5745
5766
  /**
@@ -6588,8 +6609,8 @@ export declare type ProgressTarget =
6588
6609
  * the session keys its overlay and snapshot by), and a draft/version
6589
6610
  * representation's stored id rides along as `_originalId` — session-side
6590
6611
  * conditions (including the `_originalId in path("versions.**")` shape) then
6591
- * read exactly what the engine's own hydration ({@link contentDocQuery})
6592
- * returns. Strict by construction: only the ids in
6612
+ * read the same projected identity as the engine's perspective-aware hydration.
6613
+ * Strict by construction: only the ids in
6593
6614
  * {@link watchRefRepresentations} are accepted — an id that merely *ends* in
6594
6615
  * the watched id (another doc's dotted id under a version prefix), a release
6595
6616
  * the perspective doesn't read, or a draft the perspective makes invisible is
@@ -6977,8 +6998,8 @@ export declare function resourceAliasesToMap(
6977
6998
  * refs to the resources it stops serving.
6978
6999
  *
6979
7000
  * Engine-owned verb scopes rebind resolved clients onto
6980
- * `ENGINE_API_VERSION`. Effect handlers receive resolver clients unchanged
6981
- * because handler traffic belongs to the host.
7001
+ * `ENGINE_API_VERSION`. Effect handlers derive request-tagged siblings from
7002
+ * resolver clients so their concrete APIs remain available and attributed.
6982
7003
  */
6983
7004
  export declare type ResourceClientResolver = (
6984
7005
  parsed: ParsedGdr,
@@ -7636,7 +7657,7 @@ declare const StoredFieldOpSchema: v.VariantSchema<
7636
7657
  {
7637
7658
  readonly scope: v.PicklistSchema<
7638
7659
  readonly ["workflow", "stage", "activity"],
7639
- `Invalid option: expected one of ${string}`
7660
+ string
7640
7661
  >;
7641
7662
  readonly field: v.SchemaWithPipe<
7642
7663
  readonly [
@@ -7658,7 +7679,7 @@ declare const StoredFieldOpSchema: v.VariantSchema<
7658
7679
  {
7659
7680
  readonly scope: v.PicklistSchema<
7660
7681
  readonly ["workflow", "stage", "activity"],
7661
- `Invalid option: expected one of ${string}`
7682
+ string
7662
7683
  >;
7663
7684
  readonly field: v.SchemaWithPipe<
7664
7685
  readonly [
@@ -7679,7 +7700,7 @@ declare const StoredFieldOpSchema: v.VariantSchema<
7679
7700
  {
7680
7701
  readonly scope: v.PicklistSchema<
7681
7702
  readonly ["workflow", "stage", "activity"],
7682
- `Invalid option: expected one of ${string}`
7703
+ string
7683
7704
  >;
7684
7705
  readonly field: v.SchemaWithPipe<
7685
7706
  readonly [
@@ -7701,7 +7722,7 @@ declare const StoredFieldOpSchema: v.VariantSchema<
7701
7722
  {
7702
7723
  readonly scope: v.PicklistSchema<
7703
7724
  readonly ["workflow", "stage", "activity"],
7704
- `Invalid option: expected one of ${string}`
7725
+ string
7705
7726
  >;
7706
7727
  readonly field: v.SchemaWithPipe<
7707
7728
  readonly [
@@ -7729,7 +7750,7 @@ declare const StoredFieldOpSchema: v.VariantSchema<
7729
7750
  {
7730
7751
  readonly scope: v.PicklistSchema<
7731
7752
  readonly ["workflow", "stage", "activity"],
7732
- `Invalid option: expected one of ${string}`
7753
+ string
7733
7754
  >;
7734
7755
  readonly field: v.SchemaWithPipe<
7735
7756
  readonly [
@@ -7759,7 +7780,7 @@ declare const StoredFieldRefSchema: v.StrictObjectSchema<
7759
7780
  {
7760
7781
  readonly scope: v.PicklistSchema<
7761
7782
  readonly ["workflow", "stage", "activity"],
7762
- `Invalid option: expected one of ${string}`
7783
+ string
7763
7784
  >;
7764
7785
  readonly field: v.SchemaWithPipe<
7765
7786
  readonly [
@@ -7794,7 +7815,7 @@ declare const StoredManualTargetSchema: v.VariantSchema<
7794
7815
  {
7795
7816
  readonly scope: v.PicklistSchema<
7796
7817
  readonly ["workflow", "stage", "activity"],
7797
- `Invalid option: expected one of ${string}`
7818
+ string
7798
7819
  >;
7799
7820
  readonly field: v.SchemaWithPipe<
7800
7821
  readonly [
@@ -7822,7 +7843,7 @@ declare const StoredOpSchema: v.VariantSchema<
7822
7843
  {
7823
7844
  readonly scope: v.PicklistSchema<
7824
7845
  readonly ["workflow", "stage", "activity"],
7825
- `Invalid option: expected one of ${string}`
7846
+ string
7826
7847
  >;
7827
7848
  readonly field: v.SchemaWithPipe<
7828
7849
  readonly [
@@ -7844,7 +7865,7 @@ declare const StoredOpSchema: v.VariantSchema<
7844
7865
  {
7845
7866
  readonly scope: v.PicklistSchema<
7846
7867
  readonly ["workflow", "stage", "activity"],
7847
- `Invalid option: expected one of ${string}`
7868
+ string
7848
7869
  >;
7849
7870
  readonly field: v.SchemaWithPipe<
7850
7871
  readonly [
@@ -7865,7 +7886,7 @@ declare const StoredOpSchema: v.VariantSchema<
7865
7886
  {
7866
7887
  readonly scope: v.PicklistSchema<
7867
7888
  readonly ["workflow", "stage", "activity"],
7868
- `Invalid option: expected one of ${string}`
7889
+ string
7869
7890
  >;
7870
7891
  readonly field: v.SchemaWithPipe<
7871
7892
  readonly [
@@ -7887,7 +7908,7 @@ declare const StoredOpSchema: v.VariantSchema<
7887
7908
  {
7888
7909
  readonly scope: v.PicklistSchema<
7889
7910
  readonly ["workflow", "stage", "activity"],
7890
- `Invalid option: expected one of ${string}`
7911
+ string
7891
7912
  >;
7892
7913
  readonly field: v.SchemaWithPipe<
7893
7914
  readonly [
@@ -7915,7 +7936,7 @@ declare const StoredOpSchema: v.VariantSchema<
7915
7936
  {
7916
7937
  readonly scope: v.PicklistSchema<
7917
7938
  readonly ["workflow", "stage", "activity"],
7918
- `Invalid option: expected one of ${string}`
7939
+ string
7919
7940
  >;
7920
7941
  readonly field: v.SchemaWithPipe<
7921
7942
  readonly [
@@ -7946,7 +7967,7 @@ declare const StoredOpSchema: v.VariantSchema<
7946
7967
  >;
7947
7968
  readonly status: v.PicklistSchema<
7948
7969
  readonly ["active", "done", "skipped", "failed"],
7949
- `Invalid option: expected one of ${string}`
7970
+ string
7950
7971
  >;
7951
7972
  },
7952
7973
  undefined
@@ -8220,10 +8241,7 @@ declare const SubworkflowsSchema: v.StrictObjectSchema<
8220
8241
  * `$subworkflows`) decide.
8221
8242
  */
8222
8243
  readonly onExit: v.OptionalSchema<
8223
- v.PicklistSchema<
8224
- readonly ["detach", "abort"],
8225
- `Invalid option: expected one of ${string}`
8226
- >,
8244
+ v.PicklistSchema<readonly ["detach", "abort"], string>,
8227
8245
  undefined
8228
8246
  >;
8229
8247
  },
@@ -8541,9 +8559,10 @@ declare type ValueExprInternal =
8541
8559
  * physically scoped: a guard doc in a watched content dataset that
8542
8560
  * self-declares the engine's resource id must never reach a verdict. This
8543
8561
  * keeps the advisory layer consistent (verdicts are UX, not enforcement);
8544
- * it is not itself a security boundary. Runs the same query the reactive
8545
- * adapters subscribe with ({@link instanceGuardQuery}), so the stateless and
8546
- * reactive paths agree.
8562
+ * it is not itself a security boundary. Reads through the same filter
8563
+ * definition the reactive adapters subscribe with
8564
+ * ({@link instanceGuardQuery}, the one-id form of the set-shaped
8565
+ * {@link instancesGuardQuery}), so the stateless and reactive paths agree.
8547
8566
  */
8548
8567
  export declare function verdictGuardsForInstance(
8549
8568
  client: WorkflowClient,
@@ -9107,7 +9126,7 @@ export declare interface WorkflowClient {
9107
9126
  * Optional — present on the real `@sanity/client` and the in-memory test
9108
9127
  * fake. Returns a sibling client with the given config overrides,
9109
9128
  * inheriting everything else from the source (token, apiHost). The engine
9110
- * derives two things from it:
9129
+ * derives three things from it:
9111
9130
  *
9112
9131
  * - **Cross-resource routing** (`resource` + the dataset pair): a sibling
9113
9132
  * for a foreign GDR when `resourceClients` doesn't map it. A client
@@ -9121,6 +9140,10 @@ export declare interface WorkflowClient {
9121
9140
  * rebound and is used as-is — it must be built to serve
9122
9141
  * {@link ENGINE_API_VERSION} already; older dated versions fail
9123
9142
  * silently incomplete, not loud.
9143
+ * - **Effect request attribution** (`requestTagPrefix`): handlers receive a
9144
+ * derived client whose untagged traffic carries the effect tag while the
9145
+ * caller's own client remains untouched. A client without `withConfig`
9146
+ * uses the structural request wrapper instead.
9124
9147
  *
9125
9148
  * Dataset resources carry the `{projectId, dataset}` pair alongside
9126
9149
  * `resource`: the real client routes by `resource` (it takes precedence in
@@ -9129,7 +9152,7 @@ export declare interface WorkflowClient {
9129
9152
  * only — a canvas/media-library derivation on the fake aliases the current
9130
9153
  * store until the fake learns `resource` upstream.
9131
9154
  */
9132
- withConfig?: (config: WorkflowClientConfig) => WorkflowClient;
9155
+ withConfig?: (config: WorkflowClientConfig) => this;
9133
9156
  /**
9134
9157
  * Optional — present on the real `@sanity/client`, absent on the
9135
9158
  * in-memory test client. The engine probes for it when auto-resolving
@@ -9155,14 +9178,15 @@ export declare interface WorkflowClient {
9155
9178
  /**
9156
9179
  * The config bag {@link WorkflowClient.withConfig} accepts — all optional: a
9157
9180
  * resource rebind (`resource`, plus the dataset pair for dataset targets), an
9158
- * `apiVersion` rebind, or both. Everything omitted is inherited from the
9159
- * source client.
9181
+ * `apiVersion` rebind, a request-tag prefix, or any combination. Everything
9182
+ * omitted is inherited from the source client.
9160
9183
  */
9161
9184
  export declare interface WorkflowClientConfig {
9162
9185
  resource?: WorkflowResource;
9163
9186
  projectId?: string;
9164
9187
  dataset?: string;
9165
9188
  apiVersion?: string;
9189
+ requestTagPrefix?: string;
9166
9190
  }
9167
9191
 
9168
9192
  export declare interface WorkflowCommitOptions {