bysquare 2.4.0 → 2.6.0

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.
package/lib/mjs/cli.js DELETED
@@ -1,83 +0,0 @@
1
- #!/usr/bin/env node
2
- import { existsSync, readFileSync } from "node:fs";
3
- import path from "node:path";
4
- import { createInterface } from "node:readline";
5
- import { generate } from "./generate.js";
6
- if /** bysquare "file" */ (process.stdin.isTTY) {
7
- handleInput(process.argv[2]);
8
- } /** bysquare <<< "data" */
9
- else {
10
- ;
11
- (async () => {
12
- const stdin = await handleStdin();
13
- console.log(fromJsonString(stdin));
14
- process.exit(0);
15
- })();
16
- }
17
- function handleInput(input) {
18
- if (input === undefined || input === "-h" || input === "--help") {
19
- console.log(help());
20
- process.exit(0);
21
- }
22
- if (existsSync(process.argv[2])) {
23
- const file = readFileSync(process.argv[2], "utf8");
24
- console.log(fromJsonString(file));
25
- }
26
- else {
27
- console.error(`File ${process.argv[2]} doesn't exists`);
28
- process.exit(1);
29
- }
30
- }
31
- function fromJsonString(stdin) {
32
- const data = JSON.parse(stdin);
33
- return generate(data);
34
- }
35
- async function handleStdin() {
36
- const readline = createInterface({
37
- input: process.stdin,
38
- output: process.stdout,
39
- terminal: false
40
- });
41
- const lines = [];
42
- return new Promise((resolve, reject) => {
43
- readline
44
- .on("line", (line) => {
45
- lines.push(line);
46
- })
47
- .on("close", () => {
48
- resolve(lines.join(""));
49
- })
50
- .on("SIGINT", /* CTRL+C */ reject);
51
- });
52
- }
53
- function help() {
54
- const exe = path.basename(process.argv[1]);
55
- return [
56
- "Simple Node.js library to generate 'PAY by square' QR string.",
57
- "",
58
- "Usage:",
59
- ` ${exe} file`,
60
- "",
61
- "File:",
62
- " Valid json file",
63
- "",
64
- "Flags:",
65
- " -h, --help display this help and exit",
66
- "",
67
- "If <file> is omitted, reads from stdin.",
68
- "",
69
- "Examples:",
70
- " bysquare <<< \"{",
71
- " \"invoiceId\": \"random-id\",",
72
- " \"payments\": [",
73
- " {",
74
- " \"type\": 1,",
75
- " \"amount\": 100.0,",
76
- " \"bankAccounts\": [{ \"iban\": \"SK9611000000002918599669\" }],",
77
- " \"currencyCode\": \"EUR\",",
78
- " \"variableSymbol\": \"123\"",
79
- " }",
80
- " ]",
81
- " }\""
82
- ].join("\n");
83
- }
@@ -1,56 +0,0 @@
1
- import { DataModel } from "./types.js";
2
- /**
3
- * Returns a 2 byte buffer that represents the header of the bysquare
4
- * specification
5
- *
6
- * ```
7
- * | Attribute | Number of bits | Possible values | Note
8
- * --------------------------------------------------------------------------------------------
9
- * | BySquareType | 4 | 0-15 | by square type
10
- * | Version | 4 | 0-15 | version of the by square type
11
- * | DocumentType | 4 | 0-15 | document type within given by square type
12
- * | Reserved | 4 | 0-15 | bits reserved for future needs
13
- * ```
14
- *
15
- * @see 3.5.
16
- */
17
- export declare function headerBysquare(
18
- /** dprint-ignore */
19
- header?: [
20
- bySquareType: number,
21
- version: number,
22
- documentType: number,
23
- reserved: number
24
- ]): Uint8Array;
25
- /**
26
- * Creates a one-byte array that represents the length of compressed data in
27
- * combination with CRC32 in bytes.
28
- */
29
- export declare function headerDataLength(length: number): Uint8Array;
30
- /**
31
- * Transfer object to a tabbed string and append a CRC32 checksum
32
- *
33
- * @see 3.10.
34
- */
35
- export declare function addChecksum(serialized: string): Uint8Array;
36
- /**
37
- * Transform data to ordered tab-separated intermediate representation ready for
38
- * encoding
39
- *
40
- * @see Table 15.
41
- */
42
- export declare function serialize(data: DataModel): string;
43
- type Options = {
44
- /**
45
- * Many banking apps do not support diacritics, which results in errors when
46
- * serializing data from QR codes.
47
- *
48
- * @default true
49
- */
50
- deburr: boolean;
51
- };
52
- /**
53
- * Generate QR string ready for encoding into text QR code
54
- */
55
- export declare function generate(model: DataModel, options?: Options): string;
56
- export {};
@@ -1,3 +0,0 @@
1
- export { generate } from "./generate.js";
2
- export { detect, parse } from "./parse.js";
3
- export * from "./types.js";
@@ -1,61 +0,0 @@
1
- {
2
- "name": "bysquare",
3
- "description": "It's a national standard for payment QR codes adopted by Slovak Banking Association (SBA)",
4
- "version": "2.4.0",
5
- "license": "Apache-2.0",
6
- "funding": "https://github.com/sponsors/xseman",
7
- "homepage": "https://github.com/xseman/bysquare#readme",
8
- "author": "Filip Seman <filip.seman@pm.me>",
9
- "keywords": [
10
- "pay by square",
11
- "qr string",
12
- "paybysquare",
13
- "bysquare"
14
- ],
15
- "repository": {
16
- "type": "git",
17
- "url": "git+https://github.com/xseman/bysquare.git"
18
- },
19
- "scripts": {
20
- "prebuild": "rm -rf ./lib || :",
21
- "build": ".scripts/build.sh",
22
- "postbuild": ".scripts/postbuild.sh",
23
- "test": "xv --loader=tsx ./src",
24
- "test:watch": "xv --loader=tsx --watch ./src",
25
- "typecheck": "tsc --noEmit",
26
- "cli:local": "npm run build && npm link bysquare",
27
- "preversion": "git checkout develop",
28
- "postversion": "npm run build && git flow release start v${npm_package_version}"
29
- },
30
- "dependencies": {
31
- "crc-32": "~1.2.0",
32
- "lodash.deburr": "~4.1.0",
33
- "lzma1": "~0.0.1",
34
- "rfc4648": "~1.5.0"
35
- },
36
- "devDependencies": {
37
- "@types/lodash.deburr": "~4.1.0",
38
- "@types/node": ">=16.14",
39
- "dprint": "~0.36.0",
40
- "tsx": "~3.12.0",
41
- "typescript": "~5.0.0",
42
- "xv": "~2.1.0"
43
- },
44
- "type": "module",
45
- "bin": "lib/mjs/cli.js",
46
- "types": "lib/mjs/index.d.ts",
47
- "exports": {
48
- ".": {
49
- "require": "./lib/cjs/index.js",
50
- "import": "./lib/mjs/index.js"
51
- }
52
- },
53
- "files": [
54
- "lib",
55
- "!lib/*.test.*"
56
- ],
57
- "engines": {
58
- "node": ">=16.14",
59
- "npm": ">=7.0"
60
- }
61
- }
@@ -1,25 +0,0 @@
1
- import { DataModel } from "./index.js";
2
- /**
3
- * Generating by square Code
4
- *
5
- * @see 3.14.
6
- */
7
- export declare function deserialize(qr: string): DataModel;
8
- export declare class DecodeError extends Error {
9
- cause: Error;
10
- name: string;
11
- constructor(cause: Error, msg?: string);
12
- }
13
- /**
14
- * Decoding client data from QR Code 2005 symbol
15
- *
16
- * @see 3.16.
17
- */
18
- export declare function parse(qr: string): DataModel;
19
- /**
20
- * Detect if qr string contains bysquare header.
21
- *
22
- * Bysquare header does not have too much information, therefore it is
23
- * not very reliable, there is room for improvement for the future.
24
- */
25
- export declare function detect(qr: string): boolean;
@@ -1,397 +0,0 @@
1
- /**
2
- * Mapping semantic version to encoded version number, header 4-bits
3
- *
4
- * It's a bit silly to limit the version number to 4-bit, if they keep
5
- * increasing the version number, the latest possible mapped value is 16
6
- */
7
- export declare const enum Version {
8
- /**
9
- * 2013-02-22
10
- * Created this document from original by square specifications
11
- */
12
- "1.0.0" = 0,
13
- /**
14
- * 2015-06-24
15
- * Added fields for beneficiary name and address
16
- */
17
- "1.1.0" = 1
18
- }
19
- /**
20
- * Selection of one or more months on which payment occurs. This is enabled
21
- * only if periodicity is set to one of the following value: “Weekly,
22
- * Biweekly, Monthly, Bimonthly”. Otherwise it must not be specified.
23
- */
24
- export declare enum MonthClassifier {
25
- January = 1,
26
- February = 2,
27
- March = 4,
28
- April = 8,
29
- May = 16,
30
- June = 32,
31
- July = 64,
32
- August = 128,
33
- September = 256,
34
- October = 512,
35
- November = 1024,
36
- December = 2048
37
- }
38
- /**
39
- * Periodicity of the payment. All valid options are „Daily“, „Weekly“,
40
- * „Biweekly“, „Monthly“, „Bimonthly“, „Quarterly“, „Annually“,
41
- * „Semiannually“. To find out which periodicity types are supported by the
42
- * banks see the following web site: http://www.sbaonline.sk/sk/
43
- */
44
- export declare enum Periodicity {
45
- Daily = "d",
46
- Weekly = "w",
47
- Biweekly = "b",
48
- Monthly = "m",
49
- Bimonthly = "B",
50
- Quarterly = "q",
51
- Semiannually = "s",
52
- Annually = "a"
53
- }
54
- /**
55
- * This is the payment day. It‘s meaning depends on the periodicity, meaning
56
- * either day of the month (number between 1 and 31) or day of the week
57
- * (1=Monday,2=Tuesday, …, 7=Sunday).
58
- *
59
- * Max length 2
60
- */
61
- export type Day = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31;
62
- export declare enum PaymentOptions {
63
- PaymentOrder = 1,
64
- StandingOrder = 2,
65
- DirectDebit = 4
66
- }
67
- /**
68
- * In section „encoding BankAccounts“ we provide further recommendations for
69
- * encoding bank account
70
- */
71
- export type BankAccount = {
72
- /**
73
- * Max length 34
74
- */
75
- iban: string;
76
- /**
77
- * Format ISO 9362 (swift)
78
- * 8 or 11 characters long
79
- */
80
- bic?: string;
81
- };
82
- /**
83
- * If DirectDebitScheme value is 1, which is „SEPA“ than encoded direct
84
- * debit follows SEPA direct debit scheme which means that fields MandateID,
85
- * CreditorID and optional ContractID are used. If direct debit scheme is 0,
86
- * which is „OTHER“ this means no specific direct debit scheme and following
87
- * rules do apply:
88
- *
89
- * a. Creditor is identified via bank accounts
90
- *
91
- * b. Contract between debtor and creditor is identified using one of the
92
- * following two ways: 1. by two optional fields SpecificSymbol and
93
- * VariableSymbol. 2. by one optional field OriginatorsReferenceInformation.
94
- * If SpecificSymbol and VariableSymbol fields or
95
- * OriginatorsReferenceInformation field is filled in DirectDebitExt then
96
- * these fields do apply for the direct debit.
97
- */
98
- export declare enum DirectDebitScheme {
99
- Other = 0,
100
- Sepa = 1
101
- }
102
- /**
103
- * Can be „one­off“ for one time debit or „recurrent“ for repeated debit
104
- * until cancelled.
105
- *
106
- * Max length 1
107
- */
108
- export declare enum DirectDebitType {
109
- OneOff = 0,
110
- Recurrent = 1
111
- }
112
- export type Beneficiary = {
113
- /**
114
- * Belongs to the N-th payment
115
- *
116
- * Max length 70
117
- */
118
- name?: string;
119
- /**
120
- * Belongs to the N-th payment
121
- * Commonly used street and street number
122
- *
123
- * Max length 70
124
- */
125
- street?: string;
126
- /**
127
- * Belongs to the N-th payment
128
- * Commonly used for City
129
- *
130
- * Max length 70
131
- */
132
- city?: string;
133
- };
134
- export type SimplePayment = {
135
- /**
136
- * Encoded with amount payable. This field is not required and can be left
137
- * blank in cases payment amount is not known ­such as donations.
138
- *
139
- * Decimal, max length 15
140
- */
141
- amount?: number;
142
- /**
143
- * 3 letter, payment currency code according to ISO-4217
144
- */
145
- currencyCode: keyof typeof CurrencyCodeEnum;
146
- /**
147
- * Format YYYYMMDD
148
- */
149
- paymentDueDate?: string;
150
- /**
151
- * Max length 10
152
- */
153
- variableSymbol?: string;
154
- /**
155
- * Max length 4
156
- */
157
- constantSymbol?: string;
158
- /**
159
- * Max length 10
160
- */
161
- specificSymbol?: string;
162
- /**
163
- * Max length 35
164
- */
165
- originatorRefInfo?: string;
166
- /**
167
- * Optional field. In previous section we provide further recommendations
168
- * for encoding payment note.
169
- *
170
- * Max length 140
171
- */
172
- paymentNote?: string;
173
- bankAccounts: BankAccount[];
174
- beneficiary?: Beneficiary;
175
- };
176
- export type PaymentOrder = SimplePayment & {
177
- type: PaymentOptions.PaymentOrder;
178
- };
179
- export type StandingOrder = SimplePayment & {
180
- type: PaymentOptions.StandingOrder;
181
- day?: Day;
182
- month?: MonthClassifier;
183
- periodicity?: Periodicity;
184
- /**
185
- * Defines the day of the last payment of the standing order. After this
186
- * date, standing order is cancelled.
187
- *
188
- * Format YYYYMMDD
189
- */
190
- lastDate?: string;
191
- };
192
- export type DirectDebit = SimplePayment & {
193
- type: PaymentOptions.DirectDebit;
194
- directDebitScheme?: DirectDebitScheme;
195
- directDebitType?: DirectDebitType;
196
- /**
197
- * Max length 35
198
- */
199
- mandateId?: string;
200
- /**
201
- * Max length 35
202
- */
203
- creditorId?: string;
204
- /**
205
- * Max length 35
206
- */
207
- contractId?: string;
208
- /**
209
- * Optional field. As most users prefer to set up some maximum amount for
210
- * the direct debit, this can be pre­-filled for them.
211
- *
212
- * Decimal, max length 15
213
- */
214
- maxAmount?: number;
215
- /**
216
- * Defines the day after which direct debit is cancelled.
217
- *
218
- * Max length 8
219
- * Format YYYYMMDD
220
- */
221
- validTillDate?: string;
222
- };
223
- export type Payment = PaymentOrder | StandingOrder | DirectDebit;
224
- export type DataModel = {
225
- /**
226
- * Max length 10
227
- */
228
- invoiceId?: string;
229
- payments: Payment[];
230
- };
231
- /**
232
- * Currency codes based on ISO-4217
233
- */
234
- export declare enum CurrencyCodeEnum {
235
- AED = "United Arab Emirates Dirham",
236
- AFN = "Afghanistan Afghani",
237
- ALL = "Albania Lek",
238
- AMD = "Armenia Dram",
239
- ANG = "Netherlands Antilles Guilder",
240
- AOA = "Angola Kwanza",
241
- ARS = "Argentina Peso",
242
- AUD = "Australia Dollar",
243
- AWG = "Aruba Guilder",
244
- AZN = "Azerbaijan New Manat",
245
- BAM = "Bosnia and Herzegovina Convertible Marka",
246
- BBD = "Barbados Dollar",
247
- BDT = "Bangladesh Taka",
248
- BGN = "Bulgaria Lev",
249
- BHD = "Bahrain Dinar",
250
- BIF = "Burundi Franc",
251
- BMD = "Bermuda Dollar",
252
- BND = "Brunei Darussalam Dollar",
253
- BOB = "Bolivia Bol\u00EDviano",
254
- BRL = "Brazil Real",
255
- BSD = "Bahamas Dollar",
256
- BTN = "Bhutan Ngultrum",
257
- BWP = "Botswana Pula",
258
- BYR = "Belarus Ruble",
259
- BZD = "Belize Dollar",
260
- CAD = "Canada Dollar",
261
- CDF = "Congo/Kinshasa Franc",
262
- CHF = "Switzerland Franc",
263
- CLP = "Chile Peso",
264
- CNY = "China Yuan Renminbi",
265
- COP = "Colombia Peso",
266
- CRC = "Costa Rica Colon",
267
- CUC = "Cuba Convertible Peso",
268
- CUP = "Cuba Peso",
269
- CVE = "Cape Verde Escudo",
270
- CZK = "Czech Republic Koruna",
271
- DJF = "Djibouti Franc",
272
- DKK = "Denmark Krone",
273
- DOP = "Dominican Republic Peso",
274
- DZD = "Algeria Dinar",
275
- EGP = "Egypt Pound",
276
- ERN = "Eritrea Nakfa",
277
- ETB = "Ethiopia Birr",
278
- EUR = "Euro Member Countries",
279
- FJD = "Fiji Dollar",
280
- FKP = "Falkland Islands = Malvinas Pound",
281
- GBP = "United Kingdom Pound",
282
- GEL = "Georgia Lari",
283
- GGP = "Guernsey Pound",
284
- GHS = "Ghana Cedi",
285
- GIP = "Gibraltar Pound",
286
- GMD = "Gambia Dalasi",
287
- GNF = "Guinea Franc",
288
- GTQ = "Guatemala Quetzal",
289
- GYD = "Guyana Dollar",
290
- HKD = "Hong Kong Dollar",
291
- HNL = "Honduras Lempira",
292
- HRK = "Croatia Kuna",
293
- HTG = "Haiti Gourde",
294
- HUF = "Hungary Forint",
295
- IDR = "Indonesia Rupiah",
296
- ILS = "Israel Shekel",
297
- IMP = "Isle of Man Pound",
298
- INR = "India Rupee",
299
- IQD = "Iraq Dinar",
300
- IRR = "Iran Rial",
301
- ISK = "Iceland Krona",
302
- JEP = "Jersey Pound",
303
- JMD = "Jamaica Dollar",
304
- JOD = "Jordan Dinar",
305
- JPY = "Japan Yen",
306
- KES = "Kenya Shilling",
307
- KGS = "Kyrgyzstan Som",
308
- KHR = "Cambodia Riel",
309
- KMF = "Comoros Franc",
310
- KPW = "Korea = North Won",
311
- KRW = "Korea = South Won",
312
- KWD = "Kuwait Dinar",
313
- KYD = "Cayman Islands Dollar",
314
- KZT = "Kazakhstan Tenge",
315
- LAK = "Laos Kip",
316
- LBP = "Lebanon Pound",
317
- LKR = "Sri Lanka Rupee",
318
- LRD = "Liberia Dollar",
319
- LSL = "Lesotho Loti",
320
- LYD = "Libya Dinar",
321
- MAD = "Morocco Dirham",
322
- MDL = "Moldova Leu",
323
- MGA = "Madagascar Ariary",
324
- MKD = "Macedonia Denar",
325
- MMK = "Myanmar = Burma Kyat",
326
- MNT = "Mongolia Tughrik",
327
- MOP = "Macau Pataca",
328
- MRO = "Mauritania Ouguiya",
329
- MUR = "Mauritius Rupee",
330
- MVR = "Maldives = Maldive Islands Rufiyaa",
331
- MWK = "Malawi Kwacha",
332
- MXN = "Mexico Peso",
333
- MYR = "Malaysia Ringgit",
334
- MZN = "Mozambique Metical",
335
- NAD = "Namibia Dollar",
336
- NGN = "Nigeria Naira",
337
- NIO = "Nicaragua Cordoba",
338
- NOK = "Norway Krone",
339
- NPR = "Nepal Rupee",
340
- NZD = "New Zealand Dollar",
341
- OMR = "Oman Rial",
342
- PAB = "Panama Balboa",
343
- PEN = "Peru Sol",
344
- PGK = "Papua New Guinea Kina",
345
- PHP = "Philippines Peso",
346
- PKR = "Pakistan Rupee",
347
- PLN = "Poland Zloty",
348
- PYG = "Paraguay Guarani",
349
- QAR = "Qatar Riyal",
350
- RON = "Romania New Leu",
351
- RSD = "Serbia Dinar",
352
- RUB = "Russia Ruble",
353
- RWF = "Rwanda Franc",
354
- SAR = "Saudi Arabia Riyal",
355
- SBD = "Solomon Islands Dollar",
356
- SCR = "Seychelles Rupee",
357
- SDG = "Sudan Pound",
358
- SEK = "Sweden Krona",
359
- SGD = "Singapore Dollar",
360
- SHP = "Saint Helena Pound",
361
- SLL = "Sierra Leone Leone",
362
- SOS = "Somalia Shilling",
363
- SPL = "Seborga Luigino",
364
- SRD = "Suriname Dollar",
365
- STD = "S\u00E3o Tom\u00E9 and Pr\u00EDncipe Dobra",
366
- SVC = "El Salvador Colon",
367
- SYP = "Syria Pound",
368
- SZL = "Swaziland Lilangeni",
369
- THB = "Thailand Baht",
370
- TJS = "Tajikistan Somoni",
371
- TMT = "Turkmenistan Manat",
372
- TND = "Tunisia Dinar",
373
- TOP = "Tonga Pa'anga",
374
- TRY = "Turkey Lira",
375
- TTD = "Trinidad and Tobago Dollar",
376
- TVD = "Tuvalu Dollar",
377
- TWD = "Taiwan New Dollar",
378
- TZS = "Tanzania Shilling",
379
- UAH = "Ukraine Hryvnia",
380
- UGX = "Uganda Shilling",
381
- USD = "United States Dollar",
382
- UYU = "Uruguay Peso",
383
- UZS = "Uzbekistan Som",
384
- VEF = "Venezuela Bolivar",
385
- VND = "Viet Nam Dong",
386
- VUV = "Vanuatu Vatu",
387
- WST = "Samoa Tala",
388
- XAF = "Communaut\u00E9 Financi\u00E8re Africaine = BEAC CFA Franc BEAC",
389
- XCD = "East Caribbean Dollar",
390
- XDR = "International Monetary Fund = IMF Special Drawing Rights",
391
- XOF = "Communaut\u00E9 Financi\u00E8re Africaine = BCEAO Franc",
392
- XPF = "Comptoirs Fran\u00E7ais du Pacifique = CFP Franc",
393
- YER = "Yemen Rial",
394
- ZAR = "South Africa Rand",
395
- ZMW = "Zambia Kwacha",
396
- ZWD = "Zimbabwe Dollar"
397
- }