ti2 1.0.74 → 1.0.76

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/api.yml CHANGED
@@ -680,6 +680,43 @@ paths:
680
680
  application/json:
681
681
  schema:
682
682
  $ref: '#/components/schemas/Message'
683
+ put:
684
+ tags:
685
+ - app
686
+ - user
687
+ summary: Should update a user+appToken configuration
688
+ security:
689
+ - bearerAuth: ['admin', 'app', 'user']
690
+ operationId: updateAppToken
691
+ parameters:
692
+ - name: app
693
+ in: path
694
+ description: app name to read the userId for (must match app token)
695
+ example: 'expedia'
696
+ required: true
697
+ schema:
698
+ type: string
699
+ - name: userId
700
+ in: path
701
+ description: user to read the app token for
702
+ example: '536830b6ed19afa44a000002'
703
+ required: true
704
+ schema:
705
+ type: string
706
+ requestBody:
707
+ description: The User+App configuration to update
708
+ required: true
709
+ content:
710
+ application/json:
711
+ schema:
712
+ $ref: '#/components/schemas/UserAppDelete'
713
+ responses:
714
+ 200:
715
+ description: success
716
+ content:
717
+ application/json:
718
+ schema:
719
+ $ref: '#/components/schemas/Message'
683
720
  /{app}/{userId}/{hint}/token:
684
721
  get:
685
722
  tags:
@@ -141,6 +141,33 @@ const createAppToken = async (req, res, next) => {
141
141
  }
142
142
  };
143
143
 
144
+ const updateAppToken = async (req, res, next) => {
145
+ const {
146
+ body: {
147
+ configuration,
148
+ hint,
149
+ },
150
+ params: {
151
+ app: integrationId,
152
+ userId,
153
+ },
154
+ } = req;
155
+ // check if the user exists
156
+ const userRecord = await sqldb.User.findOne({ where: { userId } });
157
+ if (!userRecord) return next({ status: 404, message: 'User does not exists' });
158
+ await sqldb.UserAppKey.update({
159
+ configuration,
160
+ }, {
161
+ where: {
162
+ integrationId,
163
+ userId,
164
+ hint,
165
+ },
166
+ raw: true,
167
+ });
168
+ return res.json({ message: `${hint} updated ` });
169
+ };
170
+
144
171
  const deleteAppToken = async (req, res, next) => {
145
172
  const {
146
173
  body: {
@@ -449,6 +476,7 @@ module.exports = plugins => ({
449
476
  getAppToken,
450
477
  createAppSettings,
451
478
  getAppSettings,
479
+ updateAppToken,
452
480
  deleteAppToken,
453
481
  deleteAppSettings,
454
482
  getAppScheduledJobs,
@@ -42,6 +42,7 @@ const typeDefs = `
42
42
  type Query {
43
43
  id: ID
44
44
  orderId: ID
45
+ orderReference: String
45
46
  bookingId: ID
46
47
  supplierBookingId: ID
47
48
  status: String
@@ -1,3 +1,4 @@
1
+ /* eslint-disable no-restricted-syntax */
1
2
  const jwt = require('jsonwebtoken');
2
3
  const R = require('ramda');
3
4
  const assert = require('assert');
@@ -10,27 +11,37 @@ const { env: { dbCryptoKey } } = process;
10
11
  module.exports = {
11
12
  up: async () => {
12
13
  // encrypt all data
13
- const existingTokens = await sqldb.UserAppKey.findAll();
14
- const valuesToUpdate = [];
15
- for (const currentToken of existingTokens) {
16
- const decodedToken = JSON.stringify(R.omit(
17
- ['iat'],
18
- jwt.verify(currentToken.dataValues.appKey, dbCryptoKey),
19
- ));
20
- const encryptedToken = encrypt(decodedToken);
21
- // make sure we can decrypt it
22
- const decodedValue = decrypt(encryptedToken);
23
- assert(R.equals(decodedToken, decodedValue));
24
- currentToken.appKey = encryptedToken;
25
- valuesToUpdate.push({
26
- id: currentToken.id,
27
- appToken: encryptedToken,
14
+ try {
15
+ const existingTokens = await sqldb.UserAppKey.findAll({
16
+ attributes: ['id', 'appKey', 'userId', 'integrationId', 'hint', 'createdAt', 'updatedAt'],
28
17
  });
29
- }
30
- for (const { id, appToken } of valuesToUpdate) {
31
- const currentToken = await sqldb.UserAppKey.findOne({ where: { id } });
32
- currentToken.setDataValue('appKey', appToken);
33
- await currentToken.save();
18
+ const valuesToUpdate = [];
19
+ for (const currentToken of existingTokens) {
20
+ const decodedToken = JSON.stringify(R.omit(
21
+ ['iat'],
22
+ jwt.verify(currentToken.dataValues.appKey, dbCryptoKey),
23
+ ));
24
+ const encryptedToken = encrypt(decodedToken);
25
+ // make sure we can decrypt it
26
+ const decodedValue = decrypt(encryptedToken);
27
+ assert(R.equals(decodedToken, decodedValue));
28
+ currentToken.appKey = encryptedToken;
29
+ valuesToUpdate.push({
30
+ id: currentToken.id,
31
+ appToken: encryptedToken,
32
+ });
33
+ }
34
+ for (const { id, appToken } of valuesToUpdate) {
35
+ const currentToken = await sqldb.UserAppKey.findOne({
36
+ where: { id },
37
+ attributes: ['id', 'appKey', 'userId', 'integrationId', 'hint', 'createdAt', 'updatedAt'],
38
+ });
39
+ currentToken.setDataValue('appKey', appToken);
40
+ await currentToken.save();
41
+ }
42
+ } catch (err) {
43
+ console.error(err);
44
+ throw err;
34
45
  }
35
46
  },
36
47
  down: async () => {
@@ -0,0 +1,12 @@
1
+ module.exports = {
2
+ up: (queryInterface, Sequelize) => queryInterface.addColumn(
3
+ 'UserAppKeys',
4
+ 'configuration',
5
+ {
6
+ type: Sequelize.JSON,
7
+ allowNull: true,
8
+ validate: {},
9
+ },
10
+ ),
11
+ down: queryInterface => queryInterface.removeColumn('UserAppKeys', 'configuration'),
12
+ };
@@ -60,9 +60,14 @@ const UserAppKey = db.define('UserAppKey', {
60
60
  return {
61
61
  ...R.pathOr({}, ['settings'], userIntegrationSettings),
62
62
  ...removeEmptyAttributes(appKey),
63
+ ...(this.getDataValue('configuration') ? { configuration: this.getDataValue('configuration') } : {}),
63
64
  };
64
65
  },
65
66
  },
67
+ configuration: {
68
+ type: Sequelize.JSON,
69
+ allowNull: true,
70
+ },
66
71
  }, {});
67
72
  UserAppKey.associate = models => {
68
73
  UserAppKey.belongsTo(models.User, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ti2",
3
- "version": "1.0.74",
3
+ "version": "1.0.76",
4
4
  "description": "Tourist Industry Exchange (TI2)",
5
5
  "main": "index.js",
6
6
  "scripts": {