Merge branch 'v3.0-do-not-zip' into v3.0

This commit is contained in:
Alexander Cerutti
2021-10-16 00:26:05 +02:00
5 changed files with 313 additions and 53 deletions

314
package-lock.json generated
View File

@@ -1,8 +1,284 @@
{ {
"name": "passkit-generator", "name": "passkit-generator",
"version": "2.0.8", "version": "2.0.8",
"lockfileVersion": 1, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": {
"": {
"name": "passkit-generator",
"version": "2.0.8",
"license": "MIT",
"dependencies": {
"do-not-zip": "^1.0.0",
"joi": "^17.4.2",
"node-forge": "^0.10.0",
"tslib": "^2.3.1"
},
"devDependencies": {
"@types/do-not-zip": "^1.0.0",
"@types/jasmine": "^3.9.1",
"@types/node": "^16.10.8",
"@types/node-forge": "^0.10.8",
"jasmine": "^3.9.0",
"prettier": "^2.4.1",
"rimraf": "^3.0.2",
"typescript": "^4.4.4"
},
"engines": {
"node": ">=14.18.1"
}
},
"node_modules/@hapi/hoek": {
"version": "9.1.1",
"resolved": "https://registry.npmjs.org/@hapi/hoek/-/hoek-9.1.1.tgz",
"integrity": "sha512-CAEbWH7OIur6jEOzaai83jq3FmKmv4PmX1JYfs9IrYcGEVI/lyL1EXJGCj7eFVJ0bg5QR8LMxBlEtA+xKiLpFw=="
},
"node_modules/@hapi/topo": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/@hapi/topo/-/topo-5.0.0.tgz",
"integrity": "sha512-tFJlT47db0kMqVm3H4nQYgn6Pwg10GTZHb1pwmSiv1K4ks6drQOtfEF5ZnPjkvC+y4/bUPHK+bc87QvLcL+WMw==",
"dependencies": {
"@hapi/hoek": "^9.0.0"
}
},
"node_modules/@sideway/address": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/@sideway/address/-/address-4.1.0.tgz",
"integrity": "sha512-wAH/JYRXeIFQRsxerIuLjgUu2Xszam+O5xKeatJ4oudShOOirfmsQ1D6LL54XOU2tizpCYku+s1wmU0SYdpoSA==",
"dependencies": {
"@hapi/hoek": "^9.0.0"
}
},
"node_modules/@sideway/formula": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/@sideway/formula/-/formula-3.0.0.tgz",
"integrity": "sha512-vHe7wZ4NOXVfkoRb8T5otiENVlT7a3IAiw7H5M2+GO+9CDgcVUUsX1zalAztCmwyOr2RUTGJdgB+ZvSVqmdHmg=="
},
"node_modules/@sideway/pinpoint": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/@sideway/pinpoint/-/pinpoint-2.0.0.tgz",
"integrity": "sha512-RNiOoTPkptFtSVzQevY/yWtZwf/RxyVnPy/OcA9HBM3MlGDnBEYL5B41H0MTn0Uec8Hi+2qUtTfG2WWZBmMejQ=="
},
"node_modules/@types/do-not-zip": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/@types/do-not-zip/-/do-not-zip-1.0.0.tgz",
"integrity": "sha512-A/itOzxvHqp0dGAhbhDLm62Wmx0W6c9eYvKkb8VijDBnSoC9u0e8GwouyIxluFCJELOilTe48oCzeTrQK1kkjg==",
"dev": true,
"dependencies": {
"@types/node": "*"
}
},
"node_modules/@types/jasmine": {
"version": "3.9.1",
"resolved": "https://registry.npmjs.org/@types/jasmine/-/jasmine-3.9.1.tgz",
"integrity": "sha512-PVpjh8S8lqKFKurWSKdFATlfBHGPzgy0PoDdzQ+rr78jTQ0aacyh9YndzZcAUPxhk4kRujItFFGQdUJ7flHumw==",
"dev": true
},
"node_modules/@types/node": {
"version": "16.10.8",
"resolved": "https://registry.npmjs.org/@types/node/-/node-16.10.8.tgz",
"integrity": "sha512-atlRPM4gM/BABQ2MiXm38veMVL+kz6vFAj1hvqC1wDxWNrnr3t58PozLSecgLBrKNGISunQl2SxxIJcYV3tO2w==",
"dev": true
},
"node_modules/@types/node-forge": {
"version": "0.10.8",
"resolved": "https://registry.npmjs.org/@types/node-forge/-/node-forge-0.10.8.tgz",
"integrity": "sha512-pS02y9i4oqhyijveLYrgb7C/tQVHxyaFg7cxZITHO4C9oHU5gjIvtCnZXQNP6K7adXl4VtxCnijnKeuWqT++nA==",
"dev": true,
"dependencies": {
"@types/node": "*"
}
},
"node_modules/balanced-match": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
"integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=",
"dev": true
},
"node_modules/brace-expansion": {
"version": "1.1.11",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
"dev": true,
"dependencies": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
}
},
"node_modules/concat-map": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=",
"dev": true
},
"node_modules/do-not-zip": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/do-not-zip/-/do-not-zip-1.0.0.tgz",
"integrity": "sha512-Pgd81ET43bhAGaN2Hq1zluSX1FmD7kl7KcV9ER/lawiLsRUB9pRA5y8r6us29Xk6BrINZETO8TjhYwtwafWUww=="
},
"node_modules/fs.realpath": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
"integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=",
"dev": true
},
"node_modules/glob": {
"version": "7.1.6",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz",
"integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==",
"dev": true,
"dependencies": {
"fs.realpath": "^1.0.0",
"inflight": "^1.0.4",
"inherits": "2",
"minimatch": "^3.0.4",
"once": "^1.3.0",
"path-is-absolute": "^1.0.0"
},
"engines": {
"node": "*"
},
"funding": {
"url": "https://github.com/sponsors/isaacs"
}
},
"node_modules/inflight": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
"integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=",
"dev": true,
"dependencies": {
"once": "^1.3.0",
"wrappy": "1"
}
},
"node_modules/inherits": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==",
"dev": true
},
"node_modules/jasmine": {
"version": "3.9.0",
"resolved": "https://registry.npmjs.org/jasmine/-/jasmine-3.9.0.tgz",
"integrity": "sha512-JgtzteG7xnqZZ51fg7N2/wiQmXon09szkALcRMTgCMX4u/m17gVJFjObnvw5FXkZOWuweHPaPRVB6DI2uN0wVA==",
"dev": true,
"dependencies": {
"glob": "^7.1.6",
"jasmine-core": "~3.9.0"
},
"bin": {
"jasmine": "bin/jasmine.js"
}
},
"node_modules/jasmine-core": {
"version": "3.9.0",
"resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-3.9.0.tgz",
"integrity": "sha512-Tv3kVbPCGVrjsnHBZ38NsPU3sDOtNa0XmbG2baiyJqdb5/SPpDO6GVwJYtUryl6KB4q1Ssckwg612ES9Z0dreQ==",
"dev": true
},
"node_modules/joi": {
"version": "17.4.2",
"resolved": "https://registry.npmjs.org/joi/-/joi-17.4.2.tgz",
"integrity": "sha512-Lm56PP+n0+Z2A2rfRvsfWVDXGEWjXxatPopkQ8qQ5mxCEhwHG+Ettgg5o98FFaxilOxozoa14cFhrE/hOzh/Nw==",
"dependencies": {
"@hapi/hoek": "^9.0.0",
"@hapi/topo": "^5.0.0",
"@sideway/address": "^4.1.0",
"@sideway/formula": "^3.0.0",
"@sideway/pinpoint": "^2.0.0"
}
},
"node_modules/minimatch": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
"integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
"dev": true,
"dependencies": {
"brace-expansion": "^1.1.7"
},
"engines": {
"node": "*"
}
},
"node_modules/node-forge": {
"version": "0.10.0",
"resolved": "https://registry.npmjs.org/node-forge/-/node-forge-0.10.0.tgz",
"integrity": "sha512-PPmu8eEeG9saEUvI97fm4OYxXVB6bFvyNTyiUOBichBpFG8A1Ljw3bY62+5oOjDEMHRnd0Y7HQ+x7uzxOzC6JA==",
"engines": {
"node": ">= 6.0.0"
}
},
"node_modules/once": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
"integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
"dev": true,
"dependencies": {
"wrappy": "1"
}
},
"node_modules/path-is-absolute": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
"integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=",
"dev": true,
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/prettier": {
"version": "2.4.1",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.4.1.tgz",
"integrity": "sha512-9fbDAXSBcc6Bs1mZrDYb3XKzDLm4EXXL9sC1LqKP5rZkT6KRr/rf9amVUcODVXgguK/isJz0d0hP72WeaKWsvA==",
"dev": true,
"bin": {
"prettier": "bin-prettier.js"
},
"engines": {
"node": ">=10.13.0"
}
},
"node_modules/rimraf": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz",
"integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==",
"dev": true,
"dependencies": {
"glob": "^7.1.3"
},
"bin": {
"rimraf": "bin.js"
},
"funding": {
"url": "https://github.com/sponsors/isaacs"
}
},
"node_modules/tslib": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.1.tgz",
"integrity": "sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw=="
},
"node_modules/typescript": {
"version": "4.4.4",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.4.4.tgz",
"integrity": "sha512-DqGhF5IKoBl8WNf8C1gu8q0xZSInh9j1kJJMqT3a94w1JzVaBU4EXOSMrz9yDqMT0xt3selp83fuFMQ0uzv6qA==",
"dev": true,
"bin": {
"tsc": "bin/tsc",
"tsserver": "bin/tsserver"
},
"engines": {
"node": ">=4.2.0"
}
},
"node_modules/wrappy": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=",
"dev": true
}
},
"dependencies": { "dependencies": {
"@hapi/hoek": { "@hapi/hoek": {
"version": "9.1.1", "version": "9.1.1",
@@ -35,6 +311,15 @@
"resolved": "https://registry.npmjs.org/@sideway/pinpoint/-/pinpoint-2.0.0.tgz", "resolved": "https://registry.npmjs.org/@sideway/pinpoint/-/pinpoint-2.0.0.tgz",
"integrity": "sha512-RNiOoTPkptFtSVzQevY/yWtZwf/RxyVnPy/OcA9HBM3MlGDnBEYL5B41H0MTn0Uec8Hi+2qUtTfG2WWZBmMejQ==" "integrity": "sha512-RNiOoTPkptFtSVzQevY/yWtZwf/RxyVnPy/OcA9HBM3MlGDnBEYL5B41H0MTn0Uec8Hi+2qUtTfG2WWZBmMejQ=="
}, },
"@types/do-not-zip": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/@types/do-not-zip/-/do-not-zip-1.0.0.tgz",
"integrity": "sha512-A/itOzxvHqp0dGAhbhDLm62Wmx0W6c9eYvKkb8VijDBnSoC9u0e8GwouyIxluFCJELOilTe48oCzeTrQK1kkjg==",
"dev": true,
"requires": {
"@types/node": "*"
}
},
"@types/jasmine": { "@types/jasmine": {
"version": "3.9.1", "version": "3.9.1",
"resolved": "https://registry.npmjs.org/@types/jasmine/-/jasmine-3.9.1.tgz", "resolved": "https://registry.npmjs.org/@types/jasmine/-/jasmine-3.9.1.tgz",
@@ -56,15 +341,6 @@
"@types/node": "*" "@types/node": "*"
} }
}, },
"@types/yazl": {
"version": "2.4.2",
"resolved": "https://registry.npmjs.org/@types/yazl/-/yazl-2.4.2.tgz",
"integrity": "sha512-T+9JH8O2guEjXNxqmybzQ92mJUh2oCwDDMSSimZSe1P+pceZiFROZLYmcbqkzV5EUwz6VwcKXCO2S2yUpra6XQ==",
"dev": true,
"requires": {
"@types/node": "*"
}
},
"balanced-match": { "balanced-match": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
@@ -81,17 +357,17 @@
"concat-map": "0.0.1" "concat-map": "0.0.1"
} }
}, },
"buffer-crc32": {
"version": "0.2.13",
"resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.13.tgz",
"integrity": "sha1-DTM+PwDqxQqhRUq9MO+MKl2ackI="
},
"concat-map": { "concat-map": {
"version": "0.0.1", "version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=",
"dev": true "dev": true
}, },
"do-not-zip": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/do-not-zip/-/do-not-zip-1.0.0.tgz",
"integrity": "sha512-Pgd81ET43bhAGaN2Hq1zluSX1FmD7kl7KcV9ER/lawiLsRUB9pRA5y8r6us29Xk6BrINZETO8TjhYwtwafWUww=="
},
"fs.realpath": { "fs.realpath": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
@@ -216,14 +492,6 @@
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=",
"dev": true "dev": true
},
"yazl": {
"version": "2.5.1",
"resolved": "https://registry.npmjs.org/yazl/-/yazl-2.5.1.tgz",
"integrity": "sha512-phENi2PLiHnHb6QBVot+dJnaAZ0xosj7p3fWl+znIjBDlnMI2PsZCJZ306BPTFOaHf5qdDEI8x5qFrSOBN5vrw==",
"requires": {
"buffer-crc32": "~0.2.3"
}
} }
} }
} }

View File

@@ -25,10 +25,10 @@
"Pass" "Pass"
], ],
"dependencies": { "dependencies": {
"do-not-zip": "^1.0.0",
"joi": "^17.4.2", "joi": "^17.4.2",
"node-forge": "^0.10.0", "node-forge": "^0.10.0",
"tslib": "^2.3.1", "tslib": "^2.3.1"
"yazl": "^2.5.1"
}, },
"engines": { "engines": {
"node": ">=14.18.1" "node": ">=14.18.1"
@@ -37,7 +37,7 @@
"@types/jasmine": "^3.9.1", "@types/jasmine": "^3.9.1",
"@types/node": "^16.10.8", "@types/node": "^16.10.8",
"@types/node-forge": "^0.10.8", "@types/node-forge": "^0.10.8",
"@types/yazl": "^2.4.2", "@types/do-not-zip": "^1.0.0",
"jasmine": "^3.9.0", "jasmine": "^3.9.0",
"prettier": "^2.4.1", "prettier": "^2.4.1",
"rimraf": "^3.0.2", "rimraf": "^3.0.2",

View File

@@ -65,21 +65,21 @@ describe("Bundle", () => {
}); });
describe("getAsBuffer", () => { describe("getAsBuffer", () => {
it("should return a buffer", async () => { it("should return a buffer", () => {
addEmptyFilesToBundle(bundle); addEmptyFilesToBundle(bundle);
expect(await bundle.getAsBuffer()).toBeInstanceOf(Buffer); expect(bundle.getAsBuffer()).toBeInstanceOf(Buffer);
}); });
it("should freeze the bundle", async () => { it("should freeze the bundle", () => {
await bundle.getAsBuffer(); bundle.getAsBuffer();
expect(bundle.isFrozen).toBe(true); expect(bundle.isFrozen).toBe(true);
}); });
it("should throw error if a file is attempted to be added when bundle is frozen", async () => { it("should throw error if a file is attempted to be added when bundle is frozen", () => {
addEmptyFilesToBundle(bundle); addEmptyFilesToBundle(bundle);
await bundle.getAsBuffer(); bundle.getAsBuffer();
expect(() => expect(() =>
bundle.addBuffer("icon.png", Buffer.alloc(0)), bundle.addBuffer("icon.png", Buffer.alloc(0)),

View File

@@ -1,10 +1,9 @@
import { Stream } from "stream"; import { Readable, Stream } from "stream";
import * as Messages from "./messages"; import * as Messages from "./messages";
import { ZipFile } from "yazl"; import * as zip from "do-not-zip";
export const filesSymbol = Symbol("bundleFiles"); export const filesSymbol = Symbol("bundleFiles");
export const freezeSymbol = Symbol("bundleFreeze"); export const freezeSymbol = Symbol("bundleFreeze");
const archiveSymbol = Symbol("zip");
namespace Mime { namespace Mime {
export type type = string; export type type = string;
@@ -19,7 +18,6 @@ namespace Mime {
export default class Bundle { export default class Bundle {
private [filesSymbol]: { [key: string]: Buffer } = {}; private [filesSymbol]: { [key: string]: Buffer } = {};
private [archiveSymbol] = new ZipFile();
constructor(public mimeType: `${Mime.type}/${Mime.subtype}`) { constructor(public mimeType: `${Mime.type}/${Mime.subtype}`) {
if (!mimeType) { if (!mimeType) {
@@ -66,7 +64,6 @@ export default class Bundle {
} }
Object.freeze(this[filesSymbol]); Object.freeze(this[filesSymbol]);
this[archiveSymbol].end();
} }
/** /**
@@ -92,7 +89,6 @@ export default class Bundle {
} }
this[filesSymbol][fileName] = buffer; this[filesSymbol][fileName] = buffer;
this[archiveSymbol].addBuffer(buffer, fileName);
} }
/** /**
@@ -100,20 +96,17 @@ export default class Bundle {
* Once closed, the bundle does not allow files * Once closed, the bundle does not allow files
* to be added any further. * to be added any further.
* *
* @returns Promise<Buffer> * @returns Buffer
*/ */
public getAsBuffer(): Promise<Buffer> { public getAsBuffer(): Buffer {
const stream = this.getAsStream(); this[freezeSymbol]();
const chunks = []; return zip.toBuffer(
Object.entries(this[filesSymbol]).map(([path, data]) => ({
return new Promise((resolve) => { path,
stream.on("data", (data: Buffer) => { data,
chunks.push(data); })),
}); );
stream.on("end", () => resolve(Buffer.from(chunks)));
});
} }
/** /**
@@ -125,8 +118,7 @@ export default class Bundle {
*/ */
public getAsStream(): Stream { public getAsStream(): Stream {
this[freezeSymbol](); return Readable.from(this.getAsBuffer());
return this[archiveSymbol].outputStream;
} }
/** /**

View File

@@ -638,7 +638,7 @@ export default class PKPass extends Bundle {
* @returns * @returns
*/ */
public async getAsBuffer(): Promise<Buffer> { public getAsBuffer(): Buffer {
if (!this.isFrozen) { if (!this.isFrozen) {
this[closePassSymbol](); this[closePassSymbol]();
} }