Skip to content

Commit e99db2b

Browse files
feat: Added bubbleAppUrl a simple way to get the data in bubble app (#1040)
2 parents b9563d2 + 39fc432 commit e99db2b

File tree

13 files changed

+59
-114
lines changed

13 files changed

+59
-114
lines changed

apps/api/src/app/shared/services/bubble-io.service.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ interface IThingsResponse {
1717
export class BubbleIoService extends BubbleBaseService {
1818
async getDatatypeData(data: Omit<BubbleDestinationEntity, '_id' | '_templateId'>) {
1919
try {
20-
const url = this.createBubbleIoUrl(data);
21-
const response = await axios.get<IThingsResponse>(url, {
20+
const response = await axios.get<IThingsResponse>(data.bubbleAppUrl, {
2221
headers: {
2322
Authorization: `Bearer ${data.apiPrivateKey}`,
2423
},

apps/api/src/app/template/commands/update-destination.command.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
} from 'class-validator';
1313
import { Type } from 'class-transformer';
1414
import { BaseCommand } from '@shared/commands/base.command';
15-
import { BubbleDestinationEnvironmentEnum, DestinationsEnum } from '@impler/shared';
15+
import { DestinationsEnum } from '@impler/shared';
1616

1717
export class WebhookDestinationObject {
1818
@IsUrl()
@@ -42,7 +42,7 @@ export class BubbleIoDestinationObject {
4242
@IsString()
4343
@IsDefined()
4444
@ValidateIf((obj) => obj.destination === DestinationsEnum.BUBBLEIO)
45-
appName: string;
45+
bubbleAppUrl: string;
4646

4747
@IsString()
4848
@IsDefined()
@@ -54,15 +54,19 @@ export class BubbleIoDestinationObject {
5454
@ValidateIf((obj) => obj.destination === DestinationsEnum.BUBBLEIO)
5555
datatype: string;
5656

57-
@IsEnum(BubbleDestinationEnvironmentEnum)
58-
@IsDefined()
59-
@ValidateIf((obj) => obj.destination === DestinationsEnum.BUBBLEIO)
60-
environment: BubbleDestinationEnvironmentEnum;
57+
/*
58+
* @IsEnum(BubbleDestinationEnvironmentEnum)
59+
* @IsDefined()
60+
* @ValidateIf((obj) => obj.destination === DestinationsEnum.BUBBLEIO)
61+
* environment: BubbleDestinationEnvironmentEnum;
62+
*/
6163

62-
@IsString()
63-
@IsOptional()
64-
@ValidateIf((obj) => obj.destination === DestinationsEnum.BUBBLEIO)
65-
customDomainName?: string;
64+
/*
65+
* @IsString()
66+
* @IsOptional()
67+
* @ValidateIf((obj) => obj.destination === DestinationsEnum.BUBBLEIO)
68+
* customDomainName?: string;
69+
*/
6670
}
6771

6872
export class UpdateDestinationCommand extends BaseCommand {

apps/api/src/app/template/dtos/destination-response.dto.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ export class DestinationResponseDto {
1010
retryCount?: number;
1111
};
1212
bubbleio?: {
13-
appName: string;
13+
bubbleAppUrl: string;
1414
apiPrivateKey: string;
1515
datatype: string;
16-
environment: string;
17-
customDomainName?: string;
1816
};
1917
}

apps/api/src/app/template/dtos/update-destination-request.dto.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
IsNotEmptyObject,
1111
ValidateNested,
1212
} from 'class-validator';
13-
import { BubbleDestinationEnvironmentEnum, DestinationsEnum } from '@impler/shared';
13+
import { DestinationsEnum } from '@impler/shared';
1414
import { Type } from 'class-transformer';
1515

1616
class WebhookDestinationObject {
@@ -41,7 +41,7 @@ class BubbleIoDestinationObject {
4141
@IsString()
4242
@IsDefined()
4343
@ValidateIf((obj) => obj.destination === DestinationsEnum.BUBBLEIO)
44-
appName: string;
44+
bubbleAppUrl: string;
4545

4646
@IsString()
4747
@IsDefined()
@@ -53,15 +53,19 @@ class BubbleIoDestinationObject {
5353
@ValidateIf((obj) => obj.destination === DestinationsEnum.BUBBLEIO)
5454
datatype: string;
5555

56-
@IsEnum(BubbleDestinationEnvironmentEnum)
57-
@IsDefined()
58-
@ValidateIf((obj) => obj.destination === DestinationsEnum.BUBBLEIO)
59-
environment: BubbleDestinationEnvironmentEnum;
56+
/*
57+
* @IsEnum(BubbleDestinationEnvironmentEnum)
58+
* @IsDefined()
59+
* @ValidateIf((obj) => obj.destination === DestinationsEnum.BUBBLEIO)
60+
* environment: BubbleDestinationEnvironmentEnum;
61+
*/
6062

61-
@IsString()
62-
@IsOptional()
63-
@ValidateIf((obj) => obj.destination === DestinationsEnum.BUBBLEIO)
64-
customDomainName?: string;
63+
/*
64+
* @IsString()
65+
* @IsOptional()
66+
* @ValidateIf((obj) => obj.destination === DestinationsEnum.BUBBLEIO)
67+
* customDomainName?: string;
68+
*/
6569
}
6670

6771
export class UpdateDestinationDto {

apps/queue-manager/src/consumers/send-bubble-data.consumer.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export class SendBubbleDataConsumer extends BaseConsumer {
7676

7777
await this.makeResponseEntry(
7878
response,
79-
{ datatype: cachedData.datatype, environment: cachedData.environment, url: cachedData.bubbleUrl },
79+
{ bubbleAppUrl: cachedData.bubbleUrl, datatype: cachedData.datatype },
8080
cachedData.name,
8181
cachedData.email
8282
);
@@ -142,7 +142,7 @@ export class SendBubbleDataConsumer extends BaseConsumer {
142142
const templateData = await this.templateRepository.findById(uploadata._templateId, 'name');
143143

144144
const bubbleDestination = await this.bubbleDestinationRepository.findOne({ _templateId: uploadata._templateId });
145-
const bubbleUrl = this.bubbleBaseService.createBubbleIoUrl(bubbleDestination, 'bulk');
145+
const bubbleUrl = bubbleDestination.bubbleAppUrl;
146146

147147
const defaultValueObj = {};
148148
const customSchema = JSON.parse(uploadata.customSchema) as ITemplateSchemaItem;
@@ -168,7 +168,6 @@ export class SendBubbleDataConsumer extends BaseConsumer {
168168
email: userEmail,
169169
datatype: bubbleDestination.datatype,
170170
name: templateData.name,
171-
environment: bubbleDestination.environment,
172171
_templateId: uploadata._templateId,
173172
recordFormat: uploadata.customRecordFormat,
174173
defaultValues: JSON.stringify(defaultValueObj),
@@ -179,7 +178,7 @@ export class SendBubbleDataConsumer extends BaseConsumer {
179178

180179
private async makeResponseEntry(
181180
data: Partial<WebhookLogEntity>,
182-
bubbleData: { datatype: string; environment: string; url: string },
181+
bubbleData: { datatype: string; bubbleAppUrl: string },
183182
importName: string,
184183
userEmail: string
185184
) {
@@ -191,8 +190,7 @@ export class SendBubbleDataConsumer extends BaseConsumer {
191190
importName,
192191
time: data.callDate.toString(),
193192
datatype: bubbleData.datatype,
194-
environment: bubbleData.environment,
195-
url: bubbleData.url,
193+
bubbleAppUrl: bubbleData.bubbleAppUrl,
196194
importId: data._uploadId,
197195
},
198196
});

apps/web/components/imports/destination/Destination.tsx

Lines changed: 6 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import { Stack, TextInput as Input, Group, Select } from '@mantine/core';
44

55
import { Button } from '@ui/button';
66
import { NumberInput } from '@ui/number-input';
7-
import { DoaminInput } from '@ui/domain-input';
87
import { DOCUMENTATION_REFERENCE_LINKS, REGULAR_EXPRESSIONS } from '@config';
9-
import { NativeSelect } from '@ui/native-select';
108
import { useDestination } from '@hooks/useDestination';
119
import { DestinationItem } from './DestinationItem';
1210

@@ -16,7 +14,6 @@ interface DestinationProps {
1614

1715
export function Destination({ template }: DestinationProps) {
1816
const {
19-
watch,
2017
errors,
2118
control,
2219
onSubmit,
@@ -45,7 +42,6 @@ export function Destination({ template }: DestinationProps) {
4542
}
4643
}
4744
};
48-
const bubbleDestinationEnvironment = watch('bubbleIo.environment');
4945

5046
return (
5147
<Stack>
@@ -148,48 +144,13 @@ export function Destination({ template }: DestinationProps) {
148144
>
149145
<form onSubmit={onSubmit}>
150146
<Stack spacing="xs">
151-
<Controller
152-
name="bubbleIo.appName"
153-
control={control}
154-
render={({ field }) => (
155-
<DoaminInput
156-
value={field.value}
157-
label="Bubble App Name"
158-
onChange={field.onChange}
159-
rightSection=".bubbleapps.io"
160-
placeholder="Bubble Application Name"
161-
error={errors.bubbleIo?.appName?.message}
162-
/>
163-
)}
164-
/>
165-
166-
<Controller
167-
control={control}
168-
name="bubbleIo.environment"
169-
render={({ field }) => (
170-
<NativeSelect
171-
register={{
172-
value: field.value,
173-
onChange: field.onChange,
174-
}}
175-
required
176-
label="Environment"
177-
data={['development', 'production']}
178-
error={errors.bubbleIo?.environment?.message}
179-
/>
180-
)}
147+
<Input
148+
required
149+
label="Bubble App URL"
150+
placeholder="Bubble App URL"
151+
{...register('bubbleIo.bubbleAppUrl')}
152+
error={errors?.bubbleIo?.bubbleAppUrl?.message}
181153
/>
182-
{bubbleDestinationEnvironment === 'production' && (
183-
<Input
184-
label="Custom Domain Name"
185-
placeholder="Custom Domain Name"
186-
{...register('bubbleIo.customDomainName', {
187-
pattern: /^((?!-)[a-zA-Z0-9-]{1,63}(?<!-)\.)+[a-zA-Z]{2,63}$/,
188-
})}
189-
description="Required, if application is hosted on custom domain. Ex. myapp.io"
190-
error={errors?.bubbleIo?.customDomainName ? 'Please enter valid domain name' : undefined}
191-
/>
192-
)}
193154
<Input
194155
required
195156
label="API Private Key"

apps/web/hooks/useDestination.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ export function useDestination({ template }: UseDestinationProps) {
3030
webhook: {
3131
chunkSize: 100,
3232
},
33-
bubbleIo: {
34-
environment: 'development',
35-
},
3633
},
3734
});
3835
useQuery<unknown, IErrorObject, IDestinationData, [string, string | undefined]>(
@@ -123,20 +120,25 @@ export function useDestination({ template }: UseDestinationProps) {
123120
});
124121
};
125122
const onSubmit = (data: IDestinationData) => {
126-
if (data.destination === DestinationsEnum.BUBBLEIO && !data.bubbleIo?.appName && !data.bubbleIo?.customDomainName) {
123+
console.log(data);
124+
if (
125+
data.destination === DestinationsEnum.BUBBLEIO &&
126+
!data.bubbleIo?.bubbleAppUrl &&
127+
!data.bubbleIo?.apiPrivateKey
128+
) {
127129
setError(
128-
'bubbleIo.appName',
130+
'bubbleIo.bubbleAppUrl',
129131
{
130132
type: 'manual',
131-
message: 'Either App Name or Custom Domain Name is required',
133+
message: 'Bubble App URL is required',
132134
},
133135
{
134136
shouldFocus: true,
135137
}
136138
);
137-
setError('bubbleIo.customDomainName', {
139+
setError('bubbleIo.apiPrivateKey', {
138140
type: 'manual',
139-
message: 'Either App Name or Custom Domain Name is required',
141+
message: 'API Private Key is required',
140142
});
141143

142144
return;

libs/dal/src/repositories/bubble-destination/bubble-destination.entity.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
1-
import { BubbleDestinationEnvironmentEnum } from '@impler/shared';
2-
31
export class BubbleDestinationEntity {
42
_id?: string;
53

6-
appName: string;
7-
8-
customDomainName?: string;
9-
10-
environment: BubbleDestinationEnvironmentEnum;
4+
bubbleAppUrl: string;
115

126
apiPrivateKey: string;
137

libs/dal/src/repositories/bubble-destination/bubble-destination.schema.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,7 @@ import { BubbleDestinationEntity } from './bubble-destination.entity';
44

55
const bubbleDestinationSchema = new Schema(
66
{
7-
appName: {
8-
type: Schema.Types.String,
9-
},
10-
customDomainName: {
11-
type: Schema.Types.String,
12-
},
13-
environment: {
7+
bubbleAppUrl: {
148
type: Schema.Types.String,
159
},
1610
_templateId: {

libs/services/src/bubble/bubble-base.service.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1+
/* eslint-disable multiline-comment-style */
12
import { AxiosError } from 'axios';
2-
import { BubbleDestinationEnvironmentEnum, IBubbleData } from '@impler/shared';
33

44
export class BubbleBaseService {
5-
createBubbleIoUrl(data: IBubbleData, type: 'single' | 'bulk' = 'single'): string {
6-
let url = data.customDomainName ? `https://${data.customDomainName}` : `https://${data.appName}.bubbleapps.io`;
7-
if (data.environment === BubbleDestinationEnvironmentEnum.DEVELOPMENT) url += '/version-test';
8-
9-
return `${url}/api/1.1/obj/${data.datatype}${type === 'bulk' ? '/bulk' : ''}`;
5+
createBubbleIoUrl(bubbleAppUrl: string): string {
6+
return bubbleAppUrl;
107
}
118
throwRequestError(errorWithType: AxiosError) {
129
if ((errorWithType as AxiosError).response) {

0 commit comments

Comments
 (0)