@forzalabs/remora 0.0.20 → 0.0.21

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.
@@ -76,7 +76,7 @@ class ValidatorClass {
76
76
  (0, Affirm_1.default)(consumer, 'Invalid consumer');
77
77
  const errors = [];
78
78
  try {
79
- // TODO: check that a consumer doens't consume himself
79
+ // TODO: check that a consumer doesn't consume hitself
80
80
  const allFieldsWithNoFrom = consumer.fields.filter(x => x.key === '*' && !x.from);
81
81
  if (allFieldsWithNoFrom.length > 0 && consumer.producers.length > 1)
82
82
  errors.push(`Field with key "*" was used without specifying the "from" producer and multiple producers were found.`);
@@ -126,17 +126,34 @@ class ValidatorClass {
126
126
  });
127
127
  return errors;
128
128
  };
129
+ const validateTransformations = (fields) => {
130
+ const errors = [];
131
+ const trxsFields = fields.filter(x => x.transform);
132
+ for (const field of trxsFields) {
133
+ const transformations = Object.keys(field.transform);
134
+ if (transformations.length !== 1)
135
+ errors.push(`There can only be 1 transformation type in your transformation pipeline. Field "${field.key}" got ${transformations.length}`);
136
+ }
137
+ return errors;
138
+ };
129
139
  errors.push(...validateGroupingLevels(consumer.fields));
140
+ errors.push(...validateTransformations(consumer.fields));
130
141
  // Validation outputs
131
142
  const duplicatesOutputs = Algo_1.default.duplicatesObject(consumer.outputs, 'format');
132
143
  if (duplicatesOutputs.length > 0) {
133
144
  const duplicatesTypes = Algo_1.default.uniq(duplicatesOutputs.map(x => x.format));
134
145
  errors.push(`There are outputs with the same type. (duplicates type: ${duplicatesTypes.join(' and ')})`);
135
146
  }
136
- for (let i = 0; i < consumer.outputs.length; i++) {
137
- const output = consumer.outputs[i];
138
- if (output.format === 'SQL' && output.accellerated && output.direct)
139
- errors.push(`An output SQL cannot be both direct and accelerated. (output: ${output.format})`);
147
+ for (const output of consumer.outputs) {
148
+ const format = output.format.toUpperCase();
149
+ if (format === 'SQL' && output.accellerated && output.direct)
150
+ errors.push(`An output SQL cannot be both direct and accelerated (output: ${format})`);
151
+ if ((format === 'CSV' || format === 'JSON' || format === 'PARQUET')) {
152
+ if (!output.exportDestination)
153
+ errors.push(`A static file output must have an export destination set (${format})`);
154
+ else if (!Environment_1.default.getSource(output.exportDestination))
155
+ errors.push(`The export destination "${output.exportDestination}" was not found in the sources.`);
156
+ }
140
157
  }
141
158
  }
142
159
  catch (e) {
package/helper/Helper.js CHANGED
@@ -59,6 +59,13 @@ const Helper = {
59
59
  }
60
60
  read(directory);
61
61
  return functionFiles;
62
+ },
63
+ formatDateToYYYYMM(date) {
64
+ if (!date)
65
+ return '';
66
+ const year = date.getFullYear();
67
+ const month = ('0' + (date.getMonth() + 1)).slice(-2);
68
+ return `${year}-${month}`;
62
69
  }
63
70
  };
64
71
  exports.default = Helper;
package/index.js CHANGED
@@ -16,8 +16,15 @@ const discover_1 = require("./actions/discover");
16
16
  const automap_1 = require("./actions/automap");
17
17
  const create_producer_1 = require("./actions/create_producer");
18
18
  const create_consumer_1 = require("./actions/create_consumer");
19
+ const LicenceManager_1 = __importDefault(require("./licencing/LicenceManager"));
19
20
  dotenv_1.default.configDotenv();
20
21
  const program = new commander_1.Command();
22
+ const remoraLicenceKey = process.env.REMORA_LICENCE_KEY;
23
+ const check = LicenceManager_1.default.validate(remoraLicenceKey);
24
+ if (!check.valid) {
25
+ console.error(`Invalid Remora licence key, the product is not active: remember to set "REMORA_LICENCE_KEY" environment variable.`);
26
+ process.exit(1);
27
+ }
21
28
  program
22
29
  .version(Constants_1.default.cliVersion + '', '-v, --version', 'Display the version of the CLI')
23
30
  .description('CLI tool for setting up and managing Data-Remora');
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const crypto_1 = __importDefault(require("crypto"));
7
+ const PUBLICK_KEY = `-----BEGIN PUBLIC KEY-----
8
+ MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA7BWugM83YKGzTyZ6kJyy
9
+ M01JoGYBQYn/9H9utQQyC/uugV4g9d7vv87I2yUfqiHtx7BQj0mOGctqnK7vuRcg
10
+ py7fghTjsUj0MDhs8cEpc+47m0xdsU9MQQ8Xze8B3FcdvCc4xtT5nruTAUWMGIAM
11
+ WLHG8lWxkHjTSZn4S0RdpRBB7fw4jyVkc+vXCTtVtYQwMWjcErNFrdCenvci4Vus
12
+ nKlyfKS6ccLQphOc/I2w6zllFwD/l90vQeQ6kDO01aJLOmJPzvlU/TSP/lcxCYTA
13
+ TgQJQxd5UdnTSDjNw+Uu/jzZ5mVlCbtYH1RoJ6cGNglzN8Q50mVk/iVyoZCZ94b4
14
+ bwIDAQAB
15
+ -----END PUBLIC KEY-----`;
16
+ class LicenceManagerClass {
17
+ constructor() {
18
+ this.generate = (customer, expirationDays, features, privateKey) => {
19
+ const now = new Date();
20
+ const expirationDate = new Date(now.getTime() + expirationDays * 24 * 60 * 60 * 1000);
21
+ const licenceData = {
22
+ customer,
23
+ features,
24
+ issued: now.toISOString(),
25
+ expires: expirationDate.toISOString()
26
+ };
27
+ const licenceString = JSON.stringify(licenceData);
28
+ const sign = crypto_1.default.createSign('SHA256');
29
+ sign.update(licenceString);
30
+ sign.end();
31
+ const signature = sign.sign(privateKey, 'base64');
32
+ const licence = { data: licenceData, signature };
33
+ return Buffer.from(JSON.stringify(licence)).toString('base64');
34
+ };
35
+ this.validate = (licence) => {
36
+ try {
37
+ const licenceJSON = Buffer.from(licence, 'base64').toString();
38
+ const licenceData = JSON.parse(licenceJSON);
39
+ const { data, signature } = licenceData;
40
+ const now = new Date();
41
+ const expirationDate = new Date(data.expires);
42
+ if (now > expirationDate)
43
+ return { valid: false, reason: 'License expired', expiryDate: expirationDate };
44
+ const verify = crypto_1.default.createVerify('SHA256');
45
+ verify.update(JSON.stringify(data));
46
+ const isSignatureValid = verify.verify(PUBLICK_KEY, signature, 'base64');
47
+ if (!isSignatureValid)
48
+ return { valid: false, reason: 'Invalid license signature' };
49
+ return {
50
+ valid: true,
51
+ expiryDate: expirationDate,
52
+ daysRemaining: Math.ceil((expirationDate.getTime() - now.getTime()) / (24 * 60 * 60 * 1000)),
53
+ features: data.features,
54
+ customer: data.customer
55
+ };
56
+ }
57
+ catch (error) {
58
+ return { valid: false, reason: 'License parsing error', details: error.message };
59
+ }
60
+ };
61
+ }
62
+ }
63
+ const LicenceManager = new LicenceManagerClass();
64
+ exports.default = LicenceManager;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forzalabs/remora",
3
- "version": "0.0.20",
3
+ "version": "0.0.21",
4
4
  "description": "A powerful CLI tool for seamless data translation.",
5
5
  "main": "index.js",
6
6
  "private": false,