@onlyworlds/sdk 2.1.0 → 2.1.2

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 CHANGED
@@ -544,6 +544,7 @@ interface Marker extends BaseElement {
544
544
  x?: number;
545
545
  y?: number;
546
546
  z?: number;
547
+ order?: number;
547
548
  }
548
549
  /**
549
550
  * Pin element type
@@ -553,8 +554,22 @@ interface Pin extends BaseElement {
553
554
  map?: ElementId<ElementType.Map>;
554
555
  element_type?: ElementType;
555
556
  element_id?: AnyElementId;
557
+ /**
558
+ * X coordinate on map (must be integer)
559
+ * The API requires integer values. Float coordinates from mouse events
560
+ * or calculations should be rounded: Math.round(x)
561
+ */
556
562
  x?: number;
563
+ /**
564
+ * Y coordinate on map (must be integer)
565
+ * The API requires integer values. Float coordinates from mouse events
566
+ * or calculations should be rounded: Math.round(y)
567
+ */
557
568
  y?: number;
569
+ /**
570
+ * Z coordinate for 3D positioning (must be integer)
571
+ * The API requires integer values. Float coordinates should be rounded: Math.round(z)
572
+ */
558
573
  z?: number;
559
574
  }
560
575
  /**
@@ -1965,6 +1980,9 @@ declare const FIELD_SCHEMA: {
1965
1980
  readonly z: {
1966
1981
  readonly type: "number";
1967
1982
  };
1983
+ readonly order: {
1984
+ readonly type: "number";
1985
+ };
1968
1986
  };
1969
1987
  readonly narrative: {
1970
1988
  readonly name: {
@@ -3007,6 +3025,11 @@ declare class Resource<T, TInput> {
3007
3025
  create(data: TInput): Promise<T>;
3008
3026
  update(id: string, data: Partial<TInput>): Promise<T>;
3009
3027
  delete(id: string): Promise<void>;
3028
+ /**
3029
+ * Round Pin coordinates to integers (API requirement)
3030
+ * @private
3031
+ */
3032
+ private roundPinCoordinates;
3010
3033
  }
3011
3034
  /**
3012
3035
  * Special resource class for World endpoint
package/dist/index.d.ts CHANGED
@@ -544,6 +544,7 @@ interface Marker extends BaseElement {
544
544
  x?: number;
545
545
  y?: number;
546
546
  z?: number;
547
+ order?: number;
547
548
  }
548
549
  /**
549
550
  * Pin element type
@@ -553,8 +554,22 @@ interface Pin extends BaseElement {
553
554
  map?: ElementId<ElementType.Map>;
554
555
  element_type?: ElementType;
555
556
  element_id?: AnyElementId;
557
+ /**
558
+ * X coordinate on map (must be integer)
559
+ * The API requires integer values. Float coordinates from mouse events
560
+ * or calculations should be rounded: Math.round(x)
561
+ */
556
562
  x?: number;
563
+ /**
564
+ * Y coordinate on map (must be integer)
565
+ * The API requires integer values. Float coordinates from mouse events
566
+ * or calculations should be rounded: Math.round(y)
567
+ */
557
568
  y?: number;
569
+ /**
570
+ * Z coordinate for 3D positioning (must be integer)
571
+ * The API requires integer values. Float coordinates should be rounded: Math.round(z)
572
+ */
558
573
  z?: number;
559
574
  }
560
575
  /**
@@ -1965,6 +1980,9 @@ declare const FIELD_SCHEMA: {
1965
1980
  readonly z: {
1966
1981
  readonly type: "number";
1967
1982
  };
1983
+ readonly order: {
1984
+ readonly type: "number";
1985
+ };
1968
1986
  };
1969
1987
  readonly narrative: {
1970
1988
  readonly name: {
@@ -3007,6 +3025,11 @@ declare class Resource<T, TInput> {
3007
3025
  create(data: TInput): Promise<T>;
3008
3026
  update(id: string, data: Partial<TInput>): Promise<T>;
3009
3027
  delete(id: string): Promise<void>;
3028
+ /**
3029
+ * Round Pin coordinates to integers (API requirement)
3030
+ * @private
3031
+ */
3032
+ private roundPinCoordinates;
3010
3033
  }
3011
3034
  /**
3012
3035
  * 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
- return this.client.request("GET", `/${this.elementType}/`, { params: options });
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
- return this.client.request("POST", `/${this.elementType}/`, { body: data });
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
- return this.client.request("PATCH", `/${this.elementType}/${id}/`, { body: data });
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
- errorMessage += `: ${errorJson.detail || errorJson.error || errorText}`;
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
  }
@@ -431,7 +461,7 @@ var ELEMENT_SECTIONS = {
431
461
  { name: "Details", order: 1, fields: ["background_color", "hierarchy", "width", "height", "depth", "parent_map", "location"] }
432
462
  ],
433
463
  ["marker" /* Marker */]: [
434
- { name: "Details", order: 1, fields: ["map", "zone", "x", "y", "z"] }
464
+ { name: "Details", order: 1, fields: ["map", "zone", "x", "y", "z", "order"] }
435
465
  ],
436
466
  ["narrative" /* Narrative */]: [
437
467
  { name: "Context", order: 1, fields: ["story", "consequences", "start_date", "end_date", "order", "parent_narrative", "protagonist", "antagonist", "narrator", "conservator"] },
@@ -881,7 +911,8 @@ var FIELD_SCHEMA = {
881
911
  zone: { type: "single_link", target: "zone" },
882
912
  x: { type: "number" },
883
913
  y: { type: "number" },
884
- z: { type: "number" }
914
+ z: { type: "number" },
915
+ order: { type: "number" }
885
916
  },
886
917
  narrative: {
887
918
  // Base fields (shared by all elements)
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
- return this.client.request("GET", `/${this.elementType}/`, { params: options });
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
- return this.client.request("POST", `/${this.elementType}/`, { body: data });
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
- return this.client.request("PATCH", `/${this.elementType}/${id}/`, { body: data });
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
- errorMessage += `: ${errorJson.detail || errorJson.error || errorText}`;
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
  }
@@ -390,7 +420,7 @@ var ELEMENT_SECTIONS = {
390
420
  { name: "Details", order: 1, fields: ["background_color", "hierarchy", "width", "height", "depth", "parent_map", "location"] }
391
421
  ],
392
422
  ["marker" /* Marker */]: [
393
- { name: "Details", order: 1, fields: ["map", "zone", "x", "y", "z"] }
423
+ { name: "Details", order: 1, fields: ["map", "zone", "x", "y", "z", "order"] }
394
424
  ],
395
425
  ["narrative" /* Narrative */]: [
396
426
  { name: "Context", order: 1, fields: ["story", "consequences", "start_date", "end_date", "order", "parent_narrative", "protagonist", "antagonist", "narrator", "conservator"] },
@@ -840,7 +870,8 @@ var FIELD_SCHEMA = {
840
870
  zone: { type: "single_link", target: "zone" },
841
871
  x: { type: "number" },
842
872
  y: { type: "number" },
843
- z: { type: "number" }
873
+ z: { type: "number" },
874
+ order: { type: "number" }
844
875
  },
845
876
  narrative: {
846
877
  // Base fields (shared by all elements)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onlyworlds/sdk",
3
- "version": "2.1.0",
3
+ "version": "2.1.2",
4
4
  "description": "TypeScript SDK for the OnlyWorlds API - build world-building applications with type safety",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",