@open-norantec/utilities 2.1.4 → 2.2.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.
package/dist/enums.d.ts CHANGED
@@ -49,8 +49,8 @@ export declare namespace Enums {
49
49
  readonly DEBUG: "debug";
50
50
  };
51
51
  }
52
- export declare namespace EnumTypes {
53
- type OrderOrientation = (typeof Enums.OrderOrientation)[keyof typeof Enums.OrderOrientation];
54
- type WhereClauseOp = (typeof Enums.WhereClauseOp)[keyof typeof Enums.WhereClauseOp];
55
- type LogLevel = (typeof Enums.LogLevel)[keyof typeof Enums.LogLevel];
52
+ export interface EnumTypes {
53
+ OrderOrientation: (typeof Enums.OrderOrientation)[keyof typeof Enums.OrderOrientation];
54
+ WhereClauseOp: (typeof Enums.WhereClauseOp)[keyof typeof Enums.WhereClauseOp];
55
+ LogLevel: (typeof Enums.LogLevel)[keyof typeof Enums.LogLevel];
56
56
  }
@@ -1,7 +1,7 @@
1
1
  import { EnumTypes } from './enums';
2
2
  export declare class LogUtil {
3
3
  private readonly defaultLogLevel;
4
- constructor(defaultLogLevel?: EnumTypes.LogLevel);
5
- match(bottomLogLevel: EnumTypes.LogLevel | boolean, logLevel: EnumTypes.LogLevel): boolean;
6
- log(level: EnumTypes.LogLevel, message: string | Error): void;
4
+ constructor(defaultLogLevel?: EnumTypes['LogLevel']);
5
+ match(bottomLogLevel: EnumTypes['LogLevel'] | boolean, logLevel: EnumTypes['LogLevel']): boolean;
6
+ log(level: EnumTypes['LogLevel'], message: string | Error): void;
7
7
  }
@@ -0,0 +1,68 @@
1
+ import { z } from './zod';
2
+ export declare class OctoUtil {
3
+ private readonly inputConfig?;
4
+ static readonly CONFIG: z.ZodObject<{
5
+ apiPrefix: z.ZodDefault<z.ZodURL>;
6
+ owner: z.ZodDefault<z.ZodString>;
7
+ repo: z.ZodDefault<z.ZodString>;
8
+ }, z.core.$strip>;
9
+ private octokitInstance;
10
+ constructor(inputConfig?: Partial<Config> | undefined);
11
+ protected get config(): {
12
+ apiPrefix: string;
13
+ owner: string;
14
+ repo: string;
15
+ };
16
+ protected get octokit(): import("@octokit/core").Octokit & {
17
+ paginate: import("@octokit/plugin-paginate-rest").PaginateInterface;
18
+ } & import("@octokit/plugin-paginate-graphql").paginateGraphQLInterface & import("@octokit/plugin-rest-endpoint-methods").Api & {
19
+ retry: {
20
+ retryRequest: (error: import("octokit").RequestError, retries: number, retryAfter: number) => import("octokit").RequestError;
21
+ };
22
+ };
23
+ ensureReleaseByTagName(tagName: string): Promise<{
24
+ url: string;
25
+ html_url: string;
26
+ assets_url: string;
27
+ upload_url: string;
28
+ tarball_url: string | null;
29
+ zipball_url: string | null;
30
+ id: number;
31
+ node_id: string;
32
+ tag_name: string;
33
+ target_commitish: string;
34
+ name: string | null;
35
+ body?: string | null;
36
+ draft: boolean;
37
+ prerelease: boolean;
38
+ immutable?: boolean;
39
+ created_at: string;
40
+ published_at: string | null;
41
+ updated_at?: string | null;
42
+ author: import("@octokit/openapi-types").components["schemas"]["simple-user"];
43
+ assets: import("@octokit/openapi-types").components["schemas"]["release-asset"][];
44
+ body_html?: string;
45
+ body_text?: string;
46
+ mentions_count?: number;
47
+ discussion_url?: string;
48
+ reactions?: import("@octokit/openapi-types").components["schemas"]["reaction-rollup"];
49
+ }>;
50
+ getReleaseAssetContentByTagNameAndFileName(tagName: string, fileName: string): Promise<Buffer | null>;
51
+ uploadReleaseAssetByTagName(tagName: string, fileName: string, content: Buffer, type: string): Promise<{
52
+ url: string;
53
+ browser_download_url: string;
54
+ id: number;
55
+ node_id: string;
56
+ name: string;
57
+ label: string | null;
58
+ state: "uploaded" | "open";
59
+ content_type: string;
60
+ size: number;
61
+ digest: string | null;
62
+ download_count: number;
63
+ created_at: string;
64
+ updated_at: string;
65
+ uploader: import("@octokit/openapi-types").components["schemas"]["nullable-simple-user"];
66
+ }>;
67
+ }
68
+ export type Config = z.infer<typeof OctoUtil.CONFIG>;
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.OctoUtil = void 0;
13
+ const octokit_1 = require("octokit");
14
+ const zod_1 = require("./zod");
15
+ class OctoUtil {
16
+ constructor(inputConfig) {
17
+ this.inputConfig = inputConfig;
18
+ this.octokitInstance = undefined;
19
+ }
20
+ get config() {
21
+ return OctoUtil.CONFIG.parse(this.inputConfig);
22
+ }
23
+ get octokit() {
24
+ if (this.octokitInstance instanceof octokit_1.Octokit)
25
+ return this.octokitInstance;
26
+ this.octokitInstance = new octokit_1.Octokit({ auth: process.env.GITHUB_TOKEN });
27
+ return this.octokitInstance;
28
+ }
29
+ ensureReleaseByTagName(tagName) {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ return yield this.octokit.rest.repos
32
+ .getReleaseByTag({
33
+ owner: this.config.owner,
34
+ repo: this.config.repo,
35
+ tag: tagName,
36
+ baseUrl: this.config.apiPrefix,
37
+ })
38
+ .then((response) => response.data)
39
+ .catch((error) => {
40
+ if ((error === null || error === void 0 ? void 0 : error.status) === 404) {
41
+ return this.octokit.rest.repos
42
+ .createRelease({
43
+ tag_name: tagName,
44
+ target_commitish: 'main',
45
+ owner: this.config.owner,
46
+ repo: this.config.repo,
47
+ })
48
+ .then((response) => response.data);
49
+ }
50
+ else {
51
+ return Promise.reject(error);
52
+ }
53
+ });
54
+ });
55
+ }
56
+ getReleaseAssetContentByTagNameAndFileName(tagName, fileName) {
57
+ return __awaiter(this, void 0, void 0, function* () {
58
+ return yield this.octokit.rest.repos
59
+ .getReleaseByTag({
60
+ owner: this.config.owner,
61
+ repo: this.config.repo,
62
+ tag: tagName,
63
+ baseUrl: this.config.apiPrefix,
64
+ })
65
+ .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
+ .then((assetId) => {
67
+ if (typeof assetId !== 'number' || !(assetId > 0))
68
+ return null;
69
+ return this.octokit.rest.repos.getReleaseAsset({
70
+ asset_id: assetId,
71
+ repo: this.config.repo,
72
+ owner: this.config.owner,
73
+ headers: {
74
+ accept: 'application/octet-stream',
75
+ },
76
+ });
77
+ })
78
+ .then((response) => {
79
+ if (!((response === null || response === void 0 ? void 0 : response.data) instanceof ArrayBuffer))
80
+ return null;
81
+ return Buffer.from(response.data);
82
+ });
83
+ });
84
+ }
85
+ uploadReleaseAssetByTagName(tagName, fileName, content, type) {
86
+ return __awaiter(this, void 0, void 0, function* () {
87
+ return yield this.ensureReleaseByTagName(tagName)
88
+ .then((release) => {
89
+ return this.octokit.rest.repos.uploadReleaseAsset({
90
+ owner: this.config.owner,
91
+ repo: this.config.repo,
92
+ release_id: release.id,
93
+ name: fileName,
94
+ data: content.toString(),
95
+ headers: {
96
+ 'content-type': type,
97
+ length: content.byteLength,
98
+ },
99
+ });
100
+ })
101
+ .then((response) => response.data);
102
+ });
103
+ }
104
+ }
105
+ exports.OctoUtil = OctoUtil;
106
+ OctoUtil.CONFIG = zod_1.z.object({
107
+ apiPrefix: zod_1.z.url().nonempty().default('https://api.gp1.norantec.com'),
108
+ owner: zod_1.z.string().nonempty().default('getnauti'),
109
+ repo: zod_1.z.string().nonempty().default('task-records'),
110
+ });
package/dist/schemas.d.ts CHANGED
@@ -482,17 +482,17 @@ export declare namespace Schemas {
482
482
  }, z.core.$strip>], "type">>>>;
483
483
  }, z.core.$strip>;
484
484
  }
485
- export declare namespace SchemaTypes {
486
- type CommonResult = z.infer<typeof Schemas.COMMON_RESULT>;
487
- type File = z.infer<typeof Schemas.FILE>;
488
- type FindOneOptions = z.infer<typeof Schemas.FIND_ONE_OPTIONS>;
489
- type IDObject = z.infer<typeof Schemas.ID_OBJECT>;
490
- type LogLevel = z.infer<typeof Schemas.LOG_LEVEL>;
491
- type OrderItem = z.infer<typeof Schemas.ORDER_ITEM>;
492
- type OrderOrientation = z.infer<typeof Schemas.ORDER_ORIENTATION>;
493
- type PaginationOptions = z.infer<typeof Schemas.PAGINATION_OPTIONS>;
494
- type PaginationResult = z.infer<typeof Schemas.PAGINATION_RESULT>;
495
- type TimeRecord = z.infer<typeof Schemas.TIME_RECORD>;
496
- type WhereClause = z.infer<typeof Schemas.WHERE_CLAUSE>;
497
- type WhereClauseOp = z.infer<typeof Schemas.WHERE_CLAUSE_OP>;
485
+ export interface SchemaTypes {
486
+ CommonResult: z.infer<typeof Schemas.COMMON_RESULT>;
487
+ File: z.infer<typeof Schemas.FILE>;
488
+ FindOneOptions: z.infer<typeof Schemas.FIND_ONE_OPTIONS>;
489
+ IDObject: z.infer<typeof Schemas.ID_OBJECT>;
490
+ LogLevel: z.infer<typeof Schemas.LOG_LEVEL>;
491
+ OrderItem: z.infer<typeof Schemas.ORDER_ITEM>;
492
+ OrderOrientation: z.infer<typeof Schemas.ORDER_ORIENTATION>;
493
+ PaginationOptions: z.infer<typeof Schemas.PAGINATION_OPTIONS>;
494
+ PaginationResult: z.infer<typeof Schemas.PAGINATION_RESULT>;
495
+ TimeRecord: z.infer<typeof Schemas.TIME_RECORD>;
496
+ WhereClause: z.infer<typeof Schemas.WHERE_CLAUSE>;
497
+ WhereClauseOp: z.infer<typeof Schemas.WHERE_CLAUSE_OP>;
498
498
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-norantec/utilities",
3
- "version": "2.1.4",
3
+ "version": "2.2.0",
4
4
  "description": "NoranTec Utilities",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -36,6 +36,7 @@
36
36
  "@types/node": "18.11.18",
37
37
  "cross-env": "^7.0.3",
38
38
  "eslint": "^10.3.0",
39
+ "octokit": "^5.0.5",
39
40
  "rimraf": "^6.0.1",
40
41
  "ts-node": "^10.0.0",
41
42
  "type-fest": "^4.37.0",
@@ -52,5 +53,13 @@
52
53
  "prettier": "^3.0.0",
53
54
  "uuid": "^11.1.0",
54
55
  "zod": "^4.4.3"
56
+ },
57
+ "peerDependencies": {
58
+ "octokit": ">=5.0.0"
59
+ },
60
+ "peerDependenciesMeta": {
61
+ "octokit": {
62
+ "optional": true
63
+ }
55
64
  }
56
65
  }