@powerhousedao/shared 6.0.0-dev.193 → 6.0.0-dev.195
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/dist/{actions-OP2hCkXB.d.ts → actions-CAkdvsc4.d.ts} +2 -2
- package/dist/{actions-OP2hCkXB.d.ts.map → actions-CAkdvsc4.d.ts.map} +1 -1
- package/dist/analytics/index.d.ts +1 -1
- package/dist/clis/index.mjs +1 -16
- package/dist/clis/index.mjs.map +1 -1
- package/dist/{constants-CWTeHvBt.d.ts → constants-xNwF0jSl.d.ts} +1 -1
- package/dist/constants-xNwF0jSl.d.ts.map +1 -0
- package/dist/constants.d.ts +1 -1
- package/dist/document-drive/index.d.ts +2 -2
- package/dist/document-drive/index.d.ts.map +1 -1
- package/dist/document-drive/index.js +2 -1
- package/dist/document-drive/index.js.map +1 -1
- package/dist/document-model/index.d.ts +4 -2
- package/dist/document-model/index.js +12 -76
- package/dist/document-model/index.js.map +1 -1
- package/dist/document-model/mock.d.ts +2 -0
- package/dist/document-model/mock.js +9 -0
- package/dist/document-model/mock.js.map +1 -0
- package/dist/document-model/utils.d.ts +3 -0
- package/dist/document-model/utils.js +3 -0
- package/dist/{index-CNskeAB6.d.ts → index-BpqHXMvb.d.ts} +5 -13
- package/dist/index-BpqHXMvb.d.ts.map +1 -0
- package/dist/index.d.ts +4 -4
- package/dist/mock-Cgn-VBF_.d.ts +7 -0
- package/dist/mock-Cgn-VBF_.d.ts.map +1 -0
- package/dist/processors/index.d.ts +1 -1
- package/dist/registry/index.d.ts +1 -1
- package/dist/registry/index.d.ts.map +1 -1
- package/dist/{types-DWXYsIF1.d.ts → types-BFDlQkXZ.d.ts} +1 -1
- package/dist/{types-DWXYsIF1.d.ts.map → types-BFDlQkXZ.d.ts.map} +1 -1
- package/dist/{types-DyUYj_J_.d.ts → types-jCjay2PA.d.ts} +2 -2
- package/dist/{types-DyUYj_J_.d.ts.map → types-jCjay2PA.d.ts.map} +1 -1
- package/dist/utils-CJF4w5Bp.d.ts +9 -0
- package/dist/utils-CJF4w5Bp.d.ts.map +1 -0
- package/dist/utils-bCWnsmtD.js +70 -0
- package/dist/utils-bCWnsmtD.js.map +1 -0
- package/package.json +2 -1
- package/dist/constants-CWTeHvBt.d.ts.map +0 -1
- package/dist/index-CNskeAB6.d.ts.map +0 -1
- /package/dist/{index-1CTsSKEn.d.ts → index-D0E78WnU.d.ts} +0 -0
|
@@ -1,63 +1,9 @@
|
|
|
1
|
+
import { a as buildOperationSignatureParams, c as hex2ab, i as buildOperationSignatureMessage, n as generateId, o as getUnixTimestamp, r as ab2hex, s as hashBrowser, t as deriveOperationId } from "../utils-bCWnsmtD.js";
|
|
2
|
+
import { generateMock } from "./mock.js";
|
|
1
3
|
import { ZodError, z } from "zod";
|
|
2
4
|
import { stringify } from "safe-stable-stringify";
|
|
3
|
-
import { createHash } from "sha1-uint8array";
|
|
4
|
-
import { zocker } from "zocker";
|
|
5
|
-
import JSZip from "jszip";
|
|
6
5
|
import { castDraft, create, unsafe } from "mutative";
|
|
7
6
|
import { pascalCase } from "change-case";
|
|
8
|
-
//#region document-model/crypto.ts
|
|
9
|
-
const hashBrowser = (data, algorithm = "sha1", encoding = "base64", _params) => {
|
|
10
|
-
if (!["sha1"].includes(algorithm)) throw new Error(`Hashing algorithm not supported: "${algorithm}". Available: sha1`);
|
|
11
|
-
if (!["base64", "hex"].includes(encoding)) throw new Error(`Hash encoding not supported: "${encoding}". Available: base64, hex`);
|
|
12
|
-
const hash = hashUIntArray(data, algorithm);
|
|
13
|
-
if (encoding === "hex") return uint8ArrayToHex(hash);
|
|
14
|
-
return uint8ArrayToBase64(hash);
|
|
15
|
-
};
|
|
16
|
-
function uint8ArrayToBase64(uint8Array) {
|
|
17
|
-
let binaryString = "";
|
|
18
|
-
for (let i = 0; i < uint8Array.length; i++) binaryString += String.fromCharCode(uint8Array[i]);
|
|
19
|
-
return btoa(binaryString);
|
|
20
|
-
}
|
|
21
|
-
function uint8ArrayToHex(uint8Array) {
|
|
22
|
-
return Array.from(uint8Array).map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
23
|
-
}
|
|
24
|
-
function hashUIntArray(data, algorithm = "sha1") {
|
|
25
|
-
if (!["sha1"].includes(algorithm)) throw new Error("Hashing algorithm not supported: Available: sha1");
|
|
26
|
-
return createHash("sha1").update(data).digest();
|
|
27
|
-
}
|
|
28
|
-
function getUnixTimestamp(date) {
|
|
29
|
-
return (new Date(date).getTime() / 1e3).toFixed(0);
|
|
30
|
-
}
|
|
31
|
-
function buildOperationSignatureParams({ documentId, signer, action, previousStateHash }) {
|
|
32
|
-
const { scope, type } = action;
|
|
33
|
-
return [
|
|
34
|
-
getUnixTimestamp(/* @__PURE__ */ new Date()),
|
|
35
|
-
signer.app.key,
|
|
36
|
-
hashBrowser([
|
|
37
|
-
documentId,
|
|
38
|
-
scope,
|
|
39
|
-
type,
|
|
40
|
-
stringify(action.input)
|
|
41
|
-
].join("")),
|
|
42
|
-
previousStateHash
|
|
43
|
-
];
|
|
44
|
-
}
|
|
45
|
-
const textEncode = new TextEncoder();
|
|
46
|
-
function buildOperationSignatureMessage(params) {
|
|
47
|
-
const message = params.join("");
|
|
48
|
-
const prefix = "Signed Operation:\n" + message.length.toString();
|
|
49
|
-
return textEncode.encode(prefix + message);
|
|
50
|
-
}
|
|
51
|
-
function ab2hex(ab) {
|
|
52
|
-
const view = ArrayBuffer.isView(ab) ? ab : new Uint8Array(ab);
|
|
53
|
-
return Array.prototype.map.call(view, (x) => ("00" + x.toString(16)).slice(-2)).join("");
|
|
54
|
-
}
|
|
55
|
-
function hex2ab(hex) {
|
|
56
|
-
return new Uint8Array(hex.match(/[\da-f]{2}/gi)?.map(function(h) {
|
|
57
|
-
return parseInt(h, 16);
|
|
58
|
-
}) ?? []);
|
|
59
|
-
}
|
|
60
|
-
//#endregion
|
|
61
7
|
//#region document-model/errors.ts
|
|
62
8
|
const FileSystemError = /* @__PURE__ */ new Error("File system not available.");
|
|
63
9
|
var InvalidActionInputError = class extends Error {
|
|
@@ -599,21 +545,6 @@ const ManifestSchema = z.object({
|
|
|
599
545
|
config: z.array(ConfigEntrySchema).optional()
|
|
600
546
|
});
|
|
601
547
|
//#endregion
|
|
602
|
-
//#region document-model/utils.ts
|
|
603
|
-
function generateMock(schema) {
|
|
604
|
-
return zocker(schema).generate();
|
|
605
|
-
}
|
|
606
|
-
function generateId(method) {
|
|
607
|
-
if (method && method.toString() !== "UUIDv4") throw new Error(`Id generation method not supported: "${method.toString()}"`);
|
|
608
|
-
return globalThis.crypto.randomUUID();
|
|
609
|
-
}
|
|
610
|
-
/**
|
|
611
|
-
* Derives a deterministic operation ID from stable properties.
|
|
612
|
-
*/
|
|
613
|
-
function deriveOperationId(documentId, scope, branch, actionId) {
|
|
614
|
-
return hashBrowser(`${documentId}:${scope}:${branch}:${actionId}`, "sha1", "hex").slice(0, 32);
|
|
615
|
-
}
|
|
616
|
-
//#endregion
|
|
617
548
|
//#region document-model/actions.ts
|
|
618
549
|
/**
|
|
619
550
|
* Cancels the last `count` operations.
|
|
@@ -3255,8 +3186,12 @@ const documentModelReducer = createReducer(documentModelStateReducer);
|
|
|
3255
3186
|
//#endregion
|
|
3256
3187
|
//#region document-model/files.ts
|
|
3257
3188
|
const NON_DOMAIN_SCOPES = new Set(["auth", "document"]);
|
|
3258
|
-
function
|
|
3259
|
-
const
|
|
3189
|
+
async function loadJSZip() {
|
|
3190
|
+
const { default: JSZip } = await import("jszip");
|
|
3191
|
+
return JSZip;
|
|
3192
|
+
}
|
|
3193
|
+
async function createZip(document) {
|
|
3194
|
+
const zip = new (await (loadJSZip()))();
|
|
3260
3195
|
const header = document.header;
|
|
3261
3196
|
zip.file("header.json", JSON.stringify(header, null, 2));
|
|
3262
3197
|
zip.file("state.json", JSON.stringify(document.initialState || {}, null, 2));
|
|
@@ -3269,7 +3204,8 @@ function createZip(document) {
|
|
|
3269
3204
|
* Used when the full document is not available (e.g., in onOperations handler).
|
|
3270
3205
|
* Creates a ZIP with minimal header and empty operations.
|
|
3271
3206
|
*/
|
|
3272
|
-
function createMinimalZip(data) {
|
|
3207
|
+
async function createMinimalZip(data) {
|
|
3208
|
+
const JSZip = await loadJSZip();
|
|
3273
3209
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
3274
3210
|
const header = {
|
|
3275
3211
|
id: data.documentId,
|
|
@@ -3293,7 +3229,7 @@ function createMinimalZip(data) {
|
|
|
3293
3229
|
return zip;
|
|
3294
3230
|
}
|
|
3295
3231
|
async function baseSaveToFileHandle(document, input) {
|
|
3296
|
-
const blob = await createZip(document).generateAsync({ type: "blob" });
|
|
3232
|
+
const blob = await (await createZip(document)).generateAsync({ type: "blob" });
|
|
3297
3233
|
const writable = await input.createWritable();
|
|
3298
3234
|
await writable.write(blob);
|
|
3299
3235
|
await writable.close();
|
|
@@ -3320,7 +3256,7 @@ async function loadFromZip(zip, reducer, options) {
|
|
|
3320
3256
|
};
|
|
3321
3257
|
}
|
|
3322
3258
|
async function baseLoadFromInput(input, reducer, options) {
|
|
3323
|
-
const zip = new
|
|
3259
|
+
const zip = new (await (loadJSZip()))();
|
|
3324
3260
|
await zip.loadAsync(input);
|
|
3325
3261
|
return loadFromZip(zip, reducer, options);
|
|
3326
3262
|
}
|