Skip to content

Commit

Permalink
Feat: add command for generating app feature component
Browse files Browse the repository at this point in the history
  • Loading branch information
Tsemach Lifshitz committed Feb 8, 2024
1 parent 28df2a3 commit 395dc84
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/consts/urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,7 @@ export const appReleasesUrl = (appVersionId: AppId): string => {
export const generateTunnelingTokenUrl = (): string => {
return `${BASE_MONDAY_CODE_URL}/tunnel-token`;
};

export const getTunnelingDomainUrl = (): string => {
return `${BASE_MONDAY_CODE_URL}/tunnel-domain`;
};
4 changes: 3 additions & 1 deletion src/services/apps-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { getMondayDomain } from 'services/env-service';
import { cloneFolderFromGitRepo } from 'services/git-service';
import { readManifestFile } from 'services/manifest-service';
import { createAppSchema, listAppSchema } from 'services/schemas/apps-service-schemas';
import { getTunnelingDomain } from 'services/tunnel-service';
import { AppCreateCommandTasksContext } from 'types/commands/app-create';
import { HttpError } from 'types/errors';
import { HttpMethodTypes } from 'types/services/api-service';
Expand Down Expand Up @@ -79,6 +80,7 @@ export const cloneAppTemplateAndLoadManifest = async (

export const createFeatures = async (ctx: AppCreateCommandTasksContext) => {
const defaultVersion = await defaultVersionByAppId(ctx.appId!, false);
const baseUrl = await getTunnelingDomain();
if (!defaultVersion) throw new Error(`No default version found for app id - ${ctx.appId}`);
ctx.appVersionId = defaultVersion.id;
const createFeaturesPromises = ctx.features?.map(feature => {
Expand All @@ -88,7 +90,7 @@ export const createFeatures = async (ctx: AppCreateCommandTasksContext) => {
appFeatureType: feature.type,
build: feature.build && {
buildType: feature.build.source,
url: `https://baseUrl${feature.build.sufix}`,
url: `https://${baseUrl}${feature.build.sufix}`,
},
options: { name: feature.name },
});
Expand Down
6 changes: 6 additions & 0 deletions src/services/schemas/push-service-schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ export const tunnelAuthTokenSchema = z
})
.merge(baseResponseHttpMetaDataSchema);

export const tunnelDomainSchema = z
.object({
domain: z.string(),
})
.merge(baseResponseHttpMetaDataSchema);

export const deploymentStatusTypesArray = [
'started',
'pending',
Expand Down
30 changes: 27 additions & 3 deletions src/services/tunnel-service.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import * as ngrok from '@ngrok/ngrok';
import { ListrTaskWrapper } from 'listr2';

import { generateTunnelingTokenUrl } from 'consts/urls';
import { generateTunnelingTokenUrl, getTunnelingDomainUrl } from 'consts/urls';
import { execute } from 'services/api-service';
import { tunnelAuthTokenSchema } from 'services/schemas/push-service-schemas';
import { tunnelAuthTokenSchema, tunnelDomainSchema } from 'services/schemas/push-service-schemas';
import { TunnelCommandTasksContext } from 'types/commands/tunnel';
import { HttpError } from 'types/errors';
import { AppId } from 'types/general';
import { HttpMethodTypes } from 'types/services/api-service';
import { TunnelAuthToken } from 'types/services/tunnel-service';
import { TunnelAuthToken, TunnelDomain } from 'types/services/tunnel-service';
import logger from 'utils/logger';
import { appsUrlBuilder } from 'utils/urls-builder';

Expand Down Expand Up @@ -49,6 +50,29 @@ export const generateTunnelingAuthToken = async (ctx: TunnelCommandTasksContext)
}
};

export const getTunnelingDomain = async (appId?: AppId) => {
const DEBUG_TAG = 'get_tunneling_domain';
try {
const baseUrl = getTunnelingDomainUrl();
const url = appsUrlBuilder(baseUrl);
const response = await execute<TunnelDomain>(
{
url,
headers: { Accept: 'application/json' },
method: HttpMethodTypes.GET,
query: {
appId,
},
},
tunnelDomainSchema,
);

return response.domain;
} catch (error: any | HttpError) {
handleError(error, DEBUG_TAG, 'Failed to get tunneling domain.');
}
};

export const createTunnelConnection = async (ctx: TunnelCommandTasksContext) => {
const DEBUG_TAG = 'create_tunnel_connection';

Expand Down
4 changes: 3 additions & 1 deletion src/types/services/tunnel-service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { z } from 'zod';

import { tunnelAuthTokenSchema } from 'services/schemas/push-service-schemas';
import { tunnelAuthTokenSchema, tunnelDomainSchema } from 'services/schemas/push-service-schemas';

export type TunnelAuthToken = z.infer<typeof tunnelAuthTokenSchema>;

export type TunnelDomain = z.infer<typeof tunnelDomainSchema>;

0 comments on commit 395dc84

Please sign in to comment.