@wix/sdk-types 1.13.10 → 1.13.11

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.
@@ -0,0 +1,306 @@
1
+ import { MonitoringClient } from '@wix/monitoring-types';
2
+ import { ConditionalExcept, EmptyObject, Simplify, Paths, SetRequiredDeep } from 'type-fest';
3
+
4
+ type HostModule<T, H extends Host> = {
5
+ __type: 'host';
6
+ create(host: H): T;
7
+ };
8
+ type HostModuleAPI<T extends HostModule<any, any>> = T extends HostModule<infer U, any> ? U : never;
9
+ type Host<Environment = unknown> = {
10
+ channel?: {
11
+ observeState(callback: (props: unknown, environment: Environment) => unknown): {
12
+ disconnect: () => void;
13
+ } | Promise<{
14
+ disconnect: () => void;
15
+ }>;
16
+ };
17
+ environment?: Environment;
18
+ /**
19
+ * Optional name of the environment, use for logging
20
+ */
21
+ name?: string;
22
+ /**
23
+ * Optional bast url to use for API requests, for example `www.wixapis.com`
24
+ */
25
+ apiBaseUrl?: string;
26
+ /**
27
+ * Optional function to get a monitoring client
28
+ */
29
+ getMonitoringClient?: () => MonitoringClient;
30
+ /**
31
+ * Possible data to be provided by every host, for cross cutting concerns
32
+ * like internationalization, billing, etc.
33
+ */
34
+ essentials?: {
35
+ /**
36
+ * The language of the currently viewed session
37
+ */
38
+ language?: string;
39
+ /**
40
+ * The locale of the currently viewed session
41
+ */
42
+ locale?: string;
43
+ /**
44
+ * Any headers that should be passed through to the API requests
45
+ */
46
+ passThroughHeaders?: Record<string, string>;
47
+ };
48
+ };
49
+
50
+ type HTTPMethod = 'POST' | 'GET' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS';
51
+ type RESTFunctionDescriptor<T extends (...args: any[]) => any = (...args: any[]) => any> = (httpClient: HttpClient) => T;
52
+ interface HttpClient {
53
+ request<TResponse, TData = any>(req: RequestOptionsFactory<TResponse, TData>): Promise<HttpResponse<TResponse>>;
54
+ fetchWithAuth: typeof fetch;
55
+ wixAPIFetch: (relativeUrl: string, options: RequestInit) => Promise<Response>;
56
+ getActiveToken?: () => string | undefined;
57
+ }
58
+ type RequestOptionsFactory<TResponse = any, TData = any> = (context: any) => RequestOptions<TResponse, TData>;
59
+ type HttpResponse<T = any> = {
60
+ data: T;
61
+ status: number;
62
+ statusText: string;
63
+ headers: any;
64
+ request?: any;
65
+ };
66
+ type RequestOptions<_TResponse = any, Data = any> = {
67
+ method: HTTPMethod;
68
+ url: string;
69
+ data?: Data;
70
+ params?: URLSearchParams;
71
+ } & APIMetadata;
72
+ type APIMetadata = {
73
+ methodFqn?: string;
74
+ entityFqdn?: string;
75
+ packageName?: string;
76
+ };
77
+ type BuildRESTFunction<T extends RESTFunctionDescriptor> = T extends RESTFunctionDescriptor<infer U> ? U : never;
78
+ type RestModuleMeta<TMethod extends HTTPMethod = HTTPMethod, TPathParams = unknown, RequestType = unknown, TOriginalRequestType = unknown, ResponseType = unknown, OriginalResponseType = unknown> = {
79
+ getUrl(context: {
80
+ host: string;
81
+ }): string;
82
+ httpMethod: TMethod;
83
+ pathParams: TPathParams;
84
+ path: string;
85
+ __requestType: RequestType;
86
+ __originalRequestType: TOriginalRequestType;
87
+ __responseType: ResponseType;
88
+ __originalResponseType: OriginalResponseType;
89
+ };
90
+
91
+ type AuthenticationStrategy<Host = unknown> = {
92
+ getAuthHeaders: (host: Host) => Promise<{
93
+ headers: Record<string, string>;
94
+ }> | {
95
+ headers: Record<string, string>;
96
+ };
97
+ decodeJWT?: (token: string, verifyCallerClaims?: boolean) => Promise<{
98
+ decoded: {
99
+ data: unknown;
100
+ };
101
+ valid: boolean;
102
+ }>;
103
+ /**
104
+ * This function is used to get the token that is currently active in the context of the strategy.
105
+ * This is useful when direct access to the access token is needed
106
+ * (such as getTokenInfo that requires the token in the body of the request).
107
+ * @returns the token that is currently active in the context of the strategy
108
+ */
109
+ getActiveToken?: () => string | undefined;
110
+ };
111
+ type BoundAuthenticationStrategy = {
112
+ getAuthHeaders: () => Promise<{
113
+ headers: Record<string, string>;
114
+ }> | {
115
+ headers: Record<string, string>;
116
+ };
117
+ };
118
+
119
+ type EventIdentity = {
120
+ identityType: 'ANONYMOUS_VISITOR' | 'MEMBER' | 'WIX_USER' | 'APP';
121
+ anonymousVisitorId: string;
122
+ memberId: string;
123
+ wixUserId: string;
124
+ appId: string;
125
+ };
126
+ type BaseEventMetadata = {
127
+ instanceId: string;
128
+ identity?: EventIdentity;
129
+ };
130
+ type EventDefinition<Payload = unknown, Type extends string = string> = {
131
+ __type: 'event-definition';
132
+ type: Type;
133
+ isDomainEvent?: boolean;
134
+ transformations?: (envelope: unknown) => Payload;
135
+ __payload: Payload;
136
+ };
137
+ declare function EventDefinition<Type extends string>(type: Type, isDomainEvent?: boolean, transformations?: (envelope: any) => unknown): <Payload = unknown>() => EventDefinition<Payload, Type>;
138
+ type EventHandler<T extends EventDefinition> = (payload: T['__payload']) => void | Promise<void>;
139
+ type BuildEventDefinition<T extends EventDefinition<any, string>> = (handler: EventHandler<T>) => void;
140
+
141
+ type ServicePluginMethodInput = {
142
+ request: any;
143
+ metadata: any;
144
+ };
145
+ type ServicePluginContract = Record<string, (payload: ServicePluginMethodInput) => unknown | Promise<unknown>>;
146
+ type ServicePluginMethodMetadata = {
147
+ name: string;
148
+ primaryHttpMappingPath: string;
149
+ transformations: {
150
+ fromREST: (...args: unknown[]) => ServicePluginMethodInput;
151
+ toREST: (...args: unknown[]) => unknown;
152
+ };
153
+ };
154
+ type ServicePluginDefinition<Contract extends ServicePluginContract> = {
155
+ __type: 'service-plugin-definition';
156
+ componentType: string;
157
+ methods: ServicePluginMethodMetadata[];
158
+ __contract: Contract;
159
+ };
160
+ declare function ServicePluginDefinition<Contract extends ServicePluginContract>(componentType: string, methods: ServicePluginMethodMetadata[]): ServicePluginDefinition<Contract>;
161
+ type BuildServicePluginDefinition<T extends ServicePluginDefinition<any>> = (implementation: T['__contract']) => void;
162
+ declare const SERVICE_PLUGIN_ERROR_TYPE = "wix_spi_error";
163
+
164
+ type RequestContext = {
165
+ isSSR: boolean;
166
+ host: string;
167
+ protocol?: string;
168
+ };
169
+ type ResponseTransformer = (data: any, headers?: any) => any;
170
+ /**
171
+ * Ambassador request options types are copied mostly from AxiosRequestConfig.
172
+ * They are copied and not imported to reduce the amount of dependencies (to reduce install time).
173
+ * https://github.com/axios/axios/blob/3f53eb6960f05a1f88409c4b731a40de595cb825/index.d.ts#L307-L315
174
+ */
175
+ type Method = 'get' | 'GET' | 'delete' | 'DELETE' | 'head' | 'HEAD' | 'options' | 'OPTIONS' | 'post' | 'POST' | 'put' | 'PUT' | 'patch' | 'PATCH' | 'purge' | 'PURGE' | 'link' | 'LINK' | 'unlink' | 'UNLINK';
176
+ type AmbassadorRequestOptions<T = any> = {
177
+ _?: T;
178
+ url?: string;
179
+ method?: Method;
180
+ params?: any;
181
+ data?: any;
182
+ transformResponse?: ResponseTransformer | ResponseTransformer[];
183
+ };
184
+ type AmbassadorFactory<Request, Response> = (payload: Request) => ((context: RequestContext) => AmbassadorRequestOptions<Response>) & {
185
+ __isAmbassador: boolean;
186
+ };
187
+ type AmbassadorFunctionDescriptor<Request = any, Response = any> = AmbassadorFactory<Request, Response>;
188
+ type BuildAmbassadorFunction<T extends AmbassadorFunctionDescriptor> = T extends AmbassadorFunctionDescriptor<infer Request, infer Response> ? (req: Request) => Promise<Response> : never;
189
+
190
+ /**
191
+ * Descriptors are objects that describe the API of a module, and the module
192
+ * can either be a REST module or a host module.
193
+ * This type is recursive, so it can describe nested modules.
194
+ */
195
+ type Descriptors = RESTFunctionDescriptor | AmbassadorFunctionDescriptor | HostModule<any, any> | EventDefinition<any> | ServicePluginDefinition<any> | {
196
+ [key: string]: Descriptors | PublicMetadata | any;
197
+ };
198
+ /**
199
+ * This type takes in a descriptors object of a certain Host (including an `unknown` host)
200
+ * and returns an object with the same structure, but with all descriptors replaced with their API.
201
+ * Any non-descriptor properties are removed from the returned object, including descriptors that
202
+ * do not match the given host (as they will not work with the given host).
203
+ */
204
+ type BuildDescriptors<T extends Descriptors, H extends Host<any> | undefined, Depth extends number = 5> = {
205
+ done: T;
206
+ recurse: T extends {
207
+ __type: typeof SERVICE_PLUGIN_ERROR_TYPE;
208
+ } ? never : T extends AmbassadorFunctionDescriptor ? BuildAmbassadorFunction<T> : T extends RESTFunctionDescriptor ? BuildRESTFunction<T> : T extends EventDefinition<any> ? BuildEventDefinition<T> : T extends ServicePluginDefinition<any> ? BuildServicePluginDefinition<T> : T extends HostModule<any, any> ? HostModuleAPI<T> : ConditionalExcept<{
209
+ [Key in keyof T]: T[Key] extends Descriptors ? BuildDescriptors<T[Key], H, [
210
+ -1,
211
+ 0,
212
+ 1,
213
+ 2,
214
+ 3,
215
+ 4,
216
+ 5
217
+ ][Depth]> : never;
218
+ }, EmptyObject>;
219
+ }[Depth extends -1 ? 'done' : 'recurse'];
220
+ type PublicMetadata = {
221
+ PACKAGE_NAME?: string;
222
+ };
223
+
224
+ declare global {
225
+ interface ContextualClient {
226
+ }
227
+ }
228
+ /**
229
+ * A type used to create concerete types from SDK descriptors in
230
+ * case a contextual client is available.
231
+ */
232
+ type MaybeContext<T extends Descriptors> = globalThis.ContextualClient extends {
233
+ host: Host;
234
+ } ? BuildDescriptors<T, globalThis.ContextualClient['host']> : T;
235
+
236
+ /**
237
+ * Expose fields based on the current exposure toggle.
238
+ * @param T - The type to expose fields from.
239
+ * @param FieldsScope - A map of fields to their exposure scope, missing fields are considered public.
240
+ * @example Exposure toggle not set:
241
+ * ```ts
242
+ * type MyType = {
243
+ * publicField: string;
244
+ * alphaField: string;
245
+ * };
246
+ *
247
+ * type ExposedType = ExposeFieldsBasedOnToggle<MyType, { alphaField: 'alpha' }>;
248
+ * // ExposedType = { publicField: string; }
249
+ * ```
250
+ * @example Exposure toggle set to alpha:
251
+ * ```ts
252
+ * declare global {
253
+ * interface SDKExposureToggle {
254
+ * alpha: true;
255
+ * }
256
+ * }
257
+ *
258
+ * type MyType = {
259
+ * publicField: string;
260
+ * alphaField: string;
261
+ * };
262
+ *
263
+ * type ExposedType = ExposeFieldsBasedOnToggle<MyType, { alphaField: 'alpha' }>;
264
+ * // ExposedType = { publicField: string; alphaField: string; }
265
+ */
266
+ type ExposeFieldsBasedOnToggle<T extends Record<string, any>, FieldsScope extends Partial<Record<keyof T, Exposure>>> = Simplify<{
267
+ [K in keyof T as IsExposed<K, FieldsScope[K] extends Exposure ? FieldsScope[K] : 'public'>]: T[K];
268
+ }>;
269
+ declare global {
270
+ /**
271
+ * A global interface to set the exposure toggle for the SDK.
272
+ * @example
273
+ * ```ts
274
+ * declare global {
275
+ * interface SDKExposureToggle {
276
+ * alpha: true;
277
+ * }
278
+ * }
279
+ */
280
+ interface SDKExposureToggle {
281
+ }
282
+ }
283
+ type Exposure = 'alpha' | 'public';
284
+ type IsExposed<T, Scope extends Exposure> = Scope extends 'public' ? T : globalThis.SDKExposureToggle extends {
285
+ alpha: true;
286
+ } ? T : never;
287
+
288
+ declare global {
289
+ /**
290
+ * A global interface to set the type mode for the SDK.
291
+ * @example
292
+ * ```ts
293
+ * declare global {
294
+ * interface SDKTypeMode {
295
+ * strict: true;
296
+ * }
297
+ * }
298
+ */
299
+ interface SDKTypeMode {
300
+ }
301
+ }
302
+ type NonNullablePaths<T, K extends Paths<T>> = globalThis.SDKTypeMode extends {
303
+ strict: true;
304
+ } ? SetRequiredDeep<T, K> : T;
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 };
@@ -0,0 +1,306 @@
1
+ import { MonitoringClient } from '@wix/monitoring-types';
2
+ import { ConditionalExcept, EmptyObject, Simplify, Paths, SetRequiredDeep } from 'type-fest';
3
+
4
+ type HostModule<T, H extends Host> = {
5
+ __type: 'host';
6
+ create(host: H): T;
7
+ };
8
+ type HostModuleAPI<T extends HostModule<any, any>> = T extends HostModule<infer U, any> ? U : never;
9
+ type Host<Environment = unknown> = {
10
+ channel?: {
11
+ observeState(callback: (props: unknown, environment: Environment) => unknown): {
12
+ disconnect: () => void;
13
+ } | Promise<{
14
+ disconnect: () => void;
15
+ }>;
16
+ };
17
+ environment?: Environment;
18
+ /**
19
+ * Optional name of the environment, use for logging
20
+ */
21
+ name?: string;
22
+ /**
23
+ * Optional bast url to use for API requests, for example `www.wixapis.com`
24
+ */
25
+ apiBaseUrl?: string;
26
+ /**
27
+ * Optional function to get a monitoring client
28
+ */
29
+ getMonitoringClient?: () => MonitoringClient;
30
+ /**
31
+ * Possible data to be provided by every host, for cross cutting concerns
32
+ * like internationalization, billing, etc.
33
+ */
34
+ essentials?: {
35
+ /**
36
+ * The language of the currently viewed session
37
+ */
38
+ language?: string;
39
+ /**
40
+ * The locale of the currently viewed session
41
+ */
42
+ locale?: string;
43
+ /**
44
+ * Any headers that should be passed through to the API requests
45
+ */
46
+ passThroughHeaders?: Record<string, string>;
47
+ };
48
+ };
49
+
50
+ type HTTPMethod = 'POST' | 'GET' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS';
51
+ type RESTFunctionDescriptor<T extends (...args: any[]) => any = (...args: any[]) => any> = (httpClient: HttpClient) => T;
52
+ interface HttpClient {
53
+ request<TResponse, TData = any>(req: RequestOptionsFactory<TResponse, TData>): Promise<HttpResponse<TResponse>>;
54
+ fetchWithAuth: typeof fetch;
55
+ wixAPIFetch: (relativeUrl: string, options: RequestInit) => Promise<Response>;
56
+ getActiveToken?: () => string | undefined;
57
+ }
58
+ type RequestOptionsFactory<TResponse = any, TData = any> = (context: any) => RequestOptions<TResponse, TData>;
59
+ type HttpResponse<T = any> = {
60
+ data: T;
61
+ status: number;
62
+ statusText: string;
63
+ headers: any;
64
+ request?: any;
65
+ };
66
+ type RequestOptions<_TResponse = any, Data = any> = {
67
+ method: HTTPMethod;
68
+ url: string;
69
+ data?: Data;
70
+ params?: URLSearchParams;
71
+ } & APIMetadata;
72
+ type APIMetadata = {
73
+ methodFqn?: string;
74
+ entityFqdn?: string;
75
+ packageName?: string;
76
+ };
77
+ type BuildRESTFunction<T extends RESTFunctionDescriptor> = T extends RESTFunctionDescriptor<infer U> ? U : never;
78
+ type RestModuleMeta<TMethod extends HTTPMethod = HTTPMethod, TPathParams = unknown, RequestType = unknown, TOriginalRequestType = unknown, ResponseType = unknown, OriginalResponseType = unknown> = {
79
+ getUrl(context: {
80
+ host: string;
81
+ }): string;
82
+ httpMethod: TMethod;
83
+ pathParams: TPathParams;
84
+ path: string;
85
+ __requestType: RequestType;
86
+ __originalRequestType: TOriginalRequestType;
87
+ __responseType: ResponseType;
88
+ __originalResponseType: OriginalResponseType;
89
+ };
90
+
91
+ type AuthenticationStrategy<Host = unknown> = {
92
+ getAuthHeaders: (host: Host) => Promise<{
93
+ headers: Record<string, string>;
94
+ }> | {
95
+ headers: Record<string, string>;
96
+ };
97
+ decodeJWT?: (token: string, verifyCallerClaims?: boolean) => Promise<{
98
+ decoded: {
99
+ data: unknown;
100
+ };
101
+ valid: boolean;
102
+ }>;
103
+ /**
104
+ * This function is used to get the token that is currently active in the context of the strategy.
105
+ * This is useful when direct access to the access token is needed
106
+ * (such as getTokenInfo that requires the token in the body of the request).
107
+ * @returns the token that is currently active in the context of the strategy
108
+ */
109
+ getActiveToken?: () => string | undefined;
110
+ };
111
+ type BoundAuthenticationStrategy = {
112
+ getAuthHeaders: () => Promise<{
113
+ headers: Record<string, string>;
114
+ }> | {
115
+ headers: Record<string, string>;
116
+ };
117
+ };
118
+
119
+ type EventIdentity = {
120
+ identityType: 'ANONYMOUS_VISITOR' | 'MEMBER' | 'WIX_USER' | 'APP';
121
+ anonymousVisitorId: string;
122
+ memberId: string;
123
+ wixUserId: string;
124
+ appId: string;
125
+ };
126
+ type BaseEventMetadata = {
127
+ instanceId: string;
128
+ identity?: EventIdentity;
129
+ };
130
+ type EventDefinition<Payload = unknown, Type extends string = string> = {
131
+ __type: 'event-definition';
132
+ type: Type;
133
+ isDomainEvent?: boolean;
134
+ transformations?: (envelope: unknown) => Payload;
135
+ __payload: Payload;
136
+ };
137
+ declare function EventDefinition<Type extends string>(type: Type, isDomainEvent?: boolean, transformations?: (envelope: any) => unknown): <Payload = unknown>() => EventDefinition<Payload, Type>;
138
+ type EventHandler<T extends EventDefinition> = (payload: T['__payload']) => void | Promise<void>;
139
+ type BuildEventDefinition<T extends EventDefinition<any, string>> = (handler: EventHandler<T>) => void;
140
+
141
+ type ServicePluginMethodInput = {
142
+ request: any;
143
+ metadata: any;
144
+ };
145
+ type ServicePluginContract = Record<string, (payload: ServicePluginMethodInput) => unknown | Promise<unknown>>;
146
+ type ServicePluginMethodMetadata = {
147
+ name: string;
148
+ primaryHttpMappingPath: string;
149
+ transformations: {
150
+ fromREST: (...args: unknown[]) => ServicePluginMethodInput;
151
+ toREST: (...args: unknown[]) => unknown;
152
+ };
153
+ };
154
+ type ServicePluginDefinition<Contract extends ServicePluginContract> = {
155
+ __type: 'service-plugin-definition';
156
+ componentType: string;
157
+ methods: ServicePluginMethodMetadata[];
158
+ __contract: Contract;
159
+ };
160
+ declare function ServicePluginDefinition<Contract extends ServicePluginContract>(componentType: string, methods: ServicePluginMethodMetadata[]): ServicePluginDefinition<Contract>;
161
+ type BuildServicePluginDefinition<T extends ServicePluginDefinition<any>> = (implementation: T['__contract']) => void;
162
+ declare const SERVICE_PLUGIN_ERROR_TYPE = "wix_spi_error";
163
+
164
+ type RequestContext = {
165
+ isSSR: boolean;
166
+ host: string;
167
+ protocol?: string;
168
+ };
169
+ type ResponseTransformer = (data: any, headers?: any) => any;
170
+ /**
171
+ * Ambassador request options types are copied mostly from AxiosRequestConfig.
172
+ * They are copied and not imported to reduce the amount of dependencies (to reduce install time).
173
+ * https://github.com/axios/axios/blob/3f53eb6960f05a1f88409c4b731a40de595cb825/index.d.ts#L307-L315
174
+ */
175
+ type Method = 'get' | 'GET' | 'delete' | 'DELETE' | 'head' | 'HEAD' | 'options' | 'OPTIONS' | 'post' | 'POST' | 'put' | 'PUT' | 'patch' | 'PATCH' | 'purge' | 'PURGE' | 'link' | 'LINK' | 'unlink' | 'UNLINK';
176
+ type AmbassadorRequestOptions<T = any> = {
177
+ _?: T;
178
+ url?: string;
179
+ method?: Method;
180
+ params?: any;
181
+ data?: any;
182
+ transformResponse?: ResponseTransformer | ResponseTransformer[];
183
+ };
184
+ type AmbassadorFactory<Request, Response> = (payload: Request) => ((context: RequestContext) => AmbassadorRequestOptions<Response>) & {
185
+ __isAmbassador: boolean;
186
+ };
187
+ type AmbassadorFunctionDescriptor<Request = any, Response = any> = AmbassadorFactory<Request, Response>;
188
+ type BuildAmbassadorFunction<T extends AmbassadorFunctionDescriptor> = T extends AmbassadorFunctionDescriptor<infer Request, infer Response> ? (req: Request) => Promise<Response> : never;
189
+
190
+ /**
191
+ * Descriptors are objects that describe the API of a module, and the module
192
+ * can either be a REST module or a host module.
193
+ * This type is recursive, so it can describe nested modules.
194
+ */
195
+ type Descriptors = RESTFunctionDescriptor | AmbassadorFunctionDescriptor | HostModule<any, any> | EventDefinition<any> | ServicePluginDefinition<any> | {
196
+ [key: string]: Descriptors | PublicMetadata | any;
197
+ };
198
+ /**
199
+ * This type takes in a descriptors object of a certain Host (including an `unknown` host)
200
+ * and returns an object with the same structure, but with all descriptors replaced with their API.
201
+ * Any non-descriptor properties are removed from the returned object, including descriptors that
202
+ * do not match the given host (as they will not work with the given host).
203
+ */
204
+ type BuildDescriptors<T extends Descriptors, H extends Host<any> | undefined, Depth extends number = 5> = {
205
+ done: T;
206
+ recurse: T extends {
207
+ __type: typeof SERVICE_PLUGIN_ERROR_TYPE;
208
+ } ? never : T extends AmbassadorFunctionDescriptor ? BuildAmbassadorFunction<T> : T extends RESTFunctionDescriptor ? BuildRESTFunction<T> : T extends EventDefinition<any> ? BuildEventDefinition<T> : T extends ServicePluginDefinition<any> ? BuildServicePluginDefinition<T> : T extends HostModule<any, any> ? HostModuleAPI<T> : ConditionalExcept<{
209
+ [Key in keyof T]: T[Key] extends Descriptors ? BuildDescriptors<T[Key], H, [
210
+ -1,
211
+ 0,
212
+ 1,
213
+ 2,
214
+ 3,
215
+ 4,
216
+ 5
217
+ ][Depth]> : never;
218
+ }, EmptyObject>;
219
+ }[Depth extends -1 ? 'done' : 'recurse'];
220
+ type PublicMetadata = {
221
+ PACKAGE_NAME?: string;
222
+ };
223
+
224
+ declare global {
225
+ interface ContextualClient {
226
+ }
227
+ }
228
+ /**
229
+ * A type used to create concerete types from SDK descriptors in
230
+ * case a contextual client is available.
231
+ */
232
+ type MaybeContext<T extends Descriptors> = globalThis.ContextualClient extends {
233
+ host: Host;
234
+ } ? BuildDescriptors<T, globalThis.ContextualClient['host']> : T;
235
+
236
+ /**
237
+ * Expose fields based on the current exposure toggle.
238
+ * @param T - The type to expose fields from.
239
+ * @param FieldsScope - A map of fields to their exposure scope, missing fields are considered public.
240
+ * @example Exposure toggle not set:
241
+ * ```ts
242
+ * type MyType = {
243
+ * publicField: string;
244
+ * alphaField: string;
245
+ * };
246
+ *
247
+ * type ExposedType = ExposeFieldsBasedOnToggle<MyType, { alphaField: 'alpha' }>;
248
+ * // ExposedType = { publicField: string; }
249
+ * ```
250
+ * @example Exposure toggle set to alpha:
251
+ * ```ts
252
+ * declare global {
253
+ * interface SDKExposureToggle {
254
+ * alpha: true;
255
+ * }
256
+ * }
257
+ *
258
+ * type MyType = {
259
+ * publicField: string;
260
+ * alphaField: string;
261
+ * };
262
+ *
263
+ * type ExposedType = ExposeFieldsBasedOnToggle<MyType, { alphaField: 'alpha' }>;
264
+ * // ExposedType = { publicField: string; alphaField: string; }
265
+ */
266
+ type ExposeFieldsBasedOnToggle<T extends Record<string, any>, FieldsScope extends Partial<Record<keyof T, Exposure>>> = Simplify<{
267
+ [K in keyof T as IsExposed<K, FieldsScope[K] extends Exposure ? FieldsScope[K] : 'public'>]: T[K];
268
+ }>;
269
+ declare global {
270
+ /**
271
+ * A global interface to set the exposure toggle for the SDK.
272
+ * @example
273
+ * ```ts
274
+ * declare global {
275
+ * interface SDKExposureToggle {
276
+ * alpha: true;
277
+ * }
278
+ * }
279
+ */
280
+ interface SDKExposureToggle {
281
+ }
282
+ }
283
+ type Exposure = 'alpha' | 'public';
284
+ type IsExposed<T, Scope extends Exposure> = Scope extends 'public' ? T : globalThis.SDKExposureToggle extends {
285
+ alpha: true;
286
+ } ? T : never;
287
+
288
+ declare global {
289
+ /**
290
+ * A global interface to set the type mode for the SDK.
291
+ * @example
292
+ * ```ts
293
+ * declare global {
294
+ * interface SDKTypeMode {
295
+ * strict: true;
296
+ * }
297
+ * }
298
+ */
299
+ interface SDKTypeMode {
300
+ }
301
+ }
302
+ type NonNullablePaths<T, K extends Paths<T>> = globalThis.SDKTypeMode extends {
303
+ strict: true;
304
+ } ? SetRequiredDeep<T, K> : T;
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 };
@@ -0,0 +1,24 @@
1
+ // src/event-handlers-modules.ts
2
+ function EventDefinition(type, isDomainEvent = false, transformations = (x) => x) {
3
+ return () => ({
4
+ __type: "event-definition",
5
+ type,
6
+ isDomainEvent,
7
+ transformations
8
+ });
9
+ }
10
+
11
+ // src/service-plugins.ts
12
+ function ServicePluginDefinition(componentType, methods) {
13
+ return {
14
+ __type: "service-plugin-definition",
15
+ componentType,
16
+ methods
17
+ };
18
+ }
19
+ var SERVICE_PLUGIN_ERROR_TYPE = "wix_spi_error";
20
+ export {
21
+ EventDefinition,
22
+ SERVICE_PLUGIN_ERROR_TYPE,
23
+ ServicePluginDefinition
24
+ };
@@ -0,0 +1,306 @@
1
+ import { MonitoringClient } from '@wix/monitoring-types';
2
+ import { ConditionalExcept, EmptyObject, Simplify, Paths, SetRequiredDeep } from 'type-fest';
3
+
4
+ type HostModule<T, H extends Host> = {
5
+ __type: 'host';
6
+ create(host: H): T;
7
+ };
8
+ type HostModuleAPI<T extends HostModule<any, any>> = T extends HostModule<infer U, any> ? U : never;
9
+ type Host<Environment = unknown> = {
10
+ channel?: {
11
+ observeState(callback: (props: unknown, environment: Environment) => unknown): {
12
+ disconnect: () => void;
13
+ } | Promise<{
14
+ disconnect: () => void;
15
+ }>;
16
+ };
17
+ environment?: Environment;
18
+ /**
19
+ * Optional name of the environment, use for logging
20
+ */
21
+ name?: string;
22
+ /**
23
+ * Optional bast url to use for API requests, for example `www.wixapis.com`
24
+ */
25
+ apiBaseUrl?: string;
26
+ /**
27
+ * Optional function to get a monitoring client
28
+ */
29
+ getMonitoringClient?: () => MonitoringClient;
30
+ /**
31
+ * Possible data to be provided by every host, for cross cutting concerns
32
+ * like internationalization, billing, etc.
33
+ */
34
+ essentials?: {
35
+ /**
36
+ * The language of the currently viewed session
37
+ */
38
+ language?: string;
39
+ /**
40
+ * The locale of the currently viewed session
41
+ */
42
+ locale?: string;
43
+ /**
44
+ * Any headers that should be passed through to the API requests
45
+ */
46
+ passThroughHeaders?: Record<string, string>;
47
+ };
48
+ };
49
+
50
+ type HTTPMethod = 'POST' | 'GET' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS';
51
+ type RESTFunctionDescriptor<T extends (...args: any[]) => any = (...args: any[]) => any> = (httpClient: HttpClient) => T;
52
+ interface HttpClient {
53
+ request<TResponse, TData = any>(req: RequestOptionsFactory<TResponse, TData>): Promise<HttpResponse<TResponse>>;
54
+ fetchWithAuth: typeof fetch;
55
+ wixAPIFetch: (relativeUrl: string, options: RequestInit) => Promise<Response>;
56
+ getActiveToken?: () => string | undefined;
57
+ }
58
+ type RequestOptionsFactory<TResponse = any, TData = any> = (context: any) => RequestOptions<TResponse, TData>;
59
+ type HttpResponse<T = any> = {
60
+ data: T;
61
+ status: number;
62
+ statusText: string;
63
+ headers: any;
64
+ request?: any;
65
+ };
66
+ type RequestOptions<_TResponse = any, Data = any> = {
67
+ method: HTTPMethod;
68
+ url: string;
69
+ data?: Data;
70
+ params?: URLSearchParams;
71
+ } & APIMetadata;
72
+ type APIMetadata = {
73
+ methodFqn?: string;
74
+ entityFqdn?: string;
75
+ packageName?: string;
76
+ };
77
+ type BuildRESTFunction<T extends RESTFunctionDescriptor> = T extends RESTFunctionDescriptor<infer U> ? U : never;
78
+ type RestModuleMeta<TMethod extends HTTPMethod = HTTPMethod, TPathParams = unknown, RequestType = unknown, TOriginalRequestType = unknown, ResponseType = unknown, OriginalResponseType = unknown> = {
79
+ getUrl(context: {
80
+ host: string;
81
+ }): string;
82
+ httpMethod: TMethod;
83
+ pathParams: TPathParams;
84
+ path: string;
85
+ __requestType: RequestType;
86
+ __originalRequestType: TOriginalRequestType;
87
+ __responseType: ResponseType;
88
+ __originalResponseType: OriginalResponseType;
89
+ };
90
+
91
+ type AuthenticationStrategy<Host = unknown> = {
92
+ getAuthHeaders: (host: Host) => Promise<{
93
+ headers: Record<string, string>;
94
+ }> | {
95
+ headers: Record<string, string>;
96
+ };
97
+ decodeJWT?: (token: string, verifyCallerClaims?: boolean) => Promise<{
98
+ decoded: {
99
+ data: unknown;
100
+ };
101
+ valid: boolean;
102
+ }>;
103
+ /**
104
+ * This function is used to get the token that is currently active in the context of the strategy.
105
+ * This is useful when direct access to the access token is needed
106
+ * (such as getTokenInfo that requires the token in the body of the request).
107
+ * @returns the token that is currently active in the context of the strategy
108
+ */
109
+ getActiveToken?: () => string | undefined;
110
+ };
111
+ type BoundAuthenticationStrategy = {
112
+ getAuthHeaders: () => Promise<{
113
+ headers: Record<string, string>;
114
+ }> | {
115
+ headers: Record<string, string>;
116
+ };
117
+ };
118
+
119
+ type EventIdentity = {
120
+ identityType: 'ANONYMOUS_VISITOR' | 'MEMBER' | 'WIX_USER' | 'APP';
121
+ anonymousVisitorId: string;
122
+ memberId: string;
123
+ wixUserId: string;
124
+ appId: string;
125
+ };
126
+ type BaseEventMetadata = {
127
+ instanceId: string;
128
+ identity?: EventIdentity;
129
+ };
130
+ type EventDefinition<Payload = unknown, Type extends string = string> = {
131
+ __type: 'event-definition';
132
+ type: Type;
133
+ isDomainEvent?: boolean;
134
+ transformations?: (envelope: unknown) => Payload;
135
+ __payload: Payload;
136
+ };
137
+ declare function EventDefinition<Type extends string>(type: Type, isDomainEvent?: boolean, transformations?: (envelope: any) => unknown): <Payload = unknown>() => EventDefinition<Payload, Type>;
138
+ type EventHandler<T extends EventDefinition> = (payload: T['__payload']) => void | Promise<void>;
139
+ type BuildEventDefinition<T extends EventDefinition<any, string>> = (handler: EventHandler<T>) => void;
140
+
141
+ type ServicePluginMethodInput = {
142
+ request: any;
143
+ metadata: any;
144
+ };
145
+ type ServicePluginContract = Record<string, (payload: ServicePluginMethodInput) => unknown | Promise<unknown>>;
146
+ type ServicePluginMethodMetadata = {
147
+ name: string;
148
+ primaryHttpMappingPath: string;
149
+ transformations: {
150
+ fromREST: (...args: unknown[]) => ServicePluginMethodInput;
151
+ toREST: (...args: unknown[]) => unknown;
152
+ };
153
+ };
154
+ type ServicePluginDefinition<Contract extends ServicePluginContract> = {
155
+ __type: 'service-plugin-definition';
156
+ componentType: string;
157
+ methods: ServicePluginMethodMetadata[];
158
+ __contract: Contract;
159
+ };
160
+ declare function ServicePluginDefinition<Contract extends ServicePluginContract>(componentType: string, methods: ServicePluginMethodMetadata[]): ServicePluginDefinition<Contract>;
161
+ type BuildServicePluginDefinition<T extends ServicePluginDefinition<any>> = (implementation: T['__contract']) => void;
162
+ declare const SERVICE_PLUGIN_ERROR_TYPE = "wix_spi_error";
163
+
164
+ type RequestContext = {
165
+ isSSR: boolean;
166
+ host: string;
167
+ protocol?: string;
168
+ };
169
+ type ResponseTransformer = (data: any, headers?: any) => any;
170
+ /**
171
+ * Ambassador request options types are copied mostly from AxiosRequestConfig.
172
+ * They are copied and not imported to reduce the amount of dependencies (to reduce install time).
173
+ * https://github.com/axios/axios/blob/3f53eb6960f05a1f88409c4b731a40de595cb825/index.d.ts#L307-L315
174
+ */
175
+ type Method = 'get' | 'GET' | 'delete' | 'DELETE' | 'head' | 'HEAD' | 'options' | 'OPTIONS' | 'post' | 'POST' | 'put' | 'PUT' | 'patch' | 'PATCH' | 'purge' | 'PURGE' | 'link' | 'LINK' | 'unlink' | 'UNLINK';
176
+ type AmbassadorRequestOptions<T = any> = {
177
+ _?: T;
178
+ url?: string;
179
+ method?: Method;
180
+ params?: any;
181
+ data?: any;
182
+ transformResponse?: ResponseTransformer | ResponseTransformer[];
183
+ };
184
+ type AmbassadorFactory<Request, Response> = (payload: Request) => ((context: RequestContext) => AmbassadorRequestOptions<Response>) & {
185
+ __isAmbassador: boolean;
186
+ };
187
+ type AmbassadorFunctionDescriptor<Request = any, Response = any> = AmbassadorFactory<Request, Response>;
188
+ type BuildAmbassadorFunction<T extends AmbassadorFunctionDescriptor> = T extends AmbassadorFunctionDescriptor<infer Request, infer Response> ? (req: Request) => Promise<Response> : never;
189
+
190
+ /**
191
+ * Descriptors are objects that describe the API of a module, and the module
192
+ * can either be a REST module or a host module.
193
+ * This type is recursive, so it can describe nested modules.
194
+ */
195
+ type Descriptors = RESTFunctionDescriptor | AmbassadorFunctionDescriptor | HostModule<any, any> | EventDefinition<any> | ServicePluginDefinition<any> | {
196
+ [key: string]: Descriptors | PublicMetadata | any;
197
+ };
198
+ /**
199
+ * This type takes in a descriptors object of a certain Host (including an `unknown` host)
200
+ * and returns an object with the same structure, but with all descriptors replaced with their API.
201
+ * Any non-descriptor properties are removed from the returned object, including descriptors that
202
+ * do not match the given host (as they will not work with the given host).
203
+ */
204
+ type BuildDescriptors<T extends Descriptors, H extends Host<any> | undefined, Depth extends number = 5> = {
205
+ done: T;
206
+ recurse: T extends {
207
+ __type: typeof SERVICE_PLUGIN_ERROR_TYPE;
208
+ } ? never : T extends AmbassadorFunctionDescriptor ? BuildAmbassadorFunction<T> : T extends RESTFunctionDescriptor ? BuildRESTFunction<T> : T extends EventDefinition<any> ? BuildEventDefinition<T> : T extends ServicePluginDefinition<any> ? BuildServicePluginDefinition<T> : T extends HostModule<any, any> ? HostModuleAPI<T> : ConditionalExcept<{
209
+ [Key in keyof T]: T[Key] extends Descriptors ? BuildDescriptors<T[Key], H, [
210
+ -1,
211
+ 0,
212
+ 1,
213
+ 2,
214
+ 3,
215
+ 4,
216
+ 5
217
+ ][Depth]> : never;
218
+ }, EmptyObject>;
219
+ }[Depth extends -1 ? 'done' : 'recurse'];
220
+ type PublicMetadata = {
221
+ PACKAGE_NAME?: string;
222
+ };
223
+
224
+ declare global {
225
+ interface ContextualClient {
226
+ }
227
+ }
228
+ /**
229
+ * A type used to create concerete types from SDK descriptors in
230
+ * case a contextual client is available.
231
+ */
232
+ type MaybeContext<T extends Descriptors> = globalThis.ContextualClient extends {
233
+ host: Host;
234
+ } ? BuildDescriptors<T, globalThis.ContextualClient['host']> : T;
235
+
236
+ /**
237
+ * Expose fields based on the current exposure toggle.
238
+ * @param T - The type to expose fields from.
239
+ * @param FieldsScope - A map of fields to their exposure scope, missing fields are considered public.
240
+ * @example Exposure toggle not set:
241
+ * ```ts
242
+ * type MyType = {
243
+ * publicField: string;
244
+ * alphaField: string;
245
+ * };
246
+ *
247
+ * type ExposedType = ExposeFieldsBasedOnToggle<MyType, { alphaField: 'alpha' }>;
248
+ * // ExposedType = { publicField: string; }
249
+ * ```
250
+ * @example Exposure toggle set to alpha:
251
+ * ```ts
252
+ * declare global {
253
+ * interface SDKExposureToggle {
254
+ * alpha: true;
255
+ * }
256
+ * }
257
+ *
258
+ * type MyType = {
259
+ * publicField: string;
260
+ * alphaField: string;
261
+ * };
262
+ *
263
+ * type ExposedType = ExposeFieldsBasedOnToggle<MyType, { alphaField: 'alpha' }>;
264
+ * // ExposedType = { publicField: string; alphaField: string; }
265
+ */
266
+ type ExposeFieldsBasedOnToggle<T extends Record<string, any>, FieldsScope extends Partial<Record<keyof T, Exposure>>> = Simplify<{
267
+ [K in keyof T as IsExposed<K, FieldsScope[K] extends Exposure ? FieldsScope[K] : 'public'>]: T[K];
268
+ }>;
269
+ declare global {
270
+ /**
271
+ * A global interface to set the exposure toggle for the SDK.
272
+ * @example
273
+ * ```ts
274
+ * declare global {
275
+ * interface SDKExposureToggle {
276
+ * alpha: true;
277
+ * }
278
+ * }
279
+ */
280
+ interface SDKExposureToggle {
281
+ }
282
+ }
283
+ type Exposure = 'alpha' | 'public';
284
+ type IsExposed<T, Scope extends Exposure> = Scope extends 'public' ? T : globalThis.SDKExposureToggle extends {
285
+ alpha: true;
286
+ } ? T : never;
287
+
288
+ declare global {
289
+ /**
290
+ * A global interface to set the type mode for the SDK.
291
+ * @example
292
+ * ```ts
293
+ * declare global {
294
+ * interface SDKTypeMode {
295
+ * strict: true;
296
+ * }
297
+ * }
298
+ */
299
+ interface SDKTypeMode {
300
+ }
301
+ }
302
+ type NonNullablePaths<T, K extends Paths<T>> = globalThis.SDKTypeMode extends {
303
+ strict: true;
304
+ } ? SetRequiredDeep<T, K> : T;
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 };
@@ -0,0 +1,306 @@
1
+ import { MonitoringClient } from '@wix/monitoring-types';
2
+ import { ConditionalExcept, EmptyObject, Simplify, Paths, SetRequiredDeep } from 'type-fest';
3
+
4
+ type HostModule<T, H extends Host> = {
5
+ __type: 'host';
6
+ create(host: H): T;
7
+ };
8
+ type HostModuleAPI<T extends HostModule<any, any>> = T extends HostModule<infer U, any> ? U : never;
9
+ type Host<Environment = unknown> = {
10
+ channel?: {
11
+ observeState(callback: (props: unknown, environment: Environment) => unknown): {
12
+ disconnect: () => void;
13
+ } | Promise<{
14
+ disconnect: () => void;
15
+ }>;
16
+ };
17
+ environment?: Environment;
18
+ /**
19
+ * Optional name of the environment, use for logging
20
+ */
21
+ name?: string;
22
+ /**
23
+ * Optional bast url to use for API requests, for example `www.wixapis.com`
24
+ */
25
+ apiBaseUrl?: string;
26
+ /**
27
+ * Optional function to get a monitoring client
28
+ */
29
+ getMonitoringClient?: () => MonitoringClient;
30
+ /**
31
+ * Possible data to be provided by every host, for cross cutting concerns
32
+ * like internationalization, billing, etc.
33
+ */
34
+ essentials?: {
35
+ /**
36
+ * The language of the currently viewed session
37
+ */
38
+ language?: string;
39
+ /**
40
+ * The locale of the currently viewed session
41
+ */
42
+ locale?: string;
43
+ /**
44
+ * Any headers that should be passed through to the API requests
45
+ */
46
+ passThroughHeaders?: Record<string, string>;
47
+ };
48
+ };
49
+
50
+ type HTTPMethod = 'POST' | 'GET' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS';
51
+ type RESTFunctionDescriptor<T extends (...args: any[]) => any = (...args: any[]) => any> = (httpClient: HttpClient) => T;
52
+ interface HttpClient {
53
+ request<TResponse, TData = any>(req: RequestOptionsFactory<TResponse, TData>): Promise<HttpResponse<TResponse>>;
54
+ fetchWithAuth: typeof fetch;
55
+ wixAPIFetch: (relativeUrl: string, options: RequestInit) => Promise<Response>;
56
+ getActiveToken?: () => string | undefined;
57
+ }
58
+ type RequestOptionsFactory<TResponse = any, TData = any> = (context: any) => RequestOptions<TResponse, TData>;
59
+ type HttpResponse<T = any> = {
60
+ data: T;
61
+ status: number;
62
+ statusText: string;
63
+ headers: any;
64
+ request?: any;
65
+ };
66
+ type RequestOptions<_TResponse = any, Data = any> = {
67
+ method: HTTPMethod;
68
+ url: string;
69
+ data?: Data;
70
+ params?: URLSearchParams;
71
+ } & APIMetadata;
72
+ type APIMetadata = {
73
+ methodFqn?: string;
74
+ entityFqdn?: string;
75
+ packageName?: string;
76
+ };
77
+ type BuildRESTFunction<T extends RESTFunctionDescriptor> = T extends RESTFunctionDescriptor<infer U> ? U : never;
78
+ type RestModuleMeta<TMethod extends HTTPMethod = HTTPMethod, TPathParams = unknown, RequestType = unknown, TOriginalRequestType = unknown, ResponseType = unknown, OriginalResponseType = unknown> = {
79
+ getUrl(context: {
80
+ host: string;
81
+ }): string;
82
+ httpMethod: TMethod;
83
+ pathParams: TPathParams;
84
+ path: string;
85
+ __requestType: RequestType;
86
+ __originalRequestType: TOriginalRequestType;
87
+ __responseType: ResponseType;
88
+ __originalResponseType: OriginalResponseType;
89
+ };
90
+
91
+ type AuthenticationStrategy<Host = unknown> = {
92
+ getAuthHeaders: (host: Host) => Promise<{
93
+ headers: Record<string, string>;
94
+ }> | {
95
+ headers: Record<string, string>;
96
+ };
97
+ decodeJWT?: (token: string, verifyCallerClaims?: boolean) => Promise<{
98
+ decoded: {
99
+ data: unknown;
100
+ };
101
+ valid: boolean;
102
+ }>;
103
+ /**
104
+ * This function is used to get the token that is currently active in the context of the strategy.
105
+ * This is useful when direct access to the access token is needed
106
+ * (such as getTokenInfo that requires the token in the body of the request).
107
+ * @returns the token that is currently active in the context of the strategy
108
+ */
109
+ getActiveToken?: () => string | undefined;
110
+ };
111
+ type BoundAuthenticationStrategy = {
112
+ getAuthHeaders: () => Promise<{
113
+ headers: Record<string, string>;
114
+ }> | {
115
+ headers: Record<string, string>;
116
+ };
117
+ };
118
+
119
+ type EventIdentity = {
120
+ identityType: 'ANONYMOUS_VISITOR' | 'MEMBER' | 'WIX_USER' | 'APP';
121
+ anonymousVisitorId: string;
122
+ memberId: string;
123
+ wixUserId: string;
124
+ appId: string;
125
+ };
126
+ type BaseEventMetadata = {
127
+ instanceId: string;
128
+ identity?: EventIdentity;
129
+ };
130
+ type EventDefinition<Payload = unknown, Type extends string = string> = {
131
+ __type: 'event-definition';
132
+ type: Type;
133
+ isDomainEvent?: boolean;
134
+ transformations?: (envelope: unknown) => Payload;
135
+ __payload: Payload;
136
+ };
137
+ declare function EventDefinition<Type extends string>(type: Type, isDomainEvent?: boolean, transformations?: (envelope: any) => unknown): <Payload = unknown>() => EventDefinition<Payload, Type>;
138
+ type EventHandler<T extends EventDefinition> = (payload: T['__payload']) => void | Promise<void>;
139
+ type BuildEventDefinition<T extends EventDefinition<any, string>> = (handler: EventHandler<T>) => void;
140
+
141
+ type ServicePluginMethodInput = {
142
+ request: any;
143
+ metadata: any;
144
+ };
145
+ type ServicePluginContract = Record<string, (payload: ServicePluginMethodInput) => unknown | Promise<unknown>>;
146
+ type ServicePluginMethodMetadata = {
147
+ name: string;
148
+ primaryHttpMappingPath: string;
149
+ transformations: {
150
+ fromREST: (...args: unknown[]) => ServicePluginMethodInput;
151
+ toREST: (...args: unknown[]) => unknown;
152
+ };
153
+ };
154
+ type ServicePluginDefinition<Contract extends ServicePluginContract> = {
155
+ __type: 'service-plugin-definition';
156
+ componentType: string;
157
+ methods: ServicePluginMethodMetadata[];
158
+ __contract: Contract;
159
+ };
160
+ declare function ServicePluginDefinition<Contract extends ServicePluginContract>(componentType: string, methods: ServicePluginMethodMetadata[]): ServicePluginDefinition<Contract>;
161
+ type BuildServicePluginDefinition<T extends ServicePluginDefinition<any>> = (implementation: T['__contract']) => void;
162
+ declare const SERVICE_PLUGIN_ERROR_TYPE = "wix_spi_error";
163
+
164
+ type RequestContext = {
165
+ isSSR: boolean;
166
+ host: string;
167
+ protocol?: string;
168
+ };
169
+ type ResponseTransformer = (data: any, headers?: any) => any;
170
+ /**
171
+ * Ambassador request options types are copied mostly from AxiosRequestConfig.
172
+ * They are copied and not imported to reduce the amount of dependencies (to reduce install time).
173
+ * https://github.com/axios/axios/blob/3f53eb6960f05a1f88409c4b731a40de595cb825/index.d.ts#L307-L315
174
+ */
175
+ type Method = 'get' | 'GET' | 'delete' | 'DELETE' | 'head' | 'HEAD' | 'options' | 'OPTIONS' | 'post' | 'POST' | 'put' | 'PUT' | 'patch' | 'PATCH' | 'purge' | 'PURGE' | 'link' | 'LINK' | 'unlink' | 'UNLINK';
176
+ type AmbassadorRequestOptions<T = any> = {
177
+ _?: T;
178
+ url?: string;
179
+ method?: Method;
180
+ params?: any;
181
+ data?: any;
182
+ transformResponse?: ResponseTransformer | ResponseTransformer[];
183
+ };
184
+ type AmbassadorFactory<Request, Response> = (payload: Request) => ((context: RequestContext) => AmbassadorRequestOptions<Response>) & {
185
+ __isAmbassador: boolean;
186
+ };
187
+ type AmbassadorFunctionDescriptor<Request = any, Response = any> = AmbassadorFactory<Request, Response>;
188
+ type BuildAmbassadorFunction<T extends AmbassadorFunctionDescriptor> = T extends AmbassadorFunctionDescriptor<infer Request, infer Response> ? (req: Request) => Promise<Response> : never;
189
+
190
+ /**
191
+ * Descriptors are objects that describe the API of a module, and the module
192
+ * can either be a REST module or a host module.
193
+ * This type is recursive, so it can describe nested modules.
194
+ */
195
+ type Descriptors = RESTFunctionDescriptor | AmbassadorFunctionDescriptor | HostModule<any, any> | EventDefinition<any> | ServicePluginDefinition<any> | {
196
+ [key: string]: Descriptors | PublicMetadata | any;
197
+ };
198
+ /**
199
+ * This type takes in a descriptors object of a certain Host (including an `unknown` host)
200
+ * and returns an object with the same structure, but with all descriptors replaced with their API.
201
+ * Any non-descriptor properties are removed from the returned object, including descriptors that
202
+ * do not match the given host (as they will not work with the given host).
203
+ */
204
+ type BuildDescriptors<T extends Descriptors, H extends Host<any> | undefined, Depth extends number = 5> = {
205
+ done: T;
206
+ recurse: T extends {
207
+ __type: typeof SERVICE_PLUGIN_ERROR_TYPE;
208
+ } ? never : T extends AmbassadorFunctionDescriptor ? BuildAmbassadorFunction<T> : T extends RESTFunctionDescriptor ? BuildRESTFunction<T> : T extends EventDefinition<any> ? BuildEventDefinition<T> : T extends ServicePluginDefinition<any> ? BuildServicePluginDefinition<T> : T extends HostModule<any, any> ? HostModuleAPI<T> : ConditionalExcept<{
209
+ [Key in keyof T]: T[Key] extends Descriptors ? BuildDescriptors<T[Key], H, [
210
+ -1,
211
+ 0,
212
+ 1,
213
+ 2,
214
+ 3,
215
+ 4,
216
+ 5
217
+ ][Depth]> : never;
218
+ }, EmptyObject>;
219
+ }[Depth extends -1 ? 'done' : 'recurse'];
220
+ type PublicMetadata = {
221
+ PACKAGE_NAME?: string;
222
+ };
223
+
224
+ declare global {
225
+ interface ContextualClient {
226
+ }
227
+ }
228
+ /**
229
+ * A type used to create concerete types from SDK descriptors in
230
+ * case a contextual client is available.
231
+ */
232
+ type MaybeContext<T extends Descriptors> = globalThis.ContextualClient extends {
233
+ host: Host;
234
+ } ? BuildDescriptors<T, globalThis.ContextualClient['host']> : T;
235
+
236
+ /**
237
+ * Expose fields based on the current exposure toggle.
238
+ * @param T - The type to expose fields from.
239
+ * @param FieldsScope - A map of fields to their exposure scope, missing fields are considered public.
240
+ * @example Exposure toggle not set:
241
+ * ```ts
242
+ * type MyType = {
243
+ * publicField: string;
244
+ * alphaField: string;
245
+ * };
246
+ *
247
+ * type ExposedType = ExposeFieldsBasedOnToggle<MyType, { alphaField: 'alpha' }>;
248
+ * // ExposedType = { publicField: string; }
249
+ * ```
250
+ * @example Exposure toggle set to alpha:
251
+ * ```ts
252
+ * declare global {
253
+ * interface SDKExposureToggle {
254
+ * alpha: true;
255
+ * }
256
+ * }
257
+ *
258
+ * type MyType = {
259
+ * publicField: string;
260
+ * alphaField: string;
261
+ * };
262
+ *
263
+ * type ExposedType = ExposeFieldsBasedOnToggle<MyType, { alphaField: 'alpha' }>;
264
+ * // ExposedType = { publicField: string; alphaField: string; }
265
+ */
266
+ type ExposeFieldsBasedOnToggle<T extends Record<string, any>, FieldsScope extends Partial<Record<keyof T, Exposure>>> = Simplify<{
267
+ [K in keyof T as IsExposed<K, FieldsScope[K] extends Exposure ? FieldsScope[K] : 'public'>]: T[K];
268
+ }>;
269
+ declare global {
270
+ /**
271
+ * A global interface to set the exposure toggle for the SDK.
272
+ * @example
273
+ * ```ts
274
+ * declare global {
275
+ * interface SDKExposureToggle {
276
+ * alpha: true;
277
+ * }
278
+ * }
279
+ */
280
+ interface SDKExposureToggle {
281
+ }
282
+ }
283
+ type Exposure = 'alpha' | 'public';
284
+ type IsExposed<T, Scope extends Exposure> = Scope extends 'public' ? T : globalThis.SDKExposureToggle extends {
285
+ alpha: true;
286
+ } ? T : never;
287
+
288
+ declare global {
289
+ /**
290
+ * A global interface to set the type mode for the SDK.
291
+ * @example
292
+ * ```ts
293
+ * declare global {
294
+ * interface SDKTypeMode {
295
+ * strict: true;
296
+ * }
297
+ * }
298
+ */
299
+ interface SDKTypeMode {
300
+ }
301
+ }
302
+ type NonNullablePaths<T, K extends Paths<T>> = globalThis.SDKTypeMode extends {
303
+ strict: true;
304
+ } ? SetRequiredDeep<T, K> : T;
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 };
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ EventDefinition: () => EventDefinition,
24
+ SERVICE_PLUGIN_ERROR_TYPE: () => SERVICE_PLUGIN_ERROR_TYPE,
25
+ ServicePluginDefinition: () => ServicePluginDefinition
26
+ });
27
+ module.exports = __toCommonJS(src_exports);
28
+
29
+ // src/event-handlers-modules.ts
30
+ function EventDefinition(type, isDomainEvent = false, transformations = (x) => x) {
31
+ return () => ({
32
+ __type: "event-definition",
33
+ type,
34
+ isDomainEvent,
35
+ transformations
36
+ });
37
+ }
38
+
39
+ // src/service-plugins.ts
40
+ function ServicePluginDefinition(componentType, methods) {
41
+ return {
42
+ __type: "service-plugin-definition",
43
+ componentType,
44
+ methods
45
+ };
46
+ }
47
+ var SERVICE_PLUGIN_ERROR_TYPE = "wix_spi_error";
48
+ // Annotate the CommonJS export names for ESM import in node:
49
+ 0 && (module.exports = {
50
+ EventDefinition,
51
+ SERVICE_PLUGIN_ERROR_TYPE,
52
+ ServicePluginDefinition
53
+ });
@@ -0,0 +1,24 @@
1
+ // src/event-handlers-modules.ts
2
+ function EventDefinition(type, isDomainEvent = false, transformations = (x) => x) {
3
+ return () => ({
4
+ __type: "event-definition",
5
+ type,
6
+ isDomainEvent,
7
+ transformations
8
+ });
9
+ }
10
+
11
+ // src/service-plugins.ts
12
+ function ServicePluginDefinition(componentType, methods) {
13
+ return {
14
+ __type: "service-plugin-definition",
15
+ componentType,
16
+ methods
17
+ };
18
+ }
19
+ var SERVICE_PLUGIN_ERROR_TYPE = "wix_spi_error";
20
+ export {
21
+ EventDefinition,
22
+ SERVICE_PLUGIN_ERROR_TYPE,
23
+ ServicePluginDefinition
24
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/sdk-types",
3
- "version": "1.13.10",
3
+ "version": "1.13.11",
4
4
  "license": "MIT",
5
5
  "author": {
6
6
  "name": "Ronny Ringel",
@@ -12,7 +12,8 @@
12
12
  "sideEffects": false,
13
13
  "types": "build/index.d.ts",
14
14
  "files": [
15
- "build"
15
+ "build",
16
+ "internal"
16
17
  ],
17
18
  "publishConfig": {
18
19
  "registry": "https://registry.npmjs.org/",
@@ -28,8 +29,8 @@
28
29
  "*.{js,ts}": "yarn lint"
29
30
  },
30
31
  "dependencies": {
31
- "@wix/monitoring-types": "^0.9.0",
32
- "type-fest": "^4.39.1"
32
+ "@wix/monitoring-types": "^0.11.0",
33
+ "type-fest": "^4.40.0"
33
34
  },
34
35
  "devDependencies": {
35
36
  "@types/node": "^20.17.30",
@@ -58,5 +59,5 @@
58
59
  "wallaby": {
59
60
  "autoDetect": true
60
61
  },
61
- "falconPackageHash": "9ec9f6c5d82a51e1cc66fe5f22349d851e2a72cf72868b4f35e9effb"
62
+ "falconPackageHash": "0c110c68c82059edb9b2b53f65cb4b1db622090d2045ae67ca04468b"
62
63
  }