@onlyworlds/sdk 2.1.0 → 2.1.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/dist/index.d.mts +19 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +34 -4
- package/dist/index.mjs +34 -4
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -553,8 +553,22 @@ interface Pin extends BaseElement {
|
|
|
553
553
|
map?: ElementId<ElementType.Map>;
|
|
554
554
|
element_type?: ElementType;
|
|
555
555
|
element_id?: AnyElementId;
|
|
556
|
+
/**
|
|
557
|
+
* X coordinate on map (must be integer)
|
|
558
|
+
* The API requires integer values. Float coordinates from mouse events
|
|
559
|
+
* or calculations should be rounded: Math.round(x)
|
|
560
|
+
*/
|
|
556
561
|
x?: number;
|
|
562
|
+
/**
|
|
563
|
+
* Y coordinate on map (must be integer)
|
|
564
|
+
* The API requires integer values. Float coordinates from mouse events
|
|
565
|
+
* or calculations should be rounded: Math.round(y)
|
|
566
|
+
*/
|
|
557
567
|
y?: number;
|
|
568
|
+
/**
|
|
569
|
+
* Z coordinate for 3D positioning (must be integer)
|
|
570
|
+
* The API requires integer values. Float coordinates should be rounded: Math.round(z)
|
|
571
|
+
*/
|
|
558
572
|
z?: number;
|
|
559
573
|
}
|
|
560
574
|
/**
|
|
@@ -3007,6 +3021,11 @@ declare class Resource<T, TInput> {
|
|
|
3007
3021
|
create(data: TInput): Promise<T>;
|
|
3008
3022
|
update(id: string, data: Partial<TInput>): Promise<T>;
|
|
3009
3023
|
delete(id: string): Promise<void>;
|
|
3024
|
+
/**
|
|
3025
|
+
* Round Pin coordinates to integers (API requirement)
|
|
3026
|
+
* @private
|
|
3027
|
+
*/
|
|
3028
|
+
private roundPinCoordinates;
|
|
3010
3029
|
}
|
|
3011
3030
|
/**
|
|
3012
3031
|
* Special resource class for World endpoint
|
package/dist/index.d.ts
CHANGED
|
@@ -553,8 +553,22 @@ interface Pin extends BaseElement {
|
|
|
553
553
|
map?: ElementId<ElementType.Map>;
|
|
554
554
|
element_type?: ElementType;
|
|
555
555
|
element_id?: AnyElementId;
|
|
556
|
+
/**
|
|
557
|
+
* X coordinate on map (must be integer)
|
|
558
|
+
* The API requires integer values. Float coordinates from mouse events
|
|
559
|
+
* or calculations should be rounded: Math.round(x)
|
|
560
|
+
*/
|
|
556
561
|
x?: number;
|
|
562
|
+
/**
|
|
563
|
+
* Y coordinate on map (must be integer)
|
|
564
|
+
* The API requires integer values. Float coordinates from mouse events
|
|
565
|
+
* or calculations should be rounded: Math.round(y)
|
|
566
|
+
*/
|
|
557
567
|
y?: number;
|
|
568
|
+
/**
|
|
569
|
+
* Z coordinate for 3D positioning (must be integer)
|
|
570
|
+
* The API requires integer values. Float coordinates should be rounded: Math.round(z)
|
|
571
|
+
*/
|
|
558
572
|
z?: number;
|
|
559
573
|
}
|
|
560
574
|
/**
|
|
@@ -3007,6 +3021,11 @@ declare class Resource<T, TInput> {
|
|
|
3007
3021
|
create(data: TInput): Promise<T>;
|
|
3008
3022
|
update(id: string, data: Partial<TInput>): Promise<T>;
|
|
3009
3023
|
delete(id: string): Promise<void>;
|
|
3024
|
+
/**
|
|
3025
|
+
* Round Pin coordinates to integers (API requirement)
|
|
3026
|
+
* @private
|
|
3027
|
+
*/
|
|
3028
|
+
private roundPinCoordinates;
|
|
3010
3029
|
}
|
|
3011
3030
|
/**
|
|
3012
3031
|
* Special resource class for World endpoint
|
package/dist/index.js
CHANGED
|
@@ -191,20 +191,42 @@ var Resource = class {
|
|
|
191
191
|
this.elementType = elementType;
|
|
192
192
|
}
|
|
193
193
|
async list(options) {
|
|
194
|
-
|
|
194
|
+
const response = await this.client.request("GET", `/${this.elementType}/`, { params: options });
|
|
195
|
+
if (Array.isArray(response)) {
|
|
196
|
+
return {
|
|
197
|
+
count: response.length,
|
|
198
|
+
next: null,
|
|
199
|
+
previous: null,
|
|
200
|
+
results: response
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
return response;
|
|
195
204
|
}
|
|
196
205
|
async get(id) {
|
|
197
206
|
return this.client.request("GET", `/${this.elementType}/${id}/`);
|
|
198
207
|
}
|
|
199
208
|
async create(data) {
|
|
200
|
-
|
|
209
|
+
const body = this.elementType === "pin" ? this.roundPinCoordinates(data) : data;
|
|
210
|
+
return this.client.request("POST", `/${this.elementType}/`, { body });
|
|
201
211
|
}
|
|
202
212
|
async update(id, data) {
|
|
203
|
-
|
|
213
|
+
const body = this.elementType === "pin" ? this.roundPinCoordinates(data) : data;
|
|
214
|
+
return this.client.request("PATCH", `/${this.elementType}/${id}/`, { body });
|
|
204
215
|
}
|
|
205
216
|
async delete(id) {
|
|
206
217
|
return this.client.request("DELETE", `/${this.elementType}/${id}/`);
|
|
207
218
|
}
|
|
219
|
+
/**
|
|
220
|
+
* Round Pin coordinates to integers (API requirement)
|
|
221
|
+
* @private
|
|
222
|
+
*/
|
|
223
|
+
roundPinCoordinates(data) {
|
|
224
|
+
const rounded = { ...data };
|
|
225
|
+
if (typeof rounded.x === "number") rounded.x = Math.round(rounded.x);
|
|
226
|
+
if (typeof rounded.y === "number") rounded.y = Math.round(rounded.y);
|
|
227
|
+
if (typeof rounded.z === "number") rounded.z = Math.round(rounded.z);
|
|
228
|
+
return rounded;
|
|
229
|
+
}
|
|
208
230
|
};
|
|
209
231
|
var WorldResource = class {
|
|
210
232
|
constructor(client) {
|
|
@@ -284,7 +306,15 @@ var OnlyWorldsClient = class {
|
|
|
284
306
|
if (errorText) {
|
|
285
307
|
try {
|
|
286
308
|
const errorJson = JSON.parse(errorText);
|
|
287
|
-
|
|
309
|
+
if (Array.isArray(errorJson.detail)) {
|
|
310
|
+
const validationErrors = errorJson.detail.map((err) => {
|
|
311
|
+
const location = err.loc ? err.loc.join(".") : "unknown";
|
|
312
|
+
return `${location}: ${err.msg}`;
|
|
313
|
+
}).join("; ");
|
|
314
|
+
errorMessage += `: ${validationErrors}`;
|
|
315
|
+
} else {
|
|
316
|
+
errorMessage += `: ${errorJson.detail || errorJson.error || errorText}`;
|
|
317
|
+
}
|
|
288
318
|
} catch {
|
|
289
319
|
errorMessage += `: ${errorText}`;
|
|
290
320
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -150,20 +150,42 @@ var Resource = class {
|
|
|
150
150
|
this.elementType = elementType;
|
|
151
151
|
}
|
|
152
152
|
async list(options) {
|
|
153
|
-
|
|
153
|
+
const response = await this.client.request("GET", `/${this.elementType}/`, { params: options });
|
|
154
|
+
if (Array.isArray(response)) {
|
|
155
|
+
return {
|
|
156
|
+
count: response.length,
|
|
157
|
+
next: null,
|
|
158
|
+
previous: null,
|
|
159
|
+
results: response
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
return response;
|
|
154
163
|
}
|
|
155
164
|
async get(id) {
|
|
156
165
|
return this.client.request("GET", `/${this.elementType}/${id}/`);
|
|
157
166
|
}
|
|
158
167
|
async create(data) {
|
|
159
|
-
|
|
168
|
+
const body = this.elementType === "pin" ? this.roundPinCoordinates(data) : data;
|
|
169
|
+
return this.client.request("POST", `/${this.elementType}/`, { body });
|
|
160
170
|
}
|
|
161
171
|
async update(id, data) {
|
|
162
|
-
|
|
172
|
+
const body = this.elementType === "pin" ? this.roundPinCoordinates(data) : data;
|
|
173
|
+
return this.client.request("PATCH", `/${this.elementType}/${id}/`, { body });
|
|
163
174
|
}
|
|
164
175
|
async delete(id) {
|
|
165
176
|
return this.client.request("DELETE", `/${this.elementType}/${id}/`);
|
|
166
177
|
}
|
|
178
|
+
/**
|
|
179
|
+
* Round Pin coordinates to integers (API requirement)
|
|
180
|
+
* @private
|
|
181
|
+
*/
|
|
182
|
+
roundPinCoordinates(data) {
|
|
183
|
+
const rounded = { ...data };
|
|
184
|
+
if (typeof rounded.x === "number") rounded.x = Math.round(rounded.x);
|
|
185
|
+
if (typeof rounded.y === "number") rounded.y = Math.round(rounded.y);
|
|
186
|
+
if (typeof rounded.z === "number") rounded.z = Math.round(rounded.z);
|
|
187
|
+
return rounded;
|
|
188
|
+
}
|
|
167
189
|
};
|
|
168
190
|
var WorldResource = class {
|
|
169
191
|
constructor(client) {
|
|
@@ -243,7 +265,15 @@ var OnlyWorldsClient = class {
|
|
|
243
265
|
if (errorText) {
|
|
244
266
|
try {
|
|
245
267
|
const errorJson = JSON.parse(errorText);
|
|
246
|
-
|
|
268
|
+
if (Array.isArray(errorJson.detail)) {
|
|
269
|
+
const validationErrors = errorJson.detail.map((err) => {
|
|
270
|
+
const location = err.loc ? err.loc.join(".") : "unknown";
|
|
271
|
+
return `${location}: ${err.msg}`;
|
|
272
|
+
}).join("; ");
|
|
273
|
+
errorMessage += `: ${validationErrors}`;
|
|
274
|
+
} else {
|
|
275
|
+
errorMessage += `: ${errorJson.detail || errorJson.error || errorText}`;
|
|
276
|
+
}
|
|
247
277
|
} catch {
|
|
248
278
|
errorMessage += `: ${errorText}`;
|
|
249
279
|
}
|
package/package.json
CHANGED