dolibarr/dev/examples/zapier/index.js

94 lines
3.2 KiB
JavaScript
Raw Normal View History

2019-09-11 16:07:21 +00:00
/*jshint esversion: 6 */
2020-10-30 19:37:23 +00:00
const triggerAction = require('./triggers/action');
const triggerOrder = require('./triggers/order');
2019-05-19 19:12:22 +00:00
const triggerThirdparty = require('./triggers/thirdparty');
2021-06-05 07:37:38 +00:00
const triggerContact = require('./triggers/contact');
2020-10-30 19:37:23 +00:00
const triggerTicket = require('./triggers/ticket');
2020-10-28 23:34:41 +00:00
const triggerUser = require('./triggers/user');
2021-06-06 15:57:48 +00:00
const triggerMember = require('./triggers/member');
2019-05-19 19:12:22 +00:00
const searchThirdparty = require('./searches/thirdparty');
2021-06-06 10:12:12 +00:00
const searchContact = require('./searches/contact');
2021-06-06 15:44:06 +00:00
const searchMember = require('./searches/member');
2019-05-19 19:12:22 +00:00
const createThirdparty = require('./creates/thirdparty');
2021-06-05 13:23:29 +00:00
const createContact = require('./creates/contact');
const createMember = require('./creates/member');
2019-05-19 19:12:22 +00:00
2020-10-29 19:53:28 +00:00
const {
config: authentication,
befores = [],
afters = [],
} = require('./authentication');
2019-05-19 19:12:22 +00:00
// To include the session key header on all outbound requests, simply define a function here.
// It runs runs before each request is sent out, allowing you to make tweaks to the request in a centralized spot
2020-10-29 19:53:28 +00:00
// const includeSessionKeyHeader = (request, z, bundle) => {
// if (bundle.authData.sessionKey) {
// request.headers = request.headers || {};
// request.headers['DOLAPIKEY'] = bundle.authData.sessionKey;
// }
// return request;
// };
2019-05-19 19:12:22 +00:00
// If we get a response and it is a 401, we can raise a special error telling Zapier to retry this after another exchange.
2020-10-29 19:53:28 +00:00
// const sessionRefreshIf401 = (response, z, bundle) => {
// if (bundle.authData.sessionKey) {
// if (response.status === 401) {
// throw new z.errors.RefreshAuthError('Session apikey needs refreshing.');
// }
// }
// return response;
// };
2019-05-19 19:12:22 +00:00
// 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,
authentication: authentication,
// beforeRequest & afterResponse are optional hooks into the provided HTTP client
beforeRequest: [
2020-10-29 19:53:28 +00:00
...befores
2019-05-19 19:12:22 +00:00
],
afterResponse: [
2020-10-29 19:53:28 +00:00
...afters
2019-05-19 19:12:22 +00:00
],
// If you want to define optional resources to simplify creation of triggers, searches, creates - do that here!
resources: {
},
// If you want your trigger to show up, you better include it here!
triggers: {
2020-10-30 19:37:23 +00:00
[triggerAction.key]: triggerAction,
[triggerOrder.key]: triggerOrder,
2019-05-19 19:12:22 +00:00
[triggerThirdparty.key]: triggerThirdparty,
2021-06-05 07:37:38 +00:00
[triggerContact.key]: triggerContact,
2020-10-30 19:37:23 +00:00
[triggerTicket.key]: triggerTicket,
2020-10-28 23:34:41 +00:00
[triggerUser.key]: triggerUser,
2021-06-06 15:57:48 +00:00
[triggerMember.key]: triggerMember,
2019-05-19 19:12:22 +00:00
},
// If you want your searches to show up, you better include it here!
searches: {
[searchThirdparty.key]: searchThirdparty,
2021-06-06 10:12:12 +00:00
[searchContact.key]: searchContact,
2021-06-06 15:44:06 +00:00
[searchMember.key]: searchMember,
2019-05-19 19:12:22 +00:00
},
// If you want your creates to show up, you better include it here!
creates: {
[createThirdparty.key]: createThirdparty,
2021-06-05 13:23:29 +00:00
[createContact.key]: createContact,
[createMember.key]: createMember,
2019-05-19 19:12:22 +00:00
}
};
// Finally, export the app.
module.exports = App;