magic-hour 0.43.1 → 0.44.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 +82 -77
- package/dist/core/api-error.d.ts +6 -0
- package/dist/core/api-error.js +11 -0
- package/dist/core/api-promise.d.ts +28 -0
- package/dist/core/api-promise.js +252 -0
- package/dist/core/auth.d.ts +76 -0
- package/dist/core/auth.js +232 -0
- package/dist/core/binary-response.d.ts +6 -0
- package/dist/core/binary-response.js +10 -0
- package/dist/core/content-type.d.ts +4 -0
- package/dist/core/content-type.js +12 -0
- package/dist/core/core-client.d.ts +58 -0
- package/dist/core/core-client.js +168 -0
- package/dist/core/form-data.d.ts +26 -0
- package/dist/core/form-data.js +83 -0
- package/dist/core/index.d.ts +9 -0
- package/dist/core/index.js +28 -0
- package/dist/core/logger.d.ts +48 -0
- package/dist/core/logger.js +82 -0
- package/dist/core/query.d.ts +8 -0
- package/dist/core/query.js +77 -0
- package/dist/core/runtime.d.ts +4 -0
- package/dist/core/runtime.js +20 -0
- package/dist/core/zod.d.ts +13 -0
- package/dist/core/zod.js +60 -0
- package/dist/environment.d.ts +1 -1
- package/dist/environment.js +1 -1
- package/dist/examples/logging-example.d.ts +10 -0
- package/dist/examples/logging-example.js +137 -0
- package/dist/logging-client.d.ts +39 -0
- package/dist/logging-client.js +116 -0
- package/dist/resources/v1/ai-voice-cloner/index.d.ts +2 -0
- package/dist/resources/v1/ai-voice-cloner/index.js +5 -0
- package/dist/resources/v1/ai-voice-cloner/request-types.d.ts +31 -0
- package/dist/resources/v1/ai-voice-cloner/request-types.js +77 -0
- package/dist/resources/v1/ai-voice-cloner/resource-client.d.ts +55 -0
- package/dist/resources/v1/ai-voice-cloner/resource-client.js +99 -0
- package/dist/resources/v1/index.d.ts +1 -0
- package/dist/resources/v1/index.js +2 -1
- package/dist/resources/v1/resource-client.d.ts +3 -0
- package/dist/resources/v1/resource-client.js +6 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/v1-ai-voice-cloner-create-body-assets.d.ts +27 -0
- package/dist/types/v1-ai-voice-cloner-create-body-assets.js +67 -0
- package/dist/types/v1-ai-voice-cloner-create-body-style.d.ts +22 -0
- package/dist/types/v1-ai-voice-cloner-create-body-style.js +67 -0
- package/dist/types/v1-ai-voice-cloner-create-body.d.ts +31 -0
- package/dist/types/v1-ai-voice-cloner-create-body.js +77 -0
- package/dist/types/v1-ai-voice-cloner-create-response.d.ts +29 -0
- package/dist/types/v1-ai-voice-cloner-create-response.js +71 -0
- package/package.json +1 -1
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Logging levels for the SDK
|
|
3
|
+
*/
|
|
4
|
+
export declare enum LogLevel {
|
|
5
|
+
NONE = 0,
|
|
6
|
+
ERROR = 1,
|
|
7
|
+
WARN = 2,
|
|
8
|
+
INFO = 3,
|
|
9
|
+
DEBUG = 4
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Logger interface for the Magic Hour SDK
|
|
13
|
+
*/
|
|
14
|
+
export interface Logger {
|
|
15
|
+
/**
|
|
16
|
+
* Log an error message
|
|
17
|
+
*/
|
|
18
|
+
error(message: string, ...args: any[]): void;
|
|
19
|
+
/**
|
|
20
|
+
* Log a warning message
|
|
21
|
+
*/
|
|
22
|
+
warn(message: string, ...args: any[]): void;
|
|
23
|
+
/**
|
|
24
|
+
* Log an info message
|
|
25
|
+
*/
|
|
26
|
+
info(message: string, ...args: any[]): void;
|
|
27
|
+
/**
|
|
28
|
+
* Log a debug message
|
|
29
|
+
*/
|
|
30
|
+
debug(message: string, ...args: any[]): void;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Configuration options for the logger
|
|
34
|
+
*/
|
|
35
|
+
export interface LoggerConfig {
|
|
36
|
+
level: LogLevel;
|
|
37
|
+
logger?: Logger;
|
|
38
|
+
includeTimestamp?: boolean;
|
|
39
|
+
includeRequestId?: boolean;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Create a logger instance based on configuration
|
|
43
|
+
*/
|
|
44
|
+
export declare function createLogger(config: LoggerConfig): Logger;
|
|
45
|
+
/**
|
|
46
|
+
* Default logger configuration
|
|
47
|
+
*/
|
|
48
|
+
export declare const DEFAULT_LOGGER_CONFIG: LoggerConfig;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_LOGGER_CONFIG = exports.LogLevel = void 0;
|
|
4
|
+
exports.createLogger = createLogger;
|
|
5
|
+
/**
|
|
6
|
+
* Logging levels for the SDK
|
|
7
|
+
*/
|
|
8
|
+
var LogLevel;
|
|
9
|
+
(function (LogLevel) {
|
|
10
|
+
LogLevel[LogLevel["NONE"] = 0] = "NONE";
|
|
11
|
+
LogLevel[LogLevel["ERROR"] = 1] = "ERROR";
|
|
12
|
+
LogLevel[LogLevel["WARN"] = 2] = "WARN";
|
|
13
|
+
LogLevel[LogLevel["INFO"] = 3] = "INFO";
|
|
14
|
+
LogLevel[LogLevel["DEBUG"] = 4] = "DEBUG";
|
|
15
|
+
})(LogLevel || (exports.LogLevel = LogLevel = {}));
|
|
16
|
+
/**
|
|
17
|
+
* Default logger implementation using console
|
|
18
|
+
*/
|
|
19
|
+
class ConsoleLogger {
|
|
20
|
+
constructor(config) {
|
|
21
|
+
this.config = config;
|
|
22
|
+
}
|
|
23
|
+
shouldLog(level) {
|
|
24
|
+
return level <= this.config.level;
|
|
25
|
+
}
|
|
26
|
+
formatMessage(level, message) {
|
|
27
|
+
const timestamp = this.config.includeTimestamp
|
|
28
|
+
? `[${new Date().toISOString()}]`
|
|
29
|
+
: "";
|
|
30
|
+
const levelStr = `[${level.toUpperCase()}]`;
|
|
31
|
+
return [timestamp, levelStr, message].filter(Boolean).join(" ");
|
|
32
|
+
}
|
|
33
|
+
error(message, ...args) {
|
|
34
|
+
if (this.shouldLog(LogLevel.ERROR)) {
|
|
35
|
+
console.error(this.formatMessage("error", message), ...args);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
warn(message, ...args) {
|
|
39
|
+
if (this.shouldLog(LogLevel.WARN)) {
|
|
40
|
+
console.warn(this.formatMessage("warn", message), ...args);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
info(message, ...args) {
|
|
44
|
+
if (this.shouldLog(LogLevel.INFO)) {
|
|
45
|
+
console.info(this.formatMessage("info", message), ...args);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
debug(message, ...args) {
|
|
49
|
+
if (this.shouldLog(LogLevel.DEBUG)) {
|
|
50
|
+
console.debug(this.formatMessage("debug", message), ...args);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* No-operation logger for when logging is disabled
|
|
56
|
+
*/
|
|
57
|
+
class NoOpLogger {
|
|
58
|
+
error() { }
|
|
59
|
+
warn() { }
|
|
60
|
+
info() { }
|
|
61
|
+
debug() { }
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Create a logger instance based on configuration
|
|
65
|
+
*/
|
|
66
|
+
function createLogger(config) {
|
|
67
|
+
if (config.level === LogLevel.NONE) {
|
|
68
|
+
return new NoOpLogger();
|
|
69
|
+
}
|
|
70
|
+
if (config.logger) {
|
|
71
|
+
return config.logger;
|
|
72
|
+
}
|
|
73
|
+
return new ConsoleLogger(config);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Default logger configuration
|
|
77
|
+
*/
|
|
78
|
+
exports.DEFAULT_LOGGER_CONFIG = {
|
|
79
|
+
level: LogLevel.INFO,
|
|
80
|
+
includeTimestamp: false,
|
|
81
|
+
includeRequestId: false,
|
|
82
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type QueryStyle = "form" | "spaceDelimited" | "pipeDelimited" | "deepObject";
|
|
2
|
+
export interface EncodeQueryParamProps {
|
|
3
|
+
name: string;
|
|
4
|
+
value: any;
|
|
5
|
+
style: QueryStyle;
|
|
6
|
+
explode: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare function encodeQueryParam({ name, value, style, explode, }: EncodeQueryParamProps): string;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.encodeQueryParam = encodeQueryParam;
|
|
7
|
+
const qs_1 = __importDefault(require("qs"));
|
|
8
|
+
function encodeQueryParam({ name, value, style, explode, }) {
|
|
9
|
+
switch (style) {
|
|
10
|
+
case "form":
|
|
11
|
+
return encodeForm(name, value, explode);
|
|
12
|
+
case "spaceDelimited":
|
|
13
|
+
return encodeSpaceDelimited(name, value, explode);
|
|
14
|
+
case "pipeDelimited":
|
|
15
|
+
return encodePipeDelimited(name, value, explode);
|
|
16
|
+
case "deepObject":
|
|
17
|
+
return encodeDeepObj(name, value, explode);
|
|
18
|
+
default:
|
|
19
|
+
throw new Error(`query param style '${style}' not implemented`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function encodeForm(name, value, explode) {
|
|
23
|
+
if (Array.isArray(value)) {
|
|
24
|
+
return qs_1.default.stringify({ [name]: value }, { arrayFormat: explode ? "repeat" : "comma" });
|
|
25
|
+
}
|
|
26
|
+
else if (typeof value === "object" && value != null) {
|
|
27
|
+
if (explode) {
|
|
28
|
+
// explode form objects should be encoded like /users?key0=val0&key1=val1
|
|
29
|
+
// the input param name will be omitted
|
|
30
|
+
return Object.entries(value)
|
|
31
|
+
.map(([k, v]) => qs_1.default.stringify({ [k]: v }))
|
|
32
|
+
.join("&");
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
// non-explode form objects should be encoded like /users?id=key0,val0,key1,val1
|
|
36
|
+
return qs_1.default.stringify({ [name]: Object.entries(value).flat() }, { arrayFormat: "comma" });
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
return qs_1.default.stringify({ [name]: value });
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function encodeSpaceDelimited(name, value, explode) {
|
|
44
|
+
if (Array.isArray(value) && !explode) {
|
|
45
|
+
// non-explode spaceDelimited arrays should be encoded like /users?id=3%204%205
|
|
46
|
+
return qs_1.default.stringify({ [name]: value.map((v) => String(v)).join(" ") });
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
// according to the docs, spaceDelimited + explode=false only effects lists,
|
|
50
|
+
// all other encodings are marked as n/a or are the same as `form` style
|
|
51
|
+
// fall back on form style as it is the default for query params
|
|
52
|
+
return encodeForm(name, value, explode);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function encodePipeDelimited(name, value, explode) {
|
|
56
|
+
if (Array.isArray(value) && !explode) {
|
|
57
|
+
// non-explode pipeDelimited arrays should be encoded like /users?id=3|4|5
|
|
58
|
+
return qs_1.default.stringify({ [name]: value.map((v) => String(v)).join("|") });
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
// according to the docs, spaceDelimited + explode=false only effects lists,
|
|
62
|
+
// all other encodings are marked as n/a or are the same as `form` style
|
|
63
|
+
// fall back on form style as it is the default for query params
|
|
64
|
+
return encodeForm(name, value, explode);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function encodeDeepObj(name, value, explode) {
|
|
68
|
+
if ((Array.isArray(value) || typeof value === "object") && value != null) {
|
|
69
|
+
return qs_1.default.stringify({ [name]: value });
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
// according to the docs, deepObject style only applies to
|
|
73
|
+
// object encodes, encodings for primitives & arrays are listed as n/a,
|
|
74
|
+
// fall back on form style as it is the default for query params
|
|
75
|
+
return encodeForm(name, value, explode);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.RUNTIME = void 0;
|
|
5
|
+
const isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
6
|
+
const isNode = typeof process !== "undefined" &&
|
|
7
|
+
Boolean(process.version) &&
|
|
8
|
+
Boolean((_a = process.versions) === null || _a === void 0 ? void 0 : _a.node);
|
|
9
|
+
function getRuntime() {
|
|
10
|
+
if (isBrowser) {
|
|
11
|
+
return { type: "browser" };
|
|
12
|
+
}
|
|
13
|
+
else if (isNode) {
|
|
14
|
+
return { type: "node" };
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
return { type: "unknown" };
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.RUNTIME = getRuntime();
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
import { type UploadFile } from "./form-data";
|
|
3
|
+
/**
|
|
4
|
+
* Generic function to transform an objects keys from one string to another.
|
|
5
|
+
* If the incoming object does not have a transform key, the original key is retained.
|
|
6
|
+
* If the incoming object has a key that maps to a `null` transform key, then
|
|
7
|
+
* the value is skipped.
|
|
8
|
+
*/
|
|
9
|
+
export declare function zodTransform<Input extends Record<string, unknown>, const Transformer extends {
|
|
10
|
+
[k in keyof Input]?: string | null;
|
|
11
|
+
}>(input: Input, transformer: Transformer): any;
|
|
12
|
+
export declare const zodUploadFile: z.ZodType<UploadFile, z.ZodTypeDef, UploadFile>;
|
|
13
|
+
export declare const zodRequiredAny: z.ZodType<Required<any>, z.ZodTypeDef, Required<any>>;
|
package/dist/core/zod.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
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);
|
package/dist/environment.d.ts
CHANGED
package/dist/environment.js
CHANGED
|
@@ -4,5 +4,5 @@ exports.Environment = void 0;
|
|
|
4
4
|
var Environment;
|
|
5
5
|
(function (Environment) {
|
|
6
6
|
Environment["Environment"] = "https://api.magichour.ai";
|
|
7
|
-
Environment["MockServer"] = "https://api.sideko.dev/v1/mock/magichour/magic-hour/0.
|
|
7
|
+
Environment["MockServer"] = "https://api.sideko.dev/v1/mock/magichour/magic-hour/0.43.1";
|
|
8
8
|
})(Environment || (exports.Environment = Environment = {}));
|
|
@@ -0,0 +1,10 @@
|
|
|
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 };
|
|
@@ -0,0 +1,137 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
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;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AiVoiceClonerClient = void 0;
|
|
4
|
+
var resource_client_1 = require("./resource-client");
|
|
5
|
+
Object.defineProperty(exports, "AiVoiceClonerClient", { enumerable: true, get: function () { return resource_client_1.AiVoiceClonerClient; } });
|