@tellescope/sdk 0.0.4 → 0.0.8
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 +346 -13
- package/lib/cjs/enduser.d.ts.map +1 -1
- package/lib/cjs/enduser.js +135 -14
- package/lib/cjs/enduser.js.map +1 -1
- package/lib/cjs/sdk.d.ts +106 -19
- package/lib/cjs/sdk.d.ts.map +1 -1
- package/lib/cjs/sdk.js +116 -32
- package/lib/cjs/sdk.js.map +1 -1
- package/lib/cjs/session.d.ts +36 -175
- package/lib/cjs/session.d.ts.map +1 -1
- package/lib/cjs/session.js +131 -34
- package/lib/cjs/session.js.map +1 -1
- package/lib/cjs/tests/public_endpoint_tests.js +3 -3
- package/lib/cjs/tests/public_endpoint_tests.js.map +1 -1
- package/lib/cjs/tests/socket_tests.js +42 -31
- package/lib/cjs/tests/socket_tests.js.map +1 -1
- package/lib/cjs/tests/tests.js +196 -62
- package/lib/cjs/tests/tests.js.map +1 -1
- package/lib/esm/enduser.d.ts +346 -13
- package/lib/esm/enduser.d.ts.map +1 -1
- package/lib/esm/enduser.js +132 -12
- package/lib/esm/enduser.js.map +1 -1
- package/lib/esm/sdk.d.ts +106 -19
- package/lib/esm/sdk.d.ts.map +1 -1
- package/lib/esm/sdk.js +116 -32
- package/lib/esm/sdk.js.map +1 -1
- package/lib/esm/session.d.ts +36 -175
- package/lib/esm/session.d.ts.map +1 -1
- package/lib/esm/session.js +130 -32
- package/lib/esm/session.js.map +1 -1
- package/lib/esm/tests/public_endpoint_tests.js +3 -3
- package/lib/esm/tests/public_endpoint_tests.js.map +1 -1
- package/lib/esm/tests/socket_tests.js +41 -30
- package/lib/esm/tests/socket_tests.js.map +1 -1
- package/lib/esm/tests/tests.js +192 -63
- package/lib/esm/tests/tests.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +11 -9
- package/src/enduser.ts +93 -20
- package/src/sdk.ts +70 -42
- package/src/session.ts +121 -33
- package/src/tests/public_endpoint_tests.ts +6 -4
- package/src/tests/socket_tests.ts +37 -16
- package/src/tests/tests.ts +117 -24
- package/tsconfig.json +0 -1
package/src/tests/tests.ts
CHANGED
|
@@ -6,34 +6,44 @@ import {
|
|
|
6
6
|
ClientModelForName,
|
|
7
7
|
ClientModelForName_required,
|
|
8
8
|
} from "@tellescope/types-client"
|
|
9
|
+
import {
|
|
10
|
+
Model as ClientModel,
|
|
11
|
+
ModelName,
|
|
12
|
+
} from "@tellescope/types-models"
|
|
9
13
|
|
|
10
|
-
|
|
11
|
-
|
|
14
|
+
import {
|
|
15
|
+
Indexable,
|
|
16
|
+
Operation,
|
|
17
|
+
} from "@tellescope/types-utilities"
|
|
12
18
|
|
|
13
19
|
import {
|
|
14
20
|
fieldsToValidation,
|
|
15
21
|
mongoIdValidator,
|
|
16
22
|
|
|
17
|
-
|
|
23
|
+
InputValidation,
|
|
18
24
|
} from "@tellescope/validation"
|
|
19
25
|
|
|
20
|
-
import { Session, APIQuery } from "../sdk"
|
|
21
|
-
import {
|
|
26
|
+
import { Session, APIQuery, EnduserSession } from "../sdk"
|
|
27
|
+
import { } from "@tellescope/utilities"
|
|
22
28
|
import { DEFAULT_OPERATIONS } from "@tellescope/constants"
|
|
23
29
|
import {
|
|
24
30
|
schema,
|
|
25
|
-
|
|
26
|
-
|
|
31
|
+
Model,
|
|
32
|
+
ModelFields,
|
|
27
33
|
} from "@tellescope/schema"
|
|
28
34
|
|
|
29
35
|
import {
|
|
30
36
|
assert,
|
|
31
37
|
async_test,
|
|
32
38
|
log_header,
|
|
33
|
-
objects_equivalent,
|
|
34
39
|
wait,
|
|
35
40
|
} from "@tellescope/testing"
|
|
36
41
|
|
|
42
|
+
import {
|
|
43
|
+
objects_equivalent,
|
|
44
|
+
url_safe_path,
|
|
45
|
+
} from "@tellescope/utilities"
|
|
46
|
+
|
|
37
47
|
|
|
38
48
|
const host = process.env.TEST_URL || 'http://localhost:8080'
|
|
39
49
|
const [email, password] = [process.env.TEST_EMAIL, process.env.TEST_PASSWORD]
|
|
@@ -41,8 +51,28 @@ const [email2, password2] = [process.env.TEST_EMAIL_2, process.env.TEST_PASSWORD
|
|
|
41
51
|
|
|
42
52
|
const userId = '60398b0231a295e64f084fd9'
|
|
43
53
|
|
|
54
|
+
// const example_SDK_usage = async () => {
|
|
55
|
+
// // initialize SDK and authenticate a user
|
|
56
|
+
// const sdk = new Session()
|
|
57
|
+
// await sdk.authenticate("user-email", 'user-password')
|
|
58
|
+
|
|
59
|
+
// // create a record, using Enduser model as example
|
|
60
|
+
// const enduser = await sdk.api.endusers.createOne({ email: "enduser1@tellescope.com" })
|
|
61
|
+
|
|
62
|
+
// // update an existing record
|
|
63
|
+
// await sdk.api.endusers.updateOne(enduser.id, { phone: "+15555555555" })
|
|
64
|
+
|
|
65
|
+
// // fetch a record by id, or a list of recent records
|
|
66
|
+
// const existingEnduser: Enduser = await sdk.api.endusers.getOne(enduser.id)
|
|
67
|
+
// const existingEndusers: Enduser[] = await sdk.api.endusers.getSome({ limit: 5, lastId: enduser.id })
|
|
68
|
+
|
|
69
|
+
// // delete an individual record
|
|
70
|
+
// await sdk.api.endusers.deleteOne(enduser.id)
|
|
71
|
+
// }
|
|
72
|
+
|
|
44
73
|
const sdk = new Session()
|
|
45
74
|
const sdkOther = new Session({ host, apiKey: "ba745e25162bb95a795c5fa1af70df188d93c4d3aac9c48b34a5c8c9dd7b80f7" })
|
|
75
|
+
const enduserSDK = new EnduserSession({ host })
|
|
46
76
|
// const sdkOtherEmail = "sebass@tellescope.com"
|
|
47
77
|
|
|
48
78
|
if (!(email && password && email2 && password2)) {
|
|
@@ -299,7 +329,7 @@ const run_generated_tests = async <N extends ModelName>({ queries, model, name,
|
|
|
299
329
|
)
|
|
300
330
|
await async_test(
|
|
301
331
|
`get-${safeName}`,
|
|
302
|
-
() => queries.getSome({
|
|
332
|
+
() => queries.getSome({ filter }),
|
|
303
333
|
{ onResult: ([d, /*...others */]) => {
|
|
304
334
|
// if (others.length !== 0) return false // some collections are not reset during testing, like API keys
|
|
305
335
|
if (!d?.id) return false
|
|
@@ -527,7 +557,7 @@ const journey_tests = async (queries=sdk.api.journeys) => {
|
|
|
527
557
|
|
|
528
558
|
await async_test(
|
|
529
559
|
`journey-updateState`,
|
|
530
|
-
() => queries.updateState(journey.id, 'Added', { name: 'Updated', priority: 'N/A' }),
|
|
560
|
+
() => queries.updateState({ id: journey.id, name: 'Added', updates: { name: 'Updated', priority: 'N/A' }}),
|
|
531
561
|
passOnVoid,
|
|
532
562
|
)
|
|
533
563
|
await wait(undefined, 25) // wait for side effects to update endusers
|
|
@@ -701,7 +731,7 @@ const chat_tests = async() => {
|
|
|
701
731
|
)
|
|
702
732
|
await async_test(
|
|
703
733
|
`get-chats (with filter)`,
|
|
704
|
-
() => sdk.api.chats.getSome({
|
|
734
|
+
() => sdk.api.chats.getSome({ filter: { roomId: room.id } }),
|
|
705
735
|
{ onResult: c => c?.length === 2 }
|
|
706
736
|
)
|
|
707
737
|
|
|
@@ -712,25 +742,27 @@ const chat_tests = async() => {
|
|
|
712
742
|
)
|
|
713
743
|
await async_test(
|
|
714
744
|
`get-chats not allowed`,
|
|
715
|
-
() => sdk2.api.chats.getSome({
|
|
716
|
-
{ shouldError: true, onError: e => e.message === 'You do not have permission to access this resource' }
|
|
717
|
-
)
|
|
718
|
-
await async_test(
|
|
719
|
-
`update-chat not allowed`,
|
|
720
|
-
() => sdk2.api.chats.updateOne(chat.id, { message: 'Hi' }),
|
|
745
|
+
() => sdk2.api.chats.getSome({ filter: { roomId: room.id } }),
|
|
721
746
|
{ shouldError: true, onError: e => e.message === 'You do not have permission to access this resource' }
|
|
722
747
|
)
|
|
748
|
+
// currently disabled endpoint altogether
|
|
749
|
+
// await async_test(
|
|
750
|
+
// `update-chat not allowed`,
|
|
751
|
+
// () => sdk2.api.chats.updateOne(chat.id, { message: 'Hi' }),
|
|
752
|
+
// { shouldError: true, onError: e => e.message === 'You do not have permission to access this resource' }
|
|
753
|
+
// )
|
|
723
754
|
await async_test(
|
|
724
755
|
`delete-chat not allowed`,
|
|
725
756
|
() => sdk2.api.chats.deleteOne(chat.id),
|
|
726
757
|
{ shouldError: true, onError: e => e.message === 'You do not have permission to access this resource' }
|
|
727
758
|
)
|
|
728
759
|
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
760
|
+
// currently disabled endpoint altogether
|
|
761
|
+
// await async_test(
|
|
762
|
+
// `update-chat can't update roomId`,
|
|
763
|
+
// () => sdk.api.chats.updateOne(chat.id, { roomId: room.id } as any), // cast to any to allow calling with bad argument, but typing should catch this too
|
|
764
|
+
// { shouldError: true, onError: e => e.message === 'Error parsing field updates: roomId is not valid for updates' }
|
|
765
|
+
// )
|
|
734
766
|
|
|
735
767
|
await sdk.api.chat_rooms.deleteOne(room.id)
|
|
736
768
|
await wait(undefined, 25)
|
|
@@ -760,12 +792,12 @@ const chat_tests = async() => {
|
|
|
760
792
|
)
|
|
761
793
|
await async_test(
|
|
762
794
|
`get-chats (shared, user1)`,
|
|
763
|
-
() => sdk.api.chats.getSome({
|
|
795
|
+
() => sdk.api.chats.getSome({ filter: { roomId: sharedRoom.id } }, ),
|
|
764
796
|
{ onResult: cs => cs.length === 2 && !!cs.find(c => c.id === sharedChat.id) && !!cs.find(c => c.id === sharedChat2.id) }
|
|
765
797
|
)
|
|
766
798
|
await async_test(
|
|
767
799
|
`get-chats (shared, user2)`,
|
|
768
|
-
() => sdk2.api.chats.getSome({
|
|
800
|
+
() => sdk2.api.chats.getSome({ filter: { roomId: sharedRoom.id } }),
|
|
769
801
|
{ onResult: cs => cs.length === 2 && !!cs.find(c => c.id === sharedChat.id) && !!cs.find(c => c.id === sharedChat2.id) }
|
|
770
802
|
)
|
|
771
803
|
|
|
@@ -783,6 +815,65 @@ const chat_tests = async() => {
|
|
|
783
815
|
)
|
|
784
816
|
}
|
|
785
817
|
|
|
818
|
+
const enduserAccessTests = async () => {
|
|
819
|
+
const email = 'enduser@tellescope.com'
|
|
820
|
+
const password = 'testpassword'
|
|
821
|
+
|
|
822
|
+
const enduser = await sdk.api.endusers.createOne({ email })
|
|
823
|
+
await sdk.api.endusers.setPassword({ id: enduser.id, password }).catch(console.error)
|
|
824
|
+
await enduserSDK.authenticate(email, password).catch(console.error)
|
|
825
|
+
|
|
826
|
+
for (const n in schema) {
|
|
827
|
+
const endpoint = url_safe_path(n)
|
|
828
|
+
const model = schema[n as keyof typeof schema]
|
|
829
|
+
|
|
830
|
+
if (!model?.enduserActions?.read && (model.defaultActions.read || model.customActions.read)) {
|
|
831
|
+
await async_test(
|
|
832
|
+
`no-enduser-access getOne (${endpoint})`,
|
|
833
|
+
() => enduserSDK.GET(`/v1/${endpoint.substring(0, endpoint.length - 1)}/:id`),
|
|
834
|
+
{ shouldError: true, onError: (e: string) => e === 'Unauthenticated' }
|
|
835
|
+
)
|
|
836
|
+
}
|
|
837
|
+
if (!model.enduserActions?.readMany && (model.defaultActions.readMany || model.customActions.readMany)) {
|
|
838
|
+
await async_test(
|
|
839
|
+
`no-enduser-access getSome (${endpoint})`,
|
|
840
|
+
() => enduserSDK.GET(`/v1/${endpoint}`),
|
|
841
|
+
{ shouldError: true, onError: (e: string) => e === 'Unauthenticated' }
|
|
842
|
+
)
|
|
843
|
+
}
|
|
844
|
+
if (!model.enduserActions?.create && (model.defaultActions.create || model.customActions.create)) {
|
|
845
|
+
await async_test(
|
|
846
|
+
`no-enduser-access createOne (${endpoint})`,
|
|
847
|
+
() => enduserSDK.POST(`/v1/${endpoint.substring(0, endpoint.length - 1)}`),
|
|
848
|
+
{ shouldError: true, onError: (e: string) => e === 'Unauthenticated' }
|
|
849
|
+
)
|
|
850
|
+
}
|
|
851
|
+
if (!model.enduserActions?.createMany && (model.defaultActions.createMany || model.customActions.createMany)) {
|
|
852
|
+
await async_test(
|
|
853
|
+
`no-enduser-access createMany (${endpoint})`,
|
|
854
|
+
() => enduserSDK.POST(`/v1/${endpoint}`),
|
|
855
|
+
{ shouldError: true, onError: (e: string) => e === 'Unauthenticated' }
|
|
856
|
+
)
|
|
857
|
+
}
|
|
858
|
+
if (!model.enduserActions?.update && (model.defaultActions.update || model.customActions.update)) {
|
|
859
|
+
await async_test(
|
|
860
|
+
`no-enduser-access update (${endpoint})`,
|
|
861
|
+
() => enduserSDK.PATCH(`/v1/${endpoint.substring(0, endpoint.length - 1)}/:id`),
|
|
862
|
+
{ shouldError: true, onError: (e: string) => e === 'Unauthenticated' }
|
|
863
|
+
)
|
|
864
|
+
}
|
|
865
|
+
if (!model.enduserActions?.delete && (model.defaultActions.delete || model.customActions.delete)) {
|
|
866
|
+
await async_test(
|
|
867
|
+
`no-enduser-access delete (${endpoint})`,
|
|
868
|
+
() => enduserSDK.DELETE(`/v1/${endpoint.substring(0, endpoint.length - 1)}/:id`),
|
|
869
|
+
{ shouldError: true, onError: (e: string) => e === 'Unauthenticated' }
|
|
870
|
+
)
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
await sdk.api.endusers.deleteOne(enduser.id)
|
|
875
|
+
}
|
|
876
|
+
|
|
786
877
|
const tests: { [K in keyof ClientModelForName]: () => void } = {
|
|
787
878
|
chats: chat_tests,
|
|
788
879
|
endusers: enduser_tests,
|
|
@@ -795,6 +886,7 @@ const tests: { [K in keyof ClientModelForName]: () => void } = {
|
|
|
795
886
|
chat_rooms: chat_room_tests,
|
|
796
887
|
users: () => {},
|
|
797
888
|
templates: () => {},
|
|
889
|
+
files: () => {},
|
|
798
890
|
};
|
|
799
891
|
|
|
800
892
|
(async () => {
|
|
@@ -802,6 +894,7 @@ const tests: { [K in keyof ClientModelForName]: () => void } = {
|
|
|
802
894
|
|
|
803
895
|
log_header("API")
|
|
804
896
|
await setup_tests()
|
|
897
|
+
await enduserAccessTests()
|
|
805
898
|
await multi_tenant_tests() // should come right after setup tests
|
|
806
899
|
await threadKeyTests()
|
|
807
900
|
|