@saidsef/aws-kinesis-local 1.4.0 → 1.6.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/dist/cli.js CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { numberOption, parseArguments, stringOption } from './arguments.js';
3
+ import { isLogLevel, LOG_LEVELS } from './logger.js';
3
4
  import { defaultOptions, start } from './server.js';
4
5
  const HELP = [
5
6
  '',
@@ -18,6 +19,7 @@ const HELP = [
18
19
  '--deleteStreamMs <ms> Amount of time streams stay in DELETING state (default: 500)',
19
20
  '--updateStreamMs <ms> Amount of time streams stay in UPDATING state (default: 500)',
20
21
  '--shardLimit <limit> Shard limit for error reporting (default: 10)',
22
+ '--logLevel <level> Least severe level to log: error, warn, info, debug or trace (default: warn)',
21
23
  '',
22
24
  'Report bugs at github.com/saidsef/aws-kinesis-local/issues',
23
25
  ].join('\n');
@@ -27,6 +29,11 @@ if (args.help) {
27
29
  }
28
30
  else {
29
31
  const defaults = defaultOptions();
32
+ const logLevel = stringOption(args.logLevel) ?? defaults.logLevel;
33
+ if (!isLogLevel(logLevel)) {
34
+ console.error(`Unknown log level ${logLevel}. Use ${LOG_LEVELS.join(', ')}.`);
35
+ process.exit(1);
36
+ }
30
37
  const server = await start({
31
38
  port: numberOption(args.port, defaults.port) || defaults.port,
32
39
  path: stringOption(args.path),
@@ -37,6 +44,7 @@ else {
37
44
  deleteStreamMs: numberOption(args.deleteStreamMs, defaults.deleteStreamMs),
38
45
  updateStreamMs: numberOption(args.updateStreamMs, defaults.updateStreamMs),
39
46
  shardLimit: numberOption(args.shardLimit, defaults.shardLimit),
47
+ logLevel,
40
48
  });
41
49
  const { address, port } = server.address;
42
50
  console.log('Listening at %s://%s:%s', server.protocol, address, port);
@@ -0,0 +1,28 @@
1
+ export interface Credentials {
2
+ accessKeyId: string;
3
+ secretAccessKey: string;
4
+ }
5
+ export interface S3Client {
6
+ endpoint: string;
7
+ region: string;
8
+ credentials: Credentials;
9
+ }
10
+ export interface S3Object {
11
+ bucket: string;
12
+ key: string;
13
+ body: Buffer | string;
14
+ headers?: Record<string, string>;
15
+ }
16
+ export interface SignableRequest {
17
+ method: string;
18
+ path: string;
19
+ query?: Record<string, string>;
20
+ headers: Record<string, string>;
21
+ }
22
+ export declare class S3Error extends Error {
23
+ readonly statusCode: number;
24
+ readonly code: string | undefined;
25
+ constructor(statusCode: number, code: string | undefined, message: string);
26
+ }
27
+ export declare function authorization(request: SignableRequest, region: string, credentials: Credentials): string;
28
+ export declare function putObject(client: S3Client, object: S3Object): Promise<void>;
@@ -0,0 +1,108 @@
1
+ import { createHash, createHmac } from 'node:crypto';
2
+ import { request as httpRequest } from 'node:http';
3
+ import { request as httpsRequest } from 'node:https';
4
+ export class S3Error extends Error {
5
+ statusCode;
6
+ code;
7
+ constructor(statusCode, code, message) {
8
+ super(message);
9
+ this.name = 'S3Error';
10
+ this.statusCode = statusCode;
11
+ this.code = code;
12
+ }
13
+ }
14
+ function uriEncode(value) {
15
+ return encodeURIComponent(value).replace(/[!'()*]/g, char => `%${char.charCodeAt(0).toString(16).toUpperCase()}`);
16
+ }
17
+ function encodePath(path) {
18
+ return path.split('/').map(uriEncode).join('/');
19
+ }
20
+ function sha256(data) {
21
+ return createHash('sha256').update(data).digest('hex');
22
+ }
23
+ function hmac(key, data) {
24
+ return createHmac('sha256', key).update(data).digest();
25
+ }
26
+ function byName(a, b) {
27
+ return a.name < b.name ? -1 : a.name > b.name ? 1 : 0;
28
+ }
29
+ function canonicalQuery(query) {
30
+ return Object.entries(query)
31
+ .map(([name, value]) => ({ name: uriEncode(name), value: uriEncode(value) }))
32
+ .sort(byName)
33
+ .map(({ name, value }) => `${name}=${value}`)
34
+ .join('&');
35
+ }
36
+ function canonicalHeaders(headers) {
37
+ return Object.entries(headers)
38
+ .map(([name, value]) => ({ name: name.toLowerCase(), value: value.trim().replace(/\s+/g, ' ') }))
39
+ .sort(byName);
40
+ }
41
+ function headerValue(headers, name) {
42
+ const value = headers.find(header => header.name === name)?.value;
43
+ if (value === undefined)
44
+ throw new Error(`A signed S3 request needs the ${name} header.`);
45
+ return value;
46
+ }
47
+ export function authorization(request, region, credentials) {
48
+ const headers = canonicalHeaders(request.headers);
49
+ const timestamp = headerValue(headers, 'x-amz-date');
50
+ const date = timestamp.slice(0, 8);
51
+ const scope = `${date}/${region}/s3/aws4_request`;
52
+ const signedHeaders = headers.map(({ name }) => name).join(';');
53
+ const canonicalRequest = [
54
+ request.method,
55
+ encodePath(request.path),
56
+ canonicalQuery(request.query ?? {}),
57
+ headers.map(({ name, value }) => `${name}:${value}\n`).join(''),
58
+ signedHeaders,
59
+ headerValue(headers, 'x-amz-content-sha256'),
60
+ ].join('\n');
61
+ const stringToSign = ['AWS4-HMAC-SHA256', timestamp, scope, sha256(canonicalRequest)].join('\n');
62
+ const signingKey = [date, region, 's3', 'aws4_request'].reduce(hmac, `AWS4${credentials.secretAccessKey}`);
63
+ const signature = createHmac('sha256', signingKey).update(stringToSign).digest('hex');
64
+ return `AWS4-HMAC-SHA256 Credential=${credentials.accessKeyId}/${scope},SignedHeaders=${signedHeaders},Signature=${signature}`;
65
+ }
66
+ function xmlElement(xml, name) {
67
+ return xml.match(new RegExp(`<${name}>([^<]*)</${name}>`))?.[1];
68
+ }
69
+ function uploadError(statusCode, body, object) {
70
+ const code = xmlElement(body, 'Code');
71
+ const detail = xmlElement(body, 'Message');
72
+ let message = `PutObject ${object.bucket}/${object.key} failed with status ${statusCode}`;
73
+ if (code)
74
+ message += ` and error code ${code}`;
75
+ if (detail)
76
+ message += `: ${detail}`;
77
+ return new S3Error(statusCode, code, message);
78
+ }
79
+ export function putObject(client, object) {
80
+ const url = new URL(client.endpoint);
81
+ const path = `${decodeURIComponent(url.pathname).replace(/\/+$/, '')}/${object.bucket}/${object.key}`;
82
+ const body = typeof object.body === 'string' ? Buffer.from(object.body) : object.body;
83
+ const headers = {
84
+ ...object.headers,
85
+ host: url.host,
86
+ 'content-length': String(body.length),
87
+ 'x-amz-content-sha256': sha256(body),
88
+ 'x-amz-date': new Date().toISOString().replace(/[-:]|\.\d{3}/g, ''),
89
+ };
90
+ headers.authorization = authorization({ method: 'PUT', path, headers }, client.region, client.credentials);
91
+ const send = url.protocol === 'https:' ? httpsRequest : httpRequest;
92
+ return new Promise((resolve, reject) => {
93
+ const req = send(url, { method: 'PUT', path: encodePath(path), headers }, res => {
94
+ const chunks = [];
95
+ res.on('data', chunk => chunks.push(chunk));
96
+ res.on('error', reject);
97
+ res.on('end', () => {
98
+ const statusCode = res.statusCode ?? 0;
99
+ if (statusCode >= 200 && statusCode < 300)
100
+ resolve();
101
+ else
102
+ reject(uploadError(statusCode, Buffer.concat(chunks).toString('utf8'), object));
103
+ });
104
+ });
105
+ req.on('error', reject);
106
+ req.end(body);
107
+ });
108
+ }
package/dist/handler.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import type { IncomingMessage, ServerResponse } from 'node:http';
2
2
  import type { Http2ServerRequest, Http2ServerResponse } from 'node:http2';
3
+ import type { Logger } from './logger.ts';
3
4
  import type { Store } from './store/store.ts';
4
5
  type Request = IncomingMessage | Http2ServerRequest;
5
6
  type Response = ServerResponse | Http2ServerResponse;
6
- export declare function createHandler(store: Store): (req: Request, res: Response) => void;
7
+ export declare function createHandler(store: Store, logger: Logger): (req: Request, res: Response) => void;
7
8
  export {};
package/dist/handler.js CHANGED
@@ -2,7 +2,7 @@ import { randomBytes, randomUUID } from 'node:crypto';
2
2
  import { KinesisError } from './errors.js';
3
3
  import { operations, serviceTarget } from './generated/model.js';
4
4
  import { handlers } from './operations/index.js';
5
- import { DEFAULT_MAX_RECORD_SIZE_KIB, streamNameFromArn } from './operations/common.js';
5
+ import { DEFAULT_MAX_RECORD_SIZE_KIB, parseConsumerArn, streamNameFromArn } from './operations/common.js';
6
6
  import { Subscription } from './operations/subscribe.js';
7
7
  import { decodeCbor } from './protocol/cbor.js';
8
8
  import { AMZ_CBOR, AMZ_JSON, encodeBody, serializeShape } from './protocol/serialize.js';
@@ -20,6 +20,8 @@ function sendRaw(exchange, body, statusCode = 200) {
20
20
  const { req, res } = exchange;
21
21
  req.removeAllListeners('data');
22
22
  res.statusCode = statusCode;
23
+ if (typeof body === 'string')
24
+ exchange.output = body;
23
25
  if (body === null)
24
26
  return res.end();
25
27
  res.setHeader('Content-Length', Buffer.byteLength(body));
@@ -28,19 +30,30 @@ function sendRaw(exchange, body, statusCode = 200) {
28
30
  function protocolOf(exchange) {
29
31
  return exchange.contentType === AMZ_CBOR ? 'cbor' : 'json';
30
32
  }
33
+ function noteError(exchange, data) {
34
+ const body = (data?.Output ?? data ?? {});
35
+ exchange.errorType = body.__type;
36
+ exchange.errorMessage = (body.message ?? body.Message);
37
+ }
31
38
  function sendResponse(exchange, data, statusCode = 200) {
39
+ exchange.output = data;
40
+ if (statusCode >= 400)
41
+ noteError(exchange, data);
32
42
  exchange.res.setHeader('Content-Type', exchange.contentType);
33
43
  sendRaw(exchange, encodeBody(data, protocolOf(exchange)), statusCode);
34
44
  }
35
45
  function sendError(exchange, contentValid, type, message) {
36
46
  if (contentValid)
37
47
  return sendResponse(exchange, { __type: type, message }, 400);
48
+ exchange.errorType = type;
38
49
  if (typeof message === 'number')
39
50
  return sendRaw(exchange, `<${type}/>\n`, message);
51
+ exchange.errorMessage = message;
40
52
  return sendRaw(exchange, `<${type}>\n <Message>${message}</Message>\n</${type}>\n`, 403);
41
53
  }
42
54
  function sendHealth(store, exchange, path) {
43
55
  const healthy = store.healthy() && (path === '/healthz' || !store.draining);
56
+ exchange.level = 'debug';
44
57
  exchange.res.setHeader('Content-Type', 'text/plain');
45
58
  sendRaw(exchange, healthy ? 'ok\n' : 'unavailable\n', healthy ? 200 : 503);
46
59
  }
@@ -55,6 +68,9 @@ function sendReset(store, exchange, body) {
55
68
  }
56
69
  const stream = input?.stream;
57
70
  exchange.contentType = 'application/json';
71
+ exchange.input = input;
72
+ if (typeof stream === 'string')
73
+ exchange.stream = stream;
58
74
  if (typeof input !== 'object' || input === null || Array.isArray(input) || (stream !== undefined && typeof stream !== 'string')) {
59
75
  return sendResponse(exchange, { message: 'The body must be empty or a JSON object whose stream member is a string.' }, 400);
60
76
  }
@@ -70,6 +86,19 @@ function validationContext(store, data) {
70
86
  maxRecordBytes: (stream?.MaxRecordSizeInKiB ?? DEFAULT_MAX_RECORD_SIZE_KIB) * 1024,
71
87
  };
72
88
  }
89
+ function streamOf(data) {
90
+ if (typeof data.StreamName === 'string')
91
+ return data.StreamName;
92
+ for (const member of ['StreamARN', 'ConsumerARN', 'ResourceARN']) {
93
+ const arn = data[member];
94
+ if (typeof arn !== 'string')
95
+ continue;
96
+ const name = parseConsumerArn(arn)?.streamName ?? streamNameFromArn(arn);
97
+ if (name !== undefined)
98
+ return name;
99
+ }
100
+ return undefined;
101
+ }
73
102
  function checkAuthentication(exchange) {
74
103
  const { req } = exchange;
75
104
  const authHeader = header(req, 'authorization');
@@ -128,6 +157,10 @@ function streamEvents(exchange, subscription) {
128
157
  if (!ended)
129
158
  res.write(chunk);
130
159
  },
160
+ fail: error => {
161
+ exchange.errorType = error.type;
162
+ exchange.errorMessage = error.message;
163
+ },
131
164
  end: () => {
132
165
  if (!ended) {
133
166
  ended = true;
@@ -152,7 +185,6 @@ function dispatch(store, exchange, operation, input) {
152
185
  }
153
186
  function respond(store, exchange, body) {
154
187
  const { req, res } = exchange;
155
- res.setHeader('x-amzn-RequestId', randomUUID());
156
188
  if (req.method !== 'OPTIONS' || !req.headers.origin)
157
189
  res.setHeader('x-amz-id-2', randomBytes(72).toString('base64'));
158
190
  if (req.headers.origin) {
@@ -165,6 +197,7 @@ function respond(store, exchange, body) {
165
197
  if (requestMethod)
166
198
  res.setHeader('Access-Control-Allow-Methods', requestMethod);
167
199
  res.setHeader('Access-Control-Max-Age', 172800);
200
+ exchange.level = 'debug';
168
201
  return sendRaw(exchange, '');
169
202
  }
170
203
  res.setHeader('Access-Control-Expose-Headers', EXPOSED_HEADERS);
@@ -180,6 +213,8 @@ function respond(store, exchange, body) {
180
213
  const contentType = header(req, 'content-type').split(';')[0].trim();
181
214
  const contentValid = [AMZ_JSON, AMZ_CBOR, 'application/json'].includes(contentType);
182
215
  const [service, operation] = header(req, 'x-amz-target').split('.');
216
+ if (operation)
217
+ exchange.operation = operation;
183
218
  const serviceValid = !!service && service === serviceTarget;
184
219
  const operationValid = !!operation && Object.hasOwn(handlers, operation);
185
220
  if (!body) {
@@ -206,6 +241,8 @@ function respond(store, exchange, body) {
206
241
  }
207
242
  return sendResponse(exchange, { __type: 'SerializationException' }, 400);
208
243
  }
244
+ exchange.input = data;
245
+ exchange.stream = streamOf(data);
209
246
  if (contentType === 'application/json') {
210
247
  return sendResponse(exchange, { Output: { __type: 'com.amazon.coral.service#UnknownOperationException' }, Version: '1.0' }, 404);
211
248
  }
@@ -220,16 +257,43 @@ function respond(store, exchange, body) {
220
257
  catch (error) {
221
258
  if (error instanceof KinesisError)
222
259
  return sendResponse(exchange, error.body, error.statusCode);
223
- console.error(error instanceof Error ? error.stack : error);
260
+ exchange.error = error;
224
261
  return sendResponse(exchange, { __type: 'InternalFailure' }, 500);
225
262
  }
226
263
  }
227
- export function createHandler(store) {
264
+ function logRequest(logger, exchange, started, body) {
265
+ const { req, res } = exchange;
266
+ const status = res.statusCode;
267
+ const level = status >= 500 ? 'error' : status >= 400 || exchange.errorType ? 'warn' : exchange.level;
268
+ if (!logger.enabled(level))
269
+ return;
270
+ const trace = logger.enabled('trace');
271
+ logger.log(level, {
272
+ requestId: exchange.requestId,
273
+ method: req.method,
274
+ path: req.url?.split('?')[0],
275
+ operation: exchange.operation,
276
+ stream: exchange.stream,
277
+ status,
278
+ errorType: exchange.errorType,
279
+ errorMessage: exchange.errorMessage,
280
+ durationMs: Math.round((performance.now() - started) * 1000) / 1000,
281
+ aborted: res.writableEnded ? undefined : true,
282
+ error: exchange.error instanceof Error ? exchange.error.stack : exchange.error,
283
+ request: trace ? exchange.input ?? body?.toString('utf8') : undefined,
284
+ response: trace ? exchange.output : undefined,
285
+ });
286
+ }
287
+ export function createHandler(store, logger) {
228
288
  return (req, res) => {
229
- const exchange = { req, res: res, contentType: AMZ_JSON };
289
+ const started = performance.now();
290
+ const exchange = { req, res: res, contentType: AMZ_JSON, requestId: randomUUID(), level: 'info' };
230
291
  const chunks = [];
231
292
  let size = 0;
232
293
  let rejected = false;
294
+ let body;
295
+ exchange.res.setHeader('x-amzn-RequestId', exchange.requestId);
296
+ exchange.res.once('close', () => logRequest(logger, exchange, started, body));
233
297
  req.on('error', () => res.destroy());
234
298
  req.on('data', (chunk) => {
235
299
  if (rejected)
@@ -247,7 +311,8 @@ export function createHandler(store) {
247
311
  req.on('end', () => {
248
312
  if (rejected)
249
313
  return;
250
- respond(store, exchange, size ? Buffer.concat(chunks, size) : undefined);
314
+ body = size ? Buffer.concat(chunks, size) : undefined;
315
+ respond(store, exchange, body);
251
316
  });
252
317
  };
253
318
  }
@@ -0,0 +1,10 @@
1
+ export declare const LOG_LEVELS: readonly ['error', 'warn', 'info', 'debug', 'trace'];
2
+ export type LogLevel = typeof LOG_LEVELS[number];
3
+ export declare function isLogLevel(value: unknown): value is LogLevel;
4
+ export declare class Logger {
5
+ readonly level: LogLevel;
6
+ private readonly write;
7
+ constructor(level: LogLevel, write?: (line: string) => void);
8
+ enabled(level: LogLevel): boolean;
9
+ log(level: LogLevel, fields: Record<string, unknown>): void;
10
+ }
package/dist/logger.js ADDED
@@ -0,0 +1,27 @@
1
+ export const LOG_LEVELS = ['error', 'warn', 'info', 'debug', 'trace'];
2
+ export function isLogLevel(value) {
3
+ return LOG_LEVELS.includes(value);
4
+ }
5
+ function replacer(key, value) {
6
+ const raw = this[key];
7
+ if (raw instanceof Uint8Array)
8
+ return Buffer.from(raw.buffer, raw.byteOffset, raw.byteLength).toString('base64');
9
+ return typeof value === 'bigint' ? value.toString() : value;
10
+ }
11
+ export class Logger {
12
+ level;
13
+ write;
14
+ constructor(level, write = line => process.stdout.write(line)) {
15
+ if (!isLogLevel(level))
16
+ throw new Error(`Unknown log level ${level}. Use ${LOG_LEVELS.join(', ')}.`);
17
+ this.level = level;
18
+ this.write = write;
19
+ }
20
+ enabled(level) {
21
+ return LOG_LEVELS.indexOf(level) <= LOG_LEVELS.indexOf(this.level);
22
+ }
23
+ log(level, fields) {
24
+ if (this.enabled(level))
25
+ this.write(`${JSON.stringify({ time: new Date().toISOString(), level, ...fields }, replacer)}\n`);
26
+ }
27
+ }
@@ -3,6 +3,7 @@ import { type Protocol } from '../protocol/serialize.ts';
3
3
  import { type Context, type Input } from './common.ts';
4
4
  export interface EventSink {
5
5
  write(chunk: Buffer): void;
6
+ fail(error: KinesisError): void;
6
7
  end(): void;
7
8
  onClose(listener: () => void): void;
8
9
  }
@@ -147,6 +147,7 @@ export class Subscription {
147
147
  fail(error) {
148
148
  if (this.finished || !this.sink)
149
149
  return;
150
+ this.sink.fail(error);
150
151
  this.sink.write(encodeEvent({ ':exception-type': error.type, ':content-type': this.payloadType, ':message-type': 'exception' }, encodeBody({ message: error.message }, this.protocol)));
151
152
  this.stop();
152
153
  }
package/dist/server.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { type AddressInfo } from 'node:net';
2
+ import { type LogLevel } from './logger.ts';
2
3
  export interface StartOptions {
3
4
  port: number;
4
5
  host?: string | undefined;
@@ -14,6 +15,7 @@ export interface StartOptions {
14
15
  accountId: string;
15
16
  region: string;
16
17
  shutdownMs: number;
18
+ logLevel: LogLevel;
17
19
  }
18
20
  export interface KinesisLocal {
19
21
  endpoint: string;
package/dist/server.js CHANGED
@@ -4,6 +4,7 @@ import { createServer as createHttp2Server, createSecureServer } from 'node:http
4
4
  import { createServer as createNetServer } from 'node:net';
5
5
  import { selfSignedCertificate } from './certificate.js';
6
6
  import { createHandler } from './handler.js';
7
+ import { Logger } from './logger.js';
7
8
  import { registerTransitions } from './operations/index.js';
8
9
  import { Store } from './store/store.js';
9
10
  const HTTP2_PREFACE = Buffer.from('PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n', 'latin1');
@@ -20,6 +21,7 @@ export function defaultOptions() {
20
21
  accountId: (process.env.AWS_ACCOUNT_ID || '0000-0000-0000').replace(/[^\d]/g, ''),
21
22
  region: process.env.AWS_REGION || process.env.AWS_DEFAULT_REGION || 'us-east-1',
22
23
  shutdownMs: 5000,
24
+ logLevel: 'warn',
23
25
  };
24
26
  }
25
27
  function routeByProtocol(socket, servers) {
@@ -54,14 +56,15 @@ function hostname(address) {
54
56
  }
55
57
  export async function start(overrides = {}) {
56
58
  const options = { ...defaultOptions(), ...overrides };
59
+ const logger = new Logger(options.logLevel);
57
60
  const credentials = options.keyFile && options.certFile
58
61
  ? { key: readFileSync(options.keyFile), cert: readFileSync(options.certFile) }
59
62
  : selfSignedCertificate();
60
- const store = new Store(options);
63
+ const store = new Store(options, logger);
61
64
  registerTransitions(store);
62
65
  store.startExpiry();
63
66
  store.resume();
64
- const handle = createHandler(store);
67
+ const handle = createHandler(store, logger);
65
68
  const sockets = new Set();
66
69
  const sessions = new Set();
67
70
  let inFlight = 0;
@@ -1,4 +1,5 @@
1
1
  import { EventEmitter } from 'node:events';
2
+ import type { Logger } from '../logger.ts';
2
3
  import type { AccountSettings, ChannelDoc, ConsumerDoc, NewRecord, StoredRecord, StreamDoc } from './types.ts';
3
4
  export declare const DATABASE_FILE = "aws-kinesis-local.sqlite";
4
5
  export interface StoreOptions {
@@ -15,6 +16,7 @@ type Kind = 'stream' | 'consumer' | 'channel';
15
16
  export type Transition = (store: Store, key: string, data: unknown) => void;
16
17
  export declare class Store {
17
18
  readonly options: StoreOptions;
19
+ private readonly logger;
18
20
  readonly streams: Map<string, StreamDoc>;
19
21
  readonly consumers: Map<string, ConsumerDoc>;
20
22
  readonly channels: Map<string, ChannelDoc>;
@@ -27,7 +29,7 @@ export declare class Store {
27
29
  private readonly timers;
28
30
  private readonly statements;
29
31
  private closed;
30
- constructor(options: StoreOptions);
32
+ constructor(options: StoreOptions, logger: Logger);
31
33
  private load;
32
34
  transaction<T>(work: () => T): T;
33
35
  private collection;
@@ -8,6 +8,7 @@ const EXPIRY_BATCH_SIZE = 500;
8
8
  const defaultSettings = () => ({ MinimumThroughputBillingCommitment: { Status: 'DISABLED' } });
9
9
  export class Store {
10
10
  options;
11
+ logger;
11
12
  streams = new Map();
12
13
  consumers = new Map();
13
14
  channels = new Map();
@@ -20,8 +21,9 @@ export class Store {
20
21
  timers = new Map();
21
22
  statements;
22
23
  closed = false;
23
- constructor(options) {
24
+ constructor(options, logger) {
24
25
  this.options = options;
26
+ this.logger = logger;
25
27
  this.events.setMaxListeners(0);
26
28
  let file = ':memory:';
27
29
  if (options.path) {
@@ -215,7 +217,7 @@ export class Store {
215
217
  done = batches.next().done;
216
218
  }
217
219
  catch (error) {
218
- console.error(error instanceof Error ? error.stack : error);
220
+ this.logger.log('error', { message: 'Record expiry failed', error: error instanceof Error ? error.stack : error });
219
221
  }
220
222
  if (done)
221
223
  this.scheduleExpiry(this.options.expiryIntervalMs, this.expiryBatches());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saidsef/aws-kinesis-local",
3
- "version": "1.4.0",
3
+ "version": "1.6.0",
4
4
  "description": "Local Amazon Kinesis Data Streams server for development and CI, with all 45 operations, enhanced fan-out, JSON and CBOR over HTTP/1.1 and HTTP/2",
5
5
  "keywords": [
6
6
  "aws",
@@ -60,11 +60,11 @@
60
60
  "start": "node src/cli.ts"
61
61
  },
62
62
  "devDependencies": {
63
- "@aws-sdk/client-kinesis": "3.1164.0",
63
+ "@aws-sdk/client-kinesis": "3.1170.0",
64
64
  "@smithy/eventstream-codec": "4.5.2",
65
65
  "@smithy/node-http-handler": "4.14.2",
66
66
  "@types/node": "26.6.6",
67
- "cbor2": "2.4.1",
67
+ "cbor2": "2.4.2",
68
68
  "typescript": "7.0.2"
69
69
  }
70
70
  }