@rabstack/rab-react-sdk
Advanced tools
| function C(...t) { | ||
| if (t.length === 0) return ""; | ||
| let r = [...t].filter(Boolean); | ||
| const o = r[r.length - 1]; | ||
| if (typeof o == "object" && o !== null) { | ||
| const s = o; | ||
| r = r.slice(0, -1).map((e) => { | ||
| if (typeof e == "string") { | ||
| let a = e; | ||
| for (const n in s) | ||
| a = a.replace(`:${n}`, String(s[n])); | ||
| return a; | ||
| } | ||
| return e; | ||
| }); | ||
| } | ||
| return r.filter( | ||
| (s) => typeof s == "string" && s.trim() !== "" | ||
| ).map( | ||
| (s, e) => s.startsWith("/") || e === 0 ? s : "/" + s | ||
| ).join(""); | ||
| } | ||
| function $(t) { | ||
| const { endpointUrl: r, baseUrl: o, params: s, appendTrailingSlash: e, method: a } = t, n = C(r, s), c = o.replace(/\/$/, ""); | ||
| let i = n.startsWith("/") ? n : "/" + n; | ||
| return e && a && ["POST", "PUT", "PATCH"].includes(a) && !i.endsWith("/") && (i = i + "/"), new URL(c + i); | ||
| } | ||
| function k(t, r, o, s) { | ||
| if (o && s !== !1) { | ||
| const e = o(r); | ||
| if (e) { | ||
| const a = e.split("&"); | ||
| for (const n of a) { | ||
| const [c, i] = n.split("="); | ||
| c && i !== void 0 && t.searchParams.append(decodeURIComponent(c), decodeURIComponent(i)); | ||
| } | ||
| } | ||
| } else | ||
| Object.entries(r).forEach(([e, a]) => { | ||
| a != null && t.searchParams.append(e, String(a)); | ||
| }); | ||
| } | ||
| function x(t, r, o) { | ||
| if (!!(r && t)) { | ||
| if (t instanceof FormData) | ||
| return { processedBody: t, isFormDataRequest: !0 }; | ||
| if (o) | ||
| return { processedBody: o(t), isFormDataRequest: !0 }; | ||
| throw new Error("useFormData requires formDataParser in config or body to be FormData instance"); | ||
| } | ||
| return { | ||
| processedBody: t ? JSON.stringify(t) : void 0, | ||
| isFormDataRequest: !1 | ||
| }; | ||
| } | ||
| class m extends Error { | ||
| constructor(r) { | ||
| console.error(`API Error ${r.status}: ${r.message} [${r.method} ${r.url}]`), super(r.message), this.name = "ApiDomainError", this.status = r.status, this.url = r.url, this.method = r.method, this.errorCode = r.errorCode, this.errors = r.errors, this.data = r.data, Error.captureStackTrace && Error.captureStackTrace(this, m); | ||
| } | ||
| isNetworkError() { | ||
| return this.status === 0; | ||
| } | ||
| isClientError() { | ||
| return this.status >= 400 && this.status < 500; | ||
| } | ||
| isServerError() { | ||
| return this.status >= 500; | ||
| } | ||
| isUnauthorized() { | ||
| return this.status === 401; | ||
| } | ||
| isForbidden() { | ||
| return this.status === 403; | ||
| } | ||
| isNotFound() { | ||
| return this.status === 404; | ||
| } | ||
| isValidationError() { | ||
| return this.status === 422 || this.status === 400; | ||
| } | ||
| isConflict() { | ||
| return this.status === 409; | ||
| } | ||
| getAllMessages() { | ||
| const r = [this.message]; | ||
| return this.errors && this.errors.length > 0 && r.push(...this.errors), r; | ||
| } | ||
| getDisplayMessage() { | ||
| return this.errors && this.errors.length > 0 ? `${this.message}: ${this.errors.join(", ")}` : this.message; | ||
| } | ||
| } | ||
| function B(t, r, o, s, e) { | ||
| return { | ||
| status: t, | ||
| url: o, | ||
| method: s, | ||
| message: e?.message || r, | ||
| errorCode: e?.errorCode, | ||
| errors: e?.errors, | ||
| data: e | ||
| }; | ||
| } | ||
| function z(t) { | ||
| return typeof t == "object" && t !== null && "data" in t ? t.data : t; | ||
| } | ||
| function O(t) { | ||
| const { | ||
| baseUrl: r, | ||
| getAuthorization: o, | ||
| extractApiError: s = B, | ||
| parseQuery: e, | ||
| transformResponse: a = z, | ||
| onError: n, | ||
| appendTrailingSlash: c, | ||
| formDataParser: i, | ||
| customFetch: g | ||
| } = t; | ||
| return async (h, y) => { | ||
| try { | ||
| const { body: u, query: f, params: p, encodeQuery: E, headers: P, useFormData: b, ...q } = y ?? {}, D = $({ | ||
| endpointUrl: h.url, | ||
| baseUrl: r, | ||
| params: p ?? {}, | ||
| appendTrailingSlash: c, | ||
| method: h.method | ||
| }); | ||
| f && k(D, f, e, E); | ||
| const { processedBody: j, isFormDataRequest: T } = x(u, b, i), F = { | ||
| ...T ? {} : { "Content-Type": "application/json" }, | ||
| ...P | ||
| }, R = o?.(); | ||
| R && Object.assign(F, R); | ||
| const d = { | ||
| url: D.toString(), | ||
| method: h.method, | ||
| headers: F, | ||
| body: j, | ||
| ...q | ||
| }, l = g ? await g(d) : await fetch(d.url, { | ||
| method: d.method, | ||
| headers: d.headers, | ||
| body: d.body | ||
| }); | ||
| if (!l.ok) { | ||
| let w; | ||
| try { | ||
| w = await l.clone().json(); | ||
| } catch { | ||
| w = await l.text(); | ||
| } | ||
| const A = s(l.status, l.statusText, D.toString(), h.method, w), S = new m(A); | ||
| throw n?.(S), S; | ||
| } | ||
| const U = await l.json(); | ||
| return a(U, l); | ||
| } catch (u) { | ||
| if (u instanceof m) | ||
| throw u; | ||
| const f = { | ||
| status: 0, | ||
| url: `${r}${h.url}`, | ||
| method: h.method, | ||
| message: u instanceof Error ? u.message : "Network request failed", | ||
| data: u | ||
| }, p = new m(f); | ||
| throw n?.(p), p; | ||
| } | ||
| }; | ||
| } | ||
| function I(t) { | ||
| const { apiSpecs: r, baseUrl: o, getAuthorization: s, extractApiError: e, parseQuery: a, transformResponse: n, onError: c, appendTrailingSlash: i, formDataParser: g, customFetch: h } = t, y = O({ | ||
| baseUrl: o, | ||
| getAuthorization: s, | ||
| extractApiError: e, | ||
| parseQuery: a, | ||
| transformResponse: n, | ||
| onError: c, | ||
| appendTrailingSlash: i, | ||
| formDataParser: g, | ||
| customFetch: h | ||
| }), u = {}; | ||
| for (const [f, p] of Object.entries(r)) | ||
| u[f] = ((E) => y(p, E)); | ||
| return u; | ||
| } | ||
| export { | ||
| m as A, | ||
| O as a, | ||
| B as b, | ||
| I as c, | ||
| z as d, | ||
| C as e | ||
| }; |
| "use strict";function P(...t){if(t.length===0)return"";let r=[...t].filter(Boolean);const o=r[r.length-1];if(typeof o=="object"&&o!==null){const s=o;r=r.slice(0,-1).map(e=>{if(typeof e=="string"){let a=e;for(const n in s)a=a.replace(`:${n}`,String(s[n]));return a}return e})}return r.filter(s=>typeof s=="string"&&s.trim()!=="").map((s,e)=>s.startsWith("/")||e===0?s:"/"+s).join("")}function B(t){const{endpointUrl:r,baseUrl:o,params:s,appendTrailingSlash:e,method:a}=t,n=P(r,s),c=o.replace(/\/$/,"");let i=n.startsWith("/")?n:"/"+n;return e&&a&&["POST","PUT","PATCH"].includes(a)&&!i.endsWith("/")&&(i=i+"/"),new URL(c+i)}function z(t,r,o,s){if(o&&s!==!1){const e=o(r);if(e){const a=e.split("&");for(const n of a){const[c,i]=n.split("=");c&&i!==void 0&&t.searchParams.append(decodeURIComponent(c),decodeURIComponent(i))}}}else Object.entries(r).forEach(([e,a])=>{a!=null&&t.searchParams.append(e,String(a))})}function O(t,r,o){if(!!(r&&t)){if(t instanceof FormData)return{processedBody:t,isFormDataRequest:!0};if(o)return{processedBody:o(t),isFormDataRequest:!0};throw new Error("useFormData requires formDataParser in config or body to be FormData instance")}return{processedBody:t?JSON.stringify(t):void 0,isFormDataRequest:!1}}class d extends Error{constructor(r){console.error(`API Error ${r.status}: ${r.message} [${r.method} ${r.url}]`),super(r.message),this.name="ApiDomainError",this.status=r.status,this.url=r.url,this.method=r.method,this.errorCode=r.errorCode,this.errors=r.errors,this.data=r.data,Error.captureStackTrace&&Error.captureStackTrace(this,d)}isNetworkError(){return this.status===0}isClientError(){return this.status>=400&&this.status<500}isServerError(){return this.status>=500}isUnauthorized(){return this.status===401}isForbidden(){return this.status===403}isNotFound(){return this.status===404}isValidationError(){return this.status===422||this.status===400}isConflict(){return this.status===409}getAllMessages(){const r=[this.message];return this.errors&&this.errors.length>0&&r.push(...this.errors),r}getDisplayMessage(){return this.errors&&this.errors.length>0?`${this.message}: ${this.errors.join(", ")}`:this.message}}function q(t,r,o,s,e){return{status:t,url:o,method:s,message:e?.message||r,errorCode:e?.errorCode,errors:e?.errors,data:e}}function b(t){return typeof t=="object"&&t!==null&&"data"in t?t.data:t}function T(t){const{baseUrl:r,getAuthorization:o,extractApiError:s=q,parseQuery:e,transformResponse:a=b,onError:n,appendTrailingSlash:c,formDataParser:i,customFetch:g}=t;return async(h,y)=>{try{const{body:u,query:f,params:p,encodeQuery:E,headers:U,useFormData:j,...A}=y??{},D=B({endpointUrl:h.url,baseUrl:r,params:p??{},appendTrailingSlash:c,method:h.method});f&&z(D,f,e,E);const{processedBody:C,isFormDataRequest:$}=O(u,j,i),F={...$?{}:{"Content-Type":"application/json"},...U},S=o?.();S&&Object.assign(F,S);const m={url:D.toString(),method:h.method,headers:F,body:C,...A},l=g?await g(m):await fetch(m.url,{method:m.method,headers:m.headers,body:m.body});if(!l.ok){let R;try{R=await l.clone().json()}catch{R=await l.text()}const x=s(l.status,l.statusText,D.toString(),h.method,R),w=new d(x);throw n?.(w),w}const k=await l.json();return a(k,l)}catch(u){if(u instanceof d)throw u;const f={status:0,url:`${r}${h.url}`,method:h.method,message:u instanceof Error?u.message:"Network request failed",data:u},p=new d(f);throw n?.(p),p}}}function I(t){const{apiSpecs:r,baseUrl:o,getAuthorization:s,extractApiError:e,parseQuery:a,transformResponse:n,onError:c,appendTrailingSlash:i,formDataParser:g,customFetch:h}=t,y=T({baseUrl:o,getAuthorization:s,extractApiError:e,parseQuery:a,transformResponse:n,onError:c,appendTrailingSlash:i,formDataParser:g,customFetch:h}),u={};for(const[f,p]of Object.entries(r))u[f]=(E=>y(p,E));return u}exports.ApiDomainError=d;exports.buildUrlPath=P;exports.createRequestFunction=T;exports.createSDK=I;exports.defaultExtractApiError=q;exports.defaultTransformResponse=b; |
+1
-1
@@ -1,1 +0,1 @@ | ||
| "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const P=require("react/jsx-runtime"),S=require("react"),D=require("@tanstack/react-query"),c=require("./createSDK-DH-GKtYY.cjs"),y=require("@rabstack/rab-api-spec");function f(){const t=S.createContext(null);function d({children:e,sdk:s,baseUrl:a}){return P.jsx(t.Provider,{value:{sdk:s,baseUrl:a},children:e})}function n(){const e=S.useContext(t);if(!e)throw new Error("useSDK must be used within SDKProvider");return e.sdk}return{SDKContext:t,SDKProvider:d,useSDK:n}}function m(t){return function(n,...e){const s=t(),a=e[0],{query:u,queryKey:o,params:r,headers:i,encodeQuery:l,...p}=a||{},K=[n,u,r];return D.useQuery({queryKey:o?[...K,...o]:K,queryFn:async()=>{const b=s[n];return b({query:u,params:r,headers:i,encodeQuery:l})},...p})}}function A(t){return function(n,e){const s=t(),a=D.useQueryClient(),{invalidateQueries:u,...o}=e||{};return D.useMutation({mutationFn:async r=>{const i=s[n];return i(r)},onSettled:async(...r)=>{o.onSettled&&await o.onSettled(...r),u&&u.length>0&&await Promise.all(u.map(i=>a.invalidateQueries({queryKey:[i]})))},...o})}}function q(t){const{SDKContext:d,SDKProvider:n,useSDK:e}=f();function s({children:o,baseUrl:r,getAuthorization:i,onError:l}){const p=S.useMemo(()=>c.createSDK({...t,baseUrl:r,getAuthorization:i||t.getAuthorization,onError:l||t.onError}),[r,i,l]);return P.jsx(n,{sdk:p,baseUrl:r,children:o})}const a=m(e),u=A(e);return{SDKContext:d,SDKProvider:s,useSDK:e,useQuery:a,useMutation:u}}exports.ApiDomainError=c.ApiDomainError;exports.buildUrlPath=c.buildUrlPath;exports.createRequestFunction=c.createRequestFunction;exports.createSDK=c.createSDK;exports.defaultExtractApiError=c.defaultExtractApiError;exports.defaultTransformResponse=c.defaultTransformResponse;Object.defineProperty(exports,"DeleteApi",{enumerable:!0,get:()=>y.DeleteApi});Object.defineProperty(exports,"GetApi",{enumerable:!0,get:()=>y.GetApi});Object.defineProperty(exports,"PatchApi",{enumerable:!0,get:()=>y.PatchApi});Object.defineProperty(exports,"PostApi",{enumerable:!0,get:()=>y.PostApi});Object.defineProperty(exports,"PutApi",{enumerable:!0,get:()=>y.PutApi});exports.createSDKContext=f;exports.createSDKProvider=q;exports.createUseMutation=A;exports.createUseQuery=m; | ||
| "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const P=require("react/jsx-runtime"),S=require("react"),D=require("@tanstack/react-query"),c=require("./createSDK-D_Zi7md0.cjs"),y=require("@rabstack/rab-api-spec");function f(){const t=S.createContext(null);function d({children:e,sdk:s,baseUrl:a}){return P.jsx(t.Provider,{value:{sdk:s,baseUrl:a},children:e})}function n(){const e=S.useContext(t);if(!e)throw new Error("useSDK must be used within SDKProvider");return e.sdk}return{SDKContext:t,SDKProvider:d,useSDK:n}}function m(t){return function(n,...e){const s=t(),a=e[0],{query:u,queryKey:o,params:r,headers:i,encodeQuery:l,...p}=a||{},K=[n,u,r];return D.useQuery({queryKey:o?[...K,...o]:K,queryFn:async()=>{const b=s[n];return b({query:u,params:r,headers:i,encodeQuery:l})},...p})}}function A(t){return function(n,e){const s=t(),a=D.useQueryClient(),{invalidateQueries:u,...o}=e||{};return D.useMutation({mutationFn:async r=>{const i=s[n];return i(r)},onSettled:async(...r)=>{o.onSettled&&await o.onSettled(...r),u&&u.length>0&&await Promise.all(u.map(i=>a.invalidateQueries({queryKey:[i]})))},...o})}}function q(t){const{SDKContext:d,SDKProvider:n,useSDK:e}=f();function s({children:o,baseUrl:r,getAuthorization:i,onError:l}){const p=S.useMemo(()=>c.createSDK({...t,baseUrl:r,getAuthorization:i||t.getAuthorization,onError:l||t.onError}),[r,i,l]);return P.jsx(n,{sdk:p,baseUrl:r,children:o})}const a=m(e),u=A(e);return{SDKContext:d,SDKProvider:s,useSDK:e,useQuery:a,useMutation:u}}exports.ApiDomainError=c.ApiDomainError;exports.buildUrlPath=c.buildUrlPath;exports.createRequestFunction=c.createRequestFunction;exports.createSDK=c.createSDK;exports.defaultExtractApiError=c.defaultExtractApiError;exports.defaultTransformResponse=c.defaultTransformResponse;Object.defineProperty(exports,"DeleteApi",{enumerable:!0,get:()=>y.DeleteApi});Object.defineProperty(exports,"GetApi",{enumerable:!0,get:()=>y.GetApi});Object.defineProperty(exports,"PatchApi",{enumerable:!0,get:()=>y.PatchApi});Object.defineProperty(exports,"PostApi",{enumerable:!0,get:()=>y.PostApi});Object.defineProperty(exports,"PutApi",{enumerable:!0,get:()=>y.PutApi});exports.createSDKContext=f;exports.createSDKProvider=q;exports.createUseMutation=A;exports.createUseQuery=m; |
+2
-2
| import { jsx as f } from "react/jsx-runtime"; | ||
| import { createContext as K, useContext as S, useMemo as D } from "react"; | ||
| import { useQuery as l, useQueryClient as P, useMutation as x } from "@tanstack/react-query"; | ||
| import { c as Q } from "./createSDK-BykB15KZ.js"; | ||
| import { A as b, e as O, a as R, b as j, d as z } from "./createSDK-BykB15KZ.js"; | ||
| import { c as Q } from "./createSDK-CJs3GKAr.js"; | ||
| import { A as b, e as O, a as R, b as j, d as z } from "./createSDK-CJs3GKAr.js"; | ||
| import { DeleteApi as G, GetApi as T, PatchApi as U, PostApi as g, PutApi as H } from "@rabstack/rab-api-spec"; | ||
@@ -7,0 +7,0 @@ function v() { |
+1
-1
| { | ||
| "name": "@rabstack/rab-react-sdk", | ||
| "version": "0.8.0", | ||
| "version": "0.8.1", | ||
| "description": "React SDK for building applications with React Query and other utilities", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
+1
-1
@@ -1,1 +0,1 @@ | ||
| "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./createSDK-DH-GKtYY.cjs"),t=require("@rabstack/rab-api-spec");exports.ApiDomainError=e.ApiDomainError;exports.buildUrlPath=e.buildUrlPath;exports.createRequestFunction=e.createRequestFunction;exports.createSDK=e.createSDK;exports.defaultExtractApiError=e.defaultExtractApiError;exports.defaultTransformResponse=e.defaultTransformResponse;Object.defineProperty(exports,"DeleteApi",{enumerable:!0,get:()=>t.DeleteApi});Object.defineProperty(exports,"GetApi",{enumerable:!0,get:()=>t.GetApi});Object.defineProperty(exports,"PatchApi",{enumerable:!0,get:()=>t.PatchApi});Object.defineProperty(exports,"PostApi",{enumerable:!0,get:()=>t.PostApi});Object.defineProperty(exports,"PutApi",{enumerable:!0,get:()=>t.PutApi}); | ||
| "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./createSDK-D_Zi7md0.cjs"),t=require("@rabstack/rab-api-spec");exports.ApiDomainError=e.ApiDomainError;exports.buildUrlPath=e.buildUrlPath;exports.createRequestFunction=e.createRequestFunction;exports.createSDK=e.createSDK;exports.defaultExtractApiError=e.defaultExtractApiError;exports.defaultTransformResponse=e.defaultTransformResponse;Object.defineProperty(exports,"DeleteApi",{enumerable:!0,get:()=>t.DeleteApi});Object.defineProperty(exports,"GetApi",{enumerable:!0,get:()=>t.GetApi});Object.defineProperty(exports,"PatchApi",{enumerable:!0,get:()=>t.PatchApi});Object.defineProperty(exports,"PostApi",{enumerable:!0,get:()=>t.PostApi});Object.defineProperty(exports,"PutApi",{enumerable:!0,get:()=>t.PutApi}); |
+1
-1
@@ -1,2 +0,2 @@ | ||
| import { A as r, e as t, a as o, c as s, b as i, d as p } from "./createSDK-BykB15KZ.js"; | ||
| import { A as r, e as t, a as o, c as s, b as i, d as p } from "./createSDK-CJs3GKAr.js"; | ||
| import { DeleteApi as c, GetApi as u, PatchApi as f, PostApi as l, PutApi as n } from "@rabstack/rab-api-spec"; | ||
@@ -3,0 +3,0 @@ export { |
| function C(...t) { | ||
| if (t.length === 0) return ""; | ||
| let r = [...t].filter(Boolean); | ||
| const o = r[r.length - 1]; | ||
| if (typeof o == "object" && o !== null) { | ||
| const s = o; | ||
| r = r.slice(0, -1).map((e) => { | ||
| if (typeof e == "string") { | ||
| let a = e; | ||
| for (const n in s) | ||
| a = a.replace(`:${n}`, String(s[n])); | ||
| return a; | ||
| } | ||
| return e; | ||
| }); | ||
| } | ||
| return r.filter( | ||
| (s) => typeof s == "string" && s.trim() !== "" | ||
| ).map( | ||
| (s, e) => s.startsWith("/") || e === 0 ? s : "/" + s | ||
| ).join(""); | ||
| } | ||
| function $(t) { | ||
| const { endpointUrl: r, baseUrl: o, params: s, appendTrailingSlash: e, method: a } = t, n = C(r, s), c = o.replace(/\/$/, ""); | ||
| let i = n.startsWith("/") ? n : "/" + n; | ||
| return e && a && ["POST", "PUT", "PATCH"].includes(a) && !i.endsWith("/") && (i = i + "/"), new URL(c + i); | ||
| } | ||
| function k(t, r, o, s) { | ||
| if (o && s !== !1) { | ||
| const e = o(r); | ||
| if (e) { | ||
| const a = e.split("&"); | ||
| for (const n of a) { | ||
| const [c, i] = n.split("="); | ||
| c && i !== void 0 && t.searchParams.append(decodeURIComponent(c), decodeURIComponent(i)); | ||
| } | ||
| } | ||
| } else | ||
| Object.entries(r).forEach(([e, a]) => { | ||
| a != null && t.searchParams.append(e, String(a)); | ||
| }); | ||
| } | ||
| function x(t, r, o) { | ||
| if (!!(r && t)) { | ||
| if (t instanceof FormData) | ||
| return { processedBody: t, isFormDataRequest: !0 }; | ||
| if (o) | ||
| return { processedBody: o(t), isFormDataRequest: !0 }; | ||
| throw new Error("useFormData requires formDataParser in config or body to be FormData instance"); | ||
| } | ||
| return { | ||
| processedBody: t ? JSON.stringify(t) : void 0, | ||
| isFormDataRequest: !1 | ||
| }; | ||
| } | ||
| class d extends Error { | ||
| constructor(r) { | ||
| console.error(`API Error ${r.status}: ${r.message} [${r.method} ${r.url}]`), super(r.message), this.name = "ApiDomainError", this.status = r.status, this.url = r.url, this.method = r.method, this.errorCode = r.errorCode, this.errors = r.errors, this.data = r.data, Error.captureStackTrace && Error.captureStackTrace(this, d); | ||
| } | ||
| isNetworkError() { | ||
| return this.status === 0; | ||
| } | ||
| isClientError() { | ||
| return this.status >= 400 && this.status < 500; | ||
| } | ||
| isServerError() { | ||
| return this.status >= 500; | ||
| } | ||
| isUnauthorized() { | ||
| return this.status === 401; | ||
| } | ||
| isForbidden() { | ||
| return this.status === 403; | ||
| } | ||
| isNotFound() { | ||
| return this.status === 404; | ||
| } | ||
| isValidationError() { | ||
| return this.status === 422 || this.status === 400; | ||
| } | ||
| isConflict() { | ||
| return this.status === 409; | ||
| } | ||
| getAllMessages() { | ||
| const r = [this.message]; | ||
| return this.errors && this.errors.length > 0 && r.push(...this.errors), r; | ||
| } | ||
| getDisplayMessage() { | ||
| return this.errors && this.errors.length > 0 ? `${this.message}: ${this.errors.join(", ")}` : this.message; | ||
| } | ||
| } | ||
| function B(t, r, o, s, e) { | ||
| return { | ||
| status: t, | ||
| url: o, | ||
| method: s, | ||
| message: e?.message || r, | ||
| errorCode: e?.errorCode, | ||
| errors: e?.errors, | ||
| data: e | ||
| }; | ||
| } | ||
| function z(t) { | ||
| return typeof t == "object" && t !== null && "data" in t ? t.data : t; | ||
| } | ||
| function O(t) { | ||
| const { | ||
| baseUrl: r, | ||
| getAuthorization: o, | ||
| extractApiError: s = B, | ||
| parseQuery: e, | ||
| transformResponse: a = z, | ||
| onError: n, | ||
| appendTrailingSlash: c, | ||
| formDataParser: i, | ||
| customFetch: g | ||
| } = t; | ||
| return async (h, y) => { | ||
| try { | ||
| const { body: u, query: f, params: m, encodeQuery: E, headers: P, useFormData: b, ...q } = y ?? {}, D = $({ | ||
| endpointUrl: h.url, | ||
| baseUrl: r, | ||
| params: m ?? {}, | ||
| appendTrailingSlash: c, | ||
| method: h.method | ||
| }); | ||
| f && k(D, f, e, E); | ||
| const { processedBody: j, isFormDataRequest: T } = x(u, b, i), F = { | ||
| "Content-Type": T ? "multipart/form-data" : "application/json", | ||
| ...P | ||
| }, R = o?.(); | ||
| R && Object.assign(F, R); | ||
| const p = { | ||
| url: D.toString(), | ||
| method: h.method, | ||
| headers: F, | ||
| body: j, | ||
| ...q | ||
| }, l = g ? await g(p) : await fetch(p.url, { | ||
| method: p.method, | ||
| headers: p.headers, | ||
| body: p.body | ||
| }); | ||
| if (!l.ok) { | ||
| let w; | ||
| try { | ||
| w = await l.clone().json(); | ||
| } catch { | ||
| w = await l.text(); | ||
| } | ||
| const A = s(l.status, l.statusText, D.toString(), h.method, w), S = new d(A); | ||
| throw n?.(S), S; | ||
| } | ||
| const U = await l.json(); | ||
| return a(U, l); | ||
| } catch (u) { | ||
| if (u instanceof d) | ||
| throw u; | ||
| const f = { | ||
| status: 0, | ||
| url: `${r}${h.url}`, | ||
| method: h.method, | ||
| message: u instanceof Error ? u.message : "Network request failed", | ||
| data: u | ||
| }, m = new d(f); | ||
| throw n?.(m), m; | ||
| } | ||
| }; | ||
| } | ||
| function I(t) { | ||
| const { apiSpecs: r, baseUrl: o, getAuthorization: s, extractApiError: e, parseQuery: a, transformResponse: n, onError: c, appendTrailingSlash: i, formDataParser: g, customFetch: h } = t, y = O({ | ||
| baseUrl: o, | ||
| getAuthorization: s, | ||
| extractApiError: e, | ||
| parseQuery: a, | ||
| transformResponse: n, | ||
| onError: c, | ||
| appendTrailingSlash: i, | ||
| formDataParser: g, | ||
| customFetch: h | ||
| }), u = {}; | ||
| for (const [f, m] of Object.entries(r)) | ||
| u[f] = ((E) => y(m, E)); | ||
| return u; | ||
| } | ||
| export { | ||
| d as A, | ||
| O as a, | ||
| B as b, | ||
| I as c, | ||
| z as d, | ||
| C as e | ||
| }; |
| "use strict";function P(...t){if(t.length===0)return"";let r=[...t].filter(Boolean);const o=r[r.length-1];if(typeof o=="object"&&o!==null){const s=o;r=r.slice(0,-1).map(e=>{if(typeof e=="string"){let a=e;for(const n in s)a=a.replace(`:${n}`,String(s[n]));return a}return e})}return r.filter(s=>typeof s=="string"&&s.trim()!=="").map((s,e)=>s.startsWith("/")||e===0?s:"/"+s).join("")}function B(t){const{endpointUrl:r,baseUrl:o,params:s,appendTrailingSlash:e,method:a}=t,n=P(r,s),c=o.replace(/\/$/,"");let i=n.startsWith("/")?n:"/"+n;return e&&a&&["POST","PUT","PATCH"].includes(a)&&!i.endsWith("/")&&(i=i+"/"),new URL(c+i)}function z(t,r,o,s){if(o&&s!==!1){const e=o(r);if(e){const a=e.split("&");for(const n of a){const[c,i]=n.split("=");c&&i!==void 0&&t.searchParams.append(decodeURIComponent(c),decodeURIComponent(i))}}}else Object.entries(r).forEach(([e,a])=>{a!=null&&t.searchParams.append(e,String(a))})}function O(t,r,o){if(!!(r&&t)){if(t instanceof FormData)return{processedBody:t,isFormDataRequest:!0};if(o)return{processedBody:o(t),isFormDataRequest:!0};throw new Error("useFormData requires formDataParser in config or body to be FormData instance")}return{processedBody:t?JSON.stringify(t):void 0,isFormDataRequest:!1}}class p extends Error{constructor(r){console.error(`API Error ${r.status}: ${r.message} [${r.method} ${r.url}]`),super(r.message),this.name="ApiDomainError",this.status=r.status,this.url=r.url,this.method=r.method,this.errorCode=r.errorCode,this.errors=r.errors,this.data=r.data,Error.captureStackTrace&&Error.captureStackTrace(this,p)}isNetworkError(){return this.status===0}isClientError(){return this.status>=400&&this.status<500}isServerError(){return this.status>=500}isUnauthorized(){return this.status===401}isForbidden(){return this.status===403}isNotFound(){return this.status===404}isValidationError(){return this.status===422||this.status===400}isConflict(){return this.status===409}getAllMessages(){const r=[this.message];return this.errors&&this.errors.length>0&&r.push(...this.errors),r}getDisplayMessage(){return this.errors&&this.errors.length>0?`${this.message}: ${this.errors.join(", ")}`:this.message}}function q(t,r,o,s,e){return{status:t,url:o,method:s,message:e?.message||r,errorCode:e?.errorCode,errors:e?.errors,data:e}}function b(t){return typeof t=="object"&&t!==null&&"data"in t?t.data:t}function T(t){const{baseUrl:r,getAuthorization:o,extractApiError:s=q,parseQuery:e,transformResponse:a=b,onError:n,appendTrailingSlash:c,formDataParser:i,customFetch:g}=t;return async(h,y)=>{try{const{body:u,query:f,params:m,encodeQuery:E,headers:U,useFormData:j,...A}=y??{},D=B({endpointUrl:h.url,baseUrl:r,params:m??{},appendTrailingSlash:c,method:h.method});f&&z(D,f,e,E);const{processedBody:C,isFormDataRequest:$}=O(u,j,i),F={"Content-Type":$?"multipart/form-data":"application/json",...U},S=o?.();S&&Object.assign(F,S);const d={url:D.toString(),method:h.method,headers:F,body:C,...A},l=g?await g(d):await fetch(d.url,{method:d.method,headers:d.headers,body:d.body});if(!l.ok){let R;try{R=await l.clone().json()}catch{R=await l.text()}const x=s(l.status,l.statusText,D.toString(),h.method,R),w=new p(x);throw n?.(w),w}const k=await l.json();return a(k,l)}catch(u){if(u instanceof p)throw u;const f={status:0,url:`${r}${h.url}`,method:h.method,message:u instanceof Error?u.message:"Network request failed",data:u},m=new p(f);throw n?.(m),m}}}function I(t){const{apiSpecs:r,baseUrl:o,getAuthorization:s,extractApiError:e,parseQuery:a,transformResponse:n,onError:c,appendTrailingSlash:i,formDataParser:g,customFetch:h}=t,y=T({baseUrl:o,getAuthorization:s,extractApiError:e,parseQuery:a,transformResponse:n,onError:c,appendTrailingSlash:i,formDataParser:g,customFetch:h}),u={};for(const[f,m]of Object.entries(r))u[f]=(E=>y(m,E));return u}exports.ApiDomainError=p;exports.buildUrlPath=P;exports.createRequestFunction=T;exports.createSDK=I;exports.defaultExtractApiError=q;exports.defaultTransformResponse=b; |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
71540
-0.04%