@magiclabs.ai/magicbook-client 0.6.13 → 0.6.14-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/README.md +7 -2
- package/index.cjs +73 -16
- package/index.cjs.map +1 -1
- package/index.d.cts +594 -540
- package/index.d.ts +594 -540
- package/index.js +69 -16
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -4010,14 +4010,15 @@ var bookDesignRequestSchema = z.object({
|
|
|
4010
4010
|
embellishment_level: z.enum(embellishmentLevels),
|
|
4011
4011
|
text_sticker_level: z.enum(textStickerLevels)
|
|
4012
4012
|
});
|
|
4013
|
-
var
|
|
4013
|
+
var bookPropsSchema = z.object({
|
|
4014
4014
|
id: z.string().optional(),
|
|
4015
4015
|
title: z.string(),
|
|
4016
4016
|
subtitle: z.string().optional(),
|
|
4017
4017
|
design_request: bookDesignRequestSchema,
|
|
4018
4018
|
state: z.enum(states).optional(),
|
|
4019
4019
|
guid: z.string().optional(),
|
|
4020
|
-
cancelled_at: z.string().optional()
|
|
4020
|
+
cancelled_at: z.string().optional(),
|
|
4021
|
+
mb_client_timeout: z.number().optional()
|
|
4021
4022
|
});
|
|
4022
4023
|
var Book = class {
|
|
4023
4024
|
id;
|
|
@@ -4027,6 +4028,7 @@ var Book = class {
|
|
|
4027
4028
|
state;
|
|
4028
4029
|
guid;
|
|
4029
4030
|
cancelled_at;
|
|
4031
|
+
timeout;
|
|
4030
4032
|
constructor(props) {
|
|
4031
4033
|
this.id = props.id || "";
|
|
4032
4034
|
this.title = props.title;
|
|
@@ -4035,6 +4037,7 @@ var Book = class {
|
|
|
4035
4037
|
this.state = props.state;
|
|
4036
4038
|
this.guid = props.guid;
|
|
4037
4039
|
this.cancelled_at = props.cancelled_at;
|
|
4040
|
+
this.timeout = props.mb_client_timeout ? props.mb_client_timeout * 1e3 : void 0;
|
|
4038
4041
|
}
|
|
4039
4042
|
toDesignRequestProps() {
|
|
4040
4043
|
const props = { ...this, ...this.design_request };
|
|
@@ -4042,6 +4045,12 @@ var Book = class {
|
|
|
4042
4045
|
delete props.design_request;
|
|
4043
4046
|
return snakeCaseObjectKeysToCamelCase(props);
|
|
4044
4047
|
}
|
|
4048
|
+
toBookProps() {
|
|
4049
|
+
return {
|
|
4050
|
+
...this,
|
|
4051
|
+
mb_client_timeout: this.timeout ? this.timeout / 1e3 : void 0
|
|
4052
|
+
};
|
|
4053
|
+
}
|
|
4045
4054
|
};
|
|
4046
4055
|
|
|
4047
4056
|
// ../../core/models/design-request/image.ts
|
|
@@ -4132,11 +4141,6 @@ var designOptionsServerSchema = z.object({
|
|
|
4132
4141
|
densities: imageDensityOptionsServerSchema
|
|
4133
4142
|
});
|
|
4134
4143
|
|
|
4135
|
-
// ../../core/config.ts
|
|
4136
|
-
var defaultApiHost = "https://api.sfly-sls.magicbook.io";
|
|
4137
|
-
var defaultWebSocketHost = "wss://socket.sfly-sls.magicbook.io";
|
|
4138
|
-
var designRequestTimeout = parseInt("30000"?.toString() || "3000");
|
|
4139
|
-
|
|
4140
4144
|
// ../../core/models/design-request/index.ts
|
|
4141
4145
|
var DesignRequestOptions = {
|
|
4142
4146
|
occasion: occasions,
|
|
@@ -4185,6 +4189,7 @@ var DesignRequest = class {
|
|
|
4185
4189
|
textStickerLevel;
|
|
4186
4190
|
images;
|
|
4187
4191
|
guid;
|
|
4192
|
+
timeout;
|
|
4188
4193
|
updateDesignRequest(designRequestProps) {
|
|
4189
4194
|
Object.assign(this, designRequestProps);
|
|
4190
4195
|
}
|
|
@@ -4203,10 +4208,10 @@ var DesignRequest = class {
|
|
|
4203
4208
|
throw new Error("Design request already submitted");
|
|
4204
4209
|
} else {
|
|
4205
4210
|
submitDesignRequestProps && Object.assign(this, submitDesignRequestProps);
|
|
4206
|
-
this.getProgress();
|
|
4207
4211
|
this.updateDesignRequest(
|
|
4208
4212
|
(await this.client.engineAPI.books.update(this.parentId, this.toBook())).toDesignRequestProps()
|
|
4209
4213
|
);
|
|
4214
|
+
this.getProgress();
|
|
4210
4215
|
this.state = states[1];
|
|
4211
4216
|
return this;
|
|
4212
4217
|
}
|
|
@@ -4245,6 +4250,9 @@ var DesignRequest = class {
|
|
|
4245
4250
|
throw new Error("Design request not ready");
|
|
4246
4251
|
}
|
|
4247
4252
|
}
|
|
4253
|
+
async logEvent(name, data) {
|
|
4254
|
+
return await this.client.engineAPI.events.createBookEvent(this.parentId, name, data);
|
|
4255
|
+
}
|
|
4248
4256
|
async eventHandler(detail, type = "MagicBook.designRequestUpdated") {
|
|
4249
4257
|
const customEvent = new CustomEvent(type, { detail });
|
|
4250
4258
|
if (statesToCloseWS.includes(detail.slug)) {
|
|
@@ -4260,9 +4268,13 @@ var DesignRequest = class {
|
|
|
4260
4268
|
window.dispatchEvent(customEvent);
|
|
4261
4269
|
}
|
|
4262
4270
|
timeoutHandler() {
|
|
4263
|
-
|
|
4264
|
-
|
|
4265
|
-
|
|
4271
|
+
if (this.timeout) {
|
|
4272
|
+
return setTimeout(async () => {
|
|
4273
|
+
await this.eventHandler(timeoutEventDetail);
|
|
4274
|
+
}, this.timeout);
|
|
4275
|
+
} else {
|
|
4276
|
+
throw new Error("Design request timeout not set");
|
|
4277
|
+
}
|
|
4266
4278
|
}
|
|
4267
4279
|
async getProgress() {
|
|
4268
4280
|
let timeout;
|
|
@@ -4389,14 +4401,14 @@ var BooksEndpoints = class {
|
|
|
4389
4401
|
method: "POST"
|
|
4390
4402
|
}
|
|
4391
4403
|
});
|
|
4392
|
-
|
|
4404
|
+
bookPropsSchema.safeParse(res);
|
|
4393
4405
|
return new Book(res);
|
|
4394
4406
|
});
|
|
4395
4407
|
}
|
|
4396
4408
|
retrieve(bookId) {
|
|
4397
4409
|
return handleAsyncFunction(async () => {
|
|
4398
4410
|
const res = await this.engineAPI.fetcher.call({ path: `/v1/books/${bookId}` });
|
|
4399
|
-
|
|
4411
|
+
bookPropsSchema.safeParse(res);
|
|
4400
4412
|
return new Book(res);
|
|
4401
4413
|
});
|
|
4402
4414
|
}
|
|
@@ -4409,7 +4421,7 @@ var BooksEndpoints = class {
|
|
|
4409
4421
|
body: cleanJSON(book)
|
|
4410
4422
|
}
|
|
4411
4423
|
});
|
|
4412
|
-
|
|
4424
|
+
bookPropsSchema.safeParse(res);
|
|
4413
4425
|
return new Book(res);
|
|
4414
4426
|
});
|
|
4415
4427
|
}
|
|
@@ -4419,7 +4431,7 @@ var BooksEndpoints = class {
|
|
|
4419
4431
|
path: `/v1/books/${bookId}/cancel`,
|
|
4420
4432
|
options: { method: "POST" }
|
|
4421
4433
|
});
|
|
4422
|
-
|
|
4434
|
+
bookPropsSchema.safeParse(res);
|
|
4423
4435
|
return new Book(res);
|
|
4424
4436
|
});
|
|
4425
4437
|
}
|
|
@@ -4470,6 +4482,38 @@ var DesignOptionsEndpoints = class {
|
|
|
4470
4482
|
}
|
|
4471
4483
|
};
|
|
4472
4484
|
|
|
4485
|
+
// ../../core/models/event.ts
|
|
4486
|
+
var eventContextSchema = z.record(z.string(), z.unknown()).optional();
|
|
4487
|
+
var eventSchema = z.object({
|
|
4488
|
+
name: z.string(),
|
|
4489
|
+
context: eventContextSchema
|
|
4490
|
+
});
|
|
4491
|
+
|
|
4492
|
+
// ../../core/models/engine-api/endpoints/events.ts
|
|
4493
|
+
var EventsEndpoints = class {
|
|
4494
|
+
// eslint-disable-next-line no-unused-vars
|
|
4495
|
+
constructor(engineAPI) {
|
|
4496
|
+
this.engineAPI = engineAPI;
|
|
4497
|
+
bindThisToFunctions(this);
|
|
4498
|
+
}
|
|
4499
|
+
createBookEvent(bookId, name, data) {
|
|
4500
|
+
return handleAsyncFunction(async () => {
|
|
4501
|
+
const body = {
|
|
4502
|
+
name
|
|
4503
|
+
};
|
|
4504
|
+
data && (body["context"] = data);
|
|
4505
|
+
const res = await this.engineAPI.fetcher.call({
|
|
4506
|
+
path: `/v1/events/book/${bookId}`,
|
|
4507
|
+
options: {
|
|
4508
|
+
method: "POST",
|
|
4509
|
+
body: cleanJSON(body)
|
|
4510
|
+
}
|
|
4511
|
+
});
|
|
4512
|
+
return eventSchema.parse(res);
|
|
4513
|
+
});
|
|
4514
|
+
}
|
|
4515
|
+
};
|
|
4516
|
+
|
|
4473
4517
|
// ../../core/models/fetcher.ts
|
|
4474
4518
|
var baseOptions = {
|
|
4475
4519
|
headers: {
|
|
@@ -4791,11 +4835,16 @@ var EngineAPI = class {
|
|
|
4791
4835
|
}
|
|
4792
4836
|
books = new BooksEndpoints(this);
|
|
4793
4837
|
designOptions = new DesignOptionsEndpoints(this);
|
|
4794
|
-
|
|
4838
|
+
events = new EventsEndpoints(this);
|
|
4795
4839
|
images = new ImagesEndpoints(this);
|
|
4840
|
+
storyboardItems = new StoryboardItemsEndpoints(this);
|
|
4796
4841
|
spreads = new SpreadsEndpoints(this);
|
|
4797
4842
|
};
|
|
4798
4843
|
|
|
4844
|
+
// ../../core/config.ts
|
|
4845
|
+
var defaultApiHost = "https://api.dev-sls.magicbook.io";
|
|
4846
|
+
var defaultWebSocketHost = "wss://socket.dev-sls.magicbook.io";
|
|
4847
|
+
|
|
4799
4848
|
// ../../core/models/client.ts
|
|
4800
4849
|
var MagicBookClient = class {
|
|
4801
4850
|
constructor(apiKey, apiHost = defaultApiHost, webSocketHost = defaultWebSocketHost) {
|
|
@@ -4811,6 +4860,8 @@ var MagicBookClient = class {
|
|
|
4811
4860
|
}
|
|
4812
4861
|
};
|
|
4813
4862
|
export {
|
|
4863
|
+
Book,
|
|
4864
|
+
BookDesignRequest,
|
|
4814
4865
|
DesignRequest,
|
|
4815
4866
|
DesignRequestOptions,
|
|
4816
4867
|
ImageServer,
|
|
@@ -4818,6 +4869,8 @@ export {
|
|
|
4818
4869
|
MagicBookClient,
|
|
4819
4870
|
assetSchema,
|
|
4820
4871
|
bookCreationRequestSchema,
|
|
4872
|
+
bookDesignRequestSchema,
|
|
4873
|
+
bookPropsSchema,
|
|
4821
4874
|
bookSizes,
|
|
4822
4875
|
cancelledEventDetail,
|
|
4823
4876
|
canvasSchema,
|