@aligent/aws-wrappers 0.0.1 → 0.1.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.
Files changed (39) hide show
  1. package/cjs/index.cjs +1911 -0
  2. package/cjs/index.d.ts +1 -0
  3. package/cjs/package.json +51 -0
  4. package/{src → cjs/src}/dynamodb/dynamodb.d.ts +2 -2
  5. package/cjs/src/index.d.ts +7 -0
  6. package/{src → cjs/src}/s3/s3.d.ts +2 -2
  7. package/{src → cjs/src}/secrets-manager/secrets-manager.d.ts +2 -2
  8. package/{src → cjs/src}/sfn/sfn.d.ts +2 -2
  9. package/{src → cjs/src}/sns/sns.d.ts +2 -2
  10. package/{src → cjs/src}/sqs/sqs.d.ts +2 -2
  11. package/{src → cjs/src}/ssm/ssm.d.ts +2 -2
  12. package/{src → cjs/src}/util/redact.d.ts +2 -2
  13. package/esm/index.d.ts +1 -0
  14. package/esm/index.mjs +1903 -0
  15. package/esm/package.json +51 -0
  16. package/esm/src/dynamodb/dynamodb.d.ts +127 -0
  17. package/esm/src/index.d.ts +7 -0
  18. package/esm/src/s3/s3.d.ts +131 -0
  19. package/esm/src/secrets-manager/secrets-manager.d.ts +78 -0
  20. package/esm/src/sfn/sfn.d.ts +38 -0
  21. package/esm/src/sns/sns.d.ts +48 -0
  22. package/esm/src/sqs/sqs.d.ts +60 -0
  23. package/esm/src/ssm/ssm.d.ts +84 -0
  24. package/{src/util/redact.js → esm/src/util/redact.d.ts} +2 -13
  25. package/esm/src/util/truncate.d.ts +15 -0
  26. package/package.json +25 -7
  27. package/CLAUDE.md +0 -172
  28. package/src/dynamodb/dynamodb.js +0 -308
  29. package/src/index.d.ts +0 -7
  30. package/src/index.js +0 -17
  31. package/src/s3/s3.js +0 -244
  32. package/src/secrets-manager/secrets-manager.js +0 -152
  33. package/src/sfn/sfn.js +0 -74
  34. package/src/sns/sns.js +0 -110
  35. package/src/sqs/sqs.js +0 -134
  36. package/src/ssm/ssm.js +0 -144
  37. package/src/util/truncate.js +0 -36
  38. package/tsconfig.lib.tsbuildinfo +0 -1
  39. /package/{src → cjs/src}/util/truncate.d.ts +0 -0
package/src/sqs/sqs.js DELETED
@@ -1,134 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SQSService = void 0;
4
- const logger_1 = require("@aws-lambda-powertools/logger");
5
- const client_sqs_1 = require("@aws-sdk/client-sqs");
6
- const aws_xray_sdk_core_1 = require("aws-xray-sdk-core");
7
- const redact_1 = require("../util/redact");
8
- const truncate_1 = require("../util/truncate");
9
- const SQS_BATCH_LIMIT = 10;
10
- const SQS_MESSAGE_BODY_MAX_BYTES = 256 * 1024;
11
- /**
12
- * Fields safe to log at INFO level for `sendMessage`. Omits `MessageBody` and
13
- * `MessageAttributes` — both carry payload content.
14
- * `POWERTOOLS_LOG_LEVEL=DEBUG` unlocks the full input.
15
- */
16
- const SEND_MESSAGE_SAFE_FIELDS = [
17
- 'QueueUrl',
18
- 'DelaySeconds',
19
- 'MessageGroupId',
20
- 'MessageDeduplicationId',
21
- ];
22
- /**
23
- * Wrapper around the AWS SQS client providing structured Powertools logging
24
- * and X-Ray tracing by default.
25
- */
26
- class SQSService {
27
- client;
28
- logger;
29
- truncate;
30
- /**
31
- * @param opts.logger - Optional Powertools logger. Defaults to `new Logger()`,
32
- * which picks up `POWERTOOLS_SERVICE_NAME` from the environment.
33
- * @param opts.client - Optional pre-configured `SQSClient`. When supplied,
34
- * the wrapper does not apply X-Ray instrumentation.
35
- * @param opts.truncate - When `true`, oversized `MessageBody` is truncated
36
- * (byte-safe) before sending instead of failing at the SDK. Defaults to
37
- * `false`. Each `sendMessage` call can override via its own `truncate`
38
- * option.
39
- */
40
- constructor(opts) {
41
- this.client = opts?.client ?? (0, aws_xray_sdk_core_1.captureAWSv3Client)(new client_sqs_1.SQSClient());
42
- this.logger = opts?.logger ?? new logger_1.Logger();
43
- this.truncate = opts?.truncate ?? false;
44
- }
45
- /**
46
- * Send a single message to an SQS queue.
47
- *
48
- * At INFO level the log line includes only queue routing / FIFO metadata;
49
- * see `SEND_MESSAGE_SAFE_FIELDS`. `POWERTOOLS_LOG_LEVEL=DEBUG` unlocks the
50
- * full input.
51
- */
52
- async sendMessage(input, opts) {
53
- const shouldTruncate = opts?.truncate ?? this.truncate;
54
- const effective = shouldTruncate ? this.applyTruncation(input) : input;
55
- this.logger.info('Sending SQS message', {
56
- input: (0, redact_1.filterFieldsForLogLevel)(this.logger, effective, SEND_MESSAGE_SAFE_FIELDS),
57
- });
58
- return this.client.send(new client_sqs_1.SendMessageCommand(effective));
59
- }
60
- applyTruncation(input) {
61
- const truncated = [];
62
- let MessageBody = input.MessageBody;
63
- if (MessageBody !== undefined &&
64
- Buffer.byteLength(MessageBody, 'utf8') > SQS_MESSAGE_BODY_MAX_BYTES) {
65
- MessageBody = (0, truncate_1.truncateUtf8)(MessageBody, SQS_MESSAGE_BODY_MAX_BYTES);
66
- truncated.push('MessageBody');
67
- }
68
- if (truncated.length > 0) {
69
- this.logger.warn('Truncated SQS sendMessage input', { fields: truncated });
70
- }
71
- return { ...input, MessageBody };
72
- }
73
- /**
74
- * Receive messages from an SQS queue. Returns an empty array when no
75
- * messages are available. No automatic deletion is performed — visibility
76
- * timeout semantics are the caller's responsibility.
77
- * @returns The `Messages` array from the response, or `[]` if absent.
78
- */
79
- async receiveMessages(input) {
80
- this.logger.info('Receiving SQS messages', { input });
81
- const response = await this.client.send(new client_sqs_1.ReceiveMessageCommand(input));
82
- return response.Messages ?? [];
83
- }
84
- /**
85
- * Delete a single message from an SQS queue.
86
- */
87
- async deleteMessage(input) {
88
- this.logger.info('Deleting SQS message', { input });
89
- return this.client.send(new client_sqs_1.DeleteMessageCommand(input));
90
- }
91
- /**
92
- * Send a batch of messages to an SQS queue. The SQS API caps
93
- * SendMessageBatch at 10 entries per request, so this method auto-chunks
94
- * the caller's entries and sends one request per chunk.
95
- */
96
- async sendMessageBatch(input) {
97
- const entries = input.Entries ?? [];
98
- // Inline DEBUG check rather than `filterFieldsForLogLevel` because the
99
- // safe log shape includes the computed `entryCount`, which isn't a key
100
- // on `SendMessageBatchCommandInput`.
101
- const isDebug = this.logger.getLevelName() === 'DEBUG';
102
- this.logger.info('Sending SQS message batch', {
103
- input: isDebug ? input : { QueueUrl: input.QueueUrl, entryCount: entries.length },
104
- });
105
- const results = [];
106
- for (let i = 0; i < entries.length; i += SQS_BATCH_LIMIT) {
107
- const chunk = entries.slice(i, i + SQS_BATCH_LIMIT);
108
- results.push(await this.client.send(new client_sqs_1.SendMessageBatchCommand({ ...input, Entries: chunk })));
109
- }
110
- return results;
111
- }
112
- /**
113
- * Delete a batch of messages from an SQS queue. The SQS API caps
114
- * DeleteMessageBatch at 10 entries per request, so this method auto-chunks
115
- * the caller's entries and sends one request per chunk.
116
- */
117
- async deleteMessageBatch(input) {
118
- const entries = input.Entries ?? [];
119
- // Inline DEBUG check rather than `filterFieldsForLogLevel` because the
120
- // safe log shape includes the computed `entryCount`, which isn't a key
121
- // on `DeleteMessageBatchCommandInput`.
122
- const isDebug = this.logger.getLevelName() === 'DEBUG';
123
- this.logger.info('Deleting SQS message batch', {
124
- input: isDebug ? input : { QueueUrl: input.QueueUrl, entryCount: entries.length },
125
- });
126
- const results = [];
127
- for (let i = 0; i < entries.length; i += SQS_BATCH_LIMIT) {
128
- const chunk = entries.slice(i, i + SQS_BATCH_LIMIT);
129
- results.push(await this.client.send(new client_sqs_1.DeleteMessageBatchCommand({ ...input, Entries: chunk })));
130
- }
131
- return results;
132
- }
133
- }
134
- exports.SQSService = SQSService;
package/src/ssm/ssm.js DELETED
@@ -1,144 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SSMService = void 0;
4
- const logger_1 = require("@aws-lambda-powertools/logger");
5
- const client_ssm_1 = require("@aws-sdk/client-ssm");
6
- const aws_xray_sdk_core_1 = require("aws-xray-sdk-core");
7
- const redact_1 = require("../util/redact");
8
- /**
9
- * Fields safe to log at INFO level for `putParameter`. Omits `Value` (the
10
- * parameter content itself). `POWERTOOLS_LOG_LEVEL=DEBUG` unlocks the full
11
- * input.
12
- */
13
- const PUT_PARAMETER_SAFE_FIELDS = [
14
- 'Name',
15
- 'Type',
16
- 'Description',
17
- 'KeyId',
18
- 'Overwrite',
19
- 'AllowedPattern',
20
- 'Tags',
21
- 'Tier',
22
- 'Policies',
23
- 'DataType',
24
- ];
25
- /**
26
- * Wrapper around the AWS SSM Parameter Store client providing structured
27
- * Powertools logging and X-Ray tracing by default. All read operations enable
28
- * `WithDecryption` — callers needing plaintext should use `SSMClient`
29
- * directly.
30
- *
31
- * Write operations (`putParameter`, `deleteParameter`) are exposed for
32
- * convenience but should be used with care: parameter lifecycle is usually
33
- * managed by IaC (CDK / Terraform). Prefer IaC for anything that exists at
34
- * deploy time; reserve runtime writes for values that genuinely need to
35
- * mutate within the application.
36
- */
37
- class SSMService {
38
- client;
39
- logger;
40
- /**
41
- * @param opts.logger - Optional Powertools logger. Defaults to `new Logger()`,
42
- * which picks up `POWERTOOLS_SERVICE_NAME` from the environment.
43
- * @param opts.client - Optional pre-configured `SSMClient`. When supplied,
44
- * the wrapper does not apply X-Ray instrumentation.
45
- */
46
- constructor(opts) {
47
- this.client = opts?.client ?? (0, aws_xray_sdk_core_1.captureAWSv3Client)(new client_ssm_1.SSMClient());
48
- this.logger = opts?.logger ?? new logger_1.Logger();
49
- }
50
- /**
51
- * Fetch a single SSM parameter's value.
52
- * @param name - The parameter name (or ARN).
53
- * @returns The parameter value, or `undefined` if the parameter has no
54
- * value set.
55
- */
56
- async getParameter(name) {
57
- this.logger.info('Fetching SSM parameter', { input: { name } });
58
- const response = await this.client.send(new client_ssm_1.GetParameterCommand({ Name: name, WithDecryption: true }));
59
- return response.Parameter?.Value;
60
- }
61
- /**
62
- * Fetch multiple SSM parameters in a single request. Callers supply an
63
- * alias-to-path record, and the returned record is keyed by the same
64
- * aliases — so the SSM path is only mentioned at the call site and the
65
- * destructured names are whatever the caller wants to use locally:
66
- *
67
- * ```ts
68
- * const { username, password } = await ssm.getParameters({
69
- * username: '/myapp/db/username',
70
- * password: '/myapp/db/password',
71
- * });
72
- * ```
73
- *
74
- * @param aliases - Record mapping each desired local alias to its SSM
75
- * parameter name (or ARN).
76
- * @returns A record keyed by the same aliases, mapping each to the
77
- * parameter's value, or `undefined` when the parameter is missing or has
78
- * no value.
79
- */
80
- async getParameters(aliases) {
81
- this.logger.info('Fetching SSM parameters', { input: { aliases } });
82
- const response = await this.client.send(new client_ssm_1.GetParametersCommand({
83
- Names: Object.values(aliases),
84
- WithDecryption: true,
85
- }));
86
- const byPath = new Map();
87
- for (const parameter of response.Parameters ?? []) {
88
- if (parameter.Name !== undefined)
89
- byPath.set(parameter.Name, parameter.Value);
90
- }
91
- const result = {};
92
- for (const alias of Object.keys(aliases)) {
93
- result[alias] = byPath.get(aliases[alias]);
94
- }
95
- return result;
96
- }
97
- /**
98
- * Create or update an SSM parameter. The log line omits `Value` to avoid
99
- * leaking secret material.
100
- *
101
- * Prefer IaC (CDK / Terraform) for parameter lifecycle — use this for
102
- * runtime values only.
103
- */
104
- async putParameter(input) {
105
- this.logger.info('Putting SSM parameter', {
106
- input: (0, redact_1.filterFieldsForLogLevel)(this.logger, input, PUT_PARAMETER_SAFE_FIELDS),
107
- });
108
- return this.client.send(new client_ssm_1.PutParameterCommand(input));
109
- }
110
- /**
111
- * Delete an SSM parameter by name.
112
- *
113
- * Prefer IaC (CDK / Terraform) for parameter lifecycle — use this for
114
- * runtime cleanup only.
115
- */
116
- async deleteParameter(name) {
117
- this.logger.info('Deleting SSM parameter', { input: { name } });
118
- await this.client.send(new client_ssm_1.DeleteParameterCommand({ Name: name }));
119
- }
120
- /**
121
- * Fetch all parameters under an SSM hierarchy path, auto-paginating across
122
- * all pages. `Recursive` defaults to `true` (overriding the AWS SDK
123
- * default of `false`) to match the typical "load all config under
124
- * `/myapp/`" use case.
125
- * @param path - The parameter path prefix (e.g. `/myapp/`).
126
- * @param opts.recursive - Whether to recurse into nested paths. Defaults
127
- * to `true`.
128
- * @returns The full `Parameter` objects (including `Version`,
129
- * `LastModifiedDate`, etc.).
130
- */
131
- async getParametersByPath(path, opts) {
132
- const recursive = opts?.recursive ?? true;
133
- this.logger.info('Fetching SSM parameters by path', {
134
- input: { path, recursive },
135
- });
136
- const paginator = (0, client_ssm_1.paginateGetParametersByPath)({ client: this.client }, { Path: path, Recursive: recursive, WithDecryption: true });
137
- const parameters = [];
138
- for await (const page of paginator) {
139
- parameters.push(...(page.Parameters ?? []));
140
- }
141
- return parameters;
142
- }
143
- }
144
- exports.SSMService = SSMService;
@@ -1,36 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.truncateUtf8 = truncateUtf8;
4
- exports.truncateCodepoints = truncateCodepoints;
5
- /**
6
- * Truncate a UTF-8 string to fit within `maxBytes` when encoded as UTF-8.
7
- *
8
- * Walks back from the cut point to the start of the previous codepoint, so the
9
- * result is never a malformed UTF-8 sequence. Returns the input unchanged when
10
- * it already fits.
11
- */
12
- function truncateUtf8(str, maxBytes) {
13
- const buf = Buffer.from(str, 'utf8');
14
- if (buf.length <= maxBytes)
15
- return str;
16
- let end = maxBytes;
17
- while (end > 0) {
18
- const byte = buf[end];
19
- if (byte === undefined || (byte & 0xc0) !== 0x80)
20
- break;
21
- end--;
22
- }
23
- return buf.toString('utf8', 0, end);
24
- }
25
- /**
26
- * Truncate a string to at most `maxChars` Unicode codepoints. Splits the
27
- * string via `Array.from` so surrogate pairs (emoji, supplementary-plane
28
- * characters) are not split in the middle. Returns the input unchanged when
29
- * it already fits.
30
- */
31
- function truncateCodepoints(str, maxChars) {
32
- const codepoints = Array.from(str);
33
- if (codepoints.length <= maxChars)
34
- return str;
35
- return codepoints.slice(0, maxChars).join('');
36
- }
@@ -1 +0,0 @@
1
- {"version":"5.9.3"}
File without changes