@zapier/zapier-sdk 0.18.4 → 1.0.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 +11 -0
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.js +11 -6
- package/dist/api/client.test.js +82 -27
- package/dist/api/index.d.ts +3 -2
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +2 -3
- package/dist/api/schemas.d.ts +5 -5
- package/dist/api/types.d.ts +8 -3
- package/dist/api/types.d.ts.map +1 -1
- package/dist/auth.d.ts +54 -26
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +211 -39
- package/dist/auth.test.js +338 -64
- package/dist/constants.d.ts +14 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +14 -0
- package/dist/credentials.d.ts +57 -0
- package/dist/credentials.d.ts.map +1 -0
- package/dist/credentials.js +174 -0
- package/dist/index.cjs +341 -46
- package/dist/index.d.mts +213 -29
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.mjs +321 -45
- package/dist/plugins/api/index.d.ts +2 -0
- package/dist/plugins/api/index.d.ts.map +1 -1
- package/dist/plugins/api/index.js +8 -4
- package/dist/plugins/eventEmission/index.d.ts.map +1 -1
- package/dist/plugins/eventEmission/index.js +1 -3
- package/dist/plugins/eventEmission/index.test.js +14 -17
- package/dist/plugins/getAction/schemas.d.ts +1 -1
- package/dist/plugins/getInputFieldsSchema/schemas.d.ts +1 -1
- package/dist/plugins/listActions/index.test.js +1 -0
- package/dist/plugins/listActions/schemas.d.ts +1 -1
- package/dist/plugins/listInputFieldChoices/schemas.d.ts +1 -1
- package/dist/plugins/listInputFields/schemas.d.ts +1 -1
- package/dist/plugins/runAction/schemas.d.ts +1 -1
- package/dist/schemas/Action.d.ts +1 -1
- package/dist/sdk.d.ts +1 -0
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.test.js +5 -4
- package/dist/types/credentials.d.ts +65 -0
- package/dist/types/credentials.d.ts.map +1 -0
- package/dist/types/credentials.js +42 -0
- package/dist/types/properties.d.ts +1 -1
- package/dist/types/sdk.d.ts +12 -3
- package/dist/types/sdk.d.ts.map +1 -1
- package/dist/utils/logging.d.ts +13 -0
- package/dist/utils/logging.d.ts.map +1 -0
- package/dist/utils/logging.js +20 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
package/dist/api/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,SAAS,EACT,gBAAgB,EAGjB,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,SAAS,EACT,gBAAgB,EAGjB,MAAM,SAAS,CAAC;AAmfjB,eAAO,MAAM,eAAe,GAAI,SAAS,gBAAgB,KAAG,SAW3D,CAAC"}
|
package/dist/api/client.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
import { getAuthorizationHeader } from "./auth";
|
|
8
8
|
import { createDebugLogger, createDebugFetch } from "./debug";
|
|
9
9
|
import { pollUntilComplete } from "./polling";
|
|
10
|
-
import { resolveAuthToken } from "../auth";
|
|
10
|
+
import { resolveAuthToken, invalidateCredentialsToken } from "../auth";
|
|
11
11
|
import { getZapierBaseUrl } from "../utils/url-utils";
|
|
12
12
|
import { ZapierApiError, ZapierAuthenticationError, ZapierValidationError, ZapierNotFoundError, } from "../types/errors";
|
|
13
13
|
// Configuration for paths
|
|
@@ -68,13 +68,11 @@ class ZapierApiClient {
|
|
|
68
68
|
// Helper to get a token from the different places it could be gotten
|
|
69
69
|
async getAuthToken() {
|
|
70
70
|
return resolveAuthToken({
|
|
71
|
+
credentials: this.options.credentials,
|
|
71
72
|
token: this.options.token,
|
|
72
|
-
getToken: this.options.getToken,
|
|
73
73
|
onEvent: this.options.onEvent,
|
|
74
74
|
fetch: this.options.fetch,
|
|
75
75
|
baseUrl: this.options.baseUrl,
|
|
76
|
-
authBaseUrl: this.options.authBaseUrl,
|
|
77
|
-
authClientId: this.options.authClientId,
|
|
78
76
|
});
|
|
79
77
|
}
|
|
80
78
|
// Helper to handle responses
|
|
@@ -115,7 +113,14 @@ class ZapierApiClient {
|
|
|
115
113
|
if (response.status === 401 || response.status === 403) {
|
|
116
114
|
// If we get a 401/403 error and no auth token was provided, give helpful message
|
|
117
115
|
if (wasMissingAuthToken) {
|
|
118
|
-
throw new ZapierAuthenticationError(`Authentication required (HTTP ${response.status}). Please provide
|
|
116
|
+
throw new ZapierAuthenticationError(`Authentication required (HTTP ${response.status}). Please provide credentials in options or set ZAPIER_CREDENTIALS environment variable.`, errorOptions);
|
|
117
|
+
}
|
|
118
|
+
// On 401, invalidate cached token so next request gets a fresh one
|
|
119
|
+
if (response.status === 401) {
|
|
120
|
+
await invalidateCredentialsToken({
|
|
121
|
+
credentials: this.options.credentials,
|
|
122
|
+
token: this.options.token,
|
|
123
|
+
});
|
|
119
124
|
}
|
|
120
125
|
throw new ZapierAuthenticationError(message, errorOptions);
|
|
121
126
|
}
|
|
@@ -289,7 +294,7 @@ class ZapierApiClient {
|
|
|
289
294
|
// before we even make a request.
|
|
290
295
|
if (options.authRequired) {
|
|
291
296
|
if (headers.get("Authorization") == null && authToken == null) {
|
|
292
|
-
throw new ZapierAuthenticationError(`Authentication required but no
|
|
297
|
+
throw new ZapierAuthenticationError(`Authentication required but no credentials available. Please set ZAPIER_CREDENTIALS, or run the 'login' command with the CLI.`);
|
|
293
298
|
}
|
|
294
299
|
}
|
|
295
300
|
return headers;
|
package/dist/api/client.test.js
CHANGED
|
@@ -4,6 +4,7 @@ import * as auth from "../auth";
|
|
|
4
4
|
vi.mock("../auth");
|
|
5
5
|
describe("ApiClient", () => {
|
|
6
6
|
const mockResolveAuthToken = vi.mocked(auth.resolveAuthToken);
|
|
7
|
+
const mockInvalidateCredentialsToken = vi.mocked(auth.invalidateCredentialsToken);
|
|
7
8
|
beforeEach(() => {
|
|
8
9
|
vi.clearAllMocks();
|
|
9
10
|
// Prevent any actual HTTP calls
|
|
@@ -14,83 +15,137 @@ describe("ApiClient", () => {
|
|
|
14
15
|
});
|
|
15
16
|
});
|
|
16
17
|
describe("authentication token resolution", () => {
|
|
17
|
-
it("should pass
|
|
18
|
+
it("should pass credentials to resolveAuthToken when provided", async () => {
|
|
18
19
|
mockResolveAuthToken.mockResolvedValue("test-token");
|
|
20
|
+
const credentials = {
|
|
21
|
+
type: "client_credentials",
|
|
22
|
+
clientId: "my-client",
|
|
23
|
+
clientSecret: "my-secret",
|
|
24
|
+
};
|
|
19
25
|
const client = createZapierApi({
|
|
20
26
|
baseUrl: "https://api.custom.zapier.dev",
|
|
21
|
-
|
|
27
|
+
credentials,
|
|
22
28
|
debug: false,
|
|
23
29
|
});
|
|
24
30
|
// Make a request that would trigger token resolution
|
|
25
31
|
await client.get("/test", { authRequired: true });
|
|
26
32
|
expect(mockResolveAuthToken).toHaveBeenCalledWith({
|
|
33
|
+
credentials,
|
|
27
34
|
token: undefined,
|
|
28
|
-
getToken: undefined,
|
|
29
35
|
onEvent: undefined,
|
|
30
36
|
fetch: expect.any(Function),
|
|
31
37
|
baseUrl: "https://api.custom.zapier.dev",
|
|
32
|
-
authBaseUrl: "https://auth.custom.zapier.dev",
|
|
33
|
-
authClientId: undefined,
|
|
34
38
|
});
|
|
35
39
|
});
|
|
36
|
-
it("should pass undefined
|
|
40
|
+
it("should pass undefined credentials when not provided", async () => {
|
|
37
41
|
mockResolveAuthToken.mockResolvedValue("test-token");
|
|
38
42
|
const client = createZapierApi({
|
|
39
43
|
baseUrl: "https://api.custom.zapier.dev",
|
|
40
|
-
// authBaseUrl intentionally omitted
|
|
41
44
|
debug: false,
|
|
42
45
|
});
|
|
43
46
|
// Make a request that would trigger token resolution
|
|
44
47
|
await client.get("/test", { authRequired: true });
|
|
45
48
|
expect(mockResolveAuthToken).toHaveBeenCalledWith({
|
|
49
|
+
credentials: undefined,
|
|
46
50
|
token: undefined,
|
|
47
|
-
getToken: undefined,
|
|
48
51
|
onEvent: undefined,
|
|
49
52
|
fetch: expect.any(Function),
|
|
50
53
|
baseUrl: "https://api.custom.zapier.dev",
|
|
51
|
-
authBaseUrl: undefined,
|
|
52
|
-
authClientId: undefined,
|
|
53
54
|
});
|
|
54
55
|
});
|
|
55
|
-
it("should pass
|
|
56
|
-
mockResolveAuthToken.mockResolvedValue("
|
|
56
|
+
it("should pass deprecated token option to resolveAuthToken", async () => {
|
|
57
|
+
mockResolveAuthToken.mockResolvedValue("direct-token");
|
|
57
58
|
const client = createZapierApi({
|
|
59
|
+
token: "direct-token",
|
|
58
60
|
baseUrl: "https://api.custom.zapier.dev",
|
|
59
|
-
authClientId: "custom-client-id",
|
|
60
61
|
debug: false,
|
|
61
62
|
});
|
|
62
|
-
// Make a request that would
|
|
63
|
+
// Make a request that would use the direct token
|
|
63
64
|
await client.get("/test", { authRequired: true });
|
|
65
|
+
// resolveAuthToken is still called, but it returns the direct token immediately
|
|
64
66
|
expect(mockResolveAuthToken).toHaveBeenCalledWith({
|
|
67
|
+
credentials: undefined,
|
|
68
|
+
token: "direct-token",
|
|
69
|
+
onEvent: undefined,
|
|
70
|
+
fetch: expect.any(Function),
|
|
71
|
+
baseUrl: "https://api.custom.zapier.dev",
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
it("should pass string credentials to resolveAuthToken", async () => {
|
|
75
|
+
mockResolveAuthToken.mockResolvedValue("string-token");
|
|
76
|
+
const client = createZapierApi({
|
|
77
|
+
credentials: "string-token",
|
|
78
|
+
baseUrl: "https://api.custom.zapier.dev",
|
|
79
|
+
debug: false,
|
|
80
|
+
});
|
|
81
|
+
await client.get("/test", { authRequired: true });
|
|
82
|
+
expect(mockResolveAuthToken).toHaveBeenCalledWith({
|
|
83
|
+
credentials: "string-token",
|
|
65
84
|
token: undefined,
|
|
66
|
-
getToken: undefined,
|
|
67
85
|
onEvent: undefined,
|
|
68
86
|
fetch: expect.any(Function),
|
|
69
87
|
baseUrl: "https://api.custom.zapier.dev",
|
|
70
|
-
authBaseUrl: undefined,
|
|
71
|
-
authClientId: "custom-client-id",
|
|
72
88
|
});
|
|
73
89
|
});
|
|
74
|
-
it("should
|
|
75
|
-
mockResolveAuthToken.mockResolvedValue("
|
|
90
|
+
it("should pass credentials function to resolveAuthToken", async () => {
|
|
91
|
+
mockResolveAuthToken.mockResolvedValue("function-token");
|
|
92
|
+
const credentialsFn = () => Promise.resolve("dynamic-token");
|
|
76
93
|
const client = createZapierApi({
|
|
77
|
-
|
|
94
|
+
credentials: credentialsFn,
|
|
78
95
|
baseUrl: "https://api.custom.zapier.dev",
|
|
79
|
-
authBaseUrl: "https://auth.custom.zapier.dev",
|
|
80
96
|
debug: false,
|
|
81
97
|
});
|
|
82
|
-
// Make a request that would use the direct token
|
|
83
98
|
await client.get("/test", { authRequired: true });
|
|
84
|
-
// resolveAuthToken is still called, but it returns the direct token immediately
|
|
85
99
|
expect(mockResolveAuthToken).toHaveBeenCalledWith({
|
|
86
|
-
|
|
87
|
-
|
|
100
|
+
credentials: credentialsFn,
|
|
101
|
+
token: undefined,
|
|
88
102
|
onEvent: undefined,
|
|
89
103
|
fetch: expect.any(Function),
|
|
90
104
|
baseUrl: "https://api.custom.zapier.dev",
|
|
91
|
-
authBaseUrl: "https://auth.custom.zapier.dev",
|
|
92
|
-
authClientId: undefined,
|
|
93
105
|
});
|
|
94
106
|
});
|
|
95
107
|
});
|
|
108
|
+
describe("401 cache invalidation", () => {
|
|
109
|
+
it("should invalidate credentials token on 401 response", async () => {
|
|
110
|
+
mockResolveAuthToken.mockResolvedValue("test-token");
|
|
111
|
+
mockInvalidateCredentialsToken.mockResolvedValue(undefined);
|
|
112
|
+
const clientCredentials = {
|
|
113
|
+
type: "client_credentials",
|
|
114
|
+
clientId: "my-client-id",
|
|
115
|
+
clientSecret: "my-secret",
|
|
116
|
+
};
|
|
117
|
+
global.fetch = vi.fn().mockResolvedValue({
|
|
118
|
+
ok: false,
|
|
119
|
+
status: 401,
|
|
120
|
+
statusText: "Unauthorized",
|
|
121
|
+
json: () => Promise.resolve({ message: "Invalid token" }),
|
|
122
|
+
});
|
|
123
|
+
const client = createZapierApi({
|
|
124
|
+
credentials: clientCredentials,
|
|
125
|
+
baseUrl: "https://api.custom.zapier.dev",
|
|
126
|
+
debug: false,
|
|
127
|
+
});
|
|
128
|
+
await expect(client.get("/test")).rejects.toThrow();
|
|
129
|
+
expect(mockInvalidateCredentialsToken).toHaveBeenCalledWith({
|
|
130
|
+
credentials: clientCredentials,
|
|
131
|
+
token: undefined,
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
it("should not invalidate cache on 403 response", async () => {
|
|
135
|
+
mockResolveAuthToken.mockResolvedValue("test-token");
|
|
136
|
+
global.fetch = vi.fn().mockResolvedValue({
|
|
137
|
+
ok: false,
|
|
138
|
+
status: 403,
|
|
139
|
+
statusText: "Forbidden",
|
|
140
|
+
json: () => Promise.resolve({ message: "Access denied" }),
|
|
141
|
+
});
|
|
142
|
+
const client = createZapierApi({
|
|
143
|
+
credentials: "test-token",
|
|
144
|
+
baseUrl: "https://api.custom.zapier.dev",
|
|
145
|
+
debug: false,
|
|
146
|
+
});
|
|
147
|
+
await expect(client.get("/test")).rejects.toThrow();
|
|
148
|
+
expect(mockInvalidateCredentialsToken).not.toHaveBeenCalled();
|
|
149
|
+
});
|
|
150
|
+
});
|
|
96
151
|
});
|
package/dist/api/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
export type { ApiClient, ApiClientOptions, RequestOptions, PollOptions, DebugLogger, Action, Field, Choice, ActionExecutionResult, ActionField, ActionFieldChoice, NeedsRequest, NeedsResponse, Authentication, AuthenticationsResponse, Implementation, ImplementationsResponse, } from "./types";
|
|
9
9
|
import type { ApiClient } from "./types";
|
|
10
|
+
import type { Credentials } from "../types/credentials";
|
|
10
11
|
export { isJwt, getAuthorizationHeader } from "./auth";
|
|
11
12
|
export { createDebugLogger, createDebugFetch } from "./debug";
|
|
12
13
|
export { pollUntilComplete } from "./polling";
|
|
@@ -20,9 +21,9 @@ export declare function generateRequestId(): string;
|
|
|
20
21
|
*/
|
|
21
22
|
export declare function getOrCreateApiClient(config: {
|
|
22
23
|
baseUrl?: string;
|
|
23
|
-
|
|
24
|
+
credentials?: Credentials;
|
|
25
|
+
/** @deprecated Use `credentials` instead */
|
|
24
26
|
token?: string;
|
|
25
|
-
getToken?: () => Promise<string | undefined>;
|
|
26
27
|
api?: ApiClient;
|
|
27
28
|
debug?: boolean;
|
|
28
29
|
fetch?: typeof globalThis.fetch;
|
package/dist/api/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,YAAY,EAEV,SAAS,EACT,gBAAgB,EAChB,cAAc,EACd,WAAW,EACX,WAAW,EAEX,MAAM,EACN,KAAK,EACL,MAAM,EACN,qBAAqB,EACrB,WAAW,EACX,iBAAiB,EACjB,YAAY,EACZ,aAAa,EACb,cAAc,EACd,uBAAuB,EACvB,cAAc,EACd,uBAAuB,GACxB,MAAM,SAAS,CAAC;AAGjB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,YAAY,EAEV,SAAS,EACT,gBAAgB,EAChB,cAAc,EACd,WAAW,EACX,WAAW,EAEX,MAAM,EACN,KAAK,EACL,MAAM,EACN,qBAAqB,EACrB,WAAW,EACX,iBAAiB,EACjB,YAAY,EACZ,aAAa,EACb,cAAc,EACd,uBAAuB,EACvB,cAAc,EACd,uBAAuB,GACxB,MAAM,SAAS,CAAC;AAGjB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAIxD,OAAO,EAAE,KAAK,EAAE,sBAAsB,EAAE,MAAM,QAAQ,CAAC;AAGvD,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAG9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAG9C,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAM3C,wBAAgB,iBAAiB,IAAI,MAAM,CAE1C;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE;IAC3C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,4CAA4C;IAC5C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,SAAS,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;CACjC,GAAG,SAAS,CAsBZ"}
|
package/dist/api/index.js
CHANGED
|
@@ -27,16 +27,15 @@ export function generateRequestId() {
|
|
|
27
27
|
* @returns ApiClient instance
|
|
28
28
|
*/
|
|
29
29
|
export function getOrCreateApiClient(config) {
|
|
30
|
-
const { baseUrl = ZAPIER_BASE_URL,
|
|
30
|
+
const { baseUrl = ZAPIER_BASE_URL, credentials, token, api: providedApi, debug = false, fetch: customFetch, } = config;
|
|
31
31
|
// Use provided API client or create a new one
|
|
32
32
|
if (providedApi) {
|
|
33
33
|
return providedApi;
|
|
34
34
|
}
|
|
35
35
|
return createZapierApi({
|
|
36
36
|
baseUrl,
|
|
37
|
-
|
|
37
|
+
credentials,
|
|
38
38
|
token,
|
|
39
|
-
getToken,
|
|
40
39
|
debug,
|
|
41
40
|
fetch: customFetch,
|
|
42
41
|
});
|
package/dist/api/schemas.d.ts
CHANGED
|
@@ -42,6 +42,7 @@ export declare const NeedSchema: z.ZodObject<{
|
|
|
42
42
|
type: z.ZodOptional<z.ZodEnum<{
|
|
43
43
|
string: "string";
|
|
44
44
|
boolean: "boolean";
|
|
45
|
+
filter: "filter";
|
|
45
46
|
file: "file";
|
|
46
47
|
integer: "integer";
|
|
47
48
|
text: "text";
|
|
@@ -51,7 +52,6 @@ export declare const NeedSchema: z.ZodObject<{
|
|
|
51
52
|
password: "password";
|
|
52
53
|
dict: "dict";
|
|
53
54
|
code: "code";
|
|
54
|
-
filter: "filter";
|
|
55
55
|
json: "json";
|
|
56
56
|
}>>;
|
|
57
57
|
list: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -65,8 +65,8 @@ export declare const ActionPermissionsSchema: z.ZodObject<{
|
|
|
65
65
|
export declare const ActionSchema: z.ZodObject<{
|
|
66
66
|
id: z.ZodOptional<z.ZodString>;
|
|
67
67
|
type: z.ZodEnum<{
|
|
68
|
-
search: "search";
|
|
69
68
|
filter: "filter";
|
|
69
|
+
search: "search";
|
|
70
70
|
read: "read";
|
|
71
71
|
read_bulk: "read_bulk";
|
|
72
72
|
run: "run";
|
|
@@ -286,6 +286,7 @@ export declare const NeedsResponseSchema: z.ZodObject<{
|
|
|
286
286
|
type: z.ZodOptional<z.ZodEnum<{
|
|
287
287
|
string: "string";
|
|
288
288
|
boolean: "boolean";
|
|
289
|
+
filter: "filter";
|
|
289
290
|
file: "file";
|
|
290
291
|
integer: "integer";
|
|
291
292
|
text: "text";
|
|
@@ -295,7 +296,6 @@ export declare const NeedsResponseSchema: z.ZodObject<{
|
|
|
295
296
|
password: "password";
|
|
296
297
|
dict: "dict";
|
|
297
298
|
code: "code";
|
|
298
|
-
filter: "filter";
|
|
299
299
|
json: "json";
|
|
300
300
|
}>>;
|
|
301
301
|
list: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -312,8 +312,8 @@ export declare const ImplementationSchema: z.ZodObject<{
|
|
|
312
312
|
actions: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
313
313
|
id: z.ZodOptional<z.ZodString>;
|
|
314
314
|
type: z.ZodEnum<{
|
|
315
|
-
search: "search";
|
|
316
315
|
filter: "filter";
|
|
316
|
+
search: "search";
|
|
317
317
|
read: "read";
|
|
318
318
|
read_bulk: "read_bulk";
|
|
319
319
|
run: "run";
|
|
@@ -354,8 +354,8 @@ export declare const ImplementationsResponseSchema: z.ZodObject<{
|
|
|
354
354
|
actions: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
355
355
|
id: z.ZodOptional<z.ZodString>;
|
|
356
356
|
type: z.ZodEnum<{
|
|
357
|
-
search: "search";
|
|
358
357
|
filter: "filter";
|
|
358
|
+
search: "search";
|
|
359
359
|
read: "read";
|
|
360
360
|
read_bulk: "read_bulk";
|
|
361
361
|
run: "run";
|
package/dist/api/types.d.ts
CHANGED
|
@@ -11,14 +11,19 @@
|
|
|
11
11
|
import type { AuthenticationSchema, AuthenticationsResponseSchema } from "@zapier/zapier-sdk-core/v0/schemas/authentications";
|
|
12
12
|
import type { ImplementationMetaSchema, ImplementationsMetaResponseSchema } from "@zapier/zapier-sdk-core/v0/schemas/implementations";
|
|
13
13
|
import type { SdkEvent } from "../types/events";
|
|
14
|
+
import type { Credentials } from "../types/credentials";
|
|
14
15
|
import type { z } from "zod";
|
|
15
16
|
import type { NeedChoicesSchema, NeedSchema, ActionLinksSchema, ActionPermissionsSchema, ActionSchema, ChoiceSchema, FieldSchema, ActionExecutionResultSchema, ActionFieldChoiceSchema, ActionFieldSchema, UserProfileSchema, AppSchema, NeedsRequestSchema, NeedsResponseSchema, ImplementationSchema, ImplementationsResponseSchema, ServiceSchema, ServicesResponseSchema, NeedChoicesRequestSchema, NeedChoicesResponseSchema, NeedChoicesResponseMetaSchema, NeedChoicesResponseLinksSchema } from "./schemas";
|
|
16
17
|
export interface ApiClientOptions {
|
|
17
18
|
baseUrl: string;
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Authentication credentials.
|
|
21
|
+
*/
|
|
22
|
+
credentials?: Credentials;
|
|
23
|
+
/**
|
|
24
|
+
* @deprecated Use `credentials` instead.
|
|
25
|
+
*/
|
|
20
26
|
token?: string;
|
|
21
|
-
getToken?: () => Promise<string | undefined>;
|
|
22
27
|
debug?: boolean;
|
|
23
28
|
fetch?: typeof globalThis.fetch;
|
|
24
29
|
onEvent?: (event: SdkEvent) => void;
|
package/dist/api/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/api/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EACV,oBAAoB,EACpB,6BAA6B,EAC9B,MAAM,oDAAoD,CAAC;AAC5D,OAAO,KAAK,EACV,wBAAwB,EACxB,iCAAiC,EAClC,MAAM,oDAAoD,CAAC;AAC5D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,KAAK,EACV,iBAAiB,EACjB,UAAU,EACV,iBAAiB,EACjB,uBAAuB,EACvB,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,2BAA2B,EAC3B,uBAAuB,EACvB,iBAAiB,EACjB,iBAAiB,EACjB,SAAS,EACT,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,6BAA6B,EAC7B,aAAa,EACb,sBAAsB,EACtB,wBAAwB,EACxB,yBAAyB,EACzB,6BAA6B,EAC7B,8BAA8B,EAC/B,MAAM,WAAW,CAAC;AAMnB,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceR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|
* SDK Authentication Utilities
|
|
3
3
|
*
|
|
4
4
|
* This module provides SDK-level authentication utilities focused
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* on token acquisition. It uses the credentials system for resolution
|
|
6
|
+
* and handles different credential types appropriately.
|
|
7
|
+
*
|
|
8
|
+
* CLI-specific functionality like login/logout is handled by the
|
|
9
|
+
* @zapier/zapier-sdk-cli-login package.
|
|
7
10
|
*/
|
|
8
11
|
import type { EventCallback } from "./types/events";
|
|
12
|
+
import type { Credentials } from "./types/credentials";
|
|
9
13
|
export type { SdkEvent, AuthEvent, ApiEvent, LoadingEvent, EventCallback, } from "./types/events";
|
|
10
|
-
export
|
|
14
|
+
export type { Credentials, ResolvedCredentials, CredentialsObject, ClientCredentialsObject, PkceCredentialsObject, } from "./types/credentials";
|
|
15
|
+
export { isClientCredentials, isPkceCredentials, isCredentialsObject, isCredentialsFunction, } from "./types/credentials";
|
|
16
|
+
/**
|
|
17
|
+
* Options for resolving auth tokens.
|
|
18
|
+
*/
|
|
19
|
+
export interface ResolveAuthTokenOptions {
|
|
20
|
+
credentials?: Credentials;
|
|
21
|
+
/** @deprecated Use `credentials` instead */
|
|
22
|
+
token?: string;
|
|
11
23
|
onEvent?: EventCallback;
|
|
12
24
|
fetch?: typeof globalThis.fetch;
|
|
13
25
|
baseUrl?: string;
|
|
14
|
-
authBaseUrl?: string;
|
|
15
|
-
authClientId?: string;
|
|
16
|
-
}
|
|
17
|
-
export interface ResolveAuthTokenOptions extends AuthOptions {
|
|
18
|
-
token?: string;
|
|
19
|
-
getToken?: () => Promise<string | undefined> | string | undefined;
|
|
20
26
|
}
|
|
21
27
|
/**
|
|
22
|
-
*
|
|
23
|
-
|
|
28
|
+
* Clear the token cache. Useful for testing or forcing re-authentication.
|
|
29
|
+
*/
|
|
30
|
+
export declare function clearTokenCache(): void;
|
|
31
|
+
/**
|
|
32
|
+
* Invalidate a cached token. Called when we get a 401 response.
|
|
33
|
+
*/
|
|
34
|
+
export declare function invalidateCachedToken(clientId: string): void;
|
|
35
|
+
/**
|
|
36
|
+
* Options for getTokenFromCliLogin.
|
|
24
37
|
*/
|
|
25
|
-
|
|
38
|
+
interface CliLoginOptions {
|
|
39
|
+
onEvent?: EventCallback;
|
|
40
|
+
fetch?: typeof globalThis.fetch;
|
|
41
|
+
credentials?: {
|
|
42
|
+
type?: "pkce";
|
|
43
|
+
clientId: string;
|
|
44
|
+
baseUrl?: string;
|
|
45
|
+
scope?: string;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
26
48
|
/**
|
|
27
49
|
* Attempts to get a token by optionally importing from CLI login package.
|
|
28
50
|
* This provides a graceful fallback when the CLI login package is not available.
|
|
29
51
|
*
|
|
30
52
|
* Returns undefined if no valid token is found or CLI package is not available.
|
|
31
53
|
*/
|
|
32
|
-
export declare function getTokenFromCliLogin(options
|
|
54
|
+
export declare function getTokenFromCliLogin(options: CliLoginOptions): Promise<string | undefined>;
|
|
33
55
|
/**
|
|
34
|
-
*
|
|
35
|
-
* 1. ZAPIER_TOKEN environment variable
|
|
36
|
-
* 2. CLI login package (if available) with auto-refresh
|
|
56
|
+
* Resolves an auth token from wherever it can be found.
|
|
37
57
|
*
|
|
38
|
-
*
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
58
|
+
* Resolution order:
|
|
59
|
+
* 1. Explicit credentials option (or deprecated token option)
|
|
60
|
+
* 2. Environment variables
|
|
61
|
+
* 3. CLI login package (if available)
|
|
62
|
+
*
|
|
63
|
+
* For different credential types:
|
|
64
|
+
* - String: Used directly as the token
|
|
65
|
+
* - Client credentials: Exchanged for an access token (with caching)
|
|
66
|
+
* - PKCE: Delegates to CLI login (throws if not available)
|
|
47
67
|
*
|
|
48
|
-
* This is the canonical token resolution logic used throughout the SDK.
|
|
49
68
|
* Returns undefined if no valid token is found.
|
|
50
69
|
*/
|
|
51
70
|
export declare function resolveAuthToken(options?: ResolveAuthTokenOptions): Promise<string | undefined>;
|
|
71
|
+
/**
|
|
72
|
+
* Invalidate the cached token for the given credentials, if applicable.
|
|
73
|
+
* This is called when we receive a 401 response, indicating the token
|
|
74
|
+
* is no longer valid. Only affects client_credentials flow tokens.
|
|
75
|
+
*/
|
|
76
|
+
export declare function invalidateCredentialsToken(options: {
|
|
77
|
+
credentials?: Credentials;
|
|
78
|
+
token?: string;
|
|
79
|
+
}): Promise<void>;
|
|
52
80
|
//# 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
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,KAAK,EAAE,WAAW,EAAuB,MAAM,qBAAqB,CAAC;AAM5E,YAAY,EACV,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,YAAY,EACZ,aAAa,GACd,MAAM,gBAAgB,CAAC;AAGxB,YAAY,EACV,WAAW,EACX,mBAAmB,EACnB,iBAAiB,EACjB,uBAAuB,EACvB,qBAAqB,GACtB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,mBAAmB,EACnB,qBAAqB,GACtB,MAAM,qBAAqB,CAAC;AAE7B;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,4CAA4C;IAC5C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,aAAa,CAAC;IACxB,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;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