@easypayment/medusa-payment-paypal 1.3.3 → 1.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.medusa/server/src/admin/index.js +250 -166
- package/.medusa/server/src/admin/index.mjs +250 -166
- package/.medusa/server/src/api/admin/paypal/logs/route.d.ts +10 -0
- package/.medusa/server/src/api/admin/paypal/logs/route.d.ts.map +1 -0
- package/.medusa/server/src/api/admin/paypal/logs/route.js +43 -0
- package/.medusa/server/src/api/admin/paypal/logs/route.js.map +1 -0
- package/.medusa/server/src/api/middlewares.d.ts.map +1 -1
- package/.medusa/server/src/api/middlewares.js +22 -4
- package/.medusa/server/src/api/middlewares.js.map +1 -1
- package/.medusa/server/src/api/utils/request-logger.d.ts +11 -0
- package/.medusa/server/src/api/utils/request-logger.d.ts.map +1 -0
- package/.medusa/server/src/api/utils/request-logger.js +69 -0
- package/.medusa/server/src/api/utils/request-logger.js.map +1 -0
- package/.medusa/server/src/modules/paypal/payment-provider/base-provider.d.ts +3 -3
- package/.medusa/server/src/modules/paypal/service.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/service.js +19 -3
- package/.medusa/server/src/modules/paypal/service.js.map +1 -1
- package/.medusa/server/src/modules/paypal/types/config.js +1 -1
- package/.medusa/server/src/modules/paypal/types/config.js.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/credential-resolver.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/credential-resolver.js +10 -0
- package/.medusa/server/src/modules/paypal/utils/credential-resolver.js.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/paypal-fetch.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/paypal-fetch.js +39 -0
- package/.medusa/server/src/modules/paypal/utils/paypal-fetch.js.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/request-logger.d.ts +62 -0
- package/.medusa/server/src/modules/paypal/utils/request-logger.d.ts.map +1 -0
- package/.medusa/server/src/modules/paypal/utils/request-logger.js +297 -0
- package/.medusa/server/src/modules/paypal/utils/request-logger.js.map +1 -0
- package/CHANGELOG.md +27 -0
- package/README.md +4 -0
- package/package.json +1 -1
- package/src/admin/routes/settings/paypal/additional-settings/page.tsx +87 -0
- package/src/api/admin/paypal/logs/route.ts +50 -0
- package/src/api/middlewares.ts +22 -4
- package/src/api/utils/request-logger.ts +84 -0
- package/src/modules/paypal/service.ts +21 -3
- package/src/modules/paypal/types/config.ts +1 -1
- package/src/modules/paypal/utils/credential-resolver.ts +9 -0
- package/src/modules/paypal/utils/paypal-fetch.ts +42 -0
- package/src/modules/paypal/utils/request-logger.ts +358 -0
|
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
7
7
|
exports.CircuitOpenError = exports.PAYPAL_HTTP_TIMEOUT_MS = void 0;
|
|
8
8
|
exports.paypalFetch = paypalFetch;
|
|
9
9
|
exports.paypalFetchWithRetry = paypalFetchWithRetry;
|
|
10
|
+
const request_logger_1 = require("./request-logger");
|
|
10
11
|
exports.PAYPAL_HTTP_TIMEOUT_MS = (() => {
|
|
11
12
|
const v = Number(process.env.PAYPAL_HTTP_TIMEOUT_MS);
|
|
12
13
|
return Number.isFinite(v) && v > 0 ? v : 30_000;
|
|
@@ -96,6 +97,8 @@ function paypalFetch(input, init = {}) {
|
|
|
96
97
|
if (!cbAllowRequest(host)) {
|
|
97
98
|
return Promise.reject(new CircuitOpenError());
|
|
98
99
|
}
|
|
100
|
+
const logging = (0, request_logger_1.isRequestLoggingEnabled)();
|
|
101
|
+
const startedAt = logging ? Date.now() : 0;
|
|
99
102
|
const fetchPromise = init.signal
|
|
100
103
|
? fetch(input, init)
|
|
101
104
|
: fetch(input, {
|
|
@@ -109,9 +112,45 @@ function paypalFetch(input, init = {}) {
|
|
|
109
112
|
else {
|
|
110
113
|
cbRecordSuccess(host);
|
|
111
114
|
}
|
|
115
|
+
if (logging) {
|
|
116
|
+
// Read the body off a CLONE so the caller's stream is untouched, and
|
|
117
|
+
// fire-and-forget so logging never delays the response.
|
|
118
|
+
res
|
|
119
|
+
.clone()
|
|
120
|
+
.text()
|
|
121
|
+
.then((responseBody) => (0, request_logger_1.logOutbound)({
|
|
122
|
+
method: String(init.method || "GET").toUpperCase(),
|
|
123
|
+
url: String(input),
|
|
124
|
+
requestHeaders: init.headers,
|
|
125
|
+
requestBody: init.body,
|
|
126
|
+
status: res.status,
|
|
127
|
+
statusText: res.statusText,
|
|
128
|
+
responseHeaders: res.headers,
|
|
129
|
+
responseBody,
|
|
130
|
+
durationMs: Date.now() - startedAt,
|
|
131
|
+
}))
|
|
132
|
+
.catch(() => {
|
|
133
|
+
// best-effort: logging must never affect the payment flow
|
|
134
|
+
});
|
|
135
|
+
}
|
|
112
136
|
return res;
|
|
113
137
|
}, (err) => {
|
|
114
138
|
cbRecordFailure(host);
|
|
139
|
+
if (logging) {
|
|
140
|
+
try {
|
|
141
|
+
(0, request_logger_1.logOutbound)({
|
|
142
|
+
method: String(init.method || "GET").toUpperCase(),
|
|
143
|
+
url: String(input),
|
|
144
|
+
requestHeaders: init.headers,
|
|
145
|
+
requestBody: init.body,
|
|
146
|
+
durationMs: Date.now() - startedAt,
|
|
147
|
+
error: err,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
// best-effort only
|
|
152
|
+
}
|
|
153
|
+
}
|
|
115
154
|
throw err;
|
|
116
155
|
});
|
|
117
156
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paypal-fetch.js","sourceRoot":"","sources":["../../../../../../src/modules/paypal/utils/paypal-fetch.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;
|
|
1
|
+
{"version":3,"file":"paypal-fetch.js","sourceRoot":"","sources":["../../../../../../src/modules/paypal/utils/paypal-fetch.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAgHH,kCAsEC;AAgDD,oDA6BC;AAjQD,qDAAuE;AAE1D,QAAA,sBAAsB,GAAG,C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AW,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;YAC1C,IAAI,iBAAiB,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,OAAO,GAAG,WAAW,EAAE,CAAC;gBAC3D,qEAAqE;gBACrE,iDAAiD;gBACjD,IAAI,CAAC;oBACH,MAAM,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,CAAA;gBAC1B,CAAC;gBAAC,MAAM,CAAC;oBACP,2BAA2B;gBAC7B,CAAC;gBACD,MAAM,KAAK,GAAG,aAAa,CAAC,OAAO,CAAC,CAAA;gBACpC,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAA;gBAC9C,SAAQ;YACV,CAAC;YACD,OAAO,GAAG,CAAA;QACZ,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,SAAS,GAAG,GAAG,CAAA;YACf,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,OAAO,IAAI,WAAW;gBAAE,MAAM,GAAG,CAAA;YAC1D,MAAM,KAAK,GAAG,aAAa,CAAC,OAAO,CAAC,CAAA;YACpC,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAA;QAChD,CAAC;IACH,CAAC;IACD,MAAM,SAAS,CAAA;AACjB,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Opt-in request/response file logger for the PayPal integration.
|
|
3
|
+
*
|
|
4
|
+
* Purpose: produce a complete, human-readable log of the HTTP traffic between
|
|
5
|
+
* this plugin and PayPal (outbound) plus the plugin's own API routes (inbound),
|
|
6
|
+
* so it can be exported and handed to PayPal's integration-review team.
|
|
7
|
+
*
|
|
8
|
+
* Disabled by default. Turned on from the admin settings (the
|
|
9
|
+
* `additional_settings.debug_logging` flag, synced into this module via
|
|
10
|
+
* `setRequestLoggingEnabled`) or, as a convenience, by the `PAYPAL_REQUEST_LOG`
|
|
11
|
+
* env var. When off, every entry point here is a cheap no-op.
|
|
12
|
+
*
|
|
13
|
+
* The log intentionally KEEPS the `PayPal-Partner-Attribution-Id` (BN code)
|
|
14
|
+
* header — PayPal validates it during review — while redacting credentials
|
|
15
|
+
* (Authorization headers, access/refresh tokens, client secrets, raw card
|
|
16
|
+
* fields) so the exported file is safe to share.
|
|
17
|
+
*/
|
|
18
|
+
/** Sync the on/off flag from the persisted `additional_settings.debug_logging`. */
|
|
19
|
+
export declare function setRequestLoggingEnabled(enabled: boolean): void;
|
|
20
|
+
/** Whether request/response logging is currently active in this process. */
|
|
21
|
+
export declare function isRequestLoggingEnabled(): boolean;
|
|
22
|
+
/** Absolute path of the log file for the current day. */
|
|
23
|
+
export declare function getCurrentLogFilePath(): string;
|
|
24
|
+
export type OutboundLog = {
|
|
25
|
+
method: string;
|
|
26
|
+
url: string;
|
|
27
|
+
requestHeaders?: unknown;
|
|
28
|
+
requestBody?: unknown;
|
|
29
|
+
status?: number;
|
|
30
|
+
statusText?: string;
|
|
31
|
+
responseHeaders?: unknown;
|
|
32
|
+
responseBody?: unknown;
|
|
33
|
+
durationMs?: number;
|
|
34
|
+
error?: unknown;
|
|
35
|
+
};
|
|
36
|
+
/** Append one outbound (plugin → PayPal / onboarding service) call. */
|
|
37
|
+
export declare function logOutbound(entry: OutboundLog): void;
|
|
38
|
+
export type InboundLog = {
|
|
39
|
+
method: string;
|
|
40
|
+
path: string;
|
|
41
|
+
query?: unknown;
|
|
42
|
+
requestHeaders?: unknown;
|
|
43
|
+
requestBody?: unknown;
|
|
44
|
+
status?: number;
|
|
45
|
+
responseBody?: unknown;
|
|
46
|
+
durationMs?: number;
|
|
47
|
+
};
|
|
48
|
+
/** Append one inbound (client → plugin API route) request. */
|
|
49
|
+
export declare function logInbound(entry: InboundLog): void;
|
|
50
|
+
export type LogFileInfo = {
|
|
51
|
+
name: string;
|
|
52
|
+
size: number;
|
|
53
|
+
modified: string;
|
|
54
|
+
};
|
|
55
|
+
/** List the available daily log files, newest first. */
|
|
56
|
+
export declare function listLogFiles(): LogFileInfo[];
|
|
57
|
+
/**
|
|
58
|
+
* Resolve a requested log file name to an absolute path INSIDE the log dir, or
|
|
59
|
+
* null if it escapes the dir / doesn't exist. Guards against path traversal.
|
|
60
|
+
*/
|
|
61
|
+
export declare function resolveLogFile(name?: string): string | null;
|
|
62
|
+
//# sourceMappingURL=request-logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-logger.d.ts","sourceRoot":"","sources":["../../../../../../src/modules/paypal/utils/request-logger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAoBH,mFAAmF;AACnF,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAE/D;AAED,4EAA4E;AAC5E,wBAAgB,uBAAuB,IAAI,OAAO,CAEjD;AA4HD,yDAAyD;AACzD,wBAAgB,qBAAqB,IAAI,MAAM,CAE9C;AA6CD,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,EAAE,MAAM,CAAA;IACd,GAAG,EAAE,MAAM,CAAA;IACX,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB,CAAA;AAED,uEAAuE;AACvE,wBAAgB,WAAW,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI,CAgCpD;AAED,MAAM,MAAM,UAAU,GAAG;IACvB,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB,CAAA;AAED,8DAA8D;AAC9D,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI,CA8BlD;AAMD,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,wDAAwD;AACxD,wBAAgB,YAAY,IAAI,WAAW,EAAE,CAmB5C;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAa3D"}
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Opt-in request/response file logger for the PayPal integration.
|
|
4
|
+
*
|
|
5
|
+
* Purpose: produce a complete, human-readable log of the HTTP traffic between
|
|
6
|
+
* this plugin and PayPal (outbound) plus the plugin's own API routes (inbound),
|
|
7
|
+
* so it can be exported and handed to PayPal's integration-review team.
|
|
8
|
+
*
|
|
9
|
+
* Disabled by default. Turned on from the admin settings (the
|
|
10
|
+
* `additional_settings.debug_logging` flag, synced into this module via
|
|
11
|
+
* `setRequestLoggingEnabled`) or, as a convenience, by the `PAYPAL_REQUEST_LOG`
|
|
12
|
+
* env var. When off, every entry point here is a cheap no-op.
|
|
13
|
+
*
|
|
14
|
+
* The log intentionally KEEPS the `PayPal-Partner-Attribution-Id` (BN code)
|
|
15
|
+
* header — PayPal validates it during review — while redacting credentials
|
|
16
|
+
* (Authorization headers, access/refresh tokens, client secrets, raw card
|
|
17
|
+
* fields) so the exported file is safe to share.
|
|
18
|
+
*/
|
|
19
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
20
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
exports.setRequestLoggingEnabled = setRequestLoggingEnabled;
|
|
24
|
+
exports.isRequestLoggingEnabled = isRequestLoggingEnabled;
|
|
25
|
+
exports.getCurrentLogFilePath = getCurrentLogFilePath;
|
|
26
|
+
exports.logOutbound = logOutbound;
|
|
27
|
+
exports.logInbound = logInbound;
|
|
28
|
+
exports.listLogFiles = listLogFiles;
|
|
29
|
+
exports.resolveLogFile = resolveLogFile;
|
|
30
|
+
const fs_1 = __importDefault(require("fs"));
|
|
31
|
+
const path_1 = __importDefault(require("path"));
|
|
32
|
+
// ---------------------------------------------------------------------------
|
|
33
|
+
// Enable flag
|
|
34
|
+
// ---------------------------------------------------------------------------
|
|
35
|
+
/**
|
|
36
|
+
* `PAYPAL_REQUEST_LOG=1|true|yes|on` forces logging on regardless of the admin
|
|
37
|
+
* setting — handy on a box where you can't reach the admin UI. The admin
|
|
38
|
+
* setting controls the process-local flag below.
|
|
39
|
+
*/
|
|
40
|
+
const ENV_FORCE_ON = /^(1|true|yes|on)$/i.test((process.env.PAYPAL_REQUEST_LOG || "").trim());
|
|
41
|
+
let settingEnabled = false;
|
|
42
|
+
/** Sync the on/off flag from the persisted `additional_settings.debug_logging`. */
|
|
43
|
+
function setRequestLoggingEnabled(enabled) {
|
|
44
|
+
settingEnabled = !!enabled;
|
|
45
|
+
}
|
|
46
|
+
/** Whether request/response logging is currently active in this process. */
|
|
47
|
+
function isRequestLoggingEnabled() {
|
|
48
|
+
return ENV_FORCE_ON || settingEnabled;
|
|
49
|
+
}
|
|
50
|
+
// ---------------------------------------------------------------------------
|
|
51
|
+
// Redaction
|
|
52
|
+
// ---------------------------------------------------------------------------
|
|
53
|
+
// Body keys whose VALUES must never hit the exported file. Card fields are
|
|
54
|
+
// included even though they normally never reach the backend (the JS SDK sends
|
|
55
|
+
// them straight to PayPal) — defence in depth for the advanced-card flow.
|
|
56
|
+
const SENSITIVE_BODY_KEY_RE = /secret|password|client_secret|access_token|refresh_token|authorization|auth_code|code_verifier|api[_-]?key|private[_-]?key|security_code|\bcvv2?\b|card[_-]?number|(^|_)number$|expiry|exp_(month|year)/i;
|
|
57
|
+
// Request/response HEADER names to redact. The BN code header is deliberately
|
|
58
|
+
// NOT here — PayPal needs to see it in the log.
|
|
59
|
+
const SENSITIVE_HEADER_RE = /^(authorization|proxy-authorization|cookie|set-cookie|x-api-key)$/i;
|
|
60
|
+
const REDACTED = "[REDACTED]";
|
|
61
|
+
function redactBody(value, depth = 0) {
|
|
62
|
+
if (depth > 8 || value === null || typeof value !== "object") {
|
|
63
|
+
return value;
|
|
64
|
+
}
|
|
65
|
+
if (Array.isArray(value)) {
|
|
66
|
+
return value.slice(0, 200).map((v) => redactBody(v, depth + 1));
|
|
67
|
+
}
|
|
68
|
+
const out = {};
|
|
69
|
+
for (const [k, v] of Object.entries(value)) {
|
|
70
|
+
out[k] = SENSITIVE_BODY_KEY_RE.test(k) ? REDACTED : redactBody(v, depth + 1);
|
|
71
|
+
}
|
|
72
|
+
return out;
|
|
73
|
+
}
|
|
74
|
+
function redactHeaders(headers) {
|
|
75
|
+
const out = {};
|
|
76
|
+
for (const [k, v] of Object.entries(headers)) {
|
|
77
|
+
out[k] = SENSITIVE_HEADER_RE.test(k) ? REDACTED : v;
|
|
78
|
+
}
|
|
79
|
+
return out;
|
|
80
|
+
}
|
|
81
|
+
/** Best-effort parse + redact of a body that may be JSON, form-encoded, or text. */
|
|
82
|
+
function redactSerializedBody(body) {
|
|
83
|
+
if (body === undefined || body === null)
|
|
84
|
+
return "";
|
|
85
|
+
// Already a plain object/array (inbound res.json payloads).
|
|
86
|
+
if (typeof body === "object" && !(body instanceof Uint8Array)) {
|
|
87
|
+
try {
|
|
88
|
+
return JSON.stringify(redactBody(body), null, 2);
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
return "[unserializable object]";
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const text = String(body);
|
|
95
|
+
if (!text)
|
|
96
|
+
return "";
|
|
97
|
+
const trimmed = text.trim();
|
|
98
|
+
// JSON?
|
|
99
|
+
if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
|
|
100
|
+
try {
|
|
101
|
+
return JSON.stringify(redactBody(JSON.parse(trimmed)), null, 2);
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
// fall through to form / raw handling
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
// Form-encoded (grant_type=...&code_verifier=...)?
|
|
108
|
+
if (/^[^=\s]+=[^&\s]*(&[^=\s]+=[^&\s]*)*$/.test(trimmed)) {
|
|
109
|
+
try {
|
|
110
|
+
const params = new URLSearchParams(trimmed);
|
|
111
|
+
const obj = {};
|
|
112
|
+
for (const [k, v] of params.entries()) {
|
|
113
|
+
obj[k] = SENSITIVE_BODY_KEY_RE.test(k) ? REDACTED : v;
|
|
114
|
+
}
|
|
115
|
+
return JSON.stringify(obj, null, 2);
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
// fall through
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return trimmed.slice(0, 20_000);
|
|
122
|
+
}
|
|
123
|
+
function normalizeHeaders(headers) {
|
|
124
|
+
const out = {};
|
|
125
|
+
if (!headers)
|
|
126
|
+
return out;
|
|
127
|
+
try {
|
|
128
|
+
// Fetch Headers / Response.headers
|
|
129
|
+
if (typeof headers.forEach === "function") {
|
|
130
|
+
;
|
|
131
|
+
headers.forEach((v, k) => {
|
|
132
|
+
out[k] = v;
|
|
133
|
+
});
|
|
134
|
+
return out;
|
|
135
|
+
}
|
|
136
|
+
if (Array.isArray(headers)) {
|
|
137
|
+
for (const pair of headers) {
|
|
138
|
+
if (pair && pair.length >= 2)
|
|
139
|
+
out[String(pair[0])] = String(pair[1]);
|
|
140
|
+
}
|
|
141
|
+
return out;
|
|
142
|
+
}
|
|
143
|
+
for (const [k, v] of Object.entries(headers)) {
|
|
144
|
+
out[k] = Array.isArray(v) ? v.join(", ") : String(v);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
catch {
|
|
148
|
+
// ignore malformed header containers
|
|
149
|
+
}
|
|
150
|
+
return out;
|
|
151
|
+
}
|
|
152
|
+
// ---------------------------------------------------------------------------
|
|
153
|
+
// File sink
|
|
154
|
+
// ---------------------------------------------------------------------------
|
|
155
|
+
function getLogDir() {
|
|
156
|
+
const dir = (process.env.PAYPAL_LOG_DIR || "").trim();
|
|
157
|
+
return dir ? path_1.default.resolve(dir) : path_1.default.join(process.cwd(), "logs");
|
|
158
|
+
}
|
|
159
|
+
const LOG_PREFIX = "paypal-requests-";
|
|
160
|
+
function dateStamp(d = new Date()) {
|
|
161
|
+
return d.toISOString().slice(0, 10); // YYYY-MM-DD
|
|
162
|
+
}
|
|
163
|
+
/** Absolute path of the log file for the current day. */
|
|
164
|
+
function getCurrentLogFilePath() {
|
|
165
|
+
return path_1.default.join(getLogDir(), `${LOG_PREFIX}${dateStamp()}.log`);
|
|
166
|
+
}
|
|
167
|
+
let dirEnsured = false;
|
|
168
|
+
function ensureDir(dir) {
|
|
169
|
+
if (dirEnsured)
|
|
170
|
+
return true;
|
|
171
|
+
try {
|
|
172
|
+
fs_1.default.mkdirSync(dir, { recursive: true });
|
|
173
|
+
dirEnsured = true;
|
|
174
|
+
return true;
|
|
175
|
+
}
|
|
176
|
+
catch (e) {
|
|
177
|
+
// Only warn once; never throw into the request path.
|
|
178
|
+
console.warn("[paypal_request_log] could not create log dir", dir, e?.message);
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
function write(block) {
|
|
183
|
+
try {
|
|
184
|
+
const dir = getLogDir();
|
|
185
|
+
if (!ensureDir(dir))
|
|
186
|
+
return;
|
|
187
|
+
fs_1.default.appendFileSync(getCurrentLogFilePath(), block);
|
|
188
|
+
}
|
|
189
|
+
catch (e) {
|
|
190
|
+
console.warn("[paypal_request_log] write failed:", e?.message);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
const DIVIDER = "=".repeat(80);
|
|
194
|
+
function renderHeaders(headers) {
|
|
195
|
+
const keys = Object.keys(headers);
|
|
196
|
+
if (keys.length === 0)
|
|
197
|
+
return " (none)";
|
|
198
|
+
return keys.map((k) => ` ${k}: ${headers[k]}`).join("\n");
|
|
199
|
+
}
|
|
200
|
+
/** Append one outbound (plugin → PayPal / onboarding service) call. */
|
|
201
|
+
function logOutbound(entry) {
|
|
202
|
+
if (!isRequestLoggingEnabled())
|
|
203
|
+
return;
|
|
204
|
+
const reqHeaders = redactHeaders(normalizeHeaders(entry.requestHeaders));
|
|
205
|
+
const resHeaders = redactHeaders(normalizeHeaders(entry.responseHeaders));
|
|
206
|
+
const outcome = entry.error
|
|
207
|
+
? `ERROR ${entry.error?.message || String(entry.error)}`
|
|
208
|
+
: `-> ${entry.status ?? "?"}${entry.statusText ? " " + entry.statusText : ""}`;
|
|
209
|
+
const duration = typeof entry.durationMs === "number" ? ` (${entry.durationMs}ms)` : "";
|
|
210
|
+
const block = [
|
|
211
|
+
DIVIDER,
|
|
212
|
+
`[${new Date().toISOString()}] OUTBOUND ${entry.method} ${entry.url} ${outcome}${duration}`,
|
|
213
|
+
"Request Headers:",
|
|
214
|
+
renderHeaders(reqHeaders),
|
|
215
|
+
"Request Body:",
|
|
216
|
+
redactSerializedBody(entry.requestBody) || " (empty)",
|
|
217
|
+
"Response Headers:",
|
|
218
|
+
renderHeaders(resHeaders),
|
|
219
|
+
"Response Body:",
|
|
220
|
+
entry.error
|
|
221
|
+
? ` ${entry.error?.stack || String(entry.error)}`
|
|
222
|
+
: redactSerializedBody(entry.responseBody) || " (empty)",
|
|
223
|
+
DIVIDER,
|
|
224
|
+
"",
|
|
225
|
+
"",
|
|
226
|
+
].join("\n");
|
|
227
|
+
write(block);
|
|
228
|
+
}
|
|
229
|
+
/** Append one inbound (client → plugin API route) request. */
|
|
230
|
+
function logInbound(entry) {
|
|
231
|
+
if (!isRequestLoggingEnabled())
|
|
232
|
+
return;
|
|
233
|
+
const reqHeaders = redactHeaders(normalizeHeaders(entry.requestHeaders));
|
|
234
|
+
const duration = typeof entry.durationMs === "number" ? ` (${entry.durationMs}ms)` : "";
|
|
235
|
+
const query = entry.query && Object.keys(entry.query).length
|
|
236
|
+
? `?${new URLSearchParams(entry.query).toString()}`
|
|
237
|
+
: "";
|
|
238
|
+
const block = [
|
|
239
|
+
DIVIDER,
|
|
240
|
+
`[${new Date().toISOString()}] INBOUND ${entry.method} ${entry.path}${query} -> ${entry.status ?? "?"}${duration}`,
|
|
241
|
+
"Request Headers:",
|
|
242
|
+
renderHeaders(reqHeaders),
|
|
243
|
+
"Request Body:",
|
|
244
|
+
redactSerializedBody(entry.requestBody) || " (empty)",
|
|
245
|
+
"Response Body:",
|
|
246
|
+
redactSerializedBody(entry.responseBody) || " (empty)",
|
|
247
|
+
DIVIDER,
|
|
248
|
+
"",
|
|
249
|
+
"",
|
|
250
|
+
].join("\n");
|
|
251
|
+
write(block);
|
|
252
|
+
}
|
|
253
|
+
/** List the available daily log files, newest first. */
|
|
254
|
+
function listLogFiles() {
|
|
255
|
+
try {
|
|
256
|
+
const dir = getLogDir();
|
|
257
|
+
if (!fs_1.default.existsSync(dir))
|
|
258
|
+
return [];
|
|
259
|
+
return fs_1.default
|
|
260
|
+
.readdirSync(dir)
|
|
261
|
+
.filter((f) => f.startsWith(LOG_PREFIX) && f.endsWith(".log"))
|
|
262
|
+
.map((name) => {
|
|
263
|
+
const stat = fs_1.default.statSync(path_1.default.join(dir, name));
|
|
264
|
+
return {
|
|
265
|
+
name,
|
|
266
|
+
size: stat.size,
|
|
267
|
+
modified: stat.mtime.toISOString(),
|
|
268
|
+
};
|
|
269
|
+
})
|
|
270
|
+
.sort((a, b) => (a.name < b.name ? 1 : -1));
|
|
271
|
+
}
|
|
272
|
+
catch {
|
|
273
|
+
return [];
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Resolve a requested log file name to an absolute path INSIDE the log dir, or
|
|
278
|
+
* null if it escapes the dir / doesn't exist. Guards against path traversal.
|
|
279
|
+
*/
|
|
280
|
+
function resolveLogFile(name) {
|
|
281
|
+
const dir = getLogDir();
|
|
282
|
+
const target = name && name.trim() ? name.trim() : null;
|
|
283
|
+
const chosen = target
|
|
284
|
+
? path_1.default.join(dir, path_1.default.basename(target))
|
|
285
|
+
: listLogFiles()[0]
|
|
286
|
+
? path_1.default.join(dir, listLogFiles()[0].name)
|
|
287
|
+
: null;
|
|
288
|
+
if (!chosen)
|
|
289
|
+
return null;
|
|
290
|
+
// basename() already strips any directory component; verify containment.
|
|
291
|
+
if (path_1.default.dirname(chosen) !== path_1.default.resolve(dir))
|
|
292
|
+
return null;
|
|
293
|
+
if (!fs_1.default.existsSync(chosen))
|
|
294
|
+
return null;
|
|
295
|
+
return chosen;
|
|
296
|
+
}
|
|
297
|
+
//# sourceMappingURL=request-logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-logger.js","sourceRoot":"","sources":["../../../../../../src/modules/paypal/utils/request-logger.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG;;;;;AAqBH,4DAEC;AAGD,0DAEC;AA6HD,sDAEC;AA2DD,kCAgCC;AAcD,gCA8BC;AAaD,oCAmBC;AAMD,wCAaC;AAnVD,4CAAmB;AACnB,gDAAuB;AAEvB,8EAA8E;AAC9E,cAAc;AACd,8EAA8E;AAE9E;;;;GAIG;AACH,MAAM,YAAY,GAAG,oBAAoB,CAAC,IAAI,CAC5C,CAAC,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAC9C,CAAA;AAED,IAAI,cAAc,GAAG,KAAK,CAAA;AAE1B,mFAAmF;AACnF,SAAgB,wBAAwB,CA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AC,CAAC,CAAC,CAAC,IAAI,CAAC;YACxC,CAAC,CAAC,IAAI,CAAA;IACV,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAA;IACxB,yEAAyE;IACzE,IAAI,cAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,cAAI,CAAC,OAAO,CAAC,GAAG,CAAC;QAAE,OAAO,IAAI,CAAA;IAC3D,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,MAAM,CAAC;QAAE,OAAO,IAAI,CAAA;IACvC,OAAO,MAAM,CAAA;AACf,CAAC"}
|
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,33 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to `@easypayment/medusa-payment-paypal` are documented here.
|
|
4
4
|
|
|
5
|
+
## 1.3.5 — 2026-11-16
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
|
|
9
|
+
- **Upgraded installs now onboard through the current partner service.** The
|
|
10
|
+
partner service URL was only written to `onboarding_config` when the field
|
|
11
|
+
was empty, so stores set up on an earlier version kept sending onboarding
|
|
12
|
+
link requests to the previous service
|
|
13
|
+
(`.../ppcp-seller-onboarding/...`) instead of
|
|
14
|
+
`.../medusa-seller-onboarding/...`. For the same reason, setting
|
|
15
|
+
`PAYPAL_PARTNER_SERVICE_URL` after the first run had no effect. The stored
|
|
16
|
+
URL now follows the configured one on the next settings-defaults pass.
|
|
17
|
+
- **Stored BN code is now refreshed on upgraded installs.** Stores set up before
|
|
18
|
+
the switch to `MBJ_Medusa_SI` kept the previous code
|
|
19
|
+
(`MBJTechnolabs_SI_SPB`) in `onboarding_config.bn_code`, because the settings
|
|
20
|
+
defaults only filled the field when it was empty. PayPal API calls already
|
|
21
|
+
sent the new code; the stale value only showed in the stored settings and
|
|
22
|
+
the `/admin/paypal/settings` response. It is now replaced on the next
|
|
23
|
+
settings-defaults pass.
|
|
24
|
+
|
|
25
|
+
## 1.3.4 — 2026-11-13
|
|
26
|
+
|
|
27
|
+
### Changed
|
|
28
|
+
|
|
29
|
+
- No code changes. Version aligned with `@easypayment/medusa-paypal-ui` 1.3.4,
|
|
30
|
+
which refreshes the storefront unsupported-currency notice.
|
|
31
|
+
|
|
5
32
|
## 1.3.3 — 2026-11-05
|
|
6
33
|
|
|
7
34
|
### Fixed
|
package/README.md
CHANGED
|
@@ -165,6 +165,8 @@ Everything is managed in **Medusa Admin → Settings → PayPal** — changes ap
|
|
|
165
165
|
| `PAYPAL_CURRENCY` | `EUR` | Fallback currency if none is configured |
|
|
166
166
|
| `PAYPAL_ALERT_WEBHOOK_URLS` | *(unset)* | Comma-separated URLs that receive operational alerts (including dead-lettered webhook events) |
|
|
167
167
|
| `PAYPAL_SETTINGS_CACHE_MS` | `15000` | In-process cache for plugin settings reads; `0` disables |
|
|
168
|
+
| `PAYPAL_REQUEST_LOG` | *(off)* | `1`/`true` force-enables the request/response log file regardless of the admin toggle (normally enabled from **Settings → PayPal → Additional Settings**) |
|
|
169
|
+
| `PAYPAL_LOG_DIR` | `./logs` | Directory for the `paypal-requests-YYYY-MM-DD.log` file written when logging is on |
|
|
168
170
|
| `PAYPAL_SEND_SHIPPING_ADDRESS` | `false` | `true` sends the cart's shipping address on PayPal orders (`SET_PROVIDED_ADDRESS`) — improves PayPal Seller Protection eligibility |
|
|
169
171
|
| `PAYPAL_PARTNER_SERVICE_URL` | *(built-in)* | Override the partner onboarding service used by the connect flow |
|
|
170
172
|
| `PAYPAL_PARTNER_MERCHANT_ID_SANDBOX` / `PAYPAL_PARTNER_MERCHANT_ID_LIVE` | *(built-in)* | Override the partner merchant ids used for onboarding |
|
|
@@ -173,6 +175,8 @@ Everything is managed in **Medusa Admin → Settings → PayPal** — changes ap
|
|
|
173
175
|
|
|
174
176
|
**Monitoring:** operational counters live in the `paypal_metric` table; every webhook is recorded in `paypal_webhook_event` with automatic retries (events that exhaust retries are dead-lettered **and pushed to `PAYPAL_ALERT_WEBHOOK_URLS`**); audit events are logged as JSON lines tagged `"log":"paypal_audit"` (secrets redacted).
|
|
175
177
|
|
|
178
|
+
**Integration log for PayPal review:** turn on **Settings → PayPal → Additional Settings → Request/response logging** (off by default) to append every PayPal API call and every plugin API request/response to `logs/paypal-requests-YYYY-MM-DD.log`. Credentials are redacted while the `PayPal-Partner-Attribution-Id` (BN code) is kept, so the file is safe to hand to PayPal's go-live review. Download it from the same settings page (**Download log**) or at `GET /admin/paypal/logs?download=1`. Turn it back off once the review is complete.
|
|
179
|
+
|
|
176
180
|
</details>
|
|
177
181
|
|
|
178
182
|
---
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@easypayment/medusa-payment-paypal",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.5",
|
|
4
4
|
"description": "PayPal & credit card payments for Medusa v2 — PayPal Buttons, hosted card fields, 3D Secure, and an admin dashboard. Built by a PayPal Partner.",
|
|
5
5
|
"author": "EasyPayment Plugins",
|
|
6
6
|
"license": "MIT",
|
|
@@ -16,6 +16,7 @@ type AdditionalSettingsForm = {
|
|
|
16
16
|
sendItemDetails: boolean
|
|
17
17
|
invoicePrefix: string
|
|
18
18
|
creditCardStatementName: string
|
|
19
|
+
debugLogging: boolean
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
const DEFAULT_FORM: AdditionalSettingsForm = {
|
|
@@ -26,6 +27,7 @@ const DEFAULT_FORM: AdditionalSettingsForm = {
|
|
|
26
27
|
sendItemDetails: true,
|
|
27
28
|
invoicePrefix: "PP-",
|
|
28
29
|
creditCardStatementName: "PayPal",
|
|
30
|
+
debugLogging: false,
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
/** Overlay saved values on the defaults, ignoring `undefined` entries. */
|
|
@@ -47,11 +49,55 @@ export default function AdditionalSettingsTab() {
|
|
|
47
49
|
}))
|
|
48
50
|
const [loading, setLoading] = useState(false)
|
|
49
51
|
const [saving, setSaving] = useState(false)
|
|
52
|
+
const [downloading, setDownloading] = useState(false)
|
|
50
53
|
const [toast, setToast] = useState<ToastState>(null)
|
|
51
54
|
const didInit = useRef(false)
|
|
52
55
|
|
|
53
56
|
const dismissToast = useCallback(() => setToast(null), [])
|
|
54
57
|
|
|
58
|
+
async function onDownloadLog() {
|
|
59
|
+
try {
|
|
60
|
+
setDownloading(true)
|
|
61
|
+
setToast(null)
|
|
62
|
+
const headers: Record<string, string> = { Accept: "text/plain" }
|
|
63
|
+
if (typeof window !== "undefined") {
|
|
64
|
+
const token = (window as any).__medusa__?.token
|
|
65
|
+
if (token) headers["Authorization"] = `Bearer ${token}`
|
|
66
|
+
}
|
|
67
|
+
const res = await fetch("/admin/paypal/logs?download=1", {
|
|
68
|
+
headers,
|
|
69
|
+
credentials: "include",
|
|
70
|
+
})
|
|
71
|
+
if (!res.ok) {
|
|
72
|
+
if (res.status === 404) {
|
|
73
|
+
throw new Error(
|
|
74
|
+
"No log file yet. Enable logging, run a test transaction, then download."
|
|
75
|
+
)
|
|
76
|
+
}
|
|
77
|
+
throw new Error(`Download failed (${res.status})`)
|
|
78
|
+
}
|
|
79
|
+
const blob = await res.blob()
|
|
80
|
+
const dispo = res.headers.get("Content-Disposition") || ""
|
|
81
|
+
const match = dispo.match(/filename="?([^"]+)"?/)
|
|
82
|
+
const filename = match?.[1] || "paypal-requests.log"
|
|
83
|
+
const url = URL.createObjectURL(blob)
|
|
84
|
+
const a = document.createElement("a")
|
|
85
|
+
a.href = url
|
|
86
|
+
a.download = filename
|
|
87
|
+
document.body.appendChild(a)
|
|
88
|
+
a.click()
|
|
89
|
+
a.remove()
|
|
90
|
+
URL.revokeObjectURL(url)
|
|
91
|
+
} catch (e: unknown) {
|
|
92
|
+
setToast({
|
|
93
|
+
kind: "error",
|
|
94
|
+
message: e instanceof Error ? e.message : "Failed to download log",
|
|
95
|
+
})
|
|
96
|
+
} finally {
|
|
97
|
+
setDownloading(false)
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
55
101
|
useEffect(() => {
|
|
56
102
|
if (didInit.current) return
|
|
57
103
|
didInit.current = true
|
|
@@ -240,6 +286,47 @@ export default function AdditionalSettingsTab() {
|
|
|
240
286
|
</FieldRow>
|
|
241
287
|
</div>
|
|
242
288
|
</SectionCard>
|
|
289
|
+
|
|
290
|
+
<SectionCard
|
|
291
|
+
title="Integration logging (PayPal review)"
|
|
292
|
+
description="Write every PayPal API request/response and plugin API request/response to a log file you can download and send to PayPal for integration approval. Credentials (auth tokens, client secrets, card fields) are redacted; the BN code is kept. Keep this OFF in normal production use."
|
|
293
|
+
right={
|
|
294
|
+
<div className="flex items-center gap-3">
|
|
295
|
+
<button
|
|
296
|
+
type="button"
|
|
297
|
+
onClick={onDownloadLog}
|
|
298
|
+
disabled={downloading}
|
|
299
|
+
className="transition-fg relative inline-flex w-fit items-center justify-center overflow-hidden rounded-md outline-none shadow-buttons-neutral text-ui-fg-base bg-ui-button-neutral after:transition-fg after:absolute after:inset-0 after:content-[''] after:button-neutral-gradient hover:bg-ui-button-neutral-hover hover:after:button-neutral-hover-gradient active:bg-ui-button-neutral-pressed active:after:button-neutral-pressed-gradient focus-visible:shadow-buttons-neutral-focus disabled:bg-ui-bg-disabled disabled:border-ui-border-base disabled:text-ui-fg-disabled disabled:shadow-buttons-neutral disabled:after:hidden txt-compact-small-plus px-3 py-1.5"
|
|
300
|
+
>
|
|
301
|
+
{downloading ? "Preparing…" : "Download log"}
|
|
302
|
+
</button>
|
|
303
|
+
</div>
|
|
304
|
+
}
|
|
305
|
+
>
|
|
306
|
+
<div className="divide-y divide-ui-border-base">
|
|
307
|
+
<FieldRow
|
|
308
|
+
label="Request/response logging"
|
|
309
|
+
hint="When enabled, the plugin appends each request and response to logs/paypal-requests-YYYY-MM-DD.log (path configurable via PAYPAL_LOG_DIR). Remember to save after toggling."
|
|
310
|
+
>
|
|
311
|
+
<label className="inline-flex items-center gap-2">
|
|
312
|
+
<input
|
|
313
|
+
type="checkbox"
|
|
314
|
+
checked={form.debugLogging}
|
|
315
|
+
onChange={(e) =>
|
|
316
|
+
setForm((p) => ({
|
|
317
|
+
...p,
|
|
318
|
+
debugLogging: e.target.checked,
|
|
319
|
+
}))
|
|
320
|
+
}
|
|
321
|
+
className="h-4 w-4 rounded border-ui-border-base"
|
|
322
|
+
/>
|
|
323
|
+
<span className="text-sm text-ui-fg-base">
|
|
324
|
+
Enable request/response log file
|
|
325
|
+
</span>
|
|
326
|
+
</label>
|
|
327
|
+
</FieldRow>
|
|
328
|
+
</div>
|
|
329
|
+
</SectionCard>
|
|
243
330
|
</div>
|
|
244
331
|
</div>
|
|
245
332
|
)
|