@axiumine/koa-utils 9.1.1 → 9.3.0
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 +6 -6
- package/dist/email/ISocketLabsClient.d.mts +4 -3
- package/dist/email/ISocketLabsMessage.d.mts +1 -1
- package/dist/email/ISocketLabsSendResult.d.mts +3 -3
- package/dist/email/ISocketLabsSenderOptions.d.mts +9 -8
- package/dist/email/SocketLabsLib.d.mts +2 -15
- package/dist/email/SocketLabsLib.mjs +4 -19
- package/dist/email/createSocketLabsSender.d.mts +9 -8
- package/dist/email/createSocketLabsSender.mjs +16 -22
- package/dist/files/GLB_POLICY_DEFAULTS.d.mts +49 -0
- package/dist/files/GLB_POLICY_DEFAULTS.mjs +45 -0
- package/dist/files/GLB_REJECT_CODES.d.mts +29 -0
- package/dist/files/GLB_REJECT_CODES.mjs +51 -0
- package/dist/files/IGlbContainer.d.mts +12 -0
- package/dist/files/IGlbContainer.mjs +2 -0
- package/dist/files/IGlbSanitiseResult.d.mts +56 -0
- package/dist/files/IGlbSanitiseResult.mjs +2 -0
- package/dist/files/checkGlbContainer.d.mts +11 -0
- package/dist/files/checkGlbContainer.mjs +68 -0
- package/dist/files/sanitiseGlb.d.mts +22 -0
- package/dist/files/sanitiseGlb.mjs +66 -0
- package/dist/files/sanitiseGlbFile.d.mts +16 -0
- package/dist/files/sanitiseGlbFile.mjs +36 -0
- package/dist/files/validateGlbExtension.d.mts +1 -0
- package/dist/files/validateGlbExtension.mjs +9 -0
- package/dist/files/validateMimeTypeGlb.d.mts +5 -0
- package/dist/files/validateMimeTypeGlb.mjs +9 -0
- package/dist/private/email/ISocketLabsBasicMessage.d.mts +22 -0
- package/dist/private/email/ISocketLabsBasicMessage.mjs +2 -0
- package/dist/private/email/ISocketLabsOutcome.d.mts +10 -0
- package/dist/private/email/ISocketLabsOutcome.mjs +2 -0
- package/dist/private/email/SocketLabsSendError.d.mts +17 -0
- package/dist/private/email/SocketLabsSendError.mjs +21 -0
- package/dist/private/email/socketLabsClient.d.mts +26 -0
- package/dist/private/email/socketLabsClient.mjs +80 -0
- package/dist/private/email/socketLabsMessage.d.mts +9 -0
- package/dist/private/email/socketLabsMessage.mjs +36 -0
- package/dist/private/email/socketLabsRequest.d.mts +19 -0
- package/dist/private/email/socketLabsRequest.mjs +86 -0
- package/dist/private/email/socketLabsResponse.d.mts +10 -0
- package/dist/private/email/socketLabsResponse.mjs +49 -0
- package/dist/private/email/withDefined.d.mts +4 -0
- package/dist/private/email/withDefined.mjs +5 -0
- package/dist/private/glb/IImageSize.d.mts +5 -0
- package/dist/private/glb/IImageSize.mjs +2 -0
- package/dist/private/glb/checkGlbCounts.d.mts +15 -0
- package/dist/private/glb/checkGlbCounts.mjs +53 -0
- package/dist/private/glb/checkGlbExtensions.d.mts +7 -0
- package/dist/private/glb/checkGlbExtensions.mjs +26 -0
- package/dist/private/glb/checkGlbGeometry.d.mts +9 -0
- package/dist/private/glb/checkGlbGeometry.mjs +56 -0
- package/dist/private/glb/checkGlbImages.d.mts +10 -0
- package/dist/private/glb/checkGlbImages.mjs +60 -0
- package/dist/private/glb/checkGlbUris.d.mts +7 -0
- package/dist/private/glb/checkGlbUris.mjs +25 -0
- package/dist/private/glb/glbExtensions.d.mts +7 -0
- package/dist/private/glb/glbExtensions.mjs +13 -0
- package/dist/private/glb/glbIo.d.mts +7 -0
- package/dist/private/glb/glbIo.mjs +16 -0
- package/dist/private/glb/glbReason.d.mts +7 -0
- package/dist/private/glb/glbReason.mjs +14 -0
- package/dist/private/glb/glbStats.d.mts +5 -0
- package/dist/private/glb/glbStats.mjs +24 -0
- package/dist/private/glb/inspectGlbJson.d.mts +8 -0
- package/dist/private/glb/inspectGlbJson.mjs +21 -0
- package/dist/private/glb/jsonAccess.d.mts +17 -0
- package/dist/private/glb/jsonAccess.mjs +24 -0
- package/dist/private/glb/parseGlbJson.d.mts +11 -0
- package/dist/private/glb/parseGlbJson.mjs +14 -0
- package/dist/private/glb/reEncodeImage.d.mts +13 -0
- package/dist/private/glb/reEncodeImage.mjs +24 -0
- package/dist/private/glb/readImageHeader.d.mts +25 -0
- package/dist/private/glb/readImageHeader.mjs +68 -0
- package/dist/private/glb/readJpegSize.d.mts +3 -0
- package/dist/private/glb/readJpegSize.mjs +27 -0
- package/dist/private/glb/readKtx2Size.d.mts +3 -0
- package/dist/private/glb/readKtx2Size.mjs +23 -0
- package/dist/private/glb/reencodeTextures.d.mts +9 -0
- package/dist/private/glb/reencodeTextures.mjs +34 -0
- package/dist/private/glb/resolveGlbPolicy.d.mts +6 -0
- package/dist/private/glb/resolveGlbPolicy.mjs +48 -0
- package/dist/private/glb/rewriteGlb.d.mts +16 -0
- package/dist/private/glb/rewriteGlb.mjs +49 -0
- package/dist/private/glb/stripExtras.d.mts +8 -0
- package/dist/private/glb/stripExtras.mjs +16 -0
- package/dist/private/glb/validateKhronos.d.mts +12 -0
- package/dist/private/glb/validateKhronos.mjs +32 -0
- package/dist/private/glb/verifyGlbOutput.d.mts +8 -0
- package/dist/private/glb/verifyGlbOutput.mjs +20 -0
- package/package.json +69 -16
package/README.md
CHANGED
|
@@ -34,10 +34,10 @@ yarn add @node-rs/bcrypt graphql mongoose redis
|
|
|
34
34
|
| `graphql` | `graphQL/throw/*`, `graphQL/schema/types/*`, `graphQL/schema/GraphQLInput/*`, the mutations, and every subpath that raises a `GraphQLError` through a `throw*` helper: `lib/checkEmailLen`, `lib/checkPwdLen`, `lib/tryCatchRethrow`, `lib/MongoDB/*`, `lib/MariaDB/throwSqlErrors`, `lib/throwIfNotValidEnumValue`, `lib/access/create*Flow`, `lib/access/*Mailer`, `koa/customFormatErrorFn`, `koa/tdwKoaErrorHandler`, the `koa/middleware/*` handlers, `koa/router/verifyEmail`, `email/SocketLabsLib`, `files/uploadTempImage` and `files/reEncodeTo*` |
|
|
35
35
|
| `mongoose` | `dataSources/MongoDB`, the models (`graphQL/models/MongoDB/*`), the mutations other than `logout` and `refresh`, `lib/db/*`, `lib/OBJECTID_0_OBJ`, `lib/access/create*Flow`, `koa/router/verifyEmail`, `koa/middleware/authenticatedAuthorizationHandler`, `koa/middleware/authenticatedResourceHandler` (its types are also named by a few `.d.mts` files) |
|
|
36
36
|
| `redis` | `dataSources/Redis`, the `login*` / `logout` / `refresh` mutations, `koa/middleware/authenticatedAuthorizationHandler`, `koa/middleware/authenticatedLogoutHandler`, `koa/middleware/authenticatedResourceHandler` |
|
|
37
|
-
| `@
|
|
37
|
+
| `@gltf-transform/core`, `@gltf-transform/extensions`, `@gltf-transform/functions`, `gltf-validator`, `meshoptimizer` | `files/sanitiseGlb`, `files/sanitiseGlbFile` only (the GLB sanitiser; `sharp` is needed there too). `gltf-validator` is published only as `2.0.0-dev.*` prereleases, so its peer range is `>=2.0.0-0 <3` |
|
|
38
38
|
| `clamscan` | `files/scanVirus`, `files/uploadTempImage`, `files/uploadTempPdf` |
|
|
39
|
-
| `file-type` | `files/validateMimeType`, `files/validateMimeTypeImages`, `files/validateJpgPngMimeType`, `files/uploadTempImage`, `files/uploadTempPdf` — loaded lazily, at first call |
|
|
40
|
-
| `fs-extra` | the `files/move*` and `files/validate*` helpers, `files/uploadTempImage`, `files/uploadTempPdf` |
|
|
39
|
+
| `file-type` | `files/validateMimeType`, `files/validateMimeTypeImages`, `files/validateJpgPngMimeType`, `files/validateMimeTypeGlb`, `files/uploadTempImage`, `files/uploadTempPdf` — loaded lazily, at first call |
|
|
40
|
+
| `fs-extra` | the `files/move*` and `files/validate*` helpers (the GLB ones included), `files/uploadTempImage`, `files/uploadTempPdf` |
|
|
41
41
|
| `keygrip` | `koa/middleware/authenticatedAuthorizationHandler`, `.../verifySignedRefreshToken`, `koa/middleware/authenticatedLogoutHandler` — types only; the `Keygrip` instance is yours to construct and pass in |
|
|
42
42
|
| `koa` | the `koa/middleware/*` handlers, `koa/tdwKoaErrorHandler`, `koa/logRequestToDb` — types only (`Next`) |
|
|
43
43
|
| `mariadb` | `dataSources/MariaDB` — Sequelize connects with `dialect: 'mariadb'` and loads the driver itself |
|
|
@@ -45,11 +45,11 @@ yarn add @node-rs/bcrypt graphql mongoose redis
|
|
|
45
45
|
| `reflect-metadata` | `dataSources/MariaDB` — required by `sequelize-typescript`, never imported by this package |
|
|
46
46
|
| `sequelize` | `dataSources/MariaDB` — peer of `sequelize-typescript` |
|
|
47
47
|
| `sequelize-typescript` | `dataSources/MariaDB` |
|
|
48
|
-
| `sharp` | `files/reEncodeToJpeg`, `files/reEncodeToPng`, `files/reEncodeToWebp`, `files/uploadTempImage` |
|
|
48
|
+
| `sharp` | `files/reEncodeToJpeg`, `files/reEncodeToPng`, `files/reEncodeToWebp`, `files/uploadTempImage`, `files/sanitiseGlb`, `files/sanitiseGlbFile` |
|
|
49
49
|
|
|
50
50
|
A subpath that reaches no peer needs nothing installed, not even `koa` (it appears there only as a type you pass in): `koa/createKoaErrorHandler`, a Koa error middleware you configure with `statusOf`, `bodyOf`, `report` and `noBodyStatuses`, and its two type files `koa/IKoaErrorHandlerOptions` and `koa/IKoaErrorHandlerContext`. `koa/tdwKoaErrorHandler` is the same middleware preconfigured for GraphQL errors, Sentry and dotenv, which is why it needs the peers above.
|
|
51
51
|
|
|
52
|
-
`email/createSocketLabsSender` needs
|
|
52
|
+
`email/createSocketLabsSender` needs nothing installed: it builds a function that sends one mail you composed, with your own `serverId` and `apiKey`, and returns `{ ok: true }` or `{ ok: false, code }` instead of throwing on a rejected send. It posts to the SocketLabs Injection API with Node's built-in `fetch` (a timeout, and retries on a timeout or a 429, 500, 502, 503 or 504 answer), reads no environment variable and loads no Sentry, no dotenv and no `graphql`; its four type files (`email/ISocketLabsSenderOptions`, `ISocketLabsMessage`, `ISocketLabsSendResult`, `ISocketLabsClient`) need nothing installed either. `email/SocketLabsLib` sends through it and adds the copy, the HTML template, the environment variables and the Sentry report. `@socketlabs/email` is not a peer of this package any more and nothing here imports it: remove it from your project if this package was the only reason you installed it (it depends on `axios` 0.21, which has published advisories). Node's `fetch` does not read `HTTP_PROXY` / `HTTPS_PROXY` on its own: behind a proxy, start Node with `NODE_USE_ENV_PROXY=1`.
|
|
53
53
|
|
|
54
54
|
The PostgreSQL kit under `lib/PostgreSQL/{error,parse,pool,url,counter,tx,guard,role,clock,lock}/` reaches no peer either, `pg` included: `lib/PostgreSQL/pool/createPool` takes the `pg` module you imported as its `driver` argument and talks to it through structural types, so you install `pg` yourself for your own code and the kit never imports it. It holds the pool factory (URL allow-list, `SHOW timezone` must answer `UTC`, one connect deadline, a listener for idle-client errors), `lib/PostgreSQL/tx/withTx` (one transaction wrapper: closed `BEGIN`, `SET LOCAL lock_timeout`, a bounded retry on deadlocks and serialisation failures, and an error factory you pass in), string parsers for `date`, `time`, `timestamptz`, `int8`, `uuid` and arrays of them that never build a `Date`, closed-reason `DbParseError`, `DbConnectError` and `DbTxError`, SQLSTATE readers, `lib/PostgreSQL/error/mapDbError` (turns any driver failure into an error of your own family through a constraint table you pass in, and logs a closed reason, never the driver text), `lib/PostgreSQL/guard/assertAffected` and `guardVersion` (say why an update matched no row), `lib/PostgreSQL/role/assertRole` (a boot check that the connected database role has no dangerous attribute, owns nothing, has no unlisted membership and holds the grants you list, with a closed-reason `RoleAssertionError`), `lib/PostgreSQL/clock/createDbClock` (the server time read once per transaction, which a write transaction may read only after a lock), `lib/PostgreSQL/lock/createLockOrderTracker` (the order of the locks of a transaction from a spec you give, checked before each statement) with the small parts for writing your own lock helpers (the kit exports no lock clause), and `databaseUrlReason`, a strict check for a database URL. See [docs/code/lib-postgres.md](https://github.com/Axiumine/koa-utils/blob/main/docs/code/lib-postgres.md).
|
|
55
55
|
|
|
@@ -325,7 +325,7 @@ yarn check:static # every static gate: caps, lint, typecheck (src, scripts, spec
|
|
|
325
325
|
yarn clean
|
|
326
326
|
```
|
|
327
327
|
|
|
328
|
-
Source files are `.mts`. Imports use `.mjs` extension explicitly (NodeNext). Path aliases (`@lib/*`, `@throw/*`, `@models/*`, `@context/*`, `@stypes/*`, `@private/*`, `@email/*`, `@dataSources/*`) are rewritten to relative paths in emitted
|
|
328
|
+
Source files are `.mts`. Imports use `.mjs` extension explicitly (NodeNext). Path aliases (`@lib/*`, `@throw/*`, `@models/*`, `@context/*`, `@stypes/*`, `@private/*`, `@email/*`, `@dataSources/*`) are rewritten to relative paths in the emitted `.mjs` / `.d.mts` right after `tsc`, by `scripts/rewrite-path-aliases.mts`, which reads the alias map from the tsconfig `paths`. The build is a plain `tsc` plus that step: it does not patch the compiler or need a transformer plugin.
|
|
329
329
|
|
|
330
330
|
Adding a new public symbol requires both:
|
|
331
331
|
1. Creating `src/<area>/<Name>.mts`
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The part of a SocketLabs client that {@link createSocketLabsSender} calls.
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* The part of a SocketLabs client that {@link createSocketLabsSender} calls. The client the sender builds fits it, so does
|
|
3
|
+
* the `SocketLabsClient` of the SocketLabs Node SDK if you still use it, and so does a test double such as
|
|
4
|
+
* `{ send: async () => ({}) }`. A client resolves when the mail was accepted and rejects when it was not; the sender turns
|
|
5
|
+
* the rejection into `{ ok: false, code }`. It is declared here so `.d.mts` files that name this interface need no package.
|
|
5
6
|
*/
|
|
6
7
|
export interface ISocketLabsClient {
|
|
7
8
|
send(message: unknown): Promise<unknown>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* One mail handed to the function that {@link createSocketLabsSender} returns. A single recipient, no attachments,
|
|
3
|
-
* no copies. `text` and `html` are both optional here, but
|
|
3
|
+
* no copies. `text` and `html` are both optional here, but a message with neither is not sent: the send fails with the code `MessageValidationEmptyMessage`.
|
|
4
4
|
*/
|
|
5
5
|
export interface ISocketLabsMessage {
|
|
6
6
|
/** Sender address. */
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* What the function from {@link createSocketLabsSender} resolves to. A failed send does not reject: it resolves to
|
|
3
|
-
* `{ ok: false, code }`, where `code` is
|
|
4
|
-
* `'Warning'`, ...) or `'UnknownError'` when the rejection carries none. The code is all that is exposed: never
|
|
5
|
-
*
|
|
3
|
+
* `{ ok: false, code }`, where `code` is a SocketLabs result name (`'Timeout'`, `'InvalidAuthentication'`,
|
|
4
|
+
* `'Warning'`, ...) or `'UnknownError'` when the rejection carries none. The code is all that is exposed: never a
|
|
5
|
+
* response message, the per-recipient results or the raw rejection, which can hold recipients and a receipt.
|
|
6
6
|
*/
|
|
7
7
|
export type ISocketLabsSendResult = {
|
|
8
8
|
ok: true;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ISocketLabsClient } from './ISocketLabsClient.mjs';
|
|
2
2
|
/**
|
|
3
3
|
* Options of {@link createSocketLabsSender}. Nothing is read from the environment: you pass the credentials.
|
|
4
|
-
* There is no `endpointUrl` and no proxy option on purpose, so the sender can only talk to the
|
|
4
|
+
* There is no `endpointUrl` and no proxy option on purpose, so the sender can only talk to the SocketLabs Injection API.
|
|
5
5
|
*/
|
|
6
6
|
export interface ISocketLabsSenderOptions {
|
|
7
7
|
/** SocketLabs server id. Not validated here. Ignored when `client` is given. */
|
|
@@ -9,21 +9,22 @@ export interface ISocketLabsSenderOptions {
|
|
|
9
9
|
/** SocketLabs injection API key. Not validated here, never put in an error text. Ignored when `client` is given. */
|
|
10
10
|
apiKey: string;
|
|
11
11
|
/**
|
|
12
|
-
* Timeout of one HTTP request, in seconds
|
|
13
|
-
* sender is created. Unused when `client` is given.
|
|
12
|
+
* Timeout of one HTTP request, in seconds, counted from the start of the request to the last byte of the answer. Default 120.
|
|
13
|
+
* Must be finite and above 0, else `RangeError` when the sender is created. Unused when `client` is given.
|
|
14
14
|
*/
|
|
15
15
|
requestTimeout?: number | undefined;
|
|
16
16
|
/**
|
|
17
|
-
* How many times the
|
|
18
|
-
* the sender is created. Unused when `client` is given. Retries add to the time
|
|
19
|
-
* (up to `requestTimeout` x (1 + `numberOfRetries`) plus
|
|
17
|
+
* How many times the client retries a failed request: a timeout, or a 429, 500, 502, 503 or 504 answer (`Retry-After` is not read). Default 3. Must be an
|
|
18
|
+
* integer from 0 to 5, else `RangeError` when the sender is created. Unused when `client` is given. Retries add to the time
|
|
19
|
+
* one send can take (up to `requestTimeout` x (1 + `numberOfRetries`) plus a back-off of 1 to 10 s before each retry), and a
|
|
20
|
+
* retry after a timeout can deliver the mail twice.
|
|
20
21
|
*/
|
|
21
22
|
numberOfRetries?: number | undefined;
|
|
22
|
-
/** Use this client instead of
|
|
23
|
+
/** Use this client instead of the built-in one. For tests and for a client you configure yourself. */
|
|
23
24
|
client?: ISocketLabsClient | undefined;
|
|
24
25
|
/**
|
|
25
26
|
* Called with the raw rejection of a failed send, before the sender resolves to `{ ok: false, code }`. Default: nothing.
|
|
26
|
-
* The value is whatever the client rejected with (a `
|
|
27
|
+
* The value is whatever the client rejected with (the built-in client rejects with an `Error` that carries a `result`; another client may reject with a `SendResponse`, a `TypeError`, a string, `null`) and can
|
|
27
28
|
* hold recipients and a transaction receipt: do not log or serialise it as is. A throw from here rejects the sender's promise.
|
|
28
29
|
*/
|
|
29
30
|
onError?: ((rejection: unknown) => void) | undefined;
|
|
@@ -42,21 +42,8 @@ export declare class SocketLabsLib {
|
|
|
42
42
|
*/
|
|
43
43
|
sendEmailVerify(emailTo: string, hash: string, name?: string, linkBase?: string, linkPath?: string): Promise<boolean>;
|
|
44
44
|
/**
|
|
45
|
-
* A timed-out send is
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
statusCode: ECONNABORTED
|
|
49
|
-
Error in sending the email
|
|
50
|
-
SendResponse {
|
|
51
|
-
transactionReceipt: null,
|
|
52
|
-
addressResults: null,
|
|
53
|
-
result: {
|
|
54
|
-
name: 'Timeout',
|
|
55
|
-
value: 1,
|
|
56
|
-
message: 'A timeout occurred sending the message'
|
|
57
|
-
},
|
|
58
|
-
responseMessage: 'A timeout occurred sending the message'
|
|
59
|
-
}
|
|
45
|
+
* A timed-out send is retried by the client (`numberOfRetries: 3`, with a back-off of 1 to 10 s between tries). When the
|
|
46
|
+
* last try times out as well, the send is reported as failed and the template methods return `false`. This class adds no retry of its own.
|
|
60
47
|
*/
|
|
61
48
|
sendEmailChangeVerify(emailTo: string, hash: string, name?: string): Promise<boolean>;
|
|
62
49
|
sendWelcome(emailTo: string): Promise<boolean>;
|
|
@@ -5,9 +5,9 @@ import { confirmationLink, httpLinkBase } from "../private/email/messageParts.mj
|
|
|
5
5
|
import * as notice from "../private/email/noticeMessages.mjs";
|
|
6
6
|
import { orFalse } from "../private/email/orFalse.mjs";
|
|
7
7
|
import * as reset from "../private/email/resetMessages.mjs";
|
|
8
|
+
import { createSocketLabsClient } from "../private/email/socketLabsClient.mjs";
|
|
8
9
|
import { loadEnv } from "../private/lib/loadEnv.mjs";
|
|
9
10
|
import * as Sentry from "../private/lib/sentry.mjs";
|
|
10
|
-
import { SocketLabsClient } from '@socketlabs/email';
|
|
11
11
|
import { createSocketLabsSender } from './createSocketLabsSender.mjs';
|
|
12
12
|
loadEnv();
|
|
13
13
|
export class SocketLabsLib {
|
|
@@ -24,9 +24,7 @@ export class SocketLabsLib {
|
|
|
24
24
|
/* c8 ignore next -- env fallback '0' covered only when SOCKETLABS_SERVER_ID is unset */
|
|
25
25
|
const serverId = parseInt(process.env['SOCKETLABS_SERVER_ID'] || '0');
|
|
26
26
|
const apiKey = `${process.env['SOCKETLABS_SERVER_APIKEY']}`;
|
|
27
|
-
|
|
28
|
-
const Client = SocketLabsClient;
|
|
29
|
-
this.client = new Client(serverId, apiKey, { requestTimeout: 120, numberOfRetries: 3 });
|
|
27
|
+
this.client = createSocketLabsClient({ serverId, apiKey, requestTimeout: 120, numberOfRetries: 3 });
|
|
30
28
|
this.credentials = { serverId, apiKey };
|
|
31
29
|
this.platformName = `${process.env['PLATFORM_NAME']}`;
|
|
32
30
|
this.linkBase = `${process.env['APP_DOMAIN']}`;
|
|
@@ -105,21 +103,8 @@ export class SocketLabsLib {
|
|
|
105
103
|
}
|
|
106
104
|
*/
|
|
107
105
|
/**
|
|
108
|
-
* A timed-out send is
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
statusCode: ECONNABORTED
|
|
112
|
-
Error in sending the email
|
|
113
|
-
SendResponse {
|
|
114
|
-
transactionReceipt: null,
|
|
115
|
-
addressResults: null,
|
|
116
|
-
result: {
|
|
117
|
-
name: 'Timeout',
|
|
118
|
-
value: 1,
|
|
119
|
-
message: 'A timeout occurred sending the message'
|
|
120
|
-
},
|
|
121
|
-
responseMessage: 'A timeout occurred sending the message'
|
|
122
|
-
}
|
|
106
|
+
* A timed-out send is retried by the client (`numberOfRetries: 3`, with a back-off of 1 to 10 s between tries). When the
|
|
107
|
+
* last try times out as well, the send is reported as failed and the template methods return `false`. This class adds no retry of its own.
|
|
123
108
|
*/
|
|
124
109
|
async sendEmailChangeVerify(emailTo, hash, name = '') {
|
|
125
110
|
const link = `${httpLinkBase(this.linkBase)}/check/verify-change-email/${encodeURI(emailTo)}/${hash}`;
|
|
@@ -4,16 +4,17 @@ import type { ISocketLabsSendResult } from './ISocketLabsSendResult.mjs';
|
|
|
4
4
|
/**
|
|
5
5
|
* Builds a function that sends one mail through SocketLabs and reports the outcome as a value.
|
|
6
6
|
*
|
|
7
|
-
* The returned function builds
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* `
|
|
7
|
+
* The returned function builds the message (`buildBasicMessage`: the fields of the SocketLabs SDK's `BasicMessage`) and passes
|
|
8
|
+
* it to the client. On success it resolves to `{ ok: true }`. When the client rejects it calls `onError` with the raw
|
|
9
|
+
* rejection and resolves to `{ ok: false, code }`, where `code` is `rejection.result.name` if that is a string and
|
|
10
|
+
* `'UnknownError'` otherwise.
|
|
11
11
|
*
|
|
12
|
-
* There is no `try`/`catch`: a throw from a
|
|
13
|
-
* returned promise, and when
|
|
12
|
+
* There is no `try`/`catch`: a throw from the message builder (a field that is not a string), from `client.send` itself,
|
|
13
|
+
* and from `onError`, reject the returned promise, and when the builder throws `client.send` is never called.
|
|
14
14
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
15
|
+
* The built-in client posts with `fetch` to the SocketLabs Injection API and nothing else; it needs no package. The sender reads no
|
|
16
|
+
* environment variable and checks nothing about `serverId` and `apiKey` when it is created: a bad pair is rejected at
|
|
17
|
+
* send time and comes back as a code. Importing it loads no peer: no Sentry, no dotenv.
|
|
17
18
|
*
|
|
18
19
|
* @throws RangeError `requestTimeout` is not a finite number above 0, or `numberOfRetries` is not an integer from 0 to 5. The text never holds the API key.
|
|
19
20
|
*/
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createSocketLabsClient } from "../private/email/socketLabsClient.mjs";
|
|
2
|
+
import { buildBasicMessage } from "../private/email/socketLabsMessage.mjs";
|
|
2
3
|
/** Seconds, what `SocketLabsLib` has always passed. */
|
|
3
4
|
const DEFAULT_REQUEST_TIMEOUT = 120;
|
|
4
5
|
/** What `SocketLabsLib` has always passed. */
|
|
5
6
|
const DEFAULT_NUMBER_OF_RETRIES = 3;
|
|
6
7
|
/** Upper bound of `numberOfRetries`: every retry can run a full timeout, so a larger value outlives any sane job lease. */
|
|
7
8
|
const MAX_NUMBER_OF_RETRIES = 5;
|
|
8
|
-
/** The
|
|
9
|
+
/** The name a failure gets when nothing classifies it: the name the SocketLabs SDK's result enum gave it. */
|
|
9
10
|
const UNKNOWN_ERROR = 'UnknownError';
|
|
10
|
-
// The import is `any` (src/types/socketlabs-email.d.ts): one assertion each gives the two classes the shapes above
|
|
11
|
-
const Message = BasicMessage;
|
|
12
|
-
const Client = SocketLabsClient;
|
|
13
11
|
// Messages name the constraint, never the value: the options object also holds the API key
|
|
14
12
|
function assertRequestTimeout(requestTimeout) {
|
|
15
13
|
if (!Number.isFinite(requestTimeout) || requestTimeout <= 0) {
|
|
@@ -21,7 +19,7 @@ function assertNumberOfRetries(numberOfRetries) {
|
|
|
21
19
|
throw new RangeError(`numberOfRetries must be an integer from 0 to ${MAX_NUMBER_OF_RETRIES}`);
|
|
22
20
|
}
|
|
23
21
|
}
|
|
24
|
-
/** `rejection.result.name` when it is a string, else `'UnknownError'`. The
|
|
22
|
+
/** `rejection.result.name` when it is a string, else `'UnknownError'`. The built-in client rejects with an error whose `result` holds the name. */
|
|
25
23
|
const codeOf = (rejection) => {
|
|
26
24
|
const name = rejection?.result?.name;
|
|
27
25
|
return typeof name === 'string' ? name : UNKNOWN_ERROR;
|
|
@@ -29,16 +27,17 @@ const codeOf = (rejection) => {
|
|
|
29
27
|
/**
|
|
30
28
|
* Builds a function that sends one mail through SocketLabs and reports the outcome as a value.
|
|
31
29
|
*
|
|
32
|
-
* The returned function builds
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* `
|
|
30
|
+
* The returned function builds the message (`buildBasicMessage`: the fields of the SocketLabs SDK's `BasicMessage`) and passes
|
|
31
|
+
* it to the client. On success it resolves to `{ ok: true }`. When the client rejects it calls `onError` with the raw
|
|
32
|
+
* rejection and resolves to `{ ok: false, code }`, where `code` is `rejection.result.name` if that is a string and
|
|
33
|
+
* `'UnknownError'` otherwise.
|
|
36
34
|
*
|
|
37
|
-
* There is no `try`/`catch`: a throw from a
|
|
38
|
-
* returned promise, and when
|
|
35
|
+
* There is no `try`/`catch`: a throw from the message builder (a field that is not a string), from `client.send` itself,
|
|
36
|
+
* and from `onError`, reject the returned promise, and when the builder throws `client.send` is never called.
|
|
39
37
|
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
38
|
+
* The built-in client posts with `fetch` to the SocketLabs Injection API and nothing else; it needs no package. The sender reads no
|
|
39
|
+
* environment variable and checks nothing about `serverId` and `apiKey` when it is created: a bad pair is rejected at
|
|
40
|
+
* send time and comes back as a code. Importing it loads no peer: no Sentry, no dotenv.
|
|
42
41
|
*
|
|
43
42
|
* @throws RangeError `requestTimeout` is not a finite number above 0, or `numberOfRetries` is not an integer from 0 to 5. The text never holds the API key.
|
|
44
43
|
*/
|
|
@@ -47,16 +46,11 @@ export function createSocketLabsSender(options) {
|
|
|
47
46
|
const numberOfRetries = options.numberOfRetries ?? DEFAULT_NUMBER_OF_RETRIES;
|
|
48
47
|
assertRequestTimeout(requestTimeout);
|
|
49
48
|
assertNumberOfRetries(numberOfRetries);
|
|
50
|
-
const client = options.client ??
|
|
49
|
+
const client = options.client ??
|
|
50
|
+
createSocketLabsClient({ serverId: options.serverId, apiKey: options.apiKey, requestTimeout, numberOfRetries });
|
|
51
51
|
const { onError } = options;
|
|
52
52
|
return async function sendSocketLabsMessage(message) {
|
|
53
|
-
const basicMessage =
|
|
54
|
-
basicMessage.setFromAddress(message.from, message.fromName);
|
|
55
|
-
basicMessage.setSubject(message.subject);
|
|
56
|
-
basicMessage.setTextBody(message.text);
|
|
57
|
-
basicMessage.setHtmlBody(message.html);
|
|
58
|
-
basicMessage.setTo(message.to);
|
|
59
|
-
basicMessage.setMessageId(message.messageId);
|
|
53
|
+
const basicMessage = buildBasicMessage(message);
|
|
60
54
|
return client.send(basicMessage).then(() => ({ ok: true }), (rejection) => {
|
|
61
55
|
onError?.(rejection);
|
|
62
56
|
return { ok: false, code: codeOf(rejection) };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What `sanitiseGlb` accepts. Every field has a safe default in {@link GLB_POLICY_DEFAULTS}; the caller passes only the
|
|
3
|
+
* fields it wants to change. Every limit is a positive integer: a `0`, a negative number, a float or a `NaN` is a
|
|
4
|
+
* programming error and throws.
|
|
5
|
+
*/
|
|
6
|
+
export interface IGlbPolicy {
|
|
7
|
+
/** Bytes of the whole GLB file. */
|
|
8
|
+
maxBytes: number;
|
|
9
|
+
/** Bytes of the JSON chunk. */
|
|
10
|
+
maxJsonBytes: number;
|
|
11
|
+
/** Bytes of all buffers as declared in the JSON, plus the decoded size of every `EXT_meshopt_compression` view. */
|
|
12
|
+
maxBufferBytes: number;
|
|
13
|
+
/** Triangles, counted once for every node that instances the mesh. */
|
|
14
|
+
maxTriangles: number;
|
|
15
|
+
/** Vertices, counted once for every node that instances the mesh. */
|
|
16
|
+
maxVertices: number;
|
|
17
|
+
/** Number of accessors. */
|
|
18
|
+
maxAccessors: number;
|
|
19
|
+
/** `count` of the biggest single accessor, sparse or not. */
|
|
20
|
+
maxAccessorElements: number;
|
|
21
|
+
/** Sum of the `sparse.count` of every accessor. */
|
|
22
|
+
maxSparseElements: number;
|
|
23
|
+
/** Number of meshes. */
|
|
24
|
+
maxMeshes: number;
|
|
25
|
+
/** Number of nodes. */
|
|
26
|
+
maxNodes: number;
|
|
27
|
+
/** Number of materials. */
|
|
28
|
+
maxMaterials: number;
|
|
29
|
+
/** Number of textures, and of images. */
|
|
30
|
+
maxTextures: number;
|
|
31
|
+
/** Number of animations. */
|
|
32
|
+
maxAnimations: number;
|
|
33
|
+
/** Width or height of one image in pixels, read from its header. */
|
|
34
|
+
maxTextureSide: number;
|
|
35
|
+
/** Sum of width times height over every image, read from the headers. */
|
|
36
|
+
maxTexturePixels: number;
|
|
37
|
+
/** JPEG and WebP quality (1 to 100) used when the textures are re-encoded. PNG is always lossless. */
|
|
38
|
+
textureQuality: number;
|
|
39
|
+
/** Extension names the file may declare. Every name must be one the sanitiser can rewrite. */
|
|
40
|
+
allowedExtensions: readonly string[];
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The safe defaults of {@link IGlbPolicy}. A caller that wants one more extension spreads the list:
|
|
44
|
+
* `{ allowedExtensions: [...GLB_POLICY_DEFAULTS.allowedExtensions, 'KHR_lights_punctual'] }`.
|
|
45
|
+
*
|
|
46
|
+
* `KHR_draco_mesh_compression` is not in the list: the sanitiser has no Draco decoder, so it could not check the data.
|
|
47
|
+
* `KHR_interactivity` is refused whatever the list says.
|
|
48
|
+
*/
|
|
49
|
+
export declare const GLB_POLICY_DEFAULTS: Readonly<IGlbPolicy>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const MIB = 1024 * 1024;
|
|
2
|
+
/**
|
|
3
|
+
* The safe defaults of {@link IGlbPolicy}. A caller that wants one more extension spreads the list:
|
|
4
|
+
* `{ allowedExtensions: [...GLB_POLICY_DEFAULTS.allowedExtensions, 'KHR_lights_punctual'] }`.
|
|
5
|
+
*
|
|
6
|
+
* `KHR_draco_mesh_compression` is not in the list: the sanitiser has no Draco decoder, so it could not check the data.
|
|
7
|
+
* `KHR_interactivity` is refused whatever the list says.
|
|
8
|
+
*/
|
|
9
|
+
export const GLB_POLICY_DEFAULTS = {
|
|
10
|
+
maxBytes: 32 * MIB,
|
|
11
|
+
maxJsonBytes: 4 * MIB,
|
|
12
|
+
maxBufferBytes: 128 * MIB,
|
|
13
|
+
maxTriangles: 500_000,
|
|
14
|
+
maxVertices: 1_000_000,
|
|
15
|
+
maxAccessors: 5000,
|
|
16
|
+
maxAccessorElements: 2_000_000,
|
|
17
|
+
maxSparseElements: 100_000,
|
|
18
|
+
maxMeshes: 1000,
|
|
19
|
+
maxNodes: 10_000,
|
|
20
|
+
maxMaterials: 500,
|
|
21
|
+
maxTextures: 100,
|
|
22
|
+
maxAnimations: 100,
|
|
23
|
+
maxTextureSide: 2048,
|
|
24
|
+
maxTexturePixels: 64 * MIB,
|
|
25
|
+
textureQuality: 90,
|
|
26
|
+
allowedExtensions: [
|
|
27
|
+
'KHR_materials_anisotropy',
|
|
28
|
+
'KHR_materials_clearcoat',
|
|
29
|
+
'KHR_materials_dispersion',
|
|
30
|
+
'KHR_materials_emissive_strength',
|
|
31
|
+
'KHR_materials_ior',
|
|
32
|
+
'KHR_materials_iridescence',
|
|
33
|
+
'KHR_materials_sheen',
|
|
34
|
+
'KHR_materials_specular',
|
|
35
|
+
'KHR_materials_transmission',
|
|
36
|
+
'KHR_materials_unlit',
|
|
37
|
+
'KHR_materials_volume',
|
|
38
|
+
'KHR_texture_transform',
|
|
39
|
+
'KHR_mesh_quantization',
|
|
40
|
+
'EXT_meshopt_compression',
|
|
41
|
+
'KHR_texture_basisu',
|
|
42
|
+
'EXT_texture_webp'
|
|
43
|
+
]
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=GLB_POLICY_DEFAULTS.mjs.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The closed reasons a GLB upload is rejected for (see `IGlbReason` in `IGlbSanitiseResult`):
|
|
3
|
+
*
|
|
4
|
+
* - `GLB_TOO_LARGE`: the file is bigger than `maxBytes`.
|
|
5
|
+
* - `GLB_TRUNCATED`: the file is shorter than the 12 byte header plus one chunk header.
|
|
6
|
+
* - `GLB_BAD_MAGIC`: the first four bytes are not `glTF`.
|
|
7
|
+
* - `GLB_BAD_VERSION`: the container version is not 2.
|
|
8
|
+
* - `GLB_LENGTH_MISMATCH`: the length in the header differs from the real size of the file.
|
|
9
|
+
* - `GLB_BAD_CHUNKS`: the chunks are not exactly one JSON chunk followed by at most one BIN chunk, or one of them overruns the file.
|
|
10
|
+
* - `GLB_JSON_TOO_LARGE`: the JSON chunk is bigger than `maxJsonBytes`.
|
|
11
|
+
* - `JSON_INVALID`: the JSON chunk is not UTF-8 text holding one JSON object.
|
|
12
|
+
* - `URI_EXTERNAL`: a buffer or image points at a file or a URL. Only the embedded GLB buffer is allowed.
|
|
13
|
+
* - `URI_DATA`: a buffer or image carries a `data:` URI. Only the embedded GLB buffer is allowed.
|
|
14
|
+
* - `EXTENSION_FORBIDDEN`: the file uses an extension that is always refused (`KHR_interactivity`).
|
|
15
|
+
* - `EXTENSION_NOT_ALLOWED`: the file uses an extension that is not in `allowedExtensions`.
|
|
16
|
+
* - `LIMIT_EXCEEDED`: a count or a size is over the limit named in `limit` (see `IGlbPolicy`).
|
|
17
|
+
* - `IMAGE_UNREADABLE`: an image has no bytes inside the BIN chunk, or its header cannot be read.
|
|
18
|
+
* - `IMAGE_UNSUPPORTED`: the bytes of an image are not PNG, JPEG, WebP or KTX2.
|
|
19
|
+
* - `IMAGE_FORMAT_MISMATCH`: the `mimeType` of an image names another format than its bytes.
|
|
20
|
+
* - `IMAGE_DECODE_FAILED`: the image passed the header check but could not be decoded and re-encoded.
|
|
21
|
+
* - `VALIDATOR_ERROR`: the Khronos glTF Validator reported an error.
|
|
22
|
+
* - `VALIDATOR_FAILED`: the Khronos glTF Validator crashed on the file.
|
|
23
|
+
* - `MESHOPT_DECODE_FAILED`: the `EXT_meshopt_compression` data does not decode.
|
|
24
|
+
* - `READ_FAILED`: the glTF Transform reader could not read the file.
|
|
25
|
+
* - `OUTPUT_INVALID`: the rewritten file failed its own check (validator or decode). Never expected: the input is rejected instead.
|
|
26
|
+
*/
|
|
27
|
+
export declare const GLB_REJECT_CODES: readonly ["GLB_TOO_LARGE", "GLB_TRUNCATED", "GLB_BAD_MAGIC", "GLB_BAD_VERSION", "GLB_LENGTH_MISMATCH", "GLB_BAD_CHUNKS", "GLB_JSON_TOO_LARGE", "JSON_INVALID", "URI_EXTERNAL", "URI_DATA", "EXTENSION_FORBIDDEN", "EXTENSION_NOT_ALLOWED", "LIMIT_EXCEEDED", "IMAGE_UNREADABLE", "IMAGE_UNSUPPORTED", "IMAGE_FORMAT_MISMATCH", "IMAGE_DECODE_FAILED", "VALIDATOR_ERROR", "VALIDATOR_FAILED", "MESHOPT_DECODE_FAILED", "READ_FAILED", "OUTPUT_INVALID"];
|
|
28
|
+
/** One of {@link GLB_REJECT_CODES}. */
|
|
29
|
+
export type IGlbRejectCode = (typeof GLB_REJECT_CODES)[number];
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The closed reasons a GLB upload is rejected for (see `IGlbReason` in `IGlbSanitiseResult`):
|
|
3
|
+
*
|
|
4
|
+
* - `GLB_TOO_LARGE`: the file is bigger than `maxBytes`.
|
|
5
|
+
* - `GLB_TRUNCATED`: the file is shorter than the 12 byte header plus one chunk header.
|
|
6
|
+
* - `GLB_BAD_MAGIC`: the first four bytes are not `glTF`.
|
|
7
|
+
* - `GLB_BAD_VERSION`: the container version is not 2.
|
|
8
|
+
* - `GLB_LENGTH_MISMATCH`: the length in the header differs from the real size of the file.
|
|
9
|
+
* - `GLB_BAD_CHUNKS`: the chunks are not exactly one JSON chunk followed by at most one BIN chunk, or one of them overruns the file.
|
|
10
|
+
* - `GLB_JSON_TOO_LARGE`: the JSON chunk is bigger than `maxJsonBytes`.
|
|
11
|
+
* - `JSON_INVALID`: the JSON chunk is not UTF-8 text holding one JSON object.
|
|
12
|
+
* - `URI_EXTERNAL`: a buffer or image points at a file or a URL. Only the embedded GLB buffer is allowed.
|
|
13
|
+
* - `URI_DATA`: a buffer or image carries a `data:` URI. Only the embedded GLB buffer is allowed.
|
|
14
|
+
* - `EXTENSION_FORBIDDEN`: the file uses an extension that is always refused (`KHR_interactivity`).
|
|
15
|
+
* - `EXTENSION_NOT_ALLOWED`: the file uses an extension that is not in `allowedExtensions`.
|
|
16
|
+
* - `LIMIT_EXCEEDED`: a count or a size is over the limit named in `limit` (see `IGlbPolicy`).
|
|
17
|
+
* - `IMAGE_UNREADABLE`: an image has no bytes inside the BIN chunk, or its header cannot be read.
|
|
18
|
+
* - `IMAGE_UNSUPPORTED`: the bytes of an image are not PNG, JPEG, WebP or KTX2.
|
|
19
|
+
* - `IMAGE_FORMAT_MISMATCH`: the `mimeType` of an image names another format than its bytes.
|
|
20
|
+
* - `IMAGE_DECODE_FAILED`: the image passed the header check but could not be decoded and re-encoded.
|
|
21
|
+
* - `VALIDATOR_ERROR`: the Khronos glTF Validator reported an error.
|
|
22
|
+
* - `VALIDATOR_FAILED`: the Khronos glTF Validator crashed on the file.
|
|
23
|
+
* - `MESHOPT_DECODE_FAILED`: the `EXT_meshopt_compression` data does not decode.
|
|
24
|
+
* - `READ_FAILED`: the glTF Transform reader could not read the file.
|
|
25
|
+
* - `OUTPUT_INVALID`: the rewritten file failed its own check (validator or decode). Never expected: the input is rejected instead.
|
|
26
|
+
*/
|
|
27
|
+
export const GLB_REJECT_CODES = [
|
|
28
|
+
'GLB_TOO_LARGE',
|
|
29
|
+
'GLB_TRUNCATED',
|
|
30
|
+
'GLB_BAD_MAGIC',
|
|
31
|
+
'GLB_BAD_VERSION',
|
|
32
|
+
'GLB_LENGTH_MISMATCH',
|
|
33
|
+
'GLB_BAD_CHUNKS',
|
|
34
|
+
'GLB_JSON_TOO_LARGE',
|
|
35
|
+
'JSON_INVALID',
|
|
36
|
+
'URI_EXTERNAL',
|
|
37
|
+
'URI_DATA',
|
|
38
|
+
'EXTENSION_FORBIDDEN',
|
|
39
|
+
'EXTENSION_NOT_ALLOWED',
|
|
40
|
+
'LIMIT_EXCEEDED',
|
|
41
|
+
'IMAGE_UNREADABLE',
|
|
42
|
+
'IMAGE_UNSUPPORTED',
|
|
43
|
+
'IMAGE_FORMAT_MISMATCH',
|
|
44
|
+
'IMAGE_DECODE_FAILED',
|
|
45
|
+
'VALIDATOR_ERROR',
|
|
46
|
+
'VALIDATOR_FAILED',
|
|
47
|
+
'MESHOPT_DECODE_FAILED',
|
|
48
|
+
'READ_FAILED',
|
|
49
|
+
'OUTPUT_INVALID'
|
|
50
|
+
];
|
|
51
|
+
//# sourceMappingURL=GLB_REJECT_CODES.mjs.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { IGlbReason } from './IGlbSanitiseResult.mjs';
|
|
2
|
+
/** Result of `checkGlbContainer`. The byte arrays are views into the input, not copies. */
|
|
3
|
+
export type IGlbContainerResult = {
|
|
4
|
+
ok: true;
|
|
5
|
+
/** The JSON chunk. */
|
|
6
|
+
json: Uint8Array;
|
|
7
|
+
/** The BIN chunk, `null` when the file has none. */
|
|
8
|
+
bin: Uint8Array | null;
|
|
9
|
+
} | {
|
|
10
|
+
ok: false;
|
|
11
|
+
reason: IGlbReason;
|
|
12
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { IGlbPolicy } from './GLB_POLICY_DEFAULTS.mjs';
|
|
2
|
+
import type { IGlbRejectCode } from './GLB_REJECT_CODES.mjs';
|
|
3
|
+
/** A name in {@link IGlbPolicy} that holds a limit (every field but the quality and the extension list). */
|
|
4
|
+
export type IGlbLimitName = Exclude<keyof IGlbPolicy, 'allowedExtensions' | 'textureQuality'>;
|
|
5
|
+
/** One reason a file was rejected. */
|
|
6
|
+
export interface IGlbReason {
|
|
7
|
+
/** Machine code, one of `GLB_REJECT_CODES`. */
|
|
8
|
+
code: IGlbRejectCode;
|
|
9
|
+
/** English text for a log. The wording can change in a patch release, so do not match on it. */
|
|
10
|
+
message: string;
|
|
11
|
+
/** JSON pointer into the glTF JSON when the reason points at one object, for example `/images/0`. */
|
|
12
|
+
pointer?: string;
|
|
13
|
+
/** Set for `LIMIT_EXCEEDED`: the name of the limit that was hit. */
|
|
14
|
+
limit?: IGlbLimitName;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* What was measured. A number is `0` for a stage the file never reached, so a file rejected in the container check has
|
|
18
|
+
* only `inputBytes` set.
|
|
19
|
+
*/
|
|
20
|
+
export interface IGlbStats {
|
|
21
|
+
/** Size of the uploaded file. */
|
|
22
|
+
inputBytes: number;
|
|
23
|
+
/** Size of the sanitised file, `0` when the file was rejected. */
|
|
24
|
+
outputBytes: number;
|
|
25
|
+
nodes: number;
|
|
26
|
+
meshes: number;
|
|
27
|
+
materials: number;
|
|
28
|
+
textures: number;
|
|
29
|
+
animations: number;
|
|
30
|
+
accessors: number;
|
|
31
|
+
/** Triangles, counted once for every node that instances the mesh. */
|
|
32
|
+
triangles: number;
|
|
33
|
+
/** Vertices, counted once for every node that instances the mesh. */
|
|
34
|
+
vertices: number;
|
|
35
|
+
/** Declared buffer bytes plus the decoded size of the `EXT_meshopt_compression` views. */
|
|
36
|
+
bufferBytes: number;
|
|
37
|
+
/** Longest side in pixels over all images, read from the headers. */
|
|
38
|
+
maxTextureSide: number;
|
|
39
|
+
/** Textures that were decoded and re-encoded by `sharp`. */
|
|
40
|
+
texturesReencoded: number;
|
|
41
|
+
}
|
|
42
|
+
/** The file passed every check and `glb` is the freshly written file. `reasons` is empty. */
|
|
43
|
+
export interface IGlbAccepted {
|
|
44
|
+
accepted: true;
|
|
45
|
+
glb: Uint8Array;
|
|
46
|
+
reasons: [];
|
|
47
|
+
stats: IGlbStats;
|
|
48
|
+
}
|
|
49
|
+
/** The file failed at least one check. `reasons` is never empty. */
|
|
50
|
+
export interface IGlbRejected {
|
|
51
|
+
accepted: false;
|
|
52
|
+
reasons: IGlbReason[];
|
|
53
|
+
stats: IGlbStats;
|
|
54
|
+
}
|
|
55
|
+
/** Result of `sanitiseGlb`. A hostile file gives `accepted: false`, never a thrown error. */
|
|
56
|
+
export type IGlbSanitiseResult = IGlbAccepted | IGlbRejected;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type IGlbPolicy } from './GLB_POLICY_DEFAULTS.mjs';
|
|
2
|
+
import type { IGlbContainerResult } from './IGlbContainer.mjs';
|
|
3
|
+
/**
|
|
4
|
+
* Check the container of a GLB without parsing its JSON: magic `glTF`, version 2, the length in the header against the
|
|
5
|
+
* real size, and the chunk layout (one JSON chunk, then at most one BIN chunk, nothing else). Cheap, so a caller can use
|
|
6
|
+
* it to turn a file away before any heavy work. Never throws on a hostile file.
|
|
7
|
+
*
|
|
8
|
+
* @param bytes the whole file
|
|
9
|
+
* @param limits `maxBytes` and `maxJsonBytes` of {@link IGlbPolicy}; the defaults apply to a field that is left out
|
|
10
|
+
*/
|
|
11
|
+
export declare function checkGlbContainer(bytes: Uint8Array, limits?: Partial<Pick<IGlbPolicy, 'maxBytes' | 'maxJsonBytes'>>): IGlbContainerResult;
|