l402-server 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.
package/dist/index.js ADDED
@@ -0,0 +1,235 @@
1
+ // src/errors.ts
2
+ var L402ServerError = class extends Error {
3
+ constructor(message, options) {
4
+ super(message, options);
5
+ this.name = "L402ServerError";
6
+ }
7
+ };
8
+ var L402AuthError = class extends L402ServerError {
9
+ constructor(message = "Merchant API key is missing or invalid.") {
10
+ super(message);
11
+ this.name = "L402AuthError";
12
+ }
13
+ };
14
+ var L402PlanError = class extends L402ServerError {
15
+ /**
16
+ * The plan tier currently on the merchant (e.g., "starter").
17
+ * Populated when the server includes it in the error payload.
18
+ */
19
+ currentPlan;
20
+ constructor(message = "L402 is not enabled on this merchant's plan.", currentPlan) {
21
+ super(message);
22
+ this.name = "L402PlanError";
23
+ this.currentPlan = currentPlan;
24
+ }
25
+ };
26
+ var L402NetworkError = class extends L402ServerError {
27
+ constructor(message, cause) {
28
+ super(message, { cause });
29
+ this.name = "L402NetworkError";
30
+ }
31
+ };
32
+ var L402ApiError = class extends L402ServerError {
33
+ /**
34
+ * HTTP status code returned by the producer API.
35
+ */
36
+ statusCode;
37
+ /**
38
+ * Raw response body, useful for debugging. May be a parsed object or a
39
+ * string if parsing failed.
40
+ */
41
+ responseBody;
42
+ constructor(statusCode, message, responseBody) {
43
+ super(message);
44
+ this.name = "L402ApiError";
45
+ this.statusCode = statusCode;
46
+ this.responseBody = responseBody;
47
+ }
48
+ };
49
+
50
+ // src/L402Server.ts
51
+ var DEFAULT_BASE_URL = "https://api.lightningenable.com";
52
+ var DEFAULT_TIMEOUT_MS = 1e4;
53
+ var L402Server = class {
54
+ apiKey;
55
+ baseUrl;
56
+ timeoutMs;
57
+ fetchImpl;
58
+ constructor(options) {
59
+ if (!options.apiKey || options.apiKey.trim().length === 0) {
60
+ throw new Error(
61
+ "L402Server: `apiKey` is required. Get one from your Lightning Enable dashboard."
62
+ );
63
+ }
64
+ this.apiKey = options.apiKey;
65
+ this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
66
+ this.timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
67
+ this.fetchImpl = options.fetch ?? fetch;
68
+ }
69
+ /**
70
+ * Mint an L402 challenge — a Lightning invoice plus a macaroon scoped to
71
+ * the given resource. Present this to the requesting client/agent in a
72
+ * `402 Payment Required` response. Once they pay the invoice and obtain
73
+ * the preimage, they will retry the request with
74
+ * `Authorization: L402 <macaroon>:<preimage>`.
75
+ *
76
+ * @param args - resource path, price in sats, optional description and idempotency key.
77
+ * @returns The {@link Challenge} containing the invoice, macaroon, and metadata.
78
+ * @throws {@link L402AuthError} on 401 (invalid API key).
79
+ * @throws {@link L402PlanError} on 403 (L402 not enabled on merchant's plan).
80
+ * @throws {@link L402ApiError} on other non-2xx responses.
81
+ * @throws {@link L402NetworkError} on timeout or transport failure.
82
+ */
83
+ async createChallenge(args) {
84
+ if (!args.resource || args.resource.trim().length === 0) {
85
+ throw new Error("createChallenge: `resource` is required.");
86
+ }
87
+ if (!Number.isFinite(args.priceSats) || args.priceSats < 1) {
88
+ throw new Error("createChallenge: `priceSats` must be an integer \u2265 1.");
89
+ }
90
+ const headers = {
91
+ "Content-Type": "application/json",
92
+ "X-API-Key": this.apiKey,
93
+ Accept: "application/json"
94
+ };
95
+ if (args.idempotencyKey) {
96
+ headers["X-Idempotency-Key"] = args.idempotencyKey;
97
+ }
98
+ const body = JSON.stringify({
99
+ resource: args.resource,
100
+ priceSats: args.priceSats,
101
+ description: args.description
102
+ });
103
+ const response = await this.request(
104
+ "/api/l402/challenges",
105
+ "POST",
106
+ headers,
107
+ body
108
+ );
109
+ if (response.status === 200) {
110
+ const data = await response.json();
111
+ return {
112
+ invoice: data.invoice,
113
+ macaroon: data.macaroon,
114
+ paymentHash: data.paymentHash,
115
+ expiresAt: data.expiresAt,
116
+ resource: data.resource,
117
+ priceSats: data.priceSats,
118
+ mppChallenge: data.mppChallenge ?? void 0
119
+ };
120
+ }
121
+ await this.throwForStatus(response);
122
+ throw new L402ApiError(
123
+ response.status,
124
+ "Unexpected response from L402 producer API."
125
+ );
126
+ }
127
+ /**
128
+ * Verify an L402 token. Returns a {@link VerificationResult} indicating
129
+ * whether the token is valid plus metadata extracted from the macaroon
130
+ * (resource, merchant ID, amount).
131
+ *
132
+ * The producer API returns `200 OK` for both valid and invalid tokens;
133
+ * inspect `result.valid` rather than relying on HTTP status. Non-200
134
+ * responses indicate a higher-level problem (auth, plan, transport).
135
+ *
136
+ * @param args - macaroon (required for L402; omit only for MPP) + preimage.
137
+ * @returns The {@link VerificationResult}.
138
+ * @throws {@link L402AuthError} on 401 (invalid API key).
139
+ * @throws {@link L402PlanError} on 403 (L402 not enabled on merchant's plan).
140
+ * @throws {@link L402ApiError} on other non-2xx responses.
141
+ * @throws {@link L402NetworkError} on timeout or transport failure.
142
+ */
143
+ async verifyToken(args) {
144
+ if (!args.preimage || args.preimage.trim().length === 0) {
145
+ throw new Error("verifyToken: `preimage` is required.");
146
+ }
147
+ const headers = {
148
+ "Content-Type": "application/json",
149
+ "X-API-Key": this.apiKey,
150
+ Accept: "application/json"
151
+ };
152
+ const body = JSON.stringify({
153
+ macaroon: args.macaroon,
154
+ preimage: args.preimage
155
+ });
156
+ const response = await this.request(
157
+ "/api/l402/challenges/verify",
158
+ "POST",
159
+ headers,
160
+ body
161
+ );
162
+ if (response.status === 200) {
163
+ const data = await response.json();
164
+ return {
165
+ valid: data.valid,
166
+ error: data.error ?? void 0,
167
+ resource: data.resource ?? void 0,
168
+ merchantId: data.merchantId ?? void 0,
169
+ amountSats: data.amountSats ?? void 0,
170
+ paymentHash: data.paymentHash ?? void 0
171
+ };
172
+ }
173
+ await this.throwForStatus(response);
174
+ throw new L402ApiError(
175
+ response.status,
176
+ "Unexpected response from L402 producer API."
177
+ );
178
+ }
179
+ async request(path, method, headers, body) {
180
+ const url = `${this.baseUrl}${path}`;
181
+ const controller = new AbortController();
182
+ const timer = setTimeout(() => controller.abort(), this.timeoutMs);
183
+ try {
184
+ return await this.fetchImpl(url, {
185
+ method,
186
+ headers,
187
+ body,
188
+ signal: controller.signal
189
+ });
190
+ } catch (err) {
191
+ if (err?.name === "AbortError") {
192
+ throw new L402NetworkError(
193
+ `Request to ${url} timed out after ${this.timeoutMs}ms`,
194
+ err
195
+ );
196
+ }
197
+ throw new L402NetworkError(
198
+ `Network error talking to ${url}: ${err.message}`,
199
+ err
200
+ );
201
+ } finally {
202
+ clearTimeout(timer);
203
+ }
204
+ }
205
+ async throwForStatus(response) {
206
+ let body;
207
+ try {
208
+ body = await response.json();
209
+ } catch {
210
+ try {
211
+ body = await response.text();
212
+ } catch {
213
+ body = void 0;
214
+ }
215
+ }
216
+ const errorMessage = body?.error ?? body?.message ?? `HTTP ${response.status} from ${response.url}`;
217
+ if (response.status === 401) {
218
+ throw new L402AuthError(errorMessage);
219
+ }
220
+ if (response.status === 403) {
221
+ const currentPlan = body?.current_plan;
222
+ throw new L402PlanError(errorMessage, currentPlan);
223
+ }
224
+ throw new L402ApiError(response.status, errorMessage, body);
225
+ }
226
+ };
227
+ export {
228
+ L402ApiError,
229
+ L402AuthError,
230
+ L402NetworkError,
231
+ L402PlanError,
232
+ L402Server,
233
+ L402ServerError
234
+ };
235
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/errors.ts","../src/L402Server.ts"],"sourcesContent":["/**\n * Base error class for all SDK-thrown errors. Distinguishable from arbitrary\n * `Error` instances via `instanceof L402ServerError`.\n */\nexport class L402ServerError extends Error {\n constructor(message: string, options?: ErrorOptions) {\n super(message, options);\n this.name = \"L402ServerError\";\n }\n}\n\n/**\n * Thrown on `401 Unauthorized` from the producer API. Almost always means\n * the merchant API key is missing, malformed, expired, or revoked.\n */\nexport class L402AuthError extends L402ServerError {\n constructor(message: string = \"Merchant API key is missing or invalid.\") {\n super(message);\n this.name = \"L402AuthError\";\n }\n}\n\n/**\n * Thrown on `403 Forbidden` from the producer API. Means the merchant\n * exists and the key is valid, but L402 is not enabled on their plan.\n * The merchant needs to upgrade to an Agentic Commerce plan.\n */\nexport class L402PlanError extends L402ServerError {\n /**\n * The plan tier currently on the merchant (e.g., \"starter\").\n * Populated when the server includes it in the error payload.\n */\n readonly currentPlan?: string;\n\n constructor(\n message: string = \"L402 is not enabled on this merchant's plan.\",\n currentPlan?: string,\n ) {\n super(message);\n this.name = \"L402PlanError\";\n this.currentPlan = currentPlan;\n }\n}\n\n/**\n * Thrown for transport-level failures: timeout, DNS error, TLS error,\n * unreachable host. The `cause` carries the original error.\n */\nexport class L402NetworkError extends L402ServerError {\n constructor(message: string, cause?: unknown) {\n super(message, { cause });\n this.name = \"L402NetworkError\";\n }\n}\n\n/**\n * Thrown when the server returns a non-success status that doesn't map to\n * a more specific error class above (e.g., 400 with a request-validation\n * problem, 500 from upstream wallet failure, 429 from rate limiting).\n */\nexport class L402ApiError extends L402ServerError {\n /**\n * HTTP status code returned by the producer API.\n */\n readonly statusCode: number;\n\n /**\n * Raw response body, useful for debugging. May be a parsed object or a\n * string if parsing failed.\n */\n readonly responseBody?: unknown;\n\n constructor(\n statusCode: number,\n message: string,\n responseBody?: unknown,\n ) {\n super(message);\n this.name = \"L402ApiError\";\n this.statusCode = statusCode;\n this.responseBody = responseBody;\n }\n}\n","import {\n L402ApiError,\n L402AuthError,\n L402NetworkError,\n L402PlanError,\n} from \"./errors.js\";\nimport type {\n Challenge,\n CreateChallengeArgs,\n L402ServerOptions,\n VerificationResult,\n VerifyTokenArgs,\n} from \"./types.js\";\n\nconst DEFAULT_BASE_URL = \"https://api.lightningenable.com\";\nconst DEFAULT_TIMEOUT_MS = 10_000;\n\n/**\n * Server-side client for Lightning Enable's L402 producer API. Wraps two\n * endpoints:\n *\n * - {@link createChallenge} → `POST /api/l402/challenges` — mint a\n * Lightning invoice + macaroon for a given resource and price.\n * - {@link verifyToken} → `POST /api/l402/challenges/verify` — validate\n * an incoming L402 token (macaroon + preimage).\n *\n * **No protocol logic lives in this SDK.** The Lightning Enable backend\n * signs macaroons, mints invoices, verifies preimages, and tracks consumed\n * tokens for replay protection. The SDK is purely an HTTP client with\n * typed inputs/outputs.\n *\n * @example\n * ```ts\n * import { L402Server } from \"l402-server\";\n *\n * const l402 = new L402Server({\n * apiKey: process.env.LIGHTNING_ENABLE_API_KEY!,\n * });\n *\n * // On an unauthenticated incoming request:\n * const challenge = await l402.createChallenge({\n * resource: \"/api/premium/weather\",\n * priceSats: 100,\n * description: \"Premium weather forecast\",\n * });\n *\n * // Send back as 402 Payment Required with the challenge headers.\n *\n * // When client comes back with Authorization: L402 mac:preimage,\n * // parse and verify:\n * const verification = await l402.verifyToken({\n * macaroon: parsedMacaroon,\n * preimage: parsedPreimage,\n * });\n * if (verification.valid) {\n * // Serve the response.\n * }\n * ```\n */\nexport class L402Server {\n private readonly apiKey: string;\n private readonly baseUrl: string;\n private readonly timeoutMs: number;\n private readonly fetchImpl: typeof fetch;\n\n constructor(options: L402ServerOptions) {\n if (!options.apiKey || options.apiKey.trim().length === 0) {\n throw new Error(\n \"L402Server: `apiKey` is required. Get one from your Lightning Enable dashboard.\",\n );\n }\n\n this.apiKey = options.apiKey;\n this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/+$/, \"\");\n this.timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;\n this.fetchImpl = options.fetch ?? fetch;\n }\n\n /**\n * Mint an L402 challenge — a Lightning invoice plus a macaroon scoped to\n * the given resource. Present this to the requesting client/agent in a\n * `402 Payment Required` response. Once they pay the invoice and obtain\n * the preimage, they will retry the request with\n * `Authorization: L402 <macaroon>:<preimage>`.\n *\n * @param args - resource path, price in sats, optional description and idempotency key.\n * @returns The {@link Challenge} containing the invoice, macaroon, and metadata.\n * @throws {@link L402AuthError} on 401 (invalid API key).\n * @throws {@link L402PlanError} on 403 (L402 not enabled on merchant's plan).\n * @throws {@link L402ApiError} on other non-2xx responses.\n * @throws {@link L402NetworkError} on timeout or transport failure.\n */\n async createChallenge(args: CreateChallengeArgs): Promise<Challenge> {\n if (!args.resource || args.resource.trim().length === 0) {\n throw new Error(\"createChallenge: `resource` is required.\");\n }\n if (!Number.isFinite(args.priceSats) || args.priceSats < 1) {\n throw new Error(\"createChallenge: `priceSats` must be an integer ≥ 1.\");\n }\n\n const headers: Record<string, string> = {\n \"Content-Type\": \"application/json\",\n \"X-API-Key\": this.apiKey,\n Accept: \"application/json\",\n };\n if (args.idempotencyKey) {\n headers[\"X-Idempotency-Key\"] = args.idempotencyKey;\n }\n\n const body = JSON.stringify({\n resource: args.resource,\n priceSats: args.priceSats,\n description: args.description,\n });\n\n const response = await this.request(\n \"/api/l402/challenges\",\n \"POST\",\n headers,\n body,\n );\n\n if (response.status === 200) {\n const data = (await response.json()) as {\n invoice: string;\n macaroon: string;\n paymentHash: string;\n expiresAt: string;\n resource: string;\n priceSats: number;\n mppChallenge?: string | null;\n };\n return {\n invoice: data.invoice,\n macaroon: data.macaroon,\n paymentHash: data.paymentHash,\n expiresAt: data.expiresAt,\n resource: data.resource,\n priceSats: data.priceSats,\n mppChallenge: data.mppChallenge ?? undefined,\n };\n }\n\n await this.throwForStatus(response);\n // Unreachable — throwForStatus always throws on non-2xx.\n throw new L402ApiError(\n response.status,\n \"Unexpected response from L402 producer API.\",\n );\n }\n\n /**\n * Verify an L402 token. Returns a {@link VerificationResult} indicating\n * whether the token is valid plus metadata extracted from the macaroon\n * (resource, merchant ID, amount).\n *\n * The producer API returns `200 OK` for both valid and invalid tokens;\n * inspect `result.valid` rather than relying on HTTP status. Non-200\n * responses indicate a higher-level problem (auth, plan, transport).\n *\n * @param args - macaroon (required for L402; omit only for MPP) + preimage.\n * @returns The {@link VerificationResult}.\n * @throws {@link L402AuthError} on 401 (invalid API key).\n * @throws {@link L402PlanError} on 403 (L402 not enabled on merchant's plan).\n * @throws {@link L402ApiError} on other non-2xx responses.\n * @throws {@link L402NetworkError} on timeout or transport failure.\n */\n async verifyToken(args: VerifyTokenArgs): Promise<VerificationResult> {\n if (!args.preimage || args.preimage.trim().length === 0) {\n throw new Error(\"verifyToken: `preimage` is required.\");\n }\n\n const headers: Record<string, string> = {\n \"Content-Type\": \"application/json\",\n \"X-API-Key\": this.apiKey,\n Accept: \"application/json\",\n };\n\n const body = JSON.stringify({\n macaroon: args.macaroon,\n preimage: args.preimage,\n });\n\n const response = await this.request(\n \"/api/l402/challenges/verify\",\n \"POST\",\n headers,\n body,\n );\n\n if (response.status === 200) {\n const data = (await response.json()) as {\n valid: boolean;\n resource?: string | null;\n merchantId?: number | null;\n amountSats?: number | null;\n paymentHash?: string | null;\n error?: string | null;\n };\n return {\n valid: data.valid,\n error: data.error ?? undefined,\n resource: data.resource ?? undefined,\n merchantId: data.merchantId ?? undefined,\n amountSats: data.amountSats ?? undefined,\n paymentHash: data.paymentHash ?? undefined,\n };\n }\n\n await this.throwForStatus(response);\n throw new L402ApiError(\n response.status,\n \"Unexpected response from L402 producer API.\",\n );\n }\n\n private async request(\n path: string,\n method: string,\n headers: Record<string, string>,\n body: string,\n ): Promise<Response> {\n const url = `${this.baseUrl}${path}`;\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), this.timeoutMs);\n\n try {\n return await this.fetchImpl(url, {\n method,\n headers,\n body,\n signal: controller.signal,\n });\n } catch (err) {\n if ((err as { name?: string })?.name === \"AbortError\") {\n throw new L402NetworkError(\n `Request to ${url} timed out after ${this.timeoutMs}ms`,\n err,\n );\n }\n throw new L402NetworkError(\n `Network error talking to ${url}: ${(err as Error).message}`,\n err,\n );\n } finally {\n clearTimeout(timer);\n }\n }\n\n private async throwForStatus(response: Response): Promise<never> {\n let body: unknown;\n try {\n body = await response.json();\n } catch {\n try {\n body = await response.text();\n } catch {\n body = undefined;\n }\n }\n\n const errorMessage =\n (body as { error?: string; message?: string })?.error ??\n (body as { error?: string; message?: string })?.message ??\n `HTTP ${response.status} from ${response.url}`;\n\n if (response.status === 401) {\n throw new L402AuthError(errorMessage);\n }\n if (response.status === 403) {\n const currentPlan = (body as { current_plan?: string })?.current_plan;\n throw new L402PlanError(errorMessage, currentPlan);\n }\n throw new L402ApiError(response.status, errorMessage, body);\n }\n}\n"],"mappings":";AAIO,IAAM,kBAAN,cAA8B,MAAM;AAAA,EACzC,YAAY,SAAiB,SAAwB;AACnD,UAAM,SAAS,OAAO;AACtB,SAAK,OAAO;AAAA,EACd;AACF;AAMO,IAAM,gBAAN,cAA4B,gBAAgB;AAAA,EACjD,YAAY,UAAkB,2CAA2C;AACvE,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;AAOO,IAAM,gBAAN,cAA4B,gBAAgB;AAAA;AAAA;AAAA;AAAA;AAAA,EAKxC;AAAA,EAET,YACE,UAAkB,gDAClB,aACA;AACA,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,cAAc;AAAA,EACrB;AACF;AAMO,IAAM,mBAAN,cAA+B,gBAAgB;AAAA,EACpD,YAAY,SAAiB,OAAiB;AAC5C,UAAM,SAAS,EAAE,MAAM,CAAC;AACxB,SAAK,OAAO;AAAA,EACd;AACF;AAOO,IAAM,eAAN,cAA2B,gBAAgB;AAAA;AAAA;AAAA;AAAA,EAIvC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA;AAAA,EAET,YACE,YACA,SACA,cACA;AACA,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,aAAa;AAClB,SAAK,eAAe;AAAA,EACtB;AACF;;;ACpEA,IAAM,mBAAmB;AACzB,IAAM,qBAAqB;AA4CpB,IAAM,aAAN,MAAiB;AAAA,EACL;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEjB,YAAY,SAA4B;AACtC,QAAI,CAAC,QAAQ,UAAU,QAAQ,OAAO,KAAK,EAAE,WAAW,GAAG;AACzD,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,SAAK,SAAS,QAAQ;AACtB,SAAK,WAAW,Q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ACrD,cAAM,IAAI;AAAA,UACR,cAAc,GAAG,oBAAoB,KAAK,SAAS;AAAA,UACnD;AAAA,QACF;AAAA,MACF;AACA,YAAM,IAAI;AAAA,QACR,4BAA4B,GAAG,KAAM,IAAc,OAAO;AAAA,QAC1D;AAAA,MACF;AAAA,IACF,UAAE;AACA,mBAAa,KAAK;AAAA,IACpB;AAAA,EACF;AAAA,EAEA,MAAc,eAAe,UAAoC;AAC/D,QAAI;AACJ,QAAI;AACF,aAAO,MAAM,SAAS,KAAK;AAAA,IAC7B,QAAQ;AACN,UAAI;AACF,eAAO,MAAM,SAAS,KAAK;AAAA,MAC7B,QAAQ;AACN,eAAO;AAAA,MACT;AAAA,IACF;AAEA,UAAM,eACH,MAA+C,SAC/C,MAA+C,WAChD,QAAQ,SAAS,MAAM,SAAS,SAAS,GAAG;AAE9C,QAAI,SAAS,WAAW,KAAK;AAC3B,YAAM,IAAI,cAAc,YAAY;AAAA,IACtC;AACA,QAAI,SAAS,WAAW,KAAK;AAC3B,YAAM,cAAe,MAAoC;AACzD,YAAM,IAAI,cAAc,cAAc,WAAW;AAAA,IACnD;AACA,UAAM,IAAI,aAAa,SAAS,QAAQ,cAAc,IAAI;AAAA,EAC5D;AACF;","names":[]}
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "l402-server",
3
+ "version": "0.1.0",
4
+ "description": "L402 server SDK for Node — mint Lightning invoices + macaroons and verify L402 tokens. Thin TypeScript wrapper around Lightning Enable's hosted producer API.",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "require": {
16
+ "types": "./dist/index.d.cts",
17
+ "default": "./dist/index.cjs"
18
+ }
19
+ }
20
+ },
21
+ "files": [
22
+ "dist"
23
+ ],
24
+ "scripts": {
25
+ "build": "tsup",
26
+ "typecheck": "tsc --noEmit",
27
+ "test": "vitest run",
28
+ "test:watch": "vitest",
29
+ "prepublishOnly": "npm run build"
30
+ },
31
+ "keywords": [
32
+ "l402",
33
+ "lightning",
34
+ "lightning-network",
35
+ "bitcoin",
36
+ "macaroon",
37
+ "payment",
38
+ "402",
39
+ "api",
40
+ "monetization",
41
+ "agent",
42
+ "ai"
43
+ ],
44
+ "author": "Refined Element, LLC",
45
+ "license": "MIT",
46
+ "repository": {
47
+ "type": "git",
48
+ "url": "git+https://github.com/refined-element/le-server-l402-node.git"
49
+ },
50
+ "bugs": {
51
+ "url": "https://github.com/refined-element/le-server-l402-node/issues"
52
+ },
53
+ "homepage": "https://github.com/refined-element/le-server-l402-node#readme",
54
+ "devDependencies": {
55
+ "@types/node": "^22.0.0",
56
+ "tsup": "^8.0.0",
57
+ "typescript": "^5.6.0",
58
+ "vitest": "^2.0.0"
59
+ },
60
+ "engines": {
61
+ "node": ">=18"
62
+ }
63
+ }