@zapier/zapier-sdk 0.18.2 → 0.18.3

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/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- import { AuthenticationItemSchema as AuthenticationItemSchema$1, GetAuthenticationParamSchema } from '@zapier/zapier-sdk-core/v0/schemas/authentications';
2
+ import { ListAuthenticationsQuerySchema as ListAuthenticationsQuerySchema$1, AuthenticationItemSchema as AuthenticationItemSchema$1, GetAuthenticationParamSchema } from '@zapier/zapier-sdk-core/v0/schemas/authentications';
3
3
  import { setTimeout as setTimeout$1 } from 'timers/promises';
4
4
  import * as os from 'os';
5
5
 
@@ -694,10 +694,16 @@ function createPageFunction(coreFn) {
694
694
  try {
695
695
  const result = await coreFn(options);
696
696
  if (result && typeof result === "object" && "data" in result) {
697
- const data = result.data;
697
+ const paginatedResult = result;
698
+ let nextCursor;
699
+ if (paginatedResult.nextCursor) {
700
+ nextCursor = paginatedResult.nextCursor;
701
+ } else if (paginatedResult.links?.next) {
702
+ nextCursor = extractCursor({ next: paginatedResult.links.next });
703
+ }
698
704
  return {
699
- data: Array.isArray(data) ? data : [data],
700
- nextCursor: result.nextCursor
705
+ data: Array.isArray(paginatedResult.data) ? paginatedResult.data : [paginatedResult.data],
706
+ nextCursor
701
707
  };
702
708
  }
703
709
  if (Array.isArray(result)) {
@@ -1003,34 +1009,6 @@ z.object({
1003
1009
  format: z.string().optional(),
1004
1010
  inputFormat: z.array(z.string()).optional()
1005
1011
  });
1006
- var AuthenticationSchema = z.object({
1007
- id: z.number(),
1008
- date: z.string(),
1009
- lastchanged: z.string().optional(),
1010
- account_id: z.number(),
1011
- customuser_id: z.number().optional(),
1012
- selected_api: z.string(),
1013
- destination_selected_api: z.string().nullable().optional(),
1014
- is_invite_only: z.boolean(),
1015
- is_private: z.boolean(),
1016
- shared_with_all: z.boolean(),
1017
- is_stale: z.string().optional(),
1018
- is_shared: z.string().optional(),
1019
- marked_stale_at: z.string().nullable().optional(),
1020
- label: z.string().nullable().optional(),
1021
- identifier: z.string().nullable().optional(),
1022
- title: z.string().nullable().optional(),
1023
- url: z.string().optional(),
1024
- groups: z.string().optional(),
1025
- members: z.string().optional(),
1026
- permissions: z.record(z.string(), z.boolean()).optional()
1027
- });
1028
- z.object({
1029
- count: z.number(),
1030
- next: z.string().nullable().optional(),
1031
- previous: z.string().nullable().optional(),
1032
- results: z.array(AuthenticationSchema)
1033
- });
1034
1012
  z.object({
1035
1013
  id: z.number(),
1036
1014
  code: z.string(),
@@ -1421,50 +1399,6 @@ function normalizeImplementationMetaToAppItem(implementationMeta) {
1421
1399
  version: appVersion
1422
1400
  };
1423
1401
  }
1424
- function normalizeAuthenticationItem(auth, options = {}) {
1425
- let appKey = options.app_key;
1426
- let appVersion = options.app_version;
1427
- if (auth.selected_api) {
1428
- const [extractedAppKey, extractedVersion] = splitVersionedKey(
1429
- auth.selected_api
1430
- );
1431
- if (!appKey) {
1432
- appKey = extractedAppKey;
1433
- }
1434
- if (!appVersion) {
1435
- appVersion = extractedVersion;
1436
- }
1437
- }
1438
- const {
1439
- selected_api: selectedApi,
1440
- customuser_id: profileId,
1441
- id,
1442
- account_id: accountId,
1443
- ...restOfAuth
1444
- } = auth;
1445
- return {
1446
- ...restOfAuth,
1447
- // Pass through all other API response fields except selected_api
1448
- id: String(id),
1449
- // Convert to string
1450
- account_id: String(accountId),
1451
- // Convert to string
1452
- implementation_id: selectedApi,
1453
- // Rename selected_api to implementation_id
1454
- title: auth.title || auth.label || void 0,
1455
- // Coerce title from label if missing
1456
- is_expired: auth.is_stale,
1457
- // Map is_stale to is_expired
1458
- expired_at: auth.marked_stale_at,
1459
- // Map marked_stale_at to expired_at
1460
- app_key: appKey,
1461
- // App key from implementations endpoint or parsed from selected_api
1462
- app_version: appVersion,
1463
- // Version from selected_api or provided
1464
- profile_id: profileId != null ? String(profileId) : void 0
1465
- // Map customuser_id to profile_id, convert to string
1466
- };
1467
- }
1468
1402
  function normalizeActionItem(action) {
1469
1403
  const { name, type, selected_api: selectedApi } = action;
1470
1404
  const [appKey, appVersion] = selectedApi ? splitVersionedKey(selectedApi) : ["", void 0];
@@ -2226,19 +2160,22 @@ var listInputFieldsPlugin = ({ sdk, context }) => {
2226
2160
  }
2227
2161
  };
2228
2162
  };
2229
- var ListAuthenticationsSchema = z.object({
2163
+ var ListAuthenticationsQuerySchema = ListAuthenticationsQuerySchema$1.omit(
2164
+ {
2165
+ offset: true
2166
+ }
2167
+ ).extend({
2168
+ // Override appKey with our custom schema (array type, different description)
2230
2169
  appKey: AppKeyPropertySchema.optional().describe(
2231
2170
  "App key of authentications to list (e.g., 'SlackCLIAPI' or slug like 'github')"
2232
2171
  ),
2172
+ // Override authenticationIds to be an array instead of comma-separated string
2233
2173
  authenticationIds: z.array(z.string()).optional().describe("List of authentication IDs to filter by"),
2234
- search: z.string().optional().describe("Search term to filter authentications by title"),
2235
- title: z.string().optional().describe("Filter authentications by exact title match"),
2236
- accountId: z.string().optional().describe("Filter by account ID"),
2237
- owner: z.union([z.string(), z.literal("me")]).optional().describe(
2238
- "Filter by owner, 'me' for your own authentications or a specific user ID"
2239
- ),
2174
+ // Override pageSize to make optional (needs to be fixed in `zapier-sdk-core`)
2240
2175
  pageSize: z.number().min(1).optional().describe("Number of authentications per page"),
2176
+ // SDK specific property for pagination/iterator helpers
2241
2177
  maxItems: z.number().min(1).optional().describe("Maximum total items to return across all pages"),
2178
+ // SDK specific property for pagination/iterator helpers
2242
2179
  cursor: z.string().optional().describe("Cursor to start from")
2243
2180
  }).merge(TelemetryMarkerSchema).describe("List available authentications with optional filtering");
2244
2181
  var AuthenticationItemSchema = withFormatter(
@@ -2275,36 +2212,38 @@ var AuthenticationItemSchema = withFormatter(
2275
2212
  var listAuthenticationsPlugin = ({ context }) => {
2276
2213
  async function listAuthenticationsPage(options) {
2277
2214
  const { api, getVersionedImplementationId } = context;
2278
- const searchParams = {};
2215
+ const searchParams = {
2216
+ pageSize: options.pageSize.toString()
2217
+ };
2279
2218
  if (options.appKey) {
2280
2219
  const implementationId = await getVersionedImplementationId(
2281
2220
  options.appKey
2282
2221
  );
2283
2222
  if (implementationId) {
2284
2223
  const [versionlessSelectedApi] = splitVersionedKey(implementationId);
2285
- searchParams.versionless_selected_api = versionlessSelectedApi;
2224
+ searchParams.appKey = versionlessSelectedApi;
2286
2225
  }
2287
2226
  }
2288
2227
  if (options.authenticationIds && options.authenticationIds.length > 0) {
2289
- searchParams.ids = options.authenticationIds.join(",");
2228
+ searchParams.authenticationIds = options.authenticationIds.join(",");
2290
2229
  }
2291
2230
  if (options.search) {
2292
2231
  searchParams.search = options.search;
2293
- } else if (options.title) {
2294
- searchParams.search = options.title;
2232
+ }
2233
+ if (options.title) {
2234
+ searchParams.title = options.title;
2295
2235
  }
2296
2236
  if (options.accountId) {
2297
- searchParams.account_id = options.accountId;
2237
+ searchParams.accountId = options.accountId;
2298
2238
  }
2299
2239
  if (options.owner) {
2300
2240
  searchParams.owner = options.owner;
2301
2241
  }
2302
- searchParams.limit = options.pageSize.toString();
2303
2242
  if (options.cursor) {
2304
2243
  searchParams.offset = options.cursor;
2305
2244
  }
2306
- const data = await api.get(
2307
- "/zapier/api/v4/authentications/",
2245
+ const response = await api.get(
2246
+ "/api/v0/authentications",
2308
2247
  {
2309
2248
  searchParams,
2310
2249
  customErrorHandler: ({ status }) => {
@@ -2325,23 +2264,12 @@ var listAuthenticationsPlugin = ({ context }) => {
2325
2264
  authRequired: true
2326
2265
  }
2327
2266
  );
2328
- let auths = (data.results || []).map(
2329
- (auth) => normalizeAuthenticationItem(auth)
2330
- );
2331
- if (options.title) {
2332
- auths = auths.filter(
2333
- (auth) => auth.title === options.title
2334
- );
2335
- }
2336
- return {
2337
- data: auths,
2338
- nextCursor: extractCursor(data)
2339
- };
2267
+ return response;
2340
2268
  }
2341
2269
  const methodName = stripPageSuffix(listAuthenticationsPage.name);
2342
2270
  const listAuthenticationsDefinition = createPaginatedFunction(
2343
2271
  listAuthenticationsPage,
2344
- ListAuthenticationsSchema,
2272
+ ListAuthenticationsQuerySchema,
2345
2273
  createTelemetryCallback(context.eventEmission.emitMethodCalled, methodName),
2346
2274
  methodName
2347
2275
  );
@@ -2353,7 +2281,7 @@ var listAuthenticationsPlugin = ({ context }) => {
2353
2281
  categories: ["authentication"],
2354
2282
  type: "list",
2355
2283
  itemType: "Authentication",
2356
- inputSchema: ListAuthenticationsSchema,
2284
+ inputSchema: ListAuthenticationsQuerySchema,
2357
2285
  outputSchema: AuthenticationItemSchema,
2358
2286
  resolvers: {
2359
2287
  appKey: appKeyResolver
@@ -4859,7 +4787,7 @@ function getCpuTime() {
4859
4787
 
4860
4788
  // package.json
4861
4789
  var package_default = {
4862
- version: "0.18.2"};
4790
+ version: "0.18.3"};
4863
4791
 
4864
4792
  // src/plugins/eventEmission/builders.ts
4865
4793
  function createBaseEvent(context = {}) {
@@ -2,7 +2,7 @@ import { describe, it, expect, vi, beforeEach } from "vitest";
2
2
  import { ZapierValidationError } from "../../types/errors";
3
3
  import { findFirstAuthenticationPlugin } from "./index";
4
4
  import { createSdk } from "../../sdk";
5
- import { ListAuthenticationsSchema } from "../listAuthentications/schemas";
5
+ import { ListAuthenticationsQuerySchema } from "../listAuthentications/schemas";
6
6
  import { eventEmissionPlugin } from "../eventEmission";
7
7
  const mockAuthentications = [
8
8
  {
@@ -45,7 +45,7 @@ describe("findFirstAuthentication plugin", () => {
45
45
  context: {
46
46
  meta: {
47
47
  listAuthentications: {
48
- inputSchema: ListAuthenticationsSchema,
48
+ inputSchema: ListAuthenticationsQuerySchema,
49
49
  },
50
50
  },
51
51
  },
@@ -2,7 +2,7 @@ import { describe, it, expect, vi, beforeEach } from "vitest";
2
2
  import { ZapierValidationError, ZapierResourceNotFoundError, } from "../../types/errors";
3
3
  import { findUniqueAuthenticationPlugin } from "./index";
4
4
  import { createSdk } from "../../sdk";
5
- import { ListAuthenticationsSchema } from "../listAuthentications/schemas";
5
+ import { ListAuthenticationsQuerySchema } from "../listAuthentications/schemas";
6
6
  import { eventEmissionPlugin } from "../eventEmission";
7
7
  const mockAuthentication = {
8
8
  id: "123",
@@ -46,7 +46,7 @@ describe("findUniqueAuthentication plugin", () => {
46
46
  context: {
47
47
  meta: {
48
48
  listAuthentications: {
49
- inputSchema: ListAuthenticationsSchema,
49
+ inputSchema: ListAuthenticationsQuerySchema,
50
50
  },
51
51
  },
52
52
  },
@@ -1,24 +1,18 @@
1
1
  import type { Plugin, GetSdkType } from "../../types/plugin";
2
2
  import type { ApiClient } from "../../api";
3
- import type { AuthenticationItem } from "../../types/domain";
4
- import { ListAuthenticationsSchema, type ListAuthenticationsOptions } from "./schemas";
3
+ import type { AuthenticationItem } from "@zapier/zapier-sdk-core/v0/schemas/authentications";
4
+ import { ListAuthenticationsQuerySchema, type ListAuthenticationsOptions, type ListAuthenticationsPage } from "./schemas";
5
5
  import type { GetVersionedImplementationId } from "../manifest/schemas";
6
6
  import type { ManifestPluginProvides } from "../manifest";
7
7
  import type { EventEmissionContext } from "../eventEmission";
8
8
  export interface ListAuthenticationsPluginProvides {
9
- listAuthentications: (options?: ListAuthenticationsOptions) => Promise<{
10
- data: AuthenticationItem[];
11
- nextCursor?: string;
12
- }> & AsyncIterable<{
13
- data: AuthenticationItem[];
14
- nextCursor?: string;
15
- }> & {
9
+ listAuthentications: (options?: ListAuthenticationsOptions) => Promise<ListAuthenticationsPage> & AsyncIterable<ListAuthenticationsPage> & {
16
10
  items(): AsyncIterable<AuthenticationItem>;
17
11
  };
18
12
  context: {
19
13
  meta: {
20
14
  listAuthentications: {
21
- inputSchema: typeof ListAuthenticationsSchema;
15
+ inputSchema: typeof ListAuthenticationsQuerySchema;
22
16
  };
23
17
  };
24
18
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/listAuthentications/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,UAA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C7D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oDAAoD,CAAC;AAC7F,OAAO,EACL,8BAA8B,EAC9B,KAAK,0BAA0B,EAC/B,KAAK,uBAAuB,EAC7B,MAAM,WAAW,CAAC;AAInB,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAG1D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAK7D,MAAM,WAAW,iCAAiC;IAChD,mBAAmB,EAAE,CACnB,OAAO,CAAC,EAAE,0BAA0B,KACjC,OAAO,CAAC,uBAAuB,CAAC,GACnC,aAAa,CAAC,uBAAuB,CAAC,GAAG;QACvC,KAAK,IAAI,aAAa,CAAC,kBAAkB,CAAC,CAAC;KAC5C,CAAC;IACJ,OAAO,EAAE;QACP,IAAI,EAAE;YACJ,mBAAmB,EAAE;gBACnB,WAAW,EAAE,OAAO,8BAA8B,CAAC;aACpD,CAAC;SACH,CAAC;KACH,CAAC;CACH;AAED,eAAO,MAAM,yBAAyB,EAAE,MAAM,CAC5C,UAAU,CAAC,sBAAsB,CAAC,EAClC;IACE,GAAG,EAAE,SAAS,CAAC;IACf,4BAA4B,EAAE,4BAA4B,CAAC;CAC5D,GAAG,oBAAoB,EACxB,iCAAiC,CAiGlC,CAAC"}
@@ -1,49 +1,46 @@
1
- import { ListAuthenticationsSchema, } from "./schemas";
2
- import { normalizeAuthenticationItem, splitVersionedKey, } from "../../utils/domain-utils";
3
- import { ZapierAuthenticationError } from "../../types/errors";
4
- import { createPaginatedFunction, extractCursor, } from "../../utils/function-utils";
1
+ import { ListAuthenticationsQuerySchema, } from "./schemas";
2
+ import { splitVersionedKey } from "../../utils/domain-utils";
3
+ import { createPaginatedFunction } from "../../utils/function-utils";
5
4
  import { appKeyResolver } from "../../resolvers";
6
5
  import { AuthenticationItemSchema } from "../../schemas/Auth";
7
6
  import { createTelemetryCallback } from "../../utils/telemetry-utils";
8
7
  import { stripPageSuffix } from "../../utils/string-utils";
8
+ import { ZapierAuthenticationError } from "../../types/errors";
9
9
  export const listAuthenticationsPlugin = ({ context }) => {
10
10
  async function listAuthenticationsPage(options) {
11
11
  const { api, getVersionedImplementationId } = context;
12
- // Build search parameters
13
- const searchParams = {};
14
- // Handle appKey filtering by getting the selected_api first
12
+ const searchParams = {
13
+ pageSize: options.pageSize.toString(),
14
+ };
15
+ // Resolve appKey to implementationId if provided
15
16
  if (options.appKey) {
16
17
  const implementationId = await getVersionedImplementationId(options.appKey);
17
18
  if (implementationId) {
19
+ // Extract versionless app key to pass to handler
18
20
  const [versionlessSelectedApi] = splitVersionedKey(implementationId);
19
- searchParams.versionless_selected_api = versionlessSelectedApi;
21
+ searchParams.appKey = versionlessSelectedApi;
20
22
  }
21
23
  }
22
- // Add authenticationIds as ids parameter if provided
24
+ // Pass other filter options as searchParams
23
25
  if (options.authenticationIds && options.authenticationIds.length > 0) {
24
- searchParams.ids = options.authenticationIds.join(",");
26
+ searchParams.authenticationIds = options.authenticationIds.join(",");
25
27
  }
26
- // Add other query parameters if provided
27
- // Use title as search if no explicit search provided
28
28
  if (options.search) {
29
29
  searchParams.search = options.search;
30
30
  }
31
- else if (options.title) {
32
- searchParams.search = options.title;
31
+ if (options.title) {
32
+ searchParams.title = options.title;
33
33
  }
34
34
  if (options.accountId) {
35
- searchParams.account_id = options.accountId;
35
+ searchParams.accountId = options.accountId;
36
36
  }
37
37
  if (options.owner) {
38
38
  searchParams.owner = options.owner;
39
39
  }
40
- // pageSize is now guaranteed to be set by the higher-order function
41
- searchParams.limit = options.pageSize.toString();
42
40
  if (options.cursor) {
43
- // Convert cursor back to offset for the API
44
41
  searchParams.offset = options.cursor;
45
42
  }
46
- const data = await api.get("/zapier/api/v4/authentications/", {
43
+ const response = await api.get("/api/v0/authentications", {
47
44
  searchParams,
48
45
  customErrorHandler: ({ status }) => {
49
46
  if (status === 401) {
@@ -56,19 +53,10 @@ export const listAuthenticationsPlugin = ({ context }) => {
56
53
  },
57
54
  authRequired: true,
58
55
  });
59
- // Transform API response and filter by exact title match if specified
60
- let auths = (data.results || []).map((auth) => normalizeAuthenticationItem(auth));
61
- // Filter by exact title match if specified
62
- if (options.title) {
63
- auths = auths.filter((auth) => auth.title === options.title);
64
- }
65
- return {
66
- data: auths,
67
- nextCursor: extractCursor(data),
68
- };
56
+ return response;
69
57
  }
70
58
  const methodName = stripPageSuffix(listAuthenticationsPage.name);
71
- const listAuthenticationsDefinition = createPaginatedFunction(listAuthenticationsPage, ListAuthenticationsSchema, createTelemetryCallback(context.eventEmission.emitMethodCalled, methodName), methodName);
59
+ const listAuthenticationsDefinition = createPaginatedFunction(listAuthenticationsPage, ListAuthenticationsQuerySchema, createTelemetryCallback(context.eventEmission.emitMethodCalled, methodName), methodName);
72
60
  return {
73
61
  listAuthentications: listAuthenticationsDefinition,
74
62
  context: {
@@ -77,7 +65,7 @@ export const listAuthenticationsPlugin = ({ context }) => {
77
65
  categories: ["authentication"],
78
66
  type: "list",
79
67
  itemType: "Authentication",
80
- inputSchema: ListAuthenticationsSchema,
68
+ inputSchema: ListAuthenticationsQuerySchema,
81
69
  outputSchema: AuthenticationItemSchema,
82
70
  resolvers: {
83
71
  appKey: appKeyResolver,