@dcl/sdk 7.20.1-21975617794.commit-7189140 → 7.20.1-22059706997.commit-95189a7
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/network/binary-message-bus.d.ts +3 -6
- package/network/binary-message-bus.js +5 -9
- package/network/index.d.ts +2 -8
- package/network/index.js +3 -16
- package/network/message-bus-sync.d.ts +1 -14
- package/network/message-bus-sync.js +103 -166
- package/network/state.js +5 -3
- package/package.json +6 -6
- package/src/network/binary-message-bus.ts +4 -9
- package/src/network/index.ts +3 -40
- package/src/network/message-bus-sync.ts +110 -180
- package/src/network/state.ts +4 -3
- package/atom.d.ts +0 -19
- package/atom.js +0 -83
- package/future.d.ts +0 -8
- package/future.js +0 -26
- package/network/chunking.d.ts +0 -5
- package/network/chunking.js +0 -38
- package/network/events/implementation.d.ts +0 -93
- package/network/events/implementation.js +0 -230
- package/network/events/index.d.ts +0 -42
- package/network/events/index.js +0 -43
- package/network/events/protocol.d.ts +0 -27
- package/network/events/protocol.js +0 -66
- package/network/events/registry.d.ts +0 -8
- package/network/events/registry.js +0 -3
- package/network/server/index.d.ts +0 -14
- package/network/server/index.js +0 -219
- package/network/server/utils.d.ts +0 -18
- package/network/server/utils.js +0 -135
- package/server/env-var.d.ts +0 -15
- package/server/env-var.js +0 -31
- package/server/index.d.ts +0 -2
- package/server/index.js +0 -3
- package/server/storage/constants.d.ts +0 -1
- package/server/storage/constants.js +0 -2
- package/server/storage/index.d.ts +0 -21
- package/server/storage/index.js +0 -28
- package/server/storage/player.d.ts +0 -34
- package/server/storage/player.js +0 -61
- package/server/storage/scene.d.ts +0 -30
- package/server/storage/scene.js +0 -61
- package/server/storage-url.d.ts +0 -10
- package/server/storage-url.js +0 -29
- package/server/utils.d.ts +0 -35
- package/server/utils.js +0 -56
- package/src/atom.ts +0 -98
- package/src/future.ts +0 -38
- package/src/network/chunking.ts +0 -45
- package/src/network/events/implementation.ts +0 -286
- package/src/network/events/index.ts +0 -48
- package/src/network/events/protocol.ts +0 -94
- package/src/network/events/registry.ts +0 -18
- package/src/network/server/index.ts +0 -301
- package/src/network/server/utils.ts +0 -189
- package/src/server/env-var.ts +0 -36
- package/src/server/index.ts +0 -2
- package/src/server/storage/constants.ts +0 -1
- package/src/server/storage/index.ts +0 -42
- package/src/server/storage/player.ts +0 -106
- package/src/server/storage/scene.ts +0 -102
- package/src/server/storage-url.ts +0 -34
- package/src/server/utils.ts +0 -73
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { getStorageServerUrl } from '../storage-url'
|
|
2
|
-
import { assertIsServer, wrapSignedFetch } from '../utils'
|
|
3
|
-
import { MODULE_NAME } from './constants'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Scene-scoped storage interface for key-value pairs from the Server Side Storage service.
|
|
7
|
-
* This is NOT filesystem storage - data is stored in the remote storage service.
|
|
8
|
-
*/
|
|
9
|
-
export interface ISceneStorage {
|
|
10
|
-
/**
|
|
11
|
-
* Retrieves a value from scene storage by key from the Server Side Storage service.
|
|
12
|
-
* @param key - The key to retrieve
|
|
13
|
-
* @returns A promise that resolves to the parsed JSON value, or null if not found
|
|
14
|
-
*/
|
|
15
|
-
get<T = unknown>(key: string): Promise<T | null>
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Stores a value in scene storage in the Server Side Storage service.
|
|
19
|
-
* @param key - The key to store the value under
|
|
20
|
-
* @param value - The value to store (will be JSON serialized)
|
|
21
|
-
*/
|
|
22
|
-
set<T = unknown>(key: string, value: T): Promise<boolean>
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Deletes a value from scene storage in the Server Side Storage service.
|
|
26
|
-
* @param key - The key to delete
|
|
27
|
-
* @returns A promise that resolves to true if deleted, false if not found
|
|
28
|
-
*/
|
|
29
|
-
delete(key: string): Promise<boolean>
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Creates scene-scoped storage that provides methods to interact with
|
|
34
|
-
* scene-specific key-value pairs from the Server Side Storage service.
|
|
35
|
-
* This module only works when running on server-side scenes.
|
|
36
|
-
*/
|
|
37
|
-
export const createSceneStorage = (): ISceneStorage => {
|
|
38
|
-
return {
|
|
39
|
-
async get<T = unknown>(key: string): Promise<T | null> {
|
|
40
|
-
assertIsServer(MODULE_NAME)
|
|
41
|
-
|
|
42
|
-
const baseUrl = await getStorageServerUrl()
|
|
43
|
-
const url = `${baseUrl}/values/${encodeURIComponent(key)}`
|
|
44
|
-
|
|
45
|
-
const [error, data] = await wrapSignedFetch<{ value: T }>({ url })
|
|
46
|
-
|
|
47
|
-
if (error) {
|
|
48
|
-
console.error(`Failed to get storage value '${key}': ${error}`)
|
|
49
|
-
return null
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return data?.value ?? null
|
|
53
|
-
},
|
|
54
|
-
|
|
55
|
-
async set<T = unknown>(key: string, value: T): Promise<boolean> {
|
|
56
|
-
assertIsServer(MODULE_NAME)
|
|
57
|
-
|
|
58
|
-
const baseUrl = await getStorageServerUrl()
|
|
59
|
-
const url = `${baseUrl}/values/${encodeURIComponent(key)}`
|
|
60
|
-
|
|
61
|
-
const [error] = await wrapSignedFetch({
|
|
62
|
-
url,
|
|
63
|
-
init: {
|
|
64
|
-
method: 'PUT',
|
|
65
|
-
headers: {
|
|
66
|
-
'content-type': 'application/json'
|
|
67
|
-
},
|
|
68
|
-
body: JSON.stringify({ value })
|
|
69
|
-
}
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
if (error) {
|
|
73
|
-
console.error(`Failed to set storage value '${key}': ${error}`)
|
|
74
|
-
return false
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return true
|
|
78
|
-
},
|
|
79
|
-
|
|
80
|
-
async delete(key: string): Promise<boolean> {
|
|
81
|
-
assertIsServer(MODULE_NAME)
|
|
82
|
-
|
|
83
|
-
const baseUrl = await getStorageServerUrl()
|
|
84
|
-
const url = `${baseUrl}/values/${encodeURIComponent(key)}`
|
|
85
|
-
|
|
86
|
-
const [error] = await wrapSignedFetch({
|
|
87
|
-
url,
|
|
88
|
-
init: {
|
|
89
|
-
method: 'DELETE',
|
|
90
|
-
headers: {}
|
|
91
|
-
}
|
|
92
|
-
})
|
|
93
|
-
|
|
94
|
-
if (error) {
|
|
95
|
-
console.error(`Failed to delete storage value '${key}': ${error}`)
|
|
96
|
-
return false
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
return true
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { getRealm } from '~system/Runtime'
|
|
2
|
-
|
|
3
|
-
const STORAGE_SERVER_ORG = 'https://storage.decentraland.org'
|
|
4
|
-
const STORAGE_SERVER_ZONE = 'https://storage.decentraland.zone'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Determines the correct storage server URL based on the current realm.
|
|
8
|
-
*
|
|
9
|
-
* - If `isPreview` is true, uses the realm's baseUrl (localhost)
|
|
10
|
-
* - If the realm's baseUrl contains `.zone`, uses storage.decentraland.zone
|
|
11
|
-
* - Otherwise, uses storage.decentraland.org (production)
|
|
12
|
-
*
|
|
13
|
-
* @returns The storage server base URL
|
|
14
|
-
*/
|
|
15
|
-
export async function getStorageServerUrl(): Promise<string> {
|
|
16
|
-
const { realmInfo } = await getRealm({})
|
|
17
|
-
|
|
18
|
-
if (!realmInfo) {
|
|
19
|
-
throw new Error('Unable to retrieve realm information')
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// Local development / preview mode
|
|
23
|
-
if (realmInfo.isPreview) {
|
|
24
|
-
return realmInfo.baseUrl
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// Staging / testing environment
|
|
28
|
-
if (realmInfo.baseUrl.includes('.zone')) {
|
|
29
|
-
return STORAGE_SERVER_ZONE
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// Production environment
|
|
33
|
-
return STORAGE_SERVER_ORG
|
|
34
|
-
}
|
package/src/server/utils.ts
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { signedFetch, SignedFetchRequest } from '~system/SignedFetch'
|
|
2
|
-
import { isServer } from '../network'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Validates that the code is running on a server-side scene.
|
|
6
|
-
* Throws an error if called from a client-side context.
|
|
7
|
-
*
|
|
8
|
-
* @param moduleName - The name of the module for the error message
|
|
9
|
-
* @throws Error if not running on a server-side scene
|
|
10
|
-
*/
|
|
11
|
-
export function assertIsServer(moduleName: string): void {
|
|
12
|
-
if (!isServer()) {
|
|
13
|
-
throw new Error(`${moduleName} is only available on server-side scenes`)
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Result type for operations that can fail.
|
|
19
|
-
* Returns a tuple of [error, null] on failure or [null, data] on success.
|
|
20
|
-
*/
|
|
21
|
-
export type Result<T, E = string> = [E, null] | [null, T]
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Extended result type that includes HTTP status code information.
|
|
25
|
-
*/
|
|
26
|
-
export type FetchResult<T> = [string, null, number?] | [null, T, number]
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Wraps a promise to catch errors and return a Result tuple.
|
|
30
|
-
* This allows for cleaner error handling without try-catch blocks.
|
|
31
|
-
*
|
|
32
|
-
* @param promise - The promise to wrap
|
|
33
|
-
* @returns A tuple of [error, null] on failure or [null, data] on success
|
|
34
|
-
*/
|
|
35
|
-
export async function tryCatch<T, E = Error>(promise: Promise<T>): Promise<Result<T, E>> {
|
|
36
|
-
try {
|
|
37
|
-
const data = await promise
|
|
38
|
-
return [null, data]
|
|
39
|
-
} catch (error) {
|
|
40
|
-
return [error as E, null]
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Wraps signedFetch with automatic error handling and JSON parsing.
|
|
46
|
-
* Returns a FetchResult tuple with parsed JSON data or error message and status code.
|
|
47
|
-
*
|
|
48
|
-
* @param signedFetchBody - The signedFetch request configuration
|
|
49
|
-
* @returns A tuple of [error, null, statusCode?] on failure or [null, data, statusCode] on success
|
|
50
|
-
*/
|
|
51
|
-
export async function wrapSignedFetch<T = unknown>(signedFetchBody: SignedFetchRequest): Promise<FetchResult<T>> {
|
|
52
|
-
const [error, response] = await tryCatch(signedFetch(signedFetchBody))
|
|
53
|
-
|
|
54
|
-
if (error) {
|
|
55
|
-
console.error(`Error in ${signedFetchBody.url} endpoint`, { error })
|
|
56
|
-
return [error.message, null, undefined]
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (!response.ok) {
|
|
60
|
-
const errorMessage = `${response.status} ${response.statusText}`
|
|
61
|
-
console.error(`Error in ${signedFetchBody.url} endpoint`, { response })
|
|
62
|
-
return [errorMessage, null, response.status]
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const [parseError, body] = await tryCatch<T>(JSON.parse(response.body || '{}'))
|
|
66
|
-
|
|
67
|
-
if (parseError) {
|
|
68
|
-
console.error(`Failed to parse response from ${signedFetchBody.url}`)
|
|
69
|
-
return ['Failed to parse response', null, response.status]
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return [null, (body ?? {}) as T, response.status]
|
|
73
|
-
}
|