@blamejs/blamejs-shop 0.0.83 → 0.0.98

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 (33) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/lib/admin.js +11 -7
  3. package/lib/customer-import.js +1 -1
  4. package/lib/email-campaigns.js +1 -1
  5. package/lib/pwa-manifest.js +1 -0
  6. package/lib/vendor/MANIFEST.json +2 -2
  7. package/lib/vendor/blamejs/.github/workflows/sha-to-tag-verify.yml +8 -0
  8. package/lib/vendor/blamejs/CHANGELOG.md +6 -0
  9. package/lib/vendor/blamejs/README.md +1 -1
  10. package/lib/vendor/blamejs/SECURITY.md +1 -0
  11. package/lib/vendor/blamejs/api-snapshot.json +167 -2
  12. package/lib/vendor/blamejs/fuzz/safe-archive.fuzz.js +37 -0
  13. package/lib/vendor/blamejs/index.js +15 -1
  14. package/lib/vendor/blamejs/lib/archive-adapters.js +629 -0
  15. package/lib/vendor/blamejs/lib/archive-gz.js +229 -0
  16. package/lib/vendor/blamejs/lib/archive-read.js +781 -0
  17. package/lib/vendor/blamejs/lib/archive-tar-read.js +418 -0
  18. package/lib/vendor/blamejs/lib/archive-tar.js +571 -0
  19. package/lib/vendor/blamejs/lib/archive.js +24 -2
  20. package/lib/vendor/blamejs/lib/audit.js +22 -7
  21. package/lib/vendor/blamejs/lib/backup/index.js +469 -0
  22. package/lib/vendor/blamejs/lib/guard-archive.js +180 -0
  23. package/lib/vendor/blamejs/lib/guard-filename.js +205 -0
  24. package/lib/vendor/blamejs/lib/safe-archive.js +309 -0
  25. package/lib/vendor/blamejs/package.json +1 -1
  26. package/lib/vendor/blamejs/release-notes/v0.12.7.json +86 -0
  27. package/lib/vendor/blamejs/release-notes/v0.12.8.json +81 -0
  28. package/lib/vendor/blamejs/release-notes/v0.12.9.json +61 -0
  29. package/lib/vendor/blamejs/test/layer-0-primitives/archive-gz.test.js +159 -0
  30. package/lib/vendor/blamejs/test/layer-0-primitives/archive-read.test.js +247 -0
  31. package/lib/vendor/blamejs/test/layer-0-primitives/archive-tar.test.js +228 -0
  32. package/lib/vendor/blamejs/test/layer-0-primitives/codebase-patterns.test.js +180 -0
  33. package/package.json +2 -2
@@ -0,0 +1,229 @@
1
+ "use strict";
2
+ /**
3
+ * archive-gz — gzip composition primitives. Sibling of lib/archive.js
4
+ * (ZIP write), lib/archive-read.js (ZIP read), lib/archive-tar.js (tar
5
+ * write), and lib/archive-tar-read.js (tar read). The @module block
6
+ * lives on lib/archive.js; this file declares only @primitive entries
7
+ * under the b.archive namespace (`b.archive.gz` write, `b.archive.read.gz`
8
+ * read). Bomb defenses ride with the read path: every read.gz call
9
+ * composes b.safeDecompress with the framework's default caps (1 GiB
10
+ * output / 100× ratio).
11
+ */
12
+
13
+ var zlib = require("node:zlib");
14
+ var nodeCrypto = require("node:crypto");
15
+ var C = require("./constants");
16
+ var lazyRequire = require("./lazy-require");
17
+ var safeBuffer = require("./safe-buffer");
18
+ var { defineClass } = require("./framework-error");
19
+
20
+ var ArchiveGzError = defineClass("ArchiveGzError", { alwaysPermanent: true });
21
+
22
+ var safeDecompress = lazyRequire(function () { return require("./safe-decompress"); });
23
+ var archiveAdapters = lazyRequire(function () { return require("./archive-adapters"); });
24
+ var archiveRead = lazyRequire(function () { return require("./archive-read"); });
25
+ var archiveTarRead = lazyRequire(function () { return require("./archive-tar-read"); });
26
+
27
+ // gzip magic — RFC 1952 §2.2 ("ID1=0x1f, ID2=0x8b").
28
+ var GZIP_MAGIC_0 = 0x1f; // allow:raw-byte-literal — RFC 1952 §2.2 ID1
29
+ var GZIP_MAGIC_1 = 0x8b; // allow:raw-byte-literal — RFC 1952 §2.2 ID2
30
+
31
+ var DEFAULT_MAX_OUTPUT_BYTES = C.BYTES.gib(1);
32
+ var DEFAULT_MAX_RATIO = 100;
33
+
34
+ function _isGzipMagic(buf) {
35
+ return buf.length >= 2 && buf[0] === GZIP_MAGIC_0 && buf[1] === GZIP_MAGIC_1;
36
+ }
37
+
38
+ /**
39
+ * @primitive b.archive.gz
40
+ * @signature b.archive.gz(bytes, opts?)
41
+ * @since 0.12.9
42
+ * @status stable
43
+ * @related b.archive.read.gz, b.safeDecompress
44
+ *
45
+ * Wrap a buffer in a gzip envelope. Returns a builder with the same
46
+ * write surface as the other `b.archive` builders — `toBuffer()` /
47
+ * `toAdapter(adapter)` / `digest()` — so gzip slots into the same
48
+ * downstream sinks (object-store + filesystem + http adapters).
49
+ *
50
+ * Composes `b.archive.tar().toGzip(adapter)` / `b.archive.zip().
51
+ * toGzip(adapter)` indirectly: those convenience methods call this
52
+ * primitive after materializing their archive bytes.
53
+ *
54
+ * @opts
55
+ * level: number, // 0-9, default 6 (zlib default).
56
+ *
57
+ * @example
58
+ * var compressed = b.archive.gz(Buffer.from("hello world")).toBuffer();
59
+ * // → 31-byte gzip stream
60
+ */
61
+ function gz(bytes, opts) {
62
+ opts = opts || {};
63
+ if (!Buffer.isBuffer(bytes) && !(bytes instanceof Uint8Array)) {
64
+ throw new ArchiveGzError("archive-gz/bad-input",
65
+ "gz: input must be a Buffer or Uint8Array");
66
+ }
67
+ var input = Buffer.isBuffer(bytes) ? bytes : Buffer.from(bytes);
68
+ var level = opts.level;
69
+ if (level !== undefined &&
70
+ (typeof level !== "number" || level < 0 || level > 9)) {
71
+ throw new ArchiveGzError("archive-gz/bad-arg",
72
+ "gz: opts.level must be a number 0-9; got " + JSON.stringify(level));
73
+ }
74
+ var compressed = null;
75
+ function _materialize() {
76
+ if (compressed !== null) return compressed;
77
+ var zopts = {};
78
+ if (typeof level === "number") zopts.level = level;
79
+ compressed = zlib.gzipSync(input, zopts);
80
+ return compressed;
81
+ }
82
+ return {
83
+ toBuffer: function () { return _materialize(); },
84
+ toAdapter: async function (adapter) {
85
+ if (!adapter || typeof adapter.write !== "function") {
86
+ throw new ArchiveGzError("archive-gz/bad-adapter",
87
+ "gz.toAdapter: adapter must be writable (no .write method)");
88
+ }
89
+ var buf = _materialize();
90
+ await adapter.write(buf);
91
+ if (typeof adapter.close === "function") await adapter.close();
92
+ },
93
+ digest: function () {
94
+ return nodeCrypto.createHash("sha3-512")
95
+ .update(_materialize())
96
+ .digest("hex");
97
+ },
98
+ get compressedBytes() { return _materialize().length; },
99
+ };
100
+ }
101
+
102
+ /**
103
+ * @primitive b.archive.read.gz
104
+ * @signature b.archive.read.gz(adapter, opts)
105
+ * @since 0.12.9
106
+ * @status stable
107
+ * @related b.archive.gz, b.safeDecompress, b.archive.read.tar, b.archive.read.zip
108
+ *
109
+ * Read a gzip stream from an adapter, surface it as either raw bytes
110
+ * (`toBuffer()`) or as a hand-off to a downstream archive reader
111
+ * (`asTar()` / `asZip()`). Every decompression composes
112
+ * `b.safeDecompress` with framework-default caps — `maxOutputBytes`
113
+ * (1 GiB) and `maxExpansionRatio` (100×) — so a hostile `tar.gz`
114
+ * fails the gz gate before any tar parsing happens.
115
+ *
116
+ * @opts
117
+ * maxDecompressedBytes: number, // default 1 GiB
118
+ * maxExpansionRatio: number, // default 100×
119
+ * audit: object,
120
+ *
121
+ * @example
122
+ * var reader = b.archive.read.gz(b.archive.adapters.fs("./bundle.tar.gz"));
123
+ * var tarReader = reader.asTar();
124
+ * var result = await tarReader.extract({ destination: "./out" });
125
+ */
126
+ function readGz(adapter, opts) {
127
+ opts = opts || {};
128
+ if (!adapter || typeof adapter !== "object") {
129
+ throw new ArchiveGzError("archive-gz/bad-adapter",
130
+ "read.gz: adapter is required");
131
+ }
132
+ var maxOutputBytes = opts.maxDecompressedBytes !== undefined
133
+ ? opts.maxDecompressedBytes
134
+ : DEFAULT_MAX_OUTPUT_BYTES;
135
+ var maxRatio = opts.maxExpansionRatio !== undefined
136
+ ? opts.maxExpansionRatio
137
+ : DEFAULT_MAX_RATIO;
138
+ var decompressed = null;
139
+
140
+ async function _collect() {
141
+ if (adapter.kind === "random-access") {
142
+ var size = adapter.size;
143
+ if (size == null && typeof adapter.resolveSize === "function") {
144
+ size = await adapter.resolveSize();
145
+ }
146
+ if (typeof size !== "number" || size === 0) {
147
+ throw new ArchiveGzError("archive-gz/empty-input",
148
+ "read.gz: adapter reports empty payload");
149
+ }
150
+ return adapter.range(0, size);
151
+ }
152
+ if (adapter.kind === "trusted-sequential") {
153
+ var collector = safeBuffer.boundedChunkCollector({
154
+ maxBytes: maxOutputBytes,
155
+ errorClass: ArchiveGzError,
156
+ sizeCode: "archive-gz/trusted-stream-too-large",
157
+ });
158
+ for await (var chunk of adapter.readable) collector.push(chunk);
159
+ return collector.result();
160
+ }
161
+ throw new ArchiveGzError("archive-gz/bad-adapter",
162
+ "read.gz: adapter kind " + JSON.stringify(adapter.kind) + " not supported");
163
+ }
164
+
165
+ async function _materialize() {
166
+ if (decompressed !== null) return decompressed;
167
+ var compressed = await _collect();
168
+ if (!_isGzipMagic(compressed)) {
169
+ throw new ArchiveGzError("archive-gz/bad-magic",
170
+ "read.gz: input does not start with gzip magic 0x1f 0x8b");
171
+ }
172
+ decompressed = safeDecompress().safeDecompress(compressed, {
173
+ algorithm: "gzip",
174
+ maxOutputBytes: maxOutputBytes,
175
+ maxCompressedBytes: compressed.length,
176
+ maxRatio: maxRatio,
177
+ audit: opts.audit,
178
+ });
179
+ return decompressed;
180
+ }
181
+
182
+ return {
183
+ toBuffer: async function () { return _materialize(); },
184
+ asTar: function (tarOpts) {
185
+ tarOpts = tarOpts || {};
186
+ return {
187
+ inspect: async function () {
188
+ var bytes = await _materialize();
189
+ var reader = archiveTarRead().tar(
190
+ archiveAdapters().buffer(bytes), tarOpts);
191
+ return reader.inspect();
192
+ },
193
+ extract: async function (extractOpts) {
194
+ var bytes = await _materialize();
195
+ var reader = archiveTarRead().tar(
196
+ archiveAdapters().buffer(bytes), tarOpts);
197
+ return reader.extract(extractOpts);
198
+ },
199
+ };
200
+ },
201
+ asZip: function (zipOpts) {
202
+ zipOpts = zipOpts || {};
203
+ return {
204
+ inspect: async function () {
205
+ var bytes = await _materialize();
206
+ var reader = archiveRead().zip(
207
+ archiveAdapters().buffer(bytes), zipOpts);
208
+ return reader.inspect();
209
+ },
210
+ extract: async function (extractOpts) {
211
+ var bytes = await _materialize();
212
+ var reader = archiveRead().zip(
213
+ archiveAdapters().buffer(bytes), zipOpts);
214
+ return reader.extract(extractOpts);
215
+ },
216
+ };
217
+ },
218
+ };
219
+ }
220
+
221
+ module.exports = {
222
+ gz: gz,
223
+ read: { gz: readGz },
224
+ ArchiveGzError: ArchiveGzError,
225
+ // Exposed for sibling modules
226
+ _isGzipMagic: _isGzipMagic,
227
+ GZIP_MAGIC_0: GZIP_MAGIC_0,
228
+ GZIP_MAGIC_1: GZIP_MAGIC_1,
229
+ };