Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mockaroo

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mockaroo - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

169

client.js

@@ -33,18 +33,20 @@ var __create = Object.create;

module.exports = __toCommonJS(client_exports);
var import_shim = require("core-js/shim");
var import_axios = __toESM(require("axios"));
var errors = __toESM(require("./errors"));
var import_axios = __toESM(require("axios"), 1);
var errors = __toESM(require("./errors"), 1);
import_axios.default.defaults.adapter = "http";
class Client {
/**
* Creates a new instance
* @param {Object} options
* @param {string} options.apiKey Your mockaroo api key. See http://mockaroo.com/api/docs under "Gaining Access".
* @param {string} [options.host='mockaroo.com'] The hostname of the mockaroo server.
* @param {int} [options.port=80] The port to use.
* @param {boolean} [options.secure=true] Set to false to use http instead of https
*/
* Creates a new instance
* @param {Object} options
* @param {string} options.apiKey Your mockaroo api key. See http://mockaroo.com/api/docs under "Gaining Access".
* @param {string} [options.host='mockaroo.com'] The hostname of the mockaroo server.
* @param {int} [options.port=80] The port to use.
* @param {boolean} [options.secure=true] Set to false to use http instead of https
*/
constructor(options) {
var defaults = {
const defaults = {
host: "api.mockaroo.com",
secure: true
secure: true,
port: null,
apiKey: null
};

@@ -55,50 +57,53 @@ Object.assign(this, defaults, options);

/**
* Generates data based on the specified options. You can use either a saved schema using the "schema" option:
*
* @example
*
* // generate data from a saved schema
* client.generate({
* schema: 'My Saved Schema'
* }).then(function(data) {
* // keys are the names of the columns in your saved schema.
* })
*
* @example
*
* //specify fields using the api
* client.generate({
* count: 10,
* fields: [{
* name: 'id'
* type: 'Row Number',
* }, {
* name: 'transactionType'
* type: 'Custom List',
* values: ['debit', 'credit']
* }, {
* name: 'amount',
* type: 'Number'
* min: 1
* max: 10000,
* decimals: 2
* }]
* }).then(function(data) {
* for (var i=0; i<data.length; i++) {
* var record = data[i];
* console.log('id', record.id, 'transactionType', record.transactionType, 'amount', record.amount);
* }
* })
*
* @param {Object} options
* @param {int} [options.count=1] The number of records to generate. See usage limits here: http://mockaroo.com/api/docs
* @param {string} options.schema The name of the saved schema. Use this to generate data based on schema you've built using the website. Use the fields array to generate data using an ad-doc schema.
* @param {string} [options.format='json'] 'json' by default, set to 'csv' to generate csv data.
* @param {boolean} [options.header=true] when using format: 'csv', set to false to remove the header row
* @param {boolean} [options.array=false] set to true to always return an array of objects, even if count == 1
* @param {Object[]} options.fields An array of fields
* @param {string} options.fields.type The type of field. Many field types such as "Number" and "Custom List" take additional parameters, which are documented here: http://mockaroo.com/api/docs#types.
* @param {string} options.field.name The value will be returned under this key in the resulting data objects.
* @return {Promise<Object[]>} The promise resolves to an object if count == 1 or array of objects if count > 1. Each object represents a record. Keys are the field names.
*/
* Generates data based on the specified options. You can use either a saved schema using the "schema" option:
*
* @example
*
* // generate data from a saved schema
* client.generate({
* schema: 'My Saved Schema'
* }).then(function(data) {
* // keys are the names of the columns in your saved schema.
* })
*
* @example
*
* //specify fields using the api
* client.generate({
* count: 10,
* fields: [{
* name: 'id'
* type: 'Row Number',
* }, {
* name: 'transactionType'
* type: 'Custom List',
* values: ['debit', 'credit']
* }, {
* name: 'amount',
* type: 'Number'
* min: 1
* max: 10000,
* decimals: 2
* }]
* }).then(function(data) {
* for (var i=0; i<data.length; i++) {
* var record = data[i];
* console.log('id', record.id, 'transactionType', record.transactionType, 'amount', record.amount);
* }
* })
*
*
* @typedef {Object} Field
* @property {string} type The type of field. Many field types such as "Number" and "Custom List" take additional parameters, which are documented here: http://mockaroo.com/api/docs#types.
* @property {string} name The value will be returned under this key in the resulting data objects.
*
* @param {Object} options
* @param {int} [options.count=1] The number of records to generate. See usage limits here: http://mockaroo.com/api/docs
* @param {string} options.schema The name of the saved schema. Use this to generate data based on schema you've built using the website. Use the fields array to generate data using an ad-doc schema.
* @param {string} [options.format='json'] 'json' by default, set to 'csv' to generate csv data.
* @param {boolean} [options.header=true] when using format: 'csv', set to false to remove the header row
* @param {boolean} [options.array=false] set to true to always return an array of objects, even if count == 1
* @param {Field[]} options.fields
* @return {Promise<Object[]>} The promise resolves to an object if count == 1 or array of objects if count > 1. Each object represents a record. Keys are the field names.
*/
generate(options) {

@@ -108,3 +113,3 @@ if (!options || !options.schema && !options.fields)

this.validateFields(options.fields);
var url = this.getUrl(options);
const url = this.getUrl(options);
return new Promise((resolve, reject) => {

@@ -115,5 +120,5 @@ import_axios.default.post(url, options.fields).then((resp) => resolve(resp.data)).catch((resp) => reject(this.convertError(resp)));

/**
* @private
* @param {Object[]} fields
*/
* @private
* @param {Object[]} fields
*/
validateFields(fields) {

@@ -123,3 +128,3 @@ if (!fields)

if (fields instanceof Array) {
for (var field of fields) {
for (const field of fields) {
if (!field.name)

@@ -135,13 +140,13 @@ throw new Error("each field must have a name");

/**
* Generates the rest api url
* @private
* @return {String}
*/
* Generates the rest api url
* @private
* @return {String}
*/
getUrl(options) {
options = Object.assign({ count: 1, format: "json" }, options);
var protocol = this.secure ? "https" : "http";
var port = this.port ? `:${this.port}` : "";
var schema = options.schema ? `&schema=${options.schema}` : "";
var header = options.header !== void 0 ? `&header=${options.header}` : "";
var array = options.array !== void 0 ? `&array=${options.array}` : "";
const protocol = this.secure ? "https" : "http";
const port = this.port ? `:${this.port}` : "";
const schema = options.schema ? `&schema=${options.schema}` : "";
const header = options.header !== void 0 ? `&header=${options.header}` : "";
const array = options.array !== void 0 ? `&array=${options.array}` : "";
if (options.format !== "json" && options.format !== "csv")

@@ -152,8 +157,8 @@ throw new Error("format must be json or csv");

/**
* Converts error messages from the mockaroo server to error classes
* @private
*/
* Converts error messages from the mockaroo server to error classes
* @private
*/
convertError(response) {
var error = response.data.error;
if (error == "Invalid API Key") {
const error = response.data.error;
if (error === "Invalid API Key") {
return new errors.InvalidApiKeyError(response.error);

@@ -167,5 +172,5 @@ } else if (error.match(/limited/)) {

/**
* Validates that all required options have be specified.
* @private
*/
* Validates that all required options have be specified.
* @private
*/
validate() {

@@ -172,0 +177,0 @@ if (!this.apiKey)

@@ -35,16 +35,4 @@ var __defProp = Object.defineProperty;

class UsageLimitExceededError extends ApiError {
/**
* @param {String} message
*/
constructor(message) {
super(message);
}
}
class InvalidApiKeyError extends ApiError {
/**
* @param {String} message
*/
constructor(message) {
super(message);
}
}

@@ -51,0 +39,0 @@ // Annotate the CommonJS export names for ESM import in node:

@@ -7,2 +7,6 @@ var __create = Object.create;

var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {

@@ -24,7 +28,13 @@ if (from && typeof from === "object" || typeof from === "function") {

));
var errors = __toESM(require("./errors"));
var import_client = __toESM(require("./client"));
module.exports = {
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var src_exports = {};
__export(src_exports, {
default: () => src_default
});
module.exports = __toCommonJS(src_exports);
var import_client = __toESM(require("./client.js"), 1);
var errors = __toESM(require("./errors"), 1);
var src_default = {
errors,
Client: import_client.default
};
{
"name": "mockaroo",
"version": "1.0.0",
"version": "1.0.1",
"description": "Generate data using the mockaroo.com API",
"main": "index.js",
"type": "module",
"author": "Mark Brocato",

@@ -11,3 +12,3 @@ "license": "MIT",

"type": "git",
"url": "git://github.com:mockaroo/mockaroo-node.git"
"url": "git://github.com/mockaroo/mockaroo-node.git"
},

@@ -22,15 +23,25 @@ "scripts": {

},
"targets": {
"default": {
"distDir": "dist"
}
},
"dependencies": {
"axios": "^0.5.4"
"axios": "1.6.8"
},
"devDependencies": {
"@edgio/cli": "^7.0.17",
"@edgio/core": "^7.0.17",
"chai": "^3.0.0",
"esbuild": "^0.17.19",
"esdoc": "^1.1.0",
"esdoc-standard-plugin": "^1.0.0",
"mocha": "^2.2.5",
"nock": "^2.6.0"
"@edgio/cli": "7.11.3",
"@edgio/core": "7.11.3",
"chai": "5.1.0",
"esbuild": "0.20.2",
"esdoc": "1.1.0",
"esdoc-standard-plugin": "1.0.0",
"eslint": "8.0.1",
"eslint-config-standard": "17.1.0",
"eslint-plugin-import": "2.25.2",
"eslint-plugin-n": "15.0.0 || 16.0.0 ",
"eslint-plugin-promise": "6.0.0",
"mocha": "10.4.0",
"nock": "13.5.4"
}
}
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc