@uidev1116/acms-js-sdk 0.0.3 → 0.1.1
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 +114 -9
- package/dist/{browser-ponyfill-lYv-p29A.js → browser-ponyfill-EPWIFhDK.js} +53 -56
- package/dist/browser-ponyfill-r3mBr4hd.cjs +2 -0
- package/dist/cjs/acms-js-sdk.cjs +3 -3
- package/dist/cjs/acms-path.cjs +1 -1
- package/dist/es/acms-js-sdk.js +53 -47
- package/dist/es/acms-path.js +4 -92
- package/dist/es/type-guard.js +2 -2
- package/dist/index-H2fSgwjT.js +328 -0
- package/dist/index-WFlkDf6U.cjs +1 -0
- package/dist/{index-w7KUzF0v.js → index-ZZQxXurp.js} +1 -1
- package/dist/{typeGuard-30fb1DDr.js → typeGuard-Jsany_41.js} +2 -2
- package/dist/types/core/AcmsClient.d.ts +5 -4
- package/dist/types/index.d.ts +3 -1
- package/dist/types/lib/acmsPath/acmsPath.d.ts +2 -0
- package/dist/types/lib/acmsPath/acmsPath.test.d.ts +1 -0
- package/dist/types/lib/acmsPath/defaultOptions.d.ts +16 -0
- package/dist/types/lib/acmsPath/index.d.ts +3 -3
- package/dist/types/lib/acmsPath/parseAcmsPath.d.ts +2 -0
- package/dist/types/lib/acmsPath/parseAcmsPath.test.d.ts +1 -0
- package/dist/types/lib/acmsPath/types.d.ts +57 -1
- package/dist/types/lib/acmsPath/utils.d.ts +1 -0
- package/dist/types/types/index.d.ts +8 -0
- package/package.json +3 -2
- package/dist/browser-ponyfill-fsIF2jNb.cjs +0 -2
- /package/dist/types/{lib/acmsPath/index.test.d.ts → core/AcmsClient.test.d.ts} +0 -0
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> | 'blob'<br> | 'formData'<br> | 'json'<br> | '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
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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: () =>
|
|
11
|
+
get: () => y[h]
|
|
11
12
|
});
|
|
12
13
|
}
|
|
13
14
|
}
|
|
14
15
|
}
|
|
15
|
-
return Object.freeze(Object.defineProperty(
|
|
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(
|
|
23
|
-
var
|
|
24
|
-
function
|
|
25
|
-
this.fetch = !1, this.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
|
|
24
|
+
return p.prototype = b, new p();
|
|
28
25
|
}();
|
|
29
|
-
(function(
|
|
26
|
+
(function(p) {
|
|
30
27
|
(function(u) {
|
|
31
|
-
var a = typeof
|
|
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
|
|
131
|
+
function I(e) {
|
|
135
132
|
var t = new FileReader(), r = P(t);
|
|
136
133
|
return t.readAsArrayBuffer(e), r;
|
|
137
134
|
}
|
|
138
|
-
function
|
|
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(
|
|
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
|
|
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
|
|
201
|
-
if (!(this instanceof
|
|
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
|
|
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
|
-
|
|
224
|
-
return new
|
|
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(
|
|
249
|
-
function
|
|
250
|
-
if (!(this instanceof
|
|
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(
|
|
255
|
-
return new
|
|
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
|
-
},
|
|
262
|
-
var e = new
|
|
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
|
-
|
|
263
|
+
l.redirect = function(e, t) {
|
|
267
264
|
if (N.indexOf(t) === -1)
|
|
268
265
|
throw new RangeError("Invalid status code");
|
|
269
|
-
return new
|
|
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
|
|
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
|
|
287
|
+
var c = {
|
|
291
288
|
status: o.status,
|
|
292
289
|
statusText: o.statusText,
|
|
293
290
|
headers: k(o.getAllResponseHeaders() || "")
|
|
294
291
|
};
|
|
295
|
-
|
|
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
|
|
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(
|
|
310
|
+
function G(c) {
|
|
314
311
|
try {
|
|
315
|
-
return
|
|
312
|
+
return c === "" && a.location.href ? a.location.href : c;
|
|
316
313
|
} catch {
|
|
317
|
-
return
|
|
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(
|
|
321
|
-
o.setRequestHeader(
|
|
322
|
-
}) : i.headers.forEach(function(
|
|
323
|
-
o.setRequestHeader(g,
|
|
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 =
|
|
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
|
-
})(
|
|
332
|
-
var
|
|
333
|
-
|
|
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__ */
|
|
333
|
+
const $ = /* @__PURE__ */ V(U), J = /* @__PURE__ */ z({
|
|
337
334
|
__proto__: null,
|
|
338
335
|
default: $
|
|
339
336
|
}, [U]);
|
|
340
337
|
export {
|
|
341
|
-
|
|
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=$;
|
package/dist/cjs/acms-js-sdk.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
message is \`${
|
|
1
|
+
"use strict";var A=Object.defineProperty;var P=(r,e,t)=>e in r?A(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var n=(r,e,t)=>(P(r,typeof e!="symbol"?e+"":e,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("../index-WFlkDf6U.cjs"),a=require("../typeGuard-eqTQ9U-x.cjs"),c=require("../index-x-5Zn68j.cjs");async function b(r){try{const{message:e}=await r.json();return e??null}catch{return null}}async function F(){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 U(...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 $={responseType:"json",acmsPathOptions:{}};class j{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(!a.isString(e))throw new Error("baseUrl must be string.");if(!a.isString(t))throw new Error("apiKey must be string.");this.baseUrl=e,this.apiKey=t,this.config={...$,...i}}async request(e,t={}){const i={...this.config,...t},{requestInit:l,responseType:d,acmsPathOptions:p}=i,m=await F(),g=this.createUrl(e,p),y=await this.createFetchOptions(l);try{const s=await m(g,y),{ok:E,status:o,statusText:h,headers:q}=s,f={data:await s[d](),status:o,statusText:h,headers:q};if(!E){const w=await b(s);return await Promise.reject(new c.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
|
|
4
|
+
Details: Unknown Error`))}}async createFetchOptions(e){const t=await U(e==null?void 0:e.headers);return t.has("X-API-KEY")||t.set("X-API-KEY",this.apiKey),{...e,headers:t}}createUrl(e,t={}){return a.isString(e)?new URL(e,this.baseUrl):e instanceof URL?new URL(e,this.baseUrl):new URL(u.acmsPath({...e},t),this.baseUrl)}async get(e,t={}){return await this.request(e,{...t,requestInit:{...t.requestInit,method:"GET"}})}static isAcmsFetchError(e){return c.isAcmsFetchError(e)}getConfig(){return this.config}}function I(...r){return new j(...r)}exports.acmsPath=u.acmsPath;exports.parseAcmsPath=u.parseAcmsPath;exports.isAcmsFetchError=c.isAcmsFetchError;exports.createClient=I;
|
package/dist/cjs/acms-path.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";
|
|
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;
|
package/dist/es/acms-js-sdk.js
CHANGED
|
@@ -1,72 +1,74 @@
|
|
|
1
1
|
var y = Object.defineProperty;
|
|
2
|
-
var
|
|
3
|
-
var n = (
|
|
4
|
-
import b from "
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
2
|
+
var A = (r, e, t) => e in r ? y(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
|
|
3
|
+
var n = (r, e, t) => (A(r, typeof e != "symbol" ? e + "" : e, t), t);
|
|
4
|
+
import { a as b } from "../index-H2fSgwjT.js";
|
|
5
|
+
import { p as N } from "../index-H2fSgwjT.js";
|
|
6
|
+
import { i as a } from "../typeGuard-Jsany_41.js";
|
|
7
|
+
import { A as q, i as F } from "../index-ZZQxXurp.js";
|
|
8
|
+
async function U(r) {
|
|
8
9
|
try {
|
|
9
|
-
const { message: e } = await
|
|
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
|
|
16
|
+
async function I() {
|
|
16
17
|
if (typeof fetch > "u") {
|
|
17
|
-
const { default:
|
|
18
|
-
return
|
|
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
|
|
23
|
+
async function R(...r) {
|
|
23
24
|
if (typeof Headers > "u") {
|
|
24
|
-
const { Headers: e } = await import("../browser-ponyfill-
|
|
25
|
-
return new e(...
|
|
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(...
|
|
28
|
+
return new Headers(...r);
|
|
28
29
|
}
|
|
29
|
-
const
|
|
30
|
-
responseType: "json"
|
|
30
|
+
const $ = {
|
|
31
|
+
responseType: "json",
|
|
32
|
+
acmsPathOptions: {}
|
|
31
33
|
};
|
|
32
|
-
class
|
|
34
|
+
class j {
|
|
33
35
|
constructor({
|
|
34
36
|
baseUrl: e,
|
|
35
|
-
apiKey:
|
|
36
|
-
...
|
|
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 (
|
|
45
|
+
if (t != null && t === "")
|
|
44
46
|
throw new Error("apiKey is required.");
|
|
45
|
-
if (!
|
|
47
|
+
if (!a(e))
|
|
46
48
|
throw new Error("baseUrl must be string.");
|
|
47
|
-
if (!
|
|
49
|
+
if (!a(t))
|
|
48
50
|
throw new Error("apiKey must be string.");
|
|
49
|
-
this.baseUrl = e, this.apiKey =
|
|
50
|
-
|
|
51
|
-
...
|
|
51
|
+
this.baseUrl = e, this.apiKey = t, this.config = {
|
|
52
|
+
...$,
|
|
53
|
+
...o
|
|
52
54
|
};
|
|
53
55
|
}
|
|
54
|
-
async request(e,
|
|
55
|
-
const
|
|
56
|
+
async request(e, t = {}) {
|
|
57
|
+
const o = { ...this.config, ...t }, { requestInit: h, responseType: w, acmsPathOptions: p } = o, m = await I(), l = this.createUrl(e, p), d = await this.createFetchOptions(h);
|
|
56
58
|
try {
|
|
57
|
-
const s = await m(
|
|
59
|
+
const s = await m(l, d), { ok: g, status: i, statusText: c, headers: E } = s, u = {
|
|
58
60
|
data: await s[w](),
|
|
59
|
-
status:
|
|
61
|
+
status: i,
|
|
60
62
|
statusText: c,
|
|
61
63
|
headers: E
|
|
62
64
|
};
|
|
63
|
-
if (!
|
|
64
|
-
const
|
|
65
|
+
if (!g) {
|
|
66
|
+
const f = await U(s);
|
|
65
67
|
return await Promise.reject(
|
|
66
|
-
new
|
|
67
|
-
`fetch API response status: ${
|
|
68
|
-
message is \`${
|
|
69
|
-
`${
|
|
68
|
+
new q(
|
|
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,31 @@ class R {
|
|
|
83
85
|
}
|
|
84
86
|
}
|
|
85
87
|
async createFetchOptions(e) {
|
|
86
|
-
const
|
|
87
|
-
return
|
|
88
|
+
const t = await R(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
|
-
createUrl(e) {
|
|
90
|
-
return
|
|
91
|
+
createUrl(e, t = {}) {
|
|
92
|
+
return a(e) ? new URL(e, this.baseUrl) : e instanceof URL ? new URL(e, this.baseUrl) : new URL(b({ ...e }, t), this.baseUrl);
|
|
91
93
|
}
|
|
92
|
-
async get(e,
|
|
94
|
+
async get(e, t = {}) {
|
|
93
95
|
return await this.request(e, {
|
|
94
|
-
...
|
|
95
|
-
requestInit: { ...
|
|
96
|
+
...t,
|
|
97
|
+
requestInit: { ...t.requestInit, method: "GET" }
|
|
96
98
|
});
|
|
97
99
|
}
|
|
98
100
|
static isAcmsFetchError(e) {
|
|
99
|
-
return
|
|
101
|
+
return F(e);
|
|
102
|
+
}
|
|
103
|
+
getConfig() {
|
|
104
|
+
return this.config;
|
|
100
105
|
}
|
|
101
106
|
}
|
|
102
|
-
function
|
|
103
|
-
return new
|
|
107
|
+
function x(...r) {
|
|
108
|
+
return new j(...r);
|
|
104
109
|
}
|
|
105
110
|
export {
|
|
106
111
|
b as acmsPath,
|
|
107
|
-
|
|
108
|
-
|
|
112
|
+
x as createClient,
|
|
113
|
+
F as isAcmsFetchError,
|
|
114
|
+
N as parseAcmsPath
|
|
109
115
|
};
|