@api-client/core 0.14.3 → 0.14.5

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.
Files changed (40) hide show
  1. package/build/src/browser.d.ts +1 -1
  2. package/build/src/browser.d.ts.map +1 -1
  3. package/build/src/browser.js +1 -0
  4. package/build/src/browser.js.map +1 -1
  5. package/build/src/events/BaseEvents.d.ts +4 -0
  6. package/build/src/events/BaseEvents.d.ts.map +1 -1
  7. package/build/src/events/BaseEvents.js.map +1 -1
  8. package/build/src/index.d.ts +1 -1
  9. package/build/src/index.d.ts.map +1 -1
  10. package/build/src/index.js +1 -0
  11. package/build/src/index.js.map +1 -1
  12. package/build/src/models/kinds.d.ts +1 -0
  13. package/build/src/models/kinds.d.ts.map +1 -1
  14. package/build/src/models/kinds.js +1 -0
  15. package/build/src/models/kinds.js.map +1 -1
  16. package/build/src/models/store/Group.d.ts +76 -2
  17. package/build/src/models/store/Group.d.ts.map +1 -1
  18. package/build/src/models/store/Group.js +84 -1
  19. package/build/src/models/store/Group.js.map +1 -1
  20. package/build/src/sdk/GroupsSdk.d.ts +43 -0
  21. package/build/src/sdk/GroupsSdk.d.ts.map +1 -0
  22. package/build/src/sdk/GroupsSdk.js +199 -0
  23. package/build/src/sdk/GroupsSdk.js.map +1 -0
  24. package/build/src/sdk/RouteBuilder.d.ts +3 -0
  25. package/build/src/sdk/RouteBuilder.d.ts.map +1 -1
  26. package/build/src/sdk/RouteBuilder.js +9 -0
  27. package/build/src/sdk/RouteBuilder.js.map +1 -1
  28. package/build/src/sdk/Sdk.d.ts +2 -0
  29. package/build/src/sdk/Sdk.d.ts.map +1 -1
  30. package/build/src/sdk/Sdk.js +5 -0
  31. package/build/src/sdk/Sdk.js.map +1 -1
  32. package/build/tsconfig.tsbuildinfo +1 -1
  33. package/data/models/example-generator-api.json +19 -19
  34. package/package.json +1 -1
  35. package/src/events/BaseEvents.ts +4 -0
  36. package/src/models/kinds.ts +1 -0
  37. package/src/models/store/Group.ts +148 -2
  38. package/src/sdk/GroupsSdk.ts +214 -0
  39. package/src/sdk/RouteBuilder.ts +12 -0
  40. package/src/sdk/Sdk.ts +6 -0
@@ -42071,15 +42071,15 @@
42071
42071
  "@id": "#197"
42072
42072
  },
42073
42073
  {
42074
- "@id": "#206"
42075
- },
42076
- {
42077
42074
  "@id": "#200"
42078
42075
  },
42079
42076
  {
42080
42077
  "@id": "#203"
42081
42078
  },
42082
42079
  {
42080
+ "@id": "#206"
42081
+ },
42082
+ {
42083
42083
  "@id": "#209"
42084
42084
  }
42085
42085
  ],
@@ -42810,9 +42810,6 @@
42810
42810
  "@id": "#219"
42811
42811
  },
42812
42812
  {
42813
- "@id": "#219"
42814
- },
42815
- {
42816
42813
  "@id": "#210"
42817
42814
  },
42818
42815
  {
@@ -42820,6 +42817,9 @@
42820
42817
  },
42821
42818
  {
42822
42819
  "@id": "#216"
42820
+ },
42821
+ {
42822
+ "@id": "#219"
42823
42823
  }
42824
42824
  ],
42825
42825
  "doc:root": false,
@@ -43499,7 +43499,7 @@
43499
43499
  "doc:ExternalDomainElement",
43500
43500
  "doc:DomainElement"
43501
43501
  ],
43502
- "doc:raw": "code: 'J'\ndescription: 'Information and communication'\n",
43502
+ "doc:raw": "class: '3'\ndescription: '150 - 300'\nnumberOfFte: 5500\nnumberOfEmployees: 5232\n",
43503
43503
  "core:mediaType": "application/yaml",
43504
43504
  "sourcemaps:sources": [
43505
43505
  {
@@ -43520,7 +43520,7 @@
43520
43520
  "doc:ExternalDomainElement",
43521
43521
  "doc:DomainElement"
43522
43522
  ],
43523
- "doc:raw": "code: '7487'\ndescription: 'Financial and insurance activities'\ntype: \"PRIMARY\"\nclassificationCode: 'BE_NACEBEL2008'\nactivityGroupCode: 'ABCDE'\n",
43523
+ "doc:raw": "code: 'J'\ndescription: 'Information and communication'\n",
43524
43524
  "core:mediaType": "application/yaml",
43525
43525
  "sourcemaps:sources": [
43526
43526
  {
@@ -43541,7 +43541,7 @@
43541
43541
  "doc:ExternalDomainElement",
43542
43542
  "doc:DomainElement"
43543
43543
  ],
43544
- "doc:raw": "class: '3'\ndescription: '150 - 300'\nnumberOfFte: 5500\nnumberOfEmployees: 5232\n",
43544
+ "doc:raw": "code: '7487'\ndescription: 'Financial and insurance activities'\ntype: \"PRIMARY\"\nclassificationCode: 'BE_NACEBEL2008'\nactivityGroupCode: 'ABCDE'\n",
43545
43545
  "core:mediaType": "application/yaml",
43546
43546
  "sourcemaps:sources": [
43547
43547
  {
@@ -44232,7 +44232,7 @@
44232
44232
  "doc:ExternalDomainElement",
44233
44233
  "doc:DomainElement"
44234
44234
  ],
44235
- "doc:raw": "type: 'GENERAL'\ncountryDialCode : '+32'\nareaCode : '21'\nsubscriberNumber: '12.87.00'\nformatted: '+32-(0)21 302099'\n",
44235
+ "doc:raw": "type: 'GENERAL'\ncountryDialCode : '+32'\nareaCode : '22'\nsubscriberNumber: '12.87.00'\nformatted: '+32-(0)22 000000'\n",
44236
44236
  "core:mediaType": "application/yaml",
44237
44237
  "sourcemaps:sources": [
44238
44238
  {
@@ -44253,7 +44253,7 @@
44253
44253
  "doc:ExternalDomainElement",
44254
44254
  "doc:DomainElement"
44255
44255
  ],
44256
- "doc:raw": "-\n type: 'GENERAL'\n value: 'info@company.be'\n-\n type: 'IT_DEPT'\n value: 'it-service@company.be'\n",
44256
+ "doc:raw": "type: 'GENERAL'\ncountryDialCode : '+32'\nareaCode : '21'\nsubscriberNumber: '12.87.00'\nformatted: '+32-(0)21 302099'\n",
44257
44257
  "core:mediaType": "application/yaml",
44258
44258
  "sourcemaps:sources": [
44259
44259
  {
@@ -44274,7 +44274,7 @@
44274
44274
  "doc:ExternalDomainElement",
44275
44275
  "doc:DomainElement"
44276
44276
  ],
44277
- "doc:raw": "type: \"GENERAL\"\nvalue: \"www.company.be\"\n",
44277
+ "doc:raw": "-\n type: 'GENERAL'\n value: 'info@company.be'\n-\n type: 'IT_DEPT'\n value: 'it-service@company.be'\n",
44278
44278
  "core:mediaType": "application/yaml",
44279
44279
  "sourcemaps:sources": [
44280
44280
  {
@@ -44295,7 +44295,7 @@
44295
44295
  "doc:ExternalDomainElement",
44296
44296
  "doc:DomainElement"
44297
44297
  ],
44298
- "doc:raw": "type: 'GENERAL'\ncountryDialCode : '+32'\nareaCode : '22'\nsubscriberNumber: '12.87.00'\nformatted: '+32-(0)22 000000'\n",
44298
+ "doc:raw": "type: \"GENERAL\"\nvalue: \"www.company.be\"\n",
44299
44299
  "core:mediaType": "application/yaml",
44300
44300
  "sourcemaps:sources": [
44301
44301
  {
@@ -44771,17 +44771,17 @@
44771
44771
  {
44772
44772
  "@id": "#202/source-map/lexical/element_0",
44773
44773
  "sourcemaps:element": "amf://id#202",
44774
- "sourcemaps:value": "[(1,0)-(3,0)]"
44774
+ "sourcemaps:value": "[(1,0)-(5,0)]"
44775
44775
  },
44776
44776
  {
44777
44777
  "@id": "#205/source-map/lexical/element_0",
44778
44778
  "sourcemaps:element": "amf://id#205",
44779
- "sourcemaps:value": "[(1,0)-(6,0)]"
44779
+ "sourcemaps:value": "[(1,0)-(3,0)]"
44780
44780
  },
44781
44781
  {
44782
44782
  "@id": "#208/source-map/lexical/element_0",
44783
44783
  "sourcemaps:element": "amf://id#208",
44784
- "sourcemaps:value": "[(1,0)-(5,0)]"
44784
+ "sourcemaps:value": "[(1,0)-(6,0)]"
44785
44785
  },
44786
44786
  {
44787
44787
  "@id": "#223/source-map/lexical/element_0",
@@ -45121,17 +45121,17 @@
45121
45121
  {
45122
45122
  "@id": "#215/source-map/lexical/element_0",
45123
45123
  "sourcemaps:element": "amf://id#215",
45124
- "sourcemaps:value": "[(1,0)-(7,0)]"
45124
+ "sourcemaps:value": "[(1,0)-(6,0)]"
45125
45125
  },
45126
45126
  {
45127
45127
  "@id": "#218/source-map/lexical/element_0",
45128
45128
  "sourcemaps:element": "amf://id#218",
45129
- "sourcemaps:value": "[(1,0)-(3,0)]"
45129
+ "sourcemaps:value": "[(1,0)-(7,0)]"
45130
45130
  },
45131
45131
  {
45132
45132
  "@id": "#221/source-map/lexical/element_0",
45133
45133
  "sourcemaps:element": "amf://id#221",
45134
- "sourcemaps:value": "[(1,0)-(6,0)]"
45134
+ "sourcemaps:value": "[(1,0)-(3,0)]"
45135
45135
  },
45136
45136
  {
45137
45137
  "@id": "#338/source-map/synthesized-field/element_1",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@api-client/core",
3
3
  "description": "The API Client's core client library. Works in NodeJS and in a ES enabled browser.",
4
- "version": "0.14.3",
4
+ "version": "0.14.5",
5
5
  "license": "Apache-2.0",
6
6
  "exports": {
7
7
  "./browser.js": {
@@ -439,6 +439,10 @@ export interface ContextListOptions {
439
439
  * Some specific list operations might use this directly if not part of the main path.
440
440
  */
441
441
  oid?: string
442
+ /**
443
+ * Optional user id to filter results by the user
444
+ */
445
+ uid?: string
442
446
  /**
443
447
  * A structured filter object for advanced querying.
444
448
  */
@@ -22,3 +22,4 @@ export const OrganizationKind = 'Core#Organization'
22
22
  export const InvitationKind = 'Core#Invitation'
23
23
  export const ApiModelKind = 'Core#ApiModel'
24
24
  export const ApiFileKind = 'Core#ApiFile'
25
+ export const GroupKind = 'Core#Group'
@@ -1,21 +1,167 @@
1
+ import { GroupKind } from '../kinds.js'
2
+ import type { IDeletion } from './Deletion.js'
3
+ import { nanoid } from '../../nanoid.js'
4
+
5
+ /**
6
+ * @deprecated Use `GroupSchema` instead.
7
+ * This interface is kept for backward compatibility.
8
+ */
9
+ // eslint-disable-next-line @typescript-eslint/no-empty-object-type
10
+ export interface IGroup extends GroupSchema {}
11
+
1
12
  /**
2
13
  * An object representing a user group.
3
14
  */
4
- export interface IGroup {
15
+ export interface GroupSchema {
16
+ kind: typeof GroupKind
5
17
  /**
6
18
  * The key of the group.
19
+ * If not provided, it will be generated automatically by the API
7
20
  */
8
21
  key: string
9
22
  /**
10
- * The name of the group
23
+ * The name of the group.
24
+ * This is a required field and must be unique within the organization.
25
+ * @required
11
26
  */
12
27
  name: string
28
+ /**
29
+ * The description of the group.
30
+ */
31
+ description?: string
13
32
  /**
14
33
  * The id of the user that created this group.
34
+ * This field is ignored by the API and is set automatically.
35
+ * @readonly
15
36
  */
16
37
  owner: string
38
+ /**
39
+ * The icon of the group, if any.
40
+ * An optional icon for the group, stored as a URL or path.
41
+ * Max 255 characters.
42
+ */
43
+ icon?: string
44
+ /**
45
+ * The color of the group, if any.
46
+ * An optional color for the group, stored as a hex code.
47
+ * Max 50 characters (including the #).
48
+ */
49
+ color?: string
50
+ /**
51
+ * The organization ID this group belongs to.
52
+ * This field is ignored by the API and is set automatically.
53
+ * @readonly
54
+ */
55
+ oid: string
17
56
  /**
18
57
  * The list of users in this group.
58
+ * This field is ignored by the API and is set automatically.
59
+ * @readonly
19
60
  */
20
61
  users: string[]
62
+ /**
63
+ * Describes when this group was created
64
+ * This field is ignored by the API and is set automatically.
65
+ * @readonly
66
+ */
67
+ createdAt: number
68
+ /**
69
+ * Describes when this group was updated
70
+ * This field is ignored by the API and is set automatically.
71
+ * @readonly
72
+ */
73
+ updatedAt: number
74
+ /**
75
+ * Optional deletion information if the group has been deleted.
76
+ * This field is ignored by the API and is set automatically.
77
+ * @readonly
78
+ */
79
+ deleteInfo?: IDeletion
80
+ }
81
+
82
+ export class Group implements GroupSchema {
83
+ kind: typeof GroupKind = GroupKind
84
+ key = ''
85
+ name = ''
86
+ description?: string
87
+ owner = ''
88
+ icon?: string
89
+ color?: string
90
+ oid = ''
91
+ users: string[] = []
92
+ createdAt = 0
93
+ updatedAt = 0
94
+ deleteInfo?: IDeletion
95
+
96
+ static createSchema(input: Partial<GroupSchema> = {}): GroupSchema {
97
+ const { key = nanoid() } = input
98
+ const result: GroupSchema = {
99
+ kind: GroupKind,
100
+ key,
101
+ name: input.name || 'Unnamed group',
102
+ oid: input.oid || '',
103
+ owner: input.owner || '',
104
+ users: input.users || [],
105
+ createdAt: input.createdAt || Date.now(),
106
+ updatedAt: input.updatedAt || Date.now(),
107
+ }
108
+ if (input.description) {
109
+ result.description = input.description
110
+ }
111
+ if (input.icon) {
112
+ result.icon = input.icon
113
+ }
114
+ if (input.color) {
115
+ result.color = input.color
116
+ }
117
+ if (input.deleteInfo) {
118
+ result.deleteInfo = input.deleteInfo
119
+ }
120
+ return result
121
+ }
122
+
123
+ static fromName(name: string, oid: string): Group {
124
+ return new Group({ name, oid })
125
+ }
126
+
127
+ constructor(state?: Partial<GroupSchema>) {
128
+ const init = Group.createSchema(state)
129
+ this.key = init.key
130
+ this.name = init.name
131
+ this.description = init.description
132
+ this.owner = init.owner
133
+ this.icon = init.icon
134
+ this.color = init.color
135
+ this.oid = init.oid
136
+ this.users = init.users
137
+ this.createdAt = init.createdAt
138
+ this.updatedAt = init.updatedAt
139
+ this.deleteInfo = init.deleteInfo
140
+ }
141
+
142
+ toJSON(): GroupSchema {
143
+ const result: GroupSchema = {
144
+ kind: this.kind,
145
+ key: GroupKind,
146
+ name: this.name,
147
+ oid: this.oid,
148
+ owner: this.owner,
149
+ users: [...this.users],
150
+ createdAt: this.createdAt,
151
+ updatedAt: this.updatedAt,
152
+ }
153
+ if (this.description) {
154
+ result.description = this.description
155
+ }
156
+ if (this.icon) {
157
+ result.icon = this.icon
158
+ }
159
+ if (this.color) {
160
+ result.color = this.color
161
+ }
162
+ if (this.deleteInfo) {
163
+ result.deleteInfo = { ...this.deleteInfo }
164
+ }
165
+ return result
166
+ }
21
167
  }
@@ -0,0 +1,214 @@
1
+ import { ContextListOptions, ContextListResult } from '../browser.js'
2
+ import { Exception } from '../exceptions/exception.js'
3
+ import type { GroupSchema } from '../models/store/Group.js'
4
+ import { RouteBuilder } from './RouteBuilder.js'
5
+ import {
6
+ E_INVALID_JSON,
7
+ E_RESPONSE_NO_VALUE,
8
+ E_RESPONSE_STATUS,
9
+ E_RESPONSE_UNKNOWN,
10
+ SdkBase,
11
+ type SdkOptions,
12
+ } from './SdkBase.js'
13
+
14
+ export class GroupsSdk extends SdkBase {
15
+ /**
16
+ * Creates a new group in the specified organization.
17
+ * @param oid The organization ID where the group will be created.
18
+ * @param info The information about the group to create. See the `GroupSchema` interface for required fields.
19
+ * @param request Optional SDK options, including authentication token.
20
+ * @returns A promise that resolves to the created group.
21
+ */
22
+ async create(oid: string, info: Partial<GroupSchema>, request: SdkOptions = {}): Promise<GroupSchema> {
23
+ const { token } = request
24
+ const url = this.sdk.getUrl(RouteBuilder.groups(oid))
25
+ const body = JSON.stringify(info)
26
+ const result = await this.sdk.http.post(url.toString(), {
27
+ token,
28
+ body,
29
+ headers: {
30
+ 'content-type': 'application/json',
31
+ },
32
+ })
33
+ this.inspectCommonStatusCodes(result)
34
+ const E_PREFIX = 'Unable to create a group. '
35
+ if (result.status !== 201) {
36
+ this.logInvalidResponse(result)
37
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
38
+ }
39
+
40
+ if (!result.body) {
41
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
42
+ }
43
+ let data: GroupSchema
44
+ try {
45
+ data = JSON.parse(result.body)
46
+ } catch {
47
+ throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
48
+ }
49
+ if (!data.key) {
50
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
51
+ }
52
+ return data
53
+ }
54
+
55
+ /**
56
+ * Lists user groups in the specified organization.
57
+ * If you want to list specific user groups, you can use the `uid` option to filter by user ID.
58
+ * @param oid The organization ID to list groups from.
59
+ * @param options Optional parameters for filtering, sorting, and pagination.
60
+ * @param request Optional SDK options, including authentication token.
61
+ * @returns A promise that resolves to a list of groups in the organization.
62
+ */
63
+ async list(
64
+ oid: string,
65
+ options: ContextListOptions = {},
66
+ request: SdkOptions = {}
67
+ ): Promise<ContextListResult<GroupSchema>> {
68
+ const { token } = request
69
+ const url = this.sdk.getUrl(RouteBuilder.groups(oid))
70
+ this.sdk.appendListOptions(url, options)
71
+ const result = await this.sdk.http.get(url.toString(), { token })
72
+ this.inspectCommonStatusCodes(result)
73
+ const E_PREFIX = 'Unable to create a group. '
74
+ if (result.status !== 200) {
75
+ this.logInvalidResponse(result)
76
+ throw this.createApiError(E_PREFIX + E_RESPONSE_STATUS + result.status, result.body)
77
+ }
78
+ if (!result.body) {
79
+ throw new Exception(E_PREFIX + E_RESPONSE_NO_VALUE, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
80
+ }
81
+ let data: ContextListResult<GroupSchema>
82
+ try {
83
+ data = JSON.parse(result.body)
84
+ } catch {
85
+ throw new Exception(E_PREFIX + E_INVALID_JSON, { code: 'E_INVALID_JSON', status: result.status })
86
+ }
87
+ return data
88
+ }
89
+
90
+ /**
91
+ * Updates an existing group in the specified organization.
92
+ * Note that this method support PUT requests only. Some fields are ignored by the API and are set automatically.
93
+ * @param oid The organization ID where the group exists.
94
+ * @param updated The updated information for the group. Must include the `key` of the group to update.
95
+ * @param request Optional SDK options, including authentication token.
96
+ * @returns A promise that resolves to the updated group.
97
+ */
98
+ async update(oid: string, updated: GroupSchema, request: SdkOptions = {}): Promise<GroupSchema> {
99
+ const { token } = request
100
+ const url = this.sdk.getUrl(RouteBuilder.group(oid, updated.key))
101
+ const body = JSON.stringify(updated)
102
+ const result = await this.sdk.http.put(url.toString(), {
103
+ token,
104
+ body,
105
+ headers: {
106
+ 'content-type': 'application/json',
107
+ },
108
+ })
109
+ this.inspectCommonStatusCodes(result)
110
+ const E_PREFIX = 'Unable to update a group. '
111
+ if (result.status !== 200) {
112
+ this.logInvalidResponse(result)
113
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
114
+ }
115
+
116
+ if (!result.body) {
117
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
118
+ }
119
+ let data: GroupSchema
120
+ try {
121
+ data = JSON.parse(result.body)
122
+ } catch {
123
+ throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
124
+ }
125
+ if (!data.key) {
126
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
127
+ }
128
+ return data
129
+ }
130
+
131
+ /**
132
+ * Deletes a group in the specified organization.
133
+ * The groups support soft deletion, meaning that the group is not immediately removed from the database.
134
+ * @param oid The organization ID where the group exists.
135
+ * @param gid The group ID to delete.
136
+ * @param request Optional SDK options, including authentication token.
137
+ * @returns A promise that resolves when the group is deleted.
138
+ */
139
+ async delete(oid: string, gid: string, request: SdkOptions = {}): Promise<void> {
140
+ const { token } = request
141
+ const url = this.sdk.getUrl(RouteBuilder.group(oid, gid))
142
+ const result = await this.sdk.http.delete(url.toString(), { token })
143
+ this.inspectCommonStatusCodes(result)
144
+ const E_PREFIX = 'Unable to delete a group. '
145
+ if (result.status !== 204) {
146
+ this.logInvalidResponse(result)
147
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
148
+ }
149
+ }
150
+
151
+ async addUsers(oid: string, gid: string, uids: string[], request: SdkOptions = {}): Promise<GroupSchema> {
152
+ const { token } = request
153
+ const url = this.sdk.getUrl(RouteBuilder.groupUsers(oid, gid))
154
+ const body = JSON.stringify({ ids: uids })
155
+ const result = await this.sdk.http.post(url.toString(), {
156
+ token,
157
+ body,
158
+ headers: {
159
+ 'content-type': 'application/json',
160
+ },
161
+ })
162
+ this.inspectCommonStatusCodes(result)
163
+ const E_PREFIX = 'Unable to add users to a group. '
164
+ if (result.status !== 200) {
165
+ this.logInvalidResponse(result)
166
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
167
+ }
168
+ if (!result.body) {
169
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
170
+ }
171
+ let data: GroupSchema
172
+ try {
173
+ data = JSON.parse(result.body)
174
+ } catch {
175
+ throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
176
+ }
177
+ if (!data.key) {
178
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
179
+ }
180
+ return data
181
+ }
182
+
183
+ async removeUsers(oid: string, gid: string, uids: string[], request: SdkOptions = {}): Promise<GroupSchema> {
184
+ const { token } = request
185
+ const url = this.sdk.getUrl(RouteBuilder.groupUsers(oid, gid))
186
+ const body = JSON.stringify({ ids: uids })
187
+ const result = await this.sdk.http.delete(url.toString(), {
188
+ token,
189
+ body,
190
+ headers: {
191
+ 'content-type': 'application/json',
192
+ },
193
+ })
194
+ this.inspectCommonStatusCodes(result)
195
+ const E_PREFIX = 'Unable to remove users from a group. '
196
+ if (result.status !== 200) {
197
+ this.logInvalidResponse(result)
198
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
199
+ }
200
+ if (!result.body) {
201
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
202
+ }
203
+ let data: GroupSchema
204
+ try {
205
+ data = JSON.parse(result.body)
206
+ } catch {
207
+ throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
208
+ }
209
+ if (!data.key) {
210
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
211
+ }
212
+ return data
213
+ }
214
+ }
@@ -287,4 +287,16 @@ export class RouteBuilder {
287
287
  static dataCatalogVersionUnpublish(entryId: string, version: string): string {
288
288
  return `${RouteBuilder.dataCatalogVersion(entryId, version)}/unpublish`
289
289
  }
290
+
291
+ static groups(oid: string): string {
292
+ return `/v1/orgs/${oid}/groups`
293
+ }
294
+
295
+ static group(oid: string, gid: string): string {
296
+ return `/v1/orgs/${oid}/groups/${gid}`
297
+ }
298
+
299
+ static groupUsers(oid: string, gid: string): string | undefined {
300
+ return `/v1/orgs/${oid}/groups/${gid}/users`
301
+ }
290
302
  }
package/src/sdk/Sdk.ts CHANGED
@@ -11,6 +11,7 @@ import { TrashSdk } from './TrashSdk.js'
11
11
  import { ProjectExecutionSdk } from './ProjectExecutionsSdk.js'
12
12
  import { OrganizationsSdk } from './OrganizationsSdk.js'
13
13
  import { DataCatalogSdk } from './DataCatalogSdk.js'
14
+ import { GroupsSdk } from './GroupsSdk.js'
14
15
 
15
16
  const baseUriSymbol = Symbol('baseUri')
16
17
 
@@ -70,6 +71,8 @@ export abstract class Sdk {
70
71
  organizations = new OrganizationsSdk(this)
71
72
 
72
73
  dataCatalog = new DataCatalogSdk(this)
74
+
75
+ groups = new GroupsSdk(this)
73
76
  /**
74
77
  * When set it limits log output to minimum.
75
78
  */
@@ -162,6 +165,9 @@ export abstract class Sdk {
162
165
  if (options.oid) {
163
166
  searchParams.set('oid', String(options.oid))
164
167
  }
168
+ if (options.uid) {
169
+ searchParams.set('uid', String(options.uid))
170
+ }
165
171
  if (options.filter) {
166
172
  const bytes = new TextEncoder().encode(JSON.stringify(options.filter))
167
173
  // To be used when Uint8Array.prototype.toBase64() is available.