@api-client/core 0.18.35 → 0.18.36

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/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.35",
4
+ "version": "0.18.36",
5
5
  "license": "Apache-2.0",
6
6
  "exports": {
7
7
  "./browser.js": {
@@ -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 { OrganizationKind } from '../models/kinds.js'
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
- * Mocks the `organizations.read()` method.
120
- * @param options Optional response customization.
121
- * @returns A stub reference that can be used to restore the original behavior.
122
- */
123
- read: (options?: MockResponseOptions): StubReference => {
124
- return this.createStub('organizations', 'read', () => {
125
- const defaultData = this.generateOrganization()
126
- if (options?.status !== undefined && options.status !== 200) {
127
- throw new Exception('Mocked error', { status: options.status })
128
- }
129
- return (options?.data ?? defaultData) as unknown
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
- * Mocks the `organizations.delete()` method.
135
- * @param options Optional response customization.
136
- * @returns A stub reference that can be used to restore the original behavior.
137
- */
138
- delete: (options?: MockResponseOptions): StubReference => {
139
- return this.createStub('organizations', 'delete', () => {
140
- const status = options?.status ?? 204
141
- if (status !== 204) {
142
- throw new Exception('Mocked error', { status })
143
- }
144
- return undefined
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
  /**
@@ -587,15 +712,28 @@ export class SdkMock {
587
712
  * @returns A stub reference.
588
713
  */
589
714
  private createStub(
590
- api: 'organizations' | 'groups' | 'user' | 'auth' | 'file' | 'shared' | 'trash',
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
- const target = (this.sdk as any)[api]
597
- if (!target) {
598
- throw new Error(`API '${api}' not found in SDK`)
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
  */