@wix/notifications 1.0.35 → 1.0.37
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.
- package/build/cjs/context.js +1 -0
- package/build/cjs/context.js.map +1 -0
- package/build/cjs/index.js +1 -0
- package/build/cjs/index.js.map +1 -0
- package/build/cjs/meta.js +1 -0
- package/build/cjs/meta.js.map +1 -0
- package/package.json +4 -4
- package/type-bundles/context.bundle.d.ts +823 -55
- package/type-bundles/index.bundle.d.ts +823 -55
- package/type-bundles/meta.bundle.d.ts +14 -25
|
@@ -1,29 +1,127 @@
|
|
|
1
|
-
type
|
|
2
|
-
|
|
3
|
-
|
|
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,43 +130,311 @@ 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;
|
|
38
414
|
}
|
|
39
415
|
interface PublicNotifyRequest extends PublicNotifyRequestRecipientsFilterOneOf, PublicNotifyRequestActionTargetOneOf {
|
|
40
|
-
/**
|
|
416
|
+
/** Send to [site contributors]((https://support.wix.com/en/article/roles-permissions-overview)). This includes site administrators, website managers, and back office managers. */
|
|
41
417
|
toSiteContributors?: ToSiteContributors;
|
|
42
|
-
/**
|
|
418
|
+
/** Send to [site contacts](https://support.wix.com/en/article/about-your-contact-list). */
|
|
43
419
|
toContacts?: ToContacts;
|
|
44
420
|
/** URL to navigate to when the `action` text is clicked. */
|
|
45
421
|
targetUrl?: string | null;
|
|
46
|
-
/**
|
|
422
|
+
/** Dashboard page to open when the notification action is clicked. */
|
|
47
423
|
targetDashboardPage?: DashboardPages;
|
|
48
|
-
/**
|
|
49
|
-
* Notification title. Only displayed on mobile and browser notifications.
|
|
50
|
-
*
|
|
51
|
-
* Max: 512 characters
|
|
52
|
-
*/
|
|
424
|
+
/** Title of the notification. Max: 512 characters. */
|
|
53
425
|
title?: string | null;
|
|
54
426
|
/**
|
|
55
|
-
*
|
|
56
|
-
*
|
|
427
|
+
* Body of the notification. This contains the main content of the notification.
|
|
57
428
|
* Max: 512 characters
|
|
58
429
|
*/
|
|
59
430
|
body?: string | null;
|
|
60
|
-
/**
|
|
61
|
-
* Clickable text that links to the `targetUrl` or `targetDashboardPage`. For example, "Click this!".
|
|
62
|
-
*
|
|
63
|
-
* Max: 512 characters
|
|
64
|
-
*/
|
|
431
|
+
/** Title of the notification action. Clicking the action refers the user to a target URL or a dashboard page. */
|
|
65
432
|
action?: string | null;
|
|
66
433
|
/**
|
|
67
|
-
*
|
|
68
|
-
*
|
|
434
|
+
* Channel through which users receive the notification.
|
|
69
435
|
* - `"Mobile"`: Sends the notification to the Wix App.
|
|
70
|
-
* - `"Dashboard"`: Sends the notification to the
|
|
71
|
-
* - `"Browser"`: Sends the notification to the
|
|
436
|
+
* - `"Dashboard"`: Sends the notification to the collaborator's Wix Dashboard.
|
|
437
|
+
* - `"Browser"`: Sends the notification to the collaborator's browser.
|
|
72
438
|
*/
|
|
73
439
|
channels?: Channel[];
|
|
74
440
|
}
|
|
@@ -83,15 +449,14 @@ interface PublicNotifyRequestRecipientsFilterOneOf {
|
|
|
83
449
|
interface PublicNotifyRequestActionTargetOneOf {
|
|
84
450
|
/** URL to navigate to when the `action` text is clicked. */
|
|
85
451
|
targetUrl?: string | null;
|
|
86
|
-
/**
|
|
452
|
+
/** Dashboard page to open when the notification action is clicked. */
|
|
87
453
|
targetDashboardPage?: DashboardPages;
|
|
88
454
|
}
|
|
89
455
|
interface ToSiteContributors {
|
|
90
456
|
/**
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
* - `"
|
|
94
|
-
* - `"Owner"`: Only the site owner.
|
|
457
|
+
* Role assigned to site contributors. Only contributors with the specified roles receive the notification:
|
|
458
|
+
* - `"All_Contributors"`: All site collaborators (default).
|
|
459
|
+
* - `"Owner"`: Site owner only.
|
|
95
460
|
*/
|
|
96
461
|
withRole?: Role;
|
|
97
462
|
}
|
|
@@ -102,13 +467,13 @@ declare enum Role {
|
|
|
102
467
|
Owner = "Owner"
|
|
103
468
|
}
|
|
104
469
|
interface ToContacts {
|
|
105
|
-
/**
|
|
470
|
+
/** Contacts that receive the notification. */
|
|
106
471
|
contactIds?: string[];
|
|
107
472
|
}
|
|
108
473
|
interface ToTopicsSubscribers {
|
|
109
|
-
/**
|
|
474
|
+
/** Notification topics to which the recipients have subscribed. Only contacts who subscribed to the specified topics receive the notification. */
|
|
110
475
|
topics?: string[];
|
|
111
|
-
/**
|
|
476
|
+
/** Excluded contact IDs. Contacts with these IDs don't receive the notification. */
|
|
112
477
|
excludedContactIds?: string[];
|
|
113
478
|
}
|
|
114
479
|
declare enum Channel {
|
|
@@ -133,25 +498,21 @@ interface NotifyOptions$1 extends PublicNotifyRequestRecipientsFilterOneOf, Publ
|
|
|
133
498
|
toSiteContributors?: ToSiteContributors;
|
|
134
499
|
/** List of contacts to notify. */
|
|
135
500
|
toContacts?: ToContacts;
|
|
136
|
-
/**
|
|
137
|
-
* Notification title. Only displayed on mobile and browser notifications.
|
|
138
|
-
*
|
|
139
|
-
* Max: 512 characters
|
|
140
|
-
*/
|
|
501
|
+
/** Title of the notification. Max: 512 characters. */
|
|
141
502
|
title?: string | null;
|
|
142
503
|
/**
|
|
143
|
-
*
|
|
504
|
+
* Title of the notification action. Clicking the action refers the user to a target URL or a dashboard page.
|
|
144
505
|
*
|
|
145
|
-
* Max: 512 characters
|
|
506
|
+
* Max: 512 characters.
|
|
146
507
|
*/
|
|
147
508
|
action?: string | null;
|
|
148
|
-
/** URL to
|
|
509
|
+
/** External URL to open when the notification action is clicked. */
|
|
149
510
|
targetUrl?: string | null;
|
|
150
|
-
/**
|
|
511
|
+
/** Dashboard page to open when the notification action is clicked. */
|
|
151
512
|
targetDashboardPage?: DashboardPages;
|
|
152
513
|
}
|
|
153
514
|
|
|
154
|
-
declare function notify$3(httpClient: HttpClient): NotifySignature$1;
|
|
515
|
+
declare function notify$3(httpClient: HttpClient$1): NotifySignature$1;
|
|
155
516
|
interface NotifySignature$1 {
|
|
156
517
|
/**
|
|
157
518
|
* Sends a notification.
|
|
@@ -163,20 +524,17 @@ interface NotifySignature$1 {
|
|
|
163
524
|
*
|
|
164
525
|
* List the recipients for the notification in the `toContacts`, `toSiteContributors`, and `toTopicsSubscribers` parameters.
|
|
165
526
|
* @param - Notification options.
|
|
166
|
-
* @param -
|
|
167
|
-
*
|
|
168
|
-
* Max: 512 characters
|
|
169
|
-
* @param - The channels to send the notification on. One or more of:
|
|
170
|
-
*
|
|
527
|
+
* @param - Body of the notification. This contains the main content of the notification.
|
|
528
|
+
* @param - Channel through which users receive the notification.
|
|
171
529
|
* - `"Mobile"`: Sends the notification to the Wix App.
|
|
172
|
-
* - `"Dashboard"`: Sends the notification to the
|
|
173
|
-
* - `"Browser"`: Sends the notification to the
|
|
530
|
+
* - `"Dashboard"`: Sends the notification to the collaborator's Wix Dashboard.
|
|
531
|
+
* - `"Browser"`: Sends the notification to the collaborator's browser.
|
|
174
532
|
* @returns Fulfilled when the send notification request is received.
|
|
175
533
|
*/
|
|
176
534
|
(body: string | null, channels: Channel[], options?: NotifyOptions$1 | undefined): Promise<void>;
|
|
177
535
|
}
|
|
178
536
|
|
|
179
|
-
declare const notify$2: BuildRESTFunction<typeof notify$3> & typeof notify$3
|
|
537
|
+
declare const notify$2: MaybeContext$1<BuildRESTFunction$1<typeof notify$3> & typeof notify$3>;
|
|
180
538
|
|
|
181
539
|
type index_d$1_Channel = Channel;
|
|
182
540
|
declare const index_d$1_Channel: typeof Channel;
|
|
@@ -196,6 +554,416 @@ declare namespace index_d$1 {
|
|
|
196
554
|
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 };
|
|
197
555
|
}
|
|
198
556
|
|
|
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
|
+
|
|
199
967
|
interface Notification {
|
|
200
968
|
/** The id of the notification */
|
|
201
969
|
_id?: string;
|
|
@@ -347,7 +1115,7 @@ interface NotifySignature {
|
|
|
347
1115
|
(notificationTemplateId: string, options?: NotifyOptions | undefined): Promise<NotifyResponse & NotifyResponseNonNullableFields>;
|
|
348
1116
|
}
|
|
349
1117
|
|
|
350
|
-
declare const notify: BuildRESTFunction<typeof notify$1> & typeof notify$1
|
|
1118
|
+
declare const notify: MaybeContext<BuildRESTFunction<typeof notify$1> & typeof notify$1>;
|
|
351
1119
|
|
|
352
1120
|
type index_d_ArrayDynamicValue = ArrayDynamicValue;
|
|
353
1121
|
type index_d_AttachmentDynamicValue = AttachmentDynamicValue;
|