@heyhru/business-dms-approval 0.7.0 → 0.7.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/dist/approvals.model.d.ts +1 -1
- package/dist/approvals.model.d.ts.map +1 -1
- package/dist/approvals.sql.d.ts +1 -1
- package/dist/approvals.sql.d.ts.map +1 -1
- package/dist/index.js +15 -13
- package/dist/index.mjs +16 -14
- package/package.json +2 -2
|
@@ -3,7 +3,7 @@ export declare function listApprovals(filters?: {
|
|
|
3
3
|
submittedBy?: string;
|
|
4
4
|
}): Promise<Record<string, unknown>[]>;
|
|
5
5
|
export declare function getApprovalById(id: string): Promise<Record<string, unknown> | undefined>;
|
|
6
|
-
export declare function insertApproval(dataSourceId: string, sqlText: string, submittedBy: string): Promise<Record<string, unknown> | undefined>;
|
|
6
|
+
export declare function insertApproval(dataSourceId: string, dbName: string | null, sqlText: string, submittedBy: string): Promise<Record<string, unknown> | undefined>;
|
|
7
7
|
export declare function updateReview(id: string, status: string, reviewedBy: string, rejectReason: string | null): Promise<Record<string, unknown> | undefined>;
|
|
8
8
|
export declare function setExecuting(id: string): Promise<{
|
|
9
9
|
changes: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"approvals.model.d.ts","sourceRoot":"","sources":["../src/approvals.model.ts"],"names":[],"mappings":"AAGA,wBAAsB,aAAa,CAAC,OAAO,CAAC,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,sCAgBtF;AAED,wBAAgB,eAAe,CAAC,EAAE,EAAE,MAAM,gDAEzC;AAED,wBAAgB,cAAc,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"approvals.model.d.ts","sourceRoot":"","sources":["../src/approvals.model.ts"],"names":[],"mappings":"AAGA,wBAAsB,aAAa,CAAC,OAAO,CAAC,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,sCAgBtF;AAED,wBAAgB,eAAe,CAAC,EAAE,EAAE,MAAM,gDAEzC;AAED,wBAAgB,cAAc,CAAC,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,gDAE/G;AAED,wBAAgB,YAAY,CAC1B,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,MAAM,GAAG,IAAI,gDAG5B;AAED,wBAAgB,YAAY,CAAC,EAAE,EAAE,MAAM;;GAEtC;AAED,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;;GAE1E"}
|
package/dist/approvals.sql.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare const FIND_BY_ID = "\nSELECT *\nFROM approvals\nWHERE id = ?";
|
|
2
|
-
export declare const CREATE = "\nINSERT INTO approvals (data_source_id, sql_text, submitted_by)\nVALUES (?, ?, ?)\nRETURNING *";
|
|
2
|
+
export declare const CREATE = "\nINSERT INTO approvals (data_source_id, db_name, sql_text, submitted_by)\nVALUES (?, ?, ?, ?)\nRETURNING *";
|
|
3
3
|
export declare const UPDATE_REVIEW: () => string;
|
|
4
4
|
export declare const UPDATE_EXECUTING: () => string;
|
|
5
5
|
export declare const UPDATE_RESULT: () => string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"approvals.sql.d.ts","sourceRoot":"","sources":["../src/approvals.sql.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,6CAGV,CAAC;AAEd,eAAO,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"approvals.sql.d.ts","sourceRoot":"","sources":["../src/approvals.sql.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,6CAGV,CAAC;AAEd,eAAO,MAAM,MAAM,gHAGP,CAAC;AAEb,eAAO,MAAM,aAAa,cAId,CAAC;AAEb,eAAO,MAAM,gBAAgB,cAGhB,CAAC;AAEd,eAAO,MAAM,aAAa,cAGb,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -42,8 +42,8 @@ SELECT *
|
|
|
42
42
|
FROM approvals
|
|
43
43
|
WHERE id = ?`;
|
|
44
44
|
var CREATE = `
|
|
45
|
-
INSERT INTO approvals (data_source_id, sql_text, submitted_by)
|
|
46
|
-
VALUES (?, ?, ?)
|
|
45
|
+
INSERT INTO approvals (data_source_id, db_name, sql_text, submitted_by)
|
|
46
|
+
VALUES (?, ?, ?, ?)
|
|
47
47
|
RETURNING *`;
|
|
48
48
|
var UPDATE_REVIEW = () => `
|
|
49
49
|
UPDATE approvals
|
|
@@ -80,8 +80,8 @@ WHERE 1=1`;
|
|
|
80
80
|
function getApprovalById(id) {
|
|
81
81
|
return (0, import_server_plugin_pg.getPgDb)().queryOne(FIND_BY_ID, [id]);
|
|
82
82
|
}
|
|
83
|
-
function insertApproval(dataSourceId, sqlText, submittedBy) {
|
|
84
|
-
return (0, import_server_plugin_pg.getPgDb)().queryOne(CREATE, [dataSourceId, sqlText, submittedBy]);
|
|
83
|
+
function insertApproval(dataSourceId, dbName, sqlText, submittedBy) {
|
|
84
|
+
return (0, import_server_plugin_pg.getPgDb)().queryOne(CREATE, [dataSourceId, dbName, sqlText, submittedBy]);
|
|
85
85
|
}
|
|
86
86
|
function updateReview(id, status, reviewedBy, rejectReason) {
|
|
87
87
|
return (0, import_server_plugin_pg.getPgDb)().queryOne(UPDATE_REVIEW(), [status, reviewedBy, rejectReason, id]);
|
|
@@ -110,11 +110,11 @@ async function approvalGet(req, reply) {
|
|
|
110
110
|
return reply.send(approval);
|
|
111
111
|
}
|
|
112
112
|
async function approvalCreate(req, reply) {
|
|
113
|
-
const { dataSourceId, sql } = req.body ?? {};
|
|
113
|
+
const { dataSourceId, database, sql } = req.body ?? {};
|
|
114
114
|
if (!dataSourceId || !sql) {
|
|
115
115
|
return reply.code(400).send({ error: "Data source ID and SQL are required" });
|
|
116
116
|
}
|
|
117
|
-
const approval = await insertApproval(dataSourceId, sql, req.user.id);
|
|
117
|
+
const approval = await insertApproval(dataSourceId, database ?? null, sql, req.user.id);
|
|
118
118
|
req.log.info("Approval submitted (user=%s)", req.user.id);
|
|
119
119
|
return reply.code(201).send(approval);
|
|
120
120
|
}
|
|
@@ -170,19 +170,21 @@ async function doExecuteApproval({ id, userId, ip, encryptionKey }, log) {
|
|
|
170
170
|
}
|
|
171
171
|
await setExecuting(id);
|
|
172
172
|
try {
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
173
|
+
const dataSourceId = approval["data_source_id"];
|
|
174
|
+
const dbName = approval["db_name"];
|
|
175
|
+
const pool = dbName ? await (0, import_business_dms_datasource.getPoolForDatabase)(dataSourceId, dbName, encryptionKey) : await (async () => {
|
|
176
|
+
const ds = await (0, import_business_dms_datasource.getDataSourceWithPassword)(dataSourceId, encryptionKey);
|
|
177
|
+
if (!ds) throw new Error("Data source not found");
|
|
178
|
+
return (0, import_business_dms_datasource.getPool)({ ...ds, database: ds.database ?? "" });
|
|
179
|
+
})();
|
|
180
|
+
if (!pool) throw new Error("Data source not found");
|
|
179
181
|
const rows = await pool.execute(approval["sql_text"]);
|
|
180
182
|
const result = `${rows.length} rows affected`;
|
|
181
183
|
await setExecuteResult(id, "executed", result);
|
|
182
184
|
log.info("Approval executed (id=%s, user=%s)", id, userId);
|
|
183
185
|
await (0, import_business_dms_audit.writeAuditLog)({
|
|
184
186
|
userId,
|
|
185
|
-
dataSourceId
|
|
187
|
+
dataSourceId,
|
|
186
188
|
action: "DML_EXECUTE",
|
|
187
189
|
sqlText: approval["sql_text"],
|
|
188
190
|
resultSummary: result,
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/approvals.service.ts
|
|
2
|
-
import { getDataSourceWithPassword, getPool } from "@heyhru/business-dms-datasource";
|
|
2
|
+
import { getDataSourceWithPassword, getPool, getPoolForDatabase } from "@heyhru/business-dms-datasource";
|
|
3
3
|
import { writeAuditLog } from "@heyhru/business-dms-audit";
|
|
4
4
|
|
|
5
5
|
// src/approvals.model.ts
|
|
@@ -11,8 +11,8 @@ SELECT *
|
|
|
11
11
|
FROM approvals
|
|
12
12
|
WHERE id = ?`;
|
|
13
13
|
var CREATE = `
|
|
14
|
-
INSERT INTO approvals (data_source_id, sql_text, submitted_by)
|
|
15
|
-
VALUES (?, ?, ?)
|
|
14
|
+
INSERT INTO approvals (data_source_id, db_name, sql_text, submitted_by)
|
|
15
|
+
VALUES (?, ?, ?, ?)
|
|
16
16
|
RETURNING *`;
|
|
17
17
|
var UPDATE_REVIEW = () => `
|
|
18
18
|
UPDATE approvals
|
|
@@ -49,8 +49,8 @@ WHERE 1=1`;
|
|
|
49
49
|
function getApprovalById(id) {
|
|
50
50
|
return getPgDb().queryOne(FIND_BY_ID, [id]);
|
|
51
51
|
}
|
|
52
|
-
function insertApproval(dataSourceId, sqlText, submittedBy) {
|
|
53
|
-
return getPgDb().queryOne(CREATE, [dataSourceId, sqlText, submittedBy]);
|
|
52
|
+
function insertApproval(dataSourceId, dbName, sqlText, submittedBy) {
|
|
53
|
+
return getPgDb().queryOne(CREATE, [dataSourceId, dbName, sqlText, submittedBy]);
|
|
54
54
|
}
|
|
55
55
|
function updateReview(id, status, reviewedBy, rejectReason) {
|
|
56
56
|
return getPgDb().queryOne(UPDATE_REVIEW(), [status, reviewedBy, rejectReason, id]);
|
|
@@ -79,11 +79,11 @@ async function approvalGet(req, reply) {
|
|
|
79
79
|
return reply.send(approval);
|
|
80
80
|
}
|
|
81
81
|
async function approvalCreate(req, reply) {
|
|
82
|
-
const { dataSourceId, sql } = req.body ?? {};
|
|
82
|
+
const { dataSourceId, database, sql } = req.body ?? {};
|
|
83
83
|
if (!dataSourceId || !sql) {
|
|
84
84
|
return reply.code(400).send({ error: "Data source ID and SQL are required" });
|
|
85
85
|
}
|
|
86
|
-
const approval = await insertApproval(dataSourceId, sql, req.user.id);
|
|
86
|
+
const approval = await insertApproval(dataSourceId, database ?? null, sql, req.user.id);
|
|
87
87
|
req.log.info("Approval submitted (user=%s)", req.user.id);
|
|
88
88
|
return reply.code(201).send(approval);
|
|
89
89
|
}
|
|
@@ -139,19 +139,21 @@ async function doExecuteApproval({ id, userId, ip, encryptionKey }, log) {
|
|
|
139
139
|
}
|
|
140
140
|
await setExecuting(id);
|
|
141
141
|
try {
|
|
142
|
-
const
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
142
|
+
const dataSourceId = approval["data_source_id"];
|
|
143
|
+
const dbName = approval["db_name"];
|
|
144
|
+
const pool = dbName ? await getPoolForDatabase(dataSourceId, dbName, encryptionKey) : await (async () => {
|
|
145
|
+
const ds = await getDataSourceWithPassword(dataSourceId, encryptionKey);
|
|
146
|
+
if (!ds) throw new Error("Data source not found");
|
|
147
|
+
return getPool({ ...ds, database: ds.database ?? "" });
|
|
148
|
+
})();
|
|
149
|
+
if (!pool) throw new Error("Data source not found");
|
|
148
150
|
const rows = await pool.execute(approval["sql_text"]);
|
|
149
151
|
const result = `${rows.length} rows affected`;
|
|
150
152
|
await setExecuteResult(id, "executed", result);
|
|
151
153
|
log.info("Approval executed (id=%s, user=%s)", id, userId);
|
|
152
154
|
await writeAuditLog({
|
|
153
155
|
userId,
|
|
154
|
-
dataSourceId
|
|
156
|
+
dataSourceId,
|
|
155
157
|
action: "DML_EXECUTE",
|
|
156
158
|
sqlText: approval["sql_text"],
|
|
157
159
|
resultSummary: result,
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "0.7.
|
|
6
|
+
"version": "0.7.1",
|
|
7
7
|
"description": "DMS approval workflow domain logic: service, model, sql",
|
|
8
8
|
"main": "./dist/index.js",
|
|
9
9
|
"module": "./dist/index.mjs",
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"typescript": "^6.0.2",
|
|
37
37
|
"vitest": "^4.1.4"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "6bd2092d7f1dd2bc23d5252e2be4136792ddec4f"
|
|
40
40
|
}
|