@rdyl/node-koa-controller 0.5.9 → 0.6.1

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/CHANGELOG.md CHANGED
@@ -1,4 +1,4 @@
1
- ## 0.5.7 (2026-01-07)
1
+ ## 0.6.1 (2026-01-07)
2
2
 
3
3
 
4
4
 
package/dist/cache.js CHANGED
@@ -111,7 +111,7 @@ var ASTCache = /** @class */ (function () {
111
111
  handlers.forEach(function (handler) {
112
112
  var method = handler.method, url = handler.url, name = handler.name, hAuth = handler.auth;
113
113
  var path = (0, path_1.join)("/" + ASTCache.prefix, prefix, url);
114
- var isPublic = route.isPublic || handler.isPublic;
114
+ var isPublic = cAuth.isPublic || hAuth.isPublic;
115
115
  if (isPublic) {
116
116
  ASTCache.whitelist.push(path);
117
117
  }
@@ -209,6 +209,7 @@ var ASTCache = /** @class */ (function () {
209
209
  ASTCache.prefix = "";
210
210
  ASTCache.routes = [];
211
211
  ASTCache.whitelist = [];
212
+ ASTCache.authList = [];
212
213
  return ASTCache;
213
214
  }());
214
215
  exports.default = ASTCache;
package/dist/index.js CHANGED
@@ -95,6 +95,7 @@ function useApiController(props) {
95
95
  ip = (0, utils_1.getIPAdress)();
96
96
  return [2 /*return*/, {
97
97
  whitelist: cache_1.default.whitelist,
98
+ authList: Array.from(new Set(cache_1.default.authList)),
98
99
  port: port,
99
100
  prefix: prefix,
100
101
  ip: ip,
package/dist/meta.js CHANGED
@@ -55,7 +55,7 @@ var BaseController = /** @class */ (function () {
55
55
  function BaseController(_ctx) {
56
56
  this._ctx = _ctx;
57
57
  this.jwt = {
58
- token: '',
58
+ token: "",
59
59
  current: {},
60
60
  permissions: [],
61
61
  };
@@ -85,7 +85,7 @@ var BaseController = /** @class */ (function () {
85
85
  var b = values[k];
86
86
  if (!b)
87
87
  return null;
88
- if (b === '1' || b === 'true' || b === 'TRUE') {
88
+ if (b === "1" || b === "true" || b === "TRUE") {
89
89
  return true;
90
90
  }
91
91
  return false;
@@ -113,7 +113,7 @@ var BaseController = /** @class */ (function () {
113
113
  var b = values[k];
114
114
  if (!b)
115
115
  return null;
116
- if (b === '1' || b === 'true' || b === 'TRUE') {
116
+ if (b === "1" || b === "true" || b === "TRUE") {
117
117
  return true;
118
118
  }
119
119
  return false;
@@ -143,7 +143,7 @@ var BaseController = /** @class */ (function () {
143
143
  get: function () {
144
144
  var _this = this;
145
145
  var sendJson = function (body) {
146
- _this._ctx.response.set('Content-Type', 'application/json;charset=utf-8');
146
+ _this._ctx.response.set("Content-Type", "application/json;charset=utf-8");
147
147
  _this._ctx.status = body.code;
148
148
  _this._ctx.body = body;
149
149
  };
@@ -151,39 +151,39 @@ var BaseController = /** @class */ (function () {
151
151
  raw: function (body, headers) {
152
152
  var _a;
153
153
  if (headers === void 0) { headers = {}; }
154
- _this._ctx.response.set('Content-Type', (_a = headers['Content-Type']) !== null && _a !== void 0 ? _a : 'application/json;charset=utf-8');
154
+ _this._ctx.response.set("Content-Type", (_a = headers["Content-Type"]) !== null && _a !== void 0 ? _a : "application/json;charset=utf-8");
155
155
  _this._ctx.status = 200;
156
156
  _this._ctx.body = body;
157
157
  },
158
158
  ok: function (data) {
159
- sendJson({ data: data, code: 200, msg: 'ok' });
159
+ sendJson({ data: data, code: 200, msg: "ok" });
160
160
  },
161
161
  okCreated: function (data, msg) {
162
- if (msg === void 0) { msg = 'ok created'; }
162
+ if (msg === void 0) { msg = "ok created"; }
163
163
  sendJson({ code: 201, data: data, msg: msg });
164
164
  },
165
165
  okAccept: function (data, msg) {
166
- if (msg === void 0) { msg = 'ok accept'; }
166
+ if (msg === void 0) { msg = "ok accept"; }
167
167
  sendJson({ code: 203, data: data, msg: msg });
168
168
  },
169
169
  parameterError: function (msg) {
170
- if (msg === void 0) { msg = 'Parameter Error'; }
170
+ if (msg === void 0) { msg = "Parameter Error"; }
171
171
  sendJson({ msg: msg, code: 400 });
172
172
  },
173
173
  unauthorized: function (msg) {
174
- if (msg === void 0) { msg = 'User Unauthorized'; }
174
+ if (msg === void 0) { msg = "User Unauthorized"; }
175
175
  sendJson({ msg: msg, code: 401 });
176
176
  },
177
177
  inaccessible: function (msg) {
178
- if (msg === void 0) { msg = 'User Inaccessible'; }
178
+ if (msg === void 0) { msg = "User Inaccessible"; }
179
179
  sendJson({ msg: msg, code: 403 });
180
180
  },
181
181
  exception: function (msg) {
182
- if (msg === void 0) { msg = 'Service Exception'; }
182
+ if (msg === void 0) { msg = "Service Exception"; }
183
183
  sendJson({ msg: msg, code: 500 });
184
184
  },
185
185
  unavailable: function (msg) {
186
- if (msg === void 0) { msg = 'Service Unavailable'; }
186
+ if (msg === void 0) { msg = "Service Unavailable"; }
187
187
  sendJson({ msg: msg, code: 503 });
188
188
  },
189
189
  };
@@ -197,7 +197,6 @@ exports.BaseController = BaseController;
197
197
  function MethodFactory(method) {
198
198
  return function (url) {
199
199
  return function (target, name) {
200
- console.log('method', name);
201
200
  var item = {
202
201
  url: url,
203
202
  method: method,
@@ -232,6 +231,9 @@ function Controller(prefix) {
232
231
  };
233
232
  }
234
233
  function AuthControl(name, mode) {
234
+ var _a;
235
+ var keys = typeof name === "string" ? [name] : name || [];
236
+ (_a = cache_1.default.authList).push.apply(_a, keys);
235
237
  return function (target, method) {
236
238
  if (method) {
237
239
  target.routes.forEach(function (ele) {
package/dist/utils.js CHANGED
@@ -152,9 +152,7 @@ function ParsedAuthControl() {
152
152
  var any = [];
153
153
  for (var _a = 0, auths_1 = auths; _a < auths_1.length; _a++) {
154
154
  var auth = auths_1[_a];
155
- var _b = auth.mode, mode = _b === void 0 ? "AND" : _b, _c = auth.name, name_1 = _c === void 0 ? [] : _c, isPublic = auth.isPublic;
156
- if (isPublic)
157
- continue;
155
+ var _b = auth.mode, mode = _b === void 0 ? "AND" : _b, _c = auth.name, name_1 = _c === void 0 ? [] : _c;
158
156
  var keys = typeof name_1 === "string" ? [name_1] : name_1;
159
157
  if (!keys.length)
160
158
  continue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rdyl/node-koa-controller",
3
- "version": "0.5.9",
3
+ "version": "0.6.1",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "types/index.d.ts",
@@ -15,7 +15,7 @@
15
15
  ],
16
16
  "scripts": {
17
17
  "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0",
18
- "build": "tsc && copyfiles -u 1 src/**/*.d.ts src/*.d.ts types && npm run changelog && git add CHANGELOG.md"
18
+ "build": "tsc && copyfiles -u 1 src/**/*.d.ts src/*.d.ts types && copyfiles -u 1 src/**/*.ejs src/*.ejs dist && npm run changelog && git add CHANGELOG.md"
19
19
  },
20
20
  "dependencies": {
21
21
  "@koa/router": "^15.1.1",
package/types/cache.d.ts CHANGED
@@ -5,6 +5,7 @@ export default class ASTCache {
5
5
  static prefix: string;
6
6
  static routes: ASTCacheRoute[];
7
7
  static whitelist: (string | RegExp)[];
8
+ static authList: string[];
8
9
  static resolve(dir: string): Promise<void>;
9
10
  static register(router: RouterInstance, useJwt?: UseJwtHandler): void;
10
11
  }
package/types/meta.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { ParameterizedContext } from 'koa';
2
- import { ExtendedFormidableOptions } from 'koa-body';
1
+ import { ParameterizedContext } from "koa";
2
+ import { ExtendedFormidableOptions } from "koa-body";
3
3
  export type KoaCtx = ParameterizedContext<any, any, any>;
4
4
  export declare enum HttpMethod {
5
5
  GET = "GET",
@@ -38,7 +38,7 @@ export declare class BaseController {
38
38
  };
39
39
  }
40
40
  export declare function Controller(prefix: string): (target: any) => void;
41
- export declare function AuthControl(name: string | string[] | null, mode?: 'AND' | 'OR'): (target: any, method?: string) => void;
41
+ export declare function AuthControl(name: string | string[] | null, mode?: "AND" | "OR"): (target: any, method?: string) => void;
42
42
  export declare const Get: (url: string) => (target: any, name: string) => void;
43
43
  export declare const Post: (url: string) => (target: any, name: string) => void;
44
44
  export declare const Delete: (url: string) => (target: any, name: string) => void;
@@ -59,10 +59,11 @@ export interface UseProps {
59
59
  useJwt?: UseJwtHandler;
60
60
  }
61
61
  export interface SyncUseValue {
62
- context: import('koa').DefaultContext;
62
+ context: import("koa").DefaultContext;
63
63
  port: number;
64
64
  prefix: string;
65
65
  whitelist: (string | RegExp)[];
66
+ authList: string[];
66
67
  ip: string;
67
68
  }
68
69
  export interface ASTCacheHandler {
@@ -85,11 +86,11 @@ export type UseJwtRes = {
85
86
  permissions?: string[];
86
87
  };
87
88
  export type HandlerStatusBody = {
88
- 'Content-Type'?: string;
89
+ "Content-Type"?: string;
89
90
  };
90
91
  export type UseJwtHandler = (_ctx: KoaCtx) => Promise<UseJwtRes | null>;
91
92
  export type AuthControlProps = {
92
93
  isPublic: boolean;
93
- mode?: 'AND' | 'OR';
94
+ mode?: "AND" | "OR";
94
95
  name?: string | string[];
95
96
  };