@rdyl/node-koa-controller 0.6.0 → 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 +1 -1
- package/dist/cache.js +1 -0
- package/dist/index.js +1 -0
- package/dist/meta.js +16 -14
- package/package.json +1 -1
- package/types/cache.d.ts +1 -0
- package/types/meta.d.ts +7 -6
package/CHANGELOG.md
CHANGED
package/dist/cache.js
CHANGED
package/dist/index.js
CHANGED
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 ===
|
|
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 ===
|
|
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(
|
|
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(
|
|
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:
|
|
159
|
+
sendJson({ data: data, code: 200, msg: "ok" });
|
|
160
160
|
},
|
|
161
161
|
okCreated: function (data, msg) {
|
|
162
|
-
if (msg === void 0) { msg =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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/package.json
CHANGED
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
|
|
2
|
-
import { ExtendedFormidableOptions } from
|
|
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?:
|
|
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(
|
|
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
|
-
|
|
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?:
|
|
94
|
+
mode?: "AND" | "OR";
|
|
94
95
|
name?: string | string[];
|
|
95
96
|
};
|