@mynthio/sdk 0.0.50 → 0.0.51
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 +2 -16
- package/dist/index.d.ts +6 -1
- package/dist/index.js +8 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1049,7 +1049,8 @@ try {
|
|
|
1049
1049
|
} catch (error) {
|
|
1050
1050
|
if (error instanceof MynthAPIError) {
|
|
1051
1051
|
// `message` says what to fix. On a validation_error, `issues` lists each invalid field.
|
|
1052
|
-
|
|
1052
|
+
// On public_access_token_failed, the task was created: follow `taskId` rather than resending.
|
|
1053
|
+
console.error(error.status, error.code, error.message, error.issues, error.taskId);
|
|
1053
1054
|
} else if (error instanceof TaskAsyncTimeoutError) {
|
|
1054
1055
|
console.error("Task polling timed out");
|
|
1055
1056
|
} else if (error instanceof TaskAsyncUnauthorizedError) {
|
|
@@ -1064,21 +1065,6 @@ try {
|
|
|
1064
1065
|
}
|
|
1065
1066
|
```
|
|
1066
1067
|
|
|
1067
|
-
## Migrating from 0.0.49
|
|
1068
|
-
|
|
1069
|
-
0.0.50 follows the stable API, which changed in one go. Nothing in it is backward compatible:
|
|
1070
|
-
|
|
1071
|
-
- Request fields are snake_case, and the API now rejects a field it does not know. `size.aspectRatio` is `size.aspect_ratio`.
|
|
1072
|
-
- `access: { pat: { enabled } }` is `generate_public_access_token: true`, and it now defaults to `false`: pass it to get `taskAsync.access.publicAccessToken` from `generateAsync()`, `removeBackgroundAsync()`, `upscaleAsync()` and `video.generateAsync()`.
|
|
1073
|
-
- `webhook.dashboard` is `webhook.registered`.
|
|
1074
|
-
- `MynthAPIError.code` and every task error code are lowercase: `validation_error`, `insufficient_balance`, `provider_error`.
|
|
1075
|
-
- API data the SDK returns as is is snake_case: `MynthSDKTypes.TaskData` (`user_id`, `api_key_id`, `created_at`, `updated_at`), the model catalog (`display_name`, `per_image`, `per_second`, `max_total`) and `video.estimate()` (`estimated_cost`, `estimate_kind`).
|
|
1076
|
-
- A video's `url` can be `null`, like an image's. `result.urls` skips it.
|
|
1077
|
-
- Webhooks follow Standard Webhooks. Every registered webhook got a new `whsec_...` signing secret: copy it from the dashboard into `MYNTH_WEBHOOK_SECRET`. `X-Mynth-Event`, `X-Mynth-Delivery` and `X-Mynth-Signature` are gone; deliveries carry `webhook-id`, `webhook-timestamp` and `webhook-signature`.
|
|
1078
|
-
- The webhook body is an event, `{ id, type, timestamp, data }`, with the task in `data`. `MynthSDKTypes.WebhookPayload` and its variants are replaced by `MynthSDKTypes.WebhookEvent`, and `verifyWebhook()` returns one.
|
|
1079
|
-
- Webhook callbacks get `{ event }` in their last argument instead of `deliveryId`. Deduplicate on `event.id`.
|
|
1080
|
-
- Unsigned deliveries to a custom URL are refused unless the helper gets the `unsigned` option.
|
|
1081
|
-
|
|
1082
1068
|
## Documentation
|
|
1083
1069
|
|
|
1084
1070
|
For product documentation and API guides, visit [mynth.io/docs](https://mynth.io/docs).
|
package/dist/index.d.ts
CHANGED
|
@@ -13,7 +13,12 @@ export declare class MynthAPIError extends Error {
|
|
|
13
13
|
* `message` already states all of them.
|
|
14
14
|
*/
|
|
15
15
|
readonly issues?: ReadonlyArray<MynthAPIErrorIssue> | undefined;
|
|
16
|
-
|
|
16
|
+
/**
|
|
17
|
+
* The task the request created before it failed, when `code` is
|
|
18
|
+
* `public_access_token_failed`. It will run: follow it rather than resending.
|
|
19
|
+
*/
|
|
20
|
+
readonly taskId?: string | undefined;
|
|
21
|
+
constructor(message: string, status: number, code?: string, issues?: ReadonlyArray<MynthAPIErrorIssue>, taskId?: string);
|
|
17
22
|
}
|
|
18
23
|
type MynthAPIErrorIssue = {
|
|
19
24
|
/** Where the problem is, e.g. `["size", "scale"]`. Empty for the body as a whole. */
|
package/dist/index.js
CHANGED
|
@@ -407,18 +407,24 @@ var MynthAPIError = class extends Error {
|
|
|
407
407
|
* `message` already states all of them.
|
|
408
408
|
*/
|
|
409
409
|
issues;
|
|
410
|
-
|
|
410
|
+
/**
|
|
411
|
+
* The task the request created before it failed, when `code` is
|
|
412
|
+
* `public_access_token_failed`. It will run: follow it rather than resending.
|
|
413
|
+
*/
|
|
414
|
+
taskId;
|
|
415
|
+
constructor(message, status, code, issues, taskId) {
|
|
411
416
|
super(message);
|
|
412
417
|
this.name = "MynthAPIError";
|
|
413
418
|
this.status = status;
|
|
414
419
|
this.code = code;
|
|
415
420
|
this.issues = issues;
|
|
421
|
+
this.taskId = taskId;
|
|
416
422
|
}
|
|
417
423
|
};
|
|
418
424
|
function createApiError(data, status) {
|
|
419
425
|
const body = typeof data === "object" && data !== null ? data : {};
|
|
420
426
|
const error = typeof body.error === "object" && body.error !== null ? body.error : {};
|
|
421
|
-
return new MynthAPIError(typeof error.message === "string" && error.message || `Request failed with status ${status}`, status, typeof error.code === "string" ? error.code : void 0, Array.isArray(error.issues) ? error.issues : void 0);
|
|
427
|
+
return new MynthAPIError(typeof error.message === "string" && error.message || `Request failed with status ${status}`, status, typeof error.code === "string" ? error.code : void 0, Array.isArray(error.issues) ? error.issues : void 0, typeof error.task_id === "string" ? error.task_id : void 0);
|
|
422
428
|
}
|
|
423
429
|
/** An error body that is not JSON (a proxy's HTML page, say) still yields an API error. */
|
|
424
430
|
async function readErrorBody(response) {
|