@intlayer/backend 3.2.2 → 3.3.2
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/dist/cjs/controllers/stripe.controller.cjs +110 -5
- package/dist/cjs/controllers/stripe.controller.cjs.map +1 -1
- package/dist/cjs/index.cjs +9 -2
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/middlewares/request.middleware.cjs +0 -4
- package/dist/cjs/middlewares/request.middleware.cjs.map +1 -1
- package/dist/cjs/routes/stripe.routes.cjs +8 -2
- package/dist/cjs/routes/stripe.routes.cjs.map +1 -1
- package/dist/cjs/schemas/plans.schema.cjs +27 -5
- package/dist/cjs/schemas/plans.schema.cjs.map +1 -1
- package/dist/cjs/services/organization.service.cjs +5 -27
- package/dist/cjs/services/organization.service.cjs.map +1 -1
- package/dist/cjs/services/subscription.service.cjs +110 -116
- package/dist/cjs/services/subscription.service.cjs.map +1 -1
- package/dist/cjs/types/plan.types.cjs.map +1 -1
- package/dist/cjs/utils/errors/errorCodes.cjs +107 -3
- package/dist/cjs/utils/errors/errorCodes.cjs.map +1 -1
- package/dist/cjs/utils/plan.cjs +1 -1
- package/dist/cjs/utils/plan.cjs.map +1 -1
- package/dist/cjs/webhooks/stripe.webhook.cjs +102 -89
- package/dist/cjs/webhooks/stripe.webhook.cjs.map +1 -1
- package/dist/esm/controllers/stripe.controller.mjs +99 -5
- package/dist/esm/controllers/stripe.controller.mjs.map +1 -1
- package/dist/esm/index.mjs +10 -3
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/middlewares/request.middleware.mjs +0 -4
- package/dist/esm/middlewares/request.middleware.mjs.map +1 -1
- package/dist/esm/routes/stripe.routes.mjs +12 -3
- package/dist/esm/routes/stripe.routes.mjs.map +1 -1
- package/dist/esm/schemas/plans.schema.mjs +27 -5
- package/dist/esm/schemas/plans.schema.mjs.map +1 -1
- package/dist/esm/services/organization.service.mjs +5 -25
- package/dist/esm/services/organization.service.mjs.map +1 -1
- package/dist/esm/services/subscription.service.mjs +101 -120
- package/dist/esm/services/subscription.service.mjs.map +1 -1
- package/dist/esm/utils/errors/errorCodes.mjs +107 -3
- package/dist/esm/utils/errors/errorCodes.mjs.map +1 -1
- package/dist/esm/utils/plan.mjs +1 -1
- package/dist/esm/utils/plan.mjs.map +1 -1
- package/dist/esm/webhooks/stripe.webhook.mjs +103 -90
- package/dist/esm/webhooks/stripe.webhook.mjs.map +1 -1
- package/dist/types/controllers/stripe.controller.d.ts +14 -0
- package/dist/types/controllers/stripe.controller.d.ts.map +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/routes/stripe.routes.d.ts +6 -1
- package/dist/types/routes/stripe.routes.d.ts.map +1 -1
- package/dist/types/schemas/plans.schema.d.ts.map +1 -1
- package/dist/types/services/organization.service.d.ts +1 -8
- package/dist/types/services/organization.service.d.ts.map +1 -1
- package/dist/types/services/subscription.service.d.ts +5 -21
- package/dist/types/services/subscription.service.d.ts.map +1 -1
- package/dist/types/types/plan.types.d.ts +2 -1
- package/dist/types/types/plan.types.d.ts.map +1 -1
- package/dist/types/utils/errors/errorCodes.d.ts +104 -0
- package/dist/types/utils/errors/errorCodes.d.ts.map +1 -1
- package/dist/types/webhooks/stripe.webhook.d.ts +7 -2
- package/dist/types/webhooks/stripe.webhook.d.ts.map +1 -1
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/webhooks/stripe.webhook.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../../src/webhooks/stripe.webhook.ts"],"sourcesContent":["import { logger } from '@logger';\nimport { getOrganizationById } from '@services/organization.service';\nimport {\n addOrUpdateSubscription,\n cancelSubscription,\n changeSubscriptionStatus,\n} from '@services/subscription.service';\nimport { GenericError } from '@utils/errors';\nimport type { Request, Response } from 'express';\nimport type { Locales } from 'intlayer';\nimport { Stripe } from 'stripe';\nimport type { Plan } from '@/types/plan.types';\n\n// Initialize the Stripe client with the secret key\nconst stripe = new Stripe(process.env.STRIPE_SECRET_KEY!);\n\ntype SubscriptionMetadata = {\n locale: Locales; // Localization setting (e.g., 'en', 'fr', 'es')\n userId: string; // ID of the user associated with the subscription\n organizationId: string; // ID of the organization associated with the subscription\n};\n\n/**\n * Stripe webhook handler for processing subscription and invoice events.\n * @param req - Express request object.\n * @param res - Express response object.\n */\nexport const stripeWebhook = async (req: Request, res: Response) => {\n const endpointSecret = process.env.STRIPE_WEBHOOK_SECRET!; // Webhook secret for verifying event signatures\n const sig = req.headers['stripe-signature']!; // Retrieve the signature from the webhook request headers\n\n let event: Stripe.Event;\n\n // Verify the webhook signature to ensure the request is authentic\n try {\n event = stripe.webhooks.constructEvent(req.body, sig, endpointSecret);\n } catch (err) {\n // Respond with a 400 status code if the signature verification fails\n res.status(400).send(`Webhook Error: ${(err as Error).message}`);\n return;\n }\n\n // Utility function to extract metadata from a Stripe customer\n const extractMetadata = async (customerId: string) => {\n const customer = await stripe.customers.retrieve(customerId); // Retrieve customer details from Stripe\n return (customer as Stripe.Customer).metadata as SubscriptionMetadata; // Return the metadata object\n };\n\n // Handles subscription-related events (creation, update, deletion)\n const handleSubscriptionEvent = async (\n subscription: Stripe.Subscription,\n statusOverride?: Plan['status'] // Optionally override the subscription status\n ) => {\n const { id: subscriptionId, customer } = subscription;\n const priceId = subscription.items.data[0]?.price?.id; // Extract the price ID from subscription items\n\n if (!customer) {\n throw new GenericError('STRIPE_SUBSCRIPTION_NO_CUSTOMER');\n }\n\n const customerId = customer as string;\n const { locale, userId, organizationId } =\n await extractMetadata(customerId); // Extract metadata from the customer\n\n // Set localization in response locals if available\n if (locale) {\n res.locals.locales = locale;\n }\n\n const organization = await getOrganizationById(organizationId); // Fetch organization details by ID\n\n if (!organization) {\n throw new GenericError('ORGANIZATION_NOT_FOUND');\n }\n\n const status = statusOverride ?? subscription.status; // Use the provided status override or the subscription's status\n\n // Update or create a subscription record in the database\n await addOrUpdateSubscription(\n subscriptionId,\n priceId!,\n customerId,\n userId,\n organization,\n status\n );\n };\n\n // Handles invoice-related events (payment success or failure)\n const handleInvoiceEvent = async (\n invoice: Stripe.Invoice,\n status: 'active' | 'incomplete'\n ) => {\n const subscriptionId = invoice.subscription as string; // Extract the subscription ID from the invoice\n if (!subscriptionId) {\n logger.warn('Subscription ID is undefined in invoice.');\n return;\n }\n\n // Retrieve the subscription details from Stripe\n const subscription = await stripe.subscriptions.retrieve(subscriptionId);\n const organization = await getOrganizationById(\n subscription.metadata.organizationId\n );\n\n // Prevent duplicate subscriptions by canceling conflicting subscriptions\n if (\n organization.plan.subscriptionId &&\n organization.plan.subscriptionId !== subscriptionId\n ) {\n await stripe.subscriptions.cancel(subscriptionId);\n }\n\n const customerId = invoice.customer as string;\n const { locale, userId, organizationId } =\n await extractMetadata(customerId);\n\n // Set localization in response locals if available\n if (locale) {\n res.locals.locales = locale;\n }\n\n // Update the subscription status in the database\n await changeSubscriptionStatus(\n subscriptionId,\n status,\n userId,\n organizationId\n );\n };\n\n try {\n // Log the event type for debugging and monitoring\n logger.info(`Triggered event type ${event.type}`);\n\n // Handle specific event types\n switch (event.type) {\n case 'customer.subscription.created': {\n logger.info(`Handled event type ${event.type}`);\n // Process a new subscription creation event\n await handleSubscriptionEvent(event.data.object as Stripe.Subscription);\n break;\n }\n case 'customer.subscription.updated': {\n logger.info(`Handled event type ${event.type}`);\n // Process a subscription update event\n await handleSubscriptionEvent(event.data.object as Stripe.Subscription);\n break;\n }\n case 'customer.subscription.deleted': {\n logger.info(`Handled event type ${event.type}`);\n const subscription = event.data\n .object as unknown as Stripe.Subscription;\n const customerId = subscription.customer as string;\n const { locale, organizationId } = await extractMetadata(customerId);\n\n // Set localization in response locals if available\n if (locale) {\n res.locals.locales = locale;\n }\n\n // Handle subscription deletion by canceling it in the database\n await cancelSubscription(subscription.id, organizationId);\n break;\n }\n case 'invoice.payment_succeeded': {\n logger.info(`Handled event type ${event.type}`);\n // Handle successful invoice payment\n await handleInvoiceEvent(event.data.object as Stripe.Invoice, 'active');\n break;\n }\n case 'invoice.payment_failed': {\n logger.info(`Handled event type ${event.type}`);\n // Handle failed invoice payment\n await handleInvoiceEvent(\n event.data.object as Stripe.Invoice,\n 'incomplete'\n );\n break;\n }\n default:\n // Log unhandled event types for visibility\n logger.info(`Unhandled event type ${event.type}`);\n }\n\n // Respond to Stripe to confirm the event was processed successfully\n res.send();\n } catch (error) {\n // Log errors for debugging and respond with a 500 status code\n logger.error(\n `Error handling event ${event.type}: ${(error as Error).message}`\n );\n res.status(500).send('Server Error');\n }\n};\n"],"mappings":"AAAA,SAAS,cAAc;AACvB,SAAS,2BAA2B;AACpC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,oBAAoB;AAG7B,SAAS,cAAc;AAIvB,MAAM,SAAS,IAAI,OAAO,QAAQ,IAAI,iBAAkB;AAajD,MAAM,gBAAgB,OAAO,KAAc,QAAkB;AAClE,QAAM,iBAAiB,QAAQ,IAAI;AACnC,QAAM,MAAM,IAAI,QAAQ,kBAAkB;AAE1C,MAAI;AAGJ,MAAI;AACF,YAAQ,OAAO,SAAS,eAAe,IAAI,MAAM,KAAK,cAAc;AAAA,EACtE,SAAS,KAAK;AAEZ,QAAI,OAAO,GAAG,EAAE,KAAK,kBAAmB,IAAc,OAAO,EAAE;AAC/D;AAAA,EACF;AAGA,QAAM,kBAAkB,OAAO,eAAuB;AACpD,UAAM,WAAW,MAAM,OAAO,UAAU,SAAS,UAAU;AAC3D,WAAQ,SAA6B;AAAA,EACvC;AAGA,QAAM,0BAA0B,OAC9B,cACA,mBACG;AACH,UAAM,EAAE,IAAI,gBAAgB,SAAS,IAAI;AACzC,UAAM,UAAU,aAAa,MAAM,KAAK,CAAC,GAAG,OAAO;AAEnD,QAAI,CAAC,UAAU;AACb,YAAM,IAAI,aAAa,iCAAiC;AAAA,IAC1D;AAEA,UAAM,aAAa;AACnB,UAAM,EAAE,QAAQ,QAAQ,eAAe,IACrC,MAAM,gBAAgB,UAA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iC;AACpC,eAAO,KAAK,sBAAsB,MAAM,IAAI,EAAE;AAC9C,cAAM,eAAe,MAAM,KACxB;AACH,cAAM,aAAa,aAAa;AAChC,cAAM,EAAE,QAAQ,eAAe,IAAI,MAAM,gBAAgB,UAAU;AAGnE,YAAI,QAAQ;AACV,cAAI,OAAO,UAAU;AAAA,QACvB;AAGA,cAAM,mBAAmB,aAAa,IAAI,cAAc;AACxD;AAAA,MACF;AAAA,MACA,KAAK,6BAA6B;AAChC,eAAO,KAAK,sBAAsB,MAAM,IAAI,EAAE;AAE9C,cAAM,mBAAmB,MAAM,KAAK,QAA0B,QAAQ;AACtE;AAAA,MACF;AAAA,MACA,KAAK,0BAA0B;AAC7B,eAAO,KAAK,sBAAsB,MAAM,IAAI,EAAE;AAE9C,cAAM;AAAA,UACJ,MAAM,KAAK;AAAA,UACX;AAAA,QACF;AACA;AAAA,MACF;AAAA,MACA;AAEE,eAAO,KAAK,wBAAwB,MAAM,IAAI,EAAE;AAAA,IACpD;AAGA,QAAI,KAAK;AAAA,EACX,SAAS,OAAO;AAEd,WAAO;AAAA,MACL,wBAAwB,MAAM,IAAI,KAAM,MAAgB,OAAO;AAAA,IACjE;AACA,QAAI,OAAO,GAAG,EAAE,KAAK,cAAc;AAAA,EACrC;AACF;","names":[]}
|
|
@@ -2,6 +2,7 @@ import { ResponseWithInformation } from '../middlewares/sessionAuth.middleware';
|
|
|
2
2
|
import { ResponseData } from '../utils/responseData';
|
|
3
3
|
import { Request } from 'express';
|
|
4
4
|
import { Stripe } from 'stripe';
|
|
5
|
+
import type { Organization } from '../types/organization.types';
|
|
5
6
|
export type GetCheckoutSessionBody = {
|
|
6
7
|
organizationId: string;
|
|
7
8
|
priceId: string;
|
|
@@ -12,6 +13,19 @@ type CheckoutSessionData = {
|
|
|
12
13
|
status: Stripe.Subscription.Status;
|
|
13
14
|
};
|
|
14
15
|
export type GetCheckoutSessionResult = ResponseData<CheckoutSessionData>;
|
|
16
|
+
/**
|
|
17
|
+
* Handles subscription creation or update with Stripe and returns a ClientSecret.
|
|
18
|
+
* @param req - Express request object.
|
|
19
|
+
* @param res - Express response object.
|
|
20
|
+
*/
|
|
15
21
|
export declare const getSubscription: (req: Request<undefined, undefined, GetCheckoutSessionBody>, res: ResponseWithInformation<GetCheckoutSessionResult>) => Promise<void>;
|
|
22
|
+
type CancelSubscriptionData = Organization['plan'];
|
|
23
|
+
type CancelSubscriptionResult = ResponseData<CancelSubscriptionData>;
|
|
24
|
+
/**
|
|
25
|
+
* Cancels a subscription for an organization.
|
|
26
|
+
* @param _req - Express request object.
|
|
27
|
+
* @param res - Express response object.
|
|
28
|
+
*/
|
|
29
|
+
export declare const cancelSubscription: (_req: Request, res: ResponseWithInformation<CancelSubscriptionResult>) => Promise<void>;
|
|
16
30
|
export {};
|
|
17
31
|
//# sourceMappingURL=stripe.controller.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stripe.controller.d.ts","sourceRoot":"","sources":["../../../src/controllers/stripe.controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;
|
|
1
|
+
{"version":3,"file":"stripe.controller.d.ts","sourceRoot":"","sources":["../../../src/controllers/stripe.controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAI9E,OAAO,EAAkB,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAGlC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAI/D,MAAM,MAAM,sBAAsB,GAAG;IACnC,cAAc,EAAE,MAAM,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,KAAK,mBAAmB,GAAG;IACzB,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC;CACpC,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG,YAAY,CAAC,mBAAmB,CAAC,CAAC;AAEzE;;;;GAIG;AACH,eAAO,MAAM,eAAe,QACrB,OAAO,CAAC,SAAS,EAAE,SAAS,EAAE,sBAAsB,CAAC,OACrD,uBAAuB,CAAC,wBAAwB,CAAC,KACrD,OAAO,CAAC,IAAI,CAkHd,CAAC;AAEF,KAAK,sBAAsB,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;AAEnD,KAAK,wBAAwB,GAAG,YAAY,CAAC,sBAAsB,CAAC,CAAC;AAErE;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,SACvB,OAAO,OACR,uBAAuB,CAAC,wBAAwB,CAAC,KACrD,OAAO,CAAC,IAAI,CA2Ed,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAOA,OAAgB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAOA,OAAgB,EAAE,KAAK,OAAO,EAAE,MAAM,SAAS,CAAC;AA4ChD,QAAA,MAAM,GAAG,EAAE,OAAmB,CAAC;AAgI/B,eAAe,GAAG,CAAC"}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
2
|
export declare const stripeRouter: Router;
|
|
3
3
|
export declare const stripeRoutes: {
|
|
4
|
-
|
|
4
|
+
createSubscription: {
|
|
5
|
+
urlModel: string;
|
|
6
|
+
url: string;
|
|
7
|
+
method: "POST";
|
|
8
|
+
};
|
|
9
|
+
cancelSubscription: {
|
|
5
10
|
urlModel: string;
|
|
6
11
|
url: string;
|
|
7
12
|
method: "POST";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stripe.routes.d.ts","sourceRoot":"","sources":["../../../src/routes/stripe.routes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"stripe.routes.d.ts","sourceRoot":"","sources":["../../../src/routes/stripe.routes.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAGjC,eAAO,MAAM,YAAY,EAAE,MAAiB,CAAC;AAI7C,eAAO,MAAM,YAAY;;;;;;;;;;;CAWP,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plans.schema.d.ts","sourceRoot":"","sources":["../../../src/schemas/plans.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE1C,eAAO,MAAM,UAAU;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"plans.schema.d.ts","sourceRoot":"","sources":["../../../src/schemas/plans.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE1C,eAAO,MAAM,UAAU;;;;;;;;;;;;EAgDtB,CAAC"}
|
|
@@ -47,18 +47,11 @@ export declare const updateOrganizationById: (organizationId: ObjectId | string,
|
|
|
47
47
|
* @returns The result of the deletion operation.
|
|
48
48
|
*/
|
|
49
49
|
export declare const deleteOrganizationById: (organizationId: ObjectId | string) => Promise<OrganizationDocument>;
|
|
50
|
-
export declare const saveStripeCustomerId: (organization: Organization, customerId: string) => Promise<any>;
|
|
51
50
|
/**
|
|
52
51
|
* Updates an existing plan in the database by its ID.
|
|
53
52
|
* @param planId - The ID of the plan to update.
|
|
54
53
|
* @param plan - The updated plan data.
|
|
55
54
|
* @returns The updated plan.
|
|
56
55
|
*/
|
|
57
|
-
export declare const updatePlan: (organization: Organization, plan: Partial<Plan>) => Promise<OrganizationDocument | null>;
|
|
58
|
-
/**
|
|
59
|
-
* Retrieves an organization by its customer ID.
|
|
60
|
-
* @param customerId - The ID of the customer to find the organization.
|
|
61
|
-
* @returns The organizations matching the customer ID.
|
|
62
|
-
*/
|
|
63
|
-
export declare const getOrganizationByCustomerId: (customerId: string) => Promise<OrganizationDocument | null>;
|
|
56
|
+
export declare const updatePlan: (organization: Organization | OrganizationDocument, plan: Partial<Plan>) => Promise<OrganizationDocument | null>;
|
|
64
57
|
//# sourceMappingURL=organization.service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"organization.service.d.ts","sourceRoot":"","sources":["../../../src/services/organization.service.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iEAAiE,CAAC;AAK3G,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,KAAK,EACV,YAAY,EACZ,wBAAwB,EACxB,oBAAoB,EACrB,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,IAAI,
|
|
1
|
+
{"version":3,"file":"organization.service.d.ts","sourceRoot":"","sources":["../../../src/services/organization.service.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iEAAiE,CAAC;AAK3G,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,KAAK,EACV,YAAY,EACZ,wBAAwB,EACxB,oBAAoB,EACrB,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,IAAI,EAAgB,MAAM,oBAAoB,CAAC;AAE7D;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,YACnB,mBAAmB,QACtB,MAAM,SACL,MAAM,KACZ,OAAO,CAAC,oBAAoB,EAAE,CAEhC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,mBACd,QAAQ,GAAG,MAAM,KAChC,OAAO,CAAC,oBAAoB,CAQ9B,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,WAC1B,MAAM,GAAG,QAAQ,KACxB,OAAO,CAAC,oBAAoB,EAAE,GAAG,IAAI,CAMvC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,YACpB,mBAAmB,KAC3B,OAAO,CAAC,MAAM,CAQhB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,iBACf,wBAAwB,UAC9B,MAAM,GAAG,QAAQ,KACxB,OAAO,CAAC,oBAAoB,CAmB9B,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,mBACjB,QAAQ,GAAG,MAAM,gBACnB,OAAO,CAAC,YAAY,CAAC,KAClC,OAAO,CAAC,oBAAoB,CAqB9B,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,mBACjB,QAAQ,GAAG,MAAM,KAChC,OAAO,CAAC,oBAAoB,CAS9B,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,iBACP,YAAY,GAAG,oBAAoB,QAC3C,OAAO,CAAC,IAAI,CAAC,KAClB,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAsBrC,CAAC"}
|
|
@@ -1,22 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Plan } from '../types/plan.types';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* @param customerId - The ID of the customer to add.
|
|
7
|
-
* @param email - The email of the user to add.
|
|
8
|
-
* @param locale - The locale of the user to add.
|
|
9
|
-
* @returns The added plan.
|
|
10
|
-
*/
|
|
11
|
-
export declare const addSubscription: (priceId: string, customerId: string, email: string, locale?: Locales) => Promise<Plan | null>;
|
|
12
|
-
export declare const cancelSubscription: (customerId: string) => Promise<Plan>;
|
|
13
|
-
/**
|
|
14
|
-
* Changes the subscription status of an organization.
|
|
15
|
-
*
|
|
16
|
-
* @param customerId - The ID of the customer to change the subscription status for.
|
|
17
|
-
* @param status - The new status of the subscription.
|
|
18
|
-
* @param locale - The locale of the user to change the subscription status for.
|
|
19
|
-
* @returns The updated plan.
|
|
20
|
-
*/
|
|
21
|
-
export declare const changeSubscriptionStatus: (customerId: string, status: Plan["status"], locale?: Locales) => Promise<Plan>;
|
|
1
|
+
import type { Organization } from '../types/organization.types';
|
|
2
|
+
import type { Plan } from '../types/plan.types';
|
|
3
|
+
export declare const addOrUpdateSubscription: (subscriptionId: string, priceId: string, customerId: string, userId: string, organization: Organization, status: Plan["status"]) => Promise<Plan | null>;
|
|
4
|
+
export declare const cancelSubscription: (subscriptionId: string | Organization["_id"], organizationId: Organization["_id"] | string) => Promise<Plan | null>;
|
|
5
|
+
export declare const changeSubscriptionStatus: (subscriptionId: string, status: Plan["status"], userId: string, organizationId: string) => Promise<Plan | null>;
|
|
22
6
|
//# sourceMappingURL=subscription.service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscription.service.d.ts","sourceRoot":"","sources":["../../../src/services/subscription.service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"subscription.service.d.ts","sourceRoot":"","sources":["../../../src/services/subscription.service.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAI/C,eAAO,MAAM,uBAAuB,mBAClB,MAAM,WACb,MAAM,cACH,MAAM,UACV,MAAM,gBACA,YAAY,UAClB,IAAI,CAAC,QAAQ,CAAC,KACrB,OAAO,CAAC,IAAI,GAAG,IAAI,CAsDrB,CAAC;AAEF,eAAO,MAAM,kBAAkB,mBACb,MAAM,GAAG,YAAY,CAAC,KAAK,CAAC,kBAC5B,YAAY,CAAC,KAAK,CAAC,GAAG,MAAM,KAC3C,OAAO,CAAC,IAAI,GAAG,IAAI,CAmCrB,CAAC;AAEF,eAAO,MAAM,wBAAwB,mBACnB,MAAM,UACd,IAAI,CAAC,QAAQ,CAAC,UACd,MAAM,kBACE,MAAM,KACrB,OAAO,CAAC,IAAI,GAAG,IAAI,CAiFrB,CAAC"}
|
|
@@ -4,9 +4,10 @@ export type PlanType = 'FREE' | 'PREMIUM' | 'ENTERPRISE';
|
|
|
4
4
|
export type PlanData = {
|
|
5
5
|
type: PlanType;
|
|
6
6
|
creatorId?: User['_id'];
|
|
7
|
+
subscriptionId?: string;
|
|
7
8
|
customerId?: string;
|
|
8
9
|
priceId?: string;
|
|
9
|
-
status?: '
|
|
10
|
+
status?: 'active' | 'canceled' | 'past_due' | 'unpaid' | 'incomplete' | 'incomplete_expired' | 'paused' | 'trialing';
|
|
10
11
|
period?: 'MONTHLY' | 'YEARLY';
|
|
11
12
|
};
|
|
12
13
|
export type Plan = PlanData & {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plan.types.d.ts","sourceRoot":"","sources":["../../../src/types/plan.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAEpC,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,SAAS,GAAG,YAAY,CAAC;AAEzD,MAAM,MAAM,QAAQ,GAAG;IACrB,IAAI,EAAE,QAAQ,CAAC;IACf,SAAS,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"plan.types.d.ts","sourceRoot":"","sources":["../../../src/types/plan.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAEpC,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,SAAS,GAAG,YAAY,CAAC;AAEzD,MAAM,MAAM,QAAQ,GAAG;IACrB,IAAI,EAAE,QAAQ,CAAC;IACf,SAAS,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;IACxB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EACH,QAAQ,GACR,UAAU,GACV,UAAU,GACV,QAAQ,GACR,YAAY,GACZ,oBAAoB,GACpB,QAAQ,GACR,UAAU,CAAC;IACf,MAAM,CAAC,EAAE,SAAS,GAAG,QAAQ,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,IAAI,GAAG,QAAQ,GAAG;IAC5B,GAAG,EAAE,QAAQ,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,QAAQ,CAAC,OAAO,EAAE,EAAE,EAAE,IAAI,CAAC,GAAG,IAAI,CAAC"}
|
|
@@ -234,6 +234,32 @@ export declare const errorData: {
|
|
|
234
234
|
};
|
|
235
235
|
statusCode: HttpStatusCodes.NOT_FOUND_404;
|
|
236
236
|
};
|
|
237
|
+
USER_NOT_ORGANIZATION_MEMBER: {
|
|
238
|
+
title: {
|
|
239
|
+
en: string;
|
|
240
|
+
fr: string;
|
|
241
|
+
es: string;
|
|
242
|
+
};
|
|
243
|
+
message: {
|
|
244
|
+
en: string;
|
|
245
|
+
fr: string;
|
|
246
|
+
es: string;
|
|
247
|
+
};
|
|
248
|
+
statusCode: HttpStatusCodes.FORBIDDEN_403;
|
|
249
|
+
};
|
|
250
|
+
USER_NOT_ORGANIZATION_ADMIN: {
|
|
251
|
+
title: {
|
|
252
|
+
en: string;
|
|
253
|
+
fr: string;
|
|
254
|
+
es: string;
|
|
255
|
+
};
|
|
256
|
+
message: {
|
|
257
|
+
en: string;
|
|
258
|
+
fr: string;
|
|
259
|
+
es: string;
|
|
260
|
+
};
|
|
261
|
+
statusCode: HttpStatusCodes.FORBIDDEN_403;
|
|
262
|
+
};
|
|
237
263
|
JWT_TOKEN_CREATION_FAILED_USER: {
|
|
238
264
|
title: {
|
|
239
265
|
en: string;
|
|
@@ -1118,6 +1144,84 @@ export declare const errorData: {
|
|
|
1118
1144
|
};
|
|
1119
1145
|
statusCode: HttpStatusCodes.BAD_REQUEST_400;
|
|
1120
1146
|
};
|
|
1147
|
+
STRIPE_SUBSCRIPTION_NO_CUSTOMER: {
|
|
1148
|
+
title: {
|
|
1149
|
+
en: string;
|
|
1150
|
+
fr: string;
|
|
1151
|
+
es: string;
|
|
1152
|
+
};
|
|
1153
|
+
message: {
|
|
1154
|
+
en: string;
|
|
1155
|
+
fr: string;
|
|
1156
|
+
es: string;
|
|
1157
|
+
};
|
|
1158
|
+
statusCode: HttpStatusCodes.INTERNAL_SERVER_ERROR_500;
|
|
1159
|
+
};
|
|
1160
|
+
NO_SUBSCRIPTION_ID_PROVIDED: {
|
|
1161
|
+
title: {
|
|
1162
|
+
en: string;
|
|
1163
|
+
fr: string;
|
|
1164
|
+
es: string;
|
|
1165
|
+
};
|
|
1166
|
+
message: {
|
|
1167
|
+
en: string;
|
|
1168
|
+
fr: string;
|
|
1169
|
+
es: string;
|
|
1170
|
+
};
|
|
1171
|
+
statusCode: HttpStatusCodes.BAD_REQUEST_400;
|
|
1172
|
+
};
|
|
1173
|
+
CANNOT_CANCEL_SUBSCRIPTION: {
|
|
1174
|
+
title: {
|
|
1175
|
+
en: string;
|
|
1176
|
+
fr: string;
|
|
1177
|
+
es: string;
|
|
1178
|
+
};
|
|
1179
|
+
message: {
|
|
1180
|
+
en: string;
|
|
1181
|
+
fr: string;
|
|
1182
|
+
es: string;
|
|
1183
|
+
};
|
|
1184
|
+
statusCode: HttpStatusCodes.INTERNAL_SERVER_ERROR_500;
|
|
1185
|
+
};
|
|
1186
|
+
ALREADY_SUBSCRIBED: {
|
|
1187
|
+
title: {
|
|
1188
|
+
en: string;
|
|
1189
|
+
fr: string;
|
|
1190
|
+
es: string;
|
|
1191
|
+
};
|
|
1192
|
+
message: {
|
|
1193
|
+
en: string;
|
|
1194
|
+
fr: string;
|
|
1195
|
+
es: string;
|
|
1196
|
+
};
|
|
1197
|
+
statusCode: HttpStatusCodes.BAD_REQUEST_400;
|
|
1198
|
+
};
|
|
1199
|
+
SESSION_CREATION_FAILED: {
|
|
1200
|
+
title: {
|
|
1201
|
+
en: string;
|
|
1202
|
+
fr: string;
|
|
1203
|
+
es: string;
|
|
1204
|
+
};
|
|
1205
|
+
message: {
|
|
1206
|
+
en: string;
|
|
1207
|
+
fr: string;
|
|
1208
|
+
es: string;
|
|
1209
|
+
};
|
|
1210
|
+
statusCode: HttpStatusCodes.INTERNAL_SERVER_ERROR_500;
|
|
1211
|
+
};
|
|
1212
|
+
SETUP_INTENT_CREATION_FAILED: {
|
|
1213
|
+
title: {
|
|
1214
|
+
en: string;
|
|
1215
|
+
fr: string;
|
|
1216
|
+
es: string;
|
|
1217
|
+
};
|
|
1218
|
+
message: {
|
|
1219
|
+
en: string;
|
|
1220
|
+
fr: string;
|
|
1221
|
+
es: string;
|
|
1222
|
+
};
|
|
1223
|
+
statusCode: HttpStatusCodes.INTERNAL_SERVER_ERROR_500;
|
|
1224
|
+
};
|
|
1121
1225
|
};
|
|
1122
1226
|
export type ErrorCodes = keyof typeof errorData;
|
|
1123
1227
|
//# sourceMappingURL=errorCodes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errorCodes.d.ts","sourceRoot":"","sources":["../../../../src/utils/errors/errorCodes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAUzD,eAAO,MAAM,SAAS
|
|
1
|
+
{"version":3,"file":"errorCodes.d.ts","sourceRoot":"","sources":["../../../../src/utils/errors/errorCodes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAysCe,CAAC;AAEtC,MAAM,MAAM,UAAU,GAAG,MAAM,OAAO,SAAS,CAAC"}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import type { Request, Response } from 'express';
|
|
2
|
+
/**
|
|
3
|
+
* Stripe webhook handler for processing subscription and invoice events.
|
|
4
|
+
* @param req - Express request object.
|
|
5
|
+
* @param res - Express response object.
|
|
6
|
+
*/
|
|
7
|
+
export declare const stripeWebhook: (req: Request, res: Response) => Promise<void>;
|
|
3
8
|
//# sourceMappingURL=stripe.webhook.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stripe.webhook.d.ts","sourceRoot":"","sources":["../../../src/webhooks/stripe.webhook.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"stripe.webhook.d.ts","sourceRoot":"","sources":["../../../src/webhooks/stripe.webhook.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAcjD;;;;GAIG;AACH,eAAO,MAAM,aAAa,QAAe,OAAO,OAAO,QAAQ,kBAuK9D,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/backend",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "IntLayer Backend is a an application that allow you to manage your IntLayer content and interact with the intlayer editor.",
|
|
6
6
|
"keywords": [
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
"uuid": "^11.0.3",
|
|
73
73
|
"validator": "^13.12.0",
|
|
74
74
|
"winston": "^3.17.0",
|
|
75
|
-
"express-intlayer": "^3.
|
|
75
|
+
"express-intlayer": "^3.3.2"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
78
|
"@types/bcrypt": "^5.0.2",
|
|
@@ -96,12 +96,12 @@
|
|
|
96
96
|
"tsup": "^8.3.5",
|
|
97
97
|
"tsx": "^4.19.2",
|
|
98
98
|
"typescript": "^5.6.3",
|
|
99
|
-
"@intlayer/core": "^3.
|
|
99
|
+
"@intlayer/core": "^3.3.2",
|
|
100
100
|
"@utils/eslint-config": "^1.0.4",
|
|
101
101
|
"@utils/ts-config": "^1.0.4",
|
|
102
102
|
"@utils/ts-config-types": "^1.0.4",
|
|
103
103
|
"@utils/tsup-config": "^1.0.4",
|
|
104
|
-
"intlayer": "^3.
|
|
104
|
+
"intlayer": "^3.3.2"
|
|
105
105
|
},
|
|
106
106
|
"scripts": {
|
|
107
107
|
"build": "pnpm build:package & pnpm build:types",
|