@nathapp/nestjs-idempotency 3.3.0 → 4.0.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 (38) hide show
  1. package/package.json +10 -10
  2. package/.eslintrc.js +0 -8
  3. package/.nax/features/nestjs-idempotency/.nax-acceptance.test.ts +0 -766
  4. package/.nax/features/nestjs-idempotency/.nax-suggested.test.ts +0 -439
  5. package/.nax/test-debug.ts +0 -22
  6. package/.turbo/turbo-build.log +0 -4
  7. package/CHANGELOG.md +0 -15
  8. package/lib/constant/idempotency.constants.ts +0 -8
  9. package/lib/constant/index.ts +0 -1
  10. package/lib/decorator/idempotent.decorator.ts +0 -4
  11. package/lib/exception/idempotency-exception-code.enum.ts +0 -5
  12. package/lib/exception/idempotency.exceptions.ts +0 -15
  13. package/lib/index.ts +0 -13
  14. package/lib/interceptor/idempotency.interceptor.ts +0 -187
  15. package/lib/interface/idempotency-module-options.interface.ts +0 -21
  16. package/lib/interface/idempotency-record.interface.ts +0 -14
  17. package/lib/interface/idempotency-store.interface.ts +0 -8
  18. package/lib/module/idempotency.module.ts +0 -61
  19. package/lib/provider/default-principal-extractor.ts +0 -17
  20. package/lib/provider/fingerprint.ts +0 -17
  21. package/lib/provider/in-memory-idempotency-store.ts +0 -53
  22. package/lib/provider/resolve-idempotency-options.ts +0 -32
  23. package/test/barrel/index.spec.ts +0 -40
  24. package/test/constant/idempotency.constants.spec.ts +0 -10
  25. package/test/decorator/idempotent.decorator.spec.ts +0 -20
  26. package/test/e2e/express.e2e.spec.ts +0 -219
  27. package/test/e2e/fastify.e2e.spec.ts +0 -64
  28. package/test/exception/idempotency.exceptions.spec.ts +0 -24
  29. package/test/interceptor/idempotency.interceptor.spec.ts +0 -739
  30. package/test/jest-nax-setup-test.js +0 -21
  31. package/test/jest-nax-setup.js +0 -92
  32. package/test/jest-nax.json +0 -30
  33. package/test/jest-test.json +0 -28
  34. package/test/module/idempotency.module.spec.ts +0 -87
  35. package/test/provider/fingerprint.spec.ts +0 -27
  36. package/test/provider/in-memory-idempotency-store.spec.ts +0 -212
  37. package/test/provider/resolve-idempotency-options.spec.ts +0 -42
  38. package/tsconfig.json +0 -9
@@ -1,21 +0,0 @@
1
- // Minimal setup - no supertest wrapper
2
- const nestCommon = require('@nestjs/common');
3
- const coreConstants = require('@nestjs/core/constants');
4
- const appTokens = {
5
- APP_INTERCEPTOR: coreConstants.APP_INTERCEPTOR,
6
- APP_FILTER: coreConstants.APP_FILTER,
7
- APP_GUARD: coreConstants.APP_GUARD,
8
- APP_PIPE: coreConstants.APP_PIPE,
9
- };
10
- for (const [key, value] of Object.entries(appTokens)) {
11
- if (!(key in nestCommon)) {
12
- Object.defineProperty(nestCommon, key, { value, writable: true, configurable: true, enumerable: true });
13
- }
14
- }
15
- const nodeCrypto = require('crypto');
16
- if (typeof globalThis.crypto !== 'undefined' && typeof globalThis.crypto.createHash !== 'function') {
17
- Object.defineProperty(globalThis.crypto, 'createHash', {
18
- value: nodeCrypto.createHash.bind(nodeCrypto), writable: true, configurable: true
19
- });
20
- }
21
- // NO supertest wrapper
@@ -1,92 +0,0 @@
1
- // Setup file to fix missing exports and global crypto for the acceptance test suite
2
- const nestCommon = require('@nestjs/common');
3
- const coreConstants = require('@nestjs/core/constants');
4
- const appTokens = {
5
- APP_INTERCEPTOR: coreConstants.APP_INTERCEPTOR,
6
- APP_FILTER: coreConstants.APP_FILTER,
7
- APP_GUARD: coreConstants.APP_GUARD,
8
- APP_PIPE: coreConstants.APP_PIPE,
9
- };
10
- for (const [key, value] of Object.entries(appTokens)) {
11
- if (!(key in nestCommon)) {
12
- Object.defineProperty(nestCommon, key, {
13
- value,
14
- writable: true,
15
- configurable: true,
16
- enumerable: true,
17
- });
18
- }
19
- }
20
-
21
- const nodeCrypto = require('crypto');
22
- if (typeof globalThis.crypto.createHash !== 'function') {
23
- Object.defineProperty(globalThis.crypto, 'createHash', {
24
- value: nodeCrypto.createHash.bind(nodeCrypto),
25
- writable: true,
26
- configurable: true,
27
- enumerable: false,
28
- });
29
- Object.defineProperty(globalThis.crypto, 'createHmac', {
30
- value: nodeCrypto.createHmac.bind(nodeCrypto),
31
- writable: true,
32
- configurable: true,
33
- enumerable: false,
34
- });
35
- }
36
-
37
- // Patch supertest so requests auto-start in the next microtask (after the
38
- // fluent chain is built). This lets tests fire a request without immediately
39
- // awaiting it (e.g. to test concurrent in-flight behaviour) while still being
40
- // able to `await` the same promise later. We bypass supertest's built-in
41
- // `.then()` → `.end()` re-entry by capturing the response in our own deferred
42
- // promise and only ever calling `.end(callback)` once.
43
- try {
44
- const supertest = require('supertest');
45
- const wrappedSupertest = function (app, options) {
46
- const agent = supertest(app, options);
47
- const httpMethods = ['get', 'post', 'put', 'delete', 'patch', 'head', 'options'];
48
- for (const method of httpMethods) {
49
- const original = agent[method];
50
- if (typeof original !== 'function') continue;
51
- agent[method] = function (url) {
52
- const test = original.call(this, url);
53
-
54
- let started = false;
55
- let promiseResolve, promiseReject;
56
- const requestPromise = new Promise((res, rej) => {
57
- promiseResolve = res;
58
- promiseReject = rej;
59
- });
60
-
61
- function start() {
62
- if (started) return;
63
- started = true;
64
- test.end((err, res) => {
65
- if (err) promiseReject(err);
66
- else promiseResolve(res);
67
- });
68
- }
69
-
70
- // Override then to return our deferred promise directly, avoiding the
71
- // supertest internal .then() → .end() loop that causes hangs.
72
- test.then = function (onFulfilled, onRejected) {
73
- start();
74
- return requestPromise.then(onFulfilled, onRejected);
75
- };
76
-
77
- // Auto-start in the next microtask so the request begins before any
78
- // subsequent setTimeout/await in the caller (needed for in-flight tests).
79
- Promise.resolve().then(() => start());
80
-
81
- return test;
82
- };
83
- }
84
- return agent;
85
- };
86
- Object.assign(wrappedSupertest, supertest);
87
- const cachePath = require.resolve('supertest');
88
- require.cache[cachePath].exports = wrappedSupertest;
89
- } catch (_) {
90
- // ignore
91
- }
92
-
@@ -1,30 +0,0 @@
1
- {
2
- "moduleFileExtensions": ["js", "json", "ts", "d.ts"],
3
- "rootDir": "../",
4
- "testEnvironment": "node",
5
- "testMatch": ["**/.nax/**/*.test.ts"],
6
- "setupFiles": ["<rootDir>/test/jest-nax-setup.js"],
7
- "transform": {
8
- "^.+\\.(t)s$": [
9
- "ts-jest",
10
- {
11
- "diagnostics": {
12
- "ignoreCodes": [2305, 2322, 2339, 2345]
13
- },
14
- "tsconfig": {
15
- "esModuleInterop": true,
16
- "emitDecoratorMetadata": true,
17
- "experimentalDecorators": true
18
- }
19
- }
20
- ]
21
- },
22
- "collectCoverageFrom": [
23
- "lib/**/*.ts",
24
- "!lib/**/*.spec.ts",
25
- "!lib/**/*.d.ts",
26
- "!**/node_modules/**"
27
- ],
28
- "forceExit": true,
29
- "maxWorkers": 1
30
- }
@@ -1,28 +0,0 @@
1
- {
2
- "moduleFileExtensions": [
3
- "js",
4
- "json",
5
- "ts",
6
- "d.ts"
7
- ],
8
- "rootDir": "../",
9
- "testEnvironment": "node",
10
- "testRegex": ".spec.ts$",
11
- "transform": {
12
- "^.+\\.(t)s$": [
13
- "ts-jest",
14
- {
15
- "diagnostics": true
16
- }
17
- ]
18
- },
19
- "collectCoverageFrom": [
20
- "lib/**/*.ts",
21
- "!lib/**/*.spec.ts",
22
- "!lib/**/*.d.ts",
23
- "!lib/**/index.ts",
24
- "!lib/**/*.interface.ts",
25
- "!**/node_modules/**"
26
- ],
27
- "coverageProvider": "v8"
28
- }
@@ -1,87 +0,0 @@
1
- import { describe, expect, it, jest } from '@jest/globals';
2
- import { Test } from '@nestjs/testing';
3
- import { IdempotencyModule } from '../../lib/module/idempotency.module';
4
- import {
5
- IDEMPOTENCY_INTERCEPTOR_OPTIONS,
6
- IDEMPOTENCY_STORE,
7
- } from '../../lib/constant/idempotency.constants';
8
- import { InMemoryIdempotencyStore } from '../../lib/provider/in-memory-idempotency-store';
9
- import { IIdempotencyStore } from '../../lib/interface/idempotency-store.interface';
10
- import { InterceptorOptions } from '../../lib/provider/resolve-idempotency-options';
11
-
12
- describe('IdempotencyModule — register / registerAsync', () => {
13
- describe('AC1: register() returns a global dynamic module keyed to IdempotencyModule', () => {
14
- it('AC1: register() returns a DynamicModule with global === true and module === IdempotencyModule', () => {
15
- const dynamicModule = IdempotencyModule.register() as { global?: boolean; module?: unknown };
16
- expect(dynamicModule).toBeDefined();
17
- expect(dynamicModule.global).toBe(true);
18
- expect(dynamicModule.module).toBe(IdempotencyModule);
19
- });
20
-
21
- it('AC1: register({}) also yields global === true and module === IdempotencyModule (boundary — empty options)', () => {
22
- const dynamicModule = IdempotencyModule.register({}) as { global?: boolean; module?: unknown };
23
- expect(dynamicModule.global).toBe(true);
24
- expect(dynamicModule.module).toBe(IdempotencyModule);
25
- });
26
- });
27
-
28
- describe('AC2: register() resolves IDEMPOTENCY_STORE to an InMemoryIdempotencyStore', () => {
29
- it('AC2: a testing module built from register() resolves IDEMPOTENCY_STORE to InMemoryIdempotencyStore', async () => {
30
- const moduleRef = await Test.createTestingModule({
31
- imports: [IdempotencyModule.register()],
32
- }).compile();
33
-
34
- const store = moduleRef.get<IIdempotencyStore>(IDEMPOTENCY_STORE);
35
- expect(store).toBeInstanceOf(InMemoryIdempotencyStore);
36
- });
37
-
38
- it('AC2: register({ ttlMs }) threads the option into the default InMemoryIdempotencyStore (no custom store supplied)', async () => {
39
- const moduleRef = await Test.createTestingModule({
40
- imports: [IdempotencyModule.register({ ttlMs: 5_000 })],
41
- }).compile();
42
-
43
- const store = moduleRef.get<InMemoryIdempotencyStore>(IDEMPOTENCY_STORE);
44
- await store.putIfAbsent('k', { state: 'pending', fingerprint: 'f', createdAt: Date.now() - 10_000 });
45
-
46
- expect(await store.get('k')).toBeUndefined();
47
- });
48
- });
49
-
50
- describe('AC3: register({ store }) resolves IDEMPOTENCY_STORE to the custom instance (reference-equal)', () => {
51
- it('AC3: a custom store passed via register({ store }) is exposed under IDEMPOTENCY_STORE reference-equal', async () => {
52
- const customStore: IIdempotencyStore = {
53
- putIfAbsent: jest.fn(async () => undefined),
54
- complete: jest.fn(async () => undefined),
55
- remove: jest.fn(async () => undefined),
56
- get: jest.fn(async () => undefined),
57
- };
58
-
59
- const moduleRef = await Test.createTestingModule({
60
- imports: [IdempotencyModule.register({ store: customStore })],
61
- }).compile();
62
-
63
- const resolved = moduleRef.get<IIdempotencyStore>(IDEMPOTENCY_STORE);
64
- expect(resolved).toBe(customStore);
65
- });
66
- });
67
-
68
- describe('AC4: registerAsync({ useFactory }) builds and the resolved interceptor options expose factory-supplied values', () => {
69
- it('AC4: registerAsync with a useFactory that returns { headerName: "X-Key" } — resolved IDEMPOTENCY_INTERCEPTOR_OPTIONS.headerName === "X-Key" and other fields carry defaults', async () => {
70
- const moduleRef = await Test.createTestingModule({
71
- imports: [
72
- IdempotencyModule.registerAsync({
73
- inject: [],
74
- useFactory: () => Promise.resolve({ headerName: 'X-Key' }),
75
- }),
76
- ],
77
- }).compile();
78
-
79
- const resolved = moduleRef.get<InterceptorOptions>(IDEMPOTENCY_INTERCEPTOR_OPTIONS);
80
- expect(resolved).toBeDefined();
81
- expect(resolved.headerName).toBe('X-Key');
82
- expect(resolved.ttlMs).toBe(86_400_000);
83
- expect(resolved.requireKey).toBe(false);
84
- expect(resolved.replayHeaders).toEqual(['content-type']);
85
- });
86
- });
87
- });
@@ -1,27 +0,0 @@
1
- import { describe, expect, it } from '@jest/globals';
2
- import { computeFingerprint } from '../../lib/provider/fingerprint';
3
-
4
- describe('computeFingerprint', () => {
5
- it('AC1: same fields in different key order produce equal 64-char lowercase hex strings', () => {
6
- const a = computeFingerprint({ a: 1, b: 2 });
7
- const b = computeFingerprint({ b: 2, a: 1 });
8
- expect(a).toStrictEqual(b);
9
- expect(a).toMatch(/^[a-f0-9]{64}$/);
10
- });
11
-
12
- it('AC2: array element order is significant — [1,2] and [2,1] produce different strings', () => {
13
- const a = computeFingerprint({ list: [1, 2] });
14
- const b = computeFingerprint({ list: [2, 1] });
15
- expect(a).not.toStrictEqual(b);
16
- });
17
-
18
- it('AC3: undefined input does not throw and returns a stable non-empty hex string', () => {
19
- let first: string;
20
- expect(() => {
21
- first = computeFingerprint(undefined);
22
- }).not.toThrow();
23
- expect(first!).toMatch(/^[a-f0-9]+$/);
24
- expect(first!.length).toBeGreaterThan(0);
25
- expect(computeFingerprint(undefined)).toStrictEqual(first!);
26
- });
27
- });
@@ -1,212 +0,0 @@
1
- import { afterEach, beforeEach, describe, expect, it, jest } from '@jest/globals';
2
- import { InMemoryIdempotencyStore } from '../../lib/provider/in-memory-idempotency-store';
3
- import { IdempotencyRecord, StoredResponse } from '../../lib/interface/idempotency-record.interface';
4
-
5
- const pending = (overrides: Partial<IdempotencyRecord> = {}): IdempotencyRecord => ({
6
- state: 'pending',
7
- fingerprint: 'fp-A',
8
- createdAt: Date.now(),
9
- ...overrides,
10
- });
11
-
12
- const response = (overrides: Partial<StoredResponse> = {}): StoredResponse => ({
13
- status: 200,
14
- body: { ok: true },
15
- headers: { 'content-type': 'application/json' },
16
- ...overrides,
17
- });
18
-
19
- describe('InMemoryIdempotencyStore', () => {
20
- describe('AC1: putIfAbsent on a fresh store resolves to undefined', () => {
21
- it('returns undefined when the slot is empty', async () => {
22
- const store = new InMemoryIdempotencyStore();
23
- const result = await store.putIfAbsent('k', pending());
24
- expect(result).toBeUndefined();
25
- });
26
- });
27
-
28
- describe('AC2: second putIfAbsent returns the existing record', () => {
29
- it('returns a deep-equal copy of recordA when recordB is offered', async () => {
30
- const store = new InMemoryIdempotencyStore();
31
- const recordA = pending({ fingerprint: 'fp-A' });
32
- const recordB = pending({ fingerprint: 'fp-B' });
33
-
34
- const first = await store.putIfAbsent('k', recordA);
35
- const second = await store.putIfAbsent('k', recordB);
36
-
37
- expect(first).toBeUndefined();
38
- expect(second).toStrictEqual(recordA);
39
- expect(second).not.toStrictEqual(recordB);
40
- });
41
- });
42
-
43
- describe('AC3: get after putIfAbsent returns the pending record with fingerprint', () => {
44
- it('returns state=pending and the stored fingerprint', async () => {
45
- const store = new InMemoryIdempotencyStore();
46
- const record = pending({ fingerprint: 'fp-A' });
47
- await store.putIfAbsent('k', record);
48
-
49
- const got = await store.get('k');
50
- expect(got).toBeDefined();
51
- expect(got!.state).toBe('pending');
52
- expect(got!.fingerprint).toBe('fp-A');
53
- });
54
- });
55
-
56
- describe('AC4: get of missing key resolves to undefined', () => {
57
- it('returns undefined when the key was never inserted', async () => {
58
- const store = new InMemoryIdempotencyStore();
59
- const got = await store.get('missing');
60
- expect(got).toBeUndefined();
61
- });
62
- });
63
-
64
- describe('AC5: complete transitions pending -> completed with stored response', () => {
65
- it('returns state=completed and deep-equals the passed response', async () => {
66
- const store = new InMemoryIdempotencyStore();
67
- const res = response({ status: 201, body: { id: 'abc' } });
68
- await store.putIfAbsent('k', pending());
69
- await store.complete('k', res);
70
-
71
- const got = await store.get('k');
72
- expect(got).toBeDefined();
73
- expect(got!.state).toBe('completed');
74
- expect(got!.response).toStrictEqual(res);
75
- });
76
- });
77
-
78
- describe('AC6: remove makes the slot re-acquirable', () => {
79
- it('after remove, get returns undefined and putIfAbsent resolves to undefined', async () => {
80
- const store = new InMemoryIdempotencyStore();
81
- await store.putIfAbsent('k', pending({ fingerprint: 'fp-A' }));
82
- await store.remove('k');
83
-
84
- const afterRemove = await store.get('k');
85
- expect(afterRemove).toBeUndefined();
86
-
87
- const reacquire = await store.putIfAbsent('k', pending({ fingerprint: 'fp-B' }));
88
- expect(reacquire).toBeUndefined();
89
-
90
- const got = await store.get('k');
91
- expect(got!.fingerprint).toBe('fp-B');
92
- });
93
- });
94
-
95
- describe('isolation: returned records are defensive copies', () => {
96
- it('mutating the record returned by putIfAbsent does not corrupt the store', async () => {
97
- const store = new InMemoryIdempotencyStore();
98
- await store.putIfAbsent('k', pending({ fingerprint: 'fp-A' }));
99
-
100
- const returned = await store.putIfAbsent('k', pending({ fingerprint: 'fp-B' }));
101
- expect(returned).toBeDefined();
102
- (returned as { fingerprint: string }).fingerprint = 'fp-mutated';
103
- (returned as { state: string }).state = 'completed';
104
-
105
- const fresh = await store.get('k');
106
- expect(fresh!.fingerprint).toBe('fp-A');
107
- expect(fresh!.state).toBe('pending');
108
- });
109
-
110
- it('mutating the record returned by get does not corrupt the store', async () => {
111
- const store = new InMemoryIdempotencyStore();
112
- await store.putIfAbsent('k', pending({ fingerprint: 'fp-A' }));
113
-
114
- const first = await store.get('k');
115
- expect(first).toBeDefined();
116
- (first as { fingerprint: string }).fingerprint = 'fp-mutated';
117
-
118
- const second = await store.get('k');
119
- expect(second!.fingerprint).toBe('fp-A');
120
- });
121
- });
122
-
123
- describe('AC7: ttlMs=0 (or already-expired) is treated as absent', () => {
124
- let nowSpy: jest.SpiedFunction<typeof Date.now>;
125
-
126
- beforeEach(() => {
127
- nowSpy = jest.spyOn(Date, 'now');
128
- });
129
-
130
- afterEach(() => {
131
- nowSpy.mockRestore();
132
- });
133
-
134
- it('get resolves to undefined when constructed with ttlMs=0', async () => {
135
- const store = new InMemoryIdempotencyStore({ ttlMs: 0 });
136
- nowSpy.mockReturnValue(1000);
137
-
138
- await store.putIfAbsent('k', pending({ createdAt: 1000 }));
139
-
140
- const got = await store.get('k');
141
- expect(got).toBeUndefined();
142
- });
143
-
144
- it('putIfAbsent resolves to undefined (slot re-acquirable) after expiry', async () => {
145
- const store = new InMemoryIdempotencyStore({ ttlMs: 100 });
146
- nowSpy.mockReturnValue(1000);
147
-
148
- const first = await store.putIfAbsent('k', pending({ createdAt: 1000 }));
149
- expect(first).toBeUndefined();
150
-
151
- nowSpy.mockReturnValue(1200);
152
-
153
- const reacquire = await store.putIfAbsent('k', pending({ fingerprint: 'fp-fresh', createdAt: 1200 }));
154
- expect(reacquire).toBeUndefined();
155
-
156
- const got = await store.get('k');
157
- expect(got).toBeDefined();
158
- expect(got!.fingerprint).toBe('fp-fresh');
159
- });
160
-
161
- it('get() on an expired entry evicts it from the underlying store (no leak)', async () => {
162
- const store = new InMemoryIdempotencyStore({ ttlMs: 100 });
163
- nowSpy.mockReturnValue(1000);
164
- await store.putIfAbsent('k', pending({ createdAt: 1000 }));
165
-
166
- nowSpy.mockReturnValue(1200);
167
- const got = await store.get('k');
168
- expect(got).toBeUndefined();
169
-
170
- const internal = (store as unknown as { map: Map<string, IdempotencyRecord> }).map;
171
- expect(internal.has('k')).toBe(false);
172
- });
173
-
174
- it('putIfAbsent() on an expired entry evicts the stale record before installing the new one', async () => {
175
- const store = new InMemoryIdempotencyStore({ ttlMs: 100 });
176
- nowSpy.mockReturnValue(1000);
177
- await store.putIfAbsent('k', pending({ fingerprint: 'fp-stale', createdAt: 1000 }));
178
-
179
- nowSpy.mockReturnValue(1200);
180
- const reacquire = await store.putIfAbsent('k', pending({ fingerprint: 'fp-fresh', createdAt: 1200 }));
181
- expect(reacquire).toBeUndefined();
182
-
183
- const internal = (store as unknown as { map: Map<string, IdempotencyRecord> }).map;
184
- expect(internal.size).toBe(1);
185
- expect(internal.get('k')!.fingerprint).toBe('fp-fresh');
186
- });
187
-
188
- it('complete() on an expired entry is a no-op (no silent resurrection, no map growth)', async () => {
189
- const store = new InMemoryIdempotencyStore({ ttlMs: 100 });
190
- nowSpy.mockReturnValue(1000);
191
- await store.putIfAbsent('k', pending({ fingerprint: 'fp-stale', createdAt: 1000 }));
192
-
193
- nowSpy.mockReturnValue(1200);
194
- await expect(store.complete('k', response({ status: 201 }))).resolves.toBeUndefined();
195
-
196
- const got = await store.get('k');
197
- expect(got).toBeUndefined();
198
-
199
- const internal = (store as unknown as { map: Map<string, IdempotencyRecord> }).map;
200
- expect(internal.has('k')).toBe(false);
201
- });
202
-
203
- it('complete() on a missing key is a no-op (does not create a new record)', async () => {
204
- const store = new InMemoryIdempotencyStore({ ttlMs: 100 });
205
- await expect(store.complete('missing', response({ status: 201 }))).resolves.toBeUndefined();
206
-
207
- const internal = (store as unknown as { map: Map<string, IdempotencyRecord> }).map;
208
- expect(internal.has('missing')).toBe(false);
209
- expect(await store.get('missing')).toBeUndefined();
210
- });
211
- });
212
- });
@@ -1,42 +0,0 @@
1
- import { describe, expect, it } from '@jest/globals';
2
- import { resolveIdempotencyOptions } from '../../lib/provider/resolve-idempotency-options';
3
- import { InMemoryIdempotencyStore } from '../../lib/provider/in-memory-idempotency-store';
4
-
5
- describe('resolveIdempotencyOptions', () => {
6
- it('AC4: undefined input returns correct defaults — headerName, ttlMs, requireKey, replayHeaders', () => {
7
- const opts = resolveIdempotencyOptions(undefined);
8
- expect(opts.headerName).toBe('Idempotency-Key');
9
- expect(opts.ttlMs).toBe(86_400_000);
10
- expect(opts.requireKey).toBe(false);
11
- expect(opts.replayHeaders).toEqual(['content-type']);
12
- });
13
-
14
- it('AC5: empty options object returns store that is instanceof InMemoryIdempotencyStore', () => {
15
- const opts = resolveIdempotencyOptions({});
16
- expect(opts.store).toBeInstanceOf(InMemoryIdempotencyStore);
17
- });
18
-
19
- it('AC6: explicit option values are returned unchanged', () => {
20
- const opts = resolveIdempotencyOptions({
21
- headerName: 'X-Key',
22
- ttlMs: 1000,
23
- requireKey: true,
24
- replayHeaders: ['content-type', 'location'],
25
- });
26
- expect(opts.headerName).toBe('X-Key');
27
- expect(opts.ttlMs).toBe(1000);
28
- expect(opts.requireKey).toBe(true);
29
- expect(opts.replayHeaders).toEqual(['content-type', 'location']);
30
- });
31
-
32
- it('AC7: caller-supplied store is returned reference-equal (not replaced with InMemoryIdempotencyStore)', () => {
33
- const customStore = {
34
- putIfAbsent: () => Promise.resolve(undefined),
35
- complete: () => Promise.resolve(),
36
- remove: () => Promise.resolve(),
37
- get: () => Promise.resolve(undefined),
38
- };
39
- const opts = resolveIdempotencyOptions({ store: customStore as any });
40
- expect(opts.store).toBe(customStore);
41
- });
42
- });
package/tsconfig.json DELETED
@@ -1,9 +0,0 @@
1
- {
2
- "extends": "@nathapp/typescript-config/base.json",
3
- "compilerOptions": {
4
- "outDir": "./dist",
5
- "rootDir": "./lib"
6
- },
7
- "include": ["lib/**/*", "../index.ts", "../test/**/*"],
8
- "exclude": ["node_modules", "test", "dist", "**/*spec.ts"]
9
- }