@zapier/zapier-sdk 0.46.0 → 0.47.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 +18 -0
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.js +17 -6
- package/dist/api/types.d.ts +11 -0
- package/dist/api/types.d.ts.map +1 -1
- package/dist/index.cjs +3048 -3629
- package/dist/index.d.mts +6700 -2148
- package/dist/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.mjs +3045 -3630
- package/dist/plugins/api/index.d.ts +22 -10
- package/dist/plugins/api/index.d.ts.map +1 -1
- package/dist/plugins/api/index.js +4 -4
- package/dist/plugins/apps/index.d.ts +108 -7
- package/dist/plugins/apps/index.d.ts.map +1 -1
- package/dist/plugins/apps/index.js +3 -4
- package/dist/plugins/capabilities/index.d.ts +9 -6
- package/dist/plugins/capabilities/index.d.ts.map +1 -1
- package/dist/plugins/capabilities/index.js +3 -2
- package/dist/plugins/connections/index.d.ts +15 -9
- package/dist/plugins/connections/index.d.ts.map +1 -1
- package/dist/plugins/connections/index.js +3 -2
- package/dist/plugins/createClientCredentials/index.d.ts +26 -14
- package/dist/plugins/createClientCredentials/index.d.ts.map +1 -1
- package/dist/plugins/createClientCredentials/index.js +16 -39
- package/dist/plugins/createClientCredentials/schemas.d.ts +0 -2
- package/dist/plugins/createClientCredentials/schemas.d.ts.map +1 -1
- package/dist/plugins/deleteClientCredentials/index.d.ts +20 -14
- package/dist/plugins/deleteClientCredentials/index.d.ts.map +1 -1
- package/dist/plugins/deleteClientCredentials/index.js +18 -37
- package/dist/plugins/deleteClientCredentials/schemas.d.ts +0 -2
- package/dist/plugins/deleteClientCredentials/schemas.d.ts.map +1 -1
- package/dist/plugins/deprecated/authentications.d.ts +597 -41
- package/dist/plugins/deprecated/authentications.d.ts.map +1 -1
- package/dist/plugins/deprecated/authentications.js +9 -8
- package/dist/plugins/eventEmission/index.d.ts +9 -6
- package/dist/plugins/eventEmission/index.d.ts.map +1 -1
- package/dist/plugins/eventEmission/index.js +3 -2
- package/dist/plugins/fetch/index.d.ts +40 -17
- package/dist/plugins/fetch/index.d.ts.map +1 -1
- package/dist/plugins/fetch/index.js +6 -4
- package/dist/plugins/findFirstConnection/index.d.ts +109 -14
- package/dist/plugins/findFirstConnection/index.d.ts.map +1 -1
- package/dist/plugins/findFirstConnection/index.js +14 -26
- package/dist/plugins/findFirstConnection/schemas.d.ts +0 -2
- package/dist/plugins/findFirstConnection/schemas.d.ts.map +1 -1
- package/dist/plugins/findUniqueConnection/index.d.ts +109 -14
- package/dist/plugins/findUniqueConnection/index.d.ts.map +1 -1
- package/dist/plugins/findUniqueConnection/index.js +14 -26
- package/dist/plugins/findUniqueConnection/schemas.d.ts +0 -2
- package/dist/plugins/findUniqueConnection/schemas.d.ts.map +1 -1
- package/dist/plugins/getAction/index.d.ts +68 -15
- package/dist/plugins/getAction/index.d.ts.map +1 -1
- package/dist/plugins/getAction/index.js +21 -31
- package/dist/plugins/getAction/schemas.d.ts +0 -2
- package/dist/plugins/getAction/schemas.d.ts.map +1 -1
- package/dist/plugins/getApp/index.d.ts +140 -14
- package/dist/plugins/getApp/index.d.ts.map +1 -1
- package/dist/plugins/getApp/index.js +16 -38
- package/dist/plugins/getApp/schemas.d.ts +0 -2
- package/dist/plugins/getApp/schemas.d.ts.map +1 -1
- package/dist/plugins/getConnection/index.d.ts +50 -16
- package/dist/plugins/getConnection/index.d.ts.map +1 -1
- package/dist/plugins/getConnection/index.js +22 -29
- package/dist/plugins/getConnection/schemas.d.ts +0 -2
- package/dist/plugins/getConnection/schemas.d.ts.map +1 -1
- package/dist/plugins/getInputFieldsSchema/index.d.ts +59 -13
- package/dist/plugins/getInputFieldsSchema/index.d.ts.map +1 -1
- package/dist/plugins/getInputFieldsSchema/index.js +21 -32
- package/dist/plugins/getInputFieldsSchema/schemas.d.ts +0 -2
- package/dist/plugins/getInputFieldsSchema/schemas.d.ts.map +1 -1
- package/dist/plugins/getProfile/index.d.ts +25 -18
- package/dist/plugins/getProfile/index.d.ts.map +1 -1
- package/dist/plugins/getProfile/index.js +13 -26
- package/dist/plugins/getProfile/schemas.d.ts +0 -8
- package/dist/plugins/getProfile/schemas.d.ts.map +1 -1
- package/dist/plugins/getProfile/schemas.js +0 -1
- package/dist/plugins/listActions/index.d.ts +73 -23
- package/dist/plugins/listActions/index.d.ts.map +1 -1
- package/dist/plugins/listActions/index.js +25 -53
- package/dist/plugins/listActions/schemas.d.ts +0 -11
- package/dist/plugins/listActions/schemas.d.ts.map +1 -1
- package/dist/plugins/listApps/index.d.ts +121 -13
- package/dist/plugins/listApps/index.d.ts.map +1 -1
- package/dist/plugins/listApps/index.js +22 -31
- package/dist/plugins/listApps/schemas.d.ts +0 -2
- package/dist/plugins/listApps/schemas.d.ts.map +1 -1
- package/dist/plugins/listClientCredentials/index.d.ts +29 -16
- package/dist/plugins/listClientCredentials/index.d.ts.map +1 -1
- package/dist/plugins/listClientCredentials/index.js +17 -37
- package/dist/plugins/listClientCredentials/schemas.d.ts +0 -2
- package/dist/plugins/listClientCredentials/schemas.d.ts.map +1 -1
- package/dist/plugins/listConnections/index.d.ts +95 -17
- package/dist/plugins/listConnections/index.d.ts.map +1 -1
- package/dist/plugins/listConnections/index.js +25 -49
- package/dist/plugins/listConnections/schemas.d.ts +0 -2
- package/dist/plugins/listConnections/schemas.d.ts.map +1 -1
- package/dist/plugins/listInputFieldChoices/index.d.ts +77 -22
- package/dist/plugins/listInputFieldChoices/index.d.ts.map +1 -1
- package/dist/plugins/listInputFieldChoices/index.js +27 -50
- package/dist/plugins/listInputFieldChoices/schemas.d.ts +0 -2
- package/dist/plugins/listInputFieldChoices/schemas.d.ts.map +1 -1
- package/dist/plugins/listInputFields/index.d.ts +154 -22
- package/dist/plugins/listInputFields/index.d.ts.map +1 -1
- package/dist/plugins/listInputFields/index.js +28 -41
- package/dist/plugins/listInputFields/schemas.d.ts +0 -2
- package/dist/plugins/listInputFields/schemas.d.ts.map +1 -1
- package/dist/plugins/manifest/index.d.ts +40 -36
- package/dist/plugins/manifest/index.d.ts.map +1 -1
- package/dist/plugins/manifest/index.js +3 -2
- package/dist/plugins/registry/index.d.ts +11 -9
- package/dist/plugins/registry/index.d.ts.map +1 -1
- package/dist/plugins/registry/index.js +3 -2
- package/dist/plugins/request/index.d.ts +61 -15
- package/dist/plugins/request/index.d.ts.map +1 -1
- package/dist/plugins/request/index.js +14 -22
- package/dist/plugins/request/schemas.d.ts +0 -2
- package/dist/plugins/request/schemas.d.ts.map +1 -1
- package/dist/plugins/runAction/index.d.ts +137 -23
- package/dist/plugins/runAction/index.d.ts.map +1 -1
- package/dist/plugins/runAction/index.js +65 -78
- package/dist/plugins/runAction/schemas.d.ts +0 -10
- package/dist/plugins/runAction/schemas.d.ts.map +1 -1
- package/dist/plugins/tables/createTable/index.d.ts +43 -11
- package/dist/plugins/tables/createTable/index.d.ts.map +1 -1
- package/dist/plugins/tables/createTable/index.js +16 -44
- package/dist/plugins/tables/createTable/schemas.d.ts +0 -2
- package/dist/plugins/tables/createTable/schemas.d.ts.map +1 -1
- package/dist/plugins/tables/createTableFields/index.d.ts +54 -11
- package/dist/plugins/tables/createTableFields/index.d.ts.map +1 -1
- package/dist/plugins/tables/createTableFields/index.js +17 -41
- package/dist/plugins/tables/createTableFields/schemas.d.ts +0 -2
- package/dist/plugins/tables/createTableFields/schemas.d.ts.map +1 -1
- package/dist/plugins/tables/createTableRecords/index.d.ts +47 -11
- package/dist/plugins/tables/createTableRecords/index.d.ts.map +1 -1
- package/dist/plugins/tables/createTableRecords/index.js +17 -43
- package/dist/plugins/tables/createTableRecords/schemas.d.ts +0 -2
- package/dist/plugins/tables/createTableRecords/schemas.d.ts.map +1 -1
- package/dist/plugins/tables/deleteTable/index.d.ts +36 -13
- package/dist/plugins/tables/deleteTable/index.d.ts.map +1 -1
- package/dist/plugins/tables/deleteTable/index.js +18 -40
- package/dist/plugins/tables/deleteTable/schemas.d.ts +0 -2
- package/dist/plugins/tables/deleteTable/schemas.d.ts.map +1 -1
- package/dist/plugins/tables/deleteTableFields/index.d.ts +36 -11
- package/dist/plugins/tables/deleteTableFields/index.d.ts.map +1 -1
- package/dist/plugins/tables/deleteTableFields/index.js +17 -39
- package/dist/plugins/tables/deleteTableFields/schemas.d.ts +0 -2
- package/dist/plugins/tables/deleteTableFields/schemas.d.ts.map +1 -1
- package/dist/plugins/tables/deleteTableRecords/index.d.ts +36 -11
- package/dist/plugins/tables/deleteTableRecords/index.d.ts.map +1 -1
- package/dist/plugins/tables/deleteTableRecords/index.js +18 -41
- package/dist/plugins/tables/deleteTableRecords/schemas.d.ts +0 -2
- package/dist/plugins/tables/deleteTableRecords/schemas.d.ts.map +1 -1
- package/dist/plugins/tables/getTable/index.d.ts +43 -12
- package/dist/plugins/tables/getTable/index.d.ts.map +1 -1
- package/dist/plugins/tables/getTable/index.js +18 -43
- package/dist/plugins/tables/getTable/schemas.d.ts +0 -2
- package/dist/plugins/tables/getTable/schemas.d.ts.map +1 -1
- package/dist/plugins/tables/getTableRecord/index.d.ts +43 -11
- package/dist/plugins/tables/getTableRecord/index.d.ts.map +1 -1
- package/dist/plugins/tables/getTableRecord/index.js +18 -42
- package/dist/plugins/tables/getTableRecord/schemas.d.ts +0 -2
- package/dist/plugins/tables/getTableRecord/schemas.d.ts.map +1 -1
- package/dist/plugins/tables/listTableFields/index.d.ts +46 -11
- package/dist/plugins/tables/listTableFields/index.d.ts.map +1 -1
- package/dist/plugins/tables/listTableFields/index.js +17 -41
- package/dist/plugins/tables/listTableFields/schemas.d.ts +0 -2
- package/dist/plugins/tables/listTableFields/schemas.d.ts.map +1 -1
- package/dist/plugins/tables/listTableRecords/index.d.ts +66 -18
- package/dist/plugins/tables/listTableRecords/index.d.ts.map +1 -1
- package/dist/plugins/tables/listTableRecords/index.js +27 -50
- package/dist/plugins/tables/listTableRecords/schemas.d.ts +0 -2
- package/dist/plugins/tables/listTableRecords/schemas.d.ts.map +1 -1
- package/dist/plugins/tables/listTables/index.d.ts +53 -20
- package/dist/plugins/tables/listTables/index.d.ts.map +1 -1
- package/dist/plugins/tables/listTables/index.js +24 -51
- package/dist/plugins/tables/listTables/schemas.d.ts +0 -2
- package/dist/plugins/tables/listTables/schemas.d.ts.map +1 -1
- package/dist/plugins/tables/shared.d.ts +10 -0
- package/dist/plugins/tables/shared.d.ts.map +1 -0
- package/dist/plugins/tables/shared.js +9 -0
- package/dist/plugins/tables/updateTableRecords/index.d.ts +49 -11
- package/dist/plugins/tables/updateTableRecords/index.d.ts.map +1 -1
- package/dist/plugins/tables/updateTableRecords/index.js +20 -43
- package/dist/plugins/tables/updateTableRecords/schemas.d.ts +0 -2
- package/dist/plugins/tables/updateTableRecords/schemas.d.ts.map +1 -1
- package/dist/plugins/tables/utils.d.ts.map +1 -1
- package/dist/plugins/tables/utils.js +1 -0
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +21 -1
- package/dist/resolvers/actionKey.d.ts +1 -2
- package/dist/resolvers/actionKey.d.ts.map +1 -1
- package/dist/resolvers/actionType.d.ts +1 -2
- package/dist/resolvers/actionType.d.ts.map +1 -1
- package/dist/sdk.d.ts +2942 -2
- package/dist/sdk.d.ts.map +1 -1
- package/dist/types/errors.d.ts +13 -10
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/errors.js +15 -12
- package/dist/types/functions.d.ts +18 -2
- package/dist/types/functions.d.ts.map +1 -1
- package/dist/types/plugin.d.ts +1 -1
- package/dist/types/plugin.d.ts.map +1 -1
- package/dist/types/registry.d.ts +1 -1
- package/dist/types/registry.d.ts.map +1 -1
- package/dist/utils/function-utils.d.ts +11 -12
- package/dist/utils/function-utils.d.ts.map +1 -1
- package/dist/utils/plugin-utils.d.ts +243 -0
- package/dist/utils/plugin-utils.d.ts.map +1 -0
- package/dist/utils/plugin-utils.js +232 -0
- package/package.json +2 -1
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ------------------------------
|
|
3
|
+
* Plugin authoring helpers
|
|
4
|
+
* ------------------------------
|
|
5
|
+
*
|
|
6
|
+
* - `definePlugin`: identity wrapper that constrains a plugin's return to
|
|
7
|
+
* `PluginProvides` while preserving the narrow inferred shape, so callers
|
|
8
|
+
* can derive their `*PluginProvides` type via `ReturnType<typeof plugin>`
|
|
9
|
+
* instead of declaring it by hand.
|
|
10
|
+
* - `createPluginMethod` / `createPaginatedPluginMethod`: per-method
|
|
11
|
+
* primitives that sit inside a `definePlugin` callback and build the
|
|
12
|
+
*
|
|
13
|
+
* { [name]: wrappedFn, context: { meta: { [name]: meta } } }
|
|
14
|
+
*
|
|
15
|
+
* fragment a plugin returns for a single method, wiring up
|
|
16
|
+
* `createFunction` / `createPaginatedFunction`, the telemetry callback,
|
|
17
|
+
* and the doubled `name` (function key + meta key) in one place.
|
|
18
|
+
*
|
|
19
|
+
* Two method helpers (rather than one with a `paginated: true` discriminant)
|
|
20
|
+
* because the handler signature changes shape across pagination, and
|
|
21
|
+
* discriminated unions on optional booleans produce noisy TS errors.
|
|
22
|
+
*/
|
|
23
|
+
import { createFunction, createPaginatedFunction } from "./function-utils";
|
|
24
|
+
import { createTelemetryCallback } from "./telemetry-utils";
|
|
25
|
+
/**
|
|
26
|
+
* Identity helper that preserves the narrow inferred return type of a plugin.
|
|
27
|
+
*
|
|
28
|
+
* Wrapping a plugin function with `definePlugin(...)` lets callers derive the
|
|
29
|
+
* plugin's contribution via `ReturnType<typeof plugin>` instead of declaring a
|
|
30
|
+
* matching `*PluginProvides` interface by hand. The constraint
|
|
31
|
+
* `TProvides extends PluginProvides` enforces the structural floor (must
|
|
32
|
+
* return a valid plugin output); beyond that the inferred shape flows through.
|
|
33
|
+
*/
|
|
34
|
+
export function definePlugin(fn) {
|
|
35
|
+
return fn;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Build a telemetry callback only when the SDK actually has eventEmission
|
|
39
|
+
* wired up. Plugin tests sometimes assemble a minimal SDK without the
|
|
40
|
+
* eventEmission plugin; in that case telemetry is silently skipped, matching
|
|
41
|
+
* the legacy `createFunction` behavior of accepting an undefined telemetry
|
|
42
|
+
* arg.
|
|
43
|
+
*/
|
|
44
|
+
function maybeTelemetry(sdk, name) {
|
|
45
|
+
const ctx = sdk.context;
|
|
46
|
+
if (!ctx.eventEmission)
|
|
47
|
+
return undefined;
|
|
48
|
+
return createTelemetryCallback(ctx.eventEmission.emitMethodCalled, name);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Build the method fragment for a non-paginated SDK method. Used inside a
|
|
52
|
+
* `definePlugin(...)` callback:
|
|
53
|
+
*
|
|
54
|
+
* export const getProfilePlugin = definePlugin(
|
|
55
|
+
* (sdk: ApiPluginProvides & EventEmissionProvides) =>
|
|
56
|
+
* createPluginMethod(sdk, {
|
|
57
|
+
* name: "getProfile",
|
|
58
|
+
* categories: ["account"],
|
|
59
|
+
* inputSchema: GetProfileSchema,
|
|
60
|
+
* handler: async ({ sdk }) => { ... },
|
|
61
|
+
* }),
|
|
62
|
+
* );
|
|
63
|
+
*/
|
|
64
|
+
export function createPluginMethod(sdk, config) {
|
|
65
|
+
const { name, inputSchema, handler, ...metaFields } = config;
|
|
66
|
+
// Preserve the method name on the inner function so telemetry and any
|
|
67
|
+
// `function.name`-based diagnostics see the right value.
|
|
68
|
+
const namedHandlers = {
|
|
69
|
+
[name]: async function (options) {
|
|
70
|
+
return handler({ sdk, options });
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
const wrappedFn = createFunction(namedHandlers[name], inputSchema, maybeTelemetry(sdk, name));
|
|
74
|
+
return {
|
|
75
|
+
[name]: wrappedFn,
|
|
76
|
+
context: {
|
|
77
|
+
meta: {
|
|
78
|
+
[name]: {
|
|
79
|
+
...metaFields,
|
|
80
|
+
...(inputSchema ? { inputSchema } : {}),
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Paginated variant of `createPluginMethod`. The handler receives
|
|
88
|
+
* `{ cursor?, pageSize? }` in `options` and returns whatever shape the
|
|
89
|
+
* upstream API gives back, as long as it has a `data: TItem[]` field.
|
|
90
|
+
* Pair JSON:API responses with `extractCursor` to make the cursor
|
|
91
|
+
* extraction visible at the call site:
|
|
92
|
+
*
|
|
93
|
+
* createPaginatedPluginMethod(sdk, {
|
|
94
|
+
* name: "listApps",
|
|
95
|
+
* inputSchema: ListAppsSchema,
|
|
96
|
+
* handler: ({ sdk, options }) =>
|
|
97
|
+
* sdk.context.api.get<ListAppsResponse>("/api/v0/apps", {...}),
|
|
98
|
+
* extractCursor: (response) => extractCursor(response.links),
|
|
99
|
+
* });
|
|
100
|
+
*/
|
|
101
|
+
export function createPaginatedPluginMethod(sdk, config) {
|
|
102
|
+
const { name, inputSchema, handler, extractCursor: extractCursorFn, defaultPageSize, ...metaFields } = config;
|
|
103
|
+
const namedPageHandlers = {
|
|
104
|
+
[name]: async function (options) {
|
|
105
|
+
const response = await handler({ sdk, options });
|
|
106
|
+
if (extractCursorFn) {
|
|
107
|
+
const extracted = extractCursorFn(response);
|
|
108
|
+
// Pass through the original response when the extractor doesn't
|
|
109
|
+
// produce a cursor — that way the runtime in `createPageFunction`
|
|
110
|
+
// can still auto-detect `nextCursor` or JSON:API `links.next` if
|
|
111
|
+
// they're present (e.g. from test mocks that don't go through the
|
|
112
|
+
// real API envelope).
|
|
113
|
+
if (extracted !== undefined) {
|
|
114
|
+
return { data: response.data, nextCursor: extracted };
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return response;
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
const wrappedFn = createPaginatedFunction(namedPageHandlers[name], inputSchema, maybeTelemetry(sdk, name), name, defaultPageSize);
|
|
121
|
+
return {
|
|
122
|
+
[name]: wrappedFn,
|
|
123
|
+
context: {
|
|
124
|
+
meta: {
|
|
125
|
+
[name]: {
|
|
126
|
+
...metaFields,
|
|
127
|
+
...(inputSchema ? { inputSchema } : {}),
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
// ----------------------------------------------------------------------------
|
|
134
|
+
// composePlugins — runtime merge helpers
|
|
135
|
+
// ----------------------------------------------------------------------------
|
|
136
|
+
// Three merge rules, one per shape of key the function deals with. Each is
|
|
137
|
+
// a small, single-purpose helper so the main loop reads top-to-bottom.
|
|
138
|
+
/**
|
|
139
|
+
* Merge root-level keys (the SDK methods a plugin contributes) into the
|
|
140
|
+
* accumulator. Throws on collision: composePlugins is bag-mode, so two
|
|
141
|
+
* sub-plugins registering the same method name is a programmer error.
|
|
142
|
+
*/
|
|
143
|
+
function mergeRootKeysWithCollisionCheck(target, source, seen) {
|
|
144
|
+
for (const key of Object.keys(source)) {
|
|
145
|
+
if (seen.has(key)) {
|
|
146
|
+
throw new Error(`composePlugins: duplicate root key "${key}". Plugins composed in the same call must register distinct method names.`);
|
|
147
|
+
}
|
|
148
|
+
seen.add(key);
|
|
149
|
+
target[key] = source[key];
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Merge per-method metadata (the registry view of input/output schemas,
|
|
154
|
+
* categories, etc.) with the same collision rule as root keys. Even when
|
|
155
|
+
* two sub-plugins' root method keys differ, registry-level shadowing
|
|
156
|
+
* is dangerous, so silent overwrites aren't allowed.
|
|
157
|
+
*/
|
|
158
|
+
function mergeMetaKeysWithCollisionCheck(target, source, seen) {
|
|
159
|
+
for (const key of Object.keys(source)) {
|
|
160
|
+
if (seen.has(key)) {
|
|
161
|
+
throw new Error(`composePlugins: duplicate context.meta key "${key}". Two sub-plugins registered metadata for the same name.`);
|
|
162
|
+
}
|
|
163
|
+
seen.add(key);
|
|
164
|
+
target[key] = source[key];
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Merge non-meta context keys (everything under `context.*` that isn't
|
|
169
|
+
* `meta`) into the accumulator. Throws on collision — bag mode says
|
|
170
|
+
* sub-plugins shouldn't be re-providing shared infrastructure like
|
|
171
|
+
* `context.api`, so two of them claiming the same context slot is a
|
|
172
|
+
* programmer error. Note that this only applies *inside* a single
|
|
173
|
+
* `composePlugins(...)` call; cross-`addPlugin` overrides go through
|
|
174
|
+
* `addPlugin`'s last-write-wins merge, which is unaffected by this check.
|
|
175
|
+
*/
|
|
176
|
+
function mergeContextKeysWithCollisionCheck(target, source, seen) {
|
|
177
|
+
for (const key of Object.keys(source)) {
|
|
178
|
+
if (seen.has(key)) {
|
|
179
|
+
throw new Error(`composePlugins: duplicate context key "${key}". Two sub-plugins contributed the same context.${key} field.`);
|
|
180
|
+
}
|
|
181
|
+
seen.add(key);
|
|
182
|
+
target[key] = source[key];
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Bundle N plugins into a single plugin so a consumer can call
|
|
187
|
+
* `addPlugin(combined)` once. Use this when an extension package wants to
|
|
188
|
+
* expose granular sub-plugins for tree-shaking *and* a one-call convenience
|
|
189
|
+
* entry point.
|
|
190
|
+
*
|
|
191
|
+
* Three commitments (per the boilerplate-reduction design):
|
|
192
|
+
* 1. **Bag mode.** Sub-plugins must not depend on each other; order is
|
|
193
|
+
* irrelevant. If you need pipeline composition (later sub-plugins
|
|
194
|
+
* reading earlier sub-plugins' outputs), use a regular `definePlugin`
|
|
195
|
+
* callback that calls each `createPluginMethod` in turn.
|
|
196
|
+
* 2. **Over-approximation of TSdk.** The composed plugin requires the
|
|
197
|
+
* intersection of every sub-plugin's requirements (all of them, all at
|
|
198
|
+
* once). Works fine for homogeneous-deps groups; widens slightly for
|
|
199
|
+
* heterogeneous ones, which keeps the variadic types tractable.
|
|
200
|
+
* 3. **Collision detection.** Throws on duplicate root keys, duplicate
|
|
201
|
+
* `context.meta` keys, and duplicate non-meta `context.*` keys. Note
|
|
202
|
+
* this only applies *inside* a single `composePlugins(...)` call —
|
|
203
|
+
* cross-`addPlugin` overrides (e.g. a CLI plugin overriding meta from
|
|
204
|
+
* a core SDK plugin) still go through `addPlugin`'s last-write-wins
|
|
205
|
+
* merge unchanged.
|
|
206
|
+
*
|
|
207
|
+
* Why prefer this over an `addPlugin([...])` array overload: TypeScript's
|
|
208
|
+
* overload resolution interacts badly with arrays carrying a mix of
|
|
209
|
+
* `TProvides` shapes — chained inference downstream of `addPlugin([...])`
|
|
210
|
+
* tends to widen and lose individual method types. A single composed
|
|
211
|
+
* plugin flows through the existing single-plugin `addPlugin` cleanly.
|
|
212
|
+
*/
|
|
213
|
+
export function composePlugins(...plugins) {
|
|
214
|
+
return ((sdk) => {
|
|
215
|
+
const merged = { context: { meta: {} } };
|
|
216
|
+
const seenRoot = new Set();
|
|
217
|
+
const seenMeta = new Set();
|
|
218
|
+
const seenContext = new Set();
|
|
219
|
+
for (const plugin of plugins) {
|
|
220
|
+
const { context, ...rootKeys } = plugin(sdk);
|
|
221
|
+
mergeRootKeysWithCollisionCheck(merged, rootKeys, seenRoot);
|
|
222
|
+
if (context) {
|
|
223
|
+
const { meta, ...nonMetaContext } = context;
|
|
224
|
+
if (meta) {
|
|
225
|
+
mergeMetaKeysWithCollisionCheck(merged.context.meta, meta, seenMeta);
|
|
226
|
+
}
|
|
227
|
+
mergeContextKeysWithCollisionCheck(merged.context, nonMetaContext, seenContext);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return merged;
|
|
231
|
+
});
|
|
232
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zapier/zapier-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.47.0",
|
|
4
4
|
"description": "Complete Zapier SDK - combines all Zapier SDK packages",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -68,6 +68,7 @@
|
|
|
68
68
|
"url": "https://gitlab.com/zapier/zapier-sdk/zapier-sdk.git",
|
|
69
69
|
"directory": "packages/zapier-sdk"
|
|
70
70
|
},
|
|
71
|
+
"homepage": "https://docs.zapier.com/sdk",
|
|
71
72
|
"publishConfig": {
|
|
72
73
|
"access": "public"
|
|
73
74
|
},
|