expediate 0.0.3 → 1.0.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/.npmignore +7 -5
- package/LICENSE +21 -0
- package/README.md +662 -51
- package/dist/apis.d.ts +166 -0
- package/dist/apis.d.ts.map +1 -0
- package/dist/apis.js.map +1 -0
- package/dist/git.d.ts +74 -0
- package/dist/git.d.ts.map +1 -0
- package/dist/git.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +55 -0
- package/dist/index.js.map +1 -0
- package/dist/jwt-auth.d.ts +280 -0
- package/dist/jwt-auth.d.ts.map +1 -0
- package/dist/jwt-auth.js.map +1 -0
- package/dist/misc.d.ts +203 -0
- package/dist/misc.d.ts.map +1 -0
- package/dist/misc.js.map +1 -0
- package/dist/router.d.ts +224 -0
- package/dist/router.d.ts.map +1 -0
- package/dist/router.js.map +1 -0
- package/dist/static.d.ts +164 -0
- package/dist/static.d.ts.map +1 -0
- package/dist/static.js.map +1 -0
- package/package.json +31 -7
- package/src/apis.ts +428 -0
- package/src/git.ts +326 -0
- package/src/index.ts +85 -0
- package/src/jwt-auth.ts +861 -0
- package/src/mimetypes.json +1 -0
- package/src/misc.ts +734 -0
- package/src/router.ts +736 -0
- package/src/static.ts +904 -0
- package/.gitignore +0 -14
- package/index.js +0 -305
- package/sample.js +0 -9
- package/static.js +0 -416
package/dist/apis.d.ts
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import type { RouterRequest, Router } from './router.js';
|
|
2
|
+
/**
|
|
3
|
+
* An API error thrown (or rejected) by a service method.
|
|
4
|
+
*
|
|
5
|
+
* When a service method throws or rejects with an object of this shape, the
|
|
6
|
+
* framework translates it into an HTTP error response automatically:
|
|
7
|
+
* - `httpStatus` → HTTP status code (defaults to `500`).
|
|
8
|
+
* - `data` → JSON-serialised response body (takes precedence over `message`).
|
|
9
|
+
* - `message` → Plain-text response body.
|
|
10
|
+
*/
|
|
11
|
+
export interface ApiError {
|
|
12
|
+
/** HTTP status code to send (e.g. `404`, `503`). Defaults to `500`. */
|
|
13
|
+
httpStatus?: number;
|
|
14
|
+
/** Structured error payload; serialised to JSON when present. */
|
|
15
|
+
data?: unknown;
|
|
16
|
+
/** Human-readable error message used when `data` is absent. */
|
|
17
|
+
message?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* A service method handler.
|
|
21
|
+
*
|
|
22
|
+
* Called with `this` bound to the current service instance.
|
|
23
|
+
*
|
|
24
|
+
* @param params - Route parameters extracted from the URL (e.g. `{ uid: '42' }`),
|
|
25
|
+
* merged with URL query-string parameters.
|
|
26
|
+
* @param body - Parsed request body (populated by a body-parsing middleware
|
|
27
|
+
* such as `json()`).
|
|
28
|
+
* @returns The value to send as the JSON response body, a `Promise` of the
|
|
29
|
+
* same, or `undefined` / `null` / any falsy value to send **201 No
|
|
30
|
+
* Content** (useful for mutations that produce no response body).
|
|
31
|
+
*/
|
|
32
|
+
export type ServiceMethod<TInstance = ServiceInstance> = (this: TInstance, params: Record<string, string>, body?: unknown) => unknown | Promise<unknown>;
|
|
33
|
+
/**
|
|
34
|
+
* The runtime state object that backs a service instance.
|
|
35
|
+
*
|
|
36
|
+
* Produced by `service.data()` and extended with the methods from
|
|
37
|
+
* `service.methods` before `service.setup()` is called. A hidden `$key`
|
|
38
|
+
* property carries the scope key when `data()` is not supplied.
|
|
39
|
+
*/
|
|
40
|
+
export type ServiceInstance = Record<string, unknown> & {
|
|
41
|
+
/** The scope key used to identify this instance (set by the framework). */
|
|
42
|
+
$key?: string | null;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* A named map of method functions to mix into every service instance.
|
|
46
|
+
*
|
|
47
|
+
* Methods declared here are copied onto the instance object, bound to `this`,
|
|
48
|
+
* so they can call each other and read/write instance state naturally.
|
|
49
|
+
*/
|
|
50
|
+
export type ServiceMethods<TInstance extends ServiceInstance = ServiceInstance> = {
|
|
51
|
+
[name: string]: (this: TInstance, ...args: unknown[]) => unknown;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* A route map: keys are Express-style path patterns, values are handler
|
|
55
|
+
* functions that are invoked with `this` bound to the service instance.
|
|
56
|
+
*/
|
|
57
|
+
export type RouteMap<TInstance extends ServiceInstance = ServiceInstance> = {
|
|
58
|
+
[path: string]: ServiceMethod<TInstance>;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* A service definition object — the single argument to {@link apiBuilder}.
|
|
62
|
+
*
|
|
63
|
+
* A service declares its state, helper methods, and HTTP route handlers in
|
|
64
|
+
* one cohesive object. The framework instantiates the service (once globally
|
|
65
|
+
* for a singleton, or per-scope key), mixes in the helper methods, runs
|
|
66
|
+
* `setup()`, then calls the appropriate route handler for each HTTP request.
|
|
67
|
+
*
|
|
68
|
+
* **Scoping:**
|
|
69
|
+
* - When `scope` is **absent** (or not a function), the service is a
|
|
70
|
+
* **singleton**: one shared instance handles all requests.
|
|
71
|
+
* - When `scope` returns a **truthy string**, the same instance is reused
|
|
72
|
+
* for all requests that share that key (e.g. one instance per session).
|
|
73
|
+
* - When `scope` returns **`null`**, a **fresh instance** is created for
|
|
74
|
+
* every request and discarded afterwards (recommended for stateless services).
|
|
75
|
+
*
|
|
76
|
+
* @template TInstance - The shape of the service's state object.
|
|
77
|
+
*/
|
|
78
|
+
export interface ServiceDefinition<TInstance extends ServiceInstance = ServiceInstance> {
|
|
79
|
+
/**
|
|
80
|
+
* Determine the scope key for the current request.
|
|
81
|
+
*
|
|
82
|
+
* - Return a **string** → instances are cached by that key (e.g. session ID).
|
|
83
|
+
* - Return **`null`** → create a new, disposable instance per request.
|
|
84
|
+
* - Omit entirely → the service is a **singleton** (one global instance).
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```ts
|
|
88
|
+
* scope: (req) => (req as any).session?.ssid ?? null,
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
scope?: (req: RouterRequest) => string | null;
|
|
92
|
+
/**
|
|
93
|
+
* Factory that returns the initial state object for a new instance.
|
|
94
|
+
*
|
|
95
|
+
* When omitted, the instance is initialised as `{ $key: key }`.
|
|
96
|
+
*
|
|
97
|
+
* @param key - The scope key passed by the framework (`'singleton'` for
|
|
98
|
+
* global instances, `null` for ephemeral ones, or the string
|
|
99
|
+
* returned by `scope()`).
|
|
100
|
+
*/
|
|
101
|
+
data?: (key: string | null) => TInstance;
|
|
102
|
+
/**
|
|
103
|
+
* Lifecycle hook called once after an instance is created and its methods
|
|
104
|
+
* are mixed in.
|
|
105
|
+
*
|
|
106
|
+
* May be synchronous or asynchronous. When asynchronous, the returned
|
|
107
|
+
* `Promise` is not awaited by the framework — use a `throwIfNotReady()`
|
|
108
|
+
* pattern in your methods to guard against premature access.
|
|
109
|
+
*/
|
|
110
|
+
setup?: (this: TInstance) => void | Promise<void>;
|
|
111
|
+
/**
|
|
112
|
+
* Helper methods mixed into every service instance.
|
|
113
|
+
*
|
|
114
|
+
* All methods are bound to the instance (`this` = instance), so they can
|
|
115
|
+
* read and write state, call other methods, and throw {@link ApiError}
|
|
116
|
+
* objects to trigger HTTP error responses.
|
|
117
|
+
*/
|
|
118
|
+
methods?: ServiceMethods<TInstance>;
|
|
119
|
+
/** Route handlers for `GET` requests. */
|
|
120
|
+
GET?: RouteMap<TInstance>;
|
|
121
|
+
/** Route handlers for `POST` requests. */
|
|
122
|
+
POST?: RouteMap<TInstance>;
|
|
123
|
+
/** Route handlers for `PUT` requests. */
|
|
124
|
+
PUT?: RouteMap<TInstance>;
|
|
125
|
+
/** Route handlers for `DELETE` requests. */
|
|
126
|
+
DELETE?: RouteMap<TInstance>;
|
|
127
|
+
/** Route handlers for `PATCH` requests. */
|
|
128
|
+
PATCH?: RouteMap<TInstance>;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Build an Express-compatible router from a service definition object.
|
|
132
|
+
*
|
|
133
|
+
* The returned router is suitable for mounting via `app.use()`:
|
|
134
|
+
*
|
|
135
|
+
* ```ts
|
|
136
|
+
* import myService from './my-service.js';
|
|
137
|
+
*
|
|
138
|
+
* app.use('/api', apiBuilder(myService));
|
|
139
|
+
* ```
|
|
140
|
+
*
|
|
141
|
+
* **Route handlers** declared in `service.GET`, `service.POST`, etc. are
|
|
142
|
+
* called with `this` bound to the service instance. They receive two
|
|
143
|
+
* arguments:
|
|
144
|
+
* 1. `params` — merged route + query-string parameters from `req.params`.
|
|
145
|
+
* 2. `body` — the parsed request body from `req.body` (requires a
|
|
146
|
+
* body-parsing middleware such as `json()` to run first).
|
|
147
|
+
*
|
|
148
|
+
* **Return values:**
|
|
149
|
+
* - A **truthy value** (or a `Promise` resolving to one) → serialised as JSON
|
|
150
|
+
* with status `200 OK`.
|
|
151
|
+
* - A **falsy value** (`undefined`, `null`, `false`, `0`, `''`) or a
|
|
152
|
+
* `Promise` resolving to one → `201 No Content` (useful for mutations).
|
|
153
|
+
*
|
|
154
|
+
* **Error handling:**
|
|
155
|
+
* - Throwing or rejecting with `{ httpStatus, message }` sends the
|
|
156
|
+
* corresponding HTTP error.
|
|
157
|
+
* - Throwing or rejecting with `{ httpStatus, data }` sends the `data` object
|
|
158
|
+
* as a JSON body.
|
|
159
|
+
* - Any other thrown value produces `500 Internal Server Error`.
|
|
160
|
+
*
|
|
161
|
+
* @param service - The service definition (see {@link ServiceDefinition}).
|
|
162
|
+
* @returns A router instance pre-configured with all declared routes.
|
|
163
|
+
*/
|
|
164
|
+
export declare function apiBuilder<TInstance extends ServiceInstance = ServiceInstance>(service: ServiceDefinition<TInstance>): Router;
|
|
165
|
+
export default apiBuilder;
|
|
166
|
+
//# sourceMappingURL=apis.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apis.d.ts","sourceRoot":"","sources":["../src/apis.ts"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EAAE,aAAa,EAAkB,MAAM,EAAE,MAAM,aAAa,CAAC;AAMzE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,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAI,CAAQ,CAAC,CAAC,CAAC;IACrE,WAAW,CAAC,OAAO,CAAC,GAAG,EAAK,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAK,CAAQ,CAAC,CAAC,CAAC;IACrE,WAAW,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,CAAQ,CAAC,CAAC,CAAC;IACrE,WAAW,CAAC,OAAO,CAAC,KAAK,EAAG,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAG,CAAQ,CAAC,CAAC,CAAC;IAErE,OAAO,GAAG,CAAC;AACb,CAAC;AAED,kBAAe,UAAU,CAAC"}
|
package/dist/git.d.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { RouterRequest, RouterResponse } from './router.js';
|
|
2
|
+
/**
|
|
3
|
+
* Configuration options for {@link gitHandler}.
|
|
4
|
+
*/
|
|
5
|
+
export interface GitHandlerOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Resolve the absolute filesystem path of the Git repository for an
|
|
8
|
+
* incoming request.
|
|
9
|
+
*
|
|
10
|
+
* Return a non-empty string to serve that repository, or a falsy value
|
|
11
|
+
* (`''`, `null`, `undefined`) to respond with **404 Repository not found**.
|
|
12
|
+
*
|
|
13
|
+
* This is the only required option; all others have defaults.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* repository: (req) => path.join('/srv/git', req.params.repo + '.git')
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
repository: (req: RouterRequest) => string | null | undefined | false;
|
|
21
|
+
/**
|
|
22
|
+
* Directory that contains the `git-upload-pack` executable, including a
|
|
23
|
+
* trailing path separator (e.g. `'/usr/lib/git-core/'`).
|
|
24
|
+
*
|
|
25
|
+
* Leave empty (default) to locate the binary via the system `PATH`.
|
|
26
|
+
*/
|
|
27
|
+
gitPath?: string;
|
|
28
|
+
/**
|
|
29
|
+
* When `true`, the `--strict` flag is passed to `git-upload-pack`.
|
|
30
|
+
* This causes the process to exit with an error when the resolved path is
|
|
31
|
+
* not a bare Git repository.
|
|
32
|
+
*
|
|
33
|
+
* Defaults to `false` (non-strict / `--no-strict`).
|
|
34
|
+
*/
|
|
35
|
+
strict?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Kill the `git-upload-pack` process if it does not complete within this
|
|
38
|
+
* many **seconds**. When omitted or `0`, no timeout is applied.
|
|
39
|
+
*/
|
|
40
|
+
timeout?: number | string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Middleware factory that exposes a Git repository over the **Git Smart HTTP
|
|
44
|
+
* protocol** (read-only fetch / clone, via `git-upload-pack`).
|
|
45
|
+
*
|
|
46
|
+
* Mount this handler at the root of a repository-scoped path so that the two
|
|
47
|
+
* sub-paths it handles (`/info/refs` and `/git-upload-pack`) are reachable:
|
|
48
|
+
*
|
|
49
|
+
* ```ts
|
|
50
|
+
* app.use('/repos/:repo', gitHandler({
|
|
51
|
+
* repository: (req) => path.join('/srv/git', req.params.repo + '.git'),
|
|
52
|
+
* }));
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* **Supported endpoints:**
|
|
56
|
+
*
|
|
57
|
+
* | Method | Path | Purpose |
|
|
58
|
+
* |--------|-------------------|----------------------------------------------|
|
|
59
|
+
* | GET | `/info/refs` | Smart HTTP capability advertisement |
|
|
60
|
+
* | POST | `/git-upload-pack`| Pack-file negotiation and transfer |
|
|
61
|
+
*
|
|
62
|
+
* Only `git-upload-pack` (fetch / clone) is implemented.
|
|
63
|
+
* `git-receive-pack` (push) is intentionally excluded.
|
|
64
|
+
*
|
|
65
|
+
* **Compression:** gzip-compressed POST bodies are transparently decompressed
|
|
66
|
+
* before being piped to `git-upload-pack`.
|
|
67
|
+
*
|
|
68
|
+
* @param opt - Handler configuration (see {@link GitHandlerOptions}).
|
|
69
|
+
* @returns An Express-compatible middleware function `(req, res) => void`.
|
|
70
|
+
* @throws {TypeError} When `opt.repository` is not a function.
|
|
71
|
+
*/
|
|
72
|
+
export declare function gitHandler(opt: GitHandlerOptions): (req: RouterRequest, res: RouterResponse) => void;
|
|
73
|
+
export default gitHandler;
|
|
74
|
+
//# sourceMappingURL=git.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"git.d.ts","sourceRoot":"","sources":["../src/git.ts"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAMjE;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;;;;;;;;;;;OAaG;IACH,UAAU,EAAE,CAAC,GAAG,EAAE,aAAa,KAAK,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,KAAK,CAAC;IAEtE;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CAC3B;AA6CD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,iBAAiB,GAAG,CAAC,GAAG,EAAE,aAAa,EAAE,GAAG,EAAE,cAAc,KAAK,IAAI,CAwIpG;AAyCD,eAAe,UAAU,CAAC"}
|
package/dist/git.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"git.js","sourceRoot":"","sources":["../src/git.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,YAAY,CAAC;;AAgIb,gCAwIC;AAtQD,iDAA4C;AAC5C,+BAAoC;AAoDpC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AAE9E;;;;;;;;;;;GAWG;AACH,SAAS,SAAS,CAAC,GAAsB,EAAE,QAAkB;IAC3D,MAAM,IAAI,GAAa,EAAE,CAAC;IAE1B,IAAI,GAAG,CAAC,OAAO,EAAE,CAAC;QAChB,yEAAyE;QACzE,0EAA0E;QAC1E,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC;QAClD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,OAAO,GAAG,CAAC;YAChC,IAAI,CAAC,IAAI,CAAC,aAAa,OAAO,EAAE,CAAC,CAAC;IACtC,CAAC;IAED,0EAA0E;IAC1E,sEAAsE;IACtE,0EAA0E;IAC1E,2EAA2E;IAC3E,yEAAyE;IACzE,6EAA6E;IAC7E,IAAI,CAAC,GAAG,CAAC,MAAM;QACb,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IAE3B,OAAO,CAAC,GAAG,IAAI,EAAE,GAAG,QAAQ,CAAC,CAAC;AAChC,CAAC;AAED,kBAAe,UAAU,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module expediate
|
|
3
|
+
* TypeScript package for web server routing.
|
|
4
|
+
*/
|
|
5
|
+
import createRouter from './router';
|
|
6
|
+
export { createRouter };
|
|
7
|
+
export type { Router, RouterRequest, RouterResponse, Middleware, MiddlewareArg, NextFunction, Layer, CookieOptions, TlsOptions, StringMap, } from './router';
|
|
8
|
+
export { serveStatic, serveFile, sendFile, mime } from './static';
|
|
9
|
+
export type { StaticOptions, Mime } from './static';
|
|
10
|
+
export { json, formData, parseBody, logger } from './misc';
|
|
11
|
+
export type { BodyOptions, LoggerOptions, FormPart, } from './misc';
|
|
12
|
+
import createJwtPlugin from './jwt-auth';
|
|
13
|
+
export { createJwtPlugin };
|
|
14
|
+
export type { JwtPlugin, JwtConfig } from './jwt-auth';
|
|
15
|
+
import gitHandler from './git';
|
|
16
|
+
export { gitHandler };
|
|
17
|
+
export type { GitHandlerOptions, } from './git';
|
|
18
|
+
import apiBuilder from './apis';
|
|
19
|
+
export { apiBuilder };
|
|
20
|
+
export type { ApiError, ServiceMethod, ServiceInstance, ServiceMethods, RouteMap, ServiceDefinition } from './apis';
|
|
21
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAoBA;;;GAGG;AAGH,OAAO,YAAY,MAAM,UAAU,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,CAAA;AACvB,YAAY,EACV,MAAM,EACN,aAAa,EACb,cAAc,EACd,UAAU,EACV,aAAa,EACb,YAAY,EACZ,KAAK,EACL,aAAa,EACb,UAAU,EACV,SAAS,GACV,MAAM,UAAU,CAAC;AAIlB,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAClE,YAAY,EACV,aAAa,EACb,IAAI,EACL,MAAM,UAAU,CAAC;AAIlB,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC3D,YAAY,EACV,WAAW,EACX,aAAa,EACb,QAAQ,GACT,MAAM,QAAQ,CAAC;AAGhB,OAAO,eAAe,MAAM,YAAY,CAAA;AACxC,OAAO,EAAE,eAAe,EAAE,CAAA;AAC1B,YAAY,EACV,SAAS,EACT,SAAS,EACV,MAAM,YAAY,CAAC;AAGpB,OAAQ,UAAU,MAAM,OAAO,CAAA;AAC/B,OAAO,EAAE,UAAU,EAAE,CAAA;AACrB,YAAY,EACR,iBAAiB,GACpB,MAAM,OAAO,CAAA;AAGd,OAAO,UAAU,MAAM,QAAQ,CAAA;AAC/B,OAAO,EAAE,UAAU,EAAE,CAAA;AACrB,YAAY,EACR,QAAQ,EACR,aAAa,EACb,eAAe,EACf,cAAc,EACd,QAAQ,EACR,iBAAiB,EACpB,MAAM,QAAQ,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* Copyright 2021 Fabien Bavent
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
5
|
+
* copy of this software and associated documentation files (the "Software"),
|
|
6
|
+
* to deal in the Software without restriction, including without limitation
|
|
7
|
+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
8
|
+
* and/or sell copies of the Software, and to permit persons to whom the
|
|
9
|
+
* Software is furnished to do so, subject to the following conditions:
|
|
10
|
+
*
|
|
11
|
+
* The above copyright notice and this permission notice shall be included
|
|
12
|
+
* in all copies or substantial portions of the Software.
|
|
13
|
+
*
|
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
15
|
+
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
17
|
+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
19
|
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
20
|
+
* DEALINGS IN THE SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
/**
|
|
23
|
+
* @module expediate
|
|
24
|
+
* TypeScript package for web server routing.
|
|
25
|
+
*/
|
|
26
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
27
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
28
|
+
};
|
|
29
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
+
exports.apiBuilder = exports.gitHandler = exports.createJwtPlugin = exports.logger = exports.parseBody = exports.formData = exports.json = exports.mime = exports.sendFile = exports.serveFile = exports.serveStatic = exports.createRouter = void 0;
|
|
31
|
+
// ── Router ────────────────────────────────────────────────────────────────────
|
|
32
|
+
const router_1 = __importDefault(require("./router"));
|
|
33
|
+
exports.createRouter = router_1.default;
|
|
34
|
+
// ── Static ────────────────────────────────────────────────────────────────────
|
|
35
|
+
var static_1 = require("./static");
|
|
36
|
+
Object.defineProperty(exports, "serveStatic", { enumerable: true, get: function () { return static_1.serveStatic; } });
|
|
37
|
+
Object.defineProperty(exports, "serveFile", { enumerable: true, get: function () { return static_1.serveFile; } });
|
|
38
|
+
Object.defineProperty(exports, "sendFile", { enumerable: true, get: function () { return static_1.sendFile; } });
|
|
39
|
+
Object.defineProperty(exports, "mime", { enumerable: true, get: function () { return static_1.mime; } });
|
|
40
|
+
// ── Miscallenous ──────────────────────────────────────────────────────────────
|
|
41
|
+
var misc_1 = require("./misc");
|
|
42
|
+
Object.defineProperty(exports, "json", { enumerable: true, get: function () { return misc_1.json; } });
|
|
43
|
+
Object.defineProperty(exports, "formData", { enumerable: true, get: function () { return misc_1.formData; } });
|
|
44
|
+
Object.defineProperty(exports, "parseBody", { enumerable: true, get: function () { return misc_1.parseBody; } });
|
|
45
|
+
Object.defineProperty(exports, "logger", { enumerable: true, get: function () { return misc_1.logger; } });
|
|
46
|
+
// ── JWT Authentication ────────────────────────────────────────────────────────
|
|
47
|
+
const jwt_auth_1 = __importDefault(require("./jwt-auth"));
|
|
48
|
+
exports.createJwtPlugin = jwt_auth_1.default;
|
|
49
|
+
// ── Git repository ────────────────────────────────────────────────────────────
|
|
50
|
+
const git_1 = __importDefault(require("./git"));
|
|
51
|
+
exports.gitHandler = git_1.default;
|
|
52
|
+
// ── API Service ───────────────────────────────────────────────────────────────
|
|
53
|
+
const apis_1 = __importDefault(require("./apis"));
|
|
54
|
+
exports.apiBuilder = apis_1.default;
|
|
55
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH;;;GAGG;;;;;;AAEH,iFAAiF;AACjF,sDAAoC;AAC3B,uBADF,gBAAY,CACE;AAcrB,iFAAiF;AAEjF,mCAAkE;AAAzD,qGAAA,WAAW,OAAA;AAAE,mGAAA,SAAS,OAAA;AAAE,kGAAA,QAAQ,OAAA;AAAE,8FAAA,IAAI,OAAA;AAM/C,iFAAiF;AAEjF,+BAA2D;AAAlD,4FAAA,IAAI,OAAA;AAAE,gGAAA,QAAQ,OAAA;AAAE,iGAAA,SAAS,OAAA;AAAE,8FAAA,MAAM,OAAA;AAO1C,iFAAiF;AACjF,0DAAwC;AAC/B,0BADF,kBAAe,CACE;AAMxB,iFAAiF;AACjF,gDAA+B;AACtB,qBADD,aAAU,CACC;AAKnB,iFAAiF;AACjF,kDAA+B;AACtB,qBADF,cAAU,CACE"}
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* jwt-auth.ts
|
|
3
|
+
*
|
|
4
|
+
* JWT authentication plugin for the Expediate router.
|
|
5
|
+
*
|
|
6
|
+
* Provides:
|
|
7
|
+
* - Stateless access tokens (HS256 / HS384 / HS512 HMAC-signed JWTs).
|
|
8
|
+
* - Opaque refresh tokens with server-side storage and automatic rotation.
|
|
9
|
+
* - Route handlers for login, token refresh, and logout.
|
|
10
|
+
* - Middleware for token validation, authorisation, role checks, and
|
|
11
|
+
* permission checks.
|
|
12
|
+
*
|
|
13
|
+
* Security notes:
|
|
14
|
+
* - Passwords are hashed with SHA-256 for demonstration purposes only.
|
|
15
|
+
* Replace with bcrypt / argon2 in production.
|
|
16
|
+
* - The default secrets are placeholders — always override them in production.
|
|
17
|
+
* - Refresh token storage defaults to an in-process Map; replace with a
|
|
18
|
+
* persistent store (Redis, database) for multi-instance deployments.
|
|
19
|
+
*/
|
|
20
|
+
import type { Middleware } from './router.js';
|
|
21
|
+
/** A user record as stored in (or returned by) the user database. */
|
|
22
|
+
export interface UserRecord {
|
|
23
|
+
/** Stable unique identifier (used as JWT `sub` claim when present). */
|
|
24
|
+
id?: string;
|
|
25
|
+
/** Login username. */
|
|
26
|
+
username: string;
|
|
27
|
+
/**
|
|
28
|
+
* SHA-256 hex digest of the user's password.
|
|
29
|
+
* Replace with a bcrypt/argon2 hash in production.
|
|
30
|
+
*/
|
|
31
|
+
passwordHash: string;
|
|
32
|
+
/** Role labels assigned to this user (e.g. `'admin'`, `'editor'`). */
|
|
33
|
+
roles?: string[];
|
|
34
|
+
/**
|
|
35
|
+
* Fine-grained permission strings assigned to this user
|
|
36
|
+
* (e.g. `'read'`, `'write'`, `'delete'`).
|
|
37
|
+
*/
|
|
38
|
+
permissions?: string[];
|
|
39
|
+
/** Any additional fields the application wants to carry. */
|
|
40
|
+
[key: string]: unknown;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The decoded JWT access-token payload attached to `req.user` after
|
|
44
|
+
* successful authentication.
|
|
45
|
+
*/
|
|
46
|
+
export interface TokenPayload {
|
|
47
|
+
/** JWT subject — typically the user's stable ID. */
|
|
48
|
+
sub: string;
|
|
49
|
+
/** Username extracted from the user record. */
|
|
50
|
+
username: string;
|
|
51
|
+
/** Issuer claim, set to `config.issuer`. */
|
|
52
|
+
iss: string;
|
|
53
|
+
/** Issued-at timestamp (Unix seconds). */
|
|
54
|
+
iat: number;
|
|
55
|
+
/** Expiration timestamp (Unix seconds). */
|
|
56
|
+
exp: number;
|
|
57
|
+
/** Roles copied from the user record. */
|
|
58
|
+
roles?: string[];
|
|
59
|
+
/** Permissions copied from the user record. */
|
|
60
|
+
permissions?: string[];
|
|
61
|
+
/** Any additional claims produced by `config.payload`. */
|
|
62
|
+
[key: string]: unknown;
|
|
63
|
+
}
|
|
64
|
+
/** Internal metadata stored alongside each active refresh token. */
|
|
65
|
+
interface RefreshTokenData {
|
|
66
|
+
/** Username the refresh token was issued to. */
|
|
67
|
+
username: string;
|
|
68
|
+
/** Unix ms timestamp of issuance. */
|
|
69
|
+
issuedAt: number;
|
|
70
|
+
/** Unix ms timestamp after which the token must be rejected. */
|
|
71
|
+
expiresAt: number;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Minimal interface for the refresh-token store.
|
|
75
|
+
* Any object implementing these four methods is accepted (Map, Redis client
|
|
76
|
+
* adapter, database wrapper, etc.).
|
|
77
|
+
*/
|
|
78
|
+
export interface TokenStore {
|
|
79
|
+
set(key: string, value: RefreshTokenData): void;
|
|
80
|
+
get(key: string): RefreshTokenData | undefined;
|
|
81
|
+
delete(key: string): void;
|
|
82
|
+
has(key: string): boolean;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Supported HMAC-SHA signing algorithms for JWT.
|
|
86
|
+
* RS*, ES*, and PS* families are not yet implemented.
|
|
87
|
+
*/
|
|
88
|
+
export type JwtAlgorithm = 'HS256' | 'HS384' | 'HS512';
|
|
89
|
+
/**
|
|
90
|
+
* Full configuration object for {@link createJwtPlugin}.
|
|
91
|
+
* All fields have defaults; override only what you need.
|
|
92
|
+
*/
|
|
93
|
+
export interface JwtConfig {
|
|
94
|
+
/** HMAC secret used to sign access tokens. **Change in production.** */
|
|
95
|
+
accessTokenSecret: string;
|
|
96
|
+
/** HMAC secret used to sign refresh tokens (currently unused — refresh *
|
|
97
|
+
* tokens are opaque random strings, not JWTs). Reserved for future use. */
|
|
98
|
+
refreshTokenSecret: string;
|
|
99
|
+
/** Access token lifetime in **seconds**. Defaults to 15 minutes. */
|
|
100
|
+
accessTokenExpiry: number;
|
|
101
|
+
/** Refresh token lifetime in **seconds**. Defaults to 7 days. */
|
|
102
|
+
refreshTokenExpiry: number;
|
|
103
|
+
/** Value placed in the JWT `iss` claim. */
|
|
104
|
+
issuer: string;
|
|
105
|
+
/**
|
|
106
|
+
* When `true`, the `authenticate` middleware rejects tokens whose `iss`
|
|
107
|
+
* claim does not match `config.issuer`.
|
|
108
|
+
* Defaults to `false` (issuer not checked).
|
|
109
|
+
*/
|
|
110
|
+
checkIssuer: boolean;
|
|
111
|
+
/** JWT signing algorithm. Defaults to `'HS256'`. */
|
|
112
|
+
alg: JwtAlgorithm;
|
|
113
|
+
/**
|
|
114
|
+
* Extract the login username from a user record.
|
|
115
|
+
* Defaults to `(user) => user.username`.
|
|
116
|
+
*/
|
|
117
|
+
username: (user: UserRecord) => string;
|
|
118
|
+
/**
|
|
119
|
+
* Fetch a user record by username.
|
|
120
|
+
* Return `undefined` (or any falsy value) when the user does not exist.
|
|
121
|
+
*/
|
|
122
|
+
fetchUser: (username: string) => UserRecord | undefined;
|
|
123
|
+
/**
|
|
124
|
+
* Return `true` when the supplied plain-text `password` is valid for
|
|
125
|
+
* `user`, `false` otherwise.
|
|
126
|
+
*
|
|
127
|
+
* The default implementation compares SHA-256 hashes; replace with a
|
|
128
|
+
* timing-safe bcrypt/argon2 check in production.
|
|
129
|
+
*/
|
|
130
|
+
isPasswordValid: (user: UserRecord, password: string) => boolean;
|
|
131
|
+
/**
|
|
132
|
+
* Build the JWT payload for a user.
|
|
133
|
+
* The `iss`, `iat`, `exp`, and `sub` claims are added automatically.
|
|
134
|
+
* Returning a partial object is fine — the plugin merges the rest.
|
|
135
|
+
*/
|
|
136
|
+
payload: (user: UserRecord) => Partial<TokenPayload>;
|
|
137
|
+
/**
|
|
138
|
+
* Active refresh-token store.
|
|
139
|
+
* Defaults to an in-process `Map` (lost on restart; not suitable for
|
|
140
|
+
* multi-instance deployments).
|
|
141
|
+
*/
|
|
142
|
+
refreshTokenStore: TokenStore;
|
|
143
|
+
}
|
|
144
|
+
/** Result returned by {@link verifyToken}. */
|
|
145
|
+
type VerifyResult = {
|
|
146
|
+
valid: true;
|
|
147
|
+
payload: TokenPayload;
|
|
148
|
+
} | {
|
|
149
|
+
valid: false;
|
|
150
|
+
error: string;
|
|
151
|
+
};
|
|
152
|
+
/**
|
|
153
|
+
* Hash a plain-text password with SHA-256 and return the hex digest.
|
|
154
|
+
*
|
|
155
|
+
* > **⚠ Warning:** SHA-256 is fast and therefore unsuitable for password
|
|
156
|
+
* > hashing in production. Use bcrypt or argon2 instead.
|
|
157
|
+
*
|
|
158
|
+
* @param password - The plain-text password to hash.
|
|
159
|
+
* @returns A 64-character lowercase hex string.
|
|
160
|
+
*/
|
|
161
|
+
export declare function hashPassword(password: string): string;
|
|
162
|
+
/**
|
|
163
|
+
* Default in-memory user database used when no custom `fetchUser` is
|
|
164
|
+
* provided. Contains three demo accounts: alice (admin), bob (editor),
|
|
165
|
+
* charlie (viewer).
|
|
166
|
+
*
|
|
167
|
+
* Replace or ignore this map entirely when you supply your own `fetchUser`.
|
|
168
|
+
*/
|
|
169
|
+
export declare const userDatabase: Map<string, UserRecord>;
|
|
170
|
+
/**
|
|
171
|
+
* Sign a payload object and return a compact JWT string.
|
|
172
|
+
*
|
|
173
|
+
* Automatically adds the `iat` (issued-at) and `exp` (expiration) claims.
|
|
174
|
+
* Any claims already present in `payload` are preserved and take precedence
|
|
175
|
+
* over `iat`/`exp` (use this to override expiry if needed).
|
|
176
|
+
*
|
|
177
|
+
* @param payload - JWT payload claims (must be JSON-serialisable).
|
|
178
|
+
* @param secret - HMAC secret used to sign the token.
|
|
179
|
+
* @param expiresIn - Validity window in **seconds** from the current time.
|
|
180
|
+
* @param alg - Signing algorithm. Defaults to `'HS256'`.
|
|
181
|
+
* @returns A compact JWT string in the form `header.payload.signature`.
|
|
182
|
+
*/
|
|
183
|
+
declare function signToken(payload: Partial<TokenPayload>, secret: string, expiresIn: number, alg?: JwtAlgorithm): string;
|
|
184
|
+
/**
|
|
185
|
+
* Verify a compact JWT string and return its decoded payload on success.
|
|
186
|
+
*
|
|
187
|
+
* Performs the following checks in order:
|
|
188
|
+
* 1. Structural validity (exactly three dot-separated segments).
|
|
189
|
+
* 2. Algorithm consistency (header `alg` matches the expected `alg`).
|
|
190
|
+
* 3. Signature integrity (timing-safe HMAC comparison).
|
|
191
|
+
* 4. Expiration (`exp` claim is in the future).
|
|
192
|
+
*
|
|
193
|
+
* All errors are returned as `{ valid: false, error }` — no exception is
|
|
194
|
+
* thrown to the caller.
|
|
195
|
+
*
|
|
196
|
+
* @param token - The compact JWT string to verify.
|
|
197
|
+
* @param secret - HMAC secret that was used to sign the token.
|
|
198
|
+
* @param alg - Expected signing algorithm.
|
|
199
|
+
* @returns A {@link VerifyResult} discriminated union.
|
|
200
|
+
*/
|
|
201
|
+
declare function verifyToken(token: string, secret: string, alg: JwtAlgorithm): VerifyResult;
|
|
202
|
+
/**
|
|
203
|
+
* The object returned by {@link createJwtPlugin}.
|
|
204
|
+
*
|
|
205
|
+
* Mount the handlers on your router and apply the middleware to protected
|
|
206
|
+
* routes:
|
|
207
|
+
*
|
|
208
|
+
* ```ts
|
|
209
|
+
* const auth = createJwtPlugin({ accessTokenSecret: process.env.JWT_SECRET! });
|
|
210
|
+
*
|
|
211
|
+
* app.post('/auth/login', json(), auth.login);
|
|
212
|
+
* app.post('/auth/refresh', json(), auth.refresh);
|
|
213
|
+
* app.post('/auth/logout', json(), auth.logout);
|
|
214
|
+
*
|
|
215
|
+
* app.get('/me', auth.authenticate, auth.authorize, getProfile);
|
|
216
|
+
* app.delete('/admin', ...auth.requireRole('admin'), deleteHandler);
|
|
217
|
+
* app.put('/posts', ...auth.requirePermission('write'), updateHandler);
|
|
218
|
+
* ```
|
|
219
|
+
*/
|
|
220
|
+
export interface JwtPlugin {
|
|
221
|
+
/**
|
|
222
|
+
* Route handler for `POST /auth/login`.
|
|
223
|
+
* Expects a JSON body with `{ username, password }`.
|
|
224
|
+
* On success: responds with `{ accessToken, refreshToken, expiresIn, tokenType }`.
|
|
225
|
+
*/
|
|
226
|
+
login: Middleware;
|
|
227
|
+
/**
|
|
228
|
+
* Route handler for `POST /auth/refresh`.
|
|
229
|
+
* Expects a JSON body with `{ username, refreshToken }`.
|
|
230
|
+
* On success: responds with a new `{ accessToken, refreshToken, ... }` pair.
|
|
231
|
+
*/
|
|
232
|
+
refresh: Middleware;
|
|
233
|
+
/**
|
|
234
|
+
* Route handler for `POST /auth/logout`.
|
|
235
|
+
* Expects a JSON body with `{ refreshToken }` (optional).
|
|
236
|
+
* Always responds with 200; revokes the refresh token if provided.
|
|
237
|
+
*/
|
|
238
|
+
logout: Middleware;
|
|
239
|
+
/**
|
|
240
|
+
* Middleware that validates the `Authorization: Bearer <token>` header.
|
|
241
|
+
* Sets `req.user` to the decoded {@link TokenPayload} on success.
|
|
242
|
+
* Calls `next()` silently (without error) when the token is absent or invalid,
|
|
243
|
+
* allowing the route to decide how to handle unauthenticated requests.
|
|
244
|
+
*/
|
|
245
|
+
authenticate: Middleware;
|
|
246
|
+
/**
|
|
247
|
+
* Middleware that rejects unauthenticated requests with 401.
|
|
248
|
+
* Should be placed **after** {@link authenticate}:
|
|
249
|
+
* `router.get('/me', auth.authenticate, auth.authorize, handler)`.
|
|
250
|
+
*/
|
|
251
|
+
authorize: Middleware;
|
|
252
|
+
/**
|
|
253
|
+
* Middleware factory that requires the authenticated user to have at least
|
|
254
|
+
* one of the specified roles. Returns `[authenticate, roleCheck]` so it
|
|
255
|
+
* can be spread directly into a route registration:
|
|
256
|
+
* `router.get('/admin', ...auth.requireRole('admin'), handler)`.
|
|
257
|
+
* Responds with 401 when unauthenticated, 403 when the role is missing.
|
|
258
|
+
*/
|
|
259
|
+
requireRole: (...roles: string[]) => Middleware[];
|
|
260
|
+
/**
|
|
261
|
+
* Middleware factory that requires the authenticated user to have **all**
|
|
262
|
+
* of the specified permissions. Returns `[authenticate, permCheck]`.
|
|
263
|
+
* Responds with 401 when unauthenticated, 403 when any permission is missing.
|
|
264
|
+
*/
|
|
265
|
+
requirePermission: (...permissions: string[]) => Middleware[];
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Create a JWT authentication plugin pre-configured with the given options.
|
|
269
|
+
*
|
|
270
|
+
* All config fields have safe defaults for development. At minimum, set
|
|
271
|
+
* `accessTokenSecret` (and `refreshTokenSecret` if you plan to use it) to
|
|
272
|
+
* random values in production.
|
|
273
|
+
*
|
|
274
|
+
* @param userConfig - Partial {@link JwtConfig} overrides.
|
|
275
|
+
* @returns A {@link JwtPlugin} object exposing handlers and middleware.
|
|
276
|
+
*/
|
|
277
|
+
export declare function createJwtPlugin(userConfig?: Partial<JwtConfig>): JwtPlugin;
|
|
278
|
+
export default createJwtPlugin;
|
|
279
|
+
export { signToken, verifyToken, hashPassword as _hashPassword };
|
|
280
|
+
//# sourceMappingURL=jwt-auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jwt-auth.d.ts","sourceRoot":"","sources":["../src/jwt-auth.ts"],"names":[],"mappings":"AAoBA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,KAAK,EAAiC,UAAU,EAAE,MAAM,aAAa,CAAC;AAM7E,qEAAqE;AACrE,MAAM,WAAW,UAAU;IACzB,uEAAuE;IACvE,EAAE,CAAC,EAAY,MAAM,CAAC;IACtB,sBAAsB;IACtB,QAAQ,EAAO,MAAM,CAAC;IACtB;;;OAGG;IACH,YAAY,EAAG,MAAM,CAAC;IACtB,sEAAsE;IACtE,KAAK,CAAC,EAAS,MAAM,EAAE,CAAC;IACxB;;;OAGG;IACH,WAAW,CAAC,EAAG,MAAM,EAAE,CAAC;IACxB,4DAA4D;IAC5D,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,oDAAoD;IACpD,GAAG,EAAW,MAAM,CAAC;IACrB,+CAA+C;IAC/C,QAAQ,EAAM,MAAM,CAAC;IACrB,4CAA4C;IAC5C,GAAG,EAAW,MAAM,CAAC;IACrB,0CAA0C;IAC1C,GAAG,EAAW,MAAM,CAAC;IACrB,2CAA2C;IAC3C,GAAG,EAAW,MAAM,CAAC;IACrB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