mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-10 07:48:37 +01:00
partial configs for docker
This commit is contained in:
@@ -25,6 +25,7 @@ export default defineEventHandler(async event => {
|
|||||||
return await Redis.useCache({ key: `invoices:${project_id}`, exp: 10 }, async () => {
|
return await Redis.useCache({ key: `invoices:${project_id}`, exp: 10 }, async () => {
|
||||||
|
|
||||||
const invoices = await StripeService.getInvoices(project.customer_id);
|
const invoices = await StripeService.getInvoices(project.customer_id);
|
||||||
|
if (!invoices) return [];
|
||||||
|
|
||||||
return invoices?.data.map(e => {
|
return invoices?.data.map(e => {
|
||||||
const result: InvoiceData = {
|
const result: InvoiceData = {
|
||||||
@@ -37,6 +38,7 @@ export default defineEventHandler(async event => {
|
|||||||
return result;
|
return result;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
@@ -29,7 +29,7 @@ export default defineEventHandler(async event => {
|
|||||||
billing_expire_at: projectLimits.billing_expire_at,
|
billing_expire_at: projectLimits.billing_expire_at,
|
||||||
limit: projectLimits.limit,
|
limit: projectLimits.limit,
|
||||||
count: projectLimits.events + projectLimits.visits,
|
count: projectLimits.events + projectLimits.visits,
|
||||||
subscription_status: subscription.status
|
subscription_status: StripeService.isDisabled() ? 'Disabled mode' : (subscription?.status ?? '?')
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -10,15 +10,19 @@ export default async () => {
|
|||||||
|
|
||||||
console.log('[SERVER] Initializing');
|
console.log('[SERVER] Initializing');
|
||||||
|
|
||||||
EmailService.createTransport(
|
if (config.EMAIL_SERVICE) {
|
||||||
config.EMAIL_SERVICE,
|
EmailService.createTransport(config.EMAIL_SERVICE, config.EMAIL_HOST, config.EMAIL_USER, config.EMAIL_PASS);
|
||||||
config.EMAIL_HOST,
|
console.log('[EMAIL] Initialized')
|
||||||
config.EMAIL_USER,
|
}
|
||||||
config.EMAIL_PASS,
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
StripeService.init(config.STRIPE_SECRET, config.STRIPE_WH_SECRET, false);
|
if (config.STRIPE_SECRET) {
|
||||||
|
StripeService.init(config.STRIPE_SECRET, config.STRIPE_WH_SECRET, false);
|
||||||
|
console.log('[STRIPE] Initialized')
|
||||||
|
} else {
|
||||||
|
StripeService.disable();
|
||||||
|
console.log('[STRIPE] No stripe key - Disabled mode')
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!connection || connection.connection.readyState == mongoose.ConnectionStates.disconnected) {
|
if (!connection || connection.connection.readyState == mongoose.ConnectionStates.disconnected) {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ class StripeService {
|
|||||||
private privateKey?: string;
|
private privateKey?: string;
|
||||||
private webhookSecret?: string;
|
private webhookSecret?: string;
|
||||||
public testMode?: boolean;
|
public testMode?: boolean;
|
||||||
|
private disabledMode: boolean = false;
|
||||||
|
|
||||||
init(privateKey: string, webhookSecret: string, testMode: boolean = false) {
|
init(privateKey: string, webhookSecret: string, testMode: boolean = false) {
|
||||||
this.privateKey = privateKey;
|
this.privateKey = privateKey;
|
||||||
@@ -14,7 +15,12 @@ class StripeService {
|
|||||||
this.testMode = testMode;
|
this.testMode = testMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
disable() { this.disabledMode = true; }
|
||||||
|
enable() { this.disabledMode = false; }
|
||||||
|
isDisabled() { return this.disabledMode; }
|
||||||
|
|
||||||
parseWebhook(body: any, sig: string) {
|
parseWebhook(body: any, sig: string) {
|
||||||
|
if (this.disabledMode) return;
|
||||||
if (!this.stripe) throw Error('Stripe not initialized');
|
if (!this.stripe) throw Error('Stripe not initialized');
|
||||||
if (!this.webhookSecret) {
|
if (!this.webhookSecret) {
|
||||||
console.error('Stripe not initialized')
|
console.error('Stripe not initialized')
|
||||||
@@ -24,6 +30,7 @@ class StripeService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async cretePayment(price: string, success_url: string, pid: string, customer?: string) {
|
async cretePayment(price: string, success_url: string, pid: string, customer?: string) {
|
||||||
|
if (this.disabledMode) return;
|
||||||
if (!this.stripe) throw Error('Stripe not initialized');
|
if (!this.stripe) throw Error('Stripe not initialized');
|
||||||
|
|
||||||
const checkout = await this.stripe.checkout.sessions.create({
|
const checkout = await this.stripe.checkout.sessions.create({
|
||||||
@@ -44,42 +51,50 @@ class StripeService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async deleteSubscription(subscriptionId: string) {
|
async deleteSubscription(subscriptionId: string) {
|
||||||
|
if (this.disabledMode) return;
|
||||||
if (!this.stripe) throw Error('Stripe not initialized');
|
if (!this.stripe) throw Error('Stripe not initialized');
|
||||||
const subscription = await this.stripe.subscriptions.cancel(subscriptionId);
|
const subscription = await this.stripe.subscriptions.cancel(subscriptionId);
|
||||||
return subscription;
|
return subscription;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getSubscription(subscriptionId: string) {
|
async getSubscription(subscriptionId: string) {
|
||||||
|
if (this.disabledMode) return;
|
||||||
if (!this.stripe) throw Error('Stripe not initialized');
|
if (!this.stripe) throw Error('Stripe not initialized');
|
||||||
const subscription = await this.stripe.subscriptions.retrieve(subscriptionId);
|
const subscription = await this.stripe.subscriptions.retrieve(subscriptionId);
|
||||||
return subscription;
|
return subscription;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getAllSubscriptions(customer_id: string) {
|
async getAllSubscriptions(customer_id: string) {
|
||||||
|
if (this.disabledMode) return;
|
||||||
if (!this.stripe) throw Error('Stripe not initialized');
|
if (!this.stripe) throw Error('Stripe not initialized');
|
||||||
const subscriptions = await this.stripe.subscriptions.list({customer: customer_id});
|
const subscriptions = await this.stripe.subscriptions.list({ customer: customer_id });
|
||||||
return subscriptions;
|
return subscriptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getInvoices(customer_id: string) {
|
async getInvoices(customer_id: string) {
|
||||||
|
if (this.disabledMode) return;
|
||||||
|
if (!this.stripe) throw Error('Stripe not initialized');
|
||||||
const invoices = await this.stripe?.invoices.list({ customer: customer_id });
|
const invoices = await this.stripe?.invoices.list({ customer: customer_id });
|
||||||
return invoices;
|
return invoices;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async getCustomer(customer_id: string) {
|
async getCustomer(customer_id: string) {
|
||||||
|
if (this.disabledMode) return;
|
||||||
if (!this.stripe) throw Error('Stripe not initialized');
|
if (!this.stripe) throw Error('Stripe not initialized');
|
||||||
const customer = await this.stripe.customers.retrieve(customer_id, { expand: [] })
|
const customer = await this.stripe.customers.retrieve(customer_id, { expand: [] })
|
||||||
return customer;
|
return customer;
|
||||||
}
|
}
|
||||||
|
|
||||||
async createCustomer(email: string) {
|
async createCustomer(email: string) {
|
||||||
|
if (this.disabledMode) return;
|
||||||
if (!this.stripe) throw Error('Stripe not initialized');
|
if (!this.stripe) throw Error('Stripe not initialized');
|
||||||
const customer = await this.stripe.customers.create({ email });
|
const customer = await this.stripe.customers.create({ email });
|
||||||
return customer;
|
return customer;
|
||||||
}
|
}
|
||||||
|
|
||||||
async deleteCustomer(customer_id: string) {
|
async deleteCustomer(customer_id: string) {
|
||||||
|
if (this.disabledMode) return;
|
||||||
if (!this.stripe) throw Error('Stripe not initialized');
|
if (!this.stripe) throw Error('Stripe not initialized');
|
||||||
const { deleted } = await this.stripe.customers.del(customer_id);
|
const { deleted } = await this.stripe.customers.del(customer_id);
|
||||||
return deleted;
|
return deleted;
|
||||||
@@ -89,6 +104,7 @@ class StripeService {
|
|||||||
|
|
||||||
|
|
||||||
async createFreeSubscription(customer_id: string) {
|
async createFreeSubscription(customer_id: string) {
|
||||||
|
if (this.disabledMode) return;
|
||||||
if (!this.stripe) throw Error('Stripe not initialized');
|
if (!this.stripe) throw Error('Stripe not initialized');
|
||||||
|
|
||||||
const FREE_PLAN = getPlanFromTag('FREE');
|
const FREE_PLAN = getPlanFromTag('FREE');
|
||||||
|
|||||||
@@ -37,10 +37,14 @@ services:
|
|||||||
ports:
|
ports:
|
||||||
- "3999:3999"
|
- "3999:3999"
|
||||||
environment:
|
environment:
|
||||||
|
|
||||||
|
# Optional - Used to send welcome and quota emails
|
||||||
|
|
||||||
# EMAIL_SERVICE: ""
|
# EMAIL_SERVICE: ""
|
||||||
# EMAIL_HOST: ""
|
# EMAIL_HOST: ""
|
||||||
# EMAIL_USER: ""
|
# EMAIL_USER: ""
|
||||||
# EMAIL_PASS: ""
|
# EMAIL_PASS: ""
|
||||||
|
|
||||||
PORT: "3999"
|
PORT: "3999"
|
||||||
MONGO_CONNECTION_STRING: "mongodb://litlyx:litlyx@mongo:27017/SimpleMetrics?readPreference=primaryPreferred&authSource=admin"
|
MONGO_CONNECTION_STRING: "mongodb://litlyx:litlyx@mongo:27017/SimpleMetrics?readPreference=primaryPreferred&authSource=admin"
|
||||||
REDIS_URL: "redis://cache"
|
REDIS_URL: "redis://cache"
|
||||||
@@ -63,9 +67,15 @@ services:
|
|||||||
NUXT_REDIS_USERNAME: "default"
|
NUXT_REDIS_USERNAME: "default"
|
||||||
NUXT_REDIS_PASSWORD: "litlyx"
|
NUXT_REDIS_PASSWORD: "litlyx"
|
||||||
|
|
||||||
NUXT_AI_ORG: 'OPEN_AI_ORGANIZATION'
|
|
||||||
NUXT_AI_PROJECT: 'OPEN_AI_PROJECT'
|
# Optional - Used to use Lit, the AI analyst
|
||||||
NUXT_AI_KEY: 'OPEN_AI_KEY'
|
|
||||||
|
# NUXT_AI_ORG: 'OPEN_AI_ORGANIZATION'
|
||||||
|
# NUXT_AI_PROJECT: 'OPEN_AI_PROJECT'
|
||||||
|
# NUXT_AI_KEY: 'OPEN_AI_KEY'
|
||||||
|
|
||||||
|
|
||||||
|
# Optional - Used to send welcome and quota emails
|
||||||
|
|
||||||
# NUXT_EMAIL_SERVICE: ""
|
# NUXT_EMAIL_SERVICE: ""
|
||||||
# NUXT_EMAIL_HOST: ""
|
# NUXT_EMAIL_HOST: ""
|
||||||
@@ -74,14 +84,24 @@ services:
|
|||||||
|
|
||||||
NUXT_AUTH_JWT_SECRET: "litlyx_jwt_secret"
|
NUXT_AUTH_JWT_SECRET: "litlyx_jwt_secret"
|
||||||
|
|
||||||
NUXT_GOOGLE_AUTH_CLIENT_ID: "GOOGLE_AUTH_CLIENT_ID"
|
|
||||||
NUXT_GOOGLE_AUTH_CLIENT_SECRET: "GOOGLE_AUTH_CLIENT_SECRET"
|
|
||||||
|
|
||||||
NUXT_STRIPE_SECRET_TEST: "STRIPE_SECRET_TEST"
|
# Optional - Used to register / login
|
||||||
NUXT_STRIPE_WH_SECRET_TEST: "STRIPE_WEBHOOK_SECRET_TEST"
|
|
||||||
|
# NUXT_GOOGLE_AUTH_CLIENT_ID: ""
|
||||||
|
# NUXT_GOOGLE_AUTH_CLIENT_SECRET: ""
|
||||||
|
|
||||||
|
|
||||||
|
# Optional - Used for tests
|
||||||
|
|
||||||
|
# NUXT_STRIPE_SECRET_TEST: ""
|
||||||
|
# NUXT_STRIPE_WH_SECRET_TEST: ""
|
||||||
|
|
||||||
|
|
||||||
|
# Optional - Stripe secret - Used to change plans of the projects
|
||||||
|
|
||||||
|
#NUXT_STRIPE_SECRET: ""
|
||||||
|
#NUXT_STRIPE_WH_SECRET: ""
|
||||||
|
|
||||||
NUXT_STRIPE_SECRET: "STRIPE_SECRET"
|
|
||||||
NUXT_STRIPE_WH_SECRET: "STRIPE_WEBHOOK_SECRET"
|
|
||||||
build:
|
build:
|
||||||
dockerfile: ./dashboard/Dockerfile
|
dockerfile: ./dashboard/Dockerfile
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user