mblabs-roccato-backend-commons 1.0.70 → 1.0.72
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/dist/interfaces/elastic-apm.d.ts +20 -0
- package/dist/interfaces/elastic-apm.js +2 -0
- package/dist/interfaces/index.d.ts +1 -0
- package/dist/interfaces/index.js +1 -0
- package/dist/services/aws/secret-manager.js +2 -2
- package/dist/services/aws/sqs.js +3 -3
- package/dist/services/azure/keyvault.js +1 -1
- package/dist/services/elastic-apm.d.ts +6 -0
- package/dist/services/elastic-apm.js +8 -0
- package/dist/services/firebase.d.ts +1 -0
- package/dist/services/firebase.js +14 -24
- package/dist/services/gcp/secrets.js +1 -1
- package/dist/services/index.d.ts +2 -1
- package/dist/services/index.js +3 -1
- package/dist/services/kafka.js +3 -3
- package/dist/services/rabbit.js +3 -3
- package/dist/services/redis.js +2 -2
- package/dist/utils/parser.d.ts +2 -1
- package/dist/utils/parser.js +17 -6
- package/package.json +2 -1
- package/src/interfaces/elastic-apm.ts +21 -0
- package/src/interfaces/index.ts +1 -0
- package/src/services/aws/secret-manager.ts +3 -3
- package/src/services/aws/sqs.ts +4 -4
- package/src/services/azure/keyvault.ts +2 -2
- package/src/services/elastic-apm.ts +9 -0
- package/src/services/firebase.ts +22 -27
- package/src/services/gcp/secrets.ts +2 -2
- package/src/services/index.ts +2 -0
- package/src/services/kafka.ts +4 -4
- package/src/services/rabbit.ts +4 -4
- package/src/services/redis.ts +3 -3
- package/src/utils/parser.ts +18 -5
- package/yarn.lock +391 -11
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
interface Credentials {
|
|
2
|
+
service: string;
|
|
3
|
+
server: string;
|
|
4
|
+
environment: string;
|
|
5
|
+
secretToken: string;
|
|
6
|
+
}
|
|
7
|
+
export declare namespace ElasticAPM {
|
|
8
|
+
namespace CaptureError {
|
|
9
|
+
interface Request {
|
|
10
|
+
data: {
|
|
11
|
+
error: Error | string;
|
|
12
|
+
};
|
|
13
|
+
credentials: Credentials;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export interface IElasticAPMService {
|
|
18
|
+
captureError(req: ElasticAPM.CaptureError.Request): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
export {};
|
package/dist/interfaces/index.js
CHANGED
|
@@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./aws"), exports);
|
|
18
18
|
__exportStar(require("./azure"), exports);
|
|
19
|
+
__exportStar(require("./elastic-apm"), exports);
|
|
19
20
|
__exportStar(require("./firebase"), exports);
|
|
20
21
|
__exportStar(require("./gcp"), exports);
|
|
21
22
|
__exportStar(require("./grafana"), exports);
|
|
@@ -13,14 +13,14 @@ class AmazonSecretManagerService {
|
|
|
13
13
|
});
|
|
14
14
|
const { SecretString, SecretBinary } = await client.getSecretValue({ SecretId: data.secret });
|
|
15
15
|
if (SecretString) {
|
|
16
|
-
const secret = (0, parser_1.
|
|
16
|
+
const secret = (0, parser_1.safeParser)(SecretString);
|
|
17
17
|
return {
|
|
18
18
|
secret,
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
21
|
if (SecretBinary) {
|
|
22
22
|
const decoded = Buffer.from(SecretBinary);
|
|
23
|
-
const secret = (0, parser_1.
|
|
23
|
+
const secret = (0, parser_1.safeParser)(decoded.toString('utf-8'));
|
|
24
24
|
return {
|
|
25
25
|
secret,
|
|
26
26
|
};
|
package/dist/services/aws/sqs.js
CHANGED
|
@@ -13,7 +13,7 @@ class AmazonSQSService {
|
|
|
13
13
|
});
|
|
14
14
|
const { QueueUrl } = await client.getQueueUrl({ QueueName: data.queue });
|
|
15
15
|
await client.sendMessage({
|
|
16
|
-
MessageBody:
|
|
16
|
+
MessageBody: (0, utils_1.safeStringify)(data.message),
|
|
17
17
|
QueueUrl,
|
|
18
18
|
});
|
|
19
19
|
}
|
|
@@ -37,7 +37,7 @@ class AmazonSQSService {
|
|
|
37
37
|
ReceiptHandle: message.ReceiptHandle,
|
|
38
38
|
}));
|
|
39
39
|
return {
|
|
40
|
-
message: (0, utils_1.
|
|
40
|
+
message: (0, utils_1.safeParser)(message?.Body),
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
43
|
return {
|
|
@@ -63,7 +63,7 @@ class AmazonSQSService {
|
|
|
63
63
|
ReceiptHandle: message?.ReceiptHandle,
|
|
64
64
|
}))));
|
|
65
65
|
return {
|
|
66
|
-
messages: Messages?.map((message) => (0, utils_1.
|
|
66
|
+
messages: Messages?.map((message) => (0, utils_1.safeParser)(message?.Body)),
|
|
67
67
|
};
|
|
68
68
|
}
|
|
69
69
|
return {
|
|
@@ -9,7 +9,7 @@ class AzureKeyVaultService {
|
|
|
9
9
|
const client = new keyvault_secrets_1.SecretClient(data.vault, credential);
|
|
10
10
|
const { value } = await client.getSecret(data.secretName);
|
|
11
11
|
if (value) {
|
|
12
|
-
const secret = (0, parser_1.
|
|
12
|
+
const secret = (0, parser_1.safeParser)(value);
|
|
13
13
|
return {
|
|
14
14
|
secret,
|
|
15
15
|
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ElasticAPM, IElasticAPMService } from '../interfaces';
|
|
2
|
+
declare class ElasticAPMService implements IElasticAPMService {
|
|
3
|
+
captureError(req: ElasticAPM.CaptureError.Request): Promise<void>;
|
|
4
|
+
}
|
|
5
|
+
declare const _default: ElasticAPMService;
|
|
6
|
+
export default _default;
|
|
@@ -3,6 +3,7 @@ declare class FirebaseService implements IFirebaseService {
|
|
|
3
3
|
publishConfig({ credentials, data, }: Firebase.PublishConfig.Request): Promise<void>;
|
|
4
4
|
sendNotification({ credentials, data, }: Firebase.SendNotification.Request): Promise<void>;
|
|
5
5
|
saveFirestore<T>({ credentials, data, }: Firebase.SaveFirestore.Request<T>): Promise<void>;
|
|
6
|
+
private createClient;
|
|
6
7
|
}
|
|
7
8
|
declare const _default: FirebaseService;
|
|
8
9
|
export default _default;
|
|
@@ -7,14 +7,7 @@ const firebase_admin_1 = __importDefault(require("firebase-admin"));
|
|
|
7
7
|
class FirebaseService {
|
|
8
8
|
async publishConfig({ credentials, data, }) {
|
|
9
9
|
const exists = firebase_admin_1.default.apps?.find(app => app.name === credentials.instance) ?? undefined;
|
|
10
|
-
const client = exists ??
|
|
11
|
-
credential: firebase_admin_1.default.credential.cert({
|
|
12
|
-
projectId: credentials.project,
|
|
13
|
-
clientEmail: credentials.clientEmail,
|
|
14
|
-
privateKey: credentials.privateKey,
|
|
15
|
-
}),
|
|
16
|
-
databaseURL: credentials.database,
|
|
17
|
-
}, credentials.instance);
|
|
10
|
+
const client = exists ?? this.createClient(credentials);
|
|
18
11
|
const template = client
|
|
19
12
|
.remoteConfig()
|
|
20
13
|
.createTemplateFromJSON(data.template);
|
|
@@ -25,14 +18,7 @@ class FirebaseService {
|
|
|
25
18
|
}
|
|
26
19
|
async sendNotification({ credentials, data, }) {
|
|
27
20
|
const exists = firebase_admin_1.default.apps?.find(app => app.name === credentials.instance) ?? undefined;
|
|
28
|
-
const client = exists ??
|
|
29
|
-
credential: firebase_admin_1.default.credential.cert({
|
|
30
|
-
projectId: credentials.project,
|
|
31
|
-
clientEmail: credentials.clientEmail,
|
|
32
|
-
privateKey: credentials.privateKey,
|
|
33
|
-
}),
|
|
34
|
-
databaseURL: credentials.database,
|
|
35
|
-
}, credentials.instance);
|
|
21
|
+
const client = exists ?? this.createClient(credentials);
|
|
36
22
|
await client
|
|
37
23
|
.messaging()
|
|
38
24
|
.sendEachForMulticast(data.message, data.isTest);
|
|
@@ -40,19 +26,23 @@ class FirebaseService {
|
|
|
40
26
|
}
|
|
41
27
|
async saveFirestore({ credentials, data, }) {
|
|
42
28
|
const exists = firebase_admin_1.default.apps?.find(app => app.name === credentials.instance) ?? undefined;
|
|
43
|
-
const client = exists ??
|
|
44
|
-
credential: firebase_admin_1.default.credential.cert({
|
|
45
|
-
projectId: credentials.project,
|
|
46
|
-
clientEmail: credentials.clientEmail,
|
|
47
|
-
privateKey: credentials.privateKey,
|
|
48
|
-
}),
|
|
49
|
-
databaseURL: credentials.database,
|
|
50
|
-
}, credentials.instance);
|
|
29
|
+
const client = exists ?? this.createClient(credentials);
|
|
51
30
|
await client
|
|
52
31
|
.firestore()
|
|
53
32
|
.collection(data.collection)
|
|
54
33
|
.add(data.record);
|
|
55
34
|
await client.delete();
|
|
56
35
|
}
|
|
36
|
+
createClient(dto) {
|
|
37
|
+
const client = firebase_admin_1.default.initializeApp({
|
|
38
|
+
credential: firebase_admin_1.default.credential.cert({
|
|
39
|
+
projectId: dto.project,
|
|
40
|
+
clientEmail: dto.clientEmail,
|
|
41
|
+
privateKey: dto.privateKey,
|
|
42
|
+
}),
|
|
43
|
+
databaseURL: dto.database,
|
|
44
|
+
}, dto.instance);
|
|
45
|
+
return client;
|
|
46
|
+
}
|
|
57
47
|
}
|
|
58
48
|
exports.default = new FirebaseService();
|
|
@@ -14,7 +14,7 @@ class GoogleSecretsService {
|
|
|
14
14
|
const buffer = (version.payload?.data ?? new Uint8Array());
|
|
15
15
|
const secret = Buffer.from(buffer).toString('utf-8');
|
|
16
16
|
return {
|
|
17
|
-
secret: (0, parser_1.
|
|
17
|
+
secret: (0, parser_1.safeParser)(secret),
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
20
|
}
|
package/dist/services/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AmazonCloudwatchService, AmazonPinpointService, AmazonS3Service, AmazonSecretManagerService, AmazonSQSService } from './aws';
|
|
2
2
|
import { AzureApplicationInsightsService, AzureAuthService, AzureCalendarService, AzureCommunicationService, AzureKeyVaultService, AzureStorageBlobService } from './azure';
|
|
3
3
|
import DateService from './date';
|
|
4
|
+
import ElasticAPMService from './elastic-apm';
|
|
4
5
|
import FileService from './file';
|
|
5
6
|
import FirebaseService from './firebase';
|
|
6
7
|
import { GoogleAuthService, GoogleCalendarService, GoogleMonitorService, GoogleSecretsService, GoogleSheetsService, GoogleStorageService } from './gcp';
|
|
@@ -12,4 +13,4 @@ import NodeMailerService from './nodemailer';
|
|
|
12
13
|
import RabbitMQService from './rabbit';
|
|
13
14
|
import RedisService from './redis';
|
|
14
15
|
import SendgridService from './sendgrid';
|
|
15
|
-
export { AmazonCloudwatchService, AmazonPinpointService, AmazonS3Service, AmazonSecretManagerService, AmazonSQSService, AzureApplicationInsightsService, AzureAuthService, AzureCalendarService, AzureCommunicationService, AzureKeyVaultService, AzureStorageBlobService, DateService, FileService, FirebaseService, GoogleAuthService, GoogleCalendarService, GoogleMonitorService, GoogleSecretsService, GoogleSheetsService, GoogleStorageService, GrafanaService, I18nService, KafkaService, KeycloakService, NodeMailerService, RabbitMQService, RedisService, SendgridService, };
|
|
16
|
+
export { AmazonCloudwatchService, AmazonPinpointService, AmazonS3Service, AmazonSecretManagerService, AmazonSQSService, AzureApplicationInsightsService, AzureAuthService, AzureCalendarService, AzureCommunicationService, AzureKeyVaultService, AzureStorageBlobService, DateService, ElasticAPMService, FileService, FirebaseService, GoogleAuthService, GoogleCalendarService, GoogleMonitorService, GoogleSecretsService, GoogleSheetsService, GoogleStorageService, GrafanaService, I18nService, KafkaService, KeycloakService, NodeMailerService, RabbitMQService, RedisService, SendgridService, };
|
package/dist/services/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.SendgridService = exports.RedisService = exports.RabbitMQService = exports.NodeMailerService = exports.KeycloakService = exports.KafkaService = exports.I18nService = exports.GrafanaService = exports.GoogleStorageService = exports.GoogleSheetsService = exports.GoogleSecretsService = exports.GoogleMonitorService = exports.GoogleCalendarService = exports.GoogleAuthService = exports.FirebaseService = exports.FileService = exports.DateService = exports.AzureStorageBlobService = exports.AzureKeyVaultService = exports.AzureCommunicationService = exports.AzureCalendarService = exports.AzureAuthService = exports.AzureApplicationInsightsService = exports.AmazonSQSService = exports.AmazonSecretManagerService = exports.AmazonS3Service = exports.AmazonPinpointService = exports.AmazonCloudwatchService = void 0;
|
|
6
|
+
exports.SendgridService = exports.RedisService = exports.RabbitMQService = exports.NodeMailerService = exports.KeycloakService = exports.KafkaService = exports.I18nService = exports.GrafanaService = exports.GoogleStorageService = exports.GoogleSheetsService = exports.GoogleSecretsService = exports.GoogleMonitorService = exports.GoogleCalendarService = exports.GoogleAuthService = exports.FirebaseService = exports.FileService = exports.ElasticAPMService = exports.DateService = exports.AzureStorageBlobService = exports.AzureKeyVaultService = exports.AzureCommunicationService = exports.AzureCalendarService = exports.AzureAuthService = exports.AzureApplicationInsightsService = exports.AmazonSQSService = exports.AmazonSecretManagerService = exports.AmazonS3Service = exports.AmazonPinpointService = exports.AmazonCloudwatchService = void 0;
|
|
7
7
|
const aws_1 = require("./aws");
|
|
8
8
|
Object.defineProperty(exports, "AmazonCloudwatchService", { enumerable: true, get: function () { return aws_1.AmazonCloudwatchService; } });
|
|
9
9
|
Object.defineProperty(exports, "AmazonPinpointService", { enumerable: true, get: function () { return aws_1.AmazonPinpointService; } });
|
|
@@ -19,6 +19,8 @@ Object.defineProperty(exports, "AzureKeyVaultService", { enumerable: true, get:
|
|
|
19
19
|
Object.defineProperty(exports, "AzureStorageBlobService", { enumerable: true, get: function () { return azure_1.AzureStorageBlobService; } });
|
|
20
20
|
const date_1 = __importDefault(require("./date"));
|
|
21
21
|
exports.DateService = date_1.default;
|
|
22
|
+
const elastic_apm_1 = __importDefault(require("./elastic-apm"));
|
|
23
|
+
exports.ElasticAPMService = elastic_apm_1.default;
|
|
22
24
|
const file_1 = __importDefault(require("./file"));
|
|
23
25
|
exports.FileService = file_1.default;
|
|
24
26
|
const firebase_1 = __importDefault(require("./firebase"));
|
package/dist/services/kafka.js
CHANGED
|
@@ -13,7 +13,7 @@ class KafkaService {
|
|
|
13
13
|
await producer.send({
|
|
14
14
|
topic: data.topic,
|
|
15
15
|
messages: data.messages.map(message => ({
|
|
16
|
-
value:
|
|
16
|
+
value: (0, utils_1.safeStringify)(message),
|
|
17
17
|
})),
|
|
18
18
|
});
|
|
19
19
|
await producer.disconnect();
|
|
@@ -32,7 +32,7 @@ class KafkaService {
|
|
|
32
32
|
if (!message?.value) {
|
|
33
33
|
resolve(null);
|
|
34
34
|
}
|
|
35
|
-
const value = (0, utils_1.
|
|
35
|
+
const value = (0, utils_1.safeParser)(message.value.toString());
|
|
36
36
|
resolve(value);
|
|
37
37
|
},
|
|
38
38
|
});
|
|
@@ -63,7 +63,7 @@ class KafkaService {
|
|
|
63
63
|
resolve();
|
|
64
64
|
}
|
|
65
65
|
try {
|
|
66
|
-
const value = (0, utils_1.
|
|
66
|
+
const value = (0, utils_1.safeParser)(message.value.toString());
|
|
67
67
|
messages.push(value);
|
|
68
68
|
// eslint-disable-next-line no-unused-vars
|
|
69
69
|
}
|
package/dist/services/rabbit.js
CHANGED
|
@@ -7,7 +7,7 @@ class RabbitMQService {
|
|
|
7
7
|
const connection = await (0, amqplib_1.connect)(credentials.uri);
|
|
8
8
|
const channel = await connection.createChannel();
|
|
9
9
|
await channel.assertExchange(data.exchange, 'topic', { durable: true });
|
|
10
|
-
channel.publish(data.exchange, data.routingKey, Buffer.from(
|
|
10
|
+
channel.publish(data.exchange, data.routingKey, Buffer.from((0, utils_1.safeStringify)(data.message)));
|
|
11
11
|
await channel.close();
|
|
12
12
|
await connection.close();
|
|
13
13
|
}
|
|
@@ -20,7 +20,7 @@ class RabbitMQService {
|
|
|
20
20
|
if (!message?.content) {
|
|
21
21
|
resolve(null);
|
|
22
22
|
}
|
|
23
|
-
const value = (0, utils_1.
|
|
23
|
+
const value = (0, utils_1.safeParser)(message.content.toString());
|
|
24
24
|
resolve(value);
|
|
25
25
|
});
|
|
26
26
|
});
|
|
@@ -44,7 +44,7 @@ class RabbitMQService {
|
|
|
44
44
|
if (!message?.content) {
|
|
45
45
|
resolve(null);
|
|
46
46
|
}
|
|
47
|
-
const value = (0, utils_1.
|
|
47
|
+
const value = (0, utils_1.safeParser)(message.content.toString());
|
|
48
48
|
resolve(value);
|
|
49
49
|
});
|
|
50
50
|
});
|
package/dist/services/redis.js
CHANGED
|
@@ -20,7 +20,7 @@ class RedisService {
|
|
|
20
20
|
},
|
|
21
21
|
};
|
|
22
22
|
await client.connect();
|
|
23
|
-
await client.set(data.key,
|
|
23
|
+
await client.set(data.key, (0, utils_1.safeStringify)(data.value), options);
|
|
24
24
|
await client.close();
|
|
25
25
|
}
|
|
26
26
|
async get({ credentials, data }) {
|
|
@@ -36,7 +36,7 @@ class RedisService {
|
|
|
36
36
|
await client.close();
|
|
37
37
|
return {
|
|
38
38
|
data: typeof response === 'string'
|
|
39
|
-
? (0, utils_1.
|
|
39
|
+
? (0, utils_1.safeParser)(response)
|
|
40
40
|
: null,
|
|
41
41
|
};
|
|
42
42
|
}
|
package/dist/utils/parser.d.ts
CHANGED
package/dist/utils/parser.js
CHANGED
|
@@ -1,17 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.safeParser = safeParser;
|
|
4
4
|
exports.parseRegex = parseRegex;
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
exports.safeStringify = safeStringify;
|
|
6
|
+
function safeParser(raw) {
|
|
7
|
+
let response = null;
|
|
7
8
|
try {
|
|
8
|
-
|
|
9
|
+
response = JSON.parse(raw);
|
|
9
10
|
}
|
|
10
11
|
catch {
|
|
11
|
-
|
|
12
|
+
response = {};
|
|
12
13
|
}
|
|
13
|
-
return
|
|
14
|
+
return response;
|
|
14
15
|
}
|
|
15
16
|
function parseRegex(text) {
|
|
16
17
|
return text.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
|
|
17
18
|
}
|
|
19
|
+
function safeStringify(obj) {
|
|
20
|
+
let response = null;
|
|
21
|
+
try {
|
|
22
|
+
response = safeStringify(obj);
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
response = '{}';
|
|
26
|
+
}
|
|
27
|
+
return response;
|
|
28
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mblabs-roccato-backend-commons",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.72",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -66,6 +66,7 @@
|
|
|
66
66
|
"applicationinsights": "^3.7.0",
|
|
67
67
|
"axios": "^1.8.4",
|
|
68
68
|
"class-transformer": "^0.5.1",
|
|
69
|
+
"elastic-apm-node": "^4.15.0",
|
|
69
70
|
"firebase-admin": "^13.4.0",
|
|
70
71
|
"google-auth-library": "^10.3.0",
|
|
71
72
|
"googleapis": "^148.0.0",
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
interface Credentials {
|
|
2
|
+
service: string;
|
|
3
|
+
server: string;
|
|
4
|
+
environment: string;
|
|
5
|
+
secretToken: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export namespace ElasticAPM {
|
|
9
|
+
export namespace CaptureError {
|
|
10
|
+
export interface Request {
|
|
11
|
+
data: {
|
|
12
|
+
error: Error | string;
|
|
13
|
+
};
|
|
14
|
+
credentials: Credentials;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface IElasticAPMService {
|
|
20
|
+
captureError (req: ElasticAPM.CaptureError.Request): Promise<void>;
|
|
21
|
+
}
|
package/src/interfaces/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SecretsManager } from '@aws-sdk/client-secrets-manager';
|
|
2
2
|
|
|
3
3
|
import { AmazonSecretManager, IAmazonSecretManagerService } from '../../interfaces';
|
|
4
|
-
import {
|
|
4
|
+
import { safeParser } from '../../utils/parser';
|
|
5
5
|
|
|
6
6
|
class AmazonSecretManagerService implements IAmazonSecretManagerService {
|
|
7
7
|
public async getSecret<T> ({
|
|
@@ -19,7 +19,7 @@ class AmazonSecretManagerService implements IAmazonSecretManagerService {
|
|
|
19
19
|
const { SecretString, SecretBinary } = await client.getSecretValue({ SecretId: data.secret });
|
|
20
20
|
|
|
21
21
|
if (SecretString) {
|
|
22
|
-
const secret =
|
|
22
|
+
const secret = safeParser(SecretString) as T;
|
|
23
23
|
|
|
24
24
|
return {
|
|
25
25
|
secret,
|
|
@@ -28,7 +28,7 @@ class AmazonSecretManagerService implements IAmazonSecretManagerService {
|
|
|
28
28
|
|
|
29
29
|
if (SecretBinary) {
|
|
30
30
|
const decoded = Buffer.from(SecretBinary as Uint8Array);
|
|
31
|
-
const secret =
|
|
31
|
+
const secret = safeParser(decoded.toString('utf-8')) as T;
|
|
32
32
|
|
|
33
33
|
return {
|
|
34
34
|
secret,
|
package/src/services/aws/sqs.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DeleteMessageCommand, SQS } from '@aws-sdk/client-sqs';
|
|
2
2
|
|
|
3
3
|
import { AmazonSQS, IAmazonSQSService } from '../../interfaces';
|
|
4
|
-
import {
|
|
4
|
+
import { safeParser, safeStringify } from '../../utils';
|
|
5
5
|
|
|
6
6
|
class AmazonSQSService implements IAmazonSQSService {
|
|
7
7
|
async publishMessage ({ credentials, data }: AmazonSQS.PublishMessage.Request): Promise<void> {
|
|
@@ -16,7 +16,7 @@ class AmazonSQSService implements IAmazonSQSService {
|
|
|
16
16
|
const { QueueUrl } = await client.getQueueUrl({ QueueName: data.queue });
|
|
17
17
|
|
|
18
18
|
await client.sendMessage({
|
|
19
|
-
MessageBody:
|
|
19
|
+
MessageBody: safeStringify(data.message),
|
|
20
20
|
QueueUrl,
|
|
21
21
|
});
|
|
22
22
|
}
|
|
@@ -51,7 +51,7 @@ class AmazonSQSService implements IAmazonSQSService {
|
|
|
51
51
|
);
|
|
52
52
|
|
|
53
53
|
return {
|
|
54
|
-
message:
|
|
54
|
+
message: safeParser(message?.Body) as T,
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
57
|
|
|
@@ -92,7 +92,7 @@ class AmazonSQSService implements IAmazonSQSService {
|
|
|
92
92
|
);
|
|
93
93
|
|
|
94
94
|
return {
|
|
95
|
-
messages: Messages?.map((message) =>
|
|
95
|
+
messages: Messages?.map((message) => safeParser(message?.Body) as T),
|
|
96
96
|
};
|
|
97
97
|
}
|
|
98
98
|
|
|
@@ -2,7 +2,7 @@ import { DefaultAzureCredential } from '@azure/identity';
|
|
|
2
2
|
import { SecretClient } from '@azure/keyvault-secrets';
|
|
3
3
|
|
|
4
4
|
import { AzureKeyVault, IAzureKeyVaultService } from '../../interfaces';
|
|
5
|
-
import {
|
|
5
|
+
import { safeParser } from '../../utils/parser';
|
|
6
6
|
|
|
7
7
|
class AzureKeyVaultService implements IAzureKeyVaultService {
|
|
8
8
|
async getSecret<T> ({ data }: AzureKeyVault.GetSecret.Request): Promise<AzureKeyVault.GetSecret.Response<T>> {
|
|
@@ -12,7 +12,7 @@ class AzureKeyVaultService implements IAzureKeyVaultService {
|
|
|
12
12
|
const { value } = await client.getSecret(data.secretName);
|
|
13
13
|
|
|
14
14
|
if (value) {
|
|
15
|
-
const secret =
|
|
15
|
+
const secret = safeParser(value) as T;
|
|
16
16
|
return {
|
|
17
17
|
secret,
|
|
18
18
|
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ElasticAPM, IElasticAPMService } from '../interfaces';
|
|
2
|
+
|
|
3
|
+
class ElasticAPMService implements IElasticAPMService {
|
|
4
|
+
captureError (req: ElasticAPM.CaptureError.Request): Promise<void> {
|
|
5
|
+
throw new Error('Method not implemented.');
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export default new ElasticAPMService();
|
package/src/services/firebase.ts
CHANGED
|
@@ -8,15 +8,7 @@ class FirebaseService implements IFirebaseService {
|
|
|
8
8
|
data,
|
|
9
9
|
}: Firebase.PublishConfig.Request): Promise<void> {
|
|
10
10
|
const exists = FirebaseAdmin.apps?.find(app => app.name === credentials.instance) ?? undefined;
|
|
11
|
-
|
|
12
|
-
const client = exists ?? FirebaseAdmin.initializeApp({
|
|
13
|
-
credential: FirebaseAdmin.credential.cert({
|
|
14
|
-
projectId: credentials.project,
|
|
15
|
-
clientEmail: credentials.clientEmail,
|
|
16
|
-
privateKey: credentials.privateKey,
|
|
17
|
-
}),
|
|
18
|
-
databaseURL: credentials.database,
|
|
19
|
-
}, credentials.instance);
|
|
11
|
+
const client = exists ?? this.createClient(credentials);
|
|
20
12
|
|
|
21
13
|
const template = client
|
|
22
14
|
.remoteConfig()
|
|
@@ -34,15 +26,7 @@ class FirebaseService implements IFirebaseService {
|
|
|
34
26
|
data,
|
|
35
27
|
}: Firebase.SendNotification.Request): Promise<void> {
|
|
36
28
|
const exists = FirebaseAdmin.apps?.find(app => app.name === credentials.instance) ?? undefined;
|
|
37
|
-
|
|
38
|
-
const client = exists ?? FirebaseAdmin.initializeApp({
|
|
39
|
-
credential: FirebaseAdmin.credential.cert({
|
|
40
|
-
projectId: credentials.project,
|
|
41
|
-
clientEmail: credentials.clientEmail,
|
|
42
|
-
privateKey: credentials.privateKey,
|
|
43
|
-
}),
|
|
44
|
-
databaseURL: credentials.database,
|
|
45
|
-
}, credentials.instance);
|
|
29
|
+
const client = exists ?? this.createClient(credentials);
|
|
46
30
|
|
|
47
31
|
await client
|
|
48
32
|
.messaging()
|
|
@@ -56,15 +40,7 @@ class FirebaseService implements IFirebaseService {
|
|
|
56
40
|
data,
|
|
57
41
|
}: Firebase.SaveFirestore.Request<T>) {
|
|
58
42
|
const exists = FirebaseAdmin.apps?.find(app => app.name === credentials.instance) ?? undefined;
|
|
59
|
-
|
|
60
|
-
const client = exists ?? FirebaseAdmin.initializeApp({
|
|
61
|
-
credential: FirebaseAdmin.credential.cert({
|
|
62
|
-
projectId: credentials.project,
|
|
63
|
-
clientEmail: credentials.clientEmail,
|
|
64
|
-
privateKey: credentials.privateKey,
|
|
65
|
-
}),
|
|
66
|
-
databaseURL: credentials.database,
|
|
67
|
-
}, credentials.instance);
|
|
43
|
+
const client = exists ?? this.createClient(credentials);
|
|
68
44
|
|
|
69
45
|
await client
|
|
70
46
|
.firestore()
|
|
@@ -73,6 +49,25 @@ class FirebaseService implements IFirebaseService {
|
|
|
73
49
|
|
|
74
50
|
await client.delete();
|
|
75
51
|
}
|
|
52
|
+
|
|
53
|
+
private createClient (dto: {
|
|
54
|
+
project: string;
|
|
55
|
+
clientEmail: string;
|
|
56
|
+
privateKey: string;
|
|
57
|
+
database: string;
|
|
58
|
+
instance: string;
|
|
59
|
+
}) {
|
|
60
|
+
const client = FirebaseAdmin.initializeApp({
|
|
61
|
+
credential: FirebaseAdmin.credential.cert({
|
|
62
|
+
projectId: dto.project,
|
|
63
|
+
clientEmail: dto.clientEmail,
|
|
64
|
+
privateKey: dto.privateKey,
|
|
65
|
+
}),
|
|
66
|
+
databaseURL: dto.database,
|
|
67
|
+
}, dto.instance);
|
|
68
|
+
|
|
69
|
+
return client;
|
|
70
|
+
}
|
|
76
71
|
}
|
|
77
72
|
|
|
78
73
|
export default new FirebaseService();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SecretManagerServiceClient } from '@google-cloud/secret-manager';
|
|
2
2
|
|
|
3
3
|
import { GoogleSecrets, IGoogleSecretsService } from '../../interfaces';
|
|
4
|
-
import {
|
|
4
|
+
import { safeParser } from '../../utils/parser';
|
|
5
5
|
|
|
6
6
|
class GoogleSecretsService implements IGoogleSecretsService {
|
|
7
7
|
public async getSecret<T> ({
|
|
@@ -21,7 +21,7 @@ class GoogleSecretsService implements IGoogleSecretsService {
|
|
|
21
21
|
const secret = Buffer.from(buffer).toString('utf-8');
|
|
22
22
|
|
|
23
23
|
return {
|
|
24
|
-
secret:
|
|
24
|
+
secret: safeParser(secret) as T,
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
27
|
}
|
package/src/services/index.ts
CHANGED
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
AzureStorageBlobService,
|
|
15
15
|
} from './azure';
|
|
16
16
|
import DateService from './date';
|
|
17
|
+
import ElasticAPMService from './elastic-apm';
|
|
17
18
|
import FileService from './file';
|
|
18
19
|
import FirebaseService from './firebase';
|
|
19
20
|
import {
|
|
@@ -46,6 +47,7 @@ export {
|
|
|
46
47
|
AzureKeyVaultService,
|
|
47
48
|
AzureStorageBlobService,
|
|
48
49
|
DateService,
|
|
50
|
+
ElasticAPMService,
|
|
49
51
|
FileService,
|
|
50
52
|
FirebaseService,
|
|
51
53
|
GoogleAuthService,
|
package/src/services/kafka.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Kafka as KafkaClient } from 'kafkajs';
|
|
2
2
|
|
|
3
3
|
import { IKafkaService, Kafka } from '../interfaces';
|
|
4
|
-
import {
|
|
4
|
+
import { safeParser, safeStringify } from '../utils';
|
|
5
5
|
|
|
6
6
|
class KafkaService implements IKafkaService {
|
|
7
7
|
async publishMessage<T> ({
|
|
@@ -20,7 +20,7 @@ class KafkaService implements IKafkaService {
|
|
|
20
20
|
await producer.send({
|
|
21
21
|
topic: data.topic,
|
|
22
22
|
messages: data.messages.map(message => ({
|
|
23
|
-
value:
|
|
23
|
+
value: safeStringify(message),
|
|
24
24
|
})),
|
|
25
25
|
});
|
|
26
26
|
|
|
@@ -48,7 +48,7 @@ class KafkaService implements IKafkaService {
|
|
|
48
48
|
resolve(null);
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
const value: T =
|
|
51
|
+
const value: T = safeParser(message.value.toString()) as T;
|
|
52
52
|
|
|
53
53
|
resolve(value);
|
|
54
54
|
},
|
|
@@ -93,7 +93,7 @@ class KafkaService implements IKafkaService {
|
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
try {
|
|
96
|
-
const value: T =
|
|
96
|
+
const value: T = safeParser(message.value.toString()) as T;
|
|
97
97
|
|
|
98
98
|
messages.push(value as T);
|
|
99
99
|
|