@almatar/branding 0.1.0 → 0.1.2
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/Storage.test.d.ts +0 -0
- package/lib/Storage.test.js +4 -0
- package/lib/index.d.ts +2 -2
- package/lib/index.js +1 -1
- package/lib/lib/TenantModel/NestMongoose/TenantMongooseModule.js +1 -0
- package/lib/lib/TenantModel/NestMongoose/mongoose.providers.js +2 -3
- package/package.json +1 -1
- package/readme.md +20 -20
|
File without changes
|
package/lib/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import ContextNamespace from './lib/Storage';
|
|
2
2
|
import MultiTenant from './lib/TenantModel/Mongoose/MultiTenant';
|
|
3
|
-
import
|
|
3
|
+
import TenantMongooseModule from './lib/TenantModel/NestMongoose/TenantMongooseModule';
|
|
4
4
|
import TenantRequest from './lib/request/TenantRequest';
|
|
5
5
|
import AlmatarBranding from "./lib/AlmatarBranding";
|
|
6
6
|
declare const _default: {
|
|
7
7
|
ContextNamespace: typeof ContextNamespace;
|
|
8
8
|
MultiTenant: typeof MultiTenant;
|
|
9
|
-
|
|
9
|
+
TenantMongooseModule: typeof TenantMongooseModule;
|
|
10
10
|
TenantRequest: typeof TenantRequest;
|
|
11
11
|
AlmatarBranding: typeof AlmatarBranding;
|
|
12
12
|
};
|
package/lib/index.js
CHANGED
|
@@ -7,7 +7,7 @@ var AlmatarBranding_1 = require("./lib/AlmatarBranding");
|
|
|
7
7
|
module.exports = {
|
|
8
8
|
ContextNamespace: Storage_1.default,
|
|
9
9
|
MultiTenant: MultiTenant_1.default,
|
|
10
|
-
|
|
10
|
+
TenantMongooseModule: TenantMongooseModule_1.default,
|
|
11
11
|
TenantRequest: TenantRequest_1.default,
|
|
12
12
|
AlmatarBranding: AlmatarBranding_1.default
|
|
13
13
|
};
|
|
@@ -29,6 +29,7 @@ var TenantMongooseModule = /** @class */ (function (_super) {
|
|
|
29
29
|
}
|
|
30
30
|
TenantMongooseModule.forFeature = function (models, connectionName) {
|
|
31
31
|
if (models === void 0) { models = []; }
|
|
32
|
+
connectionName = (connectionName) ? connectionName + "Connection" : 'MongooseConnectionName';
|
|
32
33
|
var modelProviders = mongoose_providers_1.createMongooseProviders(connectionName, models);
|
|
33
34
|
return {
|
|
34
35
|
module: mongoose_1.MongooseModule,
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var mongoose_utils_1 = require("../../../../node_modules/@nestjs/mongoose/dist/common/mongoose.utils");
|
|
4
3
|
var MongooseModel_1 = require("../MongooseModel");
|
|
5
4
|
function createMongooseProviders(connectionName, models) {
|
|
6
5
|
if (models === void 0) { models = []; }
|
|
7
6
|
var providers = (models || []).map(function (model) { return ({
|
|
8
|
-
provide:
|
|
7
|
+
provide: model.name + "Model",
|
|
9
8
|
useFactory: function (connection) {
|
|
10
9
|
var mongooseModel = new MongooseModel_1.MongooseModel(connection);
|
|
11
10
|
return mongooseModel.createModel(model.name, model.schema, model.collection, {});
|
|
12
11
|
},
|
|
13
|
-
inject: [
|
|
12
|
+
inject: [connectionName + "Connection"],
|
|
14
13
|
}); });
|
|
15
14
|
return providers;
|
|
16
15
|
}
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -4,13 +4,24 @@ this package make microservice able to handle different brands
|
|
|
4
4
|
|
|
5
5
|
## How It Works
|
|
6
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
|
+
|
|
7
18
|
## Nest.js
|
|
8
19
|
|
|
9
20
|
### save brand on any request
|
|
10
21
|
|
|
11
22
|
save brand on any request using the package middleware in main.ts file
|
|
12
23
|
```
|
|
13
|
-
import { ContextNamespace } from 'almatar
|
|
24
|
+
import { ContextNamespace } from '@almatar/branding';
|
|
14
25
|
|
|
15
26
|
app.use(ContextNamespace.bindENamespace);
|
|
16
27
|
app.use(ContextNamespace.setEBrand);
|
|
@@ -18,14 +29,14 @@ app.use(ContextNamespace.setEBrand);
|
|
|
18
29
|
|
|
19
30
|
### build mongoose model
|
|
20
31
|
|
|
21
|
-
`import {
|
|
32
|
+
`import { TenantMongooseModule } from '@almatar/branding';` instead of `import {MongooseModule} from '@nestjs/mongoose';`
|
|
22
33
|
|
|
23
34
|
```
|
|
24
|
-
import {
|
|
35
|
+
import { TenantMongooseModule } from '@almatar/branding';
|
|
25
36
|
|
|
26
37
|
@Module({
|
|
27
38
|
imports: [
|
|
28
|
-
|
|
39
|
+
TenantMongooseModule.forFeature([{name: 'Test', schema: TestSchema}]),
|
|
29
40
|
],
|
|
30
41
|
controllers: [TestController],
|
|
31
42
|
providers: [
|
|
@@ -48,7 +59,7 @@ example: `await this.Test.find({ id: '123' }).exec()`
|
|
|
48
59
|
save brand on each request by using the package middleware in pre functions on each route
|
|
49
60
|
|
|
50
61
|
```
|
|
51
|
-
import { ContextNamespace } from 'almatar
|
|
62
|
+
import { ContextNamespace } from '@almatar/branding';
|
|
52
63
|
|
|
53
64
|
// configs
|
|
54
65
|
|
|
@@ -69,7 +80,7 @@ handler: (request, reply) => {
|
|
|
69
80
|
### build mongoose model
|
|
70
81
|
|
|
71
82
|
```
|
|
72
|
-
import { MultiTenant } from 'almatar
|
|
83
|
+
import { MultiTenant } from '@almatar/branding';
|
|
73
84
|
const mongoose = require('mongoose');
|
|
74
85
|
|
|
75
86
|
const TestSchema = new mongoose.Schema(
|
|
@@ -105,7 +116,7 @@ Test({ skipBrand: true }).count({}, callback);
|
|
|
105
116
|
### to keep the context in multiple callbacks
|
|
106
117
|
|
|
107
118
|
```
|
|
108
|
-
import { ContextNamespace } from 'almatar
|
|
119
|
+
import { ContextNamespace } from '@almatar/branding';
|
|
109
120
|
|
|
110
121
|
const ns = ContextNamespace.getNamespace();
|
|
111
122
|
async.waterfall(
|
|
@@ -124,23 +135,12 @@ async.waterfall(
|
|
|
124
135
|
### Send request With brand header
|
|
125
136
|
|
|
126
137
|
```
|
|
127
|
-
import {
|
|
138
|
+
import { TenantRequest } from '@almatar/branding';
|
|
128
139
|
|
|
129
140
|
const reqOptions = {
|
|
130
141
|
url: `${BASEURL}/test`
|
|
131
142
|
};
|
|
132
|
-
|
|
143
|
+
TenantRequest.request(reqOptions, (error, response, body) => {
|
|
133
144
|
console.log(body);
|
|
134
145
|
});
|
|
135
146
|
```
|
|
136
|
-
|
|
137
|
-
### Setup Branding Package
|
|
138
|
-
|
|
139
|
-
```
|
|
140
|
-
import { AlmatarBranding } from 'almatar-branding';
|
|
141
|
-
|
|
142
|
-
AlmatarBranding.setup({
|
|
143
|
-
employeeAuthService: config.EMPLOYEE_AUTH_SERVICE
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
```
|