Skip to content

Commit a5a44b8

Browse files
authored
feat: buildkit tools limit (#58)
1 parent 765d778 commit a5a44b8

File tree

5 files changed

+55
-0
lines changed

5 files changed

+55
-0
lines changed

apps/event-system/services/stripe/stripe-webhook.service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export default {
2323

2424
actions: {
2525
async handleWebhook(ctx: any) {
26+
2627
try {
2728
const rawBody = ctx?.options?.parentCtx?.params?.req?.rawBody;
2829
const signature = ctx?.meta?.request?.headers['stripe-signature'];
@@ -63,6 +64,7 @@ export default {
6364
if (key && subscriptionCreated?.status === 'active') {
6465
const billing = {
6566
throughput: parseInt(process.env.DEFAULT_CLIENT_THROUGHPUT) || 500,
67+
buildKitIntegrationLimit: parseInt(process.env.DEFAULT_CLIENT_BUILDKIT_INTEGRATION_LIMIT) || 3,
6668
provider: 'stripe',
6769
customerId: subscriptionCreated?.customer,
6870
subscription: {
@@ -105,6 +107,7 @@ export default {
105107

106108
const billing = {
107109
throughput: parseInt(process.env.DEFAULT_CLIENT_THROUGHPUT) || 500,
110+
buildKitIntegrationLimit: parseInt(process.env.DEFAULT_CLIENT_BUILDKIT_INTEGRATION_LIMIT) || 3,
108111
provider: 'stripe',
109112
customerId: subscriptionUpdated?.customer,
110113
subscription: {
@@ -162,6 +165,7 @@ export default {
162165

163166
const updatedBilling = {
164167
throughput: parseInt(process.env.DEFAULT_CLIENT_THROUGHPUT) || 500,
168+
buildKitIntegrationLimit: parseInt(process.env.DEFAULT_CLIENT_BUILDKIT_INTEGRATION_LIMIT) || 3,
165169
provider: 'stripe',
166170
customerId: subscriptionCreated?.customer,
167171
subscription: {

libs-private/service-logic/generators/settings/linkSettings.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,16 @@ export const generateSettingsRecord = ({
99
ownership,
1010
features,
1111
platforms,
12+
buildKitIntegrations,
1213
}: {
1314
ownership: Ownership;
1415
features?: Feature[];
1516
platforms: Platform[];
17+
buildKitIntegrations?: {
18+
connectionDefinitionId: string;
19+
platformName: string;
20+
environment: 'test' | 'live';
21+
}[]
1622
}): Settings => {
1723
return {
1824
createdAt: Date.now(),
@@ -22,5 +28,6 @@ export const generateSettingsRecord = ({
2228
updatedDate: new Date(),
2329
connectedPlatforms: platforms,
2430
features,
31+
buildKitIntegrations,
2532
};
2633
};

libs-private/service-logic/services/onboarding/useOnboardingService.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export const useOnboardingService = (ctx: Context, ownership: Ownership) => {
3838
const billing = {
3939
throughput: parseInt(process.env.DEFAULT_CLIENT_THROUGHPUT) || 500,
4040
customerId: response?.customer?.id,
41+
buildKitIntegrationLimit: parseInt(process.env.DEFAULT_CLIENT_BUILDKIT_INTEGRATION_LIMIT) || 3,
4142
subscription: {
4243
id: response?.subscription?.id,
4344
endDate: response?.subscription?.current_period_end,

libs-private/service-logic/services/settings/useSettingsService.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
Platform,
1010
LinkSettings as Settings,
1111
Feature,
12+
BuildKitIntegration,
1213
} from '@event-inc/types/settings';
1314
import EventAccess from '@apps/event-system/services/events/event-access.service';
1415
import { BResult, ConnectionDefinitions } from '@event-inc/types';
@@ -58,13 +59,15 @@ export const useSettingsService = (ctx: Context, ownership: Ownership) => {
5859
platform,
5960
configuration,
6061
features,
62+
buildKitIntegration,
6163
}: {
6264
platform?: Platform;
6365
configuration?: {
6466
CLIENT_ID: string;
6567
CLIENT_SECRET: string;
6668
};
6769
features?: Feature[];
70+
buildKitIntegration?: BuildKitIntegration;
6871
}): Promise<BResult<boolean, 'service', unknown>> {
6972
try {
7073
const settingsRecord = (await _list()).unwrap().rows[0] as Settings;
@@ -112,11 +115,32 @@ export const useSettingsService = (ctx: Context, ownership: Ownership) => {
112115
}
113116
}
114117

118+
if (buildKitIntegration) {
119+
if (!settingsRecord.buildKitIntegrations) {
120+
settingsRecord.buildKitIntegrations = [];
121+
}
122+
123+
if (buildKitIntegration.active) {
124+
settingsRecord.buildKitIntegrations.push({
125+
connectionDefinitionId: buildKitIntegration.connectionDefinitionId,
126+
environment: buildKitIntegration.environment,
127+
platformName: buildKitIntegration.platformName,
128+
});
129+
} else {
130+
settingsRecord.buildKitIntegrations = settingsRecord.buildKitIntegrations.filter(
131+
integration =>
132+
!(integration.connectionDefinitionId === buildKitIntegration.connectionDefinitionId &&
133+
integration.environment === buildKitIntegration.environment)
134+
);
135+
}
136+
}
137+
115138
await updateById(settingsRecord._id, {
116139
connectedPlatforms: settingsRecord.connectedPlatforms,
117140
updatedAt: new Date().getTime(),
118141
updatedDate: new Date().toISOString(),
119142
features: features?.length ? features : settingsRecord.features,
143+
buildKitIntegrations: settingsRecord.buildKitIntegrations || [],
120144
});
121145

122146
return resultOk(true);
@@ -126,6 +150,7 @@ export const useSettingsService = (ctx: Context, ownership: Ownership) => {
126150
ownership,
127151
platforms: [platform],
128152
features: [],
153+
buildKitIntegrations: []
129154
});
130155

131156
await _create<Settings>('st', settings);
@@ -177,6 +202,7 @@ export const useSettingsService = (ctx: Context, ownership: Ownership) => {
177202
ownership,
178203
platforms,
179204
features: [],
205+
buildKitIntegrations: [],
180206
});
181207

182208
await _create<Settings>('st', settings);

packages/types/settings.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ export interface Platform {
1717
environment?: 'test' | 'live';
1818
}
1919

20+
export interface BuildKitIntegration {
21+
connectionDefinitionId: string;
22+
active: boolean;
23+
environment: 'test' | 'live';
24+
platformName: string;
25+
}
26+
2027
export interface Feature {
2128
key: string;
2229
value: 'enabled' | 'disabled';
@@ -32,6 +39,11 @@ export interface LinkSettings {
3239
createdDate: Date;
3340
updatedDate: Date;
3441
features?: Feature[];
42+
buildKitIntegrations?: {
43+
connectionDefinitionId: string;
44+
environment: 'test' | 'live';
45+
platformName: string;
46+
}[]
3547
}
3648

3749
export interface ListLinkSettings {
@@ -49,4 +61,9 @@ export interface CreateSettingPayload {
4961
CLIENT_SECRET: string;
5062
};
5163
features?: Feature[];
64+
buildKitIntegrations?: {
65+
connectionDefinitionId: string;
66+
environment: 'test' | 'live';
67+
platformName: string;
68+
}[];
5269
}

0 commit comments

Comments
 (0)