@wix/sdk-types 1.13.13 → 1.13.15

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.
@@ -1,5 +1,5 @@
1
1
  import { MonitoringClient } from '@wix/monitoring-types';
2
- import { ConditionalExcept, EmptyObject, Simplify, Paths, SetRequiredDeep } from 'type-fest';
2
+ import { ConditionalExcept, EmptyObject, Simplify, Paths, SetRequiredDeep, JsonObject } from 'type-fest';
3
3
 
4
4
  interface BiLogger {
5
5
  log(params: LogParams, context?: LogOptions): Promise<any>;
@@ -366,4 +366,469 @@ type NonNullablePaths<T, K extends Paths<T>> = globalThis.SDKTypeMode extends {
366
366
  strict: true;
367
367
  } ? SetRequiredDeep<T, K> : T;
368
368
 
369
- 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 ServicePluginContract, ServicePluginDefinition, type ServicePluginMethodInput, type ServicePluginMethodMetadata };
369
+ /**
370
+ * Constant used to indicate all applicable operators for a field type
371
+ */
372
+ declare const ALL_APPLICABLE_OPERATORS: "*";
373
+ /**
374
+ * Operators available for string fields
375
+ */
376
+ type StringOperators = '$eq' | '$ne' | '$gt' | '$lt' | '$gte' | '$lte' | '$isEmpty' | '$exists' | '$in' | '$nin' | '$startsWith';
377
+ /**
378
+ * Operators available for number fields
379
+ */
380
+ type NumberOperators = '$eq' | '$ne' | '$gt' | '$lt' | '$gte' | '$lte' | '$exists' | '$in' | '$nin';
381
+ /**
382
+ * Operators available for boolean fields
383
+ */
384
+ type BooleanOperators = '$eq' | '$ne' | '$exists' | '$in' | '$nin';
385
+ /**
386
+ * Operators available for date fields
387
+ */
388
+ type DateOperators = '$eq' | '$ne' | '$gt' | '$lt' | '$gte' | '$lte' | '$exists' | '$in' | '$nin';
389
+ /**
390
+ * Operators available for object fields
391
+ */
392
+ type ObjectOperators = '$exists';
393
+ /**
394
+ * Base operators available for all array types
395
+ */
396
+ type ArrayBaseOperators = '$isEmpty' | '$exists';
397
+ /**
398
+ * Operators available for arrays of primitive values
399
+ */
400
+ type ArrayOfPrimitivesOperators = '$hasAll' | '$hasSome' | ArrayBaseOperators;
401
+ /**
402
+ * Operators available for arrays of objects
403
+ */
404
+ type ArrayOfObjectsOperators = ArrayBaseOperators | '$matchItems';
405
+ type OperatorsWithBooleanValues = '$isEmpty' | '$exists';
406
+ type OperatorsWithArrayValues = '$in' | '$nin' | '$hasAll' | '$hasSome';
407
+ type OperatorForArrayFiltering = '$matchItems';
408
+
409
+ /**
410
+ * Cursor-based paging configuration
411
+ */
412
+ interface CursorPaging {
413
+ /** Maximum number of items to return in the results (0-100) */
414
+ limit?: number | null;
415
+ /**
416
+ * Pointer to the next or previous page in the results
417
+ * Pass the cursor token from the pagingMetadata of the previous response
418
+ */
419
+ cursor?: string | null;
420
+ }
421
+ /**
422
+ * Offset-based paging configuration
423
+ */
424
+ interface OffsetPaging {
425
+ /** Number of items to load */
426
+ limit?: number | null;
427
+ /** Number of items to skip in the current sort order */
428
+ offset?: number | null;
429
+ }
430
+ /**
431
+ * Supported paging types for search APIs
432
+ */
433
+ type PagingType = 'cursor' | 'offset';
434
+ /**
435
+ * Paging type based on the SearchSpec's paging type
436
+ */
437
+ type Paging<Spec extends {
438
+ paging?: PagingType;
439
+ }> = Spec['paging'] extends 'cursor' ? {
440
+ cursorPaging: CursorPaging;
441
+ } : Spec['paging'] extends 'offset' ? {
442
+ paging: OffsetPaging;
443
+ } : {};
444
+
445
+ /**
446
+ * Sort direction type for requests
447
+ */
448
+ type SortOrder = 'ASC' | 'DESC';
449
+ /**
450
+ * Sort capability type for defining field sort options in SearchSpec
451
+ */
452
+ type SortCapability = SortOrder | 'BOTH';
453
+ /**
454
+ * Constants for sort directions
455
+ */
456
+ declare const SORT_DIRECTIONS: {
457
+ readonly ASC: "ASC";
458
+ readonly DESC: "DESC";
459
+ };
460
+ /**
461
+ * Constants for sort capabilities
462
+ */
463
+ declare const SORT_CAPABILITIES: {
464
+ readonly BOTH: "BOTH";
465
+ readonly ASC: "ASC";
466
+ readonly DESC: "DESC";
467
+ };
468
+ /**
469
+ * Helper type to get the fields from a WQL group
470
+ * @template WQLGroup The WQL group type
471
+ */
472
+ type WQLFields<WQLGroup> = WQLGroup extends {
473
+ fields: readonly string[];
474
+ } ? WQLGroup['fields'][number] : never;
475
+ /**
476
+ * Sorting configuration for search results
477
+ * @template Spec The search specification type
478
+ */
479
+ type Sorting<Spec extends SearchSpec> = Spec['wql'] extends {
480
+ length: 0;
481
+ } | [] ? {
482
+ fieldName?: string;
483
+ order?: SortOrder;
484
+ selectItemsBy?: Record<string, any>[] | null;
485
+ } : {
486
+ [WQLGroupIndex in keyof Spec['wql']]: Spec['wql'][WQLGroupIndex] extends {
487
+ fields: readonly string[];
488
+ sort: infer GroupSortCapability;
489
+ } ? GroupSortCapability extends typeof SORT_DIRECTIONS.ASC ? {
490
+ fieldName: WQLFields<Spec['wql'][WQLGroupIndex]>;
491
+ order: typeof SORT_DIRECTIONS.ASC;
492
+ selectItemsBy?: Record<string, any>[] | null;
493
+ } : GroupSortCapability extends typeof SORT_DIRECTIONS.DESC ? {
494
+ fieldName: WQLFields<Spec['wql'][WQLGroupIndex]>;
495
+ order: typeof SORT_DIRECTIONS.DESC;
496
+ selectItemsBy?: Record<string, any>[] | null;
497
+ } : GroupSortCapability extends typeof SORT_CAPABILITIES.BOTH ? {
498
+ fieldName: WQLFields<Spec['wql'][WQLGroupIndex]>;
499
+ order: SortOrder;
500
+ selectItemsBy?: Record<string, any>[] | null;
501
+ } : never : never;
502
+ }[keyof Spec['wql']];
503
+
504
+ /**
505
+ * Defines a group of fields that share the same operator and sorting capabilities
506
+ * This is part of the Wix Query Language (WQL) specification
507
+ * @example
508
+ * const wql: WQL = {
509
+ * operators: ['$eq', '$ne', '$startsWith'],
510
+ * fields: ['name', 'description'],
511
+ * sort: 'BOTH'
512
+ * };
513
+ */
514
+ interface WQL {
515
+ /**
516
+ * List of operators that can be used with these fields
517
+ * If not specified, uses ALL_APPLICABLE_OPERATORS
518
+ */
519
+ operators?: typeof ALL_APPLICABLE_OPERATORS | readonly string[];
520
+ /**
521
+ * List of fields that share these operator capabilities
522
+ * These fields can be used in filters and sorting
523
+ */
524
+ fields: readonly string[];
525
+ /**
526
+ * Sort capabilities for fields in this group
527
+ * If omitted, sorting is not allowed for these fields
528
+ */
529
+ sort?: SortCapability;
530
+ }
531
+
532
+ /**
533
+ * Specification for a search API
534
+ * Defines what fields can be filtered, sorted, searched, and aggregated
535
+ * @example
536
+ * interface MySearchSpec extends SearchSpec {
537
+ * wql: [{
538
+ * operators: ['$eq', '$ne'], // or 'typeof ALL_APPLICABLE_OPERATORS' for all operators that can be used based on the field type
539
+ * fields: ['id', 'title'],
540
+ * sort: 'BOTH' // or 'ASC' / 'DESC' for specific sorting
541
+ * }],
542
+ * paging: 'offset', // or 'cursor' for cursor-based pagination
543
+ * searchable: ['title', 'description'],
544
+ * aggregatable: ['category', 'price']
545
+ * };
546
+ */
547
+ interface SearchSpec {
548
+ /**
549
+ * Groups of fields with shared operator and sorting capabilities
550
+ * Each group defines what operations can be performed on its fields
551
+ */
552
+ wql: readonly WQL[];
553
+ /**
554
+ * Supported paging type for this search API
555
+ * - 'cursor': Uses cursor-based pagination
556
+ * - 'offset': Uses offset-based pagination
557
+ */
558
+ paging: PagingType;
559
+ /**
560
+ * Fields that can be used for full-text search
561
+ * If not specified, all fields are searchable
562
+ */
563
+ searchable?: readonly string[];
564
+ /**
565
+ * Fields that can be used for aggregations
566
+ * These fields must be searchable and not contain PII
567
+ */
568
+ aggregatable?: readonly string[];
569
+ }
570
+
571
+ /**
572
+ * Gets the type of a field at a nested path
573
+ */
574
+ 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;
575
+ /**
576
+ * Extracts all filterable field paths from a search spec
577
+ * @template Spec The search specification type
578
+ * // Results in a union type of all field paths that can be filtered
579
+ */
580
+ type FilterableFields<Spec extends SearchSpec> = Spec['wql'][number]['fields'][number];
581
+ /**
582
+ * Extracts all searchable field paths from a search spec
583
+ * @template Spec The search specification type
584
+ * // Results in a union type of all field paths that can be searched
585
+ */
586
+ type SearchableFields<Spec extends SearchSpec> = Spec extends {
587
+ searchable: readonly string[];
588
+ } ? Spec['searchable'][number] : string;
589
+
590
+ /**
591
+ * Determines operators applicable to a field based on its type
592
+ * @template Entity The entity type
593
+ * @template Path The field path to check
594
+ */
595
+ type ApplicableOperators<Entity, Path extends string> = Path extends keyof Entity ? Entity[Path] extends string | null | undefined ? 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;
596
+ /**
597
+ * Determines allowed operators for a field based on the search spec
598
+ * @template Entity The entity type
599
+ * @template Spec The search specification type
600
+ * @template Field The field to check
601
+ */
602
+ 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;
603
+ /**
604
+ * Filter operations type for individual field conditions
605
+ * @template Entity The entity type
606
+ * @template Spec The search specification type
607
+ * @template Field The field to filter on
608
+ */
609
+ type FilterOps<Entity, Spec extends SearchSpec, Field extends FilterableFields<Spec>> = Simplify<{
610
+ [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>;
611
+ }>;
612
+ /**
613
+ * Filter type for building type-safe query filters
614
+ * @template Entity The entity type
615
+ * @template Spec The search specification type
616
+ * @example
617
+ * // Simple filter
618
+ * const filter: Filter<Product, ProductSpec> = {
619
+ * name: { $eq: 'iPhone' },
620
+ * price: { $gte: 100 }
621
+ * };
622
+ *
623
+ * // Complex filter with logical operators
624
+ * const filter: Filter<Product, ProductSpec> = {
625
+ * $and: [
626
+ * { name: { $startsWith: 'i' } },
627
+ * { $or: [
628
+ * { price: { $lt: 1000 } },
629
+ * { onSale: { $eq: true } }
630
+ * ]}
631
+ * ]
632
+ * };
633
+ */
634
+ type Filter<Entity, Spec extends SearchSpec> = Simplify<{
635
+ [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;
636
+ } | {
637
+ $and?: Filter<Entity, Spec>[];
638
+ $or?: Filter<Entity, Spec>[];
639
+ $not?: Filter<Entity, Spec>;
640
+ }>;
641
+
642
+ /**
643
+ * Type of scalar aggregation to perform
644
+ */
645
+ type ScalarType = 'COUNT_DISTINCT' | 'MIN' | 'MAX' | 'SUM' | 'AVG';
646
+ /**
647
+ * Sort type for value aggregations
648
+ */
649
+ type ValueSortType = 'COUNT' | 'VALUE';
650
+ /**
651
+ * Sort direction for value aggregations
652
+ */
653
+ type ValueSortDirection = 'DESC' | 'ASC';
654
+ /**
655
+ * Missing values handling for value aggregations
656
+ */
657
+ type MissingValues = 'EXCLUDE' | 'INCLUDE';
658
+ /**
659
+ * Date histogram interval
660
+ */
661
+ type DateHistogramInterval = 'YEAR' | 'MONTH' | 'WEEK' | 'DAY' | 'HOUR' | 'MINUTE' | 'SECOND';
662
+ /**
663
+ * Range bucket for range aggregations
664
+ */
665
+ interface RangeBucket {
666
+ from?: number | null;
667
+ to?: number | null;
668
+ }
669
+ /**
670
+ * Value aggregation configuration
671
+ */
672
+ interface ValueAggregation {
673
+ sortType?: ValueSortType;
674
+ sortDirection?: ValueSortDirection;
675
+ limit?: number | null;
676
+ missingValues?: MissingValues;
677
+ includeOptions?: {
678
+ addToBucket?: string;
679
+ };
680
+ }
681
+ /**
682
+ * Range aggregation configuration
683
+ */
684
+ interface RangeAggregation {
685
+ buckets?: RangeBucket[];
686
+ }
687
+ /**
688
+ * Scalar aggregation configuration
689
+ */
690
+ interface ScalarAggregation {
691
+ type?: ScalarType;
692
+ }
693
+ /**
694
+ * Date histogram aggregation configuration
695
+ */
696
+ interface DateHistogramAggregation {
697
+ interval?: DateHistogramInterval;
698
+ }
699
+ /**
700
+ * Base aggregation type that can be used for both top-level and nested aggregations
701
+ */
702
+ type BaseAggregation<Spec extends SearchSpec> = {
703
+ name?: string | null;
704
+ fieldPath?: AggregatableFields<Spec>;
705
+ } & ({
706
+ type?: 'VALUE';
707
+ value?: ValueAggregation;
708
+ } | {
709
+ type?: 'RANGE';
710
+ range?: RangeAggregation;
711
+ } | {
712
+ type?: 'SCALAR';
713
+ scalar?: ScalarAggregation;
714
+ } | {
715
+ type?: 'DATE_HISTOGRAM';
716
+ dateHistogram?: DateHistogramAggregation;
717
+ });
718
+ /**
719
+ * Nested aggregation item
720
+ */
721
+ type NestedAggregationItem<Spec extends SearchSpec> = BaseAggregation<Spec>;
722
+ /**
723
+ * Nested aggregation configuration
724
+ */
725
+ interface NestedAggregation<Spec extends SearchSpec> {
726
+ nestedAggregations?: NestedAggregationItem<Spec>[];
727
+ }
728
+ /**
729
+ * Extracts all aggregatable field paths from a search spec
730
+ * @template Spec The search specification type
731
+ */
732
+ type AggregatableFields<Spec extends SearchSpec> = Spec extends {
733
+ aggregatable: readonly string[];
734
+ } ? Spec['aggregatable'][number] : string;
735
+ /**
736
+ * Base aggregation interface
737
+ * @template Spec The search specification type
738
+ */
739
+ type Aggregation<Spec extends SearchSpec> = BaseAggregation<Spec> | {
740
+ type?: 'NESTED';
741
+ fieldPath?: AggregatableFields<Spec>;
742
+ nested?: NestedAggregation<Spec>;
743
+ };
744
+
745
+ /**
746
+ * Configuration for full-text search functionality
747
+ * @template Spec The search specification type
748
+ * @example
749
+ * const search: SearchDetails<MySearchSpec> = {
750
+ * expression: 'urgent task',
751
+ * mode: 'AND',
752
+ * fields: ['title', 'description'],
753
+ * fuzzy: true
754
+ * };
755
+ */
756
+ interface SearchDetails<Spec extends SearchSpec> {
757
+ /**
758
+ * The search query text
759
+ * @example 'urgent task'
760
+ */
761
+ expression?: string | null;
762
+ /**
763
+ * How to combine multiple search terms
764
+ * - 'AND': All terms must match
765
+ * - 'OR': Any term can match
766
+ */
767
+ mode?: 'AND' | 'OR';
768
+ /**
769
+ * Fields to search within
770
+ * If not specified, searches all searchable fields
771
+ */
772
+ fields?: SearchableFields<Spec>[];
773
+ /**
774
+ * Whether to enable fuzzy matching
775
+ * Fuzzy matching allows for approximate matches
776
+ */
777
+ fuzzy?: boolean;
778
+ }
779
+ /**
780
+ * Base search request without paging
781
+ * @template Entity The entity type being searched
782
+ * @template Spec The search specification type
783
+ */
784
+ type BaseSearch<Entity, Spec extends SearchSpec> = {
785
+ /**
786
+ * Filter conditions for the search
787
+ * @example { status: { $eq: 'PUBLISHED' } }
788
+ */
789
+ filter?: Filter<Entity, Spec>;
790
+ /**
791
+ * Sorting options for the results
792
+ * @example [{ fieldName: 'createdAt', order: 'DESC' }]
793
+ */
794
+ sort?: Sorting<Spec>[];
795
+ /**
796
+ * Full-text search configuration
797
+ * @example { expression: 'urgent', mode: 'AND' }
798
+ */
799
+ search?: SearchDetails<Spec>;
800
+ /**
801
+ * Aggregations for data analysis
802
+ * Aggregations provide summaries about data partitions
803
+ */
804
+ aggregations?: Aggregation<Spec>[];
805
+ /**
806
+ * Timezone for date-related queries
807
+ * Affects how date fields are interpreted
808
+ */
809
+ timeZone?: string | null;
810
+ };
811
+ /**
812
+ * Complete search request for an entity type
813
+ * @template Entity The entity type being searched
814
+ * @template Spec The search specification type
815
+ * @example
816
+ * // Define a search type for products
817
+ * type SearchProducts = Search<Product, ProductSearchSpec>;
818
+ *
819
+ * // Create a search request
820
+ * const search: SearchProducts = {
821
+ * filter: { price: { $gte: 10 } },
822
+ * sort: [{ fieldName: 'price', order: 'ASC' }],
823
+ * search: { expression: 'shirt', mode: 'AND' },
824
+ *
825
+ * // For offset paging:
826
+ * paging: { limit: 20, offset: 0 }
827
+ *
828
+ * // For cursor paging:
829
+ * cursorPaging: { limit: 20, cursor: "..." }
830
+ * };
831
+ */
832
+ type Search<Entity, Spec extends SearchSpec> = BaseSearch<Entity, Spec> & Partial<Paging<Spec>>;
833
+
834
+ 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 };