| 
									
										
										
										
											2024-02-17 20:24:28 +01:00
										 |  |  | import { SzEmailConnector } from './email/classes.emailconnector.js'; | 
					
						
							|  |  |  | import { SzSmsConnector } from './email/classes.smsconnector.js'; | 
					
						
							|  |  |  | import * as plugins from './plugins.js'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export class SzPlatformClient { | 
					
						
							|  |  |  |   private authorizationString: string; | 
					
						
							|  |  |  |   public typedrouter = new plugins.typedrequest.TypedRouter(); | 
					
						
							|  |  |  |   public typedsocket: plugins.typedsocket.TypedSocket; | 
					
						
							|  |  |  |   private qenvInstance = new plugins.qenv.Qenv(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   public emailConnector = new SzEmailConnector(this); | 
					
						
							|  |  |  |   public smsConnector = new SzSmsConnector(this); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-17 20:35:46 +01:00
										 |  |  |   constructor(authorizationStringArg?: string) { | 
					
						
							| 
									
										
										
										
											2024-02-17 20:24:28 +01:00
										 |  |  |     this.authorizationString = authorizationStringArg; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-17 20:35:46 +01:00
										 |  |  |   public async init(authorizationStringArg?: string) { | 
					
						
							|  |  |  |     if (authorizationStringArg) this.authorizationString = authorizationStringArg; | 
					
						
							|  |  |  |     if (!this.authorizationString) this.authorizationString = process.env.SERVEZONE_PLATFROM_AUTHORIZATION; | 
					
						
							|  |  |  |     if (!this.authorizationString) throw new Error('authorizationString is required'); | 
					
						
							| 
									
										
										
										
											2024-02-17 20:24:28 +01:00
										 |  |  |     this.typedsocket = await plugins.typedsocket.TypedSocket.createClient(this.typedrouter, await this.getConnectionAddress()); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   private async getConnectionAddress() { | 
					
						
							|  |  |  |     const connectionAddress = await this.qenvInstance.getEnvVarOnDemand('SERVEZONE_API_DOMAIN'); | 
					
						
							|  |  |  |     return connectionAddress; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } |