@happyvertical/smrt-profiles 0.51.31 → 0.51.33

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.
Files changed (100) hide show
  1. package/dist/__smrt-register__.d.ts +2 -0
  2. package/dist/__smrt-register__.d.ts.map +1 -0
  3. package/dist/agent-profile.d.ts +71 -0
  4. package/dist/agent-profile.d.ts.map +1 -0
  5. package/dist/auth/index.d.ts +12 -0
  6. package/dist/auth/index.d.ts.map +1 -0
  7. package/dist/auth/magicLinkService.d.ts +79 -0
  8. package/dist/auth/magicLinkService.d.ts.map +1 -0
  9. package/dist/auth/nip05Handler.d.ts +73 -0
  10. package/dist/auth/nip05Handler.d.ts.map +1 -0
  11. package/dist/auth/normalizeIdentityEmail.d.ts +8 -0
  12. package/dist/auth/normalizeIdentityEmail.d.ts.map +1 -0
  13. package/dist/auth/nostrCrypto.d.ts +111 -0
  14. package/dist/auth/nostrCrypto.d.ts.map +1 -0
  15. package/dist/auth/oidcProvisioningCoordinator.d.ts +58 -0
  16. package/dist/auth/oidcProvisioningCoordinator.d.ts.map +1 -0
  17. package/dist/auth/oidcProvisioningPrimitives.d.ts +23 -0
  18. package/dist/auth/oidcProvisioningPrimitives.d.ts.map +1 -0
  19. package/dist/auth/resolveIdentity.d.ts +188 -0
  20. package/dist/auth/resolveIdentity.d.ts.map +1 -0
  21. package/dist/collections/ApiKeyCollection.d.ts +46 -0
  22. package/dist/collections/ApiKeyCollection.d.ts.map +1 -0
  23. package/dist/collections/AuditLogCollection.d.ts +50 -0
  24. package/dist/collections/AuditLogCollection.d.ts.map +1 -0
  25. package/dist/collections/MagicLinkTokenCollection.d.ts +58 -0
  26. package/dist/collections/MagicLinkTokenCollection.d.ts.map +1 -0
  27. package/dist/collections/NostrIdentityCollection.d.ts +66 -0
  28. package/dist/collections/NostrIdentityCollection.d.ts.map +1 -0
  29. package/dist/collections/OidcIdentityCollection.d.ts +45 -0
  30. package/dist/collections/OidcIdentityCollection.d.ts.map +1 -0
  31. package/dist/collections/OidcProfileEmailReservationCollection.d.ts +7 -0
  32. package/dist/collections/OidcProfileEmailReservationCollection.d.ts.map +1 -0
  33. package/dist/collections/ProfileAssetCollection.d.ts +17 -0
  34. package/dist/collections/ProfileAssetCollection.d.ts.map +1 -0
  35. package/dist/collections/ProfileCollection.d.ts +130 -0
  36. package/dist/collections/ProfileCollection.d.ts.map +1 -0
  37. package/dist/collections/ProfileMetadataCollection.d.ts +33 -0
  38. package/dist/collections/ProfileMetadataCollection.d.ts.map +1 -0
  39. package/dist/collections/ProfileMetafieldCollection.d.ts +31 -0
  40. package/dist/collections/ProfileMetafieldCollection.d.ts.map +1 -0
  41. package/dist/collections/ProfileRelationshipCollection.d.ts +44 -0
  42. package/dist/collections/ProfileRelationshipCollection.d.ts.map +1 -0
  43. package/dist/collections/ProfileRelationshipTermCollection.d.ts +32 -0
  44. package/dist/collections/ProfileRelationshipTermCollection.d.ts.map +1 -0
  45. package/dist/collections/ProfileRelationshipTypeCollection.d.ts +41 -0
  46. package/dist/collections/ProfileRelationshipTypeCollection.d.ts.map +1 -0
  47. package/dist/collections/ProfileTypeCollection.d.ts +40 -0
  48. package/dist/collections/ProfileTypeCollection.d.ts.map +1 -0
  49. package/dist/collections/index.d.ts +18 -0
  50. package/dist/collections/index.d.ts.map +1 -0
  51. package/dist/index.d.ts +55 -2059
  52. package/dist/index.d.ts.map +1 -0
  53. package/dist/index.js +1 -1
  54. package/dist/internal/oidc-provisioning.d.ts +14 -119
  55. package/dist/internal/oidc-provisioning.d.ts.map +1 -0
  56. package/dist/manifest.json +1 -1
  57. package/dist/migrations/backfillProfileEmailKeys.d.ts +16 -0
  58. package/dist/migrations/backfillProfileEmailKeys.d.ts.map +1 -0
  59. package/dist/models/ApiKey.d.ts +94 -0
  60. package/dist/models/ApiKey.d.ts.map +1 -0
  61. package/dist/models/AuditLog.d.ts +71 -0
  62. package/dist/models/AuditLog.d.ts.map +1 -0
  63. package/dist/models/MagicLinkToken.d.ts +104 -0
  64. package/dist/models/MagicLinkToken.d.ts.map +1 -0
  65. package/dist/models/NostrIdentity.d.ts +112 -0
  66. package/dist/models/NostrIdentity.d.ts.map +1 -0
  67. package/dist/models/OidcIdentity.d.ts +82 -0
  68. package/dist/models/OidcIdentity.d.ts.map +1 -0
  69. package/dist/models/OidcProfileEmailReservation.d.ts +12 -0
  70. package/dist/models/OidcProfileEmailReservation.d.ts.map +1 -0
  71. package/dist/models/Profile.d.ts +243 -0
  72. package/dist/models/Profile.d.ts.map +1 -0
  73. package/dist/models/ProfileAsset.d.ts +18 -0
  74. package/dist/models/ProfileAsset.d.ts.map +1 -0
  75. package/dist/models/ProfileMetadata.d.ts +33 -0
  76. package/dist/models/ProfileMetadata.d.ts.map +1 -0
  77. package/dist/models/ProfileMetafield.d.ts +62 -0
  78. package/dist/models/ProfileMetafield.d.ts.map +1 -0
  79. package/dist/models/ProfileRelationship.d.ts +56 -0
  80. package/dist/models/ProfileRelationship.d.ts.map +1 -0
  81. package/dist/models/ProfileRelationshipTerm.d.ts +37 -0
  82. package/dist/models/ProfileRelationshipTerm.d.ts.map +1 -0
  83. package/dist/models/ProfileRelationshipType.d.ts +59 -0
  84. package/dist/models/ProfileRelationshipType.d.ts.map +1 -0
  85. package/dist/models/ProfileType.d.ts +27 -0
  86. package/dist/models/ProfileType.d.ts.map +1 -0
  87. package/dist/models/ProfileTypes.d.ts +32 -0
  88. package/dist/models/ProfileTypes.d.ts.map +1 -0
  89. package/dist/models/index.d.ts +18 -0
  90. package/dist/models/index.d.ts.map +1 -0
  91. package/dist/prompts.d.ts +17 -0
  92. package/dist/prompts.d.ts.map +1 -0
  93. package/dist/smrt-knowledge.json +4 -4
  94. package/dist/testing/oidcProvisioningDecisionMatrix.d.ts +1168 -0
  95. package/dist/testing/oidcProvisioningDecisionMatrix.d.ts.map +1 -0
  96. package/dist/types.d.ts +33 -732
  97. package/dist/types.d.ts.map +1 -0
  98. package/dist/utils.d.ts +52 -817
  99. package/dist/utils.d.ts.map +1 -0
  100. package/package.json +7 -7
package/dist/utils.d.ts CHANGED
@@ -1,823 +1,58 @@
1
- import { Asset } from '@happyvertical/smrt-assets';
2
- import { SmrtObject } from '@happyvertical/smrt-core';
3
- import { SmrtObjectOptions } from '@happyvertical/smrt-core';
4
-
5
- declare class ApiKey extends SmrtObject {
6
- /**
7
- * Link to the Profile (Person, Organization, Bot)
8
- */
9
- profileId?: string;
10
- /**
11
- * SHA-256 hash of the API key.
12
- *
13
- * Indexed: `verify()` looks keys up by this hash on every authenticated
14
- * request (#2364, epic #2382 finding A3).
15
- */
16
- keyHash: string;
17
- /**
18
- * First 8 characters of the key for identification (e.g., "sk_live_a1b2...")
19
- */
20
- keyPrefix: string;
21
- /**
22
- * Human-readable name for the key (e.g., "CI Bot", "Local CLI")
23
- */
24
- name: string;
25
- /**
26
- * Scopes/permissions for this key
27
- */
28
- scopes: string[];
29
- /**
30
- * Last time this key was used
31
- */
32
- lastUsedAt: Date | null;
33
- /**
34
- * When this key expires (null = never)
35
- */
36
- expiresAt: Date | null;
37
- /**
38
- * When this key was revoked (null = active)
39
- */
40
- revokedAt: Date | null;
41
- constructor(options?: ApiKeyOptions);
42
- /**
43
- * Get the linked Profile
44
- */
45
- getProfile(): Promise<Profile | null>;
46
- /**
47
- * Check if this key is valid (not expired, not revoked)
48
- */
49
- isValid(): boolean;
50
- /**
51
- * Check if this key has a specific scope
52
- */
53
- hasScope(scope: string): boolean;
54
- /**
55
- * Revoke this key
56
- */
57
- revoke(): Promise<void>;
58
- /**
59
- * Record usage of this key
60
- */
61
- recordUsage(): Promise<void>;
62
- /**
63
- * Hash an API key
64
- */
65
- static hashKey(key: string): string;
66
- /**
67
- * Generate a new API key for a profile
68
- */
69
- static generate(profile: Profile, options: {
70
- name: string;
71
- scopes?: string[];
72
- expiresAt?: Date | null;
73
- db?: SmrtObjectOptions['db'];
74
- }): Promise<GenerateKeyResult>;
75
- /**
76
- * Verify an API key and return the ApiKey record if valid
77
- */
78
- static verify(key: string, options?: SmrtObjectOptions): Promise<ApiKey | null>;
79
- }
80
-
81
- declare interface ApiKeyOptions extends SmrtObjectOptions {
82
- profileId?: string;
83
- name?: string;
84
- scopes?: string[];
85
- expiresAt?: Date | null;
86
- }
87
-
88
- declare class AuditLog extends SmrtObject {
89
- tenantId: string | null;
90
- /**
91
- * The profile who performed the action
92
- */
93
- profileId?: string;
94
- /**
95
- * Action performed (e.g., 'issue.update', 'feedback.incorporate')
96
- */
97
- action: string;
98
- /**
99
- * Type of resource affected (e.g., 'Issue', 'Repository')
100
- */
101
- resourceType: string;
102
- /**
103
- * ID of the affected resource
104
- */
105
- resourceId: string;
106
- /**
107
- * Source of the action
108
- */
109
- source: AuditSource;
110
- /**
111
- * Additional context (CI run ID, request ID, etc.)
112
- */
113
- metadata: Record<string, unknown>;
114
- /**
115
- * For pass-through identity in CI - the actual person who triggered
116
- */
117
- onBehalfOfId?: string | null;
118
- constructor(options?: AuditLogOptions);
119
- /**
120
- * Get the profile who performed the action
121
- */
122
- getProfile(): Promise<Profile | null>;
123
- /**
124
- * Get the profile on whose behalf the action was performed (if any)
125
- */
126
- getOnBehalfOf(): Promise<Profile | null>;
127
- /**
128
- * Get the effective actor (onBehalfOf if set, otherwise profile)
129
- */
130
- getEffectiveActor(): Promise<Profile | null>;
131
- /**
132
- * Create an audit log entry
133
- */
134
- static record(options: AuditLogOptions & {
135
- profile: Profile;
136
- onBehalfOf?: Profile | null;
137
- }): Promise<AuditLog>;
138
- }
139
-
140
- declare interface AuditLogOptions extends SmrtObjectOptions {
141
- profileId?: string;
142
- action?: string;
143
- resourceType?: string;
144
- resourceId?: string;
145
- source?: AuditSource;
146
- metadata?: Record<string, unknown>;
147
- onBehalfOfId?: string | null;
148
- tenantId?: string | null;
149
- }
150
-
151
- declare type AuditSource = 'web' | 'cli' | 'ci' | 'webhook' | 'mcp';
152
-
153
- /**
154
- * Create a reciprocal relationship between two profiles
155
- *
156
- * This is a convenience function that creates a relationship and automatically
157
- * handles the reciprocal relationship based on the relationship type configuration.
158
- *
159
- * @param fromProfile - The initiating profile
160
- * @param toProfile - The target profile
161
- * @param relationshipSlug - The type of relationship
162
- * @param contextProfile - Optional context profile for tertiary relationships
163
- */
164
- export declare function createReciprocalRelationship(fromProfile: Profile, toProfile: Profile, relationshipSlug: string, contextProfile?: Profile): Promise<void>;
165
-
166
- /**
167
- * Find profiles with a specific metadata key-value pair
168
- *
169
- * @param metafieldSlug - The slug of the metafield to search
170
- * @param value - The value to match
171
- * @param options - Database and configuration options
172
- * @returns Array of matching profile IDs
173
- */
174
- export declare function findProfilesByMeta(metafieldSlug: string, value: unknown, options?: SmrtObjectOptions): Promise<string[]>;
175
-
176
- declare interface GenerateKeyResult {
177
- key: string;
178
- apiKey: ApiKey;
179
- }
180
-
181
- /**
182
- * Retrieve all metadata for a profile as a key-value object
183
- *
184
- * @param profileId - The UUID of the profile
185
- * @param options - Database and configuration options
186
- * @returns Object with metafield slugs as keys and values as values
187
- */
188
- export declare function getProfileMetadata(profileId: string, options?: SmrtObjectOptions): Promise<Record<string, string>>;
189
-
190
- declare class NostrIdentity extends SmrtObject {
191
- /**
192
- * Link to the Profile (Person, Organization, Bot)
193
- */
194
- profileId?: string;
195
- /**
196
- * Hex-encoded secp256k1 public key (64 characters).
197
- *
198
- * Indexed: `findByPubkey()` looks identities up by this column (#2364,
199
- * epic #2382 finding A3).
200
- */
201
- pubkey: string;
202
- /**
203
- * AES-256-GCM encrypted private key (base64-encoded ciphertext)
204
- */
205
- encryptedPrivkey: string;
206
- /**
207
- * Initialization vector for AES-GCM decryption (base64)
208
- */
209
- encryptionIv: string;
210
- /**
211
- * Authentication tag from AES-GCM (base64)
212
- */
213
- encryptionTag: string;
214
- /**
215
- * Email address associated with this identity
216
- */
217
- email: string;
218
- /**
219
- * Username for NIP-05 verification (e.g., "alice" for alice@domain.com)
220
- */
221
- nip05Username: string;
222
- /**
223
- * Last time this identity was used for authentication
224
- */
225
- lastUsedAt: Date | null;
226
- /**
227
- * When this identity was verified via magic link
228
- */
229
- verifiedAt: Date | null;
230
- constructor(options?: NostrIdentityOptions);
231
- /**
232
- * Get the linked Profile
233
- */
234
- getProfile(): Promise<Profile | null>;
235
- /**
236
- * Find identity by public key
237
- */
238
- static findByPubkey(pubkey: string, options?: SmrtObjectOptions): Promise<NostrIdentity | null>;
239
- /**
240
- * Find identity by email
241
- */
242
- static findByEmail(email: string, options?: SmrtObjectOptions): Promise<NostrIdentity | null>;
243
- /**
244
- * Find identity by NIP-05 username
245
- */
246
- static findByNip05(username: string, options?: SmrtObjectOptions): Promise<NostrIdentity | null>;
247
- /**
248
- * Decrypt the private key using the server master secret
249
- * @param masterSecret - SERVER_MASTER_SECRET from environment
250
- * @returns Hex-encoded private key
251
- */
252
- decryptPrivkey(masterSecret: string): string;
253
- /**
254
- * Get the full keypair (requires master secret)
255
- * @param masterSecret - SERVER_MASTER_SECRET from environment
256
- */
257
- getKeypair(masterSecret: string): {
258
- pubkey: string;
259
- privkey: string;
260
- npub: string;
261
- nsec: string;
262
- };
263
- /**
264
- * Record usage of this identity
265
- */
266
- recordUsage(): Promise<void>;
267
- /**
268
- * Mark this identity as verified
269
- */
270
- markVerified(): Promise<void>;
271
- /**
272
- * Check if this identity is verified
273
- */
274
- isVerified(): boolean;
275
- /**
276
- * Get the NIP-05 identifier (username@domain)
277
- * Note: Domain must be provided by the application
278
- */
279
- getNip05Identifier(domain: string): string;
280
- }
281
-
282
- declare interface NostrIdentityOptions extends SmrtObjectOptions {
283
- profileId?: string;
284
- pubkey?: string;
285
- encryptedPrivkey?: string;
286
- encryptionIv?: string;
287
- encryptionTag?: string;
288
- email?: string;
289
- nip05Username?: string;
290
- lastUsedAt?: Date | null;
291
- verifiedAt?: Date | null;
292
- }
293
-
294
- declare class OidcIdentity extends SmrtObject {
295
- /**
296
- * Link to the Profile (Person, Organization, Bot)
297
- */
298
- profileId?: string;
299
- /**
300
- * Provider name (e.g., 'keycloak', 'google', 'github')
301
- */
302
- provider: string;
303
- /**
304
- * OIDC issuer URL (e.g., https://keycloak.example.com/realms/bmp)
305
- */
306
- issuer: string;
307
- /**
308
- * OIDC subject claim - unique identifier from the provider
309
- */
310
- subject: string;
311
- /**
312
- * Stable issuer+subject key used as the database race arbiter.
313
- *
314
- * Nullable for legacy rows; every newly linked or reused identity backfills
315
- * it. A separate unique constraint makes concurrent first login fail with a
316
- * retryable conflict instead of creating two identities.
317
- */
318
- identityKey: string | null;
319
- /**
320
- * Cached email from the IdP (for display/lookup)
321
- */
322
- email: string;
323
- /**
324
- * Last time this identity was used for authentication
325
- */
326
- lastUsedAt: Date | null;
327
- constructor(options?: OidcIdentityOptions);
328
- /**
329
- * Get the linked Profile
330
- */
331
- getProfile(): Promise<Profile | null>;
332
- /**
333
- * Find identity by issuer and subject
334
- */
335
- static findBySubject(issuer: string, subject: string, options?: SmrtObjectOptions): Promise<OidcIdentity | null>;
336
- /** Build the collision-free natural key for one OIDC issuer subject. */
337
- static buildIdentityKey(issuer: string, subject: string): string;
338
- /** Keep the durable key derived from its natural-key source fields. */
339
- save(): Promise<this>;
340
- /**
341
- * Reuse an existing exact identity for its unchanged Profile.
342
- *
343
- * @deprecated Authentication links must be created through transactional
344
- * provisioning. This compatibility method only refreshes a unique mapping
345
- * that already belongs to the supplied Profile, including legacy Profile
346
- * types, and deliberately refuses to create or rebind authority.
347
- */
348
- static findOrCreate(profile: Profile, oidcData: {
349
- provider: string;
350
- issuer: string;
351
- subject: string;
352
- email?: string;
353
- }, options?: SmrtObjectOptions): Promise<OidcIdentity>;
354
- /**
355
- * Record usage of this identity
356
- */
357
- recordUsage(): Promise<void>;
358
- }
359
-
360
- declare interface OidcIdentityOptions extends SmrtObjectOptions {
361
- profileId?: string;
362
- provider?: string;
363
- issuer?: string;
364
- subject?: string;
365
- email?: string;
366
- lastUsedAt?: Date | null;
367
- }
368
-
369
- declare class Profile extends SmrtObject {
370
- tenantId: string | null;
371
- typeId?: string;
372
- email?: string;
373
- /** Adapter-independent identity lookup key derived from email on save. */
374
- emailKey: string | null;
375
- name: string;
376
- description?: string;
377
- metadata: ProfileMetadata[];
378
- relationshipsFrom: ProfileRelationship[];
379
- relationshipsTo: ProfileRelationship[];
380
- constructor(options?: ProfileOptions);
381
- /** Keep the durable identity key derived from the public email field. */
382
- save(): Promise<this>;
383
- /**
384
- * Get the profile type slug for this profile
385
- *
386
- * @returns The slug of the profile type
387
- */
388
- getTypeSlug(): Promise<string>;
389
- /**
390
- * Set the profile type by slug
391
- *
392
- * @param slug - The slug of the profile type
393
- * @throws Error if profile type not found
394
- */
395
- setTypeBySlug(slug: string): Promise<void>;
396
- /**
397
- * Add metadata to this profile
398
- *
399
- * @param metafieldSlug - The slug of the metafield
400
- * @param value - The value to set
401
- */
402
- addMetadata(metafieldSlug: string, value: unknown): Promise<void>;
403
- /**
404
- * Get all metadata for this profile as key-value object
405
- *
406
- * @returns Object with metafield slugs as keys
407
- */
408
- getMetadata(): Promise<Record<string, string>>;
409
- /**
410
- * Update multiple metadata values
411
- *
412
- * @param metadata - Object with metafield slugs as keys and values
413
- */
414
- updateMetadata(metadata: Record<string, unknown>): Promise<void>;
415
- /**
416
- * Remove metadata by metafield slug
417
- *
418
- * @param metafieldSlug - The slug of the metafield to remove
419
- */
420
- removeMetadata(metafieldSlug: string): Promise<void>;
421
- private getProfileAssetCollection;
422
- getAssets(relationship?: string): Promise<Asset[]>;
423
- addAsset(asset: Asset, relationship?: string, sortOrder?: number): Promise<void>;
424
- removeAsset(assetId: string, relationship?: string): Promise<void>;
425
- /**
426
- * Add a relationship to another profile
427
- *
428
- * @param toProfile - The target profile
429
- * @param relationshipSlug - The type of relationship
430
- * @param contextProfile - Optional context profile for tertiary relationships
431
- */
432
- addRelationship(toProfile: Profile, relationshipSlug: string, contextProfile?: Profile): Promise<void>;
433
- /**
434
- * Get all relationships for this profile
435
- *
436
- * @param options - Filter options (typeSlug, direction)
437
- * @returns Array of ProfileRelationship instances
438
- */
439
- getRelationships(options?: {
440
- typeSlug?: string;
441
- direction?: 'from' | 'to' | 'all';
442
- }): Promise<ProfileRelationship[]>;
443
- /**
444
- * Get related profiles
445
- *
446
- * @param relationshipSlug - Optional filter by relationship type slug
447
- * @returns Array of related Profile instances
448
- */
449
- getRelatedProfiles(relationshipSlug?: string): Promise<Profile[]>;
450
- /**
451
- * Remove a relationship to another profile
452
- *
453
- * @param toProfile - The target profile
454
- * @param relationshipSlug - The type of relationship to remove
455
- */
456
- removeRelationship(toProfile: Profile, relationshipSlug: string): Promise<void>;
457
- /**
458
- * AI-powered: Generate a professional bio for this profile
459
- *
460
- * Uses the `smrtProfiles.profile.generateBio` prompt registered via
461
- * `@happyvertical/smrt-prompts`, allowing tenant- or instance-level
462
- * overrides of the template, model, and parameters at runtime.
463
- *
464
- * @returns Generated bio text
465
- */
466
- generateBio(): Promise<string>;
467
- /**
468
- * AI-powered: Check if profile matches criteria
469
- *
470
- * @param criteria - Criteria to match against
471
- * @returns True if matches criteria
472
- */
473
- matches(criteria: string): Promise<boolean>;
474
- /**
475
- * Find profiles by metadata key-value pair
476
- *
477
- * @param metafieldSlug - The metafield slug to search
478
- * @param value - The value to match
479
- * @returns Array of matching profiles
480
- */
481
- static findByMetadata(_metafieldSlug: string, _value: unknown): Promise<Profile[]>;
482
- /**
483
- * Find profiles by type slug
484
- *
485
- * @param typeSlug - The profile type slug
486
- * @returns Array of matching profiles
487
- */
488
- static findByType(_typeSlug: string): Promise<Profile[]>;
489
- /**
490
- * Find related profiles for a given profile
491
- *
492
- * @param profileId - The profile UUID
493
- * @param relationshipSlug - Optional filter by relationship type
494
- * @returns Array of related profiles
495
- */
496
- static findRelated(_profileId: string, _relationshipSlug?: string): Promise<Profile[]>;
497
- /**
498
- * Search profiles by email
499
- *
500
- * @param email - The email to search for
501
- * @returns Profile or null if not found
502
- */
503
- static searchByEmail(_email: string): Promise<Profile | null>;
504
- /**
505
- * Get all API keys for this profile
506
- *
507
- * @returns Array of API keys
508
- */
509
- getApiKeys(): Promise<ApiKey[]>;
510
- /**
511
- * Get active (non-revoked, non-expired) API keys for this profile
512
- *
513
- * @returns Array of active API keys
514
- */
515
- getActiveApiKeys(): Promise<ApiKey[]>;
516
- /**
517
- * Generate a new API key for this profile
518
- *
519
- * @param options - Key options (name, scopes, expiration)
520
- * @returns The generated key (plaintext) and ApiKey record
521
- */
522
- generateApiKey(options: {
523
- name: string;
524
- scopes?: string[];
525
- expiresAt?: Date | null;
526
- }): Promise<GenerateKeyResult>;
527
- /**
528
- * Get all OIDC identities linked to this profile
529
- *
530
- * @returns Array of OIDC identity records
531
- */
532
- getOidcIdentities(): Promise<OidcIdentity[]>;
533
- /**
534
- * Reuse an existing exact OIDC identity for this unchanged Profile.
535
- *
536
- * @param oidcData - OIDC provider data
537
- * @returns The linked OIDC identity record
538
- * @deprecated New authentication links require owner-aware transactional
539
- * provisioning. This compatibility helper may refresh a legacy Profile
540
- * type, but refuses to create or rebind authority.
541
- */
542
- linkOidcIdentity(oidcData: {
543
- provider: string;
544
- issuer: string;
545
- subject: string;
546
- email?: string;
547
- }): Promise<OidcIdentity>;
548
- /**
549
- * Get all Nostr identities linked to this profile
550
- *
551
- * @returns Array of Nostr identity records
552
- */
553
- getNostrIdentities(): Promise<NostrIdentity[]>;
554
- /**
555
- * Link a new Nostr identity to this profile
556
- *
557
- * @param nostrData - Nostr identity data (encrypted keypair)
558
- * @returns The linked Nostr identity record
559
- */
560
- linkNostrIdentity(nostrData: {
561
- pubkey: string;
562
- encryptedPrivkey: string;
563
- encryptionIv: string;
564
- encryptionTag: string;
565
- email: string;
566
- nip05Username?: string;
567
- }): Promise<NostrIdentity>;
568
- /**
569
- * Get audit logs for actions performed by this profile
570
- *
571
- * @param limit - Maximum number of logs to return
572
- * @returns Array of audit log entries
573
- */
574
- getAuditLogs(limit?: number): Promise<AuditLog[]>;
575
- /**
576
- * Record an audit log entry for an action by this profile
577
- *
578
- * @param options - Audit log options
579
- * @returns The created audit log entry
580
- */
581
- recordAction(options: {
582
- action: string;
583
- resourceType: string;
584
- resourceId: string;
585
- source?: 'web' | 'cli' | 'ci' | 'webhook' | 'mcp';
586
- metadata?: Record<string, unknown>;
587
- onBehalfOf?: Profile | null;
588
- }): Promise<AuditLog>;
589
- }
590
-
591
- declare class ProfileMetadata extends SmrtObject {
592
- tenantId: string | null;
593
- profileId?: string;
594
- metafieldId?: string;
595
- value: string;
596
- constructor(options?: ProfileMetadataOptions);
597
- /**
598
- * Validate this metadata value against the metafield's validation schema
599
- *
600
- * @returns True if valid, throws error if invalid
601
- */
602
- validate(): Promise<boolean>;
603
- /**
604
- * Get the metafield slug for this metadata
605
- *
606
- * @returns The slug of the metafield
607
- */
608
- getMetafieldSlug(): Promise<string>;
609
- }
610
-
611
- declare interface ProfileMetadataOptions extends SmrtObjectOptions {
612
- profileId?: string;
613
- metafieldId?: string;
614
- value?: string;
615
- tenantId?: string | null;
616
- }
617
-
618
- declare class ProfileMetafield extends SmrtObject {
619
- tenantId: string | null;
620
- name: string;
621
- description?: string;
622
- validation?: ValidationSchema;
623
- constructor(options?: ProfileMetafieldOptions);
624
- /**
625
- * Convenience method for slug-based lookup
626
- *
627
- * @param slug - The slug to search for
628
- * @returns ProfileMetafield instance or null if not found
629
- */
630
- static getBySlug(_slug: string): Promise<ProfileMetafield | null>;
631
- /**
632
- * Register a custom validator function
633
- *
634
- * @param name - Name of the validator (used in validation.custom field)
635
- * @param validator - The validator function
636
- */
637
- static registerValidator(name: string, validator: ValidatorFunction): void;
638
- /**
639
- * Get a registered custom validator
640
- *
641
- * @param name - Name of the validator
642
- * @returns The validator function or undefined
643
- */
644
- static getValidator(name: string): ValidatorFunction | undefined;
645
- /**
646
- * Validate a value against this metafield's validation schema
647
- *
648
- * @param value - The value to validate
649
- * @returns True if valid, throws ValidationError if invalid
650
- */
651
- validateValue(value: unknown): Promise<boolean>;
652
- }
653
-
654
- declare interface ProfileMetafieldOptions extends SmrtObjectOptions {
655
- slug?: string;
656
- name?: string;
657
- description?: string;
658
- validation?: ValidationSchema;
659
- tenantId?: string | null;
660
- }
661
-
662
- declare interface ProfileOptions extends SmrtObjectOptions {
663
- typeId?: string;
664
- email?: string;
665
- name?: string;
666
- description?: string;
667
- tenantId?: string | null;
668
- }
669
-
670
- declare class ProfileRelationship extends SmrtObject {
671
- tenantId: string | null;
672
- fromProfileId?: string;
673
- toProfileId?: string;
674
- typeId?: string;
675
- contextProfileId?: string;
676
- terms: ProfileRelationshipTerm[];
677
- constructor(options?: ProfileRelationshipOptions);
678
- /**
679
- * Get the relationship type slug
680
- *
681
- * @returns The slug of the relationship type
682
- */
683
- getTypeSlug(): Promise<string>;
684
- /**
685
- * Add a term (time period) to this relationship
686
- *
687
- * @param startedAt - Start date of the term
688
- * @param endedAt - Optional end date of the term
689
- */
690
- addTerm(startedAt: Date, endedAt?: Date): Promise<void>;
691
- /**
692
- * End the current active term
693
- *
694
- * @param endedAt - End date for the term
695
- */
696
- endCurrentTerm(endedAt: Date): Promise<void>;
697
- /**
698
- * Get all terms for this relationship
699
- *
700
- * @returns Array of ProfileRelationshipTerm instances
701
- */
702
- getTerms(): Promise<ProfileRelationshipTerm[]>;
703
- /**
704
- * Get the active term (no end date)
705
- *
706
- * @returns Current term or null if none active
707
- */
708
- getActiveTerm(): Promise<ProfileRelationshipTerm | null>;
709
- }
710
-
711
- declare interface ProfileRelationshipOptions extends SmrtObjectOptions {
712
- fromProfileId?: string;
713
- toProfileId?: string;
714
- typeId?: string;
715
- contextProfileId?: string;
716
- tenantId?: string | null;
717
- }
718
-
719
- declare class ProfileRelationshipTerm extends SmrtObject {
720
- relationshipId?: string;
721
- startedAt: Date;
722
- endedAt?: Date;
723
- constructor(options?: ProfileRelationshipTermOptions);
724
- /**
725
- * Check if this term is currently active
726
- *
727
- * @returns True if active (no end date or end date in future)
728
- */
729
- isActive(): boolean;
730
- /**
731
- * End this term
732
- *
733
- * @param endedAt - End date for the term (defaults to now)
734
- */
735
- end(endedAt?: Date): Promise<void>;
736
- /**
737
- * Get the duration of this term in days
738
- *
739
- * @returns Duration in days
740
- */
741
- getDurationDays(): number;
742
- }
743
-
744
- declare interface ProfileRelationshipTermOptions extends SmrtObjectOptions {
745
- relationshipId?: string;
746
- startedAt?: Date;
747
- endedAt?: Date;
748
- }
749
-
750
- /**
751
- * Set a single metadata value for a profile
752
- *
753
- * @param profileId - The UUID of the profile
754
- * @param metafieldSlug - The slug of the metafield
755
- * @param value - The value to set
756
- * @param options - Database and configuration options
757
- */
758
- export declare function setProfileMetadata(profileId: string, metafieldSlug: string, value: unknown, options?: SmrtObjectOptions): Promise<void>;
759
-
760
- /**
761
- * Validate a metadata value against a metafield's validation schema
762
- *
763
- * @param metafield - The metafield with validation rules
764
- * @param value - The value to validate
765
- * @returns True if valid, throws error if invalid
766
- */
767
- export declare function validateMetadataValue(metafield: ProfileMetafield, value: unknown): Promise<boolean>;
768
-
769
- /**
770
- * Validation schema structure for profile metadata fields
771
- */
772
- declare interface ValidationSchema {
773
- /** Type constraint */
774
- type?: 'string' | 'number' | 'boolean' | 'date' | 'json';
775
- /** Regex pattern for string validation */
776
- pattern?: string;
777
- /** Minimum string length */
778
- minLength?: number;
779
- /** Maximum string length */
780
- maxLength?: number;
781
- /** Minimum numeric value */
782
- min?: number;
783
- /** Maximum numeric value */
784
- max?: number;
785
- /** Custom validator function name */
786
- custom?: string;
787
- /** Custom validation error message */
788
- message?: string;
789
- }
790
-
791
- /**
792
- * Custom validator function type
793
- */
794
- declare type ValidatorFunction = (value: unknown) => boolean | Promise<boolean>;
795
-
796
- export { }
797
-
798
-
799
1
  /**
800
- * Extend globalThis to include custom validators registry.
801
- * Using globalThis ensures all module instances share the same validators,
802
- * which is critical in monorepos where the same package can be loaded
803
- * from different paths (e.g., pnpm store vs workspace symlink).
2
+ * Utility functions for profile operations
804
3
  *
805
- * @see https://github.com/happyvertical/smrt/issues/543
4
+ * Provides standalone helper functions for metadata management,
5
+ * relationship operations, and validation.
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+ import type { SmrtObjectOptions } from '@happyvertical/smrt-core';
10
+ import type { Profile } from './models/Profile';
11
+ import type { ProfileMetafield } from './models/ProfileMetafield';
12
+ /**
13
+ * Retrieve all metadata for a profile as a key-value object
14
+ *
15
+ * @param profileId - The UUID of the profile
16
+ * @param options - Database and configuration options
17
+ * @returns Object with metafield slugs as keys and values as values
18
+ */
19
+ export declare function getProfileMetadata(profileId: string, options?: SmrtObjectOptions): Promise<Record<string, string>>;
20
+ /**
21
+ * Set a single metadata value for a profile
22
+ *
23
+ * @param profileId - The UUID of the profile
24
+ * @param metafieldSlug - The slug of the metafield
25
+ * @param value - The value to set
26
+ * @param options - Database and configuration options
27
+ */
28
+ export declare function setProfileMetadata(profileId: string, metafieldSlug: string, value: unknown, options?: SmrtObjectOptions): Promise<void>;
29
+ /**
30
+ * Find profiles with a specific metadata key-value pair
31
+ *
32
+ * @param metafieldSlug - The slug of the metafield to search
33
+ * @param value - The value to match
34
+ * @param options - Database and configuration options
35
+ * @returns Array of matching profile IDs
36
+ */
37
+ export declare function findProfilesByMeta(metafieldSlug: string, value: unknown, options?: SmrtObjectOptions): Promise<string[]>;
38
+ /**
39
+ * Create a reciprocal relationship between two profiles
40
+ *
41
+ * This is a convenience function that creates a relationship and automatically
42
+ * handles the reciprocal relationship based on the relationship type configuration.
43
+ *
44
+ * @param fromProfile - The initiating profile
45
+ * @param toProfile - The target profile
46
+ * @param relationshipSlug - The type of relationship
47
+ * @param contextProfile - Optional context profile for tertiary relationships
806
48
  */
807
- declare global {
808
- var __smrtProfileMetafieldValidators: Map<string, ValidatorFunction> | undefined;
809
- }
810
-
811
-
49
+ export declare function createReciprocalRelationship(fromProfile: Profile, toProfile: Profile, relationshipSlug: string, contextProfile?: Profile): Promise<void>;
812
50
  /**
813
- * Extend globalThis to include reciprocal handlers registry.
814
- * Using globalThis ensures all module instances share the same handlers,
815
- * which is critical in monorepos where the same package can be loaded
816
- * from different paths (e.g., pnpm store vs workspace symlink).
51
+ * Validate a metadata value against a metafield's validation schema
817
52
  *
818
- * @see https://github.com/happyvertical/smrt/issues/543
53
+ * @param metafield - The metafield with validation rules
54
+ * @param value - The value to validate
55
+ * @returns True if valid, throws error if invalid
819
56
  */
820
- declare global {
821
- var __smrtProfileRelationshipHandlers: Map<string, ReciprocalHandler> | undefined;
822
- var __smrtProfileRelationshipHandlersInitialized: boolean | undefined;
823
- }
57
+ export declare function validateMetadataValue(metafield: ProfileMetafield, value: unknown): Promise<boolean>;
58
+ //# sourceMappingURL=utils.d.ts.map