@coasys/ad4m 0.11.1 → 0.11.2-dev-multi-user-email

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.
@@ -27,6 +27,9 @@ export class PerspectiveHandle {
27
27
  @Field(type => NeighbourhoodExpression, {nullable: true})
28
28
  neighbourhood?: NeighbourhoodExpression
29
29
 
30
+ @Field(type => [String], {nullable: true})
31
+ owners?: string[]
32
+
30
33
  constructor(uuid?: string, name?: string, state?: PerspectiveState) {
31
34
  this.uuid = uuid
32
35
  this.name = name
@@ -379,6 +379,9 @@ export class PerspectiveProxy {
379
379
  /** Current sync state if this perspective is shared */
380
380
  state: PerspectiveState|null;
381
381
 
382
+ /** List of owners of this perspective */
383
+ owners?: string[]
384
+
382
385
  #handle: PerspectiveHandle
383
386
  #client: PerspectiveClient
384
387
  #perspectiveLinkAddedCallbacks: LinkCallback[]
@@ -399,6 +402,7 @@ export class PerspectiveProxy {
399
402
  this.#client = ad4m
400
403
  this.uuid = this.#handle.uuid;
401
404
  this.name = this.#handle.name;
405
+ this.owners = this.#handle.owners;
402
406
  this.sharedUrl = this.#handle.sharedUrl;
403
407
  this.neighbourhood = this.#handle.neighbourhood;
404
408
  this.state = this.#handle.state;
@@ -1,7 +1,7 @@
1
1
  import { ApolloClient, gql } from "@apollo/client/core"
2
2
  import { Perspective, PerspectiveExpression } from "../perspectives/Perspective"
3
3
  import unwrapApolloResult from "../unwrapApolloResult"
4
- import { RuntimeInfo, ExceptionInfo, SentMessage, NotificationInput, Notification, TriggeredNotification, ImportResult } from "./RuntimeResolver"
4
+ import { RuntimeInfo, ExceptionInfo, SentMessage, NotificationInput, Notification, TriggeredNotification, ImportResult, UserStatistics } from "./RuntimeResolver"
5
5
 
6
6
  const PERSPECTIVE_EXPRESSION_FIELDS = `
7
7
  author
@@ -386,6 +386,86 @@ export class RuntimeClient {
386
386
  return runtimeImportPerspective
387
387
  }
388
388
 
389
+ async multiUserEnabled(): Promise<boolean> {
390
+ const { runtimeMultiUserEnabled } = unwrapApolloResult(await this.#apolloClient.query({
391
+ query: gql`query runtimeMultiUserEnabled {
392
+ runtimeMultiUserEnabled
393
+ }`,
394
+ }))
395
+ return runtimeMultiUserEnabled
396
+ }
397
+
398
+ async setMultiUserEnabled(enabled: boolean): Promise<boolean> {
399
+ const { runtimeSetMultiUserEnabled } = unwrapApolloResult(await this.#apolloClient.mutate({
400
+ mutation: gql`mutation runtimeSetMultiUserEnabled($enabled: Boolean!) {
401
+ runtimeSetMultiUserEnabled(enabled: $enabled)
402
+ }`,
403
+ variables: { enabled }
404
+ }))
405
+ return runtimeSetMultiUserEnabled
406
+ }
407
+
408
+ async listUsers(): Promise<UserStatistics[]> {
409
+ const { runtimeListUsers } = unwrapApolloResult(await this.#apolloClient.query({
410
+ query: gql`query runtimeListUsers {
411
+ runtimeListUsers {
412
+ email
413
+ did
414
+ lastSeen
415
+ perspectiveCount
416
+ }
417
+ }`
418
+ }))
419
+ return runtimeListUsers
420
+ }
421
+
422
+ async emailTestModeEnable(): Promise<boolean> {
423
+ const { runtimeEmailTestModeEnable } = unwrapApolloResult(await this.#apolloClient.mutate({
424
+ mutation: gql`mutation runtimeEmailTestModeEnable {
425
+ runtimeEmailTestModeEnable
426
+ }`
427
+ }))
428
+ return runtimeEmailTestModeEnable
429
+ }
430
+
431
+ async emailTestModeDisable(): Promise<boolean> {
432
+ const { runtimeEmailTestModeDisable } = unwrapApolloResult(await this.#apolloClient.mutate({
433
+ mutation: gql`mutation runtimeEmailTestModeDisable {
434
+ runtimeEmailTestModeDisable
435
+ }`
436
+ }))
437
+ return runtimeEmailTestModeDisable
438
+ }
439
+
440
+ async emailTestGetCode(email: string): Promise<string | null> {
441
+ const { runtimeEmailTestGetCode } = unwrapApolloResult(await this.#apolloClient.mutate({
442
+ mutation: gql`mutation runtimeEmailTestGetCode($email: String!) {
443
+ runtimeEmailTestGetCode(email: $email)
444
+ }`,
445
+ variables: { email }
446
+ }))
447
+ return runtimeEmailTestGetCode
448
+ }
449
+
450
+ async emailTestClearCodes(): Promise<boolean> {
451
+ const { runtimeEmailTestClearCodes } = unwrapApolloResult(await this.#apolloClient.mutate({
452
+ mutation: gql`mutation runtimeEmailTestClearCodes {
453
+ runtimeEmailTestClearCodes
454
+ }`
455
+ }))
456
+ return runtimeEmailTestClearCodes
457
+ }
458
+
459
+ async emailTestSetExpiry(email: string, verificationType: string, expiresAt: number): Promise<boolean> {
460
+ const { runtimeEmailTestSetExpiry } = unwrapApolloResult(await this.#apolloClient.mutate({
461
+ mutation: gql`mutation runtimeEmailTestSetExpiry($email: String!, $verificationType: String!, $expiresAt: Int!) {
462
+ runtimeEmailTestSetExpiry(email: $email, verificationType: $verificationType, expiresAt: $expiresAt)
463
+ }`,
464
+ variables: { email, verificationType, expiresAt }
465
+ }))
466
+ return runtimeEmailTestSetExpiry
467
+ }
468
+
389
469
  addNotificationTriggeredCallback(cb: NotificationTriggeredCallback) {
390
470
  this.#notificationTriggeredCallbacks.push(cb)
391
471
  }
@@ -4,6 +4,7 @@ import { ExpressionProof } from "../expression/Expression";
4
4
  import { LinkExpression } from "../links/Links";
5
5
  import { ExceptionType } from "../Exception";
6
6
  import { RUNTIME_MESSAGED_RECEIVED_TOPIC, EXCEPTION_OCCURRED_TOPIC, RUNTIME_NOTIFICATION_REQUESTED_TOPIC, RUNTIME_NOTIFICATION_TRIGGERED_TOPIC } from '../PubSub';
7
+ import { UserCreationResult, AuthInfoInput } from "../agent/Agent";
7
8
 
8
9
  const testLink = new LinkExpression()
9
10
  testLink.author = "did:ad4m:test"
@@ -192,6 +193,33 @@ export class ImportResult {
192
193
  knownLinkLanguages: ImportStats;
193
194
  }
194
195
 
196
+ @ObjectType()
197
+ export class UserStatistics {
198
+ @Field()
199
+ email: string;
200
+
201
+ @Field()
202
+ did: string;
203
+
204
+ @Field({nullable: true})
205
+ lastSeen?: string;
206
+
207
+ @Field(type => Int)
208
+ perspectiveCount: number;
209
+ }
210
+
211
+ @ObjectType()
212
+ export class VerificationRequestResult {
213
+ @Field()
214
+ success: boolean;
215
+
216
+ @Field()
217
+ message: string;
218
+
219
+ @Field()
220
+ requiresPassword: boolean;
221
+ }
222
+
195
223
  /**
196
224
  * Resolver classes are used here to define the GraphQL schema
197
225
  * (through the type-graphql annotations)
@@ -426,5 +454,107 @@ export default class RuntimeResolver {
426
454
  runtimeImportPerspective(@Arg("filePath", type => String) filePath: string): boolean {
427
455
  return true
428
456
  }
457
+
458
+ @Query(returns => Boolean)
459
+ runtimeMultiUserEnabled(): boolean {
460
+ return false
461
+ }
462
+
463
+ @Mutation(returns => Boolean)
464
+ runtimeSetMultiUserEnabled(@Arg("enabled") enabled: boolean): boolean {
465
+ return enabled
466
+ }
467
+
468
+ @Query(returns => [UserStatistics])
469
+ runtimeListUsers(): UserStatistics[] {
470
+ return [{
471
+ email: "test@example.com",
472
+ did: "did:key:test123",
473
+ lastSeen: new Date().toISOString(),
474
+ perspectiveCount: 5
475
+ }]
476
+ }
477
+
478
+ @Mutation(returns => VerificationRequestResult)
479
+ runtimeRequestLoginVerification(
480
+ @Arg("email") email: string,
481
+ @Arg("appInfo", { nullable: true }) appInfo?: AuthInfoInput
482
+ ): VerificationRequestResult {
483
+ // For testing: simulate existing user
484
+ return {
485
+ success: true,
486
+ message: "Verification email sent",
487
+ requiresPassword: false
488
+ }
489
+ }
490
+
491
+ @Mutation(returns => String)
492
+ runtimeVerifyEmailCode(
493
+ @Arg("email") email: string,
494
+ @Arg("code") code: string,
495
+ @Arg("verificationType") verificationType: string
496
+ ): string {
497
+ // For testing: return a test JWT token
498
+ return "test-jwt-token-from-email-verification"
499
+ }
500
+
501
+ @Mutation(returns => Boolean)
502
+ runtimeTestEmail(@Arg("to") to: string): boolean {
503
+ // For testing: simulate successful email send
504
+ return true
505
+ }
506
+
507
+ @Mutation(returns => UserCreationResult)
508
+ runtimeCreateUser(
509
+ @Arg("email") email: string,
510
+ @Arg("password") password: string,
511
+ @Arg("appInfo", { nullable: true }) appInfo?: AuthInfoInput
512
+ ): UserCreationResult {
513
+ // For testing: simulate successful user creation (email verification flow)
514
+ return new UserCreationResult("did:key:test123", true)
515
+ }
516
+
517
+ @Mutation(returns => String)
518
+ runtimeLoginUser(
519
+ @Arg("email") email: string,
520
+ @Arg("password") password: string
521
+ ): string {
522
+ // For testing: return a test JWT token
523
+ return "test-jwt-token-from-password-login"
524
+ }
525
+
526
+ @Mutation(returns => Boolean)
527
+ runtimeEmailTestModeEnable(): boolean {
528
+ // For testing: enable test mode
529
+ return true
530
+ }
531
+
532
+ @Mutation(returns => Boolean)
533
+ runtimeEmailTestModeDisable(): boolean {
534
+ // For testing: disable test mode
535
+ return true
536
+ }
537
+
538
+ @Mutation(returns => String, { nullable: true })
539
+ runtimeEmailTestGetCode(@Arg("email") email: string): string | null {
540
+ // For testing: return a mock code
541
+ return "123456"
542
+ }
543
+
544
+ @Mutation(returns => Boolean)
545
+ runtimeEmailTestClearCodes(): boolean {
546
+ // For testing: clear codes
547
+ return true
548
+ }
549
+
550
+ @Mutation(returns => Boolean)
551
+ runtimeEmailTestSetExpiry(
552
+ @Arg("email") email: string,
553
+ @Arg("verificationType") verificationType: string,
554
+ @Arg("expiresAt") expiresAt: number
555
+ ): boolean {
556
+ // For testing: simulate setting expiry (no-op in mock)
557
+ return true
558
+ }
429
559
  }
430
560