@wix/notifications 1.0.35 → 1.0.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,29 +1,127 @@
1
- type RESTFunctionDescriptor<T extends (...args: any[]) => any = (...args: any[]) => any> = (httpClient: HttpClient) => T;
2
- interface HttpClient {
3
- request<TResponse, TData = any>(req: RequestOptionsFactory<TResponse, TData>): Promise<HttpResponse<TResponse>>;
1
+ type HostModule$1<T, H extends Host$1> = {
2
+ __type: 'host';
3
+ create(host: H): T;
4
+ };
5
+ type HostModuleAPI$1<T extends HostModule$1<any, any>> = T extends HostModule$1<infer U, any> ? U : never;
6
+ type Host$1<Environment = unknown> = {
7
+ channel: {
8
+ observeState(callback: (props: unknown, environment: Environment) => unknown): {
9
+ disconnect: () => void;
10
+ } | Promise<{
11
+ disconnect: () => void;
12
+ }>;
13
+ };
14
+ environment?: Environment;
15
+ /**
16
+ * Optional bast url to use for API requests, for example `www.wixapis.com`
17
+ */
18
+ apiBaseUrl?: string;
19
+ /**
20
+ * Possible data to be provided by every host, for cross cutting concerns
21
+ * like internationalization, billing, etc.
22
+ */
23
+ essentials?: {
24
+ /**
25
+ * The language of the currently viewed session
26
+ */
27
+ language?: string;
28
+ /**
29
+ * The locale of the currently viewed session
30
+ */
31
+ locale?: string;
32
+ /**
33
+ * Any headers that should be passed through to the API requests
34
+ */
35
+ passThroughHeaders?: Record<string, string>;
36
+ };
37
+ };
38
+
39
+ type RESTFunctionDescriptor$1<T extends (...args: any[]) => any = (...args: any[]) => any> = (httpClient: HttpClient$1) => T;
40
+ interface HttpClient$1 {
41
+ request<TResponse, TData = any>(req: RequestOptionsFactory$1<TResponse, TData>): Promise<HttpResponse$1<TResponse>>;
4
42
  fetchWithAuth: typeof fetch;
5
43
  wixAPIFetch: (relativeUrl: string, options: RequestInit) => Promise<Response>;
44
+ getActiveToken?: () => string | undefined;
6
45
  }
7
- type RequestOptionsFactory<TResponse = any, TData = any> = (context: any) => RequestOptions<TResponse, TData>;
8
- type HttpResponse<T = any> = {
46
+ type RequestOptionsFactory$1<TResponse = any, TData = any> = (context: any) => RequestOptions$1<TResponse, TData>;
47
+ type HttpResponse$1<T = any> = {
9
48
  data: T;
10
49
  status: number;
11
50
  statusText: string;
12
51
  headers: any;
13
52
  request?: any;
14
53
  };
15
- type RequestOptions<_TResponse = any, Data = any> = {
54
+ type RequestOptions$1<_TResponse = any, Data = any> = {
16
55
  method: 'POST' | 'GET' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS';
17
56
  url: string;
18
57
  data?: Data;
19
58
  params?: URLSearchParams;
20
- } & APIMetadata;
21
- type APIMetadata = {
59
+ } & APIMetadata$1;
60
+ type APIMetadata$1 = {
22
61
  methodFqn?: string;
23
62
  entityFqdn?: string;
24
63
  packageName?: string;
25
64
  };
26
- type BuildRESTFunction<T extends RESTFunctionDescriptor> = T extends RESTFunctionDescriptor<infer U> ? U : never;
65
+ type BuildRESTFunction$1<T extends RESTFunctionDescriptor$1> = T extends RESTFunctionDescriptor$1<infer U> ? U : never;
66
+ type EventDefinition$1<Payload = unknown, Type extends string = string> = {
67
+ __type: 'event-definition';
68
+ type: Type;
69
+ isDomainEvent?: boolean;
70
+ transformations?: (envelope: unknown) => Payload;
71
+ __payload: Payload;
72
+ };
73
+ declare function EventDefinition$1<Type extends string>(type: Type, isDomainEvent?: boolean, transformations?: (envelope: any) => unknown): <Payload = unknown>() => EventDefinition$1<Payload, Type>;
74
+ type EventHandler$1<T extends EventDefinition$1> = (payload: T['__payload']) => void | Promise<void>;
75
+ type BuildEventDefinition$1<T extends EventDefinition$1<any, string>> = (handler: EventHandler$1<T>) => void;
76
+
77
+ type ServicePluginMethodInput$1 = {
78
+ request: any;
79
+ metadata: any;
80
+ };
81
+ type ServicePluginContract$1 = Record<string, (payload: ServicePluginMethodInput$1) => unknown | Promise<unknown>>;
82
+ type ServicePluginMethodMetadata$1 = {
83
+ name: string;
84
+ primaryHttpMappingPath: string;
85
+ transformations: {
86
+ fromREST: (...args: unknown[]) => ServicePluginMethodInput$1;
87
+ toREST: (...args: unknown[]) => unknown;
88
+ };
89
+ };
90
+ type ServicePluginDefinition$1<Contract extends ServicePluginContract$1> = {
91
+ __type: 'service-plugin-definition';
92
+ componentType: string;
93
+ methods: ServicePluginMethodMetadata$1[];
94
+ __contract: Contract;
95
+ };
96
+ declare function ServicePluginDefinition$1<Contract extends ServicePluginContract$1>(componentType: string, methods: ServicePluginMethodMetadata$1[]): ServicePluginDefinition$1<Contract>;
97
+ type BuildServicePluginDefinition$1<T extends ServicePluginDefinition$1<any>> = (implementation: T['__contract']) => void;
98
+ declare const SERVICE_PLUGIN_ERROR_TYPE$1 = "wix_spi_error";
99
+
100
+ type RequestContext$1 = {
101
+ isSSR: boolean;
102
+ host: string;
103
+ protocol?: string;
104
+ };
105
+ type ResponseTransformer$1 = (data: any, headers?: any) => any;
106
+ /**
107
+ * Ambassador request options types are copied mostly from AxiosRequestConfig.
108
+ * They are copied and not imported to reduce the amount of dependencies (to reduce install time).
109
+ * https://github.com/axios/axios/blob/3f53eb6960f05a1f88409c4b731a40de595cb825/index.d.ts#L307-L315
110
+ */
111
+ type Method$1 = 'get' | 'GET' | 'delete' | 'DELETE' | 'head' | 'HEAD' | 'options' | 'OPTIONS' | 'post' | 'POST' | 'put' | 'PUT' | 'patch' | 'PATCH' | 'purge' | 'PURGE' | 'link' | 'LINK' | 'unlink' | 'UNLINK';
112
+ type AmbassadorRequestOptions$1<T = any> = {
113
+ _?: T;
114
+ url?: string;
115
+ method?: Method$1;
116
+ params?: any;
117
+ data?: any;
118
+ transformResponse?: ResponseTransformer$1 | ResponseTransformer$1[];
119
+ };
120
+ type AmbassadorFactory$1<Request, Response> = (payload: Request) => ((context: RequestContext$1) => AmbassadorRequestOptions$1<Response>) & {
121
+ __isAmbassador: boolean;
122
+ };
123
+ type AmbassadorFunctionDescriptor$1<Request = any, Response = any> = AmbassadorFactory$1<Request, Response>;
124
+ type BuildAmbassadorFunction$1<T extends AmbassadorFunctionDescriptor$1> = T extends AmbassadorFunctionDescriptor$1<infer Request, infer Response> ? (req: Request) => Promise<Response> : never;
27
125
 
28
126
  declare global {
29
127
  // eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
@@ -32,6 +130,284 @@ declare global {
32
130
  }
33
131
  }
34
132
 
133
+ declare const emptyObjectSymbol$1: unique symbol;
134
+
135
+ /**
136
+ Represents a strictly empty plain object, the `{}` value.
137
+
138
+ When you annotate something as the type `{}`, it can be anything except `null` and `undefined`. This means that you cannot use `{}` to represent an empty plain object ([read more](https://stackoverflow.com/questions/47339869/typescript-empty-object-and-any-difference/52193484#52193484)).
139
+
140
+ @example
141
+ ```
142
+ import type {EmptyObject} from 'type-fest';
143
+
144
+ // The following illustrates the problem with `{}`.
145
+ const foo1: {} = {}; // Pass
146
+ const foo2: {} = []; // Pass
147
+ const foo3: {} = 42; // Pass
148
+ const foo4: {} = {a: 1}; // Pass
149
+
150
+ // With `EmptyObject` only the first case is valid.
151
+ const bar1: EmptyObject = {}; // Pass
152
+ const bar2: EmptyObject = 42; // Fail
153
+ const bar3: EmptyObject = []; // Fail
154
+ const bar4: EmptyObject = {a: 1}; // Fail
155
+ ```
156
+
157
+ Unfortunately, `Record<string, never>`, `Record<keyof any, never>` and `Record<never, never>` do not work. See {@link https://github.com/sindresorhus/type-fest/issues/395 #395}.
158
+
159
+ @category Object
160
+ */
161
+ type EmptyObject$1 = {[emptyObjectSymbol$1]?: never};
162
+
163
+ /**
164
+ Returns a boolean for whether the two given types are equal.
165
+
166
+ @link https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650
167
+ @link https://stackoverflow.com/questions/68961864/how-does-the-equals-work-in-typescript/68963796#68963796
168
+
169
+ Use-cases:
170
+ - If you want to make a conditional branch based on the result of a comparison of two types.
171
+
172
+ @example
173
+ ```
174
+ import type {IsEqual} from 'type-fest';
175
+
176
+ // This type returns a boolean for whether the given array includes the given item.
177
+ // `IsEqual` is used to compare the given array at position 0 and the given item and then return true if they are equal.
178
+ type Includes<Value extends readonly any[], Item> =
179
+ Value extends readonly [Value[0], ...infer rest]
180
+ ? IsEqual<Value[0], Item> extends true
181
+ ? true
182
+ : Includes<rest, Item>
183
+ : false;
184
+ ```
185
+
186
+ @category Type Guard
187
+ @category Utilities
188
+ */
189
+ type IsEqual$1<A, B> =
190
+ (<G>() => G extends A ? 1 : 2) extends
191
+ (<G>() => G extends B ? 1 : 2)
192
+ ? true
193
+ : false;
194
+
195
+ /**
196
+ Filter out keys from an object.
197
+
198
+ Returns `never` if `Exclude` is strictly equal to `Key`.
199
+ Returns `never` if `Key` extends `Exclude`.
200
+ Returns `Key` otherwise.
201
+
202
+ @example
203
+ ```
204
+ type Filtered = Filter<'foo', 'foo'>;
205
+ //=> never
206
+ ```
207
+
208
+ @example
209
+ ```
210
+ type Filtered = Filter<'bar', string>;
211
+ //=> never
212
+ ```
213
+
214
+ @example
215
+ ```
216
+ type Filtered = Filter<'bar', 'foo'>;
217
+ //=> 'bar'
218
+ ```
219
+
220
+ @see {Except}
221
+ */
222
+ type Filter$1<KeyType, ExcludeType> = IsEqual$1<KeyType, ExcludeType> extends true ? never : (KeyType extends ExcludeType ? never : KeyType);
223
+
224
+ type ExceptOptions$1 = {
225
+ /**
226
+ Disallow assigning non-specified properties.
227
+
228
+ Note that any omitted properties in the resulting type will be present in autocomplete as `undefined`.
229
+
230
+ @default false
231
+ */
232
+ requireExactProps?: boolean;
233
+ };
234
+
235
+ /**
236
+ Create a type from an object type without certain keys.
237
+
238
+ We recommend setting the `requireExactProps` option to `true`.
239
+
240
+ This type is a stricter version of [`Omit`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-5.html#the-omit-helper-type). The `Omit` type does not restrict the omitted keys to be keys present on the given type, while `Except` does. The benefits of a stricter type are avoiding typos and allowing the compiler to pick up on rename refactors automatically.
241
+
242
+ This type was proposed to the TypeScript team, which declined it, saying they prefer that libraries implement stricter versions of the built-in types ([microsoft/TypeScript#30825](https://github.com/microsoft/TypeScript/issues/30825#issuecomment-523668235)).
243
+
244
+ @example
245
+ ```
246
+ import type {Except} from 'type-fest';
247
+
248
+ type Foo = {
249
+ a: number;
250
+ b: string;
251
+ };
252
+
253
+ type FooWithoutA = Except<Foo, 'a'>;
254
+ //=> {b: string}
255
+
256
+ const fooWithoutA: FooWithoutA = {a: 1, b: '2'};
257
+ //=> errors: 'a' does not exist in type '{ b: string; }'
258
+
259
+ type FooWithoutB = Except<Foo, 'b', {requireExactProps: true}>;
260
+ //=> {a: number} & Partial<Record<"b", never>>
261
+
262
+ const fooWithoutB: FooWithoutB = {a: 1, b: '2'};
263
+ //=> errors at 'b': Type 'string' is not assignable to type 'undefined'.
264
+ ```
265
+
266
+ @category Object
267
+ */
268
+ type Except$1<ObjectType, KeysType extends keyof ObjectType, Options extends ExceptOptions$1 = {requireExactProps: false}> = {
269
+ [KeyType in keyof ObjectType as Filter$1<KeyType, KeysType>]: ObjectType[KeyType];
270
+ } & (Options['requireExactProps'] extends true
271
+ ? Partial<Record<KeysType, never>>
272
+ : {});
273
+
274
+ /**
275
+ Extract the keys from a type where the value type of the key extends the given `Condition`.
276
+
277
+ Internally this is used for the `ConditionalPick` and `ConditionalExcept` types.
278
+
279
+ @example
280
+ ```
281
+ import type {ConditionalKeys} from 'type-fest';
282
+
283
+ interface Example {
284
+ a: string;
285
+ b: string | number;
286
+ c?: string;
287
+ d: {};
288
+ }
289
+
290
+ type StringKeysOnly = ConditionalKeys<Example, string>;
291
+ //=> 'a'
292
+ ```
293
+
294
+ To support partial types, make sure your `Condition` is a union of undefined (for example, `string | undefined`) as demonstrated below.
295
+
296
+ @example
297
+ ```
298
+ import type {ConditionalKeys} from 'type-fest';
299
+
300
+ type StringKeysAndUndefined = ConditionalKeys<Example, string | undefined>;
301
+ //=> 'a' | 'c'
302
+ ```
303
+
304
+ @category Object
305
+ */
306
+ type ConditionalKeys$1<Base, Condition> = NonNullable<
307
+ // Wrap in `NonNullable` to strip away the `undefined` type from the produced union.
308
+ {
309
+ // Map through all the keys of the given base type.
310
+ [Key in keyof Base]:
311
+ // Pick only keys with types extending the given `Condition` type.
312
+ Base[Key] extends Condition
313
+ // Retain this key since the condition passes.
314
+ ? Key
315
+ // Discard this key since the condition fails.
316
+ : never;
317
+
318
+ // Convert the produced object into a union type of the keys which passed the conditional test.
319
+ }[keyof Base]
320
+ >;
321
+
322
+ /**
323
+ Exclude keys from a shape that matches the given `Condition`.
324
+
325
+ This is useful when you want to create a new type with a specific set of keys from a shape. For example, you might want to exclude all the primitive properties from a class and form a new shape containing everything but the primitive properties.
326
+
327
+ @example
328
+ ```
329
+ import type {Primitive, ConditionalExcept} from 'type-fest';
330
+
331
+ class Awesome {
332
+ name: string;
333
+ successes: number;
334
+ failures: bigint;
335
+
336
+ run() {}
337
+ }
338
+
339
+ type ExceptPrimitivesFromAwesome = ConditionalExcept<Awesome, Primitive>;
340
+ //=> {run: () => void}
341
+ ```
342
+
343
+ @example
344
+ ```
345
+ import type {ConditionalExcept} from 'type-fest';
346
+
347
+ interface Example {
348
+ a: string;
349
+ b: string | number;
350
+ c: () => void;
351
+ d: {};
352
+ }
353
+
354
+ type NonStringKeysOnly = ConditionalExcept<Example, string>;
355
+ //=> {b: string | number; c: () => void; d: {}}
356
+ ```
357
+
358
+ @category Object
359
+ */
360
+ type ConditionalExcept$1<Base, Condition> = Except$1<
361
+ Base,
362
+ ConditionalKeys$1<Base, Condition>
363
+ >;
364
+
365
+ /**
366
+ * Descriptors are objects that describe the API of a module, and the module
367
+ * can either be a REST module or a host module.
368
+ * This type is recursive, so it can describe nested modules.
369
+ */
370
+ type Descriptors$1 = RESTFunctionDescriptor$1 | AmbassadorFunctionDescriptor$1 | HostModule$1<any, any> | EventDefinition$1<any> | ServicePluginDefinition$1<any> | {
371
+ [key: string]: Descriptors$1 | PublicMetadata$1 | any;
372
+ };
373
+ /**
374
+ * This type takes in a descriptors object of a certain Host (including an `unknown` host)
375
+ * and returns an object with the same structure, but with all descriptors replaced with their API.
376
+ * Any non-descriptor properties are removed from the returned object, including descriptors that
377
+ * do not match the given host (as they will not work with the given host).
378
+ */
379
+ type BuildDescriptors$1<T extends Descriptors$1, H extends Host$1<any> | undefined, Depth extends number = 5> = {
380
+ done: T;
381
+ recurse: T extends {
382
+ __type: typeof SERVICE_PLUGIN_ERROR_TYPE$1;
383
+ } ? never : T extends AmbassadorFunctionDescriptor$1 ? BuildAmbassadorFunction$1<T> : T extends RESTFunctionDescriptor$1 ? BuildRESTFunction$1<T> : T extends EventDefinition$1<any> ? BuildEventDefinition$1<T> : T extends ServicePluginDefinition$1<any> ? BuildServicePluginDefinition$1<T> : T extends HostModule$1<any, any> ? HostModuleAPI$1<T> : ConditionalExcept$1<{
384
+ [Key in keyof T]: T[Key] extends Descriptors$1 ? BuildDescriptors$1<T[Key], H, [
385
+ -1,
386
+ 0,
387
+ 1,
388
+ 2,
389
+ 3,
390
+ 4,
391
+ 5
392
+ ][Depth]> : never;
393
+ }, EmptyObject$1>;
394
+ }[Depth extends -1 ? 'done' : 'recurse'];
395
+ type PublicMetadata$1 = {
396
+ PACKAGE_NAME?: string;
397
+ };
398
+
399
+ declare global {
400
+ interface ContextualClient {
401
+ }
402
+ }
403
+ /**
404
+ * A type used to create concerete types from SDK descriptors in
405
+ * case a contextual client is available.
406
+ */
407
+ type MaybeContext$1<T extends Descriptors$1> = globalThis.ContextualClient extends {
408
+ host: Host$1;
409
+ } ? BuildDescriptors$1<T, globalThis.ContextualClient['host']> : T;
410
+
35
411
  interface Public_notification {
36
412
  /** Notification ID. */
37
413
  _id?: string | null;
@@ -151,7 +527,7 @@ interface NotifyOptions$1 extends PublicNotifyRequestRecipientsFilterOneOf, Publ
151
527
  targetDashboardPage?: DashboardPages;
152
528
  }
153
529
 
154
- declare function notify$3(httpClient: HttpClient): NotifySignature$1;
530
+ declare function notify$3(httpClient: HttpClient$1): NotifySignature$1;
155
531
  interface NotifySignature$1 {
156
532
  /**
157
533
  * Sends a notification.
@@ -176,7 +552,7 @@ interface NotifySignature$1 {
176
552
  (body: string | null, channels: Channel[], options?: NotifyOptions$1 | undefined): Promise<void>;
177
553
  }
178
554
 
179
- declare const notify$2: BuildRESTFunction<typeof notify$3> & typeof notify$3;
555
+ declare const notify$2: MaybeContext$1<BuildRESTFunction$1<typeof notify$3> & typeof notify$3>;
180
556
 
181
557
  type context$1_Channel = Channel;
182
558
  declare const context$1_Channel: typeof Channel;
@@ -196,6 +572,416 @@ declare namespace context$1 {
196
572
  export { context$1_Channel as Channel, context$1_DashboardPages as DashboardPages, type context$1_Empty as Empty, type NotifyOptions$1 as NotifyOptions, type context$1_PublicNotifyRequest as PublicNotifyRequest, type context$1_PublicNotifyRequestActionTargetOneOf as PublicNotifyRequestActionTargetOneOf, type context$1_PublicNotifyRequestRecipientsFilterOneOf as PublicNotifyRequestRecipientsFilterOneOf, type context$1_Public_notification as Public_notification, context$1_Role as Role, type context$1_ToContacts as ToContacts, type context$1_ToSiteContributors as ToSiteContributors, type context$1_ToTopicsSubscribers as ToTopicsSubscribers, notify$2 as notify };
197
573
  }
198
574
 
575
+ type HostModule<T, H extends Host> = {
576
+ __type: 'host';
577
+ create(host: H): T;
578
+ };
579
+ type HostModuleAPI<T extends HostModule<any, any>> = T extends HostModule<infer U, any> ? U : never;
580
+ type Host<Environment = unknown> = {
581
+ channel: {
582
+ observeState(callback: (props: unknown, environment: Environment) => unknown): {
583
+ disconnect: () => void;
584
+ } | Promise<{
585
+ disconnect: () => void;
586
+ }>;
587
+ };
588
+ environment?: Environment;
589
+ /**
590
+ * Optional bast url to use for API requests, for example `www.wixapis.com`
591
+ */
592
+ apiBaseUrl?: string;
593
+ /**
594
+ * Possible data to be provided by every host, for cross cutting concerns
595
+ * like internationalization, billing, etc.
596
+ */
597
+ essentials?: {
598
+ /**
599
+ * The language of the currently viewed session
600
+ */
601
+ language?: string;
602
+ /**
603
+ * The locale of the currently viewed session
604
+ */
605
+ locale?: string;
606
+ /**
607
+ * Any headers that should be passed through to the API requests
608
+ */
609
+ passThroughHeaders?: Record<string, string>;
610
+ };
611
+ };
612
+
613
+ type RESTFunctionDescriptor<T extends (...args: any[]) => any = (...args: any[]) => any> = (httpClient: HttpClient) => T;
614
+ interface HttpClient {
615
+ request<TResponse, TData = any>(req: RequestOptionsFactory<TResponse, TData>): Promise<HttpResponse<TResponse>>;
616
+ fetchWithAuth: typeof fetch;
617
+ wixAPIFetch: (relativeUrl: string, options: RequestInit) => Promise<Response>;
618
+ getActiveToken?: () => string | undefined;
619
+ }
620
+ type RequestOptionsFactory<TResponse = any, TData = any> = (context: any) => RequestOptions<TResponse, TData>;
621
+ type HttpResponse<T = any> = {
622
+ data: T;
623
+ status: number;
624
+ statusText: string;
625
+ headers: any;
626
+ request?: any;
627
+ };
628
+ type RequestOptions<_TResponse = any, Data = any> = {
629
+ method: 'POST' | 'GET' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS';
630
+ url: string;
631
+ data?: Data;
632
+ params?: URLSearchParams;
633
+ } & APIMetadata;
634
+ type APIMetadata = {
635
+ methodFqn?: string;
636
+ entityFqdn?: string;
637
+ packageName?: string;
638
+ };
639
+ type BuildRESTFunction<T extends RESTFunctionDescriptor> = T extends RESTFunctionDescriptor<infer U> ? U : never;
640
+ type EventDefinition<Payload = unknown, Type extends string = string> = {
641
+ __type: 'event-definition';
642
+ type: Type;
643
+ isDomainEvent?: boolean;
644
+ transformations?: (envelope: unknown) => Payload;
645
+ __payload: Payload;
646
+ };
647
+ declare function EventDefinition<Type extends string>(type: Type, isDomainEvent?: boolean, transformations?: (envelope: any) => unknown): <Payload = unknown>() => EventDefinition<Payload, Type>;
648
+ type EventHandler<T extends EventDefinition> = (payload: T['__payload']) => void | Promise<void>;
649
+ type BuildEventDefinition<T extends EventDefinition<any, string>> = (handler: EventHandler<T>) => void;
650
+
651
+ type ServicePluginMethodInput = {
652
+ request: any;
653
+ metadata: any;
654
+ };
655
+ type ServicePluginContract = Record<string, (payload: ServicePluginMethodInput) => unknown | Promise<unknown>>;
656
+ type ServicePluginMethodMetadata = {
657
+ name: string;
658
+ primaryHttpMappingPath: string;
659
+ transformations: {
660
+ fromREST: (...args: unknown[]) => ServicePluginMethodInput;
661
+ toREST: (...args: unknown[]) => unknown;
662
+ };
663
+ };
664
+ type ServicePluginDefinition<Contract extends ServicePluginContract> = {
665
+ __type: 'service-plugin-definition';
666
+ componentType: string;
667
+ methods: ServicePluginMethodMetadata[];
668
+ __contract: Contract;
669
+ };
670
+ declare function ServicePluginDefinition<Contract extends ServicePluginContract>(componentType: string, methods: ServicePluginMethodMetadata[]): ServicePluginDefinition<Contract>;
671
+ type BuildServicePluginDefinition<T extends ServicePluginDefinition<any>> = (implementation: T['__contract']) => void;
672
+ declare const SERVICE_PLUGIN_ERROR_TYPE = "wix_spi_error";
673
+
674
+ type RequestContext = {
675
+ isSSR: boolean;
676
+ host: string;
677
+ protocol?: string;
678
+ };
679
+ type ResponseTransformer = (data: any, headers?: any) => any;
680
+ /**
681
+ * Ambassador request options types are copied mostly from AxiosRequestConfig.
682
+ * They are copied and not imported to reduce the amount of dependencies (to reduce install time).
683
+ * https://github.com/axios/axios/blob/3f53eb6960f05a1f88409c4b731a40de595cb825/index.d.ts#L307-L315
684
+ */
685
+ type Method = 'get' | 'GET' | 'delete' | 'DELETE' | 'head' | 'HEAD' | 'options' | 'OPTIONS' | 'post' | 'POST' | 'put' | 'PUT' | 'patch' | 'PATCH' | 'purge' | 'PURGE' | 'link' | 'LINK' | 'unlink' | 'UNLINK';
686
+ type AmbassadorRequestOptions<T = any> = {
687
+ _?: T;
688
+ url?: string;
689
+ method?: Method;
690
+ params?: any;
691
+ data?: any;
692
+ transformResponse?: ResponseTransformer | ResponseTransformer[];
693
+ };
694
+ type AmbassadorFactory<Request, Response> = (payload: Request) => ((context: RequestContext) => AmbassadorRequestOptions<Response>) & {
695
+ __isAmbassador: boolean;
696
+ };
697
+ type AmbassadorFunctionDescriptor<Request = any, Response = any> = AmbassadorFactory<Request, Response>;
698
+ type BuildAmbassadorFunction<T extends AmbassadorFunctionDescriptor> = T extends AmbassadorFunctionDescriptor<infer Request, infer Response> ? (req: Request) => Promise<Response> : never;
699
+
700
+ declare global {
701
+ // eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
702
+ interface SymbolConstructor {
703
+ readonly observable: symbol;
704
+ }
705
+ }
706
+
707
+ declare const emptyObjectSymbol: unique symbol;
708
+
709
+ /**
710
+ Represents a strictly empty plain object, the `{}` value.
711
+
712
+ When you annotate something as the type `{}`, it can be anything except `null` and `undefined`. This means that you cannot use `{}` to represent an empty plain object ([read more](https://stackoverflow.com/questions/47339869/typescript-empty-object-and-any-difference/52193484#52193484)).
713
+
714
+ @example
715
+ ```
716
+ import type {EmptyObject} from 'type-fest';
717
+
718
+ // The following illustrates the problem with `{}`.
719
+ const foo1: {} = {}; // Pass
720
+ const foo2: {} = []; // Pass
721
+ const foo3: {} = 42; // Pass
722
+ const foo4: {} = {a: 1}; // Pass
723
+
724
+ // With `EmptyObject` only the first case is valid.
725
+ const bar1: EmptyObject = {}; // Pass
726
+ const bar2: EmptyObject = 42; // Fail
727
+ const bar3: EmptyObject = []; // Fail
728
+ const bar4: EmptyObject = {a: 1}; // Fail
729
+ ```
730
+
731
+ Unfortunately, `Record<string, never>`, `Record<keyof any, never>` and `Record<never, never>` do not work. See {@link https://github.com/sindresorhus/type-fest/issues/395 #395}.
732
+
733
+ @category Object
734
+ */
735
+ type EmptyObject = {[emptyObjectSymbol]?: never};
736
+
737
+ /**
738
+ Returns a boolean for whether the two given types are equal.
739
+
740
+ @link https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650
741
+ @link https://stackoverflow.com/questions/68961864/how-does-the-equals-work-in-typescript/68963796#68963796
742
+
743
+ Use-cases:
744
+ - If you want to make a conditional branch based on the result of a comparison of two types.
745
+
746
+ @example
747
+ ```
748
+ import type {IsEqual} from 'type-fest';
749
+
750
+ // This type returns a boolean for whether the given array includes the given item.
751
+ // `IsEqual` is used to compare the given array at position 0 and the given item and then return true if they are equal.
752
+ type Includes<Value extends readonly any[], Item> =
753
+ Value extends readonly [Value[0], ...infer rest]
754
+ ? IsEqual<Value[0], Item> extends true
755
+ ? true
756
+ : Includes<rest, Item>
757
+ : false;
758
+ ```
759
+
760
+ @category Type Guard
761
+ @category Utilities
762
+ */
763
+ type IsEqual<A, B> =
764
+ (<G>() => G extends A ? 1 : 2) extends
765
+ (<G>() => G extends B ? 1 : 2)
766
+ ? true
767
+ : false;
768
+
769
+ /**
770
+ Filter out keys from an object.
771
+
772
+ Returns `never` if `Exclude` is strictly equal to `Key`.
773
+ Returns `never` if `Key` extends `Exclude`.
774
+ Returns `Key` otherwise.
775
+
776
+ @example
777
+ ```
778
+ type Filtered = Filter<'foo', 'foo'>;
779
+ //=> never
780
+ ```
781
+
782
+ @example
783
+ ```
784
+ type Filtered = Filter<'bar', string>;
785
+ //=> never
786
+ ```
787
+
788
+ @example
789
+ ```
790
+ type Filtered = Filter<'bar', 'foo'>;
791
+ //=> 'bar'
792
+ ```
793
+
794
+ @see {Except}
795
+ */
796
+ type Filter<KeyType, ExcludeType> = IsEqual<KeyType, ExcludeType> extends true ? never : (KeyType extends ExcludeType ? never : KeyType);
797
+
798
+ type ExceptOptions = {
799
+ /**
800
+ Disallow assigning non-specified properties.
801
+
802
+ Note that any omitted properties in the resulting type will be present in autocomplete as `undefined`.
803
+
804
+ @default false
805
+ */
806
+ requireExactProps?: boolean;
807
+ };
808
+
809
+ /**
810
+ Create a type from an object type without certain keys.
811
+
812
+ We recommend setting the `requireExactProps` option to `true`.
813
+
814
+ This type is a stricter version of [`Omit`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-5.html#the-omit-helper-type). The `Omit` type does not restrict the omitted keys to be keys present on the given type, while `Except` does. The benefits of a stricter type are avoiding typos and allowing the compiler to pick up on rename refactors automatically.
815
+
816
+ This type was proposed to the TypeScript team, which declined it, saying they prefer that libraries implement stricter versions of the built-in types ([microsoft/TypeScript#30825](https://github.com/microsoft/TypeScript/issues/30825#issuecomment-523668235)).
817
+
818
+ @example
819
+ ```
820
+ import type {Except} from 'type-fest';
821
+
822
+ type Foo = {
823
+ a: number;
824
+ b: string;
825
+ };
826
+
827
+ type FooWithoutA = Except<Foo, 'a'>;
828
+ //=> {b: string}
829
+
830
+ const fooWithoutA: FooWithoutA = {a: 1, b: '2'};
831
+ //=> errors: 'a' does not exist in type '{ b: string; }'
832
+
833
+ type FooWithoutB = Except<Foo, 'b', {requireExactProps: true}>;
834
+ //=> {a: number} & Partial<Record<"b", never>>
835
+
836
+ const fooWithoutB: FooWithoutB = {a: 1, b: '2'};
837
+ //=> errors at 'b': Type 'string' is not assignable to type 'undefined'.
838
+ ```
839
+
840
+ @category Object
841
+ */
842
+ type Except<ObjectType, KeysType extends keyof ObjectType, Options extends ExceptOptions = {requireExactProps: false}> = {
843
+ [KeyType in keyof ObjectType as Filter<KeyType, KeysType>]: ObjectType[KeyType];
844
+ } & (Options['requireExactProps'] extends true
845
+ ? Partial<Record<KeysType, never>>
846
+ : {});
847
+
848
+ /**
849
+ Extract the keys from a type where the value type of the key extends the given `Condition`.
850
+
851
+ Internally this is used for the `ConditionalPick` and `ConditionalExcept` types.
852
+
853
+ @example
854
+ ```
855
+ import type {ConditionalKeys} from 'type-fest';
856
+
857
+ interface Example {
858
+ a: string;
859
+ b: string | number;
860
+ c?: string;
861
+ d: {};
862
+ }
863
+
864
+ type StringKeysOnly = ConditionalKeys<Example, string>;
865
+ //=> 'a'
866
+ ```
867
+
868
+ To support partial types, make sure your `Condition` is a union of undefined (for example, `string | undefined`) as demonstrated below.
869
+
870
+ @example
871
+ ```
872
+ import type {ConditionalKeys} from 'type-fest';
873
+
874
+ type StringKeysAndUndefined = ConditionalKeys<Example, string | undefined>;
875
+ //=> 'a' | 'c'
876
+ ```
877
+
878
+ @category Object
879
+ */
880
+ type ConditionalKeys<Base, Condition> = NonNullable<
881
+ // Wrap in `NonNullable` to strip away the `undefined` type from the produced union.
882
+ {
883
+ // Map through all the keys of the given base type.
884
+ [Key in keyof Base]:
885
+ // Pick only keys with types extending the given `Condition` type.
886
+ Base[Key] extends Condition
887
+ // Retain this key since the condition passes.
888
+ ? Key
889
+ // Discard this key since the condition fails.
890
+ : never;
891
+
892
+ // Convert the produced object into a union type of the keys which passed the conditional test.
893
+ }[keyof Base]
894
+ >;
895
+
896
+ /**
897
+ Exclude keys from a shape that matches the given `Condition`.
898
+
899
+ This is useful when you want to create a new type with a specific set of keys from a shape. For example, you might want to exclude all the primitive properties from a class and form a new shape containing everything but the primitive properties.
900
+
901
+ @example
902
+ ```
903
+ import type {Primitive, ConditionalExcept} from 'type-fest';
904
+
905
+ class Awesome {
906
+ name: string;
907
+ successes: number;
908
+ failures: bigint;
909
+
910
+ run() {}
911
+ }
912
+
913
+ type ExceptPrimitivesFromAwesome = ConditionalExcept<Awesome, Primitive>;
914
+ //=> {run: () => void}
915
+ ```
916
+
917
+ @example
918
+ ```
919
+ import type {ConditionalExcept} from 'type-fest';
920
+
921
+ interface Example {
922
+ a: string;
923
+ b: string | number;
924
+ c: () => void;
925
+ d: {};
926
+ }
927
+
928
+ type NonStringKeysOnly = ConditionalExcept<Example, string>;
929
+ //=> {b: string | number; c: () => void; d: {}}
930
+ ```
931
+
932
+ @category Object
933
+ */
934
+ type ConditionalExcept<Base, Condition> = Except<
935
+ Base,
936
+ ConditionalKeys<Base, Condition>
937
+ >;
938
+
939
+ /**
940
+ * Descriptors are objects that describe the API of a module, and the module
941
+ * can either be a REST module or a host module.
942
+ * This type is recursive, so it can describe nested modules.
943
+ */
944
+ type Descriptors = RESTFunctionDescriptor | AmbassadorFunctionDescriptor | HostModule<any, any> | EventDefinition<any> | ServicePluginDefinition<any> | {
945
+ [key: string]: Descriptors | PublicMetadata | any;
946
+ };
947
+ /**
948
+ * This type takes in a descriptors object of a certain Host (including an `unknown` host)
949
+ * and returns an object with the same structure, but with all descriptors replaced with their API.
950
+ * Any non-descriptor properties are removed from the returned object, including descriptors that
951
+ * do not match the given host (as they will not work with the given host).
952
+ */
953
+ type BuildDescriptors<T extends Descriptors, H extends Host<any> | undefined, Depth extends number = 5> = {
954
+ done: T;
955
+ recurse: T extends {
956
+ __type: typeof SERVICE_PLUGIN_ERROR_TYPE;
957
+ } ? 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<{
958
+ [Key in keyof T]: T[Key] extends Descriptors ? BuildDescriptors<T[Key], H, [
959
+ -1,
960
+ 0,
961
+ 1,
962
+ 2,
963
+ 3,
964
+ 4,
965
+ 5
966
+ ][Depth]> : never;
967
+ }, EmptyObject>;
968
+ }[Depth extends -1 ? 'done' : 'recurse'];
969
+ type PublicMetadata = {
970
+ PACKAGE_NAME?: string;
971
+ };
972
+
973
+ declare global {
974
+ interface ContextualClient {
975
+ }
976
+ }
977
+ /**
978
+ * A type used to create concerete types from SDK descriptors in
979
+ * case a contextual client is available.
980
+ */
981
+ type MaybeContext<T extends Descriptors> = globalThis.ContextualClient extends {
982
+ host: Host;
983
+ } ? BuildDescriptors<T, globalThis.ContextualClient['host']> : T;
984
+
199
985
  interface Notification {
200
986
  /** The id of the notification */
201
987
  _id?: string;
@@ -347,7 +1133,7 @@ interface NotifySignature {
347
1133
  (notificationTemplateId: string, options?: NotifyOptions | undefined): Promise<NotifyResponse & NotifyResponseNonNullableFields>;
348
1134
  }
349
1135
 
350
- declare const notify: BuildRESTFunction<typeof notify$1> & typeof notify$1;
1136
+ declare const notify: MaybeContext<BuildRESTFunction<typeof notify$1> & typeof notify$1>;
351
1137
 
352
1138
  type context_ArrayDynamicValue = ArrayDynamicValue;
353
1139
  type context_AttachmentDynamicValue = AttachmentDynamicValue;