Complete preliminary addition of infisical-node to support service tokens

This commit is contained in:
Tuan Dang
2023-03-14 16:38:30 +07:00
parent 1e859c19f4
commit 7fd06e36bc
47 changed files with 691 additions and 691 deletions
+19 -16
View File
@@ -1,24 +1,10 @@
import infisical from 'infisical-node';
import * as Sentry from '@sentry/node';
import Stripe from 'stripe';
import {
STRIPE_SECRET_KEY,
STRIPE_PRODUCT_STARTER,
STRIPE_PRODUCT_TEAM,
STRIPE_PRODUCT_PRO
} from '../config';
const stripe = new Stripe(STRIPE_SECRET_KEY, {
apiVersion: '2022-08-01'
});
import { Types } from 'mongoose';
import { ACCEPTED } from '../variables';
import { Organization, MembershipOrg } from '../models';
const productToPriceMap = {
starter: STRIPE_PRODUCT_STARTER,
team: STRIPE_PRODUCT_TEAM,
pro: STRIPE_PRODUCT_PRO
};
/**
* Create an organization with name [name]
* @param {Object} obj
@@ -36,8 +22,11 @@ const createOrganization = async ({
let organization;
try {
// register stripe account
const stripe = new Stripe(infisical.get('STRIPE_SECRET_KEY')!, {
apiVersion: '2022-08-01'
});
if (STRIPE_SECRET_KEY) {
if (infisical.get('STRIPE_SECRET_KEY')) {
const customer = await stripe.customers.create({
email,
description: name
@@ -87,6 +76,16 @@ const initSubscriptionOrg = async ({
if (organization) {
if (organization.customerId) {
// initialize starter subscription with quantity of 0
const stripe = new Stripe(infisical.get('STRIPE_SECRET_KEY')!, {
apiVersion: '2022-08-01'
});
const productToPriceMap = {
starter: infisical.get('STRIPE_PRODUCT_STARTER')!,
team: infisical.get('STRIPE_PRODUCT_TEAM')!,
pro: infisical.get('STRIPE_PRODUCT_PRO')!
};
stripeSubscription = await stripe.subscriptions.create({
customer: organization.customerId,
items: [
@@ -139,6 +138,10 @@ const updateSubscriptionOrgQuantity = async ({
status: ACCEPTED
});
const stripe = new Stripe(infisical.get('STRIPE_SECRET_KEY')!, {
apiVersion: '2022-08-01'
});
const subscription = (
await stripe.subscriptions.list({
customer: organization.customerId