@open-norantec/utilities 2.2.0 → 2.3.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.
@@ -20,7 +20,9 @@ export declare class OctoUtil {
20
20
  retryRequest: (error: import("octokit").RequestError, retries: number, retryAfter: number) => import("octokit").RequestError;
21
21
  };
22
22
  };
23
- ensureReleaseByTagName(tagName: string): Promise<{
23
+ ensureReleaseByTagName({ tagName }: {
24
+ tagName: string;
25
+ }): Promise<{
24
26
  url: string;
25
27
  html_url: string;
26
28
  assets_url: string;
@@ -47,8 +49,20 @@ export declare class OctoUtil {
47
49
  discussion_url?: string;
48
50
  reactions?: import("@octokit/openapi-types").components["schemas"]["reaction-rollup"];
49
51
  }>;
50
- getReleaseAssetContentByTagNameAndFileName(tagName: string, fileName: string): Promise<Buffer | null>;
51
- uploadReleaseAssetByTagName(tagName: string, fileName: string, content: Buffer, type: string): Promise<{
52
+ getReleaseAssetContentByTagNameAndFileName({ tagName, fileName, }: {
53
+ fileName: string;
54
+ tagName: string;
55
+ }): Promise<Buffer | null>;
56
+ deleteReleaseAssetByTagName({ fileName, tagName }: {
57
+ fileName: string;
58
+ tagName: string;
59
+ }): Promise<import("@octokit/types").OctokitResponse<never, 204>>;
60
+ uploadReleaseAssetByTagName({ tagName, fileName, content, type, }: {
61
+ content: Buffer;
62
+ fileName: string;
63
+ tagName: string;
64
+ type?: string;
65
+ }): Promise<{
52
66
  url: string;
53
67
  browser_download_url: string;
54
68
  id: number;
@@ -26,8 +26,8 @@ class OctoUtil {
26
26
  this.octokitInstance = new octokit_1.Octokit({ auth: process.env.GITHUB_TOKEN });
27
27
  return this.octokitInstance;
28
28
  }
29
- ensureReleaseByTagName(tagName) {
30
- return __awaiter(this, void 0, void 0, function* () {
29
+ ensureReleaseByTagName(_a) {
30
+ return __awaiter(this, arguments, void 0, function* ({ tagName }) {
31
31
  return yield this.octokit.rest.repos
32
32
  .getReleaseByTag({
33
33
  owner: this.config.owner,
@@ -53,14 +53,13 @@ class OctoUtil {
53
53
  });
54
54
  });
55
55
  }
56
- getReleaseAssetContentByTagNameAndFileName(tagName, fileName) {
57
- return __awaiter(this, void 0, void 0, function* () {
56
+ getReleaseAssetContentByTagNameAndFileName(_a) {
57
+ return __awaiter(this, arguments, void 0, function* ({ tagName, fileName, }) {
58
58
  return yield this.octokit.rest.repos
59
59
  .getReleaseByTag({
60
60
  owner: this.config.owner,
61
61
  repo: this.config.repo,
62
62
  tag: tagName,
63
- baseUrl: this.config.apiPrefix,
64
63
  })
65
64
  .then((response) => { var _a, _b, _c; return (_c = (_b = (_a = response.data.assets) === null || _a === void 0 ? void 0 : _a.find) === null || _b === void 0 ? void 0 : _b.call(_a, (asset) => (asset === null || asset === void 0 ? void 0 : asset.name) === fileName)) === null || _c === void 0 ? void 0 : _c.id; })
66
65
  .then((assetId) => {
@@ -82,9 +81,32 @@ class OctoUtil {
82
81
  });
83
82
  });
84
83
  }
85
- uploadReleaseAssetByTagName(tagName, fileName, content, type) {
86
- return __awaiter(this, void 0, void 0, function* () {
87
- return yield this.ensureReleaseByTagName(tagName)
84
+ deleteReleaseAssetByTagName(_a) {
85
+ return __awaiter(this, arguments, void 0, function* ({ fileName, tagName }) {
86
+ return yield this.octokit.rest.repos
87
+ .getReleaseByTag({
88
+ owner: this.config.owner,
89
+ repo: this.config.repo,
90
+ tag: tagName,
91
+ })
92
+ .then((response) => { var _a, _b, _c; return (_c = (_b = (_a = response.data.assets) === null || _a === void 0 ? void 0 : _a.find) === null || _b === void 0 ? void 0 : _b.call(_a, (asset) => (asset === null || asset === void 0 ? void 0 : asset.name) === fileName)) === null || _c === void 0 ? void 0 : _c.id; })
93
+ .then((id) => {
94
+ if (!(Number(id) > 0))
95
+ return Promise.reject(`Could not find asset file named ${fileName}`);
96
+ return id;
97
+ })
98
+ .then((id) => {
99
+ return this.octokit.rest.repos.deleteReleaseAsset({
100
+ asset_id: id,
101
+ owner: this.config.owner,
102
+ repo: this.config.repo,
103
+ });
104
+ });
105
+ });
106
+ }
107
+ uploadReleaseAssetByTagName(_a) {
108
+ return __awaiter(this, arguments, void 0, function* ({ tagName, fileName, content, type, }) {
109
+ return yield this.ensureReleaseByTagName({ tagName })
88
110
  .then((release) => {
89
111
  return this.octokit.rest.repos.uploadReleaseAsset({
90
112
  owner: this.config.owner,
@@ -93,7 +115,7 @@ class OctoUtil {
93
115
  name: fileName,
94
116
  data: content.toString(),
95
117
  headers: {
96
- 'content-type': type,
118
+ 'content-type': type !== null && type !== void 0 ? type : 'application/octet-stream',
97
119
  length: content.byteLength,
98
120
  },
99
121
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-norantec/utilities",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "NoranTec Utilities",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {