UNPKG

stability-ai

Version:
76 lines 2.96 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.balance = exports.account = void 0; const axios_1 = __importDefault(require("axios")); const util_1 = require("../util"); const error_1 = require("../error"); const SAIUtil = __importStar(require("../util")); const RESOURCE = 'user'; var Endpoint; (function (Endpoint) { Endpoint["ACCOUNT"] = "account"; Endpoint["BALANCE"] = "balance"; })(Endpoint || (Endpoint = {})); /** * Stability Get Balance (v1/user) */ async function account() { const response = await axios_1.default.get(SAIUtil.makeUrl(util_1.APIVersion.V1, RESOURCE, Endpoint.ACCOUNT), { headers: this.authHeaders, }); if (response.status === 200 && typeof response.data.email === 'string' && typeof response.data.id === 'string' && Array.isArray(response.data.organizations)) { return { email: response.data.email, id: response.data.id, organizations: response.data.organizations, profile_picture: response.data.profile_picture, }; } throw new error_1.StabilityAIError(response.status, 'Failed to get user account', response.data); } exports.account = account; /** * Stability Get Balance (v1/user) */ async function balance() { const response = await axios_1.default.get(SAIUtil.makeUrl(util_1.APIVersion.V1, RESOURCE, Endpoint.BALANCE), { headers: this.orgAuthHeaders, }); if (response.status === 200 && typeof response.data.credits === 'number') { return { credits: response.data.credits, }; } throw new error_1.StabilityAIError(response.status, 'Failed to get user token balance', response.data); } exports.balance = balance; //# sourceMappingURL=user.js.map