@or-sdk/users 3.4.0 → 3.5.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/CHANGELOG.md +9 -0
- package/dist/cjs/Users.js +74 -39
- package/dist/cjs/Users.js.map +1 -1
- package/dist/cjs/__tests__/Users.spec.js +67 -39
- package/dist/cjs/__tests__/Users.spec.js.map +1 -1
- package/dist/cjs/errors.js +1 -1
- package/dist/cjs/errors.js.map +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/schemas/_base.js +26 -0
- package/dist/cjs/schemas/_base.js.map +1 -0
- package/dist/cjs/schemas/constructor.js +22 -0
- package/dist/cjs/schemas/constructor.js.map +1 -0
- package/dist/cjs/schemas/createUserWithMulti.js +21 -0
- package/dist/cjs/schemas/createUserWithMulti.js.map +1 -0
- package/dist/cjs/schemas/getAccountInfo.js +3 -0
- package/dist/cjs/schemas/getAccountInfo.js.map +1 -0
- package/dist/cjs/schemas/getCurrentMultiUserProfile.js +19 -0
- package/dist/cjs/schemas/getCurrentMultiUserProfile.js.map +1 -0
- package/dist/cjs/schemas/getUserById.js +9 -0
- package/dist/cjs/schemas/getUserById.js.map +1 -0
- package/dist/cjs/schemas/index.js +28 -0
- package/dist/cjs/schemas/index.js.map +1 -0
- package/dist/cjs/schemas/listAccountProfiles.js +3 -0
- package/dist/cjs/schemas/listAccountProfiles.js.map +1 -0
- package/dist/cjs/schemas/listProfiles.js +13 -0
- package/dist/cjs/schemas/listProfiles.js.map +1 -0
- package/dist/cjs/schemas/listUsers.js +13 -0
- package/dist/cjs/schemas/listUsers.js.map +1 -0
- package/dist/cjs/schemas/listUsersAdvanced.js +10 -0
- package/dist/cjs/schemas/listUsersAdvanced.js.map +1 -0
- package/dist/cjs/schemas/upsertMultiUser.js +11 -0
- package/dist/cjs/schemas/upsertMultiUser.js.map +1 -0
- package/dist/esm/Users.js +43 -26
- package/dist/esm/Users.js.map +1 -1
- package/dist/esm/__tests__/Users.spec.js +13 -5
- package/dist/esm/__tests__/Users.spec.js.map +1 -1
- package/dist/esm/errors.js +2 -2
- package/dist/esm/errors.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/schemas/_base.js +20 -0
- package/dist/esm/schemas/_base.js.map +1 -0
- package/dist/esm/schemas/constructor.js +19 -0
- package/dist/esm/schemas/constructor.js.map +1 -0
- package/dist/esm/schemas/createUserWithMulti.js +18 -0
- package/dist/esm/schemas/createUserWithMulti.js.map +1 -0
- package/dist/esm/schemas/getAccountInfo.js +2 -0
- package/dist/esm/schemas/getAccountInfo.js.map +1 -0
- package/dist/esm/schemas/getCurrentMultiUserProfile.js +16 -0
- package/dist/esm/schemas/getCurrentMultiUserProfile.js.map +1 -0
- package/dist/esm/schemas/getUserById.js +6 -0
- package/dist/esm/schemas/getUserById.js.map +1 -0
- package/dist/esm/schemas/index.js +12 -0
- package/dist/esm/schemas/index.js.map +1 -0
- package/dist/esm/schemas/listAccountProfiles.js +2 -0
- package/dist/esm/schemas/listAccountProfiles.js.map +1 -0
- package/dist/esm/schemas/listProfiles.js +10 -0
- package/dist/esm/schemas/listProfiles.js.map +1 -0
- package/dist/esm/schemas/listUsers.js +10 -0
- package/dist/esm/schemas/listUsers.js.map +1 -0
- package/dist/esm/schemas/listUsersAdvanced.js +7 -0
- package/dist/esm/schemas/listUsersAdvanced.js.map +1 -0
- package/dist/esm/schemas/upsertMultiUser.js +8 -0
- package/dist/esm/schemas/upsertMultiUser.js.map +1 -0
- package/dist/types/Users.d.ts +11 -10
- package/dist/types/Users.d.ts.map +1 -1
- package/dist/types/__tests__/mocks/server.d.ts +3 -3
- package/dist/types/__tests__/mocks/server.d.ts.map +1 -1
- package/dist/types/errors.d.ts +2 -2
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/schemas/_base.d.ts +16 -0
- package/dist/types/schemas/_base.d.ts.map +1 -0
- package/dist/types/schemas/constructor.d.ts +34 -0
- package/dist/types/schemas/constructor.d.ts.map +1 -0
- package/dist/types/schemas/createUserWithMulti.d.ts +46 -0
- package/dist/types/schemas/createUserWithMulti.d.ts.map +1 -0
- package/dist/types/schemas/getAccountInfo.d.ts +5 -0
- package/dist/types/schemas/getAccountInfo.d.ts.map +1 -0
- package/dist/types/schemas/getCurrentMultiUserProfile.d.ts +66 -0
- package/dist/types/schemas/getCurrentMultiUserProfile.d.ts.map +1 -0
- package/dist/types/schemas/getUserById.d.ts +26 -0
- package/dist/types/schemas/getUserById.d.ts.map +1 -0
- package/dist/types/schemas/index.d.ts +12 -0
- package/dist/types/schemas/index.d.ts.map +1 -0
- package/dist/types/schemas/listAccountProfiles.d.ts +4 -0
- package/dist/types/schemas/listAccountProfiles.d.ts.map +1 -0
- package/dist/types/schemas/listProfiles.d.ts +43 -0
- package/dist/types/schemas/listProfiles.d.ts.map +1 -0
- package/dist/types/schemas/listUsers.d.ts +36 -0
- package/dist/types/schemas/listUsers.d.ts.map +1 -0
- package/dist/types/schemas/listUsersAdvanced.d.ts +44 -0
- package/dist/types/schemas/listUsersAdvanced.d.ts.map +1 -0
- package/dist/types/schemas/upsertMultiUser.d.ts +18 -0
- package/dist/types/schemas/upsertMultiUser.d.ts.map +1 -0
- package/dist/types/types.d.ts +8 -90
- package/dist/types/types.d.ts.map +1 -1
- package/package.json +13 -13
- package/src/Users.ts +160 -60
- package/src/__tests__/Users.spec.ts +15 -5
- package/src/__tests__/__snapshots__/Users.spec.ts.snap +66 -56
- package/src/errors.ts +2 -2
- package/src/index.ts +1 -1
- package/src/schemas/_base.ts +29 -0
- package/src/schemas/constructor.ts +21 -0
- package/src/schemas/createUserWithMulti.ts +26 -0
- package/src/schemas/getAccountInfo.ts +4 -0
- package/src/schemas/getCurrentMultiUserProfile.ts +19 -0
- package/src/schemas/getUserById.ts +22 -0
- package/src/schemas/index.ts +11 -0
- package/src/schemas/listAccountProfiles.ts +5 -0
- package/src/schemas/listProfiles.ts +37 -0
- package/src/schemas/listUsers.ts +27 -0
- package/src/schemas/listUsersAdvanced.ts +39 -0
- package/src/schemas/upsertMultiUser.ts +13 -0
- package/src/types.ts +13 -111
- package/{vitest.config.js → vitest.config.mts} +2 -2
- package/dist/cjs/schemas.js +0 -52
- package/dist/cjs/schemas.js.map +0 -1
- package/dist/esm/schemas.js +0 -45
- package/dist/esm/schemas.js.map +0 -1
- package/dist/types/schemas.d.ts +0 -111
- package/dist/types/schemas.d.ts.map +0 -1
- package/src/schemas.ts +0 -52
package/dist/types/types.d.ts
CHANGED
|
@@ -1,40 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export type {
|
|
3
|
-
export type UsersConfig = {
|
|
4
|
-
token: Token;
|
|
5
|
-
discoveryUrl?: string;
|
|
6
|
-
accountId?: string;
|
|
7
|
-
usersUrl: string;
|
|
8
|
-
sdkUrl?: string;
|
|
9
|
-
};
|
|
10
|
-
export type ListUsersParams = OrderOptions & PaginationOptions & {
|
|
11
|
-
query: {
|
|
12
|
-
[key: string]: any;
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
export type UserItem = {
|
|
16
|
-
id: string;
|
|
17
|
-
email: string;
|
|
18
|
-
username: string;
|
|
19
|
-
data: {
|
|
20
|
-
firstName: string;
|
|
21
|
-
lastName: string;
|
|
22
|
-
contactPhone: string;
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
export type User = {
|
|
26
|
-
dateCreated: number;
|
|
27
|
-
accountId: string;
|
|
28
|
-
email: string;
|
|
29
|
-
role: string;
|
|
30
|
-
data: {
|
|
31
|
-
firstName: string;
|
|
32
|
-
updatedBy: string;
|
|
33
|
-
};
|
|
34
|
-
dateModified: number;
|
|
35
|
-
username: string;
|
|
36
|
-
id: string;
|
|
37
|
-
};
|
|
1
|
+
import { Token } from '@or-sdk/base';
|
|
2
|
+
export type { Token };
|
|
38
3
|
export type TokenData = {
|
|
39
4
|
allow: boolean;
|
|
40
5
|
tokenType: string;
|
|
@@ -51,21 +16,7 @@ export type Profile = {
|
|
|
51
16
|
email: string;
|
|
52
17
|
username: string;
|
|
53
18
|
};
|
|
54
|
-
export type
|
|
55
|
-
id: string;
|
|
56
|
-
accountName: string;
|
|
57
|
-
};
|
|
58
|
-
export type AccountProfile = {
|
|
59
|
-
id: string;
|
|
60
|
-
email: string;
|
|
61
|
-
username: string;
|
|
62
|
-
};
|
|
63
|
-
export type ListProfilesParams = {
|
|
64
|
-
email?: string;
|
|
65
|
-
username?: string;
|
|
66
|
-
id?: string;
|
|
67
|
-
};
|
|
68
|
-
export type AttachResponse = {
|
|
19
|
+
export type AttachResult = {
|
|
69
20
|
emailSent?: boolean;
|
|
70
21
|
userAttached?: boolean;
|
|
71
22
|
};
|
|
@@ -85,37 +36,6 @@ export type ProfileAccountItem = {
|
|
|
85
36
|
id: string;
|
|
86
37
|
accountName: string;
|
|
87
38
|
};
|
|
88
|
-
export type UserAdvanced = {
|
|
89
|
-
id: string;
|
|
90
|
-
email: string;
|
|
91
|
-
dateCreated: Date;
|
|
92
|
-
disabled: boolean;
|
|
93
|
-
username: string;
|
|
94
|
-
role: string;
|
|
95
|
-
data: {
|
|
96
|
-
firstName?: string;
|
|
97
|
-
lastName?: string;
|
|
98
|
-
disableAt?: Date;
|
|
99
|
-
phoneNumber?: string;
|
|
100
|
-
permissions?: {
|
|
101
|
-
scope?: Array<string>;
|
|
102
|
-
};
|
|
103
|
-
};
|
|
104
|
-
profile?: {
|
|
105
|
-
id: string;
|
|
106
|
-
firstName?: string;
|
|
107
|
-
lastName?: string;
|
|
108
|
-
phoneNumber?: string;
|
|
109
|
-
email: string;
|
|
110
|
-
icon?: string;
|
|
111
|
-
};
|
|
112
|
-
createdBy?: string;
|
|
113
|
-
bySuperAdmin?: boolean;
|
|
114
|
-
};
|
|
115
|
-
export type ListUsersAdvancedParams = {
|
|
116
|
-
limit?: number;
|
|
117
|
-
offset?: number;
|
|
118
|
-
};
|
|
119
39
|
export type ListAccountsParams = {
|
|
120
40
|
limit?: number;
|
|
121
41
|
skip?: number;
|
|
@@ -124,8 +44,10 @@ export type ListAccountsParams = {
|
|
|
124
44
|
};
|
|
125
45
|
projection?: string[];
|
|
126
46
|
};
|
|
127
|
-
export type
|
|
128
|
-
items:
|
|
47
|
+
export type ListAccountsResult = {
|
|
48
|
+
items: {
|
|
49
|
+
id: string;
|
|
50
|
+
accountName: string;
|
|
129
51
|
dateCreated: string;
|
|
130
52
|
dateModified: string;
|
|
131
53
|
disabled: boolean;
|
|
@@ -133,7 +55,7 @@ export type ListAccountsResponse = {
|
|
|
133
55
|
data: {
|
|
134
56
|
[key: string]: unknown;
|
|
135
57
|
};
|
|
136
|
-
}
|
|
58
|
+
}[];
|
|
137
59
|
total: number;
|
|
138
60
|
};
|
|
139
61
|
export interface ValidateParams {
|
|
@@ -154,8 +76,4 @@ export type UpdateUserParam = {
|
|
|
154
76
|
role?: string;
|
|
155
77
|
multiUserId?: string;
|
|
156
78
|
};
|
|
157
|
-
export type CreateUserWithMultResponse = {
|
|
158
|
-
emailSent: boolean;
|
|
159
|
-
userCreated?: true;
|
|
160
|
-
};
|
|
161
79
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAErC,YAAY,EAAE,KAAK,EAAE,CAAC;AAEtB,MAAM,MAAM,SAAS,GAAG;IACtB,KAAK,EAAE,OAAO,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,gBAAgB,EAAE,MAAM,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gBAAgB,CAAC,EAAE,GAAG,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IAAE,SAAS,CAAC,EAAE,OAAO,CAAC;IAAC,YAAY,CAAC,EAAE,OAAO,CAAC;CAAE,CAAC;AAE5E,MAAM,MAAM,YAAY,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAAE,CAAC;AAElF,MAAM,MAAM,eAAe,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;CAAE,CAAC;AAEtH,MAAM,MAAM,kBAAkB,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;CAAE,CAAC;AAEtE,MAAM,MAAM,kBAAkB,GAAG;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KAAE,CAAC;IACpC,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,KAAK,EAAE;QACL,EAAE,EAAE,MAAM,CAAC;QACX,WAAW,EAAE,MAAM,CAAC;QACpB,WAAW,EAAE,MAAM,CAAC;QACpB,YAAY,EAAE,MAAM,CAAC;QACrB,QAAQ,EAAE,OAAO,CAAC;QAClB,OAAO,EAAE,OAAO,CAAC;QACjB,IAAI,EAAE;YAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;SAAE,CAAC;KACnC,EAAE,CAAC;IACJ,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,CAAC,EAAE;QACL,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAC/B,WAAW,CAAC,EAAE;YACZ,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;SAClB,CAAC;KACH,CAAC;IACF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@or-sdk/users",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
7
7
|
"types": "dist/types/index.d.ts",
|
|
8
8
|
"scripts": {
|
|
9
|
-
"build": "pnpm clean &&
|
|
9
|
+
"build": "pnpm clean && concurrently 'npm:build:*(!watch)'",
|
|
10
10
|
"build:cjs": "tsc --project tsconfig.json",
|
|
11
11
|
"build:esm": "tsc --project tsconfig.esm.json",
|
|
12
12
|
"build:types": "tsc --project tsconfig.types.json",
|
|
13
|
-
"build:watch": "concurrently -r --hide 1,2
|
|
14
|
-
"build:watch:cjs": "
|
|
15
|
-
"build:watch:esm": "
|
|
16
|
-
"build:watch:types": "
|
|
13
|
+
"build:watch": "concurrently -r --hide 1,2 'npm:build:watch:*'",
|
|
14
|
+
"build:watch:cjs": "pnpm build:cjs -w",
|
|
15
|
+
"build:watch:esm": "pnpm build:esm -w",
|
|
16
|
+
"build:watch:types": "pnpm build:types -w",
|
|
17
17
|
"clean": "rm -rf ./dist",
|
|
18
18
|
"dev": "pnpm build:watch:esm",
|
|
19
|
-
"test": "vitest
|
|
19
|
+
"test": "vitest",
|
|
20
20
|
"test:watch": "vitest --watch"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@or-sdk/base": "^0.
|
|
24
|
-
"@or-sdk/sdk-api": "^0.26.
|
|
23
|
+
"@or-sdk/base": "^0.42.0",
|
|
24
|
+
"@or-sdk/sdk-api": "^0.26.24",
|
|
25
25
|
"validator": "^13.11.0",
|
|
26
|
-
"zod": "^3.
|
|
26
|
+
"zod": "^3.24.4"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/validator": "^13.11.8",
|
|
30
30
|
"concurrently": "9.0.1",
|
|
31
|
-
"msw": "^2.
|
|
31
|
+
"msw": "^2.8.2",
|
|
32
32
|
"typescript": "5.6.2",
|
|
33
|
-
"vitest": "^
|
|
33
|
+
"vitest": "^3.1.3"
|
|
34
34
|
},
|
|
35
35
|
"publishConfig": {
|
|
36
36
|
"access": "public"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "7c8a6a4bcd0ea2a445262dd9fc5a8cfd6974c8b0"
|
|
39
39
|
}
|
package/src/Users.ts
CHANGED
|
@@ -4,27 +4,50 @@ import { SdkApi } from '@or-sdk/sdk-api';
|
|
|
4
4
|
|
|
5
5
|
import { SERVICE_KEY } from './constants';
|
|
6
6
|
import { CreateUserConflictError } from './errors';
|
|
7
|
-
import { CurrentMultiUserProfile, CreateUserWithMultData } from './schemas';
|
|
8
7
|
import {
|
|
9
|
-
|
|
8
|
+
currentMultiUserProfileSchema,
|
|
9
|
+
createUserWithMultDataSchema,
|
|
10
|
+
upsertMultiUserParamsSchema,
|
|
11
|
+
usersConfigSchema,
|
|
12
|
+
listUsersParamsSchema,
|
|
13
|
+
getUserByIdParamsSchema,
|
|
14
|
+
listProfilesParamsSchema,
|
|
15
|
+
listUsersAdvancedParamsSchema,
|
|
16
|
+
} from './schemas/index';
|
|
17
|
+
import type {
|
|
10
18
|
AccountProfile,
|
|
11
|
-
|
|
12
|
-
|
|
19
|
+
AccountItem,
|
|
20
|
+
CreateUserWithMultData,
|
|
21
|
+
CreateUserWithMultResult,
|
|
22
|
+
CurrentMultiUserProfile,
|
|
23
|
+
GetUserByIdParams,
|
|
24
|
+
ListAccountProfilesResult,
|
|
13
25
|
ListProfilesParams,
|
|
14
|
-
|
|
26
|
+
ListProfilesResult,
|
|
27
|
+
ListUsersParams,
|
|
28
|
+
ListUsersResult,
|
|
29
|
+
ListUsersAdvancedParams,
|
|
30
|
+
UserAdvanced,
|
|
31
|
+
ProfileItem,
|
|
32
|
+
UpsertMultiUserParams,
|
|
33
|
+
UpsertMultiUserResult,
|
|
34
|
+
User,
|
|
15
35
|
UsersConfig,
|
|
16
|
-
|
|
17
|
-
|
|
36
|
+
} from './schemas/index';
|
|
37
|
+
import type {
|
|
38
|
+
AttachParams,
|
|
39
|
+
AttachResult,
|
|
40
|
+
Profile, ProfileAccountItem, ProfileUserItem, TokenData,
|
|
41
|
+
ListAccountsParams, ListAccountsResult,
|
|
18
42
|
ValidateParams,
|
|
19
43
|
UpdateUserParam,
|
|
20
|
-
CreateUserWithMultResponse,
|
|
21
44
|
} from './types';
|
|
22
45
|
|
|
23
46
|
export class Users extends Base {
|
|
24
47
|
private readonly sdkApi!: SdkApi;
|
|
25
48
|
|
|
26
49
|
constructor(params: UsersConfig) {
|
|
27
|
-
const { token, discoveryUrl = '', accountId, usersUrl, sdkUrl } = params;
|
|
50
|
+
const { token, discoveryUrl = '', accountId, usersUrl, sdkUrl } = usersConfigSchema.parse(params);
|
|
28
51
|
|
|
29
52
|
super({
|
|
30
53
|
token,
|
|
@@ -49,13 +72,22 @@ export class Users extends Base {
|
|
|
49
72
|
}
|
|
50
73
|
|
|
51
74
|
/**
|
|
52
|
-
* List users
|
|
75
|
+
* List users in account
|
|
76
|
+
*
|
|
53
77
|
* ```typescript
|
|
54
|
-
* await users.listUsers({
|
|
78
|
+
* await users.listUsers({
|
|
79
|
+
* from: 0,
|
|
80
|
+
* size: 1,
|
|
81
|
+
* orderDirection: 'asc',
|
|
82
|
+
* orderProperty: 'email',
|
|
83
|
+
* query: {
|
|
84
|
+
* // optional
|
|
85
|
+
* },
|
|
86
|
+
* });
|
|
55
87
|
* ```
|
|
56
88
|
*/
|
|
57
|
-
public async listUsers(params = {} as ListUsersParams): Promise<
|
|
58
|
-
const { from = 0, size, orderDirection, orderProperty, query } = params;
|
|
89
|
+
public async listUsers(params = {} as ListUsersParams): Promise<ListUsersResult> {
|
|
90
|
+
const { from = 0, size, orderDirection, orderProperty, query } = listUsersParamsSchema.parse(params);
|
|
59
91
|
return this.callApiV2({
|
|
60
92
|
route: '/users',
|
|
61
93
|
method: 'GET',
|
|
@@ -70,21 +102,27 @@ export class Users extends Base {
|
|
|
70
102
|
}
|
|
71
103
|
|
|
72
104
|
/**
|
|
73
|
-
* Get user by Id
|
|
105
|
+
* Get account user by Id
|
|
106
|
+
*
|
|
74
107
|
* ```typescript
|
|
75
|
-
* const result = await users.getUserById('user-id');
|
|
108
|
+
* const result = await users.getUserById('<user-id>');
|
|
76
109
|
* ```
|
|
77
110
|
*/
|
|
78
|
-
public async getUserById(
|
|
111
|
+
public async getUserById(
|
|
112
|
+
userId: GetUserByIdParams['userId'],
|
|
113
|
+
projection: GetUserByIdParams['projection'],
|
|
114
|
+
): Promise<User> {
|
|
115
|
+
const { userId: parsedUserId, projection: parsedProjection = [] } = getUserByIdParamsSchema.parse({
|
|
116
|
+
userId,
|
|
117
|
+
projection,
|
|
118
|
+
});
|
|
79
119
|
const accountPrefix = this.sdkApi.isCrossAccount ? `accounts/${this.sdkApi.currentAccountId}` : '';
|
|
80
|
-
const route = `${accountPrefix}/users/${encodeURIComponent(
|
|
120
|
+
const route = `${accountPrefix}/users/${encodeURIComponent(parsedUserId)}`;
|
|
81
121
|
|
|
82
122
|
return this.sdkApi.makeRequest({
|
|
83
123
|
route,
|
|
84
124
|
method: 'GET',
|
|
85
|
-
params: {
|
|
86
|
-
projection,
|
|
87
|
-
},
|
|
125
|
+
params: { projection: parsedProjection },
|
|
88
126
|
});
|
|
89
127
|
}
|
|
90
128
|
|
|
@@ -109,12 +147,13 @@ export class Users extends Base {
|
|
|
109
147
|
route: '/user/multi-user',
|
|
110
148
|
});
|
|
111
149
|
return validate
|
|
112
|
-
? await
|
|
150
|
+
? await currentMultiUserProfileSchema.parseAsync(profile)
|
|
113
151
|
: profile;
|
|
114
152
|
}
|
|
115
153
|
|
|
116
154
|
/**
|
|
117
|
-
* Get account info
|
|
155
|
+
* Get account info based on given token
|
|
156
|
+
*
|
|
118
157
|
* ```typescript
|
|
119
158
|
* await users.getAccountInfo();
|
|
120
159
|
* ```
|
|
@@ -127,12 +166,13 @@ export class Users extends Base {
|
|
|
127
166
|
}
|
|
128
167
|
|
|
129
168
|
/**
|
|
130
|
-
* List account profiles
|
|
169
|
+
* List account multi-user profiles
|
|
170
|
+
*
|
|
131
171
|
* ```typescript
|
|
132
172
|
* await users.listAccountProfiles();
|
|
133
173
|
* ```
|
|
134
174
|
*/
|
|
135
|
-
public async listAccountProfiles(): Promise<
|
|
175
|
+
public async listAccountProfiles(): Promise<ListAccountProfilesResult> {
|
|
136
176
|
return this.callApiV2({
|
|
137
177
|
route: '/account/multi-users',
|
|
138
178
|
method: 'GET',
|
|
@@ -140,35 +180,40 @@ export class Users extends Base {
|
|
|
140
180
|
}
|
|
141
181
|
|
|
142
182
|
/**
|
|
143
|
-
* List profiles
|
|
183
|
+
* List profiles with ability for partial match by email, username or match by id.
|
|
184
|
+
*
|
|
185
|
+
* Super admin only.
|
|
186
|
+
*
|
|
144
187
|
* ```typescript
|
|
145
188
|
* await users.listProfiles();
|
|
146
189
|
* ```
|
|
147
190
|
*/
|
|
148
|
-
public async listProfiles(params
|
|
149
|
-
const
|
|
191
|
+
public async listProfiles(params: ListProfilesParams): Promise<ListProfilesResult> {
|
|
192
|
+
const parsedParams = listProfilesParamsSchema.parse(params);
|
|
193
|
+
const data = await this.callApiV2<ProfileItem[]>({
|
|
150
194
|
route: '/multi-users',
|
|
151
195
|
method: 'GET',
|
|
152
|
-
params:
|
|
153
|
-
email: params.email,
|
|
154
|
-
username: params.username,
|
|
155
|
-
id: params.id,
|
|
156
|
-
},
|
|
196
|
+
params: parsedParams,
|
|
157
197
|
});
|
|
158
|
-
return makeList<
|
|
198
|
+
return makeList<ProfileItem>(data);
|
|
159
199
|
}
|
|
160
200
|
|
|
161
201
|
/**
|
|
162
202
|
* List users with profile information
|
|
203
|
+
*
|
|
163
204
|
* ```typescript
|
|
164
205
|
* const result = await users.listUsersAdvanced();
|
|
165
206
|
* ```
|
|
166
207
|
*/
|
|
167
|
-
public async listUsersAdvanced(params
|
|
208
|
+
public async listUsersAdvanced(params: ListUsersAdvancedParams): Promise<UserAdvanced[]> {
|
|
209
|
+
const parsedParams = listUsersAdvancedParamsSchema.parse(params);
|
|
168
210
|
return this.callApiV2({
|
|
169
211
|
route: '/users/advanced',
|
|
170
212
|
method: 'GET',
|
|
171
|
-
params
|
|
213
|
+
params: {
|
|
214
|
+
...parsedParams,
|
|
215
|
+
skipShareViews: parsedParams?.skipShareViews || undefined,
|
|
216
|
+
},
|
|
172
217
|
});
|
|
173
218
|
}
|
|
174
219
|
|
|
@@ -177,9 +222,8 @@ export class Users extends Base {
|
|
|
177
222
|
*
|
|
178
223
|
* Super admin only.
|
|
179
224
|
*
|
|
180
|
-
* @example
|
|
181
225
|
* ```typescript
|
|
182
|
-
* const result = await users.getProfileByEmail('user@example.com');
|
|
226
|
+
* const result = await users.getProfileByEmail('multi-user@example.com');
|
|
183
227
|
* ```
|
|
184
228
|
*/
|
|
185
229
|
public async getProfileByEmail(email: string): Promise<AccountProfile> {
|
|
@@ -190,9 +234,9 @@ export class Users extends Base {
|
|
|
190
234
|
}
|
|
191
235
|
|
|
192
236
|
/**
|
|
193
|
-
* Get profile by Id
|
|
237
|
+
* Get multi-user profile by Id
|
|
194
238
|
* ```typescript
|
|
195
|
-
* const result = await users.getProfileById('profile-id');
|
|
239
|
+
* const result = await users.getProfileById('<profile-id>');
|
|
196
240
|
* ```
|
|
197
241
|
*/
|
|
198
242
|
public async getProfileById(profileId: string): Promise<Profile> {
|
|
@@ -218,18 +262,39 @@ export class Users extends Base {
|
|
|
218
262
|
/**
|
|
219
263
|
* Attach profile.
|
|
220
264
|
*
|
|
221
|
-
* Normal
|
|
265
|
+
* ### Normal: Attach current user (based on token) to multi-user profile
|
|
222
266
|
*
|
|
223
|
-
*
|
|
224
|
-
*
|
|
267
|
+
* Pass only multi-user email and it will begin attachment process with email verification.
|
|
268
|
+
* ```typescript
|
|
269
|
+
* await users.attachProfile({
|
|
270
|
+
* email: 'multi-user@example.com',
|
|
271
|
+
* })
|
|
272
|
+
* ```
|
|
273
|
+
*
|
|
274
|
+
* ### Super admin: Attach another user to multi-user profile
|
|
275
|
+
* Send userId if you want to attach another user instead of current.
|
|
276
|
+
*
|
|
277
|
+
* ```typescript
|
|
278
|
+
* await users.attachProfile({
|
|
279
|
+
* email: 'multi-user@example.com',
|
|
280
|
+
* userId: '<user-id-uuid>',
|
|
281
|
+
* });
|
|
282
|
+
* ```
|
|
283
|
+
*
|
|
284
|
+
* ### Super admin: Attach another user to multi-user profile and create new profile if it doesn't exist
|
|
285
|
+
* Send password if you want to automatically create profile.
|
|
225
286
|
*
|
|
226
287
|
* ```typescript
|
|
227
|
-
* await users.attachProfile(
|
|
288
|
+
* await users.attachProfile({
|
|
289
|
+
* email: 'multi-user@example.com',
|
|
290
|
+
* userId: '<user-id-uuid>',
|
|
291
|
+
* password: 's3cure_p@ss0rd!',
|
|
292
|
+
* });
|
|
228
293
|
* ```
|
|
229
294
|
*/
|
|
230
|
-
public async attachProfile(params: AttachParams): Promise<
|
|
295
|
+
public async attachProfile(params: AttachParams): Promise<AttachResult> {
|
|
231
296
|
return this.sdkApi.makeRequest({
|
|
232
|
-
route: `/accounts/${this.currentAccountId
|
|
297
|
+
route: `/accounts/${this.currentAccountId ?? 'current'}/multi-user/attach-start`,
|
|
233
298
|
method: 'POST',
|
|
234
299
|
data: {
|
|
235
300
|
email: params.email,
|
|
@@ -273,7 +338,7 @@ export class Users extends Base {
|
|
|
273
338
|
*/
|
|
274
339
|
public async getUserEmail(userId?: string): Promise<{ email: string; }> {
|
|
275
340
|
return this.callApiV2<{ email: string; }>({
|
|
276
|
-
route: `/users/${userId
|
|
341
|
+
route: `/users/${userId ?? 'current'}/email`,
|
|
277
342
|
method: 'GET',
|
|
278
343
|
});
|
|
279
344
|
}
|
|
@@ -296,7 +361,7 @@ export class Users extends Base {
|
|
|
296
361
|
/**
|
|
297
362
|
* Update user
|
|
298
363
|
* ```typescript
|
|
299
|
-
* await users.updateUser(userId, user,
|
|
364
|
+
* await users.updateUser(userId, user, accountId);
|
|
300
365
|
* ```
|
|
301
366
|
*/
|
|
302
367
|
public async updateUser(userId: string, user: UpdateUserParam, accountId?: string): Promise<void> {
|
|
@@ -346,33 +411,41 @@ export class Users extends Base {
|
|
|
346
411
|
}
|
|
347
412
|
|
|
348
413
|
/**
|
|
349
|
-
*
|
|
414
|
+
* Initiate the creation of the multi-user
|
|
415
|
+
*
|
|
416
|
+
* @example
|
|
350
417
|
* ```typescript
|
|
351
|
-
* const
|
|
418
|
+
* const { userCreated, emailSent } = await users.createUserWithMulti(userData, accountId);
|
|
419
|
+
* // userCreated === true - if user already exists
|
|
420
|
+
* // emailSent === true - if user does not exists and invitation email was sent
|
|
352
421
|
* ```
|
|
353
|
-
* response.userCreated - if multi user exists.
|
|
354
|
-
* if not it will send verification email and create only after comfirmation
|
|
355
422
|
*/
|
|
356
423
|
public async createUserWithMulti(
|
|
357
424
|
userData: CreateUserWithMultData,
|
|
358
425
|
accountId?: string,
|
|
359
|
-
): Promise<
|
|
426
|
+
): Promise<CreateUserWithMultResult> {
|
|
360
427
|
try {
|
|
361
|
-
const data = await
|
|
428
|
+
const data = await createUserWithMultDataSchema.parseAsync(userData);
|
|
362
429
|
|
|
363
|
-
return await this.sdkApi.makeRequest<
|
|
364
|
-
route: `/accounts/${accountId
|
|
430
|
+
return await this.sdkApi.makeRequest<CreateUserWithMultResult>({
|
|
431
|
+
route: `/accounts/${accountId ?? undefined}/multi-user/create-start`,
|
|
365
432
|
method: 'POST',
|
|
366
433
|
data,
|
|
367
434
|
});
|
|
368
435
|
} catch (error) {
|
|
369
436
|
if (error instanceof Error && error.cause instanceof AxiosError && error.cause?.response?.status === 409) {
|
|
370
437
|
const errorMessage = parseAxiosErrorMessage(error.cause);
|
|
371
|
-
throw new CreateUserConflictError(errorMessage, {
|
|
438
|
+
throw new CreateUserConflictError(errorMessage, {
|
|
439
|
+
cause: error.cause,
|
|
440
|
+
statusCode: error.cause.response.status,
|
|
441
|
+
});
|
|
372
442
|
}
|
|
373
443
|
if (error instanceof AxiosError && error.response?.status === 409) {
|
|
374
444
|
const errorMessage = parseAxiosErrorMessage(error);
|
|
375
|
-
throw new CreateUserConflictError(errorMessage, {
|
|
445
|
+
throw new CreateUserConflictError(errorMessage, {
|
|
446
|
+
cause: error,
|
|
447
|
+
statusCode: error.response.status,
|
|
448
|
+
});
|
|
376
449
|
}
|
|
377
450
|
throw error;
|
|
378
451
|
}
|
|
@@ -396,8 +469,8 @@ export class Users extends Base {
|
|
|
396
469
|
* await users.listAccounts({limit, skip, query, projection});
|
|
397
470
|
* ```
|
|
398
471
|
*/
|
|
399
|
-
public async listAccounts(params: ListAccountsParams = {}): Promise<
|
|
400
|
-
const data = await this.callApiV2<{ count: number; rows:
|
|
472
|
+
public async listAccounts(params: ListAccountsParams = {}): Promise<ListAccountsResult> {
|
|
473
|
+
const data = await this.callApiV2<{ count: number; rows: ListAccountsResult['items']; }>({
|
|
401
474
|
route: '/accounts',
|
|
402
475
|
params,
|
|
403
476
|
});
|
|
@@ -406,5 +479,32 @@ export class Users extends Base {
|
|
|
406
479
|
items: data.rows,
|
|
407
480
|
};
|
|
408
481
|
}
|
|
409
|
-
}
|
|
410
482
|
|
|
483
|
+
/**
|
|
484
|
+
* Upsert multi-user.
|
|
485
|
+
*
|
|
486
|
+
* If multi-user with email already exists return it, otherwise create new one with given email and password
|
|
487
|
+
*
|
|
488
|
+
* Super admin only!
|
|
489
|
+
*
|
|
490
|
+
* @example
|
|
491
|
+
* ```typescript
|
|
492
|
+
* await users.createMultiUser({
|
|
493
|
+
* email: 'user@example.com',
|
|
494
|
+
* password: 's3cure_p@ss0rd!',
|
|
495
|
+
* data: {
|
|
496
|
+
* // optional
|
|
497
|
+
* }
|
|
498
|
+
* });
|
|
499
|
+
* ```
|
|
500
|
+
*/
|
|
501
|
+
public async upsertMultiUser(params: UpsertMultiUserParams): Promise<UpsertMultiUserResult> {
|
|
502
|
+
const data = await upsertMultiUserParamsSchema.parseAsync(params);
|
|
503
|
+
|
|
504
|
+
return await this.sdkApi.makeRequest<UpsertMultiUserResult>({
|
|
505
|
+
route: '/multi-user/create',
|
|
506
|
+
method: 'PUT',
|
|
507
|
+
data,
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { http } from 'msw';
|
|
4
4
|
import { afterAll, afterEach, beforeAll, describe, expect, it } from 'vitest';
|
|
5
|
+
import { z } from 'zod';
|
|
5
6
|
|
|
6
7
|
import { Users, UserRole, CreateUserConflictError } from '../index';
|
|
7
8
|
|
|
@@ -14,7 +15,7 @@ import {
|
|
|
14
15
|
profileFixture,
|
|
15
16
|
profileNoPhoneFixture,
|
|
16
17
|
createUserWithMultiFixture,
|
|
17
|
-
} from './mocks';
|
|
18
|
+
} from './mocks/index';
|
|
18
19
|
|
|
19
20
|
function buildUsersInstance() {
|
|
20
21
|
return new Users({
|
|
@@ -35,6 +36,15 @@ describe('Users API', () => {
|
|
|
35
36
|
expect(api.serviceUrl).toBe(USERS_URL);
|
|
36
37
|
expect((api as any).sdkApi.serviceUrl).toBe(SDK_URL);
|
|
37
38
|
});
|
|
39
|
+
|
|
40
|
+
it('throws error if usersUrl and discoveryUrl are not provided', () => {
|
|
41
|
+
expect(() => {
|
|
42
|
+
new Users({
|
|
43
|
+
token: 'test-token',
|
|
44
|
+
sdkUrl: SDK_URL,
|
|
45
|
+
});
|
|
46
|
+
}).toThrowErrorMatchingSnapshot();
|
|
47
|
+
});
|
|
38
48
|
});
|
|
39
49
|
|
|
40
50
|
describe('getCurrentMultiUserProfile', () => {
|
|
@@ -65,7 +75,7 @@ describe('Users API', () => {
|
|
|
65
75
|
mockApiServer.use(http.get(url, errorRes(testError)) as any);
|
|
66
76
|
|
|
67
77
|
const api = buildUsersInstance();
|
|
68
|
-
expect(api.getCurrentMultiUserProfile()).rejects.toThrow(testError);
|
|
78
|
+
await expect(api.getCurrentMultiUserProfile()).rejects.toThrow(testError);
|
|
69
79
|
});
|
|
70
80
|
|
|
71
81
|
it('show throw error on invalid response', async () => {
|
|
@@ -74,7 +84,7 @@ describe('Users API', () => {
|
|
|
74
84
|
);
|
|
75
85
|
|
|
76
86
|
const api = buildUsersInstance();
|
|
77
|
-
expect(api.getCurrentMultiUserProfile()).rejects.toThrowErrorMatchingSnapshot();
|
|
87
|
+
await expect(api.getCurrentMultiUserProfile()).rejects.toThrowErrorMatchingSnapshot();
|
|
78
88
|
});
|
|
79
89
|
|
|
80
90
|
it('show throw error on invalid response if validate = true', async () => {
|
|
@@ -83,7 +93,7 @@ describe('Users API', () => {
|
|
|
83
93
|
);
|
|
84
94
|
|
|
85
95
|
const api = buildUsersInstance();
|
|
86
|
-
expect(api.getCurrentMultiUserProfile({ validate: true })).rejects.toThrowErrorMatchingSnapshot();
|
|
96
|
+
await expect(api.getCurrentMultiUserProfile({ validate: true })).rejects.toThrowErrorMatchingSnapshot();
|
|
87
97
|
});
|
|
88
98
|
|
|
89
99
|
it('show not throw error on invalid response if validate = false', async () => {
|
|
@@ -142,7 +152,7 @@ describe('Users API', () => {
|
|
|
142
152
|
disableAt: new Date(Date.now() - 1000 * 60 * 60 * 24).toISOString(),
|
|
143
153
|
};
|
|
144
154
|
const api = buildUsersInstance();
|
|
145
|
-
expect(api.createUserWithMulti(userData)).rejects.toThrowErrorMatchingSnapshot();
|
|
155
|
+
await expect(api.createUserWithMulti(userData)).rejects.toThrowErrorMatchingSnapshot();
|
|
146
156
|
});
|
|
147
157
|
});
|
|
148
158
|
});
|