@wix/notifications 1.0.46 → 1.0.47

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,9 +1,9 @@
1
- type HostModule$1<T, H extends Host$1> = {
1
+ type HostModule<T, H extends Host> = {
2
2
  __type: 'host';
3
3
  create(host: H): T;
4
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> = {
5
+ type HostModuleAPI<T extends HostModule<any, any>> = T extends HostModule<infer U, any> ? U : never;
6
+ type Host<Environment = unknown> = {
7
7
  channel: {
8
8
  observeState(callback: (props: unknown, environment: Environment) => unknown): {
9
9
  disconnect: () => void;
@@ -12,6 +12,10 @@ type Host$1<Environment = unknown> = {
12
12
  }>;
13
13
  };
14
14
  environment?: Environment;
15
+ /**
16
+ * Optional name of the environment, use for logging
17
+ */
18
+ name?: string;
15
19
  /**
16
20
  * Optional bast url to use for API requests, for example `www.wixapis.com`
17
21
  */
@@ -36,92 +40,92 @@ type Host$1<Environment = unknown> = {
36
40
  };
37
41
  };
38
42
 
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>>;
43
+ type RESTFunctionDescriptor<T extends (...args: any[]) => any = (...args: any[]) => any> = (httpClient: HttpClient) => T;
44
+ interface HttpClient {
45
+ request<TResponse, TData = any>(req: RequestOptionsFactory<TResponse, TData>): Promise<HttpResponse<TResponse>>;
42
46
  fetchWithAuth: typeof fetch;
43
47
  wixAPIFetch: (relativeUrl: string, options: RequestInit) => Promise<Response>;
44
48
  getActiveToken?: () => string | undefined;
45
49
  }
46
- type RequestOptionsFactory$1<TResponse = any, TData = any> = (context: any) => RequestOptions$1<TResponse, TData>;
47
- type HttpResponse$1<T = any> = {
50
+ type RequestOptionsFactory<TResponse = any, TData = any> = (context: any) => RequestOptions<TResponse, TData>;
51
+ type HttpResponse<T = any> = {
48
52
  data: T;
49
53
  status: number;
50
54
  statusText: string;
51
55
  headers: any;
52
56
  request?: any;
53
57
  };
54
- type RequestOptions$1<_TResponse = any, Data = any> = {
58
+ type RequestOptions<_TResponse = any, Data = any> = {
55
59
  method: 'POST' | 'GET' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS';
56
60
  url: string;
57
61
  data?: Data;
58
62
  params?: URLSearchParams;
59
- } & APIMetadata$1;
60
- type APIMetadata$1 = {
63
+ } & APIMetadata;
64
+ type APIMetadata = {
61
65
  methodFqn?: string;
62
66
  entityFqdn?: string;
63
67
  packageName?: string;
64
68
  };
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> = {
69
+ type BuildRESTFunction<T extends RESTFunctionDescriptor> = T extends RESTFunctionDescriptor<infer U> ? U : never;
70
+ type EventDefinition<Payload = unknown, Type extends string = string> = {
67
71
  __type: 'event-definition';
68
72
  type: Type;
69
73
  isDomainEvent?: boolean;
70
74
  transformations?: (envelope: unknown) => Payload;
71
75
  __payload: Payload;
72
76
  };
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;
77
+ declare function EventDefinition<Type extends string>(type: Type, isDomainEvent?: boolean, transformations?: (envelope: any) => unknown): <Payload = unknown>() => EventDefinition<Payload, Type>;
78
+ type EventHandler<T extends EventDefinition> = (payload: T['__payload']) => void | Promise<void>;
79
+ type BuildEventDefinition<T extends EventDefinition<any, string>> = (handler: EventHandler<T>) => void;
76
80
 
77
- type ServicePluginMethodInput$1 = {
81
+ type ServicePluginMethodInput = {
78
82
  request: any;
79
83
  metadata: any;
80
84
  };
81
- type ServicePluginContract$1 = Record<string, (payload: ServicePluginMethodInput$1) => unknown | Promise<unknown>>;
82
- type ServicePluginMethodMetadata$1 = {
85
+ type ServicePluginContract = Record<string, (payload: ServicePluginMethodInput) => unknown | Promise<unknown>>;
86
+ type ServicePluginMethodMetadata = {
83
87
  name: string;
84
88
  primaryHttpMappingPath: string;
85
89
  transformations: {
86
- fromREST: (...args: unknown[]) => ServicePluginMethodInput$1;
90
+ fromREST: (...args: unknown[]) => ServicePluginMethodInput;
87
91
  toREST: (...args: unknown[]) => unknown;
88
92
  };
89
93
  };
90
- type ServicePluginDefinition$1<Contract extends ServicePluginContract$1> = {
94
+ type ServicePluginDefinition<Contract extends ServicePluginContract> = {
91
95
  __type: 'service-plugin-definition';
92
96
  componentType: string;
93
- methods: ServicePluginMethodMetadata$1[];
97
+ methods: ServicePluginMethodMetadata[];
94
98
  __contract: Contract;
95
99
  };
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";
100
+ declare function ServicePluginDefinition<Contract extends ServicePluginContract>(componentType: string, methods: ServicePluginMethodMetadata[]): ServicePluginDefinition<Contract>;
101
+ type BuildServicePluginDefinition<T extends ServicePluginDefinition<any>> = (implementation: T['__contract']) => void;
102
+ declare const SERVICE_PLUGIN_ERROR_TYPE = "wix_spi_error";
99
103
 
100
- type RequestContext$1 = {
104
+ type RequestContext = {
101
105
  isSSR: boolean;
102
106
  host: string;
103
107
  protocol?: string;
104
108
  };
105
- type ResponseTransformer$1 = (data: any, headers?: any) => any;
109
+ type ResponseTransformer = (data: any, headers?: any) => any;
106
110
  /**
107
111
  * Ambassador request options types are copied mostly from AxiosRequestConfig.
108
112
  * They are copied and not imported to reduce the amount of dependencies (to reduce install time).
109
113
  * https://github.com/axios/axios/blob/3f53eb6960f05a1f88409c4b731a40de595cb825/index.d.ts#L307-L315
110
114
  */
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> = {
115
+ type Method = 'get' | 'GET' | 'delete' | 'DELETE' | 'head' | 'HEAD' | 'options' | 'OPTIONS' | 'post' | 'POST' | 'put' | 'PUT' | 'patch' | 'PATCH' | 'purge' | 'PURGE' | 'link' | 'LINK' | 'unlink' | 'UNLINK';
116
+ type AmbassadorRequestOptions<T = any> = {
113
117
  _?: T;
114
118
  url?: string;
115
- method?: Method$1;
119
+ method?: Method;
116
120
  params?: any;
117
121
  data?: any;
118
- transformResponse?: ResponseTransformer$1 | ResponseTransformer$1[];
122
+ transformResponse?: ResponseTransformer | ResponseTransformer[];
119
123
  };
120
- type AmbassadorFactory$1<Request, Response> = (payload: Request) => ((context: RequestContext$1) => AmbassadorRequestOptions$1<Response>) & {
124
+ type AmbassadorFactory<Request, Response> = (payload: Request) => ((context: RequestContext) => AmbassadorRequestOptions<Response>) & {
121
125
  __isAmbassador: boolean;
122
126
  };
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;
127
+ type AmbassadorFunctionDescriptor<Request = any, Response = any> = AmbassadorFactory<Request, Response>;
128
+ type BuildAmbassadorFunction<T extends AmbassadorFunctionDescriptor> = T extends AmbassadorFunctionDescriptor<infer Request, infer Response> ? (req: Request) => Promise<Response> : never;
125
129
 
126
130
  declare global {
127
131
  // eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
@@ -130,7 +134,7 @@ declare global {
130
134
  }
131
135
  }
132
136
 
133
- declare const emptyObjectSymbol$1: unique symbol;
137
+ declare const emptyObjectSymbol: unique symbol;
134
138
 
135
139
  /**
136
140
  Represents a strictly empty plain object, the `{}` value.
@@ -158,7 +162,7 @@ Unfortunately, `Record<string, never>`, `Record<keyof any, never>` and `Record<n
158
162
 
159
163
  @category Object
160
164
  */
161
- type EmptyObject$1 = {[emptyObjectSymbol$1]?: never};
165
+ type EmptyObject = {[emptyObjectSymbol]?: never};
162
166
 
163
167
  /**
164
168
  Returns a boolean for whether the two given types are equal.
@@ -186,7 +190,7 @@ type Includes<Value extends readonly any[], Item> =
186
190
  @category Type Guard
187
191
  @category Utilities
188
192
  */
189
- type IsEqual$1<A, B> =
193
+ type IsEqual<A, B> =
190
194
  (<G>() => G extends A ? 1 : 2) extends
191
195
  (<G>() => G extends B ? 1 : 2)
192
196
  ? true
@@ -219,9 +223,9 @@ type Filtered = Filter<'bar', 'foo'>;
219
223
 
220
224
  @see {Except}
221
225
  */
222
- type Filter$1<KeyType, ExcludeType> = IsEqual$1<KeyType, ExcludeType> extends true ? never : (KeyType extends ExcludeType ? never : KeyType);
226
+ type Filter<KeyType, ExcludeType> = IsEqual<KeyType, ExcludeType> extends true ? never : (KeyType extends ExcludeType ? never : KeyType);
223
227
 
224
- type ExceptOptions$1 = {
228
+ type ExceptOptions = {
225
229
  /**
226
230
  Disallow assigning non-specified properties.
227
231
 
@@ -265,12 +269,78 @@ const fooWithoutB: FooWithoutB = {a: 1, b: '2'};
265
269
 
266
270
  @category Object
267
271
  */
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];
272
+ type Except<ObjectType, KeysType extends keyof ObjectType, Options extends ExceptOptions = {requireExactProps: false}> = {
273
+ [KeyType in keyof ObjectType as Filter<KeyType, KeysType>]: ObjectType[KeyType];
270
274
  } & (Options['requireExactProps'] extends true
271
275
  ? Partial<Record<KeysType, never>>
272
276
  : {});
273
277
 
278
+ /**
279
+ Returns a boolean for whether the given type is `never`.
280
+
281
+ @link https://github.com/microsoft/TypeScript/issues/31751#issuecomment-498526919
282
+ @link https://stackoverflow.com/a/53984913/10292952
283
+ @link https://www.zhenghao.io/posts/ts-never
284
+
285
+ Useful in type utilities, such as checking if something does not occur.
286
+
287
+ @example
288
+ ```
289
+ import type {IsNever, And} from 'type-fest';
290
+
291
+ // https://github.com/andnp/SimplyTyped/blob/master/src/types/strings.ts
292
+ type AreStringsEqual<A extends string, B extends string> =
293
+ And<
294
+ IsNever<Exclude<A, B>> extends true ? true : false,
295
+ IsNever<Exclude<B, A>> extends true ? true : false
296
+ >;
297
+
298
+ type EndIfEqual<I extends string, O extends string> =
299
+ AreStringsEqual<I, O> extends true
300
+ ? never
301
+ : void;
302
+
303
+ function endIfEqual<I extends string, O extends string>(input: I, output: O): EndIfEqual<I, O> {
304
+ if (input === output) {
305
+ process.exit(0);
306
+ }
307
+ }
308
+
309
+ endIfEqual('abc', 'abc');
310
+ //=> never
311
+
312
+ endIfEqual('abc', '123');
313
+ //=> void
314
+ ```
315
+
316
+ @category Type Guard
317
+ @category Utilities
318
+ */
319
+ type IsNever<T> = [T] extends [never] ? true : false;
320
+
321
+ /**
322
+ An if-else-like type that resolves depending on whether the given type is `never`.
323
+
324
+ @see {@link IsNever}
325
+
326
+ @example
327
+ ```
328
+ import type {IfNever} from 'type-fest';
329
+
330
+ type ShouldBeTrue = IfNever<never>;
331
+ //=> true
332
+
333
+ type ShouldBeBar = IfNever<'not never', 'foo', 'bar'>;
334
+ //=> 'bar'
335
+ ```
336
+
337
+ @category Type Guard
338
+ @category Utilities
339
+ */
340
+ type IfNever<T, TypeIfNever = true, TypeIfNotNever = false> = (
341
+ IsNever<T> extends true ? TypeIfNever : TypeIfNotNever
342
+ );
343
+
274
344
  /**
275
345
  Extract the keys from a type where the value type of the key extends the given `Condition`.
276
346
 
@@ -303,21 +373,19 @@ type StringKeysAndUndefined = ConditionalKeys<Example, string | undefined>;
303
373
 
304
374
  @category Object
305
375
  */
306
- type ConditionalKeys$1<Base, Condition> = NonNullable<
307
- // Wrap in `NonNullable` to strip away the `undefined` type from the produced union.
376
+ type ConditionalKeys<Base, Condition> =
308
377
  {
309
378
  // Map through all the keys of the given base type.
310
- [Key in keyof Base]:
379
+ [Key in keyof Base]-?:
311
380
  // Pick only keys with types extending the given `Condition` type.
312
381
  Base[Key] extends Condition
313
- // Retain this key since the condition passes.
314
- ? Key
382
+ // Retain this key
383
+ // If the value for the key extends never, only include it if `Condition` also extends never
384
+ ? IfNever<Base[Key], IfNever<Condition, Key, never>, Key>
315
385
  // Discard this key since the condition fails.
316
386
  : never;
317
-
318
387
  // Convert the produced object into a union type of the keys which passed the conditional test.
319
- }[keyof Base]
320
- >;
388
+ }[keyof Base];
321
389
 
322
390
  /**
323
391
  Exclude keys from a shape that matches the given `Condition`.
@@ -357,9 +425,9 @@ type NonStringKeysOnly = ConditionalExcept<Example, string>;
357
425
 
358
426
  @category Object
359
427
  */
360
- type ConditionalExcept$1<Base, Condition> = Except$1<
428
+ type ConditionalExcept<Base, Condition> = Except<
361
429
  Base,
362
- ConditionalKeys$1<Base, Condition>
430
+ ConditionalKeys<Base, Condition>
363
431
  >;
364
432
 
365
433
  /**
@@ -367,8 +435,8 @@ ConditionalKeys$1<Base, Condition>
367
435
  * can either be a REST module or a host module.
368
436
  * This type is recursive, so it can describe nested modules.
369
437
  */
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;
438
+ type Descriptors = RESTFunctionDescriptor | AmbassadorFunctionDescriptor | HostModule<any, any> | EventDefinition<any> | ServicePluginDefinition<any> | {
439
+ [key: string]: Descriptors | PublicMetadata | any;
372
440
  };
373
441
  /**
374
442
  * This type takes in a descriptors object of a certain Host (including an `unknown` host)
@@ -376,12 +444,12 @@ type Descriptors$1 = RESTFunctionDescriptor$1 | AmbassadorFunctionDescriptor$1 |
376
444
  * Any non-descriptor properties are removed from the returned object, including descriptors that
377
445
  * do not match the given host (as they will not work with the given host).
378
446
  */
379
- type BuildDescriptors$1<T extends Descriptors$1, H extends Host$1<any> | undefined, Depth extends number = 5> = {
447
+ type BuildDescriptors<T extends Descriptors, H extends Host<any> | undefined, Depth extends number = 5> = {
380
448
  done: T;
381
449
  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, [
450
+ __type: typeof SERVICE_PLUGIN_ERROR_TYPE;
451
+ } ? 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<{
452
+ [Key in keyof T]: T[Key] extends Descriptors ? BuildDescriptors<T[Key], H, [
385
453
  -1,
386
454
  0,
387
455
  1,
@@ -390,9 +458,9 @@ type BuildDescriptors$1<T extends Descriptors$1, H extends Host$1<any> | undefin
390
458
  4,
391
459
  5
392
460
  ][Depth]> : never;
393
- }, EmptyObject$1>;
461
+ }, EmptyObject>;
394
462
  }[Depth extends -1 ? 'done' : 'recurse'];
395
- type PublicMetadata$1 = {
463
+ type PublicMetadata = {
396
464
  PACKAGE_NAME?: string;
397
465
  };
398
466
 
@@ -404,9 +472,9 @@ declare global {
404
472
  * A type used to create concerete types from SDK descriptors in
405
473
  * case a contextual client is available.
406
474
  */
407
- type MaybeContext$1<T extends Descriptors$1> = globalThis.ContextualClient extends {
408
- host: Host$1;
409
- } ? BuildDescriptors$1<T, globalThis.ContextualClient['host']> : T;
475
+ type MaybeContext<T extends Descriptors> = globalThis.ContextualClient extends {
476
+ host: Host;
477
+ } ? BuildDescriptors<T, globalThis.ContextualClient['host']> : T;
410
478
 
411
479
  interface Public_notification {
412
480
  /** Notification ID. */
@@ -512,7 +580,7 @@ interface NotifyOptions$1 extends PublicNotifyRequestRecipientsFilterOneOf, Publ
512
580
  targetDashboardPage?: DashboardPages;
513
581
  }
514
582
 
515
- declare function notify$3(httpClient: HttpClient$1): NotifySignature$1;
583
+ declare function notify$3(httpClient: HttpClient): NotifySignature$1;
516
584
  interface NotifySignature$1 {
517
585
  /**
518
586
  * Sends a notification.
@@ -534,7 +602,7 @@ interface NotifySignature$1 {
534
602
  (body: string | null, channels: Channel[], options?: NotifyOptions$1 | undefined): Promise<void>;
535
603
  }
536
604
 
537
- declare const notify$2: MaybeContext$1<BuildRESTFunction$1<typeof notify$3> & typeof notify$3>;
605
+ declare const notify$2: MaybeContext<BuildRESTFunction<typeof notify$3> & typeof notify$3>;
538
606
 
539
607
  type index_d$1_Channel = Channel;
540
608
  declare const index_d$1_Channel: typeof Channel;
@@ -554,416 +622,6 @@ declare namespace index_d$1 {
554
622
  export { index_d$1_Channel as Channel, index_d$1_DashboardPages as DashboardPages, type index_d$1_Empty as Empty, type NotifyOptions$1 as NotifyOptions, type index_d$1_PublicNotifyRequest as PublicNotifyRequest, type index_d$1_PublicNotifyRequestActionTargetOneOf as PublicNotifyRequestActionTargetOneOf, type index_d$1_PublicNotifyRequestRecipientsFilterOneOf as PublicNotifyRequestRecipientsFilterOneOf, type index_d$1_Public_notification as Public_notification, index_d$1_Role as Role, type index_d$1_ToContacts as ToContacts, type index_d$1_ToSiteContributors as ToSiteContributors, type index_d$1_ToTopicsSubscribers as ToTopicsSubscribers, notify$2 as notify };
555
623
  }
556
624
 
557
- type HostModule<T, H extends Host> = {
558
- __type: 'host';
559
- create(host: H): T;
560
- };
561
- type HostModuleAPI<T extends HostModule<any, any>> = T extends HostModule<infer U, any> ? U : never;
562
- type Host<Environment = unknown> = {
563
- channel: {
564
- observeState(callback: (props: unknown, environment: Environment) => unknown): {
565
- disconnect: () => void;
566
- } | Promise<{
567
- disconnect: () => void;
568
- }>;
569
- };
570
- environment?: Environment;
571
- /**
572
- * Optional bast url to use for API requests, for example `www.wixapis.com`
573
- */
574
- apiBaseUrl?: string;
575
- /**
576
- * Possible data to be provided by every host, for cross cutting concerns
577
- * like internationalization, billing, etc.
578
- */
579
- essentials?: {
580
- /**
581
- * The language of the currently viewed session
582
- */
583
- language?: string;
584
- /**
585
- * The locale of the currently viewed session
586
- */
587
- locale?: string;
588
- /**
589
- * Any headers that should be passed through to the API requests
590
- */
591
- passThroughHeaders?: Record<string, string>;
592
- };
593
- };
594
-
595
- type RESTFunctionDescriptor<T extends (...args: any[]) => any = (...args: any[]) => any> = (httpClient: HttpClient) => T;
596
- interface HttpClient {
597
- request<TResponse, TData = any>(req: RequestOptionsFactory<TResponse, TData>): Promise<HttpResponse<TResponse>>;
598
- fetchWithAuth: typeof fetch;
599
- wixAPIFetch: (relativeUrl: string, options: RequestInit) => Promise<Response>;
600
- getActiveToken?: () => string | undefined;
601
- }
602
- type RequestOptionsFactory<TResponse = any, TData = any> = (context: any) => RequestOptions<TResponse, TData>;
603
- type HttpResponse<T = any> = {
604
- data: T;
605
- status: number;
606
- statusText: string;
607
- headers: any;
608
- request?: any;
609
- };
610
- type RequestOptions<_TResponse = any, Data = any> = {
611
- method: 'POST' | 'GET' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS';
612
- url: string;
613
- data?: Data;
614
- params?: URLSearchParams;
615
- } & APIMetadata;
616
- type APIMetadata = {
617
- methodFqn?: string;
618
- entityFqdn?: string;
619
- packageName?: string;
620
- };
621
- type BuildRESTFunction<T extends RESTFunctionDescriptor> = T extends RESTFunctionDescriptor<infer U> ? U : never;
622
- type EventDefinition<Payload = unknown, Type extends string = string> = {
623
- __type: 'event-definition';
624
- type: Type;
625
- isDomainEvent?: boolean;
626
- transformations?: (envelope: unknown) => Payload;
627
- __payload: Payload;
628
- };
629
- declare function EventDefinition<Type extends string>(type: Type, isDomainEvent?: boolean, transformations?: (envelope: any) => unknown): <Payload = unknown>() => EventDefinition<Payload, Type>;
630
- type EventHandler<T extends EventDefinition> = (payload: T['__payload']) => void | Promise<void>;
631
- type BuildEventDefinition<T extends EventDefinition<any, string>> = (handler: EventHandler<T>) => void;
632
-
633
- type ServicePluginMethodInput = {
634
- request: any;
635
- metadata: any;
636
- };
637
- type ServicePluginContract = Record<string, (payload: ServicePluginMethodInput) => unknown | Promise<unknown>>;
638
- type ServicePluginMethodMetadata = {
639
- name: string;
640
- primaryHttpMappingPath: string;
641
- transformations: {
642
- fromREST: (...args: unknown[]) => ServicePluginMethodInput;
643
- toREST: (...args: unknown[]) => unknown;
644
- };
645
- };
646
- type ServicePluginDefinition<Contract extends ServicePluginContract> = {
647
- __type: 'service-plugin-definition';
648
- componentType: string;
649
- methods: ServicePluginMethodMetadata[];
650
- __contract: Contract;
651
- };
652
- declare function ServicePluginDefinition<Contract extends ServicePluginContract>(componentType: string, methods: ServicePluginMethodMetadata[]): ServicePluginDefinition<Contract>;
653
- type BuildServicePluginDefinition<T extends ServicePluginDefinition<any>> = (implementation: T['__contract']) => void;
654
- declare const SERVICE_PLUGIN_ERROR_TYPE = "wix_spi_error";
655
-
656
- type RequestContext = {
657
- isSSR: boolean;
658
- host: string;
659
- protocol?: string;
660
- };
661
- type ResponseTransformer = (data: any, headers?: any) => any;
662
- /**
663
- * Ambassador request options types are copied mostly from AxiosRequestConfig.
664
- * They are copied and not imported to reduce the amount of dependencies (to reduce install time).
665
- * https://github.com/axios/axios/blob/3f53eb6960f05a1f88409c4b731a40de595cb825/index.d.ts#L307-L315
666
- */
667
- type Method = 'get' | 'GET' | 'delete' | 'DELETE' | 'head' | 'HEAD' | 'options' | 'OPTIONS' | 'post' | 'POST' | 'put' | 'PUT' | 'patch' | 'PATCH' | 'purge' | 'PURGE' | 'link' | 'LINK' | 'unlink' | 'UNLINK';
668
- type AmbassadorRequestOptions<T = any> = {
669
- _?: T;
670
- url?: string;
671
- method?: Method;
672
- params?: any;
673
- data?: any;
674
- transformResponse?: ResponseTransformer | ResponseTransformer[];
675
- };
676
- type AmbassadorFactory<Request, Response> = (payload: Request) => ((context: RequestContext) => AmbassadorRequestOptions<Response>) & {
677
- __isAmbassador: boolean;
678
- };
679
- type AmbassadorFunctionDescriptor<Request = any, Response = any> = AmbassadorFactory<Request, Response>;
680
- type BuildAmbassadorFunction<T extends AmbassadorFunctionDescriptor> = T extends AmbassadorFunctionDescriptor<infer Request, infer Response> ? (req: Request) => Promise<Response> : never;
681
-
682
- declare global {
683
- // eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
684
- interface SymbolConstructor {
685
- readonly observable: symbol;
686
- }
687
- }
688
-
689
- declare const emptyObjectSymbol: unique symbol;
690
-
691
- /**
692
- Represents a strictly empty plain object, the `{}` value.
693
-
694
- 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)).
695
-
696
- @example
697
- ```
698
- import type {EmptyObject} from 'type-fest';
699
-
700
- // The following illustrates the problem with `{}`.
701
- const foo1: {} = {}; // Pass
702
- const foo2: {} = []; // Pass
703
- const foo3: {} = 42; // Pass
704
- const foo4: {} = {a: 1}; // Pass
705
-
706
- // With `EmptyObject` only the first case is valid.
707
- const bar1: EmptyObject = {}; // Pass
708
- const bar2: EmptyObject = 42; // Fail
709
- const bar3: EmptyObject = []; // Fail
710
- const bar4: EmptyObject = {a: 1}; // Fail
711
- ```
712
-
713
- 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}.
714
-
715
- @category Object
716
- */
717
- type EmptyObject = {[emptyObjectSymbol]?: never};
718
-
719
- /**
720
- Returns a boolean for whether the two given types are equal.
721
-
722
- @link https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650
723
- @link https://stackoverflow.com/questions/68961864/how-does-the-equals-work-in-typescript/68963796#68963796
724
-
725
- Use-cases:
726
- - If you want to make a conditional branch based on the result of a comparison of two types.
727
-
728
- @example
729
- ```
730
- import type {IsEqual} from 'type-fest';
731
-
732
- // This type returns a boolean for whether the given array includes the given item.
733
- // `IsEqual` is used to compare the given array at position 0 and the given item and then return true if they are equal.
734
- type Includes<Value extends readonly any[], Item> =
735
- Value extends readonly [Value[0], ...infer rest]
736
- ? IsEqual<Value[0], Item> extends true
737
- ? true
738
- : Includes<rest, Item>
739
- : false;
740
- ```
741
-
742
- @category Type Guard
743
- @category Utilities
744
- */
745
- type IsEqual<A, B> =
746
- (<G>() => G extends A ? 1 : 2) extends
747
- (<G>() => G extends B ? 1 : 2)
748
- ? true
749
- : false;
750
-
751
- /**
752
- Filter out keys from an object.
753
-
754
- Returns `never` if `Exclude` is strictly equal to `Key`.
755
- Returns `never` if `Key` extends `Exclude`.
756
- Returns `Key` otherwise.
757
-
758
- @example
759
- ```
760
- type Filtered = Filter<'foo', 'foo'>;
761
- //=> never
762
- ```
763
-
764
- @example
765
- ```
766
- type Filtered = Filter<'bar', string>;
767
- //=> never
768
- ```
769
-
770
- @example
771
- ```
772
- type Filtered = Filter<'bar', 'foo'>;
773
- //=> 'bar'
774
- ```
775
-
776
- @see {Except}
777
- */
778
- type Filter<KeyType, ExcludeType> = IsEqual<KeyType, ExcludeType> extends true ? never : (KeyType extends ExcludeType ? never : KeyType);
779
-
780
- type ExceptOptions = {
781
- /**
782
- Disallow assigning non-specified properties.
783
-
784
- Note that any omitted properties in the resulting type will be present in autocomplete as `undefined`.
785
-
786
- @default false
787
- */
788
- requireExactProps?: boolean;
789
- };
790
-
791
- /**
792
- Create a type from an object type without certain keys.
793
-
794
- We recommend setting the `requireExactProps` option to `true`.
795
-
796
- 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.
797
-
798
- 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)).
799
-
800
- @example
801
- ```
802
- import type {Except} from 'type-fest';
803
-
804
- type Foo = {
805
- a: number;
806
- b: string;
807
- };
808
-
809
- type FooWithoutA = Except<Foo, 'a'>;
810
- //=> {b: string}
811
-
812
- const fooWithoutA: FooWithoutA = {a: 1, b: '2'};
813
- //=> errors: 'a' does not exist in type '{ b: string; }'
814
-
815
- type FooWithoutB = Except<Foo, 'b', {requireExactProps: true}>;
816
- //=> {a: number} & Partial<Record<"b", never>>
817
-
818
- const fooWithoutB: FooWithoutB = {a: 1, b: '2'};
819
- //=> errors at 'b': Type 'string' is not assignable to type 'undefined'.
820
- ```
821
-
822
- @category Object
823
- */
824
- type Except<ObjectType, KeysType extends keyof ObjectType, Options extends ExceptOptions = {requireExactProps: false}> = {
825
- [KeyType in keyof ObjectType as Filter<KeyType, KeysType>]: ObjectType[KeyType];
826
- } & (Options['requireExactProps'] extends true
827
- ? Partial<Record<KeysType, never>>
828
- : {});
829
-
830
- /**
831
- Extract the keys from a type where the value type of the key extends the given `Condition`.
832
-
833
- Internally this is used for the `ConditionalPick` and `ConditionalExcept` types.
834
-
835
- @example
836
- ```
837
- import type {ConditionalKeys} from 'type-fest';
838
-
839
- interface Example {
840
- a: string;
841
- b: string | number;
842
- c?: string;
843
- d: {};
844
- }
845
-
846
- type StringKeysOnly = ConditionalKeys<Example, string>;
847
- //=> 'a'
848
- ```
849
-
850
- To support partial types, make sure your `Condition` is a union of undefined (for example, `string | undefined`) as demonstrated below.
851
-
852
- @example
853
- ```
854
- import type {ConditionalKeys} from 'type-fest';
855
-
856
- type StringKeysAndUndefined = ConditionalKeys<Example, string | undefined>;
857
- //=> 'a' | 'c'
858
- ```
859
-
860
- @category Object
861
- */
862
- type ConditionalKeys<Base, Condition> = NonNullable<
863
- // Wrap in `NonNullable` to strip away the `undefined` type from the produced union.
864
- {
865
- // Map through all the keys of the given base type.
866
- [Key in keyof Base]:
867
- // Pick only keys with types extending the given `Condition` type.
868
- Base[Key] extends Condition
869
- // Retain this key since the condition passes.
870
- ? Key
871
- // Discard this key since the condition fails.
872
- : never;
873
-
874
- // Convert the produced object into a union type of the keys which passed the conditional test.
875
- }[keyof Base]
876
- >;
877
-
878
- /**
879
- Exclude keys from a shape that matches the given `Condition`.
880
-
881
- 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.
882
-
883
- @example
884
- ```
885
- import type {Primitive, ConditionalExcept} from 'type-fest';
886
-
887
- class Awesome {
888
- name: string;
889
- successes: number;
890
- failures: bigint;
891
-
892
- run() {}
893
- }
894
-
895
- type ExceptPrimitivesFromAwesome = ConditionalExcept<Awesome, Primitive>;
896
- //=> {run: () => void}
897
- ```
898
-
899
- @example
900
- ```
901
- import type {ConditionalExcept} from 'type-fest';
902
-
903
- interface Example {
904
- a: string;
905
- b: string | number;
906
- c: () => void;
907
- d: {};
908
- }
909
-
910
- type NonStringKeysOnly = ConditionalExcept<Example, string>;
911
- //=> {b: string | number; c: () => void; d: {}}
912
- ```
913
-
914
- @category Object
915
- */
916
- type ConditionalExcept<Base, Condition> = Except<
917
- Base,
918
- ConditionalKeys<Base, Condition>
919
- >;
920
-
921
- /**
922
- * Descriptors are objects that describe the API of a module, and the module
923
- * can either be a REST module or a host module.
924
- * This type is recursive, so it can describe nested modules.
925
- */
926
- type Descriptors = RESTFunctionDescriptor | AmbassadorFunctionDescriptor | HostModule<any, any> | EventDefinition<any> | ServicePluginDefinition<any> | {
927
- [key: string]: Descriptors | PublicMetadata | any;
928
- };
929
- /**
930
- * This type takes in a descriptors object of a certain Host (including an `unknown` host)
931
- * and returns an object with the same structure, but with all descriptors replaced with their API.
932
- * Any non-descriptor properties are removed from the returned object, including descriptors that
933
- * do not match the given host (as they will not work with the given host).
934
- */
935
- type BuildDescriptors<T extends Descriptors, H extends Host<any> | undefined, Depth extends number = 5> = {
936
- done: T;
937
- recurse: T extends {
938
- __type: typeof SERVICE_PLUGIN_ERROR_TYPE;
939
- } ? 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<{
940
- [Key in keyof T]: T[Key] extends Descriptors ? BuildDescriptors<T[Key], H, [
941
- -1,
942
- 0,
943
- 1,
944
- 2,
945
- 3,
946
- 4,
947
- 5
948
- ][Depth]> : never;
949
- }, EmptyObject>;
950
- }[Depth extends -1 ? 'done' : 'recurse'];
951
- type PublicMetadata = {
952
- PACKAGE_NAME?: string;
953
- };
954
-
955
- declare global {
956
- interface ContextualClient {
957
- }
958
- }
959
- /**
960
- * A type used to create concerete types from SDK descriptors in
961
- * case a contextual client is available.
962
- */
963
- type MaybeContext<T extends Descriptors> = globalThis.ContextualClient extends {
964
- host: Host;
965
- } ? BuildDescriptors<T, globalThis.ContextualClient['host']> : T;
966
-
967
625
  interface Notification {
968
626
  /** The id of the notification */
969
627
  _id?: string;