@zapier/zapier-sdk 0.13.9 → 0.15.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 +13 -0
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.js +45 -22
- package/dist/index.cjs +210 -123
- package/dist/index.mjs +210 -123
- package/dist/plugins/getAuthentication/index.js +1 -1
- package/dist/plugins/getAuthentication/index.test.js +1 -1
- package/dist/plugins/getProfile/index.d.ts.map +1 -1
- package/dist/plugins/getProfile/index.js +1 -1
- package/dist/plugins/listActions/index.js +1 -1
- package/dist/plugins/listActions/index.test.js +1 -1
- package/dist/plugins/listApps/index.js +2 -2
- package/dist/plugins/listApps/index.test.js +1 -1
- package/dist/plugins/listAuthentications/index.js +1 -1
- package/dist/plugins/listAuthentications/index.test.js +13 -13
- package/dist/plugins/listInputFieldChoices/index.d.ts +3 -1
- package/dist/plugins/listInputFieldChoices/index.d.ts.map +1 -1
- package/dist/plugins/listInputFieldChoices/index.js +42 -21
- package/dist/plugins/listInputFieldChoices/index.test.js +188 -11
- package/dist/plugins/listInputFields/index.d.ts.map +1 -1
- package/dist/plugins/listInputFields/index.js +11 -16
- package/dist/plugins/listInputFields/index.test.js +8 -6
- package/dist/plugins/manifest/index.js +2 -2
- package/dist/plugins/manifest/index.test.js +3 -3
- package/dist/plugins/runAction/index.js +2 -2
- package/dist/plugins/runAction/index.test.js +4 -4
- package/dist/sdk.test.js +1 -1
- package/dist/services/implementations.d.ts +63 -0
- package/dist/services/implementations.d.ts.map +1 -0
- package/dist/services/implementations.js +79 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @zapier/zapier-sdk
|
|
2
2
|
|
|
3
|
+
## 0.15.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- f92bc07: Route all API requests through new service.
|
|
8
|
+
|
|
9
|
+
## 0.14.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- 3f2f104: - Introduce a `services` layer for reusability between plugins
|
|
14
|
+
- `listInputFieldChoices` now supports returning static choices if they exist
|
|
15
|
+
|
|
3
16
|
## 0.13.9
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
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;AAwejB,eAAO,MAAM,eAAe,GAAI,SAAS,gBAAgB,KAAG,SAW3D,CAAC"}
|
package/dist/api/client.js
CHANGED
|
@@ -8,11 +8,18 @@ import { getAuthorizationHeader } from "./auth";
|
|
|
8
8
|
import { createDebugLogger, createDebugFetch } from "./debug";
|
|
9
9
|
import { pollUntilComplete } from "./polling";
|
|
10
10
|
import { getTokenFromEnvOrConfig } from "../auth";
|
|
11
|
+
import { getZapierBaseUrl } from "../utils/url-utils";
|
|
11
12
|
import { ZapierApiError, ZapierAuthenticationError, ZapierValidationError, ZapierNotFoundError, } from "../types/errors";
|
|
12
|
-
const
|
|
13
|
-
// e.g. https://
|
|
14
|
-
relay: {
|
|
13
|
+
const pathConfig = {
|
|
14
|
+
// e.g. /relay -> https://sdkapi.zapier.com/api/v0/sdk/relay/...
|
|
15
|
+
"/relay": {
|
|
15
16
|
authHeader: "X-Relay-Authorization",
|
|
17
|
+
pathPrefix: "/api/v0/sdk/relay",
|
|
18
|
+
},
|
|
19
|
+
// e.g. /zapier -> https://sdkapi.zapier.com/api/v0/sdk/zapier/...
|
|
20
|
+
"/zapier": {
|
|
21
|
+
authHeader: "Authorization",
|
|
22
|
+
pathPrefix: "/api/v0/sdk/zapier",
|
|
16
23
|
},
|
|
17
24
|
};
|
|
18
25
|
class ZapierApiClient {
|
|
@@ -223,37 +230,53 @@ class ZapierApiClient {
|
|
|
223
230
|
return { message: fallbackMessage };
|
|
224
231
|
}
|
|
225
232
|
}
|
|
226
|
-
//
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
const
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
233
|
+
// Apply any special routing logic for configured paths.
|
|
234
|
+
applyPathConfiguration(path) {
|
|
235
|
+
// Find matching path configuration.
|
|
236
|
+
const matchingPathKey = Object.keys(pathConfig).find((configPath) => path === configPath || path.startsWith(configPath + "/"));
|
|
237
|
+
const config = matchingPathKey ? pathConfig[matchingPathKey] : undefined;
|
|
238
|
+
// Check if baseUrl is a Zapier-inferred base URL.
|
|
239
|
+
const zapierBaseUrl = getZapierBaseUrl(this.options.baseUrl);
|
|
240
|
+
// Let's remain compatible with a base URL that is set to a Zapier-inferred
|
|
241
|
+
// domain, rather than requiring the base URL to go to our proxy. Later, the
|
|
242
|
+
// proxy will be removed, so this should make that transition easier.
|
|
243
|
+
if (zapierBaseUrl === this.options.baseUrl) {
|
|
244
|
+
// If baseUrl is already the Zapier base URL, use sdkapi subdomain.
|
|
235
245
|
const originalBaseUrl = new URL(this.options.baseUrl);
|
|
236
|
-
const finalBaseUrl = `https
|
|
237
|
-
|
|
238
|
-
|
|
246
|
+
const finalBaseUrl = `https://sdkapi.${originalBaseUrl.hostname}`;
|
|
247
|
+
// Only prepend pathPrefix if there's a matching config with pathPrefix.
|
|
248
|
+
let finalPath = path;
|
|
249
|
+
if (config &&
|
|
250
|
+
"pathPrefix" in config &&
|
|
251
|
+
config.pathPrefix &&
|
|
252
|
+
matchingPathKey) {
|
|
253
|
+
// Strip the matching path key, and use the pathPrefix instead.
|
|
254
|
+
const pathWithoutPrefix = path.slice(matchingPathKey.length) || "/";
|
|
255
|
+
finalPath = `${config.pathPrefix}${pathWithoutPrefix}`;
|
|
256
|
+
}
|
|
257
|
+
return {
|
|
258
|
+
url: new URL(finalPath, finalBaseUrl),
|
|
259
|
+
pathConfig: config,
|
|
260
|
+
};
|
|
239
261
|
}
|
|
262
|
+
// For a base URL that isn't a Zapier-inferred domain, use the whole base URL.
|
|
240
263
|
return {
|
|
241
264
|
url: new URL(path, this.options.baseUrl),
|
|
242
|
-
|
|
265
|
+
pathConfig: config,
|
|
243
266
|
};
|
|
244
267
|
}
|
|
245
268
|
// Helper to build full URLs and return routing info
|
|
246
269
|
buildUrl(path, searchParams) {
|
|
247
|
-
const { url,
|
|
270
|
+
const { url, pathConfig: config } = this.applyPathConfiguration(path);
|
|
248
271
|
if (searchParams) {
|
|
249
272
|
Object.entries(searchParams).forEach(([key, value]) => {
|
|
250
273
|
url.searchParams.set(key, value);
|
|
251
274
|
});
|
|
252
275
|
}
|
|
253
|
-
return { url: url.toString(),
|
|
276
|
+
return { url: url.toString(), pathConfig: config };
|
|
254
277
|
}
|
|
255
278
|
// Helper to build headers
|
|
256
|
-
async buildHeaders(options = {},
|
|
279
|
+
async buildHeaders(options = {}, pathConfig) {
|
|
257
280
|
const headers = new Headers(options.headers ?? {});
|
|
258
281
|
// Even if auth is not required, we still want to add it in case it adds
|
|
259
282
|
// useful context to the API. The session is a good example of this. Auth
|
|
@@ -261,7 +284,7 @@ class ZapierApiClient {
|
|
|
261
284
|
// session!
|
|
262
285
|
const authToken = await this.getAuthToken();
|
|
263
286
|
if (authToken) {
|
|
264
|
-
const authHeaderName =
|
|
287
|
+
const authHeaderName = pathConfig?.authHeader || "Authorization";
|
|
265
288
|
headers.set(authHeaderName, getAuthorizationHeader(authToken));
|
|
266
289
|
}
|
|
267
290
|
// If we know auth is required, and we don't have a token, throw an error
|
|
@@ -307,8 +330,8 @@ class ZapierApiClient {
|
|
|
307
330
|
if (fetchOptions?.body && typeof fetchOptions.body === "object") {
|
|
308
331
|
fetchOptions.body = JSON.stringify(fetchOptions.body);
|
|
309
332
|
}
|
|
310
|
-
const { url,
|
|
311
|
-
const builtHeaders = await this.buildHeaders(fetchOptions,
|
|
333
|
+
const { url, pathConfig } = this.buildUrl(path, fetchOptions?.searchParams);
|
|
334
|
+
const builtHeaders = await this.buildHeaders(fetchOptions, pathConfig);
|
|
312
335
|
const inputHeaders = new Headers(fetchOptions?.headers ?? {});
|
|
313
336
|
const mergedHeaders = new Headers();
|
|
314
337
|
builtHeaders.forEach((value, key) => {
|
package/dist/index.cjs
CHANGED
|
@@ -1295,7 +1295,7 @@ var listAppsPlugin = ({ context }) => {
|
|
|
1295
1295
|
const searchParams2 = {};
|
|
1296
1296
|
searchParams2.term = options.search;
|
|
1297
1297
|
const searchEnvelope = await api.get(
|
|
1298
|
-
"/api/v4/implementations-meta/search/",
|
|
1298
|
+
"/zapier/api/v4/implementations-meta/search/",
|
|
1299
1299
|
{
|
|
1300
1300
|
searchParams: searchParams2
|
|
1301
1301
|
}
|
|
@@ -1335,7 +1335,7 @@ var listAppsPlugin = ({ context }) => {
|
|
|
1335
1335
|
};
|
|
1336
1336
|
}
|
|
1337
1337
|
const implementationsEnvelope = await api.get(
|
|
1338
|
-
"/api/v4/implementations-meta/lookup/",
|
|
1338
|
+
"/zapier/api/v4/implementations-meta/lookup/",
|
|
1339
1339
|
{
|
|
1340
1340
|
searchParams
|
|
1341
1341
|
}
|
|
@@ -1621,7 +1621,7 @@ var listActionsPlugin = ({ context }) => {
|
|
|
1621
1621
|
selected_apis: selectedApi
|
|
1622
1622
|
};
|
|
1623
1623
|
const data = await api.get(
|
|
1624
|
-
"/api/v4/implementations/",
|
|
1624
|
+
"/zapier/api/v4/implementations/",
|
|
1625
1625
|
{
|
|
1626
1626
|
searchParams,
|
|
1627
1627
|
customErrorHandler: ({ status }) => {
|
|
@@ -1812,6 +1812,64 @@ var RootFieldItemSchema = zod.z.union([
|
|
|
1812
1812
|
FieldsetItemSchema
|
|
1813
1813
|
]);
|
|
1814
1814
|
|
|
1815
|
+
// src/services/implementations.ts
|
|
1816
|
+
async function fetchImplementationNeeds({
|
|
1817
|
+
api,
|
|
1818
|
+
selectedApi,
|
|
1819
|
+
action,
|
|
1820
|
+
actionType,
|
|
1821
|
+
authenticationId,
|
|
1822
|
+
inputs
|
|
1823
|
+
}) {
|
|
1824
|
+
const request = {
|
|
1825
|
+
selected_api: selectedApi,
|
|
1826
|
+
action,
|
|
1827
|
+
type_of: actionType,
|
|
1828
|
+
params: inputs || {}
|
|
1829
|
+
};
|
|
1830
|
+
if (authenticationId !== null) {
|
|
1831
|
+
request.authentication_id = authenticationId;
|
|
1832
|
+
}
|
|
1833
|
+
const response = await api.post(
|
|
1834
|
+
"/zapier/api/v4/implementations/needs/",
|
|
1835
|
+
request
|
|
1836
|
+
);
|
|
1837
|
+
if (!response.success) {
|
|
1838
|
+
throw new ZapierApiError(
|
|
1839
|
+
`Failed to get input fields: ${response.errors?.join(", ") || "Unknown error"}`
|
|
1840
|
+
);
|
|
1841
|
+
}
|
|
1842
|
+
return response;
|
|
1843
|
+
}
|
|
1844
|
+
async function fetchImplementationChoices({
|
|
1845
|
+
api,
|
|
1846
|
+
actionId,
|
|
1847
|
+
inputFieldId,
|
|
1848
|
+
authenticationId,
|
|
1849
|
+
inputs,
|
|
1850
|
+
page
|
|
1851
|
+
}) {
|
|
1852
|
+
const request = {
|
|
1853
|
+
action_id: actionId,
|
|
1854
|
+
input_field_id: inputFieldId,
|
|
1855
|
+
page,
|
|
1856
|
+
params: inputs || {}
|
|
1857
|
+
};
|
|
1858
|
+
if (authenticationId !== null) {
|
|
1859
|
+
request.authentication_id = authenticationId;
|
|
1860
|
+
}
|
|
1861
|
+
const response = await api.post(
|
|
1862
|
+
"/zapier/api/v4/implementations/choices/",
|
|
1863
|
+
request
|
|
1864
|
+
);
|
|
1865
|
+
if (!response.success) {
|
|
1866
|
+
throw new ZapierApiError(
|
|
1867
|
+
`Failed to get input field choices: ${response.errors?.join(", ") || "Unknown error"}`
|
|
1868
|
+
);
|
|
1869
|
+
}
|
|
1870
|
+
return response;
|
|
1871
|
+
}
|
|
1872
|
+
|
|
1815
1873
|
// src/plugins/listInputFields/index.ts
|
|
1816
1874
|
function getInputFieldTypeFromNeed(need) {
|
|
1817
1875
|
if (need.list) {
|
|
@@ -1915,7 +1973,13 @@ var listInputFieldsPlugin = ({ sdk, context }) => {
|
|
|
1915
1973
|
const listInputFields = createPaginatedFunction(
|
|
1916
1974
|
async function listInputFieldsPage(options) {
|
|
1917
1975
|
const { api, getVersionedImplementationId } = context;
|
|
1918
|
-
const {
|
|
1976
|
+
const {
|
|
1977
|
+
appKey,
|
|
1978
|
+
actionKey,
|
|
1979
|
+
actionType,
|
|
1980
|
+
authenticationId = null,
|
|
1981
|
+
inputs
|
|
1982
|
+
} = options;
|
|
1919
1983
|
const selectedApi = await getVersionedImplementationId(appKey);
|
|
1920
1984
|
if (!selectedApi) {
|
|
1921
1985
|
throw new ZapierConfigurationError(
|
|
@@ -1928,24 +1992,14 @@ var listInputFieldsPlugin = ({ sdk, context }) => {
|
|
|
1928
1992
|
actionType,
|
|
1929
1993
|
actionKey
|
|
1930
1994
|
});
|
|
1931
|
-
const
|
|
1932
|
-
|
|
1995
|
+
const needsData = await fetchImplementationNeeds({
|
|
1996
|
+
api,
|
|
1997
|
+
selectedApi,
|
|
1933
1998
|
action: action.key,
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
needsRequest.authentication_id = authenticationId;
|
|
1939
|
-
}
|
|
1940
|
-
const needsData = await api.post(
|
|
1941
|
-
"/api/v4/implementations/needs/",
|
|
1942
|
-
needsRequest
|
|
1943
|
-
);
|
|
1944
|
-
if (!needsData.success) {
|
|
1945
|
-
throw new ZapierApiError(
|
|
1946
|
-
`Failed to get action fields: ${needsData.errors?.join(", ") || "Unknown error"}`
|
|
1947
|
-
);
|
|
1948
|
-
}
|
|
1999
|
+
actionType,
|
|
2000
|
+
authenticationId,
|
|
2001
|
+
inputs
|
|
2002
|
+
});
|
|
1949
2003
|
const rootFieldset = transformNeedsToFields(needsData.needs || []);
|
|
1950
2004
|
return {
|
|
1951
2005
|
data: rootFieldset,
|
|
@@ -2070,7 +2124,7 @@ var listAuthenticationsPlugin = ({ context }) => {
|
|
|
2070
2124
|
searchParams.offset = options.cursor;
|
|
2071
2125
|
}
|
|
2072
2126
|
const data = await api.get(
|
|
2073
|
-
"/api/v4/authentications/",
|
|
2127
|
+
"/zapier/api/v4/authentications/",
|
|
2074
2128
|
{
|
|
2075
2129
|
searchParams,
|
|
2076
2130
|
customErrorHandler: ({ status }) => {
|
|
@@ -2210,7 +2264,7 @@ var getAuthenticationPlugin = ({ context }) => {
|
|
|
2210
2264
|
const { api } = context;
|
|
2211
2265
|
const { authenticationId } = options;
|
|
2212
2266
|
const data = await api.get(
|
|
2213
|
-
`/api/v4/authentications/${authenticationId}/`,
|
|
2267
|
+
`/zapier/api/v4/authentications/${authenticationId}/`,
|
|
2214
2268
|
{
|
|
2215
2269
|
customErrorHandler: ({ status }) => {
|
|
2216
2270
|
if (status === 401) {
|
|
@@ -2403,11 +2457,11 @@ async function executeAction(actionOptions) {
|
|
|
2403
2457
|
data: runRequestData
|
|
2404
2458
|
};
|
|
2405
2459
|
const runData = await api.post(
|
|
2406
|
-
"/api/actions/v1/runs",
|
|
2460
|
+
"/zapier/api/actions/v1/runs",
|
|
2407
2461
|
runRequest
|
|
2408
2462
|
);
|
|
2409
2463
|
const runId = runData.data.id;
|
|
2410
|
-
return await api.poll(`/api/actions/v1/runs/${runId}`, {
|
|
2464
|
+
return await api.poll(`/zapier/api/actions/v1/runs/${runId}`, {
|
|
2411
2465
|
successStatus: 200,
|
|
2412
2466
|
pendingStatus: 202,
|
|
2413
2467
|
resultExtractor: (result) => result.data
|
|
@@ -2688,7 +2742,7 @@ async function getPreferredManifestEntryKey({
|
|
|
2688
2742
|
}
|
|
2689
2743
|
if (locator.implementationName) {
|
|
2690
2744
|
try {
|
|
2691
|
-
const implementationsEnvelope = await api.get(`/api/v4/implementations-meta/lookup/`, {
|
|
2745
|
+
const implementationsEnvelope = await api.get(`/zapier/api/v4/implementations-meta/lookup/`, {
|
|
2692
2746
|
searchParams: {
|
|
2693
2747
|
selected_apis: locator.implementationName
|
|
2694
2748
|
}
|
|
@@ -2715,7 +2769,7 @@ async function listAppsForSlugsPage({
|
|
|
2715
2769
|
searchParams.offset = cursor;
|
|
2716
2770
|
}
|
|
2717
2771
|
const implementationsEnvelope = await api.get(
|
|
2718
|
-
"/api/v4/implementations-meta/lookup/",
|
|
2772
|
+
"/zapier/api/v4/implementations-meta/lookup/",
|
|
2719
2773
|
{
|
|
2720
2774
|
searchParams
|
|
2721
2775
|
}
|
|
@@ -2954,9 +3008,12 @@ var UserProfileItemSchema = withFormatter(
|
|
|
2954
3008
|
// src/plugins/getProfile/index.ts
|
|
2955
3009
|
var getProfilePlugin = ({ context }) => {
|
|
2956
3010
|
const getProfile = createFunction(async function getProfile2() {
|
|
2957
|
-
const profile = await context.api.get(
|
|
2958
|
-
|
|
2959
|
-
|
|
3011
|
+
const profile = await context.api.get(
|
|
3012
|
+
"/zapier/api/v4/profile/",
|
|
3013
|
+
{
|
|
3014
|
+
authRequired: true
|
|
3015
|
+
}
|
|
3016
|
+
);
|
|
2960
3017
|
const { user_id: _unusedUserId, ...data } = profile;
|
|
2961
3018
|
return {
|
|
2962
3019
|
data: {
|
|
@@ -3283,11 +3340,63 @@ async function getTokenFromEnvOrConfig(options = {}) {
|
|
|
3283
3340
|
return getTokenFromCliLogin(options);
|
|
3284
3341
|
}
|
|
3285
3342
|
|
|
3343
|
+
// src/utils/url-utils.ts
|
|
3344
|
+
function getZapierBaseUrl(baseUrl) {
|
|
3345
|
+
if (!baseUrl) {
|
|
3346
|
+
return void 0;
|
|
3347
|
+
}
|
|
3348
|
+
try {
|
|
3349
|
+
const url = new URL(baseUrl);
|
|
3350
|
+
const hostname = url.hostname;
|
|
3351
|
+
const hostParts = hostname.split(".");
|
|
3352
|
+
if (hostParts.length < 2) {
|
|
3353
|
+
return void 0;
|
|
3354
|
+
}
|
|
3355
|
+
const hasZapierPart = hostParts.some(
|
|
3356
|
+
(part) => part === "zapier" || part.startsWith("zapier-")
|
|
3357
|
+
);
|
|
3358
|
+
if (!hasZapierPart) {
|
|
3359
|
+
return void 0;
|
|
3360
|
+
}
|
|
3361
|
+
const rootDomain = hostParts.slice(-2).join(".");
|
|
3362
|
+
return `${url.protocol}//${rootDomain}`;
|
|
3363
|
+
} catch {
|
|
3364
|
+
return void 0;
|
|
3365
|
+
}
|
|
3366
|
+
}
|
|
3367
|
+
function getTrackingBaseUrl({
|
|
3368
|
+
trackingBaseUrl,
|
|
3369
|
+
baseUrl
|
|
3370
|
+
}) {
|
|
3371
|
+
if (trackingBaseUrl) {
|
|
3372
|
+
return trackingBaseUrl;
|
|
3373
|
+
}
|
|
3374
|
+
if (process.env.ZAPIER_TRACKING_BASE_URL) {
|
|
3375
|
+
return process.env.ZAPIER_TRACKING_BASE_URL;
|
|
3376
|
+
}
|
|
3377
|
+
if (baseUrl) {
|
|
3378
|
+
const zapierBaseUrl = getZapierBaseUrl(baseUrl);
|
|
3379
|
+
if (zapierBaseUrl) {
|
|
3380
|
+
return zapierBaseUrl;
|
|
3381
|
+
}
|
|
3382
|
+
}
|
|
3383
|
+
if (baseUrl) {
|
|
3384
|
+
return baseUrl;
|
|
3385
|
+
}
|
|
3386
|
+
return ZAPIER_BASE_URL;
|
|
3387
|
+
}
|
|
3388
|
+
|
|
3286
3389
|
// src/api/client.ts
|
|
3287
|
-
var
|
|
3288
|
-
// e.g. https://
|
|
3289
|
-
relay: {
|
|
3290
|
-
authHeader: "X-Relay-Authorization"
|
|
3390
|
+
var pathConfig = {
|
|
3391
|
+
// e.g. /relay -> https://sdkapi.zapier.com/api/v0/sdk/relay/...
|
|
3392
|
+
"/relay": {
|
|
3393
|
+
authHeader: "X-Relay-Authorization",
|
|
3394
|
+
pathPrefix: "/api/v0/sdk/relay"
|
|
3395
|
+
},
|
|
3396
|
+
// e.g. /zapier -> https://sdkapi.zapier.com/api/v0/sdk/zapier/...
|
|
3397
|
+
"/zapier": {
|
|
3398
|
+
authHeader: "Authorization",
|
|
3399
|
+
pathPrefix: "/api/v0/sdk/zapier"
|
|
3291
3400
|
}
|
|
3292
3401
|
};
|
|
3293
3402
|
var ZapierApiClient = class {
|
|
@@ -3476,39 +3585,47 @@ var ZapierApiClient = class {
|
|
|
3476
3585
|
return { message: fallbackMessage };
|
|
3477
3586
|
}
|
|
3478
3587
|
}
|
|
3479
|
-
//
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
|
|
3588
|
+
// Apply any special routing logic for configured paths.
|
|
3589
|
+
applyPathConfiguration(path) {
|
|
3590
|
+
const matchingPathKey = Object.keys(pathConfig).find(
|
|
3591
|
+
(configPath) => path === configPath || path.startsWith(configPath + "/")
|
|
3592
|
+
);
|
|
3593
|
+
const config = matchingPathKey ? pathConfig[matchingPathKey] : void 0;
|
|
3594
|
+
const zapierBaseUrl = getZapierBaseUrl(this.options.baseUrl);
|
|
3595
|
+
if (zapierBaseUrl === this.options.baseUrl) {
|
|
3486
3596
|
const originalBaseUrl = new URL(this.options.baseUrl);
|
|
3487
|
-
const finalBaseUrl = `https
|
|
3488
|
-
|
|
3489
|
-
|
|
3597
|
+
const finalBaseUrl = `https://sdkapi.${originalBaseUrl.hostname}`;
|
|
3598
|
+
let finalPath = path;
|
|
3599
|
+
if (config && "pathPrefix" in config && config.pathPrefix && matchingPathKey) {
|
|
3600
|
+
const pathWithoutPrefix = path.slice(matchingPathKey.length) || "/";
|
|
3601
|
+
finalPath = `${config.pathPrefix}${pathWithoutPrefix}`;
|
|
3602
|
+
}
|
|
3603
|
+
return {
|
|
3604
|
+
url: new URL(finalPath, finalBaseUrl),
|
|
3605
|
+
pathConfig: config
|
|
3606
|
+
};
|
|
3490
3607
|
}
|
|
3491
3608
|
return {
|
|
3492
3609
|
url: new URL(path, this.options.baseUrl),
|
|
3493
|
-
|
|
3610
|
+
pathConfig: config
|
|
3494
3611
|
};
|
|
3495
3612
|
}
|
|
3496
3613
|
// Helper to build full URLs and return routing info
|
|
3497
3614
|
buildUrl(path, searchParams) {
|
|
3498
|
-
const { url,
|
|
3615
|
+
const { url, pathConfig: config } = this.applyPathConfiguration(path);
|
|
3499
3616
|
if (searchParams) {
|
|
3500
3617
|
Object.entries(searchParams).forEach(([key, value]) => {
|
|
3501
3618
|
url.searchParams.set(key, value);
|
|
3502
3619
|
});
|
|
3503
3620
|
}
|
|
3504
|
-
return { url: url.toString(),
|
|
3621
|
+
return { url: url.toString(), pathConfig: config };
|
|
3505
3622
|
}
|
|
3506
3623
|
// Helper to build headers
|
|
3507
|
-
async buildHeaders(options = {},
|
|
3624
|
+
async buildHeaders(options = {}, pathConfig2) {
|
|
3508
3625
|
const headers = new Headers(options.headers ?? {});
|
|
3509
3626
|
const authToken = await this.getAuthToken();
|
|
3510
3627
|
if (authToken) {
|
|
3511
|
-
const authHeaderName =
|
|
3628
|
+
const authHeaderName = pathConfig2?.authHeader || "Authorization";
|
|
3512
3629
|
headers.set(authHeaderName, getAuthorizationHeader(authToken));
|
|
3513
3630
|
}
|
|
3514
3631
|
if (options.authRequired) {
|
|
@@ -3555,13 +3672,10 @@ var ZapierApiClient = class {
|
|
|
3555
3672
|
if (fetchOptions?.body && typeof fetchOptions.body === "object") {
|
|
3556
3673
|
fetchOptions.body = JSON.stringify(fetchOptions.body);
|
|
3557
3674
|
}
|
|
3558
|
-
const { url,
|
|
3559
|
-
path,
|
|
3560
|
-
fetchOptions?.searchParams
|
|
3561
|
-
);
|
|
3675
|
+
const { url, pathConfig: pathConfig2 } = this.buildUrl(path, fetchOptions?.searchParams);
|
|
3562
3676
|
const builtHeaders = await this.buildHeaders(
|
|
3563
3677
|
fetchOptions,
|
|
3564
|
-
|
|
3678
|
+
pathConfig2
|
|
3565
3679
|
);
|
|
3566
3680
|
const inputHeaders = new Headers(fetchOptions?.headers ?? {});
|
|
3567
3681
|
const mergedHeaders = new Headers();
|
|
@@ -3855,43 +3969,62 @@ function transformNeedChoicesToInputFieldChoiceItem(choice) {
|
|
|
3855
3969
|
}
|
|
3856
3970
|
var listInputFieldChoicesPlugin = ({ context, sdk }) => {
|
|
3857
3971
|
const listInputFieldChoices = createPaginatedFunction(async function listInputFieldChoicesPage(options) {
|
|
3858
|
-
const { api } = context;
|
|
3972
|
+
const { api, getVersionedImplementationId } = context;
|
|
3859
3973
|
const {
|
|
3860
3974
|
appKey,
|
|
3861
3975
|
actionType,
|
|
3862
3976
|
actionKey,
|
|
3863
3977
|
inputFieldKey,
|
|
3864
|
-
authenticationId,
|
|
3978
|
+
authenticationId = null,
|
|
3865
3979
|
inputs,
|
|
3866
3980
|
page,
|
|
3867
3981
|
cursor
|
|
3868
3982
|
} = options;
|
|
3869
|
-
const
|
|
3870
|
-
|
|
3871
|
-
|
|
3872
|
-
|
|
3873
|
-
|
|
3983
|
+
const selectedApi = await getVersionedImplementationId(appKey);
|
|
3984
|
+
if (!selectedApi) {
|
|
3985
|
+
throw new ZapierConfigurationError(
|
|
3986
|
+
"No current_implementation_id found for app",
|
|
3987
|
+
{ configType: "current_implementation_id" }
|
|
3874
3988
|
);
|
|
3875
3989
|
}
|
|
3876
|
-
const
|
|
3877
|
-
|
|
3878
|
-
|
|
3879
|
-
|
|
3880
|
-
|
|
3881
|
-
|
|
3882
|
-
|
|
3883
|
-
|
|
3884
|
-
|
|
3885
|
-
|
|
3886
|
-
|
|
3887
|
-
|
|
3888
|
-
|
|
3990
|
+
const { data: action } = await sdk.getAction({
|
|
3991
|
+
appKey,
|
|
3992
|
+
actionType,
|
|
3993
|
+
actionKey
|
|
3994
|
+
});
|
|
3995
|
+
const needsData = await fetchImplementationNeeds({
|
|
3996
|
+
api,
|
|
3997
|
+
selectedApi,
|
|
3998
|
+
action: action.key,
|
|
3999
|
+
actionType,
|
|
4000
|
+
authenticationId,
|
|
4001
|
+
inputs
|
|
4002
|
+
});
|
|
4003
|
+
const targetNeed = needsData.needs?.find(
|
|
4004
|
+
(need) => need.key === inputFieldKey
|
|
3889
4005
|
);
|
|
3890
|
-
if (
|
|
4006
|
+
if (targetNeed?.choices && targetNeed.choices.length > 0) {
|
|
4007
|
+
return {
|
|
4008
|
+
data: targetNeed.choices.map(
|
|
4009
|
+
transformNeedChoicesToInputFieldChoiceItem
|
|
4010
|
+
),
|
|
4011
|
+
nextCursor: void 0
|
|
4012
|
+
};
|
|
4013
|
+
}
|
|
4014
|
+
if (!action.id) {
|
|
3891
4015
|
throw new ZapierApiError(
|
|
3892
|
-
`
|
|
4016
|
+
`Action ${actionKey} does not have an ID - cannot retrieve input field choices`
|
|
3893
4017
|
);
|
|
3894
4018
|
}
|
|
4019
|
+
const requestPage = cursor ? parseInt(cursor, 10) : page ?? 0;
|
|
4020
|
+
const choicesData = await fetchImplementationChoices({
|
|
4021
|
+
api,
|
|
4022
|
+
actionId: action.id,
|
|
4023
|
+
inputFieldId: inputFieldKey,
|
|
4024
|
+
authenticationId,
|
|
4025
|
+
inputs,
|
|
4026
|
+
page: requestPage
|
|
4027
|
+
});
|
|
3895
4028
|
const choices = (choicesData.choices || []).map(
|
|
3896
4029
|
transformNeedChoicesToInputFieldChoiceItem
|
|
3897
4030
|
);
|
|
@@ -4089,7 +4222,7 @@ function getCpuTime() {
|
|
|
4089
4222
|
|
|
4090
4223
|
// package.json
|
|
4091
4224
|
var package_default = {
|
|
4092
|
-
version: "0.
|
|
4225
|
+
version: "0.15.0"};
|
|
4093
4226
|
|
|
4094
4227
|
// src/plugins/eventEmission/builders.ts
|
|
4095
4228
|
function createBaseEvent(context = {}) {
|
|
@@ -4159,52 +4292,6 @@ function buildErrorEventWithContext(data, context = {}) {
|
|
|
4159
4292
|
};
|
|
4160
4293
|
}
|
|
4161
4294
|
|
|
4162
|
-
// src/utils/url-utils.ts
|
|
4163
|
-
function getZapierBaseUrl(baseUrl) {
|
|
4164
|
-
if (!baseUrl) {
|
|
4165
|
-
return void 0;
|
|
4166
|
-
}
|
|
4167
|
-
try {
|
|
4168
|
-
const url = new URL(baseUrl);
|
|
4169
|
-
const hostname = url.hostname;
|
|
4170
|
-
const hostParts = hostname.split(".");
|
|
4171
|
-
if (hostParts.length < 2) {
|
|
4172
|
-
return void 0;
|
|
4173
|
-
}
|
|
4174
|
-
const hasZapierPart = hostParts.some(
|
|
4175
|
-
(part) => part === "zapier" || part.startsWith("zapier-")
|
|
4176
|
-
);
|
|
4177
|
-
if (!hasZapierPart) {
|
|
4178
|
-
return void 0;
|
|
4179
|
-
}
|
|
4180
|
-
const rootDomain = hostParts.slice(-2).join(".");
|
|
4181
|
-
return `${url.protocol}//${rootDomain}`;
|
|
4182
|
-
} catch {
|
|
4183
|
-
return void 0;
|
|
4184
|
-
}
|
|
4185
|
-
}
|
|
4186
|
-
function getTrackingBaseUrl({
|
|
4187
|
-
trackingBaseUrl,
|
|
4188
|
-
baseUrl
|
|
4189
|
-
}) {
|
|
4190
|
-
if (trackingBaseUrl) {
|
|
4191
|
-
return trackingBaseUrl;
|
|
4192
|
-
}
|
|
4193
|
-
if (process.env.ZAPIER_TRACKING_BASE_URL) {
|
|
4194
|
-
return process.env.ZAPIER_TRACKING_BASE_URL;
|
|
4195
|
-
}
|
|
4196
|
-
if (baseUrl) {
|
|
4197
|
-
const zapierBaseUrl = getZapierBaseUrl(baseUrl);
|
|
4198
|
-
if (zapierBaseUrl) {
|
|
4199
|
-
return zapierBaseUrl;
|
|
4200
|
-
}
|
|
4201
|
-
}
|
|
4202
|
-
if (baseUrl) {
|
|
4203
|
-
return baseUrl;
|
|
4204
|
-
}
|
|
4205
|
-
return ZAPIER_BASE_URL;
|
|
4206
|
-
}
|
|
4207
|
-
|
|
4208
4295
|
// src/plugins/eventEmission/index.ts
|
|
4209
4296
|
var APPLICATION_LIFECYCLE_EVENT_SUBJECT = "platform.sdk.ApplicationLifecycleEvent";
|
|
4210
4297
|
var ERROR_OCCURRED_EVENT_SUBJECT = "platform.sdk.ErrorOccurredEvent";
|