@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.
- package/CHANGELOG.md +38 -0
- package/LICENSE +21 -0
- package/README.md +192 -2
- package/assets/coins/arb.svg +10 -0
- package/assets/coins/base.svg +4 -0
- package/assets/coins/bln.svg +4 -0
- package/assets/coins/bnb.svg +13 -0
- package/assets/coins/btc.svg +1 -0
- package/assets/coins/busd.svg +7 -0
- package/assets/coins/coin.svg +1 -0
- package/assets/coins/dai.svg +1 -0
- package/assets/coins/doge.svg +109 -0
- package/assets/coins/eth.svg +10 -0
- package/assets/coins/jst.svg +11 -0
- package/assets/coins/link.svg +4 -0
- package/assets/coins/ltc.svg +4 -0
- package/assets/coins/op.svg +12 -0
- package/assets/coins/pol.svg +11 -0
- package/assets/coins/shib.svg +18 -0
- package/assets/coins/sol.svg +15 -0
- package/assets/coins/sun.svg +71 -0
- package/assets/coins/trx.svg +4 -0
- package/assets/coins/uni.svg +10 -0
- package/assets/coins/usdc.svg +6 -0
- package/assets/coins/usdd.svg +18 -0
- package/assets/coins/usdt.svg +1 -0
- package/assets/coins/wbtc.svg +16 -0
- package/assets/coins/weth.svg +17 -0
- package/assets/tly-pay-mark.svg +31 -0
- package/dashboard/api.ts +167 -0
- package/dashboard/appearance.tsx +253 -0
- package/dashboard/banner.tsx +72 -0
- package/dashboard/i18n/en.po +584 -0
- package/dashboard/index.tsx +33 -0
- package/dashboard/logic.ts +219 -0
- package/dashboard/messages.tsx +90 -0
- package/dashboard/notice.tsx +15 -0
- package/dashboard/order-block.tsx +21 -0
- package/dashboard/orders.tsx +246 -0
- package/dashboard/page.tsx +174 -0
- package/dashboard/settings.tsx +186 -0
- package/dashboard/use-connect.ts +46 -0
- package/dist/api.d.ts +169 -0
- package/dist/api.js +541 -0
- package/dist/client-ref.d.ts +75 -0
- package/dist/client-ref.js +165 -0
- package/dist/connect-flow.d.ts +65 -0
- package/dist/connect-flow.js +177 -0
- package/dist/connection-check.d.ts +28 -0
- package/dist/connection-check.js +49 -0
- package/dist/connection.d.ts +140 -0
- package/dist/connection.js +361 -0
- package/dist/contracts.d.ts +66 -0
- package/dist/contracts.js +151 -0
- package/dist/creation-service.d.ts +136 -0
- package/dist/creation-service.js +242 -0
- package/dist/handler.d.ts +13 -0
- package/dist/handler.js +45 -0
- package/dist/hosted-checkout.d.ts +3 -0
- package/dist/hosted-checkout.js +25 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +32 -0
- package/dist/ownership.d.ts +38 -0
- package/dist/ownership.js +38 -0
- package/dist/payment-sync.d.ts +45 -0
- package/dist/payment-sync.js +111 -0
- package/dist/persistence.d.ts +104 -0
- package/dist/persistence.js +405 -0
- package/dist/plugin.d.ts +26 -0
- package/dist/plugin.js +112 -0
- package/dist/public-api.d.ts +56 -0
- package/dist/public-api.js +221 -0
- package/dist/records.d.ts +53 -0
- package/dist/records.js +109 -0
- package/dist/release-config.d.ts +55 -0
- package/dist/release-config.js +107 -0
- package/dist/release-config.json +15 -0
- package/dist/secret-box.d.ts +19 -0
- package/dist/secret-box.js +65 -0
- package/dist/service.d.ts +267 -0
- package/dist/service.js +788 -0
- package/dist/signed-webhook.d.ts +67 -0
- package/dist/signed-webhook.js +119 -0
- package/dist/storefront/checkout.d.mts +86 -0
- package/dist/storefront/checkout.mjs +149 -0
- package/package.json +97 -4
package/dist/api.js
ADDED
|
@@ -0,0 +1,541 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
15
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
16
|
+
};
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.TlyPayController = exports.TlyPayAdminResolver = exports.TlyPayShopResolver = exports.adminApiExtensions = exports.shopApiExtensions = exports.MAX_WEBHOOK_BYTES = void 0;
|
|
19
|
+
exports.rawWebhookBody = rawWebhookBody;
|
|
20
|
+
const promises_1 = require("node:fs/promises");
|
|
21
|
+
const common_1 = require("@nestjs/common");
|
|
22
|
+
const graphql_1 = require("@nestjs/graphql");
|
|
23
|
+
const core_1 = require("@vendure/core");
|
|
24
|
+
const graphql_tag_1 = __importDefault(require("graphql-tag"));
|
|
25
|
+
const creation_service_1 = require("./creation-service");
|
|
26
|
+
const service_1 = require("./service");
|
|
27
|
+
const LOG_CONTEXT = "TlyPay";
|
|
28
|
+
/** Largest Webhook body the plugin reads; `verifySignedEvent` accepts the same limit. */
|
|
29
|
+
exports.MAX_WEBHOOK_BYTES = 65_536;
|
|
30
|
+
const SHARED_TYPES = `
|
|
31
|
+
type TlyPayCheckoutIcon { mark: String!, label: String!, iconUrl: String! }
|
|
32
|
+
`;
|
|
33
|
+
exports.shopApiExtensions = (0, graphql_tag_1.default) `
|
|
34
|
+
${SHARED_TYPES}
|
|
35
|
+
type TlyPayCheckout {
|
|
36
|
+
available: Boolean!
|
|
37
|
+
checkoutMode: String!
|
|
38
|
+
widgetScriptUrl: String!
|
|
39
|
+
widgetActionTimeoutSecs: Int!
|
|
40
|
+
paidStatuses: [String!]!
|
|
41
|
+
title: String!
|
|
42
|
+
coinNames: String
|
|
43
|
+
icons: [TlyPayCheckoutIcon!]!
|
|
44
|
+
}
|
|
45
|
+
type TlyPayPaymentSession {
|
|
46
|
+
paymentId: String!
|
|
47
|
+
checkoutMode: String!
|
|
48
|
+
hostedUrl: String!
|
|
49
|
+
returnUrl: String
|
|
50
|
+
widgetScriptUrl: String!
|
|
51
|
+
widgetActionTimeoutSecs: Int!
|
|
52
|
+
paidStatuses: [String!]!
|
|
53
|
+
}
|
|
54
|
+
extend type Query { tlyPayCheckout: TlyPayCheckout! }
|
|
55
|
+
extend type Mutation { createTlyPayPayment(returnUrl: String): TlyPayPaymentSession! }
|
|
56
|
+
`;
|
|
57
|
+
/** Intent ids are UUID strings, typed `String` so Vendure's entity ID codec leaves them unchanged. */
|
|
58
|
+
exports.adminApiExtensions = (0, graphql_tag_1.default) `
|
|
59
|
+
${SHARED_TYPES}
|
|
60
|
+
type TlyPayAsset { symbol: String!, name: String!, networks: [String!]! }
|
|
61
|
+
type TlyPayCheckoutIconOption { mark: String!, label: String!, iconUrl: String!, accepted: Boolean! }
|
|
62
|
+
type TlyPayStatus {
|
|
63
|
+
connected: Boolean!
|
|
64
|
+
state: String!
|
|
65
|
+
displayName: String!
|
|
66
|
+
storeId: String!
|
|
67
|
+
currency: String!
|
|
68
|
+
merchantDomain: String!
|
|
69
|
+
paymentsReady: Boolean!
|
|
70
|
+
paymentAssets: [TlyPayAsset!]!
|
|
71
|
+
lastErr: String!
|
|
72
|
+
unverified: Boolean!
|
|
73
|
+
validatedAt: Int!
|
|
74
|
+
webhookUrl: String!
|
|
75
|
+
releaseComplete: Boolean!
|
|
76
|
+
consoleOrigin: String!
|
|
77
|
+
apiHost: String!
|
|
78
|
+
checkoutMode: String!
|
|
79
|
+
checkoutIcons: [String!]!
|
|
80
|
+
checkoutIconOptions: [TlyPayCheckoutIconOption!]!
|
|
81
|
+
checkoutCoinNames: Boolean!
|
|
82
|
+
checkoutTitle: String!
|
|
83
|
+
paymentMethodId: ID
|
|
84
|
+
siteMode: String!
|
|
85
|
+
channelCurrency: String!
|
|
86
|
+
paymentMethod: String!
|
|
87
|
+
}
|
|
88
|
+
type TlyPayResult { result: String!, retry: Boolean! }
|
|
89
|
+
type TlyPayStart { url: String, result: String! }
|
|
90
|
+
type TlyPayOrderRow {
|
|
91
|
+
id: String!
|
|
92
|
+
orderCode: String!
|
|
93
|
+
orderId: ID
|
|
94
|
+
orderState: String
|
|
95
|
+
state: String!
|
|
96
|
+
status: String
|
|
97
|
+
statusVersion: Int!
|
|
98
|
+
amountRaw: String!
|
|
99
|
+
currency: String!
|
|
100
|
+
checkoutMode: String!
|
|
101
|
+
paymentId: String
|
|
102
|
+
err: String
|
|
103
|
+
settleErr: String
|
|
104
|
+
settledAt: DateTime
|
|
105
|
+
createdAt: DateTime!
|
|
106
|
+
updatedAt: DateTime!
|
|
107
|
+
}
|
|
108
|
+
type TlyPayOrderCounts { all: Int!, open: Int!, paid: Int!, attention: Int!, closed: Int!, creating: Int! }
|
|
109
|
+
type TlyPayOrderList { items: [TlyPayOrderRow!]!, totalItems: Int!, counts: TlyPayOrderCounts! }
|
|
110
|
+
type TlyPayEventRow {
|
|
111
|
+
eventId: String!
|
|
112
|
+
status: String!
|
|
113
|
+
statusVersion: Int!
|
|
114
|
+
occurredAt: String!
|
|
115
|
+
receivedAt: DateTime!
|
|
116
|
+
outcome: String
|
|
117
|
+
processedAt: DateTime
|
|
118
|
+
}
|
|
119
|
+
type TlyPayLivePayment {
|
|
120
|
+
status: String!
|
|
121
|
+
statusVersion: Int!
|
|
122
|
+
activatedAt: String
|
|
123
|
+
paymentExpiresAt: String!
|
|
124
|
+
updatedAt: String!
|
|
125
|
+
}
|
|
126
|
+
type TlyPayOrderDetail {
|
|
127
|
+
row: TlyPayOrderRow!
|
|
128
|
+
checkoutOrigin: String
|
|
129
|
+
returnUrl: String
|
|
130
|
+
clientRef: String
|
|
131
|
+
live: TlyPayLivePayment
|
|
132
|
+
liveErr: String
|
|
133
|
+
events: [TlyPayEventRow!]!
|
|
134
|
+
}
|
|
135
|
+
extend type Query {
|
|
136
|
+
tlyPayStatus: TlyPayStatus!
|
|
137
|
+
tlyPayOrders(filter: String, skip: Int, take: Int): TlyPayOrderList!
|
|
138
|
+
tlyPayOrder(id: String!): TlyPayOrderDetail
|
|
139
|
+
tlyPayOrderIntent(orderCode: String!): String
|
|
140
|
+
}
|
|
141
|
+
extend type Mutation {
|
|
142
|
+
tlyPayCheckConnection: TlyPayStatus!
|
|
143
|
+
tlyPayStartConnect(adminUrl: String!, popup: Boolean!): TlyPayStart!
|
|
144
|
+
tlyPayCompleteConnect(state: String!, code: String!): TlyPayResult!
|
|
145
|
+
tlyPayRetryConnect(state: String!): TlyPayResult!
|
|
146
|
+
tlyPayDisconnect(confirm: Boolean!): TlyPayResult!
|
|
147
|
+
tlyPaySetCheckoutMode(mode: String!): TlyPayResult!
|
|
148
|
+
tlyPaySetCheckoutAppearance(marks: [String!]!, coinNames: Boolean!): TlyPayResult!
|
|
149
|
+
tlyPaySyncCheckoutIcons: TlyPayResult!
|
|
150
|
+
tlyPaySetSiteMode(mode: String!): TlyPayResult!
|
|
151
|
+
tlyPayReconcile(id: String!): TlyPayResult!
|
|
152
|
+
tlyPayCreatePaymentMethod(name: String!): TlyPayResult!
|
|
153
|
+
}
|
|
154
|
+
`;
|
|
155
|
+
let TlyPayShopResolver = class TlyPayShopResolver {
|
|
156
|
+
service;
|
|
157
|
+
constructor(service) {
|
|
158
|
+
this.service = service;
|
|
159
|
+
}
|
|
160
|
+
tlyPayCheckout(ctx) {
|
|
161
|
+
return this.service.presentation(ctx);
|
|
162
|
+
}
|
|
163
|
+
async createTlyPayPayment(ctx, args) {
|
|
164
|
+
try {
|
|
165
|
+
return await this.service.createPayment(ctx, args.returnUrl ?? null);
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
if (error instanceof creation_service_1.CheckoutRejected)
|
|
169
|
+
throw new core_1.UserInputError(error.code);
|
|
170
|
+
throw error;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
exports.TlyPayShopResolver = TlyPayShopResolver;
|
|
175
|
+
__decorate([
|
|
176
|
+
(0, graphql_1.Query)(),
|
|
177
|
+
__param(0, (0, core_1.Ctx)()),
|
|
178
|
+
__metadata("design:type", Function),
|
|
179
|
+
__metadata("design:paramtypes", [core_1.RequestContext]),
|
|
180
|
+
__metadata("design:returntype", void 0)
|
|
181
|
+
], TlyPayShopResolver.prototype, "tlyPayCheckout", null);
|
|
182
|
+
__decorate([
|
|
183
|
+
(0, graphql_1.Mutation)(),
|
|
184
|
+
__param(0, (0, core_1.Ctx)()),
|
|
185
|
+
__param(1, (0, graphql_1.Args)()),
|
|
186
|
+
__metadata("design:type", Function),
|
|
187
|
+
__metadata("design:paramtypes", [core_1.RequestContext, Object]),
|
|
188
|
+
__metadata("design:returntype", Promise)
|
|
189
|
+
], TlyPayShopResolver.prototype, "createTlyPayPayment", null);
|
|
190
|
+
exports.TlyPayShopResolver = TlyPayShopResolver = __decorate([
|
|
191
|
+
(0, graphql_1.Resolver)(),
|
|
192
|
+
__metadata("design:paramtypes", [service_1.TlyPayService])
|
|
193
|
+
], TlyPayShopResolver);
|
|
194
|
+
let TlyPayAdminResolver = class TlyPayAdminResolver {
|
|
195
|
+
service;
|
|
196
|
+
constructor(service) {
|
|
197
|
+
this.service = service;
|
|
198
|
+
}
|
|
199
|
+
async status(ctx) {
|
|
200
|
+
const release = await this.service.release();
|
|
201
|
+
const status = await this.service.status();
|
|
202
|
+
const chosen = await this.service.chosenMarks(status.paymentAssets);
|
|
203
|
+
const title = await this.service.checkoutTitle(ctx);
|
|
204
|
+
return {
|
|
205
|
+
...status,
|
|
206
|
+
releaseComplete: release !== null,
|
|
207
|
+
consoleOrigin: release?.consoleOrigin ?? "",
|
|
208
|
+
apiHost: release === null ? "" : new URL(release.apiOrigin).host,
|
|
209
|
+
checkoutMode: await this.service.checkoutSettings.get(),
|
|
210
|
+
checkoutIcons: chosen,
|
|
211
|
+
checkoutIconOptions: this.service.iconOptions(status.paymentAssets, chosen),
|
|
212
|
+
checkoutCoinNames: await this.service.coinNameSettings.get(),
|
|
213
|
+
checkoutTitle: title.title,
|
|
214
|
+
paymentMethodId: title.methodId,
|
|
215
|
+
siteMode: await this.service.siteSettings.get(),
|
|
216
|
+
channelCurrency: ctx.channel.defaultCurrencyCode,
|
|
217
|
+
paymentMethod: await this.service.methodState(ctx),
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
tlyPayStatus(ctx) {
|
|
221
|
+
return this.status(ctx);
|
|
222
|
+
}
|
|
223
|
+
tlyPayOrders(ctx, args) {
|
|
224
|
+
return this.service.listOrders(ctx, args.filter ?? "all", args.skip ?? 0, args.take ?? 0);
|
|
225
|
+
}
|
|
226
|
+
tlyPayOrder(ctx, args) {
|
|
227
|
+
return this.service.orderDetail(ctx, String(args.id));
|
|
228
|
+
}
|
|
229
|
+
tlyPayOrderIntent(ctx, args) {
|
|
230
|
+
return this.service.intentForOrder(ctx, args.orderCode);
|
|
231
|
+
}
|
|
232
|
+
async tlyPayCheckConnection(ctx) {
|
|
233
|
+
await this.service.refreshConnection();
|
|
234
|
+
return this.status(ctx);
|
|
235
|
+
}
|
|
236
|
+
tlyPayStartConnect(ctx, args) {
|
|
237
|
+
return this.service.start(ctx, args.adminUrl, args.popup);
|
|
238
|
+
}
|
|
239
|
+
tlyPayCompleteConnect(ctx, args) {
|
|
240
|
+
return this.service.complete(ctx, args.state, args.code);
|
|
241
|
+
}
|
|
242
|
+
tlyPayRetryConnect(ctx, args) {
|
|
243
|
+
return this.service.complete(ctx, args.state, null);
|
|
244
|
+
}
|
|
245
|
+
tlyPayDisconnect(args) {
|
|
246
|
+
return this.service.disconnect(args.confirm);
|
|
247
|
+
}
|
|
248
|
+
async tlyPaySetCheckoutMode(args) {
|
|
249
|
+
const saved = await this.service.checkoutSettings.set(args.mode);
|
|
250
|
+
return { result: saved ? "checkout_mode_saved" : "checkout_mode_invalid", retry: false };
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Saves the checkout appearance: the marks replace the choice exactly (none is a valid choice) and the
|
|
254
|
+
* coin names switch is stored beside them. The title is the payment method's own name and is not
|
|
255
|
+
* saved here.
|
|
256
|
+
*/
|
|
257
|
+
async tlyPaySetCheckoutAppearance(args) {
|
|
258
|
+
const saved = typeof args.coinNames === "boolean" && await this.service.iconSettings.set(args.marks);
|
|
259
|
+
if (saved)
|
|
260
|
+
await this.service.coinNameSettings.set(args.coinNames === true);
|
|
261
|
+
return { result: saved ? "checkout_icons_saved" : "checkout_icons_invalid", retry: false };
|
|
262
|
+
}
|
|
263
|
+
/** Runs the connection check, then selects exactly the coins the Store accepts now. */
|
|
264
|
+
tlyPaySyncCheckoutIcons() {
|
|
265
|
+
return this.service.syncCheckoutIcons();
|
|
266
|
+
}
|
|
267
|
+
/** Switches the TLY Pay site; the saved connection is kept and the store connects again. */
|
|
268
|
+
async tlyPaySetSiteMode(args) {
|
|
269
|
+
const saved = await this.service.siteSettings.set(args.mode);
|
|
270
|
+
return { result: saved ? "site_saved" : "site_invalid", retry: false };
|
|
271
|
+
}
|
|
272
|
+
tlyPayReconcile(ctx, args) {
|
|
273
|
+
return this.service.reconcile(ctx, String(args.id));
|
|
274
|
+
}
|
|
275
|
+
tlyPayCreatePaymentMethod(ctx, args) {
|
|
276
|
+
return this.service.createMethod(ctx, args.name);
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
exports.TlyPayAdminResolver = TlyPayAdminResolver;
|
|
280
|
+
__decorate([
|
|
281
|
+
(0, graphql_1.Query)(),
|
|
282
|
+
(0, core_1.Allow)(core_1.Permission.ReadSettings),
|
|
283
|
+
__param(0, (0, core_1.Ctx)()),
|
|
284
|
+
__metadata("design:type", Function),
|
|
285
|
+
__metadata("design:paramtypes", [core_1.RequestContext]),
|
|
286
|
+
__metadata("design:returntype", void 0)
|
|
287
|
+
], TlyPayAdminResolver.prototype, "tlyPayStatus", null);
|
|
288
|
+
__decorate([
|
|
289
|
+
(0, graphql_1.Query)(),
|
|
290
|
+
(0, core_1.Allow)(core_1.Permission.ReadOrder),
|
|
291
|
+
__param(0, (0, core_1.Ctx)()),
|
|
292
|
+
__param(1, (0, graphql_1.Args)()),
|
|
293
|
+
__metadata("design:type", Function),
|
|
294
|
+
__metadata("design:paramtypes", [core_1.RequestContext, Object]),
|
|
295
|
+
__metadata("design:returntype", void 0)
|
|
296
|
+
], TlyPayAdminResolver.prototype, "tlyPayOrders", null);
|
|
297
|
+
__decorate([
|
|
298
|
+
(0, graphql_1.Query)(),
|
|
299
|
+
(0, core_1.Allow)(core_1.Permission.ReadOrder),
|
|
300
|
+
__param(0, (0, core_1.Ctx)()),
|
|
301
|
+
__param(1, (0, graphql_1.Args)()),
|
|
302
|
+
__metadata("design:type", Function),
|
|
303
|
+
__metadata("design:paramtypes", [core_1.RequestContext, Object]),
|
|
304
|
+
__metadata("design:returntype", void 0)
|
|
305
|
+
], TlyPayAdminResolver.prototype, "tlyPayOrder", null);
|
|
306
|
+
__decorate([
|
|
307
|
+
(0, graphql_1.Query)(),
|
|
308
|
+
(0, core_1.Allow)(core_1.Permission.ReadOrder),
|
|
309
|
+
__param(0, (0, core_1.Ctx)()),
|
|
310
|
+
__param(1, (0, graphql_1.Args)()),
|
|
311
|
+
__metadata("design:type", Function),
|
|
312
|
+
__metadata("design:paramtypes", [core_1.RequestContext, Object]),
|
|
313
|
+
__metadata("design:returntype", void 0)
|
|
314
|
+
], TlyPayAdminResolver.prototype, "tlyPayOrderIntent", null);
|
|
315
|
+
__decorate([
|
|
316
|
+
(0, graphql_1.Mutation)(),
|
|
317
|
+
(0, core_1.Allow)(core_1.Permission.UpdateSettings),
|
|
318
|
+
__param(0, (0, core_1.Ctx)()),
|
|
319
|
+
__metadata("design:type", Function),
|
|
320
|
+
__metadata("design:paramtypes", [core_1.RequestContext]),
|
|
321
|
+
__metadata("design:returntype", Promise)
|
|
322
|
+
], TlyPayAdminResolver.prototype, "tlyPayCheckConnection", null);
|
|
323
|
+
__decorate([
|
|
324
|
+
(0, graphql_1.Mutation)(),
|
|
325
|
+
(0, core_1.Allow)(core_1.Permission.UpdateSettings),
|
|
326
|
+
__param(0, (0, core_1.Ctx)()),
|
|
327
|
+
__param(1, (0, graphql_1.Args)()),
|
|
328
|
+
__metadata("design:type", Function),
|
|
329
|
+
__metadata("design:paramtypes", [core_1.RequestContext, Object]),
|
|
330
|
+
__metadata("design:returntype", void 0)
|
|
331
|
+
], TlyPayAdminResolver.prototype, "tlyPayStartConnect", null);
|
|
332
|
+
__decorate([
|
|
333
|
+
(0, graphql_1.Mutation)(),
|
|
334
|
+
(0, core_1.Allow)(core_1.Permission.UpdateSettings),
|
|
335
|
+
__param(0, (0, core_1.Ctx)()),
|
|
336
|
+
__param(1, (0, graphql_1.Args)()),
|
|
337
|
+
__metadata("design:type", Function),
|
|
338
|
+
__metadata("design:paramtypes", [core_1.RequestContext, Object]),
|
|
339
|
+
__metadata("design:returntype", void 0)
|
|
340
|
+
], TlyPayAdminResolver.prototype, "tlyPayCompleteConnect", null);
|
|
341
|
+
__decorate([
|
|
342
|
+
(0, graphql_1.Mutation)(),
|
|
343
|
+
(0, core_1.Allow)(core_1.Permission.UpdateSettings),
|
|
344
|
+
__param(0, (0, core_1.Ctx)()),
|
|
345
|
+
__param(1, (0, graphql_1.Args)()),
|
|
346
|
+
__metadata("design:type", Function),
|
|
347
|
+
__metadata("design:paramtypes", [core_1.RequestContext, Object]),
|
|
348
|
+
__metadata("design:returntype", void 0)
|
|
349
|
+
], TlyPayAdminResolver.prototype, "tlyPayRetryConnect", null);
|
|
350
|
+
__decorate([
|
|
351
|
+
(0, graphql_1.Mutation)(),
|
|
352
|
+
(0, core_1.Allow)(core_1.Permission.UpdateSettings),
|
|
353
|
+
__param(0, (0, graphql_1.Args)()),
|
|
354
|
+
__metadata("design:type", Function),
|
|
355
|
+
__metadata("design:paramtypes", [Object]),
|
|
356
|
+
__metadata("design:returntype", void 0)
|
|
357
|
+
], TlyPayAdminResolver.prototype, "tlyPayDisconnect", null);
|
|
358
|
+
__decorate([
|
|
359
|
+
(0, graphql_1.Mutation)(),
|
|
360
|
+
(0, core_1.Allow)(core_1.Permission.UpdateSettings),
|
|
361
|
+
__param(0, (0, graphql_1.Args)()),
|
|
362
|
+
__metadata("design:type", Function),
|
|
363
|
+
__metadata("design:paramtypes", [Object]),
|
|
364
|
+
__metadata("design:returntype", Promise)
|
|
365
|
+
], TlyPayAdminResolver.prototype, "tlyPaySetCheckoutMode", null);
|
|
366
|
+
__decorate([
|
|
367
|
+
(0, graphql_1.Mutation)(),
|
|
368
|
+
(0, core_1.Allow)(core_1.Permission.UpdateSettings),
|
|
369
|
+
__param(0, (0, graphql_1.Args)()),
|
|
370
|
+
__metadata("design:type", Function),
|
|
371
|
+
__metadata("design:paramtypes", [Object]),
|
|
372
|
+
__metadata("design:returntype", Promise)
|
|
373
|
+
], TlyPayAdminResolver.prototype, "tlyPaySetCheckoutAppearance", null);
|
|
374
|
+
__decorate([
|
|
375
|
+
(0, graphql_1.Mutation)(),
|
|
376
|
+
(0, core_1.Allow)(core_1.Permission.UpdateSettings),
|
|
377
|
+
__metadata("design:type", Function),
|
|
378
|
+
__metadata("design:paramtypes", []),
|
|
379
|
+
__metadata("design:returntype", void 0)
|
|
380
|
+
], TlyPayAdminResolver.prototype, "tlyPaySyncCheckoutIcons", null);
|
|
381
|
+
__decorate([
|
|
382
|
+
(0, graphql_1.Mutation)(),
|
|
383
|
+
(0, core_1.Allow)(core_1.Permission.UpdateSettings),
|
|
384
|
+
__param(0, (0, graphql_1.Args)()),
|
|
385
|
+
__metadata("design:type", Function),
|
|
386
|
+
__metadata("design:paramtypes", [Object]),
|
|
387
|
+
__metadata("design:returntype", Promise)
|
|
388
|
+
], TlyPayAdminResolver.prototype, "tlyPaySetSiteMode", null);
|
|
389
|
+
__decorate([
|
|
390
|
+
(0, graphql_1.Mutation)(),
|
|
391
|
+
(0, core_1.Allow)(core_1.Permission.UpdateOrder),
|
|
392
|
+
__param(0, (0, core_1.Ctx)()),
|
|
393
|
+
__param(1, (0, graphql_1.Args)()),
|
|
394
|
+
__metadata("design:type", Function),
|
|
395
|
+
__metadata("design:paramtypes", [core_1.RequestContext, Object]),
|
|
396
|
+
__metadata("design:returntype", void 0)
|
|
397
|
+
], TlyPayAdminResolver.prototype, "tlyPayReconcile", null);
|
|
398
|
+
__decorate([
|
|
399
|
+
(0, graphql_1.Mutation)(),
|
|
400
|
+
(0, core_1.Allow)(core_1.Permission.CreatePaymentMethod),
|
|
401
|
+
__param(0, (0, core_1.Ctx)()),
|
|
402
|
+
__param(1, (0, graphql_1.Args)()),
|
|
403
|
+
__metadata("design:type", Function),
|
|
404
|
+
__metadata("design:paramtypes", [core_1.RequestContext, Object]),
|
|
405
|
+
__metadata("design:returntype", void 0)
|
|
406
|
+
], TlyPayAdminResolver.prototype, "tlyPayCreatePaymentMethod", null);
|
|
407
|
+
exports.TlyPayAdminResolver = TlyPayAdminResolver = __decorate([
|
|
408
|
+
(0, graphql_1.Resolver)(),
|
|
409
|
+
__metadata("design:paramtypes", [service_1.TlyPayService])
|
|
410
|
+
], TlyPayAdminResolver);
|
|
411
|
+
/**
|
|
412
|
+
* Reads the exact Webhook bytes before Vendure's JSON body parser, which skips a request already
|
|
413
|
+
* marked as parsed. Bodies over the limit are answered 413 without reading further.
|
|
414
|
+
*/
|
|
415
|
+
function rawWebhookBody(req, res, next) {
|
|
416
|
+
if (req.method !== "POST") {
|
|
417
|
+
next();
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
const chunks = [];
|
|
421
|
+
let size = 0;
|
|
422
|
+
let done = false;
|
|
423
|
+
req.on("data", (chunk) => {
|
|
424
|
+
if (done)
|
|
425
|
+
return;
|
|
426
|
+
size += chunk.byteLength;
|
|
427
|
+
if (size > exports.MAX_WEBHOOK_BYTES) {
|
|
428
|
+
done = true;
|
|
429
|
+
res.status(413).end();
|
|
430
|
+
req.destroy();
|
|
431
|
+
return;
|
|
432
|
+
}
|
|
433
|
+
chunks.push(chunk);
|
|
434
|
+
});
|
|
435
|
+
req.on("end", () => {
|
|
436
|
+
if (done)
|
|
437
|
+
return;
|
|
438
|
+
done = true;
|
|
439
|
+
req.tlyPayRawBody = Buffer.concat(chunks);
|
|
440
|
+
req._body = true;
|
|
441
|
+
next();
|
|
442
|
+
});
|
|
443
|
+
req.on("error", (error) => {
|
|
444
|
+
if (done)
|
|
445
|
+
return;
|
|
446
|
+
done = true;
|
|
447
|
+
next(error);
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* The public routes registered for Vendure in the platform connection registry: the Webhook
|
|
452
|
+
* `POST /tly-pay/webhook` and the connection callback `GET /tly-pay/connect/return`, plus the
|
|
453
|
+
* bundled coin icons the storefront shows beside the checkout title.
|
|
454
|
+
*/
|
|
455
|
+
let TlyPayController = class TlyPayController {
|
|
456
|
+
service;
|
|
457
|
+
constructor(service) {
|
|
458
|
+
this.service = service;
|
|
459
|
+
}
|
|
460
|
+
async webhook(req, res) {
|
|
461
|
+
const headers = {};
|
|
462
|
+
for (const name of ["content-type", "x-tly-webhook-id", "x-tly-webhook-timestamp", "x-tly-webhook-signature"]) {
|
|
463
|
+
const value = req.headers[name];
|
|
464
|
+
headers[name] = typeof value === "string" ? value : undefined;
|
|
465
|
+
}
|
|
466
|
+
let answer;
|
|
467
|
+
try {
|
|
468
|
+
answer = req.tlyPayRawBody === undefined ? { status: 400 }
|
|
469
|
+
: await this.service.webhook(new Uint8Array(req.tlyPayRawBody), headers);
|
|
470
|
+
}
|
|
471
|
+
catch (error) {
|
|
472
|
+
core_1.Logger.error(`Webhook handling failed: ${error.message}`, LOG_CONTEXT);
|
|
473
|
+
answer = { status: 503 };
|
|
474
|
+
}
|
|
475
|
+
for (const [name, value] of Object.entries(answer.headers ?? {}))
|
|
476
|
+
res.setHeader(name, value);
|
|
477
|
+
// A connection check answer is signed over these exact bytes, so they are written unchanged.
|
|
478
|
+
if (answer.body === undefined)
|
|
479
|
+
res.status(answer.status).end();
|
|
480
|
+
else
|
|
481
|
+
res.status(answer.status).end(answer.body);
|
|
482
|
+
}
|
|
483
|
+
/** Needs no session: forwards `state` and `code` to the Dashboard page that started the connection. */
|
|
484
|
+
async connectReturn(state, code, res) {
|
|
485
|
+
let target = null;
|
|
486
|
+
try {
|
|
487
|
+
target = typeof state === "string" ? await this.service.flow.returnTarget(state, typeof code === "string" ? code : "") : null;
|
|
488
|
+
}
|
|
489
|
+
catch (error) {
|
|
490
|
+
core_1.Logger.warn(`Connection return failed: ${error.message}`, LOG_CONTEXT);
|
|
491
|
+
}
|
|
492
|
+
res.setHeader("Cache-Control", "no-store");
|
|
493
|
+
res.setHeader("Referrer-Policy", "no-referrer");
|
|
494
|
+
if (target !== null) {
|
|
495
|
+
res.redirect(302, target);
|
|
496
|
+
return;
|
|
497
|
+
}
|
|
498
|
+
res.status(404).type("text/plain").send("This TLY Pay connection request expired. Start the connection again in the Vendure Dashboard.");
|
|
499
|
+
}
|
|
500
|
+
async coin(file, res) {
|
|
501
|
+
const path = this.service.coinPath(file);
|
|
502
|
+
if (path === null) {
|
|
503
|
+
res.status(404).end();
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
506
|
+
res.setHeader("Content-Type", "image/svg+xml");
|
|
507
|
+
res.setHeader("Content-Security-Policy", "default-src 'none'; style-src 'unsafe-inline'");
|
|
508
|
+
res.setHeader("X-Content-Type-Options", "nosniff");
|
|
509
|
+
res.status(200).send(await (0, promises_1.readFile)(path));
|
|
510
|
+
}
|
|
511
|
+
};
|
|
512
|
+
exports.TlyPayController = TlyPayController;
|
|
513
|
+
__decorate([
|
|
514
|
+
(0, common_1.Post)("webhook"),
|
|
515
|
+
__param(0, (0, common_1.Req)()),
|
|
516
|
+
__param(1, (0, common_1.Res)()),
|
|
517
|
+
__metadata("design:type", Function),
|
|
518
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
519
|
+
__metadata("design:returntype", Promise)
|
|
520
|
+
], TlyPayController.prototype, "webhook", null);
|
|
521
|
+
__decorate([
|
|
522
|
+
(0, common_1.Get)("connect/return"),
|
|
523
|
+
__param(0, (0, common_1.Query)("state")),
|
|
524
|
+
__param(1, (0, common_1.Query)("code")),
|
|
525
|
+
__param(2, (0, common_1.Res)()),
|
|
526
|
+
__metadata("design:type", Function),
|
|
527
|
+
__metadata("design:paramtypes", [Object, Object, Object]),
|
|
528
|
+
__metadata("design:returntype", Promise)
|
|
529
|
+
], TlyPayController.prototype, "connectReturn", null);
|
|
530
|
+
__decorate([
|
|
531
|
+
(0, common_1.Get)("coins/:file"),
|
|
532
|
+
__param(0, (0, common_1.Param)("file")),
|
|
533
|
+
__param(1, (0, common_1.Res)()),
|
|
534
|
+
__metadata("design:type", Function),
|
|
535
|
+
__metadata("design:paramtypes", [String, Object]),
|
|
536
|
+
__metadata("design:returntype", Promise)
|
|
537
|
+
], TlyPayController.prototype, "coin", null);
|
|
538
|
+
exports.TlyPayController = TlyPayController = __decorate([
|
|
539
|
+
(0, common_1.Controller)("tly-pay"),
|
|
540
|
+
__metadata("design:paramtypes", [service_1.TlyPayService])
|
|
541
|
+
], TlyPayController);
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { TransactionalConnection } from "@vendure/core";
|
|
2
|
+
import { SiteMode } from "./release-config";
|
|
3
|
+
export declare const CLIENT_REF_NAMESPACE = "tlyPay";
|
|
4
|
+
export declare const CLIENT_REF_FIELD = "clientRef";
|
|
5
|
+
export declare const CLIENT_REF_KEY = "tlyPay.clientRef";
|
|
6
|
+
/**
|
|
7
|
+
* Keeps this installation's `client_ref` in the Vendure Settings Store, apart from the API Key and
|
|
8
|
+
* Webhook Secrets, so changing or reconnecting them keeps it. Reads and the first insert use the raw
|
|
9
|
+
* autocommit connection, outside any host request transaction: a request that rolls back after the
|
|
10
|
+
* Payment was created cannot lose the value, and a caller whose insert is ignored reads the committed
|
|
11
|
+
* winner.
|
|
12
|
+
*/
|
|
13
|
+
export declare class TlyPayClientRefService {
|
|
14
|
+
private readonly connection;
|
|
15
|
+
constructor(connection: TransactionalConnection);
|
|
16
|
+
get(): Promise<string>;
|
|
17
|
+
}
|
|
18
|
+
export declare const CHECKOUT_MODE_FIELD = "checkoutMode";
|
|
19
|
+
export declare const CHECKOUT_MODE_KEY = "tlyPay.checkoutMode";
|
|
20
|
+
export declare const CHECKOUT_MODES: readonly ["hosted", "embedded"];
|
|
21
|
+
export type CheckoutModeSetting = typeof CHECKOUT_MODES[number];
|
|
22
|
+
/** Vendure storefronts are headless, so new Payments use Hosted Checkout until the merchant opts in. */
|
|
23
|
+
export declare const DEFAULT_CHECKOUT_MODE: CheckoutModeSetting;
|
|
24
|
+
/**
|
|
25
|
+
* Keeps the checkout mode of new Payments in the Settings Store. It is independent of the connection,
|
|
26
|
+
* so Disconnect keeps it; an existing intent keeps the mode it was created with.
|
|
27
|
+
*/
|
|
28
|
+
export declare class TlyPayCheckoutSettings {
|
|
29
|
+
private readonly connection;
|
|
30
|
+
constructor(connection: TransactionalConnection);
|
|
31
|
+
get(): Promise<CheckoutModeSetting>;
|
|
32
|
+
set(mode: string): Promise<boolean>;
|
|
33
|
+
}
|
|
34
|
+
export declare const CHECKOUT_ICONS_FIELD = "checkoutIcons";
|
|
35
|
+
export declare const CHECKOUT_ICONS_KEY = "tlyPay.checkoutIcons";
|
|
36
|
+
/** A checkout icon mark: the lowercase key of a bundled coin icon. */
|
|
37
|
+
export declare const ICON_MARK: RegExp;
|
|
38
|
+
/**
|
|
39
|
+
* Keeps the checkout icon marks chosen in Settings > Checkout appearance in the Settings Store as a JSON
|
|
40
|
+
* array. A missing entry means the merchant never chose and reads as null, which checkout resolves to
|
|
41
|
+
* every coin the Store accepts; an empty array shows no icons. A saved mark is shown whether or not the
|
|
42
|
+
* Store accepts it.
|
|
43
|
+
*/
|
|
44
|
+
export declare class TlyPayCheckoutIconSettings {
|
|
45
|
+
private readonly connection;
|
|
46
|
+
constructor(connection: TransactionalConnection);
|
|
47
|
+
/** The saved marks, or null while no choice was saved. */
|
|
48
|
+
get(): Promise<string[] | null>;
|
|
49
|
+
/** Replaces the choice with the sanitized marks; false when the input is not a list of strings. */
|
|
50
|
+
set(input: unknown): Promise<boolean>;
|
|
51
|
+
}
|
|
52
|
+
export declare const CHECKOUT_COIN_NAMES_FIELD = "checkoutCoinNames";
|
|
53
|
+
export declare const CHECKOUT_COIN_NAMES_KEY = "tlyPay.checkoutCoinNames";
|
|
54
|
+
/**
|
|
55
|
+
* Keeps the "Show coin names under the title" switch of Settings > Checkout appearance in the Settings
|
|
56
|
+
* Store. It is off unless saved on, so checkout shows no text under the title by default.
|
|
57
|
+
*/
|
|
58
|
+
export declare class TlyPayCoinNamesSettings {
|
|
59
|
+
private readonly connection;
|
|
60
|
+
constructor(connection: TransactionalConnection);
|
|
61
|
+
get(): Promise<boolean>;
|
|
62
|
+
set(shown: boolean): Promise<void>;
|
|
63
|
+
}
|
|
64
|
+
export declare const SITE_MODE_FIELD = "siteMode";
|
|
65
|
+
export declare const SITE_MODE_KEY = "tlyPay.siteMode";
|
|
66
|
+
/**
|
|
67
|
+
* Keeps the TLY Pay site of Settings > Advanced in the Settings Store. Changing it keeps the saved
|
|
68
|
+
* connection; a connection saved for the other site is not used until the store connects again.
|
|
69
|
+
*/
|
|
70
|
+
export declare class TlyPaySiteSettings {
|
|
71
|
+
private readonly connection;
|
|
72
|
+
constructor(connection: TransactionalConnection);
|
|
73
|
+
get(): Promise<SiteMode>;
|
|
74
|
+
set(mode: string): Promise<boolean>;
|
|
75
|
+
}
|