This repository has been archived by the owner on Jun 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
64 lines (52 loc) · 1.68 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const _ = require('lodash');
const recipe = require('./triggers/recipe');
const movie = require('./triggers/movie');
// HTTP before middleware that adds sorting query params.
// We want *every* request to our API to be sorted in reverse chronological order.
// Applying this middleware guarantees this.
const addSortingParams = (request /*, z*/) => {
request.params = _.extend({}, request.params, {
_sort: 'id',
_order: 'desc'
});
return request;
};
// HTTP after middleware that checks for errors in the response.
const checkForErrors = (response, z) => {
// If we get a bad status code, throw an error. This will halt the zap.
if (response.status >= 300) {
throw new z.errors.HaltedError(`Unexpected status code ${response.status} from ${response.request.url}`);
}
// If no errors just return original response
return response;
};
// 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: [
// add our before middlewares
addSortingParams
],
afterResponse: [
// add our after middlewares
checkForErrors
],
resources: {
},
// If you want your trigger to show up, you better include it here!
triggers: {
[recipe.key]: recipe,
[movie.key]: movie
},
// 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;