@uidev1116/acms-js-sdk 0.0.3 → 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
@@ -5,11 +5,11 @@ JavaScript SDK for a-blog cms. Works in Node.js and modern browsers.
5
5
  ## Installation
6
6
 
7
7
  ```bash
8
- npm install acms-js-sdk
8
+ npm install @uidev1116/acms-js-sdk
9
9
 
10
10
  # or
11
11
 
12
- yarn add acms-js-sdk
12
+ yarn add @uidev1116/acms-js-sdk
13
13
  ```
14
14
 
15
15
  ## Usage
@@ -19,7 +19,7 @@ First, you need to create a client instance.
19
19
  ES Modules:
20
20
 
21
21
  ```js
22
- import { createClient } from 'acms-js-sdk';
22
+ import { createClient } from '@uidev1116/acms-js-sdk';
23
23
 
24
24
  const acmsClient = createClient({
25
25
  baseUrl: 'YOUR_BASE_URL',
@@ -30,7 +30,7 @@ const acmsClient = createClient({
30
30
  CommonJS:
31
31
 
32
32
  ```js
33
- const { createClient } = require('acms-js-sdk');
33
+ const { createClient } = require('@uidev1116/acms-js-sdk');
34
34
 
35
35
  const acmsClient = createClient({
36
36
  baseUrl: 'YOUR_BASE_URL',
@@ -42,7 +42,7 @@ CDN:
42
42
 
43
43
  ```html
44
44
  <script type="module">
45
- const { createClient } = 'https://unpkg.com/acms-js-sdk/dist/es/acms-js-sdk.js';
45
+ const { createClient } = 'https://unpkg.com/@uidev1116/acms-js-sdk@latest/dist/es/acms-js-sdk.js';
46
46
 
47
47
  const acmsClient = createClient({
48
48
  baseUrl: 'YOUR_BASE_URL',
@@ -68,7 +68,7 @@ acmsClient
68
68
  });
69
69
  ```
70
70
 
71
- Relative paths can also be specified.
71
+ Relative paths from `baseUrl` can also be specified.
72
72
 
73
73
  ```js
74
74
  acmsClient
@@ -101,6 +101,8 @@ acmsClient
101
101
  });
102
102
  ```
103
103
 
104
+ You can see the acmsPath section for more details.
105
+
104
106
  ### Error Handling
105
107
 
106
108
  You can handle errors.
@@ -124,13 +126,95 @@ acmsClient
124
126
  });
125
127
  ```
126
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
+
127
211
  ## acmsPath
128
212
 
129
213
  You can get the path of Url Context by using utility function `acmsPath`.
130
214
 
131
215
  ```js
132
216
 
133
- import { acmsPath } from 'acms-js-sdk';
217
+ import { acmsPath } from '@uidev1116/acms-js-sdk';
134
218
 
135
219
  const path = acmsPath({
136
220
  blog: 'BLOG_CODE',
@@ -146,6 +230,7 @@ const path = acmsPath({
146
230
  // limit: 10,
147
231
  // keyword: 'KEYWORD',
148
232
  // tpl: 'include/sample.json'
233
+ // admin: 'entry_index',
149
234
  api: 'MODULE_ID',
150
235
  });
151
236
  ```
@@ -153,8 +238,9 @@ const path = acmsPath({
153
238
  ### Params Type
154
239
 
155
240
  ```ts
156
- interface AcmsContext {
241
+ interface AcmsPathParams {
157
242
  blog?: string | number;
243
+ admin?: string;
158
244
  category?: string | string[] | number;
159
245
  entry?: string | number;
160
246
  user?: number;
@@ -177,7 +263,7 @@ interface AcmsContext {
177
263
  You can check if the error is `AcmsFetchError` by using utility function `isAcmsFetchError`.
178
264
 
179
265
  ```js
180
- import { isAcmsFetchError } from 'acms-js-sdk';
266
+ import { isAcmsFetchError } from '@uidev1116/acms-js-sdk';
181
267
 
182
268
  acmsClient
183
269
  .get({
@@ -194,3 +280,22 @@ acmsClient
194
280
  console.error(error);
195
281
  });
196
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;
@@ -1,72 +1,74 @@
1
- var y = Object.defineProperty;
2
- var g = (t, e, r) => e in t ? y(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
3
- var n = (t, e, r) => (g(t, typeof e != "symbol" ? e + "" : e, r), r);
4
- import b from "./acms-path.js";
5
- import { a as i } from "../typeGuard-30fb1DDr.js";
6
- import { A, i as q } from "../index-w7KUzF0v.js";
7
- async function F(t) {
1
+ var E = Object.defineProperty;
2
+ var y = (r, e, t) => e in r ? E(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
3
+ var n = (r, e, t) => (y(r, typeof e != "symbol" ? e + "" : e, t), t);
4
+ import { a as A } from "../index-H2fSgwjT.js";
5
+ import { p as D } from "../index-H2fSgwjT.js";
6
+ import { i as a } from "../typeGuard-Jsany_41.js";
7
+ import { A as b, i as q } from "../index-ZZQxXurp.js";
8
+ async function F(r) {
8
9
  try {
9
- const { message: e } = await t.json();
10
+ const { message: e } = await r.json();
10
11
  return e ?? null;
11
12
  } catch {
12
13
  return null;
13
14
  }
14
15
  }
15
- async function P() {
16
+ async function U() {
16
17
  if (typeof fetch > "u") {
17
- const { default: t } = await import("../browser-ponyfill-lYv-p29A.js").then((e) => e.b);
18
- return t;
18
+ const { default: r } = await import("../browser-ponyfill-EPWIFhDK.js").then((e) => e.b);
19
+ return r;
19
20
  }
20
21
  return fetch;
21
22
  }
22
- async function U(...t) {
23
+ async function I(...r) {
23
24
  if (typeof Headers > "u") {
24
- const { Headers: e } = await import("../browser-ponyfill-lYv-p29A.js").then((r) => r.b);
25
- return new e(...t);
25
+ const { Headers: e } = await import("../browser-ponyfill-EPWIFhDK.js").then((t) => t.b);
26
+ return new e(...r);
26
27
  }
27
- return new Headers(...t);
28
+ return new Headers(...r);
28
29
  }
29
- const I = {
30
- responseType: "json"
30
+ const R = {
31
+ responseType: "json",
32
+ acmsPathOptions: {}
31
33
  };
32
- class R {
34
+ class $ {
33
35
  constructor({
34
36
  baseUrl: e,
35
- apiKey: r,
36
- ...a
37
+ apiKey: t,
38
+ ...o
37
39
  }) {
38
40
  n(this, "baseUrl");
39
41
  n(this, "apiKey");
40
42
  n(this, "config");
41
43
  if (e != null && e === "")
42
44
  throw new Error("baseUrl is required.");
43
- if (r != null && r === "")
45
+ if (t != null && t === "")
44
46
  throw new Error("apiKey is required.");
45
- if (!i(e))
47
+ if (!a(e))
46
48
  throw new Error("baseUrl must be string.");
47
- if (!i(r))
49
+ if (!a(t))
48
50
  throw new Error("apiKey must be string.");
49
- this.baseUrl = e, this.apiKey = r, this.config = {
50
- ...I,
51
- ...a
51
+ this.baseUrl = e, this.apiKey = t, this.config = {
52
+ ...R,
53
+ ...o
52
54
  };
53
55
  }
54
- async request(e, r = {}) {
55
- const a = { ...this.config, ...r }, { requestInit: f, responseType: w } = a, m = await P(), p = this.createUrl(e), l = await this.createFetchOptions(f);
56
+ async request(e, t = {}) {
57
+ const o = { ...this.config, ...t }, { requestInit: h, responseType: w } = o, p = await U(), m = this.createUrl(e), l = await this.createFetchOptions(h);
56
58
  try {
57
- const s = await m(p, l), { ok: d, status: o, statusText: c, headers: E } = s, u = {
59
+ const s = await p(m, l), { ok: d, status: i, statusText: c, headers: g } = s, u = {
58
60
  data: await s[w](),
59
- status: o,
61
+ status: i,
60
62
  statusText: c,
61
- headers: E
63
+ headers: g
62
64
  };
63
65
  if (!d) {
64
- const h = await F(s);
66
+ const f = await F(s);
65
67
  return await Promise.reject(
66
- new A(
67
- `fetch API response status: ${o}${h != null ? `
68
- message is \`${h}\`` : ""}`,
69
- `${o} ${c}`,
68
+ new b(
69
+ `fetch API response status: ${i}${f != null ? `
70
+ message is \`${f}\`` : ""}`,
71
+ `${i} ${c}`,
70
72
  u
71
73
  )
72
74
  );
@@ -83,27 +85,34 @@ class R {
83
85
  }
84
86
  }
85
87
  async createFetchOptions(e) {
86
- const r = await U(e == null ? void 0 : e.headers);
87
- return r.has("X-API-KEY") || r.set("X-API-KEY", this.apiKey), { ...e, headers: r };
88
+ const t = await I(e == null ? void 0 : e.headers);
89
+ return t.has("X-API-KEY") || t.set("X-API-KEY", this.apiKey), { ...e, headers: t };
88
90
  }
89
91
  createUrl(e) {
90
- return i(e) ? new URL(e, this.baseUrl) : e instanceof URL ? new URL(e, this.baseUrl) : new URL(b({ ...e }), this.baseUrl);
92
+ return a(e) ? new URL(e, this.baseUrl) : e instanceof URL ? new URL(e, this.baseUrl) : new URL(
93
+ A({ ...e }, this.config.acmsPathOptions),
94
+ this.baseUrl
95
+ );
91
96
  }
92
- async get(e, r = {}) {
97
+ async get(e, t = {}) {
93
98
  return await this.request(e, {
94
- ...r,
95
- requestInit: { ...r.requestInit, method: "GET" }
99
+ ...t,
100
+ requestInit: { ...t.requestInit, method: "GET" }
96
101
  });
97
102
  }
98
103
  static isAcmsFetchError(e) {
99
104
  return q(e);
100
105
  }
106
+ getConfig() {
107
+ return this.config;
108
+ }
101
109
  }
102
- function L(...t) {
103
- return new R(...t);
110
+ function T(...r) {
111
+ return new $(...r);
104
112
  }
105
113
  export {
106
- b as acmsPath,
107
- L as createClient,
108
- q as isAcmsFetchError
114
+ A as acmsPath,
115
+ T as createClient,
116
+ q as isAcmsFetchError,
117
+ D as parseAcmsPath
109
118
  };