@homebridge-plugins/homebridge-sharkiq 1.3.2

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.
Files changed (75) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/LICENSE +176 -0
  3. package/README.md +92 -0
  4. package/config.schema.json +114 -0
  5. package/dist/config.d.ts +7 -0
  6. package/dist/config.d.ts.map +1 -0
  7. package/dist/config.js +131 -0
  8. package/dist/config.js.map +1 -0
  9. package/dist/homebridge-ui/public/index.html +201 -0
  10. package/dist/homebridge-ui/server.d.ts +2 -0
  11. package/dist/homebridge-ui/server.d.ts.map +1 -0
  12. package/dist/homebridge-ui/server.js +47 -0
  13. package/dist/homebridge-ui/server.js.map +1 -0
  14. package/dist/index.d.ts +4 -0
  15. package/dist/index.d.ts.map +1 -0
  16. package/dist/index.js +7 -0
  17. package/dist/index.js.map +1 -0
  18. package/dist/login.d.ts +16 -0
  19. package/dist/login.d.ts.map +1 -0
  20. package/dist/login.js +242 -0
  21. package/dist/login.js.map +1 -0
  22. package/dist/platform.d.ts +16 -0
  23. package/dist/platform.d.ts.map +1 -0
  24. package/dist/platform.js +118 -0
  25. package/dist/platform.js.map +1 -0
  26. package/dist/platformAccessory.d.ts +29 -0
  27. package/dist/platformAccessory.d.ts.map +1 -0
  28. package/dist/platformAccessory.js +285 -0
  29. package/dist/platformAccessory.js.map +1 -0
  30. package/dist/settings.d.ts +3 -0
  31. package/dist/settings.d.ts.map +1 -0
  32. package/dist/settings.js +3 -0
  33. package/dist/settings.js.map +1 -0
  34. package/dist/sharkiq-js/ayla_api.d.ts +39 -0
  35. package/dist/sharkiq-js/ayla_api.d.ts.map +1 -0
  36. package/dist/sharkiq-js/ayla_api.js +289 -0
  37. package/dist/sharkiq-js/ayla_api.js.map +1 -0
  38. package/dist/sharkiq-js/const.d.ts +22 -0
  39. package/dist/sharkiq-js/const.d.ts.map +1 -0
  40. package/dist/sharkiq-js/const.js +23 -0
  41. package/dist/sharkiq-js/const.js.map +1 -0
  42. package/dist/sharkiq-js/properties.d.ts +52 -0
  43. package/dist/sharkiq-js/properties.d.ts.map +1 -0
  44. package/dist/sharkiq-js/properties.js +56 -0
  45. package/dist/sharkiq-js/properties.js.map +1 -0
  46. package/dist/sharkiq-js/sharkiq.d.ts +59 -0
  47. package/dist/sharkiq-js/sharkiq.d.ts.map +1 -0
  48. package/dist/sharkiq-js/sharkiq.js +359 -0
  49. package/dist/sharkiq-js/sharkiq.js.map +1 -0
  50. package/dist/type.d.ts +12 -0
  51. package/dist/type.d.ts.map +1 -0
  52. package/dist/type.js +2 -0
  53. package/dist/type.js.map +1 -0
  54. package/dist/utils.d.ts +10 -0
  55. package/dist/utils.d.ts.map +1 -0
  56. package/dist/utils.js +35 -0
  57. package/dist/utils.js.map +1 -0
  58. package/docs/.nojekyll +1 -0
  59. package/docs/assets/dmt/dmt-component-data.js +1 -0
  60. package/docs/assets/dmt/dmt-components.css +20 -0
  61. package/docs/assets/dmt/dmt-components.js +67 -0
  62. package/docs/assets/dmt/dmt-search.cmp +0 -0
  63. package/docs/assets/dmt/dmt-theme.css +1 -0
  64. package/docs/assets/hierarchy.js +1 -0
  65. package/docs/assets/highlight.css +57 -0
  66. package/docs/assets/icons.js +18 -0
  67. package/docs/assets/icons.svg +1 -0
  68. package/docs/assets/main.js +60 -0
  69. package/docs/assets/style.css +1611 -0
  70. package/docs/functions/default.html +2 -0
  71. package/docs/index.html +50 -0
  72. package/docs/modules.html +2 -0
  73. package/eslint.config.js +49 -0
  74. package/package.json +87 -0
  75. package/typedoc.json +21 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,12 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file. This project uses [Semantic Versioning](https://semver.org/)
4
+
5
+ ## [1.4.0](https://github.com/homebridge-plugins/homebridge-sharkiq/releases/tag/v1.4.0) (2025-01-25)
6
+
7
+ ### What's Changes
8
+ - Convert to ESModule
9
+ - Fix JSON parsing errors in SharkIQ API responses [#44](https://github.com/homebridge-plugins/homebridge-sharkiq/pull/44) [@mmenanno](https://github.com/mmenanno)
10
+ - Housekeeping and updated dependencies.
11
+
12
+ **Full Changelog**: https://github.com/homebridge-plugins/homebridge-sharkiq/compare/v1.3.2...v1.4.0
package/LICENSE ADDED
@@ -0,0 +1,176 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
package/README.md ADDED
@@ -0,0 +1,92 @@
1
+ <span align="center">
2
+
3
+ # Homebridge Shark Clean Vacuum Plugin
4
+ [![verified-by-homebridge](https://badgen.net/badge/homebridge/verified/purple)](https://github.com/homebridge/homebridge/wiki/Verified-Plugins)
5
+ [![npm](https://badgen.net/npm/dt/homebridge-sharkiq?color=purple)](https://www.npmjs.com/package/homebridge-sharkiq)
6
+ [![npm](https://badgen.net/npm/v/homebridge-sharkiq?color=purple)](https://www.npmjs.com/package/homebridge-sharkiq)
7
+
8
+ </span>
9
+
10
+ A new homebridge plugin for SharkIQ Vacuums.
11
+
12
+ Contributions are always welcome. I used the [sharkiq](https://github.com/JeffResc/sharkiq/) python module as a reference for creating the javascript wrapper to control SharkIQ Vacuums.
13
+
14
+ This plguin has only been tested on the `UR250BEXUS` model.
15
+
16
+ The fastest way to get community support (not for bugs) is to join the [Homebridge Discord server](https://discord.gg/kqNCe2D) and chat in the #sharkiq channel.
17
+
18
+ ## Install and Setup
19
+
20
+ ### Step 1.
21
+
22
+ Run `npm install -g homebridge-sharkiq`
23
+
24
+ ### Step 2.
25
+
26
+ Configure Homebridge. The config file for SharkIQ should include:
27
+ ```json
28
+ {
29
+ "platforms": [
30
+ {
31
+ "name": "SharkIQ",
32
+ "platform": "SharkIQ",
33
+ "email": "[Shark Clean Account Email]",
34
+ "password": "[Shark Clean Account Password]",
35
+ "oAuthCode": "[Optional. Use for manually obtaining credentials]",
36
+ "vacuums": [
37
+ "[Shark Vacuum DSN]",
38
+ "..."
39
+ ],
40
+ "europe": false,
41
+ "invertDockedStatus": false,
42
+ "dockedUpdateInterval": 30000
43
+ }
44
+ ]
45
+ }
46
+ ```
47
+
48
+
49
+ # Important
50
+
51
+ You may be prompted to use the manual OAuth login method. In order to use the manual OAuth login method, you must remove the email and password values in your configuration first.
52
+
53
+ #
54
+
55
+ The email and password is your Shark Clean account you used to setup the vacuum. The Vacuums array is a list of your vacuum's device serial numbers (DSN). If you only have one vacuum, just include the one's DSN. The DSN(s) can be found in the SharkClean mobile app.
56
+
57
+ If you would like to manually obtain your Shark Clean credentials without using your email and password, you can obtain a OAuth code instead. Refer to the `OAuth Code Login Method` section.
58
+
59
+ The Vacuums array is a list of your vacuum's device serial numbers (DSN). If you only have one vacuum, just include the one's DSN. The DSN(s) can be found in the SharkClean mobile app.
60
+
61
+ If you are in Europe, set the `europe` config value to `true`. SharkClean has separate servers for the U.S. and Europe. The default value is `false`, which connects to the U.S. server.
62
+
63
+ The default interval between updating the docked status is 30 seconds (30000 ms). To change the docked status interval, add `dockedUpdateInterval` to your config. Value is in milliseconds. If the interval is too low, you have the risk of your account being rate limited.
64
+
65
+ ## Features
66
+
67
+ - Be able to turn on and off the vacuum
68
+ - Set the power mode of the vacuum and change it while running
69
+ - Sensor for if the vacuum is docked or not
70
+ - The sensor will display as "opened" when the vacuum is docked and "closed" when the vacuum is not docked
71
+ - Set `invertDockedStatus` to `true` to display as "closed" when the vacuum is docked and "opened" when the vacuum is not docked
72
+ - Pause switch for pausing the vacuum while it's running
73
+
74
+ ### OAuth Code Login Method
75
+ The OAuth Code value is for creating and storing the login for the plugin. Here is how to sign in with this method.
76
+ 1. Run Homebridge with the latest plugin version.
77
+ 2. Open the Homebridge logs
78
+ 3. Open the URL in the console printed by homebridge-sharkiq. Safari will not work due to the way Safari handles the results of the login
79
+ 4. Before you login, open up developer tools in your browser (inspect element), and navigate to the network tab
80
+ 5. Enter your login info, and press continue
81
+ 6. Open the request with the uri of `/authorize/resume` that shows up and view the headers
82
+ 7. Search `com.sharkninja.shark` in the headers
83
+ 8. Copy the code in between `code=` and `&`. for example in `com.sharkninja.shark://login.sharkninja.com/ios/com.sharkninja.shark/callback?code=abcdefghijkl&state=`, `abcdefghijkl` is the code that needs to be copied
84
+ 9. Open your Homebridge configuration, and paste the `code` value in the OAuth Code config option
85
+ 10. Restart Homebridge
86
+
87
+ ## Notes
88
+
89
+ Contributions would be very helpful to help this Homebridge plugin stay maintained and up to date. If you have any problems, please create an issue.
90
+
91
+ ## Useful Links
92
+ - [SharkIQ Python](https://github.com/JeffResc/sharkiq/)
@@ -0,0 +1,114 @@
1
+ {
2
+ "pluginAlias": "SharkIQ",
3
+ "pluginType": "platform",
4
+ "singular": true,
5
+ "customUi": true,
6
+ "customUiPath": "./dist/homebridge-ui",
7
+ "schema": {
8
+ "type": "object",
9
+ "properties": {
10
+ "name": {
11
+ "title": "Name",
12
+ "type": "string",
13
+ "default": "SharkIQ"
14
+ },
15
+ "email": {
16
+ "title": "SharkClean Account Email",
17
+ "type": "string",
18
+ "required": false
19
+ },
20
+ "password": {
21
+ "title": "SharkClean Account Password",
22
+ "type": "string",
23
+ "required": false
24
+ },
25
+ "oAuthCode": {
26
+ "title": "SharkClean OAuth Code",
27
+ "type": "string",
28
+ "required": false
29
+ },
30
+ "vacuums": {
31
+ "title": "SharkClean Vacuum Devicess",
32
+ "type": "array",
33
+ "required": true,
34
+ "items": {
35
+ "title": "SharkClean DSN",
36
+ "type": "string"
37
+ }
38
+ },
39
+ "europe": {
40
+ "title": "SharkClean European Server",
41
+ "type": "boolean",
42
+ "required": false,
43
+ "default": false
44
+ },
45
+ "invertDockedStatus": {
46
+ "title": "Invert Vacuum Docked Status",
47
+ "type": "boolean",
48
+ "required": false,
49
+ "default": false
50
+ },
51
+ "dockedUpdateInterval": {
52
+ "title": "Docked Update Interval",
53
+ "type": "integer",
54
+ "required": false,
55
+ "default": 30000
56
+ }
57
+ }
58
+ },
59
+ "layout": [
60
+ {
61
+ "type": "fieldset",
62
+ "title": "SharkIQ Account Info",
63
+ "expandable": true,
64
+ "expanded": true,
65
+ "items": [
66
+ "email",
67
+ "password"
68
+ ]
69
+ },
70
+ {
71
+ "type": "fieldset",
72
+ "title": "SharkIQ OAuth Info",
73
+ "expandable": true,
74
+ "expanded": false,
75
+ "items": [
76
+ {
77
+ "type": "help",
78
+ "helpvalue": "<h5>OAuth Code</h5><em class='primary-text'>Enter the OAuth code you received from SharkClean. This is used for manually obtaining credentials.</em>"
79
+ },
80
+ "oAuthCode"
81
+ ]
82
+ },
83
+ {
84
+ "type": "fieldset",
85
+ "title": "Vacuum Settings",
86
+ "expandable": true,
87
+ "expanded": true,
88
+ "items": [
89
+ {
90
+ "type": "help",
91
+ "helpvalue": "<h5>Vacuums</h5><em class='primary-text'>Enter SharkClean DSN(s) you want to add to HomeKit.</em>"
92
+ },
93
+ {
94
+ "key": "vacuums",
95
+ "notitle": true,
96
+ "type": "tabarray",
97
+ "title": "{{ 'New Vacuum' }}",
98
+ "expandable": true,
99
+ "expanded": false,
100
+ "orderable": true,
101
+ "items": [
102
+ {
103
+ "key": "vacuums[]",
104
+ "title": "{{ value || 'New DSN' }}"
105
+ }
106
+ ]
107
+ },
108
+ "europe",
109
+ "invertDockedStatus",
110
+ "dockedUpdateInterval"
111
+ ]
112
+ }
113
+ ]
114
+ }
@@ -0,0 +1,7 @@
1
+ import type { AuthData, OAuthData } from './type';
2
+ export declare function getAuthData(authFilePath: string): Promise<AuthData>;
3
+ export declare function setAuthData(authFilePath: string, data: AuthData): Promise<void>;
4
+ export declare function getOAuthData(oAuthFilePath: string): Promise<OAuthData>;
5
+ export declare function removeFile(filePath: string): Promise<void>;
6
+ export declare function generateURL(oauth_file_path: string): Promise<string>;
7
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAA;AAOjD,wBAAsB,WAAW,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAQzE;AAiCD,wBAAsB,WAAW,CAAC,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAMrF;AAsCD,wBAAsB,YAAY,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAQ5E;AAUD,wBAAsB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAMhE;AAED,wBAAsB,WAAW,CAAC,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CA6B1E"}
package/dist/config.js ADDED
@@ -0,0 +1,131 @@
1
+ import crypto from 'node:crypto';
2
+ import { promises as fs } from 'node:fs';
3
+ import { global_vars } from './sharkiq-js/const.js';
4
+ export async function getAuthData(authFilePath) {
5
+ try {
6
+ const data = await fs.readFile(authFilePath, 'utf8');
7
+ const authData = JSON.parse(data);
8
+ return authData;
9
+ }
10
+ catch (error) {
11
+ return Promise.reject(new Error(`Error reading OAuth data: ${error}`));
12
+ }
13
+ }
14
+ // export async function getAuthData(configPath: string): Promise<AuthData> {
15
+ // try {
16
+ // const data = await fs.readFile(configPath, 'utf8');
17
+ // const currentConfig = JSON.parse(data);
18
+ // if (!Array.isArray(currentConfig.platforms)) {
19
+ // return Promise.reject('No platforms array found in config');
20
+ // }
21
+ // const pluginConfig = currentConfig.platforms.find((x: { platform: string }) => x.platform === PLATFORM_NAME);
22
+ // if (!pluginConfig) {
23
+ // return Promise.reject(`${PLATFORM_NAME} platform not found in config`);
24
+ // }
25
+ // if (typeof pluginConfig.credentials !== 'object') {
26
+ // return Promise.reject(`No credentials object found in ${PLATFORM_NAME} platform config`);
27
+ // }
28
+ // if (typeof pluginConfig.credentials.access_token !== 'string' ||
29
+ // typeof pluginConfig.credentials.refresh_token !== 'string' ||
30
+ // typeof pluginConfig.credentials.expiration !== 'string') {
31
+ // return Promise.reject('Invalid types found in credentials object');
32
+ // }
33
+ // return pluginConfig.credentials;
34
+ // } catch (error) {
35
+ // return Promise.reject('Error reading auth data from config: ' + error);
36
+ // }
37
+ // }
38
+ export async function setAuthData(authFilePath, data) {
39
+ try {
40
+ await fs.writeFile(authFilePath, JSON.stringify(data, null, 4), 'utf8');
41
+ }
42
+ catch (error) {
43
+ return Promise.reject(new Error(`Error writing auth data: ${error}`));
44
+ }
45
+ }
46
+ // export async function setAuthData(configPath: string, data: AuthData): Promise<void> {
47
+ // try {
48
+ // if (!data) {
49
+ // return Promise.reject('No data provided');
50
+ // }
51
+ // const currentConfigData = await fs.readFile(configPath, 'utf8');
52
+ // const currentConfig = JSON.parse(currentConfigData);
53
+ // if (!Array.isArray(currentConfig.platforms)) {
54
+ // return Promise.reject('No platforms array found in config');
55
+ // }
56
+ // const pluginConfig = currentConfig.platforms.find((x: { platform: string }) => x.platform === PLATFORM_NAME);
57
+ // if (!pluginConfig) {
58
+ // return Promise.reject('No platform found in config');
59
+ // }
60
+ // if (typeof pluginConfig.credentials !== 'object') {
61
+ // pluginConfig.credentials = {};
62
+ // }
63
+ // pluginConfig.credentials.access_token = data.access_token;
64
+ // pluginConfig.credentials.refresh_token = data.refresh_token;
65
+ // pluginConfig.credentials.expiration = data.expiration;
66
+ // try {
67
+ // await fs.writeFile(configPath, JSON.stringify(currentConfig, null, 4), 'utf8');
68
+ // } catch (error) {
69
+ // return Promise.reject(`${error}`);
70
+ // }
71
+ // } catch (error) {
72
+ // return Promise.reject('Error writing auth data to config: ' + error);
73
+ // }
74
+ // }
75
+ export async function getOAuthData(oAuthFilePath) {
76
+ try {
77
+ const data = await fs.readFile(oAuthFilePath, 'utf8');
78
+ const oAuthData = JSON.parse(data);
79
+ return oAuthData;
80
+ }
81
+ catch (error) {
82
+ return Promise.reject(new Error(`Error reading OAuth data: ${error}`));
83
+ }
84
+ }
85
+ async function setOAuthData(oAuthFilePath, data) {
86
+ try {
87
+ await fs.writeFile(oAuthFilePath, JSON.stringify(data, null, 4), 'utf8');
88
+ }
89
+ catch (error) {
90
+ return Promise.reject(new Error(`Error writing OAuth data: ${error}`));
91
+ }
92
+ }
93
+ export async function removeFile(filePath) {
94
+ try {
95
+ await fs.unlink(filePath);
96
+ }
97
+ catch (error) {
98
+ return Promise.reject(new Error(`Error removing file: ${error}`));
99
+ }
100
+ }
101
+ export async function generateURL(oauth_file_path) {
102
+ const state = generateRandomString(43);
103
+ const code_verify = generateRandomString(43);
104
+ const code_challenge = crypto.createHash('sha256').update(code_verify).digest('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
105
+ const oAuthData = {
106
+ state,
107
+ code_verify,
108
+ code_challenge,
109
+ };
110
+ try {
111
+ await setOAuthData(oauth_file_path, oAuthData);
112
+ const url = `${global_vars.OAUTH.AUTH_URL}?response_type=code`
113
+ + `&client_id=${encodeURIComponent(global_vars.OAUTH.CLIENT_ID)}&state=${encodeURIComponent(oAuthData.state)}&scope=${encodeURIComponent(global_vars.OAUTH.SCOPES)}&redirect_uri=${encodeURIComponent(global_vars.OAUTH.REDIRECT_URI)}&code_challenge=${encodeURIComponent(oAuthData.code_challenge)}&code_challenge_method=S256`
114
+ + `&ui_locales=en`
115
+ + `&auth0Client=${global_vars.OAUTH.AUTH0_CLIENT}`;
116
+ return url;
117
+ }
118
+ catch (error) {
119
+ return Promise.reject(new Error(`Error generating Shark login URL: ${error}`));
120
+ }
121
+ }
122
+ function generateRandomString(length) {
123
+ const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
124
+ let result = '';
125
+ for (let i = 0; i < length; i++) {
126
+ const randomIndex = Math.floor(Math.random() * characters.length);
127
+ result += characters.charAt(randomIndex);
128
+ }
129
+ return result;
130
+ }
131
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAEA,OAAO,MAAM,MAAM,aAAa,CAAA;AAChC,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAA;AAExC,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAEnD,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,YAAoB;IACpD,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC,CAAA;QACpD,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;QACjC,OAAO,QAAQ,CAAA;IACjB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,6BAA6B,KAAK,EAAE,CAAC,CAAC,CAAA;IACxE,CAAC;AACH,CAAC;AAED,6EAA6E;AAC7E,U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