@ghostpaygg/node 0.0.0-stage → 1.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/CHANGELOG.md +22 -0
- package/README.md +176 -2
- package/dist/index.cjs +456 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2647 -0
- package/dist/index.d.ts +2647 -0
- package/dist/index.js +423 -0
- package/dist/index.js.map +1 -0
- package/package.json +38 -4
package/dist/index.js
ADDED
|
@@ -0,0 +1,423 @@
|
|
|
1
|
+
// src/http.ts
|
|
2
|
+
import { randomUUID } from "crypto";
|
|
3
|
+
|
|
4
|
+
// src/errors.ts
|
|
5
|
+
var GhostPayError = class extends Error {
|
|
6
|
+
name = "GhostPayError";
|
|
7
|
+
};
|
|
8
|
+
var GhostPayApiError = class extends GhostPayError {
|
|
9
|
+
name = "GhostPayApiError";
|
|
10
|
+
status;
|
|
11
|
+
code;
|
|
12
|
+
param;
|
|
13
|
+
headers;
|
|
14
|
+
raw;
|
|
15
|
+
constructor(status, code, message, param, headers, raw) {
|
|
16
|
+
super(message);
|
|
17
|
+
this.status = status;
|
|
18
|
+
this.code = code;
|
|
19
|
+
this.param = param;
|
|
20
|
+
this.headers = headers;
|
|
21
|
+
this.raw = raw;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
var GhostPayConnectionError = class extends GhostPayError {
|
|
25
|
+
name = "GhostPayConnectionError";
|
|
26
|
+
timedOut;
|
|
27
|
+
constructor(message, timedOut, options) {
|
|
28
|
+
super(message, options);
|
|
29
|
+
this.timedOut = timedOut;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
var WebhookVerificationError = class extends GhostPayError {
|
|
33
|
+
name = "WebhookVerificationError";
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// src/version.ts
|
|
37
|
+
var VERSION = "1.1.0";
|
|
38
|
+
|
|
39
|
+
// src/http.ts
|
|
40
|
+
var RETRY_BASE_MS = 500;
|
|
41
|
+
var RETRY_MAX_MS = 8e3;
|
|
42
|
+
var DEFAULT_BASE_URL = "https://api.ghostpay.gg";
|
|
43
|
+
var HttpClient = class {
|
|
44
|
+
constructor(options) {
|
|
45
|
+
this.options = options;
|
|
46
|
+
this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
47
|
+
this.fetchImpl = options.fetch ?? globalThis.fetch;
|
|
48
|
+
if (!this.fetchImpl) throw new GhostPayError("No fetch available: use Node 18+ or pass options.fetch");
|
|
49
|
+
this.userAgent = `ghostpay-node/${VERSION} node/${process.versions.node}${options.appInfo ? ` ${options.appInfo}` : ""}`;
|
|
50
|
+
}
|
|
51
|
+
options;
|
|
52
|
+
baseUrl;
|
|
53
|
+
fetchImpl;
|
|
54
|
+
userAgent;
|
|
55
|
+
async request(spec, options = {}) {
|
|
56
|
+
const auth = spec.auth ?? true;
|
|
57
|
+
if (auth && !this.options.apiKey) throw new GhostPayError("This call needs an API key: new GhostPay({ apiKey, baseUrl })");
|
|
58
|
+
const url = this.baseUrl + spec.path + queryString(spec.query);
|
|
59
|
+
const idempotencyKey = spec.method === "POST" ? options.idempotencyKey ?? randomUUID() : void 0;
|
|
60
|
+
const headers = {
|
|
61
|
+
accept: "application/json",
|
|
62
|
+
"user-agent": this.userAgent,
|
|
63
|
+
...auth ? { authorization: `Bearer ${this.options.apiKey}` } : {},
|
|
64
|
+
...idempotencyKey ? { "idempotency-key": idempotencyKey } : {},
|
|
65
|
+
...spec.body !== void 0 ? { "content-type": "application/json" } : {},
|
|
66
|
+
...options.headers
|
|
67
|
+
};
|
|
68
|
+
const body = spec.body !== void 0 ? JSON.stringify(spec.body) : void 0;
|
|
69
|
+
const maxRetries = options.maxRetries ?? this.options.maxRetries ?? 2;
|
|
70
|
+
const timeoutMs = options.timeoutMs ?? this.options.timeoutMs ?? 3e4;
|
|
71
|
+
for (let attempt = 0; ; attempt++) {
|
|
72
|
+
let response;
|
|
73
|
+
let text;
|
|
74
|
+
try {
|
|
75
|
+
({ response, text } = await this.send(url, { method: spec.method, headers, ...body !== void 0 ? { body } : {} }, timeoutMs, options.signal));
|
|
76
|
+
} catch (error2) {
|
|
77
|
+
if (options.signal?.aborted) throw error2;
|
|
78
|
+
const sent = !(error2 instanceof GhostPayConnectionError && isRefused(error2));
|
|
79
|
+
if (attempt < maxRetries && (spec.method === "GET" || !sent || spec.retryAfterSend !== false)) {
|
|
80
|
+
await sleep(backoff(attempt));
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
throw error2;
|
|
84
|
+
}
|
|
85
|
+
const parsed = text ? safeJson(text) : void 0;
|
|
86
|
+
if (response.ok) {
|
|
87
|
+
if (parsed === void 0 && text) throw new GhostPayError(`Invalid JSON from ${spec.method} ${spec.path} (HTTP ${response.status})`);
|
|
88
|
+
return withMeta(parsed, {
|
|
89
|
+
status: response.status,
|
|
90
|
+
headers: response.headers,
|
|
91
|
+
idempotentReplayed: response.headers.get("idempotent-replayed") === "true",
|
|
92
|
+
idempotencyKey
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
const error = toApiError(response, parsed, text);
|
|
96
|
+
if (attempt < maxRetries && retryable(error) && (spec.method === "GET" || spec.retryAfterSend !== false)) {
|
|
97
|
+
await sleep(retryAfterMs(response.headers) ?? backoff(attempt));
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
throw error;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/** Every item of a cursor-paginated list, fetching pages as needed. */
|
|
104
|
+
async *paginate(path, query, options) {
|
|
105
|
+
let after = query.after ?? void 0;
|
|
106
|
+
for (; ; ) {
|
|
107
|
+
const page = await this.request({ method: "GET", path, query: { ...query, after } }, options);
|
|
108
|
+
for (const item of page.data) yield item;
|
|
109
|
+
const last = page.data[page.data.length - 1];
|
|
110
|
+
if (!page.has_more || !last) return;
|
|
111
|
+
after = last.id;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
async send(url, init, timeoutMs, signal) {
|
|
115
|
+
const controller = new AbortController();
|
|
116
|
+
let timedOut = false;
|
|
117
|
+
const timer = setTimeout(() => {
|
|
118
|
+
timedOut = true;
|
|
119
|
+
controller.abort();
|
|
120
|
+
}, timeoutMs);
|
|
121
|
+
const onAbort = () => controller.abort(signal?.reason);
|
|
122
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
123
|
+
try {
|
|
124
|
+
const response = await this.fetchImpl(url, { ...init, signal: controller.signal });
|
|
125
|
+
return { response, text: await response.text() };
|
|
126
|
+
} catch (error) {
|
|
127
|
+
if (signal?.aborted) throw error;
|
|
128
|
+
if (timedOut) throw new GhostPayConnectionError(`Request timed out after ${timeoutMs} ms`, true, { cause: error });
|
|
129
|
+
throw new GhostPayConnectionError(`Could not reach GhostPay: ${error?.message ?? error}`, false, { cause: error });
|
|
130
|
+
} finally {
|
|
131
|
+
clearTimeout(timer);
|
|
132
|
+
signal?.removeEventListener("abort", onAbort);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
function listResult(http, path, query = {}, options) {
|
|
137
|
+
let pending;
|
|
138
|
+
const first = () => pending ??= http.request({ method: "GET", path, query }, options);
|
|
139
|
+
return {
|
|
140
|
+
then: (onFulfilled, onRejected) => first().then(onFulfilled, onRejected),
|
|
141
|
+
catch: (onRejected) => first().catch(onRejected),
|
|
142
|
+
finally: (onFinally) => first().finally(onFinally),
|
|
143
|
+
[Symbol.toStringTag]: "ListResult",
|
|
144
|
+
[Symbol.asyncIterator]: () => http.paginate(path, query, options)
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
function withMeta(value, meta) {
|
|
148
|
+
const target = value && typeof value === "object" ? value : {};
|
|
149
|
+
Object.defineProperty(target, "lastResponse", { value: meta, enumerable: false });
|
|
150
|
+
return target;
|
|
151
|
+
}
|
|
152
|
+
function toApiError(response, parsed, text) {
|
|
153
|
+
const envelope = parsed?.error;
|
|
154
|
+
const code = envelope?.code ?? (response.status >= 500 ? "api_error" : "invalid_request");
|
|
155
|
+
const message = envelope?.message ?? `HTTP ${response.status}${text ? `: ${text.slice(0, 200)}` : ""}`;
|
|
156
|
+
return new GhostPayApiError(response.status, code, message, envelope?.param, response.headers, parsed ?? text);
|
|
157
|
+
}
|
|
158
|
+
function retryable(error) {
|
|
159
|
+
if (error.status === 429 || error.status >= 500) return true;
|
|
160
|
+
return error.status === 409 && error.code === "conflict" && !error.param && /idempotency-key/i.test(error.message);
|
|
161
|
+
}
|
|
162
|
+
function isRefused(error) {
|
|
163
|
+
const cause = error.cause?.cause;
|
|
164
|
+
return cause?.code === "ECONNREFUSED" || cause?.code === "ENOTFOUND" || cause?.code === "EAI_AGAIN";
|
|
165
|
+
}
|
|
166
|
+
function backoff(attempt) {
|
|
167
|
+
const base = Math.min(RETRY_MAX_MS, RETRY_BASE_MS * 2 ** attempt);
|
|
168
|
+
return base / 2 + Math.random() * (base / 2);
|
|
169
|
+
}
|
|
170
|
+
function retryAfterMs(headers) {
|
|
171
|
+
const value = headers.get("retry-after");
|
|
172
|
+
if (!value) return void 0;
|
|
173
|
+
const seconds = Number(value);
|
|
174
|
+
if (Number.isFinite(seconds)) return Math.min(RETRY_MAX_MS * 4, Math.max(0, seconds * 1e3));
|
|
175
|
+
const date = Date.parse(value);
|
|
176
|
+
return Number.isFinite(date) ? Math.min(RETRY_MAX_MS * 4, Math.max(0, date - Date.now())) : void 0;
|
|
177
|
+
}
|
|
178
|
+
function queryString(query) {
|
|
179
|
+
if (!query) return "";
|
|
180
|
+
const params = new URLSearchParams();
|
|
181
|
+
for (const [key, value] of Object.entries(query)) if (value !== void 0 && value !== null) params.set(key, String(value));
|
|
182
|
+
const text = params.toString();
|
|
183
|
+
return text ? `?${text}` : "";
|
|
184
|
+
}
|
|
185
|
+
function safeJson(text) {
|
|
186
|
+
try {
|
|
187
|
+
return JSON.parse(text);
|
|
188
|
+
} catch {
|
|
189
|
+
return void 0;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
function sleep(ms) {
|
|
193
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// src/webhooks.ts
|
|
197
|
+
import { createHmac, timingSafeEqual } from "crypto";
|
|
198
|
+
var PREFIX = "whsec_";
|
|
199
|
+
var Webhook = class {
|
|
200
|
+
keys;
|
|
201
|
+
toleranceSec;
|
|
202
|
+
constructor(secret, options = {}) {
|
|
203
|
+
const secrets = Array.isArray(secret) ? secret : [secret];
|
|
204
|
+
if (secrets.length === 0 || secrets.some((value) => typeof value !== "string" || value.length === 0)) {
|
|
205
|
+
throw new WebhookVerificationError("A webhook signing secret (whsec_\u2026) is required");
|
|
206
|
+
}
|
|
207
|
+
this.keys = secrets.map(decodeSecret);
|
|
208
|
+
this.toleranceSec = options.toleranceSec ?? 300;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Checks the signature and timestamp and returns the parsed, typed event. `payload` must be the raw request body,
|
|
212
|
+
* exactly as received (e.g. `express.raw({ type: "application/json" })`), never re-serialized JSON.
|
|
213
|
+
*/
|
|
214
|
+
verify(payload, headers, now = /* @__PURE__ */ new Date()) {
|
|
215
|
+
const body = rawBody(payload);
|
|
216
|
+
const id = header(headers, "webhook-id");
|
|
217
|
+
const timestamp = header(headers, "webhook-timestamp");
|
|
218
|
+
const signatures = header(headers, "webhook-signature");
|
|
219
|
+
if (!id || !timestamp || !signatures) throw new WebhookVerificationError("Missing webhook-id, webhook-timestamp or webhook-signature header");
|
|
220
|
+
const seconds = Number(timestamp);
|
|
221
|
+
if (!/^\d+$/.test(timestamp) || !Number.isSafeInteger(seconds)) throw new WebhookVerificationError("Invalid webhook-timestamp");
|
|
222
|
+
const skew = Math.floor(now.getTime() / 1e3) - seconds;
|
|
223
|
+
if (skew > this.toleranceSec) throw new WebhookVerificationError("Webhook timestamp is too old");
|
|
224
|
+
if (skew < -this.toleranceSec) throw new WebhookVerificationError("Webhook timestamp is in the future");
|
|
225
|
+
const expected = this.keys.map((key) => sign(key, id, timestamp, body));
|
|
226
|
+
const valid = signatures.split(" ").some((entry) => {
|
|
227
|
+
const [version, signature] = entry.split(",", 2);
|
|
228
|
+
if (version !== "v1" || !signature) return false;
|
|
229
|
+
const given = Buffer.from(signature, "base64");
|
|
230
|
+
return expected.some((candidate) => given.length === candidate.length && timingSafeEqual(given, candidate));
|
|
231
|
+
});
|
|
232
|
+
if (!valid) throw new WebhookVerificationError("No matching webhook signature");
|
|
233
|
+
let event;
|
|
234
|
+
try {
|
|
235
|
+
event = JSON.parse(body.toString("utf8"));
|
|
236
|
+
} catch {
|
|
237
|
+
throw new WebhookVerificationError("Webhook body is not valid JSON");
|
|
238
|
+
}
|
|
239
|
+
if (!event || typeof event !== "object" || event.id !== id) throw new WebhookVerificationError("Webhook body id does not match webhook-id");
|
|
240
|
+
return event;
|
|
241
|
+
}
|
|
242
|
+
/** The `webhook-signature` header value for a body (for your own tests). */
|
|
243
|
+
sign(id, timestamp, payload) {
|
|
244
|
+
const seconds = String(typeof timestamp === "number" ? timestamp : Math.floor(timestamp.getTime() / 1e3));
|
|
245
|
+
return `v1,${sign(this.keys[0], id, seconds, rawBody(payload)).toString("base64")}`;
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
function sign(key, id, timestamp, body) {
|
|
249
|
+
return createHmac("sha256", key).update(`${id}.${timestamp}.`).update(body).digest();
|
|
250
|
+
}
|
|
251
|
+
function decodeSecret(secret) {
|
|
252
|
+
const key = Buffer.from(secret.startsWith(PREFIX) ? secret.slice(PREFIX.length) : secret, "base64");
|
|
253
|
+
if (key.length === 0) throw new WebhookVerificationError("Invalid webhook signing secret");
|
|
254
|
+
return key;
|
|
255
|
+
}
|
|
256
|
+
function rawBody(payload) {
|
|
257
|
+
if (typeof payload === "string") return Buffer.from(payload, "utf8");
|
|
258
|
+
if (payload instanceof Uint8Array) return Buffer.from(payload.buffer, payload.byteOffset, payload.byteLength);
|
|
259
|
+
throw new WebhookVerificationError(
|
|
260
|
+
"Pass the raw request body (string or Buffer), not parsed JSON: re-serializing changes the bytes and breaks the signature"
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
function header(headers, name) {
|
|
264
|
+
if (typeof headers.get === "function") return headers.get(name) ?? void 0;
|
|
265
|
+
const record = headers;
|
|
266
|
+
const key = Object.keys(record).find((candidate) => candidate.toLowerCase() === name);
|
|
267
|
+
const value = key === void 0 ? void 0 : record[key];
|
|
268
|
+
return Array.isArray(value) ? value.join(" ") : value;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// src/client.ts
|
|
272
|
+
var seg = (value) => encodeURIComponent(value);
|
|
273
|
+
var GhostPay = class {
|
|
274
|
+
networks;
|
|
275
|
+
currencies;
|
|
276
|
+
rates;
|
|
277
|
+
balances;
|
|
278
|
+
customers;
|
|
279
|
+
addresses;
|
|
280
|
+
deposits;
|
|
281
|
+
invoices;
|
|
282
|
+
withdrawals;
|
|
283
|
+
webhookEndpoints;
|
|
284
|
+
webhookDeliveries;
|
|
285
|
+
events;
|
|
286
|
+
transactions;
|
|
287
|
+
stats;
|
|
288
|
+
settings;
|
|
289
|
+
checkout;
|
|
290
|
+
webhooks;
|
|
291
|
+
constructor(options) {
|
|
292
|
+
const http = new HttpClient(options);
|
|
293
|
+
const get = (path, query, opts) => http.request({ method: "GET", path, query }, opts);
|
|
294
|
+
const post = (path, body, opts, extra) => http.request({ method: "POST", path, body, ...extra }, opts);
|
|
295
|
+
this.networks = {
|
|
296
|
+
/** Every network, with confirmations and whether deposits/withdrawals are on. */
|
|
297
|
+
list: (opts) => get("/v1/networks", void 0, opts)
|
|
298
|
+
};
|
|
299
|
+
this.currencies = {
|
|
300
|
+
/** Enabled currencies with your minimums and fees. */
|
|
301
|
+
list: (opts) => get("/v1/currencies", void 0, opts)
|
|
302
|
+
};
|
|
303
|
+
this.rates = {
|
|
304
|
+
/** Indicative USD price per currency. */
|
|
305
|
+
list: (opts) => get("/v1/rates", void 0, opts)
|
|
306
|
+
};
|
|
307
|
+
this.balances = {
|
|
308
|
+
/** Available, on-hold and pending balance per currency. */
|
|
309
|
+
list: (opts) => get("/v1/balances", void 0, opts)
|
|
310
|
+
};
|
|
311
|
+
this.customers = {
|
|
312
|
+
/** Create the customer, or update its metadata if `external_id` exists. */
|
|
313
|
+
upsert: (params, opts) => post("/v1/customers", params, opts),
|
|
314
|
+
list: (params = {}, opts) => listResult(http, "/v1/customers", params, opts),
|
|
315
|
+
/** By `cus_…` id or `ext:<external_id>`. */
|
|
316
|
+
get: (customer, opts) => get(`/v1/customers/${seg(customer)}`, void 0, opts),
|
|
317
|
+
getByExternalId: (externalId, opts) => get(`/v1/customers/${seg(`ext:${externalId}`)}`, void 0, opts)
|
|
318
|
+
};
|
|
319
|
+
this.addresses = {
|
|
320
|
+
/** The customer's permanent deposit address for the network's address scope (created on first call; `lastResponse.status` 201). */
|
|
321
|
+
getOrCreate: (params, opts) => post("/v1/addresses", params, opts),
|
|
322
|
+
list: (params = {}, opts) => listResult(http, "/v1/addresses", params, opts),
|
|
323
|
+
/** By `addr_…` id or the on-chain address. */
|
|
324
|
+
get: (address, opts) => get(`/v1/addresses/${seg(address)}`, void 0, opts),
|
|
325
|
+
/** Stop handing this address out; payments to it are still credited. */
|
|
326
|
+
retire: (address, opts) => post(`/v1/addresses/${seg(address)}/retire`, void 0, opts),
|
|
327
|
+
/** Your own addresses for funding your balance, one per address scope; credited with no fees. */
|
|
328
|
+
topUps: (opts) => get("/v1/top-up-addresses", void 0, opts)
|
|
329
|
+
};
|
|
330
|
+
this.deposits = {
|
|
331
|
+
list: (params = {}, opts) => listResult(http, "/v1/deposits", params, opts),
|
|
332
|
+
get: (id, opts) => get(`/v1/deposits/${seg(id)}`, void 0, opts)
|
|
333
|
+
};
|
|
334
|
+
this.invoices = {
|
|
335
|
+
create: (params, opts) => post("/v1/invoices", params, opts),
|
|
336
|
+
list: (params = {}, opts) => listResult(http, "/v1/invoices", params, opts),
|
|
337
|
+
get: (id, opts) => get(`/v1/invoices/${seg(id)}`, void 0, opts),
|
|
338
|
+
/** Only while `NEW`. */
|
|
339
|
+
cancel: (id, opts) => post(`/v1/invoices/${seg(id)}/cancel`, void 0, opts)
|
|
340
|
+
};
|
|
341
|
+
this.withdrawals = {
|
|
342
|
+
/** Fee, total and whether your balance covers it. Creates nothing. */
|
|
343
|
+
quote: (params, opts) => post("/v1/withdrawals/quote", params, opts),
|
|
344
|
+
/**
|
|
345
|
+
* Pays out from your balance. The Idempotency-Key defaults to `withdrawal:<external_id>` when you give an
|
|
346
|
+
* `external_id`, so retrying the same payout (even after a restart) can never pay twice.
|
|
347
|
+
*/
|
|
348
|
+
create: (params, opts = {}) => post("/v1/withdrawals", params, {
|
|
349
|
+
...opts,
|
|
350
|
+
...opts.idempotencyKey === void 0 && params.external_id ? { idempotencyKey: `withdrawal:${params.external_id}` } : {}
|
|
351
|
+
}),
|
|
352
|
+
list: (params = {}, opts) => listResult(http, "/v1/withdrawals", params, opts),
|
|
353
|
+
/** By `wd_…` id or your external id. */
|
|
354
|
+
get: (withdrawal, opts) => get(`/v1/withdrawals/${seg(withdrawal)}`, void 0, opts),
|
|
355
|
+
getByExternalId: (externalId, opts) => get(`/v1/withdrawals/${seg(`ext:${externalId}`)}`, void 0, opts),
|
|
356
|
+
/** Only before it is sent. The hold returns to your available balance. */
|
|
357
|
+
cancel: (withdrawal, opts) => post(`/v1/withdrawals/${seg(withdrawal)}/cancel`, void 0, opts)
|
|
358
|
+
};
|
|
359
|
+
this.webhookEndpoints = {
|
|
360
|
+
/** The response's `secret` is shown only once: store it. Not retried once sent (a retry would create a second endpoint). */
|
|
361
|
+
create: (params, opts) => post("/v1/webhook-endpoints", params, opts, { retryAfterSend: false }),
|
|
362
|
+
list: (params = {}, opts) => listResult(http, "/v1/webhook-endpoints", params, opts),
|
|
363
|
+
get: (id, opts) => get(`/v1/webhook-endpoints/${seg(id)}`, void 0, opts),
|
|
364
|
+
update: (id, params, opts) => http.request({ method: "PATCH", path: `/v1/webhook-endpoints/${seg(id)}`, body: params }, opts),
|
|
365
|
+
delete: (id, opts) => http.request({ method: "DELETE", path: `/v1/webhook-endpoints/${seg(id)}` }, opts),
|
|
366
|
+
/** Sends a `ping` event to this endpoint. */
|
|
367
|
+
test: (id, opts) => post(`/v1/webhook-endpoints/${seg(id)}/test`, void 0, opts),
|
|
368
|
+
/** Re-sends matching events created in `[from, to]` as new deliveries; events already queued for the endpoint are skipped. */
|
|
369
|
+
replay: (id, params, opts) => post(`/v1/webhook-endpoints/${seg(id)}/replay`, params, opts)
|
|
370
|
+
};
|
|
371
|
+
this.webhookDeliveries = {
|
|
372
|
+
list: (params = {}, opts) => listResult(http, "/v1/webhook-deliveries", params, opts),
|
|
373
|
+
/** With every attempt (status code, response body, timing). */
|
|
374
|
+
get: (id, opts) => get(`/v1/webhook-deliveries/${seg(id)}`, void 0, opts),
|
|
375
|
+
/** Re-sends a FAILED delivery's event as a new delivery (returned), retried per the endpoint's `auto_retry`. */
|
|
376
|
+
retry: (id, opts) => post(`/v1/webhook-deliveries/${seg(id)}/retry`, void 0, opts)
|
|
377
|
+
};
|
|
378
|
+
this.events = {
|
|
379
|
+
/** One page: newest first, or oldest first after `params.after`. */
|
|
380
|
+
list: (params = {}, opts) => get("/v1/events", params, opts),
|
|
381
|
+
get: (id, opts) => get(`/v1/events/${seg(id)}`, void 0, opts),
|
|
382
|
+
/**
|
|
383
|
+
* Every event after `after` (default: from the very first), oldest first, across pages. Store the last id you
|
|
384
|
+
* processed and pass it next time to catch up after downtime.
|
|
385
|
+
*/
|
|
386
|
+
since: (after = "evt_0", params = {}, opts) => http.paginate("/v1/events", { ...params, after }, opts)
|
|
387
|
+
};
|
|
388
|
+
this.transactions = {
|
|
389
|
+
/** Deposits, top-ups, withdrawals and payouts, newest first. */
|
|
390
|
+
list: (params = {}, opts) => listResult(http, "/v1/transactions", params, opts),
|
|
391
|
+
/** With the full deposit or withdrawal and every event about it, including webhook deliveries. */
|
|
392
|
+
get: (id, opts) => get(`/v1/transactions/${seg(id)}`, void 0, opts)
|
|
393
|
+
};
|
|
394
|
+
this.stats = {
|
|
395
|
+
/** Balances and daily volume in USD at current rates (default 30 days). */
|
|
396
|
+
get: (params = {}, opts) => get("/v1/stats", params, opts)
|
|
397
|
+
};
|
|
398
|
+
this.settings = {
|
|
399
|
+
get: (opts) => get("/v1/settings", void 0, opts)
|
|
400
|
+
};
|
|
401
|
+
this.checkout = {
|
|
402
|
+
/** Public: what a payer needs to pay an invoice (no API key needed). */
|
|
403
|
+
get: (invoiceId, opts) => http.request({ method: "GET", path: `/v1/checkout/${seg(invoiceId)}`, auth: false }, opts),
|
|
404
|
+
/** Public: choose the payment currency once, while the invoice is `NEW`. */
|
|
405
|
+
select: (invoiceId, params, opts) => post(`/v1/checkout/${seg(invoiceId)}/select`, params, opts, { auth: false })
|
|
406
|
+
};
|
|
407
|
+
this.webhooks = {
|
|
408
|
+
/** Verify a webhook request and return the typed event (see `Webhook.verify`). */
|
|
409
|
+
verify: (payload, headers, secret, options2) => new Webhook(secret, options2).verify(payload, headers)
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
};
|
|
413
|
+
export {
|
|
414
|
+
GhostPay,
|
|
415
|
+
GhostPayApiError,
|
|
416
|
+
GhostPayConnectionError,
|
|
417
|
+
GhostPayError,
|
|
418
|
+
VERSION,
|
|
419
|
+
Webhook,
|
|
420
|
+
WebhookVerificationError,
|
|
421
|
+
GhostPay as default
|
|
422
|
+
};
|
|
423
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/http.ts","../src/errors.ts","../src/version.ts","../src/webhooks.ts","../src/client.ts"],"sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { GhostPayApiError, GhostPayConnectionError, GhostPayError } from \"./errors.js\";\nimport type { ErrorCode, Page } from \"./types.js\";\nimport { VERSION } from \"./version.js\";\n\nexport interface GhostPayOptions {\n /** Secret API key (`gp_live_…`). Only the public checkout calls work without one. */\n apiKey?: string;\n /** API host. Default `https://api.ghostpay.gg`. */\n baseUrl?: string;\n /** Per-attempt timeout. Default 30 s. */\n timeoutMs?: number;\n /** Retries after a network error, timeout, 429 or 5xx (always with the same Idempotency-Key). Default 2. */\n maxRetries?: number;\n /** Custom fetch (proxies, tests). Default: global fetch. */\n fetch?: typeof fetch;\n /** Appended to the User-Agent, e.g. `my-casino/2.1`. */\n appInfo?: string;\n}\n\nexport interface RequestOptions {\n /** Idempotency-Key for this POST. Default: a random UUID, reused on every retry of this call. */\n idempotencyKey?: string;\n timeoutMs?: number;\n maxRetries?: number;\n signal?: AbortSignal;\n headers?: Record<string, string>;\n}\n\nexport interface ResponseMeta {\n status: number;\n headers: Headers;\n /** The API replayed a stored response for this Idempotency-Key. */\n idempotentReplayed: boolean;\n idempotencyKey: string | undefined;\n}\n\n/** A response object; `lastResponse` (not enumerable, not serialized) has status, headers and idempotency info. */\nexport type WithResponse<T> = T & { readonly lastResponse: ResponseMeta };\n\ntype Method = \"GET\" | \"POST\" | \"PATCH\" | \"DELETE\";\ntype Query = Record<string, string | number | boolean | undefined | null>;\n\nexport interface RequestSpec {\n method: Method;\n path: string;\n query?: Query | undefined;\n body?: unknown;\n /** Send the API key (false for public checkout calls). */\n auth?: boolean;\n /**\n * Retry a POST after the request may have reached the server. False for calls whose response is never stored for\n * idempotent replay (webhook endpoint creation returns a secret), where a retry would act twice.\n */\n retryAfterSend?: boolean;\n}\n\nconst RETRY_BASE_MS = 500;\nconst RETRY_MAX_MS = 8_000;\n\nconst DEFAULT_BASE_URL = \"https://api.ghostpay.gg\";\n\nexport class HttpClient {\n private readonly baseUrl: string;\n private readonly fetchImpl: typeof fetch;\n private readonly userAgent: string;\n\n constructor(private readonly options: GhostPayOptions) {\n this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/+$/, \"\");\n this.fetchImpl = options.fetch ?? globalThis.fetch;\n if (!this.fetchImpl) throw new GhostPayError(\"No fetch available: use Node 18+ or pass options.fetch\");\n this.userAgent = `ghostpay-node/${VERSION} node/${process.versions.node}${options.appInfo ? ` ${options.appInfo}` : \"\"}`;\n }\n\n async request<T>(spec: RequestSpec, options: RequestOptions = {}): Promise<WithResponse<T>> {\n const auth = spec.auth ?? true;\n if (auth && !this.options.apiKey) throw new GhostPayError(\"This call needs an API key: new GhostPay({ apiKey, baseUrl })\");\n\n const url = this.baseUrl + spec.path + queryString(spec.query);\n const idempotencyKey = spec.method === \"POST\" ? (options.idempotencyKey ?? randomUUID()) : undefined;\n const headers: Record<string, string> = {\n accept: \"application/json\",\n \"user-agent\": this.userAgent,\n ...(auth ? { authorization: `Bearer ${this.options.apiKey}` } : {}),\n ...(idempotencyKey ? { \"idempotency-key\": idempotencyKey } : {}),\n ...(spec.body !== undefined ? { \"content-type\": \"application/json\" } : {}),\n ...options.headers,\n };\n const body = spec.body !== undefined ? JSON.stringify(spec.body) : undefined;\n const maxRetries = options.maxRetries ?? this.options.maxRetries ?? 2;\n const timeoutMs = options.timeoutMs ?? this.options.timeoutMs ?? 30_000;\n\n for (let attempt = 0; ; attempt++) {\n let response: Response;\n let text: string;\n try {\n ({ response, text } = await this.send(url, { method: spec.method, headers, ...(body !== undefined ? { body } : {}) }, timeoutMs, options.signal));\n } catch (error) {\n if (options.signal?.aborted) throw error;\n const sent = !(error instanceof GhostPayConnectionError && isRefused(error));\n if (attempt < maxRetries && (spec.method === \"GET\" || !sent || spec.retryAfterSend !== false)) {\n await sleep(backoff(attempt));\n continue;\n }\n throw error;\n }\n\n const parsed = text ? safeJson(text) : undefined;\n if (response.ok) {\n if (parsed === undefined && text) throw new GhostPayError(`Invalid JSON from ${spec.method} ${spec.path} (HTTP ${response.status})`);\n return withMeta(parsed as T, {\n status: response.status,\n headers: response.headers,\n idempotentReplayed: response.headers.get(\"idempotent-replayed\") === \"true\",\n idempotencyKey,\n });\n }\n\n const error = toApiError(response, parsed, text);\n if (attempt < maxRetries && retryable(error) && (spec.method === \"GET\" || spec.retryAfterSend !== false)) {\n await sleep(retryAfterMs(response.headers) ?? backoff(attempt));\n continue;\n }\n throw error;\n }\n }\n\n /** Every item of a cursor-paginated list, fetching pages as needed. */\n async *paginate<T extends { id: string }>(path: string, query: Query, options?: RequestOptions): AsyncGenerator<T> {\n let after = query.after ?? undefined;\n for (;;) {\n const page = await this.request<Page<T>>({ method: \"GET\", path, query: { ...query, after } }, options);\n for (const item of page.data) yield item;\n const last = page.data[page.data.length - 1];\n if (!page.has_more || !last) return;\n after = last.id;\n }\n }\n\n private async send(url: string, init: RequestInit, timeoutMs: number, signal?: AbortSignal): Promise<{ response: Response; text: string }> {\n const controller = new AbortController();\n let timedOut = false;\n const timer = setTimeout(() => {\n timedOut = true;\n controller.abort();\n }, timeoutMs);\n const onAbort = () => controller.abort(signal?.reason);\n signal?.addEventListener(\"abort\", onAbort, { once: true });\n try {\n const response = await this.fetchImpl(url, { ...init, signal: controller.signal });\n return { response, text: await response.text() };\n } catch (error) {\n if (signal?.aborted) throw error;\n if (timedOut) throw new GhostPayConnectionError(`Request timed out after ${timeoutMs} ms`, true, { cause: error });\n throw new GhostPayConnectionError(`Could not reach GhostPay: ${(error as Error)?.message ?? error}`, false, { cause: error });\n } finally {\n clearTimeout(timer);\n signal?.removeEventListener(\"abort\", onAbort);\n }\n }\n}\n\n/** A list call: await it for one page, or `for await` it to walk every item across pages. */\nexport type ListResult<T> = Promise<WithResponse<Page<T>>> & AsyncIterable<T>;\n\nexport function listResult<T extends { id: string }>(http: HttpClient, path: string, query: Query = {}, options?: RequestOptions): ListResult<T> {\n let pending: Promise<WithResponse<Page<T>>> | undefined;\n const first = () => (pending ??= http.request<Page<T>>({ method: \"GET\", path, query }, options));\n return {\n then: (onFulfilled, onRejected) => first().then(onFulfilled, onRejected),\n catch: (onRejected) => first().catch(onRejected),\n finally: (onFinally) => first().finally(onFinally),\n [Symbol.toStringTag]: \"ListResult\",\n [Symbol.asyncIterator]: () => http.paginate<T>(path, query, options),\n } as ListResult<T>;\n}\n\nfunction withMeta<T>(value: T, meta: ResponseMeta): WithResponse<T> {\n const target = (value && typeof value === \"object\" ? value : {}) as object;\n Object.defineProperty(target, \"lastResponse\", { value: meta, enumerable: false });\n return target as WithResponse<T>;\n}\n\nfunction toApiError(response: Response, parsed: unknown, text: string): GhostPayApiError {\n const envelope = (parsed as { error?: { code?: string; message?: string; param?: string } } | undefined)?.error;\n const code = (envelope?.code ?? (response.status >= 500 ? \"api_error\" : \"invalid_request\")) as ErrorCode;\n const message = envelope?.message ?? `HTTP ${response.status}${text ? `: ${text.slice(0, 200)}` : \"\"}`;\n return new GhostPayApiError(response.status, code, message, envelope?.param, response.headers, parsed ?? text);\n}\n\nfunction retryable(error: GhostPayApiError): boolean {\n if (error.status === 429 || error.status >= 500) return true;\n // The same Idempotency-Key is still running on the server: its result will be replayed shortly.\n return error.status === 409 && error.code === \"conflict\" && !error.param && /idempotency-key/i.test(error.message);\n}\n\nfunction isRefused(error: GhostPayConnectionError): boolean {\n const cause = (error.cause as { cause?: { code?: string } } | undefined)?.cause;\n return cause?.code === \"ECONNREFUSED\" || cause?.code === \"ENOTFOUND\" || cause?.code === \"EAI_AGAIN\";\n}\n\nfunction backoff(attempt: number): number {\n const base = Math.min(RETRY_MAX_MS, RETRY_BASE_MS * 2 ** attempt);\n return base / 2 + Math.random() * (base / 2);\n}\n\nfunction retryAfterMs(headers: Headers): number | undefined {\n const value = headers.get(\"retry-after\");\n if (!value) return undefined;\n const seconds = Number(value);\n if (Number.isFinite(seconds)) return Math.min(RETRY_MAX_MS * 4, Math.max(0, seconds * 1000));\n const date = Date.parse(value);\n return Number.isFinite(date) ? Math.min(RETRY_MAX_MS * 4, Math.max(0, date - Date.now())) : undefined;\n}\n\nfunction queryString(query: Query | undefined): string {\n if (!query) return \"\";\n const params = new URLSearchParams();\n for (const [key, value] of Object.entries(query)) if (value !== undefined && value !== null) params.set(key, String(value));\n const text = params.toString();\n return text ? `?${text}` : \"\";\n}\n\nfunction safeJson(text: string): unknown {\n try {\n return JSON.parse(text);\n } catch {\n return undefined;\n }\n}\n\nfunction sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n","import type { ErrorCode } from \"./types.js\";\n\n/** Base class of every error this SDK throws. */\nexport class GhostPayError extends Error {\n override name = \"GhostPayError\";\n}\n\n/** The API answered with an error envelope. Switch on `code`; it is stable. */\nexport class GhostPayApiError extends GhostPayError {\n override name = \"GhostPayApiError\";\n readonly status: number;\n readonly code: ErrorCode;\n readonly param: string | undefined;\n readonly headers: Headers;\n readonly raw: unknown;\n\n constructor(status: number, code: ErrorCode, message: string, param: string | undefined, headers: Headers, raw: unknown) {\n super(message);\n this.status = status;\n this.code = code;\n this.param = param;\n this.headers = headers;\n this.raw = raw;\n }\n}\n\n/** No response: DNS, connection refused/reset, or the request timed out. Safe to retry with the same Idempotency-Key. */\nexport class GhostPayConnectionError extends GhostPayError {\n override name = \"GhostPayConnectionError\";\n readonly timedOut: boolean;\n constructor(message: string, timedOut: boolean, options?: { cause?: unknown }) {\n super(message, options);\n this.timedOut = timedOut;\n }\n}\n\n/** A webhook request failed signature or timestamp checks. Reply 400 and do not process it. */\nexport class WebhookVerificationError extends GhostPayError {\n override name = \"WebhookVerificationError\";\n}\n","export const VERSION = \"1.1.0\";\n","import { createHmac, timingSafeEqual } from \"node:crypto\";\nimport { WebhookVerificationError } from \"./errors.js\";\nimport type { WebhookEvent } from \"./types.js\";\n\nexport type WebhookHeaders = Headers | Record<string, string | string[] | undefined>;\nexport type WebhookPayload = string | Uint8Array;\n\nexport interface WebhookOptions {\n /** Accepted clock difference in seconds, both ways. Default 300 (5 minutes). */\n toleranceSec?: number;\n}\n\nconst PREFIX = \"whsec_\";\n\n/**\n * Verifies GhostPay webhook requests (Standard Webhooks: HMAC-SHA256 over `{webhook-id}.{webhook-timestamp}.{body}`).\n * Pass several secrets while rotating an endpoint's secret.\n */\nexport class Webhook {\n private readonly keys: Buffer[];\n private readonly toleranceSec: number;\n\n constructor(secret: string | string[], options: WebhookOptions = {}) {\n const secrets = Array.isArray(secret) ? secret : [secret];\n if (secrets.length === 0 || secrets.some((value) => typeof value !== \"string\" || value.length === 0)) {\n throw new WebhookVerificationError(\"A webhook signing secret (whsec_…) is required\");\n }\n this.keys = secrets.map(decodeSecret);\n this.toleranceSec = options.toleranceSec ?? 300;\n }\n\n /**\n * Checks the signature and timestamp and returns the parsed, typed event. `payload` must be the raw request body,\n * exactly as received (e.g. `express.raw({ type: \"application/json\" })`), never re-serialized JSON.\n */\n verify(payload: WebhookPayload, headers: WebhookHeaders, now: Date = new Date()): WebhookEvent {\n const body = rawBody(payload);\n const id = header(headers, \"webhook-id\");\n const timestamp = header(headers, \"webhook-timestamp\");\n const signatures = header(headers, \"webhook-signature\");\n if (!id || !timestamp || !signatures) throw new WebhookVerificationError(\"Missing webhook-id, webhook-timestamp or webhook-signature header\");\n\n const seconds = Number(timestamp);\n if (!/^\\d+$/.test(timestamp) || !Number.isSafeInteger(seconds)) throw new WebhookVerificationError(\"Invalid webhook-timestamp\");\n const skew = Math.floor(now.getTime() / 1000) - seconds;\n if (skew > this.toleranceSec) throw new WebhookVerificationError(\"Webhook timestamp is too old\");\n if (skew < -this.toleranceSec) throw new WebhookVerificationError(\"Webhook timestamp is in the future\");\n\n const expected = this.keys.map((key) => sign(key, id, timestamp, body));\n const valid = signatures.split(\" \").some((entry) => {\n const [version, signature] = entry.split(\",\", 2);\n if (version !== \"v1\" || !signature) return false;\n const given = Buffer.from(signature, \"base64\");\n return expected.some((candidate) => given.length === candidate.length && timingSafeEqual(given, candidate));\n });\n if (!valid) throw new WebhookVerificationError(\"No matching webhook signature\");\n\n let event: WebhookEvent;\n try {\n event = JSON.parse(body.toString(\"utf8\")) as WebhookEvent;\n } catch {\n throw new WebhookVerificationError(\"Webhook body is not valid JSON\");\n }\n if (!event || typeof event !== \"object\" || event.id !== id) throw new WebhookVerificationError(\"Webhook body id does not match webhook-id\");\n return event;\n }\n\n /** The `webhook-signature` header value for a body (for your own tests). */\n sign(id: string, timestamp: number | Date, payload: WebhookPayload): string {\n const seconds = String(typeof timestamp === \"number\" ? timestamp : Math.floor(timestamp.getTime() / 1000));\n return `v1,${sign(this.keys[0]!, id, seconds, rawBody(payload)).toString(\"base64\")}`;\n }\n}\n\nfunction sign(key: Buffer, id: string, timestamp: string, body: Buffer): Buffer {\n return createHmac(\"sha256\", key).update(`${id}.${timestamp}.`).update(body).digest();\n}\n\nfunction decodeSecret(secret: string): Buffer {\n const key = Buffer.from(secret.startsWith(PREFIX) ? secret.slice(PREFIX.length) : secret, \"base64\");\n if (key.length === 0) throw new WebhookVerificationError(\"Invalid webhook signing secret\");\n return key;\n}\n\nfunction rawBody(payload: WebhookPayload): Buffer {\n if (typeof payload === \"string\") return Buffer.from(payload, \"utf8\");\n if (payload instanceof Uint8Array) return Buffer.from(payload.buffer, payload.byteOffset, payload.byteLength);\n throw new WebhookVerificationError(\n \"Pass the raw request body (string or Buffer), not parsed JSON: re-serializing changes the bytes and breaks the signature\",\n );\n}\n\nfunction header(headers: WebhookHeaders, name: string): string | undefined {\n if (typeof (headers as Headers).get === \"function\") return (headers as Headers).get(name) ?? undefined;\n const record = headers as Record<string, string | string[] | undefined>;\n const key = Object.keys(record).find((candidate) => candidate.toLowerCase() === name);\n const value = key === undefined ? undefined : record[key];\n return Array.isArray(value) ? value.join(\" \") : value;\n}\n","import { HttpClient, listResult, type GhostPayOptions, type ListResult, type RequestOptions } from \"./http.js\";\nimport type {\n Address,\n AddressCreateParams,\n AddressListParams,\n Balance,\n Checkout,\n CheckoutSelectParams,\n Currency,\n Customer,\n CustomerListParams,\n CustomerUpsertParams,\n Deposit,\n DepositListParams,\n Event,\n EventListParams,\n Invoice,\n InvoiceCreateParams,\n InvoiceListParams,\n Network,\n Page,\n Rate,\n Settings,\n Stats,\n StatsParams,\n Transaction,\n TransactionDetail,\n TransactionListParams,\n WebhookDelivery,\n WebhookDeliveryListParams,\n WebhookDeliveryWithAttempts,\n WebhookEndpoint,\n WebhookEndpointCreateParams,\n WebhookEndpointListParams,\n WebhookEndpointUpdateParams,\n WebhookEndpointWithSecret,\n WebhookReplayParams,\n Withdrawal,\n WithdrawalCreateParams,\n WithdrawalListParams,\n WithdrawalQuote,\n WithdrawalQuoteParams,\n} from \"./types.js\";\nimport { Webhook, type WebhookHeaders, type WebhookOptions, type WebhookPayload } from \"./webhooks.js\";\n\nconst seg = (value: string) => encodeURIComponent(value);\ntype Q = Record<string, string | number | boolean | undefined | null>;\n\nexport class GhostPay {\n readonly networks;\n readonly currencies;\n readonly rates;\n readonly balances;\n readonly customers;\n readonly addresses;\n readonly deposits;\n readonly invoices;\n readonly withdrawals;\n readonly webhookEndpoints;\n readonly webhookDeliveries;\n readonly events;\n readonly transactions;\n readonly stats;\n readonly settings;\n readonly checkout;\n readonly webhooks;\n\n constructor(options: GhostPayOptions) {\n const http = new HttpClient(options);\n const get = <T>(path: string, query?: Q, opts?: RequestOptions) => http.request<T>({ method: \"GET\", path, query }, opts);\n const post = <T>(path: string, body?: unknown, opts?: RequestOptions, extra?: { auth?: boolean; retryAfterSend?: boolean }) =>\n http.request<T>({ method: \"POST\", path, body, ...extra }, opts);\n\n this.networks = {\n /** Every network, with confirmations and whether deposits/withdrawals are on. */\n list: (opts?: RequestOptions) => get<Page<Network>>(\"/v1/networks\", undefined, opts),\n };\n this.currencies = {\n /** Enabled currencies with your minimums and fees. */\n list: (opts?: RequestOptions) => get<Page<Currency>>(\"/v1/currencies\", undefined, opts),\n };\n this.rates = {\n /** Indicative USD price per currency. */\n list: (opts?: RequestOptions) => get<Page<Rate>>(\"/v1/rates\", undefined, opts),\n };\n this.balances = {\n /** Available, on-hold and pending balance per currency. */\n list: (opts?: RequestOptions) => get<Page<Balance>>(\"/v1/balances\", undefined, opts),\n };\n\n this.customers = {\n /** Create the customer, or update its metadata if `external_id` exists. */\n upsert: (params: CustomerUpsertParams, opts?: RequestOptions) => post<Customer>(\"/v1/customers\", params, opts),\n list: (params: CustomerListParams = {}, opts?: RequestOptions): ListResult<Customer> => listResult(http, \"/v1/customers\", params, opts),\n /** By `cus_…` id or `ext:<external_id>`. */\n get: (customer: string, opts?: RequestOptions) => get<Customer>(`/v1/customers/${seg(customer)}`, undefined, opts),\n getByExternalId: (externalId: string, opts?: RequestOptions) => get<Customer>(`/v1/customers/${seg(`ext:${externalId}`)}`, undefined, opts),\n };\n\n this.addresses = {\n /** The customer's permanent deposit address for the network's address scope (created on first call; `lastResponse.status` 201). */\n getOrCreate: (params: AddressCreateParams, opts?: RequestOptions) => post<Address>(\"/v1/addresses\", params, opts),\n list: (params: AddressListParams = {}, opts?: RequestOptions): ListResult<Address> => listResult(http, \"/v1/addresses\", params, opts),\n /** By `addr_…` id or the on-chain address. */\n get: (address: string, opts?: RequestOptions) => get<Address>(`/v1/addresses/${seg(address)}`, undefined, opts),\n /** Stop handing this address out; payments to it are still credited. */\n retire: (address: string, opts?: RequestOptions) => post<Address>(`/v1/addresses/${seg(address)}/retire`, undefined, opts),\n /** Your own addresses for funding your balance, one per address scope; credited with no fees. */\n topUps: (opts?: RequestOptions) => get<{ data: Address[] }>(\"/v1/top-up-addresses\", undefined, opts),\n };\n\n this.deposits = {\n list: (params: DepositListParams = {}, opts?: RequestOptions): ListResult<Deposit> => listResult(http, \"/v1/deposits\", params, opts),\n get: (id: string, opts?: RequestOptions) => get<Deposit>(`/v1/deposits/${seg(id)}`, undefined, opts),\n };\n\n this.invoices = {\n create: (params: InvoiceCreateParams, opts?: RequestOptions) => post<Invoice>(\"/v1/invoices\", params, opts),\n list: (params: InvoiceListParams = {}, opts?: RequestOptions): ListResult<Invoice> => listResult(http, \"/v1/invoices\", params, opts),\n get: (id: string, opts?: RequestOptions) => get<Invoice>(`/v1/invoices/${seg(id)}`, undefined, opts),\n /** Only while `NEW`. */\n cancel: (id: string, opts?: RequestOptions) => post<Invoice>(`/v1/invoices/${seg(id)}/cancel`, undefined, opts),\n };\n\n this.withdrawals = {\n /** Fee, total and whether your balance covers it. Creates nothing. */\n quote: (params: WithdrawalQuoteParams, opts?: RequestOptions) =>\n post<WithdrawalQuote>(\"/v1/withdrawals/quote\", params, opts),\n /**\n * Pays out from your balance. The Idempotency-Key defaults to `withdrawal:<external_id>` when you give an\n * `external_id`, so retrying the same payout (even after a restart) can never pay twice.\n */\n create: (params: WithdrawalCreateParams, opts: RequestOptions = {}) =>\n post<Withdrawal>(\"/v1/withdrawals\", params, {\n ...opts,\n ...(opts.idempotencyKey === undefined && params.external_id ? { idempotencyKey: `withdrawal:${params.external_id}` } : {}),\n }),\n list: (params: WithdrawalListParams = {}, opts?: RequestOptions): ListResult<Withdrawal> => listResult(http, \"/v1/withdrawals\", params, opts),\n /** By `wd_…` id or your external id. */\n get: (withdrawal: string, opts?: RequestOptions) => get<Withdrawal>(`/v1/withdrawals/${seg(withdrawal)}`, undefined, opts),\n getByExternalId: (externalId: string, opts?: RequestOptions) => get<Withdrawal>(`/v1/withdrawals/${seg(`ext:${externalId}`)}`, undefined, opts),\n /** Only before it is sent. The hold returns to your available balance. */\n cancel: (withdrawal: string, opts?: RequestOptions) => post<Withdrawal>(`/v1/withdrawals/${seg(withdrawal)}/cancel`, undefined, opts),\n };\n\n this.webhookEndpoints = {\n /** The response's `secret` is shown only once: store it. Not retried once sent (a retry would create a second endpoint). */\n create: (params: WebhookEndpointCreateParams, opts?: RequestOptions) =>\n post<WebhookEndpointWithSecret>(\"/v1/webhook-endpoints\", params, opts, { retryAfterSend: false }),\n list: (params: WebhookEndpointListParams = {}, opts?: RequestOptions): ListResult<WebhookEndpoint> =>\n listResult(http, \"/v1/webhook-endpoints\", params, opts),\n get: (id: string, opts?: RequestOptions) => get<WebhookEndpoint>(`/v1/webhook-endpoints/${seg(id)}`, undefined, opts),\n update: (id: string, params: WebhookEndpointUpdateParams, opts?: RequestOptions) =>\n http.request<WebhookEndpoint>({ method: \"PATCH\", path: `/v1/webhook-endpoints/${seg(id)}`, body: params }, opts),\n delete: (id: string, opts?: RequestOptions) =>\n http.request<{ id: string; object: \"webhook_endpoint\"; deleted: true }>({ method: \"DELETE\", path: `/v1/webhook-endpoints/${seg(id)}` }, opts),\n /** Sends a `ping` event to this endpoint. */\n test: (id: string, opts?: RequestOptions) =>\n post<{ event: Event; delivery: WebhookDelivery }>(`/v1/webhook-endpoints/${seg(id)}/test`, undefined, opts),\n /** Re-sends matching events created in `[from, to]` as new deliveries; events already queued for the endpoint are skipped. */\n replay: (id: string, params: WebhookReplayParams, opts?: RequestOptions) =>\n post<{ queued: number }>(`/v1/webhook-endpoints/${seg(id)}/replay`, params, opts),\n };\n\n this.webhookDeliveries = {\n list: (params: WebhookDeliveryListParams = {}, opts?: RequestOptions): ListResult<WebhookDelivery> =>\n listResult(http, \"/v1/webhook-deliveries\", params, opts),\n /** With every attempt (status code, response body, timing). */\n get: (id: string, opts?: RequestOptions) => get<WebhookDeliveryWithAttempts>(`/v1/webhook-deliveries/${seg(id)}`, undefined, opts),\n /** Re-sends a FAILED delivery's event as a new delivery (returned), retried per the endpoint's `auto_retry`. */\n retry: (id: string, opts?: RequestOptions) => post<WebhookDelivery>(`/v1/webhook-deliveries/${seg(id)}/retry`, undefined, opts),\n };\n\n this.events = {\n /** One page: newest first, or oldest first after `params.after`. */\n list: (params: EventListParams = {}, opts?: RequestOptions) => get<Page<Event>>(\"/v1/events\", params, opts),\n get: (id: string, opts?: RequestOptions) => get<Event>(`/v1/events/${seg(id)}`, undefined, opts),\n /**\n * Every event after `after` (default: from the very first), oldest first, across pages. Store the last id you\n * processed and pass it next time to catch up after downtime.\n */\n since: (after = \"evt_0\", params: Omit<EventListParams, \"after\"> = {}, opts?: RequestOptions): AsyncIterable<Event> =>\n http.paginate<Event>(\"/v1/events\", { ...params, after }, opts),\n };\n\n this.transactions = {\n /** Deposits, top-ups, withdrawals and payouts, newest first. */\n list: (params: TransactionListParams = {}, opts?: RequestOptions): ListResult<Transaction> => listResult(http, \"/v1/transactions\", params, opts),\n /** With the full deposit or withdrawal and every event about it, including webhook deliveries. */\n get: (id: string, opts?: RequestOptions) => get<TransactionDetail>(`/v1/transactions/${seg(id)}`, undefined, opts),\n };\n\n this.stats = {\n /** Balances and daily volume in USD at current rates (default 30 days). */\n get: (params: StatsParams = {}, opts?: RequestOptions) => get<Stats>(\"/v1/stats\", params, opts),\n };\n\n this.settings = {\n get: (opts?: RequestOptions) => get<Settings>(\"/v1/settings\", undefined, opts),\n };\n\n this.checkout = {\n /** Public: what a payer needs to pay an invoice (no API key needed). */\n get: (invoiceId: string, opts?: RequestOptions) => http.request<Checkout>({ method: \"GET\", path: `/v1/checkout/${seg(invoiceId)}`, auth: false }, opts),\n /** Public: choose the payment currency once, while the invoice is `NEW`. */\n select: (invoiceId: string, params: CheckoutSelectParams, opts?: RequestOptions) =>\n post<Checkout>(`/v1/checkout/${seg(invoiceId)}/select`, params, opts, { auth: false }),\n };\n\n this.webhooks = {\n /** Verify a webhook request and return the typed event (see `Webhook.verify`). */\n verify: (payload: WebhookPayload, headers: WebhookHeaders, secret: string | string[], options?: WebhookOptions) =>\n new Webhook(secret, options).verify(payload, headers),\n };\n }\n}\n"],"mappings":";AAAA,SAAS,kBAAkB;;;ACGpB,IAAM,gBAAN,cAA4B,MAAM;AAAA,EAC9B,OAAO;AAClB;AAGO,IAAM,mBAAN,cAA+B,cAAc;AAAA,EACzC,OAAO;AAAA,EACP;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAET,YAAY,QAAgB,MAAiB,SAAiB,OAA2B,SAAkB,KAAc;AACvH,UAAM,OAAO;AACb,SAAK,SAAS;AACd,SAAK,OAAO;AACZ,SAAK,QAAQ;AACb,SAAK,UAAU;AACf,SAAK,MAAM;AAAA,EACb;AACF;AAGO,IAAM,0BAAN,cAAsC,cAAc;AAAA,EAChD,OAAO;AAAA,EACP;AAAA,EACT,YAAY,SAAiB,UAAmB,SAA+B;AAC7E,UAAM,SAAS,OAAO;AACtB,SAAK,WAAW;AAAA,EAClB;AACF;AAG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AI;AAAA,IAChG;AAEA,SAAK,WAAW;AAAA,MACd,KAAK,CAAC,SAA0B,IAAc,gBAAgB,QAAW,IAAI;AAAA,IAC/E;AAEA,SAAK,WAAW;AAAA;AAAA,MAEd,KAAK,CAAC,WAAmB,SAA0B,KAAK,QAAkB,EAAE,QAAQ,OAAO,MAAM,gBAAgB,IAAI,SAAS,CAAC,IAAI,MAAM,MAAM,GAAG,IAAI;AAAA;AAAA,MAEtJ,QAAQ,CAAC,WAAmB,QAA8B,SACxD,KAAe,gBAAgB,IAAI,SAAS,CAAC,WAAW,QAAQ,MAAM,EAAE,MAAM,MAAM,CAAC;AAAA,IACzF;AAEA,SAAK,WAAW;AAAA;AAAA,MAEd,QAAQ,CAAC,SAAyB,SAAyB,QAA2BC,aACpF,IAAI,QAAQ,QAAQA,QAAO,EAAE,OAAO,SAAS,OAAO;AAAA,IACxD;AAAA,EACF;AACF;","names":["error","options"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ghostpaygg/node",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Official Node.js client for the GhostPay crypto payments API",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"engines": { "node": ">=18" },
|
|
8
|
+
"main": "./dist/index.cjs",
|
|
9
|
+
"module": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"import": { "types": "./dist/index.d.ts", "default": "./dist/index.js" },
|
|
14
|
+
"require": { "types": "./dist/index.d.cts", "default": "./dist/index.cjs" }
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": ["dist", "README.md", "CHANGELOG.md"],
|
|
18
|
+
"sideEffects": false,
|
|
19
|
+
"keywords": ["ghostpay", "crypto", "payments", "bitcoin", "ethereum", "solana", "usdt", "webhooks"],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"generate": "openapi-typescript ../../docs/openapi.yaml -o src/generated/openapi.ts",
|
|
22
|
+
"build": "tsup",
|
|
23
|
+
"typecheck": "tsc --noEmit",
|
|
24
|
+
"test": "tsx --test test/*.test.ts",
|
|
25
|
+
"test:e2e": "tsx --test test/e2e/*.test.ts",
|
|
26
|
+
"test:contract": "pnpm --dir ../.. run test:db && tsx --test test/contract/*.test.ts",
|
|
27
|
+
"prepublishOnly": "pnpm run generate && pnpm run typecheck && pnpm run test && pnpm run build"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/node": "^24.13.6",
|
|
31
|
+
"ajv": "^8.20.0",
|
|
32
|
+
"ajv-formats": "^3.0.1",
|
|
33
|
+
"openapi-typescript": "^7.13.0",
|
|
34
|
+
"standardwebhooks": "1.0.0",
|
|
35
|
+
"tsup": "^8.5.0",
|
|
36
|
+
"tsx": "^4.23.13",
|
|
37
|
+
"typescript": "~5.9.3",
|
|
38
|
+
"yaml": "^2.9.1"
|
|
39
|
+
}
|
|
40
|
+
}
|