wiki-plugin-shoppe 0.0.17 → 0.0.19

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/server/server.js +11 -8
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wiki-plugin-shoppe",
3
- "version": "0.0.17",
3
+ "version": "0.0.19",
4
4
  "description": "Multi-tenant digital goods shoppe for federated wiki, powered by Sanora",
5
5
  "keywords": [
6
6
  "wiki",
package/server/server.js CHANGED
@@ -45,8 +45,7 @@ function getSanoraUrl() {
45
45
  return `http://localhost:${process.env.SANORA_PORT || 7243}`;
46
46
  }
47
47
 
48
- function getAddieUrl(wikiOrigin) {
49
- if (wikiOrigin) return `${wikiOrigin}/plugin/allyabase/addie`;
48
+ function getAddieUrl() {
50
49
  try { return new URL(getSanoraUrl()).origin + '/plugin/allyabase/addie'; } catch { /* fall through */ }
51
50
  return `http://localhost:${process.env.ADDIE_PORT || 3005}`;
52
51
  }
@@ -60,7 +59,7 @@ function saveBuyers(buyers) {
60
59
  fs.writeFileSync(BUYERS_FILE, JSON.stringify(buyers, null, 2));
61
60
  }
62
61
 
63
- async function getOrCreateBuyerAddieUser(recoveryKey, productId, wikiOrigin) {
62
+ async function getOrCreateBuyerAddieUser(recoveryKey, productId) {
64
63
  const buyerKey = recoveryKey + productId;
65
64
  const buyers = loadBuyers();
66
65
  if (buyers[buyerKey]) return buyers[buyerKey];
@@ -71,7 +70,7 @@ async function getOrCreateBuyerAddieUser(recoveryKey, productId, wikiOrigin) {
71
70
  const message = timestamp + addieKeys.pubKey;
72
71
  const signature = await sessionless.sign(message);
73
72
 
74
- const resp = await fetch(`${getAddieUrl(wikiOrigin)}/user/create`, {
73
+ const resp = await fetch(`${getAddieUrl()}/user/create`, {
75
74
  method: 'PUT',
76
75
  headers: { 'Content-Type': 'application/json' },
77
76
  body: JSON.stringify({ timestamp, pubKey: addieKeys.pubKey, signature })
@@ -1079,7 +1078,6 @@ async function startServer(params) {
1079
1078
  if (!recoveryKey || !productId) return res.status(400).json({ error: 'recoveryKey and productId required' });
1080
1079
 
1081
1080
  const sanoraUrlInternal = getSanoraUrl();
1082
- const wikiOrigin = `${req.protocol}://${req.get('host')}`;
1083
1081
  const recoveryHash = recoveryKey + productId;
1084
1082
 
1085
1083
  // Check if already purchased
@@ -1094,14 +1092,19 @@ async function startServer(params) {
1094
1092
  const amount = product?.price || 0;
1095
1093
 
1096
1094
  // Create/retrieve buyer Addie user
1097
- const buyer = await getOrCreateBuyerAddieUser(recoveryKey, productId, wikiOrigin);
1095
+ const buyer = await getOrCreateBuyerAddieUser(recoveryKey, productId);
1098
1096
 
1099
1097
  // Create Stripe intent via Addie
1100
1098
  const payees = tenant.addieKeys ? [{ pubKey: tenant.addieKeys.pubKey, amount }] : [];
1101
- const intentResp = await fetch(`${getAddieUrl(wikiOrigin)}/user/${buyer.uuid}/processor/stripe/intent`, {
1099
+ const buyerKeys = { pubKey: buyer.pubKey, privateKey: buyer.privateKey };
1100
+ sessionless.getKeys = () => buyerKeys;
1101
+ const intentTimestamp = Date.now().toString();
1102
+ const intentMessage = intentTimestamp + buyer.uuid + amount + 'USD';
1103
+ const intentSignature = await sessionless.sign(intentMessage);
1104
+ const intentResp = await fetch(`${getAddieUrl()}/user/${buyer.uuid}/processor/stripe/intent`, {
1102
1105
  method: 'PUT',
1103
1106
  headers: { 'Content-Type': 'application/json' },
1104
- body: JSON.stringify({ timestamp: Date.now().toString(), amount, currency: 'USD', payees })
1107
+ body: JSON.stringify({ timestamp: intentTimestamp, amount, currency: 'USD', payees, signature: intentSignature })
1105
1108
  });
1106
1109
 
1107
1110
  const intentJson = await intentResp.json();