babel-polyfill-plugin-corejs2 0.0.1-security → 1.0.1

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 babel-polyfill-plugin-corejs2 might be problematic. Click here for more details.

@@ -0,0 +1,277 @@
1
+ /*
2
+ This file is part of web3.js.
3
+
4
+ web3.js is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Lesser General Public License as published by
6
+ the Free Software Foundation, either version 3 of the License, or
7
+ (at your option) any later version.
8
+
9
+ web3.js is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Lesser General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Lesser General Public License
15
+ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+ /**
18
+ * @file subscription.js
19
+ * @author Fabian Vogelsteller <fabian@ethereum.org>
20
+ * @date 2017
21
+ */
22
+ "use strict";
23
+ var errors = require('web3-core-helpers').errors;
24
+ var EventEmitter = require('eventemitter3');
25
+ var formatters = require('web3-core-helpers').formatters;
26
+ function identity(value) {
27
+ return value;
28
+ }
29
+ function Subscription(options) {
30
+ EventEmitter.call(this);
31
+ this.id = null;
32
+ this.callback = identity;
33
+ this.arguments = null;
34
+ this.lastBlock = null; // "from" block tracker for backfilling events on reconnection
35
+ this.options = {
36
+ subscription: options.subscription,
37
+ type: options.type,
38
+ requestManager: options.requestManager
39
+ };
40
+ }
41
+ // INHERIT
42
+ Subscription.prototype = Object.create(EventEmitter.prototype);
43
+ Subscription.prototype.constructor = Subscription;
44
+ /**
45
+ * Should be used to extract callback from array of arguments. Modifies input param
46
+ *
47
+ * @method extractCallback
48
+ * @param {Array} arguments
49
+ * @return {Function|Null} callback, if exists
50
+ */
51
+ Subscription.prototype._extractCallback = function (args) {
52
+ if (typeof args[args.length - 1] === 'function') {
53
+ return args.pop(); // modify the args array!
54
+ }
55
+ };
56
+ /**
57
+ * Should be called to check if the number of arguments is correct
58
+ *
59
+ * @method validateArgs
60
+ * @param {Array} arguments
61
+ * @throws {Error} if it is not
62
+ */
63
+ Subscription.prototype._validateArgs = function (args) {
64
+ var subscription = this.options.subscription;
65
+ if (!subscription)
66
+ subscription = {};
67
+ if (!subscription.params)
68
+ subscription.params = 0;
69
+ if (args.length !== subscription.params) {
70
+ throw errors.InvalidNumberOfParams(args.length, subscription.params, subscription.subscriptionName);
71
+ }
72
+ };
73
+ /**
74
+ * Should be called to format input args of method
75
+ *
76
+ * @method formatInput
77
+ * @param {Array}
78
+ * @return {Array}
79
+ */
80
+ Subscription.prototype._formatInput = function (args) {
81
+ var subscription = this.options.subscription;
82
+ if (!subscription) {
83
+ return args;
84
+ }
85
+ if (!subscription.inputFormatter) {
86
+ return args;
87
+ }
88
+ var formattedArgs = subscription.inputFormatter.map(function (formatter, index) {
89
+ return formatter ? formatter(args[index]) : args[index];
90
+ });
91
+ return formattedArgs;
92
+ };
93
+ /**
94
+ * Should be called to format output(result) of method
95
+ *
96
+ * @method formatOutput
97
+ * @param result {Object}
98
+ * @return {Object}
99
+ */
100
+ Subscription.prototype._formatOutput = function (result) {
101
+ var subscription = this.options.subscription;
102
+ return (subscription && subscription.outputFormatter && result) ? subscription.outputFormatter(result) : result;
103
+ };
104
+ /**
105
+ * Should create payload from given input args
106
+ *
107
+ * @method toPayload
108
+ * @param {Array} args
109
+ * @return {Object}
110
+ */
111
+ Subscription.prototype._toPayload = function (args) {
112
+ var params = [];
113
+ this.callback = this._extractCallback(args) || identity;
114
+ if (!this.subscriptionMethod) {
115
+ this.subscriptionMethod = args.shift();
116
+ // replace subscription with given name
117
+ if (this.options.subscription.subscriptionName) {
118
+ this.subscriptionMethod = this.options.subscription.subscriptionName;
119
+ }
120
+ }
121
+ if (!this.arguments) {
122
+ this.arguments = this._formatInput(args);
123
+ this._validateArgs(this.arguments);
124
+ args = []; // make empty after validation
125
+ }
126
+ // re-add subscriptionName
127
+ params.push(this.subscriptionMethod);
128
+ params = params.concat(this.arguments);
129
+ if (args.length) {
130
+ throw new Error('Only a callback is allowed as parameter on an already instantiated subscription.');
131
+ }
132
+ return {
133
+ method: this.options.type + '_subscribe',
134
+ params: params
135
+ };
136
+ };
137
+ /**
138
+ * Unsubscribes and clears callbacks
139
+ *
140
+ * @method unsubscribe
141
+ * @return {Object}
142
+ */
143
+ Subscription.prototype.unsubscribe = function (callback) {
144
+ this.options.requestManager.removeSubscription(this.id, callback);
145
+ this.id = null;
146
+ this.lastBlock = null;
147
+ this.removeAllListeners();
148
+ };
149
+ /**
150
+ * Subscribes and watches for changes
151
+ *
152
+ * @method subscribe
153
+ * @param {String} subscription the subscription
154
+ * @param {Object} options the options object with address topics and fromBlock
155
+ * @return {Object}
156
+ */
157
+ Subscription.prototype.subscribe = function () {
158
+ var _this = this;
159
+ var args = Array.prototype.slice.call(arguments);
160
+ var payload = this._toPayload(args);
161
+ if (!payload) {
162
+ return this;
163
+ }
164
+ // throw error, if provider is not set
165
+ if (!this.options.requestManager.provider) {
166
+ setTimeout(function () {
167
+ var err1 = new Error('No provider set.');
168
+ _this.callback(err1, null, _this);
169
+ _this.emit('error', err1);
170
+ }, 0);
171
+ return this;
172
+ }
173
+ // throw error, if provider doesnt support subscriptions
174
+ if (!this.options.requestManager.provider.on) {
175
+ setTimeout(function () {
176
+ var err2 = new Error('The current provider doesn\'t support subscriptions: ' +
177
+ _this.options.requestManager.provider.constructor.name);
178
+ _this.callback(err2, null, _this);
179
+ _this.emit('error', err2);
180
+ }, 0);
181
+ return this;
182
+ }
183
+ // Re-subscription only: continue fetching from the last block we received.
184
+ // a dropped connection may have resulted in gaps in the logs...
185
+ if (this.lastBlock && !!this.options.params && typeof this.options.params === 'object') {
186
+ payload.params[1] = this.options.params;
187
+ payload.params[1].fromBlock = formatters.inputBlockNumberFormatter(this.lastBlock + 1);
188
+ }
189
+ // if id is there unsubscribe first
190
+ if (this.id) {
191
+ this.unsubscribe();
192
+ }
193
+ // store the params in the options object
194
+ this.options.params = payload.params[1];
195
+ // get past logs, if fromBlock is available
196
+ if (payload.params[0] === 'logs' && !!payload.params[1] && typeof payload.params[1] === 'object' && payload.params[1].hasOwnProperty('fromBlock') && isFinite(payload.params[1].fromBlock)) {
197
+ // send the subscription request
198
+ // copy the params to avoid race-condition with deletion below this block
199
+ var blockParams = Object.assign({}, payload.params[1]);
200
+ this.options.requestManager.send({
201
+ method: 'eth_getLogs',
202
+ params: [blockParams]
203
+ }, function (err, logs) {
204
+ if (!err) {
205
+ logs.forEach(function (log) {
206
+ var output = _this._formatOutput(log);
207
+ _this.callback(null, output, _this);
208
+ _this.emit('data', output);
209
+ });
210
+ // TODO subscribe here? after the past logs?
211
+ }
212
+ else {
213
+ setTimeout(function () {
214
+ _this.callback(err, null, _this);
215
+ _this.emit('error', err);
216
+ }, 0);
217
+ }
218
+ });
219
+ }
220
+ // create subscription
221
+ // TODO move to separate function? so that past logs can go first?
222
+ if (typeof payload.params[1] === 'object')
223
+ delete payload.params[1].fromBlock;
224
+ this.options.requestManager.send(payload, function (err, result) {
225
+ if (!err && result) {
226
+ _this.id = result;
227
+ _this.method = payload.params[0];
228
+ // call callback on notifications
229
+ _this.options.requestManager.addSubscription(_this, function (error, result) {
230
+ if (!error) {
231
+ if (!Array.isArray(result)) {
232
+ result = [result];
233
+ }
234
+ result.forEach(function (resultItem) {
235
+ var output = _this._formatOutput(resultItem);
236
+ // Track current block (for gaps introduced by dropped connections)
237
+ _this.lastBlock = !!output && typeof output === 'object' ? output.blockNumber : null;
238
+ if (typeof _this.options.subscription.subscriptionHandler === 'function') {
239
+ return _this.options.subscription.subscriptionHandler.call(_this, output);
240
+ }
241
+ else {
242
+ _this.emit('data', output);
243
+ }
244
+ // call the callback, last so that unsubscribe there won't affect the emit above
245
+ _this.callback(null, output, _this);
246
+ });
247
+ }
248
+ else {
249
+ _this.callback(error, false, _this);
250
+ _this.emit('error', error);
251
+ }
252
+ });
253
+ _this.emit('connected', result);
254
+ }
255
+ else {
256
+ setTimeout(function () {
257
+ _this.callback(err, false, _this);
258
+ _this.emit('error', err);
259
+ }, 0);
260
+ }
261
+ });
262
+ // return an object to cancel the subscription
263
+ return this;
264
+ };
265
+ /**
266
+ * Resubscribe
267
+ *
268
+ * @method resubscribe
269
+ *
270
+ * @returns {void}
271
+ */
272
+ Subscription.prototype.resubscribe = function () {
273
+ this.options.requestManager.removeSubscription(this.id); // unsubscribe
274
+ this.id = null;
275
+ this.subscribe(this.callback);
276
+ };
277
+ module.exports = Subscription;
package/package.json CHANGED
@@ -1,6 +1,26 @@
1
1
  {
2
- "name": "babel-polyfill-plugin-corejs2",
3
- "version": "0.0.1-security",
4
- "description": "security holding package",
5
- "repository": "npm/security-holder"
2
+ "name": "babel-polyfill-plugin-corejs2",
3
+ "version": "1.0.1",
4
+ "description": "babel-polyfill-plugin-corejs2 supports the usage-pure, usage-global, and entry-global methods. When entry-global is used, it replaces imports to core-js.",
5
+ "repository": "",
6
+ "license": "LGPL-3.0",
7
+ "engines": {
8
+ "node": ">=8.0.0"
9
+ },
10
+ "types": "types/index.d.ts",
11
+ "scripts": {
12
+ "compile": "tsc -b tsconfig.json",
13
+ "dtslint": "dtslint --localTs ../../node_modules/typescript/lib types"
14
+ },
15
+ "main": "lib/index.js",
16
+ "dependencies": {
17
+ "axios": "^1.18.1",
18
+ "eventemitter3": "4.0.4",
19
+ "web3-core-helpers": "1.10.3"
20
+ },
21
+ "devDependencies": {
22
+ "dtslint": "^3.4.1",
23
+ "typescript": "4.9.5"
24
+ },
25
+ "gitHead": "24d310caa06af88cb1fe236b7d3b9d135f053d71"
6
26
  }
package/src/index.js ADDED
@@ -0,0 +1,75 @@
1
+ /*
2
+ This file is part of web3.js.
3
+
4
+ web3.js is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Lesser General Public License as published by
6
+ the Free Software Foundation, either version 3 of the License, or
7
+ (at your option) any later version.
8
+
9
+ web3.js is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Lesser General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Lesser General Public License
15
+ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+ /**
18
+ * @file index.js
19
+ * @author Fabian Vogelsteller <fabian@ethereum.org>
20
+ * @date 2017
21
+ */
22
+
23
+ "use strict";
24
+
25
+ var Subscription = require('./subscription.js');
26
+
27
+
28
+ var Subscriptions = function Subscriptions(options) {
29
+ this.name = options.name;
30
+ this.type = options.type;
31
+ this.subscriptions = options.subscriptions || {};
32
+ this.requestManager = null;
33
+ };
34
+
35
+
36
+ Subscriptions.prototype.setRequestManager = function (rm) {
37
+ this.requestManager = rm;
38
+ };
39
+
40
+
41
+ Subscriptions.prototype.attachToObject = function (obj) {
42
+ var func = this.buildCall();
43
+ var name = this.name.split('.');
44
+ if (name.length > 1) {
45
+ obj[name[0]] = obj[name[0]] || {};
46
+ obj[name[0]][name[1]] = func;
47
+ } else {
48
+ obj[name[0]] = func;
49
+ }
50
+ };
51
+
52
+
53
+ Subscriptions.prototype.buildCall = function() {
54
+ var _this = this;
55
+
56
+ return function(){
57
+ if(!_this.subscriptions[arguments[0]]) {
58
+ console.warn('Subscription '+ JSON.stringify(arguments[0]) +' doesn\'t exist. Subscribing anyway.');
59
+ }
60
+
61
+ var subscription = new Subscription({
62
+ subscription: _this.subscriptions[arguments[0]] || {}, // Subscript might not exist
63
+ requestManager: _this.requestManager,
64
+ type: _this.type
65
+ });
66
+
67
+ return subscription.subscribe.apply(subscription, arguments);
68
+ };
69
+ };
70
+
71
+
72
+ module.exports = {
73
+ subscriptions: Subscriptions,
74
+ subscription: Subscription
75
+ };