@evefrontier/dapp-kit 0.1.8 → 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.
Files changed (211) hide show
  1. package/README.md +28 -25
  2. package/dist/config/dapp-kit.d.ts +4 -0
  3. package/dist/config/dapp-kit.d.ts.map +1 -0
  4. package/dist/config/dapp-kit.js +14 -0
  5. package/dist/config/index.d.ts +2 -0
  6. package/dist/config/index.d.ts.map +1 -0
  7. package/dist/config/index.js +1 -0
  8. package/dist/graphql/client.d.ts +277 -0
  9. package/dist/graphql/client.d.ts.map +1 -0
  10. package/dist/graphql/client.js +346 -0
  11. package/dist/graphql/index.d.ts +4 -0
  12. package/dist/graphql/index.d.ts.map +1 -0
  13. package/dist/graphql/index.js +16 -0
  14. package/dist/graphql/queries.d.ts +103 -0
  15. package/dist/graphql/queries.d.ts.map +1 -0
  16. package/{graphql/queries.ts → dist/graphql/queries.js} +113 -223
  17. package/dist/graphql/types.d.ts +396 -0
  18. package/dist/graphql/types.d.ts.map +1 -0
  19. package/dist/graphql/types.js +4 -0
  20. package/dist/hooks/index.d.ts +10 -0
  21. package/dist/hooks/index.d.ts.map +1 -0
  22. package/dist/hooks/index.js +8 -0
  23. package/dist/hooks/useCharacterDirectory.d.ts +16 -0
  24. package/dist/hooks/useCharacterDirectory.d.ts.map +1 -0
  25. package/dist/hooks/useCharacterDirectory.js +23 -0
  26. package/dist/hooks/useCharacterSearch.d.ts +24 -0
  27. package/dist/hooks/useCharacterSearch.d.ts.map +1 -0
  28. package/dist/hooks/useCharacterSearch.js +24 -0
  29. package/dist/hooks/useConnection.d.ts +51 -0
  30. package/dist/hooks/useConnection.d.ts.map +1 -0
  31. package/{hooks/useConnection.ts → dist/hooks/useConnection.js} +8 -10
  32. package/dist/hooks/useEntityRole.d.ts +26 -0
  33. package/dist/hooks/useEntityRole.d.ts.map +1 -0
  34. package/dist/hooks/useEntityRole.js +91 -0
  35. package/dist/hooks/useNotification.d.ts +72 -0
  36. package/dist/hooks/useNotification.d.ts.map +1 -0
  37. package/{hooks/useNotification.ts → dist/hooks/useNotification.js} +8 -12
  38. package/dist/hooks/useSmartObject.d.ts +44 -0
  39. package/dist/hooks/useSmartObject.d.ts.map +1 -0
  40. package/dist/hooks/useSmartObject.js +50 -0
  41. package/dist/hooks/useSponsoredTransaction.d.ts +147 -0
  42. package/dist/hooks/useSponsoredTransaction.d.ts.map +1 -0
  43. package/dist/hooks/useSponsoredTransaction.js +240 -0
  44. package/dist/hooks/useTypeNames.d.ts +11 -0
  45. package/dist/hooks/useTypeNames.d.ts.map +1 -0
  46. package/dist/hooks/useTypeNames.js +24 -0
  47. package/dist/index.d.ts +11 -0
  48. package/dist/index.d.ts.map +1 -0
  49. package/dist/index.js +29 -0
  50. package/dist/providers/EveFrontierProvider.d.ts +23 -0
  51. package/dist/providers/EveFrontierProvider.d.ts.map +1 -0
  52. package/dist/providers/EveFrontierProvider.js +23 -0
  53. package/dist/providers/NotificationProvider.d.ts +14 -0
  54. package/dist/providers/NotificationProvider.d.ts.map +1 -0
  55. package/dist/providers/NotificationProvider.js +66 -0
  56. package/dist/providers/SmartObjectProvider.d.ts +31 -0
  57. package/dist/providers/SmartObjectProvider.d.ts.map +1 -0
  58. package/dist/providers/SmartObjectProvider.js +80 -0
  59. package/dist/providers/VaultProvider.d.ts +10 -0
  60. package/dist/providers/VaultProvider.d.ts.map +1 -0
  61. package/dist/providers/VaultProvider.js +79 -0
  62. package/dist/providers/index.d.ts +5 -0
  63. package/dist/providers/index.d.ts.map +1 -0
  64. package/dist/providers/index.js +4 -0
  65. package/dist/providers/smartObject/useEntityData.d.ts +29 -0
  66. package/dist/providers/smartObject/useEntityData.d.ts.map +1 -0
  67. package/dist/providers/smartObject/useEntityData.js +135 -0
  68. package/dist/providers/smartObject/useEntitySubscription.d.ts +14 -0
  69. package/dist/providers/smartObject/useEntitySubscription.d.ts.map +1 -0
  70. package/dist/providers/smartObject/useEntitySubscription.js +58 -0
  71. package/dist/providers/smartObject/useObjectSelection.d.ts +11 -0
  72. package/dist/providers/smartObject/useObjectSelection.d.ts.map +1 -0
  73. package/dist/providers/smartObject/useObjectSelection.js +27 -0
  74. package/dist/providers/smartObject/usePollingBackstop.d.ts +18 -0
  75. package/dist/providers/smartObject/usePollingBackstop.d.ts.map +1 -0
  76. package/dist/providers/smartObject/usePollingBackstop.js +38 -0
  77. package/dist/types/character.d.ts +21 -0
  78. package/dist/types/character.d.ts.map +1 -0
  79. package/dist/types/character.js +1 -0
  80. package/dist/types/contexts.d.ts +61 -0
  81. package/dist/types/contexts.d.ts.map +1 -0
  82. package/dist/types/contexts.js +6 -0
  83. package/dist/types/entity.d.ts +245 -0
  84. package/dist/types/entity.d.ts.map +1 -0
  85. package/dist/types/entity.js +6 -0
  86. package/dist/types/index.d.ts +6 -0
  87. package/dist/types/index.d.ts.map +1 -0
  88. package/dist/types/index.js +5 -0
  89. package/dist/types/sponsoredTransaction.d.ts +26 -0
  90. package/dist/types/sponsoredTransaction.d.ts.map +1 -0
  91. package/dist/types/sponsoredTransaction.js +10 -0
  92. package/dist/types/types.d.ts +110 -0
  93. package/dist/types/types.d.ts.map +1 -0
  94. package/dist/types/types.js +41 -0
  95. package/dist/types/worldApiReturnTypes.d.ts +68 -0
  96. package/dist/types/worldApiReturnTypes.d.ts.map +1 -0
  97. package/dist/types/worldApiReturnTypes.js +1 -0
  98. package/{utils/burnRate.ts → dist/utils/burnRate.d.ts} +4 -29
  99. package/dist/utils/burnRate.d.ts.map +1 -0
  100. package/dist/utils/burnRate.js +25 -0
  101. package/dist/utils/characters.d.ts +26 -0
  102. package/dist/utils/characters.d.ts.map +1 -0
  103. package/dist/utils/characters.js +84 -0
  104. package/dist/utils/constants.d.ts +153 -0
  105. package/dist/utils/constants.d.ts.map +1 -0
  106. package/dist/utils/constants.js +190 -0
  107. package/dist/utils/datahub.d.ts +40 -0
  108. package/dist/utils/datahub.d.ts.map +1 -0
  109. package/{utils/datahub.ts → dist/utils/datahub.js} +32 -25
  110. package/dist/utils/entity.d.ts +58 -0
  111. package/dist/utils/entity.d.ts.map +1 -0
  112. package/dist/utils/entity.js +386 -0
  113. package/dist/utils/errors.d.ts +18 -0
  114. package/dist/utils/errors.d.ts.map +1 -0
  115. package/dist/utils/errors.js +128 -0
  116. package/dist/utils/events/entityEvents.d.ts +44 -0
  117. package/dist/utils/events/entityEvents.d.ts.map +1 -0
  118. package/dist/utils/events/entityEvents.js +95 -0
  119. package/dist/utils/events/entitySubscription.d.ts +30 -0
  120. package/dist/utils/events/entitySubscription.d.ts.map +1 -0
  121. package/dist/utils/events/entitySubscription.js +84 -0
  122. package/dist/utils/events/graphqlEventStream.d.ts +90 -0
  123. package/dist/utils/events/graphqlEventStream.d.ts.map +1 -0
  124. package/dist/utils/events/graphqlEventStream.js +198 -0
  125. package/dist/utils/events/refetchScheduler.d.ts +30 -0
  126. package/dist/utils/events/refetchScheduler.d.ts.map +1 -0
  127. package/dist/utils/events/refetchScheduler.js +57 -0
  128. package/dist/utils/events/sseClient.d.ts +42 -0
  129. package/dist/utils/events/sseClient.d.ts.map +1 -0
  130. package/dist/utils/events/sseClient.js +97 -0
  131. package/dist/utils/fuel.d.ts +231 -0
  132. package/dist/utils/fuel.d.ts.map +1 -0
  133. package/dist/utils/fuel.js +652 -0
  134. package/dist/utils/grid.d.ts +115 -0
  135. package/dist/utils/grid.d.ts.map +1 -0
  136. package/dist/utils/grid.js +115 -0
  137. package/dist/utils/index.d.ts +15 -0
  138. package/dist/utils/index.d.ts.map +1 -0
  139. package/dist/utils/index.js +22 -0
  140. package/dist/utils/inventory.d.ts +3 -0
  141. package/dist/utils/inventory.d.ts.map +1 -0
  142. package/dist/utils/inventory.js +12 -0
  143. package/dist/utils/logger.d.ts +25 -0
  144. package/dist/utils/logger.d.ts.map +1 -0
  145. package/dist/utils/logger.js +228 -0
  146. package/dist/utils/mapping.d.ts +30 -0
  147. package/dist/utils/mapping.d.ts.map +1 -0
  148. package/dist/utils/mapping.js +73 -0
  149. package/dist/utils/mvr/worldTypes.d.ts +35 -0
  150. package/dist/utils/mvr/worldTypes.d.ts.map +1 -0
  151. package/dist/utils/mvr/worldTypes.js +54 -0
  152. package/dist/utils/role.d.ts +116 -0
  153. package/dist/utils/role.d.ts.map +1 -0
  154. package/dist/utils/role.js +120 -0
  155. package/dist/utils/smartObject.d.ts +24 -0
  156. package/dist/utils/smartObject.d.ts.map +1 -0
  157. package/dist/utils/smartObject.js +24 -0
  158. package/dist/utils/utils.d.ts +133 -0
  159. package/dist/utils/utils.d.ts.map +1 -0
  160. package/dist/utils/utils.js +213 -0
  161. package/dist/wallet/features.d.ts +28 -0
  162. package/dist/wallet/features.d.ts.map +1 -0
  163. package/dist/wallet/features.js +22 -0
  164. package/dist/wallet/index.d.ts +9 -0
  165. package/dist/wallet/index.d.ts.map +1 -0
  166. package/dist/wallet/index.js +9 -0
  167. package/dist/wallet/utils.d.ts +71 -0
  168. package/dist/wallet/utils.d.ts.map +1 -0
  169. package/dist/wallet/utils.js +79 -0
  170. package/package.json +69 -35
  171. package/config/dapp-kit.ts +0 -20
  172. package/config/index.ts +0 -1
  173. package/graphql/client.ts +0 -578
  174. package/graphql/index.ts +0 -39
  175. package/graphql/types.ts +0 -468
  176. package/hooks/index.ts +0 -15
  177. package/hooks/useSmartObject.ts +0 -66
  178. package/hooks/useSponsoredTransaction.ts +0 -442
  179. package/index.ts +0 -88
  180. package/providers/EveFrontierProvider.tsx +0 -41
  181. package/providers/NotificationProvider.tsx +0 -108
  182. package/providers/SmartObjectProvider.tsx +0 -296
  183. package/providers/VaultProvider.tsx +0 -108
  184. package/providers/index.ts +0 -10
  185. package/types/contexts.ts +0 -67
  186. package/types/global.d.ts +0 -7
  187. package/types/index.ts +0 -4
  188. package/types/sponsoredTransaction.ts +0 -70
  189. package/types/types.ts +0 -198
  190. package/types/worldApiReturnTypes.ts +0 -144
  191. package/utils/__tests__/burnRate.test.ts +0 -121
  192. package/utils/__tests__/character.test.ts +0 -112
  193. package/utils/__tests__/characterOwnedObjects.test.ts +0 -225
  194. package/utils/__tests__/config.test.ts +0 -424
  195. package/utils/__tests__/datahub.test.ts +0 -58
  196. package/utils/__tests__/logger.test.ts +0 -145
  197. package/utils/__tests__/mapping.test.ts +0 -439
  198. package/utils/__tests__/utils.test.ts +0 -299
  199. package/utils/character.ts +0 -46
  200. package/utils/characterOwnedObjects.ts +0 -53
  201. package/utils/config.ts +0 -151
  202. package/utils/constants.ts +0 -254
  203. package/utils/errors.ts +0 -171
  204. package/utils/index.ts +0 -47
  205. package/utils/logger.ts +0 -300
  206. package/utils/mapping.ts +0 -118
  207. package/utils/transforms.ts +0 -263
  208. package/utils/utils.ts +0 -270
  209. package/wallet/features.ts +0 -136
  210. package/wallet/index.ts +0 -26
  211. package/wallet/utils.ts +0 -117
package/utils/logger.ts DELETED
@@ -1,300 +0,0 @@
1
- import type {
2
- CreateLoggerOptions,
3
- GlobalProcess,
4
- GlobalWithProcess,
5
- Logger,
6
- LoggerFn,
7
- LogLevel,
8
- StackFrame,
9
- } from "../types";
10
-
11
- const LOG_LEVELS: LogLevel[] = ["silent", "error", "warn", "info", "debug"];
12
- const LOGGER_SOURCE_HINTS = ["logger.ts", "logger.js", "logger.mjs"];
13
-
14
- const isLogLevel = (value?: string | null): value is LogLevel => {
15
- if (!value) {
16
- return false;
17
- }
18
-
19
- return LOG_LEVELS.includes(value.toLowerCase() as LogLevel);
20
- };
21
-
22
- const getProcessObject = (): GlobalProcess | undefined => {
23
- try {
24
- return (globalThis as GlobalWithProcess).process;
25
- } catch {
26
- return undefined;
27
- }
28
- };
29
-
30
- /** Inputs for {@link resolveLogLevelFromEnv} (mirrors Vite `import.meta.env`). */
31
- export type ResolveLogLevelFromEnvOptions = {
32
- /** `import.meta.env.VITE_LOG_LEVEL` — when set to a valid level, overrides mode. */
33
- viteLogLevel?: string | undefined;
34
- /** `import.meta.env.MODE` — `production` → `error`, `test` → `warn`, else `debug`. */
35
- viteMode?: string | undefined;
36
- };
37
-
38
- /**
39
- * Resolves log level from `VITE_LOG_LEVEL` (if a valid level) and Vite `MODE`.
40
- * Exported for unit tests; {@link createLogger} uses the snapshot at module load.
41
- */
42
- export function resolveLogLevelFromEnv(
43
- options: ResolveLogLevelFromEnvOptions,
44
- ): LogLevel {
45
- const { viteLogLevel, viteMode } = options;
46
-
47
- if (isLogLevel(viteLogLevel)) {
48
- return viteLogLevel.toLowerCase() as LogLevel;
49
- }
50
-
51
- if (viteMode === "production") {
52
- return "error";
53
- }
54
-
55
- if (viteMode === "test") {
56
- return "warn";
57
- }
58
-
59
- return "debug";
60
- }
61
-
62
- const resolveEnvLogLevel = (): LogLevel => {
63
- return resolveLogLevelFromEnv({
64
- viteLogLevel: import.meta.env.VITE_LOG_LEVEL as string | undefined,
65
- viteMode: import.meta.env.MODE as string | undefined,
66
- });
67
- };
68
-
69
- const normalizeSeparators = (path: string): string => {
70
- return path.replace(/\\/g, "/");
71
- };
72
-
73
- const stripOrigin = (path: string): string => {
74
- if (typeof window !== "undefined" && window.location?.origin) {
75
- return path.replace(window.location.origin, "");
76
- }
77
-
78
- return path;
79
- };
80
-
81
- const stripWorkspaceRoot = (path: string): string => {
82
- try {
83
- const globalProcess = getProcessObject();
84
- if (globalProcess && typeof globalProcess.cwd === "function") {
85
- const cwd = normalizeSeparators(globalProcess.cwd());
86
- if (path.startsWith(cwd)) {
87
- return path.slice(cwd.length);
88
- }
89
- }
90
- } catch {
91
- // Ignore if process is unavailable
92
- }
93
- return path;
94
- };
95
-
96
- const sanitizeFilePath = (path: string): string => {
97
- if (!path) {
98
- return "";
99
- }
100
-
101
- let cleaned = normalizeSeparators(path);
102
- cleaned = cleaned.replace(
103
- /^webpack-internal:\/\/\/|^vite:\/\/|^file:\/\//,
104
- "",
105
- );
106
- cleaned = stripOrigin(cleaned);
107
- cleaned = stripWorkspaceRoot(cleaned);
108
- cleaned = cleaned.split(/[?#]/)[0];
109
- return cleaned;
110
- };
111
-
112
- const parseStackLine = (line: string): StackFrame | undefined => {
113
- const match = line.match(/(?:\()?(.*?):(\d+):(\d+)\)?$/);
114
- if (!match) {
115
- return undefined;
116
- }
117
-
118
- const [, rawPath, lineNumber, columnNumber] = match;
119
- return {
120
- filePath: rawPath,
121
- lineNumber: Number(lineNumber),
122
- columnNumber: Number(columnNumber),
123
- };
124
- };
125
-
126
- const captureStack = (): string | undefined => {
127
- try {
128
- return new Error().stack;
129
- } catch {
130
- return undefined;
131
- }
132
- };
133
-
134
- const getCallerFrameFromStack = (stack?: string): StackFrame | undefined => {
135
- if (!stack) {
136
- return undefined;
137
- }
138
-
139
- const lines = stack.split("\n").slice(1);
140
- for (const rawLine of lines) {
141
- const line = rawLine.trim();
142
- if (
143
- !line ||
144
- LOGGER_SOURCE_HINTS.some((hint) => line.includes(hint)) ||
145
- line.includes("node:internal")
146
- ) {
147
- continue;
148
- }
149
-
150
- const frame = parseStackLine(line);
151
- if (frame) {
152
- return frame;
153
- }
154
- }
155
-
156
- return undefined;
157
- };
158
-
159
- const deriveScopeFromPath = (filePath?: string): string | undefined => {
160
- if (!filePath) {
161
- return undefined;
162
- }
163
-
164
- const cleaned = sanitizeFilePath(filePath);
165
- const segments = cleaned.split("/").filter(Boolean);
166
-
167
- if (segments.length === 0) {
168
- return undefined;
169
- }
170
-
171
- const fileName = segments.pop();
172
- if (!fileName) {
173
- return undefined;
174
- }
175
- const parent = segments.pop();
176
- const baseName = fileName.replace(/\.[^.]+$/, "");
177
-
178
- return parent ? `${parent}/${baseName}` : baseName;
179
- };
180
-
181
- const getLocationLabel = (frame?: StackFrame): string | undefined => {
182
- if (!frame?.filePath) {
183
- return undefined;
184
- }
185
-
186
- const cleaned = sanitizeFilePath(frame.filePath);
187
- const parts = cleaned.split("/").filter(Boolean);
188
- const shortPath =
189
- parts.length > 2 ? parts.slice(-2).join("/") : parts.join("/") || cleaned;
190
-
191
- if (!shortPath) {
192
- return undefined;
193
- }
194
-
195
- if (frame.lineNumber) {
196
- return `${shortPath}:${frame.lineNumber}`;
197
- }
198
-
199
- return shortPath;
200
- };
201
-
202
- const resolveLoggerScope = (providedScope?: string): string | undefined => {
203
- if (providedScope) {
204
- return providedScope;
205
- }
206
-
207
- const frame = getCallerFrameFromStack(captureStack());
208
- return deriveScopeFromPath(frame?.filePath);
209
- };
210
-
211
- const ENV_LOG_LEVEL = resolveEnvLogLevel();
212
-
213
- const shouldLog = (
214
- requestedLevel: LogLevel,
215
- activeLevel: LogLevel,
216
- ): boolean => {
217
- return LOG_LEVELS.indexOf(requestedLevel) <= LOG_LEVELS.indexOf(activeLevel);
218
- };
219
-
220
- /**
221
- * Create a logger scoped to the current module. If no scope is provided, the
222
- * logger automatically derives the filename (plus parent folder) from the call
223
- * site so logs stay consistent without manual strings.
224
- */
225
- export const createLogger = ({
226
- scope,
227
- level = ENV_LOG_LEVEL,
228
- }: CreateLoggerOptions = {}): Logger => {
229
- const resolvedScope = resolveLoggerScope(scope);
230
-
231
- const log =
232
- (consoleMethod: keyof Console, logLevel: LogLevel): LoggerFn =>
233
- (...args: unknown[]) => {
234
- if (!shouldLog(logLevel, level)) {
235
- return;
236
- }
237
-
238
- const method = (console?.[consoleMethod] ?? console.log) as (
239
- ...args: unknown[]
240
- ) => void;
241
- if (!method) {
242
- return;
243
- }
244
-
245
- const frame = getCallerFrameFromStack(captureStack());
246
- const locationScopeCandidate = deriveScopeFromPath(frame?.filePath);
247
- const shouldShowResolvedScope =
248
- resolvedScope &&
249
- (!locationScopeCandidate || locationScopeCandidate !== resolvedScope);
250
-
251
- const scopeLabel = shouldShowResolvedScope ? resolvedScope : undefined;
252
- const locationLabel = getLocationLabel(frame);
253
-
254
- const prefixParts: string[] = [];
255
- if (scopeLabel) {
256
- prefixParts.push(`[${scopeLabel}]`);
257
- }
258
- if (locationLabel) {
259
- prefixParts.push(`(${locationLabel})`);
260
- }
261
-
262
- const prefix = prefixParts.length > 0 ? prefixParts.join(" ") : "";
263
- const finalArgs: unknown[] = (() => {
264
- if (!prefix) {
265
- return args;
266
- }
267
- if (args.length === 0) {
268
- return [prefix];
269
- }
270
- // Merge prefix into the first argument when it's a string so the first
271
- // arg remains the console format string (e.g. "%s …" still works).
272
- if (typeof args[0] === "string") {
273
- return [`${prefix} ${args[0]}`, ...args.slice(1)];
274
- }
275
- return [prefix, ...args];
276
- })();
277
-
278
- method.apply(console, finalArgs);
279
- };
280
-
281
- return {
282
- debug: log("debug", "debug"),
283
- info: log("info", "info"),
284
- warn: log("warn", "warn"),
285
- error: log("error", "error"),
286
- child: (childScope: string) => {
287
- const nestedScope =
288
- resolvedScope && resolvedScope.length > 0
289
- ? `${resolvedScope}:${childScope}`
290
- : childScope;
291
- return createLogger({ scope: nestedScope, level });
292
- },
293
- };
294
- };
295
-
296
- /**
297
- * Default logger instance scoped to the application root. Prefer using
298
- * module-level loggers (via `createLogger()`) for better call-site context.
299
- */
300
- export const logger = createLogger();
package/utils/mapping.ts DELETED
@@ -1,118 +0,0 @@
1
- import { bcs } from "@mysten/sui/bcs";
2
- import { Assemblies, State } from "../types";
3
- import { deriveObjectID } from "@mysten/sui/utils";
4
- import { getEveWorldPackageId, getObjectRegistryType } from "./constants";
5
- import { getSingletonObjectByType } from "../graphql/client";
6
-
7
- /**
8
- * Convert raw status variant string to State enum
9
- *
10
- * @category Utilities - Mapping
11
- */
12
- export function parseStatus(statusVariant: string | undefined): State {
13
- if (!statusVariant) return State.NULL;
14
-
15
- switch (statusVariant.toUpperCase()) {
16
- case "ONLINE":
17
- return State.ONLINE;
18
- case "OFFLINE":
19
- return State.ANCHORED;
20
- case "ANCHORED":
21
- return State.ANCHORED;
22
- case "UNANCHORED":
23
- return State.UNANCHORED;
24
- case "DESTROYED":
25
- return State.DESTROYED;
26
- default:
27
- return State.NULL;
28
- }
29
- }
30
-
31
- /**
32
- * Get assembly type from Move object type tag
33
- * @param typeRepr - The Move object type tag
34
- * @returns The assembly type as an enum
35
- *
36
- * @category Utilities - Mapping
37
- */
38
- export function getAssemblyType(typeRepr: string): Assemblies {
39
- if (typeRepr.includes("::storage_unit::StorageUnit")) {
40
- return Assemblies.SmartStorageUnit;
41
- }
42
- if (typeRepr.includes("::turret::Turret")) {
43
- return Assemblies.SmartTurret;
44
- }
45
- if (typeRepr.includes("::gate::Gate")) {
46
- return Assemblies.SmartGate;
47
- }
48
- if (typeRepr.includes("::network_node::NetworkNode")) {
49
- return Assemblies.NetworkNode;
50
- }
51
- if (typeRepr.includes("::manufacturing::Manufacturing")) {
52
- return Assemblies.Manufacturing;
53
- }
54
- if (typeRepr.includes("::refinery::Refinery")) {
55
- return Assemblies.Refinery;
56
- }
57
- if (typeRepr.includes("::assembly::Assembly")) {
58
- return Assemblies.Assembly;
59
- }
60
-
61
- // Assembly type not found, return default Assembly
62
- return Assemblies.Assembly;
63
- }
64
-
65
- // Cache for the Registry address
66
- let objectRegistryAddress: string | null = null;
67
- /**
68
- * Fetches the AssemblyRegistry singleton address from the chain
69
- * Caches the result to avoid repeated queries
70
- *
71
- * @category Utilities - Mapping
72
- */
73
- export async function getRegistryAddress(): Promise<string> {
74
- if (objectRegistryAddress) {
75
- return objectRegistryAddress;
76
- }
77
-
78
- const registryType = getObjectRegistryType();
79
- const result = await getSingletonObjectByType(registryType);
80
-
81
- const address = result.data?.objects?.nodes?.[0]?.address;
82
- if (!address) {
83
- throw new Error(`ObjectRegistry not found for type: ${registryType}`);
84
- }
85
-
86
- objectRegistryAddress = address;
87
- return address;
88
- }
89
-
90
- /**
91
- * Derives an object ID from an in-game item ID using the AssemblyRegistry
92
- * @param itemId - The in-game item ID
93
- * @returns The derived Sui object ID
94
- *
95
- * @category Utilities - Mapping
96
- */
97
- export async function getObjectId(
98
- itemId: string,
99
- selectedTenant: string,
100
- ): Promise<string> {
101
- const registryAddress = await getRegistryAddress();
102
-
103
- const bcsType = bcs.struct("TenantItemId", {
104
- id: bcs.u64(),
105
- tenant: bcs.string(),
106
- });
107
- const key = bcsType
108
- .serialize({ id: BigInt(itemId), tenant: selectedTenant })
109
- .toBytes();
110
-
111
- const objectId = deriveObjectID(
112
- registryAddress,
113
- `${getEveWorldPackageId()}::in_game_id::TenantItemId`,
114
- key,
115
- );
116
-
117
- return objectId;
118
- }
@@ -1,263 +0,0 @@
1
- import {
2
- Assemblies,
3
- AssemblyType,
4
- State,
5
- DetailedSmartCharacterResponse,
6
- SmartAssemblyResponse,
7
- InventoryItem,
8
- DatahubGameInfo,
9
- DetailedAssemblyResponse,
10
- } from "../types";
11
- import type {
12
- MoveObjectData,
13
- RawSuiObjectData,
14
- CharacterInfo,
15
- } from "../graphql/types";
16
- import { getAssemblyType, parseStatus } from "./mapping";
17
- import { getDatahubGameInfo } from "./datahub";
18
- import { getEnergyConfig, getEnergyUsageForType } from "./config";
19
- import { getObjectWithJson } from "../graphql";
20
- import { createLogger } from "./logger";
21
-
22
- const log = createLogger();
23
-
24
- /**
25
- * Transform CharacterInfo to DetailedSmartCharacterResponse
26
- *
27
- * @category Utilities - Transforms
28
- */
29
- export function transformToCharacter(
30
- characterInfo: CharacterInfo,
31
- ): DetailedSmartCharacterResponse {
32
- return {
33
- id: characterInfo.id,
34
- address: characterInfo.address,
35
- name: characterInfo.name,
36
- tribeId: characterInfo.tribeId,
37
- smartAssemblies: [],
38
- portrait: "",
39
- };
40
- }
41
-
42
- /**
43
- * Additional options for transformToAssembly
44
- */
45
- export interface TransformOptions {
46
- /** Character/owner information */
47
- character?: CharacterInfo | null;
48
- /** Pre-fetched datahub game info (name, description, image) */
49
- datahubInfo?: DatahubGameInfo | null;
50
- /** Energy source information */
51
- energySource?: RawSuiObjectData | null;
52
- /** Destination gate information, if Smart Gate */
53
- destinationGate?: RawSuiObjectData | null;
54
- }
55
-
56
- /**
57
- * Transform raw Sui Move object data to AssemblyType
58
- *
59
- * @param objectId - The Sui object address
60
- * @param moveObject - The Move object data from GraphQL
61
- * @param options - Optional transform options including character info
62
- *
63
- * @category Utilities - Transforms
64
- */
65
- export async function transformToAssembly(
66
- objectId: string,
67
- moveObject: MoveObjectData,
68
- options?: TransformOptions,
69
- ): Promise<AssemblyType<Assemblies> | null> {
70
- const rawData = moveObject.contents?.json as unknown as RawSuiObjectData;
71
-
72
- if (!rawData) {
73
- log.warn("[DappKit] transformToAssembly: No raw data found");
74
- return null;
75
- }
76
-
77
- // Determine assembly type from Move object
78
- const typeId = rawData.type_id || rawData.status?.type_id || "0";
79
- const assemblyType = getAssemblyType(moveObject.contents.type?.repr || ""); // This is the Move object type tag, not the typeId
80
-
81
- // Parse dynamic fields for additional data (such as inventory)
82
- const dynamicFields: Record<string, unknown> = {};
83
- if (moveObject.dynamicFields?.nodes) {
84
- for (const field of moveObject.dynamicFields.nodes) {
85
- const fieldName =
86
- typeof field.name.json === "string"
87
- ? field.name.json
88
- : JSON.stringify(field.name.json);
89
-
90
- dynamicFields[fieldName] = field.contents.json;
91
- }
92
- }
93
-
94
- // Build base assembly properties
95
- const state = parseStatus(rawData.status?.status?.["@variant"]);
96
-
97
- // Use pre-fetched datahub info for defaults (name, description, image); energy from on-chain EnergyConfig
98
- const datahubInfo = options?.datahubInfo;
99
- const energySource = options?.energySource;
100
- const energyUsage = await getEnergyUsageForType(parseInt(typeId, 10) || 0);
101
-
102
- const parentState = parseStatus(energySource?.status?.status?.["@variant"]);
103
-
104
- const baseAssembly = {
105
- id: rawData.id || objectId,
106
- item_id: parseInt(rawData.key?.item_id || "0", 10) || 0,
107
- type: assemblyType,
108
- name: rawData.metadata?.name || "",
109
- description: rawData.metadata?.description || "",
110
- dappURL: rawData.metadata?.url || "",
111
- energySourceId:
112
- assemblyType === Assemblies.NetworkNode
113
- ? undefined
114
- : energySource?.id || rawData.energy_source_id || "", // Parent network node ID
115
- isParentNodeOnline:
116
- assemblyType === Assemblies.NetworkNode
117
- ? undefined
118
- : parentState === State.ONLINE, // Defined in all cases except network nodes
119
- state,
120
- typeId: parseInt(typeId, 10) || 0,
121
- energyUsage,
122
- typeDetails: datahubInfo,
123
- // Owner information
124
- character: options?.character || undefined,
125
- // Include raw data for debugging/extension
126
- _raw: moveObject,
127
- _options: options,
128
- } as DetailedAssemblyResponse;
129
-
130
- // Add module-specific data based on assembly type
131
- switch (assemblyType) {
132
- case Assemblies.SmartStorageUnit:
133
- const inventoryKey = rawData.inventory_keys?.[0];
134
- const inventoryData = dynamicFields[inventoryKey || ""] as
135
- | {
136
- key: string;
137
- value?: {
138
- max_capacity: string;
139
- used_capacity: string;
140
- items?: {
141
- contents?: Array<{ key: string; value: unknown }>;
142
- };
143
- };
144
- }
145
- | undefined;
146
-
147
- const inventoryItems = inventoryData?.value?.items?.contents?.map(
148
- (item) => {
149
- return item.value as InventoryItem;
150
- },
151
- );
152
-
153
- return {
154
- ...baseAssembly,
155
- storage: {
156
- mainInventory: {
157
- capacity: inventoryData?.value?.max_capacity,
158
- usedCapacity: inventoryData?.value?.used_capacity,
159
- items: inventoryItems,
160
- },
161
- ephemeralInventories: [],
162
- },
163
- } as AssemblyType<Assemblies.SmartStorageUnit>;
164
-
165
- case Assemblies.SmartTurret:
166
- return {
167
- ...baseAssembly,
168
- turret: {},
169
- } as AssemblyType<Assemblies.SmartTurret>;
170
-
171
- case Assemblies.SmartGate:
172
- return {
173
- ...baseAssembly,
174
- gate: {
175
- destinationId: rawData.linked_gate_id,
176
- destinationGate: options?.destinationGate,
177
- },
178
- } as AssemblyType<Assemblies.SmartGate>;
179
-
180
- case Assemblies.NetworkNode:
181
- const energyConfig = await getEnergyConfig();
182
- // TODO: Batch this call so that it can fetch all assemblies at once
183
- const linkedAssemblies: SmartAssemblyResponse[] = await Promise.all(
184
- (rawData.connected_assembly_ids || []).map(async (id) => {
185
- const assemblyResult = await getObjectWithJson(id);
186
- const assemblyJson = assemblyResult.data?.object?.asMoveObject
187
- ?.contents?.json as RawSuiObjectData | undefined;
188
-
189
- // TODO: Change this so that it doesn't need to be fetched for each assembly
190
- const typeDetails = await getDatahubGameInfo(
191
- parseInt(assemblyJson?.type_id || "0", 10),
192
- );
193
-
194
- const linkedTypeId = parseInt(assemblyJson?.type_id || "0", 10);
195
- return {
196
- id,
197
- item_id: parseInt(assemblyJson?.key?.item_id || "0", 10),
198
- state: parseStatus(assemblyJson?.status?.status?.["@variant"]),
199
- energyUsage: energyConfig[linkedTypeId] ?? 0,
200
- typeId: linkedTypeId,
201
- name: assemblyJson?.metadata?.name || "",
202
- type: getAssemblyType(assemblyJson?.type_id || ""),
203
- typeDetails: typeDetails,
204
- };
205
- }),
206
- );
207
-
208
- return {
209
- ...baseAssembly,
210
- networkNode: {
211
- fuel: {
212
- burnTimeInMs: parseInt(rawData.fuel?.burn_rate_in_ms || "0", 10),
213
- burnStartTime: parseInt(rawData.fuel?.burn_start_time || "0", 10),
214
- isBurning: rawData.fuel?.is_burning || false,
215
- lastUpdated: parseInt(rawData.fuel?.last_updated || "0", 10),
216
- maxCapacity: parseInt(rawData.fuel?.max_capacity || "0", 10),
217
- previousCycleElapsedTime: parseInt(
218
- rawData.fuel?.previous_cycle_elapsed_time || "0",
219
- 10,
220
- ),
221
- quantity: parseInt(rawData.fuel?.quantity || "0", 10),
222
- typeId: parseInt(rawData.fuel?.type_id || "0", 10),
223
- unitVolume: parseInt(rawData.fuel?.unit_volume || "0", 10),
224
- },
225
- energyProduction: parseInt(
226
- rawData.energy_source?.current_energy_production || "0",
227
- 10,
228
- ),
229
- energyMaxCapacity: parseInt(
230
- rawData.energy_source?.max_energy_production || "0",
231
- 10,
232
- ),
233
- totalReservedEnergy: parseInt(
234
- rawData.energy_source?.total_reserved_energy || "0",
235
- 10,
236
- ),
237
- linkedAssemblies: linkedAssemblies || [],
238
- },
239
- } as AssemblyType<Assemblies.NetworkNode>;
240
-
241
- case Assemblies.Manufacturing:
242
- return {
243
- ...baseAssembly,
244
- manufacturing: {
245
- isParentNodeOnline: state === State.ONLINE,
246
- },
247
- } as AssemblyType<Assemblies.Manufacturing>;
248
-
249
- case Assemblies.Refinery:
250
- return {
251
- ...baseAssembly,
252
- refinery: {
253
- isParentNodeOnline: state === State.ONLINE,
254
- },
255
- } as AssemblyType<Assemblies.Refinery>;
256
-
257
- default:
258
- // Default to Assembly
259
- return {
260
- ...baseAssembly,
261
- } as AssemblyType<Assemblies.Assembly>;
262
- }
263
- }