@sakeetech/medusa-payment-viva 0.2.2
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/LICENSE +21 -0
- package/README.md +816 -0
- package/dist/api/index.d.ts +15 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +22 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/middlewares.d.ts +27 -0
- package/dist/api/middlewares.d.ts.map +1 -0
- package/dist/api/middlewares.js +62 -0
- package/dist/api/middlewares.js.map +1 -0
- package/dist/api/viva/admin/_admin-auth.d.ts +26 -0
- package/dist/api/viva/admin/_admin-auth.d.ts.map +1 -0
- package/dist/api/viva/admin/_admin-auth.js +49 -0
- package/dist/api/viva/admin/_admin-auth.js.map +1 -0
- package/dist/api/viva/admin/_mode-gate.d.ts +28 -0
- package/dist/api/viva/admin/_mode-gate.d.ts.map +1 -0
- package/dist/api/viva/admin/_mode-gate.js +45 -0
- package/dist/api/viva/admin/_mode-gate.js.map +1 -0
- package/dist/api/viva/admin/connected-accounts/[id]/reconcile/route.d.ts +21 -0
- package/dist/api/viva/admin/connected-accounts/[id]/reconcile/route.d.ts.map +1 -0
- package/dist/api/viva/admin/connected-accounts/[id]/reconcile/route.js +93 -0
- package/dist/api/viva/admin/connected-accounts/[id]/reconcile/route.js.map +1 -0
- package/dist/api/viva/admin/connected-accounts/[id]/route.d.ts +18 -0
- package/dist/api/viva/admin/connected-accounts/[id]/route.d.ts.map +1 -0
- package/dist/api/viva/admin/connected-accounts/[id]/route.js +59 -0
- package/dist/api/viva/admin/connected-accounts/[id]/route.js.map +1 -0
- package/dist/api/viva/admin/connected-accounts/[id]/sources/route.d.ts +34 -0
- package/dist/api/viva/admin/connected-accounts/[id]/sources/route.d.ts.map +1 -0
- package/dist/api/viva/admin/connected-accounts/[id]/sources/route.js +234 -0
- package/dist/api/viva/admin/connected-accounts/[id]/sources/route.js.map +1 -0
- package/dist/api/viva/admin/connected-accounts/route.d.ts +19 -0
- package/dist/api/viva/admin/connected-accounts/route.d.ts.map +1 -0
- package/dist/api/viva/admin/connected-accounts/route.js +78 -0
- package/dist/api/viva/admin/connected-accounts/route.js.map +1 -0
- package/dist/api/viva/internal/auth-status/route.d.ts +19 -0
- package/dist/api/viva/internal/auth-status/route.d.ts.map +1 -0
- package/dist/api/viva/internal/auth-status/route.js +91 -0
- package/dist/api/viva/internal/auth-status/route.js.map +1 -0
- package/dist/api/viva/internal/metrics/route.d.ts +13 -0
- package/dist/api/viva/internal/metrics/route.d.ts.map +1 -0
- package/dist/api/viva/internal/metrics/route.js +48 -0
- package/dist/api/viva/internal/metrics/route.js.map +1 -0
- package/dist/api/viva/webhook/health/route.d.ts +16 -0
- package/dist/api/viva/webhook/health/route.d.ts.map +1 -0
- package/dist/api/viva/webhook/health/route.js +27 -0
- package/dist/api/viva/webhook/health/route.js.map +1 -0
- package/dist/api/viva/webhook/route.d.ts +57 -0
- package/dist/api/viva/webhook/route.d.ts.map +1 -0
- package/dist/api/viva/webhook/route.js +269 -0
- package/dist/api/viva/webhook/route.js.map +1 -0
- package/dist/cli/bin.d.ts +12 -0
- package/dist/cli/bin.d.ts.map +1 -0
- package/dist/cli/bin.js +78 -0
- package/dist/cli/bin.js.map +1 -0
- package/dist/cli/index.d.ts +12 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +14 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/plan.d.ts +51 -0
- package/dist/cli/plan.d.ts.map +1 -0
- package/dist/cli/plan.js +128 -0
- package/dist/cli/plan.js.map +1 -0
- package/dist/cli/register-webhooks.d.ts +54 -0
- package/dist/cli/register-webhooks.d.ts.map +1 -0
- package/dist/cli/register-webhooks.js +366 -0
- package/dist/cli/register-webhooks.js.map +1 -0
- package/dist/cli/types.d.ts +62 -0
- package/dist/cli/types.d.ts.map +1 -0
- package/dist/cli/types.js +12 -0
- package/dist/cli/types.js.map +1 -0
- package/dist/config.d.ts +158 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +236 -0
- package/dist/config.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/dist/loaders/viva-oauth2-strategy.d.ts +26 -0
- package/dist/loaders/viva-oauth2-strategy.d.ts.map +1 -0
- package/dist/loaders/viva-oauth2-strategy.js +58 -0
- package/dist/loaders/viva-oauth2-strategy.js.map +1 -0
- package/dist/migrations/Migration_20260425000001_init_viva_payments.d.ts +19 -0
- package/dist/migrations/Migration_20260425000001_init_viva_payments.d.ts.map +1 -0
- package/dist/migrations/Migration_20260425000001_init_viva_payments.js +136 -0
- package/dist/migrations/Migration_20260425000001_init_viva_payments.js.map +1 -0
- package/dist/migrations/Migration_20260425000002_allow_null_order_code.d.ts +31 -0
- package/dist/migrations/Migration_20260425000002_allow_null_order_code.d.ts.map +1 -0
- package/dist/migrations/Migration_20260425000002_allow_null_order_code.js +71 -0
- package/dist/migrations/Migration_20260425000002_allow_null_order_code.js.map +1 -0
- package/dist/migrations/Migration_20260425000003_webhook_retry_count.d.ts +18 -0
- package/dist/migrations/Migration_20260425000003_webhook_retry_count.d.ts.map +1 -0
- package/dist/migrations/Migration_20260425000003_webhook_retry_count.js +42 -0
- package/dist/migrations/Migration_20260425000003_webhook_retry_count.js.map +1 -0
- package/dist/migrations/Migration_20260425000004_webhook_error_and_nullable_merchant.d.ts +29 -0
- package/dist/migrations/Migration_20260425000004_webhook_error_and_nullable_merchant.d.ts.map +1 -0
- package/dist/migrations/Migration_20260425000004_webhook_error_and_nullable_merchant.js +74 -0
- package/dist/migrations/Migration_20260425000004_webhook_error_and_nullable_merchant.js.map +1 -0
- package/dist/models/index.d.ts +7 -0
- package/dist/models/index.d.ts.map +1 -0
- package/dist/models/index.js +10 -0
- package/dist/models/index.js.map +1 -0
- package/dist/models/viva-tenant-merchant.d.ts +11 -0
- package/dist/models/viva-tenant-merchant.d.ts.map +1 -0
- package/dist/models/viva-tenant-merchant.js +54 -0
- package/dist/models/viva-tenant-merchant.js.map +1 -0
- package/dist/models/viva-transaction.d.ts +34 -0
- package/dist/models/viva-transaction.d.ts.map +1 -0
- package/dist/models/viva-transaction.js +104 -0
- package/dist/models/viva-transaction.js.map +1 -0
- package/dist/models/viva-webhook-event.d.ts +32 -0
- package/dist/models/viva-webhook-event.d.ts.map +1 -0
- package/dist/models/viva-webhook-event.js +88 -0
- package/dist/models/viva-webhook-event.js.map +1 -0
- package/dist/observability/config.d.ts +34 -0
- package/dist/observability/config.d.ts.map +1 -0
- package/dist/observability/config.js +57 -0
- package/dist/observability/config.js.map +1 -0
- package/dist/observability/index.d.ts +8 -0
- package/dist/observability/index.d.ts.map +1 -0
- package/dist/observability/index.js +15 -0
- package/dist/observability/index.js.map +1 -0
- package/dist/observability/prom-metrics.d.ts +41 -0
- package/dist/observability/prom-metrics.d.ts.map +1 -0
- package/dist/observability/prom-metrics.js +219 -0
- package/dist/observability/prom-metrics.js.map +1 -0
- package/dist/providers/payment-provider.d.ts +19 -0
- package/dist/providers/payment-provider.d.ts.map +1 -0
- package/dist/providers/payment-provider.js +24 -0
- package/dist/providers/payment-provider.js.map +1 -0
- package/dist/resolvers/auth-strategy-factory.d.ts +42 -0
- package/dist/resolvers/auth-strategy-factory.d.ts.map +1 -0
- package/dist/resolvers/auth-strategy-factory.js +60 -0
- package/dist/resolvers/auth-strategy-factory.js.map +1 -0
- package/dist/resolvers/tenant-resolver.d.ts +104 -0
- package/dist/resolvers/tenant-resolver.d.ts.map +1 -0
- package/dist/resolvers/tenant-resolver.js +118 -0
- package/dist/resolvers/tenant-resolver.js.map +1 -0
- package/dist/service.d.ts +200 -0
- package/dist/service.d.ts.map +1 -0
- package/dist/service.js +1003 -0
- package/dist/service.js.map +1 -0
- package/dist/subscribers/index.d.ts +5 -0
- package/dist/subscribers/index.d.ts.map +1 -0
- package/dist/subscribers/index.js +10 -0
- package/dist/subscribers/index.js.map +1 -0
- package/dist/subscribers/viva-webhook-event.d.ts +38 -0
- package/dist/subscribers/viva-webhook-event.d.ts.map +1 -0
- package/dist/subscribers/viva-webhook-event.js +133 -0
- package/dist/subscribers/viva-webhook-event.js.map +1 -0
- package/dist/workflows/cleanup-old-webhook-events.d.ts +39 -0
- package/dist/workflows/cleanup-old-webhook-events.d.ts.map +1 -0
- package/dist/workflows/cleanup-old-webhook-events.js +68 -0
- package/dist/workflows/cleanup-old-webhook-events.js.map +1 -0
- package/dist/workflows/index.d.ts +14 -0
- package/dist/workflows/index.d.ts.map +1 -0
- package/dist/workflows/index.js +19 -0
- package/dist/workflows/index.js.map +1 -0
- package/dist/workflows/per-tenant-semaphore.d.ts +47 -0
- package/dist/workflows/per-tenant-semaphore.d.ts.map +1 -0
- package/dist/workflows/per-tenant-semaphore.js +89 -0
- package/dist/workflows/per-tenant-semaphore.js.map +1 -0
- package/dist/workflows/process-webhook-event.d.ts +80 -0
- package/dist/workflows/process-webhook-event.d.ts.map +1 -0
- package/dist/workflows/process-webhook-event.js +280 -0
- package/dist/workflows/process-webhook-event.js.map +1 -0
- package/dist/workflows/reprocess-unresolved-tenants.d.ts +58 -0
- package/dist/workflows/reprocess-unresolved-tenants.d.ts.map +1 -0
- package/dist/workflows/reprocess-unresolved-tenants.js +121 -0
- package/dist/workflows/reprocess-unresolved-tenants.js.map +1 -0
- package/package.json +63 -0
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* config.ts — env parsing and runtime validation for medusa-payment-viva.
|
|
3
|
+
*
|
|
4
|
+
* Reads environment variables and returns a strongly-typed `VivaPluginConfig`
|
|
5
|
+
* discriminated union, branching on `mode: 'merchant' | 'isv'`.
|
|
6
|
+
*
|
|
7
|
+
* Plan reference: docs/plans/multi-mode-v0.md §5 (config shape), §9.1 (env vars).
|
|
8
|
+
*
|
|
9
|
+
* Back-compat (one minor — 0.2.x):
|
|
10
|
+
* - `VIVA_ISV_CLIENT_ID` / `VIVA_ISV_CLIENT_SECRET` are accepted as aliases
|
|
11
|
+
* for `VIVA_CLIENT_ID` / `VIVA_CLIENT_SECRET`, with a deprecation warning.
|
|
12
|
+
* Removal in 0.3.0.
|
|
13
|
+
*
|
|
14
|
+
* Auto-detect:
|
|
15
|
+
* - If `VIVA_MODE` is unset and any `VIVA_RESELLER_*` is set, mode defaults
|
|
16
|
+
* to `'isv'`. Otherwise mode defaults to `'merchant'`.
|
|
17
|
+
*
|
|
18
|
+
* Pure function; accepts env as a parameter for testability.
|
|
19
|
+
* No Zod — manual validation per plan P13.
|
|
20
|
+
*
|
|
21
|
+
* @see references/viva-docs/md/isv-credentials.txt:107 (credential types)
|
|
22
|
+
* @see references/viva-docs/md/oauth2-authentication.txt:119 (client_id, client_secret)
|
|
23
|
+
* @see references/viva-docs/md/payment-isv-api.txt:1 (reseller credentials)
|
|
24
|
+
*/
|
|
25
|
+
import type { RedisLockClient } from '@sakeetech/viva-payments-core/auth';
|
|
26
|
+
import type { VivaEnvironment } from '@sakeetech/viva-payments-core/types';
|
|
27
|
+
export type VivaMode = 'merchant' | 'isv';
|
|
28
|
+
export type VivaRefundStrategy = 'auto' | 'fast' | 'standard';
|
|
29
|
+
/**
|
|
30
|
+
* Fields shared by both modes.
|
|
31
|
+
*
|
|
32
|
+
* Field name rationale:
|
|
33
|
+
* - `clientId` / `clientSecret` — mode-agnostic; the OAuth2 client_credentials
|
|
34
|
+
* pair works for both merchant and ISV modes.
|
|
35
|
+
* - `legacyMerchantId` / `legacyApiKey` — Basic-auth pair against the legacy
|
|
36
|
+
* host. Required in both modes for Standard refund and IsvSources (merchant
|
|
37
|
+
* variant). Probe-verified 2026-04-25: POST /checkout/v2/transactions/{id}
|
|
38
|
+
* returns 405, only the legacy host works for refunds.
|
|
39
|
+
*/
|
|
40
|
+
export interface VivaCommonConfig {
|
|
41
|
+
/**
|
|
42
|
+
* Viva API environment.
|
|
43
|
+
* @see references/viva-docs/md/oauth2-authentication.txt:145
|
|
44
|
+
*/
|
|
45
|
+
environment: VivaEnvironment;
|
|
46
|
+
/**
|
|
47
|
+
* OAuth2 client_credentials — mode-agnostic.
|
|
48
|
+
* Renamed from `isvClientId`/`isvClientSecret` in 0.2.0.
|
|
49
|
+
* @see references/viva-docs/md/oauth2-authentication.txt:119
|
|
50
|
+
*/
|
|
51
|
+
clientId: string;
|
|
52
|
+
clientSecret: string;
|
|
53
|
+
/**
|
|
54
|
+
* Legacy Basic-auth credentials. REQUIRED in both modes for Standard refund.
|
|
55
|
+
*
|
|
56
|
+
* Probe-verified 2026-04-25 (F1): POST /checkout/v2/transactions/{id} returns
|
|
57
|
+
* 405; only POST /api/transactions/{id} on the legacy host works.
|
|
58
|
+
*
|
|
59
|
+
* @see references/viva-docs/md/merchant-id-and-api-key.txt:1
|
|
60
|
+
* @see references/viva-docs/md/tut-create-recurring-payment.txt:288
|
|
61
|
+
*/
|
|
62
|
+
legacyMerchantId: string;
|
|
63
|
+
legacyApiKey: string;
|
|
64
|
+
/**
|
|
65
|
+
* Webhook verification key (GET challenge-response).
|
|
66
|
+
* @see references/viva-docs/md/isv-credentials.txt:107
|
|
67
|
+
*/
|
|
68
|
+
webhookVerificationKey: string;
|
|
69
|
+
/**
|
|
70
|
+
* Refund strategy. Defaults to `'auto'`.
|
|
71
|
+
*
|
|
72
|
+
* 'auto' — pick fast or standard based on transaction state.
|
|
73
|
+
* 'fast' — POST /api/transactions/refund (fast/OAuth2 path).
|
|
74
|
+
* 'standard' — POST /api/transactions/{id} (legacy Basic auth).
|
|
75
|
+
*/
|
|
76
|
+
refundStrategy?: VivaRefundStrategy;
|
|
77
|
+
/**
|
|
78
|
+
* Optional Redis lock client for multi-worker token-refresh coordination
|
|
79
|
+
* (plan P11).
|
|
80
|
+
*/
|
|
81
|
+
redis?: RedisLockClient;
|
|
82
|
+
/**
|
|
83
|
+
* Optional OpenTelemetry-compatible observability hook (plan P16).
|
|
84
|
+
*/
|
|
85
|
+
observability?: {
|
|
86
|
+
onSpan?: (name: string, fn: () => Promise<unknown>) => Promise<unknown>;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Whether to process Sale Transactions HMAC webhook events.
|
|
90
|
+
* v1 default: false (HMAC dropped per amendment A8). Reserved for v1.1.
|
|
91
|
+
*/
|
|
92
|
+
enableSaleTransactionsWebhook?: boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Admin token for guarding internal endpoints (/viva/internal/*).
|
|
95
|
+
* Read from VIVA_ADMIN_TOKEN. Optional — when absent, internal endpoints
|
|
96
|
+
* return 401 with reason='admin-token-not-configured'.
|
|
97
|
+
*/
|
|
98
|
+
adminToken?: string;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Merchant-mode config. Used when the plugin acts on behalf of a single
|
|
102
|
+
* direct Viva merchant account (no reseller hierarchy).
|
|
103
|
+
*/
|
|
104
|
+
export interface VivaMerchantConfig extends VivaCommonConfig {
|
|
105
|
+
mode: 'merchant';
|
|
106
|
+
/**
|
|
107
|
+
* Optional Smart Checkout sourceCode. Defaults to `'Default'` when unset.
|
|
108
|
+
*
|
|
109
|
+
* @see references/viva-docs/md/payment-source-for-isv.txt:101
|
|
110
|
+
*/
|
|
111
|
+
sourceCode?: string;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* ISV-mode config. Used when the plugin acts on behalf of merchants under
|
|
115
|
+
* an ISV partner agreement.
|
|
116
|
+
*/
|
|
117
|
+
export interface VivaIsvConfig extends VivaCommonConfig {
|
|
118
|
+
mode: 'isv';
|
|
119
|
+
/**
|
|
120
|
+
* Reseller Basic-auth — required only when the plugin will call
|
|
121
|
+
* POST /api/sources (IsvSources). All three fields are all-or-nothing.
|
|
122
|
+
*
|
|
123
|
+
* @see references/viva-docs/md/payment-isv-api.txt:1
|
|
124
|
+
*/
|
|
125
|
+
reseller?: {
|
|
126
|
+
resellerId: string;
|
|
127
|
+
merchantId: string;
|
|
128
|
+
resellerApiKey: string;
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
export type VivaPluginConfig = VivaMerchantConfig | VivaIsvConfig;
|
|
132
|
+
/** Test-only: reset the once-per-process flag. */
|
|
133
|
+
export declare function _resetConfigStartupNoticeForTesting(): void;
|
|
134
|
+
/**
|
|
135
|
+
* Parses the plugin configuration from environment variables.
|
|
136
|
+
*
|
|
137
|
+
* Required (both modes):
|
|
138
|
+
* - VIVA_CLIENT_ID (alias: VIVA_ISV_CLIENT_ID — deprecated)
|
|
139
|
+
* - VIVA_CLIENT_SECRET (alias: VIVA_ISV_CLIENT_SECRET — deprecated)
|
|
140
|
+
* - VIVA_WEBHOOK_VERIFICATION_KEY
|
|
141
|
+
* - VIVA_MERCHANT_ID (legacy Basic auth)
|
|
142
|
+
* - VIVA_API_KEY (legacy Basic auth)
|
|
143
|
+
*
|
|
144
|
+
* Optional:
|
|
145
|
+
* - VIVA_MODE ('merchant' | 'isv'; default 'merchant',
|
|
146
|
+
* auto-detected as 'isv' when VIVA_RESELLER_* set)
|
|
147
|
+
* - VIVA_ENVIRONMENT ('demo' | 'production'; default 'demo')
|
|
148
|
+
* - VIVA_REFUND_STRATEGY ('auto' | 'fast' | 'standard'; default 'auto')
|
|
149
|
+
* - VIVA_SOURCE_CODE (merchant mode only; default 'Default')
|
|
150
|
+
* - VIVA_RESELLER_ID,
|
|
151
|
+
* VIVA_RESELLER_MERCHANT_ID,
|
|
152
|
+
* VIVA_RESELLER_API_KEY (ISV mode only; all-or-nothing)
|
|
153
|
+
* - VIVA_ADMIN_TOKEN
|
|
154
|
+
*
|
|
155
|
+
* @throws VivaValidationError with field-level messages for missing values.
|
|
156
|
+
*/
|
|
157
|
+
export declare function loadConfigFromEnv(env?: NodeJS.ProcessEnv): VivaPluginConfig;
|
|
158
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;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AAM,CAAC;QACnB,UAAU,EAAE,MAAM,CAAC;QACnB,cAAc,EAAE,MAAM,CAAC;KACxB,CAAC;CACH;AAED,MAAM,MAAM,gBAAgB,GAAG,kBAAkB,GAAG,aAAa,CAAC;AASlE,kDAAkD;AAClD,wBAAgB,mCAAmC,IAAI,IAAI,CAE1D;AAMD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,iBAAiB,CAC/B,GAAG,GAAE,MAAM,CAAC,UAAwB,GACnC,gBAAgB,CAiNlB"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* config.ts — env parsing and runtime validation for medusa-payment-viva.
|
|
4
|
+
*
|
|
5
|
+
* Reads environment variables and returns a strongly-typed `VivaPluginConfig`
|
|
6
|
+
* discriminated union, branching on `mode: 'merchant' | 'isv'`.
|
|
7
|
+
*
|
|
8
|
+
* Plan reference: docs/plans/multi-mode-v0.md §5 (config shape), §9.1 (env vars).
|
|
9
|
+
*
|
|
10
|
+
* Back-compat (one minor — 0.2.x):
|
|
11
|
+
* - `VIVA_ISV_CLIENT_ID` / `VIVA_ISV_CLIENT_SECRET` are accepted as aliases
|
|
12
|
+
* for `VIVA_CLIENT_ID` / `VIVA_CLIENT_SECRET`, with a deprecation warning.
|
|
13
|
+
* Removal in 0.3.0.
|
|
14
|
+
*
|
|
15
|
+
* Auto-detect:
|
|
16
|
+
* - If `VIVA_MODE` is unset and any `VIVA_RESELLER_*` is set, mode defaults
|
|
17
|
+
* to `'isv'`. Otherwise mode defaults to `'merchant'`.
|
|
18
|
+
*
|
|
19
|
+
* Pure function; accepts env as a parameter for testability.
|
|
20
|
+
* No Zod — manual validation per plan P13.
|
|
21
|
+
*
|
|
22
|
+
* @see references/viva-docs/md/isv-credentials.txt:107 (credential types)
|
|
23
|
+
* @see references/viva-docs/md/oauth2-authentication.txt:119 (client_id, client_secret)
|
|
24
|
+
* @see references/viva-docs/md/payment-isv-api.txt:1 (reseller credentials)
|
|
25
|
+
*/
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
exports._resetConfigStartupNoticeForTesting = _resetConfigStartupNoticeForTesting;
|
|
28
|
+
exports.loadConfigFromEnv = loadConfigFromEnv;
|
|
29
|
+
const errors_1 = require("@sakeetech/viva-payments-core/errors");
|
|
30
|
+
// ---------------------------------------------------------------------------
|
|
31
|
+
// Module-local startup state — used to ensure the "defaulting to merchant
|
|
32
|
+
// mode" notice fires at most once per process.
|
|
33
|
+
// ---------------------------------------------------------------------------
|
|
34
|
+
let _defaultModeNoticeShown = false;
|
|
35
|
+
/** Test-only: reset the once-per-process flag. */
|
|
36
|
+
function _resetConfigStartupNoticeForTesting() {
|
|
37
|
+
_defaultModeNoticeShown = false;
|
|
38
|
+
}
|
|
39
|
+
// ---------------------------------------------------------------------------
|
|
40
|
+
// Loader
|
|
41
|
+
// ---------------------------------------------------------------------------
|
|
42
|
+
/**
|
|
43
|
+
* Parses the plugin configuration from environment variables.
|
|
44
|
+
*
|
|
45
|
+
* Required (both modes):
|
|
46
|
+
* - VIVA_CLIENT_ID (alias: VIVA_ISV_CLIENT_ID — deprecated)
|
|
47
|
+
* - VIVA_CLIENT_SECRET (alias: VIVA_ISV_CLIENT_SECRET — deprecated)
|
|
48
|
+
* - VIVA_WEBHOOK_VERIFICATION_KEY
|
|
49
|
+
* - VIVA_MERCHANT_ID (legacy Basic auth)
|
|
50
|
+
* - VIVA_API_KEY (legacy Basic auth)
|
|
51
|
+
*
|
|
52
|
+
* Optional:
|
|
53
|
+
* - VIVA_MODE ('merchant' | 'isv'; default 'merchant',
|
|
54
|
+
* auto-detected as 'isv' when VIVA_RESELLER_* set)
|
|
55
|
+
* - VIVA_ENVIRONMENT ('demo' | 'production'; default 'demo')
|
|
56
|
+
* - VIVA_REFUND_STRATEGY ('auto' | 'fast' | 'standard'; default 'auto')
|
|
57
|
+
* - VIVA_SOURCE_CODE (merchant mode only; default 'Default')
|
|
58
|
+
* - VIVA_RESELLER_ID,
|
|
59
|
+
* VIVA_RESELLER_MERCHANT_ID,
|
|
60
|
+
* VIVA_RESELLER_API_KEY (ISV mode only; all-or-nothing)
|
|
61
|
+
* - VIVA_ADMIN_TOKEN
|
|
62
|
+
*
|
|
63
|
+
* @throws VivaValidationError with field-level messages for missing values.
|
|
64
|
+
*/
|
|
65
|
+
function loadConfigFromEnv(env = process.env) {
|
|
66
|
+
const errors = [];
|
|
67
|
+
// -------------------------------------------------------------------------
|
|
68
|
+
// VIVA_MODE — discriminator, with auto-detect + default-warning.
|
|
69
|
+
// -------------------------------------------------------------------------
|
|
70
|
+
const rawMode = env['VIVA_MODE'];
|
|
71
|
+
const resellerIdRaw = env['VIVA_RESELLER_ID'];
|
|
72
|
+
const resellerMerchantIdRaw = env['VIVA_RESELLER_MERCHANT_ID'];
|
|
73
|
+
const resellerApiKeyRaw = env['VIVA_RESELLER_API_KEY'];
|
|
74
|
+
const anyResellerSet = Boolean(resellerIdRaw || resellerMerchantIdRaw || resellerApiKeyRaw);
|
|
75
|
+
let mode;
|
|
76
|
+
if (rawMode === undefined || rawMode === '') {
|
|
77
|
+
mode = anyResellerSet ? 'isv' : 'merchant';
|
|
78
|
+
if (!_defaultModeNoticeShown) {
|
|
79
|
+
_defaultModeNoticeShown = true;
|
|
80
|
+
console.warn(`[viva] VIVA_MODE is unset — defaulting to '${mode}' mode` +
|
|
81
|
+
(anyResellerSet
|
|
82
|
+
? ' (auto-detected from VIVA_RESELLER_*).'
|
|
83
|
+
: '. Set VIVA_MODE=isv if running under an ISV partner.'));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
else if (rawMode === 'merchant' || rawMode === 'isv') {
|
|
87
|
+
mode = rawMode;
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
errors.push(`VIVA_MODE must be 'merchant' or 'isv', got '${rawMode}'`);
|
|
91
|
+
mode = 'merchant'; // placeholder; we'll throw before using it
|
|
92
|
+
}
|
|
93
|
+
// -------------------------------------------------------------------------
|
|
94
|
+
// VIVA_ENVIRONMENT
|
|
95
|
+
// -------------------------------------------------------------------------
|
|
96
|
+
const rawEnv = env['VIVA_ENVIRONMENT'] ?? 'demo';
|
|
97
|
+
if (rawEnv !== 'demo' && rawEnv !== 'production') {
|
|
98
|
+
errors.push(`VIVA_ENVIRONMENT must be 'demo' or 'production', got '${rawEnv}'`);
|
|
99
|
+
}
|
|
100
|
+
const environment = rawEnv;
|
|
101
|
+
// -------------------------------------------------------------------------
|
|
102
|
+
// OAuth2 client_credentials (with one-minor back-compat aliases).
|
|
103
|
+
// -------------------------------------------------------------------------
|
|
104
|
+
let clientId = env['VIVA_CLIENT_ID'];
|
|
105
|
+
if (!clientId && env['VIVA_ISV_CLIENT_ID']) {
|
|
106
|
+
clientId = env['VIVA_ISV_CLIENT_ID'];
|
|
107
|
+
console.warn('[viva] VIVA_ISV_CLIENT_ID is deprecated, rename to VIVA_CLIENT_ID. ' +
|
|
108
|
+
'Removal in 0.3.0.');
|
|
109
|
+
}
|
|
110
|
+
if (!clientId) {
|
|
111
|
+
errors.push('VIVA_CLIENT_ID is required');
|
|
112
|
+
}
|
|
113
|
+
let clientSecret = env['VIVA_CLIENT_SECRET'];
|
|
114
|
+
if (!clientSecret && env['VIVA_ISV_CLIENT_SECRET']) {
|
|
115
|
+
clientSecret = env['VIVA_ISV_CLIENT_SECRET'];
|
|
116
|
+
console.warn('[viva] VIVA_ISV_CLIENT_SECRET is deprecated, rename to VIVA_CLIENT_SECRET. ' +
|
|
117
|
+
'Removal in 0.3.0.');
|
|
118
|
+
}
|
|
119
|
+
if (!clientSecret) {
|
|
120
|
+
errors.push('VIVA_CLIENT_SECRET is required');
|
|
121
|
+
}
|
|
122
|
+
const webhookVerificationKey = env['VIVA_WEBHOOK_VERIFICATION_KEY'];
|
|
123
|
+
if (!webhookVerificationKey) {
|
|
124
|
+
errors.push('VIVA_WEBHOOK_VERIFICATION_KEY is required');
|
|
125
|
+
}
|
|
126
|
+
// -------------------------------------------------------------------------
|
|
127
|
+
// Legacy Basic-auth credentials — required in both modes for Standard refund.
|
|
128
|
+
// -------------------------------------------------------------------------
|
|
129
|
+
const legacyMerchantId = env['VIVA_MERCHANT_ID'];
|
|
130
|
+
if (!legacyMerchantId) {
|
|
131
|
+
errors.push('VIVA_MERCHANT_ID is required — needed for refundPayment (Viva legacy Basic-auth API). ' +
|
|
132
|
+
'Probe-verified 2026-04-25: POST /checkout/v2/transactions/{id} returns 405; ' +
|
|
133
|
+
'only POST /api/transactions/{id} on the legacy host works.');
|
|
134
|
+
}
|
|
135
|
+
const legacyApiKey = env['VIVA_API_KEY'];
|
|
136
|
+
if (!legacyApiKey) {
|
|
137
|
+
errors.push('VIVA_API_KEY is required — needed for refundPayment (Viva legacy Basic-auth API). ' +
|
|
138
|
+
'Pair with VIVA_MERCHANT_ID to authenticate refund calls.');
|
|
139
|
+
}
|
|
140
|
+
// -------------------------------------------------------------------------
|
|
141
|
+
// VIVA_REFUND_STRATEGY (default 'auto').
|
|
142
|
+
// -------------------------------------------------------------------------
|
|
143
|
+
const rawRefundStrategy = env['VIVA_REFUND_STRATEGY'];
|
|
144
|
+
let refundStrategy = 'auto';
|
|
145
|
+
if (rawRefundStrategy !== undefined && rawRefundStrategy !== '') {
|
|
146
|
+
if (rawRefundStrategy === 'auto' ||
|
|
147
|
+
rawRefundStrategy === 'fast' ||
|
|
148
|
+
rawRefundStrategy === 'standard') {
|
|
149
|
+
refundStrategy = rawRefundStrategy;
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
errors.push(`VIVA_REFUND_STRATEGY must be 'auto', 'fast', or 'standard', got '${rawRefundStrategy}'`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
// -------------------------------------------------------------------------
|
|
156
|
+
// Reseller credentials (ISV-only, all-or-nothing).
|
|
157
|
+
// -------------------------------------------------------------------------
|
|
158
|
+
const resellerSetCount = [
|
|
159
|
+
resellerIdRaw,
|
|
160
|
+
resellerMerchantIdRaw,
|
|
161
|
+
resellerApiKeyRaw,
|
|
162
|
+
].filter(Boolean).length;
|
|
163
|
+
if (mode === 'merchant' && resellerSetCount > 0) {
|
|
164
|
+
// Don't throw — warn and ignore. Reseller fields are unused in merchant mode.
|
|
165
|
+
console.warn('[viva] VIVA_RESELLER_* env vars are set but VIVA_MODE=merchant. ' +
|
|
166
|
+
'These values are ignored in merchant mode.');
|
|
167
|
+
}
|
|
168
|
+
if (mode === 'isv' && resellerSetCount > 0 && resellerSetCount < 3) {
|
|
169
|
+
const missing = [];
|
|
170
|
+
if (!resellerIdRaw)
|
|
171
|
+
missing.push('VIVA_RESELLER_ID');
|
|
172
|
+
if (!resellerMerchantIdRaw)
|
|
173
|
+
missing.push('VIVA_RESELLER_MERCHANT_ID');
|
|
174
|
+
if (!resellerApiKeyRaw)
|
|
175
|
+
missing.push('VIVA_RESELLER_API_KEY');
|
|
176
|
+
errors.push(`Reseller credentials are partially set. Missing: ${missing.join(', ')}. ` +
|
|
177
|
+
`Either set all three (VIVA_RESELLER_ID, VIVA_RESELLER_MERCHANT_ID, VIVA_RESELLER_API_KEY) or none.`);
|
|
178
|
+
}
|
|
179
|
+
// -------------------------------------------------------------------------
|
|
180
|
+
// Throw aggregated validation errors before constructing the config object.
|
|
181
|
+
// -------------------------------------------------------------------------
|
|
182
|
+
if (errors.length > 0) {
|
|
183
|
+
throw new errors_1.VivaValidationError({
|
|
184
|
+
message: `Invalid Viva plugin configuration:\n ${errors.join('\n ')}`,
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
// -------------------------------------------------------------------------
|
|
188
|
+
// VIVA_ADMIN_TOKEN — warn in production if missing.
|
|
189
|
+
// -------------------------------------------------------------------------
|
|
190
|
+
const adminToken = env['VIVA_ADMIN_TOKEN'];
|
|
191
|
+
if (!adminToken && environment === 'production') {
|
|
192
|
+
console.warn('[viva] VIVA_ADMIN_TOKEN is not set. Internal endpoints (/viva/internal/*) will return 401.');
|
|
193
|
+
}
|
|
194
|
+
// -------------------------------------------------------------------------
|
|
195
|
+
// Compose common fields.
|
|
196
|
+
// -------------------------------------------------------------------------
|
|
197
|
+
const common = {
|
|
198
|
+
environment,
|
|
199
|
+
clientId: clientId,
|
|
200
|
+
clientSecret: clientSecret,
|
|
201
|
+
legacyMerchantId: legacyMerchantId,
|
|
202
|
+
legacyApiKey: legacyApiKey,
|
|
203
|
+
webhookVerificationKey: webhookVerificationKey,
|
|
204
|
+
refundStrategy,
|
|
205
|
+
...(adminToken !== undefined ? { adminToken } : {}),
|
|
206
|
+
};
|
|
207
|
+
// -------------------------------------------------------------------------
|
|
208
|
+
// Branch on mode.
|
|
209
|
+
// -------------------------------------------------------------------------
|
|
210
|
+
if (mode === 'merchant') {
|
|
211
|
+
const sourceCode = env['VIVA_SOURCE_CODE'];
|
|
212
|
+
const merchantConfig = {
|
|
213
|
+
...common,
|
|
214
|
+
mode: 'merchant',
|
|
215
|
+
...(sourceCode !== undefined && sourceCode !== ''
|
|
216
|
+
? { sourceCode }
|
|
217
|
+
: {}),
|
|
218
|
+
};
|
|
219
|
+
return merchantConfig;
|
|
220
|
+
}
|
|
221
|
+
// mode === 'isv'
|
|
222
|
+
const reseller = resellerSetCount === 3
|
|
223
|
+
? {
|
|
224
|
+
resellerId: resellerIdRaw,
|
|
225
|
+
merchantId: resellerMerchantIdRaw,
|
|
226
|
+
resellerApiKey: resellerApiKeyRaw,
|
|
227
|
+
}
|
|
228
|
+
: undefined;
|
|
229
|
+
const isvConfig = {
|
|
230
|
+
...common,
|
|
231
|
+
mode: 'isv',
|
|
232
|
+
...(reseller !== undefined ? { reseller } : {}),
|
|
233
|
+
};
|
|
234
|
+
return isvConfig;
|
|
235
|
+
}
|
|
236
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;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C3B,sBAAsB,EAAE,sBAAuB;QAC/C,cAAc;QACd,GAAG,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACpD,CAAC;IAEF,4EAA4E;IAC5E,kBAAkB;IAClB,4EAA4E;IAC5E,IAAI,IAAI,KAAK,UAAU,EAAE,CAAC;QACxB,MAAM,UAAU,GAAG,GAAG,CAAC,kBAAkB,CAAC,CAAC;QAC3C,MAAM,cAAc,GAAuB;YACzC,GAAG,MAAM;YACT,IAAI,EAAE,UAAU;YAChB,GAAG,CAAC,UAAU,KAAK,SAAS,IAAI,UAAU,KAAK,EAAE;gBAC/C,CAAC,CAAC,EAAE,UAAU,EAAE;gBAChB,CAAC,CAAC,EAAE,CAAC;SACR,CAAC;QACF,OAAO,cAAc,CAAC;IACxB,CAAC;IAED,iBAAiB;IACjB,MAAM,QAAQ,GACZ,gBAAgB,KAAK,CAAC;QACpB,CAAC,CAAC;YACE,UAAU,EAAE,aAAc;YAC1B,UAAU,EAAE,qBAAsB;YAClC,cAAc,EAAE,iBAAkB;SACnC;QACH,CAAC,CAAC,SAAS,CAAC;IAEhB,MAAM,SAAS,GAAkB;QAC/B,GAAG,MAAM;QACT,IAAI,EAAE,KAAK;QACX,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAChD,CAAC;IACF,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* medusa-payment-viva
|
|
3
|
+
*
|
|
4
|
+
* Medusa v2 payment provider module for Viva Wallet under the ISV partner
|
|
5
|
+
* program. Wraps `viva-payments-core` and adapts it to Medusa's
|
|
6
|
+
* AbstractPaymentProvider interface.
|
|
7
|
+
*
|
|
8
|
+
* @see references/viva-docs/md/payment-isv-api.txt:1 (ISV API)
|
|
9
|
+
* @see references/viva-docs/md/isv-partner-program.txt:61 (ISV overview)
|
|
10
|
+
*/
|
|
11
|
+
export { VivaPaymentProvider } from './service.js';
|
|
12
|
+
export type { VivaPaymentProviderOptions } from './service.js';
|
|
13
|
+
export { loadConfigFromEnv } from './config.js';
|
|
14
|
+
export type { VivaPluginConfig } from './config.js';
|
|
15
|
+
export { DefaultTenantResolver, assertSingleTenantCart } from './resolvers/tenant-resolver.js';
|
|
16
|
+
export type { TenantResolver, CartLike } from './resolvers/tenant-resolver.js';
|
|
17
|
+
export { buildAuthStrategies } from './resolvers/auth-strategy-factory.js';
|
|
18
|
+
export type { AuthStrategySet } from './resolvers/auth-strategy-factory.js';
|
|
19
|
+
export { default as providerExport } from './providers/payment-provider.js';
|
|
20
|
+
export declare const VERSION = "0.0.0";
|
|
21
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,YAAY,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAE/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AAC/F,YAAY,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAC;AAE/E,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAC3E,YAAY,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AAE5E,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAE5E,eAAO,MAAM,OAAO,UAAU,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* medusa-payment-viva
|
|
4
|
+
*
|
|
5
|
+
* Medusa v2 payment provider module for Viva Wallet under the ISV partner
|
|
6
|
+
* program. Wraps `viva-payments-core` and adapts it to Medusa's
|
|
7
|
+
* AbstractPaymentProvider interface.
|
|
8
|
+
*
|
|
9
|
+
* @see references/viva-docs/md/payment-isv-api.txt:1 (ISV API)
|
|
10
|
+
* @see references/viva-docs/md/isv-partner-program.txt:61 (ISV overview)
|
|
11
|
+
*/
|
|
12
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
13
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
|
+
};
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.VERSION = exports.providerExport = exports.buildAuthStrategies = exports.assertSingleTenantCart = exports.DefaultTenantResolver = exports.loadConfigFromEnv = exports.VivaPaymentProvider = void 0;
|
|
17
|
+
var service_js_1 = require("./service.js");
|
|
18
|
+
Object.defineProperty(exports, "VivaPaymentProvider", { enumerable: true, get: function () { return service_js_1.VivaPaymentProvider; } });
|
|
19
|
+
var config_js_1 = require("./config.js");
|
|
20
|
+
Object.defineProperty(exports, "loadConfigFromEnv", { enumerable: true, get: function () { return config_js_1.loadConfigFromEnv; } });
|
|
21
|
+
var tenant_resolver_js_1 = require("./resolvers/tenant-resolver.js");
|
|
22
|
+
Object.defineProperty(exports, "DefaultTenantResolver", { enumerable: true, get: function () { return tenant_resolver_js_1.DefaultTenantResolver; } });
|
|
23
|
+
Object.defineProperty(exports, "assertSingleTenantCart", { enumerable: true, get: function () { return tenant_resolver_js_1.assertSingleTenantCart; } });
|
|
24
|
+
var auth_strategy_factory_js_1 = require("./resolvers/auth-strategy-factory.js");
|
|
25
|
+
Object.defineProperty(exports, "buildAuthStrategies", { enumerable: true, get: function () { return auth_strategy_factory_js_1.buildAuthStrategies; } });
|
|
26
|
+
var payment_provider_js_1 = require("./providers/payment-provider.js");
|
|
27
|
+
Object.defineProperty(exports, "providerExport", { enumerable: true, get: function () { return __importDefault(payment_provider_js_1).default; } });
|
|
28
|
+
exports.VERSION = '0.0.0';
|
|
29
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;;;;AAEH,2CAAmD;AAA1C,iHAAA,mBAAmB,OAAA;AAG5B,yCAAgD;AAAvC,8GAAA,iBAAiB,OAAA;AAG1B,qEAA+F;AAAtF,2HAAA,qBAAqB,OAAA;AAAE,4HAAA,sBAAsB,OAAA;AAGtD,iFAA2E;AAAlE,+HAAA,mBAAmB,OAAA;AAG5B,uEAA4E;AAAnE,sIAAA,OAAO,OAAkB;AAErB,QAAA,OAAO,GAAG,OAAO,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* loaders/viva-oauth2-strategy.ts — registers the OAuth2 strategy singleton.
|
|
3
|
+
*
|
|
4
|
+
* Medusa v2 plugin loaders receive the global container and can register
|
|
5
|
+
* additional dependencies. This loader builds the primary
|
|
6
|
+
* OAuth2ClientCredentialsStrategy once from env config and registers it under
|
|
7
|
+
* the key `vivaOAuth2Strategy` so that route handlers (e.g. auth-status) can
|
|
8
|
+
* resolve the same stateful instance that the payment provider uses.
|
|
9
|
+
*
|
|
10
|
+
* Registration key: `vivaOAuth2Strategy`
|
|
11
|
+
*
|
|
12
|
+
* @see references/viva-docs/md/isv-partner-program.txt:61 (P16 health endpoints)
|
|
13
|
+
*/
|
|
14
|
+
import type { MedusaContainer } from '@medusajs/framework/types';
|
|
15
|
+
export declare const VIVA_OAUTH2_STRATEGY_KEY = "vivaOAuth2Strategy";
|
|
16
|
+
/**
|
|
17
|
+
* Medusa v2 plugin loader.
|
|
18
|
+
* Called once at startup with the global container.
|
|
19
|
+
* Registers the OAuth2 strategy singleton under `vivaOAuth2Strategy`.
|
|
20
|
+
*
|
|
21
|
+
* If config env vars are missing (e.g. in test environments that don't set
|
|
22
|
+
* them), the registration is skipped silently — route handlers must handle
|
|
23
|
+
* the absent-key case.
|
|
24
|
+
*/
|
|
25
|
+
export default function vivaOAuth2StrategyLoader(container: MedusaContainer): void;
|
|
26
|
+
//# sourceMappingURL=viva-oauth2-strategy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"viva-oauth2-strategy.d.ts","sourceRoot":"","sources":["../../src/loaders/viva-oauth2-strategy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAIjE,eAAO,MAAM,wBAAwB,uBAAuB,CAAC;AAE7D;;;;;;;;GAQG;AACH,MAAM,CAAC,OAAO,UAAU,wBAAwB,CAC9C,SAAS,EAAE,eAAe,GACzB,IAAI,CA4BN"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* loaders/viva-oauth2-strategy.ts — registers the OAuth2 strategy singleton.
|
|
4
|
+
*
|
|
5
|
+
* Medusa v2 plugin loaders receive the global container and can register
|
|
6
|
+
* additional dependencies. This loader builds the primary
|
|
7
|
+
* OAuth2ClientCredentialsStrategy once from env config and registers it under
|
|
8
|
+
* the key `vivaOAuth2Strategy` so that route handlers (e.g. auth-status) can
|
|
9
|
+
* resolve the same stateful instance that the payment provider uses.
|
|
10
|
+
*
|
|
11
|
+
* Registration key: `vivaOAuth2Strategy`
|
|
12
|
+
*
|
|
13
|
+
* @see references/viva-docs/md/isv-partner-program.txt:61 (P16 health endpoints)
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.VIVA_OAUTH2_STRATEGY_KEY = void 0;
|
|
17
|
+
exports.default = vivaOAuth2StrategyLoader;
|
|
18
|
+
const auth_1 = require("@sakeetech/viva-payments-core/auth");
|
|
19
|
+
const config_js_1 = require("../config.js");
|
|
20
|
+
exports.VIVA_OAUTH2_STRATEGY_KEY = 'vivaOAuth2Strategy';
|
|
21
|
+
/**
|
|
22
|
+
* Medusa v2 plugin loader.
|
|
23
|
+
* Called once at startup with the global container.
|
|
24
|
+
* Registers the OAuth2 strategy singleton under `vivaOAuth2Strategy`.
|
|
25
|
+
*
|
|
26
|
+
* If config env vars are missing (e.g. in test environments that don't set
|
|
27
|
+
* them), the registration is skipped silently — route handlers must handle
|
|
28
|
+
* the absent-key case.
|
|
29
|
+
*/
|
|
30
|
+
function vivaOAuth2StrategyLoader(container) {
|
|
31
|
+
try {
|
|
32
|
+
const config = (0, config_js_1.loadConfigFromEnv)(process.env);
|
|
33
|
+
const cache = new auth_1.InMemoryTokenCache();
|
|
34
|
+
const mutex = new auth_1.AsyncMutex();
|
|
35
|
+
const strategy = new auth_1.OAuth2ClientCredentialsStrategy({
|
|
36
|
+
environment: config.environment,
|
|
37
|
+
clientId: config.clientId,
|
|
38
|
+
clientSecret: config.clientSecret,
|
|
39
|
+
cache,
|
|
40
|
+
mutex,
|
|
41
|
+
...(config.redis !== undefined ? { redisLock: config.redis } : {}),
|
|
42
|
+
});
|
|
43
|
+
// Register the singleton using the Awilix NameAndRegistrationPair form.
|
|
44
|
+
// `asValue` shape: { resolve: () => T, lifetime: 'SINGLETON' }.
|
|
45
|
+
// Cast through unknown to satisfy the strict MedusaContainer overload.
|
|
46
|
+
container.register({
|
|
47
|
+
[exports.VIVA_OAUTH2_STRATEGY_KEY]: {
|
|
48
|
+
resolve: () => strategy,
|
|
49
|
+
lifetime: 'SINGLETON',
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
// Config not available (e.g. in test or CI without env vars).
|
|
55
|
+
// The route falls back gracefully.
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=viva-oauth2-strategy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"viva-oauth2-strategy.js","sourceRoot":"","sources":["../../src/loaders/viva-oauth2-strategy.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;AAiBH,2CA8BC;AA5CD,6DAAqH;AACrH,4CAAiD;AAEpC,QAAA,wBAAwB,GAAG,oBAAoB,CAAC;AAE7D;;;;;;;;GAQG;AACH,SAAwB,wBAAwB,CAC9C,SAA0B;IAE1B,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAA,6BAAiB,EAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAC9C,MAAM,KAAK,GAAG,IAAI,yBAAkB,EAAE,CAAC;QACvC,MAAM,KAAK,GAAG,IAAI,iBAAU,EAAE,CAAC;QAE/B,MAAM,QAAQ,GAAG,IAAI,sCAA+B,CAAC;YACnD,WAAW,EAAE,MAAM,CAAC,WAAW;YAC/B,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,YAAY,EAAE,MAAM,CAAC,YAAY;YACjC,KAAK;YACL,KAAK;YACL,GAAG,CAAC,MAAM,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACnE,CAAC,CAAC;QAEH,wEAAwE;QACxE,gEAAgE;QAChE,uEAAuE;QACtE,SAAS,CAAC,QAAoD,CAAC;YAC9D,CAAC,gCAAwB,CAAC,EAAE;gBAC1B,OAAO,EAAE,GAAG,EAAE,CAAC,QAAQ;gBACvB,QAAQ,EAAE,WAAW;aACtB;SACF,CAAC,CAAC;IACL,CAAC;IAAC,MAAM,CAAC;QACP,8DAA8D;QAC9D,mCAAmC;IACrC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Migration } from "@medusajs/framework/mikro-orm/migrations";
|
|
2
|
+
/**
|
|
3
|
+
* S7 — initial migration: creates all three plugin-owned tables atomically.
|
|
4
|
+
*
|
|
5
|
+
* up() — CREATE TABLE IF NOT EXISTS + indexes (idempotent).
|
|
6
|
+
* down() — Attempts COPY of viva_webhook_event raw_payload to /tmp before drop
|
|
7
|
+
* for forensic preservation per plan line 205.
|
|
8
|
+
* NOTE: COPY TO file requires the postgres superuser role. If the
|
|
9
|
+
* migration runner connects as a non-superuser, this COPY will fail.
|
|
10
|
+
* In that case, wrap the COPY in a DO block that catches the error and
|
|
11
|
+
* logs a notice — data preservation is best-effort in non-superuser
|
|
12
|
+
* deployments. Operators should take a pg_dump backup before running
|
|
13
|
+
* down() in production.
|
|
14
|
+
*/
|
|
15
|
+
export declare class Migration_20260425000001_init_viva_payments extends Migration {
|
|
16
|
+
up(): Promise<void>;
|
|
17
|
+
down(): Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=Migration_20260425000001_init_viva_payments.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Migration_20260425000001_init_viva_payments.d.ts","sourceRoot":"","sources":["../../src/migrations/Migration_20260425000001_init_viva_payments.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,0CAA0C,CAAC;AAErE;;;;;;;;;;;;GAYG;AACH,qBAAa,2CAA4C,SAAQ,SAAS;IACzD,EAAE,IAAI,OAAO,CAAC,IAAI,CAAC;IA6GnB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAsBrC"}
|