@zapier/zapier-sdk-cli 0.13.0 → 0.13.2

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
@@ -466,21 +466,17 @@ var AstTypeGenerator = class {
466
466
  * Generate TypeScript types using AST for a specific app
467
467
  */
468
468
  async generateTypes(options) {
469
- const { appKey, authenticationId, sdk } = options;
470
- const { app, version } = this.parseAppIdentifier(appKey);
469
+ const { app, authenticationId, sdk } = options;
471
470
  const actionsResult = await sdk.listActions({
472
- appKey: app
471
+ appKey: app.implementation_id
473
472
  });
474
473
  const actions = actionsResult.data;
475
- if (actions.length === 0) {
476
- return this.generateEmptyTypesFile(app, version);
477
- }
478
474
  const actionsWithFields = [];
479
475
  if (authenticationId) {
480
476
  for (const action of actions) {
481
477
  try {
482
478
  const fieldsResult = await sdk.listInputFields({
483
- appKey,
479
+ appKey: app.implementation_id,
484
480
  actionKey: action.key,
485
481
  actionType: action.action_type,
486
482
  authenticationId
@@ -506,7 +502,7 @@ var AstTypeGenerator = class {
506
502
  ...action,
507
503
  inputFields: [],
508
504
  name: action.title || action.key,
509
- app_key: action.app_key || appKey,
505
+ app_key: action.app_key || app.implementation_id,
510
506
  action_type: action.action_type || "write",
511
507
  title: action.title || action.key,
512
508
  type: "action",
@@ -515,20 +511,15 @@ var AstTypeGenerator = class {
515
511
  }
516
512
  );
517
513
  }
518
- const sourceFile = this.createSourceFile(app, actionsWithFields, version);
514
+ const sourceFile = this.createSourceFile(app, actionsWithFields);
519
515
  return this.printer.printFile(sourceFile);
520
516
  }
521
- parseAppIdentifier(identifier) {
522
- const parts = identifier.split("@");
523
- return {
524
- app: parts[0],
525
- version: parts[1]
526
- };
527
- }
528
- createSourceFile(appKey, actions, version) {
529
- const appName = this.capitalize(appKey);
530
- const versionComment = version ? ` * Generated for ${appKey}@${version}` : ` * Generated for ${appKey}`;
531
- const headerComment = `Auto-generated TypeScript types for Zapier ${appKey} actions
517
+ createSourceFile(app, actions) {
518
+ const appName = this.getPreferredAppName(app);
519
+ const versionComment = ` * Generated for ${app.implementation_id}`;
520
+ const preferredKey = this.getPreferredProgrammaticKey(app);
521
+ const myVariableName = `my${appName}`;
522
+ const headerComment = `Auto-generated TypeScript types for Zapier ${app.key} actions
532
523
  ${versionComment.slice(3)}
533
524
  Generated on: ${(/* @__PURE__ */ new Date()).toISOString()}
534
525
 
@@ -540,11 +531,11 @@ Usage:
540
531
 
541
532
  const zapier = createZapierSdk();
542
533
  // Types are automatically available:
543
- await zapier.apps.${appKey}.search.user_by_email({ authenticationId: 123, inputs: { email } })
534
+ await zapier.apps.${preferredKey}.search.user_by_email({ authenticationId: 123, inputs: { email } })
544
535
 
545
536
  // Factory usage (pinned auth):
546
- const my${appName} = zapier.apps.${appKey}({ authenticationId: 123 })
547
- await my${appName}.search.user_by_email({ inputs: { email } })`;
537
+ const ${myVariableName} = zapier.apps.${preferredKey}({ authenticationId: 123 })
538
+ await ${myVariableName}.search.user_by_email({ inputs: { email } })`;
548
539
  const statements = [
549
540
  // Import the SDK to activate module augmentation
550
541
  this.createImportStatement(["@zapier/zapier-sdk"]),
@@ -582,7 +573,8 @@ Usage:
582
573
  statements.push(appFactoryInterface);
583
574
  const appWithFactoryType = this.createAppWithFactoryType(appName);
584
575
  statements.push(appWithFactoryType);
585
- const moduleAugmentation = this.createModuleAugmentation(appKey, appName);
576
+ const allKeys = this.getAllKeys(app);
577
+ const moduleAugmentation = this.createModuleAugmentation(allKeys, appName);
586
578
  statements.push(moduleAugmentation);
587
579
  statements.push(
588
580
  this.factory.createExportDeclaration(
@@ -908,7 +900,15 @@ Usage:
908
900
  ])
909
901
  );
910
902
  }
911
- createModuleAugmentation(appKey, appName) {
903
+ createModuleAugmentation(appKeys, appName) {
904
+ const properties = appKeys.map(
905
+ (appKey) => this.factory.createPropertySignature(
906
+ void 0,
907
+ this.createPropertyName(appKey),
908
+ void 0,
909
+ this.factory.createTypeReferenceNode(`${appName}AppWithFactory`)
910
+ )
911
+ );
912
912
  return this.factory.createModuleDeclaration(
913
913
  [this.factory.createToken(ts__namespace.SyntaxKind.DeclareKeyword)],
914
914
  this.factory.createStringLiteral("@zapier/zapier-sdk"),
@@ -918,14 +918,7 @@ Usage:
918
918
  "ZapierSdkApps",
919
919
  void 0,
920
920
  void 0,
921
- [
922
- this.factory.createPropertySignature(
923
- void 0,
924
- appKey,
925
- void 0,
926
- this.factory.createTypeReferenceNode(`${appName}AppWithFactory`)
927
- )
928
- ]
921
+ properties
929
922
  )
930
923
  ])
931
924
  );
@@ -963,38 +956,6 @@ Usage:
963
956
  ]);
964
957
  }
965
958
  }
966
- generateEmptyTypesFile(appKey, version) {
967
- const appName = this.capitalize(appKey);
968
- const versionComment = version ? ` * Generated for ${appKey}@${version}` : ` * Generated for ${appKey}`;
969
- return `/* eslint-disable @typescript-eslint/naming-convention, @typescript-eslint/no-explicit-any */
970
- /**
971
- * Auto-generated TypeScript types for Zapier ${appKey} actions
972
- ${versionComment}
973
- * Generated on: ${(/* @__PURE__ */ new Date()).toISOString()}
974
- *
975
- * No actions found for this app.
976
- */
977
-
978
- import type { ActionExecutionOptions, ActionExecutionResult, ZapierFetchInitOptions } from '@zapier/zapier-sdk'
979
-
980
- interface ${appName}AppProxy {
981
- /** Make authenticated HTTP requests through Zapier's Relay service */
982
- fetch: (url: string | URL, init?: ZapierFetchInitOptions) => Promise<Response>
983
- }
984
-
985
- interface ${appName}AppFactory {
986
- (options: { authenticationId: number }): ${appName}AppProxy
987
- }
988
-
989
- type ${appName}AppWithFactory = ${appName}AppFactory & ${appName}AppProxy
990
-
991
- declare module "@zapier/zapier-sdk" {
992
- interface ZapierSdkApps {
993
- ${appKey}: ${appName}AppWithFactory
994
- }
995
- }
996
- `;
997
- }
998
959
  capitalize(str) {
999
960
  return str.charAt(0).toUpperCase() + str.slice(1).replace(/[-_]/g, "");
1000
961
  }
@@ -1015,6 +976,50 @@ declare module "@zapier/zapier-sdk" {
1015
976
  escapeComment(comment) {
1016
977
  return comment.replace(/\*\//g, "*\\/").replace(/\r?\n/g, " ");
1017
978
  }
979
+ createPropertyName(name) {
980
+ if (this.isValidIdentifier(name)) {
981
+ return this.factory.createIdentifier(name);
982
+ } else {
983
+ return this.factory.createStringLiteral(name);
984
+ }
985
+ }
986
+ isValidIdentifier(name) {
987
+ return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
988
+ }
989
+ getPreferredProgrammaticKey(app) {
990
+ if (app.slug) {
991
+ const snakeCaseSlug = zapierSdk.toSnakeCase(app.slug);
992
+ if (this.isValidIdentifier(snakeCaseSlug)) {
993
+ return snakeCaseSlug;
994
+ }
995
+ }
996
+ if (this.isValidIdentifier(app.key)) {
997
+ return app.key;
998
+ }
999
+ return this.sanitizeToIdentifier(app.key);
1000
+ }
1001
+ getPreferredAppName(app) {
1002
+ const preferredKey = this.getPreferredProgrammaticKey(app);
1003
+ if (preferredKey.includes("_")) {
1004
+ return preferredKey.split("_").map((word) => this.capitalize(word.toLowerCase())).join("");
1005
+ }
1006
+ return this.capitalize(preferredKey);
1007
+ }
1008
+ sanitizeToIdentifier(name) {
1009
+ let sanitized = name.replace(/[^a-zA-Z0-9_$]/g, "_");
1010
+ if (/^[0-9]/.test(sanitized)) {
1011
+ sanitized = "_" + sanitized;
1012
+ }
1013
+ return sanitized;
1014
+ }
1015
+ getAllKeys(app) {
1016
+ const allKeys = /* @__PURE__ */ new Set([app.key]);
1017
+ if (app.slug) {
1018
+ allKeys.add(app.slug);
1019
+ allKeys.add(zapierSdk.toSnakeCase(app.slug));
1020
+ }
1021
+ return Array.from(allKeys);
1022
+ }
1018
1023
  };
1019
1024
  async function detectTypesOutputDirectory() {
1020
1025
  const candidates = ["src", "lib"];
@@ -1099,7 +1104,7 @@ var addPlugin = ({ sdk, context }) => {
1099
1104
  try {
1100
1105
  const generator = new AstTypeGenerator();
1101
1106
  const typeDefinitions = await generator.generateTypes({
1102
- appKey: manifestKey,
1107
+ app,
1103
1108
  authenticationId,
1104
1109
  sdk
1105
1110
  });
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { createFunction, OutputPropertySchema, DEFAULT_CONFIG_PATH, createZapierSdkWithoutRegistry, registryPlugin } from '@zapier/zapier-sdk';
1
+ import { createFunction, OutputPropertySchema, DEFAULT_CONFIG_PATH, createZapierSdkWithoutRegistry, registryPlugin, toSnakeCase } from '@zapier/zapier-sdk';
2
2
  import open from 'open';
3
3
  import crypto from 'crypto';
4
4
  import express from 'express';
@@ -435,21 +435,17 @@ var AstTypeGenerator = class {
435
435
  * Generate TypeScript types using AST for a specific app
436
436
  */
437
437
  async generateTypes(options) {
438
- const { appKey, authenticationId, sdk } = options;
439
- const { app, version } = this.parseAppIdentifier(appKey);
438
+ const { app, authenticationId, sdk } = options;
440
439
  const actionsResult = await sdk.listActions({
441
- appKey: app
440
+ appKey: app.implementation_id
442
441
  });
443
442
  const actions = actionsResult.data;
444
- if (actions.length === 0) {
445
- return this.generateEmptyTypesFile(app, version);
446
- }
447
443
  const actionsWithFields = [];
448
444
  if (authenticationId) {
449
445
  for (const action of actions) {
450
446
  try {
451
447
  const fieldsResult = await sdk.listInputFields({
452
- appKey,
448
+ appKey: app.implementation_id,
453
449
  actionKey: action.key,
454
450
  actionType: action.action_type,
455
451
  authenticationId
@@ -475,7 +471,7 @@ var AstTypeGenerator = class {
475
471
  ...action,
476
472
  inputFields: [],
477
473
  name: action.title || action.key,
478
- app_key: action.app_key || appKey,
474
+ app_key: action.app_key || app.implementation_id,
479
475
  action_type: action.action_type || "write",
480
476
  title: action.title || action.key,
481
477
  type: "action",
@@ -484,20 +480,15 @@ var AstTypeGenerator = class {
484
480
  }
485
481
  );
486
482
  }
487
- const sourceFile = this.createSourceFile(app, actionsWithFields, version);
483
+ const sourceFile = this.createSourceFile(app, actionsWithFields);
488
484
  return this.printer.printFile(sourceFile);
489
485
  }
490
- parseAppIdentifier(identifier) {
491
- const parts = identifier.split("@");
492
- return {
493
- app: parts[0],
494
- version: parts[1]
495
- };
496
- }
497
- createSourceFile(appKey, actions, version) {
498
- const appName = this.capitalize(appKey);
499
- const versionComment = version ? ` * Generated for ${appKey}@${version}` : ` * Generated for ${appKey}`;
500
- const headerComment = `Auto-generated TypeScript types for Zapier ${appKey} actions
486
+ createSourceFile(app, actions) {
487
+ const appName = this.getPreferredAppName(app);
488
+ const versionComment = ` * Generated for ${app.implementation_id}`;
489
+ const preferredKey = this.getPreferredProgrammaticKey(app);
490
+ const myVariableName = `my${appName}`;
491
+ const headerComment = `Auto-generated TypeScript types for Zapier ${app.key} actions
501
492
  ${versionComment.slice(3)}
502
493
  Generated on: ${(/* @__PURE__ */ new Date()).toISOString()}
503
494
 
@@ -509,11 +500,11 @@ Usage:
509
500
 
510
501
  const zapier = createZapierSdk();
511
502
  // Types are automatically available:
512
- await zapier.apps.${appKey}.search.user_by_email({ authenticationId: 123, inputs: { email } })
503
+ await zapier.apps.${preferredKey}.search.user_by_email({ authenticationId: 123, inputs: { email } })
513
504
 
514
505
  // Factory usage (pinned auth):
515
- const my${appName} = zapier.apps.${appKey}({ authenticationId: 123 })
516
- await my${appName}.search.user_by_email({ inputs: { email } })`;
506
+ const ${myVariableName} = zapier.apps.${preferredKey}({ authenticationId: 123 })
507
+ await ${myVariableName}.search.user_by_email({ inputs: { email } })`;
517
508
  const statements = [
518
509
  // Import the SDK to activate module augmentation
519
510
  this.createImportStatement(["@zapier/zapier-sdk"]),
@@ -551,7 +542,8 @@ Usage:
551
542
  statements.push(appFactoryInterface);
552
543
  const appWithFactoryType = this.createAppWithFactoryType(appName);
553
544
  statements.push(appWithFactoryType);
554
- const moduleAugmentation = this.createModuleAugmentation(appKey, appName);
545
+ const allKeys = this.getAllKeys(app);
546
+ const moduleAugmentation = this.createModuleAugmentation(allKeys, appName);
555
547
  statements.push(moduleAugmentation);
556
548
  statements.push(
557
549
  this.factory.createExportDeclaration(
@@ -877,7 +869,15 @@ Usage:
877
869
  ])
878
870
  );
879
871
  }
880
- createModuleAugmentation(appKey, appName) {
872
+ createModuleAugmentation(appKeys, appName) {
873
+ const properties = appKeys.map(
874
+ (appKey) => this.factory.createPropertySignature(
875
+ void 0,
876
+ this.createPropertyName(appKey),
877
+ void 0,
878
+ this.factory.createTypeReferenceNode(`${appName}AppWithFactory`)
879
+ )
880
+ );
881
881
  return this.factory.createModuleDeclaration(
882
882
  [this.factory.createToken(ts.SyntaxKind.DeclareKeyword)],
883
883
  this.factory.createStringLiteral("@zapier/zapier-sdk"),
@@ -887,14 +887,7 @@ Usage:
887
887
  "ZapierSdkApps",
888
888
  void 0,
889
889
  void 0,
890
- [
891
- this.factory.createPropertySignature(
892
- void 0,
893
- appKey,
894
- void 0,
895
- this.factory.createTypeReferenceNode(`${appName}AppWithFactory`)
896
- )
897
- ]
890
+ properties
898
891
  )
899
892
  ])
900
893
  );
@@ -932,38 +925,6 @@ Usage:
932
925
  ]);
933
926
  }
934
927
  }
935
- generateEmptyTypesFile(appKey, version) {
936
- const appName = this.capitalize(appKey);
937
- const versionComment = version ? ` * Generated for ${appKey}@${version}` : ` * Generated for ${appKey}`;
938
- return `/* eslint-disable @typescript-eslint/naming-convention, @typescript-eslint/no-explicit-any */
939
- /**
940
- * Auto-generated TypeScript types for Zapier ${appKey} actions
941
- ${versionComment}
942
- * Generated on: ${(/* @__PURE__ */ new Date()).toISOString()}
943
- *
944
- * No actions found for this app.
945
- */
946
-
947
- import type { ActionExecutionOptions, ActionExecutionResult, ZapierFetchInitOptions } from '@zapier/zapier-sdk'
948
-
949
- interface ${appName}AppProxy {
950
- /** Make authenticated HTTP requests through Zapier's Relay service */
951
- fetch: (url: string | URL, init?: ZapierFetchInitOptions) => Promise<Response>
952
- }
953
-
954
- interface ${appName}AppFactory {
955
- (options: { authenticationId: number }): ${appName}AppProxy
956
- }
957
-
958
- type ${appName}AppWithFactory = ${appName}AppFactory & ${appName}AppProxy
959
-
960
- declare module "@zapier/zapier-sdk" {
961
- interface ZapierSdkApps {
962
- ${appKey}: ${appName}AppWithFactory
963
- }
964
- }
965
- `;
966
- }
967
928
  capitalize(str) {
968
929
  return str.charAt(0).toUpperCase() + str.slice(1).replace(/[-_]/g, "");
969
930
  }
@@ -984,6 +945,50 @@ declare module "@zapier/zapier-sdk" {
984
945
  escapeComment(comment) {
985
946
  return comment.replace(/\*\//g, "*\\/").replace(/\r?\n/g, " ");
986
947
  }
948
+ createPropertyName(name) {
949
+ if (this.isValidIdentifier(name)) {
950
+ return this.factory.createIdentifier(name);
951
+ } else {
952
+ return this.factory.createStringLiteral(name);
953
+ }
954
+ }
955
+ isValidIdentifier(name) {
956
+ return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
957
+ }
958
+ getPreferredProgrammaticKey(app) {
959
+ if (app.slug) {
960
+ const snakeCaseSlug = toSnakeCase(app.slug);
961
+ if (this.isValidIdentifier(snakeCaseSlug)) {
962
+ return snakeCaseSlug;
963
+ }
964
+ }
965
+ if (this.isValidIdentifier(app.key)) {
966
+ return app.key;
967
+ }
968
+ return this.sanitizeToIdentifier(app.key);
969
+ }
970
+ getPreferredAppName(app) {
971
+ const preferredKey = this.getPreferredProgrammaticKey(app);
972
+ if (preferredKey.includes("_")) {
973
+ return preferredKey.split("_").map((word) => this.capitalize(word.toLowerCase())).join("");
974
+ }
975
+ return this.capitalize(preferredKey);
976
+ }
977
+ sanitizeToIdentifier(name) {
978
+ let sanitized = name.replace(/[^a-zA-Z0-9_$]/g, "_");
979
+ if (/^[0-9]/.test(sanitized)) {
980
+ sanitized = "_" + sanitized;
981
+ }
982
+ return sanitized;
983
+ }
984
+ getAllKeys(app) {
985
+ const allKeys = /* @__PURE__ */ new Set([app.key]);
986
+ if (app.slug) {
987
+ allKeys.add(app.slug);
988
+ allKeys.add(toSnakeCase(app.slug));
989
+ }
990
+ return Array.from(allKeys);
991
+ }
987
992
  };
988
993
  async function detectTypesOutputDirectory() {
989
994
  const candidates = ["src", "lib"];
@@ -1068,7 +1073,7 @@ var addPlugin = ({ sdk, context }) => {
1068
1073
  try {
1069
1074
  const generator = new AstTypeGenerator();
1070
1075
  const typeDefinitions = await generator.generateTypes({
1071
- appKey: manifestKey,
1076
+ app,
1072
1077
  authenticationId,
1073
1078
  sdk
1074
1079
  });
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zapier/zapier-sdk-cli",
3
- "version": "0.13.0",
3
+ "version": "0.13.2",
4
4
  "description": "Command line interface for Zapier SDK",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",
@@ -1,6 +1,6 @@
1
- import type { GetSdkType, ListActionsPluginProvides, ListInputFieldsPluginProvides, ManifestPluginProvides } from "@zapier/zapier-sdk";
1
+ import type { GetSdkType, ListActionsPluginProvides, ListInputFieldsPluginProvides, ManifestPluginProvides, AppItem } from "@zapier/zapier-sdk";
2
2
  interface GenerateTypesOptions {
3
- appKey: string;
3
+ app: AppItem;
4
4
  authenticationId?: number;
5
5
  }
6
6
  /**
@@ -15,7 +15,6 @@ export declare class AstTypeGenerator {
15
15
  generateTypes(options: GenerateTypesOptions & {
16
16
  sdk: GetSdkType<ListActionsPluginProvides & ListInputFieldsPluginProvides & ManifestPluginProvides>;
17
17
  }): Promise<string>;
18
- private parseAppIdentifier;
19
18
  private createSourceFile;
20
19
  private createImportStatement;
21
20
  private createTypeImportStatement;
@@ -28,10 +27,15 @@ export declare class AstTypeGenerator {
28
27
  private createAppWithFactoryType;
29
28
  private createModuleAugmentation;
30
29
  private mapFieldTypeToTypeNode;
31
- private generateEmptyTypesFile;
32
30
  private capitalize;
33
31
  private sanitizeActionName;
34
32
  private sanitizeFieldName;
35
33
  private escapeComment;
34
+ private createPropertyName;
35
+ private isValidIdentifier;
36
+ private getPreferredProgrammaticKey;
37
+ private getPreferredAppName;
38
+ private sanitizeToIdentifier;
39
+ private getAllKeys;
36
40
  }
37
41
  export {};