@qrxcode/js 0.3.0 → 0.4.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 CHANGED
@@ -30,6 +30,7 @@ and natural as following someone on social media.
30
30
  Examples of flows:
31
31
 
32
32
  - Feed flows
33
+ - QRX flows
33
34
 
34
35
  In QRX, a "flow" is a recognized machine-readable relationship
35
36
  that applications can discover and interact with.
@@ -42,7 +43,7 @@ Learn more at https://qrx.dev
42
43
 
43
44
  ## Breaking change in 0.3.0
44
45
 
45
- Version `0.3.0` introduces a breaking cleanup of feed flow classification.
46
+ Version `0.3.0` introduced a breaking cleanup of feed flow classification.
46
47
 
47
48
  Before `0.3.0`, RSS, Atom, and JSON Feed were represented as separate
48
49
  QRX flow types:
@@ -91,6 +92,56 @@ Migration:
91
92
 
92
93
  QRX discovers recognized flows. Applications decide what to do with them.
93
94
 
95
+ ## New in 0.4.0
96
+
97
+ Version `0.4.0` adds a new flow category:
98
+
99
+ ```js
100
+ flowType: "qrx"
101
+ ```
102
+
103
+ A QRX flow is discovered from an explicit HTML `<link>` declaration:
104
+
105
+ ```html
106
+ <link
107
+ rel="qrx"
108
+ type="application/qrx+json"
109
+ href="/qrx.json">
110
+ ```
111
+
112
+ QRX flow discovery requires all of these:
113
+
114
+ * `rel="qrx"`
115
+ * `href`
116
+ * explicit `type`
117
+
118
+ For `qrx` flows, `rel` must be exactly `qrx`.
119
+
120
+ These are valid:
121
+
122
+ ```html
123
+ <link rel="qrx" type="application/qrx+json" href="/qrx.json">
124
+ <link rel="qrx" type="text/html" href="/demo.html">
125
+ <link rel="qrx" type="application/json" href="/manifest.json">
126
+ ```
127
+
128
+ These are not valid QRX flow declarations:
129
+
130
+ ```html
131
+ <link rel="alternate qrx" type="application/qrx+json" href="/qrx.json">
132
+ <link rel="qrx something" type="application/qrx+json" href="/qrx.json">
133
+ <link rel="notqrx" type="application/qrx+json" href="/qrx.json">
134
+ <link rel="qrx" href="/qrx.json">
135
+ ```
136
+
137
+ The `type` value can be any explicit media type, not only
138
+ `application/qrx+json`.
139
+
140
+ The package does not fetch or parse QRX payloads. It only discovers the
141
+ declared flow.
142
+
143
+ Applications decide what to do with discovered QRX flows.
144
+
94
145
  ## Install
95
146
 
96
147
  ```bash
@@ -103,7 +154,7 @@ npm install @qrxcode/js
103
154
  import { resolveQRX } from "@qrxcode/js";
104
155
 
105
156
  const result = await resolveQRX(
106
- "https://podnews.net"
157
+ "https://example.com"
107
158
  );
108
159
 
109
160
  console.log(result.flows);
@@ -116,14 +167,14 @@ console.log(result.flows);
116
167
  {
117
168
  flowType: "feed",
118
169
  rel: "alternate",
119
- href: "https://podnews.net/rss",
170
+ href: "https://example.com/feed.xml",
120
171
  type: "application/rss+xml"
121
172
  },
122
173
  {
123
- flowType: "feed",
124
- rel: "alternate",
125
- href: "https://podnews.net/feed.json",
126
- type: "application/feed+json"
174
+ flowType: "qrx",
175
+ rel: "qrx",
176
+ href: "https://example.com/qrx.json",
177
+ type: "application/qrx+json"
127
178
  }
128
179
  ]
129
180
  ```
@@ -139,7 +190,7 @@ import {
139
190
  } from "@qrxcode/js";
140
191
 
141
192
  const result = await resolveQRX(
142
- "https://podnews.net"
193
+ "https://example.com"
143
194
  );
144
195
 
145
196
  const feeds = selectFlowsByFlowType(
@@ -160,29 +211,19 @@ const rssFeeds = result.flows.filter(
160
211
  );
161
212
  ```
162
213
 
163
- To select only Atom feeds:
214
+ To select QRX flows:
164
215
 
165
216
  ```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"
217
+ const qrxFlows = selectFlowsByFlowType(
218
+ result.flows,
219
+ ["qrx"]
180
220
  );
181
221
  ```
182
222
 
183
223
  ## Supported flow types
184
224
 
185
225
  * feed
226
+ * qrx
186
227
 
187
228
  ## Supported feed formats
188
229
 
@@ -192,6 +233,8 @@ const jsonFeeds = result.flows.filter(
192
233
 
193
234
  ## Supported discovery methods
194
235
 
236
+ Feed flow:
237
+
195
238
  ```html
196
239
  <link
197
240
  rel="alternate"
@@ -213,6 +256,15 @@ const jsonFeeds = result.flows.filter(
213
256
  href="/feed.json">
214
257
  ```
215
258
 
259
+ QRX flow:
260
+
261
+ ```html
262
+ <link
263
+ rel="qrx"
264
+ type="application/qrx+json"
265
+ href="/qrx.json">
266
+ ```
267
+
216
268
  ## Philosophy
217
269
 
218
270
  QRX does not change QR codes.
package/dist/index.cjs CHANGED
@@ -45,6 +45,19 @@ function detectFlows(html, sourceUrl) {
45
45
  }
46
46
  const normalizedRel = rel.trim();
47
47
  const normalizedType = type.trim().toLowerCase();
48
+ const resolvedHref = new URL(
49
+ href,
50
+ sourceUrl
51
+ ).toString();
52
+ if (normalizedRel === "qrx") {
53
+ flows.push({
54
+ flowType: "qrx",
55
+ rel: normalizedRel,
56
+ href: resolvedHref,
57
+ type: normalizedType
58
+ });
59
+ continue;
60
+ }
48
61
  if (!hasRel(normalizedRel, "alternate")) {
49
62
  continue;
50
63
  }
@@ -54,7 +67,7 @@ function detectFlows(html, sourceUrl) {
54
67
  flows.push({
55
68
  flowType: "feed",
56
69
  rel: normalizedRel,
57
- href: new URL(href, sourceUrl).toString(),
70
+ href: resolvedHref,
58
71
  type: normalizedType
59
72
  });
60
73
  }
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- type FlowType = "feed";
1
+ type FlowType = "feed" | "qrx";
2
2
  interface Flow {
3
3
  flowType: FlowType;
4
4
  rel: string;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- type FlowType = "feed";
1
+ type FlowType = "feed" | "qrx";
2
2
  interface Flow {
3
3
  flowType: FlowType;
4
4
  rel: string;
package/dist/index.js CHANGED
@@ -17,6 +17,19 @@ function detectFlows(html, sourceUrl) {
17
17
  }
18
18
  const normalizedRel = rel.trim();
19
19
  const normalizedType = type.trim().toLowerCase();
20
+ const resolvedHref = new URL(
21
+ href,
22
+ sourceUrl
23
+ ).toString();
24
+ if (normalizedRel === "qrx") {
25
+ flows.push({
26
+ flowType: "qrx",
27
+ rel: normalizedRel,
28
+ href: resolvedHref,
29
+ type: normalizedType
30
+ });
31
+ continue;
32
+ }
20
33
  if (!hasRel(normalizedRel, "alternate")) {
21
34
  continue;
22
35
  }
@@ -26,7 +39,7 @@ function detectFlows(html, sourceUrl) {
26
39
  flows.push({
27
40
  flowType: "feed",
28
41
  rel: normalizedRel,
29
- href: new URL(href, sourceUrl).toString(),
42
+ href: resolvedHref,
30
43
  type: normalizedType
31
44
  });
32
45
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qrxcode/js",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "QRX flow discovery SDK for JavaScript.",
5
5
  "homepage": "https://qrx.dev",
6
6
  "repository": {