Skip to content

Commit

Permalink
chore: deprecated endpoint id cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
drochetti committed Jul 27, 2024
1 parent 4c4055d commit 55b646c
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 30 deletions.
9 changes: 1 addition & 8 deletions libs/client/src/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
QueueStatus,
RequestLog,
} from './types';
import { ensureAppIdFormat, isUUIDv4, isValidUrl, parseAppId } from './utils';
import { ensureAppIdFormat, isValidUrl, parseAppId } from './utils';

/**
* The function input and other configuration when running
Expand Down Expand Up @@ -79,20 +79,13 @@ export function buildUrl<Input>(
Object.keys(params).length > 0
? `?${new URLSearchParams(params).toString()}`
: '';
const parts = id.split('/');

// if a fal url is passed, just use it
if (isValidUrl(id)) {
const url = id.endsWith('/') ? id : `${id}/`;
return `${url}${path}${queryParams}`;
}

// TODO remove this after some time, fal.run should be preferred
if (parts.length === 2 && isUUIDv4(parts[1])) {
const host = 'gateway.alpha.fal.ai';
return `https://${host}/trigger/${id}/${path}${queryParams}`;
}

const appId = ensureAppIdFormat(id);
const subdomain = options.subdomain ? `${options.subdomain}.` : '';
const url = `https://${subdomain}fal.run/${appId}/${path}`;
Expand Down
1 change: 0 additions & 1 deletion libs/client/src/streaming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ export class FalStream<Input, Output> {
const token = await getTemporaryAuthToken(endpointId);
const { fetch = global.fetch } = getConfig();
const parsedUrl = new URL(this.url);
console.log(this.url);
parsedUrl.searchParams.set('fal_jwt_token', token);
const response = await fetch(parsedUrl.toString(), {
method: method.toUpperCase(),
Expand Down
13 changes: 1 addition & 12 deletions libs/client/src/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
import uuid from 'uuid-random';
import { ensureAppIdFormat, isUUIDv4, parseAppId } from './utils';
import { ensureAppIdFormat, parseAppId } from './utils';

describe('The utils test suite', () => {
it('should match a valid v4 uuid', () => {
const id = uuid();
expect(isUUIDv4(id)).toBe(true);
});

it('should not match invalid v4 id', () => {
const id = 'e726b886-e2c2-11ed-b5ea-0242ac120002';
expect(isUUIDv4(id)).toBe(false);
});

it('shoud match match a legacy appOwner-appId format', () => {
const id = '12345-abcde-fgh';
expect(ensureAppIdFormat(id)).toBe('12345/abcde-fgh');
Expand Down
9 changes: 0 additions & 9 deletions libs/client/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
export function isUUIDv4(id: string): boolean {
return (
typeof id === 'string' &&
id.length === 36 &&
id[14] === '4' &&
['8', '9', 'a', 'b'].includes(id[19])
);
}

export function ensureAppIdFormat(id: string): string {
const parts = id.split('/');
if (parts.length > 1) {
Expand Down

0 comments on commit 55b646c

Please sign in to comment.