@dsmrt/axiom-aws-sdk 0.0.10 → 0.1.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/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ # @dsmrt/axiom-aws-sdk
2
+
3
+ ## 0.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - c3ffa47: Updating build and publishing tools to use tsup for esm support and @changesets/cli
8
+
9
+ ### Patch Changes
10
+
11
+ - 533b167: trying to figure out changeset
@@ -0,0 +1,29 @@
1
+ import { SSMClient, Parameter } from '@aws-sdk/client-ssm';
2
+
3
+ declare const ssmClient: SSMClient;
4
+ declare const getParametersByPath: (path: string, parameters?: Parameter[], nextToken?: string, client?: SSMClient) => Promise<Parameter[]>;
5
+ declare const getParameters: (names: string[], client?: SSMClient) => Promise<Parameter[]>;
6
+ /**
7
+ * Extract a single parameter from an array of params (typically from params by path)
8
+ *
9
+ * @param name
10
+ * @param params
11
+ */
12
+ declare const extractParamValue: (path: string, name: string, params: Parameter[]) => string;
13
+
14
+ type Params = {
15
+ [key: string]: Parameter;
16
+ };
17
+ declare class ParameterCollection<TParams extends Params> {
18
+ readonly path: string;
19
+ private readonly client?;
20
+ readonly map: Map<keyof TParams, Parameter>;
21
+ constructor(path: string, client?: SSMClient | undefined);
22
+ hasParam(param: keyof TParams): Promise<boolean>;
23
+ findParam(param: keyof TParams): Promise<Parameter | undefined>;
24
+ getParam(param: keyof TParams): Promise<Parameter>;
25
+ get(): Promise<Map<keyof TParams, Parameter>>;
26
+ private loadParameters;
27
+ }
28
+
29
+ export { ParameterCollection, type Params, extractParamValue, getParameters, getParametersByPath, ssmClient };
@@ -0,0 +1,29 @@
1
+ import { SSMClient, Parameter } from '@aws-sdk/client-ssm';
2
+
3
+ declare const ssmClient: SSMClient;
4
+ declare const getParametersByPath: (path: string, parameters?: Parameter[], nextToken?: string, client?: SSMClient) => Promise<Parameter[]>;
5
+ declare const getParameters: (names: string[], client?: SSMClient) => Promise<Parameter[]>;
6
+ /**
7
+ * Extract a single parameter from an array of params (typically from params by path)
8
+ *
9
+ * @param name
10
+ * @param params
11
+ */
12
+ declare const extractParamValue: (path: string, name: string, params: Parameter[]) => string;
13
+
14
+ type Params = {
15
+ [key: string]: Parameter;
16
+ };
17
+ declare class ParameterCollection<TParams extends Params> {
18
+ readonly path: string;
19
+ private readonly client?;
20
+ readonly map: Map<keyof TParams, Parameter>;
21
+ constructor(path: string, client?: SSMClient | undefined);
22
+ hasParam(param: keyof TParams): Promise<boolean>;
23
+ findParam(param: keyof TParams): Promise<Parameter | undefined>;
24
+ getParam(param: keyof TParams): Promise<Parameter>;
25
+ get(): Promise<Map<keyof TParams, Parameter>>;
26
+ private loadParameters;
27
+ }
28
+
29
+ export { ParameterCollection, type Params, extractParamValue, getParameters, getParametersByPath, ssmClient };
package/dist/index.js ADDED
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ ParameterCollection: () => ParameterCollection,
24
+ extractParamValue: () => extractParamValue,
25
+ getParameters: () => getParameters,
26
+ getParametersByPath: () => getParametersByPath,
27
+ ssmClient: () => ssmClient
28
+ });
29
+ module.exports = __toCommonJS(src_exports);
30
+
31
+ // src/ssm-parameters.ts
32
+ var import_client_ssm = require("@aws-sdk/client-ssm");
33
+ var ssmClient = new import_client_ssm.SSMClient({});
34
+ var getParametersByPath = async (path, parameters, nextToken, client) => {
35
+ client ??= ssmClient;
36
+ let returnParams = parameters || [];
37
+ const command = new import_client_ssm.GetParametersByPathCommand({
38
+ Path: path,
39
+ Recursive: true,
40
+ WithDecryption: true,
41
+ NextToken: nextToken
42
+ });
43
+ const output = await client.send(command);
44
+ if (output.Parameters !== void 0) {
45
+ returnParams = [...returnParams, ...output.Parameters];
46
+ }
47
+ if (output.NextToken !== void 0) {
48
+ return getParametersByPath(path, returnParams, output.NextToken, client);
49
+ }
50
+ return returnParams;
51
+ };
52
+ var getParameters = async (names, client) => {
53
+ client ??= ssmClient;
54
+ const command = new import_client_ssm.GetParametersCommand({
55
+ Names: names,
56
+ WithDecryption: true
57
+ });
58
+ const result = await client.send(command);
59
+ if (result.Parameters === void 0) {
60
+ return [];
61
+ }
62
+ return result.Parameters;
63
+ };
64
+ var extractParamValue = (path, name, params) => {
65
+ const fullName = `${path.replace(/\/$/, "")}/${name}`;
66
+ const item = params.find((item2) => item2.Name === fullName);
67
+ if (!item || !item.Value) {
68
+ throw new Error(`Parameter '${fullName}' is not set.`);
69
+ }
70
+ return item.Value;
71
+ };
72
+
73
+ // src/ssm-parameter-collection.ts
74
+ var ParameterCollection = class {
75
+ constructor(path, client) {
76
+ this.path = path;
77
+ this.client = client;
78
+ }
79
+ map = /* @__PURE__ */ new Map();
80
+ async hasParam(param) {
81
+ if (this.map.size < 1) {
82
+ await this.loadParameters();
83
+ }
84
+ return this.map.has(param);
85
+ }
86
+ async findParam(param) {
87
+ if (this.map.size < 1) {
88
+ await this.loadParameters();
89
+ }
90
+ return this.map.get(param);
91
+ }
92
+ async getParam(param) {
93
+ if (!await this.hasParam(param)) {
94
+ throw new Error(`Parameter '${param.toString()}' does not exist'`);
95
+ }
96
+ return this.map.get(param);
97
+ }
98
+ async get() {
99
+ if (this.map.size < 1) {
100
+ await this.loadParameters();
101
+ }
102
+ return this.map;
103
+ }
104
+ async loadParameters() {
105
+ if (!this.path) {
106
+ throw new Error(`Parameter path is not set or is undefined`);
107
+ }
108
+ const params = await getParametersByPath(
109
+ this.path,
110
+ void 0,
111
+ void 0,
112
+ this.client
113
+ );
114
+ params.forEach((param) => {
115
+ const fullName = param.Name;
116
+ const name = fullName.replace(`${this.path}/`, "");
117
+ this.map.set(name, param);
118
+ });
119
+ }
120
+ };
121
+ // Annotate the CommonJS export names for ESM import in node:
122
+ 0 && (module.exports = {
123
+ ParameterCollection,
124
+ extractParamValue,
125
+ getParameters,
126
+ getParametersByPath,
127
+ ssmClient
128
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,101 @@
1
+ // src/ssm-parameters.ts
2
+ import {
3
+ SSMClient,
4
+ GetParametersByPathCommand,
5
+ GetParametersCommand
6
+ } from "@aws-sdk/client-ssm";
7
+ var ssmClient = new SSMClient({});
8
+ var getParametersByPath = async (path, parameters, nextToken, client) => {
9
+ client ??= ssmClient;
10
+ let returnParams = parameters || [];
11
+ const command = new GetParametersByPathCommand({
12
+ Path: path,
13
+ Recursive: true,
14
+ WithDecryption: true,
15
+ NextToken: nextToken
16
+ });
17
+ const output = await client.send(command);
18
+ if (output.Parameters !== void 0) {
19
+ returnParams = [...returnParams, ...output.Parameters];
20
+ }
21
+ if (output.NextToken !== void 0) {
22
+ return getParametersByPath(path, returnParams, output.NextToken, client);
23
+ }
24
+ return returnParams;
25
+ };
26
+ var getParameters = async (names, client) => {
27
+ client ??= ssmClient;
28
+ const command = new GetParametersCommand({
29
+ Names: names,
30
+ WithDecryption: true
31
+ });
32
+ const result = await client.send(command);
33
+ if (result.Parameters === void 0) {
34
+ return [];
35
+ }
36
+ return result.Parameters;
37
+ };
38
+ var extractParamValue = (path, name, params) => {
39
+ const fullName = `${path.replace(/\/$/, "")}/${name}`;
40
+ const item = params.find((item2) => item2.Name === fullName);
41
+ if (!item || !item.Value) {
42
+ throw new Error(`Parameter '${fullName}' is not set.`);
43
+ }
44
+ return item.Value;
45
+ };
46
+
47
+ // src/ssm-parameter-collection.ts
48
+ var ParameterCollection = class {
49
+ constructor(path, client) {
50
+ this.path = path;
51
+ this.client = client;
52
+ }
53
+ map = /* @__PURE__ */ new Map();
54
+ async hasParam(param) {
55
+ if (this.map.size < 1) {
56
+ await this.loadParameters();
57
+ }
58
+ return this.map.has(param);
59
+ }
60
+ async findParam(param) {
61
+ if (this.map.size < 1) {
62
+ await this.loadParameters();
63
+ }
64
+ return this.map.get(param);
65
+ }
66
+ async getParam(param) {
67
+ if (!await this.hasParam(param)) {
68
+ throw new Error(`Parameter '${param.toString()}' does not exist'`);
69
+ }
70
+ return this.map.get(param);
71
+ }
72
+ async get() {
73
+ if (this.map.size < 1) {
74
+ await this.loadParameters();
75
+ }
76
+ return this.map;
77
+ }
78
+ async loadParameters() {
79
+ if (!this.path) {
80
+ throw new Error(`Parameter path is not set or is undefined`);
81
+ }
82
+ const params = await getParametersByPath(
83
+ this.path,
84
+ void 0,
85
+ void 0,
86
+ this.client
87
+ );
88
+ params.forEach((param) => {
89
+ const fullName = param.Name;
90
+ const name = fullName.replace(`${this.path}/`, "");
91
+ this.map.set(name, param);
92
+ });
93
+ }
94
+ };
95
+ export {
96
+ ParameterCollection,
97
+ extractParamValue,
98
+ getParameters,
99
+ getParametersByPath,
100
+ ssmClient
101
+ };
package/package.json CHANGED
@@ -1,8 +1,10 @@
1
1
  {
2
2
  "name": "@dsmrt/axiom-aws-sdk",
3
- "version": "0.0.10",
3
+ "version": "0.1.0",
4
4
  "description": "AWS sdk library for working with axiom cli",
5
- "main": "lib/index.js",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
6
8
  "repository": {
7
9
  "type": "git",
8
10
  "url": "git@github.com:dsmrt/axiom.git",
@@ -22,6 +24,7 @@
22
24
  },
23
25
  "license": "MIT",
24
26
  "devDependencies": {
27
+ "@changesets/cli": "^2.27.1",
25
28
  "@types/node": "^20.9.0",
26
29
  "@typescript-eslint/eslint-plugin": "^6.12.0",
27
30
  "@typescript-eslint/parser": "^6.12.0",
@@ -29,6 +32,7 @@
29
32
  "eslint": "^8.54.0",
30
33
  "prettier": "^3.1.0",
31
34
  "ts-node": "^10.9.1",
35
+ "tsup": "^8.0.1",
32
36
  "typescript": "^5.2.2",
33
37
  "vitest": "^0.34.6"
34
38
  },
@@ -43,7 +47,7 @@
43
47
  "lint:fix": "eslint ./src/ --ext .ts --fix",
44
48
  "test": "vitest run --coverage -c ./vitest.config.ts",
45
49
  "watch": "vitest watch --coverage -c ./vitest.config.ts",
46
- "build": "tsc -d -p ./tsconfig.json",
47
- "version:patch": "pnpm version patch"
50
+ "build": "tsup --entry ./src/bin/axiom.ts --entry ./src/index.ts --format cjs,esm --dts --clean",
51
+ "release": "pnpm run build && pnpm changeset publish"
48
52
  }
49
53
  }
package/tsconfig.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "target": "es2022",
4
- "module": "node16",
5
- "strict": true,
4
+ "module": "commonjs",
6
5
  "esModuleInterop": true,
7
- "moduleResolution": "node16",
8
- "outDir": "lib"
6
+ "forceConsistentCasingInFileNames": true,
7
+ "strict": true,
8
+ "skipLibCheck": true,
9
+ "noEmit": true
9
10
  },
10
11
  "include": ["src/index.ts"]
11
12
  }
package/lib/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from "./ssm-parameters";
2
- export * from "./ssm-parameter-collection";
@@ -1,15 +0,0 @@
1
- import { Parameter, SSMClient } from "@aws-sdk/client-ssm";
2
- export type Params = {
3
- [key: string]: Parameter;
4
- };
5
- export declare class ParameterCollection<TParams extends Params> {
6
- readonly path: string;
7
- private readonly client?;
8
- readonly map: Map<keyof TParams, Parameter>;
9
- constructor(path: string, client?: SSMClient | undefined);
10
- hasParam(param: keyof TParams): Promise<boolean>;
11
- findParam(param: keyof TParams): Promise<Parameter | undefined>;
12
- getParam(param: keyof TParams): Promise<Parameter>;
13
- get(): Promise<Map<keyof TParams, Parameter>>;
14
- private loadParameters;
15
- }
@@ -1,11 +0,0 @@
1
- import { SSMClient, Parameter } from "@aws-sdk/client-ssm";
2
- export declare const ssmClient: SSMClient;
3
- export declare const getParametersByPath: (path: string, parameters?: Parameter[], nextToken?: string, client?: SSMClient) => Promise<Parameter[]>;
4
- export declare const getParameters: (names: string[], client?: SSMClient) => Promise<Parameter[]>;
5
- /**
6
- * Extract a single parameter from an array of params (typically from params by path)
7
- *
8
- * @param name
9
- * @param params
10
- */
11
- export declare const extractParamValue: (path: string, name: string, params: Parameter[]) => string;