soajs.multitenant 2.1.17 → 2.1.19
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/.github/workflows/ci.yml +43 -0
- package/.github/workflows/release.yml +94 -0
- package/Gruntfile.js +1 -1
- package/_index.js +7 -1
- package/bl/tenant.js +19 -2
- package/config.js +14 -0
- package/model/mongo/tenant.js +49 -0
- package/package.json +5 -5
- package/.travis.yml +0 -72
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [ master, develop, feature/*, features/* ]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [ master, develop ]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
|
|
13
|
+
services:
|
|
14
|
+
mongodb:
|
|
15
|
+
image: mongo:8
|
|
16
|
+
ports:
|
|
17
|
+
- 27017:27017
|
|
18
|
+
|
|
19
|
+
steps:
|
|
20
|
+
- name: Checkout code
|
|
21
|
+
uses: actions/checkout@v4
|
|
22
|
+
|
|
23
|
+
- name: Setup Node.js
|
|
24
|
+
uses: actions/setup-node@v4
|
|
25
|
+
with:
|
|
26
|
+
node-version: '24'
|
|
27
|
+
|
|
28
|
+
- name: Install dependencies
|
|
29
|
+
run: npm install
|
|
30
|
+
|
|
31
|
+
- name: Install grunt-cli
|
|
32
|
+
run: npm install -g grunt-cli
|
|
33
|
+
|
|
34
|
+
- name: Run linting
|
|
35
|
+
run: grunt
|
|
36
|
+
|
|
37
|
+
- name: Run tests
|
|
38
|
+
if: github.ref != 'refs/heads/master'
|
|
39
|
+
run: grunt test
|
|
40
|
+
|
|
41
|
+
- name: Run coverage
|
|
42
|
+
if: github.ref == 'refs/heads/master'
|
|
43
|
+
run: grunt coverage
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- release
|
|
7
|
+
- 'release/**'
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
|
|
13
|
+
services:
|
|
14
|
+
mongodb:
|
|
15
|
+
image: mongo:8
|
|
16
|
+
ports:
|
|
17
|
+
- 27017:27017
|
|
18
|
+
|
|
19
|
+
steps:
|
|
20
|
+
- name: Checkout code
|
|
21
|
+
uses: actions/checkout@v4
|
|
22
|
+
|
|
23
|
+
- name: Setup Node.js
|
|
24
|
+
uses: actions/setup-node@v4
|
|
25
|
+
with:
|
|
26
|
+
node-version: '24'
|
|
27
|
+
|
|
28
|
+
- name: Install dependencies
|
|
29
|
+
run: npm install
|
|
30
|
+
|
|
31
|
+
- name: Install grunt-cli
|
|
32
|
+
run: npm install -g grunt-cli
|
|
33
|
+
|
|
34
|
+
- name: Run linting
|
|
35
|
+
run: grunt
|
|
36
|
+
|
|
37
|
+
- name: Run tests
|
|
38
|
+
run: grunt test
|
|
39
|
+
|
|
40
|
+
publish-docker:
|
|
41
|
+
runs-on: ubuntu-latest
|
|
42
|
+
needs: test
|
|
43
|
+
|
|
44
|
+
steps:
|
|
45
|
+
- name: Checkout code
|
|
46
|
+
uses: actions/checkout@v4
|
|
47
|
+
|
|
48
|
+
- name: Extract version from package.json
|
|
49
|
+
id: version
|
|
50
|
+
run: |
|
|
51
|
+
PACKAGE_VERSION=$(node -p "require('./package.json').version")
|
|
52
|
+
MAJOR_VERSION=$(echo ${PACKAGE_VERSION} | awk -F. '{ print $1 }')
|
|
53
|
+
echo "PACKAGE_VERSION=${PACKAGE_VERSION}" >> $GITHUB_OUTPUT
|
|
54
|
+
echo "MAJOR_VERSION=${MAJOR_VERSION}" >> $GITHUB_OUTPUT
|
|
55
|
+
echo "Package version: ${PACKAGE_VERSION}"
|
|
56
|
+
echo "Major version: ${MAJOR_VERSION}"
|
|
57
|
+
|
|
58
|
+
- name: Set up Docker Buildx
|
|
59
|
+
uses: docker/setup-buildx-action@v3
|
|
60
|
+
|
|
61
|
+
- name: Login to Docker Hub
|
|
62
|
+
uses: docker/login-action@v3
|
|
63
|
+
with:
|
|
64
|
+
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
65
|
+
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
66
|
+
|
|
67
|
+
- name: Build and push Docker image
|
|
68
|
+
uses: docker/build-push-action@v5
|
|
69
|
+
with:
|
|
70
|
+
context: .
|
|
71
|
+
platforms: linux/amd64
|
|
72
|
+
push: true
|
|
73
|
+
tags: |
|
|
74
|
+
soajsorg/multitenant:latest
|
|
75
|
+
soajsorg/multitenant:${{ steps.version.outputs.PACKAGE_VERSION }}
|
|
76
|
+
soajsorg/multitenant:${{ steps.version.outputs.MAJOR_VERSION }}.x
|
|
77
|
+
|
|
78
|
+
- name: Create Git tag
|
|
79
|
+
run: |
|
|
80
|
+
git config --local user.name "github-actions[bot]"
|
|
81
|
+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
|
|
82
|
+
git tag ${{ steps.version.outputs.PACKAGE_VERSION }} || true
|
|
83
|
+
|
|
84
|
+
- name: Push tag
|
|
85
|
+
run: git push origin ${{ steps.version.outputs.PACKAGE_VERSION }} || true
|
|
86
|
+
|
|
87
|
+
- name: Create GitHub Release
|
|
88
|
+
uses: softprops/action-gh-release@v1
|
|
89
|
+
with:
|
|
90
|
+
tag_name: ${{ steps.version.outputs.PACKAGE_VERSION }}
|
|
91
|
+
name: Release ${{ steps.version.outputs.PACKAGE_VERSION }}
|
|
92
|
+
generate_release_notes: true
|
|
93
|
+
env:
|
|
94
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
package/Gruntfile.js
CHANGED
|
@@ -197,7 +197,7 @@ module.exports = function (grunt) {
|
|
|
197
197
|
// When true, grunt-coveralls will only print a warning rather than
|
|
198
198
|
// an error, to prevent CI builds from failing unnecessarily (e.g. if
|
|
199
199
|
// coveralls.io is down). Optional, defaults to false.
|
|
200
|
-
force:
|
|
200
|
+
force: true
|
|
201
201
|
},
|
|
202
202
|
your_target: {
|
|
203
203
|
// Target-specific LCOV coverage file
|
package/_index.js
CHANGED
|
@@ -514,7 +514,13 @@ function run(serviceStartCb) {
|
|
|
514
514
|
return res.json(req.soajs.buildResponse(error, data));
|
|
515
515
|
});
|
|
516
516
|
});
|
|
517
|
-
|
|
517
|
+
|
|
518
|
+
service.get("/admin/tenants", (req, res) => {
|
|
519
|
+
bl.tenant.getByIds(req.soajs, req.soajs.inputmaskData, (error, data) => {
|
|
520
|
+
return res.json(req.soajs.buildResponse(error, data));
|
|
521
|
+
});
|
|
522
|
+
});
|
|
523
|
+
|
|
518
524
|
service.get("/tenant/console", (req, res) => {
|
|
519
525
|
req.soajs.inputmaskData.soajs = true;
|
|
520
526
|
bl.tenant.get(req.soajs, req.soajs.inputmaskData, (error, data) => {
|
package/bl/tenant.js
CHANGED
|
@@ -218,7 +218,7 @@ let bl = {
|
|
|
218
218
|
data.id = inputmaskData.id;
|
|
219
219
|
data.code = inputmaskData.code;
|
|
220
220
|
data.name = inputmaskData.name;
|
|
221
|
-
|
|
221
|
+
|
|
222
222
|
if (!data.id && !data.code && !data.name) {
|
|
223
223
|
data.id = soajs.tenant.id;
|
|
224
224
|
}
|
|
@@ -234,7 +234,24 @@ let bl = {
|
|
|
234
234
|
return cb(null, record);
|
|
235
235
|
});
|
|
236
236
|
},
|
|
237
|
-
|
|
237
|
+
|
|
238
|
+
"getByIds": (soajs, inputmaskData, cb) => {
|
|
239
|
+
if (!inputmaskData || !inputmaskData.ids) {
|
|
240
|
+
return cb(bl.handleError(soajs, 400, null));
|
|
241
|
+
}
|
|
242
|
+
let modelObj = bl.mp.getModel(soajs);
|
|
243
|
+
let data = {
|
|
244
|
+
ids: inputmaskData.ids
|
|
245
|
+
};
|
|
246
|
+
modelObj.getTenantsById(data, (err, result) => {
|
|
247
|
+
bl.mp.closeModel(soajs, modelObj);
|
|
248
|
+
if (err) {
|
|
249
|
+
return cb(bl.handleError(soajs, 602, err));
|
|
250
|
+
}
|
|
251
|
+
return cb(null, result);
|
|
252
|
+
});
|
|
253
|
+
},
|
|
254
|
+
|
|
238
255
|
"list": (soajs, inputmaskData, cb) => {
|
|
239
256
|
if (!inputmaskData) {
|
|
240
257
|
return cb(bl.handleError(soajs, 400, null));
|
package/config.js
CHANGED
|
@@ -961,6 +961,20 @@ module.exports = {
|
|
|
961
961
|
"commonFields": ['appId', 'key']
|
|
962
962
|
},
|
|
963
963
|
|
|
964
|
+
"/admin/tenants": {
|
|
965
|
+
_apiInfo: {
|
|
966
|
+
"l": "Get admin tenants by ids",
|
|
967
|
+
"group": "Admin Tenant"
|
|
968
|
+
},
|
|
969
|
+
"ids": {
|
|
970
|
+
"source": ['query.ids'],
|
|
971
|
+
"required": true,
|
|
972
|
+
"validation": {
|
|
973
|
+
'type': 'array',
|
|
974
|
+
'items': { 'type': 'string' }
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
},
|
|
964
978
|
"/admin/tenant": {
|
|
965
979
|
_apiInfo: {
|
|
966
980
|
"l": "Get admin tenant",
|
package/model/mongo/tenant.js
CHANGED
|
@@ -107,6 +107,55 @@ Tenant.prototype.getTenants = function (data, cb) {
|
|
|
107
107
|
__self.mongoCore.find(colName, condition, null, cb);
|
|
108
108
|
};
|
|
109
109
|
|
|
110
|
+
Tenant.prototype.getTenantsById = function (data, cb) {
|
|
111
|
+
let __self = this;
|
|
112
|
+
if (!data || !data.ids || !Array.isArray(data.ids) || data.ids.length === 0) {
|
|
113
|
+
let error = new Error("Array of ids is required.");
|
|
114
|
+
return cb(error, null);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
let objectIds = data.ids.map(id => __self.mongoCore.ObjectId(id));
|
|
118
|
+
|
|
119
|
+
let pipeline = [
|
|
120
|
+
{ "$match": { "_id": { "$in": objectIds } } },
|
|
121
|
+
{
|
|
122
|
+
"$facet": {
|
|
123
|
+
"count": [{ "$count": "count" }],
|
|
124
|
+
"items": [
|
|
125
|
+
{
|
|
126
|
+
"$project": {
|
|
127
|
+
"_id": 1,
|
|
128
|
+
"name": 1
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
]
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
{ "$unwind": { "path": "$count", "preserveNullAndEmptyArrays": true } },
|
|
135
|
+
{
|
|
136
|
+
"$project": {
|
|
137
|
+
"items": "$items",
|
|
138
|
+
"count": { "$ifNull": ["$count.count", 0] }
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
];
|
|
142
|
+
|
|
143
|
+
__self.mongoCore.aggregate(colName, pipeline, {}, (err, cursor) => {
|
|
144
|
+
if (err) {
|
|
145
|
+
return cb(err);
|
|
146
|
+
}
|
|
147
|
+
cursor.toArray((err, response) => {
|
|
148
|
+
if (err) {
|
|
149
|
+
return cb(err);
|
|
150
|
+
}
|
|
151
|
+
if (response && response[0]) {
|
|
152
|
+
return cb(null, response[0]);
|
|
153
|
+
}
|
|
154
|
+
return cb(null, { items: [], count: 0 });
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
};
|
|
158
|
+
|
|
110
159
|
Tenant.prototype.getTenant = function (data, cb) {
|
|
111
160
|
let __self = this;
|
|
112
161
|
if (!data || !(data.id || data.code || data.name)) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "soajs.multitenant",
|
|
3
3
|
"description": "soajs multitenant service",
|
|
4
|
-
"version": "2.1.
|
|
4
|
+
"version": "2.1.19",
|
|
5
5
|
"author": "soajs team <team@soajs.org>",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -29,13 +29,13 @@
|
|
|
29
29
|
"grunt-jsdoc": "2.4.1",
|
|
30
30
|
"grunt-mocha-test": "0.13.3",
|
|
31
31
|
"mocha": "11.7.5",
|
|
32
|
-
"nock": "14.0.
|
|
33
|
-
"soajs.controller": "4.
|
|
32
|
+
"nock": "14.0.11",
|
|
33
|
+
"soajs.controller": "4.3.0"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"async": "3.2.6",
|
|
37
|
-
"soajs": "4.1.
|
|
38
|
-
"soajs.core.libs": "1.2.
|
|
37
|
+
"soajs": "4.1.21",
|
|
38
|
+
"soajs.core.libs": "1.2.2",
|
|
39
39
|
"request": "2.88.2",
|
|
40
40
|
"uuid": "13.0.0"
|
|
41
41
|
}
|
package/.travis.yml
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
dist: focal
|
|
2
|
-
language: node_js
|
|
3
|
-
node_js: 20
|
|
4
|
-
|
|
5
|
-
jobs:
|
|
6
|
-
include:
|
|
7
|
-
|
|
8
|
-
- stage: install, check code style and coverage
|
|
9
|
-
if: tag IS blank
|
|
10
|
-
services:
|
|
11
|
-
- mongodb
|
|
12
|
-
addons:
|
|
13
|
-
hosts:
|
|
14
|
-
- localhost
|
|
15
|
-
before_script:
|
|
16
|
-
- npm install -g grunt-cli
|
|
17
|
-
- sleep 10
|
|
18
|
-
script:
|
|
19
|
-
- grunt
|
|
20
|
-
- if [ "$TRAVIS_BRANCH" != "master" ]; then grunt test; fi
|
|
21
|
-
- if [ "$TRAVIS_BRANCH" = "master" ]; then grunt coverage; fi
|
|
22
|
-
|
|
23
|
-
# - stage: Publish to npm
|
|
24
|
-
# if: branch =~ /(release)/
|
|
25
|
-
# script:
|
|
26
|
-
# - echo "PUBLISH npm"
|
|
27
|
-
# deploy:
|
|
28
|
-
# skip_cleanup: true
|
|
29
|
-
# provider: npm
|
|
30
|
-
# email: $NPM_EMAIL
|
|
31
|
-
# api_key: $NPM_TOKEN
|
|
32
|
-
# on:
|
|
33
|
-
# all_branches: true
|
|
34
|
-
# condition: $TRAVIS_BRANCH =~ ^(release)*
|
|
35
|
-
|
|
36
|
-
- stage: Publish to docker registry
|
|
37
|
-
if: branch =~ /(release)/
|
|
38
|
-
script:
|
|
39
|
-
- echo "PUBLISH docker"
|
|
40
|
-
- export PACKAGE_VERSION=$(cat package.json | grep version | head -1 | awk -Fn '{ print $2 }' | sed 's/[n:",]//g' | tr -d '[[:space:]]')
|
|
41
|
-
- export MAJOR_VERSION=$(echo ${PACKAGE_VERSION} | awk -F. '{ print $1 }')
|
|
42
|
-
- echo Package version ${PACKAGE_VERSION}
|
|
43
|
-
- echo Major version ${MAJOR_VERSION}
|
|
44
|
-
|
|
45
|
-
- git config --local user.name ${GIT_USER}
|
|
46
|
-
- git config --local user.email ${GIT_EMAIL}
|
|
47
|
-
- git tag ${PACKAGE_VERSION}
|
|
48
|
-
|
|
49
|
-
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
|
|
50
|
-
|
|
51
|
-
- docker build -t soajsorg/multitenant .
|
|
52
|
-
|
|
53
|
-
- docker images
|
|
54
|
-
|
|
55
|
-
- docker tag soajsorg/multitenant:latest soajsorg/multitenant:${PACKAGE_VERSION}
|
|
56
|
-
- docker tag soajsorg/multitenant:latest soajsorg/multitenant:${MAJOR_VERSION}.x
|
|
57
|
-
|
|
58
|
-
- docker push soajsorg/multitenant
|
|
59
|
-
- docker push soajsorg/multitenant:${PACKAGE_VERSION}
|
|
60
|
-
- docker push soajsorg/multitenant:${MAJOR_VERSION}.x
|
|
61
|
-
before_deploy:
|
|
62
|
-
- yes | gem update --system --force
|
|
63
|
-
- gem install bundler
|
|
64
|
-
- gem install faraday-net_http -v '3.3.0'
|
|
65
|
-
- gem install uri
|
|
66
|
-
- gem install logger
|
|
67
|
-
deploy:
|
|
68
|
-
on:
|
|
69
|
-
all_branches: true
|
|
70
|
-
provider: releases
|
|
71
|
-
api_key: ${GIT_TOKEN}
|
|
72
|
-
skip_cleanup: true
|