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.
- package/dist/environment.d.ts +1 -1
- package/dist/environment.js +1 -1
- package/dist/resources/v1/ai-image-editor/resource-client.d.ts +1 -1
- package/dist/resources/v1/ai-image-editor/resource-client.js +1 -1
- package/dist/resources/v1/ai-image-generator/request-types.d.ts +48 -4
- package/dist/resources/v1/ai-image-generator/request-types.js +30 -2
- package/dist/resources/v1/ai-image-generator/resource-client.d.ts +1 -1
- package/dist/resources/v1/ai-image-generator/resource-client.js +1 -1
- package/dist/resources/v1/image-to-video/request-types.d.ts +29 -7
- package/dist/resources/v1/image-to-video/request-types.js +24 -0
- package/dist/resources/v1/text-to-video/request-types.d.ts +41 -12
- package/dist/resources/v1/text-to-video/request-types.js +30 -2
- package/dist/types/index.d.ts +6 -0
- package/dist/types/v1-ai-image-editor-create-body-style-model-enum.d.ts +2 -1
- package/dist/types/v1-ai-image-editor-create-body-style.d.ts +2 -1
- package/dist/types/v1-ai-image-generator-create-body-aspect-ratio-enum.d.ts +4 -0
- package/dist/types/v1-ai-image-generator-create-body-aspect-ratio-enum.js +2 -0
- package/dist/types/v1-ai-image-generator-create-body-model-enum.d.ts +24 -0
- package/dist/types/v1-ai-image-generator-create-body-model-enum.js +2 -0
- package/dist/types/v1-ai-image-generator-create-body-orientation-enum.d.ts +3 -1
- package/dist/types/v1-ai-image-generator-create-body-resolution-enum.d.ts +11 -0
- package/dist/types/v1-ai-image-generator-create-body-resolution-enum.js +2 -0
- package/dist/types/v1-ai-image-generator-create-body-style-quality-mode-enum.d.ts +5 -5
- package/dist/types/v1-ai-image-generator-create-body-style.d.ts +5 -5
- package/dist/types/v1-ai-image-generator-create-body.d.ts +48 -4
- package/dist/types/v1-ai-image-generator-create-body.js +30 -2
- package/dist/types/v1-ai-talking-photo-create-body-style-generation-mode-enum.d.ts +8 -5
- package/dist/types/v1-ai-talking-photo-create-body-style.d.ts +15 -6
- package/dist/types/v1-ai-talking-photo-create-body-style.js +20 -2
- package/dist/types/v1-image-projects-get-response.d.ts +1 -1
- package/dist/types/v1-image-to-video-create-body-assets.d.ts +1 -1
- package/dist/types/v1-image-to-video-create-body-model-enum.d.ts +11 -0
- package/dist/types/v1-image-to-video-create-body-model-enum.js +2 -0
- package/dist/types/v1-image-to-video-create-body-resolution-enum.d.ts +7 -6
- package/dist/types/v1-image-to-video-create-body.d.ts +29 -7
- package/dist/types/v1-image-to-video-create-body.js +24 -0
- package/dist/types/v1-text-to-video-create-body-aspect-ratio-enum.d.ts +10 -0
- package/dist/types/v1-text-to-video-create-body-aspect-ratio-enum.js +2 -0
- package/dist/types/v1-text-to-video-create-body-model-enum.d.ts +11 -0
- package/dist/types/v1-text-to-video-create-body-model-enum.js +2 -0
- package/dist/types/v1-text-to-video-create-body-orientation-enum.d.ts +1 -1
- package/dist/types/v1-text-to-video-create-body-resolution-enum.d.ts +7 -6
- package/dist/types/v1-text-to-video-create-body.d.ts +41 -12
- package/dist/types/v1-text-to-video-create-body.js +30 -2
- package/dist/types/v1-video-projects-get-response.d.ts +1 -1
- package/package.json +1 -1
- package/dist/core/api-error.d.ts +0 -6
- package/dist/core/api-error.js +0 -11
- package/dist/core/api-promise.d.ts +0 -28
- package/dist/core/api-promise.js +0 -252
- package/dist/core/auth.d.ts +0 -76
- package/dist/core/auth.js +0 -232
- package/dist/core/binary-response.d.ts +0 -6
- package/dist/core/binary-response.js +0 -10
- package/dist/core/content-type.d.ts +0 -4
- package/dist/core/content-type.js +0 -12
- package/dist/core/core-client.d.ts +0 -58
- package/dist/core/core-client.js +0 -168
- package/dist/core/form-data.d.ts +0 -26
- package/dist/core/form-data.js +0 -83
- package/dist/core/index.d.ts +0 -9
- package/dist/core/index.js +0 -28
- package/dist/core/logger.d.ts +0 -48
- package/dist/core/logger.js +0 -82
- package/dist/core/query.d.ts +0 -8
- package/dist/core/query.js +0 -77
- package/dist/core/runtime.d.ts +0 -4
- package/dist/core/runtime.js +0 -20
- package/dist/core/zod.d.ts +0 -13
- package/dist/core/zod.js +0 -60
- package/dist/examples/logging-example.d.ts +0 -10
- package/dist/examples/logging-example.js +0 -137
- package/dist/logging-client.d.ts +0 -39
- package/dist/logging-client.js +0 -116
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import type * as z from "zod";
|
|
2
|
-
import type { Response as NodeResponse } from "node-fetch";
|
|
3
|
-
import type { AuthProvider } from "./auth";
|
|
4
|
-
import { ApiPromise } from "./api-promise";
|
|
5
|
-
import { type QueryStyle } from "./query";
|
|
6
|
-
export interface CoreClientProps {
|
|
7
|
-
baseUrl: string | Record<string, string | undefined>;
|
|
8
|
-
timeout?: number | undefined;
|
|
9
|
-
auths?: Record<string, AuthProvider>;
|
|
10
|
-
}
|
|
11
|
-
export type ApiResponse = Response | NodeResponse;
|
|
12
|
-
export type HttpMethod = "get" | "post" | "put" | "patch" | "delete";
|
|
13
|
-
export type RequestConfig = {
|
|
14
|
-
method: HttpMethod;
|
|
15
|
-
path: string;
|
|
16
|
-
serviceName?: string | undefined;
|
|
17
|
-
responseSchema?: z.Schema;
|
|
18
|
-
responseStream?: boolean;
|
|
19
|
-
responseRaw?: boolean;
|
|
20
|
-
auth?: string[];
|
|
21
|
-
query?: string[];
|
|
22
|
-
body?: any;
|
|
23
|
-
bodyEncoding?: {
|
|
24
|
-
style?: Record<string, QueryStyle>;
|
|
25
|
-
explode?: Record<string, boolean>;
|
|
26
|
-
};
|
|
27
|
-
contentType?: string;
|
|
28
|
-
headers?: Record<string, string>;
|
|
29
|
-
opts?: RequestOptions | undefined;
|
|
30
|
-
withCredentials?: boolean;
|
|
31
|
-
};
|
|
32
|
-
export interface RequestOptions {
|
|
33
|
-
timeout?: number;
|
|
34
|
-
additionalHeaders?: Record<string, string>;
|
|
35
|
-
additionalQuery?: Record<string, string>;
|
|
36
|
-
}
|
|
37
|
-
export declare class CoreClient {
|
|
38
|
-
private baseUrl;
|
|
39
|
-
private auths;
|
|
40
|
-
private timeout;
|
|
41
|
-
constructor(props: CoreClientProps);
|
|
42
|
-
private applyAuths;
|
|
43
|
-
buildUrl(path: string, serviceName?: string): string;
|
|
44
|
-
private buildUrlFromCfg;
|
|
45
|
-
private applyHeaders;
|
|
46
|
-
private encodeBodyByContentType;
|
|
47
|
-
private buildRequestInit;
|
|
48
|
-
private request;
|
|
49
|
-
makeRequest<R>(cfg: RequestConfig): ApiPromise<R>;
|
|
50
|
-
}
|
|
51
|
-
export interface ResourceClientOptions {
|
|
52
|
-
lazyLoad?: boolean | undefined;
|
|
53
|
-
}
|
|
54
|
-
export declare class CoreResourceClient {
|
|
55
|
-
protected _client: CoreClient;
|
|
56
|
-
protected _opts: ResourceClientOptions;
|
|
57
|
-
constructor(client: CoreClient, opts: ResourceClientOptions);
|
|
58
|
-
}
|
package/dist/core/core-client.js
DELETED
|
@@ -1,168 +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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.CoreResourceClient = exports.CoreClient = void 0;
|
|
13
|
-
const runtime_1 = require("./runtime");
|
|
14
|
-
const api_promise_1 = require("./api-promise");
|
|
15
|
-
const api_error_1 = require("./api-error");
|
|
16
|
-
const form_data_1 = require("./form-data");
|
|
17
|
-
const query_1 = require("./query");
|
|
18
|
-
const content_type_1 = require("./content-type");
|
|
19
|
-
const _DEFAULT_SERVICE_NAME = "__default_service__";
|
|
20
|
-
class CoreClient {
|
|
21
|
-
constructor(props) {
|
|
22
|
-
var _a;
|
|
23
|
-
this.baseUrl =
|
|
24
|
-
typeof props.baseUrl === "string"
|
|
25
|
-
? { [_DEFAULT_SERVICE_NAME]: props.baseUrl }
|
|
26
|
-
: props.baseUrl;
|
|
27
|
-
this.auths = (_a = props.auths) !== null && _a !== void 0 ? _a : {};
|
|
28
|
-
this.timeout = props.timeout;
|
|
29
|
-
}
|
|
30
|
-
applyAuths(cfg) {
|
|
31
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
-
var _a;
|
|
33
|
-
for (const name of (_a = cfg.auth) !== null && _a !== void 0 ? _a : []) {
|
|
34
|
-
const provider = this.auths[name];
|
|
35
|
-
if (provider) {
|
|
36
|
-
cfg = yield provider.applyAuth(cfg);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return cfg;
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
buildUrl(path, serviceName = _DEFAULT_SERVICE_NAME) {
|
|
43
|
-
var _a;
|
|
44
|
-
const baseUrl = (_a = this.baseUrl[serviceName !== null && serviceName !== void 0 ? serviceName : _DEFAULT_SERVICE_NAME]) !== null && _a !== void 0 ? _a : "";
|
|
45
|
-
const base = baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl;
|
|
46
|
-
const cleanPath = path.startsWith("/") ? path.slice(1) : path;
|
|
47
|
-
return `${base}/${cleanPath}`;
|
|
48
|
-
}
|
|
49
|
-
buildUrlFromCfg(cfg) {
|
|
50
|
-
var _a, _b, _c;
|
|
51
|
-
let url = this.buildUrl(cfg.path, cfg.serviceName);
|
|
52
|
-
const searchParams = new URLSearchParams(((_a = cfg.query) !== null && _a !== void 0 ? _a : []).join("&"));
|
|
53
|
-
for (const [key, val] of Object.entries((_c = (_b = cfg.opts) === null || _b === void 0 ? void 0 : _b.additionalQuery) !== null && _c !== void 0 ? _c : {})) {
|
|
54
|
-
searchParams.append(key, val);
|
|
55
|
-
}
|
|
56
|
-
if (searchParams.toString().length > 0) {
|
|
57
|
-
url += `?${searchParams.toString()}`;
|
|
58
|
-
}
|
|
59
|
-
return url;
|
|
60
|
-
}
|
|
61
|
-
applyHeaders(cfg, reqInit) {
|
|
62
|
-
var _a, _b, _c;
|
|
63
|
-
const finalHeaders = Object.assign(Object.assign(Object.assign(Object.assign({ "x-sideko-sdk-language": "Javascript", "x-sideko-runtime": runtime_1.RUNTIME.type }, ((_a = reqInit.headers) !== null && _a !== void 0 ? _a : {})), ((_b = cfg.headers) !== null && _b !== void 0 ? _b : {})), (cfg.contentType ? { "content-type": cfg.contentType } : {})), (_c = cfg.opts) === null || _c === void 0 ? void 0 : _c.additionalHeaders);
|
|
64
|
-
reqInit.headers = finalHeaders;
|
|
65
|
-
return reqInit;
|
|
66
|
-
}
|
|
67
|
-
encodeBodyByContentType(cfg, reqInit) {
|
|
68
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
69
|
-
const contentTypeOverride = (_c = (_b = (_a = cfg.opts) === null || _a === void 0 ? void 0 : _a.additionalHeaders) === null || _b === void 0 ? void 0 : _b["content-type"]) !== null && _c !== void 0 ? _c : (_e = (_d = cfg.opts) === null || _d === void 0 ? void 0 : _d.additionalHeaders) === null || _e === void 0 ? void 0 : _e["Content-Type"];
|
|
70
|
-
const contentType = (_f = contentTypeOverride !== null && contentTypeOverride !== void 0 ? contentTypeOverride : cfg.contentType) !== null && _f !== void 0 ? _f : "";
|
|
71
|
-
if (typeof cfg.body === "undefined") {
|
|
72
|
-
return reqInit;
|
|
73
|
-
}
|
|
74
|
-
else if (contentType.match(content_type_1.JSON_PATTERN)) {
|
|
75
|
-
reqInit.body = JSON.stringify(cfg.body);
|
|
76
|
-
}
|
|
77
|
-
else if (contentType.match(content_type_1.TEXT_PATTERN)) {
|
|
78
|
-
reqInit.body = String(cfg.body);
|
|
79
|
-
}
|
|
80
|
-
else if (contentType === content_type_1.MULTIPART_FORM) {
|
|
81
|
-
// encode form
|
|
82
|
-
const form = (0, form_data_1.createForm)(cfg.body);
|
|
83
|
-
const headers = (_g = reqInit.headers) !== null && _g !== void 0 ? _g : {};
|
|
84
|
-
if (runtime_1.RUNTIME.type === "node") {
|
|
85
|
-
// explicitly set boundary
|
|
86
|
-
headers["content-type"] = `${content_type_1.MULTIPART_FORM}; boundary=${form.getBoundary()}`;
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
// the browser should automatically set the content type
|
|
90
|
-
delete headers["content-type"];
|
|
91
|
-
}
|
|
92
|
-
reqInit.headers = headers;
|
|
93
|
-
reqInit.body = form;
|
|
94
|
-
}
|
|
95
|
-
else if (contentType === content_type_1.URL_FORM) {
|
|
96
|
-
if (typeof cfg.body !== "object") {
|
|
97
|
-
throw new TypeError("x-www-form-urlencoded data must be an object at the top level");
|
|
98
|
-
}
|
|
99
|
-
// encode form data
|
|
100
|
-
const styleMap = (_j = (_h = cfg.bodyEncoding) === null || _h === void 0 ? void 0 : _h.style) !== null && _j !== void 0 ? _j : {};
|
|
101
|
-
const explodeMap = (_l = (_k = cfg.bodyEncoding) === null || _k === void 0 ? void 0 : _k.explode) !== null && _l !== void 0 ? _l : {};
|
|
102
|
-
const formData = Object.entries(cfg.body).map(([name, value]) => {
|
|
103
|
-
var _a, _b;
|
|
104
|
-
const style = (_a = styleMap[name]) !== null && _a !== void 0 ? _a : "form";
|
|
105
|
-
const explode = (_b = explodeMap[name]) !== null && _b !== void 0 ? _b : style === "form";
|
|
106
|
-
return (0, query_1.encodeQueryParam)({ name, value, style, explode });
|
|
107
|
-
});
|
|
108
|
-
reqInit.body = formData.join("&");
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
// we expect body to already be encoded in the correct fashion
|
|
112
|
-
reqInit.body = cfg.body;
|
|
113
|
-
}
|
|
114
|
-
return reqInit;
|
|
115
|
-
}
|
|
116
|
-
buildRequestInit(cfg) {
|
|
117
|
-
let reqInit = { method: cfg.method.toUpperCase() };
|
|
118
|
-
reqInit = this.applyHeaders(cfg, reqInit);
|
|
119
|
-
reqInit = this.encodeBodyByContentType(cfg, reqInit);
|
|
120
|
-
if (cfg.withCredentials) {
|
|
121
|
-
reqInit.credentials = "include";
|
|
122
|
-
}
|
|
123
|
-
return reqInit;
|
|
124
|
-
}
|
|
125
|
-
request(cfg) {
|
|
126
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
127
|
-
var _a, _b;
|
|
128
|
-
const fetcherFn = runtime_1.RUNTIME.type === "node" || typeof fetch !== "function"
|
|
129
|
-
? require("node-fetch").default
|
|
130
|
-
: fetch;
|
|
131
|
-
cfg = yield this.applyAuths(cfg);
|
|
132
|
-
const reqInit = this.buildRequestInit(cfg);
|
|
133
|
-
const url = this.buildUrlFromCfg(cfg);
|
|
134
|
-
const timeout = (_b = (_a = cfg.opts) === null || _a === void 0 ? void 0 : _a.timeout) !== null && _b !== void 0 ? _b : this.timeout;
|
|
135
|
-
const controller = new AbortController();
|
|
136
|
-
let timeoutId;
|
|
137
|
-
if (typeof timeout !== "undefined") {
|
|
138
|
-
timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
139
|
-
}
|
|
140
|
-
reqInit.signal = controller.signal;
|
|
141
|
-
const response = yield fetcherFn(url, reqInit);
|
|
142
|
-
if (timeoutId) {
|
|
143
|
-
clearTimeout(timeoutId);
|
|
144
|
-
}
|
|
145
|
-
if (!response.ok) {
|
|
146
|
-
throw new api_error_1.ApiError(cfg, response);
|
|
147
|
-
}
|
|
148
|
-
return response;
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
makeRequest(cfg) {
|
|
152
|
-
var _a, _b;
|
|
153
|
-
return new api_promise_1.ApiPromise({
|
|
154
|
-
responsePromise: this.request(cfg),
|
|
155
|
-
responseRaw: (_a = cfg.responseRaw) !== null && _a !== void 0 ? _a : false,
|
|
156
|
-
responseStream: (_b = cfg.responseStream) !== null && _b !== void 0 ? _b : false,
|
|
157
|
-
responseSchema: cfg.responseSchema,
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
exports.CoreClient = CoreClient;
|
|
162
|
-
class CoreResourceClient {
|
|
163
|
-
constructor(client, opts) {
|
|
164
|
-
this._client = client;
|
|
165
|
-
this._opts = opts;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
exports.CoreResourceClient = CoreResourceClient;
|
package/dist/core/form-data.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { ReadStream as NodeReadStream } from "node:fs";
|
|
2
|
-
export type UploadFile = FileLike | NodeReadStream;
|
|
3
|
-
export declare function isUploadFile(val: any): val is UploadFile;
|
|
4
|
-
export declare function isNodeReadStream(val: any): val is NodeReadStream;
|
|
5
|
-
/**
|
|
6
|
-
* Defines common File spec compatible with modern browser File, node-fetch, etc.
|
|
7
|
-
*/
|
|
8
|
-
export interface FileLike extends BlobLike {
|
|
9
|
-
lastModified: number;
|
|
10
|
-
name: string;
|
|
11
|
-
}
|
|
12
|
-
export declare function isFileLike(val: any): val is FileLike;
|
|
13
|
-
/**
|
|
14
|
-
* Defines common Blob spec compatible with modern browser Blob, fetch-blob, etc.
|
|
15
|
-
*/
|
|
16
|
-
export interface BlobLike {
|
|
17
|
-
type: string;
|
|
18
|
-
size: number;
|
|
19
|
-
slice(start?: number, end?: number, type?: string): BlobLike;
|
|
20
|
-
text(): Promise<string>;
|
|
21
|
-
arrayBuffer(): Promise<ArrayBuffer>;
|
|
22
|
-
}
|
|
23
|
-
export declare function isBlobLike(val: any): val is BlobLike;
|
|
24
|
-
export declare function createForm(data: {
|
|
25
|
-
[key: string]: unknown;
|
|
26
|
-
}): any;
|
package/dist/core/form-data.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isUploadFile = isUploadFile;
|
|
4
|
-
exports.isNodeReadStream = isNodeReadStream;
|
|
5
|
-
exports.isFileLike = isFileLike;
|
|
6
|
-
exports.isBlobLike = isBlobLike;
|
|
7
|
-
exports.createForm = createForm;
|
|
8
|
-
const runtime_1 = require("./runtime");
|
|
9
|
-
function isUploadFile(val) {
|
|
10
|
-
return isFileLike(val) || isNodeReadStream(val);
|
|
11
|
-
}
|
|
12
|
-
function isNodeReadStream(val) {
|
|
13
|
-
// node read stream duck-typing check
|
|
14
|
-
return (runtime_1.RUNTIME.type === "node" &&
|
|
15
|
-
typeof val === "object" &&
|
|
16
|
-
typeof val.bytesRead === "number" &&
|
|
17
|
-
(typeof val.path === "string" || val.path instanceof Buffer) &&
|
|
18
|
-
typeof val.pending === "boolean" &&
|
|
19
|
-
typeof val.readable === "boolean" &&
|
|
20
|
-
typeof val.read === "function" &&
|
|
21
|
-
typeof val.setEncoding === "function" &&
|
|
22
|
-
typeof val.pause === "function" &&
|
|
23
|
-
typeof val.resume === "function" &&
|
|
24
|
-
typeof val.isPaused === "function" &&
|
|
25
|
-
typeof val.pipe === "function" &&
|
|
26
|
-
typeof val.unpipe === "function" &&
|
|
27
|
-
typeof val.unshift === "function" &&
|
|
28
|
-
typeof val.wrap === "function");
|
|
29
|
-
}
|
|
30
|
-
function isFileLike(val) {
|
|
31
|
-
// https://developer.mozilla.org/docs/Web/API/File
|
|
32
|
-
// https://github.com/node-fetch/fetch-blob/blob/main/file.js
|
|
33
|
-
return (typeof (val === null || val === void 0 ? void 0 : val.lastModified) === "number" &&
|
|
34
|
-
typeof (val === null || val === void 0 ? void 0 : val.name) === "string" &&
|
|
35
|
-
isBlobLike(val));
|
|
36
|
-
}
|
|
37
|
-
function isBlobLike(val) {
|
|
38
|
-
// https://developer.mozilla.org/docs/Web/API/Blob
|
|
39
|
-
// https://github.com/node-fetch/fetch-blob/blob/main/index.js
|
|
40
|
-
return (typeof (val === null || val === void 0 ? void 0 : val.size) === "number" &&
|
|
41
|
-
typeof (val === null || val === void 0 ? void 0 : val.type) === "string" &&
|
|
42
|
-
typeof (val === null || val === void 0 ? void 0 : val.slice) === "function" &&
|
|
43
|
-
typeof (val === null || val === void 0 ? void 0 : val.text) === "function" &&
|
|
44
|
-
typeof (val === null || val === void 0 ? void 0 : val.arrayBuffer) === "function");
|
|
45
|
-
}
|
|
46
|
-
function appendFormData(form, key, val) {
|
|
47
|
-
if (val === null || typeof val === "undefined") {
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
else if (["string", "boolean", "number"].includes(typeof val)) {
|
|
51
|
-
form.append(key, val.toString());
|
|
52
|
-
}
|
|
53
|
-
else if (Array.isArray(val)) {
|
|
54
|
-
for (const arrVal of val) {
|
|
55
|
-
appendFormData(form, key, arrVal);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
else if (isUploadFile(val)) {
|
|
59
|
-
form.append(key, val);
|
|
60
|
-
}
|
|
61
|
-
else if (typeof val === "object") {
|
|
62
|
-
for (const [objKey, objVal] of Object.entries(val)) {
|
|
63
|
-
appendFormData(form, `${key}[${objKey}]`, objVal);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
throw new TypeError(`Invalid value given to form: ${val}`);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
function createForm(data) {
|
|
71
|
-
let form;
|
|
72
|
-
if (runtime_1.RUNTIME.type === "node") {
|
|
73
|
-
const NodeFormData = require("form-data");
|
|
74
|
-
form = new NodeFormData();
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
form = new FormData();
|
|
78
|
-
}
|
|
79
|
-
for (const [key, val] of Object.entries(data)) {
|
|
80
|
-
appendFormData(form, key, val);
|
|
81
|
-
}
|
|
82
|
-
return form;
|
|
83
|
-
}
|
package/dist/core/index.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export { ApiError } from "./api-error";
|
|
2
|
-
export { ApiPromise, EventSourceResponse } from "./api-promise";
|
|
3
|
-
export { AuthBasic, AuthBearer, AuthKey, AuthProvider, OAuth2, OAuth2ClientCredentials, OAuth2Password, } from "./auth";
|
|
4
|
-
export { BinaryResponse } from "./binary-response";
|
|
5
|
-
export { ApiResponse, CoreClient, CoreClientProps, ResourceClientOptions, CoreResourceClient, RequestOptions, } from "./core-client";
|
|
6
|
-
export { createForm, isUploadFile, UploadFile } from "./form-data";
|
|
7
|
-
export { encodeQueryParam } from "./query";
|
|
8
|
-
export { RUNTIME } from "./runtime";
|
|
9
|
-
export { zodRequiredAny, zodTransform, zodUploadFile } from "./zod";
|
package/dist/core/index.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.zodUploadFile = exports.zodTransform = exports.zodRequiredAny = exports.RUNTIME = exports.encodeQueryParam = exports.isUploadFile = exports.createForm = exports.CoreResourceClient = exports.CoreClient = exports.BinaryResponse = exports.OAuth2 = exports.AuthKey = exports.AuthBearer = exports.AuthBasic = exports.ApiPromise = exports.ApiError = void 0;
|
|
4
|
-
var api_error_1 = require("./api-error");
|
|
5
|
-
Object.defineProperty(exports, "ApiError", { enumerable: true, get: function () { return api_error_1.ApiError; } });
|
|
6
|
-
var api_promise_1 = require("./api-promise");
|
|
7
|
-
Object.defineProperty(exports, "ApiPromise", { enumerable: true, get: function () { return api_promise_1.ApiPromise; } });
|
|
8
|
-
var auth_1 = require("./auth");
|
|
9
|
-
Object.defineProperty(exports, "AuthBasic", { enumerable: true, get: function () { return auth_1.AuthBasic; } });
|
|
10
|
-
Object.defineProperty(exports, "AuthBearer", { enumerable: true, get: function () { return auth_1.AuthBearer; } });
|
|
11
|
-
Object.defineProperty(exports, "AuthKey", { enumerable: true, get: function () { return auth_1.AuthKey; } });
|
|
12
|
-
Object.defineProperty(exports, "OAuth2", { enumerable: true, get: function () { return auth_1.OAuth2; } });
|
|
13
|
-
var binary_response_1 = require("./binary-response");
|
|
14
|
-
Object.defineProperty(exports, "BinaryResponse", { enumerable: true, get: function () { return binary_response_1.BinaryResponse; } });
|
|
15
|
-
var core_client_1 = require("./core-client");
|
|
16
|
-
Object.defineProperty(exports, "CoreClient", { enumerable: true, get: function () { return core_client_1.CoreClient; } });
|
|
17
|
-
Object.defineProperty(exports, "CoreResourceClient", { enumerable: true, get: function () { return core_client_1.CoreResourceClient; } });
|
|
18
|
-
var form_data_1 = require("./form-data");
|
|
19
|
-
Object.defineProperty(exports, "createForm", { enumerable: true, get: function () { return form_data_1.createForm; } });
|
|
20
|
-
Object.defineProperty(exports, "isUploadFile", { enumerable: true, get: function () { return form_data_1.isUploadFile; } });
|
|
21
|
-
var query_1 = require("./query");
|
|
22
|
-
Object.defineProperty(exports, "encodeQueryParam", { enumerable: true, get: function () { return query_1.encodeQueryParam; } });
|
|
23
|
-
var runtime_1 = require("./runtime");
|
|
24
|
-
Object.defineProperty(exports, "RUNTIME", { enumerable: true, get: function () { return runtime_1.RUNTIME; } });
|
|
25
|
-
var zod_1 = require("./zod");
|
|
26
|
-
Object.defineProperty(exports, "zodRequiredAny", { enumerable: true, get: function () { return zod_1.zodRequiredAny; } });
|
|
27
|
-
Object.defineProperty(exports, "zodTransform", { enumerable: true, get: function () { return zod_1.zodTransform; } });
|
|
28
|
-
Object.defineProperty(exports, "zodUploadFile", { enumerable: true, get: function () { return zod_1.zodUploadFile; } });
|
package/dist/core/logger.d.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
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;
|
package/dist/core/logger.js
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
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
|
-
};
|
package/dist/core/query.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
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;
|
package/dist/core/query.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
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
|
-
}
|
package/dist/core/runtime.d.ts
DELETED
package/dist/core/runtime.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
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();
|
package/dist/core/zod.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
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>>;
|