@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.
package/build/index.js CHANGED
@@ -22,6 +22,8 @@ var src_exports = {};
22
22
  __export(src_exports, {
23
23
  EventDefinition: () => EventDefinition,
24
24
  SERVICE_PLUGIN_ERROR_TYPE: () => SERVICE_PLUGIN_ERROR_TYPE,
25
+ SORT_CAPABILITIES: () => SORT_CAPABILITIES,
26
+ SORT_DIRECTIONS: () => SORT_DIRECTIONS,
25
27
  ServicePluginDefinition: () => ServicePluginDefinition
26
28
  });
27
29
  module.exports = __toCommonJS(src_exports);
@@ -45,9 +47,22 @@ function ServicePluginDefinition(componentType, methods) {
45
47
  };
46
48
  }
47
49
  var SERVICE_PLUGIN_ERROR_TYPE = "wix_spi_error";
50
+
51
+ // src/common/sort.ts
52
+ var SORT_DIRECTIONS = {
53
+ ASC: "ASC",
54
+ DESC: "DESC"
55
+ };
56
+ var SORT_CAPABILITIES = {
57
+ ...SORT_DIRECTIONS,
58
+ BOTH: "BOTH",
59
+ NONE: "NONE"
60
+ };
48
61
  // Annotate the CommonJS export names for ESM import in node:
49
62
  0 && (module.exports = {
50
63
  EventDefinition,
51
64
  SERVICE_PLUGIN_ERROR_TYPE,
65
+ SORT_CAPABILITIES,
66
+ SORT_DIRECTIONS,
52
67
  ServicePluginDefinition
53
68
  });
package/build/index.mjs CHANGED
@@ -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
  };
@@ -116,6 +116,13 @@ type Host<Environment = unknown> = {
116
116
  */
117
117
  passThroughHeaders?: Record<string, string>;
118
118
  };
119
+ translations?: () => {
120
+ [language: string]: {
121
+ [namespace: string]: {
122
+ [key: string]: string;
123
+ };
124
+ };
125
+ } | undefined;
119
126
  };
120
127
 
121
128
  type HTTPMethod = 'POST' | 'GET' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS';
@@ -432,44 +439,6 @@ type OperatorsWithBooleanValues = '$isEmpty' | '$exists';
432
439
  type OperatorsWithArrayValues = '$in' | '$nin' | '$hasAll' | '$hasSome';
433
440
  type OperatorForArrayFiltering = '$matchItems';
434
441
 
435
- /**
436
- * Cursor-based paging configuration
437
- */
438
- interface CursorPaging {
439
- /** Maximum number of items to return in the results. */
440
- limit?: number | null;
441
- /**
442
- * Pointer to the next or previous page in the list of results.
443
- *
444
- * Pass the relevant cursor token from the `pagingMetadata` object in the previous call's response.
445
- * Not relevant for the first request.
446
- */
447
- cursor?: string | null;
448
- }
449
- /**
450
- * Offset-based paging configuration
451
- */
452
- interface OffsetPaging {
453
- /** Number of items to load */
454
- limit?: number | null;
455
- /** Number of items to skip in the current sort order */
456
- offset?: number | null;
457
- }
458
- /**
459
- * Supported paging types for search APIs
460
- */
461
- type PagingType = 'cursor' | 'offset';
462
- /**
463
- * Paging type based on the SearchSpec's paging type
464
- */
465
- type Paging<Spec extends {
466
- paging?: PagingType;
467
- }> = Spec['paging'] extends 'cursor' ? {
468
- cursorPaging: CursorPaging;
469
- } : Spec['paging'] extends 'offset' ? {
470
- paging: OffsetPaging;
471
- } : {};
472
-
473
442
  /**
474
443
  * Sort direction type for requests
475
444
  */
@@ -502,10 +471,10 @@ type WQLFields<WQLGroup> = WQLGroup extends {
502
471
  fields: readonly string[];
503
472
  } ? WQLGroup['fields'][number] : never;
504
473
  /**
505
- * Sorting configuration for search results
506
- * @template Spec The search specification type
474
+ * Sorting configuration for search/query results
475
+ * @template Spec The WQL specification type
507
476
  */
508
- type Sorting<Spec extends SearchSpec> = Spec['wql'] extends {
477
+ type Sorting<Spec extends WQLSpec> = Spec['wql'] extends {
509
478
  length: 0;
510
479
  } | [] ? {
511
480
  fieldName?: string;
@@ -563,42 +532,14 @@ interface WQL {
563
532
  }
564
533
 
565
534
  /**
566
- * Specification for a search API
567
- * Defines what fields can be filtered, sorted, searched, and aggregated
568
- * @example
569
- * interface MySearchSpec extends SearchSpec {
570
- * wql: [{
571
- * operators: ['$eq', '$ne'], // or 'typeof ALL_APPLICABLE_OPERATORS' for all operators that can be used based on the field type
572
- * fields: ['id', 'title'],
573
- * sort: 'BOTH' // or 'ASC' / 'DESC' for specific sorting
574
- * }],
575
- * paging: 'offset', // or 'cursor' for cursor-based pagination
576
- * searchable: ['title', 'description'],
577
- * aggregatable: ['category', 'price']
578
- * };
535
+ * Base specification interface for APIs that support WQL (Wix Query Language)
579
536
  */
580
- interface SearchSpec {
537
+ interface WQLSpec {
581
538
  /**
582
539
  * Groups of fields with shared operator and sorting capabilities
583
540
  * Each group defines what operations can be performed on its fields
584
541
  */
585
542
  wql: readonly WQL[];
586
- /**
587
- * Supported paging type for this search API
588
- * - 'cursor': Uses cursor-based pagination
589
- * - 'offset': Uses offset-based pagination
590
- */
591
- paging: PagingType;
592
- /**
593
- * Fields that can be used for full-text search
594
- * If not specified, all fields are searchable
595
- */
596
- searchable?: readonly string[];
597
- /**
598
- * Fields that can be used for aggregations
599
- * These fields must be searchable and not contain PII
600
- */
601
- aggregatable?: readonly string[];
602
543
  }
603
544
 
604
545
  /**
@@ -606,19 +547,11 @@ interface SearchSpec {
606
547
  */
607
548
  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;
608
549
  /**
609
- * Extracts all filterable field paths from a search spec
610
- * @template Spec The search specification type
550
+ * Extracts all filterable field paths from a spec
551
+ * @template Spec The WQL specification type
611
552
  * // Results in a union type of all field paths that can be filtered
612
553
  */
613
- type FilterableFields<Spec extends SearchSpec> = Spec['wql'][number]['fields'][number];
614
- /**
615
- * Extracts all searchable field paths from a search spec
616
- * @template Spec The search specification type
617
- * // Results in a union type of all field paths that can be searched
618
- */
619
- type SearchableFields<Spec extends SearchSpec> = Spec extends {
620
- searchable: readonly string[];
621
- } ? Spec['searchable'][number] : string;
554
+ type FilterableFields<Spec extends WQLSpec> = Spec['wql'][number]['fields'][number];
622
555
 
623
556
  /**
624
557
  * Helper type to detect if a type is an enum-like union of string literals
@@ -633,25 +566,25 @@ type IsEnumLike<T> = T extends string | null | undefined ? string extends NonNul
633
566
  */
634
567
  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;
635
568
  /**
636
- * Determines allowed operators for a field based on the search spec
569
+ * Determines allowed operators for a field based on the spec
637
570
  * @template Entity The entity type
638
- * @template Spec The search specification type
571
+ * @template Spec The WQL specification type
639
572
  * @template Field The field to check
640
573
  */
641
- 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;
574
+ 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;
642
575
  /**
643
576
  * Filter operations type for individual field conditions
644
577
  * @template Entity The entity type
645
- * @template Spec The search specification type
578
+ * @template Spec The WQL specification type
646
579
  * @template Field The field to filter on
647
580
  */
648
- type FilterOps<Entity, Spec extends SearchSpec, Field extends FilterableFields<Spec>> = Simplify<{
581
+ type FilterOps<Entity, Spec extends WQLSpec, Field extends FilterableFields<Spec>> = Simplify<{
649
582
  [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>;
650
583
  }>;
651
584
  /**
652
585
  * Filter type for building type-safe query filters
653
586
  * @template Entity The entity type
654
- * @template Spec The search specification type
587
+ * @template Spec The WQL specification type
655
588
  * @example
656
589
  * // Simple filter
657
590
  * const filter: Filter<Product, ProductSpec> = {
@@ -670,7 +603,7 @@ type FilterOps<Entity, Spec extends SearchSpec, Field extends FilterableFields<S
670
603
  * ]
671
604
  * };
672
605
  */
673
- type Filter<Entity, Spec extends SearchSpec> = Simplify<{
606
+ type Filter<Entity, Spec extends WQLSpec> = Simplify<{
674
607
  [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;
675
608
  } | {
676
609
  $and?: Filter<Entity, Spec>[];
@@ -678,6 +611,78 @@ type Filter<Entity, Spec extends SearchSpec> = Simplify<{
678
611
  $not?: Filter<Entity, Spec>;
679
612
  }>;
680
613
 
614
+ /**
615
+ * Cursor-based paging configuration
616
+ */
617
+ interface CursorPaging {
618
+ /** Maximum number of items to return in the results. */
619
+ limit?: number | null;
620
+ /**
621
+ * Pointer to the next or previous page in the list of results.
622
+ *
623
+ * Pass the relevant cursor token from the `pagingMetadata` object in the previous call's response.
624
+ * Not relevant for the first request.
625
+ */
626
+ cursor?: string | null;
627
+ }
628
+ /**
629
+ * Offset-based paging configuration
630
+ */
631
+ interface OffsetPaging {
632
+ /** Number of items to load */
633
+ limit?: number | null;
634
+ /** Number of items to skip in the current sort order */
635
+ offset?: number | null;
636
+ }
637
+ /**
638
+ * Supported paging types for search APIs
639
+ */
640
+ type PagingType = 'cursor' | 'offset';
641
+ /**
642
+ * Paging type based on the SearchSpec's paging type
643
+ */
644
+ type Paging<Spec extends {
645
+ paging?: PagingType;
646
+ }> = Spec['paging'] extends 'cursor' ? {
647
+ cursorPaging: CursorPaging;
648
+ } : Spec['paging'] extends 'offset' ? {
649
+ paging: OffsetPaging;
650
+ } : {};
651
+
652
+ /**
653
+ * Specification for a search API
654
+ * Defines what fields can be filtered, sorted, searched, and aggregated
655
+ * @example
656
+ * interface MySearchSpec extends SearchSpec {
657
+ * wql: [{
658
+ * operators: ['$eq', '$ne'], // or 'typeof ALL_APPLICABLE_OPERATORS' for all operators that can be used based on the field type
659
+ * fields: ['id', 'title'],
660
+ * sort: 'BOTH' // or 'ASC' / 'DESC' for specific sorting
661
+ * }],
662
+ * paging: 'offset', // or 'cursor' for cursor-based pagination
663
+ * searchable: ['title', 'description'],
664
+ * aggregatable: ['category', 'price']
665
+ * };
666
+ */
667
+ interface SearchSpec extends WQLSpec {
668
+ /**
669
+ * Supported paging type for this search API
670
+ * - 'cursor': Uses cursor-based pagination
671
+ * - 'offset': Uses offset-based pagination
672
+ */
673
+ paging: PagingType;
674
+ /**
675
+ * Fields that can be used for full-text search
676
+ * If not specified, all fields are searchable
677
+ */
678
+ searchable?: readonly string[];
679
+ /**
680
+ * Fields that can be used for aggregations
681
+ * These fields must be searchable and not contain PII
682
+ */
683
+ aggregatable?: readonly string[];
684
+ }
685
+
681
686
  /**
682
687
  * Type of scalar aggregation to perform
683
688
  */
@@ -785,6 +790,15 @@ type Aggregation<Spec extends SearchSpec> = BaseAggregationWithoutType<Spec> & {
785
790
  nested?: NestedAggregation<Spec>;
786
791
  };
787
792
 
793
+ /**
794
+ * Extracts all searchable field paths from a search spec
795
+ * @template Spec The search specification type
796
+ * // Results in a union type of all field paths that can be searched
797
+ */
798
+ type SearchableFields<Spec extends SearchSpec> = Spec extends {
799
+ searchable: readonly string[];
800
+ } ? Spec['searchable'][number] : string;
801
+
788
802
  /**
789
803
  * Configuration for full-text search functionality
790
804
  * @template Spec The search specification type
@@ -875,4 +889,61 @@ type BaseSearch<Entity, Spec extends SearchSpec> = {
875
889
  */
876
890
  type Search<Entity, Spec extends SearchSpec> = BaseSearch<Entity, Spec> & Partial<Paging<Spec>>;
877
891
 
878
- 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 };
892
+ /**
893
+ * Specification for a query API
894
+ * Defines what fields can be filtered and sorted
895
+ * @example
896
+ * interface MyQuerySpec extends QuerySpec {
897
+ * wql: [{
898
+ * operators: ['$eq', '$ne'],
899
+ * fields: ['id', 'title'],
900
+ * sort: 'BOTH'
901
+ * }],
902
+ * paging: 'offset', // or 'cursor' for cursor-based pagination
903
+ * };
904
+ */
905
+ interface QuerySpec extends WQLSpec {
906
+ /**
907
+ * Supported paging type for this query API
908
+ * - 'cursor': Uses cursor-based pagination
909
+ * - 'offset': Uses offset-based pagination
910
+ */
911
+ paging: PagingType;
912
+ }
913
+
914
+ /**
915
+ * Complete query request for an entity type
916
+ * @template Entity The entity type being queried
917
+ * @template Spec The query specification type
918
+ * @example
919
+ * // Define a query type for products
920
+ * type QueryProducts = Query<Product, ProductQuerySpec>;
921
+ *
922
+ * // Create a query request with offset paging
923
+ * const query: QueryProducts = {
924
+ * filter: { price: { $gte: 10 } },
925
+ * sort: [{ fieldName: 'price', order: 'ASC' }],
926
+ * paging: { limit: 20, offset: 0 }
927
+ * };
928
+ *
929
+ * // Or with cursor paging (if spec.paging = 'cursor')
930
+ * const query: QueryProducts = {
931
+ * filter: { price: { $gte: 10 } },
932
+ * sort: [{ fieldName: 'price', order: 'ASC' }],
933
+ * cursorPaging: { limit: 20, cursor: "..." }
934
+ * };
935
+ */
936
+ type Query<Entity, Spec extends QuerySpec> = {
937
+ /**
938
+ * Filter object.
939
+ * Learn more about the [filter section](https://dev.wix.com/docs/rest/articles/getting-started/api-query-language#the-filter-section).
940
+ */
941
+ filter?: Filter<Entity, Spec>;
942
+ /**
943
+ * List of sort objects.
944
+ * Learn more about the [sort section](https://dev.wix.com/docs/rest/articles/getting-started/api-query-language#the-sort-section).
945
+ */
946
+ sort?: Sorting<Spec>[];
947
+ } & Partial<Paging<Spec>>;
948
+
949
+ 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
  };