@open-xchange/soap-client 0.1.6 → 0.2.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.
@@ -18,117 +18,138 @@
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 } from '../../soap.js'
28
22
 
29
23
  /**
30
- * This function removes the user with the specified context and user ID.
31
- * @param {Object} context The context of the user to be removed.
32
- * @param {number} userId The ID of the user to be removed.
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
- }
28
+ export function createUserService (createClient) {
29
+ const getClient = memoizeClient(createClient, 'OXUserService')
42
30
 
43
- /**
44
- * This function creates a new user.
45
- * @param {Object} context The context of the user to be created.
46
- * @param {Object} usrdata The user to create.
47
- * @returns {Promise<Object>} The created user.
48
- */
49
- export async function create (context, usrdata) {
50
- return (await getClient()).createAsync({
51
- ctx: { id: context.id },
52
- usrdata,
53
- auth: context.admin
54
- })
55
- }
31
+ /**
32
+ * This function removes the user with the specified context and user ID.
33
+ * @param {Object} context The context of the user to be removed.
34
+ * @param {number} userId The ID of the user to be removed.
35
+ * @returns {Promise<Boolean>} Returns true if it could remove the user and false if it could not
36
+ */
37
+ async function remove (context, userId) {
38
+ return (await getClient()).deleteAsync({
39
+ ctx: { id: context.id },
40
+ user: { id: userId },
41
+ auth: context.admin
42
+ }).catch(logSoapError)
43
+ }
56
44
 
57
- /**
58
- * This function changes the context with the specified ID.
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
- }
45
+ /**
46
+ * This function creates a new user.
47
+ * @param {Object} context The context of the user to be created.
48
+ * @param {Object} usrdata The user to create.
49
+ * @returns {Promise<Object>} The created user.
50
+ */
51
+ async function create (context, usrdata) {
52
+ return (await getClient()).createAsync({
53
+ ctx: { id: context.id },
54
+ usrdata,
55
+ auth: context.admin
56
+ })
57
+ }
70
58
 
71
- export async function changeByModuleAccess (context, userId, currentAccess, moduleAccess) {
72
- return (await getClient()).changeByModuleAccessAsync({
73
- ctx: { id: context.id },
74
- moduleAccess: Object.assign({}, currentAccess, moduleAccess),
75
- user: { id: userId },
76
- auth: context.admin
77
- })
78
- }
59
+ /**
60
+ * This function changes the user with the specified data. Only the fields
61
+ * present in usrdata are sent.
62
+ * @param {Object} context The context of the user to be changed.
63
+ * @param {Object} usrdata The user to change.
64
+ * @returns {Promise<void>}
65
+ */
66
+ async function change (context, usrdata) {
67
+ return (await getClient()).changeAsync({
68
+ ctx: { id: context.id },
69
+ usrdata,
70
+ auth: context.admin
71
+ })
72
+ }
79
73
 
80
- export async function changeByModuleAccessName (context, userId, accessCombinationName) {
81
- return (await getClient()).changeByModuleAccessNameAsync({
82
- ctx: { id: context.id },
83
- access_combination_name: accessCombinationName,
84
- user: { id: userId },
85
- auth: context.admin
86
- }).catch(error => console.error('Module access change error:', error))
87
- }
74
+ async function changeByModuleAccess (context, userId, currentAccess, moduleAccess) {
75
+ return (await getClient()).changeByModuleAccessAsync({
76
+ ctx: { id: context.id },
77
+ moduleAccess: Object.assign({}, currentAccess, moduleAccess),
78
+ user: { id: userId },
79
+ auth: context.admin
80
+ })
81
+ }
88
82
 
89
- export async function getModuleAccess (context, userId) {
90
- return (await getClient()).getModuleAccessAsync({
91
- ctx: { id: context.id },
92
- user: { id: userId },
93
- auth: context.admin
94
- }).then(
95
- (res) => res
96
- )
97
- }
83
+ async function changeByModuleAccessName (context, userId, accessCombinationName) {
84
+ return (await getClient()).changeByModuleAccessNameAsync({
85
+ ctx: { id: context.id },
86
+ access_combination_name: accessCombinationName,
87
+ user: { id: userId },
88
+ auth: context.admin
89
+ })
90
+ }
98
91
 
99
- export async function changeCapabilities (context, userId, capsToAdd, capsToRemove) {
100
- const data = {
101
- ctx: { id: context.id },
102
- user: { id: userId },
103
- auth: context.admin
92
+ async function getModuleAccess (context, userId) {
93
+ return (await getClient()).getModuleAccessAsync({
94
+ ctx: { id: context.id },
95
+ user: { id: userId },
96
+ auth: context.admin
97
+ })
104
98
  }
105
- if (capsToAdd) data.capsToAdd = capsToAdd
106
- if (capsToRemove) data.capsToRemove = capsToRemove
107
- return (await getClient()).changeCapabilitiesAsync(data)
108
- }
109
99
 
110
- export async function exists (context, userId) {
111
- return (await getClient()).existsAsync({
112
- ctx: { id: context.id },
113
- user: { id: userId },
114
- auth: context.admin
115
- })
116
- }
100
+ async function changeCapabilities (context, userId, capsToAdd, capsToRemove) {
101
+ const data = {
102
+ ctx: { id: context.id },
103
+ user: { id: userId },
104
+ auth: context.admin
105
+ }
106
+ if (capsToAdd) data.capsToAdd = capsToAdd
107
+ if (capsToRemove) data.capsToRemove = capsToRemove
108
+ return (await getClient()).changeCapabilitiesAsync(data)
109
+ }
117
110
 
118
- export async function list (context, searchPattern, includeGuests = false) {
119
- return (await getClient()).listAsync({
120
- ctx: { id: context.id },
121
- search_pattern: searchPattern,
122
- include_guests: includeGuests,
123
- auth: context.admin
124
- })
125
- }
111
+ async function exists (context, userId) {
112
+ return (await getClient()).existsAsync({
113
+ ctx: { id: context.id },
114
+ user: { id: userId },
115
+ auth: context.admin
116
+ })
117
+ }
118
+
119
+ async function list (context, searchPattern, includeGuests = false) {
120
+ return (await getClient()).listAsync({
121
+ ctx: { id: context.id },
122
+ search_pattern: searchPattern,
123
+ include_guests: includeGuests,
124
+ auth: context.admin
125
+ })
126
+ }
126
127
 
127
- export async function listAll (context, includeGuests = false, excludeUsers = []) {
128
- return (await getClient()).listAsync({
129
- ctx: { id: context.id },
130
- include_guests: includeGuests,
131
- exclude_users: excludeUsers,
132
- auth: context.admin
133
- })
128
+ async function listAll (context, includeGuests = false, excludeUsers = []) {
129
+ return (await getClient()).listAsync({
130
+ ctx: { id: context.id },
131
+ include_guests: includeGuests,
132
+ exclude_users: excludeUsers,
133
+ auth: context.admin
134
+ })
135
+ }
136
+
137
+ return { remove, create, change, changeByModuleAccess, changeByModuleAccessName, getModuleAccess, changeCapabilities, exists, list, listAll }
134
138
  }
139
+
140
+ // Classic module exports, bound to the env-configured default endpoint.
141
+ // Note: changeByModuleAccessName used to swallow SOAP errors via console.error;
142
+ // it now rejects like every other operation (see CHANGELOG, Unreleased).
143
+ let defaultService
144
+ const service = () => (defaultService ??= createUserService(createClientAsync))
145
+
146
+ export const remove = (...args) => service().remove(...args)
147
+ export const create = (...args) => service().create(...args)
148
+ export const change = (...args) => service().change(...args)
149
+ export const changeByModuleAccess = (...args) => service().changeByModuleAccess(...args)
150
+ export const changeByModuleAccessName = (...args) => service().changeByModuleAccessName(...args)
151
+ export const getModuleAccess = (...args) => service().getModuleAccess(...args)
152
+ export const changeCapabilities = (...args) => service().changeCapabilities(...args)
153
+ export const exists = (...args) => service().exists(...args)
154
+ export const list = (...args) => service().list(...args)
155
+ export const listAll = (...args) => service().listAll(...args)
@@ -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
- * This function retrieves the ID of the first filestorage.
25
- * @returns {Promise<number>} The ID of the first filestorage.
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
- let fileStoreId
28
+ export function createUtilService (createClient) {
29
+ const getClient = memoizeClient(createClient, 'OXUtilService')
30
+ let fileStoreId
28
31
 
29
- export async function getFilestorageId () {
30
- const OXUtilService = createClientAsync('OXUtilService')
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
- if (fileStoreId) return fileStoreId
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
- let OXaaSService
24
- function getClient () {
25
- if (!OXaaSService) OXaaSService = createClientAsync('OXaaSService')
26
- return OXaaSService
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
- export async function setMailQuota (data) {
30
- return (await getClient()).setMailQuotaAsync(data)
31
- }
31
+ async function setMailQuota (data) {
32
+ return (await getClient()).setMailQuotaAsync(data)
33
+ }
32
34
 
33
- export async function createSharedDomain (data) {
34
- return (await getClient()).createSharedDomain(data)
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
- let OXResellerContextService
24
- function getClient () {
25
- if (!OXResellerContextService) OXResellerContextService = createClientAsync('OXResellerContextService')
26
- return OXResellerContextService
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
- export async function create (data) {
30
- return (await getClient()).createAsync(data)
31
- }
31
+ async function create (data) {
32
+ return (await getClient()).createAsync(data)
33
+ }
32
34
 
33
- export async function remove (contextId) {
34
- return (await getClient()).deleteAsync({
35
- ctx: { id: contextId }
36
- }).catch(logSoapError)
37
- }
35
+ async function remove (contextId) {
36
+ return (await getClient()).deleteAsync({
37
+ ctx: { id: contextId }
38
+ }).catch(logSoapError)
39
+ }
38
40
 
39
- export async function change (ctx) {
40
- return (await getClient()).changeAsync({ ctx })
41
- }
41
+ async function change (ctx) {
42
+ return (await getClient()).changeAsync({ ctx })
43
+ }
42
44
 
43
- export async function get (id) {
44
- return (await getClient()).getDataAsync({ ctx: { id } })
45
- }
45
+ async function get (id) {
46
+ return (await getClient()).getDataAsync({ ctx: { id } })
47
+ }
46
48
 
47
- export async function getModuleAccess (id) {
48
- return (await getClient()).getModuleAccessAsync({ ctx: id })
49
- }
49
+ async function getModuleAccess (id) {
50
+ return (await getClient()).getModuleAccessAsync({ ctx: id })
51
+ }
50
52
 
51
- export async function changeModuleAccess (id, access) {
52
- const currentAccess = await getModuleAccess(id)
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
- return (await getClient()).changeModuleAccessAsync({ ctx: { id }, access: { ...currentAccess, ...access } })
55
- }
58
+ async function listAll (data) {
59
+ return (await getClient()).listAllAsync(data)
60
+ }
56
61
 
57
- export async function listAll (data) {
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
- * This function changes the context with the specified ID.
38
- * @param {Object} context The context of the user to be changed.
39
- * @param {Object} usrdata The user to change.
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 async function change (context, usrdata) {
43
- return (await getClient()).changeAsync({
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
- export async function get (data) {
51
- return (await getClient()).getDataAsync(data)
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
- export async function getModuleAccess (context, userId) {
55
- return (await getClient()).getModuleAccessAsync({
56
- ctx: { id: context.id },
57
- user: { id: userId },
58
- auth: { login: context.admin.name, password: context.admin.password }
59
- }).then(
60
- (res) => res
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: { login: context.admin.name, password: context.admin.password }
49
+ })
50
+ }
63
51
 
64
- export 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: { 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
- export 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: { login: context.admin.name, password: context.admin.password }
79
- }).catch(error => console.error('Module access change error: ', error))
80
- }
56
+ async function getModuleAccess (context, userId) {
57
+ return (await getClient()).getModuleAccessAsync({
58
+ ctx: { id: context.id },
59
+ user: { id: userId },
60
+ auth: { login: context.admin.name, password: context.admin.password }
61
+ })
62
+ }
81
63
 
82
- export async function createByModuleAccessName (context, usrdata) {
83
- return (await getClient()).createByModuleAccessNameAsync({
84
- ctx: { id: context.id },
85
- usrdata,
86
- access_combination_name: 'all',
87
- auth: { login: context.admin.name, password: context.admin.password }
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: { login: context.admin.name, password: context.admin.password }
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: { login: context.admin.name, password: context.admin.password }
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: { login: context.admin.name, password: context.admin.password }
88
+ })
89
+ }
90
90
 
91
- export async function listAll (data) {
92
- return await (await getClient()).listAllAsync(data)
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)