@zapier/zapier-sdk 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/client.js +22 -6
- package/dist/api/index.d.ts +4 -2
- package/dist/api/index.js +5 -4
- package/dist/api/types.d.ts +2 -0
- package/dist/functions/findFirstAuthentication/index.d.ts +12 -0
- package/dist/functions/findFirstAuthentication/index.js +21 -0
- package/dist/functions/findFirstAuthentication/info.d.ts +30 -0
- package/dist/functions/findFirstAuthentication/info.js +11 -0
- package/dist/functions/findFirstAuthentication/schemas.d.ts +42 -0
- package/dist/functions/findFirstAuthentication/schemas.js +25 -0
- package/dist/functions/findUniqueAuthentication/index.d.ts +13 -0
- package/dist/functions/findUniqueAuthentication/index.js +28 -0
- package/dist/functions/findUniqueAuthentication/info.d.ts +30 -0
- package/dist/functions/findUniqueAuthentication/info.js +11 -0
- package/dist/functions/{listAuths → findUniqueAuthentication}/schemas.d.ts +10 -4
- package/dist/functions/findUniqueAuthentication/schemas.js +25 -0
- package/dist/functions/{listAuths → listAuthentications}/index.d.ts +2 -2
- package/dist/functions/{listAuths → listAuthentications}/index.js +24 -11
- package/dist/functions/{listAuths → listAuthentications}/info.d.ts +9 -3
- package/dist/functions/listAuthentications/info.js +11 -0
- package/dist/functions/listAuthentications/schemas.d.ts +44 -0
- package/dist/functions/{listAuths → listAuthentications}/schemas.js +10 -2
- package/dist/functions/runAction/index.js +1 -3
- package/dist/functions/runAction/schemas.d.ts +2 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +10 -3
- package/dist/resolvers/authenticationId.js +1 -1
- package/dist/schema-utils.d.ts +5 -0
- package/dist/schema-utils.js +24 -0
- package/dist/schemas/Auth.d.ts +0 -3
- package/dist/schemas/Auth.js +1 -8
- package/dist/sdk.js +32 -36
- package/dist/types/domain.d.ts +1 -0
- package/dist/types/properties.js +2 -4
- package/dist/types/sdk.d.ts +4 -2
- package/dist/utils/getTokenFromConfig.d.ts +7 -0
- package/dist/utils/getTokenFromConfig.js +29 -0
- package/package.json +1 -3
- package/src/api/client.ts +30 -5
- package/src/api/index.ts +12 -5
- package/src/api/types.ts +2 -0
- package/src/functions/findFirstAuthentication/index.ts +24 -0
- package/src/functions/findFirstAuthentication/info.ts +9 -0
- package/src/functions/findFirstAuthentication/schemas.ts +60 -0
- package/src/functions/findUniqueAuthentication/index.ts +35 -0
- package/src/functions/findUniqueAuthentication/info.ts +9 -0
- package/src/functions/findUniqueAuthentication/schemas.ts +60 -0
- package/src/functions/{listAuths → listAuthentications}/index.ts +27 -17
- package/src/functions/listAuthentications/info.ts +9 -0
- package/src/functions/{listAuths → listAuthentications}/schemas.ts +18 -4
- package/src/functions/runAction/index.ts +1 -6
- package/src/functions/runAction/schemas.ts +2 -0
- package/src/index.ts +6 -1
- package/src/resolvers/authenticationId.ts +1 -1
- package/src/schema-utils.ts +35 -0
- package/src/schemas/Auth.ts +1 -9
- package/src/sdk.ts +32 -35
- package/src/types/domain.ts +1 -0
- package/src/types/properties.ts +4 -4
- package/src/types/sdk.ts +6 -2
- package/src/utils/getTokenFromConfig.ts +28 -0
- package/dist/functions/listAuths/info.js +0 -11
- package/src/functions/listAuths/info.ts +0 -9
|
@@ -15,10 +15,8 @@ const getApp_1 = require("../getApp");
|
|
|
15
15
|
*/
|
|
16
16
|
async function runAction(options) {
|
|
17
17
|
const { appKey, actionType, actionKey, inputs, authenticationId: providedAuthenticationId, token, } = options;
|
|
18
|
-
if (!token && !process.env.ZAPIER_TOKEN) {
|
|
19
|
-
throw new Error("Authentication token is required to run actions. Please provide token in options or set ZAPIER_TOKEN environment variable.");
|
|
20
|
-
}
|
|
21
18
|
const api = (0, api_1.getOrCreateApiClient)(options);
|
|
19
|
+
api.requireAuthTo("run actions");
|
|
22
20
|
// Validate that the action exists
|
|
23
21
|
const actionData = await (0, getAction_1.getAction)({
|
|
24
22
|
...options,
|
|
@@ -24,6 +24,8 @@ export type RunActionOptions = z.infer<typeof RunActionSchema> & {
|
|
|
24
24
|
baseUrl?: string;
|
|
25
25
|
/** Authentication token */
|
|
26
26
|
token?: string;
|
|
27
|
+
/** Function to dynamically resolve authentication token */
|
|
28
|
+
getToken?: () => Promise<string | undefined>;
|
|
27
29
|
/** Optional pre-instantiated API client */
|
|
28
30
|
api?: any;
|
|
29
31
|
/** Enable debug logging */
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
export * from "./types/domain";
|
|
2
2
|
export * from "./types/properties";
|
|
3
3
|
export * from "./plugins/apps";
|
|
4
|
+
export { isPositional } from "./schema-utils";
|
|
4
5
|
export * from "./resolvers";
|
|
5
|
-
export {
|
|
6
|
+
export { listAuthentications } from "./functions/listAuthentications";
|
|
7
|
+
export { findFirstAuthentication } from "./functions/findFirstAuthentication";
|
|
8
|
+
export { findUniqueAuthentication } from "./functions/findUniqueAuthentication";
|
|
6
9
|
export { listApps } from "./functions/listApps";
|
|
7
10
|
export { getApp } from "./functions/getApp";
|
|
8
11
|
export { listActions } from "./functions/listActions";
|
package/dist/index.js
CHANGED
|
@@ -14,17 +14,24 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.createZapierSdk = exports.bundleCode = exports.generateTypes = exports.listFields = exports.runAction = exports.getAction = exports.listActions = exports.getApp = exports.listApps = exports.
|
|
17
|
+
exports.createZapierSdk = exports.bundleCode = exports.generateTypes = exports.listFields = exports.runAction = exports.getAction = exports.listActions = exports.getApp = exports.listApps = exports.findUniqueAuthentication = exports.findFirstAuthentication = exports.listAuthentications = exports.isPositional = void 0;
|
|
18
18
|
// Export everything from types and plugins
|
|
19
19
|
__exportStar(require("./types/domain"), exports);
|
|
20
20
|
__exportStar(require("./types/properties"), exports);
|
|
21
21
|
__exportStar(require("./plugins/apps"), exports);
|
|
22
|
+
// Export schema utilities for CLI
|
|
23
|
+
var schema_utils_1 = require("./schema-utils");
|
|
24
|
+
Object.defineProperty(exports, "isPositional", { enumerable: true, get: function () { return schema_utils_1.isPositional; } });
|
|
22
25
|
// Export resolvers for CLI use
|
|
23
26
|
__exportStar(require("./resolvers"), exports);
|
|
24
27
|
// Note: SdkSchemas is now available via SDK.__registry
|
|
25
28
|
// Export individual functions for tree-shaking
|
|
26
|
-
var
|
|
27
|
-
Object.defineProperty(exports, "
|
|
29
|
+
var listAuthentications_1 = require("./functions/listAuthentications");
|
|
30
|
+
Object.defineProperty(exports, "listAuthentications", { enumerable: true, get: function () { return listAuthentications_1.listAuthentications; } });
|
|
31
|
+
var findFirstAuthentication_1 = require("./functions/findFirstAuthentication");
|
|
32
|
+
Object.defineProperty(exports, "findFirstAuthentication", { enumerable: true, get: function () { return findFirstAuthentication_1.findFirstAuthentication; } });
|
|
33
|
+
var findUniqueAuthentication_1 = require("./functions/findUniqueAuthentication");
|
|
34
|
+
Object.defineProperty(exports, "findUniqueAuthentication", { enumerable: true, get: function () { return findUniqueAuthentication_1.findUniqueAuthentication; } });
|
|
28
35
|
var listApps_1 = require("./functions/listApps");
|
|
29
36
|
Object.defineProperty(exports, "listApps", { enumerable: true, get: function () { return listApps_1.listApps; } });
|
|
30
37
|
var getApp_1 = require("./functions/getApp");
|
|
@@ -6,7 +6,7 @@ exports.authenticationIdResolver = {
|
|
|
6
6
|
depends: ["appKey"],
|
|
7
7
|
fetch: async (sdk, resolvedParams) => {
|
|
8
8
|
// Get auths for the specific app (owned auths will be prioritized automatically)
|
|
9
|
-
return await sdk.
|
|
9
|
+
return await sdk.listAuthentications({
|
|
10
10
|
appKey: resolvedParams.appKey,
|
|
11
11
|
limit: 1000,
|
|
12
12
|
});
|
package/dist/schema-utils.d.ts
CHANGED
|
@@ -37,3 +37,8 @@ export interface ResolverConfig {
|
|
|
37
37
|
export declare function withResolver<T extends z.ZodType>(schema: T, config: ResolverConfig): T;
|
|
38
38
|
export declare function getSchemaDescription(schema: z.ZodSchema): string | undefined;
|
|
39
39
|
export declare function getFieldDescriptions(schema: z.ZodObject<any>): Record<string, string>;
|
|
40
|
+
export interface PositionalMetadata {
|
|
41
|
+
positional: true;
|
|
42
|
+
}
|
|
43
|
+
export declare function withPositional<T extends z.ZodType>(schema: T): T;
|
|
44
|
+
export declare function isPositional(schema: z.ZodType): boolean;
|
package/dist/schema-utils.js
CHANGED
|
@@ -7,6 +7,8 @@ exports.getOutputSchema = getOutputSchema;
|
|
|
7
7
|
exports.withResolver = withResolver;
|
|
8
8
|
exports.getSchemaDescription = getSchemaDescription;
|
|
9
9
|
exports.getFieldDescriptions = getFieldDescriptions;
|
|
10
|
+
exports.withPositional = withPositional;
|
|
11
|
+
exports.isPositional = isPositional;
|
|
10
12
|
const zod_1 = require("zod");
|
|
11
13
|
// Helper function to add format metadata to schemas
|
|
12
14
|
function withFormatter(schema, formatMeta) {
|
|
@@ -50,3 +52,25 @@ function getFieldDescriptions(schema) {
|
|
|
50
52
|
}
|
|
51
53
|
return descriptions;
|
|
52
54
|
}
|
|
55
|
+
// Helper function to mark a parameter as positional for CLI
|
|
56
|
+
function withPositional(schema) {
|
|
57
|
+
// Store positional metadata on the schema definition
|
|
58
|
+
schema._def.positionalMeta = { positional: true };
|
|
59
|
+
return schema;
|
|
60
|
+
}
|
|
61
|
+
// Helper function to check if a parameter should be positional
|
|
62
|
+
function isPositional(schema) {
|
|
63
|
+
// Check the current schema first
|
|
64
|
+
if (schema._def.positionalMeta?.positional) {
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
// If this is a ZodOptional, check the inner type
|
|
68
|
+
if (schema instanceof zod_1.z.ZodOptional) {
|
|
69
|
+
return isPositional(schema._def.innerType);
|
|
70
|
+
}
|
|
71
|
+
// If this is a ZodDefault, check the inner type
|
|
72
|
+
if (schema instanceof zod_1.z.ZodDefault) {
|
|
73
|
+
return isPositional(schema._def.innerType);
|
|
74
|
+
}
|
|
75
|
+
return false;
|
|
76
|
+
}
|
package/dist/schemas/Auth.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { z } from "zod";
|
|
|
2
2
|
export declare const AuthItemSchema: z.ZodObject<{
|
|
3
3
|
id: z.ZodNumber;
|
|
4
4
|
title: z.ZodOptional<z.ZodString>;
|
|
5
|
-
label: z.ZodOptional<z.ZodString>;
|
|
6
5
|
identifier: z.ZodOptional<z.ZodString>;
|
|
7
6
|
account_id: z.ZodOptional<z.ZodString>;
|
|
8
7
|
is_private: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -11,7 +10,6 @@ export declare const AuthItemSchema: z.ZodObject<{
|
|
|
11
10
|
}, "strip", z.ZodTypeAny, {
|
|
12
11
|
id: number;
|
|
13
12
|
title?: string | undefined;
|
|
14
|
-
label?: string | undefined;
|
|
15
13
|
identifier?: string | undefined;
|
|
16
14
|
account_id?: string | undefined;
|
|
17
15
|
is_private?: boolean | undefined;
|
|
@@ -20,7 +18,6 @@ export declare const AuthItemSchema: z.ZodObject<{
|
|
|
20
18
|
}, {
|
|
21
19
|
id: number;
|
|
22
20
|
title?: string | undefined;
|
|
23
|
-
label?: string | undefined;
|
|
24
21
|
identifier?: string | undefined;
|
|
25
22
|
account_id?: string | undefined;
|
|
26
23
|
is_private?: boolean | undefined;
|
package/dist/schemas/Auth.js
CHANGED
|
@@ -9,7 +9,6 @@ const schema_utils_1 = require("../schema-utils");
|
|
|
9
9
|
exports.AuthItemSchema = (0, schema_utils_1.withFormatter)(zod_1.z.object({
|
|
10
10
|
id: zod_1.z.number(),
|
|
11
11
|
title: zod_1.z.string().optional(),
|
|
12
|
-
label: zod_1.z.string().optional(),
|
|
13
12
|
identifier: zod_1.z.string().optional(),
|
|
14
13
|
account_id: zod_1.z.string().optional(),
|
|
15
14
|
is_private: zod_1.z.boolean().optional(),
|
|
@@ -24,12 +23,6 @@ exports.AuthItemSchema = (0, schema_utils_1.withFormatter)(zod_1.z.object({
|
|
|
24
23
|
style: "accent",
|
|
25
24
|
});
|
|
26
25
|
}
|
|
27
|
-
if (item.label && item.title && item.label !== item.title) {
|
|
28
|
-
details.push({
|
|
29
|
-
text: `Label: ${item.label}`,
|
|
30
|
-
style: "normal",
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
26
|
details.push({
|
|
34
27
|
text: `Account: ${item.account_id || "unknown"} | Private: ${item.is_private || false} | Shared: ${item.shared_with_all || false}`,
|
|
35
28
|
style: "dim",
|
|
@@ -41,7 +34,7 @@ exports.AuthItemSchema = (0, schema_utils_1.withFormatter)(zod_1.z.object({
|
|
|
41
34
|
});
|
|
42
35
|
}
|
|
43
36
|
return {
|
|
44
|
-
title: item.title ||
|
|
37
|
+
title: item.title || `Authentication ${item.id}`,
|
|
45
38
|
subtitle: `(ID: ${item.id})`,
|
|
46
39
|
details,
|
|
47
40
|
};
|
package/dist/sdk.js
CHANGED
|
@@ -8,7 +8,9 @@ const getApp_1 = require("./functions/getApp");
|
|
|
8
8
|
const listActions_1 = require("./functions/listActions");
|
|
9
9
|
const getAction_1 = require("./functions/getAction");
|
|
10
10
|
const runAction_1 = require("./functions/runAction");
|
|
11
|
-
const
|
|
11
|
+
const listAuthentications_1 = require("./functions/listAuthentications");
|
|
12
|
+
const findFirstAuthentication_1 = require("./functions/findFirstAuthentication");
|
|
13
|
+
const findUniqueAuthentication_1 = require("./functions/findUniqueAuthentication");
|
|
12
14
|
const listFields_1 = require("./functions/listFields");
|
|
13
15
|
const generateTypes_1 = require("./functions/generateTypes");
|
|
14
16
|
const bundleCode_1 = require("./functions/bundleCode");
|
|
@@ -18,10 +20,12 @@ const info_2 = require("./functions/getApp/info");
|
|
|
18
20
|
const info_3 = require("./functions/listActions/info");
|
|
19
21
|
const info_4 = require("./functions/getAction/info");
|
|
20
22
|
const info_5 = require("./functions/runAction/info");
|
|
21
|
-
const info_6 = require("./functions/
|
|
22
|
-
const info_7 = require("./functions/
|
|
23
|
-
const info_8 = require("./functions/
|
|
24
|
-
const info_9 = require("./functions/
|
|
23
|
+
const info_6 = require("./functions/listAuthentications/info");
|
|
24
|
+
const info_7 = require("./functions/findFirstAuthentication/info");
|
|
25
|
+
const info_8 = require("./functions/findUniqueAuthentication/info");
|
|
26
|
+
const info_9 = require("./functions/listFields/info");
|
|
27
|
+
const info_10 = require("./functions/generateTypes/info");
|
|
28
|
+
const info_11 = require("./functions/bundleCode/info");
|
|
25
29
|
// Function registry as array - uses names from function info objects
|
|
26
30
|
const functionRegistry = [
|
|
27
31
|
info_1.listAppsInfo,
|
|
@@ -29,32 +33,22 @@ const functionRegistry = [
|
|
|
29
33
|
info_3.listActionsInfo,
|
|
30
34
|
info_4.getActionInfo,
|
|
31
35
|
info_5.runActionInfo,
|
|
32
|
-
info_6.
|
|
33
|
-
info_7.
|
|
34
|
-
info_8.
|
|
35
|
-
info_9.
|
|
36
|
+
info_6.listAuthenticationsInfo,
|
|
37
|
+
info_7.findFirstAuthenticationInfo,
|
|
38
|
+
info_8.findUniqueAuthenticationInfo,
|
|
39
|
+
info_9.listFieldsInfo,
|
|
40
|
+
info_10.generateTypesInfo,
|
|
41
|
+
info_11.bundleCodeInfo,
|
|
36
42
|
];
|
|
37
43
|
// Import plugin functions
|
|
38
44
|
const index_1 = require("./plugins/apps/index");
|
|
39
45
|
function createBaseZapierSdk(options = {}) {
|
|
40
|
-
|
|
41
|
-
try {
|
|
42
|
-
const { findUpSync } = require("find-up");
|
|
43
|
-
const envPath = findUpSync(".env");
|
|
44
|
-
if (envPath) {
|
|
45
|
-
require("dotenv").config({ path: envPath, quiet: true });
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
catch {
|
|
49
|
-
// Silently fail if dotenv/find-up not available or .env not found
|
|
50
|
-
}
|
|
51
|
-
const { fetch: customFetch = globalThis.fetch, baseUrl = "https://zapier.com", token, debug = false, } = options;
|
|
52
|
-
// If no token provided, try to get it from environment variable
|
|
53
|
-
const finalToken = token || process.env.ZAPIER_TOKEN;
|
|
46
|
+
const { fetch: customFetch = globalThis.fetch, baseUrl = "https://zapier.com", token, getToken, debug = false, } = options;
|
|
54
47
|
// Create the API client
|
|
55
48
|
const api = (0, api_1.createZapierApi)({
|
|
56
49
|
baseUrl,
|
|
57
|
-
token
|
|
50
|
+
token,
|
|
51
|
+
getToken,
|
|
58
52
|
debug,
|
|
59
53
|
fetch: customFetch,
|
|
60
54
|
});
|
|
@@ -63,14 +57,16 @@ function createBaseZapierSdk(options = {}) {
|
|
|
63
57
|
// Registry for CLI
|
|
64
58
|
__registry: functionRegistry,
|
|
65
59
|
// Function implementations with API config injection
|
|
66
|
-
listApps: (options = {}) => (0, listApps_1.listApps)({ ...options, api
|
|
67
|
-
getApp: (options) => (0, getApp_1.getApp)({ ...options, api
|
|
68
|
-
listActions: (options = {}) => (0, listActions_1.listActions)({ ...options, api
|
|
69
|
-
getAction: (options) => (0, getAction_1.getAction)({ ...options, api
|
|
70
|
-
runAction: (options) => (0, runAction_1.runAction)({ ...options, api
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
60
|
+
listApps: (options = {}) => (0, listApps_1.listApps)({ ...options, api }),
|
|
61
|
+
getApp: (options) => (0, getApp_1.getApp)({ ...options, api }),
|
|
62
|
+
listActions: (options = {}) => (0, listActions_1.listActions)({ ...options, api }),
|
|
63
|
+
getAction: (options) => (0, getAction_1.getAction)({ ...options, api }),
|
|
64
|
+
runAction: (options) => (0, runAction_1.runAction)({ ...options, api }),
|
|
65
|
+
listAuthentications: (options = {}) => (0, listAuthentications_1.listAuthentications)({ ...options, api }),
|
|
66
|
+
findFirstAuthentication: (options = {}) => (0, findFirstAuthentication_1.findFirstAuthentication)({ ...options, api }),
|
|
67
|
+
findUniqueAuthentication: (options = {}) => (0, findUniqueAuthentication_1.findUniqueAuthentication)({ ...options, api }),
|
|
68
|
+
listFields: (options) => (0, listFields_1.listFields)({ ...options, api }),
|
|
69
|
+
generateTypes: (options) => (0, generateTypes_1.generateTypes)({ ...options, api }),
|
|
74
70
|
bundleCode: (options) => (0, bundleCode_1.bundleCode)(options), // No API config needed
|
|
75
71
|
};
|
|
76
72
|
return sdk;
|
|
@@ -79,19 +75,19 @@ function createZapierSdk(options = {}) {
|
|
|
79
75
|
// Create base SDK
|
|
80
76
|
const baseSdk = createBaseZapierSdk(options);
|
|
81
77
|
// Extract options needed for plugins
|
|
82
|
-
const { fetch: customFetch = globalThis.fetch, baseUrl = "https://zapier.com", token, debug = false, } = options;
|
|
83
|
-
const finalToken = token || process.env.ZAPIER_TOKEN;
|
|
78
|
+
const { fetch: customFetch = globalThis.fetch, baseUrl = "https://zapier.com", token, getToken, debug = false, } = options;
|
|
84
79
|
// Create the API client for plugins
|
|
85
80
|
const api = (0, api_1.createZapierApi)({
|
|
86
81
|
baseUrl,
|
|
87
|
-
token
|
|
82
|
+
token,
|
|
83
|
+
getToken,
|
|
88
84
|
debug,
|
|
89
85
|
fetch: customFetch,
|
|
90
86
|
});
|
|
91
87
|
// Create plugins directly - TypeScript will enforce correct implementation
|
|
92
88
|
const appsPlugin = (0, index_1.createAppsPlugin)({
|
|
93
89
|
api,
|
|
94
|
-
token
|
|
90
|
+
token,
|
|
95
91
|
});
|
|
96
92
|
// Compose final SDK - TypeScript will enforce we have all required properties
|
|
97
93
|
const fullSdk = {
|
package/dist/types/domain.d.ts
CHANGED
package/dist/types/properties.js
CHANGED
|
@@ -2,12 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ParamsPropertySchema = exports.DebugPropertySchema = exports.OutputPropertySchema = exports.OffsetPropertySchema = exports.LimitPropertySchema = exports.InputsPropertySchema = exports.AuthenticationIdPropertySchema = exports.ActionKeyPropertySchema = exports.ActionTypePropertySchema = exports.AppKeyPropertySchema = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
|
+
const schema_utils_1 = require("../schema-utils");
|
|
5
6
|
// Shared property definitions for common parameters across functions
|
|
6
7
|
// These can be reused in function schemas without duplication
|
|
7
|
-
exports.AppKeyPropertySchema = zod_1.z
|
|
8
|
-
.string()
|
|
9
|
-
.min(1)
|
|
10
|
-
.describe("App slug (e.g., 'slack', 'github')");
|
|
8
|
+
exports.AppKeyPropertySchema = (0, schema_utils_1.withPositional)(zod_1.z.string().min(1).describe("App slug (e.g., 'slack', 'github')"));
|
|
11
9
|
exports.ActionTypePropertySchema = zod_1.z
|
|
12
10
|
.enum(["read", "write", "search", "create", "update", "delete"])
|
|
13
11
|
.describe("Action type that matches the action's defined type");
|
package/dist/types/sdk.d.ts
CHANGED
|
@@ -3,12 +3,14 @@ import type { GetActionSdkFunction } from "../functions/getAction/schemas";
|
|
|
3
3
|
import type { GetAppSdkFunction } from "../functions/getApp/schemas";
|
|
4
4
|
import type { RunActionSdkFunction } from "../functions/runAction/schemas";
|
|
5
5
|
import type { ListFieldsSdkFunction } from "../functions/listFields/schemas";
|
|
6
|
-
import type {
|
|
6
|
+
import type { ListAuthenticationsSdkFunction } from "../functions/listAuthentications/schemas";
|
|
7
|
+
import type { FindFirstAuthenticationSdkFunction } from "../functions/findFirstAuthentication/schemas";
|
|
8
|
+
import type { FindUniqueAuthenticationSdkFunction } from "../functions/findUniqueAuthentication/schemas";
|
|
7
9
|
import type { GenerateTypesSdkFunction } from "../functions/generateTypes/schemas";
|
|
8
10
|
import type { ListAppsSdkFunction } from "../functions/listApps/schemas";
|
|
9
11
|
import type { BundleCodeSdkFunction } from "../functions/bundleCode/schemas";
|
|
10
12
|
import type { AppsPluginSdkExtension } from "../plugins/apps/types";
|
|
11
|
-
export interface ZapierSdkFunctions extends ListActionsSdkFunction, GetActionSdkFunction, GetAppSdkFunction, RunActionSdkFunction, ListFieldsSdkFunction,
|
|
13
|
+
export interface ZapierSdkFunctions extends ListActionsSdkFunction, GetActionSdkFunction, GetAppSdkFunction, RunActionSdkFunction, ListFieldsSdkFunction, ListAuthenticationsSdkFunction, FindFirstAuthenticationSdkFunction, FindUniqueAuthenticationSdkFunction, GenerateTypesSdkFunction, ListAppsSdkFunction, BundleCodeSdkFunction {
|
|
12
14
|
}
|
|
13
15
|
export interface ZapierSdkPlugins extends AppsPluginSdkExtension {
|
|
14
16
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Attempts to read the JWT token from the CLI config file.
|
|
3
|
+
* This is a synchronous function that only returns valid, non-expired tokens.
|
|
4
|
+
* For token refresh logic, the CLI should handle that separately.
|
|
5
|
+
* Returns undefined if config file doesn't exist, token is not available, or token is expired.
|
|
6
|
+
*/
|
|
7
|
+
export declare function getTokenFromConfig(): string | undefined;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getTokenFromConfig = getTokenFromConfig;
|
|
4
|
+
/**
|
|
5
|
+
* Attempts to read the JWT token from the CLI config file.
|
|
6
|
+
* This is a synchronous function that only returns valid, non-expired tokens.
|
|
7
|
+
* For token refresh logic, the CLI should handle that separately.
|
|
8
|
+
* Returns undefined if config file doesn't exist, token is not available, or token is expired.
|
|
9
|
+
*/
|
|
10
|
+
function getTokenFromConfig() {
|
|
11
|
+
try {
|
|
12
|
+
// Dynamically import conf to avoid dependency issues if not installed
|
|
13
|
+
const Conf = require("conf");
|
|
14
|
+
const config = new Conf({ projectName: "zapier-sdk-cli" });
|
|
15
|
+
// Get the stored JWT token
|
|
16
|
+
const jwt = config.get("login_jwt");
|
|
17
|
+
const expiresAt = config.get("login_expires_at");
|
|
18
|
+
// Check if token exists and is not expired (with 30s buffer)
|
|
19
|
+
if (jwt && expiresAt && expiresAt > Date.now() + 30 * 1000) {
|
|
20
|
+
return jwt;
|
|
21
|
+
}
|
|
22
|
+
// Token is missing or expired - return undefined so SDK will require explicit auth
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
// Config package not available or other error - silently fail
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zapier/zapier-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Complete Zapier SDK - combines all Zapier SDK packages",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -18,9 +18,7 @@
|
|
|
18
18
|
"access": "restricted"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"dotenv": "^17.0.0",
|
|
22
21
|
"esbuild": "^0.25.5",
|
|
23
|
-
"find-up": "^7.0.0",
|
|
24
22
|
"zod": "^3.25.67"
|
|
25
23
|
},
|
|
26
24
|
"devDependencies": {
|
package/src/api/client.ts
CHANGED
|
@@ -19,6 +19,7 @@ export function createZapierApi(options: ApiClientOptions): ApiClient {
|
|
|
19
19
|
const {
|
|
20
20
|
baseUrl,
|
|
21
21
|
token,
|
|
22
|
+
getToken,
|
|
22
23
|
debug = false,
|
|
23
24
|
fetch: originalFetch = globalThis.fetch,
|
|
24
25
|
} = options;
|
|
@@ -41,14 +42,29 @@ export function createZapierApi(options: ApiClientOptions): ApiClient {
|
|
|
41
42
|
}
|
|
42
43
|
|
|
43
44
|
// Helper to build headers
|
|
44
|
-
function buildHeaders(
|
|
45
|
+
async function buildHeaders(
|
|
46
|
+
options: RequestOptions = {},
|
|
47
|
+
): Promise<Record<string, string>> {
|
|
45
48
|
const headers: Record<string, string> = {
|
|
46
49
|
...options.headers,
|
|
47
50
|
};
|
|
48
51
|
|
|
49
52
|
// Add auth header if token provided and not explicitly disabled
|
|
50
|
-
if (
|
|
51
|
-
|
|
53
|
+
if (options.authRequired !== false) {
|
|
54
|
+
let resolvedToken = token;
|
|
55
|
+
|
|
56
|
+
// Token resolution precedence: explicit token > getToken() > env var
|
|
57
|
+
if (!resolvedToken && getToken) {
|
|
58
|
+
resolvedToken = await getToken();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (!resolvedToken) {
|
|
62
|
+
resolvedToken = process.env.ZAPIER_TOKEN;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (resolvedToken) {
|
|
66
|
+
headers.Authorization = getAuthorizationHeader(resolvedToken);
|
|
67
|
+
}
|
|
52
68
|
}
|
|
53
69
|
|
|
54
70
|
return headers;
|
|
@@ -87,7 +103,7 @@ export function createZapierApi(options: ApiClientOptions): ApiClient {
|
|
|
87
103
|
options: RequestOptions = {},
|
|
88
104
|
): Promise<any> {
|
|
89
105
|
const url = buildUrl(path, options.searchParams);
|
|
90
|
-
const headers = buildHeaders(options);
|
|
106
|
+
const headers = await buildHeaders(options);
|
|
91
107
|
|
|
92
108
|
// Add Content-Type for JSON requests with body data
|
|
93
109
|
if (data && typeof data === "object") {
|
|
@@ -130,7 +146,7 @@ export function createZapierApi(options: ApiClientOptions): ApiClient {
|
|
|
130
146
|
|
|
131
147
|
async poll(path: string, options: PollOptions = {}): Promise<any> {
|
|
132
148
|
const url = buildUrl(path, options.searchParams);
|
|
133
|
-
const headers = buildHeaders(options);
|
|
149
|
+
const headers = await buildHeaders(options);
|
|
134
150
|
|
|
135
151
|
return pollUntilComplete({
|
|
136
152
|
fetch,
|
|
@@ -144,5 +160,14 @@ export function createZapierApi(options: ApiClientOptions): ApiClient {
|
|
|
144
160
|
resultExtractor: options.resultExtractor,
|
|
145
161
|
});
|
|
146
162
|
},
|
|
163
|
+
|
|
164
|
+
requireAuthTo(operation: string): void {
|
|
165
|
+
// Check if any authentication method is available
|
|
166
|
+
if (!token && !getToken && !process.env.ZAPIER_TOKEN) {
|
|
167
|
+
throw new Error(
|
|
168
|
+
`Authentication token is required to ${operation}. Please provide token in options or set ZAPIER_TOKEN environment variable.`,
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
},
|
|
147
172
|
};
|
|
148
173
|
}
|
package/src/api/index.ts
CHANGED
|
@@ -29,6 +29,9 @@ export type {
|
|
|
29
29
|
AuthenticationsResponse,
|
|
30
30
|
} from "./types";
|
|
31
31
|
|
|
32
|
+
// Import for local use
|
|
33
|
+
import type { ApiClient } from "./types";
|
|
34
|
+
|
|
32
35
|
// Re-export authentication utilities
|
|
33
36
|
export { isJwt, getAuthorizationHeader } from "./auth";
|
|
34
37
|
|
|
@@ -41,6 +44,9 @@ export { pollUntilComplete } from "./polling";
|
|
|
41
44
|
// Re-export the main client factory
|
|
42
45
|
export { createZapierApi } from "./client";
|
|
43
46
|
|
|
47
|
+
// Import for local use
|
|
48
|
+
import { createZapierApi } from "./client";
|
|
49
|
+
|
|
44
50
|
// Utility Functions
|
|
45
51
|
export function generateRequestId(): string {
|
|
46
52
|
return Math.random().toString(36).substring(2) + Date.now().toString(36);
|
|
@@ -55,13 +61,15 @@ export function generateRequestId(): string {
|
|
|
55
61
|
export function getOrCreateApiClient(config: {
|
|
56
62
|
baseUrl?: string;
|
|
57
63
|
token?: string;
|
|
58
|
-
|
|
64
|
+
getToken?: () => Promise<string | undefined>;
|
|
65
|
+
api?: ApiClient;
|
|
59
66
|
debug?: boolean;
|
|
60
67
|
fetch?: typeof globalThis.fetch;
|
|
61
|
-
}):
|
|
68
|
+
}): ApiClient {
|
|
62
69
|
const {
|
|
63
70
|
baseUrl = "https://zapier.com",
|
|
64
|
-
token
|
|
71
|
+
token,
|
|
72
|
+
getToken,
|
|
65
73
|
api: providedApi,
|
|
66
74
|
debug = false,
|
|
67
75
|
fetch: customFetch,
|
|
@@ -72,11 +80,10 @@ export function getOrCreateApiClient(config: {
|
|
|
72
80
|
return providedApi;
|
|
73
81
|
}
|
|
74
82
|
|
|
75
|
-
// Import createZapierApi locally to avoid circular imports
|
|
76
|
-
const { createZapierApi } = require("./client");
|
|
77
83
|
return createZapierApi({
|
|
78
84
|
baseUrl,
|
|
79
85
|
token,
|
|
86
|
+
getToken,
|
|
80
87
|
debug,
|
|
81
88
|
fetch: customFetch,
|
|
82
89
|
});
|
package/src/api/types.ts
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
export interface ApiClientOptions {
|
|
14
14
|
baseUrl: string;
|
|
15
15
|
token?: string;
|
|
16
|
+
getToken?: () => Promise<string | undefined>;
|
|
16
17
|
debug?: boolean;
|
|
17
18
|
fetch?: typeof globalThis.fetch;
|
|
18
19
|
}
|
|
@@ -23,6 +24,7 @@ export interface ApiClient {
|
|
|
23
24
|
put: (path: string, data?: any, options?: RequestOptions) => Promise<any>;
|
|
24
25
|
delete: (path: string, options?: RequestOptions) => Promise<any>;
|
|
25
26
|
poll: (path: string, options?: PollOptions) => Promise<any>;
|
|
27
|
+
requireAuthTo: (operation: string) => void;
|
|
26
28
|
}
|
|
27
29
|
|
|
28
30
|
export interface RequestOptions {
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Authentication } from "../../types/domain";
|
|
2
|
+
import { listAuthentications } from "../listAuthentications";
|
|
3
|
+
import type { FindFirstAuthenticationOptions } from "./schemas";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Find the first authentication matching the given criteria
|
|
7
|
+
*
|
|
8
|
+
* This function can be used standalone without instantiating a full SDK,
|
|
9
|
+
* which enables better tree-shaking in applications that only need this functionality.
|
|
10
|
+
*
|
|
11
|
+
* @param options - Filtering and API configuration options
|
|
12
|
+
* @returns Promise<Authentication | null> - First matching authentication or null if not found
|
|
13
|
+
*/
|
|
14
|
+
export async function findFirstAuthentication(
|
|
15
|
+
options: Partial<FindFirstAuthenticationOptions> = {},
|
|
16
|
+
): Promise<Authentication | null> {
|
|
17
|
+
// Use listAuthentications with limit 1 to get the first result
|
|
18
|
+
const auths = await listAuthentications({
|
|
19
|
+
...options,
|
|
20
|
+
limit: 1,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
return auths.length > 0 ? auths[0] : null;
|
|
24
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { findFirstAuthentication } from "./index";
|
|
2
|
+
import { FindFirstAuthenticationSchema } from "./schemas";
|
|
3
|
+
|
|
4
|
+
// Function registry info - imports both function and schema
|
|
5
|
+
export const findFirstAuthenticationInfo = {
|
|
6
|
+
name: findFirstAuthentication.name,
|
|
7
|
+
inputSchema: FindFirstAuthenticationSchema,
|
|
8
|
+
implementation: findFirstAuthentication,
|
|
9
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import {
|
|
3
|
+
AppKeyPropertySchema,
|
|
4
|
+
LimitPropertySchema,
|
|
5
|
+
OffsetPropertySchema,
|
|
6
|
+
} from "../../types/properties";
|
|
7
|
+
import { withOutputSchema } from "../../schema-utils";
|
|
8
|
+
import { AuthItemSchema } from "../../schemas/Auth";
|
|
9
|
+
import type { Authentication } from "../../types/domain";
|
|
10
|
+
|
|
11
|
+
// Pure Zod schema - no resolver metadata!
|
|
12
|
+
export const FindFirstAuthenticationSchema = withOutputSchema(
|
|
13
|
+
z
|
|
14
|
+
.object({
|
|
15
|
+
appKey: AppKeyPropertySchema.optional().describe(
|
|
16
|
+
"App slug to get authentications for (e.g., 'slack', 'github')",
|
|
17
|
+
),
|
|
18
|
+
search: z
|
|
19
|
+
.string()
|
|
20
|
+
.optional()
|
|
21
|
+
.describe("Search term to filter authentications by title"),
|
|
22
|
+
title: z
|
|
23
|
+
.string()
|
|
24
|
+
.optional()
|
|
25
|
+
.describe("Filter authentications by exact title match"),
|
|
26
|
+
account_id: z.string().optional().describe("Filter by account ID"),
|
|
27
|
+
owner: z.string().optional().describe("Filter by owner"),
|
|
28
|
+
limit: LimitPropertySchema.optional().describe(
|
|
29
|
+
"Maximum number of items to return (1-200)",
|
|
30
|
+
),
|
|
31
|
+
offset: OffsetPropertySchema.optional().describe(
|
|
32
|
+
"Number of items to skip for pagination",
|
|
33
|
+
),
|
|
34
|
+
})
|
|
35
|
+
.describe("Find the first authentication matching the criteria"),
|
|
36
|
+
AuthItemSchema,
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
// Type inferred from schema + function config
|
|
40
|
+
export type FindFirstAuthenticationOptions = z.infer<
|
|
41
|
+
typeof FindFirstAuthenticationSchema
|
|
42
|
+
> & {
|
|
43
|
+
/** Base URL for Zapier API */
|
|
44
|
+
baseUrl?: string;
|
|
45
|
+
/** Authentication token */
|
|
46
|
+
token?: string;
|
|
47
|
+
/** Optional pre-instantiated API client */
|
|
48
|
+
api?: any;
|
|
49
|
+
/** Enable debug logging */
|
|
50
|
+
debug?: boolean;
|
|
51
|
+
/** Custom fetch implementation */
|
|
52
|
+
fetch?: typeof globalThis.fetch;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// SDK function interface - ready to be mixed into main SDK interface
|
|
56
|
+
export interface FindFirstAuthenticationSdkFunction {
|
|
57
|
+
findFirstAuthentication: (
|
|
58
|
+
options?: Partial<FindFirstAuthenticationOptions>,
|
|
59
|
+
) => Promise<Authentication | null>;
|
|
60
|
+
}
|