@aligent/aws-wrappers 0.2.0 → 0.4.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/esm/package.json CHANGED
@@ -1,7 +1,10 @@
1
1
  {
2
2
  "name": "@aligent/aws-wrappers",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "Opinionated AWS SDK wrappers with Powertools logging and X-Ray tracing",
5
+ "engines": {
6
+ "node": ">=18"
7
+ },
5
8
  "main": "./cjs/index.cjs",
6
9
  "module": "./index.esm.js",
7
10
  "types": "./cjs/src/index.d.ts",
@@ -11,6 +11,10 @@ type WithTypedKey<TInput, K extends Record<string, unknown>> = Omit<TInput, 'Key
11
11
  * Wrapper around the AWS DynamoDB Document client providing structured
12
12
  * Powertools logging and X-Ray tracing by default.
13
13
  *
14
+ * Where a method's input carries payloads, secret material or PII, the INFO
15
+ * log line omits them; the verbose levels (`POWERTOOLS_LOG_LEVEL=DEBUG` or
16
+ * `TRACE`) log full SDK inputs.
17
+ *
14
18
  * Items are automatically marshalled / unmarshalled via the document client —
15
19
  * callers work with plain TypeScript objects in both directions.
16
20
  */
@@ -115,11 +119,38 @@ export declare class DynamoDBService {
115
119
  batchWrite(input: BatchWriteCommandInput): Promise<BatchWriteCommandOutput>;
116
120
  /**
117
121
  * Paginate over Query results, yielding one unmarshalled item at a time.
122
+ *
123
+ * **`Limit` is a page size, not a total cap.** DynamoDB applies it per
124
+ * request, and this method walks every page until `LastEvaluatedKey` is
125
+ * exhausted — so `paginateItems({ Limit: 10 })` yields *every* matching
126
+ * item, in pages of 10, not the first 10 items.
127
+ *
128
+ * To bound the number of items, `break` out of the loop. This is an
129
+ * `AsyncGenerator`, so `break` calls its `return()`, which unwinds the
130
+ * pagination and issues no further requests:
131
+ *
132
+ * ```ts
133
+ * const firstTen: Item[] = [];
134
+ * for await (const item of ddb.paginateItems<Item>(input)) {
135
+ * firstTen.push(item);
136
+ * if (firstTen.length === 10) break;
137
+ * }
138
+ * ```
139
+ *
140
+ * `Limit` remains the right knob for tuning per-request consumed capacity
141
+ * and page memory — set it deliberately, just don't expect it to stop the
142
+ * walk.
143
+ *
118
144
  * @template T - Expected shape of each yielded item.
119
145
  */
120
146
  paginateItems<T extends Record<string, unknown> = Record<string, unknown>>(input: QueryCommandInput): AsyncGenerator<T>;
121
147
  /**
122
148
  * Paginate over Scan results, yielding one unmarshalled item at a time.
149
+ *
150
+ * **`Limit` is a page size, not a total cap** — see `paginateItems` for the
151
+ * detail. `break` out of the loop to bound the number of items; `Limit`
152
+ * stays the right knob for per-request consumed capacity and page memory.
153
+ *
123
154
  * @template T - Expected shape of each yielded item.
124
155
  */
125
156
  paginateScan<T extends Record<string, unknown> = Record<string, unknown>>(input: ScanCommandInput): AsyncGenerator<T>;
@@ -13,6 +13,10 @@ type PutJsonObjectInput<T> = {
13
13
  * Wrapper around the AWS S3 client providing structured Powertools logging
14
14
  * and X-Ray tracing by default.
15
15
  *
16
+ * Where a method's input carries payloads, secret material or PII, the INFO
17
+ * log line omits them; the verbose levels (`POWERTOOLS_LOG_LEVEL=DEBUG` or
18
+ * `TRACE`) log full SDK inputs.
19
+ *
16
20
  * Input shapes are intentionally tight (Bucket/Key/Body only). Callers
17
21
  * needing SDK-level options not exposed here (server-side encryption,
18
22
  * tagging, version IDs) should use `S3Client` directly.
@@ -121,10 +125,21 @@ export declare class S3Service {
121
125
  */
122
126
  deleteObjects(bucket: string, keys: string[]): Promise<DeleteObjectsCommandOutput[]>;
123
127
  /**
124
- * Delete every object in a bucket. Streams the listing page-by-page and
125
- * delegates each page's deletion to `deleteObjects`, so peak memory stays
126
- * bounded by one page (~1000 keys) regardless of bucket size.
127
- * @returns The keys of every deleted object.
128
+ * Delete every object in an **unversioned** bucket. Streams the listing
129
+ * page-by-page and delegates each page's deletion to `deleteObjects`, so
130
+ * peak memory stays bounded by one page (~1000 keys) regardless of bucket
131
+ * size.
132
+ *
133
+ * **Versioned buckets are out of scope.** This paginates `ListObjectsV2`,
134
+ * which reports only current object versions — never noncurrent versions or
135
+ * delete markers. Against a versioned bucket the call therefore succeeds and
136
+ * the bucket then *looks* empty to `ListObjectsV2`, but the deletes only
137
+ * added delete markers: every object version is still stored, still billed,
138
+ * and `DeleteBucket` will still fail with `BucketNotEmpty`. Emptying a
139
+ * versioned bucket requires `ListObjectVersions` and per-version deletes;
140
+ * use `S3Client` directly for that.
141
+ *
142
+ * @returns The keys this call issued deletes for.
128
143
  */
129
144
  emptyBucket(bucket: string): Promise<string[]>;
130
145
  }
@@ -4,6 +4,10 @@ import { CreateScheduleCommandInput, CreateScheduleCommandOutput, CreateSchedule
4
4
  * Wrapper around the AWS EventBridge Scheduler client providing structured
5
5
  * Powertools logging and X-Ray tracing by default.
6
6
  *
7
+ * Where a method's input carries payloads, secret material or PII, the INFO
8
+ * log line omits them; the verbose levels (`POWERTOOLS_LOG_LEVEL=DEBUG` or
9
+ * `TRACE`) log full SDK inputs.
10
+ *
7
11
  * Covers CRUD on schedules and their groups. Named `SchedulerService` (not
8
12
  * `EventBridgeSchedulerService`) so it doesn't collide with a future wrapper
9
13
  * over the separate EventBridge bus/rules API (`@aws-sdk/client-eventbridge`).
@@ -27,8 +31,7 @@ export declare class SchedulerService {
27
31
  });
28
32
  /**
29
33
  * Create a new schedule. At INFO the log line omits `Target.Input` (the
30
- * target payload, a PII carrier); `POWERTOOLS_LOG_LEVEL=DEBUG` unlocks the
31
- * full input.
34
+ * target payload, a PII carrier).
32
35
  */
33
36
  createSchedule(input: CreateScheduleCommandInput): Promise<CreateScheduleCommandOutput>;
34
37
  /**
@@ -46,8 +49,7 @@ export declare class SchedulerService {
46
49
  * your behalf: deep-merging a `Target` (with its mutually-exclusive
47
50
  * target-type params) has no single correct semantics.
48
51
  *
49
- * At INFO the log line omits `Target.Input`; `POWERTOOLS_LOG_LEVEL=DEBUG`
50
- * unlocks the full input.
52
+ * At INFO the log line omits `Target.Input`.
51
53
  */
52
54
  updateSchedule(input: UpdateScheduleCommandInput): Promise<UpdateScheduleCommandOutput>;
53
55
  /**
@@ -4,6 +4,10 @@ import { CreateSecretCommandInput, CreateSecretCommandOutput, DeleteSecretComman
4
4
  * Wrapper around the AWS Secrets Manager client providing structured
5
5
  * Powertools logging and X-Ray tracing by default.
6
6
  *
7
+ * Where a method's input carries payloads, secret material or PII, the INFO
8
+ * log line omits them; the verbose levels (`POWERTOOLS_LOG_LEVEL=DEBUG` or
9
+ * `TRACE`) log full SDK inputs.
10
+ *
7
11
  * Write operations (`createSecret`, `updateSecret`, `putSecretValue`,
8
12
  * `deleteSecret`) are exposed for convenience but should be used with care:
9
13
  * secret lifecycle is usually managed by IaC (CDK / Terraform). Prefer IaC
@@ -43,8 +47,7 @@ export declare class SecretsManagerService {
43
47
  getJsonSecret<T>(secretId: string): Promise<T>;
44
48
  /**
45
49
  * Create a new secret. At INFO level the log line includes only identity
46
- * and non-secret metadata; `POWERTOOLS_LOG_LEVEL=DEBUG` unlocks the full
47
- * input (including `SecretString` / `SecretBinary`).
50
+ * and non-secret metadata.
48
51
  *
49
52
  * Prefer IaC (CDK / Terraform) for secret lifecycle — use this for
50
53
  * dynamically-issued credentials only.
@@ -52,8 +55,7 @@ export declare class SecretsManagerService {
52
55
  createSecret(input: CreateSecretCommandInput): Promise<CreateSecretCommandOutput>;
53
56
  /**
54
57
  * Update an existing secret's metadata or value. At INFO level the log
55
- * line omits `SecretString` / `SecretBinary`; `POWERTOOLS_LOG_LEVEL=DEBUG`
56
- * unlocks the full input.
58
+ * line omits `SecretString` / `SecretBinary`.
57
59
  *
58
60
  * Prefer IaC (CDK / Terraform) for secret lifecycle — use this for
59
61
  * runtime metadata updates only.
@@ -61,8 +63,7 @@ export declare class SecretsManagerService {
61
63
  updateSecret(input: UpdateSecretCommandInput): Promise<UpdateSecretCommandOutput>;
62
64
  /**
63
65
  * Store a new version of a secret's value. At INFO level the log line
64
- * omits `SecretString` / `SecretBinary`; `POWERTOOLS_LOG_LEVEL=DEBUG`
65
- * unlocks the full input.
66
+ * omits `SecretString` / `SecretBinary`.
66
67
  *
67
68
  * Typically used by rotation flows.
68
69
  */
@@ -3,6 +3,10 @@ import { DescribeExecutionCommandInput, DescribeExecutionCommandOutput, Executio
3
3
  /**
4
4
  * Wrapper around the AWS Step Functions client providing structured
5
5
  * Powertools logging and X-Ray tracing by default.
6
+ *
7
+ * Where a method's input carries payloads, secret material or PII, the INFO
8
+ * log line omits them; the verbose levels (`POWERTOOLS_LOG_LEVEL=DEBUG` or
9
+ * `TRACE`) log full SDK inputs.
6
10
  */
7
11
  export declare class StepFunctionsService {
8
12
  private readonly client;
@@ -3,6 +3,10 @@ import { PublishBatchCommandInput, PublishBatchCommandOutput, PublishCommandInpu
3
3
  /**
4
4
  * Wrapper around the AWS SNS client providing structured Powertools logging
5
5
  * and X-Ray tracing by default.
6
+ *
7
+ * Where a method's input carries payloads, secret material or PII, the INFO
8
+ * log line omits them; the verbose levels (`POWERTOOLS_LOG_LEVEL=DEBUG` or
9
+ * `TRACE`) log full SDK inputs.
6
10
  */
7
11
  export declare class SNSService {
8
12
  private readonly client;
@@ -28,14 +32,20 @@ export declare class SNSService {
28
32
  * Publish a single message to an SNS topic.
29
33
  *
30
34
  * At INFO level the log line includes only routing / dedup metadata; see
31
- * `PUBLISH_SAFE_FIELDS` for the list. Setting `POWERTOOLS_LOG_LEVEL=DEBUG`
32
- * unlocks the full input.
35
+ * `PUBLISH_SAFE_FIELDS` for the list.
33
36
  *
34
37
  * @param input - PublishCommandInput including TopicArn and Message.
35
38
  */
36
39
  publish(input: PublishCommandInput, opts?: {
37
40
  truncate?: boolean;
38
41
  }): Promise<PublishCommandOutput>;
42
+ /**
43
+ * The truncation helpers return the input unchanged when it already fits, so
44
+ * a `!==` comparison against their result is what decides whether a field
45
+ * was modified. Don't reintroduce a size guard here: that would state each
46
+ * limit twice, encode the string to a `Buffer` twice, and let the two
47
+ * expressions drift into warning without truncating (or the reverse).
48
+ */
39
49
  private applyTruncation;
40
50
  /**
41
51
  * Publish a batch of messages to an SNS topic. The SNS API caps
@@ -3,6 +3,10 @@ import { DeleteMessageBatchCommandInput, DeleteMessageBatchCommandOutput, Delete
3
3
  /**
4
4
  * Wrapper around the AWS SQS client providing structured Powertools logging
5
5
  * and X-Ray tracing by default.
6
+ *
7
+ * Where a method's input carries payloads, secret material or PII, the INFO
8
+ * log line omits them; the verbose levels (`POWERTOOLS_LOG_LEVEL=DEBUG` or
9
+ * `TRACE`) log full SDK inputs.
6
10
  */
7
11
  export declare class SQSService {
8
12
  private readonly client;
@@ -27,12 +31,18 @@ export declare class SQSService {
27
31
  * Send a single message to an SQS queue.
28
32
  *
29
33
  * At INFO level the log line includes only queue routing / FIFO metadata;
30
- * see `SEND_MESSAGE_SAFE_FIELDS`. `POWERTOOLS_LOG_LEVEL=DEBUG` unlocks the
31
- * full input.
34
+ * see `SEND_MESSAGE_SAFE_FIELDS`.
32
35
  */
33
36
  sendMessage(input: SendMessageCommandInput, opts?: {
34
37
  truncate?: boolean;
35
38
  }): Promise<SendMessageCommandOutput>;
39
+ /**
40
+ * `truncateUtf8` returns the input unchanged when it already fits, so a
41
+ * `!==` comparison against its result is what decides whether the body was
42
+ * modified. Don't reintroduce a size guard here: that would state the limit
43
+ * twice, encode the string to a `Buffer` twice, and let the two expressions
44
+ * drift into warning without truncating (or the reverse).
45
+ */
36
46
  private applyTruncation;
37
47
  /**
38
48
  * Receive messages from an SQS queue. Returns an empty array when no
@@ -6,6 +6,10 @@ import { Parameter, PutParameterCommandInput, PutParameterCommandOutput, SSMClie
6
6
  * `WithDecryption` — callers needing plaintext should use `SSMClient`
7
7
  * directly.
8
8
  *
9
+ * Where a method's input carries payloads, secret material or PII, the INFO
10
+ * log line omits them; the verbose levels (`POWERTOOLS_LOG_LEVEL=DEBUG` or
11
+ * `TRACE`) log full SDK inputs.
12
+ *
9
13
  * Write operations (`putParameter`, `deleteParameter`) are exposed for
10
14
  * convenience but should be used with care: parameter lifecycle is usually
11
15
  * managed by IaC (CDK / Terraform). Prefer IaC for anything that exists at
@@ -1,11 +1,21 @@
1
1
  import type { LoggerInterface } from '@aws-lambda-powertools/logger/types';
2
+ /**
3
+ * Whether the logger is verbose enough that full SDK inputs — payloads, secret
4
+ * material and PII — may be written to the log.
5
+ *
6
+ * **This is the only place in the package that reads the log level.** Never
7
+ * compare `logger.getLevelName()` yourself: Powertools orders `TRACE` as *more*
8
+ * verbose than `DEBUG` (thresholds 6 and 8), so the obvious
9
+ * `getLevelName() === 'DEBUG'` check silently redacts at the most verbose level
10
+ * available. Route every disclosure decision through this predicate instead.
11
+ */
12
+ export declare function shouldLogFullInput(logger: LoggerInterface): boolean;
2
13
  /**
3
14
  * Return a log-safe projection of `input` based on the logger's configured level.
4
15
  *
5
- * At `DEBUG`, the full input is returned unchanged — operators who set
6
- * `POWERTOOLS_LOG_LEVEL=DEBUG` (or call `logger.setLogLevel('DEBUG')`) have
7
- * explicitly opted into seeing everything, including payloads, secret material
8
- * and PII.
16
+ * At the verbose levels — see {@link shouldLogFullInput} — the full input is
17
+ * returned unchanged: operators who asked for that verbosity have explicitly
18
+ * opted into seeing everything, including payloads, secret material and PII.
9
19
  *
10
20
  * At any other level, only the fields listed in `safeFields` are included.
11
21
  * Missing fields are silently skipped — the result type narrows to
package/package.json CHANGED
@@ -1,7 +1,10 @@
1
1
  {
2
2
  "name": "@aligent/aws-wrappers",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "Opinionated AWS SDK wrappers with Powertools logging and X-Ray tracing",
5
+ "engines": {
6
+ "node": ">=18"
7
+ },
5
8
  "main": "./cjs/index.cjs",
6
9
  "module": "./esm/index.mjs",
7
10
  "types": "./cjs/src/index.d.ts",