@api-client/core 0.19.35 → 0.19.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.
Files changed (58) hide show
  1. package/build/src/events/BaseEvents.d.ts +14 -4
  2. package/build/src/events/BaseEvents.d.ts.map +1 -1
  3. package/build/src/events/BaseEvents.js +14 -0
  4. package/build/src/events/BaseEvents.js.map +1 -1
  5. package/build/src/mocking/lib/Deployment.d.ts +3 -0
  6. package/build/src/mocking/lib/Deployment.d.ts.map +1 -1
  7. package/build/src/mocking/lib/Deployment.js +11 -0
  8. package/build/src/mocking/lib/Deployment.js.map +1 -1
  9. package/build/src/models/store/Deployment.d.ts +4 -4
  10. package/build/src/models/store/Deployment.d.ts.map +1 -1
  11. package/build/src/models/store/Deployment.js +4 -4
  12. package/build/src/models/store/Deployment.js.map +1 -1
  13. package/build/src/sdk/AiSdk.js +2 -2
  14. package/build/src/sdk/AiSdk.js.map +1 -1
  15. package/build/src/sdk/DeploymentsSdk.d.ts +50 -5
  16. package/build/src/sdk/DeploymentsSdk.d.ts.map +1 -1
  17. package/build/src/sdk/DeploymentsSdk.js +31 -11
  18. package/build/src/sdk/DeploymentsSdk.js.map +1 -1
  19. package/build/src/sdk/FilesSdk.js +4 -4
  20. package/build/src/sdk/FilesSdk.js.map +1 -1
  21. package/build/src/sdk/HistorySdk.js +3 -3
  22. package/build/src/sdk/HistorySdk.js.map +1 -1
  23. package/build/src/sdk/OrganizationsSdk.js +4 -4
  24. package/build/src/sdk/OrganizationsSdk.js.map +1 -1
  25. package/build/src/sdk/RevisionsSdk.js +1 -1
  26. package/build/src/sdk/RevisionsSdk.js.map +1 -1
  27. package/build/src/sdk/RouteBuilder.d.ts +2 -4
  28. package/build/src/sdk/RouteBuilder.d.ts.map +1 -1
  29. package/build/src/sdk/RouteBuilder.js +5 -8
  30. package/build/src/sdk/RouteBuilder.js.map +1 -1
  31. package/build/src/sdk/SdkBase.d.ts +2 -2
  32. package/build/src/sdk/SdkBase.d.ts.map +1 -1
  33. package/build/src/sdk/SdkBase.js +6 -5
  34. package/build/src/sdk/SdkBase.js.map +1 -1
  35. package/build/src/sdk/SdkMock.d.ts +17 -14
  36. package/build/src/sdk/SdkMock.d.ts.map +1 -1
  37. package/build/src/sdk/SdkMock.js +158 -209
  38. package/build/src/sdk/SdkMock.js.map +1 -1
  39. package/build/src/sdk/SharedSdk.js +1 -1
  40. package/build/src/sdk/SharedSdk.js.map +1 -1
  41. package/build/src/sdk/TrashSdk.js +1 -1
  42. package/build/src/sdk/TrashSdk.js.map +1 -1
  43. package/build/tsconfig.tsbuildinfo +1 -1
  44. package/package.json +2 -2
  45. package/src/events/BaseEvents.ts +20 -4
  46. package/src/mocking/lib/Deployment.ts +14 -0
  47. package/src/models/store/Deployment.ts +4 -4
  48. package/src/sdk/AiSdk.ts +2 -2
  49. package/src/sdk/DeploymentsSdk.ts +66 -19
  50. package/src/sdk/FilesSdk.ts +4 -4
  51. package/src/sdk/HistorySdk.ts +3 -3
  52. package/src/sdk/OrganizationsSdk.ts +4 -4
  53. package/src/sdk/RevisionsSdk.ts +1 -1
  54. package/src/sdk/RouteBuilder.ts +6 -11
  55. package/src/sdk/SdkBase.ts +6 -6
  56. package/src/sdk/SdkMock.ts +177 -270
  57. package/src/sdk/SharedSdk.ts +1 -1
  58. package/src/sdk/TrashSdk.ts +1 -1
@@ -11,7 +11,13 @@ import type { GroupSchema } from '../models/store/Group.js'
11
11
  import type { UserSchema } from '../models/store/User.js'
12
12
  import type { InvitationSchema } from '../models/store/Invitation.js'
13
13
  import { type FileSchema, type FileBreadcrumb } from '../models/store/File.js'
14
- import type { ContextChangeRecord, ContextListResult, IBulkOperationResult } from '../events/BaseEvents.js'
14
+ import {
15
+ isAtomicFilter,
16
+ type ContextChangeRecord,
17
+ type ContextListResult,
18
+ type IBulkOperationResult,
19
+ type QueryFilter,
20
+ } from '../events/BaseEvents.js'
15
21
  import type { TrashEntry } from '../models/TrashEntry.js'
16
22
  import { RouteBuilder } from './RouteBuilder.js'
17
23
  import { ModelingMock } from '../mocking/ModelingMock.js'
@@ -29,7 +35,7 @@ import type { AiSessionSchema, AiSessionApp } from '../models/AiSession.js'
29
35
  import type { AiMessageSchema } from '../models/AiMessage.js'
30
36
  import type { DeploymentSchema } from '../models/store/Deployment.js'
31
37
  import { DeploymentEnvironment } from '../models/store/Deployment.js'
32
- import type { CreateDeploymentPayload } from './DeploymentsSdk.js'
38
+ import type { CreateDeploymentPayload, DeploymentApi, DeploymentLatestEnvironmentsResponse } from './DeploymentsSdk.js'
33
39
 
34
40
  export interface MockResult {
35
41
  /**
@@ -152,49 +158,6 @@ export class SdkMock {
152
158
  return this.handler
153
159
  }
154
160
 
155
- protected createCursorOption(init: MockListResult = {}): string | undefined {
156
- if (init.cursor === false) {
157
- return undefined
158
- }
159
- const hasCursor = init.cursor === true ? true : this.gen.faker.datatype.boolean()
160
- if (!hasCursor) {
161
- return undefined
162
- }
163
- return this.gen.faker.internet.jwt()
164
- }
165
-
166
- protected createDefaultResponse(
167
- status: number,
168
- headers?: Record<string, string>,
169
- body?: (req: SerializedRequest) => string,
170
- userConfig?: MockResult
171
- ): ResponseGenerator {
172
- let respond: ResponseGenerator
173
- if (userConfig?.response) {
174
- // user config takes precedence
175
- respond = userConfig.response
176
- } else {
177
- respond = {}
178
- }
179
- // Set defaults if not provided in user config
180
- if (!respond.status) {
181
- respond.status = status
182
- }
183
- // only set headers if the user didn't configure the response only.
184
- // The user may want to remove default headers.
185
- if (!userConfig || !userConfig.response) {
186
- respond.headers = headers
187
- }
188
- if (!respond.body && userConfig?.forceBody && body) {
189
- // when body is missing and forceBody is set, generate the body
190
- respond.body = (req: SerializedRequest) => body(req)
191
- } else if (body && (!userConfig || !userConfig.response)) {
192
- // we set the body by default when the user config is missing
193
- respond.body = (req: SerializedRequest) => body(req)
194
- }
195
- return respond
196
- }
197
-
198
161
  /**
199
162
  * Organization API mocks.
200
163
  */
@@ -205,20 +168,12 @@ export class SdkMock {
205
168
  */
206
169
  list: async (init?: MockListResult, options?: InterceptOptions): Promise<void> => {
207
170
  const { mock } = this
208
- // const respond = init?.response ?? {
209
- // status: 200,
210
- // headers: { 'content-type': 'application/json' },
211
- // body: JSON.stringify({
212
- // items: this.gen.organization.organizations(init?.size ?? 5),
213
- // cursor: this.createCursorOption(init),
214
- // } as ContextListResult<OrganizationSchema>),
215
- // }
216
171
  const respond = this.createDefaultResponse(
217
172
  200,
218
173
  { 'content-type': 'application/json' },
219
174
  () =>
220
175
  JSON.stringify({
221
- items: this.gen.organization.organizations(init?.size ?? 5),
176
+ data: this.gen.organization.organizations(init?.size ?? 5),
222
177
  cursor: this.createCursorOption(init),
223
178
  } as ContextListResult<OrganizationSchema>),
224
179
  init
@@ -267,20 +222,12 @@ export class SdkMock {
267
222
  invitations: {
268
223
  list: async (init?: MockListResult, options?: InterceptOptions): Promise<void> => {
269
224
  const { mock } = this
270
- // const respond = init?.response ?? {
271
- // status: 200,
272
- // headers: { 'content-type': 'application/json' },
273
- // body: JSON.stringify({
274
- // items: this.gen.invitation.invitations(init?.size ?? 5),
275
- // cursor: this.createCursorOption(init),
276
- // } as ContextListResult<InvitationSchema>),
277
- // }
278
225
  const respond = this.createDefaultResponse(
279
226
  200,
280
227
  { 'content-type': 'application/json' },
281
228
  () => {
282
229
  const obj: ContextListResult<InvitationSchema> = {
283
- items: this.gen.invitation.invitations(init?.size ?? 5),
230
+ data: this.gen.invitation.invitations(init?.size ?? 5),
284
231
  cursor: this.createCursorOption(init),
285
232
  }
286
233
  return JSON.stringify(obj)
@@ -451,20 +398,12 @@ export class SdkMock {
451
398
  users: {
452
399
  list: async (init?: MockListResult, options?: InterceptOptions): Promise<void> => {
453
400
  const { mock } = this
454
- // const respond = init?.response ?? {
455
- // status: 200,
456
- // headers: { 'content-type': 'application/json' },
457
- // body: JSON.stringify({
458
- // items: this.gen.users.users(init?.size ?? 5),
459
- // cursor: this.createCursorOption(init),
460
- // } as ContextListResult<UserSchema>),
461
- // }
462
401
  const respond = this.createDefaultResponse(
463
402
  200,
464
403
  { 'content-type': 'application/json' },
465
404
  () => {
466
405
  const obj: ContextListResult<UserSchema> = {
467
- items: this.gen.users.users(init?.size ?? 5),
406
+ data: this.gen.users.users(init?.size ?? 5),
468
407
  cursor: this.createCursorOption(init),
469
408
  }
470
409
  return JSON.stringify(obj)
@@ -513,7 +452,7 @@ export class SdkMock {
513
452
  status: 200,
514
453
  headers: { 'content-type': 'application/json' },
515
454
  body: JSON.stringify({
516
- items: this.gen.users.users(init?.size ?? 5),
455
+ data: this.gen.users.users(init?.size ?? 5),
517
456
  cursor: this.createCursorOption(init),
518
457
  } as ContextListResult<UserSchema>),
519
458
  }
@@ -644,122 +583,6 @@ export class SdkMock {
644
583
  )
645
584
  },
646
585
  },
647
-
648
- deployments: {
649
- list: async (init?: MockListResult, options?: InterceptOptions): Promise<void> => {
650
- const { mock } = this
651
- const respond = this.createDefaultResponse(
652
- 200,
653
- { 'content-type': 'application/json' },
654
- () =>
655
- JSON.stringify({
656
- items: this.gen.deployments.deployments(init?.size ?? 5),
657
- cursor: this.createCursorOption(init),
658
- } as ContextListResult<DeploymentSchema>),
659
- init
660
- )
661
- await mock.add(
662
- {
663
- match: { uri: RouteBuilder.deployments(':oid'), methods: ['GET'] },
664
- respond,
665
- },
666
- options
667
- )
668
- },
669
-
670
- create: async (init?: MockResult, options?: InterceptOptions): Promise<void> => {
671
- const { mock } = this
672
- const respond = this.createDefaultResponse(
673
- 202,
674
- { 'content-type': 'application/json' },
675
- () => JSON.stringify(this.gen.deployments.deployment()),
676
- init
677
- )
678
- await mock.add(
679
- {
680
- match: { uri: RouteBuilder.deployments(':oid'), methods: ['POST'] },
681
- respond,
682
- },
683
- options
684
- )
685
- },
686
-
687
- read: async (init?: MockResult, options?: InterceptOptions): Promise<void> => {
688
- const { mock } = this
689
- const respond = this.createDefaultResponse(
690
- 200,
691
- { 'content-type': 'application/json' },
692
- () => JSON.stringify(this.gen.deployments.deployment()),
693
- init
694
- )
695
- await mock.add(
696
- {
697
- match: { uri: RouteBuilder.deployment(':oid', ':did'), methods: ['GET'] },
698
- respond,
699
- },
700
- options
701
- )
702
- },
703
-
704
- deactivate: async (init?: MockResult, options?: InterceptOptions): Promise<void> => {
705
- const { mock } = this
706
- const respond = this.createDefaultResponse(204, undefined, undefined, init)
707
- await mock.add(
708
- {
709
- match: { uri: RouteBuilder.deployment(':oid', ':did'), methods: ['DELETE'] },
710
- respond,
711
- },
712
- options
713
- )
714
- },
715
-
716
- apis: {
717
- listAllForApi: async (init?: MockListResult, options?: InterceptOptions): Promise<void> => {
718
- const { mock } = this
719
- const respond = this.createDefaultResponse(
720
- 200,
721
- { 'content-type': 'application/json' },
722
- () =>
723
- JSON.stringify({
724
- items: this.gen.deployments.deployments(init?.size ?? 3),
725
- cursor: this.createCursorOption(init),
726
- } as ContextListResult<DeploymentSchema>),
727
- init
728
- )
729
- await mock.add(
730
- {
731
- match: { uri: RouteBuilder.deploymentsApisByEnv(':oid', ':apiId'), methods: ['GET'] },
732
- respond,
733
- },
734
- options
735
- )
736
- },
737
-
738
- listForEnvironment: async (init?: MockListResult, options?: InterceptOptions): Promise<void> => {
739
- const { mock } = this
740
- const respond = this.createDefaultResponse(
741
- 200,
742
- { 'content-type': 'application/json' },
743
- () =>
744
- JSON.stringify({
745
- items: this.gen.deployments.deployments(init?.size ?? 5),
746
- cursor: this.createCursorOption(init),
747
- } as ContextListResult<DeploymentSchema>),
748
- init
749
- )
750
- await mock.add(
751
- {
752
- match: {
753
- uri: RouteBuilder.deploymentsApisForEnv(':oid', ':apiId', ':env' as unknown as DeploymentEnvironment),
754
- methods: ['GET'],
755
- },
756
- respond,
757
- },
758
- options
759
- )
760
- },
761
- },
762
- },
763
586
  }
764
587
 
765
588
  /**
@@ -772,20 +595,12 @@ export class SdkMock {
772
595
  */
773
596
  list: async (init?: MockListResult, options?: InterceptOptions): Promise<void> => {
774
597
  const { mock } = this
775
- // const respond = init?.response ?? {
776
- // status: 200,
777
- // headers: { 'content-type': 'application/json' },
778
- // body: JSON.stringify({
779
- // items: this.gen.group.groups(init?.size ?? 5),
780
- // cursor: this.createCursorOption(init),
781
- // } as ContextListResult<GroupSchema>),
782
- // }
783
598
  const respond = this.createDefaultResponse(
784
599
  200,
785
600
  { 'content-type': 'application/json' },
786
601
  () => {
787
602
  const obj: ContextListResult<GroupSchema> = {
788
- items: this.gen.group.groups(init?.size ?? 5),
603
+ data: this.gen.group.groups(init?.size ?? 5),
789
604
  cursor: this.createCursorOption(init),
790
605
  }
791
606
  return JSON.stringify(obj)
@@ -950,7 +765,7 @@ export class SdkMock {
950
765
  { 'content-type': 'application/json' },
951
766
  () => {
952
767
  const obj: ContextListResult<AiSessionSchema> = {
953
- items: this.gen.ai.sessions('general', init?.size ?? 5),
768
+ data: this.gen.ai.sessions('general', init?.size ?? 5),
954
769
  cursor: this.createCursorOption(init),
955
770
  }
956
771
  return JSON.stringify(obj)
@@ -1049,7 +864,7 @@ export class SdkMock {
1049
864
  { 'content-type': 'application/json' },
1050
865
  () => {
1051
866
  const obj: ContextListResult<AiMessageSchema> = {
1052
- items: this.gen.ai.messages(init?.size ?? 5),
867
+ data: this.gen.ai.messages(init?.size ?? 5),
1053
868
  cursor: this.createCursorOption(init),
1054
869
  }
1055
870
  return JSON.stringify(obj)
@@ -1167,20 +982,12 @@ export class SdkMock {
1167
982
  */
1168
983
  list: async (init?: MockListResult, options?: InterceptOptions): Promise<void> => {
1169
984
  const { mock } = this
1170
- // const respond = init?.response ?? {
1171
- // status: 200,
1172
- // headers: { 'content-type': 'application/json' },
1173
- // body: JSON.stringify({
1174
- // items: this.gen.files.files(init?.size ?? 5),
1175
- // cursor: this.createCursorOption(init),
1176
- // } as ContextListResult<FileSchema>),
1177
- // }
1178
985
  const respond = this.createDefaultResponse(
1179
986
  200,
1180
987
  { 'content-type': 'application/json' },
1181
988
  () => {
1182
989
  const obj: ContextListResult<FileSchema> = {
1183
- items: this.gen.files.files(init?.size ?? 5),
990
+ data: this.gen.files.files(init?.size ?? 5),
1184
991
  cursor: this.createCursorOption(init),
1185
992
  }
1186
993
  return JSON.stringify(obj)
@@ -1354,19 +1161,12 @@ export class SdkMock {
1354
1161
  */
1355
1162
  readBulk: async (init?: MockListResult, options?: InterceptOptions): Promise<void> => {
1356
1163
  const { mock } = this
1357
- // const respond = init?.response ?? {
1358
- // status: 200,
1359
- // headers: { 'content-type': 'application/json' },
1360
- // body: JSON.stringify({
1361
- // items: this.gen.files.files(init?.size ?? 5),
1362
- // } as IBulkOperationResult<FileSchema>),
1363
- // }
1364
1164
  const respond = this.createDefaultResponse(
1365
1165
  200,
1366
1166
  { 'content-type': 'application/json' },
1367
1167
  () => {
1368
1168
  const obj: IBulkOperationResult<FileSchema> = {
1369
- items: this.gen.files.files(init?.size ?? 5),
1169
+ data: this.gen.files.files(init?.size ?? 5),
1370
1170
  }
1371
1171
  return JSON.stringify(obj)
1372
1172
  },
@@ -1529,20 +1329,12 @@ export class SdkMock {
1529
1329
  */
1530
1330
  listUsers: async (init?: MockListResult, options?: InterceptOptions): Promise<void> => {
1531
1331
  const { mock } = this
1532
- // const respond = init?.response ?? {
1533
- // status: 200,
1534
- // headers: { 'content-type': 'application/json' },
1535
- // body: JSON.stringify({
1536
- // items: this.gen.users.users(init?.size ?? 5),
1537
- // cursor: this.createCursorOption(init),
1538
- // } as ContextListResult<UserSchema>),
1539
- // }
1540
1332
  const respond = this.createDefaultResponse(
1541
1333
  200,
1542
1334
  { 'content-type': 'application/json' },
1543
1335
  () => {
1544
1336
  const obj: ContextListResult<UserSchema> = {
1545
- items: this.gen.users.users(init?.size ?? 5),
1337
+ data: this.gen.users.users(init?.size ?? 5),
1546
1338
  cursor: this.createCursorOption(init),
1547
1339
  }
1548
1340
  return JSON.stringify(obj)
@@ -1566,20 +1358,12 @@ export class SdkMock {
1566
1358
  */
1567
1359
  breadcrumbs: async (init?: MockListResult, options?: InterceptOptions): Promise<void> => {
1568
1360
  const { mock } = this
1569
- // const respond = init?.response ?? {
1570
- // status: 200,
1571
- // headers: { 'content-type': 'application/json' },
1572
- // body: JSON.stringify({
1573
- // items: this.gen.files.fileBreadcrumbs(init?.size ?? 5),
1574
- // cursor: this.createCursorOption(init),
1575
- // } as ContextListResult<FileBreadcrumb>),
1576
- // }
1577
1361
  const respond = this.createDefaultResponse(
1578
1362
  200,
1579
1363
  { 'content-type': 'application/json' },
1580
1364
  () => {
1581
1365
  const obj: ContextListResult<FileBreadcrumb> = {
1582
- items: this.gen.files.fileBreadcrumbs(init?.size ?? 5),
1366
+ data: this.gen.files.fileBreadcrumbs(init?.size ?? 5),
1583
1367
  cursor: this.createCursorOption(init),
1584
1368
  }
1585
1369
  return JSON.stringify(obj)
@@ -1610,20 +1394,12 @@ export class SdkMock {
1610
1394
  shared = {
1611
1395
  list: async (init?: MockListResult, options?: InterceptOptions): Promise<void> => {
1612
1396
  const { mock } = this
1613
- // const respond = init?.response ?? {
1614
- // status: 200,
1615
- // headers: { 'content-type': 'application/json' },
1616
- // body: JSON.stringify({
1617
- // items: this.gen.files.files(init?.size ?? 5),
1618
- // cursor: this.createCursorOption(init),
1619
- // } as ContextListResult<FileSchema>),
1620
- // }
1621
1397
  const respond = this.createDefaultResponse(
1622
1398
  200,
1623
1399
  { 'content-type': 'application/json' },
1624
1400
  () => {
1625
1401
  const obj: ContextListResult<FileSchema> = {
1626
- items: this.gen.files.files(init?.size ?? 5),
1402
+ data: this.gen.files.files(init?.size ?? 5),
1627
1403
  cursor: this.createCursorOption(init),
1628
1404
  }
1629
1405
  return JSON.stringify(obj)
@@ -1649,20 +1425,12 @@ export class SdkMock {
1649
1425
  trash = {
1650
1426
  list: async (init?: MockListResult, options?: InterceptOptions): Promise<void> => {
1651
1427
  const { mock } = this
1652
- // const respond = init?.response ?? {
1653
- // status: 200,
1654
- // headers: { 'content-type': 'application/json' },
1655
- // body: JSON.stringify({
1656
- // items: this.gen.trash.trashEntries(init?.size ?? 5),
1657
- // cursor: this.createCursorOption(init),
1658
- // } as ContextListResult<TrashEntry>),
1659
- // }
1660
1428
  const respond = this.createDefaultResponse(
1661
1429
  200,
1662
1430
  { 'content-type': 'application/json' },
1663
1431
  () => {
1664
1432
  const obj: ContextListResult<TrashEntry> = {
1665
- items: this.gen.trash.trashEntries(init?.size ?? 5),
1433
+ data: this.gen.trash.trashEntries(init?.size ?? 5),
1666
1434
  cursor: this.createCursorOption(init),
1667
1435
  }
1668
1436
  return JSON.stringify(obj)
@@ -1742,9 +1510,58 @@ export class SdkMock {
1742
1510
  const respond = this.createDefaultResponse(
1743
1511
  200,
1744
1512
  { 'content-type': 'application/json' },
1745
- () => {
1513
+ (req: SerializedRequest) => {
1514
+ const { query } = req
1515
+ const filter = this.decodeFilter(query.filter)
1516
+ const schema: Partial<DeploymentSchema> = {}
1517
+ if (isAtomicFilter(filter)) {
1518
+ if (['apiId', 'api_id'].includes(filter.field)) {
1519
+ if (filter.operator === 'eq') {
1520
+ schema.apiId = filter.value as string
1521
+ }
1522
+ }
1523
+ if (['apiSlug', 'api_slug'].includes(filter.field)) {
1524
+ if (filter.operator === 'eq') {
1525
+ schema.apiSlug = filter.value as string
1526
+ }
1527
+ }
1528
+ if (['orgId', 'organization'].includes(filter.field)) {
1529
+ if (filter.operator === 'eq') {
1530
+ schema.orgId = filter.value as string
1531
+ }
1532
+ }
1533
+ if (['modelVersion', 'model_version'].includes(filter.field)) {
1534
+ if (filter.operator === 'eq') {
1535
+ schema.modelVersion = filter.value as string
1536
+ }
1537
+ }
1538
+ if (filter.field === 'version') {
1539
+ if (filter.operator === 'eq') {
1540
+ schema.version = filter.value as string
1541
+ }
1542
+ }
1543
+ if (filter.field === 'env') {
1544
+ if (filter.operator === 'eq') {
1545
+ schema.env = filter.value as DeploymentEnvironment
1546
+ }
1547
+ }
1548
+ }
1549
+ const limit = this.readQueryLimit(req, init)
1550
+ const data = this.gen.deployments.deployments(limit, schema)
1551
+ const { order = 'asc', sort } = req.query
1552
+ if (sort) {
1553
+ data.sort((a, b) => {
1554
+ const aValue = a[sort as keyof DeploymentSchema] ?? 0
1555
+ const bValue = b[sort as keyof DeploymentSchema] ?? 0
1556
+ if (order === 'asc') {
1557
+ return aValue < bValue ? -1 : aValue > bValue ? 1 : 0
1558
+ } else {
1559
+ return aValue > bValue ? -1 : aValue < bValue ? 1 : 0
1560
+ }
1561
+ })
1562
+ }
1746
1563
  const obj: ContextListResult<DeploymentSchema> = {
1747
- items: this.gen.deployments.deployments(init?.size ?? 5),
1564
+ data,
1748
1565
  cursor: this.createCursorOption(init),
1749
1566
  }
1750
1567
  return JSON.stringify(obj)
@@ -1832,15 +1649,30 @@ export class SdkMock {
1832
1649
  )
1833
1650
  },
1834
1651
  apis: {
1835
- listAllForApi: async (init?: MockListResult, options?: InterceptOptions): Promise<void> => {
1652
+ getLatestPerEnvironment: async (
1653
+ init?: MockResult & { prod?: boolean; stage?: boolean; dev?: boolean },
1654
+ options?: InterceptOptions
1655
+ ): Promise<void> => {
1836
1656
  const { mock } = this
1837
1657
  const respond = this.createDefaultResponse(
1838
1658
  200,
1839
1659
  { 'content-type': 'application/json' },
1840
1660
  () => {
1841
- const obj: ContextListResult<DeploymentSchema> = {
1842
- items: this.gen.deployments.deployments(init?.size ?? 5),
1843
- cursor: this.createCursorOption(init),
1661
+ const obj: DeploymentLatestEnvironmentsResponse = {
1662
+ data: {},
1663
+ }
1664
+ const hasProd = init?.prod ?? this.gen.faker.datatype.boolean()
1665
+ const hasStage = init?.stage ?? this.gen.faker.datatype.boolean()
1666
+ const hasDev = init?.dev ?? this.gen.faker.datatype.boolean()
1667
+
1668
+ if (hasProd) {
1669
+ obj.data.prod = this.gen.deployments.deployment()
1670
+ }
1671
+ if (hasStage) {
1672
+ obj.data.stage = this.gen.deployments.deployment()
1673
+ }
1674
+ if (hasDev) {
1675
+ obj.data.dev = this.gen.deployments.deployment()
1844
1676
  }
1845
1677
  return JSON.stringify(obj)
1846
1678
  },
@@ -1849,7 +1681,7 @@ export class SdkMock {
1849
1681
  await mock.add(
1850
1682
  {
1851
1683
  match: {
1852
- uri: RouteBuilder.deploymentsApisByEnv(':oid', ':apiId'),
1684
+ uri: RouteBuilder.deploymentsApisByEnvLatest(':oid', ':fileId'),
1853
1685
  methods: ['GET'],
1854
1686
  },
1855
1687
  respond,
@@ -1857,15 +1689,14 @@ export class SdkMock {
1857
1689
  options
1858
1690
  )
1859
1691
  },
1860
- listAllForEnv: async (init?: MockListResult, options?: InterceptOptions): Promise<void> => {
1692
+ list: async (init?: MockListResult, options?: InterceptOptions): Promise<void> => {
1861
1693
  const { mock } = this
1862
1694
  const respond = this.createDefaultResponse(
1863
1695
  200,
1864
1696
  { 'content-type': 'application/json' },
1865
1697
  () => {
1866
- const obj: ContextListResult<DeploymentSchema> = {
1867
- items: this.gen.deployments.deployments(init?.size ?? 5),
1868
- cursor: this.createCursorOption(init),
1698
+ const obj: ContextListResult<DeploymentApi> = {
1699
+ data: this.gen.deployments.deploymentApis(init?.size ?? 5),
1869
1700
  }
1870
1701
  return JSON.stringify(obj)
1871
1702
  },
@@ -1874,7 +1705,7 @@ export class SdkMock {
1874
1705
  await mock.add(
1875
1706
  {
1876
1707
  match: {
1877
- uri: RouteBuilder.deploymentsApisForEnv(':oid', ':apiId', ':env' as unknown as DeploymentEnvironment),
1708
+ uri: RouteBuilder.deploymentsApis(':oid'),
1878
1709
  methods: ['GET'],
1879
1710
  },
1880
1711
  respond,
@@ -1896,7 +1727,7 @@ export class SdkMock {
1896
1727
  { 'content-type': 'application/json' },
1897
1728
  () => {
1898
1729
  const obj: ContextListResult<DataCatalogSchemaWithVersion> = {
1899
- items: this.gen.dataCatalog.dataCatalogsWithVersion(init?.size ?? 5),
1730
+ data: this.gen.dataCatalog.dataCatalogsWithVersion(init?.size ?? 5),
1900
1731
  cursor: this.createCursorOption(init),
1901
1732
  }
1902
1733
  return JSON.stringify(obj)
@@ -1922,7 +1753,7 @@ export class SdkMock {
1922
1753
  { 'content-type': 'application/json' },
1923
1754
  () => {
1924
1755
  const obj: ContextListResult<DataCatalogVersionInfo> = {
1925
- items: this.gen.dataCatalog.versionInfos(init?.size ?? 5),
1756
+ data: this.gen.dataCatalog.versionInfos(init?.size ?? 5),
1926
1757
  cursor: this.createCursorOption(init),
1927
1758
  }
1928
1759
  return JSON.stringify(obj)
@@ -2108,16 +1939,16 @@ export class SdkMock {
2108
1939
  { 'content-type': 'application/json' },
2109
1940
  (req: SerializedRequest) => {
2110
1941
  const requirements = JSON.parse(req.body as string) as { items: ForeignDomainDependency[] }
2111
- const items: DataDomainSchema[] = []
1942
+ const data: DataDomainSchema[] = []
2112
1943
  for (const item of requirements.items) {
2113
1944
  const domain = new DataDomain({
2114
1945
  key: item.key,
2115
1946
  info: { name: `Domain ${item.key}`, version: item.version },
2116
1947
  })
2117
- items.push(domain.toJSON())
1948
+ data.push(domain.toJSON())
2118
1949
  }
2119
1950
  const obj: ContextListResult<DataDomainSchema> = {
2120
- items: items,
1951
+ data,
2121
1952
  }
2122
1953
  return JSON.stringify(obj)
2123
1954
  },
@@ -2222,4 +2053,80 @@ export class SdkMock {
2222
2053
  )
2223
2054
  },
2224
2055
  }
2056
+
2057
+ //
2058
+ // Helpers
2059
+ //
2060
+
2061
+ /**
2062
+ * Decodes the filter parameter from the query string.
2063
+ *
2064
+ * @param filter The filter parameter from the query string.
2065
+ * @returns The decoded filter or undefined if the filter is invalid.
2066
+ */
2067
+ decodeFilter(filter?: string | string[]): QueryFilter | undefined {
2068
+ if (typeof filter !== 'string' || !filter) {
2069
+ return undefined
2070
+ }
2071
+ try {
2072
+ return JSON.parse(atob(filter)) as QueryFilter
2073
+ } catch {
2074
+ return undefined
2075
+ }
2076
+ }
2077
+
2078
+ readQueryLimit(req: SerializedRequest, init?: MockListResult): number {
2079
+ let limit = init?.size ?? 5
2080
+ if (req.query?.limit) {
2081
+ const l = Array.isArray(req.query.limit) ? req.query.limit[0] : req.query.limit
2082
+ const tmp = parseInt(l, 10)
2083
+ if (Number.isInteger(tmp) && tmp > 0) {
2084
+ limit = tmp
2085
+ }
2086
+ }
2087
+ return limit
2088
+ }
2089
+
2090
+ protected createCursorOption(init: MockListResult = {}): string | undefined {
2091
+ if (init.cursor === false) {
2092
+ return undefined
2093
+ }
2094
+ const hasCursor = init.cursor === true ? true : this.gen.faker.datatype.boolean()
2095
+ if (!hasCursor) {
2096
+ return undefined
2097
+ }
2098
+ return this.gen.faker.internet.jwt()
2099
+ }
2100
+
2101
+ protected createDefaultResponse(
2102
+ status: number,
2103
+ headers?: Record<string, string>,
2104
+ body?: (req: SerializedRequest) => string,
2105
+ userConfig?: MockResult
2106
+ ): ResponseGenerator {
2107
+ let respond: ResponseGenerator
2108
+ if (userConfig?.response) {
2109
+ // user config takes precedence
2110
+ respond = userConfig.response
2111
+ } else {
2112
+ respond = {}
2113
+ }
2114
+ // Set defaults if not provided in user config
2115
+ if (!respond.status) {
2116
+ respond.status = status
2117
+ }
2118
+ // only set headers if the user didn't configure the response only.
2119
+ // The user may want to remove default headers.
2120
+ if (!userConfig || !userConfig.response) {
2121
+ respond.headers = headers
2122
+ }
2123
+ if (!respond.body && userConfig?.forceBody && body) {
2124
+ // when body is missing and forceBody is set, generate the body
2125
+ respond.body = (req: SerializedRequest) => body(req)
2126
+ } else if (body && (!userConfig || !userConfig.response)) {
2127
+ // we set the body by default when the user config is missing
2128
+ respond.body = (req: SerializedRequest) => body(req)
2129
+ }
2130
+ return respond
2131
+ }
2225
2132
  }
@@ -43,7 +43,7 @@ export class SharedSdk extends SdkBase {
43
43
  } catch {
44
44
  throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
45
45
  }
46
- if (!Array.isArray(data.items)) {
46
+ if (!Array.isArray(data.data)) {
47
47
  throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
48
48
  }
49
49
  return data