@umbra-privacy/sdk 1.0.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/LICENSE +21 -0
- package/README.md +122 -0
- package/dist/addresses-Brzgurv_.d.ts +145 -0
- package/dist/addresses-D_0YAS6B.d.cts +145 -0
- package/dist/chunk-2Q75CQQJ.js +12 -0
- package/dist/chunk-2Q75CQQJ.js.map +1 -0
- package/dist/chunk-7QVYU63E.js +6 -0
- package/dist/chunk-7QVYU63E.js.map +1 -0
- package/dist/chunk-BM7N6N7E.js +1883 -0
- package/dist/chunk-BM7N6N7E.js.map +1 -0
- package/dist/chunk-GXKSUB2U.cjs +4416 -0
- package/dist/chunk-GXKSUB2U.cjs.map +1 -0
- package/dist/chunk-HOEXDXRC.cjs +792 -0
- package/dist/chunk-HOEXDXRC.cjs.map +1 -0
- package/dist/chunk-MDFSBU5W.cjs +2033 -0
- package/dist/chunk-MDFSBU5W.cjs.map +1 -0
- package/dist/chunk-MQY7HDIA.js +600 -0
- package/dist/chunk-MQY7HDIA.js.map +1 -0
- package/dist/chunk-MVKTV3FT.cjs +20 -0
- package/dist/chunk-MVKTV3FT.cjs.map +1 -0
- package/dist/chunk-PG2J6V6Y.js +4094 -0
- package/dist/chunk-PG2J6V6Y.js.map +1 -0
- package/dist/chunk-PK6SKIKE.cjs +8 -0
- package/dist/chunk-PK6SKIKE.cjs.map +1 -0
- package/dist/chunk-VEGLTTYQ.cjs +621 -0
- package/dist/chunk-VEGLTTYQ.cjs.map +1 -0
- package/dist/chunk-WVHQ46DD.js +758 -0
- package/dist/chunk-WVHQ46DD.js.map +1 -0
- package/dist/constants/index.cjs +316 -0
- package/dist/constants/index.cjs.map +1 -0
- package/dist/constants/index.d.cts +739 -0
- package/dist/constants/index.d.ts +739 -0
- package/dist/constants/index.js +193 -0
- package/dist/constants/index.js.map +1 -0
- package/dist/cryptography-BTGC72u-.d.cts +4809 -0
- package/dist/cryptography-BTGC72u-.d.ts +4809 -0
- package/dist/errors/index.cjs +141 -0
- package/dist/errors/index.cjs.map +1 -0
- package/dist/errors/index.d.cts +1415 -0
- package/dist/errors/index.d.ts +1415 -0
- package/dist/errors/index.js +4 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/index-B9pDY73x.d.ts +12933 -0
- package/dist/index-CLj_zWSD.d.ts +235 -0
- package/dist/index-CX6_pIRS.d.cts +235 -0
- package/dist/index-D33yo0qB.d.cts +12933 -0
- package/dist/index.cjs +22464 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +11694 -0
- package/dist/index.d.ts +11694 -0
- package/dist/index.js +22314 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces/index.cjs +4 -0
- package/dist/interfaces/index.cjs.map +1 -0
- package/dist/interfaces/index.d.cts +8 -0
- package/dist/interfaces/index.d.ts +8 -0
- package/dist/interfaces/index.js +3 -0
- package/dist/interfaces/index.js.map +1 -0
- package/dist/networks-C-orpSFW.d.ts +65 -0
- package/dist/networks-FxYERGD1.d.cts +65 -0
- package/dist/types/index.cjs +605 -0
- package/dist/types/index.cjs.map +1 -0
- package/dist/types/index.d.cts +1853 -0
- package/dist/types/index.d.ts +1853 -0
- package/dist/types/index.js +4 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types-BBuELtY8.d.cts +495 -0
- package/dist/types-n-sHFcgr.d.ts +495 -0
- package/dist/utils/index.cjs +1295 -0
- package/dist/utils/index.cjs.map +1 -0
- package/dist/utils/index.d.cts +9559 -0
- package/dist/utils/index.d.ts +9559 -0
- package/dist/utils/index.js +6 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/versions-D9PqsEvj.d.cts +173 -0
- package/dist/versions-D9PqsEvj.d.ts +173 -0
- package/package.json +151 -0
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { Y as Year, M as Month, D as Day, H as Hour, a as Minute, S as Second } from './types-n-sHFcgr.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Temporal Utilities
|
|
5
|
+
*
|
|
6
|
+
* This module provides utility functions for working with UTC timestamps
|
|
7
|
+
* and extracting calendar components. These utilities are used for
|
|
8
|
+
* time-scoped viewing key derivation and other temporal operations.
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* All functions in this module work exclusively with UTC timestamps to ensure consistent
|
|
12
|
+
* key derivation regardless of the local timezone of the machine running the SDK.
|
|
13
|
+
*
|
|
14
|
+
* The dependency-injection pattern (`getUtcNowFunction`, `getExtractUtcComponentsFunction`)
|
|
15
|
+
* allows tests to inject a fixed `dateProvider` so that time-based key derivation is
|
|
16
|
+
* deterministic in test environments.
|
|
17
|
+
*
|
|
18
|
+
* @packageDocumentation
|
|
19
|
+
* @module common/temporal
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* UTC timestamp components decomposed into individually branded fields.
|
|
24
|
+
*
|
|
25
|
+
* Contains all six calendar components extracted from a UTC timestamp. Each field is
|
|
26
|
+
* a branded type that enforces the correct range at compile time and runtime.
|
|
27
|
+
*
|
|
28
|
+
* @remarks
|
|
29
|
+
* This interface is produced by `extractUtcComponents` and `getUtcNow`. It is consumed
|
|
30
|
+
* by time-scoped viewing key derivation functions to select the correct time granularity
|
|
31
|
+
* (yearly, monthly, daily, etc.).
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* const now: UtcTimestampComponents = getUtcNow();
|
|
36
|
+
* // now.year is a Year, now.month is a Month, etc.
|
|
37
|
+
* const yearKey = deriveYearlyViewingKey(masterViewingKey, now.year);
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @see {@link extractUtcComponents}
|
|
41
|
+
* @see {@link getUtcNow}
|
|
42
|
+
* @public
|
|
43
|
+
*/
|
|
44
|
+
interface UtcTimestampComponents {
|
|
45
|
+
/**
|
|
46
|
+
* The year component in the range [0, 9999].
|
|
47
|
+
* @see {@link Year}
|
|
48
|
+
*/
|
|
49
|
+
year: Year;
|
|
50
|
+
/**
|
|
51
|
+
* The month component in the range [1, 12] (1 = January, 12 = December).
|
|
52
|
+
* @see {@link Month}
|
|
53
|
+
*/
|
|
54
|
+
month: Month;
|
|
55
|
+
/**
|
|
56
|
+
* The day-of-month component in the range [1, 31].
|
|
57
|
+
* @see {@link Day}
|
|
58
|
+
*/
|
|
59
|
+
day: Day;
|
|
60
|
+
/**
|
|
61
|
+
* The hour component in 24-hour format, in the range [0, 23].
|
|
62
|
+
* @see {@link Hour}
|
|
63
|
+
*/
|
|
64
|
+
hour: Hour;
|
|
65
|
+
/**
|
|
66
|
+
* The minute component in the range [0, 59].
|
|
67
|
+
* @see {@link Minute}
|
|
68
|
+
*/
|
|
69
|
+
minute: Minute;
|
|
70
|
+
/**
|
|
71
|
+
* The second component in the range [0, 59].
|
|
72
|
+
* @see {@link Second}
|
|
73
|
+
*/
|
|
74
|
+
second: Second;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Function type for getting the current UTC timestamp components.
|
|
78
|
+
*
|
|
79
|
+
* @remarks
|
|
80
|
+
* Implementations should return the current moment in UTC. The default implementation calls
|
|
81
|
+
* `new Date()`, but tests can substitute a fixed-time provider via `getUtcNowFunction`.
|
|
82
|
+
*
|
|
83
|
+
* @returns The current UTC timestamp decomposed into branded calendar components
|
|
84
|
+
*
|
|
85
|
+
* @see {@link getUtcNowFunction}
|
|
86
|
+
* @see {@link defaultGetUtcNow}
|
|
87
|
+
* @public
|
|
88
|
+
*/
|
|
89
|
+
type GetUtcNowFunction = () => UtcTimestampComponents;
|
|
90
|
+
/**
|
|
91
|
+
* Function type for extracting UTC components from a `Date` object.
|
|
92
|
+
*
|
|
93
|
+
* @remarks
|
|
94
|
+
* Useful when working with a specific historical timestamp rather than the current time.
|
|
95
|
+
*
|
|
96
|
+
* @param date - A JavaScript `Date` object (any timezone; UTC getters are always used)
|
|
97
|
+
* @returns The timestamp decomposed into branded UTC calendar components
|
|
98
|
+
*
|
|
99
|
+
* @see {@link getExtractUtcComponentsFunction}
|
|
100
|
+
* @see {@link defaultExtractUtcComponents}
|
|
101
|
+
* @public
|
|
102
|
+
*/
|
|
103
|
+
type ExtractUtcComponentsFunction = (date: Date) => UtcTimestampComponents;
|
|
104
|
+
/**
|
|
105
|
+
* Extracts UTC timestamp components from a `Date` object.
|
|
106
|
+
*
|
|
107
|
+
* @remarks
|
|
108
|
+
* All calendar components are extracted using the `getUTC*` family of methods, so the
|
|
109
|
+
* result is independent of the local timezone setting of the host machine.
|
|
110
|
+
*
|
|
111
|
+
* Month is adjusted from the 0-indexed `Date.getUTCMonth()` (0–11) to the 1-indexed
|
|
112
|
+
* `Month` branded type (1–12).
|
|
113
|
+
*
|
|
114
|
+
* @param date - The `Date` object to extract components from
|
|
115
|
+
* @returns The six UTC calendar components as branded `UtcTimestampComponents`
|
|
116
|
+
* @throws {TemporalAssertionError} If any extracted component is out of range (should not
|
|
117
|
+
* occur with valid `Date` objects produced by the JavaScript runtime)
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```typescript
|
|
121
|
+
* const date = new Date('2024-06-15T14:30:45Z');
|
|
122
|
+
* const components = extractUtcComponents(date);
|
|
123
|
+
* // { year: 2024n, month: 6n, day: 15n, hour: 14n, minute: 30n, second: 45n }
|
|
124
|
+
* ```
|
|
125
|
+
*
|
|
126
|
+
* @see {@link UtcTimestampComponents}
|
|
127
|
+
* @see {@link getUtcNow}
|
|
128
|
+
* @public
|
|
129
|
+
*/
|
|
130
|
+
declare function extractUtcComponents(date: Date): UtcTimestampComponents;
|
|
131
|
+
/**
|
|
132
|
+
* Gets the current UTC timestamp components.
|
|
133
|
+
*
|
|
134
|
+
* @remarks
|
|
135
|
+
* Equivalent to calling `extractUtcComponents(new Date())`. Provided as a convenience
|
|
136
|
+
* function for the common case of deriving keys for the current moment.
|
|
137
|
+
*
|
|
138
|
+
* @returns The current UTC timestamp decomposed into branded calendar components
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```typescript
|
|
142
|
+
* const now = getUtcNow();
|
|
143
|
+
* console.log(`Current UTC: ${now.year}-${now.month}-${now.day} ${now.hour}:${now.minute}:${now.second}`);
|
|
144
|
+
* ```
|
|
145
|
+
*
|
|
146
|
+
* @see {@link extractUtcComponents}
|
|
147
|
+
* @see {@link defaultGetUtcNow}
|
|
148
|
+
* @public
|
|
149
|
+
*/
|
|
150
|
+
declare function getUtcNow(): UtcTimestampComponents;
|
|
151
|
+
/**
|
|
152
|
+
* Creates a UTC timestamp components getter with optional dependency injection.
|
|
153
|
+
*
|
|
154
|
+
* @remarks
|
|
155
|
+
* Use this factory when you need to inject a custom date source for testing or for
|
|
156
|
+
* deterministic key derivation in non-interactive scripts. The returned function captures
|
|
157
|
+
* `dateProvider` in its closure.
|
|
158
|
+
*
|
|
159
|
+
* @param deps - Optional dependency overrides
|
|
160
|
+
* @param deps.dateProvider - A zero-argument function returning the current `Date`. Defaults
|
|
161
|
+
* to `() => new Date()`.
|
|
162
|
+
* @defaultValue `deps` — `undefined` (uses real system clock)
|
|
163
|
+
* @returns A `GetUtcNowFunction` that calls `dateProvider` on each invocation
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* ```typescript
|
|
167
|
+
* // Default usage
|
|
168
|
+
* const getUtc = getUtcNowFunction();
|
|
169
|
+
* const now = getUtc();
|
|
170
|
+
*
|
|
171
|
+
* // With custom date provider (for testing)
|
|
172
|
+
* const getUtc = getUtcNowFunction({
|
|
173
|
+
* dateProvider: () => new Date('2024-06-15T14:30:45Z')
|
|
174
|
+
* });
|
|
175
|
+
* const fixedTime = getUtc();
|
|
176
|
+
* ```
|
|
177
|
+
*
|
|
178
|
+
* @see {@link GetUtcNowFunction}
|
|
179
|
+
* @see {@link defaultGetUtcNow}
|
|
180
|
+
* @public
|
|
181
|
+
*/
|
|
182
|
+
declare function getUtcNowFunction(deps?: {
|
|
183
|
+
dateProvider?: () => Date;
|
|
184
|
+
}): GetUtcNowFunction;
|
|
185
|
+
/**
|
|
186
|
+
* Creates an extractor function for UTC components with optional dependency injection.
|
|
187
|
+
*
|
|
188
|
+
* @remarks
|
|
189
|
+
* Currently a pass-through to `extractUtcComponents`. The `deps` parameter is reserved
|
|
190
|
+
* for future use (e.g., injecting a custom calendar implementation). Prefer
|
|
191
|
+
* `defaultExtractUtcComponents` unless you need the factory pattern for consistency with
|
|
192
|
+
* other injectable utilities in the SDK.
|
|
193
|
+
*
|
|
194
|
+
* @param deps - Reserved for future dependency overrides; currently unused
|
|
195
|
+
* @returns An `ExtractUtcComponentsFunction` backed by the built-in `extractUtcComponents`
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* ```typescript
|
|
199
|
+
* const extract = getExtractUtcComponentsFunction();
|
|
200
|
+
* const components = extract(new Date());
|
|
201
|
+
* ```
|
|
202
|
+
*
|
|
203
|
+
* @see {@link ExtractUtcComponentsFunction}
|
|
204
|
+
* @see {@link defaultExtractUtcComponents}
|
|
205
|
+
* @public
|
|
206
|
+
*/
|
|
207
|
+
declare function getExtractUtcComponentsFunction(deps?: Record<string, never>): ExtractUtcComponentsFunction;
|
|
208
|
+
/**
|
|
209
|
+
* Default `GetUtcNowFunction` using the real system clock.
|
|
210
|
+
*
|
|
211
|
+
* @remarks
|
|
212
|
+
* This is the pre-built instance of `getUtcNowFunction()` for use throughout the SDK.
|
|
213
|
+
* Pass `defaultGetUtcNow` as the `getUtcNow` dependency when constructing SDK services
|
|
214
|
+
* in production. Substitute a custom function in tests.
|
|
215
|
+
*
|
|
216
|
+
* @see {@link GetUtcNowFunction}
|
|
217
|
+
* @see {@link getUtcNowFunction}
|
|
218
|
+
* @public
|
|
219
|
+
*/
|
|
220
|
+
declare const defaultGetUtcNow: GetUtcNowFunction;
|
|
221
|
+
/**
|
|
222
|
+
* Default `ExtractUtcComponentsFunction` backed by `extractUtcComponents`.
|
|
223
|
+
*
|
|
224
|
+
* @remarks
|
|
225
|
+
* This is the pre-built instance for use throughout the SDK when an
|
|
226
|
+
* `ExtractUtcComponentsFunction` is required. Equivalent to calling
|
|
227
|
+
* `getExtractUtcComponentsFunction()` with no arguments.
|
|
228
|
+
*
|
|
229
|
+
* @see {@link ExtractUtcComponentsFunction}
|
|
230
|
+
* @see {@link getExtractUtcComponentsFunction}
|
|
231
|
+
* @public
|
|
232
|
+
*/
|
|
233
|
+
declare const defaultExtractUtcComponents: ExtractUtcComponentsFunction;
|
|
234
|
+
|
|
235
|
+
export { type ExtractUtcComponentsFunction as E, type GetUtcNowFunction as G, type UtcTimestampComponents as U, defaultGetUtcNow as a, getUtcNow as b, getUtcNowFunction as c, defaultExtractUtcComponents as d, extractUtcComponents as e, getExtractUtcComponentsFunction as g };
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { Y as Year, M as Month, D as Day, H as Hour, a as Minute, S as Second } from './types-BBuELtY8.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Temporal Utilities
|
|
5
|
+
*
|
|
6
|
+
* This module provides utility functions for working with UTC timestamps
|
|
7
|
+
* and extracting calendar components. These utilities are used for
|
|
8
|
+
* time-scoped viewing key derivation and other temporal operations.
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* All functions in this module work exclusively with UTC timestamps to ensure consistent
|
|
12
|
+
* key derivation regardless of the local timezone of the machine running the SDK.
|
|
13
|
+
*
|
|
14
|
+
* The dependency-injection pattern (`getUtcNowFunction`, `getExtractUtcComponentsFunction`)
|
|
15
|
+
* allows tests to inject a fixed `dateProvider` so that time-based key derivation is
|
|
16
|
+
* deterministic in test environments.
|
|
17
|
+
*
|
|
18
|
+
* @packageDocumentation
|
|
19
|
+
* @module common/temporal
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* UTC timestamp components decomposed into individually branded fields.
|
|
24
|
+
*
|
|
25
|
+
* Contains all six calendar components extracted from a UTC timestamp. Each field is
|
|
26
|
+
* a branded type that enforces the correct range at compile time and runtime.
|
|
27
|
+
*
|
|
28
|
+
* @remarks
|
|
29
|
+
* This interface is produced by `extractUtcComponents` and `getUtcNow`. It is consumed
|
|
30
|
+
* by time-scoped viewing key derivation functions to select the correct time granularity
|
|
31
|
+
* (yearly, monthly, daily, etc.).
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* const now: UtcTimestampComponents = getUtcNow();
|
|
36
|
+
* // now.year is a Year, now.month is a Month, etc.
|
|
37
|
+
* const yearKey = deriveYearlyViewingKey(masterViewingKey, now.year);
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @see {@link extractUtcComponents}
|
|
41
|
+
* @see {@link getUtcNow}
|
|
42
|
+
* @public
|
|
43
|
+
*/
|
|
44
|
+
interface UtcTimestampComponents {
|
|
45
|
+
/**
|
|
46
|
+
* The year component in the range [0, 9999].
|
|
47
|
+
* @see {@link Year}
|
|
48
|
+
*/
|
|
49
|
+
year: Year;
|
|
50
|
+
/**
|
|
51
|
+
* The month component in the range [1, 12] (1 = January, 12 = December).
|
|
52
|
+
* @see {@link Month}
|
|
53
|
+
*/
|
|
54
|
+
month: Month;
|
|
55
|
+
/**
|
|
56
|
+
* The day-of-month component in the range [1, 31].
|
|
57
|
+
* @see {@link Day}
|
|
58
|
+
*/
|
|
59
|
+
day: Day;
|
|
60
|
+
/**
|
|
61
|
+
* The hour component in 24-hour format, in the range [0, 23].
|
|
62
|
+
* @see {@link Hour}
|
|
63
|
+
*/
|
|
64
|
+
hour: Hour;
|
|
65
|
+
/**
|
|
66
|
+
* The minute component in the range [0, 59].
|
|
67
|
+
* @see {@link Minute}
|
|
68
|
+
*/
|
|
69
|
+
minute: Minute;
|
|
70
|
+
/**
|
|
71
|
+
* The second component in the range [0, 59].
|
|
72
|
+
* @see {@link Second}
|
|
73
|
+
*/
|
|
74
|
+
second: Second;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Function type for getting the current UTC timestamp components.
|
|
78
|
+
*
|
|
79
|
+
* @remarks
|
|
80
|
+
* Implementations should return the current moment in UTC. The default implementation calls
|
|
81
|
+
* `new Date()`, but tests can substitute a fixed-time provider via `getUtcNowFunction`.
|
|
82
|
+
*
|
|
83
|
+
* @returns The current UTC timestamp decomposed into branded calendar components
|
|
84
|
+
*
|
|
85
|
+
* @see {@link getUtcNowFunction}
|
|
86
|
+
* @see {@link defaultGetUtcNow}
|
|
87
|
+
* @public
|
|
88
|
+
*/
|
|
89
|
+
type GetUtcNowFunction = () => UtcTimestampComponents;
|
|
90
|
+
/**
|
|
91
|
+
* Function type for extracting UTC components from a `Date` object.
|
|
92
|
+
*
|
|
93
|
+
* @remarks
|
|
94
|
+
* Useful when working with a specific historical timestamp rather than the current time.
|
|
95
|
+
*
|
|
96
|
+
* @param date - A JavaScript `Date` object (any timezone; UTC getters are always used)
|
|
97
|
+
* @returns The timestamp decomposed into branded UTC calendar components
|
|
98
|
+
*
|
|
99
|
+
* @see {@link getExtractUtcComponentsFunction}
|
|
100
|
+
* @see {@link defaultExtractUtcComponents}
|
|
101
|
+
* @public
|
|
102
|
+
*/
|
|
103
|
+
type ExtractUtcComponentsFunction = (date: Date) => UtcTimestampComponents;
|
|
104
|
+
/**
|
|
105
|
+
* Extracts UTC timestamp components from a `Date` object.
|
|
106
|
+
*
|
|
107
|
+
* @remarks
|
|
108
|
+
* All calendar components are extracted using the `getUTC*` family of methods, so the
|
|
109
|
+
* result is independent of the local timezone setting of the host machine.
|
|
110
|
+
*
|
|
111
|
+
* Month is adjusted from the 0-indexed `Date.getUTCMonth()` (0–11) to the 1-indexed
|
|
112
|
+
* `Month` branded type (1–12).
|
|
113
|
+
*
|
|
114
|
+
* @param date - The `Date` object to extract components from
|
|
115
|
+
* @returns The six UTC calendar components as branded `UtcTimestampComponents`
|
|
116
|
+
* @throws {TemporalAssertionError} If any extracted component is out of range (should not
|
|
117
|
+
* occur with valid `Date` objects produced by the JavaScript runtime)
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```typescript
|
|
121
|
+
* const date = new Date('2024-06-15T14:30:45Z');
|
|
122
|
+
* const components = extractUtcComponents(date);
|
|
123
|
+
* // { year: 2024n, month: 6n, day: 15n, hour: 14n, minute: 30n, second: 45n }
|
|
124
|
+
* ```
|
|
125
|
+
*
|
|
126
|
+
* @see {@link UtcTimestampComponents}
|
|
127
|
+
* @see {@link getUtcNow}
|
|
128
|
+
* @public
|
|
129
|
+
*/
|
|
130
|
+
declare function extractUtcComponents(date: Date): UtcTimestampComponents;
|
|
131
|
+
/**
|
|
132
|
+
* Gets the current UTC timestamp components.
|
|
133
|
+
*
|
|
134
|
+
* @remarks
|
|
135
|
+
* Equivalent to calling `extractUtcComponents(new Date())`. Provided as a convenience
|
|
136
|
+
* function for the common case of deriving keys for the current moment.
|
|
137
|
+
*
|
|
138
|
+
* @returns The current UTC timestamp decomposed into branded calendar components
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```typescript
|
|
142
|
+
* const now = getUtcNow();
|
|
143
|
+
* console.log(`Current UTC: ${now.year}-${now.month}-${now.day} ${now.hour}:${now.minute}:${now.second}`);
|
|
144
|
+
* ```
|
|
145
|
+
*
|
|
146
|
+
* @see {@link extractUtcComponents}
|
|
147
|
+
* @see {@link defaultGetUtcNow}
|
|
148
|
+
* @public
|
|
149
|
+
*/
|
|
150
|
+
declare function getUtcNow(): UtcTimestampComponents;
|
|
151
|
+
/**
|
|
152
|
+
* Creates a UTC timestamp components getter with optional dependency injection.
|
|
153
|
+
*
|
|
154
|
+
* @remarks
|
|
155
|
+
* Use this factory when you need to inject a custom date source for testing or for
|
|
156
|
+
* deterministic key derivation in non-interactive scripts. The returned function captures
|
|
157
|
+
* `dateProvider` in its closure.
|
|
158
|
+
*
|
|
159
|
+
* @param deps - Optional dependency overrides
|
|
160
|
+
* @param deps.dateProvider - A zero-argument function returning the current `Date`. Defaults
|
|
161
|
+
* to `() => new Date()`.
|
|
162
|
+
* @defaultValue `deps` — `undefined` (uses real system clock)
|
|
163
|
+
* @returns A `GetUtcNowFunction` that calls `dateProvider` on each invocation
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* ```typescript
|
|
167
|
+
* // Default usage
|
|
168
|
+
* const getUtc = getUtcNowFunction();
|
|
169
|
+
* const now = getUtc();
|
|
170
|
+
*
|
|
171
|
+
* // With custom date provider (for testing)
|
|
172
|
+
* const getUtc = getUtcNowFunction({
|
|
173
|
+
* dateProvider: () => new Date('2024-06-15T14:30:45Z')
|
|
174
|
+
* });
|
|
175
|
+
* const fixedTime = getUtc();
|
|
176
|
+
* ```
|
|
177
|
+
*
|
|
178
|
+
* @see {@link GetUtcNowFunction}
|
|
179
|
+
* @see {@link defaultGetUtcNow}
|
|
180
|
+
* @public
|
|
181
|
+
*/
|
|
182
|
+
declare function getUtcNowFunction(deps?: {
|
|
183
|
+
dateProvider?: () => Date;
|
|
184
|
+
}): GetUtcNowFunction;
|
|
185
|
+
/**
|
|
186
|
+
* Creates an extractor function for UTC components with optional dependency injection.
|
|
187
|
+
*
|
|
188
|
+
* @remarks
|
|
189
|
+
* Currently a pass-through to `extractUtcComponents`. The `deps` parameter is reserved
|
|
190
|
+
* for future use (e.g., injecting a custom calendar implementation). Prefer
|
|
191
|
+
* `defaultExtractUtcComponents` unless you need the factory pattern for consistency with
|
|
192
|
+
* other injectable utilities in the SDK.
|
|
193
|
+
*
|
|
194
|
+
* @param deps - Reserved for future dependency overrides; currently unused
|
|
195
|
+
* @returns An `ExtractUtcComponentsFunction` backed by the built-in `extractUtcComponents`
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* ```typescript
|
|
199
|
+
* const extract = getExtractUtcComponentsFunction();
|
|
200
|
+
* const components = extract(new Date());
|
|
201
|
+
* ```
|
|
202
|
+
*
|
|
203
|
+
* @see {@link ExtractUtcComponentsFunction}
|
|
204
|
+
* @see {@link defaultExtractUtcComponents}
|
|
205
|
+
* @public
|
|
206
|
+
*/
|
|
207
|
+
declare function getExtractUtcComponentsFunction(deps?: Record<string, never>): ExtractUtcComponentsFunction;
|
|
208
|
+
/**
|
|
209
|
+
* Default `GetUtcNowFunction` using the real system clock.
|
|
210
|
+
*
|
|
211
|
+
* @remarks
|
|
212
|
+
* This is the pre-built instance of `getUtcNowFunction()` for use throughout the SDK.
|
|
213
|
+
* Pass `defaultGetUtcNow` as the `getUtcNow` dependency when constructing SDK services
|
|
214
|
+
* in production. Substitute a custom function in tests.
|
|
215
|
+
*
|
|
216
|
+
* @see {@link GetUtcNowFunction}
|
|
217
|
+
* @see {@link getUtcNowFunction}
|
|
218
|
+
* @public
|
|
219
|
+
*/
|
|
220
|
+
declare const defaultGetUtcNow: GetUtcNowFunction;
|
|
221
|
+
/**
|
|
222
|
+
* Default `ExtractUtcComponentsFunction` backed by `extractUtcComponents`.
|
|
223
|
+
*
|
|
224
|
+
* @remarks
|
|
225
|
+
* This is the pre-built instance for use throughout the SDK when an
|
|
226
|
+
* `ExtractUtcComponentsFunction` is required. Equivalent to calling
|
|
227
|
+
* `getExtractUtcComponentsFunction()` with no arguments.
|
|
228
|
+
*
|
|
229
|
+
* @see {@link ExtractUtcComponentsFunction}
|
|
230
|
+
* @see {@link getExtractUtcComponentsFunction}
|
|
231
|
+
* @public
|
|
232
|
+
*/
|
|
233
|
+
declare const defaultExtractUtcComponents: ExtractUtcComponentsFunction;
|
|
234
|
+
|
|
235
|
+
export { type ExtractUtcComponentsFunction as E, type GetUtcNowFunction as G, type UtcTimestampComponents as U, defaultGetUtcNow as a, getUtcNow as b, getUtcNowFunction as c, defaultExtractUtcComponents as d, extractUtcComponents as e, getExtractUtcComponentsFunction as g };
|