@easypayment/medusa-payment-paypal 1.3.5 → 1.3.7

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.
@@ -51,8 +51,14 @@ export function isRequestLoggingEnabled(): boolean {
51
51
  // Body keys whose VALUES must never hit the exported file. Card fields are
52
52
  // included even though they normally never reach the backend (the JS SDK sends
53
53
  // them straight to PayPal) — defence in depth for the advanced-card flow.
54
+ //
55
+ // `authorization(?!s$)`: redact `authorization`, `authorization_code`, … but
56
+ // not PayPal's `payments.authorizations` collection, which holds the
57
+ // authorization id, status, amount and expiry a reviewer needs to see and no
58
+ // credential. `client_token` is the JS SDK token, which embeds a live access
59
+ // token.
54
60
  const SENSITIVE_BODY_KEY_RE =
55
- /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
61
+ /secret|password|client_secret|client_token|access_token|refresh_token|authorization(?!s$)|auth_code|code_verifier|api[_-]?key|private[_-]?key|security_code|\bcvv2?\b|card[_-]?number|(^|_)number$|expiry|exp_(month|year)/i
56
62
 
57
63
  // Request/response HEADER names to redact. The BN code header is deliberately
58
64
  // NOT here — PayPal needs to see it in the log.
@@ -61,7 +67,8 @@ const SENSITIVE_HEADER_RE =
61
67
 
62
68
  const REDACTED = "[REDACTED]"
63
69
 
64
- function redactBody(value: unknown, depth = 0): unknown {
70
+ /** Deep-copy `value` with the values of sensitive keys replaced. */
71
+ export function redactBody(value: unknown, depth = 0): unknown {
65
72
  if (depth > 8 || value === null || typeof value !== "object") {
66
73
  return value
67
74
  }
@@ -123,9 +130,7 @@ function redactSerializedBody(body: unknown): string {
123
130
  return trimmed.slice(0, 20_000)
124
131
  }
125
132
 
126
- function normalizeHeaders(
127
- headers: unknown
128
- ): Record<string, string> {
133
+ function normalizeHeaders(headers: unknown): Record<string, string> {
129
134
  const out: Record<string, string> = {}
130
135
  if (!headers) return out
131
136
  try {
@@ -195,10 +200,7 @@ function write(block: string): void {
195
200
  if (!ensureDir(dir)) return
196
201
  fs.appendFileSync(getCurrentLogFilePath(), block)
197
202
  } catch (e) {
198
- console.warn(
199
- "[paypal_request_log] write failed:",
200
- (e as Error)?.message
201
- )
203
+ console.warn("[paypal_request_log] write failed:", (e as Error)?.message)
202
204
  }
203
205
  }
204
206
 
@@ -240,24 +242,23 @@ export function logOutbound(entry: OutboundLog): void {
240
242
  const duration =
241
243
  typeof entry.durationMs === "number" ? ` (${entry.durationMs}ms)` : ""
242
244
 
243
- const block =
244
- [
245
- DIVIDER,
246
- `[${new Date().toISOString()}] OUTBOUND ${entry.method} ${entry.url} ${outcome}${duration}`,
247
- "Request Headers:",
248
- renderHeaders(reqHeaders),
249
- "Request Body:",
250
- redactSerializedBody(entry.requestBody) || " (empty)",
251
- "Response Headers:",
252
- renderHeaders(resHeaders),
253
- "Response Body:",
254
- entry.error
255
- ? ` ${(entry.error as Error)?.stack || String(entry.error)}`
256
- : redactSerializedBody(entry.responseBody) || " (empty)",
257
- DIVIDER,
258
- "",
259
- "",
260
- ].join("\n")
245
+ const block = [
246
+ DIVIDER,
247
+ `[${new Date().toISOString()}] OUTBOUND ${entry.method} ${entry.url} ${outcome}${duration}`,
248
+ "Request Headers:",
249
+ renderHeaders(reqHeaders),
250
+ "Request Body:",
251
+ redactSerializedBody(entry.requestBody) || " (empty)",
252
+ "Response Headers:",
253
+ renderHeaders(resHeaders),
254
+ "Response Body:",
255
+ entry.error
256
+ ? ` ${(entry.error as Error)?.stack || String(entry.error)}`
257
+ : redactSerializedBody(entry.responseBody) || " (empty)",
258
+ DIVIDER,
259
+ "",
260
+ "",
261
+ ].join("\n")
261
262
 
262
263
  write(block)
263
264
  }
@@ -286,22 +287,21 @@ export function logInbound(entry: InboundLog): void {
286
287
  ).toString()}`
287
288
  : ""
288
289
 
289
- const block =
290
- [
291
- DIVIDER,
292
- `[${new Date().toISOString()}] INBOUND ${entry.method} ${entry.path}${query} -> ${
293
- entry.status ?? "?"
294
- }${duration}`,
295
- "Request Headers:",
296
- renderHeaders(reqHeaders),
297
- "Request Body:",
298
- redactSerializedBody(entry.requestBody) || " (empty)",
299
- "Response Body:",
300
- redactSerializedBody(entry.responseBody) || " (empty)",
301
- DIVIDER,
302
- "",
303
- "",
304
- ].join("\n")
290
+ const block = [
291
+ DIVIDER,
292
+ `[${new Date().toISOString()}] INBOUND ${entry.method} ${entry.path}${query} -> ${
293
+ entry.status ?? "?"
294
+ }${duration}`,
295
+ "Request Headers:",
296
+ renderHeaders(reqHeaders),
297
+ "Request Body:",
298
+ redactSerializedBody(entry.requestBody) || " (empty)",
299
+ "Response Body:",
300
+ redactSerializedBody(entry.responseBody) || " (empty)",
301
+ DIVIDER,
302
+ "",
303
+ "",
304
+ ].join("\n")
305
305
 
306
306
  write(block)
307
307
  }