@c9up/goldstone 0.0.0-stage → 0.1.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.
Files changed (83) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +238 -2
  3. package/dist/GoldstoneProvider.d.ts +33 -0
  4. package/dist/GoldstoneProvider.d.ts.map +1 -0
  5. package/dist/GoldstoneProvider.js +55 -0
  6. package/dist/GoldstoneProvider.js.map +1 -0
  7. package/dist/InboxManager.d.ts +17 -0
  8. package/dist/InboxManager.d.ts.map +1 -0
  9. package/dist/InboxManager.js +39 -0
  10. package/dist/InboxManager.js.map +1 -0
  11. package/dist/Mailbox.d.ts +83 -0
  12. package/dist/Mailbox.d.ts.map +1 -0
  13. package/dist/Mailbox.js +326 -0
  14. package/dist/Mailbox.js.map +1 -0
  15. package/dist/ReceivedMessage.d.ts +152 -0
  16. package/dist/ReceivedMessage.d.ts.map +1 -0
  17. package/dist/ReceivedMessage.js +179 -0
  18. package/dist/ReceivedMessage.js.map +1 -0
  19. package/dist/augmentations.d.ts +18 -0
  20. package/dist/augmentations.d.ts.map +1 -0
  21. package/dist/augmentations.js +10 -0
  22. package/dist/augmentations.js.map +1 -0
  23. package/dist/authenticity.d.ts +81 -0
  24. package/dist/authenticity.d.ts.map +1 -0
  25. package/dist/authenticity.js +102 -0
  26. package/dist/authenticity.js.map +1 -0
  27. package/dist/config.d.ts +85 -0
  28. package/dist/config.d.ts.map +1 -0
  29. package/dist/config.js +50 -0
  30. package/dist/config.js.map +1 -0
  31. package/dist/errors.d.ts +15 -0
  32. package/dist/errors.d.ts.map +1 -0
  33. package/dist/errors.js +50 -0
  34. package/dist/errors.js.map +1 -0
  35. package/dist/inbound/context.d.ts +43 -0
  36. package/dist/inbound/context.d.ts.map +1 -0
  37. package/dist/inbound/context.js +56 -0
  38. package/dist/inbound/context.js.map +1 -0
  39. package/dist/inbound/mailgun.d.ts +57 -0
  40. package/dist/inbound/mailgun.d.ts.map +1 -0
  41. package/dist/inbound/mailgun.js +132 -0
  42. package/dist/inbound/mailgun.js.map +1 -0
  43. package/dist/index.d.ts +11 -0
  44. package/dist/index.d.ts.map +1 -0
  45. package/dist/index.js +11 -0
  46. package/dist/index.js.map +1 -0
  47. package/dist/native/generated.d.ts +106 -0
  48. package/dist/native/generated.d.ts.map +1 -0
  49. package/dist/native/generated.js +7 -0
  50. package/dist/native/generated.js.map +1 -0
  51. package/dist/native.d.ts +23 -0
  52. package/dist/native.d.ts.map +1 -0
  53. package/dist/native.js +45 -0
  54. package/dist/native.js.map +1 -0
  55. package/dist/services/main.d.ts +22 -0
  56. package/dist/services/main.d.ts.map +1 -0
  57. package/dist/services/main.js +43 -0
  58. package/dist/services/main.js.map +1 -0
  59. package/dist/vendor/nativeBinary.d.ts +67 -0
  60. package/dist/vendor/nativeBinary.d.ts.map +1 -0
  61. package/dist/vendor/nativeBinary.js +156 -0
  62. package/dist/vendor/nativeBinary.js.map +1 -0
  63. package/index.darwin-arm64.node +0 -0
  64. package/index.darwin-x64.node +0 -0
  65. package/index.linux-arm64-gnu.node +0 -0
  66. package/index.linux-x64-gnu.node +0 -0
  67. package/index.win32-x64-msvc.node +0 -0
  68. package/package.json +67 -3
  69. package/src/GoldstoneProvider.ts +75 -0
  70. package/src/InboxManager.ts +51 -0
  71. package/src/Mailbox.ts +433 -0
  72. package/src/ReceivedMessage.ts +287 -0
  73. package/src/augmentations.ts +22 -0
  74. package/src/authenticity.ts +183 -0
  75. package/src/config.ts +132 -0
  76. package/src/errors.ts +57 -0
  77. package/src/inbound/context.ts +92 -0
  78. package/src/inbound/mailgun.ts +201 -0
  79. package/src/index.ts +53 -0
  80. package/src/native/generated.ts +141 -0
  81. package/src/native.ts +62 -0
  82. package/src/services/main.ts +51 -0
  83. package/src/vendor/nativeBinary.ts +186 -0
@@ -0,0 +1,186 @@
1
+ // Generated from scripts/vendor/nativeBinary.ts — do not edit.
2
+ //
3
+ // This package is published and built from its own repository, so the file
4
+ // has to exist here rather than be imported. `pnpm vendor:sync` rewrites it,
5
+ // and `pnpm vendor:check` fails if this copy has drifted from the original.
6
+
7
+ /**
8
+ * Finding the NAPI binary a package ships beside itself.
9
+ *
10
+ * Every package with a Rust engine repeats the same table: napi-rs names its
11
+ * artefacts `index.<platform>-<arch>-<abi>.node`, and the mapping from Node's
12
+ * `platform`/`arch` to that suffix is the part that must never differ between
13
+ * packages. Adding a target means adding it everywhere, and a package that
14
+ * missed the edit fails only on that platform — which is exactly the failure
15
+ * nobody reproduces.
16
+ *
17
+ * What is NOT here is the policy. Some packages degrade when the binary is
18
+ * absent and answer `undefined`; others refuse loudly with build instructions.
19
+ * Both are right for their package, so the loader reports what happened and
20
+ * the caller decides.
21
+ */
22
+
23
+ import { createRequire } from "node:module";
24
+ import { dirname, join } from "node:path";
25
+ import { arch, platform } from "node:process";
26
+ import { fileURLToPath } from "node:url";
27
+
28
+ /** Node's `platform-arch` → the suffix napi-rs builds under. */
29
+ const TARGETS: Record<string, string> = {
30
+ "linux-x64": "linux-x64-gnu",
31
+ "linux-arm64": "linux-arm64-gnu",
32
+ "darwin-x64": "darwin-x64",
33
+ "darwin-arm64": "darwin-arm64",
34
+ "win32-x64": "win32-x64-msvc",
35
+ };
36
+
37
+ /**
38
+ * Every `platform-arch` a binary is built for.
39
+ *
40
+ * For the message a package raises when it refuses: "no binary for
41
+ * linux-riscv64" is only actionable next to the list of what there IS.
42
+ */
43
+ export function supportedTargets(): readonly string[] {
44
+ return Object.keys(TARGETS);
45
+ }
46
+
47
+ /** The suffix a given `platform-arch` builds under, or `undefined`. */
48
+ export function nativeTargetSuffix(target: string): string | undefined {
49
+ return TARGETS[target];
50
+ }
51
+
52
+ /** The suffix for THIS platform, or `undefined` where no binary is built. */
53
+ export function nativeBinarySuffix(): string | undefined {
54
+ return nativeTargetSuffix(`${platform}-${arch}`);
55
+ }
56
+
57
+ /**
58
+ * Why the binary is not there, phrased for whoever has to fix it.
59
+ *
60
+ * "not found" and "not built for your platform" call for different actions,
61
+ * and a single "unavailable" leaves the reader to guess which one they are
62
+ * looking at.
63
+ */
64
+ export function unavailableReason(cause?: unknown): string {
65
+ if (cause !== undefined) {
66
+ return `failed to load (${cause instanceof Error ? cause.message : String(cause)})`;
67
+ }
68
+ const target = `${platform}-${arch}`;
69
+ return nativeTargetSuffix(target) !== undefined
70
+ ? "binary not found"
71
+ : `no prebuilt binary for ${target}`;
72
+ }
73
+
74
+ /**
75
+ * `musl` builds under a different suffix, and the failure is otherwise
76
+ * baffling: the file is there, and `require` still refuses it. Worth saying so
77
+ * in a message rather than leaving a reader to discover glibc.
78
+ */
79
+ export function muslHint(): string {
80
+ return platform === "linux"
81
+ ? " On Alpine/musl, the gnu binary will not load — build the musl target."
82
+ : "";
83
+ }
84
+
85
+ /** What a load attempt did, so the caller can apply its own policy. */
86
+ export type NativeBinaryResult<T> =
87
+ | { loaded: true; binary: T }
88
+ | { loaded: false; suffix: string | undefined; cause?: unknown };
89
+
90
+ /** Whether `value` carries a function under `name` (a napi class is one too). */
91
+ function hasFunction(value: object, name: string): boolean {
92
+ const member: unknown = Reflect.get(value, name);
93
+ return typeof member === "function";
94
+ }
95
+
96
+ /**
97
+ * The names among `names` that `value` does not carry as functions.
98
+ *
99
+ * Classes count, being functions, and so does a class's static member: `value`
100
+ * may itself be a function. What a guard rejects is only useful named, so the
101
+ * loader reports this list rather than a bare "no".
102
+ */
103
+ export function missingFunctions(
104
+ value: unknown,
105
+ names: readonly string[],
106
+ ): string[] {
107
+ if (
108
+ value === null ||
109
+ (typeof value !== "object" && typeof value !== "function")
110
+ ) {
111
+ return [...names];
112
+ }
113
+ return names.filter((name) => !hasFunction(value, name));
114
+ }
115
+
116
+ /**
117
+ * Whether `value` carries every one of `names` as a function.
118
+ *
119
+ * The building block of the guard a package hands to `loadNativeBinary`, over
120
+ * the list of what it actually calls on its binary — the same list it passes
121
+ * as `expects`, so the message can name what is missing.
122
+ */
123
+ export function hasFunctions(
124
+ value: unknown,
125
+ names: readonly string[],
126
+ ): value is object {
127
+ if (
128
+ value === null ||
129
+ (typeof value !== "object" && typeof value !== "function")
130
+ ) {
131
+ return false;
132
+ }
133
+ return missingFunctions(value, names).length === 0;
134
+ }
135
+
136
+ /**
137
+ * Load `<package root>/index.<suffix>.node`, and check it is the binary the
138
+ * package calls.
139
+ *
140
+ * The path is fixed rather than passed: this file is generated into
141
+ * `<package>/src/vendor/`, so the package root is always two levels up, from
142
+ * `src` and from `dist` alike.
143
+ *
144
+ * `isBinary` is the package's own check of what it calls. A declaration only
145
+ * says what the Rust promises: a stale build, or one from another version,
146
+ * loads just as well and then fails on the first missing call, far from here.
147
+ * A rejected module is reported as a failed load, so the package's policy
148
+ * (degrade or refuse) applies to it unchanged. `expects`, the list the guard is
149
+ * built from, lets that report name the missing calls.
150
+ */
151
+ export function loadNativeBinary<T>(
152
+ isBinary: (value: unknown) => value is T,
153
+ expects?: readonly string[],
154
+ ): NativeBinaryResult<T> {
155
+ const suffix = nativeBinarySuffix();
156
+ if (suffix === undefined) return { loaded: false, suffix };
157
+ const here = dirname(fileURLToPath(import.meta.url));
158
+ let loaded: unknown;
159
+ try {
160
+ const nodeRequire = createRequire(import.meta.url);
161
+ loaded = nodeRequire(join(here, `../../index.${suffix}.node`));
162
+ } catch (cause) {
163
+ return { loaded: false, suffix, cause };
164
+ }
165
+ if (isBinary(loaded)) return { loaded: true, binary: loaded };
166
+ return {
167
+ loaded: false,
168
+ suffix,
169
+ cause: new Error(
170
+ `index.${suffix}.node loaded, but ${rejection(loaded, expects)}. ` +
171
+ "The binary is stale or from another version: rebuild it.",
172
+ ),
173
+ };
174
+ }
175
+
176
+ /** What a rejected binary lacks, or, without a list to check, what it has. */
177
+ function rejection(loaded: unknown, expects?: readonly string[]): string {
178
+ const missing =
179
+ expects === undefined ? [] : missingFunctions(loaded, expects);
180
+ if (missing.length > 0) return `it lacks ${missing.join(", ")}`;
181
+ const exported =
182
+ typeof loaded === "object" && loaded !== null
183
+ ? Object.keys(loaded).filter((name) => hasFunction(loaded, name))
184
+ : [];
185
+ return `it is not the binary this package calls (it exports: ${exported.length > 0 ? exported.join(", ") : "none"})`;
186
+ }