@tellescope/schema 1.3.46 → 1.4.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.
package/src/schema.ts CHANGED
@@ -31,6 +31,7 @@ import {
31
31
  MeetingInfo,
32
32
  PreviousFormField,
33
33
  OrganizationTheme,
34
+ AvailabilityBlock,
34
35
  } from "@tellescope/types-models"
35
36
 
36
37
  import {
@@ -128,6 +129,15 @@ import {
128
129
  databaseFieldsValidator,
129
130
  databaseRecordValuesValidator,
130
131
  automationEventsValidator,
132
+ portalPageValidator,
133
+ portalBlocksValidator,
134
+ enduserFormResponsesForEventValidator,
135
+ enduserTasksForEventValidator,
136
+ stateCredentialsValidator,
137
+ stateValidator,
138
+ availabilityBlocksValidator,
139
+ weeklyAvailabilitiesValidator,
140
+ timezoneValidator,
131
141
  } from "@tellescope/validation"
132
142
 
133
143
  import {
@@ -137,6 +147,7 @@ import {
137
147
  ENDUSER_SESSION_TYPE,
138
148
  USER_SESSION_TYPE,
139
149
  } from "@tellescope/constants"
150
+ import { response } from "express"
140
151
 
141
152
  export type RelationshipConstraint<T> = {
142
153
  explanation: string; // human readable, for documentation purposes
@@ -345,7 +356,9 @@ export type CustomActions = {
345
356
  file_download_URL: CustomAction<{ secureName: string }, { downloadURL: string }>,
346
357
  },
347
358
  form_responses: {
348
- prepare_form_response: CustomAction<{ formId: string, enduserId: string, automationStepId?: string }, { accessCode: string, url: string }>,
359
+ prepare_form_response: CustomAction<{ formId: string, enduserId: string, automationStepId?: string, expireAt?: Date },
360
+ { accessCode: string, url: string, response: FormResponse, }>
361
+ ,
349
362
  submit_form_response: CustomAction<{ accessCode: string, responses: FormResponseValue[], automationStepId?: string }, { formResponse: FormResponse }>,
350
363
  info_for_access_code: CustomAction<{ accessCode: string }, {
351
364
  form: Form,
@@ -417,7 +430,17 @@ export type CustomActions = {
417
430
  sync_integrations: CustomAction<{ enduserEmail: string }, { newEmails: Email[] }>,
418
431
  },
419
432
  calendar_events: {
420
- get_external_events_for_user: CustomAction<{ userId: string, from: Date, limit?: number }, { events: CalendarEvent[] }>,
433
+ get_events_for_user: CustomAction<{ userId: string, from: Date, to?: Date, limit?: number }, { events: CalendarEvent[] }>,
434
+ get_appointment_availability: CustomAction<{
435
+ from: Date, calendarEventTemplateId: string, to?: Date, restrictedByState?: boolean, limit?: number,
436
+ }, {
437
+ availabilityBlocks: AvailabilityBlock[],
438
+ }>,
439
+ book_appointment: CustomAction<{
440
+ userId: string, startTime: Date, calendarEventTemplateId: string,
441
+ }, {
442
+ createdEvent: CalendarEvent,
443
+ }>,
421
444
  },
422
445
  }
423
446
 
@@ -605,6 +628,7 @@ export const schema: SchemaV1 = build_schema({
605
628
  },
606
629
  ]
607
630
  },
631
+ state: { validator: stateValidator },
608
632
  // recentMessagePreview: {
609
633
  // validator: stringValidator,
610
634
  // },
@@ -1469,7 +1493,7 @@ export const schema: SchemaV1 = build_schema({
1469
1493
  }],
1470
1494
  },
1471
1495
  defaultActions: {
1472
- create: { adminOnly: true }, delete: { adminOnly: true },
1496
+ create: { adminOnly: true }, createMany: { adminOnly: true }, delete: { adminOnly: true },
1473
1497
  read: {}, readMany: {}, update: { description: "Users can only be updated by self or an organization admin"}
1474
1498
  },
1475
1499
  enduserActions: { display_info: {}, read: {}, readMany: {} },
@@ -1567,6 +1591,7 @@ export const schema: SchemaV1 = build_schema({
1567
1591
  lname: {
1568
1592
  validator: nameValidator,
1569
1593
  },
1594
+ suffixes: { validator: listOfStringsValidatorEmptyOk },
1570
1595
  organization: {
1571
1596
  validator: mongoIdStringValidator,
1572
1597
  updatesDisabled: true,
@@ -1611,6 +1636,11 @@ export const schema: SchemaV1 = build_schema({
1611
1636
  },
1612
1637
  ]
1613
1638
  },
1639
+ credentialedStates: {
1640
+ validator: stateCredentialsValidator,
1641
+ },
1642
+ timezone: { validator: timezoneValidator },
1643
+ weeklyAvailabilities: { validator: weeklyAvailabilitiesValidator },
1614
1644
  }
1615
1645
  },
1616
1646
  templates: {
@@ -2125,10 +2155,12 @@ export const schema: SchemaV1 = build_schema({
2125
2155
  formId: { validator: mongoIdStringValidator, required: true },
2126
2156
  enduserId: { validator: mongoIdStringValidator, required: true },
2127
2157
  automationStepId: { validator: mongoIdStringValidator },
2158
+ expireAt: { validator: dateValidator },
2128
2159
  },
2129
2160
  returns: {
2130
2161
  accessCode: { validator: stringValidator250, required: true },
2131
2162
  url: { validator: stringValidator250, required: true },
2163
+ response: { validator: 'form_response' as any, required: true }
2132
2164
  },
2133
2165
  },
2134
2166
  submit_form_response: {
@@ -2312,22 +2344,53 @@ export const schema: SchemaV1 = build_schema({
2312
2344
  },
2313
2345
  defaultActions: DEFAULT_OPERATIONS,
2314
2346
  customActions: {
2315
- get_external_events_for_user: {
2347
+ get_events_for_user: {
2316
2348
  op: "custom", access: 'read', method: "get",
2317
- name: 'Get External Events for User',
2318
- path: '/external-events-for-user',
2319
- description: "Gets events from external calendars, formatted as a Tellescope event",
2349
+ name: 'Get Events for User (Including Integrations)',
2350
+ path: '/events-for-user',
2351
+ description: "Combines internal and external events, formatted as a Tellescope events",
2320
2352
  parameters: {
2321
2353
  userId: { validator: mongoIdStringValidator, required: true },
2322
2354
  from: { validator: dateValidator, required: true },
2355
+ to: { validator: dateValidator },
2323
2356
  limit: { validator: nonNegNumberValidator },
2324
2357
  },
2325
2358
  returns: {
2326
2359
  events: { validator: 'calendar_events' as any }
2327
2360
  },
2328
2361
  },
2362
+ get_appointment_availability: {
2363
+ op: "custom", access: 'read', method: "get",
2364
+ name: 'Get Appointment Availability for a Calendar Event Type',
2365
+ path: '/calendar-availability',
2366
+ description: "Gets availability blocks for different users based on their internal and external calendars",
2367
+ parameters: {
2368
+ calendarEventTemplateId: { validator: mongoIdStringValidator, required: true },
2369
+ from: { validator: dateValidator, required: true },
2370
+ restrictedByState: { validator: booleanValidator },
2371
+ to: { validator: dateValidator },
2372
+ limit: { validator: nonNegNumberValidator },
2373
+ },
2374
+ returns: {
2375
+ availabilityBlocks: { validator: availabilityBlocksValidator }
2376
+ },
2377
+ },
2378
+ book_appointment: {
2379
+ op: "custom", access: 'create', method: "post",
2380
+ name: 'Book Appointment',
2381
+ path: '/book-appointment',
2382
+ description: "Books an appointment with a given user if available",
2383
+ parameters: {
2384
+ calendarEventTemplateId: { validator: mongoIdStringValidator, required: true },
2385
+ userId: { validator: mongoIdStringValidator, required: true },
2386
+ startTime: { validator: dateValidator, required: true },
2387
+ },
2388
+ returns: {
2389
+ createdEvent: { validator: 'calenar_event' as any },
2390
+ },
2391
+ },
2329
2392
  },
2330
- enduserActions: { read: {}, readMany: {} },
2393
+ enduserActions: { read: {}, readMany: {}, get_appointment_availability: {}, book_appointment: {} },
2331
2394
  fields: {
2332
2395
  ...BuiltInFields,
2333
2396
  title: {
@@ -2358,6 +2421,15 @@ export const schema: SchemaV1 = build_schema({
2358
2421
  onDependencyDelete: 'setNull',
2359
2422
  }]
2360
2423
  },
2424
+ carePlanId: {
2425
+ validator: mongoIdStringValidator,
2426
+ dependencies: [{
2427
+ dependsOn: ['care_plans'],
2428
+ dependencyField: '_id',
2429
+ relationship: 'foreignKey',
2430
+ onDependencyDelete: 'setNull',
2431
+ }]
2432
+ },
2361
2433
  attendees: {
2362
2434
  validator: listOfUserIndentitiesValidator,
2363
2435
  initializer: () => [],
@@ -2372,7 +2444,7 @@ export const schema: SchemaV1 = build_schema({
2372
2444
  dependsOn: ['calendar_event_templates'],
2373
2445
  dependencyField: '_id',
2374
2446
  relationship: 'foreignKey',
2375
- onDependencyDelete: 'delete',
2447
+ onDependencyDelete: 'nop',
2376
2448
  }]
2377
2449
  },
2378
2450
  publicRead: { validator: booleanValidator },
@@ -2380,6 +2452,11 @@ export const schema: SchemaV1 = build_schema({
2380
2452
  fields: { validator: fieldsValidator },
2381
2453
  numRSVPs: { validator: nonNegNumberValidator },
2382
2454
  image: { validator: stringValidator5000 },
2455
+ sharedContentIds: { validator: listOfMongoIdStringValidatorEmptyOk },
2456
+ enduserFormResponses: { validator: enduserFormResponsesForEventValidator },
2457
+ enduserTasks: { validator: enduserTasksForEventValidator },
2458
+ location: { validator: stringValidator1000 },
2459
+ phone: { validator: stringValidator100 }, // leave more generous than phone validator in favor of lower friction
2383
2460
  }
2384
2461
  },
2385
2462
  calendar_event_templates: {
@@ -2455,25 +2532,6 @@ export const schema: SchemaV1 = build_schema({
2455
2532
  }
2456
2533
  }
2457
2534
  },
2458
- sequence_automations: {
2459
- info: {},
2460
- constraints: {
2461
- unique: [],
2462
- relationship: [],
2463
- access: []
2464
- },
2465
- defaultActions: DEFAULT_OPERATIONS,
2466
- customActions: { },
2467
- enduserActions: { },
2468
- fields: {
2469
- ...BuiltInFields,
2470
- title: {
2471
- validator: stringValidator250,
2472
- required: true,
2473
- examples: ['Automation Title']
2474
- }
2475
- }
2476
- },
2477
2535
  automation_steps: {
2478
2536
  info: {},
2479
2537
  constraints: {
@@ -2757,6 +2815,9 @@ export const schema: SchemaV1 = build_schema({
2757
2815
  required: true,
2758
2816
  examples: ["Template Name"],
2759
2817
  },
2818
+ category: {
2819
+ validator: stringValidator100,
2820
+ },
2760
2821
  description: {
2761
2822
  validator: stringValidator5000,
2762
2823
  examples: ["Template Subject"],
@@ -3180,6 +3241,118 @@ export const schema: SchemaV1 = build_schema({
3180
3241
  },
3181
3242
  },
3182
3243
  },
3244
+ portal_customizations: {
3245
+ info: {},
3246
+ constraints: {
3247
+ unique: [
3248
+ 'page' // prevents duplicate customizations for the same page (may need to combine with a version number / draft status later to allow drafting)
3249
+ ],
3250
+ relationship: [
3251
+ {
3252
+ explanation: 'One of email or phone is required',
3253
+ evaluate: ({ page, disabled }) => {
3254
+ if (page === 'Home' && disabled)
3255
+ return 'Home page cannot be disabled'
3256
+ }
3257
+ },
3258
+ ],
3259
+ access: []
3260
+ },
3261
+ defaultActions: DEFAULT_OPERATIONS,
3262
+ customActions: { },
3263
+ enduserActions: { readMany: {} },
3264
+ fields: {
3265
+ ...BuiltInFields,
3266
+ title: {
3267
+ validator: stringValidator1000,
3268
+ examples: ['Example Title']
3269
+ },
3270
+ page: {
3271
+ validator: portalPageValidator,
3272
+ required: true,
3273
+ examples: ['Home']
3274
+ },
3275
+ blocks: {
3276
+ required: true,
3277
+ examples: [[]],
3278
+ validator: portalBlocksValidator,
3279
+ },
3280
+ disabled: { validator: booleanValidator },
3281
+ mobileBottomNavigationPosition: { validator: nonNegNumberValidator },
3282
+ },
3283
+ },
3284
+ enduser_tasks: {
3285
+ info: {},
3286
+ constraints: {
3287
+ unique: [
3288
+ ['enduserId', 'title']
3289
+ ],
3290
+ relationship: [],
3291
+ access: []
3292
+ },
3293
+ defaultActions: DEFAULT_OPERATIONS,
3294
+ customActions: { },
3295
+ enduserActions: { update: {}, read: {}, readMany: {} },
3296
+ fields: {
3297
+ ...BuiltInFields,
3298
+ title: {
3299
+ validator: stringValidator1000,
3300
+ required: true,
3301
+ examples: ['Example Title']
3302
+ },
3303
+ enduserId: {
3304
+ validator: mongoIdStringValidator,
3305
+ examples: [PLACEHOLDER_ID],
3306
+ required: true,
3307
+ dependencies: [{
3308
+ dependsOn: ['endusers'],
3309
+ dependencyField: '_id',
3310
+ relationship: 'foreignKey',
3311
+ onDependencyDelete: 'delete',
3312
+ }]
3313
+ },
3314
+ completedAt: { validator: dateValidator },
3315
+ description: { validator: stringValidator1000 },
3316
+ },
3317
+ },
3318
+ care_plans: {
3319
+ info: {},
3320
+ constraints: {
3321
+ unique: [
3322
+ ['enduserId', 'title']
3323
+ ],
3324
+ relationship: [],
3325
+ access: []
3326
+ },
3327
+ defaultActions: DEFAULT_OPERATIONS,
3328
+ customActions: { },
3329
+ enduserActions: { read: {}, readMany: {} },
3330
+ fields: {
3331
+ ...BuiltInFields,
3332
+ title: {
3333
+ validator: stringValidator1000,
3334
+ required: true,
3335
+ examples: ['Example Title']
3336
+ },
3337
+ enduserId: {
3338
+ validator: mongoIdStringValidator,
3339
+ examples: [PLACEHOLDER_ID],
3340
+ required: true,
3341
+ dependencies: [{
3342
+ dependsOn: ['endusers'],
3343
+ dependencyField: '_id',
3344
+ relationship: 'foreignKey',
3345
+ onDependencyDelete: 'delete',
3346
+ }]
3347
+ },
3348
+ description: {
3349
+ validator: stringValidator1000,
3350
+ },
3351
+ eventIds: {
3352
+ validator: listOfMongoIdStringValidatorEmptyOk,
3353
+ }
3354
+ },
3355
+ },
3183
3356
  })
3184
3357
 
3185
3358
  // export type SchemaType = typeof schema