-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
77 lines (64 loc) · 2.42 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
65
66
67
68
69
70
71
72
73
74
75
76
77
const WorkbookResource = require('./resources/workbook');
const WebhookworkbookTrigger = require('./triggers/webhook_workbook');
const WorkbookSearch = require('./searches/workbook');
const ProjectResource = require('./resources/project');
const PublishworkbookCreate = require('./creates/publish_workbook');
const authentication = require('./authentication');
const createNewUser = require('./creates/newuser');
const updateUser = require('./creates/updateuser');
const searchUsers = require('./searches/users');
const hydrators = require('./hydrators');
const includeSessionKeyHeader = (request, z, bundle) => {
request.headers = request.headers || {};
request.headers["Accept"] = "application/json";
request.headers["Content-Type"] = "application/json";
if (bundle.authData.creds && bundle.authData.creds.token) {
request.headers['X-Tableau-Auth'] = bundle.authData.creds.token;
}
return request;
};
const sessionRefreshIf401 = (response, z, bundle) => {
if (bundle.authData.creds) {
if (response.status === 401) {
throw new z.errors.RefreshAuthError(); // ask for a refresh & retry
}
}
return response;
};
// 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: [
includeSessionKeyHeader
],
afterResponse: [
],
hydrators: hydrators,
// If you want to define optional resources to simplify creation of triggers, searches, creates - do that here!
resources: {
[WorkbookResource.key]: WorkbookResource,
[ProjectResource.key]: ProjectResource,
},
// If you want your trigger to show up, you better include it here!
triggers: {
[WebhookworkbookTrigger.key]: WebhookworkbookTrigger
},
// If you want your searches to show up, you better include it here!
searches: {
[WorkbookSearch.key]: WorkbookSearch,
[searchUsers.key]: searchUsers
},
// If you want your creates to show up, you better include it here!
creates: {
[PublishworkbookCreate.key]: PublishworkbookCreate,
[createNewUser.key]: createNewUser,
[updateUser.key]: updateUser
}
};
// Finally, export the app.
module.exports = App;