Skip to content

feat: integrate zapier v0 #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ release: ## [Local development] Release a new version of the API.
git push origin main
@echo "Done, check '\033[0;31mhttps://github.com/different-ai/embedbase/actions\033[0m'"

openapi:
curl localhost:8000/openapi.json | yq -y > .well-known/openapi.yaml
integrations/zapier:
rm -rf integrations/zapier && zapier convert 182530 integrations/zapier --version=1.0.0

#* Poetry
.PHONY: poetry-download
Expand Down
62 changes: 62 additions & 0 deletions integrations/zapier/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# environment variables file
.env
.environment

# next.js build output
.next
3 changes: 3 additions & 0 deletions integrations/zapier/.zapierapprc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"id": 182530
}
37 changes: 37 additions & 0 deletions integrations/zapier/authentication.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const testAuth = async (z, bundle) => {
const options = {
url: 'https://api.embedbase.xyz/v1/datasets',
method: 'GET',
headers: {
Authorization: 'Bearer ' + bundle.authData.api_key,
'Content-Type': 'application/json',
},
};

return z.request(options).then((response) => {
console.log(options);
console.log(response);
response.throwForStatus();
const results = response.json;

// You can do any parsing you need for results here before returning them

return results;
});
};

module.exports = {
type: 'custom',
test: testAuth,
fields: [
{
computed: false,
key: 'api_key',
required: true,
label: 'Embedbase API key',
type: 'string',
helpText: 'Get your Embedbase API key here https://app.embedbase.xyz',
},
],
customConfig: {},
};
89 changes: 89 additions & 0 deletions integrations/zapier/creates/add.js

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions integrations/zapier/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const authentication = require('./authentication');
const searchTrigger = require('./triggers/search.js');
const datasetsTrigger = require('./triggers/datasets.js');
const addCreate = require('./creates/add.js');
const listDatasetsSearch = require('./searches/list_datasets.js');

module.exports = {
version: require('./package.json').version,
platformVersion: require('zapier-platform-core').version,
authentication: authentication,
triggers: {
[searchTrigger.key]: searchTrigger,
[datasetsTrigger.key]: datasetsTrigger,
},
creates: { [addCreate.key]: addCreate },
searches: { [listDatasetsSearch.key]: listDatasetsSearch },
};
24 changes: 24 additions & 0 deletions integrations/zapier/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "embedbase",
"version": "1.0.1",
"description": "Synchronize everything into embedbase",
"main": "index.js",
"scripts": {
"test": "mocha --recursive -t 10000"
},
"engines": {
"node": ">=v16",
"npm": ">=5.6.0"
},
"dependencies": {
"zapier-platform-core": "14.0.0"
},
"devDependencies": {
"mocha": "^5.2.0",
"should": "^13.2.0"
},
"private": true,
"zapier": {
"convertedByCLIVersion": "14.0.0"
}
}
11 changes: 11 additions & 0 deletions integrations/zapier/searches/list_datasets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
operation: { perform: {} },
key: 'list_datasets',
noun: 'Datasets',
display: {
label: 'List datasets',
description: 'List your embedbase datasets',
hidden: false,
important: true,
},
};
30 changes: 30 additions & 0 deletions integrations/zapier/test/creates/add.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require('should');

const zapier = require('zapier-platform-core');

const App = require('../../index');
const appTester = zapier.createAppTester(App);

describe('Create - add', () => {
zapier.tools.env.inject();

it('should create an object', async () => {
const bundle = {
authData: {
api_key: process.env.API_KEY,
oauth_consumer_key: process.env.OAUTH_CONSUMER_KEY,
oauth_consumer_secret: process.env.OAUTH_CONSUMER_SECRET,
oauth_token: process.env.OAUTH_TOKEN,
oauth_token_secret: process.env.OAUTH_TOKEN_SECRET,
},

inputData: {},
};

const result = await appTester(
App.creates['add'].operation.perform,
bundle
);
result.should.not.be.an.Array();
});
});
32 changes: 32 additions & 0 deletions integrations/zapier/test/searches/list_datasets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require('should');

const zapier = require('zapier-platform-core');

const App = require('../../index');
const appTester = zapier.createAppTester(App);

describe('Search - list_datasets', () => {
zapier.tools.env.inject();

it('should get an array', async () => {
const bundle = {
authData: {
api_key: process.env.API_KEY,
oauth_consumer_key: process.env.OAUTH_CONSUMER_KEY,
oauth_consumer_secret: process.env.OAUTH_CONSUMER_SECRET,
oauth_token: process.env.OAUTH_TOKEN,
oauth_token_secret: process.env.OAUTH_TOKEN_SECRET,
},

inputData: {},
};

const results = await appTester(
App.searches['list_datasets'].operation.perform,
bundle
);
results.should.be.an.Array();
results.length.should.be.aboveOrEqual(1);
results[0].should.have.property('id');
});
});
30 changes: 30 additions & 0 deletions integrations/zapier/test/triggers/datasets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require('should');

const zapier = require('zapier-platform-core');

const App = require('../../index');
const appTester = zapier.createAppTester(App);

describe('Trigger - datasets', () => {
zapier.tools.env.inject();

it('should get an array', async () => {
const bundle = {
authData: {
api_key: process.env.API_KEY,
oauth_consumer_key: process.env.OAUTH_CONSUMER_KEY,
oauth_consumer_secret: process.env.OAUTH_CONSUMER_SECRET,
oauth_token: process.env.OAUTH_TOKEN,
oauth_token_secret: process.env.OAUTH_TOKEN_SECRET,
},

inputData: {},
};

const results = await appTester(
App.triggers['datasets'].operation.perform,
bundle
);
results.should.be.an.Array();
});
});
30 changes: 30 additions & 0 deletions integrations/zapier/test/triggers/search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require('should');

const zapier = require('zapier-platform-core');

const App = require('../../index');
const appTester = zapier.createAppTester(App);

describe('Trigger - search', () => {
zapier.tools.env.inject();

it('should get an array', async () => {
const bundle = {
authData: {
api_key: process.env.API_KEY,
oauth_consumer_key: process.env.OAUTH_CONSUMER_KEY,
oauth_consumer_secret: process.env.OAUTH_CONSUMER_SECRET,
oauth_token: process.env.OAUTH_TOKEN,
oauth_token_secret: process.env.OAUTH_TOKEN_SECRET,
},

inputData: {},
};

const results = await appTester(
App.triggers['search'].operation.perform,
bundle
);
results.should.be.an.Array();
});
});
44 changes: 44 additions & 0 deletions integrations/zapier/triggers/datasets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const perform = async (z, bundle) => {
return bundle.cleanedRequest;
};

const performList = async (z, bundle) => {
const options = {
url: 'https://api.embedbase.xyz/v1/datasets',
method: 'GET',
headers: {
Accept: 'application/json',
Authorization: 'Bearer ' + bundle.authData.api_key,
},
};

return z.request(options).then((response) => {
response.throwForStatus();
const results = response.json;

// You can do any parsing you need for results here before returning them

return results.datasets;
});
};

module.exports = {
operation: {
perform: perform,
type: 'hook',
performList: performList,
sample: { dataset_id: 'foo', documents_count: 65 },
outputFields: [
{ key: 'dataset_id', type: 'string' },
{ key: 'documents_count', type: 'number' },
],
},
key: 'datasets',
noun: 'Datasets',
display: {
label: 'List datasets',
description: 'List your embedbase datasets',
hidden: false,
important: true,
},
};
Loading