feat(#5): use auth
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
import {defineStore} from "pinia";
|
||||
import {ref} from "vue";
|
||||
import {CharacterResponse} from "@/generated/mammon";
|
||||
import {addCharacter as addCharacterRequest, fetchMe, mammonLoginUrl, postLogout, refreshAccessToken, setOnAuthExpired} from "@/mammon";
|
||||
import {setAccessToken} from "./token";
|
||||
|
||||
export const useAuthStore = defineStore('auth', () => {
|
||||
const userId = ref<string | null>(null);
|
||||
const characters = ref<CharacterResponse[]>([]);
|
||||
const isAuthenticated = ref(false);
|
||||
|
||||
const clear = () => {
|
||||
setAccessToken(null);
|
||||
userId.value = null;
|
||||
characters.value = [];
|
||||
isAuthenticated.value = false;
|
||||
}
|
||||
|
||||
const refresh = async (): Promise<boolean> => {
|
||||
const token = await refreshAccessToken();
|
||||
|
||||
if (!token) {
|
||||
clear();
|
||||
return false;
|
||||
}
|
||||
isAuthenticated.value = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
const fetch = async (): Promise<void> => {
|
||||
const me = await fetchMe();
|
||||
|
||||
userId.value = me.userId;
|
||||
characters.value = me.characters;
|
||||
isAuthenticated.value = true;
|
||||
}
|
||||
|
||||
const login = (): void => {
|
||||
window.location.assign(mammonLoginUrl);
|
||||
}
|
||||
|
||||
const addCharacter = async (): Promise<void> => {
|
||||
await addCharacterRequest();
|
||||
window.location.assign(mammonLoginUrl);
|
||||
}
|
||||
|
||||
const logout = async (): Promise<void> => {
|
||||
try {
|
||||
await postLogout();
|
||||
} finally {
|
||||
clear();
|
||||
}
|
||||
}
|
||||
|
||||
const bootstrap = async (): Promise<void> => {
|
||||
setOnAuthExpired(() => {
|
||||
clear();
|
||||
login();
|
||||
});
|
||||
|
||||
if (await refresh()) {
|
||||
await fetch();
|
||||
}
|
||||
}
|
||||
|
||||
return {userId, characters, isAuthenticated, refresh, fetch, login, addCharacter, logout, bootstrap};
|
||||
})
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './auth';
|
||||
export * from './token';
|
||||
@@ -0,0 +1,7 @@
|
||||
let accessToken: string | null = null;
|
||||
|
||||
export const getAccessToken = (): string | null => accessToken;
|
||||
|
||||
export const setAccessToken = (token: string | null): void => {
|
||||
accessToken = token;
|
||||
};
|
||||
+716
-3
@@ -23,14 +23,41 @@ import type { RequestArgs } from './base';
|
||||
// @ts-ignore
|
||||
import { BASE_PATH, COLLECTION_FORMATS, BaseAPI, RequiredError, operationServerMap } from './base';
|
||||
|
||||
/**
|
||||
* A single acquisition of a market type, tracking the remaining quantity available in the FIFO cost pool.
|
||||
*/
|
||||
export interface AcquisitionResponse {
|
||||
/**
|
||||
* Unique acquisition identifier.
|
||||
*/
|
||||
'acquisitionId': string;
|
||||
/**
|
||||
* EVE character id that made the acquisition.
|
||||
*/
|
||||
'characterId': number;
|
||||
/**
|
||||
* EVE market type (item) id that was acquired.
|
||||
*/
|
||||
'marketTypeId': number;
|
||||
/**
|
||||
* How the item entered the inventory.
|
||||
*/
|
||||
'source': AcquisitionResponseSourceEnum;
|
||||
/**
|
||||
* When the acquisition occurred.
|
||||
*/
|
||||
'datetime': string;
|
||||
/**
|
||||
* Quantity originally acquired.
|
||||
*/
|
||||
'quantity': number;
|
||||
/**
|
||||
* Quantity still remaining in the FIFO cost pool.
|
||||
*/
|
||||
'remaining': number;
|
||||
/**
|
||||
* Cost per unit at acquisition time, in ISK.
|
||||
*/
|
||||
'unitCost': number;
|
||||
}
|
||||
|
||||
@@ -41,44 +68,140 @@ export const AcquisitionResponseSourceEnum = {
|
||||
|
||||
export type AcquisitionResponseSourceEnum = typeof AcquisitionResponseSourceEnum[keyof typeof AcquisitionResponseSourceEnum];
|
||||
|
||||
/**
|
||||
* The balance of a ledger: its ISK total plus the quantity of each item type held.
|
||||
*/
|
||||
export interface BalanceResponse {
|
||||
/**
|
||||
* ISK balance of the ledger.
|
||||
*/
|
||||
'iskBalance': number;
|
||||
/**
|
||||
* Per-item-type quantities held in the ledger.
|
||||
*/
|
||||
'itemBalances': Array<ItemBalanceResponse>;
|
||||
}
|
||||
/**
|
||||
* An EVE Online character.
|
||||
*/
|
||||
export interface CharacterResponse {
|
||||
/**
|
||||
* EVE character id.
|
||||
*/
|
||||
'characterId': number;
|
||||
/**
|
||||
* Character name.
|
||||
*/
|
||||
'name': string;
|
||||
}
|
||||
/**
|
||||
* A rule book assigned to a character, with the ledger bindings that resolve its references.
|
||||
*/
|
||||
export interface CharacterRuleBookResponse {
|
||||
/**
|
||||
* The character the rule book is assigned to.
|
||||
*/
|
||||
'character': CharacterResponse;
|
||||
/**
|
||||
* Summary of the assigned rule book.
|
||||
*/
|
||||
'ruleBook': RuleBookSummaryResponse;
|
||||
/**
|
||||
* Bindings from each ledger reference name to the ledger id it resolves to for this character.
|
||||
*/
|
||||
'bindings': { [key: string]: string; };
|
||||
}
|
||||
/**
|
||||
* A combined ledger: an aggregate whose balance is the sum of its member ledgers.
|
||||
*/
|
||||
export interface CombinedLedgerResponse extends LedgerResponse {
|
||||
/**
|
||||
* Unique ledger identifier.
|
||||
*/
|
||||
'ledgerId': string;
|
||||
/**
|
||||
* Ledger name.
|
||||
*/
|
||||
'name': string;
|
||||
/**
|
||||
* Aggregate ISK balance across all member ledgers.
|
||||
*/
|
||||
'balance': number;
|
||||
/**
|
||||
* Ids of the ledgers aggregated by this combined ledger.
|
||||
*/
|
||||
'memberLedgerIds': Array<string>;
|
||||
}
|
||||
/**
|
||||
* Request to create a new combined ledger aggregating the given member ledgers.
|
||||
*/
|
||||
export interface CreateCombinedLedgerRequest {
|
||||
/**
|
||||
* Name for the new combined ledger.
|
||||
*/
|
||||
'name': string;
|
||||
/**
|
||||
* Ids of the ledgers to aggregate.
|
||||
*/
|
||||
'memberLedgerIds': Array<string>;
|
||||
}
|
||||
/**
|
||||
* Request to create a new main ledger.
|
||||
*/
|
||||
export interface CreateMainLedgerRequest {
|
||||
/**
|
||||
* Name for the new ledger.
|
||||
*/
|
||||
'name': string;
|
||||
}
|
||||
/**
|
||||
* Request to create a new rule book.
|
||||
*/
|
||||
export interface CreateRuleBookRequest {
|
||||
/**
|
||||
* Rule book name.
|
||||
*/
|
||||
'name': string;
|
||||
/**
|
||||
* Whether this rule book is used to derive acquisitions.
|
||||
*/
|
||||
'usedForAcquisitions': boolean;
|
||||
/**
|
||||
* Symbolic ledger references the script writes to; each must be bound to a ledger per character.
|
||||
*/
|
||||
'ledgerRefs': Array<string>;
|
||||
/**
|
||||
* The classification script source.
|
||||
*/
|
||||
'script': string;
|
||||
}
|
||||
/**
|
||||
* Quartile statistics computed over a market type\'s price history.
|
||||
*/
|
||||
export interface HistoryQuartilesResponse {
|
||||
/**
|
||||
* EVE market type (item) id.
|
||||
*/
|
||||
'marketTypeId': number;
|
||||
/**
|
||||
* First quartile (25th percentile) price, in ISK.
|
||||
*/
|
||||
'q1': number;
|
||||
/**
|
||||
* Median (50th percentile) price, in ISK.
|
||||
*/
|
||||
'median': number;
|
||||
/**
|
||||
* Third quartile (75th percentile) price, in ISK.
|
||||
*/
|
||||
'q3': number;
|
||||
/**
|
||||
* Total traded volume over the period.
|
||||
*/
|
||||
'totalVolume': number;
|
||||
/**
|
||||
* Overall price trend over the period.
|
||||
*/
|
||||
'trend': HistoryQuartilesResponseTrendEnum;
|
||||
}
|
||||
|
||||
@@ -90,56 +213,177 @@ export const HistoryQuartilesResponseTrendEnum = {
|
||||
|
||||
export type HistoryQuartilesResponseTrendEnum = typeof HistoryQuartilesResponseTrendEnum[keyof typeof HistoryQuartilesResponseTrendEnum];
|
||||
|
||||
/**
|
||||
* A transfer of ISK from one ledger to another.
|
||||
*/
|
||||
export interface IskTransferResponse extends TransferResponse {
|
||||
/**
|
||||
* Id of the ledger the ISK is debited from.
|
||||
*/
|
||||
'fromLedgerId': string;
|
||||
/**
|
||||
* Id of the ledger the ISK is credited to.
|
||||
*/
|
||||
'toLedgerId': string;
|
||||
/**
|
||||
* Amount of ISK transferred.
|
||||
*/
|
||||
'amount': number;
|
||||
}
|
||||
/**
|
||||
* Quantity of a single item type held in a ledger.
|
||||
*/
|
||||
export interface ItemBalanceResponse {
|
||||
/**
|
||||
* EVE market type (item) id.
|
||||
*/
|
||||
'typeId': number;
|
||||
/**
|
||||
* Number of units held.
|
||||
*/
|
||||
'quantity': number;
|
||||
}
|
||||
/**
|
||||
* A transfer of an item stack from one ledger to another.
|
||||
*/
|
||||
export interface ItemTransferResponse extends TransferResponse {
|
||||
/**
|
||||
* Id of the ledger the items are debited from.
|
||||
*/
|
||||
'fromLedgerId': string;
|
||||
/**
|
||||
* Id of the ledger the items are credited to.
|
||||
*/
|
||||
'toLedgerId': string;
|
||||
/**
|
||||
* EVE market type (item) id transferred.
|
||||
*/
|
||||
'marketTypeId': number;
|
||||
/**
|
||||
* Number of units transferred.
|
||||
*/
|
||||
'quantity': number;
|
||||
}
|
||||
/**
|
||||
* @type LedgerResponse
|
||||
* A ledger, either a standalone main ledger or a combined ledger aggregating others.
|
||||
*/
|
||||
export type LedgerResponse = { type: 'COMBINED' } & CombinedLedgerResponse | { type: 'MAIN' } & MainLedgerResponse;
|
||||
|
||||
/**
|
||||
* A main ledger: a standalone ledger with its own balance.
|
||||
*/
|
||||
export interface MainLedgerResponse extends LedgerResponse {
|
||||
/**
|
||||
* Unique ledger identifier.
|
||||
*/
|
||||
'ledgerId': string;
|
||||
/**
|
||||
* Ledger name.
|
||||
*/
|
||||
'name': string;
|
||||
/**
|
||||
* Current ISK balance of the ledger.
|
||||
*/
|
||||
'balance': number;
|
||||
}
|
||||
/**
|
||||
* A single day of market history for a market type.
|
||||
*/
|
||||
export interface MarketHistoryResponse {
|
||||
/**
|
||||
* EVE market type (item) id.
|
||||
*/
|
||||
'marketTypeId': number;
|
||||
/**
|
||||
* Date the history entry covers.
|
||||
*/
|
||||
'date': string;
|
||||
/**
|
||||
* Average price for the day, in ISK.
|
||||
*/
|
||||
'average': number;
|
||||
/**
|
||||
* Highest price for the day, in ISK.
|
||||
*/
|
||||
'highest': number;
|
||||
/**
|
||||
* Lowest price for the day, in ISK.
|
||||
*/
|
||||
'lowest': number;
|
||||
/**
|
||||
* Number of orders for the day.
|
||||
*/
|
||||
'orderCount': number;
|
||||
/**
|
||||
* Traded volume for the day.
|
||||
*/
|
||||
'volume': number;
|
||||
}
|
||||
/**
|
||||
* Current best buy and sell prices for a market type.
|
||||
*/
|
||||
export interface MarketPriceResponse {
|
||||
/**
|
||||
* EVE market type (item) id.
|
||||
*/
|
||||
'marketTypeId': number;
|
||||
/**
|
||||
* Best buy price, in ISK.
|
||||
*/
|
||||
'buy': number;
|
||||
/**
|
||||
* Best sell price, in ISK.
|
||||
*/
|
||||
'sell': number;
|
||||
/**
|
||||
* Number of market orders considered.
|
||||
*/
|
||||
'orderCount': number;
|
||||
}
|
||||
/**
|
||||
* Result of a market scan combining current prices, history quartiles and a computed profitability score for a market type.
|
||||
*/
|
||||
export interface MarketScanResponse {
|
||||
/**
|
||||
* EVE market type (item) id.
|
||||
*/
|
||||
'marketTypeId': number;
|
||||
/**
|
||||
* Current best buy price, in ISK.
|
||||
*/
|
||||
'buy': number;
|
||||
/**
|
||||
* Current best sell price, in ISK.
|
||||
*/
|
||||
'sell': number;
|
||||
/**
|
||||
* First quartile (25th percentile) historical price, in ISK.
|
||||
*/
|
||||
'q1': number;
|
||||
/**
|
||||
* Median (50th percentile) historical price, in ISK.
|
||||
*/
|
||||
'median': number;
|
||||
/**
|
||||
* Third quartile (75th percentile) historical price, in ISK.
|
||||
*/
|
||||
'q3': number;
|
||||
/**
|
||||
* Total traded volume over the scanned period.
|
||||
*/
|
||||
'totalVolume': number;
|
||||
/**
|
||||
* Overall price trend over the scanned period.
|
||||
*/
|
||||
'trend': MarketScanResponseTrendEnum;
|
||||
/**
|
||||
* Estimated profit per unit after fees and taxes, in ISK.
|
||||
*/
|
||||
'profit': number;
|
||||
/**
|
||||
* Computed profitability score used to rank scan results.
|
||||
*/
|
||||
'score': number;
|
||||
}
|
||||
|
||||
@@ -151,79 +395,273 @@ export const MarketScanResponseTrendEnum = {
|
||||
|
||||
export type MarketScanResponseTrendEnum = typeof MarketScanResponseTrendEnum[keyof typeof MarketScanResponseTrendEnum];
|
||||
|
||||
/**
|
||||
* An EVE Online market type (item) and its static attributes.
|
||||
*/
|
||||
export interface MarketTypeResponse {
|
||||
/**
|
||||
* EVE market type (item) id.
|
||||
*/
|
||||
'id': number;
|
||||
/**
|
||||
* Item name.
|
||||
*/
|
||||
'name': string;
|
||||
/**
|
||||
* Group id the item belongs to.
|
||||
*/
|
||||
'groupId': number;
|
||||
/**
|
||||
* Market group id the item is listed under.
|
||||
*/
|
||||
'marketGroupId': number;
|
||||
/**
|
||||
* Item description.
|
||||
*/
|
||||
'description': string;
|
||||
/**
|
||||
* Whether the item is published and visible in game.
|
||||
*/
|
||||
'published': boolean;
|
||||
'basePrice': number;
|
||||
/**
|
||||
* Base price of the item, in ISK, if defined.
|
||||
*/
|
||||
'basePrice': number | null;
|
||||
/**
|
||||
* Packaged volume of a single unit, in m³.
|
||||
*/
|
||||
'volume': number;
|
||||
/**
|
||||
* Number of units produced or reprocessed per portion.
|
||||
*/
|
||||
'portionSize': number;
|
||||
'iconId': number;
|
||||
/**
|
||||
* Icon id for the item, if defined.
|
||||
*/
|
||||
'iconId': number | null;
|
||||
}
|
||||
/**
|
||||
* A market type stack valued at current buy and sell prices.
|
||||
*/
|
||||
export interface MarketTypeStackAppraisalResponse {
|
||||
/**
|
||||
* EVE market type (item) id.
|
||||
*/
|
||||
'marketTypeId': number;
|
||||
/**
|
||||
* Number of units in the stack.
|
||||
*/
|
||||
'quantity': number;
|
||||
/**
|
||||
* Total buy value of the stack, in ISK.
|
||||
*/
|
||||
'buy': number;
|
||||
/**
|
||||
* Total sell value of the stack, in ISK.
|
||||
*/
|
||||
'sell': number;
|
||||
/**
|
||||
* Number of market orders considered for the valuation.
|
||||
*/
|
||||
'orderCount': number;
|
||||
}
|
||||
/**
|
||||
* A quantity of a single market type to reprocess.
|
||||
*/
|
||||
export interface MarketTypeStackRequest {
|
||||
/**
|
||||
* EVE market type (item) id to reprocess.
|
||||
*/
|
||||
'marketTypeId': number;
|
||||
/**
|
||||
* Number of units to reprocess.
|
||||
*/
|
||||
'quantity': number;
|
||||
}
|
||||
/**
|
||||
* A quantity of a single market type.
|
||||
*/
|
||||
export interface MarketTypeStackResponse {
|
||||
/**
|
||||
* EVE market type (item) id.
|
||||
*/
|
||||
'marketTypeId': number;
|
||||
/**
|
||||
* Number of units in the stack.
|
||||
*/
|
||||
'quantity': number;
|
||||
}
|
||||
/**
|
||||
* The authenticated user and the characters they own.
|
||||
*/
|
||||
export interface MeResponse {
|
||||
/**
|
||||
* Unique user identifier.
|
||||
*/
|
||||
'userId': string;
|
||||
/**
|
||||
* Characters owned by the user.
|
||||
*/
|
||||
'characters': Array<CharacterResponse>;
|
||||
}
|
||||
/**
|
||||
* A freshly minted access token.
|
||||
*/
|
||||
export interface RefreshResponse {
|
||||
/**
|
||||
* Short-lived bearer access token (JWT) for the Authorization header.
|
||||
*/
|
||||
'accessToken': string;
|
||||
}
|
||||
/**
|
||||
* Request to reprocess a set of item stacks on behalf of a character.
|
||||
*/
|
||||
export interface ReprocessItemsRequest {
|
||||
/**
|
||||
* EVE character id whose reprocessing skills and facility standings are applied.
|
||||
*/
|
||||
'characterId': number;
|
||||
/**
|
||||
* Item stacks to reprocess.
|
||||
*/
|
||||
'items': Array<MarketTypeStackRequest>;
|
||||
}
|
||||
/**
|
||||
* Result of reprocessing an item stack: the input stack and the resulting material outputs, each valued at market prices.
|
||||
*/
|
||||
export interface ReprocessingResultResponse {
|
||||
/**
|
||||
* The input stack that was reprocessed.
|
||||
*/
|
||||
'input': MarketTypeStackAppraisalResponse;
|
||||
/**
|
||||
* Material stacks yielded by reprocessing the input.
|
||||
*/
|
||||
'output': Array<MarketTypeStackAppraisalResponse>;
|
||||
}
|
||||
/**
|
||||
* A rule book: a named script that classifies transactions, together with the ledger references it expects.
|
||||
*/
|
||||
export interface RuleBookResponse {
|
||||
/**
|
||||
* Unique rule book identifier.
|
||||
*/
|
||||
'ruleBookId': string;
|
||||
/**
|
||||
* Rule book name.
|
||||
*/
|
||||
'name': string;
|
||||
/**
|
||||
* Whether this rule book is used to derive acquisitions.
|
||||
*/
|
||||
'usedForAcquisitions': boolean;
|
||||
/**
|
||||
* Symbolic ledger references the script writes to; each must be bound to a ledger per character.
|
||||
*/
|
||||
'ledgerRefs': Array<string>;
|
||||
/**
|
||||
* The classification script source.
|
||||
*/
|
||||
'script': string;
|
||||
}
|
||||
/**
|
||||
* Lightweight reference to a rule book: its id and name only.
|
||||
*/
|
||||
export interface RuleBookSummaryResponse {
|
||||
/**
|
||||
* Unique rule book identifier.
|
||||
*/
|
||||
'ruleBookId': string;
|
||||
/**
|
||||
* Rule book name.
|
||||
*/
|
||||
'name': string;
|
||||
}
|
||||
/**
|
||||
* Request to assign a rule book to a character, binding each of its ledger references to a concrete ledger.
|
||||
*/
|
||||
export interface SetCharacterRuleBookRequest {
|
||||
/**
|
||||
* Id of the rule book to assign.
|
||||
*/
|
||||
'ruleBookId': string;
|
||||
/**
|
||||
* Bindings from each ledger reference name to the ledger id it resolves to for this character.
|
||||
*/
|
||||
'bindings': { [key: string]: string; };
|
||||
}
|
||||
/**
|
||||
* A transaction: a dated, described group of transfers between ledgers.
|
||||
*/
|
||||
export interface TransactionResponse {
|
||||
/**
|
||||
* Unique transaction identifier.
|
||||
*/
|
||||
'transactionId': string;
|
||||
'characterId': number;
|
||||
/**
|
||||
* EVE character id the transaction is attributed to, if any.
|
||||
*/
|
||||
'characterId': number | null;
|
||||
/**
|
||||
* When the transaction occurred.
|
||||
*/
|
||||
'datetime': string;
|
||||
/**
|
||||
* Human-readable description of the transaction.
|
||||
*/
|
||||
'description': string;
|
||||
/**
|
||||
* The transfers that make up this transaction.
|
||||
*/
|
||||
'transfers': Array<TransferResponse>;
|
||||
}
|
||||
/**
|
||||
* @type TransferResponse
|
||||
* A transfer between two ledgers, either of ISK or of an item stack.
|
||||
*/
|
||||
export type TransferResponse = { type: 'ISK' } & IskTransferResponse | { type: 'ITEM' } & ItemTransferResponse;
|
||||
|
||||
/**
|
||||
* Request to update an existing combined ledger; replaces its name and member set.
|
||||
*/
|
||||
export interface UpdateCombinedLedgerRequest {
|
||||
/**
|
||||
* New name for the combined ledger.
|
||||
*/
|
||||
'name': string;
|
||||
/**
|
||||
* Ids of the ledgers to aggregate.
|
||||
*/
|
||||
'memberLedgerIds': Array<string>;
|
||||
}
|
||||
/**
|
||||
* Request to update an existing main ledger.
|
||||
*/
|
||||
export interface UpdateMainLedgerRequest {
|
||||
/**
|
||||
* New name for the ledger.
|
||||
*/
|
||||
'name': string;
|
||||
}
|
||||
/**
|
||||
* Request to update an existing rule book; replaces its mutable fields.
|
||||
*/
|
||||
export interface UpdateRuleBookRequest {
|
||||
/**
|
||||
* Rule book name.
|
||||
*/
|
||||
'name': string;
|
||||
/**
|
||||
* Whether this rule book is used to derive acquisitions.
|
||||
*/
|
||||
'usedForAcquisitions': boolean;
|
||||
/**
|
||||
* Symbolic ledger references the script writes to; each must be bound to a ledger per character.
|
||||
*/
|
||||
'ledgerRefs': Array<string>;
|
||||
/**
|
||||
* The classification script source.
|
||||
*/
|
||||
'script': string;
|
||||
}
|
||||
|
||||
@@ -557,6 +995,281 @@ export class ActivityApi extends BaseAPI {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* AuthApi - axios parameter creator
|
||||
*/
|
||||
export const AuthApiAxiosParamCreator = function (configuration?: Configuration) {
|
||||
return {
|
||||
/**
|
||||
*
|
||||
* @summary Seed the current user in the session so the next SSO links the new character to them
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
addCharacter: async (options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
|
||||
const localVarPath = `/characters/add`;
|
||||
// use dummy base URL string because the URL constructor only accepts absolute URLs.
|
||||
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
|
||||
let baseOptions;
|
||||
if (configuration) {
|
||||
baseOptions = configuration.baseOptions;
|
||||
}
|
||||
|
||||
const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options};
|
||||
const localVarHeaderParameter = {} as any;
|
||||
const localVarQueryParameter = {} as any;
|
||||
|
||||
|
||||
setSearchParams(localVarUrlObj, localVarQueryParameter);
|
||||
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
||||
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
|
||||
|
||||
return {
|
||||
url: toPathString(localVarUrlObj),
|
||||
options: localVarRequestOptions,
|
||||
};
|
||||
},
|
||||
/**
|
||||
*
|
||||
* @summary Revoke the refresh session and clear the refresh cookie
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
logout: async (options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
|
||||
const localVarPath = `/logout`;
|
||||
// use dummy base URL string because the URL constructor only accepts absolute URLs.
|
||||
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
|
||||
let baseOptions;
|
||||
if (configuration) {
|
||||
baseOptions = configuration.baseOptions;
|
||||
}
|
||||
|
||||
const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options};
|
||||
const localVarHeaderParameter = {} as any;
|
||||
const localVarQueryParameter = {} as any;
|
||||
|
||||
|
||||
setSearchParams(localVarUrlObj, localVarQueryParameter);
|
||||
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
||||
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
|
||||
|
||||
return {
|
||||
url: toPathString(localVarUrlObj),
|
||||
options: localVarRequestOptions,
|
||||
};
|
||||
},
|
||||
/**
|
||||
*
|
||||
* @summary Return the authenticated user and the characters they own
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
me: async (options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
|
||||
const localVarPath = `/me`;
|
||||
// use dummy base URL string because the URL constructor only accepts absolute URLs.
|
||||
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
|
||||
let baseOptions;
|
||||
if (configuration) {
|
||||
baseOptions = configuration.baseOptions;
|
||||
}
|
||||
|
||||
const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options};
|
||||
const localVarHeaderParameter = {} as any;
|
||||
const localVarQueryParameter = {} as any;
|
||||
|
||||
localVarHeaderParameter['Accept'] = '*/*';
|
||||
|
||||
setSearchParams(localVarUrlObj, localVarQueryParameter);
|
||||
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
||||
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
|
||||
|
||||
return {
|
||||
url: toPathString(localVarUrlObj),
|
||||
options: localVarRequestOptions,
|
||||
};
|
||||
},
|
||||
/**
|
||||
*
|
||||
* @summary Rotate the refresh session and mint a fresh access token
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
refresh: async (options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
|
||||
const localVarPath = `/refresh`;
|
||||
// use dummy base URL string because the URL constructor only accepts absolute URLs.
|
||||
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
|
||||
let baseOptions;
|
||||
if (configuration) {
|
||||
baseOptions = configuration.baseOptions;
|
||||
}
|
||||
|
||||
const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options};
|
||||
const localVarHeaderParameter = {} as any;
|
||||
const localVarQueryParameter = {} as any;
|
||||
|
||||
localVarHeaderParameter['Accept'] = '*/*';
|
||||
|
||||
setSearchParams(localVarUrlObj, localVarQueryParameter);
|
||||
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
||||
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
|
||||
|
||||
return {
|
||||
url: toPathString(localVarUrlObj),
|
||||
options: localVarRequestOptions,
|
||||
};
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* AuthApi - functional programming interface
|
||||
*/
|
||||
export const AuthApiFp = function(configuration?: Configuration) {
|
||||
const localVarAxiosParamCreator = AuthApiAxiosParamCreator(configuration)
|
||||
return {
|
||||
/**
|
||||
*
|
||||
* @summary Seed the current user in the session so the next SSO links the new character to them
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
async addCharacter(options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<void>> {
|
||||
const localVarAxiosArgs = await localVarAxiosParamCreator.addCharacter(options);
|
||||
const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
|
||||
const localVarOperationServerBasePath = operationServerMap['AuthApi.addCharacter']?.[localVarOperationServerIndex]?.url;
|
||||
return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
|
||||
},
|
||||
/**
|
||||
*
|
||||
* @summary Revoke the refresh session and clear the refresh cookie
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
async logout(options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<void>> {
|
||||
const localVarAxiosArgs = await localVarAxiosParamCreator.logout(options);
|
||||
const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
|
||||
const localVarOperationServerBasePath = operationServerMap['AuthApi.logout']?.[localVarOperationServerIndex]?.url;
|
||||
return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
|
||||
},
|
||||
/**
|
||||
*
|
||||
* @summary Return the authenticated user and the characters they own
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
async me(options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<MeResponse>> {
|
||||
const localVarAxiosArgs = await localVarAxiosParamCreator.me(options);
|
||||
const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
|
||||
const localVarOperationServerBasePath = operationServerMap['AuthApi.me']?.[localVarOperationServerIndex]?.url;
|
||||
return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
|
||||
},
|
||||
/**
|
||||
*
|
||||
* @summary Rotate the refresh session and mint a fresh access token
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
async refresh(options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<RefreshResponse>> {
|
||||
const localVarAxiosArgs = await localVarAxiosParamCreator.refresh(options);
|
||||
const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
|
||||
const localVarOperationServerBasePath = operationServerMap['AuthApi.refresh']?.[localVarOperationServerIndex]?.url;
|
||||
return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* AuthApi - factory interface
|
||||
*/
|
||||
export const AuthApiFactory = function (configuration?: Configuration, basePath?: string, axios?: AxiosInstance) {
|
||||
const localVarFp = AuthApiFp(configuration)
|
||||
return {
|
||||
/**
|
||||
*
|
||||
* @summary Seed the current user in the session so the next SSO links the new character to them
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
addCharacter(options?: RawAxiosRequestConfig): AxiosPromise<void> {
|
||||
return localVarFp.addCharacter(options).then((request) => request(axios, basePath));
|
||||
},
|
||||
/**
|
||||
*
|
||||
* @summary Revoke the refresh session and clear the refresh cookie
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
logout(options?: RawAxiosRequestConfig): AxiosPromise<void> {
|
||||
return localVarFp.logout(options).then((request) => request(axios, basePath));
|
||||
},
|
||||
/**
|
||||
*
|
||||
* @summary Return the authenticated user and the characters they own
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
me(options?: RawAxiosRequestConfig): AxiosPromise<MeResponse> {
|
||||
return localVarFp.me(options).then((request) => request(axios, basePath));
|
||||
},
|
||||
/**
|
||||
*
|
||||
* @summary Rotate the refresh session and mint a fresh access token
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
refresh(options?: RawAxiosRequestConfig): AxiosPromise<RefreshResponse> {
|
||||
return localVarFp.refresh(options).then((request) => request(axios, basePath));
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* AuthApi - object-oriented interface
|
||||
*/
|
||||
export class AuthApi extends BaseAPI {
|
||||
/**
|
||||
*
|
||||
* @summary Seed the current user in the session so the next SSO links the new character to them
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
public addCharacter(options?: RawAxiosRequestConfig) {
|
||||
return AuthApiFp(this.configuration).addCharacter(options).then((request) => request(this.axios, this.basePath));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @summary Revoke the refresh session and clear the refresh cookie
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
public logout(options?: RawAxiosRequestConfig) {
|
||||
return AuthApiFp(this.configuration).logout(options).then((request) => request(this.axios, this.basePath));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @summary Return the authenticated user and the characters they own
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
public me(options?: RawAxiosRequestConfig) {
|
||||
return AuthApiFp(this.configuration).me(options).then((request) => request(this.axios, this.basePath));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @summary Rotate the refresh session and mint a fresh access token
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
public refresh(options?: RawAxiosRequestConfig) {
|
||||
return AuthApiFp(this.configuration).refresh(options).then((request) => request(this.axios, this.basePath));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* CharacterApi - axios parameter creator
|
||||
*/
|
||||
|
||||
+16
-6
@@ -1,9 +1,10 @@
|
||||
import { createPinia } from 'pinia';
|
||||
import { createApp } from 'vue';
|
||||
import { createRouter, createWebHistory } from 'vue-router';
|
||||
import {createPinia} from 'pinia';
|
||||
import {createApp} from 'vue';
|
||||
import {createRouter, createWebHistory} from 'vue-router';
|
||||
import App from './App.vue';
|
||||
import { initLogger } from './logger';
|
||||
import { routes } from './routes';
|
||||
import {useAuthStore} from './auth';
|
||||
import {initLogger} from './logger';
|
||||
import {routeNames, routes} from './routes';
|
||||
import './style.css';
|
||||
|
||||
initLogger();
|
||||
@@ -18,4 +19,13 @@ const router = createRouter({
|
||||
app.use(pinia);
|
||||
app.use(router);
|
||||
|
||||
app.mount('#app');
|
||||
const authStore = useAuthStore();
|
||||
|
||||
router.beforeEach(to => {
|
||||
if (!to.meta.public && !authStore.isAuthenticated) {
|
||||
return {name: routeNames.home};
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
authStore.bootstrap().finally(() => app.mount('#app'));
|
||||
@@ -1,19 +1,22 @@
|
||||
import {logResource} from "@/service";
|
||||
import axios from "axios";
|
||||
import {getAccessToken, setAccessToken} from "@/auth/token";
|
||||
import axios, {InternalAxiosRequestConfig} from "axios";
|
||||
import {
|
||||
AcquisitionApi,
|
||||
ActivityApi,
|
||||
AuthApi,
|
||||
CharacterApi,
|
||||
CharacterRuleBookApi,
|
||||
LedgerApi,
|
||||
MarketApi,
|
||||
MeResponse,
|
||||
ReprocessingApi,
|
||||
RuleBookApi,
|
||||
TransactionApi
|
||||
} from "@/generated/mammon";
|
||||
|
||||
export const mammonUrl = import.meta.env.VITE_MAMMON_URL;
|
||||
export const mammonAddCharacterUrl = mammonUrl + "oauth2/authorization/esi"
|
||||
export const mammonLoginUrl = mammonUrl + "oauth2/authorization/esi"
|
||||
|
||||
const mammonAxiosInstance = axios.create({
|
||||
baseURL: mammonUrl,
|
||||
@@ -24,6 +27,76 @@ const mammonAxiosInstance = axios.create({
|
||||
})
|
||||
logResource(mammonAxiosInstance)
|
||||
|
||||
const credentialedClient = axios.create({
|
||||
baseURL: mammonUrl,
|
||||
withCredentials: true,
|
||||
})
|
||||
logResource(credentialedClient)
|
||||
|
||||
mammonAxiosInstance.interceptors.request.use(config => {
|
||||
const token = getAccessToken();
|
||||
|
||||
if (token) {
|
||||
config.headers.Authorization = `Bearer ${token}`;
|
||||
}
|
||||
return config;
|
||||
})
|
||||
|
||||
const authApi = new AuthApi(undefined, mammonUrl, mammonAxiosInstance);
|
||||
const credentialedAuthApi = new AuthApi(undefined, mammonUrl, credentialedClient);
|
||||
|
||||
let onAuthExpired: () => void = () => {};
|
||||
|
||||
export const setOnAuthExpired = (callback: () => void): void => {
|
||||
onAuthExpired = callback;
|
||||
}
|
||||
|
||||
let refreshing: Promise<string | null> | null = null;
|
||||
|
||||
export const refreshAccessToken = (): Promise<string | null> => {
|
||||
if (!refreshing) {
|
||||
refreshing = credentialedAuthApi.refresh()
|
||||
.then(response => {
|
||||
setAccessToken(response.data.accessToken);
|
||||
return response.data.accessToken;
|
||||
})
|
||||
.catch(() => {
|
||||
setAccessToken(null);
|
||||
return null;
|
||||
})
|
||||
.finally(() => {
|
||||
refreshing = null;
|
||||
});
|
||||
}
|
||||
return refreshing;
|
||||
}
|
||||
|
||||
mammonAxiosInstance.interceptors.response.use(response => response, async error => {
|
||||
const original = error.config as (InternalAxiosRequestConfig & { _retried?: boolean }) | undefined;
|
||||
|
||||
if (error.response?.status === 401 && original && !original._retried) {
|
||||
original._retried = true;
|
||||
|
||||
const token = await refreshAccessToken();
|
||||
|
||||
if (token) {
|
||||
original.headers.Authorization = `Bearer ${token}`;
|
||||
return mammonAxiosInstance(original);
|
||||
}
|
||||
onAuthExpired();
|
||||
}
|
||||
return Promise.reject(error);
|
||||
})
|
||||
|
||||
export const fetchMe = (): Promise<MeResponse> =>
|
||||
authApi.me().then(response => response.data);
|
||||
|
||||
export const addCharacter = (): Promise<void> =>
|
||||
authApi.addCharacter({withCredentials: true}).then(() => undefined);
|
||||
|
||||
export const postLogout = (): Promise<void> =>
|
||||
credentialedAuthApi.logout().then(() => undefined);
|
||||
|
||||
export const ledgerApi = new LedgerApi(undefined, mammonUrl, mammonAxiosInstance);
|
||||
export const transactionApi = new TransactionApi(undefined, mammonUrl, mammonAxiosInstance);
|
||||
export const characterApi = new CharacterApi(undefined, mammonUrl, mammonAxiosInstance);
|
||||
@@ -32,4 +105,4 @@ export const characterRuleBookApi = new CharacterRuleBookApi(undefined, mammonUr
|
||||
export const activityApi = new ActivityApi(undefined, mammonUrl, mammonAxiosInstance);
|
||||
export const acquisitionApi = new AcquisitionApi(undefined, mammonUrl, mammonAxiosInstance);
|
||||
export const marketApi = new MarketApi(undefined, mammonUrl, mammonAxiosInstance);
|
||||
export const reprocessingApi = new ReprocessingApi(undefined, mammonUrl, mammonAxiosInstance);
|
||||
export const reprocessingApi = new ReprocessingApi(undefined, mammonUrl, mammonAxiosInstance);
|
||||
@@ -1,14 +1,13 @@
|
||||
<script setup lang="ts">
|
||||
|
||||
import {mammonAddCharacterUrl} from "@/mammon";
|
||||
import {CharacterLabel, useCharactersStore} from "@/characters";
|
||||
import {useAuthStore} from "@/auth";
|
||||
import {ArrowPathIcon} from '@heroicons/vue/24/outline';
|
||||
|
||||
const charactersStore = useCharactersStore()
|
||||
const authStore = useAuthStore()
|
||||
|
||||
const addCharacter = () => {
|
||||
window.location.replace(mammonAddCharacterUrl);
|
||||
}
|
||||
const addCharacter = () => authStore.addCharacter();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
+9
-1
@@ -1,6 +1,14 @@
|
||||
<script setup lang="ts">
|
||||
import {useAuthStore} from '@/auth';
|
||||
|
||||
const authStore = useAuthStore();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div></div>
|
||||
<div class="flex flex-col items-center justify-center h-screen gap-4">
|
||||
<h1 class="text-2xl">eveal</h1>
|
||||
<button v-if="!authStore.isAuthenticated" @click="authStore.login()">
|
||||
Login with EVE Online
|
||||
</button>
|
||||
</div>
|
||||
</template>
|
||||
+9
-3
@@ -1,5 +1,11 @@
|
||||
import {RouteRecordRaw} from 'vue-router';
|
||||
|
||||
declare module 'vue-router' {
|
||||
interface RouteMeta {
|
||||
public?: boolean;
|
||||
}
|
||||
}
|
||||
|
||||
export const routeNames = {
|
||||
home: 'home',
|
||||
callback: 'callback',
|
||||
@@ -15,8 +21,8 @@ export const routeNames = {
|
||||
} as const;
|
||||
|
||||
export const routes: RouteRecordRaw[] = [
|
||||
{path: '/', name: routeNames.home, component: () => import('@/pages/Index.vue')},
|
||||
{path: '/callback', name: routeNames.callback, component: () => import('@/pages/Index.vue')},
|
||||
{path: '/', name: routeNames.home, component: () => import('@/pages/Index.vue'), meta: {public: true}},
|
||||
{path: '/callback', name: routeNames.callback, component: () => import('@/pages/Index.vue'), meta: {public: true}},
|
||||
|
||||
{path: '/ledgers', component: () => import('@/pages/Ledgers.vue'), children: [
|
||||
{path: '', component: () => import('@/pages/ledger/ListLedgers.vue')},
|
||||
@@ -52,5 +58,5 @@ export const routes: RouteRecordRaw[] = [
|
||||
{path: '/tools', component: () => import('@/pages/Tools.vue')},
|
||||
|
||||
{path: '/characters', component: () => import('@/pages/Characters.vue')},
|
||||
{path: '/about', name: routeNames.about, component: () => import('@/pages/About.vue')},
|
||||
{path: '/about', name: routeNames.about, component: () => import('@/pages/About.vue'), meta: {public: true}},
|
||||
] as const;
|
||||
@@ -1,7 +1,13 @@
|
||||
<script setup lang="ts">
|
||||
import {Dropdown} from '@/components';
|
||||
import {RouterLink} from 'vue-router';
|
||||
import {computed} from 'vue';
|
||||
import {routeNames} from '@/routes';
|
||||
import {useAuthStore} from '@/auth';
|
||||
|
||||
const authStore = useAuthStore();
|
||||
|
||||
const name = computed(() => authStore.characters[0]?.name ?? 'NAME');
|
||||
|
||||
const links = [
|
||||
{name: "Market", path: "/market"},
|
||||
@@ -12,8 +18,7 @@ const links = [
|
||||
];
|
||||
|
||||
|
||||
const logout = async () => {
|
||||
}
|
||||
const logout = () => authStore.logout();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -22,7 +27,7 @@ const logout = async () => {
|
||||
<div class="mb-2 border-b-2 border-emerald-500">
|
||||
<Dropdown class="mb-2 user-dropdown">
|
||||
<template #button>
|
||||
<span>NAME</span>
|
||||
<span>{{ name }}</span>
|
||||
</template>
|
||||
<ul>
|
||||
<li>
|
||||
|
||||
Reference in New Issue
Block a user