@almatar/branding 0.1.3 → 0.1.5

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 CHANGED
@@ -1,13 +1,13 @@
1
- import ContextNamespace from './lib/Storage';
2
- import MultiTenant from './lib/TenantModel/Mongoose/MultiTenant';
3
- import TenantMongooseModule from './lib/TenantModel/NestMongoose/TenantMongooseModule';
4
- import TenantRequest from './lib/request/TenantRequest';
5
- import AlmatarBranding from "./lib/AlmatarBranding";
6
- declare const _default: {
7
- ContextNamespace: typeof ContextNamespace;
8
- MultiTenant: typeof MultiTenant;
9
- TenantMongooseModule: typeof TenantMongooseModule;
10
- TenantRequest: typeof TenantRequest;
11
- AlmatarBranding: typeof AlmatarBranding;
12
- };
13
- export = _default;
1
+ import ContextNamespace from './lib/Storage';
2
+ import MultiTenant from './lib/TenantModel/Mongoose/MultiTenant';
3
+ import TenantMongooseModule from './lib/TenantModel/NestMongoose/TenantMongooseModule';
4
+ import TenantRequest from './lib/request/TenantRequest';
5
+ import AlmatarBranding from "./lib/AlmatarBranding";
6
+ declare const _default: {
7
+ ContextNamespace: typeof ContextNamespace;
8
+ MultiTenant: typeof MultiTenant;
9
+ TenantMongooseModule: typeof TenantMongooseModule;
10
+ TenantRequest: typeof TenantRequest;
11
+ AlmatarBranding: typeof AlmatarBranding;
12
+ };
13
+ export = _default;
package/lib/index.js CHANGED
@@ -1,13 +1,13 @@
1
- "use strict";
2
- var Storage_1 = require("./lib/Storage");
3
- var MultiTenant_1 = require("./lib/TenantModel/Mongoose/MultiTenant");
4
- var TenantMongooseModule_1 = require("./lib/TenantModel/NestMongoose/TenantMongooseModule");
5
- var TenantRequest_1 = require("./lib/request/TenantRequest");
6
- var AlmatarBranding_1 = require("./lib/AlmatarBranding");
7
- module.exports = {
8
- ContextNamespace: Storage_1.default,
9
- MultiTenant: MultiTenant_1.default,
10
- TenantMongooseModule: TenantMongooseModule_1.default,
11
- TenantRequest: TenantRequest_1.default,
12
- AlmatarBranding: AlmatarBranding_1.default
13
- };
1
+ "use strict";
2
+ var Storage_1 = require("./lib/Storage");
3
+ var MultiTenant_1 = require("./lib/TenantModel/Mongoose/MultiTenant");
4
+ var TenantMongooseModule_1 = require("./lib/TenantModel/NestMongoose/TenantMongooseModule");
5
+ var TenantRequest_1 = require("./lib/request/TenantRequest");
6
+ var AlmatarBranding_1 = require("./lib/AlmatarBranding");
7
+ module.exports = {
8
+ ContextNamespace: Storage_1.default,
9
+ MultiTenant: MultiTenant_1.default,
10
+ TenantMongooseModule: TenantMongooseModule_1.default,
11
+ TenantRequest: TenantRequest_1.default,
12
+ AlmatarBranding: AlmatarBranding_1.default
13
+ };
@@ -1,4 +1,5 @@
1
- export default class AlmatarBranding {
2
- static employeeAuthService: string;
3
- static setup(configs: any): void;
4
- }
1
+ export default class AlmatarBranding {
2
+ static employeeAuthService: string;
3
+ static dictionaryService: string;
4
+ static setup(configs: any): void;
5
+ }
@@ -1,12 +1,14 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var AlmatarBranding = /** @class */ (function () {
4
- function AlmatarBranding() {
5
- }
6
- AlmatarBranding.setup = function (configs) {
7
- this.employeeAuthService = configs.employeeAuthService;
8
- };
9
- AlmatarBranding.employeeAuthService = '';
10
- return AlmatarBranding;
11
- }());
12
- exports.default = AlmatarBranding;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var AlmatarBranding = /** @class */ (function () {
4
+ function AlmatarBranding() {
5
+ }
6
+ AlmatarBranding.setup = function (configs) {
7
+ this.employeeAuthService = configs.employeeAuthService;
8
+ this.dictionaryService = configs.dictionaryService;
9
+ };
10
+ AlmatarBranding.employeeAuthService = '';
11
+ AlmatarBranding.dictionaryService = '';
12
+ return AlmatarBranding;
13
+ }());
14
+ exports.default = AlmatarBranding;
@@ -1,6 +1,8 @@
1
- export declare class BrandIdentifier {
2
- private readonly type;
3
- constructor(type: string);
4
- getBrand(req: any): Promise<string | string[] | null | Error>;
5
- private error;
6
- }
1
+ export declare class BrandIdentifier {
2
+ private readonly type;
3
+ constructor(type: string);
4
+ getBrand(req: any): Promise<string | string[] | null | Error>;
5
+ getBrands(): Promise<string[] | null | Error>;
6
+ getDefaultBrand(): string;
7
+ private error;
8
+ }
@@ -1,86 +1,108 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
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 (_) 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
- }
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.BrandIdentifier = void 0;
40
- var Boom = require("@hapi/boom");
41
- var BrandManager_1 = require("./BrandManager");
42
- var BrandIdentifier = /** @class */ (function () {
43
- function BrandIdentifier(type) {
44
- this.type = type;
45
- }
46
- BrandIdentifier.prototype.getBrand = function (req) {
47
- return __awaiter(this, void 0, void 0, function () {
48
- var brandManager, brand;
49
- return __generator(this, function (_a) {
50
- switch (_a.label) {
51
- case 0:
52
- brandManager = new BrandManager_1.BrandManager(this.type);
53
- if (!req.headers['x-brand']) return [3 /*break*/, 1];
54
- return [2 /*return*/, brandManager.getB2CBrand(req)];
55
- case 1:
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*/, 'almatar'];
65
- }
66
- return [2 /*return*/, this.error('Unauthorized!')];
67
- case 3: return [2 /*return*/, 'almatar'];
68
- }
69
- });
70
- });
71
- };
72
- BrandIdentifier.prototype.error = function (message) {
73
- switch (this.type) {
74
- case 'hapi':
75
- return Boom.unauthorized(message);
76
- break;
77
- case 'express':
78
- return new Error(message);
79
- break;
80
- default:
81
- return new Error(message);
82
- }
83
- };
84
- return BrandIdentifier;
85
- }());
86
- exports.BrandIdentifier = BrandIdentifier;
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
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 (_) 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
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.BrandIdentifier = void 0;
40
+ var Boom = require("@hapi/boom");
41
+ var BrandManager_1 = require("./BrandManager");
42
+ var BrandIdentifier = /** @class */ (function () {
43
+ function BrandIdentifier(type) {
44
+ this.type = type;
45
+ }
46
+ BrandIdentifier.prototype.getBrand = function (req) {
47
+ return __awaiter(this, void 0, void 0, function () {
48
+ var brandManager, brand;
49
+ return __generator(this, function (_a) {
50
+ switch (_a.label) {
51
+ case 0:
52
+ brandManager = new BrandManager_1.BrandManager(this.type);
53
+ if (!req.headers['x-brand']) return [3 /*break*/, 1];
54
+ return [2 /*return*/, brandManager.getB2CBrand(req)];
55
+ case 1:
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()];
68
+ }
69
+ });
70
+ });
71
+ };
72
+ BrandIdentifier.prototype.getBrands = function () {
73
+ return __awaiter(this, void 0, void 0, function () {
74
+ var brandManager, brands;
75
+ return __generator(this, function (_a) {
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];
86
+ }
87
+ });
88
+ });
89
+ };
90
+ BrandIdentifier.prototype.getDefaultBrand = function () {
91
+ var brandManager = new BrandManager_1.BrandManager(this.type);
92
+ return brandManager.getDefaultBrand();
93
+ };
94
+ BrandIdentifier.prototype.error = function (message) {
95
+ switch (this.type) {
96
+ case 'hapi':
97
+ return Boom.unauthorized(message);
98
+ break;
99
+ case 'express':
100
+ return new Error(message);
101
+ break;
102
+ default:
103
+ return new Error(message);
104
+ }
105
+ };
106
+ return BrandIdentifier;
107
+ }());
108
+ exports.BrandIdentifier = BrandIdentifier;
@@ -1,7 +1,17 @@
1
- export declare class BrandManager {
2
- private readonly type;
3
- constructor(type: string);
4
- getB2CBrand(req: any): string;
5
- getConsoleBrands(req: any): Promise<string[] | null>;
6
- loadBrands(req: any): Promise<string[] | null>;
7
- }
1
+ export declare class BrandManager {
2
+ private readonly type;
3
+ private readonly defaultBrand;
4
+ constructor(type: string);
5
+ getB2CBrand(req: any): string;
6
+ getConsoleBrands(req: any): Promise<string[] | null>;
7
+ loadBrands(req: any): Promise<string[] | null>;
8
+ /**
9
+ * get all brands list
10
+ * @param req
11
+ */
12
+ getBrands(): Promise<string[] | null>;
13
+ /**
14
+ * get default brand
15
+ */
16
+ getDefaultBrand(): string;
17
+ }
@@ -1,108 +1,148 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
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 (_) 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
- }
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.BrandManager = void 0;
40
- var AlmatarBranding_1 = require("./AlmatarBranding");
41
- var Storage_1 = require("./Storage");
42
- var PromiseRequest_1 = require("./request/PromiseRequest");
43
- var BrandManager = /** @class */ (function () {
44
- function BrandManager(type) {
45
- this.type = type;
46
- }
47
- BrandManager.prototype.getB2CBrand = function (req) {
48
- return req.headers['x-brand'];
49
- };
50
- BrandManager.prototype.getConsoleBrands = function (req) {
51
- return __awaiter(this, void 0, void 0, function () {
52
- var reqBody, brands;
53
- return __generator(this, function (_a) {
54
- switch (_a.label) {
55
- case 0:
56
- if (req.headers['x-employee-brands']) {
57
- return [2 /*return*/, req.headers['x-employee-brands'].split(',')];
58
- }
59
- reqBody = (req.payload) ? req.payload : req.body;
60
- return [4 /*yield*/, this.loadBrands(req)];
61
- case 1:
62
- brands = _a.sent();
63
- if (reqBody && reqBody.brand) {
64
- Storage_1.default.setBrand(reqBody.brand);
65
- }
66
- return [2 /*return*/, brands];
67
- }
68
- });
69
- });
70
- };
71
- BrandManager.prototype.loadBrands = function (req) {
72
- return __awaiter(this, void 0, void 0, function () {
73
- var reqBody, options, employeeBrands, brands, err_1;
74
- return __generator(this, function (_a) {
75
- switch (_a.label) {
76
- case 0:
77
- _a.trys.push([0, 2, , 3]);
78
- reqBody = (req.payload) ? req.payload : req.body;
79
- options = {
80
- url: AlmatarBranding_1.default.employeeAuthService + '/v1/user/brands',
81
- headers: {
82
- authorization: req.headers.authorization
83
- }
84
- };
85
- return [4 /*yield*/, PromiseRequest_1.PromiseRequest.request(options)];
86
- case 1:
87
- employeeBrands = _a.sent();
88
- if (employeeBrands.status === 200) {
89
- brands = employeeBrands.data.map(function (brand) { return brand.slug; });
90
- if (reqBody && reqBody.brand) {
91
- return [2 /*return*/, (brands.indexOf(reqBody.brand) > -1) ? brands : null];
92
- }
93
- return [2 /*return*/, brands];
94
- }
95
- return [2 /*return*/, null];
96
- case 2:
97
- err_1 = _a.sent();
98
- // tslint:disable-next-line no-console
99
- console.log(err_1);
100
- return [2 /*return*/, null];
101
- case 3: return [2 /*return*/];
102
- }
103
- });
104
- });
105
- };
106
- return BrandManager;
107
- }());
108
- exports.BrandManager = BrandManager;
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
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 (_) 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
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.BrandManager = void 0;
40
+ var AlmatarBranding_1 = require("./AlmatarBranding");
41
+ var Storage_1 = require("./Storage");
42
+ var PromiseRequest_1 = require("./request/PromiseRequest");
43
+ var BrandManager = /** @class */ (function () {
44
+ function BrandManager(type) {
45
+ this.defaultBrand = 'almatar';
46
+ this.type = type;
47
+ }
48
+ BrandManager.prototype.getB2CBrand = function (req) {
49
+ return req.headers['x-brand'];
50
+ };
51
+ BrandManager.prototype.getConsoleBrands = function (req) {
52
+ return __awaiter(this, void 0, void 0, function () {
53
+ var reqBody, brands;
54
+ return __generator(this, function (_a) {
55
+ switch (_a.label) {
56
+ case 0:
57
+ if (req.headers['x-employee-brands']) {
58
+ return [2 /*return*/, req.headers['x-employee-brands'].split(',')];
59
+ }
60
+ reqBody = (req.payload) ? req.payload : req.body;
61
+ return [4 /*yield*/, this.loadBrands(req)];
62
+ case 1:
63
+ brands = _a.sent();
64
+ if (reqBody && reqBody.brand) {
65
+ Storage_1.default.setBrand(reqBody.brand);
66
+ }
67
+ return [2 /*return*/, brands];
68
+ }
69
+ });
70
+ });
71
+ };
72
+ BrandManager.prototype.loadBrands = function (req) {
73
+ return __awaiter(this, void 0, void 0, function () {
74
+ var reqBody, options, employeeBrands, brands, err_1;
75
+ return __generator(this, function (_a) {
76
+ switch (_a.label) {
77
+ case 0:
78
+ _a.trys.push([0, 2, , 3]);
79
+ reqBody = (req.payload) ? req.payload : req.body;
80
+ options = {
81
+ url: AlmatarBranding_1.default.employeeAuthService + '/v1/user/brands',
82
+ headers: {
83
+ authorization: req.headers.authorization
84
+ }
85
+ };
86
+ return [4 /*yield*/, PromiseRequest_1.PromiseRequest.request(options)];
87
+ case 1:
88
+ employeeBrands = _a.sent();
89
+ if (employeeBrands.status === 200) {
90
+ brands = employeeBrands.data.map(function (brand) { return brand.slug; });
91
+ if (reqBody && reqBody.brand) {
92
+ return [2 /*return*/, (brands.indexOf(reqBody.brand) > -1) ? brands : null];
93
+ }
94
+ return [2 /*return*/, brands];
95
+ }
96
+ return [2 /*return*/, null];
97
+ case 2:
98
+ err_1 = _a.sent();
99
+ // tslint:disable-next-line no-console
100
+ console.log(err_1);
101
+ return [2 /*return*/, null];
102
+ case 3: return [2 /*return*/];
103
+ }
104
+ });
105
+ });
106
+ };
107
+ /**
108
+ * get all brands list
109
+ * @param req
110
+ */
111
+ BrandManager.prototype.getBrands = function () {
112
+ return __awaiter(this, void 0, void 0, function () {
113
+ var option, brandsResponse, brands, err_2;
114
+ return __generator(this, function (_a) {
115
+ switch (_a.label) {
116
+ case 0:
117
+ _a.trys.push([0, 2, , 3]);
118
+ option = {
119
+ url: AlmatarBranding_1.default.dictionaryService + 'dictionary/brands',
120
+ };
121
+ return [4 /*yield*/, PromiseRequest_1.PromiseRequest.request(option)];
122
+ case 1:
123
+ brandsResponse = _a.sent();
124
+ if (brandsResponse.status === 200) {
125
+ brands = brandsResponse.data.map.list.map(function (brand) { return brand.key; });
126
+ Storage_1.default.setBrands(brands);
127
+ return [2 /*return*/, brands];
128
+ }
129
+ return [2 /*return*/, null];
130
+ case 2:
131
+ err_2 = _a.sent();
132
+ // tslint:disable-next-line:no-console
133
+ console.log(err_2);
134
+ return [2 /*return*/, null];
135
+ case 3: return [2 /*return*/];
136
+ }
137
+ });
138
+ });
139
+ };
140
+ /**
141
+ * get default brand
142
+ */
143
+ BrandManager.prototype.getDefaultBrand = function () {
144
+ return this.defaultBrand;
145
+ };
146
+ return BrandManager;
147
+ }());
148
+ exports.BrandManager = BrandManager;
@@ -1,6 +1,6 @@
1
- export declare class EmployeeBrandModel {
2
- id: number;
3
- slug: string;
4
- name: string;
5
- constructor(init?: Partial<EmployeeBrandModel>);
6
- }
1
+ export declare class EmployeeBrandModel {
2
+ id: number;
3
+ slug: string;
4
+ name: string;
5
+ constructor(init?: Partial<EmployeeBrandModel>);
6
+ }
@@ -1,10 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EmployeeBrandModel = void 0;
4
- var EmployeeBrandModel = /** @class */ (function () {
5
- function EmployeeBrandModel(init) {
6
- Object.assign(this, init);
7
- }
8
- return EmployeeBrandModel;
9
- }());
10
- exports.EmployeeBrandModel = EmployeeBrandModel;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EmployeeBrandModel = void 0;
4
+ var EmployeeBrandModel = /** @class */ (function () {
5
+ function EmployeeBrandModel(init) {
6
+ Object.assign(this, init);
7
+ }
8
+ return EmployeeBrandModel;
9
+ }());
10
+ exports.EmployeeBrandModel = EmployeeBrandModel;