@evefrontier/dapp-kit 0.1.9 → 0.2.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -25
- package/dist/config/dapp-kit.d.ts +4 -0
- package/dist/config/dapp-kit.d.ts.map +1 -0
- package/dist/config/dapp-kit.js +14 -0
- package/dist/config/index.d.ts +2 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +1 -0
- package/dist/graphql/client.d.ts +277 -0
- package/dist/graphql/client.d.ts.map +1 -0
- package/dist/graphql/client.js +346 -0
- package/dist/graphql/index.d.ts +4 -0
- package/dist/graphql/index.d.ts.map +1 -0
- package/dist/graphql/index.js +16 -0
- package/dist/graphql/queries.d.ts +103 -0
- package/dist/graphql/queries.d.ts.map +1 -0
- package/{graphql/queries.ts → dist/graphql/queries.js} +113 -223
- package/dist/graphql/types.d.ts +396 -0
- package/dist/graphql/types.d.ts.map +1 -0
- package/dist/graphql/types.js +4 -0
- package/dist/hooks/index.d.ts +10 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +8 -0
- package/dist/hooks/useCharacterDirectory.d.ts +16 -0
- package/dist/hooks/useCharacterDirectory.d.ts.map +1 -0
- package/dist/hooks/useCharacterDirectory.js +23 -0
- package/dist/hooks/useCharacterSearch.d.ts +24 -0
- package/dist/hooks/useCharacterSearch.d.ts.map +1 -0
- package/dist/hooks/useCharacterSearch.js +24 -0
- package/dist/hooks/useConnection.d.ts +51 -0
- package/dist/hooks/useConnection.d.ts.map +1 -0
- package/{hooks/useConnection.ts → dist/hooks/useConnection.js} +8 -10
- package/dist/hooks/useEntityRole.d.ts +26 -0
- package/dist/hooks/useEntityRole.d.ts.map +1 -0
- package/dist/hooks/useEntityRole.js +91 -0
- package/dist/hooks/useNotification.d.ts +72 -0
- package/dist/hooks/useNotification.d.ts.map +1 -0
- package/{hooks/useNotification.ts → dist/hooks/useNotification.js} +8 -12
- package/dist/hooks/useSmartObject.d.ts +44 -0
- package/dist/hooks/useSmartObject.d.ts.map +1 -0
- package/dist/hooks/useSmartObject.js +50 -0
- package/dist/hooks/useSponsoredTransaction.d.ts +147 -0
- package/dist/hooks/useSponsoredTransaction.d.ts.map +1 -0
- package/dist/hooks/useSponsoredTransaction.js +240 -0
- package/dist/hooks/useTypeNames.d.ts +11 -0
- package/dist/hooks/useTypeNames.d.ts.map +1 -0
- package/dist/hooks/useTypeNames.js +24 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/providers/EveFrontierProvider.d.ts +23 -0
- package/dist/providers/EveFrontierProvider.d.ts.map +1 -0
- package/dist/providers/EveFrontierProvider.js +23 -0
- package/dist/providers/NotificationProvider.d.ts +14 -0
- package/dist/providers/NotificationProvider.d.ts.map +1 -0
- package/dist/providers/NotificationProvider.js +66 -0
- package/dist/providers/SmartObjectProvider.d.ts +31 -0
- package/dist/providers/SmartObjectProvider.d.ts.map +1 -0
- package/dist/providers/SmartObjectProvider.js +80 -0
- package/dist/providers/VaultProvider.d.ts +10 -0
- package/dist/providers/VaultProvider.d.ts.map +1 -0
- package/dist/providers/VaultProvider.js +79 -0
- package/dist/providers/index.d.ts +5 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +4 -0
- package/dist/providers/smartObject/useEntityData.d.ts +29 -0
- package/dist/providers/smartObject/useEntityData.d.ts.map +1 -0
- package/dist/providers/smartObject/useEntityData.js +135 -0
- package/dist/providers/smartObject/useEntitySubscription.d.ts +14 -0
- package/dist/providers/smartObject/useEntitySubscription.d.ts.map +1 -0
- package/dist/providers/smartObject/useEntitySubscription.js +58 -0
- package/dist/providers/smartObject/useObjectSelection.d.ts +11 -0
- package/dist/providers/smartObject/useObjectSelection.d.ts.map +1 -0
- package/dist/providers/smartObject/useObjectSelection.js +27 -0
- package/dist/providers/smartObject/usePollingBackstop.d.ts +18 -0
- package/dist/providers/smartObject/usePollingBackstop.d.ts.map +1 -0
- package/dist/providers/smartObject/usePollingBackstop.js +38 -0
- package/dist/types/character.d.ts +21 -0
- package/dist/types/character.d.ts.map +1 -0
- package/dist/types/character.js +1 -0
- package/dist/types/contexts.d.ts +61 -0
- package/dist/types/contexts.d.ts.map +1 -0
- package/dist/types/contexts.js +6 -0
- package/dist/types/entity.d.ts +245 -0
- package/dist/types/entity.d.ts.map +1 -0
- package/dist/types/entity.js +6 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +5 -0
- package/dist/types/sponsoredTransaction.d.ts +26 -0
- package/dist/types/sponsoredTransaction.d.ts.map +1 -0
- package/dist/types/sponsoredTransaction.js +10 -0
- package/dist/types/types.d.ts +110 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/types.js +41 -0
- package/dist/types/worldApiReturnTypes.d.ts +68 -0
- package/dist/types/worldApiReturnTypes.d.ts.map +1 -0
- package/dist/types/worldApiReturnTypes.js +1 -0
- package/{utils/burnRate.ts → dist/utils/burnRate.d.ts} +4 -29
- package/dist/utils/burnRate.d.ts.map +1 -0
- package/dist/utils/burnRate.js +25 -0
- package/dist/utils/characters.d.ts +26 -0
- package/dist/utils/characters.d.ts.map +1 -0
- package/dist/utils/characters.js +84 -0
- package/dist/utils/constants.d.ts +153 -0
- package/dist/utils/constants.d.ts.map +1 -0
- package/dist/utils/constants.js +190 -0
- package/dist/utils/datahub.d.ts +40 -0
- package/dist/utils/datahub.d.ts.map +1 -0
- package/{utils/datahub.ts → dist/utils/datahub.js} +32 -25
- package/dist/utils/entity.d.ts +58 -0
- package/dist/utils/entity.d.ts.map +1 -0
- package/dist/utils/entity.js +386 -0
- package/dist/utils/errors.d.ts +18 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +128 -0
- package/dist/utils/events/entityEvents.d.ts +44 -0
- package/dist/utils/events/entityEvents.d.ts.map +1 -0
- package/dist/utils/events/entityEvents.js +95 -0
- package/dist/utils/events/entitySubscription.d.ts +30 -0
- package/dist/utils/events/entitySubscription.d.ts.map +1 -0
- package/dist/utils/events/entitySubscription.js +84 -0
- package/dist/utils/events/graphqlEventStream.d.ts +90 -0
- package/dist/utils/events/graphqlEventStream.d.ts.map +1 -0
- package/dist/utils/events/graphqlEventStream.js +198 -0
- package/dist/utils/events/refetchScheduler.d.ts +30 -0
- package/dist/utils/events/refetchScheduler.d.ts.map +1 -0
- package/dist/utils/events/refetchScheduler.js +57 -0
- package/dist/utils/events/sseClient.d.ts +42 -0
- package/dist/utils/events/sseClient.d.ts.map +1 -0
- package/dist/utils/events/sseClient.js +97 -0
- package/dist/utils/fuel.d.ts +231 -0
- package/dist/utils/fuel.d.ts.map +1 -0
- package/dist/utils/fuel.js +652 -0
- package/dist/utils/grid.d.ts +115 -0
- package/dist/utils/grid.d.ts.map +1 -0
- package/dist/utils/grid.js +115 -0
- package/dist/utils/index.d.ts +15 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +22 -0
- package/dist/utils/inventory.d.ts +3 -0
- package/dist/utils/inventory.d.ts.map +1 -0
- package/dist/utils/inventory.js +12 -0
- package/dist/utils/logger.d.ts +25 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +228 -0
- package/dist/utils/mapping.d.ts +30 -0
- package/dist/utils/mapping.d.ts.map +1 -0
- package/dist/utils/mapping.js +73 -0
- package/dist/utils/mvr/worldTypes.d.ts +35 -0
- package/dist/utils/mvr/worldTypes.d.ts.map +1 -0
- package/dist/utils/mvr/worldTypes.js +54 -0
- package/dist/utils/role.d.ts +116 -0
- package/dist/utils/role.d.ts.map +1 -0
- package/dist/utils/role.js +120 -0
- package/dist/utils/smartObject.d.ts +24 -0
- package/dist/utils/smartObject.d.ts.map +1 -0
- package/dist/utils/smartObject.js +24 -0
- package/dist/utils/utils.d.ts +133 -0
- package/dist/utils/utils.d.ts.map +1 -0
- package/dist/utils/utils.js +213 -0
- package/dist/wallet/features.d.ts +28 -0
- package/dist/wallet/features.d.ts.map +1 -0
- package/dist/wallet/features.js +22 -0
- package/dist/wallet/index.d.ts +9 -0
- package/dist/wallet/index.d.ts.map +1 -0
- package/dist/wallet/index.js +9 -0
- package/dist/wallet/utils.d.ts +71 -0
- package/dist/wallet/utils.d.ts.map +1 -0
- package/dist/wallet/utils.js +79 -0
- package/package.json +69 -35
- package/config/dapp-kit.ts +0 -20
- package/config/index.ts +0 -1
- package/graphql/client.ts +0 -578
- package/graphql/index.ts +0 -39
- package/graphql/types.ts +0 -468
- package/hooks/index.ts +0 -15
- package/hooks/useSmartObject.ts +0 -66
- package/hooks/useSponsoredTransaction.ts +0 -442
- package/index.ts +0 -88
- package/providers/EveFrontierProvider.tsx +0 -41
- package/providers/NotificationProvider.tsx +0 -108
- package/providers/SmartObjectProvider.tsx +0 -296
- package/providers/VaultProvider.tsx +0 -108
- package/providers/index.ts +0 -10
- package/types/contexts.ts +0 -67
- package/types/global.d.ts +0 -7
- package/types/index.ts +0 -4
- package/types/sponsoredTransaction.ts +0 -70
- package/types/types.ts +0 -198
- package/types/worldApiReturnTypes.ts +0 -144
- package/utils/__tests__/burnRate.test.ts +0 -121
- package/utils/__tests__/character.test.ts +0 -112
- package/utils/__tests__/characterOwnedObjects.test.ts +0 -225
- package/utils/__tests__/config.test.ts +0 -424
- package/utils/__tests__/datahub.test.ts +0 -58
- package/utils/__tests__/logger.test.ts +0 -145
- package/utils/__tests__/mapping.test.ts +0 -439
- package/utils/__tests__/utils.test.ts +0 -299
- package/utils/character.ts +0 -46
- package/utils/characterOwnedObjects.ts +0 -53
- package/utils/config.ts +0 -151
- package/utils/constants.ts +0 -254
- package/utils/errors.ts +0 -171
- package/utils/index.ts +0 -47
- package/utils/logger.ts +0 -300
- package/utils/mapping.ts +0 -118
- package/utils/transforms.ts +0 -263
- package/utils/utils.ts +0 -270
- package/wallet/features.ts +0 -136
- package/wallet/index.ts +0 -26
- package/wallet/utils.ts +0 -117
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { getEventsByType } from '../graphql/client.js';
|
|
2
|
+
import { getWorldPackageId, getWorldType } from './mvr/worldTypes.js';
|
|
3
|
+
/** Pages in every event of a type, oldest first. */
|
|
4
|
+
async function fetchAllEvents(eventType) {
|
|
5
|
+
const events = [];
|
|
6
|
+
let after;
|
|
7
|
+
do {
|
|
8
|
+
const response = await getEventsByType(eventType, after ? { after } : {});
|
|
9
|
+
if (response.errors?.length) {
|
|
10
|
+
throw new Error(response.errors.map((e) => e.message).join('; '));
|
|
11
|
+
}
|
|
12
|
+
const page = response.data?.events;
|
|
13
|
+
if (!page)
|
|
14
|
+
break;
|
|
15
|
+
events.push(...page.nodes);
|
|
16
|
+
after = page.pageInfo.hasNextPage
|
|
17
|
+
? (page.pageInfo.endCursor ?? undefined)
|
|
18
|
+
: undefined;
|
|
19
|
+
} while (after);
|
|
20
|
+
return events;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Builds the list of every character from world events: `CharacterCreated`
|
|
24
|
+
* gives the character's wallet, and the latest `MetadataChanged`
|
|
25
|
+
* for that character gives its name. There is no on-chain name index, so the
|
|
26
|
+
* whole list is fetched and searched client-side.
|
|
27
|
+
*
|
|
28
|
+
* @category Utilities - Characters
|
|
29
|
+
* @param tenant - Tenant whose tier to use when VITE_EVE_WORLD_TIER is unset
|
|
30
|
+
* @returns Every character, in creation order
|
|
31
|
+
* @throws If a GraphQL response has errors
|
|
32
|
+
*/
|
|
33
|
+
export async function fetchCharacterDirectory(tenant) {
|
|
34
|
+
// TODO(wallet-core): use getWorldType once MetadataChanged is in WORLD_TYPE_KEYS
|
|
35
|
+
const metadataChangedType = `${getWorldPackageId('metadata', tenant)}::metadata::MetadataChanged`;
|
|
36
|
+
const [created, renamed] = await Promise.all([
|
|
37
|
+
fetchAllEvents(getWorldType('character::identity::CharacterCreated', tenant)),
|
|
38
|
+
fetchAllEvents(metadataChangedType),
|
|
39
|
+
]);
|
|
40
|
+
const names = new Map();
|
|
41
|
+
for (const event of renamed) {
|
|
42
|
+
const json = event.contents?.json;
|
|
43
|
+
if (json)
|
|
44
|
+
names.set(json.entity_id, json.name);
|
|
45
|
+
}
|
|
46
|
+
const characters = [];
|
|
47
|
+
for (const event of created) {
|
|
48
|
+
const json = event.contents?.json;
|
|
49
|
+
if (!json)
|
|
50
|
+
continue;
|
|
51
|
+
characters.push({
|
|
52
|
+
characterId: json.character_id,
|
|
53
|
+
name: names.get(json.character_id) ?? '',
|
|
54
|
+
walletAddress: json.character_address,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
return characters;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Searches characters by name, case-insensitively, with prefix matches first.
|
|
61
|
+
* A query starting with `0x` matches nothing: an address is not searched, it
|
|
62
|
+
* is entered in full.
|
|
63
|
+
*
|
|
64
|
+
* @category Utilities - Characters
|
|
65
|
+
* @param characters - From {@link fetchCharacterDirectory}
|
|
66
|
+
* @param query - Search text
|
|
67
|
+
* @param limit - Maximum number of results
|
|
68
|
+
* @returns Matching characters
|
|
69
|
+
*/
|
|
70
|
+
export function searchCharacters(characters, query, limit = 20) {
|
|
71
|
+
const needle = query.trim().toLowerCase();
|
|
72
|
+
if (!needle || needle.startsWith('0x'))
|
|
73
|
+
return [];
|
|
74
|
+
const prefix = [];
|
|
75
|
+
const contains = [];
|
|
76
|
+
for (const character of characters) {
|
|
77
|
+
const index = character.name.toLowerCase().indexOf(needle);
|
|
78
|
+
if (index === 0)
|
|
79
|
+
prefix.push(character);
|
|
80
|
+
else if (index > 0)
|
|
81
|
+
contains.push(character);
|
|
82
|
+
}
|
|
83
|
+
return [...prefix, ...contains].slice(0, limit);
|
|
84
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { TENANT_CONFIG, type TenantId } from '@evefrontier/wallet-core/tenant';
|
|
2
|
+
import type { SuiGraphqlNetwork } from '../types/index.js';
|
|
3
|
+
export { getEveCoinType, isEveCoinType, } from '@evefrontier/wallet-core/eve-token';
|
|
4
|
+
export { DEFAULT_TENANT, EVE_PACKAGE_ID_BY_TENANT, TenantId, WORLD_PACKAGES, type WorldPackage, } from '@evefrontier/wallet-core/tenant';
|
|
5
|
+
/**
|
|
6
|
+
* Get the Sui GraphQL query endpoint URL for the given network.
|
|
7
|
+
*
|
|
8
|
+
* Unknown networks fall back to
|
|
9
|
+
* testnet to avoid returning undefined.
|
|
10
|
+
* @param env - Network identifier (testnet, devnet, mainnet). Defaults to testnet.
|
|
11
|
+
* @returns The GraphQL endpoint URL
|
|
12
|
+
* @category Utilities - Config
|
|
13
|
+
*/
|
|
14
|
+
export declare function getSuiGraphqlEndpoint(env?: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* Get the Sui GraphQL subscription endpoint URL for the given network: the
|
|
17
|
+
* second URL beside {@link getSuiGraphqlEndpoint}. Subscriptions are served
|
|
18
|
+
* over SSE at `/graphql/subscriptions` on the same host; the query URL rejects
|
|
19
|
+
* them. VITE_SUI_GRAPHQL_SUBSCRIPTION_URL overrides it for every network, as
|
|
20
|
+
* the counterpart of an overridden query URL.
|
|
21
|
+
*
|
|
22
|
+
* @param env - Network identifier (testnet, devnet, mainnet). Defaults to testnet.
|
|
23
|
+
* @returns The GraphQL subscription endpoint URL
|
|
24
|
+
* @category Utilities - Config
|
|
25
|
+
*/
|
|
26
|
+
export declare function getSuiGraphqlSubscriptionEndpoint(env?: string): string;
|
|
27
|
+
/**
|
|
28
|
+
* Optional bearer token for the GraphQL subscription, from
|
|
29
|
+
* VITE_GRAPHQL_SUBSCRIPTION_AUTH_TOKEN. The public endpoints need none.
|
|
30
|
+
* @category Utilities - Config
|
|
31
|
+
*/
|
|
32
|
+
export declare function getGraphqlSubscriptionAuthToken(): string | undefined;
|
|
33
|
+
export { getObjectRegistryType, getWorldPackageId, getWorldTier, getWorldType, } from './mvr/worldTypes.js';
|
|
34
|
+
/** Default Sui network for GraphQL endpoint selection.
|
|
35
|
+
* @category Constants
|
|
36
|
+
*/
|
|
37
|
+
export declare const DEFAULT_GRAPHQL_NETWORK: SuiGraphqlNetwork;
|
|
38
|
+
/** Allowed Sui network identifiers for GraphQL endpoint selection.
|
|
39
|
+
* @category Constants
|
|
40
|
+
*/
|
|
41
|
+
export declare const SUI_GRAPHQL_NETWORKS: readonly ['testnet', 'devnet', 'mainnet'];
|
|
42
|
+
/** Sui GraphQL query endpoints per network.
|
|
43
|
+
* @category Constants
|
|
44
|
+
*/
|
|
45
|
+
export declare const GRAPHQL_ENDPOINTS: Record<SuiGraphqlNetwork, string>;
|
|
46
|
+
/**
|
|
47
|
+
* Client identifier sent as the `X-Client-ID` header on GraphQL requests.
|
|
48
|
+
* Random per client, generated once and
|
|
49
|
+
* cached for the module lifetime — used for session affinity during pagination.
|
|
50
|
+
* @category Constants
|
|
51
|
+
*/
|
|
52
|
+
export declare const GRAPHQL_CLIENT_ID: `${string}-${string}-${string}-${string}-${string}`;
|
|
53
|
+
/** Sui GraphQL subscription endpoints per network: SSE, on the same host as
|
|
54
|
+
* the query endpoint. See {@link getSuiGraphqlSubscriptionEndpoint}.
|
|
55
|
+
* @category Constants
|
|
56
|
+
*/
|
|
57
|
+
export declare const GRAPHQL_SUBSCRIPTION_ENDPOINTS: Record<SuiGraphqlNetwork, string>;
|
|
58
|
+
/** gRPC base URLs for each Sui network.
|
|
59
|
+
* @category Constants
|
|
60
|
+
*/
|
|
61
|
+
export declare const SUI_GRPC_URLS: Record<SuiGraphqlNetwork, string>;
|
|
62
|
+
/** Default polling interval in milliseconds.
|
|
63
|
+
*
|
|
64
|
+
* The update source with the `polling` transport, and the fallback when the
|
|
65
|
+
* subscription fails. Each tick is a cheap version check until the object
|
|
66
|
+
* changes. Override with VITE_POLLING_INTERVAL; set it to 0 to disable
|
|
67
|
+
* polling entirely.
|
|
68
|
+
* @category Constants
|
|
69
|
+
*/
|
|
70
|
+
export declare const POLLING_INTERVAL = 15000;
|
|
71
|
+
/**
|
|
72
|
+
* Resolve the polling interval in milliseconds.
|
|
73
|
+
* Reads VITE_POLLING_INTERVAL when set (0 disables the backstop), otherwise
|
|
74
|
+
* falls back to POLLING_INTERVAL.
|
|
75
|
+
* @returns Interval in ms; 0 means the periodic poll is disabled.
|
|
76
|
+
* @category Utilities - Config
|
|
77
|
+
*/
|
|
78
|
+
export declare function getPollingInterval(): number;
|
|
79
|
+
/**
|
|
80
|
+
* How the selected entity is kept up to date:
|
|
81
|
+
* - `subscription`: refetch when a GraphQL subscription delivers one of the
|
|
82
|
+
* entity's inventory or power events, with slow polling as a backstop;
|
|
83
|
+
* falls back to `polling` on its own if the subscription fails.
|
|
84
|
+
* - `polling`: poll every {@link POLLING_INTERVAL} only.
|
|
85
|
+
* @category Constants
|
|
86
|
+
*/
|
|
87
|
+
export type UpdateTransport = 'subscription' | 'polling';
|
|
88
|
+
/** The update transport when none is given. @category Constants */
|
|
89
|
+
export declare const DEFAULT_UPDATE_TRANSPORT: UpdateTransport;
|
|
90
|
+
/** Default backstop polling interval while the subscription is up, in ms.
|
|
91
|
+
* @category Constants
|
|
92
|
+
*/
|
|
93
|
+
export declare const SUBSCRIPTION_BACKSTOP_INTERVAL = 60000;
|
|
94
|
+
/** How long the subscription may take to connect before it counts as failed, in ms.
|
|
95
|
+
* @category Constants
|
|
96
|
+
*/
|
|
97
|
+
export declare const SUBSCRIPTION_CONNECT_TIMEOUT_MS = 10000;
|
|
98
|
+
/**
|
|
99
|
+
* Resolve the backstop polling interval in ms while the subscription is up.
|
|
100
|
+
* Reads VITE_SUBSCRIPTION_POLLING_INTERVAL when set (0 disables it), otherwise
|
|
101
|
+
* SUBSCRIPTION_BACKSTOP_INTERVAL.
|
|
102
|
+
* @category Utilities - Config
|
|
103
|
+
*/
|
|
104
|
+
export declare function getSubscriptionBackstopInterval(): number;
|
|
105
|
+
/**
|
|
106
|
+
* State of the entity subscription: `off` with the `polling` transport,
|
|
107
|
+
* `connecting` until the first connect, `live` once connected, `failed` after
|
|
108
|
+
* an error or a connect timeout.
|
|
109
|
+
* @category Constants
|
|
110
|
+
*/
|
|
111
|
+
export type SubscriptionStatus = 'off' | 'connecting' | 'live' | 'failed';
|
|
112
|
+
/**
|
|
113
|
+
* The polling interval to run: the slow backstop while the subscription is
|
|
114
|
+
* connecting or live, the normal interval with `polling` or once the
|
|
115
|
+
* subscription has failed.
|
|
116
|
+
* @category Utilities - Config
|
|
117
|
+
*/
|
|
118
|
+
export declare function backstopInterval(transport: UpdateTransport, status: SubscriptionStatus): number;
|
|
119
|
+
/** Local storage keys.
|
|
120
|
+
* @category Constants
|
|
121
|
+
*/
|
|
122
|
+
export declare const STORAGE_KEYS: {
|
|
123
|
+
readonly CONNECTED: 'eve-dapp-connected';
|
|
124
|
+
};
|
|
125
|
+
/** Type IDs for in-game items.
|
|
126
|
+
* @category Constants
|
|
127
|
+
*/
|
|
128
|
+
export declare enum TYPEIDS {
|
|
129
|
+
LENS = 77518,
|
|
130
|
+
TRANSACTION_CHIP = 79193,
|
|
131
|
+
COMMON_ORE = 77800,
|
|
132
|
+
METAL_RICH_ORE = 77810,
|
|
133
|
+
SMART_STORAGE_UNIT = 77917,
|
|
134
|
+
PROTOCOL_DEPOT = 85249,
|
|
135
|
+
GATEKEEPER = 83907,
|
|
136
|
+
SALT = 83839,
|
|
137
|
+
NETWORK_NODE = 88092,
|
|
138
|
+
PORTABLE_REFINERY = 87161,
|
|
139
|
+
PORTABLE_PRINTER = 87162,
|
|
140
|
+
PORTABLE_STORAGE = 87566,
|
|
141
|
+
REFUGE = 87160
|
|
142
|
+
}
|
|
143
|
+
/** @category Constants */
|
|
144
|
+
export declare const EXCLUDED_TYPEIDS: TYPEIDS[];
|
|
145
|
+
/** Per-tenant config: world tier, EVE token package ID (Sui) and Datahub API host.
|
|
146
|
+
* @category Constants
|
|
147
|
+
*/
|
|
148
|
+
export type TenantConfig = (typeof TENANT_CONFIG)[TenantId];
|
|
149
|
+
/** Datahub API host per tenant (derived from TENANT_CONFIG).
|
|
150
|
+
* @category Constants
|
|
151
|
+
*/
|
|
152
|
+
export declare const DATAHUB_BY_TENANT: Record<TenantId, string>;
|
|
153
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../utils/constants.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,KAAK,QAAQ,EAAE,MAAM,iCAAiC,CAAA;AAC9E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAA;AAEjD,OAAO,EACL,cAAc,EACd,aAAa,GACd,MAAM,oCAAoC,CAAA;AAC3C,OAAO,EACL,cAAc,EACd,wBAAwB,EACxB,QAAQ,EACR,cAAc,EACd,KAAK,YAAY,GAClB,MAAM,iCAAiC,CAAA;AAUxC;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CACnC,GAAG,GAAE,MAAgC,GACpC,MAAM,CAGR;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,iCAAiC,CAC/C,GAAG,GAAE,MAAgC,GACpC,MAAM,CAKR;AAED;;;;GAIG;AACH,wBAAgB,+BAA+B,IAAI,MAAM,GAAG,SAAS,CAEpE;AAID,OAAO,EACL,qBAAqB,EACrB,iBAAiB,EACjB,YAAY,EACZ,YAAY,GACb,MAAM,kBAAkB,CAAA;AAMzB;;GAEG;AACH,eAAO,MAAM,uBAAuB,EAAE,iBAA6B,CAAA;AAEnE;;GAEG;AACH,eAAO,MAAM,oBAAoB,YAAI,SAAS,EAAE,QAAQ,EAAE,SAAS,CAAU,CAAA;AAE7E;;GAEG;AACH,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,iBAAiB,EAAE,MAAM,CAI/D,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,qDAAiC,CAAA;AAE/D;;;GAGG;AACH,eAAO,MAAM,8BAA8B,EAAE,MAAM,CAAC,iBAAiB,EAAE,MAAM,CAK1E,CAAA;AAEH;;GAEG;AACH,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,iBAAiB,EAAE,MAAM,CAI3D,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,QAAQ,CAAA;AASrC;;;;;;GAMG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,CAK3C;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,eAAe,GAAG,cAAc,GAAG,SAAS,CAAA;AAExD,mEAAmE;AACnE,eAAO,MAAM,wBAAwB,EAAE,eAAgC,CAAA;AAEvE;;GAEG;AACH,eAAO,MAAM,8BAA8B,QAAS,CAAA;AAEpD;;GAEG;AACH,eAAO,MAAM,+BAA+B,QAAS,CAAA;AAErD;;;;;GAKG;AACH,wBAAgB,+BAA+B,IAAI,MAAM,CAKxD;AAED;;;;;GAKG;AACH,MAAM,MAAM,kBAAkB,GAAG,KAAK,GAAG,YAAY,GAAG,MAAM,GAAG,QAAQ,CAAA;AAEzE;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,eAAe,EAC1B,MAAM,EAAE,kBAAkB,GACzB,MAAM,CAKR;AAED;;GAEG;AACH,eAAO,MAAM,YAAY;aACvB,SAAS,EAAE,oBAAoB;CACvB,CAAA;AAEV;;GAEG;AACH,oBAAY,OAAO;IACjB,IAAI,QAAQ;IACZ,gBAAgB,QAAQ;IACxB,UAAU,QAAQ;IAClB,cAAc,QAAQ;IACtB,kBAAkB,QAAQ;IAC1B,cAAc,QAAQ;IACtB,UAAU,QAAQ;IAClB,IAAI,QAAQ;IACZ,YAAY,QAAQ;IACpB,iBAAiB,QAAQ;IACzB,gBAAgB,QAAQ;IACxB,gBAAgB,QAAQ;IACxB,MAAM,QAAQ;CACf;AAED,0BAA0B;AAC1B,eAAO,MAAM,gBAAgB,WAK5B,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,QAAQ,CAAC,CAAA;AAE3D;;GAEG;AACH,eAAO,MAAM,iBAAiB,EAIzB,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA"}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// Environment Variable Helpers
|
|
3
|
+
// ============================================================================
|
|
4
|
+
import { TENANT_CONFIG } from '@evefrontier/wallet-core/tenant';
|
|
5
|
+
export { getEveCoinType, isEveCoinType, } from '@evefrontier/wallet-core/eve-token';
|
|
6
|
+
export { DEFAULT_TENANT, EVE_PACKAGE_ID_BY_TENANT, TenantId, WORLD_PACKAGES, } from '@evefrontier/wallet-core/tenant';
|
|
7
|
+
// ============================================================================
|
|
8
|
+
// Environment-Based Configuration
|
|
9
|
+
// ============================================================================
|
|
10
|
+
function isSuiGraphqlNetwork(value) {
|
|
11
|
+
return SUI_GRAPHQL_NETWORKS.includes(value);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Get the Sui GraphQL query endpoint URL for the given network.
|
|
15
|
+
*
|
|
16
|
+
* Unknown networks fall back to
|
|
17
|
+
* testnet to avoid returning undefined.
|
|
18
|
+
* @param env - Network identifier (testnet, devnet, mainnet). Defaults to testnet.
|
|
19
|
+
* @returns The GraphQL endpoint URL
|
|
20
|
+
* @category Utilities - Config
|
|
21
|
+
*/
|
|
22
|
+
export function getSuiGraphqlEndpoint(env = DEFAULT_GRAPHQL_NETWORK) {
|
|
23
|
+
const network = isSuiGraphqlNetwork(env) ? env : DEFAULT_GRAPHQL_NETWORK;
|
|
24
|
+
return GRAPHQL_ENDPOINTS[network];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Get the Sui GraphQL subscription endpoint URL for the given network: the
|
|
28
|
+
* second URL beside {@link getSuiGraphqlEndpoint}. Subscriptions are served
|
|
29
|
+
* over SSE at `/graphql/subscriptions` on the same host; the query URL rejects
|
|
30
|
+
* them. VITE_SUI_GRAPHQL_SUBSCRIPTION_URL overrides it for every network, as
|
|
31
|
+
* the counterpart of an overridden query URL.
|
|
32
|
+
*
|
|
33
|
+
* @param env - Network identifier (testnet, devnet, mainnet). Defaults to testnet.
|
|
34
|
+
* @returns The GraphQL subscription endpoint URL
|
|
35
|
+
* @category Utilities - Config
|
|
36
|
+
*/
|
|
37
|
+
export function getSuiGraphqlSubscriptionEndpoint(env = DEFAULT_GRAPHQL_NETWORK) {
|
|
38
|
+
const override = import.meta.env.VITE_SUI_GRAPHQL_SUBSCRIPTION_URL;
|
|
39
|
+
if (override)
|
|
40
|
+
return override;
|
|
41
|
+
const network = isSuiGraphqlNetwork(env) ? env : DEFAULT_GRAPHQL_NETWORK;
|
|
42
|
+
return GRAPHQL_SUBSCRIPTION_ENDPOINTS[network];
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Optional bearer token for the GraphQL subscription, from
|
|
46
|
+
* VITE_GRAPHQL_SUBSCRIPTION_AUTH_TOKEN. The public endpoints need none.
|
|
47
|
+
* @category Utilities - Config
|
|
48
|
+
*/
|
|
49
|
+
export function getGraphqlSubscriptionAuthToken() {
|
|
50
|
+
return import.meta.env.VITE_GRAPHQL_SUBSCRIPTION_AUTH_TOKEN || undefined;
|
|
51
|
+
}
|
|
52
|
+
// World type/package resolution lives in `mvr/worldTypes.ts`. Re-exported here
|
|
53
|
+
// so existing `utils/constants` importers keep working.
|
|
54
|
+
export { getObjectRegistryType, getWorldPackageId, getWorldTier, getWorldType, } from './mvr/worldTypes.js';
|
|
55
|
+
// ============================================================================
|
|
56
|
+
// Constants
|
|
57
|
+
// ============================================================================
|
|
58
|
+
/** Default Sui network for GraphQL endpoint selection.
|
|
59
|
+
* @category Constants
|
|
60
|
+
*/
|
|
61
|
+
export const DEFAULT_GRAPHQL_NETWORK = 'testnet';
|
|
62
|
+
/** Allowed Sui network identifiers for GraphQL endpoint selection.
|
|
63
|
+
* @category Constants
|
|
64
|
+
*/
|
|
65
|
+
export const SUI_GRAPHQL_NETWORKS = ['testnet', 'devnet', 'mainnet'];
|
|
66
|
+
/** Sui GraphQL query endpoints per network.
|
|
67
|
+
* @category Constants
|
|
68
|
+
*/
|
|
69
|
+
export const GRAPHQL_ENDPOINTS = {
|
|
70
|
+
testnet: 'https://graphql.testnet.sui.io/graphql',
|
|
71
|
+
devnet: 'https://graphql.devnet.sui.io/graphql',
|
|
72
|
+
mainnet: 'https://graphql.mainnet.sui.io/graphql',
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Client identifier sent as the `X-Client-ID` header on GraphQL requests.
|
|
76
|
+
* Random per client, generated once and
|
|
77
|
+
* cached for the module lifetime — used for session affinity during pagination.
|
|
78
|
+
* @category Constants
|
|
79
|
+
*/
|
|
80
|
+
export const GRAPHQL_CLIENT_ID = globalThis.crypto.randomUUID();
|
|
81
|
+
/** Sui GraphQL subscription endpoints per network: SSE, on the same host as
|
|
82
|
+
* the query endpoint. See {@link getSuiGraphqlSubscriptionEndpoint}.
|
|
83
|
+
* @category Constants
|
|
84
|
+
*/
|
|
85
|
+
export const GRAPHQL_SUBSCRIPTION_ENDPOINTS = {
|
|
86
|
+
testnet: 'https://graphql.testnet.sui.io/graphql/subscriptions',
|
|
87
|
+
devnet: 'https://graphql.devnet.sui.io/graphql/subscriptions',
|
|
88
|
+
mainnet: 'https://graphql.mainnet.sui.io/graphql/subscriptions',
|
|
89
|
+
};
|
|
90
|
+
/** gRPC base URLs for each Sui network.
|
|
91
|
+
* @category Constants
|
|
92
|
+
*/
|
|
93
|
+
export const SUI_GRPC_URLS = {
|
|
94
|
+
testnet: 'https://fullnode.testnet.sui.io:443',
|
|
95
|
+
devnet: 'https://fullnode.devnet.sui.io:443',
|
|
96
|
+
mainnet: 'https://fullnode.mainnet.sui.io:443',
|
|
97
|
+
};
|
|
98
|
+
/** Default polling interval in milliseconds.
|
|
99
|
+
*
|
|
100
|
+
* The update source with the `polling` transport, and the fallback when the
|
|
101
|
+
* subscription fails. Each tick is a cheap version check until the object
|
|
102
|
+
* changes. Override with VITE_POLLING_INTERVAL; set it to 0 to disable
|
|
103
|
+
* polling entirely.
|
|
104
|
+
* @category Constants
|
|
105
|
+
*/
|
|
106
|
+
export const POLLING_INTERVAL = 15000;
|
|
107
|
+
/** Read a non-negative millisecond interval from an env value, or `fallback`. */
|
|
108
|
+
function intervalFromEnv(raw, fallback) {
|
|
109
|
+
if (raw === undefined || raw === '')
|
|
110
|
+
return fallback;
|
|
111
|
+
const parsed = Number(raw);
|
|
112
|
+
return Number.isFinite(parsed) && parsed >= 0 ? parsed : fallback;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Resolve the polling interval in milliseconds.
|
|
116
|
+
* Reads VITE_POLLING_INTERVAL when set (0 disables the backstop), otherwise
|
|
117
|
+
* falls back to POLLING_INTERVAL.
|
|
118
|
+
* @returns Interval in ms; 0 means the periodic poll is disabled.
|
|
119
|
+
* @category Utilities - Config
|
|
120
|
+
*/
|
|
121
|
+
export function getPollingInterval() {
|
|
122
|
+
return intervalFromEnv(import.meta.env.VITE_POLLING_INTERVAL, POLLING_INTERVAL);
|
|
123
|
+
}
|
|
124
|
+
/** The update transport when none is given. @category Constants */
|
|
125
|
+
export const DEFAULT_UPDATE_TRANSPORT = 'subscription';
|
|
126
|
+
/** Default backstop polling interval while the subscription is up, in ms.
|
|
127
|
+
* @category Constants
|
|
128
|
+
*/
|
|
129
|
+
export const SUBSCRIPTION_BACKSTOP_INTERVAL = 60000;
|
|
130
|
+
/** How long the subscription may take to connect before it counts as failed, in ms.
|
|
131
|
+
* @category Constants
|
|
132
|
+
*/
|
|
133
|
+
export const SUBSCRIPTION_CONNECT_TIMEOUT_MS = 10000;
|
|
134
|
+
/**
|
|
135
|
+
* Resolve the backstop polling interval in ms while the subscription is up.
|
|
136
|
+
* Reads VITE_SUBSCRIPTION_POLLING_INTERVAL when set (0 disables it), otherwise
|
|
137
|
+
* SUBSCRIPTION_BACKSTOP_INTERVAL.
|
|
138
|
+
* @category Utilities - Config
|
|
139
|
+
*/
|
|
140
|
+
export function getSubscriptionBackstopInterval() {
|
|
141
|
+
return intervalFromEnv(import.meta.env.VITE_SUBSCRIPTION_POLLING_INTERVAL, SUBSCRIPTION_BACKSTOP_INTERVAL);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* The polling interval to run: the slow backstop while the subscription is
|
|
145
|
+
* connecting or live, the normal interval with `polling` or once the
|
|
146
|
+
* subscription has failed.
|
|
147
|
+
* @category Utilities - Config
|
|
148
|
+
*/
|
|
149
|
+
export function backstopInterval(transport, status) {
|
|
150
|
+
return transport === 'subscription' &&
|
|
151
|
+
(status === 'connecting' || status === 'live')
|
|
152
|
+
? getSubscriptionBackstopInterval()
|
|
153
|
+
: getPollingInterval();
|
|
154
|
+
}
|
|
155
|
+
/** Local storage keys.
|
|
156
|
+
* @category Constants
|
|
157
|
+
*/
|
|
158
|
+
export const STORAGE_KEYS = {
|
|
159
|
+
CONNECTED: 'eve-dapp-connected',
|
|
160
|
+
};
|
|
161
|
+
/** Type IDs for in-game items.
|
|
162
|
+
* @category Constants
|
|
163
|
+
*/
|
|
164
|
+
export var TYPEIDS;
|
|
165
|
+
(function (TYPEIDS) {
|
|
166
|
+
TYPEIDS[TYPEIDS["LENS"] = 77518] = "LENS";
|
|
167
|
+
TYPEIDS[TYPEIDS["TRANSACTION_CHIP"] = 79193] = "TRANSACTION_CHIP";
|
|
168
|
+
TYPEIDS[TYPEIDS["COMMON_ORE"] = 77800] = "COMMON_ORE";
|
|
169
|
+
TYPEIDS[TYPEIDS["METAL_RICH_ORE"] = 77810] = "METAL_RICH_ORE";
|
|
170
|
+
TYPEIDS[TYPEIDS["SMART_STORAGE_UNIT"] = 77917] = "SMART_STORAGE_UNIT";
|
|
171
|
+
TYPEIDS[TYPEIDS["PROTOCOL_DEPOT"] = 85249] = "PROTOCOL_DEPOT";
|
|
172
|
+
TYPEIDS[TYPEIDS["GATEKEEPER"] = 83907] = "GATEKEEPER";
|
|
173
|
+
TYPEIDS[TYPEIDS["SALT"] = 83839] = "SALT";
|
|
174
|
+
TYPEIDS[TYPEIDS["NETWORK_NODE"] = 88092] = "NETWORK_NODE";
|
|
175
|
+
TYPEIDS[TYPEIDS["PORTABLE_REFINERY"] = 87161] = "PORTABLE_REFINERY";
|
|
176
|
+
TYPEIDS[TYPEIDS["PORTABLE_PRINTER"] = 87162] = "PORTABLE_PRINTER";
|
|
177
|
+
TYPEIDS[TYPEIDS["PORTABLE_STORAGE"] = 87566] = "PORTABLE_STORAGE";
|
|
178
|
+
TYPEIDS[TYPEIDS["REFUGE"] = 87160] = "REFUGE";
|
|
179
|
+
})(TYPEIDS || (TYPEIDS = {}));
|
|
180
|
+
/** @category Constants */
|
|
181
|
+
export const EXCLUDED_TYPEIDS = [
|
|
182
|
+
TYPEIDS.PORTABLE_REFINERY,
|
|
183
|
+
TYPEIDS.PORTABLE_PRINTER,
|
|
184
|
+
TYPEIDS.PORTABLE_STORAGE,
|
|
185
|
+
TYPEIDS.REFUGE,
|
|
186
|
+
];
|
|
187
|
+
/** Datahub API host per tenant (derived from TENANT_CONFIG).
|
|
188
|
+
* @category Constants
|
|
189
|
+
*/
|
|
190
|
+
export const DATAHUB_BY_TENANT = Object.fromEntries(Object.entries(TENANT_CONFIG).map(([id, config]) => [id, config.datahubHost]));
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type DatahubGameInfo } from '../types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Fetch game type information from the EVE Frontier Datahub API.
|
|
4
|
+
*
|
|
5
|
+
* Retrieves metadata about a game type by its ID, including display name,
|
|
6
|
+
* description, icon URL, and physical properties. This data is used to
|
|
7
|
+
* enrich on-chain objects with human-readable information.
|
|
8
|
+
*
|
|
9
|
+
* Resolves tenant from the window.location.search param.
|
|
10
|
+
*
|
|
11
|
+
* @category Utilities - Config
|
|
12
|
+
* @param typeId - The numeric type ID (from on-chain type_id field)
|
|
13
|
+
* @returns Promise resolving to the type's game info
|
|
14
|
+
*
|
|
15
|
+
* @example Fetch assembly type info
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const typeInfo = await getDatahubGameInfo(83463);
|
|
18
|
+
* console.log(typeInfo.name); // "Smart Storage Unit"
|
|
19
|
+
* console.log(typeInfo.iconUrl); // URL to icon
|
|
20
|
+
* console.log(typeInfo.description); // Description text
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @example Enrich inventory items
|
|
24
|
+
* ```typescript
|
|
25
|
+
* const inventoryItem = { type_id: 12345, quantity: 100 };
|
|
26
|
+
* const info = await getDatahubGameInfo(inventoryItem.type_id);
|
|
27
|
+
* console.log(`${info.name} x${inventoryItem.quantity}`);
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare function getDatahubGameInfo(typeId: number): Promise<DatahubGameInfo>;
|
|
31
|
+
/**
|
|
32
|
+
* Type id → display name from Datahub lookups, skipping any that failed or
|
|
33
|
+
* have no name (Datahub answers unknown ids with an error object).
|
|
34
|
+
*
|
|
35
|
+
* @category Utilities - Datahub
|
|
36
|
+
* @param typeIds - Type ids, in the same order as `infos`
|
|
37
|
+
* @param infos - Datahub answers, or undefined while one is loading
|
|
38
|
+
*/
|
|
39
|
+
export declare function typeNamesFrom(typeIds: string[], infos: Array<Partial<DatahubGameInfo> | undefined>): Record<string, string>;
|
|
40
|
+
//# sourceMappingURL=datahub.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"datahub.d.ts","sourceRoot":"","sources":["../../utils/datahub.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,eAAe,EAAe,MAAM,UAAU,CAAA;AA0B5D;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,eAAe,CAAC,CAQ1B;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,EAAE,EACjB,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,eAAe,CAAC,GAAG,SAAS,CAAC,GACjD,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAOxB"}
|
|
@@ -1,29 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { QueryParams } from '../types/index.js';
|
|
2
|
+
import { DATAHUB_BY_TENANT, DEFAULT_TENANT } from './constants.js';
|
|
4
3
|
/**
|
|
5
4
|
* Resolves tenant from a URL search string (e.g. window.location.search).
|
|
6
5
|
* Trims the param value and falls back to DEFAULT_TENANT when missing or blank.
|
|
7
6
|
* @internal
|
|
8
7
|
*/
|
|
9
|
-
export function resolveTenantFromSearch(search
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return tenant;
|
|
8
|
+
export function resolveTenantFromSearch(search) {
|
|
9
|
+
const tenant = new URLSearchParams(search).get(QueryParams.TENANT)?.trim() ||
|
|
10
|
+
DEFAULT_TENANT;
|
|
11
|
+
return tenant;
|
|
14
12
|
}
|
|
15
|
-
|
|
16
13
|
/**
|
|
17
14
|
* Resolves the datahub host for a tenant key. Falls back to DEFAULT_TENANT host for unknown tenants.
|
|
18
15
|
* @internal
|
|
19
16
|
*/
|
|
20
|
-
export function resolveDatahubHost(tenant
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
DATAHUB_BY_TENANT[DEFAULT_TENANT]
|
|
24
|
-
);
|
|
17
|
+
export function resolveDatahubHost(tenant) {
|
|
18
|
+
return (DATAHUB_BY_TENANT[tenant] ??
|
|
19
|
+
DATAHUB_BY_TENANT[DEFAULT_TENANT]);
|
|
25
20
|
}
|
|
26
|
-
|
|
27
21
|
/**
|
|
28
22
|
* Fetch game type information from the EVE Frontier Datahub API.
|
|
29
23
|
*
|
|
@@ -52,14 +46,27 @@ export function resolveDatahubHost(tenant: string): string {
|
|
|
52
46
|
* console.log(`${info.name} x${inventoryItem.quantity}`);
|
|
53
47
|
* ```
|
|
54
48
|
*/
|
|
55
|
-
export async function getDatahubGameInfo(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
49
|
+
export async function getDatahubGameInfo(typeId) {
|
|
50
|
+
const tenant = resolveTenantFromSearch(window.location.search);
|
|
51
|
+
const host = resolveDatahubHost(tenant);
|
|
52
|
+
const response = await fetch(`https://${host}/v2/types/${typeId}`);
|
|
53
|
+
const data = await response.json();
|
|
54
|
+
return data;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Type id → display name from Datahub lookups, skipping any that failed or
|
|
58
|
+
* have no name (Datahub answers unknown ids with an error object).
|
|
59
|
+
*
|
|
60
|
+
* @category Utilities - Datahub
|
|
61
|
+
* @param typeIds - Type ids, in the same order as `infos`
|
|
62
|
+
* @param infos - Datahub answers, or undefined while one is loading
|
|
63
|
+
*/
|
|
64
|
+
export function typeNamesFrom(typeIds, infos) {
|
|
65
|
+
const names = {};
|
|
66
|
+
typeIds.forEach((typeId, i) => {
|
|
67
|
+
const name = infos[i]?.name;
|
|
68
|
+
if (name)
|
|
69
|
+
names[typeId] = name;
|
|
70
|
+
});
|
|
71
|
+
return names;
|
|
65
72
|
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { ContentsTypeAndJson, DynamicFieldTableEntryNode } from '../graphql/types.js';
|
|
2
|
+
import type { EntityData, EntityOwner } from '../types/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* An entity as fetched: contents plus every dynamic field, with nested
|
|
5
|
+
* tables (layout sections, inventory items) fully paged in.
|
|
6
|
+
*
|
|
7
|
+
* @category Utilities - Entity
|
|
8
|
+
*/
|
|
9
|
+
export interface RawEntity {
|
|
10
|
+
version: number;
|
|
11
|
+
contents: ContentsTypeAndJson;
|
|
12
|
+
fields: Array<{
|
|
13
|
+
name: ContentsTypeAndJson;
|
|
14
|
+
value: ContentsTypeAndJson;
|
|
15
|
+
table: DynamicFieldTableEntryNode[] | null;
|
|
16
|
+
}>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Fetches an object as a world entity, paging through all of its dynamic
|
|
20
|
+
* fields and any layout section or inventory item tables.
|
|
21
|
+
*
|
|
22
|
+
* Pages after the first are read at the latest version rather than pinned to
|
|
23
|
+
* `version`, so an entity that changes mid-fetch can mix fields from two
|
|
24
|
+
* versions. Polling callers converge on the next fetch, as the newer version
|
|
25
|
+
* no longer matches.
|
|
26
|
+
*
|
|
27
|
+
* @category Utilities - Entity
|
|
28
|
+
* @param objectId - The Sui object ID
|
|
29
|
+
* @returns The raw entity, or null if there is no Move object at that address
|
|
30
|
+
* @throws If a GraphQL response has errors, or a nested table cannot be paged
|
|
31
|
+
*/
|
|
32
|
+
export declare function fetchEntity(objectId: string): Promise<RawEntity | null>;
|
|
33
|
+
/** True when the raw object is a `core::entity::Entity`. @category Utilities - Entity */
|
|
34
|
+
export declare function isEntity(raw: RawEntity): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Parses a fetched entity into typed components. Components without a
|
|
37
|
+
* parser still appear in `components`.
|
|
38
|
+
*
|
|
39
|
+
* @category Utilities - Entity
|
|
40
|
+
* @param raw - The entity from {@link fetchEntity}
|
|
41
|
+
* @returns The parsed entity
|
|
42
|
+
*/
|
|
43
|
+
export declare function parseEntity(raw: RawEntity): EntityData;
|
|
44
|
+
/**
|
|
45
|
+
* Resolves who controls an entity from the holder of its AccessCap. A cap
|
|
46
|
+
* parked on a Character is held by the Character's object id; its wallet is
|
|
47
|
+
* the Character's `Identity.owner`. See {@link EntityOwner} `kind` for the
|
|
48
|
+
* cases.
|
|
49
|
+
*
|
|
50
|
+
* @category Utilities - Entity
|
|
51
|
+
* @param accessCapId - The entity's `accessCapId`
|
|
52
|
+
* @param previous - The last owner resolved for this cap; returned as-is when
|
|
53
|
+
* the holder hasn't changed, skipping the Character fetch
|
|
54
|
+
* @returns The holder, its wallet, and the Character entity when there is one
|
|
55
|
+
* @throws If a GraphQL response has errors
|
|
56
|
+
*/
|
|
57
|
+
export declare function fetchEntityOwner(accessCapId: string, previous?: EntityOwner | null): Promise<EntityOwner>;
|
|
58
|
+
//# sourceMappingURL=entity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entity.d.ts","sourceRoot":"","sources":["../../utils/entity.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,mBAAmB,EACnB,0BAA0B,EAG3B,MAAM,kBAAkB,CAAA;AACzB,OAAO,KAAK,EAGV,UAAU,EAMV,WAAW,EAGZ,MAAM,UAAU,CAAA;AAIjB;;;;;GAKG;AACH,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,mBAAmB,CAAA;IAC7B,MAAM,EAAE,KAAK,CAAC;QACZ,IAAI,EAAE,mBAAmB,CAAA;QACzB,KAAK,EAAE,mBAAmB,CAAA;QAC1B,KAAK,EAAE,0BAA0B,EAAE,GAAG,IAAI,CAAA;KAC3C,CAAC,CAAA;CACH;AA2HD;;;;;;;;;;;;;GAaG;AACH,wBAAsB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,CAqC7E;AAED,yFAAyF;AACzF,wBAAgB,QAAQ,CAAC,GAAG,EAAE,SAAS,GAAG,OAAO,CAEhD;AA6ND;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,SAAS,GAAG,UAAU,CA0FtD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,gBAAgB,CACpC,WAAW,EAAE,MAAM,EACnB,QAAQ,CAAC,EAAE,WAAW,GAAG,IAAI,GAC5B,OAAO,CAAC,WAAW,CAAC,CAgCtB"}
|