@uidev1116/acms-js-sdk 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
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.
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"),o=require("../index-x-5Zn68j.cjs");async function U(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 O(...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 b{constructor({baseUrl:e,apiKey:t,...a}){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={...$,...a}}async request(e,t={}){const a={...this.config,...t},{requestInit:l,responseType:m,acmsPathOptions:d}=a,g=await F(),y=this.createUrl(e,d),P=await this.createFetchOptions(l);try{const s=await g(y,P),{ok:p,status:i,statusText:h,headers:E}=s,f={data:await s[m](),status:i,statusText:h,headers:E};if(!p){const w=await U(s);return await Promise.reject(new o.AcmsFetchError(`fetch API response status: ${i}${w!=null?`
2
+ message is \`${w}\``:""}`,`${i} ${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 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;
4
+ Details: Unknown Error`))}}async createFetchOptions(e){const t=await O(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 c.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 o.isAcmsFetchError(e)}getConfig(){return this.config}}function j(...r){return new b(...r)}exports.acmsPath=u.acmsPath;exports.parseAcmsPath=u.parseAcmsPath;exports.isAcmsFetchError=o.isAcmsFetchError;exports.createClient=j;
@@ -1,11 +1,11 @@
1
1
  var y = Object.defineProperty;
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) {
2
+ var U = (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) => (U(r, typeof e != "symbol" ? e + "" : e, t), t);
4
+ import { a as P } from "../index-H2fSgwjT.js";
5
+ import { p as D } from "../index-H2fSgwjT.js";
6
+ import { i as o } from "../typeGuard-Jsany_41.js";
7
+ import { A, i as q } from "../index-ZZQxXurp.js";
8
+ async function F(r) {
9
9
  try {
10
10
  const { message: e } = await r.json();
11
11
  return e ?? null;
@@ -20,22 +20,22 @@ async function I() {
20
20
  }
21
21
  return fetch;
22
22
  }
23
- async function R(...r) {
23
+ async function O(...r) {
24
24
  if (typeof Headers > "u") {
25
25
  const { Headers: e } = await import("../browser-ponyfill-EPWIFhDK.js").then((t) => t.b);
26
26
  return new e(...r);
27
27
  }
28
28
  return new Headers(...r);
29
29
  }
30
- const $ = {
30
+ const R = {
31
31
  responseType: "json",
32
32
  acmsPathOptions: {}
33
33
  };
34
- class j {
34
+ class $ {
35
35
  constructor({
36
36
  baseUrl: e,
37
37
  apiKey: t,
38
- ...o
38
+ ...a
39
39
  }) {
40
40
  n(this, "baseUrl");
41
41
  n(this, "apiKey");
@@ -44,36 +44,36 @@ class j {
44
44
  throw new Error("baseUrl is required.");
45
45
  if (t != null && t === "")
46
46
  throw new Error("apiKey is required.");
47
- if (!a(e))
47
+ if (!o(e))
48
48
  throw new Error("baseUrl must be string.");
49
- if (!a(t))
49
+ if (!o(t))
50
50
  throw new Error("apiKey must be string.");
51
51
  this.baseUrl = e, this.apiKey = t, this.config = {
52
- ...$,
53
- ...o
52
+ ...R,
53
+ ...a
54
54
  };
55
55
  }
56
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);
57
+ const a = { ...this.config, ...t }, { requestInit: f, responseType: w, acmsPathOptions: m } = a, p = await I(), d = this.createUrl(e, m), g = await this.createFetchOptions(f);
58
58
  try {
59
- const s = await m(l, d), { ok: g, status: i, statusText: c, headers: E } = s, u = {
59
+ const s = await p(d, g), { ok: l, status: i, statusText: c, headers: E } = s, h = {
60
60
  data: await s[w](),
61
61
  status: i,
62
62
  statusText: c,
63
63
  headers: E
64
64
  };
65
- if (!g) {
66
- const f = await U(s);
65
+ if (!l) {
66
+ const u = await F(s);
67
67
  return await Promise.reject(
68
- new q(
69
- `fetch API response status: ${i}${f != null ? `
70
- message is \`${f}\`` : ""}`,
68
+ new A(
69
+ `fetch API response status: ${i}${u != null ? `
70
+ message is \`${u}\`` : ""}`,
71
71
  `${i} ${c}`,
72
- u
72
+ h
73
73
  )
74
74
  );
75
75
  }
76
- return u;
76
+ return h;
77
77
  } catch (s) {
78
78
  return s instanceof Error ? await Promise.reject(
79
79
  new Error(`Network Error.
@@ -85,11 +85,11 @@ class j {
85
85
  }
86
86
  }
87
87
  async createFetchOptions(e) {
88
- const t = await R(e == null ? void 0 : e.headers);
88
+ const t = await O(e == null ? void 0 : e.headers);
89
89
  return t.has("X-API-KEY") || t.set("X-API-KEY", this.apiKey), { ...e, headers: t };
90
90
  }
91
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);
92
+ return o(e) ? new URL(e, this.baseUrl) : e instanceof URL ? new URL(e, this.baseUrl) : new URL(P({ ...e }, t), this.baseUrl);
93
93
  }
94
94
  async get(e, t = {}) {
95
95
  return await this.request(e, {
@@ -98,18 +98,18 @@ class j {
98
98
  });
99
99
  }
100
100
  static isAcmsFetchError(e) {
101
- return F(e);
101
+ return q(e);
102
102
  }
103
103
  getConfig() {
104
104
  return this.config;
105
105
  }
106
106
  }
107
- function x(...r) {
108
- return new j(...r);
107
+ function L(...r) {
108
+ return new $(...r);
109
109
  }
110
110
  export {
111
- b as acmsPath,
112
- x as createClient,
113
- F as isAcmsFetchError,
114
- N as parseAcmsPath
111
+ P as acmsPath,
112
+ L as createClient,
113
+ q as isAcmsFetchError,
114
+ D as parseAcmsPath
115
115
  };
@@ -1,5 +1,4 @@
1
- import { type AcmsPathParams } from '../lib/acmsPath';
2
- import { type AcmsClientOptions, type AcmsClientConfig, type AcmsResponse } from '../types';
1
+ import { type AcmsClientOptions, type AcmsClientConfig, type AcmsResponse, type URLComposable } from '../types';
3
2
  export default class AcmsClient {
4
3
  private readonly baseUrl;
5
4
  private readonly apiKey;
@@ -11,7 +10,7 @@ export default class AcmsClient {
11
10
  private request;
12
11
  private createFetchOptions;
13
12
  private createUrl;
14
- get<T = any>(acmsPathParamsOrUrl: AcmsPathParams | URL | string, options?: AcmsClientOptions): Promise<AcmsResponse<T>>;
13
+ get<T = any>(urlComposable: URLComposable, options?: AcmsClientOptions): Promise<AcmsResponse<T>>;
15
14
  static isAcmsFetchError(payload: any): boolean;
16
15
  getConfig(): AcmsClientConfig;
17
16
  }
@@ -1,4 +1,4 @@
1
- import { AcmsPathOptions } from '../lib/acmsPath';
1
+ import { AcmsPathOptions, acmsPath } from '../lib/acmsPath';
2
2
  export interface AcmsResponse<T> {
3
3
  data: T;
4
4
  status: number;
@@ -16,4 +16,5 @@ type RecursivePartial<T> = {
16
16
  };
17
17
  export interface AcmsClientOptions extends RecursivePartial<AcmsClientConfig> {
18
18
  }
19
+ export type URLComposable = Parameters<typeof acmsPath>[0] | URL | string;
19
20
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uidev1116/acms-js-sdk",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "a-blog cms JavaScript SDK",
5
5
  "type": "module",
6
6
  "files": [