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,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `molecule` API resource.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import { client } from '../../client.js';
|
|
7
|
+
export * as types from './types.js';
|
|
8
|
+
export const read = (id) => (client.get(`molecules/${id}`));
|
|
9
|
+
export const readClone = (id) => (client.get(`molecules/${id}/clone`));
|
|
10
|
+
export const create = (props) => (client.post(`molecules`, props));
|
|
11
|
+
export const update = (id, props) => (client.patch(`molecules/${id}`, props));
|
|
12
|
+
export const updatePlan = (id, { planKey, receipt, quantity }) => (client.patch(`molecules/${id}/plan`, { planKey, receipt, quantity }));
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { plans } from '../../payment/plans.js';
|
|
2
|
+
/**
|
|
3
|
+
* Gets a molecule's current `plan`.
|
|
4
|
+
*/
|
|
5
|
+
export const getPlan = (molecule) => {
|
|
6
|
+
let plan = plans[''];
|
|
7
|
+
const planExpiresTime = (molecule.planExpiresAt && new Date(String(molecule.planExpiresAt)).getTime()) || 0;
|
|
8
|
+
if (molecule.planKey && plans[molecule.planKey] && (!planExpiresTime || (Date.now() < planExpiresTime))) {
|
|
9
|
+
plan = plans[molecule.planKey];
|
|
10
|
+
}
|
|
11
|
+
plan = {
|
|
12
|
+
...plan,
|
|
13
|
+
};
|
|
14
|
+
return plan;
|
|
15
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as platforms from './platforms/index.js';
|
|
2
|
+
const defaultPlan = {
|
|
3
|
+
planKey: ``,
|
|
4
|
+
platformKey: ``,
|
|
5
|
+
platformProductId: ``,
|
|
6
|
+
alias: ``,
|
|
7
|
+
period: ``,
|
|
8
|
+
price: ``,
|
|
9
|
+
title: `Free`,
|
|
10
|
+
description: `Certain features are limited. Upgrade your plan to unlock premium features.`,
|
|
11
|
+
shortDescription: `Limited features and usage.`,
|
|
12
|
+
capabilities: {},
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* A map of every available `planKey` to `plan`.
|
|
16
|
+
*
|
|
17
|
+
* Every plan key for every platform should be unique.
|
|
18
|
+
* E.g., `appleMonthly` and `appleYearly` vs `googleMonthly` and `googleYearly`.
|
|
19
|
+
*
|
|
20
|
+
* You'll need to customize the `Plan` type, adding properties and logic surrounding it
|
|
21
|
+
* as necessary for your particular application.
|
|
22
|
+
*/
|
|
23
|
+
export const plans = {
|
|
24
|
+
'': defaultPlan,
|
|
25
|
+
...platforms.stripe.plans,
|
|
26
|
+
...platforms.google.plans,
|
|
27
|
+
...platforms.apple.plans,
|
|
28
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as platforms from './platforms/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* The payment platform for the current app platform.
|
|
4
|
+
*/
|
|
5
|
+
export const platform = Object.values(platforms).find(platform => (Array.isArray(platform.appPlatforms)
|
|
6
|
+
? platform.appPlatforms.includes(process.env.APP_PLATFORM || undefined)
|
|
7
|
+
: (platform.appPlatforms || undefined) === (process.env.APP_PLATFORM || undefined)));
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Properties and methods for handling payments through Apple.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import * as plans from './plans/index.js';
|
|
7
|
+
/**
|
|
8
|
+
* The Apple Pay payment platform.
|
|
9
|
+
*/
|
|
10
|
+
export const apple = {
|
|
11
|
+
/**
|
|
12
|
+
* An array of app platforms compatible with Apple Pay.
|
|
13
|
+
*/
|
|
14
|
+
appPlatforms: [
|
|
15
|
+
`ios`,
|
|
16
|
+
],
|
|
17
|
+
/**
|
|
18
|
+
* A map of Apple plan keys to plan properties.
|
|
19
|
+
*/
|
|
20
|
+
plans,
|
|
21
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The monthly Apple Pay plan.
|
|
3
|
+
*/
|
|
4
|
+
export const appleMonthly = {
|
|
5
|
+
planKey: `appleMonthly`,
|
|
6
|
+
platformKey: `apple`,
|
|
7
|
+
platformProductId: `molecule_monthly_early_adopter`,
|
|
8
|
+
alias: `monthly`,
|
|
9
|
+
period: `month`,
|
|
10
|
+
price: `$5.99`,
|
|
11
|
+
autoRenews: true,
|
|
12
|
+
title: `Monthly`,
|
|
13
|
+
description: `Create and view attachments.`,
|
|
14
|
+
capabilities: {
|
|
15
|
+
attachments: true,
|
|
16
|
+
}
|
|
17
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The yearly Apple Pay plan.
|
|
3
|
+
*/
|
|
4
|
+
export const appleYearly = {
|
|
5
|
+
planKey: `appleYearly`,
|
|
6
|
+
platformKey: `apple`,
|
|
7
|
+
platformProductId: `molecule_yearly_early_adopter`,
|
|
8
|
+
alias: `yearly`,
|
|
9
|
+
period: `year`,
|
|
10
|
+
price: `$64.99`,
|
|
11
|
+
autoRenews: true,
|
|
12
|
+
title: `Yearly`,
|
|
13
|
+
description: `Create and view attachments.`,
|
|
14
|
+
highlightedDescription: `Get one month free, every year.`,
|
|
15
|
+
capabilities: {
|
|
16
|
+
attachments: true,
|
|
17
|
+
}
|
|
18
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Properties and methods for handling payments through Google.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import * as plans from './plans/index.js';
|
|
7
|
+
/**
|
|
8
|
+
* The Google Pay payment platform.
|
|
9
|
+
*/
|
|
10
|
+
export const google = {
|
|
11
|
+
/**
|
|
12
|
+
* An array of app platforms compatible with Google Pay.
|
|
13
|
+
*/
|
|
14
|
+
appPlatforms: [
|
|
15
|
+
`android`,
|
|
16
|
+
],
|
|
17
|
+
/**
|
|
18
|
+
* A map of Google plan keys to plan properties.
|
|
19
|
+
*/
|
|
20
|
+
plans,
|
|
21
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The monthly Google Pay plan.
|
|
3
|
+
*/
|
|
4
|
+
export const googleMonthly = {
|
|
5
|
+
planKey: `googleMonthly`,
|
|
6
|
+
platformKey: `google`,
|
|
7
|
+
platformProductId: `monthly_early_adopter`,
|
|
8
|
+
alias: `monthly`,
|
|
9
|
+
period: `month`,
|
|
10
|
+
price: `$5.99`,
|
|
11
|
+
autoRenews: true,
|
|
12
|
+
title: `Monthly`,
|
|
13
|
+
description: `Create and view attachments.`,
|
|
14
|
+
capabilities: {
|
|
15
|
+
attachments: true,
|
|
16
|
+
}
|
|
17
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The yearly Google Pay plan.
|
|
3
|
+
*/
|
|
4
|
+
export const googleYearly = {
|
|
5
|
+
planKey: `googleYearly`,
|
|
6
|
+
platformKey: `google`,
|
|
7
|
+
platformProductId: `yearly_early_adopter`,
|
|
8
|
+
alias: `yearly`,
|
|
9
|
+
period: `year`,
|
|
10
|
+
price: `$64.99`,
|
|
11
|
+
autoRenews: true,
|
|
12
|
+
title: `Yearly`,
|
|
13
|
+
description: `Create and view attachments.`,
|
|
14
|
+
highlightedDescription: `Get one month free, every year.`,
|
|
15
|
+
capabilities: {
|
|
16
|
+
attachments: true,
|
|
17
|
+
}
|
|
18
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Properties and methods for handling payments through Stripe.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import * as plans from './plans/index.js';
|
|
7
|
+
/**
|
|
8
|
+
* The Stripe payment platform.
|
|
9
|
+
*/
|
|
10
|
+
export const stripe = {
|
|
11
|
+
/**
|
|
12
|
+
* An array of app platforms compatible with Stripe.
|
|
13
|
+
*/
|
|
14
|
+
appPlatforms: [
|
|
15
|
+
undefined,
|
|
16
|
+
`mac`,
|
|
17
|
+
`windows`,
|
|
18
|
+
`linux`,
|
|
19
|
+
`cli`
|
|
20
|
+
],
|
|
21
|
+
/**
|
|
22
|
+
* A map of Stripe plan keys to plan properties.
|
|
23
|
+
*/
|
|
24
|
+
plans,
|
|
25
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every available Stripe plan.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
export * from './stripeBusinessMolecule.js';
|
|
7
|
+
export * from './stripeMonthly.js';
|
|
8
|
+
export * from './stripeMonthlyMolecule.js';
|
|
9
|
+
export * from './stripeSingleUseMolecule.js';
|
|
10
|
+
export * from './stripeUnlimitedUseMolecule.js';
|
|
11
|
+
export * from './stripeYearly.js';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The business Stripe plan for molecules.
|
|
3
|
+
*/
|
|
4
|
+
export const stripeBusinessMolecule = {
|
|
5
|
+
planKey: `stripeBusinessMolecule`,
|
|
6
|
+
platformKey: `stripe`,
|
|
7
|
+
platformProductId: ``,
|
|
8
|
+
alias: `businessMolecule`,
|
|
9
|
+
period: ``,
|
|
10
|
+
price: `$449`,
|
|
11
|
+
allowMultiple: true,
|
|
12
|
+
minimumQuantity: 10,
|
|
13
|
+
autoRenews: false,
|
|
14
|
+
title: `Business Molecule`,
|
|
15
|
+
description: `Includes all of the core functionality available for full-stack applications.`,
|
|
16
|
+
capabilities: {
|
|
17
|
+
forMolecules: true,
|
|
18
|
+
premium: true,
|
|
19
|
+
attachments: true,
|
|
20
|
+
}
|
|
21
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The monthly Stripe plan.
|
|
3
|
+
*/
|
|
4
|
+
export const stripeMonthly = {
|
|
5
|
+
planKey: `stripeMonthly`,
|
|
6
|
+
platformKey: `stripe`,
|
|
7
|
+
platformProductId: ``,
|
|
8
|
+
alias: `monthly`,
|
|
9
|
+
period: `month`,
|
|
10
|
+
price: `$5`,
|
|
11
|
+
autoRenews: true,
|
|
12
|
+
title: `Monthly`,
|
|
13
|
+
description: `Create and view attachments.`,
|
|
14
|
+
capabilities: {
|
|
15
|
+
forUsers: true,
|
|
16
|
+
attachments: true,
|
|
17
|
+
}
|
|
18
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The monthly Stripe plan for molecules.
|
|
3
|
+
*/
|
|
4
|
+
export const stripeMonthlyMolecule = {
|
|
5
|
+
planKey: `stripeMonthlyMolecule`,
|
|
6
|
+
platformKey: `stripe`,
|
|
7
|
+
platformProductId: ``,
|
|
8
|
+
alias: `monthlyMolecule`,
|
|
9
|
+
period: `month`,
|
|
10
|
+
price: `$19`,
|
|
11
|
+
autoRenews: true,
|
|
12
|
+
title: `Monthly Molecule`,
|
|
13
|
+
description: `Includes all of the core functionality you've selected for your full-stack application.`,
|
|
14
|
+
capabilities: {
|
|
15
|
+
forMolecules: true,
|
|
16
|
+
attachments: true,
|
|
17
|
+
}
|
|
18
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The single use Stripe plan for molecules.
|
|
3
|
+
*/
|
|
4
|
+
export const stripeSingleUseMolecule = {
|
|
5
|
+
planKey: `stripeSingleUseMolecule`,
|
|
6
|
+
platformKey: `stripe`,
|
|
7
|
+
platformProductId: ``,
|
|
8
|
+
alias: `singleUseMolecule`,
|
|
9
|
+
period: ``,
|
|
10
|
+
price: `$499`,
|
|
11
|
+
autoRenews: false,
|
|
12
|
+
title: `Single Use Molecule`,
|
|
13
|
+
description: `Includes all of the core functionality you've selected for your full-stack application.`,
|
|
14
|
+
capabilities: {
|
|
15
|
+
forMolecules: true,
|
|
16
|
+
premium: true,
|
|
17
|
+
attachments: true,
|
|
18
|
+
}
|
|
19
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The unlimited use Stripe plan for molecules.
|
|
3
|
+
*/
|
|
4
|
+
export const stripeUnlimitedUseMolecule = {
|
|
5
|
+
planKey: `stripeUnlimitedUseMolecule`,
|
|
6
|
+
platformKey: `stripe`,
|
|
7
|
+
platformProductId: ``,
|
|
8
|
+
alias: `unlimitedUseMolecule`,
|
|
9
|
+
period: ``,
|
|
10
|
+
price: `$1499`,
|
|
11
|
+
autoRenews: false,
|
|
12
|
+
title: `Unlimited Use Molecule`,
|
|
13
|
+
description: `Includes all of the core functionality you've selected for your full-stack application.`,
|
|
14
|
+
capabilities: {
|
|
15
|
+
forMolecules: true,
|
|
16
|
+
premium: true,
|
|
17
|
+
attachments: true,
|
|
18
|
+
}
|
|
19
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The yearly Stripe plan.
|
|
3
|
+
*/
|
|
4
|
+
export const stripeYearly = {
|
|
5
|
+
planKey: `stripeYearly`,
|
|
6
|
+
platformKey: `stripe`,
|
|
7
|
+
platformProductId: ``,
|
|
8
|
+
alias: `yearly`,
|
|
9
|
+
period: `year`,
|
|
10
|
+
price: `$55`,
|
|
11
|
+
autoRenews: true,
|
|
12
|
+
title: `Yearly`,
|
|
13
|
+
description: `Create and view attachments.`,
|
|
14
|
+
highlightedDescription: `Get one month free, every year.`,
|
|
15
|
+
capabilities: {
|
|
16
|
+
forUsers: true,
|
|
17
|
+
attachments: true,
|
|
18
|
+
}
|
|
19
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The user API resource.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import { client } from '../../client.js';
|
|
7
|
+
import * as authorization from '../../authorization.js';
|
|
8
|
+
export * as utilities from './utilities/index.js';
|
|
9
|
+
export * as types from './types.js';
|
|
10
|
+
export const logInCLI = ({ token, deviceIds, deviceName }) => (client.post(`users/log-in/cli`, { token, deviceIds, deviceName }));
|
|
11
|
+
export const logOut = async () => {
|
|
12
|
+
authorization.removeHeader();
|
|
13
|
+
return null;
|
|
14
|
+
};
|
|
15
|
+
export const read = (id) => (client.get(`users/${id}`));
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { plans } from '../../payment/plans.js';
|
|
2
|
+
/**
|
|
3
|
+
* Gets a user's current `plan`.
|
|
4
|
+
*/
|
|
5
|
+
export const getPlan = (user) => {
|
|
6
|
+
const planKey = user.planKey || ``;
|
|
7
|
+
const planExpiresTime = (user.planExpiresAt && new Date(String(user.planExpiresAt)).getTime()) || 0;
|
|
8
|
+
if (plans[planKey] && Date.now() < planExpiresTime) {
|
|
9
|
+
return plans[planKey];
|
|
10
|
+
}
|
|
11
|
+
return plans[''];
|
|
12
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import os from 'os';
|
|
2
|
+
import open from 'open';
|
|
3
|
+
import { logInCLI } from '../index.js';
|
|
4
|
+
import { getUserIdsToDeviceIds } from '../../../authorization.js';
|
|
5
|
+
import { logger } from '../../../../logger.js';
|
|
6
|
+
import { getErrorMessage } from '../../../../utilities/getErrorMessage.js';
|
|
7
|
+
import { userConfig } from '../../../../userConfig.js';
|
|
8
|
+
import { writeUserConfig } from '../../../../utilities/writeUserConfig.js';
|
|
9
|
+
const CHECK_AFTER = 3000; // 3 seconds
|
|
10
|
+
const MAX_TRIES = 20;
|
|
11
|
+
export const logIn = async () => {
|
|
12
|
+
const deviceIds = Object.values(getUserIdsToDeviceIds());
|
|
13
|
+
const deviceName = `CLI (${os.platform()})`;
|
|
14
|
+
let token = ``;
|
|
15
|
+
try {
|
|
16
|
+
token = (await logInCLI({ deviceIds, deviceName })).data.token || ``;
|
|
17
|
+
if (!token) {
|
|
18
|
+
logger.warn(`No token was returned by the API.`);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
logger.warn(`Error fetching token: ${getErrorMessage(error)}`);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
logger.info(`Opening your browser and waiting for your allowance...`);
|
|
27
|
+
const url = `${process.env.WEB_ORIGIN}/#/allow-auth-token?token=${encodeURIComponent(token)}`;
|
|
28
|
+
const childProcess = await open(url);
|
|
29
|
+
childProcess.on(`error`, error => {
|
|
30
|
+
logger.warn(`Error opening the auth URL: ${getErrorMessage(error)}`);
|
|
31
|
+
logger.warn(`If your browser didn't open on its own, visit the following URL to continue logging in: ${url}`);
|
|
32
|
+
});
|
|
33
|
+
childProcess.on(`close`, code => {
|
|
34
|
+
if (code !== 0) {
|
|
35
|
+
logger.warn(`If your browser didn't open on its own, visit the following URL to continue logging in: ${url}`);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
const check = async (tryCount = 0) => {
|
|
39
|
+
if (tryCount >= MAX_TRIES) {
|
|
40
|
+
logger.info(`Reached maximum number of tries.`);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
await new Promise(resolve => setTimeout(resolve, CHECK_AFTER));
|
|
45
|
+
const user = (await logInCLI({ token, deviceIds, deviceName })).data.props;
|
|
46
|
+
if (user) {
|
|
47
|
+
logger.info(`Hello, ${user.name || user.username}!`);
|
|
48
|
+
userConfig.user = user;
|
|
49
|
+
writeUserConfig();
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
await check(tryCount + 1);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
await check(tryCount + 1);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
await check();
|
|
60
|
+
};
|
package/build/cli.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Molecule.dev command line tools.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import './environment.js';
|
|
8
|
+
import { program } from 'commander';
|
|
9
|
+
import { commands } from './index.js';
|
|
10
|
+
for (const commandKey in commands) {
|
|
11
|
+
if (typeof commands[commandKey] === `function`) {
|
|
12
|
+
commands[commandKey](program);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
program.parse();
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { userConfig } from '../userConfig.js';
|
|
2
|
+
import { userLoggedIn } from '../utilities/userLoggedIn.js';
|
|
3
|
+
import * as API from '../API/index.js';
|
|
4
|
+
import { logger } from '../logger.js';
|
|
5
|
+
/**
|
|
6
|
+
* Adds the `add-ssh-key` command to the program.
|
|
7
|
+
*/
|
|
8
|
+
export const addSshKey = (program) => {
|
|
9
|
+
program.command(`add-ssh-key`)
|
|
10
|
+
.description(`finds or creates \`~/.ssh/id_*.pub\` (using \`ssh-keygen\`) and adds it to your Molecule.dev account for your current CLI device`)
|
|
11
|
+
.argument(`[path]`, `specify the location of the SSH key`)
|
|
12
|
+
.action(async (sshKeyPath = ``) => {
|
|
13
|
+
const user = await userLoggedIn();
|
|
14
|
+
if (!user) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const deviceId = userConfig.userIdsToDeviceIds?.[user.id] || ``;
|
|
18
|
+
if (!deviceId) {
|
|
19
|
+
logger.warn(`No device ID for the current user. Try logging out and in again.`);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
await API.resource.device.utilities.sendSshKey(deviceId, user.username, sshKeyPath);
|
|
23
|
+
});
|
|
24
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import open from 'open';
|
|
2
|
+
import { Argument } from 'commander';
|
|
3
|
+
import { userLoggedIn } from '../utilities/userLoggedIn.js';
|
|
4
|
+
import { repoConfig } from '../repoConfig.js';
|
|
5
|
+
import * as API from '../API/index.js';
|
|
6
|
+
import { logger } from '../logger.js';
|
|
7
|
+
import { getErrorMessage } from '../utilities/getErrorMessage.js';
|
|
8
|
+
import { plans } from '../API/resource/payment/plans.js';
|
|
9
|
+
/**
|
|
10
|
+
* Adds the `buy` command to the program.
|
|
11
|
+
*/
|
|
12
|
+
export const buy = (program) => {
|
|
13
|
+
program.command(`buy`)
|
|
14
|
+
.description(`purchase a license for your Molecule`)
|
|
15
|
+
.addArgument(new Argument(`[license]`, `the type of license`).choices([`single`, `unlimited`, `business`]))
|
|
16
|
+
.addArgument(new Argument(`[quantity]`, `the quantity for the business license (at least ${plans.stripeBusinessMolecule.minimumQuantity})`))
|
|
17
|
+
.action(async (license, quantity = 1) => {
|
|
18
|
+
if (!license) {
|
|
19
|
+
logger.info(`Usage:`);
|
|
20
|
+
logger.info(` mlcl buy single - one app with this Molecule`);
|
|
21
|
+
logger.info(` mlcl buy unlimited - unlimited apps with this Molecule`);
|
|
22
|
+
logger.info(` mlcl buy business <quantity> - at least 10 apps with any Molecule`);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const user = await userLoggedIn();
|
|
26
|
+
if (!user) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (!repoConfig?.id) {
|
|
30
|
+
logger.warn(`Not within a Molecule repository or \`.mlclrc.json\` not found.`);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const planKey = ({
|
|
34
|
+
single: `stripeSingleUseMolecule`,
|
|
35
|
+
unlimited: `stripeUnlimitedUseMolecule`,
|
|
36
|
+
business: `stripeBusinessMolecule`,
|
|
37
|
+
})[license || ``];
|
|
38
|
+
if (!planKey || !plans[planKey]) {
|
|
39
|
+
logger.warn(`Unknown license option.`);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
quantity = Math.max(plans[planKey]?.minimumQuantity || 1, Math.round(Number(quantity) || 1));
|
|
44
|
+
const molecule = (await API.resource.molecule.read(repoConfig.id)).data.props;
|
|
45
|
+
if (!molecule) {
|
|
46
|
+
throw new Error(`Failed to fetch Molecule by ID ${repoConfig.id}.`);
|
|
47
|
+
}
|
|
48
|
+
const { checkoutUrl } = (await API.resource.molecule.updatePlan(molecule.id, { planKey, quantity })).data;
|
|
49
|
+
if (checkoutUrl) {
|
|
50
|
+
logger.info(`Opening your browser to complete checkout via Stripe...`);
|
|
51
|
+
const childProcess = await open(checkoutUrl);
|
|
52
|
+
childProcess.on(`error`, error => {
|
|
53
|
+
logger.warn(`Error opening the checkout URL: ${getErrorMessage(error)}`);
|
|
54
|
+
logger.warn(`If your browser didn't open on its own, visit the following URL: ${checkoutUrl}`);
|
|
55
|
+
});
|
|
56
|
+
childProcess.on(`close`, code => {
|
|
57
|
+
if (code !== 0) {
|
|
58
|
+
logger.warn(`If your browser didn't open on its own, visit the following URL: ${checkoutUrl}`);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
throw new Error(`Unexpected response. Please contact developer-support@molecule.dev so we can fix this.`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
logger.warn(`Something went wrong. ${getErrorMessage(error)}`);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
};
|