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

bir1

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bir1 - npm Package Compare versions

Comparing version 2.0.2 to 3.0.1

dist/client.d.ts

96

dist/bir.d.ts

@@ -0,1 +1,20 @@

import { GetValueOptions, DanePobierzPelnyRaportOptions, DanePobierzRaportZbiorczyOptions } from './types.js';
/**
* Class Bir provides access to REGON API
*
* @example Create a new Bir instance
* ```js
* import Bir from 'bir1'
* const bir = new Bir()
* console.log(await bir.search({ nip: '5261040567' }))
* // output:
* // {
* // regon: '011417295',
* // nip: '5261040567',
* // statusNip: '',
* // nazwa: 'T-MOBILE POLSKA SPÓŁKA AKCYJNA',
* // ...
* // }
* ```
*/
export default class Bir {

@@ -5,12 +24,55 @@ private key;

private prod;
private api;
private _normalizeFn?;
/**
* Create a new Bir instance
*
* @remarks
* If `options.key` is not provided, the internally stored public API key
* is used to access non-production GUS database. It allows quick start,
* however non-production database contains old and anonymized data.
* Providing GUS provided key connects to the production database.
*/
constructor(options?: {
/**
* API key provided by GUS.
*/
key?: string;
/**
* Function to modify response to a more convenient format.
*/
normalizeFn?: (obj: any) => any;
});
private normalize;
private api;
/**
* Login to the API (method: Zaloguj)
*
* After successful login, the session id (`sid`) is stored in the
* instance and used in subsequent requests.
*
* @remarks
* This method must be called before any other method. It is called
* automatically before other requests if the session id (`sid`) is
* `undefined`.
*/
login(): Promise<void>;
value(value: string): Promise<string>;
report(query: {
regon: string;
report: string;
}): Promise<any>;
/**
* Automatically login to the API if not already logged in.
*/
private autologin;
/**
* Get diagnostic information (method: GetValue)
* @param value value to retrieve
*/
value(value: GetValueOptions): Promise<string>;
/**
* Search (method: DaneSzukajPodmioty)
* @param query
* @param query.nip NIP number
* @param query.regon REGON number
* @param query.krs KRS number
*
* @remarks
* Only one of the query parameters can be used at a time.
*/
search(query: {

@@ -23,2 +85,24 @@ nip: string;

}): Promise<any>;
/**
* Retrive report (method: DanePobierzPelnyRaport)
* @param query.regon REGON number
* @param query.report report name
*/
report(query: {
regon: string;
report: DanePobierzPelnyRaportOptions;
}): Promise<any>;
/**
* Retrive summary report (method: DanePobierzRaportZbiorczy)
* @param query.date date in format YYYY-MM-DD not earlier than week before
* @param query.report report name
*/
summary(query: {
date: string;
report: DanePobierzRaportZbiorczyOptions;
}): Promise<any>;
/**
* Logout (method: Wyloguj)
*/
logout(): Promise<void>;
}

170

dist/bir.js

@@ -1,67 +0,133 @@

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const assert_1 = __importDefault(require("assert"));
const got_1 = __importDefault(require("got"));
const template_js_1 = require("./template.js");
const xml_parser_js_1 = require("./xml-parser.js");
const bir_error_js_1 = __importDefault(require("./bir-error.js"));
const url = {
prod: 'https://wyszukiwarkaregon.stat.gov.pl/wsBIR/UslugaBIRzewnPubl.svc',
test: 'https://wyszukiwarkaregontest.stat.gov.pl/wsBIR/UslugaBIRzewnPubl.svc',
};
function soapResult(string) {
const match = /<\S+Result>(.+)<\/\S+Result>/s.exec(string);
(0, assert_1.default)(match && match[1], new Error('SOAP Result empty or not found in response'));
return match[1];
}
function extractData(object) {
return object['root']['dane'];
}
function validate(data) {
if (bir_error_js_1.default.looksLike(data)) {
throw bir_error_js_1.default.fromResponse(data);
}
return data;
}
class Bir {
import assert from 'assert';
import * as template from './templates/index.js';
import { unsoap, parse } from './extract.js';
import { query } from './client.js';
import { BirError } from './error.js';
/**
* Class Bir provides access to REGON API
*
* @example Create a new Bir instance
* ```js
* import Bir from 'bir1'
* const bir = new Bir()
* console.log(await bir.search({ nip: '5261040567' }))
* // output:
* // {
* // regon: '011417295',
* // nip: '5261040567',
* // statusNip: '',
* // nazwa: 'T-MOBILE POLSKA SPÓŁKA AKCYJNA',
* // ...
* // }
* ```
*/
export default class Bir {
/**
* Create a new Bir instance
*
* @remarks
* If `options.key` is not provided, the internally stored public API key
* is used to access non-production GUS database. It allows quick start,
* however non-production database contains old and anonymized data.
* Providing GUS provided key connects to the production database.
*/
constructor(options = {}) {
this.key = options.key || 'abcde12345abcde12345';
this.prod = options.key ? true : false;
this.api = got_1.default.extend({
method: 'POST',
prefixUrl: this.prod ? url.prod : url.test,
headers: {
'Content-Type': 'application/soap+xml',
},
});
this._normalizeFn = options.normalizeFn;
}
normalize(obj) {
return this._normalizeFn ? this._normalizeFn(obj) : obj;
}
async api(options) {
if (this.sid) {
options.headers = { ...options.headers, sid: this.sid };
}
return query(this.prod, options);
}
/**
* Login to the API (method: Zaloguj)
*
* After successful login, the session id (`sid`) is stored in the
* instance and used in subsequent requests.
*
* @remarks
* This method must be called before any other method. It is called
* automatically before other requests if the session id (`sid`) is
* `undefined`.
*/
async login() {
(0, assert_1.default)(this.key, new Error('no api key provided'));
const body = await (0, template_js_1.template)('Zaloguj', { key: this.key });
assert(this.key, new BirError('No api key provided'));
const body = template.Zaloguj({ key: this.key });
const response = await this.api({ body });
const sid = soapResult(response.body);
(0, assert_1.default)(sid, new Error('login failed, no session foun in response'));
const sid = unsoap(response);
assert(sid, new BirError('Login failed, no session found'));
this.sid = sid;
}
/**
* Automatically login to the API if not already logged in.
*/
async autologin() {
if (!this.sid) {
await this.login();
}
}
/**
* Get diagnostic information (method: GetValue)
* @param value value to retrieve
*/
async value(value) {
const body = await (0, template_js_1.template)('GetValue', { value });
await this.autologin();
const body = template.GetValue({ value });
const response = await this.api({ body });
return soapResult(response.body);
return unsoap(response);
}
/**
* Search (method: DaneSzukajPodmioty)
* @param query
* @param query.nip NIP number
* @param query.regon REGON number
* @param query.krs KRS number
*
* @remarks
* Only one of the query parameters can be used at a time.
*/
async search(query) {
await this.autologin();
const body = template.DaneSzukajPodmioty(query);
const response = await this.api({ body });
return this.normalize(parse(unsoap(response)));
}
/**
* Retrive report (method: DanePobierzPelnyRaport)
* @param query.regon REGON number
* @param query.report report name
*/
async report(query) {
const body = await (0, template_js_1.template)('DanePobierzPelnyRaport', query);
const response = await this.api({ headers: { sid: this.sid }, body });
const result = await (0, xml_parser_js_1.xml2json)(soapResult(response.body));
return validate(extractData(result));
await this.autologin();
const body = template.DanePobierzPelnyRaport(query);
const response = await this.api({ body });
return this.normalize(parse(unsoap(response)));
}
async search(query) {
const body = await (0, template_js_1.template)('DaneSzukajPodmioty', query);
const response = await this.api({ headers: { sid: this.sid }, body });
const result = await (0, xml_parser_js_1.xml2json)(soapResult(response.body));
return validate(extractData(result));
/**
* Retrive summary report (method: DanePobierzRaportZbiorczy)
* @param query.date date in format YYYY-MM-DD not earlier than week before
* @param query.report report name
*/
async summary(query) {
await this.autologin();
const body = template.DanePobierzRaportZbiorczy(query);
const response = await this.api({ body });
return this.normalize(parse(unsoap(response)));
}
/**
* Logout (method: Wyloguj)
*/
async logout() {
if (!this.sid)
return;
const body = template.Wyloguj({ sid: this.sid });
const response = await this.api({ body });
unsoap(response);
}
}
exports.default = Bir;
import Bir from './bir.js';
export = Bir;
export default Bir;

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

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
const bir_js_1 = __importDefault(require("./bir.js"));
module.exports = bir_js_1.default;
import Bir from './bir.js';
export default Bir;

@@ -1,1 +0,44 @@

export declare function removePrefix(prefix: string): (param: string) => string;
/**
* Transform object parsed from raw API response to format compatible with
* earlier versions of the API. This function:
* - removes 'praw_' prefix from keys
* - lower first letter of keys
* - replaces empty strings with `undefined`
*
* Note: GUS API returns more prefixed keys than 'praw_'. Removing only this
* prefix was initial partial implementation. This is inconsistent approach and
* thus marked as deprecated, left only for compatibility with legacy code.
*
* @example
* ```js
* import Bir from 'bir1'
* import { legacy } from 'bir1/normalize'
* const bir = new Bir({ normalizeFn: legacy })
* const result = await bir.search('010058960')
* ```
*
* @param obj object to normalize
* @deprecated
*/
export declare function legacy(obj: any): any;
/**
* Transform object parsed from raw API response to convenient format commonly
* used in modern JavaScript applications. This is subjective and opinionated.
* This function:
* - remove prefixes from keys (e.g. `fiz_`, `praw_`, ...)
* - lower camel case keys
* - unifies some keys (e.g. `regon9` -> `regon`)
* - replaces empty strings with `undefined`
*
* @example
* ```js
* import Bir from 'bir1'
* import { modern } from 'bir1/normalize'
* const bir = new Bir({ normalizeFn: modern })
* const result = await bir.search('010058960')
* ```
*
* @param obj object to normalize
* @beta
*/
export declare function modern(obj: any): any;

@@ -1,8 +0,145 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.removePrefix = void 0;
function removePrefix(prefix) {
const prefixLength = prefix.length;
return (param) => param.startsWith(prefix) ? param.slice(prefixLength) : param;
/**
* Lower first letter of the string.
*/
function lowerFirstLetter(name) {
if (name.length === 0)
return name;
return name[0].toLowerCase() + name.slice(1);
}
exports.removePrefix = removePrefix;
/**
* Strip `prefix` from the `name` string.
*/
function stripPrefix(name, prefix) {
if (typeof prefix === 'string')
prefix = [prefix];
for (let p of prefix) {
if (name.startsWith(p)) {
return name.slice(p.length);
}
}
return name;
}
/**
* Replace some strings.
*/
function replace(value, replaceArray) {
for (let [search, replace] of replaceArray) {
if (value === search)
value = replace;
}
return value;
}
/**
* Convert string to lower camel case.
*
* @remarks
* This is simplified implementation assuming that input string is already
* partially camel cased. In some edge cases this function produce
* results different from proper implementation.
* However it is stable and faster and sufficient for our use case.
*/
function lowerCamelCase(name) {
const words = name.split(/[^a-zA-Z0-9]/);
const camelCaseWords = words.map((word, index) => {
if (index === 0) {
return word.charAt(0).toLowerCase() + word.slice(1);
}
else {
return word.charAt(0).toUpperCase() + word.slice(1);
}
});
return camelCaseWords.join('');
}
/**
* Traverse object recursively and apply provided function `fn` to each
* key-value pair. Returns new object.
* @param obj object to traverse
* @param fn function to apply
*/
function morph(obj, fn) {
if (typeof obj === 'object' && obj !== null) {
if (Array.isArray(obj)) {
return obj.map((element) => morph(element, fn));
}
else {
let newObj = {};
for (let [key, value] of Object.entries(obj)) {
if (typeof value === 'object') {
newObj[key] = morph(value, fn);
}
else {
const updated = fn(key, value);
newObj[updated.key] = updated.value;
}
}
return newObj;
}
}
}
/**
* Transform object parsed from raw API response to format compatible with
* earlier versions of the API. This function:
* - removes 'praw_' prefix from keys
* - lower first letter of keys
* - replaces empty strings with `undefined`
*
* Note: GUS API returns more prefixed keys than 'praw_'. Removing only this
* prefix was initial partial implementation. This is inconsistent approach and
* thus marked as deprecated, left only for compatibility with legacy code.
*
* @example
* ```js
* import Bir from 'bir1'
* import { legacy } from 'bir1/normalize'
* const bir = new Bir({ normalizeFn: legacy })
* const result = await bir.search('010058960')
* ```
*
* @param obj object to normalize
* @deprecated
*/
export function legacy(obj) {
return morph(obj, (key, value) => {
key = stripPrefix(key, 'praw_');
key = lowerFirstLetter(key);
value = replace(value, [['', undefined]]);
return { key, value };
});
}
/**
* Transform object parsed from raw API response to convenient format commonly
* used in modern JavaScript applications. This is subjective and opinionated.
* This function:
* - remove prefixes from keys (e.g. `fiz_`, `praw_`, ...)
* - lower camel case keys
* - unifies some keys (e.g. `regon9` -> `regon`)
* - replaces empty strings with `undefined`
*
* @example
* ```js
* import Bir from 'bir1'
* import { modern } from 'bir1/normalize'
* const bir = new Bir({ normalizeFn: modern })
* const result = await bir.search('010058960')
* ```
*
* @param obj object to normalize
* @beta
*/
export function modern(obj) {
return morph(obj, (key, value) => {
key = stripPrefix(key, [
'fiz_',
'praw_',
'fizC_',
'fizP_',
'lokfiz_',
'lokpraw_',
'wspolsc_',
]);
key = lowerCamelCase(key);
key = replace(key, [['regon9', 'regon']]);
value = replace(value, [['', undefined]]);
return { key, value };
});
}

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DanePobierzPelnyRaport = void 0;
const DanePobierzPelnyRaport = (params) => `
export const DanePobierzPelnyRaport = (params) => `
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:ns="http://CIS/BIR/PUBL/2014/07">

@@ -18,2 +15,1 @@ <soap:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">

`;
exports.DanePobierzPelnyRaport = DanePobierzPelnyRaport;

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DaneSzukajPodmioty = void 0;
const DaneSzukajPodmioty = (params) => `
export const DaneSzukajPodmioty = (params) => `
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:ns="http://CIS/BIR/PUBL/2014/07" xmlns:dat="http://CIS/BIR/PUBL/2014/07/DataContract">

@@ -21,2 +18,1 @@ <soap:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">

`;
exports.DaneSzukajPodmioty = DaneSzukajPodmioty;

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GetValue = void 0;
const GetValue = (params) => `
export const GetValue = (params) => `
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:ns="http://CIS/BIR/2014/07">

@@ -17,2 +14,1 @@ <soap:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">

`;
exports.GetValue = GetValue;
export * from './DanePobierzPelnyRaport.js';
export * from './DanePobierzRaportZbiorczy.js';
export * from './DaneSzukajPodmioty.js';
export * from './GetValue.js';
export * from './Zaloguj.js';
export * from './Wyloguj.js';

@@ -1,20 +0,6 @@

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (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 });
__exportStar(require("./DanePobierzPelnyRaport.js"), exports);
__exportStar(require("./DaneSzukajPodmioty.js"), exports);
__exportStar(require("./GetValue.js"), exports);
__exportStar(require("./Zaloguj.js"), exports);
export * from './DanePobierzPelnyRaport.js';
export * from './DanePobierzRaportZbiorczy.js';
export * from './DaneSzukajPodmioty.js';
export * from './GetValue.js';
export * from './Zaloguj.js';
export * from './Wyloguj.js';

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Zaloguj = void 0;
const Zaloguj = (params) => `
export const Zaloguj = (params) => `
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:ns="http://CIS/BIR/PUBL/2014/07">

@@ -17,2 +14,1 @@ <soap:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">

`;
exports.Zaloguj = Zaloguj;
{
"name": "bir1",
"version": "2.0.2",
"version": "3.0.1",
"description": "GUS REGON api client",

@@ -14,6 +14,13 @@ "keywords": [

"author": "Paweł Idczak <pawel.idczak@gmail.com>",
"type": "commonjs",
"exports": "./dist/index.js",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"type": "module",
"exports": {
".": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"./normalize": {
"types": "./dist/normalize.d.ts",
"default": "./dist/normalize.js"
}
},
"files": [

@@ -23,19 +30,26 @@ "dist"

"scripts": {
"docs": "rimraf docs && typedoc",
"build": "rimraf dist && tsc",
"dev": "tsc -w",
"test": "tap"
"test": "tap",
"pretty": "prettier --write src"
},
"dependencies": {
"entities": "^4.5.0",
"got": "^11.8.2",
"xml2js": "^0.6.2"
"fast-xml-parser": "^4.3.2",
"got": "^11.8.6"
},
"devDependencies": {
"@tapjs/tsx": "^1.1.18",
"@types/node": "^20.10.5",
"@types/xml2js": "^0.4.14",
"bir1-legacy": "npm:bir1@^2",
"dotenv": "^16.3.1",
"prettier": "3.2.5",
"rimraf": "^5.0.5",
"tap": "^18.6.1",
"tap": "^18.7.0",
"ts-node": "^10.9.2",
"typedoc": "^0.25.6",
"typedoc-plugin-markdown": "^3.17.1",
"typedoc-plugin-missing-exports": "^2.1.0",
"typedoc-plugin-rename-defaults": "^0.7.0",
"typescript": "^5.3.3"

@@ -45,9 +59,3 @@ },

"node": ">=16"
},
"tap": {
"plugin": [
"@tapjs/tsx",
"!@tapjs/typescript"
]
}
}
# BIR1 - GUS REGON client
Simple node.js client library to
[Statistics Poland](https://en.wikipedia.org/wiki/Statistics_Poland) (GUS)
information about companies
[api REGON](https://api.stat.gov.pl/Home/RegonApi?lang=en)
Simple node.js client library to provide information about authorized government
administration authorities, regional authorities, government institutions and to
commercial entities. It connects to
[REGON service](https://api.stat.gov.pl/Home/RegonApi?lang=en) and returns data
in JSON format. Data returned from original SOAP messages are parsed to JSON. By
default the following rules apply:
- the structure of the original SOAP messages are preserved (see original
messages in
[documentation](https://api.stat.gov.pl/Content/files/regon/GUS-Regon-UslugaBIR11-dokumentacja_v1.32.zip))
- keys are left intact (GUS use mix of snake_case and camelCase)
- values are converted to strings. Empty values are left as empty strings
Why BIR1 was choosen as package name? BIR1 (polish: "Baza Internetowa REGON") is
an internal name of the API service maintained by GUS.
Implementation follows good practices of modern node.js. It is ESM module
written in TypeScript with carefully crafted type definitions. Enjoy!
## Install
```bash
npm i bir1
npm install bir1
```
## Usage
## Quick start
```javascript
```js
import Bir from 'bir1'
const bir = new Bir()
await bir.login()
console.log(await bir.search({ nip: '5261040567' }))
// output:
// {
// Regon: '012100784',
// Nip: '5260250995',
// StatusNip: '',
// Nazwa: 'ORANGE POLSKA SPÓŁKA AKCYJNA',
// Wojewodztwo: 'MAZOWIECKIE',
// Powiat: 'm. st. Warszawa',
// Gmina: 'Ochota',
// Miejscowosc: 'Warszawa',
// KodPocztowy: '02-326',
// ...
// }
```
/*
output:
See more examples [here](./examples).
{
regon: '011417295',
nip: '5261040567',
statusNip: null,
nazwa: 'T-MOBILE POLSKA SPÓŁKA AKCYJNA',
wojewodztwo: 'MAZOWIECKIE',
powiat: 'Warszawa',
gmina: 'Mokotów',
miejscowosc: 'Warszawa',
kodPocztowy: '02-674',
ulica: 'ul. Marynarska',
nrNieruchomosci: '12',
nrLokalu: null,
typ: 'P',
silosID: '6',
dataZakonczeniaDzialalnosci: null,
miejscowoscPoczty: 'Warszawa'
}
*/
```
## API
### constructor
### Class: Bir
• **new Bir**(`options?`)
Class Bir provides access to REGON API
#### Parameters
#### Constructor
| Name | Type | Notes |
| -------------- | -------- | ------------------ |
| `options` | `Object` | |
| `options.key?` | `string` | production API key |
`new Bir(options?): Bir`
Note: by default it connects to non production GUS database using public default
key. In order to connect to production database with current company data
provide a key granted by GUS.
Create a new Bir instance.
### login
parameters:
▸ **login**(): `Promise`<void\>
- `options?: Object` - options object
- `options.key?: string` - API key. If this is not provided, the internally
stored public API key is used to access non-production GUS database. It allows
quick start, however non-production database contains old and anonymized data.
Providing GUS provided key connects to the production database.
- `options.normalizeFn?: (obj: any) => any` Function to modify response to a
more convenient format. Every JSON object extracted from SOAP message is
passed to this function. It should return modified object. E.g. it is possible
provide a function to to convert keys to camelCase or convert some values to
numbers.
#### Returns
#### Methods
`Promise`<void\>
`login(): Promise<void>`
Login to the API (method: Zaloguj)
This method uses the key provided in the constructor to login to the API. After
successful login, the session id (`sid`) is stored in class instance and used in
subsequent requests.
Starting from version 3.0 calling this method is optional as it is called
automatically.
---
### search
`value(value): Promise<string>`
▸ **search**(`query`): `Promise`<any\>
Get diagnostic information (method: GetValue)
#### Parameters
parameters:
| Name | Type | Notes |
| -------------- | -------- | ----- |
| `query` | `Object` | |
| `query.nip?` | `string` | |
| `query.regon?` | `string` | |
| `query.krs?` | `string` | |
- `value` - value to retrieve. One of:
- `StanDanych`
- `KomunikatKod`
- `KomunikatTresc`
- `StatusSesji`
- `StatusUslugi`
- `KomunikatUslugi`
#### Returns
---
`Promise`<any\>
`search(query): Promise<any>`
Search (method: DaneSzukajPodmioty). Returns basic information about entity.
parameters:
- `query: Object` - search query param. One of:
- `query.nip: string` - NIP number
- `query.regon: string` - REGON number
- `query.krs: string` - KRS number
example:
```js
import Bir from 'bir1'
const bir = new Bir()
console.log(await bir.search({ nip: '5261040567' }))
```
---
### report
`report(query): Promise<any>`
▸ **report**(`query`): `Promise`<any\>
Retrive report (method: DanePobierzPelnyRaport). Returns more detailed
information about entity depending on report type.
#### Parameters
parameters:
| Name | Type | Notes |
| -------------- | -------- | --------------------- |
| `query` | `Object` | |
| `query.regon` | `string` | |
| `query.report` | `string` | e.g.: `BIR11OsPrawna` |
- `query: Object`
- `query.regon: string` - REGON number
- `query.report` - report name. One of:
- `PublDaneRaportFizycznaOsoba`
- `PublDaneRaportDzialalnoscFizycznejCeidg`
- `PublDaneRaportDzialalnoscFizycznejRolnicza`
- `PublDaneRaportDzialalnoscFizycznejPozostala`
- `PublDaneRaportDzialalnoscFizycznejWKrupgn`
- `PublDaneRaportDzialalnosciFizycznej`
- `PublDaneRaportLokalneFizycznej`
- `PublDaneRaportLokalnaFizycznej`
- `PublDaneRaportDzialalnosciLokalnejFizycznej`
- `PublDaneRaportPrawna`
- `PublDaneRaportDzialalnosciPrawnej`
- `PublDaneRaportLokalnePrawnej`
- `PublDaneRaportLokalnaPrawnej`
- `PublDaneRaportDzialalnosciLokalnejPrawnej`
- `PublDaneRaportWspolnicyPrawnej`
- `PublDaneRaportTypJednostki`
- `BIR11OsFizycznaDaneOgolne`
- `BIR11OsFizycznaDzialalnoscCeidg`
- `BIR11OsFizycznaDzialalnoscRolnicza`
- `BIR11OsFizycznaDzialalnoscPozostala`
- `BIR11OsFizycznaDzialalnoscSkreslonaDo20141108`
- `BIR11OsFizycznaPkd`
- `BIR11OsFizycznaListaJednLokalnych`
- `BIR11JednLokalnaOsFizycznej`
- `BIR11JednLokalnaOsFizycznejPkd`
- `BIR11OsPrawna`
- `BIR11OsPrawnaPkd`
- `BIR11OsPrawnaListaJednLokalnych`
- `BIR11JednLokalnaOsPrawnej`
- `BIR11JednLokalnaOsPrawnejPkd`
- `BIR11OsPrawnaSpCywilnaWspolnicy`
- `BIR11TypPodmiotu`
See BIR1 original documentation for more report types.
example:
#### Returns
```js
import Bir from 'bir1'
`Promise`<any\>
const bir = new Bir()
console.log(
await bir.report({ regon: '012100784', report: 'PublDaneRaportPrawna' })
)
```
---
### value
`summary(query): Promise<any>`
▸ **value**(`value`): `Promise`<string\>
Retrive summary report (method: DanePobierzRaportZbiorczy). Returns summary of
changes in database.
#### Parameters
parameters:
| Name | Type |
| ------- | -------- |
| `value` | `string` |
- `query: Object`
- `query.date: string` - date in format YYYY-MM-DD not earlier than week before
- `query.report` - report name. One of:
- `BIR11NowePodmiotyPrawneOrazDzialalnosciOsFizycznych`
- `BIR11AktualizowanePodmiotyPrawneOrazDzialalnosciOsFizycznych`
- `BIR11SkreslonePodmiotyPrawneOrazDzialalnosciOsFizycznych`
- `BIR11NoweJednostkiLokalne`
- `BIR11AktualizowaneJednostkiLokalne`
- `BIR11SkresloneJednostkiLokalne`
#### Returns
---
`Promise`<string\>
`logout(): Promise<void>`
Logout (method: Wyloguj)
## Normalization
By default this library returns data in the same format as it is returned in
orginal SOAP messages.
Take a look at the following example showing default behavior:
```js
import Bir from 'bir1'
const bir = new Bir()
console.log(
await bir.report({
regon: '010058960',
report: 'BIR11OsPrawna',
})
)
// output:
// {
// praw_regon9: '010058960',
// praw_nip: '5220002334',
// praw_statusNip: '',
// praw_nazwa: 'POLSKIE LINIE LOTNICZE "LOT" SPÓŁKA AKCYJNA',
// praw_nazwaSkrocona: '',
// ...
// }
```
In above output keys have unnecessary prefix `praw_`. There is incosistent
casing, etc... Then in order to make it cleaner it is possible to provide a
function to normalize the response:
```js
import Bir from 'bir1'
import { modern } from 'bir1/normalize'
const bir = new Bir({ normalizeFn: modern })
console.log(
await bir.report({
regon: '010058960',
report: 'BIR11OsPrawna',
})
)
// output:
// {
// regon: '010058960',
// nip: '5220002334',
// statusNip: undefined,
// nazwa: 'POLSKIE LINIE LOTNICZE "LOT" SPÓŁKA AKCYJNA',
// nazwaSkrocona: undefined,
// ...
// }
```
Currently there are two normalization functions provided:
- `legacy` - to preserve the old behavior. Don't use it unless want to provide
backward compatibility with previous versions of the library. It does the
following:
- removes 'praw\_' prefix from keys
- lower first letter of keys
- replaces empty strings with `undefined`
- `modern` - to convert to modern format in consistent way. It does the
following:
- remove prefixes from keys (e.g. `fiz_`, `praw_`, ...)
- lower camel case keys
- unifies some keys (e.g. `regon9` -> `regon`)
- replaces empty strings with `undefined`
Using above functions is completely optional. It is also possible to provide own
function which takes JSON object and returns modified.
## Migrating from version 2.x to 3.x
Please note that starting from version 3.0 of that library the following
breaking changes were introduced:
1. the library is now pure ESM module (previously CJS)
2. the keys and values are returned 'as is' (previously they were processed)
- the keys are left intact (previously they were lowercased and a bit
trimmed)
- the empty values are now returned as empty strings (previously they were
returned as `undefined`)
See further details in the source code of [legacy](src/normalize.ts)
normalize function. This function can be used to preserve the old behavior as
shown in the [example](examples/normalize.js).
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