Skip to content

Commit 60876bb

Browse files
authored
feat: add redact to wasm (#729)
* feat: add redact to wasm - Implemented `redact_json_updates` function to redact sensitive content in JSON updates. - Added tests for `redactJsonUpdates` to ensure sensitive content is properly redacted.
1 parent e37256c commit 60876bb

19 files changed

Lines changed: 791 additions & 85 deletions

File tree

.changeset/grumpy-chicken-beam.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"loro-crdt": patch
3+
---
4+
5+
Feat: redact

.github/workflows/rust.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
with:
4141
version: "0.2.100"
4242
- uses: Swatinem/rust-cache@v2
43-
- name: Check
43+
- name: Clippy Check
4444
run: cargo clippy --all-features -- -Dwarnings
4545
- name: Run rust tests
46-
run: deno task test-all
46+
run: GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} deno task test-all

crates/loro-ffi/src/doc.rs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,10 +345,36 @@ impl LoroDoc {
345345
start_vv: &VersionVector,
346346
end_vv: &VersionVector,
347347
) -> String {
348-
let json = self
349-
.doc
350-
.export_json_updates_without_peer_compression(&start_vv.into(), &end_vv.into());
351-
serde_json::to_string(&json).unwrap()
348+
serde_json::to_string(
349+
&self
350+
.doc
351+
.export_json_updates_without_peer_compression(&start_vv.into(), &end_vv.into()),
352+
)
353+
.unwrap()
354+
}
355+
356+
/// Redacts sensitive content in JSON updates within the specified version range.
357+
///
358+
/// This function allows you to share document history while removing potentially sensitive content.
359+
/// It preserves the document structure and collaboration capabilities while replacing content with
360+
/// placeholders according to these redaction rules:
361+
///
362+
/// - Preserves delete and move operations
363+
/// - Replaces text insertion content with the Unicode replacement character
364+
/// - Substitutes list and map insert values with null
365+
/// - Maintains structure of child containers
366+
/// - Replaces text mark values with null
367+
/// - Preserves map keys and text annotation keys
368+
pub fn redact_json_updates(
369+
&self,
370+
json: &str,
371+
version_range: VersionRange,
372+
) -> Result<String, LoroError> {
373+
let mut schema: JsonSchema =
374+
serde_json::from_str(json).map_err(|_e| LoroError::InvalidJsonSchema)?;
375+
loro::json::redact(&mut schema, version_range)
376+
.map_err(|e| LoroError::Unknown(e.to_string().into_boxed_str()))?;
377+
Ok(serde_json::to_string(&schema).unwrap())
352378
}
353379

354380
/// Export the readable [`Change`]s in the given [`IdSpan`]

crates/loro-internal/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ unexpected_cfgs = { level = "warn", check-cfg = ['cfg(loom)'] }
6565
version = "0.2.15"
6666
features = ["js"]
6767

68-
[target.'cfg(all(target_arch = "wasm32", not(feature = "wasm")))'.dependencies]
68+
[target.'cfg(all(target_arch = "wasm32", not(features = "wasm")))'.dependencies]
6969
wasm-bindgen = "0.2.100"
7070

7171
[dev-dependencies]

crates/loro-internal/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.5.0
1+
1.5.5

crates/loro-internal/src/container/richtext/tracker.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ impl Tracker {
220220
self.applied_vv.extend_to_include_end_id(end_id);
221221
}
222222

223-
#[must_use]
224223
fn skip_applied(
225224
&mut self,
226225
op_id: ID,

crates/loro-internal/src/oplog/change_store.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,6 +1240,7 @@ impl ChangesBlock {
12401240
self.estimated_size > MAX_BLOCK_SIZE
12411241
}
12421242

1243+
#[allow(clippy::result_large_err)]
12431244
fn push_change(
12441245
self: &mut Arc<Self>,
12451246
change: Change,

crates/loro-internal/src/state/counter_state.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ impl ContainerState for CounterState {
3838
false
3939
}
4040

41-
#[must_use]
4241
fn apply_diff_and_convert(&mut self, diff: InternalDiff, _ctx: DiffApplyContext) -> Diff {
4342
if let InternalDiff::Counter(diff) = diff {
4443
self.value += diff;

crates/loro-wasm/deno.lock

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/loro-wasm/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,15 @@
3636
"author": "",
3737
"license": "MIT",
3838
"devDependencies": {
39+
"@actions/core": "^1.11.1",
40+
"@actions/github": "^6.0.1",
3941
"@rollup/plugin-alias": "^5.1.1",
4042
"@rollup/plugin-node-resolve": "^15.0.1",
4143
"@rollup/plugin-typescript": "^12.1.1",
4244
"@rollup/plugin-wasm": "^6.2.2",
4345
"@typescript-eslint/parser": "^6.2.0",
4446
"@vitest/ui": "^1.0.4",
47+
"brotli-wasm": "^3.0.1",
4548
"esbuild": "^0.18.20",
4649
"eslint": "^8.46.0",
4750
"loro-crdt-alpha-4": "npm:loro-crdt@=1.0.0-alpha.4",

0 commit comments

Comments
 (0)