@sakeetech/vendure-payment-viva 0.2.1 → 0.2.3
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/README.md +6 -2
- package/dist/api/admin-internal.controller.js +30 -27
- package/dist/api/admin-internal.controller.js.map +1 -1
- package/dist/api/admin-onboarding.controller.js +58 -55
- package/dist/api/admin-onboarding.controller.js.map +1 -1
- package/dist/api/admin-sources.controller.js +44 -41
- package/dist/api/admin-sources.controller.js.map +1 -1
- package/dist/api/shop-api.extension.d.ts.map +1 -1
- package/dist/api/shop-api.extension.js +32 -3
- package/dist/api/shop-api.extension.js.map +1 -1
- package/dist/api/shop-api.resolver.js +27 -24
- package/dist/api/shop-api.resolver.js.map +1 -1
- package/dist/api/webhook.controller.js +31 -28
- package/dist/api/webhook.controller.js.map +1 -1
- package/dist/cli/bin.d.ts +1 -1
- package/dist/cli/bin.js +10 -6
- package/dist/cli/bin.js.map +1 -1
- package/dist/cli/plan.js +6 -2
- package/dist/cli/plan.js.map +1 -1
- package/dist/cli/register-webhooks.js +25 -22
- package/dist/cli/register-webhooks.js.map +1 -1
- package/dist/cli/types.js +2 -1
- package/dist/cli/types.js.map +1 -1
- package/dist/constants.js +17 -14
- package/dist/constants.js.map +1 -1
- package/dist/entities/index.js +7 -2
- package/dist/entities/index.js.map +1 -1
- package/dist/entities/viva-transaction.entity.js +20 -17
- package/dist/entities/viva-transaction.entity.js.map +1 -1
- package/dist/entities/viva-webhook-event.entity.js +19 -16
- package/dist/entities/viva-webhook-event.entity.js.map +1 -1
- package/dist/index.js +36 -12
- package/dist/index.js.map +1 -1
- package/dist/jobs/process-viva-webhook.handler.js +64 -62
- package/dist/jobs/process-viva-webhook.handler.js.map +1 -1
- package/dist/jobs/queue-names.js +5 -2
- package/dist/jobs/queue-names.js.map +1 -1
- package/dist/jobs/retention-cleanup.handler.js +17 -14
- package/dist/jobs/retention-cleanup.handler.js.map +1 -1
- package/dist/loaders/bootstrap.js +20 -17
- package/dist/loaders/bootstrap.js.map +1 -1
- package/dist/migrations/1714000000000-create-viva-tables.js +5 -2
- package/dist/migrations/1714000000000-create-viva-tables.js.map +1 -1
- package/dist/observability/metrics-state.service.js +16 -13
- package/dist/observability/metrics-state.service.js.map +1 -1
- package/dist/payment-method-handler.js +63 -59
- package/dist/payment-method-handler.js.map +1 -1
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +50 -42
- package/dist/plugin.js.map +1 -1
- package/dist/providers/viva-oauth2-strategy.provider.js +16 -11
- package/dist/providers/viva-oauth2-strategy.provider.js.map +1 -1
- package/dist/services/connected-accounts.service.js +16 -13
- package/dist/services/connected-accounts.service.js.map +1 -1
- package/dist/services/per-merchant-semaphore.service.js +10 -7
- package/dist/services/per-merchant-semaphore.service.js.map +1 -1
- package/dist/services/state-machine.service.js +26 -23
- package/dist/services/state-machine.service.js.map +1 -1
- package/dist/types.js +2 -1
- package/dist/types.js.map +1 -1
- package/dist/util/currency.js +11 -6
- package/dist/util/currency.js.map +1 -1
- package/dist/util/error-envelope.js +5 -1
- package/dist/util/error-envelope.js.map +1 -1
- package/dist/util/ip-allowlist.js +11 -6
- package/dist/util/ip-allowlist.js.map +1 -1
- package/dist/util/normalize-options.js +8 -4
- package/dist/util/normalize-options.js.map +1 -1
- package/dist/util/url-template.js +4 -1
- package/dist/util/url-template.js.map +1 -1
- package/package.json +4 -5
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* loaders/bootstrap.ts — Vendure plugin bootstrap warmup hook.
|
|
3
4
|
*
|
|
@@ -25,10 +26,12 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
25
26
|
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
26
27
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
27
28
|
};
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
+
exports.VivaBootstrap = void 0;
|
|
31
|
+
const common_1 = require("@nestjs/common");
|
|
32
|
+
const core_1 = require("@vendure/core");
|
|
33
|
+
const auth_1 = require("@sakeetech/viva-payments-core/auth");
|
|
34
|
+
const constants_js_1 = require("../constants.js");
|
|
32
35
|
// ---------------------------------------------------------------------------
|
|
33
36
|
// Bootstrap service
|
|
34
37
|
// ---------------------------------------------------------------------------
|
|
@@ -43,7 +46,7 @@ let VivaBootstrap = class VivaBootstrap {
|
|
|
43
46
|
_lastWarmupFailed = false;
|
|
44
47
|
get lastWarmupFailed() { return this._lastWarmupFailed; }
|
|
45
48
|
async onApplicationBootstrap() {
|
|
46
|
-
Logger.info('Starting Viva Wallet bootstrap warmup…', VIVA_LOG_CONTEXT);
|
|
49
|
+
core_1.Logger.info('Starting Viva Wallet bootstrap warmup…', constants_js_1.VIVA_LOG_CONTEXT);
|
|
47
50
|
await this._runWarmup(false);
|
|
48
51
|
}
|
|
49
52
|
// ---------------------------------------------------------------------------
|
|
@@ -54,13 +57,13 @@ let VivaBootstrap = class VivaBootstrap {
|
|
|
54
57
|
try {
|
|
55
58
|
// 1. Eager OAuth token fetch — warms the in-memory cache.
|
|
56
59
|
await this.oauth2.getBearerToken();
|
|
57
|
-
Logger.info(`${tag}Viva OAuth2 token cached successfully.`, VIVA_LOG_CONTEXT);
|
|
60
|
+
core_1.Logger.info(`${tag}Viva OAuth2 token cached successfully.`, constants_js_1.VIVA_LOG_CONTEXT);
|
|
58
61
|
// 2. Pre-connect undici pools to both Viva hosts.
|
|
59
62
|
// Fire-and-forget: just accessing the pool initialises the connection.
|
|
60
63
|
// We don't need to do an actual HTTP request for the warmup.
|
|
61
|
-
getAuthDispatcher(this.options.environment);
|
|
62
|
-
getApiDispatcher(this.options.environment);
|
|
63
|
-
Logger.info(`${tag}Viva undici pools pre-connected (env=${this.options.environment}).`, VIVA_LOG_CONTEXT);
|
|
64
|
+
(0, auth_1.getAuthDispatcher)(this.options.environment);
|
|
65
|
+
(0, auth_1.getApiDispatcher)(this.options.environment);
|
|
66
|
+
core_1.Logger.info(`${tag}Viva undici pools pre-connected (env=${this.options.environment}).`, constants_js_1.VIVA_LOG_CONTEXT);
|
|
64
67
|
this._lastWarmupFailed = false;
|
|
65
68
|
}
|
|
66
69
|
catch (err) {
|
|
@@ -68,23 +71,23 @@ let VivaBootstrap = class VivaBootstrap {
|
|
|
68
71
|
const msg = err instanceof Error ? err.message : String(err);
|
|
69
72
|
if (isRetry) {
|
|
70
73
|
// Retry also failed — leave cache empty, log warning, stop retrying.
|
|
71
|
-
Logger.warn(`Viva bootstrap warmup retry failed: ${msg}. Token will be lazily fetched on first createPayment call.`, VIVA_LOG_CONTEXT);
|
|
74
|
+
core_1.Logger.warn(`Viva bootstrap warmup retry failed: ${msg}. Token will be lazily fetched on first createPayment call.`, constants_js_1.VIVA_LOG_CONTEXT);
|
|
72
75
|
}
|
|
73
76
|
else {
|
|
74
77
|
// First attempt failed — schedule one retry.
|
|
75
|
-
Logger.warn(`Viva bootstrap warmup failed: ${msg}. Scheduling retry in ${BOOTSTRAP_RETRY_DELAY_MS}ms.`, VIVA_LOG_CONTEXT);
|
|
78
|
+
core_1.Logger.warn(`Viva bootstrap warmup failed: ${msg}. Scheduling retry in ${constants_js_1.BOOTSTRAP_RETRY_DELAY_MS}ms.`, constants_js_1.VIVA_LOG_CONTEXT);
|
|
76
79
|
setTimeout(() => {
|
|
77
80
|
void this._runWarmup(true);
|
|
78
|
-
}, BOOTSTRAP_RETRY_DELAY_MS);
|
|
81
|
+
}, constants_js_1.BOOTSTRAP_RETRY_DELAY_MS);
|
|
79
82
|
}
|
|
80
83
|
}
|
|
81
84
|
}
|
|
82
85
|
};
|
|
83
|
-
VivaBootstrap =
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
__param(
|
|
86
|
+
exports.VivaBootstrap = VivaBootstrap;
|
|
87
|
+
exports.VivaBootstrap = VivaBootstrap = __decorate([
|
|
88
|
+
(0, common_1.Injectable)(),
|
|
89
|
+
__param(0, (0, common_1.Inject)(constants_js_1.VIVA_PLUGIN_OPTIONS)),
|
|
90
|
+
__param(1, (0, common_1.Inject)(constants_js_1.VIVA_OAUTH2_STRATEGY_TOKEN)),
|
|
87
91
|
__metadata("design:paramtypes", [Object, Object])
|
|
88
92
|
], VivaBootstrap);
|
|
89
|
-
export { VivaBootstrap };
|
|
90
93
|
//# sourceMappingURL=bootstrap.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../../src/loaders/bootstrap.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG
|
|
1
|
+
{"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../../src/loaders/bootstrap.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;AAEH,2CAAoD;AAEpD,wCAAuC;AACvC,6DAAyF;AAGzF,kDAKyB;AAEzB,8EAA8E;AAC9E,oBAAoB;AACpB,8EAA8E;AAGvE,IAAM,aAAa,GAAnB,MAAM,aAAa;IAEwB;IACO;IAFvD,YACgD,OAAiC,EAC1B,MAA0B;QADjC,YAAO,GAAP,OAAO,CAA0B;QAC1B,WAAM,GAAN,MAAM,CAAoB;IAC9E,CAAC;IAEJ,+DAA+D;IACvD,iBAAiB,GAAG,KAAK,CAAC;IAClC,IAAI,gBAAgB,KAAc,OAAO,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC;IAElE,KAAK,CAAC,sBAAsB;QAC1B,aAAM,CAAC,IAAI,CAAC,wCAAwC,EAAE,+BAAgB,CAAC,CAAC;QACxE,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;IAED,8EAA8E;IAC9E,WAAW;IACX,8EAA8E;IAEtE,KAAK,CAAC,UAAU,CAAC,OAAgB;QACvC,MAAM,GAAG,GAAG,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC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,WAAA,IAAA,eAAM,EAAC,kCAAmB,CAAC,CAAA;IAC3B,WAAA,IAAA,eAAM,EAAC,yCAA0B,CAAC,CAAA;;GAH1B,aAAa,CAyDzB"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* 1714000000000-create-viva-tables.ts — Initial migration for Viva Wallet plugin tables.
|
|
3
4
|
*
|
|
@@ -13,8 +14,9 @@
|
|
|
13
14
|
* Partial indexes (WHERE clauses) use raw SQL via queryRunner.query() because
|
|
14
15
|
* TypeORM's createIndex API does not support WHERE predicates.
|
|
15
16
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.CreateVivaTables1714000000000 = void 0;
|
|
19
|
+
class CreateVivaTables1714000000000 {
|
|
18
20
|
name = 'CreateVivaTables1714000000000';
|
|
19
21
|
async up(queryRunner) {
|
|
20
22
|
// -----------------------------------------------------------------------
|
|
@@ -102,4 +104,5 @@ export class CreateVivaTables1714000000000 {
|
|
|
102
104
|
await queryRunner.query(`DROP TABLE IF EXISTS "viva_transaction"`);
|
|
103
105
|
}
|
|
104
106
|
}
|
|
107
|
+
exports.CreateVivaTables1714000000000 = CreateVivaTables1714000000000;
|
|
105
108
|
//# sourceMappingURL=1714000000000-create-viva-tables.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"1714000000000-create-viva-tables.js","sourceRoot":"","sources":["../../src/migrations/1714000000000-create-viva-tables.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG
|
|
1
|
+
{"version":3,"file":"1714000000000-create-viva-tables.js","sourceRoot":"","sources":["../../src/migrations/1714000000000-create-viva-tables.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAIH,MAAa,6BAA6B;IACxC,IAAI,GAAG,+BAA+B,CAAC;IAEvC,KAAK,CAAC,EAAE,CAAC,WAAwB;QAC/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C"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* observability/metrics-state.service.ts — In-process metrics state singleton.
|
|
3
4
|
*
|
|
@@ -27,11 +28,13 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
27
28
|
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;
|
|
28
29
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
29
30
|
};
|
|
30
|
-
|
|
31
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
+
exports.MetricsStateService = exports.ISV_API_DURATION_BUCKETS = void 0;
|
|
33
|
+
const common_1 = require("@nestjs/common");
|
|
31
34
|
// ---------------------------------------------------------------------------
|
|
32
35
|
// Histogram buckets
|
|
33
36
|
// ---------------------------------------------------------------------------
|
|
34
|
-
|
|
37
|
+
exports.ISV_API_DURATION_BUCKETS = Object.freeze([
|
|
35
38
|
0.05, 0.1, 0.25, 0.5, 1, 2, 5,
|
|
36
39
|
]);
|
|
37
40
|
// ---------------------------------------------------------------------------
|
|
@@ -133,18 +136,18 @@ let MetricsStateService = class MetricsStateService {
|
|
|
133
136
|
state.labelMap.set(key, labels);
|
|
134
137
|
if (!state.counts.has(key)) {
|
|
135
138
|
// +1 slot for +Inf
|
|
136
|
-
state.counts.set(key, new Array(ISV_API_DURATION_BUCKETS.length + 1).fill(0));
|
|
139
|
+
state.counts.set(key, new Array(exports.ISV_API_DURATION_BUCKETS.length + 1).fill(0));
|
|
137
140
|
}
|
|
138
141
|
const bucketCounts = state.counts.get(key);
|
|
139
|
-
for (let i = 0; i < ISV_API_DURATION_BUCKETS.length; i++) {
|
|
140
|
-
if (durationSeconds <= ISV_API_DURATION_BUCKETS[i]) {
|
|
142
|
+
for (let i = 0; i < exports.ISV_API_DURATION_BUCKETS.length; i++) {
|
|
143
|
+
if (durationSeconds <= exports.ISV_API_DURATION_BUCKETS[i]) {
|
|
141
144
|
bucketCounts[i];
|
|
142
145
|
bucketCounts[i] = (bucketCounts[i] ?? 0) + 1;
|
|
143
146
|
}
|
|
144
147
|
}
|
|
145
148
|
// +Inf always
|
|
146
|
-
bucketCounts[ISV_API_DURATION_BUCKETS.length] =
|
|
147
|
-
(bucketCounts[ISV_API_DURATION_BUCKETS.length] ?? 0) + 1;
|
|
149
|
+
bucketCounts[exports.ISV_API_DURATION_BUCKETS.length] =
|
|
150
|
+
(bucketCounts[exports.ISV_API_DURATION_BUCKETS.length] ?? 0) + 1;
|
|
148
151
|
state.sum.set(key, (state.sum.get(key) ?? 0) + durationSeconds);
|
|
149
152
|
state.count.set(key, (state.count.get(key) ?? 0) + 1);
|
|
150
153
|
}
|
|
@@ -187,11 +190,11 @@ let MetricsStateService = class MetricsStateService {
|
|
|
187
190
|
lines.push(`# TYPE ${name} histogram`);
|
|
188
191
|
for (const [key, bucketCounts] of state.counts) {
|
|
189
192
|
const labels = state.labelMap.get(key) ?? {};
|
|
190
|
-
for (let i = 0; i < ISV_API_DURATION_BUCKETS.length; i++) {
|
|
191
|
-
const le = ISV_API_DURATION_BUCKETS[i];
|
|
193
|
+
for (let i = 0; i < exports.ISV_API_DURATION_BUCKETS.length; i++) {
|
|
194
|
+
const le = exports.ISV_API_DURATION_BUCKETS[i];
|
|
192
195
|
lines.push(`${name}_bucket${labelStr({ ...labels, le: String(le) })} ${bucketCounts[i] ?? 0}`);
|
|
193
196
|
}
|
|
194
|
-
lines.push(`${name}_bucket${labelStr({ ...labels, le: '+Inf' })} ${bucketCounts[ISV_API_DURATION_BUCKETS.length] ?? 0}`);
|
|
197
|
+
lines.push(`${name}_bucket${labelStr({ ...labels, le: '+Inf' })} ${bucketCounts[exports.ISV_API_DURATION_BUCKETS.length] ?? 0}`);
|
|
195
198
|
lines.push(`${name}_sum${labelStr(labels)} ${state.sum.get(key) ?? 0}`);
|
|
196
199
|
lines.push(`${name}_count${labelStr(labels)} ${state.count.get(key) ?? 0}`);
|
|
197
200
|
}
|
|
@@ -200,8 +203,8 @@ let MetricsStateService = class MetricsStateService {
|
|
|
200
203
|
return lines.join('\n');
|
|
201
204
|
}
|
|
202
205
|
};
|
|
203
|
-
MetricsStateService =
|
|
204
|
-
|
|
206
|
+
exports.MetricsStateService = MetricsStateService;
|
|
207
|
+
exports.MetricsStateService = MetricsStateService = __decorate([
|
|
208
|
+
(0, common_1.Injectable)()
|
|
205
209
|
], MetricsStateService);
|
|
206
|
-
export { MetricsStateService };
|
|
207
210
|
//# sourceMappingURL=metrics-state.service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metrics-state.service.js","sourceRoot":"","sources":["../../src/observability/metrics-state.service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG
|
|
1
|
+
{"version":3,"file":"metrics-state.service.js","sourceRoot":"","sources":["../../src/observability/metrics-state.service.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;;;;;;;;;AAEH,2CAA4C;AAE5C,8EAA8E;AAC9E,oBAAoB;AACpB,8EAA8E;AAEjE,QAAA,wBAAwB,GAAsB,MAAM,CAAC,MAAM,CAAC;IACvE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;CAC9B,CAAC,CAAC;AAcH,8EAA8E;AAC9E,UAAU;AACV,8EAA8E;AAE9E,SAAS,QAAQ,CAAC,MAA8B;IAC9C,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC;IACxC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACxD,CAAC;AAED,SAAS,QAAQ,CAAC,MAA8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,CAAC;YACD,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACjB,CAAC;QAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;CACF,CAAA;AAhLY,kDAAmB;8BAAnB,mBAAmB;IAD/B,IAAA,mBAAU,GAAE;GACA,mBAAmB,CAgL/B"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* payment-method-handler.ts — Vendure PaymentMethodHandler for Viva Wallet ISV.
|
|
3
4
|
*
|
|
@@ -8,17 +9,20 @@
|
|
|
8
9
|
* @see docs/plans/vendure-plugin-v0.md §"API Surface — PaymentMethodHandler operations"
|
|
9
10
|
* @see docs/plans/vendure-plugin-v0.md §"Architecture Decisions D3 + D5 + D11"
|
|
10
11
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.vivaPaymentMethodHandler = void 0;
|
|
14
|
+
exports._testInjectDeps = _testInjectDeps;
|
|
15
|
+
const core_1 = require("@vendure/core");
|
|
16
|
+
const isv_1 = require("@sakeetech/viva-payments-core/isv");
|
|
17
|
+
const payments_1 = require("@sakeetech/viva-payments-core/payments");
|
|
18
|
+
const legacy_1 = require("@sakeetech/viva-payments-core/legacy");
|
|
19
|
+
const refunds_1 = require("@sakeetech/viva-payments-core/refunds");
|
|
20
|
+
const errors_1 = require("@sakeetech/viva-payments-core/errors");
|
|
21
|
+
const state_machine_service_js_1 = require("./services/state-machine.service.js");
|
|
22
|
+
const error_envelope_js_1 = require("./util/error-envelope.js");
|
|
23
|
+
const currency_js_1 = require("./util/currency.js");
|
|
24
|
+
const url_template_js_1 = require("./util/url-template.js");
|
|
25
|
+
const constants_js_1 = require("./constants.js");
|
|
22
26
|
// ---------------------------------------------------------------------------
|
|
23
27
|
// Constants
|
|
24
28
|
// ---------------------------------------------------------------------------
|
|
@@ -51,7 +55,7 @@ let _stateMachine;
|
|
|
51
55
|
* @see docs/plans/multi-mode-v0.md §9
|
|
52
56
|
*/
|
|
53
57
|
function buildPaymentsClient(options, oauth2) {
|
|
54
|
-
const client = new IsvHttpClient({
|
|
58
|
+
const client = new isv_1.IsvHttpClient({
|
|
55
59
|
environment: options.environment,
|
|
56
60
|
authStrategy: oauth2,
|
|
57
61
|
});
|
|
@@ -60,7 +64,7 @@ function buildPaymentsClient(options, oauth2) {
|
|
|
60
64
|
// Refund must use the legacy host with Basic auth (legacyMerchantId:legacyApiKey).
|
|
61
65
|
// @see references/viva-docs/md/tut-create-recurring-payment.txt:288
|
|
62
66
|
const legacyClient = buildLegacyClient(options);
|
|
63
|
-
return new Payments({
|
|
67
|
+
return new payments_1.Payments({
|
|
64
68
|
mode: options.mode,
|
|
65
69
|
client,
|
|
66
70
|
legacyClient,
|
|
@@ -76,7 +80,7 @@ function buildPaymentsClient(options, oauth2) {
|
|
|
76
80
|
* @see docs/AUTH.md §6.2
|
|
77
81
|
*/
|
|
78
82
|
function buildLegacyClient(options) {
|
|
79
|
-
return new BasicAuthClient({
|
|
83
|
+
return new legacy_1.BasicAuthClient({
|
|
80
84
|
environment: options.environment,
|
|
81
85
|
merchantId: options.legacyMerchantId,
|
|
82
86
|
apiKey: options.legacyApiKey,
|
|
@@ -92,17 +96,17 @@ function buildLegacyClient(options) {
|
|
|
92
96
|
* @see docs/ENDPOINTS.md §4
|
|
93
97
|
*/
|
|
94
98
|
function buildFastRefundClient(options, oauth2) {
|
|
95
|
-
const client = new IsvHttpClient({
|
|
99
|
+
const client = new isv_1.IsvHttpClient({
|
|
96
100
|
environment: options.environment,
|
|
97
101
|
authStrategy: oauth2,
|
|
98
102
|
});
|
|
99
|
-
return new FastRefundClient({ client });
|
|
103
|
+
return new refunds_1.FastRefundClient({ client });
|
|
100
104
|
}
|
|
101
105
|
function getIsvPayments() {
|
|
102
106
|
if (_isvPaymentsOverride)
|
|
103
107
|
return _isvPaymentsOverride;
|
|
104
108
|
if (!_oauth2 || !_options) {
|
|
105
|
-
throw VivaPluginError.internalError('VivaPaymentMethodHandler not initialised. Did you call init()?');
|
|
109
|
+
throw error_envelope_js_1.VivaPluginError.internalError('VivaPaymentMethodHandler not initialised. Did you call init()?');
|
|
106
110
|
}
|
|
107
111
|
return buildPaymentsClient(_options, _oauth2);
|
|
108
112
|
}
|
|
@@ -110,7 +114,7 @@ function getFastRefundClient() {
|
|
|
110
114
|
if (_fastRefundOverride)
|
|
111
115
|
return _fastRefundOverride;
|
|
112
116
|
if (!_oauth2 || !_options) {
|
|
113
|
-
throw VivaPluginError.internalError('VivaPaymentMethodHandler not initialised. Did you call init()?');
|
|
117
|
+
throw error_envelope_js_1.VivaPluginError.internalError('VivaPaymentMethodHandler not initialised. Did you call init()?');
|
|
114
118
|
}
|
|
115
119
|
return buildFastRefundClient(_options, _oauth2);
|
|
116
120
|
}
|
|
@@ -224,13 +228,13 @@ function mapApiError(err) {
|
|
|
224
228
|
if (err.message)
|
|
225
229
|
opts.vivaErrorMessage = err.message;
|
|
226
230
|
opts.cause = err;
|
|
227
|
-
throw VivaPluginError.apiError(opts);
|
|
231
|
+
throw error_envelope_js_1.VivaPluginError.apiError(opts);
|
|
228
232
|
}
|
|
229
233
|
/** Returns true when the error indicates a Viva-side 5xx / auth / network failure. */
|
|
230
234
|
function isRetryableVivaError(err) {
|
|
231
|
-
if (err instanceof VivaAuthError)
|
|
235
|
+
if (err instanceof errors_1.VivaAuthError)
|
|
232
236
|
return true;
|
|
233
|
-
if (err instanceof VivaApiError && err.httpStatus !== undefined && err.httpStatus >= 500)
|
|
237
|
+
if (err instanceof errors_1.VivaApiError && err.httpStatus !== undefined && err.httpStatus >= 500)
|
|
234
238
|
return true;
|
|
235
239
|
return false;
|
|
236
240
|
}
|
|
@@ -238,7 +242,7 @@ function isRetryableVivaError(err) {
|
|
|
238
242
|
// Test injection — allows unit tests to bypass NestJS DI
|
|
239
243
|
// ---------------------------------------------------------------------------
|
|
240
244
|
/** @internal Test-only: inject dependencies without NestJS DI. */
|
|
241
|
-
|
|
245
|
+
function _testInjectDeps(opts) {
|
|
242
246
|
_options = opts.options;
|
|
243
247
|
_oauth2 = opts.oauth2;
|
|
244
248
|
_stateMachine = opts.stateMachine;
|
|
@@ -251,11 +255,11 @@ let _fastRefundOverride;
|
|
|
251
255
|
// ---------------------------------------------------------------------------
|
|
252
256
|
// PaymentMethodHandler
|
|
253
257
|
// ---------------------------------------------------------------------------
|
|
254
|
-
|
|
258
|
+
exports.vivaPaymentMethodHandler = new core_1.PaymentMethodHandler({
|
|
255
259
|
code: 'viva',
|
|
256
260
|
description: [
|
|
257
261
|
{
|
|
258
|
-
languageCode: LanguageCode.en,
|
|
262
|
+
languageCode: core_1.LanguageCode.en,
|
|
259
263
|
value: 'Viva Wallet — Smart Checkout (ISV)',
|
|
260
264
|
},
|
|
261
265
|
],
|
|
@@ -264,9 +268,9 @@ export const vivaPaymentMethodHandler = new PaymentMethodHandler({
|
|
|
264
268
|
// init — resolve injected services from NestJS DI
|
|
265
269
|
// -------------------------------------------------------------------------
|
|
266
270
|
init(injector) {
|
|
267
|
-
_options = injector.get(VIVA_PLUGIN_OPTIONS);
|
|
268
|
-
_oauth2 = injector.get(VIVA_OAUTH2_STRATEGY_TOKEN);
|
|
269
|
-
_stateMachine = injector.get(StateMachineService);
|
|
271
|
+
_options = injector.get(constants_js_1.VIVA_PLUGIN_OPTIONS);
|
|
272
|
+
_oauth2 = injector.get(constants_js_1.VIVA_OAUTH2_STRATEGY_TOKEN);
|
|
273
|
+
_stateMachine = injector.get(state_machine_service_js_1.StateMachineService);
|
|
270
274
|
},
|
|
271
275
|
// -------------------------------------------------------------------------
|
|
272
276
|
// createPayment
|
|
@@ -281,7 +285,7 @@ export const vivaPaymentMethodHandler = new PaymentMethodHandler({
|
|
|
281
285
|
// on the stored row for ops/audit consistency.
|
|
282
286
|
const merchantId = resolveMerchantId(options, ctx);
|
|
283
287
|
if (options.mode === 'isv' && !merchantId) {
|
|
284
|
-
throw VivaPluginError.channelMisconfigured();
|
|
288
|
+
throw error_envelope_js_1.VivaPluginError.channelMisconfigured();
|
|
285
289
|
}
|
|
286
290
|
// Step 2: check vivaPayoutsEnabled gate — ISV-only.
|
|
287
291
|
// In merchant mode there's no onboarding flip; this custom field is
|
|
@@ -289,7 +293,7 @@ export const vivaPaymentMethodHandler = new PaymentMethodHandler({
|
|
|
289
293
|
if (options.mode === 'isv') {
|
|
290
294
|
const payoutsEnabled = ctx.channel.customFields['vivaPayoutsEnabled'];
|
|
291
295
|
if (payoutsEnabled === false) {
|
|
292
|
-
throw VivaPluginError.accountNotVerified();
|
|
296
|
+
throw error_envelope_js_1.VivaPluginError.accountNotVerified();
|
|
293
297
|
}
|
|
294
298
|
}
|
|
295
299
|
// Step 3: resolve sourceCode (mode-aware — channel override → fallback).
|
|
@@ -299,7 +303,7 @@ export const vivaPaymentMethodHandler = new PaymentMethodHandler({
|
|
|
299
303
|
// Step 5: isvAmount guard — only meaningful in ISV mode (merchant mode
|
|
300
304
|
// returns 0 unconditionally, so this guard never fires there).
|
|
301
305
|
if (isvAmount >= amount) {
|
|
302
|
-
throw VivaPluginError.isvAmountTooHigh(isvAmount, amount);
|
|
306
|
+
throw error_envelope_js_1.VivaPluginError.isvAmountTooHigh(isvAmount, amount);
|
|
303
307
|
}
|
|
304
308
|
// Step 6: resolve checkout color (optional, mode-aware).
|
|
305
309
|
const color = resolveCheckoutColor(options, ctx);
|
|
@@ -330,7 +334,7 @@ export const vivaPaymentMethodHandler = new PaymentMethodHandler({
|
|
|
330
334
|
if (!wasInserted && row.vivaOrderCode) {
|
|
331
335
|
const existingRedirect = row.metadata['redirectUrl'];
|
|
332
336
|
if (existingRedirect) {
|
|
333
|
-
Logger.info(`[createPayment] Idempotency hit for order ${String(order.id)} — returning cached redirect URL.`, VIVA_LOG_CONTEXT);
|
|
337
|
+
core_1.Logger.info(`[createPayment] Idempotency hit for order ${String(order.id)} — returning cached redirect URL.`, constants_js_1.VIVA_LOG_CONTEXT);
|
|
334
338
|
return {
|
|
335
339
|
amount,
|
|
336
340
|
state: 'Created',
|
|
@@ -348,7 +352,7 @@ export const vivaPaymentMethodHandler = new PaymentMethodHandler({
|
|
|
348
352
|
// The mode branch is entirely inside the `Payments` class — adapter passes
|
|
349
353
|
// `merchantId` either way; merchant-mode Payments silently drops it.
|
|
350
354
|
const isvPayments = getIsvPayments();
|
|
351
|
-
const currencyCode = alphaToNumeric(order.currencyCode);
|
|
355
|
+
const currencyCode = (0, currency_js_1.alphaToNumeric)(order.currencyCode);
|
|
352
356
|
const callStart = Date.now();
|
|
353
357
|
let orderCode;
|
|
354
358
|
try {
|
|
@@ -370,23 +374,23 @@ export const vivaPaymentMethodHandler = new PaymentMethodHandler({
|
|
|
370
374
|
}
|
|
371
375
|
catch (err) {
|
|
372
376
|
if (isRetryableVivaError(err)) {
|
|
373
|
-
throw VivaPluginError.authDown(err instanceof Error ? err.message : String(err), err);
|
|
377
|
+
throw error_envelope_js_1.VivaPluginError.authDown(err instanceof Error ? err.message : String(err), err);
|
|
374
378
|
}
|
|
375
|
-
if (err instanceof VivaApiError) {
|
|
379
|
+
if (err instanceof errors_1.VivaApiError) {
|
|
376
380
|
mapApiError(err);
|
|
377
381
|
}
|
|
378
382
|
throw err;
|
|
379
383
|
}
|
|
380
384
|
const elapsed = Date.now() - callStart;
|
|
381
385
|
if (elapsed > VIVA_LATENCY_WARN_MS) {
|
|
382
|
-
Logger.warn(`[createPayment] Viva createOrder took ${elapsed}ms (budget: ${VIVA_LATENCY_WARN_MS}ms) for order ${String(order.id)}.`, VIVA_LOG_CONTEXT);
|
|
386
|
+
core_1.Logger.warn(`[createPayment] Viva createOrder took ${elapsed}ms (budget: ${VIVA_LATENCY_WARN_MS}ms) for order ${String(order.id)}.`, constants_js_1.VIVA_LOG_CONTEXT);
|
|
383
387
|
}
|
|
384
388
|
// Step 12: construct redirect URL
|
|
385
389
|
const orderCodeStr = orderCode.toString();
|
|
386
390
|
const redirectUrl = buildCheckoutUrl(options.environment, orderCode, color);
|
|
387
391
|
// Step 13: substitute {orderCode} in success/failure URLs and store on row metadata
|
|
388
|
-
const successUrl = substitute(successUrlTemplate, { orderCode: orderCodeStr });
|
|
389
|
-
const failureUrl = substitute(failureUrlTemplate, { orderCode: orderCodeStr });
|
|
392
|
+
const successUrl = (0, url_template_js_1.substitute)(successUrlTemplate, { orderCode: orderCodeStr });
|
|
393
|
+
const failureUrl = (0, url_template_js_1.substitute)(failureUrlTemplate, { orderCode: orderCodeStr });
|
|
390
394
|
const rowMetadata = {
|
|
391
395
|
idempotencyKey,
|
|
392
396
|
redirectUrl,
|
|
@@ -446,11 +450,11 @@ export const vivaPaymentMethodHandler = new PaymentMethodHandler({
|
|
|
446
450
|
const row = await stateMachine.getVivaTransaction(ctx, ctx.channelId, payment.id);
|
|
447
451
|
// Step 2: missing row or no orderCode
|
|
448
452
|
if (!row || !row.vivaOrderCode) {
|
|
449
|
-
throw VivaPluginError.paymentNotCancellable('No Viva order code found — payment may not have been initiated.');
|
|
453
|
+
throw error_envelope_js_1.VivaPluginError.paymentNotCancellable('No Viva order code found — payment may not have been initiated.');
|
|
450
454
|
}
|
|
451
455
|
// Step 3: already terminal
|
|
452
456
|
if (TERMINAL_STATUSES.has(row.status)) {
|
|
453
|
-
throw VivaPluginError.paymentNotCancellable(`Payment is already in terminal state: ${row.status}.`);
|
|
457
|
+
throw error_envelope_js_1.VivaPluginError.paymentNotCancellable(`Payment is already in terminal state: ${row.status}.`);
|
|
454
458
|
}
|
|
455
459
|
// Step 4: resolve merchantId (ISV mode only — fallback to metadata-stored
|
|
456
460
|
// value for robustness when the channel custom field was unset after the
|
|
@@ -462,7 +466,7 @@ export const vivaPaymentMethodHandler = new PaymentMethodHandler({
|
|
|
462
466
|
(resolveMerchantId(options, ctx) ??
|
|
463
467
|
row.metadata['vivaMerchantId']);
|
|
464
468
|
if (!merchantId) {
|
|
465
|
-
throw VivaPluginError.channelMisconfigured();
|
|
469
|
+
throw error_envelope_js_1.VivaPluginError.channelMisconfigured();
|
|
466
470
|
}
|
|
467
471
|
}
|
|
468
472
|
// Step 5: call Viva cancelOrder.
|
|
@@ -475,9 +479,9 @@ export const vivaPaymentMethodHandler = new PaymentMethodHandler({
|
|
|
475
479
|
}
|
|
476
480
|
catch (err) {
|
|
477
481
|
if (isRetryableVivaError(err)) {
|
|
478
|
-
throw VivaPluginError.authDown(err instanceof Error ? err.message : String(err), err);
|
|
482
|
+
throw error_envelope_js_1.VivaPluginError.authDown(err instanceof Error ? err.message : String(err), err);
|
|
479
483
|
}
|
|
480
|
-
if (err instanceof VivaApiError) {
|
|
484
|
+
if (err instanceof errors_1.VivaApiError) {
|
|
481
485
|
mapApiError(err);
|
|
482
486
|
}
|
|
483
487
|
throw err;
|
|
@@ -499,15 +503,15 @@ export const vivaPaymentMethodHandler = new PaymentMethodHandler({
|
|
|
499
503
|
// Step 1: load transaction row
|
|
500
504
|
const row = await stateMachine.getVivaTransaction(ctx, ctx.channelId, payment.id);
|
|
501
505
|
if (!row) {
|
|
502
|
-
throw VivaPluginError.refundRejected('VivaTransaction row not found for this payment.');
|
|
506
|
+
throw error_envelope_js_1.VivaPluginError.refundRejected('VivaTransaction row not found for this payment.');
|
|
503
507
|
}
|
|
504
508
|
// Step 2: status must be captured
|
|
505
509
|
if (row.status !== 'captured') {
|
|
506
|
-
throw VivaPluginError.refundRejected(`Payment not yet captured (status: ${row.status}). Refund requires captured status.`);
|
|
510
|
+
throw error_envelope_js_1.VivaPluginError.refundRejected(`Payment not yet captured (status: ${row.status}). Refund requires captured status.`);
|
|
507
511
|
}
|
|
508
512
|
// Step 3: need vivaTransactionId (populated by webhook worker V7)
|
|
509
513
|
if (!row.vivaTransactionId) {
|
|
510
|
-
throw VivaPluginError.refundRejected('Viva transaction ID not yet known — webhook may be pending.');
|
|
514
|
+
throw error_envelope_js_1.VivaPluginError.refundRejected('Viva transaction ID not yet known — webhook may be pending.');
|
|
511
515
|
}
|
|
512
516
|
// Step 4: determine amountMinor (omit for full refund per SDK contract)
|
|
513
517
|
const isFullRefund = input.amount === payment.amount;
|
|
@@ -523,7 +527,7 @@ export const vivaPaymentMethodHandler = new PaymentMethodHandler({
|
|
|
523
527
|
const resolved = (resolveMerchantId(options, ctx) ??
|
|
524
528
|
row.metadata['vivaMerchantId']);
|
|
525
529
|
if (!resolved) {
|
|
526
|
-
throw VivaPluginError.channelMisconfigured();
|
|
530
|
+
throw error_envelope_js_1.VivaPluginError.channelMisconfigured();
|
|
527
531
|
}
|
|
528
532
|
merchantId = resolved;
|
|
529
533
|
}
|
|
@@ -537,7 +541,7 @@ export const vivaPaymentMethodHandler = new PaymentMethodHandler({
|
|
|
537
541
|
// cannot proceed.
|
|
538
542
|
// @see references/viva-docs/md/tut-create-recurring-payment.txt:288
|
|
539
543
|
if (!options.legacyMerchantId || !options.legacyApiKey) {
|
|
540
|
-
throw VivaPluginError.refundRejected('Viva refund requires legacyMerchantId and legacyApiKey in plugin options. ' +
|
|
544
|
+
throw error_envelope_js_1.VivaPluginError.refundRejected('Viva refund requires legacyMerchantId and legacyApiKey in plugin options. ' +
|
|
541
545
|
'Probe-verified 2026-04-25: POST /checkout/v2/transactions/{id} returns 405. ' +
|
|
542
546
|
'Only the legacy host with Basic auth works for Standard refund.');
|
|
543
547
|
}
|
|
@@ -607,10 +611,10 @@ async function callStandardRefund(isvPayments, vivaTransactionId, merchantId, am
|
|
|
607
611
|
}
|
|
608
612
|
catch (err) {
|
|
609
613
|
if (isRetryableVivaError(err)) {
|
|
610
|
-
throw VivaPluginError.authDown(err instanceof Error ? err.message : String(err), err);
|
|
614
|
+
throw error_envelope_js_1.VivaPluginError.authDown(err instanceof Error ? err.message : String(err), err);
|
|
611
615
|
}
|
|
612
|
-
if (err instanceof VivaApiError) {
|
|
613
|
-
throw VivaPluginError.refundRejected(err.message, err);
|
|
616
|
+
if (err instanceof errors_1.VivaApiError) {
|
|
617
|
+
throw error_envelope_js_1.VivaPluginError.refundRejected(err.message, err);
|
|
614
618
|
}
|
|
615
619
|
throw err;
|
|
616
620
|
}
|
|
@@ -644,12 +648,12 @@ async function refundMerchantMode(params) {
|
|
|
644
648
|
cardType = tx.cardType;
|
|
645
649
|
}
|
|
646
650
|
catch (err) {
|
|
647
|
-
Logger.warn(`[createRefund] retrieveTransaction failed for '${vivaTransactionId}': ` +
|
|
651
|
+
core_1.Logger.warn(`[createRefund] retrieveTransaction failed for '${vivaTransactionId}': ` +
|
|
648
652
|
`${err instanceof Error ? err.message : String(err)}. ` +
|
|
649
|
-
`Refund strategy will route via 'auto-no-card-info' (Standard).`, VIVA_LOG_CONTEXT);
|
|
653
|
+
`Refund strategy will route via 'auto-no-card-info' (Standard).`, constants_js_1.VIVA_LOG_CONTEXT);
|
|
650
654
|
}
|
|
651
655
|
// Step 2: resolve strategy.
|
|
652
|
-
const decision = resolveRefundStrategy(configuredStrategy, {
|
|
656
|
+
const decision = (0, refunds_1.resolveRefundStrategy)(configuredStrategy, {
|
|
653
657
|
...(cardType !== undefined ? { cardType } : {}),
|
|
654
658
|
isCardNotPresent: true, // Smart Checkout — always CNP
|
|
655
659
|
});
|
|
@@ -667,24 +671,24 @@ async function refundMerchantMode(params) {
|
|
|
667
671
|
return { transactionId: result.transactionId };
|
|
668
672
|
}
|
|
669
673
|
catch (err) {
|
|
670
|
-
const is403 = err instanceof VivaApiError && err.httpStatus === 403;
|
|
674
|
+
const is403 = err instanceof errors_1.VivaApiError && err.httpStatus === 403;
|
|
671
675
|
if (is403 && configuredStrategy === 'fast') {
|
|
672
676
|
// Explicit `fast` opt-in does not fall back — surface as a distinct
|
|
673
677
|
// code so callers can prompt operators to switch to 'auto' instead of
|
|
674
678
|
// treating it as a generic refund rejection.
|
|
675
|
-
throw VivaPluginError.fastRefundIneligible(undefined, err);
|
|
679
|
+
throw error_envelope_js_1.VivaPluginError.fastRefundIneligible(undefined, err);
|
|
676
680
|
}
|
|
677
681
|
if (!is403) {
|
|
678
682
|
if (isRetryableVivaError(err)) {
|
|
679
|
-
throw VivaPluginError.authDown(err instanceof Error ? err.message : String(err), err);
|
|
683
|
+
throw error_envelope_js_1.VivaPluginError.authDown(err instanceof Error ? err.message : String(err), err);
|
|
680
684
|
}
|
|
681
|
-
if (err instanceof VivaApiError) {
|
|
682
|
-
throw VivaPluginError.refundRejected(err.message, err);
|
|
685
|
+
if (err instanceof errors_1.VivaApiError) {
|
|
686
|
+
throw error_envelope_js_1.VivaPluginError.refundRejected(err.message, err);
|
|
683
687
|
}
|
|
684
688
|
throw err;
|
|
685
689
|
}
|
|
686
690
|
// is403 + auto → fall through to Standard refund.
|
|
687
|
-
Logger.info(`[createRefund] Fast Refund 403 with strategy='auto' — falling back to Standard refund for ${vivaTransactionId}.`, VIVA_LOG_CONTEXT);
|
|
691
|
+
core_1.Logger.info(`[createRefund] Fast Refund 403 with strategy='auto' — falling back to Standard refund for ${vivaTransactionId}.`, constants_js_1.VIVA_LOG_CONTEXT);
|
|
688
692
|
}
|
|
689
693
|
}
|
|
690
694
|
// Standard refund — Payments.refundPayment routes via legacy/Basic auth.
|