magic-hour 0.46.0 → 0.48.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.
Files changed (74) hide show
  1. package/dist/environment.d.ts +1 -1
  2. package/dist/environment.js +1 -1
  3. package/dist/resources/v1/ai-image-editor/resource-client.d.ts +1 -1
  4. package/dist/resources/v1/ai-image-editor/resource-client.js +1 -1
  5. package/dist/resources/v1/ai-image-generator/request-types.d.ts +48 -4
  6. package/dist/resources/v1/ai-image-generator/request-types.js +30 -2
  7. package/dist/resources/v1/ai-image-generator/resource-client.d.ts +1 -1
  8. package/dist/resources/v1/ai-image-generator/resource-client.js +1 -1
  9. package/dist/resources/v1/image-to-video/request-types.d.ts +29 -7
  10. package/dist/resources/v1/image-to-video/request-types.js +24 -0
  11. package/dist/resources/v1/text-to-video/request-types.d.ts +41 -12
  12. package/dist/resources/v1/text-to-video/request-types.js +30 -2
  13. package/dist/types/index.d.ts +6 -0
  14. package/dist/types/v1-ai-image-editor-create-body-style-model-enum.d.ts +2 -1
  15. package/dist/types/v1-ai-image-editor-create-body-style.d.ts +2 -1
  16. package/dist/types/v1-ai-image-generator-create-body-aspect-ratio-enum.d.ts +4 -0
  17. package/dist/types/v1-ai-image-generator-create-body-aspect-ratio-enum.js +2 -0
  18. package/dist/types/v1-ai-image-generator-create-body-model-enum.d.ts +24 -0
  19. package/dist/types/v1-ai-image-generator-create-body-model-enum.js +2 -0
  20. package/dist/types/v1-ai-image-generator-create-body-orientation-enum.d.ts +3 -1
  21. package/dist/types/v1-ai-image-generator-create-body-resolution-enum.d.ts +11 -0
  22. package/dist/types/v1-ai-image-generator-create-body-resolution-enum.js +2 -0
  23. package/dist/types/v1-ai-image-generator-create-body-style-quality-mode-enum.d.ts +5 -5
  24. package/dist/types/v1-ai-image-generator-create-body-style.d.ts +5 -5
  25. package/dist/types/v1-ai-image-generator-create-body.d.ts +48 -4
  26. package/dist/types/v1-ai-image-generator-create-body.js +30 -2
  27. package/dist/types/v1-ai-talking-photo-create-body-style-generation-mode-enum.d.ts +8 -5
  28. package/dist/types/v1-ai-talking-photo-create-body-style.d.ts +15 -6
  29. package/dist/types/v1-ai-talking-photo-create-body-style.js +20 -2
  30. package/dist/types/v1-image-projects-get-response.d.ts +1 -1
  31. package/dist/types/v1-image-to-video-create-body-assets.d.ts +1 -1
  32. package/dist/types/v1-image-to-video-create-body-model-enum.d.ts +11 -0
  33. package/dist/types/v1-image-to-video-create-body-model-enum.js +2 -0
  34. package/dist/types/v1-image-to-video-create-body-resolution-enum.d.ts +7 -6
  35. package/dist/types/v1-image-to-video-create-body.d.ts +29 -7
  36. package/dist/types/v1-image-to-video-create-body.js +24 -0
  37. package/dist/types/v1-text-to-video-create-body-aspect-ratio-enum.d.ts +10 -0
  38. package/dist/types/v1-text-to-video-create-body-aspect-ratio-enum.js +2 -0
  39. package/dist/types/v1-text-to-video-create-body-model-enum.d.ts +11 -0
  40. package/dist/types/v1-text-to-video-create-body-model-enum.js +2 -0
  41. package/dist/types/v1-text-to-video-create-body-orientation-enum.d.ts +1 -1
  42. package/dist/types/v1-text-to-video-create-body-resolution-enum.d.ts +7 -6
  43. package/dist/types/v1-text-to-video-create-body.d.ts +41 -12
  44. package/dist/types/v1-text-to-video-create-body.js +30 -2
  45. package/dist/types/v1-video-projects-get-response.d.ts +1 -1
  46. package/package.json +1 -1
  47. package/dist/core/api-error.d.ts +0 -6
  48. package/dist/core/api-error.js +0 -11
  49. package/dist/core/api-promise.d.ts +0 -28
  50. package/dist/core/api-promise.js +0 -252
  51. package/dist/core/auth.d.ts +0 -76
  52. package/dist/core/auth.js +0 -232
  53. package/dist/core/binary-response.d.ts +0 -6
  54. package/dist/core/binary-response.js +0 -10
  55. package/dist/core/content-type.d.ts +0 -4
  56. package/dist/core/content-type.js +0 -12
  57. package/dist/core/core-client.d.ts +0 -58
  58. package/dist/core/core-client.js +0 -168
  59. package/dist/core/form-data.d.ts +0 -26
  60. package/dist/core/form-data.js +0 -83
  61. package/dist/core/index.d.ts +0 -9
  62. package/dist/core/index.js +0 -28
  63. package/dist/core/logger.d.ts +0 -48
  64. package/dist/core/logger.js +0 -82
  65. package/dist/core/query.d.ts +0 -8
  66. package/dist/core/query.js +0 -77
  67. package/dist/core/runtime.d.ts +0 -4
  68. package/dist/core/runtime.js +0 -20
  69. package/dist/core/zod.d.ts +0 -13
  70. package/dist/core/zod.js +0 -60
  71. package/dist/examples/logging-example.d.ts +0 -10
  72. package/dist/examples/logging-example.js +0 -137
  73. package/dist/logging-client.d.ts +0 -39
  74. package/dist/logging-client.js +0 -116
package/dist/core/zod.js DELETED
@@ -1,60 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.zodRequiredAny = exports.zodUploadFile = void 0;
37
- exports.zodTransform = zodTransform;
38
- const z = __importStar(require("zod"));
39
- const form_data_1 = require("./form-data");
40
- /**
41
- * Generic function to transform an objects keys from one string to another.
42
- * If the incoming object does not have a transform key, the original key is retained.
43
- * If the incoming object has a key that maps to a `null` transform key, then
44
- * the value is skipped.
45
- */
46
- function zodTransform(input, transformer) {
47
- const transformed = {};
48
- for (const [key, val] of Object.entries(input)) {
49
- const toKey = transformer[key];
50
- if (toKey === null) {
51
- continue;
52
- }
53
- transformed[toKey !== null && toKey !== void 0 ? toKey : key] = val;
54
- }
55
- return transformed;
56
- }
57
- exports.zodUploadFile = z.custom((val) => (0, form_data_1.isUploadFile)(val));
58
- // Workaround because the type zod infers from z.any() allows undefined
59
- // https://github.com/colinhacks/zod/issues/3730
60
- exports.zodRequiredAny = z.custom((x) => x !== undefined);
@@ -1,10 +0,0 @@
1
- /**
2
- * Example demonstrating how to use logging with the Magic Hour SDK
3
- * This implementation doesn't modify any core files
4
- */
5
- import { LoggingClient } from "../index.js";
6
- declare const client1: LoggingClient;
7
- declare const client2: LoggingClient;
8
- declare const client3: LoggingClient;
9
- declare const client4: LoggingClient;
10
- export { client1, client2, client3, client4 };
@@ -1,137 +0,0 @@
1
- "use strict";
2
- /**
3
- * Example demonstrating how to use logging with the Magic Hour SDK
4
- * This implementation doesn't modify any core files
5
- */
6
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
7
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
8
- return new (P || (P = Promise))(function (resolve, reject) {
9
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
10
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
11
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
12
- step((generator = generator.apply(thisArg, _arguments || [])).next());
13
- });
14
- };
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.client4 = exports.client3 = exports.client2 = exports.client1 = void 0;
17
- const magic_hour_1 = require("../index.js");
18
- // Example 1: Basic logging with default console logger
19
- const client1 = new magic_hour_1.LoggingClient({
20
- token: process.env["MAGIC_HOUR_API_TOKEN"] || "your-api-token-here",
21
- logger: {
22
- level: "info", // Only show info and above
23
- includeTimestamp: true,
24
- },
25
- });
26
- exports.client1 = client1;
27
- // Example 2: Custom logger implementation
28
- class CustomLogger {
29
- error(message, ...args) {
30
- console.error(`[MYAPP] ${message}`, ...args);
31
- }
32
- warn(message, ...args) {
33
- console.warn(`[MYAPP] ${message}`, ...args);
34
- }
35
- info(message, ...args) {
36
- console.info(`[MYAPP] ${message}`, ...args);
37
- }
38
- debug(message, ...args) {
39
- console.debug(`[MYAPP] ${message}`, ...args);
40
- }
41
- }
42
- const client2 = new magic_hour_1.LoggingClient({
43
- token: process.env["MAGIC_HOUR_API_TOKEN"] || "your-api-token-here",
44
- logger: {
45
- level: "debug",
46
- logger: new CustomLogger(),
47
- includeTimestamp: true,
48
- },
49
- });
50
- exports.client2 = client2;
51
- // Example 3: Disable logging completely
52
- const client3 = new magic_hour_1.LoggingClient({
53
- token: process.env["MAGIC_HOUR_API_TOKEN"] || "your-api-token-here",
54
- logger: {
55
- level: "none", // Disable all logging
56
- },
57
- });
58
- exports.client3 = client3;
59
- // Example 4: Runtime logger configuration changes
60
- const client4 = new magic_hour_1.LoggingClient({
61
- token: process.env["MAGIC_HOUR_API_TOKEN"] || "your-api-token-here",
62
- logger: {
63
- level: "info",
64
- },
65
- });
66
- exports.client4 = client4;
67
- // Change log level at runtime
68
- client4.setLoggerConfig({
69
- level: "debug",
70
- includeTimestamp: true,
71
- });
72
- // Example 5: Using external logging library (like Winston)
73
- // Note: You would need to install winston as a dependency first
74
- // npm install winston
75
- /*
76
- import winston from "winston";
77
-
78
- const winstonLogger = winston.createLogger({
79
- level: "info",
80
- format: winston.format.combine(
81
- winston.format.timestamp(),
82
- winston.format.json()
83
- ),
84
- transports: [
85
- new winston.transports.Console(),
86
- new winston.transports.File({ filename: "magic-hour.log" }),
87
- ],
88
- });
89
-
90
- class WinstonLoggerAdapter implements Logger {
91
- error(message: string, ...args: any[]): void {
92
- winstonLogger.error(message, ...args);
93
- }
94
-
95
- warn(message: string, ...args: any[]): void {
96
- winstonLogger.warn(message, ...args);
97
- }
98
-
99
- info(message: string, ...args: any[]): void {
100
- winstonLogger.info(message, ...args);
101
- }
102
-
103
- debug(message: string, ...args: any[]): void {
104
- winstonLogger.debug(message, ...args);
105
- }
106
- }
107
-
108
- const client5 = new LoggingClient({
109
- token: process.env["MAGIC_HOUR_API_TOKEN"] || "your-api-token-here",
110
- logger: {
111
- level: "info",
112
- logger: new WinstonLoggerAdapter(),
113
- },
114
- });
115
- */
116
- // Usage example
117
- function exampleUsage() {
118
- return __awaiter(this, void 0, void 0, function* () {
119
- try {
120
- // This will log request/response details at DEBUG level
121
- console.log("=== Creating image generation request ===");
122
- const result = yield client2.v1.aiImageGenerator.create({
123
- assets: { prompt: "A beautiful sunset over mountains" },
124
- style: { type: "ai-image-generator" },
125
- });
126
- console.log("Image generation result:", result);
127
- // The logging client will automatically log:
128
- // - Method calls with sanitized parameters
129
- // - Execution time
130
- // - Operation status updates
131
- // - Any errors that occur
132
- }
133
- catch (error) {
134
- console.error("Error:", error);
135
- }
136
- });
137
- }
@@ -1,39 +0,0 @@
1
- import Client, { ClientOptions } from "./index.js";
2
- import { Logger, LoggerConfig } from "./logger";
3
- /**
4
- * Extended client options with logging support
5
- */
6
- export interface LoggingClientOptions extends ClientOptions {
7
- logger?: LoggerConfig;
8
- }
9
- /**
10
- * Magic Hour client with built-in logging capabilities
11
- *
12
- * This class extends the base Client and adds comprehensive logging
13
- * without modifying any core files. It provides:
14
- * - Request/response logging
15
- * - Operation status logging
16
- * - Configurable log levels
17
- * - Custom logger support
18
- */
19
- export declare class LoggingClient extends Client {
20
- private logger;
21
- private originalV1;
22
- constructor(opts?: LoggingClientOptions);
23
- /**
24
- * Create a proxy that wraps method calls with logging
25
- */
26
- private createLoggingProxy;
27
- /**
28
- * Sanitize arguments for logging (remove sensitive data)
29
- */
30
- private sanitizeArgs;
31
- /**
32
- * Update logger configuration at runtime
33
- */
34
- setLoggerConfig(config: LoggerConfig): void;
35
- /**
36
- * Get current logger instance
37
- */
38
- getLogger(): Logger;
39
- }
@@ -1,116 +0,0 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.LoggingClient = void 0;
16
- const magic_hour_1 = __importDefault(require("./index.js"));
17
- const logger_1 = require("./logger");
18
- /**
19
- * Magic Hour client with built-in logging capabilities
20
- *
21
- * This class extends the base Client and adds comprehensive logging
22
- * without modifying any core files. It provides:
23
- * - Request/response logging
24
- * - Operation status logging
25
- * - Configurable log levels
26
- * - Custom logger support
27
- */
28
- class LoggingClient extends magic_hour_1.default {
29
- constructor(opts) {
30
- var _a;
31
- super(opts);
32
- // Initialize logger
33
- this.logger = (0, logger_1.createLogger)((_a = opts === null || opts === void 0 ? void 0 : opts.logger) !== null && _a !== void 0 ? _a : logger_1.DEFAULT_LOGGER_CONFIG);
34
- // Store original v1 for proxying
35
- this.originalV1 = this.v1;
36
- // Create logging proxy for v1
37
- this.v1 = this.createLoggingProxy(this.originalV1, 'v1');
38
- }
39
- /**
40
- * Create a proxy that wraps method calls with logging
41
- */
42
- createLoggingProxy(target, path) {
43
- const logger = this.logger;
44
- const sanitizeArgs = this.sanitizeArgs.bind(this);
45
- const createNestedProxy = this.createLoggingProxy.bind(this);
46
- return new Proxy(target, {
47
- get(target, property) {
48
- const value = target[property];
49
- if (typeof value === 'function') {
50
- // Wrap functions with logging
51
- return (...args) => __awaiter(this, void 0, void 0, function* () {
52
- const methodName = `${path}.${String(property)}`;
53
- logger.debug(`Calling ${methodName}`, { args: sanitizeArgs(args) });
54
- try {
55
- const startTime = Date.now();
56
- const result = yield value.apply(target, args);
57
- const duration = Date.now() - startTime;
58
- logger.debug(`${methodName} completed in ${duration}ms`, {
59
- duration,
60
- hasResult: result !== undefined
61
- });
62
- // Log status for operations that have status
63
- if (result && typeof result === 'object' && 'status' in result) {
64
- const level = result.status === 'error' ? 'error' : 'info';
65
- logger[level](`${methodName} status: ${result.status}`, {
66
- id: result.id,
67
- status: result.status,
68
- error: result.error
69
- });
70
- }
71
- return result;
72
- }
73
- catch (error) {
74
- logger.error(`${methodName} failed`, { error: error.message });
75
- throw error;
76
- }
77
- });
78
- }
79
- else if (value && typeof value === 'object') {
80
- // Recursively proxy nested objects
81
- return createNestedProxy(value, `${path}.${String(property)}`);
82
- }
83
- return value;
84
- }
85
- });
86
- }
87
- /**
88
- * Sanitize arguments for logging (remove sensitive data)
89
- */
90
- sanitizeArgs(args) {
91
- return args.map(arg => {
92
- if (arg && typeof arg === 'object') {
93
- const sanitized = Object.assign({}, arg);
94
- // Remove potential sensitive fields
95
- delete sanitized.token;
96
- delete sanitized.apiKey;
97
- delete sanitized.authorization;
98
- return sanitized;
99
- }
100
- return arg;
101
- });
102
- }
103
- /**
104
- * Update logger configuration at runtime
105
- */
106
- setLoggerConfig(config) {
107
- this.logger = (0, logger_1.createLogger)(config);
108
- }
109
- /**
110
- * Get current logger instance
111
- */
112
- getLogger() {
113
- return this.logger;
114
- }
115
- }
116
- exports.LoggingClient = LoggingClient;