@blockonomics/medusa-payment-blockonomics 0.0.0-stage → 1.0.1
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/.medusa/server/src/admin/index.js +134 -0
- package/.medusa/server/src/admin/index.mjs +135 -0
- package/.medusa/server/src/api/hooks/blockonomics/[provider]/route.js +48 -0
- package/.medusa/server/src/api/store/blockonomics/payment-sessions/[id]/route.js +39 -0
- package/.medusa/server/src/providers/blockonomics/core/blockonomics-base.js +458 -0
- package/.medusa/server/src/providers/blockonomics/index.js +9 -0
- package/.medusa/server/src/providers/blockonomics/services/blockonomics-provider.js +15 -0
- package/.medusa/server/src/providers/blockonomics/services/index.js +9 -0
- package/.medusa/server/src/providers/blockonomics/types/index.js +29 -0
- package/.medusa/server/src/providers/blockonomics/utils/amounts.js +36 -0
- package/.medusa/server/src/providers/blockonomics/utils/blockonomics-client.js +78 -0
- package/.medusa/server/src/providers/blockonomics/utils/index.js +19 -0
- package/.medusa/server/src/subscribers/blockonomics-webhook.js +74 -0
- package/LICENSE +21 -0
- package/README.md +140 -2
- package/bin/generate-callback-secret.js +6 -0
- package/package.json +88 -6
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
3
|
+
const adminSdk = require("@medusajs/admin-sdk");
|
|
4
|
+
const ui = require("@medusajs/ui");
|
|
5
|
+
const react = require("react");
|
|
6
|
+
const NEW = 0;
|
|
7
|
+
const IN_PROGRESS = 1;
|
|
8
|
+
const SETTLED = 2;
|
|
9
|
+
const BlockonomicsPaymentWidget = ({
|
|
10
|
+
data: order
|
|
11
|
+
}) => {
|
|
12
|
+
const [sessions, setSessions] = react.useState([]);
|
|
13
|
+
react.useEffect(() => {
|
|
14
|
+
let active = true;
|
|
15
|
+
fetch(
|
|
16
|
+
`${""}/admin/orders/${order.id}?fields=id,*payment_collections.payment_sessions`,
|
|
17
|
+
{ credentials: "include" }
|
|
18
|
+
).then((res) => {
|
|
19
|
+
if (!res.ok) {
|
|
20
|
+
throw new Error(`${res.status}`);
|
|
21
|
+
}
|
|
22
|
+
return res.json();
|
|
23
|
+
}).then(({ order: withSessions }) => {
|
|
24
|
+
if (!active) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
setSessions(
|
|
28
|
+
(withSessions.payment_collections ?? []).flatMap((collection) => collection.payment_sessions ?? []).filter(
|
|
29
|
+
(session) => session.provider_id.startsWith("pp_blockonomics_")
|
|
30
|
+
).map((session) => session.data).filter(
|
|
31
|
+
(data) => data?.payments?.some(
|
|
32
|
+
(payment) => payment.payment_status !== NEW
|
|
33
|
+
)
|
|
34
|
+
)
|
|
35
|
+
);
|
|
36
|
+
}).catch(() => {
|
|
37
|
+
});
|
|
38
|
+
return () => {
|
|
39
|
+
active = false;
|
|
40
|
+
};
|
|
41
|
+
}, [order.id]);
|
|
42
|
+
if (!sessions.length) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "divide-y p-0", children: [
|
|
46
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", children: "Bitcoin payment" }) }),
|
|
47
|
+
sessions.map((data, i) => {
|
|
48
|
+
const money = (amount) => new Intl.NumberFormat(void 0, {
|
|
49
|
+
style: "currency",
|
|
50
|
+
currency: data.currency_code.toUpperCase()
|
|
51
|
+
}).format(amount);
|
|
52
|
+
const payments = data.payments;
|
|
53
|
+
const active = payments[payments.length - 1];
|
|
54
|
+
const confirming = active.payment_status === IN_PROGRESS;
|
|
55
|
+
const difference = data.paid_fiat - data.fiat_amount;
|
|
56
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-3 px-6 py-4", children: [
|
|
57
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between", children: [
|
|
58
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", weight: "plus", children: [
|
|
59
|
+
"Received ",
|
|
60
|
+
money(data.paid_fiat),
|
|
61
|
+
" of ",
|
|
62
|
+
money(data.fiat_amount)
|
|
63
|
+
] }),
|
|
64
|
+
confirming && /* @__PURE__ */ jsxRuntime.jsx(ui.Badge, { color: "blue", size: "2xsmall", children: "Confirming" }),
|
|
65
|
+
data.overpaid && /* @__PURE__ */ jsxRuntime.jsx(ui.Badge, { color: "orange", size: "2xsmall", children: "Overpaid" }),
|
|
66
|
+
data.underpaid && !confirming && /* @__PURE__ */ jsxRuntime.jsx(ui.Badge, { color: "red", size: "2xsmall", children: "Underpaid" })
|
|
67
|
+
] }),
|
|
68
|
+
confirming && /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "A payment was sent and is waiting for confirmations on the Bitcoin network. The order is marked as paid once it confirms; nothing needs to be done." }),
|
|
69
|
+
data.underpaid && !confirming && /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
|
|
70
|
+
"The customer still owes ",
|
|
71
|
+
money(-difference),
|
|
72
|
+
". They can pay it from the checkout page, and the order is marked as paid once it arrives. If they don't, contact them, or cancel the order and send back what they paid from your wallet."
|
|
73
|
+
] }),
|
|
74
|
+
data.overpaid && /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
|
|
75
|
+
"The customer sent ",
|
|
76
|
+
money(difference),
|
|
77
|
+
" more than the order total. Nothing is refunded automatically: decide whether to send the difference back from your wallet or compensate the customer another way."
|
|
78
|
+
] }),
|
|
79
|
+
payments.map((payment) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-1", children: [
|
|
80
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "xsmall", className: "text-ui-fg-subtle break-all", children: payment.address }),
|
|
81
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "xsmall", className: "text-ui-fg-subtle break-all", children: [
|
|
82
|
+
describe(payment, money),
|
|
83
|
+
payment.txid ? ` · txid ${payment.txid}` : ""
|
|
84
|
+
] })
|
|
85
|
+
] }, payment.address))
|
|
86
|
+
] }, i);
|
|
87
|
+
})
|
|
88
|
+
] });
|
|
89
|
+
};
|
|
90
|
+
function describe(payment, money) {
|
|
91
|
+
switch (payment.payment_status) {
|
|
92
|
+
case SETTLED:
|
|
93
|
+
return `${(payment.paid_satoshis / 1e8).toFixed(8)} BTC, worth ${money(payment.paid_fiat)}`;
|
|
94
|
+
case IN_PROGRESS:
|
|
95
|
+
return `Payment seen, ${payment.confirmations} ${payment.confirmations === 1 ? "confirmation" : "confirmations"} so far`;
|
|
96
|
+
default:
|
|
97
|
+
return `Waiting for ${money(payment.expected_fiat)}`;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
adminSdk.defineWidgetConfig({
|
|
101
|
+
zone: "order.details.side.after"
|
|
102
|
+
});
|
|
103
|
+
const i18nTranslations0 = {};
|
|
104
|
+
const widgetModule = { widgets: [
|
|
105
|
+
{
|
|
106
|
+
Component: BlockonomicsPaymentWidget,
|
|
107
|
+
zone: ["order.details.side.after"],
|
|
108
|
+
widgetId: "Widget-fc36"
|
|
109
|
+
}
|
|
110
|
+
] };
|
|
111
|
+
const routeModule = {
|
|
112
|
+
routes: []
|
|
113
|
+
};
|
|
114
|
+
const menuItemModule = {
|
|
115
|
+
menuItems: []
|
|
116
|
+
};
|
|
117
|
+
const formModule = { customFields: {} };
|
|
118
|
+
const displayModule = {
|
|
119
|
+
displays: {}
|
|
120
|
+
};
|
|
121
|
+
const i18nModule = { resources: i18nTranslations0 };
|
|
122
|
+
const cellRendererModule = {};
|
|
123
|
+
const layoutModule = { layouts: [] };
|
|
124
|
+
const plugin = {
|
|
125
|
+
widgetModule,
|
|
126
|
+
routeModule,
|
|
127
|
+
menuItemModule,
|
|
128
|
+
formModule,
|
|
129
|
+
displayModule,
|
|
130
|
+
i18nModule,
|
|
131
|
+
cellRendererModule,
|
|
132
|
+
layoutModule
|
|
133
|
+
};
|
|
134
|
+
module.exports = plugin;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
+
import { defineWidgetConfig } from "@medusajs/admin-sdk";
|
|
3
|
+
import { Container, Heading, Text, Badge } from "@medusajs/ui";
|
|
4
|
+
import { useState, useEffect } from "react";
|
|
5
|
+
const NEW = 0;
|
|
6
|
+
const IN_PROGRESS = 1;
|
|
7
|
+
const SETTLED = 2;
|
|
8
|
+
const BlockonomicsPaymentWidget = ({
|
|
9
|
+
data: order
|
|
10
|
+
}) => {
|
|
11
|
+
const [sessions, setSessions] = useState([]);
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
let active = true;
|
|
14
|
+
fetch(
|
|
15
|
+
`${""}/admin/orders/${order.id}?fields=id,*payment_collections.payment_sessions`,
|
|
16
|
+
{ credentials: "include" }
|
|
17
|
+
).then((res) => {
|
|
18
|
+
if (!res.ok) {
|
|
19
|
+
throw new Error(`${res.status}`);
|
|
20
|
+
}
|
|
21
|
+
return res.json();
|
|
22
|
+
}).then(({ order: withSessions }) => {
|
|
23
|
+
if (!active) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
setSessions(
|
|
27
|
+
(withSessions.payment_collections ?? []).flatMap((collection) => collection.payment_sessions ?? []).filter(
|
|
28
|
+
(session) => session.provider_id.startsWith("pp_blockonomics_")
|
|
29
|
+
).map((session) => session.data).filter(
|
|
30
|
+
(data) => data?.payments?.some(
|
|
31
|
+
(payment) => payment.payment_status !== NEW
|
|
32
|
+
)
|
|
33
|
+
)
|
|
34
|
+
);
|
|
35
|
+
}).catch(() => {
|
|
36
|
+
});
|
|
37
|
+
return () => {
|
|
38
|
+
active = false;
|
|
39
|
+
};
|
|
40
|
+
}, [order.id]);
|
|
41
|
+
if (!sessions.length) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
return /* @__PURE__ */ jsxs(Container, { className: "divide-y p-0", children: [
|
|
45
|
+
/* @__PURE__ */ jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsx(Heading, { level: "h2", children: "Bitcoin payment" }) }),
|
|
46
|
+
sessions.map((data, i) => {
|
|
47
|
+
const money = (amount) => new Intl.NumberFormat(void 0, {
|
|
48
|
+
style: "currency",
|
|
49
|
+
currency: data.currency_code.toUpperCase()
|
|
50
|
+
}).format(amount);
|
|
51
|
+
const payments = data.payments;
|
|
52
|
+
const active = payments[payments.length - 1];
|
|
53
|
+
const confirming = active.payment_status === IN_PROGRESS;
|
|
54
|
+
const difference = data.paid_fiat - data.fiat_amount;
|
|
55
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-3 px-6 py-4", children: [
|
|
56
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
|
|
57
|
+
/* @__PURE__ */ jsxs(Text, { size: "small", weight: "plus", children: [
|
|
58
|
+
"Received ",
|
|
59
|
+
money(data.paid_fiat),
|
|
60
|
+
" of ",
|
|
61
|
+
money(data.fiat_amount)
|
|
62
|
+
] }),
|
|
63
|
+
confirming && /* @__PURE__ */ jsx(Badge, { color: "blue", size: "2xsmall", children: "Confirming" }),
|
|
64
|
+
data.overpaid && /* @__PURE__ */ jsx(Badge, { color: "orange", size: "2xsmall", children: "Overpaid" }),
|
|
65
|
+
data.underpaid && !confirming && /* @__PURE__ */ jsx(Badge, { color: "red", size: "2xsmall", children: "Underpaid" })
|
|
66
|
+
] }),
|
|
67
|
+
confirming && /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "A payment was sent and is waiting for confirmations on the Bitcoin network. The order is marked as paid once it confirms; nothing needs to be done." }),
|
|
68
|
+
data.underpaid && !confirming && /* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
|
|
69
|
+
"The customer still owes ",
|
|
70
|
+
money(-difference),
|
|
71
|
+
". They can pay it from the checkout page, and the order is marked as paid once it arrives. If they don't, contact them, or cancel the order and send back what they paid from your wallet."
|
|
72
|
+
] }),
|
|
73
|
+
data.overpaid && /* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
|
|
74
|
+
"The customer sent ",
|
|
75
|
+
money(difference),
|
|
76
|
+
" more than the order total. Nothing is refunded automatically: decide whether to send the difference back from your wallet or compensate the customer another way."
|
|
77
|
+
] }),
|
|
78
|
+
payments.map((payment) => /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-1", children: [
|
|
79
|
+
/* @__PURE__ */ jsx(Text, { size: "xsmall", className: "text-ui-fg-subtle break-all", children: payment.address }),
|
|
80
|
+
/* @__PURE__ */ jsxs(Text, { size: "xsmall", className: "text-ui-fg-subtle break-all", children: [
|
|
81
|
+
describe(payment, money),
|
|
82
|
+
payment.txid ? ` · txid ${payment.txid}` : ""
|
|
83
|
+
] })
|
|
84
|
+
] }, payment.address))
|
|
85
|
+
] }, i);
|
|
86
|
+
})
|
|
87
|
+
] });
|
|
88
|
+
};
|
|
89
|
+
function describe(payment, money) {
|
|
90
|
+
switch (payment.payment_status) {
|
|
91
|
+
case SETTLED:
|
|
92
|
+
return `${(payment.paid_satoshis / 1e8).toFixed(8)} BTC, worth ${money(payment.paid_fiat)}`;
|
|
93
|
+
case IN_PROGRESS:
|
|
94
|
+
return `Payment seen, ${payment.confirmations} ${payment.confirmations === 1 ? "confirmation" : "confirmations"} so far`;
|
|
95
|
+
default:
|
|
96
|
+
return `Waiting for ${money(payment.expected_fiat)}`;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
defineWidgetConfig({
|
|
100
|
+
zone: "order.details.side.after"
|
|
101
|
+
});
|
|
102
|
+
const i18nTranslations0 = {};
|
|
103
|
+
const widgetModule = { widgets: [
|
|
104
|
+
{
|
|
105
|
+
Component: BlockonomicsPaymentWidget,
|
|
106
|
+
zone: ["order.details.side.after"],
|
|
107
|
+
widgetId: "Widget-fc36"
|
|
108
|
+
}
|
|
109
|
+
] };
|
|
110
|
+
const routeModule = {
|
|
111
|
+
routes: []
|
|
112
|
+
};
|
|
113
|
+
const menuItemModule = {
|
|
114
|
+
menuItems: []
|
|
115
|
+
};
|
|
116
|
+
const formModule = { customFields: {} };
|
|
117
|
+
const displayModule = {
|
|
118
|
+
displays: {}
|
|
119
|
+
};
|
|
120
|
+
const i18nModule = { resources: i18nTranslations0 };
|
|
121
|
+
const cellRendererModule = {};
|
|
122
|
+
const layoutModule = { layouts: [] };
|
|
123
|
+
const plugin = {
|
|
124
|
+
widgetModule,
|
|
125
|
+
routeModule,
|
|
126
|
+
menuItemModule,
|
|
127
|
+
formModule,
|
|
128
|
+
displayModule,
|
|
129
|
+
i18nModule,
|
|
130
|
+
cellRendererModule,
|
|
131
|
+
layoutModule
|
|
132
|
+
};
|
|
133
|
+
export {
|
|
134
|
+
plugin as default
|
|
135
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GET = void 0;
|
|
4
|
+
const utils_1 = require("@medusajs/framework/utils");
|
|
5
|
+
const blockonomics_webhook_1 = require("../../../../subscribers/blockonomics-webhook");
|
|
6
|
+
/**
|
|
7
|
+
* Receives Blockonomics payment callbacks.
|
|
8
|
+
*
|
|
9
|
+
* Blockonomics sends callbacks as `GET`, which Medusa's `/hooks/payment`
|
|
10
|
+
* endpoint does not accept. This route passes the query to the plugin's
|
|
11
|
+
* webhook subscriber instead.
|
|
12
|
+
*
|
|
13
|
+
* `:provider` is `blockonomics_{id}`, where `id` is the provider's `id` in
|
|
14
|
+
* `medusa-config.ts`.
|
|
15
|
+
*/
|
|
16
|
+
const GET = async (req, res) => {
|
|
17
|
+
try {
|
|
18
|
+
const { provider } = req.params;
|
|
19
|
+
const options =
|
|
20
|
+
// @ts-expect-error options is not typed on the module service
|
|
21
|
+
req.scope.resolve(utils_1.Modules.PAYMENT).options || {};
|
|
22
|
+
const event = {
|
|
23
|
+
provider,
|
|
24
|
+
payload: {
|
|
25
|
+
data: req.query,
|
|
26
|
+
rawData: "",
|
|
27
|
+
headers: req.headers,
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
const eventBus = req.scope.resolve(utils_1.Modules.EVENT_BUS);
|
|
31
|
+
// Delayed like Medusa's own webhook endpoint, to avoid racing the request
|
|
32
|
+
// that created the payment session.
|
|
33
|
+
await eventBus.emit({
|
|
34
|
+
name: blockonomics_webhook_1.BLOCKONOMICS_WEBHOOK_EVENT,
|
|
35
|
+
data: event,
|
|
36
|
+
}, {
|
|
37
|
+
delay: options.webhook_delay || 5000,
|
|
38
|
+
attempts: options.webhook_retries || 3,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
res.status(400).send(`Webhook Error: ${err.message}`);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
res.sendStatus(200);
|
|
46
|
+
};
|
|
47
|
+
exports.GET = GET;
|
|
48
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicm91dGUuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi8uLi9zcmMvYXBpL2hvb2tzL2Jsb2Nrb25vbWljcy9bcHJvdmlkZXJdL3JvdXRlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUtBLHFEQUFtRDtBQUVuRCx1RkFBeUY7QUFFekY7Ozs7Ozs7OztHQVNHO0FBQ0ksTUFBTSxHQUFHLEdBQUcsS0FBSyxFQUFFLEdBQWtCLEVBQUUsR0FBbUIsRUFBRSxFQUFFO0lBQ25FLElBQUksQ0FBQztRQUNILE1BQU0sRUFBRSxRQUFRLEVBQUUsR0FBRyxHQUFHLENBQUMsTUFBTSx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0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.POST = void 0;
|
|
4
|
+
const utils_1 = require("@medusajs/framework/utils");
|
|
5
|
+
/**
|
|
6
|
+
* Re-quotes the BTC amount of a Blockonomics payment session.
|
|
7
|
+
*
|
|
8
|
+
* The storefront calls this when the price lock runs out, the way the
|
|
9
|
+
* WooCommerce plugin refreshes the order amount. Medusa's own endpoint for
|
|
10
|
+
* payment sessions replaces the session, which hands the customer a new
|
|
11
|
+
* address; this one runs the provider's `updatePayment`, which keeps the
|
|
12
|
+
* address and only re-quotes the amount once the lock has expired with nothing
|
|
13
|
+
* received.
|
|
14
|
+
*/
|
|
15
|
+
const POST = async (req, res) => {
|
|
16
|
+
const { id } = req.params;
|
|
17
|
+
const paymentModule = req.scope.resolve(utils_1.Modules.PAYMENT);
|
|
18
|
+
const session = await paymentModule.retrievePaymentSession(id, {
|
|
19
|
+
select: ["id", "provider_id", "amount", "currency_code", "data", "status"],
|
|
20
|
+
});
|
|
21
|
+
if (!session.provider_id.startsWith("pp_blockonomics_")) {
|
|
22
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.NOT_FOUND, `Payment session ${id} is not a Blockonomics session`);
|
|
23
|
+
}
|
|
24
|
+
const updated = await paymentModule.updatePaymentSession({
|
|
25
|
+
id: session.id,
|
|
26
|
+
amount: session.amount,
|
|
27
|
+
currency_code: session.currency_code,
|
|
28
|
+
data: session.data ?? {},
|
|
29
|
+
});
|
|
30
|
+
res.json({
|
|
31
|
+
payment_session: {
|
|
32
|
+
id: updated.id,
|
|
33
|
+
status: updated.status,
|
|
34
|
+
data: updated.data,
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
exports.POST = POST;
|
|
39
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicm91dGUuanMiLCJzb3VyY2VSb290IjoiIiwic291cm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