Milestone 0: import zappier billing, Verae middleware, and Zapier research

Compose-ready workspace: packages/zappier (rate card, portal, Stripe),
packages/verae-zapier-middleware (timestamp + NATS), packages/verae-zapier
(CLI app), vendor/zapier-platform, and research/zapier vendor corpus.

Gate 0 structure checks pass. Product code and research are not yet wired.
This commit is contained in:
George Lambert 2026-09-09 02:37:36 -04:00
commit b4150c8250
190 changed files with 6814366 additions and 0 deletions

View file

@ -0,0 +1,36 @@
// list of template (example) apps
// https://github.com/zapier?utf8=%E2%9C%93&q=zapier-platform-example-app-&type=&language=
module.exports = [
// basic
'minimal',
'trigger',
'search',
'create',
// auth types
'basic-auth',
'custom-auth',
'digest-auth',
'oauth2',
'oauth1-trello',
'oauth1-tumblr',
'oauth1-twitter',
'session-auth',
// features
'dynamic-dropdown',
'files',
'line-items',
'middleware',
'resource',
'rest-hooks',
'search-or-create',
// transpilers
'babel',
'typescript',
// full examples
'github',
'onedrive',
];

View file

@ -0,0 +1,6 @@
#!/usr/bin/env node
(async () => {
const oclif = await import('@oclif/core');
await oclif.execute({ development: false, dir: __dirname });
})();

View file

@ -0,0 +1,109 @@
const os = require('node:os');
const path = require('node:path');
const versionStore = require('./version-store');
const BASE_ENDPOINT = process.env.ZAPIER_BASE_ENDPOINT || 'https://zapier.com';
const API_PATH = '/api/platform/cli';
const ENDPOINT = process.env.ZAPIER_ENDPOINT || BASE_ENDPOINT + API_PATH;
const STARTER_REPO =
process.env.ZAPIER_STARTER_REPO || 'zapier/zapier-platform-example-app';
const AUTH_LOCATION_RAW = '~/.zapierrc';
const AUTH_LOCATION =
process.env.ZAPIER_AUTH_LOCATION || path.resolve(os.homedir(), '.zapierrc');
const CURRENT_APP_FILE = process.env.ZAPIER_CURRENT_APP_FILE || '.zapierapprc';
const PLATFORM_PACKAGE = 'zapier-platform-core';
const LEGACY_RUNNER_PACKAGE = 'zapier-platform-legacy-scripting-runner';
const BUILD_DIR = 'build';
const DEFINITION_PATH = `${BUILD_DIR}/definition.json`;
const BUILD_PATH = `${BUILD_DIR}/build.zip`;
const SOURCE_PATH = `${BUILD_DIR}/source.zip`;
const NODE_VERSION = versionStore[versionStore.length - 1].nodeVersion;
const LAMBDA_VERSION = `v${NODE_VERSION}`;
const NODE_VERSION_CLI_REQUIRES = '>=22'; // should be the oldest non-ETL version
const AUTH_KEY = 'deployKey';
const ANALYTICS_KEY = 'analyticsMode';
const ANALYTICS_MODES = {
enabled: 'enabled',
anonymous: 'anonymous',
disabled: 'disabled',
};
const packageJson = require('../package.json');
const PACKAGE_NAME = packageJson.name;
const PACKAGE_VERSION = packageJson.version;
const UPDATE_NOTIFICATION_INTERVAL = 1000 * 60 * 60 * 24 * 7; // one week
const CHECK_REF_DOC_LINK =
'https://docs.zapier.com/platform/publish/integration-checks-reference';
const ISSUES_URL =
'https://github.com/zapier/zapier-platform/issues/new/choose';
// can't just read from argv because they could have lots of extra data, such as
// [ '/Users/david/.nvm/versions/node/v10.13.0/bin/node',
// '/Users/david/projects/zapier/platform/node_modules/.bin/mocha',
// 'src/tests' ]
const argvStr = process.argv.join(' ');
const IS_TESTING =
argvStr.includes('mocha') ||
argvStr.includes('jest') ||
(process.env.NODE_ENV || '').toLowerCase().startsWith('test');
const MIN_TITLE_LENGTH = 2;
const MAX_DESCRIPTION_LENGTH = 140;
const EXAMPLE_CHANGELOG = `
## 3.0.0
Made some changes that affect app actions
1. Update the trigger/pr_review action, as well as changes for #456
2. Fix trigger/new_card #208
3. New action! create/add_contact
However, we also addressed fixed open issues!
- Fix #123 and an issue with create/send_message
## 2.0.0
* Fix some bugs.
* Major docs fixes.
## 1.0.0
Initial release to public.
`;
module.exports = {
ANALYTICS_KEY,
ANALYTICS_MODES,
API_PATH,
AUTH_KEY,
AUTH_LOCATION,
AUTH_LOCATION_RAW,
BASE_ENDPOINT,
BUILD_DIR,
BUILD_PATH,
CHECK_REF_DOC_LINK,
CURRENT_APP_FILE,
DEFINITION_PATH,
ENDPOINT,
IS_TESTING,
ISSUES_URL,
LAMBDA_VERSION,
LEGACY_RUNNER_PACKAGE,
MIN_TITLE_LENGTH,
MAX_DESCRIPTION_LENGTH,
NODE_VERSION,
NODE_VERSION_CLI_REQUIRES,
PACKAGE_NAME,
PACKAGE_VERSION,
PLATFORM_PACKAGE,
SOURCE_PATH,
STARTER_REPO,
UPDATE_NOTIFICATION_INTERVAL,
EXAMPLE_CHANGELOG,
};

View file

@ -0,0 +1,346 @@
const path = require('path');
const { merge } = require('lodash');
const filter = require('gulp-filter');
const { createGeneratorClass } = require('../utils/esm-wrapper');
const prettier = require('gulp-prettier');
const { PACKAGE_VERSION, PLATFORM_PACKAGE } = require('../constants');
const authFilesCodegen = require('../utils/auth-files-codegen');
const PullGeneratorPromise = require('./pull');
const writeGenericReadme = (gen) => {
gen.fs.copyTpl(
gen.templatePath('README.template.md'),
gen.destinationPath('README.md'),
{ name: gen.options.packageName },
);
};
const appendReadme = (gen) => {
const content = gen.fs.read(
gen.templatePath(gen.options.template, 'README.md'),
{ defaults: '' },
);
if (content) {
gen.fs.append(gen.destinationPath('README.md'), '\n' + content);
}
};
const writeGitignore = (gen) => {
gen.fs.copy(gen.templatePath('gitignore'), gen.destinationPath('.gitignore'));
};
const writeGenericPackageJson = (gen, packageJsonExtension) => {
const moduleExtension =
gen.options.module === 'esm'
? {
exports: './index.js',
type: 'module',
}
: {
main: 'index.js',
};
const fullExtension = merge(moduleExtension, packageJsonExtension);
gen.fs.writeJSON(
gen.destinationPath('package.json'),
merge(
{
name: gen.options.packageName,
version: '1.0.0',
description: '',
scripts: {
test: 'jest --testTimeout 10000',
},
dependencies: {
[PLATFORM_PACKAGE]: PACKAGE_VERSION,
},
devDependencies: {
jest: '^29.6.0',
},
private: true,
},
fullExtension,
),
);
};
const writeGenericTypeScriptPackageJson = (gen, packageJsonExtension) => {
gen.fs.writeJSON(
gen.destinationPath('package.json'),
merge(
{
name: gen.options.packageName,
version: '1.0.0',
description: '',
scripts: {
test: 'npm run build && vitest --run',
clean: 'rimraf ./dist ./build',
build: 'npm run clean && tsc',
dev: 'npm run build -- --watch',
'_zapier-build': 'npm run build',
},
dependencies: {
[PLATFORM_PACKAGE]: PACKAGE_VERSION,
},
devDependencies: {
rimraf: '^5.0.10',
typescript: '5.6.2',
vitest: '^2.1.2',
},
private: true,
exports: './dist/index.js',
type: 'module',
},
packageJsonExtension,
),
);
};
const writeGenericIndex = (gen, hasAuth) => {
const templatePath =
gen.options.module === 'esm'
? 'index-esm.template.js'
: 'index.template.js';
gen.fs.copyTpl(
gen.templatePath(templatePath),
gen.destinationPath('index.js'),
{ corePackageName: PLATFORM_PACKAGE, hasAuth },
);
};
const writeGenericTypescriptIndex = (gen) => {
gen.fs.copyTpl(
gen.templatePath('index.template.ts'),
gen.destinationPath('src/index.ts'),
{ corePackageName: PLATFORM_PACKAGE },
);
};
const authTypes = {
'basic-auth': 'basic',
'custom-auth': 'custom',
'digest-auth': 'digest',
'oauth1-trello': 'oauth1',
oauth2: 'oauth2',
'session-auth': 'session',
};
const writeGenericAuth = (gen) => {
const authType = authTypes[gen.options.template];
const content = authFilesCodegen[authType](gen.options.language);
const destPath = (key) =>
gen.options.language === 'typescript' ? `src/${key}.ts` : `${key}.js`;
Object.entries(content).forEach(([key, value]) => {
gen.fs.write(gen.destinationPath(destPath(key)), value);
});
};
const writeGenericAuthTest = (gen) => {
const authType = authTypes[gen.options.template];
const fileExtension = gen.options.language === 'typescript' ? 'ts' : 'js';
const destPath = gen.options.language === 'typescript' ? 'src/test' : 'test';
gen.fs.copyTpl(
gen.templatePath(
`authTests/${authType || 'generic'}.test.${fileExtension}`,
),
gen.destinationPath(`${destPath}/authentication.test.${fileExtension}`),
);
};
const writeGenericTest = (gen) => {
gen.fs.copyTpl(
gen.templatePath('authTests/generic.test.js'),
gen.destinationPath('test/example.test.js'),
);
};
// Write files for templates that demonstrate an auth type
const writeForAuthTemplate = (gen) => {
writeGitignore(gen);
writeGenericReadme(gen);
if (gen.options.language === 'typescript') {
writeGenericTypescriptIndex(gen);
writeGenericTypeScriptPackageJson(gen);
gen.fs.copyTpl(
gen.templatePath('tsconfig.template.json'),
gen.destinationPath('tsconfig.json'),
);
} else {
writeGenericIndex(gen, true);
writeGenericPackageJson(gen);
}
writeGenericAuth(gen);
writeGenericAuthTest(gen);
};
const writeForMinimalTemplate = (gen) => {
writeGitignore(gen);
writeGenericReadme(gen);
writeGenericPackageJson(gen);
writeGenericIndex(gen, false);
writeGenericTest(gen);
};
// Write files for "standalone" templates, which essentially just copies an
// example directory
const writeForStandaloneTemplate = (gen) => {
writeGitignore(gen);
writeGenericReadme(gen);
appendReadme(gen);
const packageJsonExtension = {
// Put template-specific package.json settings here, grouped by template
// names. This is going to used to extend the generic package.json.
files: {
dependencies: {
'form-data': '4.0.0',
},
},
}[gen.options.template];
writeGenericPackageJson(gen, packageJsonExtension);
gen.fs.copy(
gen.templatePath(gen.options.template, '**', '*.{js,json,ts}'),
gen.destinationPath(),
);
};
const TEMPLATE_ROUTES = {
'basic-auth': writeForAuthTemplate,
callback: writeForStandaloneTemplate,
'custom-auth': writeForAuthTemplate,
'digest-auth': writeForAuthTemplate,
'dynamic-dropdown': writeForStandaloneTemplate,
files: writeForStandaloneTemplate,
'line-items': writeForStandaloneTemplate,
minimal: writeForMinimalTemplate,
'oauth1-trello': writeForAuthTemplate,
oauth2: writeForAuthTemplate,
openai: writeForStandaloneTemplate,
'search-or-create': writeForStandaloneTemplate,
'session-auth': writeForAuthTemplate,
};
const ESM_SUPPORTED_TEMPLATES = ['minimal'];
// Which templates can be used with the --language typescript flag
const TS_SUPPORTED_TEMPLATES = [
'basic-auth',
'custom-auth',
'digest-auth',
'oauth1-trello',
'oauth2',
'session-auth',
];
const TEMPLATE_CHOICES = Object.keys(TEMPLATE_ROUTES);
const ProjectGeneratorPromise = createGeneratorClass((Generator) => {
return class ProjectGenerator extends Generator {
initializing() {
this.sourceRoot(path.resolve(__dirname, 'templates'));
this.destinationRoot(path.resolve(this.options.path));
const jsFilter = filter(['*.js', '*.json', '*.ts'], { restore: true });
this.queueTransformStream(
{ disabled: true },
jsFilter,
prettier({ singleQuote: true }),
jsFilter.restore,
);
}
async prompting() {
if (!this.options.template) {
// Filter template choices based on language and module type
let templateChoices = TEMPLATE_CHOICES;
let defaultTemplate = 'minimal';
// TypeScript filtering takes precedence over ESM filtering
if (this.options.language === 'typescript') {
templateChoices = TS_SUPPORTED_TEMPLATES;
defaultTemplate = 'basic-auth';
} else if (this.options.module === 'esm') {
templateChoices = ESM_SUPPORTED_TEMPLATES;
defaultTemplate = 'minimal'; // minimal is the only ESM template
}
this.answers = await this.prompt([
{
type: 'list',
name: 'template',
choices: templateChoices,
message: 'Choose a project template to start with:',
default: defaultTemplate,
},
]);
this.options.template = this.answers.template;
}
if (
ESM_SUPPORTED_TEMPLATES.includes(this.options.template) &&
!this.options.module
) {
this.answers = await this.prompt([
{
type: 'list',
name: 'module',
choices: ['esm', 'commonjs'],
message: 'Choose module type:',
default: 'esm',
},
]);
this.options.module = this.answers.module;
}
if (this.options.language) {
if (this.options.language === 'typescript') {
// check if the template supports typescript
if (!TS_SUPPORTED_TEMPLATES.includes(this.options.template)) {
throw new Error(
'Typescript is not supported for this template, please use a different template or set the language to javascript. Supported templates: ' +
TS_SUPPORTED_TEMPLATES.join(', '),
);
}
// if they try to combine typescript with commonjs, throw an error
if (this.options.module === 'commonjs') {
throw new Error('Typescript is not supported for commonjs');
} // esm is supported for typescript templates
}
} else {
// default to javascript for the language if it's not set
this.options.language = 'javascript';
}
if (
!ESM_SUPPORTED_TEMPLATES.includes(this.options.template) &&
this.options.module === 'esm' &&
this.options.language === 'javascript'
) {
throw new Error(
'ESM is not supported for this template, please use a different template, set the module to commonjs, or try setting the language to Typescript',
);
}
}
writing() {
this.options.packageName = path.basename(this.options.path);
const writeFunc = TEMPLATE_ROUTES[this.options.template];
writeFunc(this);
}
};
});
module.exports = {
TEMPLATE_CHOICES,
ESM_SUPPORTED_TEMPLATES,
TS_SUPPORTED_TEMPLATES,
PullGenerator: PullGeneratorPromise,
ProjectGenerator: ProjectGeneratorPromise,
};

View file

@ -0,0 +1,55 @@
const colors = require('colors/safe');
const debug = require('debug')('zapier:pull');
const inquirer = require('inquirer');
const path = require('path');
const { createGeneratorClass } = require('../utils/esm-wrapper');
const maybeOverwriteFiles = async (gen) => {
const dstDir = gen.options.dstDir;
const srcDir = gen.options.srcDir;
for (const file of gen.options.sourceFiles) {
gen.fs.copy(path.join(srcDir, file), path.join(dstDir, file), gen.options);
}
};
// Export a factory function that creates the PullGenerator class
module.exports = createGeneratorClass((Generator) => {
return class PullGenerator extends Generator {
initializing() {
debug('SRC', this.options.sourceFiles);
}
prompting() {
const prompts = [
{
type: 'confirm',
name: 'confirm',
message: `Warning: You are about to overwrite existing files.
Before proceeding, please make sure you have saved your work. Consider creating a backup or saving your current state in a git branch.
If presented with a series of options ('ynarxdeiH'), you may
press Enter to view more details about each option. For example, 'x' will abort the process.
Do you want to continue?`,
default: false,
},
];
return inquirer.prompt(prompts).then((answers) => {
if (!answers.confirm) {
this.log(colors.green('zapier pull cancelled'));
process.exit(1);
}
});
}
writing() {
maybeOverwriteFiles(this);
}
end() {
this.log(colors.green('zapier pull completed successfully'));
}
};
});

View file

@ -0,0 +1,34 @@
# <%= name %>
This Zapier integration project is generated by the `zapier-platform init` CLI command.
These are what you normally do next:
```bash
# Install dependencies
npm install --ignore-scripts # or you can use pnpm or yarn
# Run tests
zapier-platform test
# Register the integration on Zapier if you haven't
zapier-platform register "App Title"
# Or you can link to an existing integration on Zapier
zapier-platform link
# Push it to Zapier
zapier-platform push
```
Then, to add more features, you can use the `zapier-platform scaffold` command, for example:
```bash
# Add a trigger
zapier-platform scaffold trigger contact
# Add an action
zapier-platform scaffold create contact
```
Find out more on the latest docs: https://docs.zapier.com/platform

View file

@ -0,0 +1,43 @@
/* globals describe, it, expect */
const zapier = require('zapier-platform-core');
const App = require('../index');
const appTester = zapier.createAppTester(App);
describe('basic auth', () => {
it('automatically has Authorize Header add', async () => {
const bundle = {
authData: {
username: 'user',
password: 'secret',
},
};
const response = await appTester(App.authentication.test, bundle);
expect(response.status).toBe(200);
expect(response.request.headers.Authorization).toBe(
'Basic dXNlcjpzZWNyZXQ='
);
});
it('fails on bad auth', async () => {
const bundle = {
authData: {
username: 'user',
password: 'badpwd',
},
};
try {
await appTester(App.authentication.test, bundle);
} catch (err) {
expect(err.message).toContain(
'The username and/or password you supplied is incorrect'
);
return;
}
throw new Error('appTester should have thrown');
});
});

View file

@ -0,0 +1,42 @@
import { describe, expect, it } from 'vitest';
import zapier from 'zapier-platform-core';
import App from '../index.js';
const appTester = zapier.createAppTester(App);
describe('basic auth', () => {
it('automatically has Authorize Header add', async () => {
const bundle = {
authData: {
username: 'user',
password: 'secret',
},
};
const response = await appTester(App.authentication.test, bundle);
expect(response.status).toBe(200);
expect(response.request.headers.Authorization).toBe(
'Basic dXNlcjpzZWNyZXQ='
);
});
it('fails on bad auth', async () => {
const bundle = {
authData: {
username: 'user',
password: 'badpwd',
},
};
try {
await appTester(App.authentication.test, bundle);
} catch (err) {
expect(err.message).toContain(
'The username and/or password you supplied is incorrect'
);
return;
}
throw new Error('appTester should have thrown');
});
});

View file

@ -0,0 +1,35 @@
/* globals describe, it, expect */
const zapier = require('zapier-platform-core');
const App = require('../index');
const appTester = zapier.createAppTester(App);
describe('custom auth', () => {
it('passes authentication and returns json', async () => {
const bundle = {
authData: {
apiKey: 'secret',
},
};
const response = await appTester(App.authentication.test, bundle);
expect(response.data).toHaveProperty('username');
});
it('fails on bad auth', async () => {
const bundle = {
authData: {
apiKey: 'bad',
},
};
try {
await appTester(App.authentication.test, bundle);
} catch (error) {
expect(error.message).toContain('The API Key you supplied is incorrect');
return;
}
throw new Error('appTester should have thrown');
});
});

View file

@ -0,0 +1,34 @@
import { describe, expect, it } from 'vitest';
import zapier from 'zapier-platform-core';
import App from '../index.js';
const appTester = zapier.createAppTester(App);
describe('custom auth', () => {
it('passes authentication and returns json', async () => {
const bundle = {
authData: {
apiKey: 'secret',
},
};
const response = await appTester(App.authentication.test, bundle);
expect(response.data).toHaveProperty('username');
});
it('fails on bad auth', async () => {
const bundle = {
authData: {
apiKey: 'bad',
},
};
try {
await appTester(App.authentication.test, bundle);
} catch (error) {
expect(error.message).toContain('The API Key you supplied is incorrect');
return;
}
throw new Error('appTester should have thrown');
});
});

View file

@ -0,0 +1,44 @@
/* globals describe, it, expect */
const zapier = require('zapier-platform-core');
const App = require('../index');
const appTester = zapier.createAppTester(App);
describe('digest auth', () => {
it('correctly authenticates', async () => {
// Try changing the values of username or password to see how the test method behaves
const bundle = {
authData: {
username: 'myuser',
password: 'mypass',
},
};
const response = await appTester(App.authentication.test, bundle);
expect(response.status).toBe(200);
expect(response.data.authorized).toBe(true);
expect(response.data.user).toBe('myuser');
});
it('fails on bad auth', async () => {
// Try changing the values of username or password to see how the test method behaves
const bundle = {
authData: {
username: 'user',
password: 'badpwd',
},
};
try {
await appTester(App.authentication.test, bundle);
} catch (err) {
expect(err.message).toContain(
'The username and/or password you supplied is incorrect'
);
return;
}
throw new Error('appTester should have thrown');
});
});

View file

@ -0,0 +1,43 @@
import { describe, expect, it } from 'vitest';
import zapier from 'zapier-platform-core';
import App from '../index.js';
const appTester = zapier.createAppTester(App);
describe('digest auth', () => {
it('correctly authenticates', async () => {
// Try changing the values of username or password to see how the test method behaves
const bundle = {
authData: {
username: 'myuser',
password: 'mypass',
},
};
const response = await appTester(App.authentication.test, bundle);
expect(response.status).toBe(200);
expect(response.data.authorized).toBe(true);
expect(response.data.user).toBe('myuser');
});
it('fails on bad auth', async () => {
// Try changing the values of username or password to see how the test method behaves
const bundle = {
authData: {
username: 'user',
password: 'badpwd',
},
};
try {
await appTester(App.authentication.test, bundle);
} catch (err) {
expect(err.message).toContain(
'The username and/or password you supplied is incorrect'
);
return;
}
throw new Error('appTester should have thrown');
});
});

View file

@ -0,0 +1,7 @@
/* globals describe, it, expect */
describe('addition ', () => {
it('should work', () => {
expect(1 + 1).toEqual(2);
});
});

View file

@ -0,0 +1,65 @@
/* globals describe, it, expect, beforeAll */
const zapier = require('zapier-platform-core');
zapier.tools.env.inject(); // read from the .env file
const App = require('../index');
const appTester = zapier.createAppTester(App);
// You should create a `.env` file and populate it with your actual Trello
// client ID and secret (called "API Key" and "API Secret" by Trello), which you
// can find on https://trello.com/app-key.
// The `.env` file should look like
/*
CLIENT_ID=<trello_api_key>
CLIENT_SECRET=<trello_api_secret>
*/
// then you can delete the following 2 lines
process.env.CLIENT_ID = process.env.CLIENT_ID || '<trello_api_key>';
process.env.CLIENT_SECRET = process.env.CLIENT_SECRET || '<trello_api_secret>';
describe('oauth1 app', () => {
beforeAll(() => {
// It's a good idea to store your Client ID and Secret in the environment rather than in code.
if (!(process.env.CLIENT_ID && process.env.CLIENT_SECRET)) {
throw new Error(
`Before running the tests, make sure CLIENT_ID and CLIENT_SECRET are available in the environment.`
);
}
});
it('fetch a request token', async () => {
const bundle = {
inputData: {
// You should add your redirect URI to https://trello.com/app-key
redirect_uri: 'https://zapier.com',
},
};
const tokens = await appTester(
App.authentication.oauth1Config.getRequestToken,
bundle
);
expect(tokens).toHaveProperty('oauth_token');
expect(tokens).toHaveProperty('oauth_token_secret');
});
it('generates an authorize URL', async () => {
const bundle = {
// In production, these will be generated by Zapier and set automatically
inputData: {
oauth_token: '4444',
redirect_uri: 'https://zapier.com/',
},
};
const authorizeUrl = await appTester(
App.authentication.oauth1Config.authorizeUrl,
bundle
);
expect(authorizeUrl).toBe(
'https://trello.com/1/OAuthAuthorizeToken?oauth_token=4444&name=Zapier%2FTrello%20OAuth1%20Test'
);
});
});

View file

@ -0,0 +1,63 @@
import { describe, expect, it, beforeAll } from 'vitest';
import zapier from 'zapier-platform-core';
import App from '../index.js';
const appTester = zapier.createAppTester(App);
// Only defining the env vars here so the tests out of the box.
// You should create a `.env` file and populate it with your actual Trello
// client ID and secret (called "API Key" and "API Secret" by Trello), which you
// can find on https://trello.com/app-key.
// The `.env` file should look like
/*
CLIENT_ID=<trello_api_key>
CLIENT_SECRET=<trello_api_secret>
*/
// then you can delete the following 2 lines
process.env.CLIENT_ID = process.env.CLIENT_ID || '<trello_api_key>';
process.env.CLIENT_SECRET = process.env.CLIENT_SECRET || '<trello_api_secret>';
describe('oauth1 app', () => {
beforeAll(() => {
// It's a good idea to store your Client ID and Secret in the environment rather than in code.
if (!(process.env.CLIENT_ID && process.env.CLIENT_SECRET)) {
throw new Error(
`Before running the tests, make sure CLIENT_ID and CLIENT_SECRET are available in the environment.`
);
}
});
it('fetch a request token', async () => {
const bundle = {
inputData: {
// You should add your redirect URI to https://trello.com/app-key
redirect_uri: 'https://zapier.com',
},
};
const tokens = await appTester(
App.authentication.oauth1Config.getRequestToken,
bundle
);
expect(tokens).toHaveProperty('oauth_token');
expect(tokens).toHaveProperty('oauth_token_secret');
});
it('generates an authorize URL', async () => {
const bundle = {
// In production, these will be generated by Zapier and set automatically
inputData: {
oauth_token: '4444',
redirect_uri: 'https://zapier.com/',
},
};
const authorizeUrl = await appTester(
App.authentication.oauth1Config.authorizeUrl,
bundle
);
expect(authorizeUrl).toBe(
'https://trello.com/1/OAuthAuthorizeToken?oauth_token=4444&name=Zapier%2FTrello%20OAuth1%20Test'
);
});
});

View file

@ -0,0 +1,118 @@
/* globals describe, it, expect, beforeAll */
const zapier = require('zapier-platform-core');
zapier.tools.env.inject(); // read from the .env file
const App = require('../index');
const appTester = zapier.createAppTester(App);
// Only here so the tests out of the box.
// You should create a `.env` file and populate it with the necessarily configuration
// it should look like:
/*
CLIENT_ID=1234
CLIENT_SECRET=asdf
*/
// then you can delete the following 2 lines
process.env.CLIENT_ID = process.env.CLIENT_ID || '1234';
process.env.CLIENT_SECRET = process.env.CLIENT_SECRET || 'asdf';
describe('oauth2 app', () => {
beforeAll(() => {
// It's a good idea to store your Client ID and Secret in the environment rather than in code.
if (!(process.env.CLIENT_ID && process.env.CLIENT_SECRET)) {
throw new Error(
`Before running the tests, make sure CLIENT_ID and CLIENT_SECRET are available in the environment.`
);
}
});
it('generates an authorize URL', async () => {
const bundle = {
// In production, these will be generated by Zapier and set automatically
inputData: {
state: '4444',
redirect_uri: 'https://zapier.com/',
},
environment: {
CLIENT_ID: process.env.CLIENT_ID,
CLIENT_SECRET: process.env.CLIENT_SECRET,
},
};
const authorizeUrl = await appTester(
App.authentication.oauth2Config.authorizeUrl,
bundle
);
expect(authorizeUrl).toBe(
'https://auth-json-server.zapier-staging.com/oauth/authorize?client_id=1234&state=4444&redirect_uri=https%3A%2F%2Fzapier.com%2F&response_type=code'
);
});
it('can fetch an access token', async () => {
const bundle = {
inputData: {
// In production, Zapier passes along whatever code your API set in the query params when it redirects
// the user's browser to the `redirect_uri`
code: 'one_time_code',
},
environment: {
CLIENT_ID: process.env.CLIENT_ID,
CLIENT_SECRET: process.env.CLIENT_SECRET,
},
cleanedRequest: {
querystring: {
accountDomain: 'test-account',
code: 'one_time_code',
},
},
rawRequest: {
querystring: '?accountDomain=test-account&code=one_time_code',
},
};
const result = await appTester(
App.authentication.oauth2Config.getAccessToken,
bundle
);
expect(result.access_token).toBe('a_token');
expect(result.refresh_token).toBe('a_refresh_token');
});
it('can refresh the access token', async () => {
const bundle = {
// In production, Zapier provides these. For testing, we have hard-coded them.
// When writing tests for your own app, you should consider exporting them and doing process.env.MY_ACCESS_TOKEN
authData: {
access_token: 'a_token',
refresh_token: 'a_refresh_token',
},
environment: {
CLIENT_ID: process.env.CLIENT_ID,
CLIENT_SECRET: process.env.CLIENT_SECRET,
},
};
const result = await appTester(
App.authentication.oauth2Config.refreshAccessToken,
bundle
);
expect(result.access_token).toBe('a_token');
});
it('includes the access token in future requests', async () => {
const bundle = {
authData: {
access_token: 'a_token',
refresh_token: 'a_refresh_token',
},
};
const response = await appTester(App.authentication.test, bundle);
expect(response.data).toHaveProperty('username');
expect(response.data.username).toBe('Bret');
});
});

View file

@ -0,0 +1,115 @@
import { describe, expect, it, beforeAll } from 'vitest';
import zapier from 'zapier-platform-core';
import App from '../index.js';
const appTester = zapier.createAppTester(App);
// Only defining the env vars here so the tests out of the box.
// You should create a `.env` file and populate it with the necessarily configuration
// it should look like:
/*
CLIENT_ID=1234
CLIENT_SECRET=asdf
*/
// then you can delete the following 2 lines
process.env.CLIENT_ID = process.env.CLIENT_ID || '1234';
process.env.CLIENT_SECRET = process.env.CLIENT_SECRET || 'asdf';
describe('authentication', () => {
beforeAll(() => {
// It's a good idea to store your Client ID and Secret in the environment rather than in code.
if (!(process.env.CLIENT_ID && process.env.CLIENT_SECRET)) {
throw new Error(
`Before running the tests, make sure CLIENT_ID and CLIENT_SECRET are available in the environment.`,
);
}
});
it('generates an authorize URL', async () => {
const bundle = {
// In production, these will be generated by Zapier and set automatically
inputData: {
state: '4444',
redirect_uri: 'https://zapier.com/',
},
environment: {
CLIENT_ID: process.env.CLIENT_ID,
CLIENT_SECRET: process.env.CLIENT_SECRET,
},
};
const authorizeUrl = await appTester(
App.authentication.oauth2Config.authorizeUrl,
bundle,
);
expect(authorizeUrl).toBe(
'https://auth-json-server.zapier-staging.com/oauth/authorize?client_id=1234&state=4444&redirect_uri=https%3A%2F%2Fzapier.com%2F&response_type=code',
);
});
it('can fetch an access token', async () => {
const bundle = {
inputData: {
// In production, Zapier passes along whatever code your API set in the query params when it redirects
// the user's browser to the `redirect_uri`
code: 'one_time_code',
},
environment: {
CLIENT_ID: process.env.CLIENT_ID,
CLIENT_SECRET: process.env.CLIENT_SECRET,
},
cleanedRequest: {
querystring: {
accountDomain: 'test-account',
code: 'one_time_code',
},
},
rawRequest: {
querystring: '?accountDomain=test-account&code=one_time_code',
},
};
const result = await appTester(
App.authentication.oauth2Config.getAccessToken,
bundle,
);
expect(result.access_token).toBe('a_token');
expect(result.refresh_token).toBe('a_refresh_token');
});
it('can refresh the access token', async () => {
const bundle = {
// In production, Zapier provides these. For testing, we have hard-coded them.
// When writing tests for your own app, you should consider exporting them and doing process.env.MY_ACCESS_TOKEN
authData: {
access_token: 'a_token',
refresh_token: 'a_refresh_token',
},
environment: {
CLIENT_ID: process.env.CLIENT_ID,
CLIENT_SECRET: process.env.CLIENT_SECRET,
},
};
const result = await appTester(
App.authentication.oauth2Config.refreshAccessToken,
bundle,
);
expect(result.access_token).toBe('a_token');
});
it('includes the access token in future requests', async () => {
const bundle = {
authData: {
access_token: 'a_token',
refresh_token: 'a_refresh_token',
},
};
const response = await appTester(App.authentication.test, bundle);
expect(response.data).toHaveProperty('username');
expect(response.data.username).toBe('Bret');
});
});

View file

@ -0,0 +1,37 @@
/* globals describe, it, expect */
const zapier = require('zapier-platform-core');
const App = require('../index');
const appTester = zapier.createAppTester(App);
describe('session auth app', () => {
it('has an exchange for username/password', async () => {
const bundle = {
authData: {
username: 'bryan',
password: 'hunter2',
},
};
const newAuthData = await appTester(
App.authentication.sessionConfig.perform,
bundle
);
expect(newAuthData.sessionKey).toBe('secret');
});
it('has auth details added to every request', async () => {
const bundle = {
authData: {
sessionKey: 'secret',
},
};
const response = await appTester(App.authentication.test, bundle);
expect(response.status).toBe(200);
expect(response.request.headers['X-API-Key']).toBe('secret');
});
});

View file

@ -0,0 +1,36 @@
import { describe, expect, it } from 'vitest';
import zapier from 'zapier-platform-core';
import App from '../index.js';
const appTester = zapier.createAppTester(App);
describe('session auth app', () => {
it('has an exchange for username/password', async () => {
const bundle = {
authData: {
username: 'bryan',
password: 'hunter2',
},
};
const newAuthData = await appTester(
App.authentication.sessionConfig.perform,
bundle
);
expect(newAuthData.sessionKey).toBe('secret');
});
it('has auth details added to every request', async () => {
const bundle = {
authData: {
sessionKey: 'secret',
},
};
const response = await appTester(App.authentication.test, bundle);
expect(response.status).toBe(200);
expect(response.request.headers['X-API-Key']).toBe('secret');
});
});

View file

@ -0,0 +1,5 @@
# The "Callback" Template
This example has a create showcasing the `performResume` callback function.
Find out more in the docs: https://github.com/zapier/zapier-platform/blob/main/packages/cli#zgeneratecallbackurl.

Some files were not shown because too many files have changed in this diff Show more