@dropins/tools 0.23.0-alpha37 → 0.23.0-alpha38

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/types.d.ts +242 -0
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name": "@dropins/tools", "version": "0.23.0-alpha37"}
1
+ {"name": "@dropins/tools", "version": "0.23.0-alpha38"}
package/types.d.ts ADDED
@@ -0,0 +1,242 @@
1
+ declare module '@dropins/tools/initializer.js'{
2
+ import { Config } from '.';
3
+
4
+ type Listener = {
5
+ off(): void;
6
+ };
7
+ type Listeners<T> = (config?: T) => Array<Listener | undefined>;
8
+ type Init<T> = (config?: T) => Promise<void>;
9
+ type Options<T> = {
10
+ init: Init<T>;
11
+ listeners: Listeners<T>;
12
+ };
13
+ /**
14
+ * `Initializer` is a class that represents an initializer.
15
+ * An initializer is responsible for setting up event listeners and initializing a module.
16
+ *
17
+ * @class
18
+ *
19
+ * @property {Function} listeners - A method that accepts a config object and returns an array of listeners.
20
+ * @property {Function} init - A method that initializes the module. It accepts an options object.
21
+ * @property {Config} config - A Config object that stores the configuration for the module.
22
+ *
23
+ * @method constructor - Constructs a new Initializer. Accepts an options object with `init` and `listeners` properties.
24
+ */
25
+ export declare class Initializer<T> {
26
+ private _listeners;
27
+ listeners: Listeners<T>;
28
+ init: Init<T>;
29
+ config: Config<T>;
30
+ /**
31
+ * Constructs a new Initializer.
32
+ *
33
+ * @param {Object} options - The options for the Initializer.
34
+ * @param {Function} options.listeners - A function that accepts a config object and returns an array of listeners.
35
+ * @param {Function} options.init - A function that initializes the module. It accepts an options object.
36
+ */
37
+ constructor({ init, listeners }: Options<T>);
38
+ }
39
+ type Initializers = [Initializer<any>, {
40
+ [key: string]: any;
41
+ } | undefined][];
42
+ /**
43
+ * Class representing initializerss.
44
+ *
45
+ * @class
46
+ *
47
+ * @method register - Registers a new initializer. If the initializers have already been mounted, it also immediately binds the event listeners and initializes the API for the new initializer.
48
+ * @method mount - Mounts all registered initializers. This involves binding the event listeners and initializing the APIs for each initializer, in that order.
49
+ * @method setImageParamKeys - Sets the image parameter keys. These keys are used when initializing the APIs for the initializers.
50
+ */
51
+ export declare class initializers {
52
+ static _initializers: Initializers;
53
+ static _mounted: boolean;
54
+ static _imageParamsKeyMap: {
55
+ [key: string]: string;
56
+ } | undefined;
57
+ /**
58
+ * Registers a new initializer.
59
+ *
60
+ * @param {Initializer<any>} initializer - The initializer to register. This should be an object with `listeners` and `init` methods.
61
+ * @param {Object.<string, any>} [options] - An optional object with additional options. These options are passed to the `listeners` and `init` methods of the initializer.
62
+ */
63
+ static register(initializer: Initializer<any>, options?: {
64
+ [key: string]: any;
65
+ }): void;
66
+ /**
67
+ * Mounts all registered initializers.
68
+ *
69
+ * @returns {void}
70
+ */
71
+ static mount(): void;
72
+ /**
73
+ * Sets the image parameter keys.
74
+ *
75
+ * @param {Object.<string, any>} params - An object mapping keys to values.
76
+ * @returns {void}
77
+ */
78
+ static setImageParamKeys(params: {
79
+ [key: string]: any;
80
+ }): void;
81
+ }
82
+ export {};
83
+ //# sourceMappingURL=initializer.d.ts.map
84
+ }
85
+
86
+ declare module '@dropins/tools/event-bus.js'{
87
+ import { Events } from './events-catalog';
88
+
89
+ export * from './events-catalog';
90
+ /**
91
+ * `events` is a class that provides static methods for event handling.
92
+ *
93
+ * @class
94
+ * @extends {Events}
95
+ *
96
+ * @property {Function} on - Subscribes to an event. Accepts an event name, a handler function, and an optional options object.
97
+ * @property {Function} emit - Emits an event. Accepts an event name and a payload.
98
+ * @property {Function} enableLogger - Enables or disables logging of events. Accepts a boolean.
99
+ */
100
+ export declare class events {
101
+ static _identifier: string;
102
+ static _logger: BroadcastChannel | null;
103
+ static _lastEvent: {
104
+ [key: string]: {
105
+ payload: any;
106
+ };
107
+ };
108
+ /**
109
+ * Subscribes to an event.
110
+ *
111
+ * @param {string} event - The name of the event to subscribe to.
112
+ * @param {Function} handler - The function to call when the event is emitted.
113
+ * @param {Object} [options] - An optional object with additional options.
114
+ * @param {boolean} [options.eager] - If true, the handler will be called immediately with the last emitted event.
115
+ */
116
+ static on<K extends keyof Events>(event: K, handler: (payload: Events[K]) => void, options?: {
117
+ eager?: boolean;
118
+ }): {
119
+ off(): void;
120
+ } | undefined;
121
+ /**
122
+ * Emits an event.
123
+ *
124
+ * @param {string} event - The name of the event to emit.
125
+ * @param {*} payload - The data to send with the event.
126
+ */
127
+ static emit<K extends keyof Events>(event: K, payload: Events[K]): void;
128
+ /**
129
+ * Enables or disables logging of events.
130
+ *
131
+ * @param {boolean} enabled - If true, events will be logged to the console.
132
+ */
133
+ static enableLogger(enabled: boolean): void;
134
+ }
135
+ //# sourceMappingURL=index.d.ts.map
136
+ }
137
+
138
+ declare module '@dropins/tools/fetch-graphql.js'{
139
+ /**
140
+ * @typedef {Object} Header
141
+ * @property {string|null} key - The header name and value.
142
+ */
143
+ export type Header = {
144
+ [key: string]: string | null;
145
+ };
146
+ /**
147
+ * Type representing options for a fetch request.
148
+ * @typedef {Object} FetchOptions
149
+ * @property {'GET'|'POST'} [method] - The HTTP method to use for the request.
150
+ * @property {Object} [variables] - Variables to include in the request.
151
+ * @property {AbortSignal} [signal] - An AbortSignal to cancel the request.
152
+ * @property {'default'|'no-store'|'reload'|'no-cache'|'force-cache'|'only-if-cached'} [cache] - The cache mode to use for the request.
153
+ */
154
+ export type FetchOptions = {
155
+ method?: 'GET' | 'POST';
156
+ variables?: {
157
+ [key: string]: any;
158
+ };
159
+ signal?: AbortSignal;
160
+ cache?: 'default' | 'no-store' | 'reload' | 'no-cache' | 'force-cache' | 'only-if-cached';
161
+ };
162
+ /**
163
+ * Represents an array of error objects that might be returned from a fetch query.
164
+ * Each error object contains a message and extensions with a category.
165
+ *
166
+ * @typedef {Object} FetchQueryError
167
+ * @property {string} message - The error message.
168
+ * @property {Object} extensions - Additional error information.
169
+ * @property {string} extensions.category - The category of the error.
170
+ */
171
+ export type FetchQueryError = Array<{
172
+ message: string;
173
+ extensions: {
174
+ category: string;
175
+ };
176
+ }>;
177
+ declare class FetchGraphQLMesh {
178
+ _endpoint?: string;
179
+ get endpoint(): string | undefined;
180
+ get fetchGraphQlHeaders(): Header | undefined;
181
+ _fetchGraphQlHeaders: Header | undefined;
182
+ setEndpoint(endpoint: string): void;
183
+ setFetchGraphQlHeader(key: string, value: string | null): void;
184
+ removeFetchGraphQlHeader(key: string): void;
185
+ setFetchGraphQlHeaders(header: Header): void;
186
+ fetchGraphQl<T = any>(query: string, options?: FetchOptions): Promise<{
187
+ errors?: FetchQueryError;
188
+ data: T;
189
+ }>;
190
+ getConfig(): {
191
+ endpoint: string | undefined;
192
+ fetchGraphQlHeaders: Header | undefined;
193
+ };
194
+ getMethods(): {
195
+ setEndpoint: (endpoint: string) => void;
196
+ setFetchGraphQlHeader: (key: string, value: string | null) => void;
197
+ removeFetchGraphQlHeader: (key: string) => void;
198
+ setFetchGraphQlHeaders: (header: Header) => void;
199
+ fetchGraphQl: <T = any>(query: string, options?: FetchOptions | undefined) => Promise<{
200
+ errors?: FetchQueryError | undefined;
201
+ data: T;
202
+ }>;
203
+ getConfig: () => {
204
+ endpoint: string | undefined;
205
+ fetchGraphQlHeaders: Header | undefined;
206
+ };
207
+ };
208
+ }
209
+ /**
210
+ * `FetchGraphQL` is a class that extends `FetchGraphQLMesh`. It provides methods to get the GraphQL endpoint and headers.
211
+ *
212
+ * @property {string} endpoint - Gets the GraphQL endpoint. If `_endpoint` is not defined, it will return the `mesh.endpoint`.
213
+ * @property {Object} fetchGraphQlHeaders - Gets the GraphQL headers. If `_endpoint` is defined, it will return `_fetchGraphQlHeaders`.
214
+ * Otherwise, it will return a combination of `_fetchGraphQlHeaders` and `mesh.fetchGraphQlHeaders`.
215
+ * If neither is defined, it will return an empty object.
216
+ *
217
+ * @extends FetchGraphQLMesh
218
+ */
219
+ export declare class FetchGraphQL extends FetchGraphQLMesh {
220
+ get endpoint(): string | undefined;
221
+ get fetchGraphQlHeaders(): Header;
222
+ }
223
+ /**
224
+ * Exports several methods from the `mesh` object.
225
+ *
226
+ * @property {Function} setEndpoint - Sets the GraphQL endpoint. Accepts a string as parameter.
227
+ * @property {Function} setFetchGraphQlHeaders - Sets the GraphQL headers. Accepts an object of headers as parameter.
228
+ * @property {Function} setFetchGraphQlHeader - Sets a specific GraphQL header. Accepts a key-value pair as parameters.
229
+ * @property {Function} removeFetchGraphQlHeader - Removes a specific GraphQL header. Accepts the key of the header as parameter.
230
+ * @property {Function} fetchGraphQl - Fetches GraphQL data. Accepts a query string and an optional options object as parameters. Returns a promise that resolves with the fetched data.
231
+ * @property {Function} getConfig - Gets the configuration. Returns an object with the endpoint and GraphQL headers.
232
+ */
233
+ export declare const setEndpoint: (endpoint: string) => void, setFetchGraphQlHeaders: (header: Header) => void, setFetchGraphQlHeader: (key: string, value: string | null) => void, removeFetchGraphQlHeader: (key: string) => void, fetchGraphQl: <T = any>(query: string, options?: FetchOptions) => Promise<{
234
+ errors?: FetchQueryError | undefined;
235
+ data: T;
236
+ }>, getConfig: () => {
237
+ endpoint: string | undefined;
238
+ fetchGraphQlHeaders: Header | undefined;
239
+ };
240
+ export {};
241
+ //# sourceMappingURL=index.d.ts.map
242
+ }