@zapier/zapier-sdk 0.37.0 → 0.38.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.
Files changed (52) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +56 -49
  3. package/dist/index.cjs +145 -41
  4. package/dist/index.d.mts +38 -7
  5. package/dist/index.d.ts +1 -0
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +2 -0
  8. package/dist/index.mjs +145 -42
  9. package/dist/plugins/capabilities/index.d.ts +22 -0
  10. package/dist/plugins/capabilities/index.d.ts.map +1 -0
  11. package/dist/plugins/capabilities/index.js +76 -0
  12. package/dist/plugins/findFirstConnection/schemas.d.ts +1 -0
  13. package/dist/plugins/findFirstConnection/schemas.d.ts.map +1 -1
  14. package/dist/plugins/findUniqueConnection/schemas.d.ts +1 -0
  15. package/dist/plugins/findUniqueConnection/schemas.d.ts.map +1 -1
  16. package/dist/plugins/listConnections/index.d.ts +2 -1
  17. package/dist/plugins/listConnections/index.d.ts.map +1 -1
  18. package/dist/plugins/listConnections/index.js +10 -3
  19. package/dist/plugins/listConnections/schemas.d.ts +1 -0
  20. package/dist/plugins/listConnections/schemas.d.ts.map +1 -1
  21. package/dist/plugins/listConnections/schemas.js +5 -0
  22. package/dist/plugins/manifest/index.d.ts +1 -0
  23. package/dist/plugins/manifest/index.d.ts.map +1 -1
  24. package/dist/plugins/manifest/index.js +1 -0
  25. package/dist/plugins/manifest/schemas.d.ts +9 -0
  26. package/dist/plugins/manifest/schemas.d.ts.map +1 -1
  27. package/dist/plugins/manifest/schemas.js +9 -0
  28. package/dist/plugins/tables/deleteTable/index.d.ts +2 -1
  29. package/dist/plugins/tables/deleteTable/index.d.ts.map +1 -1
  30. package/dist/plugins/tables/deleteTable/index.js +1 -0
  31. package/dist/plugins/tables/listTables/index.d.ts +2 -1
  32. package/dist/plugins/tables/listTables/index.d.ts.map +1 -1
  33. package/dist/plugins/tables/listTables/index.js +14 -6
  34. package/dist/plugins/tables/listTables/schemas.d.ts +1 -0
  35. package/dist/plugins/tables/listTables/schemas.d.ts.map +1 -1
  36. package/dist/plugins/tables/listTables/schemas.js +5 -1
  37. package/dist/resolvers/connectionId.d.ts.map +1 -1
  38. package/dist/resolvers/connectionId.js +13 -23
  39. package/dist/resolvers/tableId.d.ts.map +1 -1
  40. package/dist/resolvers/tableId.js +17 -6
  41. package/dist/sdk.d.ts +3 -2
  42. package/dist/sdk.d.ts.map +1 -1
  43. package/dist/sdk.js +3 -0
  44. package/dist/types/sdk.d.ts +3 -0
  45. package/dist/types/sdk.d.ts.map +1 -1
  46. package/dist/types/sdk.js +9 -0
  47. package/dist/utils/pagination-utils.d.ts +6 -0
  48. package/dist/utils/pagination-utils.d.ts.map +1 -1
  49. package/dist/utils/pagination-utils.js +8 -0
  50. package/dist/utils/schema-utils.d.ts +6 -1
  51. package/dist/utils/schema-utils.d.ts.map +1 -1
  52. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @zapier/zapier-sdk
2
2
 
3
+ ## 0.38.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 2906101: Default `listConnections` and `listTables` to only return your own items. Gate shared access and table deletion behind boolean flags: `canIncludeSharedConnections`, `canIncludeSharedTables`, `canDeleteTables`. Set via SDK options, `.zapierrc`, CLI flags (`--can-delete-tables`), or env vars (`ZAPIER_CAN_DELETE_TABLES=true`).
8
+
3
9
  ## 0.37.0
4
10
 
5
11
  ### Minor Changes
package/README.md CHANGED
@@ -320,14 +320,17 @@ console.log(emojiData.emoji);
320
320
 
321
321
  The `createZapierSdk(...)` factory function is the main entry point for the SDK. It provides methods for managing connections, listing apps, running actions, and more.
322
322
 
323
- | Name | Type | Required | Default | Possible Values | Description |
324
- | ------------------------ | -------------------------- | -------- | ------- | --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
325
- | `credentials` | `string, object, function` | ❌ | — | — | Authentication credentials. Can be a string (token or API key), a client credentials object ({ clientId, clientSecret }), a PKCE object ({ clientId }), or a function returning any of those. |
326
- | `debug` | `boolean` | ❌ | — | — | Enable debug logging. |
327
- | `baseUrl` | `string` | ❌ | — | — | Base URL for Zapier API endpoints. |
328
- | `trackingBaseUrl` | `string` | ❌ | — | — | Base URL for Zapier tracking endpoints. |
329
- | `maxNetworkRetries` | `number` | ❌ | — | — | Max retries for rate-limited requests (default: 3). |
330
- | `maxNetworkRetryDelayMs` | `number` | ❌ | — | — | Max delay in ms to wait for retry (default: 60000). |
323
+ | Name | Type | Required | Default | Possible Values | Description |
324
+ | ----------------------------- | -------------------------- | -------- | ------- | --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
325
+ | `credentials` | `string, object, function` | ❌ | — | — | Authentication credentials. Can be a string (token or API key), a client credentials object ({ clientId, clientSecret }), a PKCE object ({ clientId }), or a function returning any of those. |
326
+ | `debug` | `boolean` | ❌ | — | — | Enable debug logging. |
327
+ | `baseUrl` | `string` | ❌ | — | — | Base URL for Zapier API endpoints. |
328
+ | `trackingBaseUrl` | `string` | ❌ | — | — | Base URL for Zapier tracking endpoints. |
329
+ | `maxNetworkRetries` | `number` | ❌ | — | — | Max retries for rate-limited requests (default: 3). |
330
+ | `maxNetworkRetryDelayMs` | `number` | ❌ | — | — | Max delay in ms to wait for retry (default: 60000). |
331
+ | `canIncludeSharedConnections` | `boolean` | ❌ | — | — | Allow listing shared connections. |
332
+ | `canIncludeSharedTables` | `boolean` | ❌ | — | — | Allow listing shared tables. |
333
+ | `canDeleteTables` | `boolean` | ❌ | — | — | Allow deleting tables. |
331
334
 
332
335
  ## Named Connections
333
336
 
@@ -862,15 +865,16 @@ Find the first connection matching the criteria
862
865
 
863
866
  **Parameters:**
864
867
 
865
- | Name | Type | Required | Default | Possible Values | Description |
866
- | ------------- | --------- | -------- | ------- | --------------- | ------------------------------------------------------------------------------ |
867
- | `options` | `object` | ✅ | — | — | |
868
- | ↳ `search` | `string` | ❌ | — | — | Search term to filter connections by title |
869
- | ↳ `title` | `string` | ❌ | — | — | Filter connections by exact title match (searches first, then filters locally) |
870
- | ↳ `owner` | `string` | ❌ | — | — | Filter by owner, 'me' for your own connections or a specific user ID |
871
- | ↳ `appKey` | `string` | ❌ | — | — | App key of connections to list (e.g., 'SlackCLIAPI' or slug like 'github') |
872
- | ↳ `accountId` | `string` | ❌ | — | — | Account ID to filter by |
873
- | ↳ `isExpired` | `boolean` | ❌ | — | — | Filter by expired status |
868
+ | Name | Type | Required | Default | Possible Values | Description |
869
+ | ----------------- | --------- | -------- | ------- | --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
870
+ | `options` | `object` | ✅ | — | — | |
871
+ | ↳ `search` | `string` | ❌ | — | — | Search term to filter connections by title |
872
+ | ↳ `title` | `string` | ❌ | — | — | Filter connections by exact title match (searches first, then filters locally) |
873
+ | ↳ `owner` | `string` | ❌ | — | — | Filter by owner, 'me' for your own connections or a specific user ID |
874
+ | ↳ `appKey` | `string` | ❌ | — | — | App key of connections to list (e.g., 'SlackCLIAPI' or slug like 'github') |
875
+ | ↳ `accountId` | `string` | ❌ | — | — | Account ID to filter by |
876
+ | ↳ `includeShared` | `boolean` | ❌ | — | — | Include connections shared with you. By default, only your own connections are returned (owner=me). Set to true to also include shared connections. |
877
+ | ↳ `isExpired` | `boolean` | ❌ | — | — | Filter by expired status |
874
878
 
875
879
  **Returns:** `Promise<ConnectionItem>`
876
880
 
@@ -886,15 +890,16 @@ Find a unique connection matching the criteria
886
890
 
887
891
  **Parameters:**
888
892
 
889
- | Name | Type | Required | Default | Possible Values | Description |
890
- | ------------- | --------- | -------- | ------- | --------------- | ------------------------------------------------------------------------------ |
891
- | `options` | `object` | ✅ | — | — | |
892
- | ↳ `search` | `string` | ❌ | — | — | Search term to filter connections by title |
893
- | ↳ `title` | `string` | ❌ | — | — | Filter connections by exact title match (searches first, then filters locally) |
894
- | ↳ `owner` | `string` | ❌ | — | — | Filter by owner, 'me' for your own connections or a specific user ID |
895
- | ↳ `appKey` | `string` | ❌ | — | — | App key of connections to list (e.g., 'SlackCLIAPI' or slug like 'github') |
896
- | ↳ `accountId` | `string` | ❌ | — | — | Account ID to filter by |
897
- | ↳ `isExpired` | `boolean` | ❌ | — | — | Filter by expired status |
893
+ | Name | Type | Required | Default | Possible Values | Description |
894
+ | ----------------- | --------- | -------- | ------- | --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
895
+ | `options` | `object` | ✅ | — | — | |
896
+ | ↳ `search` | `string` | ❌ | — | — | Search term to filter connections by title |
897
+ | ↳ `title` | `string` | ❌ | — | — | Filter connections by exact title match (searches first, then filters locally) |
898
+ | ↳ `owner` | `string` | ❌ | — | — | Filter by owner, 'me' for your own connections or a specific user ID |
899
+ | ↳ `appKey` | `string` | ❌ | — | — | App key of connections to list (e.g., 'SlackCLIAPI' or slug like 'github') |
900
+ | ↳ `accountId` | `string` | ❌ | — | — | Account ID to filter by |
901
+ | ↳ `includeShared` | `boolean` | ❌ | — | — | Include connections shared with you. By default, only your own connections are returned (owner=me). Set to true to also include shared connections. |
902
+ | ↳ `isExpired` | `boolean` | ❌ | — | — | Filter by expired status |
898
903
 
899
904
  **Returns:** `Promise<ConnectionItem>`
900
905
 
@@ -929,19 +934,20 @@ List available connections with optional filtering
929
934
 
930
935
  **Parameters:**
931
936
 
932
- | Name | Type | Required | Default | Possible Values | Description |
933
- | ----------------- | --------- | -------- | ------- | --------------- | ------------------------------------------------------------------------------ |
934
- | `options` | `object` | ✅ | — | — | |
935
- | ↳ `search` | `string` | ❌ | — | — | Search term to filter connections by title |
936
- | ↳ `title` | `string` | ❌ | — | — | Filter connections by exact title match (searches first, then filters locally) |
937
- | ↳ `owner` | `string` | ❌ | — | — | Filter by owner, 'me' for your own connections or a specific user ID |
938
- | ↳ `appKey` | `string` | ❌ | — | — | App key of connections to list (e.g., 'SlackCLIAPI' or slug like 'github') |
939
- | ↳ `connectionIds` | `array` | ❌ | — | — | List of connection IDs to filter by |
940
- | ↳ `accountId` | `string` | ❌ | — | — | Account ID to filter by |
941
- | ↳ `isExpired` | `boolean` | ❌ | — | — | Filter by expired status |
942
- | ↳ `pageSize` | `number` | ❌ | — | — | Number of connections per page |
943
- | ↳ `maxItems` | `number` | ❌ | — | — | Maximum total items to return across all pages |
944
- | ↳ `cursor` | `string` | ❌ | — | — | Cursor to start from |
937
+ | Name | Type | Required | Default | Possible Values | Description |
938
+ | ----------------- | --------- | -------- | ------- | --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
939
+ | `options` | `object` | ✅ | — | — | |
940
+ | ↳ `search` | `string` | ❌ | — | — | Search term to filter connections by title |
941
+ | ↳ `title` | `string` | ❌ | — | — | Filter connections by exact title match (searches first, then filters locally) |
942
+ | ↳ `owner` | `string` | ❌ | — | — | Filter by owner, 'me' for your own connections or a specific user ID |
943
+ | ↳ `appKey` | `string` | ❌ | — | — | App key of connections to list (e.g., 'SlackCLIAPI' or slug like 'github') |
944
+ | ↳ `connectionIds` | `array` | ❌ | — | — | List of connection IDs to filter by |
945
+ | ↳ `accountId` | `string` | ❌ | — | — | Account ID to filter by |
946
+ | ↳ `includeShared` | `boolean` | ❌ | — | — | Include connections shared with you. By default, only your own connections are returned (owner=me). Set to true to also include shared connections. |
947
+ | ↳ `isExpired` | `boolean` | ❌ | — | — | Filter by expired status |
948
+ | ↳ `pageSize` | `number` | ❌ | — | — | Number of connections per page |
949
+ | ↳ `maxItems` | `number` | ❌ | — | — | Maximum total items to return across all pages |
950
+ | ↳ `cursor` | `string` | ❌ | — | — | Cursor to start from |
945
951
 
946
952
  **Returns:** `Promise<PaginatedResult<ConnectionItem>>`
947
953
 
@@ -1263,16 +1269,17 @@ List tables available to the authenticated user
1263
1269
 
1264
1270
  **Parameters:**
1265
1271
 
1266
- | Name | Type | Required | Default | Possible Values | Description |
1267
- | ------------ | -------- | -------- | ------- | -------------------------------- | --------------------------------------------------------------------------- |
1268
- | `options` | `object` | ✅ | — | — | |
1269
- | ↳ `tableIds` | `array` | ❌ | — | — | Filter by specific table IDs |
1270
- | ↳ `kind` | `string` | ❌ | — | `table`, `virtual_table`, `both` | Filter by table type |
1271
- | ↳ `search` | `string` | ❌ | — | — | Search term to filter tables by name |
1272
- | ↳ `owner` | `string` | ❌ | — | — | Filter by table owner. Use "me" for the current user, or a numeric user ID. |
1273
- | ↳ `pageSize` | `number` | ❌ | — | — | Number of tables per page |
1274
- | ↳ `maxItems` | `number` | ❌ | — | — | Maximum total items to return across all pages |
1275
- | ↳ `cursor` | `string` | ❌ | — | — | Cursor to start from |
1272
+ | Name | Type | Required | Default | Possible Values | Description |
1273
+ | ----------------- | --------- | -------- | ------- | -------------------------------- | -------------------------------------------------------------------------------------------------------------- |
1274
+ | `options` | `object` | ✅ | — | — | |
1275
+ | ↳ `tableIds` | `array` | ❌ | — | — | Filter by specific table IDs |
1276
+ | ↳ `kind` | `string` | ❌ | — | `table`, `virtual_table`, `both` | Filter by table type |
1277
+ | ↳ `search` | `string` | ❌ | — | — | Search term to filter tables by name |
1278
+ | ↳ `owner` | `string` | ❌ | — | — | Filter by table owner. Use "me" for the current user, or a numeric user ID. Requires includeShared to be true. |
1279
+ | ↳ `includeShared` | `boolean` | ❌ | — | — | Include tables shared with you. Without this, only your own tables are returned. |
1280
+ | ↳ `pageSize` | `number` | ❌ | — | — | Number of tables per page |
1281
+ | ↳ `maxItems` | `number` | ❌ | — | — | Maximum total items to return across all pages |
1282
+ | ↳ `cursor` | `string` | ❌ | — | — | Cursor to start from |
1276
1283
 
1277
1284
  **Returns:** `Promise<PaginatedResult<TableItem>>`
1278
1285
 
package/dist/index.cjs CHANGED
@@ -1075,6 +1075,9 @@ function concatPaginated({
1075
1075
  }
1076
1076
  });
1077
1077
  }
1078
+ function toIterable(source) {
1079
+ return { [Symbol.asyncIterator]: () => source[Symbol.asyncIterator]() };
1080
+ }
1078
1081
 
1079
1082
  // src/utils/validation.ts
1080
1083
  var validate = (schema, input) => {
@@ -1852,44 +1855,32 @@ var actionKeyResolver = {
1852
1855
 
1853
1856
  // src/resolvers/connectionId.ts
1854
1857
  async function fetchConnections(sdk, resolvedParams) {
1855
- const listOptions = {
1856
- maxItems: 1e3
1857
- };
1858
- if (resolvedParams.appKey) {
1859
- listOptions.appKey = resolvedParams.appKey;
1860
- }
1861
- const myConnections = await sdk.listConnections({
1862
- ...listOptions,
1863
- owner: "me"
1864
- });
1865
- const allConnections = await sdk.listConnections(listOptions);
1866
- const otherConnections = allConnections.data.filter(
1867
- (connection) => !myConnections.data.some(
1868
- (myConnection) => myConnection.id === connection.id
1869
- )
1858
+ const context = sdk.getContext();
1859
+ const includeShared = await context.hasCapability?.(
1860
+ "canIncludeSharedConnections"
1861
+ );
1862
+ return toIterable(
1863
+ sdk.listConnections({
1864
+ appKey: resolvedParams.appKey,
1865
+ includeShared: includeShared || void 0
1866
+ })
1870
1867
  );
1871
- return [...myConnections.data, ...otherConnections];
1872
1868
  }
1873
1869
  function promptForConnection(connections, params) {
1874
1870
  return {
1875
1871
  type: "list",
1876
1872
  name: "connectionId",
1877
1873
  message: params.appKey ? `Select connection for ${params.appKey}:` : "Select connection:",
1878
- choices: [
1879
- ...connections.map((connection) => ({
1880
- name: `${connection.title || connection.label || "Connection"} (ID: ${connection.id})`,
1881
- value: connection.id
1882
- })),
1883
- {
1884
- name: "-> Skip connection (may fail)",
1885
- value: null
1886
- }
1887
- ]
1874
+ choices: connections.map((connection) => ({
1875
+ name: `${connection.title || connection.label || "Connection"} (ID: ${connection.id})`,
1876
+ value: connection.id
1877
+ }))
1888
1878
  };
1889
1879
  }
1890
1880
  var connectionIdResolver = {
1891
1881
  type: "dynamic",
1892
1882
  depends: ["appKey"],
1883
+ requireCapabilities: ["canIncludeSharedConnections"],
1893
1884
  tryResolveWithoutPrompt: async (sdk, params) => {
1894
1885
  if (!params.appKey) return null;
1895
1886
  try {
@@ -1907,6 +1898,7 @@ var connectionIdResolver = {
1907
1898
  var connectionIdGenericResolver = {
1908
1899
  type: "dynamic",
1909
1900
  depends: [],
1901
+ requireCapabilities: ["canIncludeSharedConnections"],
1910
1902
  fetch: fetchConnections,
1911
1903
  prompt: promptForConnection
1912
1904
  };
@@ -2030,11 +2022,24 @@ var clientIdResolver = {
2030
2022
  // src/resolvers/tableId.ts
2031
2023
  var tableIdResolver = {
2032
2024
  type: "dynamic",
2033
- fetch: (sdk) => {
2034
- return concatPaginated({
2035
- sources: [() => sdk.listTables({ owner: "me" }), () => sdk.listTables()],
2036
- dedupe: (table) => table.id
2037
- });
2025
+ requireCapabilities: ["canIncludeSharedTables"],
2026
+ fetch: async (sdk) => {
2027
+ const context = sdk.getContext();
2028
+ const includeShared = await context.hasCapability?.(
2029
+ "canIncludeSharedTables"
2030
+ );
2031
+ if (includeShared) {
2032
+ return toIterable(
2033
+ concatPaginated({
2034
+ sources: [
2035
+ () => sdk.listTables(),
2036
+ () => sdk.listTables({ includeShared: true })
2037
+ ],
2038
+ dedupe: (table) => table.id
2039
+ })
2040
+ );
2041
+ }
2042
+ return toIterable(sdk.listTables());
2038
2043
  },
2039
2044
  prompt: (tables) => ({
2040
2045
  type: "list",
@@ -3130,6 +3135,10 @@ var ListConnectionsQuerySchema = connections.ListConnectionsQuerySchema.omit({
3130
3135
  ),
3131
3136
  // camelCase account ID
3132
3137
  accountId: zod.z.string().optional().describe("Account ID to filter by"),
3138
+ // Include shared connections (overrides default owner=me filter)
3139
+ includeShared: zod.z.boolean().optional().describe(
3140
+ "Include connections shared with you. By default, only your own connections are returned (owner=me). Set to true to also include shared connections."
3141
+ ),
3133
3142
  // camelCase isExpired
3134
3143
  isExpired: zod.z.boolean().optional().describe("Filter by expired status"),
3135
3144
  // Override pageSize to make optional
@@ -3169,6 +3178,9 @@ var ConnectionItemSchema = withFormatter(connections.ConnectionItemSchema, {
3169
3178
  // src/plugins/listConnections/index.ts
3170
3179
  var listConnectionsPlugin = ({ context }) => {
3171
3180
  async function listConnectionsPage(options) {
3181
+ if (options.includeShared) {
3182
+ await context.checkCapability("canIncludeSharedConnections");
3183
+ }
3172
3184
  const { api, getVersionedImplementationId } = context;
3173
3185
  const searchParams = {};
3174
3186
  if (options.pageSize !== void 0) {
@@ -3199,8 +3211,14 @@ var listConnectionsPlugin = ({ context }) => {
3199
3211
  if (options.accountId) {
3200
3212
  searchParams.account_id = options.accountId;
3201
3213
  }
3202
- if (options.owner) {
3203
- searchParams.owner = options.owner;
3214
+ if (options.owner && options.owner !== "me" && !options.includeShared) {
3215
+ throw new ZapierValidationError(
3216
+ 'The "owner" option requires "includeShared" to be true. Without includeShared, only your own connections are returned.'
3217
+ );
3218
+ }
3219
+ const owner = options.includeShared ? options.owner : "me";
3220
+ if (owner) {
3221
+ searchParams.owner = owner;
3204
3222
  }
3205
3223
  if (options.isExpired !== void 0) {
3206
3224
  searchParams.is_expired = options.isExpired.toString();
@@ -4122,6 +4140,9 @@ var ManifestSchema = zod.z.object({
4122
4140
  })
4123
4141
  ).optional(),
4124
4142
  actions: zod.z.record(zod.z.string(), ActionEntrySchema).optional().describe("Saved action configurations with their schemas"),
4143
+ canIncludeSharedConnections: zod.z.boolean().optional().describe("Allow listing shared connections"),
4144
+ canIncludeSharedTables: zod.z.boolean().optional().describe("Allow listing shared tables"),
4145
+ canDeleteTables: zod.z.boolean().optional().describe("Allow deleting tables"),
4125
4146
  connections: ConnectionsMapSchema.optional().describe(
4126
4147
  "Named connections map. Keys are connection names, values contain a connectionId."
4127
4148
  )
@@ -4477,6 +4498,7 @@ var manifestPlugin = (params) => {
4477
4498
  };
4478
4499
  return {
4479
4500
  context: {
4501
+ getResolvedManifest,
4480
4502
  getVersionedImplementationId,
4481
4503
  resolveAppKeys: async ({ appKeys }) => resolveAppKeys({
4482
4504
  appKeys,
@@ -5880,6 +5902,69 @@ var connectionsPlugin = (params) => {
5880
5902
  }
5881
5903
  };
5882
5904
  };
5905
+
5906
+ // src/plugins/capabilities/index.ts
5907
+ function toDescription(key) {
5908
+ const words = key.replace(/^can/, "").replace(/([A-Z])/g, " $1").trim().toLowerCase();
5909
+ return `To ${words}`;
5910
+ }
5911
+ function toEnvVar(key) {
5912
+ return "ZAPIER_" + key.replace(/([A-Z])/g, "_$1").toUpperCase();
5913
+ }
5914
+ function toCliFlag(key) {
5915
+ return "--" + key.replace(/([A-Z])/g, "-$1").toLowerCase();
5916
+ }
5917
+ function buildCapabilityMessage(key) {
5918
+ return [
5919
+ `${toDescription(key)}, use ${toCliFlag(key)} in the CLI,`,
5920
+ `set ${key}: true in SDK options or .zapierrc,`,
5921
+ `or set ${toEnvVar(key)}=true.`
5922
+ ].join(" ");
5923
+ }
5924
+ var GATED_FLAGS = [
5925
+ "canIncludeSharedConnections",
5926
+ "canIncludeSharedTables",
5927
+ "canDeleteTables"
5928
+ ];
5929
+ function isEnabledByEnv(key) {
5930
+ if (typeof process === "undefined") return void 0;
5931
+ const value = process.env[toEnvVar(key)];
5932
+ if (value === void 0) return void 0;
5933
+ if (value === "true" || value === "1") return true;
5934
+ if (value === "false" || value === "0") return false;
5935
+ return void 0;
5936
+ }
5937
+ var capabilitiesPlugin = ({ context }) => {
5938
+ const options = context.options ?? {};
5939
+ let cached;
5940
+ async function resolveFlags() {
5941
+ if (cached) return cached;
5942
+ const manifest = await context.getResolvedManifest();
5943
+ cached = {};
5944
+ for (const flag of GATED_FLAGS) {
5945
+ cached[flag] = Boolean(
5946
+ options[flag] ?? isEnabledByEnv(flag) ?? manifest?.[flag]
5947
+ );
5948
+ }
5949
+ return cached;
5950
+ }
5951
+ return {
5952
+ context: {
5953
+ checkCapability: async (key) => {
5954
+ const flags = await resolveFlags();
5955
+ if (flags[key]) return;
5956
+ throw new ZapierConfigurationError(
5957
+ buildCapabilityMessage(key) + " (If you are an AI agent, you MUST NOT retry. Ask the user if they want to enable this.)",
5958
+ { configType: key }
5959
+ );
5960
+ },
5961
+ hasCapability: async (key) => {
5962
+ const flags = await resolveFlags();
5963
+ return flags[key];
5964
+ }
5965
+ }
5966
+ };
5967
+ };
5883
5968
  var TableApiItemSchema = zod.z.object({
5884
5969
  id: zod.z.string(),
5885
5970
  name: zod.z.string(),
@@ -5914,7 +5999,10 @@ var ListTablesOptionsSchema = zod.z.object({
5914
5999
  kind: zod.z.enum(["table", "virtual_table", "both"]).optional().describe("Filter by table type"),
5915
6000
  search: zod.z.string().optional().describe("Search term to filter tables by name"),
5916
6001
  owner: zod.z.string().optional().describe(
5917
- 'Filter by table owner. Use "me" for the current user, or a numeric user ID.'
6002
+ 'Filter by table owner. Use "me" for the current user, or a numeric user ID. Requires includeShared to be true.'
6003
+ ),
6004
+ includeShared: zod.z.boolean().optional().describe(
6005
+ "Include tables shared with you. Without this, only your own tables are returned."
5918
6006
  ),
5919
6007
  pageSize: zod.z.number().min(1).optional().describe("Number of tables per page"),
5920
6008
  maxItems: zod.z.number().min(1).optional().describe("Maximum total items to return across all pages"),
@@ -5936,6 +6024,9 @@ function extractNextCursor(links) {
5936
6024
  }
5937
6025
  var listTablesPlugin = ({ context }) => {
5938
6026
  async function listTablesPage(options) {
6027
+ if (options.includeShared) {
6028
+ await context.checkCapability("canIncludeSharedTables");
6029
+ }
5939
6030
  const { api } = context;
5940
6031
  const searchParams = {};
5941
6032
  if (options.pageSize !== void 0) {
@@ -5950,15 +6041,23 @@ var listTablesPlugin = ({ context }) => {
5950
6041
  if (options?.search) {
5951
6042
  searchParams.q = options.search;
5952
6043
  }
5953
- if (options?.owner) {
5954
- let ownerId = options.owner;
5955
- if (ownerId === "me") {
6044
+ if (options?.owner && options.owner !== "me" && !options.includeShared) {
6045
+ throw new ZapierValidationError(
6046
+ 'The "owner" option requires "includeShared" to be true. Without includeShared, only your own tables are returned.'
6047
+ );
6048
+ }
6049
+ const owner = options.includeShared ? options.owner : "me";
6050
+ if (owner) {
6051
+ if (owner === "me") {
5956
6052
  const profile = await api.get("/zapier/api/v4/profile/", {
5957
6053
  authRequired: true
5958
6054
  });
5959
- ownerId = String(profile.id);
6055
+ searchParams.owner_customuser_id = String(
6056
+ profile.id
6057
+ );
6058
+ } else {
6059
+ searchParams.owner_customuser_id = owner;
5960
6060
  }
5961
- searchParams.owner_customuser_id = ownerId;
5962
6061
  }
5963
6062
  if (options.cursor) {
5964
6063
  searchParams.offset = options.cursor;
@@ -6152,6 +6251,7 @@ var DeleteTableOptionsSchema = zod.z.object({
6152
6251
  // src/plugins/tables/deleteTable/index.ts
6153
6252
  var deleteTablePlugin = ({ context }) => {
6154
6253
  async function deleteTable(options) {
6254
+ await context.checkCapability("canDeleteTables");
6155
6255
  const { api } = context;
6156
6256
  await api.delete(`/tables/api/v1/tables/${options.tableId}`, void 0, {
6157
6257
  customErrorHandler: ({ status }) => {
@@ -7561,7 +7661,7 @@ function getCpuTime() {
7561
7661
  }
7562
7662
 
7563
7663
  // src/plugins/eventEmission/builders.ts
7564
- var SDK_VERSION = "0.37.0";
7664
+ var SDK_VERSION = "0.38.0";
7565
7665
  function createBaseEvent(context = {}) {
7566
7666
  return {
7567
7667
  event_id: generateEventId(),
@@ -8054,7 +8154,7 @@ function createSdk(options = {}, initialSdk = {}, initialContext = { meta: {} })
8054
8154
  };
8055
8155
  }
8056
8156
  function createZapierSdkWithoutRegistry(options = {}) {
8057
- return createSdk(options).addPlugin(eventEmissionPlugin).addPlugin(apiPlugin).addPlugin(manifestPlugin).addPlugin(connectionsPlugin).addPlugin(listAppsPlugin).addPlugin(getAppPlugin).addPlugin(listActionsPlugin).addPlugin(getActionPlugin).addPlugin(listInputFieldsPlugin).addPlugin(getInputFieldsSchemaPlugin).addPlugin(listInputFieldChoicesPlugin).addPlugin(runActionPlugin).addPlugin(listConnectionsPlugin).addPlugin(getConnectionPlugin).addPlugin(findFirstConnectionPlugin).addPlugin(findUniqueConnectionPlugin).addPlugin(listAuthenticationsPlugin).addPlugin(getAuthenticationPlugin).addPlugin(findFirstAuthenticationPlugin).addPlugin(findUniqueAuthenticationPlugin).addPlugin(listClientCredentialsPlugin).addPlugin(createClientCredentialsPlugin).addPlugin(deleteClientCredentialsPlugin).addPlugin(fetchPlugin).addPlugin(requestPlugin).addPlugin(listTablesPlugin).addPlugin(getTablePlugin).addPlugin(deleteTablePlugin).addPlugin(createTablePlugin).addPlugin(listTableFieldsPlugin).addPlugin(createTableFieldsPlugin).addPlugin(deleteTableFieldsPlugin).addPlugin(getTableRecordPlugin).addPlugin(listTableRecordsPlugin).addPlugin(createTableRecordsPlugin).addPlugin(deleteTableRecordsPlugin).addPlugin(updateTableRecordsPlugin).addPlugin(appsPlugin).addPlugin(getProfilePlugin);
8157
+ return createSdk(options).addPlugin(eventEmissionPlugin).addPlugin(apiPlugin).addPlugin(manifestPlugin).addPlugin(capabilitiesPlugin).addPlugin(connectionsPlugin).addPlugin(listAppsPlugin).addPlugin(getAppPlugin).addPlugin(listActionsPlugin).addPlugin(getActionPlugin).addPlugin(listInputFieldsPlugin).addPlugin(getInputFieldsSchemaPlugin).addPlugin(listInputFieldChoicesPlugin).addPlugin(runActionPlugin).addPlugin(listConnectionsPlugin).addPlugin(getConnectionPlugin).addPlugin(findFirstConnectionPlugin).addPlugin(findUniqueConnectionPlugin).addPlugin(listAuthenticationsPlugin).addPlugin(getAuthenticationPlugin).addPlugin(findFirstAuthenticationPlugin).addPlugin(findUniqueAuthenticationPlugin).addPlugin(listClientCredentialsPlugin).addPlugin(createClientCredentialsPlugin).addPlugin(deleteClientCredentialsPlugin).addPlugin(fetchPlugin).addPlugin(requestPlugin).addPlugin(listTablesPlugin).addPlugin(getTablePlugin).addPlugin(deleteTablePlugin).addPlugin(createTablePlugin).addPlugin(listTableFieldsPlugin).addPlugin(createTableFieldsPlugin).addPlugin(deleteTableFieldsPlugin).addPlugin(getTableRecordPlugin).addPlugin(listTableRecordsPlugin).addPlugin(createTableRecordsPlugin).addPlugin(deleteTableRecordsPlugin).addPlugin(updateTableRecordsPlugin).addPlugin(appsPlugin).addPlugin(getProfilePlugin);
8058
8158
  }
8059
8159
  function createZapierSdk(options = {}) {
8060
8160
  return createZapierSdkWithoutRegistry(options).addPlugin(registryPlugin);
@@ -8083,6 +8183,9 @@ var BaseSdkOptionsSchema = zod.z.object({
8083
8183
  onEvent: zod.z.custom().optional().meta({ internal: true }),
8084
8184
  fetch: zod.z.custom().optional().meta({ internal: true }),
8085
8185
  eventEmission: zod.z.custom().optional().meta({ internal: true }),
8186
+ canIncludeSharedConnections: zod.z.boolean().optional().describe("Allow listing shared connections."),
8187
+ canIncludeSharedTables: zod.z.boolean().optional().describe("Allow listing shared tables."),
8188
+ canDeleteTables: zod.z.boolean().optional().describe("Allow deleting tables."),
8086
8189
  // Deprecated
8087
8190
  token: zod.z.string().optional().meta({ deprecated: true })
8088
8191
  // Use credentials instead
@@ -8144,6 +8247,7 @@ exports.authenticationIdGenericResolver = connectionIdGenericResolver;
8144
8247
  exports.authenticationIdResolver = connectionIdResolver;
8145
8248
  exports.batch = batch;
8146
8249
  exports.buildApplicationLifecycleEvent = buildApplicationLifecycleEvent;
8250
+ exports.buildCapabilityMessage = buildCapabilityMessage;
8147
8251
  exports.buildErrorEvent = buildErrorEvent;
8148
8252
  exports.buildErrorEventWithContext = buildErrorEventWithContext;
8149
8253
  exports.buildMethodCalledEvent = buildMethodCalledEvent;