wiki-plugin-shoppe 0.0.16 → 0.0.17
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/package.json +1 -1
- package/server/server.js +9 -11
package/package.json
CHANGED
package/server/server.js
CHANGED
|
@@ -14,9 +14,6 @@ const RECOVER_STRIPE_TMPL = fs.readFileSync(path.join(TEMPLATES_DIR, 'generic-r
|
|
|
14
14
|
const ADDRESS_STRIPE_TMPL = fs.readFileSync(path.join(TEMPLATES_DIR, 'generic-address-stripe.html'), 'utf8');
|
|
15
15
|
const EBOOK_DOWNLOAD_TMPL = fs.readFileSync(path.join(TEMPLATES_DIR, 'ebook-download.html'), 'utf8');
|
|
16
16
|
|
|
17
|
-
function getAllyabaseOrigin() {
|
|
18
|
-
try { return new URL(getSanoraUrl()).origin; } catch { return getSanoraUrl(); }
|
|
19
|
-
}
|
|
20
17
|
|
|
21
18
|
function fillTemplate(tmpl, vars) {
|
|
22
19
|
return Object.entries(vars).reduce((html, [k, v]) =>
|
|
@@ -48,9 +45,9 @@ function getSanoraUrl() {
|
|
|
48
45
|
return `http://localhost:${process.env.SANORA_PORT || 7243}`;
|
|
49
46
|
}
|
|
50
47
|
|
|
51
|
-
function getAddieUrl() {
|
|
52
|
-
|
|
53
|
-
|
|
48
|
+
function getAddieUrl(wikiOrigin) {
|
|
49
|
+
if (wikiOrigin) return `${wikiOrigin}/plugin/allyabase/addie`;
|
|
50
|
+
try { return new URL(getSanoraUrl()).origin + '/plugin/allyabase/addie'; } catch { /* fall through */ }
|
|
54
51
|
return `http://localhost:${process.env.ADDIE_PORT || 3005}`;
|
|
55
52
|
}
|
|
56
53
|
|
|
@@ -63,7 +60,7 @@ function saveBuyers(buyers) {
|
|
|
63
60
|
fs.writeFileSync(BUYERS_FILE, JSON.stringify(buyers, null, 2));
|
|
64
61
|
}
|
|
65
62
|
|
|
66
|
-
async function getOrCreateBuyerAddieUser(recoveryKey, productId) {
|
|
63
|
+
async function getOrCreateBuyerAddieUser(recoveryKey, productId, wikiOrigin) {
|
|
67
64
|
const buyerKey = recoveryKey + productId;
|
|
68
65
|
const buyers = loadBuyers();
|
|
69
66
|
if (buyers[buyerKey]) return buyers[buyerKey];
|
|
@@ -74,7 +71,7 @@ async function getOrCreateBuyerAddieUser(recoveryKey, productId) {
|
|
|
74
71
|
const message = timestamp + addieKeys.pubKey;
|
|
75
72
|
const signature = await sessionless.sign(message);
|
|
76
73
|
|
|
77
|
-
const resp = await fetch(`${getAddieUrl()}/user/create`, {
|
|
74
|
+
const resp = await fetch(`${getAddieUrl(wikiOrigin)}/user/create`, {
|
|
78
75
|
method: 'PUT',
|
|
79
76
|
headers: { 'Content-Type': 'application/json' },
|
|
80
77
|
body: JSON.stringify({ timestamp, pubKey: addieKeys.pubKey, signature })
|
|
@@ -201,7 +198,7 @@ async function addieCreateUser() {
|
|
|
201
198
|
const message = timestamp + addieKeys.pubKey;
|
|
202
199
|
const signature = await sessionless.sign(message);
|
|
203
200
|
|
|
204
|
-
const resp = await fetch(`${
|
|
201
|
+
const resp = await fetch(`${getAddieUrl()}/user/create`, {
|
|
205
202
|
method: 'PUT',
|
|
206
203
|
headers: { 'Content-Type': 'application/json' },
|
|
207
204
|
body: JSON.stringify({ timestamp, pubKey: addieKeys.pubKey, signature })
|
|
@@ -1082,6 +1079,7 @@ async function startServer(params) {
|
|
|
1082
1079
|
if (!recoveryKey || !productId) return res.status(400).json({ error: 'recoveryKey and productId required' });
|
|
1083
1080
|
|
|
1084
1081
|
const sanoraUrlInternal = getSanoraUrl();
|
|
1082
|
+
const wikiOrigin = `${req.protocol}://${req.get('host')}`;
|
|
1085
1083
|
const recoveryHash = recoveryKey + productId;
|
|
1086
1084
|
|
|
1087
1085
|
// Check if already purchased
|
|
@@ -1096,11 +1094,11 @@ async function startServer(params) {
|
|
|
1096
1094
|
const amount = product?.price || 0;
|
|
1097
1095
|
|
|
1098
1096
|
// Create/retrieve buyer Addie user
|
|
1099
|
-
const buyer = await getOrCreateBuyerAddieUser(recoveryKey, productId);
|
|
1097
|
+
const buyer = await getOrCreateBuyerAddieUser(recoveryKey, productId, wikiOrigin);
|
|
1100
1098
|
|
|
1101
1099
|
// Create Stripe intent via Addie
|
|
1102
1100
|
const payees = tenant.addieKeys ? [{ pubKey: tenant.addieKeys.pubKey, amount }] : [];
|
|
1103
|
-
const intentResp = await fetch(`${getAddieUrl()}/user/${buyer.uuid}/processor/stripe/intent`, {
|
|
1101
|
+
const intentResp = await fetch(`${getAddieUrl(wikiOrigin)}/user/${buyer.uuid}/processor/stripe/intent`, {
|
|
1104
1102
|
method: 'PUT',
|
|
1105
1103
|
headers: { 'Content-Type': 'application/json' },
|
|
1106
1104
|
body: JSON.stringify({ timestamp: Date.now().toString(), amount, currency: 'USD', payees })
|