lh-vibex-frontend-sdk 1.0.0
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 +28 -0
- package/dist/index.min.js +1 -0
- package/dist/sdk.min.js +1 -0
- package/package.json +36 -0
package/README.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Vibex Frontend Sdk Package
|
|
2
|
+
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
- **Node.js** >= 18.x
|
|
8
|
+
- **npm** >= 9.x
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## Getting Started
|
|
13
|
+
|
|
14
|
+
### 1. Build the package
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm run build
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### 2. Use the package in your project
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install lh-vibex-frontend-sdk
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
```javascript
|
|
27
|
+
import { createClient } from "lh-vibex-frontend-sdk";
|
|
28
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function b(e){return e.endsWith("/")?e:e+"/"}function O(e){return e?Array.isArray(e)?e.join(","):e:void 0}function S(e){let o={...e};return Object.keys(o).forEach(a=>o[a]===void 0&&delete o[a]),o}function l(e){return typeof File<"u"&&e instanceof File||typeof Blob<"u"&&e instanceof Blob}function m(e){return typeof FormData<"u"&&e instanceof FormData}function y(e){if(!e||typeof e!="object")return!1;if(m(e)||l(e))return!0;if(Array.isArray(e))return e.some(y);for(let o of Object.values(e))if(y(o))return!0;return!1}function h(e,o=new FormData,a){return e==null?o:l(e)?(o.append(a||"file",e),o):Array.isArray(e)?(e.forEach((n,i)=>{let r=a?`${a}[${i}]`:String(i);l(n)?o.append(r,n):typeof n=="object"&&n!==null?h(n,o,r):o.append(r,n==null?"":String(n))}),o):typeof e=="object"?(Object.entries(e).forEach(([n,i])=>{let r=a?`${a}[${n}]`:n;i!=null&&(l(i)?o.append(r,i):typeof i=="object"?h(i,o,r):o.append(r,String(i)))}),o):(o.append(a||"value",String(e)),o)}function q(e){let o=e.fetchImpl??fetch,a="access_token",n=e.token??(typeof window<"u"?localStorage.getItem(a)??void 0:void 0),i=(t,u)=>{n=t,typeof window<"u"&&u&&(t?localStorage.setItem(a,t):localStorage.removeItem(a))},r=(t,u)=>{let d=new URL(t,b(e.serverUrl));return u&&Object.entries(u).forEach(([f,c])=>c!=null&&d.searchParams.append(f,String(c))),d.toString()};return{request:async(t,u={})=>{let d=r(t,u.query),f=typeof window<"u"?localStorage.getItem(a)??n:n,c;try{c=await o(d,{...u,headers:{Accept:"application/json",...u.headers||{},...f?{Authorization:`Bearer ${f}`}:{}}})}catch{return}if(c.status===204)return;let T=c.headers.get("content-type")||"",g=await c.text(),p=g,w=T.includes("application/json")||T.includes("application/problem+json");if(w)try{p=g?JSON.parse(g):void 0}catch{}if(c.status===401||c.status===403){console.warn(`[vibexClient SDK] Unauthorized (${c.status})`);try{n=void 0,typeof window<"u"&&!t.includes("auth/login")&&!t.includes("auth/register")&&(window.location.href="/")}catch{}throw{name:"vibexClientError",message:"Unauthorized",status:c.status,data:p}}if(!c.ok)throw{name:"vibexClientError",message:p?.message||p?.title||"Request failed",status:p?.status??c.status,data:p};return w?p:g},setToken:i,getConfig:()=>({serverUrl:e.serverUrl})}}function P(e,o){return new Proxy({},{get(a,n){let i=String(n);return async(...r)=>{let s=e,t=r[r.length-1];if(t?.filter&&(t.filter=JSON.stringify(t.filter)),t?.sort&&(t.sort=JSON.stringify(t.sort)),["list","filter","search","count","paging"].includes(i))return o.request(`${s}/${i}`,{method:"GET",query:S(t)});let d=t&&typeof t=="object"&&!Array.isArray(t)&&!l(t)&&!m(t)&&!y(t),f=d?t:void 0,c=d?r.slice(0,-1):r;if(c.length&&(s+="/"+c.map(encodeURIComponent).join("/")),s+="/"+encodeURIComponent(i),m(f))return o.request(s,{method:"POST",body:f});if(l(f)||y(f)){let T=h(f);return o.request(s,{method:"POST",body:T})}return f?o.request(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(f)}):o.request(s,{method:"GET"})}}})}function $(e){return new Proxy({},{get(o,a){let n=String(a);return new Proxy({},{get(i,r){let s=String(r);return async(...t)=>{switch(s){case"list":return e.request(`${n}`,{method:"GET",query:S({query:S({filter:1,sort:1,limit:t[0]?.limit,skip:t[0]?.skip,fields:O(t[0]?.fields)})})});case"paging":return e.request(`${n}/paging`,{method:"GET",query:S({page:t[0]?.page,pageSize:t[0]?.pageSize,filter:t[0]?.filter?JSON.stringify(t[0].filter):void 0,sort:t[0]?.sort?JSON.stringify(t[0].sort):void 0,fields:O(t[0]?.fields)})});case"get":return e.request(`${n}/${encodeURIComponent(t[0])}/get`,{method:"GET"});case"create":{let u=t[0];if(m(u))return e.request(`${n}`,{method:"POST",body:u});if(l(u)||y(u)){let d=h(u);return e.request(`${n}/create`,{method:"POST",body:d})}return e.request(`${n}/create`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(u)})}case"update":{let u=t[0],d=t[1];if(m(d))return e.request(`${n}/${u}`,{method:"POST",body:d});if(l(d)||y(d)){let f=h(d);return e.request(`${n}/${u}/update`,{method:"POST",body:f})}return e.request(`${n}/${u}/update`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(d)})}case"delete":return e.request(`${n}/${t[0]}/delete`,{method:"GET"});default:return e.request(`${n}`,{method:"GET",query:S(t[0])})}}}})}})}function C(e){return new Proxy({},{get(o,a){let n=String(a);return new Proxy({},{get(i,r){let s=String(r);return async t=>{if(m(t))return e.request(`integrations/${n}/${s}`,{method:"POST",body:t});if(l(t)||y(t)){let u=h(t);return e.request(`integrations/${n}/${s}`,{method:"POST",body:u})}return e.request(`integrations/${n}/${s}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t??{})})}}})}})}function x(e,o){return new Proxy({},{get(a,n){let i=String(n);return async(...r)=>{switch(i){case"register":{let s=await e.request("auth/register",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r[0]??{})});return s?.data.data.token&&localStorage.setItem("access_token",s.data.data.token),s?.data.data.user&&localStorage.setItem("user",JSON.stringify(s.data.data.user)),s}case"login":{let s=typeof r[0]=="string"?{email:r[0],password:r[1]}:r[0],t=await e.request("auth/login",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});return t?.data?.data?.token&&localStorage.setItem("access_token",t.data.data.token),t?.data?.data?.user&&localStorage.setItem("user",JSON.stringify(t.data.data.user)),t}case"me":return e.request("auth/me",{method:"GET"});case"refresh":{let s=await e.request("auth/refresh",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r[0]??{})});return s?.data.refresh_token&&e.setToken(s.data.refresh_token,!0),s}case"changePassword":return e.request("auth/change-password",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r[0]??{})});case"updateProfile":return e.request("auth/update-profile",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r[0]??{})});case"verify":return e.request("auth/verify",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r[0]??{})});case"updateMe":return e.request("auth/me",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(r[0])});case"logout":e.setToken(void 0,!0),typeof window<"u"&&(localStorage.removeItem("access_token"),localStorage.removeItem("user"),window.location.href="/");return;case"setToken":return e.setToken(r[0],r[1]);default:return e.request(`auth/${i}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r[0]??{})})}}}})}function j(e){let o=async(a,n={})=>{let i=(n.method||"POST").toUpperCase(),r={method:i};return n.query&&(r.query=n.query),n.headers&&(r.headers={...n.headers}),n.body&&i!=="GET"&&i!=="HEAD"&&(r.headers={"Content-Type":"application/json",...r.headers||{}},r.body=JSON.stringify(n.body)),e.request(`functions/${encodeURIComponent(a)}`,r)};return new Proxy({invoke:o},{get(a,n){if(n in a)return a[n];let i=String(n);return async(r,s={})=>o(i,{...s,body:r})}})}function k(e){if(!e?.serverUrl)throw new Error("serverUrl is required");let o=q(e),a=q({...e,serverUrl:e.serverUrl.replace(/\/entities\/?$/,"")}),n={entities:$(o),integrations:C(o),functions:j(a),auth:x(o,e),setToken:i=>o.setToken(i,!0),getConfig:()=>({serverUrl:e.serverUrl})};return new Proxy(n,{get(i,r){if(r in i)return i[r];let s=P(r,o);return i[r]=s,s}})}export{k as createClient};
|
package/dist/sdk.min.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var $=Object.defineProperty;var C=(e,o)=>{for(var a in o)$(e,a,{get:o[a],enumerable:!0})};var P={};C(P,{createClient:()=>k});function b(e){return e.endsWith("/")?e:e+"/"}function O(e){return e?Array.isArray(e)?e.join(","):e:void 0}function S(e){let o={...e};return Object.keys(o).forEach(a=>o[a]===void 0&&delete o[a]),o}function l(e){return typeof File<"u"&&e instanceof File||typeof Blob<"u"&&e instanceof Blob}function m(e){return typeof FormData<"u"&&e instanceof FormData}function y(e){if(!e||typeof e!="object")return!1;if(m(e)||l(e))return!0;if(Array.isArray(e))return e.some(y);for(let o of Object.values(e))if(y(o))return!0;return!1}function h(e,o=new FormData,a){return e==null?o:l(e)?(o.append(a||"file",e),o):Array.isArray(e)?(e.forEach((n,i)=>{let r=a?`${a}[${i}]`:String(i);l(n)?o.append(r,n):typeof n=="object"&&n!==null?h(n,o,r):o.append(r,n==null?"":String(n))}),o):typeof e=="object"?(Object.entries(e).forEach(([n,i])=>{let r=a?`${a}[${n}]`:n;i!=null&&(l(i)?o.append(r,i):typeof i=="object"?h(i,o,r):o.append(r,String(i)))}),o):(o.append(a||"value",String(e)),o)}function q(e){let o=e.fetchImpl??fetch,a="access_token",n=e.token??(typeof window<"u"?localStorage.getItem(a)??void 0:void 0),i=(t,u)=>{n=t,typeof window<"u"&&u&&(t?localStorage.setItem(a,t):localStorage.removeItem(a))},r=(t,u)=>{let d=new URL(t,b(e.serverUrl));return u&&Object.entries(u).forEach(([f,c])=>c!=null&&d.searchParams.append(f,String(c))),d.toString()};return{request:async(t,u={})=>{let d=r(t,u.query),f=typeof window<"u"?localStorage.getItem(a)??n:n,c;try{c=await o(d,{...u,headers:{Accept:"application/json",...u.headers||{},...f?{Authorization:`Bearer ${f}`}:{}}})}catch{return}if(c.status===204)return;let T=c.headers.get("content-type")||"",g=await c.text(),p=g,w=T.includes("application/json")||T.includes("application/problem+json");if(w)try{p=g?JSON.parse(g):void 0}catch{}if(c.status===401||c.status===403){console.warn(`[vibexClient SDK] Unauthorized (${c.status})`);try{n=void 0,typeof window<"u"&&!t.includes("auth/login")&&!t.includes("auth/register")&&(window.location.href="/")}catch{}throw{name:"vibexClientError",message:"Unauthorized",status:c.status,data:p}}if(!c.ok)throw{name:"vibexClientError",message:p?.message||p?.title||"Request failed",status:p?.status??c.status,data:p};return w?p:g},setToken:i,getConfig:()=>({serverUrl:e.serverUrl})}}function x(e,o){return new Proxy({},{get(a,n){let i=String(n);return async(...r)=>{let s=e,t=r[r.length-1];if(t?.filter&&(t.filter=JSON.stringify(t.filter)),t?.sort&&(t.sort=JSON.stringify(t.sort)),["list","filter","search","count","paging"].includes(i))return o.request(`${s}/${i}`,{method:"GET",query:S(t)});let d=t&&typeof t=="object"&&!Array.isArray(t)&&!l(t)&&!m(t)&&!y(t),f=d?t:void 0,c=d?r.slice(0,-1):r;if(c.length&&(s+="/"+c.map(encodeURIComponent).join("/")),s+="/"+encodeURIComponent(i),m(f))return o.request(s,{method:"POST",body:f});if(l(f)||y(f)){let T=h(f);return o.request(s,{method:"POST",body:T})}return f?o.request(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(f)}):o.request(s,{method:"GET"})}}})}function j(e){return new Proxy({},{get(o,a){let n=String(a);return new Proxy({},{get(i,r){let s=String(r);return async(...t)=>{switch(s){case"list":return e.request(`${n}`,{method:"GET",query:S({query:S({filter:1,sort:1,limit:t[0]?.limit,skip:t[0]?.skip,fields:O(t[0]?.fields)})})});case"paging":return e.request(`${n}/paging`,{method:"GET",query:S({page:t[0]?.page,pageSize:t[0]?.pageSize,filter:t[0]?.filter?JSON.stringify(t[0].filter):void 0,sort:t[0]?.sort?JSON.stringify(t[0].sort):void 0,fields:O(t[0]?.fields)})});case"get":return e.request(`${n}/${encodeURIComponent(t[0])}/get`,{method:"GET"});case"create":{let u=t[0];if(m(u))return e.request(`${n}`,{method:"POST",body:u});if(l(u)||y(u)){let d=h(u);return e.request(`${n}/create`,{method:"POST",body:d})}return e.request(`${n}/create`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(u)})}case"update":{let u=t[0],d=t[1];if(m(d))return e.request(`${n}/${u}`,{method:"POST",body:d});if(l(d)||y(d)){let f=h(d);return e.request(`${n}/${u}/update`,{method:"POST",body:f})}return e.request(`${n}/${u}/update`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(d)})}case"delete":return e.request(`${n}/${t[0]}/delete`,{method:"GET"});default:return e.request(`${n}`,{method:"GET",query:S(t[0])})}}}})}})}function E(e){return new Proxy({},{get(o,a){let n=String(a);return new Proxy({},{get(i,r){let s=String(r);return async t=>{if(m(t))return e.request(`integrations/${n}/${s}`,{method:"POST",body:t});if(l(t)||y(t)){let u=h(t);return e.request(`integrations/${n}/${s}`,{method:"POST",body:u})}return e.request(`integrations/${n}/${s}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t??{})})}}})}})}function J(e,o){return new Proxy({},{get(a,n){let i=String(n);return async(...r)=>{switch(i){case"register":{let s=await e.request("auth/register",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r[0]??{})});return s?.data.data.token&&localStorage.setItem("access_token",s.data.data.token),s?.data.data.user&&localStorage.setItem("user",JSON.stringify(s.data.data.user)),s}case"login":{let s=typeof r[0]=="string"?{email:r[0],password:r[1]}:r[0],t=await e.request("auth/login",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});return t?.data?.data?.token&&localStorage.setItem("access_token",t.data.data.token),t?.data?.data?.user&&localStorage.setItem("user",JSON.stringify(t.data.data.user)),t}case"me":return e.request("auth/me",{method:"GET"});case"refresh":{let s=await e.request("auth/refresh",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r[0]??{})});return s?.data.refresh_token&&e.setToken(s.data.refresh_token,!0),s}case"changePassword":return e.request("auth/change-password",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r[0]??{})});case"updateProfile":return e.request("auth/update-profile",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r[0]??{})});case"verify":return e.request("auth/verify",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r[0]??{})});case"updateMe":return e.request("auth/me",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(r[0])});case"logout":e.setToken(void 0,!0),typeof window<"u"&&(localStorage.removeItem("access_token"),localStorage.removeItem("user"),window.location.href="/");return;case"setToken":return e.setToken(r[0],r[1]);default:return e.request(`auth/${i}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r[0]??{})})}}}})}function N(e){let o=async(a,n={})=>{let i=(n.method||"POST").toUpperCase(),r={method:i};return n.query&&(r.query=n.query),n.headers&&(r.headers={...n.headers}),n.body&&i!=="GET"&&i!=="HEAD"&&(r.headers={"Content-Type":"application/json",...r.headers||{}},r.body=JSON.stringify(n.body)),e.request(`functions/${encodeURIComponent(a)}`,r)};return new Proxy({invoke:o},{get(a,n){if(n in a)return a[n];let i=String(n);return async(r,s={})=>o(i,{...s,body:r})}})}function k(e){if(!e?.serverUrl)throw new Error("serverUrl is required");let o=q(e),a=q({...e,serverUrl:e.serverUrl.replace(/\/entities\/?$/,"")}),n={entities:j(o),integrations:E(o),functions:N(a),auth:J(o,e),setToken:i=>o.setToken(i,!0),getConfig:()=>({serverUrl:e.serverUrl})};return new Proxy(n,{get(i,r){if(r in i)return i[r];let s=x(r,o);return i[r]=s,s}})}export{P as vibex};
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "lh-vibex-frontend-sdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "JavaScript SDK for the Vibex frontend API.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.min.js",
|
|
7
|
+
"module": "dist/index.min.js",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"exports": {
|
|
12
|
+
".": "./dist/index.min.js",
|
|
13
|
+
"./sdk": "./dist/sdk.min.js"
|
|
14
|
+
},
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=18"
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"clean": "rimraf dist/*",
|
|
20
|
+
"build": "npm run clean && npx esbuild src/index.js --bundle --minify --format=esm --outfile=dist/index.min.js && npx esbuild src/sdk/index.js --bundle --minify --format=esm --outfile=dist/sdk.min.js",
|
|
21
|
+
"prepare": "npm run build",
|
|
22
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"vibex",
|
|
26
|
+
"sdk",
|
|
27
|
+
"frontend",
|
|
28
|
+
"client"
|
|
29
|
+
],
|
|
30
|
+
"author": "",
|
|
31
|
+
"license": "ISC",
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"esbuild": "^0.27.4",
|
|
34
|
+
"rimraf": "^6.1.3"
|
|
35
|
+
}
|
|
36
|
+
}
|