prizerail 1.1.0 → 1.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
@@ -105,6 +105,15 @@ for await (const drawing of campaign.drawings.all({ status: "paid" })) {
105
105
  const guarantees = await campaign.guarantees.list()
106
106
  ```
107
107
 
108
+ To answer a user who asks whether their entries counted, look them up in one drawing by the id you sent:
109
+
110
+ ```ts
111
+ const found = await campaign.drawings.entrant(drawingId, entrantId)
112
+ // { entered, entries, position, receivedAt, drawn, winner }
113
+ ```
114
+
115
+ `entered` is false, not an error, for someone who isn't in the drawing. `winner` stays null for everyone until `drawn` is true. See [Look up an entrant](https://docs.prizerail.com/api/drawings#look-up-an-entrant).
116
+
108
117
  ## Draw now, in the sandbox
109
118
 
110
119
  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).
package/dist/client.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Http } from "./http.js";
2
- import type { Campaign, Drawing, DrawingRef, DrawingStatus, DrawingsPage, Entrant, EntrantEvent, EntriesPage, Guarantee, SendEntriesResponse, SentEntrant } from "./types.js";
2
+ import type { Campaign, Drawing, DrawingRef, DrawingStatus, DrawingsPage, Entrant, EntrantEvent, EntrantLookup, EntriesPage, Guarantee, SendEntriesResponse, SentEntrant } from "./types.js";
3
3
  import { type DrawProof, type VerifyResult } from "./verify.js";
4
- export declare const VERSION = "1.1.0";
4
+ export declare const VERSION = "1.2.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 = {
@@ -146,6 +146,13 @@ export declare class DrawingsClient {
146
146
  pageSize?: number;
147
147
  }): AsyncGenerator<Drawing>;
148
148
  get(id: string): Promise<Drawing>;
149
+ /**
150
+ * Whether one entrant's entries reached a drawing, how many it holds, and
151
+ * what they won once it's drawn, from what Prizerail received. Pass the
152
+ * `entrantId` as you sent it. Someone not in the drawing resolves with
153
+ * `entered: false`, not an error.
154
+ */
155
+ entrant(id: string, entrantId: string): Promise<EntrantLookup>;
149
156
  /**
150
157
  * Sandbox only: closes the drawing's entries now and draws it,
151
158
  * instead of waiting for its cutoff. Resolves with the drawing, settled or
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 = "1.1.0";
4
+ export const VERSION = "1.2.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;
@@ -389,6 +389,15 @@ export class DrawingsClient {
389
389
  async get(id) {
390
390
  return (await this.campaign.http.request("GET", this.campaign.path(`/drawings/${encodeURIComponent(id)}`))).drawing;
391
391
  }
392
+ /**
393
+ * Whether one entrant's entries reached a drawing, how many it holds, and
394
+ * what they won once it's drawn, from what Prizerail received. Pass the
395
+ * `entrantId` as you sent it. Someone not in the drawing resolves with
396
+ * `entered: false`, not an error.
397
+ */
398
+ async entrant(id, entrantId) {
399
+ return this.campaign.http.request("GET", this.campaign.path(`/drawings/${encodeURIComponent(id)}/entrant`), { query: { entrantId } });
400
+ }
392
401
  /**
393
402
  * Sandbox only: closes the drawing's entries now and draws it,
394
403
  * instead of waiting for its cutoff. Resolves with the drawing, settled or
package/dist/types.d.ts CHANGED
@@ -110,6 +110,46 @@ export type Drawing = {
110
110
  prizeTableId: string | null;
111
111
  };
112
112
  };
113
+ /** One entrant in one drawing, from `drawings.entrant()`. */
114
+ export type EntrantLookup = {
115
+ drawing: {
116
+ id: string;
117
+ kind: DrawingKind;
118
+ number: number | null;
119
+ drawAt: string;
120
+ cutoffAt: string;
121
+ status: DrawingStatus;
122
+ };
123
+ entrantId: string;
124
+ /** Whether the drawing holds entries for this id. */
125
+ entered: boolean;
126
+ /**
127
+ * Their number of entries, or null if they didn't enter. 1 in a guarantee
128
+ * draw, which gives everyone who entered the period one entry.
129
+ */
130
+ entries: number | null;
131
+ /**
132
+ * Their place in the locked entrant list. Null until the drawing locks,
133
+ * shortly after the cutoff. Set from the start in a guarantee draw.
134
+ */
135
+ position: number | null;
136
+ /**
137
+ * When their first entry for this drawing arrived. In a guarantee draw,
138
+ * when the draw was made.
139
+ */
140
+ receivedAt: string | null;
141
+ /**
142
+ * Whether the winners are known: true once settled or paid. Until then
143
+ * `winner` is null for everyone, so null alone doesn't mean they lost.
144
+ */
145
+ drawn: boolean;
146
+ /** Their win, or null. `position` is their slot in the drawing's winners. */
147
+ winner: {
148
+ position: number;
149
+ amountCents: number;
150
+ heldForManualPayout: boolean;
151
+ } | null;
152
+ };
113
153
  export type DrawingsPage = {
114
154
  drawings: Drawing[];
115
155
  nextBefore: string | null;
@@ -120,8 +160,8 @@ export type Entrant = string | {
120
160
  entrantId: string;
121
161
  /**
122
162
  * Their number of entries, a whole number from 1. Leave it out and it's
123
- * 1. Entries are chances: 5 entries is five times as likely to win each
124
- * prize as 1.
163
+ * 1. Entries are chances: 5 entries is five times as likely to be picked
164
+ * as 1.
125
165
  */
126
166
  entries?: number;
127
167
  /** Up to 40 characters. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prizerail",
3
- "version": "1.1.0",
3
+ "version": "1.2.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",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prizerail",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Integrate Prizerail prize draws into an app, check an integration end to end, and look up or verify draws.",
5
5
  "author": {
6
6
  "name": "Prizerail",
@@ -23,7 +23,7 @@ It needs `PRIZERAIL_API_KEY` in the environment. The key picks the site: a `pr_s
23
23
  | **Open drawing** | A drawing is taking entries, with its cutoff shown | None open while paused, or between a cutoff and the next drawing being made. Entries sent now would get `409 no_open_drawing`. |
24
24
  | **Entrant ids** | The first 5,000 ids in the open drawing look opaque | It fails on ids that look like an email, a username (a word with separators or in camelCase, even with a year on the end), a name with spaces, any all-digit id, or any id shorter than 16 characters. A few username-shaped ids in a large sample are a note, not a failure, since a random id now and then reads like a word. It notes any UUID: fine if it was made for Prizerail and stored, not if it's the app's own users table id. Entrant ids are published, hashed, with every draw, so they must be an HMAC of the user id with a secret key, or a random id the app stores. See [Entrant ids](https://docs.prizerail.com/getting-started/concepts#make-entrant-ids-with-an-hmac). |
25
25
  | **Entries** | Entries are whole numbers from 1 to 4,294,967,295, and the spread looks deliberate | It notes when every entrant has exactly 1 entry, which is fine if entries aren't used, and a problem if the app meant to send totals and left `entries` out, since an entrant sent without it is set back to 1. It also notes a total that is far above the others. |
26
- | **Draw** (`--draw`, sandbox only) | The open drawing is drawn now, settles, and its proof passes the verify script | Outside the sandbox the API answers `403 sandbox_only`. With no entries the command stops with "Nothing to draw from" before asking (the API's own answer to a bare run is `409 no_entries`). If the API answers 202 with the draw still `entropy_requested`, the command polls it for up to 3 minutes and says so if it hasn't settled. A settled draw can carry an `i` "flagged for staff" note, such as "Campaign has no payout address" in a sandbox campaign with no wallet: the draw and its proof still pass, it just stays `settled` rather than `paid`. |
26
+ | **Draw** (`--draw`, sandbox only) | The open drawing is drawn now, settles, and its proof passes the verify script | Outside the sandbox the API answers `403 sandbox_only`. With no entries the command stops with "Nothing to draw from" before asking (the API's own answer to a bare run is `409 no_entries`). If the API answers 202 with the draw still `entropy_requested`, the command polls it for up to 3 minutes and says so if it hasn't settled. A `✗` saying the drawing "needs attention" before it settles is on Prizerail's side, usually the random value pending past 30 minutes, and nothing in the integration causes it: wait, and tell us if it stays. A settled draw can carry an `i` "flagged for staff" note, such as "Campaign has no payout address" in a sandbox campaign with no wallet: the draw and its proof still pass, it just stays `settled` rather than `paid`. |
27
27
 
28
28
  It prints `✓` for a passing check, `✗` for a failing one, and `i` for a note, and exits 0 only if nothing failed. Report each `✗` and `i` line as printed, with the fix from the table above.
29
29
 
@@ -5,7 +5,7 @@ description: Add Prizerail to an app so its users enter the partner's prize draw
5
5
 
6
6
  # Integrate Prizerail
7
7
 
8
- Prizerail runs prize draws for partner apps. The partner's backend sends each eligible user as an **entrant** with their number of **entries** (chances: 5 entries is five times as likely to win each prize as 1), and at each **cutoff** Prizerail locks the list, draws the winners from it with a public random value, and sends the prizes to the partner's wallet to pay out. The partner never picks winners and never handles the randomness. This skill builds the sending side.
8
+ Prizerail runs prize draws for partner apps. The partner's backend sends each eligible user as an **entrant** with their number of **entries** (chances: 5 entries is five times as likely to be picked as 1), and at each **cutoff** Prizerail locks the list, draws the winners from it with a public random value, and sends the prizes to the partner's wallet to pay out. The partner never picks winners and never handles the randomness. This skill builds the sending side.
9
9
 
10
10
  Read the docs when a detail isn't here: [Send entries](https://docs.prizerail.com/api/send-entries), [Concepts](https://docs.prizerail.com/getting-started/concepts), [Winners and eligibility](https://docs.prizerail.com/campaigns/winners), or everything at [llms-full.txt](https://docs.prizerail.com/llms-full.txt). Whole runnable projects are in [prizerail-examples](https://github.com/coordinationlabs/prizerail-examples): a Next.js app that adds entries as users earn them, a Node worker that sends the day's entries, and the same send in Python.
11
11
 
@@ -96,7 +96,13 @@ A campaign's official rules can narrow these. Read them from the partner, and po
96
96
  Set mode, from a job that runs before each cutoff:
97
97
 
98
98
  ```ts
99
- import { Prizerail, PrizerailCutoffError, hashEntrant, type Entrant } from "prizerail"
99
+ import {
100
+ Prizerail,
101
+ PrizerailCutoffError,
102
+ PrizerailDrawingChangedError,
103
+ hashEntrant,
104
+ type Entrant,
105
+ } from "prizerail"
100
106
 
101
107
  const campaign = new Prizerail({ apiKey: process.env.PRIZERAIL_API_KEY }).campaign(
102
108
  process.env.PRIZERAIL_CAMPAIGN!
@@ -114,8 +120,12 @@ export async function sendTodaysEntries() {
114
120
  const res = await campaign.entries.send(entrants)
115
121
  return { drawingId: res.drawing.id, sent: res.sent, entrantCount: res.entrantCount }
116
122
  } catch (error) {
117
- if (error instanceof PrizerailCutoffError) {
118
- // error.progress.sent entrants were confirmed. Check the rest with entries.list().
123
+ if (
124
+ error instanceof PrizerailCutoffError ||
125
+ error instanceof PrizerailDrawingChangedError
126
+ ) {
127
+ // Both carry progress: error.progress.sent entrants were confirmed in
128
+ // error.progress.drawing. Check the rest with entries.list().
119
129
  throw new Error(`${error.progress.sent} sent to ${error.progress.drawing.id}: ${error.detail}`)
120
130
  }
121
131
  throw error