@zapier/zapier-sdk 0.8.2 → 0.9.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 +12 -0
- package/README.md +10 -33
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.js +1 -2
- package/dist/api/polling.d.ts +36 -6
- package/dist/api/polling.d.ts.map +1 -1
- package/dist/api/polling.js +132 -28
- package/dist/api/polling.test.d.ts +2 -0
- package/dist/api/polling.test.d.ts.map +1 -0
- package/dist/api/polling.test.js +318 -0
- package/dist/api/types.d.ts +1 -2
- package/dist/api/types.d.ts.map +1 -1
- package/dist/index.cjs +489 -252
- package/dist/index.d.mts +182 -187
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/index.mjs +486 -251
- package/dist/plugins/apps/index.d.ts +4 -0
- package/dist/plugins/apps/index.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 +9 -9
- package/dist/plugins/getApp/index.test.js +1 -1
- package/dist/plugins/getAuthentication/index.test.js +1 -1
- 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 +1 -1
- package/dist/plugins/listActions/index.test.js +4 -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 +33 -17
- package/dist/plugins/listApps/index.test.js +22 -2
- 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 +4 -0
- package/dist/plugins/listAuthentications/index.test.js +39 -13
- package/dist/plugins/listAuthentications/schemas.d.ts +3 -0
- package/dist/plugins/listAuthentications/schemas.d.ts.map +1 -1
- package/dist/plugins/listAuthentications/schemas.js +4 -0
- 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/sdk.d.ts +5 -11
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +1 -4
- package/dist/types/plugin.d.ts +1 -0
- package/dist/types/plugin.d.ts.map +1 -1
- package/dist/types/sdk.d.ts +6 -3
- package/dist/types/sdk.d.ts.map +1 -1
- package/dist/utils/domain-utils.d.ts +16 -0
- package/dist/utils/domain-utils.d.ts.map +1 -1
- package/dist/utils/domain-utils.js +46 -27
- 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/package.json +1 -1
- package/src/api/client.ts +5 -4
- package/src/api/polling.test.ts +405 -0
- package/src/api/polling.ts +224 -44
- package/src/api/types.ts +1 -2
- package/src/index.ts +1 -1
- package/src/plugins/apps/index.ts +9 -2
- package/src/plugins/getApp/index.test.ts +1 -1
- package/src/plugins/getApp/index.ts +12 -14
- package/src/plugins/getAuthentication/index.test.ts +1 -1
- package/src/plugins/listActions/index.test.ts +8 -7
- package/src/plugins/listActions/index.ts +3 -3
- package/src/plugins/listApps/index.test.ts +23 -2
- package/src/plugins/listApps/index.ts +46 -25
- package/src/plugins/listAuthentications/index.test.ts +52 -15
- package/src/plugins/listAuthentications/index.ts +7 -2
- package/src/plugins/listAuthentications/schemas.ts +4 -0
- 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/sdk.ts +1 -5
- package/src/types/plugin.ts +3 -0
- package/src/types/sdk.ts +26 -21
- package/src/utils/domain-utils.test.ts +196 -2
- package/src/utils/domain-utils.ts +68 -35
- package/src/utils/file-utils.test.ts +73 -0
- package/src/utils/file-utils.ts +94 -0
- 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,129 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
-
import { lockVersionPlugin } from "./index";
|
|
3
|
-
import { createSdk } from "../../sdk";
|
|
4
|
-
// Mock fs module
|
|
5
|
-
vi.mock("fs", () => ({
|
|
6
|
-
readFileSync: vi.fn(),
|
|
7
|
-
writeFileSync: vi.fn(),
|
|
8
|
-
existsSync: vi.fn(),
|
|
9
|
-
}));
|
|
10
|
-
// Mock path module
|
|
11
|
-
vi.mock("path", () => ({
|
|
12
|
-
resolve: vi.fn((path) => `/resolved/${path}`),
|
|
13
|
-
}));
|
|
14
|
-
import { readFileSync, writeFileSync, existsSync } from "fs";
|
|
15
|
-
import { resolve } from "path";
|
|
16
|
-
import { apiPlugin } from "../api";
|
|
17
|
-
const mockReadFileSync = vi.mocked(readFileSync);
|
|
18
|
-
const mockWriteFileSync = vi.mocked(writeFileSync);
|
|
19
|
-
const mockExistsSync = vi.mocked(existsSync);
|
|
20
|
-
const mockResolve = vi.mocked(resolve);
|
|
21
|
-
describe("lockVersion plugin", () => {
|
|
22
|
-
let mockSdk;
|
|
23
|
-
beforeEach(() => {
|
|
24
|
-
vi.clearAllMocks();
|
|
25
|
-
mockSdk = {
|
|
26
|
-
listApps: vi.fn().mockReturnValue({
|
|
27
|
-
items: vi.fn().mockReturnValue([
|
|
28
|
-
{
|
|
29
|
-
title: "Gmail",
|
|
30
|
-
key: "GmailCLIAPI",
|
|
31
|
-
current_implementation_id: "GmailCLIAPI@2.1.0",
|
|
32
|
-
description: "Email service",
|
|
33
|
-
},
|
|
34
|
-
][Symbol.iterator]()),
|
|
35
|
-
}),
|
|
36
|
-
};
|
|
37
|
-
});
|
|
38
|
-
const listAppsPlugin = () => ({
|
|
39
|
-
listApps: mockSdk.listApps,
|
|
40
|
-
context: {
|
|
41
|
-
meta: {
|
|
42
|
-
listApps: {
|
|
43
|
-
inputSchema: {},
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
});
|
|
48
|
-
function createTestSdk() {
|
|
49
|
-
return createSdk()
|
|
50
|
-
.addPlugin(apiPlugin)
|
|
51
|
-
.addPlugin(listAppsPlugin)
|
|
52
|
-
.addPlugin(lockVersionPlugin);
|
|
53
|
-
}
|
|
54
|
-
describe("version locking", () => {
|
|
55
|
-
it("should extract implementation name and version and write to file", async () => {
|
|
56
|
-
mockExistsSync.mockReturnValue(false);
|
|
57
|
-
mockResolve.mockReturnValue("/resolved/.zapierrc");
|
|
58
|
-
const sdk = createTestSdk();
|
|
59
|
-
const result = await sdk.lockVersion({ appKey: "gmail" });
|
|
60
|
-
expect(result.data.implementationName).toBe("GmailCLIAPI");
|
|
61
|
-
expect(result.data.version).toBe("2.1.0");
|
|
62
|
-
expect(result.data.current_implementation_id).toBe("GmailCLIAPI@2.1.0");
|
|
63
|
-
expect(result.configPath).toBe("/resolved/.zapierrc");
|
|
64
|
-
// Verify file was written
|
|
65
|
-
expect(mockWriteFileSync).toHaveBeenCalledWith("/resolved/.zapierrc", JSON.stringify({
|
|
66
|
-
apps: {
|
|
67
|
-
gmail: {
|
|
68
|
-
implementationName: "GmailCLIAPI",
|
|
69
|
-
version: "2.1.0",
|
|
70
|
-
},
|
|
71
|
-
},
|
|
72
|
-
}, null, 2));
|
|
73
|
-
});
|
|
74
|
-
it("should update existing .zapierrc file", async () => {
|
|
75
|
-
const existingConfig = {
|
|
76
|
-
apps: {
|
|
77
|
-
slack: {
|
|
78
|
-
implementationName: "SlackCLIAPI",
|
|
79
|
-
version: "1.27.1",
|
|
80
|
-
},
|
|
81
|
-
},
|
|
82
|
-
};
|
|
83
|
-
mockExistsSync.mockReturnValue(true);
|
|
84
|
-
mockReadFileSync.mockReturnValue(JSON.stringify(existingConfig));
|
|
85
|
-
mockResolve.mockReturnValue("/resolved/.zapierrc");
|
|
86
|
-
const sdk = createTestSdk();
|
|
87
|
-
const result = await sdk.lockVersion({ appKey: "gmail" });
|
|
88
|
-
expect(mockReadFileSync).toHaveBeenCalledWith("/resolved/.zapierrc", "utf8");
|
|
89
|
-
expect(result.configPath).toBe("/resolved/.zapierrc");
|
|
90
|
-
// Verify file was updated with both apps
|
|
91
|
-
expect(mockWriteFileSync).toHaveBeenCalledWith("/resolved/.zapierrc", JSON.stringify({
|
|
92
|
-
apps: {
|
|
93
|
-
slack: {
|
|
94
|
-
implementationName: "SlackCLIAPI",
|
|
95
|
-
version: "1.27.1",
|
|
96
|
-
},
|
|
97
|
-
gmail: {
|
|
98
|
-
implementationName: "GmailCLIAPI",
|
|
99
|
-
version: "2.1.0",
|
|
100
|
-
},
|
|
101
|
-
},
|
|
102
|
-
}, null, 2));
|
|
103
|
-
});
|
|
104
|
-
it("should handle invalid implementation ID format", async () => {
|
|
105
|
-
mockSdk.listApps = vi.fn().mockReturnValue({
|
|
106
|
-
items: vi.fn().mockReturnValue([
|
|
107
|
-
{
|
|
108
|
-
title: "Invalid App",
|
|
109
|
-
key: "InvalidApp",
|
|
110
|
-
current_implementation_id: "InvalidFormat",
|
|
111
|
-
},
|
|
112
|
-
][Symbol.iterator]()),
|
|
113
|
-
});
|
|
114
|
-
const sdk = createTestSdk();
|
|
115
|
-
await expect(sdk.lockVersion({ appKey: "invalid" })).rejects.toThrow("Invalid implementation ID format: InvalidFormat. Expected format: <implementationName>@<version>");
|
|
116
|
-
});
|
|
117
|
-
it("should use custom config path when provided", async () => {
|
|
118
|
-
mockExistsSync.mockReturnValue(false);
|
|
119
|
-
mockResolve.mockReturnValue("/resolved/custom-config.json");
|
|
120
|
-
const sdk = createTestSdk();
|
|
121
|
-
const result = await sdk.lockVersion({
|
|
122
|
-
appKey: "gmail",
|
|
123
|
-
configPath: "custom-config.json",
|
|
124
|
-
});
|
|
125
|
-
expect(mockResolve).toHaveBeenCalledWith("custom-config.json");
|
|
126
|
-
expect(result.configPath).toBe("/resolved/custom-config.json");
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
});
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
export declare const LockVersionSchema: z.ZodObject<{
|
|
3
|
-
appKey: z.ZodString;
|
|
4
|
-
}, "strip", z.ZodTypeAny, {
|
|
5
|
-
appKey: string;
|
|
6
|
-
}, {
|
|
7
|
-
appKey: string;
|
|
8
|
-
}>;
|
|
9
|
-
export type LockVersionOptions = z.infer<typeof LockVersionSchema>;
|
|
10
|
-
//# sourceMappingURL=schemas.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../src/plugins/lockVersion/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,iBAAiB;;;;;;EAI5B,CAAC;AAEH,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC"}
|
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
-
import { lockVersionPlugin } from "./index";
|
|
3
|
-
import { createSdk } from "../../sdk";
|
|
4
|
-
|
|
5
|
-
// Mock fs module
|
|
6
|
-
vi.mock("fs", () => ({
|
|
7
|
-
readFileSync: vi.fn(),
|
|
8
|
-
writeFileSync: vi.fn(),
|
|
9
|
-
existsSync: vi.fn(),
|
|
10
|
-
}));
|
|
11
|
-
|
|
12
|
-
// Mock path module
|
|
13
|
-
vi.mock("path", () => ({
|
|
14
|
-
resolve: vi.fn((path) => `/resolved/${path}`),
|
|
15
|
-
}));
|
|
16
|
-
|
|
17
|
-
import { readFileSync, writeFileSync, existsSync } from "fs";
|
|
18
|
-
import { resolve } from "path";
|
|
19
|
-
import { apiPlugin } from "../api";
|
|
20
|
-
|
|
21
|
-
const mockReadFileSync = vi.mocked(readFileSync);
|
|
22
|
-
const mockWriteFileSync = vi.mocked(writeFileSync);
|
|
23
|
-
const mockExistsSync = vi.mocked(existsSync);
|
|
24
|
-
const mockResolve = vi.mocked(resolve);
|
|
25
|
-
|
|
26
|
-
describe("lockVersion plugin", () => {
|
|
27
|
-
let mockSdk: any;
|
|
28
|
-
|
|
29
|
-
beforeEach(() => {
|
|
30
|
-
vi.clearAllMocks();
|
|
31
|
-
|
|
32
|
-
mockSdk = {
|
|
33
|
-
listApps: vi.fn().mockReturnValue({
|
|
34
|
-
items: vi.fn().mockReturnValue(
|
|
35
|
-
[
|
|
36
|
-
{
|
|
37
|
-
title: "Gmail",
|
|
38
|
-
key: "GmailCLIAPI",
|
|
39
|
-
current_implementation_id: "GmailCLIAPI@2.1.0",
|
|
40
|
-
description: "Email service",
|
|
41
|
-
},
|
|
42
|
-
][Symbol.iterator](),
|
|
43
|
-
),
|
|
44
|
-
}),
|
|
45
|
-
};
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
const listAppsPlugin = () => ({
|
|
49
|
-
listApps: mockSdk.listApps,
|
|
50
|
-
context: {
|
|
51
|
-
meta: {
|
|
52
|
-
listApps: {
|
|
53
|
-
inputSchema: {} as any,
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
},
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
function createTestSdk() {
|
|
60
|
-
return createSdk()
|
|
61
|
-
.addPlugin(apiPlugin)
|
|
62
|
-
.addPlugin(listAppsPlugin)
|
|
63
|
-
.addPlugin(lockVersionPlugin);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
describe("version locking", () => {
|
|
67
|
-
it("should extract implementation name and version and write to file", async () => {
|
|
68
|
-
mockExistsSync.mockReturnValue(false);
|
|
69
|
-
mockResolve.mockReturnValue("/resolved/.zapierrc");
|
|
70
|
-
|
|
71
|
-
const sdk = createTestSdk();
|
|
72
|
-
const result = await sdk.lockVersion({ appKey: "gmail" });
|
|
73
|
-
|
|
74
|
-
expect((result.data as any).implementationName).toBe("GmailCLIAPI");
|
|
75
|
-
expect((result.data as any).version).toBe("2.1.0");
|
|
76
|
-
expect(result.data.current_implementation_id).toBe("GmailCLIAPI@2.1.0");
|
|
77
|
-
expect(result.configPath).toBe("/resolved/.zapierrc");
|
|
78
|
-
|
|
79
|
-
// Verify file was written
|
|
80
|
-
expect(mockWriteFileSync).toHaveBeenCalledWith(
|
|
81
|
-
"/resolved/.zapierrc",
|
|
82
|
-
JSON.stringify(
|
|
83
|
-
{
|
|
84
|
-
apps: {
|
|
85
|
-
gmail: {
|
|
86
|
-
implementationName: "GmailCLIAPI",
|
|
87
|
-
version: "2.1.0",
|
|
88
|
-
},
|
|
89
|
-
},
|
|
90
|
-
},
|
|
91
|
-
null,
|
|
92
|
-
2,
|
|
93
|
-
),
|
|
94
|
-
);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it("should update existing .zapierrc file", async () => {
|
|
98
|
-
const existingConfig = {
|
|
99
|
-
apps: {
|
|
100
|
-
slack: {
|
|
101
|
-
implementationName: "SlackCLIAPI",
|
|
102
|
-
version: "1.27.1",
|
|
103
|
-
},
|
|
104
|
-
},
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
mockExistsSync.mockReturnValue(true);
|
|
108
|
-
mockReadFileSync.mockReturnValue(JSON.stringify(existingConfig));
|
|
109
|
-
mockResolve.mockReturnValue("/resolved/.zapierrc");
|
|
110
|
-
|
|
111
|
-
const sdk = createTestSdk();
|
|
112
|
-
const result = await sdk.lockVersion({ appKey: "gmail" });
|
|
113
|
-
|
|
114
|
-
expect(mockReadFileSync).toHaveBeenCalledWith(
|
|
115
|
-
"/resolved/.zapierrc",
|
|
116
|
-
"utf8",
|
|
117
|
-
);
|
|
118
|
-
expect(result.configPath).toBe("/resolved/.zapierrc");
|
|
119
|
-
|
|
120
|
-
// Verify file was updated with both apps
|
|
121
|
-
expect(mockWriteFileSync).toHaveBeenCalledWith(
|
|
122
|
-
"/resolved/.zapierrc",
|
|
123
|
-
JSON.stringify(
|
|
124
|
-
{
|
|
125
|
-
apps: {
|
|
126
|
-
slack: {
|
|
127
|
-
implementationName: "SlackCLIAPI",
|
|
128
|
-
version: "1.27.1",
|
|
129
|
-
},
|
|
130
|
-
gmail: {
|
|
131
|
-
implementationName: "GmailCLIAPI",
|
|
132
|
-
version: "2.1.0",
|
|
133
|
-
},
|
|
134
|
-
},
|
|
135
|
-
},
|
|
136
|
-
null,
|
|
137
|
-
2,
|
|
138
|
-
),
|
|
139
|
-
);
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it("should handle invalid implementation ID format", async () => {
|
|
143
|
-
mockSdk.listApps = vi.fn().mockReturnValue({
|
|
144
|
-
items: vi.fn().mockReturnValue(
|
|
145
|
-
[
|
|
146
|
-
{
|
|
147
|
-
title: "Invalid App",
|
|
148
|
-
key: "InvalidApp",
|
|
149
|
-
current_implementation_id: "InvalidFormat",
|
|
150
|
-
},
|
|
151
|
-
][Symbol.iterator](),
|
|
152
|
-
),
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
const sdk = createTestSdk();
|
|
156
|
-
|
|
157
|
-
await expect(sdk.lockVersion({ appKey: "invalid" })).rejects.toThrow(
|
|
158
|
-
"Invalid implementation ID format: InvalidFormat. Expected format: <implementationName>@<version>",
|
|
159
|
-
);
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
it("should use custom config path when provided", async () => {
|
|
163
|
-
mockExistsSync.mockReturnValue(false);
|
|
164
|
-
mockResolve.mockReturnValue("/resolved/custom-config.json");
|
|
165
|
-
|
|
166
|
-
const sdk = createTestSdk();
|
|
167
|
-
const result = await sdk.lockVersion({
|
|
168
|
-
appKey: "gmail",
|
|
169
|
-
configPath: "custom-config.json",
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
expect(mockResolve).toHaveBeenCalledWith("custom-config.json");
|
|
173
|
-
expect(result.configPath).toBe("/resolved/custom-config.json");
|
|
174
|
-
});
|
|
175
|
-
});
|
|
176
|
-
});
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import type { Plugin, GetSdkType } from "../../types/plugin";
|
|
2
|
-
import { createFunction } from "../../utils/function-utils";
|
|
3
|
-
import { LockVersionSchema } from "./schemas";
|
|
4
|
-
import type { LockVersionOptions } from "./schemas";
|
|
5
|
-
import type { AppItem } from "../../types/domain";
|
|
6
|
-
import { readFileSync, writeFileSync, existsSync } from "fs";
|
|
7
|
-
import { resolve } from "path";
|
|
8
|
-
import { z } from "zod";
|
|
9
|
-
import type { ListAppsPluginProvides } from "../listApps";
|
|
10
|
-
|
|
11
|
-
export interface LockVersionPluginProvides {
|
|
12
|
-
lockVersion: (
|
|
13
|
-
options: LockVersionOptions & { configPath?: string },
|
|
14
|
-
) => Promise<{ data: AppItem; configPath: string }>;
|
|
15
|
-
context: {
|
|
16
|
-
meta: {
|
|
17
|
-
lockVersion: {
|
|
18
|
-
inputSchema: typeof LockVersionSchema;
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export const lockVersionPlugin: Plugin<
|
|
25
|
-
GetSdkType<ListAppsPluginProvides>, // requires getApp in SDK
|
|
26
|
-
{}, // requires manifest context
|
|
27
|
-
LockVersionPluginProvides
|
|
28
|
-
> = ({ sdk }) => {
|
|
29
|
-
const lockVersion = createFunction(
|
|
30
|
-
async function lockVersion(
|
|
31
|
-
options: LockVersionOptions & { configPath?: string },
|
|
32
|
-
) {
|
|
33
|
-
const { appKey, configPath = ".zapierrc" } = options;
|
|
34
|
-
const resolvedPath = resolve(configPath);
|
|
35
|
-
|
|
36
|
-
// Get the current app information
|
|
37
|
-
const appsIterator = sdk.listApps({ appKeys: [appKey] }).items();
|
|
38
|
-
const apps = [];
|
|
39
|
-
for await (const app of appsIterator) {
|
|
40
|
-
apps.push(app);
|
|
41
|
-
break; // Only need the first result
|
|
42
|
-
}
|
|
43
|
-
const app = apps[0];
|
|
44
|
-
|
|
45
|
-
// Extract implementation name and version from current_implementation_id
|
|
46
|
-
const currentImplementationId = app.current_implementation_id;
|
|
47
|
-
const [implementationName, version] = currentImplementationId.split("@");
|
|
48
|
-
|
|
49
|
-
if (!implementationName || !version) {
|
|
50
|
-
throw new Error(
|
|
51
|
-
`Invalid implementation ID format: ${currentImplementationId}. Expected format: <implementationName>@<version>`,
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// Read existing config or create new one
|
|
56
|
-
let config: { apps: Record<string, any> } = { apps: {} };
|
|
57
|
-
|
|
58
|
-
if (existsSync(resolvedPath)) {
|
|
59
|
-
try {
|
|
60
|
-
const configContent = readFileSync(resolvedPath, "utf8");
|
|
61
|
-
config = JSON.parse(configContent);
|
|
62
|
-
|
|
63
|
-
// Ensure apps property exists
|
|
64
|
-
if (!config.apps) {
|
|
65
|
-
config.apps = {};
|
|
66
|
-
}
|
|
67
|
-
} catch (error) {
|
|
68
|
-
console.warn(
|
|
69
|
-
`⚠️ Failed to parse existing config file, creating new one: ${error}`,
|
|
70
|
-
);
|
|
71
|
-
config = { apps: {} };
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// Update the apps section
|
|
76
|
-
config.apps[appKey] = {
|
|
77
|
-
implementationName,
|
|
78
|
-
version,
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
// Write the updated config
|
|
82
|
-
writeFileSync(resolvedPath, JSON.stringify(config, null, 2));
|
|
83
|
-
|
|
84
|
-
return {
|
|
85
|
-
data: {
|
|
86
|
-
...app,
|
|
87
|
-
implementationName,
|
|
88
|
-
version,
|
|
89
|
-
},
|
|
90
|
-
configPath: resolvedPath,
|
|
91
|
-
};
|
|
92
|
-
},
|
|
93
|
-
LockVersionSchema.extend({
|
|
94
|
-
configPath: z
|
|
95
|
-
.string()
|
|
96
|
-
.optional()
|
|
97
|
-
.describe("Path to .zapierrc file (defaults to '.zapierrc')"),
|
|
98
|
-
}),
|
|
99
|
-
);
|
|
100
|
-
|
|
101
|
-
return {
|
|
102
|
-
lockVersion,
|
|
103
|
-
context: {
|
|
104
|
-
meta: {
|
|
105
|
-
lockVersion: {
|
|
106
|
-
categories: ["utility"],
|
|
107
|
-
inputSchema: LockVersionSchema,
|
|
108
|
-
},
|
|
109
|
-
},
|
|
110
|
-
},
|
|
111
|
-
};
|
|
112
|
-
};
|