id.org.ai 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,730 @@
1
+ /**
2
+ * @packageDocumentation
3
+ * @module id.org.ai
4
+ *
5
+ * Identity primitives for schema.org.ai
6
+ *
7
+ * This package provides identity types for humans and AI agents:
8
+ * - {@link Identity} - Base identity interface
9
+ * - {@link User} - Human user identity
10
+ * - {@link AgentIdentity} - AI agent identity
11
+ * - {@link Credential} - Authentication credentials
12
+ * - {@link Session} - Active sessions
13
+ *
14
+ * All types follow JSON-LD conventions with `$id` and `$type` fields.
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * import { createUser, isUser, UserSchema } from 'id.org.ai'
19
+ *
20
+ * const user = createUser({
21
+ * email: 'alice@example.com',
22
+ * name: 'Alice'
23
+ * })
24
+ *
25
+ * // Runtime validation
26
+ * if (isUser(unknownData)) {
27
+ * console.log(unknownData.email)
28
+ * }
29
+ *
30
+ * // Schema validation
31
+ * const result = UserSchema.safeParse(data)
32
+ * ```
33
+ *
34
+ * @version 0.1.0
35
+ */
36
+ import { z } from 'zod';
37
+ /**
38
+ * Identity - Base interface for all identity types
39
+ *
40
+ * Represents a unique identity in the schema.org.ai system. All identity
41
+ * types ({@link User}, {@link AgentIdentity}) extend this base interface.
42
+ *
43
+ * @see https://schema.org.ai/Identity
44
+ *
45
+ * @example
46
+ * ```typescript
47
+ * const identity: Identity = {
48
+ * $id: 'https://schema.org.ai/identities/123',
49
+ * $type: 'https://schema.org.ai/Identity',
50
+ * createdAt: '2024-01-01T00:00:00Z',
51
+ * updatedAt: '2024-01-01T00:00:00Z'
52
+ * }
53
+ * ```
54
+ */
55
+ export interface Identity {
56
+ /** Unique identifier URI (JSON-LD @id) */
57
+ $id: string;
58
+ /** Type discriminator (JSON-LD @type) */
59
+ $type: 'https://schema.org.ai/Identity';
60
+ /** ISO 8601 timestamp when identity was created */
61
+ createdAt: string;
62
+ /** ISO 8601 timestamp when identity was last updated */
63
+ updatedAt: string;
64
+ }
65
+ /**
66
+ * Zod schema for validating Identity objects
67
+ *
68
+ * Use this schema for runtime validation of identity data.
69
+ *
70
+ * @see {@link Identity}
71
+ *
72
+ * @example
73
+ * ```typescript
74
+ * const result = IdentitySchema.safeParse(unknownData)
75
+ * if (result.success) {
76
+ * console.log(result.data.$id)
77
+ * } else {
78
+ * console.error(result.error)
79
+ * }
80
+ * ```
81
+ */
82
+ export declare const IdentitySchema: z.ZodObject<{
83
+ $id: z.ZodString;
84
+ $type: z.ZodLiteral<"https://schema.org.ai/Identity">;
85
+ createdAt: z.ZodString;
86
+ updatedAt: z.ZodString;
87
+ }, "strip", z.ZodTypeAny, {
88
+ $id: string;
89
+ $type: "https://schema.org.ai/Identity";
90
+ createdAt: string;
91
+ updatedAt: string;
92
+ }, {
93
+ $id: string;
94
+ $type: "https://schema.org.ai/Identity";
95
+ createdAt: string;
96
+ updatedAt: string;
97
+ }>;
98
+ /**
99
+ * Type guard to check if an object is a valid Identity
100
+ *
101
+ * Uses Zod schema validation internally to ensure type safety.
102
+ *
103
+ * @param obj - Object to validate
104
+ * @returns True if the object is a valid Identity
105
+ *
106
+ * @example
107
+ * ```typescript
108
+ * const data: unknown = fetchFromAPI()
109
+ * if (isIdentity(data)) {
110
+ * // TypeScript knows data is Identity
111
+ * console.log(data.createdAt)
112
+ * }
113
+ * ```
114
+ */
115
+ export declare function isIdentity(obj: unknown): obj is Identity;
116
+ /**
117
+ * Factory function to create a new Identity
118
+ *
119
+ * Creates a complete Identity object with auto-generated `$id` (if not provided)
120
+ * and timestamps. The `$type` is always set to the correct JSON-LD type.
121
+ *
122
+ * @param input - Optional partial identity data
123
+ * @param input.$id - Custom identifier URI (auto-generated if not provided)
124
+ * @returns A complete Identity object with all required fields
125
+ *
126
+ * @example
127
+ * ```typescript
128
+ * // Auto-generate all fields
129
+ * const identity = createIdentity()
130
+ *
131
+ * // With custom $id
132
+ * const identity = createIdentity({ $id: 'https://example.com/id/custom' })
133
+ * ```
134
+ */
135
+ export declare function createIdentity(input?: {
136
+ $id?: string;
137
+ }): Identity;
138
+ /**
139
+ * User - Human user identity
140
+ *
141
+ * Extends the base {@link Identity} interface with human-specific fields
142
+ * such as email, name, and an optional profile for additional metadata.
143
+ *
144
+ * @see https://schema.org.ai/User
145
+ *
146
+ * @example
147
+ * ```typescript
148
+ * const user: User = {
149
+ * $id: 'https://schema.org.ai/users/123',
150
+ * $type: 'https://schema.org.ai/User',
151
+ * email: 'alice@example.com',
152
+ * name: 'Alice Smith',
153
+ * profile: { avatar: 'https://example.com/avatar.png' },
154
+ * createdAt: '2024-01-01T00:00:00Z',
155
+ * updatedAt: '2024-01-01T00:00:00Z'
156
+ * }
157
+ * ```
158
+ */
159
+ export interface User extends Omit<Identity, '$type'> {
160
+ /** Type discriminator for User (JSON-LD @type) */
161
+ $type: 'https://schema.org.ai/User';
162
+ /** User's email address (must be valid email format) */
163
+ email: string;
164
+ /** User's display name */
165
+ name: string;
166
+ /** Optional profile data for additional user information */
167
+ profile?: Record<string, unknown>;
168
+ }
169
+ /**
170
+ * Zod schema for validating User objects
171
+ *
172
+ * Validates all User fields including email format validation.
173
+ *
174
+ * @see {@link User}
175
+ *
176
+ * @example
177
+ * ```typescript
178
+ * const result = UserSchema.safeParse({
179
+ * $id: 'https://example.com/users/1',
180
+ * $type: 'https://schema.org.ai/User',
181
+ * email: 'alice@example.com',
182
+ * name: 'Alice',
183
+ * createdAt: new Date().toISOString(),
184
+ * updatedAt: new Date().toISOString()
185
+ * })
186
+ *
187
+ * if (!result.success) {
188
+ * console.error('Invalid email:', result.error.issues)
189
+ * }
190
+ * ```
191
+ */
192
+ export declare const UserSchema: z.ZodObject<{
193
+ $id: z.ZodString;
194
+ $type: z.ZodLiteral<"https://schema.org.ai/User">;
195
+ email: z.ZodString;
196
+ name: z.ZodString;
197
+ profile: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
198
+ createdAt: z.ZodString;
199
+ updatedAt: z.ZodString;
200
+ }, "strip", z.ZodTypeAny, {
201
+ $id: string;
202
+ $type: "https://schema.org.ai/User";
203
+ createdAt: string;
204
+ updatedAt: string;
205
+ email: string;
206
+ name: string;
207
+ profile?: Record<string, unknown> | undefined;
208
+ }, {
209
+ $id: string;
210
+ $type: "https://schema.org.ai/User";
211
+ createdAt: string;
212
+ updatedAt: string;
213
+ email: string;
214
+ name: string;
215
+ profile?: Record<string, unknown> | undefined;
216
+ }>;
217
+ /**
218
+ * Type guard to check if an object is a valid User
219
+ *
220
+ * Uses Zod schema validation internally including email format validation.
221
+ *
222
+ * @param obj - Object to validate
223
+ * @returns True if the object is a valid User
224
+ *
225
+ * @example
226
+ * ```typescript
227
+ * const data: unknown = await fetchUser(id)
228
+ * if (isUser(data)) {
229
+ * // TypeScript knows data is User
230
+ * sendEmail(data.email, `Hello ${data.name}!`)
231
+ * }
232
+ * ```
233
+ */
234
+ export declare function isUser(obj: unknown): obj is User;
235
+ /**
236
+ * Factory function to create a new User
237
+ *
238
+ * Creates a complete User object with auto-generated `$id` (if not provided),
239
+ * timestamps, and the correct `$type`. Email and name are required.
240
+ *
241
+ * @param input - User data (email and name required)
242
+ * @param input.email - User's email address
243
+ * @param input.name - User's display name
244
+ * @param input.$id - Custom identifier URI (auto-generated if not provided)
245
+ * @param input.profile - Optional profile metadata
246
+ * @returns A complete User object ready for storage
247
+ *
248
+ * @example
249
+ * ```typescript
250
+ * // Basic user creation
251
+ * const user = createUser({
252
+ * email: 'alice@example.com',
253
+ * name: 'Alice Smith'
254
+ * })
255
+ *
256
+ * // With profile data
257
+ * const user = createUser({
258
+ * email: 'bob@example.com',
259
+ * name: 'Bob Jones',
260
+ * profile: {
261
+ * avatar: 'https://example.com/bob.png',
262
+ * bio: 'Software developer',
263
+ * settings: { theme: 'dark' }
264
+ * }
265
+ * })
266
+ *
267
+ * // With custom $id
268
+ * const user = createUser({
269
+ * $id: 'https://myapp.com/users/alice',
270
+ * email: 'alice@example.com',
271
+ * name: 'Alice'
272
+ * })
273
+ * ```
274
+ */
275
+ export declare function createUser(input: Omit<User, '$type' | 'createdAt' | 'updatedAt' | '$id'> & {
276
+ $id?: string;
277
+ }): User;
278
+ /**
279
+ * AgentIdentity - AI agent identity
280
+ *
281
+ * Extends the base {@link Identity} interface with AI agent-specific fields
282
+ * such as model name, capabilities, and autonomy level.
283
+ *
284
+ * @see https://schema.org.ai/AgentIdentity
285
+ *
286
+ * @example
287
+ * ```typescript
288
+ * const agent: AgentIdentity = {
289
+ * $id: 'https://schema.org.ai/agents/assistant-1',
290
+ * $type: 'https://schema.org.ai/AgentIdentity',
291
+ * model: 'claude-3-opus',
292
+ * capabilities: ['text-generation', 'code-analysis', 'tool-use'],
293
+ * autonomous: false,
294
+ * createdAt: '2024-01-01T00:00:00Z',
295
+ * updatedAt: '2024-01-01T00:00:00Z'
296
+ * }
297
+ * ```
298
+ */
299
+ export interface AgentIdentity extends Omit<Identity, '$type'> {
300
+ /** Type discriminator for AgentIdentity (JSON-LD @type) */
301
+ $type: 'https://schema.org.ai/AgentIdentity';
302
+ /** The AI model powering this agent (e.g., 'claude-3-opus', 'gpt-4') */
303
+ model: string;
304
+ /** List of capabilities this agent supports */
305
+ capabilities: string[];
306
+ /** Whether the agent can act autonomously without human approval */
307
+ autonomous: boolean;
308
+ }
309
+ /**
310
+ * Zod schema for validating AgentIdentity objects
311
+ *
312
+ * Validates all AgentIdentity fields including model, capabilities array,
313
+ * and autonomous flag.
314
+ *
315
+ * @see {@link AgentIdentity}
316
+ *
317
+ * @example
318
+ * ```typescript
319
+ * const result = AgentIdentitySchema.safeParse(agentData)
320
+ * if (result.success) {
321
+ * const agent = result.data
322
+ * if (agent.autonomous) {
323
+ * console.log('Agent can act independently')
324
+ * }
325
+ * }
326
+ * ```
327
+ */
328
+ export declare const AgentIdentitySchema: z.ZodObject<{
329
+ $id: z.ZodString;
330
+ $type: z.ZodLiteral<"https://schema.org.ai/AgentIdentity">;
331
+ model: z.ZodString;
332
+ capabilities: z.ZodArray<z.ZodString, "many">;
333
+ autonomous: z.ZodBoolean;
334
+ createdAt: z.ZodString;
335
+ updatedAt: z.ZodString;
336
+ }, "strip", z.ZodTypeAny, {
337
+ $id: string;
338
+ $type: "https://schema.org.ai/AgentIdentity";
339
+ createdAt: string;
340
+ updatedAt: string;
341
+ model: string;
342
+ capabilities: string[];
343
+ autonomous: boolean;
344
+ }, {
345
+ $id: string;
346
+ $type: "https://schema.org.ai/AgentIdentity";
347
+ createdAt: string;
348
+ updatedAt: string;
349
+ model: string;
350
+ capabilities: string[];
351
+ autonomous: boolean;
352
+ }>;
353
+ /**
354
+ * Type guard to check if an object is a valid AgentIdentity
355
+ *
356
+ * Uses Zod schema validation internally to ensure type safety.
357
+ *
358
+ * @param obj - Object to validate
359
+ * @returns True if the object is a valid AgentIdentity
360
+ *
361
+ * @example
362
+ * ```typescript
363
+ * const identity: unknown = getIdentity(id)
364
+ * if (isAgentIdentity(identity)) {
365
+ * // TypeScript knows identity is AgentIdentity
366
+ * console.log(`Agent model: ${identity.model}`)
367
+ * console.log(`Capabilities: ${identity.capabilities.join(', ')}`)
368
+ * }
369
+ * ```
370
+ */
371
+ export declare function isAgentIdentity(obj: unknown): obj is AgentIdentity;
372
+ /**
373
+ * Factory function to create a new AgentIdentity
374
+ *
375
+ * Creates a complete AgentIdentity object with auto-generated `$id` (if not provided),
376
+ * timestamps, and the correct `$type`. Model, capabilities, and autonomous flag are required.
377
+ *
378
+ * @param input - Agent identity data
379
+ * @param input.model - The AI model name (e.g., 'claude-3-opus')
380
+ * @param input.capabilities - Array of capability strings
381
+ * @param input.autonomous - Whether the agent can act autonomously
382
+ * @param input.$id - Custom identifier URI (auto-generated if not provided)
383
+ * @returns A complete AgentIdentity object ready for storage
384
+ *
385
+ * @example
386
+ * ```typescript
387
+ * // Create a supervised agent
388
+ * const assistant = createAgentIdentity({
389
+ * model: 'claude-3-opus',
390
+ * capabilities: ['text-generation', 'code-analysis'],
391
+ * autonomous: false
392
+ * })
393
+ *
394
+ * // Create an autonomous agent
395
+ * const worker = createAgentIdentity({
396
+ * model: 'claude-3-haiku',
397
+ * capabilities: ['task-execution', 'tool-use'],
398
+ * autonomous: true
399
+ * })
400
+ *
401
+ * // With custom $id
402
+ * const namedAgent = createAgentIdentity({
403
+ * $id: 'https://myapp.com/agents/ralph',
404
+ * model: 'claude-3-opus',
405
+ * capabilities: ['coding', 'review'],
406
+ * autonomous: true
407
+ * })
408
+ * ```
409
+ */
410
+ export declare function createAgentIdentity(input: Omit<AgentIdentity, '$type' | 'createdAt' | 'updatedAt' | '$id'> & {
411
+ $id?: string;
412
+ }): AgentIdentity;
413
+ /**
414
+ * Supported credential types for authentication
415
+ *
416
+ * - `password` - Traditional username/password authentication
417
+ * - `oauth` - OAuth 2.0 / OpenID Connect (Google, GitHub, etc.)
418
+ * - `api_key` - API key authentication for programmatic access
419
+ * - `sso` - Enterprise Single Sign-On (SAML, etc.)
420
+ */
421
+ export type CredentialType = 'password' | 'oauth' | 'api_key' | 'sso';
422
+ /**
423
+ * Credential - Authentication credential for an identity
424
+ *
425
+ * Represents an authentication method associated with an {@link Identity}.
426
+ * Each identity can have multiple credentials of different types.
427
+ *
428
+ * Note: This stores credential metadata, NOT the actual secret values.
429
+ * Secret handling should be done through a secure credential store.
430
+ *
431
+ * @see https://schema.org.ai/Credential
432
+ *
433
+ * @example
434
+ * ```typescript
435
+ * const credential: Credential = {
436
+ * $id: 'https://schema.org.ai/credentials/cred-123',
437
+ * $type: 'https://schema.org.ai/Credential',
438
+ * identityId: 'https://schema.org.ai/users/user-456',
439
+ * credentialType: 'oauth',
440
+ * provider: 'google',
441
+ * expiresAt: '2024-12-31T23:59:59Z'
442
+ * }
443
+ * ```
444
+ */
445
+ export interface Credential {
446
+ /** Unique identifier URI (JSON-LD @id) */
447
+ $id: string;
448
+ /** Type discriminator (JSON-LD @type) */
449
+ $type: 'https://schema.org.ai/Credential';
450
+ /** Reference to the identity this credential belongs to */
451
+ identityId: string;
452
+ /** The type of credential (password, oauth, api_key, sso) */
453
+ credentialType: CredentialType;
454
+ /** OAuth/SSO provider name (e.g., 'google', 'github', 'okta') */
455
+ provider?: string;
456
+ /** ISO 8601 timestamp when the credential expires (if applicable) */
457
+ expiresAt?: string;
458
+ }
459
+ /**
460
+ * Zod schema for validating Credential objects
461
+ *
462
+ * Validates credential type as one of the allowed enum values.
463
+ *
464
+ * @see {@link Credential}
465
+ * @see {@link CredentialType}
466
+ *
467
+ * @example
468
+ * ```typescript
469
+ * const result = CredentialSchema.safeParse(credentialData)
470
+ * if (result.success) {
471
+ * const cred = result.data
472
+ * if (cred.credentialType === 'oauth' && cred.provider) {
473
+ * console.log(`OAuth via ${cred.provider}`)
474
+ * }
475
+ * }
476
+ * ```
477
+ */
478
+ export declare const CredentialSchema: z.ZodObject<{
479
+ $id: z.ZodString;
480
+ $type: z.ZodLiteral<"https://schema.org.ai/Credential">;
481
+ identityId: z.ZodString;
482
+ credentialType: z.ZodEnum<["password", "oauth", "api_key", "sso"]>;
483
+ provider: z.ZodOptional<z.ZodString>;
484
+ expiresAt: z.ZodOptional<z.ZodString>;
485
+ }, "strip", z.ZodTypeAny, {
486
+ $id: string;
487
+ $type: "https://schema.org.ai/Credential";
488
+ identityId: string;
489
+ credentialType: "password" | "oauth" | "api_key" | "sso";
490
+ provider?: string | undefined;
491
+ expiresAt?: string | undefined;
492
+ }, {
493
+ $id: string;
494
+ $type: "https://schema.org.ai/Credential";
495
+ identityId: string;
496
+ credentialType: "password" | "oauth" | "api_key" | "sso";
497
+ provider?: string | undefined;
498
+ expiresAt?: string | undefined;
499
+ }>;
500
+ /**
501
+ * Type guard to check if an object is a valid Credential
502
+ *
503
+ * Uses Zod schema validation internally to ensure type safety.
504
+ *
505
+ * @param obj - Object to validate
506
+ * @returns True if the object is a valid Credential
507
+ *
508
+ * @example
509
+ * ```typescript
510
+ * const data: unknown = await getCredential(id)
511
+ * if (isCredential(data)) {
512
+ * // TypeScript knows data is Credential
513
+ * console.log(`Credential type: ${data.credentialType}`)
514
+ * if (data.expiresAt) {
515
+ * console.log(`Expires: ${data.expiresAt}`)
516
+ * }
517
+ * }
518
+ * ```
519
+ */
520
+ export declare function isCredential(obj: unknown): obj is Credential;
521
+ /**
522
+ * Factory function to create a new Credential
523
+ *
524
+ * Creates a complete Credential object with auto-generated `$id` (if not provided)
525
+ * and the correct `$type`. The identityId and credentialType are required.
526
+ *
527
+ * @param input - Credential data
528
+ * @param input.identityId - Reference to the owning identity
529
+ * @param input.credentialType - Type of credential (password, oauth, api_key, sso)
530
+ * @param input.$id - Custom identifier URI (auto-generated if not provided)
531
+ * @param input.provider - OAuth/SSO provider name (optional)
532
+ * @param input.expiresAt - Expiration timestamp (optional)
533
+ * @returns A complete Credential object ready for storage
534
+ *
535
+ * @example
536
+ * ```typescript
537
+ * // Password credential (never expires)
538
+ * const passwordCred = createCredential({
539
+ * identityId: 'https://schema.org.ai/users/123',
540
+ * credentialType: 'password'
541
+ * })
542
+ *
543
+ * // OAuth credential with expiration
544
+ * const oauthCred = createCredential({
545
+ * identityId: 'https://schema.org.ai/users/123',
546
+ * credentialType: 'oauth',
547
+ * provider: 'google',
548
+ * expiresAt: '2024-12-31T23:59:59Z'
549
+ * })
550
+ *
551
+ * // API key for programmatic access
552
+ * const apiKeyCred = createCredential({
553
+ * identityId: 'https://schema.org.ai/agents/worker-1',
554
+ * credentialType: 'api_key'
555
+ * })
556
+ * ```
557
+ */
558
+ export declare function createCredential(input: Omit<Credential, '$type' | '$id'> & {
559
+ $id?: string;
560
+ }): Credential;
561
+ /**
562
+ * Session - Active authentication session
563
+ *
564
+ * Represents an authenticated session for an {@link Identity}. Sessions have
565
+ * a secure token and an expiration time. Use {@link isSessionExpired} to check
566
+ * if a session is still valid.
567
+ *
568
+ * @see https://schema.org.ai/Session
569
+ *
570
+ * @example
571
+ * ```typescript
572
+ * const session: Session = {
573
+ * $id: 'https://schema.org.ai/sessions/sess-123',
574
+ * $type: 'https://schema.org.ai/Session',
575
+ * identityId: 'https://schema.org.ai/users/user-456',
576
+ * token: 'a1b2c3d4e5f6...',
577
+ * expiresAt: '2024-01-02T00:00:00Z',
578
+ * metadata: { userAgent: 'Mozilla/5.0...', ip: '192.168.1.1' }
579
+ * }
580
+ * ```
581
+ */
582
+ export interface Session {
583
+ /** Unique identifier URI (JSON-LD @id) */
584
+ $id: string;
585
+ /** Type discriminator (JSON-LD @type) */
586
+ $type: 'https://schema.org.ai/Session';
587
+ /** Reference to the authenticated identity */
588
+ identityId: string;
589
+ /** Secure session token (auto-generated if not provided) */
590
+ token: string;
591
+ /** ISO 8601 timestamp when the session expires */
592
+ expiresAt: string;
593
+ /** Optional metadata about the session (user agent, IP, etc.) */
594
+ metadata?: Record<string, unknown>;
595
+ }
596
+ /**
597
+ * Zod schema for validating Session objects
598
+ *
599
+ * Validates all Session fields including non-empty token requirement.
600
+ *
601
+ * @see {@link Session}
602
+ *
603
+ * @example
604
+ * ```typescript
605
+ * const result = SessionSchema.safeParse(sessionData)
606
+ * if (result.success) {
607
+ * const session = result.data
608
+ * // Use the validated session
609
+ * } else {
610
+ * console.error('Invalid session:', result.error.issues)
611
+ * }
612
+ * ```
613
+ */
614
+ export declare const SessionSchema: z.ZodObject<{
615
+ $id: z.ZodString;
616
+ $type: z.ZodLiteral<"https://schema.org.ai/Session">;
617
+ identityId: z.ZodString;
618
+ token: z.ZodString;
619
+ expiresAt: z.ZodString;
620
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
621
+ }, "strip", z.ZodTypeAny, {
622
+ $id: string;
623
+ $type: "https://schema.org.ai/Session";
624
+ identityId: string;
625
+ expiresAt: string;
626
+ token: string;
627
+ metadata?: Record<string, unknown> | undefined;
628
+ }, {
629
+ $id: string;
630
+ $type: "https://schema.org.ai/Session";
631
+ identityId: string;
632
+ expiresAt: string;
633
+ token: string;
634
+ metadata?: Record<string, unknown> | undefined;
635
+ }>;
636
+ /**
637
+ * Type guard to check if an object is a valid Session
638
+ *
639
+ * Uses Zod schema validation internally to ensure type safety.
640
+ * Note: This only validates structure, not expiration. Use {@link isSessionExpired}
641
+ * to check if a session has expired.
642
+ *
643
+ * @param obj - Object to validate
644
+ * @returns True if the object is a valid Session
645
+ *
646
+ * @example
647
+ * ```typescript
648
+ * const data: unknown = await getSession(token)
649
+ * if (isSession(data)) {
650
+ * // TypeScript knows data is Session
651
+ * if (!isSessionExpired(data)) {
652
+ * console.log(`Session valid until: ${data.expiresAt}`)
653
+ * }
654
+ * }
655
+ * ```
656
+ */
657
+ export declare function isSession(obj: unknown): obj is Session;
658
+ /**
659
+ * Factory function to create a new Session
660
+ *
661
+ * Creates a complete Session object with auto-generated `$id`, `token`, and
662
+ * `expiresAt` (24 hours from now) if not provided. Only `identityId` is required.
663
+ *
664
+ * @param input - Session data
665
+ * @param input.identityId - Reference to the authenticated identity
666
+ * @param input.$id - Custom identifier URI (auto-generated if not provided)
667
+ * @param input.token - Custom session token (auto-generated if not provided)
668
+ * @param input.expiresAt - Custom expiration (defaults to 24 hours from now)
669
+ * @param input.metadata - Optional session metadata
670
+ * @returns A complete Session object ready for storage
671
+ *
672
+ * @example
673
+ * ```typescript
674
+ * // Basic session with defaults (24h expiry, auto-generated token)
675
+ * const session = createSession({
676
+ * identityId: 'https://schema.org.ai/users/123'
677
+ * })
678
+ *
679
+ * // Session with custom expiration
680
+ * const shortSession = createSession({
681
+ * identityId: 'https://schema.org.ai/users/123',
682
+ * expiresAt: new Date(Date.now() + 60 * 60 * 1000).toISOString() // 1 hour
683
+ * })
684
+ *
685
+ * // Session with metadata
686
+ * const trackedSession = createSession({
687
+ * identityId: 'https://schema.org.ai/users/123',
688
+ * metadata: {
689
+ * userAgent: 'Mozilla/5.0...',
690
+ * ip: '192.168.1.1',
691
+ * device: 'desktop'
692
+ * }
693
+ * })
694
+ * ```
695
+ */
696
+ export declare function createSession(input: Omit<Session, '$type' | '$id' | 'token' | 'expiresAt'> & {
697
+ $id?: string;
698
+ token?: string;
699
+ expiresAt?: string;
700
+ }): Session;
701
+ /**
702
+ * Check if a session has expired
703
+ *
704
+ * Compares the session's `expiresAt` timestamp against the current time.
705
+ *
706
+ * @param session - The session to check
707
+ * @returns True if the session has expired (expiresAt is in the past)
708
+ *
709
+ * @example
710
+ * ```typescript
711
+ * const session = await getSession(token)
712
+ * if (isSession(session)) {
713
+ * if (isSessionExpired(session)) {
714
+ * // Redirect to login
715
+ * throw new Error('Session expired')
716
+ * }
717
+ * // Continue with authenticated request
718
+ * }
719
+ * ```
720
+ *
721
+ * @example
722
+ * ```typescript
723
+ * // Clean up expired sessions
724
+ * const sessions = await getAllSessions()
725
+ * const activeSessions = sessions.filter(s => !isSessionExpired(s))
726
+ * const expiredSessions = sessions.filter(isSessionExpired)
727
+ * ```
728
+ */
729
+ export declare function isSessionExpired(session: Session): boolean;
730
+ //# sourceMappingURL=index.d.ts.map