@magiclabs.ai/magicbook-client 0.6.13-canary → 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/README.md
CHANGED
|
@@ -94,14 +94,19 @@ After submitting you can set a GUID to the design request.
|
|
|
94
94
|
await designRequest.setGuid('a9ccb406-015a-47df-bb59-ea171b8617ca')
|
|
95
95
|
```
|
|
96
96
|
|
|
97
|
-
|
|
97
|
+
Once the design request is complete, retrieve it in JSON format.
|
|
98
98
|
|
|
99
99
|
```ts
|
|
100
100
|
await designRequest.getJSON()
|
|
101
101
|
```
|
|
102
102
|
|
|
103
|
-
|
|
103
|
+
When a user performs a specific action, log it by calling the `logEvent` method.
|
|
104
104
|
|
|
105
|
+
```ts
|
|
106
|
+
await designRequest.logEvent('book.viewed', data)
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
___
|
|
105
110
|
|
|
106
111
|
## Example
|
|
107
112
|
|
package/index.cjs
CHANGED
|
@@ -20,6 +20,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var src_exports = {};
|
|
22
22
|
__export(src_exports, {
|
|
23
|
+
Book: () => Book,
|
|
24
|
+
BookDesignRequest: () => BookDesignRequest,
|
|
23
25
|
DesignRequest: () => DesignRequest,
|
|
24
26
|
DesignRequestOptions: () => DesignRequestOptions,
|
|
25
27
|
ImageServer: () => ImageServer,
|
|
@@ -27,6 +29,8 @@ __export(src_exports, {
|
|
|
27
29
|
MagicBookClient: () => MagicBookClient,
|
|
28
30
|
assetSchema: () => assetSchema,
|
|
29
31
|
bookCreationRequestSchema: () => bookCreationRequestSchema,
|
|
32
|
+
bookDesignRequestSchema: () => bookDesignRequestSchema,
|
|
33
|
+
bookPropsSchema: () => bookPropsSchema,
|
|
30
34
|
bookSizes: () => bookSizes,
|
|
31
35
|
cancelledEventDetail: () => cancelledEventDetail,
|
|
32
36
|
canvasSchema: () => canvasSchema,
|
|
@@ -4073,14 +4077,15 @@ var bookDesignRequestSchema = z.object({
|
|
|
4073
4077
|
embellishment_level: z.enum(embellishmentLevels),
|
|
4074
4078
|
text_sticker_level: z.enum(textStickerLevels)
|
|
4075
4079
|
});
|
|
4076
|
-
var
|
|
4080
|
+
var bookPropsSchema = z.object({
|
|
4077
4081
|
id: z.string().optional(),
|
|
4078
4082
|
title: z.string(),
|
|
4079
4083
|
subtitle: z.string().optional(),
|
|
4080
4084
|
design_request: bookDesignRequestSchema,
|
|
4081
4085
|
state: z.enum(states).optional(),
|
|
4082
4086
|
guid: z.string().optional(),
|
|
4083
|
-
cancelled_at: z.string().optional()
|
|
4087
|
+
cancelled_at: z.string().optional(),
|
|
4088
|
+
mb_client_timeout: z.number().optional()
|
|
4084
4089
|
});
|
|
4085
4090
|
var Book = class {
|
|
4086
4091
|
id;
|
|
@@ -4090,6 +4095,7 @@ var Book = class {
|
|
|
4090
4095
|
state;
|
|
4091
4096
|
guid;
|
|
4092
4097
|
cancelled_at;
|
|
4098
|
+
timeout;
|
|
4093
4099
|
constructor(props) {
|
|
4094
4100
|
this.id = props.id || "";
|
|
4095
4101
|
this.title = props.title;
|
|
@@ -4098,6 +4104,7 @@ var Book = class {
|
|
|
4098
4104
|
this.state = props.state;
|
|
4099
4105
|
this.guid = props.guid;
|
|
4100
4106
|
this.cancelled_at = props.cancelled_at;
|
|
4107
|
+
this.timeout = props.mb_client_timeout ? props.mb_client_timeout * 1e3 : void 0;
|
|
4101
4108
|
}
|
|
4102
4109
|
toDesignRequestProps() {
|
|
4103
4110
|
const props = { ...this, ...this.design_request };
|
|
@@ -4105,6 +4112,12 @@ var Book = class {
|
|
|
4105
4112
|
delete props.design_request;
|
|
4106
4113
|
return snakeCaseObjectKeysToCamelCase(props);
|
|
4107
4114
|
}
|
|
4115
|
+
toBookProps() {
|
|
4116
|
+
return {
|
|
4117
|
+
...this,
|
|
4118
|
+
mb_client_timeout: this.timeout ? this.timeout / 1e3 : void 0
|
|
4119
|
+
};
|
|
4120
|
+
}
|
|
4108
4121
|
};
|
|
4109
4122
|
|
|
4110
4123
|
// ../../core/models/design-request/image.ts
|
|
@@ -4195,11 +4208,6 @@ var designOptionsServerSchema = z.object({
|
|
|
4195
4208
|
densities: imageDensityOptionsServerSchema
|
|
4196
4209
|
});
|
|
4197
4210
|
|
|
4198
|
-
// ../../core/config.ts
|
|
4199
|
-
var defaultApiHost = "https://api.dev-sls.magicbook.io";
|
|
4200
|
-
var defaultWebSocketHost = "wss://socket.dev-sls.magicbook.io";
|
|
4201
|
-
var designRequestTimeout = parseInt("30000"?.toString() || "3000");
|
|
4202
|
-
|
|
4203
4211
|
// ../../core/models/design-request/index.ts
|
|
4204
4212
|
var DesignRequestOptions = {
|
|
4205
4213
|
occasion: occasions,
|
|
@@ -4248,6 +4256,7 @@ var DesignRequest = class {
|
|
|
4248
4256
|
textStickerLevel;
|
|
4249
4257
|
images;
|
|
4250
4258
|
guid;
|
|
4259
|
+
timeout;
|
|
4251
4260
|
updateDesignRequest(designRequestProps) {
|
|
4252
4261
|
Object.assign(this, designRequestProps);
|
|
4253
4262
|
}
|
|
@@ -4266,10 +4275,10 @@ var DesignRequest = class {
|
|
|
4266
4275
|
throw new Error("Design request already submitted");
|
|
4267
4276
|
} else {
|
|
4268
4277
|
submitDesignRequestProps && Object.assign(this, submitDesignRequestProps);
|
|
4269
|
-
this.getProgress();
|
|
4270
4278
|
this.updateDesignRequest(
|
|
4271
4279
|
(await this.client.engineAPI.books.update(this.parentId, this.toBook())).toDesignRequestProps()
|
|
4272
4280
|
);
|
|
4281
|
+
this.getProgress();
|
|
4273
4282
|
this.state = states[1];
|
|
4274
4283
|
return this;
|
|
4275
4284
|
}
|
|
@@ -4308,6 +4317,9 @@ var DesignRequest = class {
|
|
|
4308
4317
|
throw new Error("Design request not ready");
|
|
4309
4318
|
}
|
|
4310
4319
|
}
|
|
4320
|
+
async logEvent(name, data) {
|
|
4321
|
+
return await this.client.engineAPI.events.createBookEvent(this.parentId, name, data);
|
|
4322
|
+
}
|
|
4311
4323
|
async eventHandler(detail, type = "MagicBook.designRequestUpdated") {
|
|
4312
4324
|
const customEvent = new CustomEvent(type, { detail });
|
|
4313
4325
|
if (statesToCloseWS.includes(detail.slug)) {
|
|
@@ -4323,9 +4335,13 @@ var DesignRequest = class {
|
|
|
4323
4335
|
window.dispatchEvent(customEvent);
|
|
4324
4336
|
}
|
|
4325
4337
|
timeoutHandler() {
|
|
4326
|
-
|
|
4327
|
-
|
|
4328
|
-
|
|
4338
|
+
if (this.timeout) {
|
|
4339
|
+
return setTimeout(async () => {
|
|
4340
|
+
await this.eventHandler(timeoutEventDetail);
|
|
4341
|
+
}, this.timeout);
|
|
4342
|
+
} else {
|
|
4343
|
+
throw new Error("Design request timeout not set");
|
|
4344
|
+
}
|
|
4329
4345
|
}
|
|
4330
4346
|
async getProgress() {
|
|
4331
4347
|
let timeout;
|
|
@@ -4452,14 +4468,14 @@ var BooksEndpoints = class {
|
|
|
4452
4468
|
method: "POST"
|
|
4453
4469
|
}
|
|
4454
4470
|
});
|
|
4455
|
-
|
|
4471
|
+
bookPropsSchema.safeParse(res);
|
|
4456
4472
|
return new Book(res);
|
|
4457
4473
|
});
|
|
4458
4474
|
}
|
|
4459
4475
|
retrieve(bookId) {
|
|
4460
4476
|
return handleAsyncFunction(async () => {
|
|
4461
4477
|
const res = await this.engineAPI.fetcher.call({ path: `/v1/books/${bookId}` });
|
|
4462
|
-
|
|
4478
|
+
bookPropsSchema.safeParse(res);
|
|
4463
4479
|
return new Book(res);
|
|
4464
4480
|
});
|
|
4465
4481
|
}
|
|
@@ -4472,7 +4488,7 @@ var BooksEndpoints = class {
|
|
|
4472
4488
|
body: cleanJSON(book)
|
|
4473
4489
|
}
|
|
4474
4490
|
});
|
|
4475
|
-
|
|
4491
|
+
bookPropsSchema.safeParse(res);
|
|
4476
4492
|
return new Book(res);
|
|
4477
4493
|
});
|
|
4478
4494
|
}
|
|
@@ -4482,7 +4498,7 @@ var BooksEndpoints = class {
|
|
|
4482
4498
|
path: `/v1/books/${bookId}/cancel`,
|
|
4483
4499
|
options: { method: "POST" }
|
|
4484
4500
|
});
|
|
4485
|
-
|
|
4501
|
+
bookPropsSchema.safeParse(res);
|
|
4486
4502
|
return new Book(res);
|
|
4487
4503
|
});
|
|
4488
4504
|
}
|
|
@@ -4533,6 +4549,38 @@ var DesignOptionsEndpoints = class {
|
|
|
4533
4549
|
}
|
|
4534
4550
|
};
|
|
4535
4551
|
|
|
4552
|
+
// ../../core/models/event.ts
|
|
4553
|
+
var eventContextSchema = z.record(z.string(), z.unknown()).optional();
|
|
4554
|
+
var eventSchema = z.object({
|
|
4555
|
+
name: z.string(),
|
|
4556
|
+
context: eventContextSchema
|
|
4557
|
+
});
|
|
4558
|
+
|
|
4559
|
+
// ../../core/models/engine-api/endpoints/events.ts
|
|
4560
|
+
var EventsEndpoints = class {
|
|
4561
|
+
// eslint-disable-next-line no-unused-vars
|
|
4562
|
+
constructor(engineAPI) {
|
|
4563
|
+
this.engineAPI = engineAPI;
|
|
4564
|
+
bindThisToFunctions(this);
|
|
4565
|
+
}
|
|
4566
|
+
createBookEvent(bookId, name, data) {
|
|
4567
|
+
return handleAsyncFunction(async () => {
|
|
4568
|
+
const body = {
|
|
4569
|
+
name
|
|
4570
|
+
};
|
|
4571
|
+
data && (body["context"] = data);
|
|
4572
|
+
const res = await this.engineAPI.fetcher.call({
|
|
4573
|
+
path: `/v1/events/book/${bookId}`,
|
|
4574
|
+
options: {
|
|
4575
|
+
method: "POST",
|
|
4576
|
+
body: cleanJSON(body)
|
|
4577
|
+
}
|
|
4578
|
+
});
|
|
4579
|
+
return eventSchema.parse(res);
|
|
4580
|
+
});
|
|
4581
|
+
}
|
|
4582
|
+
};
|
|
4583
|
+
|
|
4536
4584
|
// ../../core/models/fetcher.ts
|
|
4537
4585
|
var baseOptions = {
|
|
4538
4586
|
headers: {
|
|
@@ -4854,11 +4902,16 @@ var EngineAPI = class {
|
|
|
4854
4902
|
}
|
|
4855
4903
|
books = new BooksEndpoints(this);
|
|
4856
4904
|
designOptions = new DesignOptionsEndpoints(this);
|
|
4857
|
-
|
|
4905
|
+
events = new EventsEndpoints(this);
|
|
4858
4906
|
images = new ImagesEndpoints(this);
|
|
4907
|
+
storyboardItems = new StoryboardItemsEndpoints(this);
|
|
4859
4908
|
spreads = new SpreadsEndpoints(this);
|
|
4860
4909
|
};
|
|
4861
4910
|
|
|
4911
|
+
// ../../core/config.ts
|
|
4912
|
+
var defaultApiHost = "https://api.dev-sls.magicbook.io";
|
|
4913
|
+
var defaultWebSocketHost = "wss://socket.dev-sls.magicbook.io";
|
|
4914
|
+
|
|
4862
4915
|
// ../../core/models/client.ts
|
|
4863
4916
|
var MagicBookClient = class {
|
|
4864
4917
|
constructor(apiKey, apiHost = defaultApiHost, webSocketHost = defaultWebSocketHost) {
|
|
@@ -4875,6 +4928,8 @@ var MagicBookClient = class {
|
|
|
4875
4928
|
};
|
|
4876
4929
|
// Annotate the CommonJS export names for ESM import in node:
|
|
4877
4930
|
0 && (module.exports = {
|
|
4931
|
+
Book,
|
|
4932
|
+
BookDesignRequest,
|
|
4878
4933
|
DesignRequest,
|
|
4879
4934
|
DesignRequestOptions,
|
|
4880
4935
|
ImageServer,
|
|
@@ -4882,6 +4937,8 @@ var MagicBookClient = class {
|
|
|
4882
4937
|
MagicBookClient,
|
|
4883
4938
|
assetSchema,
|
|
4884
4939
|
bookCreationRequestSchema,
|
|
4940
|
+
bookDesignRequestSchema,
|
|
4941
|
+
bookPropsSchema,
|
|
4885
4942
|
bookSizes,
|
|
4886
4943
|
cancelledEventDetail,
|
|
4887
4944
|
canvasSchema,
|