@wix/sdk-types 1.13.41 → 1.16.0

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.
@@ -76,16 +76,27 @@ type HttpResponse<T = any> = {
76
76
  headers: any;
77
77
  request?: any;
78
78
  };
79
+ type ResponseTransformer$1 = (data: any) => any;
79
80
  type RequestOptions<_TResponse = any, Data = any> = {
80
81
  method: HTTPMethod;
81
82
  url: string;
82
83
  data?: Data;
83
84
  params?: URLSearchParams;
85
+ fallback?: RequestOptions<any, any>[];
86
+ /**
87
+ * The array option is for interoperability, defacto only the first function is used
88
+ * if an array is provided
89
+ */
90
+ transformResponse?: ResponseTransformer$1 | ResponseTransformer$1[];
84
91
  } & APIMetadata;
85
92
  type APIMetadata = {
86
93
  methodFqn?: string;
87
94
  entityFqdn?: string;
88
95
  packageName?: string;
96
+ migrationOptions?: MigrationOptions;
97
+ };
98
+ type MigrationOptions = {
99
+ optInTransformResponse?: boolean;
89
100
  };
90
101
  type BuildRESTFunction<T extends RESTFunctionDescriptor> = T extends RESTFunctionDescriptor<infer U> ? U : never;
91
102
  type RestModuleMeta<TMethod extends HTTPMethod = HTTPMethod, TPathParams = unknown, RequestType = unknown, TOriginalRequestType = unknown, ResponseType = unknown, OriginalResponseType = unknown> = {
@@ -363,44 +374,6 @@ type OperatorsWithBooleanValues = '$isEmpty' | '$exists';
363
374
  type OperatorsWithArrayValues = '$in' | '$nin' | '$hasAll' | '$hasSome';
364
375
  type OperatorForArrayFiltering = '$matchItems';
365
376
 
366
- /**
367
- * Cursor-based paging configuration
368
- */
369
- interface CursorPaging {
370
- /** Maximum number of items to return in the results. */
371
- limit?: number | null;
372
- /**
373
- * Pointer to the next or previous page in the list of results.
374
- *
375
- * Pass the relevant cursor token from the `pagingMetadata` object in the previous call's response.
376
- * Not relevant for the first request.
377
- */
378
- cursor?: string | null;
379
- }
380
- /**
381
- * Offset-based paging configuration
382
- */
383
- interface OffsetPaging {
384
- /** Number of items to load */
385
- limit?: number | null;
386
- /** Number of items to skip in the current sort order */
387
- offset?: number | null;
388
- }
389
- /**
390
- * Supported paging types for search APIs
391
- */
392
- type PagingType = 'cursor' | 'offset';
393
- /**
394
- * Paging type based on the SearchSpec's paging type
395
- */
396
- type Paging<Spec extends {
397
- paging?: PagingType;
398
- }> = Spec['paging'] extends 'cursor' ? {
399
- cursorPaging: CursorPaging;
400
- } : Spec['paging'] extends 'offset' ? {
401
- paging: OffsetPaging;
402
- } : {};
403
-
404
377
  /**
405
378
  * Sort direction type for requests
406
379
  */
@@ -433,10 +406,10 @@ type WQLFields<WQLGroup> = WQLGroup extends {
433
406
  fields: readonly string[];
434
407
  } ? WQLGroup['fields'][number] : never;
435
408
  /**
436
- * Sorting configuration for search results
437
- * @template Spec The search specification type
409
+ * Sorting configuration for search/query results
410
+ * @template Spec The WQL specification type
438
411
  */
439
- type Sorting<Spec extends SearchSpec> = Spec['wql'] extends {
412
+ type Sorting<Spec extends WQLSpec> = Spec['wql'] extends {
440
413
  length: 0;
441
414
  } | [] ? {
442
415
  fieldName?: string;
@@ -494,42 +467,14 @@ interface WQL {
494
467
  }
495
468
 
496
469
  /**
497
- * Specification for a search API
498
- * Defines what fields can be filtered, sorted, searched, and aggregated
499
- * @example
500
- * interface MySearchSpec extends SearchSpec {
501
- * wql: [{
502
- * operators: ['$eq', '$ne'], // or 'typeof ALL_APPLICABLE_OPERATORS' for all operators that can be used based on the field type
503
- * fields: ['id', 'title'],
504
- * sort: 'BOTH' // or 'ASC' / 'DESC' for specific sorting
505
- * }],
506
- * paging: 'offset', // or 'cursor' for cursor-based pagination
507
- * searchable: ['title', 'description'],
508
- * aggregatable: ['category', 'price']
509
- * };
470
+ * Base specification interface for APIs that support WQL (Wix Query Language)
510
471
  */
511
- interface SearchSpec {
472
+ interface WQLSpec {
512
473
  /**
513
474
  * Groups of fields with shared operator and sorting capabilities
514
475
  * Each group defines what operations can be performed on its fields
515
476
  */
516
477
  wql: readonly WQL[];
517
- /**
518
- * Supported paging type for this search API
519
- * - 'cursor': Uses cursor-based pagination
520
- * - 'offset': Uses offset-based pagination
521
- */
522
- paging: PagingType;
523
- /**
524
- * Fields that can be used for full-text search
525
- * If not specified, all fields are searchable
526
- */
527
- searchable?: readonly string[];
528
- /**
529
- * Fields that can be used for aggregations
530
- * These fields must be searchable and not contain PII
531
- */
532
- aggregatable?: readonly string[];
533
478
  }
534
479
 
535
480
  /**
@@ -537,19 +482,11 @@ interface SearchSpec {
537
482
  */
538
483
  type GetNestedType<Entity, Path extends string> = Path extends keyof Entity ? Entity[Path] extends (infer ArrayElement)[] | null | undefined ? ArrayElement : Exclude<Entity[Path], null | undefined> : Path extends `${infer FirstPathPart}.${infer RemainingPath}` ? FirstPathPart extends keyof Entity ? Entity[FirstPathPart] extends (infer ArrayElement)[] | null | undefined ? GetNestedType<NonNullable<ArrayElement>, RemainingPath> : Entity[FirstPathPart] extends object | null | undefined ? GetNestedType<NonNullable<Entity[FirstPathPart]>, RemainingPath> : never : never : never;
539
484
  /**
540
- * Extracts all filterable field paths from a search spec
541
- * @template Spec The search specification type
485
+ * Extracts all filterable field paths from a spec
486
+ * @template Spec The WQL specification type
542
487
  * // Results in a union type of all field paths that can be filtered
543
488
  */
544
- type FilterableFields<Spec extends SearchSpec> = Spec['wql'][number]['fields'][number];
545
- /**
546
- * Extracts all searchable field paths from a search spec
547
- * @template Spec The search specification type
548
- * // Results in a union type of all field paths that can be searched
549
- */
550
- type SearchableFields<Spec extends SearchSpec> = Spec extends {
551
- searchable: readonly string[];
552
- } ? Spec['searchable'][number] : string;
489
+ type FilterableFields<Spec extends WQLSpec> = Spec['wql'][number]['fields'][number];
553
490
 
554
491
  /**
555
492
  * Helper type to detect if a type is an enum-like union of string literals
@@ -564,25 +501,25 @@ type IsEnumLike<T> = T extends string | null | undefined ? string extends NonNul
564
501
  */
565
502
  type ApplicableOperators<Entity, Path extends string> = Path extends keyof Entity ? Entity[Path] extends string | null | undefined ? IsEnumLike<Entity[Path]> extends true ? EnumOperators : StringOperators : Entity[Path] extends number | null | undefined ? NumberOperators : Entity[Path] extends boolean | null | undefined ? BooleanOperators : Entity[Path] extends Date | null | undefined ? DateOperators : Entity[Path] extends (infer E)[] | null | undefined ? E extends object ? ArrayOfObjectsOperators : ArrayOfPrimitivesOperators : Entity[Path] extends object | null | undefined ? ObjectOperators : never : Path extends `${infer K}.${infer R}` ? K extends keyof Entity ? Entity[K] extends (infer U)[] | null | undefined ? ApplicableOperators<NonNullable<U>, R> : Entity[K] extends object | null | undefined ? ApplicableOperators<NonNullable<Entity[K]>, R> : never : never : never;
566
503
  /**
567
- * Determines allowed operators for a field based on the search spec
504
+ * Determines allowed operators for a field based on the spec
568
505
  * @template Entity The entity type
569
- * @template Spec The search specification type
506
+ * @template Spec The WQL specification type
570
507
  * @template Field The field to check
571
508
  */
572
- type AllowedOperators<Entity, Spec extends SearchSpec, Field extends FilterableFields<Spec>> = Spec['wql'][number] extends infer WQLGroup ? WQLGroup extends WQL ? Field extends WQLGroup['fields'][number] ? WQLGroup['operators'] extends typeof ALL_APPLICABLE_OPERATORS ? ApplicableOperators<Entity, Field & string> : WQLGroup['operators'] extends readonly string[] ? WQLGroup['operators'][number] : never : never : never : never;
509
+ type AllowedOperators<Entity, Spec extends WQLSpec, Field extends FilterableFields<Spec>> = Spec['wql'][number] extends infer WQLGroup ? WQLGroup extends WQL ? Field extends WQLGroup['fields'][number] ? WQLGroup['operators'] extends typeof ALL_APPLICABLE_OPERATORS ? ApplicableOperators<Entity, Field & string> : WQLGroup['operators'] extends readonly string[] ? WQLGroup['operators'][number] : never : never : never : never;
573
510
  /**
574
511
  * Filter operations type for individual field conditions
575
512
  * @template Entity The entity type
576
- * @template Spec The search specification type
513
+ * @template Spec The WQL specification type
577
514
  * @template Field The field to filter on
578
515
  */
579
- type FilterOps<Entity, Spec extends SearchSpec, Field extends FilterableFields<Spec>> = Simplify<{
516
+ type FilterOps<Entity, Spec extends WQLSpec, Field extends FilterableFields<Spec>> = Simplify<{
580
517
  [Op in AllowedOperators<Entity, Spec, Field>]?: Op extends OperatorsWithBooleanValues ? boolean : Op extends OperatorForArrayFiltering ? JsonObject[] : Op extends OperatorsWithArrayValues ? GetNestedType<Entity, Field & string>[] : GetNestedType<Entity, Field & string>;
581
518
  }>;
582
519
  /**
583
520
  * Filter type for building type-safe query filters
584
521
  * @template Entity The entity type
585
- * @template Spec The search specification type
522
+ * @template Spec The WQL specification type
586
523
  * @example
587
524
  * // Simple filter
588
525
  * const filter: Filter<Product, ProductSpec> = {
@@ -601,7 +538,7 @@ type FilterOps<Entity, Spec extends SearchSpec, Field extends FilterableFields<S
601
538
  * ]
602
539
  * };
603
540
  */
604
- type Filter<Entity, Spec extends SearchSpec> = Simplify<{
541
+ type Filter<Entity, Spec extends WQLSpec> = Simplify<{
605
542
  [Field in FilterableFields<Spec>]?: AllowedOperators<Entity, Spec, Field> extends infer AllowedOps ? AllowedOps extends '$eq' ? GetNestedType<Entity, Field & string> | FilterOps<Entity, Spec, Field> : FilterOps<Entity, Spec, Field> : never;
606
543
  } | {
607
544
  $and?: Filter<Entity, Spec>[];
@@ -609,6 +546,78 @@ type Filter<Entity, Spec extends SearchSpec> = Simplify<{
609
546
  $not?: Filter<Entity, Spec>;
610
547
  }>;
611
548
 
549
+ /**
550
+ * Cursor-based paging configuration
551
+ */
552
+ interface CursorPaging {
553
+ /** Maximum number of items to return in the results. */
554
+ limit?: number | null;
555
+ /**
556
+ * Pointer to the next or previous page in the list of results.
557
+ *
558
+ * Pass the relevant cursor token from the `pagingMetadata` object in the previous call's response.
559
+ * Not relevant for the first request.
560
+ */
561
+ cursor?: string | null;
562
+ }
563
+ /**
564
+ * Offset-based paging configuration
565
+ */
566
+ interface OffsetPaging {
567
+ /** Number of items to load */
568
+ limit?: number | null;
569
+ /** Number of items to skip in the current sort order */
570
+ offset?: number | null;
571
+ }
572
+ /**
573
+ * Supported paging types for search APIs
574
+ */
575
+ type PagingType = 'cursor' | 'offset';
576
+ /**
577
+ * Paging type based on the SearchSpec's paging type
578
+ */
579
+ type Paging<Spec extends {
580
+ paging?: PagingType;
581
+ }> = Spec['paging'] extends 'cursor' ? {
582
+ cursorPaging: CursorPaging;
583
+ } : Spec['paging'] extends 'offset' ? {
584
+ paging: OffsetPaging;
585
+ } : {};
586
+
587
+ /**
588
+ * Specification for a search API
589
+ * Defines what fields can be filtered, sorted, searched, and aggregated
590
+ * @example
591
+ * interface MySearchSpec extends SearchSpec {
592
+ * wql: [{
593
+ * operators: ['$eq', '$ne'], // or 'typeof ALL_APPLICABLE_OPERATORS' for all operators that can be used based on the field type
594
+ * fields: ['id', 'title'],
595
+ * sort: 'BOTH' // or 'ASC' / 'DESC' for specific sorting
596
+ * }],
597
+ * paging: 'offset', // or 'cursor' for cursor-based pagination
598
+ * searchable: ['title', 'description'],
599
+ * aggregatable: ['category', 'price']
600
+ * };
601
+ */
602
+ interface SearchSpec extends WQLSpec {
603
+ /**
604
+ * Supported paging type for this search API
605
+ * - 'cursor': Uses cursor-based pagination
606
+ * - 'offset': Uses offset-based pagination
607
+ */
608
+ paging: PagingType;
609
+ /**
610
+ * Fields that can be used for full-text search
611
+ * If not specified, all fields are searchable
612
+ */
613
+ searchable?: readonly string[];
614
+ /**
615
+ * Fields that can be used for aggregations
616
+ * These fields must be searchable and not contain PII
617
+ */
618
+ aggregatable?: readonly string[];
619
+ }
620
+
612
621
  /**
613
622
  * Type of scalar aggregation to perform
614
623
  */
@@ -716,6 +725,15 @@ type Aggregation<Spec extends SearchSpec> = BaseAggregationWithoutType<Spec> & {
716
725
  nested?: NestedAggregation<Spec>;
717
726
  };
718
727
 
728
+ /**
729
+ * Extracts all searchable field paths from a search spec
730
+ * @template Spec The search specification type
731
+ * // Results in a union type of all field paths that can be searched
732
+ */
733
+ type SearchableFields<Spec extends SearchSpec> = Spec extends {
734
+ searchable: readonly string[];
735
+ } ? Spec['searchable'][number] : string;
736
+
719
737
  /**
720
738
  * Configuration for full-text search functionality
721
739
  * @template Spec The search specification type
@@ -806,4 +824,61 @@ type BaseSearch<Entity, Spec extends SearchSpec> = {
806
824
  */
807
825
  type Search<Entity, Spec extends SearchSpec> = BaseSearch<Entity, Spec> & Partial<Paging<Spec>>;
808
826
 
809
- export { type APIMetadata, type AmbassadorFactory, type AmbassadorFunctionDescriptor, type AmbassadorRequestOptions, type AuthenticationStrategy, type BaseEventMetadata, type BoundAuthenticationStrategy, type BuildAmbassadorFunction, type BuildDescriptors, type BuildEventDefinition, type BuildRESTFunction, type BuildServicePluginDefinition, type Descriptors, EventDefinition, type EventHandler, type EventIdentity, type ExposeFieldsBasedOnToggle, type HTTPMethod, type Host, type HostModule, type HostModuleAPI, type HttpClient, type HttpResponse, type MaybeContext, type Method, type NonNullablePaths, type PublicMetadata, type RESTFunctionDescriptor, type RequestContext, type RequestOptions, type RequestOptionsFactory, type RestModuleMeta, SERVICE_PLUGIN_ERROR_TYPE, type Search, type SearchSpec, type ServicePluginContract, ServicePluginDefinition, type ServicePluginMethodInput, type ServicePluginMethodMetadata };
827
+ /**
828
+ * Specification for a query API
829
+ * Defines what fields can be filtered and sorted
830
+ * @example
831
+ * interface MyQuerySpec extends QuerySpec {
832
+ * wql: [{
833
+ * operators: ['$eq', '$ne'],
834
+ * fields: ['id', 'title'],
835
+ * sort: 'BOTH'
836
+ * }],
837
+ * paging: 'offset', // or 'cursor' for cursor-based pagination
838
+ * };
839
+ */
840
+ interface QuerySpec extends WQLSpec {
841
+ /**
842
+ * Supported paging type for this query API
843
+ * - 'cursor': Uses cursor-based pagination
844
+ * - 'offset': Uses offset-based pagination
845
+ */
846
+ paging: PagingType;
847
+ }
848
+
849
+ /**
850
+ * Complete query request for an entity type
851
+ * @template Entity The entity type being queried
852
+ * @template Spec The query specification type
853
+ * @example
854
+ * // Define a query type for products
855
+ * type QueryProducts = Query<Product, ProductQuerySpec>;
856
+ *
857
+ * // Create a query request with offset paging
858
+ * const query: QueryProducts = {
859
+ * filter: { price: { $gte: 10 } },
860
+ * sort: [{ fieldName: 'price', order: 'ASC' }],
861
+ * paging: { limit: 20, offset: 0 }
862
+ * };
863
+ *
864
+ * // Or with cursor paging (if spec.paging = 'cursor')
865
+ * const query: QueryProducts = {
866
+ * filter: { price: { $gte: 10 } },
867
+ * sort: [{ fieldName: 'price', order: 'ASC' }],
868
+ * cursorPaging: { limit: 20, cursor: "..." }
869
+ * };
870
+ */
871
+ type Query<Entity, Spec extends QuerySpec> = {
872
+ /**
873
+ * Filter object.
874
+ * Learn more about the [filter section](https://dev.wix.com/docs/rest/articles/getting-started/api-query-language#the-filter-section).
875
+ */
876
+ filter?: Filter<Entity, Spec>;
877
+ /**
878
+ * List of sort objects.
879
+ * Learn more about the [sort section](https://dev.wix.com/docs/rest/articles/getting-started/api-query-language#the-sort-section).
880
+ */
881
+ sort?: Sorting<Spec>[];
882
+ } & Partial<Paging<Spec>>;
883
+
884
+ export { type APIMetadata, type AmbassadorFactory, type AmbassadorFunctionDescriptor, type AmbassadorRequestOptions, type AuthenticationStrategy, type BaseEventMetadata, type BoundAuthenticationStrategy, type BuildAmbassadorFunction, type BuildDescriptors, type BuildEventDefinition, type BuildRESTFunction, type BuildServicePluginDefinition, type Descriptors, EventDefinition, type EventHandler, type EventIdentity, type ExposeFieldsBasedOnToggle, type Filter, type FilterableFields, type GetNestedType, type HTTPMethod, type Host, type HostModule, type HostModuleAPI, type HttpClient, type HttpResponse, type MaybeContext, type Method, type MigrationOptions, type NonNullablePaths, type PublicMetadata, type Query, type QuerySpec, type RESTFunctionDescriptor, type RequestContext, type RequestOptions, type RequestOptionsFactory, type RestModuleMeta, SERVICE_PLUGIN_ERROR_TYPE, SORT_CAPABILITIES, SORT_DIRECTIONS, type Search, type SearchSpec, type ServicePluginContract, ServicePluginDefinition, type ServicePluginMethodInput, type ServicePluginMethodMetadata, type SortCapability, type SortOrder, type Sorting, type WQL, type WQLSpec };
@@ -17,8 +17,21 @@ function ServicePluginDefinition(componentType, methods) {
17
17
  };
18
18
  }
19
19
  var SERVICE_PLUGIN_ERROR_TYPE = "wix_spi_error";
20
+
21
+ // src/common/sort.ts
22
+ var SORT_DIRECTIONS = {
23
+ ASC: "ASC",
24
+ DESC: "DESC"
25
+ };
26
+ var SORT_CAPABILITIES = {
27
+ ...SORT_DIRECTIONS,
28
+ BOTH: "BOTH",
29
+ NONE: "NONE"
30
+ };
20
31
  export {
21
32
  EventDefinition,
22
33
  SERVICE_PLUGIN_ERROR_TYPE,
34
+ SORT_CAPABILITIES,
35
+ SORT_DIRECTIONS,
23
36
  ServicePluginDefinition
24
37
  };