@velocitycareerlabs/data-loader 1.20.0-dev-build.188151f81 → 1.20.0-qa-build.1ed749dfb

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@velocitycareerlabs/data-loader",
3
- "version": "1.20.0-dev-build.188151f81",
3
+ "version": "1.20.0-qa-build.1ed749dfb",
4
4
  "description": "A tool for uploading data to the different target systems.",
5
5
  "repository": "https://github.com/velocitycareerlabs/packages",
6
6
  "main": "src/index.js",
@@ -38,7 +38,8 @@
38
38
  "handlebars": "~4.7.7",
39
39
  "inquirer": "^8.0.0",
40
40
  "lodash": "~4.17.20",
41
- "nanoid": "3.3.1"
41
+ "nanoid": "3.3.1",
42
+ "strip-bom-stream": "^4.0.0"
42
43
  },
43
- "gitHead": "4a2d56e5252547827dc6439d6829287fcb547675"
44
+ "gitHead": "7765ee052ba21627bbc243185fe5e96ef93d432e"
44
45
  }
@@ -1,3 +1,4 @@
1
+ const { env } = require('node:process');
1
2
  const got = require('got');
2
3
  const { map, isEmpty } = require('lodash/fp');
3
4
  const { printInfo } = require('../helpers/common');
@@ -10,6 +11,11 @@ const setupGot = ({ endpoint, authToken, did }) => {
10
11
  if (authToken != null) {
11
12
  options.headers = { Authorization: `Bearer ${authToken}` };
12
13
  }
14
+ if (env.NODE_TLS_REJECT_UNAUTHORIZED === '0') {
15
+ options.https = {
16
+ rejectUnauthorized: false,
17
+ };
18
+ }
13
19
  return got.extend(options);
14
20
  };
15
21
 
@@ -3,6 +3,12 @@ const { reduce } = require('lodash/fp');
3
3
  const { printInfo, printError, parseColumn } = require('../helpers');
4
4
  const { runBatchIssuing } = require('./orchestrators');
5
5
 
6
+ const parseVar = reduce((acc, pair) => {
7
+ const [key, value] = pair.split('=');
8
+ acc[key] = value;
9
+ return acc;
10
+ }, {});
11
+
6
12
  program
7
13
  .name('data-loader vendorcreds')
8
14
  .description('Loads data into a db')
@@ -109,9 +115,3 @@ program
109
115
  }
110
116
  })
111
117
  .parseAsync(process.argv);
112
-
113
- const parseVar = reduce((acc, pair) => {
114
- const [key, value] = pair.split('=');
115
- acc[key] = value;
116
- return acc;
117
- }, {});
@@ -62,21 +62,22 @@ const runBatchIssuing = async (opts) => {
62
62
  return { disclosureRequest, newExchangeOffers };
63
63
  }
64
64
 
65
- if (disclosureRequest.id == null) {
66
- await createDisclosureRequest(disclosureRequest, context);
67
- }
65
+ const issuingDisclosure =
66
+ disclosureRequest.id != null
67
+ ? disclosureRequest
68
+ : await createDisclosureRequest(disclosureRequest, context);
68
69
 
69
- await writeDisclosureToJson(disclosureRequest, options);
70
+ await writeDisclosureToJson(issuingDisclosure, options);
70
71
 
71
72
  const outputs = options.legacy
72
73
  ? await runLegacyBatchIssuing(
73
- disclosureRequest,
74
+ issuingDisclosure,
74
75
  newExchangeOffers,
75
76
  options,
76
77
  context
77
78
  )
78
79
  : await runSingleQrCodeBatchIssuing(
79
- disclosureRequest,
80
+ issuingDisclosure,
80
81
  newExchangeOffers,
81
82
  options,
82
83
  context
@@ -227,14 +228,17 @@ const writeDisclosureToJson = async (disclosureRequest, options) => {
227
228
  const createOfferExchangeAndQrCode = async (
228
229
  { newExchange, newOffer, disclosureRequest },
229
230
  options,
230
- { fetchers }
231
+ context
231
232
  ) => {
232
- const { exchange, offer, vendorUserId } = await createOfferExchange({
233
- newExchange,
234
- newOffer,
235
- disclosureRequest,
236
- fetchers,
237
- });
233
+ const { fetchers } = context;
234
+ const { exchange, offer, vendorUserId } = await createOfferExchange(
235
+ {
236
+ newExchange,
237
+ newOffer,
238
+ disclosureRequest,
239
+ },
240
+ context
241
+ );
238
242
 
239
243
  const deeplink = await fetchers.loadExchangeDeeplink(exchange);
240
244
  const qrcode = await fetchers.loadExchangeQrcode(exchange);
@@ -258,8 +262,9 @@ const createOfferExchangeAndQrCode = async (
258
262
 
259
263
  const createOfferExchange = async (
260
264
  { newExchange, newOffer, disclosureRequest },
261
- { fetchers }
265
+ context
262
266
  ) => {
267
+ const { fetchers } = context;
263
268
  const { vendorUserId } = newOffer.credentialSubject;
264
269
  printInfo(`Setting up vendorUserId:${vendorUserId}`);
265
270
  const exchange = await fetchers.createOfferExchange({
@@ -1,5 +1,6 @@
1
1
  const fs = require('fs');
2
2
  const csv = require('csv-parser');
3
+ const stripBom = require('strip-bom-stream');
3
4
  const { isString, indexOf } = require('lodash/fp');
4
5
 
5
6
  const loadCsv = (fileName) => {
@@ -7,6 +8,7 @@ const loadCsv = (fileName) => {
7
8
  const csvRows = [];
8
9
  let csvHeaders;
9
10
  fs.createReadStream(fileName)
11
+ .pipe(stripBom())
10
12
  .pipe(csv())
11
13
  .on('headers', (headers) => {
12
14
  // eslint-disable-next-line better-mutation/no-mutation
@@ -1,5 +1,9 @@
1
+ const { env } = require('node:process');
1
2
  const path = require('path');
2
3
  const nock = require('nock');
4
+ const got = require('got');
5
+
6
+ const gotExtendSpy = jest.spyOn(got, 'extend');
3
7
  const { nanoid } = require('nanoid');
4
8
  const { runBatchIssuing } = require('../src/batch-issuing/orchestrators');
5
9
 
@@ -15,6 +19,10 @@ describe('batch issuing test', () => {
15
19
  nock.restore();
16
20
  });
17
21
 
22
+ beforeEach(() => {
23
+ jest.clearAllMocks();
24
+ });
25
+
18
26
  it("should fail if options don't have credential type or type doesn't exist", async () => {
19
27
  const options = {
20
28
  csvFilename: path.join(__dirname, 'data/batch-vars-offerids.csv'),
@@ -1087,6 +1095,95 @@ describe('batch issuing test', () => {
1087
1095
  });
1088
1096
  });
1089
1097
 
1098
+ it('should handle csv with BOM characters', async () => {
1099
+ const options = {
1100
+ csvFilename: path.join(__dirname, 'data/with-bom.csv'),
1101
+ offerTemplateFilename: path.join(
1102
+ __dirname,
1103
+ 'data/email-offer.template.json'
1104
+ ),
1105
+ termsUrl: 'http://example.com/terms.html',
1106
+ did: 'did:ion:sap123',
1107
+ idCredentialType: 'EmailV1.0',
1108
+ vendorUseridColumn: 'email',
1109
+ new: true,
1110
+ dryrun: true,
1111
+ };
1112
+
1113
+ const updates = await runBatchIssuing(options);
1114
+ expect(
1115
+ new Date(updates.disclosureRequest.activationDate).getTime()
1116
+ ).toBeLessThan(Date.now());
1117
+
1118
+ expect(updates).toEqual({
1119
+ disclosureRequest: {
1120
+ configurationType: 'issuing',
1121
+ vendorEndpoint: 'integrated-issuing-identification',
1122
+ types: [
1123
+ {
1124
+ type: 'EmailV1.0',
1125
+ },
1126
+ ],
1127
+ identityMatchers: {
1128
+ rules: [
1129
+ {
1130
+ valueIndex: 0,
1131
+ path: ['$.emails'],
1132
+ rule: 'pick',
1133
+ },
1134
+ ],
1135
+ vendorUserIdIndex: 2,
1136
+ },
1137
+ vendorDisclosureId: expect.any(Number),
1138
+ setIssuingDefault: true,
1139
+ duration: '1h', // 1 hour by default
1140
+ offerMode: 'preloaded',
1141
+ purpose: 'Issuing Career Credential', // by default have a generic message
1142
+ activationDate: expect.stringMatching(ISO_DATETIME_TZ_FORMAT),
1143
+ termsUrl: 'http://example.com/terms.html',
1144
+ authTokenExpiresIn: 525600,
1145
+ },
1146
+ newExchangeOffers: [
1147
+ {
1148
+ newOffer: {
1149
+ type: ['EmailV1.0'],
1150
+ issuer: {
1151
+ id: 'did:ion:sap123',
1152
+ },
1153
+ credentialSubject: {
1154
+ vendorUserId: 'joan.lee@sap.com',
1155
+ email: 'joan.lee@sap.com',
1156
+ },
1157
+
1158
+ offerId: expect.any(String),
1159
+ },
1160
+ newExchange: {
1161
+ type: 'ISSUING',
1162
+ identityMatcherValues: ['joan.lee@sap.com'],
1163
+ },
1164
+ },
1165
+ {
1166
+ newOffer: {
1167
+ type: ['EmailV1.0'],
1168
+ issuer: {
1169
+ id: 'did:ion:sap123',
1170
+ },
1171
+ credentialSubject: {
1172
+ vendorUserId: 'john.smith@sap.com',
1173
+ email: 'john.smith@sap.com',
1174
+ },
1175
+
1176
+ offerId: expect.any(String),
1177
+ },
1178
+ newExchange: {
1179
+ type: 'ISSUING',
1180
+ identityMatcherValues: ['john.smith@sap.com'],
1181
+ },
1182
+ },
1183
+ ],
1184
+ });
1185
+ });
1186
+
1090
1187
  it('should load the templates and csv with vars', async () => {
1091
1188
  const options = {
1092
1189
  csvFilename: path.join(__dirname, 'data/variables.csv'),
@@ -1286,4 +1383,55 @@ describe('batch issuing test', () => {
1286
1383
  });
1287
1384
  });
1288
1385
  });
1386
+
1387
+ describe('https.rejectUnauthorized test suite', () => {
1388
+ beforeEach(() => {
1389
+ env.NODE_TLS_REJECT_UNAUTHORIZED = '';
1390
+ });
1391
+ afterAll(() => {
1392
+ env.NODE_TLS_REJECT_UNAUTHORIZED = '';
1393
+ });
1394
+
1395
+ it('when NODE_TLS_REJECT_UNAUTHORIZED is "0", got client should be setup with https.rejectUnauthorized false', async () => {
1396
+ env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
1397
+ const options = {
1398
+ csvFilename: path.join(__dirname, 'data/batch-vars-offerids.csv'),
1399
+ offerTemplateFilename: path.join(
1400
+ __dirname,
1401
+ 'data/email-offer.template.json'
1402
+ ),
1403
+ termsUrl: 'http://example.com/terms.html',
1404
+ did: 'did:ion:sap123',
1405
+ new: true,
1406
+ dryrun: true,
1407
+ };
1408
+ await runBatchIssuing(options);
1409
+ expect(gotExtendSpy.mock.calls).toEqual([
1410
+ [{ https: { rejectUnauthorized: false } }],
1411
+ ]);
1412
+ });
1413
+
1414
+ it('when NODE_TLS_REJECT_UNAUTHORIZED is value other than "0", got client should be setup without https.rejectUnauthorized', async () => {
1415
+ const options = {
1416
+ csvFilename: path.join(__dirname, 'data/batch-vars-offerids.csv'),
1417
+ offerTemplateFilename: path.join(
1418
+ __dirname,
1419
+ 'data/email-offer.template.json'
1420
+ ),
1421
+ termsUrl: 'http://example.com/terms.html',
1422
+ did: 'did:ion:sap123',
1423
+ new: true,
1424
+ dryrun: true,
1425
+ };
1426
+ env.NODE_TLS_REJECT_UNAUTHORIZED = 'false';
1427
+ await runBatchIssuing(options);
1428
+ env.NODE_TLS_REJECT_UNAUTHORIZED = '';
1429
+ await runBatchIssuing(options);
1430
+ env.NODE_TLS_REJECT_UNAUTHORIZED = 'undefined';
1431
+ await runBatchIssuing(options);
1432
+ delete env.NODE_TLS_REJECT_UNAUTHORIZED;
1433
+ await runBatchIssuing(options);
1434
+ expect(gotExtendSpy.mock.calls).toEqual([[{}], [{}], [{}], [{}]]);
1435
+ });
1436
+ });
1289
1437
  });
@@ -0,0 +1,3 @@
1
+ givenName,familyName,email,did
2
+ Joan,Lee,joan.lee@sap.com,did:ion:sap123
3
+ John,Smith,john.smith@sap.com,did:ion:sap123