@sanity/client 8.2.0 → 8.3.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/README.md +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +30 -40
- package/dist/index.js.map +1 -1
- package/dist/index.node.d.ts +91 -15
- package/dist/index.node.js +31 -41
- package/dist/index.node.js.map +1 -1
- package/dist/media-library.d.ts +1 -1
- package/dist/{types-nJhm5Nyq.d.ts → types-0x2hPfhJ.d.ts} +92 -16
- package/package.json +1 -2
- package/src/collaboration/types.ts +59 -8
- package/src/functions/FunctionsClient.ts +52 -9
- package/src/functions/invoke.ts +47 -6
- package/src/types.ts +6 -1
- package/src/util/createVersionId.ts +15 -5
package/dist/media-library.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _r as VideoSubtitleInfoPublic, dr as VideoPlaybackInfoSigned, fr as VideoPlaybackTokens, gr as VideoSubtitleInfo, hr as VideoRenditionInfoSigned, mr as VideoRenditionInfoPublic, or as VideoPlaybackInfo, pr as VideoRenditionInfo, vr as VideoSubtitleInfoSigned } from "./types-
|
|
1
|
+
import { _r as VideoSubtitleInfoPublic, dr as VideoPlaybackInfoSigned, fr as VideoPlaybackTokens, gr as VideoSubtitleInfo, hr as VideoRenditionInfoSigned, mr as VideoRenditionInfoPublic, or as VideoPlaybackInfo, pr as VideoRenditionInfo, vr as VideoSubtitleInfoSigned } from "./types-0x2hPfhJ.js";
|
|
2
2
|
/**
|
|
3
3
|
* Check if the entire playback info response requires signed URLs
|
|
4
4
|
* @public
|
|
@@ -1285,6 +1285,17 @@ interface CollaborationCommentRange {
|
|
|
1285
1285
|
offset: number;
|
|
1286
1286
|
};
|
|
1287
1287
|
}
|
|
1288
|
+
/**
|
|
1289
|
+
* Portable Text covering a comment `range`. Callers can send just the blocks
|
|
1290
|
+
* from the `range` start `_key` through end `_key`, or the full field.
|
|
1291
|
+
*
|
|
1292
|
+
* @alpha
|
|
1293
|
+
*/
|
|
1294
|
+
type CollaborationCommentFieldValue = Array<{
|
|
1295
|
+
_type: string;
|
|
1296
|
+
_key: string;
|
|
1297
|
+
[key: string]: Any$1;
|
|
1298
|
+
}>;
|
|
1288
1299
|
/**
|
|
1289
1300
|
* Target for a top-level comment. Inline selections require both `path` and
|
|
1290
1301
|
* `range`; field-level comments may set `path` alone.
|
|
@@ -1293,6 +1304,9 @@ interface CollaborationCommentRange {
|
|
|
1293
1304
|
* `target.path.field`, and `range` is resolved against the document into
|
|
1294
1305
|
* `target.path.selection` and `contentSnapshot` rather than being stored.
|
|
1295
1306
|
*
|
|
1307
|
+
* An optional `fieldValue` is Portable Text covering the `range`. When set,
|
|
1308
|
+
* the `range` is resolved from those blocks instead of from the live document.
|
|
1309
|
+
*
|
|
1296
1310
|
* @alpha
|
|
1297
1311
|
*/
|
|
1298
1312
|
type CollaborationCommentTarget = {
|
|
@@ -1303,10 +1317,16 @@ type CollaborationCommentTarget = {
|
|
|
1303
1317
|
/** Path to the field containing the inline comment selection */
|
|
1304
1318
|
path: string;
|
|
1305
1319
|
range: CollaborationCommentRange;
|
|
1320
|
+
/**
|
|
1321
|
+
* Portable Text covering the `range`. When set, the `range` is resolved
|
|
1322
|
+
* from these blocks instead of from the live document.
|
|
1323
|
+
*/
|
|
1324
|
+
fieldValue?: CollaborationCommentFieldValue;
|
|
1306
1325
|
} | {
|
|
1307
1326
|
/** Path to the commented field */
|
|
1308
1327
|
path?: string;
|
|
1309
1328
|
range?: never;
|
|
1329
|
+
fieldValue?: never;
|
|
1310
1330
|
});
|
|
1311
1331
|
/**
|
|
1312
1332
|
* Comment to create with `collaboration.comments.create`.
|
|
@@ -1325,6 +1345,19 @@ type CollaborationCommentTarget = {
|
|
|
1325
1345
|
* })
|
|
1326
1346
|
* ```
|
|
1327
1347
|
*
|
|
1348
|
+
* #### Inline comment
|
|
1349
|
+
* ```ts
|
|
1350
|
+
* await client.collaboration.comments.create({
|
|
1351
|
+
* message,
|
|
1352
|
+
* target: {
|
|
1353
|
+
* documentId: 'doc-1',
|
|
1354
|
+
* documentType: 'article',
|
|
1355
|
+
* path: 'body',
|
|
1356
|
+
* range: {start: {_key: 'block-1', offset: 0}, end: {_key: 'block-1', offset: 5}},
|
|
1357
|
+
* },
|
|
1358
|
+
* })
|
|
1359
|
+
* ```
|
|
1360
|
+
*
|
|
1328
1361
|
* #### Reply
|
|
1329
1362
|
* ```ts
|
|
1330
1363
|
* await client.collaboration.comments.create({
|
|
@@ -1352,20 +1385,33 @@ type CollaborationCommentCreate = {
|
|
|
1352
1385
|
/**
|
|
1353
1386
|
* Fields that can be updated on an existing comment.
|
|
1354
1387
|
*
|
|
1388
|
+
* A `range` re-anchors the comment within the field it already targets.
|
|
1389
|
+
* Pass `null` to remove the selection and leave a field-level comment.
|
|
1390
|
+
* An optional `fieldValue` is Portable Text covering that `range`; when set,
|
|
1391
|
+
* the `range` is resolved from those blocks instead of from the live document.
|
|
1392
|
+
* `fieldValue` cannot be sent alone or together with `range: null`.
|
|
1393
|
+
*
|
|
1355
1394
|
* @alpha
|
|
1356
1395
|
*/
|
|
1357
|
-
|
|
1396
|
+
type CollaborationCommentUpdate = {
|
|
1358
1397
|
/** Replaces the current message */
|
|
1359
1398
|
message?: CollaborationCommentMessage;
|
|
1360
1399
|
/** Cascades to the comment's replies */
|
|
1361
1400
|
status?: CollaborationCommentStatus;
|
|
1401
|
+
} & ({
|
|
1402
|
+
range: CollaborationCommentRange;
|
|
1362
1403
|
/**
|
|
1363
|
-
*
|
|
1364
|
-
*
|
|
1365
|
-
* comment.
|
|
1404
|
+
* Portable Text covering the `range`. When set, the `range` is resolved
|
|
1405
|
+
* from these blocks instead of from the live document.
|
|
1366
1406
|
*/
|
|
1367
|
-
|
|
1368
|
-
}
|
|
1407
|
+
fieldValue?: CollaborationCommentFieldValue;
|
|
1408
|
+
} | {
|
|
1409
|
+
range: null;
|
|
1410
|
+
fieldValue?: never;
|
|
1411
|
+
} | {
|
|
1412
|
+
range?: undefined;
|
|
1413
|
+
fieldValue?: never;
|
|
1414
|
+
});
|
|
1369
1415
|
/**
|
|
1370
1416
|
* Comments on the configured organization resource.
|
|
1371
1417
|
*
|
|
@@ -2091,6 +2137,17 @@ interface InvokeFunctionRequest {
|
|
|
2091
2137
|
signal?: AbortSignal;
|
|
2092
2138
|
}
|
|
2093
2139
|
/** @public */
|
|
2140
|
+
interface InvokeFunctionOptions {
|
|
2141
|
+
/**
|
|
2142
|
+
* Wait for the function to finish and resolve with its return value.
|
|
2143
|
+
*
|
|
2144
|
+
* Defaults to `false`: the invocation is started, the request resolves as soon
|
|
2145
|
+
* as it is accepted, and the value is always `undefined`. Only function types
|
|
2146
|
+
* that support running inline can be invoked synchronously.
|
|
2147
|
+
*/
|
|
2148
|
+
sync?: boolean;
|
|
2149
|
+
}
|
|
2150
|
+
/** @public */
|
|
2094
2151
|
declare class ObservableFunctionsClient {
|
|
2095
2152
|
#private;
|
|
2096
2153
|
constructor(client: ObservableSanityClient$1, httpRequest: HttpRequest);
|
|
@@ -2098,12 +2155,21 @@ declare class ObservableFunctionsClient {
|
|
|
2098
2155
|
* Invoke a deployed function by its blueprint name.
|
|
2099
2156
|
*
|
|
2100
2157
|
* The name is resolved within the stack given by `stackId` on the request or
|
|
2101
|
-
* the client config.
|
|
2158
|
+
* the client config. Starts the invocation and emits `undefined` as soon as
|
|
2159
|
+
* it is accepted; pass `{sync: true}` to wait for the function's return value
|
|
2160
|
+
* instead.
|
|
2102
2161
|
*
|
|
2103
2162
|
* @param functionName - name of the function, as declared in the blueprint
|
|
2104
2163
|
* @param request - payload and request options
|
|
2164
|
+
* @param options - invocation options
|
|
2105
2165
|
*/
|
|
2106
|
-
invoke
|
|
2166
|
+
invoke(functionName: string, request?: InvokeFunctionRequest, options?: InvokeFunctionOptions & {
|
|
2167
|
+
sync?: false;
|
|
2168
|
+
}): Observable<undefined>;
|
|
2169
|
+
invoke<R = unknown>(functionName: string, request: InvokeFunctionRequest | undefined, options: InvokeFunctionOptions & {
|
|
2170
|
+
sync: true;
|
|
2171
|
+
}): Observable<R>;
|
|
2172
|
+
invoke<R = unknown>(functionName: string, request?: InvokeFunctionRequest, options?: InvokeFunctionOptions): Observable<R | undefined>;
|
|
2107
2173
|
}
|
|
2108
2174
|
/** @public */
|
|
2109
2175
|
declare class FunctionsClient {
|
|
@@ -2114,20 +2180,30 @@ declare class FunctionsClient {
|
|
|
2114
2180
|
*
|
|
2115
2181
|
* The name is resolved within the stack given by `stackId` on the request or
|
|
2116
2182
|
* the client config, which costs one extra request per call. Rejects if the
|
|
2117
|
-
* stack has no function by that name, or if the name resolves to
|
|
2118
|
-
*
|
|
2183
|
+
* stack has no function by that name, or if the name resolves to a function
|
|
2184
|
+
* type that cannot be invoked the way it was asked for.
|
|
2119
2185
|
*
|
|
2120
2186
|
* The lookup is scoped to `projectId`, or to `organizationId` when one is set
|
|
2121
2187
|
* for a stack deployed at organization scope.
|
|
2122
2188
|
*
|
|
2123
|
-
* The
|
|
2124
|
-
*
|
|
2125
|
-
*
|
|
2189
|
+
* The invocation is started by default: the promise resolves with `undefined`
|
|
2190
|
+
* as soon as the call is accepted, without waiting for the function to run.
|
|
2191
|
+
* Pass `{sync: true}` to keep the request open until the function finishes
|
|
2192
|
+
* and resolve with its return value — long-running functions may then need an
|
|
2193
|
+
* explicit `timeout`. Only `sanity.function.pubsub` functions can be invoked
|
|
2194
|
+
* synchronously.
|
|
2126
2195
|
*
|
|
2127
2196
|
* @param functionName - name of the function, as declared in the blueprint
|
|
2128
2197
|
* @param request - payload and request options
|
|
2198
|
+
* @param options - invocation options
|
|
2129
2199
|
*/
|
|
2130
|
-
invoke
|
|
2200
|
+
invoke(functionName: string, request?: InvokeFunctionRequest, options?: InvokeFunctionOptions & {
|
|
2201
|
+
sync?: false;
|
|
2202
|
+
}): Promise<undefined>;
|
|
2203
|
+
invoke<R = unknown>(functionName: string, request: InvokeFunctionRequest | undefined, options: InvokeFunctionOptions & {
|
|
2204
|
+
sync: true;
|
|
2205
|
+
}): Promise<R>;
|
|
2206
|
+
invoke<R = unknown>(functionName: string, request?: InvokeFunctionRequest, options?: InvokeFunctionOptions): Promise<R | undefined>;
|
|
2131
2207
|
}
|
|
2132
2208
|
/** @internal */
|
|
2133
2209
|
declare class ObservableMediaLibraryVideoClient {
|
|
@@ -6384,5 +6460,5 @@ interface MediaLibraryAssetDocument {
|
|
|
6384
6460
|
parent?: SanityReference | null;
|
|
6385
6461
|
rootDirectory?: Any$1;
|
|
6386
6462
|
}
|
|
6387
|
-
export { DisconnectEvent as $, UploadClientConfig as $n,
|
|
6388
|
-
//# sourceMappingURL=types-
|
|
6463
|
+
export { DisconnectEvent as $, UploadClientConfig as $n, CollaborationCommentMessage as $r, QueryWithoutParams as $t, ContentSourceMapMappings as A, AgentActionTarget as Ai, SanityReference as An, ObservableProjectsClient as Ar, MediaLibraryAssetVersion as At, CreateVersionAction as B, TransactionAllDocumentIdsMutationOptions as Bn, ObservablePatchBuilder as Br, MutationSelection as Bt, ContentSourceMap$1 as C, PatchDocument as Ci, SanityDocument$1 as Cn, GenerateTarget as Cr, LiveEventGoAway as Ct, ContentSourceMapDocuments$1 as D, AgentActionParams as Di, SanityProject as Dn, SanityClient$1 as Dr, LiveEventWelcome as Dt, ContentSourceMapDocumentValueSource as E, AgentActionParam as Ei, SanityImagePalette as En, ObservableSanityClient$1 as Er, LiveEventRestart as Et, ContentSourceMapValueMapping as F, StackablePerspective as Fn, InvokeFunctionOptions as Fr, Mutation as Ft, DatasetResponse as G, UnarchiveReleaseAction as Gn, ObservablePatch as Gr, PatchOperations as Gt, DatasetAclMode as H, TransactionFirstDocumentIdMutationOptions as Hn, PatchBuilder as Hr, OpenEvent as Ht, CreateAction as I, StillImageFormat as In, InvokeFunctionRequest as Ir, MutationError as It, DeleteReleaseAction as J, UnpublishAction as Jn, CollaborationCommentsClient as Jr, PublishReleaseAction as Jt, DatasetsResponse as K, UnfilteredResponseQueryOptions as Kn, Patch as Kr, PatchSelection as Kt, CreateReleaseAction as L, StoryboardTransformOptions as Ln, DatasetsClient as Lr, MutationErrorItem as Lt, ContentSourceMapRemoteDocument as M, DocumentAgentActionParam as Mi, ScheduleReleaseAction as Mn, MediaLibraryVideoClient as Mr, MediaLibraryVideoPlaybackTransformations as Mt, ContentSourceMapSource as N, FieldAgentActionParam as Ni, SingleActionResult as Nn, ObservableMediaLibraryVideoClient as Nr, MultipleActionResult as Nt, ContentSourceMapLiteralSource as O, AgentActionPath as Oi, SanityProjectMember as On, ObservableUsersClient as Or, MediaLibraryAssetDocument as Ot, ContentSourceMapUnknownSource as P, GroqAgentActionParam as Pi, SingleMutationResult as Pn, InvokeFunctionEvent as Pr, MultipleMutationResult as Pt, DiscardVersionAction as Q, UploadBody as Qn, CollaborationCommentFieldValue as Qr, QueryParseError as Qt, CreateVariantAction as R, SyncTag as Rn, ObservableDatasetsClient as Rr, MutationEvent as Rt, ClientVariantConditions as S, PromptRequest as Si, SanityAssetDocument as Sn, GenerateOperation as Sr, LiveEvent as St, ContentSourceMapDocumentBase as T, PatchTarget as Ti, SanityImageAssetDocument as Tn, GenerateTargetInclude as Tr, LiveEventReconnect as Tt, DatasetCreateOptions as U, TransactionFirstDocumentMutationOptions as Un, Transaction as Ur, PartialExcept as Ut, CurrentSanityUser as V, TransactionAllDocumentsMutationOptions as Vn, ObservableTransaction as Vr, MutationSelectionQueryParams as Vt, DatasetEditOptions as W, TransactionMutationOptions as Wn, BasePatch as Wr, PatchMutationOperation as Wt, DeleteVariantDefinitionAction as X, UnpublishVersionAction as Xn, CollaborationCommentCreate as Xr, QueryOptions as Xt, DeleteVariantAction as Y, UnpublishVariantAction as Yn, ObservableCollaborationCommentsClient as Yr, PublishVariantAction as Yt, DiscardAction as Z, UnscheduleReleaseAction as Zn, CollaborationCommentDocument as Zr, QueryParams as Zt, ChannelErrorEvent as _, TransformDocument as _i, Requester as _n, VideoSubtitleInfoPublic as _r, InsertPatch as _t, AllDocumentsMutationOptions as a, CollaborationCommentTarget as ai, ReleaseCardinality as an, VersionAction as ar, EditableReleaseDocument as at, ClientReturn$1 as b, TransformTargetDocument as bi, ResumableListenEventNames as bn, WelcomeEvent as br, ListenOptions as bt, Any$1 as c, CollaborationCommentsRequestOptions as ci, ReleaseState as cn, VideoPlaybackInfoItemPublic as cr, ErrorProps as ct, AssetMetadataType as d, AssetsClient as di, ReplaceVersionAction as dn, VideoPlaybackInfoSigned as dr, FirstDocumentMutationOptions as dt, CollaborationCommentPortableTextBlock as ei, RawQueryResponse$1 as en, UploadEvent as er, EXPERIMENTAL_API_WARNING as et, AttributeSet as f, ObservableAssetsClient as fi, RequestHandler as fn, VideoPlaybackTokens as fr, FitMode as ft, BaseMutationOptions as g, ImageDescriptionOperation as gi, RequestUrlOptions as gn, VideoSubtitleInfo as gr, InitializedClientConfig$1 as gt, BaseActionOptions as h, TranslateTargetInclude as hi, RequestOptions$1 as hn, VideoRenditionInfoSigned as hr, ImportReleaseAction as ht, AllDocumentIdsMutationOptions as i, CollaborationCommentStatus as ii, ReleaseAction as in, VariantDefinitionAction as ir, EditVariantDefinitionAction as it, ContentSourceMapPaths as j, ConstantAgentActionParam as ji, SanityUser as jn, ProjectsClient as jr, MediaLibraryPlaybackInfoOptions as jt, ContentSourceMapMapping as k, AgentActionPathSegment as ki, SanityQueries as kn, UsersClient as kr, MediaLibraryAssetInstanceIdentifier as kt, ApiError as l, CollaborationCommentsWriteOptions as li, ReleaseType as ln, VideoPlaybackInfoItemSigned as lr, FilteredResponseQueryOptions as lt, AuthProviderResponse as m, TranslateTarget as mi, RequestObservableOptions as mn, VideoRenditionInfoPublic as mr, IdentifiedSanityDocumentStub as mt, ActionError as n, CollaborationCommentReactionShortName as ni, RawRequestOptions as nn, UploadResponseEvent as nr, EditReleaseAction as nt, AnimatedImageFormat as o, CollaborationCommentUpdate as oi, ReleaseDocument as on, VideoPlaybackInfo as or, EmbeddingsSettings as ot, AuthProvider as p, TranslateDocument as pi, RequestHandlerOptions as pn, VideoRenditionInfo as pr, HttpRequest as pt, DeleteAction as q, UnfilteredResponseWithoutQuery as qn, LiveClient as qr, PublishAction as qt, ActionErrorItem as r, CollaborationCommentSelection as ri, ReconnectEvent as rn, VariantAction as rr, EditVariantAction as rt, AnimatedTransformOptions as s, CollaborationCommentsListenOptions as si, ReleaseId as sn, VideoPlaybackInfoItem as sr, EmbeddingsSettingsBody as st, Action as t, CollaborationCommentRange as ti, RawQuerylessQueryResponse as tn, UploadProgressEvent as tr, EditAction as tt, ArchiveReleaseAction as u, _listen as ui, ReplaceDraftAction as un, VideoPlaybackInfoPublic as ur, FirstDocumentIdMutationOptions as ut, ClientConfig$1 as v, TransformOperation as vi, ResetEvent as vn, VideoSubtitleInfoSigned as vr, ListenEvent as vt, ContentSourceMapDocument as w, PatchOperation as wi, SanityDocumentStub as wn, GenerateTargetDocument as wr, LiveEventMessage as wt, ClientVariant as x, TransformTargetInclude as xi, ResumableListenOptions as xn, GenerateInstruction as xr, ListenParams as xt, ClientPerspective$1 as y, TransformTarget as yi, ResponseQueryOptions as yn, WelcomeBackEvent as yr, ListenEventName as yt, CreateVariantDefinitionAction as z, ThumbnailTransformOptions as zn, BaseTransaction as zr, MutationOperation as zt };
|
|
6464
|
+
//# sourceMappingURL=types-0x2hPfhJ.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/client",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.3.0",
|
|
4
4
|
"description": "Client for retrieving, creating and patching data from Sanity.io",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api",
|
|
@@ -51,7 +51,6 @@
|
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"eventsource": "^5.1.0",
|
|
53
53
|
"get-it": "^9.5.0",
|
|
54
|
-
"nanoid": "^6.0.1",
|
|
55
54
|
"obug": "^2.1.4",
|
|
56
55
|
"rxjs": "^7.8.2"
|
|
57
56
|
},
|
|
@@ -161,6 +161,18 @@ export interface CollaborationCommentRange {
|
|
|
161
161
|
end: {_key: string; offset: number}
|
|
162
162
|
}
|
|
163
163
|
|
|
164
|
+
/**
|
|
165
|
+
* Portable Text covering a comment `range`. Callers can send just the blocks
|
|
166
|
+
* from the `range` start `_key` through end `_key`, or the full field.
|
|
167
|
+
*
|
|
168
|
+
* @alpha
|
|
169
|
+
*/
|
|
170
|
+
export type CollaborationCommentFieldValue = Array<{
|
|
171
|
+
_type: string
|
|
172
|
+
_key: string
|
|
173
|
+
[key: string]: Any
|
|
174
|
+
}>
|
|
175
|
+
|
|
164
176
|
/**
|
|
165
177
|
* Target for a top-level comment. Inline selections require both `path` and
|
|
166
178
|
* `range`; field-level comments may set `path` alone.
|
|
@@ -169,6 +181,9 @@ export interface CollaborationCommentRange {
|
|
|
169
181
|
* `target.path.field`, and `range` is resolved against the document into
|
|
170
182
|
* `target.path.selection` and `contentSnapshot` rather than being stored.
|
|
171
183
|
*
|
|
184
|
+
* An optional `fieldValue` is Portable Text covering the `range`. When set,
|
|
185
|
+
* the `range` is resolved from those blocks instead of from the live document.
|
|
186
|
+
*
|
|
172
187
|
* @alpha
|
|
173
188
|
*/
|
|
174
189
|
export type CollaborationCommentTarget = {
|
|
@@ -180,11 +195,17 @@ export type CollaborationCommentTarget = {
|
|
|
180
195
|
/** Path to the field containing the inline comment selection */
|
|
181
196
|
path: string
|
|
182
197
|
range: CollaborationCommentRange
|
|
198
|
+
/**
|
|
199
|
+
* Portable Text covering the `range`. When set, the `range` is resolved
|
|
200
|
+
* from these blocks instead of from the live document.
|
|
201
|
+
*/
|
|
202
|
+
fieldValue?: CollaborationCommentFieldValue
|
|
183
203
|
}
|
|
184
204
|
| {
|
|
185
205
|
/** Path to the commented field */
|
|
186
206
|
path?: string
|
|
187
207
|
range?: never
|
|
208
|
+
fieldValue?: never
|
|
188
209
|
}
|
|
189
210
|
)
|
|
190
211
|
|
|
@@ -205,6 +226,19 @@ export type CollaborationCommentTarget = {
|
|
|
205
226
|
* })
|
|
206
227
|
* ```
|
|
207
228
|
*
|
|
229
|
+
* #### Inline comment
|
|
230
|
+
* ```ts
|
|
231
|
+
* await client.collaboration.comments.create({
|
|
232
|
+
* message,
|
|
233
|
+
* target: {
|
|
234
|
+
* documentId: 'doc-1',
|
|
235
|
+
* documentType: 'article',
|
|
236
|
+
* path: 'body',
|
|
237
|
+
* range: {start: {_key: 'block-1', offset: 0}, end: {_key: 'block-1', offset: 5}},
|
|
238
|
+
* },
|
|
239
|
+
* })
|
|
240
|
+
* ```
|
|
241
|
+
*
|
|
208
242
|
* #### Reply
|
|
209
243
|
* ```ts
|
|
210
244
|
* await client.collaboration.comments.create({
|
|
@@ -236,17 +270,34 @@ export type CollaborationCommentCreate = {
|
|
|
236
270
|
/**
|
|
237
271
|
* Fields that can be updated on an existing comment.
|
|
238
272
|
*
|
|
273
|
+
* A `range` re-anchors the comment within the field it already targets.
|
|
274
|
+
* Pass `null` to remove the selection and leave a field-level comment.
|
|
275
|
+
* An optional `fieldValue` is Portable Text covering that `range`; when set,
|
|
276
|
+
* the `range` is resolved from those blocks instead of from the live document.
|
|
277
|
+
* `fieldValue` cannot be sent alone or together with `range: null`.
|
|
278
|
+
*
|
|
239
279
|
* @alpha
|
|
240
280
|
*/
|
|
241
|
-
export
|
|
281
|
+
export type CollaborationCommentUpdate = {
|
|
242
282
|
/** Replaces the current message */
|
|
243
283
|
message?: CollaborationCommentMessage
|
|
244
284
|
/** Cascades to the comment's replies */
|
|
245
285
|
status?: CollaborationCommentStatus
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
286
|
+
} & (
|
|
287
|
+
| {
|
|
288
|
+
range: CollaborationCommentRange
|
|
289
|
+
/**
|
|
290
|
+
* Portable Text covering the `range`. When set, the `range` is resolved
|
|
291
|
+
* from these blocks instead of from the live document.
|
|
292
|
+
*/
|
|
293
|
+
fieldValue?: CollaborationCommentFieldValue
|
|
294
|
+
}
|
|
295
|
+
| {
|
|
296
|
+
range: null
|
|
297
|
+
fieldValue?: never
|
|
298
|
+
}
|
|
299
|
+
| {
|
|
300
|
+
range?: undefined
|
|
301
|
+
fieldValue?: never
|
|
302
|
+
}
|
|
303
|
+
)
|
|
@@ -2,7 +2,7 @@ import {lastValueFrom, type Observable} from 'rxjs'
|
|
|
2
2
|
|
|
3
3
|
import type {ObservableSanityClient, SanityClient} from '../SanityClient'
|
|
4
4
|
import type {HttpRequest} from '../types'
|
|
5
|
-
import {_invoke, type InvokeFunctionRequest} from './invoke'
|
|
5
|
+
import {_invoke, type InvokeFunctionOptions, type InvokeFunctionRequest} from './invoke'
|
|
6
6
|
|
|
7
7
|
/** @public */
|
|
8
8
|
export class ObservableFunctionsClient {
|
|
@@ -17,16 +17,36 @@ export class ObservableFunctionsClient {
|
|
|
17
17
|
* Invoke a deployed function by its blueprint name.
|
|
18
18
|
*
|
|
19
19
|
* The name is resolved within the stack given by `stackId` on the request or
|
|
20
|
-
* the client config.
|
|
20
|
+
* the client config. Starts the invocation and emits `undefined` as soon as
|
|
21
|
+
* it is accepted; pass `{sync: true}` to wait for the function's return value
|
|
22
|
+
* instead.
|
|
21
23
|
*
|
|
22
24
|
* @param functionName - name of the function, as declared in the blueprint
|
|
23
25
|
* @param request - payload and request options
|
|
26
|
+
* @param options - invocation options
|
|
24
27
|
*/
|
|
28
|
+
invoke(
|
|
29
|
+
functionName: string,
|
|
30
|
+
request?: InvokeFunctionRequest,
|
|
31
|
+
options?: InvokeFunctionOptions & {sync?: false},
|
|
32
|
+
): Observable<undefined>
|
|
33
|
+
invoke<R = unknown>(
|
|
34
|
+
functionName: string,
|
|
35
|
+
request: InvokeFunctionRequest | undefined,
|
|
36
|
+
options: InvokeFunctionOptions & {sync: true},
|
|
37
|
+
): Observable<R>
|
|
38
|
+
invoke<R = unknown>(
|
|
39
|
+
functionName: string,
|
|
40
|
+
request?: InvokeFunctionRequest,
|
|
41
|
+
options?: InvokeFunctionOptions,
|
|
42
|
+
): Observable<R | undefined>
|
|
43
|
+
// Implementation signature — not part of the public API.
|
|
25
44
|
invoke<R = unknown>(
|
|
26
45
|
functionName: string,
|
|
27
46
|
request?: InvokeFunctionRequest,
|
|
47
|
+
options?: InvokeFunctionOptions,
|
|
28
48
|
): Observable<R | undefined> {
|
|
29
|
-
return _invoke<R>(this.#client, this.#httpRequest, functionName, request)
|
|
49
|
+
return _invoke<R>(this.#client, this.#httpRequest, functionName, request, options)
|
|
30
50
|
}
|
|
31
51
|
}
|
|
32
52
|
|
|
@@ -44,23 +64,46 @@ export class FunctionsClient {
|
|
|
44
64
|
*
|
|
45
65
|
* The name is resolved within the stack given by `stackId` on the request or
|
|
46
66
|
* the client config, which costs one extra request per call. Rejects if the
|
|
47
|
-
* stack has no function by that name, or if the name resolves to
|
|
48
|
-
*
|
|
67
|
+
* stack has no function by that name, or if the name resolves to a function
|
|
68
|
+
* type that cannot be invoked the way it was asked for.
|
|
49
69
|
*
|
|
50
70
|
* The lookup is scoped to `projectId`, or to `organizationId` when one is set
|
|
51
71
|
* for a stack deployed at organization scope.
|
|
52
72
|
*
|
|
53
|
-
* The
|
|
54
|
-
*
|
|
55
|
-
*
|
|
73
|
+
* The invocation is started by default: the promise resolves with `undefined`
|
|
74
|
+
* as soon as the call is accepted, without waiting for the function to run.
|
|
75
|
+
* Pass `{sync: true}` to keep the request open until the function finishes
|
|
76
|
+
* and resolve with its return value — long-running functions may then need an
|
|
77
|
+
* explicit `timeout`. Only `sanity.function.pubsub` functions can be invoked
|
|
78
|
+
* synchronously.
|
|
56
79
|
*
|
|
57
80
|
* @param functionName - name of the function, as declared in the blueprint
|
|
58
81
|
* @param request - payload and request options
|
|
82
|
+
* @param options - invocation options
|
|
59
83
|
*/
|
|
84
|
+
invoke(
|
|
85
|
+
functionName: string,
|
|
86
|
+
request?: InvokeFunctionRequest,
|
|
87
|
+
options?: InvokeFunctionOptions & {sync?: false},
|
|
88
|
+
): Promise<undefined>
|
|
89
|
+
invoke<R = unknown>(
|
|
90
|
+
functionName: string,
|
|
91
|
+
request: InvokeFunctionRequest | undefined,
|
|
92
|
+
options: InvokeFunctionOptions & {sync: true},
|
|
93
|
+
): Promise<R>
|
|
94
|
+
invoke<R = unknown>(
|
|
95
|
+
functionName: string,
|
|
96
|
+
request?: InvokeFunctionRequest,
|
|
97
|
+
options?: InvokeFunctionOptions,
|
|
98
|
+
): Promise<R | undefined>
|
|
99
|
+
// Implementation signature — not part of the public API.
|
|
60
100
|
invoke<R = unknown>(
|
|
61
101
|
functionName: string,
|
|
62
102
|
request?: InvokeFunctionRequest,
|
|
103
|
+
options?: InvokeFunctionOptions,
|
|
63
104
|
): Promise<R | undefined> {
|
|
64
|
-
return lastValueFrom(
|
|
105
|
+
return lastValueFrom(
|
|
106
|
+
_invoke<R>(this.#client, this.#httpRequest, functionName, request, options),
|
|
107
|
+
)
|
|
65
108
|
}
|
|
66
109
|
}
|
package/src/functions/invoke.ts
CHANGED
|
@@ -6,7 +6,15 @@ import type {HttpRequest, InitializedClientConfig} from '../types'
|
|
|
6
6
|
|
|
7
7
|
/** Function resource types in a blueprint are namespaced under this prefix. */
|
|
8
8
|
const FUNCTION_RESOURCE_PREFIX = 'sanity.function.'
|
|
9
|
-
const
|
|
9
|
+
const SYNC_INVOCABLE_FUNCTION_TYPES = ['sanity.function.pubsub']
|
|
10
|
+
const ASYNC_INVOCABLE_FUNCTION_TYPES = [
|
|
11
|
+
'sanity.function.durable',
|
|
12
|
+
'sanity.function.pubsub',
|
|
13
|
+
'sanity.function.queue',
|
|
14
|
+
]
|
|
15
|
+
const INVOCABLE_FUNCTION_TYPES = [
|
|
16
|
+
...new Set([...SYNC_INVOCABLE_FUNCTION_TYPES, ...ASYNC_INVOCABLE_FUNCTION_TYPES]),
|
|
17
|
+
]
|
|
10
18
|
|
|
11
19
|
/** @public */
|
|
12
20
|
export interface InvokeFunctionEvent {
|
|
@@ -37,6 +45,18 @@ export interface InvokeFunctionRequest {
|
|
|
37
45
|
signal?: AbortSignal
|
|
38
46
|
}
|
|
39
47
|
|
|
48
|
+
/** @public */
|
|
49
|
+
export interface InvokeFunctionOptions {
|
|
50
|
+
/**
|
|
51
|
+
* Wait for the function to finish and resolve with its return value.
|
|
52
|
+
*
|
|
53
|
+
* Defaults to `false`: the invocation is started, the request resolves as soon
|
|
54
|
+
* as it is accepted, and the value is always `undefined`. Only function types
|
|
55
|
+
* that support running inline can be invoked synchronously.
|
|
56
|
+
*/
|
|
57
|
+
sync?: boolean
|
|
58
|
+
}
|
|
59
|
+
|
|
40
60
|
/**
|
|
41
61
|
* Subset of a stack resource the client needs in order to resolve a name.
|
|
42
62
|
*
|
|
@@ -109,6 +129,7 @@ function _resolveFunctionId(
|
|
|
109
129
|
stackId: string,
|
|
110
130
|
headers: Record<string, string>,
|
|
111
131
|
request: InvokeFunctionRequest | undefined,
|
|
132
|
+
sync: boolean,
|
|
112
133
|
): Observable<string> {
|
|
113
134
|
return _requestObservable<{resources?: StackResource[]}>(client, httpRequest, {
|
|
114
135
|
method: 'GET',
|
|
@@ -132,9 +153,15 @@ function _resolveFunctionId(
|
|
|
132
153
|
)
|
|
133
154
|
}
|
|
134
155
|
|
|
135
|
-
if (match.type
|
|
156
|
+
if (!INVOCABLE_FUNCTION_TYPES.includes(match.type)) {
|
|
136
157
|
throw new Error(`Function invocation is not supported for ${match.type}`)
|
|
137
158
|
}
|
|
159
|
+
if (sync && !SYNC_INVOCABLE_FUNCTION_TYPES.includes(match.type)) {
|
|
160
|
+
throw new Error(`Synchronous function invocation is not supported for ${match.type}`)
|
|
161
|
+
}
|
|
162
|
+
if (!sync && !ASYNC_INVOCABLE_FUNCTION_TYPES.includes(match.type)) {
|
|
163
|
+
throw new Error(`Asynchronous function invocation is not supported for ${match.type}`)
|
|
164
|
+
}
|
|
138
165
|
|
|
139
166
|
return match.externalId
|
|
140
167
|
}),
|
|
@@ -147,6 +174,7 @@ export function _invoke<R = unknown>(
|
|
|
147
174
|
httpRequest: HttpRequest,
|
|
148
175
|
functionName: string,
|
|
149
176
|
request?: InvokeFunctionRequest,
|
|
177
|
+
options?: InvokeFunctionOptions,
|
|
150
178
|
): Observable<R | undefined> {
|
|
151
179
|
// Deferred so a bad config surfaces as an error on the returned observable
|
|
152
180
|
// (and so a rejected promise) rather than throwing at the call site.
|
|
@@ -154,17 +182,30 @@ export function _invoke<R = unknown>(
|
|
|
154
182
|
const config = client.config()
|
|
155
183
|
const headers = scopeHeaders(config, request)
|
|
156
184
|
const stackId = resolveStackId(config, request)
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
185
|
+
const sync = options?.sync ?? false
|
|
186
|
+
|
|
187
|
+
return _resolveFunctionId(
|
|
188
|
+
client,
|
|
189
|
+
httpRequest,
|
|
190
|
+
functionName,
|
|
191
|
+
stackId,
|
|
192
|
+
headers,
|
|
193
|
+
request,
|
|
194
|
+
sync,
|
|
195
|
+
).pipe(
|
|
196
|
+
// An async invocation is only acknowledged (202, no body), and a sync
|
|
197
|
+
// function that returns nothing answers 204, which the transport parses
|
|
160
198
|
// to an `undefined` body. The status code is not observable from here —
|
|
161
199
|
// the `HttpRequest` boundary resolves to the body alone — so an empty
|
|
162
200
|
// response and a function that returned nothing both surface as
|
|
163
201
|
// `undefined`.
|
|
202
|
+
//
|
|
203
|
+
// The route is async by default, so `sync=false` is left off the wire
|
|
204
|
+
// rather than spelled out.
|
|
164
205
|
mergeMap((functionId) =>
|
|
165
206
|
_requestObservable<R | undefined>(client, httpRequest, {
|
|
166
207
|
method: 'POST',
|
|
167
|
-
url: `/functions/${functionId}/invoke`,
|
|
208
|
+
url: `/functions/${functionId}/invoke${sync ? '?sync=true' : ''}`,
|
|
168
209
|
headers,
|
|
169
210
|
body: {event: {data: request?.event?.data ?? {}}},
|
|
170
211
|
timeout: request?.timeout,
|
package/src/types.ts
CHANGED
|
@@ -2297,7 +2297,11 @@ export type {
|
|
|
2297
2297
|
TranslateTarget,
|
|
2298
2298
|
TranslateTargetInclude,
|
|
2299
2299
|
} from './agent/actions/translate'
|
|
2300
|
-
export type {
|
|
2300
|
+
export type {
|
|
2301
|
+
InvokeFunctionEvent,
|
|
2302
|
+
InvokeFunctionOptions,
|
|
2303
|
+
InvokeFunctionRequest,
|
|
2304
|
+
} from './functions/invoke'
|
|
2301
2305
|
export type {
|
|
2302
2306
|
CollaborationCommentCreate,
|
|
2303
2307
|
CollaborationCommentDocument,
|
|
@@ -2312,6 +2316,7 @@ export type {
|
|
|
2312
2316
|
CollaborationCommentTarget,
|
|
2313
2317
|
CollaborationCommentUpdate,
|
|
2314
2318
|
CollaborationCommentRange,
|
|
2319
|
+
CollaborationCommentFieldValue,
|
|
2315
2320
|
} from './collaboration/types'
|
|
2316
2321
|
export type {
|
|
2317
2322
|
ContentSourceMapParsedPath,
|
|
@@ -5,20 +5,30 @@ import {
|
|
|
5
5
|
isDraftId,
|
|
6
6
|
isVersionId,
|
|
7
7
|
} from '@sanity/client/csm'
|
|
8
|
-
import {customAlphabet} from 'nanoid'
|
|
9
8
|
|
|
10
9
|
import type {IdentifiedSanityDocumentStub, SanityDocumentStub} from '../types'
|
|
11
10
|
import {validateVersionIdMatch} from '../validators'
|
|
12
11
|
|
|
12
|
+
const alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
|
|
13
|
+
|
|
13
14
|
/**
|
|
14
15
|
* @internal
|
|
15
16
|
*
|
|
16
17
|
* ~24 years (or 7.54e+8 seconds) needed, in order to have a 1% probability of at least one collision if 10 ID's are generated every hour.
|
|
17
18
|
*/
|
|
18
|
-
export
|
|
19
|
-
'
|
|
20
|
-
|
|
21
|
-
)
|
|
19
|
+
export function generateReleaseId() {
|
|
20
|
+
let id = ''
|
|
21
|
+
|
|
22
|
+
while (id.length < 8) {
|
|
23
|
+
const bytes = crypto.getRandomValues(new Uint8Array(8 - id.length))
|
|
24
|
+
for (const byte of bytes) {
|
|
25
|
+
const index = byte & 63
|
|
26
|
+
if (index < alphabet.length) id += alphabet[index]
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return id
|
|
31
|
+
}
|
|
22
32
|
|
|
23
33
|
/** @internal */
|
|
24
34
|
export const getDocumentVersionId = (publishedId: string, releaseId?: string) =>
|