puntersedge 0.1.0 → 1.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.
Files changed (55) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +289 -37
  3. package/dist/cjs/client.js +502 -0
  4. package/dist/cjs/client.js.map +1 -0
  5. package/dist/cjs/credits.js +82 -0
  6. package/dist/cjs/credits.js.map +1 -0
  7. package/dist/cjs/errors.js +130 -0
  8. package/dist/cjs/errors.js.map +1 -0
  9. package/dist/cjs/http.js +218 -0
  10. package/dist/cjs/http.js.map +1 -0
  11. package/dist/cjs/index.js +58 -0
  12. package/dist/cjs/index.js.map +1 -0
  13. package/dist/cjs/package.json +3 -0
  14. package/dist/cjs/types.generated.js +13 -0
  15. package/dist/cjs/types.generated.js.map +1 -0
  16. package/dist/cjs/webhook.js +95 -0
  17. package/dist/cjs/webhook.js.map +1 -0
  18. package/dist/esm/client.d.ts +495 -0
  19. package/dist/esm/client.d.ts.map +1 -0
  20. package/dist/esm/client.js +498 -0
  21. package/dist/esm/client.js.map +1 -0
  22. package/dist/esm/credits.d.ts +78 -0
  23. package/dist/esm/credits.d.ts.map +1 -0
  24. package/dist/esm/credits.js +78 -0
  25. package/dist/esm/credits.js.map +1 -0
  26. package/dist/esm/errors.d.ts +132 -0
  27. package/dist/esm/errors.d.ts.map +1 -0
  28. package/dist/esm/errors.js +117 -0
  29. package/dist/esm/errors.js.map +1 -0
  30. package/dist/esm/http.d.ts +52 -0
  31. package/dist/esm/http.d.ts.map +1 -0
  32. package/dist/esm/http.js +214 -0
  33. package/dist/esm/http.js.map +1 -0
  34. package/dist/esm/index.d.ts +22 -0
  35. package/dist/esm/index.d.ts.map +1 -0
  36. package/dist/esm/index.js +23 -0
  37. package/dist/esm/index.js.map +1 -0
  38. package/dist/esm/types.generated.d.ts +1453 -0
  39. package/dist/esm/types.generated.d.ts.map +1 -0
  40. package/dist/esm/types.generated.js +12 -0
  41. package/dist/esm/types.generated.js.map +1 -0
  42. package/dist/esm/webhook.d.ts +56 -0
  43. package/dist/esm/webhook.d.ts.map +1 -0
  44. package/dist/esm/webhook.js +92 -0
  45. package/dist/esm/webhook.js.map +1 -0
  46. package/package.json +52 -19
  47. package/src/client.ts +814 -0
  48. package/src/credits.ts +131 -0
  49. package/src/errors.ts +166 -0
  50. package/src/http.ts +268 -0
  51. package/src/index.ts +68 -206
  52. package/src/types.generated.ts +1514 -0
  53. package/src/webhook.ts +113 -0
  54. package/dist/index.d.ts +0 -117
  55. package/dist/index.js +0 -99
@@ -0,0 +1,502 @@
1
+ "use strict";
2
+ /**
3
+ * The PuntersEdge client.
4
+ *
5
+ * Endpoints are grouped the way the API groups them, because the split is real and getting it
6
+ * wrong is the single most common first mistake against this API: **racing is not a sport key.**
7
+ * There is no `sport_key` of `"horse-racing"`. Thoroughbred, greyhound and harness live under
8
+ * `pe.racing.*`; AFL, NRL, NBA and the rest live under `pe.sports.*`.
9
+ *
10
+ * pe.racing.* thoroughbred, greyhound and harness — AU and NZ
11
+ * pe.sports.* Australian sports odds by sport key
12
+ * pe.arb.* cross-book price comparison and arbitrage scanning
13
+ * pe.account.* usage, key metadata, rotation, billing portal
14
+ * pe.webhooks.* push delivery instead of polling
15
+ * pe.health.* per-connector freshness and public uptime
16
+ * pe.demo.* the sandbox: real prices, truncated, no key, no credits
17
+ *
18
+ * Option names are camelCase and map to the API's snake_case query parameters. Two parameters
19
+ * are camelCase on the wire too (`oddsFormat`, `maxAgeMinutes`); those pass through untouched.
20
+ */
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.PuntersEdge = exports.DEFAULT_BASE_URL = exports.VERSION = void 0;
23
+ const http_js_1 = require("./http.js");
24
+ exports.VERSION = "1.0.1";
25
+ /** Default base URL. The API is also reachable at `https://puntersedge.online/api`. */
26
+ exports.DEFAULT_BASE_URL = "https://api.puntersedge.online";
27
+ /**
28
+ * These go over the wire camelCase. Every other option key is converted to snake_case, so
29
+ * `numRaces` becomes `num_races` — but `oddsFormat` must NOT become `odds_format`, which the
30
+ * server would ignore, silently returning decimal odds to a caller who asked for American.
31
+ */
32
+ const WIRE_CAMEL = new Set(["oddsFormat", "maxAgeMinutes"]);
33
+ function toWireKey(key) {
34
+ if (WIRE_CAMEL.has(key))
35
+ return key;
36
+ return key.replace(/[A-Z]/g, (c) => "_" + c.toLowerCase());
37
+ }
38
+ /**
39
+ * camelCase options object -> the query object the transport serialises.
40
+ *
41
+ * Takes `object` rather than `Record<string, unknown>`: a TypeScript interface without an index
42
+ * signature is not assignable to `Record`, and every options type in this file is an interface.
43
+ */
44
+ function q(options) {
45
+ if (!options)
46
+ return undefined;
47
+ const out = {};
48
+ for (const [key, value] of Object.entries(options)) {
49
+ if (value === undefined || value === null)
50
+ continue;
51
+ out[toWireKey(key)] = value;
52
+ }
53
+ return out;
54
+ }
55
+ /** Split a caller's options object into API parameters and per-request transport options. */
56
+ function split(options) {
57
+ if (!options)
58
+ return { params: undefined, request: {} };
59
+ const { signal, timeoutMs, headers, ...rest } = options;
60
+ return { params: q(rest), request: { signal, timeoutMs, headers } };
61
+ }
62
+ /**
63
+ * Thoroughbred and greyhound form, and the paced bulk backfill queue.
64
+ *
65
+ * Form is collected from Racing Australia and Topaz on a deliberate pace — the upstream rate-
66
+ * limits hard, and a burst gets the whole estate flagged. `backfill` is the supported way to ask
67
+ * for many horses: you submit a batch, the queue collects them at a sustainable rate, and you
68
+ * collect the results when they land. Looping `form()` over 400 horses is the unsupported way.
69
+ */
70
+ class HorsesAPI {
71
+ pe;
72
+ constructor(pe) {
73
+ this.pe = pe;
74
+ }
75
+ /** Form, career record and profile for one horse. 3 credits. */
76
+ form(horse, options) {
77
+ return this.pe.get("/v1/racing/horses/form", { horse, ...options });
78
+ }
79
+ /** Queue a batch of horses for paced form collection. 3 credits. */
80
+ submitBackfill(body, options) {
81
+ return this.pe.post("/v1/racing/horses/backfill", body, options);
82
+ }
83
+ /** Progress of a backfill job. 3 credits. */
84
+ backfillStatus(jobId, options) {
85
+ return this.pe.get(`/v1/racing/horses/backfill/${encodeURIComponent(jobId)}`, options);
86
+ }
87
+ /** Collect the form of the horses this job has delivered so far. 3 credits. */
88
+ backfillResults(jobId, options) {
89
+ return this.pe.get(`/v1/racing/horses/backfill/${encodeURIComponent(jobId)}/results`, options);
90
+ }
91
+ /** Cancel the horses a job has not collected yet. Free. */
92
+ cancelBackfill(jobId, options) {
93
+ return this.pe.delete(`/v1/racing/horses/backfill/${encodeURIComponent(jobId)}`, options);
94
+ }
95
+ }
96
+ class GreyhoundsAPI {
97
+ pe;
98
+ constructor(pe) {
99
+ this.pe = pe;
100
+ }
101
+ /**
102
+ * Form history for one dog. 3 credits.
103
+ * `dog` is a name or a Topaz dogId; names match case- and punctuation-insensitively.
104
+ */
105
+ form(dog, options) {
106
+ return this.pe.get("/v1/racing/greyhounds/form", { dog, ...options });
107
+ }
108
+ /**
109
+ * Record by track, distance, box or grade. 3 credits.
110
+ * `by` crosses dimensions: `["track", "distance"]` groups by both.
111
+ */
112
+ stats(dog, options) {
113
+ return this.pe.get("/v1/racing/greyhounds/stats", { dog, ...options });
114
+ }
115
+ }
116
+ /** Thoroughbred, greyhound and harness racing across Australia and New Zealand. */
117
+ class RacingAPI {
118
+ horses;
119
+ greyhounds;
120
+ // Assigned in the body rather than as field initializers: under ES2022 class fields, field
121
+ // initializers run BEFORE a constructor parameter property is assigned, so `new
122
+ // HorsesAPI(this.pe)` in an initializer would hand it `undefined`.
123
+ pe;
124
+ constructor(pe) {
125
+ this.pe = pe;
126
+ this.horses = new HorsesAPI(pe);
127
+ this.greyhounds = new GreyhoundsAPI(pe);
128
+ }
129
+ /**
130
+ * Races about to jump, with runners and live per-bookmaker prices. 2 credits.
131
+ * The usual starting point. Each quote carries its own `age_seconds` and `stale` flag —
132
+ * read them, because a stalled scraper keeps serving its last value.
133
+ */
134
+ nextToGo(options) {
135
+ return this.pe.get("/v1/racing/next-to-go", options);
136
+ }
137
+ /** Scheduled races in a forward window, without prices. 1 credit. */
138
+ events(options) {
139
+ return this.pe.get("/v1/racing/events", options);
140
+ }
141
+ /** Best win, place and tote price per runner across books, with the book offering it. 3 credits. */
142
+ bestOdds(options) {
143
+ return this.pe.get("/v1/racing/best-odds", options);
144
+ }
145
+ /** Consensus steamers and drifters in the live window. 3 credits. */
146
+ movers(options) {
147
+ return this.pe.get("/v1/racing/movers", options);
148
+ }
149
+ /** Settled results: placings, settled prices, dividends and scratchings. 2 credits. */
150
+ results(options) {
151
+ return this.pe.get("/v1/racing/results", options);
152
+ }
153
+ /** What the results field coverage actually is, measured rather than promised. 1 credit. */
154
+ resultsCoverage(options) {
155
+ return this.pe.get("/v1/racing/results/coverage", options);
156
+ }
157
+ /** Per-bookmaker price ticks for one race. 5 credits. */
158
+ priceHistory(options) {
159
+ return this.pe.get("/v1/racing/price-history", options);
160
+ }
161
+ /**
162
+ * Races and prices that changed since a timestamp. 2 credits.
163
+ *
164
+ * This is the endpoint to build a live board on. Polling `nextToGo` in a loop re-downloads
165
+ * every race every time and bills you 2 credits for the privilege; `changes` returns only
166
+ * what moved, and hands back the cursor for the next call.
167
+ */
168
+ changes(options) {
169
+ return this.pe.get("/v1/racing/changes", options);
170
+ }
171
+ /**
172
+ * The permanent closing-line and result archive. **5 credits.** Standard plan and above.
173
+ *
174
+ * See `closingLinesCsv` for the bulk form, which costs 20 — the archive endpoints are the
175
+ * only two on the API whose price depends on the format you ask for.
176
+ */
177
+ closingLines(options) {
178
+ return this.pe.get("/v1/racing/closing-lines", options);
179
+ }
180
+ /** What the closing-line archive actually holds — its floor date, row count and coverage. 1 credit. */
181
+ closingLinesCoverage(options) {
182
+ return this.pe.get("/v1/racing/closing-lines/coverage", options);
183
+ }
184
+ /**
185
+ * Bulk export of the permanent price-movement archive. **5 credits.** Standard plan and
186
+ * above. The CSV form (`pricePathsCsv`) costs 20.
187
+ */
188
+ pricePaths(options) {
189
+ return this.pe.get("/v1/racing/price-paths", options);
190
+ }
191
+ /** Canonical venue directory: `venue_id`, display name and physical site. 1 credit. */
192
+ venues(options) {
193
+ return this.pe.get("/v1/racing/venues", options);
194
+ }
195
+ /**
196
+ * Full-day AU thoroughbred acceptance card. 2 credits.
197
+ *
198
+ * Read `completeness` and each race's `runner_set_status` before treating a count as the
199
+ * field size — the response is explicit about when a figure is a floor rather than exact.
200
+ */
201
+ acceptances(options) {
202
+ return this.pe.get("/v1/racing/acceptances", options);
203
+ }
204
+ /** Track condition, weather and rail: current state and the day's change log. 1 credit. */
205
+ trackConditions(options) {
206
+ return this.pe.get("/v1/racing/track-conditions", options);
207
+ }
208
+ /** Jockey premiership leaderboards, or one jockey by name. 2 credits. */
209
+ jockeyStats(options) {
210
+ return this.pe.get("/v1/racing/jockeys/stats", options);
211
+ }
212
+ /** Trainer premiership leaderboards, or one trainer by name. 2 credits. */
213
+ trainerStats(options) {
214
+ return this.pe.get("/v1/racing/trainers/stats", options);
215
+ }
216
+ /**
217
+ * The closing-line archive as a CSV string, streamed by the server in a stable column order.
218
+ *
219
+ * **20 credits, not 5.** This is `closingLines` with `format=csv`, and CSV is priced as the
220
+ * bulk export it is: the server caps a CSV pull at 50,000 rows against 5,000 for a JSON
221
+ * page, so one call can return ten times the data. Same filters, four times the price.
222
+ */
223
+ closingLinesCsv(options) {
224
+ return this.pe.get("/v1/racing/closing-lines", { ...options, format: "csv" }, { Accept: "text/csv" });
225
+ }
226
+ /**
227
+ * The price-path archive as a CSV string, in a stable column order.
228
+ *
229
+ * **20 credits, not 5** — same bulk-export pricing as `closingLinesCsv`.
230
+ */
231
+ pricePathsCsv(options) {
232
+ return this.pe.get("/v1/racing/price-paths", { ...options, format: "csv" }, { Accept: "text/csv" });
233
+ }
234
+ }
235
+ /** Australian sports odds. Racing is NOT here — see `pe.racing`. */
236
+ class SportsAPI {
237
+ pe;
238
+ constructor(pe) {
239
+ this.pe = pe;
240
+ }
241
+ /** The sport catalogue: every queryable `sport_key` with its display name. 1 credit. */
242
+ list(options) {
243
+ return this.pe.get("/v1/sports", options);
244
+ }
245
+ /**
246
+ * Odds for one sport. **1 credit per market requested** — asking for
247
+ * `["h2h", "spreads", "totals"]` costs 3, not 1.
248
+ */
249
+ odds(sportKey, options) {
250
+ return this.pe.get(`/v1/sports/${encodeURIComponent(sportKey)}/odds`, options);
251
+ }
252
+ /** Best available price per outcome across bookmakers, for one sport. 3 credits. */
253
+ bestOdds(sportKey, options) {
254
+ return this.pe.get(`/v1/best-odds/${encodeURIComponent(sportKey)}`, options);
255
+ }
256
+ /** Historical odds snapshots. 5 credits. */
257
+ oddsHistory(sportKey, options) {
258
+ return this.pe.get(`/v1/sports/${encodeURIComponent(sportKey)}/odds/history`, options);
259
+ }
260
+ /** Price movement feed for one sport. 5 credits. */
261
+ oddsMovements(sportKey, options) {
262
+ return this.pe.get(`/v1/sports/${encodeURIComponent(sportKey)}/odds/movements`, options);
263
+ }
264
+ }
265
+ /**
266
+ * Cross-book comparison and arbitrage scanning.
267
+ *
268
+ * A word of warning that costs nothing to read: a two-outcome market that only one book is
269
+ * quoting will look like a large arb and is not one. Check how many books are behind each leg
270
+ * before acting on a number from here.
271
+ */
272
+ class ArbAPI {
273
+ pe;
274
+ constructor(pe) {
275
+ this.pe = pe;
276
+ }
277
+ /** Head-to-head arb scanner. 3 credits. */
278
+ sports(options) {
279
+ return this.pe.get("/v1/arb/sports", options);
280
+ }
281
+ /** Spreads and totals line arb. 3 credits. */
282
+ lines(options) {
283
+ return this.pe.get("/v1/arb/lines", options);
284
+ }
285
+ /** Best price per selection with every book's quote alongside. 2 credits. */
286
+ bestPrices(options) {
287
+ return this.pe.get("/v1/arb/best-prices", options);
288
+ }
289
+ }
290
+ // ── account ───────────────────────────────────────────────────────────────────────────────
291
+ /** Usage, key metadata and billing. Every method here is free — it costs no credits to ask. */
292
+ class AccountAPI {
293
+ pe;
294
+ constructor(pe) {
295
+ this.pe = pe;
296
+ }
297
+ /**
298
+ * Plan, allowance, credits used and reset date. Free.
299
+ *
300
+ * You rarely need this: every billed response already carries the balance in its headers,
301
+ * which the client exposes as `pe.credits`.
302
+ */
303
+ usage(options) {
304
+ return this.pe.get("/v1/usage", options);
305
+ }
306
+ /** Usage broken down by endpoint. Free. */
307
+ usageAnalytics(options) {
308
+ return this.pe.get("/v1/usage/analytics", options);
309
+ }
310
+ /** Plan, limits and status for the key in use. Free. */
311
+ keyInfo(options) {
312
+ return this.pe.get("/v1/keys/info", options);
313
+ }
314
+ /** A Stripe self-service billing portal link. Free. */
315
+ billingPortal(options) {
316
+ return this.pe.get("/v1/billing/portal", options);
317
+ }
318
+ /**
319
+ * Rotate the key. Free.
320
+ *
321
+ * The old key keeps working through a grace window so a deploy can roll. Pass
322
+ * `{ immediate: true }` only when rotating because the key leaked — that revokes it now and
323
+ * will break anything still holding it.
324
+ */
325
+ rotateKey(options) {
326
+ const { params, request } = split(options);
327
+ return this.pe.raw("POST", "/v1/keys/rotate", params, undefined, request)
328
+ .then((r) => r.data);
329
+ }
330
+ /** Restrict this key to a set of source IPs. Free. Pass `[]` to clear the whitelist. */
331
+ setIpWhitelist(ips, options) {
332
+ const { request } = split(options);
333
+ return this.pe.raw("POST", "/v1/keys/ip-whitelist", undefined, ips, request)
334
+ .then((r) => r.data);
335
+ }
336
+ }
337
+ /**
338
+ * Push delivery instead of polling. Creating a webhook needs the Standard plan or above.
339
+ *
340
+ * Every delivery is signed: `X-Webhook-Signature` is an HMAC-SHA256 over the **raw request
341
+ * body**, keyed with the secret returned when you create the subscription. Verify it against
342
+ * the bytes you received, before parsing — re-serialising the JSON first changes the bytes and
343
+ * the signature will never match.
344
+ */
345
+ class WebhooksAPI {
346
+ pe;
347
+ constructor(pe) {
348
+ this.pe = pe;
349
+ }
350
+ /** Create a subscription. The response carries the signing secret — it is shown once. */
351
+ create(input, options) {
352
+ return this.pe.post("/v1/webhooks", input, options);
353
+ }
354
+ list(options) {
355
+ return this.pe.get("/v1/webhooks", options);
356
+ }
357
+ delete(webhookId, options) {
358
+ return this.pe.delete(`/v1/webhooks/${encodeURIComponent(webhookId)}`, options);
359
+ }
360
+ /** Recent delivery attempts, with response codes — the first place to look when nothing arrives. */
361
+ deliveries(webhookId, options) {
362
+ return this.pe.get(`/v1/webhooks/${encodeURIComponent(webhookId)}/deliveries`, options);
363
+ }
364
+ /** Fire a test delivery at the endpoint, so you can verify your signature check end to end. */
365
+ test(webhookId, options) {
366
+ return this.pe.post(`/v1/webhooks/${encodeURIComponent(webhookId)}/test`, undefined, options);
367
+ }
368
+ }
369
+ // ── health ────────────────────────────────────────────────────────────────────────────────
370
+ /**
371
+ * Is the data current?
372
+ *
373
+ * `connectors()` is the one to watch. A stalled scraper does not return an error — it keeps
374
+ * serving its last value, which is exactly what a live price looks like. `last_ok` per
375
+ * connector is how you tell the difference.
376
+ */
377
+ class HealthAPI {
378
+ pe;
379
+ constructor(pe) {
380
+ this.pe = pe;
381
+ }
382
+ /** Per-connector freshness: `last_ok`, status, records written. Requires a key. */
383
+ connectors(options) {
384
+ return this.pe.get("/v1/health", options);
385
+ }
386
+ /** Per-connector freshness with tunable staleness thresholds and optional per-sport coverage. 1 credit. */
387
+ connectorDetail(options) {
388
+ return this.pe.get("/v1/health/connectors", options);
389
+ }
390
+ /** Public uptime stats. No key, no credits. */
391
+ uptime(options) {
392
+ return this.pe.get("/v1/uptime", options);
393
+ }
394
+ }
395
+ // ── sandbox ───────────────────────────────────────────────────────────────────────────────
396
+ /**
397
+ * The sandbox: real prices, truncated to 3 races, 5 runners and 3 bookmakers. No key, no
398
+ * credits. Use it to learn the response shape before you spend anything, and to keep an
399
+ * example in your README runnable by someone who has not signed up yet.
400
+ */
401
+ class DemoAPI {
402
+ pe;
403
+ constructor(pe) {
404
+ this.pe = pe;
405
+ }
406
+ nextToGo(options) {
407
+ return this.pe.get("/v1/demo/racing/next-to-go", options);
408
+ }
409
+ /** Sample best-odds with arb detection. `sport` is optional; a live sport is picked if omitted. */
410
+ bestOdds(options) {
411
+ return this.pe.get("/v1/demo/best-odds", options);
412
+ }
413
+ }
414
+ /**
415
+ * ```ts
416
+ * import { PuntersEdge } from "puntersedge";
417
+ *
418
+ * const pe = new PuntersEdge({ apiKey: process.env.PUNTERSEDGE_API_KEY });
419
+ *
420
+ * for (const race of await pe.racing.nextToGo({ numRaces: 5, categories: "horse" })) {
421
+ * console.log(race.venue, race.race_number, race.start_time);
422
+ * }
423
+ *
424
+ * console.log(pe.credits?.remaining, "credits left");
425
+ * ```
426
+ */
427
+ class PuntersEdge {
428
+ racing = new RacingAPI(this);
429
+ sports = new SportsAPI(this);
430
+ arb = new ArbAPI(this);
431
+ account = new AccountAPI(this);
432
+ webhooks = new WebhooksAPI(this);
433
+ health = new HealthAPI(this);
434
+ demo = new DemoAPI(this);
435
+ /**
436
+ * Credit accounting from the most recent billed response — balance, cost, and the upgrade
437
+ * recommendation once you cross the warning threshold. Undefined until the first billed call.
438
+ */
439
+ credits;
440
+ // A true #private field, not TypeScript's compile-time `private`. TS `private` is erased,
441
+ // leaving an ordinary enumerable property — so `console.log(pe)` would print the API key,
442
+ // and so would any error reporter that serialises the object. `#config` is unreachable from
443
+ // outside the class and invisible to enumeration.
444
+ #config;
445
+ constructor(options = {}) {
446
+ const opts = typeof options === "string" ? { apiKey: options } : options;
447
+ const base = (opts.baseUrl ?? exports.DEFAULT_BASE_URL).replace(/\/+$/, "");
448
+ const ua = opts.userAgent
449
+ ? `puntersedge-node/${exports.VERSION} ${opts.userAgent}`
450
+ : `puntersedge-node/${exports.VERSION}`;
451
+ const fetchImpl = opts.fetch ?? globalThis.fetch;
452
+ if (typeof fetchImpl !== "function") {
453
+ throw new Error("No global fetch. Use Node 18 or later, or pass one: new PuntersEdge({ fetch }).");
454
+ }
455
+ this.#config = {
456
+ baseUrl: base,
457
+ apiKey: opts.apiKey,
458
+ timeoutMs: opts.timeoutMs ?? 30_000,
459
+ userAgent: ua,
460
+ // Bound: some runtimes throw "Illegal invocation" on a detached global fetch.
461
+ fetch: fetchImpl.bind(globalThis),
462
+ onCredits: (credits) => {
463
+ this.credits = credits;
464
+ opts.onCredits?.(credits);
465
+ },
466
+ };
467
+ }
468
+ /**
469
+ * The full response for one call: data, credits and headers together.
470
+ *
471
+ * ```ts
472
+ * const { data, credits } = await pe.withCredits((p) => p.racing.nextToGo());
473
+ * ```
474
+ */
475
+ async withCredits(call) {
476
+ const data = await call(this);
477
+ return { data, credits: this.credits };
478
+ }
479
+ /** Escape hatch: any endpoint, including ones added after this SDK was published. */
480
+ async raw(method, path, params, body, options = {}) {
481
+ return (0, http_js_1.request)(this.#config, method, path, params, body, options);
482
+ }
483
+ /** @internal */
484
+ get(path, options, extraHeaders) {
485
+ const { params, request: req } = split(options);
486
+ if (extraHeaders)
487
+ req.headers = { ...extraHeaders, ...req.headers };
488
+ return this.raw("GET", path, params, undefined, req).then((r) => r.data);
489
+ }
490
+ /** @internal */
491
+ post(path, body, options) {
492
+ const { request: req } = split(options);
493
+ return this.raw("POST", path, undefined, body, req).then((r) => r.data);
494
+ }
495
+ /** @internal */
496
+ delete(path, options) {
497
+ const { request: req } = split(options);
498
+ return this.raw("DELETE", path, undefined, undefined, req).then((r) => r.data);
499
+ }
500
+ }
501
+ exports.PuntersEdge = PuntersEdge;
502
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;GAkBG;;;AAEH,uCAAwG;AAY3F,QAAA,OAAO,GAAG,OAAO,CAAC;AAE/B,uFAAuF;AAC1E,QAAA,gBAAgB,GAAG,gCAAgC,CAAC;AAEjE;;;;GAIG;AACH,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,CAAC,YAAY,EAAE,eAAe,CAAC,CAAC,CAAC;AAE5D,SAAS,SAAS,CAAC,GAAW;IAC5B,IAAI,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC;QAAE,OAAO,GAAG,CAAC;IACpC,OAAO,GAAG,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CA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AO,IAAI,CAAC,GAAG,CAAI,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IAC7E,CAAC;IAED,gBAAgB;IAChB,MAAM,CAAI,IAAY,EAAE,OAAqB;QAC3C,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC;QACxC,OAAO,IAAI,CAAC,GAAG,CAAI,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IACpF,CAAC;CACF;AAhGD,kCAgGC"}
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ /**
3
+ * Credit accounting, read off the headers of the response you already made.
4
+ *
5
+ * WHY THIS EXISTS. The API bills per successful request and reports the running balance on
6
+ * every single response — `X-Credits-Remaining`, plus a `X-Credits-Warning` once you cross the
7
+ * warning threshold and an `X-Upgrade-*` block telling you exactly what to buy and how. Polling
8
+ * `/v1/usage` to learn the same thing is a round-trip that answers a question the last response
9
+ * already answered.
10
+ *
11
+ * So the client parses the headers on every call and hands them to you three ways:
12
+ *
13
+ * client.credits // the most recent snapshot, or undefined
14
+ * new PuntersEdge({ onCredits }) // a callback fired after every billed call
15
+ * await client.withCredits(c => ...) // data and credits together for one call
16
+ *
17
+ * `remaining` and `limit` are `"unlimited"` on an unlimited plan rather than a number, because
18
+ * that is what the header says and coercing it to `Infinity` would let `remaining < 100` quietly
19
+ * mean something different on two plans.
20
+ */
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.parseUpgrade = parseUpgrade;
23
+ exports.parseCredits = parseCredits;
24
+ function num(h, name) {
25
+ const v = h.get(name);
26
+ if (v === null)
27
+ return undefined;
28
+ const n = Number(v);
29
+ return Number.isFinite(n) ? n : undefined;
30
+ }
31
+ function countOrUnlimited(h, name) {
32
+ const v = h.get(name);
33
+ if (v === null)
34
+ return undefined;
35
+ if (v === "unlimited")
36
+ return "unlimited";
37
+ const n = Number(v);
38
+ return Number.isFinite(n) ? n : undefined;
39
+ }
40
+ /** Pull the `X-Upgrade-*` block off a response, or undefined when the API did not send one. */
41
+ function parseUpgrade(h) {
42
+ const plan = h.get("X-Upgrade-Plan");
43
+ const url = h.get("X-Upgrade-Url");
44
+ if (!plan || !url)
45
+ return undefined;
46
+ const method = h.get("X-Upgrade-Checkout-Method");
47
+ const endpoint = h.get("X-Upgrade-Checkout-Endpoint");
48
+ const body = h.get("X-Upgrade-Checkout-Body");
49
+ const covers = h.get("X-Upgrade-Covers");
50
+ return {
51
+ plan,
52
+ url,
53
+ credits: num(h, "X-Upgrade-Credits"),
54
+ priceAud: num(h, "X-Upgrade-Price-AUD"),
55
+ covers: covers === "full" || covers === "partial" ? covers : undefined,
56
+ sizedFor: num(h, "X-Upgrade-Sized-For"),
57
+ checkout: method && endpoint && body !== null
58
+ ? { method, endpoint, body, prorated: h.get("X-Upgrade-Prorated") === "true" }
59
+ : undefined,
60
+ };
61
+ }
62
+ /**
63
+ * Pull the credit block off a response. Returns undefined when the response carried no
64
+ * `X-Credits-*` headers at all — the sandbox endpoints and `/v1/uptime` take no key and bill
65
+ * nothing, so there is nothing to report.
66
+ */
67
+ function parseCredits(h) {
68
+ if (h.get("X-Credits-Remaining") === null && h.get("X-Credits-Used") === null) {
69
+ return undefined;
70
+ }
71
+ const warning = h.get("X-Credits-Warning");
72
+ return {
73
+ cost: num(h, "X-Credits-Cost"),
74
+ used: num(h, "X-Credits-Used"),
75
+ limit: countOrUnlimited(h, "X-Credits-Limit"),
76
+ remaining: countOrUnlimited(h, "X-Credits-Remaining"),
77
+ pctUsed: num(h, "X-Credits-Pct-Used"),
78
+ warning: warning === "approaching-limit" ? warning : undefined,
79
+ upgrade: parseUpgrade(h),
80
+ };
81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