UNPKG

shipthis

Version:

ShipThis manages building and uploading your Godot games to the App Store and Google Play.

83 lines (79 loc) 3.25 kB
import { jsxs, jsx } from 'react/jsx-runtime'; import { Box, Text } from 'ink'; import Spinner from 'ink-spinner'; import 'node:crypto'; import 'node:fs'; import 'node:path'; import 'node:readline'; import 'node:url'; import 'readline-sync'; import 'luxon'; import axios from 'axios'; import 'isomorphic-git'; import { c as getShortDate, p as getAuthedHeaders, o as API_URL, F as castArrayObjectDates } from './baseCommand-CTn3KGH3.js'; import '@oclif/core'; import { useQuery } from '@tanstack/react-query'; import 'react'; import 'crypto-js'; import 'uuid'; import 'fast-glob'; import 'yazl'; import { k as cacheKeys, g as getShortUUID } from './baseGameCommand-8VL7xe-O.js'; import 'socket.io-client'; import 'fullscreen-ink'; import { T as Table } from './Table-FaNgpyeq.js'; import { T as Title } from './Title-BCQtayg6.js'; async function queryUserCredentials(params) { try { const headers = getAuthedHeaders(); const url = `${API_URL}/credentials`; const response = await axios.get(url, { headers, params }); return { ...response.data, data: castArrayObjectDates(response.data.data) }; } catch (error) { console.warn("queryUserCredentials Error", error); throw error; } } function getUserCredentialSummary(credential) { const summary = {}; summary.id = getShortUUID(credential.id); summary.type = credential.type; summary.serial = credential.serialNumber; summary.isActive = credential.isActive; summary.createdAt = getShortDate(credential.createdAt); return summary; } const useUserCredentials = ({ platform, type, ...pageAndSortParams }) => { const queryResult = useQuery({ queryFn: async () => queryUserCredentials(pageAndSortParams), queryKey: cacheKeys.userCredentials(pageAndSortParams), select(data) { if (!(platform || type)) return data; return { ...data, data: data.data.filter((credential) => (!platform || credential.platform === platform) && (!type || credential.type === type)) }; } }); return queryResult; }; const UserCredentialsTable = ({ credentialTypeName, queryProps, ...boxProps }) => { const { data, isLoading } = useUserCredentials(queryProps); const hasActive = data?.data.some((credential) => credential.isActive); const hasInactive = data?.data.some((credential) => !credential.isActive); return /* @__PURE__ */ jsxs(Box, { flexDirection: "column", marginBottom: 1, ...boxProps, children: [ /* @__PURE__ */ jsx(Title, { children: `${credentialTypeName}s in your ShipThis account` }), /* @__PURE__ */ jsx(Box, { flexDirection: "column", marginBottom: 1, marginLeft: 2, children: /* @__PURE__ */ jsx(Text, { children: hasActive ? `You have an active ${credentialTypeName} in your ShipThis account.` : `You DO NOT have an active ${credentialTypeName} which ShipThis can use.` }) }), isLoading && /* @__PURE__ */ jsx(Spinner, { type: "dots" }), data && data.data.length > 0 && /* @__PURE__ */ jsx(Table, { data: data.data.map(getUserCredentialSummary) }), hasInactive && /* @__PURE__ */ jsx(Text, { children: "Inactive credentials are automatically removed from storage after 24 hours." }) ] }); }; export { UserCredentialsTable as U, useUserCredentials as u };