magic-hour 0.35.0 → 0.37.0
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 +208 -10
- package/dist/client.js +2 -2
- package/dist/core/api-error.d.ts +1 -1
- package/dist/core/api-promise.d.ts +2 -2
- package/dist/core/api-promise.js +2 -1
- package/dist/core/auth.d.ts +1 -1
- package/dist/core/auth.js +1 -1
- package/dist/core/binary-response.d.ts +1 -1
- package/dist/core/core-client.d.ts +5 -5
- package/dist/core/core-client.js +2 -5
- package/dist/core/form-data.d.ts +1 -1
- package/dist/core/zod.d.ts +1 -1
- package/dist/core/zod.js +1 -1
- package/dist/environment.d.ts +1 -1
- package/dist/environment.js +1 -1
- package/dist/helpers/download.d.ts +5 -0
- package/dist/helpers/download.js +88 -0
- package/dist/helpers/generate-type.d.ts +51 -0
- package/dist/helpers/generate-type.js +2 -0
- package/dist/helpers/sleep.d.ts +4 -0
- package/dist/helpers/sleep.js +9 -0
- package/dist/logger.d.ts +48 -0
- package/dist/logger.js +97 -0
- package/dist/resources/v1/ai-clothes-changer/request-types.d.ts +1 -1
- package/dist/resources/v1/ai-clothes-changer/request-types.js +1 -1
- package/dist/resources/v1/ai-clothes-changer/resource-client.d.ts +50 -0
- package/dist/resources/v1/ai-clothes-changer/resource-client.js +75 -0
- package/dist/resources/v1/ai-face-editor/request-types.d.ts +1 -1
- package/dist/resources/v1/ai-face-editor/request-types.js +1 -1
- package/dist/resources/v1/ai-face-editor/resource-client.d.ts +55 -0
- package/dist/resources/v1/ai-face-editor/resource-client.js +85 -0
- package/dist/resources/v1/ai-gif-generator/request-types.d.ts +1 -1
- package/dist/resources/v1/ai-gif-generator/request-types.js +1 -1
- package/dist/resources/v1/ai-gif-generator/resource-client.d.ts +29 -0
- package/dist/resources/v1/ai-gif-generator/resource-client.js +60 -0
- package/dist/resources/v1/ai-headshot-generator/request-types.d.ts +1 -1
- package/dist/resources/v1/ai-headshot-generator/request-types.js +1 -1
- package/dist/resources/v1/ai-headshot-generator/resource-client.d.ts +38 -0
- package/dist/resources/v1/ai-headshot-generator/resource-client.js +68 -0
- package/dist/resources/v1/ai-image-editor/request-types.d.ts +1 -1
- package/dist/resources/v1/ai-image-editor/request-types.js +1 -1
- package/dist/resources/v1/ai-image-editor/resource-client.d.ts +39 -0
- package/dist/resources/v1/ai-image-editor/resource-client.js +69 -0
- package/dist/resources/v1/ai-image-generator/request-types.d.ts +1 -1
- package/dist/resources/v1/ai-image-generator/request-types.js +1 -1
- package/dist/resources/v1/ai-image-generator/resource-client.d.ts +31 -0
- package/dist/resources/v1/ai-image-generator/resource-client.js +62 -0
- package/dist/resources/v1/ai-image-upscaler/request-types.d.ts +1 -1
- package/dist/resources/v1/ai-image-upscaler/request-types.js +1 -1
- package/dist/resources/v1/ai-image-upscaler/resource-client.d.ts +40 -0
- package/dist/resources/v1/ai-image-upscaler/resource-client.js +70 -0
- package/dist/resources/v1/ai-meme-generator/request-types.d.ts +1 -1
- package/dist/resources/v1/ai-meme-generator/request-types.js +1 -1
- package/dist/resources/v1/ai-meme-generator/resource-client.d.ts +33 -0
- package/dist/resources/v1/ai-meme-generator/resource-client.js +64 -0
- package/dist/resources/v1/ai-photo-editor/request-types.d.ts +1 -1
- package/dist/resources/v1/ai-photo-editor/request-types.js +1 -1
- package/dist/resources/v1/ai-photo-editor/resource-client.d.ts +49 -0
- package/dist/resources/v1/ai-photo-editor/resource-client.js +79 -0
- package/dist/resources/v1/ai-qr-code-generator/request-types.d.ts +1 -1
- package/dist/resources/v1/ai-qr-code-generator/request-types.js +1 -1
- package/dist/resources/v1/ai-qr-code-generator/resource-client.d.ts +30 -0
- package/dist/resources/v1/ai-qr-code-generator/resource-client.js +61 -0
- package/dist/resources/v1/ai-talking-photo/request-types.d.ts +1 -1
- package/dist/resources/v1/ai-talking-photo/request-types.js +1 -1
- package/dist/resources/v1/ai-talking-photo/resource-client.d.ts +51 -0
- package/dist/resources/v1/ai-talking-photo/resource-client.js +76 -0
- package/dist/resources/v1/animation/request-types.d.ts +1 -1
- package/dist/resources/v1/animation/request-types.js +1 -1
- package/dist/resources/v1/animation/resource-client.d.ts +61 -0
- package/dist/resources/v1/animation/resource-client.js +98 -0
- package/dist/resources/v1/auto-subtitle-generator/request-types.d.ts +1 -1
- package/dist/resources/v1/auto-subtitle-generator/request-types.js +1 -1
- package/dist/resources/v1/auto-subtitle-generator/resource-client.d.ts +41 -0
- package/dist/resources/v1/auto-subtitle-generator/resource-client.js +71 -0
- package/dist/resources/v1/face-detection/request-types.d.ts +1 -1
- package/dist/resources/v1/face-detection/request-types.js +1 -1
- package/dist/resources/v1/face-detection/resource-client.d.ts +30 -0
- package/dist/resources/v1/face-detection/resource-client.js +75 -0
- package/dist/resources/v1/face-swap/request-types.d.ts +7 -1
- package/dist/resources/v1/face-swap/request-types.js +6 -1
- package/dist/resources/v1/face-swap/resource-client.d.ts +77 -0
- package/dist/resources/v1/face-swap/resource-client.js +125 -0
- package/dist/resources/v1/face-swap-photo/request-types.d.ts +1 -1
- package/dist/resources/v1/face-swap-photo/request-types.js +1 -1
- package/dist/resources/v1/face-swap-photo/resource-client.d.ts +73 -0
- package/dist/resources/v1/face-swap-photo/resource-client.js +117 -0
- package/dist/resources/v1/files/resource-client.d.ts +40 -0
- package/dist/resources/v1/files/resource-client.js +236 -0
- package/dist/resources/v1/files/resource-client.test.d.ts +1 -0
- package/dist/resources/v1/files/resource-client.test.js +422 -0
- package/dist/resources/v1/files/upload-urls/request-types.d.ts +1 -1
- package/dist/resources/v1/files/upload-urls/request-types.js +1 -1
- package/dist/resources/v1/image-background-remover/request-types.d.ts +1 -1
- package/dist/resources/v1/image-background-remover/request-types.js +1 -1
- package/dist/resources/v1/image-background-remover/resource-client.d.ts +49 -0
- package/dist/resources/v1/image-background-remover/resource-client.js +82 -0
- package/dist/resources/v1/image-projects/request-types.js +1 -1
- package/dist/resources/v1/image-projects/resource-client.d.ts +22 -0
- package/dist/resources/v1/image-projects/resource-client.js +68 -0
- package/dist/resources/v1/image-projects/resource-client.test.d.ts +1 -0
- package/dist/resources/v1/image-projects/resource-client.test.js +538 -0
- package/dist/resources/v1/image-to-video/request-types.d.ts +1 -1
- package/dist/resources/v1/image-to-video/request-types.js +1 -1
- package/dist/resources/v1/image-to-video/resource-client.d.ts +40 -0
- package/dist/resources/v1/image-to-video/resource-client.js +70 -0
- package/dist/resources/v1/lip-sync/request-types.d.ts +1 -1
- package/dist/resources/v1/lip-sync/request-types.js +1 -1
- package/dist/resources/v1/lip-sync/resource-client.d.ts +53 -0
- package/dist/resources/v1/lip-sync/resource-client.js +84 -0
- package/dist/resources/v1/photo-colorizer/request-types.d.ts +1 -1
- package/dist/resources/v1/photo-colorizer/request-types.js +1 -1
- package/dist/resources/v1/photo-colorizer/resource-client.d.ts +38 -0
- package/dist/resources/v1/photo-colorizer/resource-client.js +68 -0
- package/dist/resources/v1/resource-client.js +3 -3
- package/dist/resources/v1/text-to-video/request-types.d.ts +1 -1
- package/dist/resources/v1/text-to-video/request-types.js +1 -1
- package/dist/resources/v1/text-to-video/resource-client.d.ts +32 -0
- package/dist/resources/v1/text-to-video/resource-client.js +63 -0
- package/dist/resources/v1/video-projects/request-types.js +1 -1
- package/dist/resources/v1/video-projects/resource-client.d.ts +22 -0
- package/dist/resources/v1/video-projects/resource-client.js +68 -0
- package/dist/resources/v1/video-projects/resource-client.test.d.ts +1 -0
- package/dist/resources/v1/video-projects/resource-client.test.js +713 -0
- package/dist/resources/v1/video-to-video/request-types.d.ts +1 -1
- package/dist/resources/v1/video-to-video/request-types.js +1 -1
- package/dist/resources/v1/video-to-video/resource-client.d.ts +48 -0
- package/dist/resources/v1/video-to-video/resource-client.js +84 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/v1-ai-clothes-changer-create-body-assets.js +1 -1
- package/dist/types/v1-ai-clothes-changer-create-body.d.ts +1 -1
- package/dist/types/v1-ai-clothes-changer-create-body.js +2 -2
- package/dist/types/v1-ai-clothes-changer-create-response.js +1 -1
- package/dist/types/v1-ai-face-editor-create-body-assets.js +1 -1
- package/dist/types/v1-ai-face-editor-create-body-style.js +1 -1
- package/dist/types/v1-ai-face-editor-create-body.d.ts +1 -1
- package/dist/types/v1-ai-face-editor-create-body.js +2 -2
- package/dist/types/v1-ai-face-editor-create-response.js +1 -1
- package/dist/types/v1-ai-gif-generator-create-body-style.js +1 -1
- package/dist/types/v1-ai-gif-generator-create-body.d.ts +1 -1
- package/dist/types/v1-ai-gif-generator-create-body.js +2 -2
- package/dist/types/v1-ai-gif-generator-create-response.js +1 -1
- package/dist/types/v1-ai-headshot-generator-create-body-assets.js +1 -1
- package/dist/types/v1-ai-headshot-generator-create-body-style.js +1 -1
- package/dist/types/v1-ai-headshot-generator-create-body.d.ts +1 -1
- package/dist/types/v1-ai-headshot-generator-create-body.js +2 -2
- package/dist/types/v1-ai-headshot-generator-create-response.js +1 -1
- package/dist/types/v1-ai-image-editor-create-body-assets.js +1 -1
- package/dist/types/v1-ai-image-editor-create-body-style.js +1 -1
- package/dist/types/v1-ai-image-editor-create-body.d.ts +1 -1
- package/dist/types/v1-ai-image-editor-create-body.js +2 -2
- package/dist/types/v1-ai-image-editor-create-response.js +1 -1
- package/dist/types/v1-ai-image-generator-create-body-style.js +1 -1
- package/dist/types/v1-ai-image-generator-create-body.d.ts +1 -1
- package/dist/types/v1-ai-image-generator-create-body.js +2 -2
- package/dist/types/v1-ai-image-generator-create-response.js +1 -1
- package/dist/types/v1-ai-image-upscaler-create-body-assets.js +1 -1
- package/dist/types/v1-ai-image-upscaler-create-body-style.js +1 -1
- package/dist/types/v1-ai-image-upscaler-create-body.d.ts +1 -1
- package/dist/types/v1-ai-image-upscaler-create-body.js +2 -2
- package/dist/types/v1-ai-image-upscaler-create-response.js +1 -1
- package/dist/types/v1-ai-meme-generator-create-body-style.js +1 -1
- package/dist/types/v1-ai-meme-generator-create-body.d.ts +1 -1
- package/dist/types/v1-ai-meme-generator-create-body.js +2 -2
- package/dist/types/v1-ai-meme-generator-create-response.js +1 -1
- package/dist/types/v1-ai-photo-editor-create-body-assets.js +1 -1
- package/dist/types/v1-ai-photo-editor-create-body-style.js +1 -1
- package/dist/types/v1-ai-photo-editor-create-body.d.ts +1 -1
- package/dist/types/v1-ai-photo-editor-create-body.js +2 -2
- package/dist/types/v1-ai-photo-editor-create-response.js +1 -1
- package/dist/types/v1-ai-qr-code-generator-create-body-style.js +1 -1
- package/dist/types/v1-ai-qr-code-generator-create-body.d.ts +1 -1
- package/dist/types/v1-ai-qr-code-generator-create-body.js +2 -2
- package/dist/types/v1-ai-qr-code-generator-create-response.js +1 -1
- package/dist/types/v1-ai-talking-photo-create-body-assets.js +1 -1
- package/dist/types/v1-ai-talking-photo-create-body-style.js +1 -1
- package/dist/types/v1-ai-talking-photo-create-body.d.ts +1 -1
- package/dist/types/v1-ai-talking-photo-create-body.js +2 -2
- package/dist/types/v1-ai-talking-photo-create-response.js +1 -1
- package/dist/types/v1-animation-create-body-assets.js +1 -1
- package/dist/types/v1-animation-create-body-style.js +1 -1
- package/dist/types/v1-animation-create-body.d.ts +1 -1
- package/dist/types/v1-animation-create-body.js +2 -2
- package/dist/types/v1-animation-create-response.js +1 -1
- package/dist/types/v1-auto-subtitle-generator-create-body-assets.js +1 -1
- package/dist/types/v1-auto-subtitle-generator-create-body-style-custom-config.js +1 -1
- package/dist/types/v1-auto-subtitle-generator-create-body-style.d.ts +1 -1
- package/dist/types/v1-auto-subtitle-generator-create-body-style.js +2 -2
- package/dist/types/v1-auto-subtitle-generator-create-body.d.ts +1 -1
- package/dist/types/v1-auto-subtitle-generator-create-body.js +2 -2
- package/dist/types/v1-auto-subtitle-generator-create-response.js +1 -1
- package/dist/types/v1-face-detection-create-body-assets.js +1 -1
- package/dist/types/v1-face-detection-create-body.d.ts +1 -1
- package/dist/types/v1-face-detection-create-body.js +2 -2
- package/dist/types/v1-face-detection-create-response.js +1 -1
- package/dist/types/v1-face-detection-get-response-faces-item.js +1 -1
- package/dist/types/v1-face-detection-get-response.d.ts +1 -1
- package/dist/types/v1-face-detection-get-response.js +2 -2
- package/dist/types/v1-face-swap-create-body-assets-face-mappings-item.js +1 -1
- package/dist/types/v1-face-swap-create-body-assets.d.ts +1 -1
- package/dist/types/v1-face-swap-create-body-assets.js +2 -2
- package/dist/types/v1-face-swap-create-body-style-version-enum.d.ts +6 -0
- package/dist/types/v1-face-swap-create-body-style-version-enum.js +2 -0
- package/dist/types/v1-face-swap-create-body-style.d.ts +24 -0
- package/dist/types/v1-face-swap-create-body-style.js +67 -0
- package/dist/types/v1-face-swap-create-body.d.ts +7 -1
- package/dist/types/v1-face-swap-create-body.js +7 -2
- package/dist/types/v1-face-swap-create-response.js +1 -1
- package/dist/types/v1-face-swap-photo-create-body-assets-face-mappings-item.js +1 -1
- package/dist/types/v1-face-swap-photo-create-body-assets.d.ts +1 -1
- package/dist/types/v1-face-swap-photo-create-body-assets.js +2 -2
- package/dist/types/v1-face-swap-photo-create-body.d.ts +1 -1
- package/dist/types/v1-face-swap-photo-create-body.js +2 -2
- package/dist/types/v1-face-swap-photo-create-response.js +1 -1
- package/dist/types/v1-files-upload-urls-create-body-items-item.js +1 -1
- package/dist/types/v1-files-upload-urls-create-body.d.ts +1 -1
- package/dist/types/v1-files-upload-urls-create-body.js +2 -2
- package/dist/types/v1-files-upload-urls-create-response-items-item.js +1 -1
- package/dist/types/v1-files-upload-urls-create-response.d.ts +1 -1
- package/dist/types/v1-files-upload-urls-create-response.js +2 -2
- package/dist/types/v1-image-background-remover-create-body-assets.js +1 -1
- package/dist/types/v1-image-background-remover-create-body.d.ts +1 -1
- package/dist/types/v1-image-background-remover-create-body.js +2 -2
- package/dist/types/v1-image-background-remover-create-response.js +1 -1
- package/dist/types/v1-image-projects-get-response-downloads-item.js +1 -1
- package/dist/types/v1-image-projects-get-response-error.js +1 -1
- package/dist/types/v1-image-projects-get-response.d.ts +1 -1
- package/dist/types/v1-image-projects-get-response.js +2 -2
- package/dist/types/v1-image-to-video-create-body-assets.js +1 -1
- package/dist/types/v1-image-to-video-create-body-style.js +1 -1
- package/dist/types/v1-image-to-video-create-body.d.ts +1 -1
- package/dist/types/v1-image-to-video-create-body.js +2 -2
- package/dist/types/v1-image-to-video-create-response.js +1 -1
- package/dist/types/v1-lip-sync-create-body-assets.js +1 -1
- package/dist/types/v1-lip-sync-create-body.d.ts +1 -1
- package/dist/types/v1-lip-sync-create-body.js +2 -2
- package/dist/types/v1-lip-sync-create-response.js +1 -1
- package/dist/types/v1-photo-colorizer-create-body-assets.js +1 -1
- package/dist/types/v1-photo-colorizer-create-body.d.ts +1 -1
- package/dist/types/v1-photo-colorizer-create-body.js +2 -2
- package/dist/types/v1-photo-colorizer-create-response.js +1 -1
- package/dist/types/v1-text-to-video-create-body-style.js +1 -1
- package/dist/types/v1-text-to-video-create-body.d.ts +1 -1
- package/dist/types/v1-text-to-video-create-body.js +2 -2
- package/dist/types/v1-text-to-video-create-response.js +1 -1
- package/dist/types/v1-video-projects-get-response-download.js +1 -1
- package/dist/types/v1-video-projects-get-response-downloads-item.js +1 -1
- package/dist/types/v1-video-projects-get-response-error.js +1 -1
- package/dist/types/v1-video-projects-get-response.d.ts +1 -1
- package/dist/types/v1-video-projects-get-response.js +2 -2
- package/dist/types/v1-video-to-video-create-body-assets.js +1 -1
- package/dist/types/v1-video-to-video-create-body-style.js +1 -1
- package/dist/types/v1-video-to-video-create-body.d.ts +1 -1
- package/dist/types/v1-video-to-video-create-body.js +2 -2
- package/dist/types/v1-video-to-video-create-response.js +1 -1
- package/package.json +14 -9
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
|
+
};
|
|
47
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
+
const magic_hour_1 = __importDefault(require("../../../index.js"));
|
|
49
|
+
const fs = __importStar(require("fs"));
|
|
50
|
+
const path = __importStar(require("path"));
|
|
51
|
+
const stream_1 = require("stream");
|
|
52
|
+
const msw_1 = require("msw");
|
|
53
|
+
const node_1 = require("msw/node");
|
|
54
|
+
// Mock fs module
|
|
55
|
+
jest.mock("fs", () => ({
|
|
56
|
+
existsSync: jest.fn(),
|
|
57
|
+
readFileSync: jest.fn(),
|
|
58
|
+
}));
|
|
59
|
+
const mockFs = fs;
|
|
60
|
+
// Create MSW server for mocking API requests
|
|
61
|
+
const server = (0, node_1.setupServer)(
|
|
62
|
+
// Mock upload URLs creation - handle both possible URLs
|
|
63
|
+
msw_1.http.post("https://api.magichour.ai/v1/files/upload-urls", () => {
|
|
64
|
+
return msw_1.HttpResponse.json({
|
|
65
|
+
items: [
|
|
66
|
+
{
|
|
67
|
+
upload_url: "https://storage.example.com/upload?token=abc123",
|
|
68
|
+
file_path: "api-assets/12345/image.jpg",
|
|
69
|
+
expires_at: "2024-12-31T23:59:59Z",
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
});
|
|
73
|
+
}),
|
|
74
|
+
// Mock file upload to storage
|
|
75
|
+
msw_1.http.put("https://storage.example.com/upload", () => {
|
|
76
|
+
return msw_1.HttpResponse.json({ status: 200 });
|
|
77
|
+
}),
|
|
78
|
+
// Handle any other upload URLs that might be generated
|
|
79
|
+
msw_1.http.put("https://example.com/upload", () => {
|
|
80
|
+
return msw_1.HttpResponse.json({ status: 200 });
|
|
81
|
+
}));
|
|
82
|
+
// Mock RUNTIME to ensure we use node-fetch
|
|
83
|
+
jest.mock("magic-hour/core", () => {
|
|
84
|
+
const actual = jest.requireActual("magic-hour/core");
|
|
85
|
+
return Object.assign(Object.assign({}, actual), { RUNTIME: { type: "node" } });
|
|
86
|
+
});
|
|
87
|
+
// Start and stop MSW server
|
|
88
|
+
beforeAll(() => server.listen());
|
|
89
|
+
afterAll(() => server.close());
|
|
90
|
+
afterEach(() => server.resetHandlers());
|
|
91
|
+
describe("FilesClient.uploadFile", () => {
|
|
92
|
+
let client;
|
|
93
|
+
beforeEach(() => {
|
|
94
|
+
client = new magic_hour_1.default({
|
|
95
|
+
token: "API_TOKEN",
|
|
96
|
+
});
|
|
97
|
+
// Reset all mocks
|
|
98
|
+
jest.clearAllMocks();
|
|
99
|
+
// Setup default fs mocks
|
|
100
|
+
mockFs.existsSync.mockReturnValue(true);
|
|
101
|
+
mockFs.readFileSync.mockReturnValue(Buffer.from("mock file content"));
|
|
102
|
+
});
|
|
103
|
+
describe("File type detection", () => {
|
|
104
|
+
// MSW handles the uploadUrls.create call automatically
|
|
105
|
+
test("should detect video file types correctly", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
106
|
+
const videoExtensions = ["mp4", "m4v", "mov", "webm"];
|
|
107
|
+
for (const ext of videoExtensions) {
|
|
108
|
+
const filePath = `/path/to/video.${ext}`;
|
|
109
|
+
// Spy on the uploadUrls.create method to verify it gets called with correct params
|
|
110
|
+
const createSpy = jest.spyOn(client.v1.files.uploadUrls, "create");
|
|
111
|
+
const result = yield client.v1.files.uploadFile(filePath);
|
|
112
|
+
expect(createSpy).toHaveBeenCalledWith({
|
|
113
|
+
items: [{ extension: ext, type: "video" }],
|
|
114
|
+
});
|
|
115
|
+
expect(result).toBe("api-assets/12345/image.jpg"); // MSW returns this mock value
|
|
116
|
+
createSpy.mockRestore();
|
|
117
|
+
}
|
|
118
|
+
}));
|
|
119
|
+
test("should detect audio file types correctly", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
120
|
+
const audioExtensions = ["mp3", "mpeg", "wav", "aac", "aiff", "flac"];
|
|
121
|
+
for (const ext of audioExtensions) {
|
|
122
|
+
const filePath = `/path/to/audio.${ext}`;
|
|
123
|
+
const createSpy = jest.spyOn(client.v1.files.uploadUrls, "create");
|
|
124
|
+
const result = yield client.v1.files.uploadFile(filePath);
|
|
125
|
+
expect(createSpy).toHaveBeenCalledWith({
|
|
126
|
+
items: [{ extension: ext, type: "audio" }],
|
|
127
|
+
});
|
|
128
|
+
expect(result).toBe("api-assets/12345/image.jpg");
|
|
129
|
+
createSpy.mockRestore();
|
|
130
|
+
}
|
|
131
|
+
}));
|
|
132
|
+
test("should detect image file types correctly", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
133
|
+
const imageExtensions = [
|
|
134
|
+
"png",
|
|
135
|
+
"jpg",
|
|
136
|
+
"jpeg",
|
|
137
|
+
"webp",
|
|
138
|
+
"avif",
|
|
139
|
+
"jp2",
|
|
140
|
+
"tiff",
|
|
141
|
+
"bmp",
|
|
142
|
+
];
|
|
143
|
+
for (const ext of imageExtensions) {
|
|
144
|
+
const filePath = `/path/to/image.${ext}`;
|
|
145
|
+
const createSpy = jest.spyOn(client.v1.files.uploadUrls, "create");
|
|
146
|
+
const result = yield client.v1.files.uploadFile(filePath);
|
|
147
|
+
expect(createSpy).toHaveBeenCalledWith({
|
|
148
|
+
items: [{ extension: ext, type: "image" }],
|
|
149
|
+
});
|
|
150
|
+
expect(result).toBe("api-assets/12345/image.jpg");
|
|
151
|
+
createSpy.mockRestore();
|
|
152
|
+
}
|
|
153
|
+
}));
|
|
154
|
+
test("should handle case-insensitive file extensions", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
155
|
+
const testCases = [
|
|
156
|
+
{
|
|
157
|
+
input: "/path/to/VIDEO.MP4",
|
|
158
|
+
expectedExt: "mp4",
|
|
159
|
+
expectedType: "video",
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
input: "/path/to/IMAGE.JPG",
|
|
163
|
+
expectedExt: "jpg",
|
|
164
|
+
expectedType: "image",
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
input: "/path/to/AUDIO.WAV",
|
|
168
|
+
expectedExt: "wav",
|
|
169
|
+
expectedType: "audio",
|
|
170
|
+
},
|
|
171
|
+
];
|
|
172
|
+
for (const { input, expectedExt, expectedType } of testCases) {
|
|
173
|
+
const createSpy = jest.spyOn(client.v1.files.uploadUrls, "create");
|
|
174
|
+
const result = yield client.v1.files.uploadFile(input);
|
|
175
|
+
expect(createSpy).toHaveBeenCalledWith({
|
|
176
|
+
items: [{ extension: expectedExt, type: expectedType }],
|
|
177
|
+
});
|
|
178
|
+
expect(result).toBe("api-assets/12345/image.jpg");
|
|
179
|
+
createSpy.mockRestore();
|
|
180
|
+
}
|
|
181
|
+
}));
|
|
182
|
+
test("should throw error for unsupported file extensions", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
183
|
+
const unsupportedFiles = [
|
|
184
|
+
"/path/to/file.txt",
|
|
185
|
+
"/path/to/document.pdf",
|
|
186
|
+
"/path/to/archive.zip",
|
|
187
|
+
"/path/to/data.json",
|
|
188
|
+
];
|
|
189
|
+
for (const filePath of unsupportedFiles) {
|
|
190
|
+
const ext = path.extname(filePath).slice(1).toLowerCase();
|
|
191
|
+
yield expect(client.v1.files.uploadFile(filePath)).rejects.toThrow(`Unsupported file extension: ${ext}`);
|
|
192
|
+
}
|
|
193
|
+
}));
|
|
194
|
+
});
|
|
195
|
+
describe("File input validation", () => {
|
|
196
|
+
const mockUploadResponse = {
|
|
197
|
+
items: [
|
|
198
|
+
{
|
|
199
|
+
uploadUrl: "https://example.com/upload",
|
|
200
|
+
filePath: "uploaded-file.jpg",
|
|
201
|
+
expiresAt: "2024-01-01T00:00:00Z",
|
|
202
|
+
},
|
|
203
|
+
],
|
|
204
|
+
};
|
|
205
|
+
beforeEach(() => {
|
|
206
|
+
jest
|
|
207
|
+
.spyOn(client.v1.files.uploadUrls, "create")
|
|
208
|
+
.mockResolvedValue(mockUploadResponse);
|
|
209
|
+
});
|
|
210
|
+
test("should validate file exists for string input", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
211
|
+
const filePath = "/path/to/image.jpg";
|
|
212
|
+
mockFs.existsSync.mockReturnValue(true);
|
|
213
|
+
yield client.v1.files.uploadFile(filePath);
|
|
214
|
+
expect(mockFs.existsSync).toHaveBeenCalledWith(filePath);
|
|
215
|
+
}));
|
|
216
|
+
test("should throw error for non-existent file path", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
217
|
+
const filePath = "/nonexistent/file.jpg";
|
|
218
|
+
mockFs.existsSync.mockReturnValue(false);
|
|
219
|
+
yield expect(client.v1.files.uploadFile(filePath)).rejects.toThrow(`File not found: ${filePath}`);
|
|
220
|
+
}));
|
|
221
|
+
test("should reject Buffer input without filename", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
222
|
+
const buffer = Buffer.from("image content");
|
|
223
|
+
yield expect(client.v1.files.uploadFile(buffer)).rejects.toThrow("Buffer input requires a file name for extension detection");
|
|
224
|
+
}));
|
|
225
|
+
test("should validate Readable stream has path property", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
226
|
+
const mockStream = new stream_1.Readable({
|
|
227
|
+
read() {
|
|
228
|
+
this.push(Buffer.from("stream content"));
|
|
229
|
+
this.push(null);
|
|
230
|
+
},
|
|
231
|
+
});
|
|
232
|
+
// Stream without path property should fail
|
|
233
|
+
yield expect(client.v1.files.uploadFile(mockStream)).rejects.toThrow("Stream must have a 'path' property for extension detection");
|
|
234
|
+
}));
|
|
235
|
+
test("should accept Readable stream with path property", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
236
|
+
const mockStream = new stream_1.Readable({
|
|
237
|
+
read() {
|
|
238
|
+
this.push(Buffer.from("stream content"));
|
|
239
|
+
this.push(null);
|
|
240
|
+
},
|
|
241
|
+
});
|
|
242
|
+
mockStream.path = "/path/to/video.mp4";
|
|
243
|
+
const result = yield client.v1.files.uploadFile(mockStream);
|
|
244
|
+
expect(result).toBe("uploaded-file.jpg");
|
|
245
|
+
expect(client.v1.files.uploadUrls.create).toHaveBeenCalledWith({
|
|
246
|
+
items: [{ extension: "mp4", type: "video" }],
|
|
247
|
+
});
|
|
248
|
+
}));
|
|
249
|
+
test.skip("should handle File object in browser-like environment", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
250
|
+
// Skipping this test as File object mocking is complex in Node.js environment
|
|
251
|
+
// This functionality would work in actual browser environments
|
|
252
|
+
}));
|
|
253
|
+
});
|
|
254
|
+
describe("File content processing", () => {
|
|
255
|
+
// MSW handles the uploadUrls.create call automatically
|
|
256
|
+
test("should read file content from file path", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
257
|
+
const filePath = "/path/to/image.jpg";
|
|
258
|
+
const fileContent = Buffer.from("image content");
|
|
259
|
+
mockFs.readFileSync.mockReturnValue(fileContent);
|
|
260
|
+
const createSpy = jest.spyOn(client.v1.files.uploadUrls, "create");
|
|
261
|
+
const result = yield client.v1.files.uploadFile(filePath);
|
|
262
|
+
expect(mockFs.readFileSync).toHaveBeenCalledWith(filePath);
|
|
263
|
+
expect(createSpy).toHaveBeenCalledWith({
|
|
264
|
+
items: [{ extension: "jpg", type: "image" }],
|
|
265
|
+
});
|
|
266
|
+
expect(result).toBe("api-assets/12345/image.jpg");
|
|
267
|
+
createSpy.mockRestore();
|
|
268
|
+
}));
|
|
269
|
+
test("should process Readable stream content", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
270
|
+
const streamContent = Buffer.from("stream video content");
|
|
271
|
+
const mockStream = new stream_1.Readable({
|
|
272
|
+
read() {
|
|
273
|
+
this.push(streamContent);
|
|
274
|
+
this.push(null);
|
|
275
|
+
},
|
|
276
|
+
});
|
|
277
|
+
mockStream.path = "/path/to/video.mp4";
|
|
278
|
+
const createSpy = jest.spyOn(client.v1.files.uploadUrls, "create");
|
|
279
|
+
const result = yield client.v1.files.uploadFile(mockStream);
|
|
280
|
+
expect(createSpy).toHaveBeenCalledWith({
|
|
281
|
+
items: [{ extension: "mp4", type: "video" }],
|
|
282
|
+
});
|
|
283
|
+
expect(result).toBe("api-assets/12345/image.jpg");
|
|
284
|
+
createSpy.mockRestore();
|
|
285
|
+
}));
|
|
286
|
+
test("should handle large stream content", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
287
|
+
const largeContent = Buffer.from("a".repeat(1024 * 1024)); // 1MB of content
|
|
288
|
+
const mockStream = new stream_1.Readable({
|
|
289
|
+
read() {
|
|
290
|
+
this.push(largeContent);
|
|
291
|
+
this.push(null);
|
|
292
|
+
},
|
|
293
|
+
});
|
|
294
|
+
mockStream.path = "/path/to/large-video.mp4";
|
|
295
|
+
const createSpy = jest.spyOn(client.v1.files.uploadUrls, "create");
|
|
296
|
+
const result = yield client.v1.files.uploadFile(mockStream);
|
|
297
|
+
expect(createSpy).toHaveBeenCalledWith({
|
|
298
|
+
items: [{ extension: "mp4", type: "video" }],
|
|
299
|
+
});
|
|
300
|
+
expect(result).toBe("api-assets/12345/image.jpg");
|
|
301
|
+
createSpy.mockRestore();
|
|
302
|
+
}));
|
|
303
|
+
test.skip("should handle File object arrayBuffer conversion", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
304
|
+
// Skipping this test as File object mocking is complex in Node.js environment
|
|
305
|
+
// This functionality would work in actual browser environments
|
|
306
|
+
}));
|
|
307
|
+
});
|
|
308
|
+
describe("Upload process and error handling", () => {
|
|
309
|
+
test("should successfully complete upload process", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
310
|
+
const createSpy = jest.spyOn(client.v1.files.uploadUrls, "create");
|
|
311
|
+
const result = yield client.v1.files.uploadFile("/path/to/image.jpg");
|
|
312
|
+
expect(result).toBe("api-assets/12345/image.jpg");
|
|
313
|
+
expect(createSpy).toHaveBeenCalledWith({
|
|
314
|
+
items: [{ extension: "jpg", type: "image" }],
|
|
315
|
+
});
|
|
316
|
+
createSpy.mockRestore();
|
|
317
|
+
}));
|
|
318
|
+
test("should handle empty upload URL response", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
319
|
+
const mockResponse = { items: [] };
|
|
320
|
+
jest
|
|
321
|
+
.spyOn(client.v1.files.uploadUrls, "create")
|
|
322
|
+
.mockResolvedValue(mockResponse);
|
|
323
|
+
yield expect(client.v1.files.uploadFile("/path/to/image.jpg")).rejects.toThrow("No upload URL was returned from the server");
|
|
324
|
+
}));
|
|
325
|
+
test("should handle null upload info", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
326
|
+
const mockResponse = { items: [null] };
|
|
327
|
+
jest
|
|
328
|
+
.spyOn(client.v1.files.uploadUrls, "create")
|
|
329
|
+
.mockResolvedValue(mockResponse);
|
|
330
|
+
yield expect(client.v1.files.uploadFile("/path/to/image.jpg")).rejects.toThrow("Upload info is missing from server response");
|
|
331
|
+
}));
|
|
332
|
+
test("should handle upload HTTP failure", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
333
|
+
// Change server behavior for this test
|
|
334
|
+
server.use(msw_1.http.put("https://storage.example.com/upload", () => {
|
|
335
|
+
return msw_1.HttpResponse.json({ error: "Internal Server Error" }, { status: 500 });
|
|
336
|
+
}));
|
|
337
|
+
yield expect(client.v1.files.uploadFile("/path/to/image.jpg")).rejects.toThrow("Upload failed with status 500");
|
|
338
|
+
}));
|
|
339
|
+
test("should handle network errors during upload", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
340
|
+
// Change server behavior for this test to simulate network error
|
|
341
|
+
server.use(msw_1.http.put("https://storage.example.com/upload", () => {
|
|
342
|
+
return msw_1.HttpResponse.error();
|
|
343
|
+
}));
|
|
344
|
+
yield expect(client.v1.files.uploadFile("/path/to/image.jpg")).rejects.toThrow("Network error");
|
|
345
|
+
}));
|
|
346
|
+
test("should handle upload URLs creation failure", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
347
|
+
jest
|
|
348
|
+
.spyOn(client.v1.files.uploadUrls, "create")
|
|
349
|
+
.mockRejectedValue(new Error("API authentication failed"));
|
|
350
|
+
yield expect(client.v1.files.uploadFile("/path/to/image.jpg")).rejects.toThrow("API authentication failed");
|
|
351
|
+
}));
|
|
352
|
+
test("should handle file system read errors", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
353
|
+
mockFs.readFileSync.mockImplementation(() => {
|
|
354
|
+
throw new Error("Permission denied");
|
|
355
|
+
});
|
|
356
|
+
yield expect(client.v1.files.uploadFile("/path/to/image.jpg")).rejects.toThrow("Permission denied");
|
|
357
|
+
}));
|
|
358
|
+
});
|
|
359
|
+
describe("Integration and edge cases", () => {
|
|
360
|
+
test("should handle files with special characters in names", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
361
|
+
const specialFiles = [
|
|
362
|
+
"/path/to/image with spaces.jpg",
|
|
363
|
+
"/path/to/image-with-dashes.png",
|
|
364
|
+
"/path/to/image_with_underscores.webp",
|
|
365
|
+
"/path/to/image.with.dots.mp4",
|
|
366
|
+
"/path/to/123numeric.mp3",
|
|
367
|
+
];
|
|
368
|
+
const mockResponse = {
|
|
369
|
+
items: [
|
|
370
|
+
{
|
|
371
|
+
uploadUrl: "https://example.com/upload",
|
|
372
|
+
filePath: "uploaded-file.jpg",
|
|
373
|
+
expiresAt: "2024-01-01T00:00:00Z",
|
|
374
|
+
},
|
|
375
|
+
],
|
|
376
|
+
};
|
|
377
|
+
jest
|
|
378
|
+
.spyOn(client.v1.files.uploadUrls, "create")
|
|
379
|
+
.mockResolvedValue(mockResponse);
|
|
380
|
+
for (const filePath of specialFiles) {
|
|
381
|
+
const ext = path.extname(filePath).slice(1).toLowerCase();
|
|
382
|
+
const expectedType = getFileTypeFromExtension(ext);
|
|
383
|
+
yield client.v1.files.uploadFile(filePath);
|
|
384
|
+
expect(client.v1.files.uploadUrls.create).toHaveBeenCalledWith({
|
|
385
|
+
items: [{ extension: ext, type: expectedType }],
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
}));
|
|
389
|
+
test("should handle empty file content", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
390
|
+
mockFs.readFileSync.mockReturnValue(Buffer.from(""));
|
|
391
|
+
const createSpy = jest.spyOn(client.v1.files.uploadUrls, "create");
|
|
392
|
+
const result = yield client.v1.files.uploadFile("/path/to/empty.jpg");
|
|
393
|
+
expect(result).toBe("api-assets/12345/image.jpg");
|
|
394
|
+
expect(createSpy).toHaveBeenCalledWith({
|
|
395
|
+
items: [{ extension: "jpg", type: "image" }],
|
|
396
|
+
});
|
|
397
|
+
createSpy.mockRestore();
|
|
398
|
+
}));
|
|
399
|
+
});
|
|
400
|
+
});
|
|
401
|
+
// Helper function for tests
|
|
402
|
+
function getFileTypeFromExtension(ext) {
|
|
403
|
+
const videoExts = ["mp4", "m4v", "mov", "webm"];
|
|
404
|
+
const audioExts = ["mp3", "mpeg", "wav", "aac", "aiff", "flac"];
|
|
405
|
+
const imageExts = [
|
|
406
|
+
"png",
|
|
407
|
+
"jpg",
|
|
408
|
+
"jpeg",
|
|
409
|
+
"webp",
|
|
410
|
+
"avif",
|
|
411
|
+
"jp2",
|
|
412
|
+
"tiff",
|
|
413
|
+
"bmp",
|
|
414
|
+
];
|
|
415
|
+
if (videoExts.includes(ext))
|
|
416
|
+
return "video";
|
|
417
|
+
if (audioExts.includes(ext))
|
|
418
|
+
return "audio";
|
|
419
|
+
if (imageExts.includes(ext))
|
|
420
|
+
return "image";
|
|
421
|
+
throw new Error(`Unsupported extension: ${ext}`);
|
|
422
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { External$V1FilesUploadUrlsCreateBodyItemsItem, V1FilesUploadUrlsCreateBodyItemsItem } from "../../../../types/v1-files-upload-urls-create-body-items-item";
|
|
2
1
|
import * as z from "zod";
|
|
2
|
+
import { External$V1FilesUploadUrlsCreateBodyItemsItem, V1FilesUploadUrlsCreateBodyItemsItem } from "../../../../types/v1-files-upload-urls-create-body-items-item";
|
|
3
3
|
/**
|
|
4
4
|
* CreateRequest
|
|
5
5
|
*/
|
|
@@ -34,9 +34,9 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.Schemas$CreateRequest = void 0;
|
|
37
|
+
const z = __importStar(require("zod"));
|
|
37
38
|
const core_1 = require("../../../../core");
|
|
38
39
|
const v1_files_upload_urls_create_body_items_item_1 = require("../../../../types/v1-files-upload-urls-create-body-items-item");
|
|
39
|
-
const z = __importStar(require("zod"));
|
|
40
40
|
/**
|
|
41
41
|
* Takes network data, validates it, and transforms keys to match typescript object CreateRequest
|
|
42
42
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { External$V1ImageBackgroundRemoverCreateBodyAssets, V1ImageBackgroundRemoverCreateBodyAssets } from "../../../types/v1-image-background-remover-create-body-assets";
|
|
2
1
|
import * as z from "zod";
|
|
2
|
+
import { External$V1ImageBackgroundRemoverCreateBodyAssets, V1ImageBackgroundRemoverCreateBodyAssets } from "../../../types/v1-image-background-remover-create-body-assets";
|
|
3
3
|
/**
|
|
4
4
|
* CreateRequest
|
|
5
5
|
*/
|
|
@@ -34,9 +34,9 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.Schemas$CreateRequest = void 0;
|
|
37
|
+
const z = __importStar(require("zod"));
|
|
37
38
|
const core_1 = require("../../../core");
|
|
38
39
|
const v1_image_background_remover_create_body_assets_1 = require("../../../types/v1-image-background-remover-create-body-assets");
|
|
39
|
-
const z = __importStar(require("zod"));
|
|
40
40
|
/**
|
|
41
41
|
* Takes network data, validates it, and transforms keys to match typescript object CreateRequest
|
|
42
42
|
*/
|
|
@@ -1,8 +1,56 @@
|
|
|
1
1
|
import { types } from "../../../index.js";
|
|
2
2
|
import { ApiPromise, CoreClient, CoreResourceClient, RequestOptions, ResourceClientOptions } from "../../../core";
|
|
3
|
+
import { GenerateOptions, GenerateRequestType } from "../../../helpers/generate-type";
|
|
3
4
|
import * as requests from "../../../resources/v1/image-background-remover/request-types";
|
|
5
|
+
type GenerateRequest = GenerateRequestType<requests.CreateRequest, {
|
|
6
|
+
/**
|
|
7
|
+
* The image used as the new background for the image_file_path. This value is either
|
|
8
|
+
* - a direct URL to the image file
|
|
9
|
+
* - a path to a local file
|
|
10
|
+
*
|
|
11
|
+
* Note: if the path begins with `api-assets`, it will be assumed to already be uploaded to Magic Hour's storage, and will not be uploaded again.
|
|
12
|
+
*/
|
|
13
|
+
backgroundImageFilePath?: string | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* The image to remove the background. This value is either
|
|
16
|
+
* - a direct URL to the image file
|
|
17
|
+
* - a path to a local file
|
|
18
|
+
*
|
|
19
|
+
* Note: if the path begins with `api-assets`, it will be assumed to already be uploaded to Magic Hour's storage, and will not be uploaded again.
|
|
20
|
+
*/
|
|
21
|
+
imageFilePath: string;
|
|
22
|
+
}>;
|
|
4
23
|
export declare class ImageBackgroundRemoverClient extends CoreResourceClient {
|
|
5
24
|
constructor(coreClient: CoreClient, opts: ResourceClientOptions);
|
|
25
|
+
/**
|
|
26
|
+
* Image Background Remover
|
|
27
|
+
*
|
|
28
|
+
* Remove background from image
|
|
29
|
+
*
|
|
30
|
+
* This method provides a convenient way to create a request and automatically wait for completion and download outputs.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* import Client from "../../../index.js";
|
|
35
|
+
*
|
|
36
|
+
* const client = new Client({ token: process.env["API_TOKEN"]!! });
|
|
37
|
+
* const res = await client.v1.imageBackgroundRemover.generate(
|
|
38
|
+
* {
|
|
39
|
+
* assets: {
|
|
40
|
+
* backgroundImageFilePath: "/path/to/1234.png",
|
|
41
|
+
* imageFilePath: "/path/to/1234.png",
|
|
42
|
+
* },
|
|
43
|
+
* name: "Background Remover image",
|
|
44
|
+
* },
|
|
45
|
+
* {
|
|
46
|
+
* waitForCompletion: true,
|
|
47
|
+
* downloadOutputs: true,
|
|
48
|
+
* downloadDirectory: "outputs",
|
|
49
|
+
* },
|
|
50
|
+
* );
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
generate(request: GenerateRequest, opts?: GenerateOptions): Promise<import("../image-projects/resource-client").V1ImageProjectsGetResponseWithDownloads>;
|
|
6
54
|
/**
|
|
7
55
|
* Image Background Remover
|
|
8
56
|
*
|
|
@@ -12,3 +60,4 @@ export declare class ImageBackgroundRemoverClient extends CoreResourceClient {
|
|
|
12
60
|
*/
|
|
13
61
|
create(request: requests.CreateRequest, opts?: RequestOptions): ApiPromise<types.V1ImageBackgroundRemoverCreateResponse>;
|
|
14
62
|
}
|
|
63
|
+
export {};
|
|
@@ -1,13 +1,95 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
2
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
23
|
exports.ImageBackgroundRemoverClient = void 0;
|
|
4
24
|
const core_1 = require("../../../core");
|
|
25
|
+
const files_1 = require("../../../resources/v1/files");
|
|
5
26
|
const v1_image_background_remover_create_body_1 = require("../../../types/v1-image-background-remover-create-body");
|
|
6
27
|
const v1_image_background_remover_create_response_1 = require("../../../types/v1-image-background-remover-create-response");
|
|
28
|
+
const logger_1 = require("../../../logger");
|
|
29
|
+
const image_projects_1 = require("../../../resources/v1/image-projects");
|
|
7
30
|
class ImageBackgroundRemoverClient extends core_1.CoreResourceClient {
|
|
8
31
|
constructor(coreClient, opts) {
|
|
9
32
|
super(coreClient, opts);
|
|
10
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Image Background Remover
|
|
36
|
+
*
|
|
37
|
+
* Remove background from image
|
|
38
|
+
*
|
|
39
|
+
* This method provides a convenient way to create a request and automatically wait for completion and download outputs.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* import Client from "../../../index.js";
|
|
44
|
+
*
|
|
45
|
+
* const client = new Client({ token: process.env["API_TOKEN"]!! });
|
|
46
|
+
* const res = await client.v1.imageBackgroundRemover.generate(
|
|
47
|
+
* {
|
|
48
|
+
* assets: {
|
|
49
|
+
* backgroundImageFilePath: "/path/to/1234.png",
|
|
50
|
+
* imageFilePath: "/path/to/1234.png",
|
|
51
|
+
* },
|
|
52
|
+
* name: "Background Remover image",
|
|
53
|
+
* },
|
|
54
|
+
* {
|
|
55
|
+
* waitForCompletion: true,
|
|
56
|
+
* downloadOutputs: true,
|
|
57
|
+
* downloadDirectory: "outputs",
|
|
58
|
+
* },
|
|
59
|
+
* );
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
generate(request_1) {
|
|
63
|
+
return __awaiter(this, arguments, void 0, function* (request, opts = {}) {
|
|
64
|
+
const { waitForCompletion = true, downloadOutputs = true, downloadDirectory = undefined } = opts, createOpts = __rest(opts, ["waitForCompletion", "downloadOutputs", "downloadDirectory"]);
|
|
65
|
+
const fileClient = new files_1.FilesClient(this._client, this._opts);
|
|
66
|
+
const _a = request.assets, { backgroundImageFilePath, imageFilePath } = _a, restAssets = __rest(_a, ["backgroundImageFilePath", "imageFilePath"]);
|
|
67
|
+
if (backgroundImageFilePath) {
|
|
68
|
+
(0, logger_1.getLogger)().debug(`Uploading file ${backgroundImageFilePath} to Magic Hour's storage`);
|
|
69
|
+
}
|
|
70
|
+
(0, logger_1.getLogger)().debug(`Uploading file ${imageFilePath} to Magic Hour's storage`);
|
|
71
|
+
const [uploadedBackgroundImageFilePath, uploadedImageFilePath] = yield Promise.all([
|
|
72
|
+
backgroundImageFilePath
|
|
73
|
+
? fileClient.uploadFile(backgroundImageFilePath)
|
|
74
|
+
: Promise.resolve(backgroundImageFilePath),
|
|
75
|
+
fileClient.uploadFile(imageFilePath),
|
|
76
|
+
]);
|
|
77
|
+
if (backgroundImageFilePath) {
|
|
78
|
+
(0, logger_1.getLogger)().info(`Uploaded file ${backgroundImageFilePath} to Magic Hour's storage as ${uploadedBackgroundImageFilePath}`);
|
|
79
|
+
}
|
|
80
|
+
(0, logger_1.getLogger)().info(`Uploaded file ${imageFilePath} to Magic Hour's storage as ${uploadedImageFilePath}`);
|
|
81
|
+
const createResponse = yield this.create(Object.assign(Object.assign({}, request), { assets: Object.assign(Object.assign({}, restAssets), { backgroundImageFilePath: backgroundImageFilePath
|
|
82
|
+
? uploadedBackgroundImageFilePath
|
|
83
|
+
: backgroundImageFilePath, imageFilePath: uploadedImageFilePath }) }), createOpts);
|
|
84
|
+
(0, logger_1.getLogger)().info(`Created ImageBackgroundRemoverClient project ${createResponse.id}`);
|
|
85
|
+
const projectsClient = new image_projects_1.ImageProjectsClient(this._client, this._opts);
|
|
86
|
+
(0, logger_1.getLogger)().debug(`Checking result for ImageBackgroundRemoverClient project ${createResponse.id}`);
|
|
87
|
+
const result = yield projectsClient.checkResult({ id: createResponse.id }, Object.assign({ waitForCompletion,
|
|
88
|
+
downloadOutputs,
|
|
89
|
+
downloadDirectory }, createOpts));
|
|
90
|
+
return result;
|
|
91
|
+
});
|
|
92
|
+
}
|
|
11
93
|
/**
|
|
12
94
|
* Image Background Remover
|
|
13
95
|
*
|
|
@@ -34,8 +34,8 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.Schemas$GetRequest = exports.Schemas$DeleteRequest = void 0;
|
|
37
|
-
const core_1 = require("../../../core");
|
|
38
37
|
const z = __importStar(require("zod"));
|
|
38
|
+
const core_1 = require("../../../core");
|
|
39
39
|
/**
|
|
40
40
|
* Takes network data, validates it, and transforms keys to match typescript object DeleteRequest
|
|
41
41
|
*/
|
|
@@ -1,8 +1,30 @@
|
|
|
1
1
|
import { types } from "../../../index.js";
|
|
2
2
|
import { ApiPromise, CoreClient, CoreResourceClient, RequestOptions, ResourceClientOptions } from "../../../core";
|
|
3
|
+
import { GenerateOptions } from "../../../helpers/generate-type";
|
|
3
4
|
import * as requests from "../../../resources/v1/image-projects/request-types";
|
|
5
|
+
/**
|
|
6
|
+
* Extended response interface that includes downloaded paths
|
|
7
|
+
*/
|
|
8
|
+
export interface V1ImageProjectsGetResponseWithDownloads extends types.V1ImageProjectsGetResponse {
|
|
9
|
+
/**
|
|
10
|
+
* The paths to the downloaded files.
|
|
11
|
+
* This field is only populated if `download_outputs` is True and the image project is complete.
|
|
12
|
+
*/
|
|
13
|
+
downloadedPaths?: string[];
|
|
14
|
+
}
|
|
4
15
|
export declare class ImageProjectsClient extends CoreResourceClient {
|
|
5
16
|
constructor(coreClient: CoreClient, opts: ResourceClientOptions);
|
|
17
|
+
/**
|
|
18
|
+
* Check the result of an image project with optional waiting and downloading.
|
|
19
|
+
*
|
|
20
|
+
* This method retrieves the status of an image project and optionally waits for completion
|
|
21
|
+
* and downloads the output files.
|
|
22
|
+
*
|
|
23
|
+
* @param request - Request object containing the image project ID
|
|
24
|
+
* @param opts - Additional request options
|
|
25
|
+
* @returns The image project response with optional downloaded file paths included
|
|
26
|
+
*/
|
|
27
|
+
checkResult(request: requests.GetRequest, opts?: GenerateOptions): Promise<V1ImageProjectsGetResponseWithDownloads>;
|
|
6
28
|
/**
|
|
7
29
|
* Delete image
|
|
8
30
|
*
|