@zapier/zapier-sdk 0.8.3 → 0.10.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 +18 -0
- package/README.md +17 -40
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.js +14 -0
- package/dist/api/debug.d.ts +1 -0
- package/dist/api/debug.d.ts.map +1 -1
- package/dist/api/debug.js +42 -1
- package/dist/api/debug.test.d.ts +2 -0
- package/dist/api/debug.test.d.ts.map +1 -0
- package/dist/api/debug.test.js +59 -0
- package/dist/api/schemas.d.ts +451 -251
- package/dist/api/schemas.d.ts.map +1 -1
- package/dist/api/schemas.js +51 -29
- package/dist/index.cjs +1149 -751
- package/dist/index.d.mts +2359 -2161
- package/dist/index.d.ts +3 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -4
- package/dist/index.mjs +1143 -743
- package/dist/plugins/apps/index.d.ts +4 -0
- package/dist/plugins/apps/index.d.ts.map +1 -1
- package/dist/plugins/findFirstAuthentication/index.d.ts +1 -1
- package/dist/plugins/findFirstAuthentication/index.d.ts.map +1 -1
- package/dist/plugins/findFirstAuthentication/index.js +9 -1
- package/dist/plugins/findFirstAuthentication/index.test.js +3 -4
- package/dist/plugins/findFirstAuthentication/schemas.d.ts +5 -3
- package/dist/plugins/findFirstAuthentication/schemas.d.ts.map +1 -1
- package/dist/plugins/findUniqueAuthentication/index.d.ts.map +1 -1
- package/dist/plugins/findUniqueAuthentication/index.js +4 -0
- package/dist/plugins/findUniqueAuthentication/schemas.d.ts +5 -3
- package/dist/plugins/findUniqueAuthentication/schemas.d.ts.map +1 -1
- package/dist/plugins/getAction/index.d.ts.map +1 -1
- package/dist/plugins/getAction/index.js +10 -0
- package/dist/plugins/getAction/schemas.d.ts +5 -3
- package/dist/plugins/getAction/schemas.d.ts.map +1 -1
- package/dist/plugins/getApp/index.d.ts +2 -7
- package/dist/plugins/getApp/index.d.ts.map +1 -1
- package/dist/plugins/getApp/index.js +17 -9
- package/dist/plugins/getApp/index.test.js +3 -3
- package/dist/plugins/getApp/schemas.d.ts +3 -1
- package/dist/plugins/getApp/schemas.d.ts.map +1 -1
- package/dist/plugins/getApp/schemas.js +2 -4
- package/dist/plugins/getAuthentication/index.d.ts.map +1 -1
- package/dist/plugins/getAuthentication/index.js +8 -0
- package/dist/plugins/getAuthentication/index.test.js +1 -1
- package/dist/plugins/getProfile/index.d.ts.map +1 -1
- package/dist/plugins/getProfile/index.js +4 -0
- package/dist/plugins/getProfile/schemas.d.ts.map +1 -1
- package/dist/plugins/getProfile/schemas.js +4 -3
- package/dist/plugins/listActions/index.d.ts +2 -4
- package/dist/plugins/listActions/index.d.ts.map +1 -1
- package/dist/plugins/listActions/index.js +10 -1
- package/dist/plugins/listActions/index.test.js +4 -4
- package/dist/plugins/listActions/schemas.d.ts +5 -3
- package/dist/plugins/listActions/schemas.d.ts.map +1 -1
- package/dist/plugins/listActions/schemas.js +2 -4
- package/dist/plugins/listApps/index.d.ts +4 -7
- package/dist/plugins/listApps/index.d.ts.map +1 -1
- package/dist/plugins/listApps/index.js +37 -17
- package/dist/plugins/listApps/index.test.js +23 -3
- package/dist/plugins/listApps/schemas.d.ts.map +1 -1
- package/dist/plugins/listApps/schemas.js +3 -9
- package/dist/plugins/listAuthentications/index.d.ts +2 -4
- package/dist/plugins/listAuthentications/index.d.ts.map +1 -1
- package/dist/plugins/listAuthentications/index.js +12 -0
- package/dist/plugins/listAuthentications/index.test.js +39 -13
- package/dist/plugins/listAuthentications/schemas.d.ts +8 -3
- package/dist/plugins/listAuthentications/schemas.d.ts.map +1 -1
- package/dist/plugins/listAuthentications/schemas.js +4 -0
- package/dist/plugins/listInputFieldChoices/index.d.ts.map +1 -1
- package/dist/plugins/listInputFieldChoices/index.js +14 -2
- package/dist/plugins/listInputFieldChoices/schemas.d.ts +5 -3
- package/dist/plugins/listInputFieldChoices/schemas.d.ts.map +1 -1
- package/dist/plugins/listInputFieldChoices/schemas.js +10 -19
- package/dist/plugins/listInputFields/index.d.ts.map +1 -1
- package/dist/plugins/listInputFields/index.js +14 -2
- package/dist/plugins/listInputFields/index.test.js +5 -9
- package/dist/plugins/listInputFields/schemas.d.ts +5 -3
- package/dist/plugins/listInputFields/schemas.d.ts.map +1 -1
- package/dist/plugins/manifest/index.d.ts +25 -9
- package/dist/plugins/manifest/index.d.ts.map +1 -1
- package/dist/plugins/manifest/index.js +239 -67
- package/dist/plugins/manifest/index.test.js +426 -171
- package/dist/plugins/manifest/schemas.d.ts +5 -1
- package/dist/plugins/manifest/schemas.d.ts.map +1 -1
- package/dist/plugins/manifest/schemas.js +1 -0
- package/dist/plugins/registry/index.d.ts.map +1 -1
- package/dist/plugins/registry/index.js +8 -2
- package/dist/plugins/request/index.d.ts.map +1 -1
- package/dist/plugins/request/index.js +1 -0
- package/dist/plugins/runAction/index.d.ts.map +1 -1
- package/dist/plugins/runAction/index.js +12 -0
- package/dist/plugins/runAction/schemas.d.ts +5 -3
- package/dist/plugins/runAction/schemas.d.ts.map +1 -1
- package/dist/resolvers/actionKey.d.ts +13 -7
- package/dist/resolvers/actionKey.d.ts.map +1 -1
- package/dist/resolvers/actionType.d.ts +8 -7
- package/dist/resolvers/actionType.d.ts.map +1 -1
- package/dist/resolvers/appKey.d.ts +2 -6
- package/dist/resolvers/appKey.d.ts.map +1 -1
- package/dist/resolvers/authenticationId.d.ts +7 -7
- package/dist/resolvers/authenticationId.d.ts.map +1 -1
- package/dist/resolvers/authenticationId.js +16 -7
- package/dist/resolvers/index.d.ts +3 -35
- package/dist/resolvers/index.d.ts.map +1 -1
- package/dist/resolvers/index.js +4 -87
- package/dist/resolvers/inputFieldKey.d.ts +11 -0
- package/dist/resolvers/inputFieldKey.d.ts.map +1 -0
- package/dist/resolvers/inputFieldKey.js +23 -0
- package/dist/resolvers/inputs.d.ts +11 -6
- package/dist/resolvers/inputs.d.ts.map +1 -1
- package/dist/resolvers/inputs.js +17 -0
- package/dist/schemas/Action.d.ts +8 -8
- package/dist/schemas/Action.d.ts.map +1 -1
- package/dist/schemas/Action.js +8 -3
- package/dist/schemas/App.d.ts +183 -11
- package/dist/schemas/App.d.ts.map +1 -1
- package/dist/schemas/App.js +7 -9
- package/dist/schemas/Auth.d.ts +12 -12
- package/dist/schemas/Auth.js +1 -1
- package/dist/schemas/Field.d.ts +5 -98
- package/dist/schemas/Field.d.ts.map +1 -1
- package/dist/schemas/Field.js +24 -52
- package/dist/schemas/Run.d.ts +3 -0
- package/dist/schemas/Run.d.ts.map +1 -0
- package/dist/schemas/Run.js +31 -0
- package/dist/schemas/UserProfile.d.ts +11 -11
- package/dist/schemas/UserProfile.d.ts.map +1 -1
- package/dist/schemas/UserProfile.js +21 -7
- package/dist/sdk.d.ts +15 -14
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +1 -4
- package/dist/types/plugin.d.ts +6 -0
- package/dist/types/plugin.d.ts.map +1 -1
- package/dist/types/properties.d.ts +3 -1
- package/dist/types/properties.d.ts.map +1 -1
- package/dist/types/sdk.d.ts +11 -3
- package/dist/types/sdk.d.ts.map +1 -1
- package/dist/utils/domain-utils.d.ts +17 -16
- package/dist/utils/domain-utils.d.ts.map +1 -1
- package/dist/utils/domain-utils.js +53 -78
- package/dist/utils/domain-utils.test.js +157 -3
- package/dist/utils/file-utils.d.ts +4 -0
- package/dist/utils/file-utils.d.ts.map +1 -0
- package/dist/utils/file-utils.js +74 -0
- package/dist/utils/file-utils.test.d.ts +2 -0
- package/dist/utils/file-utils.test.d.ts.map +1 -0
- package/dist/utils/file-utils.test.js +51 -0
- package/dist/utils/schema-utils.d.ts +44 -21
- package/dist/utils/schema-utils.d.ts.map +1 -1
- package/dist/utils/schema-utils.js +17 -11
- package/package.json +1 -1
- package/src/api/client.ts +12 -0
- package/src/api/debug.test.ts +76 -0
- package/src/api/debug.ts +46 -2
- package/src/api/schemas.ts +51 -29
- package/src/index.ts +5 -6
- package/src/plugins/apps/index.ts +9 -2
- package/src/plugins/findFirstAuthentication/index.test.ts +8 -5
- package/src/plugins/findFirstAuthentication/index.ts +14 -2
- package/src/plugins/findUniqueAuthentication/index.ts +4 -0
- package/src/plugins/getAction/index.ts +14 -0
- package/src/plugins/getApp/index.test.ts +3 -3
- package/src/plugins/getApp/index.ts +20 -14
- package/src/plugins/getApp/schemas.ts +7 -12
- package/src/plugins/getAuthentication/index.test.ts +1 -1
- package/src/plugins/getAuthentication/index.ts +8 -0
- package/src/plugins/getProfile/index.ts +4 -0
- package/src/plugins/getProfile/schemas.ts +4 -6
- package/src/plugins/listActions/index.test.ts +8 -7
- package/src/plugins/listActions/index.ts +12 -3
- package/src/plugins/listActions/schemas.ts +20 -25
- package/src/plugins/listApps/index.test.ts +24 -3
- package/src/plugins/listApps/index.ts +50 -25
- package/src/plugins/listApps/schemas.ts +17 -26
- package/src/plugins/listAuthentications/index.test.ts +52 -15
- package/src/plugins/listAuthentications/index.ts +15 -2
- package/src/plugins/listAuthentications/schemas.ts +4 -0
- package/src/plugins/listInputFieldChoices/index.ts +21 -1
- package/src/plugins/listInputFieldChoices/schemas.ts +61 -76
- package/src/plugins/listInputFields/index.test.ts +5 -9
- package/src/plugins/listInputFields/index.ts +20 -2
- package/src/plugins/manifest/index.test.ts +503 -197
- package/src/plugins/manifest/index.ts +338 -82
- package/src/plugins/manifest/schemas.ts +9 -2
- package/src/plugins/registry/index.ts +8 -2
- package/src/plugins/request/index.ts +1 -0
- package/src/plugins/runAction/index.ts +18 -0
- package/src/resolvers/actionKey.ts +15 -13
- package/src/resolvers/actionType.ts +10 -12
- package/src/resolvers/appKey.ts +2 -6
- package/src/resolvers/authenticationId.ts +25 -19
- package/src/resolvers/index.ts +7 -113
- package/src/resolvers/inputFieldKey.ts +38 -0
- package/src/resolvers/inputs.ts +28 -10
- package/src/schemas/Action.ts +8 -3
- package/src/schemas/App.ts +7 -9
- package/src/schemas/Auth.ts +1 -1
- package/src/schemas/Field.ts +24 -57
- package/src/schemas/Run.ts +40 -0
- package/src/schemas/UserProfile.ts +24 -7
- package/src/sdk.ts +18 -12
- package/src/types/plugin.ts +8 -0
- package/src/types/sdk.ts +31 -21
- package/src/utils/domain-utils.test.ts +196 -2
- package/src/utils/domain-utils.ts +77 -102
- package/src/utils/file-utils.test.ts +73 -0
- package/src/utils/file-utils.ts +94 -0
- package/src/utils/schema-utils.ts +96 -44
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/plugins/lockVersion/index.d.ts +0 -24
- package/dist/plugins/lockVersion/index.d.ts.map +0 -1
- package/dist/plugins/lockVersion/index.js +0 -72
- package/dist/plugins/lockVersion/index.test.d.ts +0 -2
- package/dist/plugins/lockVersion/index.test.d.ts.map +0 -1
- package/dist/plugins/lockVersion/index.test.js +0 -129
- package/dist/plugins/lockVersion/schemas.d.ts +0 -10
- package/dist/plugins/lockVersion/schemas.d.ts.map +0 -1
- package/dist/plugins/lockVersion/schemas.js +0 -6
- package/src/plugins/lockVersion/index.test.ts +0 -176
- package/src/plugins/lockVersion/index.ts +0 -112
- package/src/plugins/lockVersion/schemas.ts +0 -9
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { DynamicResolver } from "../utils/schema-utils";
|
|
2
|
+
import type { AuthItem } from "../schemas/Auth";
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
type: "dynamic";
|
|
5
|
-
depends: readonly string[];
|
|
6
|
-
fetch: (
|
|
7
|
-
sdk: ZapierSdk,
|
|
8
|
-
resolvedParams: Record<string, any>,
|
|
9
|
-
) => Promise<any[]>;
|
|
10
|
-
prompt: (items: any[], params: Record<string, any>) => any;
|
|
11
|
-
}
|
|
4
|
+
type AuthenticationIdResolver = DynamicResolver<AuthItem, { appKey?: string }>;
|
|
12
5
|
|
|
13
6
|
export const authenticationIdResolver: AuthenticationIdResolver = {
|
|
14
7
|
type: "dynamic",
|
|
15
8
|
depends: ["appKey"] as const,
|
|
16
|
-
fetch: async (sdk
|
|
17
|
-
const
|
|
18
|
-
appKey: resolvedParams.appKey,
|
|
9
|
+
fetch: async (sdk, resolvedParams) => {
|
|
10
|
+
const listOptions: { maxItems: number; appKey?: string } = {
|
|
19
11
|
maxItems: 1000,
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
if (resolvedParams.appKey) {
|
|
15
|
+
listOptions.appKey = resolvedParams.appKey;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const myAuths = await sdk.listAuthentications({
|
|
19
|
+
...listOptions,
|
|
20
20
|
owner: "me",
|
|
21
21
|
});
|
|
22
|
-
const allAuths = await sdk.listAuthentications(
|
|
23
|
-
|
|
24
|
-
maxItems: 1000,
|
|
25
|
-
});
|
|
22
|
+
const allAuths = await sdk.listAuthentications(listOptions);
|
|
23
|
+
|
|
26
24
|
// Filter out myAuths from allAuths
|
|
27
25
|
const otherAuths = allAuths.data.filter(
|
|
28
26
|
(auth) => !myAuths.data.some((myAuth) => myAuth.id === auth.id),
|
|
29
27
|
);
|
|
30
28
|
return [...myAuths.data, ...otherAuths];
|
|
31
29
|
},
|
|
32
|
-
prompt: (auths
|
|
30
|
+
prompt: (auths, params) => ({
|
|
33
31
|
type: "list",
|
|
34
32
|
name: "authenticationId",
|
|
35
|
-
message:
|
|
33
|
+
message: params.appKey
|
|
34
|
+
? `Select authentication for ${params.appKey}:`
|
|
35
|
+
: "Select authentication:",
|
|
36
36
|
choices: [
|
|
37
37
|
...auths.map((auth) => ({
|
|
38
38
|
name: `${auth.title || auth.label || "Authentication"} (ID: ${auth.id})`,
|
|
@@ -45,3 +45,9 @@ export const authenticationIdResolver: AuthenticationIdResolver = {
|
|
|
45
45
|
],
|
|
46
46
|
}),
|
|
47
47
|
};
|
|
48
|
+
|
|
49
|
+
// Generic version without appKey dependency
|
|
50
|
+
export const authenticationIdGenericResolver: AuthenticationIdResolver = {
|
|
51
|
+
...authenticationIdResolver,
|
|
52
|
+
depends: [] as const,
|
|
53
|
+
};
|
package/src/resolvers/index.ts
CHANGED
|
@@ -1,117 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
import { actionTypeResolver } from "./actionType";
|
|
3
|
-
import { actionKeyResolver } from "./actionKey";
|
|
4
|
-
import { authenticationIdResolver } from "./authenticationId";
|
|
5
|
-
import { inputsResolver } from "./inputs";
|
|
6
|
-
|
|
7
|
-
// Centralized resolver registry
|
|
8
|
-
export const resolverRegistry = {
|
|
9
|
-
appKey: appKeyResolver,
|
|
10
|
-
actionType: actionTypeResolver,
|
|
11
|
-
actionKey: actionKeyResolver,
|
|
12
|
-
authenticationId: authenticationIdResolver,
|
|
13
|
-
inputs: inputsResolver,
|
|
14
|
-
} as const;
|
|
15
|
-
|
|
16
|
-
// Type definitions
|
|
17
|
-
export type ResolverName = keyof typeof resolverRegistry;
|
|
18
|
-
export type ResolverType = (typeof resolverRegistry)[ResolverName];
|
|
19
|
-
|
|
20
|
-
// Utility functions for working with resolvers
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Get a resolver by name
|
|
24
|
-
*/
|
|
25
|
-
export function getResolver(name: string): ResolverType | undefined {
|
|
26
|
-
return resolverRegistry[name as ResolverName];
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Get all resolvers for a list of missing parameters
|
|
31
|
-
*/
|
|
32
|
-
export function getResolversForMissingParams(
|
|
33
|
-
missingParams: string[],
|
|
34
|
-
): Record<string, ResolverType> {
|
|
35
|
-
const resolvers: Record<string, ResolverType> = {};
|
|
36
|
-
|
|
37
|
-
for (const param of missingParams) {
|
|
38
|
-
const resolver = resolverRegistry[param as ResolverName];
|
|
39
|
-
if (resolver) {
|
|
40
|
-
resolvers[param] = resolver;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return resolvers;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Check if a parameter has a resolver
|
|
49
|
-
*/
|
|
50
|
-
export function hasResolver(paramName: string): boolean {
|
|
51
|
-
return paramName in resolverRegistry;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Get all parameter names that have resolvers
|
|
56
|
-
*/
|
|
57
|
-
export function getResolvableParams(): string[] {
|
|
58
|
-
return Object.keys(resolverRegistry);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Resolve dependency chain for a parameter
|
|
63
|
-
* Returns parameters in the order they need to be resolved
|
|
64
|
-
*/
|
|
65
|
-
export function getResolutionOrder(
|
|
66
|
-
paramName: string,
|
|
67
|
-
resolved: Set<string> = new Set(),
|
|
68
|
-
): string[] {
|
|
69
|
-
const resolver = getResolver(paramName);
|
|
70
|
-
if (!resolver || resolver.type === "static") {
|
|
71
|
-
return [paramName];
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const order: string[] = [];
|
|
75
|
-
|
|
76
|
-
if ("depends" in resolver && resolver.depends) {
|
|
77
|
-
for (const dependency of resolver.depends) {
|
|
78
|
-
if (!resolved.has(dependency)) {
|
|
79
|
-
order.push(...getResolutionOrder(dependency, resolved));
|
|
80
|
-
resolved.add(dependency);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (!resolved.has(paramName)) {
|
|
86
|
-
order.push(paramName);
|
|
87
|
-
resolved.add(paramName);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return order;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Get resolution order for multiple parameters
|
|
95
|
-
*/
|
|
96
|
-
export function getResolutionOrderForParams(paramNames: string[]): string[] {
|
|
97
|
-
const resolved = new Set<string>();
|
|
98
|
-
const order: string[] = [];
|
|
99
|
-
|
|
100
|
-
for (const paramName of paramNames) {
|
|
101
|
-
const paramOrder = getResolutionOrder(paramName, resolved);
|
|
102
|
-
for (const param of paramOrder) {
|
|
103
|
-
if (!order.includes(param)) {
|
|
104
|
-
order.push(param);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return order;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// Re-export individual resolvers for direct access if needed
|
|
1
|
+
// Re-export individual resolvers for plugin use
|
|
113
2
|
export { appKeyResolver } from "./appKey";
|
|
114
3
|
export { actionTypeResolver } from "./actionType";
|
|
115
4
|
export { actionKeyResolver } from "./actionKey";
|
|
116
|
-
export {
|
|
5
|
+
export {
|
|
6
|
+
authenticationIdResolver,
|
|
7
|
+
authenticationIdGenericResolver,
|
|
8
|
+
} from "./authenticationId";
|
|
117
9
|
export { inputsResolver } from "./inputs";
|
|
10
|
+
export { inputFieldKeyResolver } from "./inputFieldKey";
|
|
11
|
+
export { inputsAllOptionalResolver } from "./inputs";
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { DynamicResolver } from "../utils/schema-utils";
|
|
2
|
+
import type { InputFieldItem } from "../schemas/Field";
|
|
3
|
+
import type { ActionTypeProperty } from "../types/properties";
|
|
4
|
+
|
|
5
|
+
export const inputFieldKeyResolver: DynamicResolver<
|
|
6
|
+
InputFieldItem,
|
|
7
|
+
{
|
|
8
|
+
appKey: string;
|
|
9
|
+
actionKey: string;
|
|
10
|
+
actionType: ActionTypeProperty;
|
|
11
|
+
authenticationId: number;
|
|
12
|
+
inputs?: Record<string, unknown>;
|
|
13
|
+
}
|
|
14
|
+
> = {
|
|
15
|
+
type: "dynamic",
|
|
16
|
+
depends: ["appKey", "actionKey", "actionType", "authenticationId"] as const,
|
|
17
|
+
fetch: async (sdk, resolvedParams) => {
|
|
18
|
+
const fieldsResponse = await sdk.listInputFields({
|
|
19
|
+
appKey: resolvedParams.appKey,
|
|
20
|
+
actionKey: resolvedParams.actionKey,
|
|
21
|
+
actionType: resolvedParams.actionType,
|
|
22
|
+
authenticationId: resolvedParams.authenticationId,
|
|
23
|
+
inputs: resolvedParams.inputs, // Pass along currently resolved inputs
|
|
24
|
+
});
|
|
25
|
+
return fieldsResponse.data;
|
|
26
|
+
},
|
|
27
|
+
prompt: (fields) => ({
|
|
28
|
+
type: "list",
|
|
29
|
+
name: "inputFieldKey",
|
|
30
|
+
message: "Select input field:",
|
|
31
|
+
choices: fields.map((field) => ({
|
|
32
|
+
name: `${field.title || field.key} - ${
|
|
33
|
+
field.value_type || "No type"
|
|
34
|
+
} ${field.is_required ? "(required)" : "(optional)"}`,
|
|
35
|
+
value: field.key,
|
|
36
|
+
})),
|
|
37
|
+
}),
|
|
38
|
+
};
|
package/src/resolvers/inputs.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { FieldsResolver } from "../utils/schema-utils";
|
|
2
|
+
import type { ActionTypeProperty } from "../types/properties";
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
4
|
+
type InputsResolver = FieldsResolver<{
|
|
5
|
+
appKey: string;
|
|
6
|
+
actionKey: string;
|
|
7
|
+
actionType: ActionTypeProperty;
|
|
8
|
+
authenticationId: number;
|
|
9
|
+
inputs?: Record<string, unknown>;
|
|
10
|
+
}>;
|
|
11
11
|
|
|
12
12
|
export const inputsResolver: InputsResolver = {
|
|
13
13
|
type: "fields",
|
|
14
14
|
depends: ["appKey", "actionKey", "actionType", "authenticationId"] as const,
|
|
15
|
-
fetch: async (sdk
|
|
15
|
+
fetch: async (sdk, resolvedParams) => {
|
|
16
16
|
const fieldsResponse = await sdk.listInputFields({
|
|
17
17
|
appKey: resolvedParams.appKey,
|
|
18
18
|
actionKey: resolvedParams.actionKey,
|
|
@@ -23,3 +23,21 @@ export const inputsResolver: InputsResolver = {
|
|
|
23
23
|
return fieldsResponse.data;
|
|
24
24
|
},
|
|
25
25
|
};
|
|
26
|
+
|
|
27
|
+
export const inputsAllOptionalResolver: InputsResolver = {
|
|
28
|
+
type: "fields",
|
|
29
|
+
depends: ["appKey", "actionKey", "actionType", "authenticationId"] as const,
|
|
30
|
+
fetch: async (sdk, resolvedParams) => {
|
|
31
|
+
const fieldsResponse = await sdk.listInputFields({
|
|
32
|
+
appKey: resolvedParams.appKey,
|
|
33
|
+
actionKey: resolvedParams.actionKey,
|
|
34
|
+
actionType: resolvedParams.actionType,
|
|
35
|
+
authenticationId: resolvedParams.authenticationId,
|
|
36
|
+
inputs: resolvedParams.inputs, // Pass along currently resolved inputs
|
|
37
|
+
});
|
|
38
|
+
return fieldsResponse.data.map((field) => ({
|
|
39
|
+
...field,
|
|
40
|
+
is_required: false,
|
|
41
|
+
}));
|
|
42
|
+
},
|
|
43
|
+
};
|
package/src/schemas/Action.ts
CHANGED
|
@@ -27,12 +27,17 @@ export const ActionItemSchema = withFormatter(
|
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
29
|
if (item.description) {
|
|
30
|
-
details.push({
|
|
30
|
+
details.push({
|
|
31
|
+
text: item.description,
|
|
32
|
+
style: "dim" as const,
|
|
33
|
+
});
|
|
31
34
|
}
|
|
32
35
|
|
|
33
36
|
return {
|
|
34
|
-
title: item.title || item.
|
|
35
|
-
|
|
37
|
+
title: item.title || item.key,
|
|
38
|
+
id: item.id,
|
|
39
|
+
key: item.key,
|
|
40
|
+
description: item.description,
|
|
36
41
|
details,
|
|
37
42
|
};
|
|
38
43
|
},
|
package/src/schemas/App.ts
CHANGED
|
@@ -1,27 +1,25 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { withFormatter } from "../utils/schema-utils";
|
|
3
|
+
import { ImplementationMetaSchema } from "../api/schemas";
|
|
3
4
|
|
|
4
5
|
export { FormattedItem, FormatMetadata } from "../utils/schema-utils";
|
|
5
6
|
|
|
6
7
|
// ============================================================================
|
|
7
|
-
// App Item Schema (extends
|
|
8
|
+
// App Item Schema (extends ImplementationMetaSchema with transformed fields)
|
|
8
9
|
// ============================================================================
|
|
9
10
|
|
|
10
11
|
export const AppItemSchema = withFormatter(
|
|
11
|
-
|
|
12
|
-
// Essential properties only
|
|
12
|
+
ImplementationMetaSchema.omit({ name: true, id: true }).extend({
|
|
13
13
|
title: z.string(), // Mapped from name
|
|
14
|
-
key: z.string(), //
|
|
15
|
-
|
|
16
|
-
version: z.string().optional(), // Extracted from implementation ID
|
|
17
|
-
description: z.string().optional(),
|
|
18
|
-
slug: z.string().optional(),
|
|
14
|
+
key: z.string(), // Extracted from id (base part without version)
|
|
15
|
+
implementation_id: z.string(), // Mapped from id (full versioned ID)
|
|
19
16
|
}),
|
|
20
17
|
{
|
|
21
18
|
format: (item) => {
|
|
22
19
|
return {
|
|
23
20
|
title: item.title,
|
|
24
|
-
|
|
21
|
+
key: item.key,
|
|
22
|
+
description: item.description,
|
|
25
23
|
details: [],
|
|
26
24
|
};
|
|
27
25
|
},
|
package/src/schemas/Auth.ts
CHANGED
package/src/schemas/Field.ts
CHANGED
|
@@ -1,28 +1,22 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { withFormatter } from "../utils/schema-utils";
|
|
3
|
-
import { NeedSchema } from "../api/schemas";
|
|
4
3
|
|
|
5
4
|
// ============================================================================
|
|
6
5
|
// Input Field Item Schema (extends API Need schema with computed fields and formatting)
|
|
7
6
|
// ============================================================================
|
|
8
7
|
|
|
9
8
|
export const InputFieldItemSchema = withFormatter(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
placeholder: true,
|
|
13
|
-
required: true,
|
|
14
|
-
format: true,
|
|
15
|
-
}).extend({
|
|
16
|
-
id: z.string(), // Mapped from 'key'
|
|
9
|
+
z.object({
|
|
10
|
+
key: z.string(), // From need.key
|
|
17
11
|
default_value: z.string(), // Mapped from 'default' with fallback to ""
|
|
18
|
-
depends_on: z.array(z.string()), //
|
|
12
|
+
depends_on: z.array(z.string()), // Mapped from 'depends_on' with fallback to []
|
|
19
13
|
description: z.string(), // Mapped from 'help_text' with fallback to ""
|
|
20
14
|
invalidates_input_fields: z.boolean(), // Mapped from 'alters_custom_fields' with fallback to false
|
|
21
|
-
is_required: z.boolean(), //
|
|
22
|
-
placeholder: z.string(), //
|
|
15
|
+
is_required: z.boolean(), // Mapped from 'required' with fallback to false
|
|
16
|
+
placeholder: z.string(), // Mapped from 'placeholder' with fallback to ""
|
|
23
17
|
title: z.string(), // Mapped from 'label' with fallback to ""
|
|
24
18
|
value_type: z.string(), // Computed from InputFieldType enum
|
|
25
|
-
format: z.string().optional(), //
|
|
19
|
+
format: z.string().optional(), // Computed from InputFieldFormat enum (optional)
|
|
26
20
|
items: z.object({ type: z.string() }).optional(), // Computed from ItemsType enum (optional, only for arrays)
|
|
27
21
|
}),
|
|
28
22
|
{
|
|
@@ -31,8 +25,8 @@ export const InputFieldItemSchema = withFormatter(
|
|
|
31
25
|
|
|
32
26
|
// Type and required status
|
|
33
27
|
const typeInfo = [
|
|
34
|
-
item.
|
|
35
|
-
`Required: ${item.
|
|
28
|
+
item.value_type && `Type: ${item.value_type}`,
|
|
29
|
+
`Required: ${item.is_required ? "Yes" : "No"}`,
|
|
36
30
|
]
|
|
37
31
|
.filter(Boolean)
|
|
38
32
|
.join(" | ");
|
|
@@ -40,15 +34,18 @@ export const InputFieldItemSchema = withFormatter(
|
|
|
40
34
|
details.push({ text: typeInfo, style: "dim" as const });
|
|
41
35
|
}
|
|
42
36
|
|
|
43
|
-
//
|
|
44
|
-
if (item.
|
|
45
|
-
details.push({
|
|
37
|
+
// Description
|
|
38
|
+
if (item.description) {
|
|
39
|
+
details.push({
|
|
40
|
+
text: item.description,
|
|
41
|
+
style: "normal" as const,
|
|
42
|
+
});
|
|
46
43
|
}
|
|
47
44
|
|
|
48
45
|
// Default value
|
|
49
|
-
if (item.
|
|
46
|
+
if (item.default_value) {
|
|
50
47
|
details.push({
|
|
51
|
-
text: `Default: ${item.
|
|
48
|
+
text: `Default: ${item.default_value}`,
|
|
52
49
|
style: "accent" as const,
|
|
53
50
|
});
|
|
54
51
|
}
|
|
@@ -61,25 +58,10 @@ export const InputFieldItemSchema = withFormatter(
|
|
|
61
58
|
});
|
|
62
59
|
}
|
|
63
60
|
|
|
64
|
-
// Choices
|
|
65
|
-
if (item.choices && item.choices.length > 0) {
|
|
66
|
-
const choiceText =
|
|
67
|
-
item.choices.length <= 3
|
|
68
|
-
? `Choices: ${item.choices.map((c: { label?: string; value: string | number }) => c.label || c.value).join(", ")}`
|
|
69
|
-
: `Choices: ${item.choices
|
|
70
|
-
.slice(0, 3)
|
|
71
|
-
.map(
|
|
72
|
-
(c: { label?: string; value: string | number }) =>
|
|
73
|
-
c.label || c.value,
|
|
74
|
-
)
|
|
75
|
-
.join(", ")} (+${item.choices.length - 3} more)`;
|
|
76
|
-
details.push({ text: choiceText, style: "accent" as const });
|
|
77
|
-
}
|
|
78
|
-
|
|
79
61
|
// Dependencies
|
|
80
|
-
if (item.
|
|
62
|
+
if (item.depends_on && item.depends_on.length > 0) {
|
|
81
63
|
details.push({
|
|
82
|
-
text: `Depends on: ${item.
|
|
64
|
+
text: `Depends on: ${item.depends_on.join(", ")}`,
|
|
83
65
|
style: "warning" as const,
|
|
84
66
|
});
|
|
85
67
|
}
|
|
@@ -89,33 +71,18 @@ export const InputFieldItemSchema = withFormatter(
|
|
|
89
71
|
details.push({ text: `Format: ${item.format}`, style: "dim" as const });
|
|
90
72
|
}
|
|
91
73
|
|
|
92
|
-
//
|
|
93
|
-
if (item.
|
|
74
|
+
// Items type for arrays
|
|
75
|
+
if (item.items) {
|
|
94
76
|
details.push({
|
|
95
|
-
text: `
|
|
77
|
+
text: `Items type: ${item.items.type}`,
|
|
96
78
|
style: "dim" as const,
|
|
97
79
|
});
|
|
98
80
|
}
|
|
99
81
|
|
|
100
|
-
// Special field flags
|
|
101
|
-
const flags = [];
|
|
102
|
-
if (item.computed) flags.push("computed");
|
|
103
|
-
if (item.customField) flags.push("custom");
|
|
104
|
-
if (flags.length > 0) {
|
|
105
|
-
details.push({
|
|
106
|
-
text: `Flags: ${flags.join(", ")}`,
|
|
107
|
-
style: "success" as const,
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// Backwards compatibility: show description if no helpText
|
|
112
|
-
if (item.description && !item.helpText) {
|
|
113
|
-
details.push({ text: item.description, style: "normal" as const });
|
|
114
|
-
}
|
|
115
|
-
|
|
116
82
|
return {
|
|
117
|
-
title: item.
|
|
118
|
-
|
|
83
|
+
title: item.title || item.key,
|
|
84
|
+
key: item.key,
|
|
85
|
+
description: item.description,
|
|
119
86
|
details,
|
|
120
87
|
};
|
|
121
88
|
},
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { withFormatter, type FormattedItem } from "../utils/schema-utils";
|
|
3
|
+
|
|
4
|
+
// Type guard to safely access object properties
|
|
5
|
+
function getStringProperty(obj: unknown, key: string): string | undefined {
|
|
6
|
+
if (typeof obj === "object" && obj !== null && key in obj) {
|
|
7
|
+
const value = (obj as Record<string, unknown>)[key];
|
|
8
|
+
return typeof value === "string" ? value : undefined;
|
|
9
|
+
}
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// Formatter for action results - handles any data structure
|
|
14
|
+
function formatActionResult(item: unknown): FormattedItem {
|
|
15
|
+
// Try to extract common fields for structured display
|
|
16
|
+
const obj = typeof item === "object" && item !== null ? item : {};
|
|
17
|
+
|
|
18
|
+
// Try common title fields
|
|
19
|
+
const title =
|
|
20
|
+
getStringProperty(obj, "title") ||
|
|
21
|
+
getStringProperty(obj, "name") ||
|
|
22
|
+
getStringProperty(obj, "label") ||
|
|
23
|
+
getStringProperty(obj, "subject") ||
|
|
24
|
+
"Action Result";
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
title,
|
|
28
|
+
id: getStringProperty(obj, "id"),
|
|
29
|
+
key: getStringProperty(obj, "key"),
|
|
30
|
+
description: getStringProperty(obj, "description"),
|
|
31
|
+
data: item, // Let formatJsonOutput handle the JSON rendering
|
|
32
|
+
details: [], // Not used when data is provided
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Flexible schema for action results - can be any object
|
|
37
|
+
export const ActionResultItemSchema = withFormatter(
|
|
38
|
+
z.unknown().describe("Action execution result"),
|
|
39
|
+
{ format: formatActionResult },
|
|
40
|
+
);
|
|
@@ -15,21 +15,38 @@ export const UserProfileItemSchema = withFormatter(
|
|
|
15
15
|
{
|
|
16
16
|
format: (item) => {
|
|
17
17
|
const details = [];
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
if (
|
|
19
|
+
item == null ||
|
|
20
|
+
typeof item !== "object" ||
|
|
21
|
+
!("full_name" in item) ||
|
|
22
|
+
!("username" in item)
|
|
23
|
+
) {
|
|
24
|
+
return {
|
|
25
|
+
title: "User Profile",
|
|
26
|
+
subtitle: "Malformatted result item",
|
|
27
|
+
details: [],
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if ("email" in item) {
|
|
32
|
+
details.push({ text: item.email, style: "dim" as const });
|
|
33
|
+
}
|
|
34
|
+
if ("timezone" in item && item.timezone) {
|
|
20
35
|
details.push({
|
|
21
36
|
text: `Timezone: ${item.timezone}`,
|
|
22
37
|
style: "accent" as const,
|
|
23
38
|
});
|
|
24
39
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
40
|
+
if ("since_signup" in item && item.since_signup) {
|
|
41
|
+
details.push({
|
|
42
|
+
text: `Member since: ${item.since_signup}`,
|
|
43
|
+
style: "dim" as const,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
29
46
|
|
|
30
47
|
return {
|
|
31
48
|
title: item.full_name,
|
|
32
|
-
|
|
49
|
+
id: item.id.toString(),
|
|
33
50
|
details,
|
|
34
51
|
};
|
|
35
52
|
},
|
package/src/sdk.ts
CHANGED
|
@@ -9,6 +9,7 @@ import type {
|
|
|
9
9
|
Sdk,
|
|
10
10
|
Plugin,
|
|
11
11
|
ExtractContextProperties,
|
|
12
|
+
ExtractSdkProperties,
|
|
12
13
|
PluginProvides,
|
|
13
14
|
PluginMeta,
|
|
14
15
|
} from "./types/plugin";
|
|
@@ -32,7 +33,6 @@ import { listInputFieldsPlugin } from "./plugins/listInputFields";
|
|
|
32
33
|
import { listInputFieldChoicesPlugin } from "./plugins/listInputFieldChoices";
|
|
33
34
|
import { requestPlugin } from "./plugins/request";
|
|
34
35
|
import { manifestPlugin } from "./plugins/manifest";
|
|
35
|
-
import { lockVersionPlugin } from "./plugins/lockVersion";
|
|
36
36
|
|
|
37
37
|
// Full SDK interface with plugins applied
|
|
38
38
|
// Note: ZapierSdk is now defined as ReturnType<typeof createZapierSdk> at the bottom of this file
|
|
@@ -42,12 +42,14 @@ export interface ZapierSdkOptions extends BaseSdkOptions {}
|
|
|
42
42
|
// Create SDK that supports flat plugins - returns an SDK, not a builder
|
|
43
43
|
export function createSdk<
|
|
44
44
|
TCurrentSdk = {},
|
|
45
|
-
TCurrentContext
|
|
45
|
+
TCurrentContext extends { meta: Record<string, PluginMeta> } = {
|
|
46
|
+
meta: Record<string, PluginMeta>;
|
|
47
|
+
},
|
|
46
48
|
>(
|
|
47
49
|
options: ZapierSdkOptions = {},
|
|
48
50
|
initialSdk: TCurrentSdk = {} as TCurrentSdk,
|
|
49
51
|
initialContext: TCurrentContext = { meta: {} } as TCurrentContext,
|
|
50
|
-
)
|
|
52
|
+
) {
|
|
51
53
|
return {
|
|
52
54
|
...initialSdk,
|
|
53
55
|
getContext: () => initialContext,
|
|
@@ -57,8 +59,11 @@ export function createSdk<
|
|
|
57
59
|
TRequiresContext,
|
|
58
60
|
TProvides
|
|
59
61
|
>,
|
|
60
|
-
addPluginOptions:
|
|
61
|
-
)
|
|
62
|
+
addPluginOptions: Record<string, unknown> = {},
|
|
63
|
+
): Sdk<
|
|
64
|
+
TCurrentSdk & ExtractSdkProperties<TProvides>,
|
|
65
|
+
TCurrentContext & NonNullable<ExtractContextProperties<TProvides>>
|
|
66
|
+
> {
|
|
62
67
|
// Create SDK with getContext method for plugins to use
|
|
63
68
|
const currentSdkWithContext = {
|
|
64
69
|
...initialSdk,
|
|
@@ -72,7 +77,7 @@ export function createSdk<
|
|
|
72
77
|
...initialContext,
|
|
73
78
|
// Add the options that createSdk was called with to context
|
|
74
79
|
options,
|
|
75
|
-
},
|
|
80
|
+
} as TCurrentContext & { options: ZapierSdkOptions } & TRequiresContext,
|
|
76
81
|
...addPluginOptions,
|
|
77
82
|
});
|
|
78
83
|
|
|
@@ -87,7 +92,8 @@ export function createSdk<
|
|
|
87
92
|
let newContext = {
|
|
88
93
|
...initialContext,
|
|
89
94
|
...addPluginOptions,
|
|
90
|
-
meta:
|
|
95
|
+
meta:
|
|
96
|
+
(initialContext as { meta?: Record<string, PluginMeta> }).meta || {},
|
|
91
97
|
} as TCurrentContext & NonNullable<ExtractContextProperties<TProvides>>;
|
|
92
98
|
|
|
93
99
|
if (pluginContext) {
|
|
@@ -113,7 +119,10 @@ export function createSdk<
|
|
|
113
119
|
}
|
|
114
120
|
|
|
115
121
|
// Recursively create new SDK with updated properties
|
|
116
|
-
return createSdk(options, newSdk, newContext) as
|
|
122
|
+
return createSdk(options, newSdk, newContext) as Sdk<
|
|
123
|
+
TCurrentSdk & ExtractSdkProperties<TProvides>,
|
|
124
|
+
TCurrentContext & NonNullable<ExtractContextProperties<TProvides>>
|
|
125
|
+
>;
|
|
117
126
|
},
|
|
118
127
|
};
|
|
119
128
|
}
|
|
@@ -125,10 +134,10 @@ export function createZapierSdkWithoutRegistry(options: ZapierSdkOptions = {}) {
|
|
|
125
134
|
.addPlugin(apiPlugin)
|
|
126
135
|
|
|
127
136
|
// Manifest plugin (provides version locking context)
|
|
137
|
+
.addPlugin(manifestPlugin)
|
|
128
138
|
|
|
129
139
|
// Apps/actions/fields
|
|
130
140
|
.addPlugin(listAppsPlugin)
|
|
131
|
-
.addPlugin(manifestPlugin)
|
|
132
141
|
.addPlugin(getAppPlugin)
|
|
133
142
|
.addPlugin(listActionsPlugin)
|
|
134
143
|
.addPlugin(getActionPlugin)
|
|
@@ -138,9 +147,6 @@ export function createZapierSdkWithoutRegistry(options: ZapierSdkOptions = {}) {
|
|
|
138
147
|
// Run action
|
|
139
148
|
.addPlugin(runActionPlugin)
|
|
140
149
|
|
|
141
|
-
// Version locking
|
|
142
|
-
.addPlugin(lockVersionPlugin)
|
|
143
|
-
|
|
144
150
|
// Authentications
|
|
145
151
|
.addPlugin(listAuthenticationsPlugin)
|
|
146
152
|
.addPlugin(getAuthenticationPlugin)
|