@almatar/branding 0.2.0 → 1.0.0-beta.3
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/lib/index.d.ts +6 -0
- package/lib/index.js +14 -5
- package/lib/lib/AlmatarBranding.js +6 -9
- package/lib/lib/BrandIdentifier.d.ts +2 -2
- package/lib/lib/BrandIdentifier.js +72 -88
- package/lib/lib/BrandManager.d.ts +5 -0
- package/lib/lib/BrandManager.js +178 -127
- package/lib/lib/Models/BrandModel.js +3 -4
- package/lib/lib/Models/EmployeeBrandModel.js +3 -4
- package/lib/lib/Storage.js +78 -151
- package/lib/lib/TenantModel/Mongoose/MultiTenant.js +13 -17
- package/lib/lib/TenantModel/MongooseModel.js +56 -39
- package/lib/lib/TenantModel/NestMongoose/TenantMongooseModule.js +12 -33
- package/lib/lib/TenantModel/NestMongoose/mongoose.providers.d.ts +0 -24
- package/lib/lib/TenantModel/NestMongoose/mongoose.providers.js +8 -9
- package/lib/lib/TenantModel/TypeORM/TenantEntitySubscriber.d.ts +27 -0
- package/lib/lib/TenantModel/TypeORM/TenantEntitySubscriber.js +68 -0
- package/lib/lib/TenantModel/TypeORM/TenantHttpInterceptor.d.ts +26 -0
- package/lib/lib/TenantModel/TypeORM/TenantHttpInterceptor.js +92 -0
- package/lib/lib/TenantModel/TypeORM/TenantRepository.d.ts +58 -0
- package/lib/lib/TenantModel/TypeORM/TenantRepository.js +281 -0
- package/lib/lib/request/PromiseRequest.js +37 -56
- package/lib/lib/request/TenantRequest.d.ts +4 -1
- package/lib/lib/request/TenantRequest.js +38 -68
- package/package.json +31 -25
package/lib/index.d.ts
CHANGED
|
@@ -3,11 +3,17 @@ 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';
|
|
6
9
|
declare const _default: {
|
|
7
10
|
ContextNamespace: typeof ContextNamespace;
|
|
8
11
|
MultiTenant: typeof MultiTenant;
|
|
9
12
|
TenantMongooseModule: typeof TenantMongooseModule;
|
|
10
13
|
TenantRequest: typeof TenantRequest;
|
|
11
14
|
AlmatarBranding: typeof AlmatarBranding;
|
|
15
|
+
TenantRepository: typeof TenantRepository;
|
|
16
|
+
TenantEntitySubscriber: typeof TenantEntitySubscriber;
|
|
17
|
+
TenantHttpInterceptor: typeof TenantHttpInterceptor;
|
|
12
18
|
};
|
|
13
19
|
export = _default;
|
package/lib/index.js
CHANGED
|
@@ -1,13 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
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");
|
|
7
13
|
module.exports = {
|
|
8
14
|
ContextNamespace: Storage_1.default,
|
|
9
15
|
MultiTenant: MultiTenant_1.default,
|
|
10
16
|
TenantMongooseModule: TenantMongooseModule_1.default,
|
|
11
17
|
TenantRequest: TenantRequest_1.default,
|
|
12
18
|
AlmatarBranding: AlmatarBranding_1.default,
|
|
19
|
+
TenantRepository: TenantRepository_1.TenantRepository,
|
|
20
|
+
TenantEntitySubscriber: TenantEntitySubscriber_1.TenantEntitySubscriber,
|
|
21
|
+
TenantHttpInterceptor: TenantHttpInterceptor_1.TenantHttpInterceptor,
|
|
13
22
|
};
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
11
|
-
AlmatarBranding.dictionaryService = '';
|
|
12
|
-
return AlmatarBranding;
|
|
13
|
-
}());
|
|
7
|
+
}
|
|
8
|
+
}
|
|
14
9
|
exports.default = AlmatarBranding;
|
|
10
|
+
AlmatarBranding.employeeAuthService = '';
|
|
11
|
+
AlmatarBranding.dictionaryService = '';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export declare class BrandIdentifier {
|
|
2
2
|
private readonly type;
|
|
3
3
|
constructor(type: string);
|
|
4
|
-
getBrand(req: any): Promise<string | string[] | null
|
|
5
|
-
getBrands(): Promise<string[] | null
|
|
4
|
+
getBrand(req: any): Promise<string | string[] | null>;
|
|
5
|
+
getBrands(): Promise<string[] | null>;
|
|
6
6
|
getDefaultBrand(): string;
|
|
7
7
|
private error;
|
|
8
8
|
}
|
|
@@ -1,97 +1,82 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
37
20
|
};
|
|
38
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
22
|
exports.BrandIdentifier = void 0;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
23
|
+
const Boom = __importStar(require("@hapi/boom"));
|
|
24
|
+
const BrandManager_1 = require("./BrandManager");
|
|
25
|
+
class BrandIdentifier {
|
|
26
|
+
constructor(type) {
|
|
44
27
|
this.type = type;
|
|
45
28
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (!(req.headers.authorization || req.headers['x-employee-brands'])) return [3 /*break*/, 3];
|
|
57
|
-
return [4 /*yield*/, brandManager.getConsoleBrands(req)];
|
|
58
|
-
case 2:
|
|
59
|
-
brand = _a.sent();
|
|
60
|
-
if (brand) {
|
|
61
|
-
if (brand.length) {
|
|
62
|
-
return [2 /*return*/, brand];
|
|
63
|
-
}
|
|
64
|
-
return [2 /*return*/, brandManager.getDefaultBrand()];
|
|
65
|
-
}
|
|
66
|
-
return [2 /*return*/, this.error('Unauthorized!')];
|
|
67
|
-
case 3: return [2 /*return*/, brandManager.getDefaultBrand()];
|
|
29
|
+
async getBrand(req) {
|
|
30
|
+
const brandManager = new BrandManager_1.BrandManager(this.type);
|
|
31
|
+
if (req.headers['x-brand']) {
|
|
32
|
+
return brandManager.getB2CBrand(req);
|
|
33
|
+
}
|
|
34
|
+
else if (req.headers.authorization || req.headers['x-employee-brands']) {
|
|
35
|
+
const brand = await brandManager.getConsoleBrands(req);
|
|
36
|
+
if (brand) {
|
|
37
|
+
if (brand.length) {
|
|
38
|
+
return brand;
|
|
68
39
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
switch (_a.label) {
|
|
77
|
-
case 0:
|
|
78
|
-
brandManager = new BrandManager_1.BrandManager(this.type);
|
|
79
|
-
return [4 /*yield*/, brandManager.getBrands()];
|
|
80
|
-
case 1:
|
|
81
|
-
brands = _a.sent();
|
|
82
|
-
if (!brands) {
|
|
83
|
-
this.error('error while fetching brands list from dictionary service');
|
|
84
|
-
}
|
|
85
|
-
return [2 /*return*/, brands];
|
|
40
|
+
return brandManager.getDefaultBrand();
|
|
41
|
+
}
|
|
42
|
+
// If no brand found but we have authorization, try extracting from token directly
|
|
43
|
+
if (req.headers.authorization) {
|
|
44
|
+
const tokenBrands = brandManager.extractBrandFromToken(req.headers.authorization);
|
|
45
|
+
if (tokenBrands && tokenBrands.length > 0) {
|
|
46
|
+
return tokenBrands;
|
|
86
47
|
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
48
|
+
}
|
|
49
|
+
// Return empty array instead of null when no brand found in token
|
|
50
|
+
// tslint:disable-next-line no-console
|
|
51
|
+
console.log('[BrandIdentifier] No brand found in token, returning empty array');
|
|
52
|
+
return [];
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
return brandManager.getDefaultBrand();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async getBrands() {
|
|
59
|
+
const brandManager = new BrandManager_1.BrandManager(this.type);
|
|
60
|
+
try {
|
|
61
|
+
const brands = await brandManager.getBrands();
|
|
62
|
+
if (!brands) {
|
|
63
|
+
// tslint:disable-next-line no-console
|
|
64
|
+
console.log('[BrandIdentifier] Could not fetch brands list from dictionary service, continuing without it');
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
return brands;
|
|
68
|
+
}
|
|
69
|
+
catch (err) {
|
|
70
|
+
// tslint:disable-next-line no-console
|
|
71
|
+
console.log('[BrandIdentifier] Error fetching brands list, continuing without it:', err);
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
getDefaultBrand() {
|
|
76
|
+
const brandManager = new BrandManager_1.BrandManager(this.type);
|
|
92
77
|
return brandManager.getDefaultBrand();
|
|
93
|
-
}
|
|
94
|
-
|
|
78
|
+
}
|
|
79
|
+
error(message) {
|
|
95
80
|
switch (this.type) {
|
|
96
81
|
case 'hapi':
|
|
97
82
|
return Boom.unauthorized(message);
|
|
@@ -102,7 +87,6 @@ var BrandIdentifier = /** @class */ (function () {
|
|
|
102
87
|
default:
|
|
103
88
|
return new Error(message);
|
|
104
89
|
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
}());
|
|
90
|
+
}
|
|
91
|
+
}
|
|
108
92
|
exports.BrandIdentifier = BrandIdentifier;
|
|
@@ -3,6 +3,11 @@ export declare class BrandManager {
|
|
|
3
3
|
private readonly defaultBrand;
|
|
4
4
|
constructor(type: string);
|
|
5
5
|
getB2CBrand(req: any): string;
|
|
6
|
+
/**
|
|
7
|
+
* Extract brand from JWT token payload
|
|
8
|
+
* @param token - JWT token string (with or without Bearer prefix)
|
|
9
|
+
*/
|
|
10
|
+
extractBrandFromToken(token: string): string[] | null;
|
|
6
11
|
getConsoleBrands(req: any): Promise<string[] | null>;
|
|
7
12
|
loadBrands(req: any): Promise<string[] | null>;
|
|
8
13
|
/**
|
package/lib/lib/BrandManager.js
CHANGED
|
@@ -1,149 +1,200 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
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
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
4
|
};
|
|
38
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
6
|
exports.BrandManager = void 0;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
7
|
+
const AlmatarBranding_1 = __importDefault(require("./AlmatarBranding"));
|
|
8
|
+
const Storage_1 = __importDefault(require("./Storage"));
|
|
9
|
+
const PromiseRequest_1 = require("./request/PromiseRequest");
|
|
10
|
+
class BrandManager {
|
|
11
|
+
constructor(type) {
|
|
45
12
|
this.defaultBrand = 'almatar';
|
|
46
13
|
this.type = type;
|
|
47
14
|
}
|
|
48
|
-
|
|
15
|
+
getB2CBrand(req) {
|
|
49
16
|
return req.headers['x-brand'];
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Extract brand from JWT token payload
|
|
20
|
+
* @param token - JWT token string (with or without Bearer prefix)
|
|
21
|
+
*/
|
|
22
|
+
extractBrandFromToken(token) {
|
|
23
|
+
try {
|
|
24
|
+
// Remove 'Bearer ' prefix if present
|
|
25
|
+
const cleanToken = token.replace(/^Bearer\s+/i, '');
|
|
26
|
+
// JWT format: header.payload.signature
|
|
27
|
+
const parts = cleanToken.split('.');
|
|
28
|
+
if (parts.length !== 3) {
|
|
29
|
+
// tslint:disable-next-line no-console
|
|
30
|
+
console.log('[BrandManager] Invalid JWT token format - expected 3 parts');
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
// Decode payload (base64url)
|
|
34
|
+
const payload = parts[1];
|
|
35
|
+
// Replace URL-safe base64 characters
|
|
36
|
+
const base64 = payload.replace(/-/g, '+').replace(/_/g, '/');
|
|
37
|
+
// Add padding if needed
|
|
38
|
+
const padded = base64 + '='.repeat((4 - (base64.length % 4)) % 4);
|
|
39
|
+
const decoded = Buffer.from(padded, 'base64').toString('utf-8');
|
|
40
|
+
const tokenPayload = JSON.parse(decoded);
|
|
41
|
+
// Extract brand from token payload
|
|
42
|
+
if (tokenPayload.brand) {
|
|
43
|
+
// Brand can be array or single string
|
|
44
|
+
let brands;
|
|
45
|
+
if (Array.isArray(tokenPayload.brand)) {
|
|
46
|
+
brands = tokenPayload.brand;
|
|
47
|
+
}
|
|
48
|
+
else if (typeof tokenPayload.brand === 'string') {
|
|
49
|
+
brands = [tokenPayload.brand];
|
|
68
50
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
51
|
+
else {
|
|
52
|
+
// tslint:disable-next-line no-console
|
|
53
|
+
console.log('[BrandManager] Brand in token is neither array nor string:', typeof tokenPayload.brand);
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
// tslint:disable-next-line no-console
|
|
57
|
+
console.log('[BrandManager] Successfully extracted brands from token:', brands);
|
|
58
|
+
return brands;
|
|
59
|
+
}
|
|
60
|
+
// tslint:disable-next-line no-console
|
|
61
|
+
console.log('[BrandManager] No brand field found in token payload');
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
// tslint:disable-next-line no-console
|
|
66
|
+
console.log('[BrandManager] Error extracting brand from token:', err);
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
async getConsoleBrands(req) {
|
|
71
|
+
// Priority 1: Check x-employee-brands header first
|
|
72
|
+
if (req.headers['x-employee-brands']) {
|
|
73
|
+
const brands = req.headers['x-employee-brands'].split(',').map((b) => b.trim()).filter((b) => b);
|
|
74
|
+
// tslint:disable-next-line no-console
|
|
75
|
+
console.log('[BrandManager] Extracted brands from x-employee-brands header:', brands);
|
|
76
|
+
if (brands.length > 0) {
|
|
77
|
+
return brands;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
// Priority 2: Try to extract brand from JWT token
|
|
81
|
+
if (req.headers.authorization) {
|
|
82
|
+
const tokenBrands = this.extractBrandFromToken(req.headers.authorization);
|
|
83
|
+
if (tokenBrands && tokenBrands.length > 0) {
|
|
84
|
+
// tslint:disable-next-line no-console
|
|
85
|
+
console.log('[BrandManager] Using brands extracted from token:', tokenBrands);
|
|
86
|
+
return tokenBrands;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
// DO NOT call loadBrands() here - it makes HTTP requests that can cause infinite loops
|
|
90
|
+
// If we don't have brand from token/header, return null instead
|
|
91
|
+
// tslint:disable-next-line no-console
|
|
92
|
+
console.log('[BrandManager] No brand found in token or headers, returning null (skipping loadBrands to prevent loops)');
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
async loadBrands(req) {
|
|
96
|
+
try {
|
|
97
|
+
const reqBody = req.payload ? req.payload : req.body;
|
|
98
|
+
const options = {
|
|
99
|
+
url: AlmatarBranding_1.default.employeeAuthService + '/v1/user/brands',
|
|
100
|
+
method: 'GET',
|
|
101
|
+
headers: {
|
|
102
|
+
authorization: req.headers.authorization,
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
const employeeBrands = await PromiseRequest_1.PromiseRequest.request(options);
|
|
106
|
+
// Check if response is valid and has the expected structure
|
|
107
|
+
if (employeeBrands && employeeBrands.status === 200 && employeeBrands.data) {
|
|
108
|
+
// Handle different possible response structures
|
|
109
|
+
const brandsData = Array.isArray(employeeBrands.data)
|
|
110
|
+
? employeeBrands.data
|
|
111
|
+
: (employeeBrands.data.data || employeeBrands.data.list || []);
|
|
112
|
+
if (Array.isArray(brandsData) && brandsData.length > 0) {
|
|
113
|
+
const brands = brandsData
|
|
114
|
+
.map((brand) => {
|
|
115
|
+
if (typeof brand === 'string') {
|
|
116
|
+
return brand;
|
|
95
117
|
}
|
|
96
|
-
return
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
118
|
+
return (brand === null || brand === void 0 ? void 0 : brand.slug) || '';
|
|
119
|
+
})
|
|
120
|
+
.filter((b) => !!b);
|
|
121
|
+
if (reqBody && reqBody.brand) {
|
|
122
|
+
return brands.indexOf(reqBody.brand) > -1 ? brands : null;
|
|
123
|
+
}
|
|
124
|
+
// tslint:disable-next-line no-console
|
|
125
|
+
console.log('[BrandManager] Successfully loaded brands from employee auth service:', brands);
|
|
126
|
+
return brands;
|
|
103
127
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
128
|
+
else {
|
|
129
|
+
// tslint:disable-next-line no-console
|
|
130
|
+
console.log('[BrandManager] Invalid response structure from employee auth service, expected array but got:', typeof brandsData);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
// tslint:disable-next-line no-console
|
|
135
|
+
console.log('[BrandManager] Failed to load brands from employee auth service, status:', employeeBrands === null || employeeBrands === void 0 ? void 0 : employeeBrands.status, 'data:', employeeBrands === null || employeeBrands === void 0 ? void 0 : employeeBrands.data);
|
|
136
|
+
}
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
catch (err) {
|
|
140
|
+
// tslint:disable-next-line no-console
|
|
141
|
+
console.log('[BrandManager] Error loading brands:', err);
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
107
145
|
/**
|
|
108
146
|
* get all brands list
|
|
109
147
|
* @param req
|
|
110
148
|
*/
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
return
|
|
149
|
+
async getBrands() {
|
|
150
|
+
var _a;
|
|
151
|
+
try {
|
|
152
|
+
const option = {
|
|
153
|
+
url: AlmatarBranding_1.default.dictionaryService + 'brands',
|
|
154
|
+
method: 'GET',
|
|
155
|
+
};
|
|
156
|
+
const brandsResponse = await PromiseRequest_1.PromiseRequest.request(option);
|
|
157
|
+
// Check if response is valid and has the expected structure
|
|
158
|
+
if (brandsResponse && brandsResponse.status === 200 && brandsResponse.data) {
|
|
159
|
+
// Handle different possible response structures
|
|
160
|
+
const brandsList = brandsResponse.data.list || ((_a = brandsResponse.data.data) === null || _a === void 0 ? void 0 : _a.list) || brandsResponse.data;
|
|
161
|
+
if (Array.isArray(brandsList) && brandsList.length > 0) {
|
|
162
|
+
Storage_1.default.setBrandsList(brandsList);
|
|
163
|
+
const brands = brandsList
|
|
164
|
+
.map((brand) => {
|
|
165
|
+
if (typeof brand === 'string') {
|
|
166
|
+
return brand;
|
|
129
167
|
}
|
|
130
|
-
return
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
168
|
+
return (brand === null || brand === void 0 ? void 0 : brand.key) || '';
|
|
169
|
+
})
|
|
170
|
+
.filter((b) => !!b);
|
|
171
|
+
Storage_1.default.setBrands(brands);
|
|
172
|
+
// tslint:disable-next-line:no-console
|
|
173
|
+
console.log('[BrandManager] Successfully loaded brands from dictionary service:', brands);
|
|
174
|
+
return brands;
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
// tslint:disable-next-line:no-console
|
|
178
|
+
console.log('[BrandManager] Invalid response structure from dictionary service, expected array but got:', typeof brandsList);
|
|
137
179
|
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
// tslint:disable-next-line:no-console
|
|
183
|
+
console.log('[BrandManager] Failed to get brands from dictionary service, status:', brandsResponse === null || brandsResponse === void 0 ? void 0 : brandsResponse.status, 'data:', brandsResponse === null || brandsResponse === void 0 ? void 0 : brandsResponse.data);
|
|
184
|
+
}
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
catch (err) {
|
|
188
|
+
// tslint:disable-next-line:no-console
|
|
189
|
+
console.log('[BrandManager] Error getting brands from dictionary service:', err);
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
141
193
|
/**
|
|
142
194
|
* get default brand
|
|
143
195
|
*/
|
|
144
|
-
|
|
196
|
+
getDefaultBrand() {
|
|
145
197
|
return this.defaultBrand;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
}());
|
|
198
|
+
}
|
|
199
|
+
}
|
|
149
200
|
exports.BrandManager = BrandManager;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BrandModel = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
class BrandModel {
|
|
5
|
+
constructor(init) {
|
|
6
6
|
Object.assign(this, init);
|
|
7
7
|
}
|
|
8
|
-
|
|
9
|
-
}());
|
|
8
|
+
}
|
|
10
9
|
exports.BrandModel = BrandModel;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.EmployeeBrandModel = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
class EmployeeBrandModel {
|
|
5
|
+
constructor(init) {
|
|
6
6
|
Object.assign(this, init);
|
|
7
7
|
}
|
|
8
|
-
|
|
9
|
-
}());
|
|
8
|
+
}
|
|
10
9
|
exports.EmployeeBrandModel = EmployeeBrandModel;
|