@almatar/branding 0.1.7 → 0.1.9-alpha

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.
@@ -14,7 +14,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
14
14
  function verb(n) { return function (v) { return step([n, v]); }; }
15
15
  function step(op) {
16
16
  if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
18
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
19
  if (y = 0, t) op = [op[0] & 2, t.value];
20
20
  switch (op[0]) {
@@ -14,7 +14,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
14
14
  function verb(n) { return function (v) { return step([n, v]); }; }
15
15
  function step(op) {
16
16
  if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
18
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
19
  if (y = 0, t) op = [op[0] & 2, t.value];
20
20
  switch (op[0]) {
@@ -40,6 +40,10 @@ exports.BrandManager = void 0;
40
40
  var AlmatarBranding_1 = require("./AlmatarBranding");
41
41
  var Storage_1 = require("./Storage");
42
42
  var PromiseRequest_1 = require("./request/PromiseRequest");
43
+ var NodeCahe = require("node-cache");
44
+ var cacheManager = new NodeCahe({
45
+ stdTTL: 86400
46
+ });
43
47
  var BrandManager = /** @class */ (function () {
44
48
  function BrandManager(type) {
45
49
  this.defaultBrand = 'almatar';
@@ -71,12 +75,14 @@ var BrandManager = /** @class */ (function () {
71
75
  };
72
76
  BrandManager.prototype.loadBrands = function (req) {
73
77
  return __awaiter(this, void 0, void 0, function () {
74
- var reqBody, options, employeeBrands, brands, err_1;
78
+ var reqBody, employeeBrands, options, brands, err_1;
75
79
  return __generator(this, function (_a) {
76
80
  switch (_a.label) {
77
81
  case 0:
78
- _a.trys.push([0, 2, , 3]);
82
+ _a.trys.push([0, 4, , 5]);
79
83
  reqBody = req.payload ? req.payload : req.body;
84
+ employeeBrands = cacheManager.get('employee_brands');
85
+ if (!!(employeeBrands === null || employeeBrands === void 0 ? void 0 : employeeBrands.status)) return [3 /*break*/, 3];
80
86
  options = {
81
87
  url: AlmatarBranding_1.default.employeeAuthService + '/v1/user/brands',
82
88
  headers: {
@@ -86,6 +92,11 @@ var BrandManager = /** @class */ (function () {
86
92
  return [4 /*yield*/, PromiseRequest_1.PromiseRequest.request(options)];
87
93
  case 1:
88
94
  employeeBrands = _a.sent();
95
+ return [4 /*yield*/, cacheManager.set('employee_brands', employeeBrands)];
96
+ case 2:
97
+ _a.sent();
98
+ _a.label = 3;
99
+ case 3:
89
100
  if (employeeBrands.status === 200) {
90
101
  brands = employeeBrands.data.map(function (brand) { return brand.slug; });
91
102
  if (reqBody && reqBody.brand) {
@@ -94,12 +105,12 @@ var BrandManager = /** @class */ (function () {
94
105
  return [2 /*return*/, brands];
95
106
  }
96
107
  return [2 /*return*/, null];
97
- case 2:
108
+ case 4:
98
109
  err_1 = _a.sent();
99
110
  // tslint:disable-next-line no-console
100
111
  console.log(err_1);
101
112
  return [2 /*return*/, null];
102
- case 3: return [2 /*return*/];
113
+ case 5: return [2 /*return*/];
103
114
  }
104
115
  });
105
116
  });
@@ -110,17 +121,24 @@ var BrandManager = /** @class */ (function () {
110
121
  */
111
122
  BrandManager.prototype.getBrands = function () {
112
123
  return __awaiter(this, void 0, void 0, function () {
113
- var option, brandsResponse, brands, err_2;
124
+ var brandsResponse, option, brands, err_2;
114
125
  return __generator(this, function (_a) {
115
126
  switch (_a.label) {
116
127
  case 0:
117
- _a.trys.push([0, 2, , 3]);
128
+ _a.trys.push([0, 4, , 5]);
129
+ brandsResponse = cacheManager.get('cachedBrands');
130
+ if (!!(brandsResponse === null || brandsResponse === void 0 ? void 0 : brandsResponse.status)) return [3 /*break*/, 3];
118
131
  option = {
119
132
  url: AlmatarBranding_1.default.dictionaryService + 'brands',
120
133
  };
121
134
  return [4 /*yield*/, PromiseRequest_1.PromiseRequest.request(option)];
122
135
  case 1:
123
136
  brandsResponse = _a.sent();
137
+ return [4 /*yield*/, cacheManager.set('cachedBrands', brandsResponse)];
138
+ case 2:
139
+ _a.sent();
140
+ _a.label = 3;
141
+ case 3:
124
142
  if (brandsResponse.status === 200) {
125
143
  Storage_1.default.setBrandsList(brandsResponse.data.list);
126
144
  brands = brandsResponse.data.list.map(function (brand) { return brand.key; });
@@ -128,12 +146,12 @@ var BrandManager = /** @class */ (function () {
128
146
  return [2 /*return*/, brands];
129
147
  }
130
148
  return [2 /*return*/, null];
131
- case 2:
149
+ case 4:
132
150
  err_2 = _a.sent();
133
151
  // tslint:disable-next-line:no-console
134
152
  console.log(err_2);
135
153
  return [2 /*return*/, null];
136
- case 3: return [2 /*return*/];
154
+ case 5: return [2 /*return*/];
137
155
  }
138
156
  });
139
157
  });
@@ -14,7 +14,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
14
14
  function verb(n) { return function (v) { return step([n, v]); }; }
15
15
  function step(op) {
16
16
  if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
18
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
19
  if (y = 0, t) op = [op[0] & 2, t.value];
20
20
  switch (op[0]) {
@@ -53,7 +53,7 @@ var ContextNamespace = /** @class */ (function () {
53
53
  return __generator(this, function (_a) {
54
54
  switch (_a.label) {
55
55
  case 0:
56
- brandIdentifier = new BrandIdentifier_1.BrandIdentifier('hapi');
56
+ brandIdentifier = new BrandIdentifier_1.BrandIdentifier('express');
57
57
  return [4 /*yield*/, brandIdentifier.getBrands()];
58
58
  case 1:
59
59
  _a.sent();
@@ -18,7 +18,7 @@ var MongooseModel = /** @class */ (function () {
18
18
  this.addPreSaveQueries(schema);
19
19
  this.addPreInsertManyQueries(schema);
20
20
  }
21
- var modelName = skipBrand || !Array.isArray(brands) ? name : name + "-" + brands.join('-');
21
+ var modelName = skipBrand || !Array.isArray(brands) ? name : "".concat(name, "-").concat(brands.join('-'));
22
22
  if (!existingModels[modelName]) {
23
23
  existingModels[modelName] = this.mongoose.model(modelName, schema, options);
24
24
  }
@@ -3,10 +3,12 @@ var __extends = (this && this.__extends) || (function () {
3
3
  var extendStatics = function (d, b) {
4
4
  extendStatics = Object.setPrototypeOf ||
5
5
  ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
7
  return extendStatics(d, b);
8
8
  };
9
9
  return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
10
12
  extendStatics(d, b);
11
13
  function __() { this.constructor = d; }
12
14
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
@@ -29,8 +31,8 @@ var TenantMongooseModule = /** @class */ (function (_super) {
29
31
  }
30
32
  TenantMongooseModule.forFeature = function (models, connectionName) {
31
33
  if (models === void 0) { models = []; }
32
- connectionName = connectionName ? connectionName + "Connection" : 'MongooseConnectionName';
33
- var modelProviders = mongoose_providers_1.createMongooseProviders(connectionName, models);
34
+ connectionName = connectionName ? "".concat(connectionName, "Connection") : 'MongooseConnectionName';
35
+ var modelProviders = (0, mongoose_providers_1.createMongooseProviders)(connectionName, models);
34
36
  return {
35
37
  module: mongoose_1.MongooseModule,
36
38
  providers: modelProviders,
@@ -38,7 +40,7 @@ var TenantMongooseModule = /** @class */ (function (_super) {
38
40
  };
39
41
  };
40
42
  TenantMongooseModule = __decorate([
41
- common_1.Module({})
43
+ (0, common_1.Module)({})
42
44
  ], TenantMongooseModule);
43
45
  return TenantMongooseModule;
44
46
  }(mongoose_1.MongooseModule));
@@ -5,12 +5,12 @@ var MongooseModel_1 = require("../MongooseModel");
5
5
  function createMongooseProviders(connectionName, models) {
6
6
  if (models === void 0) { models = []; }
7
7
  var providers = (models || []).map(function (model) { return ({
8
- provide: model.name + "Model",
8
+ provide: "".concat(model.name, "Model"),
9
9
  useFactory: function (connection) {
10
10
  var mongooseModel = new MongooseModel_1.MongooseModel(connection);
11
11
  return mongooseModel.createModel(model.name, model.schema, model.collection, {});
12
12
  },
13
- inject: [connectionName + "Connection"],
13
+ inject: ["".concat(connectionName, "Connection")],
14
14
  }); });
15
15
  return providers;
16
16
  }
@@ -14,7 +14,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
14
14
  function verb(n) { return function (v) { return step([n, v]); }; }
15
15
  function step(op) {
16
16
  if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
18
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
19
  if (y = 0, t) op = [op[0] & 2, t.value];
20
20
  switch (op[0]) {
@@ -14,7 +14,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
14
14
  function verb(n) { return function (v) { return step([n, v]); }; }
15
15
  function step(op) {
16
16
  if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
18
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
19
  if (y = 0, t) op = [op[0] & 2, t.value];
20
20
  switch (op[0]) {
@@ -56,7 +56,7 @@ var TenantRequest = /** @class */ (function () {
56
56
  options.reqObject.headers['x-brand'] = brand;
57
57
  // tslint:disable-next-line:no-unused-expression
58
58
  employeeBrands ? (options.reqObject.headers['x-employee-brands'] = employeeBrands.join(',')) : null;
59
- return [4 /*yield*/, node_fetch_1.default(options.url, options.reqObject)
59
+ return [4 /*yield*/, (0, node_fetch_1.default)(options.url, options.reqObject)
60
60
  .then(function (res) {
61
61
  return res.json();
62
62
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@almatar/branding",
3
- "version": "0.1.7",
3
+ "version": "0.1.9-alpha",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -27,9 +27,11 @@
27
27
  "@nestjs/core": "^6.8.2",
28
28
  "@nestjs/mongoose": "^6.1.2",
29
29
  "@types/mongoose": "^5.5.19",
30
+ "@types/node-cache": "^4.2.5",
30
31
  "@types/request": "^2.48.3",
31
32
  "cls-hooked": "^4.2.2",
32
33
  "mongoose": "^5.7.3",
34
+ "node-cache": "^5.1.2",
33
35
  "node-fetch": "^2.6.1",
34
36
  "reflect-metadata": "^0.1.13",
35
37
  "request": "^2.88.0",
@@ -51,6 +53,7 @@
51
53
  "ts-jest": "^24.1.0",
52
54
  "tslint": "^5.20.0",
53
55
  "tslint-config-prettier": "^1.18.0",
54
- "typescript": "^3.6.3"
56
+ "ts-node": "^10.8.1",
57
+ "typescript": "^4.6.3"
55
58
  }
56
59
  }