@felloh-org/lambda-wrapper 1.1.43 → 1.1.46
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.
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = exports.Dependencies = exports.DEFINITIONS = void 0;
|
|
7
7
|
|
|
8
|
+
var _authentication = _interopRequireDefault(require("../service/authentication"));
|
|
9
|
+
|
|
8
10
|
var _eventBridge = _interopRequireDefault(require("../service/event-bridge"));
|
|
9
11
|
|
|
10
12
|
var _http = _interopRequireDefault(require("../service/http"));
|
|
@@ -18,6 +20,7 @@ var _warehouse = _interopRequireDefault(require("../service/warehouse"));
|
|
|
18
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
21
|
|
|
20
22
|
const DEFINITIONS = {
|
|
23
|
+
AUTHENTICATION: 'AUTHENTICATION',
|
|
21
24
|
EVENT_BRIDGE: 'EVENT_BRIDGE',
|
|
22
25
|
HTTP: 'HTTP',
|
|
23
26
|
LOGGER: 'LOGGER',
|
|
@@ -30,7 +33,8 @@ const Dependencies = {
|
|
|
30
33
|
[DEFINITIONS.HTTP]: _http.default,
|
|
31
34
|
[DEFINITIONS.LOGGER]: _logger.default,
|
|
32
35
|
[DEFINITIONS.REQUEST]: _request.default,
|
|
33
|
-
[DEFINITIONS.WAREHOUSE]: _warehouse.default
|
|
36
|
+
[DEFINITIONS.WAREHOUSE]: _warehouse.default,
|
|
37
|
+
[DEFINITIONS.AUTHENTICATION]: _authentication.default
|
|
34
38
|
};
|
|
35
39
|
exports.Dependencies = Dependencies;
|
|
36
40
|
var _default = {
|
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default = void 0;
|
|
6
|
+
exports.default = exports.PAYMENT_METHOD = void 0;
|
|
7
7
|
|
|
8
8
|
var _typeorm = require("typeorm");
|
|
9
9
|
|
|
10
10
|
var _uuid = require("uuid");
|
|
11
11
|
|
|
12
|
-
var _dec, _dec2, _dec3, _dec4, _dec5, _class, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4;
|
|
12
|
+
var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _class, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5;
|
|
13
13
|
|
|
14
14
|
function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }
|
|
15
15
|
|
|
@@ -17,25 +17,34 @@ function _applyDecoratedDescriptor(target, property, decorators, descriptor, con
|
|
|
17
17
|
|
|
18
18
|
function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'proposal-class-properties is enabled and runs after the decorators transform.'); }
|
|
19
19
|
|
|
20
|
+
const PAYMENT_METHOD = {
|
|
21
|
+
CARD: 'CARD',
|
|
22
|
+
OPEN_BANKING: 'OPEN_BANKING'
|
|
23
|
+
};
|
|
24
|
+
exports.PAYMENT_METHOD = PAYMENT_METHOD;
|
|
20
25
|
let PaymentProvider = (_dec = (0, _typeorm.Entity)({
|
|
21
26
|
name: 'payment_provider',
|
|
22
27
|
schema: 'payment'
|
|
23
28
|
}), _dec2 = (0, _typeorm.PrimaryColumn)("varchar"), _dec3 = (0, _typeorm.Column)({
|
|
24
29
|
type: "varchar",
|
|
25
|
-
length: "150"
|
|
26
|
-
nullable: true
|
|
30
|
+
length: "150"
|
|
27
31
|
}), _dec4 = (0, _typeorm.Column)({
|
|
32
|
+
type: "varchar",
|
|
33
|
+
length: "20"
|
|
34
|
+
}), _dec5 = (0, _typeorm.Column)({
|
|
28
35
|
type: "boolean",
|
|
29
36
|
default: false
|
|
30
|
-
}),
|
|
37
|
+
}), _dec6 = (0, _typeorm.CreateDateColumn)(), _dec(_class = (_class2 = class PaymentProvider {
|
|
31
38
|
constructor() {
|
|
32
39
|
_initializerDefineProperty(this, "id", _descriptor, this);
|
|
33
40
|
|
|
34
41
|
_initializerDefineProperty(this, "name", _descriptor2, this);
|
|
35
42
|
|
|
36
|
-
_initializerDefineProperty(this, "
|
|
43
|
+
_initializerDefineProperty(this, "payment_method", _descriptor3, this);
|
|
44
|
+
|
|
45
|
+
_initializerDefineProperty(this, "is_active", _descriptor4, this);
|
|
37
46
|
|
|
38
|
-
_initializerDefineProperty(this, "created_at",
|
|
47
|
+
_initializerDefineProperty(this, "created_at", _descriptor5, this);
|
|
39
48
|
}
|
|
40
49
|
|
|
41
50
|
}, (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "id", [_dec2], {
|
|
@@ -52,14 +61,21 @@ let PaymentProvider = (_dec = (0, _typeorm.Entity)({
|
|
|
52
61
|
initializer: function () {
|
|
53
62
|
return "";
|
|
54
63
|
}
|
|
55
|
-
}), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "
|
|
64
|
+
}), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "payment_method", [_dec4], {
|
|
65
|
+
configurable: true,
|
|
66
|
+
enumerable: true,
|
|
67
|
+
writable: true,
|
|
68
|
+
initializer: function () {
|
|
69
|
+
return "";
|
|
70
|
+
}
|
|
71
|
+
}), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "is_active", [_dec5], {
|
|
56
72
|
configurable: true,
|
|
57
73
|
enumerable: true,
|
|
58
74
|
writable: true,
|
|
59
75
|
initializer: function () {
|
|
60
76
|
return false;
|
|
61
77
|
}
|
|
62
|
-
}),
|
|
78
|
+
}), _descriptor5 = _applyDecoratedDescriptor(_class2.prototype, "created_at", [_dec6], {
|
|
63
79
|
configurable: true,
|
|
64
80
|
enumerable: true,
|
|
65
81
|
writable: true,
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const { MigrationInterface, QueryRunner } = require("typeorm");
|
|
2
|
+
|
|
3
|
+
module.exports = class paymentProviderPaymentMethod1658483667045 {
|
|
4
|
+
name = 'paymentProviderPaymentMethod1658483667045'
|
|
5
|
+
|
|
6
|
+
async up(queryRunner) {
|
|
7
|
+
await queryRunner.query(`ALTER TABLE "payment"."payment_provider" ADD "payment_method" character varying(20) NOT NULL DEFAULT 'UNKNOWN'`);
|
|
8
|
+
await queryRunner.query(`ALTER TABLE "payment"."payment_provider" ALTER COLUMN "name" SET NOT NULL`);
|
|
9
|
+
await queryRunner.query(`UPDATE "payment"."payment_provider" SET "payment_method" = 'CARD' WHERE "name" = 'TOTAL_PROCESSING'`);
|
|
10
|
+
await queryRunner.query(`UPDATE "payment"."payment_provider" SET "payment_method" = 'OPEN_BANKING' WHERE "name" = 'NUAPAY'`);
|
|
11
|
+
await queryRunner.query(`UPDATE "payment"."payment_provider" SET "payment_method" = 'CARD' WHERE "name" = 'NUVEI'`);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async down(queryRunner) {
|
|
15
|
+
await queryRunner.query(`ALTER TABLE "payment"."payment_provider" ALTER COLUMN "name" DROP NOT NULL`);
|
|
16
|
+
await queryRunner.query(`ALTER TABLE "payment"."payment_provider" DROP COLUMN "payment_method"`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _dependencies = require("../config/dependencies");
|
|
9
|
+
|
|
10
|
+
var _dependencyAware = _interopRequireDefault(require("../dependency-injection/dependency-aware"));
|
|
11
|
+
|
|
12
|
+
var _organisation = _interopRequireDefault(require("../entity/user/organisation"));
|
|
13
|
+
|
|
14
|
+
var _userRole = _interopRequireDefault(require("../entity/user/user-role"));
|
|
15
|
+
|
|
16
|
+
var _response = _interopRequireDefault(require("../model/response"));
|
|
17
|
+
|
|
18
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
+
|
|
20
|
+
// eslint-disable-next-line import/no-named-as-default,import/no-named-as-default-member
|
|
21
|
+
// eslint-disable-next-line import/no-named-as-default,import/no-named-as-default-member
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Authentication Service class
|
|
25
|
+
*/
|
|
26
|
+
class AuthenticationService extends _dependencyAware.default {
|
|
27
|
+
constructor(di) {
|
|
28
|
+
super(di);
|
|
29
|
+
this.initialised = false;
|
|
30
|
+
const that = this;
|
|
31
|
+
|
|
32
|
+
this.initialise = async () => {
|
|
33
|
+
if (that.initialised === false) {
|
|
34
|
+
const warehouse = di.get(_dependencies.DEFINITIONS.WAREHOUSE);
|
|
35
|
+
that.connection = await warehouse.connect();
|
|
36
|
+
this.initialised = true;
|
|
37
|
+
this.userRoleRepository = await that.connection.getRepository(_userRole.default);
|
|
38
|
+
this.organisationRepository = await that.connection.getRepository(_organisation.default);
|
|
39
|
+
this.user = JSON.parse(di.getEvent().requestContext.authorizer.user);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Fetch a users organisations
|
|
45
|
+
* @param user
|
|
46
|
+
* @returns {Promise<*[]>}
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
async fetchUserOrganisations(user) {
|
|
51
|
+
await this.initialise();
|
|
52
|
+
const response = [];
|
|
53
|
+
|
|
54
|
+
for await (const organisation of user.organisations) {
|
|
55
|
+
const orgs = await this.organisationRepository.findDescendants(organisation, {
|
|
56
|
+
relations: ['parent']
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
for (const org of orgs) {
|
|
60
|
+
response.push(org);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return response;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Check user role and organisation access
|
|
68
|
+
* @param organisationID
|
|
69
|
+
* @param roles
|
|
70
|
+
* @returns {Promise<boolean>}
|
|
71
|
+
*/
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
async checkUserRoles(organisationID = null, roles = []) {
|
|
75
|
+
await this.initialise(); // If the organisation is not null, then check the user organisation permissions
|
|
76
|
+
|
|
77
|
+
if (organisationID !== null) {
|
|
78
|
+
// Fetch the users organisations that they have access to
|
|
79
|
+
const organisations = await this.fetchUserOrganisations(this.user); // Loop through the organisations and try to find
|
|
80
|
+
|
|
81
|
+
let organisationFound = false;
|
|
82
|
+
|
|
83
|
+
for (const organisationEntity of organisations) {
|
|
84
|
+
if (organisationEntity.id === organisationID) {
|
|
85
|
+
organisationFound = true;
|
|
86
|
+
}
|
|
87
|
+
} // Throw an error if the user does not have the organisation
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
if (organisationFound === false) {
|
|
91
|
+
const notFoundResponse = new _response.default(null, 401);
|
|
92
|
+
notFoundResponse.addError({
|
|
93
|
+
title: 'Unauthorized',
|
|
94
|
+
message: 'You do not have sufficient privileges to access data for this organisation',
|
|
95
|
+
documentation_url: 'https://developers.felloh.com/errors#error-responses',
|
|
96
|
+
type: 'unauthorized',
|
|
97
|
+
code: 'unauthorized.organisation'
|
|
98
|
+
});
|
|
99
|
+
throw notFoundResponse;
|
|
100
|
+
}
|
|
101
|
+
} // If the roles are not null, then check the users roles
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
if (roles.length >= 1) {
|
|
105
|
+
// Fetch the users assigned roles
|
|
106
|
+
const userRoles = await this.userRoleRepository.createQueryBuilder('user_roles').leftJoinAndSelect('user_roles.role', 'role').where('user_id = :userID', {
|
|
107
|
+
userID: this.user.id
|
|
108
|
+
}).getMany(); // Loop through the roles and determine match count
|
|
109
|
+
|
|
110
|
+
let roleCount = 0;
|
|
111
|
+
|
|
112
|
+
for (const userRole of userRoles) {
|
|
113
|
+
if (roles.indexOf(userRole.role.machine_name) !== -1) {
|
|
114
|
+
roleCount += 1;
|
|
115
|
+
}
|
|
116
|
+
} // Throw an error if the user does not have all the roles
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
if (roleCount !== roles.length) {
|
|
120
|
+
const notFoundResponse = new _response.default(null, 401);
|
|
121
|
+
notFoundResponse.addError({
|
|
122
|
+
title: 'Unauthorized',
|
|
123
|
+
message: 'You do not have sufficient privileges to be able to facilitate this request',
|
|
124
|
+
documentation_url: 'https://developers.felloh.com/errors#error-responses',
|
|
125
|
+
type: 'unauthorized',
|
|
126
|
+
code: 'unauthorized.roles'
|
|
127
|
+
});
|
|
128
|
+
throw notFoundResponse;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
exports.default = AuthenticationService;
|