microcms-js-sdk 3.1.1 → 3.1.2

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
@@ -4,13 +4,15 @@ It helps you to use microCMS from JavaScript and Node.js applications.
4
4
 
5
5
  <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
6
 
7
- ## Getting Started
7
+ ## Tutorial
8
8
 
9
- ### Install
9
+ See the [official tutorial](https://document.microcms.io/tutorial/javascript/javascript-top).
10
10
 
11
- #### Node.js
11
+ ## Getting started
12
+
13
+ ### Installation
12
14
 
13
- Install npm package.
15
+ #### Node.js
14
16
 
15
17
  ```bash
16
18
  $ npm install microcms-js-sdk
@@ -37,23 +39,44 @@ Please load and use the URL provided by an external provider.
37
39
 
38
40
  ```html
39
41
  <script src="https://cdn.jsdelivr.net/npm/microcms-js-sdk@3.1.1/dist/umd/microcms-js-sdk.min.js"></script>
42
+ ```
40
43
 
41
44
  or
42
45
 
46
+ ```html
43
47
  <script src="https://cdn.jsdelivr.net/npm/microcms-js-sdk/dist/umd/microcms-js-sdk.min.js"></script>
44
48
  ```
45
49
 
46
50
  > [!WARNING]
47
- > The hosting service (unpkg.com) is not related to microCMS. For production use, we recommend self-hosting on your own server.
51
+ > The hosting service (cdn.jsdelivr.net) is not related to microCMS. For production use, we recommend self-hosting on your own server.
52
+
53
+ ## Contents API
48
54
 
49
- ### How to use
55
+ ### Import
50
56
 
51
- First, create a client.
57
+ #### Node.js
52
58
 
53
59
  ```javascript
54
60
  const { createClient } = require('microcms-js-sdk'); // CommonJS
61
+ ```
62
+
63
+ or
64
+
65
+ ```javascript
55
66
  import { createClient } from 'microcms-js-sdk'; //ES6
67
+ ```
68
+
69
+ #### Usage with a browser
70
+
71
+ ```html
72
+ <script>
73
+ const { createClient } = microcms;
74
+ </script>
75
+ ```
56
76
 
77
+ ### Create client object
78
+
79
+ ```javascript
57
80
  // Initialize Client SDK.
58
81
  const client = createClient({
59
82
  serviceDomain: 'YOUR_DOMAIN', // YOUR_DOMAIN is the XXXX part of XXXX.microcms.io
@@ -62,63 +85,101 @@ const client = createClient({
62
85
  });
63
86
  ```
64
87
 
65
- When using with a browser.
88
+ ### API methods
66
89
 
67
- ```html
68
- <script>
69
- const { createClient } = microcms;
90
+ 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
91
 
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
- ```
92
+ | Method | List Format | Object Format |
93
+ |-------------------|-------------|---------------|
94
+ | getList | ✔️ | |
95
+ | getListDetail | ✔️ | |
96
+ | getObject | | ✔️ |
97
+ | getAllContentIds | ✔️ | |
98
+ | getAllContents | ✔️ | |
99
+ | create | ✔️ | |
100
+ | update | ✔️ | ✔️ |
101
+ | delete | ✔️ | |
102
+
103
+ > [!NOTE]
104
+ > - ✔️ in "List Format" indicates the method can be used when the API type is set to List Format.
105
+ > - ✔️ in "Object Format" indicates the method can be used when the API type is set to Object Format.
79
106
 
80
- After, How to use `get` it below.
107
+ ### Get content list
108
+
109
+ The `getList` method is used to retrieve a list of content from a specified endpoint.
81
110
 
82
111
  ```javascript
83
112
  client
84
- .get({
113
+ .getList({
85
114
  endpoint: 'endpoint',
86
- queries: { limit: 20, filters: 'createdAt[greater_than]2021' },
87
115
  })
88
116
  .then((res) => console.log(res))
89
117
  .catch((err) => console.error(err));
118
+ ```
119
+
120
+ #### Get content list with parameters
90
121
 
122
+ 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).
123
+
124
+ ```javascript
91
125
  client
92
- .get({
126
+ .getList({
93
127
  endpoint: 'endpoint',
94
- contentId: 'contentId',
95
- queries: { fields: 'title,publishedAt' },
128
+ queries: {
129
+ draftKey: 'abcd',
130
+ limit: 100,
131
+ offset: 1,
132
+ orders: 'createdAt',
133
+ q: 'Hello',
134
+ fields: 'id,title',
135
+ ids: 'foo',
136
+ filters: 'publishedAt[greater_than]2021-01-01T03:00:00.000Z',
137
+ depth: 1,
138
+ }
96
139
  })
97
140
  .then((res) => console.log(res))
98
141
  .catch((err) => console.error(err));
99
142
  ```
100
143
 
101
- And, Api corresponding to each content are also available. example.
144
+ ### Get single content
145
+
146
+ The `getListDetail` method is used to retrieve a single content specified by its ID.
102
147
 
103
148
  ```javascript
104
- // Get list API data
105
149
  client
106
- .getList({
150
+ .getListDetail({
107
151
  endpoint: 'endpoint',
152
+ contentId: 'contentId',
108
153
  })
109
154
  .then((res) => console.log(res))
110
155
  .catch((err) => console.error(err));
156
+ ```
157
+
158
+ #### Get single content with parameters
111
159
 
112
- // Get list API detail data
160
+ 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).
161
+
162
+ ```javascript
113
163
  client
114
164
  .getListDetail({
115
165
  endpoint: 'endpoint',
116
166
  contentId: 'contentId',
167
+ queries: {
168
+ draftKey: 'abcd',
169
+ fields: 'id,title',
170
+ depth: 1,
171
+ }
117
172
  })
118
173
  .then((res) => console.log(res))
119
174
  .catch((err) => console.error(err));
120
175
 
121
- // Get object API data
176
+ ```
177
+
178
+ ### Get object format content
179
+
180
+ The `getObject` method is used to retrieve a single object format content
181
+
182
+ ```javascript
122
183
  client
123
184
  .getObject({
124
185
  endpoint: 'endpoint',
@@ -127,11 +188,9 @@ client
127
188
  .catch((err) => console.error(err));
128
189
  ```
129
190
 
130
- #### Get all content ids
191
+ ### Get all contentIds
131
192
 
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.
193
+ The `getAllContentIds` method is used to retrieve all content IDs only.
135
194
 
136
195
  ```javascript
137
196
  client
@@ -140,8 +199,13 @@ client
140
199
  })
141
200
  .then((res) => console.log(res))
142
201
  .catch((err) => console.error(err));
202
+ ```
203
+
204
+ #### Get all contentIds with filters
205
+
206
+ It is possible to retrieve only the content IDs for a specific category by specifying the `filters`.
143
207
 
144
- // Get all content ids with filters
208
+ ```javascript
145
209
  client
146
210
  .getAllContentIds({
147
211
  endpoint: 'endpoint',
@@ -149,8 +213,13 @@ client
149
213
  })
150
214
  .then((res) => console.log(res))
151
215
  .catch((err) => console.error(err));
216
+ ```
217
+
218
+ #### Get all contentIds with draftKey
219
+
220
+ It is possible to include content from a specific draft by specifying the `draftKey`.
152
221
 
153
- // Get all content ids with draftKey
222
+ ```javascript
154
223
  client
155
224
  .getAllContentIds({
156
225
  endpoint: 'endpoint',
@@ -158,8 +227,13 @@ client
158
227
  })
159
228
  .then((res) => console.log(res))
160
229
  .catch((err) => console.error(err));
230
+ ```
231
+
232
+ #### Get all contentIds with alternateField
233
+
234
+ 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.
161
235
 
162
- // Get all content ids with alternateField
236
+ ```javascript
163
237
  client
164
238
  .getAllContentIds({
165
239
  endpoint: 'endpoint',
@@ -169,9 +243,9 @@ client
169
243
  .catch((err) => console.error(err));
170
244
  ```
171
245
 
172
- #### Get all contents
246
+ ### Get all contents
173
247
 
174
- This function can be used to retrieve all content data.
248
+ The `getAllContents` method is used to retrieve all content data.
175
249
 
176
250
  ```javascript
177
251
  client
@@ -180,23 +254,27 @@ client
180
254
  })
181
255
  .then((res) => console.log(res))
182
256
  .catch((err) => console.error(err));
257
+ ```
258
+
259
+ #### Get all contents with parameters
183
260
 
184
- // with queries
261
+ 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).
262
+
263
+ ```javascript
185
264
  client
186
265
  .getAllContents({
187
266
  endpoint: 'endpoint',
188
- queries: { filters: 'createdAt[greater_than]2021', orders: '-createdAt' },
267
+ queries: { filters: 'createdAt[greater_than]2021-01-01T03:00:00.000Z', orders: '-createdAt' },
189
268
  })
190
269
  .then((res) => console.log(res))
191
270
  .catch((err) => console.error(err));
192
271
  ```
193
272
 
194
- #### CREATE API
273
+ ### Create content
195
274
 
196
- The following is how to use the write system when making a request to the write system API.
275
+ The `create` method is used to register content.
197
276
 
198
277
  ```javascript
199
- // Create content
200
278
  client
201
279
  .create({
202
280
  endpoint: 'endpoint',
@@ -207,8 +285,13 @@ client
207
285
  })
208
286
  .then((res) => console.log(res.id))
209
287
  .catch((err) => console.error(err));
288
+ ```
289
+
290
+ #### Create content with specified ID
210
291
 
211
- // Create content with specified ID
292
+ By specifying the `contentId` property, it is possible to register content with a specified ID.
293
+
294
+ ```javascript
212
295
  client
213
296
  .create({
214
297
  endpoint: 'endpoint',
@@ -220,7 +303,13 @@ client
220
303
  })
221
304
  .then((res) => console.log(res.id))
222
305
  .catch((err) => console.error(err));
223
- // Create draft content
306
+ ```
307
+
308
+ #### Create draft content
309
+
310
+ By specifying the `isDraft` property, it is possible to register the content as a draft.
311
+
312
+ ```javascript
224
313
  client
225
314
  .create({
226
315
  endpoint: 'endpoint',
@@ -234,8 +323,13 @@ client
234
323
  })
235
324
  .then((res) => console.log(res.id))
236
325
  .catch((err) => console.error(err));
326
+ ```
237
327
 
238
- // Create draft content with specified ID
328
+ #### Create draft content with specified ID
329
+
330
+ By specifying the `contentId` and `isDraft` properties, it is possible to register the content as a draft with a specified ID.
331
+
332
+ ```javascript
239
333
  client
240
334
  .create({
241
335
  endpoint: 'endpoint',
@@ -252,10 +346,11 @@ client
252
346
  .catch((err) => console.error(err));
253
347
  ```
254
348
 
255
- ### UPDATE API
349
+ ### Update content
350
+
351
+ The `update` method is used to update a single content specified by its ID.
256
352
 
257
353
  ```javascript
258
- // Update content
259
354
  client
260
355
  .update({
261
356
  endpoint: 'endpoint',
@@ -266,8 +361,13 @@ client
266
361
  })
267
362
  .then((res) => console.log(res.id))
268
363
  .catch((err) => console.error(err));
364
+ ```
365
+
366
+ #### Update object format content
269
367
 
270
- // Update object form content
368
+ When updating object content, use the `update` method without specifying a `contentId` property.
369
+
370
+ ```javascript
271
371
  client
272
372
  .update({
273
373
  endpoint: 'endpoint',
@@ -279,10 +379,11 @@ client
279
379
  .catch((err) => console.error(err));
280
380
  ```
281
381
 
282
- ### DELETE API
382
+ ### Delete content
383
+
384
+ The `delete` method is used to delete a single content specified by its ID.
283
385
 
284
386
  ```javascript
285
- // Delete content
286
387
  client
287
388
  .delete({
288
389
  endpoint: 'endpoint',
@@ -295,14 +396,13 @@ client
295
396
 
296
397
  If you are using TypeScript, use `getList`, `getListDetail`, `getObject`. This internally contains a common type of content.
297
398
 
399
+ #### Response type for getList method
400
+
298
401
  ```typescript
299
- // Type definition
300
402
  type Content = {
301
403
  text: string,
302
- }
303
-
404
+ };
304
405
  /**
305
- * // getList response type
306
406
  * {
307
407
  * contents: Content[]; // This is array type of Content
308
408
  * totalCount: number;
@@ -310,10 +410,16 @@ type Content = {
310
410
  * offset: number;
311
411
  * }
312
412
  */
313
- client.getList<Content>({ //other })
413
+ client.getList<Content>({ /* other */ })
414
+ ```
415
+
416
+ #### Response type for getListDetail method
314
417
 
418
+ ```typescript
419
+ type Content = {
420
+ text: string,
421
+ };
315
422
  /**
316
- * // getListDetail response type
317
423
  * {
318
424
  * id: string;
319
425
  * createdAt: string;
@@ -323,10 +429,16 @@ client.getList<Content>({ //other })
323
429
  * text: string; // This is Content type.
324
430
  * }
325
431
  */
326
- client.getListDetail<Content>({ //other })
432
+ client.getListDetail<Content>({ /* other */ })
433
+ ```
434
+
435
+ #### Response type for getObject method
327
436
 
437
+ ```typescript
438
+ type Content = {
439
+ text: string,
440
+ };
328
441
  /**
329
- * // getObject response type
330
442
  * {
331
443
  * createdAt: string;
332
444
  * updatedAt: string;
@@ -335,20 +447,22 @@ client.getListDetail<Content>({ //other })
335
447
  * text: string; // This is Content type.
336
448
  * }
337
449
  */
338
- client.getObject<Content>({ //other })
450
+
451
+ client.getObject<Content>({ /* other */ })
339
452
  ```
340
453
 
341
- The type of `getAllContentIds` is as follows.
454
+ #### Response type for getAllContentIds method
342
455
 
343
456
  ```typescript
344
457
  /**
345
- * // getAllContentIds response type
346
458
  * string[] // This is array type of string
347
459
  */
348
- client.getAllContentIds({ //other })
460
+ client.getAllContentIds({ /* other */ })
349
461
  ```
350
462
 
351
- Write functions can also be performed type-safely.
463
+ #### Create method with type safety
464
+
465
+ Since `content` will be of type `Content`, no required fields will be missed.
352
466
 
353
467
  ```typescript
354
468
  type Content = {
@@ -358,25 +472,34 @@ type Content = {
358
472
 
359
473
  client.create<Content>({
360
474
  endpoint: 'endpoint',
361
- // Since `content` will be of type `Content`, no required fields will be missed.
362
475
  content: {
363
476
  title: 'title',
364
477
  body: 'body',
365
478
  },
366
479
  });
480
+ ```
481
+
482
+ #### Update method with type safety
483
+
484
+ The `content` will be of type `Partial<Content>`, so you can enter only the items needed for the update.
485
+
486
+ ```typescript
487
+ type Content = {
488
+ title: string;
489
+ body?: string;
490
+ };
367
491
 
368
492
  client.update<Content>({
369
493
  endpoint: 'endpoint',
370
- // The `content` will be of type `Partial<Content>`, so you can enter only the items needed for the update.
371
494
  content: {
372
495
  body: 'body',
373
496
  },
374
497
  });
375
498
  ```
376
499
 
377
- ## CustomRequestInit
500
+ ### CustomRequestInit
378
501
 
379
- ### Next.js App Router
502
+ #### Next.js App Router
380
503
 
381
504
  You can now use the fetch option of the Next.js App Router as CustomRequestInit.
382
505
  Please refer to the official Next.js documentation as the available options depend on the Next.js Type file.
@@ -394,7 +517,7 @@ const response = await client.getList({
394
517
  });
395
518
  ```
396
519
 
397
- ### AbortController: abort() method
520
+ #### AbortController: abort() method
398
521
 
399
522
  You can abort fetch requests.
400
523
 
@@ -414,23 +537,38 @@ setTimeout(() => {
414
537
 
415
538
  ## Management API
416
539
 
417
- Clients can be created for the Management API.
540
+ ### Import
418
541
 
419
- ### How to use
542
+ #### Node.js
420
543
 
421
- First, create a client.
544
+ ```javascript
545
+ const { createManagementClient } = require('microcms-js-sdk'); // CommonJS
546
+ ```
547
+
548
+ or
422
549
 
423
550
  ```javascript
424
551
  import { createManagementClient } from 'microcms-js-sdk'; //ES6
552
+ ```
425
553
 
426
- // Initialize Client SDK.
554
+ #### Usage with a browser
555
+
556
+ ```html
557
+ <script>
558
+ const { createManagementClient } = microcms;
559
+ </script>
560
+ ```
561
+
562
+ ### Create client object
563
+
564
+ ```javascript
427
565
  const client = createManagementClient({
428
566
  serviceDomain: 'YOUR_DOMAIN', // YOUR_DOMAIN is the XXXX part of XXXX.microcms.io
429
567
  apiKey: 'YOUR_API_KEY',
430
568
  });
431
569
  ```
432
570
 
433
- ### UploadMedia API
571
+ ### Upload media
434
572
 
435
573
  Media files can be uploaded using the 'POST /api/v1/media' endpoint of the Management API.
436
574
 
@@ -495,9 +633,9 @@ client
495
633
  .catch((err) => console.error(err));
496
634
  ```
497
635
 
498
- ### Type Definition
636
+ ### TypeScript
499
637
 
500
- #### UploadMedia
638
+ #### Parameter type for uploadMedia method
501
639
 
502
640
  ```typescript
503
641
  type UploadMediaRequest =
@@ -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