microcms-js-sdk 3.1.1 → 3.2.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 CHANGED
@@ -1,16 +1,20 @@
1
1
  # microCMS JavaScript SDK
2
2
 
3
+ [日本語版 README](README_jp.md)
4
+
3
5
  It helps you to use microCMS from JavaScript and Node.js applications.
4
6
 
5
7
  <a href="https://discord.com/invite/K3DPqw4EJ2" target="_blank"><img src="https://img.shields.io/badge/Discord-%235865F2.svg?style=for-the-badge&logo=discord&logoColor=white" alt="Discord"></a>
6
8
 
7
- ## Getting Started
9
+ ## Tutorial
8
10
 
9
- ### Install
11
+ See the [official tutorial](https://document.microcms.io/tutorial/javascript/javascript-top).
10
12
 
11
- #### Node.js
13
+ ## Getting started
12
14
 
13
- Install npm package.
15
+ ### Installation
16
+
17
+ #### Node.js
14
18
 
15
19
  ```bash
16
20
  $ npm install microcms-js-sdk
@@ -37,23 +41,44 @@ Please load and use the URL provided by an external provider.
37
41
 
38
42
  ```html
39
43
  <script src="https://cdn.jsdelivr.net/npm/microcms-js-sdk@3.1.1/dist/umd/microcms-js-sdk.min.js"></script>
44
+ ```
40
45
 
41
46
  or
42
47
 
48
+ ```html
43
49
  <script src="https://cdn.jsdelivr.net/npm/microcms-js-sdk/dist/umd/microcms-js-sdk.min.js"></script>
44
50
  ```
45
51
 
46
52
  > [!WARNING]
47
- > The hosting service (unpkg.com) is not related to microCMS. For production use, we recommend self-hosting on your own server.
53
+ > The hosting service (cdn.jsdelivr.net) is not related to microCMS. For production use, we recommend self-hosting on your own server.
48
54
 
49
- ### How to use
55
+ ## Contents API
50
56
 
51
- First, create a client.
57
+ ### Import
58
+
59
+ #### Node.js
52
60
 
53
61
  ```javascript
54
62
  const { createClient } = require('microcms-js-sdk'); // CommonJS
63
+ ```
64
+
65
+ or
66
+
67
+ ```javascript
55
68
  import { createClient } from 'microcms-js-sdk'; //ES6
69
+ ```
70
+
71
+ #### Usage with a browser
72
+
73
+ ```html
74
+ <script>
75
+ const { createClient } = microcms;
76
+ </script>
77
+ ```
78
+
79
+ ### Create client object
56
80
 
81
+ ```javascript
57
82
  // Initialize Client SDK.
58
83
  const client = createClient({
59
84
  serviceDomain: 'YOUR_DOMAIN', // YOUR_DOMAIN is the XXXX part of XXXX.microcms.io
@@ -62,63 +87,101 @@ const client = createClient({
62
87
  });
63
88
  ```
64
89
 
65
- When using with a browser.
90
+ ### API methods
66
91
 
67
- ```html
68
- <script>
69
- const { createClient } = microcms;
92
+ The table below shows each API method of microCMS JavaScript SDK and indicates which API format (List Format or Object Format) they can be used with using ✔️.
70
93
 
71
- // Initialize Client SDK.
72
- const client = createClient({
73
- serviceDomain: 'YOUR_DOMAIN', // YOUR_DOMAIN is the XXXX part of XXXX.microcms.io
74
- apiKey: 'YOUR_API_KEY',
75
- // retry: true // Retry attempts up to a maximum of two times.
76
- });
77
- </script>
78
- ```
94
+ | Method | List Format | Object Format |
95
+ |-------------------|-------------|---------------|
96
+ | getList | ✔️ | |
97
+ | getListDetail | ✔️ | |
98
+ | getObject | | ✔️ |
99
+ | getAllContentIds | ✔️ | |
100
+ | getAllContents | ✔️ | |
101
+ | create | ✔️ | |
102
+ | update | ✔️ | ✔️ |
103
+ | delete | ✔️ | |
79
104
 
80
- After, How to use `get` it below.
105
+ > [!NOTE]
106
+ > - ✔️ in "List Format" indicates the method can be used when the API type is set to List Format.
107
+ > - ✔️ in "Object Format" indicates the method can be used when the API type is set to Object Format.
108
+
109
+ ### Get content list
110
+
111
+ The `getList` method is used to retrieve a list of content from a specified endpoint.
81
112
 
82
113
  ```javascript
83
114
  client
84
- .get({
115
+ .getList({
85
116
  endpoint: 'endpoint',
86
- queries: { limit: 20, filters: 'createdAt[greater_than]2021' },
87
117
  })
88
118
  .then((res) => console.log(res))
89
119
  .catch((err) => console.error(err));
120
+ ```
90
121
 
122
+ #### Get content list with parameters
123
+
124
+ The `queries` property can be used to specify parameters for retrieving content that matches specific criteria. For more details on each available property, refer to the [microCMS Documentation](https://document.microcms.io/content-api/get-list-contents#h929d25d495).
125
+
126
+ ```javascript
91
127
  client
92
- .get({
128
+ .getList({
93
129
  endpoint: 'endpoint',
94
- contentId: 'contentId',
95
- queries: { fields: 'title,publishedAt' },
130
+ queries: {
131
+ draftKey: 'abcd',
132
+ limit: 100,
133
+ offset: 1,
134
+ orders: 'createdAt',
135
+ q: 'Hello',
136
+ fields: 'id,title',
137
+ ids: 'foo',
138
+ filters: 'publishedAt[greater_than]2021-01-01T03:00:00.000Z',
139
+ depth: 1,
140
+ }
96
141
  })
97
142
  .then((res) => console.log(res))
98
143
  .catch((err) => console.error(err));
99
144
  ```
100
145
 
101
- And, Api corresponding to each content are also available. example.
146
+ ### Get single content
147
+
148
+ The `getListDetail` method is used to retrieve a single content specified by its ID.
102
149
 
103
150
  ```javascript
104
- // Get list API data
105
151
  client
106
- .getList({
152
+ .getListDetail({
107
153
  endpoint: 'endpoint',
154
+ contentId: 'contentId',
108
155
  })
109
156
  .then((res) => console.log(res))
110
157
  .catch((err) => console.error(err));
158
+ ```
159
+
160
+ #### Get single content with parameters
161
+
162
+ The `queries` property can be used to specify parameters for retrieving a single content that matches specific criteria. For more details on each available property, refer to the [microCMS Documentation](https://document.microcms.io/content-api/get-content#h929d25d495).
111
163
 
112
- // Get list API detail data
164
+ ```javascript
113
165
  client
114
166
  .getListDetail({
115
167
  endpoint: 'endpoint',
116
168
  contentId: 'contentId',
169
+ queries: {
170
+ draftKey: 'abcd',
171
+ fields: 'id,title',
172
+ depth: 1,
173
+ }
117
174
  })
118
175
  .then((res) => console.log(res))
119
176
  .catch((err) => console.error(err));
120
177
 
121
- // Get object API data
178
+ ```
179
+
180
+ ### Get object format content
181
+
182
+ The `getObject` method is used to retrieve a single object format content
183
+
184
+ ```javascript
122
185
  client
123
186
  .getObject({
124
187
  endpoint: 'endpoint',
@@ -127,11 +190,9 @@ client
127
190
  .catch((err) => console.error(err));
128
191
  ```
129
192
 
130
- #### Get all content ids
193
+ ### Get all contentIds
131
194
 
132
- This function can be used to retrieve all content IDs only.
133
- Since `filters` and `draftKey` can also be specified, it is possible to retrieve only the content IDs for a specific category, or to include content from a specific draft. \
134
- The `alternateField` property can also be used to address cases where the value of a field other than content ID is used in a URL, etc.
195
+ The `getAllContentIds` method is used to retrieve all content IDs only.
135
196
 
136
197
  ```javascript
137
198
  client
@@ -140,8 +201,13 @@ client
140
201
  })
141
202
  .then((res) => console.log(res))
142
203
  .catch((err) => console.error(err));
204
+ ```
205
+
206
+ #### Get all contentIds with filters
143
207
 
144
- // Get all content ids with filters
208
+ It is possible to retrieve only the content IDs for a specific category by specifying the `filters`.
209
+
210
+ ```javascript
145
211
  client
146
212
  .getAllContentIds({
147
213
  endpoint: 'endpoint',
@@ -149,8 +215,13 @@ client
149
215
  })
150
216
  .then((res) => console.log(res))
151
217
  .catch((err) => console.error(err));
218
+ ```
219
+
220
+ #### Get all contentIds with draftKey
152
221
 
153
- // Get all content ids with draftKey
222
+ It is possible to include content from a specific draft by specifying the `draftKey`.
223
+
224
+ ```javascript
154
225
  client
155
226
  .getAllContentIds({
156
227
  endpoint: 'endpoint',
@@ -158,8 +229,13 @@ client
158
229
  })
159
230
  .then((res) => console.log(res))
160
231
  .catch((err) => console.error(err));
232
+ ```
233
+
234
+ #### Get all contentIds with alternateField
161
235
 
162
- // Get all content ids with alternateField
236
+ The `alternateField` property can be used to address cases where the value of a field other than content ID is used in a URL, etc.
237
+
238
+ ```javascript
163
239
  client
164
240
  .getAllContentIds({
165
241
  endpoint: 'endpoint',
@@ -169,9 +245,9 @@ client
169
245
  .catch((err) => console.error(err));
170
246
  ```
171
247
 
172
- #### Get all contents
248
+ ### Get all contents
173
249
 
174
- This function can be used to retrieve all content data.
250
+ The `getAllContents` method is used to retrieve all content data.
175
251
 
176
252
  ```javascript
177
253
  client
@@ -180,23 +256,27 @@ client
180
256
  })
181
257
  .then((res) => console.log(res))
182
258
  .catch((err) => console.error(err));
259
+ ```
260
+
261
+ #### Get all contents with parameters
183
262
 
184
- // with queries
263
+ The `queries` property can be used to specify parameters for retrieving all content that matches specific criteria. For more details on each available property, refer to the [microCMS Documentation](https://document.microcms.io/content-api/get-list-contents#h929d25d495).
264
+
265
+ ```javascript
185
266
  client
186
267
  .getAllContents({
187
268
  endpoint: 'endpoint',
188
- queries: { filters: 'createdAt[greater_than]2021', orders: '-createdAt' },
269
+ queries: { filters: 'createdAt[greater_than]2021-01-01T03:00:00.000Z', orders: '-createdAt' },
189
270
  })
190
271
  .then((res) => console.log(res))
191
272
  .catch((err) => console.error(err));
192
273
  ```
193
274
 
194
- #### CREATE API
275
+ ### Create content
195
276
 
196
- The following is how to use the write system when making a request to the write system API.
277
+ The `create` method is used to register content.
197
278
 
198
279
  ```javascript
199
- // Create content
200
280
  client
201
281
  .create({
202
282
  endpoint: 'endpoint',
@@ -207,8 +287,13 @@ client
207
287
  })
208
288
  .then((res) => console.log(res.id))
209
289
  .catch((err) => console.error(err));
290
+ ```
291
+
292
+ #### Create content with specified ID
210
293
 
211
- // Create content with specified ID
294
+ By specifying the `contentId` property, it is possible to register content with a specified ID.
295
+
296
+ ```javascript
212
297
  client
213
298
  .create({
214
299
  endpoint: 'endpoint',
@@ -220,7 +305,13 @@ client
220
305
  })
221
306
  .then((res) => console.log(res.id))
222
307
  .catch((err) => console.error(err));
223
- // Create draft content
308
+ ```
309
+
310
+ #### Create draft content
311
+
312
+ By specifying the `isDraft` property, it is possible to register the content as a draft.
313
+
314
+ ```javascript
224
315
  client
225
316
  .create({
226
317
  endpoint: 'endpoint',
@@ -234,8 +325,13 @@ client
234
325
  })
235
326
  .then((res) => console.log(res.id))
236
327
  .catch((err) => console.error(err));
328
+ ```
237
329
 
238
- // Create draft content with specified ID
330
+ #### Create draft content with specified ID
331
+
332
+ By specifying the `contentId` and `isDraft` properties, it is possible to register the content as a draft with a specified ID.
333
+
334
+ ```javascript
239
335
  client
240
336
  .create({
241
337
  endpoint: 'endpoint',
@@ -252,10 +348,11 @@ client
252
348
  .catch((err) => console.error(err));
253
349
  ```
254
350
 
255
- ### UPDATE API
351
+ ### Update content
352
+
353
+ The `update` method is used to update a single content specified by its ID.
256
354
 
257
355
  ```javascript
258
- // Update content
259
356
  client
260
357
  .update({
261
358
  endpoint: 'endpoint',
@@ -266,8 +363,13 @@ client
266
363
  })
267
364
  .then((res) => console.log(res.id))
268
365
  .catch((err) => console.error(err));
366
+ ```
367
+
368
+ #### Update object format content
269
369
 
270
- // Update object form content
370
+ When updating object content, use the `update` method without specifying a `contentId` property.
371
+
372
+ ```javascript
271
373
  client
272
374
  .update({
273
375
  endpoint: 'endpoint',
@@ -279,10 +381,11 @@ client
279
381
  .catch((err) => console.error(err));
280
382
  ```
281
383
 
282
- ### DELETE API
384
+ ### Delete content
385
+
386
+ The `delete` method is used to delete a single content specified by its ID.
283
387
 
284
388
  ```javascript
285
- // Delete content
286
389
  client
287
390
  .delete({
288
391
  endpoint: 'endpoint',
@@ -295,14 +398,13 @@ client
295
398
 
296
399
  If you are using TypeScript, use `getList`, `getListDetail`, `getObject`. This internally contains a common type of content.
297
400
 
401
+ #### Response type for getList method
402
+
298
403
  ```typescript
299
- // Type definition
300
404
  type Content = {
301
405
  text: string,
302
- }
303
-
406
+ };
304
407
  /**
305
- * // getList response type
306
408
  * {
307
409
  * contents: Content[]; // This is array type of Content
308
410
  * totalCount: number;
@@ -310,10 +412,16 @@ type Content = {
310
412
  * offset: number;
311
413
  * }
312
414
  */
313
- client.getList<Content>({ //other })
415
+ client.getList<Content>({ /* other */ })
416
+ ```
417
+
418
+ #### Response type for getListDetail method
314
419
 
420
+ ```typescript
421
+ type Content = {
422
+ text: string,
423
+ };
315
424
  /**
316
- * // getListDetail response type
317
425
  * {
318
426
  * id: string;
319
427
  * createdAt: string;
@@ -323,10 +431,16 @@ client.getList<Content>({ //other })
323
431
  * text: string; // This is Content type.
324
432
  * }
325
433
  */
326
- client.getListDetail<Content>({ //other })
434
+ client.getListDetail<Content>({ /* other */ })
435
+ ```
436
+
437
+ #### Response type for getObject method
327
438
 
439
+ ```typescript
440
+ type Content = {
441
+ text: string,
442
+ };
328
443
  /**
329
- * // getObject response type
330
444
  * {
331
445
  * createdAt: string;
332
446
  * updatedAt: string;
@@ -335,20 +449,22 @@ client.getListDetail<Content>({ //other })
335
449
  * text: string; // This is Content type.
336
450
  * }
337
451
  */
338
- client.getObject<Content>({ //other })
452
+
453
+ client.getObject<Content>({ /* other */ })
339
454
  ```
340
455
 
341
- The type of `getAllContentIds` is as follows.
456
+ #### Response type for getAllContentIds method
342
457
 
343
458
  ```typescript
344
459
  /**
345
- * // getAllContentIds response type
346
460
  * string[] // This is array type of string
347
461
  */
348
- client.getAllContentIds({ //other })
462
+ client.getAllContentIds({ /* other */ })
349
463
  ```
350
464
 
351
- Write functions can also be performed type-safely.
465
+ #### Create method with type safety
466
+
467
+ Since `content` will be of type `Content`, no required fields will be missed.
352
468
 
353
469
  ```typescript
354
470
  type Content = {
@@ -358,25 +474,34 @@ type Content = {
358
474
 
359
475
  client.create<Content>({
360
476
  endpoint: 'endpoint',
361
- // Since `content` will be of type `Content`, no required fields will be missed.
362
477
  content: {
363
478
  title: 'title',
364
479
  body: 'body',
365
480
  },
366
481
  });
482
+ ```
483
+
484
+ #### Update method with type safety
485
+
486
+ The `content` will be of type `Partial<Content>`, so you can enter only the items needed for the update.
487
+
488
+ ```typescript
489
+ type Content = {
490
+ title: string;
491
+ body?: string;
492
+ };
367
493
 
368
494
  client.update<Content>({
369
495
  endpoint: 'endpoint',
370
- // The `content` will be of type `Partial<Content>`, so you can enter only the items needed for the update.
371
496
  content: {
372
497
  body: 'body',
373
498
  },
374
499
  });
375
500
  ```
376
501
 
377
- ## CustomRequestInit
502
+ ### CustomRequestInit
378
503
 
379
- ### Next.js App Router
504
+ #### Next.js App Router
380
505
 
381
506
  You can now use the fetch option of the Next.js App Router as CustomRequestInit.
382
507
  Please refer to the official Next.js documentation as the available options depend on the Next.js Type file.
@@ -394,7 +519,7 @@ const response = await client.getList({
394
519
  });
395
520
  ```
396
521
 
397
- ### AbortController: abort() method
522
+ #### AbortController: abort() method
398
523
 
399
524
  You can abort fetch requests.
400
525
 
@@ -414,23 +539,38 @@ setTimeout(() => {
414
539
 
415
540
  ## Management API
416
541
 
417
- Clients can be created for the Management API.
542
+ ### Import
418
543
 
419
- ### How to use
544
+ #### Node.js
420
545
 
421
- First, create a client.
546
+ ```javascript
547
+ const { createManagementClient } = require('microcms-js-sdk'); // CommonJS
548
+ ```
549
+
550
+ or
422
551
 
423
552
  ```javascript
424
553
  import { createManagementClient } from 'microcms-js-sdk'; //ES6
554
+ ```
425
555
 
426
- // Initialize Client SDK.
556
+ #### Usage with a browser
557
+
558
+ ```html
559
+ <script>
560
+ const { createManagementClient } = microcms;
561
+ </script>
562
+ ```
563
+
564
+ ### Create client object
565
+
566
+ ```javascript
427
567
  const client = createManagementClient({
428
568
  serviceDomain: 'YOUR_DOMAIN', // YOUR_DOMAIN is the XXXX part of XXXX.microcms.io
429
569
  apiKey: 'YOUR_API_KEY',
430
570
  });
431
571
  ```
432
572
 
433
- ### UploadMedia API
573
+ ### Upload media
434
574
 
435
575
  Media files can be uploaded using the 'POST /api/v1/media' endpoint of the Management API.
436
576
 
@@ -495,9 +635,9 @@ client
495
635
  .catch((err) => console.error(err));
496
636
  ```
497
637
 
498
- ### Type Definition
638
+ ### TypeScript
499
639
 
500
- #### UploadMedia
640
+ #### Parameter type for uploadMedia method
501
641
 
502
642
  ```typescript
503
643
  type UploadMediaRequest =
@@ -527,6 +667,6 @@ const writeClient = createClient({
527
667
  });
528
668
  ```
529
669
 
530
- # LICENSE
670
+ ## LICENSE
531
671
 
532
672
  Apache-2.0
@@ -1 +1 @@
1
- function e(e,t){if(t==null||t>e.length)t=e.length;for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function t(e){if(Array.isArray(e))return e}function r(t){if(Array.isArray(t))return e(t)}function n(e,t,r,n,i,o,u){try{var a=e[o](u);var s=a.value}catch(e){r(e);return}if(a.done){t(s)}else{Promise.resolve(s).then(n,i)}}function i(e){return function(){var t=this,r=arguments;return new Promise(function(i,o){var u=e.apply(t,r);function a(e){n(u,i,o,a,s,"next",e)}function s(e){n(u,i,o,a,s,"throw",e)}a(undefined)})}}function o(e,t,r){if(t in e){Object.defineProperty(e,t,{value:r,enumerable:true,configurable:true,writable:true})}else{e[t]=r}return e}function u(e,t){if(t!=null&&typeof Symbol!=="undefined"&&t[Symbol.hasInstance]){return!!t[Symbol.hasInstance](e)}else{return e instanceof t}}function a(e){if(typeof Symbol!=="undefined"&&e[Symbol.iterator]!=null||e["@@iterator"]!=null)return Array.from(e)}function s(e,t){var r=e==null?null:typeof Symbol!=="undefined"&&e[Symbol.iterator]||e["@@iterator"];if(r==null)return;var n=[];var i=true;var o=false;var u,a;try{for(r=r.call(e);!(i=(u=r.next()).done);i=true){n.push(u.value);if(t&&n.length===t)break}}catch(e){o=true;a=e}finally{try{if(!i&&r["return"]!=null)r["return"]()}finally{if(o)throw a}}return n}function c(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function l(){throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function f(e){for(var t=1;t<arguments.length;t++){var r=arguments[t]!=null?arguments[t]:{};var n=Object.keys(r);if(typeof Object.getOwnPropertySymbols==="function"){n=n.concat(Object.getOwnPropertySymbols(r).filter(function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}))}n.forEach(function(t){o(e,t,r[t])})}return e}function d(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);if(t){n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})}r.push.apply(r,n)}return r}function p(e,t){t=t!=null?t:{};if(Object.getOwnPropertyDescriptors){Object.defineProperties(e,Object.getOwnPropertyDescriptors(t))}else{d(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})}return e}function h(e,r){return t(e)||s(e,r)||y(e,r)||c()}function v(e){return r(e)||a(e)||y(e)||l()}function y(t,r){if(!t)return;if(typeof t==="string")return e(t,r);var n=Object.prototype.toString.call(t).slice(8,-1);if(n==="Object"&&t.constructor)n=t.constructor.name;if(n==="Map"||n==="Set")return Array.from(n);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return e(t,r)}function m(e,t){var r,n,i,o,u={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),"throw":a(1),"return":a(2)},typeof Symbol==="function"&&(o[Symbol.iterator]=function(){return this}),o;function a(e){return function(t){return s([e,t])}}function s(o){if(r)throw new TypeError("Generator is already executing.");while(u)try{if(r=1,n&&(i=o[0]&2?n["return"]:o[0]?n["throw"]||((i=n["return"])&&i.call(n),0):n.next)&&!(i=i.call(n,o[1])).done)return i;if(n=0,i)o=[o[0]&2,i.value];switch(o[0]){case 0:case 1:i=o;break;case 4:u.label++;return{value:o[1],done:false};case 5:u.label++;n=o[1];o=[0];continue;case 7:o=u.ops.pop();u.trys.pop();continue;default:if(!(i=u.trys,i=i.length>0&&i[i.length-1])&&(o[0]===6||o[0]===2)){u=0;continue}if(o[0]===3&&(!i||o[1]>i[0]&&o[1]<i[3])){u.label=o[1];break}if(o[0]===6&&u.label<i[1]){u.label=i[1];i=o;break}if(i&&u.label<i[2]){u.label=i[2];u.ops.push(o);break}if(i[2])u.ops.pop();u.trys.pop();continue}o=t.call(e,u)}catch(e){o=[6,e];n=0}finally{r=i=0}if(o[0]&5)throw o[1];return{value:o[0]?o[1]:void 0,done:true}}}import b from"async-retry";var w=function(e){return function(){var t=i(function(t,r){var n;return m(this,function(i){n=new Headers(r===null||r===void 0?void 0:r.headers);return[2,(n.has("X-MICROCMS-API-KEY")||n.set("X-MICROCMS-API-KEY",e),fetch(t,p(f({},r),{headers:n})))]})});return function(e,r){return t.apply(this,arguments)}}()};var g="microcms.io",q="microcms-management.io",I="v1";var j=function(e){return e!==null&&typeof e=="object"},E=function(e){return typeof e=="string"};var P=function(e){if(!j(e))throw new Error("queries is not object");return new URLSearchParams(Object.entries(e).reduce(function(e,t){var r=h(t,2),n=r[0],i=r[1];return e[n]=String(i),e},{})).toString()};var O=function(e){var t=e.serviceDomain,r=e.apiKey,n=e.retry;if(!t||!r)throw new Error("parameter is required (check serviceDomain and apiKey)");if(!E(t)||!E(r))throw new Error("parameter is not string");var o="https://".concat(t,".").concat(g,"/api/").concat(I),u=function(){var e=i(function(e){var t,u,a,s,c,l,d,h,v;return m(this,function(y){switch(y.label){case 0:t=e.endpoint,u=e.contentId,a=e.queries,s=a===void 0?{}:a,c=e.requestInit;l=w(r),d=P(s),h="".concat(o,"/").concat(t).concat(u?"/".concat(u):"").concat(d?"?".concat(d):""),v=function(){var e=i(function(e){var t,r,n;return m(this,function(i){switch(i.label){case 0:i.trys.push([0,2,,3]);return[4,e.json()];case 1:t=i.sent(),r=t.message;return[2,r!==null&&r!==void 0?r:null];case 2:n=i.sent();return[2,null];case 3:return[2]}})});return function t(t){return e.apply(this,arguments)}}();return[4,b(function(){var e=i(function(e){var t,r,n,i,o,u,a;return m(this,function(s){switch(s.label){case 0:s.trys.push([0,6,,7]);return[4,l(h,p(f({},c),{method:(r=c===null||c===void 0?void 0:c.method)!==null&&r!==void 0?r:"GET"}))];case 1:if(!(t=s.sent(),t.status!==429&&t.status>=400&&t.status<500))return[3,3];return[4,v(t)];case 2:n=s.sent();return[2,e(new Error("fetch API response status: ".concat(t.status).concat(n?"\n message is `".concat(n,"`"):"")))];case 3:if(!!t.ok)return[3,5];return[4,v(t)];case 4:i=s.sent();return[2,Promise.reject(new Error("fetch API response status: ".concat(t.status).concat(i?"\n message is `".concat(i,"`"):"")))];case 5:return[2,(c===null||c===void 0?void 0:c.method)==="DELETE"?void 0:t.json()];case 6:o=s.sent();if(o.data)throw o.data;if((u=o.response)===null||u===void 0?void 0:u.data)throw o.response.data;return[2,Promise.reject(new Error("Network Error.\n Details: ".concat((a=o.message)!==null&&a!==void 0?a:"")))];case 7:return[2]}})});return function(t){return e.apply(this,arguments)}}(),{retries:n?2:0,onRetry:function(e,t){console.log(e),console.log("Waiting for retry (".concat(t,"/",2,")"))},minTimeout:5e3})];case 1:return[2,y.sent()]}})});return function t(t){return e.apply(this,arguments)}}();return{get:function(){var e=i(function(e){var t,r,n,i,o,a;return m(this,function(s){switch(s.label){case 0:t=e.endpoint,r=e.contentId,n=e.queries,i=n===void 0?{}:n,o=e.customRequestInit;if(!t)return[3,2];return[4,u({endpoint:t,contentId:r,queries:i,requestInit:o})];case 1:a=s.sent();return[3,3];case 2:a=Promise.reject(new Error("endpoint is required"));s.label=3;case 3:return[2,a]}})});return function(t){return e.apply(this,arguments)}}(),getList:function(){var e=i(function(e){var t,r,n,i,o;return m(this,function(a){switch(a.label){case 0:t=e.endpoint,r=e.queries,n=r===void 0?{}:r,i=e.customRequestInit;if(!t)return[3,2];return[4,u({endpoint:t,queries:n,requestInit:i})];case 1:o=a.sent();return[3,3];case 2:o=Promise.reject(new Error("endpoint is required"));a.label=3;case 3:return[2,o]}})});return function(t){return e.apply(this,arguments)}}(),getListDetail:function(){var e=i(function(e){var t,r,n,i,o,a;return m(this,function(s){switch(s.label){case 0:t=e.endpoint,r=e.contentId,n=e.queries,i=n===void 0?{}:n,o=e.customRequestInit;if(!t)return[3,2];return[4,u({endpoint:t,contentId:r,queries:i,requestInit:o})];case 1:a=s.sent();return[3,3];case 2:a=Promise.reject(new Error("endpoint is required"));s.label=3;case 3:return[2,a]}})});return function(t){return e.apply(this,arguments)}}(),getObject:function(){var e=i(function(e){var t,r,n,i,o;return m(this,function(a){switch(a.label){case 0:t=e.endpoint,r=e.queries,n=r===void 0?{}:r,i=e.customRequestInit;if(!t)return[3,2];return[4,u({endpoint:t,queries:n,requestInit:i})];case 1:o=a.sent();return[3,3];case 2:o=Promise.reject(new Error("endpoint is required"));a.label=3;case 3:return[2,o]}})});return function(t){return e.apply(this,arguments)}}(),getAllContentIds:function(){var e=i(function(e){var t,r,n,i,o,a,s,c,l,d,h,y,b,w,g,q,I;return m(this,function(m){switch(m.label){case 0:t=e.endpoint,r=e.alternateField,n=e.draftKey,i=e.filters,o=e.orders,a=e.customRequestInit;s={draftKey:n,filters:i,orders:o,limit:100,fields:r!==null&&r!==void 0?r:"id",depth:0};return[4,u({endpoint:t,queries:p(f({},s),{limit:0}),requestInit:a})];case 1:c=m.sent(),l=c.totalCount,d=[],h=0,y=function(e){return new Promise(function(t){return setTimeout(t,e)})},b=function(e){return e.every(function(e){return typeof e=="string"})};m.label=2;case 2:if(!(d.length<l))return[3,7];return[4,u({endpoint:t,queries:p(f({},s),{offset:h}),requestInit:a})];case 3:w=m.sent(),g=w.contents,q=g.map(function(e){return e[r!==null&&r!==void 0?r:"id"]});if(!b(q))throw new Error("The value of the field specified by `alternateField` is not a string.");d=v(d).concat(v(q)),h+=100;I=d.length<l;if(!I)return[3,5];return[4,y(1e3)];case 4:I=m.sent();m.label=5;case 5:I;m.label=6;case 6:return[3,2];case 7:return[2,d]}})});return function(t){return e.apply(this,arguments)}}(),getAllContents:function(){var e=i(function(e){var t,r,n,i,o,a,s,c,l,d,h,v;return m(this,function(y){switch(y.label){case 0:t=e.endpoint,r=e.queries,n=r===void 0?{}:r,i=e.customRequestInit;return[4,u({endpoint:t,queries:p(f({},n),{limit:0}),requestInit:i})];case 1:o=y.sent(),a=o.totalCount,s=[],c=0,l=function(e){return new Promise(function(t){return setTimeout(t,e)})};y.label=2;case 2:if(!(s.length<a))return[3,7];return[4,u({endpoint:t,queries:p(f({},n),{limit:100,offset:c}),requestInit:i})];case 3:d=y.sent(),h=d.contents;s=s.concat(h),c+=100;v=s.length<a;if(!v)return[3,5];return[4,l(1e3)];case 4:v=y.sent();y.label=5;case 5:v;y.label=6;case 6:return[3,2];case 7:return[2,s]}})});return function(t){return e.apply(this,arguments)}}(),create:function(){var e=i(function(e){var t,r,n,i,o,a,s,c;return m(this,function(l){t=e.endpoint,r=e.contentId,n=e.content,i=e.isDraft,o=i===void 0?!1:i,a=e.customRequestInit;if(!t)return[2,Promise.reject(new Error("endpoint is required"))];s=o?{status:"draft"}:{},c=p(f({},a),{method:r?"PUT":"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});return[2,u({endpoint:t,contentId:r,queries:s,requestInit:c})]})});return function(t){return e.apply(this,arguments)}}(),update:function(){var e=i(function(e){var t,r,n,i,o;return m(this,function(a){t=e.endpoint,r=e.contentId,n=e.content,i=e.customRequestInit;if(!t)return[2,Promise.reject(new Error("endpoint is required"))];o=p(f({},i),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});return[2,u({endpoint:t,contentId:r,requestInit:o})]})});return function(t){return e.apply(this,arguments)}}(),delete:function(){var e=i(function(e){var t,r,n,i;return m(this,function(o){switch(o.label){case 0:t=e.endpoint,r=e.contentId,n=e.customRequestInit;if(!t)return[2,Promise.reject(new Error("endpoint is required"))];if(!r)return[2,Promise.reject(new Error("contentId is required"))];i=p(f({},n),{method:"DELETE",headers:{},body:void 0});return[4,u({endpoint:t,contentId:r,requestInit:i})];case 1:o.sent();return[2]}})});return function(t){return e.apply(this,arguments)}}()}};var S=function(e){var t=e.serviceDomain,r=e.apiKey;if(!t||!r)throw new Error("parameter is required (check serviceDomain and apiKey)");if(!E(t)||!E(r))throw new Error("parameter is not string");var n=function(){var e=i(function(e){var n,o,u,a,s,c,l,d,h,v,y,b,g,I,j,E;return m(this,function(O){switch(O.label){case 0:n=e.path,o=e.apiVersion,u=e.queries,a=u===void 0?{}:u,s=e.requestInit;c="https://".concat(t,".").concat(q,"/api/").concat(o),l=w(r),d=P(a),h="".concat(c,"/").concat(n).concat(d?"?".concat(d):""),v=function(){var e=i(function(e){var t,r,n;return m(this,function(i){switch(i.label){case 0:i.trys.push([0,2,,3]);return[4,e.json()];case 1:t=i.sent(),r=t.message;return[2,r!==null&&r!==void 0?r:null];case 2:n=i.sent();return[2,null];case 3:return[2]}})});return function t(t){return e.apply(this,arguments)}}();O.label=1;case 1:O.trys.push([1,3,,4]);return[4,l(h,p(f({},s),{method:(b=s===null||s===void 0?void 0:s.method)!==null&&b!==void 0?b:"GET"}))];case 2:y=O.sent();return[3,4];case 3:g=O.sent();if(g.data)throw g.data;if((I=g.response)===null||I===void 0?void 0:I.data)throw g.response.data;return[2,Promise.reject(new Error("Network Error.\n Details: ".concat((j=g.message)!==null&&j!==void 0?j:"")))];case 4:if(!!y.ok)return[3,6];return[4,v(y)];case 5:E=O.sent();return[2,Promise.reject(new Error("fetch API response status: ".concat(y.status).concat(E?"\n message is `".concat(E,"`"):"")))];case 6:return[2,y.json()]}})});return function t(t){return e.apply(this,arguments)}}();return{uploadMedia:function(){var e=i(function(e){var t,r,i,o,a,s,c,l,f,d,p,h;return m(this,function(v){switch(v.label){case 0:t=e.data,r=e.name,i=e.type,o=e.customRequestHeaders;a=new FormData;if(!u(t,Blob))return[3,1];if(t.name)a.set("file",t,t.name);else{if(!r)throw new Error("name is required when data is a Blob");a.set("file",t,r)}return[3,9];case 1:if(!u(t,ReadableStream))return[3,6];if(!r)throw new Error("name is required when data is a ReadableStream");if(!i)throw new Error("type is required when data is a ReadableStream");s=[],c=t.getReader();v.label=2;case 2:return[4,c.read()];case 3:if(!!(l=v.sent()).done)return[3,5];s.push(l.value);v.label=4;case 4:return[3,2];case 5:a.set("file",new Blob(s,{type:i}),r);return[3,9];case 6:if(!(typeof t=="string"||u(t,URL)))return[3,9];f=u(t,URL)?t:new URL(t);return[4,fetch(f.toString(),o?{headers:o}:void 0)];case 7:d=v.sent();return[4,d.blob()];case 8:p=v.sent(),h=new URL(d.url).pathname.split("/").pop();a.set("file",p,r!==null&&r!==void 0?r:h);v.label=9;case 9:return[2,n({path:"media",apiVersion:I,requestInit:{method:"POST",body:a}})]}})});return function(t){return e.apply(this,arguments)}}()}};export{O as createClient,S as createManagementClient};//# sourceMappingURL=microcms-js-sdk.js.map
1
+ function e(e,t){if(t==null||t>e.length)t=e.length;for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function t(e){if(Array.isArray(e))return e}function r(t){if(Array.isArray(t))return e(t)}function n(e,t,r,n,i,o,u){try{var a=e[o](u);var s=a.value}catch(e){r(e);return}if(a.done){t(s)}else{Promise.resolve(s).then(n,i)}}function i(e){return function(){var t=this,r=arguments;return new Promise(function(i,o){var u=e.apply(t,r);function a(e){n(u,i,o,a,s,"next",e)}function s(e){n(u,i,o,a,s,"throw",e)}a(undefined)})}}function o(e,t,r){if(t in e){Object.defineProperty(e,t,{value:r,enumerable:true,configurable:true,writable:true})}else{e[t]=r}return e}function u(e,t){if(t!=null&&typeof Symbol!=="undefined"&&t[Symbol.hasInstance]){return!!t[Symbol.hasInstance](e)}else{return e instanceof t}}function a(e){if(typeof Symbol!=="undefined"&&e[Symbol.iterator]!=null||e["@@iterator"]!=null)return Array.from(e)}function s(e,t){var r=e==null?null:typeof Symbol!=="undefined"&&e[Symbol.iterator]||e["@@iterator"];if(r==null)return;var n=[];var i=true;var o=false;var u,a;try{for(r=r.call(e);!(i=(u=r.next()).done);i=true){n.push(u.value);if(t&&n.length===t)break}}catch(e){o=true;a=e}finally{try{if(!i&&r["return"]!=null)r["return"]()}finally{if(o)throw a}}return n}function c(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function l(){throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function f(e){for(var t=1;t<arguments.length;t++){var r=arguments[t]!=null?arguments[t]:{};var n=Object.keys(r);if(typeof Object.getOwnPropertySymbols==="function"){n=n.concat(Object.getOwnPropertySymbols(r).filter(function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}))}n.forEach(function(t){o(e,t,r[t])})}return e}function d(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);if(t){n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})}r.push.apply(r,n)}return r}function p(e,t){t=t!=null?t:{};if(Object.getOwnPropertyDescriptors){Object.defineProperties(e,Object.getOwnPropertyDescriptors(t))}else{d(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})}return e}function h(e,r){return t(e)||s(e,r)||y(e,r)||c()}function v(e){return r(e)||a(e)||y(e)||l()}function y(t,r){if(!t)return;if(typeof t==="string")return e(t,r);var n=Object.prototype.toString.call(t).slice(8,-1);if(n==="Object"&&t.constructor)n=t.constructor.name;if(n==="Map"||n==="Set")return Array.from(n);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return e(t,r)}function m(e,t){var r,n,i,o,u={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),"throw":a(1),"return":a(2)},typeof Symbol==="function"&&(o[Symbol.iterator]=function(){return this}),o;function a(e){return function(t){return s([e,t])}}function s(o){if(r)throw new TypeError("Generator is already executing.");while(u)try{if(r=1,n&&(i=o[0]&2?n["return"]:o[0]?n["throw"]||((i=n["return"])&&i.call(n),0):n.next)&&!(i=i.call(n,o[1])).done)return i;if(n=0,i)o=[o[0]&2,i.value];switch(o[0]){case 0:case 1:i=o;break;case 4:u.label++;return{value:o[1],done:false};case 5:u.label++;n=o[1];o=[0];continue;case 7:o=u.ops.pop();u.trys.pop();continue;default:if(!(i=u.trys,i=i.length>0&&i[i.length-1])&&(o[0]===6||o[0]===2)){u=0;continue}if(o[0]===3&&(!i||o[1]>i[0]&&o[1]<i[3])){u.label=o[1];break}if(o[0]===6&&u.label<i[1]){u.label=i[1];i=o;break}if(i&&u.label<i[2]){u.label=i[2];u.ops.push(o);break}if(i[2])u.ops.pop();u.trys.pop();continue}o=t.call(e,u)}catch(e){o=[6,e];n=0}finally{r=i=0}if(o[0]&5)throw o[1];return{value:o[0]?o[1]:void 0,done:true}}}import b from"async-retry";var w=function(e){return function(){var t=i(function(t,r){var n;return m(this,function(i){n=new Headers(r===null||r===void 0?void 0:r.headers);return[2,(n.has("X-MICROCMS-API-KEY")||n.set("X-MICROCMS-API-KEY",e),fetch(t,p(f({},r),{headers:n})))]})});return function(e,r){return t.apply(this,arguments)}}()};var g="microcms.io",q="microcms-management.io",I="v1";var j=function(e){return e!==null&&typeof e=="object"},E=function(e){return typeof e=="string"};var P=function(e){if(!j(e))throw new Error("queries is not object");return new URLSearchParams(Object.entries(e).reduce(function(e,t){var r=h(t,2),n=r[0],i=r[1];return i!==void 0&&(e[n]=String(i)),e},{})).toString()};var O=function(e){var t=e.serviceDomain,r=e.apiKey,n=e.retry;if(!t||!r)throw new Error("parameter is required (check serviceDomain and apiKey)");if(!E(t)||!E(r))throw new Error("parameter is not string");var o="https://".concat(t,".").concat(g,"/api/").concat(I),u=function(){var e=i(function(e){var t,u,a,s,c,l,d,h,v;return m(this,function(y){switch(y.label){case 0:t=e.endpoint,u=e.contentId,a=e.queries,s=a===void 0?{}:a,c=e.requestInit;l=w(r),d=P(s),h="".concat(o,"/").concat(t).concat(u?"/".concat(u):"").concat(d?"?".concat(d):""),v=function(){var e=i(function(e){var t,r,n;return m(this,function(i){switch(i.label){case 0:i.trys.push([0,2,,3]);return[4,e.json()];case 1:t=i.sent(),r=t.message;return[2,r!==null&&r!==void 0?r:null];case 2:n=i.sent();return[2,null];case 3:return[2]}})});return function t(t){return e.apply(this,arguments)}}();return[4,b(function(){var e=i(function(e){var t,r,n,i,o,u,a;return m(this,function(s){switch(s.label){case 0:s.trys.push([0,6,,7]);return[4,l(h,p(f({},c),{method:(r=c===null||c===void 0?void 0:c.method)!==null&&r!==void 0?r:"GET"}))];case 1:if(!(t=s.sent(),t.status!==429&&t.status>=400&&t.status<500))return[3,3];return[4,v(t)];case 2:n=s.sent();return[2,e(new Error("fetch API response status: ".concat(t.status).concat(n?"\n message is `".concat(n,"`"):"")))];case 3:if(!!t.ok)return[3,5];return[4,v(t)];case 4:i=s.sent();return[2,Promise.reject(new Error("fetch API response status: ".concat(t.status).concat(i?"\n message is `".concat(i,"`"):"")))];case 5:return[2,(c===null||c===void 0?void 0:c.method)==="DELETE"?void 0:t.json()];case 6:o=s.sent();if(o.data)throw o.data;if((u=o.response)===null||u===void 0?void 0:u.data)throw o.response.data;return[2,Promise.reject(new Error("Network Error.\n Details: ".concat((a=o.message)!==null&&a!==void 0?a:"")))];case 7:return[2]}})});return function(t){return e.apply(this,arguments)}}(),{retries:n?2:0,onRetry:function(e,t){console.log(e),console.log("Waiting for retry (".concat(t,"/",2,")"))},minTimeout:5e3})];case 1:return[2,y.sent()]}})});return function t(t){return e.apply(this,arguments)}}();return{get:function(){var e=i(function(e){var t,r,n,i,o,a;return m(this,function(s){switch(s.label){case 0:t=e.endpoint,r=e.contentId,n=e.queries,i=n===void 0?{}:n,o=e.customRequestInit;if(!t)return[3,2];return[4,u({endpoint:t,contentId:r,queries:i,requestInit:o})];case 1:a=s.sent();return[3,3];case 2:a=Promise.reject(new Error("endpoint is required"));s.label=3;case 3:return[2,a]}})});return function(t){return e.apply(this,arguments)}}(),getList:function(){var e=i(function(e){var t,r,n,i,o;return m(this,function(a){switch(a.label){case 0:t=e.endpoint,r=e.queries,n=r===void 0?{}:r,i=e.customRequestInit;if(!t)return[3,2];return[4,u({endpoint:t,queries:n,requestInit:i})];case 1:o=a.sent();return[3,3];case 2:o=Promise.reject(new Error("endpoint is required"));a.label=3;case 3:return[2,o]}})});return function(t){return e.apply(this,arguments)}}(),getListDetail:function(){var e=i(function(e){var t,r,n,i,o,a;return m(this,function(s){switch(s.label){case 0:t=e.endpoint,r=e.contentId,n=e.queries,i=n===void 0?{}:n,o=e.customRequestInit;if(!t)return[3,2];return[4,u({endpoint:t,contentId:r,queries:i,requestInit:o})];case 1:a=s.sent();return[3,3];case 2:a=Promise.reject(new Error("endpoint is required"));s.label=3;case 3:return[2,a]}})});return function(t){return e.apply(this,arguments)}}(),getObject:function(){var e=i(function(e){var t,r,n,i,o;return m(this,function(a){switch(a.label){case 0:t=e.endpoint,r=e.queries,n=r===void 0?{}:r,i=e.customRequestInit;if(!t)return[3,2];return[4,u({endpoint:t,queries:n,requestInit:i})];case 1:o=a.sent();return[3,3];case 2:o=Promise.reject(new Error("endpoint is required"));a.label=3;case 3:return[2,o]}})});return function(t){return e.apply(this,arguments)}}(),getAllContentIds:function(){var e=i(function(e){var t,r,n,i,o,a,s,c,l,d,h,y,b,w,g,q,I;return m(this,function(m){switch(m.label){case 0:t=e.endpoint,r=e.alternateField,n=e.draftKey,i=e.filters,o=e.orders,a=e.customRequestInit;s={draftKey:n,filters:i,orders:o,limit:100,fields:r!==null&&r!==void 0?r:"id",depth:0};return[4,u({endpoint:t,queries:p(f({},s),{limit:0}),requestInit:a})];case 1:c=m.sent(),l=c.totalCount,d=[],h=0,y=function(e){return new Promise(function(t){return setTimeout(t,e)})},b=function(e){return e.every(function(e){return typeof e=="string"})};m.label=2;case 2:if(!(d.length<l))return[3,7];return[4,u({endpoint:t,queries:p(f({},s),{offset:h}),requestInit:a})];case 3:w=m.sent(),g=w.contents,q=g.map(function(e){return e[r!==null&&r!==void 0?r:"id"]});if(!b(q))throw new Error("The value of the field specified by `alternateField` is not a string.");d=v(d).concat(v(q)),h+=100;I=d.length<l;if(!I)return[3,5];return[4,y(1e3)];case 4:I=m.sent();m.label=5;case 5:I;m.label=6;case 6:return[3,2];case 7:return[2,d]}})});return function(t){return e.apply(this,arguments)}}(),getAllContents:function(){var e=i(function(e){var t,r,n,i,o,a,s,c,l,d,h,v;return m(this,function(y){switch(y.label){case 0:t=e.endpoint,r=e.queries,n=r===void 0?{}:r,i=e.customRequestInit;return[4,u({endpoint:t,queries:p(f({},n),{limit:0}),requestInit:i})];case 1:o=y.sent(),a=o.totalCount,s=[],c=0,l=function(e){return new Promise(function(t){return setTimeout(t,e)})};y.label=2;case 2:if(!(s.length<a))return[3,7];return[4,u({endpoint:t,queries:p(f({},n),{limit:100,offset:c}),requestInit:i})];case 3:d=y.sent(),h=d.contents;s=s.concat(h),c+=100;v=s.length<a;if(!v)return[3,5];return[4,l(1e3)];case 4:v=y.sent();y.label=5;case 5:v;y.label=6;case 6:return[3,2];case 7:return[2,s]}})});return function(t){return e.apply(this,arguments)}}(),create:function(){var e=i(function(e){var t,r,n,i,o,a,s,c;return m(this,function(l){t=e.endpoint,r=e.contentId,n=e.content,i=e.isDraft,o=i===void 0?!1:i,a=e.customRequestInit;if(!t)return[2,Promise.reject(new Error("endpoint is required"))];s=o?{status:"draft"}:{},c=p(f({},a),{method:r?"PUT":"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});return[2,u({endpoint:t,contentId:r,queries:s,requestInit:c})]})});return function(t){return e.apply(this,arguments)}}(),update:function(){var e=i(function(e){var t,r,n,i,o;return m(this,function(a){t=e.endpoint,r=e.contentId,n=e.content,i=e.customRequestInit;if(!t)return[2,Promise.reject(new Error("endpoint is required"))];o=p(f({},i),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});return[2,u({endpoint:t,contentId:r,requestInit:o})]})});return function(t){return e.apply(this,arguments)}}(),delete:function(){var e=i(function(e){var t,r,n,i;return m(this,function(o){switch(o.label){case 0:t=e.endpoint,r=e.contentId,n=e.customRequestInit;if(!t)return[2,Promise.reject(new Error("endpoint is required"))];if(!r)return[2,Promise.reject(new Error("contentId is required"))];i=p(f({},n),{method:"DELETE",headers:{},body:void 0});return[4,u({endpoint:t,contentId:r,requestInit:i})];case 1:o.sent();return[2]}})});return function(t){return e.apply(this,arguments)}}()}};var S=function(e){var t=e.serviceDomain,r=e.apiKey;if(!t||!r)throw new Error("parameter is required (check serviceDomain and apiKey)");if(!E(t)||!E(r))throw new Error("parameter is not string");var n=function(){var e=i(function(e){var n,o,u,a,s,c,l,d,h,v,y,b,g,I,j,E;return m(this,function(O){switch(O.label){case 0:n=e.path,o=e.apiVersion,u=e.queries,a=u===void 0?{}:u,s=e.requestInit;c="https://".concat(t,".").concat(q,"/api/").concat(o),l=w(r),d=P(a),h="".concat(c,"/").concat(n).concat(d?"?".concat(d):""),v=function(){var e=i(function(e){var t,r,n;return m(this,function(i){switch(i.label){case 0:i.trys.push([0,2,,3]);return[4,e.json()];case 1:t=i.sent(),r=t.message;return[2,r!==null&&r!==void 0?r:null];case 2:n=i.sent();return[2,null];case 3:return[2]}})});return function t(t){return e.apply(this,arguments)}}();O.label=1;case 1:O.trys.push([1,3,,4]);return[4,l(h,p(f({},s),{method:(b=s===null||s===void 0?void 0:s.method)!==null&&b!==void 0?b:"GET"}))];case 2:y=O.sent();return[3,4];case 3:g=O.sent();if(g.data)throw g.data;if((I=g.response)===null||I===void 0?void 0:I.data)throw g.response.data;return[2,Promise.reject(new Error("Network Error.\n Details: ".concat((j=g.message)!==null&&j!==void 0?j:"")))];case 4:if(!!y.ok)return[3,6];return[4,v(y)];case 5:E=O.sent();return[2,Promise.reject(new Error("fetch API response status: ".concat(y.status).concat(E?"\n message is `".concat(E,"`"):"")))];case 6:return[2,y.json()]}})});return function t(t){return e.apply(this,arguments)}}();return{uploadMedia:function(){var e=i(function(e){var t,r,i,o,a,s,c,l,f,d,p,h;return m(this,function(v){switch(v.label){case 0:t=e.data,r=e.name,i=e.type,o=e.customRequestHeaders;a=new FormData;if(!u(t,Blob))return[3,1];if(t.name)a.set("file",t,t.name);else{if(!r)throw new Error("name is required when data is a Blob");a.set("file",t,r)}return[3,9];case 1:if(!u(t,ReadableStream))return[3,6];if(!r)throw new Error("name is required when data is a ReadableStream");if(!i)throw new Error("type is required when data is a ReadableStream");s=[],c=t.getReader();v.label=2;case 2:return[4,c.read()];case 3:if(!!(l=v.sent()).done)return[3,5];s.push(l.value);v.label=4;case 4:return[3,2];case 5:a.set("file",new Blob(s,{type:i}),r);return[3,9];case 6:if(!(typeof t=="string"||u(t,URL)))return[3,9];f=u(t,URL)?t:new URL(t);return[4,fetch(f.toString(),o?{headers:o}:void 0)];case 7:d=v.sent();return[4,d.blob()];case 8:p=v.sent(),h=new URL(d.url).pathname.split("/").pop();a.set("file",p,r!==null&&r!==void 0?r:h);v.label=9;case 9:return[2,n({path:"media",apiVersion:I,requestInit:{method:"POST",body:a}})]}})});return function(t){return e.apply(this,arguments)}}()}};export{O as createClient,S as createManagementClient};//# sourceMappingURL=microcms-js-sdk.js.map