@monocloud/auth-node-core 0.1.5 → 0.1.6
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 +466 -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,432 @@
|
|
|
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
|
+
/** Retrieves a single cookie value by name. */
|
|
876
18
|
getCookie(name: string): Promise<string | undefined>;
|
|
19
|
+
/** Retrieves all cookies from the request. */
|
|
877
20
|
getAllCookies(): Promise<Map<string, string>>;
|
|
878
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Represents a request object that includes cookie handling capabilities.
|
|
24
|
+
*
|
|
25
|
+
* @category Types
|
|
26
|
+
*/
|
|
879
27
|
interface MonoCloudRequest extends IMonoCloudCookieRequest {
|
|
28
|
+
/** Retrieves a query parameter value by name. */
|
|
880
29
|
getQuery(parameter: string): string | string[] | undefined;
|
|
30
|
+
/** Returns the raw request details including method, URL, and body. */
|
|
881
31
|
getRawRequest(): Promise<{
|
|
882
32
|
method: string;
|
|
883
33
|
url: string;
|
|
884
34
|
body: Record<string, string> | string;
|
|
885
35
|
}>;
|
|
886
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Interface for setting cookies on an outgoing response.
|
|
39
|
+
*
|
|
40
|
+
* @category Types
|
|
41
|
+
*/
|
|
887
42
|
interface IMonoCloudCookieResponse {
|
|
43
|
+
/** Sets a cookie on the response. */
|
|
888
44
|
setCookie(cookieName: string, value: string, options: CookieOptions): Promise<void>;
|
|
889
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Represents an outgoing HTTP response with common helper methods.
|
|
48
|
+
*
|
|
49
|
+
* @category Types
|
|
50
|
+
*/
|
|
890
51
|
interface MonoCloudResponse extends IMonoCloudCookieResponse {
|
|
52
|
+
/** Redirects the client to the specified URL. */
|
|
891
53
|
redirect(url: string, statusCode?: number): void;
|
|
54
|
+
/** Sends a JSON response with an optional status code. */
|
|
892
55
|
sendJson(data: any, statusCode?: number): void;
|
|
56
|
+
/** Sends a 404 Not Found response. */
|
|
893
57
|
notFound(): void;
|
|
58
|
+
/** Sends a 204 No Content response. */
|
|
894
59
|
noContent(): void;
|
|
60
|
+
/** Sends a 500 Internal Server Error response. */
|
|
895
61
|
internalServerError(): void;
|
|
62
|
+
/** Sends a 405 Method Not Allowed response. */
|
|
896
63
|
methodNotAllowed(): void;
|
|
64
|
+
/** Sets cache-control headers to prevent caching. */
|
|
897
65
|
setNoCache(): void;
|
|
66
|
+
/** Finalizes and returns the response. */
|
|
898
67
|
done(): any;
|
|
899
68
|
}
|
|
900
69
|
//#endregion
|
|
901
70
|
//#region src/types/index.d.ts
|
|
902
71
|
/**
|
|
903
|
-
*
|
|
72
|
+
* Allowed values for the cookie `SameSite` attribute.
|
|
73
|
+
*
|
|
74
|
+
* The `SameSite` setting controls when cookies are included in cross-site requests and helps protect against cross-site request forgery (CSRF) attacks.
|
|
75
|
+
*
|
|
76
|
+
* @category Types (Enums)
|
|
904
77
|
*/
|
|
905
|
-
type SameSiteValues =
|
|
78
|
+
type SameSiteValues =
|
|
906
79
|
/**
|
|
907
|
-
*
|
|
80
|
+
* Cookies are only sent for same-site requests.
|
|
81
|
+
*
|
|
82
|
+
* Cookies will NOT be included in cross-site navigations, redirects, or embedded requests.
|
|
83
|
+
*
|
|
84
|
+
* Provides the strongest CSRF protection but may break authentication flows that rely on cross-site redirects.
|
|
908
85
|
*/
|
|
909
|
-
|
|
86
|
+
'strict'
|
|
910
87
|
/**
|
|
911
|
-
*
|
|
912
|
-
*
|
|
88
|
+
* Cookies are sent for same-site requests and top-level cross-site navigations (for example, following a link).
|
|
89
|
+
*
|
|
90
|
+
* This is the recommended default for most authentication flows.
|
|
91
|
+
*/
|
|
92
|
+
| 'lax'
|
|
93
|
+
/**
|
|
94
|
+
* Cookies are sent with all requests, including cross-site requests.
|
|
95
|
+
*
|
|
96
|
+
* Must be used together with `Secure=true` (HTTPS only).
|
|
97
|
+
*
|
|
98
|
+
* Required for some third-party or cross-origin authentication scenarios.
|
|
99
|
+
*/
|
|
100
|
+
| 'none';
|
|
101
|
+
/**
|
|
102
|
+
* Represents the lifetime metadata associated with a user session.
|
|
103
|
+
*
|
|
104
|
+
* The properties use short keys to minimize cookie and storage size, since this structure may be serialized as part of session data.
|
|
105
|
+
*
|
|
106
|
+
* All timestamps are expressed as **Unix epoch time (seconds)**.
|
|
107
|
+
*
|
|
108
|
+
* @category Types
|
|
913
109
|
*/
|
|
914
110
|
interface SessionLifetime {
|
|
915
111
|
/**
|
|
916
|
-
*
|
|
112
|
+
* Session creation time.
|
|
113
|
+
*
|
|
114
|
+
* The moment the session was initially established.
|
|
917
115
|
*/
|
|
918
116
|
c: number;
|
|
919
117
|
/**
|
|
920
|
-
*
|
|
118
|
+
* Last updated time.
|
|
119
|
+
*
|
|
120
|
+
* Updated whenever the session is refreshed or extended (for example, during sliding expiration).
|
|
921
121
|
*/
|
|
922
122
|
u: number;
|
|
923
123
|
/**
|
|
924
|
-
* Optional
|
|
124
|
+
* Optional expiration time.
|
|
925
125
|
*/
|
|
926
126
|
e?: number;
|
|
927
127
|
}
|
|
928
128
|
/**
|
|
929
|
-
*
|
|
129
|
+
* Defines a storage adapter used to persist authentication sessions.
|
|
130
|
+
*
|
|
131
|
+
* Implement this interface to store sessions outside the default cookie-based storage — for example in Redis, a database, or a distributed cache.
|
|
132
|
+
*
|
|
133
|
+
* @category Types
|
|
930
134
|
*/
|
|
931
135
|
interface MonoCloudSessionStore {
|
|
932
136
|
/**
|
|
933
|
-
* Retrieves a session
|
|
934
|
-
*
|
|
935
|
-
* @
|
|
137
|
+
* Retrieves a session associated with the provided key.
|
|
138
|
+
*
|
|
139
|
+
* @param key Unique identifier of the session.
|
|
140
|
+
* @returns Returns the stored session, or `undefined` / `null` if no session exists.
|
|
936
141
|
*/
|
|
937
142
|
get(key: string): Promise<MonoCloudSession$1 | undefined | null>;
|
|
938
143
|
/**
|
|
939
|
-
*
|
|
940
|
-
*
|
|
941
|
-
*
|
|
942
|
-
*
|
|
943
|
-
* @
|
|
144
|
+
* Persists or updates a session.
|
|
145
|
+
*
|
|
146
|
+
* The provided lifetime information can be used by the store to configure TTL/expiration policies.
|
|
147
|
+
*
|
|
148
|
+
* @param key Unique identifier of the session.
|
|
149
|
+
* @param data The session data to persist.
|
|
150
|
+
* @param lifetime Session lifetime metadata (creation, update, expiration).
|
|
944
151
|
*/
|
|
945
152
|
set(key: string, data: MonoCloudSession$1, lifetime: SessionLifetime): Promise<void>;
|
|
946
153
|
/**
|
|
947
|
-
*
|
|
948
|
-
*
|
|
949
|
-
* @
|
|
154
|
+
* Removes a session from the store.
|
|
155
|
+
*
|
|
156
|
+
* @param key Unique identifier of the session to delete.
|
|
950
157
|
*/
|
|
951
158
|
delete(key: string): Promise<void>;
|
|
952
159
|
}
|
|
953
160
|
/**
|
|
954
|
-
*
|
|
161
|
+
* Configuration options for authentication cookies.
|
|
162
|
+
*
|
|
163
|
+
* These settings control how MonoCloud session and state cookies are created, scoped, and transmitted by the browser.
|
|
164
|
+
*
|
|
165
|
+
* @category Types
|
|
955
166
|
*/
|
|
956
167
|
interface MonoCloudCookieOptions {
|
|
957
168
|
/**
|
|
958
|
-
* The name
|
|
959
|
-
*
|
|
960
|
-
*
|
|
169
|
+
* The cookie name.
|
|
170
|
+
*
|
|
171
|
+
* - Session cookie default: `"session"`
|
|
172
|
+
* - State cookie default: `"state"`
|
|
961
173
|
*/
|
|
962
174
|
name: string;
|
|
963
175
|
/**
|
|
964
|
-
* The path for which the cookie is valid.
|
|
176
|
+
* The URL path for which the cookie is valid.
|
|
177
|
+
*
|
|
965
178
|
* @defaultValue '/'
|
|
966
179
|
*/
|
|
967
180
|
path: string;
|
|
968
181
|
/**
|
|
969
|
-
* Optional
|
|
182
|
+
* Optional domain scope for the cookie.
|
|
970
183
|
*/
|
|
971
184
|
domain?: string;
|
|
972
185
|
/**
|
|
973
|
-
*
|
|
974
|
-
*
|
|
186
|
+
* Indicates whether the cookie is accessible only via HTTP requests. Helps mitigate XSS attacks by preventing client-side JavaScript access.
|
|
187
|
+
*
|
|
188
|
+
* > Always enforced as `true` for state cookies.
|
|
189
|
+
*
|
|
975
190
|
* @defaultValue true
|
|
976
191
|
*/
|
|
977
192
|
httpOnly: boolean;
|
|
978
193
|
/**
|
|
979
|
-
*
|
|
980
|
-
*
|
|
194
|
+
* Indicates whether the cookie should only be transmitted over HTTPS.
|
|
195
|
+
*
|
|
196
|
+
* If not explicitly provided, this value is automatically inferred from the application URL scheme.
|
|
981
197
|
*/
|
|
982
198
|
secure: boolean;
|
|
983
199
|
/**
|
|
984
|
-
* The SameSite
|
|
200
|
+
* The SameSite policy applied to the cookie. Controls cross-site request behavior and CSRF protection.
|
|
201
|
+
*
|
|
985
202
|
* @defaultValue 'lax'
|
|
986
203
|
*/
|
|
987
204
|
sameSite: SameSiteValues;
|
|
988
205
|
/**
|
|
989
|
-
* Determines whether the cookie
|
|
990
|
-
*
|
|
991
|
-
*
|
|
206
|
+
* Determines whether the cookie persists across browser restarts.
|
|
207
|
+
*
|
|
208
|
+
* - Session cookies default to `true`
|
|
209
|
+
* - State cookies default to `false`
|
|
992
210
|
*/
|
|
993
211
|
persistent: boolean;
|
|
994
212
|
}
|
|
995
213
|
/**
|
|
996
|
-
*
|
|
214
|
+
* Configuration options for authentication sessions.
|
|
215
|
+
*
|
|
216
|
+
* These options control how user sessions are created, persisted, and expired.
|
|
217
|
+
*
|
|
218
|
+
* @category Types
|
|
997
219
|
*/
|
|
998
220
|
interface MonoCloudSessionOptionsBase {
|
|
999
221
|
/**
|
|
1000
|
-
* Configuration
|
|
222
|
+
* Configuration for the session cookie used to identify the user session.
|
|
1001
223
|
*/
|
|
1002
224
|
cookie: MonoCloudCookieOptions;
|
|
1003
225
|
/**
|
|
1004
|
-
*
|
|
226
|
+
* Enables sliding session expiration.
|
|
227
|
+
*
|
|
228
|
+
* When enabled, the session expiration is extended on active requests, up to the configured `maximumDuration`.
|
|
229
|
+
*
|
|
230
|
+
* When disabled, the session expires after a fixed duration regardless of user activity.
|
|
231
|
+
*
|
|
1005
232
|
* @defaultValue false
|
|
1006
233
|
*/
|
|
1007
234
|
sliding: boolean;
|
|
1008
235
|
/**
|
|
1009
|
-
* The
|
|
236
|
+
* The session lifetime in seconds.
|
|
237
|
+
*
|
|
238
|
+
* - With **absolute sessions** (`sliding = false`), this defines the total session lifetime.
|
|
239
|
+
* - With **sliding sessions**, this defines the idle timeout before the session expires.
|
|
240
|
+
*
|
|
1010
241
|
* @defaultValue 86400 (1 Day)
|
|
1011
242
|
*/
|
|
1012
243
|
duration: number;
|
|
1013
244
|
/**
|
|
1014
|
-
* The maximum
|
|
1015
|
-
*
|
|
1016
|
-
*
|
|
245
|
+
* The absolute maximum lifetime of a sliding session in seconds.
|
|
246
|
+
*
|
|
247
|
+
* This value limits how long a session can exist even if the user remains continuously active.
|
|
248
|
+
*
|
|
249
|
+
* Only applies when `sliding` is enabled.
|
|
250
|
+
*
|
|
251
|
+
* @defaultValue 604800 (7 days)
|
|
1017
252
|
*/
|
|
1018
253
|
maximumDuration: number;
|
|
1019
254
|
/**
|
|
1020
|
-
* Optional
|
|
255
|
+
* Optional session store used to persist session data.
|
|
256
|
+
*
|
|
257
|
+
* If not provided, The SDK uses the default cookie-based session storage.
|
|
258
|
+
*
|
|
259
|
+
* Custom stores allow centralized session management (e.g. Redis, database).
|
|
1021
260
|
*/
|
|
1022
261
|
store?: MonoCloudSessionStore;
|
|
1023
262
|
}
|
|
1024
263
|
/**
|
|
1025
|
-
*
|
|
264
|
+
* Partial configuration options for authentication state handling.
|
|
265
|
+
*
|
|
266
|
+
* @category Types
|
|
267
|
+
*/
|
|
268
|
+
interface MonoCloudStatePartialOptions {
|
|
269
|
+
/**
|
|
270
|
+
* Partial configuration for the state cookie.
|
|
271
|
+
*
|
|
272
|
+
* This cookie temporarily stores authorization transaction data required to validate the callback response and prevent replay or CSRF attacks.
|
|
273
|
+
*/
|
|
274
|
+
cookie?: Partial<MonoCloudCookieOptions>;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Configuration options for authentication state handling.
|
|
278
|
+
*
|
|
279
|
+
* @category Types
|
|
1026
280
|
*/
|
|
1027
281
|
interface MonoCloudStateOptions {
|
|
1028
282
|
/**
|
|
1029
|
-
* Configuration
|
|
283
|
+
* Configuration for the state cookie.
|
|
284
|
+
*
|
|
285
|
+
* This cookie temporarily stores authorization transaction data required to validate the callback response and prevent replay or CSRF attacks.
|
|
1030
286
|
*/
|
|
1031
287
|
cookie: MonoCloudCookieOptions;
|
|
1032
288
|
}
|
|
1033
289
|
/**
|
|
1034
|
-
*
|
|
290
|
+
* Route configuration for MonoCloud authentication handlers.
|
|
291
|
+
*
|
|
292
|
+
* 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.
|
|
293
|
+
*
|
|
294
|
+
* You typically do not need to change these values unless you want to customize your application's authentication URLs.
|
|
295
|
+
*
|
|
296
|
+
* > When customizing routes, ensure the corresponding URLs are also configured in your MonoCloud Dashboard and exposed to the client using the matching environment variables.
|
|
297
|
+
*
|
|
298
|
+
* @category Types
|
|
1035
299
|
*/
|
|
1036
300
|
interface MonoCloudRoutes {
|
|
1037
301
|
/**
|
|
1038
|
-
*
|
|
302
|
+
* Route that receives the authorization callback from MonoCloud after a successful authentication.
|
|
303
|
+
*
|
|
1039
304
|
* @defaultValue '/api/auth/callback'
|
|
1040
305
|
*/
|
|
1041
306
|
callback: string;
|
|
1042
307
|
/**
|
|
1043
|
-
*
|
|
308
|
+
* Route that handles OpenID Connect back-channel logout requests initiated by MonoCloud.
|
|
309
|
+
*
|
|
1044
310
|
* @defaultValue '/api/auth/backchannel-logout'
|
|
1045
311
|
*/
|
|
1046
312
|
backChannelLogout: string;
|
|
1047
313
|
/**
|
|
1048
|
-
*
|
|
314
|
+
* Route used to initiate the sign-in flow.
|
|
315
|
+
*
|
|
1049
316
|
* @defaultValue '/api/auth/signin'
|
|
1050
317
|
*/
|
|
1051
318
|
signIn: string;
|
|
1052
319
|
/**
|
|
1053
|
-
*
|
|
320
|
+
* Route used to initiate the sign-out flow.
|
|
321
|
+
*
|
|
1054
322
|
* @defaultValue '/api/auth/signout'
|
|
1055
323
|
*/
|
|
1056
324
|
signOut: string;
|
|
1057
325
|
/**
|
|
1058
|
-
*
|
|
326
|
+
* Route that exposes the authenticated user's profile information.
|
|
327
|
+
*
|
|
1059
328
|
* @defaultValue '/api/auth/userinfo'
|
|
1060
329
|
*/
|
|
1061
330
|
userInfo: string;
|
|
1062
331
|
}
|
|
1063
332
|
/**
|
|
1064
|
-
* Represents an
|
|
333
|
+
* Represents an additional resource indicator that can be requested during token acquisition.
|
|
334
|
+
*
|
|
335
|
+
* 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.
|
|
336
|
+
*
|
|
337
|
+
* @category Types
|
|
1065
338
|
*/
|
|
1066
339
|
interface Indicator {
|
|
1067
340
|
/**
|
|
1068
|
-
* Space
|
|
341
|
+
* Space-separated list of resource identifiers (audiences) that the access token should be issued for.
|
|
342
|
+
*
|
|
343
|
+
* Each value typically represents an API identifier or resource URI.
|
|
1069
344
|
*/
|
|
1070
345
|
resource: string;
|
|
1071
346
|
/**
|
|
1072
|
-
* Optional
|
|
347
|
+
* Optional. Space-separated list of scopes to request specifically for this resource.
|
|
1073
348
|
*/
|
|
1074
349
|
scopes?: string;
|
|
1075
350
|
}
|
|
1076
351
|
/**
|
|
1077
|
-
*
|
|
352
|
+
* Core configuration options for the SDK.
|
|
353
|
+
*
|
|
354
|
+
* These options define how the SDK communicates with your MonoCloud tenant, manages sessions, and performs authentication flows.
|
|
355
|
+
*
|
|
356
|
+
* @category Types
|
|
1078
357
|
*/
|
|
1079
358
|
interface MonoCloudOptionsBase {
|
|
1080
359
|
/**
|
|
1081
|
-
*
|
|
360
|
+
* Client identifier of the application registered in MonoCloud.
|
|
1082
361
|
*/
|
|
1083
362
|
clientId: string;
|
|
1084
363
|
/**
|
|
1085
|
-
* Optional
|
|
364
|
+
* Optional client secret used for confidential clients.
|
|
1086
365
|
*/
|
|
1087
366
|
clientSecret?: string;
|
|
1088
367
|
/**
|
|
1089
|
-
* MonoCloud tenant domain.
|
|
368
|
+
* MonoCloud tenant domain (for example, `https://your-tenant.us.monocloud.com`).
|
|
1090
369
|
*/
|
|
1091
370
|
tenantDomain: string;
|
|
1092
371
|
/**
|
|
1093
|
-
*
|
|
372
|
+
* Secret used to encrypt and sign authentication cookies. This value should be long, random, and kept private.
|
|
1094
373
|
*/
|
|
1095
374
|
cookieSecret: string;
|
|
1096
375
|
/**
|
|
1097
|
-
*
|
|
376
|
+
* Base URL where the application is hosted.
|
|
377
|
+
*
|
|
378
|
+
* Used to construct redirect URLs and validate requests.
|
|
1098
379
|
*/
|
|
1099
380
|
appUrl: string;
|
|
1100
381
|
/**
|
|
1101
|
-
*
|
|
382
|
+
* Route paths used by MonoCloud authentication handlers.
|
|
1102
383
|
*/
|
|
1103
384
|
routes: MonoCloudRoutes;
|
|
1104
385
|
/**
|
|
1105
|
-
*
|
|
386
|
+
* Allowed clock skew (in seconds) when validating token timestamps.
|
|
387
|
+
*
|
|
1106
388
|
* @defaultValue 60 (seconds)
|
|
1107
389
|
*/
|
|
1108
390
|
clockSkew: number;
|
|
1109
391
|
/**
|
|
1110
|
-
*
|
|
392
|
+
* Maximum time (in milliseconds) to wait for responses from the MonoCloud authorization server.
|
|
393
|
+
*
|
|
1111
394
|
* @defaultValue 10000 (10 seconds)
|
|
1112
395
|
*/
|
|
1113
396
|
responseTimeout: number;
|
|
1114
397
|
/**
|
|
1115
|
-
*
|
|
398
|
+
* Enables Pushed Authorization Requests (PAR).
|
|
399
|
+
*
|
|
400
|
+
* When enabled, authorization parameters are sent securely via the PAR endpoint instead of the browser.
|
|
401
|
+
*
|
|
1116
402
|
* @defaultValue false
|
|
1117
403
|
*/
|
|
1118
404
|
usePar: boolean;
|
|
1119
405
|
/**
|
|
1120
|
-
*
|
|
406
|
+
* URL to redirect users to after logout completes.
|
|
1121
407
|
*/
|
|
1122
408
|
postLogoutRedirectUri?: string;
|
|
1123
409
|
/**
|
|
1124
|
-
*
|
|
410
|
+
* When `true`, signing out also logs the user out of MonoCloud (Single Sign-Out).
|
|
411
|
+
*
|
|
1125
412
|
* @defaultValue true
|
|
1126
413
|
*/
|
|
1127
414
|
federatedSignOut: boolean;
|
|
1128
415
|
/**
|
|
1129
|
-
*
|
|
416
|
+
* Fetch user profile data from the `UserInfo` endpoint after authentication completes.
|
|
417
|
+
*
|
|
1130
418
|
* @defaultValue true
|
|
1131
419
|
*/
|
|
1132
420
|
userInfo: boolean;
|
|
1133
421
|
/**
|
|
1134
|
-
*
|
|
1135
|
-
*
|
|
422
|
+
* Refetch user profile data whenever the application's `UserInfo` endpoint is invoked.
|
|
423
|
+
*
|
|
1136
424
|
* @defaultValue false
|
|
1137
425
|
*/
|
|
1138
426
|
refetchUserInfo: boolean;
|
|
1139
427
|
/**
|
|
1140
|
-
* Default authorization parameters
|
|
428
|
+
* Default authorization parameters included in authentication requests.
|
|
429
|
+
*
|
|
1141
430
|
* @defaultValue {
|
|
1142
431
|
* scope: 'openid email profile',
|
|
1143
432
|
* response_type: 'code'
|
|
@@ -1145,281 +434,408 @@ interface MonoCloudOptionsBase {
|
|
|
1145
434
|
*/
|
|
1146
435
|
defaultAuthParams: AuthorizationParams$1;
|
|
1147
436
|
/**
|
|
1148
|
-
* Optional
|
|
437
|
+
* Optional resource indicators available when requesting tokens via `getTokens()`.
|
|
1149
438
|
*
|
|
1150
439
|
*/
|
|
1151
440
|
resources?: Indicator[];
|
|
1152
441
|
/**
|
|
1153
|
-
*
|
|
442
|
+
* Session configuration.
|
|
1154
443
|
*/
|
|
1155
444
|
session: MonoCloudSessionOptionsBase;
|
|
1156
445
|
/**
|
|
1157
|
-
*
|
|
446
|
+
* Authentication state configuration.
|
|
1158
447
|
*/
|
|
1159
448
|
state: MonoCloudStateOptions;
|
|
1160
449
|
/**
|
|
1161
|
-
*
|
|
450
|
+
* Expected signing algorithm for ID tokens.
|
|
451
|
+
*
|
|
1162
452
|
* @defaultValue 'RS256'
|
|
1163
453
|
*/
|
|
1164
|
-
idTokenSigningAlg: SecurityAlgorithms;
|
|
454
|
+
idTokenSigningAlg: SecurityAlgorithms$1;
|
|
1165
455
|
/**
|
|
1166
|
-
*
|
|
456
|
+
* List of ID token claims that should be removed before storing data in the session.
|
|
1167
457
|
*/
|
|
1168
458
|
filteredIdTokenClaims: string[];
|
|
1169
459
|
/**
|
|
1170
|
-
*
|
|
460
|
+
* Identifier used for internal debugging/logging.
|
|
1171
461
|
*/
|
|
1172
462
|
debugger: string;
|
|
1173
463
|
/**
|
|
1174
|
-
*
|
|
464
|
+
* Custom User-Agent value sent with requests to MonoCloud.
|
|
1175
465
|
*/
|
|
1176
466
|
userAgent: string;
|
|
1177
467
|
/**
|
|
1178
|
-
*
|
|
1179
|
-
*
|
|
1180
|
-
* Time in seconds to cache the JWKS document after it is fetched
|
|
468
|
+
* Duration (in seconds) to cache the JWKS document.
|
|
1181
469
|
*
|
|
1182
|
-
* @
|
|
1183
|
-
|
|
1184
|
-
* */
|
|
470
|
+
* @defaultValue 300
|
|
471
|
+
*/
|
|
1185
472
|
jwksCacheDuration?: number;
|
|
1186
473
|
/**
|
|
1187
|
-
*
|
|
1188
|
-
*
|
|
1189
|
-
* Time in seconds to cache the metadata document after it is fetched.
|
|
474
|
+
* Duration (in seconds) to cache OpenID discovery metadata.
|
|
1190
475
|
*
|
|
1191
|
-
* @
|
|
1192
|
-
|
|
476
|
+
* @defaultValue 300
|
|
477
|
+
*/
|
|
1193
478
|
metadataCacheDuration?: number;
|
|
1194
479
|
/**
|
|
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
|
|
480
|
+
* Allows authorization parameters to be overridden using query parameters.
|
|
1202
481
|
*
|
|
1203
|
-
*
|
|
1204
|
-
* https://example.com/api/auth/signin?prompt=login&login_hint=user@example.com
|
|
482
|
+
* 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
483
|
*
|
|
1206
|
-
* @
|
|
484
|
+
* @defaultValue false
|
|
1207
485
|
*/
|
|
1208
486
|
allowQueryParamOverrides?: boolean;
|
|
1209
487
|
/**
|
|
1210
|
-
*
|
|
488
|
+
* Invoked when a back-channel logout request is received.
|
|
1211
489
|
*/
|
|
1212
490
|
onBackChannelLogout?: OnBackChannelLogout;
|
|
1213
491
|
/**
|
|
1214
|
-
*
|
|
492
|
+
* Invoked before authentication begins to attach custom application state.
|
|
1215
493
|
*/
|
|
1216
494
|
onSetApplicationState?: OnSetApplicationState;
|
|
1217
495
|
/**
|
|
1218
|
-
*
|
|
496
|
+
* Invoked before a session is created or updated. Can be used to modify session data or attach custom fields.
|
|
1219
497
|
*/
|
|
1220
498
|
onSessionCreating?: OnSessionCreating;
|
|
1221
499
|
}
|
|
1222
500
|
/**
|
|
1223
|
-
*
|
|
501
|
+
* Partial configuration options for authentication sessions.
|
|
502
|
+
*
|
|
503
|
+
* @category Types
|
|
1224
504
|
*/
|
|
1225
|
-
|
|
505
|
+
interface MonoCloudSessionOptions extends Partial<Omit<MonoCloudSessionOptionsBase, 'store' | 'cookie'>> {
|
|
506
|
+
/**
|
|
507
|
+
* Session cookie settings.
|
|
508
|
+
*/
|
|
509
|
+
cookie?: Partial<MonoCloudCookieOptions>;
|
|
1226
510
|
/**
|
|
1227
|
-
*
|
|
511
|
+
* A custom session store implementation.
|
|
512
|
+
*
|
|
513
|
+
* When provided, sessions are persisted using this store instead of cookies-only storage.
|
|
1228
514
|
*/
|
|
1229
515
|
store?: MonoCloudSessionStore;
|
|
1230
|
-
}
|
|
516
|
+
}
|
|
1231
517
|
/**
|
|
1232
|
-
*
|
|
518
|
+
* Configuration options used to initialize the SDK client.
|
|
519
|
+
*
|
|
520
|
+
* ## Configuration Sources
|
|
521
|
+
*
|
|
522
|
+
* Configuration values can be provided using either:
|
|
523
|
+
*
|
|
524
|
+
* - **Constructor options** - passed when creating the client instance.
|
|
525
|
+
* - **Environment variables** - using `MONOCLOUD_AUTH_*` variables.
|
|
526
|
+
*
|
|
527
|
+
* When both are provided, **constructor options override environment variables**.
|
|
528
|
+
*
|
|
529
|
+
* ## Environment Variables
|
|
530
|
+
*
|
|
531
|
+
* ### Core Configuration (Required)
|
|
532
|
+
*
|
|
533
|
+
* | Environment Variable | Description |
|
|
534
|
+
* |----------------------|-------------|
|
|
535
|
+
* | `MONOCLOUD_AUTH_CLIENT_ID` | Unique identifier for your application/client. |
|
|
536
|
+
* | `MONOCLOUD_AUTH_CLIENT_SECRET` | Application/client secret used for authentication. |
|
|
537
|
+
* | `MONOCLOUD_AUTH_TENANT_DOMAIN` | The domain of your MonoCloud tenant (for example, `https://your-tenant.us.monocloud.com`). |
|
|
538
|
+
* | `MONOCLOUD_AUTH_APP_URL` | The base URL where your application is hosted. |
|
|
539
|
+
* | `MONOCLOUD_AUTH_COOKIE_SECRET` | A long, random string used to encrypt and sign session cookies. |
|
|
540
|
+
*
|
|
541
|
+
* ### Authentication & Security
|
|
542
|
+
*
|
|
543
|
+
* | Environment Variable | Description |
|
|
544
|
+
* |----------------------|-------------|
|
|
545
|
+
* | `MONOCLOUD_AUTH_SCOPES` | Space-separated list of OIDC scopes to request (for example, `openid profile email`). |
|
|
546
|
+
* | `MONOCLOUD_AUTH_RESOURCE` | Default resource (audience) identifier used when issuing access tokens. |
|
|
547
|
+
* | `MONOCLOUD_AUTH_USE_PAR` | Enables Pushed Authorization Requests (PAR) for authorization flows. |
|
|
548
|
+
* | `MONOCLOUD_AUTH_CLOCK_SKEW` | Allowed clock drift (in seconds) when validating token timestamps. |
|
|
549
|
+
* | `MONOCLOUD_AUTH_FEDERATED_SIGNOUT` | If `true`, signing out of the application also signs the user out of MonoCloud (SSO sign-out). |
|
|
550
|
+
* | `MONOCLOUD_AUTH_RESPONSE_TIMEOUT` | Maximum time (in milliseconds) to wait for responses from the authentication service. |
|
|
551
|
+
* | `MONOCLOUD_AUTH_ALLOW_QUERY_PARAM_OVERRIDES` | Allows authorization parameters (such as `scope`, `resource`, or `prompt`) to be overridden via URL query parameters. |
|
|
552
|
+
* | `MONOCLOUD_AUTH_POST_LOGOUT_REDIRECT_URI` | URL users are redirected to after a successful logout. |
|
|
553
|
+
* | `MONOCLOUD_AUTH_USER_INFO` | Determines whether user profile data is fetched from the `UserInfo` endpoint after authorization. |
|
|
554
|
+
* | `MONOCLOUD_AUTH_REFETCH_USER_INFO` | If `true`, user information is re-fetched on each userinfo request. |
|
|
555
|
+
* | `MONOCLOUD_AUTH_ID_TOKEN_SIGNING_ALG` | Expected signing algorithm for ID tokens (for example, `RS256`). |
|
|
556
|
+
* | `MONOCLOUD_AUTH_FILTERED_ID_TOKEN_CLAIMS` | Space-separated list of ID token claims excluded from the session object. |
|
|
557
|
+
*
|
|
558
|
+
* ### Routes
|
|
559
|
+
*
|
|
560
|
+
* | Environment Variable | Description |
|
|
561
|
+
* |----------------------|-------------|
|
|
562
|
+
* | `MONOCLOUD_AUTH_CALLBACK_URL` | Application path where the authorization server redirects the user after authentication. |
|
|
563
|
+
* | `MONOCLOUD_AUTH_SIGNIN_URL` | Internal route used to initiate the sign-in flow. |
|
|
564
|
+
* | `MONOCLOUD_AUTH_SIGNOUT_URL` | Internal route used to initiate the sign-out flow. |
|
|
565
|
+
* | `MONOCLOUD_AUTH_USER_INFO_URL` | Route that exposes the authenticated user’s profile retrieved from the UserInfo endpoint. |
|
|
566
|
+
*
|
|
567
|
+
* ### Session Cookie Settings
|
|
568
|
+
*
|
|
569
|
+
* | Environment Variable | Description |
|
|
570
|
+
* |----------------------|-------------|
|
|
571
|
+
* | `MONOCLOUD_AUTH_SESSION_COOKIE_NAME` | Name of the cookie used to store the authenticated user session. |
|
|
572
|
+
* | `MONOCLOUD_AUTH_SESSION_COOKIE_PATH` | Path scope for which the session cookie is valid. |
|
|
573
|
+
* | `MONOCLOUD_AUTH_SESSION_COOKIE_DOMAIN` | Domain scope for which the session cookie is valid. |
|
|
574
|
+
* | `MONOCLOUD_AUTH_SESSION_COOKIE_HTTP_ONLY` | Prevents client-side scripts from accessing the session cookie. |
|
|
575
|
+
* | `MONOCLOUD_AUTH_SESSION_COOKIE_SECURE` | Ensures the session cookie is only sent over HTTPS connections. |
|
|
576
|
+
* | `MONOCLOUD_AUTH_SESSION_COOKIE_SAME_SITE` | SameSite policy applied to the session cookie (`lax`, `strict`, or `none`). |
|
|
577
|
+
* | `MONOCLOUD_AUTH_SESSION_COOKIE_PERSISTENT` | Determines whether the session cookie persists across browser restarts. |
|
|
578
|
+
* | `MONOCLOUD_AUTH_SESSION_SLIDING` | Enables sliding session expiration instead of absolute expiration. |
|
|
579
|
+
* | `MONOCLOUD_AUTH_SESSION_DURATION` | Session lifetime in seconds. |
|
|
580
|
+
* | `MONOCLOUD_AUTH_SESSION_MAX_DURATION` | Maximum allowed lifetime of a sliding session in seconds. |
|
|
581
|
+
*
|
|
582
|
+
* ### State Cookie Settings
|
|
583
|
+
*
|
|
584
|
+
* | Environment Variable | Description |
|
|
585
|
+
* |----------------------|-------------|
|
|
586
|
+
* | `MONOCLOUD_AUTH_STATE_COOKIE_NAME` | Name of the cookie used to store OpenID Connect state and nonce values during authentication. |
|
|
587
|
+
* | `MONOCLOUD_AUTH_STATE_COOKIE_PATH` | Path scope for which the state cookie is valid. |
|
|
588
|
+
* | `MONOCLOUD_AUTH_STATE_COOKIE_DOMAIN` | Domain scope for which the state cookie is valid. |
|
|
589
|
+
* | `MONOCLOUD_AUTH_STATE_COOKIE_SECURE` | Ensures the state cookie is only sent over HTTPS connections. |
|
|
590
|
+
* | `MONOCLOUD_AUTH_STATE_COOKIE_SAME_SITE` | SameSite policy applied to the state cookie (`lax`, `strict`, or `none`). |
|
|
591
|
+
* | `MONOCLOUD_AUTH_STATE_COOKIE_PERSISTENT` | Determines whether the state cookie persists beyond the current browser session. |
|
|
592
|
+
*
|
|
593
|
+
* ### Caching
|
|
594
|
+
*
|
|
595
|
+
* | Environment Variable | Description |
|
|
596
|
+
* |----------------------|-------------|
|
|
597
|
+
* | `MONOCLOUD_AUTH_JWKS_CACHE_DURATION` | Duration (in seconds) to cache the JSON Web Key Set (JWKS) used to verify tokens. |
|
|
598
|
+
* | `MONOCLOUD_AUTH_METADATA_CACHE_DURATION` | Duration (in seconds) to cache the OpenID Connect discovery metadata. |
|
|
599
|
+
*
|
|
600
|
+
* @category Types
|
|
1233
601
|
*/
|
|
1234
|
-
|
|
602
|
+
interface MonoCloudOptions extends Partial<Omit<MonoCloudOptionsBase, 'defaultAuthParams' | 'session' | 'routes' | 'state'>> {
|
|
1235
603
|
/**
|
|
1236
|
-
* Default authorization parameters
|
|
604
|
+
* Default authorization parameters automatically included in authentication requests unless explicitly overridden.
|
|
605
|
+
*
|
|
1237
606
|
* @defaultValue {
|
|
1238
607
|
* scope: 'openid email profile',
|
|
1239
608
|
* response_type: 'code'
|
|
1240
609
|
* }
|
|
1241
610
|
*/
|
|
1242
|
-
defaultAuthParams?:
|
|
611
|
+
defaultAuthParams?: AuthorizationParams$1;
|
|
612
|
+
/**
|
|
613
|
+
* Overrides for built-in authentication route paths.
|
|
614
|
+
*/
|
|
615
|
+
routes?: Partial<MonoCloudRoutes>;
|
|
1243
616
|
/**
|
|
1244
|
-
*
|
|
617
|
+
* Session configuration overrides.
|
|
1245
618
|
*/
|
|
1246
619
|
session?: MonoCloudSessionOptions;
|
|
1247
|
-
|
|
620
|
+
/**
|
|
621
|
+
* Configuration for authentication state handling.
|
|
622
|
+
*/
|
|
623
|
+
state?: MonoCloudStatePartialOptions;
|
|
624
|
+
}
|
|
1248
625
|
/**
|
|
1249
|
-
*
|
|
1250
|
-
*
|
|
626
|
+
* Callback invoked when a back-channel logout event is received from the authorization server.
|
|
627
|
+
*
|
|
628
|
+
* Back-channel logout allows MonoCloud to notify the application that a user session should be terminated without browser interaction.
|
|
629
|
+
*
|
|
630
|
+
* @category Types (Handler)
|
|
1251
631
|
*
|
|
1252
|
-
* @param sub
|
|
1253
|
-
* @param sid
|
|
1254
|
-
* @returns
|
|
632
|
+
* @param sub Optional subject identifier (`sub`) of the user associated with the logout event.
|
|
633
|
+
* @param sid Optional session identifier (`sid`) for the session being terminated.
|
|
634
|
+
* @returns Returns a promise or void. Execution completes once logout handling finishes.
|
|
1255
635
|
*/
|
|
1256
636
|
type OnBackChannelLogout = (
|
|
1257
637
|
/**
|
|
1258
|
-
*
|
|
638
|
+
* Subject identifier of the user.
|
|
1259
639
|
*/
|
|
1260
|
-
|
|
1261
640
|
sub?: string,
|
|
1262
641
|
/**
|
|
1263
|
-
*
|
|
642
|
+
* Session identifier associated with the logout event.
|
|
1264
643
|
*/
|
|
1265
|
-
|
|
1266
644
|
sid?: string) => Promise<void> | void;
|
|
1267
645
|
/**
|
|
1268
|
-
*
|
|
646
|
+
* Represents custom application state associated with an authentication request.
|
|
647
|
+
*
|
|
648
|
+
* 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).
|
|
649
|
+
*
|
|
650
|
+
* @category Types
|
|
1269
651
|
*/
|
|
1270
|
-
|
|
652
|
+
interface ApplicationState extends Record<string, any> {}
|
|
1271
653
|
/**
|
|
1272
|
-
*
|
|
1273
|
-
*
|
|
1274
|
-
*
|
|
1275
|
-
*
|
|
1276
|
-
*
|
|
1277
|
-
*
|
|
1278
|
-
*
|
|
1279
|
-
*
|
|
1280
|
-
*
|
|
1281
|
-
* @
|
|
654
|
+
* Callback invoked before a session is created or updated.
|
|
655
|
+
*
|
|
656
|
+
* 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.
|
|
657
|
+
*
|
|
658
|
+
* Common use cases include:
|
|
659
|
+
* - Adding custom properties to the session
|
|
660
|
+
* - Mapping or filtering claims
|
|
661
|
+
* - Attaching tenant or application-specific metadata
|
|
662
|
+
*
|
|
663
|
+
* @category Types (Handler)
|
|
664
|
+
*
|
|
665
|
+
* @param session The session being created or updated. Changes made to this object are persisted.
|
|
666
|
+
* @param idToken Optional claims extracted from the ID token.
|
|
667
|
+
* @param userInfo Optional claims returned from the `UserInfo` endpoint.
|
|
668
|
+
* @param state Optional application state created during the authentication request.
|
|
669
|
+
* @returns Returns a promise or void. Execution continues once the callback completes.
|
|
1282
670
|
*/
|
|
1283
671
|
type OnSessionCreating = (
|
|
1284
672
|
/**
|
|
1285
|
-
* The
|
|
673
|
+
* The session being created or updated.
|
|
1286
674
|
*/
|
|
1287
|
-
|
|
1288
675
|
session: MonoCloudSession$1,
|
|
1289
676
|
/**
|
|
1290
|
-
* Optional
|
|
677
|
+
* Optional claims extracted from the ID token.
|
|
1291
678
|
*/
|
|
1292
|
-
|
|
1293
679
|
idToken?: Partial<IdTokenClaims$1>,
|
|
1294
680
|
/**
|
|
1295
|
-
* Optional
|
|
681
|
+
* Optional claims returned from the `UserInfo` endpoint.
|
|
1296
682
|
*/
|
|
1297
|
-
|
|
1298
683
|
userInfo?: UserinfoResponse$1,
|
|
1299
684
|
/**
|
|
1300
|
-
* Optional
|
|
685
|
+
* Optional application state associated with the authentication flow.
|
|
1301
686
|
*/
|
|
1302
|
-
|
|
1303
687
|
state?: ApplicationState) => Promise<void> | void;
|
|
1304
688
|
/**
|
|
1305
|
-
*
|
|
1306
|
-
*
|
|
689
|
+
* Callback invoked when the authentication state is being created before redirecting the user to the authorization server.
|
|
690
|
+
*
|
|
691
|
+
* 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.
|
|
692
|
+
*
|
|
693
|
+
* The returned value is stored securely and later provided during session creation.
|
|
1307
694
|
*
|
|
1308
|
-
*
|
|
1309
|
-
*
|
|
695
|
+
* Common use cases include:
|
|
696
|
+
* - Preserving return URLs or navigation context
|
|
697
|
+
* - Passing tenant or organization identifiers
|
|
698
|
+
* - Storing temporary workflow state across authentication
|
|
699
|
+
*
|
|
700
|
+
* @category Types (Handler)
|
|
701
|
+
*
|
|
702
|
+
* @param req The incoming request initiating authentication.
|
|
703
|
+
* @returns Returns an application state object, either synchronously or as a Promise.
|
|
1310
704
|
*/
|
|
1311
705
|
type OnSetApplicationState = (
|
|
1312
706
|
/**
|
|
1313
|
-
* The incoming request.
|
|
707
|
+
* The incoming request initiating authentication.
|
|
1314
708
|
*/
|
|
1315
|
-
|
|
1316
709
|
req: MonoCloudRequest) => Promise<ApplicationState> | ApplicationState;
|
|
1317
710
|
/**
|
|
1318
|
-
* Represents the
|
|
711
|
+
* Represents the token set associated with the currently authenticated user.
|
|
712
|
+
*
|
|
713
|
+
* This object extends {@link AccessToken} and includes additional tokens issued during authentication, along with convenience metadata used by the SDK to indicate token validity.
|
|
714
|
+
*
|
|
715
|
+
* @category Types
|
|
1319
716
|
*/
|
|
1320
717
|
interface MonoCloudTokens extends AccessToken$1 {
|
|
1321
718
|
/**
|
|
1322
|
-
* The ID token
|
|
719
|
+
* The ID token issued during authentication. Contains identity claims about the authenticated user.
|
|
1323
720
|
*/
|
|
1324
721
|
idToken?: string;
|
|
1325
722
|
/**
|
|
1326
|
-
* The refresh token
|
|
723
|
+
* The refresh token used to obtain new access tokens without requiring the user to re-authenticate.
|
|
1327
724
|
*/
|
|
1328
725
|
refreshToken?: string;
|
|
1329
726
|
/**
|
|
1330
|
-
*
|
|
727
|
+
* Indicates whether the current access token is expired at the time of evaluation.
|
|
1331
728
|
*/
|
|
1332
729
|
isExpired: boolean;
|
|
1333
730
|
}
|
|
1334
731
|
/**
|
|
1335
|
-
*
|
|
732
|
+
* Defines a callback invoked when an unexpected error occurs during execution of authentication endpoints such as sign-in, callback, sign-out, or userinfo.
|
|
733
|
+
*
|
|
734
|
+
* This handler allows applications to log, transform, or respond to errors before the SDK applies its default error handling behavior.
|
|
1336
735
|
*
|
|
1337
|
-
* @
|
|
736
|
+
* @category Types (Handler)
|
|
737
|
+
*
|
|
738
|
+
* @param error - The error thrown during endpoint execution.
|
|
1338
739
|
*/
|
|
1339
740
|
type OnError = (error: Error) => Promise<any> | any;
|
|
1340
741
|
/**
|
|
1341
|
-
*
|
|
742
|
+
* Options used to customize the sign-in flow.
|
|
743
|
+
*
|
|
744
|
+
* @category Types
|
|
1342
745
|
*/
|
|
1343
746
|
interface SignInOptions {
|
|
1344
747
|
/**
|
|
1345
|
-
*
|
|
1346
|
-
*
|
|
1347
|
-
*
|
|
748
|
+
* Relative URL to redirect the user to after successful authentication.
|
|
749
|
+
*
|
|
750
|
+
* If not provided, the application base URL (`appUrl`) is used.
|
|
1348
751
|
*/
|
|
1349
752
|
returnUrl?: string;
|
|
1350
753
|
/**
|
|
1351
|
-
*
|
|
754
|
+
* When `true`, initiates the user registration (sign-up) flow instead of a standard sign-in.
|
|
1352
755
|
*/
|
|
1353
756
|
register?: boolean;
|
|
1354
757
|
/**
|
|
1355
|
-
* Additional authorization parameters
|
|
758
|
+
* Additional authorization parameters merged into the authentication request.
|
|
1356
759
|
*/
|
|
1357
760
|
authParams?: AuthorizationParams$1;
|
|
1358
761
|
/**
|
|
1359
|
-
*
|
|
762
|
+
* Callback invoked if an unexpected error occurs during the sign-in flow.
|
|
1360
763
|
*/
|
|
1361
764
|
onError?: OnError;
|
|
1362
765
|
}
|
|
1363
766
|
/**
|
|
1364
|
-
*
|
|
767
|
+
* Options used to customize callback processing after authentication.
|
|
768
|
+
*
|
|
769
|
+
* @category Types
|
|
1365
770
|
*/
|
|
1366
771
|
interface CallbackOptions {
|
|
1367
772
|
/**
|
|
1368
|
-
*
|
|
773
|
+
* When `true`, fetches user profile data from the `UserInfo` endpoint after the authorization code exchange completes.
|
|
1369
774
|
*/
|
|
1370
775
|
userInfo?: boolean;
|
|
1371
776
|
/**
|
|
1372
|
-
*
|
|
777
|
+
* Redirect URI sent to the token endpoint during the authorization code exchange.
|
|
778
|
+
*
|
|
779
|
+
* > This must match the redirect URI used during the sign-in request.
|
|
1373
780
|
*/
|
|
1374
781
|
redirectUri?: string;
|
|
1375
782
|
/**
|
|
1376
|
-
*
|
|
783
|
+
* Callback invoked if an unexpected error occurs while processing the authentication callback.
|
|
1377
784
|
*/
|
|
1378
785
|
onError?: OnError;
|
|
1379
786
|
}
|
|
1380
787
|
/**
|
|
1381
|
-
*
|
|
788
|
+
* Options used to customize the behavior of the userinfo handler.
|
|
789
|
+
*
|
|
790
|
+
* @category Types
|
|
1382
791
|
*/
|
|
1383
792
|
interface UserInfoOptions {
|
|
1384
793
|
/**
|
|
1385
|
-
*
|
|
794
|
+
* When `true`, forces user profile data to be re-fetched from the authentication service instead of using cached session data.
|
|
1386
795
|
*/
|
|
1387
796
|
refresh?: boolean;
|
|
1388
797
|
/**
|
|
1389
|
-
*
|
|
798
|
+
* Callback invoked if an unexpected error occurs while retrieving user information.
|
|
1390
799
|
*/
|
|
1391
800
|
onError?: OnError;
|
|
1392
801
|
}
|
|
1393
802
|
/**
|
|
1394
|
-
*
|
|
803
|
+
* Options used to customize the behavior of the sign-out handler.
|
|
804
|
+
*
|
|
805
|
+
* @category Types
|
|
1395
806
|
*/
|
|
1396
|
-
|
|
807
|
+
interface SignOutOptions extends EndSessionParameters$1 {
|
|
1397
808
|
/**
|
|
1398
|
-
*
|
|
809
|
+
* When `true`, also signs the user out of the MonoCloud session (Single Sign-Out) in addition to the local application session.
|
|
1399
810
|
*/
|
|
1400
811
|
federatedSignOut?: boolean;
|
|
1401
812
|
/**
|
|
1402
|
-
*
|
|
813
|
+
* Callback invoked if an unexpected error occurs during the sign-out flow.
|
|
1403
814
|
*/
|
|
1404
815
|
onError?: OnError;
|
|
1405
|
-
}
|
|
816
|
+
}
|
|
1406
817
|
/**
|
|
1407
|
-
*
|
|
818
|
+
* Options used to control token retrieval and refresh behavior when calling `getTokens()`.
|
|
819
|
+
*
|
|
820
|
+
* @category Types
|
|
1408
821
|
*/
|
|
1409
822
|
interface GetTokensOptions extends RefreshGrantOptions$1 {
|
|
1410
823
|
/**
|
|
1411
|
-
*
|
|
824
|
+
* When `true`, forces a refresh of the access token even if the current token has not expired.
|
|
1412
825
|
*/
|
|
1413
826
|
forceRefresh?: boolean;
|
|
1414
827
|
/**
|
|
1415
|
-
*
|
|
828
|
+
* When enabled, refetches user information from the `UserInfo` endpoint after tokens are refreshed.
|
|
1416
829
|
*/
|
|
1417
830
|
refetchUserInfo?: boolean;
|
|
1418
831
|
}
|
|
1419
832
|
//#endregion
|
|
1420
833
|
//#region src/monocloud-node-core-client.d.ts
|
|
834
|
+
/**
|
|
835
|
+
* @category Classes
|
|
836
|
+
*/
|
|
1421
837
|
declare class MonoCloudCoreClient {
|
|
1422
|
-
readonly oidcClient: MonoCloudOidcClient
|
|
838
|
+
readonly oidcClient: MonoCloudOidcClient;
|
|
1423
839
|
private readonly options;
|
|
1424
840
|
private readonly stateService;
|
|
1425
841
|
private readonly sessionService;
|
|
@@ -1430,7 +846,7 @@ declare class MonoCloudCoreClient {
|
|
|
1430
846
|
* Initiates the sign-in flow by redirecting the user to the MonoCloud authorization endpoint.
|
|
1431
847
|
*
|
|
1432
848
|
* This method handles scope and resource merging, state generation (nonce, state, PKCE),
|
|
1433
|
-
* and
|
|
849
|
+
* and constructing the final authorization URL.
|
|
1434
850
|
*
|
|
1435
851
|
* @param request - MonoCloud request object.
|
|
1436
852
|
* @param response - MonoCloud response object.
|
|
@@ -1551,7 +967,7 @@ declare class MonoCloudCoreClient {
|
|
|
1551
967
|
* @param response - MonoCloud cookie response object.
|
|
1552
968
|
* @param options - Configuration for token retrieval (force refresh, specific scopes/resources).
|
|
1553
969
|
*
|
|
1554
|
-
* @returns Fetched tokens
|
|
970
|
+
* @returns Fetched tokens.
|
|
1555
971
|
*
|
|
1556
972
|
* @throws {@link MonoCloudValidationError} If the session does not exist or tokens cannot be found/refreshed.
|
|
1557
973
|
*/
|
|
@@ -1561,5 +977,5 @@ declare class MonoCloudCoreClient {
|
|
|
1561
977
|
private validateOptions;
|
|
1562
978
|
}
|
|
1563
979
|
//#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
|
|
980
|
+
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
981
|
//# sourceMappingURL=index.d.mts.map
|