@hsuite/smart-engines-sdk 3.0.0 → 3.0.2

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/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  // Generated by dts-bundle-generator v9.5.1
2
2
 
3
- import { DynamicModule, OnModuleDestroy, OnModuleInit, Type } from '@nestjs/common';
4
3
  import { z } from 'zod';
5
4
 
6
5
  export type CircuitState = "closed" | "open" | "half_open";
@@ -2757,77 +2756,7 @@ export declare class BaasError extends Error {
2757
2756
  readonly details?: BaasErrorDetails | undefined;
2758
2757
  constructor(message: string, statusCode: number, details?: BaasErrorDetails | undefined);
2759
2758
  }
2760
- export interface SmartEngineServiceConfig extends SmartEngineClientConfig {
2761
- testConnection?: boolean;
2762
- autoReconnect?: boolean;
2763
- reconnectInterval?: number;
2764
- maxReconnectAttempts?: number;
2765
- }
2766
- export declare const SMART_ENGINE_CONFIG = "SMART_ENGINE_CONFIG";
2767
- interface BaasClient$1 {
2768
- readonly client: SmartEngineClient;
2769
- isHealthy(): Promise<boolean>;
2770
- getBaseUrl(): string;
2771
- }
2772
- export declare class SmartEngineService implements OnModuleInit, OnModuleDestroy {
2773
- private readonly config?;
2774
- private readonly logger;
2775
- private client;
2776
- private baasClient;
2777
- private connected;
2778
- private reconnectTimer;
2779
- private reconnectAttempts;
2780
- constructor(config?: SmartEngineServiceConfig | undefined);
2781
- onModuleInit(): Promise<void>;
2782
- onModuleDestroy(): Promise<void>;
2783
- initialize(config: SmartEngineServiceConfig): Promise<void>;
2784
- shutdown(): Promise<void>;
2785
- getClient(): SmartEngineClient;
2786
- getBaasClient(): BaasClient$1;
2787
- isConnected(): boolean;
2788
- testConnection(): Promise<boolean>;
2789
- getStatus(): {
2790
- connected: boolean;
2791
- baseUrl: string | null;
2792
- authenticated: boolean;
2793
- reconnectAttempts: number;
2794
- };
2795
- createGatewayClient(config: {
2796
- baseUrl: string;
2797
- apiKey?: string;
2798
- authToken?: string;
2799
- timeout?: number;
2800
- allowInsecure?: boolean;
2801
- }): SmartGatewayClient;
2802
- createHostClient(config: {
2803
- hostUrl: string;
2804
- appId?: string;
2805
- timeout?: number;
2806
- allowInsecure?: boolean;
2807
- }): BaasClient;
2808
- private createBaasClient;
2809
- private scheduleReconnect;
2810
- }
2811
- export interface SmartEngineModuleAsyncOptions {
2812
- imports?: any[];
2813
- useFactory?: (...args: any[]) => Promise<SmartEngineServiceConfig> | SmartEngineServiceConfig;
2814
- inject?: any[];
2815
- useClass?: Type<SmartEngineOptionsFactory>;
2816
- useExisting?: Type<SmartEngineOptionsFactory>;
2817
- isGlobal?: boolean;
2818
- }
2819
- export interface SmartEngineOptionsFactory {
2820
- createSmartEngineOptions(): Promise<SmartEngineServiceConfig> | SmartEngineServiceConfig;
2821
- }
2822
- export declare class SmartEngineModule {
2823
- static forRoot(config: SmartEngineServiceConfig, isGlobal?: boolean): DynamicModule;
2824
- static forRootAsync(options: SmartEngineModuleAsyncOptions): DynamicModule;
2825
- private static createAsyncProviders;
2826
- }
2827
2759
 
2828
- declare namespace nestjs {
2829
- export { BaasClient$1 as BaasClient, SMART_ENGINE_CONFIG, SmartEngineModule, SmartEngineModuleAsyncOptions, SmartEngineOptionsFactory, SmartEngineService, SmartEngineServiceConfig };
2830
- }
2831
2760
  declare namespace bitcoin {
2832
2761
  export { btcToSatoshis, satoshisToBtc, validateBitcoinAddress };
2833
2762
  }
@@ -2846,6 +2775,9 @@ declare namespace solana {
2846
2775
  declare namespace stellar {
2847
2776
  export { stroopsToXlm, validateStellarAddress, xlmToStroops };
2848
2777
  }
2778
+ declare namespace baas {
2779
+ export { AgentBalance, AgentEvent, AgentFundRequest, AgentInfo, AgentOperation, AgentRegisterRequest, AgentRules, AgentRulesValidationResult, AgentStatus, AgentTradeRequest, AgentWithdrawRequest, AgentsClient, AuthenticateOptions, BaasAppListResponse, BaasAuthConfig, BaasAuthResult, BaasChallengeRequest, BaasChallengeResponse, BaasChannelConfig, BaasClient, BaasClientConfig, BaasDeleteResult, BaasDeployRequest, BaasDeployResult, BaasDocument, BaasEndpoints, BaasError, BaasErrorDetails, BaasErrorResponse, BaasFileInfo, BaasFileMetadata, BaasFindResult, BaasFunctionDeployRequest, BaasFunctionDeployResult, BaasFunctionInfo, BaasFunctionLog, BaasFunctionLogOptions, BaasFunctionResources, BaasFunctionResult, BaasFunctionRuntime, BaasHistoryOptions, BaasInsertResult, BaasMerkleProof, BaasMessage, BaasPresenceInfo, BaasPresenceMember, BaasPublishResult, BaasQueryOptions, BaasRegisterRequest, BaasRegisterResponse, BaasService, BaasSessionInfo, BaasStateTransition, BaasStorageUsage, BaasSupportedChain, BaasTriggerType, BaasUpdateResult, BaasUploadResult, BaasVerifyRequest, ChannelSubscription, DatabaseClient, DatabaseStatsResponse, DbComparisonOperator, DbDocument, DbQuery, DeployedApp, DeployedAppInfo, DeployedAppLimits, DeployedAppStatus, DeployedAppUsage, DeploymentClient, DocumentProofResponse, FunctionsClient, MessageHandler, MessagingClient, StateRootResponse, StateTransitionsResponse, StorageClient, validateAgentRules };
2780
+ }
2849
2781
  declare namespace discovery {
2850
2782
  export { MIRROR_NODE_URLS, MirrorNodeClient, MirrorNodeConfig, MirrorNodeError, TopicMessage, TopicMessagesResponse, ValidatorDiscoveryClient, ValidatorDiscoveryConfig, ValidatorInfo, ValidatorMetadata, ValidatorNetworkEndpoints };
2851
2783
  }
@@ -2861,19 +2793,14 @@ declare namespace subscription {
2861
2793
  declare namespace settlement {
2862
2794
  export { SettlementAsset, SettlementClient, SettlementHistoryEntry, SettlementInitiateRequest, SettlementPurpose, SettlementStatusResponse };
2863
2795
  }
2864
- declare namespace baas {
2865
- export { AgentBalance, AgentEvent, AgentFundRequest, AgentInfo, AgentOperation, AgentRegisterRequest, AgentRules, AgentRulesValidationResult, AgentStatus, AgentTradeRequest, AgentWithdrawRequest, AgentsClient, AuthenticateOptions, BaasAppListResponse, BaasAuthConfig, BaasAuthResult, BaasChallengeRequest, BaasChallengeResponse, BaasChannelConfig, BaasClient, BaasClientConfig, BaasDeleteResult, BaasDeployRequest, BaasDeployResult, BaasDocument, BaasEndpoints, BaasError, BaasErrorDetails, BaasErrorResponse, BaasFileInfo, BaasFileMetadata, BaasFindResult, BaasFunctionDeployRequest, BaasFunctionDeployResult, BaasFunctionInfo, BaasFunctionLog, BaasFunctionLogOptions, BaasFunctionResources, BaasFunctionResult, BaasFunctionRuntime, BaasHistoryOptions, BaasInsertResult, BaasMerkleProof, BaasMessage, BaasPresenceInfo, BaasPresenceMember, BaasPublishResult, BaasQueryOptions, BaasRegisterRequest, BaasRegisterResponse, BaasService, BaasSessionInfo, BaasStateTransition, BaasStorageUsage, BaasSupportedChain, BaasTriggerType, BaasUpdateResult, BaasUploadResult, BaasVerifyRequest, ChannelSubscription, DatabaseClient, DatabaseStatsResponse, DbComparisonOperator, DbDocument, DbQuery, DeployedApp, DeployedAppInfo, DeployedAppLimits, DeployedAppStatus, DeployedAppUsage, DeploymentClient, DocumentProofResponse, FunctionsClient, MessageHandler, MessagingClient, StateRootResponse, StateTransitionsResponse, StorageClient, validateAgentRules };
2866
- }
2867
2796
 
2868
2797
  export {
2869
- BaasClient$1 as NestJsBaasClient,
2870
2798
  RetryConfig as ResilienceRetryConfig,
2871
2799
  RetryConfig$1 as RetryConfig,
2872
2800
  auth,
2873
2801
  baas,
2874
2802
  chains,
2875
2803
  discovery,
2876
- nestjs,
2877
2804
  settlement,
2878
2805
  subscription,
2879
2806
  };
package/dist/index.js CHANGED
@@ -1,22 +1,12 @@
1
1
  'use strict';
2
2
 
3
3
  var zod = require('zod');
4
- var common = require('@nestjs/common');
5
4
 
6
5
  var __defProp = Object.defineProperty;
7
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
10
8
  __defProp(target, name, { get: all[name], enumerable: true });
11
9
  };
12
- var __decorateClass = (decorators, target, key, kind) => {
13
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
14
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
15
- if (decorator = decorators[i])
16
- result = (decorator(result)) || result;
17
- return result;
18
- };
19
- var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
20
10
 
21
11
  // src/_vendor/circuit-breaker.ts
22
12
  var DEFAULT_CIRCUIT_BREAKER_CONFIG = {
@@ -4010,293 +4000,6 @@ function validateUrl2(url, allowInsecure = false) {
4010
4000
  }
4011
4001
  }
4012
4002
 
4013
- // src/nestjs/index.ts
4014
- var nestjs_exports = {};
4015
- __export(nestjs_exports, {
4016
- SMART_ENGINE_CONFIG: () => SMART_ENGINE_CONFIG,
4017
- SmartEngineModule: () => exports.SmartEngineModule,
4018
- SmartEngineService: () => exports.SmartEngineService
4019
- });
4020
- var SMART_ENGINE_CONFIG = "SMART_ENGINE_CONFIG";
4021
- exports.SmartEngineService = class SmartEngineService {
4022
- constructor(config) {
4023
- this.config = config;
4024
- }
4025
- config;
4026
- logger = new common.Logger(exports.SmartEngineService.name);
4027
- client = null;
4028
- baasClient = null;
4029
- connected = false;
4030
- reconnectTimer = null;
4031
- reconnectAttempts = 0;
4032
- /**
4033
- * Initialize the service when the module starts
4034
- */
4035
- async onModuleInit() {
4036
- if (!this.config) {
4037
- this.logger.warn(
4038
- "SmartEngineService initialized without configuration. Call configure() before using."
4039
- );
4040
- return;
4041
- }
4042
- await this.initialize(this.config);
4043
- }
4044
- /**
4045
- * Clean up resources when the module is destroyed
4046
- */
4047
- async onModuleDestroy() {
4048
- await this.shutdown();
4049
- }
4050
- /**
4051
- * Initialize the service with configuration
4052
- *
4053
- * Can be called manually if not using DI configuration
4054
- */
4055
- async initialize(config) {
4056
- this.logger.log(`Initializing SmartEngineService for ${config.baseUrl}`);
4057
- try {
4058
- this.client = new SmartEngineClient({
4059
- baseUrl: config.baseUrl,
4060
- apiKey: config.apiKey,
4061
- authToken: config.authToken,
4062
- timeout: config.timeout,
4063
- allowInsecure: config.allowInsecure
4064
- });
4065
- this.baasClient = this.createBaasClient(this.client);
4066
- if (config.testConnection !== false) {
4067
- await this.testConnection();
4068
- }
4069
- this.connected = true;
4070
- this.reconnectAttempts = 0;
4071
- this.logger.log("SmartEngineService initialized successfully");
4072
- } catch (error) {
4073
- const err = error;
4074
- this.logger.error(`Failed to initialize SmartEngineService: ${err.message}`);
4075
- if (config.autoReconnect) {
4076
- this.scheduleReconnect(config);
4077
- } else {
4078
- throw error;
4079
- }
4080
- }
4081
- }
4082
- /**
4083
- * Gracefully shutdown the service
4084
- */
4085
- async shutdown() {
4086
- this.logger.log("Shutting down SmartEngineService");
4087
- if (this.reconnectTimer) {
4088
- clearTimeout(this.reconnectTimer);
4089
- this.reconnectTimer = null;
4090
- }
4091
- this.client = null;
4092
- this.baasClient = null;
4093
- this.connected = false;
4094
- this.logger.log("SmartEngineService shutdown complete");
4095
- }
4096
- /**
4097
- * Get the SmartEngineClient instance
4098
- *
4099
- * @throws SmartEngineError if client is not initialized
4100
- */
4101
- getClient() {
4102
- if (!this.client) {
4103
- throw new SmartEngineError2(
4104
- "SmartEngineClient not initialized. Ensure SmartEngineService is configured properly.",
4105
- 500
4106
- );
4107
- }
4108
- return this.client;
4109
- }
4110
- /**
4111
- * Get the BaaS client for simplified blockchain access
4112
- *
4113
- * The BaaS client provides a simplified interface for applications
4114
- * that need managed blockchain infrastructure access.
4115
- *
4116
- * @throws SmartEngineError if client is not initialized
4117
- */
4118
- getBaasClient() {
4119
- if (!this.baasClient) {
4120
- throw new SmartEngineError2(
4121
- "BaasClient not initialized. Ensure SmartEngineService is configured properly.",
4122
- 500
4123
- );
4124
- }
4125
- return this.baasClient;
4126
- }
4127
- /**
4128
- * Check if the service is connected and healthy
4129
- */
4130
- isConnected() {
4131
- return this.connected;
4132
- }
4133
- /**
4134
- * Test the connection to the validator
4135
- */
4136
- async testConnection() {
4137
- if (!this.client) {
4138
- return false;
4139
- }
4140
- try {
4141
- const health = await this.client.getHealth();
4142
- this.connected = health.status === "healthy" || health.status === "ok";
4143
- return this.connected;
4144
- } catch (error) {
4145
- const err = error;
4146
- this.logger.warn(`Connection test failed: ${err.message}`);
4147
- this.connected = false;
4148
- return false;
4149
- }
4150
- }
4151
- /**
4152
- * Get the current connection status
4153
- */
4154
- getStatus() {
4155
- return {
4156
- connected: this.connected,
4157
- baseUrl: this.client?.getBaseUrl() ?? null,
4158
- authenticated: this.client?.isAuthenticated() ?? false,
4159
- reconnectAttempts: this.reconnectAttempts
4160
- };
4161
- }
4162
- /**
4163
- * Create a SmartGatewayClient for gateway operations
4164
- */
4165
- createGatewayClient(config) {
4166
- return new SmartGatewayClient(config);
4167
- }
4168
- /**
4169
- * Create a BaaS client for host operations
4170
- */
4171
- createHostClient(config) {
4172
- return new BaasClient(config);
4173
- }
4174
- /**
4175
- * Create a BaaS client wrapper around the SmartEngineClient
4176
- */
4177
- createBaasClient(client) {
4178
- return {
4179
- client,
4180
- isHealthy: async () => {
4181
- try {
4182
- const health = await client.getHealth();
4183
- return health.status === "healthy" || health.status === "ok";
4184
- } catch {
4185
- return false;
4186
- }
4187
- },
4188
- getBaseUrl: () => client.getBaseUrl()
4189
- };
4190
- }
4191
- /**
4192
- * Schedule a reconnection attempt
4193
- */
4194
- scheduleReconnect(config) {
4195
- const maxAttempts = config.maxReconnectAttempts ?? 0;
4196
- const interval = config.reconnectInterval ?? 5e3;
4197
- if (maxAttempts > 0 && this.reconnectAttempts >= maxAttempts) {
4198
- this.logger.error(`Max reconnection attempts (${maxAttempts}) reached. Giving up.`);
4199
- return;
4200
- }
4201
- this.reconnectAttempts++;
4202
- this.logger.log(`Scheduling reconnection attempt ${this.reconnectAttempts} in ${interval}ms`);
4203
- this.reconnectTimer = setTimeout(async () => {
4204
- try {
4205
- await this.initialize(config);
4206
- } catch {
4207
- }
4208
- }, interval);
4209
- }
4210
- };
4211
- exports.SmartEngineService = __decorateClass([
4212
- common.Injectable(),
4213
- __decorateParam(0, common.Optional()),
4214
- __decorateParam(0, common.Inject(SMART_ENGINE_CONFIG))
4215
- ], exports.SmartEngineService);
4216
-
4217
- // src/nestjs/smart-engine.module.ts
4218
- exports.SmartEngineModule = class SmartEngineModule {
4219
- /**
4220
- * Configure the module with static configuration
4221
- *
4222
- * @param config - SmartEngine service configuration
4223
- * @param isGlobal - Whether to make the module global (default: true)
4224
- */
4225
- static forRoot(config, isGlobal = true) {
4226
- return {
4227
- module: exports.SmartEngineModule,
4228
- global: isGlobal,
4229
- providers: [
4230
- {
4231
- provide: SMART_ENGINE_CONFIG,
4232
- useValue: config
4233
- },
4234
- exports.SmartEngineService
4235
- ],
4236
- exports: [exports.SmartEngineService]
4237
- };
4238
- }
4239
- /**
4240
- * Configure the module with async configuration
4241
- *
4242
- * Supports factory functions, configuration classes, and existing providers.
4243
- *
4244
- * @param options - Async configuration options
4245
- */
4246
- static forRootAsync(options) {
4247
- const asyncProviders = this.createAsyncProviders(options);
4248
- return {
4249
- module: exports.SmartEngineModule,
4250
- global: options.isGlobal ?? true,
4251
- imports: options.imports || [],
4252
- providers: [...asyncProviders, exports.SmartEngineService],
4253
- exports: [exports.SmartEngineService]
4254
- };
4255
- }
4256
- /**
4257
- * Create async providers based on configuration options
4258
- */
4259
- static createAsyncProviders(options) {
4260
- if (options.useFactory) {
4261
- return [
4262
- {
4263
- provide: SMART_ENGINE_CONFIG,
4264
- useFactory: options.useFactory,
4265
- inject: options.inject || []
4266
- }
4267
- ];
4268
- }
4269
- if (options.useClass) {
4270
- return [
4271
- {
4272
- provide: options.useClass,
4273
- useClass: options.useClass
4274
- },
4275
- {
4276
- provide: SMART_ENGINE_CONFIG,
4277
- useFactory: async (optionsFactory) => optionsFactory.createSmartEngineOptions(),
4278
- inject: [options.useClass]
4279
- }
4280
- ];
4281
- }
4282
- if (options.useExisting) {
4283
- return [
4284
- {
4285
- provide: SMART_ENGINE_CONFIG,
4286
- useFactory: async (optionsFactory) => optionsFactory.createSmartEngineOptions(),
4287
- inject: [options.useExisting]
4288
- }
4289
- ];
4290
- }
4291
- throw new Error(
4292
- "Invalid SmartEngineModuleAsyncOptions: must provide useFactory, useClass, or useExisting"
4293
- );
4294
- }
4295
- };
4296
- exports.SmartEngineModule = __decorateClass([
4297
- common.Module({})
4298
- ], exports.SmartEngineModule);
4299
-
4300
4003
  exports.AgentsClient = AgentsClient;
4301
4004
  exports.BaasClient = BaasClient;
4302
4005
  exports.BaasError = BaasError;
@@ -4319,7 +4022,6 @@ exports.MirrorNodeClient = MirrorNodeClient;
4319
4022
  exports.MirrorNodeError = MirrorNodeError;
4320
4023
  exports.RateLimiter = RateLimiter;
4321
4024
  exports.RoutingClient = RoutingClient;
4322
- exports.SMART_ENGINE_CONFIG = SMART_ENGINE_CONFIG;
4323
4025
  exports.SdkHttpError = SdkHttpError;
4324
4026
  exports.SettlementClient = SettlementClient;
4325
4027
  exports.SmartEngineClient = SmartEngineClient;
@@ -4341,7 +4043,6 @@ exports.createHttpClient = createHttpClient;
4341
4043
  exports.createResilientFetchWithBreaker = createResilientFetchWithBreaker;
4342
4044
  exports.discovery = discovery_exports;
4343
4045
  exports.encodePathParam = encodePathParam;
4344
- exports.nestjs = nestjs_exports;
4345
4046
  exports.resilientFetch = resilientFetch;
4346
4047
  exports.settlement = settlement_exports;
4347
4048
  exports.subscription = subscription_exports;