@almatar/branding 0.1.4 → 0.1.6
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 +13 -13
- package/lib/index.js +13 -13
- package/lib/lib/AlmatarBranding.d.ts +5 -4
- package/lib/lib/AlmatarBranding.js +14 -12
- package/lib/lib/BrandIdentifier.d.ts +8 -6
- package/lib/lib/BrandIdentifier.js +108 -86
- package/lib/lib/BrandManager.d.ts +17 -7
- package/lib/lib/BrandManager.js +148 -108
- package/lib/lib/Models/BrandModel.d.ts +8 -0
- package/lib/lib/Models/BrandModel.js +10 -0
- package/lib/lib/Models/EmployeeBrandModel.d.ts +6 -6
- package/lib/lib/Models/EmployeeBrandModel.js +10 -10
- package/lib/lib/Storage.d.ts +14 -10
- package/lib/lib/Storage.js +173 -135
- package/lib/lib/TenantModel/Mongoose/MultiTenant.d.ts +8 -8
- package/lib/lib/TenantModel/Mongoose/MultiTenant.js +24 -24
- package/lib/lib/TenantModel/MongooseModel.d.ts +13 -13
- package/lib/lib/TenantModel/MongooseModel.js +90 -84
- package/lib/lib/TenantModel/NestMongoose/TenantMongooseModule.d.ts +9 -9
- package/lib/lib/TenantModel/NestMongoose/TenantMongooseModule.js +45 -45
- package/lib/lib/TenantModel/NestMongoose/mongoose.providers.d.ts +10 -10
- package/lib/lib/TenantModel/NestMongoose/mongoose.providers.js +17 -17
- package/lib/lib/request/PromiseRequest.d.ts +3 -3
- package/lib/lib/request/PromiseRequest.js +61 -62
- package/lib/lib/request/TenantRequest.d.ts +4 -4
- package/lib/lib/request/TenantRequest.js +73 -73
- package/package.json +56 -56
- package/readme.md +146 -146
package/readme.md
CHANGED
|
@@ -1,146 +1,146 @@
|
|
|
1
|
-
# Almatar Branding
|
|
2
|
-
|
|
3
|
-
this package make microservice able to handle different brands
|
|
4
|
-
|
|
5
|
-
## How It Works
|
|
6
|
-
|
|
7
|
-
## Setup Branding Package
|
|
8
|
-
|
|
9
|
-
```
|
|
10
|
-
import { AlmatarBranding } from '@almatar/branding';
|
|
11
|
-
|
|
12
|
-
AlmatarBranding.setup({
|
|
13
|
-
employeeAuthService: config.EMPLOYEE_AUTH_SERVICE
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
## Nest.js
|
|
19
|
-
|
|
20
|
-
### save brand on any request
|
|
21
|
-
|
|
22
|
-
save brand on any request using the package middleware in main.ts file
|
|
23
|
-
```
|
|
24
|
-
import { ContextNamespace } from '@almatar/branding';
|
|
25
|
-
|
|
26
|
-
app.use(ContextNamespace.bindENamespace);
|
|
27
|
-
app.use(ContextNamespace.setEBrand);
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
### build mongoose model
|
|
31
|
-
|
|
32
|
-
`import { TenantMongooseModule } from '@almatar/branding';` instead of `import {MongooseModule} from '@nestjs/mongoose';`
|
|
33
|
-
|
|
34
|
-
```
|
|
35
|
-
import { TenantMongooseModule } from '@almatar/branding';
|
|
36
|
-
|
|
37
|
-
@Module({
|
|
38
|
-
imports: [
|
|
39
|
-
TenantMongooseModule.forFeature([{name: 'Test', schema: TestSchema}]),
|
|
40
|
-
],
|
|
41
|
-
controllers: [TestController],
|
|
42
|
-
providers: [
|
|
43
|
-
TestService,
|
|
44
|
-
],
|
|
45
|
-
})
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
and add `.exec()` at the end of any query make search on database
|
|
49
|
-
|
|
50
|
-
`count, find, findOne, aggregate, update, findOneAndUpdate, updateOne, updateMany, findOneAndDelete, findOneAndRemove, deleteMany, deleteOne, remove`
|
|
51
|
-
|
|
52
|
-
example: `await this.Test.find({ id: '123' }).exec()`
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
## Hapi.js
|
|
56
|
-
|
|
57
|
-
### save brand on each request
|
|
58
|
-
|
|
59
|
-
save brand on each request by using the package middleware in pre functions on each route
|
|
60
|
-
|
|
61
|
-
```
|
|
62
|
-
import { ContextNamespace } from '@almatar/branding';
|
|
63
|
-
|
|
64
|
-
// configs
|
|
65
|
-
|
|
66
|
-
auth: false,
|
|
67
|
-
// "tags" enable swagger to document API
|
|
68
|
-
tags: ['api'],
|
|
69
|
-
description: 'Get all coupon data',
|
|
70
|
-
notes: 'Returns a list of all coupons',
|
|
71
|
-
pre: [
|
|
72
|
-
{ method: ContextNamespace.bindHNamespace },
|
|
73
|
-
{ method: ContextNamespace.setHBrand }
|
|
74
|
-
],
|
|
75
|
-
handler: (request, reply) => {
|
|
76
|
-
// some code
|
|
77
|
-
}
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
### build mongoose model
|
|
81
|
-
|
|
82
|
-
```
|
|
83
|
-
import { MultiTenant } from '@almatar/branding';
|
|
84
|
-
const mongoose = require('mongoose');
|
|
85
|
-
|
|
86
|
-
const TestSchema = new mongoose.Schema(
|
|
87
|
-
{
|
|
88
|
-
id: { type: Number, required: true }
|
|
89
|
-
}
|
|
90
|
-
)
|
|
91
|
-
|
|
92
|
-
const multiTenant = new MultiTenant(mongoose);
|
|
93
|
-
|
|
94
|
-
module.exports = multiTenant.tenantModel('Test', TestSchema);
|
|
95
|
-
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
### use mongoose model
|
|
99
|
-
|
|
100
|
-
```
|
|
101
|
-
const Test = require('../models/coupon.model');
|
|
102
|
-
|
|
103
|
-
Test().count({}, callback);
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
### skip brand for specific query
|
|
107
|
-
|
|
108
|
-
add { skipBrand: true } if you need to get the data regardless of the brand
|
|
109
|
-
|
|
110
|
-
```
|
|
111
|
-
const Test = require('../models/coupon.model');
|
|
112
|
-
|
|
113
|
-
Test({ skipBrand: true }).count({}, callback);
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
### to keep the context in multiple callbacks
|
|
117
|
-
|
|
118
|
-
```
|
|
119
|
-
import { ContextNamespace } from '@almatar/branding';
|
|
120
|
-
|
|
121
|
-
const ns = ContextNamespace.getNamespace();
|
|
122
|
-
async.waterfall(
|
|
123
|
-
[
|
|
124
|
-
ns.bind(function(cb) {
|
|
125
|
-
cb(err, data)
|
|
126
|
-
}),
|
|
127
|
-
ns.bind(function(couponsCount, cb1) {
|
|
128
|
-
cb1(err, data)
|
|
129
|
-
})
|
|
130
|
-
],
|
|
131
|
-
callback
|
|
132
|
-
);
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
### Send request With brand header
|
|
136
|
-
|
|
137
|
-
```
|
|
138
|
-
import { TenantRequest } from '@almatar/branding';
|
|
139
|
-
|
|
140
|
-
const reqOptions = {
|
|
141
|
-
url: `${BASEURL}/test`
|
|
142
|
-
};
|
|
143
|
-
TenantRequest.request(reqOptions, (error, response, body) => {
|
|
144
|
-
console.log(body);
|
|
145
|
-
});
|
|
146
|
-
```
|
|
1
|
+
# Almatar Branding
|
|
2
|
+
|
|
3
|
+
this package make microservice able to handle different brands
|
|
4
|
+
|
|
5
|
+
## How It Works
|
|
6
|
+
|
|
7
|
+
## Setup Branding Package
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
import { AlmatarBranding } from '@almatar/branding';
|
|
11
|
+
|
|
12
|
+
AlmatarBranding.setup({
|
|
13
|
+
employeeAuthService: config.EMPLOYEE_AUTH_SERVICE
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Nest.js
|
|
19
|
+
|
|
20
|
+
### save brand on any request
|
|
21
|
+
|
|
22
|
+
save brand on any request using the package middleware in main.ts file
|
|
23
|
+
```
|
|
24
|
+
import { ContextNamespace } from '@almatar/branding';
|
|
25
|
+
|
|
26
|
+
app.use(ContextNamespace.bindENamespace);
|
|
27
|
+
app.use(ContextNamespace.setEBrand);
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### build mongoose model
|
|
31
|
+
|
|
32
|
+
`import { TenantMongooseModule } from '@almatar/branding';` instead of `import {MongooseModule} from '@nestjs/mongoose';`
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
import { TenantMongooseModule } from '@almatar/branding';
|
|
36
|
+
|
|
37
|
+
@Module({
|
|
38
|
+
imports: [
|
|
39
|
+
TenantMongooseModule.forFeature([{name: 'Test', schema: TestSchema}]),
|
|
40
|
+
],
|
|
41
|
+
controllers: [TestController],
|
|
42
|
+
providers: [
|
|
43
|
+
TestService,
|
|
44
|
+
],
|
|
45
|
+
})
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
and add `.exec()` at the end of any query make search on database
|
|
49
|
+
|
|
50
|
+
`count, find, findOne, aggregate, update, findOneAndUpdate, updateOne, updateMany, findOneAndDelete, findOneAndRemove, deleteMany, deleteOne, remove`
|
|
51
|
+
|
|
52
|
+
example: `await this.Test.find({ id: '123' }).exec()`
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
## Hapi.js
|
|
56
|
+
|
|
57
|
+
### save brand on each request
|
|
58
|
+
|
|
59
|
+
save brand on each request by using the package middleware in pre functions on each route
|
|
60
|
+
|
|
61
|
+
```
|
|
62
|
+
import { ContextNamespace } from '@almatar/branding';
|
|
63
|
+
|
|
64
|
+
// configs
|
|
65
|
+
|
|
66
|
+
auth: false,
|
|
67
|
+
// "tags" enable swagger to document API
|
|
68
|
+
tags: ['api'],
|
|
69
|
+
description: 'Get all coupon data',
|
|
70
|
+
notes: 'Returns a list of all coupons',
|
|
71
|
+
pre: [
|
|
72
|
+
{ method: ContextNamespace.bindHNamespace },
|
|
73
|
+
{ method: ContextNamespace.setHBrand }
|
|
74
|
+
],
|
|
75
|
+
handler: (request, reply) => {
|
|
76
|
+
// some code
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### build mongoose model
|
|
81
|
+
|
|
82
|
+
```
|
|
83
|
+
import { MultiTenant } from '@almatar/branding';
|
|
84
|
+
const mongoose = require('mongoose');
|
|
85
|
+
|
|
86
|
+
const TestSchema = new mongoose.Schema(
|
|
87
|
+
{
|
|
88
|
+
id: { type: Number, required: true }
|
|
89
|
+
}
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
const multiTenant = new MultiTenant(mongoose);
|
|
93
|
+
|
|
94
|
+
module.exports = multiTenant.tenantModel('Test', TestSchema);
|
|
95
|
+
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### use mongoose model
|
|
99
|
+
|
|
100
|
+
```
|
|
101
|
+
const Test = require('../models/coupon.model');
|
|
102
|
+
|
|
103
|
+
Test().count({}, callback);
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### skip brand for specific query
|
|
107
|
+
|
|
108
|
+
add { skipBrand: true } if you need to get the data regardless of the brand
|
|
109
|
+
|
|
110
|
+
```
|
|
111
|
+
const Test = require('../models/coupon.model');
|
|
112
|
+
|
|
113
|
+
Test({ skipBrand: true }).count({}, callback);
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### to keep the context in multiple callbacks
|
|
117
|
+
|
|
118
|
+
```
|
|
119
|
+
import { ContextNamespace } from '@almatar/branding';
|
|
120
|
+
|
|
121
|
+
const ns = ContextNamespace.getNamespace();
|
|
122
|
+
async.waterfall(
|
|
123
|
+
[
|
|
124
|
+
ns.bind(function(cb) {
|
|
125
|
+
cb(err, data)
|
|
126
|
+
}),
|
|
127
|
+
ns.bind(function(couponsCount, cb1) {
|
|
128
|
+
cb1(err, data)
|
|
129
|
+
})
|
|
130
|
+
],
|
|
131
|
+
callback
|
|
132
|
+
);
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Send request With brand header
|
|
136
|
+
|
|
137
|
+
```
|
|
138
|
+
import { TenantRequest } from '@almatar/branding';
|
|
139
|
+
|
|
140
|
+
const reqOptions = {
|
|
141
|
+
url: `${BASEURL}/test`
|
|
142
|
+
};
|
|
143
|
+
TenantRequest.request(reqOptions, (error, response, body) => {
|
|
144
|
+
console.log(body);
|
|
145
|
+
});
|
|
146
|
+
```
|