@commercetools/connect-payments-sdk 0.8.0 → 0.8.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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @commercetools/connect-payments-sdk
2
2
 
3
+ ## 0.8.2
4
+
5
+ ### Patch Changes
6
+
7
+ - c10522b: - Do not crash the commercetools permissions health check if the config is incorrect. Instead return a proper health check status.
8
+
9
+ ## 0.8.1
10
+
11
+ ### Patch Changes
12
+
13
+ - de97af3: Improve updatePayment for resolving conflicts updating the interfaceId
14
+
3
15
  ## 0.8.0
4
16
 
5
17
  ### Minor Changes
@@ -68,26 +68,38 @@ exports.statusHandler = statusHandler;
68
68
  * @returns
69
69
  */
70
70
  const healthCheckCommercetoolsPermissions = (opts) => async () => {
71
- const token = await opts.ctAuthorizationService.getAccessToken();
72
- const foundAll = opts.requiredPermissions.every((currentScope) => token.scope.split(' ').some((scopeInToken) => scopeInToken === `${currentScope}:${opts.projectKey}`));
73
- if (foundAll) {
71
+ try {
72
+ const token = await opts.ctAuthorizationService.getAccessToken();
73
+ const foundAll = opts.requiredPermissions.every((currentScope) => token.scope.split(' ').some((scopeInToken) => scopeInToken === `${currentScope}:${opts.projectKey}`));
74
+ if (foundAll) {
75
+ return {
76
+ name: 'commercetools permissions',
77
+ status: 'UP',
78
+ details: {
79
+ scope: token.scope,
80
+ },
81
+ };
82
+ }
74
83
  return {
75
- name: 'CoCo Permissions',
76
- status: 'UP',
84
+ name: 'commercetools permissions',
85
+ status: 'DOWN',
86
+ message: `commercetools permissions are not correct, expected scopes: ${opts.requiredPermissions.join(' ')}, actual scopes: ${token.scope}`,
77
87
  details: {
78
- scope: token.scope,
88
+ expectedScopes: opts.requiredPermissions,
89
+ actualScopes: token.scope,
90
+ reason: 'scopes not available',
91
+ },
92
+ };
93
+ }
94
+ catch (error) {
95
+ return {
96
+ name: 'commercetools permissions',
97
+ status: 'DOWN',
98
+ message: `Not able to talk with commercetools API`,
99
+ details: {
100
+ error,
79
101
  },
80
102
  };
81
103
  }
82
- return {
83
- name: 'CoCo Permissions',
84
- status: 'DOWN',
85
- message: `CoCo permissions are not correct, expected scopes: ${opts.requiredPermissions.join(' ')}, actual scopes: ${token.scope}`,
86
- details: {
87
- expectedScopes: opts.requiredPermissions,
88
- actualScopes: token.scope,
89
- reason: 'scopes not available',
90
- },
91
- };
92
104
  };
93
105
  exports.healthCheckCommercetoolsPermissions = healthCheckCommercetoolsPermissions;
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { IncomingHttpHeaders } from 'node:http';
3
2
  import { JWTAuthenticationManager } from '../../security/authn/jwt-authn-manager';
4
3
  import { ContextProvider, RequestContextData } from '../context/types/request-context.type';
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { IncomingHttpHeaders } from 'node:http';
3
2
  import { Oauth2AuthenticationManager } from '../../security/authn/oauth2-authn-manager';
4
3
  import { ContextProvider, RequestContextData } from '../context/types/request-context.type';
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { IncomingHttpHeaders } from 'node:http';
3
2
  import { ContextProvider, RequestContextData } from '../context/types/request-context.type';
4
3
  import { SessionHeaderAuthenticationManager } from '../../security';
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { IncomingHttpHeaders } from 'node:http';
3
2
  import { ContextProvider, RequestContextData } from '../context/types/request-context.type';
4
3
  import { SessionQueryParamAuthenticationManager } from '../../security';
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { IncomingHttpHeaders } from 'node:http';
3
2
  export interface AuthenticationHook {
4
3
  authenticate(): (request: {
@@ -24,7 +24,11 @@ class DefaultPaymentService {
24
24
  for (let retries = 0; retries < maxRetries; retries++) {
25
25
  const payment = await this.getPayment({ id: opts.id });
26
26
  const actions = this.consolidateUpdateActions(payment, opts);
27
- this.logger.info({ paymentId: payment.id, actions }, 'Updating payment with actions');
27
+ this.logger.info({ paymentId: payment.id, paymentVersion: payment.version, actions, retries }, 'Updating payment with actions');
28
+ if (actions.length === 0) {
29
+ this.logger.info({ paymentId: payment.id, paymentVersion: payment.version, retries }, 'Update payment skipped, no actions to perform');
30
+ return payment;
31
+ }
28
32
  try {
29
33
  const updatedPayment = await this.ctAPI.payment.updatePayment({
30
34
  resource: {
@@ -37,10 +41,14 @@ class DefaultPaymentService {
37
41
  }
38
42
  catch (e) {
39
43
  err = e;
40
- if (e instanceof ct_api_error_1.CommercetoolsAPIError && e.httpErrorStatus === 409) {
44
+ if (e instanceof ct_api_error_1.CommercetoolsAPIError &&
45
+ (e.httpErrorStatus === 409 ||
46
+ (e.httpErrorStatus === 400 && e.message.includes('already used without setting a payment interface')))) {
47
+ this.logger.warn({ paymentId: payment.id, paymentVersion: payment.version, retries, err }, 'Unable to update the payment, retrying');
41
48
  retries++;
42
49
  }
43
50
  else {
51
+ this.logger.error({ paymentId: payment.id, paymentVersion: payment.version, retries, err }, 'Unable to update the payment, abort');
44
52
  throw e;
45
53
  }
46
54
  }
@@ -52,7 +60,7 @@ class DefaultPaymentService {
52
60
  if (!payment.interfaceId && updateInfo.pspReference) {
53
61
  actions.push(this.populateSetInterfaceIdAction(updateInfo.pspReference));
54
62
  }
55
- if (!payment.paymentMethodInfo.method && updateInfo.paymentMethod) {
63
+ if (!payment.paymentMethodInfo?.method && updateInfo.paymentMethod) {
56
64
  actions.push(this.populateSetPaymentMethod(updateInfo.paymentMethod));
57
65
  }
58
66
  if (updateInfo.transaction) {
@@ -1,5 +1,3 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
1
  import { Fetcher } from '../types/fetch.type';
4
2
  /**
5
3
  * Basic fetcher implementation
@@ -1,5 +1,3 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
1
  import { ContextProvider, RequestContextData } from '../../api';
4
2
  import { Fetcher } from '../types/fetch.type';
5
3
  /**
@@ -1,5 +1,3 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
1
  export interface Fetcher {
4
2
  run(input: string | URL | globalThis.Request, init?: RequestInit): Promise<Response>;
5
3
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commercetools/connect-payments-sdk",
3
- "version": "0.8.0",
3
+ "version": "0.8.2",
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.27.0",
18
+ "@commercetools-backend/loggers": "22.29.0",
19
19
  "@commercetools/platform-sdk": "7.9.0",
20
20
  "@commercetools/sdk-client-v2": "2.5.0",
21
21
  "jsonwebtoken": "9.0.2",