@omegasolutions/vallora-log-sdk 1.0.0 → 1.2.0
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/README.md +30 -19
- package/dist/log-client.d.ts +2 -2
- package/dist/log-client.js +7 -3
- package/package.json +16 -6
package/README.md
CHANGED
|
@@ -1,29 +1,40 @@
|
|
|
1
1
|
# README #
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Este sdk será utilizado para importar nos projetos do vallora, com o objetivo de simplificar a interface com o serviço de logs https://bitbucket.org/omegasolutionssp/vallora-back-log-registry.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
No projeto acima do serviço de log, você encontra todas as especificações de payloads para integração com suas rotinas no backend.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
* Version
|
|
9
|
-
* [Learn Markdown](https://bitbucket.org/tutorials/markdowndemo)
|
|
7
|
+
### Como testar isoladamente ###
|
|
10
8
|
|
|
11
|
-
|
|
9
|
+
```bash
|
|
10
|
+
$ export GOOGLE_PROJECT_ID=omega-development-381223
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
* Dependencies
|
|
16
|
-
* Database configuration
|
|
17
|
-
* How to run tests
|
|
18
|
-
* Deployment instructions
|
|
12
|
+
#Solicite a criação de um arquivo de service account do Google para o Admin
|
|
13
|
+
$ export GOOGLE_APPLICATION_CREDENTIALS="/Users/user-local/omega-development-381223-e6f174c57cbb.json"
|
|
19
14
|
|
|
20
|
-
|
|
15
|
+
$ mkdir sdk-local-test
|
|
16
|
+
$ cd sdk-local-test
|
|
17
|
+
$ npm install @omegasolutions/vallora-log-sdk
|
|
21
18
|
|
|
22
|
-
|
|
23
|
-
* Code review
|
|
24
|
-
* Other guidelines
|
|
19
|
+
```
|
|
25
20
|
|
|
26
|
-
|
|
21
|
+
Crie uma classe de teste index.js
|
|
27
22
|
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
import { LogClient, ServiceType } from '@omegasolutions/vallora-log-sdk';
|
|
24
|
+
|
|
25
|
+
const logClient = new LogClient();
|
|
26
|
+
|
|
27
|
+
await logClient.publishLog({
|
|
28
|
+
idMessage: 'bbb2f9c2-8a92-4bc8-bf93-23b2b05c4999',
|
|
29
|
+
idUser: 'a4a2f9c9-8a92-4bc8-bf93-23b2b05c49a1', //uuid
|
|
30
|
+
idService: ServiceType.SEND_TO_PAYMENT,
|
|
31
|
+
inputPayload: { orderId: 456, amount: 200.5 },
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
Finalmente, execute:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
$ node index.js
|
|
39
|
+
|
|
40
|
+
```
|
package/dist/log-client.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { TransactionLogPayload } from './types';
|
|
2
2
|
export declare class LogClient {
|
|
3
3
|
private pubsub;
|
|
4
|
-
private topicName;
|
|
5
|
-
constructor(
|
|
4
|
+
private readonly topicName;
|
|
5
|
+
constructor();
|
|
6
6
|
/**
|
|
7
7
|
* Publishes a log message to the transaction-log-topic
|
|
8
8
|
*/
|
package/dist/log-client.js
CHANGED
|
@@ -4,9 +4,13 @@ exports.LogClient = void 0;
|
|
|
4
4
|
const pubsub_1 = require("@google-cloud/pubsub");
|
|
5
5
|
const uuid_1 = require("uuid");
|
|
6
6
|
class LogClient {
|
|
7
|
-
constructor(
|
|
7
|
+
constructor() {
|
|
8
|
+
this.topicName = process.env.TOPIC_LOGS_NAME || 'transaction-log-topic';
|
|
9
|
+
const projectId = process.env.GOOGLE_PROJECT_ID;
|
|
10
|
+
if (!projectId) {
|
|
11
|
+
throw new Error('Environment variable GOOGLE_PROJECT_ID is not defined. Please set it before using LogClient.');
|
|
12
|
+
}
|
|
8
13
|
this.pubsub = new pubsub_1.PubSub({ projectId });
|
|
9
|
-
this.topicName = topicName;
|
|
10
14
|
}
|
|
11
15
|
/**
|
|
12
16
|
* Publishes a log message to the transaction-log-topic
|
|
@@ -20,7 +24,7 @@ class LogClient {
|
|
|
20
24
|
};
|
|
21
25
|
const buffer = Buffer.from(JSON.stringify(message));
|
|
22
26
|
const messageId = await this.pubsub.topic(this.topicName).publish(buffer);
|
|
23
|
-
console.log(`Published message ${messageId} to ${this.topicName}`);
|
|
27
|
+
console.log(`Published message ${messageId} to topic "${this.topicName}" in project ${process.env.GOOGLE_PROJECT_ID}`);
|
|
24
28
|
return messageId;
|
|
25
29
|
}
|
|
26
30
|
}
|
package/package.json
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@omegasolutions/vallora-log-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "A lightweight SDK for publishing transaction log events to Google Pub/Sub",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
-
"files": [
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
8
10
|
"scripts": {
|
|
9
11
|
"build": "tsc",
|
|
10
12
|
"prepublishOnly": "npm run build"
|
|
11
13
|
},
|
|
12
|
-
"keywords": [
|
|
14
|
+
"keywords": [
|
|
15
|
+
"nestjs",
|
|
16
|
+
"pubsub",
|
|
17
|
+
"sdk",
|
|
18
|
+
"google-cloud",
|
|
19
|
+
"logging"
|
|
20
|
+
],
|
|
13
21
|
"author": "Your Name <rogerio.benetti@omegasolutions.com.br>",
|
|
14
22
|
"license": "MIT",
|
|
15
23
|
"repository": {
|
|
@@ -17,10 +25,12 @@
|
|
|
17
25
|
"url": "git clone https://rogeriobenetti@bitbucket.org/omegasolutionssp/vallora-back-log-registry-sdk.git"
|
|
18
26
|
},
|
|
19
27
|
"dependencies": {
|
|
20
|
-
"@google-cloud/pubsub": "^4.
|
|
21
|
-
"
|
|
28
|
+
"@google-cloud/pubsub": "^4.11.0",
|
|
29
|
+
"@omegasolutions/vallora-log-sdk": "^1.0.0",
|
|
30
|
+
"uuid": "^9.0.1"
|
|
22
31
|
},
|
|
23
32
|
"devDependencies": {
|
|
24
|
-
"
|
|
33
|
+
"@types/uuid": "^10.0.0",
|
|
34
|
+
"typescript": "^5.9.3"
|
|
25
35
|
}
|
|
26
36
|
}
|