Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat[gen2][react] ENG-7239 console.log() the API URL when process.env.DEBUG is true #3699

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions packages/sdks/src/blocks/form/form/form.lite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { filterAttrs } from '../../helpers.js';
/**
* This import is used by the Svelte SDK. Do not remove.
*/
import { logFetch } from '../../../functions/log-fetch.js';
import { setAttrs } from '../../helpers.js';

export type FormProps = BuilderDataProps &
Expand Down Expand Up @@ -193,16 +194,18 @@ export default function FormComponent(props: FormProps) {
props.sendSubmissionsToEmail || ''
)}&name=${encodeURIComponent(props.name || '')}`;

fetch(
const url =
props.sendSubmissionsTo === 'email'
? formUrl
: props.action! /* TODO: throw error if no action URL */,
{
body,
headers,
method: props.method || 'post',
}
).then(
: props.action!; /* TODO: throw error if no action URL */

logFetch(url);

fetch(url, {
body,
headers,
method: props.method || 'post',
}).then(
async (res) => {
let body;
const contentType = res.headers.get('content-type');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { fetchOneEntry } from '../../../functions/get-content/index.js';
import { isBrowser } from '../../../functions/is-browser.js';
import { isEditing } from '../../../functions/is-editing.js';
import { isPreviewing } from '../../../functions/is-previewing.js';
import { logFetch } from '../../../functions/log-fetch.js';
import { createRegisterComponentMessage } from '../../../functions/register-component.js';
import { _track } from '../../../functions/track/index.js';
import { getInteractionPropertiesForEvent } from '../../../functions/track/interaction.js';
Expand Down Expand Up @@ -202,6 +203,8 @@ export default function EnableEditor(props: BuilderEditorProps) {
)
);

logFetch(evaluatedUrl);

fetch(evaluatedUrl)
.then((response) => response.json())
.then((json) => {
Expand Down
7 changes: 7 additions & 0 deletions packages/sdks/src/functions/log-fetch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { logger } from '../helpers/logger';

export function logFetch(url: string) {
if (String(process.env.DEBUG) == 'true') {
logger.log(url);
}
}
7 changes: 6 additions & 1 deletion packages/sdks/src/functions/track/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { CanTrack } from '../../types/can-track.js';
import type { Dictionary } from '../../types/typescript.js';
import { isBrowser } from '../is-browser.js';
import { isEditing } from '../is-editing.js';
import { logFetch } from '../log-fetch.js';
import { getUserAttributes } from './helpers.js';

interface Event {
Expand Down Expand Up @@ -124,7 +125,11 @@ export async function _track({

const baseUrl = apiHost || 'https://cdn.builder.io';

return fetch(`${baseUrl}/api/v1/track`, {
const url = `${baseUrl}/api/v1/track`;

logFetch(url);

return fetch(url, {
method: 'POST',
body: JSON.stringify({
events: [await createEvent(eventProps)],
Expand Down
Loading