@commercetools/connect-payments-sdk 0.17.2 → 0.18.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @commercetools/connect-payments-sdk
2
2
 
3
+ ## 0.18.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 1ec3a60: Read logging correlation id from session
8
+
9
+ ## 0.18.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 1bd159b: feat(currency): add more unit-tests for currency convertions. Improve conversion logic.
14
+
15
+ ### Patch Changes
16
+
17
+ - 64ee10e: fix(dependency): explicitly add @eslint/js to devDependency to fix the lint related scripts
18
+
3
19
  ## 0.17.2
4
20
 
5
21
  ### Patch Changes
@@ -16,8 +16,10 @@ class SessionHeaderAuthenticationHook {
16
16
  return async (request) => {
17
17
  const sessionIdAuthn = new security_1.HeaderBasedAuthentication(request.headers['x-session-id']);
18
18
  const authn = await this.authenticationManager.authenticate(sessionIdAuthn);
19
+ const correlationId = authn.getPrincipal().correlationId;
19
20
  this.contextProvider.updateContextData({
20
21
  authentication: authn,
22
+ ...(correlationId && { correlationId }),
21
23
  });
22
24
  };
23
25
  }
@@ -16,8 +16,10 @@ class SessionQueryParamAuthenticationHook {
16
16
  return async (request) => {
17
17
  const sessionIdAuthn = new security_1.QueryParamBasedAuthentication(request.query['ctsid']);
18
18
  const authn = await this.authenticationManager.authenticate(sessionIdAuthn);
19
+ const correlationId = authn.getPrincipal().correlationId;
19
20
  this.contextProvider.updateContextData({
20
21
  authentication: authn,
22
+ ...(correlationId && { correlationId }),
21
23
  });
22
24
  };
23
25
  }
@@ -2,10 +2,15 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.convertWithMapping = exports.convert = void 0;
4
4
  const validateFractionDigit = (fractionDigit) => {
5
- if (!Number.isInteger(fractionDigit)) {
5
+ if (!Number.isSafeInteger(fractionDigit)) {
6
6
  throw new Error(`The given fraction digit of "${fractionDigit}" is not a integer. Fraction digit must be an integer value.`);
7
7
  }
8
8
  };
9
+ const validateAmount = (amount) => {
10
+ if (!Number.isSafeInteger(amount)) {
11
+ throw new Error(`The given value of ${amount} is not a safe integer number`);
12
+ }
13
+ };
9
14
  /**
10
15
  * Applies the fraction digit to the given amount.
11
16
  * Positive fraction digit moves the decimal to the right, negative to the left. (i.e. adding or removing zeros from either end)
@@ -30,6 +35,7 @@ const validateFractionDigit = (fractionDigit) => {
30
35
  */
31
36
  const convert = (amount, fractionDigit) => {
32
37
  validateFractionDigit(fractionDigit);
38
+ validateAmount(amount);
33
39
  const result = amount * Math.pow(10, fractionDigit);
34
40
  const strResult = result.toFixed(Math.abs(fractionDigit));
35
41
  return parseFloat(strResult);
@@ -22,5 +22,6 @@ export declare class DefaultSessionService implements SessionService {
22
22
  getMerchantReturnUrlFromSession(session: Session): string | undefined;
23
23
  getFutureOrderNumberFromSession(session: Session): string | undefined;
24
24
  getGiftCardPlannedAmountFromSession(session: Session): Money | undefined;
25
+ getCorrelationIdFromSession(session: Session): string | undefined;
25
26
  private getSession;
26
27
  }
@@ -78,6 +78,9 @@ class DefaultSessionService {
78
78
  getGiftCardPlannedAmountFromSession(session) {
79
79
  return session.metadata?.giftCardPlannedAmount;
80
80
  }
81
+ getCorrelationIdFromSession(session) {
82
+ return session.metadata?.correlationId;
83
+ }
81
84
  async getSession(sessionId) {
82
85
  return await fetch(`${this.sessionUrl}/${this.projectKey}/sessions/${sessionId}`, {
83
86
  method: 'GET',
@@ -31,4 +31,5 @@ export interface SessionService {
31
31
  getMerchantReturnUrlFromSession(session: Session): string | undefined;
32
32
  getFutureOrderNumberFromSession(session: Session): string | undefined;
33
33
  getGiftCardPlannedAmountFromSession(session: Session): Money | undefined;
34
+ getCorrelationIdFromSession(session: Session): string | undefined;
34
35
  }
@@ -22,6 +22,7 @@ class SessionHeaderAuthenticationManager {
22
22
  merchantReturnUrl: this.sessionService.getMerchantReturnUrlFromSession(session),
23
23
  futureOrderNumber: this.sessionService.getFutureOrderNumberFromSession(session),
24
24
  giftCardPlannedAmount: this.sessionService.getGiftCardPlannedAmountFromSession(session),
25
+ correlationId: this.sessionService.getCorrelationIdFromSession(session),
25
26
  });
26
27
  }
27
28
  catch (e) {
@@ -24,6 +24,7 @@ export type SessionPrincipal = {
24
24
  merchantReturnUrl?: string;
25
25
  futureOrderNumber?: string;
26
26
  giftCardPlannedAmount?: Money;
27
+ correlationId?: string;
27
28
  };
28
29
  export type Oauth2Principal = {
29
30
  clientId: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commercetools/connect-payments-sdk",
3
- "version": "0.17.2",
3
+ "version": "0.18.1",
4
4
  "description": "Payment SDK for commercetools payment connectors",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -15,7 +15,7 @@
15
15
  ],
16
16
  "license": "ISC",
17
17
  "dependencies": {
18
- "@commercetools-backend/loggers": "22.39.0",
18
+ "@commercetools-backend/loggers": "22.39.1",
19
19
  "@commercetools/platform-sdk": "8.1.0",
20
20
  "@commercetools/sdk-client-v2": "2.5.0",
21
21
  "jsonwebtoken": "9.0.2",