twenty-client-sdk 2.46.0 → 2.48.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/{application-C_qFrGob.mjs → application-BmgukPzb.mjs} +4748 -4517
- package/dist/{application-Y3WdAYqg.js → application-gV7J_BKH.js} +23 -21
- package/dist/generate.cjs +3 -3
- package/dist/generate.mjs +1 -1
- package/dist/metadata/generated/schema.d.ts +133 -12
- package/dist/metadata/generated/types.d.ts +58 -1
- package/dist/metadata.cjs +2 -2
- package/dist/metadata.mjs +3149 -3067
- package/dist/rest.cjs +1 -1
- package/dist/rest.mjs +10 -10
- package/package.json +1 -1
package/dist/rest.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("./application-
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("./application-gV7J_BKH.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=>/^\/?s\//.test(e),a=e=>e.replace(/^(\/?)s\//,`$1`),o=(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}`},s=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,this.runAs=e?.runAs}request(e,t,n){return this.execute(e,t,n?.body,n)}get(e,t){return this.execute(`GET`,e,void 0,t)}resolveUrl(e,t){let n=this.resolveTarget(e);return o(n.baseUrl,n.path,t?.query)}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.i}\` environment variable or pass \`baseUrl\` to \`RestApiClient\`.`);return i.replace(/\/+$/,``)}resolveFunctionsBaseUrl(){let n=r()[e.a];if(!(!t(n)||n.trim().length===0))return n.trim().replace(/\/+$/,``)}resolveTarget(e){return t(this.baseUrl)||!i(e)?{baseUrl:this.resolveBaseUrl(),path:e}:{baseUrl:this.resolveFunctionsBaseUrl()??`${this.resolveBaseUrl()}/s`,path:a(e)}}resolveToken(){let i=this.runAs===`application`?e.t:e.n;if(!t(this.authorizationToken)){let e=r();this.authorizationToken=this.token??e[i]??e.TWENTY_API_KEY??null}if(!t(this.authorizationToken)||this.authorizationToken.length===0)throw new n(`Missing application access token. Set the \`${i}\` 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,i){let a=this.resolveTarget(n),s=o(a.baseUrl,a.path,i?.query),c=this.resolveToken(),l=await this.sendRequest(s,e,r,c,i);if(l.status===401){let n=await this.requestRefreshedAccessToken();t(n)&&(l=await this.sendRequest(s,e,r,n,i))}return this.parseResponse(l,s)}};exports.RestApiClient=s,exports.RestApiClientError=n;
|
package/dist/rest.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as e, i as t, n, t as r } from "./application-BmgukPzb.mjs";
|
|
2
2
|
//#region src/rest/index.ts
|
|
3
3
|
var i = (e) => e != null, a = class extends Error {
|
|
4
4
|
constructor(e, t) {
|
|
@@ -39,12 +39,12 @@ var i = (e) => e != null, a = class extends Error {
|
|
|
39
39
|
}
|
|
40
40
|
resolveBaseUrl() {
|
|
41
41
|
let e = this.baseUrl ?? o().TWENTY_API_URL;
|
|
42
|
-
if (!i(e) || e.trim().length === 0) throw new a(`Missing API url. Set the \`${
|
|
42
|
+
if (!i(e) || e.trim().length === 0) throw new a(`Missing API url. Set the \`${t}\` environment variable or pass \`baseUrl\` to \`RestApiClient\`.`);
|
|
43
43
|
return e.replace(/\/+$/, "");
|
|
44
44
|
}
|
|
45
45
|
resolveFunctionsBaseUrl() {
|
|
46
|
-
let
|
|
47
|
-
if (!(!i(
|
|
46
|
+
let t = o()[e];
|
|
47
|
+
if (!(!i(t) || t.trim().length === 0)) return t.trim().replace(/\/+$/, "");
|
|
48
48
|
}
|
|
49
49
|
resolveTarget(e) {
|
|
50
50
|
return i(this.baseUrl) || !s(e) ? {
|
|
@@ -56,17 +56,17 @@ var i = (e) => e != null, a = class extends Error {
|
|
|
56
56
|
};
|
|
57
57
|
}
|
|
58
58
|
resolveToken() {
|
|
59
|
-
let
|
|
59
|
+
let e = this.runAs === "application" ? r : n;
|
|
60
60
|
if (!i(this.authorizationToken)) {
|
|
61
|
-
let
|
|
62
|
-
this.authorizationToken = this.token ?? e
|
|
61
|
+
let t = o();
|
|
62
|
+
this.authorizationToken = this.token ?? t[e] ?? t.TWENTY_API_KEY ?? null;
|
|
63
63
|
}
|
|
64
|
-
if (!i(this.authorizationToken) || this.authorizationToken.length === 0) throw new a(`Missing application access token. Set the \`${
|
|
64
|
+
if (!i(this.authorizationToken) || this.authorizationToken.length === 0) throw new a(`Missing application access token. Set the \`${e}\` environment variable or pass \`token\` to \`RestApiClient\`.`);
|
|
65
65
|
return this.authorizationToken;
|
|
66
66
|
}
|
|
67
67
|
async requestRefreshedAccessToken() {
|
|
68
|
-
let
|
|
69
|
-
return typeof
|
|
68
|
+
let e = globalThis.frontComponentHostCommunicationApi?.requestAccessTokenRefresh;
|
|
69
|
+
return typeof e == "function" ? (this.refreshAccessTokenPromise ||= e().then((e) => typeof e != "string" || e.length === 0 ? null : (this.authorizationToken = e, o()[n] = e, e)).catch((e) => (console.error("Twenty REST client: token refresh failed", e), null)).finally(() => {
|
|
70
70
|
this.refreshAccessTokenPromise = null;
|
|
71
71
|
}), this.refreshAccessTokenPromise) : null;
|
|
72
72
|
}
|