inngest 0.8.5 → 0.8.6-beta.1

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/cloudflare.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ServeHandler } from "./express";
1
+ import { ServeHandler } from "./components/InngestCommHandler";
2
2
  /**
3
3
  * In Cloudflare, serve and register any declared functions with Inngest, making
4
4
  * them available to be triggered by events.
@@ -1 +1 @@
1
- {"version":3,"file":"cloudflare.d.ts","sourceRoot":"","sources":["../src/cloudflare.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,YAAY,EACb,MAAM,WAAW,CAAC;AAqHnB;;;;;GAKG;AACH,eAAO,MAAM,KAAK,EAAE,YAOnB,CAAC"}
1
+ {"version":3,"file":"cloudflare.d.ts","sourceRoot":"","sources":["../src/cloudflare.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,YAAY,EACb,MAAM,iCAAiC,CAAC;AAGzC;;;;;GAKG;AACH,eAAO,MAAM,KAAK,EAAE,YAmEnB,CAAC"}
package/cloudflare.js CHANGED
@@ -1,87 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.serve = void 0;
4
- const zod_1 = require("zod");
5
- const express_1 = require("./express");
4
+ const InngestCommHandler_1 = require("./components/InngestCommHandler");
6
5
  const consts_1 = require("./helpers/consts");
7
- const devserver_1 = require("./helpers/devserver");
8
- const landing_1 = require("./landing");
9
- class CloudflareCommHandler extends express_1.InngestCommHandler {
10
- constructor() {
11
- super(...arguments);
12
- this.frameworkName = "cloudflare-pages";
13
- }
14
- createHandler() {
15
- return async ({ request: req, env, }) => {
16
- const headers = { "x-inngest-sdk": this.sdkHeader.join("") };
17
- let reqUrl;
18
- let isIntrospection;
19
- try {
20
- reqUrl = this.reqUrl(req.url, `https://${req.headers.get("host") || ""}`);
21
- isIntrospection = reqUrl.searchParams.has(consts_1.queryKeys.Introspect);
22
- reqUrl.searchParams.delete(consts_1.queryKeys.Introspect);
23
- }
24
- catch (err) {
25
- return new Response(JSON.stringify(err), {
26
- status: 500,
27
- headers,
28
- });
29
- }
30
- if (!this.signingKey && env[consts_1.envKeys.SigningKey]) {
31
- this.signingKey = env[consts_1.envKeys.SigningKey];
32
- }
33
- this._isProd = env.CF_PAGES === "1" || env.ENVIRONMENT === "production";
34
- switch (req.method) {
35
- case "GET": {
36
- const showLandingPage = this.shouldShowLandingPage(env[consts_1.envKeys.LandingPage]);
37
- if (this._isProd || !showLandingPage)
38
- break;
39
- if (isIntrospection) {
40
- const introspection = Object.assign(Object.assign({}, this.registerBody(reqUrl)), { devServerURL: (0, devserver_1.devServerUrl)(env[consts_1.envKeys.DevServerUrl]).href, hasSigningKey: Boolean(this.signingKey) });
41
- return new Response(JSON.stringify(introspection), {
42
- status: 200,
43
- headers,
44
- });
45
- }
46
- // Grab landing page and serve
47
- return new Response(landing_1.landing, {
48
- status: 200,
49
- headers: Object.assign(Object.assign({}, headers), { "content-type": "text/html; charset=utf-8" }),
50
- });
51
- }
52
- case "PUT": {
53
- // Push config to Inngest.
54
- const { status, message } = await this.register(reqUrl, env[consts_1.envKeys.DevServerUrl]);
55
- return new Response(JSON.stringify({ message }), { status, headers });
56
- }
57
- case "POST": {
58
- // Inngest is trying to run a step; confirm signed and run.
59
- const { fnId, stepId } = zod_1.z
60
- .object({
61
- fnId: zod_1.z.string().min(1),
62
- stepId: zod_1.z.string().min(1),
63
- })
64
- .parse({
65
- fnId: reqUrl.searchParams.get(consts_1.queryKeys.FnId),
66
- stepId: reqUrl.searchParams.get(consts_1.queryKeys.StepId),
67
- });
68
- const stepRes = await this.runStep(fnId, stepId, await req.json());
69
- if (stepRes.status === 500) {
70
- return new Response(JSON.stringify(stepRes.error), {
71
- status: stepRes.status,
72
- headers,
73
- });
74
- }
75
- return new Response(JSON.stringify(stepRes.body), {
76
- status: stepRes.status,
77
- headers,
78
- });
79
- }
80
- }
81
- return new Response(null, { status: 405, headers });
82
- };
83
- }
84
- }
85
6
  /**
86
7
  * In Cloudflare, serve and register any declared functions with Inngest, making
87
8
  * them available to be triggered by events.
@@ -89,7 +10,54 @@ class CloudflareCommHandler extends express_1.InngestCommHandler {
89
10
  * @public
90
11
  */
91
12
  const serve = (nameOrInngest, fns, opts) => {
92
- return (0, express_1.serve)(new CloudflareCommHandler(nameOrInngest, fns, Object.assign({ fetch: fetch.bind(globalThis) }, opts)));
13
+ const handler = new InngestCommHandler_1.InngestCommHandler("cloudflare-pages", nameOrInngest, fns, Object.assign({
14
+ /**
15
+ * Assume that we want to override the `fetch` implementation with the one
16
+ * globally available in the Cloudflare env. Specifying it here will
17
+ * ensure we avoid trying to load a Node-compatible version later.
18
+ */
19
+ fetch: fetch.bind(globalThis) }, opts), ({ request: req, env, }) => {
20
+ const url = new URL(req.url, `https://${req.headers.get("host") || ""}`);
21
+ const isProduction = env.CF_PAGES === "1" || env.ENVIRONMENT === "production";
22
+ return {
23
+ view: () => {
24
+ if (req.method === "GET") {
25
+ return {
26
+ url,
27
+ env,
28
+ isIntrospection: url.searchParams.has(consts_1.queryKeys.Introspect),
29
+ isProduction,
30
+ };
31
+ }
32
+ },
33
+ register: () => {
34
+ if (req.method === "PUT") {
35
+ return {
36
+ env,
37
+ url,
38
+ isProduction,
39
+ };
40
+ }
41
+ },
42
+ run: async () => {
43
+ if (req.method === "POST") {
44
+ return {
45
+ fnId: url.searchParams.get(consts_1.queryKeys.FnId),
46
+ data: (await req.json()),
47
+ env,
48
+ isProduction,
49
+ url,
50
+ };
51
+ }
52
+ },
53
+ };
54
+ }, ({ body, status, headers }) => {
55
+ return new Response(body, {
56
+ status,
57
+ headers,
58
+ });
59
+ });
60
+ return handler.createHandler();
93
61
  };
94
62
  exports.serve = serve;
95
63
  //# sourceMappingURL=cloudflare.js.map
package/cloudflare.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cloudflare.js","sourceRoot":"","sources":["../src/cloudflare.ts"],"names":[],"mappings":";;;AAAA,6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,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAwB;wBAC/C,GAAG;wBACH,YAAY;wBACZ,GAAG;qBACJ,CAAC;iBACH;YACH,CAAC;SACF,CAAC;IACJ,CAAC,EACD,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,EAAY,EAAE;QACtC,OAAO,IAAI,QAAQ,CAAC,IAAI,EAAE;YACxB,MAAM;YACN,OAAO;SACR,CAAC,CAAC;IACL,CAAC,CACF,CAAC;IAEF,OAAO,OAAO,CAAC,aAAa,EAAE,CAAC;AACjC,CAAC,CAAC;AAnEW,QAAA,KAAK,SAmEhB"}
@@ -0,0 +1,379 @@
1
+ import type { MaybePromise } from "../helpers/types";
2
+ import type { FunctionConfig, RegisterOptions, RegisterRequest, StepRunResponse } from "../types";
3
+ import type { Inngest } from "./Inngest";
4
+ import type { InngestFunction } from "./InngestFunction";
5
+ /**
6
+ * A handler for serving Inngest functions. This type should be used
7
+ * whenever a handler for a new framework is being added to enforce that the
8
+ * registration process is always the same for the user.
9
+ *
10
+ * @example
11
+ * ```
12
+ * // my-custom-handler.ts
13
+ * import { InngestCommHandler, ServeHandler } from "inngest";
14
+ *
15
+ * export const serve: ServeHandler = (nameOrInngest, fns, opts) => {
16
+ * const handler = new InngestCommHandler(
17
+ * "my-custom-handler",
18
+ * nameOrInngest,
19
+ * fns,
20
+ * opts,
21
+ * () => { ... },
22
+ * () => { ... }
23
+ * );
24
+ *
25
+ * return handler.createHandler();
26
+ * };
27
+ * ```
28
+ *
29
+ * @public
30
+ */
31
+ export declare type ServeHandler = (
32
+ /**
33
+ * The name of this app, used to scope and group Inngest functions, or
34
+ * the `Inngest` instance used to declare all functions.
35
+ */
36
+ nameOrInngest: string | Inngest<any>,
37
+ /**
38
+ * An array of the functions to serve and register with Inngest.
39
+ */
40
+ functions: InngestFunction<any>[],
41
+ /**
42
+ * A set of options to further configure the registration of Inngest
43
+ * functions.
44
+ */
45
+ opts?: RegisterOptions) => any;
46
+ /**
47
+ * `InngestCommHandler` is a class for handling incoming requests from Inngest (or
48
+ * Inngest's tooling such as the dev server or CLI) and taking appropriate
49
+ * action for any served functions.
50
+ *
51
+ * All handlers (Next.js, RedwoodJS, Remix, Deno Fresh, etc) are created using
52
+ * this class; the exposed `serve` function will - most commonly - create an
53
+ * instance of `InngestCommHandler` and then return `instance.createHandler()`.
54
+ *
55
+ * Two critical parameters required are the `handler` and the `transformRes`
56
+ * function. See individual parameter details for more information, or see the
57
+ * source code for an existing handler, e.g.
58
+ * {@link https://github.com/inngest/inngest-js/blob/main/src/next.ts}
59
+ *
60
+ * @example
61
+ * ```
62
+ * // my-custom-handler.ts
63
+ * import { InngestCommHandler, ServeHandler } from "inngest";
64
+ *
65
+ * export const serve: ServeHandler = (nameOrInngest, fns, opts) => {
66
+ * const handler = new InngestCommHandler(
67
+ * "my-custom-handler",
68
+ * nameOrInngest,
69
+ * fns,
70
+ * opts,
71
+ * () => { ... },
72
+ * () => { ... }
73
+ * );
74
+ *
75
+ * return handler.createHandler();
76
+ * };
77
+ * ```
78
+ *
79
+ * @public
80
+ */
81
+ export declare class InngestCommHandler<H extends Handler, TransformedRes> {
82
+ /**
83
+ * The name of this serve handler, e.g. `"My App"`. It's recommended that this
84
+ * value represents the overarching app/service that this set of functions is
85
+ * being served from.
86
+ */
87
+ readonly name: string;
88
+ /**
89
+ * The handler specified during instantiation of the class.
90
+ */
91
+ readonly handler: H;
92
+ /**
93
+ * The response transformer specified during instantiation of the class.
94
+ */
95
+ readonly transformRes: (res: ActionResponse, ...args: Parameters<H>) => TransformedRes;
96
+ /**
97
+ * The URL of the Inngest function registration endpoint.
98
+ */
99
+ private readonly inngestRegisterUrl;
100
+ /**
101
+ * The name of the framework this handler is designed for. Should be
102
+ * lowercase, alphanumeric characters inclusive of `-` and `/`. This should
103
+ * never be defined by the user; a {@link ServeHandler} should abstract this.
104
+ */
105
+ protected readonly frameworkName: string;
106
+ /**
107
+ * The signing key used to validate requests from Inngest. This is
108
+ * intentionally mutatble so that we can pick up the signing key from the
109
+ * environment during execution if needed.
110
+ */
111
+ protected signingKey: string | undefined;
112
+ /**
113
+ * A property that can be set to indicate whether or not we believe we are in
114
+ * production mode.
115
+ *
116
+ * Should be set every time a request is received.
117
+ */
118
+ protected _isProd: boolean;
119
+ /**
120
+ * A set of headers sent back with every request. Usually includes generic
121
+ * functionality such as `"Content-Type"`, alongside informational headers
122
+ * such as Inngest SDK version.
123
+ */
124
+ private readonly headers;
125
+ /**
126
+ * The localized `fetch` implementation used by this handler.
127
+ */
128
+ private readonly fetch;
129
+ /**
130
+ * Whether we should show the SDK Landing Page.
131
+ *
132
+ * This purposefully does not take in to account any environment variables, as
133
+ * accessing them safely is platform-specific.
134
+ */
135
+ protected readonly showLandingPage: boolean | undefined;
136
+ /**
137
+ * The host used to access the Inngest serve endpoint, e.g.:
138
+ *
139
+ * "https://myapp.com"
140
+ *
141
+ * By default, the library will try to infer this using request details such
142
+ * as the "Host" header and request path, but sometimes this isn't possible
143
+ * (e.g. when running in a more controlled environments such as AWS Lambda or
144
+ * when dealing with proxies/rediects).
145
+ *
146
+ * Provide the custom hostname here to ensure that the path is reported
147
+ * correctly when registering functions with Inngest.
148
+ *
149
+ * To also provide a custom path, use `servePath`.
150
+ */
151
+ protected readonly serveHost: string | undefined;
152
+ /**
153
+ * The path to the Inngest serve endpoint. e.g.:
154
+ *
155
+ * "/some/long/path/to/inngest/endpoint"
156
+ *
157
+ * By default, the library will try to infer this using request details such
158
+ * as the "Host" header and request path, but sometimes this isn't possible
159
+ * (e.g. when running in a more controlled environments such as AWS Lambda or
160
+ * when dealing with proxies/rediects).
161
+ *
162
+ * Provide the custom path (excluding the hostname) here to ensure that the
163
+ * path is reported correctly when registering functions with Inngest.
164
+ *
165
+ * To also provide a custom hostname, use `serveHost`.
166
+ */
167
+ protected readonly servePath: string | undefined;
168
+ /**
169
+ * A private collection of functions that are being served. This map is used
170
+ * to find and register functions when interacting with Inngest Cloud.
171
+ */
172
+ private readonly fns;
173
+ constructor(
174
+ /**
175
+ * The name of the framework this handler is designed for. Should be
176
+ * lowercase, alphanumeric characters inclusive of `-` and `/`.
177
+ *
178
+ * This should never be defined by the user; a {@link ServeHandler} should
179
+ * abstract this.
180
+ */
181
+ frameworkName: string,
182
+ /**
183
+ * The name of this serve handler, e.g. `"My App"`. It's recommended that this
184
+ * value represents the overarching app/service that this set of functions is
185
+ * being served from.
186
+ *
187
+ * This can also be an `Inngest` client, in which case the name given when
188
+ * instantiating the client is used. This is useful if you're sending and
189
+ * receiving events from the same service, as you can reuse a single
190
+ * definition of Inngest.
191
+ */
192
+ appNameOrInngest: string | Inngest<any>,
193
+ /**
194
+ * An array of the functions to serve and register with Inngest.
195
+ */
196
+ functions: InngestFunction<any>[], { inngestRegisterUrl, fetch, landingPage, signingKey, serveHost, servePath, }: RegisterOptions | undefined,
197
+ /**
198
+ * The `handler` is the function your framework requires to handle a
199
+ * request. For example, this is most commonly a function that is given a
200
+ * `Request` and must return a `Response`.
201
+ *
202
+ * The handler must map out any incoming parameters, then return a
203
+ * strictly-typed object to assess what kind of request is being made,
204
+ * collecting any relevant data as we go.
205
+ *
206
+ * @example
207
+ * ```
208
+ * return {
209
+ * register: () => { ... },
210
+ * run: () => { ... },
211
+ * view: () => { ... }
212
+ * };
213
+ * ```
214
+ *
215
+ * Every key must be specified and must be a function that either returns
216
+ * a strictly-typed payload or `undefined` if the request is not for that
217
+ * purpose.
218
+ *
219
+ * This gives handlers freedom to choose how their platform of choice will
220
+ * trigger differing actions, whilst also ensuring all required information
221
+ * is given for each request type.
222
+ *
223
+ * See any existing handler for a full example.
224
+ *
225
+ * This should never be defined by the user; a {@link ServeHandler} should
226
+ * abstract this.
227
+ */
228
+ handler: H,
229
+ /**
230
+ * The `transformRes` function receives the output of the Inngest SDK and
231
+ * can decide how to package up that information to appropriately return the
232
+ * information to Inngest.
233
+ *
234
+ * Mostly, this is taking the given parameters and returning a new
235
+ * `Response`.
236
+ *
237
+ * The function is passed an {@link ActionResponse} (an object containing a
238
+ * `status` code, a `headers` object, and a stringified `body`), as well as
239
+ * every parameter passed to the given `handler` function. This ensures you
240
+ * can appropriately handle the response, including use of any required
241
+ * parameters such as `res` in Express-/Connect-like frameworks.
242
+ *
243
+ * This should never be defined by the user; a {@link ServeHandler} should
244
+ * abstract this.
245
+ */
246
+ transformRes: (actionRes: ActionResponse, ...args: Parameters<H>) => TransformedRes);
247
+ private get hashedSigningKey();
248
+ /**
249
+ * `createHandler` should be used to return a type-equivalent version of the
250
+ * `handler` specified during instantiation.
251
+ *
252
+ * @example
253
+ * ```
254
+ * // my-custom-handler.ts
255
+ * import { InngestCommHandler, ServeHandler } from "inngest";
256
+ *
257
+ * export const serve: ServeHandler = (nameOrInngest, fns, opts) => {
258
+ * const handler = new InngestCommHandler(
259
+ * "my-custom-handler",
260
+ * nameOrInngest,
261
+ * fns,
262
+ * opts,
263
+ * () => { ... },
264
+ * () => { ... }
265
+ * );
266
+ *
267
+ * return handler.createHandler();
268
+ * };
269
+ * ```
270
+ */
271
+ createHandler(): (...args: Parameters<H>) => Promise<TransformedRes>;
272
+ /**
273
+ * Given a set of functions to check if an action is available from the
274
+ * instance's handler, enact any action that is found.
275
+ *
276
+ * This method can fetch varying payloads of data, but ultimately is the place
277
+ * where _decisions_ are made regarding functionality.
278
+ *
279
+ * For example, if we find that we should be viewing the UI, this function
280
+ * will decide whether the UI should be visible based on the payload it has
281
+ * found (e.g. env vars, options, etc).
282
+ */
283
+ private handleAction;
284
+ protected runStep(functionId: string, stepId: string, data: any): Promise<StepRunResponse>;
285
+ protected configs(url: URL): FunctionConfig[];
286
+ /**
287
+ * Returns an SDK header split in to three parts so that they can be used for
288
+ * different purposes.
289
+ *
290
+ * To use the entire string, run `this.sdkHeader.join("")`.
291
+ */
292
+ protected get sdkHeader(): [
293
+ prefix: string,
294
+ version: RegisterRequest["sdk"],
295
+ suffix: string
296
+ ];
297
+ /**
298
+ * Return an Inngest serve endpoint URL given a potential `path` and `host`.
299
+ *
300
+ * Will automatically use the `serveHost` and `servePath` if they have been
301
+ * set when registering.
302
+ */
303
+ protected reqUrl(url: URL): URL;
304
+ protected registerBody(url: URL): RegisterRequest;
305
+ protected register(url: URL, devServerHost: string | undefined): Promise<{
306
+ status: number;
307
+ message: string;
308
+ }>;
309
+ private get isProd();
310
+ private upsertSigningKeyFromEnv;
311
+ protected shouldShowLandingPage(strEnvVar: string | undefined): boolean;
312
+ protected validateSignature(): boolean;
313
+ protected signResponse(): string;
314
+ }
315
+ /**
316
+ * The broad definition of a handler passed when instantiating an
317
+ * {@link InngestCommHandler} instance.
318
+ */
319
+ declare type Handler = (...args: any[]) => {
320
+ [K in Extract<HandlerAction, {
321
+ action: "run" | "register" | "view";
322
+ }>["action"]]: () => MaybePromise<Omit<Extract<HandlerAction, {
323
+ action: K;
324
+ }>, "action"> | undefined>;
325
+ };
326
+ /**
327
+ * The response from the Inngest SDK before it is transformed in to a
328
+ * framework-compatible response by an {@link InngestCommHandler} instance.
329
+ */
330
+ interface ActionResponse {
331
+ /**
332
+ * The HTTP status code to return.
333
+ */
334
+ status: number;
335
+ /**
336
+ * The headers to return in the response.
337
+ */
338
+ headers: Record<string, string>;
339
+ /**
340
+ * A stringified body to return.
341
+ */
342
+ body: string;
343
+ }
344
+ /**
345
+ * A set of actions the SDK is aware of, including any payloads they require
346
+ * when requesting them.
347
+ */
348
+ declare type HandlerAction = {
349
+ action: "error";
350
+ data: Record<string, string>;
351
+ env: Record<string, string | undefined>;
352
+ isProduction: boolean;
353
+ url: URL;
354
+ } | {
355
+ action: "view";
356
+ env: Record<string, string | undefined>;
357
+ url: URL;
358
+ isIntrospection: boolean;
359
+ isProduction: boolean;
360
+ } | {
361
+ action: "register";
362
+ env: Record<string, string | undefined>;
363
+ url: URL;
364
+ isProduction: boolean;
365
+ } | {
366
+ action: "run";
367
+ fnId: string;
368
+ data: Record<string, any>;
369
+ env: Record<string, string | undefined>;
370
+ isProduction: boolean;
371
+ url: URL;
372
+ } | {
373
+ action: "bad-method";
374
+ env: Record<string, string | undefined>;
375
+ isProduction: boolean;
376
+ url: URL;
377
+ };
378
+ export {};
379
+ //# sourceMappingURL=InngestCommHandler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InngestCommHandler.d.ts","sourceRoot":"","sources":["../../src/components/InngestCommHandler.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAErD,OAAO,KAAK,EACV,cAAc,EAEd,eAAe,EACf,eAAe,EACf,eAAe,EAChB,MAAM,UAAU,CAAC;AAElB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEzD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,oBAAY,YAAY,GAAG;AACzB;;;GAGG;AACH,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;AAEpC;;GAEG;AACH,SAAS,EAAE,eAAe,CAAC,GAAG,CAAC,EAAE;AAEjC;;;GAGG;AACH,IAAI,CAAC,EAAE,eAAe,KACnB,GAAG,CAAC;AAgBT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,qBAAa,kBAAkB,CAAC,CAAC,SAAS,OAAO,EAAE,cAAc;IAC/D;;;;OAIG;IACH,SAAgB,IAAI,EAAE,MAAM,CAAC;IAE7B;;OAEG;IACH,SAAgB,OAAO,EAAE,CAAC,CAAC;IAE3B;;OAEG;IACH,SAAgB,YAAY,EAAE,CAC5B,GAAG,EAAE,cAAc,EACnB,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,KACnB,cAAc,CAAC;IAEpB;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAM;IAEzC;;;;OAIG;IACH,SAAS,CAAC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAEzC;;;;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