@wix/sdk-types 1.13.14 → 1.13.16

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