Skip to content

Commit 9cfabc9

Browse files
author
Mayur
committed
feat: Added Enhancements in Bubble io import
1 parent fbec306 commit 9cfabc9

File tree

5 files changed

+38
-6
lines changed

5 files changed

+38
-6
lines changed

apps/api/src/app/shared/constants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ export const APIMessages = {
4242
ONBOARD_TEMPLATE_SHEET_NOT_FOUND: 'No sheets found in the workbook',
4343
ONBOARD_TEMPLATE_FILE_EMPTY: 'File is empty or invalid',
4444
ONBOARD_TEMPLATE_FILE_EMPTY_RECORDS: 'The file contains empty records',
45+
46+
INVALID_API_RESPONSE_STRUCTURE: `Invalid API response structure. Please recheck the URL and ensure the API is correctly configured to return data.`,
47+
DATATYPE_EMPTY: `The datatype appears to be empty. Please add at least one entry and verify the URL points to the correct data source.`,
4548
};
4649

4750
export const CONSTANTS = {

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Injectable } from '@nestjs/common';
33
import { BubbleBaseService } from '@impler/services';
44
import { BubbleDestinationEntity } from '@impler/dal';
55
import { ColumnTypesEnum, DEFAULT_KEYS_OBJ, IColumn } from '@impler/shared';
6+
import { APIMessages } from '@shared/constants';
67

78
interface IThingsResponse {
89
response: {
@@ -17,13 +18,19 @@ interface IThingsResponse {
1718
export class BubbleIoService extends BubbleBaseService {
1819
async getDatatypeData(data: Omit<BubbleDestinationEntity, '_id' | '_templateId'>) {
1920
try {
20-
const response = await axios.get<IThingsResponse>(data.bubbleAppUrl, {
21+
const response = await axios.get<IThingsResponse>(this.createBubbleIoUrl(data.bubbleAppUrl), {
2122
headers: {
2223
Authorization: `Bearer ${data.apiPrivateKey}`,
2324
},
2425
});
25-
if (!response.data.response.results.length)
26-
throw new Error('Datatype is empty. Please add at least one entry to the datatype');
26+
27+
if (!Array.isArray(response.data.response.results)) {
28+
throw new Error(APIMessages.INVALID_API_RESPONSE_STRUCTURE);
29+
}
30+
31+
if (response.data.response.results.length === 0) {
32+
throw new Error(APIMessages.DATATYPE_EMPTY);
33+
}
2734

2835
return response.data.response.results;
2936
} catch (error: unknown) {

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,23 @@ 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 = bubbleDestination.bubbleAppUrl;
145+
let bubbleUrl = bubbleDestination?.bubbleAppUrl;
146+
147+
if (
148+
!bubbleUrl &&
149+
'baseUrl' in bubbleDestination &&
150+
'datatype' in bubbleDestination &&
151+
bubbleDestination.baseUrl &&
152+
bubbleDestination.datatype
153+
) {
154+
const baseUrl = bubbleDestination.baseUrl as string;
155+
bubbleUrl = `${baseUrl}/api/1.1/obj/${bubbleDestination.datatype}`;
156+
}
157+
158+
// If still no URL, return null as we can't proceed without a valid URL
159+
if (!bubbleUrl) {
160+
return null;
161+
}
146162

147163
const defaultValueObj = {};
148164
const customSchema = JSON.parse(uploadata.customSchema) as ITemplateSchemaItem;

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,13 @@ export function Destination({ template }: DestinationProps) {
147147
<Input
148148
required
149149
label="Bubble App URL"
150-
placeholder="Bubble App URL"
150+
placeholder="https://acme.in/api/1.1/obj/customers"
151+
description={
152+
<>
153+
<div>Example with default domain: https://your-app.bubbleapps.io/api/1.1/obj/your-datatype</div>
154+
<div>Example with custom domain: https://yourapp.com/api/1.1/obj/your-datatype</div>
155+
</>
156+
}
151157
{...register('bubbleIo.bubbleAppUrl')}
152158
error={errors?.bubbleIo?.bubbleAppUrl?.message}
153159
/>

apps/widget/src/hooks/Phase3/usePhase3.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ export function usePhase3({ onNext }: IUsePhase3Props) {
196196
setTotalPages(reviewDataResponse.totalPages);
197197
},
198198
onError(error: IErrorObject) {
199-
notifier.showError({ message: 'Hellow World', title: error.error });
199+
notifier.showError({ message: error.message, title: error.error });
200200
},
201201
}
202202
);

0 commit comments

Comments
 (0)