Socket
Socket
Sign inDemoInstall

@crowdrz/crowdrz-js

Package Overview
Dependencies
56
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.3.0 to 3.0.0

index.ts

11

demo/demo.js

@@ -1,4 +0,4 @@

const Crowdrz = require('../lib/crowdrz');
const Crowdrz = require('../built/crowdrz')
const apiKey = '<api key>';
const apiKey = '<api key>'

@@ -9,3 +9,6 @@ const getMeDemo = async () => {

const me = await facebook.call('GET', '/me')
const me2 = await facebook.setMethod('GET').setEndpoint('/me').call()
const me2 = await facebook
.setMethod('GET')
.setEndpoint('/me')
.call()
const me3 = await facebook.setEndpoint('/me').get()

@@ -15,2 +18,2 @@ console.log(me, me2, me3)

getMeDemo()
getMeDemo()
'use strict'
const servicesList = require('./services')
class Crowdrz {
constructor(provider = '', apiToken = '', apiVersion = '5.0') {
var __assign =
(this && this.__assign) ||
function() {
__assign =
Object.assign ||
function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i]
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]
}
return t
}
return __assign.apply(this, arguments)
}
var __awaiter =
(this && this.__awaiter) ||
function(thisArg, _arguments, P, generator) {
function adopt(value) {
return value instanceof P
? value
: new P(function(resolve) {
resolve(value)
})
}
return new (P || (P = Promise))(function(resolve, reject) {
function fulfilled(value) {
try {
step(generator.next(value))
} catch (e) {
reject(e)
}
}
function rejected(value) {
try {
step(generator['throw'](value))
} catch (e) {
reject(e)
}
}
function step(result) {
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected)
}
step((generator = generator.apply(thisArg, _arguments || [])).next())
})
}
var __generator =
(this && this.__generator) ||
function(thisArg, body) {
var _ = {
label: 0,
sent: function() {
if (t[0] & 1) throw t[1]
return t[1]
},
trys: [],
ops: []
},
f,
y,
t,
g
return (
(g = {next: verb(0), throw: verb(1), return: verb(2)}),
typeof Symbol === 'function' &&
(g[Symbol.iterator] = function() {
return this
}),
g
)
function verb(n) {
return function(v) {
return step([n, v])
}
}
function step(op) {
if (f) throw new TypeError('Generator is already executing.')
while (_)
try {
if (
((f = 1), y && (t = op[0] & 2 ? y['return'] : op[0] ? y['throw'] || ((t = y['return']) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
)
return t
if (((y = 0), t)) op = [op[0] & 2, t.value]
switch (op[0]) {
case 0:
case 1:
t = op
break
case 4:
_.label++
return {value: op[1], done: false}
case 5:
_.label++
y = op[1]
op = [0]
continue
case 7:
op = _.ops.pop()
_.trys.pop()
continue
default:
if (!((t = _.trys), (t = t.length > 0 && t[t.length - 1])) && (op[0] === 6 || op[0] === 2)) {
_ = 0
continue
}
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
_.label = op[1]
break
}
if (op[0] === 6 && _.label < t[1]) {
_.label = t[1]
t = op
break
}
if (t && _.label < t[2]) {
_.label = t[2]
_.ops.push(op)
break
}
if (t[2]) _.ops.pop()
_.trys.pop()
continue
}
op = body.call(thisArg, _)
} catch (e) {
op = [6, e]
y = 0
} finally {
f = t = 0
}
if (op[0] & 5) throw op[1]
return {value: op[0] ? op[1] : void 0, done: true}
}
}
Object.defineProperty(exports, '__esModule', {value: true})
exports.Crowdrz = void 0
var services_1 = require('./services')
var Crowdrz = /** @class */ (function() {
function Crowdrz(provider, apiToken, apiVersion) {
if (apiVersion === void 0) {
apiVersion = '5.0'
}
this.provider = provider
this.apiToken = apiToken
this.apiVersion = apiVersion
this._resetQuery()

@@ -11,34 +152,26 @@ this.provider = provider

this.debug = false
this.request = {}
}
// Private method
_resetQuery() {
Crowdrz.prototype._resetQuery = function() {
this.request = {
method: 'GET',
endpoint: null,
endpoint: '',
params: {}
}
}
_resetQueryElem(elem) {
this[elem] = null
}
// Setter
setProvider(provider) {
Crowdrz.prototype.setProvider = function(provider) {
this.provider = provider
return this
}
setDebug(debug) {
Crowdrz.prototype.setDebug = function(debug) {
this.debug = debug
return this
}
setApiVersion(version) {
Crowdrz.prototype.setApiVersion = function(version) {
this.apiVersion = version
return this
}
setToken(token) {
Crowdrz.prototype.setToken = function(token) {
if (token) {

@@ -49,4 +182,3 @@ this.apiToken = token

}
setMethod(method) {
Crowdrz.prototype.setMethod = function(method) {
if (method) {

@@ -57,4 +189,3 @@ this.request.method = method

}
setEndpoint(endpoint) {
Crowdrz.prototype.setEndpoint = function(endpoint) {
if (endpoint) {

@@ -65,4 +196,3 @@ this.request.endpoint = endpoint

}
setParams(params) {
Crowdrz.prototype.setParams = function(params) {
if (params) {

@@ -73,43 +203,89 @@ this.request.params = params

}
// Core
async call(method, endpoint, params) {
params = JSON.parse(JSON.stringify(params)) // Clone given object to avoid reference being updated during crowdrz call
let data = null
this.setMethod(method).setEndpoint(endpoint).setParams(params)
if (this.debug) {
console.log(method, endpoint, params, '\n')
}
try {
data = await servicesList[this.provider].getData({apiVersion: this.apiVersion, apiToken: this.apiToken, ...this.request})
} catch (error) {
if (this.debug) {
console.log(error.message, '\n')
}
throw error
} finally {
this._resetQuery()
}
return data
Crowdrz.prototype.call = function(method, endpoint, params) {
return __awaiter(this, void 0, void 0, function() {
var data, error_1
return __generator(this, function(_a) {
switch (_a.label) {
case 0:
params = JSON.parse(JSON.stringify(params)) // Clone given object to avoid reference being updated during crowdrz call
data = null
this.setMethod(method)
.setEndpoint(endpoint)
.setParams(params)
if (this.debug) {
console.log(method, endpoint, params, '\n')
}
_a.label = 1
case 1:
_a.trys.push([1, 3, 4, 5])
return [4 /*yield*/, services_1.servicesList[this.provider].getData(__assign({apiVersion: this.apiVersion, apiToken: this.apiToken}, this.request))]
case 2:
data = _a.sent()
return [3 /*break*/, 5]
case 3:
error_1 = _a.sent()
if (this.debug) {
console.log(error_1.message, '\n')
}
throw error_1
case 4:
this._resetQuery()
return [7 /*endfinally*/]
case 5:
return [2 /*return*/, data]
}
})
})
}
async get(endpoint, params) {
return await this.call('GET', endpoint, params)
Crowdrz.prototype.get = function(endpoint, params) {
return __awaiter(this, void 0, void 0, function() {
return __generator(this, function(_a) {
switch (_a.label) {
case 0:
return [4 /*yield*/, this.call('GET', endpoint, params)]
case 1:
return [2 /*return*/, _a.sent()]
}
})
})
}
async post(endpoint, params) {
return await this.call('POST', endpoint, params)
Crowdrz.prototype.post = function(endpoint, params) {
return __awaiter(this, void 0, void 0, function() {
return __generator(this, function(_a) {
switch (_a.label) {
case 0:
return [4 /*yield*/, this.call('POST', endpoint, params)]
case 1:
return [2 /*return*/, _a.sent()]
}
})
})
}
async put(endpoint, params) {
return await this.call('PUT', endpoint, params)
Crowdrz.prototype.put = function(endpoint, params) {
return __awaiter(this, void 0, void 0, function() {
return __generator(this, function(_a) {
switch (_a.label) {
case 0:
return [4 /*yield*/, this.call('PUT', endpoint, params)]
case 1:
return [2 /*return*/, _a.sent()]
}
})
})
}
async delete(endpoint, params) {
return await this.call('DELETE', endpoint, params)
Crowdrz.prototype.delete = function(endpoint, params) {
return __awaiter(this, void 0, void 0, function() {
return __generator(this, function(_a) {
switch (_a.label) {
case 0:
return [4 /*yield*/, this.call('DELETE', endpoint, params)]
case 1:
return [2 /*return*/, _a.sent()]
}
})
})
}
}
module.exports = Crowdrz
return Crowdrz
})()
exports.Crowdrz = Crowdrz
'use strict'
const FB = require('fb').default
const _checkParams = (request) => {
var __awaiter =
(this && this.__awaiter) ||
function(thisArg, _arguments, P, generator) {
function adopt(value) {
return value instanceof P
? value
: new P(function(resolve) {
resolve(value)
})
}
return new (P || (P = Promise))(function(resolve, reject) {
function fulfilled(value) {
try {
step(generator.next(value))
} catch (e) {
reject(e)
}
}
function rejected(value) {
try {
step(generator['throw'](value))
} catch (e) {
reject(e)
}
}
function step(result) {
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected)
}
step((generator = generator.apply(thisArg, _arguments || [])).next())
})
}
var __generator =
(this && this.__generator) ||
function(thisArg, body) {
var _ = {
label: 0,
sent: function() {
if (t[0] & 1) throw t[1]
return t[1]
},
trys: [],
ops: []
},
f,
y,
t,
g
return (
(g = {next: verb(0), throw: verb(1), return: verb(2)}),
typeof Symbol === 'function' &&
(g[Symbol.iterator] = function() {
return this
}),
g
)
function verb(n) {
return function(v) {
return step([n, v])
}
}
function step(op) {
if (f) throw new TypeError('Generator is already executing.')
while (_)
try {
if (
((f = 1), y && (t = op[0] & 2 ? y['return'] : op[0] ? y['throw'] || ((t = y['return']) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
)
return t
if (((y = 0), t)) op = [op[0] & 2, t.value]
switch (op[0]) {
case 0:
case 1:
t = op
break
case 4:
_.label++
return {value: op[1], done: false}
case 5:
_.label++
y = op[1]
op = [0]
continue
case 7:
op = _.ops.pop()
_.trys.pop()
continue
default:
if (!((t = _.trys), (t = t.length > 0 && t[t.length - 1])) && (op[0] === 6 || op[0] === 2)) {
_ = 0
continue
}
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
_.label = op[1]
break
}
if (op[0] === 6 && _.label < t[1]) {
_.label = t[1]
t = op
break
}
if (t && _.label < t[2]) {
_.label = t[2]
_.ops.push(op)
break
}
if (t[2]) _.ops.pop()
_.trys.pop()
continue
}
op = body.call(thisArg, _)
} catch (e) {
op = [6, e]
y = 0
} finally {
f = t = 0
}
if (op[0] & 5) throw op[1]
return {value: op[0] ? op[1] : void 0, done: true}
}
}
Object.defineProperty(exports, '__esModule', {value: true})
exports.getData = void 0
var FB = require('fb')
var _checkParams = function(request) {
if (!(request.apiToken && request.method && request.endpoint && request.apiVersion)) {

@@ -11,47 +131,65 @@ return false

}
const getData = async (request, _accumulator = [], totalLimit = null) => {
// Check param validity
if (!_checkParams(request)) {
throw new Error('Api Token, Method and endpoint are required')
var getData = function(request, _accumulator, totalLimit) {
if (_accumulator === void 0) {
_accumulator = []
}
// Set api token to facebook SDK
FB.setAccessToken(request.apiToken)
FB.options({version: `v${request.apiVersion}`})
// If params.limit is set, prepare recursive data
if (!totalLimit && request.params.limit) {
totalLimit = request.params.limit
request.params.limit = 100
if (totalLimit === void 0) {
totalLimit = -1
}
let apiRes = null
// Call facebook SDK
apiRes = await FB.api(request.endpoint, request.method, request.params)
// Recursive block
if (totalLimit && apiRes.paging && apiRes.paging.cursors) {
// Store after token
request.params.after = apiRes.paging ? apiRes.paging.cursors.after : false
// concat new results with last results
_accumulator = _accumulator.concat(apiRes.data)
if (totalLimit > 0 && _accumulator.length >= totalLimit) {
return _accumulator.splice(0, totalLimit)
// If no limit, send all data after last page.
} else if (totalLimit === -1 && !request.params.after) {
return _accumulator
}
// Reccursice call with new params.
return getData(request, _accumulator, totalLimit)
} else {
if (apiRes.data) {
_accumulator = _accumulator.concat(apiRes.data)
return _accumulator
}
return apiRes
}
return __awaiter(void 0, void 0, void 0, function() {
var apiRes
return __generator(this, function(_a) {
switch (_a.label) {
case 0:
// Check param validity
if (!_checkParams(request)) {
throw new Error('Api Token, Method and endpoint are required')
}
// Set api token to facebook SDK
FB.setAccessToken(request.apiToken)
FB.options({version: 'v' + request.apiVersion})
// If params.limit is set, prepare recursive data
if (totalLimit === -1 && request.params.limit) {
totalLimit = request.params.limit
request.params.limit = 100
}
apiRes = null
return [
4 /*yield*/,
FB.api(request.endpoint, request.method, request.params)
// Recursive block
]
case 1:
// Call facebook SDK
apiRes = _a.sent()
// Recursive block
if (totalLimit && apiRes.paging && apiRes.paging.cursors) {
// Store after token
request.params.after = apiRes.paging ? apiRes.paging.cursors.after : false
// concat new results with last results
_accumulator = _accumulator.concat(apiRes.data)
if (totalLimit > 0 && _accumulator.length >= totalLimit) {
return [
2 /*return*/,
_accumulator.splice(0, totalLimit)
// If no limit, send all data after last page.
]
// If no limit, send all data after last page.
} else if (totalLimit === -1 && !request.params.after) {
return [2 /*return*/, _accumulator]
}
// Reccursice call with new params.
return [2 /*return*/, exports.getData(request, _accumulator, totalLimit)]
} else {
if (apiRes.data) {
_accumulator = _accumulator.concat(apiRes.data)
return [2 /*return*/, _accumulator]
}
return [2 /*return*/, apiRes]
}
return [2 /*return*/]
}
})
})
}
module.exports = {
getData
}
exports.getData = getData
'use strict'
const facebookService = require('./facebook')
module.exports = {
Object.defineProperty(exports, '__esModule', {value: true})
exports.servicesList = void 0
var facebook_1 = require('./facebook')
exports.servicesList = {
facebook: {
getData: facebookService.getData
getData: facebook_1.getData
}
}
{
"name": "@crowdrz/crowdrz-js",
"version": "2.3.0",
"version": "3.0.0",
"description": "Simplified wrapper for Social API",
"repository": "crowdrz/crowdrz-js",
"main": "./lib/crowdrz.js",
"main": "lib/crowdrz.js",
"types": "lib/crowdrz.d.ts",
"scripts": {

@@ -11,3 +12,3 @@ "demo": "node demo/demo.js",

"clean": "rm -r dist",
"build": "webpack --mode production"
"build": "tsc"
},

@@ -17,6 +18,7 @@ "author": "Antonin Bouscarel <antonin.bouscarel.pro@gmail.com>",

"devDependencies": {
"@babel/core": "^7.11.6",
"@types/node": "^12.12.57",
"babel-loader": "^8.1.0",
"chai": "^4.2.0",
"@babel/core": "^7.15.0",
"@types/fb": "0.0.28",
"@types/node": "^12.20.20",
"babel-loader": "^8.2.2",
"chai": "^4.3.4",
"husky": "^3.1.0",

@@ -27,7 +29,10 @@ "mocha": "^6.2.3",

"sinon": "^7.5.0",
"webpack": "^4.44.1",
"source-map-loader": "^3.0.0",
"ts-loader": "^8.2.0",
"typescript": "^4.3.5",
"webpack": "^4.46.0",
"webpack-cli": "^3.3.12"
},
"dependencies": {
"async": "^3.2.0",
"async": "^3.2.1",
"fb": "^2.0.0"

@@ -34,0 +39,0 @@ },

@@ -1,13 +0,16 @@

'use strict';
'use strict'
const chai = require('chai');
const expect = chai.expect;
const chai = require('chai')
const expect = chai.expect
const Crowdrz = require('../../lib/crowdrz');
const {Crowdrz} = require('../../lib/crowdrz')
describe('Crowdrz Core', () => {
it('should be init', () => {
const node = new Crowdrz();
expect(node).to.be.exist;
});
});
const node = new Crowdrz('facebook', '123', '4.3')
expect(node).to.be.exist
expect(node.apiToken).to.eql('123')
expect(node.apiVersion).to.eql('4.3')
expect(node.provider).to.eql('facebook')
})
})

@@ -1,29 +0,22 @@

const path = require('path');
module.exports = {
mode: 'production',
entry: './lib/crowdrz.js',
entry: './src/crowdrz.ts',
output: {
path: path.resolve('dist'),
filename: 'crowdrz.js',
libraryTarget: 'commonjs2',
filename: './dist/bundle.js'
},
node: {
fs: 'empty',
net: 'empty',
tls: 'empty',
dns: 'empty'
// Enable sourcemaps for debugging webpack's output.
target: 'node',
devtool: 'source-map',
resolve: {
// Add '.ts' and '.tsx' as resolvable extensions.
extensions: ['.webpack.js', '.web.js', '.ts', '.tsx', '.js']
},
module: {
rules: [
{
test: /\.js?$/,
exclude: /(node_modules)/,
use: 'babel-loader',
},
],
},
resolve: {
extensions: ['.js'],
},
};
// All files with a '.ts' or '.tsx' extension will be handled by 'ts-loader'.
{test: /\.tsx?$/, loader: 'ts-loader'}
// All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
// { test: /\.js$/, loader: "source-map-loader" },
]
}
// Other options...
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc