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