@qrxcode/js 0.1.1 → 0.3.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/LICENSE +21 -0
- package/README.md +126 -14
- package/dist/index.cjs +34 -26
- package/dist/index.d.cts +7 -5
- package/dist/index.d.ts +7 -5
- package/dist/index.js +33 -25
- package/package.json +6 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Yeldar Kudaibergen
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# QRX flow discovery SDK for JavaScript
|
|
2
2
|
|
|
3
|
-
Detect
|
|
3
|
+
Detect machine-readable flows from normal website and page URLs.
|
|
4
4
|
|
|
5
5
|
With QRX, applications with QR scanners can interact with QR codes
|
|
6
6
|
more like browsers interact with links.
|
|
@@ -29,12 +29,10 @@ and natural as following someone on social media.
|
|
|
29
29
|
|
|
30
30
|
Examples of flows:
|
|
31
31
|
|
|
32
|
-
-
|
|
33
|
-
- Atom feeds
|
|
34
|
-
- JSON feeds
|
|
32
|
+
- Feed flows
|
|
35
33
|
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
In QRX, a "flow" is a recognized machine-readable relationship
|
|
35
|
+
that applications can discover and interact with.
|
|
38
36
|
|
|
39
37
|
QRX does not replace RSS or existing feed technologies.
|
|
40
38
|
|
|
@@ -42,6 +40,57 @@ QRX helps applications discover and work with them more naturally.
|
|
|
42
40
|
|
|
43
41
|
Learn more at https://qrx.dev
|
|
44
42
|
|
|
43
|
+
## Breaking change in 0.3.0
|
|
44
|
+
|
|
45
|
+
Version `0.3.0` introduces a breaking cleanup of feed flow classification.
|
|
46
|
+
|
|
47
|
+
Before `0.3.0`, RSS, Atom, and JSON Feed were represented as separate
|
|
48
|
+
QRX flow types:
|
|
49
|
+
|
|
50
|
+
```js
|
|
51
|
+
{
|
|
52
|
+
flowType: "rss",
|
|
53
|
+
rel: "alternate",
|
|
54
|
+
href: "https://example.com/feed.xml",
|
|
55
|
+
type: "application/rss+xml"
|
|
56
|
+
}
|
|
57
|
+
````
|
|
58
|
+
|
|
59
|
+
Starting from `0.3.0`, RSS, Atom, and JSON Feed are represented as the same
|
|
60
|
+
QRX flow category:
|
|
61
|
+
|
|
62
|
+
```js
|
|
63
|
+
{
|
|
64
|
+
flowType: "feed",
|
|
65
|
+
rel: "alternate",
|
|
66
|
+
href: "https://example.com/feed.xml",
|
|
67
|
+
type: "application/rss+xml"
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
The actual feed format remains in the original HTML/link media type:
|
|
72
|
+
|
|
73
|
+
```js
|
|
74
|
+
type: "application/rss+xml"
|
|
75
|
+
type: "application/atom+xml"
|
|
76
|
+
type: "application/feed+json"
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Core formula:
|
|
80
|
+
|
|
81
|
+
```txt
|
|
82
|
+
flowType = QRX category
|
|
83
|
+
type = original web/media format
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Migration:
|
|
87
|
+
|
|
88
|
+
* `flow.flowType === "rss"` is now `flow.flowType === "feed" && flow.type === "application/rss+xml"`.
|
|
89
|
+
* `flow.flowType === "atom"` is now `flow.flowType === "feed" && flow.type === "application/atom+xml"`.
|
|
90
|
+
* `flow.flowType === "jsonfeed"` is now `flow.flowType === "feed" && flow.type === "application/feed+json"`.
|
|
91
|
+
|
|
92
|
+
QRX discovers recognized flows. Applications decide what to do with them.
|
|
93
|
+
|
|
45
94
|
## Install
|
|
46
95
|
|
|
47
96
|
```bash
|
|
@@ -65,21 +114,81 @@ console.log(result.flows);
|
|
|
65
114
|
```js
|
|
66
115
|
[
|
|
67
116
|
{
|
|
68
|
-
|
|
69
|
-
|
|
117
|
+
flowType: "feed",
|
|
118
|
+
rel: "alternate",
|
|
119
|
+
href: "https://podnews.net/rss",
|
|
120
|
+
type: "application/rss+xml"
|
|
70
121
|
},
|
|
71
122
|
{
|
|
72
|
-
|
|
73
|
-
|
|
123
|
+
flowType: "feed",
|
|
124
|
+
rel: "alternate",
|
|
125
|
+
href: "https://podnews.net/feed.json",
|
|
126
|
+
type: "application/feed+json"
|
|
74
127
|
}
|
|
75
128
|
]
|
|
76
129
|
```
|
|
77
130
|
|
|
131
|
+
## Selecting flows
|
|
132
|
+
|
|
133
|
+
To select all feed flows:
|
|
134
|
+
|
|
135
|
+
```js
|
|
136
|
+
import {
|
|
137
|
+
resolveQRX,
|
|
138
|
+
selectFlowsByFlowType
|
|
139
|
+
} from "@qrxcode/js";
|
|
140
|
+
|
|
141
|
+
const result = await resolveQRX(
|
|
142
|
+
"https://podnews.net"
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
const feeds = selectFlowsByFlowType(
|
|
146
|
+
result.flows,
|
|
147
|
+
["feed"]
|
|
148
|
+
);
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
This returns RSS, Atom, and JSON Feed flows together.
|
|
152
|
+
|
|
153
|
+
To select only RSS feeds, filter by the original media type:
|
|
154
|
+
|
|
155
|
+
```js
|
|
156
|
+
const rssFeeds = result.flows.filter(
|
|
157
|
+
(discoveredFlow) =>
|
|
158
|
+
discoveredFlow.flowType === "feed" &&
|
|
159
|
+
discoveredFlow.type === "application/rss+xml"
|
|
160
|
+
);
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
To select only Atom feeds:
|
|
164
|
+
|
|
165
|
+
```js
|
|
166
|
+
const atomFeeds = result.flows.filter(
|
|
167
|
+
(discoveredFlow) =>
|
|
168
|
+
discoveredFlow.flowType === "feed" &&
|
|
169
|
+
discoveredFlow.type === "application/atom+xml"
|
|
170
|
+
);
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
To select only JSON Feed feeds:
|
|
174
|
+
|
|
175
|
+
```js
|
|
176
|
+
const jsonFeeds = result.flows.filter(
|
|
177
|
+
(discoveredFlow) =>
|
|
178
|
+
discoveredFlow.flowType === "feed" &&
|
|
179
|
+
discoveredFlow.type === "application/feed+json"
|
|
180
|
+
);
|
|
181
|
+
```
|
|
182
|
+
|
|
78
183
|
## Supported flow types
|
|
79
184
|
|
|
80
|
-
*
|
|
81
|
-
|
|
82
|
-
|
|
185
|
+
* feed
|
|
186
|
+
|
|
187
|
+
## Supported feed formats
|
|
188
|
+
|
|
189
|
+
* RSS: `application/rss+xml`
|
|
190
|
+
* Atom: `application/atom+xml`
|
|
191
|
+
* JSON Feed: `application/feed+json`
|
|
83
192
|
|
|
84
193
|
## Supported discovery methods
|
|
85
194
|
|
|
@@ -108,6 +217,9 @@ console.log(result.flows);
|
|
|
108
217
|
|
|
109
218
|
QRX does not change QR codes.
|
|
110
219
|
|
|
220
|
+
QRX discovers recognized flows.
|
|
221
|
+
|
|
222
|
+
Applications decide what to do with them.
|
|
223
|
+
|
|
111
224
|
With QRX, sources can expose machine-readable flows,
|
|
112
225
|
and applications can understand and interact with them naturally.
|
|
113
|
-
|
package/dist/index.cjs
CHANGED
|
@@ -22,16 +22,16 @@ var index_exports = {};
|
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
detectFlows: () => detectFlows,
|
|
24
24
|
resolveQRX: () => resolveQRX,
|
|
25
|
-
|
|
25
|
+
selectFlowsByFlowType: () => selectFlowsByFlowType
|
|
26
26
|
});
|
|
27
27
|
module.exports = __toCommonJS(index_exports);
|
|
28
28
|
|
|
29
29
|
// src/detect.ts
|
|
30
|
-
var
|
|
31
|
-
"application/rss+xml"
|
|
32
|
-
"application/atom+xml"
|
|
33
|
-
"application/feed+json"
|
|
34
|
-
|
|
30
|
+
var FEED_TYPES = /* @__PURE__ */ new Set([
|
|
31
|
+
"application/rss+xml",
|
|
32
|
+
"application/atom+xml",
|
|
33
|
+
"application/feed+json"
|
|
34
|
+
]);
|
|
35
35
|
function detectFlows(html, sourceUrl) {
|
|
36
36
|
const flows = [];
|
|
37
37
|
const linkTagRegex = /<link\s+[^>]*>/gi;
|
|
@@ -40,54 +40,62 @@ function detectFlows(html, sourceUrl) {
|
|
|
40
40
|
const rel = getAttribute(tag, "rel");
|
|
41
41
|
const type = getAttribute(tag, "type");
|
|
42
42
|
const href = getAttribute(tag, "href");
|
|
43
|
-
if (!rel || !type || !href)
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
if (!rel || !type || !href) {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
const normalizedRel = rel.trim();
|
|
47
|
+
const normalizedType = type.trim().toLowerCase();
|
|
48
|
+
if (!hasRel(normalizedRel, "alternate")) {
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (!FEED_TYPES.has(normalizedType)) {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
47
54
|
flows.push({
|
|
48
|
-
|
|
49
|
-
|
|
55
|
+
flowType: "feed",
|
|
56
|
+
rel: normalizedRel,
|
|
57
|
+
href: new URL(href, sourceUrl).toString(),
|
|
58
|
+
type: normalizedType
|
|
50
59
|
});
|
|
51
60
|
}
|
|
52
|
-
return
|
|
61
|
+
return flows;
|
|
53
62
|
}
|
|
54
63
|
function getAttribute(tag, attribute) {
|
|
55
64
|
const regex = new RegExp(
|
|
56
|
-
`${attribute}
|
|
65
|
+
`${attribute}\\s*=\\s*["']([^"']+)["']`,
|
|
57
66
|
"i"
|
|
58
67
|
);
|
|
59
68
|
const match = tag.match(regex);
|
|
60
69
|
return match ? match[1] : null;
|
|
61
70
|
}
|
|
62
|
-
function
|
|
63
|
-
|
|
64
|
-
return flows.filter((flow) => {
|
|
65
|
-
const key = `${flow.type}:${flow.url}`;
|
|
66
|
-
if (seen.has(key)) return false;
|
|
67
|
-
seen.add(key);
|
|
68
|
-
return true;
|
|
69
|
-
});
|
|
71
|
+
function hasRel(rel, expected) {
|
|
72
|
+
return rel.toLowerCase().split(/\s+/).includes(expected);
|
|
70
73
|
}
|
|
71
74
|
|
|
72
75
|
// src/resolve.ts
|
|
73
76
|
async function resolveQRX(url) {
|
|
74
77
|
const response = await fetch(url);
|
|
75
78
|
const html = await response.text();
|
|
76
|
-
const flows = detectFlows(
|
|
79
|
+
const flows = detectFlows(
|
|
80
|
+
html,
|
|
81
|
+
response.url
|
|
82
|
+
);
|
|
77
83
|
return {
|
|
78
84
|
flows
|
|
79
85
|
};
|
|
80
86
|
}
|
|
81
87
|
|
|
82
88
|
// src/select.ts
|
|
83
|
-
function
|
|
89
|
+
function selectFlowsByFlowType(flows, preferredFlowTypes) {
|
|
84
90
|
return flows.filter(
|
|
85
|
-
(flow) =>
|
|
91
|
+
(flow) => preferredFlowTypes.includes(
|
|
92
|
+
flow.flowType
|
|
93
|
+
)
|
|
86
94
|
);
|
|
87
95
|
}
|
|
88
96
|
// Annotate the CommonJS export names for ESM import in node:
|
|
89
97
|
0 && (module.exports = {
|
|
90
98
|
detectFlows,
|
|
91
99
|
resolveQRX,
|
|
92
|
-
|
|
100
|
+
selectFlowsByFlowType
|
|
93
101
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
type FlowType = "
|
|
1
|
+
type FlowType = "feed";
|
|
2
2
|
interface Flow {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
flowType: FlowType;
|
|
4
|
+
rel: string;
|
|
5
|
+
href: string;
|
|
6
|
+
type: string;
|
|
5
7
|
}
|
|
6
8
|
interface QRXResult {
|
|
7
9
|
flows: Flow[];
|
|
@@ -11,6 +13,6 @@ declare function detectFlows(html: string, sourceUrl: string): Flow[];
|
|
|
11
13
|
|
|
12
14
|
declare function resolveQRX(url: string): Promise<QRXResult>;
|
|
13
15
|
|
|
14
|
-
declare function
|
|
16
|
+
declare function selectFlowsByFlowType(flows: Flow[], preferredFlowTypes: FlowType[]): Flow[];
|
|
15
17
|
|
|
16
|
-
export { type Flow, type FlowType, type QRXResult, detectFlows, resolveQRX,
|
|
18
|
+
export { type Flow, type FlowType, type QRXResult, detectFlows, resolveQRX, selectFlowsByFlowType };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
type FlowType = "
|
|
1
|
+
type FlowType = "feed";
|
|
2
2
|
interface Flow {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
flowType: FlowType;
|
|
4
|
+
rel: string;
|
|
5
|
+
href: string;
|
|
6
|
+
type: string;
|
|
5
7
|
}
|
|
6
8
|
interface QRXResult {
|
|
7
9
|
flows: Flow[];
|
|
@@ -11,6 +13,6 @@ declare function detectFlows(html: string, sourceUrl: string): Flow[];
|
|
|
11
13
|
|
|
12
14
|
declare function resolveQRX(url: string): Promise<QRXResult>;
|
|
13
15
|
|
|
14
|
-
declare function
|
|
16
|
+
declare function selectFlowsByFlowType(flows: Flow[], preferredFlowTypes: FlowType[]): Flow[];
|
|
15
17
|
|
|
16
|
-
export { type Flow, type FlowType, type QRXResult, detectFlows, resolveQRX,
|
|
18
|
+
export { type Flow, type FlowType, type QRXResult, detectFlows, resolveQRX, selectFlowsByFlowType };
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// src/detect.ts
|
|
2
|
-
var
|
|
3
|
-
"application/rss+xml"
|
|
4
|
-
"application/atom+xml"
|
|
5
|
-
"application/feed+json"
|
|
6
|
-
|
|
2
|
+
var FEED_TYPES = /* @__PURE__ */ new Set([
|
|
3
|
+
"application/rss+xml",
|
|
4
|
+
"application/atom+xml",
|
|
5
|
+
"application/feed+json"
|
|
6
|
+
]);
|
|
7
7
|
function detectFlows(html, sourceUrl) {
|
|
8
8
|
const flows = [];
|
|
9
9
|
const linkTagRegex = /<link\s+[^>]*>/gi;
|
|
@@ -12,53 +12,61 @@ function detectFlows(html, sourceUrl) {
|
|
|
12
12
|
const rel = getAttribute(tag, "rel");
|
|
13
13
|
const type = getAttribute(tag, "type");
|
|
14
14
|
const href = getAttribute(tag, "href");
|
|
15
|
-
if (!rel || !type || !href)
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
if (!rel || !type || !href) {
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
const normalizedRel = rel.trim();
|
|
19
|
+
const normalizedType = type.trim().toLowerCase();
|
|
20
|
+
if (!hasRel(normalizedRel, "alternate")) {
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
if (!FEED_TYPES.has(normalizedType)) {
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
19
26
|
flows.push({
|
|
20
|
-
|
|
21
|
-
|
|
27
|
+
flowType: "feed",
|
|
28
|
+
rel: normalizedRel,
|
|
29
|
+
href: new URL(href, sourceUrl).toString(),
|
|
30
|
+
type: normalizedType
|
|
22
31
|
});
|
|
23
32
|
}
|
|
24
|
-
return
|
|
33
|
+
return flows;
|
|
25
34
|
}
|
|
26
35
|
function getAttribute(tag, attribute) {
|
|
27
36
|
const regex = new RegExp(
|
|
28
|
-
`${attribute}
|
|
37
|
+
`${attribute}\\s*=\\s*["']([^"']+)["']`,
|
|
29
38
|
"i"
|
|
30
39
|
);
|
|
31
40
|
const match = tag.match(regex);
|
|
32
41
|
return match ? match[1] : null;
|
|
33
42
|
}
|
|
34
|
-
function
|
|
35
|
-
|
|
36
|
-
return flows.filter((flow) => {
|
|
37
|
-
const key = `${flow.type}:${flow.url}`;
|
|
38
|
-
if (seen.has(key)) return false;
|
|
39
|
-
seen.add(key);
|
|
40
|
-
return true;
|
|
41
|
-
});
|
|
43
|
+
function hasRel(rel, expected) {
|
|
44
|
+
return rel.toLowerCase().split(/\s+/).includes(expected);
|
|
42
45
|
}
|
|
43
46
|
|
|
44
47
|
// src/resolve.ts
|
|
45
48
|
async function resolveQRX(url) {
|
|
46
49
|
const response = await fetch(url);
|
|
47
50
|
const html = await response.text();
|
|
48
|
-
const flows = detectFlows(
|
|
51
|
+
const flows = detectFlows(
|
|
52
|
+
html,
|
|
53
|
+
response.url
|
|
54
|
+
);
|
|
49
55
|
return {
|
|
50
56
|
flows
|
|
51
57
|
};
|
|
52
58
|
}
|
|
53
59
|
|
|
54
60
|
// src/select.ts
|
|
55
|
-
function
|
|
61
|
+
function selectFlowsByFlowType(flows, preferredFlowTypes) {
|
|
56
62
|
return flows.filter(
|
|
57
|
-
(flow) =>
|
|
63
|
+
(flow) => preferredFlowTypes.includes(
|
|
64
|
+
flow.flowType
|
|
65
|
+
)
|
|
58
66
|
);
|
|
59
67
|
}
|
|
60
68
|
export {
|
|
61
69
|
detectFlows,
|
|
62
70
|
resolveQRX,
|
|
63
|
-
|
|
71
|
+
selectFlowsByFlowType
|
|
64
72
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qrxcode/js",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "QRX flow discovery SDK for JavaScript.",
|
|
5
5
|
"homepage": "https://qrx.dev",
|
|
6
6
|
"repository": {
|
|
@@ -21,7 +21,11 @@
|
|
|
21
21
|
"require": "./dist/index.cjs"
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
|
-
"files": [
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"README.md",
|
|
27
|
+
"LICENSE"
|
|
28
|
+
],
|
|
25
29
|
"scripts": {
|
|
26
30
|
"build": "tsup src/index.ts --format esm,cjs --dts",
|
|
27
31
|
"test": "vitest run",
|