@sanity/client 3.3.2 → 3.3.3-esm.10
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 +1 -1
- package/dist/sanityClient.browser.mjs +2948 -0
- package/dist/sanityClient.browser.mjs.map +7 -0
- package/lib/assets/assetsClient.js +29 -15
- package/lib/auth/authClient.js +11 -3
- package/lib/config.js +40 -22
- package/lib/data/dataMethods.js +38 -24
- package/lib/data/encodeQueryString.js +9 -2
- package/lib/data/listen.js +30 -22
- package/lib/data/patch.js +36 -27
- package/lib/data/transaction.js +27 -11
- package/lib/datasets/datasetsClient.js +18 -4
- package/lib/generateHelpUrl.js +13 -0
- package/lib/http/browserMiddleware.js +7 -1
- package/lib/http/errors.js +16 -8
- package/lib/http/nodeMiddleware.js +16 -7
- package/lib/http/queryString.js +10 -2
- package/lib/http/request.js +23 -23
- package/lib/http/requestOptions.js +13 -5
- package/lib/projects/projectsClient.js +11 -3
- package/lib/sanityClient.js +59 -45
- package/lib/users/usersClient.js +11 -3
- package/lib/util/defaults.js +10 -2
- package/lib/util/getSelection.js +9 -2
- package/lib/util/observable.js +24 -13
- package/lib/util/once.js +10 -2
- package/lib/util/pick.js +10 -2
- package/lib/validators.js +38 -15
- package/lib/warnings.js +16 -6
- package/package.json +45 -19
- package/sanityClient.d.ts +114 -18
- package/umd/sanityClient.js +173 -105
- package/umd/sanityClient.min.js +1 -1
- package/test/client.test.js +0 -2561
- package/test/encodeQueryString.test.js +0 -36
- package/test/fixtures/horsehead-nebula.jpg +0 -0
- package/test/fixtures/pdf-sample.pdf +0 -0
- package/test/helpers/sseServer.js +0 -26
- package/test/listen.test.js +0 -205
- package/test/warnings.test.disabled.js +0 -80
package/lib/warnings.js
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.printNoApiVersionSpecifiedWarning = exports.printCdnWarning = exports.printBrowserTokenWarning = void 0;
|
|
4
7
|
|
|
5
|
-
var
|
|
8
|
+
var _generateHelpUrl = _interopRequireDefault(require("./generateHelpUrl"));
|
|
9
|
+
|
|
10
|
+
var _once = _interopRequireDefault(require("./util/once"));
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
6
13
|
|
|
7
14
|
var createWarningPrinter = function createWarningPrinter(message) {
|
|
8
15
|
return (// eslint-disable-next-line no-console
|
|
9
|
-
|
|
16
|
+
(0, _once.default)(function () {
|
|
10
17
|
var _console;
|
|
11
18
|
|
|
12
19
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
@@ -18,6 +25,9 @@ var createWarningPrinter = function createWarningPrinter(message) {
|
|
|
18
25
|
);
|
|
19
26
|
};
|
|
20
27
|
|
|
21
|
-
|
|
22
|
-
exports.
|
|
23
|
-
|
|
28
|
+
var printCdnWarning = createWarningPrinter(['You are not using the Sanity CDN. That means your data is always fresh, but the CDN is faster and', "cheaper. Think about it! For more info, see ".concat((0, _generateHelpUrl.default)('js-client-cdn-configuration'), "."), 'To hide this warning, please set the `useCdn` option to either `true` or `false` when creating', 'the client.']);
|
|
29
|
+
exports.printCdnWarning = printCdnWarning;
|
|
30
|
+
var printBrowserTokenWarning = createWarningPrinter(['You have configured Sanity client to use a token in the browser. This may cause unintentional security issues.', "See ".concat((0, _generateHelpUrl.default)('js-client-browser-token'), " for more information and how to hide this warning.")]);
|
|
31
|
+
exports.printBrowserTokenWarning = printBrowserTokenWarning;
|
|
32
|
+
var printNoApiVersionSpecifiedWarning = createWarningPrinter(['Using the Sanity client without specifying an API version is deprecated.', "See ".concat((0, _generateHelpUrl.default)('js-client-api-version'))]);
|
|
33
|
+
exports.printNoApiVersionSpecifiedWarning = printNoApiVersionSpecifiedWarning;
|
package/package.json
CHANGED
|
@@ -1,22 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/client",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.3-esm.10",
|
|
4
4
|
"description": "Client for retrieving, creating and patching data from Sanity.io",
|
|
5
|
+
"type": "commonjs",
|
|
5
6
|
"main": "lib/sanityClient.js",
|
|
6
7
|
"umd": "umd/sanityClient.min.js",
|
|
7
8
|
"unpkg": "umd/sanityClient.min.js",
|
|
8
9
|
"types": "./sanityClient.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"source": "./src/sanityClient.js",
|
|
13
|
+
"types": "./sanityClient.d.ts",
|
|
14
|
+
"browser": "./dist/sanityClient.browser.mjs",
|
|
15
|
+
"deno": "./dist/sanityClient.browser.mjs",
|
|
16
|
+
"default": "./lib/sanityClient.js"
|
|
17
|
+
},
|
|
18
|
+
"./package.json": "./package.json"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist",
|
|
22
|
+
"lib",
|
|
23
|
+
"umd",
|
|
24
|
+
"sanityClient.d.ts"
|
|
25
|
+
],
|
|
9
26
|
"scripts": {
|
|
10
27
|
"browserify": "NODE_ENV=production BROWSERIFY_ENV=build DEBUG='' browserify -t envify -g uglifyify lib/sanityClient.js -o umd/sanityClient.js --standalone=SanityClient",
|
|
11
28
|
"compile": "babel -d lib src",
|
|
12
|
-
"build": "npm run compile && npm run browserify && npm run minify",
|
|
29
|
+
"build": "npm run compile && npm run browserify && npm run minify && npm run esbuild:browser",
|
|
30
|
+
"esbuild": "esbuild src/sanityClient.js --bundle --sourcemap --external:get-it",
|
|
31
|
+
"esbuild-when-upstream-deps-works-in-deno-cloudflare-and-vercel": "esbuild src/sanityClient.js --bundle --sourcemap --external:rxjs --external:@sanity/eventsource --external:get-it --external:make-error",
|
|
32
|
+
"esbuild:browser": "npm run esbuild -- --format=esm --outfile=dist/sanityClient.browser.mjs --platform=browser",
|
|
13
33
|
"lint": "eslint .",
|
|
14
|
-
"clean": "rimraf lib coverage .nyc_output umd/*.js",
|
|
34
|
+
"clean": "rimraf dist lib coverage .nyc_output umd/*.js",
|
|
35
|
+
"typecheck": "tsc --lib es2015 --lib dom,es2015 --noEmit sanityClient.d.ts",
|
|
15
36
|
"coverage": "DEBUG=sanity NODE_ENV=test nyc --reporter=html --reporter=lcov --reporter=text npm test",
|
|
16
37
|
"minify": "terser -c -m -- umd/sanityClient.js > umd/sanityClient.min.js",
|
|
17
|
-
"prepublishOnly": "npm run build",
|
|
18
|
-
"test": "NODE_ENV=test tape test/*.test.js",
|
|
19
|
-
"posttest": "npm run lint"
|
|
38
|
+
"prepublishOnly": "npm run clean && npm run build",
|
|
39
|
+
"test": "NODE_ENV=test babel-tape-runner test/*.test.js",
|
|
40
|
+
"posttest": "npm run lint && npm run typecheck"
|
|
20
41
|
},
|
|
21
42
|
"browser": {
|
|
22
43
|
"./src/http/nodeMiddleware.js": "./src/http/browserMiddleware.js",
|
|
@@ -27,29 +48,34 @@
|
|
|
27
48
|
},
|
|
28
49
|
"dependencies": {
|
|
29
50
|
"@sanity/eventsource": "^4.0.0",
|
|
30
|
-
"
|
|
31
|
-
"get-it": "^6.0.1",
|
|
51
|
+
"get-it": "6.1.1-esm.8",
|
|
32
52
|
"make-error": "^1.3.0",
|
|
33
|
-
"
|
|
34
|
-
"rxjs": "^6.0.0"
|
|
53
|
+
"rxjs": "^6.6.7"
|
|
35
54
|
},
|
|
36
55
|
"devDependencies": {
|
|
37
|
-
"@babel/cli": "^7.
|
|
38
|
-
"@babel/core": "^7.
|
|
39
|
-
"@babel/
|
|
56
|
+
"@babel/cli": "^7.18.10",
|
|
57
|
+
"@babel/core": "^7.18.10",
|
|
58
|
+
"@babel/plugin-transform-object-assign": "^7.18.6",
|
|
59
|
+
"@babel/preset-env": "^7.18.10",
|
|
60
|
+
"@types/node": "^16.11.49",
|
|
61
|
+
"babel-plugin-add-module-exports": "^1.0.4",
|
|
62
|
+
"babel-plugin-istanbul": "^6.1.1",
|
|
63
|
+
"babel-tape-runner": "^3.0.0",
|
|
40
64
|
"browserify": "^17.0.0",
|
|
41
65
|
"envify": "^4.0.0",
|
|
42
|
-
"
|
|
66
|
+
"esbuild": "^0.15.5",
|
|
67
|
+
"eslint": "^8.21.0",
|
|
43
68
|
"eslint-config-prettier": "^8.5.0",
|
|
44
|
-
"eslint-config-sanity": "^
|
|
45
|
-
"nock": "^13.2.
|
|
69
|
+
"eslint-config-sanity": "^6.0.0",
|
|
70
|
+
"nock": "^13.2.9",
|
|
46
71
|
"nyc": "^15.1.0",
|
|
47
|
-
"prettier": "^2.
|
|
72
|
+
"prettier": "^2.7.1",
|
|
48
73
|
"rimraf": "^3.0.2",
|
|
49
74
|
"sse-channel": "^4.0.0",
|
|
50
|
-
"tape": "^5.5.
|
|
75
|
+
"tape": "^5.5.3",
|
|
51
76
|
"terser": "^5.12.1",
|
|
52
|
-
"
|
|
77
|
+
"typescript": "^4.7.4",
|
|
78
|
+
"uglifyify": "^5.0.0",
|
|
53
79
|
"xtend": "4.0.2"
|
|
54
80
|
},
|
|
55
81
|
"repository": {
|
package/sanityClient.d.ts
CHANGED
|
@@ -224,14 +224,7 @@ export interface MultipleMutationResult {
|
|
|
224
224
|
results: {id: string; operation: MutationOperation}[]
|
|
225
225
|
}
|
|
226
226
|
|
|
227
|
-
export class
|
|
228
|
-
constructor(documentId: string, operations?: PatchOperations, client?: SanityClient)
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
* Clones the patch
|
|
232
|
-
*/
|
|
233
|
-
clone(): Patch
|
|
234
|
-
|
|
227
|
+
export abstract class BasePatch {
|
|
235
228
|
/**
|
|
236
229
|
* DEPRECATED: Don't use.
|
|
237
230
|
* The operation is added to the current patch, ready to be commited by `commit()`
|
|
@@ -339,6 +332,20 @@ export class Patch {
|
|
|
339
332
|
*/
|
|
340
333
|
toJSON(): PatchMutationOperation
|
|
341
334
|
|
|
335
|
+
/**
|
|
336
|
+
* Clears the patch of all operations
|
|
337
|
+
*/
|
|
338
|
+
reset(): this
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
export class Patch extends BasePatch {
|
|
342
|
+
constructor(documentId: string, operations?: PatchOperations, client?: SanityClient)
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Clones the patch
|
|
346
|
+
*/
|
|
347
|
+
clone(): Patch
|
|
348
|
+
|
|
342
349
|
/**
|
|
343
350
|
* Commit the patch, returning a promise that resolves to the first patched document
|
|
344
351
|
*
|
|
@@ -373,17 +380,53 @@ export class Patch {
|
|
|
373
380
|
* @param options Options for the mutation operation
|
|
374
381
|
*/
|
|
375
382
|
commit<R = any>(options?: BaseMutationOptions): Promise<SanityDocument<R>>
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
export class ObservablePatch extends BasePatch {
|
|
386
|
+
constructor(documentId: string, operations?: PatchOperations, client?: ObservableSanityClient)
|
|
376
387
|
|
|
377
388
|
/**
|
|
378
|
-
*
|
|
389
|
+
* Clones the patch
|
|
379
390
|
*/
|
|
380
|
-
|
|
381
|
-
}
|
|
391
|
+
clone(): ObservablePatch
|
|
382
392
|
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
393
|
+
/**
|
|
394
|
+
* Commit the patch, returning an observable that produces the first patched document
|
|
395
|
+
*
|
|
396
|
+
* @param options Options for the mutation operation
|
|
397
|
+
*/
|
|
398
|
+
commit<R = any>(options: FirstDocumentMutationOptions): Observable<SanityDocument<R>>
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* Commit the patch, returning an observable that produces an array of the mutated documents
|
|
402
|
+
*
|
|
403
|
+
* @param options Options for the mutation operation
|
|
404
|
+
*/
|
|
405
|
+
commit<R = any>(options: AllDocumentsMutationOptions): Observable<SanityDocument<R>[]>
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* Commit the patch, returning an observable that produces a mutation result object
|
|
409
|
+
*
|
|
410
|
+
* @param options Options for the mutation operation
|
|
411
|
+
*/
|
|
412
|
+
commit(options: FirstDocumentIdMutationOptions): Observable<SingleMutationResult>
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* Commit the patch, returning an observable that produces a mutation result object
|
|
416
|
+
*
|
|
417
|
+
* @param options Options for the mutation operation
|
|
418
|
+
*/
|
|
419
|
+
commit(options: AllDocumentIdsMutationOptions): Observable<MultipleMutationResult>
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* Commit the patch, returning an observable that produces the first patched document
|
|
423
|
+
*
|
|
424
|
+
* @param options Options for the mutation operation
|
|
425
|
+
*/
|
|
426
|
+
commit<R = any>(options?: BaseMutationOptions): Observable<SanityDocument<R>>
|
|
427
|
+
}
|
|
386
428
|
|
|
429
|
+
export abstract class BaseTransaction {
|
|
387
430
|
/**
|
|
388
431
|
* Creates a new Sanity document. If `_id` is provided and already exists, the mutation will fail. If no `_id` is given, one will automatically be generated by the database.
|
|
389
432
|
* The operation is added to the current transaction, ready to be commited by `commit()`
|
|
@@ -452,6 +495,20 @@ export class Transaction {
|
|
|
452
495
|
*/
|
|
453
496
|
toJSON(): Mutation[]
|
|
454
497
|
|
|
498
|
+
/**
|
|
499
|
+
* Clears the transaction of all operations
|
|
500
|
+
*/
|
|
501
|
+
reset(): this
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
export class Transaction extends BaseTransaction {
|
|
505
|
+
constructor(operations?: Mutation[], client?: SanityClient, transactionId?: string)
|
|
506
|
+
|
|
507
|
+
/**
|
|
508
|
+
* Clones the transaction
|
|
509
|
+
*/
|
|
510
|
+
clone(): Transaction
|
|
511
|
+
|
|
455
512
|
/**
|
|
456
513
|
* Commit the transaction, returning a promise that resolves to the first mutated document
|
|
457
514
|
*
|
|
@@ -486,11 +543,50 @@ export class Transaction {
|
|
|
486
543
|
* @param options Options for the mutation operation
|
|
487
544
|
*/
|
|
488
545
|
commit(options?: BaseMutationOptions): Promise<MultipleMutationResult>
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
export class ObservableTransaction {
|
|
549
|
+
constructor(operations?: Mutation[], client?: ObservableSanityClient, transactionId?: string)
|
|
489
550
|
|
|
490
551
|
/**
|
|
491
|
-
*
|
|
552
|
+
* Clones the transaction
|
|
492
553
|
*/
|
|
493
|
-
|
|
554
|
+
clone(): ObservableTransaction
|
|
555
|
+
|
|
556
|
+
/**
|
|
557
|
+
* Commit the transaction, returning an observable that produces the first mutated document
|
|
558
|
+
*
|
|
559
|
+
* @param options Options for the mutation operation
|
|
560
|
+
*/
|
|
561
|
+
commit<R>(options: TransactionFirstDocumentMutationOptions): Observable<SanityDocument<R>>
|
|
562
|
+
|
|
563
|
+
/**
|
|
564
|
+
* Commit the transaction, returning an observable that produces an array of the mutated documents
|
|
565
|
+
*
|
|
566
|
+
* @param options Options for the mutation operation
|
|
567
|
+
*/
|
|
568
|
+
commit<R>(options: TransactionAllDocumentsMutationOptions): Observable<SanityDocument<R>[]>
|
|
569
|
+
|
|
570
|
+
/**
|
|
571
|
+
* Commit the transaction, returning an observable that produces a mutation result object
|
|
572
|
+
*
|
|
573
|
+
* @param options Options for the mutation operation
|
|
574
|
+
*/
|
|
575
|
+
commit(options: TransactionFirstDocumentIdMutationOptions): Observable<SingleMutationResult>
|
|
576
|
+
|
|
577
|
+
/**
|
|
578
|
+
* Commit the transaction, returning an observable that produces a mutation result object
|
|
579
|
+
*
|
|
580
|
+
* @param options Options for the mutation operation
|
|
581
|
+
*/
|
|
582
|
+
commit(options: TransactionAllDocumentIdsMutationOptions): Observable<MultipleMutationResult>
|
|
583
|
+
|
|
584
|
+
/**
|
|
585
|
+
* Commit the transaction, returning an observable that produces a mutation result object
|
|
586
|
+
*
|
|
587
|
+
* @param options Options for the mutation operation
|
|
588
|
+
*/
|
|
589
|
+
commit(options?: BaseMutationOptions): Observable<MultipleMutationResult>
|
|
494
590
|
}
|
|
495
591
|
|
|
496
592
|
export interface ClientConfig {
|
|
@@ -1385,14 +1481,14 @@ export class ObservableSanityClient {
|
|
|
1385
1481
|
* @param documentId Document ID to patch
|
|
1386
1482
|
* @param operations Optional object of patch operations to initialize the patch instance with
|
|
1387
1483
|
*/
|
|
1388
|
-
patch(documentId: string | MutationSelection, operations?: PatchOperations):
|
|
1484
|
+
patch(documentId: string | MutationSelection, operations?: PatchOperations): ObservablePatch
|
|
1389
1485
|
|
|
1390
1486
|
/**
|
|
1391
1487
|
* Create a new transaction of mutations
|
|
1392
1488
|
*
|
|
1393
1489
|
* @param operations Optional array of mutation operations to initialize the transaction instance with
|
|
1394
1490
|
*/
|
|
1395
|
-
transaction<R = any>(operations?: Mutation<R>[]):
|
|
1491
|
+
transaction<R = any>(operations?: Mutation<R>[]): ObservableTransaction
|
|
1396
1492
|
|
|
1397
1493
|
// "Internals", should generally not be used externally
|
|
1398
1494
|
/**
|