@monocloud/auth-node-core 0.1.5 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +7 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +485 -1050
- package/dist/index.mjs +10 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/dist/index.d.cts +0 -1565
- package/dist/utils/index.d.cts +0 -1
- package/dist/utils/internal.d.cts +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,1143 +1,451 @@
|
|
|
1
|
-
import { AccessToken, AccessToken as AccessToken$1, AuthState, AuthenticateOptions, Authenticators, AuthorizationParams, AuthorizationParams as AuthorizationParams$1, CallbackParams, ClientAuthMethod, CodeChallengeMethod, DisplayOptions, EndSessionParameters, EndSessionParameters as EndSessionParameters$1, Group, IdTokenClaims, IdTokenClaims as IdTokenClaims$1, IssuerMetadata,
|
|
2
|
-
import { SerializeOptions } from "cookie";
|
|
1
|
+
import { AccessToken, AccessToken as AccessToken$1, Address, AuthState, AuthenticateOptions, Authenticators, AuthorizationParams, AuthorizationParams as AuthorizationParams$1, CallbackParams, ClientAuthMethod, CodeChallengeMethod, DisplayOptions, EndSessionParameters, EndSessionParameters as EndSessionParameters$1, Group, IdTokenClaims, IdTokenClaims as IdTokenClaims$1, IssuerMetadata, Jwk, Jwks, JwsHeaderParameters, MonoCloudAuthBaseError, MonoCloudClientOptions, MonoCloudHttpError, MonoCloudOPError, MonoCloudOidcClient, MonoCloudSession, MonoCloudSession as MonoCloudSession$1, MonoCloudTokenError, MonoCloudUser, MonoCloudValidationError, OnSessionCreating as OnCoreSessionCreating, ParResponse, Prompt, PushedAuthorizationParams, RefetchUserInfoOptions, RefreshGrantOptions, RefreshGrantOptions as RefreshGrantOptions$1, RefreshSessionOptions, ResponseModes, ResponseTypes, SecurityAlgorithms, SecurityAlgorithms as SecurityAlgorithms$1, Tokens, UserinfoResponse, UserinfoResponse as UserinfoResponse$1 } from "@monocloud/auth-core";
|
|
2
|
+
import { SerializeOptions, SerializeOptions as SerializeOptions$1, SetCookie } from "cookie";
|
|
3
3
|
|
|
4
|
-
//#region
|
|
5
|
-
/**
|
|
6
|
-
Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
|
|
7
|
-
|
|
8
|
-
@category Type
|
|
9
|
-
*/
|
|
10
|
-
type Primitive = null | undefined | string | number | boolean | symbol | bigint;
|
|
11
|
-
//#endregion
|
|
12
|
-
//#region ../../node_modules/.pnpm/type-fest@5.4.4/node_modules/type-fest/source/is-any.d.ts
|
|
13
|
-
/**
|
|
14
|
-
Returns a boolean for whether the given type is `any`.
|
|
15
|
-
|
|
16
|
-
@link https://stackoverflow.com/a/49928360/1490091
|
|
17
|
-
|
|
18
|
-
Useful in type utilities, such as disallowing `any`s to be passed to a function.
|
|
19
|
-
|
|
20
|
-
@example
|
|
21
|
-
```
|
|
22
|
-
import type {IsAny} from 'type-fest';
|
|
23
|
-
|
|
24
|
-
const typedObject = {a: 1, b: 2} as const;
|
|
25
|
-
const anyObject: any = {a: 1, b: 2};
|
|
26
|
-
|
|
27
|
-
function get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(object: O, key: K) {
|
|
28
|
-
return object[key];
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const typedA = get(typedObject, 'a');
|
|
32
|
-
//=> 1
|
|
33
|
-
|
|
34
|
-
const anyA = get(anyObject, 'a');
|
|
35
|
-
//=> any
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
@category Type Guard
|
|
39
|
-
@category Utilities
|
|
40
|
-
*/
|
|
41
|
-
type IsAny<T> = 0 extends 1 & NoInfer<T> ? true : false;
|
|
42
|
-
//#endregion
|
|
43
|
-
//#region ../../node_modules/.pnpm/type-fest@5.4.4/node_modules/type-fest/source/is-optional-key-of.d.ts
|
|
44
|
-
/**
|
|
45
|
-
Returns a boolean for whether the given key is an optional key of type.
|
|
46
|
-
|
|
47
|
-
This is useful when writing utility types or schema validators that need to differentiate `optional` keys.
|
|
48
|
-
|
|
49
|
-
@example
|
|
50
|
-
```
|
|
51
|
-
import type {IsOptionalKeyOf} from 'type-fest';
|
|
52
|
-
|
|
53
|
-
type User = {
|
|
54
|
-
name: string;
|
|
55
|
-
surname: string;
|
|
56
|
-
|
|
57
|
-
luckyNumber?: number;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
type Admin = {
|
|
61
|
-
name: string;
|
|
62
|
-
surname?: string;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
type T1 = IsOptionalKeyOf<User, 'luckyNumber'>;
|
|
66
|
-
//=> true
|
|
67
|
-
|
|
68
|
-
type T2 = IsOptionalKeyOf<User, 'name'>;
|
|
69
|
-
//=> false
|
|
70
|
-
|
|
71
|
-
type T3 = IsOptionalKeyOf<User, 'name' | 'luckyNumber'>;
|
|
72
|
-
//=> boolean
|
|
73
|
-
|
|
74
|
-
type T4 = IsOptionalKeyOf<User | Admin, 'name'>;
|
|
75
|
-
//=> false
|
|
76
|
-
|
|
77
|
-
type T5 = IsOptionalKeyOf<User | Admin, 'surname'>;
|
|
78
|
-
//=> boolean
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
@category Type Guard
|
|
82
|
-
@category Utilities
|
|
83
|
-
*/
|
|
84
|
-
type IsOptionalKeyOf<Type extends object, Key extends keyof Type> = IsAny<Type | Key> extends true ? never : Key extends keyof Type ? Type extends Record<Key, Type[Key]> ? false : true : false;
|
|
85
|
-
//#endregion
|
|
86
|
-
//#region ../../node_modules/.pnpm/type-fest@5.4.4/node_modules/type-fest/source/optional-keys-of.d.ts
|
|
87
|
-
/**
|
|
88
|
-
Extract all optional keys from the given type.
|
|
89
|
-
|
|
90
|
-
This is useful when you want to create a new type that contains different type values for the optional keys only.
|
|
91
|
-
|
|
92
|
-
@example
|
|
93
|
-
```
|
|
94
|
-
import type {OptionalKeysOf, Except} from 'type-fest';
|
|
95
|
-
|
|
96
|
-
type User = {
|
|
97
|
-
name: string;
|
|
98
|
-
surname: string;
|
|
99
|
-
|
|
100
|
-
luckyNumber?: number;
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
const REMOVE_FIELD = Symbol('remove field symbol');
|
|
104
|
-
type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {
|
|
105
|
-
[Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
const update1: UpdateOperation<User> = {
|
|
109
|
-
name: 'Alice',
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
const update2: UpdateOperation<User> = {
|
|
113
|
-
name: 'Bob',
|
|
114
|
-
luckyNumber: REMOVE_FIELD,
|
|
115
|
-
};
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
@category Utilities
|
|
119
|
-
*/
|
|
120
|
-
type OptionalKeysOf<Type extends object> = Type extends unknown // For distributing `Type`
|
|
121
|
-
? (keyof { [Key in keyof Type as IsOptionalKeyOf<Type, Key> extends false ? never : Key]: never }) & keyof Type // Intersect with `keyof Type` to ensure result of `OptionalKeysOf<Type>` is always assignable to `keyof Type`
|
|
122
|
-
: never;
|
|
123
|
-
//#endregion
|
|
124
|
-
//#region ../../node_modules/.pnpm/type-fest@5.4.4/node_modules/type-fest/source/required-keys-of.d.ts
|
|
125
|
-
/**
|
|
126
|
-
Extract all required keys from the given type.
|
|
127
|
-
|
|
128
|
-
This is useful when you want to create a new type that contains different type values for the required keys only or use the list of keys for validation purposes, etc...
|
|
129
|
-
|
|
130
|
-
@example
|
|
131
|
-
```
|
|
132
|
-
import type {RequiredKeysOf} from 'type-fest';
|
|
133
|
-
|
|
134
|
-
declare function createValidation<
|
|
135
|
-
Entity extends object,
|
|
136
|
-
Key extends RequiredKeysOf<Entity> = RequiredKeysOf<Entity>,
|
|
137
|
-
>(field: Key, validator: (value: Entity[Key]) => boolean): (entity: Entity) => boolean;
|
|
138
|
-
|
|
139
|
-
type User = {
|
|
140
|
-
name: string;
|
|
141
|
-
surname: string;
|
|
142
|
-
luckyNumber?: number;
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
const validator1 = createValidation<User>('name', value => value.length < 25);
|
|
146
|
-
const validator2 = createValidation<User>('surname', value => value.length < 25);
|
|
147
|
-
|
|
148
|
-
// @ts-expect-error
|
|
149
|
-
const validator3 = createValidation<User>('luckyNumber', value => value > 0);
|
|
150
|
-
// Error: Argument of type '"luckyNumber"' is not assignable to parameter of type '"name" | "surname"'.
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
@category Utilities
|
|
154
|
-
*/
|
|
155
|
-
type RequiredKeysOf<Type extends object> = Type extends unknown // For distributing `Type`
|
|
156
|
-
? Exclude<keyof Type, OptionalKeysOf<Type>> : never;
|
|
157
|
-
//#endregion
|
|
158
|
-
//#region ../../node_modules/.pnpm/type-fest@5.4.4/node_modules/type-fest/source/is-never.d.ts
|
|
159
|
-
/**
|
|
160
|
-
Returns a boolean for whether the given type is `never`.
|
|
161
|
-
|
|
162
|
-
@link https://github.com/microsoft/TypeScript/issues/31751#issuecomment-498526919
|
|
163
|
-
@link https://stackoverflow.com/a/53984913/10292952
|
|
164
|
-
@link https://www.zhenghao.io/posts/ts-never
|
|
165
|
-
|
|
166
|
-
Useful in type utilities, such as checking if something does not occur.
|
|
167
|
-
|
|
168
|
-
@example
|
|
169
|
-
```
|
|
170
|
-
import type {IsNever, And} from 'type-fest';
|
|
171
|
-
|
|
172
|
-
type A = IsNever<never>;
|
|
173
|
-
//=> true
|
|
174
|
-
|
|
175
|
-
type B = IsNever<any>;
|
|
176
|
-
//=> false
|
|
177
|
-
|
|
178
|
-
type C = IsNever<unknown>;
|
|
179
|
-
//=> false
|
|
180
|
-
|
|
181
|
-
type D = IsNever<never[]>;
|
|
182
|
-
//=> false
|
|
183
|
-
|
|
184
|
-
type E = IsNever<object>;
|
|
185
|
-
//=> false
|
|
186
|
-
|
|
187
|
-
type F = IsNever<string>;
|
|
188
|
-
//=> false
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
@example
|
|
192
|
-
```
|
|
193
|
-
import type {IsNever} from 'type-fest';
|
|
194
|
-
|
|
195
|
-
type IsTrue<T> = T extends true ? true : false;
|
|
196
|
-
|
|
197
|
-
// When a distributive conditional is instantiated with `never`, the entire conditional results in `never`.
|
|
198
|
-
type A = IsTrue<never>;
|
|
199
|
-
//=> never
|
|
200
|
-
|
|
201
|
-
// If you don't want that behaviour, you can explicitly add an `IsNever` check before the distributive conditional.
|
|
202
|
-
type IsTrueFixed<T> =
|
|
203
|
-
IsNever<T> extends true ? false : T extends true ? true : false;
|
|
204
|
-
|
|
205
|
-
type B = IsTrueFixed<never>;
|
|
206
|
-
//=> false
|
|
207
|
-
```
|
|
208
|
-
|
|
209
|
-
@category Type Guard
|
|
210
|
-
@category Utilities
|
|
211
|
-
*/
|
|
212
|
-
type IsNever<T> = [T] extends [never] ? true : false;
|
|
213
|
-
//#endregion
|
|
214
|
-
//#region ../../node_modules/.pnpm/type-fest@5.4.4/node_modules/type-fest/source/if.d.ts
|
|
215
|
-
/**
|
|
216
|
-
An if-else-like type that resolves depending on whether the given `boolean` type is `true` or `false`.
|
|
217
|
-
|
|
218
|
-
Use-cases:
|
|
219
|
-
- You can use this in combination with `Is*` types to create an if-else-like experience. For example, `If<IsAny<any>, 'is any', 'not any'>`.
|
|
220
|
-
|
|
221
|
-
Note:
|
|
222
|
-
- Returns a union of if branch and else branch if the given type is `boolean` or `any`. For example, `If<boolean, 'Y', 'N'>` will return `'Y' | 'N'`.
|
|
223
|
-
- Returns the else branch if the given type is `never`. For example, `If<never, 'Y', 'N'>` will return `'N'`.
|
|
224
|
-
|
|
225
|
-
@example
|
|
226
|
-
```
|
|
227
|
-
import type {If} from 'type-fest';
|
|
228
|
-
|
|
229
|
-
type A = If<true, 'yes', 'no'>;
|
|
230
|
-
//=> 'yes'
|
|
231
|
-
|
|
232
|
-
type B = If<false, 'yes', 'no'>;
|
|
233
|
-
//=> 'no'
|
|
234
|
-
|
|
235
|
-
type C = If<boolean, 'yes', 'no'>;
|
|
236
|
-
//=> 'yes' | 'no'
|
|
237
|
-
|
|
238
|
-
type D = If<any, 'yes', 'no'>;
|
|
239
|
-
//=> 'yes' | 'no'
|
|
240
|
-
|
|
241
|
-
type E = If<never, 'yes', 'no'>;
|
|
242
|
-
//=> 'no'
|
|
243
|
-
```
|
|
244
|
-
|
|
245
|
-
@example
|
|
246
|
-
```
|
|
247
|
-
import type {If, IsAny, IsNever} from 'type-fest';
|
|
248
|
-
|
|
249
|
-
type A = If<IsAny<unknown>, 'is any', 'not any'>;
|
|
250
|
-
//=> 'not any'
|
|
251
|
-
|
|
252
|
-
type B = If<IsNever<never>, 'is never', 'not never'>;
|
|
253
|
-
//=> 'is never'
|
|
254
|
-
```
|
|
255
|
-
|
|
256
|
-
@example
|
|
257
|
-
```
|
|
258
|
-
import type {If, IsEqual} from 'type-fest';
|
|
259
|
-
|
|
260
|
-
type IfEqual<T, U, IfBranch, ElseBranch> = If<IsEqual<T, U>, IfBranch, ElseBranch>;
|
|
261
|
-
|
|
262
|
-
type A = IfEqual<string, string, 'equal', 'not equal'>;
|
|
263
|
-
//=> 'equal'
|
|
264
|
-
|
|
265
|
-
type B = IfEqual<string, number, 'equal', 'not equal'>;
|
|
266
|
-
//=> 'not equal'
|
|
267
|
-
```
|
|
268
|
-
|
|
269
|
-
Note: Sometimes using the `If` type can make an implementation non–tail-recursive, which can impact performance. In such cases, it’s better to use a conditional directly. Refer to the following example:
|
|
270
|
-
|
|
271
|
-
@example
|
|
272
|
-
```
|
|
273
|
-
import type {If, IsEqual, StringRepeat} from 'type-fest';
|
|
274
|
-
|
|
275
|
-
type HundredZeroes = StringRepeat<'0', 100>;
|
|
276
|
-
|
|
277
|
-
// The following implementation is not tail recursive
|
|
278
|
-
type Includes<S extends string, Char extends string> =
|
|
279
|
-
S extends `${infer First}${infer Rest}`
|
|
280
|
-
? If<IsEqual<First, Char>,
|
|
281
|
-
'found',
|
|
282
|
-
Includes<Rest, Char>>
|
|
283
|
-
: 'not found';
|
|
284
|
-
|
|
285
|
-
// Hence, instantiations with long strings will fail
|
|
286
|
-
// @ts-expect-error
|
|
287
|
-
type Fails = Includes<HundredZeroes, '1'>;
|
|
288
|
-
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
289
|
-
// Error: Type instantiation is excessively deep and possibly infinite.
|
|
290
|
-
|
|
291
|
-
// However, if we use a simple conditional instead of `If`, the implementation becomes tail-recursive
|
|
292
|
-
type IncludesWithoutIf<S extends string, Char extends string> =
|
|
293
|
-
S extends `${infer First}${infer Rest}`
|
|
294
|
-
? IsEqual<First, Char> extends true
|
|
295
|
-
? 'found'
|
|
296
|
-
: IncludesWithoutIf<Rest, Char>
|
|
297
|
-
: 'not found';
|
|
298
|
-
|
|
299
|
-
// Now, instantiations with long strings will work
|
|
300
|
-
type Works = IncludesWithoutIf<HundredZeroes, '1'>;
|
|
301
|
-
//=> 'not found'
|
|
302
|
-
```
|
|
303
|
-
|
|
304
|
-
@category Type Guard
|
|
305
|
-
@category Utilities
|
|
306
|
-
*/
|
|
307
|
-
type If<Type extends boolean, IfBranch, ElseBranch> = IsNever<Type> extends true ? ElseBranch : Type extends true ? IfBranch : ElseBranch;
|
|
308
|
-
//#endregion
|
|
309
|
-
//#region ../../node_modules/.pnpm/type-fest@5.4.4/node_modules/type-fest/source/internal/type.d.ts
|
|
310
|
-
/**
|
|
311
|
-
Matches any primitive, `void`, `Date`, or `RegExp` value.
|
|
312
|
-
*/
|
|
313
|
-
type BuiltIns = Primitive | void | Date | RegExp;
|
|
314
|
-
/**
|
|
315
|
-
Test if the given function has multiple call signatures.
|
|
316
|
-
|
|
317
|
-
Needed to handle the case of a single call signature with properties.
|
|
318
|
-
|
|
319
|
-
Multiple call signatures cannot currently be supported due to a TypeScript limitation.
|
|
320
|
-
@see https://github.com/microsoft/TypeScript/issues/29732
|
|
321
|
-
*/
|
|
322
|
-
type HasMultipleCallSignatures<T extends (...arguments_: any[]) => unknown> = T extends {
|
|
323
|
-
(...arguments_: infer A): unknown;
|
|
324
|
-
(...arguments_: infer B): unknown;
|
|
325
|
-
} ? B extends A ? A extends B ? false : true : true : false;
|
|
326
|
-
//#endregion
|
|
327
|
-
//#region ../../node_modules/.pnpm/type-fest@5.4.4/node_modules/type-fest/source/simplify.d.ts
|
|
328
|
-
/**
|
|
329
|
-
Useful to flatten the type output to improve type hints shown in editors. And also to transform an interface into a type to aide with assignability.
|
|
330
|
-
|
|
331
|
-
@example
|
|
332
|
-
```
|
|
333
|
-
import type {Simplify} from 'type-fest';
|
|
334
|
-
|
|
335
|
-
type PositionProps = {
|
|
336
|
-
top: number;
|
|
337
|
-
left: number;
|
|
338
|
-
};
|
|
339
|
-
|
|
340
|
-
type SizeProps = {
|
|
341
|
-
width: number;
|
|
342
|
-
height: number;
|
|
343
|
-
};
|
|
344
|
-
|
|
345
|
-
// In your editor, hovering over `Props` will show a flattened object with all the properties.
|
|
346
|
-
type Props = Simplify<PositionProps & SizeProps>;
|
|
347
|
-
```
|
|
348
|
-
|
|
349
|
-
Sometimes it is desired to pass a value as a function argument that has a different type. At first inspection it may seem assignable, and then you discover it is not because the `value`'s type definition was defined as an interface. In the following example, `fn` requires an argument of type `Record<string, unknown>`. If the value is defined as a literal, then it is assignable. And if the `value` is defined as type using the `Simplify` utility the value is assignable. But if the `value` is defined as an interface, it is not assignable because the interface is not sealed and elsewhere a non-string property could be added to the interface.
|
|
350
|
-
|
|
351
|
-
If the type definition must be an interface (perhaps it was defined in a third-party npm package), then the `value` can be defined as `const value: Simplify<SomeInterface> = ...`. Then `value` will be assignable to the `fn` argument. Or the `value` can be cast as `Simplify<SomeInterface>` if you can't re-declare the `value`.
|
|
352
|
-
|
|
353
|
-
@example
|
|
354
|
-
```
|
|
355
|
-
import type {Simplify} from 'type-fest';
|
|
356
|
-
|
|
357
|
-
interface SomeInterface {
|
|
358
|
-
foo: number;
|
|
359
|
-
bar?: string;
|
|
360
|
-
baz: number | undefined;
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
type SomeType = {
|
|
364
|
-
foo: number;
|
|
365
|
-
bar?: string;
|
|
366
|
-
baz: number | undefined;
|
|
367
|
-
};
|
|
368
|
-
|
|
369
|
-
const literal = {foo: 123, bar: 'hello', baz: 456};
|
|
370
|
-
const someType: SomeType = literal;
|
|
371
|
-
const someInterface: SomeInterface = literal;
|
|
372
|
-
|
|
373
|
-
declare function fn(object: Record<string, unknown>): void;
|
|
374
|
-
|
|
375
|
-
fn(literal); // Good: literal object type is sealed
|
|
376
|
-
fn(someType); // Good: type is sealed
|
|
377
|
-
// @ts-expect-error
|
|
378
|
-
fn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened
|
|
379
|
-
fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`
|
|
380
|
-
```
|
|
381
|
-
|
|
382
|
-
@link https://github.com/microsoft/TypeScript/issues/15300
|
|
383
|
-
@see {@link SimplifyDeep}
|
|
384
|
-
@category Object
|
|
385
|
-
*/
|
|
386
|
-
type Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {};
|
|
387
|
-
//#endregion
|
|
388
|
-
//#region ../../node_modules/.pnpm/type-fest@5.4.4/node_modules/type-fest/source/is-equal.d.ts
|
|
389
|
-
/**
|
|
390
|
-
Returns a boolean for whether the two given types are equal.
|
|
391
|
-
|
|
392
|
-
@link https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650
|
|
393
|
-
@link https://stackoverflow.com/questions/68961864/how-does-the-equals-work-in-typescript/68963796#68963796
|
|
394
|
-
|
|
395
|
-
Use-cases:
|
|
396
|
-
- If you want to make a conditional branch based on the result of a comparison of two types.
|
|
397
|
-
|
|
398
|
-
@example
|
|
399
|
-
```
|
|
400
|
-
import type {IsEqual} from 'type-fest';
|
|
401
|
-
|
|
402
|
-
// This type returns a boolean for whether the given array includes the given item.
|
|
403
|
-
// `IsEqual` is used to compare the given array at position 0 and the given item and then return true if they are equal.
|
|
404
|
-
type Includes<Value extends readonly any[], Item> =
|
|
405
|
-
Value extends readonly [Value[0], ...infer rest]
|
|
406
|
-
? IsEqual<Value[0], Item> extends true
|
|
407
|
-
? true
|
|
408
|
-
: Includes<rest, Item>
|
|
409
|
-
: false;
|
|
410
|
-
```
|
|
411
|
-
|
|
412
|
-
@category Type Guard
|
|
413
|
-
@category Utilities
|
|
414
|
-
*/
|
|
415
|
-
type IsEqual<A, B> = [A] extends [B] ? [B] extends [A] ? _IsEqual<A, B> : false : false;
|
|
416
|
-
// This version fails the `equalWrappedTupleIntersectionToBeNeverAndNeverExpanded` test in `test-d/is-equal.ts`.
|
|
417
|
-
type _IsEqual<A, B> = (<G>() => G extends A & G | G ? 1 : 2) extends (<G>() => G extends B & G | G ? 1 : 2) ? true : false;
|
|
418
|
-
//#endregion
|
|
419
|
-
//#region ../../node_modules/.pnpm/type-fest@5.4.4/node_modules/type-fest/source/omit-index-signature.d.ts
|
|
420
|
-
/**
|
|
421
|
-
Omit any index signatures from the given object type, leaving only explicitly defined properties.
|
|
422
|
-
|
|
423
|
-
This is the counterpart of `PickIndexSignature`.
|
|
424
|
-
|
|
425
|
-
Use-cases:
|
|
426
|
-
- Remove overly permissive signatures from third-party types.
|
|
427
|
-
|
|
428
|
-
This type was taken from this [StackOverflow answer](https://stackoverflow.com/a/68261113/420747).
|
|
429
|
-
|
|
430
|
-
It relies on the fact that an empty object (`{}`) is assignable to an object with just an index signature, like `Record<string, unknown>`, but not to an object with explicitly defined keys, like `Record<'foo' | 'bar', unknown>`.
|
|
431
|
-
|
|
432
|
-
(The actual value type, `unknown`, is irrelevant and could be any type. Only the key type matters.)
|
|
433
|
-
|
|
434
|
-
```
|
|
435
|
-
const indexed: Record<string, unknown> = {}; // Allowed
|
|
436
|
-
|
|
437
|
-
// @ts-expect-error
|
|
438
|
-
const keyed: Record<'foo', unknown> = {}; // Error
|
|
439
|
-
// TS2739: Type '{}' is missing the following properties from type 'Record<"foo" | "bar", unknown>': foo, bar
|
|
440
|
-
```
|
|
441
|
-
|
|
442
|
-
Instead of causing a type error like the above, you can also use a [conditional type](https://www.typescriptlang.org/docs/handbook/2/conditional-types.html) to test whether a type is assignable to another:
|
|
443
|
-
|
|
444
|
-
```
|
|
445
|
-
type Indexed = {} extends Record<string, unknown>
|
|
446
|
-
? '✅ `{}` is assignable to `Record<string, unknown>`'
|
|
447
|
-
: '❌ `{}` is NOT assignable to `Record<string, unknown>`';
|
|
448
|
-
|
|
449
|
-
type IndexedResult = Indexed;
|
|
450
|
-
//=> '✅ `{}` is assignable to `Record<string, unknown>`'
|
|
451
|
-
|
|
452
|
-
type Keyed = {} extends Record<'foo' | 'bar', unknown>
|
|
453
|
-
? '✅ `{}` is assignable to `Record<\'foo\' | \'bar\', unknown>`'
|
|
454
|
-
: '❌ `{}` is NOT assignable to `Record<\'foo\' | \'bar\', unknown>`';
|
|
455
|
-
|
|
456
|
-
type KeyedResult = Keyed;
|
|
457
|
-
//=> '❌ `{}` is NOT assignable to `Record<\'foo\' | \'bar\', unknown>`'
|
|
458
|
-
```
|
|
459
|
-
|
|
460
|
-
Using a [mapped type](https://www.typescriptlang.org/docs/handbook/2/mapped-types.html#further-exploration), you can then check for each `KeyType` of `ObjectType`...
|
|
461
|
-
|
|
462
|
-
```
|
|
463
|
-
type OmitIndexSignature<ObjectType> = {
|
|
464
|
-
[KeyType in keyof ObjectType // Map each key of `ObjectType`...
|
|
465
|
-
]: ObjectType[KeyType]; // ...to its original value, i.e. `OmitIndexSignature<Foo> == Foo`.
|
|
466
|
-
};
|
|
467
|
-
```
|
|
468
|
-
|
|
469
|
-
...whether an empty object (`{}`) would be assignable to an object with that `KeyType` (`Record<KeyType, unknown>`)...
|
|
470
|
-
|
|
471
|
-
```
|
|
472
|
-
type OmitIndexSignature<ObjectType> = {
|
|
473
|
-
[KeyType in keyof ObjectType
|
|
474
|
-
// Is `{}` assignable to `Record<KeyType, unknown>`?
|
|
475
|
-
as {} extends Record<KeyType, unknown>
|
|
476
|
-
? never // ✅ `{}` is assignable to `Record<KeyType, unknown>`
|
|
477
|
-
: KeyType // ❌ `{}` is NOT assignable to `Record<KeyType, unknown>`
|
|
478
|
-
]: ObjectType[KeyType];
|
|
479
|
-
};
|
|
480
|
-
```
|
|
481
|
-
|
|
482
|
-
If `{}` is assignable, it means that `KeyType` is an index signature and we want to remove it. If it is not assignable, `KeyType` is a "real" key and we want to keep it.
|
|
483
|
-
|
|
484
|
-
@example
|
|
485
|
-
```
|
|
486
|
-
import type {OmitIndexSignature} from 'type-fest';
|
|
487
|
-
|
|
488
|
-
type Example = {
|
|
489
|
-
// These index signatures will be removed.
|
|
490
|
-
[x: string]: any;
|
|
491
|
-
[x: number]: any;
|
|
492
|
-
[x: symbol]: any;
|
|
493
|
-
[x: `head-${string}`]: string;
|
|
494
|
-
[x: `${string}-tail`]: string;
|
|
495
|
-
[x: `head-${string}-tail`]: string;
|
|
496
|
-
[x: `${bigint}`]: string;
|
|
497
|
-
[x: `embedded-${number}`]: string;
|
|
498
|
-
|
|
499
|
-
// These explicitly defined keys will remain.
|
|
500
|
-
foo: 'bar';
|
|
501
|
-
qux?: 'baz';
|
|
502
|
-
};
|
|
503
|
-
|
|
504
|
-
type ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;
|
|
505
|
-
//=> {foo: 'bar'; qux?: 'baz'}
|
|
506
|
-
```
|
|
507
|
-
|
|
508
|
-
@see {@link PickIndexSignature}
|
|
509
|
-
@category Object
|
|
510
|
-
*/
|
|
511
|
-
type OmitIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? never : KeyType]: ObjectType[KeyType] };
|
|
512
|
-
//#endregion
|
|
513
|
-
//#region ../../node_modules/.pnpm/type-fest@5.4.4/node_modules/type-fest/source/pick-index-signature.d.ts
|
|
514
|
-
/**
|
|
515
|
-
Pick only index signatures from the given object type, leaving out all explicitly defined properties.
|
|
516
|
-
|
|
517
|
-
This is the counterpart of `OmitIndexSignature`.
|
|
518
|
-
|
|
519
|
-
@example
|
|
520
|
-
```
|
|
521
|
-
import type {PickIndexSignature} from 'type-fest';
|
|
522
|
-
|
|
523
|
-
declare const symbolKey: unique symbol;
|
|
524
|
-
|
|
525
|
-
type Example = {
|
|
526
|
-
// These index signatures will remain.
|
|
527
|
-
[x: string]: unknown;
|
|
528
|
-
[x: number]: unknown;
|
|
529
|
-
[x: symbol]: unknown;
|
|
530
|
-
[x: `head-${string}`]: string;
|
|
531
|
-
[x: `${string}-tail`]: string;
|
|
532
|
-
[x: `head-${string}-tail`]: string;
|
|
533
|
-
[x: `${bigint}`]: string;
|
|
534
|
-
[x: `embedded-${number}`]: string;
|
|
535
|
-
|
|
536
|
-
// These explicitly defined keys will be removed.
|
|
537
|
-
['kebab-case-key']: string;
|
|
538
|
-
[symbolKey]: string;
|
|
539
|
-
foo: 'bar';
|
|
540
|
-
qux?: 'baz';
|
|
541
|
-
};
|
|
542
|
-
|
|
543
|
-
type ExampleIndexSignature = PickIndexSignature<Example>;
|
|
544
|
-
// {
|
|
545
|
-
// [x: string]: unknown;
|
|
546
|
-
// [x: number]: unknown;
|
|
547
|
-
// [x: symbol]: unknown;
|
|
548
|
-
// [x: `head-${string}`]: string;
|
|
549
|
-
// [x: `${string}-tail`]: string;
|
|
550
|
-
// [x: `head-${string}-tail`]: string;
|
|
551
|
-
// [x: `${bigint}`]: string;
|
|
552
|
-
// [x: `embedded-${number}`]: string;
|
|
553
|
-
// }
|
|
554
|
-
```
|
|
555
|
-
|
|
556
|
-
@see {@link OmitIndexSignature}
|
|
557
|
-
@category Object
|
|
558
|
-
*/
|
|
559
|
-
type PickIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? KeyType : never]: ObjectType[KeyType] };
|
|
560
|
-
//#endregion
|
|
561
|
-
//#region ../../node_modules/.pnpm/type-fest@5.4.4/node_modules/type-fest/source/merge.d.ts
|
|
562
|
-
// Merges two objects without worrying about index signatures.
|
|
563
|
-
type SimpleMerge<Destination, Source> = Simplify<{ [Key in keyof Destination as Key extends keyof Source ? never : Key]: Destination[Key] } & Source>;
|
|
564
|
-
/**
|
|
565
|
-
Merge two types into a new type. Keys of the second type overrides keys of the first type.
|
|
566
|
-
|
|
567
|
-
@example
|
|
568
|
-
```
|
|
569
|
-
import type {Merge} from 'type-fest';
|
|
570
|
-
|
|
571
|
-
type Foo = {
|
|
572
|
-
[x: string]: unknown;
|
|
573
|
-
[x: number]: unknown;
|
|
574
|
-
foo: string;
|
|
575
|
-
bar: symbol;
|
|
576
|
-
};
|
|
577
|
-
|
|
578
|
-
type Bar = {
|
|
579
|
-
[x: number]: number;
|
|
580
|
-
[x: symbol]: unknown;
|
|
581
|
-
bar: Date;
|
|
582
|
-
baz: boolean;
|
|
583
|
-
};
|
|
584
|
-
|
|
585
|
-
export type FooBar = Merge<Foo, Bar>;
|
|
586
|
-
//=> {
|
|
587
|
-
// [x: string]: unknown;
|
|
588
|
-
// [x: number]: number;
|
|
589
|
-
// [x: symbol]: unknown;
|
|
590
|
-
// foo: string;
|
|
591
|
-
// bar: Date;
|
|
592
|
-
// baz: boolean;
|
|
593
|
-
// }
|
|
594
|
-
```
|
|
595
|
-
|
|
596
|
-
Note: If you want a merge type that more accurately reflects the runtime behavior of object spread or `Object.assign`, refer to the {@link ObjectMerge} type.
|
|
597
|
-
|
|
598
|
-
@see {@link ObjectMerge}
|
|
599
|
-
@category Object
|
|
600
|
-
*/
|
|
601
|
-
type Merge<Destination, Source> = Destination extends unknown // For distributing `Destination`
|
|
602
|
-
? Source extends unknown // For distributing `Source`
|
|
603
|
-
? If<IsEqual<Destination, Source>, Destination, _Merge<Destination, Source>> : never // Should never happen
|
|
604
|
-
: never;
|
|
605
|
-
// Should never happen
|
|
606
|
-
type _Merge<Destination, Source> = Simplify<SimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>> & SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>>;
|
|
607
|
-
//#endregion
|
|
608
|
-
//#region ../../node_modules/.pnpm/type-fest@5.4.4/node_modules/type-fest/source/internal/object.d.ts
|
|
609
|
-
/**
|
|
610
|
-
Merges user specified options with default options.
|
|
611
|
-
|
|
612
|
-
@example
|
|
613
|
-
```
|
|
614
|
-
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
615
|
-
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
|
|
616
|
-
type SpecifiedOptions = {leavesOnly: true};
|
|
617
|
-
|
|
618
|
-
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
619
|
-
//=> {maxRecursionDepth: 10; leavesOnly: true}
|
|
620
|
-
```
|
|
621
|
-
|
|
622
|
-
@example
|
|
623
|
-
```
|
|
624
|
-
// Complains if default values are not provided for optional options
|
|
625
|
-
|
|
626
|
-
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
627
|
-
type DefaultPathsOptions = {maxRecursionDepth: 10};
|
|
628
|
-
type SpecifiedOptions = {};
|
|
629
|
-
|
|
630
|
-
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
631
|
-
// ~~~~~~~~~~~~~~~~~~~
|
|
632
|
-
// Property 'leavesOnly' is missing in type 'DefaultPathsOptions' but required in type '{ maxRecursionDepth: number; leavesOnly: boolean; }'.
|
|
633
|
-
```
|
|
634
|
-
|
|
635
|
-
@example
|
|
636
|
-
```
|
|
637
|
-
// Complains if an option's default type does not conform to the expected type
|
|
638
|
-
|
|
639
|
-
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
640
|
-
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: 'no'};
|
|
641
|
-
type SpecifiedOptions = {};
|
|
642
|
-
|
|
643
|
-
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
644
|
-
// ~~~~~~~~~~~~~~~~~~~
|
|
645
|
-
// Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
|
|
646
|
-
```
|
|
647
|
-
|
|
648
|
-
@example
|
|
649
|
-
```
|
|
650
|
-
// Complains if an option's specified type does not conform to the expected type
|
|
651
|
-
|
|
652
|
-
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
653
|
-
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
|
|
654
|
-
type SpecifiedOptions = {leavesOnly: 'yes'};
|
|
655
|
-
|
|
656
|
-
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
657
|
-
// ~~~~~~~~~~~~~~~~
|
|
658
|
-
// Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
|
|
659
|
-
```
|
|
660
|
-
*/
|
|
661
|
-
type ApplyDefaultOptions<Options extends object, Defaults extends Simplify<Omit<Required<Options>, RequiredKeysOf<Options>> & Partial<Record<RequiredKeysOf<Options>, never>>>, SpecifiedOptions extends Options> = If<IsAny<SpecifiedOptions>, Defaults, If<IsNever<SpecifiedOptions>, Defaults, Simplify<Merge<Defaults, { [Key in keyof SpecifiedOptions as Key extends OptionalKeysOf<Options> ? undefined extends SpecifiedOptions[Key] ? never : Key : Key]: SpecifiedOptions[Key] }> & Required<Options>>>>;
|
|
662
|
-
//#endregion
|
|
663
|
-
//#region ../../node_modules/.pnpm/type-fest@5.4.4/node_modules/type-fest/source/except.d.ts
|
|
664
|
-
/**
|
|
665
|
-
Filter out keys from an object.
|
|
666
|
-
|
|
667
|
-
Returns `never` if `Exclude` is strictly equal to `Key`.
|
|
668
|
-
Returns `never` if `Key` extends `Exclude`.
|
|
669
|
-
Returns `Key` otherwise.
|
|
670
|
-
|
|
671
|
-
@example
|
|
672
|
-
```
|
|
673
|
-
type Filtered = Filter<'foo', 'foo'>;
|
|
674
|
-
//=> never
|
|
675
|
-
```
|
|
676
|
-
|
|
677
|
-
@example
|
|
678
|
-
```
|
|
679
|
-
type Filtered = Filter<'bar', string>;
|
|
680
|
-
//=> never
|
|
681
|
-
```
|
|
682
|
-
|
|
683
|
-
@example
|
|
684
|
-
```
|
|
685
|
-
type Filtered = Filter<'bar', 'foo'>;
|
|
686
|
-
//=> 'bar'
|
|
687
|
-
```
|
|
688
|
-
|
|
689
|
-
@see {Except}
|
|
690
|
-
*/
|
|
691
|
-
type Filter<KeyType, ExcludeType> = IsEqual<KeyType, ExcludeType> extends true ? never : (KeyType extends ExcludeType ? never : KeyType);
|
|
692
|
-
type ExceptOptions = {
|
|
693
|
-
/**
|
|
694
|
-
Disallow assigning non-specified properties.
|
|
695
|
-
Note that any omitted properties in the resulting type will be present in autocomplete as `undefined`.
|
|
696
|
-
@default false
|
|
697
|
-
*/
|
|
698
|
-
requireExactProps?: boolean;
|
|
699
|
-
};
|
|
700
|
-
type DefaultExceptOptions = {
|
|
701
|
-
requireExactProps: false;
|
|
702
|
-
};
|
|
703
|
-
/**
|
|
704
|
-
Create a type from an object type without certain keys.
|
|
705
|
-
|
|
706
|
-
We recommend setting the `requireExactProps` option to `true`.
|
|
707
|
-
|
|
708
|
-
This type is a stricter version of [`Omit`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-5.html#the-omit-helper-type). The `Omit` type does not restrict the omitted keys to be keys present on the given type, while `Except` does. The benefits of a stricter type are avoiding typos and allowing the compiler to pick up on rename refactors automatically.
|
|
709
|
-
|
|
710
|
-
This type was proposed to the TypeScript team, which declined it, saying they prefer that libraries implement stricter versions of the built-in types ([microsoft/TypeScript#30825](https://github.com/microsoft/TypeScript/issues/30825#issuecomment-523668235)).
|
|
711
|
-
|
|
712
|
-
@example
|
|
713
|
-
```
|
|
714
|
-
import type {Except} from 'type-fest';
|
|
715
|
-
|
|
716
|
-
type Foo = {
|
|
717
|
-
a: number;
|
|
718
|
-
b: string;
|
|
719
|
-
};
|
|
720
|
-
|
|
721
|
-
type FooWithoutA = Except<Foo, 'a'>;
|
|
722
|
-
//=> {b: string}
|
|
723
|
-
|
|
724
|
-
// @ts-expect-error
|
|
725
|
-
const fooWithoutA: FooWithoutA = {a: 1, b: '2'};
|
|
726
|
-
// errors: 'a' does not exist in type '{ b: string; }'
|
|
727
|
-
|
|
728
|
-
type FooWithoutB = Except<Foo, 'b', {requireExactProps: true}>;
|
|
729
|
-
//=> {a: number} & Partial<Record<'b', never>>
|
|
730
|
-
|
|
731
|
-
// @ts-expect-error
|
|
732
|
-
const fooWithoutB: FooWithoutB = {a: 1, b: '2'};
|
|
733
|
-
// errors at 'b': Type 'string' is not assignable to type 'undefined'.
|
|
734
|
-
|
|
735
|
-
// The `Omit` utility type doesn't work when omitting specific keys from objects containing index signatures.
|
|
736
|
-
|
|
737
|
-
// Consider the following example:
|
|
738
|
-
|
|
739
|
-
type UserData = {
|
|
740
|
-
[metadata: string]: string;
|
|
741
|
-
email: string;
|
|
742
|
-
name: string;
|
|
743
|
-
role: 'admin' | 'user';
|
|
744
|
-
};
|
|
745
|
-
|
|
746
|
-
// `Omit` clearly doesn't behave as expected in this case:
|
|
747
|
-
type PostPayload = Omit<UserData, 'email'>;
|
|
748
|
-
//=> {[x: string]: string; [x: number]: string}
|
|
749
|
-
|
|
750
|
-
// In situations like this, `Except` works better.
|
|
751
|
-
// It simply removes the `email` key while preserving all the other keys.
|
|
752
|
-
type PostPayloadFixed = Except<UserData, 'email'>;
|
|
753
|
-
//=> {[x: string]: string; name: string; role: 'admin' | 'user'}
|
|
754
|
-
```
|
|
755
|
-
|
|
756
|
-
@category Object
|
|
757
|
-
*/
|
|
758
|
-
type Except<ObjectType, KeysType extends keyof ObjectType, Options extends ExceptOptions = {}> = _Except<ObjectType, KeysType, ApplyDefaultOptions<ExceptOptions, DefaultExceptOptions, Options>>;
|
|
759
|
-
type _Except<ObjectType, KeysType extends keyof ObjectType, Options extends Required<ExceptOptions>> = { [KeyType in keyof ObjectType as Filter<KeyType, KeysType>]: ObjectType[KeyType] } & (Options['requireExactProps'] extends true ? Partial<Record<KeysType, never>> : {});
|
|
760
|
-
//#endregion
|
|
761
|
-
//#region ../../node_modules/.pnpm/type-fest@5.4.4/node_modules/type-fest/source/partial-deep.d.ts
|
|
762
|
-
/**
|
|
763
|
-
@see {@link PartialDeep}
|
|
764
|
-
*/
|
|
765
|
-
type PartialDeepOptions = {
|
|
766
|
-
/**
|
|
767
|
-
Whether to affect the individual elements of arrays and tuples.
|
|
768
|
-
@default false
|
|
769
|
-
*/
|
|
770
|
-
readonly recurseIntoArrays?: boolean;
|
|
771
|
-
/**
|
|
772
|
-
Allows `undefined` values in non-tuple arrays.
|
|
773
|
-
- When set to `true`, elements of non-tuple arrays can be `undefined`.
|
|
774
|
-
- When set to `false`, only explicitly defined elements are allowed in non-tuple arrays, ensuring stricter type checking.
|
|
775
|
-
@default false
|
|
776
|
-
@example
|
|
777
|
-
You can allow `undefined` values in non-tuple arrays by passing `{recurseIntoArrays: true; allowUndefinedInNonTupleArrays: true}` as the second type argument:
|
|
778
|
-
```
|
|
779
|
-
import type {PartialDeep} from 'type-fest';
|
|
780
|
-
type Settings = {
|
|
781
|
-
languages: string[];
|
|
782
|
-
};
|
|
783
|
-
declare const partialSettings: PartialDeep<Settings, {recurseIntoArrays: true; allowUndefinedInNonTupleArrays: true}>;
|
|
784
|
-
partialSettings.languages = [undefined]; // OK
|
|
785
|
-
```
|
|
786
|
-
*/
|
|
787
|
-
readonly allowUndefinedInNonTupleArrays?: boolean;
|
|
788
|
-
};
|
|
789
|
-
type DefaultPartialDeepOptions = {
|
|
790
|
-
recurseIntoArrays: false;
|
|
791
|
-
allowUndefinedInNonTupleArrays: false;
|
|
792
|
-
};
|
|
793
|
-
/**
|
|
794
|
-
Create a type from another type with all keys and nested keys set to optional.
|
|
795
|
-
|
|
796
|
-
Use-cases:
|
|
797
|
-
- Merging a default settings/config object with another object, the second object would be a deep partial of the default object.
|
|
798
|
-
- Mocking and testing complex entities, where populating an entire object with its keys would be redundant in terms of the mock or test.
|
|
799
|
-
|
|
800
|
-
@example
|
|
801
|
-
```
|
|
802
|
-
import type {PartialDeep} from 'type-fest';
|
|
803
|
-
|
|
804
|
-
let settings = {
|
|
805
|
-
textEditor: {
|
|
806
|
-
fontSize: 14,
|
|
807
|
-
fontColor: '#000000',
|
|
808
|
-
fontWeight: 400,
|
|
809
|
-
},
|
|
810
|
-
autocomplete: false,
|
|
811
|
-
autosave: true,
|
|
812
|
-
};
|
|
813
|
-
|
|
814
|
-
const applySavedSettings = (savedSettings: PartialDeep<typeof settings>) => (
|
|
815
|
-
{...settings, ...savedSettings, textEditor: {...settings.textEditor, ...savedSettings.textEditor}}
|
|
816
|
-
);
|
|
817
|
-
|
|
818
|
-
settings = applySavedSettings({textEditor: {fontWeight: 500}});
|
|
819
|
-
```
|
|
820
|
-
|
|
821
|
-
By default, this does not affect elements in array and tuple types. You can change this by passing `{recurseIntoArrays: true}` as the second type argument:
|
|
822
|
-
|
|
823
|
-
```
|
|
824
|
-
import type {PartialDeep} from 'type-fest';
|
|
825
|
-
|
|
826
|
-
type Shape = {
|
|
827
|
-
dimensions: [number, number];
|
|
828
|
-
};
|
|
829
|
-
|
|
830
|
-
const partialShape: PartialDeep<Shape, {recurseIntoArrays: true}> = {
|
|
831
|
-
dimensions: [], // OK
|
|
832
|
-
};
|
|
833
|
-
|
|
834
|
-
partialShape.dimensions = [15]; // OK
|
|
835
|
-
```
|
|
836
|
-
|
|
837
|
-
@see {@link PartialDeepOptions}
|
|
838
|
-
|
|
839
|
-
@category Object
|
|
840
|
-
@category Array
|
|
841
|
-
@category Set
|
|
842
|
-
@category Map
|
|
843
|
-
*/
|
|
844
|
-
type PartialDeep<T, Options extends PartialDeepOptions = {}> = _PartialDeep<T, ApplyDefaultOptions<PartialDeepOptions, DefaultPartialDeepOptions, Options>>;
|
|
845
|
-
type _PartialDeep<T, Options extends Required<PartialDeepOptions>> = T extends BuiltIns | ((new (...arguments_: any[]) => unknown)) ? T : T extends Map<infer KeyType, infer ValueType> ? PartialMapDeep<KeyType, ValueType, Options> : T extends Set<infer ItemType> ? PartialSetDeep<ItemType, Options> : T extends ReadonlyMap<infer KeyType, infer ValueType> ? PartialReadonlyMapDeep<KeyType, ValueType, Options> : T extends ReadonlySet<infer ItemType> ? PartialReadonlySetDeep<ItemType, Options> : T extends ((...arguments_: any[]) => unknown) ? IsNever<keyof T> extends true ? T // For functions with no properties
|
|
846
|
-
: HasMultipleCallSignatures<T> extends true ? T : ((...arguments_: Parameters<T>) => ReturnType<T>) & PartialObjectDeep<T, Options> : T extends object ? T extends ReadonlyArray<infer ItemType> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156
|
|
847
|
-
? Options['recurseIntoArrays'] extends true ? ItemType[] extends T // Test for arrays (non-tuples) specifically
|
|
848
|
-
? readonly ItemType[] extends T // Differentiate readonly and mutable arrays
|
|
849
|
-
? ReadonlyArray<_PartialDeep<Options['allowUndefinedInNonTupleArrays'] extends false ? ItemType : ItemType | undefined, Options>> : Array<_PartialDeep<Options['allowUndefinedInNonTupleArrays'] extends false ? ItemType : ItemType | undefined, Options>> : PartialObjectDeep<T, Options> // Tuples behave properly
|
|
850
|
-
: T // If they don't opt into array testing, just use the original type
|
|
851
|
-
: PartialObjectDeep<T, Options> : unknown;
|
|
852
|
-
/**
|
|
853
|
-
Same as `PartialDeep`, but accepts only `Map`s and as inputs. Internal helper for `PartialDeep`.
|
|
854
|
-
*/
|
|
855
|
-
type PartialMapDeep<KeyType, ValueType, Options extends Required<PartialDeepOptions>> = {} & Map<_PartialDeep<KeyType, Options>, _PartialDeep<ValueType, Options>>;
|
|
856
|
-
/**
|
|
857
|
-
Same as `PartialDeep`, but accepts only `Set`s as inputs. Internal helper for `PartialDeep`.
|
|
858
|
-
*/
|
|
859
|
-
type PartialSetDeep<T, Options extends Required<PartialDeepOptions>> = {} & Set<_PartialDeep<T, Options>>;
|
|
860
|
-
/**
|
|
861
|
-
Same as `PartialDeep`, but accepts only `ReadonlyMap`s as inputs. Internal helper for `PartialDeep`.
|
|
862
|
-
*/
|
|
863
|
-
type PartialReadonlyMapDeep<KeyType, ValueType, Options extends Required<PartialDeepOptions>> = {} & ReadonlyMap<_PartialDeep<KeyType, Options>, _PartialDeep<ValueType, Options>>;
|
|
4
|
+
//#region src/types/internal.d.ts
|
|
864
5
|
/**
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
6
|
+
* Options for serializing cookies.
|
|
7
|
+
*
|
|
8
|
+
* @category Types
|
|
9
|
+
*/
|
|
10
|
+
interface CookieOptions extends SerializeOptions$1 {}
|
|
868
11
|
/**
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
//#region src/types/internal.d.ts
|
|
874
|
-
type CookieOptions = SerializeOptions;
|
|
12
|
+
* Interface for reading cookies from an incoming request.
|
|
13
|
+
*
|
|
14
|
+
* @category Types
|
|
15
|
+
*/
|
|
875
16
|
interface IMonoCloudCookieRequest {
|
|
17
|
+
/**
|
|
18
|
+
* Retrieves a single cookie value by name.
|
|
19
|
+
*
|
|
20
|
+
* @param name - The name of the cookie to retrieve.
|
|
21
|
+
*/
|
|
876
22
|
getCookie(name: string): Promise<string | undefined>;
|
|
23
|
+
/** Retrieves all cookies from the request. */
|
|
877
24
|
getAllCookies(): Promise<Map<string, string>>;
|
|
878
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Represents a request object that includes cookie handling capabilities.
|
|
28
|
+
*
|
|
29
|
+
* @category Types
|
|
30
|
+
*/
|
|
879
31
|
interface MonoCloudRequest extends IMonoCloudCookieRequest {
|
|
32
|
+
/**
|
|
33
|
+
* Retrieves a query parameter value by name.
|
|
34
|
+
*
|
|
35
|
+
* @param parameter - The name of the query parameter to retrieve.
|
|
36
|
+
*/
|
|
880
37
|
getQuery(parameter: string): string | string[] | undefined;
|
|
38
|
+
/** Returns the raw request details including method, URL, and body. */
|
|
881
39
|
getRawRequest(): Promise<{
|
|
882
40
|
method: string;
|
|
883
41
|
url: string;
|
|
884
42
|
body: Record<string, string> | string;
|
|
885
43
|
}>;
|
|
886
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Interface for setting cookies on an outgoing response.
|
|
47
|
+
*
|
|
48
|
+
* @category Types
|
|
49
|
+
*/
|
|
887
50
|
interface IMonoCloudCookieResponse {
|
|
51
|
+
/**
|
|
52
|
+
* Sets a cookie on the response.
|
|
53
|
+
*
|
|
54
|
+
* @param cookieName - The name of the cookie to set.
|
|
55
|
+
* @param value - The value to assign to the cookie.
|
|
56
|
+
* @param options - Serialization options for the cookie.
|
|
57
|
+
*/
|
|
888
58
|
setCookie(cookieName: string, value: string, options: CookieOptions): Promise<void>;
|
|
889
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Represents an outgoing HTTP response with common helper methods.
|
|
62
|
+
*
|
|
63
|
+
* @category Types
|
|
64
|
+
*/
|
|
890
65
|
interface MonoCloudResponse extends IMonoCloudCookieResponse {
|
|
66
|
+
/**
|
|
67
|
+
* Redirects the client to the specified URL.
|
|
68
|
+
*
|
|
69
|
+
* @param url - The URL to redirect to.
|
|
70
|
+
* @param statusCode - The HTTP status code to use for the redirect.
|
|
71
|
+
*/
|
|
891
72
|
redirect(url: string, statusCode?: number): void;
|
|
73
|
+
/**
|
|
74
|
+
* Sends a JSON response with an optional status code.
|
|
75
|
+
*
|
|
76
|
+
* @param data - The data to serialize and send as JSON.
|
|
77
|
+
* @param statusCode - The HTTP status code for the response.
|
|
78
|
+
*/
|
|
892
79
|
sendJson(data: any, statusCode?: number): void;
|
|
80
|
+
/** Sends a 404 Not Found response. */
|
|
893
81
|
notFound(): void;
|
|
82
|
+
/** Sends a 204 No Content response. */
|
|
894
83
|
noContent(): void;
|
|
84
|
+
/** Sends a 500 Internal Server Error response. */
|
|
895
85
|
internalServerError(): void;
|
|
86
|
+
/** Sends a 405 Method Not Allowed response. */
|
|
896
87
|
methodNotAllowed(): void;
|
|
88
|
+
/** Sets cache-control headers to prevent caching. */
|
|
897
89
|
setNoCache(): void;
|
|
90
|
+
/** Finalizes and returns the response. */
|
|
898
91
|
done(): any;
|
|
899
92
|
}
|
|
900
93
|
//#endregion
|
|
901
94
|
//#region src/types/index.d.ts
|
|
902
95
|
/**
|
|
903
|
-
*
|
|
96
|
+
* Allowed values for the cookie `SameSite` attribute.
|
|
97
|
+
*
|
|
98
|
+
* The `SameSite` setting controls when cookies are included in cross-site requests and helps protect against cross-site request forgery (CSRF) attacks.
|
|
99
|
+
*
|
|
100
|
+
* @category Types (Enums)
|
|
101
|
+
*/
|
|
102
|
+
type SameSiteValues =
|
|
103
|
+
/**
|
|
104
|
+
* Cookies are only sent for same-site requests.
|
|
105
|
+
*
|
|
106
|
+
* Cookies will NOT be included in cross-site navigations, redirects, or embedded requests.
|
|
107
|
+
*
|
|
108
|
+
* Provides the strongest CSRF protection but may break authentication flows that rely on cross-site redirects.
|
|
904
109
|
*/
|
|
905
|
-
|
|
110
|
+
'strict'
|
|
906
111
|
/**
|
|
907
|
-
*
|
|
112
|
+
* Cookies are sent for same-site requests and top-level cross-site navigations (for example, following a link).
|
|
113
|
+
*
|
|
114
|
+
* This is the recommended default for most authentication flows.
|
|
115
|
+
*/
|
|
116
|
+
| 'lax'
|
|
117
|
+
/**
|
|
118
|
+
* Cookies are sent with all requests, including cross-site requests.
|
|
119
|
+
*
|
|
120
|
+
* Must be used together with `Secure=true` (HTTPS only).
|
|
121
|
+
*
|
|
122
|
+
* Required for some third-party or cross-origin authentication scenarios.
|
|
908
123
|
*/
|
|
909
|
-
|
|
124
|
+
| 'none';
|
|
910
125
|
/**
|
|
911
|
-
* Represents the lifetime
|
|
912
|
-
*
|
|
126
|
+
* Represents the lifetime metadata associated with a user session.
|
|
127
|
+
*
|
|
128
|
+
* The properties use short keys to minimize cookie and storage size, since this structure may be serialized as part of session data.
|
|
129
|
+
*
|
|
130
|
+
* All timestamps are expressed as **Unix epoch time (seconds)**.
|
|
131
|
+
*
|
|
132
|
+
* @category Types
|
|
913
133
|
*/
|
|
914
134
|
interface SessionLifetime {
|
|
915
135
|
/**
|
|
916
|
-
*
|
|
136
|
+
* Session creation time.
|
|
137
|
+
*
|
|
138
|
+
* The moment the session was initially established.
|
|
917
139
|
*/
|
|
918
140
|
c: number;
|
|
919
141
|
/**
|
|
920
|
-
*
|
|
142
|
+
* Last updated time.
|
|
143
|
+
*
|
|
144
|
+
* Updated whenever the session is refreshed or extended (for example, during sliding expiration).
|
|
921
145
|
*/
|
|
922
146
|
u: number;
|
|
923
147
|
/**
|
|
924
|
-
* Optional
|
|
148
|
+
* Optional expiration time.
|
|
925
149
|
*/
|
|
926
150
|
e?: number;
|
|
927
151
|
}
|
|
928
152
|
/**
|
|
929
|
-
*
|
|
153
|
+
* Defines a storage adapter used to persist authentication sessions.
|
|
154
|
+
*
|
|
155
|
+
* Implement this interface to store sessions outside the default cookie-based storage — for example in Redis, a database, or a distributed cache.
|
|
156
|
+
*
|
|
157
|
+
* @category Types
|
|
930
158
|
*/
|
|
931
159
|
interface MonoCloudSessionStore {
|
|
932
160
|
/**
|
|
933
|
-
* Retrieves a session
|
|
934
|
-
*
|
|
935
|
-
* @
|
|
161
|
+
* Retrieves a session associated with the provided key.
|
|
162
|
+
*
|
|
163
|
+
* @param key Unique identifier of the session.
|
|
164
|
+
* @returns Returns the stored session, or `undefined` / `null` if no session exists.
|
|
936
165
|
*/
|
|
937
166
|
get(key: string): Promise<MonoCloudSession$1 | undefined | null>;
|
|
938
167
|
/**
|
|
939
|
-
*
|
|
940
|
-
*
|
|
941
|
-
*
|
|
942
|
-
*
|
|
943
|
-
* @
|
|
168
|
+
* Persists or updates a session.
|
|
169
|
+
*
|
|
170
|
+
* The provided lifetime information can be used by the store to configure TTL/expiration policies.
|
|
171
|
+
*
|
|
172
|
+
* @param key Unique identifier of the session.
|
|
173
|
+
* @param data The session data to persist.
|
|
174
|
+
* @param lifetime Session lifetime metadata (creation, update, expiration).
|
|
944
175
|
*/
|
|
945
176
|
set(key: string, data: MonoCloudSession$1, lifetime: SessionLifetime): Promise<void>;
|
|
946
177
|
/**
|
|
947
|
-
*
|
|
948
|
-
*
|
|
949
|
-
* @
|
|
178
|
+
* Removes a session from the store.
|
|
179
|
+
*
|
|
180
|
+
* @param key Unique identifier of the session to delete.
|
|
950
181
|
*/
|
|
951
182
|
delete(key: string): Promise<void>;
|
|
952
183
|
}
|
|
953
184
|
/**
|
|
954
|
-
*
|
|
185
|
+
* Configuration options for authentication cookies.
|
|
186
|
+
*
|
|
187
|
+
* These settings control how MonoCloud session and state cookies are created, scoped, and transmitted by the browser.
|
|
188
|
+
*
|
|
189
|
+
* @category Types
|
|
955
190
|
*/
|
|
956
191
|
interface MonoCloudCookieOptions {
|
|
957
192
|
/**
|
|
958
|
-
* The name
|
|
959
|
-
* For session cookies, the default value is 'session'.
|
|
960
|
-
* For state cookies, the default value is 'state'.
|
|
193
|
+
* The cookie name. Defaults to `"session"` for session cookies and `"state"` for state cookies.
|
|
961
194
|
*/
|
|
962
195
|
name: string;
|
|
963
196
|
/**
|
|
964
|
-
* The path for which the cookie is valid.
|
|
197
|
+
* The URL path for which the cookie is valid.
|
|
198
|
+
*
|
|
965
199
|
* @defaultValue '/'
|
|
966
200
|
*/
|
|
967
201
|
path: string;
|
|
968
202
|
/**
|
|
969
|
-
* Optional
|
|
203
|
+
* Optional domain scope for the cookie.
|
|
970
204
|
*/
|
|
971
205
|
domain?: string;
|
|
972
206
|
/**
|
|
973
|
-
*
|
|
974
|
-
*
|
|
207
|
+
* Indicates whether the cookie is accessible only via HTTP requests. Helps mitigate XSS attacks by preventing client-side JavaScript access.
|
|
208
|
+
*
|
|
209
|
+
* Always enforced as `true` for state cookies.
|
|
210
|
+
*
|
|
975
211
|
* @defaultValue true
|
|
976
212
|
*/
|
|
977
213
|
httpOnly: boolean;
|
|
978
214
|
/**
|
|
979
|
-
*
|
|
980
|
-
*
|
|
215
|
+
* Indicates whether the cookie should only be transmitted over HTTPS.
|
|
216
|
+
*
|
|
217
|
+
* If not explicitly provided, this value is automatically inferred from the application URL scheme.
|
|
981
218
|
*/
|
|
982
219
|
secure: boolean;
|
|
983
220
|
/**
|
|
984
|
-
* The SameSite
|
|
221
|
+
* The SameSite policy applied to the cookie. Controls cross-site request behavior and CSRF protection.
|
|
222
|
+
*
|
|
985
223
|
* @defaultValue 'lax'
|
|
986
224
|
*/
|
|
987
225
|
sameSite: SameSiteValues;
|
|
988
226
|
/**
|
|
989
|
-
* Determines whether the cookie
|
|
990
|
-
*
|
|
991
|
-
* For state cookies, the default value is false.
|
|
227
|
+
* Determines whether the cookie persists across browser restarts.
|
|
228
|
+
* Defaults to `true` for session cookies and `false` for state cookies.
|
|
992
229
|
*/
|
|
993
230
|
persistent: boolean;
|
|
994
231
|
}
|
|
995
232
|
/**
|
|
996
|
-
*
|
|
233
|
+
* Configuration options for authentication sessions.
|
|
234
|
+
*
|
|
235
|
+
* These options control how user sessions are created, persisted, and expired.
|
|
236
|
+
*
|
|
237
|
+
* @category Types
|
|
997
238
|
*/
|
|
998
239
|
interface MonoCloudSessionOptionsBase {
|
|
999
240
|
/**
|
|
1000
|
-
* Configuration
|
|
241
|
+
* Configuration for the session cookie used to identify the user session.
|
|
1001
242
|
*/
|
|
1002
243
|
cookie: MonoCloudCookieOptions;
|
|
1003
244
|
/**
|
|
1004
|
-
*
|
|
245
|
+
* Enables sliding session expiration.
|
|
246
|
+
*
|
|
247
|
+
* When enabled, the session expiration is extended on active requests, up to the configured `maximumDuration`.
|
|
248
|
+
*
|
|
249
|
+
* When disabled, the session expires after a fixed duration regardless of user activity.
|
|
250
|
+
*
|
|
1005
251
|
* @defaultValue false
|
|
1006
252
|
*/
|
|
1007
253
|
sliding: boolean;
|
|
1008
254
|
/**
|
|
1009
|
-
* The
|
|
255
|
+
* The session lifetime in seconds.
|
|
256
|
+
*
|
|
257
|
+
* With **absolute sessions** (`sliding = false`), this defines the total session lifetime.
|
|
258
|
+
* With **sliding sessions**, this defines the idle timeout before the session expires.
|
|
259
|
+
*
|
|
1010
260
|
* @defaultValue 86400 (1 Day)
|
|
1011
261
|
*/
|
|
1012
262
|
duration: number;
|
|
1013
263
|
/**
|
|
1014
|
-
* The maximum
|
|
1015
|
-
*
|
|
1016
|
-
*
|
|
264
|
+
* The absolute maximum lifetime of a sliding session in seconds.
|
|
265
|
+
*
|
|
266
|
+
* This value limits how long a session can exist even if the user remains continuously active.
|
|
267
|
+
*
|
|
268
|
+
* Only applies when `sliding` is enabled.
|
|
269
|
+
*
|
|
270
|
+
* @defaultValue 604800 (7 days)
|
|
1017
271
|
*/
|
|
1018
272
|
maximumDuration: number;
|
|
1019
273
|
/**
|
|
1020
|
-
* Optional
|
|
274
|
+
* Optional session store used to persist session data.
|
|
275
|
+
*
|
|
276
|
+
* If not provided, The SDK uses the default cookie-based session storage.
|
|
277
|
+
*
|
|
278
|
+
* Custom stores allow centralized session management (e.g. Redis, database).
|
|
1021
279
|
*/
|
|
1022
280
|
store?: MonoCloudSessionStore;
|
|
1023
281
|
}
|
|
1024
282
|
/**
|
|
1025
|
-
*
|
|
283
|
+
* Partial configuration options for authentication state handling.
|
|
284
|
+
*
|
|
285
|
+
* @category Types
|
|
286
|
+
*/
|
|
287
|
+
interface MonoCloudStatePartialOptions {
|
|
288
|
+
/**
|
|
289
|
+
* Partial configuration for the state cookie.
|
|
290
|
+
*
|
|
291
|
+
* This cookie temporarily stores authorization transaction data required to validate the callback response and prevent replay or CSRF attacks.
|
|
292
|
+
*/
|
|
293
|
+
cookie?: Partial<MonoCloudCookieOptions>;
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Configuration options for authentication state handling.
|
|
297
|
+
*
|
|
298
|
+
* @category Types
|
|
1026
299
|
*/
|
|
1027
300
|
interface MonoCloudStateOptions {
|
|
1028
301
|
/**
|
|
1029
|
-
* Configuration
|
|
302
|
+
* Configuration for the state cookie.
|
|
303
|
+
*
|
|
304
|
+
* This cookie temporarily stores authorization transaction data required to validate the callback response and prevent replay or CSRF attacks.
|
|
1030
305
|
*/
|
|
1031
306
|
cookie: MonoCloudCookieOptions;
|
|
1032
307
|
}
|
|
1033
308
|
/**
|
|
1034
|
-
*
|
|
309
|
+
* Route configuration for MonoCloud authentication handlers.
|
|
310
|
+
*
|
|
311
|
+
* These routes define the internal application endpoints used by the SDK to process authentication flows such as sign-in, callback handling, sign-out, and user profile retrieval.
|
|
312
|
+
*
|
|
313
|
+
* You typically do not need to change these values unless you want to customize your application's authentication URLs.
|
|
314
|
+
*
|
|
315
|
+
* > When customizing routes, ensure the corresponding URLs are also configured in your MonoCloud Dashboard and exposed to the client using the matching environment variables.
|
|
316
|
+
*
|
|
317
|
+
* @category Types
|
|
1035
318
|
*/
|
|
1036
319
|
interface MonoCloudRoutes {
|
|
1037
320
|
/**
|
|
1038
|
-
*
|
|
321
|
+
* Route that receives the authorization callback from MonoCloud after a successful authentication.
|
|
322
|
+
*
|
|
1039
323
|
* @defaultValue '/api/auth/callback'
|
|
1040
324
|
*/
|
|
1041
325
|
callback: string;
|
|
1042
326
|
/**
|
|
1043
|
-
*
|
|
327
|
+
* Route that handles OpenID Connect back-channel logout requests initiated by MonoCloud.
|
|
328
|
+
*
|
|
1044
329
|
* @defaultValue '/api/auth/backchannel-logout'
|
|
1045
330
|
*/
|
|
1046
331
|
backChannelLogout: string;
|
|
1047
332
|
/**
|
|
1048
|
-
*
|
|
333
|
+
* Route used to initiate the sign-in flow.
|
|
334
|
+
*
|
|
1049
335
|
* @defaultValue '/api/auth/signin'
|
|
1050
336
|
*/
|
|
1051
337
|
signIn: string;
|
|
1052
338
|
/**
|
|
1053
|
-
*
|
|
339
|
+
* Route used to initiate the sign-out flow.
|
|
340
|
+
*
|
|
1054
341
|
* @defaultValue '/api/auth/signout'
|
|
1055
342
|
*/
|
|
1056
343
|
signOut: string;
|
|
1057
344
|
/**
|
|
1058
|
-
*
|
|
345
|
+
* Route that exposes the authenticated user's profile information.
|
|
346
|
+
*
|
|
1059
347
|
* @defaultValue '/api/auth/userinfo'
|
|
1060
348
|
*/
|
|
1061
349
|
userInfo: string;
|
|
1062
350
|
}
|
|
1063
351
|
/**
|
|
1064
|
-
* Represents an
|
|
352
|
+
* Represents an additional resource indicator that can be requested during token acquisition.
|
|
353
|
+
*
|
|
354
|
+
* Resource indicators allow an access token to be scoped to a specific API or service (audience). Multiple indicators may be provided when requesting tokens for different protected resources.
|
|
355
|
+
*
|
|
356
|
+
* @category Types
|
|
1065
357
|
*/
|
|
1066
358
|
interface Indicator {
|
|
1067
359
|
/**
|
|
1068
|
-
* Space
|
|
360
|
+
* Space-separated list of resource identifiers (audiences) that the access token should be issued for.
|
|
361
|
+
*
|
|
362
|
+
* Each value typically represents an API identifier or resource URI.
|
|
1069
363
|
*/
|
|
1070
364
|
resource: string;
|
|
1071
365
|
/**
|
|
1072
|
-
* Optional
|
|
366
|
+
* Optional. Space-separated list of scopes to request specifically for this resource.
|
|
1073
367
|
*/
|
|
1074
368
|
scopes?: string;
|
|
1075
369
|
}
|
|
1076
370
|
/**
|
|
1077
|
-
*
|
|
371
|
+
* Core configuration options for the SDK.
|
|
372
|
+
*
|
|
373
|
+
* These options define how the SDK communicates with your MonoCloud tenant, manages sessions, and performs authentication flows.
|
|
374
|
+
*
|
|
375
|
+
* @category Types
|
|
1078
376
|
*/
|
|
1079
377
|
interface MonoCloudOptionsBase {
|
|
1080
378
|
/**
|
|
1081
|
-
*
|
|
379
|
+
* Client identifier of the application registered in MonoCloud.
|
|
1082
380
|
*/
|
|
1083
381
|
clientId: string;
|
|
1084
382
|
/**
|
|
1085
|
-
* Optional
|
|
383
|
+
* Optional client secret used for confidential clients.
|
|
1086
384
|
*/
|
|
1087
385
|
clientSecret?: string;
|
|
1088
386
|
/**
|
|
1089
|
-
* MonoCloud tenant domain.
|
|
387
|
+
* MonoCloud tenant domain (for example, `https://your-tenant.us.monocloud.com`).
|
|
1090
388
|
*/
|
|
1091
389
|
tenantDomain: string;
|
|
1092
390
|
/**
|
|
1093
|
-
*
|
|
391
|
+
* Secret used to encrypt and sign authentication cookies. This value should be long, random, and kept private.
|
|
1094
392
|
*/
|
|
1095
393
|
cookieSecret: string;
|
|
1096
394
|
/**
|
|
1097
|
-
*
|
|
395
|
+
* Base URL where the application is hosted.
|
|
396
|
+
*
|
|
397
|
+
* Used to construct redirect URLs and validate requests.
|
|
1098
398
|
*/
|
|
1099
399
|
appUrl: string;
|
|
1100
400
|
/**
|
|
1101
|
-
*
|
|
401
|
+
* Route paths used by MonoCloud authentication handlers.
|
|
1102
402
|
*/
|
|
1103
403
|
routes: MonoCloudRoutes;
|
|
1104
404
|
/**
|
|
1105
|
-
*
|
|
405
|
+
* Allowed clock skew (in seconds) when validating token timestamps.
|
|
406
|
+
*
|
|
1106
407
|
* @defaultValue 60 (seconds)
|
|
1107
408
|
*/
|
|
1108
409
|
clockSkew: number;
|
|
1109
410
|
/**
|
|
1110
|
-
*
|
|
411
|
+
* Maximum time (in milliseconds) to wait for responses from the MonoCloud authorization server.
|
|
412
|
+
*
|
|
1111
413
|
* @defaultValue 10000 (10 seconds)
|
|
1112
414
|
*/
|
|
1113
415
|
responseTimeout: number;
|
|
1114
416
|
/**
|
|
1115
|
-
*
|
|
417
|
+
* Enables Pushed Authorization Requests (PAR).
|
|
418
|
+
*
|
|
419
|
+
* When enabled, authorization parameters are sent securely via the PAR endpoint instead of the browser.
|
|
420
|
+
*
|
|
1116
421
|
* @defaultValue false
|
|
1117
422
|
*/
|
|
1118
423
|
usePar: boolean;
|
|
1119
424
|
/**
|
|
1120
|
-
*
|
|
425
|
+
* URL to redirect users to after logout completes.
|
|
1121
426
|
*/
|
|
1122
427
|
postLogoutRedirectUri?: string;
|
|
1123
428
|
/**
|
|
1124
|
-
*
|
|
429
|
+
* When `true`, signing out also logs the user out of MonoCloud (Single Sign-Out).
|
|
430
|
+
*
|
|
1125
431
|
* @defaultValue true
|
|
1126
432
|
*/
|
|
1127
433
|
federatedSignOut: boolean;
|
|
1128
434
|
/**
|
|
1129
|
-
*
|
|
435
|
+
* Fetch user profile data from the `UserInfo` endpoint after authentication completes.
|
|
436
|
+
*
|
|
1130
437
|
* @defaultValue true
|
|
1131
438
|
*/
|
|
1132
439
|
userInfo: boolean;
|
|
1133
440
|
/**
|
|
1134
|
-
*
|
|
1135
|
-
*
|
|
441
|
+
* Refetch user profile data whenever the application's `UserInfo` endpoint is invoked.
|
|
442
|
+
*
|
|
1136
443
|
* @defaultValue false
|
|
1137
444
|
*/
|
|
1138
445
|
refetchUserInfo: boolean;
|
|
1139
446
|
/**
|
|
1140
|
-
* Default authorization parameters
|
|
447
|
+
* Default authorization parameters included in authentication requests.
|
|
448
|
+
*
|
|
1141
449
|
* @defaultValue {
|
|
1142
450
|
* scope: 'openid email profile',
|
|
1143
451
|
* response_type: 'code'
|
|
@@ -1145,281 +453,408 @@ interface MonoCloudOptionsBase {
|
|
|
1145
453
|
*/
|
|
1146
454
|
defaultAuthParams: AuthorizationParams$1;
|
|
1147
455
|
/**
|
|
1148
|
-
* Optional
|
|
456
|
+
* Optional resource indicators available when requesting tokens via `getTokens()`.
|
|
1149
457
|
*
|
|
1150
458
|
*/
|
|
1151
459
|
resources?: Indicator[];
|
|
1152
460
|
/**
|
|
1153
|
-
*
|
|
461
|
+
* Session configuration.
|
|
1154
462
|
*/
|
|
1155
463
|
session: MonoCloudSessionOptionsBase;
|
|
1156
464
|
/**
|
|
1157
|
-
*
|
|
465
|
+
* Authentication state configuration.
|
|
1158
466
|
*/
|
|
1159
467
|
state: MonoCloudStateOptions;
|
|
1160
468
|
/**
|
|
1161
|
-
*
|
|
469
|
+
* Expected signing algorithm for ID tokens.
|
|
470
|
+
*
|
|
1162
471
|
* @defaultValue 'RS256'
|
|
1163
472
|
*/
|
|
1164
|
-
idTokenSigningAlg: SecurityAlgorithms;
|
|
473
|
+
idTokenSigningAlg: SecurityAlgorithms$1;
|
|
1165
474
|
/**
|
|
1166
|
-
*
|
|
475
|
+
* List of ID token claims that should be removed before storing data in the session.
|
|
1167
476
|
*/
|
|
1168
477
|
filteredIdTokenClaims: string[];
|
|
1169
478
|
/**
|
|
1170
|
-
*
|
|
479
|
+
* Identifier used for internal debugging/logging.
|
|
1171
480
|
*/
|
|
1172
481
|
debugger: string;
|
|
1173
482
|
/**
|
|
1174
|
-
*
|
|
483
|
+
* Custom User-Agent value sent with requests to MonoCloud.
|
|
1175
484
|
*/
|
|
1176
485
|
userAgent: string;
|
|
1177
486
|
/**
|
|
1178
|
-
*
|
|
1179
|
-
*
|
|
1180
|
-
* Time in seconds to cache the JWKS document after it is fetched
|
|
487
|
+
* Duration (in seconds) to cache the JWKS document.
|
|
1181
488
|
*
|
|
1182
|
-
* @
|
|
1183
|
-
|
|
1184
|
-
* */
|
|
489
|
+
* @defaultValue 300
|
|
490
|
+
*/
|
|
1185
491
|
jwksCacheDuration?: number;
|
|
1186
492
|
/**
|
|
1187
|
-
*
|
|
1188
|
-
*
|
|
1189
|
-
* Time in seconds to cache the metadata document after it is fetched.
|
|
493
|
+
* Duration (in seconds) to cache OpenID discovery metadata.
|
|
1190
494
|
*
|
|
1191
|
-
* @
|
|
1192
|
-
|
|
495
|
+
* @defaultValue 300
|
|
496
|
+
*/
|
|
1193
497
|
metadataCacheDuration?: number;
|
|
1194
498
|
/**
|
|
1195
|
-
*
|
|
1196
|
-
* from query.
|
|
1197
|
-
*
|
|
1198
|
-
* When set to `true`, parameters such as `scope`, `resource`, `prompt` etc
|
|
1199
|
-
* from the query parameters will be merged into the authentication request.
|
|
1200
|
-
*
|
|
1201
|
-
* @example
|
|
499
|
+
* Allows authorization parameters to be overridden using query parameters.
|
|
1202
500
|
*
|
|
1203
|
-
*
|
|
1204
|
-
* https://example.com/api/auth/signin?prompt=login&login_hint=user@example.com
|
|
501
|
+
* When disabled, parameters such as `scope`, `resource`, `prompt`, and `login_hint` present in the request URL are ignored and cannot modify the authentication request.
|
|
1205
502
|
*
|
|
1206
|
-
* @
|
|
503
|
+
* @defaultValue false
|
|
1207
504
|
*/
|
|
1208
505
|
allowQueryParamOverrides?: boolean;
|
|
1209
506
|
/**
|
|
1210
|
-
*
|
|
507
|
+
* Invoked when a back-channel logout request is received.
|
|
1211
508
|
*/
|
|
1212
509
|
onBackChannelLogout?: OnBackChannelLogout;
|
|
1213
510
|
/**
|
|
1214
|
-
*
|
|
511
|
+
* Invoked before authentication begins to attach custom application state.
|
|
1215
512
|
*/
|
|
1216
513
|
onSetApplicationState?: OnSetApplicationState;
|
|
1217
514
|
/**
|
|
1218
|
-
*
|
|
515
|
+
* Invoked before a session is created or updated. Can be used to modify session data or attach custom fields.
|
|
1219
516
|
*/
|
|
1220
517
|
onSessionCreating?: OnSessionCreating;
|
|
1221
518
|
}
|
|
1222
519
|
/**
|
|
1223
|
-
*
|
|
520
|
+
* Partial configuration options for authentication sessions.
|
|
521
|
+
*
|
|
522
|
+
* @category Types
|
|
1224
523
|
*/
|
|
1225
|
-
|
|
524
|
+
interface MonoCloudSessionOptions extends Partial<Omit<MonoCloudSessionOptionsBase, 'store' | 'cookie'>> {
|
|
525
|
+
/**
|
|
526
|
+
* Session cookie settings.
|
|
527
|
+
*/
|
|
528
|
+
cookie?: Partial<MonoCloudCookieOptions>;
|
|
1226
529
|
/**
|
|
1227
|
-
*
|
|
530
|
+
* A custom session store implementation.
|
|
531
|
+
*
|
|
532
|
+
* When provided, sessions are persisted using this store instead of cookies-only storage.
|
|
1228
533
|
*/
|
|
1229
534
|
store?: MonoCloudSessionStore;
|
|
1230
|
-
}
|
|
535
|
+
}
|
|
1231
536
|
/**
|
|
1232
|
-
*
|
|
537
|
+
* Configuration options used to initialize the SDK client.
|
|
538
|
+
*
|
|
539
|
+
* ## Configuration Sources
|
|
540
|
+
*
|
|
541
|
+
* Configuration values can be provided using either:
|
|
542
|
+
*
|
|
543
|
+
* - **Constructor options** - passed when creating the client instance.
|
|
544
|
+
* - **Environment variables** - using `MONOCLOUD_AUTH_*` variables.
|
|
545
|
+
*
|
|
546
|
+
* When both are provided, **constructor options override environment variables**.
|
|
547
|
+
*
|
|
548
|
+
* ## Environment Variables
|
|
549
|
+
*
|
|
550
|
+
* ### Core Configuration (Required)
|
|
551
|
+
*
|
|
552
|
+
* | Environment Variable | Description |
|
|
553
|
+
* |----------------------|-------------|
|
|
554
|
+
* | `MONOCLOUD_AUTH_CLIENT_ID` | Unique identifier for your application/client. |
|
|
555
|
+
* | `MONOCLOUD_AUTH_CLIENT_SECRET` | Application/client secret used for authentication. |
|
|
556
|
+
* | `MONOCLOUD_AUTH_TENANT_DOMAIN` | The domain of your MonoCloud tenant (for example, `https://your-tenant.us.monocloud.com`). |
|
|
557
|
+
* | `MONOCLOUD_AUTH_APP_URL` | The base URL where your application is hosted. |
|
|
558
|
+
* | `MONOCLOUD_AUTH_COOKIE_SECRET` | A long, random string used to encrypt and sign session cookies. |
|
|
559
|
+
*
|
|
560
|
+
* ### Authentication & Security
|
|
561
|
+
*
|
|
562
|
+
* | Environment Variable | Description |
|
|
563
|
+
* |----------------------|-------------|
|
|
564
|
+
* | `MONOCLOUD_AUTH_SCOPES` | Space-separated list of OIDC scopes to request (for example, `openid profile email`). |
|
|
565
|
+
* | `MONOCLOUD_AUTH_RESOURCE` | Default resource (audience) identifier used when issuing access tokens. |
|
|
566
|
+
* | `MONOCLOUD_AUTH_USE_PAR` | Enables Pushed Authorization Requests (PAR) for authorization flows. |
|
|
567
|
+
* | `MONOCLOUD_AUTH_CLOCK_SKEW` | Allowed clock drift (in seconds) when validating token timestamps. |
|
|
568
|
+
* | `MONOCLOUD_AUTH_FEDERATED_SIGNOUT` | If `true`, signing out of the application also signs the user out of MonoCloud (SSO sign-out). |
|
|
569
|
+
* | `MONOCLOUD_AUTH_RESPONSE_TIMEOUT` | Maximum time (in milliseconds) to wait for responses from the authentication service. |
|
|
570
|
+
* | `MONOCLOUD_AUTH_ALLOW_QUERY_PARAM_OVERRIDES` | Allows authorization parameters (such as `scope`, `resource`, or `prompt`) to be overridden via URL query parameters. |
|
|
571
|
+
* | `MONOCLOUD_AUTH_POST_LOGOUT_REDIRECT_URI` | URL users are redirected to after a successful logout. |
|
|
572
|
+
* | `MONOCLOUD_AUTH_USER_INFO` | Determines whether user profile data is fetched from the `UserInfo` endpoint after authorization. |
|
|
573
|
+
* | `MONOCLOUD_AUTH_REFETCH_USER_INFO` | If `true`, user information is re-fetched on each userinfo request. |
|
|
574
|
+
* | `MONOCLOUD_AUTH_ID_TOKEN_SIGNING_ALG` | Expected signing algorithm for ID tokens (for example, `RS256`). |
|
|
575
|
+
* | `MONOCLOUD_AUTH_FILTERED_ID_TOKEN_CLAIMS` | Space-separated list of ID token claims excluded from the session object. |
|
|
576
|
+
*
|
|
577
|
+
* ### Routes
|
|
578
|
+
*
|
|
579
|
+
* | Environment Variable | Description |
|
|
580
|
+
* |----------------------|-------------|
|
|
581
|
+
* | `MONOCLOUD_AUTH_CALLBACK_URL` | Application path where the authorization server redirects the user after authentication. |
|
|
582
|
+
* | `MONOCLOUD_AUTH_SIGNIN_URL` | Internal route used to initiate the sign-in flow. |
|
|
583
|
+
* | `MONOCLOUD_AUTH_SIGNOUT_URL` | Internal route used to initiate the sign-out flow. |
|
|
584
|
+
* | `MONOCLOUD_AUTH_USER_INFO_URL` | Route that exposes the authenticated user’s profile retrieved from the UserInfo endpoint. |
|
|
585
|
+
*
|
|
586
|
+
* ### Session Cookie Settings
|
|
587
|
+
*
|
|
588
|
+
* | Environment Variable | Description |
|
|
589
|
+
* |----------------------|-------------|
|
|
590
|
+
* | `MONOCLOUD_AUTH_SESSION_COOKIE_NAME` | Name of the cookie used to store the authenticated user session. |
|
|
591
|
+
* | `MONOCLOUD_AUTH_SESSION_COOKIE_PATH` | Path scope for which the session cookie is valid. |
|
|
592
|
+
* | `MONOCLOUD_AUTH_SESSION_COOKIE_DOMAIN` | Domain scope for which the session cookie is valid. |
|
|
593
|
+
* | `MONOCLOUD_AUTH_SESSION_COOKIE_HTTP_ONLY` | Prevents client-side scripts from accessing the session cookie. |
|
|
594
|
+
* | `MONOCLOUD_AUTH_SESSION_COOKIE_SECURE` | Ensures the session cookie is only sent over HTTPS connections. |
|
|
595
|
+
* | `MONOCLOUD_AUTH_SESSION_COOKIE_SAME_SITE` | SameSite policy applied to the session cookie (`lax`, `strict`, or `none`). |
|
|
596
|
+
* | `MONOCLOUD_AUTH_SESSION_COOKIE_PERSISTENT` | Determines whether the session cookie persists across browser restarts. |
|
|
597
|
+
* | `MONOCLOUD_AUTH_SESSION_SLIDING` | Enables sliding session expiration instead of absolute expiration. |
|
|
598
|
+
* | `MONOCLOUD_AUTH_SESSION_DURATION` | Session lifetime in seconds. |
|
|
599
|
+
* | `MONOCLOUD_AUTH_SESSION_MAX_DURATION` | Maximum allowed lifetime of a sliding session in seconds. |
|
|
600
|
+
*
|
|
601
|
+
* ### State Cookie Settings
|
|
602
|
+
*
|
|
603
|
+
* | Environment Variable | Description |
|
|
604
|
+
* |----------------------|-------------|
|
|
605
|
+
* | `MONOCLOUD_AUTH_STATE_COOKIE_NAME` | Name of the cookie used to store OpenID Connect state and nonce values during authentication. |
|
|
606
|
+
* | `MONOCLOUD_AUTH_STATE_COOKIE_PATH` | Path scope for which the state cookie is valid. |
|
|
607
|
+
* | `MONOCLOUD_AUTH_STATE_COOKIE_DOMAIN` | Domain scope for which the state cookie is valid. |
|
|
608
|
+
* | `MONOCLOUD_AUTH_STATE_COOKIE_SECURE` | Ensures the state cookie is only sent over HTTPS connections. |
|
|
609
|
+
* | `MONOCLOUD_AUTH_STATE_COOKIE_SAME_SITE` | SameSite policy applied to the state cookie (`lax`, `strict`, or `none`). |
|
|
610
|
+
* | `MONOCLOUD_AUTH_STATE_COOKIE_PERSISTENT` | Determines whether the state cookie persists beyond the current browser session. |
|
|
611
|
+
*
|
|
612
|
+
* ### Caching
|
|
613
|
+
*
|
|
614
|
+
* | Environment Variable | Description |
|
|
615
|
+
* |----------------------|-------------|
|
|
616
|
+
* | `MONOCLOUD_AUTH_JWKS_CACHE_DURATION` | Duration (in seconds) to cache the JSON Web Key Set (JWKS) used to verify tokens. |
|
|
617
|
+
* | `MONOCLOUD_AUTH_METADATA_CACHE_DURATION` | Duration (in seconds) to cache the OpenID Connect discovery metadata. |
|
|
618
|
+
*
|
|
619
|
+
* @category Types
|
|
1233
620
|
*/
|
|
1234
|
-
|
|
621
|
+
interface MonoCloudOptions extends Partial<Omit<MonoCloudOptionsBase, 'defaultAuthParams' | 'session' | 'routes' | 'state'>> {
|
|
1235
622
|
/**
|
|
1236
|
-
* Default authorization parameters
|
|
623
|
+
* Default authorization parameters automatically included in authentication requests unless explicitly overridden.
|
|
624
|
+
*
|
|
1237
625
|
* @defaultValue {
|
|
1238
626
|
* scope: 'openid email profile',
|
|
1239
627
|
* response_type: 'code'
|
|
1240
628
|
* }
|
|
1241
629
|
*/
|
|
1242
|
-
defaultAuthParams?:
|
|
630
|
+
defaultAuthParams?: AuthorizationParams$1;
|
|
631
|
+
/**
|
|
632
|
+
* Overrides for built-in authentication route paths.
|
|
633
|
+
*/
|
|
634
|
+
routes?: Partial<MonoCloudRoutes>;
|
|
1243
635
|
/**
|
|
1244
|
-
*
|
|
636
|
+
* Session configuration overrides.
|
|
1245
637
|
*/
|
|
1246
638
|
session?: MonoCloudSessionOptions;
|
|
1247
|
-
|
|
639
|
+
/**
|
|
640
|
+
* Configuration for authentication state handling.
|
|
641
|
+
*/
|
|
642
|
+
state?: MonoCloudStatePartialOptions;
|
|
643
|
+
}
|
|
1248
644
|
/**
|
|
1249
|
-
*
|
|
1250
|
-
* This function receives an optional subject identifier (sub) of the user and an optional session identifier (sid).
|
|
645
|
+
* Callback invoked when a back-channel logout event is received from the authorization server.
|
|
1251
646
|
*
|
|
1252
|
-
*
|
|
1253
|
-
*
|
|
1254
|
-
* @
|
|
647
|
+
* Back-channel logout allows MonoCloud to notify the application that a user session should be terminated without browser interaction.
|
|
648
|
+
*
|
|
649
|
+
* @category Types (Handler)
|
|
650
|
+
*
|
|
651
|
+
* @param sub Optional subject identifier (`sub`) of the user associated with the logout event.
|
|
652
|
+
* @param sid Optional session identifier (`sid`) for the session being terminated.
|
|
653
|
+
* @returns Returns a promise or void. Execution completes once logout handling finishes.
|
|
1255
654
|
*/
|
|
1256
655
|
type OnBackChannelLogout = (
|
|
1257
656
|
/**
|
|
1258
|
-
*
|
|
657
|
+
* Subject identifier of the user.
|
|
1259
658
|
*/
|
|
1260
|
-
|
|
1261
659
|
sub?: string,
|
|
1262
660
|
/**
|
|
1263
|
-
*
|
|
661
|
+
* Session identifier associated with the logout event.
|
|
1264
662
|
*/
|
|
1265
|
-
|
|
1266
663
|
sid?: string) => Promise<void> | void;
|
|
1267
664
|
/**
|
|
1268
|
-
*
|
|
665
|
+
* Represents custom application state associated with an authentication request.
|
|
666
|
+
*
|
|
667
|
+
* This object is populated via `onSetApplicationState` and is persisted through the authentication flow. The resolved value is later available during session creation and can be used to carry application-specific context (for example: return targets, workflow state, or tenant hints).
|
|
668
|
+
*
|
|
669
|
+
* @category Types
|
|
1269
670
|
*/
|
|
1270
|
-
|
|
671
|
+
interface ApplicationState extends Record<string, any> {}
|
|
1271
672
|
/**
|
|
1272
|
-
*
|
|
1273
|
-
*
|
|
1274
|
-
*
|
|
1275
|
-
*
|
|
1276
|
-
*
|
|
1277
|
-
*
|
|
1278
|
-
*
|
|
1279
|
-
*
|
|
1280
|
-
*
|
|
1281
|
-
* @
|
|
673
|
+
* Callback invoked before a session is created or updated.
|
|
674
|
+
*
|
|
675
|
+
* Use this hook to modify or enrich the session before it is persisted. The callback receives the resolved session along with optional claims obtained during authentication and any custom application state.
|
|
676
|
+
*
|
|
677
|
+
* Common use cases include:
|
|
678
|
+
* - Adding custom properties to the session
|
|
679
|
+
* - Mapping or filtering claims
|
|
680
|
+
* - Attaching tenant or application-specific metadata
|
|
681
|
+
*
|
|
682
|
+
* @category Types (Handler)
|
|
683
|
+
*
|
|
684
|
+
* @param session The session being created or updated. Changes made to this object are persisted.
|
|
685
|
+
* @param idToken Optional claims extracted from the ID token.
|
|
686
|
+
* @param userInfo Optional claims returned from the `UserInfo` endpoint.
|
|
687
|
+
* @param state Optional application state created during the authentication request.
|
|
688
|
+
* @returns Returns a promise or void. Execution continues once the callback completes.
|
|
1282
689
|
*/
|
|
1283
690
|
type OnSessionCreating = (
|
|
1284
691
|
/**
|
|
1285
|
-
* The
|
|
692
|
+
* The session being created or updated.
|
|
1286
693
|
*/
|
|
1287
|
-
|
|
1288
694
|
session: MonoCloudSession$1,
|
|
1289
695
|
/**
|
|
1290
|
-
* Optional
|
|
696
|
+
* Optional claims extracted from the ID token.
|
|
1291
697
|
*/
|
|
1292
|
-
|
|
1293
698
|
idToken?: Partial<IdTokenClaims$1>,
|
|
1294
699
|
/**
|
|
1295
|
-
* Optional
|
|
700
|
+
* Optional claims returned from the `UserInfo` endpoint.
|
|
1296
701
|
*/
|
|
1297
|
-
|
|
1298
702
|
userInfo?: UserinfoResponse$1,
|
|
1299
703
|
/**
|
|
1300
|
-
* Optional
|
|
704
|
+
* Optional application state associated with the authentication flow.
|
|
1301
705
|
*/
|
|
1302
|
-
|
|
1303
706
|
state?: ApplicationState) => Promise<void> | void;
|
|
1304
707
|
/**
|
|
1305
|
-
*
|
|
1306
|
-
*
|
|
708
|
+
* Callback invoked when the authentication state is being created before redirecting the user to the authorization server.
|
|
709
|
+
*
|
|
710
|
+
* Use this hook to attach custom application state that should survive the authentication round-trip and be available after the user returns from sign-in.
|
|
1307
711
|
*
|
|
1308
|
-
*
|
|
1309
|
-
*
|
|
712
|
+
* The returned value is stored securely and later provided during session creation.
|
|
713
|
+
*
|
|
714
|
+
* Common use cases include:
|
|
715
|
+
* - Preserving return URLs or navigation context
|
|
716
|
+
* - Passing tenant or organization identifiers
|
|
717
|
+
* - Storing temporary workflow state across authentication
|
|
718
|
+
*
|
|
719
|
+
* @category Types (Handler)
|
|
720
|
+
*
|
|
721
|
+
* @param req The incoming request initiating authentication.
|
|
722
|
+
* @returns Returns an application state object, either synchronously or as a Promise.
|
|
1310
723
|
*/
|
|
1311
724
|
type OnSetApplicationState = (
|
|
1312
725
|
/**
|
|
1313
|
-
* The incoming request.
|
|
726
|
+
* The incoming request initiating authentication.
|
|
1314
727
|
*/
|
|
1315
|
-
|
|
1316
728
|
req: MonoCloudRequest) => Promise<ApplicationState> | ApplicationState;
|
|
1317
729
|
/**
|
|
1318
|
-
* Represents the
|
|
730
|
+
* Represents the token set associated with the currently authenticated user.
|
|
731
|
+
*
|
|
732
|
+
* This object extends {@link AccessToken} and includes additional tokens issued during authentication, along with convenience metadata used by the SDK to indicate token validity.
|
|
733
|
+
*
|
|
734
|
+
* @category Types
|
|
1319
735
|
*/
|
|
1320
736
|
interface MonoCloudTokens extends AccessToken$1 {
|
|
1321
737
|
/**
|
|
1322
|
-
* The ID token
|
|
738
|
+
* The ID token issued during authentication. Contains identity claims about the authenticated user.
|
|
1323
739
|
*/
|
|
1324
740
|
idToken?: string;
|
|
1325
741
|
/**
|
|
1326
|
-
* The refresh token
|
|
742
|
+
* The refresh token used to obtain new access tokens without requiring the user to re-authenticate.
|
|
1327
743
|
*/
|
|
1328
744
|
refreshToken?: string;
|
|
1329
745
|
/**
|
|
1330
|
-
*
|
|
746
|
+
* Indicates whether the current access token is expired at the time of evaluation.
|
|
1331
747
|
*/
|
|
1332
748
|
isExpired: boolean;
|
|
1333
749
|
}
|
|
1334
750
|
/**
|
|
1335
|
-
*
|
|
751
|
+
* Defines a callback invoked when an unexpected error occurs during execution of authentication endpoints such as sign-in, callback, sign-out, or userinfo.
|
|
1336
752
|
*
|
|
1337
|
-
*
|
|
753
|
+
* This handler allows applications to log, transform, or respond to errors before the SDK applies its default error handling behavior.
|
|
754
|
+
*
|
|
755
|
+
* @category Types (Handler)
|
|
756
|
+
*
|
|
757
|
+
* @param error - The error thrown during endpoint execution.
|
|
1338
758
|
*/
|
|
1339
759
|
type OnError = (error: Error) => Promise<any> | any;
|
|
1340
760
|
/**
|
|
1341
|
-
*
|
|
761
|
+
* Options used to customize the sign-in flow.
|
|
762
|
+
*
|
|
763
|
+
* @category Types
|
|
1342
764
|
*/
|
|
1343
765
|
interface SignInOptions {
|
|
1344
766
|
/**
|
|
1345
|
-
*
|
|
1346
|
-
*
|
|
1347
|
-
*
|
|
767
|
+
* Relative URL to redirect the user to after successful authentication.
|
|
768
|
+
*
|
|
769
|
+
* If not provided, the application base URL (`appUrl`) is used.
|
|
1348
770
|
*/
|
|
1349
771
|
returnUrl?: string;
|
|
1350
772
|
/**
|
|
1351
|
-
*
|
|
773
|
+
* When `true`, initiates the user registration (sign-up) flow instead of a standard sign-in.
|
|
1352
774
|
*/
|
|
1353
775
|
register?: boolean;
|
|
1354
776
|
/**
|
|
1355
|
-
* Additional authorization parameters
|
|
777
|
+
* Additional authorization parameters merged into the authentication request.
|
|
1356
778
|
*/
|
|
1357
779
|
authParams?: AuthorizationParams$1;
|
|
1358
780
|
/**
|
|
1359
|
-
*
|
|
781
|
+
* Callback invoked if an unexpected error occurs during the sign-in flow.
|
|
1360
782
|
*/
|
|
1361
783
|
onError?: OnError;
|
|
1362
784
|
}
|
|
1363
785
|
/**
|
|
1364
|
-
*
|
|
786
|
+
* Options used to customize callback processing after authentication.
|
|
787
|
+
*
|
|
788
|
+
* @category Types
|
|
1365
789
|
*/
|
|
1366
790
|
interface CallbackOptions {
|
|
1367
791
|
/**
|
|
1368
|
-
*
|
|
792
|
+
* When `true`, fetches user profile data from the `UserInfo` endpoint after the authorization code exchange completes.
|
|
1369
793
|
*/
|
|
1370
794
|
userInfo?: boolean;
|
|
1371
795
|
/**
|
|
1372
|
-
*
|
|
796
|
+
* Redirect URI sent to the token endpoint during the authorization code exchange.
|
|
797
|
+
*
|
|
798
|
+
* > This must match the redirect URI used during the sign-in request.
|
|
1373
799
|
*/
|
|
1374
800
|
redirectUri?: string;
|
|
1375
801
|
/**
|
|
1376
|
-
*
|
|
802
|
+
* Callback invoked if an unexpected error occurs while processing the authentication callback.
|
|
1377
803
|
*/
|
|
1378
804
|
onError?: OnError;
|
|
1379
805
|
}
|
|
1380
806
|
/**
|
|
1381
|
-
*
|
|
807
|
+
* Options used to customize the behavior of the userinfo handler.
|
|
808
|
+
*
|
|
809
|
+
* @category Types
|
|
1382
810
|
*/
|
|
1383
811
|
interface UserInfoOptions {
|
|
1384
812
|
/**
|
|
1385
|
-
*
|
|
813
|
+
* When `true`, forces user profile data to be re-fetched from the authentication service instead of using cached session data.
|
|
1386
814
|
*/
|
|
1387
815
|
refresh?: boolean;
|
|
1388
816
|
/**
|
|
1389
|
-
*
|
|
817
|
+
* Callback invoked if an unexpected error occurs while retrieving user information.
|
|
1390
818
|
*/
|
|
1391
819
|
onError?: OnError;
|
|
1392
820
|
}
|
|
1393
821
|
/**
|
|
1394
|
-
*
|
|
822
|
+
* Options used to customize the behavior of the sign-out handler.
|
|
823
|
+
*
|
|
824
|
+
* @category Types
|
|
1395
825
|
*/
|
|
1396
|
-
|
|
826
|
+
interface SignOutOptions extends EndSessionParameters$1 {
|
|
1397
827
|
/**
|
|
1398
|
-
*
|
|
828
|
+
* When `true`, also signs the user out of the MonoCloud session (Single Sign-Out) in addition to the local application session.
|
|
1399
829
|
*/
|
|
1400
830
|
federatedSignOut?: boolean;
|
|
1401
831
|
/**
|
|
1402
|
-
*
|
|
832
|
+
* Callback invoked if an unexpected error occurs during the sign-out flow.
|
|
1403
833
|
*/
|
|
1404
834
|
onError?: OnError;
|
|
1405
|
-
}
|
|
835
|
+
}
|
|
1406
836
|
/**
|
|
1407
|
-
*
|
|
837
|
+
* Options used to control token retrieval and refresh behavior when calling `getTokens()`.
|
|
838
|
+
*
|
|
839
|
+
* @category Types
|
|
1408
840
|
*/
|
|
1409
841
|
interface GetTokensOptions extends RefreshGrantOptions$1 {
|
|
1410
842
|
/**
|
|
1411
|
-
*
|
|
843
|
+
* When `true`, forces a refresh of the access token even if the current token has not expired.
|
|
1412
844
|
*/
|
|
1413
845
|
forceRefresh?: boolean;
|
|
1414
846
|
/**
|
|
1415
|
-
*
|
|
847
|
+
* When enabled, refetches user information from the `UserInfo` endpoint after tokens are refreshed.
|
|
1416
848
|
*/
|
|
1417
849
|
refetchUserInfo?: boolean;
|
|
1418
850
|
}
|
|
1419
851
|
//#endregion
|
|
1420
852
|
//#region src/monocloud-node-core-client.d.ts
|
|
853
|
+
/**
|
|
854
|
+
* @category Classes
|
|
855
|
+
*/
|
|
1421
856
|
declare class MonoCloudCoreClient {
|
|
1422
|
-
readonly oidcClient: MonoCloudOidcClient
|
|
857
|
+
readonly oidcClient: MonoCloudOidcClient;
|
|
1423
858
|
private readonly options;
|
|
1424
859
|
private readonly stateService;
|
|
1425
860
|
private readonly sessionService;
|
|
@@ -1430,7 +865,7 @@ declare class MonoCloudCoreClient {
|
|
|
1430
865
|
* Initiates the sign-in flow by redirecting the user to the MonoCloud authorization endpoint.
|
|
1431
866
|
*
|
|
1432
867
|
* This method handles scope and resource merging, state generation (nonce, state, PKCE),
|
|
1433
|
-
* and
|
|
868
|
+
* and constructing the final authorization URL.
|
|
1434
869
|
*
|
|
1435
870
|
* @param request - MonoCloud request object.
|
|
1436
871
|
* @param response - MonoCloud response object.
|
|
@@ -1551,7 +986,7 @@ declare class MonoCloudCoreClient {
|
|
|
1551
986
|
* @param response - MonoCloud cookie response object.
|
|
1552
987
|
* @param options - Configuration for token retrieval (force refresh, specific scopes/resources).
|
|
1553
988
|
*
|
|
1554
|
-
* @returns Fetched tokens
|
|
989
|
+
* @returns Fetched tokens.
|
|
1555
990
|
*
|
|
1556
991
|
* @throws {@link MonoCloudValidationError} If the session does not exist or tokens cannot be found/refreshed.
|
|
1557
992
|
*/
|
|
@@ -1561,5 +996,5 @@ declare class MonoCloudCoreClient {
|
|
|
1561
996
|
private validateOptions;
|
|
1562
997
|
}
|
|
1563
998
|
//#endregion
|
|
1564
|
-
export { type AccessToken, type ApplicationState, type AuthState, type AuthenticateOptions, type Authenticators, type AuthorizationParams, type CallbackOptions, type CallbackParams, type ClientAuthMethod, type CodeChallengeMethod, type CookieOptions, type DisplayOptions, type EndSessionParameters, type GetTokensOptions, type Group, type IMonoCloudCookieRequest, type IMonoCloudCookieResponse, type IdTokenClaims, type Indicator, type IssuerMetadata, type
|
|
999
|
+
export { type AccessToken, type Address, type ApplicationState, type AuthState, type AuthenticateOptions, type Authenticators, type AuthorizationParams, type CallbackOptions, type CallbackParams, type ClientAuthMethod, type CodeChallengeMethod, type CookieOptions, type DisplayOptions, type EndSessionParameters, type GetTokensOptions, type Group, type IMonoCloudCookieRequest, type IMonoCloudCookieResponse, type IdTokenClaims, type Indicator, type IssuerMetadata, type Jwk, type Jwks, type JwsHeaderParameters, MonoCloudAuthBaseError, type MonoCloudClientOptions, type MonoCloudCookieOptions, MonoCloudCoreClient, MonoCloudHttpError, MonoCloudOPError, type MonoCloudOptions, type MonoCloudOptionsBase, type MonoCloudRequest, type MonoCloudResponse, type MonoCloudRoutes, type MonoCloudSession, type MonoCloudSessionOptions, type MonoCloudSessionOptionsBase, type MonoCloudSessionStore, type MonoCloudStateOptions, type MonoCloudStatePartialOptions, MonoCloudTokenError, type MonoCloudTokens, type MonoCloudUser, MonoCloudValidationError, type OnBackChannelLogout, type OnCoreSessionCreating, type OnError, type OnSessionCreating, type OnSetApplicationState, type ParResponse, type Prompt, type PushedAuthorizationParams, type RefetchUserInfoOptions, type RefreshGrantOptions, type RefreshSessionOptions, type ResponseModes, type ResponseTypes, type SameSiteValues, type SecurityAlgorithms, type SerializeOptions, type SessionLifetime, type SetCookie, type SignInOptions, type SignOutOptions, type Tokens, type UserInfoOptions, type UserinfoResponse };
|
|
1565
1000
|
//# sourceMappingURL=index.d.mts.map
|