kauth-sdk-node 2.0.8 → 2.0.11-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.
@@ -28,6 +28,8 @@ export interface KauthConfig {
28
28
  lruMax?: number;
29
29
  apiInjected?: boolean;
30
30
  tracerInjected?: boolean;
31
+ traceConsumerKey?: string;
32
+ traceConsumer?: string;
31
33
  marmotTenantId?: number;
32
34
  marmotAccessKeyId?: string;
33
35
  marmotAccessKeySecret?: string;
@@ -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
  }
@@ -1,10 +1,8 @@
1
1
  /// <reference types="node" />
2
2
  import { ParsedUrlQueryInput } from 'querystring';
3
3
  import { MarmotOptions, MarmotPagination } from '../tool/marmot';
4
- export declare enum RoleExtendValueType {
5
- NotFilteredByAnyRoles,
6
- FilteredByGlobalRoles
7
- }
4
+ export declare const NotFilteredByAnyRoles: any;
5
+ export declare const FilteredByGlobalRoles: any;
8
6
  export interface KauthAuthenticateRequest extends ParsedUrlQueryInput, MarmotOptions {
9
7
  code: string;
10
8
  redirect_uri: string;
@@ -94,6 +92,6 @@ export interface KauthBindRoleWithUsersRequest extends MarmotOptions {
94
92
  export interface KauthSearchUsersWithUserAccountsAndRoleRequest extends MarmotOptions {
95
93
  name?: string;
96
94
  role_name?: string;
97
- role_extend_value: RoleExtendValueType | string;
95
+ role_extend_value: typeof NotFilteredByAnyRoles | typeof FilteredByGlobalRoles | string;
98
96
  pagination: Partial<MarmotPagination>;
99
97
  }
@@ -1,8 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RoleExtendValueType = void 0;
4
- var RoleExtendValueType;
5
- (function (RoleExtendValueType) {
6
- RoleExtendValueType[RoleExtendValueType["NotFilteredByAnyRoles"] = undefined] = "NotFilteredByAnyRoles";
7
- RoleExtendValueType[RoleExtendValueType["FilteredByGlobalRoles"] = null] = "FilteredByGlobalRoles";
8
- })(RoleExtendValueType = exports.RoleExtendValueType || (exports.RoleExtendValueType = {}));
3
+ exports.FilteredByGlobalRoles = exports.NotFilteredByAnyRoles = void 0;
4
+ exports.NotFilteredByAnyRoles = undefined;
5
+ exports.FilteredByGlobalRoles = null;
@@ -3,6 +3,7 @@ export interface KflowCreateGraphProcessRequest extends MarmotOptions {
3
3
  key: string;
4
4
  map: any;
5
5
  features: any;
6
+ traceConsumers?: any;
6
7
  }
7
8
  export interface KflowCompleteGraphServiceTaskRequest extends MarmotOptions {
8
9
  taskId: string;
@@ -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) {
@@ -103,6 +114,7 @@ class MarmotUtil {
103
114
  headers['x-service-name'] = this.serviceName;
104
115
  headers['x-service-port'] = this.servicePort;
105
116
  headers.authorization = `Marmot ${this.accessKeyId}:${signature}`;
117
+ console.log('request headers', headers);
106
118
  return headers;
107
119
  }
108
120
  sign(method, path, accessKeySecret) {
@@ -121,5 +133,14 @@ class MarmotUtil {
121
133
  deep: true,
122
134
  });
123
135
  }
136
+ formatTraceConsumers(traceConsumers) {
137
+ return Object
138
+ .keys(traceConsumers)
139
+ .map((k) => {
140
+ const v = this.traceConsumers[k];
141
+ return `${k}:${v}`;
142
+ })
143
+ .join(',');
144
+ }
124
145
  }
125
146
  exports.MarmotUtil = MarmotUtil;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kauth-sdk-node",
3
- "version": "2.0.8",
3
+ "version": "2.0.11-alpha.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "files": [