@tellescope/schema 0.0.8 → 0.0.12

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
@@ -13,12 +13,16 @@ import {
13
13
  JSONType,
14
14
  CRUD,
15
15
  HTTPMethod,
16
+ SessionType,
17
+ UserIdentity,
16
18
  } from "@tellescope/types-utilities"
17
19
  import {
18
20
  EnduserSession,
19
21
  ConfiguredSession,
20
22
  JourneyState,
21
23
  UserSession,
24
+ AttendeeInfo,
25
+ MeetingStatus,
22
26
  } from "@tellescope/types-models"
23
27
 
24
28
  import {
@@ -57,16 +61,24 @@ import {
57
61
  listOfDisplayNameInfo,
58
62
  fileTypeValidator,
59
63
  fileSizeValidator,
64
+ meetingStatusValidator,
65
+ listOfAttendeesValidator,
66
+ meetingInfoValidator,
67
+ listOfUserIndentitiesValidator,
68
+ attendeeInfoValidator,
69
+ listOfObjectAnyFieldsValidator,
70
+ meetingsListValidator,
60
71
  } from "@tellescope/validation"
61
72
 
62
73
  import {
63
74
  CREATOR_ONLY_ACCESS,
64
75
  DEFAULT_OPERATIONS,
65
76
  PLACEHOLDER_ID,
77
+ ENDUSER_SESSION_TYPE,
66
78
  } from "@tellescope/constants"
67
79
  export type RelationshipConstraint<T> = {
68
80
  explanation: string; // human readable, for documentation purposes
69
- evaluate: (v: T, dependencies: Indexable<Partial<DatabaseModel>>) => string | void;
81
+ evaluate: (v: T, dependencies: Indexable<Partial<DatabaseModel>>, session: UserSession | EnduserSession) => string | void;
70
82
  }
71
83
 
72
84
  export type DependencyAccessConstraint <T> = { type: 'dependency', foreignModel: ModelName, foreignField: string, accessField: keyof T }
@@ -84,7 +96,7 @@ export type Constraint <T> = {
84
96
  access?: AccessConstraint<T>[];
85
97
  }
86
98
 
87
- export type Initializer <T, R> = (a: T, s: ConfiguredSession | EnduserSession) => R
99
+ export type Initializer <T, R> = (a: T, s: UserSession | EnduserSession) => R
88
100
 
89
101
  export type EndpointOptions = {
90
102
  // parameters used for endpoint that aren't stored in the model
@@ -156,7 +168,7 @@ type ReadFilter <T> = { [K in keyof T]?: { required: boolean } }
156
168
 
157
169
  // m is the original model (or undefined, if create)
158
170
  // allows for easier event handling based on specific updates (by comparing args to pre-update model)
159
- export type SideEffectHandler <T, O=any> = (args: Partial<T>[], m: (Partial<T> | undefined)[] | undefined, n: (Partial<T> & { _id: ObjectId })[], s: ConfiguredSession | EnduserSession, o: O) => Promise<ErrorInfo[]>;
171
+ export type SideEffectHandler <T, O=any> = (args: Partial<T>[], m: (Partial<T> | undefined)[] | undefined, n: (Partial<T> & { _id: ObjectId })[], s: UserSession | EnduserSession, o: O) => Promise<ErrorInfo[]>;
160
172
 
161
173
  type SideEffect = {
162
174
  name: string;
@@ -250,7 +262,14 @@ export type CustomActions = {
250
262
  users: {
251
263
  display_names: CustomAction<{ }, { fname: string, lname: string, id: string }[]>,
252
264
  refresh_session: CustomAction<{}, { user: UserSession, authToken: string }>,
253
- }
265
+ },
266
+ meetings: {
267
+ start_meeting: CustomAction<{ }, { id: string, meeting: object, host: AttendeeInfo }>,
268
+ end_meeting: CustomAction<{ id: string }, { }>,
269
+ add_attendees_to_meeting: CustomAction<{ id: string, attendees: UserIdentity[] }, { }>,
270
+ my_meetings: CustomAction<{}, { id: string, updatedAt: string, status: MeetingStatus }[]>
271
+ attendee_info: CustomAction<{ id: string }, { attendee: AttendeeInfo, others: UserIdentity[] }>,
272
+ },
254
273
  }
255
274
 
256
275
  export type PublicActions = {
@@ -810,7 +829,7 @@ export const schema: SchemaV1 = {
810
829
  chat_rooms: {
811
830
  info: {},
812
831
  constraints: {
813
- unique: [{ array: 'userIds' }],
832
+ unique: [{ array: 'userIds' }, { array: 'enduserIds' }],
814
833
  relationship: [],
815
834
  access: [
816
835
  { type: 'filter', field: 'userIds' },
@@ -851,7 +870,13 @@ export const schema: SchemaV1 = {
851
870
  validator: mongoIdStringValidator,
852
871
  initializer: () => '',
853
872
  readonly: true,
854
- }
873
+ },
874
+ ticketId: {
875
+ validator: mongoIdStringValidator,
876
+ },
877
+ endedAt: {
878
+ validator: dateValidator,
879
+ },
855
880
  },
856
881
  defaultActions: DEFAULT_OPERATIONS,
857
882
  enduserActions: { create: {}, read: {}, readMany: {} },
@@ -985,6 +1010,9 @@ export const schema: SchemaV1 = {
985
1010
  roles: {
986
1011
  validator: listOfStringsValidator,
987
1012
  },
1013
+ skills: {
1014
+ validator: listOfStringsValidator,
1015
+ },
988
1016
  avatar: {
989
1017
  validator: stringValidator100,
990
1018
  dependencies: [
@@ -1095,5 +1123,140 @@ export const schema: SchemaV1 = {
1095
1123
  },
1096
1124
  },
1097
1125
  },
1098
- }
1126
+ },
1127
+ tickets: {
1128
+ info: {},
1129
+ constraints: {
1130
+ unique: [],
1131
+ relationship: [
1132
+ {
1133
+ explanation: 'When created by an enduser, enduserId must match their id',
1134
+ evaluate: ({ enduserId },_,session) => {
1135
+ if (session.type === ENDUSER_SESSION_TYPE && session.id !== enduserId)
1136
+ return "enduserId does not match creator id for enduser session"
1137
+ }
1138
+ },
1139
+ ],
1140
+ },
1141
+ defaultActions: DEFAULT_OPERATIONS,
1142
+ customActions: {},
1143
+ enduserActions: { create: {}, read: {}, readMany: {} },
1144
+ fields: {
1145
+ ...BuiltInFields,
1146
+ title: {
1147
+ validator: stringValidator100,
1148
+ required: true,
1149
+ examples: ["Ticket Name"],
1150
+ },
1151
+ enduserId: {
1152
+ validator: mongoIdStringValidator,
1153
+ required: true,
1154
+ examples: [PLACEHOLDER_ID],
1155
+ },
1156
+ closedAt: {
1157
+ validator: dateValidator,
1158
+ },
1159
+ owner: {
1160
+ validator: mongoIdStringValidator,
1161
+ },
1162
+ message: {
1163
+ validator: stringValidator5000,
1164
+ examples: ["Message"],
1165
+ },
1166
+ type: {
1167
+ validator: stringValidator100,
1168
+ },
1169
+ skillsRequired: {
1170
+ validator: listOfStringsValidator,
1171
+ },
1172
+ }
1173
+ },
1174
+ meetings: {
1175
+ info: {},
1176
+ constraints: {
1177
+ unique: [],
1178
+ relationship: [],
1179
+ },
1180
+ defaultActions: { },
1181
+ customActions: {
1182
+ start_meeting: {
1183
+ op: "custom", access: 'create', method: "post",
1184
+ name: 'Start Meeting',
1185
+ path: '/start-meeting',
1186
+ description: "Generates an video meeting room",
1187
+ parameters: { },
1188
+ returns: {
1189
+ id: {
1190
+ validator: mongoIdStringValidator,
1191
+ },
1192
+ meeting: {
1193
+ validator: objectAnyFieldsValidator,
1194
+ },
1195
+ host: {
1196
+ validator: attendeeInfoValidator,
1197
+ },
1198
+ },
1199
+ },
1200
+ end_meeting: {
1201
+ op: "custom", access: 'update', method: "post",
1202
+ name: "End Meeting",
1203
+ path: '/end-meeting',
1204
+ description: "Ends a video meeting",
1205
+ parameters: { id: { validator: mongoIdStringValidator } },
1206
+ returns: { },
1207
+ },
1208
+ add_attendees_to_meeting: {
1209
+ op: "custom", access: 'update', method: "post",
1210
+ name: 'Add Attendees to Meeting',
1211
+ path: '/add-attendees-to-meeting',
1212
+ description: "Adds other attendees to a meeting",
1213
+ parameters: {
1214
+ id: { validator: mongoIdStringValidator },
1215
+ attendees: { validator: listOfUserIndentitiesValidator },
1216
+ },
1217
+ returns: { },
1218
+ },
1219
+ attendee_info: {
1220
+ op: "custom", access: 'read', method: "get",
1221
+ name: 'Get attendee info for meeting',
1222
+ path: '/attendee-info',
1223
+ description: "Gets meeting info for the current user, and details about other attendees",
1224
+ parameters: {
1225
+ id: { validator: mongoIdStringValidator },
1226
+ },
1227
+ returns: {
1228
+ attendee: { validator: attendeeInfoValidator },
1229
+ others: { validator: listOfUserIndentitiesValidator },
1230
+ },
1231
+ },
1232
+ my_meetings: {
1233
+ op: "custom", access: 'read', method: "get",
1234
+ name: 'Get list of meetings',
1235
+ path: '/my-meetings',
1236
+ description: "Gets meetings for the current user.",
1237
+ parameters: {
1238
+ id: { validator: mongoIdStringValidator },
1239
+ },
1240
+ returns: { validator: meetingsListValidator },
1241
+ }
1242
+ },
1243
+ enduserActions: { my_meetings: {} },
1244
+ fields: {
1245
+ ...BuiltInFields,
1246
+ // all fields are updatable by custom endpoints only
1247
+ status: {
1248
+ validator: meetingStatusValidator,
1249
+ readonly: true,
1250
+ initializer: () => 'scheduled',
1251
+ },
1252
+ attendees: {
1253
+ validator: listOfAttendeesValidator,
1254
+ readonly: true,
1255
+ },
1256
+ meetingInfo: {
1257
+ validator: meetingInfoValidator,
1258
+ readonly: true
1259
+ }
1260
+ }
1261
+ },
1099
1262
  }