behavior-wrapped 0.11.0 → 0.12.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 +1 -1
- package/dist/assets/index-89_b8V4F.js +10 -0
- package/dist/assets/{index-CkqI9mbd.css → index-Dhat2zC7.css} +1 -1
- package/dist/index.html +2 -2
- package/docs/development.md +4 -2
- package/docs/privacy.md +4 -2
- package/docs/research-donations.md +4 -6
- package/package.json +3 -2
- package/server/cli.mjs +3 -3
- package/server/launcher.mjs +33 -72
- package/dist/assets/index-By4wq-jG.js +0 -11
- package/server/research-donation.mjs +0 -41
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { encryptResearchDonation } from "./research-donation-crypto.mjs";
|
|
2
|
-
import { BEHAVIOR_WRAPPED_ORIGIN } from "./origins.mjs";
|
|
3
|
-
|
|
4
|
-
export const RESEARCH_DONATION_URL = `${BEHAVIOR_WRAPPED_ORIGIN}/v1/research-donations`;
|
|
5
|
-
const REQUEST_TIMEOUT_MS = 30_000;
|
|
6
|
-
|
|
7
|
-
export async function submitResearchDonation(value, { clientId, endpoint = RESEARCH_DONATION_URL, fetchImpl = fetch } = {}) {
|
|
8
|
-
const encryptedDonation = encryptResearchDonation(value);
|
|
9
|
-
let response;
|
|
10
|
-
try {
|
|
11
|
-
response = await fetchImpl(endpoint, {
|
|
12
|
-
method: "POST",
|
|
13
|
-
headers: {
|
|
14
|
-
"content-type": "application/json",
|
|
15
|
-
"x-behavior-wrapped-protocol": "2",
|
|
16
|
-
...(clientId ? { "x-behavior-wrapped-client": clientId } : {}),
|
|
17
|
-
},
|
|
18
|
-
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
|
|
19
|
-
body: JSON.stringify({ encryptedDonation }),
|
|
20
|
-
});
|
|
21
|
-
} catch (error) {
|
|
22
|
-
if (error?.name === "TimeoutError" || error?.name === "AbortError") throw new Error("The research donation timed out. Your data was not confirmed as received.");
|
|
23
|
-
throw new Error("The research donation service is temporarily unavailable.");
|
|
24
|
-
}
|
|
25
|
-
const body = await response.json().catch(() => ({}));
|
|
26
|
-
if (!response.ok) throw new Error(body?.error || "The research donation could not be accepted.");
|
|
27
|
-
return body;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export async function deleteResearchDonation(id, deletionToken, { endpoint = RESEARCH_DONATION_URL, fetchImpl = fetch } = {}) {
|
|
31
|
-
if (!/^[0-9a-f-]{36}$/.test(id || "") || !/^[A-Za-z0-9_-]{43}$/.test(deletionToken || "")) throw new Error("The local deletion receipt is invalid.");
|
|
32
|
-
const response = await fetchImpl(`${endpoint}/${id}`, {
|
|
33
|
-
method: "DELETE",
|
|
34
|
-
headers: { "x-behavior-wrapped-protocol": "2", "x-behavior-wrapped-deletion-token": deletionToken },
|
|
35
|
-
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
|
|
36
|
-
}).catch(() => null);
|
|
37
|
-
if (!response) throw new Error("The research donation service is temporarily unavailable.");
|
|
38
|
-
const body = await response.json().catch(() => ({}));
|
|
39
|
-
if (!response.ok) throw new Error(body?.error || "The research donation could not be deleted.");
|
|
40
|
-
return body;
|
|
41
|
-
}
|