Socket
Socket
Sign inDemoInstall

@commercetools/connect-payments-sdk

Package Overview
Dependencies
Maintainers
12
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@commercetools/connect-payments-sdk - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

dist/api/hooks/jwt-auth.hook.d.ts

6

CHANGELOG.md
# @commercetools/connect-payments-sdk
## 0.0.4
### Patch Changes
- ab6200f: Support jwt, oauth2 authentication and support for authority based authorization
## 0.0.3

@@ -4,0 +10,0 @@

2

dist/api/handlers/config.handler.d.ts
import { HandlerResponse } from './types/handler.type';
export declare const configHandler: (options: {
configuration: () => Promise<object> | object;
}) => () => Promise<HandlerResponse>;
}) => () => Promise<HandlerResponse<object>>;
import { CommercetoolsAuthorizationService } from '../../commercetools';
import { HandlerResponse } from './types/handler.type';
type HealthCheckStatus = {
status: 'OK' | 'Partially Available' | 'Unavailable';
timestamp: string;
checks: HealthCheckResult[];
version: string;
metadata?: object;
};
export type HealthCheckResult = {

@@ -13,3 +20,3 @@ name: string;

metadataFn?: () => Promise<object> | object;
}) => () => Promise<HandlerResponse>;
}) => () => Promise<HandlerResponse<HealthCheckStatus>>;
/**

@@ -25,1 +32,2 @@ * Check if CoCo permissions are available

}) => () => Promise<HealthCheckResult>;
export {};

@@ -1,5 +0,5 @@

export type HandlerResponse = {
export type HandlerResponse<T> = {
status: number;
body?: object;
body: T;
headers?: object;
};

@@ -8,1 +8,4 @@ /// <reference types="node" />

}
export interface AuthorizationHook {
authorize(...authorities: string[]): () => Promise<void>;
}

@@ -5,3 +5,5 @@ export * from './context/request-context.provider';

export * from './handlers/status.handler';
export * from './hooks/jwt-auth.hook';
export * from './hooks/oauth2-auth.hook';
export * from './hooks/session-auth.hook';
export * from './hooks/types/hook.type';

@@ -21,3 +21,5 @@ "use strict";

__exportStar(require("./handlers/status.handler"), exports);
__exportStar(require("./hooks/jwt-auth.hook"), exports);
__exportStar(require("./hooks/oauth2-auth.hook"), exports);
__exportStar(require("./hooks/session-auth.hook"), exports);
__exportStar(require("./hooks/types/hook.type"), exports);

@@ -47,3 +47,3 @@ export type ErrorxAdditionalOpts = {

export declare class ErrorAuthErrorResponse extends Errorx {
constructor(additionalOpts?: ErrorxAdditionalOpts);
constructor(message?: string, additionalOpts?: ErrorxAdditionalOpts, code?: string);
}

@@ -50,0 +50,0 @@ /**

@@ -62,7 +62,7 @@ "use strict";

class ErrorAuthErrorResponse extends Errorx {
constructor(additionalOpts) {
constructor(message, additionalOpts, code) {
super({
code: 'AuthErrorResponse',
code: code || 'invalid_token',
httpErrorStatus: 401,
message: 'Authentication error.',
message: message || 'Authentication error.',
...additionalOpts,

@@ -69,0 +69,0 @@ });

@@ -1,6 +0,6 @@

import { RequestContextData, RequestContextProvider, SessionAuthenticationHook } from './api';
import { JWTAuthenticationHook, Oauth2AuthenticationHook, RequestContextData, RequestContextProvider, SessionAuthenticationHook } from './api';
import { DefaultCommercetoolsAPI } from './commercetools/api/root-api';
import { DefaultAuthorizationService } from './commercetools/services/ct-authorization.service';
import { DefaultCartService } from './commercetools/services/ct-cart.service';
import { DefaultPaymentService } from './commercetools/services/ct-payment.service';
import { DefaultAuthorizationService } from './commercetools/services/ct-authorization.service';
import { Logger } from './logger';

@@ -16,5 +16,7 @@ export * from './api';

sessionUrl: string;
jwksUrl: string;
clientId: string;
clientSecret: string;
projectKey: string;
jwtIssuer: string;
getContextFn: () => RequestContextData;

@@ -30,2 +32,4 @@ updateContextFn: (ctx: Partial<RequestContextData>) => void;

sessionAuthHookFn: SessionAuthenticationHook;
jwtAuthHookFn: JWTAuthenticationHook;
oauth2AuthHookFn: Oauth2AuthenticationHook;
};

@@ -20,5 +20,5 @@ "use strict";

const root_api_1 = require("./commercetools/api/root-api");
const ct_authorization_service_1 = require("./commercetools/services/ct-authorization.service");
const ct_cart_service_1 = require("./commercetools/services/ct-cart.service");
const ct_payment_service_1 = require("./commercetools/services/ct-payment.service");
const ct_authorization_service_1 = require("./commercetools/services/ct-authorization.service");
const ct_session_service_1 = require("./commercetools/services/ct-session.service");

@@ -61,5 +61,19 @@ const base_decorator_1 = require("./fetch/decorators/base.decorator");

});
const oauth2Service = new security_1.DefaultOauth2Service();
const jwtService = new security_1.DefaultJWTService({
jwksUrl: opts.jwksUrl,
});
const sessionAuthenticationManager = new security_1.SessionAuthenticationManager({
sessionService,
});
const oauth2AuthenticationManager = new security_1.Oauth2AuthenticationManager({
oauth2Service,
clientId: opts.clientId,
clientSecret: opts.clientSecret,
authUrl: opts.authUrl,
});
const jwtAuthenticationManager = new security_1.JWTAuthenticationManager({
jwtService,
iss: opts.jwtIssuer,
});
const sessionAuthHookFn = new api_1.SessionAuthenticationHook({

@@ -69,2 +83,10 @@ authenticationManager: sessionAuthenticationManager,

});
const jwtAuthHookFn = new api_1.JWTAuthenticationHook({
authenticationManager: jwtAuthenticationManager,
contextProvider,
});
const oauth2AuthHookFn = new api_1.Oauth2AuthenticationHook({
authenticationManager: oauth2AuthenticationManager,
contextProvider,
});
return {

@@ -77,4 +99,6 @@ ctAPI,

sessionAuthHookFn,
jwtAuthHookFn,
oauth2AuthHookFn,
};
};
exports.setupPaymentSDK = setupPaymentSDK;

@@ -1,2 +0,2 @@

import { Authentication, HeaderPrincipal, SessionPrincipal } from './types/authn.type';
import { Authentication, HeaderPrincipal, JWTPrincipal, Oauth2Principal, SessionPrincipal } from './types/authn.type';
export declare class SessionAuthentication implements Authentication<SessionPrincipal, string> {

@@ -25,1 +25,26 @@ private principal;

}
export declare class Oauth2Authentication implements Authentication<Oauth2Principal, string> {
private principal;
private authorities;
private authenticated;
private accessToken;
constructor(accessToken: string, principal: Oauth2Principal);
hasPrincipal(): boolean;
getAuthorities(): string[];
hasCredentials(): boolean;
getPrincipal(): Oauth2Principal;
getCredentials(): string;
isAuthenticated(): boolean;
}
export declare class JWTAuthentication implements Authentication<JWTPrincipal, string> {
private principal;
private authenticated;
private jwt;
constructor(jwt: string, principal: JWTPrincipal);
hasPrincipal(): boolean;
getAuthorities(): string[];
hasCredentials(): boolean;
getPrincipal(): JWTPrincipal;
getCredentials(): string;
isAuthenticated(): boolean;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.HeaderBasedAuthentication = exports.SessionAuthentication = void 0;
exports.JWTAuthentication = exports.Oauth2Authentication = exports.HeaderBasedAuthentication = exports.SessionAuthentication = void 0;
class SessionAuthentication {

@@ -61,1 +61,64 @@ principal;

exports.HeaderBasedAuthentication = HeaderBasedAuthentication;
class Oauth2Authentication {
principal;
authorities;
authenticated;
accessToken;
constructor(accessToken, principal) {
this.principal = principal;
this.authorities = principal.scope
.split(' ')
.map((scope) => scope.split(':')[0])
.filter((scope) => scope !== '');
this.authenticated = true;
this.accessToken = accessToken;
}
hasPrincipal() {
return this.getPrincipal() !== undefined;
}
getAuthorities() {
return this.authorities;
}
hasCredentials() {
return this.getCredentials() !== undefined;
}
getPrincipal() {
return this.principal;
}
getCredentials() {
return this.accessToken;
}
isAuthenticated() {
return this.authenticated;
}
}
exports.Oauth2Authentication = Oauth2Authentication;
class JWTAuthentication {
principal;
authenticated;
jwt;
constructor(jwt, principal) {
this.principal = principal;
this.authenticated = true;
this.jwt = jwt;
}
hasPrincipal() {
return this.getPrincipal() !== undefined;
}
getAuthorities() {
return [];
}
hasCredentials() {
return this.getCredentials() !== undefined;
}
getPrincipal() {
return this.principal;
}
getCredentials() {
return this.jwt;
}
isAuthenticated() {
return this.authenticated;
}
}
exports.JWTAuthentication = JWTAuthentication;

@@ -21,3 +21,3 @@ "use strict";

catch (e) {
throw new errorx_1.ErrorAuthErrorResponse();
throw new errorx_1.ErrorAuthErrorResponse('Session is not active');
}

@@ -24,0 +24,0 @@ }

@@ -12,2 +12,5 @@ export interface AuthenticationManager {

}
export type HeaderPrincipal = {
authHeader: string;
};
export type SessionPrincipal = {

@@ -17,4 +20,10 @@ cartId: string;

};
export type HeaderPrincipal = {
authHeader: string;
export type Oauth2Principal = {
clientId: string;
scope: string;
customerId?: string;
anonymousId?: string;
};
export type JWTPrincipal = {
mcCustomerId?: string;
};

@@ -1,3 +0,7 @@

export * from './authn/types/authn.type';
export * from './authn/authns';
export * from './authn/jwt-authn-manager';
export * from './authn/oauth2-authn-manager';
export * from './authn/session-authn-manager';
export * from './authn/types/authn.type';
export * from './services/jwt.service';
export * from './services/oauth2.service';

@@ -17,4 +17,8 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./authn/types/authn.type"), exports);
__exportStar(require("./authn/authns"), exports);
__exportStar(require("./authn/jwt-authn-manager"), exports);
__exportStar(require("./authn/oauth2-authn-manager"), exports);
__exportStar(require("./authn/session-authn-manager"), exports);
__exportStar(require("./authn/types/authn.type"), exports);
__exportStar(require("./services/jwt.service"), exports);
__exportStar(require("./services/oauth2.service"), exports);
{
"name": "@commercetools/connect-payments-sdk",
"version": "0.0.3",
"version": "0.0.4",
"description": "Payment SDK for commercetools payment connectors",

@@ -19,4 +19,6 @@ "main": "dist/index.js",

"@commercetools/platform-sdk": "7.2.0-alpha.4",
"@commercetools/sdk-client-v2": "2.3.0"
"@commercetools/sdk-client-v2": "2.3.0",
"jsonwebtoken": "9.0.2",
"jwks-rsa": "3.1.0"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc