@quanticjs/workflow-quanticflow 4.2.0 → 4.3.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.
@@ -0,0 +1,9 @@
1
+ import type { QuanticFlowWorkflowModuleOptions } from './options';
2
+ export declare class KeycloakTokenService {
3
+ private readonly options;
4
+ private readonly logger;
5
+ private accessToken;
6
+ private expiresAt;
7
+ constructor(options: QuanticFlowWorkflowModuleOptions);
8
+ getAccessToken(): Promise<string | null>;
9
+ }
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ var KeycloakTokenService_1;
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.KeycloakTokenService = void 0;
17
+ const common_1 = require("@nestjs/common");
18
+ const options_1 = require("./options");
19
+ let KeycloakTokenService = KeycloakTokenService_1 = class KeycloakTokenService {
20
+ options;
21
+ logger = new common_1.Logger(KeycloakTokenService_1.name);
22
+ accessToken = null;
23
+ expiresAt = 0;
24
+ constructor(options) {
25
+ this.options = options;
26
+ }
27
+ async getAccessToken() {
28
+ const auth = this.options.auth;
29
+ if (!auth)
30
+ return null;
31
+ if (this.accessToken && Date.now() < this.expiresAt - 30_000) {
32
+ return this.accessToken;
33
+ }
34
+ const tokenUrl = `${auth.keycloakInternalUrl ?? auth.keycloakUrl}/realms/${auth.realm}/protocol/openid-connect/token`;
35
+ const body = new URLSearchParams({
36
+ grant_type: 'client_credentials',
37
+ client_id: auth.clientId,
38
+ client_secret: auth.clientSecret,
39
+ });
40
+ const res = await fetch(tokenUrl, {
41
+ method: 'POST',
42
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
43
+ body: body.toString(),
44
+ });
45
+ if (!res.ok) {
46
+ const text = await res.text();
47
+ this.logger.error(`Keycloak token request failed: ${res.status} ${text.substring(0, 200)}`);
48
+ throw new Error(`Keycloak client credentials grant failed: ${res.status}`);
49
+ }
50
+ const data = (await res.json());
51
+ this.accessToken = data.access_token;
52
+ this.expiresAt = Date.now() + data.expires_in * 1000;
53
+ this.logger.log('Obtained service-account token from Keycloak');
54
+ return this.accessToken;
55
+ }
56
+ };
57
+ exports.KeycloakTokenService = KeycloakTokenService;
58
+ exports.KeycloakTokenService = KeycloakTokenService = KeycloakTokenService_1 = __decorate([
59
+ (0, common_1.Injectable)(),
60
+ __param(0, (0, common_1.Inject)(options_1.QUANTICFLOW_OPTIONS)),
61
+ __metadata("design:paramtypes", [Object])
62
+ ], KeycloakTokenService);
@@ -1,22 +1,14 @@
1
- import { DynamicModule } from '@nestjs/common';
2
- import { ServiceTaskHandler } from './ServiceTaskHandlerRegistry';
3
- export declare const QUANTICFLOW_OPTIONS: unique symbol;
4
- export interface ServiceTaskHandlingOptions {
5
- mode: 'callback' | 'event' | 'both';
6
- callbackSecret?: string;
7
- streamKey?: string;
8
- consumerGroup?: string;
9
- consumerName?: string;
10
- }
11
- export interface QuanticFlowWorkflowModuleOptions {
12
- url: string;
13
- requestTimeout?: number;
14
- serviceTaskHandling?: ServiceTaskHandlingOptions;
15
- handlers?: Array<{
16
- name: string;
17
- useClass: new (...args: unknown[]) => ServiceTaskHandler;
18
- }>;
19
- }
20
- export declare class QuanticFlowWorkflowModule {
1
+ import { DynamicModule, OnModuleInit } from '@nestjs/common';
2
+ import { HttpService } from '@nestjs/axios';
3
+ import { KeycloakTokenService } from './KeycloakTokenService';
4
+ import { QUANTICFLOW_OPTIONS, type QuanticFlowWorkflowModuleOptions } from './options';
5
+ export { QUANTICFLOW_OPTIONS };
6
+ export type { QuanticFlowWorkflowModuleOptions, QuanticFlowAuthOptions, ServiceTaskHandlingOptions, } from './options';
7
+ export declare class QuanticFlowWorkflowModule implements OnModuleInit {
8
+ private readonly options;
9
+ private readonly httpService;
10
+ private readonly tokenService;
11
+ constructor(options: QuanticFlowWorkflowModuleOptions, httpService: HttpService, tokenService: KeycloakTokenService);
12
+ onModuleInit(): void;
21
13
  static forRoot(options: QuanticFlowWorkflowModuleOptions): DynamicModule;
22
14
  }
@@ -5,6 +5,12 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
5
5
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
6
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7
7
  };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
8
14
  var QuanticFlowWorkflowModule_1;
9
15
  Object.defineProperty(exports, "__esModule", { value: true });
10
16
  exports.QuanticFlowWorkflowModule = exports.QUANTICFLOW_OPTIONS = void 0;
@@ -16,17 +22,39 @@ const QuanticFlowWorkflowEngine_1 = require("./QuanticFlowWorkflowEngine");
16
22
  const QuanticFlowCallbackController_1 = require("./QuanticFlowCallbackController");
17
23
  const ServiceTaskEventConsumer_1 = require("./ServiceTaskEventConsumer");
18
24
  const ServiceTaskHandlerRegistry_1 = require("./ServiceTaskHandlerRegistry");
19
- exports.QUANTICFLOW_OPTIONS = Symbol('QUANTICFLOW_OPTIONS');
25
+ const KeycloakTokenService_1 = require("./KeycloakTokenService");
26
+ const options_1 = require("./options");
27
+ Object.defineProperty(exports, "QUANTICFLOW_OPTIONS", { enumerable: true, get: function () { return options_1.QUANTICFLOW_OPTIONS; } });
20
28
  let QuanticFlowWorkflowModule = QuanticFlowWorkflowModule_1 = class QuanticFlowWorkflowModule {
29
+ options;
30
+ httpService;
31
+ tokenService;
32
+ constructor(options, httpService, tokenService) {
33
+ this.options = options;
34
+ this.httpService = httpService;
35
+ this.tokenService = tokenService;
36
+ }
37
+ onModuleInit() {
38
+ if (!this.options.auth)
39
+ return;
40
+ this.httpService.axiosRef.interceptors.request.use(async (config) => {
41
+ const token = await this.tokenService.getAccessToken();
42
+ if (token) {
43
+ config.headers.Authorization = `Bearer ${token}`;
44
+ }
45
+ return config;
46
+ });
47
+ }
21
48
  static forRoot(options) {
22
49
  const mode = options.serviceTaskHandling?.mode ?? 'callback';
23
50
  const enableCallback = mode === 'callback' || mode === 'both';
24
51
  const enableEvents = mode === 'event' || mode === 'both';
25
52
  const providers = [
26
53
  {
27
- provide: exports.QUANTICFLOW_OPTIONS,
54
+ provide: options_1.QUANTICFLOW_OPTIONS,
28
55
  useValue: options,
29
56
  },
57
+ KeycloakTokenService_1.KeycloakTokenService,
30
58
  QuanticFlowClient_1.QuanticFlowClient,
31
59
  {
32
60
  provide: core_1.WORKFLOW_ENGINE,
@@ -78,5 +106,8 @@ let QuanticFlowWorkflowModule = QuanticFlowWorkflowModule_1 = class QuanticFlowW
78
106
  exports.QuanticFlowWorkflowModule = QuanticFlowWorkflowModule;
79
107
  exports.QuanticFlowWorkflowModule = QuanticFlowWorkflowModule = QuanticFlowWorkflowModule_1 = __decorate([
80
108
  (0, common_1.Global)(),
81
- (0, common_1.Module)({})
109
+ (0, common_1.Module)({}),
110
+ __param(0, (0, common_1.Inject)(options_1.QUANTICFLOW_OPTIONS)),
111
+ __metadata("design:paramtypes", [Object, axios_1.HttpService,
112
+ KeycloakTokenService_1.KeycloakTokenService])
82
113
  ], QuanticFlowWorkflowModule);
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { QuanticFlowWorkflowModule, QUANTICFLOW_OPTIONS } from './QuanticFlowWorkflowModule';
2
- export type { QuanticFlowWorkflowModuleOptions, ServiceTaskHandlingOptions, } from './QuanticFlowWorkflowModule';
2
+ export type { QuanticFlowWorkflowModuleOptions, QuanticFlowAuthOptions, ServiceTaskHandlingOptions, } from './QuanticFlowWorkflowModule';
3
+ export { KeycloakTokenService } from './KeycloakTokenService';
3
4
  export { QuanticFlowClient } from './QuanticFlowClient';
4
5
  export type { QuanticFlowInstance, QuanticFlowTask, PaginatedResult, } from './QuanticFlowClient';
5
6
  export { QuanticFlowWorkflowEngine } from './QuanticFlowWorkflowEngine';
package/dist/index.js CHANGED
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SERVICE_TASK_HANDLERS = exports.ServiceTaskHandlerRegistry = exports.ServiceTaskEventConsumer = exports.QuanticFlowCallbackController = exports.QuanticFlowWorkflowEngine = exports.QuanticFlowClient = exports.QUANTICFLOW_OPTIONS = exports.QuanticFlowWorkflowModule = void 0;
3
+ exports.SERVICE_TASK_HANDLERS = exports.ServiceTaskHandlerRegistry = exports.ServiceTaskEventConsumer = exports.QuanticFlowCallbackController = exports.QuanticFlowWorkflowEngine = exports.QuanticFlowClient = exports.KeycloakTokenService = exports.QUANTICFLOW_OPTIONS = exports.QuanticFlowWorkflowModule = void 0;
4
4
  var QuanticFlowWorkflowModule_1 = require("./QuanticFlowWorkflowModule");
5
5
  Object.defineProperty(exports, "QuanticFlowWorkflowModule", { enumerable: true, get: function () { return QuanticFlowWorkflowModule_1.QuanticFlowWorkflowModule; } });
6
6
  Object.defineProperty(exports, "QUANTICFLOW_OPTIONS", { enumerable: true, get: function () { return QuanticFlowWorkflowModule_1.QUANTICFLOW_OPTIONS; } });
7
+ var KeycloakTokenService_1 = require("./KeycloakTokenService");
8
+ Object.defineProperty(exports, "KeycloakTokenService", { enumerable: true, get: function () { return KeycloakTokenService_1.KeycloakTokenService; } });
7
9
  var QuanticFlowClient_1 = require("./QuanticFlowClient");
8
10
  Object.defineProperty(exports, "QuanticFlowClient", { enumerable: true, get: function () { return QuanticFlowClient_1.QuanticFlowClient; } });
9
11
  var QuanticFlowWorkflowEngine_1 = require("./QuanticFlowWorkflowEngine");
@@ -0,0 +1,26 @@
1
+ import { ServiceTaskHandler } from './ServiceTaskHandlerRegistry';
2
+ export declare const QUANTICFLOW_OPTIONS: unique symbol;
3
+ export interface ServiceTaskHandlingOptions {
4
+ mode: 'callback' | 'event' | 'both';
5
+ callbackSecret?: string;
6
+ streamKey?: string;
7
+ consumerGroup?: string;
8
+ consumerName?: string;
9
+ }
10
+ export interface QuanticFlowAuthOptions {
11
+ keycloakUrl: string;
12
+ keycloakInternalUrl?: string;
13
+ realm: string;
14
+ clientId: string;
15
+ clientSecret: string;
16
+ }
17
+ export interface QuanticFlowWorkflowModuleOptions {
18
+ url: string;
19
+ requestTimeout?: number;
20
+ auth?: QuanticFlowAuthOptions;
21
+ serviceTaskHandling?: ServiceTaskHandlingOptions;
22
+ handlers?: Array<{
23
+ name: string;
24
+ useClass: new (...args: unknown[]) => ServiceTaskHandler;
25
+ }>;
26
+ }
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.QUANTICFLOW_OPTIONS = void 0;
4
+ exports.QUANTICFLOW_OPTIONS = Symbol('QUANTICFLOW_OPTIONS');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quanticjs/workflow-quanticflow",
3
- "version": "4.2.0",
3
+ "version": "4.3.1",
4
4
  "description": "QuanticFlow workflow engine adapter for @quanticjs/workflow — supports callback and event-driven service task execution",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -23,8 +23,8 @@
23
23
  "license": "MIT",
24
24
  "dependencies": {
25
25
  "@nestjs/axios": "^4.0.0",
26
- "@quanticjs/core": "^4.2.0",
27
- "@quanticjs/events": "^4.2.0",
26
+ "@quanticjs/core": "^4.3.1",
27
+ "@quanticjs/events": "^4.3.1",
28
28
  "axios": "^1.6.0"
29
29
  },
30
30
  "peerDependencies": {