vtb-appit 0.1.17 → 0.1.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/appit-base-transformer.js +1 -0
- package/appit-notify.js +87 -0
- package/appit.js +26 -2
- package/package.json +1 -1
|
@@ -9,6 +9,7 @@ class AppitBaseTransformer {
|
|
|
9
9
|
const data = JSON.parse(fs.readFileSync(pth.join(__dirname, '../../assets/travelplan.json'), {encoding: 'utf8' }));
|
|
10
10
|
this.travelplan = JSON.parse(JSON.stringify(data));
|
|
11
11
|
this.profile = {};
|
|
12
|
+
this.vtbMessages = [];
|
|
12
13
|
|
|
13
14
|
try {
|
|
14
15
|
this.token = fs.readFileSync(pth.join(__dirname, '../../assets/token.jwt'), {encoding: 'utf8' });
|
package/appit-notify.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
const axios = require('axios');
|
|
2
|
+
const {readFileSync} = require('fs');
|
|
3
|
+
|
|
4
|
+
class AppitNotify {
|
|
5
|
+
async exec(status, token, workspaceId, excursionId, messages) {
|
|
6
|
+
console.log('notify ouput');
|
|
7
|
+
let query = '';
|
|
8
|
+
if(status === 'done') {
|
|
9
|
+
query = `
|
|
10
|
+
mutation {
|
|
11
|
+
proposalbuildUpdate(input: {
|
|
12
|
+
id: "${process.env.PROPOSAL_ID}",
|
|
13
|
+
status: "done",
|
|
14
|
+
url: "https://portal.appit4travel.com/en/admin/workspaces/${workspaceId}/excursions/${excursionId}/edit"
|
|
15
|
+
}) {
|
|
16
|
+
message
|
|
17
|
+
status
|
|
18
|
+
node {
|
|
19
|
+
status
|
|
20
|
+
id
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
`;
|
|
25
|
+
} else if(status === 'failed') {
|
|
26
|
+
let url = "";
|
|
27
|
+
if(excursionId) {
|
|
28
|
+
url = `https://portal.appit4travel.com/en/admin/workspaces/${workspaceId}/excursions/${excursionId}/edit`;
|
|
29
|
+
}
|
|
30
|
+
query = `
|
|
31
|
+
mutation {
|
|
32
|
+
proposalbuildUpdate(input: {
|
|
33
|
+
id: "${process.env.PROPOSAL_ID}",
|
|
34
|
+
status: "failed",
|
|
35
|
+
url: "${url}",
|
|
36
|
+
messages: [${messages.map(msg =>
|
|
37
|
+
`{${Object.entries(msg).map(([key, value]) =>
|
|
38
|
+
`${key}: ${typeof value === 'string' ? `"${value}"` : value}`
|
|
39
|
+
).join(', ')}}`
|
|
40
|
+
).join(', ')}]
|
|
41
|
+
}) {
|
|
42
|
+
message
|
|
43
|
+
status
|
|
44
|
+
node {
|
|
45
|
+
status
|
|
46
|
+
id
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
`;
|
|
51
|
+
}
|
|
52
|
+
console.log(query);
|
|
53
|
+
console.log(token);
|
|
54
|
+
|
|
55
|
+
try {
|
|
56
|
+
const response = await axios({
|
|
57
|
+
method: 'post',
|
|
58
|
+
url: `https://vtb-global-vtb-gateway-z7stqwbrxa-ew.a.run.app/graphql`,
|
|
59
|
+
data: JSON.stringify({ query }),
|
|
60
|
+
headers: {
|
|
61
|
+
Authorization: `Bearer ${token}`,
|
|
62
|
+
'Content-Type': 'application/json'
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
console.log('abs');
|
|
66
|
+
console.log(response.data);
|
|
67
|
+
} catch (error) {
|
|
68
|
+
console.log('catch');
|
|
69
|
+
console.error(error.message);
|
|
70
|
+
}
|
|
71
|
+
console.log('end');
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
// const token = readFileSync('./assets/token.jwt', 'utf8');
|
|
77
|
+
// const branchName = process.argv[2];
|
|
78
|
+
// const branchNameSplit = branchName.split('/');
|
|
79
|
+
// const bucketUrl= process.argv[3];
|
|
80
|
+
// const filename = (process.argv.length > 4 && process.argv[4]) ? process.argv[4] : '';
|
|
81
|
+
// const frags = branchName.split('-');
|
|
82
|
+
// const proposalId = frags[1];
|
|
83
|
+
//
|
|
84
|
+
// const notifier = new Notify();
|
|
85
|
+
// notifier.triggerGraphql(proposalId, token, branchNameSplit[branchNameSplit.length - 1], bucketUrl, filename);
|
|
86
|
+
//
|
|
87
|
+
module.exports = { AppitNotify };
|
package/appit.js
CHANGED
|
@@ -6,6 +6,8 @@ const axios = require('axios');
|
|
|
6
6
|
|
|
7
7
|
// Initialize OpenTelemetry SDK first
|
|
8
8
|
const sdk = require('./tracing');
|
|
9
|
+
const { AppitNotify } = require('./appit-notify');
|
|
10
|
+
const notify = new AppitNotify();
|
|
9
11
|
|
|
10
12
|
// Then initialize Winston with OpenTelemetry transport
|
|
11
13
|
const winston = require("winston");
|
|
@@ -143,7 +145,6 @@ class Appit {
|
|
|
143
145
|
const steps = [
|
|
144
146
|
{ name: 'excursion', fn: () => this.excursion() },
|
|
145
147
|
{ name: 'labels', fn: () => this.labels() },
|
|
146
|
-
{ name: 'explores', fn: () => this.explores() },
|
|
147
148
|
{ name: 'ships', fn: () => this.ships() },
|
|
148
149
|
{ name: 'places', fn: () => this.places() },
|
|
149
150
|
{ name: 'organizations', fn: () => this.organizations() },
|
|
@@ -159,7 +160,8 @@ class Appit {
|
|
|
159
160
|
{ name: 'homescreen', fn: () => this.homescreen() },
|
|
160
161
|
{ name: 'menu', fn: () => this.menu() },
|
|
161
162
|
{ name: 'settings', fn: () => this.settings() },
|
|
162
|
-
{ name: 'notifications', fn: () => this.notifications() }
|
|
163
|
+
{ name: 'notifications', fn: () => this.notifications() },
|
|
164
|
+
{ name: 'explores', fn: () => this.explores() },
|
|
163
165
|
];
|
|
164
166
|
|
|
165
167
|
for(const step of steps) {
|
|
@@ -174,6 +176,12 @@ class Appit {
|
|
|
174
176
|
logger.info(`✓ ${step.name} completed successfully`);
|
|
175
177
|
stepSpan.setStatus({ code: SpanStatusCode.OK });
|
|
176
178
|
} catch(e) {
|
|
179
|
+
if(step.name == 'excursion' && e.message.indexOf('excursions_code_unique') !== -1) {
|
|
180
|
+
this.transformer.vtbMessages.push({
|
|
181
|
+
'message': 'Appit reis code is al gebruikt, herpubliceer de bestaande App of maak een nieuwe VTB om een nieuwe App te publiceren.'
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
|
|
177
185
|
stepSpan.recordException(e);
|
|
178
186
|
stepSpan.setStatus({ code: SpanStatusCode.ERROR, message: e.message });
|
|
179
187
|
|
|
@@ -186,6 +194,15 @@ class Appit {
|
|
|
186
194
|
stepSpan.end();
|
|
187
195
|
}
|
|
188
196
|
});
|
|
197
|
+
|
|
198
|
+
if(step.name == 'excursion' && !this.history.excursionId) {
|
|
199
|
+
if(!this.transformer.vtbMessages.length) {
|
|
200
|
+
this.transformer.vtbMessages.push({
|
|
201
|
+
'message': 'Reis kon niet worden aangemaakt in Appit, neem contact op met <a href="mailto:support@3rdfloorcoding.nl">support@3rdfloorcoding.nl</a>.'
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
break;
|
|
205
|
+
}
|
|
189
206
|
}
|
|
190
207
|
|
|
191
208
|
this.history.updatedAt = new Date().getTime();
|
|
@@ -211,6 +228,12 @@ class Appit {
|
|
|
211
228
|
sdk.shutdown();
|
|
212
229
|
}
|
|
213
230
|
|
|
231
|
+
if(this.transformer.vtbMessages.length) {
|
|
232
|
+
notify.exec('failed', this.transformer.token, this.transformer.workspace_id, this.history.excursionId, this.transformer.vtbMessages);
|
|
233
|
+
} else {
|
|
234
|
+
notify.exec('done', this.transformer.token, this.transformer.workspace_id, this.history.excursionId);
|
|
235
|
+
}
|
|
236
|
+
|
|
214
237
|
|
|
215
238
|
return true;
|
|
216
239
|
}
|
|
@@ -344,6 +367,7 @@ class Appit {
|
|
|
344
367
|
|
|
345
368
|
if(!this.history.excursionId) {
|
|
346
369
|
let model = await this.createExcursion({...excursion, ...images, workspace_id: this.transformer.workspace_id});
|
|
370
|
+
console.log('MODEL', model);
|
|
347
371
|
this.history.excursionId = model.data.id;
|
|
348
372
|
} else {
|
|
349
373
|
if(excursion.hasOwnProperty('code'))
|