/
index.ts
174 lines (161 loc) · 5.93 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import { CrowdinApi, isOptionalNumber, PaginationOptions, PatchRequest, ResponseList, ResponseObject } from '../core';
export class Distributions extends CrowdinApi {
/**
* @param projectId project identifier
* @param options optional pagination parameters for the request
* @see https://developer.crowdin.com/api/v2/#operation/api.projects.distributions.getMany
*/
listDistributions(
projectId: number,
options?: PaginationOptions,
): Promise<ResponseList<DistributionsModel.Distribution>>;
/**
* @param projectId project identifier
* @param limit maximum number of items to retrieve (default 25)
* @param offset starting offset in the collection (default 0)
* @deprecated optional parameters should be passed through an object
* @see https://developer.crowdin.com/api/v2/#operation/api.projects.distributions.getMany
*/
listDistributions(
projectId: number,
limit?: number,
offset?: number,
): Promise<ResponseList<DistributionsModel.Distribution>>;
listDistributions(
projectId: number,
options?: number | PaginationOptions,
deprecatedOffset?: number,
): Promise<ResponseList<DistributionsModel.Distribution>> {
if (isOptionalNumber(options, '1' in arguments)) {
options = { limit: options, offset: deprecatedOffset };
}
const url = `${this.url}/projects/${projectId}/distributions`;
return this.getList(url, options.limit, options.offset);
}
/**
* @param projectId project identifier
* @param request request body
* @see https://developer.crowdin.com/api/v2/#operation/api.projects.distributions.post
*/
createDistribution(
projectId: number,
request:
| DistributionsModel.CreateDistributionRequest
| DistributionsModel.CreateDistributionStringsBasedRequest,
): Promise<ResponseObject<DistributionsModel.Distribution>> {
const url = `${this.url}/projects/${projectId}/distributions`;
return this.post(url, request, this.defaultConfig());
}
/**
* @param projectId project identifier
* @param hash hash
* @see https://developer.crowdin.com/api/v2/#operation/api.projects.distributions.get
*/
getDistribution(projectId: number, hash: string): Promise<ResponseObject<DistributionsModel.Distribution>> {
const url = `${this.url}/projects/${projectId}/distributions/${hash}`;
return this.get(url, this.defaultConfig());
}
/**
* @param projectId project identifier
* @param hash hash
* @see https://developer.crowdin.com/api/v2/#operation/api.projects.distributions.delete
*/
deleteDistribution(projectId: number, hash: string): Promise<void> {
const url = `${this.url}/projects/${projectId}/distributions/${hash}`;
return this.delete(url, this.defaultConfig());
}
/**
* @param projectId project identifier
* @param hash hash
* @param request request body
* @see https://developer.crowdin.com/api/v2/#operation/api.projects.distributions.patch
*/
editDistribution(
projectId: number,
hash: string,
request: PatchRequest[],
): Promise<ResponseObject<DistributionsModel.Distribution>> {
const url = `${this.url}/projects/${projectId}/distributions/${hash}`;
return this.patch(url, request, this.defaultConfig());
}
/**
* @param projectId project identifier
* @param hash hash
* @see https://developer.crowdin.com/api/v2/#operation/api.projects.distributions.release.get
*/
getDistributionRelease(
projectId: number,
hash: string,
): Promise<
ResponseObject<DistributionsModel.DistributionRelease | DistributionsModel.DistributionStringsBasedRelease>
> {
const url = `${this.url}/projects/${projectId}/distributions/${hash}/release`;
return this.get(url, this.defaultConfig());
}
/**
* @param projectId project identifier
* @param hash hash
* @param request request body
* @see https://developer.crowdin.com/api/v2/#operation/api.projects.distributions.release.post
*/
createDistributionRelease(
projectId: number,
hash: string,
): Promise<
ResponseObject<DistributionsModel.DistributionRelease | DistributionsModel.DistributionStringsBasedRelease>
> {
const url = `${this.url}/projects/${projectId}/distributions/${hash}/release`;
return this.post(url, {}, this.defaultConfig());
}
}
export namespace DistributionsModel {
export interface Distribution {
hash: string;
exportMode: ExportMode;
name: string;
fileIds: number[];
bundleIds: number[];
format: string;
exportPattern: string;
labelIds: number[];
createdAt: string;
updatedAt: string;
}
export interface CreateDistributionRequest {
exportMode?: ExportMode;
name: string;
fileIds?: number[];
bundleIds?: number[];
/**
* @deprecated This property is deprecated. Use bundleIds instead
*/
format?: string;
/**
* @deprecated This property is deprecated. Use bundleIds instead
*/
exportPattern?: string;
/**
* @deprecated This property is deprecated. Use bundleIds instead
*/
labelIds?: number[];
}
export interface CreateDistributionStringsBasedRequest {
name: string;
bundleIds: number[];
}
export interface DistributionRelease {
status: string;
progress: number;
currentLanguageId: string;
currentFileId: number;
date: string;
}
export interface DistributionStringsBasedRelease {
status: string;
progress: number;
currentLanguageId: string;
currentBranchId: number;
date: string;
}
export type ExportMode = 'default' | 'bundle';
}