@upstart.gg/sdk
Version:
You can test the CLI without recompiling by running:
77 lines (76 loc) • 2.25 kB
JavaScript
//#region src/shared/datarecords/external/google/sheets/client.ts
var GoogleDriveClient = class {
accessToken;
constructor(accessToken) {
this.accessToken = accessToken;
}
async callDriveApi(endpoint, method = "GET", body) {
const isBinaryUpload = body instanceof ArrayBuffer || body instanceof Uint8Array;
const headers = { Authorization: `Bearer ${this.accessToken}` };
if (!isBinaryUpload) headers["Content-Type"] = "application/json";
else headers["Content-Type"] = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
const response = await fetch(endpoint, {
method,
headers,
body: isBinaryUpload ? body : body ? JSON.stringify(body) : void 0
});
if (endpoint.includes("export") && endpoint.includes("mimeType=text/csv")) {
const csvText = await response.text();
return {
success: response.ok,
data: csvText,
status: response.status,
headers: response.headers
};
}
if (endpoint.includes("export") && endpoint.includes("mimeType=application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")) {
const arrayBuffer = await response.arrayBuffer();
return {
success: response.ok,
data: arrayBuffer,
status: response.status,
headers: response.headers
};
}
if (endpoint.includes("upload/") && response.ok) try {
const data$1 = await response.json();
return {
success: response.ok,
data: data$1,
status: response.status,
headers: response.headers
};
} catch {
return {
success: true,
data: { message: "Upload successful" },
status: response.status,
headers: response.headers
};
}
if (!response.ok) {
if (response.headers.get("content-type")?.includes("text/html")) return {
success: false,
data: {
error: "HTML error response",
details: (await response.text()).substring(0, 200)
},
status: response.status,
headers: response.headers
};
}
const data = await response.json();
return {
success: response.ok,
data,
status: response.status,
headers: response.headers
};
}
};
function getClient(accessToken) {
return new GoogleDriveClient(accessToken);
}
//#endregion
export { getClient as default };
//# sourceMappingURL=client.js.map