@staraio/sdk 0.1.0 → 0.2.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/README.md CHANGED
@@ -44,6 +44,17 @@ Use a test key (`sk_test_...`) to build against the simulation, a live key (`sk_
44
44
  for real. Create keys in the dashboard (dashboard.staraio.co, API Platform). Keep the key on the
45
45
  machine that runs this, never in a browser.
46
46
 
47
+ ## Sites, categories and credits
48
+
49
+ ```js
50
+ const { sites } = await star.sites(); // each site's `link` and `link_example` say what to send
51
+ const { categories } = await star.categories(eventUrl); // when the site has categories: true
52
+ const category = categories.find((c) => c.open)?.code; // undefined queues for the default
53
+ await star.startRun({ event_url: eventUrl, category, passes: 1, tasks: 10, proxies });
54
+
55
+ const { url } = await star.creditsCheckout({ amount_cents: 5000 }); // a person opens url and pays
56
+ ```
57
+
47
58
  ## Account sites (Ticketmaster)
48
59
 
49
60
  Pass `accounts` to `startRun` for a site whose line only lets signed-in accounts through. Each
package/client.js CHANGED
@@ -24,7 +24,9 @@ export function client({ baseUrl, key, fetchImpl = fetch }) {
24
24
 
25
25
  return {
26
26
  sites: () => call("GET", "/sites"),
27
+ categories: (eventUrl) => call("GET", `/categories?${new URLSearchParams({ event_url: eventUrl })}`),
27
28
  credits: () => call("GET", "/credits"),
29
+ creditsCheckout: (body) => call("POST", "/credits/checkout", body),
28
30
  startRun: (body, idempotencyKey) =>
29
31
  call("POST", "/runs", body, idempotencyKey ? { "Idempotency-Key": idempotencyKey } : {}),
30
32
  getRun: (id) => call("GET", `/runs/${encodeURIComponent(id)}`),
@@ -75,11 +77,13 @@ export async function waitForChange(api, id, { timeoutMs, intervalMs = 2000, fro
75
77
  }
76
78
 
77
79
  function isTransient(err) {
78
- // 429 is the per-run read limit: waiting longer is exactly the right answer to it.
79
80
  if (err instanceof StarError) {
80
- if (err.status === 429) return true;
81
- // A 5xx with no API detail comes from the load balancer or a proxy, not from Star.
82
- return err.status >= 500 && (!err.detail || err.detail.suggested_action === "retry");
81
+ const action = err.detail?.suggested_action;
82
+ // 429 is the per-run read limit: waiting longer is exactly the right answer to it.
83
+ if (err.status === 429 || action === "retry") return true;
84
+ // A 5xx is the server or the load balancer in front of it, which can answer with no detail
85
+ // or a bare string. Only an explicit non-retry action from Star (e.g. "stop") ends the wait.
86
+ return err.status >= 500 && action === undefined;
83
87
  }
84
88
  return err instanceof TypeError; // fetch's network failure
85
89
  }
package/index.js CHANGED
@@ -15,9 +15,15 @@ export class StarClient {
15
15
  sites() {
16
16
  return this.api.sites();
17
17
  }
18
+ categories(eventUrl) {
19
+ return this.api.categories(eventUrl);
20
+ }
18
21
  credits() {
19
22
  return this.api.credits();
20
23
  }
24
+ creditsCheckout(body) {
25
+ return this.api.creditsCheckout(body);
26
+ }
21
27
  startRun(body, idempotencyKey) {
22
28
  return this.api.startRun(body, idempotencyKey);
23
29
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@staraio/sdk",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "JavaScript client for the Star API: start a run, follow it and take each place at the front.",
5
5
  "type": "module",
6
6
  "main": "index.js",