@dbos-inc/koa-serve 2.11.7-preview.gc208400219 → 2.11.13-preview
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/README.md +280 -1
- package/dist/src/dboshttp.d.ts +2 -2
- package/dist/src/dboshttp.d.ts.map +1 -1
- package/dist/src/dboshttp.js +1 -8
- package/dist/src/dboshttp.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/dboshttp.ts +2 -23
- package/tests/argsource.test.ts +8 -8
package/README.md
CHANGED
|
@@ -1 +1,280 @@
|
|
|
1
|
-
# DBOS HTTP
|
|
1
|
+
# Serve DBOS Functions over HTTP with Koa
|
|
2
|
+
|
|
3
|
+
## Introduction
|
|
4
|
+
|
|
5
|
+
[DBOS](https://github.com/dbos-inc/dbos-transact-ts) provides a lightweight durable execution framework that can be used as a library within any app. This package provides a simple way to serve DBOS functions with the [Koa](https://koajs.com/) web framework.
|
|
6
|
+
|
|
7
|
+
## Registering Endpoints
|
|
8
|
+
|
|
9
|
+
First, create an instance of `DBOSKoa`. This object is used to keep track of which functions are to be registered with routable URLs, so it is OK to create and use it very early in your code. Then, use this instance to register some HTTP endpoint URLs.
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
const dhttp = new DBOSKoa();
|
|
13
|
+
|
|
14
|
+
export class HTTPEndpoints {
|
|
15
|
+
@dhttp.getApi('/foobar')
|
|
16
|
+
static async foobar(arg: string) {
|
|
17
|
+
return Promise.resolve(`Value of 'arg': ${arg}`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
The example above registers an HTTP `GET` endpoint. `postApi`, `deleteApi`, `putApi`, and `patchApi` are also available.
|
|
23
|
+
|
|
24
|
+
## Starting a Koa App
|
|
25
|
+
|
|
26
|
+
The Koa server can be started by your main startup function. Note the order of operations below:
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
DBOS.registerLifecycleCallback(dhttp); // Registers the HTTP function provider with DBOS
|
|
30
|
+
await DBOS.launch(); // Starts DBOS components and begins any necessary recovery
|
|
31
|
+
DBOS.logRegisteredEndpoints(); // Optional - list out all of the registered DBOS event receivers and URLs
|
|
32
|
+
|
|
33
|
+
// Create a new Koa and router
|
|
34
|
+
app = new Koa();
|
|
35
|
+
appRouter = new Router();
|
|
36
|
+
|
|
37
|
+
// Add any URLs and middleware registered via DBOS with your Koa
|
|
38
|
+
dhttp.registerWithApp(app, appRouter);
|
|
39
|
+
|
|
40
|
+
// Tell Koa to serve on port 3000
|
|
41
|
+
app.listen(3000, () => {
|
|
42
|
+
console.log('Server running on http://localhost:3000');
|
|
43
|
+
});
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Integrating With an Existing App
|
|
47
|
+
|
|
48
|
+
If you already have a Koa server in your app, you can add the DBOS HTTP endpoints to it:
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
dhttp.registerWithApp(app, appRouter);
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
You should also be sure to call `DBOS.launch` at some point prior to starting request handling.
|
|
55
|
+
|
|
56
|
+
Node.js HTTP servers are also generally compatible with each other. Your Koa's `app.callback()` can be served within another framework (such as [express](https://expressjs.com/)), or by a HTTP server you set up.
|
|
57
|
+
|
|
58
|
+
## Inputs and HTTP Requests
|
|
59
|
+
|
|
60
|
+
When a function has arguments, DBOS automatically parses them from the HTTP request, and returns an error to the client if they are not found.
|
|
61
|
+
|
|
62
|
+
Automatic argument handling is usually sufficent. If not, see the sections below.
|
|
63
|
+
|
|
64
|
+
### URL Path Parameters
|
|
65
|
+
|
|
66
|
+
You can include a path parameter placeholder in a URL by prefixing it with a colon, like `name` in this example:
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
@dhttp.getApi('/greeting/:name')
|
|
70
|
+
static async greetingEndpoint(name: string) {
|
|
71
|
+
return `Greeting, ${name}`;
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Then, give your method an argument with a matching name (such as `name: string` above) and it is automatically parsed from the path parameter.
|
|
76
|
+
|
|
77
|
+
For example, if we send our app this request, then our method is called with `name` set to `dbos`:
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
GET /greeting/dbos
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### URL Query String Parameters
|
|
84
|
+
|
|
85
|
+
`GET` and `DELETE` endpoints automatically parse arguments from query strings.
|
|
86
|
+
|
|
87
|
+
For example, the following endpoint expects the `id` and `name` parameters to be passed through a query string:
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
@dhttp.getApi('/example')
|
|
91
|
+
static async exampleGet(id: number, name: string) {
|
|
92
|
+
return `${id} and ${name} are parsed from URL query string parameters`;
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
If we send our app this request, then our method is called with `id` set to `123` and `name` set to `dbos`:
|
|
97
|
+
|
|
98
|
+
```
|
|
99
|
+
GET /example?id=123&name=dbos
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### HTTP Body Fields
|
|
103
|
+
|
|
104
|
+
`POST`, `PATCH`, and `PUT` endpoints automatically parse arguments from the HTTP request body.
|
|
105
|
+
|
|
106
|
+
For example, the following endpoint expects the `id` and `name` parameters to be passed through the HTTP request body:
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
@DBOS.postApi('/example')
|
|
110
|
+
static async examplePost(id: number, name: string) {
|
|
111
|
+
return `${id} and ${name} are parsed from the HTTP request body`;
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
If we send our app this request, then our method is called with `id` set to `123` and `name` set to `dbos`:
|
|
116
|
+
|
|
117
|
+
```javascript
|
|
118
|
+
POST /example
|
|
119
|
+
Content-Type: application/json
|
|
120
|
+
{
|
|
121
|
+
"name": "dbos",
|
|
122
|
+
"id": 123
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
When sending an HTTP request with a JSON body, make sure you set the [`Content-Type`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type) header to `application/json`.
|
|
127
|
+
|
|
128
|
+
### Overriding Argument Sources
|
|
129
|
+
|
|
130
|
+
Argument sources can be overriden with the `DBOSKoa.argSource` parameter decorator. For example, to force a POST parameter to be taken from the query string instead of the body:
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
@dhttp.postApi('/postquery')
|
|
134
|
+
static async postQuery(@DBOSKoa.argSource(ArgSources.QUERY) name: string) {
|
|
135
|
+
return Promise.resolve(`hello ${name}`);
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Raw Requests
|
|
140
|
+
|
|
141
|
+
If you need finer-grained request parsing, any DBOS method invoked via HTTP request can access raw request information from `DBOSKoa.httpRequest`. This returns the following information:
|
|
142
|
+
|
|
143
|
+
```typescript
|
|
144
|
+
interface HTTPRequest {
|
|
145
|
+
readonly headers?: IncomingHttpHeaders; // A node's http.IncomingHttpHeaders object.
|
|
146
|
+
readonly rawHeaders?: string[]; // Raw headers.
|
|
147
|
+
readonly params?: unknown; // Parsed path parameters from the URL.
|
|
148
|
+
readonly body?: unknown; // parsed HTTP body as an object.
|
|
149
|
+
readonly rawBody?: string; // Unparsed raw HTTP body string.
|
|
150
|
+
readonly query?: ParsedUrlQuery; // Parsed query string.
|
|
151
|
+
readonly querystring?: string; // Unparsed raw query string.
|
|
152
|
+
readonly url?: string; // Request URL.
|
|
153
|
+
readonly ip?: string; // Request remote address.
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### Accessing the Koa Context
|
|
158
|
+
|
|
159
|
+
For code that needs to access the Koa context to perform a redirect, send a large response, etc., this can be accessed with `DBOSKoa.koaContext`:
|
|
160
|
+
|
|
161
|
+
```typescript
|
|
162
|
+
DBOSKoa.koaContext.redirect(url + '-dbos');
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
## Outputs and HTTP Responses
|
|
166
|
+
|
|
167
|
+
If a function invoked via HTTP request returns successfully, its return value is sent in the HTTP response body with status code `200` (or `204` if nothing is returned).
|
|
168
|
+
|
|
169
|
+
If the function throws an exception, the error message is sent in the response body with a `400` or `500` status code.
|
|
170
|
+
If the error contains a `status` field, the response uses that status code instead.
|
|
171
|
+
|
|
172
|
+
If you need custom HTTP response behavior, you can access the HTTP response directly via [`DBOSKoa.koaContext.response`].
|
|
173
|
+
|
|
174
|
+
## Koa Middleware
|
|
175
|
+
|
|
176
|
+
Middleware may be set up directly on the Koa app or router. Additionally, DBOS provides class-level decorators for placing middleware onto all URLs registered to methods in the class.
|
|
177
|
+
|
|
178
|
+
DBOS supports running arbitrary [Koa](https://koajs.com/) middleware for serving HTTP requests.
|
|
179
|
+
Middlewares are configured at the class level through the `@DBOSKoa.koaMiddleware` decorator.
|
|
180
|
+
Here is an example of a simple middleware checking an HTTP header:
|
|
181
|
+
|
|
182
|
+
```typescript
|
|
183
|
+
import { Middleware } from "koa";
|
|
184
|
+
|
|
185
|
+
const middleware: Middleware = async (ctx, next) => {
|
|
186
|
+
const contentType = ctx.request.headers["content-type"];
|
|
187
|
+
await next();
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
@dhttp.koaMiddleware(middleware)
|
|
191
|
+
class Hello {
|
|
192
|
+
...
|
|
193
|
+
}
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### CORS
|
|
197
|
+
|
|
198
|
+
[Cross-Origin Resource Sharing (CORS)](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) is a security feature that controls access to resources from different domains. DBOS uses [`@koa/cors`](https://github.com/koajs/cors) with a permissive default configuration.
|
|
199
|
+
|
|
200
|
+
If more complex logic is needed, or if the CORS configuration differs between operation classes, the `@DBOSKoa.koaCors` class-level decorator can be used to specify the CORS middleware in full.
|
|
201
|
+
|
|
202
|
+
```typescript
|
|
203
|
+
import cors from '@koa/cors';
|
|
204
|
+
|
|
205
|
+
@dhttp.koaCors(
|
|
206
|
+
cors({
|
|
207
|
+
credentials: true,
|
|
208
|
+
origin: (o: Context) => {
|
|
209
|
+
const whitelist = ['https://us.com', 'https://partner.com'];
|
|
210
|
+
const origin = o.request.header.origin ?? '*';
|
|
211
|
+
return whitelist.includes(origin) ? origin : '';
|
|
212
|
+
},
|
|
213
|
+
}),
|
|
214
|
+
)
|
|
215
|
+
class EndpointsWithSpecialCORS {}
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
### BodyParser
|
|
219
|
+
|
|
220
|
+
By default, DBOS uses [`@koa/bodyparser`](https://github.com/koajs/bodyparser) to support JSON in requests. If this default behavior is not desired, you can configure a custom body parser with the `@DBOSKoa.koaBodyParser` decorator.
|
|
221
|
+
|
|
222
|
+
```typescript
|
|
223
|
+
import { bodyParser } from '@koa/bodyparser';
|
|
224
|
+
|
|
225
|
+
@dhttp.koaBodyParser(
|
|
226
|
+
bodyParser({
|
|
227
|
+
extendTypes: {
|
|
228
|
+
json: ['application/json', 'application/custom-content-type'],
|
|
229
|
+
},
|
|
230
|
+
encoding: 'utf-8',
|
|
231
|
+
}),
|
|
232
|
+
)
|
|
233
|
+
class OperationEndpoints {}
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
### Integration With DBOS User Authentication / Authorization
|
|
237
|
+
|
|
238
|
+
DBOS provides [role-based authorization](https://docs.dbos.dev/typescript/reference/transactapi/dbos-class#declarative-role-based-security). This package provides a middleware-based approach for collecting authentication information, to populate the authenticated user and allowed roles.
|
|
239
|
+
|
|
240
|
+
First, define an authentication middleware function:
|
|
241
|
+
|
|
242
|
+
```typescript
|
|
243
|
+
async function authTestMiddleware(ctx: DBOSKoaAuthContext) {
|
|
244
|
+
if (ctx.requiredRole.length > 0) {
|
|
245
|
+
const { userid } = ctx.koaContext.request.query; // Or other source of user from request, header, cookie, etc.
|
|
246
|
+
const uid = userid?.toString();
|
|
247
|
+
|
|
248
|
+
if (!uid || uid.length === 0) {
|
|
249
|
+
return Promise.reject(new DBOSError.DBOSNotAuthorizedError('Not logged in.', 401));
|
|
250
|
+
} else {
|
|
251
|
+
if (uid === 'unwelcome') {
|
|
252
|
+
return Promise.reject(new DBOSError.DBOSNotAuthorizedError('Go away.', 401));
|
|
253
|
+
}
|
|
254
|
+
return Promise.resolve({
|
|
255
|
+
authenticatedUser: uid,
|
|
256
|
+
authenticatedRoles: uid === 'a_real_user' ? ['user'] : ['other'],
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
Then, attach it to the classes as a middleware:
|
|
265
|
+
|
|
266
|
+
```typescript
|
|
267
|
+
@DBOS.defaultRequiredRole(['user'])
|
|
268
|
+
@dhttp.authentication(authTestMiddleware)
|
|
269
|
+
class EndpointsWithAuthMiddleware {
|
|
270
|
+
// ...
|
|
271
|
+
}
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
### Global Middleware
|
|
275
|
+
|
|
276
|
+
Middleware that is to be run on all routes should be directly added to your Koa app or router. However, for compatibility with prior "serverless" DBOS SDKs, a `@DBOSKoa.koaGlobalMiddleware` decorator exists.
|
|
277
|
+
|
|
278
|
+
## Unit Testing
|
|
279
|
+
|
|
280
|
+
DBOS HTTP functions are easily called in existing test frameworks. See [the unit tests](./tests/basic.test.ts) for examples of setting up DBOS and calling `app.callback()` using `jest` and `supertest`.
|
package/dist/src/dboshttp.d.ts
CHANGED
|
@@ -69,8 +69,8 @@ export declare class DBOSHTTPBase extends DBOSLifecycleCallback {
|
|
|
69
69
|
/** Decorator indicating that the method is the target of HTTP DELETE operations for `url` */
|
|
70
70
|
deleteApi(url: string): <This, Args extends unknown[], Return>(target: object, propertyKey: string, descriptor: TypedPropertyDescriptor<(this: This, ...args: Args) => Promise<Return>>) => TypedPropertyDescriptor<(this: This, ...args: Args) => Promise<Return>>;
|
|
71
71
|
/** Parameter decorator indicating which source to use (URL, BODY, etc) for arg data */
|
|
72
|
-
argSource(source: ArgSources): (target: object, propertyKey: string | symbol, parameterIndex: number) => void;
|
|
73
|
-
getArgSource(arg: MethodParameter): ArgSources;
|
|
72
|
+
static argSource(source: ArgSources): (target: object, propertyKey: string | symbol, parameterIndex: number) => void;
|
|
73
|
+
protected getArgSource(arg: MethodParameter): ArgSources;
|
|
74
74
|
logRegisteredEndpoints(): void;
|
|
75
75
|
static argRequired(target: object, propertyKey: string | symbol, parameterIndex: number): void;
|
|
76
76
|
static argOptional(target: object, propertyKey: string | symbol, parameterIndex: number): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dboshttp.d.ts","sourceRoot":"","sources":["../../src/dboshttp.ts"],"names":[],"mappings":";;;AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAG7C,OAAO,EAEL,qBAAqB,EAErB,eAAe,EAShB,MAAM,oBAAoB,CAAC;AAE5B,oBAAY,QAAQ;IAClB,GAAG,QAAQ;IACX,IAAI,SAAS;IACb,GAAG,QAAQ;IACX,KAAK,UAAU;IACf,MAAM,WAAW;CAClB;AAED,oBAAY,UAAU;IACpB,IAAI,SAAS,CAAE,mBAAmB;IAClC,OAAO,YAAY,CAAE,4CAA4C;IACjE,IAAI,SAAS,CAAE,oBAAoB;IACnC,KAAK,UAAU;CAChB;AAED,MAAM,WAAW,kBAAkB;IACjC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,kBAAkB,EAAE,MAAM,EAAE,CAAC;CAC9B;AAED,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,QAAQ,CAAC;CACnB;AAED,MAAM,WAAW,kBAAkB;IACjC,aAAa,CAAC,EAAE,WAAW,EAAE,CAAC;CAC/B;AAED,MAAM,WAAW,eAAe;IAC9B,SAAS,CAAC,EAAE,UAAU,CAAC;CACxB;
|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E,eAAe;IAKlC,sBAAsB,IAAI,IAAI;IAmBvC,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,EAAE,cAAc,EAAE,MAAM;IAIvF,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,EAAE,cAAc,EAAE,MAAM;IAIvF,MAAM,CAAC,OAAO;IAGd,MAAM,CAAC,UAAU,CAAC,CAAC,EAAE,MAAM;IAI3B,MAAM,CAAC,kBAAkB,CAAC,CAAC,SAAS;QAAE,KAAK,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,MAAM,CAAA;KAAE,EAAE,IAAI,EAAE,CAAC;IAGjF,MAAM,CAAC,kBAAkB,CAAC,CAAC,SAAS;QAAE,KAAK,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,MAAM,CAAA;KAAE,EAAE,IAAI,EAAE,CAAC;IAGjF,MAAM,CAAC,kBAAkB,CAAC,CAAC,SAAS;QAAE,KAAK,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,MAAM,CAAA;KAAE,EAAE,IAAI,EAAE,CAAC;CAGlF"}
|
package/dist/src/dboshttp.js
CHANGED
|
@@ -18,12 +18,6 @@ var ArgSources;
|
|
|
18
18
|
ArgSources["BODY"] = "BODY";
|
|
19
19
|
ArgSources["QUERY"] = "QUERY";
|
|
20
20
|
})(ArgSources || (exports.ArgSources = ArgSources = {}));
|
|
21
|
-
var ArgRequiredOptions;
|
|
22
|
-
(function (ArgRequiredOptions) {
|
|
23
|
-
ArgRequiredOptions["REQUIRED"] = "REQUIRED";
|
|
24
|
-
ArgRequiredOptions["OPTIONAL"] = "OPTIONAL";
|
|
25
|
-
ArgRequiredOptions["DEFAULT"] = "DEFAULT";
|
|
26
|
-
})(ArgRequiredOptions || (ArgRequiredOptions = {}));
|
|
27
21
|
exports.DBOSHTTP = 'dboshttp';
|
|
28
22
|
exports.WorkflowIDHeader = 'dbos-idempotency-key';
|
|
29
23
|
exports.RequestIDHeader = 'X-Request-ID';
|
|
@@ -41,7 +35,6 @@ function isClientRequestError(e) {
|
|
|
41
35
|
return dbos_sdk_1.Error.isDataValidationError(e);
|
|
42
36
|
}
|
|
43
37
|
exports.isClientRequestError = isClientRequestError;
|
|
44
|
-
const VALIDATOR = 'validator';
|
|
45
38
|
class DBOSHTTPBase extends dbos_sdk_1.DBOSLifecycleCallback {
|
|
46
39
|
static HTTP_OPERATION_TYPE = 'http';
|
|
47
40
|
static get httpRequest() {
|
|
@@ -91,7 +84,7 @@ class DBOSHTTPBase extends dbos_sdk_1.DBOSLifecycleCallback {
|
|
|
91
84
|
return this.httpApiDec(APITypes.DELETE, url);
|
|
92
85
|
}
|
|
93
86
|
/** Parameter decorator indicating which source to use (URL, BODY, etc) for arg data */
|
|
94
|
-
argSource(source) {
|
|
87
|
+
static argSource(source) {
|
|
95
88
|
return function (target, propertyKey, parameterIndex) {
|
|
96
89
|
const curParam = dbos_sdk_1.DBOS.associateParamWithInfo(exports.DBOSHTTP,
|
|
97
90
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
package/dist/src/dboshttp.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dboshttp.js","sourceRoot":"","sources":["../../src/dboshttp.ts"],"names":[],"mappings":";;;AAEA,6CAAyC;AAEzC,iDAa4B;AAE5B,IAAY,QAMX;AAND,WAAY,QAAQ;IAClB,uBAAW,CAAA;IACX,yBAAa,CAAA;IACb,uBAAW,CAAA;IACX,2BAAe,CAAA;IACf,6BAAiB,CAAA;AACnB,CAAC,EANW,QAAQ,wBAAR,QAAQ,QAMnB;AAED,IAAY,UAKX;AALD,WAAY,UAAU;IACpB,2BAAa,CAAA;IACb,iCAAmB,CAAA;IACnB,2BAAa,CAAA;IACb,6BAAe,CAAA;AACjB,CAAC,EALW,UAAU,0BAAV,UAAU,QAKrB;
|
|
1
|
+
{"version":3,"file":"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