@squarecloud/blob
Version:
Official Square Cloud Blob SDK for NodeJS
63 lines (60 loc) • 1.77 kB
JavaScript
// src/validation/schemas/stats.ts
import { z } from "zod";
var statsResponseSchema = z.object({
/** The total number of objects in your account. */
objects: z.number(),
/** The total size of all objects in your account, in bytes. */
size: z.number(),
/** The total price of storage for all objects in your account, in BRL. */
storagePrice: z.number(),
/** The total price of all objects in your account, in BRL. */
objectsPrice: z.number(),
/** The total price of all objects in your account, in BRL. */
totalEstimate: z.number()
});
// src/structures/error.ts
var SquareCloudBlobError = class _SquareCloudBlobError extends Error {
constructor(code, message, cause) {
super(message, { cause });
this.name = _SquareCloudBlobError.name;
this.message = this.getMessage(code);
}
getMessage(rawCode) {
const code = rawCode.replaceAll("_", " ").toLowerCase().replace(/(^|\s)\S/g, (L) => L.toUpperCase());
const message = this.message ? `: ${this.message}` : "";
return `${code}${message}`;
}
};
// src/validation/assertions/handlers.ts
function handleAPIObjectAssertion({
schema,
value,
code
}) {
const name = code.toLowerCase().replaceAll("_", " ");
try {
return schema.parse(value);
} catch (err) {
const cause = err.errors?.map((err2) => ({
...err2,
path: err2.path.join(" > ")
}));
throw new SquareCloudBlobError(
`INVALID_API_${code}`,
`Invalid ${name} object received from API`,
{ cause }
);
}
}
// src/validation/assertions/stats.ts
function assertStatsResponse(value) {
return handleAPIObjectAssertion({
schema: statsResponseSchema,
code: "ACCOUNT_STATS",
value
});
}
export {
assertStatsResponse
};
//# sourceMappingURL=stats.mjs.map