@zintrust/client-rds-data 0.1.22
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/index.d.ts +15 -0
- package/dist/index.js +91 -0
- package/package.json +34 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type RdsDataClient = {
|
|
2
|
+
executeStatement: (input: unknown) => Promise<unknown>;
|
|
3
|
+
};
|
|
4
|
+
export type SecretsManagerClient = {
|
|
5
|
+
getSecretValue: (secretName: string) => Promise<{
|
|
6
|
+
SecretString?: string;
|
|
7
|
+
}>;
|
|
8
|
+
};
|
|
9
|
+
export declare function getRdsDataClient(region?: string): Promise<RdsDataClient>;
|
|
10
|
+
export declare function getSecretsManagerClient(region?: string): Promise<SecretsManagerClient>;
|
|
11
|
+
declare const _default: Readonly<{
|
|
12
|
+
getRdsDataClient: typeof getRdsDataClient;
|
|
13
|
+
getSecretsManagerClient: typeof getSecretsManagerClient;
|
|
14
|
+
}>;
|
|
15
|
+
export default _default;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { ErrorFactory } from '@zintrust/core';
|
|
2
|
+
function getErrorCode(error) {
|
|
3
|
+
if (typeof error === 'object' &&
|
|
4
|
+
error !== null &&
|
|
5
|
+
typeof error.code === 'string') {
|
|
6
|
+
return error.code;
|
|
7
|
+
}
|
|
8
|
+
if (typeof error === 'object' &&
|
|
9
|
+
error !== null &&
|
|
10
|
+
typeof error.cause === 'object' &&
|
|
11
|
+
error.cause !== null &&
|
|
12
|
+
typeof error.cause.code === 'string') {
|
|
13
|
+
return error.cause.code;
|
|
14
|
+
}
|
|
15
|
+
return '';
|
|
16
|
+
}
|
|
17
|
+
function getErrorMessage(error) {
|
|
18
|
+
if (typeof error === 'object' &&
|
|
19
|
+
error !== null &&
|
|
20
|
+
typeof error.message === 'string') {
|
|
21
|
+
return error.message;
|
|
22
|
+
}
|
|
23
|
+
if (typeof error === 'object' &&
|
|
24
|
+
error !== null &&
|
|
25
|
+
typeof error.cause === 'object' &&
|
|
26
|
+
error.cause !== null &&
|
|
27
|
+
typeof error.cause.message ===
|
|
28
|
+
'string') {
|
|
29
|
+
return error.cause.message;
|
|
30
|
+
}
|
|
31
|
+
return '';
|
|
32
|
+
}
|
|
33
|
+
function isMissingEsmPackage(error, packageName) {
|
|
34
|
+
if (typeof error !== 'object' || error === null)
|
|
35
|
+
return false;
|
|
36
|
+
const code = getErrorCode(error);
|
|
37
|
+
const message = getErrorMessage(error);
|
|
38
|
+
if (code === 'ERR_MODULE_NOT_FOUND')
|
|
39
|
+
return true;
|
|
40
|
+
if (message.includes(packageName))
|
|
41
|
+
return true;
|
|
42
|
+
if (message.includes(`Cannot find package '${packageName}'`))
|
|
43
|
+
return true;
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
async function importRdsDataModule() {
|
|
47
|
+
const specifier = '@aws-sdk/client-rds-data';
|
|
48
|
+
return (await import(specifier));
|
|
49
|
+
}
|
|
50
|
+
async function importSecretsManagerModule() {
|
|
51
|
+
const specifier = '@aws-sdk/client-secrets-manager';
|
|
52
|
+
return (await import(specifier));
|
|
53
|
+
}
|
|
54
|
+
export async function getRdsDataClient(region) {
|
|
55
|
+
try {
|
|
56
|
+
const mod = await importRdsDataModule();
|
|
57
|
+
const client = new mod.RDSDataClient({ region });
|
|
58
|
+
return {
|
|
59
|
+
executeStatement: async (input) => client.send(new mod.ExecuteStatementCommand(input)),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
if (isMissingEsmPackage(error, '@aws-sdk/client-rds-data')) {
|
|
64
|
+
throw ErrorFactory.createConfigError("RDS Data API requires '@aws-sdk/client-rds-data' (install and configure AWS credentials).");
|
|
65
|
+
}
|
|
66
|
+
throw ErrorFactory.createTryCatchError('Failed to initialize RDS Data API client', {
|
|
67
|
+
cause: error,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
export async function getSecretsManagerClient(region) {
|
|
72
|
+
try {
|
|
73
|
+
const mod = await importSecretsManagerModule();
|
|
74
|
+
const client = new mod.SecretsManagerClient({ region });
|
|
75
|
+
return {
|
|
76
|
+
getSecretValue: async (secretName) => (await client.send(new mod.GetSecretValueCommand({ SecretId: secretName }))),
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
if (isMissingEsmPackage(error, '@aws-sdk/client-secrets-manager')) {
|
|
81
|
+
throw ErrorFactory.createConfigError("Secrets Manager requires '@aws-sdk/client-secrets-manager' (install and configure AWS credentials).");
|
|
82
|
+
}
|
|
83
|
+
throw ErrorFactory.createTryCatchError('Failed to initialize Secrets Manager client', {
|
|
84
|
+
cause: error,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
export default Object.freeze({
|
|
89
|
+
getRdsDataClient,
|
|
90
|
+
getSecretsManagerClient,
|
|
91
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@zintrust/client-rds-data",
|
|
3
|
+
"version": "0.1.22",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"default": "./dist/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=20.0.0"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@aws-sdk/client-rds-data": "^3.500.0",
|
|
22
|
+
"@aws-sdk/client-secrets-manager": "^3.500.0"
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"@zintrust/core": "^0.1.22"
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "tsc -p tsconfig.json",
|
|
32
|
+
"prepublishOnly": "npm run build"
|
|
33
|
+
}
|
|
34
|
+
}
|