@open-xchange/soap-client 0.0.5 → 0.0.7

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/bin/provision.js CHANGED
@@ -6,8 +6,7 @@ import * as secondaryAccountService from '../services/secondaryAccount.js'
6
6
  import * as userService from '../services/common/user.js'
7
7
  import * as contextService from '../services/common/context.js'
8
8
 
9
- dotenv.config({ path: '.env' })
10
- dotenv.config({ path: '.env.defaults' })
9
+ dotenv.config({ path: ['.env', '.env.defaults'], quiet: true })
11
10
 
12
11
  const contextAdmin = {
13
12
  admin: {
@@ -31,7 +30,7 @@ function checkEnvironmentVariables () {
31
30
  }
32
31
  }
33
32
 
34
- async function getOrCreateContext (data) {
33
+ async function getOrCreateContext (data, accessCombinationName = 'all') {
35
34
  const contextData = {
36
35
  ...{ maxQuota: -1 },
37
36
  ...data
@@ -45,7 +44,7 @@ async function getOrCreateContext (data) {
45
44
  context = existingContext[0]
46
45
  } else {
47
46
  console.log('Creating new context')
48
- context = await contextService.create(contextData, contextAdmin.admin)
47
+ context = await contextService.create(contextData, contextAdmin.admin, accessCombinationName)
49
48
  }
50
49
  return {
51
50
  ...context,
@@ -59,12 +58,15 @@ async function getOrCreateContext (data) {
59
58
 
60
59
  async function getOrCreateUser (context, userData) {
61
60
  try {
62
- const existingUser = await userService.list(context, userData.display_name)
63
- if (existingUser?.length > 0) {
64
- console.log('User already exists, using existing one')
65
- return existingUser[0]
61
+ const existingUsers = (await Promise.all([
62
+ userService.list(context, userData.name),
63
+ userService.list(context, userData.display_name)
64
+ ])).flat().filter(Boolean)
65
+ if (existingUsers?.length > 0) {
66
+ console.log('User already exists', userData.name)
67
+ return existingUsers[0]
66
68
  }
67
- console.log('Creating new user')
69
+ console.log('Creating new user', userData.name)
68
70
  userData = {
69
71
  imapServer: process.env.IMAP_SERVER || 'main-dovecot',
70
72
  smtpServer: process.env.SMTP_SERVER || 'main-postfix',
@@ -114,10 +116,10 @@ async function provisionFromFile (configPath) {
114
116
  for (const contexts of config.contexts || []) {
115
117
  try {
116
118
  const contextData = contexts.data
117
- const context = await getOrCreateContext({ name: contexts.data.name, admin: contexts.data.admin })
118
- if (contextData.capabilities) {
119
+ const context = await getOrCreateContext({ name: contexts.data.name, admin: contexts.data.admin, }, contextData.accessCombinationName || 'all')
120
+ if (contextData.capabilities || contextData.capabilitiesToRemove) {
119
121
  try {
120
- await contextService.changeCapabilities(context.id, contextData.capabilities, undefined)
122
+ await contextService.changeCapabilities(context.id, contextData.capabilities, contextData.capabilitiesToRemove)
121
123
  console.log('Changed capabilities for context:', context.id)
122
124
  } catch (capError) {
123
125
  console.error('Error changing capabilities for context', context.id, capError)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-xchange/soap-client",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "description": "SOAP client for OX App Suite",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -22,7 +22,7 @@
22
22
  "dependencies": {
23
23
  "commander": "^14.0.0",
24
24
  "dotenv": "^17.2.1",
25
- "p-retry": "^6.2.1",
25
+ "p-retry": "^7.0.0",
26
26
  "soap": "^1.3.0"
27
27
  },
28
28
  "devDependencies": {
@@ -58,7 +58,7 @@ export async function remove (id) {
58
58
  ```
59
59
  * @returns {Promise<Object>} The created context.
60
60
  */
61
- export async function create (ctx = {}, adminUser = {}) {
61
+ export async function create (ctx = {}, adminUser = {}, accessCombinationName = 'all') {
62
62
  return await (await OXContextService)
63
63
  .createAsync({
64
64
  ctx,
@@ -73,7 +73,7 @@ export async function create (ctx = {}, adminUser = {}) {
73
73
  }, adminUser)
74
74
  })
75
75
  .then(async context => {
76
- await changeModuleAccessByName(context.id, 'all')
76
+ await changeModuleAccessByName(context.id, accessCombinationName)
77
77
  return context
78
78
  })
79
79
  .catch(e => {
@@ -119,3 +119,12 @@ export async function list (context, searchPattern, includeGuests = false) {
119
119
  auth: context.admin
120
120
  })
121
121
  }
122
+
123
+ export async function listAll (context, includeGuests = false, excludeUsers = []) {
124
+ return await (await OXUserService).listAsync({
125
+ ctx: { id: context.id },
126
+ include_guests: includeGuests,
127
+ exclude_users: excludeUsers,
128
+ auth: context.admin
129
+ })
130
+ }