prizerail 0.3.1 → 0.3.3
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 +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/client.js +26 -1
- 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()`,
|
|
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 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
|
|
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.3.
|
|
4
|
+
export declare const VERSION = "0.3.3";
|
|
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 = {
|
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.3.
|
|
4
|
+
export const VERSION = "0.3.3";
|
|
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,10 +24,23 @@ 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}.`);
|
|
30
35
|
}
|
|
36
|
+
if (e.displayName != null && typeof e.displayName !== "string") {
|
|
37
|
+
throw new TypeError(`Event ${i} (${eventId}): displayName must be a string.`);
|
|
38
|
+
}
|
|
39
|
+
if (e.avatarUrl != null &&
|
|
40
|
+
e.avatarUrl !== "" &&
|
|
41
|
+
!isAvatarUrl(e.avatarUrl)) {
|
|
42
|
+
throw new TypeError(`Event ${i} (${eventId}): avatarUrl must be an https URL of ${AVATAR_URL_MAX} characters or fewer.`);
|
|
43
|
+
}
|
|
31
44
|
const was = seen.get(eventId);
|
|
32
45
|
if (was &&
|
|
33
46
|
(was.entrantId.trim() !== id || (was.entries ?? 1) !== entries)) {
|
|
@@ -36,6 +49,18 @@ function checkEvents(events) {
|
|
|
36
49
|
seen.set(eventId, e);
|
|
37
50
|
}
|
|
38
51
|
}
|
|
52
|
+
/** The API's rule for an avatar: https, and 2,048 characters at most. */
|
|
53
|
+
const AVATAR_URL_MAX = 2048;
|
|
54
|
+
function isAvatarUrl(value) {
|
|
55
|
+
if (typeof value !== "string" || value.length > AVATAR_URL_MAX)
|
|
56
|
+
return false;
|
|
57
|
+
try {
|
|
58
|
+
return new URL(value).protocol === "https:";
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
39
64
|
/** An increment response, checked before its counts are added up. */
|
|
40
65
|
function checkIncrementResponse(r) {
|
|
41
66
|
const res = r;
|