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:
commit
b4150c8250
1364 changed files with 6814366 additions and 0 deletions
6
vendor/zapier-platform/example-apps/resource/.gitignore
vendored
Normal file
6
vendor/zapier-platform/example-apps/resource/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
build
|
||||
docs
|
||||
node_modules
|
||||
*.log
|
||||
.environment
|
||||
.env
|
||||
7
vendor/zapier-platform/example-apps/resource/.travis.yml
vendored
Normal file
7
vendor/zapier-platform/example-apps/resource/.travis.yml
vendored
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
language: node_js
|
||||
node_js:
|
||||
- 8.10.0
|
||||
before_script: 'npm install -g zapier-platform-cli'
|
||||
script: 'zapier test'
|
||||
notifications:
|
||||
email: false
|
||||
7
vendor/zapier-platform/example-apps/resource/README.md
vendored
Normal file
7
vendor/zapier-platform/example-apps/resource/README.md
vendored
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# "Resource" Example App For Zapier Platform
|
||||
|
||||
[](https://travis-ci.org/zapier/zapier-platform-example-app-resource)
|
||||
|
||||
A barebones app that has a resource defined.
|
||||
|
||||
> We recommend using the zapier-platform-cli and `zapier-platform init .` to create an app - you’ll be presented with a list of currently available templates to start with.
|
||||
36
vendor/zapier-platform/example-apps/resource/index.js
vendored
Normal file
36
vendor/zapier-platform/example-apps/resource/index.js
vendored
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
const Recipe = require('./resources/recipe');
|
||||
|
||||
const addAuthHeader = (request, z, bundle) => {
|
||||
// Hard-coded authentication just for demo
|
||||
request.headers['X-API-Key'] = 'secret';
|
||||
return request;
|
||||
};
|
||||
|
||||
// Now we can roll up all our behaviors in an App.
|
||||
const App = {
|
||||
// This is just shorthand to reference the installed dependencies you have. Zapier will
|
||||
// need to know these before we can upload
|
||||
version: require('./package.json').version,
|
||||
platformVersion: require('zapier-platform-core').version,
|
||||
|
||||
beforeRequest: [addAuthHeader],
|
||||
|
||||
afterResponse: [],
|
||||
|
||||
// If you want your resource to show up, you better include it here!
|
||||
resources: {
|
||||
[Recipe.key]: Recipe,
|
||||
},
|
||||
|
||||
// If you want your trigger to show up, you better include it here!
|
||||
triggers: {},
|
||||
|
||||
// If you want your searches to show up, you better include it here!
|
||||
searches: {},
|
||||
|
||||
// If you want your creates to show up, you better include it here!
|
||||
creates: {},
|
||||
};
|
||||
|
||||
// Finally, export the app.
|
||||
module.exports = App;
|
||||
25
vendor/zapier-platform/example-apps/resource/package.json
vendored
Normal file
25
vendor/zapier-platform/example-apps/resource/package.json
vendored
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
{
|
||||
"name": "zapier-platform-example-app-resource",
|
||||
"version": "1.0.0",
|
||||
"description": "An example app for the Zapier platform.",
|
||||
"repository": "zapier/zapier-platform-example-app-resource",
|
||||
"homepage": "https://zapier.com/",
|
||||
"author": "Bryan Helmig <bryan@zapier.com>",
|
||||
"license": "BSD-3-Clause",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "mocha --recursive"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8.10.0",
|
||||
"npm": ">=5.6.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"zapier-platform-core": "19.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"mocha": "^5.2.0",
|
||||
"should": "^13.2.0"
|
||||
},
|
||||
"private": true
|
||||
}
|
||||
173
vendor/zapier-platform/example-apps/resource/resources/recipe.js
vendored
Normal file
173
vendor/zapier-platform/example-apps/resource/resources/recipe.js
vendored
Normal file
|
|
@ -0,0 +1,173 @@
|
|||
const _sharedBaseUrl = 'https://auth-json-server.zapier-staging.com';
|
||||
|
||||
const getRecipe = (z, bundle) => {
|
||||
return z
|
||||
.request({
|
||||
url: `${_sharedBaseUrl}/recipes/${bundle.inputData.id}`,
|
||||
})
|
||||
.then((response) => response.data);
|
||||
};
|
||||
|
||||
const listRecipes = (z, bundle) => {
|
||||
return z
|
||||
.request({
|
||||
url: _sharedBaseUrl + '/recipes',
|
||||
params: {
|
||||
style: bundle.inputData.style,
|
||||
},
|
||||
})
|
||||
.then((response) => response.data);
|
||||
};
|
||||
|
||||
const createRecipe = (z, bundle) => {
|
||||
const requestOptions = {
|
||||
url: _sharedBaseUrl + '/recipes',
|
||||
method: 'POST',
|
||||
body: {
|
||||
name: bundle.inputData.name,
|
||||
directions: bundle.inputData.directions,
|
||||
authorId: bundle.inputData.authorId,
|
||||
},
|
||||
headers: {
|
||||
'content-type': 'application/json',
|
||||
},
|
||||
};
|
||||
|
||||
return z.request(requestOptions).then((response) => response.data);
|
||||
};
|
||||
|
||||
const searchRecipe = (z, bundle) => {
|
||||
return z
|
||||
.request({
|
||||
url: _sharedBaseUrl + '/recipes',
|
||||
params: {
|
||||
nameSearch: bundle.inputData.name,
|
||||
},
|
||||
})
|
||||
.then((response) => {
|
||||
const matchingRecipes = response.data;
|
||||
|
||||
// Only return the first matching recipe
|
||||
if (matchingRecipes && matchingRecipes.length) {
|
||||
return [matchingRecipes[0]];
|
||||
}
|
||||
|
||||
return [];
|
||||
});
|
||||
};
|
||||
|
||||
const sample = {
|
||||
id: 1,
|
||||
createdAt: 1472069465,
|
||||
name: 'Best Spagetti Ever',
|
||||
authorId: 1,
|
||||
directions: '1. Boil Noodles\n2.Serve with sauce',
|
||||
style: 'italian',
|
||||
};
|
||||
|
||||
// This file exports a Recipe resource. The definition below contains all of the keys available,
|
||||
// and implements the list and create methods.
|
||||
module.exports = {
|
||||
key: 'recipe',
|
||||
noun: 'Recipe',
|
||||
// The get method is used by Zapier to fetch a complete representation of a record. This is helpful when the HTTP
|
||||
// response from a create call only return an ID, or a search that only returns a minimuml representation of the
|
||||
// record. Zapier will follow these up with the get() to retrieve the entire object.
|
||||
get: {
|
||||
display: {
|
||||
label: 'Get Recipe',
|
||||
description: 'Gets a recipe.',
|
||||
},
|
||||
operation: {
|
||||
inputFields: [{ key: 'id', required: true }],
|
||||
perform: getRecipe,
|
||||
sample: sample,
|
||||
},
|
||||
},
|
||||
// The list method on this resource becomes a Trigger on the app. Zapier will use polling to watch for new records
|
||||
list: {
|
||||
display: {
|
||||
label: 'New Recipe',
|
||||
description: 'Trigger when a new recipe is added.',
|
||||
},
|
||||
operation: {
|
||||
inputFields: [
|
||||
{
|
||||
key: 'style',
|
||||
type: 'string',
|
||||
helpText: 'Explain what style of cuisine this is.',
|
||||
},
|
||||
],
|
||||
perform: listRecipes,
|
||||
sample: sample,
|
||||
},
|
||||
},
|
||||
// If your app supports webhooks, you can define a hook method instead of a list method.
|
||||
// Zapier will turn this into a webhook Trigger on the app.
|
||||
// hook: {
|
||||
//
|
||||
// },
|
||||
|
||||
// The create method on this resource becomes a Write on this app
|
||||
create: {
|
||||
display: {
|
||||
label: 'Create Recipe',
|
||||
description: 'Creates a new recipe.',
|
||||
},
|
||||
operation: {
|
||||
inputFields: [
|
||||
{ key: 'name', required: true, type: 'string' },
|
||||
{
|
||||
key: 'directions',
|
||||
required: true,
|
||||
type: 'text',
|
||||
helpText: 'Explain how should one make the recipe, step by step.',
|
||||
},
|
||||
{
|
||||
key: 'authorId',
|
||||
required: true,
|
||||
type: 'integer',
|
||||
label: 'Author ID',
|
||||
},
|
||||
{
|
||||
key: 'style',
|
||||
required: false,
|
||||
type: 'string',
|
||||
helpText: 'Explain what style of cuisine this is.',
|
||||
},
|
||||
],
|
||||
perform: createRecipe,
|
||||
sample: sample,
|
||||
},
|
||||
},
|
||||
// The search method on this resource becomes a Search on this app
|
||||
search: {
|
||||
display: {
|
||||
label: 'Find Recipe',
|
||||
description: 'Finds an existing recipe by name.',
|
||||
},
|
||||
operation: {
|
||||
inputFields: [{ key: 'name', required: true, type: 'string' }],
|
||||
perform: searchRecipe,
|
||||
sample: sample,
|
||||
},
|
||||
},
|
||||
|
||||
// In cases where Zapier needs to show an example record to the user, but we are unable to get a live example
|
||||
// from the API, Zapier will fallback to this hard-coded sample. It should reflect the data structure of
|
||||
// returned records, and have obviously dummy values that we can show to any user.
|
||||
sample: sample,
|
||||
|
||||
// If the resource can have fields that are custom on a per-user basis, define a function to fetch the custom
|
||||
// field definitions. The result will be used to augment the sample.
|
||||
// outputFields: () => { return []; }
|
||||
// Alternatively, a static field definition should be provided, to specify labels for the fields
|
||||
outputFields: [
|
||||
{ key: 'id', label: 'ID' },
|
||||
{ key: 'createdAt', label: 'Created At' },
|
||||
{ key: 'name', label: 'Name' },
|
||||
{ key: 'directions', label: 'Directions' },
|
||||
{ key: 'authorId', label: 'Author ID' },
|
||||
{ key: 'style', label: 'Style' },
|
||||
],
|
||||
};
|
||||
77
vendor/zapier-platform/example-apps/resource/test/resources/recipe.js
vendored
Normal file
77
vendor/zapier-platform/example-apps/resource/test/resources/recipe.js
vendored
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
/* globals describe, it */
|
||||
|
||||
require('should');
|
||||
|
||||
const zapier = require('zapier-platform-core');
|
||||
|
||||
const App = require('../../index');
|
||||
const appTester = zapier.createAppTester(App);
|
||||
|
||||
describe('recipe resource', () => {
|
||||
it('should get an existing recipe', (done) => {
|
||||
const bundle = {
|
||||
inputData: {
|
||||
id: 1,
|
||||
},
|
||||
};
|
||||
|
||||
appTester(App.resources.recipe.get.operation.perform, bundle)
|
||||
.then((results) => {
|
||||
results.name.should.eql('name 1');
|
||||
results.directions.should.eql('directions 1');
|
||||
done();
|
||||
})
|
||||
.catch(done);
|
||||
});
|
||||
|
||||
it('should list existing recipes', (done) => {
|
||||
const bundle = {
|
||||
inputData: {
|
||||
style: 'style 2',
|
||||
},
|
||||
};
|
||||
|
||||
appTester(App.resources.recipe.list.operation.perform, bundle)
|
||||
.then((results) => {
|
||||
results.length.should.above(0);
|
||||
|
||||
const firstRecipe = results[0];
|
||||
firstRecipe.name.should.eql('name 2');
|
||||
firstRecipe.directions.should.eql('directions 2');
|
||||
done();
|
||||
})
|
||||
.catch(done);
|
||||
});
|
||||
|
||||
it('should create a new recipe', (done) => {
|
||||
const bundle = {
|
||||
inputData: {
|
||||
name: 'Smith Family Recipe',
|
||||
directions: '1. Order out :)',
|
||||
authorId: 1,
|
||||
},
|
||||
};
|
||||
|
||||
appTester(App.resources.recipe.create.operation.perform, bundle)
|
||||
.then((results) => {
|
||||
results.should.have.property('name');
|
||||
done();
|
||||
})
|
||||
.catch(done);
|
||||
});
|
||||
|
||||
it('should find a recipe', (done) => {
|
||||
const bundle = {
|
||||
inputData: {
|
||||
name: 'Smith Family Recipe',
|
||||
},
|
||||
};
|
||||
|
||||
appTester(App.resources.recipe.search.operation.perform, bundle)
|
||||
.then((results) => {
|
||||
results[0].should.have.property('name');
|
||||
done();
|
||||
})
|
||||
.catch(done);
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue