@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.
@@ -134,16 +134,27 @@ type HttpResponse<T = any> = {
134
134
  headers: any;
135
135
  request?: any;
136
136
  };
137
+ type ResponseTransformer$1 = (data: any) => any;
137
138
  type RequestOptions<_TResponse = any, Data = any> = {
138
139
  method: HTTPMethod;
139
140
  url: string;
140
141
  data?: Data;
141
142
  params?: URLSearchParams;
143
+ fallback?: RequestOptions<any, any>[];
144
+ /**
145
+ * The array option is for interoperability, defacto only the first function is used
146
+ * if an array is provided
147
+ */
148
+ transformResponse?: ResponseTransformer$1 | ResponseTransformer$1[];
142
149
  } & APIMetadata;
143
150
  type APIMetadata = {
144
151
  methodFqn?: string;
145
152
  entityFqdn?: string;
146
153
  packageName?: string;
154
+ migrationOptions?: MigrationOptions;
155
+ };
156
+ type MigrationOptions = {
157
+ optInTransformResponse?: boolean;
147
158
  };
148
159
  type BuildRESTFunction<T extends RESTFunctionDescriptor> = T extends RESTFunctionDescriptor<infer U> ? U : never;
149
160
  type RestModuleMeta<TMethod extends HTTPMethod = HTTPMethod, TPathParams = unknown, RequestType = unknown, TOriginalRequestType = unknown, ResponseType = unknown, OriginalResponseType = unknown> = {
@@ -421,44 +432,6 @@ type OperatorsWithBooleanValues = '$isEmpty' | '$exists';
421
432
  type OperatorsWithArrayValues = '$in' | '$nin' | '$hasAll' | '$hasSome';
422
433
  type OperatorForArrayFiltering = '$matchItems';
423
434
 
424
- /**
425
- * Cursor-based paging configuration
426
- */
427
- interface CursorPaging {
428
- /** Maximum number of items to return in the results. */
429
- limit?: number | null;
430
- /**
431
- * Pointer to the next or previous page in the list of results.
432
- *
433
- * Pass the relevant cursor token from the `pagingMetadata` object in the previous call's response.
434
- * Not relevant for the first request.
435
- */
436
- cursor?: string | null;
437
- }
438
- /**
439
- * Offset-based paging configuration
440
- */
441
- interface OffsetPaging {
442
- /** Number of items to load */
443
- limit?: number | null;
444
- /** Number of items to skip in the current sort order */
445
- offset?: number | null;
446
- }
447
- /**
448
- * Supported paging types for search APIs
449
- */
450
- type PagingType = 'cursor' | 'offset';
451
- /**
452
- * Paging type based on the SearchSpec's paging type
453
- */
454
- type Paging<Spec extends {
455
- paging?: PagingType;
456
- }> = Spec['paging'] extends 'cursor' ? {
457
- cursorPaging: CursorPaging;
458
- } : Spec['paging'] extends 'offset' ? {
459
- paging: OffsetPaging;
460
- } : {};
461
-
462
435
  /**
463
436
  * Sort direction type for requests
464
437
  */
@@ -491,10 +464,10 @@ type WQLFields<WQLGroup> = WQLGroup extends {
491
464
  fields: readonly string[];
492
465
  } ? WQLGroup['fields'][number] : never;
493
466
  /**
494
- * Sorting configuration for search results
495
- * @template Spec The search specification type
467
+ * Sorting configuration for search/query results
468
+ * @template Spec The WQL specification type
496
469
  */
497
- type Sorting<Spec extends SearchSpec> = Spec['wql'] extends {
470
+ type Sorting<Spec extends WQLSpec> = Spec['wql'] extends {
498
471
  length: 0;
499
472
  } | [] ? {
500
473
  fieldName?: string;
@@ -552,42 +525,14 @@ interface WQL {
552
525
  }
553
526
 
554
527
  /**
555
- * Specification for a search API
556
- * Defines what fields can be filtered, sorted, searched, and aggregated
557
- * @example
558
- * interface MySearchSpec extends SearchSpec {
559
- * wql: [{
560
- * operators: ['$eq', '$ne'], // or 'typeof ALL_APPLICABLE_OPERATORS' for all operators that can be used based on the field type
561
- * fields: ['id', 'title'],
562
- * sort: 'BOTH' // or 'ASC' / 'DESC' for specific sorting
563
- * }],
564
- * paging: 'offset', // or 'cursor' for cursor-based pagination
565
- * searchable: ['title', 'description'],
566
- * aggregatable: ['category', 'price']
567
- * };
528
+ * Base specification interface for APIs that support WQL (Wix Query Language)
568
529
  */
569
- interface SearchSpec {
530
+ interface WQLSpec {
570
531
  /**
571
532
  * Groups of fields with shared operator and sorting capabilities
572
533
  * Each group defines what operations can be performed on its fields
573
534
  */
574
535
  wql: readonly WQL[];
575
- /**
576
- * Supported paging type for this search API
577
- * - 'cursor': Uses cursor-based pagination
578
- * - 'offset': Uses offset-based pagination
579
- */
580
- paging: PagingType;
581
- /**
582
- * Fields that can be used for full-text search
583
- * If not specified, all fields are searchable
584
- */
585
- searchable?: readonly string[];
586
- /**
587
- * Fields that can be used for aggregations
588
- * These fields must be searchable and not contain PII
589
- */
590
- aggregatable?: readonly string[];
591
536
  }
592
537
 
593
538
  /**
@@ -595,19 +540,11 @@ interface SearchSpec {
595
540
  */
596
541
  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;
597
542
  /**
598
- * Extracts all filterable field paths from a search spec
599
- * @template Spec The search specification type
543
+ * Extracts all filterable field paths from a spec
544
+ * @template Spec The WQL specification type
600
545
  * // Results in a union type of all field paths that can be filtered
601
546
  */
602
- type FilterableFields<Spec extends SearchSpec> = Spec['wql'][number]['fields'][number];
603
- /**
604
- * Extracts all searchable field paths from a search spec
605
- * @template Spec The search specification type
606
- * // Results in a union type of all field paths that can be searched
607
- */
608
- type SearchableFields<Spec extends SearchSpec> = Spec extends {
609
- searchable: readonly string[];
610
- } ? Spec['searchable'][number] : string;
547
+ type FilterableFields<Spec extends WQLSpec> = Spec['wql'][number]['fields'][number];
611
548
 
612
549
  /**
613
550
  * Helper type to detect if a type is an enum-like union of string literals
@@ -622,25 +559,25 @@ type IsEnumLike<T> = T extends string | null | undefined ? string extends NonNul
622
559
  */
623
560
  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;
624
561
  /**
625
- * Determines allowed operators for a field based on the search spec
562
+ * Determines allowed operators for a field based on the spec
626
563
  * @template Entity The entity type
627
- * @template Spec The search specification type
564
+ * @template Spec The WQL specification type
628
565
  * @template Field The field to check
629
566
  */
630
- 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;
567
+ 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;
631
568
  /**
632
569
  * Filter operations type for individual field conditions
633
570
  * @template Entity The entity type
634
- * @template Spec The search specification type
571
+ * @template Spec The WQL specification type
635
572
  * @template Field The field to filter on
636
573
  */
637
- type FilterOps<Entity, Spec extends SearchSpec, Field extends FilterableFields<Spec>> = Simplify<{
574
+ type FilterOps<Entity, Spec extends WQLSpec, Field extends FilterableFields<Spec>> = Simplify<{
638
575
  [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>;
639
576
  }>;
640
577
  /**
641
578
  * Filter type for building type-safe query filters
642
579
  * @template Entity The entity type
643
- * @template Spec The search specification type
580
+ * @template Spec The WQL specification type
644
581
  * @example
645
582
  * // Simple filter
646
583
  * const filter: Filter<Product, ProductSpec> = {
@@ -659,7 +596,7 @@ type FilterOps<Entity, Spec extends SearchSpec, Field extends FilterableFields<S
659
596
  * ]
660
597
  * };
661
598
  */
662
- type Filter<Entity, Spec extends SearchSpec> = Simplify<{
599
+ type Filter<Entity, Spec extends WQLSpec> = Simplify<{
663
600
  [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;
664
601
  } | {
665
602
  $and?: Filter<Entity, Spec>[];
@@ -667,6 +604,78 @@ type Filter<Entity, Spec extends SearchSpec> = Simplify<{
667
604
  $not?: Filter<Entity, Spec>;
668
605
  }>;
669
606
 
607
+ /**
608
+ * Cursor-based paging configuration
609
+ */
610
+ interface CursorPaging {
611
+ /** Maximum number of items to return in the results. */
612
+ limit?: number | null;
613
+ /**
614
+ * Pointer to the next or previous page in the list of results.
615
+ *
616
+ * Pass the relevant cursor token from the `pagingMetadata` object in the previous call's response.
617
+ * Not relevant for the first request.
618
+ */
619
+ cursor?: string | null;
620
+ }
621
+ /**
622
+ * Offset-based paging configuration
623
+ */
624
+ interface OffsetPaging {
625
+ /** Number of items to load */
626
+ limit?: number | null;
627
+ /** Number of items to skip in the current sort order */
628
+ offset?: number | null;
629
+ }
630
+ /**
631
+ * Supported paging types for search APIs
632
+ */
633
+ type PagingType = 'cursor' | 'offset';
634
+ /**
635
+ * Paging type based on the SearchSpec's paging type
636
+ */
637
+ type Paging<Spec extends {
638
+ paging?: PagingType;
639
+ }> = Spec['paging'] extends 'cursor' ? {
640
+ cursorPaging: CursorPaging;
641
+ } : Spec['paging'] extends 'offset' ? {
642
+ paging: OffsetPaging;
643
+ } : {};
644
+
645
+ /**
646
+ * Specification for a search API
647
+ * Defines what fields can be filtered, sorted, searched, and aggregated
648
+ * @example
649
+ * interface MySearchSpec extends SearchSpec {
650
+ * wql: [{
651
+ * operators: ['$eq', '$ne'], // or 'typeof ALL_APPLICABLE_OPERATORS' for all operators that can be used based on the field type
652
+ * fields: ['id', 'title'],
653
+ * sort: 'BOTH' // or 'ASC' / 'DESC' for specific sorting
654
+ * }],
655
+ * paging: 'offset', // or 'cursor' for cursor-based pagination
656
+ * searchable: ['title', 'description'],
657
+ * aggregatable: ['category', 'price']
658
+ * };
659
+ */
660
+ interface SearchSpec extends WQLSpec {
661
+ /**
662
+ * Supported paging type for this search API
663
+ * - 'cursor': Uses cursor-based pagination
664
+ * - 'offset': Uses offset-based pagination
665
+ */
666
+ paging: PagingType;
667
+ /**
668
+ * Fields that can be used for full-text search
669
+ * If not specified, all fields are searchable
670
+ */
671
+ searchable?: readonly string[];
672
+ /**
673
+ * Fields that can be used for aggregations
674
+ * These fields must be searchable and not contain PII
675
+ */
676
+ aggregatable?: readonly string[];
677
+ }
678
+
670
679
  /**
671
680
  * Type of scalar aggregation to perform
672
681
  */
@@ -774,6 +783,15 @@ type Aggregation<Spec extends SearchSpec> = BaseAggregationWithoutType<Spec> & {
774
783
  nested?: NestedAggregation<Spec>;
775
784
  };
776
785
 
786
+ /**
787
+ * Extracts all searchable field paths from a search spec
788
+ * @template Spec The search specification type
789
+ * // Results in a union type of all field paths that can be searched
790
+ */
791
+ type SearchableFields<Spec extends SearchSpec> = Spec extends {
792
+ searchable: readonly string[];
793
+ } ? Spec['searchable'][number] : string;
794
+
777
795
  /**
778
796
  * Configuration for full-text search functionality
779
797
  * @template Spec The search specification type
@@ -864,4 +882,61 @@ type BaseSearch<Entity, Spec extends SearchSpec> = {
864
882
  */
865
883
  type Search<Entity, Spec extends SearchSpec> = BaseSearch<Entity, Spec> & Partial<Paging<Spec>>;
866
884
 
867
- 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 };
885
+ /**
886
+ * Specification for a query API
887
+ * Defines what fields can be filtered and sorted
888
+ * @example
889
+ * interface MyQuerySpec extends QuerySpec {
890
+ * wql: [{
891
+ * operators: ['$eq', '$ne'],
892
+ * fields: ['id', 'title'],
893
+ * sort: 'BOTH'
894
+ * }],
895
+ * paging: 'offset', // or 'cursor' for cursor-based pagination
896
+ * };
897
+ */
898
+ interface QuerySpec extends WQLSpec {
899
+ /**
900
+ * Supported paging type for this query API
901
+ * - 'cursor': Uses cursor-based pagination
902
+ * - 'offset': Uses offset-based pagination
903
+ */
904
+ paging: PagingType;
905
+ }
906
+
907
+ /**
908
+ * Complete query request for an entity type
909
+ * @template Entity The entity type being queried
910
+ * @template Spec The query specification type
911
+ * @example
912
+ * // Define a query type for products
913
+ * type QueryProducts = Query<Product, ProductQuerySpec>;
914
+ *
915
+ * // Create a query request with offset paging
916
+ * const query: QueryProducts = {
917
+ * filter: { price: { $gte: 10 } },
918
+ * sort: [{ fieldName: 'price', order: 'ASC' }],
919
+ * paging: { limit: 20, offset: 0 }
920
+ * };
921
+ *
922
+ * // Or with cursor paging (if spec.paging = 'cursor')
923
+ * const query: QueryProducts = {
924
+ * filter: { price: { $gte: 10 } },
925
+ * sort: [{ fieldName: 'price', order: 'ASC' }],
926
+ * cursorPaging: { limit: 20, cursor: "..." }
927
+ * };
928
+ */
929
+ type Query<Entity, Spec extends QuerySpec> = {
930
+ /**
931
+ * Filter object.
932
+ * Learn more about the [filter section](https://dev.wix.com/docs/rest/articles/getting-started/api-query-language#the-filter-section).
933
+ */
934
+ filter?: Filter<Entity, Spec>;
935
+ /**
936
+ * List of sort objects.
937
+ * Learn more about the [sort section](https://dev.wix.com/docs/rest/articles/getting-started/api-query-language#the-sort-section).
938
+ */
939
+ sort?: Sorting<Spec>[];
940
+ } & Partial<Paging<Spec>>;
941
+
942
+ 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 };