@zapier/zapier-sdk 0.15.4 → 0.15.9
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 +30 -0
- package/dist/api/auth.d.ts.map +1 -1
- package/dist/api/auth.js +14 -4
- package/dist/api/auth.test.d.ts +2 -0
- package/dist/api/auth.test.d.ts.map +1 -0
- package/dist/api/auth.test.js +220 -0
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.js +18 -32
- package/dist/api/client.methods.test.d.ts +2 -0
- package/dist/api/client.methods.test.d.ts.map +1 -0
- package/dist/api/client.methods.test.js +158 -0
- package/dist/api/client.test.js +27 -11
- package/dist/api/router.d.ts +16 -0
- package/dist/api/router.d.ts.map +1 -0
- package/dist/api/router.js +37 -0
- package/dist/api/router.test.d.ts +2 -0
- package/dist/api/router.test.d.ts.map +1 -0
- package/dist/api/router.test.js +109 -0
- package/dist/auth.d.ts +15 -0
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +25 -0
- package/dist/index.cjs +247 -74
- package/dist/index.d.mts +402 -241
- package/dist/index.mjs +247 -75
- package/dist/plugins/eventEmission/index.d.ts.map +1 -1
- package/dist/plugins/eventEmission/index.js +9 -5
- package/dist/plugins/eventEmission/index.test.js +161 -0
- package/dist/plugins/getAction/index.d.ts.map +1 -1
- package/dist/plugins/getAction/index.js +2 -4
- package/dist/plugins/getAction/index.test.js +26 -3
- package/dist/plugins/getAuthentication/index.d.ts +2 -5
- package/dist/plugins/getAuthentication/index.d.ts.map +1 -1
- package/dist/plugins/getAuthentication/index.js +3 -24
- package/dist/plugins/getAuthentication/index.test.js +32 -144
- package/dist/plugins/getAuthentication/schemas.d.ts +4 -13
- package/dist/plugins/getAuthentication/schemas.d.ts.map +1 -1
- package/dist/plugins/getAuthentication/schemas.js +1 -11
- package/dist/sdk.d.ts +1 -1
- package/dist/temporary-internal-core/handlers/getAuthentication.d.ts +94 -0
- package/dist/temporary-internal-core/handlers/getAuthentication.d.ts.map +1 -0
- package/dist/temporary-internal-core/handlers/getAuthentication.js +68 -0
- package/dist/temporary-internal-core/handlers/getAuthentication.test.d.ts +2 -0
- package/dist/temporary-internal-core/handlers/getAuthentication.test.d.ts.map +1 -0
- package/dist/temporary-internal-core/handlers/getAuthentication.test.js +248 -0
- package/dist/temporary-internal-core/handlers/listApps.js +1 -1
- package/dist/temporary-internal-core/index.d.ts +2 -0
- package/dist/temporary-internal-core/index.d.ts.map +1 -1
- package/dist/temporary-internal-core/index.js +2 -0
- package/dist/temporary-internal-core/schemas/authentications/index.d.ts +454 -0
- package/dist/temporary-internal-core/schemas/authentications/index.d.ts.map +1 -0
- package/dist/temporary-internal-core/schemas/authentications/index.js +96 -0
- package/dist/temporary-internal-core/schemas/errors/index.d.ts +139 -0
- package/dist/temporary-internal-core/schemas/errors/index.d.ts.map +1 -0
- package/dist/temporary-internal-core/schemas/errors/index.js +129 -0
- package/dist/temporary-internal-core/utils/app-locators.d.ts +0 -20
- package/dist/temporary-internal-core/utils/app-locators.d.ts.map +1 -1
- package/dist/temporary-internal-core/utils/app-locators.js +1 -45
- package/dist/temporary-internal-core/utils/string-utils.d.ts +28 -0
- package/dist/temporary-internal-core/utils/string-utils.d.ts.map +1 -0
- package/dist/temporary-internal-core/utils/string-utils.js +52 -0
- package/dist/temporary-internal-core/utils/transformations.d.ts +14 -0
- package/dist/temporary-internal-core/utils/transformations.d.ts.map +1 -1
- package/dist/temporary-internal-core/utils/transformations.js +37 -1
- package/package.json +1 -1
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type Handler } from "../temporary-internal-core";
|
|
2
|
+
export interface Route {
|
|
3
|
+
method: string;
|
|
4
|
+
pattern: RegExp;
|
|
5
|
+
handler: Handler<any, any, any>;
|
|
6
|
+
paramMap: string[];
|
|
7
|
+
}
|
|
8
|
+
export declare function findMatchingRoute(routeList: Route[], method: string, path: string): {
|
|
9
|
+
handler: Handler<any, any, any>;
|
|
10
|
+
params: Record<string, string>;
|
|
11
|
+
} | null;
|
|
12
|
+
export declare function matchRoute(method: string, path: string): {
|
|
13
|
+
handler: Handler<any, any, any>;
|
|
14
|
+
params: Record<string, string>;
|
|
15
|
+
} | null;
|
|
16
|
+
//# sourceMappingURL=router.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/api/router.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,OAAO,EACb,MAAM,4BAA4B,CAAC;AAEpC,MAAM,WAAW,KAAK;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;IAChC,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAiBD,wBAAgB,iBAAiB,CAC/B,SAAS,EAAE,KAAK,EAAE,EAClB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM;;;SAsBb;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;;;SAEtD"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { handleListApps, handleGetAuthentication, } from "../temporary-internal-core";
|
|
2
|
+
const routes = [
|
|
3
|
+
{
|
|
4
|
+
method: "GET",
|
|
5
|
+
pattern: /^\/api\/v0\/apps$/,
|
|
6
|
+
handler: handleListApps,
|
|
7
|
+
paramMap: [],
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
method: "GET",
|
|
11
|
+
pattern: /^\/api\/v0\/authentications\/([^\/]+)$/,
|
|
12
|
+
handler: handleGetAuthentication,
|
|
13
|
+
paramMap: ["authenticationId"],
|
|
14
|
+
},
|
|
15
|
+
];
|
|
16
|
+
export function findMatchingRoute(routeList, method, path) {
|
|
17
|
+
for (const route of routeList) {
|
|
18
|
+
if (route.method !== method) {
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
const match = path.match(route.pattern);
|
|
22
|
+
if (match) {
|
|
23
|
+
const params = {};
|
|
24
|
+
route.paramMap.forEach((name, index) => {
|
|
25
|
+
params[name] = match[index + 1];
|
|
26
|
+
});
|
|
27
|
+
return {
|
|
28
|
+
handler: route.handler,
|
|
29
|
+
params,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
export function matchRoute(method, path) {
|
|
36
|
+
return findMatchingRoute(routes, method, path);
|
|
37
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router.test.d.ts","sourceRoot":"","sources":["../../src/api/router.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from "vitest";
|
|
2
|
+
import { matchRoute, findMatchingRoute } from "./router";
|
|
3
|
+
import { handleListApps, handleGetAuthentication, } from "../temporary-internal-core";
|
|
4
|
+
describe("Router", () => {
|
|
5
|
+
describe("matchRoute (Integration)", () => {
|
|
6
|
+
it("should match GET /api/v0/apps", () => {
|
|
7
|
+
const match = matchRoute("GET", "/api/v0/apps");
|
|
8
|
+
expect(match).not.toBeNull();
|
|
9
|
+
expect(match?.handler).toBe(handleListApps);
|
|
10
|
+
expect(match?.params).toEqual({});
|
|
11
|
+
});
|
|
12
|
+
it("should match GET /api/v0/authentications/:authenticationId", () => {
|
|
13
|
+
const match = matchRoute("GET", "/api/v0/authentications/12345");
|
|
14
|
+
expect(match).not.toBeNull();
|
|
15
|
+
expect(match?.handler).toBe(handleGetAuthentication);
|
|
16
|
+
expect(match?.params).toEqual({ authenticationId: "12345" });
|
|
17
|
+
});
|
|
18
|
+
it("should not match POST /api/v0/apps", () => {
|
|
19
|
+
const match = matchRoute("POST", "/api/v0/apps");
|
|
20
|
+
expect(match).toBeNull();
|
|
21
|
+
});
|
|
22
|
+
it("should not match unknown paths", () => {
|
|
23
|
+
expect(matchRoute("GET", "/api/v0/unknown")).toBeNull();
|
|
24
|
+
expect(matchRoute("GET", "/")).toBeNull();
|
|
25
|
+
});
|
|
26
|
+
it("should not match partial paths if regex is anchored", () => {
|
|
27
|
+
// The regex is /^\/api\/v0\/apps$/ so it shouldn't match suffix
|
|
28
|
+
expect(matchRoute("GET", "/api/v0/apps/something")).toBeNull();
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
describe("findMatchingRoute (Unit)", () => {
|
|
32
|
+
const mockHandler = vi.fn();
|
|
33
|
+
const testRoutes = [
|
|
34
|
+
{
|
|
35
|
+
method: "GET",
|
|
36
|
+
pattern: /^\/items$/,
|
|
37
|
+
handler: mockHandler,
|
|
38
|
+
paramMap: [],
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
method: "GET",
|
|
42
|
+
pattern: /^\/items\/(\d+)$/,
|
|
43
|
+
handler: mockHandler,
|
|
44
|
+
paramMap: ["id"],
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
method: "POST",
|
|
48
|
+
pattern: /^\/items$/,
|
|
49
|
+
handler: mockHandler,
|
|
50
|
+
paramMap: [],
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
method: "GET",
|
|
54
|
+
pattern: /^\/users\/(\w+)\/posts\/(\d+)$/,
|
|
55
|
+
handler: mockHandler,
|
|
56
|
+
paramMap: ["userId", "postId"],
|
|
57
|
+
},
|
|
58
|
+
];
|
|
59
|
+
it("should match exact path", () => {
|
|
60
|
+
const match = findMatchingRoute(testRoutes, "GET", "/items");
|
|
61
|
+
expect(match).not.toBeNull();
|
|
62
|
+
expect(match?.handler).toBe(mockHandler);
|
|
63
|
+
expect(match?.params).toEqual({});
|
|
64
|
+
});
|
|
65
|
+
it("should extract single parameter", () => {
|
|
66
|
+
const match = findMatchingRoute(testRoutes, "GET", "/items/123");
|
|
67
|
+
expect(match).not.toBeNull();
|
|
68
|
+
expect(match?.params).toEqual({ id: "123" });
|
|
69
|
+
});
|
|
70
|
+
it("should extract multiple parameters", () => {
|
|
71
|
+
const match = findMatchingRoute(testRoutes, "GET", "/users/alice/posts/456");
|
|
72
|
+
expect(match).not.toBeNull();
|
|
73
|
+
expect(match?.params).toEqual({ userId: "alice", postId: "456" });
|
|
74
|
+
});
|
|
75
|
+
it("should respect HTTP method", () => {
|
|
76
|
+
// GET /items exists
|
|
77
|
+
expect(findMatchingRoute(testRoutes, "GET", "/items")).not.toBeNull();
|
|
78
|
+
// POST /items exists
|
|
79
|
+
expect(findMatchingRoute(testRoutes, "POST", "/items")).not.toBeNull();
|
|
80
|
+
// PUT /items does not exist
|
|
81
|
+
expect(findMatchingRoute(testRoutes, "PUT", "/items")).toBeNull();
|
|
82
|
+
});
|
|
83
|
+
it("should not match if regex does not match", () => {
|
|
84
|
+
// /items/abc does not match /^\/items\/(\d+)$/ (\d+ is digits only)
|
|
85
|
+
expect(findMatchingRoute(testRoutes, "GET", "/items/abc")).toBeNull();
|
|
86
|
+
});
|
|
87
|
+
it("should handle empty route list", () => {
|
|
88
|
+
expect(findMatchingRoute([], "GET", "/anything")).toBeNull();
|
|
89
|
+
});
|
|
90
|
+
it("should return first matching route", () => {
|
|
91
|
+
const overlappingRoutes = [
|
|
92
|
+
{
|
|
93
|
+
method: "GET",
|
|
94
|
+
pattern: /^\/overlapping$/,
|
|
95
|
+
handler: mockHandler,
|
|
96
|
+
paramMap: [],
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
method: "GET",
|
|
100
|
+
pattern: /^\/overlapping$/, // duplicate pattern
|
|
101
|
+
handler: () => Promise.resolve("second"),
|
|
102
|
+
paramMap: [],
|
|
103
|
+
},
|
|
104
|
+
];
|
|
105
|
+
const match = findMatchingRoute(overlappingRoutes, "GET", "/overlapping");
|
|
106
|
+
expect(match?.handler).toBe(mockHandler); // Should match the first one
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
});
|
package/dist/auth.d.ts
CHANGED
|
@@ -14,6 +14,10 @@ export interface AuthOptions {
|
|
|
14
14
|
authBaseUrl?: string;
|
|
15
15
|
authClientId?: string;
|
|
16
16
|
}
|
|
17
|
+
export interface ResolveAuthTokenOptions extends AuthOptions {
|
|
18
|
+
token?: string;
|
|
19
|
+
getToken?: () => Promise<string | undefined> | string | undefined;
|
|
20
|
+
}
|
|
17
21
|
/**
|
|
18
22
|
* Gets the ZAPIER_TOKEN from environment variables.
|
|
19
23
|
* Returns undefined if not set.
|
|
@@ -34,4 +38,15 @@ export declare function getTokenFromCliLogin(options?: AuthOptions): Promise<str
|
|
|
34
38
|
* Returns undefined if no valid token is found.
|
|
35
39
|
*/
|
|
36
40
|
export declare function getTokenFromEnvOrConfig(options?: AuthOptions): Promise<string | undefined>;
|
|
41
|
+
/**
|
|
42
|
+
* Resolves an auth token from all possible sources with the following precedence:
|
|
43
|
+
* 1. Explicitly provided token in options
|
|
44
|
+
* 2. Token from getToken callback in options
|
|
45
|
+
* 3. ZAPIER_TOKEN environment variable
|
|
46
|
+
* 4. CLI login package (if available)
|
|
47
|
+
*
|
|
48
|
+
* This is the canonical token resolution logic used throughout the SDK.
|
|
49
|
+
* Returns undefined if no valid token is found.
|
|
50
|
+
*/
|
|
51
|
+
export declare function resolveAuthToken(options?: ResolveAuthTokenOptions): Promise<string | undefined>;
|
|
37
52
|
//# sourceMappingURL=auth.d.ts.map
|
package/dist/auth.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAGpD,YAAY,EACV,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,YAAY,EACZ,aAAa,GACd,MAAM,gBAAgB,CAAC;AAGxB,MAAM,WAAW,WAAW;IAC1B,OAAO,CAAC,EAAE,aAAa,CAAC;IACxB,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,K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S,CAAC,CAS7B;AAED;;;;;;GAMG;AACH,wBAAsB,uBAAuB,CAC3C,OAAO,GAAE,WAAgB,GACxB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAS7B;AAED;;;;;;;;;GASG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,GAAE,uBAA4B,GACpC,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAgB7B"}
|
package/dist/auth.js
CHANGED
|
@@ -45,3 +45,28 @@ export async function getTokenFromEnvOrConfig(options = {}) {
|
|
|
45
45
|
// Second priority: CLI login package (if available)
|
|
46
46
|
return getTokenFromCliLogin(options);
|
|
47
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Resolves an auth token from all possible sources with the following precedence:
|
|
50
|
+
* 1. Explicitly provided token in options
|
|
51
|
+
* 2. Token from getToken callback in options
|
|
52
|
+
* 3. ZAPIER_TOKEN environment variable
|
|
53
|
+
* 4. CLI login package (if available)
|
|
54
|
+
*
|
|
55
|
+
* This is the canonical token resolution logic used throughout the SDK.
|
|
56
|
+
* Returns undefined if no valid token is found.
|
|
57
|
+
*/
|
|
58
|
+
export async function resolveAuthToken(options = {}) {
|
|
59
|
+
// First priority: explicitly provided token
|
|
60
|
+
if (options.token) {
|
|
61
|
+
return options.token;
|
|
62
|
+
}
|
|
63
|
+
// Second priority: getToken callback
|
|
64
|
+
if (options.getToken) {
|
|
65
|
+
const token = await options.getToken();
|
|
66
|
+
if (token) {
|
|
67
|
+
return token;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
// Third and fourth priorities: environment variable or CLI login
|
|
71
|
+
return getTokenFromEnvOrConfig(options);
|
|
72
|
+
}
|