@tellescope/schema 1.4.27 → 1.4.30

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/src/schema.ts CHANGED
@@ -46,6 +46,8 @@ import {
46
46
  Email,
47
47
  File,
48
48
  CalendarEvent,
49
+ Organization,
50
+ User as UserClient,
49
51
  } from "@tellescope/types-client"
50
52
 
51
53
  import {
@@ -145,6 +147,9 @@ import {
145
147
  organizationLimitsValidator,
146
148
  organizationSettingsValidator,
147
149
  communicationsChannelValidator,
150
+ genericUnitWithQuantityValidator,
151
+ stringValidator25000EmptyOkay,
152
+ slugValidator,
148
153
  } from "@tellescope/validation"
149
154
 
150
155
  import {
@@ -236,6 +241,7 @@ type ActionInfo = {
236
241
  notes?: string[],
237
242
  warnings?: string[],
238
243
  adminOnly?: boolean,
244
+ rootAdminOnly?: boolean,
239
245
  creatorOnly?: boolean,
240
246
  }
241
247
 
@@ -343,6 +349,9 @@ const BuiltInFields = {
343
349
  validator: mongoIdStringValidator,
344
350
  readonly: true,
345
351
  },
352
+ organizationIds: {
353
+ validator: listOfMongoIdStringValidatorEmptyOk,
354
+ },
346
355
  creator: {
347
356
  validator: mongoIdStringValidator,
348
357
  readonly: true,
@@ -469,27 +478,32 @@ export type CustomActions = {
469
478
  createdEvent: CalendarEvent,
470
479
  }>,
471
480
  },
481
+ organizations: {
482
+ create_suborganization: CustomAction<{ name: string, subdomain: string }, { created: Organization }>,
483
+ invite_user: CustomAction<{ email: string, organizationId: string }, { created: UserClient }>
484
+ },
472
485
  }
473
486
 
474
487
  export type PublicActions = {
475
488
  endusers: {
476
489
  login: CustomAction<
477
- { id?: string, email?: string, phone?: string, password: string, durationInSeconds: number },
490
+ { id?: string, email?: string, phone?: string, password: string, durationInSeconds: number, businessId: string, organizationIds?: string[] },
478
491
  { authToken: string }
479
492
  >,
480
493
  register: CustomAction<{
481
494
  emailConsent?: boolean, fname?: string, lname?: string, email: string, password: string,
482
495
  termsVersion?: string, termsSigned?: Date,
496
+ businessId: string, organizationIds?: string[],
483
497
  }, { }>,
484
- request_password_reset: CustomAction<{ email: string, businessId: string }, { }>,
485
- reset_password: CustomAction<{ resetToken: string, newPassword: string, businessId: string }, { }>,
498
+ request_password_reset: CustomAction<{ email: string, businessId: string, organizationIds?: string[] }, { }>,
499
+ reset_password: CustomAction<{ resetToken: string, newPassword: string, businessId: string, organizationIds?: string[] }, { }>,
486
500
  },
487
501
  users: {
488
502
  request_password_reset: CustomAction<{ email: string }, { }>,
489
503
  reset_password: CustomAction<{ resetToken: string, newPassword: string }, { }>,
490
504
  },
491
505
  organizations: {
492
- get_theme: CustomAction<{ businessId: string }, { theme: OrganizationTheme }>,
506
+ get_theme: CustomAction<{ businessId: string, organizationIds?: string[] }, { theme: OrganizationTheme }>,
493
507
  },
494
508
  form_responses: {
495
509
  session_for_public_form: CustomAction<{
@@ -498,7 +512,8 @@ export type PublicActions = {
498
512
  email: string,
499
513
  phone?: string,
500
514
  formId: string,
501
- businessId: string
515
+ businessId: string,
516
+ // organizationIds?: string[]
502
517
  }, { accessCode: string, authToken: string, url: string, path: string }>,
503
518
  },
504
519
  }
@@ -543,6 +558,15 @@ export const schema: SchemaV1 = build_schema({
543
558
  if (session.type === USER_SESSION_TYPE) return
544
559
  if (session.id !== _id?.toString()) return "Endusers may only update their own profile"
545
560
  }
561
+ }, {
562
+ explanation: "Enduser organizationIds can only be updated by users",
563
+ evaluate: ({ }, _, session, method, { updates }) => {
564
+ if (method === 'create') return // create already admin restricted
565
+ if (session.type === 'user') return
566
+ if (!updates?.organizationIds) return
567
+
568
+ return "Enduser organizationIds can only be updated by users"
569
+ }
546
570
  }
547
571
  ],
548
572
  access: [ // for non-admins, limit access to endusers the user is assigned to, by default
@@ -595,7 +619,7 @@ export const schema: SchemaV1 = build_schema({
595
619
  validator: nameValidator,
596
620
  },
597
621
  dateOfBirth: {
598
- validator: dateValidator,
622
+ validator: stringValidator250,
599
623
  redactions: ['enduser'],
600
624
  },
601
625
  journeys: {
@@ -664,6 +688,10 @@ export const schema: SchemaV1 = build_schema({
664
688
  },
665
689
  state: { validator: stateValidator },
666
690
  timezone: { validator: timezoneValidator },
691
+ gender: { validator: stringValidator25000EmptyOkay },
692
+ height: { validator: genericUnitWithQuantityValidator },
693
+ weight: { validator: genericUnitWithQuantityValidator },
694
+ zipCode: { validator: stringValidator25000EmptyOkay },
667
695
  // recentMessagePreview: {
668
696
  // validator: stringValidator,
669
697
  // },
@@ -762,6 +790,8 @@ export const schema: SchemaV1 = build_schema({
762
790
  description: "Generates an authentication token for access to enduser-facing endpoints",
763
791
  enduserOnly: true, // implemented as authenticate in enduser sdk only
764
792
  parameters: {
793
+ businessId: { validator: mongoIdStringValidator, required: true, },
794
+ organizationIds: { validator: listOfMongoIdStringValidatorEmptyOk },
765
795
  id: { validator: mongoIdStringValidator },
766
796
  phone: { validator: phoneValidator },
767
797
  email: { validator: emailValidator },
@@ -776,6 +806,8 @@ export const schema: SchemaV1 = build_schema({
776
806
  path: '/register-as-enduser',
777
807
  description: "Allows and enduser to register directly with an email and password",
778
808
  parameters: {
809
+ businessId: { validator: mongoIdStringValidator, required: true, },
810
+ organizationIds: { validator: listOfMongoIdStringValidatorEmptyOk },
779
811
  email: { validator: emailValidator, required: true },
780
812
  password: { validator: stringValidator100, required: true },
781
813
  fname: { validator: nameValidator },
@@ -793,7 +825,8 @@ export const schema: SchemaV1 = build_schema({
793
825
  description: "Sends a password reset email",
794
826
  parameters: {
795
827
  email: { validator: emailValidator, required: true },
796
- businessId: { validator: mongoIdStringValidator, required: true },
828
+ businessId: { validator: mongoIdStringValidator, required: true, },
829
+ organizationIds: { validator: listOfMongoIdStringValidatorEmptyOk },
797
830
  },
798
831
  returns: { },
799
832
  },
@@ -805,7 +838,8 @@ export const schema: SchemaV1 = build_schema({
805
838
  parameters: {
806
839
  resetToken: { validator: stringValidator250, required: true },
807
840
  newPassword: { validator: passwordValidator, required: true },
808
- businessId: { validator: mongoIdStringValidator, required: true },
841
+ businessId: { validator: mongoIdStringValidator, required: true, },
842
+ organizationIds: { validator: listOfMongoIdStringValidatorEmptyOk },
809
843
  },
810
844
  returns: { },
811
845
  },
@@ -1549,6 +1583,14 @@ export const schema: SchemaV1 = build_schema({
1549
1583
 
1550
1584
  return "Only admin users can update others' profiles"
1551
1585
  }
1586
+ }, {
1587
+ explanation: "User organizationIds are readonly",
1588
+ evaluate: ({ }, _, session, method, { updates }) => {
1589
+ if (method === 'create') return // only concerned with updates
1590
+ if (!updates?.organizationIds) return
1591
+
1592
+ return "User organizationIds are readonly"
1593
+ }
1552
1594
  }
1553
1595
  ],
1554
1596
  },
@@ -1661,7 +1703,8 @@ export const schema: SchemaV1 = build_schema({
1661
1703
  readonly: true, // able to set once, then not change (for now, due to email configuration)
1662
1704
  },
1663
1705
  accountType: {
1664
- validator: accountTypeValidator,
1706
+ validator: stringValidator,
1707
+ readonly: true,
1665
1708
  },
1666
1709
  roles: {
1667
1710
  validator: listOfStringsValidator,
@@ -3288,11 +3331,41 @@ export const schema: SchemaV1 = build_schema({
3288
3331
  organizations: {
3289
3332
  info: {},
3290
3333
  constraints: {
3291
- unique: ['name'],
3334
+ unique: [],
3335
+ globalUnique: ['subdomain'], // must be unique across all organizations in tellescope
3292
3336
  relationship: [],
3293
3337
  },
3294
- defaultActions: { read: { }, update: { adminOnly: true } },
3295
- customActions: { },
3338
+ defaultActions: { read: { }, readMany: { }, update: { adminOnly: true } },
3339
+ customActions: {
3340
+ create_suborganization: {
3341
+ op: "custom", access: 'create', method: "post",
3342
+ adminOnly: true,
3343
+ name: 'Create Sub Organization',
3344
+ path: '/sub-organization',
3345
+ description: "Creates a sub organization",
3346
+ parameters: {
3347
+ name: { validator: stringValidator250, required: true },
3348
+ subdomain: { validator: slugValidator, required: true },
3349
+ },
3350
+ returns: {
3351
+ created: { validator: 'organization' as any, required: true },
3352
+ }
3353
+ },
3354
+ invite_user: {
3355
+ op: "custom", access: 'create', method: "post",
3356
+ adminOnly: true,
3357
+ name: 'Invite User',
3358
+ path: '/invite-user-to-organization',
3359
+ description: "Invites a user to register for the given (sub)-organization",
3360
+ parameters: {
3361
+ email: { validator: emailValidator, required: true },
3362
+ organizationId: { validator: mongoIdStringValidator, required: true },
3363
+ },
3364
+ returns: {
3365
+ created: { validator: 'user' as any, required: true },
3366
+ }
3367
+ },
3368
+ },
3296
3369
  enduserActions: { },
3297
3370
  publicActions: {
3298
3371
  get_theme: {
@@ -3302,6 +3375,7 @@ export const schema: SchemaV1 = build_schema({
3302
3375
  description: "Gets theme information for an organization",
3303
3376
  parameters: {
3304
3377
  businessId: { validator: mongoIdStringValidator },
3378
+ organizationIds: { validator: listOfMongoIdStringValidatorEmptyOk },
3305
3379
  },
3306
3380
  returns: {
3307
3381
  theme: { validator: organizationThemeValidator, required: true },
@@ -3316,10 +3390,11 @@ export const schema: SchemaV1 = build_schema({
3316
3390
  examples: ["Template Name"],
3317
3391
  },
3318
3392
  subdomain: {
3319
- validator: stringValidator100,
3393
+ validator: slugValidator,
3320
3394
  required: true,
3321
3395
  examples: ["subdomain"],
3322
3396
  },
3397
+ parentOrganizationId: { validator: mongoIdStringValidator },
3323
3398
  subscriptionExpiresAt: { validator: dateValidator },
3324
3399
  subscriptionPeriod: { validator: numberValidator },
3325
3400
  logoVersion: { validator: numberValidator },
@@ -3514,7 +3589,7 @@ export const schema: SchemaV1 = build_schema({
3514
3589
  },
3515
3590
  defaultActions: {
3516
3591
  read: {}, readMany: {},
3517
- create: { adminOnly: true }, createMany: { adminOnly: true }, update: { adminOnly: true }, delete: { adminOnly: true },
3592
+ create: { rootAdminOnly: true }, createMany: { rootAdminOnly: true }, update: { rootAdminOnly: true }, delete: { rootAdminOnly: true },
3518
3593
  },
3519
3594
  customActions: {},
3520
3595
  enduserActions: {},