@starasia/http 1.0.1 → 1.0.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.
package/dist/index.es.js CHANGED
@@ -1,4 +1,4 @@
1
- const y = (e) => {
1
+ const i = (e) => {
2
2
  switch (e) {
3
3
  case "url-encoded":
4
4
  return "application/x-www-form-urlencoded";
@@ -7,35 +7,37 @@ const y = (e) => {
7
7
  default:
8
8
  return;
9
9
  }
10
- }, i = (e, t, a) => {
10
+ }, p = (e, t, r) => {
11
11
  if (e !== "GET")
12
- return t === "form-data" ? a : JSON.stringify(a);
12
+ return t === "form-data" ? r : JSON.stringify(r);
13
13
  };
14
- function k(e) {
15
- const t = new URLSearchParams(e), a = {};
16
- for (const [r, n] of t)
17
- a[r] = n;
18
- return a;
14
+ function j(e) {
15
+ const t = new URLSearchParams(e), r = {};
16
+ for (const [n, a] of t)
17
+ r[n] = a;
18
+ return r;
19
19
  }
20
- function l(e) {
20
+ function y(e) {
21
21
  if (!e || typeof e != "object" || Array.isArray(e))
22
22
  return "";
23
23
  const t = new URLSearchParams();
24
- return Object.keys(e).forEach((a) => {
25
- const r = e[a];
26
- (typeof r == "string" || typeof r == "number") && t.append(a, r.toString());
24
+ return Object.keys(e).forEach((r) => {
25
+ const n = e[r];
26
+ n != null && (Array.isArray(n) ? n.forEach((a) => {
27
+ a != null && t.append(r, String(a));
28
+ }) : t.append(r, String(n)));
27
29
  }), t.toString();
28
30
  }
29
- function T(e, t, a) {
31
+ function d(e, t, r) {
30
32
  if (!e) return "";
31
- let r = t ? `${e}/${t}` : e;
32
- if (a) {
33
- const n = l(a);
34
- r = `${r}${n ? `?${n}` : ""}`;
33
+ let n = t ? `${e}/${t}` : e;
34
+ if (r) {
35
+ const a = y(r);
36
+ n = `${n}${a ? `?${a}` : ""}`;
35
37
  }
36
- return r;
38
+ return n;
37
39
  }
38
- async function p(e) {
40
+ async function l(e) {
39
41
  return typeof e == "function" ? await e() : e;
40
42
  }
41
43
  const h = {
@@ -44,24 +46,24 @@ const h = {
44
46
  withAppAuth: !0,
45
47
  responseContentType: "json"
46
48
  };
47
- async function w(e, t, a, r) {
48
- let n = { ...h, ...r };
49
- const s = y(n == null ? void 0 : n.contentType);
49
+ async function T(e, t, r, n) {
50
+ let a = { ...h, ...n };
51
+ const s = i(a == null ? void 0 : a.contentType);
50
52
  let o = {};
51
- s && (o["Content-Type"] = s), n.bearerToken && typeof n.bearerToken == "string" && (o.Authorization = `Bearer ${n.bearerToken}`), n.headers && (o = {
53
+ s && (o["Content-Type"] = s), a.bearerToken && typeof a.bearerToken == "string" && (o.Authorization = `Bearer ${a.bearerToken}`), a.headers && (o = {
52
54
  ...o,
53
- ...n.headers
55
+ ...a.headers
54
56
  });
55
57
  const c = await fetch(e, {
56
58
  method: t,
57
59
  headers: o,
58
- ...(n == null ? void 0 : n.signal) && { signal: n.signal },
59
- body: i(t, n.contentType, a)
60
+ ...(a == null ? void 0 : a.signal) && { signal: a.signal },
61
+ body: p(t, a.contentType, r)
60
62
  });
61
63
  let u;
62
64
  if (!c.ok)
63
65
  throw await c.json();
64
- switch (n.responseContentType) {
66
+ switch (a.responseContentType) {
65
67
  case "json":
66
68
  u = await c.json();
67
69
  break;
@@ -77,8 +79,8 @@ async function w(e, t, a, r) {
77
79
  }
78
80
  return u;
79
81
  }
80
- const f = async (e, t, a, r, n) => {
81
- const s = await p(n), o = await p(r), c = T(
82
+ const f = async (e, t, r, n, a) => {
83
+ const s = await l(a), o = await l(n), c = d(
82
84
  e,
83
85
  (o == null ? void 0 : o.path) || (s == null ? void 0 : s.path) || "",
84
86
  {
@@ -88,52 +90,52 @@ const f = async (e, t, a, r, n) => {
88
90
  ...o == null ? void 0 : o.params
89
91
  }
90
92
  ), u = { ...s, ...o };
91
- return w(c, t, a, u);
92
- }, d = (e, t) => (a) => f(
93
+ return T(c, t, r, u);
94
+ }, w = (e, t) => (r) => f(
93
95
  e,
94
96
  "GET",
95
97
  void 0,
96
- a,
98
+ r,
97
99
  t
98
- ), b = (e, t) => (a, r) => f(
100
+ ), b = (e, t) => (r, n) => f(
99
101
  e,
100
102
  "POST",
101
- a,
102
103
  r,
104
+ n,
103
105
  t
104
- ), m = (e, t) => (a, r) => f(
106
+ ), g = (e, t) => (r, n) => f(
105
107
  e,
106
108
  "PUT",
107
- a,
108
109
  r,
110
+ n,
109
111
  t
110
- ), g = (e, t) => (a, r) => f(
112
+ ), m = (e, t) => (r, n) => f(
111
113
  e,
112
114
  "PATCH",
113
- a,
114
115
  r,
116
+ n,
115
117
  t
116
- ), j = (e, t) => (a) => f(
118
+ ), v = (e, t) => (r) => f(
117
119
  e,
118
120
  "DELETE",
119
121
  void 0,
120
- a,
122
+ r,
121
123
  t
122
- ), P = {
123
- get: d,
124
+ ), A = {
125
+ get: w,
124
126
  post: b,
125
- put: m,
126
- patch: g,
127
- delete: j
127
+ put: g,
128
+ patch: m,
129
+ delete: v
128
130
  };
129
131
  export {
130
- T as createEndpoint,
132
+ d as createEndpoint,
131
133
  f as createRequest,
132
- i as getBody,
133
- y as getContentType,
134
- P as http,
135
- l as objectToSearchParams,
136
- w as request,
137
- p as resolveRequestOptions,
138
- k as searchParamsToObject
134
+ p as getBody,
135
+ i as getContentType,
136
+ A as http,
137
+ y as objectToSearchParams,
138
+ T as request,
139
+ l as resolveRequestOptions,
140
+ j as searchParamsToObject
139
141
  };
package/dist/index.umd.js CHANGED
@@ -1 +1 @@
1
- (function(s,i){typeof exports=="object"&&typeof module<"u"?i(exports):typeof define=="function"&&define.amd?define(["exports"],i):(s=typeof globalThis<"u"?globalThis:s||self,i(s["@starasia/http"]={}))})(this,function(s){"use strict";const i=e=>{switch(e){case"url-encoded":return"application/x-www-form-urlencoded";case"json":return"application/json";default:return}},y=(e,t,n)=>{if(e!=="GET")return t==="form-data"?n:JSON.stringify(n)};function b(e){const t=new URLSearchParams(e),n={};for(const[r,a]of t)n[r]=a;return n}function l(e){if(!e||typeof e!="object"||Array.isArray(e))return"";const t=new URLSearchParams;return Object.keys(e).forEach(n=>{const r=e[n];(typeof r=="string"||typeof r=="number")&&t.append(n,r.toString())}),t.toString()}function h(e,t,n){if(!e)return"";let r=t?`${e}/${t}`:e;if(n){const a=l(n);r=`${r}${a?`?${a}`:""}`}return r}async function p(e){return typeof e=="function"?await e():e}const m={contentType:"json",path:"",withAppAuth:!0,responseContentType:"json"};async function T(e,t,n,r){let a={...m,...r};const c=i(a==null?void 0:a.contentType);let o={};c&&(o["Content-Type"]=c),a.bearerToken&&typeof a.bearerToken=="string"&&(o.Authorization=`Bearer ${a.bearerToken}`),a.headers&&(o={...o,...a.headers});const u=await fetch(e,{method:t,headers:o,...(a==null?void 0:a.signal)&&{signal:a.signal},body:y(t,a.contentType,n)});let f;if(!u.ok)throw await u.json();switch(a.responseContentType){case"json":f=await u.json();break;case"text":f=await u.text();break;case"blob":f=await u.blob();break;default:f=await u.json();break}return f}const d=async(e,t,n,r,a)=>{const c=await p(a),o=await p(r),u=h(e,(o==null?void 0:o.path)||(c==null?void 0:c.path)||"",{...c==null?void 0:c.metaParams,...c==null?void 0:c.params,...o==null?void 0:o.metaParams,...o==null?void 0:o.params}),f={...c,...o};return T(u,t,n,f)},w={get:(e,t)=>n=>d(e,"GET",void 0,n,t),post:(e,t)=>(n,r)=>d(e,"POST",n,r,t),put:(e,t)=>(n,r)=>d(e,"PUT",n,r,t),patch:(e,t)=>(n,r)=>d(e,"PATCH",n,r,t),delete:(e,t)=>n=>d(e,"DELETE",void 0,n,t)};s.createEndpoint=h,s.createRequest=d,s.getBody=y,s.getContentType=i,s.http=w,s.objectToSearchParams=l,s.request=T,s.resolveRequestOptions=p,s.searchParamsToObject=b,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
1
+ (function(s,i){typeof exports=="object"&&typeof module<"u"?i(exports):typeof define=="function"&&define.amd?define(["exports"],i):(s=typeof globalThis<"u"?globalThis:s||self,i(s["@starasia/http"]={}))})(this,function(s){"use strict";const i=e=>{switch(e){case"url-encoded":return"application/x-www-form-urlencoded";case"json":return"application/json";default:return}},p=(e,t,n)=>{if(e!=="GET")return t==="form-data"?n:JSON.stringify(n)};function w(e){const t=new URLSearchParams(e),n={};for(const[r,a]of t)n[r]=a;return n}function h(e){if(!e||typeof e!="object"||Array.isArray(e))return"";const t=new URLSearchParams;return Object.keys(e).forEach(n=>{const r=e[n];r!=null&&(Array.isArray(r)?r.forEach(a=>{a!=null&&t.append(n,String(a))}):t.append(n,String(r)))}),t.toString()}function y(e,t,n){if(!e)return"";let r=t?`${e}/${t}`:e;if(n){const a=h(n);r=`${r}${a?`?${a}`:""}`}return r}async function l(e){return typeof e=="function"?await e():e}const b={contentType:"json",path:"",withAppAuth:!0,responseContentType:"json"};async function T(e,t,n,r){let a={...b,...r};const c=i(a==null?void 0:a.contentType);let o={};c&&(o["Content-Type"]=c),a.bearerToken&&typeof a.bearerToken=="string"&&(o.Authorization=`Bearer ${a.bearerToken}`),a.headers&&(o={...o,...a.headers});const u=await fetch(e,{method:t,headers:o,...(a==null?void 0:a.signal)&&{signal:a.signal},body:p(t,a.contentType,n)});let f;if(!u.ok)throw await u.json();switch(a.responseContentType){case"json":f=await u.json();break;case"text":f=await u.text();break;case"blob":f=await u.blob();break;default:f=await u.json();break}return f}const d=async(e,t,n,r,a)=>{const c=await l(a),o=await l(r),u=y(e,(o==null?void 0:o.path)||(c==null?void 0:c.path)||"",{...c==null?void 0:c.metaParams,...c==null?void 0:c.params,...o==null?void 0:o.metaParams,...o==null?void 0:o.params}),f={...c,...o};return T(u,t,n,f)},g={get:(e,t)=>n=>d(e,"GET",void 0,n,t),post:(e,t)=>(n,r)=>d(e,"POST",n,r,t),put:(e,t)=>(n,r)=>d(e,"PUT",n,r,t),patch:(e,t)=>(n,r)=>d(e,"PATCH",n,r,t),delete:(e,t)=>n=>d(e,"DELETE",void 0,n,t)};s.createEndpoint=y,s.createRequest=d,s.getBody=p,s.getContentType=i,s.http=g,s.objectToSearchParams=h,s.request=T,s.resolveRequestOptions=l,s.searchParamsToObject=w,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
@@ -1,5 +1,5 @@
1
1
  export type Method = "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
2
- export type ParamType = Record<string, string | number | undefined | null>;
2
+ export type ParamType = Record<string, string | number | boolean | null | undefined | Array<string | number | boolean | null>>;
3
3
  export interface MetaParams {
4
4
  page?: number;
5
5
  perPage?: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@starasia/http",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Client Http for starasia App",
5
5
  "author": "Prawito Hudoro",
6
6
  "main": "dist/index.umd.js",