├── .commitlintrc.js ├── .eslintrc.js ├── .github ├── FUNDING.yml ├── ISSUE_TEMPLATE │ ├── bug_report.md │ ├── feature_request.md │ └── support_question.md ├── PULL_REQUEST_TEMPLATE.md ├── dependabot.yml └── workflows │ ├── build.yml │ ├── commitlint.yml │ ├── lint.yml │ ├── nightly.yml │ └── publish.yml ├── .gitignore ├── .husky ├── .gitignore └── commit-msg ├── .npmignore ├── .prettierignore ├── .prettierrc ├── .release-it.yml ├── .vscode ├── extensions.json └── settings.json ├── CHANGELOG.md ├── LICENSE.header ├── LICENSE.md ├── README.md ├── license-checker-config.json ├── package-lock.json ├── package.json ├── src ├── index.ts ├── loader.ts └── types │ └── webpack.d.ts ├── tsconfig.json └── webpack.config.js /.commitlintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: ['@commitlint/config-angular'], 3 | rules: { 4 | 'subject-case': [ 5 | 1, 6 | 'never', 7 | ['sentence-case', 'start-case', 'pascal-case', 'upper-case'], 8 | ], 9 | 'type-enum': [ 10 | 2, 11 | 'always', 12 | [ 13 | 'build', 14 | 'chore', 15 | 'ci', 16 | 'docs', 17 | 'feat', 18 | 'fix', 19 | 'perf', 20 | 'refactor', 21 | 'revert', 22 | 'style', 23 | 'test', 24 | ], 25 | ], 26 | }, 27 | }; 28 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | // eslint-disable-next-line no-undef 2 | module.exports = { 3 | root: true, 4 | env: { 5 | browser: true, 6 | node: false, 7 | commonjs: true, 8 | }, 9 | parser: '@typescript-eslint/parser', 10 | plugins: ['@typescript-eslint'], 11 | extends: [ 12 | 'eslint:recommended', 13 | 'plugin:@typescript-eslint/eslint-recommended', 14 | 'plugin:@typescript-eslint/recommended', 15 | 'plugin:prettier/recommended', 16 | ], 17 | rules: { 18 | '@typescript-eslint/ban-types': 'off', 19 | '@typescript-eslint/no-explicit-any': 'off', 20 | // @todo more restrictive 21 | 'no-empty': ['error', { allowEmptyCatch: true }], 22 | }, 23 | overrides: [ 24 | { 25 | files: ['webpack.*.js'], 26 | env: { 27 | browser: false, 28 | node: true, 29 | }, 30 | }, 31 | ], 32 | }; 33 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | issuehunt: wppconnect-team 2 | custom: ['https://apoia.se/wppconnect'] 3 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | labels: 'bug, needs triage' 5 | --- 6 | 7 | ## Description 8 | 9 | [Description of the bug, When Issue Happens] 10 | 11 | ## Environment 12 | 13 | - **wppconnect-loader version(s):** [e.g. 2.0.27, 2.2.1] 14 | - **Browser:** [e.g. Chrome 87, Chromium 85] 15 | - **OS:** [e.g. OSX 10.13.4, Windows 10] 16 | 17 | ## Steps to Reproduce 18 | 19 | 1. [First Step] 20 | 2. [Second Step] 21 | 3. [and so on...] 22 | 23 | ## Log Output 24 | 25 | ``` 26 | If relevant, paste all of your Log Output 27 | ``` 28 | 29 | ## Your Code 30 | 31 | ``` 32 | If relevant, paste all of your challenge code in here 33 | ``` 34 | 35 | ## Additional context / Screenshot 36 | 37 | Add any other context about the problem here. If applicable, add screenshots to help explain. 38 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: "I have a suggestion (and may want to implement it \U0001F642)!" 4 | labels: 'enhancement, needs triage' 5 | --- 6 | 7 | **Is your feature request related to a problem? Please describe.** 8 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 9 | 10 | **Describe the solution you'd like** 11 | A clear and concise description of what you want to happen. 12 | 13 | **Describe alternatives you've considered** 14 | A clear and concise description of any alternative solutions or features you've considered. 15 | 16 | **Additional context** 17 | Add any other context or screenshots about the feature request here. 18 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/support_question.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Support Question 3 | about: 'If you have a question, please check out our Documentation or Discord!' 4 | labels: 'question, needs triage' 5 | --- 6 | 7 | **Before adding this issue, make sure you do the following to make sure this is not a duplicate:** 8 | 9 | 1. Search through the repo's previous issues 10 | 2. Read through the readme at least once 11 | 3. Search the docs for the feature you're looking for 12 | 13 | We primarily use GitHub as an issue tracker; for usage and support questions, please check out these resources below. Thanks! 😁. 14 | 15 | --- 16 | 17 | - WhatsApp Group: [https://chat.whatsapp.com/C1ChjyShl5cA7KvmtecF3L] 18 | - Also have a look at the readme for more information on how to get support: 19 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Fixes # . 2 | 3 | ## Changes proposed in this pull request 4 | 5 | - 6 | - 7 | 8 | To test (it takes a while): `npm install github:/wppconnect-loader#` 9 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "npm" 4 | directory: "/" 5 | schedule: 6 | interval: "daily" 7 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: build 2 | 3 | on: 4 | push: 5 | branches: 6 | - '*' 7 | pull_request: 8 | branches: 9 | - '*' 10 | 11 | jobs: 12 | build: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - name: Checkout 16 | uses: actions/checkout@v2 17 | 18 | - name: Setup Node 19 | uses: actions/setup-node@v1 20 | with: 21 | node-version: 12.x 22 | 23 | - name: Get npm cache directory 24 | id: npm-cache 25 | run: | 26 | echo "::set-output name=dir::$(npm config get cache)" 27 | - name: Setup npm cache 28 | uses: actions/cache@v2 29 | with: 30 | path: ${{ steps.npm-cache.outputs.dir }} 31 | key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} 32 | restore-keys: | 33 | ${{ runner.os }}-node- 34 | 35 | - name: Install Dependencies 36 | run: npm ci || npm install 37 | 38 | - name: Build source 39 | run: npm run compile:prod 40 | -------------------------------------------------------------------------------- /.github/workflows/commitlint.yml: -------------------------------------------------------------------------------- 1 | name: commit lint 2 | on: [pull_request] 3 | 4 | jobs: 5 | commitlint: 6 | runs-on: ubuntu-latest 7 | steps: 8 | - name: Checkout 9 | uses: actions/checkout@v2 10 | with: 11 | fetch-depth: 0 12 | 13 | - name: Lint commit 14 | uses: wagoid/commitlint-github-action@v2 15 | with: 16 | configFile: './.commitlintrc.js' 17 | -------------------------------------------------------------------------------- /.github/workflows/lint.yml: -------------------------------------------------------------------------------- 1 | name: lint 2 | 3 | on: 4 | push: 5 | branches: 6 | - '*' 7 | pull_request: 8 | branches: 9 | - '*' 10 | 11 | jobs: 12 | lint: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - name: Checkout 16 | uses: actions/checkout@v2 17 | 18 | - name: Setup Node 19 | uses: actions/setup-node@v1 20 | with: 21 | node-version: 12.x 22 | 23 | - name: Get npm cache directory 24 | id: npm-cache 25 | run: | 26 | echo "::set-output name=dir::$(npm config get cache)" 27 | - name: Setup npm cache 28 | uses: actions/cache@v2 29 | with: 30 | path: ${{ steps.npm-cache.outputs.dir }} 31 | key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} 32 | restore-keys: | 33 | ${{ runner.os }}-node- 34 | 35 | - name: Install Dependencies 36 | run: npm ci || npm install 37 | env: 38 | PUPPETEER_SKIP_DOWNLOAD: true 39 | 40 | - name: Lint source 41 | run: npm run lint 42 | -------------------------------------------------------------------------------- /.github/workflows/nightly.yml: -------------------------------------------------------------------------------- 1 | name: Nightly Release 2 | 3 | on: 4 | push: 5 | branches: 6 | - 'master' 7 | 8 | jobs: 9 | nightly: 10 | runs-on: ubuntu-latest 11 | continue-on-error: true 12 | steps: 13 | - name: Checkout 14 | uses: actions/checkout@v2 15 | with: 16 | fetch-depth: 0 17 | 18 | - name: Fetching tags 19 | run: git fetch --tags -f || true 20 | 21 | - name: Setup Node 22 | uses: actions/setup-node@v1 23 | with: 24 | node-version: 12.x 25 | 26 | - name: Get npm cache directory 27 | id: npm-cache 28 | run: | 29 | echo "::set-output name=dir::$(npm config get cache)" 30 | - name: Setup npm cache 31 | uses: actions/cache@v2 32 | with: 33 | path: ${{ steps.npm-cache.outputs.dir }} 34 | key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} 35 | restore-keys: | 36 | ${{ runner.os }}-node- 37 | 38 | - name: Install Dependencies 39 | run: npm ci || npm install 40 | 41 | - name: Update version to alpha 42 | run: npm version prerelease --preid=alpha --no-git --no-git-tag-version 43 | 44 | - name: Build NPM package 45 | run: npm pack && mv wppconnect-*.tgz wppconnect-loader-nightly.tgz 46 | 47 | - name: Generate Changelog 48 | id: generate_changelog 49 | run: | 50 | changelog=$(npm run changelog:preview --silent) 51 | changelog="${changelog//$'\n'/'%0A'}" 52 | changelog="${changelog//$'\r'/'%0D'}" 53 | echo -e "set-output name=changelog::${changelog-}\n" 54 | echo -e "::set-output name=changelog::${changelog}\n" 55 | 56 | - name: Update Nightly TAG 57 | uses: richardsimko/update-tag@v1 58 | env: 59 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 60 | with: 61 | tag_name: nightly 62 | 63 | - name: Update Nightly Release 64 | uses: meeDamian/github-release@2.0 65 | env: 66 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 67 | with: 68 | token: ${{ secrets.GITHUB_TOKEN }} 69 | tag: nightly 70 | commitish: ${{ github.sha }} 71 | name: Nightly Release 72 | body: ${{ steps.generate_changelog.outputs.changelog }} 73 | draft: false 74 | prerelease: true 75 | files: > 76 | wppconnect-loader-nightly.tgz 77 | gzip: folders 78 | allow_override: true 79 | -------------------------------------------------------------------------------- /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | name: Publish 2 | 3 | on: 4 | push: 5 | tags: 6 | - 'v*' 7 | 8 | jobs: 9 | publish: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: Checkout 13 | uses: actions/checkout@v2 14 | with: 15 | fetch-depth: 0 16 | 17 | - name: Fetching tags 18 | run: git fetch --tags -f || true 19 | 20 | - name: Setup Node 21 | uses: actions/setup-node@v1 22 | with: 23 | node-version: 12.x 24 | registry-url: 'https://registry.npmjs.org' 25 | env: 26 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} 27 | 28 | - name: Get npm cache directory 29 | id: npm-cache 30 | run: | 31 | echo "::set-output name=dir::$(npm config get cache)" 32 | - name: Setup npm cache 33 | uses: actions/cache@v2 34 | with: 35 | path: ${{ steps.npm-cache.outputs.dir }} 36 | key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} 37 | restore-keys: | 38 | ${{ runner.os }}-node- 39 | 40 | - name: Install Dependencies 41 | run: npm ci || npm install 42 | env: 43 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} 44 | 45 | - name: Publish in NPM 46 | run: npm publish 47 | env: 48 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} 49 | 50 | - name: Generate Changelog 51 | id: generate_changelog 52 | run: | 53 | changelog=$(npm run changelog:last --silent) 54 | changelog="${changelog//$'\n'/'%0A'}" 55 | changelog="${changelog//$'\r'/'%0D'}" 56 | echo -e "set-output name=changelog::${changelog-}\n" 57 | echo -e "::set-output name=changelog::${changelog}\n" 58 | 59 | - name: Create Release 60 | id: create_release 61 | uses: actions/create-release@v1 62 | env: 63 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 64 | with: 65 | tag_name: ${{ github.ref }} 66 | release_name: ${{ github.ref }} 67 | body: ${{ steps.generate_changelog.outputs.changelog }} 68 | draft: false 69 | prerelease: false 70 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.tgz 2 | /dist 3 | /node_modules 4 | -------------------------------------------------------------------------------- /.husky/.gitignore: -------------------------------------------------------------------------------- 1 | _ 2 | -------------------------------------------------------------------------------- /.husky/commit-msg: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | . "$(dirname "$0")/_/husky.sh" 3 | 4 | npx --no-install commitlint --edit $1 5 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .* 2 | *.map 3 | *.tgz 4 | *.zip 5 | docs 6 | license-checker-config.json 7 | LICENSE.header 8 | src 9 | tsconfig.json 10 | typedoc.json 11 | webpack.config.js 12 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | docs 2 | dist -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true 3 | } 4 | -------------------------------------------------------------------------------- /.release-it.yml: -------------------------------------------------------------------------------- 1 | git: 2 | commitMessage: 'chore(release): v${version}' 3 | tagAnnotation: 'chore(release): v${version}' 4 | tagName: 'v${version}' 5 | 6 | hooks: 7 | after:bump: 8 | - 'npm run changelog:update' 9 | 10 | # automatic publish from github workflow 11 | npm: 12 | publish: false 13 | private: true 14 | registry: 'OMITTED' 15 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | // List of extensions which should be recommended for users of this workspace. 3 | "recommendations": ["dbaeumer.vscode-eslint", "esbenp.prettier-vscode"], 4 | // List of extensions recommended by VS Code that should not be recommended for users of this workspace. 5 | "unwantedRecommendations": [] 6 | } 7 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.eol": "\n", 3 | "[javascript]": { 4 | "editor.defaultFormatter": "esbenp.prettier-vscode" 5 | }, 6 | "[typescript]": { 7 | "editor.defaultFormatter": "esbenp.prettier-vscode" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## [1.0.5](https://github.com/wppconnect-team/wppconnect-loader/compare/v1.0.4...v1.0.5) (2021-07-09) 2 | 3 | 4 | ### Bug Fixes 5 | 6 | * Fixed .d.ts generation ([c0e7543](https://github.com/wppconnect-team/wppconnect-loader/commit/c0e75438ff62385fefc5f6528d7ff82e4e4a03fb)) 7 | 8 | 9 | 10 | ## [1.0.4](https://github.com/wppconnect-team/wppconnect-loader/compare/v1.0.3...v1.0.4) (2021-07-09) 11 | 12 | 13 | ### Bug Fixes 14 | 15 | * Fixed webpack variable name for WhatsApp web update ([ac9d531](https://github.com/wppconnect-team/wppconnect-loader/commit/ac9d53177f37c5749289ff10eeddbcb2b4104849)) 16 | 17 | 18 | 19 | ## [1.0.3](https://github.com/wppconnect-team/wppconnect-loader/compare/v1.0.2...v1.0.3) (2021-04-22) 20 | 21 | 22 | ### Bug Fixes 23 | 24 | * Fixed default generic return type ([c4e38f1](https://github.com/wppconnect-team/wppconnect-loader/commit/c4e38f19b04165ec1a5d52471157e7ea32d1112e)) 25 | 26 | 27 | 28 | ## [1.0.2](https://github.com/wppconnect-team/wppconnect-loader/compare/v1.0.1...v1.0.2) (2021-04-21) 29 | 30 | 31 | ### Bug Fixes 32 | 33 | * Fixed .d.ts files ([5c50b7b](https://github.com/wppconnect-team/wppconnect-loader/commit/5c50b7bb992d9dd05cd7efb14c2c40f5d9983f5c)) 34 | 35 | 36 | ### Features 37 | 38 | * Added generic return type ([30cddef](https://github.com/wppconnect-team/wppconnect-loader/commit/30cddef9130ba6072ebaf4ebb2994d8f1cd7aa40)) 39 | 40 | 41 | 42 | ## [1.0.1](https://github.com/wppconnect-team/wppconnect-loader/compare/v1.0.0...v1.0.1) (2021-03-30) 43 | 44 | 45 | ### Bug Fixes 46 | 47 | * Fixed searchModule return ([3ecdd1f](https://github.com/wppconnect-team/wppconnect-loader/commit/3ecdd1f13076ed0f1f552d595e04f7d150b0c4e0)) 48 | 49 | 50 | 51 | # 1.0.0 (2021-03-01) 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /LICENSE.header: -------------------------------------------------------------------------------- 1 | This file is part of WPPConnect. 2 | 3 | WPPConnect is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU Lesser General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | WPPConnect is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU Lesser General Public License for more details. 12 | 13 | You should have received a copy of the GNU Lesser General Public License 14 | along with WPPConnect. If not, see . -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | ### GNU LESSER GENERAL PUBLIC LICENSE 2 | 3 | Version 3, 29 June 2007 4 | 5 | Copyright (C) 2007 Free Software Foundation, Inc. 6 | 7 | 8 | Everyone is permitted to copy and distribute verbatim copies of this 9 | license document, but changing it is not allowed. 10 | 11 | This version of the GNU Lesser General Public License incorporates the 12 | terms and conditions of version 3 of the GNU General Public License, 13 | supplemented by the additional permissions listed below. 14 | 15 | #### 0. Additional Definitions. 16 | 17 | As used herein, "this License" refers to version 3 of the GNU Lesser 18 | General Public License, and the "GNU GPL" refers to version 3 of the 19 | GNU General Public License. 20 | 21 | "The Library" refers to a covered work governed by this License, other 22 | than an Application or a Combined Work as defined below. 23 | 24 | An "Application" is any work that makes use of an interface provided 25 | by the Library, but which is not otherwise based on the Library. 26 | Defining a subclass of a class defined by the Library is deemed a mode 27 | of using an interface provided by the Library. 28 | 29 | A "Combined Work" is a work produced by combining or linking an 30 | Application with the Library. The particular version of the Library 31 | with which the Combined Work was made is also called the "Linked 32 | Version". 33 | 34 | The "Minimal Corresponding Source" for a Combined Work means the 35 | Corresponding Source for the Combined Work, excluding any source code 36 | for portions of the Combined Work that, considered in isolation, are 37 | based on the Application, and not on the Linked Version. 38 | 39 | The "Corresponding Application Code" for a Combined Work means the 40 | object code and/or source code for the Application, including any data 41 | and utility programs needed for reproducing the Combined Work from the 42 | Application, but excluding the System Libraries of the Combined Work. 43 | 44 | #### 1. Exception to Section 3 of the GNU GPL. 45 | 46 | You may convey a covered work under sections 3 and 4 of this License 47 | without being bound by section 3 of the GNU GPL. 48 | 49 | #### 2. Conveying Modified Versions. 50 | 51 | If you modify a copy of the Library, and, in your modifications, a 52 | facility refers to a function or data to be supplied by an Application 53 | that uses the facility (other than as an argument passed when the 54 | facility is invoked), then you may convey a copy of the modified 55 | version: 56 | 57 | - a) under this License, provided that you make a good faith effort 58 | to ensure that, in the event an Application does not supply the 59 | function or data, the facility still operates, and performs 60 | whatever part of its purpose remains meaningful, or 61 | - b) under the GNU GPL, with none of the additional permissions of 62 | this License applicable to that copy. 63 | 64 | #### 3. Object Code Incorporating Material from Library Header Files. 65 | 66 | The object code form of an Application may incorporate material from a 67 | header file that is part of the Library. You may convey such object 68 | code under terms of your choice, provided that, if the incorporated 69 | material is not limited to numerical parameters, data structure 70 | layouts and accessors, or small macros, inline functions and templates 71 | (ten or fewer lines in length), you do both of the following: 72 | 73 | - a) Give prominent notice with each copy of the object code that 74 | the Library is used in it and that the Library and its use are 75 | covered by this License. 76 | - b) Accompany the object code with a copy of the GNU GPL and this 77 | license document. 78 | 79 | #### 4. Combined Works. 80 | 81 | You may convey a Combined Work under terms of your choice that, taken 82 | together, effectively do not restrict modification of the portions of 83 | the Library contained in the Combined Work and reverse engineering for 84 | debugging such modifications, if you also do each of the following: 85 | 86 | - a) Give prominent notice with each copy of the Combined Work that 87 | the Library is used in it and that the Library and its use are 88 | covered by this License. 89 | - b) Accompany the Combined Work with a copy of the GNU GPL and this 90 | license document. 91 | - c) For a Combined Work that displays copyright notices during 92 | execution, include the copyright notice for the Library among 93 | these notices, as well as a reference directing the user to the 94 | copies of the GNU GPL and this license document. 95 | - d) Do one of the following: 96 | - 0) Convey the Minimal Corresponding Source under the terms of 97 | this License, and the Corresponding Application Code in a form 98 | suitable for, and under terms that permit, the user to 99 | recombine or relink the Application with a modified version of 100 | the Linked Version to produce a modified Combined Work, in the 101 | manner specified by section 6 of the GNU GPL for conveying 102 | Corresponding Source. 103 | - 1) Use a suitable shared library mechanism for linking with 104 | the Library. A suitable mechanism is one that (a) uses at run 105 | time a copy of the Library already present on the user's 106 | computer system, and (b) will operate properly with a modified 107 | version of the Library that is interface-compatible with the 108 | Linked Version. 109 | - e) Provide Installation Information, but only if you would 110 | otherwise be required to provide such information under section 6 111 | of the GNU GPL, and only to the extent that such information is 112 | necessary to install and execute a modified version of the 113 | Combined Work produced by recombining or relinking the Application 114 | with a modified version of the Linked Version. (If you use option 115 | 4d0, the Installation Information must accompany the Minimal 116 | Corresponding Source and Corresponding Application Code. If you 117 | use option 4d1, you must provide the Installation Information in 118 | the manner specified by section 6 of the GNU GPL for conveying 119 | Corresponding Source.) 120 | 121 | #### 5. Combined Libraries. 122 | 123 | You may place library facilities that are a work based on the Library 124 | side by side in a single library together with other library 125 | facilities that are not Applications and are not covered by this 126 | License, and convey such a combined library under terms of your 127 | choice, if you do both of the following: 128 | 129 | - a) Accompany the combined library with a copy of the same work 130 | based on the Library, uncombined with any other library 131 | facilities, conveyed under the terms of this License. 132 | - b) Give prominent notice with the combined library that part of it 133 | is a work based on the Library, and explaining where to find the 134 | accompanying uncombined form of the same work. 135 | 136 | #### 6. Revised Versions of the GNU Lesser General Public License. 137 | 138 | The Free Software Foundation may publish revised and/or new versions 139 | of the GNU Lesser General Public License from time to time. Such new 140 | versions will be similar in spirit to the present version, but may 141 | differ in detail to address new problems or concerns. 142 | 143 | Each version is given a distinguishing version number. If the Library 144 | as you received it specifies that a certain numbered version of the 145 | GNU Lesser General Public License "or any later version" applies to 146 | it, you have the option of following the terms and conditions either 147 | of that published version or of any later version published by the 148 | Free Software Foundation. If the Library as you received it does not 149 | specify a version number of the GNU Lesser General Public License, you 150 | may choose any version of the GNU Lesser General Public License ever 151 | published by the Free Software Foundation. 152 | 153 | If the Library as you received it specifies that a proxy can decide 154 | whether future versions of the GNU Lesser General Public License shall 155 | apply, that proxy's public statement of acceptance of any version is 156 | permanent authorization for you to choose that version for the 157 | Library. 158 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WPPConnectLoader 📞 2 | 3 | > WPPConnectLoader is an open source project developed by the JavaScript community with the aim of exporting functions from Webpack modules 4 | 5 | ## Our online channels 6 | 7 | [![Discord](https://img.shields.io/discord/844351092758413353?color=blueviolet&label=Discord&logo=discord&style=flat)](https://discord.gg/JU5JGGKGNG) 8 | [![Telegram Group](https://img.shields.io/badge/Telegram-Group-32AFED?logo=telegram)](https://t.me/wppconnect) 9 | [![WhatsApp Group](https://img.shields.io/badge/WhatsApp-Group-25D366?logo=whatsapp)](https://chat.whatsapp.com/C1ChjyShl5cA7KvmtecF3L) 10 | [![YouTube](https://img.shields.io/youtube/channel/subscribers/UCD7J9LG08PmGQrF5IS7Yv9A?label=YouTube)](https://www.youtube.com/c/wppconnect) 11 | 12 | ## Usage 13 | ```js 14 | var WPPConnectLoader = require('@wppconnect-team/loader'); 15 | 16 | var loader = new WPPConnectLoader(); 17 | 18 | // Get module by id 19 | loader.get(moduleId); 20 | 21 | // Get module by search function 22 | loader.searchModule(m => m.default.MyFunctionTest); 23 | 24 | // Get module ID by search function 25 | loader.searchModuleId(m => m.default.MyFunctionTest); 26 | 27 | // Return a promise with resolved módule 28 | loader.waitForModule(m => m.default.MyFunctionTest); 29 | ``` 30 | -------------------------------------------------------------------------------- /license-checker-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "ignore": ["**/.*", "**/*.md", ".github"], 3 | "license": "LICENSE.header", 4 | "licenseFormats": { 5 | "js|ts": { 6 | "prepend": "/*", 7 | "append": " */", 8 | "eachLine": { 9 | "prepend": " * " 10 | } 11 | }, 12 | "dotfile": { 13 | "eachLine": { 14 | "prepend": "# " 15 | } 16 | } 17 | }, 18 | "trailingWhitespace": "TRIM" 19 | } 20 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@wppconnect-team/loader", 3 | "version": "1.0.5", 4 | "description": "", 5 | "main": "dist/loader.js", 6 | "types": "dist/loader.d.js", 7 | "scripts": { 8 | "changelog:last": "conventional-changelog -p angular -r 2", 9 | "changelog:preview": "conventional-changelog -p angular -u", 10 | "changelog:update": "conventional-changelog -p angular -i CHANGELOG.md -s", 11 | "compile:dev": "webpack --mode development && npm run generate-dts", 12 | "compile:prod": "webpack --mode production && npm run generate-dts", 13 | "compile:watch": "webpack --mode development --watch", 14 | "generate-dts": "dts-bundle-generator -o dist/loader.d.ts src/index.ts", 15 | "license:add": "license-check-and-add add", 16 | "license:check": "license-check-and-add check", 17 | "lint": "npx eslint -c .eslintrc.js --ext .ts src", 18 | "prepare": "husky install && npm run compile:prod", 19 | "release": "release-it", 20 | "serve:dev": "webpack serve --mode development", 21 | "serve:prod": "webpack serve --mode production", 22 | "serve:watch": "webpack serve --mode development --progress --watch" 23 | }, 24 | "config": { 25 | "commitizen": { 26 | "path": "./node_modules/cz-conventional-changelog" 27 | } 28 | }, 29 | "repository": { 30 | "type": "git", 31 | "url": "git+https://github.com/wppconnect-team/wppconnect-loader.git" 32 | }, 33 | "author": "wppconnect-team", 34 | "license": "LGPL-3.0-or-later", 35 | "bugs": { 36 | "url": "https://github.com/wppconnect-team/wppconnect-loader/issues" 37 | }, 38 | "homepage": "https://github.com/wppconnect-team/wppconnect-loader#readme", 39 | "devDependencies": { 40 | "@commitlint/cli": "^14.1.0", 41 | "@commitlint/config-angular": "^14.1.0", 42 | "@typescript-eslint/eslint-plugin": "^4.16.1", 43 | "@typescript-eslint/parser": "^4.16.1", 44 | "clean-webpack-plugin": "^4.0.0", 45 | "commitizen": "^4.2.3", 46 | "conventional-changelog-cli": "^2.1.1", 47 | "cz-conventional-changelog": "^3.3.0", 48 | "dts-bundle-generator": "^5.9.0", 49 | "eslint": "^7.21.0", 50 | "eslint-config-prettier": "^8.1.0", 51 | "eslint-plugin-prettier": "^4.0.0", 52 | "events": "^3.3.0", 53 | "husky": "^7.0.2", 54 | "license-check-and-add": "^4.0.2", 55 | "prettier": "^2.2.1", 56 | "release-it": "^14.4.1", 57 | "trim-newlines": "^4.0.2", 58 | "ts-loader": "^9.0.2", 59 | "typescript": "^4.2.2", 60 | "webpack": "^5.17.0", 61 | "webpack-cli": "^4.4.0", 62 | "webpack-dev-server": "^4.0.0" 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of WPPConnect. 3 | * 4 | * WPPConnect is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * WPPConnect is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with WPPConnect. If not, see . 16 | */ 17 | import WPPConnectLoader from './loader'; 18 | 19 | export default WPPConnectLoader; 20 | -------------------------------------------------------------------------------- /src/loader.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of WPPConnect. 3 | * 4 | * WPPConnect is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * WPPConnect is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with WPPConnect. If not, see . 16 | */ 17 | export interface Options { 18 | refreshModules?: boolean; 19 | startObserver?: boolean; 20 | chunkNames?: string[]; 21 | } 22 | 23 | export const defaultOptions: Options = { 24 | refreshModules: true, 25 | startObserver: true, 26 | chunkNames: ['webpackChunkbuild', 'webpackChunkwhatsapp_web_client'], 27 | }; 28 | 29 | type SearchModuleCondition = (module: any, moduleId?: string) => boolean; 30 | 31 | class WPPConnectLoader { 32 | private _options: Options; 33 | private _modules = new Map(); 34 | 35 | private mutationObserver: MutationObserver = null; 36 | 37 | /** 38 | * EventEmitter 39 | */ 40 | private _events = new Map(); 41 | 42 | public on(topic: string, cb: Function): boolean { 43 | const oldEvents = this._events.get(topic); 44 | if (this._events.has(topic)) { 45 | this._events.set(topic, [...oldEvents, cb]); 46 | } 47 | this._events.set(topic, [cb]); 48 | 49 | return true; 50 | } 51 | 52 | public off(topic: string, cb?: Function): boolean { 53 | if (!cb) { 54 | return this._events.delete(topic); 55 | } 56 | 57 | const oldEvents = this._events.get(topic); 58 | if (Array.isArray(oldEvents) && oldEvents.length) { 59 | const filtered = oldEvents.filter((l) => l !== cb); 60 | this._events.set(topic, filtered); 61 | return true; 62 | } 63 | 64 | return false; 65 | } 66 | protected emit(topic: string, ...args: any[]): void { 67 | const myListeners = this._events.get(topic); 68 | if (Array.isArray(myListeners) && myListeners.length) { 69 | myListeners.forEach((event) => { 70 | try { 71 | event.apply(this, args); 72 | } catch (error) {} 73 | }); 74 | } 75 | } 76 | 77 | constructor(options: Options = {}) { 78 | this._options = Object.assign({}, defaultOptions, options); 79 | 80 | if (this._options.refreshModules) { 81 | this.refreshModules(); 82 | } 83 | 84 | if (this._options.startObserver) { 85 | this.initObserver(); 86 | } 87 | } 88 | 89 | public initObserver(): void { 90 | if (this.mutationObserver) { 91 | return; 92 | } 93 | 94 | this.mutationObserver = new MutationObserver(async (mutations) => { 95 | // Wait all script to load 96 | const scripts = []; 97 | for (const m of mutations) { 98 | const addedNodes = Array.from(m.addedNodes) as HTMLScriptElement[]; 99 | for (const n of addedNodes) { 100 | if (n.nodeName !== 'SCRIPT') { 101 | continue; 102 | } 103 | scripts.push( 104 | new Promise((resolve) => { 105 | n.addEventListener('load', resolve); 106 | n.addEventListener('error', resolve); 107 | }) 108 | ); 109 | } 110 | } 111 | await Promise.all(scripts); 112 | 113 | // Update loaded modules 114 | if (scripts.length) { 115 | await this.refreshModules(); 116 | } 117 | }); 118 | 119 | // Start mutation observer 120 | this.mutationObserver.observe(document.documentElement, { 121 | childList: true, 122 | subtree: true, 123 | }); 124 | } 125 | 126 | public refreshModules(): Promise { 127 | const chunkNames = this._options.chunkNames || ['webpackChunkbuild']; 128 | 129 | const chunks: any[][] = []; 130 | for (const name of chunkNames) { 131 | const chunk = (window as any)[name] as any[]; 132 | if (!Array.isArray(chunk) || !chunk.length) { 133 | continue; 134 | } 135 | chunks.push(chunk); 136 | } 137 | 138 | if (!chunks.length) { 139 | return Promise.resolve(false); 140 | } 141 | 142 | const currentSize = this._modules.size; 143 | 144 | return new Promise((resolve) => { 145 | for (const chunk of chunks) { 146 | const id = Date.now(); 147 | chunk.push([ 148 | [id], 149 | {}, 150 | (moduleLoader: any) => { 151 | for (const moduleId in moduleLoader.m) { 152 | const module = moduleLoader(moduleId); 153 | this._modules.set(moduleId + '', module); 154 | } 155 | 156 | const hasNewElement = currentSize !== this._modules.size; 157 | this.emit('refresh', hasNewElement); 158 | resolve(hasNewElement); 159 | }, 160 | ]); 161 | } 162 | }); 163 | } 164 | 165 | /** 166 | * Return the webpack module id from a search function 167 | * @param condition Function for compare the modules 168 | * @param reverse Search in reverse order 169 | */ 170 | public searchModuleId( 171 | condition: SearchModuleCondition, 172 | reverse = false 173 | ): string { 174 | let ids = Array.from(this._modules.keys()); 175 | 176 | if (reverse) { 177 | ids = ids.reverse(); 178 | } 179 | 180 | for (const moduleId of ids) { 181 | try { 182 | const module = this._modules.get(moduleId); 183 | 184 | if (condition(module, moduleId)) { 185 | return moduleId; 186 | } 187 | } catch (error) { 188 | continue; 189 | } 190 | } 191 | return null; 192 | } 193 | 194 | /** 195 | * Return the webpack module from a search function 196 | * @param condition Function for compare the modules 197 | * @param reverse Search in reverse order 198 | */ 199 | public searchModule( 200 | condition: SearchModuleCondition, 201 | reverse = false 202 | ): T { 203 | const moduleId = this.searchModuleId(condition, reverse); 204 | 205 | if (moduleId) { 206 | return this._modules.get(moduleId); 207 | } 208 | 209 | return null; 210 | } 211 | 212 | /** 213 | * Return the webpack module from a search function, checking new loaded scripts 214 | * @param condition Function for compare the modules 215 | */ 216 | async waitForModule( 217 | condition: SearchModuleCondition, 218 | reverse = false, 219 | timeout: number | false = false 220 | ): Promise { 221 | const module = await this.searchModule(condition, reverse); 222 | 223 | if (module) { 224 | return module; 225 | } 226 | 227 | this.initObserver(); 228 | 229 | return new Promise((resolve, reject) => { 230 | const check = async (refreshed: boolean) => { 231 | if (!refreshed) { 232 | return; 233 | } 234 | const module = await this.searchModule(condition, reverse); 235 | 236 | if (module) { 237 | this.off('refresh', check); 238 | resolve(module); 239 | } 240 | }; 241 | 242 | this.on('refresh', check); 243 | 244 | if (timeout) { 245 | setTimeout(() => { 246 | reject(new Error('Timeout')); 247 | }, timeout); 248 | } 249 | }); 250 | } 251 | 252 | /** 253 | * Return the webpack module from ID 254 | * @param moduleId Webpack module ID 255 | */ 256 | public get(moduleId: string): T { 257 | return this._modules.get(moduleId + ''); 258 | } 259 | 260 | public forEach( 261 | callbackfn: (value: any, key: string, map: Map) => void 262 | ): void { 263 | return this._modules.forEach(callbackfn, this); 264 | } 265 | 266 | public get size(): number { 267 | return this._modules.size; 268 | } 269 | 270 | public dispose(): void { 271 | this.mutationObserver.disconnect(); 272 | this._modules.clear(); 273 | this._events.clear(); 274 | } 275 | } 276 | 277 | export default WPPConnectLoader; 278 | -------------------------------------------------------------------------------- /src/types/webpack.d.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of WPPConnect. 3 | * 4 | * WPPConnect is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * WPPConnect is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with WPPConnect. If not, see . 16 | */ 17 | type ModuleId = string | number; 18 | 19 | interface Module { 20 | exports: any; 21 | i: string; 22 | l: boolean; 23 | } 24 | 25 | interface ModuleMap { 26 | [key: string]: Module; 27 | } 28 | 29 | interface webpackChunkbuildModules { 30 | [key: string]: ( 31 | module: any, 32 | exports: any, 33 | require: { 34 | c: ModuleMap; 35 | [key: string]: any; 36 | } 37 | ) => void; 38 | } 39 | 40 | interface Window { 41 | webpackChunkbuild?: Array<[Array, webpackChunkbuildModules, any]>; 42 | } 43 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "lib": ["es2018", "dom"], 4 | "module": "CommonJS", 5 | "moduleResolution": "node", 6 | "noImplicitAny": true, 7 | "outDir": "./dist/", 8 | "sourceMap": true, 9 | "target": "es2018", 10 | "typeRoots": ["node_modules/@types"], 11 | "types": ["node", "./src/types/webpack"] 12 | }, 13 | "include": ["./src/**/*.ts", "./test/**/*.ts"] 14 | } 15 | -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of WPPConnect. 3 | * 4 | * WPPConnect is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * WPPConnect is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with WPPConnect. If not, see . 16 | */ 17 | /* eslint-disable @typescript-eslint/no-var-requires */ 18 | 19 | const path = require('path'); 20 | const { CleanWebpackPlugin } = require('clean-webpack-plugin'); 21 | 22 | const config = { 23 | entry: './src/index.ts', 24 | output: { 25 | library: 'WPPConnectLoader', 26 | // libraryTarget: 'var', 27 | libraryTarget: 'umd', 28 | // umdNamedDefine: true, 29 | // libraryExport: 'default', 30 | filename: 'loader.js', 31 | path: path.resolve(__dirname, 'dist'), 32 | }, 33 | resolve: { 34 | extensions: ['.ts', '.js'], 35 | }, 36 | module: { 37 | rules: [ 38 | { 39 | test: /\.ts$/, 40 | use: 'ts-loader', 41 | exclude: /node_modules/, 42 | }, 43 | ], 44 | }, 45 | plugins: [new CleanWebpackPlugin()], 46 | }; 47 | 48 | module.exports = (env, argv) => { 49 | if (argv.mode === 'development') { 50 | config.devtool = 'inline-source-map'; 51 | } 52 | 53 | return config; 54 | }; 55 | --------------------------------------------------------------------------------