Skip to content

Commit 75c63d6

Browse files
authored
Merge pull request #143 from HubSpot/add/clone-app-command
Add endpoints for `hs project clone-app` command
2 parents b61041a + 42464a2 commit 75c63d6

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

api/projects.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ import {
1414
} from '../types/ComponentStructure';
1515
import { Deploy, ProjectDeployResponse } from '../types/Deploy';
1616
import { ProjectLog } from '../types/ProjectLog';
17-
import { MigrateAppResponse, PollAppResponse } from '../types/Migration';
17+
import {
18+
MigrateAppResponse,
19+
CloneAppResponse,
20+
PollAppResponse,
21+
} from '../types/Migration';
1822

1923
const PROJECTS_API_PATH = 'dfs/v1/projects';
2024
const PROJECTS_DEPLOY_API_PATH = 'dfs/deploy/v1';
@@ -318,3 +322,35 @@ export async function checkMigrationStatus(
318322
url: `${MIGRATIONS_API_PATH}/migrations/${id}`,
319323
});
320324
}
325+
326+
export async function cloneApp(
327+
accountId: number,
328+
appId: number
329+
): Promise<CloneAppResponse> {
330+
return http.post(accountId, {
331+
url: `${MIGRATIONS_API_PATH}/exports`,
332+
data: {
333+
componentId: appId,
334+
componentType: 'PUBLIC_APP_ID',
335+
},
336+
});
337+
}
338+
339+
export async function checkCloneStatus(
340+
accountId: number,
341+
exportId: number
342+
): Promise<CloneAppResponse> {
343+
return http.get(accountId, {
344+
url: `${MIGRATIONS_API_PATH}/exports/statuses/${exportId}`,
345+
});
346+
}
347+
348+
export async function downloadClonedProject(
349+
accountId: number,
350+
exportId: number
351+
): Promise<Buffer> {
352+
return http.get(accountId, {
353+
url: `${MIGRATIONS_API_PATH}/exports/${exportId}/download-as-clone`,
354+
responseType: 'arraybuffer',
355+
});
356+
}

types/Migration.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,14 @@ export type MigrateAppResponse = {
1313
status: ValueOf<typeof MIGRATION_STATUS>;
1414
};
1515

16+
export type CloneAppResponse = {
17+
exportId: number;
18+
status: ValueOf<typeof MIGRATION_STATUS>;
19+
};
20+
1621
export type PollAppResponse = {
1722
id: number;
1823
project?: { id: number; name: string; buildId: number; deployId: number };
19-
error: OptionalError;
24+
error?: OptionalError;
2025
status: ValueOf<typeof MIGRATION_STATUS>;
2126
};

0 commit comments

Comments
 (0)