twenty-client-sdk 2.18.0 → 2.19.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/dist/rest.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("./application-DB3rje-9.js");var t=e=>e!=null,n=class extends Error{constructor(e,t){super(e),this.name=`RestApiClientError`,this.status=t?.status,this.statusText=t?.statusText,this.url=t?.url,this.body=t?.body}},r=()=>globalThis.process?.env??{},i=(e,n,r)=>{let i=/^https?:\/\//i.test(n)?n:`${e}${n.startsWith(`/`)?``:`/`}${n}`;if(!t(r))return i;let a=new URLSearchParams;for(let[e,n]of Object.entries(r))t(n)&&a.append(e,String(n));let o=a.toString();return o.length===0?i:i.includes(`?`)?`${i}&${o}`:`${i}?${o}`},a=class{constructor(e){this.refreshAccessTokenPromise=null,this.baseUrl=e?.baseUrl,this.token=e?.token,this.defaultHeaders=e?.defaultHeaders,this.fetchImplementation=e?.fetch??globalThis.fetch??null,this.authorizationToken=e?.token??null}request(e,t,n){return this.execute(e,t,n?.body,n)}get(e,t){return this.execute(`GET`,e,void 0,t)}post(e,t,n){return this.execute(`POST`,e,t,n)}put(e,t,n){return this.execute(`PUT`,e,t,n)}patch(e,t,n){return this.execute(`PATCH`,e,t,n)}delete(e,t){return this.execute(`DELETE`,e,void 0,t)}resolveBaseUrl(){let i=this.baseUrl??r().TWENTY_API_URL;if(!t(i)||i.trim().length===0)throw new n(`Missing API url. Set the \`${e.n}\` environment variable or pass \`baseUrl\` to \`RestApiClient\`.`);return i.replace(/\/+$/,``)}resolveToken(){if(!t(this.authorizationToken)){let e=r();this.authorizationToken=this.token??e.TWENTY_APP_ACCESS_TOKEN??e.TWENTY_API_KEY??null}if(!t(this.authorizationToken)||this.authorizationToken.length===0)throw new n(`Missing application access token. Set the \`${e.t}\` environment variable or pass \`token\` to \`RestApiClient\`.`);return this.authorizationToken}async requestRefreshedAccessToken(){let t=globalThis.frontComponentHostCommunicationApi?.requestAccessTokenRefresh;return typeof t==`function`?(this.refreshAccessTokenPromise||=t().then(t=>typeof t!=`string`||t.length===0?null:(this.authorizationToken=t,r()[e.t]=t,t)).catch(e=>(console.error(`Twenty REST client: token refresh failed`,e),null)).finally(()=>{this.refreshAccessTokenPromise=null}),this.refreshAccessTokenPromise):null}sendRequest(e,r,i,a,o){if(!t(this.fetchImplementation))throw new n("Global `fetch` function is not available, pass a fetch implementation to `RestApiClient`.");let s=new Headers(this.defaultHeaders);t(o?.headers)&&new Headers(o.headers).forEach((e,t)=>s.set(t,e));let c=typeof FormData<`u`&&i instanceof FormData,l=t(i)&&!c&&typeof i!=`string`;c?s.delete(`Content-Type`):l&&s.set(`Content-Type`,`application/json`),s.set(`Authorization`,`Bearer ${a}`);let u=t(i)?c||typeof i==`string`?i:JSON.stringify(i):void 0;return this.fetchImplementation.call(globalThis,e,{method:r,headers:s,body:u,signal:o?.signal})}async parseResponse(e,t){let r=await e.text(),i;if(r.trim().length>0)try{i=JSON.parse(r)}catch{i=r}if(!e.ok)throw new n(`Request to ${t} failed with status ${e.status} ${e.statusText}`,{status:e.status,statusText:e.statusText,url:t,body:i});return i}async execute(e,n,r,a){let o=i(this.resolveBaseUrl(),n,a?.query),s=this.resolveToken(),c=await this.sendRequest(o,e,r,s,a);if(c.status===401){let n=await this.requestRefreshedAccessToken();t(n)&&(c=await this.sendRequest(o,e,r,n,a))}return this.parseResponse(c,o)}};exports.RestApiClient=a,exports.RestApiClientError=n;
1
+ Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("./application-CsXssff9.js");var t=e=>e!=null,n=class extends Error{constructor(e,t){super(e),this.name=`RestApiClientError`,this.status=t?.status,this.statusText=t?.statusText,this.url=t?.url,this.body=t?.body}},r=()=>globalThis.process?.env??{},i=(e,n,r)=>{let i=/^https?:\/\//i.test(n)?n:`${e}${n.startsWith(`/`)?``:`/`}${n}`;if(!t(r))return i;let a=new URLSearchParams;for(let[e,n]of Object.entries(r))t(n)&&a.append(e,String(n));let o=a.toString();return o.length===0?i:i.includes(`?`)?`${i}&${o}`:`${i}?${o}`},a=class{constructor(e){this.refreshAccessTokenPromise=null,this.baseUrl=e?.baseUrl,this.token=e?.token,this.defaultHeaders=e?.defaultHeaders,this.fetchImplementation=e?.fetch??globalThis.fetch??null,this.authorizationToken=e?.token??null}request(e,t,n){return this.execute(e,t,n?.body,n)}get(e,t){return this.execute(`GET`,e,void 0,t)}post(e,t,n){return this.execute(`POST`,e,t,n)}put(e,t,n){return this.execute(`PUT`,e,t,n)}patch(e,t,n){return this.execute(`PATCH`,e,t,n)}delete(e,t){return this.execute(`DELETE`,e,void 0,t)}resolveBaseUrl(){let i=this.baseUrl??r().TWENTY_API_URL;if(!t(i)||i.trim().length===0)throw new n(`Missing API url. Set the \`${e.t}\` environment variable or pass \`baseUrl\` to \`RestApiClient\`.`);return i.replace(/\/+$/,``)}resolveToken(){if(!t(this.authorizationToken)){let e=r();this.authorizationToken=this.token??e.TWENTY_APP_ACCESS_TOKEN??e.TWENTY_API_KEY??null}if(!t(this.authorizationToken)||this.authorizationToken.length===0)throw new n(`Missing application access token. Set the \`${e.n}\` environment variable or pass \`token\` to \`RestApiClient\`.`);return this.authorizationToken}async requestRefreshedAccessToken(){let t=globalThis.frontComponentHostCommunicationApi?.requestAccessTokenRefresh;return typeof t==`function`?(this.refreshAccessTokenPromise||=t().then(t=>typeof t!=`string`||t.length===0?null:(this.authorizationToken=t,r()[e.n]=t,t)).catch(e=>(console.error(`Twenty REST client: token refresh failed`,e),null)).finally(()=>{this.refreshAccessTokenPromise=null}),this.refreshAccessTokenPromise):null}sendRequest(e,r,i,a,o){if(!t(this.fetchImplementation))throw new n("Global `fetch` function is not available, pass a fetch implementation to `RestApiClient`.");let s=new Headers(this.defaultHeaders);t(o?.headers)&&new Headers(o.headers).forEach((e,t)=>s.set(t,e));let c=typeof FormData<`u`&&i instanceof FormData,l=t(i)&&!c&&typeof i!=`string`;c?s.delete(`Content-Type`):l&&s.set(`Content-Type`,`application/json`),s.set(`Authorization`,`Bearer ${a}`);let u=t(i)?c||typeof i==`string`?i:JSON.stringify(i):void 0;return this.fetchImplementation.call(globalThis,e,{method:r,headers:s,body:u,signal:o?.signal})}async parseResponse(e,t){let r=await e.text(),i;if(r.trim().length>0)try{i=JSON.parse(r)}catch{i=r}if(!e.ok)throw new n(`Request to ${t} failed with status ${e.status} ${e.statusText}`,{status:e.status,statusText:e.statusText,url:t,body:i});return i}async execute(e,n,r,a){let o=i(this.resolveBaseUrl(),n,a?.query),s=this.resolveToken(),c=await this.sendRequest(o,e,r,s,a);if(c.status===401){let n=await this.requestRefreshedAccessToken();t(n)&&(c=await this.sendRequest(o,e,r,n,a))}return this.parseResponse(c,o)}};exports.RestApiClient=a,exports.RestApiClientError=n;
package/dist/rest.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { n as e, t } from "./application-CbP6KYwU.mjs";
1
+ import { n as e, t } from "./application-DLgc8j8d.mjs";
2
2
  //#region src/rest/index.ts
3
3
  var n = (e) => e != null, r = class extends Error {
4
4
  constructor(e, t) {
@@ -34,21 +34,21 @@ var n = (e) => e != null, r = class extends Error {
34
34
  return this.execute("DELETE", e, void 0, t);
35
35
  }
36
36
  resolveBaseUrl() {
37
- let t = this.baseUrl ?? i().TWENTY_API_URL;
38
- if (!n(t) || t.trim().length === 0) throw new r(`Missing API url. Set the \`${e}\` environment variable or pass \`baseUrl\` to \`RestApiClient\`.`);
39
- return t.replace(/\/+$/, "");
37
+ let e = this.baseUrl ?? i().TWENTY_API_URL;
38
+ if (!n(e) || e.trim().length === 0) throw new r(`Missing API url. Set the \`${t}\` environment variable or pass \`baseUrl\` to \`RestApiClient\`.`);
39
+ return e.replace(/\/+$/, "");
40
40
  }
41
41
  resolveToken() {
42
42
  if (!n(this.authorizationToken)) {
43
43
  let e = i();
44
44
  this.authorizationToken = this.token ?? e.TWENTY_APP_ACCESS_TOKEN ?? e.TWENTY_API_KEY ?? null;
45
45
  }
46
- if (!n(this.authorizationToken) || this.authorizationToken.length === 0) throw new r(`Missing application access token. Set the \`${t}\` environment variable or pass \`token\` to \`RestApiClient\`.`);
46
+ if (!n(this.authorizationToken) || this.authorizationToken.length === 0) throw new r(`Missing application access token. Set the \`${e}\` environment variable or pass \`token\` to \`RestApiClient\`.`);
47
47
  return this.authorizationToken;
48
48
  }
49
49
  async requestRefreshedAccessToken() {
50
- let e = globalThis.frontComponentHostCommunicationApi?.requestAccessTokenRefresh;
51
- return typeof e == "function" ? (this.refreshAccessTokenPromise ||= e().then((e) => typeof e != "string" || e.length === 0 ? null : (this.authorizationToken = e, i()[t] = e, e)).catch((e) => (console.error("Twenty REST client: token refresh failed", e), null)).finally(() => {
50
+ let t = globalThis.frontComponentHostCommunicationApi?.requestAccessTokenRefresh;
51
+ return typeof t == "function" ? (this.refreshAccessTokenPromise ||= t().then((t) => typeof t != "string" || t.length === 0 ? null : (this.authorizationToken = t, i()[e] = t, t)).catch((e) => (console.error("Twenty REST client: token refresh failed", e), null)).finally(() => {
52
52
  this.refreshAccessTokenPromise = null;
53
53
  }), this.refreshAccessTokenPromise) : null;
54
54
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "twenty-client-sdk",
3
- "version": "2.18.0",
3
+ "version": "2.19.0",
4
4
  "sideEffects": false,
5
5
  "license": "AGPL-3.0",
6
6
  "scripts": {
@@ -1,99 +0,0 @@
1
- //#region ../twenty-shared/dist/ViewKey-Dib-Wyry.mjs
2
- var e = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i;
3
- //#endregion
4
- //#region ../../node_modules/uuid/dist/esm-browser/validate.js
5
- function t(t) {
6
- return typeof t == "string" && e.test(t);
7
- }
8
- //#endregion
9
- //#region ../../node_modules/uuid/dist/esm-browser/parse.js
10
- function n(e) {
11
- if (!t(e)) throw TypeError("Invalid UUID");
12
- let n;
13
- return Uint8Array.of((n = parseInt(e.slice(0, 8), 16)) >>> 24, n >>> 16 & 255, n >>> 8 & 255, n & 255, (n = parseInt(e.slice(9, 13), 16)) >>> 8, n & 255, (n = parseInt(e.slice(14, 18), 16)) >>> 8, n & 255, (n = parseInt(e.slice(19, 23), 16)) >>> 8, n & 255, (n = parseInt(e.slice(24, 36), 16)) / 1099511627776 & 255, n / 4294967296 & 255, n >>> 24 & 255, n >>> 16 & 255, n >>> 8 & 255, n & 255);
14
- }
15
- //#endregion
16
- //#region ../../node_modules/uuid/dist/esm-browser/stringify.js
17
- var r = [];
18
- for (let e = 0; e < 256; ++e) r.push((e + 256).toString(16).slice(1));
19
- function i(e, t = 0) {
20
- return (r[e[t + 0]] + r[e[t + 1]] + r[e[t + 2]] + r[e[t + 3]] + "-" + r[e[t + 4]] + r[e[t + 5]] + "-" + r[e[t + 6]] + r[e[t + 7]] + "-" + r[e[t + 8]] + r[e[t + 9]] + "-" + r[e[t + 10]] + r[e[t + 11]] + r[e[t + 12]] + r[e[t + 13]] + r[e[t + 14]] + r[e[t + 15]]).toLowerCase();
21
- }
22
- //#endregion
23
- //#region ../../node_modules/uuid/dist/esm-browser/v35.js
24
- function a(e) {
25
- e = unescape(encodeURIComponent(e));
26
- let t = new Uint8Array(e.length);
27
- for (let n = 0; n < e.length; ++n) t[n] = e.charCodeAt(n);
28
- return t;
29
- }
30
- var o = "6ba7b810-9dad-11d1-80b4-00c04fd430c8", s = "6ba7b811-9dad-11d1-80b4-00c04fd430c8";
31
- function c(e, t, r, o, s, c) {
32
- let l = typeof r == "string" ? a(r) : r, u = typeof o == "string" ? n(o) : o;
33
- if (typeof o == "string" && (o = n(o)), o?.length !== 16) throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");
34
- let d = new Uint8Array(16 + l.length);
35
- if (d.set(u), d.set(l, u.length), d = t(d), d[6] = d[6] & 15 | e, d[8] = d[8] & 63 | 128, s) {
36
- if (c ||= 0, c < 0 || c + 16 > s.length) throw RangeError(`UUID byte range ${c}:${c + 15} is out of buffer bounds`);
37
- for (let e = 0; e < 16; ++e) s[c + e] = d[e];
38
- return s;
39
- }
40
- return i(d);
41
- }
42
- //#endregion
43
- //#region ../../node_modules/uuid/dist/esm-browser/sha1.js
44
- function l(e, t, n, r) {
45
- switch (e) {
46
- case 0: return t & n ^ ~t & r;
47
- case 1: return t ^ n ^ r;
48
- case 2: return t & n ^ t & r ^ n & r;
49
- case 3: return t ^ n ^ r;
50
- }
51
- }
52
- function u(e, t) {
53
- return e << t | e >>> 32 - t;
54
- }
55
- function d(e) {
56
- let t = [
57
- 1518500249,
58
- 1859775393,
59
- 2400959708,
60
- 3395469782
61
- ], n = [
62
- 1732584193,
63
- 4023233417,
64
- 2562383102,
65
- 271733878,
66
- 3285377520
67
- ], r = new Uint8Array(e.length + 1);
68
- r.set(e), r[e.length] = 128, e = r;
69
- let i = e.length / 4 + 2, a = Math.ceil(i / 16), o = Array(a);
70
- for (let t = 0; t < a; ++t) {
71
- let n = new Uint32Array(16);
72
- for (let r = 0; r < 16; ++r) n[r] = e[t * 64 + r * 4] << 24 | e[t * 64 + r * 4 + 1] << 16 | e[t * 64 + r * 4 + 2] << 8 | e[t * 64 + r * 4 + 3];
73
- o[t] = n;
74
- }
75
- o[a - 1][14] = (e.length - 1) * 8 / 2 ** 32, o[a - 1][14] = Math.floor(o[a - 1][14]), o[a - 1][15] = (e.length - 1) * 8 & 4294967295;
76
- for (let e = 0; e < a; ++e) {
77
- let r = new Uint32Array(80);
78
- for (let t = 0; t < 16; ++t) r[t] = o[e][t];
79
- for (let e = 16; e < 80; ++e) r[e] = u(r[e - 3] ^ r[e - 8] ^ r[e - 14] ^ r[e - 16], 1);
80
- let i = n[0], a = n[1], s = n[2], c = n[3], d = n[4];
81
- for (let e = 0; e < 80; ++e) {
82
- let n = Math.floor(e / 20), o = u(i, 5) + l(n, a, s, c) + d + t[n] + r[e] >>> 0;
83
- d = c, c = s, s = u(a, 30) >>> 0, a = i, i = o;
84
- }
85
- n[0] = n[0] + i >>> 0, n[1] = n[1] + a >>> 0, n[2] = n[2] + s >>> 0, n[3] = n[3] + c >>> 0, n[4] = n[4] + d >>> 0;
86
- }
87
- return Uint8Array.of(n[0] >> 24, n[0] >> 16, n[0] >> 8, n[0], n[1] >> 24, n[1] >> 16, n[1] >> 8, n[1], n[2] >> 24, n[2] >> 16, n[2] >> 8, n[2], n[3] >> 24, n[3] >> 16, n[3] >> 8, n[3], n[4] >> 24, n[4] >> 16, n[4] >> 8, n[4]);
88
- }
89
- //#endregion
90
- //#region ../../node_modules/uuid/dist/esm-browser/v5.js
91
- function f(e, t, n, r) {
92
- return c(80, d, e, t, n, r);
93
- }
94
- f.DNS = o, f.URL = s;
95
- //#endregion
96
- //#region ../twenty-shared/dist/application.mjs
97
- var p = "TWENTY_API_KEY", m = "TWENTY_API_URL", h = "TWENTY_APP_ACCESS_TOKEN";
98
- //#endregion
99
- export { m as n, p as r, h as t };
@@ -1 +0,0 @@
1
- var e=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i;function t(t){return typeof t==`string`&&e.test(t)}function n(e){if(!t(e))throw TypeError(`Invalid UUID`);let n;return Uint8Array.of((n=parseInt(e.slice(0,8),16))>>>24,n>>>16&255,n>>>8&255,n&255,(n=parseInt(e.slice(9,13),16))>>>8,n&255,(n=parseInt(e.slice(14,18),16))>>>8,n&255,(n=parseInt(e.slice(19,23),16))>>>8,n&255,(n=parseInt(e.slice(24,36),16))/1099511627776&255,n/4294967296&255,n>>>24&255,n>>>16&255,n>>>8&255,n&255)}var r=[];for(let e=0;e<256;++e)r.push((e+256).toString(16).slice(1));function i(e,t=0){return(r[e[t+0]]+r[e[t+1]]+r[e[t+2]]+r[e[t+3]]+`-`+r[e[t+4]]+r[e[t+5]]+`-`+r[e[t+6]]+r[e[t+7]]+`-`+r[e[t+8]]+r[e[t+9]]+`-`+r[e[t+10]]+r[e[t+11]]+r[e[t+12]]+r[e[t+13]]+r[e[t+14]]+r[e[t+15]]).toLowerCase()}function a(e){e=unescape(encodeURIComponent(e));let t=new Uint8Array(e.length);for(let n=0;n<e.length;++n)t[n]=e.charCodeAt(n);return t}var o=`6ba7b810-9dad-11d1-80b4-00c04fd430c8`,s=`6ba7b811-9dad-11d1-80b4-00c04fd430c8`;function c(e,t,r,o,s,c){let l=typeof r==`string`?a(r):r,u=typeof o==`string`?n(o):o;if(typeof o==`string`&&(o=n(o)),o?.length!==16)throw TypeError(`Namespace must be array-like (16 iterable integer values, 0-255)`);let d=new Uint8Array(16+l.length);if(d.set(u),d.set(l,u.length),d=t(d),d[6]=d[6]&15|e,d[8]=d[8]&63|128,s){if(c||=0,c<0||c+16>s.length)throw RangeError(`UUID byte range ${c}:${c+15} is out of buffer bounds`);for(let e=0;e<16;++e)s[c+e]=d[e];return s}return i(d)}function l(e,t,n,r){switch(e){case 0:return t&n^~t&r;case 1:return t^n^r;case 2:return t&n^t&r^n&r;case 3:return t^n^r}}function u(e,t){return e<<t|e>>>32-t}function d(e){let t=[1518500249,1859775393,2400959708,3395469782],n=[1732584193,4023233417,2562383102,271733878,3285377520],r=new Uint8Array(e.length+1);r.set(e),r[e.length]=128,e=r;let i=e.length/4+2,a=Math.ceil(i/16),o=Array(a);for(let t=0;t<a;++t){let n=new Uint32Array(16);for(let r=0;r<16;++r)n[r]=e[t*64+r*4]<<24|e[t*64+r*4+1]<<16|e[t*64+r*4+2]<<8|e[t*64+r*4+3];o[t]=n}o[a-1][14]=(e.length-1)*8/2**32,o[a-1][14]=Math.floor(o[a-1][14]),o[a-1][15]=(e.length-1)*8&4294967295;for(let e=0;e<a;++e){let r=new Uint32Array(80);for(let t=0;t<16;++t)r[t]=o[e][t];for(let e=16;e<80;++e)r[e]=u(r[e-3]^r[e-8]^r[e-14]^r[e-16],1);let i=n[0],a=n[1],s=n[2],c=n[3],d=n[4];for(let e=0;e<80;++e){let n=Math.floor(e/20),o=u(i,5)+l(n,a,s,c)+d+t[n]+r[e]>>>0;d=c,c=s,s=u(a,30)>>>0,a=i,i=o}n[0]=n[0]+i>>>0,n[1]=n[1]+a>>>0,n[2]=n[2]+s>>>0,n[3]=n[3]+c>>>0,n[4]=n[4]+d>>>0}return Uint8Array.of(n[0]>>24,n[0]>>16,n[0]>>8,n[0],n[1]>>24,n[1]>>16,n[1]>>8,n[1],n[2]>>24,n[2]>>16,n[2]>>8,n[2],n[3]>>24,n[3]>>16,n[3]>>8,n[3],n[4]>>24,n[4]>>16,n[4]>>8,n[4])}function f(e,t,n,r){return c(80,d,e,t,n,r)}f.DNS=o,f.URL=s;var p=`TWENTY_API_KEY`,m=`TWENTY_API_URL`,h=`TWENTY_APP_ACCESS_TOKEN`;Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return h}});