@urga-panel/ur-panels-core 1.0.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.
Files changed (101) hide show
  1. package/.eslintrc.js +13 -0
  2. package/dist/ServiceManager.d.ts +26 -0
  3. package/dist/ServiceManager.js +351 -0
  4. package/dist/TestRun.d.ts +1 -0
  5. package/dist/TestRun.js +14 -0
  6. package/dist/index.d.ts +15 -0
  7. package/dist/index.js +22 -0
  8. package/dist/services/abstract/apiService/ApiService.d.ts +17 -0
  9. package/dist/services/abstract/apiService/ApiService.js +33 -0
  10. package/dist/services/abstract/authServices/AuthService.d.ts +75 -0
  11. package/dist/services/abstract/authServices/AuthService.js +275 -0
  12. package/dist/services/abstract/authServices/Authorization.d.ts +0 -0
  13. package/dist/services/abstract/authServices/Authorization.js +0 -0
  14. package/dist/services/abstract/extensionServices/ExtensionService.d.ts +25 -0
  15. package/dist/services/abstract/extensionServices/ExtensionService.js +21 -0
  16. package/dist/services/abstract/pageServices/LayoutPageService.d.ts +17 -0
  17. package/dist/services/abstract/pageServices/LayoutPageService.js +32 -0
  18. package/dist/services/abstract/pageServices/PageServices.d.ts +20 -0
  19. package/dist/services/abstract/pageServices/PageServices.js +23 -0
  20. package/dist/services/abstract/pageServices/controllers/NSPageControllerService.d.ts +10 -0
  21. package/dist/services/abstract/pageServices/controllers/NSPageControllerService.js +18 -0
  22. package/dist/services/abstract/pageServices/controllers/PageControllerService.d.ts +27 -0
  23. package/dist/services/abstract/pageServices/controllers/PageControllerService.js +24 -0
  24. package/dist/services/abstract/pageServices/controllers/SVPageControllerService.d.ts +34 -0
  25. package/dist/services/abstract/pageServices/controllers/SVPageControllerService.js +73 -0
  26. package/dist/services/abstract/pageServices/pages/NsPageService.d.ts +26 -0
  27. package/dist/services/abstract/pageServices/pages/NsPageService.js +66 -0
  28. package/dist/services/abstract/project/ProjectInfoService.d.ts +42 -0
  29. package/dist/services/abstract/project/ProjectInfoService.js +72 -0
  30. package/dist/services/abstract/webviewServices/WVBackService.d.ts +18 -0
  31. package/dist/services/abstract/webviewServices/WVBackService.js +22 -0
  32. package/dist/services/abstract/webviewServices/WVFrontService.d.ts +21 -0
  33. package/dist/services/abstract/webviewServices/WVFrontService.js +54 -0
  34. package/dist/services/abstract/webviewServices/nv.d.ts +26 -0
  35. package/dist/services/abstract/webviewServices/nv.js +99 -0
  36. package/dist/services/main/fetchServices/FetchBrowserService.d.ts +19 -0
  37. package/dist/services/main/fetchServices/FetchBrowserService.js +26 -0
  38. package/dist/services/main/httpServices/RequestHandlerService.d.ts +46 -0
  39. package/dist/services/main/httpServices/RequestHandlerService.js +165 -0
  40. package/dist/services/main/remoteApiControllerService/RemoteApiControllerService.d.ts +36 -0
  41. package/dist/services/main/remoteApiControllerService/RemoteApiControllerService.js +42 -0
  42. package/dist/services/main/testServices/TestService.d.ts +19 -0
  43. package/dist/services/main/testServices/TestService.js +22 -0
  44. package/dist/services/main/testServices/TestService2.d.ts +18 -0
  45. package/dist/services/main/testServices/TestService2.js +20 -0
  46. package/dist/types/RegisterServiceInfo.d.ts +13 -0
  47. package/dist/types/RegisterServiceInfo.js +1 -0
  48. package/dist/types/Service.d.ts +32 -0
  49. package/dist/types/Service.js +43 -0
  50. package/dist/types/ServiceConstructor.d.ts +5 -0
  51. package/dist/types/ServiceConstructor.js +1 -0
  52. package/dist/types/ServiceEntry.d.ts +6 -0
  53. package/dist/types/ServiceEntry.js +1 -0
  54. package/dist/types/ServiceOts.d.ts +12 -0
  55. package/dist/types/ServiceOts.js +1 -0
  56. package/dist/types/ServiceRegisterInfo.d.ts +29 -0
  57. package/dist/types/ServiceRegisterInfo.js +25 -0
  58. package/dist/types/ServiceResponse.d.ts +13 -0
  59. package/dist/types/ServiceResponse.js +1 -0
  60. package/dist/types/ServiceSetupOptions.d.ts +3 -0
  61. package/dist/types/ServiceSetupOptions.js +1 -0
  62. package/dist/types/ServiceStatus.d.ts +1 -0
  63. package/dist/types/ServiceStatus.js +1 -0
  64. package/dist/types/_ServiceError.d.ts +5 -0
  65. package/dist/types/_ServiceError.js +1 -0
  66. package/jest.config.js +5 -0
  67. package/package.json +35 -0
  68. package/src/ServiceManager.ts +403 -0
  69. package/src/TestRun.ts +17 -0
  70. package/src/index.ts +26 -0
  71. package/src/services/abstract/apiService/ApiService.ts +51 -0
  72. package/src/services/abstract/authServices/AuthService.ts +364 -0
  73. package/src/services/abstract/authServices/Authorization.ts +0 -0
  74. package/src/services/abstract/extensionServices/ExtensionService.ts +50 -0
  75. package/src/services/abstract/pageServices/LayoutPageService.ts +49 -0
  76. package/src/services/abstract/pageServices/PageServices.ts +37 -0
  77. package/src/services/abstract/pageServices/controllers/NSPageControllerService.ts +23 -0
  78. package/src/services/abstract/pageServices/controllers/PageControllerService.ts +56 -0
  79. package/src/services/abstract/pageServices/controllers/SVPageControllerService.ts +104 -0
  80. package/src/services/abstract/pageServices/pages/NSPageService.ts +82 -0
  81. package/src/services/abstract/project/ProjectInfoService.ts +108 -0
  82. package/src/services/abstract/webviewServices/WVBackService.ts +34 -0
  83. package/src/services/abstract/webviewServices/WVFrontService.ts +71 -0
  84. package/src/services/abstract/webviewServices/nv.js +112 -0
  85. package/src/services/abstract/webviewServices/nv.ts +125 -0
  86. package/src/services/main/fetchServices/FetchBrowserService.ts +40 -0
  87. package/src/services/main/httpServices/RequestHandlerService.ts +207 -0
  88. package/src/services/main/remoteApiControllerService/RemoteApiControllerService.ts +70 -0
  89. package/src/services/main/testServices/TestService.ts +36 -0
  90. package/src/services/main/testServices/TestService2.ts +34 -0
  91. package/src/types/RegisterServiceInfo.ts +19 -0
  92. package/src/types/Service.ts +61 -0
  93. package/src/types/ServiceConstructor.ts +6 -0
  94. package/src/types/ServiceEntry.ts +10 -0
  95. package/src/types/ServiceOts.ts +17 -0
  96. package/src/types/ServiceRegisterInfo.ts +48 -0
  97. package/src/types/ServiceResponse.ts +13 -0
  98. package/src/types/ServiceSetupOptions.ts +5 -0
  99. package/src/types/ServiceStatus.ts +2 -0
  100. package/src/types/_ServiceError.ts +5 -0
  101. package/tsconfig.json +20 -0
@@ -0,0 +1,207 @@
1
+ import { Service } from "../../../types/Service";
2
+ import { RegisterServiceInfo } from "../../../types/ServiceRegisterInfo";
3
+ import { ServiceResponse } from "../../../types/ServiceResponse";
4
+ import { ServiceSetupOptions } from "../../../types/ServiceSetupOptions";
5
+
6
+
7
+
8
+ export type HandlerList = {
9
+ [key: string]: {
10
+ callback({ params, request, url, user }: { params: any; request: any; url: any; user?: any }): Promise<any>;
11
+ options?: {
12
+ auth?: boolean;
13
+ role?: string;
14
+ }
15
+ }
16
+ }
17
+
18
+
19
+ export class RequestHandlerService extends Service {
20
+
21
+ static serviceInfo = {
22
+ name: "RequestHandlerService",
23
+ requiredServices: ["AuthService"],
24
+ }
25
+ handlers: HandlerList = {};
26
+
27
+ protected async onSetup(options?: ServiceSetupOptions): Promise<ServiceResponse> {
28
+ return { status: "success", message: "TestService setup complete" };
29
+ }
30
+
31
+ protected async onStart(): Promise<ServiceResponse> {
32
+ return { status: "success", message: "TestService started" };
33
+ }
34
+
35
+ protected async onStop(): Promise<ServiceResponse> {
36
+ return { status: "success", message: "TestService stopped" };
37
+ }
38
+
39
+ protected async onDestroy(): Promise<ServiceResponse> {
40
+ return { status: "success", message: "TestService destroyed" };
41
+ }
42
+
43
+ constructor(public ots: any) {
44
+ super(ots);
45
+ }
46
+ async addHandler(name: string, callback: ({ params, request, url, user }
47
+
48
+ ) => Promise<any>, options?: {
49
+ auth?: boolean;
50
+ role?: string;
51
+ }) {
52
+ this.handlers[name] = { callback, options };
53
+ this.log.OK("RequestHandlerService addHandler", name);
54
+ }
55
+
56
+ async requestCome({ params, request, url }): Promise<any> {
57
+ this.log.OK("RequestHandlerService requestCome", params);
58
+
59
+ let bodyData: any = null;
60
+ const contentType = request.headers.get('content-type');
61
+
62
+ try {
63
+ if (contentType?.includes('application/json')) {
64
+ bodyData = await request.json();
65
+ } else if (contentType?.includes('form')) {
66
+ const formData = await request.formData();
67
+ const data: Record<string, any> = {};
68
+ for (const [key, value] of formData.entries()) {
69
+ data[key] = value;
70
+ }
71
+ bodyData = data;
72
+ }
73
+ } catch (e) {
74
+ // JSON değilse veya body yoksa hata alınabilir, burada kontrol edebilirsiniz
75
+ bodyData = null;
76
+ }
77
+ const handlerName = params.path; // Assuming path is the handler name
78
+ const handler = this.handlers[handlerName];
79
+ if (!handler) {
80
+ this.log.ERROR("Handler not found:", handlerName);
81
+ //throw new Error(`Handler not found: ${handlerName}`);
82
+ return { status: "error", message: "An error occurred" };
83
+ }
84
+ const event = { params, request, url };
85
+ this.log.OK("RequestHandlerService requestCome event");
86
+ try {
87
+ let header = {};
88
+ let user: any = null;
89
+ if (handler.options?.auth) {
90
+
91
+ const authService = this.ots.usedService.AuthService();
92
+ if (!authService) {
93
+ this.log.ERROR("AuthService not found");
94
+ return this.resposeHandler({ status: "error", message: "Authentication service not available" });
95
+ }
96
+
97
+ const cookieHeader = request.headers.get('cookie');
98
+ const accessToken = this.getCookie(cookieHeader, 'accessToken');
99
+ const refreshToken = this.getCookie(cookieHeader, 'refreshToken');
100
+ // Check authentication and role
101
+ const isAuthenticated = await authService.checkToken({
102
+ accessToken,
103
+ refreshToken,
104
+ options: {
105
+ role: handler.options?.role
106
+ }
107
+ },);
108
+
109
+ console.log("isAuthenticated", isAuthenticated);
110
+
111
+ if (!isAuthenticated.valid) {
112
+ return this.resposeHandler({ status: "error", message: "Unauthorized" });
113
+ }
114
+ user = isAuthenticated.user || null;
115
+
116
+ if (isAuthenticated.newAccessToken) {
117
+ // Update cookies with new tokens
118
+ console.log("update token");
119
+ header = {
120
+ "Set-Cookie":
121
+ `accessToken=${isAuthenticated.newAccessToken}; Path=/; HttpOnly; Secure; SameSite=Strict; Max-Age=900, refreshToken=${isAuthenticated.newRefreshToken}; Path=/; HttpOnly; Secure; SameSite=Strict; Max-Age=604800`,
122
+ }
123
+ // const response = new Response(JSON.stringify({ status: "success", message: "Authenticated with new token" }), {
124
+ // status: 200,
125
+ // headers: {
126
+
127
+ // 'Content-Type': 'application/json'
128
+ // }
129
+ // });
130
+ // return response;
131
+ }
132
+ //return this.resposeHandler({ status: "success", message: "Authenticated with old token" });
133
+
134
+
135
+ }
136
+
137
+ let response: Response;
138
+ if (bodyData !== null) {
139
+ response = await handler.callback({ ...bodyData, ...event, user });
140
+ } else {
141
+ response = await handler.callback({ ...event, user });
142
+ }
143
+
144
+ console.log("RequestHandlerService requestCome response");
145
+ console.log("Object.keys(header).length", Object.keys(header).length);
146
+ // Eğer header içinde Set-Cookie veya başka header varsa response'a ekle
147
+ if (Object.keys(header).length > 0) {
148
+ // Response zaten bir Response nesnesi ise, header'ları birleştirerek yeni bir Response oluştur
149
+ const originalBody = await response.text();
150
+ response = new Response(originalBody, {
151
+ status: response.status,
152
+ statusText: response.statusText,
153
+ headers: {
154
+ ...Object.fromEntries(response.headers.entries()),
155
+ ...header,
156
+ }
157
+ });
158
+ }
159
+ this.log.OK("RequestHandlerService requestCome response", response);
160
+
161
+ return response;
162
+ } catch (error) {
163
+ return { status: "error", message: error.message || "An error occurred" };
164
+ }
165
+
166
+
167
+ }
168
+ getCookie(cookieHeader: string | null, name: string): string | undefined {
169
+ if (!cookieHeader) return undefined;
170
+ const cookies = cookieHeader.split(';').map(c => c.trim());
171
+ for (const cookie of cookies) {
172
+ const [key, ...val] = cookie.split('=');
173
+ if (key === name) return val.join('=');
174
+ }
175
+ return undefined;
176
+ }
177
+
178
+ resposeHandler(response: any): Response {
179
+ if (response.status === "success") {
180
+ return new Response(JSON.stringify(response), {
181
+ status: 200,
182
+ headers: {
183
+ 'Content-Type': 'application/json'
184
+ }
185
+ });
186
+ }
187
+ return new Response(JSON.stringify(response), {
188
+ status: 400,
189
+ headers: {
190
+ 'Content-Type': 'application/json'
191
+ }
192
+ });
193
+ }
194
+
195
+
196
+ }
197
+
198
+ const registerServiceInfo = new RegisterServiceInfo(
199
+ {
200
+ serviceName: "RequestHandlerService",
201
+ service: RequestHandlerService,
202
+ tag: "RequestHandlerService",
203
+ dynamicTag: false,
204
+ requiredServices: [],
205
+ isAbstract: false,
206
+ }
207
+ );
@@ -0,0 +1,70 @@
1
+ import { Service } from "../../../types/Service";
2
+ import { ServiceOts } from "../../../types/ServiceOts";
3
+ import { ServiceResponse } from "../../../types/ServiceResponse";
4
+ import { ServiceSetupOptions } from "../../../types/ServiceSetupOptions";
5
+
6
+ export type apiConfig = {
7
+ tag: string;
8
+ api: string;
9
+ baseUrl: string;
10
+ auth: {
11
+ sellerId?: string;
12
+ username?: string;
13
+ password?: string;
14
+ type?: string;
15
+ }
16
+ serviceRef?: any;
17
+ service?: any; // This will be the actual service instance created
18
+ }
19
+
20
+ export type RemoteApiControllerServiceOts = ServiceOts & {
21
+ usedService: {
22
+ }
23
+ }
24
+
25
+ export class RemoteApiControllerService extends Service {
26
+ static serviceInfo = {
27
+ name: "RemoteApiControllerService",
28
+ requiredServices: [],
29
+ }
30
+ apis: { [key: string]: apiConfig } = {};
31
+ protected async onSetup(options?: ServiceSetupOptions): Promise<ServiceResponse> {
32
+
33
+ return { status: "success", message: "onSetup complete" };
34
+ }
35
+ protected async onStart(): Promise<ServiceResponse> {
36
+ return { status: "success", message: "onStart complete" };
37
+ }
38
+ protected async onStop(): Promise<ServiceResponse> {
39
+ return { status: "success", message: "onStop complete" };
40
+ }
41
+ protected async onDestroy(): Promise<ServiceResponse> {
42
+ return { status: "success", message: "onDestroy complete" };
43
+ }
44
+ constructor(public ots: RemoteApiControllerServiceOts) {
45
+ super({ ...ots });
46
+ }
47
+ addApi(apiName: string, serviceRef: any, apiConfig: apiConfig): void {
48
+ if (this.apis[apiName]) {
49
+ console.warn(`API ${apiName} already exists. Overwriting.`);
50
+ }
51
+ this.apis[apiName] = apiConfig;
52
+ this.apis[apiName].serviceRef = serviceRef;
53
+ console.log(`API ${apiName} added with config:`, apiConfig);
54
+
55
+ // Create a service for each API
56
+ Object.keys(this.apis).forEach(async apiName => {
57
+ const service = this.ots.abilities.createChildService?.(apiName,
58
+ this.apis[apiName].serviceRef
59
+ );
60
+ if (service) {
61
+ this.apis[apiName].service = service;
62
+ }
63
+ await service.setup();
64
+ await service.start();
65
+ });
66
+ }
67
+
68
+ }
69
+
70
+
@@ -0,0 +1,36 @@
1
+ import { Service } from "../../../types/Service";
2
+ import { ServiceOts } from "../../../types/ServiceOts";
3
+ import { ServiceResponse } from "../../../types/ServiceResponse";
4
+ import { ServiceSetupOptions } from "../../../types/ServiceSetupOptions";
5
+
6
+ export type TestOts = ServiceOts & {
7
+ usedService: {
8
+ }
9
+ }
10
+
11
+ export class TestService extends Service {
12
+ serviceInfo: { name: string; requiredServices: string[]; };
13
+ constructor(ots:TestOts) {
14
+ super({...ots});
15
+ }
16
+
17
+ protected async onSetup(options?: ServiceSetupOptions): Promise<ServiceResponse> {
18
+ return { status: "success", message: "TestService setup complete" };
19
+ }
20
+
21
+ protected async onStart(): Promise<ServiceResponse> {
22
+ return { status: "success", message: "TestService started" };
23
+ }
24
+
25
+ protected async onStop(): Promise<ServiceResponse> {
26
+ return { status: "success", message: "TestService stopped" };
27
+ }
28
+
29
+ protected async onDestroy(): Promise<ServiceResponse> {
30
+ return { status: "success", message: "TestService destroyed" };
31
+ }
32
+
33
+ denemeYazi() {
34
+ return "deneme";
35
+ }
36
+ }
@@ -0,0 +1,34 @@
1
+ import { Service } from "../../../types/Service";
2
+ import { ServiceOts } from "../../../types/ServiceOts";
3
+ import { ServiceResponse } from "../../../types/ServiceResponse";
4
+ import { ServiceSetupOptions } from "../../../types/ServiceSetupOptions";
5
+
6
+
7
+ export type Test2Ots = ServiceOts & {
8
+ usedService: {
9
+ }
10
+ }
11
+
12
+ export class Test2Service extends Service {
13
+ serviceInfo: { name: string; requiredServices: string[]; };
14
+ constructor(ots:Test2Ots) {
15
+ super({...ots});
16
+ console.log("Test2Service initialized");
17
+ }
18
+
19
+ protected async onSetup(options?: ServiceSetupOptions): Promise<ServiceResponse> {
20
+ return { status: "success", message: "Test2Service setup complete" };
21
+ }
22
+
23
+ protected async onStart(): Promise<ServiceResponse> {
24
+ return { status: "success", message: "Test2Service started" };
25
+ }
26
+
27
+ protected async onStop(): Promise<ServiceResponse> {
28
+ return { status: "success", message: "Test2Service stopped" };
29
+ }
30
+
31
+ protected async onDestroy(): Promise<ServiceResponse> {
32
+ return { status: "success", message: "Test2Service destroyed" };
33
+ }
34
+ }
@@ -0,0 +1,19 @@
1
+ import { Service } from "./Service";
2
+
3
+ export interface ServiceConstructor<T extends Service> {
4
+ [x: string]: any;
5
+ new(ots: any): T;
6
+ }
7
+ export type RegisterServiceInfo = {
8
+ serviceName: string;
9
+ service: ServiceConstructor<Service>;
10
+ tag: string; // Static tag for the service
11
+ dynamicTag: boolean; // Dynamic tag for the service
12
+ // serviceCtor: any; // Service constructor
13
+ // serviceOts: any; // Service options
14
+ requiredServices?: string[]; // List of required services
15
+ // description?: string; // Service description
16
+ // version?: string; // Service version
17
+ // type?: string; // Service type
18
+ isAbstract?: boolean; // Whether the service is abstract
19
+ }
@@ -0,0 +1,61 @@
1
+ import { ServiceOts } from "./ServiceOts";
2
+ import { ServiceResponse } from "./ServiceResponse";
3
+ import { ServiceSetupOptions } from "./ServiceSetupOptions";
4
+
5
+ export abstract class Service {
6
+
7
+ static serviceInfo: {
8
+ name: string;
9
+ requiredServices: string[];
10
+ }
11
+ public tag: string = "";
12
+ public log: {
13
+ OK: Function,
14
+ ERROR: Function,
15
+ l: Function,
16
+ WARN: Function
17
+ }
18
+
19
+ protected abstract onSetup(options?: ServiceSetupOptions):Promise<ServiceResponse>;
20
+ protected abstract onStart(): Promise<ServiceResponse>;
21
+ protected abstract onStop(): Promise<ServiceResponse>;
22
+ protected abstract onDestroy(): Promise<ServiceResponse>;
23
+
24
+ public async setup(options?: ServiceSetupOptions): Promise<ServiceResponse> {
25
+ this.log.OK("setup called");
26
+ return this.onSetup(options);
27
+ }
28
+ public async start(): Promise<ServiceResponse> {
29
+ this.log.OK("start called");
30
+ return this.onStart();
31
+ }
32
+ public async stop(): Promise<ServiceResponse> {
33
+ this.log.OK("stop called");
34
+ return this.onStop();
35
+ }
36
+ public async destroy(): Promise<ServiceResponse> {
37
+ this.log.OK("destroy called");
38
+ return this.onDestroy();
39
+ }
40
+
41
+ constructor(private opts: ServiceOts) {
42
+ this.tag = opts.tag;
43
+ if (!opts.usedService["LogService"]) {
44
+ console.error("LogService not found for", opts.tag);
45
+ this.log = this.logSetup();
46
+ return;
47
+ }
48
+ else {
49
+ //console.log("LogService found for", opts.usedService["LogService"]);
50
+ this.log = (opts.usedService["LogService"] as unknown as any).logSetupForService(this.tag);
51
+ }
52
+ }
53
+ logSetup() {
54
+ return {
55
+ OK: console.log.bind(console, `[${this.tag}]` + "-[OK]"),
56
+ ERROR: console.error.bind(console, `[${this.tag}]` + "-[ERROR]"),
57
+ WARN: console.warn.bind(console, `[${this.tag}]` + "-[WARN]"),
58
+ l: console.log.bind(console, `[${this.tag}]`),
59
+ }
60
+ }
61
+ }
@@ -0,0 +1,6 @@
1
+ import { Service } from "./Service";
2
+ import { ServiceOts } from "./ServiceOts";
3
+
4
+ export interface ServiceConstructor<T extends Service> {
5
+ new(ots: ServiceOts): T;
6
+ }
@@ -0,0 +1,10 @@
1
+ import { Service } from "./Service";
2
+ import { ServiceConstructor } from "./ServiceConstructor";
3
+ import { ServiceStatus } from "./ServiceStatus";
4
+
5
+ export type ServiceEntry<T extends Service> = {
6
+ // serviceType: ServiceConstructor<T>;
7
+ serviceSelf: T | null;
8
+ status: ServiceStatus;
9
+ // create: (ots?: object) => void;
10
+ };
@@ -0,0 +1,17 @@
1
+ import { Service } from "./Service"
2
+ import { ServiceConstructor } from "./ServiceConstructor"
3
+
4
+ export type ServiceOts = {
5
+ usedService: {
6
+ [key: string]: () => Service
7
+ },
8
+ tag:string,
9
+ abilities?: {
10
+ createChildService?: (tag:string, PageCtor: ServiceConstructor<Service>)=> Service,
11
+ }
12
+ type: string
13
+ // funcs: {
14
+ // stop: () => void,
15
+ // destroy: () => void
16
+ // }
17
+ }
@@ -0,0 +1,48 @@
1
+ import { Service } from "./Service";
2
+ import { ServiceConstructor } from "./ServiceConstructor";
3
+
4
+ type abstractService = {
5
+ serviceName: string;
6
+ abstractService: typeof Service;
7
+ tag: string;
8
+ dynamicTag: boolean;
9
+ requiredServices?: string[];
10
+ isAbstract: true;
11
+ }
12
+
13
+ type normalService = {
14
+ serviceName: string;
15
+ service: ServiceConstructor<Service>;
16
+ tag: string;
17
+ dynamicTag: boolean;
18
+ requiredServices?: string[];
19
+ isAbstract: false;
20
+ }
21
+
22
+ export class RegisterServiceInfo {
23
+ serviceName: string;
24
+ service: ServiceConstructor<Service>;
25
+ abstractService: typeof Service;
26
+ tag: string; // Static tag for the service
27
+ dynamicTag: boolean; // Dynamic tag for the service
28
+ requiredServices?: string[]; // List of required services
29
+ isAbstract: boolean; // Whether the service is abstract
30
+
31
+ constructor(params: abstractService | normalService) {
32
+ this.serviceName = params.serviceName;
33
+ if ('abstractService' in params) {
34
+ this.abstractService = params.abstractService;
35
+ }
36
+ if ('service' in params) {
37
+ if (typeof params.service !== 'function') {
38
+ throw new Error("Service must be a constructor function");
39
+ }
40
+ this.service = params.service;
41
+ }
42
+
43
+ this.tag = params.tag;
44
+ this.dynamicTag = params.dynamicTag;
45
+ this.requiredServices = params.requiredServices || [];
46
+ this.isAbstract = params.isAbstract || false;
47
+ }
48
+ }
@@ -0,0 +1,13 @@
1
+ export type ServiceResponse<T = unknown> = {
2
+ status: "success" | "error";
3
+ data?: T;
4
+ error?: {
5
+ code: number;
6
+ message: string;
7
+ details?: string;
8
+ };
9
+ message?: string;
10
+ timestamp?: string;
11
+ requestId?: string;
12
+ [key: string]: unknown; // Allow additional properties
13
+ }
@@ -0,0 +1,5 @@
1
+ export type ServiceSetupOptions = {
2
+
3
+ //other options
4
+ [key:string]:unknown;
5
+ }
@@ -0,0 +1,2 @@
1
+ export type ServiceStatus =
2
+ "waitSetup" | "running" | "error" | "waitStart" | "stop";
@@ -0,0 +1,5 @@
1
+ export type ServiceError = {
2
+ code:number,
3
+ error:Error,
4
+ message:string
5
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ESNext",
4
+ "module": "ESNext",
5
+ "strict": false,
6
+ "esModuleInterop": true,
7
+ "skipLibCheck": true,
8
+ "moduleResolution": "bundler",
9
+ "noEmitOnError": false,
10
+ "forceConsistentCasingInFileNames": false,
11
+ "outDir": "./dist",
12
+ "resolveJsonModule": true,
13
+ "declaration": true,
14
+ "emitDeclarationOnly": false, // hem .js hem .d.ts çıkar
15
+
16
+ },
17
+ "include": ["src"],
18
+ "exclude": ["node_modules", "dist", "test"],
19
+
20
+ }