@dcl/sdk 7.20.2-22169778016.commit-030cbfe → 7.20.2-22231111352.commit-d2f6f0a

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 (63) hide show
  1. package/network/binary-message-bus.d.ts +3 -6
  2. package/network/binary-message-bus.js +5 -9
  3. package/network/index.d.ts +2 -8
  4. package/network/index.js +3 -16
  5. package/network/message-bus-sync.d.ts +1 -14
  6. package/network/message-bus-sync.js +103 -166
  7. package/network/state.js +5 -3
  8. package/package.json +6 -6
  9. package/src/network/binary-message-bus.ts +4 -9
  10. package/src/network/index.ts +3 -40
  11. package/src/network/message-bus-sync.ts +110 -180
  12. package/src/network/state.ts +4 -3
  13. package/atom.d.ts +0 -19
  14. package/atom.js +0 -83
  15. package/future.d.ts +0 -8
  16. package/future.js +0 -26
  17. package/network/chunking.d.ts +0 -5
  18. package/network/chunking.js +0 -38
  19. package/network/events/implementation.d.ts +0 -93
  20. package/network/events/implementation.js +0 -230
  21. package/network/events/index.d.ts +0 -42
  22. package/network/events/index.js +0 -43
  23. package/network/events/protocol.d.ts +0 -27
  24. package/network/events/protocol.js +0 -66
  25. package/network/events/registry.d.ts +0 -8
  26. package/network/events/registry.js +0 -3
  27. package/network/server/index.d.ts +0 -14
  28. package/network/server/index.js +0 -219
  29. package/network/server/utils.d.ts +0 -18
  30. package/network/server/utils.js +0 -135
  31. package/server/env-var.d.ts +0 -15
  32. package/server/env-var.js +0 -31
  33. package/server/index.d.ts +0 -2
  34. package/server/index.js +0 -3
  35. package/server/storage/constants.d.ts +0 -23
  36. package/server/storage/constants.js +0 -2
  37. package/server/storage/index.d.ts +0 -22
  38. package/server/storage/index.js +0 -29
  39. package/server/storage/player.d.ts +0 -43
  40. package/server/storage/player.js +0 -92
  41. package/server/storage/scene.d.ts +0 -38
  42. package/server/storage/scene.js +0 -90
  43. package/server/storage-url.d.ts +0 -10
  44. package/server/storage-url.js +0 -29
  45. package/server/utils.d.ts +0 -35
  46. package/server/utils.js +0 -56
  47. package/src/atom.ts +0 -98
  48. package/src/future.ts +0 -38
  49. package/src/network/chunking.ts +0 -45
  50. package/src/network/events/implementation.ts +0 -286
  51. package/src/network/events/index.ts +0 -48
  52. package/src/network/events/protocol.ts +0 -94
  53. package/src/network/events/registry.ts +0 -18
  54. package/src/network/server/index.ts +0 -301
  55. package/src/network/server/utils.ts +0 -189
  56. package/src/server/env-var.ts +0 -36
  57. package/src/server/index.ts +0 -2
  58. package/src/server/storage/constants.ts +0 -22
  59. package/src/server/storage/index.ts +0 -44
  60. package/src/server/storage/player.ts +0 -156
  61. package/src/server/storage/scene.ts +0 -149
  62. package/src/server/storage-url.ts +0 -34
  63. package/src/server/utils.ts +0 -73
@@ -1,156 +0,0 @@
1
- import { getStorageServerUrl } from '../storage-url'
2
- import { assertIsServer, wrapSignedFetch } from '../utils'
3
- import { GetValuesOptions, GetValuesResult, MODULE_NAME } from './constants'
4
-
5
- /**
6
- * Player-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 IPlayerStorage {
10
- /**
11
- * Retrieves a value from a player's storage by key from the Server Side Storage service.
12
- * @param address - The player's wallet address
13
- * @param key - The key to retrieve
14
- * @returns A promise that resolves to the parsed JSON value, or null if not found
15
- */
16
- get<T = unknown>(address: string, key: string): Promise<T | null>
17
-
18
- /**
19
- * Stores a value in a player's storage in the Server Side Storage service.
20
- * @param address - The player's wallet address
21
- * @param key - The key to store the value under
22
- * @param value - The value to store (will be JSON serialized)
23
- * @returns A promise that resolves to true if successful, false otherwise
24
- */
25
- set<T = unknown>(address: string, key: string, value: T): Promise<boolean>
26
-
27
- /**
28
- * Deletes a value from a player's storage in the Server Side Storage service.
29
- * @param address - The player's wallet address
30
- * @param key - The key to delete
31
- * @returns A promise that resolves to true if deleted, false if not found
32
- */
33
- delete(address: string, key: string): Promise<boolean>
34
-
35
- /**
36
- * Returns key-value entries from a player's storage, optionally filtered by prefix.
37
- * Supports pagination via limit and offset.
38
- * @param address - The player's wallet address
39
- * @param options - Optional { prefix, limit, offset } for filtering and pagination.
40
- * @returns A promise that resolves to { data, pagination: { offset, total } } for pagination UI
41
- */
42
- getValues(address: string, options?: GetValuesOptions): Promise<GetValuesResult>
43
- }
44
-
45
- /**
46
- * Creates player-scoped storage that provides methods to interact with
47
- * player-specific key-value pairs from the Server Side Storage service.
48
- * This module only works when running on server-side scenes.
49
- */
50
- export const createPlayerStorage = (): IPlayerStorage => {
51
- return {
52
- async get<T = unknown>(address: string, key: string): Promise<T | null> {
53
- assertIsServer(MODULE_NAME)
54
-
55
- const baseUrl = await getStorageServerUrl()
56
- const url = `${baseUrl}/players/${encodeURIComponent(address)}/values/${encodeURIComponent(key)}`
57
-
58
- const [error, data] = await wrapSignedFetch<{ value: T }>({ url })
59
-
60
- if (error) {
61
- console.error(`Failed to get player storage value '${key}' for '${address}': ${error}`)
62
- return null
63
- }
64
-
65
- return data?.value ?? null
66
- },
67
-
68
- async set<T = unknown>(address: string, key: string, value: T): Promise<boolean> {
69
- assertIsServer(MODULE_NAME)
70
-
71
- const baseUrl = await getStorageServerUrl()
72
- const url = `${baseUrl}/players/${encodeURIComponent(address)}/values/${encodeURIComponent(key)}`
73
-
74
- const [error] = await wrapSignedFetch({
75
- url,
76
- init: {
77
- method: 'PUT',
78
- headers: {
79
- 'content-type': 'application/json'
80
- },
81
- body: JSON.stringify({ value })
82
- }
83
- })
84
-
85
- if (error) {
86
- console.error(`Failed to set player storage value '${key}' for '${address}': ${error}`)
87
- return false
88
- }
89
-
90
- return true
91
- },
92
-
93
- async delete(address: string, key: string): Promise<boolean> {
94
- assertIsServer(MODULE_NAME)
95
-
96
- const baseUrl = await getStorageServerUrl()
97
- const url = `${baseUrl}/players/${encodeURIComponent(address)}/values/${encodeURIComponent(key)}`
98
-
99
- const [error] = await wrapSignedFetch({
100
- url,
101
- init: {
102
- method: 'DELETE',
103
- headers: {}
104
- }
105
- })
106
-
107
- if (error) {
108
- console.error(`Failed to delete player storage value '${key}' for '${address}': ${error}`)
109
- return false
110
- }
111
-
112
- return true
113
- },
114
-
115
- async getValues(address: string, options?: GetValuesOptions): Promise<GetValuesResult> {
116
- assertIsServer(MODULE_NAME)
117
-
118
- const { prefix, limit, offset } = options ?? {}
119
- const baseUrl = await getStorageServerUrl()
120
- const parts: string[] = []
121
-
122
- if (!!prefix) {
123
- parts.push(`prefix=${encodeURIComponent(prefix)}`)
124
- }
125
-
126
- if (!!limit) {
127
- parts.push(`limit=${limit}`)
128
- }
129
-
130
- if (!!offset) {
131
- parts.push(`offset=${offset}`)
132
- }
133
-
134
- const query = parts.join('&')
135
- const url = query
136
- ? `${baseUrl}/players/${encodeURIComponent(address)}/values?${query}`
137
- : `${baseUrl}/players/${encodeURIComponent(address)}/values`
138
-
139
- const [error, response] = await wrapSignedFetch<GetValuesResult>({ url })
140
-
141
- if (error) {
142
- console.error(`Failed to get player storage values for '${address}': ${error}`)
143
- return { data: [], pagination: { offset: 0, total: 0 } }
144
- }
145
-
146
- const data = response?.data ?? []
147
- const requestedOffset = offset ?? 0
148
- const pagination = {
149
- offset: response?.pagination?.offset ?? requestedOffset,
150
- total: response?.pagination?.total ?? data.length
151
- }
152
-
153
- return { data, pagination }
154
- }
155
- }
156
- }
@@ -1,149 +0,0 @@
1
- import { getStorageServerUrl } from '../storage-url'
2
- import { assertIsServer, wrapSignedFetch } from '../utils'
3
- import { GetValuesOptions, GetValuesResult, 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
- * Returns key-value entries from scene storage, optionally filtered by prefix.
33
- * Supports pagination via limit and offset.
34
- * @param options - Optional { prefix, limit, offset } for filtering and pagination.
35
- * @returns A promise that resolves to { data, pagination: { offset, total } } for pagination UI
36
- */
37
- getValues(options?: GetValuesOptions): Promise<GetValuesResult>
38
- }
39
-
40
- /**
41
- * Creates scene-scoped storage that provides methods to interact with
42
- * scene-specific key-value pairs from the Server Side Storage service.
43
- * This module only works when running on server-side scenes.
44
- */
45
- export const createSceneStorage = (): ISceneStorage => {
46
- return {
47
- async get<T = unknown>(key: string): Promise<T | null> {
48
- assertIsServer(MODULE_NAME)
49
-
50
- const baseUrl = await getStorageServerUrl()
51
- const url = `${baseUrl}/values/${encodeURIComponent(key)}`
52
-
53
- const [error, data] = await wrapSignedFetch<{ value: T }>({ url })
54
-
55
- if (error) {
56
- console.error(`Failed to get storage value '${key}': ${error}`)
57
- return null
58
- }
59
-
60
- return data?.value ?? null
61
- },
62
-
63
- async set<T = unknown>(key: string, value: T): Promise<boolean> {
64
- assertIsServer(MODULE_NAME)
65
-
66
- const baseUrl = await getStorageServerUrl()
67
- const url = `${baseUrl}/values/${encodeURIComponent(key)}`
68
-
69
- const [error] = await wrapSignedFetch({
70
- url,
71
- init: {
72
- method: 'PUT',
73
- headers: {
74
- 'content-type': 'application/json'
75
- },
76
- body: JSON.stringify({ value })
77
- }
78
- })
79
-
80
- if (error) {
81
- console.error(`Failed to set storage value '${key}': ${error}`)
82
- return false
83
- }
84
-
85
- return true
86
- },
87
-
88
- async delete(key: string): Promise<boolean> {
89
- assertIsServer(MODULE_NAME)
90
-
91
- const baseUrl = await getStorageServerUrl()
92
- const url = `${baseUrl}/values/${encodeURIComponent(key)}`
93
-
94
- const [error] = await wrapSignedFetch({
95
- url,
96
- init: {
97
- method: 'DELETE',
98
- headers: {}
99
- }
100
- })
101
-
102
- if (error) {
103
- console.error(`Failed to delete storage value '${key}': ${error}`)
104
- return false
105
- }
106
-
107
- return true
108
- },
109
-
110
- async getValues(options?: GetValuesOptions): Promise<GetValuesResult> {
111
- assertIsServer(MODULE_NAME)
112
-
113
- const { prefix, limit, offset } = options ?? {}
114
- const baseUrl = await getStorageServerUrl()
115
- const parts: string[] = []
116
-
117
- if (!!prefix) {
118
- parts.push(`prefix=${encodeURIComponent(prefix)}`)
119
- }
120
-
121
- if (!!limit) {
122
- parts.push(`limit=${limit}`)
123
- }
124
-
125
- if (!!offset) {
126
- parts.push(`offset=${offset}`)
127
- }
128
-
129
- const query = parts.join('&')
130
- const url = query ? `${baseUrl}/values?${query}` : `${baseUrl}/values`
131
-
132
- const [error, response] = await wrapSignedFetch<GetValuesResult>({ url })
133
-
134
- if (error) {
135
- console.error(`Failed to get storage values: ${error}`)
136
- return { data: [], pagination: { offset: 0, total: 0 } }
137
- }
138
-
139
- const data = response?.data ?? []
140
- const requestedOffset = offset ?? 0
141
- const pagination = {
142
- offset: response?.pagination?.offset ?? requestedOffset,
143
- total: response?.pagination?.total ?? data.length
144
- }
145
-
146
- return { data, pagination }
147
- }
148
- }
149
- }
@@ -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
- }
@@ -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
- }