@uidev1116/acms-js-sdk 0.0.2 → 0.1.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,3 +1,301 @@
1
1
  # acms-js-sdk
2
2
 
3
- a-blog cms JavaScript SDK
3
+ JavaScript SDK for a-blog cms. Works in Node.js and modern browsers.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @uidev1116/acms-js-sdk
9
+
10
+ # or
11
+
12
+ yarn add @uidev1116/acms-js-sdk
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ First, you need to create a client instance.
18
+
19
+ ES Modules:
20
+
21
+ ```js
22
+ import { createClient } from '@uidev1116/acms-js-sdk';
23
+
24
+ const acmsClient = createClient({
25
+ baseUrl: 'YOUR_BASE_URL',
26
+ apiKey: 'YOUR_API_KEY',
27
+ });
28
+ ```
29
+
30
+ CommonJS:
31
+
32
+ ```js
33
+ const { createClient } = require('@uidev1116/acms-js-sdk');
34
+
35
+ const acmsClient = createClient({
36
+ baseUrl: 'YOUR_BASE_URL',
37
+ apiKey: 'YOUR_API_KEY',
38
+ });
39
+ ```
40
+
41
+ CDN:
42
+
43
+ ```html
44
+ <script type="module">
45
+ const { createClient } = 'https://unpkg.com/@uidev1116/acms-js-sdk@latest/dist/es/acms-js-sdk.js';
46
+
47
+ const acmsClient = createClient({
48
+ baseUrl: 'YOUR_BASE_URL',
49
+ apiKey: 'YOUR_API_KEY',
50
+ });
51
+ </script>
52
+ ```
53
+
54
+ Then, you can use `get` method.
55
+
56
+ Specify the module ID to be used in the module's GET API function in the `api`, and information on the specified module ID can be fetched.
57
+
58
+ ```js
59
+ acmsClient
60
+ .get({
61
+ api: 'MODULE_ID',
62
+ })
63
+ .then((response) => {
64
+ console.log(response.data);
65
+ })
66
+ .catch((error) => {
67
+ console.error(error);
68
+ });
69
+ ```
70
+
71
+ Relative paths from `baseUrl` can also be specified.
72
+
73
+ ```js
74
+ acmsClient
75
+ .get('api/MODULE_ID')
76
+ .then((response) => {
77
+ console.log(response.data);
78
+ })
79
+ .catch((error) => {
80
+ console.error(error);
81
+ });
82
+ ```
83
+
84
+ ### Url Context
85
+
86
+ You can specify the URL context.
87
+
88
+ ```js
89
+ acmsClient
90
+ .get({
91
+ blog: 'BLOG_CODE',
92
+ category: 'CATEGORY_CODE',
93
+ entry: 'ENTRY_CODE',
94
+ api: 'MODULE_ID',
95
+ })
96
+ .then((response) => {
97
+ console.log(response.data);
98
+ })
99
+ .catch((error) => {
100
+ console.error(error);
101
+ });
102
+ ```
103
+
104
+ You can see the acmsPath section for more details.
105
+
106
+ ### Error Handling
107
+
108
+ You can handle errors.
109
+
110
+ Youb can check if the error is `AcmsFetchError` by using `isAcmsFetchError`.
111
+
112
+ ```js
113
+ acmsClient
114
+ .get({
115
+ api: 'MODULE_ID',
116
+ })
117
+ .then((response) => {
118
+ console.log(response.data);
119
+ })
120
+ .catch((error) => {
121
+ if (acmsClient.isAcmsFetchError(error)) {
122
+ console.error(error.response.data);
123
+ return;
124
+ }
125
+ console.error(error);
126
+ });
127
+ ```
128
+
129
+ ## Options
130
+
131
+ The second argument can be an option.
132
+
133
+ Below is a list of all options.
134
+
135
+ | name | description | type | default |
136
+ | ------------ | ------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- | --------- |
137
+ | requestInit | An object containing any custom settings that you want to apply to the request. | RequestInit | undefined |
138
+ | responseType | indication the type of data that the server will respond with | 'arrayBuffer'<br> &#124; 'blob'<br> &#124; 'formData'<br> &#124; 'json'<br> &#124; 'text'; | 'json' |
139
+
140
+ Options can also be set in the arguments of the createClinent function.
141
+
142
+ In this case, all requests will reflect the set options.
143
+
144
+ ```js
145
+ const acmsClient = createClient({
146
+ baseUrl: 'YOUR_BASE_URL',
147
+ apiKey: 'Your_API_KEY',
148
+ requestInit: {
149
+ headers: {
150
+ 'Content-Type': 'application/json',
151
+ },
152
+ },
153
+ responseType: 'json',
154
+ });
155
+ ```
156
+
157
+ ### Next.js App Router
158
+
159
+ For Next.js App Router, you can specify the `revalidate` option.
160
+
161
+ [Functions: fetch | Next.js](https://nextjs.org/docs/app/api-reference/functions/fetch)
162
+ ```js
163
+ const response = await acmsClient.get(
164
+ { api: 'MODULE_ID' },
165
+ {
166
+ requestInit: {
167
+ next: {
168
+ revalidate: 60,
169
+ },
170
+ }
171
+ },
172
+ );
173
+ ```
174
+
175
+
176
+ ### AbortController: abort() method
177
+
178
+ You can use AbortController.
179
+
180
+ ```js
181
+ const controller = new AbortController();
182
+ const response = await acmsClient.get(
183
+ { api: 'MODULE_ID' },
184
+ {
185
+ requestInit: {
186
+ signal: controller.signal,
187
+ }
188
+ },
189
+ );
190
+
191
+ setTimeout(() => {
192
+ controller.abort();
193
+ }, 1000);
194
+ ```
195
+
196
+
197
+ ## TypeScript
198
+
199
+ You can use TypeScript.
200
+
201
+ ```ts
202
+ acmsClient
203
+ .get<ResponseType>({
204
+ api: 'MODULE_ID',
205
+ })
206
+ .then((response) => {
207
+ console.log(response.data); // response.data is ResponseType
208
+ })
209
+ ```
210
+
211
+ ## acmsPath
212
+
213
+ You can get the path of Url Context by using utility function `acmsPath`.
214
+
215
+ ```js
216
+
217
+ import { acmsPath } from '@uidev1116/acms-js-sdk';
218
+
219
+ const path = acmsPath({
220
+ blog: 'BLOG_CODE',
221
+ category: 'CATEGORY_CODE',
222
+ entry: 'ENTRY_CODE',
223
+ // user: 1,
224
+ // tag: ['tag1', 'tag2'],
225
+ // field: 'color/eq/red',
226
+ // span: { start: '2021-01-01', end: '2021-12-31' },
227
+ // date: { year: 2021, month: 1, day: 1 },
228
+ // page: 1,
229
+ // order: 'id-asc',
230
+ // limit: 10,
231
+ // keyword: 'KEYWORD',
232
+ // tpl: 'include/sample.json'
233
+ // admin: 'entry_index',
234
+ api: 'MODULE_ID',
235
+ });
236
+ ```
237
+
238
+ ### Params Type
239
+
240
+ ```ts
241
+ interface AcmsPathParams {
242
+ blog?: string | number;
243
+ admin?: string;
244
+ category?: string | string[] | number;
245
+ entry?: string | number;
246
+ user?: number;
247
+ tag?: string[];
248
+ field?: string;
249
+ span?: { start?: string | Date; end?: string | Date };
250
+ date?: { year?: number; month?: number; day?: number };
251
+ page?: number;
252
+ order?: string;
253
+ limit?: number;
254
+ keyword?: string;
255
+ tpl?: string;
256
+ api?: string;
257
+ searchParams?: ConstructorParameters<typeof URLSearchParams>[0];
258
+ }
259
+ ```
260
+
261
+ ## isAcmsFetchError
262
+
263
+ You can check if the error is `AcmsFetchError` by using utility function `isAcmsFetchError`.
264
+
265
+ ```js
266
+ import { isAcmsFetchError } from '@uidev1116/acms-js-sdk';
267
+
268
+ acmsClient
269
+ .get({
270
+ api: 'MODULE_ID',
271
+ })
272
+ .then((response) => {
273
+ console.log(response.data);
274
+ })
275
+ .catch((error) => {
276
+ if (isAcmsFetchError(error)) {
277
+ console.error(error.response.data);
278
+ return;
279
+ }
280
+ console.error(error);
281
+ });
282
+ ```
283
+
284
+ ## parseAcmsPath
285
+
286
+ The `parseAcmsPath` function is a utility designed to parse [acms path](https://developer.a-blogcms.jp/document/reference/acms_path.html) into a structured context object. This function is particularly useful for extracting various segments from a URL path and organizing them into a meaningful context that can be used for further processing in applications.
287
+
288
+ ```js
289
+ import { parseAcmsPath } from '@uidev1116/acms-js-sdk';
290
+
291
+ // For example, if the current URL path is '/bid/1/cid/2/eid/3/page/2/field/color/eq/red'
292
+ const context = parseAcmsPath(window.location.pathname);
293
+ // Output:
294
+ // {
295
+ // bid: 1,
296
+ // cid: 2,
297
+ // eid: 3,
298
+ // page: 2,
299
+ // field: 'color/eq/red'
300
+ // }
301
+ ```
@@ -1,34 +1,31 @@
1
- function V(c, y) {
2
- for (var m = 0; m < y.length; m++) {
3
- const p = y[m];
4
- if (typeof p != "string" && !Array.isArray(p)) {
5
- for (const l in p)
6
- if (l !== "default" && !(l in c)) {
7
- const b = Object.getOwnPropertyDescriptor(p, l);
8
- b && Object.defineProperty(c, l, b.get ? b : {
1
+ import { g as V, c as R } from "./index-H2fSgwjT.js";
2
+ function z(w, d) {
3
+ for (var b = 0; b < d.length; b++) {
4
+ const y = d[b];
5
+ if (typeof y != "string" && !Array.isArray(y)) {
6
+ for (const h in y)
7
+ if (h !== "default" && !(h in w)) {
8
+ const p = Object.getOwnPropertyDescriptor(y, h);
9
+ p && Object.defineProperty(w, h, p.get ? p : {
9
10
  enumerable: !0,
10
- get: () => p[l]
11
+ get: () => y[h]
11
12
  });
12
13
  }
13
14
  }
14
15
  }
15
- return Object.freeze(Object.defineProperty(c, Symbol.toStringTag, { value: "Module" }));
16
- }
17
- var R = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
18
- function z(c) {
19
- return c && c.__esModule && Object.prototype.hasOwnProperty.call(c, "default") ? c.default : c;
16
+ return Object.freeze(Object.defineProperty(w, Symbol.toStringTag, { value: "Module" }));
20
17
  }
21
18
  var O = { exports: {} };
22
- (function(c, y) {
23
- var m = typeof globalThis < "u" && globalThis || typeof self < "u" && self || typeof R < "u" && R, p = function() {
24
- function b() {
25
- this.fetch = !1, this.DOMException = m.DOMException;
19
+ (function(w, d) {
20
+ var b = typeof globalThis < "u" && globalThis || typeof self < "u" && self || typeof R < "u" && R, y = function() {
21
+ function p() {
22
+ this.fetch = !1, this.DOMException = b.DOMException;
26
23
  }
27
- return b.prototype = m, new b();
24
+ return p.prototype = b, new p();
28
25
  }();
29
- (function(b) {
26
+ (function(p) {
30
27
  (function(u) {
31
- var a = typeof b < "u" && b || typeof self < "u" && self || typeof a < "u" && a, f = {
28
+ var a = typeof p < "u" && p || typeof self < "u" && self || typeof a < "u" && a, f = {
32
29
  searchParams: "URLSearchParams" in a,
33
30
  iterable: "Symbol" in a && "iterator" in Symbol,
34
31
  blob: "FileReader" in a && "Blob" in a && function() {
@@ -131,11 +128,11 @@ var O = { exports: {} };
131
128
  };
132
129
  });
133
130
  }
134
- function M(e) {
131
+ function I(e) {
135
132
  var t = new FileReader(), r = P(t);
136
133
  return t.readAsArrayBuffer(e), r;
137
134
  }
138
- function I(e) {
135
+ function M(e) {
139
136
  var t = new FileReader(), r = P(t);
140
137
  return t.readAsText(e), r;
141
138
  }
@@ -174,13 +171,13 @@ var O = { exports: {} };
174
171
  )
175
172
  ) : Promise.resolve(this._bodyArrayBuffer));
176
173
  } else
177
- return this.blob().then(M);
174
+ return this.blob().then(I);
178
175
  }), this.text = function() {
179
176
  var e = T(this);
180
177
  if (e)
181
178
  return e;
182
179
  if (this._bodyBlob)
183
- return I(this._bodyBlob);
180
+ return M(this._bodyBlob);
184
181
  if (this._bodyArrayBuffer)
185
182
  return Promise.resolve(H(this._bodyArrayBuffer));
186
183
  if (this._bodyFormData)
@@ -197,12 +194,12 @@ var O = { exports: {} };
197
194
  var t = e.toUpperCase();
198
195
  return q.indexOf(t) > -1 ? t : e;
199
196
  }
200
- function w(e, t) {
201
- if (!(this instanceof w))
197
+ function m(e, t) {
198
+ if (!(this instanceof m))
202
199
  throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');
203
200
  t = t || {};
204
201
  var r = t.body;
205
- if (e instanceof w) {
202
+ if (e instanceof m) {
206
203
  if (e.bodyUsed)
207
204
  throw new TypeError("Already read");
208
205
  this.url = e.url, this.credentials = e.credentials, t.headers || (this.headers = new s(e.headers)), this.method = e.method, this.mode = e.mode, this.signal = e.signal, !r && e._bodyInit != null && (r = e._bodyInit, e.bodyUsed = !0);
@@ -220,8 +217,8 @@ var O = { exports: {} };
220
217
  }
221
218
  }
222
219
  }
223
- w.prototype.clone = function() {
224
- return new w(this, { body: this._bodyInit });
220
+ m.prototype.clone = function() {
221
+ return new m(this, { body: this._bodyInit });
225
222
  };
226
223
  function C(e) {
227
224
  var t = new FormData();
@@ -245,28 +242,28 @@ var O = { exports: {} };
245
242
  }
246
243
  }), t;
247
244
  }
248
- x.call(w.prototype);
249
- function d(e, t) {
250
- if (!(this instanceof d))
245
+ x.call(m.prototype);
246
+ function l(e, t) {
247
+ if (!(this instanceof l))
251
248
  throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');
252
249
  t || (t = {}), this.type = "default", this.status = t.status === void 0 ? 200 : t.status, this.ok = this.status >= 200 && this.status < 300, this.statusText = t.statusText === void 0 ? "" : "" + t.statusText, this.headers = new s(t.headers), this.url = t.url || "", this._initBody(e);
253
250
  }
254
- x.call(d.prototype), d.prototype.clone = function() {
255
- return new d(this._bodyInit, {
251
+ x.call(l.prototype), l.prototype.clone = function() {
252
+ return new l(this._bodyInit, {
256
253
  status: this.status,
257
254
  statusText: this.statusText,
258
255
  headers: new s(this.headers),
259
256
  url: this.url
260
257
  });
261
- }, d.error = function() {
262
- var e = new d(null, { status: 0, statusText: "" });
258
+ }, l.error = function() {
259
+ var e = new l(null, { status: 0, statusText: "" });
263
260
  return e.type = "error", e;
264
261
  };
265
262
  var N = [301, 302, 303, 307, 308];
266
- d.redirect = function(e, t) {
263
+ l.redirect = function(e, t) {
267
264
  if (N.indexOf(t) === -1)
268
265
  throw new RangeError("Invalid status code");
269
- return new d(null, { status: t, headers: { location: e } });
266
+ return new l(null, { status: t, headers: { location: e } });
270
267
  }, u.DOMException = a.DOMException;
271
268
  try {
272
269
  new u.DOMException();
@@ -279,7 +276,7 @@ var O = { exports: {} };
279
276
  }
280
277
  function B(e, t) {
281
278
  return new Promise(function(r, n) {
282
- var i = new w(e, t);
279
+ var i = new m(e, t);
283
280
  if (i.signal && i.signal.aborted)
284
281
  return n(new u.DOMException("Aborted", "AbortError"));
285
282
  var o = new XMLHttpRequest();
@@ -287,15 +284,15 @@ var O = { exports: {} };
287
284
  o.abort();
288
285
  }
289
286
  o.onload = function() {
290
- var h = {
287
+ var c = {
291
288
  status: o.status,
292
289
  statusText: o.statusText,
293
290
  headers: k(o.getAllResponseHeaders() || "")
294
291
  };
295
- h.url = "responseURL" in o ? o.responseURL : h.headers.get("X-Request-URL");
292
+ c.url = "responseURL" in o ? o.responseURL : c.headers.get("X-Request-URL");
296
293
  var g = "response" in o ? o.response : o.responseText;
297
294
  setTimeout(function() {
298
- r(new d(g, h));
295
+ r(new l(g, c));
299
296
  }, 0);
300
297
  }, o.onerror = function() {
301
298
  setTimeout(function() {
@@ -310,33 +307,33 @@ var O = { exports: {} };
310
307
  n(new u.DOMException("Aborted", "AbortError"));
311
308
  }, 0);
312
309
  };
313
- function G(h) {
310
+ function G(c) {
314
311
  try {
315
- return h === "" && a.location.href ? a.location.href : h;
312
+ return c === "" && a.location.href ? a.location.href : c;
316
313
  } catch {
317
- return h;
314
+ return c;
318
315
  }
319
316
  }
320
- o.open(i.method, G(i.url), !0), i.credentials === "include" ? o.withCredentials = !0 : i.credentials === "omit" && (o.withCredentials = !1), "responseType" in o && (f.blob ? o.responseType = "blob" : f.arrayBuffer && i.headers.get("Content-Type") && i.headers.get("Content-Type").indexOf("application/octet-stream") !== -1 && (o.responseType = "arraybuffer")), t && typeof t.headers == "object" && !(t.headers instanceof s) ? Object.getOwnPropertyNames(t.headers).forEach(function(h) {
321
- o.setRequestHeader(h, A(t.headers[h]));
322
- }) : i.headers.forEach(function(h, g) {
323
- o.setRequestHeader(g, h);
317
+ o.open(i.method, G(i.url), !0), i.credentials === "include" ? o.withCredentials = !0 : i.credentials === "omit" && (o.withCredentials = !1), "responseType" in o && (f.blob ? o.responseType = "blob" : f.arrayBuffer && i.headers.get("Content-Type") && i.headers.get("Content-Type").indexOf("application/octet-stream") !== -1 && (o.responseType = "arraybuffer")), t && typeof t.headers == "object" && !(t.headers instanceof s) ? Object.getOwnPropertyNames(t.headers).forEach(function(c) {
318
+ o.setRequestHeader(c, A(t.headers[c]));
319
+ }) : i.headers.forEach(function(c, g) {
320
+ o.setRequestHeader(g, c);
324
321
  }), i.signal && (i.signal.addEventListener("abort", _), o.onreadystatechange = function() {
325
322
  o.readyState === 4 && i.signal.removeEventListener("abort", _);
326
323
  }), o.send(typeof i._bodyInit > "u" ? null : i._bodyInit);
327
324
  });
328
325
  }
329
- return B.polyfill = !0, a.fetch || (a.fetch = B, a.Headers = s, a.Request = w, a.Response = d), u.Headers = s, u.Request = w, u.Response = d, u.fetch = B, u;
326
+ return B.polyfill = !0, a.fetch || (a.fetch = B, a.Headers = s, a.Request = m, a.Response = l), u.Headers = s, u.Request = m, u.Response = l, u.fetch = B, u;
330
327
  })({});
331
- })(p), p.fetch.ponyfill = !0, delete p.fetch.polyfill;
332
- var l = m.fetch ? m : p;
333
- y = l.fetch, y.default = l.fetch, y.fetch = l.fetch, y.Headers = l.Headers, y.Request = l.Request, y.Response = l.Response, c.exports = y;
328
+ })(y), y.fetch.ponyfill = !0, delete y.fetch.polyfill;
329
+ var h = b.fetch ? b : y;
330
+ d = h.fetch, d.default = h.fetch, d.fetch = h.fetch, d.Headers = h.Headers, d.Request = h.Request, d.Response = h.Response, w.exports = d;
334
331
  })(O, O.exports);
335
332
  var U = O.exports;
336
- const $ = /* @__PURE__ */ z(U), X = /* @__PURE__ */ V({
333
+ const $ = /* @__PURE__ */ V(U), J = /* @__PURE__ */ z({
337
334
  __proto__: null,
338
335
  default: $
339
336
  }, [U]);
340
337
  export {
341
- X as b
338
+ J as b
342
339
  };
@@ -0,0 +1,2 @@
1
+ "use strict";const O=require("./index-WFlkDf6U.cjs");function V(w,d){for(var b=0;b<d.length;b++){const y=d[b];if(typeof y!="string"&&!Array.isArray(y)){for(const h in y)if(h!=="default"&&!(h in w)){const p=Object.getOwnPropertyDescriptor(y,h);p&&Object.defineProperty(w,h,p.get?p:{enumerable:!0,get:()=>y[h]})}}}return Object.freeze(Object.defineProperty(w,Symbol.toStringTag,{value:"Module"}))}var P={exports:{}};(function(w,d){var b=typeof globalThis<"u"&&globalThis||typeof self<"u"&&self||typeof O.commonjsGlobal<"u"&&O.commonjsGlobal,y=function(){function p(){this.fetch=!1,this.DOMException=b.DOMException}return p.prototype=b,new p}();(function(p){(function(u){var a=typeof p<"u"&&p||typeof self<"u"&&self||typeof a<"u"&&a,f={searchParams:"URLSearchParams"in a,iterable:"Symbol"in a&&"iterator"in Symbol,blob:"FileReader"in a&&"Blob"in a&&function(){try{return new Blob,!0}catch{return!1}}(),formData:"FormData"in a,arrayBuffer:"ArrayBuffer"in a};function j(e){return e&&DataView.prototype.isPrototypeOf(e)}if(f.arrayBuffer)var S=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],F=ArrayBuffer.isView||function(e){return e&&S.indexOf(Object.prototype.toString.call(e))>-1};function v(e){if(typeof e!="string"&&(e=String(e)),/[^a-z0-9\-#$%&'*+.^_`|~!]/i.test(e)||e==="")throw new TypeError('Invalid character in header field name: "'+e+'"');return e.toLowerCase()}function A(e){return typeof e!="string"&&(e=String(e)),e}function E(e){var t={next:function(){var r=e.shift();return{done:r===void 0,value:r}}};return f.iterable&&(t[Symbol.iterator]=function(){return t}),t}function s(e){this.map={},e instanceof s?e.forEach(function(t,r){this.append(r,t)},this):Array.isArray(e)?e.forEach(function(t){this.append(t[0],t[1])},this):e&&Object.getOwnPropertyNames(e).forEach(function(t){this.append(t,e[t])},this)}s.prototype.append=function(e,t){e=v(e),t=A(t);var r=this.map[e];this.map[e]=r?r+", "+t:t},s.prototype.delete=function(e){delete this.map[v(e)]},s.prototype.get=function(e){return e=v(e),this.has(e)?this.map[e]:null},s.prototype.has=function(e){return this.map.hasOwnProperty(v(e))},s.prototype.set=function(e,t){this.map[v(e)]=A(t)},s.prototype.forEach=function(e,t){for(var r in this.map)this.map.hasOwnProperty(r)&&e.call(t,this.map[r],r,this)},s.prototype.keys=function(){var e=[];return this.forEach(function(t,r){e.push(r)}),E(e)},s.prototype.values=function(){var e=[];return this.forEach(function(t){e.push(t)}),E(e)},s.prototype.entries=function(){var e=[];return this.forEach(function(t,r){e.push([r,t])}),E(e)},f.iterable&&(s.prototype[Symbol.iterator]=s.prototype.entries);function T(e){if(e.bodyUsed)return Promise.reject(new TypeError("Already read"));e.bodyUsed=!0}function D(e){return new Promise(function(t,r){e.onload=function(){t(e.result)},e.onerror=function(){r(e.error)}})}function I(e){var t=new FileReader,r=D(t);return t.readAsArrayBuffer(e),r}function M(e){var t=new FileReader,r=D(t);return t.readAsText(e),r}function H(e){for(var t=new Uint8Array(e),r=new Array(t.length),n=0;n<t.length;n++)r[n]=String.fromCharCode(t[n]);return r.join("")}function x(e){if(e.slice)return e.slice(0);var t=new Uint8Array(e.byteLength);return t.set(new Uint8Array(e)),t.buffer}function R(){return this.bodyUsed=!1,this._initBody=function(e){this.bodyUsed=this.bodyUsed,this._bodyInit=e,e?typeof e=="string"?this._bodyText=e:f.blob&&Blob.prototype.isPrototypeOf(e)?this._bodyBlob=e:f.formData&&FormData.prototype.isPrototypeOf(e)?this._bodyFormData=e:f.searchParams&&URLSearchParams.prototype.isPrototypeOf(e)?this._bodyText=e.toString():f.arrayBuffer&&f.blob&&j(e)?(this._bodyArrayBuffer=x(e.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):f.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(e)||F(e))?this._bodyArrayBuffer=x(e):this._bodyText=e=Object.prototype.toString.call(e):this._bodyText="",this.headers.get("content-type")||(typeof e=="string"?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):f.searchParams&&URLSearchParams.prototype.isPrototypeOf(e)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},f.blob&&(this.blob=function(){var e=T(this);if(e)return e;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){if(this._bodyArrayBuffer){var e=T(this);return e||(ArrayBuffer.isView(this._bodyArrayBuffer)?Promise.resolve(this._bodyArrayBuffer.buffer.slice(this._bodyArrayBuffer.byteOffset,this._bodyArrayBuffer.byteOffset+this._bodyArrayBuffer.byteLength)):Promise.resolve(this._bodyArrayBuffer))}else return this.blob().then(I)}),this.text=function(){var e=T(this);if(e)return e;if(this._bodyBlob)return M(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(H(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},f.formData&&(this.formData=function(){return this.text().then(C)}),this.json=function(){return this.text().then(JSON.parse)},this}var q=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function L(e){var t=e.toUpperCase();return q.indexOf(t)>-1?t:e}function m(e,t){if(!(this instanceof m))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');t=t||{};var r=t.body;if(e instanceof m){if(e.bodyUsed)throw new TypeError("Already read");this.url=e.url,this.credentials=e.credentials,t.headers||(this.headers=new s(e.headers)),this.method=e.method,this.mode=e.mode,this.signal=e.signal,!r&&e._bodyInit!=null&&(r=e._bodyInit,e.bodyUsed=!0)}else this.url=String(e);if(this.credentials=t.credentials||this.credentials||"same-origin",(t.headers||!this.headers)&&(this.headers=new s(t.headers)),this.method=L(t.method||this.method||"GET"),this.mode=t.mode||this.mode||null,this.signal=t.signal||this.signal,this.referrer=null,(this.method==="GET"||this.method==="HEAD")&&r)throw new TypeError("Body not allowed for GET or HEAD requests");if(this._initBody(r),(this.method==="GET"||this.method==="HEAD")&&(t.cache==="no-store"||t.cache==="no-cache")){var n=/([?&])_=[^&]*/;if(n.test(this.url))this.url=this.url.replace(n,"$1_="+new Date().getTime());else{var i=/\?/;this.url+=(i.test(this.url)?"&":"?")+"_="+new Date().getTime()}}}m.prototype.clone=function(){return new m(this,{body:this._bodyInit})};function C(e){var t=new FormData;return e.trim().split("&").forEach(function(r){if(r){var n=r.split("="),i=n.shift().replace(/\+/g," "),o=n.join("=").replace(/\+/g," ");t.append(decodeURIComponent(i),decodeURIComponent(o))}}),t}function k(e){var t=new s,r=e.replace(/\r?\n[\t ]+/g," ");return r.split("\r").map(function(n){return n.indexOf(`
2
+ `)===0?n.substr(1,n.length):n}).forEach(function(n){var i=n.split(":"),o=i.shift().trim();if(o){var _=i.join(":").trim();t.append(o,_)}}),t}R.call(m.prototype);function c(e,t){if(!(this instanceof c))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');t||(t={}),this.type="default",this.status=t.status===void 0?200:t.status,this.ok=this.status>=200&&this.status<300,this.statusText=t.statusText===void 0?"":""+t.statusText,this.headers=new s(t.headers),this.url=t.url||"",this._initBody(e)}R.call(c.prototype),c.prototype.clone=function(){return new c(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new s(this.headers),url:this.url})},c.error=function(){var e=new c(null,{status:0,statusText:""});return e.type="error",e};var N=[301,302,303,307,308];c.redirect=function(e,t){if(N.indexOf(t)===-1)throw new RangeError("Invalid status code");return new c(null,{status:t,headers:{location:e}})},u.DOMException=a.DOMException;try{new u.DOMException}catch{u.DOMException=function(t,r){this.message=t,this.name=r;var n=Error(t);this.stack=n.stack},u.DOMException.prototype=Object.create(Error.prototype),u.DOMException.prototype.constructor=u.DOMException}function B(e,t){return new Promise(function(r,n){var i=new m(e,t);if(i.signal&&i.signal.aborted)return n(new u.DOMException("Aborted","AbortError"));var o=new XMLHttpRequest;function _(){o.abort()}o.onload=function(){var l={status:o.status,statusText:o.statusText,headers:k(o.getAllResponseHeaders()||"")};l.url="responseURL"in o?o.responseURL:l.headers.get("X-Request-URL");var g="response"in o?o.response:o.responseText;setTimeout(function(){r(new c(g,l))},0)},o.onerror=function(){setTimeout(function(){n(new TypeError("Network request failed"))},0)},o.ontimeout=function(){setTimeout(function(){n(new TypeError("Network request failed"))},0)},o.onabort=function(){setTimeout(function(){n(new u.DOMException("Aborted","AbortError"))},0)};function G(l){try{return l===""&&a.location.href?a.location.href:l}catch{return l}}o.open(i.method,G(i.url),!0),i.credentials==="include"?o.withCredentials=!0:i.credentials==="omit"&&(o.withCredentials=!1),"responseType"in o&&(f.blob?o.responseType="blob":f.arrayBuffer&&i.headers.get("Content-Type")&&i.headers.get("Content-Type").indexOf("application/octet-stream")!==-1&&(o.responseType="arraybuffer")),t&&typeof t.headers=="object"&&!(t.headers instanceof s)?Object.getOwnPropertyNames(t.headers).forEach(function(l){o.setRequestHeader(l,A(t.headers[l]))}):i.headers.forEach(function(l,g){o.setRequestHeader(g,l)}),i.signal&&(i.signal.addEventListener("abort",_),o.onreadystatechange=function(){o.readyState===4&&i.signal.removeEventListener("abort",_)}),o.send(typeof i._bodyInit>"u"?null:i._bodyInit)})}return B.polyfill=!0,a.fetch||(a.fetch=B,a.Headers=s,a.Request=m,a.Response=c),u.Headers=s,u.Request=m,u.Response=c,u.fetch=B,u})({})})(y),y.fetch.ponyfill=!0,delete y.fetch.polyfill;var h=b.fetch?b:y;d=h.fetch,d.default=h.fetch,d.fetch=h.fetch,d.Headers=h.Headers,d.Request=h.Request,d.Response=h.Response,w.exports=d})(P,P.exports);var U=P.exports;const z=O.getDefaultExportFromCjs(U),$=V({__proto__:null,default:z},[U]);exports.browserPonyfill=$;
@@ -1,4 +1,4 @@
1
- "use strict";var P=Object.defineProperty;var q=(t,e,r)=>e in t?P(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var n=(t,e,r)=>(q(t,typeof e!="symbol"?e+"":e,r),r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("./acms-path.cjs"),o=require("../typeGuard-eqTQ9U-x.cjs"),c=require("../index-x-5Zn68j.cjs");async function b(t){try{const{message:e}=await t.json();return e??null}catch{return null}}async function A(){if(typeof fetch>"u"){const{default:t}=await Promise.resolve().then(()=>require("../browser-ponyfill-fsIF2jNb.cjs")).then(e=>e.browserPonyfill);return t}return fetch}async function F(...t){if(typeof Headers>"u"){const{Headers:e}=await Promise.resolve().then(()=>require("../browser-ponyfill-fsIF2jNb.cjs")).then(r=>r.browserPonyfill);return new e(...t)}return new Headers(...t)}const U={responseType:"json"};class ${constructor({baseUrl:e,apiKey:r,...i}){n(this,"baseUrl");n(this,"apiKey");n(this,"config");if(e==null&&e==="")throw new Error("baseUrl is required.");if(r==null&&r==="")throw new Error("apiKey is required.");if(!o.isString(e))throw new Error("baseUrl must be string.");if(!o.isString(r))throw new Error("apiKey must be string.");this.baseUrl=e,this.apiKey=r,this.config={...U,...i}}async request(e,r={}){const i={...this.config,...r},{requestInit:l,responseType:d}=i,y=await A(),m=this.createUrl(e),p=await this.createFetchOptions(l);try{const s=await y(m,p),{ok:E,status:a,statusText:u,headers:g}=s,h={data:await s[d](),status:a,statusText:u,headers:g};if(!E){const f=await b(s);return await Promise.reject(new c.AcmsFetchError(`fetch API response status: ${a}${f!=null?`
2
- message is \`${f}\``:""}`,`${a} ${u}`,h))}return h}catch(s){return s instanceof Error?await Promise.reject(new Error(`Network Error.
1
+ "use strict";var q=Object.defineProperty;var A=(r,e,t)=>e in r?q(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var n=(r,e,t)=>(A(r,typeof e!="symbol"?e+"":e,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("../index-WFlkDf6U.cjs"),c=require("../typeGuard-eqTQ9U-x.cjs"),a=require("../index-x-5Zn68j.cjs");async function P(r){try{const{message:e}=await r.json();return e??null}catch{return null}}async function b(){if(typeof fetch>"u"){const{default:r}=await Promise.resolve().then(()=>require("../browser-ponyfill-r3mBr4hd.cjs")).then(e=>e.browserPonyfill);return r}return fetch}async function F(...r){if(typeof Headers>"u"){const{Headers:e}=await Promise.resolve().then(()=>require("../browser-ponyfill-r3mBr4hd.cjs")).then(t=>t.browserPonyfill);return new e(...r)}return new Headers(...r)}const U={responseType:"json",acmsPathOptions:{}};class ${constructor({baseUrl:e,apiKey:t,...i}){n(this,"baseUrl");n(this,"apiKey");n(this,"config");if(e!=null&&e==="")throw new Error("baseUrl is required.");if(t!=null&&t==="")throw new Error("apiKey is required.");if(!c.isString(e))throw new Error("baseUrl must be string.");if(!c.isString(t))throw new Error("apiKey must be string.");this.baseUrl=e,this.apiKey=t,this.config={...U,...i}}async request(e,t={}){const i={...this.config,...t},{requestInit:l,responseType:d}=i,p=await b(),g=this.createUrl(e),m=await this.createFetchOptions(l);try{const s=await p(g,m),{ok:y,status:o,statusText:h,headers:E}=s,f={data:await s[d](),status:o,statusText:h,headers:E};if(!y){const w=await P(s);return await Promise.reject(new a.AcmsFetchError(`fetch API response status: ${o}${w!=null?`
2
+ message is \`${w}\``:""}`,`${o} ${h}`,f))}return f}catch(s){return s instanceof Error?await Promise.reject(new Error(`Network Error.
3
3
  Details: ${s.message}`)):await Promise.reject(new Error(`Network Error.
4
- Details: Unknown Error`))}}async createFetchOptions(e){const r=await F(e==null?void 0:e.headers);return r.has("X-API-KEY")||r.set("X-API-KEY",this.apiKey),{...e,headers:r}}createUrl(e){return o.isString(e)?new URL(e,this.baseUrl):e instanceof URL?new URL(e,this.baseUrl):new URL(w({...e}),this.baseUrl)}async get(e,r={}){return await this.request(e,{...r,requestInit:{...r.requestInit,method:"GET"}})}static isAcmsFetchError(e){return c.isAcmsFetchError(e)}}function j(...t){return new $(...t)}exports.acmsPath=w;exports.isAcmsFetchError=c.isAcmsFetchError;exports.createClient=j;
4
+ Details: Unknown Error`))}}async createFetchOptions(e){const t=await F(e==null?void 0:e.headers);return t.has("X-API-KEY")||t.set("X-API-KEY",this.apiKey),{...e,headers:t}}createUrl(e){return c.isString(e)?new URL(e,this.baseUrl):e instanceof URL?new URL(e,this.baseUrl):new URL(u.acmsPath({...e},this.config.acmsPathOptions),this.baseUrl)}async get(e,t={}){return await this.request(e,{...t,requestInit:{...t.requestInit,method:"GET"}})}static isAcmsFetchError(e){return a.isAcmsFetchError(e)}getConfig(){return this.config}}function j(...r){return new $(...r)}exports.acmsPath=u.acmsPath;exports.parseAcmsPath=u.parseAcmsPath;exports.isAcmsFetchError=a.isAcmsFetchError;exports.createClient=j;
@@ -1 +1 @@
1
- "use strict";const f=require("../typeGuard-eqTQ9U-x.cjs");function s(n){return encodeURIComponent(n).replace(/[!'()*]/g,i=>`%${i.charCodeAt(0).toString(16)}`)}function a(n){return!isNaN(Date.parse(n))}function m(n={}){let i=["blog","category","entry","user","tag","field","span","date","page","order","limit","keyword","tpl","api"].reduce((t,e)=>{const o=n[e];if(o==null)return t;if(e==="blog"){const r=n[e];return f.isNumber(r)?`${t}/bid/${r}`:`${t}/${r.split("/").map(s).join("/")}`}if(e==="category"){const r=n[e];return f.isNumber(r)?`${t}/cid/${r}`:Array.isArray(r)?`${t}/${r.map(s).join("/")}`:`${t}/${s(r)}`}if(e==="entry"){const r=n[e];return f.isNumber(r)?`${t}/eid/${r}`:`${t}/${s(r)}`}if(e==="user"){const r=n[e];return`${t}/uid/${r}`}if(e==="field"){const r=n[e];return`${t}/field/${r.split("/").map(s).join("/")}`}if(e==="span"){const{start:r,end:u}={start:"1000-01-01 00:00:00",end:"9999-12-31 23:59:59",...n[e]};if(f.isString(r)&&!a(r))throw new Error(`Invalid start date: ${r}`);if(f.isString(u)&&!a(u))throw new Error(`Invalid end date: ${u}`);return`${t}/${s(d(new Date(r)))}/-/${s(d(new Date(u)))}`}if(e==="date"){if(n.span!=null)return t;const{year:r,month:u,day:$}=n[e];return[r,u,$].reduce((g,l)=>l==null?g:`${g}/${l}`,t)}if(e==="page"){const r=n[e];return r===1?t:`${t}/page/${r}`}if(e==="tpl"){const r=n[e];return`${t}/tpl/${r.split("/").map(s).join("/")}`}return Array.isArray(o)?o.length>0?`${t}/${e}/${o.map(s).join("/")}`:t:`${t}/${e}/${s(o)}`},"");/\.[^/.]+$/.test(i)||(i+="/");const c=new URLSearchParams(n.searchParams);return c.size>0&&(i+=`?${c.toString()}`),i.startsWith("/")?i.slice(1):i}function d(n){function i($){return $<10?"0"+$:$}const c=n.getFullYear(),t=i(n.getMonth()+1),e=i(n.getDate()),o=i(n.getHours()),r=i(n.getMinutes()),u=i(n.getSeconds());return`${c}-${t}-${e} ${o}:${r}:${u}`}module.exports=m;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../index-WFlkDf6U.cjs");require("../typeGuard-eqTQ9U-x.cjs");exports.acmsPath=e.acmsPath;exports.parseAcmsPath=e.parseAcmsPath;