zapier-platform-cli 17.3.1 → 17.5.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 (31) hide show
  1. package/oclif.manifest.json +16 -4
  2. package/package.json +1 -1
  3. package/scaffold/resource.template.ts +30 -9
  4. package/src/generators/index.js +70 -68
  5. package/src/generators/templates/README.template.md +10 -0
  6. package/src/generators/templates/authTests/basic.test.ts +42 -0
  7. package/src/generators/templates/authTests/custom.test.ts +34 -0
  8. package/src/generators/templates/authTests/digest.test.ts +43 -0
  9. package/src/generators/templates/authTests/oauth1.test.ts +63 -0
  10. package/src/generators/templates/authTests/oauth2.test.ts +115 -0
  11. package/src/generators/templates/authTests/session.test.ts +36 -0
  12. package/src/generators/templates/index.template.js +2 -5
  13. package/src/generators/templates/index.template.ts +11 -14
  14. package/src/generators/templates/tsconfig.template.json +18 -0
  15. package/src/oclif/commands/init.js +9 -2
  16. package/src/oclif/commands/invoke.js +4 -0
  17. package/src/oclif/commands/versions.js +0 -24
  18. package/src/utils/auth-files-codegen.js +343 -142
  19. package/src/utils/build.js +52 -53
  20. package/src/utils/codegen.js +26 -6
  21. package/src/utils/files.js +12 -2
  22. package/src/generators/templates/index-esm.template.ts +0 -24
  23. package/src/generators/templates/typescript/README.md +0 -3
  24. package/src/generators/templates/typescript/src/authentication.ts +0 -48
  25. package/src/generators/templates/typescript/src/constants.ts +0 -3
  26. package/src/generators/templates/typescript/src/creates/movie.ts +0 -43
  27. package/src/generators/templates/typescript/src/middleware.ts +0 -11
  28. package/src/generators/templates/typescript/src/test/creates.test.ts +0 -21
  29. package/src/generators/templates/typescript/src/test/triggers.test.ts +0 -25
  30. package/src/generators/templates/typescript/src/triggers/movie.ts +0 -29
  31. package/src/generators/templates/typescript/tsconfig.json +0 -17
@@ -0,0 +1,36 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import zapier from 'zapier-platform-core';
3
+
4
+ import App from '../index.js';
5
+ const appTester = zapier.createAppTester(App);
6
+
7
+ describe('session auth app', () => {
8
+ it('has an exchange for username/password', async () => {
9
+ const bundle = {
10
+ authData: {
11
+ username: 'bryan',
12
+ password: 'hunter2',
13
+ },
14
+ };
15
+
16
+ const newAuthData = await appTester(
17
+ App.authentication.sessionConfig.perform,
18
+ bundle
19
+ );
20
+
21
+ expect(newAuthData.sessionKey).toBe('secret');
22
+ });
23
+
24
+ it('has auth details added to every request', async () => {
25
+ const bundle = {
26
+ authData: {
27
+ sessionKey: 'secret',
28
+ },
29
+ };
30
+
31
+ const response = await appTester(App.authentication.test, bundle);
32
+
33
+ expect(response.status).toBe(200);
34
+ expect(response.request.headers['X-API-Key']).toBe('secret');
35
+ });
36
+ });
@@ -1,9 +1,6 @@
1
1
  <% if (hasAuth) { %>
2
- const {
3
- config: authentication,
4
- befores = [],
5
- afters = [],
6
- } = require('./authentication');
2
+ const authentication = require('./authentication');
3
+ const { befores = [], afters = [] } = require('./middleware');
7
4
  <% } %>
8
5
 
9
6
  module.exports = {
@@ -1,24 +1,21 @@
1
- import { version as platformVersion, defineApp } from 'zapier-platform-core';
1
+ import zapier, { defineApp } from 'zapier-platform-core';
2
2
 
3
- import packageJson from '../package.json';
3
+ import packageJson from '../package.json' with { type: 'json' };
4
4
 
5
- import MovieCreate from './creates/movie';
6
- import MovieTrigger from './triggers/movie';
7
- import authentication from './authentication';
8
- import { addBearerHeader } from './middleware';
5
+ import authentication from './authentication.js';
6
+ import { befores, afters } from './middleware.js';
9
7
 
10
8
  export default defineApp({
11
9
  version: packageJson.version,
12
- platformVersion,
10
+ platformVersion: zapier.version,
13
11
 
14
12
  authentication,
15
- beforeRequest: [addBearerHeader],
13
+ beforeRequest: [...befores],
14
+ afterResponse: [...afters],
16
15
 
17
- triggers: {
18
- [MovieTrigger.key]: MovieTrigger,
19
- },
16
+ // Add your triggers here for them to show up!
17
+ triggers: {},
20
18
 
21
- creates: {
22
- [MovieCreate.key]: MovieCreate,
23
- },
19
+ // Add your creates here for them to show up!
20
+ creates: {},
24
21
  });
@@ -0,0 +1,18 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ESNext",
4
+ "module": "NodeNext",
5
+ "moduleResolution": "NodeNext",
6
+ "resolveJsonModule": true,
7
+ "esModuleInterop": true,
8
+ "noUncheckedIndexedAccess": true,
9
+ "isolatedModules": true,
10
+ "noImplicitAny": false,
11
+ "skipLibCheck": true,
12
+ "outDir": "./dist",
13
+ "rootDir": "./src",
14
+ "strict": true
15
+ },
16
+ "include": ["./src/**/*.ts"],
17
+ "exclude": ["./**/*.test.ts"]
18
+ }
@@ -10,12 +10,12 @@ const { TEMPLATE_CHOICES, ProjectGenerator } = require('../../generators');
10
10
  class InitCommand extends BaseCommand {
11
11
  async perform() {
12
12
  const { path } = this.args;
13
- const { template, module } = this.flags;
13
+ const { template, module, language } = this.flags;
14
14
 
15
15
  const env = yeoman.createEnv();
16
16
  env.registerStub(ProjectGenerator, 'zapier:integration');
17
17
 
18
- await env.run('zapier:integration', { path, template, module });
18
+ await env.run('zapier:integration', { path, template, module, language });
19
19
 
20
20
  this.log();
21
21
  this.log(`A new integration has been created in directory "${path}".`);
@@ -36,6 +36,12 @@ InitCommand.flags = buildFlags({
36
36
  'Choose module type: CommonJS or ES Modules. Only enabled for Typescript and Minimal templates.',
37
37
  options: ['commonjs', 'esm'],
38
38
  }),
39
+ language: Flags.string({
40
+ char: 'l',
41
+ description:
42
+ 'Choose the language to use for your new integration. Defaults to JavaScript.',
43
+ options: ['javascript', 'typescript'],
44
+ }),
39
45
  },
40
46
  });
41
47
  InitCommand.args = {
@@ -49,6 +55,7 @@ InitCommand.examples = [
49
55
  'zapier init myapp',
50
56
  'zapier init ./path/myapp --template oauth2',
51
57
  'zapier init ./path/myapp --template minimal --module esm',
58
+ 'zapier init ./path/myapp --template oauth2 --language typescript',
52
59
  ];
53
60
  InitCommand.description = `Initialize a new Zapier integration with a project template.
54
61
 
@@ -982,6 +982,7 @@ class InvokeCommand extends BaseCommand {
982
982
  method: methodName,
983
983
  bundle: {
984
984
  inputData,
985
+ inputDataRaw: inputData, // At this point, inputData hasn't been transformed yet
985
986
  authData,
986
987
  meta,
987
988
  },
@@ -1013,6 +1014,8 @@ class InvokeCommand extends BaseCommand {
1013
1014
  );
1014
1015
  }
1015
1016
 
1017
+ // Preserve original inputData as inputDataRaw before type resolution
1018
+ const inputDataRaw = { ...inputData };
1016
1019
  inputData = resolveInputDataTypes(inputData, inputFields, timezone);
1017
1020
  methodName = `${actionTypePlural}.${action.key}.operation.perform`;
1018
1021
 
@@ -1022,6 +1025,7 @@ class InvokeCommand extends BaseCommand {
1022
1025
  method: methodName,
1023
1026
  bundle: {
1024
1027
  inputData,
1028
+ inputDataRaw,
1025
1029
  authData,
1026
1030
  meta,
1027
1031
  },
@@ -1,4 +1,3 @@
1
- const colors = require('colors/safe');
2
1
  const { Flags } = require('@oclif/core');
3
2
  const BaseCommand = require('../ZapierBaseCommand');
4
3
  const { buildFlags } = require('../buildFlags');
@@ -34,29 +33,6 @@ class VersionCommand extends BaseCommand {
34
33
  'No versions to show. Try adding one with the `zapier push` command',
35
34
  });
36
35
 
37
- this.logTable({
38
- headers: [],
39
- rows: [
40
- {
41
- version: `- ${colors.bold('Errors')}`,
42
- platform_version:
43
- 'Issues that will prevent your integration from functioning properly. They block you from pushing.',
44
- },
45
- {
46
- version: `- ${colors.bold('Publishing Tasks')}`,
47
- platform_version:
48
- 'To-dos that must be addressed before your integration can be included in the App Directory. They block you from promoting and publishing.',
49
- },
50
- {
51
- version: `- ${colors.bold('Warnings')}`,
52
- platform_version:
53
- "Issues and recommendations that need human reviews by Zapier before publishing your integration. They don't block.",
54
- },
55
- ],
56
- hasBorder: false,
57
- style: { head: [], 'padding-left': 0, 'padding-right': 0 },
58
- });
59
-
60
36
  if (versions.map((v) => v.user_count).filter((c) => c === null).length) {
61
37
  this.warn(
62
38
  'Some user counts are still being calculated - run this command again in ~10 seconds (or longer if your integration has lots of users).',