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.
- package/.eslintignore +31 -0
- package/.eslintrc.json +54 -0
- package/LICENSE +200 -0
- package/README.md +101 -0
- package/babel.config.json +10 -0
- package/build/API/authorization.js +107 -0
- package/build/API/client.js +11 -0
- package/build/API/index.js +8 -0
- package/build/API/molecule/index.js +11 -0
- package/build/API/molecule/types.js +6 -0
- package/build/API/resource/device/index.js +12 -0
- package/build/API/resource/device/types.js +6 -0
- package/build/API/resource/device/utilities/confirmSshKey.js +20 -0
- package/build/API/resource/device/utilities/index.js +7 -0
- package/build/API/resource/device/utilities/sendSshKey.js +64 -0
- package/build/API/resource/index.js +10 -0
- package/build/API/resource/molecule/index.js +12 -0
- package/build/API/resource/molecule/types.js +6 -0
- package/build/API/resource/molecule/utilities/getPlan.js +15 -0
- package/build/API/resource/molecule/utilities/index.js +6 -0
- package/build/API/resource/payment/index.js +9 -0
- package/build/API/resource/payment/plans.js +28 -0
- package/build/API/resource/payment/platform.js +7 -0
- package/build/API/resource/payment/platforms/apple/index.js +21 -0
- package/build/API/resource/payment/platforms/apple/plans/appleMonthly.js +17 -0
- package/build/API/resource/payment/platforms/apple/plans/appleYearly.js +18 -0
- package/build/API/resource/payment/platforms/apple/plans/index.js +7 -0
- package/build/API/resource/payment/platforms/google/index.js +21 -0
- package/build/API/resource/payment/platforms/google/plans/googleMonthly.js +17 -0
- package/build/API/resource/payment/platforms/google/plans/googleYearly.js +18 -0
- package/build/API/resource/payment/platforms/google/plans/index.js +7 -0
- package/build/API/resource/payment/platforms/index.js +8 -0
- package/build/API/resource/payment/platforms/stripe/index.js +25 -0
- package/build/API/resource/payment/platforms/stripe/plans/index.js +11 -0
- package/build/API/resource/payment/platforms/stripe/plans/stripeBusinessMolecule.js +21 -0
- package/build/API/resource/payment/platforms/stripe/plans/stripeMonthly.js +18 -0
- package/build/API/resource/payment/platforms/stripe/plans/stripeMonthlyMolecule.js +18 -0
- package/build/API/resource/payment/platforms/stripe/plans/stripeSingleUseMolecule.js +19 -0
- package/build/API/resource/payment/platforms/stripe/plans/stripeUnlimitedUseMolecule.js +19 -0
- package/build/API/resource/payment/platforms/stripe/plans/stripeYearly.js +19 -0
- package/build/API/resource/payment/types.js +6 -0
- package/build/API/resource/types.js +6 -0
- package/build/API/resource/user/index.js +15 -0
- package/build/API/resource/user/types.js +6 -0
- package/build/API/resource/user/utilities/getPlan.js +12 -0
- package/build/API/resource/user/utilities/index.js +7 -0
- package/build/API/resource/user/utilities/logIn.js +60 -0
- package/build/cli.js +15 -0
- package/build/commands/add-ssh-key.js +24 -0
- package/build/commands/buy.js +70 -0
- package/build/commands/clone.js +329 -0
- package/build/commands/index.js +17 -0
- package/build/commands/info.js +33 -0
- package/build/commands/login.js +20 -0
- package/build/commands/logout.js +23 -0
- package/build/commands/molecule/index.js +11 -0
- package/build/commands/molecule/types.js +6 -0
- package/build/commands/remove-ssh-key.js +36 -0
- package/build/commands/select.js +98 -0
- package/build/commands/set-api-key.js +73 -0
- package/build/commands/subscribe.js +74 -0
- package/build/commands/unsubscribe.js +59 -0
- package/build/commands/utilities/asyncExec.js +6 -0
- package/build/commands/utilities/branchExists.js +13 -0
- package/build/commands/utilities/branchExistsSync.js +12 -0
- package/build/commands/utilities/checkoutSelectionBranch.js +49 -0
- package/build/commands/utilities/cherryPick.js +20 -0
- package/build/commands/utilities/cloneRepo.js +9 -0
- package/build/commands/utilities/convertNpmToYarn.js +60 -0
- package/build/commands/utilities/convertTypeDocToJSDoc.js +51 -0
- package/build/commands/utilities/convertTypeScriptToJavaScript.js +451 -0
- package/build/commands/utilities/enableMergeDrivers.js +50 -0
- package/build/commands/utilities/getCurrentBranch.js +11 -0
- package/build/commands/utilities/getCurrentBranchSync.js +7 -0
- package/build/commands/utilities/getRepoRootPath.js +7 -0
- package/build/commands/utilities/getRepoRootPathSync.js +13 -0
- package/build/commands/utilities/index.js +16 -0
- package/build/commands/utilities/npm-to-yarn.js +41 -0
- package/build/commands/utilities/ts-to-js.js +344 -0
- package/build/commands/version.js +14 -0
- package/build/commands/x-merge-json.js +33 -0
- package/build/config.js +5 -0
- package/build/environment.js +80 -0
- package/build/index.js +23 -0
- package/build/logger.js +12 -0
- package/build/pkg.js +5 -0
- package/build/repoConfig copy.js +5 -0
- package/build/repoConfig.js +5 -0
- package/build/types/global.js +6 -0
- package/build/types/index.js +6 -0
- package/build/userConfig.js +5 -0
- package/build/utilities/__tests__/getErrorMessage.js +26 -0
- package/build/utilities/__tests__/timeAgo.js +39 -0
- package/build/utilities/checkVersion.js +29 -0
- package/build/utilities/getErrorMessage.js +15 -0
- package/build/utilities/index.js +13 -0
- package/build/utilities/readConfig.js +19 -0
- package/build/utilities/readRepoConfig copy.js +20 -0
- package/build/utilities/readRepoConfig.js +19 -0
- package/build/utilities/readUserConfig.js +20 -0
- package/build/utilities/synchronizeUserConfig.js +25 -0
- package/build/utilities/timeAgo.js +42 -0
- package/build/utilities/userLoggedIn.js +24 -0
- package/build/utilities/writeConfig.js +8 -0
- package/build/utilities/writeRepoConfig copy.js +9 -0
- package/build/utilities/writeRepoConfig.js +10 -0
- package/build/utilities/writeUserConfig.js +11 -0
- package/jest.config.json +11 -0
- package/package.json +56 -0
- package/src/API/authorization.ts +143 -0
- package/src/API/client.ts +12 -0
- package/src/API/index.ts +10 -0
- package/src/API/resource/device/index.ts +27 -0
- package/src/API/resource/device/types.ts +80 -0
- package/src/API/resource/device/utilities/confirmSshKey.ts +25 -0
- package/src/API/resource/device/utilities/index.ts +8 -0
- package/src/API/resource/device/utilities/sendSshKey.ts +80 -0
- package/src/API/resource/index.ts +12 -0
- package/src/API/resource/molecule/index.ts +30 -0
- package/src/API/resource/molecule/types.ts +332 -0
- package/src/API/resource/molecule/utilities/getPlan.ts +21 -0
- package/src/API/resource/molecule/utilities/index.ts +7 -0
- package/src/API/resource/payment/index.ts +12 -0
- package/src/API/resource/payment/plans.ts +32 -0
- package/src/API/resource/payment/platform.ts +11 -0
- package/src/API/resource/payment/platforms/apple/index.ts +25 -0
- package/src/API/resource/payment/platforms/apple/plans/appleMonthly.ts +19 -0
- package/src/API/resource/payment/platforms/apple/plans/appleYearly.ts +20 -0
- package/src/API/resource/payment/platforms/apple/plans/index.ts +9 -0
- package/src/API/resource/payment/platforms/google/index.ts +25 -0
- package/src/API/resource/payment/platforms/google/plans/googleMonthly.ts +19 -0
- package/src/API/resource/payment/platforms/google/plans/googleYearly.ts +20 -0
- package/src/API/resource/payment/platforms/google/plans/index.ts +9 -0
- package/src/API/resource/payment/platforms/index.ts +10 -0
- package/src/API/resource/payment/platforms/stripe/index.ts +29 -0
- package/src/API/resource/payment/platforms/stripe/plans/index.ts +12 -0
- package/src/API/resource/payment/platforms/stripe/plans/stripeBusinessMolecule.ts +23 -0
- package/src/API/resource/payment/platforms/stripe/plans/stripeMonthly.ts +20 -0
- package/src/API/resource/payment/platforms/stripe/plans/stripeMonthlyMolecule.ts +20 -0
- package/src/API/resource/payment/platforms/stripe/plans/stripeSingleUseMolecule.ts +21 -0
- package/src/API/resource/payment/platforms/stripe/plans/stripeUnlimitedUseMolecule.ts +21 -0
- package/src/API/resource/payment/platforms/stripe/plans/stripeYearly.ts +21 -0
- package/src/API/resource/payment/types.ts +201 -0
- package/src/API/resource/types.ts +169 -0
- package/src/API/resource/user/index.ts +29 -0
- package/src/API/resource/user/types.ts +131 -0
- package/src/API/resource/user/utilities/getPlan.ts +16 -0
- package/src/API/resource/user/utilities/index.ts +8 -0
- package/src/API/resource/user/utilities/logIn.ts +71 -0
- package/src/commands/add-ssh-key.ts +30 -0
- package/src/commands/buy.ts +83 -0
- package/src/commands/clone.ts +363 -0
- package/src/commands/index.ts +19 -0
- package/src/commands/info.ts +40 -0
- package/src/commands/login.ts +24 -0
- package/src/commands/logout.ts +27 -0
- package/src/commands/remove-ssh-key.ts +42 -0
- package/src/commands/subscribe.ts +84 -0
- package/src/commands/unsubscribe.ts +67 -0
- package/src/commands/utilities/asyncExec.ts +7 -0
- package/src/commands/utilities/branchExists.ts +15 -0
- package/src/commands/utilities/checkoutSelectionBranch.ts +62 -0
- package/src/commands/utilities/cherryPick.ts +23 -0
- package/src/commands/utilities/cloneRepo.ts +10 -0
- package/src/commands/utilities/convertNpmToYarn.ts +71 -0
- package/src/commands/utilities/convertTypeDocToJSDoc.ts +55 -0
- package/src/commands/utilities/convertTypeScriptToJavaScript.ts +526 -0
- package/src/commands/utilities/enableMergeDrivers.ts +55 -0
- package/src/commands/utilities/getCurrentBranch.ts +14 -0
- package/src/commands/utilities/getRepoRootPathSync.ts +13 -0
- package/src/commands/utilities/index.ts +17 -0
- package/src/commands/version.ts +22 -0
- package/src/commands/x-merge-json.ts +41 -0
- package/src/environment.ts +88 -0
- package/src/index.ts +30 -0
- package/src/logger.ts +29 -0
- package/src/pkg.ts +11 -0
- package/src/repoConfig.ts +6 -0
- package/src/types/global.ts +26 -0
- package/src/types/index.ts +53 -0
- package/src/types/process.env.d.ts +56 -0
- package/src/userConfig.ts +6 -0
- package/src/utilities/__tests__/getErrorMessage.ts +32 -0
- package/src/utilities/__tests__/timeAgo.ts +46 -0
- package/src/utilities/checkVersion.ts +31 -0
- package/src/utilities/getErrorMessage.ts +30 -0
- package/src/utilities/index.ts +14 -0
- package/src/utilities/readRepoConfig.ts +22 -0
- package/src/utilities/readUserConfig.ts +24 -0
- package/src/utilities/synchronizeUserConfig.ts +26 -0
- package/src/utilities/timeAgo.ts +39 -0
- package/src/utilities/userLoggedIn.ts +28 -0
- package/src/utilities/writeRepoConfig.ts +11 -0
- package/src/utilities/writeUserConfig.ts +13 -0
- 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,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,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
|
+
}
|