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
@@ -0,0 +1,80 @@
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
+
9
+ const homeDir = os.homedir()
10
+ const sshDir = path.join(homeDir, `.ssh`)
11
+
12
+ const findPubKey = (filename: string) => /^id_(.+)\.pub$/.test(filename)
13
+
14
+ export const sendSshKey = async (deviceId: string, name: string, sshKeyPath?: string) => {
15
+ if (!sshKeyPath) {
16
+ if (!fs.existsSync(sshDir)) {
17
+ fs.mkdirSync(sshDir, { recursive: true })
18
+ }
19
+
20
+ logger.info(`Looking for ~/.ssh/id_*.pub...`)
21
+ sshKeyPath = fs.readdirSync(sshDir).find(findPubKey)
22
+
23
+ if (sshKeyPath) {
24
+ logger.info(`Found ~/.ssh/${sshKeyPath}.`)
25
+ }
26
+ }
27
+
28
+ if (!sshKeyPath) {
29
+ logger.info(`Public SSH key not found. Using \`ssh-keygen\` to create one.`)
30
+
31
+ try {
32
+ execSync(`ssh-keygen -t ed25519 -C "${name}" -f id_ed25519`, { encoding: `utf8`, stdio: [ 0, 1, 2 ] })
33
+ fs.renameSync(`id_ed25519`, path.join(sshDir, `id_ed25519`))
34
+ fs.renameSync(`id_ed25519.pub`, path.join(sshDir, `id_ed25519.pub`))
35
+ } catch (error) {
36
+ logger.warn(`Error: ${getErrorMessage(error)}`)
37
+ }
38
+
39
+ sshKeyPath = fs.readdirSync(sshDir).find(findPubKey)
40
+
41
+ if (sshKeyPath) {
42
+ logger.info(`Created ~/.ssh/${sshKeyPath}.`)
43
+ }
44
+ }
45
+
46
+ if (!sshKeyPath) {
47
+ logger.warn(`No public SSH key to add.`)
48
+ return false
49
+ }
50
+
51
+ const sshKey = fs.readFileSync(path.join(sshDir, sshKeyPath), `utf8`)
52
+
53
+ if (!sshKey) {
54
+ logger.warn(`SSH key file is empty.`)
55
+ return false
56
+ }
57
+
58
+ logger.info(`Sending public SSH key to the API...`)
59
+
60
+ const timeout = setTimeout(() => {
61
+ logger.info(`This may take a moment...`)
62
+ }, 2000)
63
+
64
+ try {
65
+ const { props } = (await update(deviceId, { sshKey })).data
66
+
67
+ if (!props.sshKey) {
68
+ throw new Error(`The Molecule.dev API did not confirm the SSH key.`)
69
+ }
70
+
71
+ clearTimeout(timeout)
72
+ logger.info(`SSH key successfully added!`)
73
+ return true
74
+ } catch (error) {
75
+ clearTimeout(timeout)
76
+ logger.warn(`Failed to add SSH key. ${getErrorMessage(error)}`)
77
+ }
78
+
79
+ return false
80
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Every available API resource.
3
+ *
4
+ * @module
5
+ */
6
+
7
+ export * as device from './device/index.js'
8
+ export * as molecule from './molecule/index.js'
9
+ export * as payment from './payment/index.js'
10
+ export * as user from './user/index.js'
11
+
12
+ export * as types from './types.js'
@@ -0,0 +1,30 @@
1
+ /**
2
+ * The `molecule` API resource.
3
+ *
4
+ * @module
5
+ */
6
+
7
+ import { client } from '../../client.js'
8
+ import * as types from './types.js'
9
+
10
+ export * as types from './types.js'
11
+
12
+ export const read = (id: string): Promise<types.SuccessResponse> => (
13
+ client.get(`molecules/${id}`)
14
+ )
15
+
16
+ export const readClone = (id: string): Promise<types.CloneResponse> => (
17
+ client.get(`molecules/${id}/clone`)
18
+ )
19
+
20
+ export const create = (props: types.CreateProps): Promise<types.SuccessResponse | types.MessageResponse> => (
21
+ client.post(`molecules`, props)
22
+ )
23
+
24
+ export const update = (id: string, props: types.UpdateProps): Promise<types.SuccessPartialResponse> => (
25
+ client.patch(`molecules/${id}`, props)
26
+ )
27
+
28
+ export const updatePlan = (id: string, { planKey, receipt, quantity }: types.UpdatePlanProps): Promise<types.UpdatePlanResponse> => (
29
+ client.patch(`molecules/${id}/plan`, { planKey, receipt, quantity })
30
+ )
@@ -0,0 +1,332 @@
1
+ /**
2
+ * Molecule type definitions.
3
+ *
4
+ * @module
5
+ */
6
+
7
+ import { Commit } from '../../../types/index.js'
8
+ import { PlanKey } from '../payment/types.js'
9
+ import * as resourceTypes from '../types.js'
10
+
11
+ // Internal reference for easier default type arguments within this module.
12
+ type MoleculeProps = Props
13
+
14
+ /**
15
+ * The molecule's properties returned by the API.
16
+ */
17
+ export interface Props extends resourceTypes.Props {
18
+ /**
19
+ * The name of the molecule, chosen by the user.
20
+ */
21
+ name?: string
22
+ /**
23
+ * The customer's user ID.
24
+ */
25
+ userId: string
26
+ /**
27
+ * The object hash of the selected options relevant to the frontend app.
28
+ *
29
+ * Set only when the selection is valid and implemented.
30
+ */
31
+ appSelectionHash?: string
32
+ /**
33
+ * The object hash of the selected options relevant to the backend API.
34
+ *
35
+ * Set only when the selection is valid and implemented.
36
+ */
37
+ apiSelectionHash?: string
38
+ /**
39
+ * The selected options.
40
+ */
41
+ selection: {
42
+ appLanguage?: `TypeScript`
43
+ | `JavaScript`
44
+ | `Dart`
45
+ | `Other`
46
+ appPackageManager?: `NPM`
47
+ | `Yarn`
48
+ | `Other`
49
+ appRenderer?: `React`
50
+ | `Vue`
51
+ | `Angular`
52
+ | `Flutter`
53
+ | `Other`
54
+ appDocs?: `TypeDoc`
55
+ | `JSDoc`
56
+ | `Other`
57
+ appTesting?: `Jest`
58
+ | `Mocha`
59
+ | `Other`
60
+ appLogging?: `Console`
61
+ | `Loglevel`
62
+ | `Other`
63
+ appPlatformSupport?: `Capacitor`
64
+ | `Cordova`
65
+ | `React Native`
66
+ | `Flutter`
67
+ | `Other`
68
+ appPlatforms?: Array<
69
+ `Web`
70
+ | `Android`
71
+ | `iOS`
72
+ | `macOS`
73
+ | `Windows`
74
+ | `Linux`
75
+ >
76
+ appUi?: `Styled Components`
77
+ | `Ionic`
78
+ | `Tailwind`
79
+ | `Other`
80
+ appThemes?: Array<
81
+ `Light`
82
+ | `Dark`
83
+ | `Other`
84
+ >
85
+ userAuthentication?: Array<
86
+ `Typical`
87
+ | `OAuth`
88
+ | `WebAuthn`
89
+ | `Other`
90
+ >
91
+ oauthServers?: Array<
92
+ `Google`
93
+ | `Twitter`
94
+ | `GitHub`
95
+ | `GitLab`
96
+ | `Other`
97
+ >
98
+ pushNotifications?: `Enabled`
99
+ | `Disabled`
100
+ paymentPlatforms?: Array<
101
+ `Stripe`
102
+ | `Apple Pay`
103
+ | `Google Pay`
104
+ | `PayPal`
105
+ | `Other`
106
+ >
107
+ appDeployment?: `Netlify`
108
+ | `Render`
109
+ | `Digital Ocean`
110
+ | `Vercel`
111
+ | `Cloudflare`
112
+ | `AWS`
113
+ | `Other`
114
+ apiLanguage?: `TypeScript`
115
+ | `JavaScript`
116
+ | `Python`
117
+ | `Go`
118
+ | `Other`
119
+ apiPackageManager?: `NPM`
120
+ | `Yarn`
121
+ | `Other`
122
+ apiDocs?: `TypeDoc`
123
+ | `JSDoc`
124
+ | `Other`
125
+ apiTesting?: `Jest`
126
+ | `Mocha`
127
+ | `Other`
128
+ apiLogging?: `Console`
129
+ | `Loglevel`
130
+ | `Winston`
131
+ | `Other`
132
+ apiDatabase?: `PostgreSQL`
133
+ | `SQLite`
134
+ | `Firebase`
135
+ | `MongoDB`
136
+ | `Other`
137
+ apiEmails?: `Sendmail`
138
+ | `Mailgun`
139
+ | `SendGrid`
140
+ | `SES`
141
+ | `Other`
142
+ apiUploads?: `S3`
143
+ | `File System`
144
+ | `Other`
145
+ apiDeployment?: `Heroku`
146
+ | `Render`
147
+ | `Digital Ocean`
148
+ | `AWS`
149
+ | `Other`
150
+ }
151
+ /**
152
+ * Other custom options requested by the customer.
153
+ */
154
+ other: {
155
+ appLanguage?: string
156
+ appPackageManager?: string
157
+ appRenderer?: string
158
+ appDocs?: string
159
+ appTesting?: string
160
+ appLogging?: string
161
+ appPlatformSupport?: string
162
+ appPlatforms?: string
163
+ appUi?: string
164
+ appThemes?: string
165
+ userAuthentication?: string
166
+ oauthServers?: string
167
+ pushNotifications?: string
168
+ paymentPlatforms?: string
169
+ appDeployment?: string
170
+ apiLanguage?: string
171
+ apiPackageManager?: string
172
+ apiDocs?: string
173
+ apiTesting?: string
174
+ apiLogging?: string
175
+ apiDatabase?: string
176
+ apiEmails?: string
177
+ apiUploads?: string
178
+ apiDeployment?: string
179
+ additionalInfo?: string
180
+ questions?: string
181
+ discountCode?: string
182
+ }
183
+ /**
184
+ * The plan the user has selected for the molecule.
185
+ */
186
+ plan?: `Free Trial`
187
+ | `Subscription`
188
+ | `Single Use`
189
+ | `Unlimited Use`
190
+ | `Business`
191
+ /**
192
+ * The molecule's current plan as a key of the `plans` object.
193
+ */
194
+ planKey?: PlanKey
195
+ /**
196
+ * When the plan expires.
197
+ *
198
+ * Usually an ISO 8061 timestamp.
199
+ */
200
+ planExpiresAt?: string
201
+ /**
202
+ * True if the plan will automatically renew.
203
+ */
204
+ planAutoRenews?: boolean
205
+ /**
206
+ * The checkout URL through which the user can subscribe or buy a license.
207
+ */
208
+ checkoutUrl?: string
209
+ /**
210
+ * The number of emails sent through the molecule within the last 24 hours.
211
+ */
212
+ emailCount?: number
213
+ /**
214
+ * The time at which the email count was last reset to 0.
215
+ */
216
+ emailCountResetAt?: string
217
+ }
218
+
219
+ /**
220
+ * The properties when creating a molecule.
221
+ */
222
+ export interface CreateProps {
223
+ selection: Props['selection']
224
+ other: Props['other']
225
+ plan: Props['plan']
226
+ quantity?: number | string
227
+ name?: string
228
+ }
229
+
230
+ /**
231
+ * The properties when updating a molecule.
232
+ */
233
+ export type UpdateProps = Pick<Props,
234
+ `name`
235
+ >
236
+
237
+ /**
238
+ * The properties when updating the molecule's plan.
239
+ */
240
+ export interface UpdatePlanProps {
241
+ planKey: PlanKey
242
+ receipt?: string
243
+ quantity?: number
244
+ }
245
+
246
+ /**
247
+ * The successful molecule resource response returning either partial props or a checkout URL.
248
+ */
249
+ export type UpdatePlanResponse<Props = MoleculeProps> = {
250
+ /**
251
+ * HTTP status code.
252
+ */
253
+ statusCode: 200 | 201
254
+ /**
255
+ * The response body.
256
+ */
257
+ data: {
258
+ /**
259
+ * Response data will contain updated `props` if the molecule's plan was updated.
260
+ */
261
+ props?: Partial<Props>
262
+ /**
263
+ * Response data will contain a `checkoutUrl` if the user should be redirected to a URL to complete checkout.
264
+ */
265
+ checkoutUrl?: string
266
+ }
267
+ }
268
+
269
+ /**
270
+ * A response containing the necessary information to clone the Molecule.
271
+ */
272
+ export type CloneResponse = {
273
+ /**
274
+ * HTTP status code.
275
+ */
276
+ statusCode: 200
277
+ /**
278
+ * The response body.
279
+ */
280
+ data: {
281
+ /**
282
+ * The Molecule's props.
283
+ */
284
+ props: Props
285
+ /**
286
+ * Response data will contain `apiRepoUrl` if the selection is relevant to the Molecule's API.
287
+ */
288
+ apiRepoUrl?: string
289
+ /**
290
+ * Response data will contain an array of commit hashes if the Molecule's API selection does not yet exist in our repositories.
291
+ */
292
+ apiCommits?: Array<Commit>
293
+ /**
294
+ * Response data will contain `appRepoUrl` if the selection is relevant to the Molecule's API.
295
+ */
296
+ appRepoUrl?: string
297
+ /**
298
+ * Response data will contain an array of commit hashes if the Molecule's API selection does not yet exist in our repositories.
299
+ */
300
+ appCommits?: Array<Commit>
301
+ }
302
+ }
303
+
304
+ /**
305
+ * The successful molecule resource response.
306
+ */
307
+ export type SuccessResponse<Props = MoleculeProps> = resourceTypes.SuccessResponse<Props>
308
+
309
+ /**
310
+ * The successful molecule resource response returning partial props.
311
+ */
312
+ export type SuccessPartialResponse<Props = MoleculeProps> = resourceTypes.SuccessPartialResponse<Props>
313
+
314
+ /**
315
+ * The response when querying molecules.
316
+ */
317
+ export type QueryResponse<Props = MoleculeProps> = resourceTypes.QueryResponse<Props>
318
+
319
+ /**
320
+ * Generic response with an optional body.
321
+ */
322
+ export type GenericResponse = resourceTypes.GenericResponse
323
+
324
+ /**
325
+ * The response containing a molecule.
326
+ */
327
+ export type MessageResponse = resourceTypes.MessageResponse
328
+
329
+ /**
330
+ * The response when an error has occurred when handling a molecule resource request.
331
+ */
332
+ export type ErrorResponse = resourceTypes.ErrorResponse
@@ -0,0 +1,21 @@
1
+ import * as types from '../types.js'
2
+ import { plans } from '../../payment/plans.js'
3
+
4
+ /**
5
+ * Gets a molecule's current `plan`.
6
+ */
7
+ export const getPlan = (molecule: types.Props) => {
8
+ let plan = plans['']
9
+
10
+ const planExpiresTime = (molecule.planExpiresAt && new Date(String(molecule.planExpiresAt)).getTime()) || 0
11
+
12
+ if (molecule.planKey && plans[molecule.planKey] && (!planExpiresTime || (Date.now() < planExpiresTime))) {
13
+ plan = plans[molecule.planKey]
14
+ }
15
+
16
+ plan = {
17
+ ...plan,
18
+ }
19
+
20
+ return plan
21
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Molecule resource utilities.
3
+ *
4
+ * @module
5
+ */
6
+
7
+ export * from './getPlan.js'
@@ -0,0 +1,12 @@
1
+ /**
2
+ * The `payment` resource properties.
3
+ *
4
+ * @module
5
+ */
6
+
7
+ export * as platforms from './platforms/index.js'
8
+
9
+ export * from './plans.js'
10
+ export * from './platform.js'
11
+
12
+ export * as types from './types.js'
@@ -0,0 +1,32 @@
1
+ import * as platforms from './platforms/index.js'
2
+ import * as types from './types.js'
3
+
4
+ const defaultPlan: types.Plan = { // No plan AKA free plan.
5
+ planKey: ``,
6
+ platformKey: ``,
7
+ platformProductId: ``,
8
+ alias: ``,
9
+ period: ``,
10
+ price: ``,
11
+ title: `Free`,
12
+ description: `Certain features are limited. Upgrade your plan to unlock premium features.`,
13
+ shortDescription: `Limited features and usage.`,
14
+ capabilities: {
15
+ },
16
+ }
17
+
18
+ /**
19
+ * A map of every available `planKey` to `plan`.
20
+ *
21
+ * Every plan key for every platform should be unique.
22
+ * E.g., `appleMonthly` and `appleYearly` vs `googleMonthly` and `googleYearly`.
23
+ *
24
+ * You'll need to customize the `Plan` type, adding properties and logic surrounding it
25
+ * as necessary for your particular application.
26
+ */
27
+ export const plans = {
28
+ '': defaultPlan,
29
+ ...platforms.stripe.plans,
30
+ ...platforms.google.plans,
31
+ ...platforms.apple.plans,
32
+ }
@@ -0,0 +1,11 @@
1
+ import * as platforms from './platforms/index.js'
2
+ import * as types from './types.js'
3
+
4
+ /**
5
+ * The payment platform for the current app platform.
6
+ */
7
+ export const platform = Object.values<types.Platform>(platforms).find(platform => (
8
+ Array.isArray(platform.appPlatforms)
9
+ ? platform.appPlatforms.includes(process.env.APP_PLATFORM || undefined)
10
+ : (platform.appPlatforms || undefined) === (process.env.APP_PLATFORM || undefined)
11
+ ))
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Properties and methods for handling payments through Apple.
3
+ *
4
+ * @module
5
+ */
6
+
7
+ import * as plans from './plans/index.js'
8
+ import * as types from '../../types.js'
9
+
10
+ /**
11
+ * The Apple Pay payment platform.
12
+ */
13
+ export const apple: types.Platform<typeof plans> = {
14
+ /**
15
+ * An array of app platforms compatible with Apple Pay.
16
+ */
17
+ appPlatforms: [
18
+ `ios`,
19
+ ],
20
+
21
+ /**
22
+ * A map of Apple plan keys to plan properties.
23
+ */
24
+ plans,
25
+ }
@@ -0,0 +1,19 @@
1
+ import { Plan } from '../../../types.js'
2
+
3
+ /**
4
+ * The monthly Apple Pay plan.
5
+ */
6
+ export const appleMonthly: Plan = {
7
+ planKey: `appleMonthly`,
8
+ platformKey: `apple`,
9
+ platformProductId: `molecule_monthly_early_adopter`,
10
+ alias: `monthly`,
11
+ period: `month`,
12
+ price: `$5.99`,
13
+ autoRenews: true,
14
+ title: `Monthly`,
15
+ description: `Create and view attachments.`,
16
+ capabilities: {
17
+ attachments: true,
18
+ }
19
+ }
@@ -0,0 +1,20 @@
1
+ import { Plan } from '../../../types.js'
2
+
3
+ /**
4
+ * The yearly Apple Pay plan.
5
+ */
6
+ export const appleYearly: Plan = {
7
+ planKey: `appleYearly`,
8
+ platformKey: `apple`,
9
+ platformProductId: `molecule_yearly_early_adopter`,
10
+ alias: `yearly`,
11
+ period: `year`,
12
+ price: `$64.99`,
13
+ autoRenews: true,
14
+ title: `Yearly`,
15
+ description: `Create and view attachments.`,
16
+ highlightedDescription: `Get one month free, every year.`,
17
+ capabilities: {
18
+ attachments: true,
19
+ }
20
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Every available Apple Pay plan.
3
+ *
4
+ * @module
5
+ */
6
+
7
+ export {}
8
+ export * from './appleMonthly.js'
9
+ export * from './appleYearly.js'
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Properties and methods for handling payments through Google.
3
+ *
4
+ * @module
5
+ */
6
+
7
+ import * as plans from './plans/index.js'
8
+ import * as types from '../../types.js'
9
+
10
+ /**
11
+ * The Google Pay payment platform.
12
+ */
13
+ export const google: types.Platform<typeof plans> = {
14
+ /**
15
+ * An array of app platforms compatible with Google Pay.
16
+ */
17
+ appPlatforms: [
18
+ `android`,
19
+ ],
20
+
21
+ /**
22
+ * A map of Google plan keys to plan properties.
23
+ */
24
+ plans,
25
+ }
@@ -0,0 +1,19 @@
1
+ import { Plan } from '../../../types.js'
2
+
3
+ /**
4
+ * The monthly Google Pay plan.
5
+ */
6
+ export const googleMonthly: Plan = {
7
+ planKey: `googleMonthly`,
8
+ platformKey: `google`,
9
+ platformProductId: `monthly_early_adopter`,
10
+ alias: `monthly`,
11
+ period: `month`,
12
+ price: `$5.99`,
13
+ autoRenews: true,
14
+ title: `Monthly`,
15
+ description: `Create and view attachments.`,
16
+ capabilities: {
17
+ attachments: true,
18
+ }
19
+ }
@@ -0,0 +1,20 @@
1
+ import { Plan } from '../../../types.js'
2
+
3
+ /**
4
+ * The yearly Google Pay plan.
5
+ */
6
+ export const googleYearly: Plan = {
7
+ planKey: `googleYearly`,
8
+ platformKey: `google`,
9
+ platformProductId: `yearly_early_adopter`,
10
+ alias: `yearly`,
11
+ period: `year`,
12
+ price: `$64.99`,
13
+ autoRenews: true,
14
+ title: `Yearly`,
15
+ description: `Create and view attachments.`,
16
+ highlightedDescription: `Get one month free, every year.`,
17
+ capabilities: {
18
+ attachments: true,
19
+ }
20
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Every available Google Pay plan.
3
+ *
4
+ * @module
5
+ */
6
+
7
+ export {}
8
+ export * from './googleMonthly.js'
9
+ export * from './googleYearly.js'