dolibarr/dev/examples/zapier/index.js

82 lines
2.7 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');
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');
2019-05-19 19:12:22 +00:00
const searchThirdparty = require('./searches/thirdparty');
const createThirdparty = require('./creates/thirdparty');
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,
2020-10-30 19:37:23 +00:00
[triggerTicket.key]: triggerTicket,
2020-10-28 23:34:41 +00:00
[triggerUser.key]: triggerUser,
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,
},
// If you want your creates to show up, you better include it here!
creates: {
[createThirdparty.key]: createThirdparty,
}
};
// Finally, export the app.
module.exports = App;