dignity.js 0.8.1 → 0.8.2
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 +23 -0
- package/dist/dignity.cjs.js +128 -1
- package/dist/dignity.cjs.js.map +4 -4
- package/dist/dignity.esm.js +128 -1
- package/dist/dignity.esm.js.map +3 -3
- package/dist/dignity.min.js +26 -26
- package/docs/assets/dignity.esm.js +128 -1
- package/docs/index.html +6 -5
- package/docs/openapi-like.json +1 -1
- package/package.json +1 -1
- package/src/apps/manifest.js +131 -0
- package/src/index.js +11 -1
package/dist/dignity.esm.js
CHANGED
|
@@ -13300,6 +13300,123 @@ var require_query_replica = __commonJS({
|
|
|
13300
13300
|
}
|
|
13301
13301
|
});
|
|
13302
13302
|
|
|
13303
|
+
// src/apps/manifest.js
|
|
13304
|
+
var require_manifest = __commonJS({
|
|
13305
|
+
"src/apps/manifest.js"(exports, module) {
|
|
13306
|
+
var MANIFEST_SCHEMA_VERSION = 1;
|
|
13307
|
+
var ID_PATTERN = /^[a-z0-9][a-z0-9._-]{0,63}$/;
|
|
13308
|
+
function isNonEmptyString(value) {
|
|
13309
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
13310
|
+
}
|
|
13311
|
+
function validateStoredCommand(command, index) {
|
|
13312
|
+
const prefix = `storedCommands[${index}]`;
|
|
13313
|
+
if (!command || typeof command !== "object") {
|
|
13314
|
+
return { ok: false, reason: `${prefix} must be an object` };
|
|
13315
|
+
}
|
|
13316
|
+
if (!isNonEmptyString(command.id)) {
|
|
13317
|
+
return { ok: false, reason: `${prefix}.id is required` };
|
|
13318
|
+
}
|
|
13319
|
+
if (!isNonEmptyString(command.collection)) {
|
|
13320
|
+
return { ok: false, reason: `${prefix}.collection is required` };
|
|
13321
|
+
}
|
|
13322
|
+
if (!["create", "update", "delete"].includes(command.kind)) {
|
|
13323
|
+
return { ok: false, reason: `${prefix}.kind must be create, update, or delete` };
|
|
13324
|
+
}
|
|
13325
|
+
if (command.allowedFields !== void 0) {
|
|
13326
|
+
if (!Array.isArray(command.allowedFields) || command.allowedFields.some((f) => !isNonEmptyString(f))) {
|
|
13327
|
+
return { ok: false, reason: `${prefix}.allowedFields must be a string array` };
|
|
13328
|
+
}
|
|
13329
|
+
}
|
|
13330
|
+
return { ok: true };
|
|
13331
|
+
}
|
|
13332
|
+
function validateDignityAppManifest(raw) {
|
|
13333
|
+
if (!raw || typeof raw !== "object") {
|
|
13334
|
+
return { ok: false, reason: "manifest must be an object" };
|
|
13335
|
+
}
|
|
13336
|
+
if (raw.schemaVersion !== void 0 && raw.schemaVersion !== MANIFEST_SCHEMA_VERSION) {
|
|
13337
|
+
return { ok: false, reason: `unsupported schemaVersion: ${raw.schemaVersion}` };
|
|
13338
|
+
}
|
|
13339
|
+
if (!isNonEmptyString(raw.id) || !ID_PATTERN.test(raw.id)) {
|
|
13340
|
+
return { ok: false, reason: "id must match [a-z0-9][a-z0-9._-]{0,63}" };
|
|
13341
|
+
}
|
|
13342
|
+
if (!isNonEmptyString(raw.title)) {
|
|
13343
|
+
return { ok: false, reason: "title is required" };
|
|
13344
|
+
}
|
|
13345
|
+
if (!Array.isArray(raw.collections) || raw.collections.length === 0) {
|
|
13346
|
+
return { ok: false, reason: "collections must be a non-empty string array" };
|
|
13347
|
+
}
|
|
13348
|
+
const collections = [];
|
|
13349
|
+
for (const name of raw.collections) {
|
|
13350
|
+
if (!isNonEmptyString(name)) {
|
|
13351
|
+
return { ok: false, reason: "collections entries must be non-empty strings" };
|
|
13352
|
+
}
|
|
13353
|
+
if (collections.includes(name)) {
|
|
13354
|
+
return { ok: false, reason: `duplicate collection: ${name}` };
|
|
13355
|
+
}
|
|
13356
|
+
collections.push(name.trim());
|
|
13357
|
+
}
|
|
13358
|
+
const storedCommands = Array.isArray(raw.storedCommands) ? raw.storedCommands : [];
|
|
13359
|
+
for (let index = 0; index < storedCommands.length; index += 1) {
|
|
13360
|
+
const result = validateStoredCommand(storedCommands[index], index);
|
|
13361
|
+
if (!result.ok) {
|
|
13362
|
+
return result;
|
|
13363
|
+
}
|
|
13364
|
+
const collection = storedCommands[index].collection;
|
|
13365
|
+
if (!collections.includes(collection)) {
|
|
13366
|
+
return {
|
|
13367
|
+
ok: false,
|
|
13368
|
+
reason: `storedCommands[${index}] references undeclared collection: ${collection}`
|
|
13369
|
+
};
|
|
13370
|
+
}
|
|
13371
|
+
}
|
|
13372
|
+
const allowedCspOrigins = Array.isArray(raw.allowedCspOrigins) ? raw.allowedCspOrigins : [];
|
|
13373
|
+
for (const origin of allowedCspOrigins) {
|
|
13374
|
+
if (!isNonEmptyString(origin) || !origin.startsWith("https://")) {
|
|
13375
|
+
return { ok: false, reason: "allowedCspOrigins entries must be https:// URLs" };
|
|
13376
|
+
}
|
|
13377
|
+
if (/localhost|127\.0\.0\.1/i.test(origin)) {
|
|
13378
|
+
return { ok: false, reason: "localhost origins are not allowed in allowedCspOrigins" };
|
|
13379
|
+
}
|
|
13380
|
+
}
|
|
13381
|
+
const manifest = {
|
|
13382
|
+
schemaVersion: MANIFEST_SCHEMA_VERSION,
|
|
13383
|
+
id: raw.id.trim(),
|
|
13384
|
+
title: raw.title.trim(),
|
|
13385
|
+
description: isNonEmptyString(raw.description) ? raw.description.trim() : "",
|
|
13386
|
+
collections,
|
|
13387
|
+
peerGroupId: isNonEmptyString(raw.peerGroupId) ? raw.peerGroupId.trim() : null,
|
|
13388
|
+
publisherId: isNonEmptyString(raw.publisherId) ? raw.publisherId.trim() : null,
|
|
13389
|
+
storedCommands: storedCommands.map((cmd) => ({
|
|
13390
|
+
id: cmd.id.trim(),
|
|
13391
|
+
collection: cmd.collection.trim(),
|
|
13392
|
+
kind: cmd.kind,
|
|
13393
|
+
allowedFields: Array.isArray(cmd.allowedFields) ? [...cmd.allowedFields] : null,
|
|
13394
|
+
requiresRole: isNonEmptyString(cmd.requiresRole) ? cmd.requiresRole.trim() : null
|
|
13395
|
+
})),
|
|
13396
|
+
allowedCspOrigins: allowedCspOrigins.map((o) => o.trim()),
|
|
13397
|
+
readOnly: storedCommands.length === 0
|
|
13398
|
+
};
|
|
13399
|
+
return { ok: true, manifest };
|
|
13400
|
+
}
|
|
13401
|
+
function collectionAllowed(manifest, collectionName) {
|
|
13402
|
+
return manifest && Array.isArray(manifest.collections) && manifest.collections.includes(collectionName);
|
|
13403
|
+
}
|
|
13404
|
+
function getStoredCommand(manifest, commandId) {
|
|
13405
|
+
if (!manifest || !Array.isArray(manifest.storedCommands)) {
|
|
13406
|
+
return null;
|
|
13407
|
+
}
|
|
13408
|
+
return manifest.storedCommands.find((cmd) => cmd.id === commandId) || null;
|
|
13409
|
+
}
|
|
13410
|
+
module.exports = {
|
|
13411
|
+
MANIFEST_SCHEMA_VERSION,
|
|
13412
|
+
ID_PATTERN,
|
|
13413
|
+
validateDignityAppManifest,
|
|
13414
|
+
collectionAllowed,
|
|
13415
|
+
getStoredCommand
|
|
13416
|
+
};
|
|
13417
|
+
}
|
|
13418
|
+
});
|
|
13419
|
+
|
|
13303
13420
|
// src/index.js
|
|
13304
13421
|
var require_index = __commonJS({
|
|
13305
13422
|
"src/index.js"(exports, module) {
|
|
@@ -13364,6 +13481,12 @@ var require_index = __commonJS({
|
|
|
13364
13481
|
} = require_peer_group_tiers();
|
|
13365
13482
|
var { electBulkRelays, DEFAULT_BULK_RELAY_COUNT } = require_bulk_relay();
|
|
13366
13483
|
var DignityQueryReplica = require_query_replica();
|
|
13484
|
+
var {
|
|
13485
|
+
MANIFEST_SCHEMA_VERSION: DIGNITY_APP_MANIFEST_SCHEMA_VERSION,
|
|
13486
|
+
validateDignityAppManifest,
|
|
13487
|
+
collectionAllowed,
|
|
13488
|
+
getStoredCommand
|
|
13489
|
+
} = require_manifest();
|
|
13367
13490
|
module.exports = {
|
|
13368
13491
|
DignityP2P,
|
|
13369
13492
|
createDefaultSignalingPool,
|
|
@@ -13412,7 +13535,11 @@ var require_index = __commonJS({
|
|
|
13412
13535
|
filterPeersByTier,
|
|
13413
13536
|
electBulkRelays,
|
|
13414
13537
|
DEFAULT_BULK_RELAY_COUNT,
|
|
13415
|
-
DignityQueryReplica
|
|
13538
|
+
DignityQueryReplica,
|
|
13539
|
+
DIGNITY_APP_MANIFEST_SCHEMA_VERSION,
|
|
13540
|
+
validateDignityAppManifest,
|
|
13541
|
+
collectionAllowed,
|
|
13542
|
+
getStoredCommand
|
|
13416
13543
|
};
|
|
13417
13544
|
}
|
|
13418
13545
|
});
|