-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #99 from HubSpot/port-filetransport
Port api/filetransport fix a few API bugs
- Loading branch information
Showing
3 changed files
with
65 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import { getCwd } from '../lib/path'; | ||
import http from '../http'; | ||
|
||
const HUBFILES_API_PATH = '/file-transport/v1/hubfiles'; | ||
|
||
export async function createSchemaFromHubFile( | ||
accountId: number, | ||
filepath: string | ||
) { | ||
const file = fs.createReadStream(path.resolve(getCwd(), filepath)); | ||
return http.post(accountId, { | ||
url: `${HUBFILES_API_PATH}/object-schemas`, | ||
data: { | ||
file, | ||
}, | ||
headers: { 'Content-Type': 'multipart/form-data' }, | ||
}); | ||
} | ||
|
||
export async function updateSchemaFromHubFile( | ||
accountId: number, | ||
filepath: string | ||
) { | ||
const file = fs.createReadStream(path.resolve(getCwd(), filepath)); | ||
return http.put(accountId, { | ||
url: `${HUBFILES_API_PATH}/object-schemas`, | ||
data: { | ||
file, | ||
}, | ||
headers: { 'Content-Type': 'multipart/form-data' }, | ||
}); | ||
} | ||
|
||
export async function fetchHubFileSchema( | ||
accountId: number, | ||
objectName: string, | ||
path: string | ||
) { | ||
return http.getOctetStream( | ||
accountId, | ||
{ | ||
url: `${HUBFILES_API_PATH}/object-schemas/${objectName}`, | ||
}, | ||
path | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters