bysquare 2.5.0 → 2.7.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/README.md +57 -85
- package/dist/cli.js +75 -77
- package/dist/{parse.d.ts → decode.d.ts} +4 -1
- package/dist/{parse.js → decode.js} +4 -1
- package/dist/{generate.d.ts → encode.d.ts} +3 -1
- package/dist/{generate.js → encode.js} +3 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/package.json +8 -11
package/README.md
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
# bysquare
|
|
2
2
|
|
|
3
|
-
![version][version]
|
|
3
|
+
![version][version]
|
|
4
|
+
![build][build]
|
|
4
5
|
|
|
5
|
-
Simple JavaScript library to
|
|
6
|
+
Simple JavaScript library to encode and decode "PAY by square" string.
|
|
6
7
|
|
|
7
8
|
**What is `PAY by square`?**
|
|
8
9
|
|
|
@@ -18,77 +19,84 @@ transformed into images depends on how you implement it. See
|
|
|
18
19
|
|
|
19
20
|
## Install
|
|
20
21
|
|
|
22
|
+
**NOTE**: This package is native [ESM][mozzila-esm] and no longer provides a
|
|
23
|
+
CommonJS export. If your project uses CommonJS, you will have to convert to ESM
|
|
24
|
+
or use the dynamic [`import()`][mozzila-import] function.
|
|
25
|
+
|
|
21
26
|
**npm registry**
|
|
22
27
|
|
|
23
28
|
```sh
|
|
24
29
|
npm install bysquare
|
|
25
30
|
```
|
|
26
31
|
|
|
27
|
-
**CLI**
|
|
28
|
-
|
|
29
|
-
```sh
|
|
30
|
-
npm install --global bysquare
|
|
31
|
-
```
|
|
32
|
-
|
|
33
32
|
**Browser**
|
|
34
33
|
|
|
35
34
|
```html
|
|
36
35
|
<script type="module">
|
|
37
|
-
import {
|
|
36
|
+
import { encode, decode } from "https://esm.sh/bysquare@2.4.0/";
|
|
38
37
|
</script>
|
|
39
38
|
```
|
|
40
39
|
|
|
41
40
|
**Deno** `v1.28+`, just import `npm:bysquare` `v2.1.0+`
|
|
42
41
|
|
|
43
42
|
```ts
|
|
44
|
-
import {
|
|
43
|
+
import { encode, decode } from "npm:bysquare@2.1.0";
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
**CLI** (Node.JS `v18`+)
|
|
47
|
+
|
|
48
|
+
```sh
|
|
49
|
+
npm install --global bysquare
|
|
45
50
|
```
|
|
46
51
|
|
|
47
|
-
|
|
52
|
+
# How it works
|
|
48
53
|
|
|
49
|
-
|
|
54
|
+
## Encoding sequence
|
|
50
55
|
|
|
51
56
|

|
|
52
57
|
|
|
53
|
-
|
|
58
|
+
# API
|
|
54
59
|
|
|
55
60
|
```ts
|
|
56
|
-
|
|
57
|
-
|
|
61
|
+
encode(model: DataModel, options?: Options): string
|
|
62
|
+
decode(qr: string): DataModel
|
|
58
63
|
detect(qr: string): Boolean
|
|
59
64
|
```
|
|
60
65
|
|
|
61
|
-
|
|
66
|
+
# Usage
|
|
62
67
|
|
|
63
|
-
|
|
68
|
+
## Encode
|
|
64
69
|
|
|
65
70
|
```ts
|
|
66
|
-
import { CurrencyCode, DataModel,
|
|
71
|
+
import { CurrencyCode, DataModel, encode, PaymentOptions } from "bysquare";
|
|
67
72
|
|
|
68
|
-
//
|
|
69
|
-
const qrString =
|
|
73
|
+
// string ready to be encoded to QR
|
|
74
|
+
const qrString = encode({
|
|
70
75
|
invoiceId: "random-id",
|
|
71
76
|
payments: [
|
|
72
77
|
{
|
|
73
78
|
type: PaymentOptions.PaymentOrder,
|
|
74
79
|
amount: 100.0,
|
|
75
80
|
bankAccounts: [
|
|
76
|
-
{
|
|
81
|
+
{
|
|
82
|
+
iban: "SK9611000000002918599669",
|
|
83
|
+
},
|
|
77
84
|
],
|
|
78
85
|
currencyCode: CurrencyCode.EUR,
|
|
79
|
-
variableSymbol: "123"
|
|
80
|
-
}
|
|
81
|
-
]
|
|
82
|
-
})
|
|
86
|
+
variableSymbol: "123",
|
|
87
|
+
},
|
|
88
|
+
],
|
|
89
|
+
});
|
|
83
90
|
```
|
|
84
91
|
|
|
85
|
-
|
|
92
|
+
## Decode
|
|
86
93
|
|
|
87
94
|
```ts
|
|
88
|
-
import {
|
|
95
|
+
import { decode } from "bysquare";
|
|
89
96
|
|
|
90
|
-
const model =
|
|
91
|
-
|
|
97
|
+
const model = decode(
|
|
98
|
+
"0405QH8090IFU27IV0J6HGGLIOTIBVHNQQJQ6LAVGNBT363HR13JC6CB54HSI0KH9FCRASHNQBSKAQD2LJ4AU400UVKDNDPFRKLOBEVVVU0QJ000"
|
|
99
|
+
);
|
|
92
100
|
|
|
93
101
|
// {
|
|
94
102
|
// invoiceId: "random-id",
|
|
@@ -107,72 +115,36 @@ const model =
|
|
|
107
115
|
//
|
|
108
116
|
```
|
|
109
117
|
|
|
110
|
-
|
|
118
|
+
# CLI
|
|
119
|
+
|
|
120
|
+
## Encode
|
|
121
|
+
|
|
122
|
+
Encode JSON data from a file and print the corresponding QR code. The file
|
|
123
|
+
argument should be a path to a JSON file.
|
|
111
124
|
|
|
112
125
|
```sh
|
|
113
|
-
|
|
114
|
-
# {
|
|
115
|
-
# "invoiceId": "random-id",
|
|
116
|
-
# "payments": [
|
|
117
|
-
# {
|
|
118
|
-
# "type": 1,
|
|
119
|
-
# "amount": 100.0,
|
|
120
|
-
# "bankAccounts": [{ "iban": "SK9611000000002918599669" }],
|
|
121
|
-
# "currencyCode": "EUR",
|
|
122
|
-
# "variableSymbol": "123"
|
|
123
|
-
# }
|
|
124
|
-
# ]
|
|
125
|
-
# }
|
|
126
|
-
|
|
127
|
-
$ npx bysquare ./example.json
|
|
128
|
-
$ 0405QH8090IFU27IV0J6HGGLIOTIBVHNQQJQ6LAVGNBT363HR13JC6CB54HSI0KH9FCRASHNQBSKAQD2LJ4AU400UVKDNDPFRKLOBEVVVU0QJ000
|
|
126
|
+
npx bysquare --encode <file>
|
|
129
127
|
```
|
|
130
128
|
|
|
131
|
-
|
|
129
|
+
## Decode
|
|
130
|
+
|
|
131
|
+
Decode the specified QR code string and print the corresponding JSON data. The
|
|
132
|
+
qrstring argument should be a valid QR code string.
|
|
132
133
|
|
|
133
134
|
```sh
|
|
134
|
-
|
|
135
|
-
"invoiceId": "random-id",
|
|
136
|
-
"payments": [
|
|
137
|
-
{
|
|
138
|
-
"type": 1,
|
|
139
|
-
"amount": 100.0,
|
|
140
|
-
"bankAccounts": [{ "iban": "SK9611000000002918599669" }],
|
|
141
|
-
"currencyCode": "EUR",
|
|
142
|
-
"variableSymbol": "123"
|
|
143
|
-
}
|
|
144
|
-
]
|
|
145
|
-
}'
|
|
146
|
-
|
|
147
|
-
$ 0405QH8090IFU27IV0J6HGGLIOTIBVHNQQJQ6LAVGNBT363HR13JC6CB54HSI0KH9FCRASHNQBSKAQD2LJ4AU400UVKDNDPFRKLOBEVVVU0QJ000
|
|
135
|
+
npx bysquare --decode <qrstring>
|
|
148
136
|
```
|
|
149
137
|
|
|
150
138
|
## Related
|
|
151
139
|
|
|
152
|
-
-
|
|
153
|
-
-
|
|
154
|
-
-
|
|
155
|
-
-
|
|
156
|
-
-
|
|
157
|
-
-
|
|
158
|
-
|
|
159
|
-
<!--
|
|
160
|
-
Versioning
|
|
161
|
-
----------
|
|
162
|
-
|
|
163
|
-
https://github.com/dherges/npm-version-git-flow
|
|
164
|
-
|
|
165
|
-
- Stash unfinished work
|
|
166
|
-
- Run `npm test`
|
|
167
|
-
- Run `npm version <patch, minor, major>`
|
|
168
|
-
- Commit and push
|
|
169
|
-
- Follow git-flow instructions
|
|
170
|
-
- Checkout to master
|
|
171
|
-
- Build artefacts
|
|
172
|
-
- Push commits and tag, git push && git push --tags
|
|
173
|
-
- Validate with `npm publish --dry-run`
|
|
174
|
-
- Publish to npm, `npm publish`
|
|
175
|
-
-->
|
|
140
|
+
- <https://bysquare.com/>
|
|
141
|
+
- <https://devel.cz/otazka/qr-kod-pay-by-square>
|
|
142
|
+
- <https://github.com/matusf/pay-by-square>
|
|
143
|
+
- <https://www.bsqr.co/schema/>
|
|
144
|
+
- <https://www.sbaonline.sk/wp-content/uploads/2020/03/pay-by-square-specifications-1_1_0.pdf>
|
|
145
|
+
- <https://www.vutbr.cz/studenti/zav-prace/detail/78439>
|
|
176
146
|
|
|
177
147
|
[build]: https://img.shields.io/github/actions/workflow/status/xseman/bysquare/tests.yml
|
|
178
148
|
[version]: https://img.shields.io/npm/v/bysquare
|
|
149
|
+
[mozzila-esm]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
|
|
150
|
+
[mozzila-import]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import
|
package/dist/cli.js
CHANGED
|
@@ -1,83 +1,81 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { existsSync, readFileSync } from "node:fs";
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
3
|
+
import { parseArgs } from "node:util";
|
|
4
|
+
import { encode } from "./encode.js";
|
|
5
|
+
import { decode } from "./decode.js";
|
|
6
|
+
const args = parseArgs({
|
|
7
|
+
allowPositionals: true,
|
|
8
|
+
options: {
|
|
9
|
+
decode: {
|
|
10
|
+
type: "string",
|
|
11
|
+
short: "d"
|
|
12
|
+
},
|
|
13
|
+
encode: {
|
|
14
|
+
type: "string",
|
|
15
|
+
short: "e"
|
|
16
|
+
},
|
|
17
|
+
help: {
|
|
18
|
+
type: "boolean",
|
|
19
|
+
short: "h"
|
|
20
|
+
}
|
|
21
21
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
});
|
|
23
|
+
if (process.stdin.isTTY) {
|
|
24
|
+
/** json file */
|
|
25
|
+
if (args.values.encode) {
|
|
26
|
+
const file = args.values.encode;
|
|
27
|
+
if (existsSync(file)) {
|
|
28
|
+
const data = readFileSync(file, "utf8");
|
|
29
|
+
console.log(encode(JSON.parse(data)));
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
console.error(`File ${file} doesn't exists`);
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
25
35
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
36
|
+
/** input string */
|
|
37
|
+
if (args.values.decode) {
|
|
38
|
+
const qrstring = args.values.decode;
|
|
39
|
+
console.log(JSON.stringify(decode(qrstring), null, 4));
|
|
40
|
+
}
|
|
41
|
+
if (args.values.help || Object.keys(args.values).length === 0) {
|
|
42
|
+
console.log([
|
|
43
|
+
"NAME",
|
|
44
|
+
" bysquare - Simple Node.js library to generate and parse PAY bysquare standard",
|
|
45
|
+
"",
|
|
46
|
+
"SYNOPSIS",
|
|
47
|
+
" bysquare [OPTIONS]",
|
|
48
|
+
"",
|
|
49
|
+
"DESCRIPTION",
|
|
50
|
+
" bysquare is a command-line tool that provides a simple Node.js library to generate ",
|
|
51
|
+
" and parse PAY bysquare standard. It offers functionality to encode JSON data into a ",
|
|
52
|
+
" corresponding QR code and decode a QR code string to obtain the associated JSON data.",
|
|
53
|
+
"",
|
|
54
|
+
"OPTIONS",
|
|
55
|
+
" -d, --decode <qrstring>",
|
|
56
|
+
" Decode the specified QR code string and print the corresponding JSON data.",
|
|
57
|
+
" The qrstring argument should be a valid QR code string.",
|
|
58
|
+
"",
|
|
59
|
+
" -e, --encode <file>",
|
|
60
|
+
" Encode JSON data from a file and print the corresponding QR code.",
|
|
61
|
+
" The file argument should be a path to a JSON file.",
|
|
62
|
+
"",
|
|
63
|
+
" -h, --help",
|
|
64
|
+
" Display the help message and exit.",
|
|
65
|
+
"",
|
|
66
|
+
"USAGE",
|
|
67
|
+
" Encoding JSON data from a file",
|
|
68
|
+
"",
|
|
69
|
+
` ${process.argv[1]} --encode <file>`,
|
|
70
|
+
" The <file> argument should be the path to the JSON file you want to encode.",
|
|
71
|
+
" The tool will read the file, generate a QR code representing the JSON data",
|
|
72
|
+
"",
|
|
73
|
+
" Decoding a QR code string",
|
|
74
|
+
"",
|
|
75
|
+
` ${process.argv[1]} --decode <qrstring>`,
|
|
76
|
+
" Replace qrstring with the QR code string you want to decode.",
|
|
77
|
+
" The program will parse the QR code string and print the resulting JSON data.",
|
|
78
|
+
""
|
|
79
|
+
].join("\n"));
|
|
29
80
|
}
|
|
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
81
|
}
|
|
@@ -10,12 +10,15 @@ export declare class DecodeError extends Error {
|
|
|
10
10
|
name: string;
|
|
11
11
|
constructor(cause: Error, msg?: string);
|
|
12
12
|
}
|
|
13
|
+
/** @deprecated */
|
|
14
|
+
export declare const parse: typeof decode;
|
|
13
15
|
/**
|
|
14
16
|
* Decoding client data from QR Code 2005 symbol
|
|
15
17
|
*
|
|
16
18
|
* @see 3.16.
|
|
19
|
+
*
|
|
17
20
|
*/
|
|
18
|
-
export declare function
|
|
21
|
+
export declare function decode(qr: string): DataModel;
|
|
19
22
|
/**
|
|
20
23
|
* Detect if qr string contains bysquare header.
|
|
21
24
|
*
|
|
@@ -155,12 +155,15 @@ export class DecodeError extends Error {
|
|
|
155
155
|
this.name = "DecodeError";
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
|
+
/** @deprecated */
|
|
159
|
+
export const parse = decode;
|
|
158
160
|
/**
|
|
159
161
|
* Decoding client data from QR Code 2005 symbol
|
|
160
162
|
*
|
|
161
163
|
* @see 3.16.
|
|
164
|
+
*
|
|
162
165
|
*/
|
|
163
|
-
export function
|
|
166
|
+
export function decode(qr) {
|
|
164
167
|
try {
|
|
165
168
|
var bytes = base32hex.parse(qr, {
|
|
166
169
|
loose: true
|
|
@@ -49,8 +49,10 @@ type Options = {
|
|
|
49
49
|
*/
|
|
50
50
|
deburr: boolean;
|
|
51
51
|
};
|
|
52
|
+
/** @deprecated */
|
|
53
|
+
export declare const generate: typeof encode;
|
|
52
54
|
/**
|
|
53
55
|
* Generate QR string ready for encoding into text QR code
|
|
54
56
|
*/
|
|
55
|
-
export declare function
|
|
57
|
+
export declare function encode(model: DataModel, options?: Options): string;
|
|
56
58
|
export {};
|
|
@@ -137,10 +137,12 @@ function removeDiacritics(model) {
|
|
|
137
137
|
}
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
|
+
/** @deprecated */
|
|
141
|
+
export const generate = encode;
|
|
140
142
|
/**
|
|
141
143
|
* Generate QR string ready for encoding into text QR code
|
|
142
144
|
*/
|
|
143
|
-
export function
|
|
145
|
+
export function encode(model, options = { deburr: true }) {
|
|
144
146
|
if (options.deburr) {
|
|
145
147
|
removeDiacritics(model);
|
|
146
148
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { generate } from "./
|
|
2
|
-
export { detect, parse } from "./
|
|
1
|
+
export { generate } from "./encode.js";
|
|
2
|
+
export { detect, parse } from "./decode.js";
|
|
3
3
|
export * from "./types.js";
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { generate } from "./
|
|
2
|
-
export { detect, parse } from "./
|
|
1
|
+
export { generate } from "./encode.js";
|
|
2
|
+
export { detect, parse } from "./decode.js";
|
|
3
3
|
export * from "./types.js";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bysquare",
|
|
3
3
|
"description": "It's a national standard for payment QR codes adopted by Slovak Banking Association (SBA)",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.7.0",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"funding": "https://github.com/sponsors/xseman",
|
|
7
7
|
"homepage": "https://github.com/xseman/bysquare#readme",
|
|
@@ -21,11 +21,10 @@
|
|
|
21
21
|
"build": "tsc --build",
|
|
22
22
|
"format": "dprint fmt ./src/**/*",
|
|
23
23
|
"typecheck": "tsc --noEmit",
|
|
24
|
-
"test": "xv --loader=tsx ./src",
|
|
25
|
-
"test:watch": "xv --loader=tsx --watch ./src",
|
|
26
|
-
"cli:local": "npm run build && npm link bysquare",
|
|
27
24
|
"version": "git checkout develop && npm test",
|
|
28
|
-
"postversion": "echo 'Now run npm run build && npm publish'"
|
|
25
|
+
"postversion": "echo 'Now run npm run build && npm publish'",
|
|
26
|
+
"test": "node --test --loader tsx --no-warnings src/*.test.ts",
|
|
27
|
+
"test:watch": "node --test --watch --loader tsx --no-warnings src/*.test.ts"
|
|
29
28
|
},
|
|
30
29
|
"dependencies": {
|
|
31
30
|
"crc-32": "~1.2.0",
|
|
@@ -36,15 +35,13 @@
|
|
|
36
35
|
"devDependencies": {
|
|
37
36
|
"@types/lodash.deburr": "~4.1.0",
|
|
38
37
|
"@types/node": ">=16.14",
|
|
39
|
-
"dprint": "~0.
|
|
38
|
+
"dprint": "~0.41.0",
|
|
40
39
|
"tsx": "~3.12.0",
|
|
41
|
-
"typescript": "~5.0.0"
|
|
42
|
-
"xv": "~2.1.0"
|
|
40
|
+
"typescript": "~5.0.0"
|
|
43
41
|
},
|
|
44
42
|
"type": "module",
|
|
45
43
|
"bin": "./dist/cli.js",
|
|
46
44
|
"types": "./dist/index.d.ts",
|
|
47
|
-
"main": "./dist/index.js",
|
|
48
45
|
"module": "./dist/index.js",
|
|
49
46
|
"exports": {
|
|
50
47
|
".": {
|
|
@@ -56,7 +53,7 @@
|
|
|
56
53
|
"!dist/*.test.*"
|
|
57
54
|
],
|
|
58
55
|
"engines": {
|
|
59
|
-
"node": ">=
|
|
60
|
-
"npm": ">=7
|
|
56
|
+
"node": ">=16",
|
|
57
|
+
"npm": ">=7"
|
|
61
58
|
}
|
|
62
59
|
}
|