Skip to content

Commit ba7cfad

Browse files
committed
fix: fix wrong package.json path
1 parent 20bb01d commit ba7cfad

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

.changeset/six-cherries-pay.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@hyperse-io/paypal-node-sdk": patch
3+
---
4+
5+
fix wrong `package.json` path

src/core/PayPalHttpClient.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
import { readFileSync } from 'fs';
2+
import { dirname, join } from 'node:path';
3+
import { fileURLToPath } from 'node:url';
24
import paypalhttp, { type HttpRequest } from '@paypal/paypalhttp';
35
import { AccessToken } from './AccessToken.js';
46
import { AccessTokenRequest } from './AccessTokenRequest.js';
57
import { type HttpRequestBase } from './HttpRequestBase.js';
68
import { type PayPalEnvironment } from './PayPalEnvironment.js';
79
import { TokenCache } from './TokenCache.js';
810

11+
/**
12+
* Provider method to simulate __dirname veriable.
13+
* @param url import.meta.url
14+
* @param paths paths to join.
15+
*/
16+
const getDirname = (url: string, ...paths: string[]) => {
17+
return join(dirname(fileURLToPath(url)), ...paths);
18+
};
19+
920
/**
1021
* PayPal Http client
1122
* Documentation
@@ -27,7 +38,9 @@ export class PayPalHttpClient extends paypalhttp.HttpClient {
2738
this._cache = TokenCache.cacheForEnvironment(environment, refreshToken);
2839
this.refreshToken = refreshToken;
2940
this.addInjector(this.authInjector);
30-
this.package = JSON.parse(readFileSync('../../package.json', 'utf8'));
41+
this.package = JSON.parse(
42+
readFileSync(getDirname(import.meta.url, '../../package.json'), 'utf8')
43+
);
3144
this.addInjector(function (req) {
3245
req.headers['Accept-Encoding'] = 'gzip';
3346
req.headers['sdk_name'] = 'Checkout SDK';

0 commit comments

Comments
 (0)