@urga-panel/ur-panels-core 1.0.18 → 1.0.20

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.
@@ -11,8 +11,8 @@ export declare class _ServiceManager {
11
11
  [key: string]: ServiceEntry<Service>;
12
12
  };
13
13
  constructor();
14
- initServices(type: "ns" | "svelte" | "node" | "svelteBackend", services: Array<RegisterServiceInfo>): Promise<void>;
15
- getService<T extends Service>(serviceName: string): T;
14
+ initServices(type: "ns" | "svelte" | "node" | "svelteBackend", services: Array<RegisterServiceInfo>, namespace?: string): Promise<void>;
15
+ getService<T extends Service>(serviceName: string, namespace?: string): T;
16
16
  private setKey;
17
17
  private quickService;
18
18
  /**
@@ -20,7 +20,7 @@ export class _ServiceManager {
20
20
  // };
21
21
  // // LayoutService?: ServiceConstructor<LayoutPageService>;
22
22
  // }
23
- services) {
23
+ services, namespace) {
24
24
  //debugger;
25
25
  console.log("ServiceManager: Initializing services...");
26
26
  // // TestService'i oluştur ve başlat
@@ -138,14 +138,25 @@ export class _ServiceManager {
138
138
  const usedService = {};
139
139
  if (Array.isArray(service.serviceInfo.requiredServices)) {
140
140
  for (const reqName of service.serviceInfo.requiredServices) {
141
- usedService[reqName] = () => { return this.getService(reqName); };
141
+ // Namespace-aware service lookup: önce namespace'li ara, yoksa global'e fallback
142
+ usedService[reqName] = () => {
143
+ if (namespace) {
144
+ const namespacedService = this.getService(`${namespace}:${reqName}`);
145
+ if (namespacedService)
146
+ return namespacedService;
147
+ }
148
+ return this.getService(reqName);
149
+ };
142
150
  }
143
151
  }
144
- const serviceInstance = this.setKey(tag, {
152
+ // Namespace varsa key'i namespace:tag formatında oluştur
153
+ const serviceKey = namespace ? `${namespace}:${tag}` : tag;
154
+ const serviceInstance = this.setKey(serviceKey, {
145
155
  serviceSelf: new service({
146
156
  usedService,
147
157
  tag: tag,
148
158
  type: type,
159
+ namespace: namespace,
149
160
  ServiceManager: _this,
150
161
  abilities: {
151
162
  createChildService: (tag, PageCtor) => {
@@ -231,15 +242,21 @@ export class _ServiceManager {
231
242
  // callback();
232
243
  // }
233
244
  // }
234
- getService(serviceName) {
235
- if (this.services[serviceName]) {
245
+ getService(serviceName, namespace) {
246
+ // Namespace verilmişse önce namespace:serviceName formatında ara
247
+ if (namespace) {
248
+ const namespacedKey = `${namespace}:${serviceName}`;
249
+ if (this.services[namespacedKey]) {
250
+ return this.services[namespacedKey].serviceSelf;
251
+ }
236
252
  }
237
- else {
238
- //console.log(`ServiceManager: Service ${serviceName} not found.`);
239
- //console.log("Available services:", Object.keys(this.services));
240
- return undefined;
253
+ // Fallback: direkt isimle ara (core servisler için)
254
+ if (this.services[serviceName]) {
255
+ return this.services[serviceName].serviceSelf;
241
256
  }
242
- return this.services[serviceName].serviceSelf;
257
+ //console.log(`ServiceManager: Service ${serviceName} not found.`);
258
+ //console.log("Available services:", Object.keys(this.services));
259
+ return undefined;
243
260
  }
244
261
  setKey(key, value) {
245
262
  this.services[key] = value;
@@ -4,8 +4,13 @@ export class ApiService extends Service {
4
4
  apis = {};
5
5
  onStart() {
6
6
  const requestHandlerService = this.ots.usedService.RequestHandlerService();
7
+ const namespace = this.ots.namespace;
7
8
  Object.entries(this.apis).forEach(([name, { handler, options }]) => {
8
- requestHandlerService.addHandler(`${this.tag}/${name}`, handler.bind(this), options || { auth: true, role: "guest" });
9
+ // Namespace varsa handler key'i namespace:ServiceName/method formatında oluştur
10
+ const handlerKey = namespace
11
+ ? `${namespace}:${this.tag}/${name}`
12
+ : `${this.tag}/${name}`;
13
+ requestHandlerService.addHandler(handlerKey, handler.bind(this), options || { auth: true, role: "guest" });
9
14
  });
10
15
  return Promise.resolve({ status: "success", message: "ApiService started" });
11
16
  }
@@ -38,7 +38,7 @@ export declare abstract class ProjectInfoService extends Service {
38
38
  getMenuPages(userGroup?: string): {
39
39
  [key: string]: ProjectsPages[string];
40
40
  };
41
- getMobilePages(limit?: number): {
41
+ getMobilePages(userGroup?: string, limit?: number): {
42
42
  [key: string]: ProjectsPages[string];
43
43
  };
44
44
  }
@@ -65,13 +65,30 @@ export class ProjectInfoService extends Service {
65
65
  });
66
66
  return result;
67
67
  }
68
- getMobilePages(limit = 4) {
68
+ getMobilePages(userGroup, limit = 4) {
69
69
  const result = {};
70
70
  let count = 0;
71
71
  for (const [key, page] of Object.entries(this.pages)) {
72
72
  if (page.showInMobile) {
73
- result[key] = page;
74
- count++;
73
+ // Apply the same group access control logic as getMenuPages
74
+ if (userGroup && userGroup == 'admin') {
75
+ // If onlyForGroup is true, admin cannot see this page
76
+ if (page.onlyForGroup !== true) {
77
+ result[key] = page;
78
+ count++;
79
+ }
80
+ }
81
+ else if (userGroup) {
82
+ // Check if the page is accessible by the user group
83
+ if (page.userGroup === userGroup) {
84
+ result[key] = page;
85
+ count++;
86
+ }
87
+ }
88
+ else {
89
+ result[key] = page;
90
+ count++;
91
+ }
75
92
  if (count >= limit)
76
93
  break;
77
94
  }
@@ -36,10 +36,11 @@ export declare class RequestHandlerService extends Service {
36
36
  auth?: boolean;
37
37
  role?: string;
38
38
  }): Promise<void>;
39
- requestCome({ params, request, url }: {
39
+ requestCome({ params, request, url, namespace }: {
40
40
  params: any;
41
41
  request: any;
42
42
  url: any;
43
+ namespace?: string;
43
44
  }): Promise<any>;
44
45
  getCookie(cookieHeader: string | null, name: string): string | undefined;
45
46
  resposeHandler(response: any): Response;
@@ -27,7 +27,7 @@ export class RequestHandlerService extends Service {
27
27
  this.handlers[name] = { callback, options };
28
28
  this.log.OK("RequestHandlerService addHandler", name);
29
29
  }
30
- async requestCome({ params, request, url }) {
30
+ async requestCome({ params, request, url, namespace }) {
31
31
  this.log.OK("RequestHandlerService requestCome", params);
32
32
  let bodyData = null;
33
33
  const contentType = request.headers.get('content-type');
@@ -49,9 +49,21 @@ export class RequestHandlerService extends Service {
49
49
  bodyData = null;
50
50
  }
51
51
  const handlerName = params.path; // Assuming path is the handler name
52
- const handler = this.handlers[handlerName];
52
+ // Namespace-aware handler lookup: önce namespace:handlerName ara, yoksa handlerName ara
53
+ let handler = null;
54
+ if (namespace) {
55
+ const namespacedKey = `${namespace}:${handlerName}`;
56
+ handler = this.handlers[namespacedKey];
57
+ if (handler) {
58
+ this.log.OK("RequestHandlerService found namespaced handler:", namespacedKey);
59
+ }
60
+ }
61
+ // Fallback: namespace'siz ara (core handlers için - login, logout, etc.)
62
+ if (!handler) {
63
+ handler = this.handlers[handlerName];
64
+ }
53
65
  if (!handler) {
54
- this.log.ERROR("Handler not found:", handlerName);
66
+ this.log.ERROR("Handler not found:", handlerName, "namespace:", namespace);
55
67
  //throw new Error(`Handler not found: ${handlerName}`);
56
68
  return { status: "error", message: "An error occurred" };
57
69
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@urga-panel/ur-panels-core",
3
- "version": "1.0.18",
3
+ "version": "1.0.20",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -34,7 +34,8 @@ export class _ServiceManager {
34
34
  // };
35
35
  // // LayoutService?: ServiceConstructor<LayoutPageService>;
36
36
  // }
37
- services: Array<RegisterServiceInfo>
37
+ services: Array<RegisterServiceInfo>,
38
+ namespace?: string
38
39
  ) {
39
40
  //debugger;
40
41
  console.log("ServiceManager: Initializing services...");
@@ -157,14 +158,24 @@ export class _ServiceManager {
157
158
  const usedService: { [key: string]: () => Service } = {};
158
159
  if (Array.isArray(service.serviceInfo.requiredServices)) {
159
160
  for (const reqName of service.serviceInfo.requiredServices) {
160
- usedService[reqName] = () => {return this.getService<Service>(reqName)}
161
+ // Namespace-aware service lookup: önce namespace'li ara, yoksa global'e fallback
162
+ usedService[reqName] = () => {
163
+ if (namespace) {
164
+ const namespacedService = this.getService<Service>(`${namespace}:${reqName}`);
165
+ if (namespacedService) return namespacedService;
166
+ }
167
+ return this.getService<Service>(reqName);
168
+ }
161
169
  }
162
170
  }
163
- const serviceInstance = this.setKey(tag, {
171
+ // Namespace varsa key'i namespace:tag formatında oluştur
172
+ const serviceKey = namespace ? `${namespace}:${tag}` : tag;
173
+ const serviceInstance = this.setKey(serviceKey, {
164
174
  serviceSelf: new service({
165
175
  usedService,
166
176
  tag: tag,
167
177
  type: type,
178
+ namespace: namespace,
168
179
  ServiceManager: _this,
169
180
  abilities: {
170
181
  createChildService: (tag: string, PageCtor?: ServiceConstructor<Service>) => {
@@ -253,16 +264,21 @@ export class _ServiceManager {
253
264
 
254
265
  // }
255
266
 
256
- public getService<T extends Service>(serviceName: string): T {
267
+ public getService<T extends Service>(serviceName: string, namespace?: string): T {
268
+ // Namespace verilmişse önce namespace:serviceName formatında ara
269
+ if (namespace) {
270
+ const namespacedKey = `${namespace}:${serviceName}`;
271
+ if (this.services[namespacedKey]) {
272
+ return this.services[namespacedKey].serviceSelf as T;
273
+ }
274
+ }
275
+ // Fallback: direkt isimle ara (core servisler için)
257
276
  if (this.services[serviceName]) {
258
- } else {
259
- //console.log(`ServiceManager: Service ${serviceName} not found.`);
260
- //console.log("Available services:", Object.keys(this.services));
261
- return undefined as T;
277
+ return this.services[serviceName].serviceSelf as T;
262
278
  }
263
-
264
- return this.services[serviceName].serviceSelf as T;
265
-
279
+ //console.log(`ServiceManager: Service ${serviceName} not found.`);
280
+ //console.log("Available services:", Object.keys(this.services));
281
+ return undefined as T;
266
282
  }
267
283
 
268
284
 
@@ -15,9 +15,15 @@ export abstract class ApiService extends Service {
15
15
  protected onStart(): Promise<ServiceResponse> {
16
16
 
17
17
  const requestHandlerService = this.ots.usedService.RequestHandlerService() as RequestHandlerService;
18
+ const namespace = this.ots.namespace as string | undefined;
19
+
18
20
  Object.entries(this.apis).forEach(([name, { handler, options }]) => {
21
+ // Namespace varsa handler key'i namespace:ServiceName/method formatında oluştur
22
+ const handlerKey = namespace
23
+ ? `${namespace}:${this.tag}/${name}`
24
+ : `${this.tag}/${name}`;
19
25
  requestHandlerService.addHandler(
20
- `${this.tag}/${name}`,
26
+ handlerKey,
21
27
  handler.bind(this),
22
28
  options || { auth: true, role: "guest" }
23
29
  );
@@ -107,13 +107,28 @@ export abstract class ProjectInfoService extends Service {
107
107
  return result;
108
108
  }
109
109
 
110
- getMobilePages(limit: number = 4): { [key: string]: ProjectsPages[string] } {
110
+ getMobilePages(userGroup?: string, limit: number = 4): { [key: string]: ProjectsPages[string] } {
111
111
  const result: { [key: string]: ProjectsPages[string] } = {};
112
112
  let count = 0;
113
113
  for (const [key, page] of Object.entries(this.pages)) {
114
114
  if (page.showInMobile) {
115
- result[key] = page;
116
- count++;
115
+ // Apply the same group access control logic as getMenuPages
116
+ if (userGroup && userGroup == 'admin') {
117
+ // If onlyForGroup is true, admin cannot see this page
118
+ if (page.onlyForGroup !== true) {
119
+ result[key] = page;
120
+ count++;
121
+ }
122
+ } else if (userGroup) {
123
+ // Check if the page is accessible by the user group
124
+ if (page.userGroup === userGroup) {
125
+ result[key] = page;
126
+ count++;
127
+ }
128
+ } else {
129
+ result[key] = page;
130
+ count++;
131
+ }
117
132
  if (count >= limit) break;
118
133
  }
119
134
  }
@@ -53,7 +53,7 @@ export class RequestHandlerService extends Service {
53
53
  this.log.OK("RequestHandlerService addHandler", name);
54
54
  }
55
55
 
56
- async requestCome({ params, request, url }): Promise<any> {
56
+ async requestCome({ params, request, url, namespace }: { params: any; request: any; url: any; namespace?: string }): Promise<any> {
57
57
  this.log.OK("RequestHandlerService requestCome", params);
58
58
 
59
59
  let bodyData: any = null;
@@ -75,9 +75,23 @@ export class RequestHandlerService extends Service {
75
75
  bodyData = null;
76
76
  }
77
77
  const handlerName = params.path; // Assuming path is the handler name
78
- const handler = this.handlers[handlerName];
78
+
79
+ // Namespace-aware handler lookup: önce namespace:handlerName ara, yoksa handlerName ara
80
+ let handler = null;
81
+ if (namespace) {
82
+ const namespacedKey = `${namespace}:${handlerName}`;
83
+ handler = this.handlers[namespacedKey];
84
+ if (handler) {
85
+ this.log.OK("RequestHandlerService found namespaced handler:", namespacedKey);
86
+ }
87
+ }
88
+ // Fallback: namespace'siz ara (core handlers için - login, logout, etc.)
89
+ if (!handler) {
90
+ handler = this.handlers[handlerName];
91
+ }
92
+
79
93
  if (!handler) {
80
- this.log.ERROR("Handler not found:", handlerName);
94
+ this.log.ERROR("Handler not found:", handlerName, "namespace:", namespace);
81
95
  //throw new Error(`Handler not found: ${handlerName}`);
82
96
  return { status: "error", message: "An error occurred" };
83
97
  }