@omnibase/core-js 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.
@@ -1,105 +1,459 @@
1
1
  import { LoginFlow as LoginFlow$1, RecoveryFlow as RecoveryFlow$1, VerificationFlow as VerificationFlow$1, RegistrationFlow as RegistrationFlow$1, SettingsFlow as SettingsFlow$1, LogoutFlow as LogoutFlow$1, SessionAuthenticationMethod, AuthenticatorAssuranceLevel, SessionDevice, Identity } from '@ory/client-fetch';
2
2
 
3
+ /**
4
+ * Union type representing all possible authentication flow types
5
+ *
6
+ * This type encompasses all self-service authentication flows supported by Ory Kratos.
7
+ * Each flow type has its own specific structure and validation rules, but they all
8
+ * follow the same general pattern of initialization, form rendering, and submission.
9
+ *
10
+ * @example
11
+ * Type guard for flow identification:
12
+ * ```typescript
13
+ * function isLoginFlow(flow: FlowType): flow is LoginFlow {
14
+ * return flow.type === 'login';
15
+ * }
16
+ *
17
+ * function handleFlow(flow: FlowType) {
18
+ * if (isLoginFlow(flow)) {
19
+ * // Handle login-specific logic
20
+ * console.log('Processing login flow:', flow.id);
21
+ * }
22
+ * }
23
+ * ```
24
+ *
25
+ * @example
26
+ * Generic flow processing:
27
+ * ```typescript
28
+ * function processFlowUI(flow: FlowType) {
29
+ * return flow.ui.nodes.map(node => ({
30
+ * name: node.attributes.name,
31
+ * type: node.type,
32
+ * required: node.attributes.required || false
33
+ * }));
34
+ * }
35
+ * ```
36
+ *
37
+ * @since 0.1.0
38
+ * @public
39
+ */
3
40
  type FlowType = LoginFlow | RecoveryFlow | VerificationFlow | RegistrationFlow | SettingsFlow;
4
41
  /**
5
- * Logout Flow - Flow Type that Ensures that the session is terminated in the Auth server
42
+ * Logout flow for terminating user sessions
43
+ *
44
+ * The logout flow ensures that user sessions are properly terminated on the
45
+ * authentication server. This flow handles both cookie-based and token-based
46
+ * session termination, providing secure logout functionality across different
47
+ * authentication methods.
48
+ *
49
+ * @example
50
+ * Initiating logout flow:
51
+ * ```typescript
52
+ * // Browser-based logout
53
+ * window.location.href = logoutFlow.logout_url;
54
+ *
55
+ * // Or for SPA/API-based logout
56
+ * await fetch(logoutFlow.logout_url, {
57
+ * method: 'GET',
58
+ * credentials: 'include'
59
+ * });
60
+ * ```
61
+ *
62
+ * @since 0.1.0
63
+ * @public
6
64
  */
7
65
  type LogoutFlow = LogoutFlow$1;
8
66
  /**
9
- * This object represents a login flow. A login flow is initiated at the "Initiate Login API / Browser Flow" endpoint by a client.
67
+ * Login flow for user authentication
68
+ *
69
+ * Represents a complete login flow initiated through Ory Kratos. This flow handles
70
+ * various authentication methods including password-based login, social providers,
71
+ * and multi-factor authentication. The flow contains all necessary UI elements
72
+ * and validation rules for rendering secure login forms.
73
+ *
74
+ * Key properties:
75
+ * - `ui`: Contains form nodes with input fields, buttons, and validation messages
76
+ * - `oauth2_login_challenge`: OAuth2 challenge for federated login scenarios
77
+ * - `refresh`: Indicates if this is a forced re-authentication
78
+ * - `request_url`: Original URL that initiated the flow
79
+ *
80
+ * @example
81
+ * Processing login form:
82
+ * ```typescript
83
+ * function renderLoginForm(flow: LoginFlow) {
84
+ * const emailField = flow.ui.nodes.find(
85
+ * node => node.attributes.name === 'identifier'
86
+ * );
87
+ * const passwordField = flow.ui.nodes.find(
88
+ * node => node.attributes.name === 'password'
89
+ * );
90
+ *
91
+ * // Render form with these fields
92
+ * return {
93
+ * action: flow.ui.action,
94
+ * method: flow.ui.method,
95
+ * fields: [emailField, passwordField]
96
+ * };
97
+ * }
98
+ * ```
10
99
  *
11
- * Once a login flow is completed successfully, a session cookie or session token will be issued.
100
+ * @example
101
+ * Handling social login:
102
+ * ```typescript
103
+ * function getSocialProviders(flow: LoginFlow) {
104
+ * return flow.ui.nodes
105
+ * .filter(node => node.group === 'oidc')
106
+ * .map(node => ({
107
+ * provider: node.attributes.value,
108
+ * name: node.meta?.label?.text || 'Unknown Provider'
109
+ * }));
110
+ * }
111
+ * ```
112
+ *
113
+ * @since 0.1.0
114
+ * @public
12
115
  */
13
116
  type LoginFlow = LoginFlow$1;
14
117
  /**
15
- * This flow is used when an identity wants to recover their account.
118
+ * Account recovery flow for password reset and account recovery
119
+ *
120
+ * This flow enables users to recover their accounts through various recovery
121
+ * methods such as email-based password reset or account unlock procedures.
122
+ * The recovery process is typically initiated when a user cannot access their
123
+ * account due to forgotten credentials or account lockout.
124
+ *
125
+ * @example
126
+ * Initiating account recovery:
127
+ * ```typescript
128
+ * function handleRecovery(flow: RecoveryFlow) {
129
+ * const emailField = flow.ui.nodes.find(
130
+ * node => node.attributes.name === 'email'
131
+ * );
132
+ *
133
+ * if (emailField) {
134
+ * // Render email input for recovery
135
+ * return {
136
+ * action: flow.ui.action,
137
+ * method: flow.ui.method,
138
+ * placeholder: 'Enter your email address'
139
+ * };
140
+ * }
141
+ * }
142
+ * ```
143
+ *
144
+ * @since 0.1.0
145
+ * @public
16
146
  */
17
147
  type RecoveryFlow = RecoveryFlow$1;
18
148
  /**
19
- * Used to verify an out-of-band communication channel such as an email address or a phone number.
149
+ * Verification flow for validating communication channels
150
+ *
151
+ * Used to verify out-of-band communication channels such as email addresses
152
+ * or phone numbers. This flow ensures that users have access to the contact
153
+ * methods they've provided, which is essential for account security and
154
+ * communication delivery.
155
+ *
156
+ * @example
157
+ * Email verification handling:
158
+ * ```typescript
159
+ * function handleEmailVerification(flow: VerificationFlow) {
160
+ * if (flow.state === 'sent_email') {
161
+ * return {
162
+ * message: 'Verification email sent. Please check your inbox.',
163
+ * canResend: true
164
+ * };
165
+ * }
166
+ *
167
+ * if (flow.state === 'passed_challenge') {
168
+ * return {
169
+ * message: 'Email verified successfully!',
170
+ * redirect: '/dashboard'
171
+ * };
172
+ * }
173
+ * }
174
+ * ```
175
+ *
176
+ * @since 0.1.0
177
+ * @public
20
178
  */
21
179
  type VerificationFlow = VerificationFlow$1;
22
180
  /**
23
- * Used when a user is registering an account
181
+ * Registration flow for new user account creation
182
+ *
183
+ * Handles the complete user registration process including identity validation,
184
+ * password requirements, and any custom registration fields defined in the
185
+ * identity schema. The registration flow can include email verification,
186
+ * terms acceptance, and integration with external identity providers.
187
+ *
188
+ * @example
189
+ * Processing registration form:
190
+ * ```typescript
191
+ * function buildRegistrationForm(flow: RegistrationFlow) {
192
+ * const passwordNode = flow.ui.nodes.find(
193
+ * node => node.attributes.name === 'password'
194
+ * );
195
+ *
196
+ * const requirements = passwordNode?.messages?.map(msg => msg.text) || [];
197
+ *
198
+ * return {
199
+ * action: flow.ui.action,
200
+ * method: flow.ui.method,
201
+ * passwordRequirements: requirements,
202
+ * hasTerms: flow.ui.nodes.some(node => node.attributes.name === 'terms')
203
+ * };
204
+ * }
205
+ * ```
206
+ *
207
+ * @example
208
+ * Handling registration validation:
209
+ * ```typescript
210
+ * function getRegistrationErrors(flow: RegistrationFlow) {
211
+ * return flow.ui.nodes.reduce((errors, node) => {
212
+ * if (node.messages && node.messages.length > 0) {
213
+ * errors[node.attributes.name] = node.messages[0].text;
214
+ * }
215
+ * return errors;
216
+ * }, {} as Record<string, string>);
217
+ * }
218
+ * ```
219
+ *
220
+ * @since 0.1.0
221
+ * @public
24
222
  */
25
223
  type RegistrationFlow = RegistrationFlow$1;
26
224
  /**
27
- * This flow is used when an identity wants to update settings (e.g. profile data, passwords, ...) in a selfservice manner.
225
+ * Settings flow for user profile and account management
226
+ *
227
+ * This flow enables users to update their account settings in a self-service manner.
228
+ * It supports updating profile information, changing passwords, managing two-factor
229
+ * authentication, updating email addresses, and other account-related settings.
230
+ * The flow enforces proper validation and security measures for sensitive changes.
231
+ *
232
+ * @example
233
+ * Profile update handling:
234
+ * ```typescript
235
+ * function handleProfileSettings(flow: SettingsFlow) {
236
+ * const profileFields = flow.ui.nodes
237
+ * .filter(node => node.group === 'profile')
238
+ * .map(node => ({
239
+ * name: node.attributes.name,
240
+ * value: node.attributes.value,
241
+ * type: node.attributes.type,
242
+ * required: node.attributes.required
243
+ * }));
244
+ *
245
+ * return {
246
+ * action: flow.ui.action,
247
+ * method: flow.ui.method,
248
+ * fields: profileFields
249
+ * };
250
+ * }
251
+ * ```
252
+ *
253
+ * @example
254
+ * Password change flow:
255
+ * ```typescript
256
+ * function handlePasswordChange(flow: SettingsFlow) {
257
+ * const passwordNodes = flow.ui.nodes.filter(
258
+ * node => node.group === 'password'
259
+ * );
260
+ *
261
+ * return passwordNodes.map(node => ({
262
+ * name: node.attributes.name,
263
+ * label: node.meta?.label?.text || node.attributes.name,
264
+ * required: node.attributes.required || false
265
+ * }));
266
+ * }
267
+ * ```
268
+ *
269
+ * @since 0.1.0
270
+ * @public
28
271
  */
29
272
  type SettingsFlow = SettingsFlow$1;
30
273
  /**
31
- * A Session
32
- * @export
33
- * @interface Session
274
+ * User session object representing an authenticated user's session state
275
+ *
276
+ * A session contains all information about a user's authentication state,
277
+ * including when they authenticated, what methods were used, device information,
278
+ * and the associated identity. Sessions have expiration times and can be
279
+ * invalidated when users log out or when security policies require it.
280
+ *
281
+ * Sessions are central to maintaining authentication state across requests
282
+ * and provide the foundation for authorization decisions throughout your
283
+ * application.
284
+ *
285
+ * @example
286
+ * Checking session validity:
287
+ * ```typescript
288
+ * function isSessionValid(session: Session): boolean {
289
+ * if (!session.active) {
290
+ * return false;
291
+ * }
292
+ *
293
+ * if (session.expires_at && new Date(session.expires_at) < new Date()) {
294
+ * return false;
295
+ * }
296
+ *
297
+ * return true;
298
+ * }
299
+ * ```
300
+ *
301
+ * @example
302
+ * Extracting user information:
303
+ * ```typescript
304
+ * function getUserInfo(session: Session) {
305
+ * return {
306
+ * id: session.identity?.id,
307
+ * email: session.identity?.traits?.email,
308
+ * name: session.identity?.traits?.name,
309
+ * isVerified: session.identity?.verifiable_addresses?.some(
310
+ * addr => addr.verified
311
+ * ) || false
312
+ * };
313
+ * }
314
+ * ```
315
+ *
316
+ * @example
317
+ * Session security analysis:
318
+ * ```typescript
319
+ * function analyzeSessionSecurity(session: Session) {
320
+ * const authMethods = session.authentication_methods || [];
321
+ * const hasMFA = authMethods.length > 1;
322
+ * const recentAuth = session.authenticated_at &&
323
+ * new Date(session.authenticated_at) > new Date(Date.now() - 3600000); // 1 hour
324
+ *
325
+ * return {
326
+ * hasMFA,
327
+ * recentAuth,
328
+ * assuranceLevel: session.authenticator_assurance_level,
329
+ * deviceCount: session.devices?.length || 0
330
+ * };
331
+ * }
332
+ * ```
333
+ *
334
+ * @since 0.1.0
335
+ * @public
34
336
  */
35
337
  type Session = {
36
338
  /**
37
- * Active state. If false the session is no longer active.
38
- * @type {boolean}
39
- * @memberof Session
339
+ * Session active state
340
+ *
341
+ * Indicates whether the session is currently active and valid for
342
+ * authentication purposes. When false, the session should be treated
343
+ * as invalid regardless of expiration time.
344
+ *
345
+ * @defaultValue true
40
346
  */
41
347
  active?: boolean;
42
348
  /**
43
- * The Session Authentication Timestamp
349
+ * Session authentication timestamp
44
350
  *
45
- * When this session was authenticated at. If multi-factor authentication was used this
46
- * is the time when the last factor was authenticated (e.g. the TOTP code challenge was completed).
47
- * @type {Date}
48
- * @memberof Session
351
+ * The exact time when this session was authenticated. For multi-factor
352
+ * authentication scenarios, this represents when the last factor was
353
+ * successfully verified (e.g., TOTP code completion, biometric verification).
354
+ *
355
+ * This timestamp is crucial for implementing security policies that require
356
+ * recent authentication for sensitive operations.
49
357
  */
50
358
  authenticated_at?: Date;
51
359
  /**
52
- * A list of authenticators which were used to authenticate the session.
53
- * @type {Array<SessionAuthenticationMethod>}
54
- * @memberof Session
360
+ * Authentication methods used for this session
361
+ *
362
+ * A comprehensive list of all authentication methods used to establish
363
+ * this session. This includes passwords, social logins, multi-factor
364
+ * authentication tokens, and any other verification methods.
365
+ *
366
+ * Useful for implementing step-up authentication or authorization decisions
367
+ * based on authentication strength.
55
368
  */
56
369
  authentication_methods?: Array<SessionAuthenticationMethod>;
57
370
  /**
371
+ * Authenticator assurance level
372
+ *
373
+ * Indicates the confidence level in the user's identity based on the
374
+ * authentication methods used. Higher assurance levels typically require
375
+ * multiple factors or stronger authentication methods.
58
376
  *
59
- * @type {AuthenticatorAssuranceLevel}
60
- * @memberof Session
377
+ * Common levels:
378
+ * - `aal1`: Single-factor authentication (password, social login)
379
+ * - `aal2`: Multi-factor authentication (password + TOTP, biometrics)
61
380
  */
62
381
  authenticator_assurance_level?: AuthenticatorAssuranceLevel;
63
382
  /**
64
- * Devices has history of all endpoints where the session was used
65
- * @type {Array<SessionDevice>}
66
- * @memberof Session
383
+ * Session device history
384
+ *
385
+ * Complete history of all devices and endpoints where this session
386
+ * has been used. This information is valuable for security monitoring,
387
+ * anomaly detection, and providing users with visibility into their
388
+ * account access patterns.
389
+ *
390
+ * Each device entry includes IP address, user agent, location data,
391
+ * and timestamp information for comprehensive session tracking.
67
392
  */
68
393
  devices?: Array<SessionDevice>;
69
394
  /**
70
- * The Session Expiry
395
+ * Session expiration timestamp
396
+ *
397
+ * The exact time when this session expires and becomes invalid.
398
+ * After this time, the session should not be accepted for authentication
399
+ * and the user should be required to log in again.
71
400
  *
72
- * When this session expires at.
73
- * @type {Date}
74
- * @memberof Session
401
+ * Session expiration can be extended through refresh tokens or
402
+ * re-authentication flows depending on your application's security policy.
75
403
  */
76
404
  expires_at?: Date;
77
405
  /**
78
- * Session ID
79
- * @type {string}
80
- * @memberof Session
406
+ * Unique session identifier
407
+ *
408
+ * A unique identifier for this session that can be used for session
409
+ * management operations such as invalidation, refresh, or audit logging.
410
+ * This ID is typically used in session storage and tracking systems.
81
411
  */
82
412
  id: string;
83
413
  /**
414
+ * Associated user identity
415
+ *
416
+ * The complete identity object of the authenticated user, containing
417
+ * all user profile information, traits, verifiable addresses, and
418
+ * recovery addresses. This is the primary source of user information
419
+ * for the session.
84
420
  *
85
- * @type {Identity}
86
- * @memberof Session
421
+ * The identity structure is defined by your identity schema and may
422
+ * include custom fields specific to your application's user model.
87
423
  */
88
424
  identity?: Identity;
89
425
  /**
90
- * The Session Issuance Timestamp
426
+ * Session issuance timestamp
91
427
  *
92
- * When this session was issued at. Usually equal or close to `authenticated_at`.
93
- * @type {Date}
94
- * @memberof Session
428
+ * The time when this session was initially created and issued.
429
+ * This is typically equal to or very close to `authenticated_at`,
430
+ * but may differ in cases where session creation and authentication
431
+ * are separate operations.
432
+ *
433
+ * Useful for implementing session age limits and security policies
434
+ * that consider the total session lifetime.
95
435
  */
96
436
  issued_at?: Date;
97
437
  /**
98
- * Tokenized is the tokenized (e.g. JWT) version of the session.
438
+ * Tokenized session representation
439
+ *
440
+ * A tokenized version of the session, typically in JWT format, that
441
+ * can be used for stateless authentication scenarios. This field is
442
+ * only populated when specifically requested through the `tokenize_as`
443
+ * query parameter during session retrieval.
444
+ *
445
+ * The tokenized session contains essential session information in a
446
+ * cryptographically signed format, allowing for distributed authentication
447
+ * without requiring centralized session storage lookups.
99
448
  *
100
- * It is only set when the `tokenize_as` query parameter was set to a valid tokenize template during calls to `/session/whoami`.
101
- * @type {string}
102
- * @memberof Session
449
+ * @example
450
+ * Using tokenized session:
451
+ * ```typescript
452
+ * if (session.tokenized) {
453
+ * // Use JWT token for API authentication
454
+ * localStorage.setItem('auth_token', session.tokenized);
455
+ * }
456
+ * ```
103
457
  */
104
458
  tokenized?: string;
105
459
  };