twenty-sdk 2.1.0 → 2.3.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 +3 -3
- package/dist/billing/index.cjs.map +1 -1
- package/dist/billing/index.mjs +9 -9
- package/dist/billing/index.mjs.map +1 -1
- package/dist/cli/commands/add.d.ts +1 -0
- package/dist/cli/operations/deploy.d.ts +2 -0
- package/dist/cli/operations/index.d.ts +3 -0
- package/dist/cli/operations/server-upgrade.d.ts +12 -0
- package/dist/cli/types.d.ts +2 -0
- package/dist/cli/utilities/build/manifest/manifest-extract-config.d.ts +6 -2
- package/dist/cli/utilities/entity/entity-command-menu-item-template.d.ts +3 -0
- package/dist/cli/utilities/entity/entity-connection-provider-template.d.ts +4 -0
- package/dist/cli/utilities/file/append-server-variables.util.d.ts +22 -0
- package/dist/cli/utilities/server/docker-container.d.ts +5 -0
- package/dist/cli.cjs +147 -105
- package/dist/cli.mjs +3213 -3023
- package/dist/define/index.cjs +16 -16
- package/dist/define/index.cjs.map +1 -1
- package/dist/define/index.d.ts +73 -35
- package/dist/define/index.mjs +3386 -6646
- package/dist/define/index.mjs.map +1 -1
- package/dist/front-component/index.cjs +15 -15
- package/dist/front-component/index.cjs.map +1 -1
- package/dist/front-component/index.d.ts +12 -1
- package/dist/front-component/index.mjs +3274 -6566
- package/dist/front-component/index.mjs.map +1 -1
- package/dist/{get-function-input-schema-BZ7_XyUh-D38OurwZ.js → get-function-input-schema-BZ7_XyUh-BXB2AcBE.js} +1 -1
- package/dist/{get-function-input-schema-BZ7_XyUh-CKgoFzji.mjs → get-function-input-schema-BZ7_XyUh-PnCntsct.mjs} +1 -1
- package/dist/logic-function/index.cjs +1 -1
- package/dist/logic-function/index.cjs.map +1 -1
- package/dist/logic-function/index.d.ts +91 -20
- package/dist/logic-function/index.mjs +52 -1
- package/dist/logic-function/index.mjs.map +1 -1
- package/dist/operations.cjs +1 -1
- package/dist/operations.mjs +24 -18
- package/dist/ui/index.cjs +36 -2234
- package/dist/ui/index.mjs +11051 -17373
- package/dist/uninstall-BiLmSWhb.js +253 -0
- package/dist/{uninstall-Bw-TK4rL.mjs → uninstall-DAf2XiS3.mjs} +5064 -8113
- package/package.json +6 -2
- package/dist/uninstall-CYiYoBPe.js +0 -250
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("typescript"),o=require("./uninstall-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("typescript"),o=require("./uninstall-BiLmSWhb.js"),c=n=>{switch(n.kind){case e.SyntaxKind.NumberKeyword:return{type:"number"};case e.SyntaxKind.StringKeyword:return{type:"string"};case e.SyntaxKind.BooleanKeyword:return{type:"boolean"};case e.SyntaxKind.ArrayType:return{type:"array",items:c(n.elementType)};case e.SyntaxKind.ObjectKeyword:return{type:"object"};case e.SyntaxKind.TypeLiteral:{const i={};return n.members.forEach(t=>{if(o.o(t.name)&&o.o(t.type)){const r=t.name.text;i[r]=c(t.type)}}),{type:"object",properties:i}}case e.SyntaxKind.UnionType:{const i=n,t=[];let r=!0;return i.types.forEach(a=>{if(a.kind===e.SyntaxKind.LiteralType){const y=a.literal;y.kind===e.SyntaxKind.StringLiteral?t.push(y.text):r=!1}else r=!1}),r?{type:"string",enum:t}:{}}default:return{}}},s=(n,i)=>n.parameters.reduce((t,r)=>{const a=r.type;return o.o(a)?[...t,c(a)]:[...t,{}]},i),d=n=>n.kind===e.SyntaxKind.FunctionDeclaration?[n]:n.kind===e.SyntaxKind.VariableStatement?n.declarationList.declarations.filter(i=>o.o(i.initializer)&&i.initializer.kind===e.SyntaxKind.ArrowFunction).map(i=>i.initializer):[],l=n=>{const i=e.createSourceFile("temp.ts",n,e.ScriptTarget.ESNext,!0);let t=[];return i.forEachChild(r=>{(r.kind===e.SyntaxKind.FunctionDeclaration||r.kind===e.SyntaxKind.VariableStatement)&&d(r).forEach(a=>{t=s(a,t)})}),t};exports.getFunctionInputSchema=l;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class c extends Error{constructor(e){super(`App connection ${e} requires the user to reconnect (authFailedAt is set). Surface a "Reconnect" prompt in your UI.`),this.name="AppConnectionAuthFailedError",this.connectionId=e}}const r="TWENTY_API_URL",i="TWENTY_APP_ACCESS_TOKEN",a=async(n,e)=>{const s=process.env[r],t=process.env[i];if(!s||!t)throw new Error(`${n==="list"?"listConnections":"getConnection"}() requires the app runtime env vars ${r} and ${i}.`);const o=await fetch(`${s}/apps/connections/${n}`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`},body:JSON.stringify(e)});if(!o.ok)throw new Error(`${n==="list"?"listConnections":"getConnection"}() failed: HTTP ${o.status} ${o.statusText}`);return await o.json()},u=async n=>{const e=await a("get",{id:n});if(e.authFailedAt!==null)throw new c(e.id);return e},p=async(n={})=>a("list",n),l=(n,e)=>{if(e.userWorkspaceId!==null){const t=n.find(o=>o.visibility==="user"&&o.userWorkspaceId===e.userWorkspaceId);if(t)return t}return n.find(t=>t.visibility==="workspace")??null};exports.AppConnectionAuthFailedError=c;exports.findConnectionForRequest=l;exports.getConnection=u;exports.listConnections=p;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/sdk/logic-function/connections/errors/app-connection-auth-failed.error.ts","../../../twenty-shared/dist/application.mjs","../../src/sdk/logic-function/connections/utils/post-connections-endpoint.util.ts","../../src/sdk/logic-function/connections/get-connection.ts","../../src/sdk/logic-function/connections/list-connections.ts","../../src/sdk/logic-function/connections/find-connection-for-request.ts"],"sourcesContent":["// Thrown when the platform asks the SDK to operate on a connection whose\n// OAuth refresh failed permanently (`authFailedAt` is set). The end user\n// must reconnect from the app's settings tab — the app cannot recover on\n// its own.\n//\n// `listConnections` filters these out by default (the user can't act on\n// them anyway). `getConnection` throws this when the looked-up connection\n// is in this state, so a stored connection id can be safely retried until\n// it works again.\nexport class AppConnectionAuthFailedError extends Error {\n readonly connectionId: string;\n\n constructor(connectionId: string) {\n super(\n `App connection ${connectionId} requires the user to reconnect ` +\n `(authFailedAt is set). Surface a \"Reconnect\" prompt in your UI.`,\n );\n this.name = 'AppConnectionAuthFailedError';\n this.connectionId = connectionId;\n }\n}\n","const _ = \"public\", A = \"TWENTY_API_KEY\", T = \"TWENTY_API_URL\", r = \"TWENTY_APP_ACCESS_TOKEN\", t = \"generated\", N = {\n js: `import { createRequire as __createRequire } from 'module';\nconst require = __createRequire(import.meta.url);`\n}, u = \".twenty/output\", I = \"Standard\", n = \"20202020-64aa-4b6f-b003-9c74b97cee20\";\nvar e = /* @__PURE__ */ ((o) => (o.Object = \"object\", o.Field = \"field\", o.LogicFunction = \"logicFunction\", o.FrontComponent = \"frontComponent\", o.Role = \"role\", o.Skill = \"skill\", o.Agent = \"agent\", o.ConnectionProvider = \"connectionProvider\", o.View = \"view\", o.NavigationMenuItem = \"navigationMenuItem\", o.PageLayout = \"pageLayout\", o.PageLayoutTab = \"pageLayoutTab\", o.CommandMenuItem = \"commandMenuItem\", o))(e || {});\nexport {\n _ as ASSETS_DIR,\n A as DEFAULT_API_KEY_NAME,\n T as DEFAULT_API_URL_NAME,\n r as DEFAULT_APP_ACCESS_TOKEN_NAME,\n t as GENERATED_DIR,\n N as NODE_ESM_CJS_BANNER,\n u as OUTPUT_DIR,\n e as SyncableEntity,\n I as TWENTY_STANDARD_APPLICATION_NAME,\n n as TWENTY_STANDARD_APPLICATION_UNIVERSAL_IDENTIFIER\n};\n","import {\n DEFAULT_API_URL_NAME,\n DEFAULT_APP_ACCESS_TOKEN_NAME,\n} from 'twenty-shared/application';\n\n// Shared transport for `/apps/connections/*` endpoints. Centralises the\n// env-var check, auth header, and HTTP error translation so each helper\n// stays focused on its own input/output shape.\nexport const postConnectionsEndpoint = async <TBody, TResponse>(\n path: 'list' | 'get',\n body: TBody,\n): Promise<TResponse> => {\n const apiUrl = process.env[DEFAULT_API_URL_NAME];\n const accessToken = process.env[DEFAULT_APP_ACCESS_TOKEN_NAME];\n\n if (!apiUrl || !accessToken) {\n throw new Error(\n `${path === 'list' ? 'listConnections' : 'getConnection'}() requires the app runtime env vars ` +\n `${DEFAULT_API_URL_NAME} and ${DEFAULT_APP_ACCESS_TOKEN_NAME}.`,\n );\n }\n\n const response = await fetch(`${apiUrl}/apps/connections/${path}`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${accessToken}`,\n },\n body: JSON.stringify(body),\n });\n\n if (!response.ok) {\n throw new Error(\n `${path === 'list' ? 'listConnections' : 'getConnection'}() failed: ` +\n `HTTP ${response.status} ${response.statusText}`,\n );\n }\n\n return (await response.json()) as TResponse;\n};\n","import { AppConnectionAuthFailedError } from '@/sdk/logic-function/connections/errors/app-connection-auth-failed.error';\nimport { type AppConnection } from '@/sdk/logic-function/connections/types/app-connection.type';\nimport { postConnectionsEndpoint } from '@/sdk/logic-function/connections/utils/post-connections-endpoint.util';\n\n// Look up a single connection by id. The id is stable across reconnects\n// (the row keeps its id when the user clicks \"Reconnect\"), so apps can\n// safely persist it in their own data and call this helper on each\n// invocation to retrieve a fresh access token.\n//\n// Throws `AppConnectionAuthFailedError` if the credential is in a\n// permanent-failure state (the user must reconnect from the app's\n// settings tab). Throws a regular `Error` for any other failure\n// (network, not-found, transient refresh failure).\nexport const getConnection = async (id: string): Promise<AppConnection> => {\n const connection = await postConnectionsEndpoint<\n { id: string },\n AppConnection\n >('get', { id });\n\n if (connection.authFailedAt !== null) {\n throw new AppConnectionAuthFailedError(connection.id);\n }\n\n return connection;\n};\n","import { type AppConnection } from '@/sdk/logic-function/connections/types/app-connection.type';\nimport { postConnectionsEndpoint } from '@/sdk/logic-function/connections/utils/post-connections-endpoint.util';\n\nexport type ListConnectionsFilter = {\n // Provider name as declared on `defineConnectionProvider({ name })`.\n providerName?: string;\n // Restrict to credentials owned by a specific user. Useful in cron\n // triggers when picking a service-account user via app config.\n userWorkspaceId?: string;\n // Restrict by row visibility — 'user' (private) or 'workspace' (shared).\n visibility?: 'user' | 'workspace';\n};\n\n// Returns every connection owned by the running app, optionally filtered.\n// The server refreshes each access token on read, so the returned values\n// are usable immediately. When the running execution carries a user\n// context (HTTP-route trigger with `isAuthRequired`, tool calls, etc.),\n// `scope: 'user'` connections belonging to other users are filtered out\n// server-side. Cron and database-event triggers see all connections.\nexport const listConnections = async (\n filter: ListConnectionsFilter = {},\n): Promise<AppConnection[]> =>\n postConnectionsEndpoint<ListConnectionsFilter, AppConnection[]>(\n 'list',\n filter,\n );\n","import { type AppConnection } from '@/sdk/logic-function/connections/types/app-connection.type';\n\n// Resolution rule for an HTTP-route handler that wants \"the request user's\n// connection, or fall back to a workspace-shared one.\" Pure function — no\n// network. Pass it the result of `listConnections` and the trigger event.\n//\n// The plan-of-record for picking a connection is documented in the v3 plan\n// notes; this utility encodes the most common case so handlers don't have\n// to repeat the same `find(...) ?? find(...)` chain.\n//\n// Returns `null` when no candidate exists — caller decides whether that's\n// a 4xx for the end user or a hard error.\nexport const findConnectionForRequest = (\n connections: AppConnection[],\n event: { userWorkspaceId: string | null },\n): AppConnection | null => {\n // 1. Personal credential of the request user (highest specificity).\n if (event.userWorkspaceId !== null) {\n const personal = connections.find(\n (connection) =>\n connection.visibility === 'user' &&\n connection.userWorkspaceId === event.userWorkspaceId,\n );\n\n if (personal) {\n return personal;\n }\n }\n\n // 2. Any workspace-shared credential (team-managed service account).\n const workspaceShared = connections.find(\n (connection) => connection.visibility === 'workspace',\n );\n\n return workspaceShared ?? null;\n};\n"],"names":["AppConnectionAuthFailedError","connectionId","T","r","postConnectionsEndpoint","path","body","apiUrl","DEFAULT_API_URL_NAME","accessToken","DEFAULT_APP_ACCESS_TOKEN_NAME","response","getConnection","id","connection","listConnections","filter","findConnectionForRequest","connections","event","personal"],"mappings":"gFASO,MAAMA,UAAqC,KAAM,CAGtD,YAAYC,EAAsB,CAChC,MACE,kBAAkBA,CAAY,iGAAA,EAGhC,KAAK,KAAO,+BACZ,KAAK,aAAeA,CACtB,CACF,CCpBK,MAAqCC,EAAI,iBAAkBC,EAAI,0BCQvDC,EAA0B,MACrCC,EACAC,IACuB,CACvB,MAAMC,EAAS,QAAQ,IAAIC,CAAoB,EACzCC,EAAc,QAAQ,IAAIC,CAA6B,EAE7D,GAAI,CAACH,GAAU,CAACE,EACd,MAAM,IAAI,MACR,GAAGJ,IAAS,OAAS,kBAAoB,eAAe,wCACnDG,CAAoB,QAAQE,CAA6B,GAAA,EAIlE,MAAMC,EAAW,MAAM,MAAM,GAAGJ,CAAM,qBAAqBF,CAAI,GAAI,CACjE,OAAQ,OACR,QAAS,CACP,eAAgB,mBAChB,cAAe,UAAUI,CAAW,EAAA,EAEtC,KAAM,KAAK,UAAUH,CAAI,CAAA,CAC1B,EAED,GAAI,CAACK,EAAS,GACZ,MAAM,IAAI,MACR,GAAGN,IAAS,OAAS,kBAAoB,eAAe,mBAC9CM,EAAS,MAAM,IAAIA,EAAS,UAAU,EAAA,EAIpD,OAAQ,MAAMA,EAAS,KAAA,CACzB,EC1BaC,EAAgB,MAAOC,GAAuC,CACzE,MAAMC,EAAa,MAAMV,EAGvB,MAAO,CAAE,GAAAS,EAAI,EAEf,GAAIC,EAAW,eAAiB,KAC9B,MAAM,IAAId,EAA6Bc,EAAW,EAAE,EAGtD,OAAOA,CACT,ECLaC,EAAkB,MAC7BC,EAAgC,CAAA,IAEhCZ,EACE,OACAY,CACF,ECbWC,EAA2B,CACtCC,EACAC,IACyB,CAEzB,GAAIA,EAAM,kBAAoB,KAAM,CAClC,MAAMC,EAAWF,EAAY,KAC1BJ,GACCA,EAAW,aAAe,QAC1BA,EAAW,kBAAoBK,EAAM,eAAA,EAGzC,GAAIC,EACF,OAAOA,CAEX,CAOA,OAJwBF,EAAY,KACjCJ,GAAeA,EAAW,aAAe,WAAA,GAGlB,IAC5B"}
|
|
@@ -2,6 +2,46 @@ type SyncableEntityOptions = {
|
|
|
2
2
|
universalIdentifier: string;
|
|
3
3
|
};
|
|
4
4
|
|
|
5
|
+
type AppConnection = {
|
|
6
|
+
id: string;
|
|
7
|
+
providerName: string;
|
|
8
|
+
name: string;
|
|
9
|
+
handle: string;
|
|
10
|
+
visibility: 'user' | 'workspace';
|
|
11
|
+
userWorkspaceId: string;
|
|
12
|
+
accessToken: string;
|
|
13
|
+
scopes: string[];
|
|
14
|
+
authFailedAt: string | null;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
declare enum FieldMetadataType {
|
|
18
|
+
ACTOR = "ACTOR",
|
|
19
|
+
ADDRESS = "ADDRESS",
|
|
20
|
+
ARRAY = "ARRAY",
|
|
21
|
+
BOOLEAN = "BOOLEAN",
|
|
22
|
+
CURRENCY = "CURRENCY",
|
|
23
|
+
DATE = "DATE",
|
|
24
|
+
DATE_TIME = "DATE_TIME",
|
|
25
|
+
EMAILS = "EMAILS",
|
|
26
|
+
FILES = "FILES",
|
|
27
|
+
FULL_NAME = "FULL_NAME",
|
|
28
|
+
LINKS = "LINKS",
|
|
29
|
+
MORPH_RELATION = "MORPH_RELATION",
|
|
30
|
+
MULTI_SELECT = "MULTI_SELECT",
|
|
31
|
+
NUMBER = "NUMBER",
|
|
32
|
+
NUMERIC = "NUMERIC",
|
|
33
|
+
PHONES = "PHONES",
|
|
34
|
+
POSITION = "POSITION",
|
|
35
|
+
RATING = "RATING",
|
|
36
|
+
RAW_JSON = "RAW_JSON",
|
|
37
|
+
RELATION = "RELATION",
|
|
38
|
+
RICH_TEXT = "RICH_TEXT",
|
|
39
|
+
SELECT = "SELECT",
|
|
40
|
+
TEXT = "TEXT",
|
|
41
|
+
TS_VECTOR = "TS_VECTOR",
|
|
42
|
+
UUID = "UUID"
|
|
43
|
+
}
|
|
44
|
+
|
|
5
45
|
declare enum HTTPMethod {
|
|
6
46
|
GET = "GET",
|
|
7
47
|
POST = "POST",
|
|
@@ -10,32 +50,20 @@ declare enum HTTPMethod {
|
|
|
10
50
|
DELETE = "DELETE"
|
|
11
51
|
}
|
|
12
52
|
|
|
13
|
-
/**
|
|
14
|
-
* AWS HTTP API v2 compatible request format for logic functions
|
|
15
|
-
* @see https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
|
|
16
|
-
*
|
|
17
|
-
* @typeParam TBody - The type of the request body. Defaults to `object` for parsed JSON bodies.
|
|
18
|
-
*/
|
|
19
53
|
type LogicFunctionEvent<TBody = object> = {
|
|
20
|
-
/** HTTP headers (filtered by forwardedRequestHeaders in route trigger) */
|
|
21
54
|
headers: Record<string, string | undefined>;
|
|
22
|
-
/** Query string parameters (multiple values are joined with commas, e.g., "1,2,3") */
|
|
23
55
|
queryStringParameters: Record<string, string | undefined>;
|
|
24
|
-
/** Path parameters extracted from the route pattern (e.g., /users/:id → { id: '123' }). Multiple values are joined with commas. */
|
|
25
56
|
pathParameters: Record<string, string | undefined>;
|
|
26
|
-
/** Request body */
|
|
27
57
|
body: TBody | null;
|
|
28
|
-
|
|
58
|
+
rawBody?: string;
|
|
29
59
|
isBase64Encoded: boolean;
|
|
30
|
-
/** Request context containing HTTP method, path, and other metadata */
|
|
31
60
|
requestContext: {
|
|
32
61
|
http: {
|
|
33
|
-
/** HTTP method (GET, POST, PUT, PATCH, DELETE) */
|
|
34
62
|
method: string;
|
|
35
|
-
/** Raw request path (e.g., /users/123) */
|
|
36
63
|
path: string;
|
|
37
64
|
};
|
|
38
65
|
};
|
|
66
|
+
userWorkspaceId: string | null;
|
|
39
67
|
};
|
|
40
68
|
|
|
41
69
|
type InputJsonSchema = {
|
|
@@ -50,6 +78,32 @@ type InputJsonSchema = {
|
|
|
50
78
|
maximum?: number;
|
|
51
79
|
};
|
|
52
80
|
|
|
81
|
+
type ToolTriggerSettings = {
|
|
82
|
+
inputSchema?: InputJsonSchema;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
type LeafType = 'string' | 'number' | 'boolean' | 'array' | 'unknown';
|
|
86
|
+
type NodeType = 'object' | 'unknown';
|
|
87
|
+
|
|
88
|
+
type InputSchemaPropertyType = LeafType | NodeType | FieldMetadataType;
|
|
89
|
+
type InputSchemaProperty = {
|
|
90
|
+
type: InputSchemaPropertyType;
|
|
91
|
+
enum?: string[];
|
|
92
|
+
items?: InputSchemaProperty;
|
|
93
|
+
properties?: Properties$1;
|
|
94
|
+
};
|
|
95
|
+
type Properties$1 = {
|
|
96
|
+
[name: string]: InputSchemaProperty;
|
|
97
|
+
};
|
|
98
|
+
type InputSchema = InputSchemaProperty[];
|
|
99
|
+
|
|
100
|
+
type WorkflowActionTriggerSettings = {
|
|
101
|
+
inputSchema?: InputSchema;
|
|
102
|
+
outputSchema?: InputSchema;
|
|
103
|
+
icon?: string;
|
|
104
|
+
label?: string;
|
|
105
|
+
};
|
|
106
|
+
|
|
53
107
|
type LogicFunctionManifest = SyncableEntityOptions & {
|
|
54
108
|
name?: string;
|
|
55
109
|
description?: string;
|
|
@@ -57,12 +111,12 @@ type LogicFunctionManifest = SyncableEntityOptions & {
|
|
|
57
111
|
cronTriggerSettings?: CronTriggerSettings;
|
|
58
112
|
databaseEventTriggerSettings?: DatabaseEventTriggerSettings;
|
|
59
113
|
httpRouteTriggerSettings?: HttpRouteTriggerSettings;
|
|
114
|
+
toolTriggerSettings?: ToolTriggerSettings;
|
|
115
|
+
workflowActionTriggerSettings?: WorkflowActionTriggerSettings;
|
|
60
116
|
sourceHandlerPath: string;
|
|
61
117
|
builtHandlerPath: string;
|
|
62
118
|
builtHandlerChecksum: string;
|
|
63
119
|
handlerName: string;
|
|
64
|
-
toolInputSchema: InputJsonSchema;
|
|
65
|
-
isTool?: boolean;
|
|
66
120
|
};
|
|
67
121
|
type CronTriggerSettings = {
|
|
68
122
|
pattern: string;
|
|
@@ -79,9 +133,8 @@ type HttpRouteTriggerSettings = {
|
|
|
79
133
|
};
|
|
80
134
|
|
|
81
135
|
type LogicFunctionHandler = (...args: any[]) => any | Promise<any>;
|
|
82
|
-
type LogicFunctionConfig = Omit<LogicFunctionManifest, 'sourceHandlerPath' | 'builtHandlerPath' | 'builtHandlerChecksum' | 'handlerName'
|
|
136
|
+
type LogicFunctionConfig = Omit<LogicFunctionManifest, 'sourceHandlerPath' | 'builtHandlerPath' | 'builtHandlerChecksum' | 'handlerName'> & {
|
|
83
137
|
handler: LogicFunctionHandler;
|
|
84
|
-
toolInputSchema?: InputJsonSchema;
|
|
85
138
|
};
|
|
86
139
|
|
|
87
140
|
type InstallPayload = {
|
|
@@ -211,5 +264,23 @@ type WorkspaceEventBatch<WorkspaceEvent> = {
|
|
|
211
264
|
};
|
|
212
265
|
type DatabaseEventPayload<T = ObjectRecordEvent> = Omit<WorkspaceEventBatch<T>, 'events'> & T;
|
|
213
266
|
|
|
214
|
-
|
|
215
|
-
|
|
267
|
+
declare const getConnection: (id: string) => Promise<AppConnection>;
|
|
268
|
+
|
|
269
|
+
type ListConnectionsFilter = {
|
|
270
|
+
providerName?: string;
|
|
271
|
+
userWorkspaceId?: string;
|
|
272
|
+
visibility?: 'user' | 'workspace';
|
|
273
|
+
};
|
|
274
|
+
declare const listConnections: (filter?: ListConnectionsFilter) => Promise<AppConnection[]>;
|
|
275
|
+
|
|
276
|
+
declare const findConnectionForRequest: (connections: AppConnection[], event: {
|
|
277
|
+
userWorkspaceId: string | null;
|
|
278
|
+
}) => AppConnection | null;
|
|
279
|
+
|
|
280
|
+
declare class AppConnectionAuthFailedError extends Error {
|
|
281
|
+
readonly connectionId: string;
|
|
282
|
+
constructor(connectionId: string);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
export { AppConnectionAuthFailedError, ObjectRecordBaseEvent, ObjectRecordCreateEvent, ObjectRecordDeleteEvent, ObjectRecordDestroyEvent, ObjectRecordRestoreEvent, ObjectRecordUpdateEvent, ObjectRecordUpsertEvent, findConnectionForRequest, getConnection, listConnections };
|
|
286
|
+
export type { AppConnection, CronPayload, DatabaseEventPayload, InputJsonSchema, InstallHandler, InstallPayload, ListConnectionsFilter, LogicFunctionConfig, LogicFunctionHandler, ObjectRecordEvent, LogicFunctionEvent as RoutePayload };
|
|
@@ -1,2 +1,53 @@
|
|
|
1
|
-
|
|
1
|
+
class a extends Error {
|
|
2
|
+
constructor(e) {
|
|
3
|
+
super(
|
|
4
|
+
`App connection ${e} requires the user to reconnect (authFailedAt is set). Surface a "Reconnect" prompt in your UI.`
|
|
5
|
+
), this.name = "AppConnectionAuthFailedError", this.connectionId = e;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
const r = "TWENTY_API_URL", i = "TWENTY_APP_ACCESS_TOKEN", c = async (n, e) => {
|
|
9
|
+
const s = process.env[r], t = process.env[i];
|
|
10
|
+
if (!s || !t)
|
|
11
|
+
throw new Error(
|
|
12
|
+
`${n === "list" ? "listConnections" : "getConnection"}() requires the app runtime env vars ${r} and ${i}.`
|
|
13
|
+
);
|
|
14
|
+
const o = await fetch(`${s}/apps/connections/${n}`, {
|
|
15
|
+
method: "POST",
|
|
16
|
+
headers: {
|
|
17
|
+
"Content-Type": "application/json",
|
|
18
|
+
Authorization: `Bearer ${t}`
|
|
19
|
+
},
|
|
20
|
+
body: JSON.stringify(e)
|
|
21
|
+
});
|
|
22
|
+
if (!o.ok)
|
|
23
|
+
throw new Error(
|
|
24
|
+
`${n === "list" ? "listConnections" : "getConnection"}() failed: HTTP ${o.status} ${o.statusText}`
|
|
25
|
+
);
|
|
26
|
+
return await o.json();
|
|
27
|
+
}, p = async (n) => {
|
|
28
|
+
const e = await c("get", { id: n });
|
|
29
|
+
if (e.authFailedAt !== null)
|
|
30
|
+
throw new a(e.id);
|
|
31
|
+
return e;
|
|
32
|
+
}, u = async (n = {}) => c(
|
|
33
|
+
"list",
|
|
34
|
+
n
|
|
35
|
+
), l = (n, e) => {
|
|
36
|
+
if (e.userWorkspaceId !== null) {
|
|
37
|
+
const t = n.find(
|
|
38
|
+
(o) => o.visibility === "user" && o.userWorkspaceId === e.userWorkspaceId
|
|
39
|
+
);
|
|
40
|
+
if (t)
|
|
41
|
+
return t;
|
|
42
|
+
}
|
|
43
|
+
return n.find(
|
|
44
|
+
(t) => t.visibility === "workspace"
|
|
45
|
+
) ?? null;
|
|
46
|
+
};
|
|
47
|
+
export {
|
|
48
|
+
a as AppConnectionAuthFailedError,
|
|
49
|
+
l as findConnectionForRequest,
|
|
50
|
+
p as getConnection,
|
|
51
|
+
u as listConnections
|
|
52
|
+
};
|
|
2
53
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../src/sdk/logic-function/connections/errors/app-connection-auth-failed.error.ts","../../../twenty-shared/dist/application.mjs","../../src/sdk/logic-function/connections/utils/post-connections-endpoint.util.ts","../../src/sdk/logic-function/connections/get-connection.ts","../../src/sdk/logic-function/connections/list-connections.ts","../../src/sdk/logic-function/connections/find-connection-for-request.ts"],"sourcesContent":["// Thrown when the platform asks the SDK to operate on a connection whose\n// OAuth refresh failed permanently (`authFailedAt` is set). The end user\n// must reconnect from the app's settings tab — the app cannot recover on\n// its own.\n//\n// `listConnections` filters these out by default (the user can't act on\n// them anyway). `getConnection` throws this when the looked-up connection\n// is in this state, so a stored connection id can be safely retried until\n// it works again.\nexport class AppConnectionAuthFailedError extends Error {\n readonly connectionId: string;\n\n constructor(connectionId: string) {\n super(\n `App connection ${connectionId} requires the user to reconnect ` +\n `(authFailedAt is set). Surface a \"Reconnect\" prompt in your UI.`,\n );\n this.name = 'AppConnectionAuthFailedError';\n this.connectionId = connectionId;\n }\n}\n","const _ = \"public\", A = \"TWENTY_API_KEY\", T = \"TWENTY_API_URL\", r = \"TWENTY_APP_ACCESS_TOKEN\", t = \"generated\", N = {\n js: `import { createRequire as __createRequire } from 'module';\nconst require = __createRequire(import.meta.url);`\n}, u = \".twenty/output\", I = \"Standard\", n = \"20202020-64aa-4b6f-b003-9c74b97cee20\";\nvar e = /* @__PURE__ */ ((o) => (o.Object = \"object\", o.Field = \"field\", o.LogicFunction = \"logicFunction\", o.FrontComponent = \"frontComponent\", o.Role = \"role\", o.Skill = \"skill\", o.Agent = \"agent\", o.ConnectionProvider = \"connectionProvider\", o.View = \"view\", o.NavigationMenuItem = \"navigationMenuItem\", o.PageLayout = \"pageLayout\", o.PageLayoutTab = \"pageLayoutTab\", o.CommandMenuItem = \"commandMenuItem\", o))(e || {});\nexport {\n _ as ASSETS_DIR,\n A as DEFAULT_API_KEY_NAME,\n T as DEFAULT_API_URL_NAME,\n r as DEFAULT_APP_ACCESS_TOKEN_NAME,\n t as GENERATED_DIR,\n N as NODE_ESM_CJS_BANNER,\n u as OUTPUT_DIR,\n e as SyncableEntity,\n I as TWENTY_STANDARD_APPLICATION_NAME,\n n as TWENTY_STANDARD_APPLICATION_UNIVERSAL_IDENTIFIER\n};\n","import {\n DEFAULT_API_URL_NAME,\n DEFAULT_APP_ACCESS_TOKEN_NAME,\n} from 'twenty-shared/application';\n\n// Shared transport for `/apps/connections/*` endpoints. Centralises the\n// env-var check, auth header, and HTTP error translation so each helper\n// stays focused on its own input/output shape.\nexport const postConnectionsEndpoint = async <TBody, TResponse>(\n path: 'list' | 'get',\n body: TBody,\n): Promise<TResponse> => {\n const apiUrl = process.env[DEFAULT_API_URL_NAME];\n const accessToken = process.env[DEFAULT_APP_ACCESS_TOKEN_NAME];\n\n if (!apiUrl || !accessToken) {\n throw new Error(\n `${path === 'list' ? 'listConnections' : 'getConnection'}() requires the app runtime env vars ` +\n `${DEFAULT_API_URL_NAME} and ${DEFAULT_APP_ACCESS_TOKEN_NAME}.`,\n );\n }\n\n const response = await fetch(`${apiUrl}/apps/connections/${path}`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${accessToken}`,\n },\n body: JSON.stringify(body),\n });\n\n if (!response.ok) {\n throw new Error(\n `${path === 'list' ? 'listConnections' : 'getConnection'}() failed: ` +\n `HTTP ${response.status} ${response.statusText}`,\n );\n }\n\n return (await response.json()) as TResponse;\n};\n","import { AppConnectionAuthFailedError } from '@/sdk/logic-function/connections/errors/app-connection-auth-failed.error';\nimport { type AppConnection } from '@/sdk/logic-function/connections/types/app-connection.type';\nimport { postConnectionsEndpoint } from '@/sdk/logic-function/connections/utils/post-connections-endpoint.util';\n\n// Look up a single connection by id. The id is stable across reconnects\n// (the row keeps its id when the user clicks \"Reconnect\"), so apps can\n// safely persist it in their own data and call this helper on each\n// invocation to retrieve a fresh access token.\n//\n// Throws `AppConnectionAuthFailedError` if the credential is in a\n// permanent-failure state (the user must reconnect from the app's\n// settings tab). Throws a regular `Error` for any other failure\n// (network, not-found, transient refresh failure).\nexport const getConnection = async (id: string): Promise<AppConnection> => {\n const connection = await postConnectionsEndpoint<\n { id: string },\n AppConnection\n >('get', { id });\n\n if (connection.authFailedAt !== null) {\n throw new AppConnectionAuthFailedError(connection.id);\n }\n\n return connection;\n};\n","import { type AppConnection } from '@/sdk/logic-function/connections/types/app-connection.type';\nimport { postConnectionsEndpoint } from '@/sdk/logic-function/connections/utils/post-connections-endpoint.util';\n\nexport type ListConnectionsFilter = {\n // Provider name as declared on `defineConnectionProvider({ name })`.\n providerName?: string;\n // Restrict to credentials owned by a specific user. Useful in cron\n // triggers when picking a service-account user via app config.\n userWorkspaceId?: string;\n // Restrict by row visibility — 'user' (private) or 'workspace' (shared).\n visibility?: 'user' | 'workspace';\n};\n\n// Returns every connection owned by the running app, optionally filtered.\n// The server refreshes each access token on read, so the returned values\n// are usable immediately. When the running execution carries a user\n// context (HTTP-route trigger with `isAuthRequired`, tool calls, etc.),\n// `scope: 'user'` connections belonging to other users are filtered out\n// server-side. Cron and database-event triggers see all connections.\nexport const listConnections = async (\n filter: ListConnectionsFilter = {},\n): Promise<AppConnection[]> =>\n postConnectionsEndpoint<ListConnectionsFilter, AppConnection[]>(\n 'list',\n filter,\n );\n","import { type AppConnection } from '@/sdk/logic-function/connections/types/app-connection.type';\n\n// Resolution rule for an HTTP-route handler that wants \"the request user's\n// connection, or fall back to a workspace-shared one.\" Pure function — no\n// network. Pass it the result of `listConnections` and the trigger event.\n//\n// The plan-of-record for picking a connection is documented in the v3 plan\n// notes; this utility encodes the most common case so handlers don't have\n// to repeat the same `find(...) ?? find(...)` chain.\n//\n// Returns `null` when no candidate exists — caller decides whether that's\n// a 4xx for the end user or a hard error.\nexport const findConnectionForRequest = (\n connections: AppConnection[],\n event: { userWorkspaceId: string | null },\n): AppConnection | null => {\n // 1. Personal credential of the request user (highest specificity).\n if (event.userWorkspaceId !== null) {\n const personal = connections.find(\n (connection) =>\n connection.visibility === 'user' &&\n connection.userWorkspaceId === event.userWorkspaceId,\n );\n\n if (personal) {\n return personal;\n }\n }\n\n // 2. Any workspace-shared credential (team-managed service account).\n const workspaceShared = connections.find(\n (connection) => connection.visibility === 'workspace',\n );\n\n return workspaceShared ?? null;\n};\n"],"names":["AppConnectionAuthFailedError","connectionId","T","r","postConnectionsEndpoint","path","body","apiUrl","DEFAULT_API_URL_NAME","accessToken","DEFAULT_APP_ACCESS_TOKEN_NAME","response","getConnection","id","connection","listConnections","filter","findConnectionForRequest","connections","event","personal"],"mappings":"AASO,MAAMA,UAAqC,MAAM;AAAA,EAGtD,YAAYC,GAAsB;AAChC;AAAA,MACE,kBAAkBA,CAAY;AAAA,IAAA,GAGhC,KAAK,OAAO,gCACZ,KAAK,eAAeA;AAAA,EACtB;AACF;ACpBK,MAAqCC,IAAI,kBAAkBC,IAAI,2BCQvDC,IAA0B,OACrCC,GACAC,MACuB;AACvB,QAAMC,IAAS,QAAQ,IAAIC,CAAoB,GACzCC,IAAc,QAAQ,IAAIC,CAA6B;AAE7D,MAAI,CAACH,KAAU,CAACE;AACd,UAAM,IAAI;AAAA,MACR,GAAGJ,MAAS,SAAS,oBAAoB,eAAe,wCACnDG,CAAoB,QAAQE,CAA6B;AAAA,IAAA;AAIlE,QAAMC,IAAW,MAAM,MAAM,GAAGJ,CAAM,qBAAqBF,CAAI,IAAI;AAAA,IACjE,QAAQ;AAAA,IACR,SAAS;AAAA,MACP,gBAAgB;AAAA,MAChB,eAAe,UAAUI,CAAW;AAAA,IAAA;AAAA,IAEtC,MAAM,KAAK,UAAUH,CAAI;AAAA,EAAA,CAC1B;AAED,MAAI,CAACK,EAAS;AACZ,UAAM,IAAI;AAAA,MACR,GAAGN,MAAS,SAAS,oBAAoB,eAAe,mBAC9CM,EAAS,MAAM,IAAIA,EAAS,UAAU;AAAA,IAAA;AAIpD,SAAQ,MAAMA,EAAS,KAAA;AACzB,GC1BaC,IAAgB,OAAOC,MAAuC;AACzE,QAAMC,IAAa,MAAMV,EAGvB,OAAO,EAAE,IAAAS,GAAI;AAEf,MAAIC,EAAW,iBAAiB;AAC9B,UAAM,IAAId,EAA6Bc,EAAW,EAAE;AAGtD,SAAOA;AACT,GCLaC,IAAkB,OAC7BC,IAAgC,CAAA,MAEhCZ;AAAA,EACE;AAAA,EACAY;AACF,GCbWC,IAA2B,CACtCC,GACAC,MACyB;AAEzB,MAAIA,EAAM,oBAAoB,MAAM;AAClC,UAAMC,IAAWF,EAAY;AAAA,MAC3B,CAACJ,MACCA,EAAW,eAAe,UAC1BA,EAAW,oBAAoBK,EAAM;AAAA,IAAA;AAGzC,QAAIC;AACF,aAAOA;AAAA,EAEX;AAOA,SAJwBF,EAAY;AAAA,IAClC,CAACJ,MAAeA,EAAW,eAAe;AAAA,EAAA,KAGlB;AAC5B;"}
|
package/dist/operations.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./uninstall-
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./uninstall-BiLmSWhb.js"),n=async t=>(t?.remote&&e.ConfigService.setActiveRemote(t.remote),await new e.ConfigService().clearConfig(),{success:!0,data:void 0}),i=t=>e.runSafe(()=>n(t),e.AUTH_ERROR_CODES.AUTH_FAILED);exports.APP_ERROR_CODES=e.APP_ERROR_CODES;exports.AUTH_ERROR_CODES=e.AUTH_ERROR_CODES;exports.ConfigService=e.ConfigService;exports.FUNCTION_ERROR_CODES=e.FUNCTION_ERROR_CODES;exports.SERVER_ERROR_CODES=e.SERVER_ERROR_CODES;exports.appBuild=e.appBuild;exports.appDeploy=e.appDeploy;exports.appDevOnce=e.appDevOnce;exports.appInstall=e.appInstall;exports.appPublish=e.appPublish;exports.appUninstall=e.appUninstall;exports.authLogin=e.authLogin;exports.authLoginOAuth=e.authLoginOAuth;exports.checkDockerRunning=e.checkDockerRunning;exports.containerExists=e.containerExists;exports.detectLocalServer=e.detectLocalServer;exports.functionExecute=e.functionExecute;exports.getContainerDigest=e.getContainerDigest;exports.getImageDigest=e.getImageDigest;exports.getImageForVersion=e.getImageForVersion;exports.serverStart=e.serverStart;exports.serverUpgrade=e.serverUpgrade;exports.authLogout=i;
|
package/dist/operations.mjs
CHANGED
|
@@ -1,22 +1,28 @@
|
|
|
1
|
-
import { r as s, A as t, C as
|
|
2
|
-
import { a as
|
|
3
|
-
const
|
|
1
|
+
import { r as s, A as t, C as a } from "./uninstall-DAf2XiS3.mjs";
|
|
2
|
+
import { a as p, F as u, S as R, b as E, c as S, d as O, e as f, f as l, g as D, h as m, i as v, j as C, k as _, l as h, m as A, n as d, o as L, p as I, s as U, q as x } from "./uninstall-DAf2XiS3.mjs";
|
|
3
|
+
const r = async (e) => (e?.remote && a.setActiveRemote(e.remote), await new a().clearConfig(), { success: !0, data: void 0 }), i = (e) => s(() => r(e), t.AUTH_FAILED);
|
|
4
4
|
export {
|
|
5
|
-
|
|
5
|
+
p as APP_ERROR_CODES,
|
|
6
6
|
t as AUTH_ERROR_CODES,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
a as ConfigService,
|
|
8
|
+
u as FUNCTION_ERROR_CODES,
|
|
9
|
+
R as SERVER_ERROR_CODES,
|
|
10
|
+
E as appBuild,
|
|
11
|
+
S as appDeploy,
|
|
12
|
+
O as appDevOnce,
|
|
13
|
+
f as appInstall,
|
|
14
14
|
l as appPublish,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
C as
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
D as appUninstall,
|
|
16
|
+
m as authLogin,
|
|
17
|
+
v as authLoginOAuth,
|
|
18
|
+
i as authLogout,
|
|
19
|
+
C as checkDockerRunning,
|
|
20
|
+
_ as containerExists,
|
|
21
|
+
h as detectLocalServer,
|
|
22
|
+
A as functionExecute,
|
|
23
|
+
d as getContainerDigest,
|
|
24
|
+
L as getImageDigest,
|
|
25
|
+
I as getImageForVersion,
|
|
26
|
+
U as serverStart,
|
|
27
|
+
x as serverUpgrade
|
|
22
28
|
};
|