prizerail 0.5.1 → 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 +39 -2
- package/dist/client.d.ts +8 -8
- package/dist/client.js +11 -19
- package/dist/types.d.ts +0 -18
- package/dist/verify-draw.d.mts +2 -1
- package/dist/verify.d.ts +0 -1
- package/dist/verify.js +1 -2
- package/package.json +20 -2
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
|
|
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,4 +154,35 @@ new Prizerail({
|
|
|
148
154
|
})
|
|
149
155
|
```
|
|
150
156
|
|
|
151
|
-
|
|
157
|
+
## Development
|
|
158
|
+
|
|
159
|
+
```sh
|
|
160
|
+
pnpm install
|
|
161
|
+
pnpm lint
|
|
162
|
+
pnpm type-check
|
|
163
|
+
pnpm test
|
|
164
|
+
pnpm build
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
Issues and pull requests are welcome. For a security problem, email team@coordinationlabs.com instead of opening an issue.
|
|
168
|
+
|
|
169
|
+
`src/verify-draw.mjs` is the public verify script that prizerail.com serves at `/verify/verify-draw.mjs`. Keep the two the same: a change to how draws are checked goes in both, and prizerail.com's tests fail if its copy differs from the one in the published package.
|
|
170
|
+
|
|
171
|
+
### Releasing
|
|
172
|
+
|
|
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).
|
|
174
|
+
2. Merge to `main`.
|
|
175
|
+
3. From an up-to-date `main`, run the checks and publish. `npm publish` builds `dist` first.
|
|
176
|
+
|
|
177
|
+
```sh
|
|
178
|
+
pnpm install --frozen-lockfile
|
|
179
|
+
pnpm lint && pnpm type-check && pnpm test
|
|
180
|
+
npm publish
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
4. Tag the commit you published, so each npm version maps to its source:
|
|
184
|
+
|
|
185
|
+
```sh
|
|
186
|
+
git tag v1.0.0
|
|
187
|
+
git push origin v1.0.0
|
|
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.
|
|
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
|
|
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.
|
|
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
|
-
|
|
80
|
-
|
|
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
|
|
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
|
-
/**
|
|
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 ??
|
|
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
|
|
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
|
|
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-draw.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Types for verify-draw.mjs, the public verify script, which this package
|
|
3
|
-
* ships unchanged
|
|
3
|
+
* ships unchanged. prizerail.com serves the same file at /verify/verify-draw.mjs,
|
|
4
|
+
* and its tests check that copy matches the one in the published package.
|
|
4
5
|
*/
|
|
5
6
|
export type Check = { ok: boolean | null; label: string; detail?: string };
|
|
6
7
|
/** [index, keccak256(entrantId), weight] */
|
package/dist/verify.d.ts
CHANGED
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
|
-
|
|
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,9 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prizerail",
|
|
3
|
-
"version": "0.
|
|
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",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/coordinationlabs/prizerail-js-sdk.git"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/coordinationlabs/prizerail-js-sdk/issues"
|
|
13
|
+
},
|
|
7
14
|
"type": "module",
|
|
8
15
|
"exports": {
|
|
9
16
|
".": {
|
|
@@ -27,6 +34,10 @@
|
|
|
27
34
|
"sideEffects": false,
|
|
28
35
|
"scripts": {
|
|
29
36
|
"build": "node scripts/build.mjs",
|
|
37
|
+
"lint": "biome check .",
|
|
38
|
+
"lint:fix": "biome check --write .",
|
|
39
|
+
"type-check": "tsc --noEmit -p tsconfig.check.json",
|
|
40
|
+
"test": "vitest run",
|
|
30
41
|
"prepublishOnly": "node scripts/build.mjs"
|
|
31
42
|
},
|
|
32
43
|
"keywords": [
|
|
@@ -35,5 +46,12 @@
|
|
|
35
46
|
"prize draw",
|
|
36
47
|
"pyth",
|
|
37
48
|
"verifiable"
|
|
38
|
-
]
|
|
49
|
+
],
|
|
50
|
+
"packageManager": "pnpm@10.18.3",
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@biomejs/biome": "2.5.6",
|
|
53
|
+
"@types/node": "24.13.3",
|
|
54
|
+
"typescript": "6.0.3",
|
|
55
|
+
"vitest": "4.1.11"
|
|
56
|
+
}
|
|
39
57
|
}
|