@open-norantec/utilities 2.2.0 → 2.4.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.
@@ -3,6 +3,7 @@ export declare class OctoUtil {
3
3
  private readonly inputConfig?;
4
4
  static readonly CONFIG: z.ZodObject<{
5
5
  apiPrefix: z.ZodDefault<z.ZodURL>;
6
+ auth: z.ZodDefault<z.ZodString>;
6
7
  owner: z.ZodDefault<z.ZodString>;
7
8
  repo: z.ZodDefault<z.ZodString>;
8
9
  }, z.core.$strip>;
@@ -10,6 +11,7 @@ export declare class OctoUtil {
10
11
  constructor(inputConfig?: Partial<Config> | undefined);
11
12
  protected get config(): {
12
13
  apiPrefix: string;
14
+ auth: string;
13
15
  owner: string;
14
16
  repo: string;
15
17
  };
@@ -20,7 +22,9 @@ export declare class OctoUtil {
20
22
  retryRequest: (error: import("octokit").RequestError, retries: number, retryAfter: number) => import("octokit").RequestError;
21
23
  };
22
24
  };
23
- ensureReleaseByTagName(tagName: string): Promise<{
25
+ ensureReleaseByTagName({ tagName }: {
26
+ tagName: string;
27
+ }): Promise<{
24
28
  url: string;
25
29
  html_url: string;
26
30
  assets_url: string;
@@ -47,8 +51,20 @@ export declare class OctoUtil {
47
51
  discussion_url?: string;
48
52
  reactions?: import("@octokit/openapi-types").components["schemas"]["reaction-rollup"];
49
53
  }>;
50
- getReleaseAssetContentByTagNameAndFileName(tagName: string, fileName: string): Promise<Buffer | null>;
51
- uploadReleaseAssetByTagName(tagName: string, fileName: string, content: Buffer, type: string): Promise<{
54
+ getReleaseAssetContentByTagNameAndFileName({ tagName, fileName, }: {
55
+ fileName: string;
56
+ tagName: string;
57
+ }): Promise<Buffer | null>;
58
+ deleteReleaseAssetByTagName({ fileName, tagName }: {
59
+ fileName: string;
60
+ tagName: string;
61
+ }): Promise<import("@octokit/types").OctokitResponse<never, 204>>;
62
+ uploadReleaseAssetByTagName({ tagName, fileName, content, type, }: {
63
+ content: Buffer;
64
+ fileName: string;
65
+ tagName: string;
66
+ type?: string;
67
+ }): Promise<{
52
68
  url: string;
53
69
  browser_download_url: string;
54
70
  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
  });
@@ -105,6 +127,7 @@ class OctoUtil {
105
127
  exports.OctoUtil = OctoUtil;
106
128
  OctoUtil.CONFIG = zod_1.z.object({
107
129
  apiPrefix: zod_1.z.url().nonempty().default('https://api.gp1.norantec.com'),
130
+ auth: zod_1.z.string().nonempty().default(' '),
108
131
  owner: zod_1.z.string().nonempty().default('getnauti'),
109
132
  repo: zod_1.z.string().nonempty().default('task-records'),
110
133
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-norantec/utilities",
3
- "version": "2.2.0",
3
+ "version": "2.4.0",
4
4
  "description": "NoranTec Utilities",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {