@tellescope/schema 0.0.9 → 0.0.13
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/lib/cjs/schema.d.ts +42 -5
- package/lib/cjs/schema.d.ts.map +1 -1
- package/lib/cjs/schema.js +160 -6
- package/lib/cjs/schema.js.map +1 -1
- package/lib/esm/schema.d.ts +42 -5
- package/lib/esm/schema.d.ts.map +1 -1
- package/lib/esm/schema.js +162 -8
- package/lib/esm/schema.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +7 -7
- package/src/schema.ts +206 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tellescope/schema",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.13",
|
|
4
4
|
"description": "Schema definition for Tellescope models",
|
|
5
5
|
"main": "./lib/cjs/schema.js",
|
|
6
6
|
"module": "./lib/esm/schema.js",
|
|
@@ -23,11 +23,11 @@
|
|
|
23
23
|
},
|
|
24
24
|
"homepage": "https://github.com/tellescope-os/tellescope#readme",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@tellescope/constants": "^0.0.
|
|
27
|
-
"@tellescope/types-models": "^0.0.
|
|
28
|
-
"@tellescope/types-server": "^0.0.
|
|
29
|
-
"@tellescope/types-utilities": "^0.0.
|
|
30
|
-
"@tellescope/validation": "^0.0.
|
|
26
|
+
"@tellescope/constants": "^0.0.13",
|
|
27
|
+
"@tellescope/types-models": "^0.0.13",
|
|
28
|
+
"@tellescope/types-server": "^0.0.13",
|
|
29
|
+
"@tellescope/types-utilities": "^0.0.13",
|
|
30
|
+
"@tellescope/validation": "^0.0.13",
|
|
31
31
|
"validator": "^13.1.17"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"publishConfig": {
|
|
43
43
|
"access": "public"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "1eb38568bd39b941e6b4a2bad9e3b33841c26b39"
|
|
46
46
|
}
|
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
|
+
ChatRoom,
|
|
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
|
|
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:
|
|
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:
|
|
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;
|
|
@@ -245,12 +257,23 @@ export type CustomActions = {
|
|
|
245
257
|
{ isAuthenticated: true, enduser: Enduser } | { isAuthenticated: false, enduser: null }
|
|
246
258
|
>,
|
|
247
259
|
refresh_session: CustomAction<{}, { enduser: Enduser, authToken: string }>,
|
|
260
|
+
generate_auth_token: CustomAction<{ id: string }, { authToken: string }>,
|
|
248
261
|
logout: CustomAction<{ }, { }>,
|
|
249
262
|
},
|
|
250
263
|
users: {
|
|
251
264
|
display_names: CustomAction<{ }, { fname: string, lname: string, id: string }[]>,
|
|
252
265
|
refresh_session: CustomAction<{}, { user: UserSession, authToken: string }>,
|
|
253
|
-
}
|
|
266
|
+
},
|
|
267
|
+
chat_rooms: {
|
|
268
|
+
join_room: CustomAction<{ id: string }, { room: ChatRoom }>,
|
|
269
|
+
},
|
|
270
|
+
meetings: {
|
|
271
|
+
start_meeting: CustomAction<{ }, { id: string, meeting: object, host: AttendeeInfo }>,
|
|
272
|
+
end_meeting: CustomAction<{ id: string }, { }>,
|
|
273
|
+
add_attendees_to_meeting: CustomAction<{ id: string, attendees: UserIdentity[] }, { }>,
|
|
274
|
+
my_meetings: CustomAction<{}, { id: string, updatedAt: string, status: MeetingStatus }[]>
|
|
275
|
+
attendee_info: CustomAction<{ id: string }, { attendee: AttendeeInfo, others: UserIdentity[] }>,
|
|
276
|
+
},
|
|
254
277
|
}
|
|
255
278
|
|
|
256
279
|
export type PublicActions = {
|
|
@@ -325,6 +348,9 @@ export const schema: SchemaV1 = {
|
|
|
325
348
|
lname: {
|
|
326
349
|
validator: nameValidator,
|
|
327
350
|
},
|
|
351
|
+
dateOfBirth: {
|
|
352
|
+
validator: dateValidator,
|
|
353
|
+
},
|
|
328
354
|
journeys: {
|
|
329
355
|
validator: journeysValidator,
|
|
330
356
|
dependencies: [
|
|
@@ -412,6 +438,14 @@ export const schema: SchemaV1 = {
|
|
|
412
438
|
enduser: { validator: 'enduser' },
|
|
413
439
|
} as any // todo: add enduser eventually, when validator defined
|
|
414
440
|
},
|
|
441
|
+
generate_auth_token: {
|
|
442
|
+
op: "custom", access: 'create', method: "get",
|
|
443
|
+
name: 'Generate authToken',
|
|
444
|
+
path: '/generate-enduser-auth-token',
|
|
445
|
+
description: "Generates an authToken for use by an enduser. Useful for integrating a 3rd-party authentication process or creating a session for an enduser without a set password in Tellescope.",
|
|
446
|
+
parameters: { id: { validator: mongoIdStringValidator } },
|
|
447
|
+
returns: { authToken: { validator: stringValidator100 } },
|
|
448
|
+
},
|
|
415
449
|
logout: {
|
|
416
450
|
op: "custom", access: 'update', method: "post",
|
|
417
451
|
name: 'Logout enduser',
|
|
@@ -810,7 +844,7 @@ export const schema: SchemaV1 = {
|
|
|
810
844
|
chat_rooms: {
|
|
811
845
|
info: {},
|
|
812
846
|
constraints: {
|
|
813
|
-
unique: [{ array: 'userIds' }],
|
|
847
|
+
unique: [{ array: 'userIds' }, { array: 'enduserIds' }],
|
|
814
848
|
relationship: [],
|
|
815
849
|
access: [
|
|
816
850
|
{ type: 'filter', field: 'userIds' },
|
|
@@ -834,8 +868,8 @@ export const schema: SchemaV1 = {
|
|
|
834
868
|
},
|
|
835
869
|
userIds: {
|
|
836
870
|
validator: listOfMongoIdStringValidator,
|
|
837
|
-
required: true,
|
|
838
871
|
examples: [[PLACEHOLDER_ID]],
|
|
872
|
+
// required: true, // no longer required
|
|
839
873
|
// add pull dependency for user deletion?
|
|
840
874
|
},
|
|
841
875
|
enduserIds: {
|
|
@@ -851,11 +885,31 @@ export const schema: SchemaV1 = {
|
|
|
851
885
|
validator: mongoIdStringValidator,
|
|
852
886
|
initializer: () => '',
|
|
853
887
|
readonly: true,
|
|
854
|
-
}
|
|
888
|
+
},
|
|
889
|
+
ticketId: {
|
|
890
|
+
validator: mongoIdStringValidator,
|
|
891
|
+
},
|
|
892
|
+
endedAt: {
|
|
893
|
+
validator: dateValidator,
|
|
894
|
+
},
|
|
895
|
+
tags: {
|
|
896
|
+
validator: listOfStringsValidator,
|
|
897
|
+
},
|
|
855
898
|
},
|
|
856
899
|
defaultActions: DEFAULT_OPERATIONS,
|
|
857
900
|
enduserActions: { create: {}, read: {}, readMany: {} },
|
|
858
|
-
customActions: {
|
|
901
|
+
customActions: {
|
|
902
|
+
join_room: {
|
|
903
|
+
op: "custom", access: 'update', method: "post",
|
|
904
|
+
name: 'Join chat room',
|
|
905
|
+
path: '/join-chat-room',
|
|
906
|
+
description: "Allows a user to join a chat room with no other users, for use in accepting support chats.",
|
|
907
|
+
parameters: { id: { validator: mongoIdStringValidator } },
|
|
908
|
+
returns: {
|
|
909
|
+
room: { validator: 'Room' },
|
|
910
|
+
} as any // add room eventually, when validator defined
|
|
911
|
+
},
|
|
912
|
+
},
|
|
859
913
|
},
|
|
860
914
|
chats: {
|
|
861
915
|
info: {
|
|
@@ -891,7 +945,7 @@ export const schema: SchemaV1 = {
|
|
|
891
945
|
senderId: {
|
|
892
946
|
validator: mongoIdStringValidator,
|
|
893
947
|
readonly: true, // create a separate endpoint for storing enduser chats
|
|
894
|
-
initializer: (a, s) =>
|
|
948
|
+
initializer: (a, s) => s.id,
|
|
895
949
|
examples: [PLACEHOLDER_ID],
|
|
896
950
|
dependencies: [{ // can be userId or enduserId
|
|
897
951
|
dependsOn: ['users', 'endusers'],
|
|
@@ -950,7 +1004,6 @@ export const schema: SchemaV1 = {
|
|
|
950
1004
|
enduser: { validator: 'user' },
|
|
951
1005
|
} as any // add enduser eventually, when validator defined
|
|
952
1006
|
},
|
|
953
|
-
|
|
954
1007
|
},
|
|
955
1008
|
enduserActions: { display_names: {} },
|
|
956
1009
|
fields: {
|
|
@@ -985,6 +1038,9 @@ export const schema: SchemaV1 = {
|
|
|
985
1038
|
roles: {
|
|
986
1039
|
validator: listOfStringsValidator,
|
|
987
1040
|
},
|
|
1041
|
+
skills: {
|
|
1042
|
+
validator: listOfStringsValidator,
|
|
1043
|
+
},
|
|
988
1044
|
avatar: {
|
|
989
1045
|
validator: stringValidator100,
|
|
990
1046
|
dependencies: [
|
|
@@ -1095,5 +1151,143 @@ export const schema: SchemaV1 = {
|
|
|
1095
1151
|
},
|
|
1096
1152
|
},
|
|
1097
1153
|
},
|
|
1098
|
-
}
|
|
1154
|
+
},
|
|
1155
|
+
tickets: {
|
|
1156
|
+
info: {},
|
|
1157
|
+
constraints: {
|
|
1158
|
+
unique: [],
|
|
1159
|
+
relationship: [
|
|
1160
|
+
{
|
|
1161
|
+
explanation: 'When created by an enduser, enduserId must match their id',
|
|
1162
|
+
evaluate: ({ enduserId },_,session) => {
|
|
1163
|
+
if (session.type === ENDUSER_SESSION_TYPE && session.id !== enduserId)
|
|
1164
|
+
return "enduserId does not match creator id for enduser session"
|
|
1165
|
+
}
|
|
1166
|
+
},
|
|
1167
|
+
],
|
|
1168
|
+
},
|
|
1169
|
+
defaultActions: DEFAULT_OPERATIONS,
|
|
1170
|
+
customActions: {},
|
|
1171
|
+
enduserActions: { create: {}, read: {}, readMany: {} },
|
|
1172
|
+
fields: {
|
|
1173
|
+
...BuiltInFields,
|
|
1174
|
+
title: {
|
|
1175
|
+
validator: stringValidator100,
|
|
1176
|
+
required: true,
|
|
1177
|
+
examples: ["Ticket Name"],
|
|
1178
|
+
},
|
|
1179
|
+
enduserId: {
|
|
1180
|
+
validator: mongoIdStringValidator,
|
|
1181
|
+
required: true,
|
|
1182
|
+
examples: [PLACEHOLDER_ID],
|
|
1183
|
+
},
|
|
1184
|
+
chatRoomId: {
|
|
1185
|
+
validator: mongoIdStringValidator,
|
|
1186
|
+
},
|
|
1187
|
+
closedAt: {
|
|
1188
|
+
validator: dateValidator,
|
|
1189
|
+
},
|
|
1190
|
+
owner: {
|
|
1191
|
+
validator: mongoIdStringValidator,
|
|
1192
|
+
},
|
|
1193
|
+
message: {
|
|
1194
|
+
validator: stringValidator5000,
|
|
1195
|
+
examples: ["Message"],
|
|
1196
|
+
},
|
|
1197
|
+
type: {
|
|
1198
|
+
validator: stringValidator100,
|
|
1199
|
+
},
|
|
1200
|
+
skillsRequired: {
|
|
1201
|
+
validator: listOfStringsValidator,
|
|
1202
|
+
},
|
|
1203
|
+
}
|
|
1204
|
+
},
|
|
1205
|
+
meetings: {
|
|
1206
|
+
info: {},
|
|
1207
|
+
constraints: {
|
|
1208
|
+
unique: [],
|
|
1209
|
+
relationship: [],
|
|
1210
|
+
},
|
|
1211
|
+
defaultActions: { },
|
|
1212
|
+
customActions: {
|
|
1213
|
+
start_meeting: {
|
|
1214
|
+
op: "custom", access: 'create', method: "post",
|
|
1215
|
+
name: 'Start Meeting',
|
|
1216
|
+
path: '/start-meeting',
|
|
1217
|
+
description: "Generates an video meeting room",
|
|
1218
|
+
parameters: { },
|
|
1219
|
+
returns: {
|
|
1220
|
+
id: {
|
|
1221
|
+
validator: mongoIdStringValidator,
|
|
1222
|
+
},
|
|
1223
|
+
meeting: {
|
|
1224
|
+
validator: objectAnyFieldsValidator,
|
|
1225
|
+
},
|
|
1226
|
+
host: {
|
|
1227
|
+
validator: attendeeInfoValidator,
|
|
1228
|
+
},
|
|
1229
|
+
},
|
|
1230
|
+
},
|
|
1231
|
+
end_meeting: {
|
|
1232
|
+
op: "custom", access: 'update', method: "post",
|
|
1233
|
+
name: "End Meeting",
|
|
1234
|
+
path: '/end-meeting',
|
|
1235
|
+
description: "Ends a video meeting",
|
|
1236
|
+
parameters: { id: { validator: mongoIdStringValidator } },
|
|
1237
|
+
returns: { },
|
|
1238
|
+
},
|
|
1239
|
+
add_attendees_to_meeting: {
|
|
1240
|
+
op: "custom", access: 'update', method: "post",
|
|
1241
|
+
name: 'Add Attendees to Meeting',
|
|
1242
|
+
path: '/add-attendees-to-meeting',
|
|
1243
|
+
description: "Adds other attendees to a meeting",
|
|
1244
|
+
parameters: {
|
|
1245
|
+
id: { validator: mongoIdStringValidator },
|
|
1246
|
+
attendees: { validator: listOfUserIndentitiesValidator },
|
|
1247
|
+
},
|
|
1248
|
+
returns: { },
|
|
1249
|
+
},
|
|
1250
|
+
attendee_info: {
|
|
1251
|
+
op: "custom", access: 'read', method: "get",
|
|
1252
|
+
name: 'Get attendee info for meeting',
|
|
1253
|
+
path: '/attendee-info',
|
|
1254
|
+
description: "Gets meeting info for the current user, and details about other attendees",
|
|
1255
|
+
parameters: {
|
|
1256
|
+
id: { validator: mongoIdStringValidator },
|
|
1257
|
+
},
|
|
1258
|
+
returns: {
|
|
1259
|
+
attendee: { validator: attendeeInfoValidator },
|
|
1260
|
+
others: { validator: listOfUserIndentitiesValidator },
|
|
1261
|
+
},
|
|
1262
|
+
},
|
|
1263
|
+
my_meetings: {
|
|
1264
|
+
op: "custom", access: 'read', method: "get",
|
|
1265
|
+
name: 'Get list of meetings',
|
|
1266
|
+
path: '/my-meetings',
|
|
1267
|
+
description: "Gets meetings for the current user.",
|
|
1268
|
+
parameters: {
|
|
1269
|
+
id: { validator: mongoIdStringValidator },
|
|
1270
|
+
},
|
|
1271
|
+
returns: { validator: meetingsListValidator },
|
|
1272
|
+
}
|
|
1273
|
+
},
|
|
1274
|
+
enduserActions: { my_meetings: {} },
|
|
1275
|
+
fields: {
|
|
1276
|
+
...BuiltInFields,
|
|
1277
|
+
// all fields are updatable by custom endpoints only
|
|
1278
|
+
status: {
|
|
1279
|
+
validator: meetingStatusValidator,
|
|
1280
|
+
readonly: true,
|
|
1281
|
+
initializer: () => 'scheduled',
|
|
1282
|
+
},
|
|
1283
|
+
attendees: {
|
|
1284
|
+
validator: listOfAttendeesValidator,
|
|
1285
|
+
readonly: true,
|
|
1286
|
+
},
|
|
1287
|
+
meetingInfo: {
|
|
1288
|
+
validator: meetingInfoValidator,
|
|
1289
|
+
readonly: true
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
},
|
|
1099
1293
|
}
|