@bearei/server-common 0.0.1
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/LICENSE +21 -0
- package/README.md +73 -0
- package/dist/action-log/action-log.interface.d.ts +12 -0
- package/dist/action-log/action-log.interface.js +3 -0
- package/dist/action-log/action-log.interface.js.map +1 -0
- package/dist/action-log/action-log.module.d.ts +2 -0
- package/dist/action-log/action-log.module.js +23 -0
- package/dist/action-log/action-log.module.js.map +1 -0
- package/dist/action-log/action-log.service.d.ts +9 -0
- package/dist/action-log/action-log.service.js +35 -0
- package/dist/action-log/action-log.service.js.map +1 -0
- package/dist/action-log/index.d.ts +3 -0
- package/dist/action-log/index.js +20 -0
- package/dist/action-log/index.js.map +1 -0
- package/dist/app.decorator.d.ts +6 -0
- package/dist/app.decorator.js +11 -0
- package/dist/app.decorator.js.map +1 -0
- package/dist/app.dto.d.ts +24 -0
- package/dist/app.dto.js +113 -0
- package/dist/app.dto.js.map +1 -0
- package/dist/app.entity.d.ts +11 -0
- package/dist/app.entity.js +87 -0
- package/dist/app.entity.js.map +1 -0
- package/dist/app.interface.d.ts +33 -0
- package/dist/app.interface.js +39 -0
- package/dist/app.interface.js.map +1 -0
- package/dist/authentication/access/access.guard.d.ts +9 -0
- package/dist/authentication/access/access.guard.js +62 -0
- package/dist/authentication/access/access.guard.js.map +1 -0
- package/dist/authentication/access/access.interface.d.ts +4 -0
- package/dist/authentication/access/access.interface.js +9 -0
- package/dist/authentication/access/access.interface.js.map +1 -0
- package/dist/authentication/access/index.d.ts +2 -0
- package/dist/authentication/access/index.js +19 -0
- package/dist/authentication/access/index.js.map +1 -0
- package/dist/authentication/auth/auth.interface.d.ts +3 -0
- package/dist/authentication/auth/auth.interface.js +3 -0
- package/dist/authentication/auth/auth.interface.js.map +1 -0
- package/dist/authentication/auth/auth.module.d.ts +2 -0
- package/dist/authentication/auth/auth.module.js +23 -0
- package/dist/authentication/auth/auth.module.js.map +1 -0
- package/dist/authentication/auth/auth.service.d.ts +8 -0
- package/dist/authentication/auth/auth.service.js +31 -0
- package/dist/authentication/auth/auth.service.js.map +1 -0
- package/dist/authentication/auth/index.d.ts +3 -0
- package/dist/authentication/auth/index.js +20 -0
- package/dist/authentication/auth/index.js.map +1 -0
- package/dist/authentication/index.d.ts +3 -0
- package/dist/authentication/index.js +20 -0
- package/dist/authentication/index.js.map +1 -0
- package/dist/authentication/permission/index.d.ts +2 -0
- package/dist/authentication/permission/index.js +19 -0
- package/dist/authentication/permission/index.js.map +1 -0
- package/dist/authentication/permission/permission.guard.d.ts +9 -0
- package/dist/authentication/permission/permission.guard.js +46 -0
- package/dist/authentication/permission/permission.guard.js.map +1 -0
- package/dist/authentication/permission/permission.interface.d.ts +35 -0
- package/dist/authentication/permission/permission.interface.js +40 -0
- package/dist/authentication/permission/permission.interface.js.map +1 -0
- package/dist/base/base.interface.d.ts +42 -0
- package/dist/base/base.interface.js +3 -0
- package/dist/base/base.interface.js.map +1 -0
- package/dist/base/base.module.d.ts +2 -0
- package/dist/base/base.module.js +23 -0
- package/dist/base/base.module.js.map +1 -0
- package/dist/base/base.service.d.ts +29 -0
- package/dist/base/base.service.js +212 -0
- package/dist/base/base.service.js.map +1 -0
- package/dist/base/index.d.ts +2 -0
- package/dist/base/index.js +19 -0
- package/dist/base/index.js.map +1 -0
- package/dist/external/external.interface.d.ts +41 -0
- package/dist/external/external.interface.js +3 -0
- package/dist/external/external.interface.js.map +1 -0
- package/dist/external/external.module.d.ts +2 -0
- package/dist/external/external.module.js +24 -0
- package/dist/external/external.module.js.map +1 -0
- package/dist/external/external.service.d.ts +12 -0
- package/dist/external/external.service.js +77 -0
- package/dist/external/external.service.js.map +1 -0
- package/dist/external/index.d.ts +3 -0
- package/dist/external/index.js +20 -0
- package/dist/external/index.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/redis/index.d.ts +3 -0
- package/dist/redis/index.js +20 -0
- package/dist/redis/index.js.map +1 -0
- package/dist/redis/redis.interface.d.ts +4 -0
- package/dist/redis/redis.interface.js +3 -0
- package/dist/redis/redis.interface.js.map +1 -0
- package/dist/redis/redis.module.d.ts +2 -0
- package/dist/redis/redis.module.js +23 -0
- package/dist/redis/redis.module.js.map +1 -0
- package/dist/redis/redis.service.d.ts +10 -0
- package/dist/redis/redis.service.js +44 -0
- package/dist/redis/redis.service.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/util/error.util.d.ts +3 -0
- package/dist/util/error.util.js +45 -0
- package/dist/util/error.util.js.map +1 -0
- package/dist/util/format.util.d.ts +3 -0
- package/dist/util/format.util.js +11 -0
- package/dist/util/format.util.js.map +1 -0
- package/dist/util/index.d.ts +3 -0
- package/dist/util/index.js +20 -0
- package/dist/util/index.js.map +1 -0
- package/dist/util/util.interface.d.ts +16 -0
- package/dist/util/util.interface.js +3 -0
- package/dist/util/util.interface.js.map +1 -0
- package/package.json +106 -0
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.BaseService = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const typeorm_1 = require("typeorm");
|
|
15
|
+
const action_log_1 = require("../action-log");
|
|
16
|
+
const app_interface_1 = require("../app.interface");
|
|
17
|
+
const util_1 = require("../util");
|
|
18
|
+
let BaseService = class BaseService {
|
|
19
|
+
constructor(actionLogService) {
|
|
20
|
+
this.actionLogService = actionLogService;
|
|
21
|
+
}
|
|
22
|
+
create({ enableLogging, entityManager, entityOptions, headers, preValidateOptions, serviceName }) {
|
|
23
|
+
return async (repository) => {
|
|
24
|
+
const actionLogOptions = { action: app_interface_1.Action.CREATE, enableLogging, headers, data: { entityOptions }, serviceName };
|
|
25
|
+
preValidateOptions &&
|
|
26
|
+
(await this.preValidate({ ...preValidateOptions, serviceName, actionLogOptions })(repository));
|
|
27
|
+
const createdEntity = repository.create(entityOptions);
|
|
28
|
+
const entity = await (entityManager ? entityManager.save(createdEntity) : createdEntity.save());
|
|
29
|
+
await this.actionLogSuccess(actionLogOptions)(entity);
|
|
30
|
+
return entity;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
del({ entityManager, findOptions, serviceName, headers, enableLogging }) {
|
|
34
|
+
return async (repository) => {
|
|
35
|
+
const actionLogOptions = { action: app_interface_1.Action.DELETE, enableLogging, headers, data: { findOptions }, serviceName };
|
|
36
|
+
const entity = await this.findOne({ serviceName, findOptions, actionLogOptions })(repository);
|
|
37
|
+
await this.checkProhibited(actionLogOptions)(entity);
|
|
38
|
+
const nextActionLogOptions = {
|
|
39
|
+
...actionLogOptions,
|
|
40
|
+
data: { ...actionLogOptions.data, entity: { ...entity } }
|
|
41
|
+
};
|
|
42
|
+
await entity.softRemove();
|
|
43
|
+
await (entityManager ? entityManager.save(entity) : entity.save());
|
|
44
|
+
await this.actionLogSuccess(nextActionLogOptions)(entity);
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
async update({ enableLogging, entityManager, entityOptions, findOptions, headers, preValidateOptions, serviceName }) {
|
|
48
|
+
return async (repository) => {
|
|
49
|
+
const actionLogOptions = {
|
|
50
|
+
action: app_interface_1.Action.UPDATE,
|
|
51
|
+
enableLogging,
|
|
52
|
+
headers,
|
|
53
|
+
raw: { findOptions, entityOptions },
|
|
54
|
+
serviceName
|
|
55
|
+
};
|
|
56
|
+
const entity = await this.findOne({ actionLogOptions, findOptions, serviceName })(repository);
|
|
57
|
+
await this.checkProhibited(actionLogOptions)(entity);
|
|
58
|
+
if (preValidateOptions) {
|
|
59
|
+
const { validateKeys = [], ...args } = preValidateOptions;
|
|
60
|
+
const preValidateKeys = [
|
|
61
|
+
...new Set([...Object.keys(preValidateOptions.findOptions), ...validateKeys])
|
|
62
|
+
];
|
|
63
|
+
const findOptions = preValidateKeys
|
|
64
|
+
.map(key => ({ [key]: entityOptions[key] ?? entity[key] }))
|
|
65
|
+
.reduce((acc, cur) => ({ ...acc, ...cur }), {});
|
|
66
|
+
await this.preValidate({
|
|
67
|
+
...args,
|
|
68
|
+
actionLogOptions,
|
|
69
|
+
findOptions: { ...findOptions, notId: entity.id },
|
|
70
|
+
serviceName
|
|
71
|
+
})(repository);
|
|
72
|
+
}
|
|
73
|
+
const nextActionLogOptions = {
|
|
74
|
+
...actionLogOptions,
|
|
75
|
+
data: { ...actionLogOptions.raw, entity: { ...entity } }
|
|
76
|
+
};
|
|
77
|
+
repository.merge(entity, entityOptions);
|
|
78
|
+
await (entityManager ? entityManager.save(entity) : entity.save());
|
|
79
|
+
await this.actionLogSuccess(nextActionLogOptions)(entity);
|
|
80
|
+
return entity;
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
find({ findOptions, findManyOptions }) {
|
|
84
|
+
return async (repository) => {
|
|
85
|
+
const { page = 1, size = 10, order = 'ASC', count = false, createdAtRange, ids, ...args } = findOptions;
|
|
86
|
+
const isCount = count && page === 1;
|
|
87
|
+
const limit = size;
|
|
88
|
+
const offset = (page - 1) * size;
|
|
89
|
+
const where = {
|
|
90
|
+
...args,
|
|
91
|
+
...(ids && { id: (0, typeorm_1.In)(ids) }),
|
|
92
|
+
...(createdAtRange && {
|
|
93
|
+
createdAt: (0, typeorm_1.Between)(createdAtRange[0], createdAtRange[1])
|
|
94
|
+
})
|
|
95
|
+
};
|
|
96
|
+
const orderOptions = { createdAt: order };
|
|
97
|
+
const [entities, total] = await Promise.all([
|
|
98
|
+
repository.find({ ...findManyOptions, order: orderOptions, skip: offset, take: limit, where }),
|
|
99
|
+
isCount ? repository.count({ where }) : undefined
|
|
100
|
+
]);
|
|
101
|
+
return { results: entities, limit, offset, total };
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
findOne({ serviceName, findOptions, actionLogOptions }) {
|
|
105
|
+
return async (repository) => {
|
|
106
|
+
const entity = await repository.findOne({ where: findOptions });
|
|
107
|
+
if (!entity) {
|
|
108
|
+
const key = Object.keys(findOptions).join(',');
|
|
109
|
+
await this.throwError({
|
|
110
|
+
errorType: app_interface_1.APIError.NOT_FOUND,
|
|
111
|
+
message: `The ${serviceName} with the fields: ${key} was not found`
|
|
112
|
+
})(actionLogOptions);
|
|
113
|
+
}
|
|
114
|
+
return entity;
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
async updateLink({ enableLogging, entityIds, entityManager, findOptions, headers, linkKey, serviceName }) {
|
|
118
|
+
return async (repository) => {
|
|
119
|
+
const size = 1024;
|
|
120
|
+
const entityOptions = [...new Set(entityIds)];
|
|
121
|
+
const actionLogOptions = {
|
|
122
|
+
action: app_interface_1.Action.UPDATE,
|
|
123
|
+
enableLogging,
|
|
124
|
+
headers,
|
|
125
|
+
raw: { findOptions, entityOptions, linkKey },
|
|
126
|
+
serviceName
|
|
127
|
+
};
|
|
128
|
+
const entities = await this.find({
|
|
129
|
+
findOptions: { ...findOptions, size },
|
|
130
|
+
findManyOptions: { withDeleted: true }
|
|
131
|
+
})(repository).then(({ results }) => results);
|
|
132
|
+
const existingIds = entities.map(entity => entity[linkKey]);
|
|
133
|
+
const entitiesToAdd = entityOptions
|
|
134
|
+
.filter(id => !existingIds.includes(id))
|
|
135
|
+
.map(id => repository.create({ ...findOptions, [linkKey]: id }));
|
|
136
|
+
const entitiesToRemove = await Promise.all(entities.filter(entity => !entityOptions.includes(entity[linkKey])).map(entity => entity.softRemove()));
|
|
137
|
+
const entitiesToRecover = await Promise.all(entities
|
|
138
|
+
.filter(entity => entityOptions.includes(entity[linkKey]) && entity.deletedAt)
|
|
139
|
+
.map(entity => entity.recover()));
|
|
140
|
+
const entityActions = [...entitiesToAdd, ...entitiesToRecover, ...entitiesToRemove];
|
|
141
|
+
await (entityManager ? entityManager.save(entityActions) : repository.save(entityActions));
|
|
142
|
+
const savedEntities = await this.find({
|
|
143
|
+
findOptions: { ...findOptions, size }
|
|
144
|
+
})(repository).then(({ results }) => results);
|
|
145
|
+
await this.actionLogSuccess(actionLogOptions)(savedEntities);
|
|
146
|
+
return savedEntities;
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
preValidate({ actionLogOptions, findOptions, serviceName, validateKeys = [], validateMethod = 'and' }) {
|
|
150
|
+
return async (repository) => {
|
|
151
|
+
const { notId, ...args } = findOptions;
|
|
152
|
+
const not = notId && { id: (0, typeorm_1.Not)(notId) };
|
|
153
|
+
const orValidateKeys = validateMethod === 'or' && Array.isArray(validateKeys[0]) ?
|
|
154
|
+
[...new Set(validateKeys.flat())]
|
|
155
|
+
: validateKeys;
|
|
156
|
+
const orOtherFindOptions = validateMethod === 'or' ?
|
|
157
|
+
validateKeys.map(keys => keys.map(key => ({ [key]: findOptions[key] })).reduce((acc, cur) => ({ ...acc, ...cur }), { ...not }))
|
|
158
|
+
: [];
|
|
159
|
+
const where = (validateMethod === 'and' ?
|
|
160
|
+
{ ...args, ...not }
|
|
161
|
+
: [
|
|
162
|
+
...Object.entries(args)
|
|
163
|
+
.filter(([key]) => !orValidateKeys.includes(key))
|
|
164
|
+
.map(([key, value]) => ({ ...not, [key]: value })),
|
|
165
|
+
...orOtherFindOptions
|
|
166
|
+
]);
|
|
167
|
+
const entity = await repository.findOne({ select: Object.keys(args), where });
|
|
168
|
+
if (entity) {
|
|
169
|
+
const key = Object.keys({
|
|
170
|
+
...args,
|
|
171
|
+
...orOtherFindOptions.reduce((acc, cur) => ({ ...acc, ...cur }), {})
|
|
172
|
+
}).join(',');
|
|
173
|
+
await this.throwError({
|
|
174
|
+
errorType: app_interface_1.APIError.UNPROCESSABLE_ENTITY,
|
|
175
|
+
message: `The ${serviceName} fields: ${key} already exists`
|
|
176
|
+
})(actionLogOptions);
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
checkProhibited(actionLogOptions) {
|
|
181
|
+
return async (entity) => {
|
|
182
|
+
const isProtected = typeof entity.protected === 'boolean' && entity.protected;
|
|
183
|
+
isProtected &&
|
|
184
|
+
(await this.throwError({
|
|
185
|
+
code: 403001,
|
|
186
|
+
errorType: app_interface_1.APIError.FORBIDDEN,
|
|
187
|
+
message: `ALL actions on default ${actionLogOptions.serviceName} are prohibited`
|
|
188
|
+
})(actionLogOptions));
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
actionLogSuccess(actionLogOptions) {
|
|
192
|
+
return async (entity) => await this.actionLogService.success(actionLogOptions)({ entity });
|
|
193
|
+
}
|
|
194
|
+
throwError({ errorType, ...args }) {
|
|
195
|
+
return async (actionLogOptions) => {
|
|
196
|
+
try {
|
|
197
|
+
(0, util_1.throwError)(args)(errorType);
|
|
198
|
+
}
|
|
199
|
+
catch (error) {
|
|
200
|
+
actionLogOptions &&
|
|
201
|
+
(await this.actionLogService.failure({ ...actionLogOptions, message: error?.message })({ error }));
|
|
202
|
+
throw error;
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
exports.BaseService = BaseService;
|
|
208
|
+
exports.BaseService = BaseService = __decorate([
|
|
209
|
+
(0, common_1.Injectable)(),
|
|
210
|
+
__metadata("design:paramtypes", [action_log_1.ActionLogService])
|
|
211
|
+
], BaseService);
|
|
212
|
+
//# sourceMappingURL=base.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.service.js","sourceRoot":"","sources":["../../src/base/base.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAyC;AACzC,qCAAqG;AACrG,8CAAgE;AAGhE,oDAAiD;AACjD,kCAAkC;AAY3B,IAAM,WAAW,GAAjB,MAAM,WAAW;IACpB,YAA6B,gBAAkC;QAAlC,qBAAgB,GAAhB,gBAAgB,CAAkB;IAAG,CAAC;IAEnE,MAAM,CAAsB,EACxB,aAAa,EACb,aAAa,EACb,aAAa,EACb,OAAO,EACP,kBAAkB,EAClB,WAAW,EACI;QACf,OAAO,KAAK,EAAE,UAAyB,EAAE,EAAE;YACvC,MAAM,gBAAgB,GAAG,EAAC,MAAM,EAAE,sBAAM,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,IAAI,EAAE,EAAC,aAAa,EAAC,EAAE,WAAW,EAAC,CAAA;YAE5G,kBAAkB;gBACd,CAAC,MAAM,IAAI,CAAC,WAAW,CAAC,EAAC,GAAG,kBAAkB,EAAE,WAAW,EAAE,gBAAgB,EAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAA;YAEhG,MAAM,aAAa,GAAG,UAAU,CAAC,MAAM,CAAC,aAAa,CAAC,CAAA;YACtD,MAAM,MAAM,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC,CAAA;YAE/F,MAAM,IAAI,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAA;YAErD,OAAO,MAAM,CAAA;QACjB,CAAC,CAAA;IACL,CAAC;IAED,GAAG,CAAsB,EAAC,aAAa,EAAE,WAAW,EAAE,WAAW,EAAE,OAAO,EAAE,aAAa,EAAgB;QACrG,OAAO,KAAK,EAAE,UAAyB,EA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QY,kCAAW;sBAAX,WAAW;IADvB,IAAA,mBAAU,GAAE;qCAEsC,6BAAgB;GADtD,WAAW,CA8QvB"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./base.module"), exports);
|
|
18
|
+
__exportStar(require("./base.service"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/base/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA6B;AAC7B,iDAA8B"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { AxiosRequestConfig } from 'axios';
|
|
2
|
+
import { Action, ActionResult, APIHeaders } from '../app.interface';
|
|
3
|
+
import { Permission } from '../authentication';
|
|
4
|
+
export interface RequestOptions extends Omit<AxiosRequestConfig, 'headers'> {
|
|
5
|
+
path?: string;
|
|
6
|
+
headers: APIHeaders;
|
|
7
|
+
}
|
|
8
|
+
export interface ExternalServiceOptions {
|
|
9
|
+
headers: APIHeaders;
|
|
10
|
+
}
|
|
11
|
+
export interface CreateExternalActionLogOptions extends ExternalServiceOptions {
|
|
12
|
+
data: {
|
|
13
|
+
action: Action;
|
|
14
|
+
data?: Record<string, unknown>;
|
|
15
|
+
raw?: Record<string, unknown>;
|
|
16
|
+
result: ActionResult;
|
|
17
|
+
serviceName: string;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export type AuthExternalAccessOptions = Omit<ExternalServiceOptions, 'data'>;
|
|
21
|
+
export interface AuthExternalPermissionOptions extends ExternalServiceOptions {
|
|
22
|
+
findOptions: {
|
|
23
|
+
keys: Permission[];
|
|
24
|
+
userId: string;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export interface AuthenticatedToken {
|
|
28
|
+
aud: string;
|
|
29
|
+
iss: string;
|
|
30
|
+
jti: string;
|
|
31
|
+
nbf: number;
|
|
32
|
+
sub: string;
|
|
33
|
+
}
|
|
34
|
+
export interface AuthenticatedPermission {
|
|
35
|
+
result: 'successes' | 'failure';
|
|
36
|
+
}
|
|
37
|
+
export interface APIRequest {
|
|
38
|
+
headers: APIHeaders;
|
|
39
|
+
params: Record<string, string>;
|
|
40
|
+
user: AuthenticatedToken;
|
|
41
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"external.interface.js","sourceRoot":"","sources":["../../src/external/external.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.ExternalModule = void 0;
|
|
10
|
+
const axios_1 = require("@nestjs/axios");
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const config_1 = require("@nestjs/config");
|
|
13
|
+
const external_service_1 = require("./external.service");
|
|
14
|
+
let ExternalModule = class ExternalModule {
|
|
15
|
+
};
|
|
16
|
+
exports.ExternalModule = ExternalModule;
|
|
17
|
+
exports.ExternalModule = ExternalModule = __decorate([
|
|
18
|
+
(0, common_1.Module)({
|
|
19
|
+
exports: [external_service_1.ExternalService],
|
|
20
|
+
imports: [config_1.default.ConfigModule, axios_1.HttpModule.register({ timeout: 20000, maxRedirects: 5 })],
|
|
21
|
+
providers: [external_service_1.ExternalService]
|
|
22
|
+
})
|
|
23
|
+
], ExternalModule);
|
|
24
|
+
//# sourceMappingURL=external.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"external.module.js","sourceRoot":"","sources":["../../src/external/external.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,yCAAwC;AACxC,2CAAqC;AACrC,2CAAmC;AACnC,yDAAkD;AAO3C,IAAM,cAAc,GAApB,MAAM,cAAc;CAAG,CAAA;AAAjB,wCAAc;yBAAd,cAAc;IAL1B,IAAA,eAAM,EAAC;QACJ,OAAO,EAAE,CAAC,kCAAe,CAAC;QAC1B,OAAO,EAAE,CAAC,gBAAM,CAAC,YAAY,EAAE,kBAAU,CAAC,QAAQ,CAAC,EAAC,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC,EAAC,CAAC,CAAC;QACtF,SAAS,EAAE,CAAC,kCAAe,CAAC;KAC/B,CAAC;GACW,cAAc,CAAG"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { HttpService } from '@nestjs/axios';
|
|
2
|
+
import { ConfigService } from '@nestjs/config';
|
|
3
|
+
import { AuthenticatedPermission, AuthenticatedToken, AuthExternalAccessOptions, AuthExternalPermissionOptions, CreateExternalActionLogOptions, RequestOptions } from './external.interface';
|
|
4
|
+
export declare class ExternalService {
|
|
5
|
+
private readonly configService;
|
|
6
|
+
private readonly httpService;
|
|
7
|
+
constructor(configService: ConfigService, httpService: HttpService);
|
|
8
|
+
authAccess({ headers }: AuthExternalAccessOptions): Promise<AuthenticatedToken>;
|
|
9
|
+
authPermission({ findOptions, headers }: AuthExternalPermissionOptions): Promise<AuthenticatedPermission>;
|
|
10
|
+
createActionLog({ data, headers }: CreateExternalActionLogOptions): Promise<void>;
|
|
11
|
+
request({ method, path, headers, ...options }: RequestOptions): Promise<any>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ExternalService = void 0;
|
|
13
|
+
const axios_1 = require("@nestjs/axios");
|
|
14
|
+
const common_1 = require("@nestjs/common");
|
|
15
|
+
const config_1 = require("@nestjs/config");
|
|
16
|
+
const rxjs_1 = require("rxjs");
|
|
17
|
+
const app_interface_1 = require("../app.interface");
|
|
18
|
+
const util_1 = require("../util");
|
|
19
|
+
let ExternalService = class ExternalService {
|
|
20
|
+
constructor(configService, httpService) {
|
|
21
|
+
this.configService = configService;
|
|
22
|
+
this.httpService = httpService;
|
|
23
|
+
}
|
|
24
|
+
async authAccess({ headers }) {
|
|
25
|
+
return this.request({ method: 'GET', path: '/auth/accesses', headers });
|
|
26
|
+
}
|
|
27
|
+
async authPermission({ findOptions, headers }) {
|
|
28
|
+
const { keys, ...args } = findOptions;
|
|
29
|
+
return this.request({
|
|
30
|
+
headers,
|
|
31
|
+
method: 'GET',
|
|
32
|
+
params: { keys: keys.join(','), ...args },
|
|
33
|
+
path: '/auth/permissions'
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
async createActionLog({ data, headers }) {
|
|
37
|
+
const { action, serviceName, ...args } = data;
|
|
38
|
+
await this.request({
|
|
39
|
+
method: 'POST',
|
|
40
|
+
path: '/action-logs',
|
|
41
|
+
data: {
|
|
42
|
+
...args,
|
|
43
|
+
action,
|
|
44
|
+
apiName: `${action}:${serviceName}`,
|
|
45
|
+
client: headers['x-client'],
|
|
46
|
+
ip: headers['x-ip'],
|
|
47
|
+
projectId: headers['x-project-id'],
|
|
48
|
+
scopeId: headers['x-scope-id'],
|
|
49
|
+
serviceName: this.configService.get('serviceName'),
|
|
50
|
+
userAgent: headers['user-agent'],
|
|
51
|
+
userId: headers['x-authorization']
|
|
52
|
+
},
|
|
53
|
+
headers
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
async request({ method = 'GET', path = '/', headers, ...options }) {
|
|
57
|
+
return (0, rxjs_1.firstValueFrom)(this.httpService
|
|
58
|
+
.request({
|
|
59
|
+
...options,
|
|
60
|
+
adapter: 'fetch',
|
|
61
|
+
headers: { ...headers, 'x-fc-invocation-type': 'Async' },
|
|
62
|
+
method,
|
|
63
|
+
url: `${this.configService.get('url')}${path}`
|
|
64
|
+
})
|
|
65
|
+
.pipe((0, rxjs_1.catchError)(error => {
|
|
66
|
+
error.status && (0, util_1.throwError)({ response: error, status: error.status })(app_interface_1.APIError.HTTP_EXCEPTION);
|
|
67
|
+
throw error;
|
|
68
|
+
}))).then(res => res.data);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
exports.ExternalService = ExternalService;
|
|
72
|
+
exports.ExternalService = ExternalService = __decorate([
|
|
73
|
+
(0, common_1.Injectable)(),
|
|
74
|
+
__metadata("design:paramtypes", [config_1.ConfigService,
|
|
75
|
+
axios_1.HttpService])
|
|
76
|
+
], ExternalService);
|
|
77
|
+
//# sourceMappingURL=external.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"external.service.js","sourceRoot":"","sources":["../../src/external/external.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yCAAyC;AACzC,2CAAyC;AACzC,2CAA4C;AAC5C,+BAA+C;AAE/C,oDAAyC;AACzC,kCAAkC;AAW3B,IAAM,eAAe,GAArB,MAAM,eAAe;IACxB,YACqB,aAA4B,EAC5B,WAAwB;QADxB,kBAAa,GAAb,aAAa,CAAe;QAC5B,gBAAW,GAAX,WAAW,CAAa;IAC1C,CAAC;IAEJ,KAAK,CAAC,UAAU,CAAC,EAAC,OAAO,EAA4B;QACjD,OAAO,IAAI,CAAC,OAAO,CAAC,EAAC,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,gBAAgB,EAAE,OAAO,EAAC,CAAC,CAAA;IACzE,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,EAAC,WAAW,EAAE,OAAO,EAAgC;QACtE,MAAM,EAAC,IAAI,EAAE,GAAG,IAAI,EAAC,GAAG,WAAW,CAAA;QAEnC,OAAO,IAAI,CAAC,OAAO,CAAC;YAChB,OAAO;YACP,MAAM,EAAE,KAAK;YACb,MAAM,EAAE,EAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,IAAI,EAAC;YACvC,IAAI,EAAE,mBAAmB;SAC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AAQ,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAC,CAAC,CAAC,wBAAQ,CAAC,cAAc,CAAC,CAAA;YAE5F,MAAM,KAAK,CAAA;QACf,CAAC,CAAC,CACL,CACR,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IAC3B,CAAC;CACJ,CAAA;AA9DY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,mBAAU,GAAE;qCAG2B,sBAAa;QACf,mBAAW;GAHpC,eAAe,CA8D3B"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./external.interface"), exports);
|
|
18
|
+
__exportStar(require("./external.module"), exports);
|
|
19
|
+
__exportStar(require("./external.service"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/external/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uDAAoC;AACpC,oDAAiC;AACjC,qDAAkC"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./app.decorator"), exports);
|
|
18
|
+
__exportStar(require("./app.dto"), exports);
|
|
19
|
+
__exportStar(require("./app.entity"), exports);
|
|
20
|
+
__exportStar(require("./app.interface"), exports);
|
|
21
|
+
__exportStar(require("./authentication"), exports);
|
|
22
|
+
__exportStar(require("./base"), exports);
|
|
23
|
+
__exportStar(require("./redis"), exports);
|
|
24
|
+
__exportStar(require("./util"), exports);
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAA+B;AAC/B,4CAAyB;AACzB,+CAA4B;AAC5B,kDAA+B;AAC/B,mDAAgC;AAChC,yCAAsB;AACtB,0CAAuB;AACvB,yCAAsB"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./redis.interface"), exports);
|
|
18
|
+
__exportStar(require("./redis.module"), exports);
|
|
19
|
+
__exportStar(require("./redis.service"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/redis/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAiC;AACjC,iDAA8B;AAC9B,kDAA+B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redis.interface.js","sourceRoot":"","sources":["../../src/redis/redis.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.RedisModule = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const config_1 = require("@nestjs/config");
|
|
12
|
+
const redis_service_1 = require("./redis.service");
|
|
13
|
+
let RedisModule = class RedisModule {
|
|
14
|
+
};
|
|
15
|
+
exports.RedisModule = RedisModule;
|
|
16
|
+
exports.RedisModule = RedisModule = __decorate([
|
|
17
|
+
(0, common_1.Module)({
|
|
18
|
+
exports: [redis_service_1.RedisService],
|
|
19
|
+
imports: [config_1.default.ConfigModule],
|
|
20
|
+
providers: [redis_service_1.RedisService]
|
|
21
|
+
})
|
|
22
|
+
], RedisModule);
|
|
23
|
+
//# sourceMappingURL=redis.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redis.module.js","sourceRoot":"","sources":["../../src/redis/redis.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAqC;AACrC,2CAAmC;AACnC,mDAA4C;AAOrC,IAAM,WAAW,GAAjB,MAAM,WAAW;CAAG,CAAA;AAAd,kCAAW;sBAAX,WAAW;IALvB,IAAA,eAAM,EAAC;QACJ,OAAO,EAAE,CAAC,4BAAY,CAAC;QACvB,OAAO,EAAE,CAAC,gBAAM,CAAC,YAAY,CAAC;QAC9B,SAAS,EAAE,CAAC,4BAAY,CAAC;KAC5B,CAAC;GACW,WAAW,CAAG"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ConfigService } from '@nestjs/config';
|
|
2
|
+
import { RedisKey } from 'ioredis';
|
|
3
|
+
import { RedisSetOptions } from './redis.interface';
|
|
4
|
+
export declare class RedisService {
|
|
5
|
+
private readonly redis;
|
|
6
|
+
constructor(configService: ConfigService);
|
|
7
|
+
set({ value, expireTime }: RedisSetOptions): (key: RedisKey) => Promise<"OK">;
|
|
8
|
+
get(key: RedisKey): Promise<string>;
|
|
9
|
+
del(key: RedisKey): Promise<number>;
|
|
10
|
+
}
|