@wix/sdk-types 1.14.0 → 1.17.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.
@@ -58,6 +58,13 @@ type Host<Environment = unknown> = {
58
58
  */
59
59
  passThroughHeaders?: Record<string, string>;
60
60
  };
61
+ translations?: () => {
62
+ [language: string]: {
63
+ [namespace: string]: {
64
+ [key: string]: string;
65
+ };
66
+ };
67
+ } | undefined;
61
68
  };
62
69
 
63
70
  type HTTPMethod = 'POST' | 'GET' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS';
@@ -374,44 +381,6 @@ type OperatorsWithBooleanValues = '$isEmpty' | '$exists';
374
381
  type OperatorsWithArrayValues = '$in' | '$nin' | '$hasAll' | '$hasSome';
375
382
  type OperatorForArrayFiltering = '$matchItems';
376
383
 
377
- /**
378
- * Cursor-based paging configuration
379
- */
380
- interface CursorPaging {
381
- /** Maximum number of items to return in the results. */
382
- limit?: number | null;
383
- /**
384
- * Pointer to the next or previous page in the list of results.
385
- *
386
- * Pass the relevant cursor token from the `pagingMetadata` object in the previous call's response.
387
- * Not relevant for the first request.
388
- */
389
- cursor?: string | null;
390
- }
391
- /**
392
- * Offset-based paging configuration
393
- */
394
- interface OffsetPaging {
395
- /** Number of items to load */
396
- limit?: number | null;
397
- /** Number of items to skip in the current sort order */
398
- offset?: number | null;
399
- }
400
- /**
401
- * Supported paging types for search APIs
402
- */
403
- type PagingType = 'cursor' | 'offset';
404
- /**
405
- * Paging type based on the SearchSpec's paging type
406
- */
407
- type Paging<Spec extends {
408
- paging?: PagingType;
409
- }> = Spec['paging'] extends 'cursor' ? {
410
- cursorPaging: CursorPaging;
411
- } : Spec['paging'] extends 'offset' ? {
412
- paging: OffsetPaging;
413
- } : {};
414
-
415
384
  /**
416
385
  * Sort direction type for requests
417
386
  */
@@ -444,10 +413,10 @@ type WQLFields<WQLGroup> = WQLGroup extends {
444
413
  fields: readonly string[];
445
414
  } ? WQLGroup['fields'][number] : never;
446
415
  /**
447
- * Sorting configuration for search results
448
- * @template Spec The search specification type
416
+ * Sorting configuration for search/query results
417
+ * @template Spec The WQL specification type
449
418
  */
450
- type Sorting<Spec extends SearchSpec> = Spec['wql'] extends {
419
+ type Sorting<Spec extends WQLSpec> = Spec['wql'] extends {
451
420
  length: 0;
452
421
  } | [] ? {
453
422
  fieldName?: string;
@@ -505,42 +474,14 @@ interface WQL {
505
474
  }
506
475
 
507
476
  /**
508
- * Specification for a search API
509
- * Defines what fields can be filtered, sorted, searched, and aggregated
510
- * @example
511
- * interface MySearchSpec extends SearchSpec {
512
- * wql: [{
513
- * operators: ['$eq', '$ne'], // or 'typeof ALL_APPLICABLE_OPERATORS' for all operators that can be used based on the field type
514
- * fields: ['id', 'title'],
515
- * sort: 'BOTH' // or 'ASC' / 'DESC' for specific sorting
516
- * }],
517
- * paging: 'offset', // or 'cursor' for cursor-based pagination
518
- * searchable: ['title', 'description'],
519
- * aggregatable: ['category', 'price']
520
- * };
477
+ * Base specification interface for APIs that support WQL (Wix Query Language)
521
478
  */
522
- interface SearchSpec {
479
+ interface WQLSpec {
523
480
  /**
524
481
  * Groups of fields with shared operator and sorting capabilities
525
482
  * Each group defines what operations can be performed on its fields
526
483
  */
527
484
  wql: readonly WQL[];
528
- /**
529
- * Supported paging type for this search API
530
- * - 'cursor': Uses cursor-based pagination
531
- * - 'offset': Uses offset-based pagination
532
- */
533
- paging: PagingType;
534
- /**
535
- * Fields that can be used for full-text search
536
- * If not specified, all fields are searchable
537
- */
538
- searchable?: readonly string[];
539
- /**
540
- * Fields that can be used for aggregations
541
- * These fields must be searchable and not contain PII
542
- */
543
- aggregatable?: readonly string[];
544
485
  }
545
486
 
546
487
  /**
@@ -548,19 +489,11 @@ interface SearchSpec {
548
489
  */
549
490
  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;
550
491
  /**
551
- * Extracts all filterable field paths from a search spec
552
- * @template Spec The search specification type
492
+ * Extracts all filterable field paths from a spec
493
+ * @template Spec The WQL specification type
553
494
  * // Results in a union type of all field paths that can be filtered
554
495
  */
555
- type FilterableFields<Spec extends SearchSpec> = Spec['wql'][number]['fields'][number];
556
- /**
557
- * Extracts all searchable field paths from a search spec
558
- * @template Spec The search specification type
559
- * // Results in a union type of all field paths that can be searched
560
- */
561
- type SearchableFields<Spec extends SearchSpec> = Spec extends {
562
- searchable: readonly string[];
563
- } ? Spec['searchable'][number] : string;
496
+ type FilterableFields<Spec extends WQLSpec> = Spec['wql'][number]['fields'][number];
564
497
 
565
498
  /**
566
499
  * Helper type to detect if a type is an enum-like union of string literals
@@ -575,25 +508,25 @@ type IsEnumLike<T> = T extends string | null | undefined ? string extends NonNul
575
508
  */
576
509
  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;
577
510
  /**
578
- * Determines allowed operators for a field based on the search spec
511
+ * Determines allowed operators for a field based on the spec
579
512
  * @template Entity The entity type
580
- * @template Spec The search specification type
513
+ * @template Spec The WQL specification type
581
514
  * @template Field The field to check
582
515
  */
583
- 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;
516
+ 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;
584
517
  /**
585
518
  * Filter operations type for individual field conditions
586
519
  * @template Entity The entity type
587
- * @template Spec The search specification type
520
+ * @template Spec The WQL specification type
588
521
  * @template Field The field to filter on
589
522
  */
590
- type FilterOps<Entity, Spec extends SearchSpec, Field extends FilterableFields<Spec>> = Simplify<{
523
+ type FilterOps<Entity, Spec extends WQLSpec, Field extends FilterableFields<Spec>> = Simplify<{
591
524
  [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>;
592
525
  }>;
593
526
  /**
594
527
  * Filter type for building type-safe query filters
595
528
  * @template Entity The entity type
596
- * @template Spec The search specification type
529
+ * @template Spec The WQL specification type
597
530
  * @example
598
531
  * // Simple filter
599
532
  * const filter: Filter<Product, ProductSpec> = {
@@ -612,7 +545,7 @@ type FilterOps<Entity, Spec extends SearchSpec, Field extends FilterableFields<S
612
545
  * ]
613
546
  * };
614
547
  */
615
- type Filter<Entity, Spec extends SearchSpec> = Simplify<{
548
+ type Filter<Entity, Spec extends WQLSpec> = Simplify<{
616
549
  [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;
617
550
  } | {
618
551
  $and?: Filter<Entity, Spec>[];
@@ -620,6 +553,78 @@ type Filter<Entity, Spec extends SearchSpec> = Simplify<{
620
553
  $not?: Filter<Entity, Spec>;
621
554
  }>;
622
555
 
556
+ /**
557
+ * Cursor-based paging configuration
558
+ */
559
+ interface CursorPaging {
560
+ /** Maximum number of items to return in the results. */
561
+ limit?: number | null;
562
+ /**
563
+ * Pointer to the next or previous page in the list of results.
564
+ *
565
+ * Pass the relevant cursor token from the `pagingMetadata` object in the previous call's response.
566
+ * Not relevant for the first request.
567
+ */
568
+ cursor?: string | null;
569
+ }
570
+ /**
571
+ * Offset-based paging configuration
572
+ */
573
+ interface OffsetPaging {
574
+ /** Number of items to load */
575
+ limit?: number | null;
576
+ /** Number of items to skip in the current sort order */
577
+ offset?: number | null;
578
+ }
579
+ /**
580
+ * Supported paging types for search APIs
581
+ */
582
+ type PagingType = 'cursor' | 'offset';
583
+ /**
584
+ * Paging type based on the SearchSpec's paging type
585
+ */
586
+ type Paging<Spec extends {
587
+ paging?: PagingType;
588
+ }> = Spec['paging'] extends 'cursor' ? {
589
+ cursorPaging: CursorPaging;
590
+ } : Spec['paging'] extends 'offset' ? {
591
+ paging: OffsetPaging;
592
+ } : {};
593
+
594
+ /**
595
+ * Specification for a search API
596
+ * Defines what fields can be filtered, sorted, searched, and aggregated
597
+ * @example
598
+ * interface MySearchSpec extends SearchSpec {
599
+ * wql: [{
600
+ * operators: ['$eq', '$ne'], // or 'typeof ALL_APPLICABLE_OPERATORS' for all operators that can be used based on the field type
601
+ * fields: ['id', 'title'],
602
+ * sort: 'BOTH' // or 'ASC' / 'DESC' for specific sorting
603
+ * }],
604
+ * paging: 'offset', // or 'cursor' for cursor-based pagination
605
+ * searchable: ['title', 'description'],
606
+ * aggregatable: ['category', 'price']
607
+ * };
608
+ */
609
+ interface SearchSpec extends WQLSpec {
610
+ /**
611
+ * Supported paging type for this search API
612
+ * - 'cursor': Uses cursor-based pagination
613
+ * - 'offset': Uses offset-based pagination
614
+ */
615
+ paging: PagingType;
616
+ /**
617
+ * Fields that can be used for full-text search
618
+ * If not specified, all fields are searchable
619
+ */
620
+ searchable?: readonly string[];
621
+ /**
622
+ * Fields that can be used for aggregations
623
+ * These fields must be searchable and not contain PII
624
+ */
625
+ aggregatable?: readonly string[];
626
+ }
627
+
623
628
  /**
624
629
  * Type of scalar aggregation to perform
625
630
  */
@@ -727,6 +732,15 @@ type Aggregation<Spec extends SearchSpec> = BaseAggregationWithoutType<Spec> & {
727
732
  nested?: NestedAggregation<Spec>;
728
733
  };
729
734
 
735
+ /**
736
+ * Extracts all searchable field paths from a search spec
737
+ * @template Spec The search specification type
738
+ * // Results in a union type of all field paths that can be searched
739
+ */
740
+ type SearchableFields<Spec extends SearchSpec> = Spec extends {
741
+ searchable: readonly string[];
742
+ } ? Spec['searchable'][number] : string;
743
+
730
744
  /**
731
745
  * Configuration for full-text search functionality
732
746
  * @template Spec The search specification type
@@ -817,4 +831,61 @@ type BaseSearch<Entity, Spec extends SearchSpec> = {
817
831
  */
818
832
  type Search<Entity, Spec extends SearchSpec> = BaseSearch<Entity, Spec> & Partial<Paging<Spec>>;
819
833
 
820
- 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 MigrationOptions, 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 };
834
+ /**
835
+ * Specification for a query API
836
+ * Defines what fields can be filtered and sorted
837
+ * @example
838
+ * interface MyQuerySpec extends QuerySpec {
839
+ * wql: [{
840
+ * operators: ['$eq', '$ne'],
841
+ * fields: ['id', 'title'],
842
+ * sort: 'BOTH'
843
+ * }],
844
+ * paging: 'offset', // or 'cursor' for cursor-based pagination
845
+ * };
846
+ */
847
+ interface QuerySpec extends WQLSpec {
848
+ /**
849
+ * Supported paging type for this query API
850
+ * - 'cursor': Uses cursor-based pagination
851
+ * - 'offset': Uses offset-based pagination
852
+ */
853
+ paging: PagingType;
854
+ }
855
+
856
+ /**
857
+ * Complete query request for an entity type
858
+ * @template Entity The entity type being queried
859
+ * @template Spec The query specification type
860
+ * @example
861
+ * // Define a query type for products
862
+ * type QueryProducts = Query<Product, ProductQuerySpec>;
863
+ *
864
+ * // Create a query request with offset paging
865
+ * const query: QueryProducts = {
866
+ * filter: { price: { $gte: 10 } },
867
+ * sort: [{ fieldName: 'price', order: 'ASC' }],
868
+ * paging: { limit: 20, offset: 0 }
869
+ * };
870
+ *
871
+ * // Or with cursor paging (if spec.paging = 'cursor')
872
+ * const query: QueryProducts = {
873
+ * filter: { price: { $gte: 10 } },
874
+ * sort: [{ fieldName: 'price', order: 'ASC' }],
875
+ * cursorPaging: { limit: 20, cursor: "..." }
876
+ * };
877
+ */
878
+ type Query<Entity, Spec extends QuerySpec> = {
879
+ /**
880
+ * Filter object.
881
+ * Learn more about the [filter section](https://dev.wix.com/docs/rest/articles/getting-started/api-query-language#the-filter-section).
882
+ */
883
+ filter?: Filter<Entity, Spec>;
884
+ /**
885
+ * List of sort objects.
886
+ * Learn more about the [sort section](https://dev.wix.com/docs/rest/articles/getting-started/api-query-language#the-sort-section).
887
+ */
888
+ sort?: Sorting<Spec>[];
889
+ } & Partial<Paging<Spec>>;
890
+
891
+ 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
  };