@api-client/core 0.19.18 → 0.19.20

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 (154) hide show
  1. package/build/src/authorization/Utils.js +3 -3
  2. package/build/src/authorization/Utils.js.map +1 -1
  3. package/build/src/browser.d.ts +1 -1
  4. package/build/src/browser.d.ts.map +1 -1
  5. package/build/src/browser.js.map +1 -1
  6. package/build/src/index.d.ts +1 -1
  7. package/build/src/index.d.ts.map +1 -1
  8. package/build/src/index.js.map +1 -1
  9. package/build/src/mocking/lib/Organization.d.ts +5 -1
  10. package/build/src/mocking/lib/Organization.d.ts.map +1 -1
  11. package/build/src/mocking/lib/Organization.js +17 -0
  12. package/build/src/mocking/lib/Organization.js.map +1 -1
  13. package/build/src/modeling/ApiModel.d.ts +16 -5
  14. package/build/src/modeling/ApiModel.d.ts.map +1 -1
  15. package/build/src/modeling/ApiModel.js +17 -2
  16. package/build/src/modeling/ApiModel.js.map +1 -1
  17. package/build/src/modeling/ApiValidation.d.ts.map +1 -1
  18. package/build/src/modeling/ApiValidation.js +2 -1
  19. package/build/src/modeling/ApiValidation.js.map +1 -1
  20. package/build/src/modeling/DomainProperty.d.ts +12 -0
  21. package/build/src/modeling/DomainProperty.d.ts.map +1 -1
  22. package/build/src/modeling/DomainProperty.js +23 -28
  23. package/build/src/modeling/DomainProperty.js.map +1 -1
  24. package/build/src/modeling/DomainSerialization.js +1 -1
  25. package/build/src/modeling/DomainSerialization.js.map +1 -1
  26. package/build/src/modeling/ExposedEntity.d.ts +15 -1
  27. package/build/src/modeling/ExposedEntity.d.ts.map +1 -1
  28. package/build/src/modeling/ExposedEntity.js +42 -4
  29. package/build/src/modeling/ExposedEntity.js.map +1 -1
  30. package/build/src/modeling/actions/Action.d.ts.map +1 -1
  31. package/build/src/modeling/actions/Action.js +1 -0
  32. package/build/src/modeling/actions/Action.js.map +1 -1
  33. package/build/src/modeling/actions/ListAction.d.ts +3 -17
  34. package/build/src/modeling/actions/ListAction.d.ts.map +1 -1
  35. package/build/src/modeling/actions/ListAction.js +18 -38
  36. package/build/src/modeling/actions/ListAction.js.map +1 -1
  37. package/build/src/modeling/actions/SearchAction.d.ts +4 -4
  38. package/build/src/modeling/actions/SearchAction.d.ts.map +1 -1
  39. package/build/src/modeling/actions/SearchAction.js +16 -13
  40. package/build/src/modeling/actions/SearchAction.js.map +1 -1
  41. package/build/src/modeling/generators/oas_312/OasGenerator.d.ts +32 -0
  42. package/build/src/modeling/generators/oas_312/OasGenerator.d.ts.map +1 -0
  43. package/build/src/modeling/generators/oas_312/OasGenerator.js +1452 -0
  44. package/build/src/modeling/generators/oas_312/OasGenerator.js.map +1 -0
  45. package/build/src/modeling/generators/oas_312/OasSchemaGenerator.d.ts +27 -0
  46. package/build/src/modeling/generators/oas_312/OasSchemaGenerator.d.ts.map +1 -0
  47. package/build/src/modeling/generators/oas_312/OasSchemaGenerator.js +295 -0
  48. package/build/src/modeling/generators/oas_312/OasSchemaGenerator.js.map +1 -0
  49. package/build/src/modeling/generators/oas_312/types.d.ts +1010 -0
  50. package/build/src/modeling/generators/oas_312/types.d.ts.map +1 -0
  51. package/build/src/modeling/generators/oas_312/types.js +2 -0
  52. package/build/src/modeling/generators/oas_312/types.js.map +1 -0
  53. package/build/src/modeling/generators/oas_320/OasGenerator.d.ts +16 -0
  54. package/build/src/modeling/generators/oas_320/OasGenerator.d.ts.map +1 -0
  55. package/build/src/modeling/generators/oas_320/OasGenerator.js +306 -0
  56. package/build/src/modeling/generators/oas_320/OasGenerator.js.map +1 -0
  57. package/build/src/modeling/generators/oas_320/OasSchemaGenerator.d.ts +25 -0
  58. package/build/src/modeling/generators/oas_320/OasSchemaGenerator.d.ts.map +1 -0
  59. package/build/src/modeling/generators/oas_320/OasSchemaGenerator.js +237 -0
  60. package/build/src/modeling/generators/oas_320/OasSchemaGenerator.js.map +1 -0
  61. package/build/src/modeling/generators/oas_320/types.d.ts +1219 -0
  62. package/build/src/modeling/generators/oas_320/types.d.ts.map +1 -0
  63. package/build/src/modeling/generators/oas_320/types.js +2 -0
  64. package/build/src/modeling/generators/oas_320/types.js.map +1 -0
  65. package/build/src/modeling/types.d.ts +50 -13
  66. package/build/src/modeling/types.d.ts.map +1 -1
  67. package/build/src/modeling/types.js.map +1 -1
  68. package/build/src/modeling/validation/api_model_rules.d.ts +1 -0
  69. package/build/src/modeling/validation/api_model_rules.d.ts.map +1 -1
  70. package/build/src/modeling/validation/api_model_rules.js +105 -29
  71. package/build/src/modeling/validation/api_model_rules.js.map +1 -1
  72. package/build/src/models/ProjectRequest.d.ts.map +1 -1
  73. package/build/src/models/ProjectRequest.js +0 -4
  74. package/build/src/models/ProjectRequest.js.map +1 -1
  75. package/build/src/models/store/Organization.d.ts +13 -0
  76. package/build/src/models/store/Organization.d.ts.map +1 -1
  77. package/build/src/models/store/Organization.js.map +1 -1
  78. package/build/src/models/transformers/ArcDexieTransformer.d.ts.map +1 -1
  79. package/build/src/models/transformers/ArcDexieTransformer.js +0 -4
  80. package/build/src/models/transformers/ArcDexieTransformer.js.map +1 -1
  81. package/build/src/models/transformers/ImportUtils.js +1 -1
  82. package/build/src/models/transformers/ImportUtils.js.map +1 -1
  83. package/build/src/models/transformers/PostmanBackupTransformer.d.ts.map +1 -1
  84. package/build/src/models/transformers/PostmanBackupTransformer.js +0 -4
  85. package/build/src/models/transformers/PostmanBackupTransformer.js.map +1 -1
  86. package/build/src/runtime/constants.d.ts +7 -0
  87. package/build/src/runtime/constants.d.ts.map +1 -0
  88. package/build/src/runtime/constants.js +8 -0
  89. package/build/src/runtime/constants.js.map +1 -0
  90. package/build/src/runtime/http-engine/ntlm/Des.d.ts.map +1 -1
  91. package/build/src/runtime/http-engine/ntlm/Des.js +1 -0
  92. package/build/src/runtime/http-engine/ntlm/Des.js.map +1 -1
  93. package/build/src/runtime/variables/EvalFunctions.d.ts.map +1 -1
  94. package/build/src/runtime/variables/EvalFunctions.js +0 -1
  95. package/build/src/runtime/variables/EvalFunctions.js.map +1 -1
  96. package/build/src/sdk/OrganizationsSdk.d.ts +17 -1
  97. package/build/src/sdk/OrganizationsSdk.d.ts.map +1 -1
  98. package/build/src/sdk/OrganizationsSdk.js +76 -0
  99. package/build/src/sdk/OrganizationsSdk.js.map +1 -1
  100. package/build/src/sdk/RouteBuilder.d.ts +2 -0
  101. package/build/src/sdk/RouteBuilder.d.ts.map +1 -1
  102. package/build/src/sdk/RouteBuilder.js +6 -0
  103. package/build/src/sdk/RouteBuilder.js.map +1 -1
  104. package/build/src/sdk/SdkMock.d.ts +12 -0
  105. package/build/src/sdk/SdkMock.d.ts.map +1 -1
  106. package/build/src/sdk/SdkMock.js +32 -0
  107. package/build/src/sdk/SdkMock.js.map +1 -1
  108. package/build/tsconfig.tsbuildinfo +1 -1
  109. package/eslint.config.js +6 -0
  110. package/package.json +3 -1
  111. package/src/authorization/Utils.ts +3 -3
  112. package/src/mocking/lib/Organization.ts +22 -1
  113. package/src/modeling/ApiModel.ts +23 -8
  114. package/src/modeling/ApiValidation.ts +2 -0
  115. package/src/modeling/DomainProperty.ts +22 -18
  116. package/src/modeling/DomainSerialization.ts +1 -1
  117. package/src/modeling/ExposedEntity.ts +44 -4
  118. package/src/modeling/actions/Action.ts +1 -0
  119. package/src/modeling/actions/ListAction.ts +12 -30
  120. package/src/modeling/actions/SearchAction.ts +11 -8
  121. package/src/modeling/generators/oas_312/OasGenerator.ts +1685 -0
  122. package/src/modeling/generators/oas_312/OasSchemaGenerator.ts +322 -0
  123. package/src/modeling/generators/oas_312/types.ts +1052 -0
  124. package/src/modeling/generators/oas_320/OasGenerator.ts +359 -0
  125. package/src/modeling/generators/oas_320/OasSchemaGenerator.ts +255 -0
  126. package/src/modeling/generators/oas_320/types.ts +1259 -0
  127. package/src/modeling/types.ts +55 -22
  128. package/src/modeling/validation/api_model_rules.ts +103 -32
  129. package/src/models/ProjectRequest.ts +0 -4
  130. package/src/models/store/Organization.ts +14 -0
  131. package/src/models/transformers/ArcDexieTransformer.ts +0 -4
  132. package/src/models/transformers/ImportUtils.ts +1 -1
  133. package/src/models/transformers/PostmanBackupTransformer.ts +0 -5
  134. package/src/runtime/constants.ts +9 -0
  135. package/src/runtime/http-engine/ntlm/Des.ts +1 -0
  136. package/src/runtime/variables/EvalFunctions.ts +0 -1
  137. package/src/sdk/OrganizationsSdk.ts +81 -1
  138. package/src/sdk/RouteBuilder.ts +8 -0
  139. package/src/sdk/SdkMock.ts +50 -0
  140. package/tests/test-utils.ts +6 -2
  141. package/tests/unit/decorators/observed.spec.ts +8 -24
  142. package/tests/unit/decorators/observed_recursive.spec.ts +0 -1
  143. package/tests/unit/events/EventsTestHelpers.ts +0 -1
  144. package/tests/unit/events/events_polyfills.ts +0 -1
  145. package/tests/unit/legacy-transformers/DataTestHelper.ts +0 -2
  146. package/tests/unit/legacy-transformers/LegacyExportProcessor.spec.ts +0 -1
  147. package/tests/unit/modeling/actions/ListAction.spec.ts +9 -69
  148. package/tests/unit/modeling/actions/SearchAction.spec.ts +9 -35
  149. package/tests/unit/modeling/api_model.spec.ts +28 -0
  150. package/tests/unit/modeling/definitions/sku.spec.ts +0 -2
  151. package/tests/unit/modeling/domain_property.spec.ts +20 -1
  152. package/tests/unit/modeling/exposed_entity.spec.ts +71 -0
  153. package/tests/unit/modeling/generators/OasGenerator.spec.ts +302 -0
  154. package/tests/unit/modeling/validation/api_model_rules.spec.ts +113 -15
@@ -223,41 +223,35 @@ export interface ProblemDetails {
223
223
  }
224
224
 
225
225
  /**
226
- * The set of supported filter operators for the List action.
226
+ * The set of supported filter operators for the List and search action.
227
227
  * These are used in query parameters, e.g., ?price[gte]=100
228
228
  *
229
229
  * - eq: Equal
230
- * - nq: Not Equal
230
+ * - neq: Not Equal
231
+ * - in: Value is one of the elements in the provided array
232
+ * - nin: Value is not one of the elements in the provided array
231
233
  * - lt: Less Than
232
234
  * - lte: Less Than or Equal
233
235
  * - gt: Greater Than
234
236
  * - gte: Greater Than or Equal
235
- * - ex: Checks if the field exists
236
- * - re: Regular expression match
237
- * - bf: Date before a specific value
238
- * - af: Date after a specific value
239
- * - cn: String contains substring / Array contains element
240
- * - st: String starts with
241
- * - end: String ends with
242
- * - in: Value is one of the elements in the provided array
243
- * - nin: Value is not one of the elements in the provided array
237
+ * - exists: Checks if the field exists
238
+ *
239
+ * Search filters only:
240
+ * - contains: String contains substring / Array contains element (Substring Match)
241
+ * - match: Lexical Match, multi-word queries against long text.
244
242
  */
245
243
  export type ResourceFilterOperator =
246
244
  | 'eq' // Equal
247
- | 'nq' // Not equal
245
+ | 'neq' // Not equal
246
+ | 'in' // Value is one of the elements in the provided array
247
+ | 'nin' // Value is not one of the elements in the provided array
248
248
  | 'lt' // Less than
249
249
  | 'lte' // Less than or equal
250
250
  | 'gt' // Greater than
251
251
  | 'gte' // Greater than or equal
252
- | 'ex' // Checks if the field exists
253
- | 're' // Regular expression match
254
- | 'bf' // Date before a specific value
255
- | 'af' // Date after a specific value
256
- | 'cn' // String contains substring / Array contains element
257
- | 'st' // String starts with
258
- | 'end' // String ends with
259
- | 'in' // Value is one of the elements in the provided array
260
- | 'nin' // Value is not one of the elements in the provided array
252
+ | 'exists' // Checks if the field exists
253
+ | 'contains' // String contains substring / Array contains element (Substring Match)
254
+ | 'match' // Lexical Match, multi-word queries against long text.
261
255
 
262
256
  /**
263
257
  * The session transport configuration interface.
@@ -384,6 +378,8 @@ export interface RolesBasedAccessControl extends AuthorizationConfiguration {
384
378
  roleKey: string
385
379
  }
386
380
 
381
+ export type AuthorizationStrategy = RolesBasedAccessControl
382
+
387
383
  /**
388
384
  * Configures the strategy for authenticating end-users.
389
385
  * An API can only support one authentication strategy at a time.
@@ -412,6 +408,8 @@ export interface UsernamePasswordConfiguration extends AuthenticationConfigurati
412
408
  passwordKey?: string
413
409
  }
414
410
 
411
+ export type AuthenticationStrategy = UsernamePasswordConfiguration
412
+
415
413
  /**
416
414
  * Represents a Data Entity from the Data Domain that the API will expose and operate upon.
417
415
  */
@@ -492,6 +490,10 @@ export interface ExposedEntitySchema {
492
490
  * When true, generation for this exposure hit configured limits
493
491
  */
494
492
  truncated?: boolean
493
+ /**
494
+ * Pagination contract for this exposure.
495
+ */
496
+ paginationContract?: PaginationContract
495
497
  }
496
498
 
497
499
  /**
@@ -542,7 +544,13 @@ export interface PaginationStrategy {
542
544
  * The default page size for the pagination strategy.
543
545
  * This is the number of items returned per page when no specific page size is requested.
544
546
  */
545
- pageSize?: number
547
+ defaultLimit?: number
548
+ /**
549
+ * The maximum page size for the pagination strategy.
550
+ * This is the maximum number of items that can be returned per page.
551
+ * The API runtime defined the upper limit to prevent abuse.
552
+ */
553
+ maxLimit?: number
546
554
  }
547
555
 
548
556
  /**
@@ -559,6 +567,31 @@ export interface OffsetPaginationStrategy extends PaginationStrategy {
559
567
  kind: 'offset'
560
568
  }
561
569
 
570
+ /**
571
+ * Represents the contract for pagination. Defines which fields can be used for filtering, sorting,
572
+ * and searching.
573
+ */
574
+ export interface PaginationContract {
575
+ /**
576
+ * The list of fields (property keys) that can be used for filtering.
577
+ */
578
+ filterableFields: string[]
579
+ /**
580
+ * The list of fields (property keys) that can be used for sorting.
581
+ */
582
+ sortableFields: string[]
583
+ /**
584
+ * The list of fields (property keys) that can be used for searching.
585
+ * Note that these properties must be of type string or array of strings.
586
+ */
587
+ searchableFields: string[]
588
+ /**
589
+ * The default sort order for the pagination strategy.
590
+ * This is the sort order that will be used when no sort order is specified.
591
+ */
592
+ defaultSort?: { field: string; direction: 'asc' | 'desc' }[]
593
+ }
594
+
562
595
  export type DomainImpactKinds =
563
596
  | typeof DomainNamespaceKind
564
597
  | typeof DomainEntityKind
@@ -348,49 +348,62 @@ export function validateApiModelMetadata(model: ApiModel): ApiModelValidationIte
348
348
  return issues
349
349
  }
350
350
 
351
- export function validateAction(action: Action, parent: ExposedEntity, apiModelKey: string): ApiModelValidationItem[] {
351
+ export function validateApiPagination(model: ApiModel): ApiModelValidationItem[] {
352
352
  const issues: ApiModelValidationItem[] = []
353
353
  const context: ApiModelValidationContext = {
354
- apiModelKey,
355
- kind: 'Action',
356
- key: action.kind, // Actions lack nanoids, kind represents its type
357
- parentExposedEntityKey: parent.key,
354
+ apiModelKey: model.key,
355
+ kind: ApiModelKind,
356
+ key: model.key,
358
357
  }
359
-
360
- if (ListAction.isListAction(action)) {
361
- if (!action.pagination || !action.pagination.kind) {
358
+ // We only need pagination when the API contains at least one List or Search action
359
+ let validate = false
360
+ for (const exposure of model.exposes.values()) {
361
+ if (exposure.actions.some((action) => ListAction.isListAction(action) || SearchAction.isSearchAction(action))) {
362
+ validate = true
363
+ break
364
+ }
365
+ }
366
+ if (!validate) {
367
+ return issues
368
+ }
369
+ if (!model.pagination || !model.pagination.kind) {
370
+ issues.push({
371
+ code: createCode('API', 'MISSING_PAGINATION'),
372
+ message: 'The API must have a defined pagination strategy when it exposes List or Search actions.',
373
+ suggestion: 'Configure how results are loaded (e.g. by page or by a continuous cursor).',
374
+ severity: 'error',
375
+ context: { ...context, property: 'pagination' },
376
+ })
377
+ } else {
378
+ if (model.pagination.defaultLimit === undefined) {
362
379
  issues.push({
363
- code: createCode('ACTION', 'LIST_MISSING_PAGINATION'),
364
- message: 'A List action must have a defined pagination strategy.',
365
- suggestion: 'Configure how results are loaded (e.g. by page or by a continuous cursor).',
366
- severity: 'error',
367
- context: { ...context, property: 'pagination' },
380
+ code: createCode('API', 'MISSING_PAGINATION_DEFAULT_LIMIT'),
381
+ message: "The API doesn't have a defined default page limit when it exposes List or Search actions.",
382
+ suggestion: 'Set a default page limit for the pagination otherwise the API will use its default limit.',
383
+ severity: 'info',
384
+ context: { ...context, property: 'pagination.defaultLimit' },
368
385
  })
369
386
  }
370
- if (
371
- (!action.filterableFields || action.filterableFields.length === 0) &&
372
- (!action.sortableFields || action.sortableFields.length === 0)
373
- ) {
387
+ if (model.pagination.maxLimit === undefined) {
374
388
  issues.push({
375
- code: createCode('ACTION', 'LIST_MISSING_FILTERS'),
376
- message: 'Listing all elements without filters or sorting could be overwhelming for large tables.',
377
- suggestion: 'Select a few important fields to allow sorting and searching by.',
378
- severity: 'warning',
379
- context,
389
+ code: createCode('API', 'MISSING_PAGINATION_MAX_LIMIT'),
390
+ message: "The API doesn't have a defined page size max limit when it exposes List or Search actions.",
391
+ suggestion: 'Set a max page size limit for the pagination otherwise the API will use its default max limit.',
392
+ severity: 'info',
393
+ context: { ...context, property: 'pagination.maxLimit' },
380
394
  })
381
395
  }
382
396
  }
397
+ return issues
398
+ }
383
399
 
384
- if (SearchAction.isSearchAction(action)) {
385
- if (!action.fields || action.fields.length === 0) {
386
- issues.push({
387
- code: createCode('ACTION', 'SEARCH_MISSING_FIELDS'),
388
- message: 'A Search action needs to know which fields to look in.',
389
- suggestion: 'Select the properties (like names or emails) that the search will run on.',
390
- severity: 'error',
391
- context: { ...context, property: 'fields' },
392
- })
393
- }
400
+ export function validateAction(action: Action, parent: ExposedEntity, apiModelKey: string): ApiModelValidationItem[] {
401
+ const issues: ApiModelValidationItem[] = []
402
+ const context: ApiModelValidationContext = {
403
+ apiModelKey,
404
+ kind: 'Action',
405
+ key: action.kind, // Actions lack nanoids, kind represents its type
406
+ parentExposedEntityKey: parent.key,
394
407
  }
395
408
 
396
409
  if (DeleteAction.isDeleteAction(action)) {
@@ -573,9 +586,14 @@ export function validateExposedEntity(entity: ExposedEntity, apiModel: ApiModel)
573
586
  context: { ...context, property: 'actions' },
574
587
  })
575
588
  } else {
589
+ let hasSearch = false
590
+ let hasList = false
576
591
  for (const action of entity.actions) {
577
592
  issues.push(...validateAction(action, entity, apiModel.key))
578
593
 
594
+ if (SearchAction.isSearchAction(action)) hasSearch = true
595
+ if (ListAction.isListAction(action)) hasList = true
596
+
579
597
  // Check inheritance of access rules
580
598
  // For a rule to exist, it might be on the action, the exposure, any parent, or the apiModel.
581
599
  let hasAuth = false
@@ -605,6 +623,59 @@ export function validateExposedEntity(entity: ExposedEntity, apiModel: ApiModel)
605
623
  })
606
624
  }
607
625
  }
626
+
627
+ if (hasList || hasSearch) {
628
+ const contract = entity.paginationContract
629
+ if (!contract) {
630
+ issues.push({
631
+ code: createCode('EXPOSURE', 'MISSING_PAGINATION_CONTRACT'),
632
+ message: 'The List or Search action needs a pagination contract.',
633
+ suggestion: 'Add a pagination contract to the exposed entity.',
634
+ severity: 'error',
635
+ context,
636
+ })
637
+ } else {
638
+ if (hasList) {
639
+ if (!contract.filterableFields || contract.filterableFields.length === 0) {
640
+ issues.push({
641
+ code: createCode('EXPOSURE', 'LIST_MISSING_FILTERS'),
642
+ message: 'Listing all elements without filters could be overwhelming for large tables.',
643
+ suggestion: 'Select a few important fields to allow filtering.',
644
+ severity: 'warning',
645
+ context,
646
+ })
647
+ }
648
+ if (!contract.sortableFields || contract.sortableFields.length === 0) {
649
+ issues.push({
650
+ code: createCode('EXPOSURE', 'LIST_MISSING_SORTING'),
651
+ message: 'Listing all elements without sorting could be overwhelming for large tables.',
652
+ suggestion: 'Select a few important fields to allow sorting.',
653
+ severity: 'warning',
654
+ context,
655
+ })
656
+ }
657
+ }
658
+ if (hasSearch) {
659
+ // Search and technically be used for filtering.
660
+ const all: string[] = []
661
+ if (Array.isArray(contract.searchableFields)) {
662
+ all.push(...contract.searchableFields)
663
+ }
664
+ if (Array.isArray(contract.filterableFields)) {
665
+ all.push(...contract.filterableFields)
666
+ }
667
+ if (!all.length) {
668
+ issues.push({
669
+ code: createCode('EXPOSURE', 'SEARCH_MISSING_FIELDS'),
670
+ message: 'Search action needs to know which fields to look in.',
671
+ suggestion: 'Select a few important fields to allow searching or full-text search.',
672
+ severity: 'warning',
673
+ context,
674
+ })
675
+ }
676
+ }
677
+ }
678
+ }
608
679
  }
609
680
 
610
681
  return issues
@@ -315,10 +315,6 @@ export class ProjectRequest extends Request implements ProjectDefinitionProperty
315
315
  if (!environment) {
316
316
  return undefined
317
317
  }
318
- let parent = this.getParent()
319
- if (parent === project) {
320
- parent = undefined
321
- }
322
318
  return project.findEnvironment(environment)
323
319
  }
324
320
 
@@ -4,6 +4,20 @@ import { OrganizationKind } from '../kinds.js'
4
4
 
5
5
  export type UserOrganizationGrantType = 'owner' | 'manager' | 'editor' | 'viewer'
6
6
 
7
+ /**
8
+ * The response of the organization slug validation.
9
+ */
10
+ export interface OrganizationSlugValidateResponse {
11
+ /**
12
+ * Whether the slug is valid.
13
+ */
14
+ valid: boolean
15
+ /**
16
+ * The reason why the slug is invalid.
17
+ */
18
+ reason?: string
19
+ }
20
+
7
21
  /**
8
22
  * In the system the user identity represents registration information associated with a specific identity provider.
9
23
  * This association allows the user to use different identity providers that map to the same user, as long as the
@@ -235,10 +235,6 @@ export class ArcDexieTransformer extends BaseTransformer {
235
235
 
236
236
  parseSavedItem(item: DexieRequest): RequestProcessItem {
237
237
  const requestName = item.name || item._name
238
- let keyName = requestName
239
- if (keyName && keyName[0] === '_') {
240
- keyName = keyName.substr(1)
241
- }
242
238
  const obj: ExportArcSavedRequest = {
243
239
  name: requestName || '',
244
240
  method: item.method,
@@ -118,7 +118,7 @@ export function prepareImportObject(data: Record<string, unknown> | string): unk
118
118
  data = JSON.parse(data)
119
119
  } catch (e) {
120
120
  const err = e as Error
121
- throw new Error(`Unable to read the file. Not a JSON: ${err.message}`)
121
+ throw new Error(`Unable to read the file. Not a JSON: ${err.message}`, { cause: e })
122
122
  }
123
123
  }
124
124
  return data
@@ -213,11 +213,6 @@ export class PostmanBackupTransformer extends PostmanTransformer {
213
213
  let headers = request.headers || ''
214
214
  headers = this.ensureVariablesSyntax(headers) as string
215
215
 
216
- let createdTime = Number(request.time)
217
- if (Number.isNaN(createdTime)) {
218
- createdTime = Date.now()
219
- }
220
-
221
216
  const created = current.addRequest(url)
222
217
  created.info.name = name
223
218
  if (request.description) {
@@ -0,0 +1,9 @@
1
+ // This is shared in the web and node.
2
+
3
+ export const OFFSET_PAGINATION_DEFAULT_LIMIT = 20
4
+ export const OFFSET_PAGINATION_MAX_LIMIT = 100
5
+ export const OFFSET_PAGINATION_MIN_LIMIT = 1
6
+
7
+ export const CURSOR_PAGINATION_DEFAULT_LIMIT = 20
8
+ export const CURSOR_PAGINATION_MAX_LIMIT = 100
9
+ export const CURSOR_PAGINATION_MIN_LIMIT = 1
@@ -128,6 +128,7 @@ export class Des {
128
128
  cbcleft =
129
129
  (iv!.charCodeAt(m++) << 24) | (iv!.charCodeAt(m++) << 16) | (iv!.charCodeAt(m++) << 8) | iv!.charCodeAt(m++)
130
130
  cbcright =
131
+ // eslint-disable-next-line no-useless-assignment
131
132
  (iv!.charCodeAt(m++) << 24) | (iv!.charCodeAt(m++) << 16) | (iv!.charCodeAt(m++) << 8) | iv!.charCodeAt(m++)
132
133
  m = 0
133
134
  }
@@ -1,4 +1,3 @@
1
- /* eslint-disable @typescript-eslint/no-extraneous-class */
2
1
  import { find, store } from './Cache.js'
3
2
 
4
3
  // eslint-disable-next-line no-restricted-globals
@@ -8,7 +8,11 @@ import {
8
8
  } from './SdkBase.js'
9
9
  import { RouteBuilder } from './RouteBuilder.js'
10
10
  import type { ContextListOptions, ContextListResult } from '../events/BaseEvents.js'
11
- import type { OrganizationSchema, UserOrganizationGrantType } from '../models/store/Organization.js'
11
+ import type {
12
+ OrganizationSchema,
13
+ UserOrganizationGrantType,
14
+ OrganizationSlugValidateResponse,
15
+ } from '../models/store/Organization.js'
12
16
  import type { InvitationSchema } from '../models/store/Invitation.js'
13
17
  import type { PatchInfo } from '../patch/types.js'
14
18
  import type { UserSchema } from '../models/store/User.js'
@@ -520,4 +524,80 @@ export class OrganizationsSdk extends SdkBase {
520
524
  }
521
525
  },
522
526
  }
527
+
528
+ slugs = {
529
+ /**
530
+ * Generates a slug for the organization.
531
+ * @param name The name of the organization.
532
+ * @param request Optional request options.
533
+ * @returns A promise that resolves to the generated slug.
534
+ */
535
+ generate: async (name: string, request: SdkOptions = {}): Promise<string> => {
536
+ const { token } = request
537
+ const url = this.sdk.getUrl(RouteBuilder.orgSlugGenerate()).toString()
538
+ const body = {
539
+ name,
540
+ }
541
+ const result = await this.sdk.http.post(url, {
542
+ body: JSON.stringify(body),
543
+ token,
544
+ })
545
+ this.inspectCommonStatusCodes(result)
546
+ const E_PREFIX = 'Unable to generate the slug. '
547
+ if (result.status !== 200) {
548
+ this.logInvalidResponse(result)
549
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
550
+ }
551
+ if (!result.body) {
552
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
553
+ }
554
+ let data: { slug: string }
555
+ try {
556
+ data = JSON.parse(result.body)
557
+ } catch {
558
+ throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
559
+ }
560
+ if (!data.slug) {
561
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
562
+ }
563
+ return data.slug
564
+ },
565
+
566
+ /**
567
+ * Validates a slug for the organization.
568
+ * @param slug The slug to validate.
569
+ * @param request Optional request options.
570
+ * @returns A promise that resolves to the validation result.
571
+ */
572
+ validate: async (slug: string, request: SdkOptions = {}): Promise<OrganizationSlugValidateResponse> => {
573
+ const { token } = request
574
+ const url = this.sdk.getUrl(RouteBuilder.orgSlugValidate()).toString()
575
+ const body = {
576
+ slug,
577
+ }
578
+ const result = await this.sdk.http.post(url, {
579
+ body: JSON.stringify(body),
580
+ token,
581
+ })
582
+ this.inspectCommonStatusCodes(result)
583
+ const E_PREFIX = 'Unable to validate the slug. '
584
+ if (result.status !== 200) {
585
+ this.logInvalidResponse(result)
586
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
587
+ }
588
+ if (!result.body) {
589
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
590
+ }
591
+ let data: OrganizationSlugValidateResponse
592
+ try {
593
+ data = JSON.parse(result.body)
594
+ } catch {
595
+ throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
596
+ }
597
+ if (typeof data.valid !== 'boolean') {
598
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
599
+ }
600
+ return data
601
+ },
602
+ }
523
603
  }
@@ -326,4 +326,12 @@ export class RouteBuilder {
326
326
  static aiMessage(oid: string, sid: string, mid: string): string {
327
327
  return `${RouteBuilder.aiMessages(oid, sid)}/${mid}`
328
328
  }
329
+
330
+ static orgSlugGenerate(): string {
331
+ return `/v1/orgs/slugs/generate`
332
+ }
333
+
334
+ static orgSlugValidate(): string {
335
+ return `/v1/orgs/slugs/validate`
336
+ }
329
337
  }
@@ -591,6 +591,56 @@ export class SdkMock {
591
591
  )
592
592
  },
593
593
  },
594
+
595
+ slugs: {
596
+ /**
597
+ * Mocks the `slugs.validate()` method.
598
+ * @param options Optional response customization.
599
+ */
600
+ validate: async (init?: MockResult, options?: InterceptOptions): Promise<void> => {
601
+ const { mock } = this
602
+ const respond = this.createDefaultResponse(
603
+ 200,
604
+ { 'content-type': 'application/json' },
605
+ () => JSON.stringify(this.gen.organization.organizationSlugValidateResponse()),
606
+ init
607
+ )
608
+ await mock.add(
609
+ {
610
+ match: {
611
+ uri: RouteBuilder.orgSlugValidate(),
612
+ methods: ['POST'],
613
+ },
614
+ respond,
615
+ },
616
+ options
617
+ )
618
+ },
619
+
620
+ /**
621
+ * Mocks the `slugs.generate()` method.
622
+ * @param options Optional response customization.
623
+ */
624
+ generate: async (init?: MockResult, options?: InterceptOptions): Promise<void> => {
625
+ const { mock } = this
626
+ const respond = this.createDefaultResponse(
627
+ 200,
628
+ { 'content-type': 'application/json' },
629
+ () => JSON.stringify(this.gen.organization.organizationSlugGenerateResponse()),
630
+ init
631
+ )
632
+ await mock.add(
633
+ {
634
+ match: {
635
+ uri: RouteBuilder.orgSlugGenerate(),
636
+ methods: ['POST'],
637
+ },
638
+ respond,
639
+ },
640
+ options
641
+ )
642
+ },
643
+ },
594
644
  }
595
645
 
596
646
  /**
@@ -111,11 +111,15 @@ export const TestUtils = {
111
111
  if (expectedMessage) {
112
112
  if (typeof expectedMessage === 'string') {
113
113
  if (!typedError.message.includes(expectedMessage)) {
114
- throw new Error(`Expected error message to include "${expectedMessage}", got "${typedError.message}"`)
114
+ throw new Error(`Expected error message to include "${expectedMessage}", got "${typedError.message}"`, {
115
+ cause: error,
116
+ })
115
117
  }
116
118
  } else if (expectedMessage instanceof RegExp) {
117
119
  if (!expectedMessage.test(typedError.message)) {
118
- throw new Error(`Expected error message to match ${expectedMessage}, got "${typedError.message}"`)
120
+ throw new Error(`Expected error message to match ${expectedMessage}, got "${typedError.message}"`, {
121
+ cause: error,
122
+ })
119
123
  }
120
124
  }
121
125
  }