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

billomat-ts

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

billomat-ts - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

6

dist/billomat-resource-client.d.ts

@@ -1,3 +0,3 @@

import { Billomat } from './billomat';
import { BillomatApiClientConfig } from './get-billomat-api-client';
import { Billomat } from './billomat.js';
import { BillomatApiClientConfig } from './get-billomat-api-client.js';
export declare class BillomatResourceClient<T extends Billomat.Resource> {

@@ -11,3 +11,3 @@ private _config;

edit(resource: T): Promise<T>;
raw<TResult extends unknown>(method: string, subUri?: string, options?: Billomat.RawOptions): Promise<TResult>;
raw<TResult>(method: string, subUri?: string, options?: Billomat.RawOptions): Promise<TResult>;
private isListResponse;

@@ -14,0 +14,0 @@ private isGetResponse;

@@ -1,17 +0,13 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BillomatResourceClient = void 0;
var request = require("superagent");
var BillomatResourceClient = /** @class */ (function () {
function BillomatResourceClient(_config, _name) {
import request from 'superagent';
export class BillomatResourceClient {
constructor(_config, _name) {
this._config = _config;
this._name = _name;
}
BillomatResourceClient.prototype.list = function (query) {
var _this = this;
return new Promise(function (resolve, reject) {
_this.createAuthedRequest('GET', "api/" + _this._name)
list(query) {
return new Promise((resolve, reject) => {
this.createAuthedRequest('GET', `api/${this._name}`)
.query(query || {})
.then(function (response) {
var singular = SINGULAR.get(_this._name);
.then((response) => {
const singular = SINGULAR.get(this._name);
if (singular === undefined) {

@@ -21,7 +17,7 @@ reject('Unsupported resource (no singular defined)');

}
if (!_this.isListResponse(response.body)) {
reject("Invalid list response: " + JSON.stringify(response.body));
if (!this.isListResponse(response.body)) {
reject(`Invalid list response: ${JSON.stringify(response.body)}`);
return;
}
var returnValue = response.body[_this._name][singular] || [];
const returnValue = response.body[this._name][singular] || [];
resolve(Array.isArray(returnValue) ? returnValue : [returnValue]); // because if exactly one result is found, this property will actually not be a JSON array

@@ -31,9 +27,8 @@ })

});
};
BillomatResourceClient.prototype.get = function (id) {
var _this = this;
return new Promise(function (resolve, reject) {
_this.createAuthedRequest('GET', "api/" + _this._name + "/" + id)
.then(function (response) {
var singular = SINGULAR.get(_this._name);
}
get(id) {
return new Promise((resolve, reject) => {
this.createAuthedRequest('GET', `api/${this._name}/${id}`)
.then((response) => {
const singular = SINGULAR.get(this._name);
if (singular === undefined) {

@@ -43,4 +38,4 @@ reject('Unsupported resource (no singular defined)');

}
if (!_this.isGetResponse(response.body)) {
reject("Invalid get response: " + JSON.stringify(response.body));
if (!this.isGetResponse(response.body)) {
reject(`Invalid get response: ${JSON.stringify(response.body)}`);
return;

@@ -52,8 +47,6 @@ }

});
};
BillomatResourceClient.prototype.create = function (resource) {
var _this = this;
return new Promise(function (resolve, reject) {
var _a;
var singular = SINGULAR.get(_this._name);
}
create(resource) {
return new Promise((resolve, reject) => {
const singular = SINGULAR.get(this._name);
if (singular === undefined) {

@@ -63,10 +56,10 @@ reject('Unsupported resource (no singular defined)');

}
var payload = (_a = {},
_a[singular] = resource,
_a);
_this.createAuthedRequest('POST', "api/" + _this._name)
const payload = {
[singular]: resource,
};
this.createAuthedRequest('POST', `api/${this._name}`)
.send(payload)
.then(function (response) {
if (!_this.isCreateResponse(response.body)) {
reject("Invalid create response: " + JSON.stringify(response.body));
.then((response) => {
if (!this.isCreateResponse(response.body)) {
reject(`Invalid create response: ${JSON.stringify(response.body)}`);
return;

@@ -78,8 +71,6 @@ }

});
};
BillomatResourceClient.prototype.edit = function (resource) {
var _this = this;
return new Promise(function (resolve, reject) {
var _a;
var singular = SINGULAR.get(_this._name);
}
edit(resource) {
return new Promise((resolve, reject) => {
const singular = SINGULAR.get(this._name);
if (singular === undefined) {

@@ -89,10 +80,10 @@ reject('Unsupported resource (no singular defined)');

}
var payload = (_a = {},
_a[singular] = resource,
_a);
_this.createAuthedRequest('PUT', "api/" + _this._name)
const payload = {
[singular]: resource,
};
this.createAuthedRequest('PUT', `api/${this._name}`)
.send(payload)
.then(function (response) {
if (!_this.isEditResponse(response.body)) {
reject("Invalid edit response: " + JSON.stringify(response.body));
.then((response) => {
if (!this.isEditResponse(response.body)) {
reject(`Invalid edit response: ${JSON.stringify(response.body)}`);
return;

@@ -104,8 +95,7 @@ }

});
};
BillomatResourceClient.prototype.raw = function (method, subUri, options) {
var _this = this;
return new Promise(function (resolve, reject) {
}
raw(method, subUri, options) {
return new Promise((resolve, reject) => {
var _a;
var singular = SINGULAR.get(_this._name);
const singular = SINGULAR.get(this._name);
if (singular === undefined) {

@@ -115,10 +105,10 @@ reject('Unsupported resource (no singular defined)');

}
var uri = "api/" + _this._name + (subUri ? "/" + subUri : '');
var req = _this.createAuthedRequest(method, uri).query((_a = options === null || options === void 0 ? void 0 : options.query) !== null && _a !== void 0 ? _a : {});
const uri = `api/${this._name}${subUri ? `/${subUri}` : ''}`;
let req = this.createAuthedRequest(method, uri).query((_a = options === null || options === void 0 ? void 0 : options.query) !== null && _a !== void 0 ? _a : {});
if (options === null || options === void 0 ? void 0 : options.payload) {
req = req.send(options.payload);
}
req.then(function (response) {
if (!_this.isRawResponse(response.body)) {
reject("Invalid response: " + JSON.stringify(response.body));
req.then((response) => {
if (!this.isRawResponse(response.body)) {
reject(`Invalid response: ${JSON.stringify(response.body)}`);
return;

@@ -129,20 +119,20 @@ }

});
};
BillomatResourceClient.prototype.isListResponse = function (o) {
}
isListResponse(o) {
return typeof o === 'object' && o !== null && this._name in o;
};
BillomatResourceClient.prototype.isGetResponse = function (o) {
}
isGetResponse(o) {
return typeof o === 'object' && o !== null;
};
BillomatResourceClient.prototype.isCreateResponse = function (o) {
}
isCreateResponse(o) {
return typeof o === 'object' && o !== null;
};
BillomatResourceClient.prototype.isEditResponse = function (o) {
}
isEditResponse(o) {
return typeof o === 'object' && o !== null;
};
BillomatResourceClient.prototype.isRawResponse = function (o) {
}
isRawResponse(o) {
return typeof o === 'object' && o !== null;
};
BillomatResourceClient.prototype.createAuthedRequest = function (method, endpoint) {
return request(method, this._config.baseUrl + "/" + endpoint)
}
createAuthedRequest(method, endpoint) {
return request(method, `${this._config.baseUrl}/${endpoint}`)
.set('Accept', 'application/json')

@@ -153,7 +143,5 @@ .set('Content-Type', 'application/json')

.set('X-AppSecret', this._config.appSecret || '');
};
return BillomatResourceClient;
}());
exports.BillomatResourceClient = BillomatResourceClient;
var SINGULAR = new Map([
}
}
const SINGULAR = new Map([
['activity-feed', 'activity'],

@@ -160,0 +148,0 @@ ['articles', 'article'],

@@ -1,10 +0,11 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// Since we'll be using meta programming extensively to abstract these tests, disable some of our linting rules.
/* eslint-disable @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access */
var chai_1 = require("chai");
var fs = require("fs");
var nock = require("nock");
var get_billomat_api_client_1 = require("./get-billomat-api-client");
var SINGULAR_OF_RESOURCE = {
/* eslint-disable @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument */
import { expect } from 'chai';
import { readFile } from 'fs';
import nock from 'nock';
import { dirname, resolve } from 'path';
import { fileURLToPath } from 'url';
import { BILLOMAT_RESOURCE_NAMES, getBillomatApiClient } from './get-billomat-api-client.js';
const modulePath = dirname(fileURLToPath(import.meta.url));
const SINGULAR_OF_RESOURCE = {
'activity-feed': 'activity',

@@ -30,20 +31,18 @@ articles: 'article',

};
var isImplemented = function (resourceName) {
return ['clients', 'client-property-values', 'confirmations', 'contacts', 'invoices'].includes(resourceName);
};
describe('Billomat API', function () {
var api = get_billomat_api_client_1.getBillomatApiClient({ baseUrl: 'billomat.net', apiKey: 'a valid key' });
var scope = nock(/billomat.net/);
var _loop_1 = function (resources) {
var resource = SINGULAR_OF_RESOURCE[resources];
describe("GET " + resources, function () {
describe('list', function () {
var expectation;
beforeEach(function (done) {
fs.readFile(require.resolve("./test-data/" + resources + "-list-response.json"), 'utf8', function (err, data) {
const isImplemented = (resourceName) => ['clients', 'client-property-values', 'confirmations', 'contacts', 'invoices'].includes(resourceName);
describe('Billomat API', () => {
const api = getBillomatApiClient({ baseUrl: 'billomat.net', apiKey: 'a valid key' });
const scope = nock(/billomat.net/);
for (const resources of BILLOMAT_RESOURCE_NAMES.filter(isImplemented)) {
const resource = SINGULAR_OF_RESOURCE[resources];
describe(`GET ${resources}`, () => {
describe('list', () => {
let expectation;
beforeEach((done) => {
readFile(resolve(modulePath, `./test-data/${resources}-list-response.json`), 'utf8', (err, data) => {
if (err)
throw err;
var sample = JSON.parse(data);
scope.get(new RegExp("api/" + resources + "$")).reply(200, sample);
var sampleValue = sample[resources][resource];
const sample = JSON.parse(data);
scope.get(new RegExp(`api/${resources}$`)).reply(200, sample);
const sampleValue = sample[resources][resource];
expectation = Array.isArray(sampleValue) ? sampleValue : [sampleValue];

@@ -53,21 +52,21 @@ done();

});
it("retrieves a list of " + resources, function (done) {
it(`retrieves a list of ${resources}`, (done) => {
api[resources]
.list()
.then(function (response) {
chai_1.expect(response).to.deep.equal(expectation);
.then((response) => {
expect(response).to.deep.equal(expectation);
done();
})
.catch(function (error) { return done(error); });
.catch((error) => done(error));
});
});
describe('single', function () {
var expectation;
beforeEach(function (done) {
fs.readFile(require.resolve("./test-data/" + resources + "-get-response.json"), 'utf8', function (err, data) {
describe('single', () => {
let expectation;
beforeEach((done) => {
readFile(resolve(modulePath, `./test-data/${resources}-get-response.json`), 'utf8', (err, data) => {
if (err)
throw err;
var sample = JSON.parse(data);
const sample = JSON.parse(data);
scope
.get(new RegExp("api/" + resources + "/" + sample[resource].id + "$"))
.get(new RegExp(`api/${resources}/${sample[resource].id}$`))
.reply(200, sample);

@@ -78,22 +77,22 @@ expectation = sample[resource];

});
it("retrieves an individual " + resource, function (done) {
it(`retrieves an individual ${resource}`, (done) => {
api[resources]
.get(expectation.id)
.then(function (response) {
chai_1.expect(response).to.deep.equal(expectation);
.then((response) => {
expect(response).to.deep.equal(expectation);
done();
})
.catch(function (error) { return done(error); });
.catch((error) => done(error));
});
});
});
describe("POST " + resources, function () {
describe('create', function () {
var expectation;
beforeEach(function (done) {
fs.readFile(require.resolve("./test-data/" + resources + "-create-response.json"), 'utf8', function (err, data) {
describe(`POST ${resources}`, () => {
describe('create', () => {
let expectation;
beforeEach((done) => {
readFile(resolve(modulePath, `./test-data/${resources}-create-response.json`), 'utf8', (err, data) => {
if (err)
throw err;
var sample = JSON.parse(data);
scope.post(new RegExp("api/" + resources)).reply(201, sample);
const sample = JSON.parse(data);
scope.post(new RegExp(`api/${resources}`)).reply(201, sample);
expectation = sample[resource];

@@ -103,20 +102,20 @@ done();

});
it("submits a request to create an individual " + resource, function (done) {
it(`submits a request to create an individual ${resource}`, (done) => {
api[resources]
.create(expectation)
.then(function (response) {
chai_1.expect(response).to.deep.equal(expectation);
.then((response) => {
expect(response).to.deep.equal(expectation);
done();
})
.catch(function (error) { return done(error); });
.catch((error) => done(error));
});
});
describe('edit', function () {
var expectation;
beforeEach(function (done) {
fs.readFile(require.resolve("./test-data/" + resources + "-create-response.json"), 'utf8', function (err, data) {
describe('edit', () => {
let expectation;
beforeEach((done) => {
readFile(resolve(modulePath, `./test-data/${resources}-create-response.json`), 'utf8', (err, data) => {
if (err)
throw err;
var sample = JSON.parse(data);
scope.put(new RegExp("api/" + resources)).reply(200, sample);
const sample = JSON.parse(data);
scope.put(new RegExp(`api/${resources}`)).reply(200, sample);
expectation = sample[resource];

@@ -126,30 +125,26 @@ done();

});
it("submits a request to change an individual " + resource, function (done) {
it(`submits a request to change an individual ${resource}`, (done) => {
api[resources]
.edit(expectation)
.then(function (response) {
chai_1.expect(response).to.deep.equal(expectation);
.then((response) => {
expect(response).to.deep.equal(expectation);
done();
})
.catch(function (error) { return done(error); });
.catch((error) => done(error));
});
});
});
};
for (var _i = 0, _a = get_billomat_api_client_1.BILLOMAT_RESOURCE_NAMES.filter(isImplemented); _i < _a.length; _i++) {
var resources = _a[_i];
_loop_1(resources);
}
describe('when calling raw', function () {
beforeEach(function () { return scope.get(new RegExp('api/invoices/1')).reply(200, { ok: 'yes' }); });
it('returns response body', function (done) {
describe('when calling raw', () => {
beforeEach(() => scope.get(new RegExp('api/invoices/1')).reply(200, { ok: 'yes' }));
it('returns response body', (done) => {
api['invoices']
.raw('GET', '1')
.then(function (response) {
chai_1.expect(response).to.deep.equal({ ok: 'yes' });
.then((response) => {
expect(response).to.deep.equal({ ok: 'yes' });
done();
})
.catch(function (error) { return done(error); });
.catch((error) => done(error));
});
});
});

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

import { BILLOMAT_RESOURCE_NAMES } from './get-billomat-api-client';
import { BILLOMAT_RESOURCE_NAMES } from './get-billomat-api-client.js';
export declare namespace Billomat {
type ResourceName = typeof BILLOMAT_RESOURCE_NAMES[number];
type ResourceName = (typeof BILLOMAT_RESOURCE_NAMES)[number];
interface Resource {

@@ -5,0 +5,0 @@ id?: string;

@@ -1,2 +0,1 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
export {};

@@ -1,3 +0,3 @@

import { Billomat } from './billomat';
import { BillomatResourceClient } from './billomat-resource-client';
import { Billomat } from './billomat.js';
import { BillomatResourceClient } from './billomat-resource-client.js';
export declare const BILLOMAT_RESOURCE_NAMES: readonly ["activity-feed", "articles", "client-property-values", "clients", "confirmations", "countries", "contacts", "credit-notes", "currencies", "delivery-notes", "estimates", "incomings", "invoices", "letters", "recurrings", "reminders", "search", "suppliers", "users"];

@@ -13,3 +13,3 @@ export interface MappedBillomatResourceType {

}
export declare type BillomatApiClient = {
export type BillomatApiClient = {
[key in Billomat.ResourceName]: BillomatResourceClient<MappedBillomatResourceType[key]>;

@@ -16,0 +16,0 @@ };

@@ -1,6 +0,3 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getBillomatApiClient = exports.BILLOMAT_RESOURCE_NAMES = void 0;
var billomat_resource_client_1 = require("./billomat-resource-client");
exports.BILLOMAT_RESOURCE_NAMES = [
import { BillomatResourceClient } from './billomat-resource-client.js';
export const BILLOMAT_RESOURCE_NAMES = [
'activity-feed',

@@ -26,17 +23,12 @@ 'articles',

];
var getBillomatApiClient = function (config) {
var api = {}; // because we're going to modify it right below
var _loop_1 = function (resource) {
export const getBillomatApiClient = (config) => {
const api = {}; // because we're going to modify it right below
for (const resource of BILLOMAT_RESOURCE_NAMES) {
Object.defineProperty(api, resource, {
get: function () {
return new billomat_resource_client_1.BillomatResourceClient(config, resource);
get: () => {
return new BillomatResourceClient(config, resource);
},
});
};
for (var _i = 0, BILLOMAT_RESOURCE_NAMES_1 = exports.BILLOMAT_RESOURCE_NAMES; _i < BILLOMAT_RESOURCE_NAMES_1.length; _i++) {
var resource = BILLOMAT_RESOURCE_NAMES_1[_i];
_loop_1(resource);
}
return api;
};
exports.getBillomatApiClient = getBillomatApiClient;

@@ -1,3 +0,3 @@

export * from './get-billomat-api-client';
export { Billomat } from './billomat';
export { BillomatResourceClient } from './billomat-resource-client';
export * from './get-billomat-api-client.js';
export { Billomat } from './billomat.js';
export { BillomatResourceClient } from './billomat-resource-client.js';

@@ -1,16 +0,2 @@

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.BillomatResourceClient = void 0;
__exportStar(require("./get-billomat-api-client"), exports);
var billomat_resource_client_1 = require("./billomat-resource-client");
Object.defineProperty(exports, "BillomatResourceClient", { enumerable: true, get: function () { return billomat_resource_client_1.BillomatResourceClient; } });
export * from './get-billomat-api-client.js';
export { BillomatResourceClient } from './billomat-resource-client.js';
{
"name": "billomat-ts",
"version": "0.2.0",
"version": "0.3.0",
"description": "Billomat API implementation in TypeScript for use in Node.js",
"type": "module",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"dependencies": {
"@types/superagent": "^4.1.10",
"superagent": "^6.1.0"
"@types/superagent": "^8.1.3",
"superagent": "^8.1.2"
},
"devDependencies": {
"@types/chai": "^4.2.15",
"@types/mocha": "^8.2.1",
"@types/nock": "^11.1.0",
"@types/proxyquire": "^1.3.28",
"@types/sinon": "^9.0.10",
"@typescript-eslint/eslint-plugin": "^4.15.1",
"@typescript-eslint/eslint-plugin-tslint": "^4.15.1",
"@typescript-eslint/parser": "^4.15.1",
"chai": "^4.3.0",
"eslint": "^7.20.0",
"@types/chai": "^4.3.11",
"@types/mocha": "^10.0.6",
"@types/proxyquire": "^1.3.31",
"@types/sinon": "^17.0.3",
"@typescript-eslint/eslint-plugin": "^6.19.1",
"@typescript-eslint/parser": "^6.19.1",
"chai": "^5.0.3",
"cross-env": "^7.0.3",
"eslint": "^8.56.0",
"eslint-config-google": "^0.14.0",
"eslint-config-prettier": "^7.2.0",
"eslint-plugin-jsdoc": "^32.0.2",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-jsdoc": "^48.0.4",
"eslint-plugin-prefer-arrow": "^1.2.3",
"eslint-plugin-prettier": "^3.3.1",
"mocha": "^8.3.0",
"nock": "^13.0.7",
"eslint-plugin-prettier": "^5.1.3",
"mocha": "^10.2.0",
"nock": "^13.5.0",
"npm-run-all": "^4.1.5",
"proxyquire": "^2.1.3",
"sinon": "^9.2.4",
"ts-node": "^9.1.1",
"typescript": "^4.1.5"
"sinon": "^17.0.1",
"ts-node": "^10.9.2",
"typescript": "^5.3.3"
},
"scripts": {
"lint": "eslint . --ext .js,.ts,.spec.js,.spec.ts",
"test": "mocha --require ts-node/register --extensions ts 'src/**/*.spec.ts'",
"test": "mocha",
"build": "tsc",

@@ -45,3 +45,7 @@ "prepare": "run-s build",

},
"author": "Seibert Media GmbH",
"author": {
"name": "Julian Felix Rost",
"email": "j-frost+billomat-ts@a3re.net",
"url": "https://a3re.net/"
},
"keywords": [

@@ -55,8 +59,8 @@ "billomat",

"bugs": {
"url": "https://github.com/seibert-media/billomat-ts/issues"
"url": "https://github.com/j-frost/billomat-ts/issues"
},
"homepage": "https://github.com/seibert-media/billomat-ts/blob/master/README.md",
"homepage": "https://github.com/j-frost/billomat-ts/blob/main/README.md",
"repository": {
"type": "git",
"url": "git@github.com:seibert-media/billomat-ts.git",
"url": "git+ssh://git@github.com/j-frost/billomat-ts.git",
"directory": "."

@@ -63,0 +67,0 @@ },

@@ -5,5 +5,4 @@ # billomat-ts

![npm bundle size](https://img.shields.io/bundlephobia/min/billomat-ts)
![GitHub repo size](https://img.shields.io/github/repo-size/seibert-media/billomat-ts)
![GitHub contributors](https://img.shields.io/github/contributors/seibert-media/billomat-ts)
![Twitter Follow](https://img.shields.io/twitter/follow/seibertmedia?style=social)
![GitHub repo size](https://img.shields.io/github/repo-size/j-frost/billomat-ts)
![GitHub contributors](https://img.shields.io/github/contributors/j-frost/billomat-ts)
![License](https://img.shields.io/npm/l/billomat-ts)

@@ -54,3 +53,3 @@

If you want to contact me you can reach me at jrost@seibert-media.net. Also feel free to open an issue if you find a bug or have a question.
If you want to contact me you can reach me at [j-frost+billomat-ts@a3re.net](mailto:j-frost+billomat-ts@a3re.net). Also feel free to open an issue if you find a bug or have a question.

@@ -57,0 +56,0 @@ ## License

Sorry, the diff of this file is not supported yet

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