@magiclabs.ai/magicbook-client 0.6.11 → 0.6.12-canary

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/index.cjs CHANGED
@@ -28,7 +28,7 @@ __export(src_exports, {
28
28
  assetSchema: () => assetSchema,
29
29
  bookCreationRequestSchema: () => bookCreationRequestSchema,
30
30
  bookSizes: () => bookSizes,
31
- cancelledMessage: () => cancelledMessage,
31
+ cancelledEventDetail: () => cancelledEventDetail,
32
32
  canvasSchema: () => canvasSchema,
33
33
  coverTypes: () => coverTypes,
34
34
  designOptionsSchema: () => designOptionsSchema,
@@ -57,7 +57,7 @@ __export(src_exports, {
57
57
  statesToReport: () => statesToReport,
58
58
  styles: () => styles,
59
59
  textStickerLevels: () => textStickerLevels,
60
- timeoutMessage: () => timeoutMessage
60
+ timeoutEventDetail: () => timeoutEventDetail
61
61
  });
62
62
  module.exports = __toCommonJS(src_exports);
63
63
 
@@ -272,13 +272,13 @@ var imageDensities = ["low", "medium", "high"];
272
272
  var imageFilteringLevels = ["best", "most", "all"];
273
273
  var embellishmentLevels = ["none", "few", "lots"];
274
274
  var textStickerLevels = ["none", "few", "lots"];
275
- var timeoutMessage = {
275
+ var timeoutEventDetail = {
276
276
  state: "timeout",
277
277
  slug: "timeout",
278
278
  progress: 100,
279
279
  message: "Design timed out"
280
280
  };
281
- var cancelledMessage = {
281
+ var cancelledEventDetail = {
282
282
  state: "cancelled",
283
283
  slug: "cancelled",
284
284
  progress: 100,
@@ -4076,6 +4076,7 @@ var bookDesignRequestSchema = z.object({
4076
4076
  var BookPropsSchema = z.object({
4077
4077
  id: z.string().optional(),
4078
4078
  title: z.string(),
4079
+ subtitle: z.string().optional(),
4079
4080
  design_request: bookDesignRequestSchema,
4080
4081
  state: z.enum(states).optional(),
4081
4082
  guid: z.string().optional(),
@@ -4084,6 +4085,7 @@ var BookPropsSchema = z.object({
4084
4085
  var Book = class {
4085
4086
  id;
4086
4087
  title;
4088
+ subtitle;
4087
4089
  design_request;
4088
4090
  state;
4089
4091
  guid;
@@ -4091,6 +4093,7 @@ var Book = class {
4091
4093
  constructor(props) {
4092
4094
  this.id = props.id || "";
4093
4095
  this.title = props.title;
4096
+ this.subtitle = props.subtitle;
4094
4097
  this.design_request = new BookDesignRequest(props.design_request);
4095
4098
  this.state = props.state;
4096
4099
  this.guid = props.guid;
@@ -4193,9 +4196,9 @@ var designOptionsServerSchema = z.object({
4193
4196
  });
4194
4197
 
4195
4198
  // ../../core/config.ts
4196
- var defaultApiHost = "https://api.sfly-sls.magicbook.io";
4197
- var defaultWebSocketHost = "wss://socket.sfly-sls.magicbook.io";
4198
- var designRequestTimeout = parseInt("30000"?.toString() || "3000");
4199
+ var defaultApiHost = "http://localhost:2812";
4200
+ var defaultWebSocketHost = "wss://localhost:2812";
4201
+ var designRequestTimeout = parseInt(""?.toString() || "3000");
4199
4202
 
4200
4203
  // ../../core/models/design-request/index.ts
4201
4204
  var DesignRequestOptions = {
@@ -4217,6 +4220,7 @@ var DesignRequest = class {
4217
4220
  this.webSocket = new WebSocket(`${this.client.webSocketHost}/?book_id=${this.parentId}`);
4218
4221
  this.state = designRequestProps?.state || states[0];
4219
4222
  this.title = designRequestProps?.title || "";
4223
+ this.subtitle = designRequestProps?.subtitle;
4220
4224
  this.occasion = designRequestProps?.occasion || occasions[0];
4221
4225
  this.style = designRequestProps?.style || parseInt(Object.keys(styles)[0]);
4222
4226
  this.bookSize = designRequestProps?.bookSize || bookSizes[0];
@@ -4229,10 +4233,10 @@ var DesignRequest = class {
4229
4233
  this.images = new Images(this.client, this.parentId);
4230
4234
  }
4231
4235
  webSocket;
4232
- // private events: DesignRequestEvent[]
4233
4236
  state;
4234
4237
  parentId;
4235
4238
  title;
4239
+ subtitle;
4236
4240
  occasion;
4237
4241
  style;
4238
4242
  bookSize;
@@ -4293,7 +4297,7 @@ var DesignRequest = class {
4293
4297
  (await this.client.engineAPI.books.cancel(this.parentId)).toDesignRequestProps()
4294
4298
  );
4295
4299
  this.state = "cancelled";
4296
- await this.eventHandler(cancelledMessage);
4300
+ await this.eventHandler(cancelledEventDetail);
4297
4301
  return this;
4298
4302
  }
4299
4303
  }
@@ -4306,7 +4310,6 @@ var DesignRequest = class {
4306
4310
  }
4307
4311
  async eventHandler(detail, type = "MagicBook.designRequestUpdated") {
4308
4312
  const customEvent = new CustomEvent(type, { detail });
4309
- window.dispatchEvent(customEvent);
4310
4313
  if (statesToCloseWS.includes(detail.slug)) {
4311
4314
  this.webSocket.close();
4312
4315
  if (statesToReport.includes(detail.slug)) {
@@ -4317,20 +4320,21 @@ var DesignRequest = class {
4317
4320
  }
4318
4321
  }
4319
4322
  this.state = detail.slug;
4323
+ window.dispatchEvent(customEvent);
4320
4324
  }
4321
4325
  timeoutHandler() {
4322
4326
  return setTimeout(async () => {
4323
- await this.eventHandler(timeoutMessage);
4327
+ await this.eventHandler(timeoutEventDetail);
4324
4328
  }, designRequestTimeout);
4325
4329
  }
4326
4330
  async getProgress() {
4327
4331
  let timeout;
4328
- this.webSocket.onmessage = (event) => {
4332
+ this.webSocket.onmessage = async (event) => {
4329
4333
  const detail = JSON.parse(event.data);
4330
4334
  if (this.state !== detail.slug) {
4331
4335
  timeout && clearTimeout(timeout);
4332
4336
  timeout = this.timeoutHandler();
4333
- this.eventHandler(detail);
4337
+ await this.eventHandler(detail);
4334
4338
  }
4335
4339
  };
4336
4340
  this.webSocket.onclose = () => clearTimeout(timeout);
@@ -4347,6 +4351,7 @@ var DesignRequest = class {
4347
4351
  id: designRequest.parentId,
4348
4352
  guid: designRequest.guid,
4349
4353
  title: designRequest.title,
4354
+ subtitle: designRequest.subtitle,
4350
4355
  design_request: bookDesignRequest,
4351
4356
  state: designRequest.state
4352
4357
  });
@@ -4878,7 +4883,7 @@ var MagicBookClient = class {
4878
4883
  assetSchema,
4879
4884
  bookCreationRequestSchema,
4880
4885
  bookSizes,
4881
- cancelledMessage,
4886
+ cancelledEventDetail,
4882
4887
  canvasSchema,
4883
4888
  coverTypes,
4884
4889
  designOptionsSchema,
@@ -4907,6 +4912,6 @@ var MagicBookClient = class {
4907
4912
  statesToReport,
4908
4913
  styles,
4909
4914
  textStickerLevels,
4910
- timeoutMessage
4915
+ timeoutEventDetail
4911
4916
  });
4912
4917
  //# sourceMappingURL=index.cjs.map