@openclaw/fs-safe 0.2.4 → 0.2.5

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.
Files changed (90) hide show
  1. package/CHANGELOG.md +15 -1
  2. package/README.md +2 -0
  3. package/dist/archive-staging.d.ts.map +1 -1
  4. package/dist/archive-staging.js +12 -1
  5. package/dist/file-store.d.ts.map +1 -1
  6. package/dist/file-store.js +6 -5
  7. package/dist/json-document-store.d.ts +1 -1
  8. package/dist/json-document-store.d.ts.map +1 -1
  9. package/dist/json-document-store.js +5 -3
  10. package/dist/json-durable-queue.d.ts.map +1 -1
  11. package/dist/json-durable-queue.js +157 -4
  12. package/dist/json-stringify.d.ts +2 -0
  13. package/dist/json-stringify.d.ts.map +1 -0
  14. package/dist/json-stringify.js +7 -0
  15. package/dist/json.d.ts.map +1 -1
  16. package/dist/json.js +3 -2
  17. package/dist/local-roots.d.ts.map +1 -1
  18. package/dist/local-roots.js +4 -1
  19. package/dist/path.js +1 -1
  20. package/dist/permissions.d.ts.map +1 -1
  21. package/dist/permissions.js +7 -10
  22. package/dist/pinned-python.d.ts.map +1 -1
  23. package/dist/pinned-python.js +125 -43
  24. package/dist/root-impl.d.ts.map +1 -1
  25. package/dist/root-impl.js +6 -2
  26. package/dist/root-paths.js +25 -3
  27. package/dist/secure-file.d.ts.map +1 -1
  28. package/dist/secure-file.js +3 -1
  29. package/dist/timing.d.ts.map +1 -1
  30. package/dist/timing.js +8 -1
  31. package/docs/index.md +1 -1
  32. package/docs/json-store.md +3 -1
  33. package/package.json +4 -4
  34. package/dist/archive-utils.d.ts +0 -3
  35. package/dist/archive-utils.d.ts.map +0 -1
  36. package/dist/archive-utils.js +0 -26
  37. package/dist/boundary-file-read.d.ts +0 -44
  38. package/dist/boundary-file-read.d.ts.map +0 -1
  39. package/dist/boundary-file-read.js +0 -129
  40. package/dist/boundary-path.d.ts +0 -39
  41. package/dist/boundary-path.d.ts.map +0 -1
  42. package/dist/boundary-path.js +0 -598
  43. package/dist/fs-pinned-path-helper.d.ts +0 -7
  44. package/dist/fs-pinned-path-helper.d.ts.map +0 -1
  45. package/dist/fs-pinned-path-helper.js +0 -182
  46. package/dist/fs-pinned-write-helper.d.ts +0 -21
  47. package/dist/fs-pinned-write-helper.d.ts.map +0 -1
  48. package/dist/fs-pinned-write-helper.js +0 -263
  49. package/dist/hardlink-guards.d.ts +0 -7
  50. package/dist/hardlink-guards.d.ts.map +0 -1
  51. package/dist/hardlink-guards.js +0 -30
  52. package/dist/install-safe-path.d.ts +0 -20
  53. package/dist/install-safe-path.d.ts.map +0 -1
  54. package/dist/install-safe-path.js +0 -94
  55. package/dist/json-file.d.ts +0 -3
  56. package/dist/json-file.d.ts.map +0 -1
  57. package/dist/json-file.js +0 -123
  58. package/dist/json-files.d.ts +0 -20
  59. package/dist/json-files.d.ts.map +0 -1
  60. package/dist/json-files.js +0 -153
  61. package/dist/path-alias-guards.d.ts +0 -19
  62. package/dist/path-alias-guards.d.ts.map +0 -1
  63. package/dist/path-alias-guards.js +0 -21
  64. package/dist/path-guards.d.ts +0 -7
  65. package/dist/path-guards.d.ts.map +0 -1
  66. package/dist/path-guards.js +0 -49
  67. package/dist/path-safety.d.ts +0 -12
  68. package/dist/path-safety.d.ts.map +0 -1
  69. package/dist/path-safety.js +0 -50
  70. package/dist/path-scope.d.ts +0 -2
  71. package/dist/path-scope.d.ts.map +0 -1
  72. package/dist/path-scope.js +0 -1
  73. package/dist/private-file-store.d.ts +0 -60
  74. package/dist/private-file-store.d.ts.map +0 -1
  75. package/dist/private-file-store.js +0 -233
  76. package/dist/safe-open-sync.d.ts +0 -24
  77. package/dist/safe-open-sync.d.ts.map +0 -1
  78. package/dist/safe-open-sync.js +0 -71
  79. package/dist/safe-root.d.ts +0 -123
  80. package/dist/safe-root.d.ts.map +0 -1
  81. package/dist/safe-root.js +0 -1060
  82. package/dist/secure-temp-workspace.d.ts +0 -25
  83. package/dist/secure-temp-workspace.d.ts.map +0 -1
  84. package/dist/secure-temp-workspace.js +0 -136
  85. package/dist/sibling-temp-file.d.ts +0 -16
  86. package/dist/sibling-temp-file.d.ts.map +0 -1
  87. package/dist/sibling-temp-file.js +0 -73
  88. package/dist/sibling-temp-write.d.ts +0 -8
  89. package/dist/sibling-temp-write.d.ts.map +0 -1
  90. package/dist/sibling-temp-write.js +0 -40
@@ -1,129 +0,0 @@
1
- import fs from "node:fs";
2
- import path from "node:path";
3
- import { resolveBoundaryPath, resolveBoundaryPathSync, } from "./boundary-path.js";
4
- import { openVerifiedFileSync, } from "./safe-open-sync.js";
5
- export function canUseBoundaryFileOpen(ioFs) {
6
- return (typeof ioFs.openSync === "function" &&
7
- typeof ioFs.closeSync === "function" &&
8
- typeof ioFs.fstatSync === "function" &&
9
- typeof ioFs.lstatSync === "function" &&
10
- typeof ioFs.realpathSync === "function" &&
11
- typeof ioFs.readFileSync === "function" &&
12
- typeof ioFs.constants === "object" &&
13
- ioFs.constants !== null);
14
- }
15
- export function openBoundaryFileSync(params) {
16
- const ioFs = params.ioFs ?? fs;
17
- const resolved = resolveBoundaryFilePathGeneric({
18
- absolutePath: params.absolutePath,
19
- resolve: (absolutePath) => resolveBoundaryPathSync({
20
- absolutePath,
21
- rootPath: params.rootPath,
22
- rootCanonicalPath: params.rootRealPath,
23
- boundaryLabel: params.boundaryLabel,
24
- skipLexicalRootCheck: params.skipLexicalRootCheck,
25
- }),
26
- });
27
- if (resolved instanceof Promise) {
28
- return toBoundaryValidationError(new Error("Unexpected async boundary resolution"));
29
- }
30
- return finalizeBoundaryFileOpen({
31
- resolved,
32
- maxBytes: params.maxBytes,
33
- rejectHardlinks: params.rejectHardlinks,
34
- allowedType: params.allowedType,
35
- ioFs,
36
- });
37
- }
38
- export function matchBoundaryFileOpenFailure(failure, handlers) {
39
- switch (failure.reason) {
40
- case "path":
41
- return handlers.path ? handlers.path(failure) : handlers.fallback(failure);
42
- case "validation":
43
- return handlers.validation ? handlers.validation(failure) : handlers.fallback(failure);
44
- case "io":
45
- return handlers.io ? handlers.io(failure) : handlers.fallback(failure);
46
- }
47
- return handlers.fallback(failure);
48
- }
49
- function openBoundaryFileResolved(params) {
50
- const opened = openVerifiedFileSync({
51
- filePath: params.absolutePath,
52
- resolvedPath: params.resolvedPath,
53
- rejectHardlinks: params.rejectHardlinks ?? true,
54
- maxBytes: params.maxBytes,
55
- allowedType: params.allowedType,
56
- ioFs: params.ioFs,
57
- });
58
- if (!opened.ok) {
59
- return opened;
60
- }
61
- return {
62
- ok: true,
63
- path: opened.path,
64
- fd: opened.fd,
65
- stat: opened.stat,
66
- rootRealPath: params.rootRealPath,
67
- };
68
- }
69
- function finalizeBoundaryFileOpen(params) {
70
- if ("ok" in params.resolved) {
71
- return params.resolved;
72
- }
73
- return openBoundaryFileResolved({
74
- absolutePath: params.resolved.absolutePath,
75
- resolvedPath: params.resolved.resolvedPath,
76
- rootRealPath: params.resolved.rootRealPath,
77
- maxBytes: params.maxBytes,
78
- rejectHardlinks: params.rejectHardlinks,
79
- allowedType: params.allowedType,
80
- ioFs: params.ioFs,
81
- });
82
- }
83
- export async function openBoundaryFile(params) {
84
- const ioFs = params.ioFs ?? fs;
85
- const maybeResolved = resolveBoundaryFilePathGeneric({
86
- absolutePath: params.absolutePath,
87
- resolve: (absolutePath) => resolveBoundaryPath({
88
- absolutePath,
89
- rootPath: params.rootPath,
90
- rootCanonicalPath: params.rootRealPath,
91
- boundaryLabel: params.boundaryLabel,
92
- policy: params.aliasPolicy,
93
- skipLexicalRootCheck: params.skipLexicalRootCheck,
94
- }),
95
- });
96
- const resolved = maybeResolved instanceof Promise ? await maybeResolved : maybeResolved;
97
- return finalizeBoundaryFileOpen({
98
- resolved,
99
- maxBytes: params.maxBytes,
100
- rejectHardlinks: params.rejectHardlinks,
101
- allowedType: params.allowedType,
102
- ioFs,
103
- });
104
- }
105
- function toBoundaryValidationError(error) {
106
- return { ok: false, reason: "validation", error };
107
- }
108
- function mapResolvedBoundaryPath(absolutePath, resolved) {
109
- return {
110
- absolutePath,
111
- resolvedPath: resolved.canonicalPath,
112
- rootRealPath: resolved.rootCanonicalPath,
113
- };
114
- }
115
- function resolveBoundaryFilePathGeneric(params) {
116
- const absolutePath = path.resolve(params.absolutePath);
117
- try {
118
- const resolved = params.resolve(absolutePath);
119
- if (resolved instanceof Promise) {
120
- return resolved
121
- .then((value) => mapResolvedBoundaryPath(absolutePath, value))
122
- .catch((error) => toBoundaryValidationError(error));
123
- }
124
- return mapResolvedBoundaryPath(absolutePath, resolved);
125
- }
126
- catch (error) {
127
- return toBoundaryValidationError(error);
128
- }
129
- }
@@ -1,39 +0,0 @@
1
- type BoundaryPathIntent = "read" | "write" | "create" | "delete" | "stat";
2
- export type BoundaryPathAliasPolicy = {
3
- allowFinalSymlinkForUnlink?: boolean;
4
- allowFinalHardlinkForUnlink?: boolean;
5
- };
6
- export declare const BOUNDARY_PATH_ALIAS_POLICIES: {
7
- readonly strict: Readonly<{
8
- allowFinalSymlinkForUnlink: false;
9
- allowFinalHardlinkForUnlink: false;
10
- }>;
11
- readonly unlinkTarget: Readonly<{
12
- allowFinalSymlinkForUnlink: true;
13
- allowFinalHardlinkForUnlink: true;
14
- }>;
15
- };
16
- type ResolveBoundaryPathParams = {
17
- absolutePath: string;
18
- rootPath: string;
19
- boundaryLabel: string;
20
- intent?: BoundaryPathIntent;
21
- policy?: BoundaryPathAliasPolicy;
22
- skipLexicalRootCheck?: boolean;
23
- rootCanonicalPath?: string;
24
- };
25
- type ResolvedBoundaryPathKind = "missing" | "file" | "directory" | "symlink" | "other";
26
- export type ResolvedBoundaryPath = {
27
- absolutePath: string;
28
- canonicalPath: string;
29
- rootPath: string;
30
- rootCanonicalPath: string;
31
- relativePath: string;
32
- exists: boolean;
33
- kind: ResolvedBoundaryPathKind;
34
- };
35
- export declare function resolveBoundaryPath(params: ResolveBoundaryPathParams): Promise<ResolvedBoundaryPath>;
36
- export declare function resolveBoundaryPathSync(params: ResolveBoundaryPathParams): ResolvedBoundaryPath;
37
- export declare function resolvePathViaExistingAncestorSync(targetPath: string): string;
38
- export {};
39
- //# sourceMappingURL=boundary-path.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"boundary-path.d.ts","sourceRoot":"","sources":["../src/boundary-path.ts"],"names":[],"mappings":"AAMA,KAAK,kBAAkB,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,QAAQ,GAAG,MAAM,CAAC;AAE1E,MAAM,MAAM,uBAAuB,GAAG;IACpC,0BAA0B,CAAC,EAAE,OAAO,CAAC;IACrC,2BAA2B,CAAC,EAAE,OAAO,CAAC;CACvC,CAAC;AAEF,eAAO,MAAM,4BAA4B;;;;;;;;;CAS/B,CAAC;AAEX,KAAK,yBAAyB,GAAG;IAC/B,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,CAAC,EAAE,kBAAkB,CAAC;IAC5B,MAAM,CAAC,EAAE,uBAAuB,CAAC;IACjC,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF,KAAK,wBAAwB,GAAG,SAAS,GAAG,MAAM,GAAG,WAAW,GAAG,SAAS,GAAG,OAAO,CAAC;AAEvF,MAAM,MAAM,oBAAoB,GAAG;IACjC,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,OAAO,CAAC;IAChB,IAAI,EAAE,wBAAwB,CAAC;CAChC,CAAC;AAEF,wBAAsB,mBAAmB,CACvC,MAAM,EAAE,yBAAyB,GAChC,OAAO,CAAC,oBAAoB,CAAC,CA+B/B;AAED,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,yBAAyB,GAAG,oBAAoB,CA+B/F;AAmkBD,wBAAgB,kCAAkC,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CA6B7E"}