@nr1e/aws 0.0.0-snapshot-20251228154426 → 0.0.0-snapshot-20251228155206
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/dynamodb.d.mts +104 -0
- package/dist/dynamodb.d.mts.map +1 -0
- package/dist/dynamodb.mjs +297 -0
- package/dist/dynamodb.mjs.map +1 -0
- package/dist/event-bridge.d.mts +10 -0
- package/dist/event-bridge.d.mts.map +1 -0
- package/dist/event-bridge.mjs +35 -0
- package/dist/event-bridge.mjs.map +1 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +4 -0
- package/dist/index.mjs.map +1 -1
- package/dist/s3.d.mts +55 -0
- package/dist/s3.d.mts.map +1 -0
- package/dist/s3.mjs +110 -0
- package/dist/s3.mjs.map +1 -0
- package/dist/sqs.d.mts +4 -0
- package/dist/sqs.d.mts.map +1 -0
- package/dist/sqs.mjs +17 -0
- package/dist/sqs.mjs.map +1 -0
- package/package.json +8 -2
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
|
|
2
|
+
import { DynamoDBDocumentClient, QueryCommand, QueryCommandInput, QueryCommandOutput, ScanCommand, ScanCommandOutput, PutCommand, PutCommandOutput } from '@aws-sdk/lib-dynamodb';
|
|
3
|
+
export { QueryCommand, QueryCommandOutput, ScanCommand, ScanCommandOutput, PutCommand, PutCommandOutput, };
|
|
4
|
+
export declare function getDynamoDBClient(region?: string): DynamoDBClient;
|
|
5
|
+
export declare function getDynamoDBDocumentClient(region?: string): DynamoDBDocumentClient;
|
|
6
|
+
export interface PaginationParams {
|
|
7
|
+
cursor?: string | null | undefined;
|
|
8
|
+
direction?: 'next' | 'prev' | null | undefined;
|
|
9
|
+
limit?: number | null | undefined;
|
|
10
|
+
}
|
|
11
|
+
export interface PaginatedResult<T> {
|
|
12
|
+
items: T[];
|
|
13
|
+
cursor: string;
|
|
14
|
+
hasNext: boolean;
|
|
15
|
+
page: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Executes a paginated DynamoDB query with full cursor-based pagination support.
|
|
19
|
+
*
|
|
20
|
+
* This helper encapsulates all pagination logic including:
|
|
21
|
+
* - Cursor encoding/decoding
|
|
22
|
+
* - ExclusiveStartKey calculation
|
|
23
|
+
* - Bidirectional pagination (next/prev)
|
|
24
|
+
* - First/last key tracking
|
|
25
|
+
* - Automatic item ordering
|
|
26
|
+
*
|
|
27
|
+
* @param params Configuration for the query and item mapping
|
|
28
|
+
* @param params.client DynamoDB Document Client instance
|
|
29
|
+
* @param params.query QueryCommand input (without ExclusiveStartKey, Limit, ScanIndexForward)
|
|
30
|
+
* @param params.keyAttributes Array of key attribute names for the table/index being queried
|
|
31
|
+
* @param params.mapItem Function to transform raw DynamoDB items into desired format
|
|
32
|
+
* @param pagination Pagination parameters from the client
|
|
33
|
+
* @param pagination.cursor Base64-encoded cursor from previous request
|
|
34
|
+
* @param pagination.direction Direction to paginate ('next' or 'prev')
|
|
35
|
+
* @param pagination.limit Number of items per page (locked after first request)
|
|
36
|
+
* @param defaultScanForward Controls the default scan direction. When true, 'next' scans forward (ascending) and 'prev' scans backward (descending). When false, the behavior is inverted.
|
|
37
|
+
* @returns Paginated result with items, cursor, hasNext flag, and page number
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* return executePaginatedQuery(
|
|
42
|
+
* {
|
|
43
|
+
* client: getDynamoDBDocumentClient(),
|
|
44
|
+
* query: {
|
|
45
|
+
* TableName: 'MyTable',
|
|
46
|
+
* IndexName: 'Gs1',
|
|
47
|
+
* KeyConditionExpression: 'Gs1Pk = :pk',
|
|
48
|
+
* ExpressionAttributeValues: { ':pk': 'Agency#123' },
|
|
49
|
+
* },
|
|
50
|
+
* keyAttributes: ['Pk', 'Sk', 'Gs1Pk', 'Gs1Sk'],
|
|
51
|
+
* mapItem: (item) => item.Detail,
|
|
52
|
+
* },
|
|
53
|
+
* { cursor: '...', direction: 'next', limit: 10 },
|
|
54
|
+
* true // defaultScanForward
|
|
55
|
+
* );
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export declare function executePaginatedQuery<T = any>(params: {
|
|
59
|
+
client: DynamoDBDocumentClient;
|
|
60
|
+
query: Omit<QueryCommandInput, 'ExclusiveStartKey' | 'Limit' | 'ScanIndexForward'>;
|
|
61
|
+
keyAttributes: string[];
|
|
62
|
+
mapItem: (item: Record<string, any>) => T;
|
|
63
|
+
}, pagination: PaginationParams, defaultScanForward?: boolean): Promise<PaginatedResult<T>>;
|
|
64
|
+
/**
|
|
65
|
+
* Executes a paginated DynamoDB scan with cursor-based pagination support.
|
|
66
|
+
*
|
|
67
|
+
* Similar to executePaginatedQuery but for Scan operations. Note that Scan operations
|
|
68
|
+
* are unordered by nature and do not support scan direction control (unlike Query operations).
|
|
69
|
+
* Scan operations only support forward pagination (no bidirectional navigation).
|
|
70
|
+
*
|
|
71
|
+
* @param params Configuration for the scan and item mapping
|
|
72
|
+
* @param params.client DynamoDB Document Client instance
|
|
73
|
+
* @param params.scan ScanCommand input (without ExclusiveStartKey or Limit)
|
|
74
|
+
* @param params.keyNames Array of key attribute names for the table
|
|
75
|
+
* @param params.mapItem Function to transform raw DynamoDB items into desired format
|
|
76
|
+
* @param pagination Pagination parameters from the client
|
|
77
|
+
* @param pagination.cursor Base64-encoded cursor from previous request
|
|
78
|
+
* @param pagination.limit Number of items per page (locked after first request)
|
|
79
|
+
* @returns Paginated result with items, cursor, hasNext flag, and page number
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* return executePaginatedScan(
|
|
84
|
+
* {
|
|
85
|
+
* client: getDynamoDBDocumentClient(),
|
|
86
|
+
* scan: {
|
|
87
|
+
* TableName: 'MyTable',
|
|
88
|
+
* FilterExpression: 'attribute_exists(#attr)',
|
|
89
|
+
* ExpressionAttributeNames: { '#attr': 'myAttribute' },
|
|
90
|
+
* },
|
|
91
|
+
* keyNames: ['Pk', 'Sk'],
|
|
92
|
+
* mapItem: (item) => item.Detail,
|
|
93
|
+
* },
|
|
94
|
+
* { cursor: '...', limit: 10 }
|
|
95
|
+
* );
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
export declare function executePaginatedScan<T = any>(params: {
|
|
99
|
+
client: DynamoDBDocumentClient;
|
|
100
|
+
scan: Omit<QueryCommandInput, 'ExclusiveStartKey' | 'Limit'>;
|
|
101
|
+
keyNames: string[];
|
|
102
|
+
mapItem: (item: Record<string, any>) => T;
|
|
103
|
+
}, pagination: PaginationParams): Promise<PaginatedResult<T>>;
|
|
104
|
+
//# sourceMappingURL=dynamodb.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dynamodb.d.mts","sourceRoot":"","sources":["../src/dynamodb.mts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,0BAA0B,CAAC;AACxD,OAAO,EACL,sBAAsB,EACtB,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,EAClB,WAAW,EACX,iBAAiB,EACjB,UAAU,EACV,gBAAgB,EACjB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EACL,YAAY,EACZ,kBAAkB,EAClB,WAAW,EACX,iBAAiB,EACjB,UAAU,EACV,gBAAgB,GACjB,CAAC;AAKF,wBAAgB,iBAAiB,CAAC,MAAM,CAAC,EAAE,MAAM,kBAQhD;AAED,wBAAgB,yBAAyB,CAAC,MAAM,CAAC,EAAE,MAAM,0BAYxD;AAwJD,MAAM,WAAW,gBAAgB;IAC/B,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACnC,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAC/C,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;CACnC;AAED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@aws-sdk/lib-dynamodb';
|
|
3
|
+
import { getAwsRegion } from './region.mjs';
|
|
4
|
+
export { QueryCommand, ScanCommand, PutCommand, };
|
|
5
|
+
const dynamoDBClients = new Map();
|
|
6
|
+
const dynamoDBDocumentClients = new Map();
|
|
7
|
+
export function getDynamoDBClient(region) {
|
|
8
|
+
const regionKey = region || getAwsRegion();
|
|
9
|
+
let client = dynamoDBClients.get(regionKey);
|
|
10
|
+
if (!client) {
|
|
11
|
+
client = new DynamoDBClient({ region: regionKey });
|
|
12
|
+
dynamoDBClients.set(regionKey, client);
|
|
13
|
+
}
|
|
14
|
+
return client;
|
|
15
|
+
}
|
|
16
|
+
export function getDynamoDBDocumentClient(region) {
|
|
17
|
+
const regionKey = region || getAwsRegion();
|
|
18
|
+
let client = dynamoDBDocumentClients.get(regionKey);
|
|
19
|
+
if (!client) {
|
|
20
|
+
client = DynamoDBDocumentClient.from(getDynamoDBClient(regionKey), {
|
|
21
|
+
marshallOptions: {
|
|
22
|
+
removeUndefinedValues: true,
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
dynamoDBDocumentClients.set(regionKey, client);
|
|
26
|
+
}
|
|
27
|
+
return client;
|
|
28
|
+
}
|
|
29
|
+
function dedupe(arr) {
|
|
30
|
+
return Array.from(new Set(arr));
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Builds a DynamoDB `ExclusiveStartKey` or `LastEvaluatedKey` object
|
|
34
|
+
* from a given item and a list of key attribute names.
|
|
35
|
+
*
|
|
36
|
+
* This is useful when performing paginated `Query` or `Scan` operations
|
|
37
|
+
* and you only have the last returned item from the previous page rather
|
|
38
|
+
* than the full `LastEvaluatedKey` returned by DynamoDB.
|
|
39
|
+
*
|
|
40
|
+
* The function copies the specified key attributes from the provided item
|
|
41
|
+
* into a new object suitable for use as `ExclusiveStartKey` in a
|
|
42
|
+
* subsequent query. For Global Secondary Index (GSI) queries, include
|
|
43
|
+
* both the table’s primary key attributes and the index’s key attributes.
|
|
44
|
+
*
|
|
45
|
+
* @param item - The DynamoDB item (from a previous page) to extract key values from.
|
|
46
|
+
* @param keyNames - The list of key attribute names that uniquely identify an item
|
|
47
|
+
* (e.g., `["Pk", "Sk"]` for a table, or
|
|
48
|
+
* `["Pk", "Sk", "Gs1Pk", "Gs1Sk"]` for a GSI).
|
|
49
|
+
* @returns A plain JavaScript object representing the `ExclusiveStartKey`.
|
|
50
|
+
*
|
|
51
|
+
* @throws {Error} If any specified key attribute is missing on the provided item.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* const lastItem = { Pk: "User#123", Sk: "Order#456", Gs1Pk: "User#123", Gs1Sk: "Order#456" };
|
|
56
|
+
* const keyNames = ["Pk", "Sk", "Gs1Pk", "Gs1Sk"];
|
|
57
|
+
* const eks = makeExclusiveStartKeyFromItem(lastItem, keyNames);
|
|
58
|
+
*
|
|
59
|
+
* await ddbDoc.query({
|
|
60
|
+
* TableName: "MyTable",
|
|
61
|
+
* IndexName: "GSI1",
|
|
62
|
+
* Limit: 100,
|
|
63
|
+
* ExclusiveStartKey: eks,
|
|
64
|
+
* });
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
function makeExclusiveStartKeyFromItem(item, keyNames) {
|
|
68
|
+
if (item) {
|
|
69
|
+
const eks = {};
|
|
70
|
+
for (const name of dedupe(keyNames)) {
|
|
71
|
+
if (!(name in item)) {
|
|
72
|
+
throw new Error(`ExclusiveStartKey: item is missing key attribute "${name}"`);
|
|
73
|
+
}
|
|
74
|
+
eks[name] = item[name];
|
|
75
|
+
}
|
|
76
|
+
return eks;
|
|
77
|
+
}
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
function encodeCursor(cursor) {
|
|
81
|
+
return Buffer.from(JSON.stringify(cursor)).toString('base64url');
|
|
82
|
+
}
|
|
83
|
+
function decodeCursor(encoded) {
|
|
84
|
+
if (encoded) {
|
|
85
|
+
return JSON.parse(Buffer.from(encoded, 'base64url').toString('utf8'));
|
|
86
|
+
}
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
function getExclusiveStartKey(previous, direction) {
|
|
90
|
+
if (!direction) {
|
|
91
|
+
direction = 'next';
|
|
92
|
+
}
|
|
93
|
+
if (previous) {
|
|
94
|
+
if (previous.d === 'p' && previous.p === 1) {
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
if (previous.p === 1 && direction === 'prev') {
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
if (previous.d === 'n' && direction === 'next') {
|
|
101
|
+
// If trying to go next but there's no LastEvaluatedKey, we're past the last page
|
|
102
|
+
// Return the first key to query from there with ScanIndexForward=true
|
|
103
|
+
// This will return an empty result set instead of wrapping to page 1
|
|
104
|
+
if (previous.l === undefined) {
|
|
105
|
+
return previous.f;
|
|
106
|
+
}
|
|
107
|
+
return previous.l;
|
|
108
|
+
}
|
|
109
|
+
if (previous.d === 'n' && direction === 'prev') {
|
|
110
|
+
return previous.f;
|
|
111
|
+
}
|
|
112
|
+
if (previous.d === 'p' && direction === 'prev') {
|
|
113
|
+
return previous.l;
|
|
114
|
+
}
|
|
115
|
+
if (previous.d === 'p' && direction === 'next') {
|
|
116
|
+
return previous.f;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
121
|
+
function getNextPage(previous, direction) {
|
|
122
|
+
if (previous) {
|
|
123
|
+
if (direction === 'next') {
|
|
124
|
+
return previous.p + 1;
|
|
125
|
+
}
|
|
126
|
+
if (direction === 'prev') {
|
|
127
|
+
return previous.p - 1;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return 1;
|
|
131
|
+
}
|
|
132
|
+
function encodeDirection(direction) {
|
|
133
|
+
if (direction === 'prev') {
|
|
134
|
+
return 'p';
|
|
135
|
+
}
|
|
136
|
+
return 'n';
|
|
137
|
+
}
|
|
138
|
+
function getDirection(previous, direction) {
|
|
139
|
+
if (direction === 'prev' && previous?.p === 1) {
|
|
140
|
+
return 'next';
|
|
141
|
+
}
|
|
142
|
+
if (direction === 'prev') {
|
|
143
|
+
return 'prev';
|
|
144
|
+
}
|
|
145
|
+
return 'next';
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Executes a paginated DynamoDB query with full cursor-based pagination support.
|
|
149
|
+
*
|
|
150
|
+
* This helper encapsulates all pagination logic including:
|
|
151
|
+
* - Cursor encoding/decoding
|
|
152
|
+
* - ExclusiveStartKey calculation
|
|
153
|
+
* - Bidirectional pagination (next/prev)
|
|
154
|
+
* - First/last key tracking
|
|
155
|
+
* - Automatic item ordering
|
|
156
|
+
*
|
|
157
|
+
* @param params Configuration for the query and item mapping
|
|
158
|
+
* @param params.client DynamoDB Document Client instance
|
|
159
|
+
* @param params.query QueryCommand input (without ExclusiveStartKey, Limit, ScanIndexForward)
|
|
160
|
+
* @param params.keyAttributes Array of key attribute names for the table/index being queried
|
|
161
|
+
* @param params.mapItem Function to transform raw DynamoDB items into desired format
|
|
162
|
+
* @param pagination Pagination parameters from the client
|
|
163
|
+
* @param pagination.cursor Base64-encoded cursor from previous request
|
|
164
|
+
* @param pagination.direction Direction to paginate ('next' or 'prev')
|
|
165
|
+
* @param pagination.limit Number of items per page (locked after first request)
|
|
166
|
+
* @param defaultScanForward Controls the default scan direction. When true, 'next' scans forward (ascending) and 'prev' scans backward (descending). When false, the behavior is inverted.
|
|
167
|
+
* @returns Paginated result with items, cursor, hasNext flag, and page number
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```typescript
|
|
171
|
+
* return executePaginatedQuery(
|
|
172
|
+
* {
|
|
173
|
+
* client: getDynamoDBDocumentClient(),
|
|
174
|
+
* query: {
|
|
175
|
+
* TableName: 'MyTable',
|
|
176
|
+
* IndexName: 'Gs1',
|
|
177
|
+
* KeyConditionExpression: 'Gs1Pk = :pk',
|
|
178
|
+
* ExpressionAttributeValues: { ':pk': 'Agency#123' },
|
|
179
|
+
* },
|
|
180
|
+
* keyAttributes: ['Pk', 'Sk', 'Gs1Pk', 'Gs1Sk'],
|
|
181
|
+
* mapItem: (item) => item.Detail,
|
|
182
|
+
* },
|
|
183
|
+
* { cursor: '...', direction: 'next', limit: 10 },
|
|
184
|
+
* true // defaultScanForward
|
|
185
|
+
* );
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
188
|
+
export async function executePaginatedQuery(params, pagination, defaultScanForward) {
|
|
189
|
+
const { client, query, keyAttributes, mapItem } = params;
|
|
190
|
+
// Decode cursor and calculate pagination parameters
|
|
191
|
+
const decodedCursor = decodeCursor(pagination?.cursor);
|
|
192
|
+
const limit = decodedCursor?.i ?? pagination?.limit ?? 25;
|
|
193
|
+
// Validate limit
|
|
194
|
+
if (limit <= 0) {
|
|
195
|
+
throw new Error('Pagination limit must be a positive number');
|
|
196
|
+
}
|
|
197
|
+
const exclusiveStartKey = getExclusiveStartKey(decodedCursor, pagination?.direction);
|
|
198
|
+
const direction = getDirection(decodedCursor, pagination?.direction);
|
|
199
|
+
// Execute query with calculated pagination parameters
|
|
200
|
+
const result = await client.send(new QueryCommand({
|
|
201
|
+
...query,
|
|
202
|
+
Limit: limit,
|
|
203
|
+
ScanIndexForward: defaultScanForward
|
|
204
|
+
? direction === 'next'
|
|
205
|
+
: direction === 'prev',
|
|
206
|
+
ExclusiveStartKey: exclusiveStartKey,
|
|
207
|
+
}));
|
|
208
|
+
// Build cursor for next request
|
|
209
|
+
const page = getNextPage(decodedCursor, direction);
|
|
210
|
+
const firstItem = result.Items?.[0];
|
|
211
|
+
const newCursor = {
|
|
212
|
+
l: result.LastEvaluatedKey,
|
|
213
|
+
f: makeExclusiveStartKeyFromItem(firstItem, keyAttributes),
|
|
214
|
+
p: page,
|
|
215
|
+
d: encodeDirection(direction),
|
|
216
|
+
i: limit,
|
|
217
|
+
};
|
|
218
|
+
// Map and order items
|
|
219
|
+
const items = (result.Items ?? []).map(mapItem);
|
|
220
|
+
return {
|
|
221
|
+
items: direction === 'next' ? items : items.reverse(),
|
|
222
|
+
cursor: encodeCursor(newCursor),
|
|
223
|
+
hasNext: !!result.LastEvaluatedKey,
|
|
224
|
+
page,
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Executes a paginated DynamoDB scan with cursor-based pagination support.
|
|
229
|
+
*
|
|
230
|
+
* Similar to executePaginatedQuery but for Scan operations. Note that Scan operations
|
|
231
|
+
* are unordered by nature and do not support scan direction control (unlike Query operations).
|
|
232
|
+
* Scan operations only support forward pagination (no bidirectional navigation).
|
|
233
|
+
*
|
|
234
|
+
* @param params Configuration for the scan and item mapping
|
|
235
|
+
* @param params.client DynamoDB Document Client instance
|
|
236
|
+
* @param params.scan ScanCommand input (without ExclusiveStartKey or Limit)
|
|
237
|
+
* @param params.keyNames Array of key attribute names for the table
|
|
238
|
+
* @param params.mapItem Function to transform raw DynamoDB items into desired format
|
|
239
|
+
* @param pagination Pagination parameters from the client
|
|
240
|
+
* @param pagination.cursor Base64-encoded cursor from previous request
|
|
241
|
+
* @param pagination.limit Number of items per page (locked after first request)
|
|
242
|
+
* @returns Paginated result with items, cursor, hasNext flag, and page number
|
|
243
|
+
*
|
|
244
|
+
* @example
|
|
245
|
+
* ```typescript
|
|
246
|
+
* return executePaginatedScan(
|
|
247
|
+
* {
|
|
248
|
+
* client: getDynamoDBDocumentClient(),
|
|
249
|
+
* scan: {
|
|
250
|
+
* TableName: 'MyTable',
|
|
251
|
+
* FilterExpression: 'attribute_exists(#attr)',
|
|
252
|
+
* ExpressionAttributeNames: { '#attr': 'myAttribute' },
|
|
253
|
+
* },
|
|
254
|
+
* keyNames: ['Pk', 'Sk'],
|
|
255
|
+
* mapItem: (item) => item.Detail,
|
|
256
|
+
* },
|
|
257
|
+
* { cursor: '...', limit: 10 }
|
|
258
|
+
* );
|
|
259
|
+
* ```
|
|
260
|
+
*/
|
|
261
|
+
export async function executePaginatedScan(params, pagination) {
|
|
262
|
+
const { client, scan, keyNames, mapItem } = params;
|
|
263
|
+
// Decode cursor and calculate pagination parameters
|
|
264
|
+
const decodedCursor = decodeCursor(pagination?.cursor);
|
|
265
|
+
const limit = decodedCursor?.i ?? pagination?.limit ?? 25;
|
|
266
|
+
// Validate limit
|
|
267
|
+
if (limit <= 0) {
|
|
268
|
+
throw new Error('Pagination limit must be a positive number');
|
|
269
|
+
}
|
|
270
|
+
// For scans, only forward pagination is supported
|
|
271
|
+
const exclusiveStartKey = decodedCursor?.l;
|
|
272
|
+
// Execute scan with calculated pagination parameters
|
|
273
|
+
const result = await client.send(new ScanCommand({
|
|
274
|
+
...scan,
|
|
275
|
+
Limit: limit,
|
|
276
|
+
ExclusiveStartKey: exclusiveStartKey,
|
|
277
|
+
}));
|
|
278
|
+
// Build cursor for next request
|
|
279
|
+
const page = (decodedCursor?.p ?? 0) + 1;
|
|
280
|
+
const firstItem = result.Items?.[0];
|
|
281
|
+
const newCursor = {
|
|
282
|
+
l: result.LastEvaluatedKey,
|
|
283
|
+
f: makeExclusiveStartKeyFromItem(firstItem, keyNames),
|
|
284
|
+
p: page,
|
|
285
|
+
d: 'n', // Scans only support forward direction
|
|
286
|
+
i: limit,
|
|
287
|
+
};
|
|
288
|
+
// Map items
|
|
289
|
+
const items = (result.Items ?? []).map(mapItem);
|
|
290
|
+
return {
|
|
291
|
+
items,
|
|
292
|
+
cursor: encodeCursor(newCursor),
|
|
293
|
+
hasNext: !!result.LastEvaluatedKey,
|
|
294
|
+
page,
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
//# sourceMappingURL=dynamodb.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dynamodb.mjs","sourceRoot":"","sources":["../src/dynamodb.mts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,0BAA0B,CAAC;AACxD,OAAO,EACL,sBAAsB,EACtB,YAAY,EAGZ,WAAW,EAEX,UAAU,GAEX,MAAM,uBAAuB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IAE3C,qDAAqD;IACrD,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,IAAI,CAC9B,IAAI,WAAW,CAAC;QACd,GAAG,IAAI;QACP,KAAK,EAAE,KAAK;QACZ,iBAAiB,EAAE,iBAAiB;KACrC,CAAC,CACH,CAAC;IAEF,gCAAgC;IAChC,MAAM,IAAI,GAAG,CAAC,aAAa,EAAE,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;IACzC,MAAM,SAAS,GAAG,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;IACpC,MAAM,SAAS,GAAW;QACxB,CAAC,EAAE,MAAM,CAAC,gBAAgB;QAC1B,CAAC,EAAE,6BAA6B,CAAC,SAAS,EAAE,QAAQ,CAAC;QACrD,CAAC,EAAE,IAAI;QACP,CAAC,EAAE,GAAG,EAAE,uCAAuC;QAC/C,CAAC,EAAE,KAAK;KACT,CAAC;IAEF,YAAY;IACZ,MAAM,KAAK,GAAQ,CAAC,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAErD,OAAO;QACL,KAAK;QACL,MAAM,EAAE,YAAY,CAAC,SAAS,CAAC;QAC/B,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC,gBAAgB;QAClC,IAAI;KACL,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { EventBridgeClient } from '@aws-sdk/client-eventbridge';
|
|
2
|
+
export declare function getEventBridgeClient(region?: string): EventBridgeClient;
|
|
3
|
+
export declare function sendEvent(eventBusName: string, source: string, detailType: string, detail: unknown, region?: string): Promise<import("@aws-sdk/client-eventbridge").PutEventsCommandOutput>;
|
|
4
|
+
export interface EventBridgeEvent {
|
|
5
|
+
source: string;
|
|
6
|
+
detailType: string;
|
|
7
|
+
detail: unknown;
|
|
8
|
+
}
|
|
9
|
+
export declare function sendEvents(eventBusName: string, events: EventBridgeEvent[], region?: string): Promise<import("@aws-sdk/client-eventbridge").PutEventsCommandOutput>;
|
|
10
|
+
//# sourceMappingURL=event-bridge.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-bridge.d.mts","sourceRoot":"","sources":["../src/event-bridge.mts"],"names":[],"mappings":"AAAA,OAAO,EAAC,iBAAiB,EAAmB,MAAM,6BAA6B,CAAC;AAIhF,wBAAgB,oBAAoB,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,iBAAiB,CAIvE;AAED,wBAAsB,SAAS,CAC7B,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,OAAO,EACf,MAAM,CAAC,EAAE,MAAM,yEAchB;AAED,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,wBAAsB,UAAU,CAC9B,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,gBAAgB,EAAE,EAC1B,MAAM,CAAC,EAAE,MAAM,yEAYhB"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { EventBridgeClient, PutEventsCommand } from '@aws-sdk/client-eventbridge';
|
|
2
|
+
let eventBridgeClient = undefined;
|
|
3
|
+
export function getEventBridgeClient(region) {
|
|
4
|
+
if (eventBridgeClient)
|
|
5
|
+
return eventBridgeClient;
|
|
6
|
+
eventBridgeClient = new EventBridgeClient({ region });
|
|
7
|
+
return eventBridgeClient;
|
|
8
|
+
}
|
|
9
|
+
export async function sendEvent(eventBusName, source, detailType, detail, region) {
|
|
10
|
+
const client = getEventBridgeClient(region);
|
|
11
|
+
const command = new PutEventsCommand({
|
|
12
|
+
Entries: [
|
|
13
|
+
{
|
|
14
|
+
Source: source,
|
|
15
|
+
DetailType: detailType,
|
|
16
|
+
Detail: JSON.stringify(detail),
|
|
17
|
+
EventBusName: eventBusName,
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
|
+
});
|
|
21
|
+
return await client.send(command);
|
|
22
|
+
}
|
|
23
|
+
export async function sendEvents(eventBusName, events, region) {
|
|
24
|
+
const client = getEventBridgeClient(region);
|
|
25
|
+
const command = new PutEventsCommand({
|
|
26
|
+
Entries: events.map((event) => ({
|
|
27
|
+
Source: event.source,
|
|
28
|
+
DetailType: event.detailType,
|
|
29
|
+
Detail: JSON.stringify(event.detail),
|
|
30
|
+
EventBusName: eventBusName,
|
|
31
|
+
})),
|
|
32
|
+
});
|
|
33
|
+
return await client.send(command);
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=event-bridge.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-bridge.mjs","sourceRoot":"","sources":["../src/event-bridge.mts"],"names":[],"mappings":"AAAA,OAAO,EAAC,iBAAiB,EAAE,gBAAgB,EAAC,MAAM,6BAA6B,CAAC;AAEhF,IAAI,iBAAiB,GAAkC,SAAS,CAAC;AAEjE,MAAM,UAAU,oBAAoB,CAAC,MAAe;IAClD,IAAI,iBAAiB;QAAE,OAAO,iBAAiB,CAAC;IAChD,iBAAiB,GAAG,IAAI,iBAAiB,CAAC,EAAC,MAAM,EAAC,CAAC,CAAC;IACpD,OAAO,iBAAiB,CAAC;AAC3B,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,YAAoB,EACpB,MAAc,EACd,UAAkB,EAClB,MAAe,EACf,MAAe;IAEf,MAAM,MAAM,GAAG,oBAAoB,CAAC,MAAM,CAAC,CAAC;IAC5C,MAAM,OAAO,GAAG,IAAI,gBAAgB,CAAC;QACnC,OAAO,EAAE;YACP;gBACE,MAAM,EAAE,MAAM;gBACd,UAAU,EAAE,UAAU;gBACtB,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;gBAC9B,YAAY,EAAE,YAAY;aAC3B;SACF;KACF,CAAC,CAAC;IACH,OAAO,MAAM,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AACpC,CAAC;AAQD,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,YAAoB,EACpB,MAA0B,EAC1B,MAAe;IAEf,MAAM,MAAM,GAAG,oBAAoB,CAAC,MAAM,CAAC,CAAC;IAC5C,MAAM,OAAO,GAAG,IAAI,gBAAgB,CAAC;QACnC,OAAO,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;YAC9B,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,UAAU,EAAE,KAAK,CAAC,UAAU;YAC5B,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC;YACpC,YAAY,EAAE,YAAY;SAC3B,CAAC,CAAC;KACJ,CAAC,CAAC;IACH,OAAO,MAAM,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AACpC,CAAC"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
+
export * from './event-bridge.mjs';
|
|
2
|
+
export * from './dynamodb.mjs';
|
|
1
3
|
export * from './region.mjs';
|
|
4
|
+
export * from './s3.mjs';
|
|
2
5
|
export * from './secrets-manager.mjs';
|
|
3
6
|
export * from './ses.mjs';
|
|
7
|
+
export * from './sqs.mjs';
|
|
4
8
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.mts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,uBAAuB,CAAC;AACtC,cAAc,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.mts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,uBAAuB,CAAC;AACtC,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC"}
|
package/dist/index.mjs
CHANGED
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.mts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,uBAAuB,CAAC;AACtC,cAAc,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.mts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,uBAAuB,CAAC;AACtC,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC"}
|
package/dist/s3.d.mts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
+
import { S3Client } from '@aws-sdk/client-s3';
|
|
4
|
+
export declare function getS3Client(region?: string): S3Client;
|
|
5
|
+
export interface PutFileInput {
|
|
6
|
+
bucketName: string;
|
|
7
|
+
key: string;
|
|
8
|
+
data: Buffer;
|
|
9
|
+
contentType: string;
|
|
10
|
+
region?: string;
|
|
11
|
+
}
|
|
12
|
+
export declare function putFile(input: PutFileInput): Promise<void>;
|
|
13
|
+
export interface GetSignedGetObjectUrlInput {
|
|
14
|
+
bucketName: string;
|
|
15
|
+
key: string;
|
|
16
|
+
region?: string;
|
|
17
|
+
expiresIn?: number;
|
|
18
|
+
}
|
|
19
|
+
export declare function getSignedGetObjectUrl(input: GetSignedGetObjectUrlInput): Promise<string>;
|
|
20
|
+
export interface GetSignedPutObjectUrlInput {
|
|
21
|
+
bucketName: string;
|
|
22
|
+
key: string;
|
|
23
|
+
contentType: string;
|
|
24
|
+
region?: string;
|
|
25
|
+
expiresIn?: number;
|
|
26
|
+
metadata?: Record<string, string>;
|
|
27
|
+
}
|
|
28
|
+
export declare function getSignedPutObjectUrl(input: GetSignedPutObjectUrlInput): Promise<string>;
|
|
29
|
+
export interface GetObjectInput {
|
|
30
|
+
bucketName: string;
|
|
31
|
+
key: string;
|
|
32
|
+
region?: string;
|
|
33
|
+
}
|
|
34
|
+
export interface GetObjectOutput {
|
|
35
|
+
buffer: Buffer;
|
|
36
|
+
fileName: string;
|
|
37
|
+
contentType?: string;
|
|
38
|
+
metadata?: Record<string, string>;
|
|
39
|
+
}
|
|
40
|
+
export declare function getFile(input: GetObjectInput): Promise<GetObjectOutput | null>;
|
|
41
|
+
export interface ListObjectsInput {
|
|
42
|
+
bucketName: string;
|
|
43
|
+
prefix: string;
|
|
44
|
+
region?: string;
|
|
45
|
+
}
|
|
46
|
+
export interface S3ObjectInfo {
|
|
47
|
+
key: string;
|
|
48
|
+
fileName: string;
|
|
49
|
+
contentType?: string;
|
|
50
|
+
metadata?: Record<string, string>;
|
|
51
|
+
lastModified?: Date;
|
|
52
|
+
size?: number;
|
|
53
|
+
}
|
|
54
|
+
export declare function listObjectsWithMetadata(input: ListObjectsInput): Promise<S3ObjectInfo[]>;
|
|
55
|
+
//# sourceMappingURL=s3.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"s3.d.mts","sourceRoot":"","sources":["../src/s3.mts"],"names":[],"mappings":";;AAAA,OAAO,EAGL,QAAQ,EAGT,MAAM,oBAAoB,CAAC;AAK5B,wBAAgB,WAAW,CAAC,MAAM,CAAC,EAAE,MAAM,YAO1C;AAED,MAAM,WAAW,YAAY;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,wBAAsB,OAAO,CAAC,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AE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,YAAY,CAAC,EAAE,IAAI,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,wBAAsB,uBAAuB,CAC3C,KAAK,EAAE,gBAAgB,GACtB,OAAO,CAAC,YAAY,EAAE,CAAC,CA8CzB"}
|
package/dist/s3.mjs
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { GetObjectCommand, PutObjectCommand, S3Client, S3ServiceException, ListObjectsV2Command, } from '@aws-sdk/client-s3';
|
|
2
|
+
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
|
|
3
|
+
const clients = {};
|
|
4
|
+
export function getS3Client(region) {
|
|
5
|
+
let client = clients[region ?? 'unspecified'];
|
|
6
|
+
if (!client) {
|
|
7
|
+
client = new S3Client({ region });
|
|
8
|
+
clients[region ?? 'unspecified'] = client;
|
|
9
|
+
}
|
|
10
|
+
return client;
|
|
11
|
+
}
|
|
12
|
+
export async function putFile(input) {
|
|
13
|
+
await getS3Client(input.region).send(new PutObjectCommand({
|
|
14
|
+
Bucket: input.bucketName,
|
|
15
|
+
Key: input.key,
|
|
16
|
+
Body: input.data,
|
|
17
|
+
ContentType: input.contentType,
|
|
18
|
+
}));
|
|
19
|
+
}
|
|
20
|
+
export async function getSignedGetObjectUrl(input) {
|
|
21
|
+
const client = getS3Client(input.region);
|
|
22
|
+
const command = new GetObjectCommand({
|
|
23
|
+
Bucket: input.bucketName,
|
|
24
|
+
Key: input.key,
|
|
25
|
+
});
|
|
26
|
+
return await getSignedUrl(client, command, {
|
|
27
|
+
expiresIn: input.expiresIn ?? 300, // Default is 5 minutes
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
export async function getSignedPutObjectUrl(input) {
|
|
31
|
+
const client = getS3Client(input.region);
|
|
32
|
+
const comment = new PutObjectCommand({
|
|
33
|
+
Bucket: input.bucketName,
|
|
34
|
+
Key: input.key,
|
|
35
|
+
Metadata: input.metadata,
|
|
36
|
+
ContentType: input.contentType,
|
|
37
|
+
});
|
|
38
|
+
return await getSignedUrl(client, comment, {
|
|
39
|
+
expiresIn: input.expiresIn ?? 300, // Default is 5 minutes
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
export async function getFile(input) {
|
|
43
|
+
try {
|
|
44
|
+
const response = await getS3Client(input.region).send(new GetObjectCommand({
|
|
45
|
+
Bucket: input.bucketName,
|
|
46
|
+
Key: input.key,
|
|
47
|
+
}));
|
|
48
|
+
// stream the body into a Buffer
|
|
49
|
+
const stream = response.Body;
|
|
50
|
+
const chunks = [];
|
|
51
|
+
for await (const chunk of stream) {
|
|
52
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
53
|
+
}
|
|
54
|
+
const fileName = input.key.split('/').pop() || input.key;
|
|
55
|
+
return {
|
|
56
|
+
fileName,
|
|
57
|
+
buffer: Buffer.concat(chunks),
|
|
58
|
+
contentType: response.ContentType ?? undefined,
|
|
59
|
+
metadata: response.Metadata,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
catch (err) {
|
|
63
|
+
// err may be an S3ServiceException
|
|
64
|
+
if (err instanceof S3ServiceException && err.name === 'NoSuchKey') {
|
|
65
|
+
// not found — return null or handle as you like
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
// re-throw other errors
|
|
69
|
+
throw err;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
export async function listObjectsWithMetadata(input) {
|
|
73
|
+
const client = getS3Client(input.region);
|
|
74
|
+
// First, list all objects with the prefix
|
|
75
|
+
const listResponse = await client.send(new ListObjectsV2Command({
|
|
76
|
+
Bucket: input.bucketName,
|
|
77
|
+
Prefix: input.prefix,
|
|
78
|
+
}));
|
|
79
|
+
if (!listResponse.Contents || listResponse.Contents.length === 0) {
|
|
80
|
+
return [];
|
|
81
|
+
}
|
|
82
|
+
// For each object, get its metadata by making a HEAD request (GetObjectCommand without Body)
|
|
83
|
+
const objectInfoPromises = listResponse.Contents.map(async (obj) => {
|
|
84
|
+
if (!obj.Key)
|
|
85
|
+
return null;
|
|
86
|
+
try {
|
|
87
|
+
const headResponse = await client.send(new GetObjectCommand({
|
|
88
|
+
Bucket: input.bucketName,
|
|
89
|
+
Key: obj.Key,
|
|
90
|
+
}));
|
|
91
|
+
const fileName = obj.Key.split('/').pop() || obj.Key;
|
|
92
|
+
return {
|
|
93
|
+
key: obj.Key,
|
|
94
|
+
fileName,
|
|
95
|
+
contentType: headResponse.ContentType,
|
|
96
|
+
metadata: headResponse.Metadata,
|
|
97
|
+
lastModified: obj.LastModified,
|
|
98
|
+
size: obj.Size,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
catch (err) {
|
|
102
|
+
// If we can't get metadata for an object, skip it
|
|
103
|
+
console.warn(`Failed to get metadata for ${obj.Key}:`, err);
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
const results = await Promise.all(objectInfoPromises);
|
|
108
|
+
return results.filter((result) => result !== null);
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=s3.mjs.map
|
package/dist/s3.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"s3.mjs","sourceRoot":"","sources":["../src/s3.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,QAAQ,EACR,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAC,YAAY,EAAC,MAAM,+BAA+B,CAAC;AAE3D,MAAM,OAAO,GAA6B,EAAE,CAAC;AAE7C,MAAM,UAAU,WAAW,CAAC,MAAe;IACzC,IAAI,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,aAAa,CAAC,CAAC;IAC9C,IAAI,CAAC,MAAM,E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AG,EAAE,CAAC;YACb,kDAAkD;YAClD,OAAO,CAAC,IAAI,CAAC,8BAA8B,GAAG,CAAC,GAAG,GAAG,EAAE,GAAG,CAAC,CAAC;YAC5D,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;IACtD,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,KAAK,IAAI,CAAmB,CAAC;AACvE,CAAC"}
|
package/dist/sqs.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sqs.d.mts","sourceRoot":"","sources":["../src/sqs.mts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAIlE,wBAAgB,YAAY,CAAC,MAAM,CAAC,EAAE,MAAM,aAO3C;AAED,wBAAsB,WAAW,CAC/B,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,EACnB,MAAM,CAAC,EAAE,MAAM,iBAQhB"}
|
package/dist/sqs.mjs
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { SendMessageCommand, SQSClient } from '@aws-sdk/client-sqs';
|
|
2
|
+
const clients = {};
|
|
3
|
+
export function getSQSClient(region) {
|
|
4
|
+
let client = clients[region ?? 'unspecified'];
|
|
5
|
+
if (!client) {
|
|
6
|
+
client = new SQSClient({ region });
|
|
7
|
+
clients[region ?? 'unspecified'] = client;
|
|
8
|
+
}
|
|
9
|
+
return client;
|
|
10
|
+
}
|
|
11
|
+
export async function sendMessage(queueUrl, messageBody, region) {
|
|
12
|
+
await getSQSClient(region).send(new SendMessageCommand({
|
|
13
|
+
QueueUrl: queueUrl,
|
|
14
|
+
MessageBody: messageBody,
|
|
15
|
+
}));
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=sqs.mjs.map
|
package/dist/sqs.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sqs.mjs","sourceRoot":"","sources":["../src/sqs.mts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAE,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAElE,MAAM,OAAO,GAA8B,EAAE,CAAC;AAE9C,MAAM,UAAU,YAAY,CAAC,MAAe;IAC1C,IAAI,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,aAAa,CAAC,CAAC;IAC9C,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,GAAG,IAAI,SAAS,CAAC,EAAC,MAAM,EAAC,CAAC,CAAC;QACjC,OAAO,CAAC,MAAM,IAAI,aAAa,CAAC,GAAG,MAAM,CAAC;IAC5C,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,QAAgB,EAChB,WAAmB,EACnB,MAAe;IAEf,MAAM,YAAY,CAAC,MAAM,CAAC,CAAC,IAAI,CAC7B,IAAI,kBAAkB,CAAC;QACrB,QAAQ,EAAE,QAAQ;QAClB,WAAW,EAAE,WAAW;KACzB,CAAC,CACH,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nr1e/aws",
|
|
3
3
|
"description": "Provides common AWS utilities",
|
|
4
|
-
"version": "0.0.0-snapshot-
|
|
4
|
+
"version": "0.0.0-snapshot-20251228155206",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "NR1E, Inc.",
|
|
7
7
|
"publishConfig": {
|
|
@@ -25,9 +25,15 @@
|
|
|
25
25
|
"vitest": "4.0.6"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
+
"@aws-sdk/client-dynamodb": "^3.839.0",
|
|
29
|
+
"@aws-sdk/client-eventbridge": "^3.839.0",
|
|
30
|
+
"@aws-sdk/client-s3": "^3.839.0",
|
|
28
31
|
"@aws-sdk/client-secrets-manager": "^3.839.0",
|
|
29
32
|
"@aws-sdk/client-ses": "^3.839.0",
|
|
30
|
-
"@
|
|
33
|
+
"@aws-sdk/client-sqs": "^3.839.0",
|
|
34
|
+
"@aws-sdk/lib-dynamodb": "^3.839.0",
|
|
35
|
+
"@aws-sdk/s3-request-presigner": "^3.839.0",
|
|
36
|
+
"@nr1e/commons": "0.0.0-snapshot-20251228155206"
|
|
31
37
|
},
|
|
32
38
|
"exports": {
|
|
33
39
|
".": {
|