@codebucket/puppet-master 1.0.0
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/.idea/Puppet-Master-Module.iml +12 -0
- package/.idea/material_theme_project_new.xml +17 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +59 -0
- package/package.json +21 -0
- package/src/index.ts +47 -0
- package/tsconfig.json +19 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<module type="WEB_MODULE" version="4">
|
|
3
|
+
<component name="NewModuleRootManager">
|
|
4
|
+
<content url="file://$MODULE_DIR$">
|
|
5
|
+
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
|
|
6
|
+
<excludeFolder url="file://$MODULE_DIR$/temp" />
|
|
7
|
+
<excludeFolder url="file://$MODULE_DIR$/tmp" />
|
|
8
|
+
</content>
|
|
9
|
+
<orderEntry type="inheritedJdk" />
|
|
10
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
|
11
|
+
</component>
|
|
12
|
+
</module>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="MaterialThemeProjectNewConfig">
|
|
4
|
+
<option name="metadata">
|
|
5
|
+
<MTProjectMetadataState>
|
|
6
|
+
<option name="migrated" value="true" />
|
|
7
|
+
<option name="pristineConfig" value="false" />
|
|
8
|
+
<option name="userId" value="2ad778c:1922f284558:-7ffd" />
|
|
9
|
+
</MTProjectMetadataState>
|
|
10
|
+
</option>
|
|
11
|
+
<option name="titleBarState">
|
|
12
|
+
<MTProjectTitleBarConfigState>
|
|
13
|
+
<option name="overrideColor" value="false" />
|
|
14
|
+
</MTProjectTitleBarConfigState>
|
|
15
|
+
</option>
|
|
16
|
+
</component>
|
|
17
|
+
</project>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="ProjectModuleManager">
|
|
4
|
+
<modules>
|
|
5
|
+
<module fileurl="file://$PROJECT_DIR$/.idea/Puppet-Master-Module.iml" filepath="$PROJECT_DIR$/.idea/Puppet-Master-Module.iml" />
|
|
6
|
+
</modules>
|
|
7
|
+
</component>
|
|
8
|
+
</project>
|
package/.idea/vcs.xml
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
type opts = {
|
|
2
|
+
baseUrl: string;
|
|
3
|
+
apiKey: string;
|
|
4
|
+
};
|
|
5
|
+
type puppeteerOpts = {
|
|
6
|
+
launchOptions?: any;
|
|
7
|
+
pageOptions?: any;
|
|
8
|
+
pdfOptions?: any;
|
|
9
|
+
otherPageFunctions?: any;
|
|
10
|
+
pdfPath: string;
|
|
11
|
+
};
|
|
12
|
+
export declare class PuppetMaster {
|
|
13
|
+
private readonly axios;
|
|
14
|
+
constructor(opts: opts);
|
|
15
|
+
pdf(opts: puppeteerOpts): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA,KAAK,IAAI,GAAG;IACR,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;CAClB,CAAA;AAED,KAAK,aAAa,GAAG;IACjB,aAAc,CAAC,EAAE,GAAG,CAAC;IACrB,WAAY,CAAC,EAAE,GAAG,CAAC;IACnB,UAAW,CAAC,EAAE,GAAG,CAAC;IAClB,kBAAmB,CAAC,EAAE,GAAG,CAAC;IAC1B,OAAO,EAAG,MAAM,CAAC;CACpB,CAAA;AAED,qBAAa,YAAY;IACrB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAQ;gBAElB,IAAI,EAAE,IAAI;IAShB,GAAG,CAAC,IAAI,EAAE,aAAa;CAahC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.PuppetMaster = void 0;
|
|
30
|
+
const axios_1 = __importStar(require("axios"));
|
|
31
|
+
const util_1 = __importDefault(require("util"));
|
|
32
|
+
const stream_1 = __importDefault(require("stream"));
|
|
33
|
+
const fs_1 = __importDefault(require("fs"));
|
|
34
|
+
const pipeline = util_1.default.promisify(stream_1.default.pipeline);
|
|
35
|
+
class PuppetMaster {
|
|
36
|
+
constructor(opts) {
|
|
37
|
+
this.axios = axios_1.default.create({
|
|
38
|
+
baseURL: opts.baseUrl,
|
|
39
|
+
headers: {
|
|
40
|
+
"x-api-key": opts.apiKey
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
async pdf(opts) {
|
|
45
|
+
try {
|
|
46
|
+
const request = await this.axios.post("/pdf", opts, {
|
|
47
|
+
responseType: "stream"
|
|
48
|
+
});
|
|
49
|
+
await pipeline(request.data, fs_1.default.createWriteStream(opts.pdfPath));
|
|
50
|
+
}
|
|
51
|
+
catch (err) {
|
|
52
|
+
if (err instanceof axios_1.AxiosError) {
|
|
53
|
+
throw new Error(err.response?.data);
|
|
54
|
+
}
|
|
55
|
+
throw err;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.PuppetMaster = PuppetMaster;
|
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@codebucket/puppet-master",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"main": "dist/index",
|
|
5
|
+
"types": "dist/index",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
8
|
+
"start": "tsc"
|
|
9
|
+
},
|
|
10
|
+
"devDependencies": {
|
|
11
|
+
"ts-node": "^10.9.2",
|
|
12
|
+
"typescript": "^5.6.2"
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"axios": "^1.7.7"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "https://github.com/Codebucket-Solutions/puppet-master-module.git"
|
|
20
|
+
}
|
|
21
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import axios, { Axios, AxiosError, AxiosResponse } from "axios";
|
|
2
|
+
import util from "util";
|
|
3
|
+
import stream from "stream";
|
|
4
|
+
import fs from "fs";
|
|
5
|
+
|
|
6
|
+
const pipeline = util.promisify(stream.pipeline);
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
type opts = {
|
|
10
|
+
baseUrl: string;
|
|
11
|
+
apiKey: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
type puppeteerOpts = {
|
|
15
|
+
launchOptions ?: any;
|
|
16
|
+
pageOptions ?: any;
|
|
17
|
+
pdfOptions ?: any;
|
|
18
|
+
otherPageFunctions ?: any;
|
|
19
|
+
pdfPath : string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export class PuppetMaster {
|
|
23
|
+
private readonly axios: Axios;
|
|
24
|
+
|
|
25
|
+
constructor(opts: opts) {
|
|
26
|
+
this.axios = axios.create({
|
|
27
|
+
baseURL: opts.baseUrl,
|
|
28
|
+
headers: {
|
|
29
|
+
"x-api-key": opts.apiKey
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async pdf(opts: puppeteerOpts) {
|
|
35
|
+
try {
|
|
36
|
+
const request = await this.axios.post("/pdf", opts, {
|
|
37
|
+
responseType: "stream"
|
|
38
|
+
});
|
|
39
|
+
await pipeline(request.data, fs.createWriteStream(opts.pdfPath));
|
|
40
|
+
} catch (err) {
|
|
41
|
+
if (err instanceof AxiosError) {
|
|
42
|
+
throw new Error(err.response?.data);
|
|
43
|
+
}
|
|
44
|
+
throw err;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"strict": true,
|
|
6
|
+
"useUnknownInCatchVariables": false,
|
|
7
|
+
"declaration": true,
|
|
8
|
+
"declarationMap": true,
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"outDir": "./dist",
|
|
11
|
+
"rootDir": "./src"
|
|
12
|
+
},
|
|
13
|
+
"include": [
|
|
14
|
+
"src/**/*.ts"
|
|
15
|
+
],
|
|
16
|
+
"exclude": [
|
|
17
|
+
"node_modules"
|
|
18
|
+
]
|
|
19
|
+
}
|