@zapier/zapier-sdk 0.5.1 → 0.5.2
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 +8 -0
- package/dist/api/index.d.ts +1 -1
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/schemas.d.ts +6 -6
- package/dist/api/types.d.ts +7 -7
- package/dist/api/types.d.ts.map +1 -1
- package/dist/index.cjs +23 -17
- package/dist/index.d.mts +8 -8
- package/dist/index.mjs +23 -17
- package/dist/plugins/apps/types.d.ts +1 -1
- package/dist/plugins/apps/types.d.ts.map +1 -1
- package/dist/plugins/listActions/index.d.ts.map +1 -1
- package/dist/plugins/runAction/index.d.ts.map +1 -1
- package/dist/schemas/Auth.d.ts +4 -4
- package/dist/schemas/Field.d.ts.map +1 -1
- package/dist/types/errors.d.ts +6 -6
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/events.d.ts +1 -1
- package/dist/types/events.d.ts.map +1 -1
- package/dist/utils/validation.test.js +2 -1
- package/package.json +2 -2
- package/src/api/client.ts +3 -3
- package/src/api/index.ts +2 -0
- package/src/api/types.ts +15 -7
- package/src/plugins/apps/types.ts +1 -1
- package/src/plugins/listActions/index.ts +21 -18
- package/src/plugins/runAction/index.ts +5 -2
- package/src/schemas/Field.ts +5 -2
- package/src/types/errors.ts +9 -6
- package/src/types/events.ts +1 -1
- package/src/utils/validation.test.ts +2 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -10,7 +10,7 @@ interface AppFactoryOptions {
|
|
|
10
10
|
|
|
11
11
|
// Base action type proxy for regular actions
|
|
12
12
|
interface BaseActionTypeProxy {
|
|
13
|
-
[action: string]: (options?: ActionExecutionOptions) =>
|
|
13
|
+
[action: string]: (options?: ActionExecutionOptions) => unknown;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
// Special fetch function type
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Plugin, GetSdkType } from "../../types/plugin";
|
|
2
|
-
import type { ApiClient } from "../../api";
|
|
2
|
+
import type { ApiClient, Implementation } from "../../api";
|
|
3
3
|
import type { ActionItem } from "../../types/domain";
|
|
4
4
|
import { normalizeActionItem } from "../../utils/domain-utils";
|
|
5
5
|
import {
|
|
@@ -57,24 +57,27 @@ export const listActionsPlugin: Plugin<
|
|
|
57
57
|
selected_apis: implementationId,
|
|
58
58
|
};
|
|
59
59
|
|
|
60
|
-
const data = await api.get(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
60
|
+
const data = await api.get<{ results: Implementation[] }>(
|
|
61
|
+
"/api/v4/implementations/",
|
|
62
|
+
{
|
|
63
|
+
searchParams,
|
|
64
|
+
customErrorHandler: ({ status }) => {
|
|
65
|
+
if (status === 401) {
|
|
66
|
+
return new ZapierAuthenticationError(
|
|
67
|
+
`Authentication failed. Your token may not have permission to access implementations or may be expired. (HTTP ${status})`,
|
|
68
|
+
{ statusCode: status },
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
if (status === 403) {
|
|
72
|
+
return new ZapierAuthenticationError(
|
|
73
|
+
`Access forbidden. Your token may not have the required scopes to list implementations. (HTTP ${status})`,
|
|
74
|
+
{ statusCode: status },
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
return undefined;
|
|
78
|
+
},
|
|
76
79
|
},
|
|
77
|
-
|
|
80
|
+
);
|
|
78
81
|
|
|
79
82
|
let allActions: ActionItem[] = [];
|
|
80
83
|
|
|
@@ -87,14 +87,17 @@ async function executeAction(actionOptions: ExecuteActionOptions): Promise<{
|
|
|
87
87
|
data: runRequestData,
|
|
88
88
|
};
|
|
89
89
|
|
|
90
|
-
const runData = await api.post(
|
|
90
|
+
const runData = await api.post<{ data: { id: string } }>(
|
|
91
|
+
"/api/actions/v1/runs",
|
|
92
|
+
runRequest,
|
|
93
|
+
);
|
|
91
94
|
const runId = runData.data.id;
|
|
92
95
|
|
|
93
96
|
// Step 2: Poll GET /actions/v1/runs/{run_id} for results
|
|
94
97
|
return await api.poll(`/api/actions/v1/runs/${runId}`, {
|
|
95
98
|
successStatus: 200,
|
|
96
99
|
pendingStatus: 202,
|
|
97
|
-
resultExtractor: (result: { data: unknown })
|
|
100
|
+
resultExtractor: (result: unknown) => (result as { data: unknown }).data,
|
|
98
101
|
});
|
|
99
102
|
}
|
|
100
103
|
|
package/src/schemas/Field.ts
CHANGED
|
@@ -65,10 +65,13 @@ export const InputFieldItemSchema = withFormatter(
|
|
|
65
65
|
if (item.choices && item.choices.length > 0) {
|
|
66
66
|
const choiceText =
|
|
67
67
|
item.choices.length <= 3
|
|
68
|
-
? `Choices: ${item.choices.map((c:
|
|
68
|
+
? `Choices: ${item.choices.map((c: { label?: string; value: string | number }) => c.label || c.value).join(", ")}`
|
|
69
69
|
: `Choices: ${item.choices
|
|
70
70
|
.slice(0, 3)
|
|
71
|
-
.map(
|
|
71
|
+
.map(
|
|
72
|
+
(c: { label?: string; value: string | number }) =>
|
|
73
|
+
c.label || c.value,
|
|
74
|
+
)
|
|
72
75
|
.join(", ")} (+${item.choices.length - 3} more)`;
|
|
73
76
|
details.push({ text: choiceText, style: "accent" as const });
|
|
74
77
|
}
|
package/src/types/errors.ts
CHANGED
|
@@ -6,8 +6,8 @@ export interface ApiError {
|
|
|
6
6
|
code: string;
|
|
7
7
|
title: string;
|
|
8
8
|
detail: string;
|
|
9
|
-
source?:
|
|
10
|
-
meta?:
|
|
9
|
+
source?: unknown;
|
|
10
|
+
meta?: unknown;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
/**
|
|
@@ -17,7 +17,7 @@ export interface ErrorOptions {
|
|
|
17
17
|
statusCode?: number;
|
|
18
18
|
errors?: ApiError[];
|
|
19
19
|
cause?: unknown;
|
|
20
|
-
response?:
|
|
20
|
+
response?: unknown;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
/**
|
|
@@ -29,7 +29,7 @@ export abstract class ZapierError extends Error {
|
|
|
29
29
|
public statusCode?: number;
|
|
30
30
|
public errors?: ApiError[];
|
|
31
31
|
public cause?: unknown;
|
|
32
|
-
public response?:
|
|
32
|
+
public response?: unknown;
|
|
33
33
|
|
|
34
34
|
constructor(message: string, options: ErrorOptions = {}) {
|
|
35
35
|
super(message);
|
|
@@ -74,9 +74,12 @@ export class ZapierAppNotFoundError extends ZapierError {
|
|
|
74
74
|
*/
|
|
75
75
|
export class ZapierValidationError extends ZapierError {
|
|
76
76
|
readonly name = "ZapierValidationError";
|
|
77
|
-
public details?:
|
|
77
|
+
public details?: unknown;
|
|
78
78
|
|
|
79
|
-
constructor(
|
|
79
|
+
constructor(
|
|
80
|
+
message: string,
|
|
81
|
+
options: ErrorOptions & { details?: unknown } = {},
|
|
82
|
+
) {
|
|
80
83
|
super(message, options);
|
|
81
84
|
this.details = options.details;
|
|
82
85
|
}
|
package/src/types/events.ts
CHANGED
|
@@ -42,7 +42,8 @@ describe("validation utilities", () => {
|
|
|
42
42
|
expect((error as ZapierValidationError).message).toContain("name:");
|
|
43
43
|
expect((error as ZapierValidationError).message).toContain("age:");
|
|
44
44
|
expect(
|
|
45
|
-
(error as ZapierValidationError).details
|
|
45
|
+
((error as ZapierValidationError).details as { zodErrors: unknown })
|
|
46
|
+
?.zodErrors,
|
|
46
47
|
).toBeDefined();
|
|
47
48
|
}
|
|
48
49
|
});
|