@uidev1116/acms-js-sdk 0.1.0 → 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.
@@ -1,4 +1,4 @@
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?`
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
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 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;
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;
@@ -1,11 +1,11 @@
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";
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
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) {
7
+ import { A as q, i as F } from "../index-ZZQxXurp.js";
8
+ async function U(r) {
9
9
  try {
10
10
  const { message: e } = await r.json();
11
11
  return e ?? null;
@@ -13,25 +13,25 @@ async function F(r) {
13
13
  return null;
14
14
  }
15
15
  }
16
- async function U() {
16
+ async function I() {
17
17
  if (typeof fetch > "u") {
18
18
  const { default: r } = await import("../browser-ponyfill-EPWIFhDK.js").then((e) => e.b);
19
19
  return r;
20
20
  }
21
21
  return fetch;
22
22
  }
23
- async function I(...r) {
23
+ async function R(...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 R = {
30
+ const $ = {
31
31
  responseType: "json",
32
32
  acmsPathOptions: {}
33
33
  };
34
- class $ {
34
+ class j {
35
35
  constructor({
36
36
  baseUrl: e,
37
37
  apiKey: t,
@@ -49,23 +49,23 @@ class $ {
49
49
  if (!a(t))
50
50
  throw new Error("apiKey must be string.");
51
51
  this.baseUrl = e, this.apiKey = t, this.config = {
52
- ...R,
52
+ ...$,
53
53
  ...o
54
54
  };
55
55
  }
56
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);
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);
58
58
  try {
59
- const s = await p(m, l), { ok: d, status: i, statusText: c, headers: g } = s, u = {
59
+ const s = await m(l, d), { ok: g, status: i, statusText: c, headers: E } = s, u = {
60
60
  data: await s[w](),
61
61
  status: i,
62
62
  statusText: c,
63
- headers: g
63
+ headers: E
64
64
  };
65
- if (!d) {
66
- const f = await F(s);
65
+ if (!g) {
66
+ const f = await U(s);
67
67
  return await Promise.reject(
68
- new b(
68
+ new q(
69
69
  `fetch API response status: ${i}${f != null ? `
70
70
  message is \`${f}\`` : ""}`,
71
71
  `${i} ${c}`,
@@ -85,14 +85,11 @@ class $ {
85
85
  }
86
86
  }
87
87
  async createFetchOptions(e) {
88
- const t = await I(e == null ? void 0 : e.headers);
88
+ const t = await R(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
- createUrl(e) {
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
+ 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);
96
93
  }
97
94
  async get(e, t = {}) {
98
95
  return await this.request(e, {
@@ -101,18 +98,18 @@ class $ {
101
98
  });
102
99
  }
103
100
  static isAcmsFetchError(e) {
104
- return q(e);
101
+ return F(e);
105
102
  }
106
103
  getConfig() {
107
104
  return this.config;
108
105
  }
109
106
  }
110
- function T(...r) {
111
- return new $(...r);
107
+ function x(...r) {
108
+ return new j(...r);
112
109
  }
113
110
  export {
114
- A as acmsPath,
115
- T as createClient,
116
- q as isAcmsFetchError,
117
- D as parseAcmsPath
111
+ b as acmsPath,
112
+ x as createClient,
113
+ F as isAcmsFetchError,
114
+ N as parseAcmsPath
118
115
  };
@@ -11,7 +11,7 @@ export default class AcmsClient {
11
11
  private request;
12
12
  private createFetchOptions;
13
13
  private createUrl;
14
- get<T = any>(acmsPathParamsOrUrl: AcmsPathParams | URL | string, options?: Partial<AcmsClientConfig>): Promise<AcmsResponse<T>>;
14
+ get<T = any>(acmsPathParamsOrUrl: AcmsPathParams | URL | string, options?: AcmsClientOptions): Promise<AcmsResponse<T>>;
15
15
  static isAcmsFetchError(payload: any): boolean;
16
16
  getConfig(): AcmsClientConfig;
17
17
  }
@@ -1,2 +1,16 @@
1
- import { type AcmsPathSegments } from './types';
2
- export declare const defaultAcmsPathSegments: AcmsPathSegments;
1
+ export declare const defaultAcmsPathSegments: {
2
+ readonly bid: "bid";
3
+ readonly cid: "cid";
4
+ readonly eid: "eid";
5
+ readonly uid: "uid";
6
+ readonly tag: "tag";
7
+ readonly field: "field";
8
+ readonly span: "-";
9
+ readonly page: "page";
10
+ readonly order: "order";
11
+ readonly limit: "limit";
12
+ readonly keyword: "keyword";
13
+ readonly admin: "admin";
14
+ readonly tpl: "tpl";
15
+ readonly api: "api";
16
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uidev1116/acms-js-sdk",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "a-blog cms JavaScript SDK",
5
5
  "type": "module",
6
6
  "files": [