@tly-pay/vendure-plugin 0.0.0-stage → 1.0.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.
Files changed (86) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/LICENSE +21 -0
  3. package/README.md +192 -2
  4. package/assets/coins/arb.svg +10 -0
  5. package/assets/coins/base.svg +4 -0
  6. package/assets/coins/bln.svg +4 -0
  7. package/assets/coins/bnb.svg +13 -0
  8. package/assets/coins/btc.svg +1 -0
  9. package/assets/coins/busd.svg +7 -0
  10. package/assets/coins/coin.svg +1 -0
  11. package/assets/coins/dai.svg +1 -0
  12. package/assets/coins/doge.svg +109 -0
  13. package/assets/coins/eth.svg +10 -0
  14. package/assets/coins/jst.svg +11 -0
  15. package/assets/coins/link.svg +4 -0
  16. package/assets/coins/ltc.svg +4 -0
  17. package/assets/coins/op.svg +12 -0
  18. package/assets/coins/pol.svg +11 -0
  19. package/assets/coins/shib.svg +18 -0
  20. package/assets/coins/sol.svg +15 -0
  21. package/assets/coins/sun.svg +71 -0
  22. package/assets/coins/trx.svg +4 -0
  23. package/assets/coins/uni.svg +10 -0
  24. package/assets/coins/usdc.svg +6 -0
  25. package/assets/coins/usdd.svg +18 -0
  26. package/assets/coins/usdt.svg +1 -0
  27. package/assets/coins/wbtc.svg +16 -0
  28. package/assets/coins/weth.svg +17 -0
  29. package/assets/tly-pay-mark.svg +31 -0
  30. package/dashboard/api.ts +167 -0
  31. package/dashboard/appearance.tsx +253 -0
  32. package/dashboard/banner.tsx +72 -0
  33. package/dashboard/i18n/en.po +584 -0
  34. package/dashboard/index.tsx +33 -0
  35. package/dashboard/logic.ts +219 -0
  36. package/dashboard/messages.tsx +90 -0
  37. package/dashboard/notice.tsx +15 -0
  38. package/dashboard/order-block.tsx +21 -0
  39. package/dashboard/orders.tsx +246 -0
  40. package/dashboard/page.tsx +174 -0
  41. package/dashboard/settings.tsx +186 -0
  42. package/dashboard/use-connect.ts +46 -0
  43. package/dist/api.d.ts +169 -0
  44. package/dist/api.js +541 -0
  45. package/dist/client-ref.d.ts +75 -0
  46. package/dist/client-ref.js +165 -0
  47. package/dist/connect-flow.d.ts +65 -0
  48. package/dist/connect-flow.js +177 -0
  49. package/dist/connection-check.d.ts +28 -0
  50. package/dist/connection-check.js +49 -0
  51. package/dist/connection.d.ts +140 -0
  52. package/dist/connection.js +361 -0
  53. package/dist/contracts.d.ts +66 -0
  54. package/dist/contracts.js +151 -0
  55. package/dist/creation-service.d.ts +136 -0
  56. package/dist/creation-service.js +242 -0
  57. package/dist/handler.d.ts +13 -0
  58. package/dist/handler.js +45 -0
  59. package/dist/hosted-checkout.d.ts +3 -0
  60. package/dist/hosted-checkout.js +25 -0
  61. package/dist/index.d.ts +11 -0
  62. package/dist/index.js +32 -0
  63. package/dist/ownership.d.ts +38 -0
  64. package/dist/ownership.js +38 -0
  65. package/dist/payment-sync.d.ts +45 -0
  66. package/dist/payment-sync.js +111 -0
  67. package/dist/persistence.d.ts +104 -0
  68. package/dist/persistence.js +405 -0
  69. package/dist/plugin.d.ts +26 -0
  70. package/dist/plugin.js +112 -0
  71. package/dist/public-api.d.ts +56 -0
  72. package/dist/public-api.js +221 -0
  73. package/dist/records.d.ts +53 -0
  74. package/dist/records.js +109 -0
  75. package/dist/release-config.d.ts +55 -0
  76. package/dist/release-config.js +107 -0
  77. package/dist/release-config.json +15 -0
  78. package/dist/secret-box.d.ts +19 -0
  79. package/dist/secret-box.js +65 -0
  80. package/dist/service.d.ts +267 -0
  81. package/dist/service.js +788 -0
  82. package/dist/signed-webhook.d.ts +67 -0
  83. package/dist/signed-webhook.js +119 -0
  84. package/dist/storefront/checkout.d.mts +86 -0
  85. package/dist/storefront/checkout.mjs +149 -0
  86. package/package.json +97 -4
@@ -0,0 +1,67 @@
1
+ import { TlyStatus } from "./contracts";
2
+ export declare const PAYMENT_UPDATED = "payment.updated";
3
+ /** TLY Pay's connection check, sent once when a connection is established. */
4
+ export declare const CONNECTION_CHECK = "endpoint.ping";
5
+ /**
6
+ * A request whose headers, timestamp and signature are verified. `secret` is the configured Secret
7
+ * (current or pending) that matched; the connection check answer is signed with it.
8
+ */
9
+ export type SignedRequest = {
10
+ secret: string;
11
+ /** `x-tly-webhook-timestamp` exactly as received. */
12
+ timestamp: string;
13
+ eventId: string;
14
+ /** The body's `event_type`, or null when it is missing or not a string. */
15
+ eventType: string | null;
16
+ body: unknown;
17
+ };
18
+ /** Missing or malformed headers, a timestamp out of tolerance or no matching Secret: answered 401. */
19
+ export declare class WebhookUnauthorized extends TypeError {
20
+ }
21
+ /** A verified request whose body or envelope is invalid; retrying cannot fix it, answered 400. */
22
+ export declare class InvalidSignedEvent extends TypeError {
23
+ }
24
+ /**
25
+ * A verified event with only the fields that decide ownership. Every Payment event of the Store
26
+ * arrives, also those of other installations with other sources, so the Payment business fields are
27
+ * validated by `validateEventPayment` only once the event belongs to a known local Payment.
28
+ */
29
+ export type SignedPaymentEvent = {
30
+ schemaVersion: "1";
31
+ eventId: string;
32
+ eventType: "payment.updated";
33
+ paymentId: string;
34
+ /** Signed `order_ref` when it is a string; any other value reads as null for intent recovery. */
35
+ orderRef: string | null;
36
+ /** Installation marker of the Payment creator; null when absent (older events, direct API use). */
37
+ clientRef: string | null;
38
+ statusVersion: number;
39
+ /** Parsed signed body, read by `validateEventPayment`. */
40
+ body: Record<string, unknown>;
41
+ };
42
+ /** Payment business fields of a verified event of a known local Payment. */
43
+ export type SignedPaymentFields = {
44
+ occurredAt: string;
45
+ orderRef: string | null;
46
+ status: TlyStatus;
47
+ sourceCurrency: string;
48
+ sourceAmountRaw: string;
49
+ sourceDecimals: number;
50
+ createdAt: string;
51
+ paymentExpiresAt: string;
52
+ updatedAt: string;
53
+ };
54
+ /** A signed event of a known local Payment carries invalid Payment fields; retrying cannot fix it. */
55
+ export declare class InvalidEventPayment extends TypeError {
56
+ constructor();
57
+ }
58
+ export declare function verifySignedRequest(body: Uint8Array, headers: Record<string, string | undefined>, secrets: string[], nowSecs: number, toleranceSecs: number): SignedRequest;
59
+ /**
60
+ * Checks a verified `endpoint.ping`: its envelope, Header and Body Event ID, and the named Endpoint,
61
+ * which must be the one the saved connection holds.
62
+ */
63
+ export declare function verifyConnectionCheck(request: SignedRequest, endpointId: string): void;
64
+ /** The ownership fields of a verified `payment.updated` Event. */
65
+ export declare function paymentEvent(request: SignedRequest): SignedPaymentEvent;
66
+ /** Validates the Payment business fields of a verified event of a known local Payment. */
67
+ export declare function validateEventPayment(event: SignedPaymentEvent): SignedPaymentFields;
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InvalidEventPayment = exports.InvalidSignedEvent = exports.WebhookUnauthorized = exports.CONNECTION_CHECK = exports.PAYMENT_UPDATED = void 0;
4
+ exports.verifySignedRequest = verifySignedRequest;
5
+ exports.verifyConnectionCheck = verifyConnectionCheck;
6
+ exports.paymentEvent = paymentEvent;
7
+ exports.validateEventPayment = validateEventPayment;
8
+ const node_crypto_1 = require("node:crypto");
9
+ const contracts_1 = require("./contracts");
10
+ exports.PAYMENT_UPDATED = "payment.updated";
11
+ /** TLY Pay's connection check, sent once when a connection is established. */
12
+ exports.CONNECTION_CHECK = "endpoint.ping";
13
+ /** Missing or malformed headers, a timestamp out of tolerance or no matching Secret: answered 401. */
14
+ class WebhookUnauthorized extends TypeError {
15
+ }
16
+ exports.WebhookUnauthorized = WebhookUnauthorized;
17
+ /** A verified request whose body or envelope is invalid; retrying cannot fix it, answered 400. */
18
+ class InvalidSignedEvent extends TypeError {
19
+ }
20
+ exports.InvalidSignedEvent = InvalidSignedEvent;
21
+ /** A signed event of a known local Payment carries invalid Payment fields; retrying cannot fix it. */
22
+ class InvalidEventPayment extends TypeError {
23
+ constructor() { super("Invalid signed Payment fields"); }
24
+ }
25
+ exports.InvalidEventPayment = InvalidEventPayment;
26
+ function verifySignedRequest(body, headers, secrets, nowSecs, toleranceSecs) {
27
+ if (!(body instanceof Uint8Array) || body.byteLength < 1 || body.byteLength > 65_536
28
+ || headers["content-type"] !== "application/json"
29
+ || typeof headers["x-tly-webhook-id"] !== "string" || !contracts_1.EVENT_ID.test(headers["x-tly-webhook-id"])
30
+ || typeof headers["x-tly-webhook-timestamp"] !== "string"
31
+ || !/^(?:0|[1-9][0-9]{0,18})$/.test(headers["x-tly-webhook-timestamp"])
32
+ || typeof headers["x-tly-webhook-signature"] !== "string"
33
+ || !/^v1=[0-9a-f]{64}$/.test(headers["x-tly-webhook-signature"])
34
+ || !Number.isSafeInteger(nowSecs) || !Number.isSafeInteger(toleranceSecs)
35
+ || toleranceSecs < 1 || toleranceSecs > 3600 || secrets.length < 1 || secrets.length > 2
36
+ || new Set(secrets).size !== secrets.length || secrets.some((secret) => !contracts_1.WEBHOOK_SECRET.test(secret))) {
37
+ throw new WebhookUnauthorized("Invalid signed Webhook");
38
+ }
39
+ const timestamp = Number(headers["x-tly-webhook-timestamp"]);
40
+ if (!Number.isSafeInteger(timestamp) || Math.abs(nowSecs - timestamp) > toleranceSecs) {
41
+ throw new WebhookUnauthorized("Invalid Webhook timestamp");
42
+ }
43
+ const signed = Buffer.from(headers["x-tly-webhook-signature"].slice(3), "hex");
44
+ const message = Buffer.concat([Buffer.from(`${timestamp}.`), Buffer.from(body)]);
45
+ const matched = secrets.filter((secret) => (0, node_crypto_1.timingSafeEqual)(signed, (0, node_crypto_1.createHmac)("sha256", secret).update(message).digest()));
46
+ if (matched.length !== 1)
47
+ throw new WebhookUnauthorized("Invalid Webhook signature");
48
+ let parsed;
49
+ try {
50
+ parsed = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(body));
51
+ }
52
+ catch (error) {
53
+ throw new InvalidSignedEvent("Invalid Webhook JSON", { cause: error });
54
+ }
55
+ return {
56
+ secret: matched[0], timestamp: headers["x-tly-webhook-timestamp"], eventId: headers["x-tly-webhook-id"],
57
+ eventType: (0, contracts_1.hasFields)(parsed, ["event_type"]) && typeof parsed.event_type === "string" ? parsed.event_type : null,
58
+ body: parsed,
59
+ };
60
+ }
61
+ /**
62
+ * Checks a verified `endpoint.ping`: its envelope, Header and Body Event ID, and the named Endpoint,
63
+ * which must be the one the saved connection holds.
64
+ */
65
+ function verifyConnectionCheck(request, endpointId) {
66
+ const parsed = request.body;
67
+ if (!(0, contracts_1.hasFields)(parsed, ["schema_version", "event_id", "event_type", "occurred_at", "data"])
68
+ || parsed.schema_version !== "1" || parsed.event_type !== exports.CONNECTION_CHECK || parsed.event_id !== request.eventId
69
+ || !(0, contracts_1.isRfc3339Timestamp)(parsed.occurred_at) || !(0, contracts_1.hasFields)(parsed.data, ["webhook_endpoint_id"])
70
+ || typeof parsed.data.webhook_endpoint_id !== "string" || endpointId === ""
71
+ || parsed.data.webhook_endpoint_id !== endpointId) {
72
+ throw new InvalidSignedEvent("Invalid connection check");
73
+ }
74
+ }
75
+ /** The ownership fields of a verified `payment.updated` Event. */
76
+ function paymentEvent(request) {
77
+ const parsed = request.body;
78
+ const clientRef = (0, contracts_1.hasFields)(parsed, ["data"]) && (0, contracts_1.isRecord)(parsed.data) ? (0, contracts_1.optionalClientRef)(parsed.data) : undefined;
79
+ if (!(0, contracts_1.hasFields)(parsed, ["schema_version", "event_id", "event_type", "data"])
80
+ || parsed.schema_version !== "1" || parsed.event_type !== exports.PAYMENT_UPDATED
81
+ || parsed.event_id !== request.eventId || !(0, contracts_1.isRecord)(parsed.data)
82
+ || clientRef === undefined
83
+ || !(0, contracts_1.hasFields)(parsed.data, ["payment_id", "status_version"])
84
+ || typeof parsed.data.payment_id !== "string" || !contracts_1.PAYMENT_ID.test(parsed.data.payment_id)
85
+ || !Number.isSafeInteger(parsed.data.status_version) || parsed.data.status_version < 1) {
86
+ throw new InvalidSignedEvent("Invalid signed Payment Event");
87
+ }
88
+ const data = parsed.data;
89
+ return {
90
+ schemaVersion: "1", eventId: parsed.event_id, eventType: "payment.updated",
91
+ paymentId: data.payment_id,
92
+ orderRef: typeof data.order_ref === "string" ? data.order_ref : null, clientRef,
93
+ statusVersion: data.status_version, body: parsed,
94
+ };
95
+ }
96
+ /** Validates the Payment business fields of a verified event of a known local Payment. */
97
+ function validateEventPayment(event) {
98
+ const data = event.body.data;
99
+ const amount = data.source_amount;
100
+ if (!(0, contracts_1.isRfc3339Timestamp)(event.body.occurred_at)
101
+ || !(0, contracts_1.hasFields)(data, ["order_ref", "status", "source_amount", "created_at", "payment_expires_at", "updated_at"])
102
+ || data.order_ref !== null && typeof data.order_ref !== "string"
103
+ || typeof data.status !== "string" || !contracts_1.TLY_STATUSES.has(data.status)
104
+ || !(0, contracts_1.hasFields)(amount, ["kind", "currency", "amount_raw", "decimals"])
105
+ || amount.kind !== "fiat"
106
+ || typeof amount.currency !== "string" || !/^[A-Z]{3}$/.test(amount.currency)
107
+ || typeof amount.amount_raw !== "string" || !contracts_1.AMOUNT_RAW.test(amount.amount_raw)
108
+ || !Number.isInteger(amount.decimals) || amount.decimals < 0 || amount.decimals > 18
109
+ || !(0, contracts_1.isRfc3339Timestamp)(data.created_at) || !(0, contracts_1.isRfc3339Timestamp)(data.payment_expires_at)
110
+ || !(0, contracts_1.isRfc3339Timestamp)(data.updated_at)) {
111
+ throw new InvalidEventPayment();
112
+ }
113
+ return {
114
+ occurredAt: event.body.occurred_at, orderRef: data.order_ref,
115
+ status: data.status, sourceCurrency: amount.currency, sourceAmountRaw: amount.amount_raw,
116
+ sourceDecimals: amount.decimals, createdAt: data.created_at,
117
+ paymentExpiresAt: data.payment_expires_at, updatedAt: data.updated_at,
118
+ };
119
+ }
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Storefront helper for TLY Pay embedded checkout in a headless Vendure storefront.
3
+ *
4
+ * The storefront preloads the Checkout Widget when the checkout page opens, and after the customer
5
+ * places the order (the Order is in `ArrangingPayment`) it calls the Shop API mutation
6
+ * `createTlyPayPayment(returnUrl)` and passes the returned session to `open()`:
7
+ * - Hosted session (the default checkout mode) -> the page goes to the Hosted Checkout URL.
8
+ * - Embedded session -> the Widget opens over the page with `open({ paymentId, onClose })`. A close
9
+ * with a paid status goes to the session's `returnUrl`; any other close resolves `closed`, so the
10
+ * storefront shows a notice and keeps the checkout usable (calling the mutation again returns the
11
+ * same Payment). When the Widget cannot load or open within the packaged deadline, or an older
12
+ * Widget rejects `onClose`, the customer continues on the Hosted URL of the same Payment.
13
+ *
14
+ * Loader invariants (shared with the WooCommerce plugin): the UMD Widget assigns a new
15
+ * `window.CryptoPay` on every execution. Only a v1 API produced by the current attempt is adopted; a
16
+ * foreign global fails closed, and a failed or stale execution restores the owned API or removes the
17
+ * global, so a later attempt can always load again in this document.
18
+ */
19
+ /** `createTlyPayPayment` result of the Shop API. */
20
+ export type TlyPaySession = {
21
+ paymentId: string;
22
+ checkoutMode: string;
23
+ hostedUrl: string;
24
+ returnUrl: string | null;
25
+ widgetScriptUrl: string;
26
+ widgetActionTimeoutSecs: number;
27
+ paidStatuses: string[];
28
+ };
29
+ /**
30
+ * `tlyPayCheckout.icons` entry of the Shop API: one coin icon shown beside the title, already limited to
31
+ * the coins the merchant chose and in display order. `label` is the image's text alternative.
32
+ */
33
+ export type TlyPayCheckoutIcon = {
34
+ mark: string;
35
+ label: string;
36
+ iconUrl: string;
37
+ };
38
+ /**
39
+ * The payment method row of `tlyPayCheckout`, as the merchant set it up under Settings > Checkout
40
+ * appearance: `title` (the name of the Vendure payment method, plain text), the `icons` beside it and,
41
+ * when the merchant shows it, the `coinNames` sentence under it (null otherwise: render no element).
42
+ * Render `title` and `coinNames` as text, never as HTML.
43
+ */
44
+ export type TlyPayCheckoutRow = {
45
+ title: string;
46
+ coinNames: string | null;
47
+ icons: TlyPayCheckoutIcon[];
48
+ };
49
+ export type OpenOutcome = "paid" | "closed" | "hosted";
50
+ /** The parts of `window` the helper uses; tests pass a fake. */
51
+ export type HelperWindow = {
52
+ CryptoPay?: unknown;
53
+ document: {
54
+ head: {
55
+ appendChild(node: unknown): unknown;
56
+ };
57
+ createElement(tag: "script"): ScriptElement;
58
+ };
59
+ location: {
60
+ assign(url: string): void;
61
+ };
62
+ setTimeout(handler: () => void, ms: number): number;
63
+ clearTimeout(id: number): void;
64
+ };
65
+ type ScriptElement = {
66
+ src: string;
67
+ async: boolean;
68
+ referrerPolicy: string;
69
+ onload: (() => void) | null;
70
+ onerror: (() => void) | null;
71
+ remove(): void;
72
+ };
73
+ /**
74
+ * One loader per document for the packaged Widget script. `preload()` never rejects; `open()` follows
75
+ * the session's checkout mode as described in the module comment.
76
+ */
77
+ export declare function createTlyPayCheckout(config: {
78
+ scriptUrl: string;
79
+ timeoutSecs: number;
80
+ }, win?: HelperWindow): {
81
+ /** Preloads the Widget on checkout page entry; placing the order retries and falls back to Hosted. */
82
+ preload(): Promise<void>;
83
+ /** Continues the customer's payment of a `createTlyPayPayment` session. */
84
+ open(session: TlyPaySession): Promise<OpenOutcome>;
85
+ };
86
+ export {};
@@ -0,0 +1,149 @@
1
+ /**
2
+ * Storefront helper for TLY Pay embedded checkout in a headless Vendure storefront.
3
+ *
4
+ * The storefront preloads the Checkout Widget when the checkout page opens, and after the customer
5
+ * places the order (the Order is in `ArrangingPayment`) it calls the Shop API mutation
6
+ * `createTlyPayPayment(returnUrl)` and passes the returned session to `open()`:
7
+ * - Hosted session (the default checkout mode) -> the page goes to the Hosted Checkout URL.
8
+ * - Embedded session -> the Widget opens over the page with `open({ paymentId, onClose })`. A close
9
+ * with a paid status goes to the session's `returnUrl`; any other close resolves `closed`, so the
10
+ * storefront shows a notice and keeps the checkout usable (calling the mutation again returns the
11
+ * same Payment). When the Widget cannot load or open within the packaged deadline, or an older
12
+ * Widget rejects `onClose`, the customer continues on the Hosted URL of the same Payment.
13
+ *
14
+ * Loader invariants (shared with the WooCommerce plugin): the UMD Widget assigns a new
15
+ * `window.CryptoPay` on every execution. Only a v1 API produced by the current attempt is adopted; a
16
+ * foreign global fails closed, and a failed or stale execution restores the owned API or removes the
17
+ * global, so a later attempt can always load again in this document.
18
+ */
19
+ const validWidget = (candidate) => {
20
+ const api = candidate;
21
+ return !!api && api.contractVersion === 1 && typeof api.open === "function" && typeof api.close === "function";
22
+ };
23
+ /**
24
+ * One loader per document for the packaged Widget script. `preload()` never rejects; `open()` follows
25
+ * the session's checkout mode as described in the module comment.
26
+ */
27
+ export function createTlyPayCheckout(config, win = globalThis) {
28
+ const timeoutMs = config.timeoutSecs * 1000;
29
+ let widget = null;
30
+ let pending = null;
31
+ let openSeq = 0;
32
+ const settleGlobal = () => {
33
+ if (widget)
34
+ win.CryptoPay = widget;
35
+ else
36
+ delete win.CryptoPay;
37
+ };
38
+ function load() {
39
+ if (widget)
40
+ return Promise.resolve(widget);
41
+ if (pending)
42
+ return pending.promise;
43
+ if (win.CryptoPay !== undefined)
44
+ return Promise.reject(new Error("Widget namespace is in use"));
45
+ const script = win.document.createElement("script");
46
+ const attempt = { promise: Promise.resolve(null), timer: 0 };
47
+ attempt.promise = new Promise((resolve, reject) => {
48
+ const fail = (error) => {
49
+ win.clearTimeout(attempt.timer);
50
+ script.remove();
51
+ pending = null;
52
+ settleGlobal();
53
+ reject(error);
54
+ };
55
+ attempt.timer = win.setTimeout(() => {
56
+ if (pending === attempt)
57
+ fail(new Error("Widget timeout"));
58
+ }, timeoutMs);
59
+ script.src = config.scriptUrl;
60
+ script.async = true;
61
+ script.referrerPolicy = "no-referrer";
62
+ script.onload = () => {
63
+ if (pending !== attempt) {
64
+ settleGlobal();
65
+ return;
66
+ }
67
+ win.clearTimeout(attempt.timer);
68
+ const candidate = win.CryptoPay;
69
+ if (!validWidget(candidate)) {
70
+ delete win.CryptoPay;
71
+ script.remove();
72
+ pending = null;
73
+ reject(new Error("Widget contract is unavailable"));
74
+ return;
75
+ }
76
+ widget = candidate;
77
+ pending = null;
78
+ resolve(candidate);
79
+ };
80
+ script.onerror = () => {
81
+ if (pending === attempt)
82
+ fail(new Error("Widget load failed"));
83
+ };
84
+ });
85
+ pending = attempt;
86
+ win.document.head.appendChild(script);
87
+ return attempt.promise;
88
+ }
89
+ /** Opens one Payment; resolves with the close status, rejects when it cannot load, open or mount in time. */
90
+ function openWidget(paymentId) {
91
+ const seq = ++openSeq;
92
+ return new Promise((resolve, reject) => {
93
+ let expired = false;
94
+ let closed = false;
95
+ const timer = win.setTimeout(() => {
96
+ expired = true;
97
+ if (seq === openSeq && widget)
98
+ widget.close();
99
+ reject(new Error("Widget open timeout"));
100
+ }, timeoutMs);
101
+ const onClose = (outcome) => {
102
+ if (closed || expired)
103
+ return;
104
+ closed = true;
105
+ resolve(outcome && typeof outcome.paymentStatus === "string" ? outcome.paymentStatus : null);
106
+ };
107
+ load()
108
+ .then((api) => api.open({ paymentId, onClose }))
109
+ .then(() => {
110
+ if (expired) {
111
+ if (seq === openSeq && widget)
112
+ widget.close();
113
+ return;
114
+ }
115
+ win.clearTimeout(timer);
116
+ }, (error) => {
117
+ win.clearTimeout(timer);
118
+ if (!expired)
119
+ reject(error);
120
+ });
121
+ });
122
+ }
123
+ return {
124
+ /** Preloads the Widget on checkout page entry; placing the order retries and falls back to Hosted. */
125
+ preload() {
126
+ return load().then(() => undefined, () => undefined);
127
+ },
128
+ /** Continues the customer's payment of a `createTlyPayPayment` session. */
129
+ async open(session) {
130
+ if (session.checkoutMode !== "embedded" || session.returnUrl === null) {
131
+ win.location.assign(session.hostedUrl);
132
+ return "hosted";
133
+ }
134
+ let status;
135
+ try {
136
+ status = await openWidget(session.paymentId);
137
+ }
138
+ catch {
139
+ win.location.assign(session.hostedUrl);
140
+ return "hosted";
141
+ }
142
+ if (status !== null && session.paidStatuses.includes(status)) {
143
+ win.location.assign(session.returnUrl);
144
+ return "paid";
145
+ }
146
+ return "closed";
147
+ },
148
+ };
149
+ }
package/package.json CHANGED
@@ -1,6 +1,99 @@
1
1
  {
2
2
  "name": "@tly-pay/vendure-plugin",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "Crypto and stablecoin payments for Vendure: accept USDT, USDC, BTC and ETH, paid straight to your own wallet",
5
+ "author": "TLY Pay",
6
+ "license": "MIT",
7
+ "homepage": "https://tlypay.com/integrations/vendure/",
8
+ "bugs": {
9
+ "email": "support@tlypay.com"
10
+ },
11
+ "keywords": [
12
+ "vendure",
13
+ "vendure-plugin",
14
+ "vendure-payment",
15
+ "crypto-payments",
16
+ "stablecoin",
17
+ "usdt",
18
+ "usdc",
19
+ "payment-gateway",
20
+ "crypto",
21
+ "payments"
22
+ ],
23
+ "main": "dist/index.js",
24
+ "types": "dist/index.d.ts",
25
+ "files": [
26
+ "dist",
27
+ "dashboard",
28
+ "assets",
29
+ "LICENSE",
30
+ "CHANGELOG.md"
31
+ ],
32
+ "scripts": {
33
+ "build": "tsc -p tsconfig.json",
34
+ "pretest": "tsc -p tsconfig.json",
35
+ "test": "tsx --test tests/*.test.ts",
36
+ "lint": "tsc -p tsconfig.json --noEmit && tsc -p tsconfig.check.json",
37
+ "package:check": "node tools/package.mjs --check",
38
+ "package": "node tools/package.mjs"
39
+ },
40
+ "peerDependencies": {
41
+ "@nestjs/common": "^12.0.1",
42
+ "@nestjs/graphql": "~14.0.0",
43
+ "@vendure/common": ">=3.8.0 <3.9.0",
44
+ "@vendure/core": ">=3.8.0 <3.9.0",
45
+ "graphql-tag": "^2.12.6",
46
+ "typeorm": "^0.3.21"
47
+ },
48
+ "peerDependenciesMeta": {
49
+ "@nestjs/common": {
50
+ "optional": true
51
+ },
52
+ "@nestjs/graphql": {
53
+ "optional": true
54
+ },
55
+ "@vendure/common": {
56
+ "optional": true
57
+ },
58
+ "@vendure/core": {
59
+ "optional": true
60
+ },
61
+ "graphql-tag": {
62
+ "optional": true
63
+ },
64
+ "typeorm": {
65
+ "optional": true
66
+ }
67
+ },
68
+ "devDependencies": {
69
+ "@types/node": "^22.0.0",
70
+ "@vendure/common": "3.8.2",
71
+ "@vendure/core": "3.8.2",
72
+ "tsx": "^4.19.0",
73
+ "typescript": "^5.7.3"
74
+ },
75
+ "engines": {
76
+ "node": ">=20.19.0"
77
+ },
78
+ "exports": {
79
+ ".": {
80
+ "types": "./dist/index.d.ts",
81
+ "default": "./dist/index.js"
82
+ },
83
+ "./storefront": {
84
+ "types": "./dist/storefront/checkout.d.mts",
85
+ "default": "./dist/storefront/checkout.mjs"
86
+ },
87
+ "./package.json": "./package.json"
88
+ },
89
+ "typesVersions": {
90
+ "*": {
91
+ "storefront": [
92
+ "./dist/storefront/checkout.d.mts"
93
+ ]
94
+ }
95
+ },
96
+ "publishConfig": {
97
+ "access": "public"
98
+ }
99
+ }