UNPKG

@codesandbox/api

Version:
392 lines 10.5 kB
export class RESTProjectApi { constructor(request) { this.request = request; this.baseUrl = "/beta"; } getBranchById(id) { return this.request({ method: "GET", path: this.baseUrl + "/sandboxes/branches/" + id, }).then(({ data }) => data); } /** * @deprecated */ getBranch({ owner, repo, branch, }) { return this.request({ method: "GET", path: this.baseUrl + `/github/${owner}/${repo}/${branch}`, }).then(({ data }) => data); } /** * @deprecated */ import({ owner, repo, branch, teamId, }) { return this.request({ method: "POST", path: this.baseUrl + `/github/${owner}/${repo}${branch ? "/" + branch : ""}`, data: { teamId, }, }).then(({ data }) => data); } forkRepository({ owner, repo, branch, teamId, name, organization, }) { return this.request({ method: "POST", path: this.baseUrl + `/fork/github/${owner}/${repo}${branch ? "/" + branch : ""}`, data: { teamId, name, organization, }, }).then(({ data }) => data); } /** * Creates a branch on a repo. By default it creates * a branch from the default branch, unless `sourceBranch` is passed. * By default it creates the new branch name, unless `newBranch` is passed. */ createBranch({ owner, repo, sourceBranch, newBranch, teamId, }) { return this.request({ method: "POST", path: this.baseUrl + `/github/${owner}/${repo}`, data: { sourceBranch, newBranch, teamId, }, }).then(({ data }) => data); } /** * Updates details of a branch */ updateBranch(id, { name }) { return this.request({ method: "PATCH", path: this.baseUrl + `/sandboxes/branches/` + id, data: { name, }, }).then(({ data }) => data); } } export class RESTSandboxesApi { constructor(request) { this.request = request; this.baseUrl = "/sandboxes"; } /** * Returns a Sandbox with modules and directories */ get(id) { return this.request({ method: "GET", path: this.baseUrl + "/" + id, }).then(({ data }) => data); } update(id, data) { return this.request({ method: "PATCH", path: this.baseUrl + "/" + id, data, }); } fork(sandboxUrl) { return this.request({ method: "POST", path: this.baseUrl + "/fork/github/" + sandboxUrl, data: {}, }); } getGitHubSandbox(sandboxUrl) { return this.request({ method: "GET", path: this.baseUrl + "/github/" + sandboxUrl, }); } createDefine() { return this.request({ method: "POST", path: this.baseUrl + "/define", data: {}, }); } getDefine() { return this.request({ method: "GET", path: this.baseUrl + "/define", }); } createMslim() { return this.request({ method: "POST", path: this.baseUrl + "/mslim", data: {}, }); } getPopular() { return this.request({ method: "GET", path: this.baseUrl + "/popular", }); } getPicked() { return this.request({ method: "GET", path: this.baseUrl + "/picked", }); } getLimits() { return this.request({ method: "GET", path: this.baseUrl + "/limits", }); } getExploreTemplates() { return this.request({ method: "GET", path: this.baseUrl + "/templates/explore", }); } getOfficialTemplates() { return this.request({ method: "GET", path: this.baseUrl + "/templates/official", }); } } export class RESTUsersApi { constructor(request) { this.request = request; this.baseUrl = "/users"; } createSurveyAnswer() { return this.request({ method: "POST", path: this.baseUrl + "/survey-answered", data: {}, }); } flagSurveySeen() { return this.request({ method: "POST", path: this.baseUrl + "/survey-seen", data: {}, }); } createExperiment() { return this.request({ method: "POST", path: this.baseUrl + "/experiments", data: {}, }); } search() { return this.request({ method: "GET", path: this.baseUrl + "/search", }); } getPending(id) { return this.request({ method: "GET", path: this.baseUrl + "/pending/" + id, }); } getUsernameAvailability(username) { return this.request({ method: "GET", path: this.baseUrl + "/available/" + username, }); } finalize() { return this.request({ method: "POST", path: this.baseUrl + "/finalize", data: {}, }); } deleteCurator(username) { return this.request({ method: "DELETE", path: this.baseUrl + "/curators/" + username, }); } createCurator(username) { return this.request({ method: "POST", path: this.baseUrl + "/curators/" + username, data: {}, }); } getUserSandboxes(id) { return this.request({ method: "GET", path: this.baseUrl + "/" + id + "/sandboxes", }); } getUserLikedSandboxes(id) { return this.request({ method: "GET", path: this.baseUrl + "/" + id + "/sandboxes/liked", }); } } export class RESTCurrentUserApi { constructor(request) { this.request = request; this.baseUrl = "/users"; } getIntegrations() { return this.request({ method: "GET", path: this.baseUrl + "/current/integrations", }); } removeIntegration(integration) { return this.request({ method: "DELETE", path: this.baseUrl + "/current_user/integrations/" + integration, }); } addIntegration(integration) { return this.request({ method: "POST", path: this.baseUrl + "/current_user/integrations/" + integration.type, data: integration.data, }); } getEditorSettings() { return this.request({ method: "GET", path: this.baseUrl + "/current_user/editor_settings", }); } setEditorSettings() { return this.request({ method: "POST", path: this.baseUrl + "/current_user/editor_settings", data: {}, }); } unsetEditorSettings() { return this.request({ method: "DELETE", path: this.baseUrl + "/current_user/editor_settings", }); } updateEditorSettings() { return this.request({ method: "PATCH", path: this.baseUrl + "/current_user/editor_settings", data: {}, }); } cancelSubscription() { return this.request({ method: "DELETE", path: this.baseUrl + "/current_user/subscription", }); } updateSubscription() { return this.request({ method: "PATCH", path: this.baseUrl + "/current_user/subscription", data: {}, }); } createSubscription() { return this.request({ method: "POST", path: this.baseUrl + "/current_user/subscription", data: {}, }); } createSse() { return this.request({ method: "POST", path: this.baseUrl + "/current_user/sse", data: {}, }); } updateBadge(id) { return this.request({ method: "PATCH", path: this.baseUrl + "/current_user/badges/" + id, data: {}, }); } getPaymentDetails() { return this.request({ method: "GET", path: this.baseUrl + "/current_user/payment_details", }); } updatePaymentDetails() { return this.request({ method: "PATCH", path: this.baseUrl + "/current_user/payment_details", data: {}, }); } getUploads() { return this.request({ method: "GET", path: this.baseUrl + "/current_user/uploads", }); } upload() { return this.request({ method: "POST", path: this.baseUrl + "/current_user/uploads", data: {}, }); } deleteUpload(id) { return this.request({ method: "DELETE", path: this.baseUrl + "/current_user/uploads/" + id, }); } getFeatureFlags() { return this.request({ method: "GET", path: this.baseUrl + "/current_user/feature_flags", }); } } export class RESTApi { constructor(request) { this.request = request; this.sandboxes = new RESTSandboxesApi(request); this.users = new RESTUsersApi(request); this.project = new RESTProjectApi(request); this.currentUser = new RESTCurrentUserApi(request); } /** * Returns the most recent subscription prices from Stripe */ getPrices() { return this.request({ method: "GET", path: "/prices", }).then(({ data }) => data); } /** * @deprecated * This should really be using the SSE Sandbox endpoint */ feedback() { } /** * Get the latest version of an NPM dependency by passing * its name and semver. Ex: react@^1.0.1 */ getLatestDependencyVersion(dependency) { return this.request({ method: "GET", path: "/dependencies/" + dependency, }).then(({ data }) => data); } } //# sourceMappingURL=RESTApi.js.map