@benclmnt/postmock 0.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/LICENSE +21 -0
- package/README.md +251 -0
- package/dist/seeds/conformance/00-core.d.ts +4 -0
- package/dist/seeds/conformance/00-core.js +12 -0
- package/dist/seeds/conformance/20-bounces.d.ts +3 -0
- package/dist/seeds/conformance/20-bounces.js +108 -0
- package/dist/seeds/conformance/40-messages.d.ts +3 -0
- package/dist/seeds/conformance/40-messages.js +144 -0
- package/dist/seeds/conformance/50-server-color.d.ts +8 -0
- package/dist/seeds/conformance/50-server-color.js +13 -0
- package/dist/seeds/conformance/70-account.d.ts +9 -0
- package/dist/seeds/conformance/70-account.js +29 -0
- package/dist/seeds/conformance/80-templates.d.ts +4 -0
- package/dist/seeds/conformance/80-templates.js +23 -0
- package/dist/seeds/conformance.d.ts +2 -0
- package/dist/seeds/conformance.js +3 -0
- package/dist/seeds/empty.d.ts +4 -0
- package/dist/seeds/empty.js +3 -0
- package/dist/seeds/lib/conformance.d.ts +16 -0
- package/dist/seeds/lib/conformance.js +18 -0
- package/dist/seeds/lib/history.d.ts +27 -0
- package/dist/seeds/lib/history.js +129 -0
- package/dist/seeds/lib/read-server.d.ts +10 -0
- package/dist/seeds/lib/read-server.js +10 -0
- package/dist/seeds/lib/template-server.d.ts +13 -0
- package/dist/seeds/lib/template-server.js +13 -0
- package/dist/src/api/account/authentication.d.ts +39 -0
- package/dist/src/api/account/authentication.js +97 -0
- package/dist/src/api/account/domains.d.ts +59 -0
- package/dist/src/api/account/domains.js +78 -0
- package/dist/src/api/account/paging.d.ts +12 -0
- package/dist/src/api/account/paging.js +35 -0
- package/dist/src/api/account/push.d.ts +14 -0
- package/dist/src/api/account/push.js +84 -0
- package/dist/src/api/account/routes.d.ts +1 -0
- package/dist/src/api/account/routes.js +288 -0
- package/dist/src/api/account/senders.d.ts +54 -0
- package/dist/src/api/account/senders.js +87 -0
- package/dist/src/api/account/servers.d.ts +40 -0
- package/dist/src/api/account/servers.js +148 -0
- package/dist/src/api/bounces/json.d.ts +25 -0
- package/dist/src/api/bounces/json.js +27 -0
- package/dist/src/api/bounces/routes.d.ts +1 -0
- package/dist/src/api/bounces/routes.js +127 -0
- package/dist/src/api/bulk/bulk.d.ts +43 -0
- package/dist/src/api/bulk/bulk.js +81 -0
- package/dist/src/api/bulk/routes.d.ts +1 -0
- package/dist/src/api/bulk/routes.js +252 -0
- package/dist/src/api/data-removals/routes.d.ts +1 -0
- package/dist/src/api/data-removals/routes.js +59 -0
- package/dist/src/api/email/json.d.ts +11 -0
- package/dist/src/api/email/json.js +33 -0
- package/dist/src/api/email/routes.d.ts +1 -0
- package/dist/src/api/email/routes.js +64 -0
- package/dist/src/api/inbound/routes.d.ts +1 -0
- package/dist/src/api/inbound/routes.js +40 -0
- package/dist/src/api/index.d.ts +1 -0
- package/dist/src/api/index.js +3 -0
- package/dist/src/api/message-streams/routes.d.ts +1 -0
- package/dist/src/api/message-streams/routes.js +211 -0
- package/dist/src/api/message-streams/streams.d.ts +28 -0
- package/dist/src/api/message-streams/streams.js +50 -0
- package/dist/src/api/messages/json.d.ts +149 -0
- package/dist/src/api/messages/json.js +114 -0
- package/dist/src/api/messages/query.d.ts +19 -0
- package/dist/src/api/messages/query.js +64 -0
- package/dist/src/api/messages/routes.d.ts +1 -0
- package/dist/src/api/messages/routes.js +203 -0
- package/dist/src/api/server/json.d.ts +26 -0
- package/dist/src/api/server/json.js +25 -0
- package/dist/src/api/server/routes.d.ts +1 -0
- package/dist/src/api/server/routes.js +17 -0
- package/dist/src/api/stats/aggregate.d.ts +58 -0
- package/dist/src/api/stats/aggregate.js +66 -0
- package/dist/src/api/stats/routes.d.ts +1 -0
- package/dist/src/api/stats/routes.js +72 -0
- package/dist/src/api/suppressions/routes.d.ts +1 -0
- package/dist/src/api/suppressions/routes.js +98 -0
- package/dist/src/api/templates/content.d.ts +21 -0
- package/dist/src/api/templates/content.js +39 -0
- package/dist/src/api/templates/routes.d.ts +1 -0
- package/dist/src/api/templates/routes.js +164 -0
- package/dist/src/api/templates/send.d.ts +13 -0
- package/dist/src/api/templates/send.js +105 -0
- package/dist/src/api/templates/templates.d.ts +100 -0
- package/dist/src/api/templates/templates.js +218 -0
- package/dist/src/api/templates/validate.d.ts +15 -0
- package/dist/src/api/templates/validate.js +77 -0
- package/dist/src/api/triggers/routes.d.ts +1 -0
- package/dist/src/api/triggers/routes.js +62 -0
- package/dist/src/api/webhooks/routes.d.ts +14 -0
- package/dist/src/api/webhooks/routes.js +192 -0
- package/dist/src/config.d.ts +17 -0
- package/dist/src/config.js +95 -0
- package/dist/src/control/app.d.ts +5 -0
- package/dist/src/control/app.js +42 -0
- package/dist/src/control/endpoints/account.d.ts +1 -0
- package/dist/src/control/endpoints/account.js +68 -0
- package/dist/src/control/endpoints/bulk.d.ts +1 -0
- package/dist/src/control/endpoints/bulk.js +29 -0
- package/dist/src/control/endpoints/core.d.ts +1 -0
- package/dist/src/control/endpoints/core.js +104 -0
- package/dist/src/control/endpoints/inbound.d.ts +1 -0
- package/dist/src/control/endpoints/inbound.js +61 -0
- package/dist/src/control/endpoints/recipients.d.ts +1 -0
- package/dist/src/control/endpoints/recipients.js +136 -0
- package/dist/src/control/endpoints/smtp.d.ts +1 -0
- package/dist/src/control/endpoints/smtp.js +74 -0
- package/dist/src/control/endpoints/tracking.d.ts +1 -0
- package/dist/src/control/endpoints/tracking.js +95 -0
- package/dist/src/control/endpoints/webhooks.d.ts +1 -0
- package/dist/src/control/endpoints/webhooks.js +36 -0
- package/dist/src/control/index.d.ts +1 -0
- package/dist/src/control/index.js +3 -0
- package/dist/src/control/registry.d.ts +25 -0
- package/dist/src/control/registry.js +19 -0
- package/dist/src/control/seed.d.ts +11 -0
- package/dist/src/control/seed.js +32 -0
- package/dist/src/control/seeding.d.ts +10 -0
- package/dist/src/control/seeding.js +27 -0
- package/dist/src/discover.d.ts +16 -0
- package/dist/src/discover.js +49 -0
- package/dist/src/errors.d.ts +49 -0
- package/dist/src/errors.js +701 -0
- package/dist/src/events.d.ts +49 -0
- package/dist/src/events.js +19 -0
- package/dist/src/http/app.d.ts +8 -0
- package/dist/src/http/app.js +51 -0
- package/dist/src/http/auth.d.ts +7 -0
- package/dist/src/http/auth.js +32 -0
- package/dist/src/http/faults.d.ts +8 -0
- package/dist/src/http/faults.js +33 -0
- package/dist/src/http/normalize.d.ts +57 -0
- package/dist/src/http/normalize.js +225 -0
- package/dist/src/http/respond.d.ts +23 -0
- package/dist/src/http/respond.js +37 -0
- package/dist/src/http/routes.d.ts +60 -0
- package/dist/src/http/routes.js +64 -0
- package/dist/src/inbound/deliver.d.ts +9 -0
- package/dist/src/inbound/deliver.js +34 -0
- package/dist/src/inbound/parse.d.ts +21 -0
- package/dist/src/inbound/parse.js +71 -0
- package/dist/src/inbound/receive.d.ts +17 -0
- package/dist/src/inbound/receive.js +89 -0
- package/dist/src/main.d.ts +2 -0
- package/dist/src/main.js +14 -0
- package/dist/src/mime/compose.d.ts +33 -0
- package/dist/src/mime/compose.js +58 -0
- package/dist/src/pipeline/addresses.d.ts +6 -0
- package/dist/src/pipeline/addresses.js +38 -0
- package/dist/src/pipeline/inactive.d.ts +8 -0
- package/dist/src/pipeline/inactive.js +20 -0
- package/dist/src/pipeline/submit.d.ts +138 -0
- package/dist/src/pipeline/submit.js +415 -0
- package/dist/src/plugins/message-events.d.ts +7 -0
- package/dist/src/plugins/message-events.js +76 -0
- package/dist/src/plugins/smtp.d.ts +15 -0
- package/dist/src/plugins/smtp.js +42 -0
- package/dist/src/plugins/stats.d.ts +7 -0
- package/dist/src/plugins/stats.js +78 -0
- package/dist/src/plugins/webhooks.d.ts +4 -0
- package/dist/src/plugins/webhooks.js +80 -0
- package/dist/src/plugins.d.ts +20 -0
- package/dist/src/plugins.js +9 -0
- package/dist/src/recipients/test-bounces.d.ts +15 -0
- package/dist/src/recipients/test-bounces.js +31 -0
- package/dist/src/recipients/transitions.d.ts +57 -0
- package/dist/src/recipients/transitions.js +279 -0
- package/dist/src/render/mustachio.d.ts +60 -0
- package/dist/src/render/mustachio.js +265 -0
- package/dist/src/runtime.d.ts +12 -0
- package/dist/src/runtime.js +11 -0
- package/dist/src/server.d.ts +25 -0
- package/dist/src/server.js +49 -0
- package/dist/src/smtp/auth.d.ts +35 -0
- package/dist/src/smtp/auth.js +66 -0
- package/dist/src/smtp/listener.d.ts +16 -0
- package/dist/src/smtp/listener.js +121 -0
- package/dist/src/smtp/mime.d.ts +36 -0
- package/dist/src/smtp/mime.js +181 -0
- package/dist/src/smtp/receive.d.ts +21 -0
- package/dist/src/smtp/receive.js +89 -0
- package/dist/src/smtp/reply.d.ts +14 -0
- package/dist/src/smtp/reply.js +24 -0
- package/dist/src/state/clock.d.ts +35 -0
- package/dist/src/state/clock.js +107 -0
- package/dist/src/state/ids.d.ts +6 -0
- package/dist/src/state/ids.js +7 -0
- package/dist/src/state/servers.d.ts +27 -0
- package/dist/src/state/servers.js +101 -0
- package/dist/src/state/store.d.ts +57 -0
- package/dist/src/state/store.js +98 -0
- package/dist/src/state/suppressions.d.ts +9 -0
- package/dist/src/state/suppressions.js +8 -0
- package/dist/src/state/types.d.ts +530 -0
- package/dist/src/state/types.js +41 -0
- package/dist/src/time.d.ts +11 -0
- package/dist/src/time.js +48 -0
- package/dist/src/tracking.d.ts +53 -0
- package/dist/src/tracking.js +150 -0
- package/dist/src/webhooks/deliver.d.ts +60 -0
- package/dist/src/webhooks/deliver.js +172 -0
- package/dist/src/webhooks/egress.d.ts +19 -0
- package/dist/src/webhooks/egress.js +40 -0
- package/dist/src/webhooks/outbound.d.ts +26 -0
- package/dist/src/webhooks/outbound.js +47 -0
- package/dist/src/webhooks/payloads.d.ts +111 -0
- package/dist/src/webhooks/payloads.js +128 -0
- package/package.json +55 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface Discovered {
|
|
2
|
+
url: URL;
|
|
3
|
+
module: unknown;
|
|
4
|
+
}
|
|
5
|
+
/** `.ts` when Node runs the sources, `.js` in the built package: discovered files share it. */
|
|
6
|
+
export declare const MODULE_EXTENSION: string;
|
|
7
|
+
/**
|
|
8
|
+
* Imports modules found on disk, sorted by path, so parallel tracks add files without editing a
|
|
9
|
+
* shared list (docs/11 §5). Names starting with `.` are skipped (macOS `._*` files).
|
|
10
|
+
* Without `file`: each module file in `dir` (`MODULE_EXTENSION`), tests excluded.
|
|
11
|
+
* With `file`: `<subdir>/<file><MODULE_EXTENSION>` for each subdirectory; a subdirectory without it
|
|
12
|
+
* throws.
|
|
13
|
+
*/
|
|
14
|
+
export declare function importAll(dir: URL, file?: string): Promise<Discovered[]>;
|
|
15
|
+
/** The default export of a discovered module, which must be a function. */
|
|
16
|
+
export declare function defaultFunction<F extends (...args: never[]) => unknown>(found: Discovered): F;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
2
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
3
|
+
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
4
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
return path;
|
|
8
|
+
};
|
|
9
|
+
import { existsSync, readdirSync } from "node:fs";
|
|
10
|
+
import { extname } from "node:path";
|
|
11
|
+
import { fileURLToPath } from "node:url";
|
|
12
|
+
/** `.ts` when Node runs the sources, `.js` in the built package: discovered files share it. */
|
|
13
|
+
export const MODULE_EXTENSION = extname(fileURLToPath(import.meta.url));
|
|
14
|
+
const visible = (name) => !name.startsWith(".");
|
|
15
|
+
/**
|
|
16
|
+
* Imports modules found on disk, sorted by path, so parallel tracks add files without editing a
|
|
17
|
+
* shared list (docs/11 §5). Names starting with `.` are skipped (macOS `._*` files).
|
|
18
|
+
* Without `file`: each module file in `dir` (`MODULE_EXTENSION`), tests excluded.
|
|
19
|
+
* With `file`: `<subdir>/<file><MODULE_EXTENSION>` for each subdirectory; a subdirectory without it
|
|
20
|
+
* throws.
|
|
21
|
+
*/
|
|
22
|
+
export async function importAll(dir, file) {
|
|
23
|
+
const ext = MODULE_EXTENSION;
|
|
24
|
+
const entries = readdirSync(dir, { withFileTypes: true }).filter((e) => visible(e.name));
|
|
25
|
+
const urls = file === undefined
|
|
26
|
+
? entries
|
|
27
|
+
.filter((e) => e.isFile() && e.name.endsWith(ext) && !e.name.endsWith(`.test${ext}`))
|
|
28
|
+
.map((e) => new URL(e.name, dir))
|
|
29
|
+
: entries
|
|
30
|
+
.filter((e) => e.isDirectory())
|
|
31
|
+
.map((e) => {
|
|
32
|
+
const url = new URL(`${e.name}/${file}${ext}`, dir);
|
|
33
|
+
if (!existsSync(url))
|
|
34
|
+
throw new Error(`${new URL(`${e.name}/`, dir).pathname}: ${e.name} has no ${file}${ext}`);
|
|
35
|
+
return url;
|
|
36
|
+
});
|
|
37
|
+
urls.sort((a, b) => (a.href < b.href ? -1 : 1));
|
|
38
|
+
const found = [];
|
|
39
|
+
for (const url of urls)
|
|
40
|
+
found.push({ url, module: await import(__rewriteRelativeImportExtension(url.href)) });
|
|
41
|
+
return found;
|
|
42
|
+
}
|
|
43
|
+
/** The default export of a discovered module, which must be a function. */
|
|
44
|
+
export function defaultFunction(found) {
|
|
45
|
+
const value = found.module.default;
|
|
46
|
+
if (typeof value !== "function")
|
|
47
|
+
throw new Error(`${found.url.pathname} has no default export function`);
|
|
48
|
+
return value;
|
|
49
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export declare const ERROR_FAMILIES: readonly ["auth", "global", "sending", "templates", "servers", "messages", "inboundRules", "streams", "suppressions", "senders", "smtpTokens", "stats", "dataRemovals", "webhooks"];
|
|
2
|
+
export type ErrorFamily = (typeof ERROR_FAMILIES)[number];
|
|
3
|
+
/** HTTP statuses a code uses. 200 means the code only appears inside a 200 body item. */
|
|
4
|
+
type Statuses = readonly [number, ...number[]];
|
|
5
|
+
type Row = readonly [
|
|
6
|
+
code: number,
|
|
7
|
+
family: ErrorFamily,
|
|
8
|
+
statuses: Statuses,
|
|
9
|
+
wording: "message" | "summary",
|
|
10
|
+
text: string
|
|
11
|
+
];
|
|
12
|
+
export declare const ERROR_TABLE: readonly Row[];
|
|
13
|
+
export type ErrorBody = {
|
|
14
|
+
ErrorCode: number;
|
|
15
|
+
Message: string;
|
|
16
|
+
};
|
|
17
|
+
/** A Postmark error response. The HTTP app turns it into the envelope (docs/02 §4.1). */
|
|
18
|
+
export declare class ApiError extends Error {
|
|
19
|
+
readonly status: number;
|
|
20
|
+
readonly body: ErrorBody & Record<string, unknown>;
|
|
21
|
+
constructor(status: number, body: ErrorBody & Record<string, unknown>);
|
|
22
|
+
}
|
|
23
|
+
export type ErrorOptions = {
|
|
24
|
+
/** Required for a code listed under more than one family (614, 1226). */
|
|
25
|
+
family?: ErrorFamily;
|
|
26
|
+
} & ({
|
|
27
|
+
/** Exact wire text, used as given. Required for a `summary` row. */
|
|
28
|
+
message: string;
|
|
29
|
+
params?: never;
|
|
30
|
+
} | {
|
|
31
|
+
message?: never;
|
|
32
|
+
/** Values for `{name}` placeholders in a `message` row. */
|
|
33
|
+
params?: Record<string, string>;
|
|
34
|
+
});
|
|
35
|
+
/** Whether the docs/02 §4.4 row of `code` is a summary that needs an exact message. */
|
|
36
|
+
export declare const isSummaryRow: (code: number, family?: ErrorFamily) => boolean;
|
|
37
|
+
/** `{ErrorCode, Message}` for a response body or a batch item. */
|
|
38
|
+
export declare function errorBody(code: number, options?: ErrorOptions): ErrorBody;
|
|
39
|
+
/** An HTTP error for `code`. `status` is required when the code uses several statuses. */
|
|
40
|
+
export declare function apiError(code: number, options?: ErrorOptions & {
|
|
41
|
+
status?: number;
|
|
42
|
+
extra?: Record<string, unknown>;
|
|
43
|
+
}): ApiError;
|
|
44
|
+
/**
|
|
45
|
+
* The HTTP error for a body `errorBody` built earlier, such as a send rejection. The code may sit
|
|
46
|
+
* under several families; every row of it must use the same single status.
|
|
47
|
+
*/
|
|
48
|
+
export declare function apiErrorOf(body: ErrorBody): ApiError;
|
|
49
|
+
export {};
|