-
Notifications
You must be signed in to change notification settings - Fork 141
/
package_api.dart
332 lines (258 loc) · 9.66 KB
/
package_api.dart
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:json_annotation/json_annotation.dart';
part 'package_api.g.dart';
/// Information for uploading a package.
@JsonSerializable()
class UploadInfo {
/// The endpoint where the uploaded data should be posted.
///
/// The upload is a POST to [url] with the headers [fields] in the HTTP
/// request. The body of the POST request must be a valid tar.gz file.
final String url;
/// The fields the uploader should add to the multipart upload.
final Map<String, String>? fields;
UploadInfo({
required this.url,
required this.fields,
});
factory UploadInfo.fromJson(Map<String, dynamic> json) =>
_$UploadInfoFromJson(json);
Map<String, dynamic> toJson() => _$UploadInfoToJson(this);
}
/// Options and flags to get/set on a package.
@JsonSerializable()
class PkgOptions {
final bool? isDiscontinued;
final String? replacedBy;
final bool? isUnlisted;
PkgOptions({
this.isDiscontinued,
this.replacedBy,
this.isUnlisted,
});
factory PkgOptions.fromJson(Map<String, dynamic> json) =>
_$PkgOptionsFromJson(json);
Map<String, dynamic> toJson() => _$PkgOptionsToJson(this);
}
/// The configuration for a package's credential-less publishing.
@JsonSerializable(includeIfNull: false, explicitToJson: true)
class AutomatedPublishingConfig {
final GithubPublishingConfig? github;
final GcpPublishingConfig? gcp;
AutomatedPublishingConfig({
this.github,
this.gcp,
});
factory AutomatedPublishingConfig.fromJson(Map<String, dynamic> json) =>
_$AutomatedPublishingConfigFromJson(json);
Map<String, dynamic> toJson() => _$AutomatedPublishingConfigToJson(this);
}
@JsonSerializable(includeIfNull: false, explicitToJson: true)
class GithubPublishingConfig {
bool isEnabled;
/// The `owner/repository` path of the project on github.com.
String? repository;
/// The tag pattern that is required for the publishing.
///
/// This pattern must have a single `{{version}}` field somewhere
/// in it, otherwise it is a character-to-character match, with no
/// regular expressions or other templating substitutes.
///
/// Some of the expected values:
/// - `{{version}}`
/// - `v{{version}}`
/// - `subproject-v{{version}}`
String? tagPattern;
/// Whether to require the action from a specific environment.
bool requireEnvironment;
/// The GitHub environment where the publishing is required from.
String? environment;
/// Whether the (default) `push` event is enabled.
bool isPushEventEnabled;
/// Whether the `workflow_dispatch` event is enabled.
bool isWorkflowDispatchEventEnabled;
GithubPublishingConfig({
this.isEnabled = false,
this.repository,
this.tagPattern,
this.requireEnvironment = false,
this.environment,
// MUST default to true, because this was the default behavior before
// isWorkflowDispatchEventEnabled was introduced!
this.isPushEventEnabled = true,
// MUST default to false, because the default behavior prior to the
// introduction of isWorkflowDispatchEventEnabled was to only allow
// publishing from push events.
this.isWorkflowDispatchEventEnabled = false,
});
factory GithubPublishingConfig.fromJson(Map<String, dynamic> json) =>
_$GithubPublishingConfigFromJson(json);
Map<String, dynamic> toJson() => _$GithubPublishingConfigToJson(this);
}
@JsonSerializable(includeIfNull: false, explicitToJson: true)
class GcpPublishingConfig {
bool isEnabled;
String? serviceAccountEmail;
GcpPublishingConfig({
this.isEnabled = false,
this.serviceAccountEmail,
});
factory GcpPublishingConfig.fromJson(Map<String, dynamic> json) =>
_$GcpPublishingConfigFromJson(json);
Map<String, dynamic> toJson() => _$GcpPublishingConfigToJson(this);
}
@JsonSerializable()
class VersionOptions {
final bool? isRetracted;
VersionOptions({
this.isRetracted,
});
factory VersionOptions.fromJson(Map<String, dynamic> json) =>
_$VersionOptionsFromJson(json);
Map<String, dynamic> toJson() => _$VersionOptionsToJson(this);
}
/// Publisher ownership to get/set on a package.
@JsonSerializable()
class PackagePublisherInfo {
/// Domain name of the publisher that owns this package, `null` if package
/// is not owned by a publisher.
final String? publisherId;
PackagePublisherInfo({
this.publisherId,
});
factory PackagePublisherInfo.fromJson(Map<String, dynamic> json) =>
_$PackagePublisherInfoFromJson(json);
Map<String, dynamic> toJson() => _$PackagePublisherInfoToJson(this);
}
/// A simple response communicating the operation was successful.
@JsonSerializable()
class SuccessMessage {
final Message success;
SuccessMessage({required this.success});
factory SuccessMessage.fromJson(Map<String, dynamic> json) =>
_$SuccessMessageFromJson(json);
Map<String, dynamic> toJson() => _$SuccessMessageToJson(this);
}
/// A message wrapper for pub client API compatibility.
@JsonSerializable()
class Message {
final String message;
Message({required this.message});
factory Message.fromJson(Map<String, dynamic> json) =>
_$MessageFromJson(json);
Map<String, dynamic> toJson() => _$MessageToJson(this);
}
/// Used in `pub` client for finding which versions exist.
/// (`listVersions` method in pubapi)
@JsonSerializable(includeIfNull: false)
class PackageData {
/// Package name.
final String name;
/// `true` if package is discontinued.
/// If it is omitted, `null` or `false` the package is *not discontinued*.
final bool? isDiscontinued;
/// If [isDiscontinued] is set, this _may_ point to a package that can be used
/// instead (set by the package admin).
final String? replacedBy;
/// This is merely a convenience property, because the [VersionInfo] for the
/// latest version also exists in the [versions] list.
///
/// This is the latest that is NOT a pre-release, unless there only is
/// pre-releases in the [versions] list.
final VersionInfo latest;
/// The available versions, sorted by their semantic version number (ascending).
final List<VersionInfo> versions;
/// The latest point the /advisories endpoint was updated.
final DateTime? advisoriesUpdated;
PackageData({
required this.name,
this.isDiscontinued,
this.replacedBy,
required this.latest,
required this.versions,
this.advisoriesUpdated,
});
factory PackageData.fromJson(Map<String, dynamic> json) =>
_$PackageDataFromJson(json);
Map<String, dynamic> toJson() => _$PackageDataToJson(this);
// The cached version list contains the versions in semantically ascending order.
// By reversing that list, we will have them in semantically descending order,
// which is the preferred order for displaying on the versions page.
late final List<VersionInfo> descendingVersions = versions.reversed.toList();
}
@JsonSerializable(includeIfNull: false)
class VersionInfo {
final String version;
/// `true` if version is retracted.
/// If it is omitted, `null` or `false` the package is *not retracted*.
final bool? retracted;
final Map<String, dynamic> pubspec;
/// As of Dart 2.8 `pub` client uses [archiveUrl] to find the archive.
@JsonKey(name: 'archive_url')
final String? archiveUrl;
/// The SHA-256 hash of the canonical archive.
@JsonKey(name: 'archive_sha256')
final String? archiveSha256;
/// This is an optional field of the API response, it may be `null` or omitted.
final DateTime? published;
VersionInfo({
required this.version,
required this.retracted,
required this.pubspec,
required this.archiveUrl,
required this.archiveSha256,
required this.published,
});
factory VersionInfo.fromJson(Map<String, dynamic> json) =>
_$VersionInfoFromJson(json);
Map<String, dynamic> toJson() => _$VersionInfoToJson(this);
}
@JsonSerializable(includeIfNull: false)
class VersionScore {
final int? grantedPoints;
final int? maxPoints;
final int? likeCount;
final double? popularityScore;
final List<String>? tags;
final DateTime? lastUpdated;
VersionScore({
required this.grantedPoints,
required this.maxPoints,
required this.likeCount,
required this.popularityScore,
required this.tags,
required this.lastUpdated,
});
factory VersionScore.fromJson(Map<String, dynamic> json) =>
_$VersionScoreFromJson(json);
Map<String, dynamic> toJson() => _$VersionScoreToJson(this);
}
/// Request payload for removing an uploader from a package.
@JsonSerializable()
class RemoveUploaderRequest {
/// Email of the uploader to be removed.
///
/// This must be the primary email associated with the users Google Account.
final String email;
RemoveUploaderRequest({required this.email});
factory RemoveUploaderRequest.fromJson(Map<String, dynamic> json) =>
_$RemoveUploaderRequestFromJson(json);
Map<String, dynamic> toJson() => _$RemoveUploaderRequestToJson(this);
}
/// Request payload for inviting a new user to become uploader of a package.
@JsonSerializable()
class InviteUploaderRequest {
/// Email to which the invitation will be sent.
///
/// This must be the primary email associated with the invited users Google
/// Account. The invited user will later be required to sign-in with a
/// Google Account that has this email in-order to accept the invitation.
final String email;
// json_serializable boiler-plate
InviteUploaderRequest({required this.email});
factory InviteUploaderRequest.fromJson(Map<String, dynamic> json) =>
_$InviteUploaderRequestFromJson(json);
Map<String, dynamic> toJson() => _$InviteUploaderRequestToJson(this);
}