@api-client/core 0.18.35 → 0.18.37
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/build/src/sdk/SdkMock.d.ts +29 -12
- package/build/src/sdk/SdkMock.d.ts.map +1 -1
- package/build/src/sdk/SdkMock.js +182 -32
- package/build/src/sdk/SdkMock.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -2
- package/src/sdk/SdkMock.ts +196 -33
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.18.
|
|
4
|
+
"version": "0.18.37",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"exports": {
|
|
7
7
|
"./browser.js": {
|
|
@@ -92,7 +92,7 @@
|
|
|
92
92
|
"@pawel-up/csv": "^0.2.0",
|
|
93
93
|
"@pawel-up/data-mock": "^0.4.0",
|
|
94
94
|
"@pawel-up/jexl": "^4.0.1",
|
|
95
|
-
"@types/sinon": "^
|
|
95
|
+
"@types/sinon": "^21.0.0",
|
|
96
96
|
"@xmldom/xmldom": "^0.8.11",
|
|
97
97
|
"amf-json-ld-lib": "^0.0.15",
|
|
98
98
|
"chalk": "^5.4.1",
|
|
@@ -116,6 +116,7 @@
|
|
|
116
116
|
"@japa/runner": "^4.2.0",
|
|
117
117
|
"@pawel-up/semver": "^0.1.4",
|
|
118
118
|
"@rollup/plugin-typescript": "^12.1.2",
|
|
119
|
+
"@types/chai-as-promised": "^8.0.2",
|
|
119
120
|
"@types/cors": "^2.8.12",
|
|
120
121
|
"@types/express-ntlm": "^2.3.3",
|
|
121
122
|
"@types/jsdom": "^27.0.0",
|
|
@@ -128,6 +129,7 @@
|
|
|
128
129
|
"@web/test-runner-playwright": "^0.11.0",
|
|
129
130
|
"amf-client-js": "^5.9.1-3",
|
|
130
131
|
"c8": "^10.1.3",
|
|
132
|
+
"chai-as-promised": "^8.0.2",
|
|
131
133
|
"conventional-changelog-cli": "^5.0.0",
|
|
132
134
|
"cors": "^2.8.5",
|
|
133
135
|
"eslint": "^9.20.1",
|
package/src/sdk/SdkMock.ts
CHANGED
|
@@ -2,8 +2,8 @@ import { nanoid } from '../nanoid.js'
|
|
|
2
2
|
import type { IOrganization } from '../models/store/Organization.js'
|
|
3
3
|
import type { GroupSchema } from '../models/store/Group.js'
|
|
4
4
|
import type { IUser } from '../models/store/User.js'
|
|
5
|
-
import {
|
|
6
|
-
import { GroupKind } from '../models/kinds.js'
|
|
5
|
+
import type { InvitationSchema } from '../models/store/Invitation.js'
|
|
6
|
+
import { OrganizationKind, GroupKind, InvitationKind } from '../models/kinds.js'
|
|
7
7
|
import { Kind as UserKind } from '../models/store/User.js'
|
|
8
8
|
import { File, type IFile, type FileBreadcrumb } from '../models/store/File.js'
|
|
9
9
|
import { CertificateFileKind, DomainFileKind, FolderKind, ProjectKind } from '../models/kinds.js'
|
|
@@ -115,34 +115,133 @@ export class SdkMock {
|
|
|
115
115
|
})
|
|
116
116
|
},
|
|
117
117
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
|
|
118
|
+
invitations: {
|
|
119
|
+
list: (options?: MockResponseOptions): StubReference => {
|
|
120
|
+
return this.createStub('organizations.invitations', 'list', () => {
|
|
121
|
+
const defaultData = {
|
|
122
|
+
items: [this.generateInvitation(), this.generateInvitation()],
|
|
123
|
+
}
|
|
124
|
+
if (options?.status !== undefined && options.status !== 200) {
|
|
125
|
+
throw new Exception('Mocked error', { status: options.status })
|
|
126
|
+
}
|
|
127
|
+
return (options?.data ?? defaultData) as unknown
|
|
128
|
+
})
|
|
129
|
+
},
|
|
130
|
+
create: (options?: MockResponseOptions): StubReference => {
|
|
131
|
+
return this.createStub('organizations.invitations', 'create', () => {
|
|
132
|
+
const defaultData = this.generateInvitation()
|
|
133
|
+
if (options?.status !== undefined && options.status !== 200) {
|
|
134
|
+
throw new Exception('Mocked error', { status: options.status })
|
|
135
|
+
}
|
|
136
|
+
return (options?.data ?? defaultData) as unknown
|
|
137
|
+
})
|
|
138
|
+
},
|
|
139
|
+
findByToken: (options?: MockResponseOptions): StubReference => {
|
|
140
|
+
return this.createStub('organizations.invitations', 'findByToken', () => {
|
|
141
|
+
const defaultData = this.generateInvitation()
|
|
142
|
+
if (options?.status !== undefined && options.status !== 200) {
|
|
143
|
+
throw new Exception('Mocked error', { status: options.status })
|
|
144
|
+
}
|
|
145
|
+
return (options?.data ?? defaultData) as unknown
|
|
146
|
+
})
|
|
147
|
+
},
|
|
148
|
+
decline: (options?: MockResponseOptions): StubReference => {
|
|
149
|
+
return this.createStub('organizations.invitations', 'decline', () => {
|
|
150
|
+
const defaultData = this.generateInvitation()
|
|
151
|
+
if (options?.status !== undefined && options.status !== 200) {
|
|
152
|
+
throw new Exception('Mocked error', { status: options.status })
|
|
153
|
+
}
|
|
154
|
+
return (options?.data ?? defaultData) as unknown
|
|
155
|
+
})
|
|
156
|
+
},
|
|
157
|
+
delete: (options?: MockResponseOptions): StubReference => {
|
|
158
|
+
return this.createStub('organizations.invitations', 'delete', () => {
|
|
159
|
+
const defaultData = this.generateInvitation()
|
|
160
|
+
if (options?.status !== undefined && options.status !== 200) {
|
|
161
|
+
throw new Exception('Mocked error', { status: options.status })
|
|
162
|
+
}
|
|
163
|
+
return (options?.data ?? defaultData) as unknown
|
|
164
|
+
})
|
|
165
|
+
},
|
|
166
|
+
patch: (options?: MockResponseOptions): StubReference => {
|
|
167
|
+
return this.createStub('organizations.invitations', 'patch', () => {
|
|
168
|
+
const defaultData = this.generateInvitation()
|
|
169
|
+
if (options?.status !== undefined && options.status !== 200) {
|
|
170
|
+
throw new Exception('Mocked error', { status: options.status })
|
|
171
|
+
}
|
|
172
|
+
return (options?.data ?? defaultData) as unknown
|
|
173
|
+
})
|
|
174
|
+
},
|
|
175
|
+
resend: (options?: MockResponseOptions): StubReference => {
|
|
176
|
+
return this.createStub('organizations.invitations', 'resend', () => {
|
|
177
|
+
const defaultData = this.generateInvitation()
|
|
178
|
+
if (options?.status !== undefined && options.status !== 200) {
|
|
179
|
+
throw new Exception('Mocked error', { status: options.status })
|
|
180
|
+
}
|
|
181
|
+
return (options?.data ?? defaultData) as unknown
|
|
182
|
+
})
|
|
183
|
+
},
|
|
131
184
|
},
|
|
132
185
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
|
|
186
|
+
users: {
|
|
187
|
+
list: (options?: MockResponseOptions): StubReference => {
|
|
188
|
+
return this.createStub('organizations.users', 'list', () => {
|
|
189
|
+
const defaultData = {
|
|
190
|
+
items: [this.generateUser(), this.generateUser()],
|
|
191
|
+
}
|
|
192
|
+
if (options?.status !== undefined && options.status !== 200) {
|
|
193
|
+
throw new Exception('Mocked error', { status: options.status })
|
|
194
|
+
}
|
|
195
|
+
return (options?.data ?? defaultData) as unknown
|
|
196
|
+
})
|
|
197
|
+
},
|
|
198
|
+
read: (options?: MockResponseOptions): StubReference => {
|
|
199
|
+
return this.createStub('organizations.users', 'read', () => {
|
|
200
|
+
const defaultData = this.generateUser()
|
|
201
|
+
if (options?.status !== undefined && options.status !== 200) {
|
|
202
|
+
throw new Exception('Mocked error', { status: options.status })
|
|
203
|
+
}
|
|
204
|
+
return (options?.data ?? defaultData) as unknown
|
|
205
|
+
})
|
|
206
|
+
},
|
|
207
|
+
readBatch: (options?: MockResponseOptions): StubReference => {
|
|
208
|
+
return this.createStub('organizations.users', 'readBatch', () => {
|
|
209
|
+
const defaultData = {
|
|
210
|
+
items: [this.generateUser(), this.generateUser()],
|
|
211
|
+
}
|
|
212
|
+
if (options?.status !== undefined && options.status !== 200) {
|
|
213
|
+
throw new Exception('Mocked error', { status: options.status })
|
|
214
|
+
}
|
|
215
|
+
return (options?.data ?? defaultData) as unknown
|
|
216
|
+
})
|
|
217
|
+
},
|
|
218
|
+
activate: (options?: MockResponseOptions): StubReference => {
|
|
219
|
+
return this.createStub('organizations.users', 'activate', () => {
|
|
220
|
+
const defaultData = this.generateUser()
|
|
221
|
+
if (options?.status !== undefined && options.status !== 200) {
|
|
222
|
+
throw new Exception('Mocked error', { status: options.status })
|
|
223
|
+
}
|
|
224
|
+
return (options?.data ?? defaultData) as unknown
|
|
225
|
+
})
|
|
226
|
+
},
|
|
227
|
+
deactivate: (options?: MockResponseOptions): StubReference => {
|
|
228
|
+
return this.createStub('organizations.users', 'deactivate', () => {
|
|
229
|
+
const defaultData = this.generateUser()
|
|
230
|
+
if (options?.status !== undefined && options.status !== 200) {
|
|
231
|
+
throw new Exception('Mocked error', { status: options.status })
|
|
232
|
+
}
|
|
233
|
+
return (options?.data ?? defaultData) as unknown
|
|
234
|
+
})
|
|
235
|
+
},
|
|
236
|
+
delete: (options?: MockResponseOptions): StubReference => {
|
|
237
|
+
return this.createStub('organizations.users', 'delete', () => {
|
|
238
|
+
const status = options?.status ?? 204
|
|
239
|
+
if (status !== 204) {
|
|
240
|
+
throw new Exception('Mocked error', { status })
|
|
241
|
+
}
|
|
242
|
+
return undefined
|
|
243
|
+
})
|
|
244
|
+
},
|
|
146
245
|
},
|
|
147
246
|
}
|
|
148
247
|
|
|
@@ -228,6 +327,32 @@ export class SdkMock {
|
|
|
228
327
|
return undefined
|
|
229
328
|
})
|
|
230
329
|
},
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Mocks the `groups.addUsers()` method.
|
|
333
|
+
*/
|
|
334
|
+
addUsers: (options?: MockResponseOptions): StubReference => {
|
|
335
|
+
return this.createStub('groups', 'addUsers', () => {
|
|
336
|
+
const defaultData = this.generateGroup()
|
|
337
|
+
if (options?.status !== undefined && options.status !== 200) {
|
|
338
|
+
throw new Exception('Mocked error', { status: options.status })
|
|
339
|
+
}
|
|
340
|
+
return (options?.data ?? defaultData) as unknown
|
|
341
|
+
})
|
|
342
|
+
},
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Mocks the `groups.removeUsers()` method.
|
|
346
|
+
*/
|
|
347
|
+
removeUsers: (options?: MockResponseOptions): StubReference => {
|
|
348
|
+
return this.createStub('groups', 'removeUsers', () => {
|
|
349
|
+
const defaultData = this.generateGroup()
|
|
350
|
+
if (options?.status !== undefined && options.status !== 200) {
|
|
351
|
+
throw new Exception('Mocked error', { status: options.status })
|
|
352
|
+
}
|
|
353
|
+
return (options?.data ?? defaultData) as unknown
|
|
354
|
+
})
|
|
355
|
+
},
|
|
231
356
|
}
|
|
232
357
|
|
|
233
358
|
/**
|
|
@@ -243,7 +368,7 @@ export class SdkMock {
|
|
|
243
368
|
return this.createStub('user', 'me', () => {
|
|
244
369
|
const defaultData = this.generateUser()
|
|
245
370
|
if (options?.status !== undefined && options.status !== 200) {
|
|
246
|
-
throw new Exception(
|
|
371
|
+
throw new Exception(`Mocked error. Status: ${options.status}`, { status: options.status })
|
|
247
372
|
}
|
|
248
373
|
return (options?.data ?? defaultData) as unknown
|
|
249
374
|
})
|
|
@@ -587,15 +712,28 @@ export class SdkMock {
|
|
|
587
712
|
* @returns A stub reference.
|
|
588
713
|
*/
|
|
589
714
|
private createStub(
|
|
590
|
-
api:
|
|
715
|
+
api:
|
|
716
|
+
| 'organizations'
|
|
717
|
+
| 'groups'
|
|
718
|
+
| 'user'
|
|
719
|
+
| 'auth'
|
|
720
|
+
| 'file'
|
|
721
|
+
| 'shared'
|
|
722
|
+
| 'trash'
|
|
723
|
+
| 'organizations.invitations'
|
|
724
|
+
| 'organizations.users',
|
|
591
725
|
method: string,
|
|
592
726
|
implementation: () => unknown,
|
|
593
727
|
sync?: boolean
|
|
594
728
|
): StubReference {
|
|
595
729
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
730
|
+
let target: any = this.sdk
|
|
731
|
+
const parts = api.split('.')
|
|
732
|
+
for (const part of parts) {
|
|
733
|
+
target = target[part]
|
|
734
|
+
if (!target) {
|
|
735
|
+
throw new Error(`API '${api}' not found in SDK`)
|
|
736
|
+
}
|
|
599
737
|
}
|
|
600
738
|
|
|
601
739
|
const original = target[method]
|
|
@@ -736,6 +874,31 @@ export class SdkMock {
|
|
|
736
874
|
return items
|
|
737
875
|
}
|
|
738
876
|
|
|
877
|
+
/**
|
|
878
|
+
* Generates a random invitation object.
|
|
879
|
+
*/
|
|
880
|
+
private generateInvitation(): InvitationSchema {
|
|
881
|
+
const firstName = this.randomString()
|
|
882
|
+
const lastName = this.randomString()
|
|
883
|
+
const now = Date.now()
|
|
884
|
+
return {
|
|
885
|
+
kind: InvitationKind,
|
|
886
|
+
key: nanoid(),
|
|
887
|
+
uid: nanoid(),
|
|
888
|
+
oid: nanoid(),
|
|
889
|
+
email: `${firstName.toLowerCase()}.${lastName.toLowerCase()}@example.com`,
|
|
890
|
+
name: `${firstName} ${lastName}`,
|
|
891
|
+
token: nanoid(),
|
|
892
|
+
expiresAt: now + 7 * 24 * 60 * 60 * 1000,
|
|
893
|
+
status: 'pending',
|
|
894
|
+
grantType: this.randomChoice(['owner', 'manager', 'editor', 'viewer'] as const),
|
|
895
|
+
createdAt: now - Math.random() * 1000 * 60 * 60 * 24,
|
|
896
|
+
updatedAt: now - Math.random() * 1000 * 60 * 60,
|
|
897
|
+
resent: 0,
|
|
898
|
+
lastSentAt: now - Math.random() * 1000 * 60 * 60,
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
|
|
739
902
|
/**
|
|
740
903
|
* Generates a random trash entry.
|
|
741
904
|
*/
|