@exode-team/kinescope.api 2.0.32

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 ADDED
@@ -0,0 +1 @@
1
+ ## kinescope.api
@@ -0,0 +1,22 @@
1
+ /**
2
+ * AnalyticsService
3
+ *
4
+ * @author: exode <hello@exode.ru>
5
+ */
6
+ import { BaseService } from './base-service';
7
+ import { AnalyticsGetCustomRequest, AnalyticsGetCustomResponse } from './types';
8
+ import { AnalyticsGetOverviewRequest, AnalyticsGetOverviewResponse } from './types';
9
+ export declare class AnalyticsService extends BaseService {
10
+ /**
11
+ * Get overview
12
+ * @param {AnalyticsGetOverviewRequest} params
13
+ * @returns {Promise<AnalyticsGetOverviewResponse>}
14
+ */
15
+ getOverview(params: AnalyticsGetOverviewRequest): Promise<AnalyticsGetOverviewResponse>;
16
+ /**
17
+ * Get custom
18
+ * @param {AnalyticsGetCustomRequest} params
19
+ * @returns {Promise<AnalyticsGetCustomResponse>}
20
+ */
21
+ getCustom(params: AnalyticsGetCustomRequest): Promise<AnalyticsGetCustomResponse>;
22
+ }
@@ -0,0 +1,63 @@
1
+ /**
2
+ * AnalyticsService
3
+ *
4
+ * @author: exode <hello@exode.ru>
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
+ (function (factory) {
16
+ if (typeof module === "object" && typeof module.exports === "object") {
17
+ var v = factory(require, exports);
18
+ if (v !== undefined) module.exports = v;
19
+ }
20
+ else if (typeof define === "function" && define.amd) {
21
+ define(["require", "exports", "./base-service"], factory);
22
+ }
23
+ })(function (require, exports) {
24
+ "use strict";
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.AnalyticsService = void 0;
27
+ const base_service_1 = require("./base-service");
28
+ class AnalyticsService extends base_service_1.BaseService {
29
+ /**
30
+ * Get overview
31
+ * @param {AnalyticsGetOverviewRequest} params
32
+ * @returns {Promise<AnalyticsGetOverviewResponse>}
33
+ */
34
+ getOverview(params) {
35
+ return __awaiter(this, void 0, void 0, function* () {
36
+ try {
37
+ return yield this.requestApi('https://api.kinescope.io/v1/analytics/overview', params, 'get');
38
+ }
39
+ catch (error) {
40
+ console.error(`${error}`);
41
+ throw error;
42
+ }
43
+ });
44
+ }
45
+ /**
46
+ * Get custom
47
+ * @param {AnalyticsGetCustomRequest} params
48
+ * @returns {Promise<AnalyticsGetCustomResponse>}
49
+ */
50
+ getCustom(params) {
51
+ return __awaiter(this, void 0, void 0, function* () {
52
+ try {
53
+ return yield this.requestApi('https://api.kinescope.io/v1/analytics', params, 'get');
54
+ }
55
+ catch (error) {
56
+ console.error(`${error}`);
57
+ throw error;
58
+ }
59
+ });
60
+ }
61
+ }
62
+ exports.AnalyticsService = AnalyticsService;
63
+ });
@@ -0,0 +1,26 @@
1
+ /**
2
+ * ApiService
3
+ *
4
+ * @author: exode <hello@exode.ru>
5
+ */
6
+ import { AnalyticsService } from './analytics-service';
7
+ import { ProjectService } from './project-service';
8
+ import { VideoService } from './video-service';
9
+ export declare class ApiService {
10
+ constructor(apiToken: string);
11
+ /**
12
+ * AnalyticsService
13
+ * @type {AnalyticsService}
14
+ */
15
+ readonly analytics: AnalyticsService;
16
+ /**
17
+ * ProjectService
18
+ * @type {ProjectService}
19
+ */
20
+ readonly project: ProjectService;
21
+ /**
22
+ * VideoService
23
+ * @type {VideoService}
24
+ */
25
+ readonly video: VideoService;
26
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * ApiService
3
+ *
4
+ * @author: exode <hello@exode.ru>
5
+ */
6
+ (function (factory) {
7
+ if (typeof module === "object" && typeof module.exports === "object") {
8
+ var v = factory(require, exports);
9
+ if (v !== undefined) module.exports = v;
10
+ }
11
+ else if (typeof define === "function" && define.amd) {
12
+ define(["require", "exports", "./analytics-service", "./project-service", "./video-service"], factory);
13
+ }
14
+ })(function (require, exports) {
15
+ "use strict";
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.ApiService = void 0;
18
+ const analytics_service_1 = require("./analytics-service");
19
+ const project_service_1 = require("./project-service");
20
+ const video_service_1 = require("./video-service");
21
+ class ApiService {
22
+ constructor(apiToken) {
23
+ this.analytics = new analytics_service_1.AnalyticsService(apiToken);
24
+ this.project = new project_service_1.ProjectService(apiToken);
25
+ this.video = new video_service_1.VideoService(apiToken);
26
+ }
27
+ }
28
+ exports.ApiService = ApiService;
29
+ });
@@ -0,0 +1,28 @@
1
+ /**
2
+ * BaseService
3
+ *
4
+ * @author: exode <hello@exode.ru>
5
+ */
6
+ /// <reference types="node" />
7
+ import { Request, Response } from './types';
8
+ export declare class BaseService {
9
+ /**
10
+ * Kinescope apiToken
11
+ */
12
+ private readonly apiToken;
13
+ /**
14
+ * Constructor
15
+ *
16
+ * @param apiToken - kinescope apiToken
17
+ */
18
+ constructor(apiToken: string);
19
+ /**
20
+ * Make request to Kinescope API
21
+ * @param {string} apiUrl
22
+ * @param {Request | File | Buffer} data
23
+ * @param {'post' | 'getMany'} httpMethod
24
+ * @param {Record} headers
25
+ * @returns {Promise<T>}
26
+ */
27
+ requestApi<T = Response>(apiUrl: string, data: Request | File | Buffer, httpMethod: 'post' | 'get' | 'put' | 'delete', headers?: Record<string, string>): Promise<T>;
28
+ }
@@ -0,0 +1,71 @@
1
+ /**
2
+ * BaseService
3
+ *
4
+ * @author: exode <hello@exode.ru>
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
16
+ return (mod && mod.__esModule) ? mod : { "default": mod };
17
+ };
18
+ (function (factory) {
19
+ if (typeof module === "object" && typeof module.exports === "object") {
20
+ var v = factory(require, exports);
21
+ if (v !== undefined) module.exports = v;
22
+ }
23
+ else if (typeof define === "function" && define.amd) {
24
+ define(["require", "exports", "axios"], factory);
25
+ }
26
+ })(function (require, exports) {
27
+ "use strict";
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.BaseService = void 0;
30
+ const axios_1 = __importDefault(require("axios"));
31
+ class BaseService {
32
+ /**
33
+ * Constructor
34
+ *
35
+ * @param apiToken - kinescope apiToken
36
+ */
37
+ constructor(apiToken) {
38
+ this.apiToken = apiToken;
39
+ }
40
+ /**
41
+ * Make request to Kinescope API
42
+ * @param {string} apiUrl
43
+ * @param {Request | File | Buffer} data
44
+ * @param {'post' | 'getMany'} httpMethod
45
+ * @param {Record} headers
46
+ * @returns {Promise<T>}
47
+ */
48
+ requestApi(apiUrl, data, httpMethod, headers) {
49
+ return __awaiter(this, void 0, void 0, function* () {
50
+ const config = {
51
+ url: apiUrl,
52
+ method: httpMethod,
53
+ maxBodyLength: Infinity,
54
+ data: httpMethod !== 'get' ? data : {},
55
+ params: httpMethod === 'get' ? data : {},
56
+ headers: Object.assign({ 'Content-Type': 'application/json', 'Accept': 'application/json', 'Authorization': `Bearer ${this.apiToken}` }, headers),
57
+ };
58
+ try {
59
+ const response = yield axios_1.default.request(config);
60
+ return response.data;
61
+ }
62
+ catch (error) {
63
+ const response = error.response;
64
+ console.error(`[Error code is ${response === null || response === void 0 ? void 0 : response.status}] ${JSON.stringify(response === null || response === void 0 ? void 0 : response.data)}`);
65
+ throw error;
66
+ }
67
+ });
68
+ }
69
+ }
70
+ exports.BaseService = BaseService;
71
+ });
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Index
3
+ *
4
+ * @author: exode <hello@exode.ru>
5
+ */
6
+ export * from './types';
7
+ export * from './api.service';
8
+ export * from './analytics-service';
9
+ export * from './project-service';
10
+ export * from './video-service';
package/dist/index.js ADDED
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Index
3
+ *
4
+ * @author: exode <hello@exode.ru>
5
+ */
6
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
+ if (k2 === undefined) k2 = k;
8
+ var desc = Object.getOwnPropertyDescriptor(m, k);
9
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
+ desc = { enumerable: true, get: function() { return m[k]; } };
11
+ }
12
+ Object.defineProperty(o, k2, desc);
13
+ }) : (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ o[k2] = m[k];
16
+ }));
17
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
18
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
19
+ };
20
+ (function (factory) {
21
+ if (typeof module === "object" && typeof module.exports === "object") {
22
+ var v = factory(require, exports);
23
+ if (v !== undefined) module.exports = v;
24
+ }
25
+ else if (typeof define === "function" && define.amd) {
26
+ define(["require", "exports", "./types", "./api.service", "./analytics-service", "./project-service", "./video-service"], factory);
27
+ }
28
+ })(function (require, exports) {
29
+ "use strict";
30
+ Object.defineProperty(exports, "__esModule", { value: true });
31
+ __exportStar(require("./types"), exports);
32
+ __exportStar(require("./api.service"), exports);
33
+ __exportStar(require("./analytics-service"), exports);
34
+ __exportStar(require("./project-service"), exports);
35
+ __exportStar(require("./video-service"), exports);
36
+ });
@@ -0,0 +1,40 @@
1
+ /**
2
+ * ProjectService
3
+ *
4
+ * @author: exode <hello@exode.ru>
5
+ */
6
+ import { BaseService } from './base-service';
7
+ import { ProjectCreateRequest, ProjectCreateResponse, ProjectDeleteResponse, ProjectGetByIdRequest, ProjectGetByIdResponse, ProjectGetRequest, ProjectGetResponse, ProjectUpdateRequest, ProjectUpdateResponse } from './types';
8
+ export declare class ProjectService extends BaseService {
9
+ /**
10
+ * Create a project
11
+ * @param {ProjectCreateRequest} data
12
+ * @returns {Promise<ProjectCreateResponse>}
13
+ */
14
+ create(data: ProjectCreateRequest): Promise<ProjectCreateResponse>;
15
+ /**
16
+ * Get many projects
17
+ * @param {ProjectGetRequest} params
18
+ * @returns {Promise<ProjectGetResponse>}
19
+ */
20
+ getMany(params: ProjectGetRequest): Promise<ProjectGetResponse>;
21
+ /**
22
+ * Get project by id
23
+ * @param {ProjectGetByIdRequest} params
24
+ * @returns {Promise<ProjectGetByIdResponse>}
25
+ */
26
+ getById(params: ProjectGetByIdRequest): Promise<ProjectGetByIdResponse>;
27
+ /**
28
+ * Update project by id
29
+ * @param {string} projectId
30
+ * @param {ProjectUpdateRequest} params
31
+ * @returns {Promise<ProjectUpdateResponse>}
32
+ */
33
+ updateById(projectId: string, params: ProjectUpdateRequest): Promise<ProjectUpdateResponse>;
34
+ /**
35
+ * Delete project by id
36
+ * @param {string} projectId
37
+ * @returns {Promise<ProjectDeleteResponse>}
38
+ */
39
+ deleteById(projectId: string): Promise<ProjectDeleteResponse>;
40
+ }
@@ -0,0 +1,114 @@
1
+ /**
2
+ * ProjectService
3
+ *
4
+ * @author: exode <hello@exode.ru>
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
+ (function (factory) {
16
+ if (typeof module === "object" && typeof module.exports === "object") {
17
+ var v = factory(require, exports);
18
+ if (v !== undefined) module.exports = v;
19
+ }
20
+ else if (typeof define === "function" && define.amd) {
21
+ define(["require", "exports", "./base-service"], factory);
22
+ }
23
+ })(function (require, exports) {
24
+ "use strict";
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.ProjectService = void 0;
27
+ const base_service_1 = require("./base-service");
28
+ class ProjectService extends base_service_1.BaseService {
29
+ /**
30
+ * Create a project
31
+ * @param {ProjectCreateRequest} data
32
+ * @returns {Promise<ProjectCreateResponse>}
33
+ */
34
+ create(data) {
35
+ return __awaiter(this, void 0, void 0, function* () {
36
+ try {
37
+ return yield this.requestApi('https://api.kinescope.io/v1/projects', data, 'post');
38
+ }
39
+ catch (error) {
40
+ console.error(`${error}`);
41
+ throw error;
42
+ }
43
+ });
44
+ }
45
+ /**
46
+ * Get many projects
47
+ * @param {ProjectGetRequest} params
48
+ * @returns {Promise<ProjectGetResponse>}
49
+ */
50
+ getMany(params) {
51
+ return __awaiter(this, void 0, void 0, function* () {
52
+ try {
53
+ return yield this.requestApi('https://api.kinescope.io/v1/projects', params, 'get');
54
+ }
55
+ catch (error) {
56
+ console.error(`${error}`);
57
+ throw error;
58
+ }
59
+ });
60
+ }
61
+ /**
62
+ * Get project by id
63
+ * @param {ProjectGetByIdRequest} params
64
+ * @returns {Promise<ProjectGetByIdResponse>}
65
+ */
66
+ getById(params) {
67
+ return __awaiter(this, void 0, void 0, function* () {
68
+ try {
69
+ return yield this.requestApi(`https://api.kinescope.io/v1/projects/${params.id}`, {}, 'get');
70
+ }
71
+ catch (error) {
72
+ console.error(`${error}`);
73
+ throw error;
74
+ }
75
+ });
76
+ }
77
+ ;
78
+ /**
79
+ * Update project by id
80
+ * @param {string} projectId
81
+ * @param {ProjectUpdateRequest} params
82
+ * @returns {Promise<ProjectUpdateResponse>}
83
+ */
84
+ updateById(projectId, params) {
85
+ return __awaiter(this, void 0, void 0, function* () {
86
+ try {
87
+ return yield this.requestApi(`https://api.kinescope.io/v1/projects/${projectId}`, params, 'put');
88
+ }
89
+ catch (error) {
90
+ console.error(`${error}`);
91
+ throw error;
92
+ }
93
+ });
94
+ }
95
+ ;
96
+ /**
97
+ * Delete project by id
98
+ * @param {string} projectId
99
+ * @returns {Promise<ProjectDeleteResponse>}
100
+ */
101
+ deleteById(projectId) {
102
+ return __awaiter(this, void 0, void 0, function* () {
103
+ try {
104
+ return yield this.requestApi(`https://api.kinescope.io/v1/projects/${projectId}`, {}, 'delete');
105
+ }
106
+ catch (error) {
107
+ console.error(`${error}`);
108
+ throw error;
109
+ }
110
+ });
111
+ }
112
+ }
113
+ exports.ProjectService = ProjectService;
114
+ });
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Analytics getMany custom
3
+ */
4
+
5
+ export interface AnalyticsGetCustomRequest {
6
+ from: string;
7
+ to: string;
8
+ group: string;
9
+ group_entities: string;
10
+ fields: string[];
11
+ order?: string[];
12
+ }
13
+
14
+ export interface AnalyticsGetCustomResponse {
15
+ readonly meta: {
16
+ order: {
17
+ view: string;
18
+ play: string;
19
+ };
20
+ time: {
21
+ from: string;
22
+ to: string;
23
+ timezone: string;
24
+ };
25
+ };
26
+
27
+ readonly data: {
28
+ workspace_id: string;
29
+ video_id: string;
30
+ date: string;
31
+ view: number;
32
+ play: number;
33
+ }[];
34
+ }
35
+
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Analytics getMany overview
3
+ */
4
+
5
+ export interface AnalyticsGetOverviewRequest {
6
+ from: string;
7
+ to: string;
8
+ group_time: string;
9
+ video_id?: string;
10
+ }
11
+
12
+ export interface AnalyticsGetOverviewResponse {
13
+ readonly meta: {
14
+ time: {
15
+ from: string;
16
+ to: string;
17
+ timezone: string;
18
+ };
19
+ };
20
+
21
+ readonly data: {
22
+ total: {
23
+ views: number;
24
+ duration: number;
25
+ watch_time: number;
26
+ player_loads: number;
27
+ };
28
+
29
+ timeline: {
30
+ views: number;
31
+ duration: number;
32
+ watch_time: number;
33
+ player_loads: number;
34
+ date: string;
35
+ }[];
36
+
37
+ top: {
38
+ oses: {
39
+ name: string;
40
+ views: number;
41
+ player_loads: number;
42
+ }[];
43
+
44
+ devices: {
45
+ name: string;
46
+ views: number;
47
+ player_loads: number;
48
+ }[];
49
+
50
+ browsers: {
51
+ name: string;
52
+ views: number;
53
+ player_loads: number;
54
+ }[];
55
+
56
+ countries: {
57
+ name: string;
58
+ code: string;
59
+ views: number;
60
+ player_loads: number;
61
+ }[];
62
+ };
63
+ };
64
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Create project
3
+ */
4
+
5
+ export interface ProjectCreateRequest {
6
+ name: string;
7
+ privacy_type: string;
8
+ privacy_domains: string[];
9
+ player_id?: string;
10
+ encrypted?: boolean;
11
+ }
12
+
13
+ export interface ProjectCreateResponse {
14
+ readonly id: string;
15
+ readonly name: string;
16
+ readonly folders: any[];
17
+ readonly privacy_type: string;
18
+ readonly privacy_domains: string[];
19
+ readonly player_id: string;
20
+ readonly favorite: boolean;
21
+ readonly size: number;
22
+ readonly items_count: number;
23
+ readonly created_at: string;
24
+ readonly updated_at: string | null;
25
+ readonly encrypted: boolean;
26
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Delete project
3
+ */
4
+
5
+ export interface ProjectDeleteResponse {
6
+ readonly projectId: string;
7
+ }
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Get project
3
+ */
4
+
5
+ export interface ProjectGetRequest {
6
+ catalog_type?: string,
7
+ per_page?: number,
8
+ page?: number,
9
+ }
10
+
11
+ export interface ProjectGetResponse {
12
+ readonly meta: {
13
+ pagination: {
14
+ page: number;
15
+ per_page: number;
16
+ total: number;
17
+ };
18
+
19
+ order: {
20
+ name: string;
21
+ };
22
+ };
23
+
24
+ readonly data: {
25
+ id: string;
26
+ name: string;
27
+ created_at: string;
28
+ updated_at: string | null;
29
+
30
+ folders: {
31
+ id: string;
32
+ name: string;
33
+ project_id: string;
34
+ created_at: string;
35
+ updated_at: string | null;
36
+ deleted_at: string | null;
37
+ }[];
38
+ }[];
39
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Get a project by id
3
+ */
4
+
5
+ export interface ProjectGetByIdRequest {
6
+ id: string;
7
+ }
8
+
9
+ export interface ProjectGetByIdResponse {
10
+ readonly id: string;
11
+ readonly name: string;
12
+ readonly created_at: string;
13
+ readonly updated_at: string | null;
14
+
15
+ folders: {
16
+ id: string;
17
+ name: string;
18
+ project_id: string;
19
+ created_at: string;
20
+ updated_at: string | null;
21
+ deleted_at: string | null;
22
+ }[];
23
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Update project
3
+ */
4
+
5
+ export interface ProjectUpdateRequest {
6
+ name: string;
7
+ privacy_type: string;
8
+ privacy_domains: string[];
9
+ }
10
+
11
+ export interface ProjectUpdateResponse {
12
+ readonly name: string;
13
+ readonly privacy_type: string;
14
+ readonly privacy_domains: string[];
15
+ readonly apply_to_videos: boolean;
16
+ readonly player_id: string;
17
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Upload Video
3
+ */
4
+
5
+ export interface VideoUploadHeadersByFile extends Record<string, string> {
6
+ 'X-Parent-ID': string;
7
+ 'X-Video-Title': string;
8
+ 'X-Video-Trim': string;
9
+ }
10
+
11
+ export interface VideoUploadHeadersByUrl extends Record<string, string> {
12
+ 'X-Parent-ID': string;
13
+ 'X-Video-Title': string;
14
+ 'X-Video-URL': string;
15
+ }
16
+
17
+ export interface VideoUploadResponse {
18
+ readonly data: boolean;
19
+ }
@@ -0,0 +1,63 @@
1
+ // noinspection ES6PreferShortImport @note: for correct dist types
2
+
3
+ /**
4
+ * Index
5
+ *
6
+ * @author: exode <hello@exode.ru>
7
+ */
8
+
9
+ import { AnalyticsGetOverviewRequest, AnalyticsGetOverviewResponse } from './dto/analytics/analyticsGetOverview';
10
+ import { AnalyticsGetCustomRequest, AnalyticsGetCustomResponse } from './dto/analytics/analyticsGetCustom';
11
+
12
+ import { ProjectCreateRequest, ProjectCreateResponse } from './dto/project/projectCreate';
13
+ import { ProjectGetRequest, ProjectGetResponse } from './dto/project/projectGet';
14
+ import { ProjectGetByIdRequest, ProjectGetByIdResponse } from './dto/project/projectGetById';
15
+ import { ProjectUpdateRequest, ProjectUpdateResponse } from './dto/project/projectUpdateById';
16
+ import { ProjectDeleteResponse } from './dto/project/projectDelete';
17
+
18
+ import { VideoUploadHeadersByFile, VideoUploadHeadersByUrl, VideoUploadResponse } from './dto/video/videoUpload';
19
+
20
+
21
+ /**
22
+ * Types of request
23
+ */
24
+ export type Request = AnalyticsGetOverviewRequest |
25
+ AnalyticsGetCustomRequest |
26
+ ProjectCreateRequest |
27
+ ProjectGetRequest |
28
+ ProjectGetByIdRequest |
29
+ ProjectUpdateRequest |
30
+ VideoUploadHeadersByFile |
31
+ VideoUploadHeadersByUrl;
32
+
33
+ /**
34
+ * Types of response
35
+ */
36
+ export type Response = AnalyticsGetOverviewResponse |
37
+ AnalyticsGetCustomResponse |
38
+ ProjectCreateResponse |
39
+ ProjectGetResponse |
40
+ ProjectGetByIdResponse |
41
+ ProjectUpdateResponse |
42
+ ProjectDeleteResponse |
43
+ VideoUploadResponse;
44
+
45
+ export {
46
+ AnalyticsGetOverviewRequest,
47
+ AnalyticsGetCustomRequest,
48
+ ProjectCreateRequest,
49
+ ProjectGetRequest,
50
+ ProjectGetByIdRequest,
51
+ ProjectUpdateRequest,
52
+ VideoUploadHeadersByFile,
53
+ VideoUploadHeadersByUrl,
54
+ AnalyticsGetOverviewResponse,
55
+ AnalyticsGetCustomResponse,
56
+ ProjectCreateResponse,
57
+ ProjectGetResponse,
58
+ ProjectGetByIdResponse,
59
+ ProjectUpdateResponse,
60
+ ProjectDeleteResponse,
61
+ VideoUploadResponse,
62
+ };
63
+
@@ -0,0 +1,23 @@
1
+ /**
2
+ * VideoService
3
+ *
4
+ * @author: exode <hello@exode.ru>
5
+ */
6
+ /// <reference types="node" />
7
+ import { BaseService } from './base-service';
8
+ import { VideoUploadHeadersByFile, VideoUploadHeadersByUrl, VideoUploadResponse } from './types';
9
+ export declare class VideoService extends BaseService {
10
+ /**
11
+ * Upload video by file
12
+ * @param {File | Buffer} data
13
+ * @param {VideoUploadHeadersByFile} headers
14
+ * @returns {Promise<VideoUploadResponse>}
15
+ */
16
+ uploadVideoByFile(data: File | Buffer, headers: VideoUploadHeadersByFile): Promise<VideoUploadResponse>;
17
+ /**
18
+ * Upload video by url
19
+ * @param {VideoUploadHeadersByUrl} headers
20
+ * @returns {Promise<VideoUploadResponse>}
21
+ */
22
+ uploadVideoByUrl(headers: VideoUploadHeadersByUrl): Promise<VideoUploadResponse>;
23
+ }
@@ -0,0 +1,64 @@
1
+ /**
2
+ * VideoService
3
+ *
4
+ * @author: exode <hello@exode.ru>
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
+ (function (factory) {
16
+ if (typeof module === "object" && typeof module.exports === "object") {
17
+ var v = factory(require, exports);
18
+ if (v !== undefined) module.exports = v;
19
+ }
20
+ else if (typeof define === "function" && define.amd) {
21
+ define(["require", "exports", "./base-service"], factory);
22
+ }
23
+ })(function (require, exports) {
24
+ "use strict";
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.VideoService = void 0;
27
+ const base_service_1 = require("./base-service");
28
+ class VideoService extends base_service_1.BaseService {
29
+ /**
30
+ * Upload video by file
31
+ * @param {File | Buffer} data
32
+ * @param {VideoUploadHeadersByFile} headers
33
+ * @returns {Promise<VideoUploadResponse>}
34
+ */
35
+ uploadVideoByFile(data, headers) {
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ try {
38
+ return yield this.requestApi('https://uploader.kinescope.io/v2/video', data, 'post', headers);
39
+ }
40
+ catch (error) {
41
+ console.error(`${error}`);
42
+ throw error;
43
+ }
44
+ });
45
+ }
46
+ /**
47
+ * Upload video by url
48
+ * @param {VideoUploadHeadersByUrl} headers
49
+ * @returns {Promise<VideoUploadResponse>}
50
+ */
51
+ uploadVideoByUrl(headers) {
52
+ return __awaiter(this, void 0, void 0, function* () {
53
+ try {
54
+ return yield this.requestApi('https://uploader.kinescope.io/v2/video', {}, 'post', headers);
55
+ }
56
+ catch (error) {
57
+ console.error(`${error}`);
58
+ throw error;
59
+ }
60
+ });
61
+ }
62
+ }
63
+ exports.VideoService = VideoService;
64
+ });
package/env.example ADDED
@@ -0,0 +1,3 @@
1
+ #Kinescope api token
2
+ API_TOKEN=""
3
+
@@ -0,0 +1,131 @@
1
+ /**
2
+ * Test api cases
3
+ */
4
+
5
+ import fs from 'fs';
6
+ import FormData from 'form-data';
7
+
8
+ import { ApiService } from '../src/api.service';
9
+
10
+
11
+ require('dotenv').config();
12
+
13
+ (async () => {
14
+ const apiService = new ApiService(`${process.env.API_TOKEN}`);
15
+
16
+ const createProject = await apiService.project.create({
17
+ name: 'Мой тестовый проект 2',
18
+ privacy_type: 'custom',
19
+ privacy_domains: [ 'exode.ru', 'staging.exode.ru' ],
20
+ });
21
+
22
+ console.log('createProject', createProject);
23
+ })();
24
+
25
+ (async () => {
26
+ const apiService = new ApiService(`${process.env.API_TOKEN}`);
27
+
28
+ const getProject = await apiService.project.getMany({
29
+ per_page: 10,
30
+ page: 1,
31
+ });
32
+
33
+ console.log('getProject', getProject);
34
+
35
+ })();
36
+
37
+ (async () => {
38
+ const apiService = new ApiService(`${process.env.API_TOKEN}`);
39
+
40
+ const getProjectById = await apiService.project.getById({
41
+ id: 'f95f15f3-f826-4af1-8641-cf5f8ce83231',
42
+ });
43
+
44
+ console.log('getProjectById', getProjectById);
45
+ })();
46
+
47
+ (async () => {
48
+ const apiService = new ApiService(`${process.env.API_TOKEN}`);
49
+
50
+ const updateProject = await apiService.project.updateById(
51
+ 'f95f15f3-f826-4af1-8641-cf5f8ce83231',
52
+ {
53
+ name: 'new name of project',
54
+ privacy_type: 'custom',
55
+ privacy_domains: [ 'exode.ru', 'staging.exode.ru' ],
56
+ },
57
+ );
58
+
59
+ console.log('updateProject', updateProject);
60
+ })();
61
+
62
+ (async () => {
63
+ const apiService = new ApiService(`${process.env.API_TOKEN}`);
64
+
65
+ const deleteProject = await apiService.project.deleteById(
66
+ 'f95f15f3-f826-4af1-8641-cf5f8ce83231',
67
+ );
68
+
69
+ console.log('deleteProject', deleteProject);
70
+ })();
71
+
72
+ (async () => {
73
+ const apiService = new ApiService(`${process.env.API_TOKEN}`);
74
+
75
+ const getOverview = await apiService.analytics.getOverview({
76
+ from: '2020-08-30',
77
+ to: '2020-09-01',
78
+ group_time: 'day',
79
+ });
80
+
81
+ console.log('getOverview', getOverview);
82
+ })();
83
+
84
+ (async () => {
85
+ const apiService = new ApiService(`${process.env.API_TOKEN}`);
86
+
87
+ const getCustom = await apiService.analytics.getCustom({
88
+ from: '2020-11-01T06:00:00Z',
89
+ to: '2020-11-01T06:00:00Z',
90
+ group: 'day',
91
+ group_entities: 'video_id',
92
+ fields: [ 'view', 'play' ],
93
+ });
94
+
95
+ console.log('getCustom', getCustom);
96
+ })();
97
+
98
+ (async () => {
99
+ const apiService = new ApiService(`${process.env.API_TOKEN}`);
100
+ const form = new FormData();
101
+
102
+ form.append('file', fs.createReadStream('test.mp4'), {
103
+ filename: 'test.mp4',
104
+ contentType: 'video/mp4',
105
+ });
106
+ const uploadVideo = await apiService.video.uploadVideoByFile(
107
+ fs.readFileSync('test.mp4'),
108
+ {
109
+ 'X-Parent-ID': '92b93e72-27cc-49be-ac53-ca4a5f276f52',
110
+ 'X-Video-Title': 'testOne',
111
+ 'X-Video-Trim': JSON.stringify({ start: 1, length: 2 }),
112
+ ...form.getHeaders(),
113
+ },
114
+ );
115
+
116
+ console.log('uploadVideo', uploadVideo);
117
+ })();
118
+
119
+ (async () => {
120
+ const apiService = new ApiService(`${process.env.API_TOKEN}`);
121
+
122
+ const headers = {
123
+ 'X-Parent-ID': '92b93e72-27cc-49be-ac53-ca4a5f276f52',
124
+ 'X-Video-Title': 'testTwo',
125
+ 'X-Video-URL': 'https://www.youtube.com/watch?v=qzbtdclsJXw',
126
+ };
127
+
128
+ const uploadVideo = await apiService.video.uploadVideoByUrl(headers);
129
+ console.log('uploadVideo', uploadVideo);
130
+
131
+ })();
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@exode-team/kinescope.api",
3
+ "version": "2.0.32",
4
+ "main": "index.js",
5
+ "author": "aslanorlov <aslanorlov@gmail.com>",
6
+ "license": "MIT",
7
+ "scripts": {
8
+ "build": "yarn clean && tsc && yarn copy-definitions",
9
+ "build:watch": "yarn clean && tsc-watch",
10
+ "lint": "eslint -c ./.eslintrc.js ./src --ext .ts,.js --fix",
11
+ "lint:test": "eslint -c ./.eslintrc.js ./src --ext .ts,.js",
12
+ "clean": "rimraf dist",
13
+ "copy-definitions": "copyfiles -u 1 \"src/**/*.d.ts\" dist",
14
+ "test": "npx ts-node examples/api-test.ts",
15
+ "npm:publish": "npm run build && npm publish"
16
+ },
17
+ "dependencies": {
18
+ "axios": "^1.6.8",
19
+ "dotenv": "^16.4.5",
20
+ "lodash": "^4.17.21"
21
+ },
22
+ "devDependencies": {
23
+ "@babel/core": "^7.24.3",
24
+ "@babel/preset-env": "^7.24.3",
25
+ "@babel/preset-typescript": "^7.24.1",
26
+ "@types/debug": "^4.1.12",
27
+ "@types/jest": "^29.5.12",
28
+ "@types/lodash": "^4.17.0",
29
+ "@types/node": "^20.11.30",
30
+ "babel-jest": "^29.7.0",
31
+ "copyfiles": "^2.4.1",
32
+ "eslint": "^8.57.0",
33
+ "jest": "^29.7.0",
34
+ "ts-jest": "^29.1.2",
35
+ "ts-watch": "^1.0.8",
36
+ "typescript": "^5.4.3"
37
+ }
38
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,76 @@
1
+ {
2
+ "compilerOptions": {
3
+ /* Basic Options */
4
+ // "incremental": true, /* Enable incremental compilation */
5
+ "target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
6
+ "module": "umd", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
7
+ // "lib": [], /* Specify library files to be included in the compilation. */
8
+ "allowJs": true, /* Allow javascript files to be compiled. */
9
+ // "checkJs": true, /* Report errors in .js files. */
10
+ // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
11
+ "declaration": true, /* Generates corresponding '.d.ts' file. */
12
+ // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
13
+ // "sourceMap": true, /* Generates corresponding '.map' file. */
14
+ // "outFile": "./", /* Concatenate and emit output to single file. */
15
+ "outDir": "./dist", /* Redirect output structure to the directory. */
16
+ // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
17
+ // "composite": true, /* Enable project compilation */
18
+ // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
19
+ // "removeComments": true, /* Do not emit comments to output. */
20
+ // "noEmit": true, /* Do not emit outputs. */
21
+ // "importHelpers": true, /* Import emit helpers from 'tslib'. */
22
+ // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
23
+ // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
24
+
25
+ /* Strict Type-Checking Options */
26
+ "strict": true, /* Enable all strict type-checking options. */
27
+ // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
28
+ // "strictNullChecks": true, /* Enable strict null checks. */
29
+ // "strictFunctionTypes": true, /* Enable strict checking of function types. */
30
+ // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
31
+ // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
32
+ // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
33
+ // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
34
+
35
+ /* Additional Checks */
36
+ // "noUnusedLocals": true, /* Report errors on unused locals. */
37
+ // "noUnusedParameters": true, /* Report errors on unused parameters. */
38
+ // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
39
+ // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
40
+
41
+ /* Module Resolution Options */
42
+ "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
43
+ "baseUrl": ".", /* Base directory to resolve non-absolute module names. */
44
+
45
+ /**
46
+ * A series of entries which re-map imports to lookup locations relative to the 'baseUrl'.
47
+ */
48
+ "paths": {
49
+ "*": [
50
+ "./src/types/*"
51
+ ]
52
+ },
53
+
54
+ // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
55
+ // "typeRoots": [], /* List of folders to include type definitions from. */
56
+ // "types": [], /* Type declaration files to be included in compilation. */
57
+ // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
58
+ "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
59
+ // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
60
+ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
61
+
62
+ /* Source Map Options */
63
+ // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
64
+ // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
65
+ // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
66
+ // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
67
+
68
+ /* Experimental Options */
69
+ // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
70
+ // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
71
+ },
72
+
73
+ "include": [
74
+ "./src/index.ts"
75
+ ]
76
+ }