@tellescope/sdk 1.13.0 → 1.13.2
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/enduser.d.ts +0 -217
- package/lib/cjs/enduser.d.ts.map +1 -1
- package/lib/cjs/sdk.d.ts +8 -219
- package/lib/cjs/sdk.d.ts.map +1 -1
- package/lib/cjs/sdk.js +27 -1
- package/lib/cjs/sdk.js.map +1 -1
- package/lib/cjs/session.d.ts +3 -1
- package/lib/cjs/session.d.ts.map +1 -1
- package/lib/cjs/session.js +30 -12
- package/lib/cjs/session.js.map +1 -1
- package/lib/cjs/tests/tests.d.ts.map +1 -1
- package/lib/cjs/tests/tests.js +8 -5
- package/lib/cjs/tests/tests.js.map +1 -1
- package/lib/cjs/tests/webhooks_tests.js +1 -0
- package/lib/cjs/tests/webhooks_tests.js.map +1 -1
- package/lib/esm/enduser.d.ts +0 -217
- package/lib/esm/enduser.d.ts.map +1 -1
- package/lib/esm/sdk.d.ts +10 -221
- package/lib/esm/sdk.d.ts.map +1 -1
- package/lib/esm/sdk.js +25 -0
- package/lib/esm/sdk.js.map +1 -1
- package/lib/esm/session.d.ts +3 -2
- package/lib/esm/session.d.ts.map +1 -1
- package/lib/esm/session.js +30 -12
- package/lib/esm/session.js.map +1 -1
- package/lib/esm/tests/tests.d.ts.map +1 -1
- package/lib/esm/tests/tests.js +8 -5
- package/lib/esm/tests/tests.js.map +1 -1
- package/lib/esm/tests/webhooks_tests.js +1 -0
- package/lib/esm/tests/webhooks_tests.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +8 -8
- package/src/sdk.ts +26 -2
- package/src/session.ts +32 -13
- package/src/tests/tests.ts +6 -3
- package/src/tests/webhooks_tests.ts +1 -0
package/src/sdk.ts
CHANGED
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
AccessPermissions,
|
|
15
15
|
OrganizationLimits,
|
|
16
16
|
SortBy,
|
|
17
|
+
AnalyticsQuery,
|
|
17
18
|
} from "@tellescope/types-models"
|
|
18
19
|
|
|
19
20
|
import {
|
|
@@ -27,7 +28,7 @@ import {
|
|
|
27
28
|
CreateFields,
|
|
28
29
|
User,
|
|
29
30
|
} from "@tellescope/types-client"
|
|
30
|
-
import { CustomUpdateOptions, SortOption,
|
|
31
|
+
import { CustomUpdateOptions, SortOption, UserIdentity, FileDetails, ReactNativeFile, SessionType } from "@tellescope/types-utilities"
|
|
31
32
|
import { url_safe_path } from "@tellescope/utilities"
|
|
32
33
|
|
|
33
34
|
import { Session as SessionManager, SessionOptions } from "./session"
|
|
@@ -35,6 +36,29 @@ import { Session as SessionManager, SessionOptions } from "./session"
|
|
|
35
36
|
export * from "./public"
|
|
36
37
|
export * from "./enduser"
|
|
37
38
|
|
|
39
|
+
|
|
40
|
+
export const load_all_pages = async <T extends { id: string }>(load: LoadFunction<T>, o?: LoadFunctionArguments<T> & { maxPages?: number }, ) => {
|
|
41
|
+
const toReturn = [] as T[]
|
|
42
|
+
const maxPages = o?.maxPages ?? 100000
|
|
43
|
+
|
|
44
|
+
let i = 0
|
|
45
|
+
while (true) {
|
|
46
|
+
if (i++ > maxPages) break;
|
|
47
|
+
|
|
48
|
+
const loaded = await load({
|
|
49
|
+
...o,
|
|
50
|
+
limit: 1000,
|
|
51
|
+
lastId: toReturn[toReturn.length - 1]?.id,
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
toReturn.push(...loaded)
|
|
55
|
+
|
|
56
|
+
if (loaded.length < 1000) break;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return toReturn
|
|
60
|
+
}
|
|
61
|
+
|
|
38
62
|
export interface LoadFunctionArguments <T> {
|
|
39
63
|
lastId?: string,
|
|
40
64
|
limit?: number,
|
|
@@ -43,6 +67,7 @@ export interface LoadFunctionArguments <T> {
|
|
|
43
67
|
from?: Date | number,
|
|
44
68
|
threadKey?: string,
|
|
45
69
|
filter?: ReadFilter<T>,
|
|
70
|
+
analyticsQuery?: AnalyticsQuery,
|
|
46
71
|
search?: SearchOptions,
|
|
47
72
|
ids?: string[],
|
|
48
73
|
}
|
|
@@ -52,7 +77,6 @@ export type LoadFunction<T> = (o?: LoadFunctionArguments<T>) => Promise<T[]>
|
|
|
52
77
|
export interface APIQuery<
|
|
53
78
|
N extends keyof ClientModelForName,
|
|
54
79
|
T=ClientModelForName[N],
|
|
55
|
-
Req=ClientModelForName_required[N],
|
|
56
80
|
CREATE=CreateFields<N>,
|
|
57
81
|
UPDATE=Omit<Partial<T>, keyof (ClientModelForName_readonly[N] & ClientModelForName_updatesDisabled[N])> & { organizationIds?: string[], sharedWithOrganizations?: string[][] },
|
|
58
82
|
>
|
package/src/session.ts
CHANGED
|
@@ -24,7 +24,7 @@ export interface SessionOptions {
|
|
|
24
24
|
cacheKey?: string;
|
|
25
25
|
expirationInSeconds?: number,
|
|
26
26
|
enableSocketLogging?: boolean,
|
|
27
|
-
handleUnauthenticated?: () => Promise<
|
|
27
|
+
handleUnauthenticated?: () => Promise<any>;
|
|
28
28
|
autoRefreshInMS?: number,
|
|
29
29
|
}
|
|
30
30
|
|
|
@@ -81,6 +81,8 @@ export class Session {
|
|
|
81
81
|
sessionStart = Date.now();
|
|
82
82
|
AUTO_REFRESH_MS = 3600000 // 1hr elapsed
|
|
83
83
|
lastSocketConnection: number;
|
|
84
|
+
handlers: Record<string, Function>
|
|
85
|
+
loadedSocketEvents: Record<string, any[]>
|
|
84
86
|
|
|
85
87
|
config: { headers: { Authorization: string }};
|
|
86
88
|
|
|
@@ -93,6 +95,9 @@ export class Session {
|
|
|
93
95
|
|
|
94
96
|
this.lastSocketConnection = 0;
|
|
95
97
|
|
|
98
|
+
this.handlers = {};
|
|
99
|
+
this.loadedSocketEvents = {};
|
|
100
|
+
|
|
96
101
|
this.host= o.host ?? DEFAULT_HOST
|
|
97
102
|
this.apiKey = o.apiKey ?? '';
|
|
98
103
|
this.servicesSecret = o.servicesSecret;
|
|
@@ -173,8 +178,10 @@ export class Session {
|
|
|
173
178
|
errorHandler = async (_err: any) => {
|
|
174
179
|
const err = parseError(_err)
|
|
175
180
|
if (err === 'Unauthenticated') {
|
|
176
|
-
this.
|
|
177
|
-
|
|
181
|
+
const refreshed = await this.handleUnauthenticated?.()
|
|
182
|
+
if (!refreshed) {
|
|
183
|
+
this.clearState()
|
|
184
|
+
}
|
|
178
185
|
}
|
|
179
186
|
|
|
180
187
|
return err
|
|
@@ -280,25 +287,29 @@ export class Session {
|
|
|
280
287
|
|
|
281
288
|
handle_events = ( handlers: { [index: string]: (a: any) => void } ) => {
|
|
282
289
|
for (const handler in handlers) {
|
|
283
|
-
//
|
|
284
|
-
|
|
290
|
+
// load any data that was pushed to this event while handler was off
|
|
291
|
+
const loadedData = this.loadedSocketEvents[handler]
|
|
292
|
+
if (Array.isArray(loadedData) && loadedData.length > 0) {
|
|
293
|
+
this.loadedSocketEvents[handler] = []
|
|
285
294
|
|
|
286
|
-
|
|
287
|
-
|
|
295
|
+
handlers[handler](loadedData)
|
|
296
|
+
}
|
|
288
297
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
298
|
+
// set handler on to load data directly for an event
|
|
299
|
+
this.handlers[handler] = handlers[handler]
|
|
300
|
+
}
|
|
292
301
|
}
|
|
293
302
|
|
|
294
303
|
unsubscribe = (roomIds: string[]) => this.EMIT('leave-rooms', { roomIds })
|
|
295
304
|
removeAllSocketListeners = () => {
|
|
296
305
|
if (this.enableSocketLogging) { console.log('removeAllSocketListeners') }
|
|
297
306
|
this.socket?.removeAllListeners()
|
|
307
|
+
this.handlers = {}
|
|
298
308
|
}
|
|
299
309
|
|
|
300
310
|
removeListenersForEvent = (event: string) => {
|
|
301
311
|
this.socket?.removeListener(event)
|
|
312
|
+
delete this.handlers[event]
|
|
302
313
|
}
|
|
303
314
|
|
|
304
315
|
socket_log = (message: string) => {
|
|
@@ -342,9 +353,17 @@ export class Session {
|
|
|
342
353
|
if (this.enableSocketLogging) { this.socket_log("pong") }
|
|
343
354
|
})
|
|
344
355
|
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
356
|
+
// handle events which are sent when handlers may be off
|
|
357
|
+
this.socket?.onAny((e, v)=> {
|
|
358
|
+
if (this.handlers[e] && v) {
|
|
359
|
+
this.handlers[e](v)
|
|
360
|
+
} else if (Array.isArray(v)) {
|
|
361
|
+
if (!this.loadedSocketEvents[e]) {
|
|
362
|
+
this.loadedSocketEvents[e] = []
|
|
363
|
+
}
|
|
364
|
+
this.loadedSocketEvents[e].push(...v)
|
|
365
|
+
}
|
|
366
|
+
})
|
|
348
367
|
|
|
349
368
|
this.socket.on('connect', () => {
|
|
350
369
|
if (this.enableSocketLogging) { this.socket_log(`connect, authenticated=${this.socketAuthenticated}`) }
|
package/src/tests/tests.ts
CHANGED
|
@@ -3682,15 +3682,18 @@ export const self_serve_appointment_booking_tests = async () => {
|
|
|
3682
3682
|
confirmationSMSDisabled: true,
|
|
3683
3683
|
})
|
|
3684
3684
|
|
|
3685
|
+
// ensure it doesn't match current day, to avoid errors on testing
|
|
3686
|
+
const dayOfWeekStartingSundayIndexedByZero = (new Date().getDay() + 1) % 7
|
|
3687
|
+
|
|
3685
3688
|
await sdk.api.users.updateOne(sdk.userInfo.id, {
|
|
3686
3689
|
weeklyAvailabilities: [
|
|
3687
3690
|
{
|
|
3688
|
-
dayOfWeekStartingSundayIndexedByZero
|
|
3691
|
+
dayOfWeekStartingSundayIndexedByZero,
|
|
3689
3692
|
startTimeInMinutes: 60 * 12, // noon,
|
|
3690
3693
|
endTimeInMinutes: 60 * 13, // 1pm,
|
|
3691
3694
|
},
|
|
3692
3695
|
{ // include as duplicate of above to ensure it doesn't produce extra availability slots
|
|
3693
|
-
dayOfWeekStartingSundayIndexedByZero
|
|
3696
|
+
dayOfWeekStartingSundayIndexedByZero, // sunday
|
|
3694
3697
|
startTimeInMinutes: 60 * 12, // noon,
|
|
3695
3698
|
endTimeInMinutes: 60 * 13, // 1pm,
|
|
3696
3699
|
},
|
|
@@ -3704,7 +3707,7 @@ export const self_serve_appointment_booking_tests = async () => {
|
|
|
3704
3707
|
await sdkNonAdmin.api.users.updateOne(sdkNonAdmin.userInfo.id, {
|
|
3705
3708
|
weeklyAvailabilities: [
|
|
3706
3709
|
{
|
|
3707
|
-
dayOfWeekStartingSundayIndexedByZero
|
|
3710
|
+
dayOfWeekStartingSundayIndexedByZero, // sunday
|
|
3708
3711
|
startTimeInMinutes: 60 * 12, // noon,
|
|
3709
3712
|
endTimeInMinutes: 60 * 13, // 1pm,
|
|
3710
3713
|
},
|
|
@@ -227,6 +227,7 @@ const endusers_tests = async (isSubscribed: boolean) => {
|
|
|
227
227
|
delete a.updates?.[0]?.recordBeforeUpdate.lockId
|
|
228
228
|
delete a.updates?.[0]?.recordBeforeUpdate.updatedAt
|
|
229
229
|
delete (enduser as any).updatedAt
|
|
230
|
+
delete (enduser as any).___didInsert
|
|
230
231
|
|
|
231
232
|
return (
|
|
232
233
|
objects_equivalent(a.updates?.[0]?.recordBeforeUpdate, enduser)
|