prizerail 1.1.1 → 1.2.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.
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.1";
4
+ export declare const VERSION = "1.2.1";
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.1";
4
+ export const VERSION = "1.2.1";
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prizerail",
3
- "version": "1.1.1",
3
+ "version": "1.2.1",
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.1",
3
+ "version": "1.2.1",
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",
@@ -32,6 +32,7 @@ It prints `✓` for a passing check, `✗` for a failing one, and `i` for a note
32
32
  - **No entries in the open drawing** with a passing key and campaign: the sender hasn't run yet, or it's pointed at another campaign or the other environment. Check `PRIZERAIL_CAMPAIGN` and the key's prefix against the site.
33
33
  - **Entries in the last drawing but not this one:** entries land in the drawing whose cutoff is next when they arrive, and totals don't carry over. A daily job must run before each cutoff.
34
34
  - **Every entrant at 1 entry** when the app rewards actions: set mode sends each entrant's total, so `entries` has to be sent every time. Or the app meant increment mode.
35
+ - **One user's entries missing:** look that id up with `campaign.drawings.entrant(drawingId, entrantId)`, or `GET /api/v1/campaigns/{slug}/drawings/{id}/entrant?entrantId=…` with a `+` sent as `%2B`. `entered: false` is a `200`, not an error: the entries went to another drawing, or never arrived.
35
36
  - **Fewer entrants than expected:** the eligibility filter, or an `eventId` reused across different events (`409 event_conflict`, nothing in that request stored). Look at the sender's logs for `409`s.
36
37
  - **A sandbox draw with winners:** the integration works end to end. `npx prizerail verify <slug> <drawing id>` checks any draw again from its public proof.
37
38
 
@@ -5,7 +5,7 @@ description: "Check the status of a Prizerail campaign's draws (whether a draw i
5
5
 
6
6
  # Prizerail draws: status and verification
7
7
 
8
- Prizerail runs prize draws for partner apps. Through each period the partner sends Prizerail its entrants. At the cutoff Prizerail locks the entrant list, a random value draws the winners from it and decides each winner's prize from the campaign's prize table, and the prizes are sent to the partner to pay out. Everything below uses public endpoints: no keys, no accounts.
8
+ Prizerail runs prize draws for partner apps. Through each period the partner sends Prizerail its entrants. At the cutoff Prizerail locks the entrant list, a random value draws the winners from it and decides each winner's prize from the campaign's prize table, and the prizes are sent to the partner to pay out. Everything below uses public endpoints, with no keys or accounts, except the one lookup marked as needing the partner's API key.
9
9
 
10
10
  **Never compute the hashes yourself.** keccak256 can't be done reliably by reasoning, and Python's `hashlib.sha3_256` is a different hash (different padding) that gives different answers. Run the verify script below and report what it prints.
11
11
 
@@ -96,6 +96,11 @@ If the user can't run code, the campaign page has a "Verify in your browser" but
96
96
 
97
97
  To cross-check with a library instead, viem's `keccak256(encodeAbiParameters(...))` with the types above gives the same values.
98
98
 
99
+ ## Check someone was in a draw
100
+
101
+ - **With no key:** once a draw is drawn, `verifyDraw(proofUrl)` and then `wasEntered(entrantId, result.entrants)` from the `prizerail` package find their row in the published list. Only read the answer when `result.ok` is true and `result.entrants` is there: `verifyDraw` still returns the rows when a check fails, and `wasEntered` only searches them. Otherwise say their entry couldn't be verified, not that they weren't in it. That is the independent check, and it gives their `entries` and index only.
102
+ - **With the partner's API key:** `new Prizerail({ apiKey }).campaign(slug).drawings.entrant(drawingId, entrantId)`, which picks the site from the key, or `GET /api/v1/campaigns/{slug}/drawings/{id}/entrant?entrantId=…` with a `+` sent as `%2B`, on the key's own site (`https://sandbox.prizerail.com` for a `pr_sandbox_` key), says what Prizerail received for any drawing, open ones too, and what they won. It is Prizerail's own record, not an independent check. `entered: false` is an answer, not an error. `winner` is `null` for everyone until `drawn` is true, so check `drawn` before reading a `null` winner as a loss, and a `skipped` drawing was never drawn. In a guarantee draw everyone has 1 entry.
103
+
99
104
  ## Gotchas
100
105
 
101
106
  - **The index is the order, not the row.** A shuffled `entrants.json` gives the same root and winners. A duplicate, missing or out-of-range index makes the list invalid, and the verify script reports it.
@@ -167,6 +167,21 @@ Write them in the project's own test framework. Each one guards a rule above:
167
167
 
168
168
  With a `pr_sandbox_` key and a sandbox campaign, send a few entrants and then run `npx prizerail check <slug> --draw` (the `prizerail-check` skill). It checks the key, the campaign and what was sent, then **draws now**: the drawing locks, settles and pays within seconds, and its proof is verified, so the whole integration is seen to pass. Draw now consumes the drawing's entries and opens a fresh, empty one, so send entries again before any second draw. To draw by hand instead, use `campaign.drawings.run(drawingId)` in the SDK, `POST /campaigns/{slug}/drawings/{id}/run`, or the **Draw now** button on the drawing in the sandbox portal, then `campaign.drawings.latest()` shows the winners and `npx prizerail verify <slug> <drawing id>` checks the proof.
169
169
 
170
+ ## 9. When a user asks whether their entries counted
171
+
172
+ Look them up in that drawing rather than paging `entries.all()`, from the server like every call with the key. The drawing taking entries now is `(await campaign.entries.openDrawing()).id`, or `drawing.id` from a `send()` result. Earlier ones come from `campaign.drawings.list()`, newest first, and open ones from `campaign.drawings.list({ status: "open" })`, soonest cutoff first, so the next one is the open drawing after it.
173
+
174
+ ```ts
175
+ const entrantId = await hashEntrant(user.id, process.env.ENTRANT_ID_KEY!)
176
+ const found = await campaign.drawings.entrant(drawingId, entrantId)
177
+ // { drawing, entrantId, entered, entries, position, receivedAt, drawn, winner }
178
+ ```
179
+
180
+ - `entered: false` is an answer, not an error: entries sent after the cutoff went to the next drawing, and ones that failed to send aren't anywhere. Check the next drawing and the sender's logs.
181
+ - `winner` is `null` for everyone until `drawn` is true, so check `drawn` before reading a `null` winner as a loss. A `skipped` drawing (`drawing.status`) was never drawn, so there's no winner to wait for.
182
+ - `position` is `null` until the drawing locks. In a guarantee draw (`drawing.kind` is `"guarantee"`) everyone has 1 entry, `position` is set from the start, and `receivedAt` is when the guarantee draw was made.
183
+ - Plain HTTP: `GET {base}/campaigns/{slug}/drawings/{id}/entrant?entrantId=…`, URL-encoded, so a `+` goes as `%2B`. A bare `+` reads as a space, and the lookup finds no one.
184
+
170
185
  ## Checklist before handing back
171
186
 
172
187
  - [ ] Mode chosen and explained in a comment at the sender