@granite-js/pulumi-aws 0.0.1
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/CHANGELOG.md +18 -0
- package/README.md +90 -0
- package/dist/index.cjs +2007 -0
- package/dist/index.d.cts +27 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +2007 -0
- package/dist/lambda/auto-cache-removal.cjs +20895 -0
- package/dist/lambda/origin-request.cjs +25436 -0
- package/dist/lambda/origin-response.cjs +24597 -0
- package/dist/prebuilt-shared/bundle.android.hbc.gz +0 -0
- package/dist/prebuilt-shared/bundle.ios.hbc.gz +0 -0
- package/package.json +57 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,2007 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
8
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
9
|
+
}) : x)(function(x) {
|
|
10
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
11
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
12
|
+
});
|
|
13
|
+
var __esm = (fn, res) => function __init() {
|
|
14
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
15
|
+
};
|
|
16
|
+
var __commonJS = (cb, mod) => function __require2() {
|
|
17
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
18
|
+
};
|
|
19
|
+
var __copyProps = (to, from, except, desc) => {
|
|
20
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
21
|
+
for (let key of __getOwnPropNames(from))
|
|
22
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
23
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
24
|
+
}
|
|
25
|
+
return to;
|
|
26
|
+
};
|
|
27
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
28
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
29
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
30
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
31
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
32
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
33
|
+
mod
|
|
34
|
+
));
|
|
35
|
+
|
|
36
|
+
// ../../.yarn/__virtual__/tsup-virtual-699424e35d/0/cache/tsup-npm-8.5.0-e9d25b74d7-2eddc1138a.zip/node_modules/tsup/assets/esm_shims.js
|
|
37
|
+
import path from "path";
|
|
38
|
+
import { fileURLToPath } from "url";
|
|
39
|
+
var getFilename, getDirname, __dirname;
|
|
40
|
+
var init_esm_shims = __esm({
|
|
41
|
+
"../../.yarn/__virtual__/tsup-virtual-699424e35d/0/cache/tsup-npm-8.5.0-e9d25b74d7-2eddc1138a.zip/node_modules/tsup/assets/esm_shims.js"() {
|
|
42
|
+
"use strict";
|
|
43
|
+
getFilename = () => fileURLToPath(import.meta.url);
|
|
44
|
+
getDirname = () => path.dirname(getFilename());
|
|
45
|
+
__dirname = /* @__PURE__ */ getDirname();
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// ../../.yarn/cache/pend-npm-1.2.0-7a13d93266-8a87e63f7a.zip/node_modules/pend/index.js
|
|
50
|
+
var require_pend = __commonJS({
|
|
51
|
+
"../../.yarn/cache/pend-npm-1.2.0-7a13d93266-8a87e63f7a.zip/node_modules/pend/index.js"(exports, module) {
|
|
52
|
+
"use strict";
|
|
53
|
+
init_esm_shims();
|
|
54
|
+
module.exports = Pend;
|
|
55
|
+
function Pend() {
|
|
56
|
+
this.pending = 0;
|
|
57
|
+
this.max = Infinity;
|
|
58
|
+
this.listeners = [];
|
|
59
|
+
this.waiting = [];
|
|
60
|
+
this.error = null;
|
|
61
|
+
}
|
|
62
|
+
Pend.prototype.go = function(fn) {
|
|
63
|
+
if (this.pending < this.max) {
|
|
64
|
+
pendGo(this, fn);
|
|
65
|
+
} else {
|
|
66
|
+
this.waiting.push(fn);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
Pend.prototype.wait = function(cb) {
|
|
70
|
+
if (this.pending === 0) {
|
|
71
|
+
cb(this.error);
|
|
72
|
+
} else {
|
|
73
|
+
this.listeners.push(cb);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
Pend.prototype.hold = function() {
|
|
77
|
+
return pendHold(this);
|
|
78
|
+
};
|
|
79
|
+
function pendHold(self) {
|
|
80
|
+
self.pending += 1;
|
|
81
|
+
var called = false;
|
|
82
|
+
return onCb;
|
|
83
|
+
function onCb(err) {
|
|
84
|
+
if (called) throw new Error("callback called twice");
|
|
85
|
+
called = true;
|
|
86
|
+
self.error = self.error || err;
|
|
87
|
+
self.pending -= 1;
|
|
88
|
+
if (self.waiting.length > 0 && self.pending < self.max) {
|
|
89
|
+
pendGo(self, self.waiting.shift());
|
|
90
|
+
} else if (self.pending === 0) {
|
|
91
|
+
var listeners = self.listeners;
|
|
92
|
+
self.listeners = [];
|
|
93
|
+
listeners.forEach(cbListener);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function cbListener(listener) {
|
|
97
|
+
listener(self.error);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function pendGo(self, fn) {
|
|
101
|
+
fn(pendHold(self));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
// ../../.yarn/cache/yauzl-npm-3.2.0-22e6762265-7b40b3dc46.zip/node_modules/yauzl/fd-slicer.js
|
|
107
|
+
var require_fd_slicer = __commonJS({
|
|
108
|
+
"../../.yarn/cache/yauzl-npm-3.2.0-22e6762265-7b40b3dc46.zip/node_modules/yauzl/fd-slicer.js"(exports) {
|
|
109
|
+
"use strict";
|
|
110
|
+
init_esm_shims();
|
|
111
|
+
var fs3 = __require("fs");
|
|
112
|
+
var util = __require("util");
|
|
113
|
+
var stream = __require("stream");
|
|
114
|
+
var Readable = stream.Readable;
|
|
115
|
+
var Writable = stream.Writable;
|
|
116
|
+
var PassThrough = stream.PassThrough;
|
|
117
|
+
var Pend = require_pend();
|
|
118
|
+
var EventEmitter = __require("events").EventEmitter;
|
|
119
|
+
exports.createFromBuffer = createFromBuffer;
|
|
120
|
+
exports.createFromFd = createFromFd;
|
|
121
|
+
exports.BufferSlicer = BufferSlicer;
|
|
122
|
+
exports.FdSlicer = FdSlicer;
|
|
123
|
+
util.inherits(FdSlicer, EventEmitter);
|
|
124
|
+
function FdSlicer(fd, options2) {
|
|
125
|
+
options2 = options2 || {};
|
|
126
|
+
EventEmitter.call(this);
|
|
127
|
+
this.fd = fd;
|
|
128
|
+
this.pend = new Pend();
|
|
129
|
+
this.pend.max = 1;
|
|
130
|
+
this.refCount = 0;
|
|
131
|
+
this.autoClose = !!options2.autoClose;
|
|
132
|
+
}
|
|
133
|
+
FdSlicer.prototype.read = function(buffer, offset, length, position, callback) {
|
|
134
|
+
var self = this;
|
|
135
|
+
self.pend.go(function(cb) {
|
|
136
|
+
fs3.read(self.fd, buffer, offset, length, position, function(err, bytesRead, buffer2) {
|
|
137
|
+
cb();
|
|
138
|
+
callback(err, bytesRead, buffer2);
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
};
|
|
142
|
+
FdSlicer.prototype.write = function(buffer, offset, length, position, callback) {
|
|
143
|
+
var self = this;
|
|
144
|
+
self.pend.go(function(cb) {
|
|
145
|
+
fs3.write(self.fd, buffer, offset, length, position, function(err, written, buffer2) {
|
|
146
|
+
cb();
|
|
147
|
+
callback(err, written, buffer2);
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
};
|
|
151
|
+
FdSlicer.prototype.createReadStream = function(options2) {
|
|
152
|
+
return new ReadStream(this, options2);
|
|
153
|
+
};
|
|
154
|
+
FdSlicer.prototype.createWriteStream = function(options2) {
|
|
155
|
+
return new WriteStream(this, options2);
|
|
156
|
+
};
|
|
157
|
+
FdSlicer.prototype.ref = function() {
|
|
158
|
+
this.refCount += 1;
|
|
159
|
+
};
|
|
160
|
+
FdSlicer.prototype.unref = function() {
|
|
161
|
+
var self = this;
|
|
162
|
+
self.refCount -= 1;
|
|
163
|
+
if (self.refCount > 0) return;
|
|
164
|
+
if (self.refCount < 0) throw new Error("invalid unref");
|
|
165
|
+
if (self.autoClose) {
|
|
166
|
+
fs3.close(self.fd, onCloseDone);
|
|
167
|
+
}
|
|
168
|
+
function onCloseDone(err) {
|
|
169
|
+
if (err) {
|
|
170
|
+
self.emit("error", err);
|
|
171
|
+
} else {
|
|
172
|
+
self.emit("close");
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
util.inherits(ReadStream, Readable);
|
|
177
|
+
function ReadStream(context, options2) {
|
|
178
|
+
options2 = options2 || {};
|
|
179
|
+
Readable.call(this, options2);
|
|
180
|
+
this.context = context;
|
|
181
|
+
this.context.ref();
|
|
182
|
+
this.start = options2.start || 0;
|
|
183
|
+
this.endOffset = options2.end;
|
|
184
|
+
this.pos = this.start;
|
|
185
|
+
this.destroyed = false;
|
|
186
|
+
}
|
|
187
|
+
ReadStream.prototype._read = function(n) {
|
|
188
|
+
var self = this;
|
|
189
|
+
if (self.destroyed) return;
|
|
190
|
+
var toRead = Math.min(self._readableState.highWaterMark, n);
|
|
191
|
+
if (self.endOffset != null) {
|
|
192
|
+
toRead = Math.min(toRead, self.endOffset - self.pos);
|
|
193
|
+
}
|
|
194
|
+
if (toRead <= 0) {
|
|
195
|
+
self.destroyed = true;
|
|
196
|
+
self.push(null);
|
|
197
|
+
self.context.unref();
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
self.context.pend.go(function(cb) {
|
|
201
|
+
if (self.destroyed) return cb();
|
|
202
|
+
var buffer = Buffer.allocUnsafe(toRead);
|
|
203
|
+
fs3.read(self.context.fd, buffer, 0, toRead, self.pos, function(err, bytesRead) {
|
|
204
|
+
if (err) {
|
|
205
|
+
self.destroy(err);
|
|
206
|
+
} else if (bytesRead === 0) {
|
|
207
|
+
self.destroyed = true;
|
|
208
|
+
self.push(null);
|
|
209
|
+
self.context.unref();
|
|
210
|
+
} else {
|
|
211
|
+
self.pos += bytesRead;
|
|
212
|
+
self.push(buffer.slice(0, bytesRead));
|
|
213
|
+
}
|
|
214
|
+
cb();
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
};
|
|
218
|
+
ReadStream.prototype.destroy = function(err) {
|
|
219
|
+
if (this.destroyed) return;
|
|
220
|
+
err = err || new Error("stream destroyed");
|
|
221
|
+
this.destroyed = true;
|
|
222
|
+
this.emit("error", err);
|
|
223
|
+
this.context.unref();
|
|
224
|
+
};
|
|
225
|
+
util.inherits(WriteStream, Writable);
|
|
226
|
+
function WriteStream(context, options2) {
|
|
227
|
+
options2 = options2 || {};
|
|
228
|
+
Writable.call(this, options2);
|
|
229
|
+
this.context = context;
|
|
230
|
+
this.context.ref();
|
|
231
|
+
this.start = options2.start || 0;
|
|
232
|
+
this.endOffset = options2.end == null ? Infinity : +options2.end;
|
|
233
|
+
this.bytesWritten = 0;
|
|
234
|
+
this.pos = this.start;
|
|
235
|
+
this.destroyed = false;
|
|
236
|
+
this.on("finish", this.destroy.bind(this));
|
|
237
|
+
}
|
|
238
|
+
WriteStream.prototype._write = function(buffer, encoding, callback) {
|
|
239
|
+
var self = this;
|
|
240
|
+
if (self.destroyed) return;
|
|
241
|
+
if (self.pos + buffer.length > self.endOffset) {
|
|
242
|
+
var err = new Error("maximum file length exceeded");
|
|
243
|
+
err.code = "ETOOBIG";
|
|
244
|
+
self.destroy();
|
|
245
|
+
callback(err);
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
self.context.pend.go(function(cb) {
|
|
249
|
+
if (self.destroyed) return cb();
|
|
250
|
+
fs3.write(self.context.fd, buffer, 0, buffer.length, self.pos, function(err2, bytes) {
|
|
251
|
+
if (err2) {
|
|
252
|
+
self.destroy();
|
|
253
|
+
cb();
|
|
254
|
+
callback(err2);
|
|
255
|
+
} else {
|
|
256
|
+
self.bytesWritten += bytes;
|
|
257
|
+
self.pos += bytes;
|
|
258
|
+
self.emit("progress");
|
|
259
|
+
cb();
|
|
260
|
+
callback();
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
};
|
|
265
|
+
WriteStream.prototype.destroy = function() {
|
|
266
|
+
if (this.destroyed) return;
|
|
267
|
+
this.destroyed = true;
|
|
268
|
+
this.context.unref();
|
|
269
|
+
};
|
|
270
|
+
util.inherits(BufferSlicer, EventEmitter);
|
|
271
|
+
function BufferSlicer(buffer, options2) {
|
|
272
|
+
EventEmitter.call(this);
|
|
273
|
+
options2 = options2 || {};
|
|
274
|
+
this.refCount = 0;
|
|
275
|
+
this.buffer = buffer;
|
|
276
|
+
this.maxChunkSize = options2.maxChunkSize || Number.MAX_SAFE_INTEGER;
|
|
277
|
+
}
|
|
278
|
+
BufferSlicer.prototype.read = function(buffer, offset, length, position, callback) {
|
|
279
|
+
if (!(0 <= offset && offset <= buffer.length)) throw new RangeError("offset outside buffer: 0 <= " + offset + " <= " + buffer.length);
|
|
280
|
+
if (position < 0) throw new RangeError("position is negative: " + position);
|
|
281
|
+
if (offset + length > buffer.length) {
|
|
282
|
+
length = buffer.length - offset;
|
|
283
|
+
}
|
|
284
|
+
if (position + length > this.buffer.length) {
|
|
285
|
+
length = this.buffer.length - position;
|
|
286
|
+
}
|
|
287
|
+
if (length <= 0) {
|
|
288
|
+
setImmediate(function() {
|
|
289
|
+
callback(null, 0);
|
|
290
|
+
});
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
this.buffer.copy(buffer, offset, position, position + length);
|
|
294
|
+
setImmediate(function() {
|
|
295
|
+
callback(null, length);
|
|
296
|
+
});
|
|
297
|
+
};
|
|
298
|
+
BufferSlicer.prototype.write = function(buffer, offset, length, position, callback) {
|
|
299
|
+
buffer.copy(this.buffer, position, offset, offset + length);
|
|
300
|
+
setImmediate(function() {
|
|
301
|
+
callback(null, length, buffer);
|
|
302
|
+
});
|
|
303
|
+
};
|
|
304
|
+
BufferSlicer.prototype.createReadStream = function(options2) {
|
|
305
|
+
options2 = options2 || {};
|
|
306
|
+
var readStream = new PassThrough(options2);
|
|
307
|
+
readStream.destroyed = false;
|
|
308
|
+
readStream.start = options2.start || 0;
|
|
309
|
+
readStream.endOffset = options2.end;
|
|
310
|
+
readStream.pos = readStream.endOffset || this.buffer.length;
|
|
311
|
+
var entireSlice = this.buffer.slice(readStream.start, readStream.pos);
|
|
312
|
+
var offset = 0;
|
|
313
|
+
while (true) {
|
|
314
|
+
var nextOffset = offset + this.maxChunkSize;
|
|
315
|
+
if (nextOffset >= entireSlice.length) {
|
|
316
|
+
if (offset < entireSlice.length) {
|
|
317
|
+
readStream.write(entireSlice.slice(offset, entireSlice.length));
|
|
318
|
+
}
|
|
319
|
+
break;
|
|
320
|
+
}
|
|
321
|
+
readStream.write(entireSlice.slice(offset, nextOffset));
|
|
322
|
+
offset = nextOffset;
|
|
323
|
+
}
|
|
324
|
+
readStream.end();
|
|
325
|
+
readStream.destroy = function() {
|
|
326
|
+
readStream.destroyed = true;
|
|
327
|
+
};
|
|
328
|
+
return readStream;
|
|
329
|
+
};
|
|
330
|
+
BufferSlicer.prototype.createWriteStream = function(options2) {
|
|
331
|
+
var bufferSlicer = this;
|
|
332
|
+
options2 = options2 || {};
|
|
333
|
+
var writeStream = new Writable(options2);
|
|
334
|
+
writeStream.start = options2.start || 0;
|
|
335
|
+
writeStream.endOffset = options2.end == null ? this.buffer.length : +options2.end;
|
|
336
|
+
writeStream.bytesWritten = 0;
|
|
337
|
+
writeStream.pos = writeStream.start;
|
|
338
|
+
writeStream.destroyed = false;
|
|
339
|
+
writeStream._write = function(buffer, encoding, callback) {
|
|
340
|
+
if (writeStream.destroyed) return;
|
|
341
|
+
var end = writeStream.pos + buffer.length;
|
|
342
|
+
if (end > writeStream.endOffset) {
|
|
343
|
+
var err = new Error("maximum file length exceeded");
|
|
344
|
+
err.code = "ETOOBIG";
|
|
345
|
+
writeStream.destroyed = true;
|
|
346
|
+
callback(err);
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
buffer.copy(bufferSlicer.buffer, writeStream.pos, 0, buffer.length);
|
|
350
|
+
writeStream.bytesWritten += buffer.length;
|
|
351
|
+
writeStream.pos = end;
|
|
352
|
+
writeStream.emit("progress");
|
|
353
|
+
callback();
|
|
354
|
+
};
|
|
355
|
+
writeStream.destroy = function() {
|
|
356
|
+
writeStream.destroyed = true;
|
|
357
|
+
};
|
|
358
|
+
return writeStream;
|
|
359
|
+
};
|
|
360
|
+
BufferSlicer.prototype.ref = function() {
|
|
361
|
+
this.refCount += 1;
|
|
362
|
+
};
|
|
363
|
+
BufferSlicer.prototype.unref = function() {
|
|
364
|
+
this.refCount -= 1;
|
|
365
|
+
if (this.refCount < 0) {
|
|
366
|
+
throw new Error("invalid unref");
|
|
367
|
+
}
|
|
368
|
+
};
|
|
369
|
+
function createFromBuffer(buffer, options2) {
|
|
370
|
+
return new BufferSlicer(buffer, options2);
|
|
371
|
+
}
|
|
372
|
+
function createFromFd(fd, options2) {
|
|
373
|
+
return new FdSlicer(fd, options2);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
// ../../.yarn/cache/buffer-crc32-npm-0.2.13-c4b6fceac1-cb0a8ddf5c.zip/node_modules/buffer-crc32/index.js
|
|
379
|
+
var require_buffer_crc32 = __commonJS({
|
|
380
|
+
"../../.yarn/cache/buffer-crc32-npm-0.2.13-c4b6fceac1-cb0a8ddf5c.zip/node_modules/buffer-crc32/index.js"(exports, module) {
|
|
381
|
+
"use strict";
|
|
382
|
+
init_esm_shims();
|
|
383
|
+
var Buffer2 = __require("buffer").Buffer;
|
|
384
|
+
var CRC_TABLE = [
|
|
385
|
+
0,
|
|
386
|
+
1996959894,
|
|
387
|
+
3993919788,
|
|
388
|
+
2567524794,
|
|
389
|
+
124634137,
|
|
390
|
+
1886057615,
|
|
391
|
+
3915621685,
|
|
392
|
+
2657392035,
|
|
393
|
+
249268274,
|
|
394
|
+
2044508324,
|
|
395
|
+
3772115230,
|
|
396
|
+
2547177864,
|
|
397
|
+
162941995,
|
|
398
|
+
2125561021,
|
|
399
|
+
3887607047,
|
|
400
|
+
2428444049,
|
|
401
|
+
498536548,
|
|
402
|
+
1789927666,
|
|
403
|
+
4089016648,
|
|
404
|
+
2227061214,
|
|
405
|
+
450548861,
|
|
406
|
+
1843258603,
|
|
407
|
+
4107580753,
|
|
408
|
+
2211677639,
|
|
409
|
+
325883990,
|
|
410
|
+
1684777152,
|
|
411
|
+
4251122042,
|
|
412
|
+
2321926636,
|
|
413
|
+
335633487,
|
|
414
|
+
1661365465,
|
|
415
|
+
4195302755,
|
|
416
|
+
2366115317,
|
|
417
|
+
997073096,
|
|
418
|
+
1281953886,
|
|
419
|
+
3579855332,
|
|
420
|
+
2724688242,
|
|
421
|
+
1006888145,
|
|
422
|
+
1258607687,
|
|
423
|
+
3524101629,
|
|
424
|
+
2768942443,
|
|
425
|
+
901097722,
|
|
426
|
+
1119000684,
|
|
427
|
+
3686517206,
|
|
428
|
+
2898065728,
|
|
429
|
+
853044451,
|
|
430
|
+
1172266101,
|
|
431
|
+
3705015759,
|
|
432
|
+
2882616665,
|
|
433
|
+
651767980,
|
|
434
|
+
1373503546,
|
|
435
|
+
3369554304,
|
|
436
|
+
3218104598,
|
|
437
|
+
565507253,
|
|
438
|
+
1454621731,
|
|
439
|
+
3485111705,
|
|
440
|
+
3099436303,
|
|
441
|
+
671266974,
|
|
442
|
+
1594198024,
|
|
443
|
+
3322730930,
|
|
444
|
+
2970347812,
|
|
445
|
+
795835527,
|
|
446
|
+
1483230225,
|
|
447
|
+
3244367275,
|
|
448
|
+
3060149565,
|
|
449
|
+
1994146192,
|
|
450
|
+
31158534,
|
|
451
|
+
2563907772,
|
|
452
|
+
4023717930,
|
|
453
|
+
1907459465,
|
|
454
|
+
112637215,
|
|
455
|
+
2680153253,
|
|
456
|
+
3904427059,
|
|
457
|
+
2013776290,
|
|
458
|
+
251722036,
|
|
459
|
+
2517215374,
|
|
460
|
+
3775830040,
|
|
461
|
+
2137656763,
|
|
462
|
+
141376813,
|
|
463
|
+
2439277719,
|
|
464
|
+
3865271297,
|
|
465
|
+
1802195444,
|
|
466
|
+
476864866,
|
|
467
|
+
2238001368,
|
|
468
|
+
4066508878,
|
|
469
|
+
1812370925,
|
|
470
|
+
453092731,
|
|
471
|
+
2181625025,
|
|
472
|
+
4111451223,
|
|
473
|
+
1706088902,
|
|
474
|
+
314042704,
|
|
475
|
+
2344532202,
|
|
476
|
+
4240017532,
|
|
477
|
+
1658658271,
|
|
478
|
+
366619977,
|
|
479
|
+
2362670323,
|
|
480
|
+
4224994405,
|
|
481
|
+
1303535960,
|
|
482
|
+
984961486,
|
|
483
|
+
2747007092,
|
|
484
|
+
3569037538,
|
|
485
|
+
1256170817,
|
|
486
|
+
1037604311,
|
|
487
|
+
2765210733,
|
|
488
|
+
3554079995,
|
|
489
|
+
1131014506,
|
|
490
|
+
879679996,
|
|
491
|
+
2909243462,
|
|
492
|
+
3663771856,
|
|
493
|
+
1141124467,
|
|
494
|
+
855842277,
|
|
495
|
+
2852801631,
|
|
496
|
+
3708648649,
|
|
497
|
+
1342533948,
|
|
498
|
+
654459306,
|
|
499
|
+
3188396048,
|
|
500
|
+
3373015174,
|
|
501
|
+
1466479909,
|
|
502
|
+
544179635,
|
|
503
|
+
3110523913,
|
|
504
|
+
3462522015,
|
|
505
|
+
1591671054,
|
|
506
|
+
702138776,
|
|
507
|
+
2966460450,
|
|
508
|
+
3352799412,
|
|
509
|
+
1504918807,
|
|
510
|
+
783551873,
|
|
511
|
+
3082640443,
|
|
512
|
+
3233442989,
|
|
513
|
+
3988292384,
|
|
514
|
+
2596254646,
|
|
515
|
+
62317068,
|
|
516
|
+
1957810842,
|
|
517
|
+
3939845945,
|
|
518
|
+
2647816111,
|
|
519
|
+
81470997,
|
|
520
|
+
1943803523,
|
|
521
|
+
3814918930,
|
|
522
|
+
2489596804,
|
|
523
|
+
225274430,
|
|
524
|
+
2053790376,
|
|
525
|
+
3826175755,
|
|
526
|
+
2466906013,
|
|
527
|
+
167816743,
|
|
528
|
+
2097651377,
|
|
529
|
+
4027552580,
|
|
530
|
+
2265490386,
|
|
531
|
+
503444072,
|
|
532
|
+
1762050814,
|
|
533
|
+
4150417245,
|
|
534
|
+
2154129355,
|
|
535
|
+
426522225,
|
|
536
|
+
1852507879,
|
|
537
|
+
4275313526,
|
|
538
|
+
2312317920,
|
|
539
|
+
282753626,
|
|
540
|
+
1742555852,
|
|
541
|
+
4189708143,
|
|
542
|
+
2394877945,
|
|
543
|
+
397917763,
|
|
544
|
+
1622183637,
|
|
545
|
+
3604390888,
|
|
546
|
+
2714866558,
|
|
547
|
+
953729732,
|
|
548
|
+
1340076626,
|
|
549
|
+
3518719985,
|
|
550
|
+
2797360999,
|
|
551
|
+
1068828381,
|
|
552
|
+
1219638859,
|
|
553
|
+
3624741850,
|
|
554
|
+
2936675148,
|
|
555
|
+
906185462,
|
|
556
|
+
1090812512,
|
|
557
|
+
3747672003,
|
|
558
|
+
2825379669,
|
|
559
|
+
829329135,
|
|
560
|
+
1181335161,
|
|
561
|
+
3412177804,
|
|
562
|
+
3160834842,
|
|
563
|
+
628085408,
|
|
564
|
+
1382605366,
|
|
565
|
+
3423369109,
|
|
566
|
+
3138078467,
|
|
567
|
+
570562233,
|
|
568
|
+
1426400815,
|
|
569
|
+
3317316542,
|
|
570
|
+
2998733608,
|
|
571
|
+
733239954,
|
|
572
|
+
1555261956,
|
|
573
|
+
3268935591,
|
|
574
|
+
3050360625,
|
|
575
|
+
752459403,
|
|
576
|
+
1541320221,
|
|
577
|
+
2607071920,
|
|
578
|
+
3965973030,
|
|
579
|
+
1969922972,
|
|
580
|
+
40735498,
|
|
581
|
+
2617837225,
|
|
582
|
+
3943577151,
|
|
583
|
+
1913087877,
|
|
584
|
+
83908371,
|
|
585
|
+
2512341634,
|
|
586
|
+
3803740692,
|
|
587
|
+
2075208622,
|
|
588
|
+
213261112,
|
|
589
|
+
2463272603,
|
|
590
|
+
3855990285,
|
|
591
|
+
2094854071,
|
|
592
|
+
198958881,
|
|
593
|
+
2262029012,
|
|
594
|
+
4057260610,
|
|
595
|
+
1759359992,
|
|
596
|
+
534414190,
|
|
597
|
+
2176718541,
|
|
598
|
+
4139329115,
|
|
599
|
+
1873836001,
|
|
600
|
+
414664567,
|
|
601
|
+
2282248934,
|
|
602
|
+
4279200368,
|
|
603
|
+
1711684554,
|
|
604
|
+
285281116,
|
|
605
|
+
2405801727,
|
|
606
|
+
4167216745,
|
|
607
|
+
1634467795,
|
|
608
|
+
376229701,
|
|
609
|
+
2685067896,
|
|
610
|
+
3608007406,
|
|
611
|
+
1308918612,
|
|
612
|
+
956543938,
|
|
613
|
+
2808555105,
|
|
614
|
+
3495958263,
|
|
615
|
+
1231636301,
|
|
616
|
+
1047427035,
|
|
617
|
+
2932959818,
|
|
618
|
+
3654703836,
|
|
619
|
+
1088359270,
|
|
620
|
+
936918e3,
|
|
621
|
+
2847714899,
|
|
622
|
+
3736837829,
|
|
623
|
+
1202900863,
|
|
624
|
+
817233897,
|
|
625
|
+
3183342108,
|
|
626
|
+
3401237130,
|
|
627
|
+
1404277552,
|
|
628
|
+
615818150,
|
|
629
|
+
3134207493,
|
|
630
|
+
3453421203,
|
|
631
|
+
1423857449,
|
|
632
|
+
601450431,
|
|
633
|
+
3009837614,
|
|
634
|
+
3294710456,
|
|
635
|
+
1567103746,
|
|
636
|
+
711928724,
|
|
637
|
+
3020668471,
|
|
638
|
+
3272380065,
|
|
639
|
+
1510334235,
|
|
640
|
+
755167117
|
|
641
|
+
];
|
|
642
|
+
if (typeof Int32Array !== "undefined") {
|
|
643
|
+
CRC_TABLE = new Int32Array(CRC_TABLE);
|
|
644
|
+
}
|
|
645
|
+
function ensureBuffer(input) {
|
|
646
|
+
if (Buffer2.isBuffer(input)) {
|
|
647
|
+
return input;
|
|
648
|
+
}
|
|
649
|
+
var hasNewBufferAPI = typeof Buffer2.alloc === "function" && typeof Buffer2.from === "function";
|
|
650
|
+
if (typeof input === "number") {
|
|
651
|
+
return hasNewBufferAPI ? Buffer2.alloc(input) : new Buffer2(input);
|
|
652
|
+
} else if (typeof input === "string") {
|
|
653
|
+
return hasNewBufferAPI ? Buffer2.from(input) : new Buffer2(input);
|
|
654
|
+
} else {
|
|
655
|
+
throw new Error("input must be buffer, number, or string, received " + typeof input);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
function bufferizeInt(num) {
|
|
659
|
+
var tmp = ensureBuffer(4);
|
|
660
|
+
tmp.writeInt32BE(num, 0);
|
|
661
|
+
return tmp;
|
|
662
|
+
}
|
|
663
|
+
function _crc32(buf, previous) {
|
|
664
|
+
buf = ensureBuffer(buf);
|
|
665
|
+
if (Buffer2.isBuffer(previous)) {
|
|
666
|
+
previous = previous.readUInt32BE(0);
|
|
667
|
+
}
|
|
668
|
+
var crc = ~~previous ^ -1;
|
|
669
|
+
for (var n = 0; n < buf.length; n++) {
|
|
670
|
+
crc = CRC_TABLE[(crc ^ buf[n]) & 255] ^ crc >>> 8;
|
|
671
|
+
}
|
|
672
|
+
return crc ^ -1;
|
|
673
|
+
}
|
|
674
|
+
function crc32() {
|
|
675
|
+
return bufferizeInt(_crc32.apply(null, arguments));
|
|
676
|
+
}
|
|
677
|
+
crc32.signed = function() {
|
|
678
|
+
return _crc32.apply(null, arguments);
|
|
679
|
+
};
|
|
680
|
+
crc32.unsigned = function() {
|
|
681
|
+
return _crc32.apply(null, arguments) >>> 0;
|
|
682
|
+
};
|
|
683
|
+
module.exports = crc32;
|
|
684
|
+
}
|
|
685
|
+
});
|
|
686
|
+
|
|
687
|
+
// ../../.yarn/cache/yauzl-npm-3.2.0-22e6762265-7b40b3dc46.zip/node_modules/yauzl/index.js
|
|
688
|
+
var require_yauzl = __commonJS({
|
|
689
|
+
"../../.yarn/cache/yauzl-npm-3.2.0-22e6762265-7b40b3dc46.zip/node_modules/yauzl/index.js"(exports) {
|
|
690
|
+
"use strict";
|
|
691
|
+
init_esm_shims();
|
|
692
|
+
var fs3 = __require("fs");
|
|
693
|
+
var zlib = __require("zlib");
|
|
694
|
+
var fd_slicer = require_fd_slicer();
|
|
695
|
+
var crc32 = require_buffer_crc32();
|
|
696
|
+
var util = __require("util");
|
|
697
|
+
var EventEmitter = __require("events").EventEmitter;
|
|
698
|
+
var Transform = __require("stream").Transform;
|
|
699
|
+
var PassThrough = __require("stream").PassThrough;
|
|
700
|
+
var Writable = __require("stream").Writable;
|
|
701
|
+
exports.open = open;
|
|
702
|
+
exports.fromFd = fromFd;
|
|
703
|
+
exports.fromBuffer = fromBuffer;
|
|
704
|
+
exports.fromRandomAccessReader = fromRandomAccessReader;
|
|
705
|
+
exports.dosDateTimeToDate = dosDateTimeToDate;
|
|
706
|
+
exports.getFileNameLowLevel = getFileNameLowLevel;
|
|
707
|
+
exports.validateFileName = validateFileName;
|
|
708
|
+
exports.parseExtraFields = parseExtraFields;
|
|
709
|
+
exports.ZipFile = ZipFile;
|
|
710
|
+
exports.Entry = Entry;
|
|
711
|
+
exports.LocalFileHeader = LocalFileHeader;
|
|
712
|
+
exports.RandomAccessReader = RandomAccessReader;
|
|
713
|
+
function open(path4, options2, callback) {
|
|
714
|
+
if (typeof options2 === "function") {
|
|
715
|
+
callback = options2;
|
|
716
|
+
options2 = null;
|
|
717
|
+
}
|
|
718
|
+
if (options2 == null) options2 = {};
|
|
719
|
+
if (options2.autoClose == null) options2.autoClose = true;
|
|
720
|
+
if (options2.lazyEntries == null) options2.lazyEntries = false;
|
|
721
|
+
if (options2.decodeStrings == null) options2.decodeStrings = true;
|
|
722
|
+
if (options2.validateEntrySizes == null) options2.validateEntrySizes = true;
|
|
723
|
+
if (options2.strictFileNames == null) options2.strictFileNames = false;
|
|
724
|
+
if (callback == null) callback = defaultCallback;
|
|
725
|
+
fs3.open(path4, "r", function(err, fd) {
|
|
726
|
+
if (err) return callback(err);
|
|
727
|
+
fromFd(fd, options2, function(err2, zipfile) {
|
|
728
|
+
if (err2) fs3.close(fd, defaultCallback);
|
|
729
|
+
callback(err2, zipfile);
|
|
730
|
+
});
|
|
731
|
+
});
|
|
732
|
+
}
|
|
733
|
+
function fromFd(fd, options2, callback) {
|
|
734
|
+
if (typeof options2 === "function") {
|
|
735
|
+
callback = options2;
|
|
736
|
+
options2 = null;
|
|
737
|
+
}
|
|
738
|
+
if (options2 == null) options2 = {};
|
|
739
|
+
if (options2.autoClose == null) options2.autoClose = false;
|
|
740
|
+
if (options2.lazyEntries == null) options2.lazyEntries = false;
|
|
741
|
+
if (options2.decodeStrings == null) options2.decodeStrings = true;
|
|
742
|
+
if (options2.validateEntrySizes == null) options2.validateEntrySizes = true;
|
|
743
|
+
if (options2.strictFileNames == null) options2.strictFileNames = false;
|
|
744
|
+
if (callback == null) callback = defaultCallback;
|
|
745
|
+
fs3.fstat(fd, function(err, stats) {
|
|
746
|
+
if (err) return callback(err);
|
|
747
|
+
var reader = fd_slicer.createFromFd(fd, { autoClose: true });
|
|
748
|
+
fromRandomAccessReader(reader, stats.size, options2, callback);
|
|
749
|
+
});
|
|
750
|
+
}
|
|
751
|
+
function fromBuffer(buffer, options2, callback) {
|
|
752
|
+
if (typeof options2 === "function") {
|
|
753
|
+
callback = options2;
|
|
754
|
+
options2 = null;
|
|
755
|
+
}
|
|
756
|
+
if (options2 == null) options2 = {};
|
|
757
|
+
options2.autoClose = false;
|
|
758
|
+
if (options2.lazyEntries == null) options2.lazyEntries = false;
|
|
759
|
+
if (options2.decodeStrings == null) options2.decodeStrings = true;
|
|
760
|
+
if (options2.validateEntrySizes == null) options2.validateEntrySizes = true;
|
|
761
|
+
if (options2.strictFileNames == null) options2.strictFileNames = false;
|
|
762
|
+
var reader = fd_slicer.createFromBuffer(buffer, { maxChunkSize: 65536 });
|
|
763
|
+
fromRandomAccessReader(reader, buffer.length, options2, callback);
|
|
764
|
+
}
|
|
765
|
+
function fromRandomAccessReader(reader, totalSize, options2, callback) {
|
|
766
|
+
if (typeof options2 === "function") {
|
|
767
|
+
callback = options2;
|
|
768
|
+
options2 = null;
|
|
769
|
+
}
|
|
770
|
+
if (options2 == null) options2 = {};
|
|
771
|
+
if (options2.autoClose == null) options2.autoClose = true;
|
|
772
|
+
if (options2.lazyEntries == null) options2.lazyEntries = false;
|
|
773
|
+
if (options2.decodeStrings == null) options2.decodeStrings = true;
|
|
774
|
+
var decodeStrings = !!options2.decodeStrings;
|
|
775
|
+
if (options2.validateEntrySizes == null) options2.validateEntrySizes = true;
|
|
776
|
+
if (options2.strictFileNames == null) options2.strictFileNames = false;
|
|
777
|
+
if (callback == null) callback = defaultCallback;
|
|
778
|
+
if (typeof totalSize !== "number") throw new Error("expected totalSize parameter to be a number");
|
|
779
|
+
if (totalSize > Number.MAX_SAFE_INTEGER) {
|
|
780
|
+
throw new Error("zip file too large. only file sizes up to 2^52 are supported due to JavaScript's Number type being an IEEE 754 double.");
|
|
781
|
+
}
|
|
782
|
+
reader.ref();
|
|
783
|
+
var eocdrWithoutCommentSize = 22;
|
|
784
|
+
var zip64EocdlSize = 20;
|
|
785
|
+
var maxCommentSize = 65535;
|
|
786
|
+
var bufferSize = Math.min(zip64EocdlSize + eocdrWithoutCommentSize + maxCommentSize, totalSize);
|
|
787
|
+
var buffer = newBuffer(bufferSize);
|
|
788
|
+
var bufferReadStart = totalSize - buffer.length;
|
|
789
|
+
readAndAssertNoEof(reader, buffer, 0, bufferSize, bufferReadStart, function(err) {
|
|
790
|
+
if (err) return callback(err);
|
|
791
|
+
for (var i = bufferSize - eocdrWithoutCommentSize; i >= 0; i -= 1) {
|
|
792
|
+
if (buffer.readUInt32LE(i) !== 101010256) continue;
|
|
793
|
+
var eocdrBuffer = buffer.subarray(i);
|
|
794
|
+
var diskNumber = eocdrBuffer.readUInt16LE(4);
|
|
795
|
+
var entryCount = eocdrBuffer.readUInt16LE(10);
|
|
796
|
+
var centralDirectoryOffset = eocdrBuffer.readUInt32LE(16);
|
|
797
|
+
var commentLength = eocdrBuffer.readUInt16LE(20);
|
|
798
|
+
var expectedCommentLength = eocdrBuffer.length - eocdrWithoutCommentSize;
|
|
799
|
+
if (commentLength !== expectedCommentLength) {
|
|
800
|
+
return callback(new Error("Invalid comment length. Expected: " + expectedCommentLength + ". Found: " + commentLength + ". Are there extra bytes at the end of the file? Or is the end of central dir signature `PK\u263A\u263B` in the comment?"));
|
|
801
|
+
}
|
|
802
|
+
var comment = decodeStrings ? decodeBuffer(eocdrBuffer.subarray(22), false) : eocdrBuffer.subarray(22);
|
|
803
|
+
if (i - zip64EocdlSize >= 0 && buffer.readUInt32LE(i - zip64EocdlSize) === 117853008) {
|
|
804
|
+
var zip64EocdlBuffer = buffer.subarray(i - zip64EocdlSize, i - zip64EocdlSize + zip64EocdlSize);
|
|
805
|
+
var zip64EocdrOffset = readUInt64LE(zip64EocdlBuffer, 8);
|
|
806
|
+
var zip64EocdrBuffer = newBuffer(56);
|
|
807
|
+
return readAndAssertNoEof(reader, zip64EocdrBuffer, 0, zip64EocdrBuffer.length, zip64EocdrOffset, function(err2) {
|
|
808
|
+
if (err2) return callback(err2);
|
|
809
|
+
if (zip64EocdrBuffer.readUInt32LE(0) !== 101075792) {
|
|
810
|
+
return callback(new Error("invalid zip64 end of central directory record signature"));
|
|
811
|
+
}
|
|
812
|
+
diskNumber = zip64EocdrBuffer.readUInt32LE(16);
|
|
813
|
+
if (diskNumber !== 0) {
|
|
814
|
+
return callback(new Error("multi-disk zip files are not supported: found disk number: " + diskNumber));
|
|
815
|
+
}
|
|
816
|
+
entryCount = readUInt64LE(zip64EocdrBuffer, 32);
|
|
817
|
+
centralDirectoryOffset = readUInt64LE(zip64EocdrBuffer, 48);
|
|
818
|
+
return callback(null, new ZipFile(reader, centralDirectoryOffset, totalSize, entryCount, comment, options2.autoClose, options2.lazyEntries, decodeStrings, options2.validateEntrySizes, options2.strictFileNames));
|
|
819
|
+
});
|
|
820
|
+
}
|
|
821
|
+
if (diskNumber !== 0) {
|
|
822
|
+
return callback(new Error("multi-disk zip files are not supported: found disk number: " + diskNumber));
|
|
823
|
+
}
|
|
824
|
+
return callback(null, new ZipFile(reader, centralDirectoryOffset, totalSize, entryCount, comment, options2.autoClose, options2.lazyEntries, decodeStrings, options2.validateEntrySizes, options2.strictFileNames));
|
|
825
|
+
}
|
|
826
|
+
callback(new Error("End of central directory record signature not found. Either not a zip file, or file is truncated."));
|
|
827
|
+
});
|
|
828
|
+
}
|
|
829
|
+
util.inherits(ZipFile, EventEmitter);
|
|
830
|
+
function ZipFile(reader, centralDirectoryOffset, fileSize, entryCount, comment, autoClose, lazyEntries, decodeStrings, validateEntrySizes, strictFileNames) {
|
|
831
|
+
var self = this;
|
|
832
|
+
EventEmitter.call(self);
|
|
833
|
+
self.reader = reader;
|
|
834
|
+
self.reader.on("error", function(err) {
|
|
835
|
+
emitError(self, err);
|
|
836
|
+
});
|
|
837
|
+
self.reader.once("close", function() {
|
|
838
|
+
self.emit("close");
|
|
839
|
+
});
|
|
840
|
+
self.readEntryCursor = centralDirectoryOffset;
|
|
841
|
+
self.fileSize = fileSize;
|
|
842
|
+
self.entryCount = entryCount;
|
|
843
|
+
self.comment = comment;
|
|
844
|
+
self.entriesRead = 0;
|
|
845
|
+
self.autoClose = !!autoClose;
|
|
846
|
+
self.lazyEntries = !!lazyEntries;
|
|
847
|
+
self.decodeStrings = !!decodeStrings;
|
|
848
|
+
self.validateEntrySizes = !!validateEntrySizes;
|
|
849
|
+
self.strictFileNames = !!strictFileNames;
|
|
850
|
+
self.isOpen = true;
|
|
851
|
+
self.emittedError = false;
|
|
852
|
+
if (!self.lazyEntries) self._readEntry();
|
|
853
|
+
}
|
|
854
|
+
ZipFile.prototype.close = function() {
|
|
855
|
+
if (!this.isOpen) return;
|
|
856
|
+
this.isOpen = false;
|
|
857
|
+
this.reader.unref();
|
|
858
|
+
};
|
|
859
|
+
function emitErrorAndAutoClose(self, err) {
|
|
860
|
+
if (self.autoClose) self.close();
|
|
861
|
+
emitError(self, err);
|
|
862
|
+
}
|
|
863
|
+
function emitError(self, err) {
|
|
864
|
+
if (self.emittedError) return;
|
|
865
|
+
self.emittedError = true;
|
|
866
|
+
self.emit("error", err);
|
|
867
|
+
}
|
|
868
|
+
ZipFile.prototype.readEntry = function() {
|
|
869
|
+
if (!this.lazyEntries) throw new Error("readEntry() called without lazyEntries:true");
|
|
870
|
+
this._readEntry();
|
|
871
|
+
};
|
|
872
|
+
ZipFile.prototype._readEntry = function() {
|
|
873
|
+
var self = this;
|
|
874
|
+
if (self.entryCount === self.entriesRead) {
|
|
875
|
+
setImmediate(function() {
|
|
876
|
+
if (self.autoClose) self.close();
|
|
877
|
+
if (self.emittedError) return;
|
|
878
|
+
self.emit("end");
|
|
879
|
+
});
|
|
880
|
+
return;
|
|
881
|
+
}
|
|
882
|
+
if (self.emittedError) return;
|
|
883
|
+
var buffer = newBuffer(46);
|
|
884
|
+
readAndAssertNoEof(self.reader, buffer, 0, buffer.length, self.readEntryCursor, function(err) {
|
|
885
|
+
if (err) return emitErrorAndAutoClose(self, err);
|
|
886
|
+
if (self.emittedError) return;
|
|
887
|
+
var entry = new Entry();
|
|
888
|
+
var signature = buffer.readUInt32LE(0);
|
|
889
|
+
if (signature !== 33639248) return emitErrorAndAutoClose(self, new Error("invalid central directory file header signature: 0x" + signature.toString(16)));
|
|
890
|
+
entry.versionMadeBy = buffer.readUInt16LE(4);
|
|
891
|
+
entry.versionNeededToExtract = buffer.readUInt16LE(6);
|
|
892
|
+
entry.generalPurposeBitFlag = buffer.readUInt16LE(8);
|
|
893
|
+
entry.compressionMethod = buffer.readUInt16LE(10);
|
|
894
|
+
entry.lastModFileTime = buffer.readUInt16LE(12);
|
|
895
|
+
entry.lastModFileDate = buffer.readUInt16LE(14);
|
|
896
|
+
entry.crc32 = buffer.readUInt32LE(16);
|
|
897
|
+
entry.compressedSize = buffer.readUInt32LE(20);
|
|
898
|
+
entry.uncompressedSize = buffer.readUInt32LE(24);
|
|
899
|
+
entry.fileNameLength = buffer.readUInt16LE(28);
|
|
900
|
+
entry.extraFieldLength = buffer.readUInt16LE(30);
|
|
901
|
+
entry.fileCommentLength = buffer.readUInt16LE(32);
|
|
902
|
+
entry.internalFileAttributes = buffer.readUInt16LE(36);
|
|
903
|
+
entry.externalFileAttributes = buffer.readUInt32LE(38);
|
|
904
|
+
entry.relativeOffsetOfLocalHeader = buffer.readUInt32LE(42);
|
|
905
|
+
if (entry.generalPurposeBitFlag & 64) return emitErrorAndAutoClose(self, new Error("strong encryption is not supported"));
|
|
906
|
+
self.readEntryCursor += 46;
|
|
907
|
+
buffer = newBuffer(entry.fileNameLength + entry.extraFieldLength + entry.fileCommentLength);
|
|
908
|
+
readAndAssertNoEof(self.reader, buffer, 0, buffer.length, self.readEntryCursor, function(err2) {
|
|
909
|
+
if (err2) return emitErrorAndAutoClose(self, err2);
|
|
910
|
+
if (self.emittedError) return;
|
|
911
|
+
entry.fileNameRaw = buffer.subarray(0, entry.fileNameLength);
|
|
912
|
+
var fileCommentStart = entry.fileNameLength + entry.extraFieldLength;
|
|
913
|
+
entry.extraFieldRaw = buffer.subarray(entry.fileNameLength, fileCommentStart);
|
|
914
|
+
entry.fileCommentRaw = buffer.subarray(fileCommentStart, fileCommentStart + entry.fileCommentLength);
|
|
915
|
+
try {
|
|
916
|
+
entry.extraFields = parseExtraFields(entry.extraFieldRaw);
|
|
917
|
+
} catch (err3) {
|
|
918
|
+
return emitErrorAndAutoClose(self, err3);
|
|
919
|
+
}
|
|
920
|
+
if (self.decodeStrings) {
|
|
921
|
+
var isUtf8 = (entry.generalPurposeBitFlag & 2048) !== 0;
|
|
922
|
+
entry.fileComment = decodeBuffer(entry.fileCommentRaw, isUtf8);
|
|
923
|
+
entry.fileName = getFileNameLowLevel(entry.generalPurposeBitFlag, entry.fileNameRaw, entry.extraFields, self.strictFileNames);
|
|
924
|
+
var errorMessage = validateFileName(entry.fileName);
|
|
925
|
+
if (errorMessage != null) return emitErrorAndAutoClose(self, new Error(errorMessage));
|
|
926
|
+
} else {
|
|
927
|
+
entry.fileComment = entry.fileCommentRaw;
|
|
928
|
+
entry.fileName = entry.fileNameRaw;
|
|
929
|
+
}
|
|
930
|
+
entry.comment = entry.fileComment;
|
|
931
|
+
self.readEntryCursor += buffer.length;
|
|
932
|
+
self.entriesRead += 1;
|
|
933
|
+
for (var i = 0; i < entry.extraFields.length; i++) {
|
|
934
|
+
var extraField = entry.extraFields[i];
|
|
935
|
+
if (extraField.id !== 1) continue;
|
|
936
|
+
var zip64EiefBuffer = extraField.data;
|
|
937
|
+
var index = 0;
|
|
938
|
+
if (entry.uncompressedSize === 4294967295) {
|
|
939
|
+
if (index + 8 > zip64EiefBuffer.length) {
|
|
940
|
+
return emitErrorAndAutoClose(self, new Error("zip64 extended information extra field does not include uncompressed size"));
|
|
941
|
+
}
|
|
942
|
+
entry.uncompressedSize = readUInt64LE(zip64EiefBuffer, index);
|
|
943
|
+
index += 8;
|
|
944
|
+
}
|
|
945
|
+
if (entry.compressedSize === 4294967295) {
|
|
946
|
+
if (index + 8 > zip64EiefBuffer.length) {
|
|
947
|
+
return emitErrorAndAutoClose(self, new Error("zip64 extended information extra field does not include compressed size"));
|
|
948
|
+
}
|
|
949
|
+
entry.compressedSize = readUInt64LE(zip64EiefBuffer, index);
|
|
950
|
+
index += 8;
|
|
951
|
+
}
|
|
952
|
+
if (entry.relativeOffsetOfLocalHeader === 4294967295) {
|
|
953
|
+
if (index + 8 > zip64EiefBuffer.length) {
|
|
954
|
+
return emitErrorAndAutoClose(self, new Error("zip64 extended information extra field does not include relative header offset"));
|
|
955
|
+
}
|
|
956
|
+
entry.relativeOffsetOfLocalHeader = readUInt64LE(zip64EiefBuffer, index);
|
|
957
|
+
index += 8;
|
|
958
|
+
}
|
|
959
|
+
break;
|
|
960
|
+
}
|
|
961
|
+
if (self.validateEntrySizes && entry.compressionMethod === 0) {
|
|
962
|
+
var expectedCompressedSize = entry.uncompressedSize;
|
|
963
|
+
if (entry.isEncrypted()) {
|
|
964
|
+
expectedCompressedSize += 12;
|
|
965
|
+
}
|
|
966
|
+
if (entry.compressedSize !== expectedCompressedSize) {
|
|
967
|
+
var msg = "compressed/uncompressed size mismatch for stored file: " + entry.compressedSize + " != " + entry.uncompressedSize;
|
|
968
|
+
return emitErrorAndAutoClose(self, new Error(msg));
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
self.emit("entry", entry);
|
|
972
|
+
if (!self.lazyEntries) self._readEntry();
|
|
973
|
+
});
|
|
974
|
+
});
|
|
975
|
+
};
|
|
976
|
+
ZipFile.prototype.openReadStream = function(entry, options2, callback) {
|
|
977
|
+
var self = this;
|
|
978
|
+
var relativeStart = 0;
|
|
979
|
+
var relativeEnd = entry.compressedSize;
|
|
980
|
+
if (callback == null) {
|
|
981
|
+
callback = options2;
|
|
982
|
+
options2 = null;
|
|
983
|
+
}
|
|
984
|
+
if (options2 == null) {
|
|
985
|
+
options2 = {};
|
|
986
|
+
} else {
|
|
987
|
+
if (options2.decrypt != null) {
|
|
988
|
+
if (!entry.isEncrypted()) {
|
|
989
|
+
throw new Error("options.decrypt can only be specified for encrypted entries");
|
|
990
|
+
}
|
|
991
|
+
if (options2.decrypt !== false) throw new Error("invalid options.decrypt value: " + options2.decrypt);
|
|
992
|
+
if (entry.isCompressed()) {
|
|
993
|
+
if (options2.decompress !== false) throw new Error("entry is encrypted and compressed, and options.decompress !== false");
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
if (options2.decompress != null) {
|
|
997
|
+
if (!entry.isCompressed()) {
|
|
998
|
+
throw new Error("options.decompress can only be specified for compressed entries");
|
|
999
|
+
}
|
|
1000
|
+
if (!(options2.decompress === false || options2.decompress === true)) {
|
|
1001
|
+
throw new Error("invalid options.decompress value: " + options2.decompress);
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
if (options2.start != null || options2.end != null) {
|
|
1005
|
+
if (entry.isCompressed() && options2.decompress !== false) {
|
|
1006
|
+
throw new Error("start/end range not allowed for compressed entry without options.decompress === false");
|
|
1007
|
+
}
|
|
1008
|
+
if (entry.isEncrypted() && options2.decrypt !== false) {
|
|
1009
|
+
throw new Error("start/end range not allowed for encrypted entry without options.decrypt === false");
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
if (options2.start != null) {
|
|
1013
|
+
relativeStart = options2.start;
|
|
1014
|
+
if (relativeStart < 0) throw new Error("options.start < 0");
|
|
1015
|
+
if (relativeStart > entry.compressedSize) throw new Error("options.start > entry.compressedSize");
|
|
1016
|
+
}
|
|
1017
|
+
if (options2.end != null) {
|
|
1018
|
+
relativeEnd = options2.end;
|
|
1019
|
+
if (relativeEnd < 0) throw new Error("options.end < 0");
|
|
1020
|
+
if (relativeEnd > entry.compressedSize) throw new Error("options.end > entry.compressedSize");
|
|
1021
|
+
if (relativeEnd < relativeStart) throw new Error("options.end < options.start");
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
if (!self.isOpen) return callback(new Error("closed"));
|
|
1025
|
+
if (entry.isEncrypted()) {
|
|
1026
|
+
if (options2.decrypt !== false) return callback(new Error("entry is encrypted, and options.decrypt !== false"));
|
|
1027
|
+
}
|
|
1028
|
+
var decompress;
|
|
1029
|
+
if (entry.compressionMethod === 0) {
|
|
1030
|
+
decompress = false;
|
|
1031
|
+
} else if (entry.compressionMethod === 8) {
|
|
1032
|
+
decompress = options2.decompress != null ? options2.decompress : true;
|
|
1033
|
+
} else {
|
|
1034
|
+
return callback(new Error("unsupported compression method: " + entry.compressionMethod));
|
|
1035
|
+
}
|
|
1036
|
+
self.readLocalFileHeader(entry, { minimal: true }, function(err, localFileHeader) {
|
|
1037
|
+
if (err) return callback(err);
|
|
1038
|
+
self.openReadStreamLowLevel(
|
|
1039
|
+
localFileHeader.fileDataStart,
|
|
1040
|
+
entry.compressedSize,
|
|
1041
|
+
relativeStart,
|
|
1042
|
+
relativeEnd,
|
|
1043
|
+
decompress,
|
|
1044
|
+
entry.uncompressedSize,
|
|
1045
|
+
callback
|
|
1046
|
+
);
|
|
1047
|
+
});
|
|
1048
|
+
};
|
|
1049
|
+
ZipFile.prototype.openReadStreamLowLevel = function(fileDataStart, compressedSize, relativeStart, relativeEnd, decompress, uncompressedSize, callback) {
|
|
1050
|
+
var self = this;
|
|
1051
|
+
var fileDataEnd = fileDataStart + compressedSize;
|
|
1052
|
+
var readStream = self.reader.createReadStream({
|
|
1053
|
+
start: fileDataStart + relativeStart,
|
|
1054
|
+
end: fileDataStart + relativeEnd
|
|
1055
|
+
});
|
|
1056
|
+
var endpointStream = readStream;
|
|
1057
|
+
if (decompress) {
|
|
1058
|
+
var destroyed = false;
|
|
1059
|
+
var inflateFilter = zlib.createInflateRaw();
|
|
1060
|
+
readStream.on("error", function(err) {
|
|
1061
|
+
setImmediate(function() {
|
|
1062
|
+
if (!destroyed) inflateFilter.emit("error", err);
|
|
1063
|
+
});
|
|
1064
|
+
});
|
|
1065
|
+
readStream.pipe(inflateFilter);
|
|
1066
|
+
if (self.validateEntrySizes) {
|
|
1067
|
+
endpointStream = new AssertByteCountStream(uncompressedSize);
|
|
1068
|
+
inflateFilter.on("error", function(err) {
|
|
1069
|
+
setImmediate(function() {
|
|
1070
|
+
if (!destroyed) endpointStream.emit("error", err);
|
|
1071
|
+
});
|
|
1072
|
+
});
|
|
1073
|
+
inflateFilter.pipe(endpointStream);
|
|
1074
|
+
} else {
|
|
1075
|
+
endpointStream = inflateFilter;
|
|
1076
|
+
}
|
|
1077
|
+
installDestroyFn(endpointStream, function() {
|
|
1078
|
+
destroyed = true;
|
|
1079
|
+
if (inflateFilter !== endpointStream) inflateFilter.unpipe(endpointStream);
|
|
1080
|
+
readStream.unpipe(inflateFilter);
|
|
1081
|
+
readStream.destroy();
|
|
1082
|
+
});
|
|
1083
|
+
}
|
|
1084
|
+
callback(null, endpointStream);
|
|
1085
|
+
};
|
|
1086
|
+
ZipFile.prototype.readLocalFileHeader = function(entry, options2, callback) {
|
|
1087
|
+
var self = this;
|
|
1088
|
+
if (callback == null) {
|
|
1089
|
+
callback = options2;
|
|
1090
|
+
options2 = null;
|
|
1091
|
+
}
|
|
1092
|
+
if (options2 == null) options2 = {};
|
|
1093
|
+
self.reader.ref();
|
|
1094
|
+
var buffer = newBuffer(30);
|
|
1095
|
+
readAndAssertNoEof(self.reader, buffer, 0, buffer.length, entry.relativeOffsetOfLocalHeader, function(err) {
|
|
1096
|
+
try {
|
|
1097
|
+
if (err) return callback(err);
|
|
1098
|
+
var signature = buffer.readUInt32LE(0);
|
|
1099
|
+
if (signature !== 67324752) {
|
|
1100
|
+
return callback(new Error("invalid local file header signature: 0x" + signature.toString(16)));
|
|
1101
|
+
}
|
|
1102
|
+
var fileNameLength = buffer.readUInt16LE(26);
|
|
1103
|
+
var extraFieldLength = buffer.readUInt16LE(28);
|
|
1104
|
+
var fileDataStart = entry.relativeOffsetOfLocalHeader + 30 + fileNameLength + extraFieldLength;
|
|
1105
|
+
if (fileDataStart + entry.compressedSize > self.fileSize) {
|
|
1106
|
+
return callback(new Error("file data overflows file bounds: " + fileDataStart + " + " + entry.compressedSize + " > " + self.fileSize));
|
|
1107
|
+
}
|
|
1108
|
+
if (options2.minimal) {
|
|
1109
|
+
return callback(null, { fileDataStart });
|
|
1110
|
+
}
|
|
1111
|
+
var localFileHeader = new LocalFileHeader();
|
|
1112
|
+
localFileHeader.fileDataStart = fileDataStart;
|
|
1113
|
+
localFileHeader.versionNeededToExtract = buffer.readUInt16LE(4);
|
|
1114
|
+
localFileHeader.generalPurposeBitFlag = buffer.readUInt16LE(6);
|
|
1115
|
+
localFileHeader.compressionMethod = buffer.readUInt16LE(8);
|
|
1116
|
+
localFileHeader.lastModFileTime = buffer.readUInt16LE(10);
|
|
1117
|
+
localFileHeader.lastModFileDate = buffer.readUInt16LE(12);
|
|
1118
|
+
localFileHeader.crc32 = buffer.readUInt32LE(14);
|
|
1119
|
+
localFileHeader.compressedSize = buffer.readUInt32LE(18);
|
|
1120
|
+
localFileHeader.uncompressedSize = buffer.readUInt32LE(22);
|
|
1121
|
+
localFileHeader.fileNameLength = fileNameLength;
|
|
1122
|
+
localFileHeader.extraFieldLength = extraFieldLength;
|
|
1123
|
+
buffer = newBuffer(fileNameLength + extraFieldLength);
|
|
1124
|
+
self.reader.ref();
|
|
1125
|
+
readAndAssertNoEof(self.reader, buffer, 0, buffer.length, entry.relativeOffsetOfLocalHeader + 30, function(err2) {
|
|
1126
|
+
try {
|
|
1127
|
+
if (err2) return callback(err2);
|
|
1128
|
+
localFileHeader.fileName = buffer.subarray(0, fileNameLength);
|
|
1129
|
+
localFileHeader.extraField = buffer.subarray(fileNameLength);
|
|
1130
|
+
return callback(null, localFileHeader);
|
|
1131
|
+
} finally {
|
|
1132
|
+
self.reader.unref();
|
|
1133
|
+
}
|
|
1134
|
+
});
|
|
1135
|
+
} finally {
|
|
1136
|
+
self.reader.unref();
|
|
1137
|
+
}
|
|
1138
|
+
});
|
|
1139
|
+
};
|
|
1140
|
+
function Entry() {
|
|
1141
|
+
}
|
|
1142
|
+
Entry.prototype.getLastModDate = function(options2) {
|
|
1143
|
+
if (options2 == null) options2 = {};
|
|
1144
|
+
if (!options2.forceDosFormat) {
|
|
1145
|
+
for (var i = 0; i < this.extraFields.length; i++) {
|
|
1146
|
+
var extraField = this.extraFields[i];
|
|
1147
|
+
if (extraField.id === 21589) {
|
|
1148
|
+
var data = extraField.data;
|
|
1149
|
+
if (data.length < 5) continue;
|
|
1150
|
+
var flags = data[0];
|
|
1151
|
+
var HAS_MTIME = 1;
|
|
1152
|
+
if (!(flags & HAS_MTIME)) continue;
|
|
1153
|
+
var posixTimestamp = data.readInt32LE(1);
|
|
1154
|
+
return new Date(posixTimestamp * 1e3);
|
|
1155
|
+
} else if (extraField.id === 10) {
|
|
1156
|
+
var data = extraField.data;
|
|
1157
|
+
var cursor = 4;
|
|
1158
|
+
while (cursor < data.length + 4) {
|
|
1159
|
+
var tag = data.readUInt16LE(cursor);
|
|
1160
|
+
cursor += 2;
|
|
1161
|
+
var size = data.readUInt16LE(cursor);
|
|
1162
|
+
cursor += 2;
|
|
1163
|
+
if (tag !== 1) {
|
|
1164
|
+
cursor += size;
|
|
1165
|
+
continue;
|
|
1166
|
+
}
|
|
1167
|
+
if (size < 8 || cursor + size > data.length) break;
|
|
1168
|
+
var hundredNanoSecondsSince1601 = 4294967296 * data.readInt32LE(cursor + 4) + data.readUInt32LE(cursor);
|
|
1169
|
+
var millisecondsSince1970 = hundredNanoSecondsSince1601 / 1e4 - 116444736e5;
|
|
1170
|
+
return new Date(millisecondsSince1970);
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
return dosDateTimeToDate(this.lastModFileDate, this.lastModFileTime, options2.timezone);
|
|
1176
|
+
};
|
|
1177
|
+
Entry.prototype.isEncrypted = function() {
|
|
1178
|
+
return (this.generalPurposeBitFlag & 1) !== 0;
|
|
1179
|
+
};
|
|
1180
|
+
Entry.prototype.isCompressed = function() {
|
|
1181
|
+
return this.compressionMethod === 8;
|
|
1182
|
+
};
|
|
1183
|
+
function LocalFileHeader() {
|
|
1184
|
+
}
|
|
1185
|
+
function dosDateTimeToDate(date, time, timezone) {
|
|
1186
|
+
var day = date & 31;
|
|
1187
|
+
var month = (date >> 5 & 15) - 1;
|
|
1188
|
+
var year = (date >> 9 & 127) + 1980;
|
|
1189
|
+
var millisecond = 0;
|
|
1190
|
+
var second = (time & 31) * 2;
|
|
1191
|
+
var minute = time >> 5 & 63;
|
|
1192
|
+
var hour = time >> 11 & 31;
|
|
1193
|
+
if (timezone == null || timezone === "local") {
|
|
1194
|
+
return new Date(year, month, day, hour, minute, second, millisecond);
|
|
1195
|
+
} else if (timezone === "UTC") {
|
|
1196
|
+
return new Date(Date.UTC(year, month, day, hour, minute, second, millisecond));
|
|
1197
|
+
} else {
|
|
1198
|
+
throw new Error("unrecognized options.timezone: " + options.timezone);
|
|
1199
|
+
}
|
|
1200
|
+
}
|
|
1201
|
+
function getFileNameLowLevel(generalPurposeBitFlag, fileNameBuffer, extraFields, strictFileNames) {
|
|
1202
|
+
var fileName = null;
|
|
1203
|
+
for (var i = 0; i < extraFields.length; i++) {
|
|
1204
|
+
var extraField = extraFields[i];
|
|
1205
|
+
if (extraField.id === 28789) {
|
|
1206
|
+
if (extraField.data.length < 6) {
|
|
1207
|
+
continue;
|
|
1208
|
+
}
|
|
1209
|
+
if (extraField.data.readUInt8(0) !== 1) {
|
|
1210
|
+
continue;
|
|
1211
|
+
}
|
|
1212
|
+
var oldNameCrc32 = extraField.data.readUInt32LE(1);
|
|
1213
|
+
if (crc32.unsigned(fileNameBuffer) !== oldNameCrc32) {
|
|
1214
|
+
continue;
|
|
1215
|
+
}
|
|
1216
|
+
fileName = decodeBuffer(extraField.data.subarray(5), true);
|
|
1217
|
+
break;
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
if (fileName == null) {
|
|
1221
|
+
var isUtf8 = (generalPurposeBitFlag & 2048) !== 0;
|
|
1222
|
+
fileName = decodeBuffer(fileNameBuffer, isUtf8);
|
|
1223
|
+
}
|
|
1224
|
+
if (!strictFileNames) {
|
|
1225
|
+
fileName = fileName.replace(/\\/g, "/");
|
|
1226
|
+
}
|
|
1227
|
+
return fileName;
|
|
1228
|
+
}
|
|
1229
|
+
function validateFileName(fileName) {
|
|
1230
|
+
if (fileName.indexOf("\\") !== -1) {
|
|
1231
|
+
return "invalid characters in fileName: " + fileName;
|
|
1232
|
+
}
|
|
1233
|
+
if (/^[a-zA-Z]:/.test(fileName) || /^\//.test(fileName)) {
|
|
1234
|
+
return "absolute path: " + fileName;
|
|
1235
|
+
}
|
|
1236
|
+
if (fileName.split("/").indexOf("..") !== -1) {
|
|
1237
|
+
return "invalid relative path: " + fileName;
|
|
1238
|
+
}
|
|
1239
|
+
return null;
|
|
1240
|
+
}
|
|
1241
|
+
function parseExtraFields(extraFieldBuffer) {
|
|
1242
|
+
var extraFields = [];
|
|
1243
|
+
var i = 0;
|
|
1244
|
+
while (i < extraFieldBuffer.length - 3) {
|
|
1245
|
+
var headerId = extraFieldBuffer.readUInt16LE(i + 0);
|
|
1246
|
+
var dataSize = extraFieldBuffer.readUInt16LE(i + 2);
|
|
1247
|
+
var dataStart = i + 4;
|
|
1248
|
+
var dataEnd = dataStart + dataSize;
|
|
1249
|
+
if (dataEnd > extraFieldBuffer.length) throw new Error("extra field length exceeds extra field buffer size");
|
|
1250
|
+
var dataBuffer = extraFieldBuffer.subarray(dataStart, dataEnd);
|
|
1251
|
+
extraFields.push({
|
|
1252
|
+
id: headerId,
|
|
1253
|
+
data: dataBuffer
|
|
1254
|
+
});
|
|
1255
|
+
i = dataEnd;
|
|
1256
|
+
}
|
|
1257
|
+
return extraFields;
|
|
1258
|
+
}
|
|
1259
|
+
function readAndAssertNoEof(reader, buffer, offset, length, position, callback) {
|
|
1260
|
+
if (length === 0) {
|
|
1261
|
+
return setImmediate(function() {
|
|
1262
|
+
callback(null, newBuffer(0));
|
|
1263
|
+
});
|
|
1264
|
+
}
|
|
1265
|
+
reader.read(buffer, offset, length, position, function(err, bytesRead) {
|
|
1266
|
+
if (err) return callback(err);
|
|
1267
|
+
if (bytesRead < length) {
|
|
1268
|
+
return callback(new Error("unexpected EOF"));
|
|
1269
|
+
}
|
|
1270
|
+
callback();
|
|
1271
|
+
});
|
|
1272
|
+
}
|
|
1273
|
+
util.inherits(AssertByteCountStream, Transform);
|
|
1274
|
+
function AssertByteCountStream(byteCount) {
|
|
1275
|
+
Transform.call(this);
|
|
1276
|
+
this.actualByteCount = 0;
|
|
1277
|
+
this.expectedByteCount = byteCount;
|
|
1278
|
+
}
|
|
1279
|
+
AssertByteCountStream.prototype._transform = function(chunk, encoding, cb) {
|
|
1280
|
+
this.actualByteCount += chunk.length;
|
|
1281
|
+
if (this.actualByteCount > this.expectedByteCount) {
|
|
1282
|
+
var msg = "too many bytes in the stream. expected " + this.expectedByteCount + ". got at least " + this.actualByteCount;
|
|
1283
|
+
return cb(new Error(msg));
|
|
1284
|
+
}
|
|
1285
|
+
cb(null, chunk);
|
|
1286
|
+
};
|
|
1287
|
+
AssertByteCountStream.prototype._flush = function(cb) {
|
|
1288
|
+
if (this.actualByteCount < this.expectedByteCount) {
|
|
1289
|
+
var msg = "not enough bytes in the stream. expected " + this.expectedByteCount + ". got only " + this.actualByteCount;
|
|
1290
|
+
return cb(new Error(msg));
|
|
1291
|
+
}
|
|
1292
|
+
cb();
|
|
1293
|
+
};
|
|
1294
|
+
util.inherits(RandomAccessReader, EventEmitter);
|
|
1295
|
+
function RandomAccessReader() {
|
|
1296
|
+
EventEmitter.call(this);
|
|
1297
|
+
this.refCount = 0;
|
|
1298
|
+
}
|
|
1299
|
+
RandomAccessReader.prototype.ref = function() {
|
|
1300
|
+
this.refCount += 1;
|
|
1301
|
+
};
|
|
1302
|
+
RandomAccessReader.prototype.unref = function() {
|
|
1303
|
+
var self = this;
|
|
1304
|
+
self.refCount -= 1;
|
|
1305
|
+
if (self.refCount > 0) return;
|
|
1306
|
+
if (self.refCount < 0) throw new Error("invalid unref");
|
|
1307
|
+
self.close(onCloseDone);
|
|
1308
|
+
function onCloseDone(err) {
|
|
1309
|
+
if (err) return self.emit("error", err);
|
|
1310
|
+
self.emit("close");
|
|
1311
|
+
}
|
|
1312
|
+
};
|
|
1313
|
+
RandomAccessReader.prototype.createReadStream = function(options2) {
|
|
1314
|
+
if (options2 == null) options2 = {};
|
|
1315
|
+
var start = options2.start;
|
|
1316
|
+
var end = options2.end;
|
|
1317
|
+
if (start === end) {
|
|
1318
|
+
var emptyStream = new PassThrough();
|
|
1319
|
+
setImmediate(function() {
|
|
1320
|
+
emptyStream.end();
|
|
1321
|
+
});
|
|
1322
|
+
return emptyStream;
|
|
1323
|
+
}
|
|
1324
|
+
var stream = this._readStreamForRange(start, end);
|
|
1325
|
+
var destroyed = false;
|
|
1326
|
+
var refUnrefFilter = new RefUnrefFilter(this);
|
|
1327
|
+
stream.on("error", function(err) {
|
|
1328
|
+
setImmediate(function() {
|
|
1329
|
+
if (!destroyed) refUnrefFilter.emit("error", err);
|
|
1330
|
+
});
|
|
1331
|
+
});
|
|
1332
|
+
installDestroyFn(refUnrefFilter, function() {
|
|
1333
|
+
stream.unpipe(refUnrefFilter);
|
|
1334
|
+
refUnrefFilter.unref();
|
|
1335
|
+
stream.destroy();
|
|
1336
|
+
});
|
|
1337
|
+
var byteCounter = new AssertByteCountStream(end - start);
|
|
1338
|
+
refUnrefFilter.on("error", function(err) {
|
|
1339
|
+
setImmediate(function() {
|
|
1340
|
+
if (!destroyed) byteCounter.emit("error", err);
|
|
1341
|
+
});
|
|
1342
|
+
});
|
|
1343
|
+
installDestroyFn(byteCounter, function() {
|
|
1344
|
+
destroyed = true;
|
|
1345
|
+
refUnrefFilter.unpipe(byteCounter);
|
|
1346
|
+
refUnrefFilter.destroy();
|
|
1347
|
+
});
|
|
1348
|
+
return stream.pipe(refUnrefFilter).pipe(byteCounter);
|
|
1349
|
+
};
|
|
1350
|
+
RandomAccessReader.prototype._readStreamForRange = function(start, end) {
|
|
1351
|
+
throw new Error("not implemented");
|
|
1352
|
+
};
|
|
1353
|
+
RandomAccessReader.prototype.read = function(buffer, offset, length, position, callback) {
|
|
1354
|
+
var readStream = this.createReadStream({ start: position, end: position + length });
|
|
1355
|
+
var writeStream = new Writable();
|
|
1356
|
+
var written = 0;
|
|
1357
|
+
writeStream._write = function(chunk, encoding, cb) {
|
|
1358
|
+
chunk.copy(buffer, offset + written, 0, chunk.length);
|
|
1359
|
+
written += chunk.length;
|
|
1360
|
+
cb();
|
|
1361
|
+
};
|
|
1362
|
+
writeStream.on("finish", callback);
|
|
1363
|
+
readStream.on("error", function(error) {
|
|
1364
|
+
callback(error);
|
|
1365
|
+
});
|
|
1366
|
+
readStream.pipe(writeStream);
|
|
1367
|
+
};
|
|
1368
|
+
RandomAccessReader.prototype.close = function(callback) {
|
|
1369
|
+
setImmediate(callback);
|
|
1370
|
+
};
|
|
1371
|
+
util.inherits(RefUnrefFilter, PassThrough);
|
|
1372
|
+
function RefUnrefFilter(context) {
|
|
1373
|
+
PassThrough.call(this);
|
|
1374
|
+
this.context = context;
|
|
1375
|
+
this.context.ref();
|
|
1376
|
+
this.unreffedYet = false;
|
|
1377
|
+
}
|
|
1378
|
+
RefUnrefFilter.prototype._flush = function(cb) {
|
|
1379
|
+
this.unref();
|
|
1380
|
+
cb();
|
|
1381
|
+
};
|
|
1382
|
+
RefUnrefFilter.prototype.unref = function(cb) {
|
|
1383
|
+
if (this.unreffedYet) return;
|
|
1384
|
+
this.unreffedYet = true;
|
|
1385
|
+
this.context.unref();
|
|
1386
|
+
};
|
|
1387
|
+
var cp437 = "\0\u263A\u263B\u2665\u2666\u2663\u2660\u2022\u25D8\u25CB\u25D9\u2642\u2640\u266A\u266B\u263C\u25BA\u25C4\u2195\u203C\xB6\xA7\u25AC\u21A8\u2191\u2193\u2192\u2190\u221F\u2194\u25B2\u25BC !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\u2302\xC7\xFC\xE9\xE2\xE4\xE0\xE5\xE7\xEA\xEB\xE8\xEF\xEE\xEC\xC4\xC5\xC9\xE6\xC6\xF4\xF6\xF2\xFB\xF9\xFF\xD6\xDC\xA2\xA3\xA5\u20A7\u0192\xE1\xED\xF3\xFA\xF1\xD1\xAA\xBA\xBF\u2310\xAC\xBD\xBC\xA1\xAB\xBB\u2591\u2592\u2593\u2502\u2524\u2561\u2562\u2556\u2555\u2563\u2551\u2557\u255D\u255C\u255B\u2510\u2514\u2534\u252C\u251C\u2500\u253C\u255E\u255F\u255A\u2554\u2569\u2566\u2560\u2550\u256C\u2567\u2568\u2564\u2565\u2559\u2558\u2552\u2553\u256B\u256A\u2518\u250C\u2588\u2584\u258C\u2590\u2580\u03B1\xDF\u0393\u03C0\u03A3\u03C3\xB5\u03C4\u03A6\u0398\u03A9\u03B4\u221E\u03C6\u03B5\u2229\u2261\xB1\u2265\u2264\u2320\u2321\xF7\u2248\xB0\u2219\xB7\u221A\u207F\xB2\u25A0\xA0";
|
|
1388
|
+
function decodeBuffer(buffer, isUtf8) {
|
|
1389
|
+
if (isUtf8) {
|
|
1390
|
+
return buffer.toString("utf8");
|
|
1391
|
+
} else {
|
|
1392
|
+
var result = "";
|
|
1393
|
+
for (var i = 0; i < buffer.length; i++) {
|
|
1394
|
+
result += cp437[buffer[i]];
|
|
1395
|
+
}
|
|
1396
|
+
return result;
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1399
|
+
function readUInt64LE(buffer, offset) {
|
|
1400
|
+
var lower32 = buffer.readUInt32LE(offset);
|
|
1401
|
+
var upper32 = buffer.readUInt32LE(offset + 4);
|
|
1402
|
+
return upper32 * 4294967296 + lower32;
|
|
1403
|
+
}
|
|
1404
|
+
var newBuffer;
|
|
1405
|
+
if (typeof Buffer.allocUnsafe === "function") {
|
|
1406
|
+
newBuffer = function(len) {
|
|
1407
|
+
return Buffer.allocUnsafe(len);
|
|
1408
|
+
};
|
|
1409
|
+
} else {
|
|
1410
|
+
newBuffer = function(len) {
|
|
1411
|
+
return new Buffer(len);
|
|
1412
|
+
};
|
|
1413
|
+
}
|
|
1414
|
+
function installDestroyFn(stream, fn) {
|
|
1415
|
+
if (typeof stream.destroy === "function") {
|
|
1416
|
+
stream._destroy = function(err, cb) {
|
|
1417
|
+
fn();
|
|
1418
|
+
if (cb != null) cb(err);
|
|
1419
|
+
};
|
|
1420
|
+
} else {
|
|
1421
|
+
stream.destroy = fn;
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1424
|
+
function defaultCallback(err) {
|
|
1425
|
+
if (err) throw err;
|
|
1426
|
+
}
|
|
1427
|
+
}
|
|
1428
|
+
});
|
|
1429
|
+
|
|
1430
|
+
// src/index.ts
|
|
1431
|
+
init_esm_shims();
|
|
1432
|
+
|
|
1433
|
+
// src/react-native-cdn.ts
|
|
1434
|
+
init_esm_shims();
|
|
1435
|
+
import fs2 from "fs";
|
|
1436
|
+
import path3 from "path";
|
|
1437
|
+
|
|
1438
|
+
// ../../packages/utils/dist/index.js
|
|
1439
|
+
init_esm_shims();
|
|
1440
|
+
var import_yauzl = __toESM(require_yauzl(), 1);
|
|
1441
|
+
import fs from "fs";
|
|
1442
|
+
import path2 from "path";
|
|
1443
|
+
function getPackageRoot() {
|
|
1444
|
+
let cwd = process.cwd();
|
|
1445
|
+
const root = path2.parse(cwd).root;
|
|
1446
|
+
while (cwd !== root) {
|
|
1447
|
+
if (fs.existsSync(path2.join(cwd, "package.json"))) {
|
|
1448
|
+
return cwd;
|
|
1449
|
+
}
|
|
1450
|
+
cwd = path2.dirname(cwd);
|
|
1451
|
+
}
|
|
1452
|
+
return cwd;
|
|
1453
|
+
}
|
|
1454
|
+
|
|
1455
|
+
// src/react-native-cdn.ts
|
|
1456
|
+
import * as aws from "@pulumi/aws";
|
|
1457
|
+
import * as pulumi from "@pulumi/pulumi";
|
|
1458
|
+
import { transform } from "oxc-transform";
|
|
1459
|
+
|
|
1460
|
+
// ../../.yarn/cache/uuid-npm-11.1.0-61d0d08928-34aa51b987.zip/node_modules/uuid/dist/esm/index.js
|
|
1461
|
+
init_esm_shims();
|
|
1462
|
+
|
|
1463
|
+
// ../../.yarn/cache/uuid-npm-11.1.0-61d0d08928-34aa51b987.zip/node_modules/uuid/dist/esm/stringify.js
|
|
1464
|
+
init_esm_shims();
|
|
1465
|
+
var byteToHex = [];
|
|
1466
|
+
for (let i = 0; i < 256; ++i) {
|
|
1467
|
+
byteToHex.push((i + 256).toString(16).slice(1));
|
|
1468
|
+
}
|
|
1469
|
+
function unsafeStringify(arr, offset = 0) {
|
|
1470
|
+
return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
|
|
1471
|
+
}
|
|
1472
|
+
|
|
1473
|
+
// ../../.yarn/cache/uuid-npm-11.1.0-61d0d08928-34aa51b987.zip/node_modules/uuid/dist/esm/rng.js
|
|
1474
|
+
init_esm_shims();
|
|
1475
|
+
import { randomFillSync } from "crypto";
|
|
1476
|
+
var rnds8Pool = new Uint8Array(256);
|
|
1477
|
+
var poolPtr = rnds8Pool.length;
|
|
1478
|
+
function rng() {
|
|
1479
|
+
if (poolPtr > rnds8Pool.length - 16) {
|
|
1480
|
+
randomFillSync(rnds8Pool);
|
|
1481
|
+
poolPtr = 0;
|
|
1482
|
+
}
|
|
1483
|
+
return rnds8Pool.slice(poolPtr, poolPtr += 16);
|
|
1484
|
+
}
|
|
1485
|
+
|
|
1486
|
+
// ../../.yarn/cache/uuid-npm-11.1.0-61d0d08928-34aa51b987.zip/node_modules/uuid/dist/esm/v7.js
|
|
1487
|
+
init_esm_shims();
|
|
1488
|
+
var _state = {};
|
|
1489
|
+
function v7(options2, buf, offset) {
|
|
1490
|
+
let bytes;
|
|
1491
|
+
if (options2) {
|
|
1492
|
+
bytes = v7Bytes(options2.random ?? options2.rng?.() ?? rng(), options2.msecs, options2.seq, buf, offset);
|
|
1493
|
+
} else {
|
|
1494
|
+
const now = Date.now();
|
|
1495
|
+
const rnds = rng();
|
|
1496
|
+
updateV7State(_state, now, rnds);
|
|
1497
|
+
bytes = v7Bytes(rnds, _state.msecs, _state.seq, buf, offset);
|
|
1498
|
+
}
|
|
1499
|
+
return buf ?? unsafeStringify(bytes);
|
|
1500
|
+
}
|
|
1501
|
+
function updateV7State(state, now, rnds) {
|
|
1502
|
+
state.msecs ??= -Infinity;
|
|
1503
|
+
state.seq ??= 0;
|
|
1504
|
+
if (now > state.msecs) {
|
|
1505
|
+
state.seq = rnds[6] << 23 | rnds[7] << 16 | rnds[8] << 8 | rnds[9];
|
|
1506
|
+
state.msecs = now;
|
|
1507
|
+
} else {
|
|
1508
|
+
state.seq = state.seq + 1 | 0;
|
|
1509
|
+
if (state.seq === 0) {
|
|
1510
|
+
state.msecs++;
|
|
1511
|
+
}
|
|
1512
|
+
}
|
|
1513
|
+
return state;
|
|
1514
|
+
}
|
|
1515
|
+
function v7Bytes(rnds, msecs, seq, buf, offset = 0) {
|
|
1516
|
+
if (rnds.length < 16) {
|
|
1517
|
+
throw new Error("Random bytes length must be >= 16");
|
|
1518
|
+
}
|
|
1519
|
+
if (!buf) {
|
|
1520
|
+
buf = new Uint8Array(16);
|
|
1521
|
+
offset = 0;
|
|
1522
|
+
} else {
|
|
1523
|
+
if (offset < 0 || offset + 16 > buf.length) {
|
|
1524
|
+
throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
|
|
1525
|
+
}
|
|
1526
|
+
}
|
|
1527
|
+
msecs ??= Date.now();
|
|
1528
|
+
seq ??= rnds[6] * 127 << 24 | rnds[7] << 16 | rnds[8] << 8 | rnds[9];
|
|
1529
|
+
buf[offset++] = msecs / 1099511627776 & 255;
|
|
1530
|
+
buf[offset++] = msecs / 4294967296 & 255;
|
|
1531
|
+
buf[offset++] = msecs / 16777216 & 255;
|
|
1532
|
+
buf[offset++] = msecs / 65536 & 255;
|
|
1533
|
+
buf[offset++] = msecs / 256 & 255;
|
|
1534
|
+
buf[offset++] = msecs & 255;
|
|
1535
|
+
buf[offset++] = 112 | seq >>> 28 & 15;
|
|
1536
|
+
buf[offset++] = seq >>> 20 & 255;
|
|
1537
|
+
buf[offset++] = 128 | seq >>> 14 & 63;
|
|
1538
|
+
buf[offset++] = seq >>> 6 & 255;
|
|
1539
|
+
buf[offset++] = seq << 2 & 255 | rnds[10] & 3;
|
|
1540
|
+
buf[offset++] = rnds[11];
|
|
1541
|
+
buf[offset++] = rnds[12];
|
|
1542
|
+
buf[offset++] = rnds[13];
|
|
1543
|
+
buf[offset++] = rnds[14];
|
|
1544
|
+
buf[offset++] = rnds[15];
|
|
1545
|
+
return buf;
|
|
1546
|
+
}
|
|
1547
|
+
var v7_default = v7;
|
|
1548
|
+
|
|
1549
|
+
// src/utils/getTimestampByUUIDv7.ts
|
|
1550
|
+
init_esm_shims();
|
|
1551
|
+
function getTimestampByUUIDv7(uuid) {
|
|
1552
|
+
const timestampHex = uuid.split("-").join("").slice(0, 12);
|
|
1553
|
+
const timestamp = Number.parseInt(timestampHex, 16);
|
|
1554
|
+
return timestamp;
|
|
1555
|
+
}
|
|
1556
|
+
function toDeployedAtString(date) {
|
|
1557
|
+
return [
|
|
1558
|
+
date.getFullYear(),
|
|
1559
|
+
(date.getMonth() + 1).toString().padStart(2, "0"),
|
|
1560
|
+
date.getDate().toString().padStart(2, "0"),
|
|
1561
|
+
date.getHours().toString().padStart(2, "0"),
|
|
1562
|
+
date.getMinutes().toString().padStart(2, "0")
|
|
1563
|
+
].join("");
|
|
1564
|
+
}
|
|
1565
|
+
|
|
1566
|
+
// src/react-native-cdn.ts
|
|
1567
|
+
var createLambdaCode = (path4, {
|
|
1568
|
+
bucketName,
|
|
1569
|
+
region
|
|
1570
|
+
}) => {
|
|
1571
|
+
const code = fs2.readFileSync(path4, "utf8");
|
|
1572
|
+
const { code: transformedCode } = transform(path4, code, {
|
|
1573
|
+
define: {
|
|
1574
|
+
_BUCKET_NAME: JSON.stringify(bucketName),
|
|
1575
|
+
_BUCKET_REGION: JSON.stringify(region)
|
|
1576
|
+
}
|
|
1577
|
+
});
|
|
1578
|
+
return new pulumi.asset.AssetArchive({
|
|
1579
|
+
"index.js": new pulumi.asset.StringAsset(transformedCode)
|
|
1580
|
+
});
|
|
1581
|
+
};
|
|
1582
|
+
var ReactNativeBundleCDN = class extends pulumi.ComponentResource {
|
|
1583
|
+
cloudfrontDistributionId;
|
|
1584
|
+
cloudfrontOriginAccessIdentityArn;
|
|
1585
|
+
bucketName;
|
|
1586
|
+
bucketEndpoint;
|
|
1587
|
+
cloudfrontDomain;
|
|
1588
|
+
monitoringSubscriptionId;
|
|
1589
|
+
sharedDeploymentId;
|
|
1590
|
+
constructor(name, args, opts) {
|
|
1591
|
+
super("granite:aws:ReactNativeBundleCDN", name, {}, opts);
|
|
1592
|
+
const { bucketName, region } = args;
|
|
1593
|
+
const resourceName = bucketName;
|
|
1594
|
+
const awsProvider = new aws.Provider(
|
|
1595
|
+
"awsProvider",
|
|
1596
|
+
{
|
|
1597
|
+
region
|
|
1598
|
+
},
|
|
1599
|
+
{ parent: this }
|
|
1600
|
+
);
|
|
1601
|
+
const usEast1Provider = new aws.Provider(
|
|
1602
|
+
"usEast1Provider",
|
|
1603
|
+
{
|
|
1604
|
+
region: "us-east-1"
|
|
1605
|
+
},
|
|
1606
|
+
{ parent: this }
|
|
1607
|
+
);
|
|
1608
|
+
const bucket = new aws.s3.Bucket(
|
|
1609
|
+
"bucket",
|
|
1610
|
+
{
|
|
1611
|
+
bucket: resourceName,
|
|
1612
|
+
acl: "private",
|
|
1613
|
+
versioning: {
|
|
1614
|
+
enabled: true
|
|
1615
|
+
},
|
|
1616
|
+
website: {
|
|
1617
|
+
indexDocument: "index.html",
|
|
1618
|
+
errorDocument: "error.html"
|
|
1619
|
+
},
|
|
1620
|
+
corsRules: [
|
|
1621
|
+
{
|
|
1622
|
+
allowedHeaders: ["*"],
|
|
1623
|
+
allowedMethods: ["GET"],
|
|
1624
|
+
allowedOrigins: ["*"],
|
|
1625
|
+
maxAgeSeconds: 3e3
|
|
1626
|
+
}
|
|
1627
|
+
]
|
|
1628
|
+
},
|
|
1629
|
+
{ provider: awsProvider, parent: this }
|
|
1630
|
+
);
|
|
1631
|
+
const deploymentId = v7_default();
|
|
1632
|
+
const deployedAt = getTimestampByUUIDv7(deploymentId);
|
|
1633
|
+
const bundlePath = path3.join(__dirname, "prebuilt-shared");
|
|
1634
|
+
const packageRoot = getPackageRoot();
|
|
1635
|
+
const granitePath = path3.join(packageRoot, ".granite");
|
|
1636
|
+
const prebuiltSharedPath = path3.join(granitePath, "prebuilt-shared");
|
|
1637
|
+
fs2.mkdirSync(prebuiltSharedPath, { recursive: true });
|
|
1638
|
+
const files = fs2.readdirSync(bundlePath);
|
|
1639
|
+
for (const file of files) {
|
|
1640
|
+
const sourcePath = path3.join(bundlePath, file);
|
|
1641
|
+
const destPath = path3.join(prebuiltSharedPath, file);
|
|
1642
|
+
fs2.copyFileSync(sourcePath, destPath);
|
|
1643
|
+
}
|
|
1644
|
+
const bundleIos = new aws.s3.BucketObjectv2("bundle.ios.hbc.gz", {
|
|
1645
|
+
bucket: bucket.id,
|
|
1646
|
+
key: `bundles/shared/${deploymentId}/bundle.ios.hbc.gz`,
|
|
1647
|
+
source: new pulumi.asset.FileAsset(path3.join(prebuiltSharedPath, "bundle.ios.hbc.gz")),
|
|
1648
|
+
contentType: "application/gzip",
|
|
1649
|
+
cacheControl: "s-maxage=31536000, max-age=0",
|
|
1650
|
+
contentEncoding: "gzip",
|
|
1651
|
+
metadata: {
|
|
1652
|
+
"x-deployment-id": deploymentId,
|
|
1653
|
+
"x-deployment-deployed-at": toDeployedAtString(new Date(deployedAt))
|
|
1654
|
+
}
|
|
1655
|
+
});
|
|
1656
|
+
const bundleAndroid = new aws.s3.BucketObjectv2("bundle.android.hbc.gz", {
|
|
1657
|
+
bucket: bucket.id,
|
|
1658
|
+
key: `bundles/shared/${deploymentId}/bundle.android.hbc.gz`,
|
|
1659
|
+
source: new pulumi.asset.FileAsset(path3.join(prebuiltSharedPath, "bundle.android.hbc.gz")),
|
|
1660
|
+
contentType: "application/gzip",
|
|
1661
|
+
cacheControl: "s-maxage=31536000, max-age=0",
|
|
1662
|
+
contentEncoding: "gzip",
|
|
1663
|
+
metadata: {
|
|
1664
|
+
"x-deployment-id": deploymentId,
|
|
1665
|
+
"x-deployment-deployed-at": toDeployedAtString(new Date(deployedAt))
|
|
1666
|
+
}
|
|
1667
|
+
});
|
|
1668
|
+
const deploymentState = new aws.s3.BucketObjectv2("deployment_state", {
|
|
1669
|
+
bucket: bucket.id,
|
|
1670
|
+
key: "deployments/shared/deployment_state",
|
|
1671
|
+
contentType: "application/json",
|
|
1672
|
+
source: new pulumi.asset.StringAsset(
|
|
1673
|
+
JSON.stringify({
|
|
1674
|
+
type: "STABLE",
|
|
1675
|
+
deploymentId
|
|
1676
|
+
})
|
|
1677
|
+
)
|
|
1678
|
+
});
|
|
1679
|
+
const deployments = new aws.s3.BucketObjectv2("DEPLOYMENTS", {
|
|
1680
|
+
bucket: bucket.id,
|
|
1681
|
+
key: "deployments/shared/DEPLOYMENTS",
|
|
1682
|
+
contentType: "application/json",
|
|
1683
|
+
source: new pulumi.asset.StringAsset(
|
|
1684
|
+
JSON.stringify([
|
|
1685
|
+
{
|
|
1686
|
+
deploymentId,
|
|
1687
|
+
deployedAt
|
|
1688
|
+
}
|
|
1689
|
+
])
|
|
1690
|
+
)
|
|
1691
|
+
});
|
|
1692
|
+
const cacheInvalidationRole = new aws.iam.Role(
|
|
1693
|
+
"cacheInvalidationRole",
|
|
1694
|
+
{
|
|
1695
|
+
name: `${resourceName}_cache_invalidation_role`,
|
|
1696
|
+
assumeRolePolicy: aws.iam.assumeRolePolicyForPrincipal({
|
|
1697
|
+
Service: "lambda.amazonaws.com"
|
|
1698
|
+
})
|
|
1699
|
+
},
|
|
1700
|
+
{ provider: awsProvider, parent: this }
|
|
1701
|
+
);
|
|
1702
|
+
const cacheInvalidationPolicy = new aws.iam.RolePolicy(
|
|
1703
|
+
"cacheInvalidationPolicy",
|
|
1704
|
+
{
|
|
1705
|
+
name: `${resourceName}_cache_invalidation_policy`,
|
|
1706
|
+
role: cacheInvalidationRole.id,
|
|
1707
|
+
policy: JSON.stringify({
|
|
1708
|
+
Version: "2012-10-17",
|
|
1709
|
+
Statement: [
|
|
1710
|
+
{
|
|
1711
|
+
Effect: "Allow",
|
|
1712
|
+
Action: [
|
|
1713
|
+
"cloudfront:CreateInvalidation",
|
|
1714
|
+
"s3:GetObject",
|
|
1715
|
+
"s3:ListBucket",
|
|
1716
|
+
"logs:CreateLogGroup",
|
|
1717
|
+
"logs:CreateLogStream",
|
|
1718
|
+
"logs:PutLogEvents"
|
|
1719
|
+
],
|
|
1720
|
+
Resource: "*"
|
|
1721
|
+
}
|
|
1722
|
+
]
|
|
1723
|
+
})
|
|
1724
|
+
},
|
|
1725
|
+
{ provider: awsProvider, parent: this }
|
|
1726
|
+
);
|
|
1727
|
+
const originAccessIdentity = new aws.cloudfront.OriginAccessIdentity(
|
|
1728
|
+
"originAccessIdentity",
|
|
1729
|
+
{
|
|
1730
|
+
comment: resourceName
|
|
1731
|
+
},
|
|
1732
|
+
{ provider: usEast1Provider, parent: this }
|
|
1733
|
+
);
|
|
1734
|
+
new aws.s3.BucketPolicy(
|
|
1735
|
+
"bucketPolicy",
|
|
1736
|
+
{
|
|
1737
|
+
bucket: bucket.id,
|
|
1738
|
+
policy: pulumi.all([bucket.arn, originAccessIdentity.iamArn]).apply(
|
|
1739
|
+
([bucketArn, oaiArn]) => JSON.stringify({
|
|
1740
|
+
Version: "2012-10-17",
|
|
1741
|
+
Statement: [
|
|
1742
|
+
{
|
|
1743
|
+
Sid: "AllowCloudFrontOAI",
|
|
1744
|
+
Effect: "Allow",
|
|
1745
|
+
Principal: {
|
|
1746
|
+
AWS: oaiArn
|
|
1747
|
+
},
|
|
1748
|
+
Action: "s3:GetObject",
|
|
1749
|
+
Resource: `${bucketArn}/*`
|
|
1750
|
+
},
|
|
1751
|
+
{
|
|
1752
|
+
Sid: "AllowCloudFrontListBucket",
|
|
1753
|
+
Effect: "Allow",
|
|
1754
|
+
Principal: {
|
|
1755
|
+
AWS: oaiArn
|
|
1756
|
+
},
|
|
1757
|
+
Action: "s3:ListBucket",
|
|
1758
|
+
Resource: bucketArn
|
|
1759
|
+
}
|
|
1760
|
+
]
|
|
1761
|
+
})
|
|
1762
|
+
)
|
|
1763
|
+
},
|
|
1764
|
+
{ provider: awsProvider, parent: this }
|
|
1765
|
+
);
|
|
1766
|
+
const lambdaAtEdgeAssumeRolePolicy = aws.iam.getPolicyDocumentOutput({
|
|
1767
|
+
statements: [
|
|
1768
|
+
{
|
|
1769
|
+
effect: "Allow",
|
|
1770
|
+
principals: [
|
|
1771
|
+
{
|
|
1772
|
+
type: "Service",
|
|
1773
|
+
identifiers: ["lambda.amazonaws.com", "edgelambda.amazonaws.com"]
|
|
1774
|
+
}
|
|
1775
|
+
],
|
|
1776
|
+
actions: ["sts:AssumeRole"]
|
|
1777
|
+
}
|
|
1778
|
+
]
|
|
1779
|
+
});
|
|
1780
|
+
const lambdaAtEdgeRole = new aws.iam.Role(
|
|
1781
|
+
"lambdaAtEdgeRole",
|
|
1782
|
+
{
|
|
1783
|
+
name: `${resourceName}_lambda_role`,
|
|
1784
|
+
assumeRolePolicy: lambdaAtEdgeAssumeRolePolicy.json
|
|
1785
|
+
},
|
|
1786
|
+
{ provider: usEast1Provider, parent: this }
|
|
1787
|
+
);
|
|
1788
|
+
const lambdaAtEdgePolicy = aws.iam.getPolicyDocumentOutput({
|
|
1789
|
+
statements: [
|
|
1790
|
+
{
|
|
1791
|
+
effect: "Allow",
|
|
1792
|
+
actions: [
|
|
1793
|
+
"iam:CreateServiceLinkedRole",
|
|
1794
|
+
"lambda:GetFunction",
|
|
1795
|
+
"lambda:EnableReplication",
|
|
1796
|
+
"cloudfront:UpdateDistribution",
|
|
1797
|
+
"s3:GetObject",
|
|
1798
|
+
"s3:ListBucket",
|
|
1799
|
+
"logs:CreateLogGroup",
|
|
1800
|
+
"logs:CreateLogStream",
|
|
1801
|
+
"logs:PutLogEvents",
|
|
1802
|
+
"logs:DescribeLogStreams"
|
|
1803
|
+
],
|
|
1804
|
+
resources: ["*"]
|
|
1805
|
+
}
|
|
1806
|
+
]
|
|
1807
|
+
});
|
|
1808
|
+
const lambdaAtEdgeRolePolicy = new aws.iam.RolePolicy(
|
|
1809
|
+
"lambdaAtEdgeRolePolicy",
|
|
1810
|
+
{
|
|
1811
|
+
name: `${resourceName}_lambda_role_policy`,
|
|
1812
|
+
role: lambdaAtEdgeRole.id,
|
|
1813
|
+
policy: lambdaAtEdgePolicy.json
|
|
1814
|
+
},
|
|
1815
|
+
{ provider: usEast1Provider, parent: this }
|
|
1816
|
+
);
|
|
1817
|
+
const originRequestPath = __require.resolve("@granite-js/pulumi-aws/lambda/origin-request");
|
|
1818
|
+
const originResponsePath = __require.resolve("@granite-js/pulumi-aws/lambda/origin-response");
|
|
1819
|
+
const autoCacheRemovalPath = __require.resolve("@granite-js/pulumi-aws/lambda/auto-cache-removal");
|
|
1820
|
+
const originRequestHandler = new aws.lambda.Function(
|
|
1821
|
+
"originRequestHandler",
|
|
1822
|
+
{
|
|
1823
|
+
publish: true,
|
|
1824
|
+
code: createLambdaCode(originRequestPath, {
|
|
1825
|
+
bucketName,
|
|
1826
|
+
region
|
|
1827
|
+
}),
|
|
1828
|
+
description: "Lambda@Edge function for serving React Native bundles from S3",
|
|
1829
|
+
name: `fe_edge_origin_request_${resourceName}`,
|
|
1830
|
+
handler: "index.handler",
|
|
1831
|
+
role: lambdaAtEdgeRole.arn,
|
|
1832
|
+
runtime: "nodejs22.x",
|
|
1833
|
+
timeout: 5
|
|
1834
|
+
},
|
|
1835
|
+
{
|
|
1836
|
+
provider: usEast1Provider,
|
|
1837
|
+
parent: this,
|
|
1838
|
+
dependsOn: [lambdaAtEdgeRolePolicy]
|
|
1839
|
+
}
|
|
1840
|
+
);
|
|
1841
|
+
const originResponseHandler = new aws.lambda.Function(
|
|
1842
|
+
"originResponseHandler",
|
|
1843
|
+
{
|
|
1844
|
+
publish: true,
|
|
1845
|
+
code: createLambdaCode(originResponsePath, {
|
|
1846
|
+
bucketName,
|
|
1847
|
+
region
|
|
1848
|
+
}),
|
|
1849
|
+
description: "Lambda@Edge function for serving React Native bundles from S3",
|
|
1850
|
+
name: `fe_edge_origin_response_${resourceName}`,
|
|
1851
|
+
handler: "index.handler",
|
|
1852
|
+
role: lambdaAtEdgeRole.arn,
|
|
1853
|
+
runtime: "nodejs22.x",
|
|
1854
|
+
timeout: 5
|
|
1855
|
+
},
|
|
1856
|
+
{
|
|
1857
|
+
provider: usEast1Provider,
|
|
1858
|
+
parent: this,
|
|
1859
|
+
dependsOn: [lambdaAtEdgeRolePolicy]
|
|
1860
|
+
}
|
|
1861
|
+
);
|
|
1862
|
+
const cloudfrontDistribution = new aws.cloudfront.Distribution(
|
|
1863
|
+
"cloudfrontDistribution",
|
|
1864
|
+
{
|
|
1865
|
+
comment: resourceName,
|
|
1866
|
+
enabled: true,
|
|
1867
|
+
httpVersion: "http2and3",
|
|
1868
|
+
origins: [
|
|
1869
|
+
{
|
|
1870
|
+
domainName: bucket.bucketRegionalDomainName,
|
|
1871
|
+
originId: bucket.id,
|
|
1872
|
+
s3OriginConfig: {
|
|
1873
|
+
originAccessIdentity: originAccessIdentity.cloudfrontAccessIdentityPath
|
|
1874
|
+
}
|
|
1875
|
+
}
|
|
1876
|
+
],
|
|
1877
|
+
restrictions: {
|
|
1878
|
+
geoRestriction: {
|
|
1879
|
+
restrictionType: "none"
|
|
1880
|
+
}
|
|
1881
|
+
},
|
|
1882
|
+
defaultCacheBehavior: {
|
|
1883
|
+
allowedMethods: ["GET", "HEAD", "OPTIONS"],
|
|
1884
|
+
cachedMethods: ["GET", "HEAD"],
|
|
1885
|
+
compress: true,
|
|
1886
|
+
defaultTtl: 0,
|
|
1887
|
+
maxTtl: 31536e3,
|
|
1888
|
+
minTtl: 0,
|
|
1889
|
+
targetOriginId: bucket.id,
|
|
1890
|
+
viewerProtocolPolicy: "allow-all",
|
|
1891
|
+
forwardedValues: {
|
|
1892
|
+
queryString: true,
|
|
1893
|
+
headers: ["Accept-Encoding"],
|
|
1894
|
+
cookies: {
|
|
1895
|
+
forward: "none"
|
|
1896
|
+
}
|
|
1897
|
+
},
|
|
1898
|
+
lambdaFunctionAssociations: [
|
|
1899
|
+
{
|
|
1900
|
+
eventType: "origin-request",
|
|
1901
|
+
lambdaArn: originRequestHandler.qualifiedArn
|
|
1902
|
+
},
|
|
1903
|
+
{
|
|
1904
|
+
eventType: "origin-response",
|
|
1905
|
+
lambdaArn: originResponseHandler.qualifiedArn
|
|
1906
|
+
}
|
|
1907
|
+
]
|
|
1908
|
+
},
|
|
1909
|
+
viewerCertificate: {
|
|
1910
|
+
cloudfrontDefaultCertificate: true
|
|
1911
|
+
}
|
|
1912
|
+
},
|
|
1913
|
+
{ provider: usEast1Provider, parent: this }
|
|
1914
|
+
);
|
|
1915
|
+
const monitoringSubscription = new aws.cloudfront.MonitoringSubscription(
|
|
1916
|
+
"monitoringSubscription",
|
|
1917
|
+
{
|
|
1918
|
+
distributionId: cloudfrontDistribution.id,
|
|
1919
|
+
monitoringSubscription: {
|
|
1920
|
+
realtimeMetricsSubscriptionConfig: {
|
|
1921
|
+
realtimeMetricsSubscriptionStatus: "Enabled"
|
|
1922
|
+
}
|
|
1923
|
+
}
|
|
1924
|
+
},
|
|
1925
|
+
{ provider: usEast1Provider, parent: this }
|
|
1926
|
+
);
|
|
1927
|
+
const cacheInvalidationLambda = new aws.lambda.Function(
|
|
1928
|
+
"cacheInvalidationLambda",
|
|
1929
|
+
{
|
|
1930
|
+
name: `${resourceName}_cache_invalidation`,
|
|
1931
|
+
code: createLambdaCode(autoCacheRemovalPath, {
|
|
1932
|
+
bucketName,
|
|
1933
|
+
region
|
|
1934
|
+
}),
|
|
1935
|
+
description: "Lambda function that invalidates CloudFront cache based on S3 events",
|
|
1936
|
+
handler: "index.handler",
|
|
1937
|
+
role: cacheInvalidationRole.arn,
|
|
1938
|
+
runtime: "nodejs22.x",
|
|
1939
|
+
timeout: 30,
|
|
1940
|
+
environment: {
|
|
1941
|
+
variables: {
|
|
1942
|
+
// CloudFront distribution ID is needed for the lambda to know which distribution to invalidate
|
|
1943
|
+
// We will use a dependency to ensure this is available
|
|
1944
|
+
CLOUDFRONT_DISTRIBUTION_ID: pulumi.interpolate`${cloudfrontDistribution.id}`
|
|
1945
|
+
}
|
|
1946
|
+
}
|
|
1947
|
+
},
|
|
1948
|
+
{
|
|
1949
|
+
provider: awsProvider,
|
|
1950
|
+
parent: this,
|
|
1951
|
+
dependsOn: [cacheInvalidationPolicy]
|
|
1952
|
+
}
|
|
1953
|
+
);
|
|
1954
|
+
const lambdaPermission = new aws.lambda.Permission(
|
|
1955
|
+
"lambdaPermission",
|
|
1956
|
+
{
|
|
1957
|
+
action: "lambda:InvokeFunction",
|
|
1958
|
+
function: cacheInvalidationLambda.name,
|
|
1959
|
+
principal: "s3.amazonaws.com",
|
|
1960
|
+
sourceArn: bucket.arn
|
|
1961
|
+
},
|
|
1962
|
+
{ provider: awsProvider, parent: this }
|
|
1963
|
+
);
|
|
1964
|
+
new aws.s3.BucketNotification(
|
|
1965
|
+
"bucketNotification",
|
|
1966
|
+
{
|
|
1967
|
+
bucket: bucket.id,
|
|
1968
|
+
lambdaFunctions: [
|
|
1969
|
+
{
|
|
1970
|
+
lambdaFunctionArn: cacheInvalidationLambda.arn,
|
|
1971
|
+
events: ["s3:ObjectCreated:*", "s3:ObjectRemoved:*"],
|
|
1972
|
+
filterPrefix: "deployments/"
|
|
1973
|
+
// Only trigger for objects in deployments/ folder
|
|
1974
|
+
}
|
|
1975
|
+
]
|
|
1976
|
+
},
|
|
1977
|
+
{
|
|
1978
|
+
provider: awsProvider,
|
|
1979
|
+
parent: this,
|
|
1980
|
+
dependsOn: [lambdaPermission, cacheInvalidationLambda]
|
|
1981
|
+
}
|
|
1982
|
+
);
|
|
1983
|
+
pulumi.all([bundleIos.id, bundleAndroid.id, deploymentState.id, deployments.id]).apply(() => {
|
|
1984
|
+
fs2.rmSync(granitePath, { recursive: true, force: true });
|
|
1985
|
+
return null;
|
|
1986
|
+
});
|
|
1987
|
+
this.cloudfrontDistributionId = cloudfrontDistribution.id;
|
|
1988
|
+
this.cloudfrontOriginAccessIdentityArn = originAccessIdentity.iamArn;
|
|
1989
|
+
this.bucketName = bucket.bucket;
|
|
1990
|
+
this.bucketEndpoint = bucket.websiteEndpoint;
|
|
1991
|
+
this.cloudfrontDomain = cloudfrontDistribution.domainName;
|
|
1992
|
+
this.monitoringSubscriptionId = monitoringSubscription.id;
|
|
1993
|
+
this.sharedDeploymentId = pulumi.output(deploymentId);
|
|
1994
|
+
this.registerOutputs({
|
|
1995
|
+
sharedDeploymentId: this.sharedDeploymentId,
|
|
1996
|
+
cloudfrontDistributionId: this.cloudfrontDistributionId,
|
|
1997
|
+
cloudfrontOriginAccessIdentityArn: this.cloudfrontOriginAccessIdentityArn,
|
|
1998
|
+
bucketName: this.bucketName,
|
|
1999
|
+
bucketEndpoint: this.bucketEndpoint,
|
|
2000
|
+
cloudfrontDomain: this.cloudfrontDomain,
|
|
2001
|
+
monitoringSubscriptionId: this.monitoringSubscriptionId
|
|
2002
|
+
});
|
|
2003
|
+
}
|
|
2004
|
+
};
|
|
2005
|
+
export {
|
|
2006
|
+
ReactNativeBundleCDN
|
|
2007
|
+
};
|