dynamodb-refresh-token-provider 0.1.2

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/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,90 @@
1
+ # DynamoDB Refresh Token Provider
2
+
3
+ [![npm version](https://img.shields.io/npm/v/dynamodb-refresh-token-provider.svg)](https://www.npmjs.com/package/dynamodb-refresh-token-provider)
4
+ [![License](https://img.shields.io/npm/l/dynamodb-refresh-token-provider.svg)](https://github.com/gammarers-aws-sdk-extensions/athena-query-result-collector/blob/main/LICENSE)
5
+ [![build](https://github.com/gammarers-aws-sdk-extensions/athena-query-result-collector/actions/workflows/build.yml/badge.svg)](https://github.com/gammarers-aws-sdk-extensions/athena-query-result-collector/actions/workflows/build.yml)
6
+
7
+ TypeScript library that stores **opaque refresh tokens** in **Amazon DynamoDB** using AWS SDK for JavaScript v3. Tokens are persisted under a hash of the plaintext value; **issue**, **rotate** (with reuse detection via a transactional write), and **revoke** (idempotent) are supported.
8
+
9
+ ## Features
10
+
11
+ - **`RefreshTokenStore` interface** — swap implementations while keeping the same API.
12
+ - **`DynamoRefreshTokenStore`** — single-table design with partition key `pk` (string), strongly consistent reads by default.
13
+ - **Rotation safety** — marks the old row as rotated and inserts the successor in one DynamoDB transaction; detects reuse and conflicting updates.
14
+ - **Structured errors** — `RefreshTokenInvalidError`, `RefreshTokenExpiredError`, `RefreshTokenRevokedError`, `RefreshTokenReusedError`, and related types for `instanceof` handling.
15
+ - **Utilities** — `sha256hex` and `randomtoken` for hashing and token generation aligned with the store.
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ npm install dynamodb-refresh-token-provider
21
+ ```
22
+
23
+ ```bash
24
+ yarn add dynamodb-refresh-token-provider
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ Create a store with your table name, AWS region, and optional `StoreOptions`. Ensure your DynamoDB table has a **string partition key** named `pk` (same attribute name the library uses for items).
30
+
31
+ ```typescript
32
+ import {
33
+ DynamoRefreshTokenStore,
34
+ RefreshTokenInvalidError,
35
+ RefreshTokenReusedError,
36
+ } from 'dynamodb-refresh-token-provider';
37
+
38
+ const store = new DynamoRefreshTokenStore('your-refresh-token-table', 'us-east-1', {
39
+ ttlDays: 60,
40
+ pkPrefix: 'rt#',
41
+ });
42
+
43
+ // Issue a new refresh token for a subject/session
44
+ const issued = await store.issue({
45
+ subjectId: 'user-123',
46
+ sessionId: 'session-456',
47
+ });
48
+ // issued.refreshToken — send to the client (plaintext)
49
+ // issued.refreshTokenExpiresAt — Unix seconds
50
+
51
+ // Rotate: exchange current token for a new one
52
+ try {
53
+ const rotated = await store.rotate({ refreshToken: issued.refreshToken });
54
+ // rotated.refreshToken, rotated.refreshTokenExpiresAt, rotated.subjectId, rotated.sessionId
55
+ } catch (e) {
56
+ if (e instanceof RefreshTokenReusedError) {
57
+ // token was already rotated or transaction lost the race
58
+ }
59
+ if (e instanceof RefreshTokenInvalidError) {
60
+ // unknown or malformed token
61
+ }
62
+ throw e;
63
+ }
64
+
65
+ // Revoke: idempotent; succeeds even if the row does not exist
66
+ await store.revoke({ refreshToken: issued.refreshToken });
67
+ ```
68
+
69
+ ## Options
70
+
71
+ Constructor: `new DynamoRefreshTokenStore(tableName, region, options?)`.
72
+
73
+ | Option | Type | Default | Description |
74
+ |--------|------|---------|-------------|
75
+ | `ttlDays` | `number` | `60` | Lifetime of issued/rotated tokens in days (added to `now` in seconds). |
76
+ | `pkPrefix` | `string` | `'rt#'` | Prefix for the partition key; full `pk` is `prefix` + SHA-256 hex of the plaintext token. |
77
+ | `consistentRead` | `boolean` | `true` | Use strongly consistent reads on `GetItem` when loading a token row. |
78
+ | `endpoint` | `string` | (none) | Custom DynamoDB API endpoint (e.g. LocalStack or DynamoDB Local). |
79
+
80
+ Method parameters also accept an optional `now?: Date` on `issue`, `rotate`, and `revoke` for testing or clock injection.
81
+
82
+ ## Requirements
83
+
84
+ - **Node.js** 20.0.0 or later.
85
+ - A **DynamoDB table** with a string partition key attribute **`pk`**.
86
+ - **AWS credentials** and permissions for `PutItem`, `GetItem`, `UpdateItem`, and `TransactWriteItems` on that table (and the configured `endpoint` if used).
87
+
88
+ ## License
89
+
90
+ This project is licensed under the Apache-2.0 License.
package/lib/index.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Public API: refresh token store types, DynamoDB-backed implementation, errors, and crypto helpers.
3
+ */
4
+ export type { RefreshTokenStore, IssueParams, IssueResult, RotateParams, RotateResult, RevokeParams, StoreOptions, TokenRecord, EpochSec, } from './types/index';
5
+ export { DynamoRefreshTokenStore } from './stores/dynamodb';
6
+ export { RefreshTokenError, RefreshTokenExpiredError, RefreshTokenInvalidError, RefreshTokenReusedError, RefreshTokenRevokedError, RefreshTokenRotateFailedError, } from './stores/refresh-token-errors';
7
+ export { sha256hex, randomtoken } from './utils/hash';
package/lib/index.js ADDED
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.randomtoken = exports.sha256hex = exports.RefreshTokenRotateFailedError = exports.RefreshTokenRevokedError = exports.RefreshTokenReusedError = exports.RefreshTokenInvalidError = exports.RefreshTokenExpiredError = exports.RefreshTokenError = exports.DynamoRefreshTokenStore = void 0;
4
+ var dynamodb_1 = require("./stores/dynamodb");
5
+ Object.defineProperty(exports, "DynamoRefreshTokenStore", { enumerable: true, get: function () { return dynamodb_1.DynamoRefreshTokenStore; } });
6
+ var refresh_token_errors_1 = require("./stores/refresh-token-errors");
7
+ Object.defineProperty(exports, "RefreshTokenError", { enumerable: true, get: function () { return refresh_token_errors_1.RefreshTokenError; } });
8
+ Object.defineProperty(exports, "RefreshTokenExpiredError", { enumerable: true, get: function () { return refresh_token_errors_1.RefreshTokenExpiredError; } });
9
+ Object.defineProperty(exports, "RefreshTokenInvalidError", { enumerable: true, get: function () { return refresh_token_errors_1.RefreshTokenInvalidError; } });
10
+ Object.defineProperty(exports, "RefreshTokenReusedError", { enumerable: true, get: function () { return refresh_token_errors_1.RefreshTokenReusedError; } });
11
+ Object.defineProperty(exports, "RefreshTokenRevokedError", { enumerable: true, get: function () { return refresh_token_errors_1.RefreshTokenRevokedError; } });
12
+ Object.defineProperty(exports, "RefreshTokenRotateFailedError", { enumerable: true, get: function () { return refresh_token_errors_1.RefreshTokenRotateFailedError; } });
13
+ var hash_1 = require("./utils/hash");
14
+ Object.defineProperty(exports, "sha256hex", { enumerable: true, get: function () { return hash_1.sha256hex; } });
15
+ Object.defineProperty(exports, "randomtoken", { enumerable: true, get: function () { return hash_1.randomtoken; } });
16
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7O0FBZUEsOENBQTREO0FBQW5ELG1IQUFBLHVCQUF1QixPQUFBO0FBQ2hDLHNFQU91QztBQU5yQyx5SEFBQSxpQkFBaUIsT0FBQTtBQUNqQixnSUFBQSx3QkFBd0IsT0FBQTtBQUN4QixnSUFBQSx3QkFBd0IsT0FBQTtBQUN4QiwrSEFBQSx1QkFBdUIsT0FBQTtBQUN2QixnSUFBQSx3QkFBd0IsT0FBQTtBQUN4QixxSUFBQSw2QkFBNkIsT0FBQTtBQUUvQixxQ0FBc0Q7QUFBN0MsaUdBQUEsU0FBUyxPQUFBO0FBQUUsbUdBQUEsV0FBVyxPQUFBIiwic291cmNlc0NvbnRlbnQiOlsiLyoqXG4gKiBQdWJsaWMgQVBJOiByZWZyZXNoIHRva2VuIHN0b3JlIHR5cGVzLCBEeW5hbW9EQi1iYWNrZWQgaW1wbGVtZW50YXRpb24sIGVycm9ycywgYW5kIGNyeXB0byBoZWxwZXJzLlxuICovXG5leHBvcnQgdHlwZSB7XG4gIFJlZnJlc2hUb2tlblN0b3JlLFxuICBJc3N1ZVBhcmFtcyxcbiAgSXNzdWVSZXN1bHQsXG4gIFJvdGF0ZVBhcmFtcyxcbiAgUm90YXRlUmVzdWx0LFxuICBSZXZva2VQYXJhbXMsXG4gIFN0b3JlT3B0aW9ucyxcbiAgVG9rZW5SZWNvcmQsXG4gIEVwb2NoU2VjLFxufSBmcm9tICcuL3R5cGVzL2luZGV4JztcblxuZXhwb3J0IHsgRHluYW1vUmVmcmVzaFRva2VuU3RvcmUgfSBmcm9tICcuL3N0b3Jlcy9keW5hbW9kYic7XG5leHBvcnQge1xuICBSZWZyZXNoVG9rZW5FcnJvcixcbiAgUmVmcmVzaFRva2VuRXhwaXJlZEVycm9yLFxuICBSZWZyZXNoVG9rZW5JbnZhbGlkRXJyb3IsXG4gIFJlZnJlc2hUb2tlblJldXNlZEVycm9yLFxuICBSZWZyZXNoVG9rZW5SZXZva2VkRXJyb3IsXG4gIFJlZnJlc2hUb2tlblJvdGF0ZUZhaWxlZEVycm9yLFxufSBmcm9tICcuL3N0b3Jlcy9yZWZyZXNoLXRva2VuLWVycm9ycyc7XG5leHBvcnQgeyBzaGEyNTZoZXgsIHJhbmRvbXRva2VuIH0gZnJvbSAnLi91dGlscy9oYXNoJztcbiJdfQ==
@@ -0,0 +1,65 @@
1
+ import type { RefreshTokenStore, StoreOptions, TokenRecord, IssueParams, RotateParams, RevokeParams, IssueResult, RotateResult } from '../types/index';
2
+ /** Re-exported types for consumers that import the DynamoDB store module. */
3
+ export { RefreshTokenStore, StoreOptions, TokenRecord, IssueParams, RotateParams, RevokeParams, IssueResult, RotateResult };
4
+ /**
5
+ * {@link RefreshTokenStore} implementation using a single DynamoDB table.
6
+ *
7
+ * This class owns the DynamoDB client; callers supply `tableName`, `region`, and optional {@link StoreOptions}.
8
+ */
9
+ export declare class DynamoRefreshTokenStore implements RefreshTokenStore {
10
+ private readonly tableName;
11
+ private readonly region;
12
+ private readonly options?;
13
+ /** Lazily initialized and cached document client. */
14
+ private ddb;
15
+ /** Random byte length for generated refresh tokens (default 32 → 256-bit). */
16
+ private readonly tokenBytes;
17
+ /**
18
+ * @param tableName - DynamoDB table name for refresh token items.
19
+ * @param region - AWS region for the DynamoDB client.
20
+ * @param options - TTL, PK prefix, consistent reads, or custom endpoint.
21
+ */
22
+ constructor(tableName: string, region: string, options?: StoreOptions | undefined);
23
+ /**
24
+ * Inserts a new token record. Fails the put if the partition key already exists.
25
+ *
26
+ * @param params - Subject, session, and optional clock (`now`).
27
+ * @returns Plaintext refresh token and expiration as Unix seconds.
28
+ */
29
+ issue: (params: IssueParams) => Promise<IssueResult>;
30
+ /**
31
+ * Marks the current token as rotated and creates the successor row in one transaction.
32
+ *
33
+ * @param params - Client refresh token and optional clock (`now`).
34
+ * @returns Subject, session, new plaintext token, and new expiration.
35
+ * @throws {@link RefreshTokenInvalidError} When the token format is invalid or no row exists.
36
+ * @throws {@link RefreshTokenExpiredError} When `expiresAt` is not after `now`.
37
+ * @throws {@link RefreshTokenRevokedError} When the token row has `revokedAt` set.
38
+ * @throws {@link RefreshTokenReusedError} When the token was already rotated or the transaction indicates reuse.
39
+ */
40
+ rotate: (params: RotateParams) => Promise<RotateResult>;
41
+ /**
42
+ * Sets `revokedAt` on the token row. Missing items succeed (idempotent revoke).
43
+ *
44
+ * @param params - Refresh token and optional clock (`now`).
45
+ * @returns `true` after a successful update or no-op when the item is absent.
46
+ * @throws {@link RefreshTokenInvalidError} When the token string format is invalid.
47
+ */
48
+ revoke: (params: RevokeParams) => Promise<true>;
49
+ /** Returns the cached client, creating it on first use. */
50
+ private getddb;
51
+ /** Loads a token row by partition key, or `null` if absent. */
52
+ private getTokenRecord;
53
+ /** Effective PK prefix from options or {@link DEFAULT_PRIMARY_KEY_PREFIX}. */
54
+ private getPrimaryKeyPrefix;
55
+ /** Full partition key: prefix + SHA-256 hex of the raw token. */
56
+ private getPrimaryKey;
57
+ /** Expiration timestamp: `nowSec` plus TTL from options (default 60 days). */
58
+ private makeExpiresAt;
59
+ /**
60
+ * Ensures the token is non-empty and matches the expected base64url length for `tokenBytes` (32 bytes → URL-safe base64 length).
61
+ *
62
+ * @throws {@link RefreshTokenInvalidError} When validation fails.
63
+ */
64
+ private validateRefreshToken;
65
+ }
@@ -0,0 +1,226 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DynamoRefreshTokenStore = void 0;
4
+ const client_dynamodb_1 = require("@aws-sdk/client-dynamodb");
5
+ const lib_dynamodb_1 = require("@aws-sdk/lib-dynamodb");
6
+ const refresh_token_errors_1 = require("./refresh-token-errors");
7
+ const hash_1 = require("../utils/hash");
8
+ const time_1 = require("../utils/time");
9
+ /** Default partition key prefix for refresh token items. */
10
+ const DEFAULT_PRIMARY_KEY_PREFIX = 'rt#';
11
+ /**
12
+ * {@link RefreshTokenStore} implementation using a single DynamoDB table.
13
+ *
14
+ * This class owns the DynamoDB client; callers supply `tableName`, `region`, and optional {@link StoreOptions}.
15
+ */
16
+ class DynamoRefreshTokenStore {
17
+ /**
18
+ * @param tableName - DynamoDB table name for refresh token items.
19
+ * @param region - AWS region for the DynamoDB client.
20
+ * @param options - TTL, PK prefix, consistent reads, or custom endpoint.
21
+ */
22
+ constructor(tableName, region, options) {
23
+ this.tableName = tableName;
24
+ this.region = region;
25
+ this.options = options;
26
+ /** Lazily initialized and cached document client. */
27
+ this.ddb = null;
28
+ /** Random byte length for generated refresh tokens (default 32 → 256-bit). */
29
+ this.tokenBytes = 32;
30
+ /**
31
+ * Inserts a new token record. Fails the put if the partition key already exists.
32
+ *
33
+ * @param params - Subject, session, and optional clock (`now`).
34
+ * @returns Plaintext refresh token and expiration as Unix seconds.
35
+ */
36
+ this.issue = async (params) => {
37
+ const ddb = this.getddb();
38
+ const now = params.now ?? new Date();
39
+ const nowSec = (0, time_1.epochsec)(now);
40
+ const expiresAt = this.makeExpiresAt(nowSec);
41
+ const refreshToken = (0, hash_1.randomtoken)(this.tokenBytes);
42
+ const hash = (0, hash_1.sha256hex)(refreshToken);
43
+ const pk = this.getPrimaryKey(hash);
44
+ await ddb.send(new lib_dynamodb_1.PutCommand({
45
+ TableName: this.tableName,
46
+ Item: {
47
+ pk,
48
+ subjectId: params.subjectId,
49
+ sessionId: params.sessionId,
50
+ createdAt: nowSec,
51
+ expiresAt,
52
+ },
53
+ ConditionExpression: 'attribute_not_exists(pk)',
54
+ }));
55
+ return {
56
+ refreshToken,
57
+ refreshTokenExpiresAt: expiresAt,
58
+ };
59
+ };
60
+ /**
61
+ * Marks the current token as rotated and creates the successor row in one transaction.
62
+ *
63
+ * @param params - Client refresh token and optional clock (`now`).
64
+ * @returns Subject, session, new plaintext token, and new expiration.
65
+ * @throws {@link RefreshTokenInvalidError} When the token format is invalid or no row exists.
66
+ * @throws {@link RefreshTokenExpiredError} When `expiresAt` is not after `now`.
67
+ * @throws {@link RefreshTokenRevokedError} When the token row has `revokedAt` set.
68
+ * @throws {@link RefreshTokenReusedError} When the token was already rotated or the transaction indicates reuse.
69
+ */
70
+ this.rotate = async (params) => {
71
+ // validate refresh token
72
+ this.validateRefreshToken(params.refreshToken);
73
+ const ddb = this.getddb();
74
+ const now = params.now ?? new Date();
75
+ const nowSec = (0, time_1.epochsec)(now);
76
+ const currentHash = (0, hash_1.sha256hex)(params.refreshToken);
77
+ const currentPk = this.getPrimaryKey(currentHash);
78
+ const current = await this.getTokenRecord(currentPk);
79
+ if (!current) {
80
+ throw new refresh_token_errors_1.RefreshTokenInvalidError();
81
+ }
82
+ if (current.expiresAt <= nowSec) {
83
+ throw new refresh_token_errors_1.RefreshTokenExpiredError();
84
+ }
85
+ if (current.revokedAt) {
86
+ throw new refresh_token_errors_1.RefreshTokenRevokedError();
87
+ }
88
+ if (current.rotatedAt) {
89
+ throw new refresh_token_errors_1.RefreshTokenReusedError();
90
+ }
91
+ const nextRefreshTokenExpiresAt = this.makeExpiresAt(nowSec);
92
+ const nextRefreshToken = (0, hash_1.randomtoken)(this.tokenBytes);
93
+ const nextHash = (0, hash_1.sha256hex)(nextRefreshToken);
94
+ const nextPk = this.getPrimaryKey(nextHash);
95
+ try {
96
+ await ddb.send(new lib_dynamodb_1.TransactWriteCommand({
97
+ TransactItems: [
98
+ {
99
+ Update: {
100
+ TableName: this.tableName,
101
+ Key: { pk: currentPk },
102
+ UpdateExpression: 'SET rotatedAt = :now, replacedByPk = :nextPk',
103
+ ConditionExpression: 'attribute_exists(pk) AND attribute_not_exists(rotatedAt) AND attribute_not_exists(revokedAt)',
104
+ ExpressionAttributeValues: {
105
+ ':now': nowSec,
106
+ ':nextPk': nextPk,
107
+ },
108
+ },
109
+ },
110
+ {
111
+ Put: {
112
+ TableName: this.tableName,
113
+ Item: {
114
+ pk: nextPk,
115
+ subjectId: current.subjectId,
116
+ sessionId: current.sessionId,
117
+ createdAt: nowSec,
118
+ expiresAt: nextRefreshTokenExpiresAt,
119
+ },
120
+ ConditionExpression: 'attribute_not_exists(pk)',
121
+ },
122
+ },
123
+ ],
124
+ }));
125
+ }
126
+ catch (error) {
127
+ if (error instanceof Error && error.name === 'TransactionCanceledException') {
128
+ // Treat conditional transaction failure as token reuse.
129
+ throw new refresh_token_errors_1.RefreshTokenReusedError();
130
+ }
131
+ throw error;
132
+ }
133
+ return {
134
+ subjectId: current.subjectId,
135
+ sessionId: current.sessionId,
136
+ refreshToken: nextRefreshToken,
137
+ refreshTokenExpiresAt: nextRefreshTokenExpiresAt,
138
+ };
139
+ };
140
+ /**
141
+ * Sets `revokedAt` on the token row. Missing items succeed (idempotent revoke).
142
+ *
143
+ * @param params - Refresh token and optional clock (`now`).
144
+ * @returns `true` after a successful update or no-op when the item is absent.
145
+ * @throws {@link RefreshTokenInvalidError} When the token string format is invalid.
146
+ */
147
+ this.revoke = async (params) => {
148
+ // validate refresh token
149
+ this.validateRefreshToken(params.refreshToken);
150
+ const ddb = this.getddb();
151
+ const now = params.now ?? new Date();
152
+ const nowSec = (0, time_1.epochsec)(now);
153
+ const hash = (0, hash_1.sha256hex)(params.refreshToken);
154
+ const pk = this.getPrimaryKey(hash);
155
+ try {
156
+ await ddb.send(new lib_dynamodb_1.UpdateCommand({
157
+ TableName: this.tableName,
158
+ Key: { pk },
159
+ UpdateExpression: 'SET revokedAt = :now',
160
+ ConditionExpression: 'attribute_exists(pk)',
161
+ ExpressionAttributeValues: {
162
+ ':now': nowSec,
163
+ },
164
+ }));
165
+ }
166
+ catch (error) {
167
+ // Missing item: treat as success (idempotent revoke).
168
+ if (error instanceof Error && error.name === 'ConditionalCheckFailedException') {
169
+ return true;
170
+ }
171
+ throw error;
172
+ }
173
+ return true;
174
+ };
175
+ /** Returns the cached client, creating it on first use. */
176
+ this.getddb = () => {
177
+ if (!this.ddb) {
178
+ const client = new client_dynamodb_1.DynamoDBClient({
179
+ region: this.region,
180
+ endpoint: (() => {
181
+ if (this.options?.endpoint) {
182
+ return this.options.endpoint;
183
+ }
184
+ return `https://dynamodb.${this.region}.amazonaws.com`;
185
+ })(),
186
+ });
187
+ this.ddb = lib_dynamodb_1.DynamoDBDocumentClient.from(client);
188
+ }
189
+ return this.ddb;
190
+ };
191
+ /** Loads a token row by partition key, or `null` if absent. */
192
+ this.getTokenRecord = async (pk) => {
193
+ const ddb = this.getddb();
194
+ const res = await ddb.send(new lib_dynamodb_1.GetCommand({
195
+ TableName: this.tableName,
196
+ Key: { pk },
197
+ ConsistentRead: this.options?.consistentRead ?? true,
198
+ }));
199
+ return res.Item ?? null;
200
+ };
201
+ /** Effective PK prefix from options or {@link DEFAULT_PRIMARY_KEY_PREFIX}. */
202
+ this.getPrimaryKeyPrefix = () => {
203
+ return `${this.options?.pkPrefix ?? DEFAULT_PRIMARY_KEY_PREFIX}`;
204
+ };
205
+ /** Full partition key: prefix + SHA-256 hex of the raw token. */
206
+ this.getPrimaryKey = (hash) => {
207
+ return `${this.getPrimaryKeyPrefix()}${hash}`;
208
+ };
209
+ /** Expiration timestamp: `nowSec` plus TTL from options (default 60 days). */
210
+ this.makeExpiresAt = (nowSec) => {
211
+ return nowSec + (this.options?.ttlDays ?? 60) * 24 * 60 * 60;
212
+ };
213
+ }
214
+ /**
215
+ * Ensures the token is non-empty and matches the expected base64url length for `tokenBytes` (32 bytes → URL-safe base64 length).
216
+ *
217
+ * @throws {@link RefreshTokenInvalidError} When validation fails.
218
+ */
219
+ validateRefreshToken(token) {
220
+ if (!token || token.length !== Math.ceil(this.tokenBytes * 8 / 6)) {
221
+ throw new refresh_token_errors_1.RefreshTokenInvalidError();
222
+ }
223
+ }
224
+ }
225
+ exports.DynamoRefreshTokenStore = DynamoRefreshTokenStore;
226
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZHluYW1vZGIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvc3RvcmVzL2R5bmFtb2RiLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUFBLDhEQUEwRDtBQUMxRCx3REFBNEg7QUFFNUgsaUVBS2dDO0FBRWhDLHdDQUF1RDtBQUN2RCx3Q0FBeUM7QUFLekMsNERBQTREO0FBQzVELE1BQU0sMEJBQTBCLEdBQUcsS0FBSyxDQUFDO0FBRXpDOzs7O0dBSUc7QUFDSCxNQUFhLHVCQUF1QjtJQU9sQzs7OztPQUlHO0lBQ0gsWUFDbUIsU0FBaUIsRUFDakIsTUFBYyxFQUNkLE9BQXNCO1FBRnRCLGNBQVMsR0FBVCxTQUFTLENBQVE7UUFDakIsV0FBTSxHQUFOLE1BQU0sQ0FBUTtRQUNkLFlBQU8sR0FBUCxPQUFPLENBQWU7UUFkekMscURBQXFEO1FBQzdDLFFBQUcsR0FBa0MsSUFBSSxDQUFDO1FBRWxELDhFQUE4RTtRQUM3RCxlQUFVLEdBQUcsRUFBRSxDQUFDO1FBYWpDOzs7OztXQUtHO1FBQ0ksVUFBSyxHQUFHLEtBQUssRUFBRSxNQUFtQixFQUF3QixFQUFFO1lBQ2pFLE1B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d2FpdCBkZGIuc2VuZChuZXcgVHJhbnNhY3RXcml0ZUNvbW1hbmQoe1xuICAgICAgICBUcmFuc2FjdEl0ZW1zOiBbXG4gICAgICAgICAge1xuICAgICAgICAgICAgVXBkYXRlOiB7XG4gICAgICAgICAgICAgIFRhYmxlTmFtZTogdGhpcy50YWJsZU5hbWUsXG4gICAgICAgICAgICAgIEtleTogeyBwazogY3VycmVudFBrIH0sXG4gICAgICAgICAgICAgIFVwZGF0ZUV4cHJlc3Npb246ICdTRVQgcm90YXRlZEF0ID0gOm5vdywgcmVwbGFjZWRCeVBrID0gOm5leHRQaycsXG4gICAgICAgICAgICAgIENvbmRpdGlvbkV4cHJlc3Npb246ICdhdHRyaWJ1dGVfZXhpc3RzKHBrKSBBTkQgYXR0cmlidXRlX25vdF9leGlzdHMocm90YXRlZEF0KSBBTkQgYXR0cmlidXRlX25vdF9leGlzdHMocmV2b2tlZEF0KScsXG4gICAgICAgICAgICAgIEV4cHJlc3Npb25BdHRyaWJ1dGVWYWx1ZXM6IHtcbiAgICAgICAgICAgICAgICAnOm5vdyc6IG5vd1NlYyxcbiAgICAgICAgICAgICAgICAnOm5leHRQayc6IG5leHRQayxcbiAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgIH0sXG4gICAgICAgICAgfSxcbiAgICAgICAgICB7XG4gICAgICAgICAgICBQdXQ6IHtcbiAgICAgICAgICAgICAgVGFibGVOYW1lOiB0aGlzLnRhYmxlTmFtZSxcbiAgICAgICAgICAgICAgSXRlbToge1xuICAgICAgICAgICAgICAgIHBrOiBuZXh0UGssXG4gICAgICAgICAgICAgICAgc3ViamVjdElkOiBjdXJyZW50LnN1YmplY3RJZCxcbiAgICAgICAgICAgICAgICBzZXNzaW9uSWQ6IGN1cnJlbnQuc2Vzc2lvbklkLFxuICAgICAgICAgICAgICAgIGNyZWF0ZWRBdDogbm93U2VjLFxuICAgICAgICAgICAgICAgIGV4cGlyZXNBdDogbmV4dFJlZnJlc2hUb2tlbkV4cGly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HVzIFRUTCBmcm9tIG9wdGlvbnMgKGRlZmF1bHQgNjAgZGF5cykuICovXG4gIHByaXZhdGUgbWFrZUV4cGlyZXNBdCA9IChub3dTZWM6IG51bWJlcik6IG51bWJlciA9PiB7XG4gICAgcmV0dXJuIG5vd1NlYyArICh0aGlzLm9wdGlvbnM/LnR0bERheXMgPz8gNjApICogMjQgKiA2MCAqIDYwO1xuICB9O1xuXG4gIC8qKlxuICAgKiBFbnN1cmVzIHRoZSB0b2tlbiBpcyBub24tZW1wdHkgYW5kIG1hdGNoZXMgdGhlIGV4cGVjdGVkIGJhc2U2NHVybCBsZW5ndGggZm9yIGB0b2tlbkJ5dGVzYCAoMzIgYnl0ZXMg4oaSIFVSTC1zYWZlIGJhc2U2NCBsZW5ndGgpLlxuICAgKlxuICAgKiBAdGhyb3dzIHtAbGluayBSZWZyZXNoVG9rZW5JbnZhbGlkRXJyb3J9IFdoZW4gdmFsaWRhdGlvbiBmYWlscy5cbiAgICovXG4gIHByaXZhdGUgdmFsaWRhdGVSZWZyZXNoVG9rZW4odG9rZW46IHN0cmluZyk6IHZvaWQge1xuICAgIGlmICghdG9rZW4gfHwgdG9rZW4ubGVuZ3RoICE9PSBNYXRoLmNlaWwodGhpcy50b2tlbkJ5dGVzICogOCAvIDYpKSB7XG4gICAgICB0aHJvdyBuZXcgUmVmcmVzaFRva2VuSW52YWxpZEVycm9yKCk7XG4gICAgfVxuICB9XG5cbn1cbiJdfQ==
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Base class for refresh token store errors.
3
+ * Use `instanceof` on concrete classes or this base for handling.
4
+ */
5
+ export declare abstract class RefreshTokenError extends Error {
6
+ protected constructor(message: string);
7
+ }
8
+ /**
9
+ * Thrown when the refresh token is missing, malformed, or not recognized.
10
+ */
11
+ export declare class RefreshTokenInvalidError extends RefreshTokenError {
12
+ constructor(message?: string);
13
+ }
14
+ /**
15
+ * Thrown when the refresh token has passed its expiration time.
16
+ */
17
+ export declare class RefreshTokenExpiredError extends RefreshTokenError {
18
+ constructor(message?: string);
19
+ }
20
+ /**
21
+ * Thrown when the refresh token has been explicitly revoked.
22
+ */
23
+ export declare class RefreshTokenRevokedError extends RefreshTokenError {
24
+ constructor(message?: string);
25
+ }
26
+ /**
27
+ * Thrown when a refresh token is presented after it has already been rotated (reuse detection).
28
+ */
29
+ export declare class RefreshTokenReusedError extends RefreshTokenError {
30
+ constructor(message?: string);
31
+ }
32
+ /**
33
+ * Thrown when rotation fails for a reason other than reuse (e.g. transient store failure).
34
+ */
35
+ export declare class RefreshTokenRotateFailedError extends RefreshTokenError {
36
+ constructor(message?: string);
37
+ }
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RefreshTokenRotateFailedError = exports.RefreshTokenReusedError = exports.RefreshTokenRevokedError = exports.RefreshTokenExpiredError = exports.RefreshTokenInvalidError = exports.RefreshTokenError = void 0;
4
+ /**
5
+ * Base class for refresh token store errors.
6
+ * Use `instanceof` on concrete classes or this base for handling.
7
+ */
8
+ class RefreshTokenError extends Error {
9
+ constructor(message) {
10
+ super(message);
11
+ this.name = new.target.name;
12
+ }
13
+ }
14
+ exports.RefreshTokenError = RefreshTokenError;
15
+ /**
16
+ * Thrown when the refresh token is missing, malformed, or not recognized.
17
+ */
18
+ class RefreshTokenInvalidError extends RefreshTokenError {
19
+ constructor(message = 'The refresh token is missing, malformed, or not recognized.') {
20
+ super(message);
21
+ }
22
+ }
23
+ exports.RefreshTokenInvalidError = RefreshTokenInvalidError;
24
+ /**
25
+ * Thrown when the refresh token has passed its expiration time.
26
+ */
27
+ class RefreshTokenExpiredError extends RefreshTokenError {
28
+ constructor(message = 'The refresh token has expired. Please sign in again.') {
29
+ super(message);
30
+ }
31
+ }
32
+ exports.RefreshTokenExpiredError = RefreshTokenExpiredError;
33
+ /**
34
+ * Thrown when the refresh token has been explicitly revoked.
35
+ */
36
+ class RefreshTokenRevokedError extends RefreshTokenError {
37
+ constructor(message = 'The refresh token has been revoked.') {
38
+ super(message);
39
+ }
40
+ }
41
+ exports.RefreshTokenRevokedError = RefreshTokenRevokedError;
42
+ /**
43
+ * Thrown when a refresh token is presented after it has already been rotated (reuse detection).
44
+ */
45
+ class RefreshTokenReusedError extends RefreshTokenError {
46
+ constructor(message = 'This refresh token has already been rotated and cannot be used again.') {
47
+ super(message);
48
+ }
49
+ }
50
+ exports.RefreshTokenReusedError = RefreshTokenReusedError;
51
+ /**
52
+ * Thrown when rotation fails for a reason other than reuse (e.g. transient store failure).
53
+ */
54
+ class RefreshTokenRotateFailedError extends RefreshTokenError {
55
+ constructor(message = 'The refresh token could not be rotated. Please try signing in again.') {
56
+ super(message);
57
+ }
58
+ }
59
+ exports.RefreshTokenRotateFailedError = RefreshTokenRotateFailedError;
60
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmVmcmVzaC10b2tlbi1lcnJvcnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvc3RvcmVzL3JlZnJlc2gtdG9rZW4tZXJyb3JzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUFBOzs7R0FHRztBQUNILE1BQXNCLGlCQUFrQixTQUFRLEtBQUs7SUFDbkQsWUFBc0IsT0FBZTtRQUNuQyxLQUFLLENBQUMsT0FBTyxDQUFDLENBQUM7UUFDZixJQUFJLENBQUMsSUFBSSxHQUFHLEdBQUcsQ0FBQyxNQUFNLENBQUMsSUFBSSxDQUFDO0lBQzlCLENBQUM7Q0FDRjtBQUxELDhDQUtDO0FBRUQ7O0dBRUc7QUFDSCxNQUFhLHdCQUF5QixTQUFRLGlCQUFpQjtJQUM3RCxZQUNFLE9BQU8sR0FBRyw2REFBNkQ7UUFFdkUsS0FBSyxDQUFDLE9BQU8sQ0FBQyxDQUFDO0lBQ2pCLENBQUM7Q0FDRjtBQU5ELDREQU1DO0FBRUQ7O0dBRUc7QUFDSCxNQUF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m93biB3aGVuIGEgcmVmcmVzaCB0b2tlbiBpcyBwcmVzZW50ZWQgYWZ0ZXIgaXQgaGFzIGFscmVhZHkgYmVlbiByb3RhdGVkIChyZXVzZSBkZXRlY3Rpb24pLlxuICovXG5leHBvcnQgY2xhc3MgUmVmcmVzaFRva2VuUmV1c2VkRXJyb3IgZXh0ZW5kcyBSZWZyZXNoVG9rZW5FcnJvciB7XG4gIGNvbnN0cnVjdG9yKFxuICAgIG1lc3NhZ2UgPSAnVGhpcyByZWZyZXNoIHRva2VuIGhhcyBhbHJlYWR5IGJlZW4gcm90YXRlZCBhbmQgY2Fubm90IGJlIHVzZWQgYWdhaW4uJyxcbiAgKSB7XG4gICAgc3VwZXIobWVzc2FnZSk7XG4gIH1cbn1cblxuLyoqXG4gKiBUaHJvd24gd2hlbiByb3RhdGlvbiBmYWlscyBmb3IgYSByZWFzb24gb3RoZXIgdGhhbiByZXVzZSAoZS5nLiB0cmFuc2llbnQgc3RvcmUgZmFpbHVyZSkuXG4gKi9cbmV4cG9ydCBjbGFzcyBSZWZyZXNoVG9rZW5Sb3RhdGVGYWlsZWRFcnJvciBleHRlbmRzIFJlZnJlc2hUb2tlbkVycm9yIHtcbiAgY29uc3RydWN0b3IoXG4gICAgbWVzc2FnZSA9ICdUaGUgcmVmcmVzaCB0b2tlbiBjb3VsZCBub3QgYmUgcm90YXRlZC4gUGxlYXNlIHRyeSBzaWduaW5nIGluIGFnYWluLicsXG4gICkge1xuICAgIHN1cGVyKG1lc3NhZ2UpO1xuICB9XG59XG4iXX0=
@@ -0,0 +1,91 @@
1
+ /** Unix timestamp in whole seconds. */
2
+ export type EpochSec = number;
3
+ export type StoreOptions = {
4
+ /**
5
+ * Refresh token time-to-live in days.
6
+ * @defaultValue 60
7
+ */
8
+ ttlDays?: number;
9
+ /**
10
+ * Partition key prefix for DynamoDB items.
11
+ * @defaultValue `'rt#'`
12
+ */
13
+ pkPrefix?: string;
14
+ /**
15
+ * Whether to use strongly consistent reads on GetItem.
16
+ * @defaultValue true
17
+ */
18
+ consistentRead?: boolean;
19
+ /**
20
+ * Custom DynamoDB API endpoint (e.g. for LocalStack or DynamoDB Local).
21
+ */
22
+ endpoint?: string;
23
+ };
24
+ export type IssueParams = {
25
+ /** Subject (user) identifier to associate with the token. */
26
+ subjectId: string;
27
+ /** Session identifier to associate with the token. */
28
+ sessionId: string;
29
+ /** Clock override for tests; defaults to `new Date()`. */
30
+ now?: Date;
31
+ };
32
+ export type IssueResult = {
33
+ /** Opaque refresh token string (plaintext; store only a hash at rest). */
34
+ refreshToken: string;
35
+ /** Expiration time as Unix seconds. */
36
+ refreshTokenExpiresAt: EpochSec;
37
+ };
38
+ export type RotateParams = {
39
+ /** Current refresh token from the client. */
40
+ refreshToken: string;
41
+ /** Clock override for tests; defaults to `new Date()`. */
42
+ now?: Date;
43
+ };
44
+ export type RotateResult = {
45
+ subjectId: string;
46
+ sessionId: string;
47
+ /** New opaque refresh token after rotation. */
48
+ refreshToken: string;
49
+ /** Expiration time of the new token as Unix seconds. */
50
+ refreshTokenExpiresAt: EpochSec;
51
+ };
52
+ export type RevokeParams = {
53
+ /** Refresh token to revoke. */
54
+ refreshToken: string;
55
+ /** Clock override for tests; defaults to `new Date()`. */
56
+ now?: Date;
57
+ };
58
+ /** DynamoDB item shape for a stored refresh token (hash-keyed). */
59
+ export type TokenRecord = {
60
+ pk: string;
61
+ subjectId: string;
62
+ sessionId: string;
63
+ createdAt: EpochSec;
64
+ expiresAt: EpochSec;
65
+ rotatedAt?: EpochSec | null;
66
+ replacedByPk?: string | null;
67
+ revokedAt?: EpochSec | null;
68
+ };
69
+ /**
70
+ * Persistence abstraction for opaque refresh tokens: issue, rotate, and revoke.
71
+ */
72
+ export interface RefreshTokenStore {
73
+ /**
74
+ * Creates a new refresh token row and returns the plaintext token.
75
+ *
76
+ * @param params - Subject, session, and optional clock.
77
+ */
78
+ issue(params: IssueParams): Promise<IssueResult>;
79
+ /**
80
+ * Validates the current token, marks it rotated, inserts the successor row, and returns the new token.
81
+ *
82
+ * @param params - Current token and optional clock.
83
+ */
84
+ rotate(params: RotateParams): Promise<RotateResult>;
85
+ /**
86
+ * Sets `revokedAt` on the token row. Idempotent if the row does not exist.
87
+ *
88
+ * @param params - Token to revoke and optional clock.
89
+ */
90
+ revoke(params: RevokeParams): Promise<true>;
91
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdHlwZXMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiIsInNvdXJjZXNDb250ZW50IjpbIi8qKiBVbml4IHRpbWVzdGFtcCBpbiB3aG9sZSBzZWNvbmRzLiAqL1xuZXhwb3J0IHR5cGUgRXBvY2hTZWMgPSBudW1iZXI7XG5cbmV4cG9ydCB0eXBlIFN0b3JlT3B0aW9ucyA9IHtcbiAgLyoqXG4gICAqIFJlZnJlc2ggdG9rZW4gdGltZS10by1saXZlIGluIGRheXMuXG4gICAqIEBkZWZhdWx0VmFsdWUgNjBcbiAgICovXG4gIHR0bERheXM/OiBudW1iZXI7XG5cbiAgLyoqXG4gICAqIFBhcnRpdGlvbiBrZXkgcHJlZml4IGZvciBEeW5hbW9EQiBpdGVtcy5cbiAgICogQGRlZmF1bHRWYWx1ZSBgJ3J0IydgXG4gICAqL1xuICBwa1ByZWZpeD86IHN0cmluZztcblxuICAvKipcbiAgICogV2hldGhlciB0byB1c2Ugc3Ryb25nbHkgY29uc2lzdGVudCByZWFkcyBvbiBHZXRJdGVtLlxuICAgKiBAZGVmYXVsdFZhbHVlIHRydWVcbiAgICovXG4gIGNvbnNpc3RlbnRSZWFkPzogYm9vbGVhbjtcblxuICAvKipcbiAgICogQ3VzdG9tIER5bmFtb0RCIEFQSSBlbmRwb2ludCAo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AvKipcbiAgICogQ3JlYXRlcyBhIG5ldyByZWZyZXNoIHRva2VuIHJvdyBhbmQgcmV0dXJucyB0aGUgcGxhaW50ZXh0IHRva2VuLlxuICAgKlxuICAgKiBAcGFyYW0gcGFyYW1zIC0gU3ViamVjdCwgc2Vzc2lvbiwgYW5kIG9wdGlvbmFsIGNsb2NrLlxuICAgKi9cbiAgaXNzdWUocGFyYW1zOiBJc3N1ZVBhcmFtcyk6IFByb21pc2U8SXNzdWVSZXN1bHQ+O1xuXG4gIC8qKlxuICAgKiBWYWxpZGF0ZXMgdGhlIGN1cnJlbnQgdG9rZW4sIG1hcmtzIGl0IHJvdGF0ZWQsIGluc2VydHMgdGhlIHN1Y2Nlc3NvciByb3csIGFuZCByZXR1cm5zIHRoZSBuZXcgdG9rZW4uXG4gICAqXG4gICAqIEBwYXJhbSBwYXJhbXMgLSBDdXJyZW50IHRva2VuIGFuZCBvcHRpb25hbCBjbG9jay5cbiAgICovXG4gIHJvdGF0ZShwYXJhbXM6IFJvdGF0ZVBhcmFtcyk6IFByb21pc2U8Um90YXRlUmVzdWx0PjtcblxuICAvKipcbiAgICogU2V0cyBgcmV2b2tlZEF0YCBvbiB0aGUgdG9rZW4gcm93LiBJZGVtcG90ZW50IGlmIHRoZSByb3cgZG9lcyBub3QgZXhpc3QuXG4gICAqXG4gICAqIEBwYXJhbSBwYXJhbXMgLSBUb2tlbiB0byByZXZva2UgYW5kIG9wdGlvbmFsIGNsb2NrLlxuICAgKi9cbiAgcmV2b2tlKHBhcmFtczogUmV2b2tlUGFyYW1zKTogUHJvbWlzZTx0cnVlPjtcbn1cbiJdfQ==
@@ -0,0 +1,15 @@
1
+ /**
2
+ * SHA-256 digest of `input` as a lowercase hexadecimal string.
3
+ * Used so refresh tokens are not stored in plaintext in DynamoDB.
4
+ *
5
+ * @param input - String to hash (e.g. raw refresh token).
6
+ * @returns 64-character hex string.
7
+ */
8
+ export declare const sha256hex: (input: string) => string;
9
+ /**
10
+ * Generates an opaque URL-safe refresh token using cryptographically secure random bytes.
11
+ *
12
+ * @param bytes - Number of random bytes (default: 32, i.e. 256 bits).
13
+ * @returns Base64url-encoded token string.
14
+ */
15
+ export declare const randomtoken: (bytes?: number) => string;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.randomtoken = exports.sha256hex = void 0;
7
+ const crypto_1 = __importDefault(require("crypto"));
8
+ /**
9
+ * SHA-256 digest of `input` as a lowercase hexadecimal string.
10
+ * Used so refresh tokens are not stored in plaintext in DynamoDB.
11
+ *
12
+ * @param input - String to hash (e.g. raw refresh token).
13
+ * @returns 64-character hex string.
14
+ */
15
+ const sha256hex = (input) => {
16
+ return crypto_1.default.createHash('sha256').update(input).digest('hex');
17
+ };
18
+ exports.sha256hex = sha256hex;
19
+ /**
20
+ * Generates an opaque URL-safe refresh token using cryptographically secure random bytes.
21
+ *
22
+ * @param bytes - Number of random bytes (default: 32, i.e. 256 bits).
23
+ * @returns Base64url-encoded token string.
24
+ */
25
+ const randomtoken = (bytes = 32) => {
26
+ return crypto_1.default.randomBytes(bytes).toString('base64url');
27
+ };
28
+ exports.randomtoken = randomtoken;
29
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaGFzaC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy91dGlscy9oYXNoLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7OztBQUFBLG9EQUE0QjtBQUU1Qjs7Ozs7O0dBTUc7QUFDSSxNQUFNLFNBQVMsR0FBRyxDQUFDLEtBQWEsRUFBVSxFQUFFO0lBQ2pELE9BQU8sZ0JBQU0sQ0FBQyxVQUFVLENBQUMsUUFBUSxDQUFDLENBQUMsTUFBTSxDQUFDLEtBQUssQ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YgcmFuZG9tIGJ5dGVzIChkZWZhdWx0OiAzMiwgaS5lLiAyNTYgYml0cykuXG4gKiBAcmV0dXJucyBCYXNlNjR1cmwtZW5jb2RlZCB0b2tlbiBzdHJpbmcuXG4gKi9cbmV4cG9ydCBjb25zdCByYW5kb210b2tlbiA9IChieXRlczogbnVtYmVyID0gMzIpOiBzdHJpbmcgPT4ge1xuICByZXR1cm4gY3J5cHRvLnJhbmRvbUJ5dGVzKGJ5dGVzKS50b1N0cmluZygnYmFzZTY0dXJsJyk7XG59O1xuIl19
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Converts a JavaScript `Date` to Unix time in whole seconds (floor).
3
+ *
4
+ * @param date - Instant to convert.
5
+ * @returns Seconds since the Unix epoch.
6
+ */
7
+ export declare const epochsec: (date: Date) => number;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.epochsec = void 0;
4
+ /**
5
+ * Converts a JavaScript `Date` to Unix time in whole seconds (floor).
6
+ *
7
+ * @param date - Instant to convert.
8
+ * @returns Seconds since the Unix epoch.
9
+ */
10
+ const epochsec = (date) => {
11
+ return Math.floor(date.getTime() / 1000);
12
+ };
13
+ exports.epochsec = epochsec;
14
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGltZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy91dGlscy90aW1lLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUFBOzs7OztHQUtHO0FBQ0ksTUFBTSxRQUFRLEdBQUcsQ0FBQyxJQUFVLEVBQVUsRUFBRTtJQUM3QyxPQUFPLElBQUksQ0FBQyxLQUFLLENBQUMsSUFBSSxDQUFDLE9BQU8sRUFBRSxHQUFHLElBQUksQ0FBQyxDQUFDO0FBQzNDLENBQUMsQ0FBQztBQUZXLFFBQUEsUUFBUSxZQUVuQiIsInNvdXJjZXNDb250ZW50IjpbIi8qKlxuICogQ29udmVydHMgYSBKYXZhU2NyaXB0IGBEYXRlYCB0byBVbml4IHRpbWUgaW4gd2hvbGUgc2Vjb25kcyAoZmxvb3IpLlxuICpcbiAqIEBwYXJhbSBkYXRlIC0gSW5zdGFudCB0byBjb252ZXJ0LlxuICogQHJldHVybnMgU2Vjb25kcyBzaW5jZSB0aGUgVW5peCBlcG9jaC5cbiAqL1xuZXhwb3J0IGNvbnN0IGVwb2Noc2VjID0gKGRhdGU6IERhdGUpOiBudW1iZXIgPT4ge1xuICByZXR1cm4gTWF0aC5mbG9vcihkYXRlLmdldFRpbWUoKSAvIDEwMDApO1xufTtcbiJdfQ==
package/package.json ADDED
@@ -0,0 +1,120 @@
1
+ {
2
+ "name": "dynamodb-refresh-token-provider",
3
+ "description": "TypeScript library that stores **opaque refresh tokens** in **Amazon DynamoDB** using AWS SDK for JavaScript v3. Tokens are persisted under a hash of the plaintext value; **issue**, **rotate** (with reuse detection via a transactional write), and **revoke** (idempotent) are supported.",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "https://github.com/gammarers-aws-sdk-modules/dynamodb-refresh-token-provider.git"
7
+ },
8
+ "scripts": {
9
+ "build": "npx projen build",
10
+ "bump": "npx projen bump",
11
+ "clobber": "npx projen clobber",
12
+ "compile": "npx projen compile",
13
+ "default": "npx projen default",
14
+ "eject": "npx projen eject",
15
+ "eslint": "npx projen eslint",
16
+ "package": "npx projen package",
17
+ "post-compile": "npx projen post-compile",
18
+ "post-upgrade": "npx projen post-upgrade",
19
+ "pre-compile": "npx projen pre-compile",
20
+ "release": "npx projen release",
21
+ "test": "npx projen test",
22
+ "test:watch": "npx projen test:watch",
23
+ "unbump": "npx projen unbump",
24
+ "upgrade": "npx projen upgrade",
25
+ "watch": "npx projen watch",
26
+ "projen": "npx projen"
27
+ },
28
+ "author": {
29
+ "name": "yicr",
30
+ "email": "yicr@users.noreply.github.com",
31
+ "organization": false
32
+ },
33
+ "devDependencies": {
34
+ "@stylistic/eslint-plugin": "^2",
35
+ "@types/jest": "^30.0.0",
36
+ "@types/node": "^20",
37
+ "@typescript-eslint/eslint-plugin": "^8",
38
+ "@typescript-eslint/parser": "^8",
39
+ "commit-and-tag-version": "^12",
40
+ "constructs": "^10.0.0",
41
+ "eslint": "^9",
42
+ "eslint-import-resolver-typescript": "^4.4.4",
43
+ "eslint-plugin-import": "^2.32.0",
44
+ "jest": "^30.3.0",
45
+ "jest-junit": "^16",
46
+ "projen": "^0.99.36",
47
+ "ts-jest": "^29.4.9",
48
+ "ts-node": "^10.9.2",
49
+ "typescript": "5.9.x"
50
+ },
51
+ "dependencies": {
52
+ "@aws-sdk/client-dynamodb": "^3.777.0",
53
+ "@aws-sdk/lib-dynamodb": "^3.777.0",
54
+ "@aws-sdk/util-dynamodb": "^3.777.0"
55
+ },
56
+ "engines": {
57
+ "node": ">= 20.0.0"
58
+ },
59
+ "devEngines": {
60
+ "packageManager": {
61
+ "name": "yarn",
62
+ "version": "1.22.22",
63
+ "onFail": "ignore"
64
+ }
65
+ },
66
+ "main": "lib/index.js",
67
+ "license": "Apache-2.0",
68
+ "publishConfig": {
69
+ "access": "public"
70
+ },
71
+ "version": "0.1.2",
72
+ "jest": {
73
+ "coverageProvider": "v8",
74
+ "testMatch": [
75
+ "<rootDir>/@(src|test)/**/*(*.)@(spec|test).ts?(x)",
76
+ "<rootDir>/@(src|test)/**/__tests__/**/*.ts?(x)",
77
+ "<rootDir>/@(projenrc)/**/*(*.)@(spec|test).ts?(x)",
78
+ "<rootDir>/@(projenrc)/**/__tests__/**/*.ts?(x)"
79
+ ],
80
+ "clearMocks": true,
81
+ "collectCoverage": true,
82
+ "coverageReporters": [
83
+ "json",
84
+ "lcov",
85
+ "clover",
86
+ "cobertura",
87
+ "text"
88
+ ],
89
+ "coverageDirectory": "coverage",
90
+ "coveragePathIgnorePatterns": [
91
+ "/node_modules/"
92
+ ],
93
+ "testPathIgnorePatterns": [
94
+ "/node_modules/"
95
+ ],
96
+ "watchPathIgnorePatterns": [
97
+ "/node_modules/"
98
+ ],
99
+ "reporters": [
100
+ "default",
101
+ [
102
+ "jest-junit",
103
+ {
104
+ "outputDirectory": "test-reports"
105
+ }
106
+ ]
107
+ ],
108
+ "transform": {
109
+ "^.+\\.[t]sx?$": [
110
+ "ts-jest",
111
+ {
112
+ "tsconfig": "tsconfig.dev.json"
113
+ }
114
+ ]
115
+ }
116
+ },
117
+ "types": "lib/index.d.ts",
118
+ "packageManager": "yarn@1.22.22",
119
+ "//": "~~ Generated by projen. To modify, edit .projenrc.ts and run \"npx projen\"."
120
+ }