@platform-mesh/portal-ui-lib 0.0.0 → 0.17.5

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,382 @@
1
+ import * as i0 from '@angular/core';
2
+ import { inject, Injectable, NgZone } from '@angular/core';
3
+ import { LuigiCoreService } from '@openmfp/portal-ui-lib';
4
+ import { ApolloLink, Observable, split, InMemoryCache } from '@apollo/client/core';
5
+ import { setContext } from '@apollo/client/link/context';
6
+ import { getMainDefinition } from '@apollo/client/utilities';
7
+ import { Apollo, gql } from 'apollo-angular';
8
+ import { HttpLink } from 'apollo-angular/http';
9
+ import { print } from 'graphql';
10
+ import { createClient } from 'graphql-sse';
11
+ import { getValueByPath, replaceDotsAndHyphensWithUnderscores, stripTypename } from '@platform-mesh/portal-ui-lib/utils';
12
+ import * as gqlBuilder from 'gql-query-builder';
13
+ import { EMPTY } from 'rxjs';
14
+ import { map, catchError } from 'rxjs/operators';
15
+
16
+ class GatewayService {
17
+ constructor() {
18
+ this.luigiCoreService = inject(LuigiCoreService);
19
+ }
20
+ getGatewayUrl(nodeContext, readFromParentKcpPath = false) {
21
+ const gatewayUrl = nodeContext.portalContext.crdGatewayApiUrl;
22
+ const currentKcpPath = this.getCurrentKcpPath(gatewayUrl);
23
+ return gatewayUrl?.replace(currentKcpPath, this.resolveKcpPath(nodeContext, readFromParentKcpPath));
24
+ }
25
+ updateCrdGatewayUrlWithEntityPath(kcpPath) {
26
+ const gatewayUrl = this.luigiCoreService.getGlobalContext().portalContext.crdGatewayApiUrl;
27
+ const kcpPathRegexp = /(.*\/)[^/]+(?=\/graphql$)/;
28
+ this.luigiCoreService.getGlobalContext().portalContext.crdGatewayApiUrl =
29
+ gatewayUrl.replace(kcpPathRegexp, `$1${kcpPath}`);
30
+ }
31
+ resolveKcpPath(nodeContext, readFromParentKcpPath = false) {
32
+ if (nodeContext.kcpPath) {
33
+ return nodeContext.kcpPath;
34
+ }
35
+ const gatewayUrl = nodeContext.portalContext.crdGatewayApiUrl;
36
+ const currentKcpPath = this.getCurrentKcpPath(gatewayUrl);
37
+ const lastIndex = currentKcpPath.lastIndexOf(':');
38
+ if (readFromParentKcpPath && lastIndex !== -1) {
39
+ return currentKcpPath.slice(0, lastIndex);
40
+ }
41
+ return currentKcpPath;
42
+ }
43
+ getCurrentKcpPath(gatewayUrl) {
44
+ const kcpPathRegexp = /\/([^\/]+)\/graphql$/;
45
+ const currentKcpPath = gatewayUrl.match(kcpPathRegexp)?.[1];
46
+ if (!currentKcpPath) {
47
+ this.luigiCoreService.showAlert({
48
+ text: 'Could not get current KCP path from gateway URL',
49
+ type: 'error',
50
+ });
51
+ return '';
52
+ }
53
+ return currentKcpPath;
54
+ }
55
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: GatewayService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
56
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: GatewayService, providedIn: 'root' }); }
57
+ }
58
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: GatewayService, decorators: [{
59
+ type: Injectable,
60
+ args: [{ providedIn: 'root' }]
61
+ }] });
62
+
63
+ class SSELink extends ApolloLink {
64
+ constructor(options) {
65
+ super();
66
+ this.client = createClient(options);
67
+ }
68
+ request(operation) {
69
+ return new Observable((sink) => {
70
+ return this.client.subscribe({ ...operation, query: print(operation.query) }, {
71
+ next: sink.next.bind(sink),
72
+ complete: sink.complete.bind(sink),
73
+ error: sink.error.bind(sink),
74
+ });
75
+ });
76
+ }
77
+ }
78
+ class ApolloFactory {
79
+ constructor() {
80
+ this.httpLink = inject(HttpLink);
81
+ this.ngZone = inject(NgZone);
82
+ this.gatewayService = inject(GatewayService);
83
+ this.apollo = (nodeContext, readFromParentKcpPath = false) => new Apollo(this.ngZone, this.createApolloOptions(nodeContext, readFromParentKcpPath));
84
+ }
85
+ createApolloOptions(nodeContext, readFromParentKcpPath = false) {
86
+ const contextLink = setContext(() => {
87
+ return {
88
+ uri: () => this.gatewayService.getGatewayUrl(nodeContext, readFromParentKcpPath),
89
+ headers: {
90
+ Authorization: `Bearer ${nodeContext.token}`,
91
+ Accept: 'charset=utf-8',
92
+ },
93
+ };
94
+ });
95
+ const splitClient = split(({ query }) => {
96
+ const definition = getMainDefinition(query);
97
+ return (definition.kind === 'OperationDefinition' &&
98
+ definition.operation === 'subscription');
99
+ }, new SSELink({
100
+ url: () => this.gatewayService.getGatewayUrl(nodeContext, readFromParentKcpPath),
101
+ headers: () => ({
102
+ Authorization: `Bearer ${nodeContext.token}`,
103
+ }),
104
+ }), this.httpLink.create({}));
105
+ const link = ApolloLink.from([contextLink, splitClient]);
106
+ const cache = new InMemoryCache();
107
+ return {
108
+ link,
109
+ cache,
110
+ };
111
+ }
112
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: ApolloFactory, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
113
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: ApolloFactory, providedIn: 'root' }); }
114
+ }
115
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: ApolloFactory, decorators: [{
116
+ type: Injectable,
117
+ args: [{
118
+ providedIn: 'root',
119
+ }]
120
+ }] });
121
+
122
+ class ResourceService {
123
+ constructor() {
124
+ this.apolloFactory = inject(ApolloFactory);
125
+ this.luigiCoreService = inject(LuigiCoreService);
126
+ }
127
+ read(resourceId, operation, kind, fieldsOrRawQuery, nodeContext, readFromParentKcpPath = true) {
128
+ const isNamespacedResource = this.isNamespacedResource(nodeContext);
129
+ let query = this.resolveReadQuery(fieldsOrRawQuery, kind, resourceId, isNamespacedResource ? nodeContext.namespaceId : undefined, operation);
130
+ try {
131
+ query = gql `
132
+ ${query}
133
+ `;
134
+ }
135
+ catch (error) {
136
+ this.luigiCoreService.showAlert({
137
+ text: `Could not read a resource: ${resourceId}. Wrong read query: <br/><br/> ${query}`,
138
+ type: 'error',
139
+ });
140
+ return EMPTY;
141
+ }
142
+ return this.apolloFactory
143
+ .apollo(nodeContext, readFromParentKcpPath)
144
+ .query({
145
+ query,
146
+ variables: {
147
+ name: resourceId,
148
+ ...(isNamespacedResource && {
149
+ namespace: nodeContext.namespaceId,
150
+ }),
151
+ },
152
+ })
153
+ .pipe(map((res) => res.data?.[operation]?.[kind]), catchError((error) => {
154
+ this.alertErrors(error);
155
+ console.error('Error executing GraphQL query.', error);
156
+ return error;
157
+ }));
158
+ }
159
+ resolveReadQuery(fieldsOrRawQuery, kind, resourceId, namespace, operation) {
160
+ if (fieldsOrRawQuery instanceof Array) {
161
+ return (gqlBuilder
162
+ .query({
163
+ operation: kind,
164
+ variables: {
165
+ name: { value: resourceId, type: 'String!' },
166
+ ...(namespace && {
167
+ namespace: { value: namespace, type: 'String' },
168
+ }),
169
+ },
170
+ fields: fieldsOrRawQuery,
171
+ })
172
+ .query.replace(kind, `${operation} { ${kind}`)
173
+ .trim() + '}');
174
+ }
175
+ else {
176
+ return fieldsOrRawQuery;
177
+ }
178
+ }
179
+ list(operation, fieldsOrRawQuery, nodeContext) {
180
+ const isNamespacedResource = this.isNamespacedResource(nodeContext);
181
+ const variables = {
182
+ ...(isNamespacedResource && {
183
+ namespace: { type: 'String', value: nodeContext.namespaceId },
184
+ }),
185
+ };
186
+ let query;
187
+ if (fieldsOrRawQuery instanceof Array) {
188
+ query = gqlBuilder.subscription({
189
+ operation,
190
+ fields: fieldsOrRawQuery,
191
+ variables: variables,
192
+ });
193
+ }
194
+ else {
195
+ query = {
196
+ variables: this.normalizeGqlBuilderVariables(variables),
197
+ query: fieldsOrRawQuery,
198
+ };
199
+ }
200
+ return this.apolloFactory
201
+ .apollo(nodeContext)
202
+ .subscribe({
203
+ query: gql `
204
+ ${query.query}
205
+ `,
206
+ variables: query.variables,
207
+ })
208
+ .pipe(map((res) => getValueByPath(res.data, operation) ?? []), catchError((error) => {
209
+ this.alertErrors(error);
210
+ console.error('Error executing GraphQL query.', error);
211
+ return error;
212
+ }));
213
+ }
214
+ alertErrors(res) {
215
+ this.luigiCoreService.showAlert({
216
+ text: res.message,
217
+ type: 'error',
218
+ });
219
+ }
220
+ delete(resource, resourceDefinition, nodeContext) {
221
+ const group = replaceDotsAndHyphensWithUnderscores(resourceDefinition.group);
222
+ const isNamespacedResource = this.isNamespacedResource(nodeContext);
223
+ const kind = resourceDefinition.kind;
224
+ const mutation = gqlBuilder.mutation({
225
+ operation: group,
226
+ fields: [
227
+ {
228
+ operation: `delete${kind}`,
229
+ variables: {
230
+ name: { type: 'String!', value: resource.metadata.name },
231
+ ...(isNamespacedResource && {
232
+ namespace: { type: 'String', value: nodeContext.namespaceId },
233
+ }),
234
+ },
235
+ fields: [],
236
+ },
237
+ ],
238
+ });
239
+ return this.apolloFactory
240
+ .apollo(nodeContext)
241
+ .mutate({
242
+ mutation: gql `
243
+ ${mutation.query}
244
+ `,
245
+ variables: mutation.variables,
246
+ })
247
+ .pipe(catchError((error) => {
248
+ this.alertErrors(error);
249
+ console.error('Error executing GraphQL query.', error);
250
+ return error;
251
+ }));
252
+ }
253
+ create(resource, resourceDefinition, nodeContext) {
254
+ const isNamespacedResource = this.isNamespacedResource(nodeContext);
255
+ const group = replaceDotsAndHyphensWithUnderscores(resourceDefinition.group);
256
+ const kind = resourceDefinition.kind;
257
+ const namespace = nodeContext.namespaceId;
258
+ const mutation = gqlBuilder.mutation({
259
+ operation: group,
260
+ fields: [
261
+ {
262
+ operation: `create${kind}`,
263
+ variables: {
264
+ ...(isNamespacedResource && {
265
+ namespace: { type: 'String', value: namespace },
266
+ }),
267
+ object: { type: `${kind}Input!`, value: resource },
268
+ },
269
+ fields: ['__typename'],
270
+ },
271
+ ],
272
+ });
273
+ return this.apolloFactory
274
+ .apollo(nodeContext)
275
+ .mutate({
276
+ mutation: gql `
277
+ ${mutation.query}
278
+ `,
279
+ fetchPolicy: 'no-cache',
280
+ variables: mutation.variables,
281
+ })
282
+ .pipe(catchError((error) => {
283
+ this.alertErrors(error);
284
+ console.error('Error executing GraphQL query.', error);
285
+ return error;
286
+ }));
287
+ }
288
+ update(resource, resourceDefinition, nodeContext) {
289
+ const isNamespacedResource = this.isNamespacedResource(nodeContext);
290
+ const group = replaceDotsAndHyphensWithUnderscores(resourceDefinition.group);
291
+ const kind = resourceDefinition.kind;
292
+ const namespace = nodeContext.namespaceId;
293
+ const cleanResource = stripTypename(resource);
294
+ const mutation = gqlBuilder.mutation({
295
+ operation: group,
296
+ fields: [
297
+ {
298
+ operation: `update${kind}`,
299
+ variables: {
300
+ ...(isNamespacedResource && {
301
+ namespace: { type: 'String', value: namespace },
302
+ }),
303
+ name: { type: 'String!', value: resource.metadata.name },
304
+ object: {
305
+ type: `${kind}Input!`,
306
+ value: cleanResource,
307
+ },
308
+ },
309
+ fields: ['__typename'],
310
+ },
311
+ ],
312
+ });
313
+ return this.apolloFactory
314
+ .apollo(nodeContext)
315
+ .mutate({
316
+ mutation: gql `
317
+ ${mutation.query}
318
+ `,
319
+ fetchPolicy: 'no-cache',
320
+ variables: mutation.variables,
321
+ })
322
+ .pipe(catchError((error) => {
323
+ this.alertErrors(error);
324
+ console.error('Error executing GraphQL query.', error);
325
+ return error;
326
+ }));
327
+ }
328
+ readAccountInfo(nodeContext) {
329
+ return this.apolloFactory
330
+ .apollo(nodeContext)
331
+ .query({
332
+ query: gql `
333
+ {
334
+ core_platform_mesh_io {
335
+ AccountInfo(name: "account") {
336
+ metadata {
337
+ name
338
+ annotations
339
+ }
340
+ spec {
341
+ clusterInfo {
342
+ ca
343
+ }
344
+ organization {
345
+ originClusterId
346
+ }
347
+ }
348
+ }
349
+ }
350
+ }
351
+ `,
352
+ })
353
+ .pipe(map((res) => {
354
+ return res.data.core_platform_mesh_io.AccountInfo;
355
+ }), catchError((error) => {
356
+ this.alertErrors(error);
357
+ console.error('Error executing GraphQL query.', error);
358
+ return error;
359
+ }));
360
+ }
361
+ isNamespacedResource(nodeContext) {
362
+ return nodeContext?.resourceDefinition?.scope === 'Namespaced';
363
+ }
364
+ normalizeGqlBuilderVariables(variables) {
365
+ return Object.fromEntries(Object.entries(variables).map(([key, value]) => [key, value.value]));
366
+ }
367
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: ResourceService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
368
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: ResourceService, providedIn: 'root' }); }
369
+ }
370
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: ResourceService, decorators: [{
371
+ type: Injectable,
372
+ args: [{
373
+ providedIn: 'root',
374
+ }]
375
+ }] });
376
+
377
+ /**
378
+ * Generated bundle index. Do not edit.
379
+ */
380
+
381
+ export { ApolloFactory, GatewayService, ResourceService };
382
+ //# sourceMappingURL=platform-mesh-portal-ui-lib-services.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platform-mesh-portal-ui-lib-services.mjs","sources":["../../projects/lib/services/resource/gateway.service.ts","../../projects/lib/services/resource/apollo-factory.ts","../../projects/lib/services/resource/resource.service.ts","../../projects/lib/services/platform-mesh-portal-ui-lib-services.ts"],"sourcesContent":["import { ResourceNodeContext } from './resource-node-context';\nimport { Injectable, inject } from '@angular/core';\nimport { LuigiCoreService } from '@openmfp/portal-ui-lib';\n\n\n@Injectable({ providedIn: 'root' })\nexport class GatewayService {\n private luigiCoreService = inject(LuigiCoreService);\n\n public getGatewayUrl(\n nodeContext: ResourceNodeContext,\n readFromParentKcpPath = false,\n ) {\n const gatewayUrl = nodeContext.portalContext.crdGatewayApiUrl;\n const currentKcpPath = this.getCurrentKcpPath(gatewayUrl);\n\n return gatewayUrl?.replace(\n currentKcpPath,\n this.resolveKcpPath(nodeContext, readFromParentKcpPath),\n );\n }\n\n public updateCrdGatewayUrlWithEntityPath(kcpPath: string) {\n const gatewayUrl =\n this.luigiCoreService.getGlobalContext().portalContext.crdGatewayApiUrl;\n const kcpPathRegexp = /(.*\\/)[^/]+(?=\\/graphql$)/;\n this.luigiCoreService.getGlobalContext().portalContext.crdGatewayApiUrl =\n gatewayUrl.replace(kcpPathRegexp, `$1${kcpPath}`);\n }\n\n public resolveKcpPath(\n nodeContext: ResourceNodeContext,\n readFromParentKcpPath = false,\n ) {\n if (nodeContext.kcpPath) {\n return nodeContext.kcpPath;\n }\n\n const gatewayUrl = nodeContext.portalContext.crdGatewayApiUrl;\n const currentKcpPath = this.getCurrentKcpPath(gatewayUrl);\n const lastIndex = currentKcpPath.lastIndexOf(':');\n\n if (readFromParentKcpPath && lastIndex !== -1) {\n return currentKcpPath.slice(0, lastIndex);\n }\n\n return currentKcpPath;\n }\n\n private getCurrentKcpPath(gatewayUrl: string): string {\n const kcpPathRegexp = /\\/([^\\/]+)\\/graphql$/;\n const currentKcpPath = gatewayUrl.match(kcpPathRegexp)?.[1];\n\n if (!currentKcpPath) {\n this.luigiCoreService.showAlert({\n text: 'Could not get current KCP path from gateway URL',\n type: 'error',\n });\n\n return '';\n }\n\n return currentKcpPath;\n }\n}\n","import { GatewayService } from './gateway.service';\nimport { ResourceNodeContext } from './resource-node-context';\nimport { Injectable, NgZone, inject } from '@angular/core';\nimport {\n type ApolloClientOptions,\n ApolloLink,\n Observable as ApolloObservable,\n FetchResult,\n InMemoryCache,\n Operation,\n split,\n} from '@apollo/client/core';\nimport { setContext } from '@apollo/client/link/context';\nimport { getMainDefinition } from '@apollo/client/utilities';\nimport { Apollo } from 'apollo-angular';\nimport { HttpLink } from 'apollo-angular/http';\nimport { print } from 'graphql';\nimport { Client, ClientOptions, createClient } from 'graphql-sse';\n\nclass SSELink extends ApolloLink {\n private client: Client;\n\n constructor(options: ClientOptions) {\n super();\n this.client = createClient(options);\n }\n\n public override request(operation: Operation): ApolloObservable<FetchResult> {\n return new ApolloObservable((sink) => {\n return this.client.subscribe(\n { ...operation, query: print(operation.query) },\n {\n next: sink.next.bind(sink),\n complete: sink.complete.bind(sink),\n error: sink.error.bind(sink),\n },\n );\n });\n }\n}\n\n@Injectable({\n providedIn: 'root',\n})\nexport class ApolloFactory {\n private httpLink = inject(HttpLink);\n private ngZone = inject(NgZone);\n private gatewayService = inject(GatewayService);\n\n public readonly apollo = (\n nodeContext: ResourceNodeContext,\n readFromParentKcpPath = false,\n ): Apollo =>\n new Apollo(\n this.ngZone,\n this.createApolloOptions(nodeContext, readFromParentKcpPath),\n );\n\n private createApolloOptions(\n nodeContext: ResourceNodeContext,\n readFromParentKcpPath = false,\n ): ApolloClientOptions<any> {\n const contextLink = setContext(() => {\n return {\n uri: () =>\n this.gatewayService.getGatewayUrl(nodeContext, readFromParentKcpPath),\n headers: {\n Authorization: `Bearer ${nodeContext.token}`,\n Accept: 'charset=utf-8',\n },\n };\n });\n\n const splitClient = split(\n ({ query }) => {\n const definition = getMainDefinition(query);\n return (\n definition.kind === 'OperationDefinition' &&\n definition.operation === 'subscription'\n );\n },\n new SSELink({\n url: () =>\n this.gatewayService.getGatewayUrl(nodeContext, readFromParentKcpPath),\n headers: () => ({\n Authorization: `Bearer ${nodeContext.token}`,\n }),\n }),\n this.httpLink.create({}),\n );\n\n const link = ApolloLink.from([contextLink, splitClient]);\n const cache = new InMemoryCache();\n\n return {\n link,\n cache,\n };\n }\n}\n","import { Injectable, inject } from '@angular/core';\nimport { TypedDocumentNode } from '@apollo/client/core';\nimport { LuigiCoreService } from '@openmfp/portal-ui-lib';\nimport {\n AccountInfo,\n Resource,\n ResourceDefinition,\n} from '@platform-mesh/portal-ui-lib/models';\nimport {\n getValueByPath,\n replaceDotsAndHyphensWithUnderscores,\n stripTypename,\n} from '@platform-mesh/portal-ui-lib/utils';\nimport { gql } from 'apollo-angular';\nimport * as gqlBuilder from 'gql-query-builder';\nimport { EMPTY, Observable } from 'rxjs';\nimport VariableOptions from 'gql-query-builder/build/VariableOptions';\nimport { catchError, map } from 'rxjs/operators';\nimport { ApolloFactory } from './apollo-factory';\nimport { ResourceNodeContext } from './resource-node-context';\n\ninterface ResourceResponseError extends Record<string, any> {\n message: string;\n}\n\n@Injectable({\n providedIn: 'root',\n})\nexport class ResourceService {\n private apolloFactory = inject(ApolloFactory);\n private luigiCoreService = inject(LuigiCoreService);\n\n read(\n resourceId: string,\n operation: string,\n kind: string,\n fieldsOrRawQuery: any[] | string,\n nodeContext: ResourceNodeContext,\n readFromParentKcpPath: boolean = true,\n ): Observable<Resource> {\n const isNamespacedResource = this.isNamespacedResource(nodeContext);\n let query: string | TypedDocumentNode<any, any> = this.resolveReadQuery(\n fieldsOrRawQuery,\n kind,\n resourceId,\n isNamespacedResource ? nodeContext.namespaceId : undefined,\n operation,\n );\n\n try {\n query = gql`\n ${query}\n `;\n } catch (error) {\n this.luigiCoreService.showAlert({\n text: `Could not read a resource: ${resourceId}. Wrong read query: <br/><br/> ${query}`,\n type: 'error',\n });\n return EMPTY;\n }\n\n return this.apolloFactory\n .apollo(nodeContext, readFromParentKcpPath)\n .query({\n query,\n variables: {\n name: resourceId,\n ...(isNamespacedResource && {\n namespace: nodeContext.namespaceId,\n }),\n },\n })\n .pipe(\n map((res) => res.data?.[operation]?.[kind]),\n catchError((error) => {\n this.alertErrors(error);\n console.error('Error executing GraphQL query.', error);\n return error;\n }),\n );\n }\n\n private resolveReadQuery(\n fieldsOrRawQuery: any[] | string,\n kind: string,\n resourceId: string,\n namespace: string | undefined,\n operation: string,\n ) {\n if (fieldsOrRawQuery instanceof Array) {\n return (\n gqlBuilder\n .query({\n operation: kind,\n variables: {\n name: { value: resourceId, type: 'String!' },\n ...(namespace && {\n namespace: { value: namespace, type: 'String' },\n }),\n },\n fields: fieldsOrRawQuery,\n })\n .query.replace(kind, `${operation} { ${kind}`)\n .trim() + '}'\n );\n } else {\n return fieldsOrRawQuery;\n }\n }\n\n list(\n operation: string,\n fieldsOrRawQuery: any[] | string,\n nodeContext: ResourceNodeContext,\n ): Observable<Resource[] | any> {\n const isNamespacedResource = this.isNamespacedResource(nodeContext);\n const variables = {\n ...(isNamespacedResource && {\n namespace: { type: 'String', value: nodeContext.namespaceId },\n }),\n };\n\n let query: { variables: any; query: string };\n\n if (fieldsOrRawQuery instanceof Array) {\n query = gqlBuilder.subscription({\n operation,\n fields: fieldsOrRawQuery,\n variables: variables,\n });\n } else {\n query = {\n variables: this.normalizeGqlBuilderVariables(variables),\n query: fieldsOrRawQuery,\n };\n }\n\n return this.apolloFactory\n .apollo(nodeContext)\n .subscribe({\n query: gql`\n ${query.query}\n `,\n variables: query.variables,\n })\n .pipe(\n map(\n (res: any): Resource[] =>\n getValueByPath<any, Resource[]>(res.data, operation) ?? [],\n ),\n catchError((error) => {\n this.alertErrors(error);\n console.error('Error executing GraphQL query.', error);\n return error;\n }),\n );\n }\n\n private alertErrors(res: ResourceResponseError) {\n this.luigiCoreService.showAlert({\n text: res.message,\n type: 'error',\n });\n }\n\n delete(\n resource: Resource,\n resourceDefinition: ResourceDefinition,\n nodeContext: ResourceNodeContext,\n ) {\n const group = replaceDotsAndHyphensWithUnderscores(\n resourceDefinition.group,\n );\n const isNamespacedResource = this.isNamespacedResource(nodeContext);\n const kind = resourceDefinition.kind;\n\n const mutation = gqlBuilder.mutation({\n operation: group,\n fields: [\n {\n operation: `delete${kind}`,\n variables: {\n name: { type: 'String!', value: resource.metadata.name },\n ...(isNamespacedResource && {\n namespace: { type: 'String', value: nodeContext.namespaceId },\n }),\n },\n fields: [],\n },\n ],\n });\n\n return this.apolloFactory\n .apollo(nodeContext)\n .mutate<void>({\n mutation: gql`\n ${mutation.query}\n `,\n variables: mutation.variables,\n })\n .pipe(\n catchError((error) => {\n this.alertErrors(error);\n console.error('Error executing GraphQL query.', error);\n return error;\n }),\n );\n }\n\n create(\n resource: Resource,\n resourceDefinition: ResourceDefinition,\n nodeContext: ResourceNodeContext,\n ) {\n const isNamespacedResource = this.isNamespacedResource(nodeContext);\n const group = replaceDotsAndHyphensWithUnderscores(\n resourceDefinition.group,\n );\n const kind = resourceDefinition.kind;\n const namespace = nodeContext.namespaceId;\n\n const mutation = gqlBuilder.mutation({\n operation: group,\n fields: [\n {\n operation: `create${kind}`,\n variables: {\n ...(isNamespacedResource && {\n namespace: { type: 'String', value: namespace },\n }),\n object: { type: `${kind}Input!`, value: resource },\n },\n fields: ['__typename'],\n },\n ],\n });\n\n return this.apolloFactory\n .apollo(nodeContext)\n .mutate({\n mutation: gql`\n ${mutation.query}\n `,\n fetchPolicy: 'no-cache',\n variables: mutation.variables,\n })\n .pipe(\n catchError((error) => {\n this.alertErrors(error);\n console.error('Error executing GraphQL query.', error);\n return error;\n }),\n );\n }\n\n update(\n resource: Resource,\n resourceDefinition: ResourceDefinition,\n nodeContext: ResourceNodeContext,\n ) {\n const isNamespacedResource = this.isNamespacedResource(nodeContext);\n const group = replaceDotsAndHyphensWithUnderscores(\n resourceDefinition.group,\n );\n const kind = resourceDefinition.kind;\n const namespace = nodeContext.namespaceId;\n\n const cleanResource = stripTypename(resource);\n\n const mutation = gqlBuilder.mutation({\n operation: group,\n fields: [\n {\n operation: `update${kind}`,\n variables: {\n ...(isNamespacedResource && {\n namespace: { type: 'String', value: namespace },\n }),\n name: { type: 'String!', value: resource.metadata.name },\n object: {\n type: `${kind}Input!`,\n value: cleanResource,\n },\n },\n fields: ['__typename'],\n },\n ],\n });\n\n return this.apolloFactory\n .apollo(nodeContext)\n .mutate({\n mutation: gql`\n ${mutation.query}\n `,\n fetchPolicy: 'no-cache',\n variables: mutation.variables,\n })\n .pipe(\n catchError((error) => {\n this.alertErrors(error);\n console.error('Error executing GraphQL query.', error);\n return error;\n }),\n );\n }\n\n readAccountInfo(nodeContext: ResourceNodeContext): Observable<AccountInfo> {\n return this.apolloFactory\n .apollo(nodeContext)\n .query<string>({\n query: gql`\n {\n core_platform_mesh_io {\n AccountInfo(name: \"account\") {\n metadata {\n name\n annotations\n }\n spec {\n clusterInfo {\n ca\n }\n organization {\n originClusterId\n }\n }\n }\n }\n }\n `,\n })\n .pipe(\n map((res: any) => {\n return res.data.core_platform_mesh_io.AccountInfo;\n }),\n catchError((error) => {\n this.alertErrors(error);\n console.error('Error executing GraphQL query.', error);\n return error;\n }),\n );\n }\n\n private isNamespacedResource(nodeContext: ResourceNodeContext) {\n return nodeContext?.resourceDefinition?.scope === 'Namespaced';\n }\n\n private normalizeGqlBuilderVariables(\n variables: VariableOptions,\n ): Record<string, any> {\n return Object.fromEntries(\n Object.entries(variables).map(([key, value]) => [key, value.value]),\n );\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":["ApolloObservable"],"mappings":";;;;;;;;;;;;;;;MAMa,cAAc,CAAA;AAD3B,IAAA,WAAA,GAAA;AAEU,QAAA,IAAA,CAAA,gBAAgB,GAAG,MAAM,CAAC,gBAAgB,CAAC;AAyDpD,IAAA;AAvDQ,IAAA,aAAa,CAClB,WAAgC,EAChC,qBAAqB,GAAG,KAAK,EAAA;AAE7B,QAAA,MAAM,UAAU,GAAG,WAAW,CAAC,aAAa,CAAC,gBAAgB;QAC7D,MAAM,cAAc,GAAG,IAAI,CAAC,iBAAiB,CAAC,UAAU,CAAC;AAEzD,QAAA,OAAO,UAAU,EAAE,OAAO,CACxB,cAAc,EACd,IAAI,CAAC,cAAc,CAAC,WAAW,EAAE,qBAAqB,CAAC,CACxD;IACH;AAEO,IAAA,iCAAiC,CAAC,OAAe,EAAA;AACtD,QAAA,MAAM,UAAU,GACd,IAAI,CAAC,gBAAgB,CAAC,gBAAgB,EAAE,CAAC,aAAa,CAAC,gBAAgB;QACzE,MAAM,aAAa,GAAG,2BAA2B;QACjD,IAAI,CAAC,gBAAgB,CAAC,gBAAgB,EAAE,CAAC,aAAa,CAAC,gBAAgB;YACrE,UAAU,CAA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CAAA,CAAA;;2FAEP,eAAe,EAAA,UAAA,EAAA,CAAA;kBAH3B,UAAU;AAAC,YAAA,IAAA,EAAA,CAAA;AACV,oBAAA,UAAU,EAAE,MAAM;AACnB,iBAAA;;;AC3BD;;AAEG;;;;"}
@@ -0,0 +1,88 @@
1
+ import jsonpath from 'jsonpath';
2
+
3
+ const generateGraphQLFields = (uiFields) => {
4
+ const graphQLFields = [];
5
+ uiFields.map((field) => {
6
+ if (field.property instanceof Array) {
7
+ field.property.map((property) => generate(property, graphQLFields));
8
+ }
9
+ else {
10
+ generate(field.property, graphQLFields);
11
+ }
12
+ });
13
+ return graphQLFields;
14
+ };
15
+ const generate = (root, fields = []) => {
16
+ if (!root) {
17
+ return [];
18
+ }
19
+ const paths = root.split('.');
20
+ for (const part of paths) {
21
+ if (paths.length === 1) {
22
+ fields.push(part);
23
+ return fields;
24
+ }
25
+ fields.push({
26
+ [part]: [...generate(paths.splice(1).join('.'))],
27
+ });
28
+ return fields;
29
+ }
30
+ };
31
+
32
+ const getResourceValueByJsonPath = (resource, field) => {
33
+ const property = field.jsonPathExpression || field.property;
34
+ if (!property) {
35
+ return undefined;
36
+ }
37
+ if (property instanceof Array) {
38
+ console.error(`Property defined as an array: ${JSON.stringify(property)}, provide "jsonPathExpression" field to properly ready resource value`);
39
+ return undefined;
40
+ }
41
+ const value = jsonpath.query(resource, `$.${property}`);
42
+ return value.length ? value[0] : undefined;
43
+ };
44
+
45
+ const getValueByPath = (obj, path) => {
46
+ return getResourceValueByJsonPath(obj, {
47
+ jsonPathExpression: path,
48
+ property: '',
49
+ });
50
+ };
51
+
52
+ /**
53
+ * Utility function to replace all occurrences of dots (.) and hyphens (-) with underscores (_)
54
+ * @param input - The input string to process
55
+ * @returns The processed string with dots and hyphens replaced by underscores
56
+ */
57
+ function replaceDotsAndHyphensWithUnderscores(input) {
58
+ if (!input) {
59
+ return input;
60
+ }
61
+ return input.replace(/[.-]/g, '_');
62
+ }
63
+
64
+ const isLocalSetup = () => {
65
+ return window.location.hostname.includes('localhost') || window.location.hostname.includes('portal.dev.local');
66
+ };
67
+
68
+ function stripTypename(value) {
69
+ if (Array.isArray(value)) {
70
+ return value.map((v) => stripTypename(v));
71
+ }
72
+ if (value && typeof value === 'object') {
73
+ const { __typename, ...rest } = value;
74
+ for (const k of Object.keys(rest)) {
75
+ // @ts-ignore - rest is an indexable object
76
+ rest[k] = stripTypename(rest[k]);
77
+ }
78
+ return rest;
79
+ }
80
+ return value;
81
+ }
82
+
83
+ /**
84
+ * Generated bundle index. Do not edit.
85
+ */
86
+
87
+ export { generateGraphQLFields, getResourceValueByJsonPath, getValueByPath, isLocalSetup, replaceDotsAndHyphensWithUnderscores, stripTypename };
88
+ //# sourceMappingURL=platform-mesh-portal-ui-lib-utils.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platform-mesh-portal-ui-lib-utils.mjs","sources":["../../projects/lib/utils/utils/columns-to-gql-fields.ts","../../projects/lib/utils/utils/resource-field-by-path.ts","../../projects/lib/utils/utils/get-value-by-path.ts","../../projects/lib/utils/utils/group-name-sanitizer.ts","../../projects/lib/utils/utils/is-local-setup.ts","../../projects/lib/utils/utils/resource-sanitizer.ts","../../projects/lib/utils/platform-mesh-portal-ui-lib-utils.ts"],"sourcesContent":["import { FieldDefinition } from '@platform-mesh/portal-ui-lib/models';\n\nexport const generateGraphQLFields = (uiFields: FieldDefinition[]): any[] => {\n const graphQLFields = [];\n uiFields.map((field) => {\n if (field.property instanceof Array) {\n field.property.map((property) => generate(property, graphQLFields));\n } else {\n generate(field.property, graphQLFields);\n }\n });\n return graphQLFields;\n};\n\nconst generate = (root: string, fields: any = []) => {\n if (!root) {\n return [];\n }\n\n const paths = root.split('.');\n\n for (const part of paths) {\n if (paths.length === 1) {\n fields.push(part);\n return fields;\n }\n\n fields.push({\n [part]: [...generate(paths.splice(1).join('.'))],\n });\n\n return fields;\n }\n};\n","import { Resource } from '@platform-mesh/portal-ui-lib/models';\nimport jsonpath from 'jsonpath';\n\nexport const getResourceValueByJsonPath = (\n resource: Resource,\n field: { jsonPathExpression?: string; property?: string | string[] },\n) => {\n const property = field.jsonPathExpression || field.property;\n if (!property) {\n return undefined;\n }\n\n if (property instanceof Array) {\n console.error(\n `Property defined as an array: ${JSON.stringify(property)}, provide \"jsonPathExpression\" field to properly ready resource value`,\n );\n return undefined;\n }\n\n const value = jsonpath.query(resource, `$.${property}`);\n return value.length ? value[0] : undefined;\n};\n","import { getResourceValueByJsonPath } from './resource-field-by-path';\nimport { Resource } from '@platform-mesh/portal-ui-lib/models';\n\nexport const getValueByPath = <T extends object, R = unknown>(\n obj: T,\n path: string,\n): R | undefined => {\n return getResourceValueByJsonPath(obj as Resource, {\n jsonPathExpression: path,\n property: '',\n });\n};\n","/**\n * Utility function to replace all occurrences of dots (.) and hyphens (-) with underscores (_)\n * @param input - The input string to process\n * @returns The processed string with dots and hyphens replaced by underscores\n */\nexport function replaceDotsAndHyphensWithUnderscores(input: string): string {\n if (!input) {\n return input;\n }\n\n return input.replace(/[.-]/g, '_');\n}\n","export const isLocalSetup = () => {\n return window.location.hostname.includes('localhost') || window.location.hostname.includes('portal.dev.local');\n};\n","export function stripTypename<T>(value: T): T {\n if (Array.isArray(value)) {\n return (value as unknown as any[]).map((v) => stripTypename(v)) as T;\n }\n if (value && typeof value === 'object') {\n const { __typename, ...rest } = value as Record<string, unknown> & {\n __typename?: string;\n };\n for (const k of Object.keys(rest)) {\n // @ts-ignore - rest is an indexable object\n rest[k] = stripTypename((rest as any)[k]);\n }\n return rest as T;\n }\n return value;\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;AAEO,MAAM,qBAAqB,GAAG,CAAC,QAA2B,KAAW;IAC1E,MAAM,aAAa,GAAG,EAAE;AACxB,IAAA,QAAQ,CAAC,GAAG,CAAC,CAAC,KAAK,KAAI;AACrB,QAAA,IAAI,KAAK,CAAC,QAAQ,YAAY,KAAK,EAAE;AACnC,YAAA,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d;;ACfA;;AAEG;;;;"}
@@ -0,0 +1,11 @@
1
+ /*
2
+ * Public API Surface of lib
3
+ */
4
+ const EMPTY_PACKAGE = true;
5
+
6
+ /**
7
+ * Generated bundle index. Do not edit.
8
+ */
9
+
10
+ export { EMPTY_PACKAGE };
11
+ //# sourceMappingURL=platform-mesh-portal-ui-lib.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platform-mesh-portal-ui-lib.mjs","sources":["../../projects/lib/public-api.ts","../../projects/lib/platform-mesh-portal-ui-lib.ts"],"sourcesContent":["/*\n * Public API Surface of lib\n */\nexport const EMPTY_PACKAGE = true;\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":"AAAA;;AAEG;AACI,MAAM,aAAa,GAAG;;ACH7B;;AAEG;;;;"}
package/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ declare const EMPTY_PACKAGE = true;
2
+
3
+ export { EMPTY_PACKAGE };
@@ -0,0 +1,82 @@
1
+ import { Condition, ObjectMeta } from 'kubernetes-types/meta/v1';
2
+
3
+ interface LabelDisplay {
4
+ backgroundColor?: string;
5
+ color?: string;
6
+ fontWeight?: string;
7
+ fontStyle?: string;
8
+ textDecoration?: string;
9
+ textTransform?: string;
10
+ }
11
+ interface FieldDefinition {
12
+ label?: string;
13
+ property: string | string[];
14
+ jsonPathExpression?: string;
15
+ required?: boolean;
16
+ values?: string[];
17
+ group?: {
18
+ name: string;
19
+ label?: string;
20
+ delimiter?: string;
21
+ multiline?: boolean;
22
+ };
23
+ labelDisplay?: LabelDisplay | boolean;
24
+ displayAsPlainText?: boolean;
25
+ dynamicValuesDefinition?: {
26
+ operation: string;
27
+ gqlQuery: string;
28
+ value: string;
29
+ key: string;
30
+ };
31
+ }
32
+ interface ResourceStatus {
33
+ conditions: Condition[];
34
+ }
35
+ interface ResourceSpec extends Record<string, any> {
36
+ type: string;
37
+ description?: string;
38
+ displayName?: string;
39
+ }
40
+ interface AccountInfo {
41
+ metadata: ObjectMeta;
42
+ spec: {
43
+ clusterInfo: {
44
+ ca: string;
45
+ };
46
+ organization: {
47
+ originClusterId: string;
48
+ };
49
+ };
50
+ }
51
+ interface Resource extends Record<string, any> {
52
+ metadata: ObjectMeta;
53
+ spec?: ResourceSpec;
54
+ status?: ResourceStatus;
55
+ __typename?: string;
56
+ ready?: boolean;
57
+ }
58
+ interface ResourceDefinition {
59
+ group: string;
60
+ plural: string;
61
+ singular: string;
62
+ kind: string;
63
+ scope?: KubernetesScope;
64
+ namespace?: string;
65
+ readyCondition?: {
66
+ jsonPathExpression: string;
67
+ property: string | string[];
68
+ };
69
+ ui?: UIDefinition;
70
+ }
71
+ interface UiView {
72
+ fields: FieldDefinition[];
73
+ }
74
+ interface UIDefinition {
75
+ logoUrl?: string;
76
+ listView?: UiView;
77
+ createView?: UiView;
78
+ detailView?: UiView;
79
+ }
80
+ type KubernetesScope = 'Cluster' | 'Namespaced';
81
+
82
+ export type { AccountInfo, FieldDefinition, KubernetesScope, LabelDisplay, Resource, ResourceDefinition, ResourceSpec, ResourceStatus, UIDefinition };
@@ -0,0 +1,3 @@
1
+ {
2
+ "module": "../fesm2022/platform-mesh-portal-ui-lib-models.mjs"
3
+ }