kauth-sdk-node 2.0.10 → 2.0.12-alpha.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/authenticator/authenticator.d.ts +3 -3
- package/dist/authenticator/authenticator.js +6 -3
- package/dist/common/config/config.d.ts +2 -0
- package/dist/common/constant/http.d.ts +5 -0
- package/dist/common/constant/http.js +6 -1
- package/dist/common/http/kauth.d.ts +7 -2
- package/dist/common/http/kauth.js +15 -0
- package/dist/common/http/kflow.d.ts +4 -0
- package/dist/common/http/kflow.js +12 -0
- package/dist/common/http/request/kauth.d.ts +28 -0
- package/dist/common/http/request/kflow.d.ts +1 -0
- package/dist/common/http/response/kauth.d.ts +72 -0
- package/dist/common/http/response/kauth.js +15 -1
- package/dist/common/http/tool/marmot.d.ts +3 -0
- package/dist/common/http/tool/marmot.js +19 -0
- package/package.json +5 -4
|
@@ -8,21 +8,21 @@ interface Authenticator {
|
|
|
8
8
|
export declare class GoogleAuthenticator implements Authenticator {
|
|
9
9
|
private kauthApi;
|
|
10
10
|
constructor(kauthApi: KauthApi);
|
|
11
|
-
authenticate(token: string, redirectUri: string): Promise<AuthenticationInformation>;
|
|
11
|
+
authenticate(token: string, redirectUri: string, preAuthorizationToken?: string): Promise<AuthenticationInformation>;
|
|
12
12
|
bind(userId: number, token: string, redirectUri: string): Promise<void>;
|
|
13
13
|
authorizeURL(callback: string, state: string, prompt?: string): Promise<string>;
|
|
14
14
|
}
|
|
15
15
|
export declare class MoziAuthenticator implements Authenticator {
|
|
16
16
|
private kauthApi;
|
|
17
17
|
constructor(kauthApi: KauthApi);
|
|
18
|
-
authenticate(token: string, redirectUri: string): Promise<AuthenticationInformation>;
|
|
18
|
+
authenticate(token: string, redirectUri: string, preAuthorizationToken?: string): Promise<AuthenticationInformation>;
|
|
19
19
|
bind(userId: number, token: string, redirectUri: string): Promise<void>;
|
|
20
20
|
authorizeURL(callback: string, state: string, prompt?: string): Promise<string>;
|
|
21
21
|
}
|
|
22
22
|
export declare class MiniprogramAuthenticator implements Authenticator {
|
|
23
23
|
private kauthApi;
|
|
24
24
|
constructor(kauthApi: KauthApi);
|
|
25
|
-
authenticate(token: string, redirectUri: string): Promise<AuthenticationInformation>;
|
|
25
|
+
authenticate(token: string, redirectUri: string, preAuthorizationToken?: string): Promise<AuthenticationInformation>;
|
|
26
26
|
bind(userId: number, token: string, redirectUri: string): Promise<void>;
|
|
27
27
|
authorizeURL(callback: string, state: string, prompt?: string): Promise<string>;
|
|
28
28
|
}
|
|
@@ -8,10 +8,11 @@ class GoogleAuthenticator {
|
|
|
8
8
|
constructor(kauthApi) {
|
|
9
9
|
this.kauthApi = kauthApi;
|
|
10
10
|
}
|
|
11
|
-
async authenticate(token, redirectUri) {
|
|
11
|
+
async authenticate(token, redirectUri, preAuthorizationToken) {
|
|
12
12
|
const request = {
|
|
13
13
|
code: token,
|
|
14
14
|
redirect_uri: redirectUri,
|
|
15
|
+
pre_authorization_token: preAuthorizationToken,
|
|
15
16
|
};
|
|
16
17
|
const result = await this.kauthApi.googleAuthenticate(request);
|
|
17
18
|
const authenticationInformation = new google_1.GoogleAuthenticationInformation();
|
|
@@ -36,10 +37,11 @@ class MoziAuthenticator {
|
|
|
36
37
|
constructor(kauthApi) {
|
|
37
38
|
this.kauthApi = kauthApi;
|
|
38
39
|
}
|
|
39
|
-
async authenticate(token, redirectUri) {
|
|
40
|
+
async authenticate(token, redirectUri, preAuthorizationToken) {
|
|
40
41
|
const request = {
|
|
41
42
|
code: token,
|
|
42
43
|
redirect_uri: redirectUri,
|
|
44
|
+
pre_authorization_token: preAuthorizationToken,
|
|
43
45
|
};
|
|
44
46
|
const result = await this.kauthApi.moziAuthenticate(request);
|
|
45
47
|
const authenticationInformation = new mozi_1.MoziAuthenticationInformation();
|
|
@@ -64,10 +66,11 @@ class MiniprogramAuthenticator {
|
|
|
64
66
|
constructor(kauthApi) {
|
|
65
67
|
this.kauthApi = kauthApi;
|
|
66
68
|
}
|
|
67
|
-
async authenticate(token, redirectUri) {
|
|
69
|
+
async authenticate(token, redirectUri, preAuthorizationToken) {
|
|
68
70
|
const request = {
|
|
69
71
|
code: token,
|
|
70
72
|
redirect_uri: redirectUri,
|
|
73
|
+
pre_authorization_token: preAuthorizationToken,
|
|
71
74
|
};
|
|
72
75
|
const result = await this.kauthApi.miniprogramAuthenticate(request);
|
|
73
76
|
const authenticationInformation = new miniprogram_1.MiniprogramAuthenticationInformation();
|
|
@@ -37,6 +37,11 @@ export declare const BindUserByRolesAndExtendValueUri = "/api/backend/bindUserBy
|
|
|
37
37
|
export declare const BindUsersByRoleNameAndExtendValueUri = "/api/backend/bindUsersByRoleNameAndExtendValue";
|
|
38
38
|
export declare const BindRoleByPermissionsUri = "/api/backend/bindRoleByPermissions";
|
|
39
39
|
export declare const BindRoleWithUsersUri = "/api/backend/bindRoleWithUsers";
|
|
40
|
+
export declare const CreatePreAuthorizationUri = "/api/backend/createPreAuthorization";
|
|
41
|
+
export declare const GetPreAuthorizationUri = "/api/backend/getPreAuthorization";
|
|
42
|
+
export declare const RefreshPreAuthorizationUri = "/api/backend/refreshPreAuthorization";
|
|
43
|
+
export declare const ProcessPreAuthorizationUri = "/api/backend/processPreAuthorization";
|
|
44
|
+
export declare const CommitPreAuthorizationUri = "/api/backend/commitPreAuthorization";
|
|
40
45
|
export declare const ProcessUri = "/api/kflow/process";
|
|
41
46
|
export declare const ServiceTaskUri = "/api/kflow/serviceTask";
|
|
42
47
|
export declare const InstanceUri = "/api/kflow/stateMachine/instance/";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CompleteGraphServiceTaskUri = exports.GetGraphStateMachineSnapshotUri = exports.StartGraphProcessUri = exports.GetProcinstUserUri = exports.InstanceUri = exports.ServiceTaskUri = exports.ProcessUri = exports.BindRoleWithUsersUri = exports.BindRoleByPermissionsUri = exports.BindUsersByRoleNameAndExtendValueUri = exports.BindUserByRolesAndExtendValueUri = exports.BindUserByRoleNamesAndExtendValueUri = exports.BindUserByRolesUri = exports.CreatePermissionUri = exports.ListPermissionsByUserIdUri = exports.ListPermissionsUri = exports.UpdateRolesWithPermissionsUri = exports.CreateRolesByUsersAndPermissionsUri = exports.CreateRoleUri = exports.ListRolesByNamesAndExtendValueUri = exports.ListRolesByUserIdUri = exports.ListRolesByExtendValueUri = exports.ListRolesUri = exports.GetRoleWithUsersUri = exports.ListUsersByPermissionNameAndExtendValueUri = exports.ListUsersByPermissionIdUri = exports.ListUsersByRoleNameAndExtendValueUri = exports.ListUsersByRoleIdUri = exports.ListUsersWithUserAccountsAndRolesByRoleExtendValueUri = exports.ListUsersWithUserAccountsAndRolesUri = exports.ListUsersUri = exports.SearchUsersWithUserAccountsAndRolesUri = exports.GetUserByIdUri = exports.UnbindUri = exports.MiniprogramAuthenticationInformationUri = exports.MiniprogramBindUri = exports.MiniprogramAuthenticateUri = exports.MiniprogramAuthorizeUri = exports.GoogleAuthenticationInformationUri = exports.GoogleBindUri = exports.GoogleAuthenticateUri = exports.GoogleAuthorizeUri = exports.MoziAuthenticationInformationUri = exports.MoziBindUri = exports.MoziAuthenticateUri = exports.MoziAuthorizeUri = void 0;
|
|
3
|
+
exports.CompleteGraphServiceTaskUri = exports.GetGraphStateMachineSnapshotUri = exports.StartGraphProcessUri = exports.GetProcinstUserUri = exports.InstanceUri = exports.ServiceTaskUri = exports.ProcessUri = exports.CommitPreAuthorizationUri = exports.ProcessPreAuthorizationUri = exports.RefreshPreAuthorizationUri = exports.GetPreAuthorizationUri = exports.CreatePreAuthorizationUri = exports.BindRoleWithUsersUri = exports.BindRoleByPermissionsUri = exports.BindUsersByRoleNameAndExtendValueUri = exports.BindUserByRolesAndExtendValueUri = exports.BindUserByRoleNamesAndExtendValueUri = exports.BindUserByRolesUri = exports.CreatePermissionUri = exports.ListPermissionsByUserIdUri = exports.ListPermissionsUri = exports.UpdateRolesWithPermissionsUri = exports.CreateRolesByUsersAndPermissionsUri = exports.CreateRoleUri = exports.ListRolesByNamesAndExtendValueUri = exports.ListRolesByUserIdUri = exports.ListRolesByExtendValueUri = exports.ListRolesUri = exports.GetRoleWithUsersUri = exports.ListUsersByPermissionNameAndExtendValueUri = exports.ListUsersByPermissionIdUri = exports.ListUsersByRoleNameAndExtendValueUri = exports.ListUsersByRoleIdUri = exports.ListUsersWithUserAccountsAndRolesByRoleExtendValueUri = exports.ListUsersWithUserAccountsAndRolesUri = exports.ListUsersUri = exports.SearchUsersWithUserAccountsAndRolesUri = exports.GetUserByIdUri = exports.UnbindUri = exports.MiniprogramAuthenticationInformationUri = exports.MiniprogramBindUri = exports.MiniprogramAuthenticateUri = exports.MiniprogramAuthorizeUri = exports.GoogleAuthenticationInformationUri = exports.GoogleBindUri = exports.GoogleAuthenticateUri = exports.GoogleAuthorizeUri = exports.MoziAuthenticationInformationUri = exports.MoziBindUri = exports.MoziAuthenticateUri = exports.MoziAuthorizeUri = void 0;
|
|
4
4
|
// kauth
|
|
5
5
|
exports.MoziAuthorizeUri = '/api/authenticator/mozi/authorizeUrl';
|
|
6
6
|
exports.MoziAuthenticateUri = '/api/authenticator/mozi/authenticate';
|
|
@@ -41,6 +41,11 @@ exports.BindUserByRolesAndExtendValueUri = '/api/backend/bindUserByRolesAndExten
|
|
|
41
41
|
exports.BindUsersByRoleNameAndExtendValueUri = '/api/backend/bindUsersByRoleNameAndExtendValue';
|
|
42
42
|
exports.BindRoleByPermissionsUri = '/api/backend/bindRoleByPermissions';
|
|
43
43
|
exports.BindRoleWithUsersUri = '/api/backend/bindRoleWithUsers';
|
|
44
|
+
exports.CreatePreAuthorizationUri = '/api/backend/createPreAuthorization';
|
|
45
|
+
exports.GetPreAuthorizationUri = '/api/backend/getPreAuthorization';
|
|
46
|
+
exports.RefreshPreAuthorizationUri = '/api/backend/refreshPreAuthorization';
|
|
47
|
+
exports.ProcessPreAuthorizationUri = '/api/backend/processPreAuthorization';
|
|
48
|
+
exports.CommitPreAuthorizationUri = '/api/backend/commitPreAuthorization';
|
|
44
49
|
// kflow
|
|
45
50
|
exports.ProcessUri = '/api/kflow/process';
|
|
46
51
|
exports.ServiceTaskUri = '/api/kflow/serviceTask';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { KauthConfig } from '../config/config';
|
|
2
|
-
import { KauthAuthenticateRequest, KauthCreatePermissionRequest, KauthCreateRoleRequest, KauthCreateRolesByPermissionsAndUsersRequest, KauthBindUsersByRoleNameAndExtendValueRequest, KauthBindRequest, KauthBindRoleByPermissionsRequest, KauthBindUserByRolesRequest, KauthBindUserByRolesAndExtendValueRequest, KauthUpdateRolesWithPermissionsRequest, KauthBindRoleWithUsersRequest, KauthBindUserByRoleNamesAndExtendValueRequest, KauthSearchUsersWithUserAccountsAndRoleRequest } from './request/kauth';
|
|
3
|
-
import { KauthMoziAuthenticationInformation, KauthGoogleAuthenticationInformation, KauthPermission, KauthMiniprogramAuthenticationInformation, KauthRole, KauthUser, KauthPagable } from './response/kauth';
|
|
2
|
+
import { KauthAuthenticateRequest, KauthCreatePermissionRequest, KauthCreateRoleRequest, KauthCreateRolesByPermissionsAndUsersRequest, KauthBindUsersByRoleNameAndExtendValueRequest, KauthBindRequest, KauthBindRoleByPermissionsRequest, KauthBindUserByRolesRequest, KauthBindUserByRolesAndExtendValueRequest, KauthUpdateRolesWithPermissionsRequest, KauthBindRoleWithUsersRequest, KauthBindUserByRoleNamesAndExtendValueRequest, KauthSearchUsersWithUserAccountsAndRoleRequest, KauthCreatePreAuthorizationRequest, GetPreAuthorizationRequest, RefreshPreAuthorizatioRequest, ProcessPreAuthorizatioRequest } from './request/kauth';
|
|
3
|
+
import { KauthMoziAuthenticationInformation, KauthGoogleAuthenticationInformation, KauthPermission, KauthMiniprogramAuthenticationInformation, KauthRole, KauthUser, KauthPagable, PreAuthorizationAllowed } from './response/kauth';
|
|
4
4
|
export declare class KauthApi {
|
|
5
5
|
private marmotUtil;
|
|
6
6
|
private cache;
|
|
@@ -51,4 +51,9 @@ export declare class KauthApi {
|
|
|
51
51
|
bindUsersByRoleNameAndExtendValue(data: KauthBindUsersByRoleNameAndExtendValueRequest): Promise<void>;
|
|
52
52
|
bindRoleByPermissions(data: KauthBindRoleByPermissionsRequest): Promise<void>;
|
|
53
53
|
bindRoleWithUsers(data: KauthBindRoleWithUsersRequest): Promise<void>;
|
|
54
|
+
createPreAuthorization(data: KauthCreatePreAuthorizationRequest): Promise<void>;
|
|
55
|
+
getPreAuthorization(data: GetPreAuthorizationRequest): Promise<any>;
|
|
56
|
+
refreshPreAuthorization(data: RefreshPreAuthorizatioRequest): Promise<any>;
|
|
57
|
+
processPreAuthorization(data: ProcessPreAuthorizatioRequest): Promise<PreAuthorizationAllowed>;
|
|
58
|
+
commitPreAuthorization(data: ProcessPreAuthorizatioRequest): Promise<PreAuthorizationAllowed>;
|
|
54
59
|
}
|
|
@@ -185,5 +185,20 @@ class KauthApi {
|
|
|
185
185
|
this.cache.del(user.id);
|
|
186
186
|
});
|
|
187
187
|
}
|
|
188
|
+
async createPreAuthorization(data) {
|
|
189
|
+
return this.marmotUtil.post(http_1.CreatePreAuthorizationUri, data);
|
|
190
|
+
}
|
|
191
|
+
async getPreAuthorization(data) {
|
|
192
|
+
return this.marmotUtil.get(http_1.GetPreAuthorizationUri, data);
|
|
193
|
+
}
|
|
194
|
+
async refreshPreAuthorization(data) {
|
|
195
|
+
return this.marmotUtil.post(http_1.RefreshPreAuthorizationUri, data);
|
|
196
|
+
}
|
|
197
|
+
async processPreAuthorization(data) {
|
|
198
|
+
return this.marmotUtil.post(http_1.ProcessPreAuthorizationUri, data);
|
|
199
|
+
}
|
|
200
|
+
async commitPreAuthorization(data) {
|
|
201
|
+
return this.marmotUtil.post(http_1.CommitPreAuthorizationUri, data);
|
|
202
|
+
}
|
|
188
203
|
}
|
|
189
204
|
exports.KauthApi = KauthApi;
|
|
@@ -4,6 +4,10 @@ import { KflowStateMachineAndNodes } from './response/kflow';
|
|
|
4
4
|
export declare class KflowApi {
|
|
5
5
|
private marmotUtil;
|
|
6
6
|
constructor({ kflowOrigin, marmotTenantId, marmotAccessKeyId, marmotAccessKeySecret, kflowServiceName, kflowServicePort, }: KauthConfig);
|
|
7
|
+
setTraceId(traceId: string): void;
|
|
8
|
+
setSpanId(spanId: string): void;
|
|
9
|
+
setUserId(userId: string): void;
|
|
10
|
+
setTraceConsumers(consumers: Record<string, string> | ((val: Record<string, string>) => Record<string, string>)): void;
|
|
7
11
|
startProcessInstanceByKey(body: KflowCreateProcessRequest): Promise<string>;
|
|
8
12
|
completeTaskService(userId: string | number, body: KflowCompleteTaskServiceRequest): Promise<void>;
|
|
9
13
|
deleteProcessInstance(userId: string | number, instanceId: string, reason: string): Promise<void>;
|
|
@@ -7,6 +7,18 @@ class KflowApi {
|
|
|
7
7
|
constructor({ kflowOrigin, marmotTenantId, marmotAccessKeyId, marmotAccessKeySecret, kflowServiceName, kflowServicePort, }) {
|
|
8
8
|
this.marmotUtil = new marmot_1.MarmotUtil(kflowOrigin, marmotTenantId, marmotAccessKeyId, marmotAccessKeySecret, kflowServiceName, kflowServicePort);
|
|
9
9
|
}
|
|
10
|
+
setTraceId(traceId) {
|
|
11
|
+
this.marmotUtil.setTraceId(traceId);
|
|
12
|
+
}
|
|
13
|
+
setSpanId(spanId) {
|
|
14
|
+
this.marmotUtil.setSpanId(spanId);
|
|
15
|
+
}
|
|
16
|
+
setUserId(userId) {
|
|
17
|
+
this.marmotUtil.setUserId(userId);
|
|
18
|
+
}
|
|
19
|
+
setTraceConsumers(consumers) {
|
|
20
|
+
this.marmotUtil.setTraceConsumers(consumers);
|
|
21
|
+
}
|
|
10
22
|
async startProcessInstanceByKey(body) {
|
|
11
23
|
return this.marmotUtil.post(http_1.ProcessUri, body);
|
|
12
24
|
}
|
|
@@ -95,3 +95,31 @@ export interface KauthSearchUsersWithUserAccountsAndRoleRequest extends MarmotOp
|
|
|
95
95
|
role_extend_value: typeof NotFilteredByAnyRoles | typeof FilteredByGlobalRoles | string;
|
|
96
96
|
pagination: Partial<MarmotPagination>;
|
|
97
97
|
}
|
|
98
|
+
export interface KauthCreatePreAuthorizationRequest extends MarmotOptions {
|
|
99
|
+
authorizerId: number;
|
|
100
|
+
roleType: string;
|
|
101
|
+
roleName: string;
|
|
102
|
+
roleExtendValue: string;
|
|
103
|
+
callback: string;
|
|
104
|
+
authorizeeTargets?: Array<{
|
|
105
|
+
type: 'mozi' | 'google' | 'miniprogram';
|
|
106
|
+
target: string;
|
|
107
|
+
}>;
|
|
108
|
+
expiredAt?: Date;
|
|
109
|
+
count?: number;
|
|
110
|
+
oldTimeUserAllowed?: boolean;
|
|
111
|
+
}
|
|
112
|
+
export interface RefreshPreAuthorizatioRequest extends MarmotOptions {
|
|
113
|
+
id: number;
|
|
114
|
+
}
|
|
115
|
+
export interface GetPreAuthorizationRequest extends MarmotOptions {
|
|
116
|
+
roleType: string;
|
|
117
|
+
roleName: string;
|
|
118
|
+
roleExtendValue?: string;
|
|
119
|
+
}
|
|
120
|
+
export interface ProcessPreAuthorizatioRequest extends MarmotOptions {
|
|
121
|
+
token: string;
|
|
122
|
+
userId: number;
|
|
123
|
+
type: 'mozi' | 'google' | 'miniprogram';
|
|
124
|
+
target: string;
|
|
125
|
+
}
|
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
import { PrimaryPrincipal } from '../../../authenticator/base';
|
|
2
2
|
import { MarmotPagination } from '../tool/marmot';
|
|
3
|
+
export declare enum UserAccountType {
|
|
4
|
+
Mozi = "mozi",
|
|
5
|
+
Google = "google",
|
|
6
|
+
Miniprogram = "miniprogram"
|
|
7
|
+
}
|
|
8
|
+
export declare enum PreAuthorizationIsAllowedErrorCode {
|
|
9
|
+
UserNotFound = "userNotFound",
|
|
10
|
+
UserNotInWhitelist = "userNotInWhitelist",
|
|
11
|
+
TokenExpired = "tokenExpired",
|
|
12
|
+
TokenNotExisted = "tokenNotExisted",
|
|
13
|
+
TokenUsedUp = "tokenUsedUp"
|
|
14
|
+
}
|
|
3
15
|
export declare enum KauthPrincipalStatus {
|
|
4
16
|
Normal = 0,
|
|
5
17
|
Locked = 1
|
|
@@ -26,10 +38,34 @@ export interface KauthMoziCredential {
|
|
|
26
38
|
expiresIn: number;
|
|
27
39
|
refreshToken: string;
|
|
28
40
|
}
|
|
41
|
+
export declare type KauthPreAuthorized = ({
|
|
42
|
+
allowed: true;
|
|
43
|
+
} & {
|
|
44
|
+
processed: boolean;
|
|
45
|
+
id: number;
|
|
46
|
+
userId: number;
|
|
47
|
+
type: UserAccountType;
|
|
48
|
+
target: string;
|
|
49
|
+
token: string;
|
|
50
|
+
roleType: 'kauth' | string;
|
|
51
|
+
roleName: string;
|
|
52
|
+
roleExtendValue: string;
|
|
53
|
+
resolvedAuthorizeeTargets: Array<{
|
|
54
|
+
type: UserAccountType;
|
|
55
|
+
target: string;
|
|
56
|
+
id: number;
|
|
57
|
+
}>;
|
|
58
|
+
}) | ({
|
|
59
|
+
allowed: false;
|
|
60
|
+
} & {
|
|
61
|
+
code: PreAuthorizationIsAllowedErrorCode;
|
|
62
|
+
reason: string;
|
|
63
|
+
});
|
|
29
64
|
export interface KauthMoziAuthenticationInformation {
|
|
30
65
|
primaryPrincipal: KauthPrimaryPrincipal;
|
|
31
66
|
principal: KauthMoziPrincipal;
|
|
32
67
|
credential: KauthMoziCredential;
|
|
68
|
+
preAuthorized?: KauthPreAuthorized;
|
|
33
69
|
}
|
|
34
70
|
export interface KauthGooglePrincipal {
|
|
35
71
|
sub: string;
|
|
@@ -89,3 +125,39 @@ export interface KauthPagable<T> {
|
|
|
89
125
|
data: T;
|
|
90
126
|
pagination: MarmotPagination;
|
|
91
127
|
}
|
|
128
|
+
export interface PreAuthorizationAllowed {
|
|
129
|
+
allowed: true;
|
|
130
|
+
processed: boolean;
|
|
131
|
+
id: number;
|
|
132
|
+
userId: number;
|
|
133
|
+
roleType: 'kauth' | string;
|
|
134
|
+
roleName: string;
|
|
135
|
+
roleExtendValue: string;
|
|
136
|
+
resolvedAuthorizeeTargets: Array<{
|
|
137
|
+
type: 'mozi' | 'google' | 'miniprogram';
|
|
138
|
+
id: number;
|
|
139
|
+
target: string;
|
|
140
|
+
}>;
|
|
141
|
+
}
|
|
142
|
+
export interface PreAuthorization {
|
|
143
|
+
id: number;
|
|
144
|
+
tenantId: string;
|
|
145
|
+
token: string;
|
|
146
|
+
authorizerId: number;
|
|
147
|
+
authorizeeTargets?: Array<{
|
|
148
|
+
type: 'mozi' | 'google' | 'miniprogram';
|
|
149
|
+
target: string;
|
|
150
|
+
}>;
|
|
151
|
+
resolvedAuthorizeeTargets: Array<{
|
|
152
|
+
type: 'mozi' | 'google' | 'miniprogram';
|
|
153
|
+
id: number;
|
|
154
|
+
target: string;
|
|
155
|
+
}>;
|
|
156
|
+
expiredAt?: Date;
|
|
157
|
+
count?: number;
|
|
158
|
+
oldTimeUserAllowed?: boolean;
|
|
159
|
+
roleType: 'kauth' | string;
|
|
160
|
+
roleName: string;
|
|
161
|
+
roleExtendValue?: string;
|
|
162
|
+
callback: string;
|
|
163
|
+
}
|
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.KauthPrincipalStatus = void 0;
|
|
3
|
+
exports.KauthPrincipalStatus = exports.PreAuthorizationIsAllowedErrorCode = exports.UserAccountType = void 0;
|
|
4
|
+
var UserAccountType;
|
|
5
|
+
(function (UserAccountType) {
|
|
6
|
+
UserAccountType["Mozi"] = "mozi";
|
|
7
|
+
UserAccountType["Google"] = "google";
|
|
8
|
+
UserAccountType["Miniprogram"] = "miniprogram";
|
|
9
|
+
})(UserAccountType = exports.UserAccountType || (exports.UserAccountType = {}));
|
|
10
|
+
var PreAuthorizationIsAllowedErrorCode;
|
|
11
|
+
(function (PreAuthorizationIsAllowedErrorCode) {
|
|
12
|
+
PreAuthorizationIsAllowedErrorCode["UserNotFound"] = "userNotFound";
|
|
13
|
+
PreAuthorizationIsAllowedErrorCode["UserNotInWhitelist"] = "userNotInWhitelist";
|
|
14
|
+
PreAuthorizationIsAllowedErrorCode["TokenExpired"] = "tokenExpired";
|
|
15
|
+
PreAuthorizationIsAllowedErrorCode["TokenNotExisted"] = "tokenNotExisted";
|
|
16
|
+
PreAuthorizationIsAllowedErrorCode["TokenUsedUp"] = "tokenUsedUp";
|
|
17
|
+
})(PreAuthorizationIsAllowedErrorCode = exports.PreAuthorizationIsAllowedErrorCode || (exports.PreAuthorizationIsAllowedErrorCode = {}));
|
|
4
18
|
var KauthPrincipalStatus;
|
|
5
19
|
(function (KauthPrincipalStatus) {
|
|
6
20
|
KauthPrincipalStatus[KauthPrincipalStatus["Normal"] = 0] = "Normal";
|
|
@@ -38,10 +38,12 @@ export declare class MarmotUtil {
|
|
|
38
38
|
private userId?;
|
|
39
39
|
private traceId?;
|
|
40
40
|
private spanId?;
|
|
41
|
+
private traceConsumers?;
|
|
41
42
|
constructor(origin: string, tenantId?: number, accessKeyId?: string, accessKeySecret?: string, serviceName?: string, servicePort?: string);
|
|
42
43
|
setUserId(userId: string): void;
|
|
43
44
|
setTraceId(traceId: string): void;
|
|
44
45
|
setSpanId(spanId: string): void;
|
|
46
|
+
setTraceConsumers(traceConsumers: Record<string, string> | ((val: Record<string, string>) => Record<string, string>)): void;
|
|
45
47
|
get<RequestType extends ParsedUrlQueryInput | MarmotOptions, ResponseType>(path: string, params?: RequestType): Promise<ResponseType>;
|
|
46
48
|
post<RequestType extends MarmotOptions, ResponseType>(path: string, params?: RequestType, config?: AxiosRequestConfig): Promise<ResponseType>;
|
|
47
49
|
del<RequestType extends MarmotOptions | ParsedUrlQueryInput, ResponseType>(path: string, params?: RequestType): Promise<ResponseType>;
|
|
@@ -49,5 +51,6 @@ export declare class MarmotUtil {
|
|
|
49
51
|
resolveHeaders(method: string, uri: string): Record<string, string | number>;
|
|
50
52
|
sign(method: string, path: string, accessKeySecret?: string): string;
|
|
51
53
|
format<T>(response: AxiosResponse<BasicReponse<any>>): Promise<T>;
|
|
54
|
+
private formatTraceConsumers;
|
|
52
55
|
}
|
|
53
56
|
export {};
|
|
@@ -36,6 +36,14 @@ class MarmotUtil {
|
|
|
36
36
|
setSpanId(spanId) {
|
|
37
37
|
this.spanId = spanId;
|
|
38
38
|
}
|
|
39
|
+
setTraceConsumers(traceConsumers) {
|
|
40
|
+
if (typeof traceConsumers === 'function') {
|
|
41
|
+
this.traceConsumers = traceConsumers(this.traceConsumers || {});
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
this.traceConsumers = traceConsumers;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
39
47
|
async get(path, params) {
|
|
40
48
|
// 兼容老的写法
|
|
41
49
|
if (params && params.userId) {
|
|
@@ -91,6 +99,9 @@ class MarmotUtil {
|
|
|
91
99
|
if (this.spanId) {
|
|
92
100
|
headers['tracelog-spanid'] = this.spanId;
|
|
93
101
|
}
|
|
102
|
+
if (this.traceConsumers) {
|
|
103
|
+
headers['x-kauth-trace-consumers'] = this.formatTraceConsumers(this.traceConsumers);
|
|
104
|
+
}
|
|
94
105
|
if (!this.proxyMatched) {
|
|
95
106
|
// 如果直连转发,需要传入 x-gw-tenant-id
|
|
96
107
|
if (this.tenantId) {
|
|
@@ -121,5 +132,13 @@ class MarmotUtil {
|
|
|
121
132
|
deep: true,
|
|
122
133
|
});
|
|
123
134
|
}
|
|
135
|
+
formatTraceConsumers(traceConsumers) {
|
|
136
|
+
return Object.keys(traceConsumers)
|
|
137
|
+
.map((k) => {
|
|
138
|
+
const v = this.traceConsumers[k];
|
|
139
|
+
return `${k}:${v}`;
|
|
140
|
+
})
|
|
141
|
+
.join(',');
|
|
142
|
+
}
|
|
124
143
|
}
|
|
125
144
|
exports.MarmotUtil = MarmotUtil;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kauth-sdk-node",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.12-alpha.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"files": [
|
|
@@ -13,9 +13,8 @@
|
|
|
13
13
|
"watch": "tsc -w",
|
|
14
14
|
"type-check": "tsc --noEmit",
|
|
15
15
|
"lint": "npm run type-check && eslint . --fix --ext .ts",
|
|
16
|
-
"test": "mocha --recursive --require ts-node/register 'test/**/*.ts'",
|
|
17
|
-
"
|
|
18
|
-
"ci": "npm run lint && npm run coverage",
|
|
16
|
+
"test": "multi='spec=- mocha-junit-reporter=-' mocha --reporter=mocha-multi --recursive --require ts-node/register 'test/**/*.ts'",
|
|
17
|
+
"ci": "nyc -t coverage --reporter=cobertura npm run test",
|
|
19
18
|
"version": "conventional-changelog -p angular -i CHANGELOG.md -s && git add .",
|
|
20
19
|
"prepublishOnly": "rm -rf dist && npm run build"
|
|
21
20
|
},
|
|
@@ -42,6 +41,8 @@
|
|
|
42
41
|
"eslint-plugin-prettier": "^3.3.1",
|
|
43
42
|
"lint-staged": "^10.5.3",
|
|
44
43
|
"mocha": "^8.0.1",
|
|
44
|
+
"mocha-junit-reporter": "^2.0.2",
|
|
45
|
+
"mocha-multi": "^1.1.6",
|
|
45
46
|
"nyc": "^15.1.0",
|
|
46
47
|
"prettier": "^2.2.1",
|
|
47
48
|
"sinon": "^9.0.2",
|