prizerail 0.3.3 → 0.5.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
@@ -11,7 +11,7 @@ The Prizerail SDK for JavaScript and TypeScript. Send entries, read results and
11
11
  npm install prizerail
12
12
  ```
13
13
 
14
- The API is early (v0.x), so names can change between minor versions. 0.3.0 adds `entries.increment()`, 0.3.1 checks every event before sending any and lists only the drawings that took entries, and 0.3.2 and 0.3.3 check avatar URLs, names and the older `weight` up front too. 0.2.0 says `entries` where 0.1.0 said `weight`: an entrant is `{ entrantId, entries }`, and totals are `entrantCount` and `totalEntries`. The old names still work, marked deprecated. Each change is in the [changelog](https://docs.prizerail.com/changelog).
14
+ The API is early (v0.x), so names can change between minor versions. 0.5.0 sends a `pr_sandbox_` key to https://sandbox.prizerail.com unless you pass `siteUrl` (0.4.0 did the same for the old `pr_test_` keys). 0.3.0 adds `entries.increment()`, 0.3.1 checks every event before sending any and lists only the drawings that took entries, and 0.3.2 and 0.3.3 check avatar URLs, names and the older `weight` up front too. 0.2.0 says `entries` where 0.1.0 said `weight`: an entrant is `{ entrantId, entries }`, and totals are `entrantCount` and `totalEntries`. The old names still work, marked deprecated. Each change is in the [changelog](https://docs.prizerail.com/changelog).
15
15
 
16
16
  ## Send entries
17
17
 
@@ -99,9 +99,9 @@ for await (const drawing of campaign.drawings.all({ status: "paid" })) {
99
99
  const guarantees = await campaign.guarantees.list()
100
100
  ```
101
101
 
102
- ## Draw now, in test
102
+ ## Draw now, in the sandbox
103
103
 
104
- In the test environment, `campaign.drawings.run(id)` closes a drawing's entries now and draws it, so you can see a whole draw without waiting for its cutoff. It resolves with the drawing, usually settled within seconds. Anywhere else it throws a `PrizerailError` with code `test_only`. See [Draw now](https://docs.prizerail.com/api/drawings#draw-now-test-only).
104
+ In the sandbox, `campaign.drawings.run(id)` closes a drawing's entries now and draws it, so you can see a whole draw without waiting for its cutoff. It resolves with the drawing, usually settled within seconds. Anywhere else it throws a `PrizerailError` with code `sandbox_only`. See [Draw now](https://docs.prizerail.com/api/drawings#draw-now-sandbox-only).
105
105
 
106
106
  ## Errors
107
107
 
@@ -132,6 +132,8 @@ npx prizerail verify https://www.prizerail.com/campaigns/your-campaign/draws/DRA
132
132
  npx prizerail verify your-campaign DRAWING_ID
133
133
  ```
134
134
 
135
+ A slug is looked up on www.prizerail.com. For a draw from a sandbox campaign, add `--site https://sandbox.prizerail.com`, or set `PRIZERAIL_API_KEY` to your `pr_sandbox_` key. The same goes for the public helpers without a key: `new Prizerail({ siteUrl: "https://sandbox.prizerail.com" })` reaches sandbox campaigns.
136
+
135
137
  It exits 0 when every check passes, 1 when one fails, and 2 when the proof can't be read.
136
138
 
137
139
  ## Options
@@ -139,7 +141,7 @@ It exits 0 when every check passes, 1 when one fails, and 2 when the proof can't
139
141
  ```ts
140
142
  new Prizerail({
141
143
  apiKey: "pr_…",
142
- siteUrl: "https://www.prizerail.com", // the default
144
+ siteUrl: "https://www.prizerail.com", // the default, or https://sandbox.prizerail.com for a pr_sandbox_ key
143
145
  timeoutMs: 30_000, // per attempt
144
146
  maxRetries: 4,
145
147
  fetch, // your own fetch, if you need one
package/dist/cli.js CHANGED
@@ -10,7 +10,10 @@ Usage:
10
10
 
11
11
  Checks a draw from its public proof: the locked entrant list, the random
12
12
  value, and every winner and prize. Exits 0 when every check passes, 1 when
13
- one fails, and 2 when the proof can't be read.`;
13
+ one fails, and 2 when the proof can't be read.
14
+
15
+ A slug is looked up on www.prizerail.com. For a sandbox campaign, pass
16
+ --site https://sandbox.prizerail.com, or set PRIZERAIL_API_KEY to a pr_sandbox_ key.`;
14
17
  function print(result) {
15
18
  const { proof, checks } = result;
16
19
  // A malformed proof may lack these, and its failed checks still print.
@@ -48,7 +51,11 @@ async function main(argv) {
48
51
  console.log(USAGE);
49
52
  return 2;
50
53
  }
51
- const campaign = new Prizerail({ siteUrl: site }).campaign(a);
54
+ // The key only picks the site: proofs are public, so nothing is sent with it.
55
+ const campaign = new Prizerail({
56
+ siteUrl: site,
57
+ apiKey: process.env.PRIZERAIL_API_KEY,
58
+ }).campaign(a);
52
59
  return print(await campaign.drawings.verify(b));
53
60
  }
54
61
  // exitCode rather than exit(), so a long report piped to a file isn't cut off.
package/dist/client.d.ts CHANGED
@@ -1,13 +1,17 @@
1
1
  import { Http } from "./http.js";
2
2
  import type { Campaign, Drawing, DrawingRef, DrawingStatus, DrawingsPage, Entrant, EntrantEvent, EntriesPage, Guarantee, SendEntriesResponse, SentEntrant } from "./types.js";
3
3
  import { type DrawProof, type VerifyResult } from "./verify.js";
4
- export declare const VERSION = "0.3.3";
4
+ export declare const VERSION = "0.5.0";
5
5
  /** The API takes up to this many entries per request. */
6
6
  export declare const ENTRIES_PER_REQUEST = 1000;
7
7
  export type PrizerailOptions = {
8
8
  /** Your `pr_…` key. Only the public helpers work without one. */
9
9
  apiKey?: string;
10
- /** Defaults to https://www.prizerail.com. */
10
+ /**
11
+ * Defaults to https://sandbox.prizerail.com for a `pr_sandbox_` key and
12
+ * https://www.prizerail.com otherwise. Set it to point anywhere else, such
13
+ * as a local server.
14
+ */
11
15
  siteUrl?: string;
12
16
  /** Per attempt. Defaults to 30 seconds. */
13
17
  timeoutMs?: number;
@@ -143,11 +147,11 @@ export declare class DrawingsClient {
143
147
  }): AsyncGenerator<Drawing>;
144
148
  get(id: string): Promise<Drawing>;
145
149
  /**
146
- * Test environment only: closes the drawing's entries now and draws it,
150
+ * Sandbox only: closes the drawing's entries now and draws it,
147
151
  * instead of waiting for its cutoff. Resolves with the drawing, settled or
148
152
  * paid, or still `entropy_requested` if the random value is on its way, in
149
153
  * which case read it again with `get(id)`. Elsewhere it throws a
150
- * PrizerailError with code `test_only`.
154
+ * PrizerailError with code `sandbox_only`.
151
155
  */
152
156
  run(id: string): Promise<Drawing>;
153
157
  /**
package/dist/client.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { PrizerailCutoffError, PrizerailDrawingChangedError, PrizerailError, } from "./errors.js";
2
2
  import { Http } from "./http.js";
3
3
  import { verifyDraw } from "./verify.js";
4
- export const VERSION = "0.3.3";
4
+ export const VERSION = "0.5.0";
5
5
  const badPage = (detail) => new PrizerailError(0, "invalid_response", `Paging stopped: ${detail}.`);
6
6
  /** The API takes up to this many entries per request. */
7
7
  export const ENTRIES_PER_REQUEST = 1000;
@@ -131,12 +131,18 @@ function normalizePage(page) {
131
131
  next: page.next,
132
132
  };
133
133
  }
134
+ /** The site a key belongs to: sandbox keys only work in the sandbox. */
135
+ function defaultSiteUrl(apiKey) {
136
+ return apiKey?.trim().startsWith("pr_sandbox_")
137
+ ? "https://sandbox.prizerail.com"
138
+ : "https://www.prizerail.com";
139
+ }
134
140
  export class Prizerail {
135
141
  siteUrl;
136
142
  /** @internal */
137
143
  http;
138
144
  constructor(options = {}) {
139
- this.siteUrl = (options.siteUrl ?? "https://www.prizerail.com").replace(/\/+$/, "");
145
+ this.siteUrl = (options.siteUrl ?? defaultSiteUrl(options.apiKey)).replace(/\/+$/, "");
140
146
  const fetchImpl = options.fetch ?? globalThis.fetch;
141
147
  if (!fetchImpl)
142
148
  throw new Error("No fetch here. Pass options.fetch.");
@@ -392,11 +398,11 @@ export class DrawingsClient {
392
398
  return (await this.campaign.http.request("GET", this.campaign.path(`/drawings/${encodeURIComponent(id)}`))).drawing;
393
399
  }
394
400
  /**
395
- * Test environment only: closes the drawing's entries now and draws it,
401
+ * Sandbox only: closes the drawing's entries now and draws it,
396
402
  * instead of waiting for its cutoff. Resolves with the drawing, settled or
397
403
  * paid, or still `entropy_requested` if the random value is on its way, in
398
404
  * which case read it again with `get(id)`. Elsewhere it throws a
399
- * PrizerailError with code `test_only`.
405
+ * PrizerailError with code `sandbox_only`.
400
406
  */
401
407
  async run(id) {
402
408
  return (await this.campaign.http.request("POST", this.campaign.path(`/drawings/${encodeURIComponent(id)}/run`),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prizerail",
3
- "version": "0.3.3",
3
+ "version": "0.5.0",
4
4
  "description": "The Prizerail SDK: send entries, read draws and verify them.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://docs.prizerail.com",