mlcl 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.
Files changed (195) hide show
  1. package/.eslintignore +31 -0
  2. package/.eslintrc.json +54 -0
  3. package/LICENSE +200 -0
  4. package/README.md +101 -0
  5. package/babel.config.json +10 -0
  6. package/build/API/authorization.js +107 -0
  7. package/build/API/client.js +11 -0
  8. package/build/API/index.js +8 -0
  9. package/build/API/molecule/index.js +11 -0
  10. package/build/API/molecule/types.js +6 -0
  11. package/build/API/resource/device/index.js +12 -0
  12. package/build/API/resource/device/types.js +6 -0
  13. package/build/API/resource/device/utilities/confirmSshKey.js +20 -0
  14. package/build/API/resource/device/utilities/index.js +7 -0
  15. package/build/API/resource/device/utilities/sendSshKey.js +64 -0
  16. package/build/API/resource/index.js +10 -0
  17. package/build/API/resource/molecule/index.js +12 -0
  18. package/build/API/resource/molecule/types.js +6 -0
  19. package/build/API/resource/molecule/utilities/getPlan.js +15 -0
  20. package/build/API/resource/molecule/utilities/index.js +6 -0
  21. package/build/API/resource/payment/index.js +9 -0
  22. package/build/API/resource/payment/plans.js +28 -0
  23. package/build/API/resource/payment/platform.js +7 -0
  24. package/build/API/resource/payment/platforms/apple/index.js +21 -0
  25. package/build/API/resource/payment/platforms/apple/plans/appleMonthly.js +17 -0
  26. package/build/API/resource/payment/platforms/apple/plans/appleYearly.js +18 -0
  27. package/build/API/resource/payment/platforms/apple/plans/index.js +7 -0
  28. package/build/API/resource/payment/platforms/google/index.js +21 -0
  29. package/build/API/resource/payment/platforms/google/plans/googleMonthly.js +17 -0
  30. package/build/API/resource/payment/platforms/google/plans/googleYearly.js +18 -0
  31. package/build/API/resource/payment/platforms/google/plans/index.js +7 -0
  32. package/build/API/resource/payment/platforms/index.js +8 -0
  33. package/build/API/resource/payment/platforms/stripe/index.js +25 -0
  34. package/build/API/resource/payment/platforms/stripe/plans/index.js +11 -0
  35. package/build/API/resource/payment/platforms/stripe/plans/stripeBusinessMolecule.js +21 -0
  36. package/build/API/resource/payment/platforms/stripe/plans/stripeMonthly.js +18 -0
  37. package/build/API/resource/payment/platforms/stripe/plans/stripeMonthlyMolecule.js +18 -0
  38. package/build/API/resource/payment/platforms/stripe/plans/stripeSingleUseMolecule.js +19 -0
  39. package/build/API/resource/payment/platforms/stripe/plans/stripeUnlimitedUseMolecule.js +19 -0
  40. package/build/API/resource/payment/platforms/stripe/plans/stripeYearly.js +19 -0
  41. package/build/API/resource/payment/types.js +6 -0
  42. package/build/API/resource/types.js +6 -0
  43. package/build/API/resource/user/index.js +15 -0
  44. package/build/API/resource/user/types.js +6 -0
  45. package/build/API/resource/user/utilities/getPlan.js +12 -0
  46. package/build/API/resource/user/utilities/index.js +7 -0
  47. package/build/API/resource/user/utilities/logIn.js +60 -0
  48. package/build/cli.js +15 -0
  49. package/build/commands/add-ssh-key.js +24 -0
  50. package/build/commands/buy.js +70 -0
  51. package/build/commands/clone.js +329 -0
  52. package/build/commands/index.js +17 -0
  53. package/build/commands/info.js +33 -0
  54. package/build/commands/login.js +20 -0
  55. package/build/commands/logout.js +23 -0
  56. package/build/commands/molecule/index.js +11 -0
  57. package/build/commands/molecule/types.js +6 -0
  58. package/build/commands/remove-ssh-key.js +36 -0
  59. package/build/commands/select.js +98 -0
  60. package/build/commands/set-api-key.js +73 -0
  61. package/build/commands/subscribe.js +74 -0
  62. package/build/commands/unsubscribe.js +59 -0
  63. package/build/commands/utilities/asyncExec.js +6 -0
  64. package/build/commands/utilities/branchExists.js +13 -0
  65. package/build/commands/utilities/branchExistsSync.js +12 -0
  66. package/build/commands/utilities/checkoutSelectionBranch.js +49 -0
  67. package/build/commands/utilities/cherryPick.js +20 -0
  68. package/build/commands/utilities/cloneRepo.js +9 -0
  69. package/build/commands/utilities/convertNpmToYarn.js +60 -0
  70. package/build/commands/utilities/convertTypeDocToJSDoc.js +51 -0
  71. package/build/commands/utilities/convertTypeScriptToJavaScript.js +451 -0
  72. package/build/commands/utilities/enableMergeDrivers.js +50 -0
  73. package/build/commands/utilities/getCurrentBranch.js +11 -0
  74. package/build/commands/utilities/getCurrentBranchSync.js +7 -0
  75. package/build/commands/utilities/getRepoRootPath.js +7 -0
  76. package/build/commands/utilities/getRepoRootPathSync.js +13 -0
  77. package/build/commands/utilities/index.js +16 -0
  78. package/build/commands/utilities/npm-to-yarn.js +41 -0
  79. package/build/commands/utilities/ts-to-js.js +344 -0
  80. package/build/commands/version.js +14 -0
  81. package/build/commands/x-merge-json.js +33 -0
  82. package/build/config.js +5 -0
  83. package/build/environment.js +80 -0
  84. package/build/index.js +23 -0
  85. package/build/logger.js +12 -0
  86. package/build/pkg.js +5 -0
  87. package/build/repoConfig copy.js +5 -0
  88. package/build/repoConfig.js +5 -0
  89. package/build/types/global.js +6 -0
  90. package/build/types/index.js +6 -0
  91. package/build/userConfig.js +5 -0
  92. package/build/utilities/__tests__/getErrorMessage.js +26 -0
  93. package/build/utilities/__tests__/timeAgo.js +39 -0
  94. package/build/utilities/checkVersion.js +29 -0
  95. package/build/utilities/getErrorMessage.js +15 -0
  96. package/build/utilities/index.js +13 -0
  97. package/build/utilities/readConfig.js +19 -0
  98. package/build/utilities/readRepoConfig copy.js +20 -0
  99. package/build/utilities/readRepoConfig.js +19 -0
  100. package/build/utilities/readUserConfig.js +20 -0
  101. package/build/utilities/synchronizeUserConfig.js +25 -0
  102. package/build/utilities/timeAgo.js +42 -0
  103. package/build/utilities/userLoggedIn.js +24 -0
  104. package/build/utilities/writeConfig.js +8 -0
  105. package/build/utilities/writeRepoConfig copy.js +9 -0
  106. package/build/utilities/writeRepoConfig.js +10 -0
  107. package/build/utilities/writeUserConfig.js +11 -0
  108. package/jest.config.json +11 -0
  109. package/package.json +56 -0
  110. package/src/API/authorization.ts +143 -0
  111. package/src/API/client.ts +12 -0
  112. package/src/API/index.ts +10 -0
  113. package/src/API/resource/device/index.ts +27 -0
  114. package/src/API/resource/device/types.ts +80 -0
  115. package/src/API/resource/device/utilities/confirmSshKey.ts +25 -0
  116. package/src/API/resource/device/utilities/index.ts +8 -0
  117. package/src/API/resource/device/utilities/sendSshKey.ts +80 -0
  118. package/src/API/resource/index.ts +12 -0
  119. package/src/API/resource/molecule/index.ts +30 -0
  120. package/src/API/resource/molecule/types.ts +332 -0
  121. package/src/API/resource/molecule/utilities/getPlan.ts +21 -0
  122. package/src/API/resource/molecule/utilities/index.ts +7 -0
  123. package/src/API/resource/payment/index.ts +12 -0
  124. package/src/API/resource/payment/plans.ts +32 -0
  125. package/src/API/resource/payment/platform.ts +11 -0
  126. package/src/API/resource/payment/platforms/apple/index.ts +25 -0
  127. package/src/API/resource/payment/platforms/apple/plans/appleMonthly.ts +19 -0
  128. package/src/API/resource/payment/platforms/apple/plans/appleYearly.ts +20 -0
  129. package/src/API/resource/payment/platforms/apple/plans/index.ts +9 -0
  130. package/src/API/resource/payment/platforms/google/index.ts +25 -0
  131. package/src/API/resource/payment/platforms/google/plans/googleMonthly.ts +19 -0
  132. package/src/API/resource/payment/platforms/google/plans/googleYearly.ts +20 -0
  133. package/src/API/resource/payment/platforms/google/plans/index.ts +9 -0
  134. package/src/API/resource/payment/platforms/index.ts +10 -0
  135. package/src/API/resource/payment/platforms/stripe/index.ts +29 -0
  136. package/src/API/resource/payment/platforms/stripe/plans/index.ts +12 -0
  137. package/src/API/resource/payment/platforms/stripe/plans/stripeBusinessMolecule.ts +23 -0
  138. package/src/API/resource/payment/platforms/stripe/plans/stripeMonthly.ts +20 -0
  139. package/src/API/resource/payment/platforms/stripe/plans/stripeMonthlyMolecule.ts +20 -0
  140. package/src/API/resource/payment/platforms/stripe/plans/stripeSingleUseMolecule.ts +21 -0
  141. package/src/API/resource/payment/platforms/stripe/plans/stripeUnlimitedUseMolecule.ts +21 -0
  142. package/src/API/resource/payment/platforms/stripe/plans/stripeYearly.ts +21 -0
  143. package/src/API/resource/payment/types.ts +201 -0
  144. package/src/API/resource/types.ts +169 -0
  145. package/src/API/resource/user/index.ts +29 -0
  146. package/src/API/resource/user/types.ts +131 -0
  147. package/src/API/resource/user/utilities/getPlan.ts +16 -0
  148. package/src/API/resource/user/utilities/index.ts +8 -0
  149. package/src/API/resource/user/utilities/logIn.ts +71 -0
  150. package/src/commands/add-ssh-key.ts +30 -0
  151. package/src/commands/buy.ts +83 -0
  152. package/src/commands/clone.ts +363 -0
  153. package/src/commands/index.ts +19 -0
  154. package/src/commands/info.ts +40 -0
  155. package/src/commands/login.ts +24 -0
  156. package/src/commands/logout.ts +27 -0
  157. package/src/commands/remove-ssh-key.ts +42 -0
  158. package/src/commands/subscribe.ts +84 -0
  159. package/src/commands/unsubscribe.ts +67 -0
  160. package/src/commands/utilities/asyncExec.ts +7 -0
  161. package/src/commands/utilities/branchExists.ts +15 -0
  162. package/src/commands/utilities/checkoutSelectionBranch.ts +62 -0
  163. package/src/commands/utilities/cherryPick.ts +23 -0
  164. package/src/commands/utilities/cloneRepo.ts +10 -0
  165. package/src/commands/utilities/convertNpmToYarn.ts +71 -0
  166. package/src/commands/utilities/convertTypeDocToJSDoc.ts +55 -0
  167. package/src/commands/utilities/convertTypeScriptToJavaScript.ts +526 -0
  168. package/src/commands/utilities/enableMergeDrivers.ts +55 -0
  169. package/src/commands/utilities/getCurrentBranch.ts +14 -0
  170. package/src/commands/utilities/getRepoRootPathSync.ts +13 -0
  171. package/src/commands/utilities/index.ts +17 -0
  172. package/src/commands/version.ts +22 -0
  173. package/src/commands/x-merge-json.ts +41 -0
  174. package/src/environment.ts +88 -0
  175. package/src/index.ts +30 -0
  176. package/src/logger.ts +29 -0
  177. package/src/pkg.ts +11 -0
  178. package/src/repoConfig.ts +6 -0
  179. package/src/types/global.ts +26 -0
  180. package/src/types/index.ts +53 -0
  181. package/src/types/process.env.d.ts +56 -0
  182. package/src/userConfig.ts +6 -0
  183. package/src/utilities/__tests__/getErrorMessage.ts +32 -0
  184. package/src/utilities/__tests__/timeAgo.ts +46 -0
  185. package/src/utilities/checkVersion.ts +31 -0
  186. package/src/utilities/getErrorMessage.ts +30 -0
  187. package/src/utilities/index.ts +14 -0
  188. package/src/utilities/readRepoConfig.ts +22 -0
  189. package/src/utilities/readUserConfig.ts +24 -0
  190. package/src/utilities/synchronizeUserConfig.ts +26 -0
  191. package/src/utilities/timeAgo.ts +39 -0
  192. package/src/utilities/userLoggedIn.ts +28 -0
  193. package/src/utilities/writeRepoConfig.ts +11 -0
  194. package/src/utilities/writeUserConfig.ts +13 -0
  195. package/tsconfig.json +25 -0
package/.eslintignore ADDED
@@ -0,0 +1,31 @@
1
+ # This file currently mirrors .gitignore as we only care about linting code committed to git,
2
+ # Feel free to modify it to suit your needs.
3
+
4
+ # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
5
+
6
+ # dependencies
7
+ /node_modules
8
+ /.pnp
9
+ .pnp.js
10
+
11
+ # the build
12
+ /build
13
+
14
+ # autogenerated docs
15
+ /docs
16
+
17
+ # testing
18
+ /coverage
19
+
20
+ # misc
21
+ .DS_Store
22
+ .env*
23
+ .eslintcache
24
+ .vscode
25
+
26
+ npm-debug.log*
27
+ yarn-debug.log*
28
+ yarn-error.log*
29
+
30
+ # keys
31
+ .keys
package/.eslintrc.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "root": true,
3
+ "env": {
4
+ "node": true,
5
+ "es2021": true,
6
+ "jest/globals": true
7
+ },
8
+ "plugins": [
9
+ "@typescript-eslint",
10
+ "jest"
11
+ ],
12
+ "parser": "@typescript-eslint/parser",
13
+ "parserOptions": {
14
+ "sourceType": "module"
15
+ },
16
+ "extends": [
17
+ "eslint:recommended",
18
+ "plugin:jest/recommended",
19
+ "plugin:@typescript-eslint/recommended"
20
+ ],
21
+ "rules": {
22
+ "semi": "off",
23
+ "@typescript-eslint/semi": [
24
+ "warn",
25
+ "never"
26
+ ],
27
+ "@typescript-eslint/member-delimiter-style": [
28
+ "warn",
29
+ {
30
+ "multiline": {
31
+ "delimiter": "none",
32
+ "requireLast": false
33
+ },
34
+ "singleline": {
35
+ "delimiter": "semi",
36
+ "requireLast": false
37
+ },
38
+ "multilineDetection": "brackets"
39
+ }
40
+ ],
41
+ "no-trailing-spaces": [
42
+ "warn",
43
+ {
44
+ "ignoreComments": true
45
+ }
46
+ ],
47
+ "no-empty": [
48
+ "warn",
49
+ {
50
+ "allowEmptyCatch": true
51
+ }
52
+ ]
53
+ }
54
+ }
package/LICENSE ADDED
@@ -0,0 +1,200 @@
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
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, replacing "Molecule.dev" with your own
182
+ identifying information. The text should be enclosed in the
183
+ appropriate comment syntax for the file format. We also recommend
184
+ that a file or class name and description of purpose be included
185
+ on the same "printed page" as the copyright notice for easier
186
+ identification within third-party archives.
187
+
188
+ Copyright 2022 Molecule.dev
189
+
190
+ Licensed under the Apache License, Version 2.0 (the "License");
191
+ you may not use this file except in compliance with the License.
192
+ You may obtain a copy of the License at
193
+
194
+ http://www.apache.org/licenses/LICENSE-2.0
195
+
196
+ Unless required by applicable law or agreed to in writing, software
197
+ distributed under the License is distributed on an "AS IS" BASIS,
198
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
199
+ See the License for the specific language governing permissions and
200
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,101 @@
1
+ # mlcl
2
+
3
+ This package contains command line tools to help with managing full-stack, cross-platform apps assembled with [Molecule.dev](https://www.molecule.dev).
4
+
5
+
6
+ ## Usage
7
+
8
+ You will need SSH, [Git](https://git-scm.com/), and [Node.js 16](https://nodejs.org/) installed on your machine.
9
+
10
+ The recommended way to use `mlcl` is via [`npx`](https://nodejs.dev/learn/the-npx-nodejs-package-runner) by passing `mlcl` commands to `npx`.
11
+
12
+ Example:
13
+
14
+ ```sh
15
+ npx mlcl --help
16
+ ```
17
+
18
+ You can also install it globally if you'd rather not use `npx`:
19
+
20
+ ```sh
21
+ npm install mlcl --global
22
+ mlcl --help
23
+ ```
24
+
25
+
26
+ ## User commands
27
+
28
+ - **`mlcl login`**
29
+
30
+ Opens your default web browser where you'll be asked for permission to log into your Molecule.dev account within your terminal.
31
+
32
+
33
+ - **`mlcl logout`**
34
+
35
+ Logs you out of your Molecule.dev account by deleting the authorization headers, usually stored within `.mlclrc.json` within your home directory.
36
+
37
+
38
+ - **`mlcl add-ssh-key [path]`**
39
+
40
+ For licensed users only. Looks for your current device's public SSH key, defaulting to a path of `~/.ssh/id_*.pub`, and sends it to our servers to allow you to access premium (private) repositories. If a key cannot be found, it will attempt to generate a new one using `ssh-keygen`.
41
+
42
+
43
+ - **`mlcl remove-ssh-key`**
44
+
45
+ For licensed users only. Removes your current device's public SSH key from our servers.
46
+
47
+
48
+ ## Molecule commands
49
+
50
+ These commands (with the exception of `clone`) must be run within a directory containing a Molecule repository, determined by the presence of a valid `.mlclrc.json` file.
51
+
52
+
53
+ - **`mlcl info`**
54
+
55
+ Opens your Molecule's information page in your default web browser.
56
+
57
+
58
+ - **`mlcl clone <moleculeId> [projectName]`**
59
+
60
+ Clones your Molecule's relevant repositories into `project-name-api` and/or `project-name-app` directories. Adds the necessary `.mlclrc.json` file to each directory.
61
+
62
+ If you are not logged in, it will attempt to log you in.
63
+
64
+ If you are a licensed user, it will attempt to add your SSH key if not already added, and your repositories will be cloned using Molecule.dev's premium (private) repositories.
65
+
66
+ If you are a free or subscribed user, your repositories will be cloned using Molecule.dev's public repositories [available on GitHub](https://github.com/molecule-dev).
67
+
68
+
69
+ - **`mlcl subscribe`**
70
+
71
+ Enables a monthly subscription for your Molecule.
72
+
73
+ If you have previously subscribed, it will attempt to reactivate your Stripe subscription. Otherwise, a Stripe checkout page will be opened in your default web browser.
74
+
75
+
76
+ - **`mlcl unsubscribe`**
77
+
78
+ Disables your Molecule's monthly subscription. You will be able to continue using subscribers' features until the monthly period ends.
79
+
80
+
81
+ - **`mlcl buy single`**
82
+
83
+ Opens a Stripe checkout page in your default web browser where you can purchase a single license for your current Molecule.
84
+
85
+
86
+ - **`mlcl buy unlimited`**
87
+
88
+ Opens a Stripe checkout page in your default web browser where you can purchase an unlimited license for your current Molecule.
89
+
90
+
91
+ - **`mlcl buy business <number>`**
92
+
93
+ Requires at least 10. Opens a Stripe checkout page in your default web browser where you can purchase a business license, allowing you to assemble any Molecule as needed.
94
+
95
+
96
+ ## Other commands
97
+
98
+ - **`mlcl x-merge-json`**
99
+
100
+ A [custom git merge driver](https://git-scm.com/docs/gitattributes#_defining_a_custom_merge_driver) used for automatically resolving merge conflicts for JSON files when assembling Molecules.
101
+
@@ -0,0 +1,10 @@
1
+ {
2
+ "presets": [
3
+ "@babel/preset-env",
4
+ "@babel/preset-typescript"
5
+ ],
6
+ "plugins": [
7
+ "@babel/transform-runtime",
8
+ "babel-plugin-transform-import-meta"
9
+ ]
10
+ }
@@ -0,0 +1,107 @@
1
+ /**
2
+ * Methods for API authorization management.
3
+ *
4
+ * @module
5
+ */
6
+ import jwtDecode from 'jwt-decode';
7
+ import { client } from './client.js';
8
+ import { userConfig } from '../userConfig.js';
9
+ import { writeUserConfig } from '../utilities/writeUserConfig.js';
10
+ import { logger } from '../logger.js';
11
+ /**
12
+ * Sets the `Authorization` header on the API client (`axios` instance)
13
+ * and saves it within the user config.
14
+ */
15
+ export const setHeader = (authorizationHeader = userConfig.authorizationHeader || ``) => {
16
+ if (authorizationHeader) {
17
+ client.defaults.headers.common.Authorization = authorizationHeader;
18
+ userConfig.authorizationHeader = authorizationHeader;
19
+ writeUserConfig();
20
+ }
21
+ };
22
+ /**
23
+ * Removes the `Authorization` header from the API client (`axios` instance)
24
+ * and removes it from the user config.
25
+ */
26
+ export const removeHeader = () => {
27
+ if (client.defaults.headers) {
28
+ delete client.defaults.headers.common.Authorization;
29
+ }
30
+ delete userConfig.authorizationHeader;
31
+ writeUserConfig();
32
+ };
33
+ /**
34
+ * If multiple users log into the same device, we use this map of user IDs to device IDs
35
+ * to allow users to properly reidentify the device when switching between users.
36
+ */
37
+ export const getUserIdsToDeviceIds = () => {
38
+ if (!userConfig.userIdsToDeviceIds) {
39
+ userConfig.userIdsToDeviceIds = {};
40
+ }
41
+ return userConfig.userIdsToDeviceIds;
42
+ };
43
+ /**
44
+ * Gets the `userId` and `deviceId` from the decoded `Authorization` header
45
+ * and saves it within the config as a map of user IDs to device IDs.
46
+ */
47
+ export const setUserIdToDeviceId = (authorizationHeader) => {
48
+ try {
49
+ const [bearer = ``, authorizationToken = ``] = authorizationHeader.split(` `);
50
+ const { session } = jwtDecode(authorizationToken);
51
+ const { userId, deviceId } = session;
52
+ const userIdsToDeviceIds = getUserIdsToDeviceIds();
53
+ if (bearer && userId && deviceId) {
54
+ userIdsToDeviceIds[userId] = deviceId;
55
+ writeUserConfig();
56
+ }
57
+ }
58
+ catch (error) {
59
+ logger.error(error);
60
+ }
61
+ };
62
+ /**
63
+ * If the `Set-Authorization` header is included in the response,
64
+ * sets the header and user ID to device ID.
65
+ */
66
+ export const interceptResponse = ({ onSet } = {}) => (response) => {
67
+ if (response.headers[`set-authorization`]) {
68
+ setHeader(response.headers[`set-authorization`]);
69
+ setUserIdToDeviceId(response.headers[`set-authorization`]);
70
+ if (onSet) {
71
+ onSet();
72
+ }
73
+ }
74
+ return response;
75
+ };
76
+ /**
77
+ * Removes the `Authorization` header if the response status code is `401`,
78
+ * or if the `Set-Authorization` header is included in the error response,
79
+ * sets the header and user ID to device ID.
80
+ */
81
+ export const interceptError = ({ onSet, onRemove } = {}) => (error) => {
82
+ if (error?.response?.status === 401) {
83
+ removeHeader();
84
+ if (onRemove) {
85
+ onRemove();
86
+ }
87
+ }
88
+ else if (error?.response?.headers[`set-authorization`]) {
89
+ setHeader(error.response.headers[`set-authorization`]);
90
+ setUserIdToDeviceId(error.response.headers[`set-authorization`]);
91
+ if (onSet) {
92
+ onSet();
93
+ }
94
+ }
95
+ return Promise.reject(error);
96
+ };
97
+ // Set the locally stored authorization header, if it exists.
98
+ setHeader();
99
+ // Intercept all requests to set and/or remove the authorization header.
100
+ client.interceptors.response.use(interceptResponse(), // Locally store authorization headers when provided.
101
+ interceptError({
102
+ onRemove: () => {
103
+ // Log out when authorization removed.
104
+ delete userConfig.user;
105
+ writeUserConfig();
106
+ }
107
+ }));
@@ -0,0 +1,11 @@
1
+ import axios from 'axios';
2
+ /**
3
+ * The API client (`axios` instance).
4
+ *
5
+ * @see https://www.npmjs.com/package/axios
6
+ */
7
+ export const client = axios.create({
8
+ baseURL: `${process.env.API_ORIGIN || ``}/api`,
9
+ headers: process.env.APP_ID ? { 'X-Requested-With': process.env.APP_ID } : {},
10
+ withCredentials: true
11
+ });
@@ -0,0 +1,8 @@
1
+ /**
2
+ * API client resources with authorization.
3
+ *
4
+ * @module
5
+ */
6
+ export * as resource from './resource/index.js';
7
+ export * as authorization from './authorization.js';
8
+ export * from './client.js';
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The `molecule` API resource.
3
+ *
4
+ * @module
5
+ */
6
+ import { client } from '../../client';
7
+ export * as types from './types';
8
+ export const read = (id) => (client.get(`molecules/${id}`));
9
+ export const create = (props) => (client.post(`molecules`, props));
10
+ export const update = (id, props) => (client.patch(`molecules/${id}`, props));
11
+ export const updatePlan = (id, { planKey, receipt, quantity }) => (client.patch(`molecules/${id}/plan`, { planKey, receipt, quantity }));
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Molecule type definitions.
3
+ *
4
+ * @module
5
+ */
6
+ export {};
@@ -0,0 +1,12 @@
1
+ /**
2
+ * The device API resource.
3
+ *
4
+ * @module
5
+ */
6
+ import { client } from '../../client.js';
7
+ export * as utilities from './utilities/index.js';
8
+ export * as types from './types.js';
9
+ export const query = () => (client.get(`devices`));
10
+ export const read = (id) => (client.get(`devices/${id}`));
11
+ export const update = (id, props) => (client.patch(`devices/${id}`, props));
12
+ export const del = (id) => (client.delete(`devices/${id}`));
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Device type definitions.
3
+ *
4
+ * @module
5
+ */
6
+ export {};
@@ -0,0 +1,20 @@
1
+ import { read } from '../index.js';
2
+ import { sendSshKey } from './sendSshKey.js';
3
+ import { logger } from '../../../../logger.js';
4
+ export const confirmSshKey = async (deviceId, name) => {
5
+ try {
6
+ const device = (await read(deviceId)).data.props;
7
+ if (device.sshKey) {
8
+ return true;
9
+ }
10
+ const sshKeyConfirmed = await sendSshKey(deviceId, name);
11
+ if (sshKeyConfirmed) {
12
+ return true;
13
+ }
14
+ }
15
+ catch (error) {
16
+ }
17
+ logger.warn(`The Molecule.dev API could not confirm your device SSH key.`);
18
+ logger.warn(`Use \`mlcl add-ssh-key\` or try logging out and in again.`);
19
+ return false;
20
+ };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Device resource utilities.
3
+ *
4
+ * @module
5
+ */
6
+ export * from './confirmSshKey.js';
7
+ export * from './sendSshKey.js';
@@ -0,0 +1,64 @@
1
+ import fs from 'fs';
2
+ import os from 'os';
3
+ import path from 'path';
4
+ import { execSync } from 'child_process';
5
+ import { update } from '../index.js';
6
+ import { logger } from '../../../../logger.js';
7
+ import { getErrorMessage } from '../../../../utilities/getErrorMessage.js';
8
+ const homeDir = os.homedir();
9
+ const sshDir = path.join(homeDir, `.ssh`);
10
+ const findPubKey = (filename) => /^id_(.+)\.pub$/.test(filename);
11
+ export const sendSshKey = async (deviceId, name, sshKeyPath) => {
12
+ if (!sshKeyPath) {
13
+ if (!fs.existsSync(sshDir)) {
14
+ fs.mkdirSync(sshDir, { recursive: true });
15
+ }
16
+ logger.info(`Looking for ~/.ssh/id_*.pub...`);
17
+ sshKeyPath = fs.readdirSync(sshDir).find(findPubKey);
18
+ if (sshKeyPath) {
19
+ logger.info(`Found ~/.ssh/${sshKeyPath}.`);
20
+ }
21
+ }
22
+ if (!sshKeyPath) {
23
+ logger.info(`Public SSH key not found. Using \`ssh-keygen\` to create one.`);
24
+ try {
25
+ execSync(`ssh-keygen -t ed25519 -C "${name}" -f id_ed25519`, { encoding: `utf8`, stdio: [0, 1, 2] });
26
+ fs.renameSync(`id_ed25519`, path.join(sshDir, `id_ed25519`));
27
+ fs.renameSync(`id_ed25519.pub`, path.join(sshDir, `id_ed25519.pub`));
28
+ }
29
+ catch (error) {
30
+ logger.warn(`Error: ${getErrorMessage(error)}`);
31
+ }
32
+ sshKeyPath = fs.readdirSync(sshDir).find(findPubKey);
33
+ if (sshKeyPath) {
34
+ logger.info(`Created ~/.ssh/${sshKeyPath}.`);
35
+ }
36
+ }
37
+ if (!sshKeyPath) {
38
+ logger.warn(`No public SSH key to add.`);
39
+ return false;
40
+ }
41
+ const sshKey = fs.readFileSync(path.join(sshDir, sshKeyPath), `utf8`);
42
+ if (!sshKey) {
43
+ logger.warn(`SSH key file is empty.`);
44
+ return false;
45
+ }
46
+ logger.info(`Sending public SSH key to the API...`);
47
+ const timeout = setTimeout(() => {
48
+ logger.info(`This may take a moment...`);
49
+ }, 2000);
50
+ try {
51
+ const { props } = (await update(deviceId, { sshKey })).data;
52
+ if (!props.sshKey) {
53
+ throw new Error(`The Molecule.dev API did not confirm the SSH key.`);
54
+ }
55
+ clearTimeout(timeout);
56
+ logger.info(`SSH key successfully added!`);
57
+ return true;
58
+ }
59
+ catch (error) {
60
+ clearTimeout(timeout);
61
+ logger.warn(`Failed to add SSH key. ${getErrorMessage(error)}`);
62
+ }
63
+ return false;
64
+ };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Every available API resource.
3
+ *
4
+ * @module
5
+ */
6
+ export * as device from './device/index.js';
7
+ export * as molecule from './molecule/index.js';
8
+ export * as payment from './payment/index.js';
9
+ export * as user from './user/index.js';
10
+ export * as types from './types.js';