atmn 0.0.19 → 0.0.20

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 (3) hide show
  1. package/dist/cli.cjs +25 -21
  2. package/dist/cli.js +25 -21
  3. package/package.json +1 -1
package/dist/cli.cjs CHANGED
@@ -118,15 +118,15 @@ async function upsertEnvVar(filePath, varName, newValue) {
118
118
  }
119
119
  fs__default.default.writeFileSync(filePath, lines.join("\n"));
120
120
  }
121
- function storeToEnv(prodKey, sandboxKey) {
121
+ async function storeToEnv(prodKey, sandboxKey) {
122
122
  const envPath = `${process.cwd()}/.env`;
123
123
  const envLocalPath = `${process.cwd()}/.env.local`;
124
124
  const envVars = `AUTUMN_PROD_SECRET_KEY=${prodKey}
125
125
  AUTUMN_SECRET_KEY=${sandboxKey}
126
126
  `;
127
127
  if (fs__default.default.existsSync(envPath)) {
128
- upsertEnvVar(envPath, "AUTUMN_PROD_SECRET_KEY", prodKey);
129
- upsertEnvVar(envPath, "AUTUMN_SECRET_KEY", sandboxKey);
128
+ await upsertEnvVar(envPath, "AUTUMN_PROD_SECRET_KEY", prodKey);
129
+ await upsertEnvVar(envPath, "AUTUMN_SECRET_KEY", sandboxKey);
130
130
  console.log(chalk7__default.default.green(".env file found. Updated keys."));
131
131
  } else if (fs__default.default.existsSync(envLocalPath)) {
132
132
  fs__default.default.writeFileSync(envPath, envVars);
@@ -181,9 +181,10 @@ async function request({
181
181
  data,
182
182
  headers,
183
183
  customAuth,
184
- throwOnError = true
184
+ throwOnError = true,
185
+ secretKey
185
186
  }) {
186
- const apiKey = readFromEnv();
187
+ const apiKey = secretKey || readFromEnv();
187
188
  try {
188
189
  const response = await axios__default.default.request({
189
190
  method,
@@ -253,17 +254,16 @@ async function deleteProduct(id) {
253
254
  path: `/products/${id}`
254
255
  });
255
256
  }
256
- async function updateCLIStripeKeys(stripeTestKey, stripeLiveKey, stripeFlowAuthKey) {
257
- return await internalRequest({
257
+ async function updateCLIStripeKeys({
258
+ stripeSecretKey,
259
+ autumnSecretKey
260
+ }) {
261
+ return await request({
262
+ base: EXTERNAL_BASE,
258
263
  method: "POST",
259
- path: "/dev/cli/stripe",
260
- data: {
261
- stripeTestKey,
262
- stripeLiveKey,
263
- successUrl: "https://useautumn.com",
264
- defaultCurrency: "usd"
265
- },
266
- customAuth: stripeFlowAuthKey
264
+ path: "/organization/stripe",
265
+ data: { secret_key: stripeSecretKey },
266
+ secretKey: autumnSecretKey
267
267
  });
268
268
  }
269
269
 
@@ -669,7 +669,7 @@ async function AuthCommand() {
669
669
  const keyInfo = await getOTP(otp);
670
670
  if (!keyInfo.stripe_connected) {
671
671
  let connectStripe = await prompts.confirm({
672
- message: "It seems like your organization doesn't have any Stripe keys connected. Would you like to connect them now?",
672
+ message: "It seems like your organization doesn't have any Stripe keys connected. Would you like to connect your Stripe test secret key now?",
673
673
  theme: inputTheme
674
674
  });
675
675
  if (connectStripe) {
@@ -678,10 +678,14 @@ async function AuthCommand() {
678
678
  mask: "*",
679
679
  theme: passwordTheme
680
680
  });
681
- await updateCLIStripeKeys(
682
- stripeTestKey,
683
- stripeTestKey,
684
- keyInfo.stripeFlowAuthKey
681
+ await updateCLIStripeKeys({
682
+ stripeSecretKey: stripeTestKey,
683
+ autumnSecretKey: keyInfo.sandboxKey
684
+ });
685
+ console.log(
686
+ chalk7__default.default.green(
687
+ "Stripe test secret key has been saved to your .env file. To connect your Stripe live secret key, please visit the Autumn dashboard here: https://app.useautumn.com/dev?tab=stripe"
688
+ )
685
689
  );
686
690
  } else {
687
691
  console.log(
@@ -691,7 +695,7 @@ async function AuthCommand() {
691
695
  );
692
696
  }
693
697
  }
694
- storeToEnv(keyInfo.prodKey, keyInfo.sandboxKey);
698
+ await storeToEnv(keyInfo.prodKey, keyInfo.sandboxKey);
695
699
  console.log(
696
700
  chalk7__default.default.green(
697
701
  "Success! Sandbox and production keys have been saved to your .env file.\n`atmn` uses the AUTUMN_SECRET_KEY to authenticate with the Autumn API."
package/dist/cli.js CHANGED
@@ -100,15 +100,15 @@ async function upsertEnvVar(filePath, varName, newValue) {
100
100
  }
101
101
  fs.writeFileSync(filePath, lines.join("\n"));
102
102
  }
103
- function storeToEnv(prodKey, sandboxKey) {
103
+ async function storeToEnv(prodKey, sandboxKey) {
104
104
  const envPath = `${process.cwd()}/.env`;
105
105
  const envLocalPath = `${process.cwd()}/.env.local`;
106
106
  const envVars = `AUTUMN_PROD_SECRET_KEY=${prodKey}
107
107
  AUTUMN_SECRET_KEY=${sandboxKey}
108
108
  `;
109
109
  if (fs.existsSync(envPath)) {
110
- upsertEnvVar(envPath, "AUTUMN_PROD_SECRET_KEY", prodKey);
111
- upsertEnvVar(envPath, "AUTUMN_SECRET_KEY", sandboxKey);
110
+ await upsertEnvVar(envPath, "AUTUMN_PROD_SECRET_KEY", prodKey);
111
+ await upsertEnvVar(envPath, "AUTUMN_SECRET_KEY", sandboxKey);
112
112
  console.log(chalk7.green(".env file found. Updated keys."));
113
113
  } else if (fs.existsSync(envLocalPath)) {
114
114
  fs.writeFileSync(envPath, envVars);
@@ -163,9 +163,10 @@ async function request({
163
163
  data,
164
164
  headers,
165
165
  customAuth,
166
- throwOnError = true
166
+ throwOnError = true,
167
+ secretKey
167
168
  }) {
168
- const apiKey = readFromEnv();
169
+ const apiKey = secretKey || readFromEnv();
169
170
  try {
170
171
  const response = await axios.request({
171
172
  method,
@@ -235,17 +236,16 @@ async function deleteProduct(id) {
235
236
  path: `/products/${id}`
236
237
  });
237
238
  }
238
- async function updateCLIStripeKeys(stripeTestKey, stripeLiveKey, stripeFlowAuthKey) {
239
- return await internalRequest({
239
+ async function updateCLIStripeKeys({
240
+ stripeSecretKey,
241
+ autumnSecretKey
242
+ }) {
243
+ return await request({
244
+ base: EXTERNAL_BASE,
240
245
  method: "POST",
241
- path: "/dev/cli/stripe",
242
- data: {
243
- stripeTestKey,
244
- stripeLiveKey,
245
- successUrl: "https://useautumn.com",
246
- defaultCurrency: "usd"
247
- },
248
- customAuth: stripeFlowAuthKey
246
+ path: "/organization/stripe",
247
+ data: { secret_key: stripeSecretKey },
248
+ secretKey: autumnSecretKey
249
249
  });
250
250
  }
251
251
 
@@ -651,7 +651,7 @@ async function AuthCommand() {
651
651
  const keyInfo = await getOTP(otp);
652
652
  if (!keyInfo.stripe_connected) {
653
653
  let connectStripe = await confirm({
654
- message: "It seems like your organization doesn't have any Stripe keys connected. Would you like to connect them now?",
654
+ message: "It seems like your organization doesn't have any Stripe keys connected. Would you like to connect your Stripe test secret key now?",
655
655
  theme: inputTheme
656
656
  });
657
657
  if (connectStripe) {
@@ -660,10 +660,14 @@ async function AuthCommand() {
660
660
  mask: "*",
661
661
  theme: passwordTheme
662
662
  });
663
- await updateCLIStripeKeys(
664
- stripeTestKey,
665
- stripeTestKey,
666
- keyInfo.stripeFlowAuthKey
663
+ await updateCLIStripeKeys({
664
+ stripeSecretKey: stripeTestKey,
665
+ autumnSecretKey: keyInfo.sandboxKey
666
+ });
667
+ console.log(
668
+ chalk7.green(
669
+ "Stripe test secret key has been saved to your .env file. To connect your Stripe live secret key, please visit the Autumn dashboard here: https://app.useautumn.com/dev?tab=stripe"
670
+ )
667
671
  );
668
672
  } else {
669
673
  console.log(
@@ -673,7 +677,7 @@ async function AuthCommand() {
673
677
  );
674
678
  }
675
679
  }
676
- storeToEnv(keyInfo.prodKey, keyInfo.sandboxKey);
680
+ await storeToEnv(keyInfo.prodKey, keyInfo.sandboxKey);
677
681
  console.log(
678
682
  chalk7.green(
679
683
  "Success! Sandbox and production keys have been saved to your .env file.\n`atmn` uses the AUTUMN_SECRET_KEY to authenticate with the Autumn API."
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "atmn",
3
- "version": "0.0.19",
3
+ "version": "0.0.20",
4
4
  "license": "MIT",
5
5
  "bin": "dist/cli.js",
6
6
  "main": "dist/index.js",