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
21
vendor/zapier-platform/example-apps/babel/src/authentication.js
vendored
Normal file
21
vendor/zapier-platform/example-apps/babel/src/authentication.js
vendored
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
const test = async (z /*, bundle */) => {
|
||||
// Normally you want to make a request to an endpoint that is either specifically designed to test auth, or one that
|
||||
// every user will have access to, such as an account or profile endpoint like /me.
|
||||
// In this example, we'll hit httpbin, which validates the Authorization Header against the arguments passed in the URL path
|
||||
const response = await z.request({
|
||||
url: 'https://auth-json-server.zapier-staging.com/me',
|
||||
});
|
||||
return response;
|
||||
};
|
||||
|
||||
const Authentication = {
|
||||
type: 'basic',
|
||||
|
||||
// The test method allows Zapier to verify that the credentials a user provides are valid. We'll execute this
|
||||
// method whenever a user connects their account for the first time.
|
||||
test,
|
||||
// assuming "username" is a key returned from the test
|
||||
connectionLabel: '{{username}}',
|
||||
};
|
||||
|
||||
export default Authentication;
|
||||
27
vendor/zapier-platform/example-apps/babel/src/index.js
vendored
Normal file
27
vendor/zapier-platform/example-apps/babel/src/index.js
vendored
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import Authentication from './authentication';
|
||||
import Recipe from './resources/recipe';
|
||||
import { version } from '../package.json';
|
||||
import { version as platformVersion } from 'zapier-platform-core';
|
||||
|
||||
const App = {
|
||||
version,
|
||||
platformVersion,
|
||||
|
||||
authentication: Authentication,
|
||||
|
||||
beforeRequest: [],
|
||||
|
||||
afterResponse: [],
|
||||
|
||||
resources: {
|
||||
[Recipe.key]: Recipe,
|
||||
},
|
||||
|
||||
triggers: {},
|
||||
|
||||
searches: {},
|
||||
|
||||
creates: {},
|
||||
};
|
||||
|
||||
export default App;
|
||||
168
vendor/zapier-platform/example-apps/babel/src/resources/recipe.js
vendored
Normal file
168
vendor/zapier-platform/example-apps/babel/src/resources/recipe.js
vendored
Normal file
|
|
@ -0,0 +1,168 @@
|
|||
const _sharedBaseUrl = 'https://auth-json-server.zapier-staging.com';
|
||||
|
||||
const getRecipe = async (z, bundle) => {
|
||||
const response = await z.request({
|
||||
url: `${_sharedBaseUrl}/recipes/${bundle.inputData.id}`,
|
||||
});
|
||||
return response.data;
|
||||
};
|
||||
|
||||
const listRecipes = async (z, bundle) => {
|
||||
const response = await z.request({
|
||||
url: _sharedBaseUrl + '/recipes',
|
||||
params: {
|
||||
style: bundle.inputData.style,
|
||||
},
|
||||
});
|
||||
return response.data;
|
||||
};
|
||||
|
||||
const createRecipe = async (z, bundle) => {
|
||||
const response = await z.request({
|
||||
url: _sharedBaseUrl + '/recipes',
|
||||
method: 'POST',
|
||||
body: {
|
||||
name: bundle.inputData.name,
|
||||
directions: bundle.inputData.directions,
|
||||
authorId: bundle.inputData.authorId,
|
||||
},
|
||||
headers: {
|
||||
'content-type': 'application/json',
|
||||
},
|
||||
});
|
||||
return response.data;
|
||||
};
|
||||
|
||||
const searchRecipe = async (z, bundle) => {
|
||||
const response = await z.request({
|
||||
url: _sharedBaseUrl + '/recipes',
|
||||
params: {
|
||||
nameSearch: bundle.inputData.name,
|
||||
},
|
||||
});
|
||||
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.
|
||||
const Recipe = {
|
||||
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,
|
||||
},
|
||||
},
|
||||
// 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,
|
||||
},
|
||||
},
|
||||
// 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: {
|
||||
//
|
||||
// },
|
||||
|
||||
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,
|
||||
},
|
||||
},
|
||||
|
||||
search: {
|
||||
display: {
|
||||
label: 'Find Recipe',
|
||||
description: 'Finds an existing recipe by name.',
|
||||
},
|
||||
operation: {
|
||||
inputFields: [{ key: 'name', required: true, type: 'string' }],
|
||||
perform: searchRecipe,
|
||||
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,
|
||||
|
||||
// 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' },
|
||||
],
|
||||
};
|
||||
|
||||
export default Recipe;
|
||||
33
vendor/zapier-platform/example-apps/babel/src/test/index.js
vendored
Normal file
33
vendor/zapier-platform/example-apps/babel/src/test/index.js
vendored
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
/* globals describe, it */
|
||||
import should from 'should';
|
||||
|
||||
import zapier from 'zapier-platform-core';
|
||||
|
||||
import App from '../index';
|
||||
const appTester = zapier.createAppTester(App);
|
||||
|
||||
describe('My Test', () => {
|
||||
it('should test the auth succeeds', async () => {
|
||||
const bundle = {
|
||||
authData: {
|
||||
username: 'user',
|
||||
password: 'secret',
|
||||
},
|
||||
};
|
||||
|
||||
const response = await appTester(App.authentication.test, bundle);
|
||||
should(response.status).eql(200);
|
||||
response.request.headers.Authorization.should.eql('Basic dXNlcjpzZWNyZXQ=');
|
||||
});
|
||||
|
||||
it('should test the auth fails', () => {
|
||||
const bundle = {
|
||||
authData: {
|
||||
username: 'user',
|
||||
password: 'boom',
|
||||
},
|
||||
};
|
||||
|
||||
return appTester(App.authentication.test, bundle).should.be.rejected();
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue