prizerail 0.3.2 → 0.4.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 +4 -2
- package/dist/cli.js +9 -2
- package/dist/client.d.ts +6 -2
- package/dist/client.js +13 -2
- package/package.json +1 -1
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
|
|
14
|
+
The API is early (v0.x), so names can change between minor versions. 0.4.0 sends a `pr_test_` key to https://test.prizerail.com unless you pass `siteUrl`. 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
|
|
|
@@ -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 test campaign, add `--site https://test.prizerail.com`, or set `PRIZERAIL_API_KEY` to your `pr_test_` key. The same goes for the public helpers without a key: `new Prizerail({ siteUrl: "https://test.prizerail.com" })` reaches test 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://test.prizerail.com for a pr_test_ 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 test campaign, pass
|
|
16
|
+
--site https://test.prizerail.com, or set PRIZERAIL_API_KEY to a pr_test_ 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
|
-
|
|
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.
|
|
4
|
+
export declare const VERSION = "0.4.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
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* Defaults to https://test.prizerail.com for a `pr_test_` 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;
|
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 = "0.4.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;
|
|
@@ -24,6 +24,11 @@ function checkEvents(events) {
|
|
|
24
24
|
if (eventId === "" || e.eventId.length > ID_MAX) {
|
|
25
25
|
throw new TypeError(`Event ${i} (${id}) needs an eventId of ${ID_MAX} characters or fewer: the id of the event behind these entries, the same on every retry.`);
|
|
26
26
|
}
|
|
27
|
+
// An event takes `entries`. The older `weight` is refused by the API in
|
|
28
|
+
// this body, so it's refused here, before any batch is sent.
|
|
29
|
+
if (e.weight !== undefined) {
|
|
30
|
+
throw new TypeError(`Event ${i} (${eventId}): use entries, not the older weight.`);
|
|
31
|
+
}
|
|
27
32
|
const entries = e.entries ?? 1;
|
|
28
33
|
if (!Number.isInteger(entries) || entries < 1 || entries > ENTRIES_MAX) {
|
|
29
34
|
throw new TypeError(`Event ${i} (${eventId}): entries must be a whole number from 1 to ${ENTRIES_MAX}.`);
|
|
@@ -126,12 +131,18 @@ function normalizePage(page) {
|
|
|
126
131
|
next: page.next,
|
|
127
132
|
};
|
|
128
133
|
}
|
|
134
|
+
/** The site a key belongs to: test keys only work on the test site. */
|
|
135
|
+
function defaultSiteUrl(apiKey) {
|
|
136
|
+
return apiKey?.trim().startsWith("pr_test_")
|
|
137
|
+
? "https://test.prizerail.com"
|
|
138
|
+
: "https://www.prizerail.com";
|
|
139
|
+
}
|
|
129
140
|
export class Prizerail {
|
|
130
141
|
siteUrl;
|
|
131
142
|
/** @internal */
|
|
132
143
|
http;
|
|
133
144
|
constructor(options = {}) {
|
|
134
|
-
this.siteUrl = (options.siteUrl ??
|
|
145
|
+
this.siteUrl = (options.siteUrl ?? defaultSiteUrl(options.apiKey)).replace(/\/+$/, "");
|
|
135
146
|
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
136
147
|
if (!fetchImpl)
|
|
137
148
|
throw new Error("No fetch here. Pass options.fetch.");
|