@zapier/zapier-sdk-cli 0.13.1 → 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/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @zapier/zapier-sdk-cli
2
2
 
3
+ ## 0.13.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 325d5c2: Fix bug where adding apps with dashed slugs would create types with syntax errors. All valid keys are now valid properties on the apps interface.
8
+ - Updated dependencies [325d5c2]
9
+ - @zapier/zapier-sdk@0.13.2
10
+ - @zapier/zapier-sdk-mcp@0.3.15
11
+
3
12
  ## 0.13.1
4
13
 
5
14
  ### Patch Changes
package/dist/cli.cjs CHANGED
@@ -1604,21 +1604,17 @@ var AstTypeGenerator = class {
1604
1604
  * Generate TypeScript types using AST for a specific app
1605
1605
  */
1606
1606
  async generateTypes(options) {
1607
- const { appKey, authenticationId, sdk: sdk2 } = options;
1608
- const { app, version } = this.parseAppIdentifier(appKey);
1607
+ const { app, authenticationId, sdk: sdk2 } = options;
1609
1608
  const actionsResult = await sdk2.listActions({
1610
- appKey: app
1609
+ appKey: app.implementation_id
1611
1610
  });
1612
1611
  const actions = actionsResult.data;
1613
- if (actions.length === 0) {
1614
- return this.generateEmptyTypesFile(app, version);
1615
- }
1616
1612
  const actionsWithFields = [];
1617
1613
  if (authenticationId) {
1618
1614
  for (const action of actions) {
1619
1615
  try {
1620
1616
  const fieldsResult = await sdk2.listInputFields({
1621
- appKey,
1617
+ appKey: app.implementation_id,
1622
1618
  actionKey: action.key,
1623
1619
  actionType: action.action_type,
1624
1620
  authenticationId
@@ -1644,7 +1640,7 @@ var AstTypeGenerator = class {
1644
1640
  ...action,
1645
1641
  inputFields: [],
1646
1642
  name: action.title || action.key,
1647
- app_key: action.app_key || appKey,
1643
+ app_key: action.app_key || app.implementation_id,
1648
1644
  action_type: action.action_type || "write",
1649
1645
  title: action.title || action.key,
1650
1646
  type: "action",
@@ -1653,20 +1649,15 @@ var AstTypeGenerator = class {
1653
1649
  }
1654
1650
  );
1655
1651
  }
1656
- const sourceFile = this.createSourceFile(app, actionsWithFields, version);
1652
+ const sourceFile = this.createSourceFile(app, actionsWithFields);
1657
1653
  return this.printer.printFile(sourceFile);
1658
1654
  }
1659
- parseAppIdentifier(identifier) {
1660
- const parts = identifier.split("@");
1661
- return {
1662
- app: parts[0],
1663
- version: parts[1]
1664
- };
1665
- }
1666
- createSourceFile(appKey, actions, version) {
1667
- const appName = this.capitalize(appKey);
1668
- const versionComment = version ? ` * Generated for ${appKey}@${version}` : ` * Generated for ${appKey}`;
1669
- const headerComment = `Auto-generated TypeScript types for Zapier ${appKey} actions
1655
+ createSourceFile(app, actions) {
1656
+ const appName = this.getPreferredAppName(app);
1657
+ const versionComment = ` * Generated for ${app.implementation_id}`;
1658
+ const preferredKey = this.getPreferredProgrammaticKey(app);
1659
+ const myVariableName = `my${appName}`;
1660
+ const headerComment = `Auto-generated TypeScript types for Zapier ${app.key} actions
1670
1661
  ${versionComment.slice(3)}
1671
1662
  Generated on: ${(/* @__PURE__ */ new Date()).toISOString()}
1672
1663
 
@@ -1678,11 +1669,11 @@ Usage:
1678
1669
 
1679
1670
  const zapier = createZapierSdk();
1680
1671
  // Types are automatically available:
1681
- await zapier.apps.${appKey}.search.user_by_email({ authenticationId: 123, inputs: { email } })
1672
+ await zapier.apps.${preferredKey}.search.user_by_email({ authenticationId: 123, inputs: { email } })
1682
1673
 
1683
1674
  // Factory usage (pinned auth):
1684
- const my${appName} = zapier.apps.${appKey}({ authenticationId: 123 })
1685
- await my${appName}.search.user_by_email({ inputs: { email } })`;
1675
+ const ${myVariableName} = zapier.apps.${preferredKey}({ authenticationId: 123 })
1676
+ await ${myVariableName}.search.user_by_email({ inputs: { email } })`;
1686
1677
  const statements = [
1687
1678
  // Import the SDK to activate module augmentation
1688
1679
  this.createImportStatement(["@zapier/zapier-sdk"]),
@@ -1720,7 +1711,8 @@ Usage:
1720
1711
  statements.push(appFactoryInterface);
1721
1712
  const appWithFactoryType = this.createAppWithFactoryType(appName);
1722
1713
  statements.push(appWithFactoryType);
1723
- const moduleAugmentation = this.createModuleAugmentation(appKey, appName);
1714
+ const allKeys = this.getAllKeys(app);
1715
+ const moduleAugmentation = this.createModuleAugmentation(allKeys, appName);
1724
1716
  statements.push(moduleAugmentation);
1725
1717
  statements.push(
1726
1718
  this.factory.createExportDeclaration(
@@ -2046,7 +2038,15 @@ Usage:
2046
2038
  ])
2047
2039
  );
2048
2040
  }
2049
- createModuleAugmentation(appKey, appName) {
2041
+ createModuleAugmentation(appKeys, appName) {
2042
+ const properties = appKeys.map(
2043
+ (appKey) => this.factory.createPropertySignature(
2044
+ void 0,
2045
+ this.createPropertyName(appKey),
2046
+ void 0,
2047
+ this.factory.createTypeReferenceNode(`${appName}AppWithFactory`)
2048
+ )
2049
+ );
2050
2050
  return this.factory.createModuleDeclaration(
2051
2051
  [this.factory.createToken(ts__namespace.SyntaxKind.DeclareKeyword)],
2052
2052
  this.factory.createStringLiteral("@zapier/zapier-sdk"),
@@ -2056,14 +2056,7 @@ Usage:
2056
2056
  "ZapierSdkApps",
2057
2057
  void 0,
2058
2058
  void 0,
2059
- [
2060
- this.factory.createPropertySignature(
2061
- void 0,
2062
- appKey,
2063
- void 0,
2064
- this.factory.createTypeReferenceNode(`${appName}AppWithFactory`)
2065
- )
2066
- ]
2059
+ properties
2067
2060
  )
2068
2061
  ])
2069
2062
  );
@@ -2101,38 +2094,6 @@ Usage:
2101
2094
  ]);
2102
2095
  }
2103
2096
  }
2104
- generateEmptyTypesFile(appKey, version) {
2105
- const appName = this.capitalize(appKey);
2106
- const versionComment = version ? ` * Generated for ${appKey}@${version}` : ` * Generated for ${appKey}`;
2107
- return `/* eslint-disable @typescript-eslint/naming-convention, @typescript-eslint/no-explicit-any */
2108
- /**
2109
- * Auto-generated TypeScript types for Zapier ${appKey} actions
2110
- ${versionComment}
2111
- * Generated on: ${(/* @__PURE__ */ new Date()).toISOString()}
2112
- *
2113
- * No actions found for this app.
2114
- */
2115
-
2116
- import type { ActionExecutionOptions, ActionExecutionResult, ZapierFetchInitOptions } from '@zapier/zapier-sdk'
2117
-
2118
- interface ${appName}AppProxy {
2119
- /** Make authenticated HTTP requests through Zapier's Relay service */
2120
- fetch: (url: string | URL, init?: ZapierFetchInitOptions) => Promise<Response>
2121
- }
2122
-
2123
- interface ${appName}AppFactory {
2124
- (options: { authenticationId: number }): ${appName}AppProxy
2125
- }
2126
-
2127
- type ${appName}AppWithFactory = ${appName}AppFactory & ${appName}AppProxy
2128
-
2129
- declare module "@zapier/zapier-sdk" {
2130
- interface ZapierSdkApps {
2131
- ${appKey}: ${appName}AppWithFactory
2132
- }
2133
- }
2134
- `;
2135
- }
2136
2097
  capitalize(str) {
2137
2098
  return str.charAt(0).toUpperCase() + str.slice(1).replace(/[-_]/g, "");
2138
2099
  }
@@ -2153,6 +2114,50 @@ declare module "@zapier/zapier-sdk" {
2153
2114
  escapeComment(comment) {
2154
2115
  return comment.replace(/\*\//g, "*\\/").replace(/\r?\n/g, " ");
2155
2116
  }
2117
+ createPropertyName(name) {
2118
+ if (this.isValidIdentifier(name)) {
2119
+ return this.factory.createIdentifier(name);
2120
+ } else {
2121
+ return this.factory.createStringLiteral(name);
2122
+ }
2123
+ }
2124
+ isValidIdentifier(name) {
2125
+ return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
2126
+ }
2127
+ getPreferredProgrammaticKey(app) {
2128
+ if (app.slug) {
2129
+ const snakeCaseSlug = zapierSdk.toSnakeCase(app.slug);
2130
+ if (this.isValidIdentifier(snakeCaseSlug)) {
2131
+ return snakeCaseSlug;
2132
+ }
2133
+ }
2134
+ if (this.isValidIdentifier(app.key)) {
2135
+ return app.key;
2136
+ }
2137
+ return this.sanitizeToIdentifier(app.key);
2138
+ }
2139
+ getPreferredAppName(app) {
2140
+ const preferredKey = this.getPreferredProgrammaticKey(app);
2141
+ if (preferredKey.includes("_")) {
2142
+ return preferredKey.split("_").map((word) => this.capitalize(word.toLowerCase())).join("");
2143
+ }
2144
+ return this.capitalize(preferredKey);
2145
+ }
2146
+ sanitizeToIdentifier(name) {
2147
+ let sanitized = name.replace(/[^a-zA-Z0-9_$]/g, "_");
2148
+ if (/^[0-9]/.test(sanitized)) {
2149
+ sanitized = "_" + sanitized;
2150
+ }
2151
+ return sanitized;
2152
+ }
2153
+ getAllKeys(app) {
2154
+ const allKeys = /* @__PURE__ */ new Set([app.key]);
2155
+ if (app.slug) {
2156
+ allKeys.add(app.slug);
2157
+ allKeys.add(zapierSdk.toSnakeCase(app.slug));
2158
+ }
2159
+ return Array.from(allKeys);
2160
+ }
2156
2161
  };
2157
2162
  async function detectTypesOutputDirectory() {
2158
2163
  const candidates = ["src", "lib"];
@@ -2237,7 +2242,7 @@ var addPlugin = ({ sdk: sdk2, context }) => {
2237
2242
  try {
2238
2243
  const generator = new AstTypeGenerator();
2239
2244
  const typeDefinitions = await generator.generateTypes({
2240
- appKey: manifestKey,
2245
+ app,
2241
2246
  authenticationId,
2242
2247
  sdk: sdk2
2243
2248
  });
@@ -2284,7 +2289,7 @@ function createZapierCliSdk(options = {}) {
2284
2289
 
2285
2290
  // package.json
2286
2291
  var package_default = {
2287
- version: "0.13.1"};
2292
+ version: "0.13.2"};
2288
2293
 
2289
2294
  // src/cli.ts
2290
2295
  var program = new commander.Command();
package/dist/cli.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { Command } from 'commander';
3
3
  import { z } from 'zod';
4
- import { createFunction, OutputPropertySchema, DEFAULT_CONFIG_PATH, createZapierSdkWithoutRegistry, registryPlugin, ZapierError, formatErrorMessage, isPositional } from '@zapier/zapier-sdk';
4
+ import { createFunction, OutputPropertySchema, DEFAULT_CONFIG_PATH, createZapierSdkWithoutRegistry, registryPlugin, toSnakeCase, ZapierError, formatErrorMessage, isPositional } from '@zapier/zapier-sdk';
5
5
  import inquirer from 'inquirer';
6
6
  import chalk3 from 'chalk';
7
7
  import util from 'util';
@@ -1571,21 +1571,17 @@ var AstTypeGenerator = class {
1571
1571
  * Generate TypeScript types using AST for a specific app
1572
1572
  */
1573
1573
  async generateTypes(options) {
1574
- const { appKey, authenticationId, sdk: sdk2 } = options;
1575
- const { app, version } = this.parseAppIdentifier(appKey);
1574
+ const { app, authenticationId, sdk: sdk2 } = options;
1576
1575
  const actionsResult = await sdk2.listActions({
1577
- appKey: app
1576
+ appKey: app.implementation_id
1578
1577
  });
1579
1578
  const actions = actionsResult.data;
1580
- if (actions.length === 0) {
1581
- return this.generateEmptyTypesFile(app, version);
1582
- }
1583
1579
  const actionsWithFields = [];
1584
1580
  if (authenticationId) {
1585
1581
  for (const action of actions) {
1586
1582
  try {
1587
1583
  const fieldsResult = await sdk2.listInputFields({
1588
- appKey,
1584
+ appKey: app.implementation_id,
1589
1585
  actionKey: action.key,
1590
1586
  actionType: action.action_type,
1591
1587
  authenticationId
@@ -1611,7 +1607,7 @@ var AstTypeGenerator = class {
1611
1607
  ...action,
1612
1608
  inputFields: [],
1613
1609
  name: action.title || action.key,
1614
- app_key: action.app_key || appKey,
1610
+ app_key: action.app_key || app.implementation_id,
1615
1611
  action_type: action.action_type || "write",
1616
1612
  title: action.title || action.key,
1617
1613
  type: "action",
@@ -1620,20 +1616,15 @@ var AstTypeGenerator = class {
1620
1616
  }
1621
1617
  );
1622
1618
  }
1623
- const sourceFile = this.createSourceFile(app, actionsWithFields, version);
1619
+ const sourceFile = this.createSourceFile(app, actionsWithFields);
1624
1620
  return this.printer.printFile(sourceFile);
1625
1621
  }
1626
- parseAppIdentifier(identifier) {
1627
- const parts = identifier.split("@");
1628
- return {
1629
- app: parts[0],
1630
- version: parts[1]
1631
- };
1632
- }
1633
- createSourceFile(appKey, actions, version) {
1634
- const appName = this.capitalize(appKey);
1635
- const versionComment = version ? ` * Generated for ${appKey}@${version}` : ` * Generated for ${appKey}`;
1636
- const headerComment = `Auto-generated TypeScript types for Zapier ${appKey} actions
1622
+ createSourceFile(app, actions) {
1623
+ const appName = this.getPreferredAppName(app);
1624
+ const versionComment = ` * Generated for ${app.implementation_id}`;
1625
+ const preferredKey = this.getPreferredProgrammaticKey(app);
1626
+ const myVariableName = `my${appName}`;
1627
+ const headerComment = `Auto-generated TypeScript types for Zapier ${app.key} actions
1637
1628
  ${versionComment.slice(3)}
1638
1629
  Generated on: ${(/* @__PURE__ */ new Date()).toISOString()}
1639
1630
 
@@ -1645,11 +1636,11 @@ Usage:
1645
1636
 
1646
1637
  const zapier = createZapierSdk();
1647
1638
  // Types are automatically available:
1648
- await zapier.apps.${appKey}.search.user_by_email({ authenticationId: 123, inputs: { email } })
1639
+ await zapier.apps.${preferredKey}.search.user_by_email({ authenticationId: 123, inputs: { email } })
1649
1640
 
1650
1641
  // Factory usage (pinned auth):
1651
- const my${appName} = zapier.apps.${appKey}({ authenticationId: 123 })
1652
- await my${appName}.search.user_by_email({ inputs: { email } })`;
1642
+ const ${myVariableName} = zapier.apps.${preferredKey}({ authenticationId: 123 })
1643
+ await ${myVariableName}.search.user_by_email({ inputs: { email } })`;
1653
1644
  const statements = [
1654
1645
  // Import the SDK to activate module augmentation
1655
1646
  this.createImportStatement(["@zapier/zapier-sdk"]),
@@ -1687,7 +1678,8 @@ Usage:
1687
1678
  statements.push(appFactoryInterface);
1688
1679
  const appWithFactoryType = this.createAppWithFactoryType(appName);
1689
1680
  statements.push(appWithFactoryType);
1690
- const moduleAugmentation = this.createModuleAugmentation(appKey, appName);
1681
+ const allKeys = this.getAllKeys(app);
1682
+ const moduleAugmentation = this.createModuleAugmentation(allKeys, appName);
1691
1683
  statements.push(moduleAugmentation);
1692
1684
  statements.push(
1693
1685
  this.factory.createExportDeclaration(
@@ -2013,7 +2005,15 @@ Usage:
2013
2005
  ])
2014
2006
  );
2015
2007
  }
2016
- createModuleAugmentation(appKey, appName) {
2008
+ createModuleAugmentation(appKeys, appName) {
2009
+ const properties = appKeys.map(
2010
+ (appKey) => this.factory.createPropertySignature(
2011
+ void 0,
2012
+ this.createPropertyName(appKey),
2013
+ void 0,
2014
+ this.factory.createTypeReferenceNode(`${appName}AppWithFactory`)
2015
+ )
2016
+ );
2017
2017
  return this.factory.createModuleDeclaration(
2018
2018
  [this.factory.createToken(ts.SyntaxKind.DeclareKeyword)],
2019
2019
  this.factory.createStringLiteral("@zapier/zapier-sdk"),
@@ -2023,14 +2023,7 @@ Usage:
2023
2023
  "ZapierSdkApps",
2024
2024
  void 0,
2025
2025
  void 0,
2026
- [
2027
- this.factory.createPropertySignature(
2028
- void 0,
2029
- appKey,
2030
- void 0,
2031
- this.factory.createTypeReferenceNode(`${appName}AppWithFactory`)
2032
- )
2033
- ]
2026
+ properties
2034
2027
  )
2035
2028
  ])
2036
2029
  );
@@ -2068,38 +2061,6 @@ Usage:
2068
2061
  ]);
2069
2062
  }
2070
2063
  }
2071
- generateEmptyTypesFile(appKey, version) {
2072
- const appName = this.capitalize(appKey);
2073
- const versionComment = version ? ` * Generated for ${appKey}@${version}` : ` * Generated for ${appKey}`;
2074
- return `/* eslint-disable @typescript-eslint/naming-convention, @typescript-eslint/no-explicit-any */
2075
- /**
2076
- * Auto-generated TypeScript types for Zapier ${appKey} actions
2077
- ${versionComment}
2078
- * Generated on: ${(/* @__PURE__ */ new Date()).toISOString()}
2079
- *
2080
- * No actions found for this app.
2081
- */
2082
-
2083
- import type { ActionExecutionOptions, ActionExecutionResult, ZapierFetchInitOptions } from '@zapier/zapier-sdk'
2084
-
2085
- interface ${appName}AppProxy {
2086
- /** Make authenticated HTTP requests through Zapier's Relay service */
2087
- fetch: (url: string | URL, init?: ZapierFetchInitOptions) => Promise<Response>
2088
- }
2089
-
2090
- interface ${appName}AppFactory {
2091
- (options: { authenticationId: number }): ${appName}AppProxy
2092
- }
2093
-
2094
- type ${appName}AppWithFactory = ${appName}AppFactory & ${appName}AppProxy
2095
-
2096
- declare module "@zapier/zapier-sdk" {
2097
- interface ZapierSdkApps {
2098
- ${appKey}: ${appName}AppWithFactory
2099
- }
2100
- }
2101
- `;
2102
- }
2103
2064
  capitalize(str) {
2104
2065
  return str.charAt(0).toUpperCase() + str.slice(1).replace(/[-_]/g, "");
2105
2066
  }
@@ -2120,6 +2081,50 @@ declare module "@zapier/zapier-sdk" {
2120
2081
  escapeComment(comment) {
2121
2082
  return comment.replace(/\*\//g, "*\\/").replace(/\r?\n/g, " ");
2122
2083
  }
2084
+ createPropertyName(name) {
2085
+ if (this.isValidIdentifier(name)) {
2086
+ return this.factory.createIdentifier(name);
2087
+ } else {
2088
+ return this.factory.createStringLiteral(name);
2089
+ }
2090
+ }
2091
+ isValidIdentifier(name) {
2092
+ return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
2093
+ }
2094
+ getPreferredProgrammaticKey(app) {
2095
+ if (app.slug) {
2096
+ const snakeCaseSlug = toSnakeCase(app.slug);
2097
+ if (this.isValidIdentifier(snakeCaseSlug)) {
2098
+ return snakeCaseSlug;
2099
+ }
2100
+ }
2101
+ if (this.isValidIdentifier(app.key)) {
2102
+ return app.key;
2103
+ }
2104
+ return this.sanitizeToIdentifier(app.key);
2105
+ }
2106
+ getPreferredAppName(app) {
2107
+ const preferredKey = this.getPreferredProgrammaticKey(app);
2108
+ if (preferredKey.includes("_")) {
2109
+ return preferredKey.split("_").map((word) => this.capitalize(word.toLowerCase())).join("");
2110
+ }
2111
+ return this.capitalize(preferredKey);
2112
+ }
2113
+ sanitizeToIdentifier(name) {
2114
+ let sanitized = name.replace(/[^a-zA-Z0-9_$]/g, "_");
2115
+ if (/^[0-9]/.test(sanitized)) {
2116
+ sanitized = "_" + sanitized;
2117
+ }
2118
+ return sanitized;
2119
+ }
2120
+ getAllKeys(app) {
2121
+ const allKeys = /* @__PURE__ */ new Set([app.key]);
2122
+ if (app.slug) {
2123
+ allKeys.add(app.slug);
2124
+ allKeys.add(toSnakeCase(app.slug));
2125
+ }
2126
+ return Array.from(allKeys);
2127
+ }
2123
2128
  };
2124
2129
  async function detectTypesOutputDirectory() {
2125
2130
  const candidates = ["src", "lib"];
@@ -2204,7 +2209,7 @@ var addPlugin = ({ sdk: sdk2, context }) => {
2204
2209
  try {
2205
2210
  const generator = new AstTypeGenerator();
2206
2211
  const typeDefinitions = await generator.generateTypes({
2207
- appKey: manifestKey,
2212
+ app,
2208
2213
  authenticationId,
2209
2214
  sdk: sdk2
2210
2215
  });
@@ -2251,7 +2256,7 @@ function createZapierCliSdk(options = {}) {
2251
2256
 
2252
2257
  // package.json
2253
2258
  var package_default = {
2254
- version: "0.13.1"};
2259
+ version: "0.13.2"};
2255
2260
 
2256
2261
  // src/cli.ts
2257
2262
  var program = new Command();
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
  });