@fastpix/fastpix-node 1.0.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/LICENSE +201 -0
- package/README.md +509 -0
- package/dist/Live/index.d.ts +19 -0
- package/dist/Live/index.js +200 -0
- package/dist/NetworkFetcher/index.d.ts +7 -0
- package/dist/NetworkFetcher/index.js +74 -0
- package/dist/VideoOnDemand/index.d.ts +16 -0
- package/dist/VideoOnDemand/index.js +166 -0
- package/dist/index.cjs +635 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.js +166 -0
- package/dist/index.mjs +614 -0
- package/docs/Live/CreateLiveStream.md +48 -0
- package/docs/Live/ManageLiveStreams.md +116 -0
- package/docs/Live/ManageStreamPlayback.md +86 -0
- package/docs/Live/ManageStreamSimulcast.md +133 -0
- package/docs/VideoOnDemand/ManageMedia.md +147 -0
- package/docs/VideoOnDemand/ManageMediaPlayback.md +61 -0
- package/docs/VideoOnDemand/UploadMedia.md +320 -0
- package/package.json +37 -0
- package/types/index.d.ts +217 -0
|
@@ -0,0 +1,200 @@
|
|
|
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
|
+
const NetworkFetcher_1 = __importDefault(require("../NetworkFetcher"));
|
|
7
|
+
class LiveStream {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.fetch = new NetworkFetcher_1.default();
|
|
10
|
+
this.livePath = "live/streams";
|
|
11
|
+
}
|
|
12
|
+
// Creates a new live stream with the given properties.
|
|
13
|
+
async createNewLiveStream(props, requestObj) {
|
|
14
|
+
var _a, _b;
|
|
15
|
+
const path = this.livePath;
|
|
16
|
+
const url = this.fetch.constructUrl(requestObj, path);
|
|
17
|
+
const constructObject = {
|
|
18
|
+
...requestObj,
|
|
19
|
+
method: "POST",
|
|
20
|
+
body: {
|
|
21
|
+
playbackSettings: {
|
|
22
|
+
accessPolicy: (_b = (_a = props === null || props === void 0 ? void 0 : props.playbackSettings) === null || _a === void 0 ? void 0 : _a.accessPolicy) !== null && _b !== void 0 ? _b : "public",
|
|
23
|
+
},
|
|
24
|
+
inputMediaSettings: {
|
|
25
|
+
...props === null || props === void 0 ? void 0 : props.inputMediaSettings,
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
const createLiveStreamHeader = this.fetch.constructHeaders(constructObject);
|
|
30
|
+
const createLiveStreamResponse = await this.fetch.fetchData(url, createLiveStreamHeader);
|
|
31
|
+
return createLiveStreamResponse;
|
|
32
|
+
}
|
|
33
|
+
// Retrieves all live streams with pagination support.
|
|
34
|
+
async getAllLiveStreams(props, requestObj) {
|
|
35
|
+
var _a, _b, _c;
|
|
36
|
+
const path = this.livePath;
|
|
37
|
+
const queryParams = `?limit=${(_a = props === null || props === void 0 ? void 0 : props.limit) !== null && _a !== void 0 ? _a : 10}&offset=${(_b = props === null || props === void 0 ? void 0 : props.offset) !== null && _b !== void 0 ? _b : 1}&orderBy=${(_c = props === null || props === void 0 ? void 0 : props.orderBy) !== null && _c !== void 0 ? _c : "desc"}`;
|
|
38
|
+
const url = this.fetch.constructUrl(requestObj, path, queryParams);
|
|
39
|
+
const constructObject = {
|
|
40
|
+
...requestObj,
|
|
41
|
+
method: "GET",
|
|
42
|
+
};
|
|
43
|
+
const getAllLiveStreamHeader = this.fetch.constructHeaders(constructObject);
|
|
44
|
+
const getAllLiveStreamResponse = await this.fetch.fetchData(url, getAllLiveStreamHeader);
|
|
45
|
+
return getAllLiveStreamResponse;
|
|
46
|
+
}
|
|
47
|
+
// Retrieves details of a specific live stream.
|
|
48
|
+
async getLiveStream(props, requestObj) {
|
|
49
|
+
var _a;
|
|
50
|
+
const path = `${this.livePath}/${(_a = props === null || props === void 0 ? void 0 : props.streamId) !== null && _a !== void 0 ? _a : ""}`;
|
|
51
|
+
const url = this.fetch.constructUrl(requestObj, path);
|
|
52
|
+
const constructObject = {
|
|
53
|
+
...requestObj,
|
|
54
|
+
method: "GET",
|
|
55
|
+
};
|
|
56
|
+
const getLiveStreamHeader = this.fetch.constructHeaders(constructObject);
|
|
57
|
+
const getLiveStreamResponse = await this.fetch.fetchData(url, getLiveStreamHeader);
|
|
58
|
+
return getLiveStreamResponse;
|
|
59
|
+
}
|
|
60
|
+
// Updates a live stream with new properties.
|
|
61
|
+
async updateLiveStream(props, updateObject, requestObj) {
|
|
62
|
+
var _a;
|
|
63
|
+
const path = `${this.livePath}/${(_a = props === null || props === void 0 ? void 0 : props.streamId) !== null && _a !== void 0 ? _a : ""}`;
|
|
64
|
+
const url = this.fetch.constructUrl(requestObj, path);
|
|
65
|
+
const constructObject = {
|
|
66
|
+
...requestObj,
|
|
67
|
+
method: "PATCH",
|
|
68
|
+
body: {
|
|
69
|
+
...(updateObject !== null && updateObject !== void 0 ? updateObject : {}),
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
const updateLiveStreamHeader = this.fetch.constructHeaders(constructObject);
|
|
73
|
+
const updateLiveStreamResponse = await this.fetch.fetchData(url, updateLiveStreamHeader);
|
|
74
|
+
return updateLiveStreamResponse;
|
|
75
|
+
}
|
|
76
|
+
// Deletes a specific live stream.
|
|
77
|
+
async deleteLiveStream(props, requestObj) {
|
|
78
|
+
var _a;
|
|
79
|
+
const path = `${this.livePath}/${(_a = props === null || props === void 0 ? void 0 : props.streamId) !== null && _a !== void 0 ? _a : ""}`;
|
|
80
|
+
const url = this.fetch.constructUrl(requestObj, path);
|
|
81
|
+
const constructObject = {
|
|
82
|
+
...requestObj,
|
|
83
|
+
method: "DELETE",
|
|
84
|
+
};
|
|
85
|
+
const deleteLiveStream = this.fetch.constructHeaders(constructObject);
|
|
86
|
+
const deleteLiveStreamResponse = await this.fetch.fetchData(url, deleteLiveStream);
|
|
87
|
+
return deleteLiveStreamResponse;
|
|
88
|
+
}
|
|
89
|
+
// Creates a playback ID for a live stream with specified access policy.
|
|
90
|
+
async createLiveStreamPlaybackId(props, playbackPolicy, requestObj) {
|
|
91
|
+
var _a, _b;
|
|
92
|
+
const path = `${this.livePath}/${(_a = props === null || props === void 0 ? void 0 : props.streamId) !== null && _a !== void 0 ? _a : ""}/playback-ids`;
|
|
93
|
+
const url = this.fetch.constructUrl(requestObj, path);
|
|
94
|
+
const constructObject = {
|
|
95
|
+
...requestObj,
|
|
96
|
+
method: "POST",
|
|
97
|
+
body: {
|
|
98
|
+
accessPolicy: (_b = playbackPolicy === null || playbackPolicy === void 0 ? void 0 : playbackPolicy.accessPolicy) !== null && _b !== void 0 ? _b : "public",
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
const createPlaybackIdHeader = this.fetch.constructHeaders(constructObject);
|
|
102
|
+
const createPlaybackIdResponse = await this.fetch.fetchData(url, createPlaybackIdHeader);
|
|
103
|
+
return createPlaybackIdResponse;
|
|
104
|
+
}
|
|
105
|
+
// Removes a playback ID associated with a live stream.
|
|
106
|
+
async removeLivePlaybackId(props, requestObj) {
|
|
107
|
+
var _a;
|
|
108
|
+
const path = `${this.livePath}/${(_a = props === null || props === void 0 ? void 0 : props.streamId) !== null && _a !== void 0 ? _a : ""}/playback-ids`;
|
|
109
|
+
let queryParams = "";
|
|
110
|
+
if (props === null || props === void 0 ? void 0 : props.playbackId) {
|
|
111
|
+
if (Array.isArray(props.playbackId)) {
|
|
112
|
+
const playbackIdParams = props.playbackId.map((id) => "playbackId=" + id);
|
|
113
|
+
queryParams = "?" + playbackIdParams.join("&");
|
|
114
|
+
}
|
|
115
|
+
else if (typeof props.playbackId === "string") {
|
|
116
|
+
queryParams = "?playbackId=" + props.playbackId;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const url = this.fetch.constructUrl(requestObj, path, queryParams);
|
|
120
|
+
const constructObject = {
|
|
121
|
+
...requestObj,
|
|
122
|
+
method: "DELETE",
|
|
123
|
+
};
|
|
124
|
+
const deletePlaybackIdHeader = this.fetch.constructHeaders(constructObject);
|
|
125
|
+
const deletePlaybackIdResponse = await this.fetch.fetchData(url, deletePlaybackIdHeader);
|
|
126
|
+
return deletePlaybackIdResponse;
|
|
127
|
+
}
|
|
128
|
+
// Retrieves the playback policy for a specific playback ID in a live stream.
|
|
129
|
+
async getLiveStreamPlaybackPolicy(props, requestObj) {
|
|
130
|
+
var _a;
|
|
131
|
+
const path = `${this.livePath}/${(_a = props === null || props === void 0 ? void 0 : props.streamId) !== null && _a !== void 0 ? _a : ""}/playback-ids/${props === null || props === void 0 ? void 0 : props.playbackId}`;
|
|
132
|
+
const url = this.fetch.constructUrl(requestObj, path);
|
|
133
|
+
const constructObject = {
|
|
134
|
+
...requestObj,
|
|
135
|
+
method: "GET",
|
|
136
|
+
};
|
|
137
|
+
const getLiveStreamPlaybackPolicyHeader = this.fetch.constructHeaders(constructObject);
|
|
138
|
+
const getLiveStreamPlaybackPolicyResponse = await this.fetch.fetchData(url, getLiveStreamPlaybackPolicyHeader);
|
|
139
|
+
return getLiveStreamPlaybackPolicyResponse;
|
|
140
|
+
}
|
|
141
|
+
// Creates a new simulcast target for a live stream.
|
|
142
|
+
async createLiveStreamSimulcast(props, liveStreamObj, requestObj) {
|
|
143
|
+
var _a;
|
|
144
|
+
const path = `${this.livePath}/${(_a = props === null || props === void 0 ? void 0 : props.streamId) !== null && _a !== void 0 ? _a : ""}/simulcast`;
|
|
145
|
+
const url = this.fetch.constructUrl(requestObj, path);
|
|
146
|
+
const constructObject = {
|
|
147
|
+
...requestObj,
|
|
148
|
+
method: "POST",
|
|
149
|
+
body: {
|
|
150
|
+
...liveStreamObj,
|
|
151
|
+
},
|
|
152
|
+
};
|
|
153
|
+
const createSimulCastHeader = this.fetch.constructHeaders(constructObject);
|
|
154
|
+
const createSimulCastResponse = await this.fetch.fetchData(url, createSimulCastHeader);
|
|
155
|
+
return createSimulCastResponse;
|
|
156
|
+
}
|
|
157
|
+
// Retrieves details of a specific simulcast target for a live stream.
|
|
158
|
+
async getLiveStreamSimulcast(props, requestObj) {
|
|
159
|
+
var _a;
|
|
160
|
+
const path = `${this.livePath}/${(_a = props === null || props === void 0 ? void 0 : props.streamId) !== null && _a !== void 0 ? _a : ""}/simulcast/${props === null || props === void 0 ? void 0 : props.simulcastId}`;
|
|
161
|
+
const url = this.fetch.constructUrl(requestObj, path);
|
|
162
|
+
const constructObject = {
|
|
163
|
+
...requestObj,
|
|
164
|
+
method: "GET",
|
|
165
|
+
};
|
|
166
|
+
const getSimulcastHeader = this.fetch.constructHeaders(constructObject);
|
|
167
|
+
const getSimulcastResponse = await this.fetch.fetchData(url, getSimulcastHeader);
|
|
168
|
+
return getSimulcastResponse;
|
|
169
|
+
}
|
|
170
|
+
// Updates an existing simulcast target for a live stream.
|
|
171
|
+
async updateLiveStreamSimulcast(props, simulcastObj, requestObj) {
|
|
172
|
+
var _a;
|
|
173
|
+
const path = `${this.livePath}/${(_a = props === null || props === void 0 ? void 0 : props.streamId) !== null && _a !== void 0 ? _a : ""}/simulcast/${props === null || props === void 0 ? void 0 : props.simulcastId}`;
|
|
174
|
+
const url = this.fetch.constructUrl(requestObj, path);
|
|
175
|
+
const constructObject = {
|
|
176
|
+
...requestObj,
|
|
177
|
+
method: "PUT",
|
|
178
|
+
body: {
|
|
179
|
+
...simulcastObj,
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
const updateLiveStreamHeader = this.fetch.constructHeaders(constructObject);
|
|
183
|
+
const updateLiveStreamResponse = await this.fetch.fetchData(url, updateLiveStreamHeader);
|
|
184
|
+
return updateLiveStreamResponse;
|
|
185
|
+
}
|
|
186
|
+
// Deletes an existing simulcast target from a live stream.
|
|
187
|
+
async deleteLiveStreamSimulcast(props, requestObj) {
|
|
188
|
+
var _a;
|
|
189
|
+
const path = `${this.livePath}/${(_a = props === null || props === void 0 ? void 0 : props.streamId) !== null && _a !== void 0 ? _a : ""}/simulcast/${props === null || props === void 0 ? void 0 : props.simulcastId}`;
|
|
190
|
+
const url = this.fetch.constructUrl(requestObj, path);
|
|
191
|
+
const constructObject = {
|
|
192
|
+
...requestObj,
|
|
193
|
+
method: "DELETE",
|
|
194
|
+
};
|
|
195
|
+
const deleteSimulcastHeader = this.fetch.constructHeaders(constructObject);
|
|
196
|
+
const deleteSimulcastResponse = await this.fetch.fetchData(url, deleteSimulcastHeader);
|
|
197
|
+
return deleteSimulcastResponse;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
exports.default = LiveStream;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { HeaderOptions, FetchResponse, RequestObject } from "../../types";
|
|
2
|
+
declare class Fetcher {
|
|
3
|
+
fetchData(url: string, header: HeaderOptions): Promise<FetchResponse>;
|
|
4
|
+
constructUrl(requestObj?: RequestObject, path?: string, queryParams?: string): string;
|
|
5
|
+
constructHeaders(requestObj: RequestObject): HeaderOptions;
|
|
6
|
+
}
|
|
7
|
+
export default Fetcher;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class Fetcher {
|
|
4
|
+
// Fetches data from the specified URL using the provided headers.
|
|
5
|
+
async fetchData(url, header) {
|
|
6
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
7
|
+
if (!url || !header) {
|
|
8
|
+
throw new Error("Invalid arguments: URL and header are required.");
|
|
9
|
+
}
|
|
10
|
+
try {
|
|
11
|
+
const response = await fetch(url, header);
|
|
12
|
+
// If the response is successful, parse and return the JSON response.
|
|
13
|
+
if (response.ok) {
|
|
14
|
+
const successResponse = await response.json();
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
return successResponse;
|
|
17
|
+
}
|
|
18
|
+
// Handle specific HTTP error statuses
|
|
19
|
+
if ([400, 401, 403, 404, 409, 422].includes(response.status)) {
|
|
20
|
+
const errorResponse = await response.json();
|
|
21
|
+
const configErrorResponse = {
|
|
22
|
+
success: false,
|
|
23
|
+
error: {
|
|
24
|
+
code: response.status,
|
|
25
|
+
message: (_c = (_b = (_a = errorResponse === null || errorResponse === void 0 ? void 0 : errorResponse.error) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : response.statusText) !== null && _c !== void 0 ? _c : "An unexpected error occurred",
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
// Add additional error field information if available.
|
|
29
|
+
if ((_d = errorResponse === null || errorResponse === void 0 ? void 0 : errorResponse.error) === null || _d === void 0 ? void 0 : _d.fields) {
|
|
30
|
+
configErrorResponse.error.fields = errorResponse.error.fields;
|
|
31
|
+
}
|
|
32
|
+
return configErrorResponse;
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
success: false,
|
|
36
|
+
error: {
|
|
37
|
+
code: (_e = response.status) !== null && _e !== void 0 ? _e : 500,
|
|
38
|
+
message: (_f = response.statusText) !== null && _f !== void 0 ? _f : "An internal server error occurred.",
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
throw new Error(`An error occurred while fetching data: ${(_g = error === null || error === void 0 ? void 0 : error.message) !== null && _g !== void 0 ? _g : "Internal error"}`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// Constructs a complete URL based on the provided request object, path, and query parameters.
|
|
47
|
+
constructUrl(requestObj, path = "", queryParams = "") {
|
|
48
|
+
var _a, _b;
|
|
49
|
+
const protocol = (_a = requestObj === null || requestObj === void 0 ? void 0 : requestObj.httpAgent) !== null && _a !== void 0 ? _a : "https";
|
|
50
|
+
const domain = (_b = requestObj === null || requestObj === void 0 ? void 0 : requestObj.domain) !== null && _b !== void 0 ? _b : "v1.fastpix.io";
|
|
51
|
+
return `${protocol}://${domain}/${path}${queryParams}`;
|
|
52
|
+
}
|
|
53
|
+
// Constructs HTTP headers for a request based on the provided request object.
|
|
54
|
+
constructHeaders(requestObj) {
|
|
55
|
+
var _a;
|
|
56
|
+
if (!(requestObj === null || requestObj === void 0 ? void 0 : requestObj.encodedAuthToken)) {
|
|
57
|
+
throw new Error("Authorization credentials are missing.");
|
|
58
|
+
}
|
|
59
|
+
const method = (_a = requestObj === null || requestObj === void 0 ? void 0 : requestObj.method) !== null && _a !== void 0 ? _a : "GET";
|
|
60
|
+
const headers = {
|
|
61
|
+
"Content-Type": "application/json",
|
|
62
|
+
Authorization: `Basic ${requestObj.encodedAuthToken}`,
|
|
63
|
+
};
|
|
64
|
+
const requestOptions = {
|
|
65
|
+
method: method,
|
|
66
|
+
headers: headers,
|
|
67
|
+
};
|
|
68
|
+
if (method !== "GET" && method !== "DELETE" && (requestObj === null || requestObj === void 0 ? void 0 : requestObj.body)) {
|
|
69
|
+
requestOptions.body = JSON.stringify(requestObj.body);
|
|
70
|
+
}
|
|
71
|
+
return requestOptions;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
exports.default = Fetcher;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { AccessPolicy, RequestObject, DirectUploadRequest, MediaProps, PaginationProps, UpdateObject, UploadMediaFromUrlProps, FetcherProps } from "../../types";
|
|
2
|
+
declare class Media {
|
|
3
|
+
mediaPath: string;
|
|
4
|
+
fetch: FetcherProps;
|
|
5
|
+
constructor();
|
|
6
|
+
createAsset(requestObj: RequestObject, props?: UploadMediaFromUrlProps): Promise<import("../../types").FetchResponse>;
|
|
7
|
+
uploadAsset(requestObj: RequestObject, props?: DirectUploadRequest): Promise<import("../../types").FetchResponse>;
|
|
8
|
+
getAllAssets(props?: PaginationProps, requestObj?: RequestObject): Promise<import("../../types").FetchResponse>;
|
|
9
|
+
getAsset(props: MediaProps, requestObj: RequestObject): Promise<import("../../types").FetchResponse>;
|
|
10
|
+
getAssetInfo(props: MediaProps, requestObj: RequestObject): Promise<import("../../types").FetchResponse>;
|
|
11
|
+
updateAsset(props: MediaProps, updateObject: UpdateObject, requestObj: RequestObject): Promise<import("../../types").FetchResponse>;
|
|
12
|
+
deleteAsset(props: MediaProps, requestObj: RequestObject): Promise<import("../../types").FetchResponse>;
|
|
13
|
+
addMediaPlaybackId(props: MediaProps, playbackPolicy: AccessPolicy, requestObj: RequestObject): Promise<import("../../types").FetchResponse>;
|
|
14
|
+
removeMediaPlaybackId(props: MediaProps, requestObj: RequestObject): Promise<import("../../types").FetchResponse>;
|
|
15
|
+
}
|
|
16
|
+
export default Media;
|
|
@@ -0,0 +1,166 @@
|
|
|
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
|
+
const NetworkFetcher_1 = __importDefault(require("../NetworkFetcher"));
|
|
7
|
+
class Media {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.fetch = new NetworkFetcher_1.default();
|
|
10
|
+
this.mediaPath = "on-demand";
|
|
11
|
+
}
|
|
12
|
+
// Creates a new media asset.
|
|
13
|
+
async createAsset(requestObj, props = {}) {
|
|
14
|
+
const path = this.mediaPath;
|
|
15
|
+
const url = this.fetch.constructUrl(requestObj, path);
|
|
16
|
+
const { accessPolicy = "public", ...restProps } = props;
|
|
17
|
+
const constructObject = {
|
|
18
|
+
...requestObj,
|
|
19
|
+
method: "POST",
|
|
20
|
+
body: {
|
|
21
|
+
accessPolicy,
|
|
22
|
+
...restProps,
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
const createAssetHeader = this.fetch.constructHeaders(constructObject);
|
|
26
|
+
const createUrlAsset = await this.fetch.fetchData(url, createAssetHeader);
|
|
27
|
+
return createUrlAsset;
|
|
28
|
+
}
|
|
29
|
+
// Uploads a media asset using direct upload.
|
|
30
|
+
async uploadAsset(requestObj, props = {
|
|
31
|
+
corsOrigin: "",
|
|
32
|
+
pushMediaSettings: {
|
|
33
|
+
accessPolicy: "public", // Default access policy
|
|
34
|
+
inputs: [], // Default empty array for inputs (inside pushMediaSettings)
|
|
35
|
+
},
|
|
36
|
+
}) {
|
|
37
|
+
const path = `${this.mediaPath}/uploads`;
|
|
38
|
+
const url = this.fetch.constructUrl(requestObj, path);
|
|
39
|
+
const { corsOrigin = "*", pushMediaSettings = { accessPolicy: "public" }, ...restProps } = props;
|
|
40
|
+
const { accessPolicy = "public", ...restPushMediaSettings } = pushMediaSettings;
|
|
41
|
+
const constructObject = {
|
|
42
|
+
...requestObj,
|
|
43
|
+
method: "POST",
|
|
44
|
+
body: {
|
|
45
|
+
corsOrigin,
|
|
46
|
+
pushMediaSettings: {
|
|
47
|
+
accessPolicy,
|
|
48
|
+
...restPushMediaSettings,
|
|
49
|
+
},
|
|
50
|
+
...restProps,
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
const uploadAssetHeader = this.fetch.constructHeaders(constructObject);
|
|
54
|
+
const uploadMediaAsset = await this.fetch.fetchData(url, uploadAssetHeader);
|
|
55
|
+
return uploadMediaAsset;
|
|
56
|
+
}
|
|
57
|
+
// Retrieves all media assets with pagination support.
|
|
58
|
+
async getAllAssets(props, requestObj) {
|
|
59
|
+
var _a, _b, _c;
|
|
60
|
+
const path = this.mediaPath;
|
|
61
|
+
const queryParams = `?limit=${(_a = props === null || props === void 0 ? void 0 : props.limit) !== null && _a !== void 0 ? _a : 10}&offset=${(_b = props === null || props === void 0 ? void 0 : props.offset) !== null && _b !== void 0 ? _b : 1}&orderBy=${(_c = props === null || props === void 0 ? void 0 : props.orderBy) !== null && _c !== void 0 ? _c : "desc"}`;
|
|
62
|
+
const url = this.fetch.constructUrl(requestObj, path, queryParams);
|
|
63
|
+
const constructObject = {
|
|
64
|
+
...requestObj,
|
|
65
|
+
method: "GET",
|
|
66
|
+
};
|
|
67
|
+
const getAllAssetsHeader = this.fetch.constructHeaders(constructObject);
|
|
68
|
+
const assetsResponse = await this.fetch.fetchData(url, getAllAssetsHeader);
|
|
69
|
+
return assetsResponse;
|
|
70
|
+
}
|
|
71
|
+
// Retrieves details of a specific media asset.
|
|
72
|
+
async getAsset(props, requestObj) {
|
|
73
|
+
var _a;
|
|
74
|
+
const path = `${this.mediaPath}/${(_a = props === null || props === void 0 ? void 0 : props.mediaId) !== null && _a !== void 0 ? _a : ""}`;
|
|
75
|
+
const url = this.fetch.constructUrl(requestObj, path);
|
|
76
|
+
const constructObject = {
|
|
77
|
+
...requestObj,
|
|
78
|
+
method: "GET",
|
|
79
|
+
};
|
|
80
|
+
const getAssetsHeader = this.fetch.constructHeaders(constructObject);
|
|
81
|
+
const assetsResponse = await this.fetch.fetchData(url, getAssetsHeader);
|
|
82
|
+
return assetsResponse;
|
|
83
|
+
}
|
|
84
|
+
// Retrieves detailed information about a media asset's input.
|
|
85
|
+
async getAssetInfo(props, requestObj) {
|
|
86
|
+
var _a;
|
|
87
|
+
const path = `${this.mediaPath}/${(_a = props === null || props === void 0 ? void 0 : props.mediaId) !== null && _a !== void 0 ? _a : ""}/input-info`;
|
|
88
|
+
const url = this.fetch.constructUrl(requestObj, path);
|
|
89
|
+
const constructObject = {
|
|
90
|
+
...requestObj,
|
|
91
|
+
method: "GET",
|
|
92
|
+
};
|
|
93
|
+
const getAssetInfoHeader = this.fetch.constructHeaders(constructObject);
|
|
94
|
+
const assetInfoResponse = await this.fetch.fetchData(url, getAssetInfoHeader);
|
|
95
|
+
return assetInfoResponse;
|
|
96
|
+
}
|
|
97
|
+
// Updates the details of a media asset.
|
|
98
|
+
async updateAsset(props, updateObject, requestObj) {
|
|
99
|
+
var _a;
|
|
100
|
+
const path = `${this.mediaPath}/${(_a = props === null || props === void 0 ? void 0 : props.mediaId) !== null && _a !== void 0 ? _a : ""}`;
|
|
101
|
+
const url = this.fetch.constructUrl(requestObj, path);
|
|
102
|
+
const constructObject = {
|
|
103
|
+
...requestObj,
|
|
104
|
+
method: "PATCH",
|
|
105
|
+
body: {
|
|
106
|
+
...(updateObject !== null && updateObject !== void 0 ? updateObject : {}),
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
const updateAssetHeader = this.fetch.constructHeaders(constructObject);
|
|
110
|
+
const updateAssetResponse = await this.fetch.fetchData(url, updateAssetHeader);
|
|
111
|
+
return updateAssetResponse;
|
|
112
|
+
}
|
|
113
|
+
// Deletes a media asset.
|
|
114
|
+
async deleteAsset(props, requestObj) {
|
|
115
|
+
var _a;
|
|
116
|
+
const path = `${this.mediaPath}/${(_a = props === null || props === void 0 ? void 0 : props.mediaId) !== null && _a !== void 0 ? _a : ""}`;
|
|
117
|
+
const url = this.fetch.constructUrl(requestObj, path);
|
|
118
|
+
const constructObject = {
|
|
119
|
+
...requestObj,
|
|
120
|
+
method: "DELETE",
|
|
121
|
+
};
|
|
122
|
+
const deleteAssetHeader = this.fetch.constructHeaders(constructObject);
|
|
123
|
+
const deleteAssetResponse = await this.fetch.fetchData(url, deleteAssetHeader);
|
|
124
|
+
return deleteAssetResponse;
|
|
125
|
+
}
|
|
126
|
+
// Adds a playback ID to a media asset with a specific access policy.
|
|
127
|
+
async addMediaPlaybackId(props, playbackPolicy, requestObj) {
|
|
128
|
+
var _a, _b;
|
|
129
|
+
const path = `${this.mediaPath}/${(_a = props === null || props === void 0 ? void 0 : props.mediaId) !== null && _a !== void 0 ? _a : ""}/playback-ids`;
|
|
130
|
+
const url = this.fetch.constructUrl(requestObj, path);
|
|
131
|
+
const constructObject = {
|
|
132
|
+
...requestObj,
|
|
133
|
+
method: "POST",
|
|
134
|
+
body: {
|
|
135
|
+
accessPolicy: (_b = playbackPolicy === null || playbackPolicy === void 0 ? void 0 : playbackPolicy.accessPolicy) !== null && _b !== void 0 ? _b : "public",
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
const createPlaybackIdHeader = this.fetch.constructHeaders(constructObject);
|
|
139
|
+
const createPlaybackIdResponse = await this.fetch.fetchData(url, createPlaybackIdHeader);
|
|
140
|
+
return createPlaybackIdResponse;
|
|
141
|
+
}
|
|
142
|
+
// Removes a playback ID from a media asset.
|
|
143
|
+
async removeMediaPlaybackId(props, requestObj) {
|
|
144
|
+
var _a;
|
|
145
|
+
const path = `${this.mediaPath}/${(_a = props === null || props === void 0 ? void 0 : props.mediaId) !== null && _a !== void 0 ? _a : ""}/playback-ids`;
|
|
146
|
+
let queryParams = "";
|
|
147
|
+
if (props === null || props === void 0 ? void 0 : props.playbackId) {
|
|
148
|
+
if (Array.isArray(props.playbackId)) {
|
|
149
|
+
const playbackIdParams = props.playbackId.map((id) => "playbackId=" + id);
|
|
150
|
+
queryParams = "?" + playbackIdParams.join("&");
|
|
151
|
+
}
|
|
152
|
+
else if (typeof props.playbackId === "string") {
|
|
153
|
+
queryParams = "?playbackId=" + props.playbackId;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
const url = this.fetch.constructUrl(requestObj, path, queryParams);
|
|
157
|
+
const constructObject = {
|
|
158
|
+
...requestObj,
|
|
159
|
+
method: "DELETE",
|
|
160
|
+
};
|
|
161
|
+
const deletePlaybackIdHeader = this.fetch.constructHeaders(constructObject);
|
|
162
|
+
const deletePlaybackIdResponse = await this.fetch.fetchData(url, deletePlaybackIdHeader);
|
|
163
|
+
return deletePlaybackIdResponse;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
exports.default = Media;
|