@magentrix-corp/magentrix-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 +50 -0
- package/dist/index.cjs.js +2 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/vue/useMagentrixSdk.js +2 -0
- package/dist/vue/useMagentrixSdk.js.map +1 -0
- package/package.json +39 -0
package/README.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
Magentrix SDK for Javascript.
|
|
2
|
+
|
|
3
|
+
Javascript:
|
|
4
|
+
|
|
5
|
+
import { MagentrixClient } from 'magentrix-sdk'
|
|
6
|
+
|
|
7
|
+
const client = new MagentrixClient({
|
|
8
|
+
baseUrl: 'https://xyz.com',
|
|
9
|
+
token: '',
|
|
10
|
+
refreshToken: 'xyz',
|
|
11
|
+
antiForgeryToken: '',
|
|
12
|
+
onSessionExpired: () => Promise<void> | void
|
|
13
|
+
onError?: (error: any) => void
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
client.createSession().then(si => {
|
|
17
|
+
console.log(si.token)
|
|
18
|
+
client.retrieve('xyz').then(r => console.log(r))
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
VUE JS:
|
|
23
|
+
|
|
24
|
+
<script setup>
|
|
25
|
+
import { onMounted } from 'vue'
|
|
26
|
+
import { MagentrixClient } from 'magentrix-sdk/vue'
|
|
27
|
+
|
|
28
|
+
const client = useMagentrixSdk({
|
|
29
|
+
baseUrl: 'https://xyz.com',
|
|
30
|
+
token: '',
|
|
31
|
+
refreshToken: 'xyz',
|
|
32
|
+
antiForgeryToken: '',
|
|
33
|
+
onSessionExpired: () => Promise<void> | void
|
|
34
|
+
onError?: (error: any) => void
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
const model = ref()
|
|
38
|
+
|
|
39
|
+
onMounted(async () => {
|
|
40
|
+
const si = await client.createSession()
|
|
41
|
+
console.log(si.token)
|
|
42
|
+
const r = await client.retrieve('xyz')
|
|
43
|
+
console.log(r)
|
|
44
|
+
model.value = r
|
|
45
|
+
})
|
|
46
|
+
</script>
|
|
47
|
+
|
|
48
|
+
<template>
|
|
49
|
+
<p>{{ model.Id }}</p>
|
|
50
|
+
</template>
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var t,e;Object.defineProperty(exports,"__esModule",{value:!0}),exports.RequestMethod=void 0,(t=exports.RequestMethod||(exports.RequestMethod={})).get="GET",t.post="POST",t.put="PUT",t.patch="PATCH",t.delete="DELETE",exports.ContentType=void 0,(e=exports.ContentType||(exports.ContentType={})).json="application/json",e.form_url_encoded="application/x-www-form-urlencoded",e.xml="application/xml",e.text="text/plain";class r extends Error{constructor(t){super(t),this.name="MagentrixError",Object.setPrototypeOf(this,r.prototype)}}class s extends Error{errors;constructor(t,e=[]){super(t),this.name="DatabaseError",this.errors=e,Object.setPrototypeOf(this,s.prototype)}getErrors(){return this.errors}hasErrors(){return this.errors.length>0}}exports.DatabaseError=s,exports.MagentrixClient=class{config;sessionInfo=null;restVersion="3.0";constructor(t){this.config={baseUrl:t.baseUrl.replace(/\/$/,""),token:t.token,refreshToken:t.refreshToken,antiForgeryToken:t.antiForgeryToken,onSessionExpired:t.onSessionExpired,onError:t.onError},t.token&&(this.sessionInfo={token:t.token,refresh_token:t.refreshToken||"",expires_in:0})}async createSession(t){const e=t||this.config.refreshToken;if(!e)throw new r("Refresh token is required to create a session");const s=`${this.config.baseUrl}/api/${this.restVersion}/token`,o={grant_type:"refresh_token",refresh_token:e},n=await fetch(s,{method:"POST",headers:{"Content-Type":exports.ContentType.json},body:JSON.stringify(o)});if(!n.ok){const t=await n.json();throw new r(t.message||"Failed to create session")}return this.sessionInfo=await n.json(),this.sessionInfo}async query(t){if(!t)throw new r("Query is required");const e={query:t,permissions:null},s=this.convertToEncodedKeyValuePairs(e);return this.postData("/iris/query",s,exports.ContentType.form_url_encoded)}async execute(t,e=null,s=exports.RequestMethod.post){if(!t)throw new r("Endpoint path is required");if(s===exports.RequestMethod.get&&e)throw new r("GET requests cannot have a request body");if(s===exports.RequestMethod.get)return this.getData(t);{const r=e?this.convertToEncodedKeyValuePairs(e):null;return this.postData(t,r,exports.ContentType.form_url_encoded)}}async retrieve(t){if(!t)throw new r("ID is required");const e={id:t,permissions:null},s=`/iris/retrieve?${this.convertToEncodedKeyValuePairs(e)}`;return this.getData(s)}async create(t,e){if(!t)throw new r("Entity name is required");if(!e)throw new r("Data is required");const s=`/api/${this.restVersion}/entity/${t}`;return this.postData(s,e)}async edit(t,e){if(!t)throw new r("Entity name is required");if(!e)throw new r("Data is required");const s=`/api/${this.restVersion}/entity/${t}`;return this.patchData(s,e)}async upsert(t,e){if(!t)throw new r("Entity name is required");if(!e)throw new r("Data is required");const s=`/api/${this.restVersion}/entity/${t}`;return this.putData(s,e)}async delete(t,e,s=!1){if(!e)throw new r("ID is required");if(!t)throw new r("Entity name is required");const o=`/api/${this.restVersion}/entity/${t}/${e}?isPermanent=${s}`;return this.deleteData(o)}async deleteMany(t,e,s=!1){if(!e||0===e.length)throw new r("IDs are required");if(!t)throw new r("Entity name is required");const o=`/api/${this.restVersion}/entity/${t}?isPermanent=${s}`;return this.deleteData(o,e)}convertToEncodedKeyValuePairs(t){let e="";for(const[r,s]of Object.entries(t)){let t;t=null==s?"":"object"==typeof s?JSON.stringify(s):s.toString(),e+=`${r}=${encodeURIComponent(t)}&`}return e.endsWith("&")&&(e=e.substring(0,e.length-1)),e}async getData(t){const e=this.getFullUrl(t),r=this.getRequestOptions(),s=await fetch(e,r);if(await this.handleAuthError(s))return this.getData(t);const o=await s.json();return s.ok||this.throwError(o),o}async postData(t,e,r=exports.ContentType.json){const s=this.getFullUrl(t),o={...this.getRequestOptions(exports.RequestMethod.post,r),body:r===exports.ContentType.json?JSON.stringify(e):e},n=await fetch(s,o);if(await this.handleAuthError(n))return this.postData(t,e,r);const i=await n.json();return n.ok||this.throwError(i),this.fillIdsOnCreate(e,i),e?.hasOwnProperty("ModifiedOn")&&(e.ModifiedOn=(new Date).toISOString().slice(0,-1)),i}async patchData(t,e){const r=this.getFullUrl(t),s={...this.getRequestOptions(exports.RequestMethod.patch),body:JSON.stringify(e)},o=await fetch(r,s);if(await this.handleAuthError(o))return this.patchData(t,e);const n=await o.json();return o.ok||this.throwError(n),e?.hasOwnProperty("ModifiedOn")&&(e.ModifiedOn=(new Date).toISOString().slice(0,-1)),n}async putData(t,e){const r=this.getFullUrl(t),s={...this.getRequestOptions(exports.RequestMethod.put),body:JSON.stringify(e)},o=await fetch(r,s);if(await this.handleAuthError(o))return this.putData(t,e);const n=await o.json();return o.ok||this.throwError(n),e.Id||this.fillIdsOnCreate(e,n),e?.hasOwnProperty("ModifiedOn")&&(e.ModifiedOn=(new Date).toISOString().slice(0,-1)),n}async deleteData(t,e=null){const r=this.getFullUrl(t),s={...this.getRequestOptions(exports.RequestMethod.delete),body:e?JSON.stringify(e):null},o=await fetch(r,s);if(await this.handleAuthError(o))return this.deleteData(t,e);const n=await o.json();return o.ok||this.throwError(n),n}getRequestOptions(t=exports.RequestMethod.get,e=exports.ContentType.json,r=exports.ContentType.json){const s={method:t,headers:{"Content-Type":e,"MAG-StrictMode":"false",Accept:r}};return t===exports.RequestMethod.post&&this.config.antiForgeryToken&&(s.headers.__RequestVerificationToken=this.config.antiForgeryToken),this.sessionInfo?.token&&(s.headers.Authorization=`Bearer ${this.sessionInfo.token}`),s}async handleAuthError(t){return!(401!==t.status&&403!==t.status||!this.config.onSessionExpired)&&(await this.config.onSessionExpired(),!0)}getFullUrl(t){return t.startsWith("http://")||t.startsWith("https://")?t:`${this.config.baseUrl}${t.startsWith("/")?t:"/"+t}`}fillIdsOnCreate(t,e){if(null==t)return;if(Array.isArray(t)){const r=t.length;if(0===r)return;for(let s=0;s<r;s++)void 0===t[s].Id&&e[s].Id&&(t[s].Id=e[s].Id)}else void 0===t.Id&&e.Id&&(t.Id=e.Id)}throwError(t){throw this.config.onError&&this.config.onError(t),"string"==typeof t?new r(t):t.hasOwnProperty("message")?new r(t.message):t.hasOwnProperty("errors")?new s("Database Error",t.errors):new r("Unknown error!")}},exports.MagentrixError=r;
|
|
2
|
+
//# sourceMappingURL=index.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../src/helpers/enums.ts","../src/helpers/errors.ts","../src/helpers/MagentrixClient.ts"],"sourcesContent":["export enum RequestMethod {\n get = 'GET',\n post = 'POST',\n put = 'PUT',\n patch = 'PATCH',\n delete = 'DELETE'\n}\n\nexport enum ContentType {\n json = 'application/json',\n form_url_encoded = 'application/x-www-form-urlencoded',\n xml = 'application/xml',\n text = 'text/plain'\n}\n","export class MagentrixError extends Error {\r\n constructor(message: string) {\r\n super(message)\r\n this.name = 'MagentrixError'\r\n Object.setPrototypeOf(this, MagentrixError.prototype)\r\n }\r\n}\r\n\r\nexport class DatabaseError extends Error {\r\n errors: any[]\r\n\r\n constructor(message: string, errors: any[] = []) {\r\n super(message)\r\n this.name = 'DatabaseError'\r\n this.errors = errors\r\n Object.setPrototypeOf(this, DatabaseError.prototype)\r\n }\r\n\r\n getErrors(): any[] {\r\n return this.errors\r\n }\r\n\r\n hasErrors(): boolean {\r\n return this.errors.length > 0\r\n }\r\n}\r\n","import { RequestMethod, ContentType } from './enums'\r\nimport { MagentrixConfig, SessionInfo } from './interfaces'\r\nimport { MagentrixError, DatabaseError } from './errors'\r\n\r\nexport class MagentrixClient {\r\n private config: MagentrixConfig\r\n private sessionInfo: SessionInfo | null = null\r\n private restVersion = '3.0'\r\n\r\n constructor(config: MagentrixConfig) {\r\n this.config = {\r\n baseUrl: config.baseUrl.replace(/\\/$/, ''),\r\n token: config.token,\r\n refreshToken: config.refreshToken,\r\n antiForgeryToken: config.antiForgeryToken,\r\n onSessionExpired: config.onSessionExpired,\r\n onError: config.onError\r\n }\r\n\r\n if (config.token) {\r\n this.sessionInfo = {\r\n token: config.token,\r\n refresh_token: config.refreshToken || '',\r\n expires_in: 0\r\n }\r\n }\r\n }\r\n\r\n async createSession(refreshToken?: string): Promise<SessionInfo> {\r\n const token = refreshToken || this.config.refreshToken\r\n\r\n if (!token)\r\n throw new MagentrixError('Refresh token is required to create a session')\r\n\r\n const url = `${this.config.baseUrl}/api/${this.restVersion}/token`\r\n const body = { grant_type: 'refresh_token', refresh_token: token }\r\n \r\n const response = await fetch(url, {\r\n method: 'POST',\r\n headers: { 'Content-Type': ContentType.json },\r\n body: JSON.stringify(body)\r\n })\r\n\r\n if (!response.ok) {\r\n const error = await response.json()\r\n throw new MagentrixError(error.message || 'Failed to create session')\r\n }\r\n\r\n this.sessionInfo = await response.json()\r\n return this.sessionInfo!\r\n }\r\n\r\n async query(query: string): Promise<any> {\r\n if (!query)\r\n throw new MagentrixError('Query is required')\r\n\r\n const path = '/iris/query'\r\n const model = { query, permissions: null }\r\n const data = this.convertToEncodedKeyValuePairs(model)\r\n \r\n return this.postData(path, data, ContentType.form_url_encoded)\r\n }\r\n\r\n async execute(path: string, model: any = null, method = RequestMethod.post): Promise<any> {\r\n if (!path)\r\n throw new MagentrixError('Endpoint path is required')\r\n\r\n if (method === RequestMethod.get && model)\r\n throw new MagentrixError('GET requests cannot have a request body')\r\n\r\n if (method === RequestMethod.get)\r\n return this.getData(path)\r\n else {\r\n const data = model ? this.convertToEncodedKeyValuePairs(model) : null\r\n return this.postData(path, data, ContentType.form_url_encoded)\r\n }\r\n }\r\n\r\n async retrieve(id: string): Promise<any> {\r\n if (!id)\r\n throw new MagentrixError('ID is required')\r\n\r\n const model = { id, permissions: null }\r\n const data = this.convertToEncodedKeyValuePairs(model)\r\n const path = `/iris/retrieve?${data}`\r\n \r\n return this.getData(path)\r\n }\r\n\r\n async create(entityName: string, data: any): Promise<any> {\r\n if (!entityName)\r\n throw new MagentrixError('Entity name is required')\r\n\r\n if (!data)\r\n throw new MagentrixError('Data is required')\r\n\r\n const path = `/api/${this.restVersion}/entity/${entityName}`\r\n \r\n return this.postData(path, data)\r\n }\r\n\r\n async edit(entityName: string, data: any): Promise<any> {\r\n if (!entityName)\r\n throw new MagentrixError('Entity name is required')\r\n\r\n if (!data)\r\n throw new MagentrixError('Data is required')\r\n\r\n const path = `/api/${this.restVersion}/entity/${entityName}`\r\n \r\n return this.patchData(path, data)\r\n }\r\n\r\n async upsert(entityName: string, data: any): Promise<any> {\r\n if (!entityName)\r\n throw new MagentrixError('Entity name is required')\r\n\r\n if (!data)\r\n throw new MagentrixError('Data is required')\r\n\r\n const path = `/api/${this.restVersion}/entity/${entityName}`\r\n \r\n return this.putData(path, data)\r\n }\r\n\r\n async delete(entityName: string, id: string, permanent: boolean = false): Promise<any> {\r\n if (!id)\r\n throw new MagentrixError('ID is required')\r\n\r\n if (!entityName)\r\n throw new MagentrixError('Entity name is required')\r\n\r\n const path = `/api/${this.restVersion}/entity/${entityName}/${id}?isPermanent=${permanent}`\r\n \r\n return this.deleteData(path)\r\n }\r\n\r\n async deleteMany(entityName: string, ids: string[], permanent: boolean = false): Promise<any> {\r\n if (!ids || ids.length === 0)\r\n throw new MagentrixError('IDs are required')\r\n\r\n if (!entityName)\r\n throw new MagentrixError('Entity name is required')\r\n\r\n const path = `/api/${this.restVersion}/entity/${entityName}?isPermanent=${permanent}`\r\n \r\n return this.deleteData(path, ids)\r\n }\r\n\r\n private convertToEncodedKeyValuePairs(obj: any): string {\r\n let result = ''\r\n\r\n for (const [key, value] of Object.entries(obj)) {\r\n let modifiedValue: string\r\n\r\n if (value === null || value === undefined)\r\n modifiedValue = ''\r\n else if (typeof value === 'object')\r\n modifiedValue = JSON.stringify(value)\r\n else\r\n modifiedValue = value.toString()\r\n\r\n result += `${key}=${encodeURIComponent(modifiedValue)}&`\r\n }\r\n\r\n if (result.endsWith('&'))\r\n result = result.substring(0, result.length - 1)\r\n\r\n return result\r\n }\r\n\r\n private async getData(path: string): Promise<any> {\r\n const url = this.getFullUrl(path)\r\n const options = this.getRequestOptions()\r\n const response = await fetch(url, options)\r\n\r\n if (await this.handleAuthError(response))\r\n return this.getData(path)\r\n\r\n const result = await response.json()\r\n\r\n if (!response.ok)\r\n this.throwError(result)\r\n\r\n return result\r\n }\r\n\r\n private async postData(path: string, data: any, contentType: ContentType = ContentType.json): Promise<any> {\r\n const url = this.getFullUrl(path)\r\n const options = {\r\n ...this.getRequestOptions(RequestMethod.post, contentType),\r\n body: contentType === ContentType.json ? JSON.stringify(data) : data\r\n }\r\n const response = await fetch(url, options)\r\n\r\n if (await this.handleAuthError(response))\r\n return this.postData(path, data, contentType)\r\n\r\n const result = await response.json()\r\n\r\n if (!response.ok)\r\n this.throwError(result)\r\n\r\n this.fillIdsOnCreate(data, result)\r\n\r\n if (data?.hasOwnProperty('ModifiedOn'))\r\n data.ModifiedOn = new Date().toISOString().slice(0, -1)\r\n\r\n return result\r\n }\r\n\r\n private async patchData(path: string, data: any): Promise<any> {\r\n const url = this.getFullUrl(path)\r\n const options = {\r\n ...this.getRequestOptions(RequestMethod.patch),\r\n body: JSON.stringify(data)\r\n }\r\n const response = await fetch(url, options)\r\n\r\n if (await this.handleAuthError(response))\r\n return this.patchData(path, data)\r\n\r\n const result = await response.json()\r\n\r\n if (!response.ok)\r\n this.throwError(result)\r\n\r\n if (data?.hasOwnProperty('ModifiedOn'))\r\n data.ModifiedOn = new Date().toISOString().slice(0, -1)\r\n\r\n return result\r\n }\r\n\r\n private async putData(path: string, data: any): Promise<any> {\r\n const url = this.getFullUrl(path)\r\n const options = {\r\n ...this.getRequestOptions(RequestMethod.put),\r\n body: JSON.stringify(data)\r\n }\r\n const response = await fetch(url, options)\r\n\r\n if (await this.handleAuthError(response))\r\n return this.putData(path, data)\r\n\r\n const result = await response.json()\r\n\r\n if (!response.ok)\r\n this.throwError(result)\r\n\r\n if (!data.Id)\r\n this.fillIdsOnCreate(data, result)\r\n\r\n if (data?.hasOwnProperty('ModifiedOn'))\r\n data.ModifiedOn = new Date().toISOString().slice(0, -1)\r\n\r\n return result\r\n }\r\n\r\n private async deleteData(path: string, data: any = null): Promise<any> {\r\n const url = this.getFullUrl(path)\r\n const options = {\r\n ...this.getRequestOptions(RequestMethod.delete),\r\n body: data ? JSON.stringify(data) : null\r\n }\r\n const response = await fetch(url, options)\r\n\r\n if (await this.handleAuthError(response))\r\n return this.deleteData(path, data)\r\n\r\n const result = await response.json()\r\n\r\n if (!response.ok)\r\n this.throwError(result)\r\n\r\n return result\r\n }\r\n\r\n private getRequestOptions(\r\n method: RequestMethod = RequestMethod.get,\r\n contentType: ContentType = ContentType.json,\r\n acceptType: ContentType = ContentType.json\r\n ): RequestInit {\r\n const options: RequestInit = {\r\n method: method,\r\n headers: {\r\n 'Content-Type': contentType,\r\n 'MAG-StrictMode': 'false',\r\n 'Accept': acceptType\r\n }\r\n }\r\n\r\n if (method === RequestMethod.post && this.config.antiForgeryToken) {\r\n (options.headers as any).__RequestVerificationToken = this.config.antiForgeryToken\r\n }\r\n\r\n if (this.sessionInfo?.token) {\r\n (options.headers as any).Authorization = `Bearer ${this.sessionInfo.token}`\r\n }\r\n\r\n return options\r\n }\r\n\r\n private async handleAuthError(response: Response): Promise<boolean> {\r\n if (response.status === 401 || response.status === 403) {\r\n if (this.config.onSessionExpired) {\r\n await this.config.onSessionExpired()\r\n return true\r\n }\r\n }\r\n\r\n return false\r\n }\r\n\r\n private getFullUrl(path: string): string {\r\n if (path.startsWith('http://') || path.startsWith('https://'))\r\n return path\r\n\r\n return `${this.config.baseUrl}${path.startsWith('/') ? path : '/' + path}`\r\n }\r\n\r\n private fillIdsOnCreate(data: any | any[], result: any | any[]): void {\r\n if (data == null)\r\n return\r\n\r\n const isArray = Array.isArray(data)\r\n\r\n if (isArray) {\r\n const count = data.length\r\n\r\n if (count === 0)\r\n return\r\n\r\n for (let i = 0; i < count; i++) {\r\n if (data[i].Id === undefined && result[i].Id)\r\n data[i].Id = result[i].Id\r\n }\r\n } else {\r\n if (data.Id === undefined && result.Id)\r\n data.Id = result.Id\r\n }\r\n }\r\n\r\n private throwError(error: any): never {\r\n if (this.config.onError)\r\n this.config.onError(error)\r\n\r\n if (typeof error === 'string')\r\n throw new MagentrixError(error)\r\n else if (error.hasOwnProperty('message'))\r\n throw new MagentrixError(error.message)\r\n else if (error.hasOwnProperty('errors'))\r\n throw new DatabaseError('Database Error', error.errors)\r\n else\r\n throw new MagentrixError('Unknown error!')\r\n }\r\n}\r\n"],"names":["RequestMethod","ContentType","MagentrixError","Error","constructor","message","super","this","name","Object","setPrototypeOf","prototype","DatabaseError","errors","getErrors","hasErrors","length","config","sessionInfo","restVersion","baseUrl","replace","token","refreshToken","antiForgeryToken","onSessionExpired","onError","refresh_token","expires_in","createSession","url","body","grant_type","response","fetch","method","headers","json","JSON","stringify","ok","error","query","model","permissions","data","convertToEncodedKeyValuePairs","postData","form_url_encoded","execute","path","post","get","getData","retrieve","id","create","entityName","edit","patchData","upsert","putData","permanent","deleteData","deleteMany","ids","obj","result","key","value","entries","modifiedValue","toString","encodeURIComponent","endsWith","substring","getFullUrl","options","getRequestOptions","handleAuthError","throwError","contentType","fillIdsOnCreate","hasOwnProperty","ModifiedOn","Date","toISOString","slice","patch","put","Id","delete","acceptType","Accept","__RequestVerificationToken","Authorization","status","startsWith","Array","isArray","count","i","undefined"],"mappings":"aAAA,IAAYA,EAQAC,yDARAD,QAMXA,mBAAA,GANWA,EAAAA,wBAAAA,QAAAA,cAMX,CAAA,IALG,IAAA,MACAA,EAAA,KAAA,OACAA,EAAA,IAAA,MACAA,EAAA,MAAA,QACAA,EAAA,OAAA,SAGQC,QAKXA,iBAAA,GALWA,EAAAA,QAAWA,cAAXA,oBAKX,CAAA,IAJG,KAAA,mBACAA,EAAA,iBAAA,oCACAA,EAAA,IAAA,kBACAA,EAAA,KAAA,aCZE,MAAOC,UAAuBC,MAChC,WAAAC,CAAYC,GACRC,MAAMD,GACNE,KAAKC,KAAO,iBACZC,OAAOC,eAAeH,KAAML,EAAeS,UAC9C,EAGC,MAAOC,UAAsBT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AVoF,EACA,OAEJ,IAAK,IAAIC,EAAI,EAAGA,EAAID,EAAOC,SACJC,IAAfzD,EAAKwD,GAAGX,IAAoBvB,EAAOkC,GAAGX,KACtC7C,EAAKwD,GAAGX,GAAKvB,EAAOkC,GAAGX,GAElC,WACmBY,IAAZzD,EAAK6C,IAAoBvB,EAAOuB,KAChC7C,EAAK6C,GAAKvB,EAAOuB,GAE5B,CAEO,UAAAV,CAAWvC,GAIf,MAHIlC,KAAKU,OAAOS,SACZnB,KAAKU,OAAOS,QAAQe,GAEH,iBAAVA,EACD,IAAIvC,EAAeuC,GACpBA,EAAM0C,eAAe,WACpB,IAAIjF,EAAeuC,EAAMpC,SAC1BoC,EAAM0C,eAAe,UACpB,IAAIvE,EAAc,iBAAkB6B,EAAM5B,QAE1C,IAAIX,EAAe,iBAChC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var t,e;!function(t){t.get="GET",t.post="POST",t.put="PUT",t.patch="PATCH",t.delete="DELETE"}(t||(t={})),function(t){t.json="application/json",t.form_url_encoded="application/x-www-form-urlencoded",t.xml="application/xml",t.text="text/plain"}(e||(e={}));class r extends Error{constructor(t){super(t),this.name="MagentrixError",Object.setPrototypeOf(this,r.prototype)}}class s extends Error{errors;constructor(t,e=[]){super(t),this.name="DatabaseError",this.errors=e,Object.setPrototypeOf(this,s.prototype)}getErrors(){return this.errors}hasErrors(){return this.errors.length>0}}class n{config;sessionInfo=null;restVersion="3.0";constructor(t){this.config={baseUrl:t.baseUrl.replace(/\/$/,""),token:t.token,refreshToken:t.refreshToken,antiForgeryToken:t.antiForgeryToken,onSessionExpired:t.onSessionExpired,onError:t.onError},t.token&&(this.sessionInfo={token:t.token,refresh_token:t.refreshToken||"",expires_in:0})}async createSession(t){const s=t||this.config.refreshToken;if(!s)throw new r("Refresh token is required to create a session");const n=`${this.config.baseUrl}/api/${this.restVersion}/token`,i={grant_type:"refresh_token",refresh_token:s},o=await fetch(n,{method:"POST",headers:{"Content-Type":e.json},body:JSON.stringify(i)});if(!o.ok){const t=await o.json();throw new r(t.message||"Failed to create session")}return this.sessionInfo=await o.json(),this.sessionInfo}async query(t){if(!t)throw new r("Query is required");const s={query:t,permissions:null},n=this.convertToEncodedKeyValuePairs(s);return this.postData("/iris/query",n,e.form_url_encoded)}async execute(s,n=null,i=t.post){if(!s)throw new r("Endpoint path is required");if(i===t.get&&n)throw new r("GET requests cannot have a request body");if(i===t.get)return this.getData(s);{const t=n?this.convertToEncodedKeyValuePairs(n):null;return this.postData(s,t,e.form_url_encoded)}}async retrieve(t){if(!t)throw new r("ID is required");const e={id:t,permissions:null},s=`/iris/retrieve?${this.convertToEncodedKeyValuePairs(e)}`;return this.getData(s)}async create(t,e){if(!t)throw new r("Entity name is required");if(!e)throw new r("Data is required");const s=`/api/${this.restVersion}/entity/${t}`;return this.postData(s,e)}async edit(t,e){if(!t)throw new r("Entity name is required");if(!e)throw new r("Data is required");const s=`/api/${this.restVersion}/entity/${t}`;return this.patchData(s,e)}async upsert(t,e){if(!t)throw new r("Entity name is required");if(!e)throw new r("Data is required");const s=`/api/${this.restVersion}/entity/${t}`;return this.putData(s,e)}async delete(t,e,s=!1){if(!e)throw new r("ID is required");if(!t)throw new r("Entity name is required");const n=`/api/${this.restVersion}/entity/${t}/${e}?isPermanent=${s}`;return this.deleteData(n)}async deleteMany(t,e,s=!1){if(!e||0===e.length)throw new r("IDs are required");if(!t)throw new r("Entity name is required");const n=`/api/${this.restVersion}/entity/${t}?isPermanent=${s}`;return this.deleteData(n,e)}convertToEncodedKeyValuePairs(t){let e="";for(const[r,s]of Object.entries(t)){let t;t=null==s?"":"object"==typeof s?JSON.stringify(s):s.toString(),e+=`${r}=${encodeURIComponent(t)}&`}return e.endsWith("&")&&(e=e.substring(0,e.length-1)),e}async getData(t){const e=this.getFullUrl(t),r=this.getRequestOptions(),s=await fetch(e,r);if(await this.handleAuthError(s))return this.getData(t);const n=await s.json();return s.ok||this.throwError(n),n}async postData(r,s,n=e.json){const i=this.getFullUrl(r),o={...this.getRequestOptions(t.post,n),body:n===e.json?JSON.stringify(s):s},a=await fetch(i,o);if(await this.handleAuthError(a))return this.postData(r,s,n);const h=await a.json();return a.ok||this.throwError(h),this.fillIdsOnCreate(s,h),s?.hasOwnProperty("ModifiedOn")&&(s.ModifiedOn=(new Date).toISOString().slice(0,-1)),h}async patchData(e,r){const s=this.getFullUrl(e),n={...this.getRequestOptions(t.patch),body:JSON.stringify(r)},i=await fetch(s,n);if(await this.handleAuthError(i))return this.patchData(e,r);const o=await i.json();return i.ok||this.throwError(o),r?.hasOwnProperty("ModifiedOn")&&(r.ModifiedOn=(new Date).toISOString().slice(0,-1)),o}async putData(e,r){const s=this.getFullUrl(e),n={...this.getRequestOptions(t.put),body:JSON.stringify(r)},i=await fetch(s,n);if(await this.handleAuthError(i))return this.putData(e,r);const o=await i.json();return i.ok||this.throwError(o),r.Id||this.fillIdsOnCreate(r,o),r?.hasOwnProperty("ModifiedOn")&&(r.ModifiedOn=(new Date).toISOString().slice(0,-1)),o}async deleteData(e,r=null){const s=this.getFullUrl(e),n={...this.getRequestOptions(t.delete),body:r?JSON.stringify(r):null},i=await fetch(s,n);if(await this.handleAuthError(i))return this.deleteData(e,r);const o=await i.json();return i.ok||this.throwError(o),o}getRequestOptions(r=t.get,s=e.json,n=e.json){const i={method:r,headers:{"Content-Type":s,"MAG-StrictMode":"false",Accept:n}};return r===t.post&&this.config.antiForgeryToken&&(i.headers.__RequestVerificationToken=this.config.antiForgeryToken),this.sessionInfo?.token&&(i.headers.Authorization=`Bearer ${this.sessionInfo.token}`),i}async handleAuthError(t){return!(401!==t.status&&403!==t.status||!this.config.onSessionExpired)&&(await this.config.onSessionExpired(),!0)}getFullUrl(t){return t.startsWith("http://")||t.startsWith("https://")?t:`${this.config.baseUrl}${t.startsWith("/")?t:"/"+t}`}fillIdsOnCreate(t,e){if(null==t)return;if(Array.isArray(t)){const r=t.length;if(0===r)return;for(let s=0;s<r;s++)void 0===t[s].Id&&e[s].Id&&(t[s].Id=e[s].Id)}else void 0===t.Id&&e.Id&&(t.Id=e.Id)}throwError(t){throw this.config.onError&&this.config.onError(t),"string"==typeof t?new r(t):t.hasOwnProperty("message")?new r(t.message):t.hasOwnProperty("errors")?new s("Database Error",t.errors):new r("Unknown error!")}}export{e as ContentType,s as DatabaseError,n as MagentrixClient,r as MagentrixError,t as RequestMethod};
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/helpers/enums.ts","../src/helpers/errors.ts","../src/helpers/MagentrixClient.ts"],"sourcesContent":["export enum RequestMethod {\n get = 'GET',\n post = 'POST',\n put = 'PUT',\n patch = 'PATCH',\n delete = 'DELETE'\n}\n\nexport enum ContentType {\n json = 'application/json',\n form_url_encoded = 'application/x-www-form-urlencoded',\n xml = 'application/xml',\n text = 'text/plain'\n}\n","export class MagentrixError extends Error {\r\n constructor(message: string) {\r\n super(message)\r\n this.name = 'MagentrixError'\r\n Object.setPrototypeOf(this, MagentrixError.prototype)\r\n }\r\n}\r\n\r\nexport class DatabaseError extends Error {\r\n errors: any[]\r\n\r\n constructor(message: string, errors: any[] = []) {\r\n super(message)\r\n this.name = 'DatabaseError'\r\n this.errors = errors\r\n Object.setPrototypeOf(this, DatabaseError.prototype)\r\n }\r\n\r\n getErrors(): any[] {\r\n return this.errors\r\n }\r\n\r\n hasErrors(): boolean {\r\n return this.errors.length > 0\r\n }\r\n}\r\n","import { RequestMethod, ContentType } from './enums'\r\nimport { MagentrixConfig, SessionInfo } from './interfaces'\r\nimport { MagentrixError, DatabaseError } from './errors'\r\n\r\nexport class MagentrixClient {\r\n private config: MagentrixConfig\r\n private sessionInfo: SessionInfo | null = null\r\n private restVersion = '3.0'\r\n\r\n constructor(config: MagentrixConfig) {\r\n this.config = {\r\n baseUrl: config.baseUrl.replace(/\\/$/, ''),\r\n token: config.token,\r\n refreshToken: config.refreshToken,\r\n antiForgeryToken: config.antiForgeryToken,\r\n onSessionExpired: config.onSessionExpired,\r\n onError: config.onError\r\n }\r\n\r\n if (config.token) {\r\n this.sessionInfo = {\r\n token: config.token,\r\n refresh_token: config.refreshToken || '',\r\n expires_in: 0\r\n }\r\n }\r\n }\r\n\r\n async createSession(refreshToken?: string): Promise<SessionInfo> {\r\n const token = refreshToken || this.config.refreshToken\r\n\r\n if (!token)\r\n throw new MagentrixError('Refresh token is required to create a session')\r\n\r\n const url = `${this.config.baseUrl}/api/${this.restVersion}/token`\r\n const body = { grant_type: 'refresh_token', refresh_token: token }\r\n \r\n const response = await fetch(url, {\r\n method: 'POST',\r\n headers: { 'Content-Type': ContentType.json },\r\n body: JSON.stringify(body)\r\n })\r\n\r\n if (!response.ok) {\r\n const error = await response.json()\r\n throw new MagentrixError(error.message || 'Failed to create session')\r\n }\r\n\r\n this.sessionInfo = await response.json()\r\n return this.sessionInfo!\r\n }\r\n\r\n async query(query: string): Promise<any> {\r\n if (!query)\r\n throw new MagentrixError('Query is required')\r\n\r\n const path = '/iris/query'\r\n const model = { query, permissions: null }\r\n const data = this.convertToEncodedKeyValuePairs(model)\r\n \r\n return this.postData(path, data, ContentType.form_url_encoded)\r\n }\r\n\r\n async execute(path: string, model: any = null, method = RequestMethod.post): Promise<any> {\r\n if (!path)\r\n throw new MagentrixError('Endpoint path is required')\r\n\r\n if (method === RequestMethod.get && model)\r\n throw new MagentrixError('GET requests cannot have a request body')\r\n\r\n if (method === RequestMethod.get)\r\n return this.getData(path)\r\n else {\r\n const data = model ? this.convertToEncodedKeyValuePairs(model) : null\r\n return this.postData(path, data, ContentType.form_url_encoded)\r\n }\r\n }\r\n\r\n async retrieve(id: string): Promise<any> {\r\n if (!id)\r\n throw new MagentrixError('ID is required')\r\n\r\n const model = { id, permissions: null }\r\n const data = this.convertToEncodedKeyValuePairs(model)\r\n const path = `/iris/retrieve?${data}`\r\n \r\n return this.getData(path)\r\n }\r\n\r\n async create(entityName: string, data: any): Promise<any> {\r\n if (!entityName)\r\n throw new MagentrixError('Entity name is required')\r\n\r\n if (!data)\r\n throw new MagentrixError('Data is required')\r\n\r\n const path = `/api/${this.restVersion}/entity/${entityName}`\r\n \r\n return this.postData(path, data)\r\n }\r\n\r\n async edit(entityName: string, data: any): Promise<any> {\r\n if (!entityName)\r\n throw new MagentrixError('Entity name is required')\r\n\r\n if (!data)\r\n throw new MagentrixError('Data is required')\r\n\r\n const path = `/api/${this.restVersion}/entity/${entityName}`\r\n \r\n return this.patchData(path, data)\r\n }\r\n\r\n async upsert(entityName: string, data: any): Promise<any> {\r\n if (!entityName)\r\n throw new MagentrixError('Entity name is required')\r\n\r\n if (!data)\r\n throw new MagentrixError('Data is required')\r\n\r\n const path = `/api/${this.restVersion}/entity/${entityName}`\r\n \r\n return this.putData(path, data)\r\n }\r\n\r\n async delete(entityName: string, id: string, permanent: boolean = false): Promise<any> {\r\n if (!id)\r\n throw new MagentrixError('ID is required')\r\n\r\n if (!entityName)\r\n throw new MagentrixError('Entity name is required')\r\n\r\n const path = `/api/${this.restVersion}/entity/${entityName}/${id}?isPermanent=${permanent}`\r\n \r\n return this.deleteData(path)\r\n }\r\n\r\n async deleteMany(entityName: string, ids: string[], permanent: boolean = false): Promise<any> {\r\n if (!ids || ids.length === 0)\r\n throw new MagentrixError('IDs are required')\r\n\r\n if (!entityName)\r\n throw new MagentrixError('Entity name is required')\r\n\r\n const path = `/api/${this.restVersion}/entity/${entityName}?isPermanent=${permanent}`\r\n \r\n return this.deleteData(path, ids)\r\n }\r\n\r\n private convertToEncodedKeyValuePairs(obj: any): string {\r\n let result = ''\r\n\r\n for (const [key, value] of Object.entries(obj)) {\r\n let modifiedValue: string\r\n\r\n if (value === null || value === undefined)\r\n modifiedValue = ''\r\n else if (typeof value === 'object')\r\n modifiedValue = JSON.stringify(value)\r\n else\r\n modifiedValue = value.toString()\r\n\r\n result += `${key}=${encodeURIComponent(modifiedValue)}&`\r\n }\r\n\r\n if (result.endsWith('&'))\r\n result = result.substring(0, result.length - 1)\r\n\r\n return result\r\n }\r\n\r\n private async getData(path: string): Promise<any> {\r\n const url = this.getFullUrl(path)\r\n const options = this.getRequestOptions()\r\n const response = await fetch(url, options)\r\n\r\n if (await this.handleAuthError(response))\r\n return this.getData(path)\r\n\r\n const result = await response.json()\r\n\r\n if (!response.ok)\r\n this.throwError(result)\r\n\r\n return result\r\n }\r\n\r\n private async postData(path: string, data: any, contentType: ContentType = ContentType.json): Promise<any> {\r\n const url = this.getFullUrl(path)\r\n const options = {\r\n ...this.getRequestOptions(RequestMethod.post, contentType),\r\n body: contentType === ContentType.json ? JSON.stringify(data) : data\r\n }\r\n const response = await fetch(url, options)\r\n\r\n if (await this.handleAuthError(response))\r\n return this.postData(path, data, contentType)\r\n\r\n const result = await response.json()\r\n\r\n if (!response.ok)\r\n this.throwError(result)\r\n\r\n this.fillIdsOnCreate(data, result)\r\n\r\n if (data?.hasOwnProperty('ModifiedOn'))\r\n data.ModifiedOn = new Date().toISOString().slice(0, -1)\r\n\r\n return result\r\n }\r\n\r\n private async patchData(path: string, data: any): Promise<any> {\r\n const url = this.getFullUrl(path)\r\n const options = {\r\n ...this.getRequestOptions(RequestMethod.patch),\r\n body: JSON.stringify(data)\r\n }\r\n const response = await fetch(url, options)\r\n\r\n if (await this.handleAuthError(response))\r\n return this.patchData(path, data)\r\n\r\n const result = await response.json()\r\n\r\n if (!response.ok)\r\n this.throwError(result)\r\n\r\n if (data?.hasOwnProperty('ModifiedOn'))\r\n data.ModifiedOn = new Date().toISOString().slice(0, -1)\r\n\r\n return result\r\n }\r\n\r\n private async putData(path: string, data: any): Promise<any> {\r\n const url = this.getFullUrl(path)\r\n const options = {\r\n ...this.getRequestOptions(RequestMethod.put),\r\n body: JSON.stringify(data)\r\n }\r\n const response = await fetch(url, options)\r\n\r\n if (await this.handleAuthError(response))\r\n return this.putData(path, data)\r\n\r\n const result = await response.json()\r\n\r\n if (!response.ok)\r\n this.throwError(result)\r\n\r\n if (!data.Id)\r\n this.fillIdsOnCreate(data, result)\r\n\r\n if (data?.hasOwnProperty('ModifiedOn'))\r\n data.ModifiedOn = new Date().toISOString().slice(0, -1)\r\n\r\n return result\r\n }\r\n\r\n private async deleteData(path: string, data: any = null): Promise<any> {\r\n const url = this.getFullUrl(path)\r\n const options = {\r\n ...this.getRequestOptions(RequestMethod.delete),\r\n body: data ? JSON.stringify(data) : null\r\n }\r\n const response = await fetch(url, options)\r\n\r\n if (await this.handleAuthError(response))\r\n return this.deleteData(path, data)\r\n\r\n const result = await response.json()\r\n\r\n if (!response.ok)\r\n this.throwError(result)\r\n\r\n return result\r\n }\r\n\r\n private getRequestOptions(\r\n method: RequestMethod = RequestMethod.get,\r\n contentType: ContentType = ContentType.json,\r\n acceptType: ContentType = ContentType.json\r\n ): RequestInit {\r\n const options: RequestInit = {\r\n method: method,\r\n headers: {\r\n 'Content-Type': contentType,\r\n 'MAG-StrictMode': 'false',\r\n 'Accept': acceptType\r\n }\r\n }\r\n\r\n if (method === RequestMethod.post && this.config.antiForgeryToken) {\r\n (options.headers as any).__RequestVerificationToken = this.config.antiForgeryToken\r\n }\r\n\r\n if (this.sessionInfo?.token) {\r\n (options.headers as any).Authorization = `Bearer ${this.sessionInfo.token}`\r\n }\r\n\r\n return options\r\n }\r\n\r\n private async handleAuthError(response: Response): Promise<boolean> {\r\n if (response.status === 401 || response.status === 403) {\r\n if (this.config.onSessionExpired) {\r\n await this.config.onSessionExpired()\r\n return true\r\n }\r\n }\r\n\r\n return false\r\n }\r\n\r\n private getFullUrl(path: string): string {\r\n if (path.startsWith('http://') || path.startsWith('https://'))\r\n return path\r\n\r\n return `${this.config.baseUrl}${path.startsWith('/') ? path : '/' + path}`\r\n }\r\n\r\n private fillIdsOnCreate(data: any | any[], result: any | any[]): void {\r\n if (data == null)\r\n return\r\n\r\n const isArray = Array.isArray(data)\r\n\r\n if (isArray) {\r\n const count = data.length\r\n\r\n if (count === 0)\r\n return\r\n\r\n for (let i = 0; i < count; i++) {\r\n if (data[i].Id === undefined && result[i].Id)\r\n data[i].Id = result[i].Id\r\n }\r\n } else {\r\n if (data.Id === undefined && result.Id)\r\n data.Id = result.Id\r\n }\r\n }\r\n\r\n private throwError(error: any): never {\r\n if (this.config.onError)\r\n this.config.onError(error)\r\n\r\n if (typeof error === 'string')\r\n throw new MagentrixError(error)\r\n else if (error.hasOwnProperty('message'))\r\n throw new MagentrixError(error.message)\r\n else if (error.hasOwnProperty('errors'))\r\n throw new DatabaseError('Database Error', error.errors)\r\n else\r\n throw new MagentrixError('Unknown error!')\r\n }\r\n}\r\n"],"names":["RequestMethod","ContentType","MagentrixError","Error","constructor","message","super","this","name","Object","setPrototypeOf","prototype","DatabaseError","errors","getErrors","hasErrors","length","MagentrixClient","config","sessionInfo","restVersion","baseUrl","replace","token","refreshToken","antiForgeryToken","onSessionExpired","onError","refresh_token","expires_in","createSession","url","body","grant_type","response","fetch","method","headers","json","JSON","stringify","ok","error","query","model","permissions","data","convertToEncodedKeyValuePairs","postData","form_url_encoded","execute","path","post","get","getData","retrieve","id","create","entityName","edit","patchData","upsert","putData","permanent","deleteData","deleteMany","ids","obj","result","key","value","entries","modifiedValue","toString","encodeURIComponent","endsWith","substring","getFullUrl","options","getRequestOptions","handleAuthError","throwError","contentType","fillIdsOnCreate","hasOwnProperty","ModifiedOn","Date","toISOString","slice","patch","put","Id","delete","acceptType","Accept","__RequestVerificationToken","Authorization","status","startsWith","Array","isArray","count","i","undefined"],"mappings":"IAAYA,EAQAC,GARZ,SAAYD,GACRA,EAAA,IAAA,MACAA,EAAA,KAAA,OACAA,EAAA,IAAA,MACAA,EAAA,MAAA,QACAA,EAAA,OAAA,QACH,CAND,CAAYA,IAAAA,EAMX,CAAA,IAED,SAAYC,GACRA,EAAA,KAAA,mBACAA,EAAA,iBAAA,oCACAA,EAAA,IAAA,kBACAA,EAAA,KAAA,YACH,CALD,CAAYA,IAAAA,EAKX,CAAA,ICbK,MAAOC,UAAuBC,MAChC,WAAAC,CAAYC,GACRC,M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AAVqF,EACA,OAEJ,IAAK,IAAIC,EAAI,EAAGA,EAAID,EAAOC,SACJC,IAAfzD,EAAKwD,GAAGX,IAAoBvB,EAAOkC,GAAGX,KACtC7C,EAAKwD,GAAGX,GAAKvB,EAAOkC,GAAGX,GAElC,WACmBY,IAAZzD,EAAK6C,IAAoBvB,EAAOuB,KAChC7C,EAAK6C,GAAKvB,EAAOuB,GAE5B,CAEO,UAAAV,CAAWvC,GAIf,MAHInC,KAAKW,OAAOS,SACZpB,KAAKW,OAAOS,QAAQe,GAEH,iBAAVA,EACD,IAAIxC,EAAewC,GACpBA,EAAM0C,eAAe,WACpB,IAAIlF,EAAewC,EAAMrC,SAC1BqC,EAAM0C,eAAe,UACpB,IAAIxE,EAAc,iBAAkB8B,EAAM7B,QAE1C,IAAIX,EAAe,iBAChC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var t,e;!function(t){t.get="GET",t.post="POST",t.put="PUT",t.patch="PATCH",t.delete="DELETE"}(t||(t={})),function(t){t.json="application/json",t.form_url_encoded="application/x-www-form-urlencoded",t.xml="application/xml",t.text="text/plain"}(e||(e={}));class r extends Error{constructor(t){super(t),this.name="MagentrixError",Object.setPrototypeOf(this,r.prototype)}}class s extends Error{errors;constructor(t,e=[]){super(t),this.name="DatabaseError",this.errors=e,Object.setPrototypeOf(this,s.prototype)}getErrors(){return this.errors}hasErrors(){return this.errors.length>0}}class n{config;sessionInfo=null;restVersion="3.0";constructor(t){this.config={baseUrl:t.baseUrl.replace(/\/$/,""),token:t.token,refreshToken:t.refreshToken,antiForgeryToken:t.antiForgeryToken,onSessionExpired:t.onSessionExpired,onError:t.onError},t.token&&(this.sessionInfo={token:t.token,refresh_token:t.refreshToken||"",expires_in:0})}async createSession(t){const s=t||this.config.refreshToken;if(!s)throw new r("Refresh token is required to create a session");const n=`${this.config.baseUrl}/api/${this.restVersion}/token`,i={grant_type:"refresh_token",refresh_token:s},o=await fetch(n,{method:"POST",headers:{"Content-Type":e.json},body:JSON.stringify(i)});if(!o.ok){const t=await o.json();throw new r(t.message||"Failed to create session")}return this.sessionInfo=await o.json(),this.sessionInfo}async query(t){if(!t)throw new r("Query is required");const s={query:t,permissions:null},n=this.convertToEncodedKeyValuePairs(s);return this.postData("/iris/query",n,e.form_url_encoded)}async execute(s,n=null,i=t.post){if(!s)throw new r("Endpoint path is required");if(i===t.get&&n)throw new r("GET requests cannot have a request body");if(i===t.get)return this.getData(s);{const t=n?this.convertToEncodedKeyValuePairs(n):null;return this.postData(s,t,e.form_url_encoded)}}async retrieve(t){if(!t)throw new r("ID is required");const e={id:t,permissions:null},s=`/iris/retrieve?${this.convertToEncodedKeyValuePairs(e)}`;return this.getData(s)}async create(t,e){if(!t)throw new r("Entity name is required");if(!e)throw new r("Data is required");const s=`/api/${this.restVersion}/entity/${t}`;return this.postData(s,e)}async edit(t,e){if(!t)throw new r("Entity name is required");if(!e)throw new r("Data is required");const s=`/api/${this.restVersion}/entity/${t}`;return this.patchData(s,e)}async upsert(t,e){if(!t)throw new r("Entity name is required");if(!e)throw new r("Data is required");const s=`/api/${this.restVersion}/entity/${t}`;return this.putData(s,e)}async delete(t,e,s=!1){if(!e)throw new r("ID is required");if(!t)throw new r("Entity name is required");const n=`/api/${this.restVersion}/entity/${t}/${e}?isPermanent=${s}`;return this.deleteData(n)}async deleteMany(t,e,s=!1){if(!e||0===e.length)throw new r("IDs are required");if(!t)throw new r("Entity name is required");const n=`/api/${this.restVersion}/entity/${t}?isPermanent=${s}`;return this.deleteData(n,e)}convertToEncodedKeyValuePairs(t){let e="";for(const[r,s]of Object.entries(t)){let t;t=null==s?"":"object"==typeof s?JSON.stringify(s):s.toString(),e+=`${r}=${encodeURIComponent(t)}&`}return e.endsWith("&")&&(e=e.substring(0,e.length-1)),e}async getData(t){const e=this.getFullUrl(t),r=this.getRequestOptions(),s=await fetch(e,r);if(await this.handleAuthError(s))return this.getData(t);const n=await s.json();return s.ok||this.throwError(n),n}async postData(r,s,n=e.json){const i=this.getFullUrl(r),o={...this.getRequestOptions(t.post,n),body:n===e.json?JSON.stringify(s):s},a=await fetch(i,o);if(await this.handleAuthError(a))return this.postData(r,s,n);const h=await a.json();return a.ok||this.throwError(h),this.fillIdsOnCreate(s,h),s?.hasOwnProperty("ModifiedOn")&&(s.ModifiedOn=(new Date).toISOString().slice(0,-1)),h}async patchData(e,r){const s=this.getFullUrl(e),n={...this.getRequestOptions(t.patch),body:JSON.stringify(r)},i=await fetch(s,n);if(await this.handleAuthError(i))return this.patchData(e,r);const o=await i.json();return i.ok||this.throwError(o),r?.hasOwnProperty("ModifiedOn")&&(r.ModifiedOn=(new Date).toISOString().slice(0,-1)),o}async putData(e,r){const s=this.getFullUrl(e),n={...this.getRequestOptions(t.put),body:JSON.stringify(r)},i=await fetch(s,n);if(await this.handleAuthError(i))return this.putData(e,r);const o=await i.json();return i.ok||this.throwError(o),r.Id||this.fillIdsOnCreate(r,o),r?.hasOwnProperty("ModifiedOn")&&(r.ModifiedOn=(new Date).toISOString().slice(0,-1)),o}async deleteData(e,r=null){const s=this.getFullUrl(e),n={...this.getRequestOptions(t.delete),body:r?JSON.stringify(r):null},i=await fetch(s,n);if(await this.handleAuthError(i))return this.deleteData(e,r);const o=await i.json();return i.ok||this.throwError(o),o}getRequestOptions(r=t.get,s=e.json,n=e.json){const i={method:r,headers:{"Content-Type":s,"MAG-StrictMode":"false",Accept:n}};return r===t.post&&this.config.antiForgeryToken&&(i.headers.__RequestVerificationToken=this.config.antiForgeryToken),this.sessionInfo?.token&&(i.headers.Authorization=`Bearer ${this.sessionInfo.token}`),i}async handleAuthError(t){return!(401!==t.status&&403!==t.status||!this.config.onSessionExpired)&&(await this.config.onSessionExpired(),!0)}getFullUrl(t){return t.startsWith("http://")||t.startsWith("https://")?t:`${this.config.baseUrl}${t.startsWith("/")?t:"/"+t}`}fillIdsOnCreate(t,e){if(null==t)return;if(Array.isArray(t)){const r=t.length;if(0===r)return;for(let s=0;s<r;s++)void 0===t[s].Id&&e[s].Id&&(t[s].Id=e[s].Id)}else void 0===t.Id&&e.Id&&(t.Id=e.Id)}throwError(t){throw this.config.onError&&this.config.onError(t),"string"==typeof t?new r(t):t.hasOwnProperty("message")?new r(t.message):t.hasOwnProperty("errors")?new s("Database Error",t.errors):new r("Unknown error!")}}function i(){return{getInstance:function(t){return new n(t)}}}export{i as useMagentrixSdk};
|
|
2
|
+
//# sourceMappingURL=useMagentrixSdk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMagentrixSdk.js","sources":["../../src/helpers/enums.ts","../../src/helpers/errors.ts","../../src/helpers/MagentrixClient.ts","../../src/vue/useMagentrixSdk.ts"],"sourcesContent":["export enum RequestMethod {\n get = 'GET',\n post = 'POST',\n put = 'PUT',\n patch = 'PATCH',\n delete = 'DELETE'\n}\n\nexport enum ContentType {\n json = 'application/json',\n form_url_encoded = 'application/x-www-form-urlencoded',\n xml = 'application/xml',\n text = 'text/plain'\n}\n","export class MagentrixError extends Error {\r\n constructor(message: string) {\r\n super(message)\r\n this.name = 'MagentrixError'\r\n Object.setPrototypeOf(this, MagentrixError.prototype)\r\n }\r\n}\r\n\r\nexport class DatabaseError extends Error {\r\n errors: any[]\r\n\r\n constructor(message: string, errors: any[] = []) {\r\n super(message)\r\n this.name = 'DatabaseError'\r\n this.errors = errors\r\n Object.setPrototypeOf(this, DatabaseError.prototype)\r\n }\r\n\r\n getErrors(): any[] {\r\n return this.errors\r\n }\r\n\r\n hasErrors(): boolean {\r\n return this.errors.length > 0\r\n }\r\n}\r\n","import { RequestMethod, ContentType } from './enums'\r\nimport { MagentrixConfig, SessionInfo } from './interfaces'\r\nimport { MagentrixError, DatabaseError } from './errors'\r\n\r\nexport class MagentrixClient {\r\n private config: MagentrixConfig\r\n private sessionInfo: SessionInfo | null = null\r\n private restVersion = '3.0'\r\n\r\n constructor(config: MagentrixConfig) {\r\n this.config = {\r\n baseUrl: config.baseUrl.replace(/\\/$/, ''),\r\n token: config.token,\r\n refreshToken: config.refreshToken,\r\n antiForgeryToken: config.antiForgeryToken,\r\n onSessionExpired: config.onSessionExpired,\r\n onError: config.onError\r\n }\r\n\r\n if (config.token) {\r\n this.sessionInfo = {\r\n token: config.token,\r\n refresh_token: config.refreshToken || '',\r\n expires_in: 0\r\n }\r\n }\r\n }\r\n\r\n async createSession(refreshToken?: string): Promise<SessionInfo> {\r\n const token = refreshToken || this.config.refreshToken\r\n\r\n if (!token)\r\n throw new MagentrixError('Refresh token is required to create a session')\r\n\r\n const url = `${this.config.baseUrl}/api/${this.restVersion}/token`\r\n const body = { grant_type: 'refresh_token', refresh_token: token }\r\n \r\n const response = await fetch(url, {\r\n method: 'POST',\r\n headers: { 'Content-Type': ContentType.json },\r\n body: JSON.stringify(body)\r\n })\r\n\r\n if (!response.ok) {\r\n const error = await response.json()\r\n throw new MagentrixError(error.message || 'Failed to create session')\r\n }\r\n\r\n this.sessionInfo = await response.json()\r\n return this.sessionInfo!\r\n }\r\n\r\n async query(query: string): Promise<any> {\r\n if (!query)\r\n throw new MagentrixError('Query is required')\r\n\r\n const path = '/iris/query'\r\n const model = { query, permissions: null }\r\n const data = this.convertToEncodedKeyValuePairs(model)\r\n \r\n return this.postData(path, data, ContentType.form_url_encoded)\r\n }\r\n\r\n async execute(path: string, model: any = null, method = RequestMethod.post): Promise<any> {\r\n if (!path)\r\n throw new MagentrixError('Endpoint path is required')\r\n\r\n if (method === RequestMethod.get && model)\r\n throw new MagentrixError('GET requests cannot have a request body')\r\n\r\n if (method === RequestMethod.get)\r\n return this.getData(path)\r\n else {\r\n const data = model ? this.convertToEncodedKeyValuePairs(model) : null\r\n return this.postData(path, data, ContentType.form_url_encoded)\r\n }\r\n }\r\n\r\n async retrieve(id: string): Promise<any> {\r\n if (!id)\r\n throw new MagentrixError('ID is required')\r\n\r\n const model = { id, permissions: null }\r\n const data = this.convertToEncodedKeyValuePairs(model)\r\n const path = `/iris/retrieve?${data}`\r\n \r\n return this.getData(path)\r\n }\r\n\r\n async create(entityName: string, data: any): Promise<any> {\r\n if (!entityName)\r\n throw new MagentrixError('Entity name is required')\r\n\r\n if (!data)\r\n throw new MagentrixError('Data is required')\r\n\r\n const path = `/api/${this.restVersion}/entity/${entityName}`\r\n \r\n return this.postData(path, data)\r\n }\r\n\r\n async edit(entityName: string, data: any): Promise<any> {\r\n if (!entityName)\r\n throw new MagentrixError('Entity name is required')\r\n\r\n if (!data)\r\n throw new MagentrixError('Data is required')\r\n\r\n const path = `/api/${this.restVersion}/entity/${entityName}`\r\n \r\n return this.patchData(path, data)\r\n }\r\n\r\n async upsert(entityName: string, data: any): Promise<any> {\r\n if (!entityName)\r\n throw new MagentrixError('Entity name is required')\r\n\r\n if (!data)\r\n throw new MagentrixError('Data is required')\r\n\r\n const path = `/api/${this.restVersion}/entity/${entityName}`\r\n \r\n return this.putData(path, data)\r\n }\r\n\r\n async delete(entityName: string, id: string, permanent: boolean = false): Promise<any> {\r\n if (!id)\r\n throw new MagentrixError('ID is required')\r\n\r\n if (!entityName)\r\n throw new MagentrixError('Entity name is required')\r\n\r\n const path = `/api/${this.restVersion}/entity/${entityName}/${id}?isPermanent=${permanent}`\r\n \r\n return this.deleteData(path)\r\n }\r\n\r\n async deleteMany(entityName: string, ids: string[], permanent: boolean = false): Promise<any> {\r\n if (!ids || ids.length === 0)\r\n throw new MagentrixError('IDs are required')\r\n\r\n if (!entityName)\r\n throw new MagentrixError('Entity name is required')\r\n\r\n const path = `/api/${this.restVersion}/entity/${entityName}?isPermanent=${permanent}`\r\n \r\n return this.deleteData(path, ids)\r\n }\r\n\r\n private convertToEncodedKeyValuePairs(obj: any): string {\r\n let result = ''\r\n\r\n for (const [key, value] of Object.entries(obj)) {\r\n let modifiedValue: string\r\n\r\n if (value === null || value === undefined)\r\n modifiedValue = ''\r\n else if (typeof value === 'object')\r\n modifiedValue = JSON.stringify(value)\r\n else\r\n modifiedValue = value.toString()\r\n\r\n result += `${key}=${encodeURIComponent(modifiedValue)}&`\r\n }\r\n\r\n if (result.endsWith('&'))\r\n result = result.substring(0, result.length - 1)\r\n\r\n return result\r\n }\r\n\r\n private async getData(path: string): Promise<any> {\r\n const url = this.getFullUrl(path)\r\n const options = this.getRequestOptions()\r\n const response = await fetch(url, options)\r\n\r\n if (await this.handleAuthError(response))\r\n return this.getData(path)\r\n\r\n const result = await response.json()\r\n\r\n if (!response.ok)\r\n this.throwError(result)\r\n\r\n return result\r\n }\r\n\r\n private async postData(path: string, data: any, contentType: ContentType = ContentType.json): Promise<any> {\r\n const url = this.getFullUrl(path)\r\n const options = {\r\n ...this.getRequestOptions(RequestMethod.post, contentType),\r\n body: contentType === ContentType.json ? JSON.stringify(data) : data\r\n }\r\n const response = await fetch(url, options)\r\n\r\n if (await this.handleAuthError(response))\r\n return this.postData(path, data, contentType)\r\n\r\n const result = await response.json()\r\n\r\n if (!response.ok)\r\n this.throwError(result)\r\n\r\n this.fillIdsOnCreate(data, result)\r\n\r\n if (data?.hasOwnProperty('ModifiedOn'))\r\n data.ModifiedOn = new Date().toISOString().slice(0, -1)\r\n\r\n return result\r\n }\r\n\r\n private async patchData(path: string, data: any): Promise<any> {\r\n const url = this.getFullUrl(path)\r\n const options = {\r\n ...this.getRequestOptions(RequestMethod.patch),\r\n body: JSON.stringify(data)\r\n }\r\n const response = await fetch(url, options)\r\n\r\n if (await this.handleAuthError(response))\r\n return this.patchData(path, data)\r\n\r\n const result = await response.json()\r\n\r\n if (!response.ok)\r\n this.throwError(result)\r\n\r\n if (data?.hasOwnProperty('ModifiedOn'))\r\n data.ModifiedOn = new Date().toISOString().slice(0, -1)\r\n\r\n return result\r\n }\r\n\r\n private async putData(path: string, data: any): Promise<any> {\r\n const url = this.getFullUrl(path)\r\n const options = {\r\n ...this.getRequestOptions(RequestMethod.put),\r\n body: JSON.stringify(data)\r\n }\r\n const response = await fetch(url, options)\r\n\r\n if (await this.handleAuthError(response))\r\n return this.putData(path, data)\r\n\r\n const result = await response.json()\r\n\r\n if (!response.ok)\r\n this.throwError(result)\r\n\r\n if (!data.Id)\r\n this.fillIdsOnCreate(data, result)\r\n\r\n if (data?.hasOwnProperty('ModifiedOn'))\r\n data.ModifiedOn = new Date().toISOString().slice(0, -1)\r\n\r\n return result\r\n }\r\n\r\n private async deleteData(path: string, data: any = null): Promise<any> {\r\n const url = this.getFullUrl(path)\r\n const options = {\r\n ...this.getRequestOptions(RequestMethod.delete),\r\n body: data ? JSON.stringify(data) : null\r\n }\r\n const response = await fetch(url, options)\r\n\r\n if (await this.handleAuthError(response))\r\n return this.deleteData(path, data)\r\n\r\n const result = await response.json()\r\n\r\n if (!response.ok)\r\n this.throwError(result)\r\n\r\n return result\r\n }\r\n\r\n private getRequestOptions(\r\n method: RequestMethod = RequestMethod.get,\r\n contentType: ContentType = ContentType.json,\r\n acceptType: ContentType = ContentType.json\r\n ): RequestInit {\r\n const options: RequestInit = {\r\n method: method,\r\n headers: {\r\n 'Content-Type': contentType,\r\n 'MAG-StrictMode': 'false',\r\n 'Accept': acceptType\r\n }\r\n }\r\n\r\n if (method === RequestMethod.post && this.config.antiForgeryToken) {\r\n (options.headers as any).__RequestVerificationToken = this.config.antiForgeryToken\r\n }\r\n\r\n if (this.sessionInfo?.token) {\r\n (options.headers as any).Authorization = `Bearer ${this.sessionInfo.token}`\r\n }\r\n\r\n return options\r\n }\r\n\r\n private async handleAuthError(response: Response): Promise<boolean> {\r\n if (response.status === 401 || response.status === 403) {\r\n if (this.config.onSessionExpired) {\r\n await this.config.onSessionExpired()\r\n return true\r\n }\r\n }\r\n\r\n return false\r\n }\r\n\r\n private getFullUrl(path: string): string {\r\n if (path.startsWith('http://') || path.startsWith('https://'))\r\n return path\r\n\r\n return `${this.config.baseUrl}${path.startsWith('/') ? path : '/' + path}`\r\n }\r\n\r\n private fillIdsOnCreate(data: any | any[], result: any | any[]): void {\r\n if (data == null)\r\n return\r\n\r\n const isArray = Array.isArray(data)\r\n\r\n if (isArray) {\r\n const count = data.length\r\n\r\n if (count === 0)\r\n return\r\n\r\n for (let i = 0; i < count; i++) {\r\n if (data[i].Id === undefined && result[i].Id)\r\n data[i].Id = result[i].Id\r\n }\r\n } else {\r\n if (data.Id === undefined && result.Id)\r\n data.Id = result.Id\r\n }\r\n }\r\n\r\n private throwError(error: any): never {\r\n if (this.config.onError)\r\n this.config.onError(error)\r\n\r\n if (typeof error === 'string')\r\n throw new MagentrixError(error)\r\n else if (error.hasOwnProperty('message'))\r\n throw new MagentrixError(error.message)\r\n else if (error.hasOwnProperty('errors'))\r\n throw new DatabaseError('Database Error', error.errors)\r\n else\r\n throw new MagentrixError('Unknown error!')\r\n }\r\n}\r\n","import { MagentrixConfig } from \"../helpers/interfaces\";\r\nimport { MagentrixClient } from \"../helpers/MagentrixClient\";\r\n\r\nexport function useMagentrixSdk() {\r\n function getInstance(config: MagentrixConfig) {\r\n return new MagentrixClient(config)\r\n }\r\n\r\n return { getInstance };\r\n}\r\n"],"names":["RequestMethod","ContentType","MagentrixError","Error","constructor","message","super","this","name","Object","setPrototypeOf","prototype","DatabaseError","errors","getErrors","hasErrors","length","MagentrixClient","config","sessionInfo","restVersion","baseUrl","replace","token","refreshToken","antiForgeryToken","onSessionExpired","onError","refresh_token","expires_in","createSession","url","body","grant_type","response","fetch","method","headers","json","JSON","stringify","ok","error","query","model","permissions","data","convertToEncodedKeyValuePairs","postData","form_url_encoded","execute","path","post","get","getData","retrieve","id","create","entityName","edit","patchData","upsert","putData","permanent","deleteData","deleteMany","ids","obj","result","key","value","entries","modifiedValue","toString","encodeURIComponent","endsWith","substring","getFullUrl","options","getRequestOptions","handleAuthError","throwError","contentType","fillIdsOnCreate","hasOwnProperty","ModifiedOn","Date","toISOString","slice","patch","put","Id","delete","acceptType","Accept","__RequestVerificationToken","Authorization","status","startsWith","Array","isArray","count","i","undefined","useMagentrixSdk","getInstance"],"mappings":"AAAA,IAAYA,EAQAC,GARZ,SAAYD,GACRA,EAAA,IAAA,MACAA,EAAA,KAAA,OACAA,EAAA,IAAA,MACAA,EAAA,MAAA,QACAA,EAA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J,GAAG5C,KAAKW,OAAOG,UAAU8B,EAAK+C,WAAW,KAAO/C,EAAO,IAAMA,GACvE,CAEO,eAAAgC,CAAgBrC,EAAmBsB,GACvC,GAAY,MAARtB,EACA,OAIJ,GAFgBqD,MAAMC,QAAQtD,GAEjB,CACT,MAAMuD,EAAQvD,EAAK9B,OAEnB,GAAc,IAAVqF,EACA,OAEJ,IAAK,IAAIC,EAAI,EAAGA,EAAID,EAAOC,SACJC,IAAfzD,EAAKwD,GAAGX,IAAoBvB,EAAOkC,GAAGX,KACtC7C,EAAKwD,GAAGX,GAAKvB,EAAOkC,GAAGX,GAElC,WACmBY,IAAZzD,EAAK6C,IAAoBvB,EAAOuB,KAChC7C,EAAK6C,GAAKvB,EAAOuB,GAE5B,CAEO,UAAAV,CAAWvC,GAIf,MAHInC,KAAKW,OAAOS,SACZpB,KAAKW,OAAOS,QAAQe,GAEH,iBAAVA,EACD,IAAIxC,EAAewC,GACpBA,EAAM0C,eAAe,WACpB,IAAIlF,EAAewC,EAAMrC,SAC1BqC,EAAM0C,eAAe,UACpB,IAAIxE,EAAc,iBAAkB8B,EAAM7B,QAE1C,IAAIX,EAAe,iBAChC,WC/VWsG,IAKd,MAAO,CAAEC,YAJT,SAAqBvF,GACnB,OAAO,IAAID,EAAgBC,EAC5B,EAGH"}
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@magentrix-corp/magentrix-sdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "dist/index.cjs.js",
|
|
6
|
+
"module": "dist/index.js",
|
|
7
|
+
"types": "dist/types/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"require": "./dist/index.cjs.js"
|
|
12
|
+
},
|
|
13
|
+
"./vue": {
|
|
14
|
+
"import": "./dist/vue/useMagentrixSdk.js",
|
|
15
|
+
"require": "./dist/vue/useMagentrixSdk.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "rollup -c"
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"vue": "^3.5.22"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@rollup/plugin-commonjs": "^29.0.0",
|
|
29
|
+
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
30
|
+
"@rollup/plugin-typescript": "^12.3.0",
|
|
31
|
+
"rollup": "^2.79.2",
|
|
32
|
+
"rollup-plugin-copy": "^3.5.0",
|
|
33
|
+
"rollup-plugin-terser": "^7.0.2",
|
|
34
|
+
"typescript": "^5.9.3"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"tslib": "^2.8.1"
|
|
38
|
+
}
|
|
39
|
+
}
|