magic-hour 0.47.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/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/package.json +2 -2
- 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
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.49.0";
|
|
8
8
|
})(Environment || (exports.Environment = Environment = {}));
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Controls overall motion style.
|
|
3
|
-
* * `
|
|
4
|
-
* * `
|
|
3
|
+
* * `realistic` - Maintains likeness well, high quality, and reliable.
|
|
4
|
+
* * `prompted` - Slightly lower likeness; allows option to prompt scene.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
* * `
|
|
6
|
+
* **Deprecated values (maintained for backward compatibility):**
|
|
7
|
+
* * `pro` - Deprecated: use `realistic`
|
|
8
|
+
* * `standard` - Deprecated: use `prompted`
|
|
9
|
+
* * `stable` - Deprecated: use `realistic`
|
|
10
|
+
* * `expressive` - Deprecated: use `prompted`
|
|
8
11
|
*/
|
|
9
|
-
export type V1AiTalkingPhotoCreateBodyStyleGenerationModeEnum = "expressive" | "pro" | "stable" | "standard";
|
|
12
|
+
export type V1AiTalkingPhotoCreateBodyStyleGenerationModeEnum = "expressive" | "pro" | "prompted" | "realistic" | "stable" | "standard";
|
|
@@ -5,19 +5,27 @@ import * as z from "zod";
|
|
|
5
5
|
export type V1AiTalkingPhotoCreateBodyStyle = {
|
|
6
6
|
/**
|
|
7
7
|
* Controls overall motion style.
|
|
8
|
-
* * `
|
|
9
|
-
* * `
|
|
8
|
+
* * `realistic` - Maintains likeness well, high quality, and reliable.
|
|
9
|
+
* * `prompted` - Slightly lower likeness; allows option to prompt scene.
|
|
10
10
|
*
|
|
11
|
-
*
|
|
12
|
-
* * `
|
|
11
|
+
* **Deprecated values (maintained for backward compatibility):**
|
|
12
|
+
* * `pro` - Deprecated: use `realistic`
|
|
13
|
+
* * `standard` - Deprecated: use `prompted`
|
|
14
|
+
* * `stable` - Deprecated: use `realistic`
|
|
15
|
+
* * `expressive` - Deprecated: use `prompted`
|
|
13
16
|
*/
|
|
14
|
-
generationMode?: ("expressive" | "pro" | "stable" | "standard") | undefined;
|
|
17
|
+
generationMode?: ("expressive" | "pro" | "prompted" | "realistic" | "stable" | "standard") | undefined;
|
|
15
18
|
/**
|
|
16
19
|
* Note: this value is only applicable when generation_mode is `expressive`. The value can include up to 2 decimal places.
|
|
17
20
|
* * Lower values yield more stability but can suppress mouth movement.
|
|
18
21
|
* * Higher values increase motion and expressiveness, with a higher risk of distortion.
|
|
19
22
|
*/
|
|
20
23
|
intensity?: number | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* A text prompt to guide the generation. Only applicable when generation_mode is `prompted`.
|
|
26
|
+
* This field is ignored for other modes.
|
|
27
|
+
*/
|
|
28
|
+
prompt?: string | undefined;
|
|
21
29
|
};
|
|
22
30
|
/**
|
|
23
31
|
* @internal
|
|
@@ -25,8 +33,9 @@ export type V1AiTalkingPhotoCreateBodyStyle = {
|
|
|
25
33
|
* we expect to come in as network data
|
|
26
34
|
*/
|
|
27
35
|
export type External$V1AiTalkingPhotoCreateBodyStyle = {
|
|
28
|
-
generation_mode?: ("expressive" | "pro" | "stable" | "standard") | undefined;
|
|
36
|
+
generation_mode?: ("expressive" | "pro" | "prompted" | "realistic" | "stable" | "standard") | undefined;
|
|
29
37
|
intensity?: number | undefined;
|
|
38
|
+
prompt?: string | undefined;
|
|
30
39
|
};
|
|
31
40
|
export declare const Schemas$V1AiTalkingPhotoCreateBodyStyle: {
|
|
32
41
|
in: z.ZodType<V1AiTalkingPhotoCreateBodyStyle, z.ZodTypeDef, unknown>;
|
|
@@ -42,14 +42,23 @@ const z = __importStar(require("zod"));
|
|
|
42
42
|
const SchemaIn$V1AiTalkingPhotoCreateBodyStyle = z
|
|
43
43
|
.object({
|
|
44
44
|
generation_mode: z
|
|
45
|
-
.enum([
|
|
45
|
+
.enum([
|
|
46
|
+
"expressive",
|
|
47
|
+
"pro",
|
|
48
|
+
"prompted",
|
|
49
|
+
"realistic",
|
|
50
|
+
"stable",
|
|
51
|
+
"standard",
|
|
52
|
+
])
|
|
46
53
|
.optional(),
|
|
47
54
|
intensity: z.number().optional(),
|
|
55
|
+
prompt: z.string().optional(),
|
|
48
56
|
})
|
|
49
57
|
.transform((obj) => {
|
|
50
58
|
return (0, make_api_request_js_1.zodTransform)(obj, {
|
|
51
59
|
generation_mode: "generationMode",
|
|
52
60
|
intensity: "intensity",
|
|
61
|
+
prompt: "prompt",
|
|
53
62
|
});
|
|
54
63
|
});
|
|
55
64
|
/**
|
|
@@ -59,14 +68,23 @@ const SchemaIn$V1AiTalkingPhotoCreateBodyStyle = z
|
|
|
59
68
|
const SchemaOut$V1AiTalkingPhotoCreateBodyStyle = z
|
|
60
69
|
.object({
|
|
61
70
|
generationMode: z
|
|
62
|
-
.enum([
|
|
71
|
+
.enum([
|
|
72
|
+
"expressive",
|
|
73
|
+
"pro",
|
|
74
|
+
"prompted",
|
|
75
|
+
"realistic",
|
|
76
|
+
"stable",
|
|
77
|
+
"standard",
|
|
78
|
+
])
|
|
63
79
|
.optional(),
|
|
64
80
|
intensity: z.number().optional(),
|
|
81
|
+
prompt: z.string().optional(),
|
|
65
82
|
})
|
|
66
83
|
.transform((obj) => {
|
|
67
84
|
return (0, make_api_request_js_1.zodTransform)(obj, {
|
|
68
85
|
generationMode: "generation_mode",
|
|
69
86
|
intensity: "intensity",
|
|
87
|
+
prompt: "prompt",
|
|
70
88
|
});
|
|
71
89
|
});
|
|
72
90
|
exports.Schemas$V1AiTalkingPhotoCreateBodyStyle = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "magic-hour",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.48.0",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -59,4 +59,4 @@
|
|
|
59
59
|
"type": "git",
|
|
60
60
|
"url": "git://github.com/magichourhq/magic-hour-node.git"
|
|
61
61
|
}
|
|
62
|
-
}
|
|
62
|
+
}
|
package/dist/core/api-error.d.ts
DELETED
package/dist/core/api-error.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ApiError = void 0;
|
|
4
|
-
class ApiError extends Error {
|
|
5
|
-
constructor(request, response) {
|
|
6
|
-
super(`${response.status} was returned from ${request.method} ${request.path}`);
|
|
7
|
-
this.request = request;
|
|
8
|
-
this.response = response;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
exports.ApiError = ApiError;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type * as z from "zod";
|
|
2
|
-
import type { ApiResponse } from "./core-client";
|
|
3
|
-
export interface ApiPromiseProps {
|
|
4
|
-
responsePromise: Promise<ApiResponse>;
|
|
5
|
-
responseStream: boolean;
|
|
6
|
-
responseRaw: boolean;
|
|
7
|
-
responseSchema?: z.Schema | undefined;
|
|
8
|
-
}
|
|
9
|
-
export type EventSourceResponse<T> = AsyncIterableIterator<T>;
|
|
10
|
-
export declare class ApiPromise<T> extends Promise<T> implements AsyncIterator<T>, AsyncIterable<T> {
|
|
11
|
-
private responseProps;
|
|
12
|
-
constructor(responseProps: ApiPromiseProps);
|
|
13
|
-
/**
|
|
14
|
-
* Gets the raw response as returned by `fetch` rather than automatically
|
|
15
|
-
* parsing the response.
|
|
16
|
-
*/
|
|
17
|
-
asResponse(): Promise<ApiResponse>;
|
|
18
|
-
private getResponseType;
|
|
19
|
-
private parseResponse;
|
|
20
|
-
private handleNodeStream;
|
|
21
|
-
private handleWebStream;
|
|
22
|
-
asEventStream(): AsyncIterableIterator<T>;
|
|
23
|
-
next(): Promise<IteratorResult<T>>;
|
|
24
|
-
[Symbol.asyncIterator](): AsyncIterator<T>;
|
|
25
|
-
then<Result1 = T, Result2 = never>(onfulfilled?: ((value: T) => Result1 | PromiseLike<Result1>) | undefined | null, onrejected?: ((reason: any) => Result2 | PromiseLike<Result2>) | undefined | null): Promise<Result1 | Result2>;
|
|
26
|
-
catch<Result = never>(onrejected?: ((reason: any) => Result | PromiseLike<Result>) | undefined | null): Promise<T | Result>;
|
|
27
|
-
finally(onfinally?: (() => void) | undefined | null): Promise<T>;
|
|
28
|
-
}
|
package/dist/core/api-promise.js
DELETED
|
@@ -1,252 +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 __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
12
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
13
|
-
var m = o[Symbol.asyncIterator], i;
|
|
14
|
-
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
15
|
-
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
16
|
-
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
17
|
-
};
|
|
18
|
-
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
|
|
19
|
-
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
|
20
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
21
|
-
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
22
|
-
return i = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
23
|
-
function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
|
|
24
|
-
function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
|
|
25
|
-
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
26
|
-
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
27
|
-
function fulfill(value) { resume("next", value); }
|
|
28
|
-
function reject(value) { resume("throw", value); }
|
|
29
|
-
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
30
|
-
};
|
|
31
|
-
var __asyncDelegator = (this && this.__asyncDelegator) || function (o) {
|
|
32
|
-
var i, p;
|
|
33
|
-
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
|
|
34
|
-
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v; } : f; }
|
|
35
|
-
};
|
|
36
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
-
exports.ApiPromise = void 0;
|
|
38
|
-
const binary_response_1 = require("./binary-response");
|
|
39
|
-
const content_type_1 = require("./content-type");
|
|
40
|
-
class ApiPromise extends Promise {
|
|
41
|
-
constructor(responseProps) {
|
|
42
|
-
super((resolve) => {
|
|
43
|
-
resolve(null);
|
|
44
|
-
});
|
|
45
|
-
this.responseProps = responseProps;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Gets the raw response as returned by `fetch` rather than automatically
|
|
49
|
-
* parsing the response.
|
|
50
|
-
*/
|
|
51
|
-
asResponse() {
|
|
52
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
-
return yield this.responseProps.responsePromise;
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
getResponseType(contentType) {
|
|
57
|
-
if (content_type_1.JSON_PATTERN.test(contentType)) {
|
|
58
|
-
return "json";
|
|
59
|
-
}
|
|
60
|
-
else if (content_type_1.TEXT_PATTERN.test(contentType)) {
|
|
61
|
-
return "text";
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
return "binary";
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
parseResponse() {
|
|
68
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
-
var _a;
|
|
70
|
-
const { responsePromise, responseSchema, responseRaw } = this.responseProps;
|
|
71
|
-
const response = yield responsePromise;
|
|
72
|
-
if (response.status === 204) {
|
|
73
|
-
return null;
|
|
74
|
-
}
|
|
75
|
-
else if (responseRaw) {
|
|
76
|
-
return response;
|
|
77
|
-
}
|
|
78
|
-
const contentType = (_a = response.headers.get("content-type")) !== null && _a !== void 0 ? _a : "";
|
|
79
|
-
switch (this.getResponseType(contentType)) {
|
|
80
|
-
case "json": {
|
|
81
|
-
const rawJson = yield response.json();
|
|
82
|
-
return responseSchema ? responseSchema.parse(rawJson) : rawJson;
|
|
83
|
-
}
|
|
84
|
-
case "text":
|
|
85
|
-
return (yield response.text());
|
|
86
|
-
case "binary":
|
|
87
|
-
default:
|
|
88
|
-
return new binary_response_1.BinaryResponse(yield response.blob(), contentType);
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
handleNodeStream(stream) {
|
|
93
|
-
return __asyncGenerator(this, arguments, function* handleNodeStream_1() {
|
|
94
|
-
var _a, e_1, _b, _c;
|
|
95
|
-
const { responseSchema } = this.responseProps;
|
|
96
|
-
const parser = new EventSourceParser();
|
|
97
|
-
try {
|
|
98
|
-
for (var _d = true, stream_1 = __asyncValues(stream), stream_1_1; stream_1_1 = yield __await(stream_1.next()), _a = stream_1_1.done, !_a; _d = true) {
|
|
99
|
-
_c = stream_1_1.value;
|
|
100
|
-
_d = false;
|
|
101
|
-
const chunk = _c;
|
|
102
|
-
const text = chunk.toString();
|
|
103
|
-
const messages = parser.parse(text);
|
|
104
|
-
for (const message of messages) {
|
|
105
|
-
if (message.data) {
|
|
106
|
-
const rawJson = { data: JSON.parse(message.data) };
|
|
107
|
-
yield yield __await(responseSchema ? responseSchema.parse(rawJson) : rawJson);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
113
|
-
finally {
|
|
114
|
-
try {
|
|
115
|
-
if (!_d && !_a && (_b = stream_1.return)) yield __await(_b.call(stream_1));
|
|
116
|
-
}
|
|
117
|
-
finally { if (e_1) throw e_1.error; }
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
handleWebStream(stream) {
|
|
122
|
-
return __asyncGenerator(this, arguments, function* handleWebStream_1() {
|
|
123
|
-
const { responseSchema } = this.responseProps;
|
|
124
|
-
const reader = stream.getReader();
|
|
125
|
-
const decoder = new TextDecoder();
|
|
126
|
-
const parser = new EventSourceParser();
|
|
127
|
-
try {
|
|
128
|
-
while (true) {
|
|
129
|
-
const { done, value } = yield __await(reader.read());
|
|
130
|
-
if (done) {
|
|
131
|
-
break;
|
|
132
|
-
}
|
|
133
|
-
const chunk = decoder.decode(value, { stream: true });
|
|
134
|
-
const messages = parser.parse(chunk);
|
|
135
|
-
for (const message of messages) {
|
|
136
|
-
if (message.data) {
|
|
137
|
-
const rawJson = { data: JSON.parse(message.data) };
|
|
138
|
-
yield yield __await(responseSchema ? responseSchema.parse(rawJson) : rawJson);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
finally {
|
|
144
|
-
reader.releaseLock();
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
asEventStream() {
|
|
149
|
-
return __asyncGenerator(this, arguments, function* asEventStream_1() {
|
|
150
|
-
const { responsePromise, responseStream } = this.responseProps;
|
|
151
|
-
if (!responseStream) {
|
|
152
|
-
throw new Error("Response is not an event stream");
|
|
153
|
-
}
|
|
154
|
-
const response = yield __await(responsePromise);
|
|
155
|
-
if (!response.body) {
|
|
156
|
-
throw new Error("Response body is undefined");
|
|
157
|
-
}
|
|
158
|
-
// Check if we're in Node.js environment
|
|
159
|
-
if ("pipe" in response.body && typeof response.body.pipe === "function") {
|
|
160
|
-
yield __await(yield* __asyncDelegator(__asyncValues(this.handleNodeStream(response.body))));
|
|
161
|
-
}
|
|
162
|
-
else {
|
|
163
|
-
yield __await(yield* __asyncDelegator(__asyncValues(this.handleWebStream(response.body))));
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
next() {
|
|
168
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
169
|
-
const { responseStream } = this.responseProps;
|
|
170
|
-
if (responseStream) {
|
|
171
|
-
const iterator = this.asEventStream();
|
|
172
|
-
const result = yield iterator.next();
|
|
173
|
-
return result;
|
|
174
|
-
}
|
|
175
|
-
const value = yield this.parseResponse();
|
|
176
|
-
return { value, done: true };
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
[Symbol.asyncIterator]() {
|
|
180
|
-
const iterator = {
|
|
181
|
-
next: () => __awaiter(this, void 0, void 0, function* () {
|
|
182
|
-
const { responseStream } = this.responseProps;
|
|
183
|
-
if (responseStream) {
|
|
184
|
-
const stream = this.asEventStream();
|
|
185
|
-
return stream.next();
|
|
186
|
-
}
|
|
187
|
-
const value = yield this.parseResponse();
|
|
188
|
-
return { value, done: true };
|
|
189
|
-
}),
|
|
190
|
-
};
|
|
191
|
-
return iterator;
|
|
192
|
-
}
|
|
193
|
-
then(onfulfilled, onrejected) {
|
|
194
|
-
if (this.responseProps.responseStream) {
|
|
195
|
-
return Promise.resolve(this.asEventStream());
|
|
196
|
-
}
|
|
197
|
-
return this.parseResponse().then(onfulfilled, onrejected);
|
|
198
|
-
}
|
|
199
|
-
catch(onrejected) {
|
|
200
|
-
return this.parseResponse().catch(onrejected);
|
|
201
|
-
}
|
|
202
|
-
finally(onfinally) {
|
|
203
|
-
return this.parseResponse().finally(onfinally);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
exports.ApiPromise = ApiPromise;
|
|
207
|
-
class EventSourceParser {
|
|
208
|
-
constructor() {
|
|
209
|
-
this.buffer = "";
|
|
210
|
-
}
|
|
211
|
-
parse(chunk) {
|
|
212
|
-
this.buffer += chunk;
|
|
213
|
-
const messages = [];
|
|
214
|
-
const lines = this.buffer.split("\n");
|
|
215
|
-
// Keep the last line in buffer if it's not complete
|
|
216
|
-
this.buffer = lines.pop() || "";
|
|
217
|
-
let currentMessage = {};
|
|
218
|
-
for (const line of lines) {
|
|
219
|
-
if (line.trim() === "") {
|
|
220
|
-
if (currentMessage.data) {
|
|
221
|
-
const message = {
|
|
222
|
-
event: currentMessage.event,
|
|
223
|
-
data: currentMessage.data,
|
|
224
|
-
id: currentMessage.id,
|
|
225
|
-
};
|
|
226
|
-
messages.push(message);
|
|
227
|
-
}
|
|
228
|
-
currentMessage = {};
|
|
229
|
-
continue;
|
|
230
|
-
}
|
|
231
|
-
const [fieldName, ...fieldValue] = line.split(":");
|
|
232
|
-
const value = fieldValue.join(":").trim();
|
|
233
|
-
switch (fieldName) {
|
|
234
|
-
case "event":
|
|
235
|
-
currentMessage.event = value;
|
|
236
|
-
break;
|
|
237
|
-
case "data":
|
|
238
|
-
currentMessage.data = currentMessage.data
|
|
239
|
-
? currentMessage.data + "\n" + value
|
|
240
|
-
: value;
|
|
241
|
-
break;
|
|
242
|
-
case "id":
|
|
243
|
-
currentMessage.id = value;
|
|
244
|
-
break;
|
|
245
|
-
case "retry":
|
|
246
|
-
// Handle retry if needed
|
|
247
|
-
break;
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
return messages;
|
|
251
|
-
}
|
|
252
|
-
}
|
package/dist/core/auth.d.ts
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import type { RequestConfig } from "./core-client";
|
|
2
|
-
export interface AuthProvider {
|
|
3
|
-
applyAuth: (cfg: RequestConfig) => Promise<RequestConfig>;
|
|
4
|
-
setValue: (val?: string | undefined) => void;
|
|
5
|
-
}
|
|
6
|
-
export declare class AuthBasic implements AuthProvider {
|
|
7
|
-
username: string | null;
|
|
8
|
-
password: string | null;
|
|
9
|
-
constructor(username?: string, password?: string);
|
|
10
|
-
applyAuth(cfg: RequestConfig): Promise<RequestConfig>;
|
|
11
|
-
setValue(val?: string | undefined): void;
|
|
12
|
-
}
|
|
13
|
-
export declare class AuthBearer implements AuthProvider {
|
|
14
|
-
token: string | null;
|
|
15
|
-
constructor(token?: string);
|
|
16
|
-
applyAuth(cfg: RequestConfig): Promise<RequestConfig>;
|
|
17
|
-
setValue(val?: string | undefined): void;
|
|
18
|
-
}
|
|
19
|
-
export declare class AuthKey implements AuthProvider {
|
|
20
|
-
name: string;
|
|
21
|
-
location: "query" | "header" | "cookie";
|
|
22
|
-
key: string | null;
|
|
23
|
-
constructor(name: string, location: "query" | "header" | "cookie", key?: string);
|
|
24
|
-
applyAuth(cfg: RequestConfig): Promise<RequestConfig>;
|
|
25
|
-
setValue(val?: string | undefined): void;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* OAuth2 authentication props for a password flow
|
|
29
|
-
*
|
|
30
|
-
* Details:
|
|
31
|
-
* https://datatracker.ietf.org/doc/html/rfc6749#section-4.3
|
|
32
|
-
*/
|
|
33
|
-
export type OAuth2Password = {
|
|
34
|
-
username: string;
|
|
35
|
-
password: string;
|
|
36
|
-
clientId?: string | undefined;
|
|
37
|
-
clientSecret?: string | undefined;
|
|
38
|
-
grantType?: "password" | string | undefined;
|
|
39
|
-
scope?: string[] | undefined;
|
|
40
|
-
tokenUrl?: string | undefined;
|
|
41
|
-
};
|
|
42
|
-
/**
|
|
43
|
-
* OAuth2 authentication props for a client credentials flow
|
|
44
|
-
*
|
|
45
|
-
* Details:
|
|
46
|
-
* https://datatracker.ietf.org/doc/html/rfc6749#section-4.4
|
|
47
|
-
*/
|
|
48
|
-
export type OAuth2ClientCredentials = {
|
|
49
|
-
clientId: string;
|
|
50
|
-
clientSecret: string;
|
|
51
|
-
grantType?: "client_credentials" | string | undefined;
|
|
52
|
-
scope?: string[] | undefined;
|
|
53
|
-
tokenUrl?: string | undefined;
|
|
54
|
-
};
|
|
55
|
-
export type OAuth2ProviderProps = {
|
|
56
|
-
baseUrl: string;
|
|
57
|
-
defaultTokenUrl: string;
|
|
58
|
-
accessTokenPointer: string;
|
|
59
|
-
expiresInPointer: string;
|
|
60
|
-
credentialsLocation: "request_body" | "basic_authorization_header";
|
|
61
|
-
bodyContent: "form" | "json";
|
|
62
|
-
requestMutator: AuthProvider;
|
|
63
|
-
form?: OAuth2Password | OAuth2ClientCredentials | undefined;
|
|
64
|
-
};
|
|
65
|
-
export declare class OAuth2 implements AuthProvider {
|
|
66
|
-
props: OAuth2ProviderProps;
|
|
67
|
-
accessToken?: string | undefined;
|
|
68
|
-
expiresAt?: Date;
|
|
69
|
-
constructor(props: OAuth2ProviderProps);
|
|
70
|
-
refresh(form: OAuth2Password | OAuth2ClientCredentials): Promise<{
|
|
71
|
-
accessToken: string;
|
|
72
|
-
expiresAt: Date;
|
|
73
|
-
}>;
|
|
74
|
-
applyAuth(cfg: RequestConfig): Promise<RequestConfig>;
|
|
75
|
-
setValue(val?: string | undefined): void;
|
|
76
|
-
}
|