prizerail 0.5.2 → 1.0.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,13 @@ 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.5.2 changes no code: it is the first release from the public repo, and links to it from npm. 0.5.1 adds the `skipped` drawing status. 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).
14
+ The API follows semantic versioning from 1.0.0: a breaking change only comes in a new major version. 1.0.0 drops the names deprecated in 0.2.0. Send `entries`, not `weight`. Read `entrantCount` and `totalEntries`, not `count` and `totalWeight`, and a page's `entrants`, not its `entries` list. An entrant row and `wasEntered()` give `entries`, not `weight`. The `Entry` and `SentEntry` types are now `Entrant` and `SentEntrant`. Each change is in the [changelog](https://docs.prizerail.com/changelog).
15
+
16
+ ## Use it from your server
17
+
18
+ Call Prizerail from your backend, or a proxy you run, never from a website or a mobile app. The API key can send entries for every campaign under your account, and anything shipped to a browser or an app can be read out of it. Your app tells your server what a user did, and your server sends the entries. To show results in your app, read them on your server and pass them on, or read the public proof, which needs no key.
19
+
20
+ The verify helpers (`verifyDraw`, `wasEntered` and `npx prizerail verify`) take no key, so they're safe to run anywhere.
15
21
 
16
22
  ## Send entries
17
23
 
@@ -148,8 +154,6 @@ new Prizerail({
148
154
  })
149
155
  ```
150
156
 
151
- Keep the API key on your server. It can send entries for every campaign under your account.
152
-
153
157
  ## Development
154
158
 
155
159
  ```sh
@@ -166,7 +170,7 @@ Issues and pull requests are welcome. For a security problem, email team@coordin
166
170
 
167
171
  ### Releasing
168
172
 
169
- 1. Bump `version` in `package.json` and `VERSION` in `src/client.ts`, and add a line to the change list above.
173
+ 1. Bump `version` in `package.json` and `VERSION` in `src/client.ts`, and add the release to the [changelog](https://docs.prizerail.com/changelog).
170
174
  2. Merge to `main`.
171
175
  3. From an up-to-date `main`, run the checks and publish. `npm publish` builds `dist` first.
172
176
 
@@ -179,6 +183,6 @@ Issues and pull requests are welcome. For a security problem, email team@coordin
179
183
  4. Tag the commit you published, so each npm version maps to its source:
180
184
 
181
185
  ```sh
182
- git tag v0.5.2
183
- git push origin v0.5.2
186
+ git tag v1.0.0
187
+ git push origin v1.0.0
184
188
  ```
package/dist/client.d.ts CHANGED
@@ -1,7 +1,7 @@
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.5.2";
4
+ export declare const VERSION = "1.0.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 = {
@@ -32,12 +32,6 @@ export type SendOptions = {
32
32
  */
33
33
  cutoffMarginMs?: number;
34
34
  };
35
- /**
36
- * `entrantCount` and `totalEntries` are the drawing's totals after the last
37
- * batch. `added`, `updated` and `unchanged` sum what each batch reported, so
38
- * a batch stored before its response was lost, then retried, counts as
39
- * unchanged. Reconcile with `entrantCount`, not with `added`.
40
- */
41
35
  /**
42
36
  * What `entries.increment()` did. Its batches go to the drawing taking
43
37
  * entries when each arrives, so a cutoff mid-way splits them between
@@ -59,6 +53,12 @@ export type IncrementResult = {
59
53
  */
60
54
  drawings: DrawingRef[];
61
55
  };
56
+ /**
57
+ * `entrantCount` and `totalEntries` are the drawing's totals after the last
58
+ * batch. `added`, `updated` and `unchanged` sum what each batch reported, so
59
+ * a batch stored before its response was lost, then retried, counts as
60
+ * unchanged. Reconcile with `entrantCount`, not with `added`.
61
+ */
62
62
  export type SendResult = SendEntriesResponse & {
63
63
  /** Entrants in the batches the drawing confirmed. */
64
64
  sent: number;
@@ -94,7 +94,7 @@ export declare class EntriesClient {
94
94
  /**
95
95
  * Sends entries to one drawing, in requests of 1,000, retrying 429s, 5xx
96
96
  * and network errors. Sending an entrant again before the cutoff only sets
97
- * their weight, so a retry is safe, but a retry after the cutoff would go
97
+ * their entries, so a retry is safe, but a retry after the cutoff would go
98
98
  * to the next drawing. So the send is pinned to one drawing: it stops with
99
99
  * a PrizerailCutoffError rather than send or retry near its cutoff, and
100
100
  * with a PrizerailDrawingChangedError if a batch lands anywhere else.
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.5.2";
4
+ export const VERSION = "1.0.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;
@@ -76,13 +76,10 @@ function checkIncrementResponse(r) {
76
76
  function toWire(entrant) {
77
77
  if (typeof entrant === "string")
78
78
  return entrant;
79
- const { weight, ...rest } = entrant;
80
- if (weight === undefined)
81
- return rest;
82
- if (rest.entries !== undefined) {
83
- throw new TypeError(`Entrant ${rest.entrantId} has both entries and weight. Send entries.`);
79
+ if (entrant.weight !== undefined) {
80
+ throw new TypeError(`Entrant ${entrant.entrantId}: use entries, not the older weight.`);
84
81
  }
85
- return { ...rest, entries: weight };
82
+ return entrant;
86
83
  }
87
84
  const badResponse = (detail) => new PrizerailError(0, "invalid_response", detail);
88
85
  const isCount = (v) => typeof v === "number" && Number.isSafeInteger(v) && v >= 0;
@@ -99,15 +96,11 @@ function pick(r, current, old) {
99
96
  }
100
97
  return value;
101
98
  }
102
- /** Both names for the totals, from whichever the server sent. */
99
+ /** The totals under their current names, from whichever the server sent. */
103
100
  function totals(r) {
104
- const entrantCount = pick(r, "entrantCount", "count");
105
- const totalEntries = pick(r, "totalEntries", "totalWeight");
106
101
  return {
107
- entrantCount,
108
- totalEntries,
109
- count: entrantCount,
110
- totalWeight: totalEntries,
102
+ entrantCount: pick(r, "entrantCount", "count"),
103
+ totalEntries: pick(r, "totalEntries", "totalWeight"),
111
104
  };
112
105
  }
113
106
  /** A page with the current names filled in, from either server shape. */
@@ -116,18 +109,17 @@ function normalizePage(page) {
116
109
  if (!Array.isArray(rows)) {
117
110
  throw badResponse("The response has no entrants list.");
118
111
  }
119
- const entrants = rows.map(e => {
120
- const n = e.entries ?? e.weight;
112
+ const entrants = rows.map(({ weight, ...e }) => {
113
+ const n = e.entries ?? weight;
121
114
  if (!isCount(n) || n < 1 || typeof e.entrantId !== "string") {
122
115
  throw badResponse("An entrant in the response has no valid id or entries.");
123
116
  }
124
- return { ...e, entries: n, weight: n };
117
+ return { ...e, entries: n };
125
118
  });
126
119
  return {
127
120
  drawing: page.drawing,
128
121
  ...totals(page),
129
122
  entrants,
130
- entries: entrants,
131
123
  next: page.next,
132
124
  };
133
125
  }
@@ -210,7 +202,7 @@ export class EntriesClient {
210
202
  /**
211
203
  * Sends entries to one drawing, in requests of 1,000, retrying 429s, 5xx
212
204
  * and network errors. Sending an entrant again before the cutoff only sets
213
- * their weight, so a retry is safe, but a retry after the cutoff would go
205
+ * their entries, so a retry is safe, but a retry after the cutoff would go
214
206
  * to the next drawing. So the send is pinned to one drawing: it stops with
215
207
  * a PrizerailCutoffError rather than send or retry near its cutoff, and
216
208
  * with a PrizerailDrawingChangedError if a batch lands anywhere else.
package/dist/types.d.ts CHANGED
@@ -120,15 +120,11 @@ export type Entrant = string | {
120
120
  entrantId: string;
121
121
  /** Their number of entries, a whole number from 1. Leave it out and it's 1. */
122
122
  entries?: number;
123
- /** @deprecated Use `entries`. Still sent as `entries`. */
124
- weight?: number;
125
123
  /** Up to 40 characters. */
126
124
  displayName?: string;
127
125
  /** https, up to 2,048 characters. */
128
126
  avatarUrl?: string;
129
127
  };
130
- /** @deprecated Use `Entrant`. */
131
- export type Entry = Entrant;
132
128
  /**
133
129
  * One event that earns an entrant entries, for `entries.increment()`. The
134
130
  * `eventId` names the event (an order id, a referral id, or a UUID made once
@@ -155,10 +151,6 @@ export type SendEntriesResponse = {
155
151
  entrantCount: number;
156
152
  /** The drawing's total entries so far. */
157
153
  totalEntries: number;
158
- /** @deprecated Use `entrantCount`. */
159
- count: number;
160
- /** @deprecated Use `totalEntries`. */
161
- totalWeight: number;
162
154
  /** Increment mode: events this campaign had already seen, so ignored. */
163
155
  duplicates?: number;
164
156
  };
@@ -166,16 +158,12 @@ export type SentEntrant = {
166
158
  entrantId: string;
167
159
  /** Their number of entries. */
168
160
  entries: number;
169
- /** @deprecated Use `entries`. */
170
- weight: number;
171
161
  displayName: string | null;
172
162
  avatarUrl: string | null;
173
163
  /** Place in the locked list. Null until the cutoff. */
174
164
  position: number | null;
175
165
  receivedAt: string;
176
166
  };
177
- /** @deprecated Use `SentEntrant`. */
178
- export type SentEntry = SentEntrant;
179
167
  export type EntriesPage = {
180
168
  drawing: DrawingRef & {
181
169
  status: DrawingStatus;
@@ -184,12 +172,6 @@ export type EntriesPage = {
184
172
  totalEntries: number;
185
173
  /** In arrival order, the order the list locks in. */
186
174
  entrants: SentEntrant[];
187
- /** @deprecated Use `entrantCount`. */
188
- count: number;
189
- /** @deprecated Use `totalEntries`. */
190
- totalWeight: number;
191
- /** @deprecated Use `entrants`, the same list. */
192
- entries: SentEntrant[];
193
175
  /** Pass as `after` for the next page. Null on the last. */
194
176
  next: string | null;
195
177
  };
package/dist/verify.d.ts CHANGED
@@ -61,5 +61,4 @@ export declare function verifyDraw(source: string | DrawProof, { entrants, proof
61
61
  export declare function wasEntered(entrantId: string, rows: EntrantRow[]): {
62
62
  index: number;
63
63
  entries: number;
64
- weight: number;
65
64
  } | null;
package/dist/verify.js CHANGED
@@ -65,6 +65,5 @@ export async function verifyDraw(source, { entrants, proofUrl, fetch: fetchImpl
65
65
  export function wasEntered(entrantId, rows) {
66
66
  const hash = winnerHash(entrantId);
67
67
  const row = rows.find(r => r[1].toLowerCase() === hash);
68
- // The proof calls an entrant's entries their weight. Both names, for now.
69
- return row ? { index: row[0], entries: row[2], weight: row[2] } : null;
68
+ return row ? { index: row[0], entries: row[2] } : null;
70
69
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prizerail",
3
- "version": "0.5.2",
3
+ "version": "1.0.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",