@zapier/zapier-sdk 0.84.2 → 0.84.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.cjs CHANGED
@@ -203,7 +203,8 @@ function getCoreErrorCause(value) {
203
203
  var CURSOR_VERSION = 1;
204
204
  var CURSOR_SOURCE = {
205
205
  API: "api",
206
- SDK: "sdk"
206
+ SDK: "sdk",
207
+ CONCAT: "concat"
207
208
  };
208
209
  function encodeBase64(str) {
209
210
  return btoa(
@@ -387,10 +388,32 @@ async function* paginateBuffered(pageFunction, pageOptions) {
387
388
  }
388
389
  }
389
390
  var paginate = paginateBuffered;
391
+ function encodeConcatCursor(index, cursor) {
392
+ const envelope = {
393
+ v: CURSOR_VERSION,
394
+ source: CURSOR_SOURCE.CONCAT,
395
+ index,
396
+ cursor
397
+ };
398
+ return encodeBase64(JSON.stringify(envelope));
399
+ }
400
+ function decodeConcatCursor(incoming) {
401
+ if (!incoming) {
402
+ return { index: 0, cursor: void 0 };
403
+ }
404
+ try {
405
+ const envelope = JSON.parse(decodeBase64(incoming));
406
+ if (envelope.v === CURSOR_VERSION && envelope.source === CURSOR_SOURCE.CONCAT && typeof envelope.index === "number") {
407
+ return { index: envelope.index, cursor: envelope.cursor };
408
+ }
409
+ } catch {
410
+ }
411
+ return { index: 0, cursor: incoming };
412
+ }
390
413
  function concatPaginated({
391
414
  sources,
392
- dedupe,
393
- pageSize = 100
415
+ pageSize = 100,
416
+ cursor
394
417
  }) {
395
418
  if (sources.length === 0) {
396
419
  const empty = { data: [] };
@@ -400,40 +423,24 @@ function concatPaginated({
400
423
  }
401
424
  });
402
425
  }
403
- let sourceIndex = 0;
404
- let currentIterator = null;
405
- const seen = /* @__PURE__ */ new Set();
406
- const pageFunction = async (_options) => {
407
- while (sourceIndex < sources.length) {
408
- if (!currentIterator) {
409
- const result = sources[sourceIndex]();
410
- currentIterator = result[Symbol.asyncIterator]();
411
- }
412
- const next = await currentIterator.next();
413
- if (next.done) {
414
- sourceIndex++;
415
- currentIterator = null;
426
+ const pageFunction = async (options) => {
427
+ let { index, cursor: sourceCursor } = decodeConcatCursor(options.cursor);
428
+ while (index < sources.length) {
429
+ const page = await sources[index]({ cursor: sourceCursor });
430
+ const hasMoreInSource = page.nextCursor != null;
431
+ if (page.data.length === 0 && !hasMoreInSource) {
432
+ index++;
433
+ sourceCursor = void 0;
416
434
  continue;
417
435
  }
418
- let items = next.value.data;
419
- if (dedupe) {
420
- if (sourceIndex > 0) {
421
- items = items.filter((item) => !seen.has(dedupe(item)));
422
- }
423
- for (const item of items) {
424
- seen.add(dedupe(item));
425
- }
426
- }
427
- const hasMoreInSource = next.value.nextCursor != null;
428
- const hasMoreSources = sourceIndex < sources.length - 1;
429
436
  return {
430
- data: items,
431
- nextCursor: hasMoreInSource || hasMoreSources ? "__has_more__" : void 0
437
+ data: page.data,
438
+ nextCursor: hasMoreInSource ? encodeConcatCursor(index, page.nextCursor) : index < sources.length - 1 ? encodeConcatCursor(index + 1, void 0) : void 0
432
439
  };
433
440
  }
434
441
  return { data: [] };
435
442
  };
436
- const iterator = paginateBuffered(pageFunction, { pageSize });
443
+ const iterator = paginateBuffered(pageFunction, { pageSize, cursor });
437
444
  const firstPagePromise = iterator.next().then((result) => {
438
445
  if (result.done) {
439
446
  return { data: [] };
@@ -1285,6 +1292,7 @@ function defineResolver(config) {
1285
1292
  getContext: config.getContext,
1286
1293
  listItems: config.listItems,
1287
1294
  prompt: config.prompt,
1295
+ validate: config.validate,
1288
1296
  tryResolveWithoutPrompt: config.tryResolveWithoutPrompt,
1289
1297
  tryResolveFromSearch: config.tryResolveFromSearch
1290
1298
  };
@@ -1930,6 +1938,7 @@ function bindResolver(resolver, plugins) {
1930
1938
  const {
1931
1939
  getContext: getContext2,
1932
1940
  listItems,
1941
+ validate,
1933
1942
  tryResolveWithoutPrompt,
1934
1943
  tryResolveFromSearch
1935
1944
  } = resolver;
@@ -1943,6 +1952,9 @@ function bindResolver(resolver, plugins) {
1943
1952
  };
1944
1953
  if (getContext2)
1945
1954
  bound.getContext = ({ input }) => getContext2({ imports, input });
1955
+ if (validate) {
1956
+ bound.validate = ({ value, input, context }) => validate({ imports, value, input, context });
1957
+ }
1946
1958
  if (tryResolveWithoutPrompt) {
1947
1959
  bound.tryResolveWithoutPrompt = ({ input }) => tryResolveWithoutPrompt({ imports, input });
1948
1960
  }
@@ -2611,14 +2623,14 @@ function coerce(leaf, raw) {
2611
2623
  }
2612
2624
  async function validationError(leaf, value, state) {
2613
2625
  if (leaf.resolver?.type !== "dynamic") return null;
2626
+ const validate = leaf.resolver.validate;
2627
+ if (!validate) return null;
2614
2628
  const context = await resolveContext(leaf, state.resolved);
2615
- const config = leaf.resolver.prompt?.({
2616
- items: state.listing?.items ?? [],
2629
+ const verdict = await validate({
2630
+ value,
2617
2631
  input: mergeInput(state.resolved, leaf.extraInput),
2618
2632
  context
2619
2633
  });
2620
- if (!config?.validate) return null;
2621
- const verdict = config.validate(value);
2622
2634
  if (verdict === true) return null;
2623
2635
  return typeof verdict === "string" ? verdict : `${leaf.name}: invalid value`;
2624
2636
  }
@@ -2744,20 +2756,36 @@ async function resolveContext(leaf, input) {
2744
2756
  input: mergeInput(input, leaf.extraInput)
2745
2757
  });
2746
2758
  }
2747
- async function fetchListing(leaf, input, opts = {}) {
2759
+ function firstPagePosition(opts = {}) {
2760
+ return {
2761
+ ...opts.search !== void 0 ? { search: opts.search } : {},
2762
+ pageCursor: null,
2763
+ previousCursors: [],
2764
+ generation: opts.generation ?? 0
2765
+ };
2766
+ }
2767
+ async function fetchListing(leaf, input, position, context) {
2768
+ if (leaf.resolver?.type === "dynamic" && leaf.resolver.inputType === "search" && position.search === void 0) {
2769
+ return { position, items: [] };
2770
+ }
2748
2771
  const page = await firstPage(
2749
2772
  leaf.resolver?.type === "dynamic" ? leaf.resolver.listItems({
2750
2773
  input: mergeInput(input, leaf.extraInput),
2751
- context: opts.context,
2752
- search: opts.search,
2753
- cursor: opts.cursor
2774
+ context,
2775
+ search: position.search,
2776
+ cursor: position.pageCursor ?? void 0
2754
2777
  }) : void 0
2755
2778
  );
2756
2779
  return {
2757
- items: [...opts.priorItems ?? [], ...page.data],
2758
- cursor: page.nextCursor,
2759
- search: opts.search,
2760
- exhausted: page.nextCursor == null
2780
+ position,
2781
+ items: page.data,
2782
+ ...page.nextCursor != null ? { nextCursor: page.nextCursor } : {}
2783
+ };
2784
+ }
2785
+ function toPagination(page) {
2786
+ return {
2787
+ position: page.position,
2788
+ ...page.nextCursor !== void 0 ? { nextCursor: page.nextCursor } : {}
2761
2789
  };
2762
2790
  }
2763
2791
  function toChoice(c) {
@@ -2777,23 +2805,32 @@ var AFFORDANCE = {
2777
2805
  description: "Filter the options by a search term",
2778
2806
  supply: "term"
2779
2807
  },
2780
- more: { action: "more", description: "Load more options" },
2808
+ nextPage: {
2809
+ action: "next_page",
2810
+ description: "Fetch the next page of options"
2811
+ },
2812
+ previousPage: {
2813
+ action: "previous_page",
2814
+ description: "Return to the previous page of options"
2815
+ },
2781
2816
  skip: { action: "skip", description: "Omit this optional parameter" },
2782
2817
  add: { action: "add", description: "Add another item" },
2783
2818
  done: { action: "done", description: "Finish the list" },
2784
2819
  retry: { action: "retry", description: "Retry loading the options" },
2785
2820
  cancel: { action: "cancel", description: "Cancel resolution" }
2786
2821
  };
2787
- function selectActions(leaf, listing, multiple) {
2822
+ function selectActions(leaf, page, multiple) {
2788
2823
  const searchMode = leaf.resolver?.type === "dynamic" && leaf.resolver.inputType === "search";
2789
- if (searchMode && listing.search === void 0 && listing.items.length === 0) {
2824
+ if (searchMode && page.position.search === void 0 && page.items.length === 0) {
2790
2825
  const actions2 = multiple ? [AFFORDANCE.search] : [AFFORDANCE.search, AFFORDANCE.custom];
2791
2826
  if (!leaf.required) actions2.push(AFFORDANCE.skip);
2792
2827
  return actions2;
2793
2828
  }
2794
2829
  const actions = multiple ? [AFFORDANCE.choose] : [AFFORDANCE.choose, AFFORDANCE.custom];
2795
2830
  if (searchMode) actions.push(AFFORDANCE.search);
2796
- if (listing.cursor) actions.push(AFFORDANCE.more);
2831
+ if (page.nextCursor) actions.push(AFFORDANCE.nextPage);
2832
+ if (page.position.previousCursors.length > 0)
2833
+ actions.push(AFFORDANCE.previousPage);
2797
2834
  if (!leaf.required) actions.push(AFFORDANCE.skip);
2798
2835
  return actions;
2799
2836
  }
@@ -2801,16 +2838,17 @@ function labeledMessage(leaf) {
2801
2838
  if (!leaf.label) return void 0;
2802
2839
  return `${leaf.label} (${leaf.required ? "required" : "optional"}):`;
2803
2840
  }
2804
- function selectQuestion(leaf, input, listing, context) {
2841
+ function selectQuestion(leaf, path, input, page, context) {
2805
2842
  const resolver = leaf.resolver?.type === "dynamic" ? leaf.resolver : void 0;
2806
2843
  const config = resolver?.prompt?.({
2807
- items: listing.items,
2844
+ items: page.items,
2808
2845
  input: mergeInput(input, leaf.extraInput),
2809
2846
  context
2810
2847
  });
2811
2848
  const multiple = config?.type === "checkbox";
2812
2849
  return {
2813
2850
  type: "select",
2851
+ path,
2814
2852
  // A labeled field's title beats the resolver's message: per-field
2815
2853
  // resolvers are shared across fields (one choices-fetcher for every
2816
2854
  // field), so only the leaf knows which field is being asked.
@@ -2818,9 +2856,13 @@ function selectQuestion(leaf, input, listing, context) {
2818
2856
  choices: (config?.choices ?? []).map(toChoice),
2819
2857
  ...multiple ? { multiple: true } : {},
2820
2858
  ...config?.notes?.length ? { notes: config.notes } : {},
2821
- ...listing.search !== void 0 ? { search: listing.search } : {},
2859
+ ...page.position.search !== void 0 ? { search: page.position.search } : {},
2822
2860
  ...resolver?.placeholder ? { placeholder: resolver.placeholder } : {},
2823
- actions: selectActions(leaf, listing, multiple)
2861
+ page: {
2862
+ generation: page.position.generation,
2863
+ index: page.position.previousCursors.length
2864
+ },
2865
+ actions: selectActions(leaf, page, multiple)
2824
2866
  };
2825
2867
  }
2826
2868
  function toControllerError(error) {
@@ -2842,6 +2884,7 @@ function failedResult(state, name, error) {
2842
2884
  error: toControllerError(error),
2843
2885
  question: {
2844
2886
  type: "select",
2887
+ path: state.current ?? [],
2845
2888
  message: `Could not load options for ${name}.`,
2846
2889
  choices: [],
2847
2890
  actions: [AFFORDANCE.retry, AFFORDANCE.cancel]
@@ -2849,27 +2892,15 @@ function failedResult(state, name, error) {
2849
2892
  }
2850
2893
  };
2851
2894
  }
2852
- async function buildQuestion(leaf, input) {
2895
+ async function buildQuestion(leaf, path, input) {
2853
2896
  const optional = !leaf.required;
2854
2897
  const resolver = leaf.resolver;
2855
2898
  if (resolver?.type === "dynamic") {
2856
2899
  const context = await resolveContext(leaf, input);
2857
- if (resolver.inputType === "search") {
2858
- const listing2 = {
2859
- items: [],
2860
- cursor: void 0,
2861
- search: void 0,
2862
- exhausted: true
2863
- };
2864
- return {
2865
- question: selectQuestion(leaf, input, listing2, context),
2866
- listing: listing2
2867
- };
2868
- }
2869
- const listing = await fetchListing(leaf, input, { context });
2900
+ const page = await fetchListing(leaf, input, firstPagePosition(), context);
2870
2901
  return {
2871
- question: selectQuestion(leaf, input, listing, context),
2872
- listing
2902
+ question: selectQuestion(leaf, path, input, page, context),
2903
+ pagination: toPagination(page)
2873
2904
  };
2874
2905
  }
2875
2906
  if (leaf.staticChoices) {
@@ -2878,6 +2909,7 @@ async function buildQuestion(leaf, input) {
2878
2909
  return {
2879
2910
  question: {
2880
2911
  type: "select",
2912
+ path,
2881
2913
  message: `Select ${leaf.name}:`,
2882
2914
  choices: leaf.staticChoices,
2883
2915
  actions: actions2
@@ -2891,6 +2923,7 @@ async function buildQuestion(leaf, input) {
2891
2923
  return {
2892
2924
  question: {
2893
2925
  type: "input",
2926
+ path,
2894
2927
  // The optional marker makes Enter-to-pass discoverable on a bare
2895
2928
  // parameter; a labeled field carries its marker via labeledMessage.
2896
2929
  message: labeledMessage(leaf) ?? `Enter ${leaf.name}${optional ? " (optional)" : ""}:`,
@@ -2905,6 +2938,7 @@ function collectionQuestion(t) {
2905
2938
  if (t.count >= t.min) actions.push(AFFORDANCE.done);
2906
2939
  return {
2907
2940
  type: "collection",
2941
+ path: t.path,
2908
2942
  message: `Add ${t.path[t.path.length - 1]}[${t.count}]?`,
2909
2943
  container: "array",
2910
2944
  count: t.count,
@@ -2918,6 +2952,7 @@ function collectionQuestion(t) {
2918
2952
  function objectGateQuestion(path) {
2919
2953
  return {
2920
2954
  type: "collection",
2955
+ path,
2921
2956
  message: `Add ${path[path.length - 1]}?`,
2922
2957
  container: "object",
2923
2958
  actions: [
@@ -2929,9 +2964,10 @@ function objectGateQuestion(path) {
2929
2964
  ]
2930
2965
  };
2931
2966
  }
2932
- function optionalsGateQuestion(pending) {
2967
+ function optionalsGateQuestion(path, pending) {
2933
2968
  return {
2934
2969
  type: "collection",
2970
+ path,
2935
2971
  // The prompt and its context ride separately so a host renders the info
2936
2972
  // line above the confirm without composing any text of its own.
2937
2973
  message: "Would you like to configure optional fields?",
@@ -3079,8 +3115,12 @@ async function askLeaf(state, path, leaf, opts = {}) {
3079
3115
  state.current = path;
3080
3116
  delete state.gate;
3081
3117
  try {
3082
- const { question, listing } = await buildQuestion(leaf, state.resolved);
3083
- state.listing = listing;
3118
+ const { question, pagination } = await buildQuestion(
3119
+ leaf,
3120
+ path,
3121
+ state.resolved
3122
+ );
3123
+ state.pagination = pagination;
3084
3124
  return {
3085
3125
  state,
3086
3126
  result: {
@@ -3090,7 +3130,7 @@ async function askLeaf(state, path, leaf, opts = {}) {
3090
3130
  }
3091
3131
  };
3092
3132
  } catch (error) {
3093
- state.listing = { items: [], exhausted: false };
3133
+ state.pagination = failedPagination(void 0, firstPagePosition());
3094
3134
  return failedResult(state, leaf.name, error);
3095
3135
  }
3096
3136
  }
@@ -3100,13 +3140,13 @@ async function advance(ctx, state) {
3100
3140
  if (!target) {
3101
3141
  delete state.current;
3102
3142
  delete state.gate;
3103
- delete state.listing;
3143
+ delete state.pagination;
3104
3144
  return { state, result: finalize(ctx, state.resolved) };
3105
3145
  }
3106
3146
  if (target.kind === "array") {
3107
3147
  state.current = target.path;
3108
3148
  state.gate = "array";
3109
- delete state.listing;
3149
+ delete state.pagination;
3110
3150
  return {
3111
3151
  state,
3112
3152
  result: { status: "ask", question: collectionQuestion(target) }
@@ -3115,7 +3155,7 @@ async function advance(ctx, state) {
3115
3155
  if (target.kind === "object") {
3116
3156
  state.current = target.path;
3117
3157
  state.gate = "entry";
3118
- delete state.listing;
3158
+ delete state.pagination;
3119
3159
  return {
3120
3160
  state,
3121
3161
  result: { status: "ask", question: objectGateQuestion(target.path) }
@@ -3124,12 +3164,12 @@ async function advance(ctx, state) {
3124
3164
  if (target.kind === "optionals") {
3125
3165
  state.current = target.path;
3126
3166
  state.gate = "optionals";
3127
- delete state.listing;
3167
+ delete state.pagination;
3128
3168
  return {
3129
3169
  state,
3130
3170
  result: {
3131
3171
  status: "ask",
3132
- question: optionalsGateQuestion(target.pending)
3172
+ question: optionalsGateQuestion(target.path, target.pending)
3133
3173
  }
3134
3174
  };
3135
3175
  }
@@ -3180,13 +3220,13 @@ async function step(ctx, prior, action) {
3180
3220
  if (action.type === "cancel") {
3181
3221
  delete state.current;
3182
3222
  delete state.gate;
3183
- delete state.listing;
3223
+ delete state.pagination;
3184
3224
  return { state, result: { status: "cancelled" } };
3185
3225
  }
3186
3226
  const path = state.current;
3187
3227
  if (!path) throw new Error("step called with no outstanding question");
3188
3228
  const leaf = await leafAt(ctx, path, state.resolved);
3189
- if (leaf && (action.type === "search" || action.type === "more" || action.type === "retry")) {
3229
+ if (leaf && (action.type === "search" || action.type === "next_page" || action.type === "previous_page" || action.type === "retry")) {
3190
3230
  return refine(ctx, state, leaf, path, action);
3191
3231
  }
3192
3232
  if (action.type === "add" || action.type === "done") {
@@ -3198,7 +3238,7 @@ async function step(ctx, prior, action) {
3198
3238
  }
3199
3239
  delete state.current;
3200
3240
  delete state.gate;
3201
- delete state.listing;
3241
+ delete state.pagination;
3202
3242
  if (action.type === "done") {
3203
3243
  settle(state, path);
3204
3244
  return advance(ctx, state);
@@ -3227,23 +3267,44 @@ async function step(ctx, prior, action) {
3227
3267
  case "choose":
3228
3268
  case "custom": {
3229
3269
  if (leaf) {
3230
- const error = await validationError(leaf, action.value, state);
3270
+ let error;
3271
+ try {
3272
+ error = await validationError(leaf, action.value, state);
3273
+ } catch (thrown) {
3274
+ return failedResult(state, leaf.name, thrown);
3275
+ }
3231
3276
  if (error) {
3232
- if (state.listing && leaf.resolver?.type === "dynamic") {
3233
- const context = await resolveContext(leaf, state.resolved);
3234
- return {
3235
- state,
3236
- result: {
3237
- status: "ask",
3238
- question: selectQuestion(
3239
- leaf,
3240
- state.resolved,
3241
- state.listing,
3242
- context
3243
- ),
3244
- error
3245
- }
3246
- };
3277
+ if (state.pagination && leaf.resolver?.type === "dynamic") {
3278
+ try {
3279
+ const context = await resolveContext(leaf, state.resolved);
3280
+ const page = await fetchListing(
3281
+ leaf,
3282
+ state.resolved,
3283
+ state.pagination.position,
3284
+ context
3285
+ );
3286
+ state.pagination = toPagination(page);
3287
+ return {
3288
+ state,
3289
+ result: {
3290
+ status: "ask",
3291
+ question: selectQuestion(
3292
+ leaf,
3293
+ path,
3294
+ state.resolved,
3295
+ page,
3296
+ context
3297
+ ),
3298
+ error
3299
+ }
3300
+ };
3301
+ } catch (fetchError) {
3302
+ state.pagination = failedPagination(
3303
+ state.pagination,
3304
+ state.pagination.position
3305
+ );
3306
+ return failedResult(state, leaf.name, fetchError);
3307
+ }
3247
3308
  }
3248
3309
  return askLeaf(state, path, leaf, { error });
3249
3310
  }
@@ -3262,15 +3323,11 @@ async function step(ctx, prior, action) {
3262
3323
  throw new Error(`action "${action.type}" is not supported here`);
3263
3324
  }
3264
3325
  delete state.current;
3265
- delete state.listing;
3326
+ delete state.pagination;
3266
3327
  return advance(ctx, state);
3267
3328
  }
3268
3329
  async function refine(ctx, state, leaf, path, action) {
3269
- const attempt = action.type === "search" ? { search: action.term, cursor: void 0, priorItems: [] } : {
3270
- search: state.listing?.search,
3271
- cursor: state.listing?.cursor,
3272
- priorItems: state.listing?.items ?? []
3273
- };
3330
+ const position = positionAfter(state.pagination, action);
3274
3331
  try {
3275
3332
  if (action.type === "search") {
3276
3333
  const exact = leaf.resolver?.type === "dynamic" ? await leaf.resolver.tryResolveFromSearch?.({
@@ -3280,32 +3337,62 @@ async function refine(ctx, state, leaf, path, action) {
3280
3337
  if (exact) {
3281
3338
  setAtPath(state.resolved, path, coerce(leaf, exact.resolvedValue));
3282
3339
  delete state.current;
3283
- delete state.listing;
3340
+ delete state.pagination;
3284
3341
  return advance(ctx, state);
3285
3342
  }
3286
3343
  }
3287
3344
  const context = await resolveContext(leaf, state.resolved);
3288
- state.listing = await fetchListing(leaf, state.resolved, {
3289
- ...attempt,
3290
- context
3291
- });
3345
+ const page = await fetchListing(leaf, state.resolved, position, context);
3346
+ state.pagination = toPagination(page);
3292
3347
  return {
3293
3348
  state,
3294
3349
  result: {
3295
3350
  status: "ask",
3296
- question: selectQuestion(leaf, state.resolved, state.listing, context)
3351
+ question: selectQuestion(leaf, path, state.resolved, page, context)
3297
3352
  }
3298
3353
  };
3299
3354
  } catch (error) {
3300
- state.listing = {
3301
- items: attempt.priorItems,
3302
- search: attempt.search,
3303
- cursor: attempt.cursor,
3304
- exhausted: false
3305
- };
3355
+ state.pagination = failedPagination(state.pagination, position);
3306
3356
  return failedResult(state, leaf.name, error);
3307
3357
  }
3308
3358
  }
3359
+ function failedPagination(pagination, retryPosition) {
3360
+ return {
3361
+ position: pagination?.position ?? firstPagePosition(),
3362
+ ...pagination?.nextCursor !== void 0 ? { nextCursor: pagination.nextCursor } : {},
3363
+ retryPosition
3364
+ };
3365
+ }
3366
+ function positionAfter(pagination, action) {
3367
+ const current = pagination?.position ?? firstPagePosition();
3368
+ switch (action.type) {
3369
+ case "search":
3370
+ return firstPagePosition({
3371
+ search: action.term,
3372
+ generation: current.generation + 1
3373
+ });
3374
+ case "next_page": {
3375
+ if (pagination?.nextCursor == null) return current;
3376
+ return {
3377
+ ...current.search !== void 0 ? { search: current.search } : {},
3378
+ pageCursor: pagination.nextCursor,
3379
+ previousCursors: [...current.previousCursors, current.pageCursor],
3380
+ generation: current.generation
3381
+ };
3382
+ }
3383
+ case "previous_page": {
3384
+ if (current.previousCursors.length === 0) return current;
3385
+ return {
3386
+ ...current.search !== void 0 ? { search: current.search } : {},
3387
+ pageCursor: current.previousCursors[current.previousCursors.length - 1],
3388
+ previousCursors: current.previousCursors.slice(0, -1),
3389
+ generation: current.generation
3390
+ };
3391
+ }
3392
+ case "retry":
3393
+ return pagination?.retryPosition ?? current;
3394
+ }
3395
+ }
3309
3396
  function toJsonSchema(schema) {
3310
3397
  if (!schema) return void 0;
3311
3398
  try {
@@ -5342,7 +5429,7 @@ function parseDeprecationDate(value) {
5342
5429
  }
5343
5430
 
5344
5431
  // src/sdk-version.ts
5345
- var SDK_VERSION = (typeof process !== "undefined" && process.env ? "0.84.2" : void 0) || "unknown";
5432
+ var SDK_VERSION = (typeof process !== "undefined" && process.env ? "0.84.3" : void 0) || "unknown";
5346
5433
 
5347
5434
  // src/utils/open-url.ts
5348
5435
  var nodePrefix = "node:";
@@ -8079,8 +8166,9 @@ var appKeyResolver = defineResolver({
8079
8166
  },
8080
8167
  listItems: ({
8081
8168
  imports,
8082
- search
8083
- }) => imports.listApps({ search }),
8169
+ search,
8170
+ cursor
8171
+ }) => imports.listApps({ search, cursor }),
8084
8172
  prompt: ({ items }) => ({
8085
8173
  type: "list",
8086
8174
  message: "Select app:",
@@ -8101,9 +8189,11 @@ var actionTypeResolver = defineResolver({
8101
8189
  imports,
8102
8190
  input
8103
8191
  }) => {
8104
- const { data } = await imports.listActions({ app: input.app });
8105
- const types = [...new Set(data.map((action) => action.action_type))];
8106
- return { data: types.map((type) => ({ key: type, name: type })) };
8192
+ const types = /* @__PURE__ */ new Set();
8193
+ for await (const action of imports.listActions({ app: input.app }).items()) {
8194
+ types.add(action.action_type);
8195
+ }
8196
+ return { data: [...types].map((type) => ({ key: type, name: type })) };
8107
8197
  },
8108
8198
  prompt: ({ items }) => ({
8109
8199
  type: "list",
@@ -8119,13 +8209,15 @@ var actionKeyResolver = defineResolver({
8119
8209
  requireParameters: ["app", "actionType"],
8120
8210
  listItems: async ({
8121
8211
  imports,
8122
- input
8212
+ input,
8213
+ cursor
8123
8214
  }) => {
8124
- const { data } = await imports.listActions({ app: input.app });
8215
+ const page = await imports.listActions({ app: input.app, cursor });
8125
8216
  return {
8126
- data: data.filter(
8217
+ data: page.data.filter(
8127
8218
  (action) => action.action_type === input.actionType && !action.is_hidden
8128
- )
8219
+ ),
8220
+ nextCursor: page.nextCursor
8129
8221
  };
8130
8222
  },
8131
8223
  prompt: ({ items }) => ({
@@ -8242,9 +8334,10 @@ var connectionIdResolver = defineResolver({
8242
8334
  }
8243
8335
  return null;
8244
8336
  },
8245
- listItems: ({ imports, input, context }) => imports.listConnections({
8337
+ listItems: ({ imports, input, context, cursor }) => imports.listConnections({
8246
8338
  app: input.app,
8247
- includeShared: context?.canIncludeShared || void 0
8339
+ includeShared: context?.canIncludeShared || void 0,
8340
+ cursor
8248
8341
  }),
8249
8342
  prompt: ({ items, input, context }) => buildConnectionPrompt(
8250
8343
  items,
@@ -8260,9 +8353,10 @@ var connectionIdGenericResolver = defineResolver({
8260
8353
  );
8261
8354
  return { canIncludeShared: canIncludeShared ?? false };
8262
8355
  },
8263
- listItems: ({ imports, input, context }) => imports.listConnections({
8356
+ listItems: ({ imports, input, context, cursor }) => imports.listConnections({
8264
8357
  app: input.app,
8265
- includeShared: context?.canIncludeShared || void 0
8358
+ includeShared: context?.canIncludeShared || void 0,
8359
+ cursor
8266
8360
  }),
8267
8361
  prompt: ({ items, input, context }) => buildConnectionPrompt(
8268
8362
  items,
@@ -8290,12 +8384,13 @@ var listActionInputFieldChoicesRef = declareMethod({ id: "listActionInputFieldCh
8290
8384
  var choiceResolver = defineResolver({
8291
8385
  imports: [listActionInputFieldChoicesRef],
8292
8386
  requireParameters: ["app", "action", "actionType"],
8293
- listItems: ({ imports, input }) => imports.listActionInputFieldChoices({
8387
+ listItems: ({ imports, input, cursor }) => imports.listActionInputFieldChoices({
8294
8388
  app: input.app,
8295
8389
  action: input.action,
8296
8390
  actionType: input.actionType,
8297
8391
  connection: input.connection,
8298
- inputField: input.inputField
8392
+ inputField: input.inputField,
8393
+ cursor
8299
8394
  }),
8300
8395
  prompt: ({ items }) => ({
8301
8396
  type: "list",
@@ -8454,7 +8549,7 @@ var clientCredentialsNameResolver = defineResolver({
8454
8549
  var listClientCredentialsRef = declareMethod({ id: "listClientCredentials" });
8455
8550
  var clientIdResolver = defineResolver({
8456
8551
  imports: [listClientCredentialsRef],
8457
- listItems: ({ imports }) => imports.listClientCredentials({}),
8552
+ listItems: ({ imports, cursor }) => imports.listClientCredentials({ cursor }),
8458
8553
  prompt: ({ items }) => ({
8459
8554
  type: "list",
8460
8555
  message: "Select client credentials to delete:",
@@ -8466,9 +8561,9 @@ var clientIdResolver = defineResolver({
8466
8561
  });
8467
8562
 
8468
8563
  // src/resolvers/tableId.ts
8469
- var listTablesRef = declareMethod({ id: "listTables" });
8564
+ var listTablesInternalRef = declareMethod({ id: "listTablesInternal" });
8470
8565
  var tableIdResolver = defineResolver({
8471
- imports: [listTablesRef, capabilitiesPluginRef],
8566
+ imports: [listTablesInternalRef, capabilitiesPluginRef],
8472
8567
  getContext: async ({ imports }) => {
8473
8568
  const includeShared = await imports.capabilities.hasCapability?.(
8474
8569
  "canIncludeSharedTables"
@@ -8476,27 +8571,36 @@ var tableIdResolver = defineResolver({
8476
8571
  return { includeShared: includeShared ?? false };
8477
8572
  },
8478
8573
  // Unlike connections, the tables API does not return personal tables first,
8479
- // so we use concatPaginated to hoist own tables above shared.
8480
- listItems: ({ imports, context }) => {
8574
+ // so we concatenate personal-only and shared-only slices to hoist own
8575
+ // tables above shared. The slices are disjoint by construction, so the
8576
+ // concatenation paginates with stateless cursors and needs no dedupe.
8577
+ listItems: ({ imports, context, cursor }) => {
8481
8578
  const includeShared = context?.includeShared;
8482
8579
  if (includeShared) {
8483
8580
  return concatPaginated({
8484
8581
  sources: [
8485
- () => imports.listTables({}),
8486
- () => imports.listTables({ includeShared: true })
8582
+ ({ cursor: sourceCursor }) => imports.listTablesInternal({ cursor: sourceCursor }),
8583
+ ({ cursor: sourceCursor }) => imports.listTablesInternal({
8584
+ includeShared: true,
8585
+ includePersonal: false,
8586
+ cursor: sourceCursor
8587
+ })
8487
8588
  ],
8488
- dedupe: (table) => table.id
8589
+ cursor
8489
8590
  });
8490
8591
  }
8491
- return imports.listTables({});
8592
+ return imports.listTablesInternal({ cursor });
8492
8593
  },
8493
- prompt: ({ items }) => ({
8594
+ prompt: ({ items, context }) => ({
8494
8595
  type: "list",
8495
8596
  message: "Select a table:",
8496
8597
  choices: items.map((table) => ({
8497
8598
  label: table.name,
8498
8599
  value: table.id
8499
- }))
8600
+ })),
8601
+ // The capability hint the legacy picker showed as a fake disabled row:
8602
+ // without it, a gated account just sees fewer tables with no explanation.
8603
+ ...context?.includeShared ? {} : { notes: ["Shared tables are hidden for this account."] }
8500
8604
  })
8501
8605
  });
8502
8606
 
@@ -8504,7 +8608,7 @@ var tableIdResolver = defineResolver({
8504
8608
  var listTriggerInboxesRef = declareMethod({ id: "listTriggerInboxes" });
8505
8609
  var triggerInboxResolver = defineResolver({
8506
8610
  imports: [listTriggerInboxesRef],
8507
- listItems: ({ imports }) => imports.listTriggerInboxes({}),
8611
+ listItems: ({ imports, cursor }) => imports.listTriggerInboxes({ cursor }),
8508
8612
  prompt: ({ items }) => ({
8509
8613
  type: "list",
8510
8614
  message: "Select a trigger inbox:",
@@ -8522,7 +8626,7 @@ var triggerInboxResolver = defineResolver({
8522
8626
  var listWorkflowsRef = declareMethod({ id: "listWorkflows" });
8523
8627
  var workflowIdResolver = defineResolver({
8524
8628
  imports: [listWorkflowsRef],
8525
- listItems: ({ imports }) => imports.listWorkflows({}),
8629
+ listItems: ({ imports, cursor }) => imports.listWorkflows({ cursor }),
8526
8630
  prompt: ({ items }) => ({
8527
8631
  type: "list",
8528
8632
  message: "Select a workflow:",
@@ -8538,7 +8642,7 @@ var workflowIdResolver = defineResolver({
8538
8642
  var listDurableRunsRef = declareMethod({ id: "listDurableRuns" });
8539
8643
  var durableRunIdResolver = defineResolver({
8540
8644
  imports: [listDurableRunsRef],
8541
- listItems: ({ imports }) => imports.listDurableRuns({}),
8645
+ listItems: ({ imports, cursor }) => imports.listDurableRuns({ cursor }),
8542
8646
  prompt: ({ items }) => ({
8543
8647
  type: "list",
8544
8648
  message: "Select a run:",
@@ -8555,7 +8659,14 @@ var listWorkflowVersionsRef = declareMethod({ id: "listWorkflowVersions" });
8555
8659
  var workflowVersionIdResolver = defineResolver({
8556
8660
  imports: [listWorkflowVersionsRef],
8557
8661
  requireParameters: ["workflow"],
8558
- listItems: ({ imports, input }) => imports.listWorkflowVersions({ workflow: input.workflow }),
8662
+ listItems: ({
8663
+ imports,
8664
+ input,
8665
+ cursor
8666
+ }) => imports.listWorkflowVersions({
8667
+ workflow: input.workflow,
8668
+ cursor
8669
+ }),
8559
8670
  prompt: ({ items }) => ({
8560
8671
  type: "list",
8561
8672
  message: "Select a workflow version:",
@@ -8571,7 +8682,11 @@ var listWorkflowRunsRef = declareMethod({ id: "listWorkflowRuns" });
8571
8682
  var workflowRunIdResolver = defineResolver({
8572
8683
  imports: [listWorkflowRunsRef],
8573
8684
  requireParameters: ["workflow"],
8574
- listItems: ({ imports, input }) => imports.listWorkflowRuns({ workflow: input.workflow }),
8685
+ listItems: ({
8686
+ imports,
8687
+ input,
8688
+ cursor
8689
+ }) => imports.listWorkflowRuns({ workflow: input.workflow, cursor }),
8575
8690
  prompt: ({ items }) => ({
8576
8691
  type: "list",
8577
8692
  message: "Select a workflow run:",
@@ -8589,8 +8704,9 @@ var triggerMessagesResolver = defineResolver({
8589
8704
  requireParameters: ["inbox"],
8590
8705
  listItems: ({
8591
8706
  imports,
8592
- input
8593
- }) => imports.listTriggerInboxMessages({ inbox: input.inbox }),
8707
+ input,
8708
+ cursor
8709
+ }) => imports.listTriggerInboxMessages({ inbox: input.inbox, cursor }),
8594
8710
  prompt: ({ items }) => ({
8595
8711
  type: "checkbox",
8596
8712
  message: "Select messages:",
@@ -8863,9 +8979,10 @@ function recordChoices(records) {
8863
8979
  var tableRecordIdResolver = defineResolver({
8864
8980
  imports: [listTableRecordsRef],
8865
8981
  requireParameters: ["table"],
8866
- listItems: ({ imports, input }) => imports.listTableRecords({
8982
+ listItems: ({ imports, input, cursor }) => imports.listTableRecords({
8867
8983
  table: input.table,
8868
- keyMode: "names"
8984
+ keyMode: "names",
8985
+ cursor
8869
8986
  }),
8870
8987
  prompt: ({ items }) => ({
8871
8988
  type: "list",
@@ -8876,16 +8993,17 @@ var tableRecordIdResolver = defineResolver({
8876
8993
  var tableRecordIdsResolver = defineResolver({
8877
8994
  imports: [listTableRecordsRef],
8878
8995
  requireParameters: ["table"],
8879
- listItems: ({ imports, input }) => imports.listTableRecords({
8996
+ listItems: ({ imports, input, cursor }) => imports.listTableRecords({
8880
8997
  table: input.table,
8881
- keyMode: "names"
8998
+ keyMode: "names",
8999
+ cursor
8882
9000
  }),
8883
9001
  prompt: ({ items }) => ({
8884
9002
  type: "checkbox",
8885
9003
  message: "Select records to delete:",
8886
- choices: recordChoices(items),
8887
- validate: (value) => Array.isArray(value) && value.length > 0 ? true : "Select at least one record"
8888
- })
9004
+ choices: recordChoices(items)
9005
+ }),
9006
+ validate: ({ value }) => Array.isArray(value) && value.length > 0 ? true : "Select at least one record"
8889
9007
  });
8890
9008
 
8891
9009
  // src/resolvers/tableFieldIds.ts
@@ -8893,6 +9011,8 @@ var listTableFieldsRef = declareMethod({ id: "listTableFields" });
8893
9011
  var tableFieldIdsResolver = defineResolver({
8894
9012
  imports: [listTableFieldsRef],
8895
9013
  requireParameters: ["table"],
9014
+ // No cursor forwarding: the fields API is unpaginated (no cursor on the
9015
+ // response), so the listing is always exhausted after one page.
8896
9016
  listItems: ({ imports, input }) => imports.listTableFields({ table: input.table }),
8897
9017
  prompt: ({ items }) => ({
8898
9018
  type: "checkbox",
@@ -8901,9 +9021,9 @@ var tableFieldIdsResolver = defineResolver({
8901
9021
  label: field.name,
8902
9022
  hint: [field.id, field.type],
8903
9023
  value: field.id
8904
- })),
8905
- validate: (value) => Array.isArray(value) && value.length > 0 ? true : "Select at least one field"
8906
- })
9024
+ }))
9025
+ }),
9026
+ validate: ({ value }) => Array.isArray(value) && value.length > 0 ? true : "Select at least one field"
8907
9027
  });
8908
9028
 
8909
9029
  // src/resolvers/tableName.ts
@@ -13147,27 +13267,31 @@ var ListTablesOptionsSchema = zod.z.object({
13147
13267
  maxItems: zod.z.number().min(1).optional().describe("Maximum total items to return across all pages"),
13148
13268
  cursor: zod.z.string().optional().describe("Cursor to start from")
13149
13269
  }).describe("List tables available to the authenticated user");
13270
+ var ListTablesInternalOptionsSchema = ListTablesOptionsSchema.extend({
13271
+ includePersonal: zod.z.boolean().optional().describe(
13272
+ "Include your own tables (default true). Set false with includeShared to list only tables shared with you."
13273
+ )
13274
+ });
13150
13275
 
13151
- // src/plugins/tables/shared.ts
13152
- var tableCategories = ["table"];
13153
-
13154
- // src/plugins/tables/listTables/index.ts
13155
- var listTablesPlugin = defineMethod({
13156
- name: "listTables",
13276
+ // src/plugins/tables/listTables/internal.ts
13277
+ var listTablesInternalPlugin = defineMethod({
13278
+ name: "listTablesInternal",
13157
13279
  imports: [apiPluginRef, capabilitiesPluginRef],
13158
- categories: tableCategories,
13159
- itemType: "Table",
13160
- inputSchema: ListTablesOptionsSchema,
13161
- outputSchema: TableItemSchema,
13280
+ inputSchema: ListTablesInternalOptionsSchema,
13162
13281
  output: {
13163
13282
  type: "list",
13164
13283
  adaptPage: adaptZapierPage,
13165
13284
  defaultPageSize: DEFAULT_PAGE_SIZE
13166
13285
  },
13167
13286
  run: async ({ imports, input }) => {
13168
- if (input.includeShared) {
13287
+ const includePersonal = input.includePersonal ?? true;
13288
+ const includeShared = input.includeShared ?? false;
13289
+ if (includeShared) {
13169
13290
  await imports.capabilities.checkCapability("canIncludeSharedTables");
13170
13291
  }
13292
+ if (!includePersonal && !includeShared) {
13293
+ return { data: [] };
13294
+ }
13171
13295
  const api = imports.api;
13172
13296
  const searchParams = {};
13173
13297
  if (input.pageSize !== void 0) {
@@ -13183,23 +13307,18 @@ var listTablesPlugin = defineMethod({
13183
13307
  if (input.search) {
13184
13308
  searchParams.q = input.search;
13185
13309
  }
13186
- if (input.owner && input.owner !== "me" && !input.includeShared) {
13310
+ if (input.owner && input.owner !== "me" && !includeShared) {
13187
13311
  throw new ZapierValidationError(
13188
13312
  'The "owner" option requires "includeShared" to be true. Without includeShared, only your own tables are returned.'
13189
13313
  );
13190
13314
  }
13191
- const owner = input.includeShared ? input.owner : "me";
13315
+ const owner = includeShared ? input.owner : "me";
13316
+ const needsProfileId = owner === "me" || !includePersonal && includeShared;
13317
+ const profileId = needsProfileId ? (await api.get("/zapier/api/v4/profile/", {
13318
+ authRequired: true
13319
+ })).id : void 0;
13192
13320
  if (owner) {
13193
- if (owner === "me") {
13194
- const profile = await api.get("/zapier/api/v4/profile/", {
13195
- authRequired: true
13196
- });
13197
- searchParams.owner_customuser_id = String(
13198
- profile.id
13199
- );
13200
- } else {
13201
- searchParams.owner_customuser_id = owner;
13202
- }
13321
+ searchParams.owner_customuser_id = owner === "me" ? String(profileId) : owner;
13203
13322
  }
13204
13323
  if (input.cursor) {
13205
13324
  searchParams.offset = input.cursor;
@@ -13209,12 +13328,35 @@ var listTablesPlugin = defineMethod({
13209
13328
  authRequired: true
13210
13329
  });
13211
13330
  const response = ListTablesApiResponseSchema.parse(rawResponse);
13331
+ const apiItems = includePersonal ? response.data : response.data.filter(
13332
+ (item) => item.owner_zapier_customuser_id !== profileId
13333
+ );
13212
13334
  return {
13213
- data: response.data.map(transformTableItem),
13335
+ data: apiItems.map(transformTableItem),
13214
13336
  links: response.links
13215
13337
  };
13216
13338
  }
13217
13339
  });
13340
+
13341
+ // src/plugins/tables/shared.ts
13342
+ var tableCategories = ["table"];
13343
+
13344
+ // src/plugins/tables/listTables/index.ts
13345
+ var listTablesPlugin = defineMethod({
13346
+ name: "listTables",
13347
+ imports: [listTablesInternalPlugin],
13348
+ categories: tableCategories,
13349
+ itemType: "Table",
13350
+ inputSchema: ListTablesOptionsSchema,
13351
+ outputSchema: TableItemSchema,
13352
+ output: "list",
13353
+ run: async ({ imports, input }) => {
13354
+ return await imports.listTablesInternal({
13355
+ ...input,
13356
+ includePersonal: void 0
13357
+ });
13358
+ }
13359
+ });
13218
13360
  var GetTableApiResponseSchema = zod.z.object({
13219
13361
  data: TableApiItemSchema
13220
13362
  });