nestjs-puppeteer 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/.prettierignore +1 -0
- package/CHANGELOG.md +13 -0
- package/LICENSE +21 -0
- package/README.md +2 -0
- package/dist/common/index.d.ts +2 -0
- package/dist/common/index.js +18 -0
- package/dist/common/puppeteer.decorators.d.ts +3 -0
- package/dist/common/puppeteer.decorators.js +9 -0
- package/dist/common/puppeteer.utils.d.ts +6 -0
- package/dist/common/puppeteer.utils.js +30 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +22 -0
- package/dist/interfaces/index.d.ts +1 -0
- package/dist/interfaces/index.js +17 -0
- package/dist/interfaces/puppeteer-options.interface.d.ts +28 -0
- package/dist/interfaces/puppeteer-options.interface.js +2 -0
- package/dist/puppeteer-core.module.d.ts +14 -0
- package/dist/puppeteer-core.module.js +144 -0
- package/dist/puppeteer.constants.d.ts +4 -0
- package/dist/puppeteer.constants.js +7 -0
- package/dist/puppeteer.module.d.ts +7 -0
- package/dist/puppeteer.module.js +42 -0
- package/dist/puppeteer.providers.d.ts +3 -0
- package/dist/puppeteer.providers.js +14 -0
- package/package.json +68 -0
package/.prettierignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
tests/**
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# 1.0.0 (2023-03-19)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* Fixed husky hook ([811fff1](https://github.com/oblakstudio/nestjs-puppeteer/commit/811fff147be88f6eeb0100f89196aadcd376e554))
|
|
7
|
+
* Fixed husky hook ([1f0d998](https://github.com/oblakstudio/nestjs-puppeteer/commit/1f0d9984cf31e1469ce1c871bfd78377cf9d8d13))
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Features
|
|
11
|
+
|
|
12
|
+
* **build:** Implemented build system ([64a36c9](https://github.com/oblakstudio/nestjs-puppeteer/commit/64a36c95e5a703544c591e10d9bc99f4f8a3e7b8))
|
|
13
|
+
* Init commit ([50936e5](https://github.com/oblakstudio/nestjs-puppeteer/commit/50936e5de86578bd9bca3add374f9ef5fd1d923a))
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Oblak Solutions
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./puppeteer.utils"), exports);
|
|
18
|
+
__exportStar(require("./puppeteer.decorators"), exports);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InjectPage = exports.InjectBrowser = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const puppeteer_utils_1 = require("./puppeteer.utils");
|
|
6
|
+
const InjectBrowser = (browserName) => (0, common_1.Inject)((0, puppeteer_utils_1.getBrowserToken)(browserName));
|
|
7
|
+
exports.InjectBrowser = InjectBrowser;
|
|
8
|
+
const InjectPage = (pageName, browserName) => (0, common_1.Inject)((0, puppeteer_utils_1.getPageToken)(pageName, browserName));
|
|
9
|
+
exports.InjectPage = InjectPage;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Type } from '@nestjs/common';
|
|
2
|
+
import { Browser, Page } from 'puppeteer';
|
|
3
|
+
import { PuppeteerModuleOptions } from '../interfaces';
|
|
4
|
+
export declare function getBrowserToken(browser?: PuppeteerModuleOptions | string): string | Function | Type<Browser>;
|
|
5
|
+
export declare function getPageToken(page: string, browser?: PuppeteerModuleOptions | string): string | Function | Type<Page>;
|
|
6
|
+
export declare function getBrowserPrefix(browser?: PuppeteerModuleOptions | string): string;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getBrowserPrefix = exports.getPageToken = exports.getBrowserToken = void 0;
|
|
4
|
+
const puppeteer_1 = require("puppeteer");
|
|
5
|
+
const puppeteer_constants_1 = require("../puppeteer.constants");
|
|
6
|
+
function getBrowserToken(browser = puppeteer_constants_1.DEFAULT_BROWSER_NAME) {
|
|
7
|
+
return puppeteer_constants_1.DEFAULT_BROWSER_NAME === browser
|
|
8
|
+
? puppeteer_1.Browser
|
|
9
|
+
: 'string' === typeof browser
|
|
10
|
+
? `${browser}Browser`
|
|
11
|
+
: puppeteer_constants_1.DEFAULT_BROWSER_NAME === browser.name || !browser.name
|
|
12
|
+
? puppeteer_1.Browser
|
|
13
|
+
: `${browser.name}Browser`;
|
|
14
|
+
}
|
|
15
|
+
exports.getBrowserToken = getBrowserToken;
|
|
16
|
+
function getPageToken(page, browser = puppeteer_constants_1.DEFAULT_BROWSER_NAME) {
|
|
17
|
+
const browserPrefix = getBrowserPrefix(browser);
|
|
18
|
+
return `${browserPrefix}${page}Page`;
|
|
19
|
+
}
|
|
20
|
+
exports.getPageToken = getPageToken;
|
|
21
|
+
function getBrowserPrefix(browser = puppeteer_constants_1.DEFAULT_BROWSER_NAME) {
|
|
22
|
+
return puppeteer_constants_1.DEFAULT_BROWSER_NAME === browser
|
|
23
|
+
? ''
|
|
24
|
+
: 'string' === typeof browser
|
|
25
|
+
? `${browser}_`
|
|
26
|
+
: puppeteer_constants_1.DEFAULT_BROWSER_NAME === browser.name || !browser.name
|
|
27
|
+
? ''
|
|
28
|
+
: `${browser.name}_`;
|
|
29
|
+
}
|
|
30
|
+
exports.getBrowserPrefix = getBrowserPrefix;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./common"), exports);
|
|
18
|
+
__exportStar(require("./interfaces"), exports);
|
|
19
|
+
__exportStar(require("./puppeteer-core.module"), exports);
|
|
20
|
+
__exportStar(require("./puppeteer.constants"), exports);
|
|
21
|
+
__exportStar(require("./puppeteer.module"), exports);
|
|
22
|
+
__exportStar(require("./puppeteer.providers"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './puppeteer-options.interface';
|
|
@@ -0,0 +1,17 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./puppeteer-options.interface"), exports);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ModuleMetadata, Type } from '@nestjs/common';
|
|
2
|
+
import { PuppeteerNodeLaunchOptions } from 'puppeteer';
|
|
3
|
+
import { PuppeteerExtraPlugin } from 'puppeteer-extra';
|
|
4
|
+
export type PuppeteerModuleOptions = {
|
|
5
|
+
/**
|
|
6
|
+
* Browser name
|
|
7
|
+
*/
|
|
8
|
+
name?: string;
|
|
9
|
+
/**
|
|
10
|
+
* Array of puppeteer-extra plugins
|
|
11
|
+
*/
|
|
12
|
+
plugins?: PuppeteerExtraPlugin[];
|
|
13
|
+
/**
|
|
14
|
+
* Is the module global
|
|
15
|
+
*/
|
|
16
|
+
isGlobal?: boolean;
|
|
17
|
+
} & Partial<PuppeteerNodeLaunchOptions>;
|
|
18
|
+
export interface PuppeteerOptionsFactory {
|
|
19
|
+
createPuppeteerOptions(browserName?: string): Promise<PuppeteerModuleOptions> | PuppeteerModuleOptions;
|
|
20
|
+
}
|
|
21
|
+
export interface PuppeteerModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
|
|
22
|
+
name?: string;
|
|
23
|
+
isGlobal?: boolean;
|
|
24
|
+
useExisting?: Type<PuppeteerOptionsFactory>;
|
|
25
|
+
useClass?: Type<PuppeteerOptionsFactory>;
|
|
26
|
+
useFactory?: (...args: any[]) => Promise<PuppeteerModuleOptions> | PuppeteerModuleOptions;
|
|
27
|
+
inject?: any[];
|
|
28
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DynamicModule, OnApplicationShutdown } from '@nestjs/common';
|
|
2
|
+
import { ModuleRef } from '@nestjs/core';
|
|
3
|
+
import { PuppeteerModuleAsyncOptions, PuppeteerModuleOptions } from './interfaces';
|
|
4
|
+
export declare class PuppeteerCoreModule implements OnApplicationShutdown {
|
|
5
|
+
private readonly options;
|
|
6
|
+
private readonly moduleRef;
|
|
7
|
+
private readonly logger;
|
|
8
|
+
constructor(options: PuppeteerModuleOptions, moduleRef: ModuleRef);
|
|
9
|
+
static forRoot(options?: any): DynamicModule;
|
|
10
|
+
static forRootAsync(options: PuppeteerModuleAsyncOptions): DynamicModule;
|
|
11
|
+
onApplicationShutdown(): Promise<void>;
|
|
12
|
+
private static createAsyncProviders;
|
|
13
|
+
private static createAsyncOptionsProvider;
|
|
14
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
15
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
16
|
+
};
|
|
17
|
+
var PuppeteerCoreModule_1;
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.PuppeteerCoreModule = void 0;
|
|
20
|
+
const common_1 = require("@nestjs/common");
|
|
21
|
+
const core_1 = require("@nestjs/core");
|
|
22
|
+
const puppeteer_extra_1 = __importDefault(require("puppeteer-extra"));
|
|
23
|
+
const puppeteer_constants_1 = require("./puppeteer.constants");
|
|
24
|
+
const common_2 = require("./common");
|
|
25
|
+
let PuppeteerCoreModule = PuppeteerCoreModule_1 = class PuppeteerCoreModule {
|
|
26
|
+
constructor(options, moduleRef) {
|
|
27
|
+
this.options = options;
|
|
28
|
+
this.moduleRef = moduleRef;
|
|
29
|
+
this.logger = new common_1.Logger('PuppeteerModule');
|
|
30
|
+
}
|
|
31
|
+
static forRoot(options = {}) {
|
|
32
|
+
const puppeteerModuleOptions = {
|
|
33
|
+
provide: puppeteer_constants_1.PUPPETEER_MODULE_OPTIONS,
|
|
34
|
+
useValue: options,
|
|
35
|
+
};
|
|
36
|
+
const pluginProvider = {
|
|
37
|
+
provide: puppeteer_constants_1.PUPPETEER_BROWSER_PLUGINS,
|
|
38
|
+
useFactory: async (options) => {
|
|
39
|
+
if (options.plugins) {
|
|
40
|
+
options.plugins.forEach((plugin) => puppeteer_extra_1.default.use(plugin));
|
|
41
|
+
return options.plugins;
|
|
42
|
+
}
|
|
43
|
+
return [];
|
|
44
|
+
},
|
|
45
|
+
inject: [puppeteer_constants_1.PUPPETEER_MODULE_OPTIONS],
|
|
46
|
+
};
|
|
47
|
+
const browserProvider = {
|
|
48
|
+
provide: (0, common_2.getBrowserToken)(options),
|
|
49
|
+
useFactory: async (options) => {
|
|
50
|
+
return await puppeteer_extra_1.default.launch(options);
|
|
51
|
+
},
|
|
52
|
+
inject: [puppeteer_constants_1.PUPPETEER_MODULE_OPTIONS],
|
|
53
|
+
};
|
|
54
|
+
const providers = [puppeteerModuleOptions, pluginProvider, browserProvider];
|
|
55
|
+
const exports = [browserProvider];
|
|
56
|
+
return {
|
|
57
|
+
module: PuppeteerCoreModule_1,
|
|
58
|
+
providers,
|
|
59
|
+
exports,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
static forRootAsync(options) {
|
|
63
|
+
const pluginProvider = {
|
|
64
|
+
provide: puppeteer_constants_1.PUPPETEER_BROWSER_PLUGINS,
|
|
65
|
+
useFactory: async (options) => {
|
|
66
|
+
if (options.plugins) {
|
|
67
|
+
options.plugins.forEach((plugin) => puppeteer_extra_1.default.use(plugin));
|
|
68
|
+
return options.plugins;
|
|
69
|
+
}
|
|
70
|
+
return [];
|
|
71
|
+
},
|
|
72
|
+
inject: [puppeteer_constants_1.PUPPETEER_MODULE_OPTIONS],
|
|
73
|
+
};
|
|
74
|
+
const browserProvider = {
|
|
75
|
+
provide: (0, common_2.getBrowserToken)(options),
|
|
76
|
+
useFactory: async (options) => {
|
|
77
|
+
return await puppeteer_extra_1.default.launch(options);
|
|
78
|
+
},
|
|
79
|
+
inject: [puppeteer_constants_1.PUPPETEER_MODULE_OPTIONS],
|
|
80
|
+
};
|
|
81
|
+
const asyncProviders = this.createAsyncProviders(options);
|
|
82
|
+
const providers = [
|
|
83
|
+
...asyncProviders,
|
|
84
|
+
pluginProvider,
|
|
85
|
+
browserProvider,
|
|
86
|
+
];
|
|
87
|
+
const exports = [browserProvider];
|
|
88
|
+
return {
|
|
89
|
+
module: PuppeteerCoreModule_1,
|
|
90
|
+
providers,
|
|
91
|
+
exports,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
async onApplicationShutdown() {
|
|
95
|
+
const browser = this.moduleRef.get((0, common_2.getBrowserToken)(this.options));
|
|
96
|
+
try {
|
|
97
|
+
if (browser && browser.isConnected()) {
|
|
98
|
+
this.logger.log('Closing browser...');
|
|
99
|
+
await browser.close();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
catch (e) {
|
|
103
|
+
this.logger.error(e === null || e === void 0 ? void 0 : e.message);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
static createAsyncProviders(options) {
|
|
107
|
+
if (options.useExisting || options.useFactory) {
|
|
108
|
+
return [this.createAsyncOptionsProvider(options)];
|
|
109
|
+
}
|
|
110
|
+
const useClass = options.useClass;
|
|
111
|
+
return [
|
|
112
|
+
this.createAsyncOptionsProvider(options),
|
|
113
|
+
{
|
|
114
|
+
provide: useClass,
|
|
115
|
+
useClass,
|
|
116
|
+
}
|
|
117
|
+
];
|
|
118
|
+
}
|
|
119
|
+
static createAsyncOptionsProvider(options) {
|
|
120
|
+
if (options.useFactory) {
|
|
121
|
+
return {
|
|
122
|
+
provide: puppeteer_constants_1.PUPPETEER_MODULE_OPTIONS,
|
|
123
|
+
useFactory: options.useFactory,
|
|
124
|
+
inject: options.inject || [],
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
const inject = [
|
|
128
|
+
(options.useClass ||
|
|
129
|
+
options.useExisting),
|
|
130
|
+
];
|
|
131
|
+
return {
|
|
132
|
+
provide: puppeteer_constants_1.PUPPETEER_MODULE_OPTIONS,
|
|
133
|
+
useFactory: async (optionsFactory) => await optionsFactory.createPuppeteerOptions(options.name),
|
|
134
|
+
inject,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
PuppeteerCoreModule = PuppeteerCoreModule_1 = __decorate([
|
|
139
|
+
(0, common_1.Global)(),
|
|
140
|
+
(0, common_1.Module)({}),
|
|
141
|
+
__param(0, (0, common_1.Inject)(puppeteer_constants_1.PUPPETEER_MODULE_OPTIONS)),
|
|
142
|
+
__metadata("design:paramtypes", [Object, core_1.ModuleRef])
|
|
143
|
+
], PuppeteerCoreModule);
|
|
144
|
+
exports.PuppeteerCoreModule = PuppeteerCoreModule;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const PUPPETEER_MODULE_OPTIONS = "PuppeteerModuleOptions";
|
|
2
|
+
export declare const PUPPETEER_BROWSER_PLUGINS = "PuppeteerBrowserPlugins";
|
|
3
|
+
export declare const PUPPETEER_MODULE_ID = "PuppeteerModuleId";
|
|
4
|
+
export declare const DEFAULT_BROWSER_NAME = "default";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_BROWSER_NAME = exports.PUPPETEER_MODULE_ID = exports.PUPPETEER_BROWSER_PLUGINS = exports.PUPPETEER_MODULE_OPTIONS = void 0;
|
|
4
|
+
exports.PUPPETEER_MODULE_OPTIONS = 'PuppeteerModuleOptions';
|
|
5
|
+
exports.PUPPETEER_BROWSER_PLUGINS = 'PuppeteerBrowserPlugins';
|
|
6
|
+
exports.PUPPETEER_MODULE_ID = 'PuppeteerModuleId';
|
|
7
|
+
exports.DEFAULT_BROWSER_NAME = 'default';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DynamicModule } from '@nestjs/common';
|
|
2
|
+
import { PuppeteerModuleAsyncOptions, PuppeteerModuleOptions } from './interfaces';
|
|
3
|
+
export declare class PuppeteerModule {
|
|
4
|
+
static forRoot(options?: PuppeteerModuleOptions): DynamicModule;
|
|
5
|
+
static forFeature(pages: string[], browser?: PuppeteerModuleOptions | string): DynamicModule;
|
|
6
|
+
static forRootAsync(options: PuppeteerModuleAsyncOptions): DynamicModule;
|
|
7
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var PuppeteerModule_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.PuppeteerModule = void 0;
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const puppeteer_core_module_1 = require("./puppeteer-core.module");
|
|
13
|
+
const puppeteer_constants_1 = require("./puppeteer.constants");
|
|
14
|
+
const puppeteer_providers_1 = require("./puppeteer.providers");
|
|
15
|
+
let PuppeteerModule = PuppeteerModule_1 = class PuppeteerModule {
|
|
16
|
+
static forRoot(options) {
|
|
17
|
+
return {
|
|
18
|
+
module: PuppeteerModule_1,
|
|
19
|
+
global: options === null || options === void 0 ? void 0 : options.isGlobal,
|
|
20
|
+
imports: [puppeteer_core_module_1.PuppeteerCoreModule.forRoot(options)],
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
static forFeature(pages, browser = puppeteer_constants_1.DEFAULT_BROWSER_NAME) {
|
|
24
|
+
const providers = (0, puppeteer_providers_1.createPuppeteerProviders)(pages, browser);
|
|
25
|
+
return {
|
|
26
|
+
module: PuppeteerModule_1,
|
|
27
|
+
providers: providers,
|
|
28
|
+
exports: providers,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
static forRootAsync(options) {
|
|
32
|
+
return {
|
|
33
|
+
module: PuppeteerModule_1,
|
|
34
|
+
global: options === null || options === void 0 ? void 0 : options.isGlobal,
|
|
35
|
+
imports: [puppeteer_core_module_1.PuppeteerCoreModule.forRootAsync(options)],
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
PuppeteerModule = PuppeteerModule_1 = __decorate([
|
|
40
|
+
(0, common_1.Module)({})
|
|
41
|
+
], PuppeteerModule);
|
|
42
|
+
exports.PuppeteerModule = PuppeteerModule;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createPuppeteerProviders = void 0;
|
|
4
|
+
const common_1 = require("./common");
|
|
5
|
+
function createPuppeteerProviders(pages, browser) {
|
|
6
|
+
return (pages || []).map((page) => ({
|
|
7
|
+
provide: (0, common_1.getPageToken)(page, browser),
|
|
8
|
+
useFactory: async (browser) => {
|
|
9
|
+
return await browser.newPage();
|
|
10
|
+
},
|
|
11
|
+
inject: [(0, common_1.getBrowserToken)(browser)]
|
|
12
|
+
}));
|
|
13
|
+
}
|
|
14
|
+
exports.createPuppeteerProviders = createPuppeteerProviders;
|
package/package.json
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "nestjs-puppeteer",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"author": {
|
|
5
|
+
"name": "Sibin Grasic",
|
|
6
|
+
"email": "sibin.grasic@oblak.studio",
|
|
7
|
+
"url": "https://oblak.studio"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "rm -rf dist && tsc -p tsconfig.json",
|
|
11
|
+
"watch": "rm -rf dist && tsc -w -p tsconfig.json",
|
|
12
|
+
"format": "prettier --write \"**/*.ts\"",
|
|
13
|
+
"lint": "eslint 'lib/**/*.ts' --fix",
|
|
14
|
+
"test:e2e": "jest --config ./tests/jest-e2e.json --runInBand",
|
|
15
|
+
"test:e2e:dev": "jest --config ./tests/jest-e2e.json --runInBand --watch",
|
|
16
|
+
"prepare": "husky install",
|
|
17
|
+
"semantic-release": "semantic-release"
|
|
18
|
+
},
|
|
19
|
+
"main": "dist/index.js",
|
|
20
|
+
"types": "dist/index.d.ts",
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@commitlint/cli": "17.4.4",
|
|
23
|
+
"@commitlint/config-angular": "17.4.4",
|
|
24
|
+
"@nestjs/common": "9.3.10",
|
|
25
|
+
"@nestjs/core": "9.3.10",
|
|
26
|
+
"@nestjs/platform-express": "9.3.10",
|
|
27
|
+
"@nestjs/testing": "9.3.10",
|
|
28
|
+
"@semantic-release/changelog": "^6.0.2",
|
|
29
|
+
"@semantic-release/exec": "^6.0.3",
|
|
30
|
+
"@semantic-release/git": "^10.0.1",
|
|
31
|
+
"@semantic-release/github": "^8.0.7",
|
|
32
|
+
"@types/jest": "29.5.0",
|
|
33
|
+
"@types/node": "18.15.3",
|
|
34
|
+
"@types/supertest": "2.0.12",
|
|
35
|
+
"@typescript-eslint/eslint-plugin": "5.55.0",
|
|
36
|
+
"@typescript-eslint/parser": "5.55.0",
|
|
37
|
+
"eslint": "8.36.0",
|
|
38
|
+
"eslint-config-prettier": "8.7.0",
|
|
39
|
+
"eslint-plugin-import": "2.27.5",
|
|
40
|
+
"husky": "^8.0.3",
|
|
41
|
+
"jest": "29.5.0",
|
|
42
|
+
"lint-staged": "^13.2.0",
|
|
43
|
+
"puppeteer": "^19.7.5",
|
|
44
|
+
"puppeteer-extra": "^3.3.6",
|
|
45
|
+
"puppeteer-extra-plugin-stealth": "^2.11.2",
|
|
46
|
+
"reflect-metadata": "^0.1.13",
|
|
47
|
+
"rxjs": "^7.8.0",
|
|
48
|
+
"semantic-release": "^20.1.3",
|
|
49
|
+
"supertest": "6.3.3",
|
|
50
|
+
"ts-jest": "29.0.5",
|
|
51
|
+
"typescript": "^4.9"
|
|
52
|
+
},
|
|
53
|
+
"peerDependencies": {
|
|
54
|
+
"@nestjs/common": "^8.0.0 || ^9.0.0",
|
|
55
|
+
"@nestjs/core": "^8.0.0 || ^9.0.0",
|
|
56
|
+
"puppeteer": "^19.7.5",
|
|
57
|
+
"puppeteer-extra": "^3.3.6",
|
|
58
|
+
"reflect-metadata": "^0.1.13",
|
|
59
|
+
"rxjs": "^7.8.0"
|
|
60
|
+
},
|
|
61
|
+
"lint-staged": {
|
|
62
|
+
"**/*.{ts,json}": []
|
|
63
|
+
},
|
|
64
|
+
"repository": {
|
|
65
|
+
"type": "git",
|
|
66
|
+
"url": "https://github.com/oblakstudio/nestjs-puppeteer"
|
|
67
|
+
}
|
|
68
|
+
}
|