@zapier/zapier-sdk 0.37.0 → 0.39.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/CHANGELOG.md +12 -0
- package/README.md +56 -49
- package/dist/apps.cjs +9036 -0
- package/dist/apps.d.mts +23 -0
- package/dist/apps.d.ts +23 -0
- package/dist/apps.mjs +9034 -0
- package/dist/define/apps-entrypoint.d.ts +3 -0
- package/dist/define/apps-entrypoint.d.ts.map +1 -0
- package/dist/define/apps-entrypoint.js +1 -0
- package/dist/define/apps-registry-keys.d.ts +2 -0
- package/dist/define/apps-registry-keys.d.ts.map +1 -0
- package/dist/define/apps-registry-keys.js +2 -0
- package/dist/define/apps-registry.d.ts +13 -0
- package/dist/define/apps-registry.d.ts.map +1 -0
- package/dist/define/apps-registry.js +31 -0
- package/dist/define/apps-registry.json +9010 -0
- package/dist/define/apps.d.ts +11 -0
- package/dist/define/apps.d.ts.map +1 -0
- package/dist/define/apps.js +2 -0
- package/dist/define/define.d.ts +13 -0
- package/dist/define/define.d.ts.map +1 -0
- package/dist/define/define.js +93 -0
- package/dist/define/helpers.d.ts +8 -0
- package/dist/define/helpers.d.ts.map +1 -0
- package/dist/define/helpers.js +6 -0
- package/dist/define/index.d.ts +5 -0
- package/dist/define/index.d.ts.map +1 -0
- package/dist/define/index.js +2 -0
- package/dist/define/types.d.ts +235 -0
- package/dist/define/types.d.ts.map +1 -0
- package/dist/define/types.js +1 -0
- package/dist/define.cjs +113 -0
- package/dist/define.d.mts +254 -0
- package/dist/define.d.ts +254 -0
- package/dist/define.mjs +107 -0
- package/dist/index.cjs +145 -41
- package/dist/index.d.mts +38 -7
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.mjs +145 -42
- package/dist/plugins/capabilities/index.d.ts +22 -0
- package/dist/plugins/capabilities/index.d.ts.map +1 -0
- package/dist/plugins/capabilities/index.js +76 -0
- package/dist/plugins/findFirstConnection/schemas.d.ts +1 -0
- package/dist/plugins/findFirstConnection/schemas.d.ts.map +1 -1
- package/dist/plugins/findUniqueConnection/schemas.d.ts +1 -0
- package/dist/plugins/findUniqueConnection/schemas.d.ts.map +1 -1
- package/dist/plugins/listConnections/index.d.ts +2 -1
- package/dist/plugins/listConnections/index.d.ts.map +1 -1
- package/dist/plugins/listConnections/index.js +10 -3
- package/dist/plugins/listConnections/schemas.d.ts +1 -0
- package/dist/plugins/listConnections/schemas.d.ts.map +1 -1
- package/dist/plugins/listConnections/schemas.js +5 -0
- package/dist/plugins/manifest/index.d.ts +1 -0
- package/dist/plugins/manifest/index.d.ts.map +1 -1
- package/dist/plugins/manifest/index.js +1 -0
- package/dist/plugins/manifest/schemas.d.ts +9 -0
- package/dist/plugins/manifest/schemas.d.ts.map +1 -1
- package/dist/plugins/manifest/schemas.js +9 -0
- package/dist/plugins/tables/deleteTable/index.d.ts +2 -1
- package/dist/plugins/tables/deleteTable/index.d.ts.map +1 -1
- package/dist/plugins/tables/deleteTable/index.js +1 -0
- package/dist/plugins/tables/listTables/index.d.ts +2 -1
- package/dist/plugins/tables/listTables/index.d.ts.map +1 -1
- package/dist/plugins/tables/listTables/index.js +14 -6
- package/dist/plugins/tables/listTables/schemas.d.ts +1 -0
- package/dist/plugins/tables/listTables/schemas.d.ts.map +1 -1
- package/dist/plugins/tables/listTables/schemas.js +5 -1
- package/dist/resolvers/connectionId.d.ts.map +1 -1
- package/dist/resolvers/connectionId.js +13 -23
- package/dist/resolvers/tableId.d.ts.map +1 -1
- package/dist/resolvers/tableId.js +17 -6
- package/dist/sdk.d.ts +3 -2
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +3 -0
- package/dist/types/sdk.d.ts +3 -0
- package/dist/types/sdk.d.ts.map +1 -1
- package/dist/types/sdk.js +9 -0
- package/dist/utils/pagination-utils.d.ts +6 -0
- package/dist/utils/pagination-utils.d.ts.map +1 -1
- package/dist/utils/pagination-utils.js +8 -0
- package/dist/utils/schema-utils.d.ts +6 -1
- package/dist/utils/schema-utils.d.ts.map +1 -1
- package/package.json +23 -1
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { AppRef } from './apps.mjs';
|
|
2
|
+
export { BuiltinApp } from './apps.mjs';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
|
|
5
|
+
interface ZapierClient {
|
|
6
|
+
fetch(url: string, options: {
|
|
7
|
+
connection?: string;
|
|
8
|
+
method?: string;
|
|
9
|
+
headers?: Record<string, string>;
|
|
10
|
+
body?: string | Record<string, unknown> | null;
|
|
11
|
+
timeout?: number;
|
|
12
|
+
}): Promise<Response>;
|
|
13
|
+
}
|
|
14
|
+
interface DefineContext {
|
|
15
|
+
zapier: ZapierClient;
|
|
16
|
+
}
|
|
17
|
+
interface StepOptions<T> {
|
|
18
|
+
name: string;
|
|
19
|
+
run: () => Promise<T>;
|
|
20
|
+
maxAttempts?: number;
|
|
21
|
+
retryDelaySeconds?: number;
|
|
22
|
+
outputSchema?: z.ZodSchema<T>;
|
|
23
|
+
}
|
|
24
|
+
interface WaitOptions {
|
|
25
|
+
name: string;
|
|
26
|
+
seconds: number;
|
|
27
|
+
}
|
|
28
|
+
interface CallbackOptions<T = unknown> {
|
|
29
|
+
name: string;
|
|
30
|
+
timeoutSeconds?: number;
|
|
31
|
+
payloadSchema?: z.ZodSchema<T>;
|
|
32
|
+
}
|
|
33
|
+
type ToolContext = DefineContext;
|
|
34
|
+
interface SingleConnectionToolContext extends DefineContext {
|
|
35
|
+
connection: string;
|
|
36
|
+
}
|
|
37
|
+
interface MultiConnectionToolContext<TConn extends Record<string, AppRef>> extends DefineContext {
|
|
38
|
+
connections: {
|
|
39
|
+
[K in keyof TConn]: string;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
interface DurableContext extends DefineContext {
|
|
43
|
+
step<T>(name: string, fn: () => Promise<T>): Promise<T>;
|
|
44
|
+
step<T>(options: StepOptions<T>): Promise<T>;
|
|
45
|
+
wait(name: string, seconds: number): Promise<void>;
|
|
46
|
+
wait(options: WaitOptions): Promise<void>;
|
|
47
|
+
createCallback(name: string): Promise<[Promise<unknown>, string]>;
|
|
48
|
+
createCallback<T>(options: CallbackOptions<T>): Promise<[Promise<T>, string]>;
|
|
49
|
+
}
|
|
50
|
+
type ComponentCtx = DefineContext;
|
|
51
|
+
declare const CONNECTION_BRAND: unique symbol;
|
|
52
|
+
type ConnectionId<TApp extends AppRef> = string & {
|
|
53
|
+
readonly [CONNECTION_BRAND]: TApp;
|
|
54
|
+
};
|
|
55
|
+
interface SingleConnExecuteOptions<TApp extends AppRef> {
|
|
56
|
+
connection: ConnectionId<TApp>;
|
|
57
|
+
}
|
|
58
|
+
interface MultiConnExecuteOptions<TConn extends Record<string, AppRef>> {
|
|
59
|
+
connections: {
|
|
60
|
+
[K in keyof TConn]: ConnectionId<TConn[K]>;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
type RefProxy<K extends string> = {
|
|
64
|
+
[P in K]: {
|
|
65
|
+
$ref: P;
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
type ResolveDirective = {
|
|
69
|
+
kind: "options";
|
|
70
|
+
tool: unknown;
|
|
71
|
+
binds?: Record<string, {
|
|
72
|
+
$ref: string;
|
|
73
|
+
}>;
|
|
74
|
+
} | {
|
|
75
|
+
kind: "schema";
|
|
76
|
+
tool: unknown;
|
|
77
|
+
binds?: Record<string, {
|
|
78
|
+
$ref: string;
|
|
79
|
+
}>;
|
|
80
|
+
};
|
|
81
|
+
interface WithInputDependencies<TInput extends z.ZodType> {
|
|
82
|
+
inputDependencies?: ($: RefProxy<keyof z.infer<TInput> & string>) => Record<string, ResolveDirective>;
|
|
83
|
+
}
|
|
84
|
+
interface WithResultProcessors {
|
|
85
|
+
options?: (result: unknown) => Array<{
|
|
86
|
+
label: string;
|
|
87
|
+
value: string;
|
|
88
|
+
}>;
|
|
89
|
+
schema?: (result: unknown) => z.ZodType;
|
|
90
|
+
digest?: (result: unknown) => unknown;
|
|
91
|
+
}
|
|
92
|
+
interface DescribeResult {
|
|
93
|
+
kind: "tool" | "durable" | "component";
|
|
94
|
+
name: string;
|
|
95
|
+
description?: string;
|
|
96
|
+
inputSchema?: Record<string, unknown>;
|
|
97
|
+
connection?: AppRef;
|
|
98
|
+
connections?: Record<string, AppRef>;
|
|
99
|
+
}
|
|
100
|
+
interface ConnectionlessToolConfig<TInput extends z.ZodType> extends WithInputDependencies<TInput>, WithResultProcessors {
|
|
101
|
+
name: string;
|
|
102
|
+
description: string;
|
|
103
|
+
connection?: never;
|
|
104
|
+
connections?: never;
|
|
105
|
+
inputSchema: TInput;
|
|
106
|
+
run: (ctx: ToolContext, input: z.infer<TInput>) => Promise<unknown>;
|
|
107
|
+
}
|
|
108
|
+
interface SingleConnToolConfig<TInput extends z.ZodType, TApp extends AppRef = AppRef> extends WithInputDependencies<TInput>, WithResultProcessors {
|
|
109
|
+
name: string;
|
|
110
|
+
description: string;
|
|
111
|
+
connection: TApp;
|
|
112
|
+
connections?: never;
|
|
113
|
+
inputSchema: TInput;
|
|
114
|
+
run: (ctx: SingleConnectionToolContext, input: z.infer<TInput>) => Promise<unknown>;
|
|
115
|
+
}
|
|
116
|
+
interface MultiConnToolConfig<TInput extends z.ZodType, TConn extends Record<string, AppRef>> extends WithInputDependencies<TInput>, WithResultProcessors {
|
|
117
|
+
name: string;
|
|
118
|
+
description: string;
|
|
119
|
+
connection?: never;
|
|
120
|
+
connections: TConn;
|
|
121
|
+
inputSchema: TInput;
|
|
122
|
+
run: (ctx: MultiConnectionToolContext<TConn>, input: z.infer<TInput>) => Promise<unknown>;
|
|
123
|
+
}
|
|
124
|
+
interface ToolFnMeta<TInput extends z.ZodType, TConn extends AppRef | Record<string, AppRef> | undefined> extends WithInputDependencies<TInput>, WithResultProcessors {
|
|
125
|
+
kind: "tool";
|
|
126
|
+
name: string;
|
|
127
|
+
description: string;
|
|
128
|
+
connection: TConn extends AppRef ? TConn : undefined;
|
|
129
|
+
connections: TConn extends Record<string, AppRef> ? TConn : undefined;
|
|
130
|
+
inputSchema: TInput;
|
|
131
|
+
run: TConn extends Record<string, AppRef> ? (ctx: MultiConnectionToolContext<TConn>, input: z.infer<TInput>) => Promise<unknown> : TConn extends AppRef ? (ctx: SingleConnectionToolContext, input: z.infer<TInput>) => Promise<unknown> : (ctx: ToolContext, input: z.infer<TInput>) => Promise<unknown>;
|
|
132
|
+
describe(): DescribeResult;
|
|
133
|
+
}
|
|
134
|
+
type ToolFn<TInput extends z.ZodType, TConn extends AppRef | Record<string, AppRef>> = (TConn extends AppRef ? (input: z.infer<TInput>, opts: SingleConnExecuteOptions<TConn>) => Promise<unknown> : TConn extends Record<string, AppRef> ? (input: z.infer<TInput>, opts: MultiConnExecuteOptions<TConn>) => Promise<unknown> : never) & ToolFnMeta<TInput, TConn>;
|
|
135
|
+
type ConnectionlessToolFn<TInput extends z.ZodType> = ((input: z.infer<TInput>) => Promise<unknown>) & ToolFnMeta<TInput, undefined>;
|
|
136
|
+
interface ConnectionlessDurableConfig<TInput extends z.ZodType> extends WithInputDependencies<TInput> {
|
|
137
|
+
name: string;
|
|
138
|
+
description: string;
|
|
139
|
+
connection?: never;
|
|
140
|
+
connections?: never;
|
|
141
|
+
inputSchema: TInput;
|
|
142
|
+
run: (ctx: DurableContext, input: z.infer<TInput>) => Promise<unknown>;
|
|
143
|
+
}
|
|
144
|
+
interface SingleConnDurableConfig<TInput extends z.ZodType, TApp extends AppRef = AppRef> extends WithInputDependencies<TInput> {
|
|
145
|
+
name: string;
|
|
146
|
+
description: string;
|
|
147
|
+
connection: TApp;
|
|
148
|
+
connections?: never;
|
|
149
|
+
inputSchema: TInput;
|
|
150
|
+
run: (ctx: DurableContext & {
|
|
151
|
+
connection: string;
|
|
152
|
+
}, input: z.infer<TInput>) => Promise<unknown>;
|
|
153
|
+
}
|
|
154
|
+
interface MultiConnDurableConfig<TInput extends z.ZodType, TConn extends Record<string, AppRef>> extends WithInputDependencies<TInput> {
|
|
155
|
+
name: string;
|
|
156
|
+
description: string;
|
|
157
|
+
connection?: never;
|
|
158
|
+
connections: TConn;
|
|
159
|
+
inputSchema: TInput;
|
|
160
|
+
run: (ctx: DurableContext & {
|
|
161
|
+
connections: {
|
|
162
|
+
[K in keyof TConn]: string;
|
|
163
|
+
};
|
|
164
|
+
}, input: z.infer<TInput>) => Promise<unknown>;
|
|
165
|
+
}
|
|
166
|
+
interface DurableResult<T = unknown> {
|
|
167
|
+
done: boolean;
|
|
168
|
+
result?: T;
|
|
169
|
+
error?: Error;
|
|
170
|
+
executionId?: string;
|
|
171
|
+
}
|
|
172
|
+
interface DurableFnMeta<TInput extends z.ZodType, TConn extends AppRef | Record<string, AppRef> | undefined> extends WithInputDependencies<TInput> {
|
|
173
|
+
kind: "durable";
|
|
174
|
+
name: string;
|
|
175
|
+
description: string;
|
|
176
|
+
connection: TConn extends AppRef ? TConn : undefined;
|
|
177
|
+
connections: TConn extends Record<string, AppRef> ? TConn : undefined;
|
|
178
|
+
inputSchema: TInput;
|
|
179
|
+
run: TConn extends Record<string, AppRef> ? (ctx: DurableContext & {
|
|
180
|
+
connections: {
|
|
181
|
+
[K in keyof TConn]: string;
|
|
182
|
+
};
|
|
183
|
+
}, input: z.infer<TInput>) => Promise<unknown> : TConn extends AppRef ? (ctx: DurableContext & {
|
|
184
|
+
connection: string;
|
|
185
|
+
}, input: z.infer<TInput>) => Promise<unknown> : (ctx: DurableContext, input: z.infer<TInput>) => Promise<unknown>;
|
|
186
|
+
describe(): DescribeResult;
|
|
187
|
+
}
|
|
188
|
+
type ConnectionlessDurableFn<TInput extends z.ZodType> = ((input: z.infer<TInput>) => Promise<DurableResult>) & DurableFnMeta<TInput, undefined>;
|
|
189
|
+
type DurableFn<TInput extends z.ZodType, TConn extends AppRef | Record<string, AppRef>> = (TConn extends AppRef ? (input: z.infer<TInput>, opts: SingleConnExecuteOptions<TConn>) => Promise<DurableResult> : TConn extends Record<string, AppRef> ? (input: z.infer<TInput>, opts: MultiConnExecuteOptions<TConn>) => Promise<DurableResult> : never) & DurableFnMeta<TInput, TConn>;
|
|
190
|
+
interface ReservedComponentProps {
|
|
191
|
+
connection?: never;
|
|
192
|
+
connections?: never;
|
|
193
|
+
zapier?: never;
|
|
194
|
+
}
|
|
195
|
+
type AssertNoReservedComponentProps<TProps> = Extract<keyof TProps, keyof ReservedComponentProps> extends never ? TProps : never;
|
|
196
|
+
interface SingleConnectionCtx<TApp extends AppRef> {
|
|
197
|
+
connection: ConnectionId<TApp>;
|
|
198
|
+
connections?: never;
|
|
199
|
+
}
|
|
200
|
+
interface MultiConnectionCtx<TConn extends Record<string, AppRef>> {
|
|
201
|
+
connection?: never;
|
|
202
|
+
connections: {
|
|
203
|
+
[K in keyof TConn]: ConnectionId<TConn[K]>;
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
interface ConnectionlessComponentConfig<TProps> {
|
|
207
|
+
name: string;
|
|
208
|
+
description?: string;
|
|
209
|
+
connection?: never;
|
|
210
|
+
connections?: never;
|
|
211
|
+
render: (props: AssertNoReservedComponentProps<TProps> & ComponentCtx) => unknown;
|
|
212
|
+
}
|
|
213
|
+
interface SingleConnComponentConfig<TProps, TApp extends AppRef> {
|
|
214
|
+
name: string;
|
|
215
|
+
description?: string;
|
|
216
|
+
connection: TApp;
|
|
217
|
+
connections?: never;
|
|
218
|
+
render: (props: AssertNoReservedComponentProps<TProps> & SingleConnectionCtx<TApp> & ComponentCtx) => unknown;
|
|
219
|
+
}
|
|
220
|
+
interface MultiConnComponentConfig<TProps, TConn extends Record<string, AppRef>> {
|
|
221
|
+
name: string;
|
|
222
|
+
description?: string;
|
|
223
|
+
connection?: never;
|
|
224
|
+
connections: TConn;
|
|
225
|
+
render: (props: AssertNoReservedComponentProps<TProps> & MultiConnectionCtx<TConn> & ComponentCtx) => unknown;
|
|
226
|
+
}
|
|
227
|
+
type ComponentConfig<TProps> = ConnectionlessComponentConfig<TProps> | SingleConnComponentConfig<TProps, AppRef> | MultiConnComponentConfig<TProps, Record<string, AppRef>>;
|
|
228
|
+
type ComponentFn<TProps> = ((props: TProps) => unknown) & {
|
|
229
|
+
kind: "component";
|
|
230
|
+
name: string;
|
|
231
|
+
description?: string;
|
|
232
|
+
connection?: AppRef;
|
|
233
|
+
connections?: Record<string, AppRef>;
|
|
234
|
+
describe(): DescribeResult;
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
declare function defineTool<TInput extends z.ZodType>(config: ConnectionlessToolConfig<TInput>): ConnectionlessToolFn<TInput>;
|
|
238
|
+
declare function defineTool<TInput extends z.ZodType, TApp extends AppRef>(config: SingleConnToolConfig<TInput, TApp>): ToolFn<TInput, TApp>;
|
|
239
|
+
declare function defineTool<TInput extends z.ZodType, TConn extends Record<string, AppRef>>(config: MultiConnToolConfig<TInput, TConn>): ToolFn<TInput, TConn>;
|
|
240
|
+
declare function defineDurable<TInput extends z.ZodType>(config: ConnectionlessDurableConfig<TInput>): ConnectionlessDurableFn<TInput>;
|
|
241
|
+
declare function defineDurable<TInput extends z.ZodType, TApp extends AppRef>(config: SingleConnDurableConfig<TInput, TApp>): DurableFn<TInput, TApp>;
|
|
242
|
+
declare function defineDurable<TInput extends z.ZodType, TConn extends Record<string, AppRef>>(config: MultiConnDurableConfig<TInput, TConn>): DurableFn<TInput, TConn>;
|
|
243
|
+
declare function defineComponent<TProps>(config: ConnectionlessComponentConfig<TProps>): ComponentFn<TProps>;
|
|
244
|
+
declare function defineComponent<TProps, TApp extends AppRef>(config: SingleConnComponentConfig<TProps, TApp>): ComponentFn<TProps & SingleConnectionCtx<TApp>>;
|
|
245
|
+
declare function defineComponent<TProps, TConn extends Record<string, AppRef>>(config: MultiConnComponentConfig<TProps, TConn>): ComponentFn<TProps & MultiConnectionCtx<TConn>>;
|
|
246
|
+
|
|
247
|
+
declare function optionsFrom(tool: unknown, binds?: Record<string, {
|
|
248
|
+
$ref: string;
|
|
249
|
+
}>): ResolveDirective;
|
|
250
|
+
declare function schemaFrom(tool: unknown, binds?: Record<string, {
|
|
251
|
+
$ref: string;
|
|
252
|
+
}>): ResolveDirective;
|
|
253
|
+
|
|
254
|
+
export { AppRef, type AssertNoReservedComponentProps, type CallbackOptions, type ComponentConfig, type ComponentCtx, type ComponentFn, type ConnectionId, type ConnectionlessComponentConfig, type ConnectionlessDurableConfig, type ConnectionlessDurableFn, type ConnectionlessToolConfig, type ConnectionlessToolFn, type DefineContext, type DescribeResult, type DurableContext, type DurableFn, type DurableResult, type MultiConnComponentConfig, type MultiConnDurableConfig, type MultiConnExecuteOptions, type MultiConnToolConfig, type MultiConnectionCtx, type MultiConnectionToolContext, type RefProxy, type ReservedComponentProps, type ResolveDirective, type SingleConnComponentConfig, type SingleConnDurableConfig, type SingleConnExecuteOptions, type SingleConnToolConfig, type SingleConnectionCtx, type SingleConnectionToolContext, type StepOptions, type ToolContext, type ToolFn, type WaitOptions, type WithInputDependencies, type WithResultProcessors, type ZapierClient, defineComponent, defineDurable, defineTool, optionsFrom, schemaFrom };
|
package/dist/define.d.ts
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { AppRef } from './apps.js';
|
|
2
|
+
export { BuiltinApp } from './apps.js';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
|
|
5
|
+
interface ZapierClient {
|
|
6
|
+
fetch(url: string, options: {
|
|
7
|
+
connection?: string;
|
|
8
|
+
method?: string;
|
|
9
|
+
headers?: Record<string, string>;
|
|
10
|
+
body?: string | Record<string, unknown> | null;
|
|
11
|
+
timeout?: number;
|
|
12
|
+
}): Promise<Response>;
|
|
13
|
+
}
|
|
14
|
+
interface DefineContext {
|
|
15
|
+
zapier: ZapierClient;
|
|
16
|
+
}
|
|
17
|
+
interface StepOptions<T> {
|
|
18
|
+
name: string;
|
|
19
|
+
run: () => Promise<T>;
|
|
20
|
+
maxAttempts?: number;
|
|
21
|
+
retryDelaySeconds?: number;
|
|
22
|
+
outputSchema?: z.ZodSchema<T>;
|
|
23
|
+
}
|
|
24
|
+
interface WaitOptions {
|
|
25
|
+
name: string;
|
|
26
|
+
seconds: number;
|
|
27
|
+
}
|
|
28
|
+
interface CallbackOptions<T = unknown> {
|
|
29
|
+
name: string;
|
|
30
|
+
timeoutSeconds?: number;
|
|
31
|
+
payloadSchema?: z.ZodSchema<T>;
|
|
32
|
+
}
|
|
33
|
+
type ToolContext = DefineContext;
|
|
34
|
+
interface SingleConnectionToolContext extends DefineContext {
|
|
35
|
+
connection: string;
|
|
36
|
+
}
|
|
37
|
+
interface MultiConnectionToolContext<TConn extends Record<string, AppRef>> extends DefineContext {
|
|
38
|
+
connections: {
|
|
39
|
+
[K in keyof TConn]: string;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
interface DurableContext extends DefineContext {
|
|
43
|
+
step<T>(name: string, fn: () => Promise<T>): Promise<T>;
|
|
44
|
+
step<T>(options: StepOptions<T>): Promise<T>;
|
|
45
|
+
wait(name: string, seconds: number): Promise<void>;
|
|
46
|
+
wait(options: WaitOptions): Promise<void>;
|
|
47
|
+
createCallback(name: string): Promise<[Promise<unknown>, string]>;
|
|
48
|
+
createCallback<T>(options: CallbackOptions<T>): Promise<[Promise<T>, string]>;
|
|
49
|
+
}
|
|
50
|
+
type ComponentCtx = DefineContext;
|
|
51
|
+
declare const CONNECTION_BRAND: unique symbol;
|
|
52
|
+
type ConnectionId<TApp extends AppRef> = string & {
|
|
53
|
+
readonly [CONNECTION_BRAND]: TApp;
|
|
54
|
+
};
|
|
55
|
+
interface SingleConnExecuteOptions<TApp extends AppRef> {
|
|
56
|
+
connection: ConnectionId<TApp>;
|
|
57
|
+
}
|
|
58
|
+
interface MultiConnExecuteOptions<TConn extends Record<string, AppRef>> {
|
|
59
|
+
connections: {
|
|
60
|
+
[K in keyof TConn]: ConnectionId<TConn[K]>;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
type RefProxy<K extends string> = {
|
|
64
|
+
[P in K]: {
|
|
65
|
+
$ref: P;
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
type ResolveDirective = {
|
|
69
|
+
kind: "options";
|
|
70
|
+
tool: unknown;
|
|
71
|
+
binds?: Record<string, {
|
|
72
|
+
$ref: string;
|
|
73
|
+
}>;
|
|
74
|
+
} | {
|
|
75
|
+
kind: "schema";
|
|
76
|
+
tool: unknown;
|
|
77
|
+
binds?: Record<string, {
|
|
78
|
+
$ref: string;
|
|
79
|
+
}>;
|
|
80
|
+
};
|
|
81
|
+
interface WithInputDependencies<TInput extends z.ZodType> {
|
|
82
|
+
inputDependencies?: ($: RefProxy<keyof z.infer<TInput> & string>) => Record<string, ResolveDirective>;
|
|
83
|
+
}
|
|
84
|
+
interface WithResultProcessors {
|
|
85
|
+
options?: (result: unknown) => Array<{
|
|
86
|
+
label: string;
|
|
87
|
+
value: string;
|
|
88
|
+
}>;
|
|
89
|
+
schema?: (result: unknown) => z.ZodType;
|
|
90
|
+
digest?: (result: unknown) => unknown;
|
|
91
|
+
}
|
|
92
|
+
interface DescribeResult {
|
|
93
|
+
kind: "tool" | "durable" | "component";
|
|
94
|
+
name: string;
|
|
95
|
+
description?: string;
|
|
96
|
+
inputSchema?: Record<string, unknown>;
|
|
97
|
+
connection?: AppRef;
|
|
98
|
+
connections?: Record<string, AppRef>;
|
|
99
|
+
}
|
|
100
|
+
interface ConnectionlessToolConfig<TInput extends z.ZodType> extends WithInputDependencies<TInput>, WithResultProcessors {
|
|
101
|
+
name: string;
|
|
102
|
+
description: string;
|
|
103
|
+
connection?: never;
|
|
104
|
+
connections?: never;
|
|
105
|
+
inputSchema: TInput;
|
|
106
|
+
run: (ctx: ToolContext, input: z.infer<TInput>) => Promise<unknown>;
|
|
107
|
+
}
|
|
108
|
+
interface SingleConnToolConfig<TInput extends z.ZodType, TApp extends AppRef = AppRef> extends WithInputDependencies<TInput>, WithResultProcessors {
|
|
109
|
+
name: string;
|
|
110
|
+
description: string;
|
|
111
|
+
connection: TApp;
|
|
112
|
+
connections?: never;
|
|
113
|
+
inputSchema: TInput;
|
|
114
|
+
run: (ctx: SingleConnectionToolContext, input: z.infer<TInput>) => Promise<unknown>;
|
|
115
|
+
}
|
|
116
|
+
interface MultiConnToolConfig<TInput extends z.ZodType, TConn extends Record<string, AppRef>> extends WithInputDependencies<TInput>, WithResultProcessors {
|
|
117
|
+
name: string;
|
|
118
|
+
description: string;
|
|
119
|
+
connection?: never;
|
|
120
|
+
connections: TConn;
|
|
121
|
+
inputSchema: TInput;
|
|
122
|
+
run: (ctx: MultiConnectionToolContext<TConn>, input: z.infer<TInput>) => Promise<unknown>;
|
|
123
|
+
}
|
|
124
|
+
interface ToolFnMeta<TInput extends z.ZodType, TConn extends AppRef | Record<string, AppRef> | undefined> extends WithInputDependencies<TInput>, WithResultProcessors {
|
|
125
|
+
kind: "tool";
|
|
126
|
+
name: string;
|
|
127
|
+
description: string;
|
|
128
|
+
connection: TConn extends AppRef ? TConn : undefined;
|
|
129
|
+
connections: TConn extends Record<string, AppRef> ? TConn : undefined;
|
|
130
|
+
inputSchema: TInput;
|
|
131
|
+
run: TConn extends Record<string, AppRef> ? (ctx: MultiConnectionToolContext<TConn>, input: z.infer<TInput>) => Promise<unknown> : TConn extends AppRef ? (ctx: SingleConnectionToolContext, input: z.infer<TInput>) => Promise<unknown> : (ctx: ToolContext, input: z.infer<TInput>) => Promise<unknown>;
|
|
132
|
+
describe(): DescribeResult;
|
|
133
|
+
}
|
|
134
|
+
type ToolFn<TInput extends z.ZodType, TConn extends AppRef | Record<string, AppRef>> = (TConn extends AppRef ? (input: z.infer<TInput>, opts: SingleConnExecuteOptions<TConn>) => Promise<unknown> : TConn extends Record<string, AppRef> ? (input: z.infer<TInput>, opts: MultiConnExecuteOptions<TConn>) => Promise<unknown> : never) & ToolFnMeta<TInput, TConn>;
|
|
135
|
+
type ConnectionlessToolFn<TInput extends z.ZodType> = ((input: z.infer<TInput>) => Promise<unknown>) & ToolFnMeta<TInput, undefined>;
|
|
136
|
+
interface ConnectionlessDurableConfig<TInput extends z.ZodType> extends WithInputDependencies<TInput> {
|
|
137
|
+
name: string;
|
|
138
|
+
description: string;
|
|
139
|
+
connection?: never;
|
|
140
|
+
connections?: never;
|
|
141
|
+
inputSchema: TInput;
|
|
142
|
+
run: (ctx: DurableContext, input: z.infer<TInput>) => Promise<unknown>;
|
|
143
|
+
}
|
|
144
|
+
interface SingleConnDurableConfig<TInput extends z.ZodType, TApp extends AppRef = AppRef> extends WithInputDependencies<TInput> {
|
|
145
|
+
name: string;
|
|
146
|
+
description: string;
|
|
147
|
+
connection: TApp;
|
|
148
|
+
connections?: never;
|
|
149
|
+
inputSchema: TInput;
|
|
150
|
+
run: (ctx: DurableContext & {
|
|
151
|
+
connection: string;
|
|
152
|
+
}, input: z.infer<TInput>) => Promise<unknown>;
|
|
153
|
+
}
|
|
154
|
+
interface MultiConnDurableConfig<TInput extends z.ZodType, TConn extends Record<string, AppRef>> extends WithInputDependencies<TInput> {
|
|
155
|
+
name: string;
|
|
156
|
+
description: string;
|
|
157
|
+
connection?: never;
|
|
158
|
+
connections: TConn;
|
|
159
|
+
inputSchema: TInput;
|
|
160
|
+
run: (ctx: DurableContext & {
|
|
161
|
+
connections: {
|
|
162
|
+
[K in keyof TConn]: string;
|
|
163
|
+
};
|
|
164
|
+
}, input: z.infer<TInput>) => Promise<unknown>;
|
|
165
|
+
}
|
|
166
|
+
interface DurableResult<T = unknown> {
|
|
167
|
+
done: boolean;
|
|
168
|
+
result?: T;
|
|
169
|
+
error?: Error;
|
|
170
|
+
executionId?: string;
|
|
171
|
+
}
|
|
172
|
+
interface DurableFnMeta<TInput extends z.ZodType, TConn extends AppRef | Record<string, AppRef> | undefined> extends WithInputDependencies<TInput> {
|
|
173
|
+
kind: "durable";
|
|
174
|
+
name: string;
|
|
175
|
+
description: string;
|
|
176
|
+
connection: TConn extends AppRef ? TConn : undefined;
|
|
177
|
+
connections: TConn extends Record<string, AppRef> ? TConn : undefined;
|
|
178
|
+
inputSchema: TInput;
|
|
179
|
+
run: TConn extends Record<string, AppRef> ? (ctx: DurableContext & {
|
|
180
|
+
connections: {
|
|
181
|
+
[K in keyof TConn]: string;
|
|
182
|
+
};
|
|
183
|
+
}, input: z.infer<TInput>) => Promise<unknown> : TConn extends AppRef ? (ctx: DurableContext & {
|
|
184
|
+
connection: string;
|
|
185
|
+
}, input: z.infer<TInput>) => Promise<unknown> : (ctx: DurableContext, input: z.infer<TInput>) => Promise<unknown>;
|
|
186
|
+
describe(): DescribeResult;
|
|
187
|
+
}
|
|
188
|
+
type ConnectionlessDurableFn<TInput extends z.ZodType> = ((input: z.infer<TInput>) => Promise<DurableResult>) & DurableFnMeta<TInput, undefined>;
|
|
189
|
+
type DurableFn<TInput extends z.ZodType, TConn extends AppRef | Record<string, AppRef>> = (TConn extends AppRef ? (input: z.infer<TInput>, opts: SingleConnExecuteOptions<TConn>) => Promise<DurableResult> : TConn extends Record<string, AppRef> ? (input: z.infer<TInput>, opts: MultiConnExecuteOptions<TConn>) => Promise<DurableResult> : never) & DurableFnMeta<TInput, TConn>;
|
|
190
|
+
interface ReservedComponentProps {
|
|
191
|
+
connection?: never;
|
|
192
|
+
connections?: never;
|
|
193
|
+
zapier?: never;
|
|
194
|
+
}
|
|
195
|
+
type AssertNoReservedComponentProps<TProps> = Extract<keyof TProps, keyof ReservedComponentProps> extends never ? TProps : never;
|
|
196
|
+
interface SingleConnectionCtx<TApp extends AppRef> {
|
|
197
|
+
connection: ConnectionId<TApp>;
|
|
198
|
+
connections?: never;
|
|
199
|
+
}
|
|
200
|
+
interface MultiConnectionCtx<TConn extends Record<string, AppRef>> {
|
|
201
|
+
connection?: never;
|
|
202
|
+
connections: {
|
|
203
|
+
[K in keyof TConn]: ConnectionId<TConn[K]>;
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
interface ConnectionlessComponentConfig<TProps> {
|
|
207
|
+
name: string;
|
|
208
|
+
description?: string;
|
|
209
|
+
connection?: never;
|
|
210
|
+
connections?: never;
|
|
211
|
+
render: (props: AssertNoReservedComponentProps<TProps> & ComponentCtx) => unknown;
|
|
212
|
+
}
|
|
213
|
+
interface SingleConnComponentConfig<TProps, TApp extends AppRef> {
|
|
214
|
+
name: string;
|
|
215
|
+
description?: string;
|
|
216
|
+
connection: TApp;
|
|
217
|
+
connections?: never;
|
|
218
|
+
render: (props: AssertNoReservedComponentProps<TProps> & SingleConnectionCtx<TApp> & ComponentCtx) => unknown;
|
|
219
|
+
}
|
|
220
|
+
interface MultiConnComponentConfig<TProps, TConn extends Record<string, AppRef>> {
|
|
221
|
+
name: string;
|
|
222
|
+
description?: string;
|
|
223
|
+
connection?: never;
|
|
224
|
+
connections: TConn;
|
|
225
|
+
render: (props: AssertNoReservedComponentProps<TProps> & MultiConnectionCtx<TConn> & ComponentCtx) => unknown;
|
|
226
|
+
}
|
|
227
|
+
type ComponentConfig<TProps> = ConnectionlessComponentConfig<TProps> | SingleConnComponentConfig<TProps, AppRef> | MultiConnComponentConfig<TProps, Record<string, AppRef>>;
|
|
228
|
+
type ComponentFn<TProps> = ((props: TProps) => unknown) & {
|
|
229
|
+
kind: "component";
|
|
230
|
+
name: string;
|
|
231
|
+
description?: string;
|
|
232
|
+
connection?: AppRef;
|
|
233
|
+
connections?: Record<string, AppRef>;
|
|
234
|
+
describe(): DescribeResult;
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
declare function defineTool<TInput extends z.ZodType>(config: ConnectionlessToolConfig<TInput>): ConnectionlessToolFn<TInput>;
|
|
238
|
+
declare function defineTool<TInput extends z.ZodType, TApp extends AppRef>(config: SingleConnToolConfig<TInput, TApp>): ToolFn<TInput, TApp>;
|
|
239
|
+
declare function defineTool<TInput extends z.ZodType, TConn extends Record<string, AppRef>>(config: MultiConnToolConfig<TInput, TConn>): ToolFn<TInput, TConn>;
|
|
240
|
+
declare function defineDurable<TInput extends z.ZodType>(config: ConnectionlessDurableConfig<TInput>): ConnectionlessDurableFn<TInput>;
|
|
241
|
+
declare function defineDurable<TInput extends z.ZodType, TApp extends AppRef>(config: SingleConnDurableConfig<TInput, TApp>): DurableFn<TInput, TApp>;
|
|
242
|
+
declare function defineDurable<TInput extends z.ZodType, TConn extends Record<string, AppRef>>(config: MultiConnDurableConfig<TInput, TConn>): DurableFn<TInput, TConn>;
|
|
243
|
+
declare function defineComponent<TProps>(config: ConnectionlessComponentConfig<TProps>): ComponentFn<TProps>;
|
|
244
|
+
declare function defineComponent<TProps, TApp extends AppRef>(config: SingleConnComponentConfig<TProps, TApp>): ComponentFn<TProps & SingleConnectionCtx<TApp>>;
|
|
245
|
+
declare function defineComponent<TProps, TConn extends Record<string, AppRef>>(config: MultiConnComponentConfig<TProps, TConn>): ComponentFn<TProps & MultiConnectionCtx<TConn>>;
|
|
246
|
+
|
|
247
|
+
declare function optionsFrom(tool: unknown, binds?: Record<string, {
|
|
248
|
+
$ref: string;
|
|
249
|
+
}>): ResolveDirective;
|
|
250
|
+
declare function schemaFrom(tool: unknown, binds?: Record<string, {
|
|
251
|
+
$ref: string;
|
|
252
|
+
}>): ResolveDirective;
|
|
253
|
+
|
|
254
|
+
export { AppRef, type AssertNoReservedComponentProps, type CallbackOptions, type ComponentConfig, type ComponentCtx, type ComponentFn, type ConnectionId, type ConnectionlessComponentConfig, type ConnectionlessDurableConfig, type ConnectionlessDurableFn, type ConnectionlessToolConfig, type ConnectionlessToolFn, type DefineContext, type DescribeResult, type DurableContext, type DurableFn, type DurableResult, type MultiConnComponentConfig, type MultiConnDurableConfig, type MultiConnExecuteOptions, type MultiConnToolConfig, type MultiConnectionCtx, type MultiConnectionToolContext, type RefProxy, type ReservedComponentProps, type ResolveDirective, type SingleConnComponentConfig, type SingleConnDurableConfig, type SingleConnExecuteOptions, type SingleConnToolConfig, type SingleConnectionCtx, type SingleConnectionToolContext, type StepOptions, type ToolContext, type ToolFn, type WaitOptions, type WithInputDependencies, type WithResultProcessors, type ZapierClient, defineComponent, defineDurable, defineTool, optionsFrom, schemaFrom };
|
package/dist/define.mjs
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
// src/define/define.ts
|
|
2
|
+
function toJsonSchema(schema) {
|
|
3
|
+
return schema.toJSONSchema();
|
|
4
|
+
}
|
|
5
|
+
function buildDescribe(meta) {
|
|
6
|
+
return () => ({
|
|
7
|
+
kind: meta.kind,
|
|
8
|
+
name: meta.name,
|
|
9
|
+
description: meta.description,
|
|
10
|
+
inputSchema: meta.inputSchema ? toJsonSchema(meta.inputSchema) : void 0,
|
|
11
|
+
connection: meta.connection,
|
|
12
|
+
connections: meta.connections
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
function defineTool(config) {
|
|
16
|
+
const execute = () => {
|
|
17
|
+
throw new Error(
|
|
18
|
+
`defineTool("${config.name}") is not callable yet. Runtime resolution is coming in Phase 2.`
|
|
19
|
+
);
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(execute, "name", {
|
|
22
|
+
value: config.name,
|
|
23
|
+
writable: false
|
|
24
|
+
});
|
|
25
|
+
return Object.assign(execute, {
|
|
26
|
+
kind: "tool",
|
|
27
|
+
description: config.description,
|
|
28
|
+
connection: config.connection,
|
|
29
|
+
connections: config.connections,
|
|
30
|
+
inputSchema: config.inputSchema,
|
|
31
|
+
inputDependencies: config.inputDependencies,
|
|
32
|
+
run: config.run,
|
|
33
|
+
options: config.options,
|
|
34
|
+
schema: config.schema,
|
|
35
|
+
digest: config.digest,
|
|
36
|
+
describe: buildDescribe({
|
|
37
|
+
kind: "tool",
|
|
38
|
+
name: config.name,
|
|
39
|
+
description: config.description,
|
|
40
|
+
inputSchema: config.inputSchema,
|
|
41
|
+
connection: config.connection,
|
|
42
|
+
connections: config.connections
|
|
43
|
+
})
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
function defineDurable(config) {
|
|
47
|
+
const execute = () => {
|
|
48
|
+
throw new Error(
|
|
49
|
+
`defineDurable("${config.name}") is not callable yet. Runtime resolution is coming in Phase 2.`
|
|
50
|
+
);
|
|
51
|
+
};
|
|
52
|
+
Object.defineProperty(execute, "name", {
|
|
53
|
+
value: config.name,
|
|
54
|
+
writable: false
|
|
55
|
+
});
|
|
56
|
+
return Object.assign(execute, {
|
|
57
|
+
kind: "durable",
|
|
58
|
+
description: config.description,
|
|
59
|
+
connection: config.connection,
|
|
60
|
+
connections: config.connections,
|
|
61
|
+
inputSchema: config.inputSchema,
|
|
62
|
+
inputDependencies: config.inputDependencies,
|
|
63
|
+
run: config.run,
|
|
64
|
+
describe: buildDescribe({
|
|
65
|
+
kind: "durable",
|
|
66
|
+
name: config.name,
|
|
67
|
+
description: config.description,
|
|
68
|
+
inputSchema: config.inputSchema,
|
|
69
|
+
connection: config.connection,
|
|
70
|
+
connections: config.connections
|
|
71
|
+
})
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
function defineComponent(config) {
|
|
75
|
+
const component = () => {
|
|
76
|
+
throw new Error(
|
|
77
|
+
`defineComponent("${config.name}") is not callable yet. Runtime resolution is coming in Phase 2.`
|
|
78
|
+
);
|
|
79
|
+
};
|
|
80
|
+
Object.defineProperty(component, "name", {
|
|
81
|
+
value: config.name,
|
|
82
|
+
writable: false
|
|
83
|
+
});
|
|
84
|
+
return Object.assign(component, {
|
|
85
|
+
kind: "component",
|
|
86
|
+
description: config.description,
|
|
87
|
+
connection: "connection" in config ? config.connection : void 0,
|
|
88
|
+
connections: "connections" in config ? config.connections : void 0,
|
|
89
|
+
describe: buildDescribe({
|
|
90
|
+
kind: "component",
|
|
91
|
+
name: config.name,
|
|
92
|
+
description: config.description,
|
|
93
|
+
connection: "connection" in config ? config.connection : void 0,
|
|
94
|
+
connections: "connections" in config ? config.connections : void 0
|
|
95
|
+
})
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// src/define/helpers.ts
|
|
100
|
+
function optionsFrom(tool, binds) {
|
|
101
|
+
return { kind: "options", tool, binds };
|
|
102
|
+
}
|
|
103
|
+
function schemaFrom(tool, binds) {
|
|
104
|
+
return { kind: "schema", tool, binds };
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export { defineComponent, defineDurable, defineTool, optionsFrom, schemaFrom };
|