@open-xchange/soap-client 0.1.6 → 0.2.1
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 +41 -1
- package/README.md +23 -0
- package/client.js +72 -0
- package/package.json +18 -7
- package/services/common/context.js +156 -130
- package/services/common/user.js +207 -98
- package/services/common/util.js +23 -9
- package/services/reseller/oxaas.js +23 -11
- package/services/reseller/resellerContext.js +45 -29
- package/services/reseller/resellerUser.js +81 -63
- package/services/secondaryAccount.js +61 -46
- package/services/sharedAccount.js +120 -104
- package/soap.js +206 -45
- package/test/soap.test.js +0 -268
- package/vitest.config.js +0 -8
package/services/common/user.js
CHANGED
|
@@ -18,117 +18,226 @@
|
|
|
18
18
|
* Any use of the work other than as authorized under this license or copyright law is prohibited.
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
-
import { createClientAsync, logSoapError } from '../../soap.js'
|
|
22
|
-
|
|
23
|
-
let OXUserService
|
|
24
|
-
function getClient () {
|
|
25
|
-
if (!OXUserService) OXUserService = createClientAsync('OXUserService')
|
|
26
|
-
return OXUserService
|
|
27
|
-
}
|
|
21
|
+
import { createClientAsync, memoizeClient, logSoapError, parseCapabilities } from '../../soap.js'
|
|
28
22
|
|
|
29
23
|
/**
|
|
30
|
-
*
|
|
31
|
-
* @param {
|
|
32
|
-
* @
|
|
33
|
-
* @returns {Promise<Boolean>} Returns true if it could remove the user and false if it could not
|
|
24
|
+
* Build a user service bound to a SOAP client constructor.
|
|
25
|
+
* @param {(type: string) => Promise<Object>} createClient
|
|
26
|
+
* @returns {Object} The user service.
|
|
34
27
|
*/
|
|
35
|
-
export async function remove (context, userId) {
|
|
36
|
-
return (await getClient()).deleteAsync({
|
|
37
|
-
ctx: { id: context.id },
|
|
38
|
-
user: { id: userId },
|
|
39
|
-
auth: context.admin
|
|
40
|
-
}).catch(logSoapError)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
28
|
/**
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
29
|
+
* Build the `user` element of a request from whatever the caller holds.
|
|
30
|
+
*
|
|
31
|
+
* Every older method on this service takes a plain id (`remove(context, 3)`,
|
|
32
|
+
* `getModuleAccess`, `exists`, `changeCapabilities`), so a caller following the
|
|
33
|
+
* convention passes one to the newer ones too. Destructuring a number yields
|
|
34
|
+
* `{ id: undefined }`, and because `user` is `nillable minOccurs="0"` the
|
|
35
|
+
* request stays schema-valid: the mistake comes back as an opaque
|
|
36
|
+
* InvalidDataException from the middleware instead of failing here. Accept both
|
|
37
|
+
* forms, and refuse a reference that names no user at all.
|
|
38
|
+
*
|
|
39
|
+
* @param {{id: number}|number} user An id, or an object carrying one.
|
|
40
|
+
* @returns {{id: number}} The `user` element to send.
|
|
48
41
|
*/
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
auth: context.admin
|
|
54
|
-
})
|
|
42
|
+
function userRef (user) {
|
|
43
|
+
const id = user !== null && typeof user === 'object' ? user.id : user
|
|
44
|
+
if (id === undefined || id === null) throw new TypeError('userRef: a user id is required')
|
|
45
|
+
return { id }
|
|
55
46
|
}
|
|
56
47
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
* @param {Object} context The context of the user to be changed.
|
|
60
|
-
* @param {Object} usrdata The user to change.
|
|
61
|
-
* @returns {Promise<void>}
|
|
62
|
-
*/
|
|
63
|
-
export async function change (context, usrdata) {
|
|
64
|
-
return (await getClient()).changeAsync({
|
|
65
|
-
ctx: { id: context.id },
|
|
66
|
-
usrdata,
|
|
67
|
-
auth: context.admin
|
|
68
|
-
})
|
|
69
|
-
}
|
|
48
|
+
export function createUserService (createClient) {
|
|
49
|
+
const getClient = memoizeClient(createClient, 'OXUserService')
|
|
70
50
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
51
|
+
/**
|
|
52
|
+
* This function removes the user with the specified context and user ID.
|
|
53
|
+
* @param {Object} context The context of the user to be removed.
|
|
54
|
+
* @param {number} userId The ID of the user to be removed.
|
|
55
|
+
* @returns {Promise<Boolean>} Returns true if it could remove the user and false if it could not
|
|
56
|
+
*/
|
|
57
|
+
async function remove (context, userId) {
|
|
58
|
+
return (await getClient()).deleteAsync({
|
|
59
|
+
ctx: { id: context.id },
|
|
60
|
+
user: { id: userId },
|
|
61
|
+
auth: context.admin
|
|
62
|
+
}).catch(logSoapError)
|
|
63
|
+
}
|
|
79
64
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
65
|
+
/**
|
|
66
|
+
* This function creates a new user.
|
|
67
|
+
* @param {Object} context The context of the user to be created.
|
|
68
|
+
* @param {Object} usrdata The user to create.
|
|
69
|
+
* @returns {Promise<Object>} The created user.
|
|
70
|
+
*/
|
|
71
|
+
async function create (context, usrdata) {
|
|
72
|
+
return (await getClient()).createAsync({
|
|
73
|
+
ctx: { id: context.id },
|
|
74
|
+
usrdata,
|
|
75
|
+
auth: context.admin
|
|
76
|
+
})
|
|
77
|
+
}
|
|
88
78
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
)
|
|
97
|
-
|
|
79
|
+
/**
|
|
80
|
+
* This function changes the user with the specified data. Only the fields
|
|
81
|
+
* present in usrdata are sent.
|
|
82
|
+
* @param {Object} context The context of the user to be changed.
|
|
83
|
+
* @param {Object} usrdata The user to change.
|
|
84
|
+
* @returns {Promise<void>}
|
|
85
|
+
*/
|
|
86
|
+
async function change (context, usrdata) {
|
|
87
|
+
return (await getClient()).changeAsync({
|
|
88
|
+
ctx: { id: context.id },
|
|
89
|
+
usrdata,
|
|
90
|
+
auth: context.admin
|
|
91
|
+
})
|
|
92
|
+
}
|
|
98
93
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
94
|
+
async function changeByModuleAccess (context, userId, currentAccess, moduleAccess) {
|
|
95
|
+
return (await getClient()).changeByModuleAccessAsync({
|
|
96
|
+
ctx: { id: context.id },
|
|
97
|
+
moduleAccess: Object.assign({}, currentAccess, moduleAccess),
|
|
98
|
+
user: { id: userId },
|
|
99
|
+
auth: context.admin
|
|
100
|
+
})
|
|
104
101
|
}
|
|
105
|
-
if (capsToAdd) data.capsToAdd = capsToAdd
|
|
106
|
-
if (capsToRemove) data.capsToRemove = capsToRemove
|
|
107
|
-
return (await getClient()).changeCapabilitiesAsync(data)
|
|
108
|
-
}
|
|
109
102
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}
|
|
103
|
+
async function changeByModuleAccessName (context, userId, accessCombinationName) {
|
|
104
|
+
return (await getClient()).changeByModuleAccessNameAsync({
|
|
105
|
+
ctx: { id: context.id },
|
|
106
|
+
access_combination_name: accessCombinationName,
|
|
107
|
+
user: { id: userId },
|
|
108
|
+
auth: context.admin
|
|
109
|
+
})
|
|
110
|
+
}
|
|
117
111
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
|
|
112
|
+
async function getModuleAccess (context, userId) {
|
|
113
|
+
return (await getClient()).getModuleAccessAsync({
|
|
114
|
+
ctx: { id: context.id },
|
|
115
|
+
user: { id: userId },
|
|
116
|
+
auth: context.admin
|
|
117
|
+
})
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
async function changeCapabilities (context, userId, capsToAdd, capsToRemove) {
|
|
121
|
+
const data = {
|
|
122
|
+
ctx: { id: context.id },
|
|
123
|
+
user: { id: userId },
|
|
124
|
+
auth: context.admin
|
|
125
|
+
}
|
|
126
|
+
if (capsToAdd) data.capsToAdd = capsToAdd
|
|
127
|
+
if (capsToRemove) data.capsToRemove = capsToRemove
|
|
128
|
+
return (await getClient()).changeCapabilitiesAsync(data)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
async function exists (context, userId) {
|
|
132
|
+
return (await getClient()).existsAsync({
|
|
133
|
+
ctx: { id: context.id },
|
|
134
|
+
user: { id: userId },
|
|
135
|
+
auth: context.admin
|
|
136
|
+
})
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
async function list (context, searchPattern, includeGuests = false) {
|
|
140
|
+
return (await getClient()).listAsync({
|
|
141
|
+
ctx: { id: context.id },
|
|
142
|
+
search_pattern: searchPattern,
|
|
143
|
+
include_guests: includeGuests,
|
|
144
|
+
auth: context.admin
|
|
145
|
+
})
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Hydrate users. `list` and `listAll` fill only the id, so their results
|
|
150
|
+
* carry no name, display_name or email and cannot be diffed against desired
|
|
151
|
+
* state; `getMultipleData` returns the full records for a set of ids in one
|
|
152
|
+
* call. Only the id of each entry is sent, whatever else the caller holds.
|
|
153
|
+
*
|
|
154
|
+
* The response element is a `List<User>`, so an empty result serializes to
|
|
155
|
+
* zero `<return>` elements and node-soap never creates the key. That would
|
|
156
|
+
* surface as `undefined` rather than an empty list and throw in the caller's
|
|
157
|
+
* `.map`, so it is normalised here.
|
|
158
|
+
*
|
|
159
|
+
* All or nothing: the operation declares `NoSuchUserException`, so if any one
|
|
160
|
+
* id disappeared between the `list` that produced it and this call, the whole
|
|
161
|
+
* request rejects and no user is hydrated. A caller that must tolerate a
|
|
162
|
+
* concurrent deletion has to fall back to `getData` per id itself; this
|
|
163
|
+
* method will not return partial results.
|
|
164
|
+
*
|
|
165
|
+
* @param {Object} context `{ id, admin }`
|
|
166
|
+
* @param {Array<{id: number}|number>} users The users to hydrate.
|
|
167
|
+
* @returns {Promise<Array<Object>>} The full user records, `[]` for none.
|
|
168
|
+
*/
|
|
169
|
+
async function getMultipleData (context, users = []) {
|
|
170
|
+
const refs = users.map(userRef)
|
|
171
|
+
if (refs.length === 0) return []
|
|
172
|
+
return (await (await getClient()).getMultipleDataAsync({
|
|
173
|
+
ctx: { id: context.id },
|
|
174
|
+
users: refs,
|
|
175
|
+
auth: context.admin
|
|
176
|
+
})) ?? []
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Hydrate one user. Same reason as getMultipleData; prefer that one for a
|
|
181
|
+
* set, since it is a single round trip.
|
|
182
|
+
* @param {Object} context `{ id, admin }`
|
|
183
|
+
* @param {{id: number}|number} user An id, or an object carrying one.
|
|
184
|
+
* @returns {Promise<Object>} The full user record.
|
|
185
|
+
*/
|
|
186
|
+
async function getData (context, user) {
|
|
187
|
+
const ref = userRef(user)
|
|
188
|
+
return (await getClient()).getDataAsync({
|
|
189
|
+
ctx: { id: context.id },
|
|
190
|
+
user: ref,
|
|
191
|
+
auth: context.admin
|
|
192
|
+
})
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* The capabilities currently in effect for a user. The middleware answers
|
|
197
|
+
* with a display string (see `parseCapabilities`), so this returns the names
|
|
198
|
+
* it lists. Without it a caller can only re-apply capabilities blindly on
|
|
199
|
+
* every reconcile, never diff them.
|
|
200
|
+
* @param {Object} context `{ id, admin }`
|
|
201
|
+
* @param {{id: number}|number} user An id, or an object carrying one.
|
|
202
|
+
* @returns {Promise<string[]>} Capability names, `[]` when there are none.
|
|
203
|
+
*/
|
|
204
|
+
async function getUserCapabilities (context, user) {
|
|
205
|
+
const ref = userRef(user)
|
|
206
|
+
return parseCapabilities(await (await getClient()).getUserCapabilitiesAsync({
|
|
207
|
+
ctx: { id: context.id },
|
|
208
|
+
user: ref,
|
|
209
|
+
auth: context.admin
|
|
210
|
+
}))
|
|
211
|
+
}
|
|
126
212
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
213
|
+
async function listAll (context, includeGuests = false, excludeUsers = []) {
|
|
214
|
+
return (await getClient()).listAsync({
|
|
215
|
+
ctx: { id: context.id },
|
|
216
|
+
include_guests: includeGuests,
|
|
217
|
+
exclude_users: excludeUsers,
|
|
218
|
+
auth: context.admin
|
|
219
|
+
})
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
return { remove, create, change, changeByModuleAccess, changeByModuleAccessName, getModuleAccess, changeCapabilities, exists, list, listAll, getData, getMultipleData, getUserCapabilities }
|
|
134
223
|
}
|
|
224
|
+
|
|
225
|
+
// Classic module exports, bound to the env-configured default endpoint.
|
|
226
|
+
// Note: changeByModuleAccessName used to swallow SOAP errors via console.error;
|
|
227
|
+
// it now rejects like every other operation (see CHANGELOG, Unreleased).
|
|
228
|
+
let defaultService
|
|
229
|
+
const service = () => (defaultService ??= createUserService(createClientAsync))
|
|
230
|
+
|
|
231
|
+
export const remove = (...args) => service().remove(...args)
|
|
232
|
+
export const create = (...args) => service().create(...args)
|
|
233
|
+
export const change = (...args) => service().change(...args)
|
|
234
|
+
export const changeByModuleAccess = (...args) => service().changeByModuleAccess(...args)
|
|
235
|
+
export const changeByModuleAccessName = (...args) => service().changeByModuleAccessName(...args)
|
|
236
|
+
export const getModuleAccess = (...args) => service().getModuleAccess(...args)
|
|
237
|
+
export const changeCapabilities = (...args) => service().changeCapabilities(...args)
|
|
238
|
+
export const exists = (...args) => service().exists(...args)
|
|
239
|
+
export const list = (...args) => service().list(...args)
|
|
240
|
+
export const listAll = (...args) => service().listAll(...args)
|
|
241
|
+
export const getData = (...args) => service().getData(...args)
|
|
242
|
+
export const getMultipleData = (...args) => service().getMultipleData(...args)
|
|
243
|
+
export const getUserCapabilities = (...args) => service().getUserCapabilities(...args)
|
package/services/common/util.js
CHANGED
|
@@ -18,18 +18,32 @@
|
|
|
18
18
|
* Any use of the work other than as authorized under this license or copyright law is prohibited.
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
-
import { createClientAsync } from '../../soap.js'
|
|
21
|
+
import { createClientAsync, memoizeClient } from '../../soap.js'
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
|
-
*
|
|
25
|
-
* @
|
|
24
|
+
* Build a util service bound to a SOAP client constructor.
|
|
25
|
+
* @param {(type: string) => Promise<Object>} createClient
|
|
26
|
+
* @returns {Object} The util service.
|
|
26
27
|
*/
|
|
27
|
-
|
|
28
|
+
export function createUtilService (createClient) {
|
|
29
|
+
const getClient = memoizeClient(createClient, 'OXUtilService')
|
|
30
|
+
let fileStoreId
|
|
28
31
|
|
|
29
|
-
|
|
30
|
-
|
|
32
|
+
/**
|
|
33
|
+
* This function retrieves the ID of the first filestorage.
|
|
34
|
+
* @returns {Promise<number>} The ID of the first filestorage.
|
|
35
|
+
*/
|
|
36
|
+
async function getFilestorageId () {
|
|
37
|
+
if (fileStoreId) return fileStoreId
|
|
38
|
+
fileStoreId = (await (await getClient()).listFilestoreAsync())[0]?.id
|
|
39
|
+
return fileStoreId
|
|
40
|
+
}
|
|
31
41
|
|
|
32
|
-
|
|
33
|
-
fileStoreId = (await (await OXUtilService).listFilestoreAsync())[0]?.id
|
|
34
|
-
return fileStoreId
|
|
42
|
+
return { getFilestorageId }
|
|
35
43
|
}
|
|
44
|
+
|
|
45
|
+
// Classic module export, bound to the env-configured default endpoint.
|
|
46
|
+
let defaultService
|
|
47
|
+
const service = () => (defaultService ??= createUtilService(createClientAsync))
|
|
48
|
+
|
|
49
|
+
export const getFilestorageId = (...args) => service().getFilestorageId(...args)
|
|
@@ -18,18 +18,30 @@
|
|
|
18
18
|
* Any use of the work other than as authorized under this license or copyright law is prohibited.
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
-
import { createClientAsync } from '../../soap.js'
|
|
21
|
+
import { createClientAsync, memoizeClient } from '../../soap.js'
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Build an OXaaS service bound to a SOAP client constructor.
|
|
25
|
+
* @param {(type: string) => Promise<Object>} createClient
|
|
26
|
+
* @returns {Object} The OXaaS service.
|
|
27
|
+
*/
|
|
28
|
+
export function createOxaasService (createClient) {
|
|
29
|
+
const getClient = memoizeClient(createClient, 'OXaaSService')
|
|
28
30
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
31
|
+
async function setMailQuota (data) {
|
|
32
|
+
return (await getClient()).setMailQuotaAsync(data)
|
|
33
|
+
}
|
|
32
34
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
+
async function createSharedDomain (data) {
|
|
36
|
+
return (await getClient()).createSharedDomainAsync(data)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return { setMailQuota, createSharedDomain }
|
|
35
40
|
}
|
|
41
|
+
|
|
42
|
+
// Classic module exports, bound to the env-configured default endpoint.
|
|
43
|
+
let defaultService
|
|
44
|
+
const service = () => (defaultService ??= createOxaasService(createClientAsync))
|
|
45
|
+
|
|
46
|
+
export const setMailQuota = (...args) => service().setMailQuota(...args)
|
|
47
|
+
export const createSharedDomain = (...args) => service().createSharedDomain(...args)
|
|
@@ -18,42 +18,58 @@
|
|
|
18
18
|
* Any use of the work other than as authorized under this license or copyright law is prohibited.
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
-
import { createClientAsync, logSoapError } from '../../soap.js'
|
|
21
|
+
import { createClientAsync, memoizeClient, logSoapError } from '../../soap.js'
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Build a reseller-context service bound to a SOAP client constructor.
|
|
25
|
+
* @param {(type: string) => Promise<Object>} createClient
|
|
26
|
+
* @returns {Object} The reseller context service.
|
|
27
|
+
*/
|
|
28
|
+
export function createResellerContextService (createClient) {
|
|
29
|
+
const getClient = memoizeClient(createClient, 'OXResellerContextService')
|
|
28
30
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
31
|
+
async function create (data) {
|
|
32
|
+
return (await getClient()).createAsync(data)
|
|
33
|
+
}
|
|
32
34
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
35
|
+
async function remove (contextId) {
|
|
36
|
+
return (await getClient()).deleteAsync({
|
|
37
|
+
ctx: { id: contextId }
|
|
38
|
+
}).catch(logSoapError)
|
|
39
|
+
}
|
|
38
40
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
41
|
+
async function change (ctx) {
|
|
42
|
+
return (await getClient()).changeAsync({ ctx })
|
|
43
|
+
}
|
|
42
44
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
45
|
+
async function get (id) {
|
|
46
|
+
return (await getClient()).getDataAsync({ ctx: { id } })
|
|
47
|
+
}
|
|
46
48
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
49
|
+
async function getModuleAccess (id) {
|
|
50
|
+
return (await getClient()).getModuleAccessAsync({ ctx: id })
|
|
51
|
+
}
|
|
50
52
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
+
async function changeModuleAccess (id, access) {
|
|
54
|
+
const currentAccess = await getModuleAccess(id)
|
|
55
|
+
return (await getClient()).changeModuleAccessAsync({ ctx: { id }, access: { ...currentAccess, ...access } })
|
|
56
|
+
}
|
|
53
57
|
|
|
54
|
-
|
|
55
|
-
|
|
58
|
+
async function listAll (data) {
|
|
59
|
+
return (await getClient()).listAllAsync(data)
|
|
60
|
+
}
|
|
56
61
|
|
|
57
|
-
|
|
58
|
-
return (await getClient()).listAllAsync(data)
|
|
62
|
+
return { create, remove, change, get, getModuleAccess, changeModuleAccess, listAll }
|
|
59
63
|
}
|
|
64
|
+
|
|
65
|
+
// Classic module exports, bound to the env-configured default endpoint.
|
|
66
|
+
let defaultService
|
|
67
|
+
const service = () => (defaultService ??= createResellerContextService(createClientAsync))
|
|
68
|
+
|
|
69
|
+
export const create = (...args) => service().create(...args)
|
|
70
|
+
export const remove = (...args) => service().remove(...args)
|
|
71
|
+
export const change = (...args) => service().change(...args)
|
|
72
|
+
export const get = (...args) => service().get(...args)
|
|
73
|
+
export const getModuleAccess = (...args) => service().getModuleAccess(...args)
|
|
74
|
+
export const changeModuleAccess = (...args) => service().changeModuleAccess(...args)
|
|
75
|
+
export const listAll = (...args) => service().listAll(...args)
|
|
@@ -18,76 +18,94 @@
|
|
|
18
18
|
* Any use of the work other than as authorized under this license or copyright law is prohibited.
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
-
import { createClientAsync, logSoapError } from '../../soap.js'
|
|
22
|
-
|
|
23
|
-
let OXResellerUserService
|
|
24
|
-
function getClient () {
|
|
25
|
-
if (!OXResellerUserService) OXResellerUserService = createClientAsync('OXResellerUserService')
|
|
26
|
-
return OXResellerUserService
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export async function remove (contextId, userId) {
|
|
30
|
-
return (await getClient()).deleteAsync({
|
|
31
|
-
ctx: { id: contextId },
|
|
32
|
-
user: { id: userId }
|
|
33
|
-
}).catch(logSoapError)
|
|
34
|
-
}
|
|
21
|
+
import { createClientAsync, memoizeClient, logSoapError } from '../../soap.js'
|
|
35
22
|
|
|
36
23
|
/**
|
|
37
|
-
*
|
|
38
|
-
* @param {
|
|
39
|
-
* @
|
|
40
|
-
* @returns {Promise<void>}
|
|
24
|
+
* Build a reseller-user service bound to a SOAP client constructor.
|
|
25
|
+
* @param {(type: string) => Promise<Object>} createClient
|
|
26
|
+
* @returns {Object} The reseller user service.
|
|
41
27
|
*/
|
|
42
|
-
export
|
|
43
|
-
|
|
44
|
-
ctx: { id: context.id },
|
|
45
|
-
usrdata,
|
|
46
|
-
auth: { login: context.admin.name, password: context.admin.password }
|
|
47
|
-
})
|
|
48
|
-
}
|
|
28
|
+
export function createResellerUserService (createClient) {
|
|
29
|
+
const getClient = memoizeClient(createClient, 'OXResellerUserService')
|
|
49
30
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
31
|
+
async function remove (contextId, userId) {
|
|
32
|
+
return (await getClient()).deleteAsync({
|
|
33
|
+
ctx: { id: contextId },
|
|
34
|
+
user: { id: userId }
|
|
35
|
+
}).catch(logSoapError)
|
|
36
|
+
}
|
|
53
37
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
38
|
+
/**
|
|
39
|
+
* This function changes the user with the specified data.
|
|
40
|
+
* @param {Object} context The context of the user to be changed.
|
|
41
|
+
* @param {Object} usrdata The user to change.
|
|
42
|
+
* @returns {Promise<void>}
|
|
43
|
+
*/
|
|
44
|
+
async function change (context, usrdata) {
|
|
45
|
+
return (await getClient()).changeAsync({
|
|
46
|
+
ctx: { id: context.id },
|
|
47
|
+
usrdata,
|
|
48
|
+
auth: context.admin
|
|
49
|
+
})
|
|
50
|
+
}
|
|
63
51
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
moduleAccess: Object.assign({}, currentAccess, moduleAccess),
|
|
68
|
-
user: { id: userId },
|
|
69
|
-
auth: { login: context.admin.name, password: context.admin.password }
|
|
70
|
-
})
|
|
71
|
-
}
|
|
52
|
+
async function get (data) {
|
|
53
|
+
return (await getClient()).getDataAsync(data)
|
|
54
|
+
}
|
|
72
55
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
}
|
|
56
|
+
async function getModuleAccess (context, userId) {
|
|
57
|
+
return (await getClient()).getModuleAccessAsync({
|
|
58
|
+
ctx: { id: context.id },
|
|
59
|
+
user: { id: userId },
|
|
60
|
+
auth: context.admin
|
|
61
|
+
})
|
|
62
|
+
}
|
|
81
63
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
64
|
+
async function changeByModuleAccess (context, userId, currentAccess, moduleAccess) {
|
|
65
|
+
return (await getClient()).changeByModuleAccessAsync({
|
|
66
|
+
ctx: { id: context.id },
|
|
67
|
+
moduleAccess: Object.assign({}, currentAccess, moduleAccess),
|
|
68
|
+
user: { id: userId },
|
|
69
|
+
auth: context.admin
|
|
70
|
+
})
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async function changeByModuleAccessName (context, userId, accessCombinationName) {
|
|
74
|
+
return (await getClient()).changeByModuleAccessNameAsync({
|
|
75
|
+
ctx: { id: context.id },
|
|
76
|
+
access_combination_name: accessCombinationName,
|
|
77
|
+
user: { id: userId },
|
|
78
|
+
auth: context.admin
|
|
79
|
+
})
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async function createByModuleAccessName (context, usrdata) {
|
|
83
|
+
return (await getClient()).createByModuleAccessNameAsync({
|
|
84
|
+
ctx: { id: context.id },
|
|
85
|
+
usrdata,
|
|
86
|
+
access_combination_name: 'all',
|
|
87
|
+
auth: context.admin
|
|
88
|
+
})
|
|
89
|
+
}
|
|
90
90
|
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
async function listAll (data) {
|
|
92
|
+
return (await getClient()).listAllAsync(data)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return { remove, change, get, getModuleAccess, changeByModuleAccess, changeByModuleAccessName, createByModuleAccessName, listAll }
|
|
93
96
|
}
|
|
97
|
+
|
|
98
|
+
// Classic module exports, bound to the env-configured default endpoint.
|
|
99
|
+
// Note: changeByModuleAccessName used to swallow SOAP errors via console.error;
|
|
100
|
+
// it now rejects like every other operation (see CHANGELOG, Unreleased).
|
|
101
|
+
let defaultService
|
|
102
|
+
const service = () => (defaultService ??= createResellerUserService(createClientAsync))
|
|
103
|
+
|
|
104
|
+
export const remove = (...args) => service().remove(...args)
|
|
105
|
+
export const change = (...args) => service().change(...args)
|
|
106
|
+
export const get = (...args) => service().get(...args)
|
|
107
|
+
export const getModuleAccess = (...args) => service().getModuleAccess(...args)
|
|
108
|
+
export const changeByModuleAccess = (...args) => service().changeByModuleAccess(...args)
|
|
109
|
+
export const changeByModuleAccessName = (...args) => service().changeByModuleAccessName(...args)
|
|
110
|
+
export const createByModuleAccessName = (...args) => service().createByModuleAccessName(...args)
|
|
111
|
+
export const listAll = (...args) => service().listAll(...args)
|