rida-format 2.0.0 → 2.0.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.0.1 — Encrypted delivery and application examples
4
+
5
+ - Added direct encrypted CDN delivery guidance and server-only key handling.
6
+ - Added detailed product catalogue and multilingual help-centre examples.
7
+ - Clarified whole-field reads, nested values, map lookup, and multi-field requests.
8
+ - Updated documentation and package numbering; the data format is unchanged.
9
+
3
10
  ## 2.0.0 — Detailed usage guide
4
11
 
5
12
  - Expanded the Node.js README with installation, CLI and JavaScript API instructions.
package/README.md CHANGED
@@ -750,6 +750,73 @@ length, or catalog structure. An app that receives the key must protect it as
750
750
  carefully as any other secret; a key embedded in a client app can be extracted
751
751
  by someone who controls that device.
752
752
 
753
+ ### Encrypted data directly from your CDN
754
+
755
+ You can host an encrypted RIDA data file at a public CDN URL while keeping its
756
+ contents unreadable without the decryption key. The reader uses its index to
757
+ find the requested value, downloads that encrypted byte range, and decrypts it
758
+ where the reader runs. You do not need to download the whole dataset first.
759
+
760
+ ```text
761
+ Reader with a key → CDN byte-range request → encrypted value → local decryption
762
+ ```
763
+
764
+ For example, a page record can contain separate `english`, `hindi`, `urdu`, and
765
+ `spanish` fields. Requesting page 2's `spanish` field downloads the stored bytes
766
+ for that field, including encryption overhead. If Spanish contains a complete
767
+ object with a title, paragraphs, and steps, you receive that complete object.
768
+ A larger value needs a larger range: RIDA does not make every response a fixed
769
+ number of bytes. HTTP headers and network overhead are additional to the value.
770
+
771
+ #### Option 1: give the authorized reader the key
772
+
773
+ Your application can authorize a user and provide the key to a compatible
774
+ reader. Subsequent reads can go directly to the CDN, with decryption on the
775
+ user's device. Keep the index and map with the reader so it can find the correct
776
+ record and field without guessing paths.
777
+
778
+ If your Worker or backend would otherwise exist only to validate a token on
779
+ **every data request**, this arrangement can avoid that proxy's execution and
780
+ extra network hop for those reads. RIDA itself adds no encryption subscription
781
+ fee. Storage, CDN delivery, your authorization service, and other hosting
782
+ services can still have charges; this is not a promise that every CDN security
783
+ feature or paid plan becomes unnecessary.
784
+
785
+ The trade-off is that a user who holds the key can copy it and read the values
786
+ encrypted with it. A public URL lets anyone download ciphertext; encryption
787
+ protects the contents, not access to that URL. The index and map can also reveal
788
+ record names, field names, and dataset structure.
789
+
790
+ Expiring a session or token does **not** revoke a copied key. To exclude that
791
+ key from future data, use a new key and newly encrypted data. Previously
792
+ downloaded data remains readable with its original key. Choose this approach
793
+ when your application accepts these limits.
794
+
795
+ #### Option 2: keep the key on your Next.js server
796
+
797
+ Store the key in a server-only environment variable such as `RIDA_KEY`. Never
798
+ use a `NEXT_PUBLIC_` variable for it, import it into client code, or return the
799
+ key in an API response. Keep the key file out of public assets as well.
800
+
801
+ ```text
802
+ User → your server checks access → CDN encrypted range
803
+ → server decrypts → permitted content returned to the user
804
+ ```
805
+
806
+ Your server checks the user's permission, fetches the requested encrypted range,
807
+ decrypts it, and returns the permitted content. The key stays on the server,
808
+ but reads now pass through your backend and its running costs remain. Keeping a
809
+ key in an environment variable does not by itself give a browser direct reads:
810
+ the browser needs the key to decrypt locally, or the server must decrypt for it.
811
+
812
+ Use this option when each read needs an account permission check. Encryption
813
+ and per-request authorization solve different problems; choose where decryption
814
+ happens according to the access rules your application needs.
815
+
816
+ The npm package runs in Node.js, including a Next.js server. Direct decryption
817
+ in a browser or mobile app requires a compatible reader for that platform;
818
+ installing this Node.js package does not itself supply a browser reader.
819
+
753
820
  ## Read a local dataset
754
821
 
755
822
  The reader finds a sibling `NameIndex.rida` automatically. For a local file it
@@ -1091,6 +1158,159 @@ Reading a dataset does not convert or rewrite it. The Node.js code can read a
1091
1158
  compatible dataset built by the Python RIDA 0.3.3 release. Building a dataset
1092
1159
  creates new output files from JSON; it does not edit the source JSON.
1093
1160
 
1161
+ ## Detailed application examples
1162
+
1163
+ These examples use numbered record IDs and the generated map. Build each example folder as its own dataset. The IDs shown apply only to these exact folder trees; adding or rearranging records can change numbered positions.
1164
+
1165
+ ### One product. Only the description your customer needs.
1166
+
1167
+ Your product catalogue can contain thousands of records. Each product may have a price, specifications, images, stock information, and descriptions in several languages.
1168
+
1169
+ ```text
1170
+ catalogue/
1171
+ └── products/
1172
+ └── 2812.json
1173
+ ```
1174
+
1175
+ Example record:
1176
+
1177
+ ```json
1178
+ {
1179
+ "name": "Travel Backpack",
1180
+ "price": 49,
1181
+ "stock": 120,
1182
+ "specifications": {
1183
+ "capacity": "30 litres",
1184
+ "weight": "900 grams"
1185
+ },
1186
+ "english": {
1187
+ "title": "Ready for everyday travel",
1188
+ "description": "A lightweight backpack with a padded laptop compartment."
1189
+ },
1190
+ "hindi": {
1191
+ "title": "Roz ke safar ke liye",
1192
+ "description": "Halka backpack, laptop ke liye alag padded jagah ke saath.",
1193
+ "care": [
1194
+ "Haath se saaf karein",
1195
+ "Chhaon mein sukhayein"
1196
+ ]
1197
+ },
1198
+ "images": [
1199
+ "front.webp",
1200
+ "back.webp"
1201
+ ]
1202
+ }
1203
+ ```
1204
+
1205
+ Build the example:
1206
+
1207
+ ```sh
1208
+ npx rida-format build ./catalogue --output ./CatalogueData.rida --records-dir .
1209
+ ```
1210
+
1211
+ #### Your customer chooses Hindi
1212
+
1213
+ Request the hindi field. The reader uses the map to resolve the record and the index to find its byte range. The response contains the complete Hindi value: its title, description, and care instructions. Price, stock, specifications, English content, and image URLs are not selected.
1214
+
1215
+ ```js
1216
+ import { RidaReader } from "rida-format";
1217
+
1218
+ const reader = await RidaReader.open("./CatalogueData.rida");
1219
+ try {
1220
+ const prefix = reader.resolve("products");
1221
+ if (!prefix) throw new Error("Folder not found in the map");
1222
+ const recordIds = reader.recordsUnder(prefix);
1223
+ // This exact example: 2812.json is the only record.
1224
+ const recordId = recordIds[0];
1225
+ console.log(await reader.get(recordId, "hindi"));
1226
+ console.log(await reader.getMany(recordId, ["price", "hindi"]));
1227
+ } finally {
1228
+ await reader.close();
1229
+ }
1230
+ ```
1231
+
1232
+ Need the price too? Request price and hindi together with a multi-field read. Nearby ranges can be combined; the number of HTTP requests depends on their positions in the data file.
1233
+
1234
+
1235
+ ### A complete help page. In the selected language.
1236
+
1237
+ A help centre can organise complete multilingual instructions inside deeply nested folders. Each language can contain a heading, introduction, steps, and troubleshooting.
1238
+
1239
+ ```text
1240
+ help-centre/
1241
+ └── guides/
1242
+ └── account/
1243
+ └── recovery/
1244
+ └── pages/
1245
+ ├── 1.json
1246
+ ├── 2.json
1247
+ └── 3812.json
1248
+ ```
1249
+
1250
+ Example record:
1251
+
1252
+ ```json
1253
+ {
1254
+ "title": "Recover your account",
1255
+ "category": "Account access",
1256
+ "english": {
1257
+ "heading": "Reset your password",
1258
+ "steps": [
1259
+ "Open account recovery",
1260
+ "Enter your email",
1261
+ "Follow the reset link"
1262
+ ]
1263
+ },
1264
+ "spanish": {
1265
+ "heading": "Restablece tu contraseña",
1266
+ "introduction": "Sigue estos pasos para recuperar el acceso a tu cuenta.",
1267
+ "steps": [
1268
+ "Abre la página de recuperación",
1269
+ "Introduce tu correo electrónico",
1270
+ "Sigue el enlace para restablecer la contraseña"
1271
+ ],
1272
+ "troubleshooting": {
1273
+ "email_missing": "Revisa la carpeta de correo no deseado.",
1274
+ "link_expired": "Solicita un nuevo enlace."
1275
+ }
1276
+ }
1277
+ }
1278
+ ```
1279
+
1280
+ Build the example:
1281
+
1282
+ ```sh
1283
+ npx rida-format build ./help-centre --output ./HelpData.rida --records-dir .
1284
+ ```
1285
+
1286
+ #### Your user needs Spanish instructions
1287
+
1288
+ Request the spanish field to receive the complete Spanish object, including its nested troubleshooting content. English instructions are not selected. Use the generated map to find the folder prefix rather than guessing a numbered path.
1289
+
1290
+ ```js
1291
+ import { RidaReader } from "rida-format";
1292
+
1293
+ const reader = await RidaReader.open("./HelpData.rida");
1294
+ try {
1295
+ const prefix = reader.resolve("guides", "account", "recovery", "pages");
1296
+ if (!prefix) throw new Error("Folder not found in the map");
1297
+ const recordIds = reader.recordsUnder(prefix);
1298
+ // This exact example: 3812.json follows 1.json and 2.json.
1299
+ const recordId = recordIds[2];
1300
+ console.log(await reader.get(recordId, "spanish"));
1301
+ console.log(await reader.getMany(recordId, ["title", "category", "spanish"]));
1302
+ } finally {
1303
+ await reader.close();
1304
+ }
1305
+ ```
1306
+
1307
+ Need page metadata too? Request title, category, and spanish together. RIDA selects stored fields, not individual properties inside them. If troubleshooting needs independent reads, store it in a separate top-level field.
1308
+
1309
+
1310
+ A field can contain a complete object or array, not just a short sentence. A long value needs a larger byte range. An encrypted build returns the same selected values after decryption with the key. Encryption and HTTP headers add overhead; responses are not a fixed few bytes. Merged ranges can also include small gaps between selected values.
1311
+
1312
+ The filenames are source names, not guaranteed numbered record IDs. The map describes folder prefixes; records_under / recordsUnder lists their record IDs. Keep the chosen ID in your application when selecting a record. For a large catalogue, use your own product identifier field or mapping to associate business IDs with numbered record IDs.
1313
+
1094
1314
  ## Current scope and limits
1095
1315
 
1096
1316
  - The CLI commands are `scan`, `build`, `info`, `get`, `get-many`, `record`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rida-format",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "Node.js reader and tools for RIDA 0.3.3 datasets",
5
5
  "type": "module",
6
6
  "engines": {
package/src/index.js CHANGED
@@ -7,7 +7,7 @@ import { inflateRawSync } from "node:zlib";
7
7
  const require = createRequire(import.meta.url);
8
8
  const lzma = require("lzma-native");
9
9
 
10
- export const version = "2.0.0";
10
+ export const version = "2.0.1";
11
11
  export const MERGE_GAP_LIMIT = 660;
12
12
  const INDEX_MAGIC = Buffer.from("RIDAIDX1");
13
13
  const CATALOG_MAGIC = Buffer.from("RDACAT01");