@almatar/branding 1.0.0-beta.2 → 1.0.0-beta.3.1

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.
Files changed (27) hide show
  1. package/lib/index.d.ts +10 -0
  2. package/lib/index.js +15 -5
  3. package/lib/lib/AlmatarBranding.js +6 -9
  4. package/lib/lib/BrandIdentifier.js +57 -111
  5. package/lib/lib/BrandManager.js +138 -192
  6. package/lib/lib/Models/BrandModel.js +3 -4
  7. package/lib/lib/Models/EmployeeBrandModel.js +3 -4
  8. package/lib/lib/Storage.js +111 -159
  9. package/lib/lib/TenantModel/Mongoose/MultiTenant.js +13 -17
  10. package/lib/lib/TenantModel/MongooseModel.d.ts +0 -4
  11. package/lib/lib/TenantModel/MongooseModel.js +153 -69
  12. package/lib/lib/TenantModel/MongooseTenantHelper.d.ts +50 -0
  13. package/lib/lib/TenantModel/MongooseTenantHelper.js +146 -0
  14. package/lib/lib/TenantModel/MongooseTenantRepository.d.ts +103 -0
  15. package/lib/lib/TenantModel/MongooseTenantRepository.js +161 -0
  16. package/lib/lib/TenantModel/NestMongoose/TenantMongooseModule.js +14 -31
  17. package/lib/lib/TenantModel/NestMongoose/mongoose.providers.d.ts +2 -2
  18. package/lib/lib/TenantModel/NestMongoose/mongoose.providers.js +8 -9
  19. package/lib/lib/TenantModel/TypeORM/TenantEntitySubscriber.d.ts +27 -0
  20. package/lib/lib/TenantModel/TypeORM/TenantEntitySubscriber.js +68 -0
  21. package/lib/lib/TenantModel/TypeORM/TenantHttpInterceptor.d.ts +26 -0
  22. package/lib/lib/TenantModel/TypeORM/TenantHttpInterceptor.js +92 -0
  23. package/lib/lib/TenantModel/TypeORM/TenantRepository.d.ts +58 -0
  24. package/lib/lib/TenantModel/TypeORM/TenantRepository.js +281 -0
  25. package/lib/lib/request/PromiseRequest.js +52 -98
  26. package/lib/lib/request/TenantRequest.js +36 -98
  27. package/package.json +5 -1
package/lib/index.d.ts CHANGED
@@ -3,11 +3,21 @@ import MultiTenant from './lib/TenantModel/Mongoose/MultiTenant';
3
3
  import TenantMongooseModule from './lib/TenantModel/NestMongoose/TenantMongooseModule';
4
4
  import TenantRequest from './lib/request/TenantRequest';
5
5
  import AlmatarBranding from './lib/AlmatarBranding';
6
+ import { TenantRepository } from './lib/TenantModel/TypeORM/TenantRepository';
7
+ import { TenantEntitySubscriber } from './lib/TenantModel/TypeORM/TenantEntitySubscriber';
8
+ import { TenantHttpInterceptor } from './lib/TenantModel/TypeORM/TenantHttpInterceptor';
9
+ import { MongooseTenantHelper } from './lib/TenantModel/MongooseTenantHelper';
10
+ import { TenantMongooseRepository } from './lib/TenantModel/MongooseTenantRepository';
6
11
  declare const _default: {
7
12
  ContextNamespace: typeof ContextNamespace;
8
13
  MultiTenant: typeof MultiTenant;
9
14
  TenantMongooseModule: typeof TenantMongooseModule;
10
15
  TenantRequest: typeof TenantRequest;
11
16
  AlmatarBranding: typeof AlmatarBranding;
17
+ TenantRepository: typeof TenantRepository;
18
+ TenantEntitySubscriber: typeof TenantEntitySubscriber;
19
+ TenantHttpInterceptor: typeof TenantHttpInterceptor;
20
+ MongooseTenantHelper: typeof MongooseTenantHelper;
21
+ TenantMongooseRepository: typeof TenantMongooseRepository;
12
22
  };
13
23
  export = _default;
package/lib/index.js CHANGED
@@ -2,15 +2,25 @@
2
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
- var Storage_1 = __importDefault(require("./lib/Storage"));
6
- var MultiTenant_1 = __importDefault(require("./lib/TenantModel/Mongoose/MultiTenant"));
7
- var TenantMongooseModule_1 = __importDefault(require("./lib/TenantModel/NestMongoose/TenantMongooseModule"));
8
- var TenantRequest_1 = __importDefault(require("./lib/request/TenantRequest"));
9
- var AlmatarBranding_1 = __importDefault(require("./lib/AlmatarBranding"));
5
+ const Storage_1 = __importDefault(require("./lib/Storage"));
6
+ const MultiTenant_1 = __importDefault(require("./lib/TenantModel/Mongoose/MultiTenant"));
7
+ const TenantMongooseModule_1 = __importDefault(require("./lib/TenantModel/NestMongoose/TenantMongooseModule"));
8
+ const TenantRequest_1 = __importDefault(require("./lib/request/TenantRequest"));
9
+ const AlmatarBranding_1 = __importDefault(require("./lib/AlmatarBranding"));
10
+ const TenantRepository_1 = require("./lib/TenantModel/TypeORM/TenantRepository");
11
+ const TenantEntitySubscriber_1 = require("./lib/TenantModel/TypeORM/TenantEntitySubscriber");
12
+ const TenantHttpInterceptor_1 = require("./lib/TenantModel/TypeORM/TenantHttpInterceptor");
13
+ const MongooseTenantHelper_1 = require("./lib/TenantModel/MongooseTenantHelper");
14
+ const MongooseTenantRepository_1 = require("./lib/TenantModel/MongooseTenantRepository");
10
15
  module.exports = {
11
16
  ContextNamespace: Storage_1.default,
12
17
  MultiTenant: MultiTenant_1.default,
13
18
  TenantMongooseModule: TenantMongooseModule_1.default,
14
19
  TenantRequest: TenantRequest_1.default,
15
20
  AlmatarBranding: AlmatarBranding_1.default,
21
+ TenantRepository: TenantRepository_1.TenantRepository,
22
+ TenantEntitySubscriber: TenantEntitySubscriber_1.TenantEntitySubscriber,
23
+ TenantHttpInterceptor: TenantHttpInterceptor_1.TenantHttpInterceptor,
24
+ MongooseTenantHelper: MongooseTenantHelper_1.MongooseTenantHelper,
25
+ TenantMongooseRepository: MongooseTenantRepository_1.TenantMongooseRepository,
16
26
  };
@@ -1,14 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var AlmatarBranding = /** @class */ (function () {
4
- function AlmatarBranding() {
5
- }
6
- AlmatarBranding.setup = function (configs) {
3
+ class AlmatarBranding {
4
+ static setup(configs) {
7
5
  this.employeeAuthService = configs.employeeAuthService;
8
6
  this.dictionaryService = configs.dictionaryService;
9
- };
10
- AlmatarBranding.employeeAuthService = '';
11
- AlmatarBranding.dictionaryService = '';
12
- return AlmatarBranding;
13
- }());
7
+ }
8
+ }
14
9
  exports.default = AlmatarBranding;
10
+ AlmatarBranding.employeeAuthService = '';
11
+ AlmatarBranding.dictionaryService = '';
@@ -18,120 +18,67 @@ var __importStar = (this && this.__importStar) || function (mod) {
18
18
  __setModuleDefault(result, mod);
19
19
  return result;
20
20
  };
21
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
- return new (P || (P = Promise))(function (resolve, reject) {
24
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
- step((generator = generator.apply(thisArg, _arguments || [])).next());
28
- });
29
- };
30
- var __generator = (this && this.__generator) || function (thisArg, body) {
31
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
32
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
33
- function verb(n) { return function (v) { return step([n, v]); }; }
34
- function step(op) {
35
- if (f) throw new TypeError("Generator is already executing.");
36
- while (_) try {
37
- 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;
38
- if (y = 0, t) op = [op[0] & 2, t.value];
39
- switch (op[0]) {
40
- case 0: case 1: t = op; break;
41
- case 4: _.label++; return { value: op[1], done: false };
42
- case 5: _.label++; y = op[1]; op = [0]; continue;
43
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
44
- default:
45
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
46
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
47
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
48
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
49
- if (t[2]) _.ops.pop();
50
- _.trys.pop(); continue;
51
- }
52
- op = body.call(thisArg, _);
53
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
54
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
55
- }
56
- };
57
21
  Object.defineProperty(exports, "__esModule", { value: true });
58
22
  exports.BrandIdentifier = void 0;
59
- var Boom = __importStar(require("@hapi/boom"));
60
- var BrandManager_1 = require("./BrandManager");
61
- var BrandIdentifier = /** @class */ (function () {
62
- function BrandIdentifier(type) {
23
+ const Boom = __importStar(require("@hapi/boom"));
24
+ const BrandManager_1 = require("./BrandManager");
25
+ class BrandIdentifier {
26
+ constructor(type) {
63
27
  this.type = type;
64
28
  }
65
- BrandIdentifier.prototype.getBrand = function (req) {
66
- return __awaiter(this, void 0, void 0, function () {
67
- var brandManager, brand, tokenBrands;
68
- return __generator(this, function (_a) {
69
- switch (_a.label) {
70
- case 0:
71
- brandManager = new BrandManager_1.BrandManager(this.type);
72
- if (!req.headers['x-brand']) return [3 /*break*/, 1];
73
- return [2 /*return*/, brandManager.getB2CBrand(req)];
74
- case 1:
75
- if (!(req.headers.authorization || req.headers['x-employee-brands'])) return [3 /*break*/, 3];
76
- return [4 /*yield*/, brandManager.getConsoleBrands(req)];
77
- case 2:
78
- brand = _a.sent();
79
- if (brand) {
80
- if (brand.length) {
81
- return [2 /*return*/, brand];
82
- }
83
- return [2 /*return*/, brandManager.getDefaultBrand()];
84
- }
85
- // If no brand found but we have authorization, try extracting from token directly
86
- if (req.headers.authorization) {
87
- tokenBrands = brandManager.extractBrandFromToken(req.headers.authorization);
88
- if (tokenBrands && tokenBrands.length > 0) {
89
- return [2 /*return*/, tokenBrands];
90
- }
91
- }
92
- // Return empty array instead of null when no brand found in token
93
- // tslint:disable-next-line no-console
94
- console.log('[BrandIdentifier] No brand found in token, returning empty array');
95
- return [2 /*return*/, []];
96
- case 3: return [2 /*return*/, brandManager.getDefaultBrand()];
97
- }
98
- });
99
- });
100
- };
101
- BrandIdentifier.prototype.getBrands = function () {
102
- return __awaiter(this, void 0, void 0, function () {
103
- var brandManager, brands, err_1;
104
- return __generator(this, function (_a) {
105
- switch (_a.label) {
106
- case 0:
107
- brandManager = new BrandManager_1.BrandManager(this.type);
108
- _a.label = 1;
109
- case 1:
110
- _a.trys.push([1, 3, , 4]);
111
- return [4 /*yield*/, brandManager.getBrands()];
112
- case 2:
113
- brands = _a.sent();
114
- if (!brands) {
115
- // tslint:disable-next-line no-console
116
- console.log('[BrandIdentifier] Could not fetch brands list from dictionary service, continuing without it');
117
- return [2 /*return*/, null];
118
- }
119
- return [2 /*return*/, brands];
120
- case 3:
121
- err_1 = _a.sent();
122
- // tslint:disable-next-line no-console
123
- console.log('[BrandIdentifier] Error fetching brands list, continuing without it:', err_1);
124
- return [2 /*return*/, null];
125
- case 4: return [2 /*return*/];
29
+ async getBrand(req) {
30
+ const brandManager = new BrandManager_1.BrandManager(this.type);
31
+ if (req.headers['x-brand']) {
32
+ // B2C scenario - return the brand from x-brand header
33
+ return brandManager.getB2CBrand(req);
34
+ }
35
+ else if (req.headers.authorization || req.headers['x-employee-brands']) {
36
+ // Employee/Console scenario - extract from token or x-employee-brands header
37
+ const brand = await brandManager.getConsoleBrands(req);
38
+ if (brand && brand.length > 0) {
39
+ return brand;
40
+ }
41
+ // If no brand found but we have authorization, try extracting from token directly
42
+ if (req.headers.authorization) {
43
+ const tokenBrands = brandManager.extractBrandFromToken(req.headers.authorization);
44
+ if (tokenBrands && tokenBrands.length > 0) {
45
+ return tokenBrands;
126
46
  }
127
- });
128
- });
129
- };
130
- BrandIdentifier.prototype.getDefaultBrand = function () {
131
- var brandManager = new BrandManager_1.BrandManager(this.type);
47
+ }
48
+ // No brand found in token/headers - return null (don't use default brand)
49
+ // tslint:disable-next-line no-console
50
+ console.log('[BrandIdentifier] No brand found in token or headers, returning null');
51
+ return null;
52
+ }
53
+ else {
54
+ // No auth token and no x-brand header - return null (don't use default brand)
55
+ // tslint:disable-next-line no-console
56
+ console.log('[BrandIdentifier] No auth token or x-brand header, returning null');
57
+ return null;
58
+ }
59
+ }
60
+ async getBrands() {
61
+ const brandManager = new BrandManager_1.BrandManager(this.type);
62
+ try {
63
+ const brands = await brandManager.getBrands();
64
+ if (!brands) {
65
+ // tslint:disable-next-line no-console
66
+ console.log('[BrandIdentifier] Could not fetch brands list from dictionary service, continuing without it');
67
+ return null;
68
+ }
69
+ return brands;
70
+ }
71
+ catch (err) {
72
+ // tslint:disable-next-line no-console
73
+ console.log('[BrandIdentifier] Error fetching brands list, continuing without it:', err);
74
+ return null;
75
+ }
76
+ }
77
+ getDefaultBrand() {
78
+ const brandManager = new BrandManager_1.BrandManager(this.type);
132
79
  return brandManager.getDefaultBrand();
133
- };
134
- BrandIdentifier.prototype.error = function (message) {
80
+ }
81
+ error(message) {
135
82
  switch (this.type) {
136
83
  case 'hapi':
137
84
  return Boom.unauthorized(message);
@@ -142,7 +89,6 @@ var BrandIdentifier = /** @class */ (function () {
142
89
  default:
143
90
  return new Error(message);
144
91
  }
145
- };
146
- return BrandIdentifier;
147
- }());
92
+ }
93
+ }
148
94
  exports.BrandIdentifier = BrandIdentifier;