zudello-integration-sdk 1.0.89 → 1.0.91
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/package.json +2 -1
- package/src/utils/config.js +33 -24
- package/src/utils/logger.js +62 -71
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zudello-integration-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.91",
|
|
4
4
|
"description": "Zudello Integrations SDK",
|
|
5
5
|
"main": "./src/index.js",
|
|
6
6
|
"repository": {
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
],
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"@aws-sdk/client-s3": "^3.658.0",
|
|
15
|
+
"@clickhouse/client": "^1.15.0",
|
|
15
16
|
"axios": "^1.6.7",
|
|
16
17
|
"circular-json": "^0.5.9",
|
|
17
18
|
"dotenv": "^16.4.5",
|
package/src/utils/config.js
CHANGED
|
@@ -27,32 +27,41 @@ module.exports = {
|
|
|
27
27
|
mam: 'acb7938a-06ba-4c6e-80e4-2bde7b0145a3',
|
|
28
28
|
sunsystems: ''
|
|
29
29
|
},
|
|
30
|
-
envs
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
30
|
+
get envs() {
|
|
31
|
+
return {
|
|
32
|
+
// TRIGGER ENVS
|
|
33
|
+
API_AUTH_TOKEN: process.env.API_AUTH_TOKEN,
|
|
34
|
+
API_VERSION: process.env.API_VERSION,
|
|
35
|
+
API_URL: process.env.API_URL,
|
|
36
|
+
EXTERNAL_API_URL: process.env.EXTERNAL_API_URL,
|
|
37
|
+
AUTH_API_URL: process.env.AUTH_API_URL,
|
|
38
|
+
ORGANIZATION_UUID: process.env.ORGANIZATION_UUID,
|
|
39
|
+
TEAM_UUID: process.env.TEAM_UUID,
|
|
40
|
+
TRIGGER_UUID: process.env.TRIGGER_UUID,
|
|
41
|
+
EXECUTION_UUID: process.env.EXECUTION_UUID,
|
|
42
|
+
MODE: process.env.MODE,
|
|
42
43
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
// GLOBAL ENVS
|
|
45
|
+
ZUDELLO_API_URL: process.env.ZUDELLO_API_URL,
|
|
46
|
+
PAUSE_PROCESS_EXIT_CODE: process.env.PAUSE_PROCESS_EXIT_CODE,
|
|
47
|
+
SKIP_SYNC: process.env.SKIP_SYNC,
|
|
47
48
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
// AWS ENVS
|
|
50
|
+
AWS_ACCESS_KEY_ID: process.env.AWS_ACCESS_KEY_ID,
|
|
51
|
+
AWS_SECRET_ACCESS_KEY: process.env.AWS_SECRET_ACCESS_KEY,
|
|
52
|
+
AWS_REGION: process.env.AWS_REGION,
|
|
53
|
+
AWS_BUCKET: process.env.AWS_BUCKET,
|
|
53
54
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
CONTEXT_DATA: process.env.CONTEXT_DATA,
|
|
56
|
+
GLOBAL_STATE: process.env.GLOBAL_STATE,
|
|
57
|
+
RESUME_PAYLOAD: process.env.RESUME_PAYLOAD,
|
|
58
|
+
|
|
59
|
+
// CLICKHOUSE ENVS
|
|
60
|
+
CLICKHOUSE_URL: process.env.CLICKHOUSE_URL,
|
|
61
|
+
CLICKHOUSE_USER: process.env.CLICKHOUSE_USER,
|
|
62
|
+
CLICKHOUSE_PASSWORD: process.env.CLICKHOUSE_PASSWORD,
|
|
63
|
+
CLICKHOUSE_DATABASE: process.env.CLICKHOUSE_DATABASE,
|
|
64
|
+
CLICKHOUSE_LOGS_TABLE: process.env.CLICKHOUSE_LOGS_TABLE
|
|
65
|
+
}
|
|
57
66
|
}
|
|
58
67
|
}
|
package/src/utils/logger.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const config = require('./config')
|
|
4
|
-
const
|
|
5
|
-
const { appendJsonArray } = require('./s3Client')
|
|
4
|
+
const { createClient } = require('@clickhouse/client')
|
|
6
5
|
|
|
7
6
|
class Logger {
|
|
8
7
|
/**
|
|
@@ -11,10 +10,17 @@ class Logger {
|
|
|
11
10
|
constructor() {
|
|
12
11
|
this.mode = config.envs.MODE || 'PRODUCTION'
|
|
13
12
|
this.productionMode = 'PRODUCTION'
|
|
14
|
-
this.logs = []
|
|
15
|
-
this._synced = false
|
|
16
13
|
|
|
17
|
-
this.
|
|
14
|
+
if (this.mode === this.productionMode) {
|
|
15
|
+
this.clickhouse = createClient({
|
|
16
|
+
url: config.envs.CLICKHOUSE_URL,
|
|
17
|
+
username: config.envs.CLICKHOUSE_USER,
|
|
18
|
+
password: config.envs.CLICKHOUSE_PASSWORD,
|
|
19
|
+
database: config.envs.CLICKHOUSE_DATABASE,
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
this.tableName = config.envs.CLICKHOUSE_LOGS_TABLE
|
|
23
|
+
}
|
|
18
24
|
}
|
|
19
25
|
|
|
20
26
|
static init() {
|
|
@@ -25,21 +31,43 @@ class Logger {
|
|
|
25
31
|
return Logger._instance
|
|
26
32
|
}
|
|
27
33
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Output log to console (development mode).
|
|
36
|
+
*/
|
|
37
|
+
_consoleLog(status, title, content) {
|
|
38
|
+
if (content instanceof Error) {
|
|
39
|
+
console.log(`[${status.toUpperCase()}] ${title}:`)
|
|
40
|
+
console.error(content.stack)
|
|
41
|
+
} else if (Array.isArray(content) || (typeof content === 'object' && content !== null)) {
|
|
42
|
+
console.log(`[${status.toUpperCase()}] ${title}:`)
|
|
43
|
+
console.log(JSON.stringify(content, null, 2))
|
|
44
|
+
} else {
|
|
45
|
+
console.log(`[${status.toUpperCase()}] ${title}: ${content}`)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
33
48
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
49
|
+
/**
|
|
50
|
+
* Store log entry in ClickHouse.
|
|
51
|
+
*/
|
|
52
|
+
async _storeInClickHouse(status, title, content) {
|
|
53
|
+
try {
|
|
54
|
+
const logEntry = {
|
|
55
|
+
timestamp: new Date(),
|
|
56
|
+
execution_uuid: config.envs.EXECUTION_UUID,
|
|
57
|
+
status,
|
|
58
|
+
title,
|
|
59
|
+
content: typeof content === 'string' ? content : JSON.stringify(content),
|
|
39
60
|
}
|
|
40
|
-
}
|
|
41
61
|
|
|
42
|
-
|
|
62
|
+
await this.clickhouse.insert({
|
|
63
|
+
table: this.tableName,
|
|
64
|
+
values: [logEntry],
|
|
65
|
+
format: 'JSONEachRow',
|
|
66
|
+
})
|
|
67
|
+
} catch (err) {
|
|
68
|
+
console.error('Failed to store log in ClickHouse:', err.message)
|
|
69
|
+
console.log(`[${status.toUpperCase()}] ${title}:`, content)
|
|
70
|
+
}
|
|
43
71
|
}
|
|
44
72
|
|
|
45
73
|
/**
|
|
@@ -48,7 +76,7 @@ class Logger {
|
|
|
48
76
|
* @param {string} title - The title or summary of the log.
|
|
49
77
|
* @param {any} content - The detailed content of the log.
|
|
50
78
|
*/
|
|
51
|
-
_log(status, title, content) {
|
|
79
|
+
async _log(status, title, content) {
|
|
52
80
|
let formattedContent = content
|
|
53
81
|
|
|
54
82
|
// If content is an Error (exception), format it into an object
|
|
@@ -60,22 +88,10 @@ class Logger {
|
|
|
60
88
|
}
|
|
61
89
|
}
|
|
62
90
|
|
|
63
|
-
// Create the log entry object
|
|
64
|
-
const logEntry = { status, title, content: formattedContent }
|
|
65
|
-
|
|
66
91
|
if (this.mode === this.productionMode) {
|
|
67
|
-
this.
|
|
92
|
+
await this._storeInClickHouse(status, title, formattedContent)
|
|
68
93
|
} else {
|
|
69
|
-
|
|
70
|
-
if (content instanceof Error) {
|
|
71
|
-
console.log(`[${status.toUpperCase()}] ${title}:`)
|
|
72
|
-
console.error(content.stack)
|
|
73
|
-
} else if (Array.isArray(content) || (typeof content === 'object' && content !== null)) {
|
|
74
|
-
console.log(`[${status.toUpperCase()}] ${title}:`)
|
|
75
|
-
console.log(JSON.stringify(content, null, 2))
|
|
76
|
-
} else {
|
|
77
|
-
console.log(`[${status.toUpperCase()}] ${title}: ${content}`)
|
|
78
|
-
}
|
|
94
|
+
this._consoleLog(status, title, content)
|
|
79
95
|
}
|
|
80
96
|
}
|
|
81
97
|
|
|
@@ -84,8 +100,8 @@ class Logger {
|
|
|
84
100
|
* @param {string} title
|
|
85
101
|
* @param {any} content
|
|
86
102
|
*/
|
|
87
|
-
warn(title, content) {
|
|
88
|
-
this._log('warn', title, content)
|
|
103
|
+
async warn(title, content) {
|
|
104
|
+
await this._log('warn', title, content)
|
|
89
105
|
}
|
|
90
106
|
|
|
91
107
|
/**
|
|
@@ -93,8 +109,8 @@ class Logger {
|
|
|
93
109
|
* @param {string} title
|
|
94
110
|
* @param {any} content
|
|
95
111
|
*/
|
|
96
|
-
info(title, content) {
|
|
97
|
-
this._log('info', title, content)
|
|
112
|
+
async info(title, content) {
|
|
113
|
+
await this._log('info', title, content)
|
|
98
114
|
}
|
|
99
115
|
|
|
100
116
|
/**
|
|
@@ -102,8 +118,8 @@ class Logger {
|
|
|
102
118
|
* @param {string} title
|
|
103
119
|
* @param {any} content
|
|
104
120
|
*/
|
|
105
|
-
debug(title, content) {
|
|
106
|
-
this._log('debug', title, content)
|
|
121
|
+
async debug(title, content) {
|
|
122
|
+
await this._log('debug', title, content)
|
|
107
123
|
}
|
|
108
124
|
|
|
109
125
|
/**
|
|
@@ -111,8 +127,8 @@ class Logger {
|
|
|
111
127
|
* @param {string} title
|
|
112
128
|
* @param {any} content
|
|
113
129
|
*/
|
|
114
|
-
log(content, title = 'Script Log') {
|
|
115
|
-
this._log('log', title, content)
|
|
130
|
+
async log(content, title = 'Script Log') {
|
|
131
|
+
await this._log('log', title, content)
|
|
116
132
|
}
|
|
117
133
|
|
|
118
134
|
/**
|
|
@@ -120,8 +136,8 @@ class Logger {
|
|
|
120
136
|
* @param {string} title
|
|
121
137
|
* @param {any} content
|
|
122
138
|
*/
|
|
123
|
-
error(title, content) {
|
|
124
|
-
this._log('error', title, content)
|
|
139
|
+
async error(title, content) {
|
|
140
|
+
await this._log('error', title, content)
|
|
125
141
|
}
|
|
126
142
|
|
|
127
143
|
/**
|
|
@@ -129,8 +145,8 @@ class Logger {
|
|
|
129
145
|
* @param {string} title
|
|
130
146
|
* @param {any} content
|
|
131
147
|
*/
|
|
132
|
-
success(title, content) {
|
|
133
|
-
this._log('success', title, content)
|
|
148
|
+
async success(title, content) {
|
|
149
|
+
await this._log('success', title, content)
|
|
134
150
|
}
|
|
135
151
|
|
|
136
152
|
/**
|
|
@@ -138,33 +154,8 @@ class Logger {
|
|
|
138
154
|
* @param {string} title
|
|
139
155
|
* @param {any} content
|
|
140
156
|
*/
|
|
141
|
-
request(title, content) {
|
|
142
|
-
this._log('request', title, content)
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Retrieve all logs.
|
|
147
|
-
* @return {Array} Array of log objects.
|
|
148
|
-
*/
|
|
149
|
-
getLogs() {
|
|
150
|
-
return this.logs
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Logs setter.
|
|
155
|
-
* @param {array} logs Array of log objects
|
|
156
|
-
*/
|
|
157
|
-
setLogs(logs = []) {
|
|
158
|
-
this.logs = logs
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
async sync() {
|
|
162
|
-
if (this._synced || config.envs.SKIP_SYNC) {
|
|
163
|
-
return
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
const globalStateClass = GlobalState.init()
|
|
167
|
-
await appendJsonArray(config.envs.AWS_BUCKET, globalStateClass.globalState.logFilePath, this.getLogs())
|
|
157
|
+
async request(title, content) {
|
|
158
|
+
await this._log('request', title, content)
|
|
168
159
|
}
|
|
169
160
|
}
|
|
170
161
|
|