@wix/sdk-types 1.17.1 → 1.17.3

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.
@@ -155,9 +155,15 @@ type EventIdentity = {
155
155
  wixUserId: string;
156
156
  appId: string;
157
157
  };
158
+ type AccountInfo = {
159
+ accountId: string;
160
+ parentAccountId?: string;
161
+ siteId?: string;
162
+ };
158
163
  type BaseEventMetadata = {
159
164
  instanceId: string;
160
165
  identity?: EventIdentity;
166
+ accountInfo?: AccountInfo;
161
167
  };
162
168
  type EventDefinition<Payload = unknown, Type extends string = string> = {
163
169
  __type: 'event-definition';
@@ -556,7 +562,7 @@ type Filter<Entity, Spec extends WQLSpec> = Simplify<{
556
562
  /**
557
563
  * Cursor-based paging configuration
558
564
  */
559
- interface CursorPaging {
565
+ interface CursorPaging$1 {
560
566
  /** Maximum number of items to return in the results. */
561
567
  limit?: number | null;
562
568
  /**
@@ -570,7 +576,7 @@ interface CursorPaging {
570
576
  /**
571
577
  * Offset-based paging configuration
572
578
  */
573
- interface OffsetPaging {
579
+ interface OffsetPaging$1 {
574
580
  /** Number of items to load */
575
581
  limit?: number | null;
576
582
  /** Number of items to skip in the current sort order */
@@ -586,9 +592,9 @@ type PagingType = 'cursor' | 'offset';
586
592
  type Paging<Spec extends {
587
593
  paging?: PagingType;
588
594
  }> = Spec['paging'] extends 'cursor' ? {
589
- cursorPaging: CursorPaging;
595
+ cursorPaging: CursorPaging$1;
590
596
  } : Spec['paging'] extends 'offset' ? {
591
- paging: OffsetPaging;
597
+ paging: OffsetPaging$1;
592
598
  } : {};
593
599
 
594
600
  /**
@@ -888,4 +894,173 @@ type Query<Entity, Spec extends QuerySpec> = {
888
894
  sort?: Sorting<Spec>[];
889
895
  } & Partial<Paging<Spec>>;
890
896
 
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 };
897
+ interface CursorPaging {
898
+ limit: number;
899
+ cursor?: string;
900
+ }
901
+ interface OffsetPaging {
902
+ limit: number;
903
+ offset?: number;
904
+ }
905
+ type PagingFor<S extends QuerySpec> = S['paging'] extends 'cursor' ? CursorPaging : OffsetPaging;
906
+ /**
907
+ * The output type from QueryBuilder.build()
908
+ * This is a plain object ready to be sent to an API
909
+ */
910
+ interface QueryRequest<T, S extends QuerySpec> {
911
+ filter?: Filter<T, S>;
912
+ sort?: Sorting<S>[];
913
+ paging?: PagingFor<S>;
914
+ /** Field projection - return only specified fields */
915
+ fields?: string[];
916
+ }
917
+ /**
918
+ * Represents a filter expression that can be combined with other filters
919
+ */
920
+ interface FilterExpression<T, S extends QuerySpec> {
921
+ readonly filter: Filter<T, S>;
922
+ }
923
+ /**
924
+ * Represents a sort expression
925
+ */
926
+ interface SortExpression<S extends QuerySpec> {
927
+ readonly sort: Sorting<S>;
928
+ }
929
+ /**
930
+ * Extract fields that support a specific operator from the spec
931
+ */
932
+ type FieldsWithOperator<S extends QuerySpec, Op extends string> = S['wql'][number] extends infer Group ? Group extends WQL ? Group['operators'] extends readonly string[] ? Op extends Group['operators'][number] ? Group['fields'][number] : never : Group['fields'][number] : never : never;
933
+ /**
934
+ * Check if a specific field supports a specific operator
935
+ */
936
+ type HasOperator<S extends QuerySpec, Field extends string, Op extends string> = Field extends FieldsWithOperator<S, Op> ? true : false;
937
+ /**
938
+ * Extract sortable fields from the spec
939
+ */
940
+ type SortableFields<S extends QuerySpec> = S['wql'][number] extends infer Group ? Group extends {
941
+ fields: readonly string[];
942
+ sort: 'ASC' | 'DESC' | 'BOTH';
943
+ } ? Group['fields'][number] : never : never;
944
+ /**
945
+ * Chainable field filter - extends FilterExpression so it can be used directly,
946
+ * but also allows chaining multiple operators on the same field.
947
+ * @example
948
+ * // Single operator - returns ChainableFieldFilter which is also FilterExpression
949
+ * Filter('price').gt(50)
950
+ *
951
+ * // Chained operators - combines into single field filter
952
+ * Filter('price').gt(50).lt(100)
953
+ * // Produces: { price: { $gt: 50, $lt: 100 } }
954
+ */
955
+ type ChainableFieldFilter<T, S extends QuerySpec, Field extends FilterableFields<S>> = FilterExpression<T, S> & (HasOperator<S, Field & string, '$eq'> extends true ? {
956
+ eq(value: GetNestedType<T, Field & string>): ChainableFieldFilter<T, S, Field>;
957
+ } : {}) & (HasOperator<S, Field & string, '$ne'> extends true ? {
958
+ ne(value: GetNestedType<T, Field & string>): ChainableFieldFilter<T, S, Field>;
959
+ } : {}) & (HasOperator<S, Field & string, '$gt'> extends true ? {
960
+ gt(value: GetNestedType<T, Field & string>): ChainableFieldFilter<T, S, Field>;
961
+ } : {}) & (HasOperator<S, Field & string, '$gte'> extends true ? {
962
+ gte(value: GetNestedType<T, Field & string>): ChainableFieldFilter<T, S, Field>;
963
+ } : {}) & (HasOperator<S, Field & string, '$lt'> extends true ? {
964
+ lt(value: GetNestedType<T, Field & string>): ChainableFieldFilter<T, S, Field>;
965
+ } : {}) & (HasOperator<S, Field & string, '$lte'> extends true ? {
966
+ lte(value: GetNestedType<T, Field & string>): ChainableFieldFilter<T, S, Field>;
967
+ } : {}) & (HasOperator<S, Field & string, '$startsWith'> extends true ? {
968
+ startsWith(value: string): ChainableFieldFilter<T, S, Field>;
969
+ } : {}) & (HasOperator<S, Field & string, '$endsWith'> extends true ? {
970
+ endsWith(value: string): ChainableFieldFilter<T, S, Field>;
971
+ } : {}) & (HasOperator<S, Field & string, '$contains'> extends true ? {
972
+ contains(value: string): ChainableFieldFilter<T, S, Field>;
973
+ } : {}) & (HasOperator<S, Field & string, '$in'> extends true ? {
974
+ in(values: GetNestedType<T, Field & string>[]): ChainableFieldFilter<T, S, Field>;
975
+ } : {}) & (HasOperator<S, Field & string, '$nin'> extends true ? {
976
+ nin(values: GetNestedType<T, Field & string>[]): ChainableFieldFilter<T, S, Field>;
977
+ } : {}) & (HasOperator<S, Field & string, '$hasSome'> extends true ? {
978
+ hasSome(values: GetNestedType<T, Field & string>[]): ChainableFieldFilter<T, S, Field>;
979
+ } : {}) & (HasOperator<S, Field & string, '$hasAll'> extends true ? {
980
+ hasAll(values: GetNestedType<T, Field & string>[]): ChainableFieldFilter<T, S, Field>;
981
+ } : {}) & (HasOperator<S, Field & string, '$exists'> extends true ? {
982
+ exists(value?: boolean): ChainableFieldFilter<T, S, Field>;
983
+ } : {}) & (HasOperator<S, Field & string, '$isEmpty'> extends true ? {
984
+ isEmpty(value?: boolean): ChainableFieldFilter<T, S, Field>;
985
+ } : {}) & (HasOperator<S, Field & string, '$ne'> extends true ? {
986
+ isNotEmpty(): ChainableFieldFilter<T, S, Field>;
987
+ } : {});
988
+ /**
989
+ * Filter methods for a specific field (alias for ChainableFieldFilter)
990
+ * Only shows methods for operators that the field supports
991
+ */
992
+ type FieldFilter<T, S extends QuerySpec, Field extends FilterableFields<S>> = ChainableFieldFilter<T, S, Field>;
993
+ /**
994
+ * Sort methods for a specific field
995
+ */
996
+ interface FieldSort<S extends QuerySpec> {
997
+ asc(): SortExpression<S>;
998
+ desc(): SortExpression<S>;
999
+ }
1000
+ /**
1001
+ * Filter factory interface - creates filter expressions
1002
+ * @example
1003
+ * Filter('price').gt(50)
1004
+ * Filter.and(Filter('title').eq('Product'), Filter('price').gt(50))
1005
+ */
1006
+ interface FilterFactory<T, S extends QuerySpec> {
1007
+ /** Create a field-specific filter */
1008
+ <Field extends FilterableFields<S>>(field: Field): FieldFilter<T, S, Field>;
1009
+ /** Combine filters with AND logic */
1010
+ and(...filters: FilterExpression<T, S>[]): FilterExpression<T, S>;
1011
+ /** Combine filters with OR logic */
1012
+ or(...filters: FilterExpression<T, S>[]): FilterExpression<T, S>;
1013
+ /** Negate a filter */
1014
+ not(filter: FilterExpression<T, S>): FilterExpression<T, S>;
1015
+ }
1016
+ /**
1017
+ * Sort factory - creates sort expressions
1018
+ * @example
1019
+ * Sort('price').desc()
1020
+ */
1021
+ type SortFactory<S extends QuerySpec> = <Field extends SortableFields<S>>(field: Field) => FieldSort<S>;
1022
+ /**
1023
+ * Query builder interface
1024
+ * @template T - Entity type
1025
+ * @template S - Query spec defining filterable/sortable fields
1026
+ * @template R - Output type from build() (defaults to QueryRequest<T, S>)
1027
+ * @example
1028
+ * QueryBuilder()
1029
+ * .withFilter(Filter.and(
1030
+ * Filter('title').eq('Product'),
1031
+ * Filter('price').gt(50)
1032
+ * ))
1033
+ * .withFields('title', 'price')
1034
+ * .withSorting(Sort('price').desc())
1035
+ * .withPaging({ limit: 20, offset: 0 })
1036
+ * .build()
1037
+ */
1038
+ interface QueryBuilder<T, S extends QuerySpec, R = QueryRequest<T, S>> {
1039
+ /** Add a filter to the query */
1040
+ withFilter(filter: FilterExpression<T, S>): QueryBuilder<T, S, R>;
1041
+ /** Add field projection - return only specified fields */
1042
+ withFields(...fields: (keyof T & string)[]): QueryBuilder<T, S, R>;
1043
+ /** Add sorting to the query */
1044
+ withSorting(...sorts: SortExpression<S>[]): QueryBuilder<T, S, R>;
1045
+ /** Add paging to the query */
1046
+ withPaging(paging: PagingFor<S>): QueryBuilder<T, S, R>;
1047
+ /** Build the final query request object */
1048
+ build(): R;
1049
+ }
1050
+ /**
1051
+ * Complete set of query helpers for an entity
1052
+ * This is what gets spread into module namespaces
1053
+ * @template T - Entity type
1054
+ * @template S - Query spec defining filterable/sortable fields
1055
+ * @template R - Output type from QueryBuilder.build() (defaults to QueryRequest<T, S>)
1056
+ */
1057
+ interface QueryHelpers<T, S extends QuerySpec, R = QueryRequest<T, S>> {
1058
+ /** QueryBuilder factory */
1059
+ QueryBuilder: () => QueryBuilder<T, S, R>;
1060
+ /** Filter factory - creates filter expressions */
1061
+ Filter: FilterFactory<T, S>;
1062
+ /** Sort factory - creates sort expressions */
1063
+ Sort: SortFactory<S>;
1064
+ }
1065
+
1066
+ export { type APIMetadata, type AccountInfo, type AmbassadorFactory, type AmbassadorFunctionDescriptor, type AmbassadorRequestOptions, type AuthenticationStrategy, type BaseEventMetadata, type BoundAuthenticationStrategy, type BuildAmbassadorFunction, type BuildDescriptors, type BuildEventDefinition, type BuildRESTFunction, type BuildServicePluginDefinition, type CursorPaging, type Descriptors, EventDefinition, type EventHandler, type EventIdentity, type ExposeFieldsBasedOnToggle, type FieldFilter, type FieldSort, type Filter, type FilterExpression, type FilterFactory, 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 OffsetPaging, type PagingFor, type PublicMetadata, type Query, type QueryBuilder, type QueryHelpers, type QueryRequest, 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 SortExpression, type SortFactory, type SortOrder, type Sorting, type WQL, type WQLSpec };
package/build/index.d.mts CHANGED
@@ -155,9 +155,15 @@ type EventIdentity = {
155
155
  wixUserId: string;
156
156
  appId: string;
157
157
  };
158
+ type AccountInfo = {
159
+ accountId: string;
160
+ parentAccountId?: string;
161
+ siteId?: string;
162
+ };
158
163
  type BaseEventMetadata = {
159
164
  instanceId: string;
160
165
  identity?: EventIdentity;
166
+ accountInfo?: AccountInfo;
161
167
  };
162
168
  type EventDefinition<Payload = unknown, Type extends string = string> = {
163
169
  __type: 'event-definition';
@@ -556,7 +562,7 @@ type Filter<Entity, Spec extends WQLSpec> = Simplify<{
556
562
  /**
557
563
  * Cursor-based paging configuration
558
564
  */
559
- interface CursorPaging {
565
+ interface CursorPaging$1 {
560
566
  /** Maximum number of items to return in the results. */
561
567
  limit?: number | null;
562
568
  /**
@@ -570,7 +576,7 @@ interface CursorPaging {
570
576
  /**
571
577
  * Offset-based paging configuration
572
578
  */
573
- interface OffsetPaging {
579
+ interface OffsetPaging$1 {
574
580
  /** Number of items to load */
575
581
  limit?: number | null;
576
582
  /** Number of items to skip in the current sort order */
@@ -586,9 +592,9 @@ type PagingType = 'cursor' | 'offset';
586
592
  type Paging<Spec extends {
587
593
  paging?: PagingType;
588
594
  }> = Spec['paging'] extends 'cursor' ? {
589
- cursorPaging: CursorPaging;
595
+ cursorPaging: CursorPaging$1;
590
596
  } : Spec['paging'] extends 'offset' ? {
591
- paging: OffsetPaging;
597
+ paging: OffsetPaging$1;
592
598
  } : {};
593
599
 
594
600
  /**
@@ -888,4 +894,173 @@ type Query<Entity, Spec extends QuerySpec> = {
888
894
  sort?: Sorting<Spec>[];
889
895
  } & Partial<Paging<Spec>>;
890
896
 
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 };
897
+ interface CursorPaging {
898
+ limit: number;
899
+ cursor?: string;
900
+ }
901
+ interface OffsetPaging {
902
+ limit: number;
903
+ offset?: number;
904
+ }
905
+ type PagingFor<S extends QuerySpec> = S['paging'] extends 'cursor' ? CursorPaging : OffsetPaging;
906
+ /**
907
+ * The output type from QueryBuilder.build()
908
+ * This is a plain object ready to be sent to an API
909
+ */
910
+ interface QueryRequest<T, S extends QuerySpec> {
911
+ filter?: Filter<T, S>;
912
+ sort?: Sorting<S>[];
913
+ paging?: PagingFor<S>;
914
+ /** Field projection - return only specified fields */
915
+ fields?: string[];
916
+ }
917
+ /**
918
+ * Represents a filter expression that can be combined with other filters
919
+ */
920
+ interface FilterExpression<T, S extends QuerySpec> {
921
+ readonly filter: Filter<T, S>;
922
+ }
923
+ /**
924
+ * Represents a sort expression
925
+ */
926
+ interface SortExpression<S extends QuerySpec> {
927
+ readonly sort: Sorting<S>;
928
+ }
929
+ /**
930
+ * Extract fields that support a specific operator from the spec
931
+ */
932
+ type FieldsWithOperator<S extends QuerySpec, Op extends string> = S['wql'][number] extends infer Group ? Group extends WQL ? Group['operators'] extends readonly string[] ? Op extends Group['operators'][number] ? Group['fields'][number] : never : Group['fields'][number] : never : never;
933
+ /**
934
+ * Check if a specific field supports a specific operator
935
+ */
936
+ type HasOperator<S extends QuerySpec, Field extends string, Op extends string> = Field extends FieldsWithOperator<S, Op> ? true : false;
937
+ /**
938
+ * Extract sortable fields from the spec
939
+ */
940
+ type SortableFields<S extends QuerySpec> = S['wql'][number] extends infer Group ? Group extends {
941
+ fields: readonly string[];
942
+ sort: 'ASC' | 'DESC' | 'BOTH';
943
+ } ? Group['fields'][number] : never : never;
944
+ /**
945
+ * Chainable field filter - extends FilterExpression so it can be used directly,
946
+ * but also allows chaining multiple operators on the same field.
947
+ * @example
948
+ * // Single operator - returns ChainableFieldFilter which is also FilterExpression
949
+ * Filter('price').gt(50)
950
+ *
951
+ * // Chained operators - combines into single field filter
952
+ * Filter('price').gt(50).lt(100)
953
+ * // Produces: { price: { $gt: 50, $lt: 100 } }
954
+ */
955
+ type ChainableFieldFilter<T, S extends QuerySpec, Field extends FilterableFields<S>> = FilterExpression<T, S> & (HasOperator<S, Field & string, '$eq'> extends true ? {
956
+ eq(value: GetNestedType<T, Field & string>): ChainableFieldFilter<T, S, Field>;
957
+ } : {}) & (HasOperator<S, Field & string, '$ne'> extends true ? {
958
+ ne(value: GetNestedType<T, Field & string>): ChainableFieldFilter<T, S, Field>;
959
+ } : {}) & (HasOperator<S, Field & string, '$gt'> extends true ? {
960
+ gt(value: GetNestedType<T, Field & string>): ChainableFieldFilter<T, S, Field>;
961
+ } : {}) & (HasOperator<S, Field & string, '$gte'> extends true ? {
962
+ gte(value: GetNestedType<T, Field & string>): ChainableFieldFilter<T, S, Field>;
963
+ } : {}) & (HasOperator<S, Field & string, '$lt'> extends true ? {
964
+ lt(value: GetNestedType<T, Field & string>): ChainableFieldFilter<T, S, Field>;
965
+ } : {}) & (HasOperator<S, Field & string, '$lte'> extends true ? {
966
+ lte(value: GetNestedType<T, Field & string>): ChainableFieldFilter<T, S, Field>;
967
+ } : {}) & (HasOperator<S, Field & string, '$startsWith'> extends true ? {
968
+ startsWith(value: string): ChainableFieldFilter<T, S, Field>;
969
+ } : {}) & (HasOperator<S, Field & string, '$endsWith'> extends true ? {
970
+ endsWith(value: string): ChainableFieldFilter<T, S, Field>;
971
+ } : {}) & (HasOperator<S, Field & string, '$contains'> extends true ? {
972
+ contains(value: string): ChainableFieldFilter<T, S, Field>;
973
+ } : {}) & (HasOperator<S, Field & string, '$in'> extends true ? {
974
+ in(values: GetNestedType<T, Field & string>[]): ChainableFieldFilter<T, S, Field>;
975
+ } : {}) & (HasOperator<S, Field & string, '$nin'> extends true ? {
976
+ nin(values: GetNestedType<T, Field & string>[]): ChainableFieldFilter<T, S, Field>;
977
+ } : {}) & (HasOperator<S, Field & string, '$hasSome'> extends true ? {
978
+ hasSome(values: GetNestedType<T, Field & string>[]): ChainableFieldFilter<T, S, Field>;
979
+ } : {}) & (HasOperator<S, Field & string, '$hasAll'> extends true ? {
980
+ hasAll(values: GetNestedType<T, Field & string>[]): ChainableFieldFilter<T, S, Field>;
981
+ } : {}) & (HasOperator<S, Field & string, '$exists'> extends true ? {
982
+ exists(value?: boolean): ChainableFieldFilter<T, S, Field>;
983
+ } : {}) & (HasOperator<S, Field & string, '$isEmpty'> extends true ? {
984
+ isEmpty(value?: boolean): ChainableFieldFilter<T, S, Field>;
985
+ } : {}) & (HasOperator<S, Field & string, '$ne'> extends true ? {
986
+ isNotEmpty(): ChainableFieldFilter<T, S, Field>;
987
+ } : {});
988
+ /**
989
+ * Filter methods for a specific field (alias for ChainableFieldFilter)
990
+ * Only shows methods for operators that the field supports
991
+ */
992
+ type FieldFilter<T, S extends QuerySpec, Field extends FilterableFields<S>> = ChainableFieldFilter<T, S, Field>;
993
+ /**
994
+ * Sort methods for a specific field
995
+ */
996
+ interface FieldSort<S extends QuerySpec> {
997
+ asc(): SortExpression<S>;
998
+ desc(): SortExpression<S>;
999
+ }
1000
+ /**
1001
+ * Filter factory interface - creates filter expressions
1002
+ * @example
1003
+ * Filter('price').gt(50)
1004
+ * Filter.and(Filter('title').eq('Product'), Filter('price').gt(50))
1005
+ */
1006
+ interface FilterFactory<T, S extends QuerySpec> {
1007
+ /** Create a field-specific filter */
1008
+ <Field extends FilterableFields<S>>(field: Field): FieldFilter<T, S, Field>;
1009
+ /** Combine filters with AND logic */
1010
+ and(...filters: FilterExpression<T, S>[]): FilterExpression<T, S>;
1011
+ /** Combine filters with OR logic */
1012
+ or(...filters: FilterExpression<T, S>[]): FilterExpression<T, S>;
1013
+ /** Negate a filter */
1014
+ not(filter: FilterExpression<T, S>): FilterExpression<T, S>;
1015
+ }
1016
+ /**
1017
+ * Sort factory - creates sort expressions
1018
+ * @example
1019
+ * Sort('price').desc()
1020
+ */
1021
+ type SortFactory<S extends QuerySpec> = <Field extends SortableFields<S>>(field: Field) => FieldSort<S>;
1022
+ /**
1023
+ * Query builder interface
1024
+ * @template T - Entity type
1025
+ * @template S - Query spec defining filterable/sortable fields
1026
+ * @template R - Output type from build() (defaults to QueryRequest<T, S>)
1027
+ * @example
1028
+ * QueryBuilder()
1029
+ * .withFilter(Filter.and(
1030
+ * Filter('title').eq('Product'),
1031
+ * Filter('price').gt(50)
1032
+ * ))
1033
+ * .withFields('title', 'price')
1034
+ * .withSorting(Sort('price').desc())
1035
+ * .withPaging({ limit: 20, offset: 0 })
1036
+ * .build()
1037
+ */
1038
+ interface QueryBuilder<T, S extends QuerySpec, R = QueryRequest<T, S>> {
1039
+ /** Add a filter to the query */
1040
+ withFilter(filter: FilterExpression<T, S>): QueryBuilder<T, S, R>;
1041
+ /** Add field projection - return only specified fields */
1042
+ withFields(...fields: (keyof T & string)[]): QueryBuilder<T, S, R>;
1043
+ /** Add sorting to the query */
1044
+ withSorting(...sorts: SortExpression<S>[]): QueryBuilder<T, S, R>;
1045
+ /** Add paging to the query */
1046
+ withPaging(paging: PagingFor<S>): QueryBuilder<T, S, R>;
1047
+ /** Build the final query request object */
1048
+ build(): R;
1049
+ }
1050
+ /**
1051
+ * Complete set of query helpers for an entity
1052
+ * This is what gets spread into module namespaces
1053
+ * @template T - Entity type
1054
+ * @template S - Query spec defining filterable/sortable fields
1055
+ * @template R - Output type from QueryBuilder.build() (defaults to QueryRequest<T, S>)
1056
+ */
1057
+ interface QueryHelpers<T, S extends QuerySpec, R = QueryRequest<T, S>> {
1058
+ /** QueryBuilder factory */
1059
+ QueryBuilder: () => QueryBuilder<T, S, R>;
1060
+ /** Filter factory - creates filter expressions */
1061
+ Filter: FilterFactory<T, S>;
1062
+ /** Sort factory - creates sort expressions */
1063
+ Sort: SortFactory<S>;
1064
+ }
1065
+
1066
+ export { type APIMetadata, type AccountInfo, type AmbassadorFactory, type AmbassadorFunctionDescriptor, type AmbassadorRequestOptions, type AuthenticationStrategy, type BaseEventMetadata, type BoundAuthenticationStrategy, type BuildAmbassadorFunction, type BuildDescriptors, type BuildEventDefinition, type BuildRESTFunction, type BuildServicePluginDefinition, type CursorPaging, type Descriptors, EventDefinition, type EventHandler, type EventIdentity, type ExposeFieldsBasedOnToggle, type FieldFilter, type FieldSort, type Filter, type FilterExpression, type FilterFactory, 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 OffsetPaging, type PagingFor, type PublicMetadata, type Query, type QueryBuilder, type QueryHelpers, type QueryRequest, 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 SortExpression, type SortFactory, type SortOrder, type Sorting, type WQL, type WQLSpec };
package/build/index.d.ts CHANGED
@@ -155,9 +155,15 @@ type EventIdentity = {
155
155
  wixUserId: string;
156
156
  appId: string;
157
157
  };
158
+ type AccountInfo = {
159
+ accountId: string;
160
+ parentAccountId?: string;
161
+ siteId?: string;
162
+ };
158
163
  type BaseEventMetadata = {
159
164
  instanceId: string;
160
165
  identity?: EventIdentity;
166
+ accountInfo?: AccountInfo;
161
167
  };
162
168
  type EventDefinition<Payload = unknown, Type extends string = string> = {
163
169
  __type: 'event-definition';
@@ -556,7 +562,7 @@ type Filter<Entity, Spec extends WQLSpec> = Simplify<{
556
562
  /**
557
563
  * Cursor-based paging configuration
558
564
  */
559
- interface CursorPaging {
565
+ interface CursorPaging$1 {
560
566
  /** Maximum number of items to return in the results. */
561
567
  limit?: number | null;
562
568
  /**
@@ -570,7 +576,7 @@ interface CursorPaging {
570
576
  /**
571
577
  * Offset-based paging configuration
572
578
  */
573
- interface OffsetPaging {
579
+ interface OffsetPaging$1 {
574
580
  /** Number of items to load */
575
581
  limit?: number | null;
576
582
  /** Number of items to skip in the current sort order */
@@ -586,9 +592,9 @@ type PagingType = 'cursor' | 'offset';
586
592
  type Paging<Spec extends {
587
593
  paging?: PagingType;
588
594
  }> = Spec['paging'] extends 'cursor' ? {
589
- cursorPaging: CursorPaging;
595
+ cursorPaging: CursorPaging$1;
590
596
  } : Spec['paging'] extends 'offset' ? {
591
- paging: OffsetPaging;
597
+ paging: OffsetPaging$1;
592
598
  } : {};
593
599
 
594
600
  /**
@@ -888,4 +894,173 @@ type Query<Entity, Spec extends QuerySpec> = {
888
894
  sort?: Sorting<Spec>[];
889
895
  } & Partial<Paging<Spec>>;
890
896
 
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 };
897
+ interface CursorPaging {
898
+ limit: number;
899
+ cursor?: string;
900
+ }
901
+ interface OffsetPaging {
902
+ limit: number;
903
+ offset?: number;
904
+ }
905
+ type PagingFor<S extends QuerySpec> = S['paging'] extends 'cursor' ? CursorPaging : OffsetPaging;
906
+ /**
907
+ * The output type from QueryBuilder.build()
908
+ * This is a plain object ready to be sent to an API
909
+ */
910
+ interface QueryRequest<T, S extends QuerySpec> {
911
+ filter?: Filter<T, S>;
912
+ sort?: Sorting<S>[];
913
+ paging?: PagingFor<S>;
914
+ /** Field projection - return only specified fields */
915
+ fields?: string[];
916
+ }
917
+ /**
918
+ * Represents a filter expression that can be combined with other filters
919
+ */
920
+ interface FilterExpression<T, S extends QuerySpec> {
921
+ readonly filter: Filter<T, S>;
922
+ }
923
+ /**
924
+ * Represents a sort expression
925
+ */
926
+ interface SortExpression<S extends QuerySpec> {
927
+ readonly sort: Sorting<S>;
928
+ }
929
+ /**
930
+ * Extract fields that support a specific operator from the spec
931
+ */
932
+ type FieldsWithOperator<S extends QuerySpec, Op extends string> = S['wql'][number] extends infer Group ? Group extends WQL ? Group['operators'] extends readonly string[] ? Op extends Group['operators'][number] ? Group['fields'][number] : never : Group['fields'][number] : never : never;
933
+ /**
934
+ * Check if a specific field supports a specific operator
935
+ */
936
+ type HasOperator<S extends QuerySpec, Field extends string, Op extends string> = Field extends FieldsWithOperator<S, Op> ? true : false;
937
+ /**
938
+ * Extract sortable fields from the spec
939
+ */
940
+ type SortableFields<S extends QuerySpec> = S['wql'][number] extends infer Group ? Group extends {
941
+ fields: readonly string[];
942
+ sort: 'ASC' | 'DESC' | 'BOTH';
943
+ } ? Group['fields'][number] : never : never;
944
+ /**
945
+ * Chainable field filter - extends FilterExpression so it can be used directly,
946
+ * but also allows chaining multiple operators on the same field.
947
+ * @example
948
+ * // Single operator - returns ChainableFieldFilter which is also FilterExpression
949
+ * Filter('price').gt(50)
950
+ *
951
+ * // Chained operators - combines into single field filter
952
+ * Filter('price').gt(50).lt(100)
953
+ * // Produces: { price: { $gt: 50, $lt: 100 } }
954
+ */
955
+ type ChainableFieldFilter<T, S extends QuerySpec, Field extends FilterableFields<S>> = FilterExpression<T, S> & (HasOperator<S, Field & string, '$eq'> extends true ? {
956
+ eq(value: GetNestedType<T, Field & string>): ChainableFieldFilter<T, S, Field>;
957
+ } : {}) & (HasOperator<S, Field & string, '$ne'> extends true ? {
958
+ ne(value: GetNestedType<T, Field & string>): ChainableFieldFilter<T, S, Field>;
959
+ } : {}) & (HasOperator<S, Field & string, '$gt'> extends true ? {
960
+ gt(value: GetNestedType<T, Field & string>): ChainableFieldFilter<T, S, Field>;
961
+ } : {}) & (HasOperator<S, Field & string, '$gte'> extends true ? {
962
+ gte(value: GetNestedType<T, Field & string>): ChainableFieldFilter<T, S, Field>;
963
+ } : {}) & (HasOperator<S, Field & string, '$lt'> extends true ? {
964
+ lt(value: GetNestedType<T, Field & string>): ChainableFieldFilter<T, S, Field>;
965
+ } : {}) & (HasOperator<S, Field & string, '$lte'> extends true ? {
966
+ lte(value: GetNestedType<T, Field & string>): ChainableFieldFilter<T, S, Field>;
967
+ } : {}) & (HasOperator<S, Field & string, '$startsWith'> extends true ? {
968
+ startsWith(value: string): ChainableFieldFilter<T, S, Field>;
969
+ } : {}) & (HasOperator<S, Field & string, '$endsWith'> extends true ? {
970
+ endsWith(value: string): ChainableFieldFilter<T, S, Field>;
971
+ } : {}) & (HasOperator<S, Field & string, '$contains'> extends true ? {
972
+ contains(value: string): ChainableFieldFilter<T, S, Field>;
973
+ } : {}) & (HasOperator<S, Field & string, '$in'> extends true ? {
974
+ in(values: GetNestedType<T, Field & string>[]): ChainableFieldFilter<T, S, Field>;
975
+ } : {}) & (HasOperator<S, Field & string, '$nin'> extends true ? {
976
+ nin(values: GetNestedType<T, Field & string>[]): ChainableFieldFilter<T, S, Field>;
977
+ } : {}) & (HasOperator<S, Field & string, '$hasSome'> extends true ? {
978
+ hasSome(values: GetNestedType<T, Field & string>[]): ChainableFieldFilter<T, S, Field>;
979
+ } : {}) & (HasOperator<S, Field & string, '$hasAll'> extends true ? {
980
+ hasAll(values: GetNestedType<T, Field & string>[]): ChainableFieldFilter<T, S, Field>;
981
+ } : {}) & (HasOperator<S, Field & string, '$exists'> extends true ? {
982
+ exists(value?: boolean): ChainableFieldFilter<T, S, Field>;
983
+ } : {}) & (HasOperator<S, Field & string, '$isEmpty'> extends true ? {
984
+ isEmpty(value?: boolean): ChainableFieldFilter<T, S, Field>;
985
+ } : {}) & (HasOperator<S, Field & string, '$ne'> extends true ? {
986
+ isNotEmpty(): ChainableFieldFilter<T, S, Field>;
987
+ } : {});
988
+ /**
989
+ * Filter methods for a specific field (alias for ChainableFieldFilter)
990
+ * Only shows methods for operators that the field supports
991
+ */
992
+ type FieldFilter<T, S extends QuerySpec, Field extends FilterableFields<S>> = ChainableFieldFilter<T, S, Field>;
993
+ /**
994
+ * Sort methods for a specific field
995
+ */
996
+ interface FieldSort<S extends QuerySpec> {
997
+ asc(): SortExpression<S>;
998
+ desc(): SortExpression<S>;
999
+ }
1000
+ /**
1001
+ * Filter factory interface - creates filter expressions
1002
+ * @example
1003
+ * Filter('price').gt(50)
1004
+ * Filter.and(Filter('title').eq('Product'), Filter('price').gt(50))
1005
+ */
1006
+ interface FilterFactory<T, S extends QuerySpec> {
1007
+ /** Create a field-specific filter */
1008
+ <Field extends FilterableFields<S>>(field: Field): FieldFilter<T, S, Field>;
1009
+ /** Combine filters with AND logic */
1010
+ and(...filters: FilterExpression<T, S>[]): FilterExpression<T, S>;
1011
+ /** Combine filters with OR logic */
1012
+ or(...filters: FilterExpression<T, S>[]): FilterExpression<T, S>;
1013
+ /** Negate a filter */
1014
+ not(filter: FilterExpression<T, S>): FilterExpression<T, S>;
1015
+ }
1016
+ /**
1017
+ * Sort factory - creates sort expressions
1018
+ * @example
1019
+ * Sort('price').desc()
1020
+ */
1021
+ type SortFactory<S extends QuerySpec> = <Field extends SortableFields<S>>(field: Field) => FieldSort<S>;
1022
+ /**
1023
+ * Query builder interface
1024
+ * @template T - Entity type
1025
+ * @template S - Query spec defining filterable/sortable fields
1026
+ * @template R - Output type from build() (defaults to QueryRequest<T, S>)
1027
+ * @example
1028
+ * QueryBuilder()
1029
+ * .withFilter(Filter.and(
1030
+ * Filter('title').eq('Product'),
1031
+ * Filter('price').gt(50)
1032
+ * ))
1033
+ * .withFields('title', 'price')
1034
+ * .withSorting(Sort('price').desc())
1035
+ * .withPaging({ limit: 20, offset: 0 })
1036
+ * .build()
1037
+ */
1038
+ interface QueryBuilder<T, S extends QuerySpec, R = QueryRequest<T, S>> {
1039
+ /** Add a filter to the query */
1040
+ withFilter(filter: FilterExpression<T, S>): QueryBuilder<T, S, R>;
1041
+ /** Add field projection - return only specified fields */
1042
+ withFields(...fields: (keyof T & string)[]): QueryBuilder<T, S, R>;
1043
+ /** Add sorting to the query */
1044
+ withSorting(...sorts: SortExpression<S>[]): QueryBuilder<T, S, R>;
1045
+ /** Add paging to the query */
1046
+ withPaging(paging: PagingFor<S>): QueryBuilder<T, S, R>;
1047
+ /** Build the final query request object */
1048
+ build(): R;
1049
+ }
1050
+ /**
1051
+ * Complete set of query helpers for an entity
1052
+ * This is what gets spread into module namespaces
1053
+ * @template T - Entity type
1054
+ * @template S - Query spec defining filterable/sortable fields
1055
+ * @template R - Output type from QueryBuilder.build() (defaults to QueryRequest<T, S>)
1056
+ */
1057
+ interface QueryHelpers<T, S extends QuerySpec, R = QueryRequest<T, S>> {
1058
+ /** QueryBuilder factory */
1059
+ QueryBuilder: () => QueryBuilder<T, S, R>;
1060
+ /** Filter factory - creates filter expressions */
1061
+ Filter: FilterFactory<T, S>;
1062
+ /** Sort factory - creates sort expressions */
1063
+ Sort: SortFactory<S>;
1064
+ }
1065
+
1066
+ export { type APIMetadata, type AccountInfo, type AmbassadorFactory, type AmbassadorFunctionDescriptor, type AmbassadorRequestOptions, type AuthenticationStrategy, type BaseEventMetadata, type BoundAuthenticationStrategy, type BuildAmbassadorFunction, type BuildDescriptors, type BuildEventDefinition, type BuildRESTFunction, type BuildServicePluginDefinition, type CursorPaging, type Descriptors, EventDefinition, type EventHandler, type EventIdentity, type ExposeFieldsBasedOnToggle, type FieldFilter, type FieldSort, type Filter, type FilterExpression, type FilterFactory, 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 OffsetPaging, type PagingFor, type PublicMetadata, type Query, type QueryBuilder, type QueryHelpers, type QueryRequest, 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 SortExpression, type SortFactory, type SortOrder, type Sorting, type WQL, type WQLSpec };