teraprox-core-sdk 0.3.3 → 0.3.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.
- package/dist/{chunk-CLNYFYWU.mjs → chunk-JK654W4P.mjs} +23 -4
- package/dist/{federation-UNcGnNB-.d.mts → federation-Bhx0XhSP.d.mts} +47 -1
- package/dist/{federation-UNcGnNB-.d.ts → federation-Bhx0XhSP.d.ts} +47 -1
- package/dist/federation.d.mts +1 -1
- package/dist/federation.d.ts +1 -1
- package/dist/federation.js +24 -4
- package/dist/federation.mjs +1 -1
- package/dist/index.d.mts +169 -3
- package/dist/index.d.ts +169 -3
- package/dist/index.js +364 -7
- package/dist/index.mjs +332 -4
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as CoreService, H as HttpController,
|
|
2
|
-
export { D as DevAutoLogin, F as FederatedBridge, M as MatchingObjectSubscription, R as ReducersBundle,
|
|
1
|
+
import { C as CoreService, T as ToastService, I as IObservabilityPort, H as HttpController, a as InteractionPayload, V as VitalsPayload, B as BreadcrumbPayload } from './federation-Bhx0XhSP.js';
|
|
2
|
+
export { D as DevAutoLogin, F as FederatedBridge, M as MatchingObjectSubscription, R as ReducersBundle, b as ReducersBundleConfig, c as RemoteManifest, d as RemoteMenuItem, e as RemoteMenuSection, S as StandaloneProvider, f as ToastOptions, g as createReducersBundle } from './federation-Bhx0XhSP.js';
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
import { Dispatch } from 'react';
|
|
5
5
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
@@ -34,8 +34,134 @@ interface NavigationConfig {
|
|
|
34
34
|
}
|
|
35
35
|
type NavigateFn = (path: string | number, config?: NavigationConfig, pageName?: string) => void;
|
|
36
36
|
|
|
37
|
+
type StatusSolicitacao = 'PENDENTE' | 'APROVADO' | 'REPROVADO' | 'CANCELADO' | 'EM_EXECUCAO';
|
|
38
|
+
interface SolicitacaoDeServico {
|
|
39
|
+
id: string | number;
|
|
40
|
+
status: StatusSolicitacao;
|
|
41
|
+
dataDeAbertura: string;
|
|
42
|
+
descricaoDoProblema: string;
|
|
43
|
+
solicitante: {
|
|
44
|
+
id: string | number;
|
|
45
|
+
nome: string;
|
|
46
|
+
};
|
|
47
|
+
recurso?: {
|
|
48
|
+
id: string | number;
|
|
49
|
+
nome: string;
|
|
50
|
+
};
|
|
51
|
+
recursoNome?: string;
|
|
52
|
+
prioridade?: 'BAIXA' | 'MEDIA' | 'ALTA' | 'URGENTE';
|
|
53
|
+
setor?: string;
|
|
54
|
+
equipamento?: string;
|
|
55
|
+
}
|
|
56
|
+
|
|
37
57
|
declare const CoreServiceContext: React.Context<CoreService | null>;
|
|
38
58
|
|
|
59
|
+
declare class FetchHttpAdapter implements HttpController {
|
|
60
|
+
private endpoint;
|
|
61
|
+
constructor(endpoint: string);
|
|
62
|
+
private request;
|
|
63
|
+
get(path?: string): Promise<any>;
|
|
64
|
+
post(path?: string, data?: any): Promise<any>;
|
|
65
|
+
put(path?: string, data?: any): Promise<any>;
|
|
66
|
+
patch(path?: string, data?: any): Promise<any>;
|
|
67
|
+
delete(path?: string, id?: string | number): Promise<any>;
|
|
68
|
+
deleteSimple(path?: string): Promise<any>;
|
|
69
|
+
save(path?: string, data?: any): Promise<any>;
|
|
70
|
+
read(path?: string, id?: string | number): Promise<any>;
|
|
71
|
+
readAll(path?: string): Promise<any>;
|
|
72
|
+
readAllwithPage(path?: string): Promise<any>;
|
|
73
|
+
bulkDelete(path?: string): Promise<any>;
|
|
74
|
+
}
|
|
75
|
+
declare class CoreServiceBuilder {
|
|
76
|
+
private _toast;
|
|
77
|
+
private _httpEndpoint?;
|
|
78
|
+
private _rtdbConfig?;
|
|
79
|
+
private _hostedByCore;
|
|
80
|
+
private _observability;
|
|
81
|
+
private _tracing;
|
|
82
|
+
withToast(toast: ToastService): this;
|
|
83
|
+
withHttpEndpoint(url: string): this;
|
|
84
|
+
withRtdbConfig(config: any): this;
|
|
85
|
+
setHostedByCore(hosted: boolean): this;
|
|
86
|
+
withObservability(observability: IObservabilityPort): this;
|
|
87
|
+
/**
|
|
88
|
+
* Ativa Distributed Tracing W3C nos controllers HTTP.
|
|
89
|
+
* Quando habilitado, `createController` retorna `TracingHttpAdapter` em vez de `FetchHttpAdapter`.
|
|
90
|
+
* O header `traceparent` é injetado em todas as requisições automaticamente.
|
|
91
|
+
*/
|
|
92
|
+
withTracing(enabled?: boolean): this;
|
|
93
|
+
build(): CoreService;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
declare class NullToastService implements ToastService {
|
|
97
|
+
success(message: string): void;
|
|
98
|
+
warning(message: string): void;
|
|
99
|
+
error(message: string): void;
|
|
100
|
+
info(message: string): void;
|
|
101
|
+
}
|
|
102
|
+
declare class NullHttpController implements HttpController {
|
|
103
|
+
private logAndResolve;
|
|
104
|
+
get(path?: string): Promise<never[]>;
|
|
105
|
+
post(path?: string): Promise<never[]>;
|
|
106
|
+
put(path?: string): Promise<never[]>;
|
|
107
|
+
patch(path?: string): Promise<never[]>;
|
|
108
|
+
delete(path?: string, id?: string | number): Promise<never[]>;
|
|
109
|
+
deleteSimple(path?: string): Promise<never[]>;
|
|
110
|
+
save(path?: string): Promise<never[]>;
|
|
111
|
+
read(path?: string, id?: string | number): Promise<never[]>;
|
|
112
|
+
readAll(path?: string): Promise<never[]>;
|
|
113
|
+
readAllwithPage(path?: string): Promise<never[]>;
|
|
114
|
+
bulkDelete(path?: string): Promise<never[]>;
|
|
115
|
+
}
|
|
116
|
+
declare const NullCoreService: CoreService;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Null Object Pattern — implementação fallback de `IObservabilityPort`.
|
|
120
|
+
* Apenas loga no console; substitua pela implementação real (Datadog/Sentry/Grafana)
|
|
121
|
+
* via `CoreServiceBuilder.withObservability()` no host.
|
|
122
|
+
*/
|
|
123
|
+
declare class NullObservabilityAdapter implements IObservabilityPort {
|
|
124
|
+
trackInteraction(payload: InteractionPayload): void;
|
|
125
|
+
captureVitals(payload: VitalsPayload): void;
|
|
126
|
+
logBreadcrumb(payload: BreadcrumbPayload): void;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Decorator de HTTP que implementa Distributed Tracing via W3C TraceContext.
|
|
131
|
+
*
|
|
132
|
+
* - Gera um `trace-id` único por instância (cobre todos os spans de um contexto/controller).
|
|
133
|
+
* - Gera um `span-id` único por requisição HTTP.
|
|
134
|
+
* - Injeta o header `traceparent` em todas as chamadas: GET, POST, PUT, PATCH, DELETE, etc.
|
|
135
|
+
* - Mesclado com quaisquer `extraHeaders` já presentes na chamada.
|
|
136
|
+
*
|
|
137
|
+
* Uso via CoreServiceBuilder:
|
|
138
|
+
* ```ts
|
|
139
|
+
* new CoreServiceBuilder()
|
|
140
|
+
* .withHttpEndpoint(process.env.REACT_APP_END_POINT)
|
|
141
|
+
* .withTracing()
|
|
142
|
+
* .build()
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
declare class TracingHttpAdapter implements HttpController {
|
|
146
|
+
private readonly endpoint;
|
|
147
|
+
/** Identificador único desta cadeia de spans — compartilhado por todas as reqs do controller. */
|
|
148
|
+
private readonly traceId;
|
|
149
|
+
constructor(endpoint: string);
|
|
150
|
+
private mergeHeaders;
|
|
151
|
+
private request;
|
|
152
|
+
get(path?: string): Promise<any>;
|
|
153
|
+
post(path?: string, data?: any, extraHeaders?: Record<string, string>): Promise<any>;
|
|
154
|
+
put(path?: string, data?: any, extraHeaders?: Record<string, string>): Promise<any>;
|
|
155
|
+
patch(path?: string, data?: any, extraHeaders?: Record<string, string>): Promise<any>;
|
|
156
|
+
delete(path?: string, id?: string | number, extraHeaders?: Record<string, string>): Promise<any>;
|
|
157
|
+
deleteSimple(path?: string, extraHeaders?: Record<string, string>): Promise<any>;
|
|
158
|
+
save(path?: string, data?: any, extraHeaders?: Record<string, string>): Promise<any>;
|
|
159
|
+
read(path?: string, id?: string | number, extraHeaders?: Record<string, string>): Promise<any>;
|
|
160
|
+
readAll(path?: string, extraHeaders?: Record<string, string>): Promise<any>;
|
|
161
|
+
readAllwithPage(path?: string): Promise<any>;
|
|
162
|
+
bulkDelete(path?: string, ids?: (string | number)[], extraHeaders?: Record<string, string>): Promise<any>;
|
|
163
|
+
}
|
|
164
|
+
|
|
39
165
|
declare function useCoreService(): CoreService;
|
|
40
166
|
|
|
41
167
|
declare function useHttpController(context: string, baseEndPoint?: string): HttpController;
|
|
@@ -80,6 +206,16 @@ interface NavigatorConfig {
|
|
|
80
206
|
*/
|
|
81
207
|
declare function useNavigator(config: NavigatorConfig): NavigateFn;
|
|
82
208
|
|
|
209
|
+
/**
|
|
210
|
+
* Atalho para acessar o Port de observabilidade via React context.
|
|
211
|
+
* Retorna a implementação real (quando fornecida pelo host) ou o NullObservabilityAdapter.
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
* const obs = useObservability()
|
|
215
|
+
* obs.logBreadcrumb({ category: 'action', message: 'Solicitação aprovada', data: { id } })
|
|
216
|
+
*/
|
|
217
|
+
declare function useObservability(): IObservabilityPort;
|
|
218
|
+
|
|
83
219
|
interface FetchDataReturn<T = any> {
|
|
84
220
|
data: T | null;
|
|
85
221
|
loading: boolean;
|
|
@@ -198,6 +334,36 @@ declare const _default: redux.Reducer<PickerState>;
|
|
|
198
334
|
|
|
199
335
|
declare function pickTextColorBasedOnBgColorAdvanced(bgColor: string, lightColor: string, darkColor: string): string;
|
|
200
336
|
|
|
337
|
+
/**
|
|
338
|
+
* Instala PerformanceObserver para LCP e CLS automaticamente no bootstrap do módulo.
|
|
339
|
+
* Fallback silencioso em ambientes que não suportam a API (Node, browsers antigos).
|
|
340
|
+
*
|
|
341
|
+
* @param observability - Implementação de IObservabilityPort para receber as métricas.
|
|
342
|
+
*/
|
|
343
|
+
declare function initWebVitals(observability: IObservabilityPort): void;
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Utilitários de Distributed Tracing seguindo a especificação W3C TraceContext.
|
|
347
|
+
* https://www.w3.org/TR/trace-context/
|
|
348
|
+
*/
|
|
349
|
+
/**
|
|
350
|
+
* Gera um trace-id de 128 bits (32 chars hex) conforme W3C TraceContext.
|
|
351
|
+
* Usado uma vez por instância de adapter — identifica toda a cadeia de spans de um contexto.
|
|
352
|
+
*/
|
|
353
|
+
declare function generateTraceId(): string;
|
|
354
|
+
/**
|
|
355
|
+
* Gera um span-id de 64 bits (16 chars hex) conforme W3C TraceContext.
|
|
356
|
+
* Chamado a cada requisição HTTP — identifica um span individual.
|
|
357
|
+
*/
|
|
358
|
+
declare function generateSpanId(): string;
|
|
359
|
+
/**
|
|
360
|
+
* Monta o header `traceparent` no formato W3C:
|
|
361
|
+
* `{version}-{traceId}-{spanId}-{flags}`
|
|
362
|
+
*
|
|
363
|
+
* Flags: `01` = sampled (enviado ao coletor), `00` = não-amostrado.
|
|
364
|
+
*/
|
|
365
|
+
declare function buildTraceparent(traceId: string, spanId: string, sampled?: boolean): string;
|
|
366
|
+
|
|
201
367
|
/**
|
|
202
368
|
* Formats a date for display in Brazilian format.
|
|
203
369
|
* Corresponds to the duplicated dateUtils.js in SGM/SGP/Services/default/.
|
|
@@ -219,4 +385,4 @@ declare function removeAccents(str: string): string;
|
|
|
219
385
|
declare function slugify(str: string): string;
|
|
220
386
|
declare function isBlank(str: string | null | undefined): boolean;
|
|
221
387
|
|
|
222
|
-
export { CoreService, CoreServiceContext, HttpController, type NavigateFn, type NavigationConfig, type Notification, type NotificationState, RecursoDisplayer, ToastService, addDays, _default$1 as branchLevelReducer, capitalize, clearBranchLevelForm, clearPicker, daysBetween, formatDate, formatDateTime, isBlank, isDateAfter, isDateBefore, pickTextColorBasedOnBgColorAdvanced, _default as pickerReducer, populateToEdit, removeAccents, setColor, setExcludeLevels, setHaveComponente, setLevel, setLevels, setNome, setPickerContext, setPickerItems, setPickerSelected, setPickerVisible, slugify, toISOString, truncate, useAnexoUpload, useCoreService, useFetchData, useFormStorage, useHttpController, useMatchingObject, useNavigator, useNotifications, usePostData, useSmartSearch, useToast, useValidation };
|
|
388
|
+
export { BreadcrumbPayload, CoreService, CoreServiceBuilder, CoreServiceContext, FetchHttpAdapter, HttpController, IObservabilityPort, InteractionPayload, type NavigateFn, type NavigationConfig, type Notification, type NotificationState, NullCoreService, NullHttpController, NullObservabilityAdapter, NullToastService, RecursoDisplayer, type SolicitacaoDeServico, type StatusSolicitacao, ToastService, TracingHttpAdapter, VitalsPayload, addDays, _default$1 as branchLevelReducer, buildTraceparent, capitalize, clearBranchLevelForm, clearPicker, daysBetween, formatDate, formatDateTime, generateSpanId, generateTraceId, initWebVitals, isBlank, isDateAfter, isDateBefore, pickTextColorBasedOnBgColorAdvanced, _default as pickerReducer, populateToEdit, removeAccents, setColor, setExcludeLevels, setHaveComponente, setLevel, setLevels, setNome, setPickerContext, setPickerItems, setPickerSelected, setPickerVisible, slugify, toISOString, truncate, useAnexoUpload, useCoreService, useFetchData, useFormStorage, useHttpController, useMatchingObject, useNavigator, useNotifications, useObservability, usePostData, useSmartSearch, useToast, useValidation };
|
package/dist/index.js
CHANGED
|
@@ -30,13 +30,21 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
+
CoreServiceBuilder: () => CoreServiceBuilder,
|
|
33
34
|
CoreServiceContext: () => CoreServiceContext,
|
|
34
35
|
DevAutoLogin: () => DevAutoLogin,
|
|
35
36
|
FederatedBridge: () => FederatedBridge,
|
|
37
|
+
FetchHttpAdapter: () => FetchHttpAdapter,
|
|
38
|
+
NullCoreService: () => NullCoreService,
|
|
39
|
+
NullHttpController: () => NullHttpController,
|
|
40
|
+
NullObservabilityAdapter: () => NullObservabilityAdapter,
|
|
41
|
+
NullToastService: () => NullToastService,
|
|
36
42
|
RecursoDisplayer: () => RecursoDisplayer_default,
|
|
37
43
|
StandaloneProvider: () => StandaloneProvider,
|
|
44
|
+
TracingHttpAdapter: () => TracingHttpAdapter,
|
|
38
45
|
addDays: () => addDays,
|
|
39
46
|
branchLevelReducer: () => branchLevelReducer_default,
|
|
47
|
+
buildTraceparent: () => buildTraceparent,
|
|
40
48
|
capitalize: () => capitalize,
|
|
41
49
|
clearBranchLevelForm: () => clearBranchLevelForm,
|
|
42
50
|
clearPicker: () => clearPicker,
|
|
@@ -44,6 +52,9 @@ __export(index_exports, {
|
|
|
44
52
|
daysBetween: () => daysBetween,
|
|
45
53
|
formatDate: () => formatDate,
|
|
46
54
|
formatDateTime: () => formatDateTime,
|
|
55
|
+
generateSpanId: () => generateSpanId,
|
|
56
|
+
generateTraceId: () => generateTraceId,
|
|
57
|
+
initWebVitals: () => initWebVitals,
|
|
47
58
|
isBlank: () => isBlank,
|
|
48
59
|
isDateAfter: () => isDateAfter,
|
|
49
60
|
isDateBefore: () => isDateBefore,
|
|
@@ -72,6 +83,7 @@ __export(index_exports, {
|
|
|
72
83
|
useMatchingObject: () => useMatchingObject,
|
|
73
84
|
useNavigator: () => useNavigator,
|
|
74
85
|
useNotifications: () => useNotifications,
|
|
86
|
+
useObservability: () => useObservability,
|
|
75
87
|
usePostData: () => usePostData,
|
|
76
88
|
useSmartSearch: () => useSmartSearch,
|
|
77
89
|
useToast: () => useToast,
|
|
@@ -83,14 +95,308 @@ module.exports = __toCommonJS(index_exports);
|
|
|
83
95
|
var import_react = require("react");
|
|
84
96
|
var CoreServiceContext = (0, import_react.createContext)(null);
|
|
85
97
|
|
|
98
|
+
// src/adapters/null/NullObservabilityAdapter.ts
|
|
99
|
+
var NullObservabilityAdapter = class {
|
|
100
|
+
trackInteraction(payload) {
|
|
101
|
+
var _a;
|
|
102
|
+
console.info(`[Observability] INTERACTION: ${payload.name}`, (_a = payload.properties) != null ? _a : {});
|
|
103
|
+
}
|
|
104
|
+
captureVitals(payload) {
|
|
105
|
+
var _a, _b;
|
|
106
|
+
const unit = (_a = payload.unit) != null ? _a : "";
|
|
107
|
+
console.info(`[Observability] VITAL: ${payload.name} = ${payload.value}${unit}`, (_b = payload.meta) != null ? _b : {});
|
|
108
|
+
}
|
|
109
|
+
logBreadcrumb(payload) {
|
|
110
|
+
var _a;
|
|
111
|
+
console.info(`[Observability] BREADCRUMB [${payload.category}]: ${payload.message}`, (_a = payload.data) != null ? _a : {});
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
// src/adapters/null/NullObjectAdapters.ts
|
|
116
|
+
var NullToastService = class {
|
|
117
|
+
success(message) {
|
|
118
|
+
console.log(`[Toast Fallback] SUCCESS: ${message}`);
|
|
119
|
+
}
|
|
120
|
+
warning(message) {
|
|
121
|
+
console.warn(`[Toast Fallback] WARNING: ${message}`);
|
|
122
|
+
}
|
|
123
|
+
error(message) {
|
|
124
|
+
console.error(`[Toast Fallback] ERROR: ${message}`);
|
|
125
|
+
}
|
|
126
|
+
info(message) {
|
|
127
|
+
console.info(`[Toast Fallback] INFO: ${message}`);
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
var NullHttpController = class {
|
|
131
|
+
logAndResolve(method, path) {
|
|
132
|
+
console.warn(`[Http Fallback] MOCK ${method} requisitado para ${path} (Nenhum adapter injetado)`);
|
|
133
|
+
return Promise.resolve([]);
|
|
134
|
+
}
|
|
135
|
+
get(path) {
|
|
136
|
+
return this.logAndResolve("GET", path);
|
|
137
|
+
}
|
|
138
|
+
post(path) {
|
|
139
|
+
return this.logAndResolve("POST", path);
|
|
140
|
+
}
|
|
141
|
+
put(path) {
|
|
142
|
+
return this.logAndResolve("PUT", path);
|
|
143
|
+
}
|
|
144
|
+
patch(path) {
|
|
145
|
+
return this.logAndResolve("PATCH", path);
|
|
146
|
+
}
|
|
147
|
+
delete(path, id) {
|
|
148
|
+
return this.logAndResolve("DELETE", `${path}/${id}`);
|
|
149
|
+
}
|
|
150
|
+
deleteSimple(path) {
|
|
151
|
+
return this.logAndResolve("DELETE", path);
|
|
152
|
+
}
|
|
153
|
+
save(path) {
|
|
154
|
+
return this.logAndResolve("SAVE", path);
|
|
155
|
+
}
|
|
156
|
+
read(path, id) {
|
|
157
|
+
return this.logAndResolve("READ", `${path}/${id}`);
|
|
158
|
+
}
|
|
159
|
+
readAll(path) {
|
|
160
|
+
return this.logAndResolve("READ_ALL", path);
|
|
161
|
+
}
|
|
162
|
+
readAllwithPage(path) {
|
|
163
|
+
return this.logAndResolve("READ_ALL_PAGE", path);
|
|
164
|
+
}
|
|
165
|
+
bulkDelete(path) {
|
|
166
|
+
return this.logAndResolve("BULK_DELETE", path);
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
var NullCoreService = {
|
|
170
|
+
toast: new NullToastService(),
|
|
171
|
+
createController: (context) => {
|
|
172
|
+
console.warn(`[CoreService Fallback] createController chamado para "${context}" sem Adapter. Usando NullHttpController.`);
|
|
173
|
+
return new NullHttpController();
|
|
174
|
+
},
|
|
175
|
+
subscribe: (mo) => console.log(`[CoreService Fallback] Inscri\xE7\xE3o simulada RTDB: ${mo.context}`),
|
|
176
|
+
unsubscribe: (mo) => console.log(`[CoreService Fallback] Desinscri\xE7\xE3o simulada RTDB: ${mo.context}`),
|
|
177
|
+
subscribeEvent: (evt) => console.log(`[CoreService Fallback] Inscri\xE7\xE3o Evento: ${evt}`),
|
|
178
|
+
unsubscribeEvent: (evt) => console.log(`[CoreService Fallback] Desinscri\xE7\xE3o Evento: ${evt}`),
|
|
179
|
+
handleLogout: () => console.log(`[CoreService Fallback] Realizando logout...`),
|
|
180
|
+
hostedByCore: false,
|
|
181
|
+
observability: new NullObservabilityAdapter()
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
// src/utils/tracing.ts
|
|
185
|
+
function toHex(bytes) {
|
|
186
|
+
return Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
187
|
+
}
|
|
188
|
+
function generateTraceId() {
|
|
189
|
+
const bytes = new Uint8Array(16);
|
|
190
|
+
crypto.getRandomValues(bytes);
|
|
191
|
+
return toHex(bytes);
|
|
192
|
+
}
|
|
193
|
+
function generateSpanId() {
|
|
194
|
+
const bytes = new Uint8Array(8);
|
|
195
|
+
crypto.getRandomValues(bytes);
|
|
196
|
+
return toHex(bytes);
|
|
197
|
+
}
|
|
198
|
+
function buildTraceparent(traceId, spanId, sampled = true) {
|
|
199
|
+
return `00-${traceId}-${spanId}-${sampled ? "01" : "00"}`;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// src/adapters/TracingHttpAdapter.ts
|
|
203
|
+
var TracingHttpAdapter = class {
|
|
204
|
+
constructor(endpoint) {
|
|
205
|
+
this.endpoint = endpoint;
|
|
206
|
+
this.traceId = generateTraceId();
|
|
207
|
+
}
|
|
208
|
+
mergeHeaders(extraHeaders, withContentType = false) {
|
|
209
|
+
const spanId = generateSpanId();
|
|
210
|
+
const headers = {
|
|
211
|
+
traceparent: buildTraceparent(this.traceId, spanId),
|
|
212
|
+
...extraHeaders
|
|
213
|
+
};
|
|
214
|
+
if (withContentType && !headers["Content-Type"]) {
|
|
215
|
+
headers["Content-Type"] = "application/json";
|
|
216
|
+
}
|
|
217
|
+
return headers;
|
|
218
|
+
}
|
|
219
|
+
async request(method, extraPath, data, extraHeaders) {
|
|
220
|
+
const url = extraPath ? `${this.endpoint}/${extraPath}` : this.endpoint;
|
|
221
|
+
const isFormData = data instanceof FormData;
|
|
222
|
+
const headers = this.mergeHeaders(extraHeaders, data !== void 0 && !isFormData);
|
|
223
|
+
try {
|
|
224
|
+
const res = await fetch(url, {
|
|
225
|
+
method,
|
|
226
|
+
headers,
|
|
227
|
+
body: data !== void 0 ? isFormData ? data : JSON.stringify(data) : void 0
|
|
228
|
+
});
|
|
229
|
+
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
230
|
+
return await res.json();
|
|
231
|
+
} catch (e) {
|
|
232
|
+
console.warn(`[TracingHttpAdapter] Falha ao fazer ${method} para ${url}:`, e);
|
|
233
|
+
return [];
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
get(path) {
|
|
237
|
+
return this.request("GET", path || "");
|
|
238
|
+
}
|
|
239
|
+
post(path, data, extraHeaders) {
|
|
240
|
+
return this.request("POST", path || "", data, extraHeaders);
|
|
241
|
+
}
|
|
242
|
+
put(path, data, extraHeaders) {
|
|
243
|
+
return this.request("PUT", path || "", data, extraHeaders);
|
|
244
|
+
}
|
|
245
|
+
patch(path, data, extraHeaders) {
|
|
246
|
+
return this.request("PATCH", path || "", data, extraHeaders);
|
|
247
|
+
}
|
|
248
|
+
delete(path, id, extraHeaders) {
|
|
249
|
+
return this.request("DELETE", `${path || ""}/${id}`, void 0, extraHeaders);
|
|
250
|
+
}
|
|
251
|
+
deleteSimple(path, extraHeaders) {
|
|
252
|
+
return this.request("DELETE", path || "", void 0, extraHeaders);
|
|
253
|
+
}
|
|
254
|
+
save(path, data, extraHeaders) {
|
|
255
|
+
return this.request("POST", path || "", data, extraHeaders);
|
|
256
|
+
}
|
|
257
|
+
read(path, id, extraHeaders) {
|
|
258
|
+
return this.request("GET", `${path || ""}/${id}`, void 0, extraHeaders);
|
|
259
|
+
}
|
|
260
|
+
readAll(path, extraHeaders) {
|
|
261
|
+
return this.request("GET", path || "", void 0, extraHeaders);
|
|
262
|
+
}
|
|
263
|
+
readAllwithPage(path) {
|
|
264
|
+
return this.request("GET", path || "");
|
|
265
|
+
}
|
|
266
|
+
bulkDelete(path, ids, extraHeaders) {
|
|
267
|
+
return this.request("DELETE", path || "", ids, extraHeaders);
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
// src/factories/CoreServiceBuilder.ts
|
|
272
|
+
var FetchHttpAdapter = class {
|
|
273
|
+
constructor(endpoint) {
|
|
274
|
+
this.endpoint = endpoint;
|
|
275
|
+
}
|
|
276
|
+
async request(method, extraPath, data) {
|
|
277
|
+
const url = extraPath ? `${this.endpoint}/${extraPath}` : this.endpoint;
|
|
278
|
+
try {
|
|
279
|
+
const res = await fetch(url, {
|
|
280
|
+
method,
|
|
281
|
+
headers: data ? { "Content-Type": "application/json" } : void 0,
|
|
282
|
+
body: data ? JSON.stringify(data) : void 0
|
|
283
|
+
});
|
|
284
|
+
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
285
|
+
return await res.json();
|
|
286
|
+
} catch (e) {
|
|
287
|
+
console.warn(`[FetchHttpAdapter] Falha ao fazer ${method} para ${url}:`, e);
|
|
288
|
+
return [];
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
get(path) {
|
|
292
|
+
return this.request("GET", path || "");
|
|
293
|
+
}
|
|
294
|
+
post(path, data) {
|
|
295
|
+
return this.request("POST", path || "", data);
|
|
296
|
+
}
|
|
297
|
+
put(path, data) {
|
|
298
|
+
return this.request("PUT", path || "", data);
|
|
299
|
+
}
|
|
300
|
+
patch(path, data) {
|
|
301
|
+
return this.request("PATCH", path || "", data);
|
|
302
|
+
}
|
|
303
|
+
delete(path, id) {
|
|
304
|
+
return this.request("DELETE", `${path || ""}/${id}`);
|
|
305
|
+
}
|
|
306
|
+
deleteSimple(path) {
|
|
307
|
+
return this.request("DELETE", path || "");
|
|
308
|
+
}
|
|
309
|
+
save(path, data) {
|
|
310
|
+
return this.request("POST", path || "", data);
|
|
311
|
+
}
|
|
312
|
+
read(path, id) {
|
|
313
|
+
return this.request("GET", `${path || ""}/${id}`);
|
|
314
|
+
}
|
|
315
|
+
readAll(path) {
|
|
316
|
+
return this.request("GET", path || "");
|
|
317
|
+
}
|
|
318
|
+
readAllwithPage(path) {
|
|
319
|
+
return this.request("GET", path || "");
|
|
320
|
+
}
|
|
321
|
+
bulkDelete(path) {
|
|
322
|
+
return this.request("DELETE", path || "");
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
var CoreServiceBuilder = class {
|
|
326
|
+
constructor() {
|
|
327
|
+
this._toast = new NullToastService();
|
|
328
|
+
this._hostedByCore = false;
|
|
329
|
+
this._observability = new NullObservabilityAdapter();
|
|
330
|
+
this._tracing = false;
|
|
331
|
+
}
|
|
332
|
+
withToast(toast) {
|
|
333
|
+
this._toast = toast;
|
|
334
|
+
return this;
|
|
335
|
+
}
|
|
336
|
+
withHttpEndpoint(url) {
|
|
337
|
+
this._httpEndpoint = url;
|
|
338
|
+
return this;
|
|
339
|
+
}
|
|
340
|
+
withRtdbConfig(config) {
|
|
341
|
+
this._rtdbConfig = config;
|
|
342
|
+
return this;
|
|
343
|
+
}
|
|
344
|
+
setHostedByCore(hosted) {
|
|
345
|
+
this._hostedByCore = hosted;
|
|
346
|
+
return this;
|
|
347
|
+
}
|
|
348
|
+
withObservability(observability) {
|
|
349
|
+
this._observability = observability;
|
|
350
|
+
return this;
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Ativa Distributed Tracing W3C nos controllers HTTP.
|
|
354
|
+
* Quando habilitado, `createController` retorna `TracingHttpAdapter` em vez de `FetchHttpAdapter`.
|
|
355
|
+
* O header `traceparent` é injetado em todas as requisições automaticamente.
|
|
356
|
+
*/
|
|
357
|
+
withTracing(enabled = true) {
|
|
358
|
+
this._tracing = enabled;
|
|
359
|
+
return this;
|
|
360
|
+
}
|
|
361
|
+
build() {
|
|
362
|
+
return {
|
|
363
|
+
toast: this._toast,
|
|
364
|
+
createController: (context, baseEndPoint) => {
|
|
365
|
+
const endpoint = baseEndPoint != null ? baseEndPoint : this._httpEndpoint ? `${this._httpEndpoint}/${context}` : null;
|
|
366
|
+
if (!endpoint) {
|
|
367
|
+
console.warn(`[CoreServiceBuilder] HttpEndpoint nulo para "${context}". Usando NullHttpController.`);
|
|
368
|
+
return new NullHttpController();
|
|
369
|
+
}
|
|
370
|
+
return this._tracing ? new TracingHttpAdapter(endpoint) : new FetchHttpAdapter(endpoint);
|
|
371
|
+
},
|
|
372
|
+
subscribe: (mo) => {
|
|
373
|
+
console.log(`[CoreServiceBuilder RTDB] Subscribe > ${mo.context}`);
|
|
374
|
+
},
|
|
375
|
+
unsubscribe: (mo) => {
|
|
376
|
+
console.log(`[CoreServiceBuilder RTDB] Unsubscribe > ${mo.context}`);
|
|
377
|
+
},
|
|
378
|
+
subscribeEvent: (evt) => {
|
|
379
|
+
},
|
|
380
|
+
unsubscribeEvent: (evt) => {
|
|
381
|
+
},
|
|
382
|
+
handleLogout: () => console.log("Logout invocado no Standalone mode"),
|
|
383
|
+
hostedByCore: this._hostedByCore,
|
|
384
|
+
observability: this._observability
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
|
|
86
389
|
// src/hooks/useCoreService.ts
|
|
87
390
|
var import_react2 = require("react");
|
|
88
391
|
function useCoreService() {
|
|
89
392
|
const ctx = (0, import_react2.useContext)(CoreServiceContext);
|
|
90
393
|
if (!ctx) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
394
|
+
if (process.env.NODE_ENV !== "production") {
|
|
395
|
+
console.warn(
|
|
396
|
+
"[useCoreService] rodando sem Provider. O SDK ativou os Fallbacks (Null Object Pattern)."
|
|
397
|
+
);
|
|
398
|
+
}
|
|
399
|
+
return NullCoreService;
|
|
94
400
|
}
|
|
95
401
|
return ctx;
|
|
96
402
|
}
|
|
@@ -191,6 +497,11 @@ function useNavigator(config) {
|
|
|
191
497
|
);
|
|
192
498
|
}
|
|
193
499
|
|
|
500
|
+
// src/hooks/useObservability.ts
|
|
501
|
+
function useObservability() {
|
|
502
|
+
return useCoreService().observability;
|
|
503
|
+
}
|
|
504
|
+
|
|
194
505
|
// src/hooks/useFetchData.ts
|
|
195
506
|
var import_react6 = require("react");
|
|
196
507
|
function useFetchData() {
|
|
@@ -1246,6 +1557,39 @@ var {
|
|
|
1246
1557
|
} = pickerSlice.actions;
|
|
1247
1558
|
var pickerReducer_default = pickerSlice.reducer;
|
|
1248
1559
|
|
|
1560
|
+
// src/utils/webVitals.ts
|
|
1561
|
+
function initWebVitals(observability) {
|
|
1562
|
+
if (typeof PerformanceObserver === "undefined") return;
|
|
1563
|
+
try {
|
|
1564
|
+
const lcpObserver = new PerformanceObserver((list) => {
|
|
1565
|
+
const entries = list.getEntries();
|
|
1566
|
+
if (!entries.length) return;
|
|
1567
|
+
const last = entries[entries.length - 1];
|
|
1568
|
+
observability.captureVitals({ name: "LCP", value: Math.round(last.startTime), unit: "ms" });
|
|
1569
|
+
});
|
|
1570
|
+
lcpObserver.observe({ type: "largest-contentful-paint", buffered: true });
|
|
1571
|
+
} catch (_) {
|
|
1572
|
+
}
|
|
1573
|
+
try {
|
|
1574
|
+
let clsValue = 0;
|
|
1575
|
+
const clsObserver = new PerformanceObserver((list) => {
|
|
1576
|
+
for (const entry of list.getEntries()) {
|
|
1577
|
+
const ls = entry;
|
|
1578
|
+
if (!ls.hadRecentInput && typeof ls.value === "number") {
|
|
1579
|
+
clsValue += ls.value;
|
|
1580
|
+
}
|
|
1581
|
+
}
|
|
1582
|
+
observability.captureVitals({
|
|
1583
|
+
name: "CLS",
|
|
1584
|
+
value: parseFloat(clsValue.toFixed(4)),
|
|
1585
|
+
unit: "score"
|
|
1586
|
+
});
|
|
1587
|
+
});
|
|
1588
|
+
clsObserver.observe({ type: "layout-shift", buffered: true });
|
|
1589
|
+
} catch (_) {
|
|
1590
|
+
}
|
|
1591
|
+
}
|
|
1592
|
+
|
|
1249
1593
|
// src/utils/dateUtils.ts
|
|
1250
1594
|
var import_dayjs = __toESM(require("dayjs"));
|
|
1251
1595
|
function formatDate(date, format = "DD/MM/YYYY") {
|
|
@@ -1559,7 +1903,8 @@ function StandaloneProvider({ createController, addToast, firebaseConfig, emulat
|
|
|
1559
1903
|
},
|
|
1560
1904
|
handleLogout: () => {
|
|
1561
1905
|
},
|
|
1562
|
-
hostedByCore: false
|
|
1906
|
+
hostedByCore: false,
|
|
1907
|
+
observability: new NullObservabilityAdapter()
|
|
1563
1908
|
}),
|
|
1564
1909
|
[createController, toast, subscribe, unsubscribe]
|
|
1565
1910
|
);
|
|
@@ -1578,14 +1923,14 @@ var DEFAULT_DEV_USER = {
|
|
|
1578
1923
|
lastName: "User",
|
|
1579
1924
|
token: "dev-standalone-token",
|
|
1580
1925
|
email: "dev@teraprox.local",
|
|
1581
|
-
id: "
|
|
1926
|
+
id: "1",
|
|
1582
1927
|
role: "admin",
|
|
1583
1928
|
user: "devuser",
|
|
1584
1929
|
userName: "devuser",
|
|
1585
1930
|
setor: "Desenvolvimento",
|
|
1586
|
-
userSetor: { setorId: "
|
|
1931
|
+
userSetor: { setorId: "1" },
|
|
1587
1932
|
companyName: "Dev Company",
|
|
1588
|
-
companyId: "
|
|
1933
|
+
companyId: "1",
|
|
1589
1934
|
filters: []
|
|
1590
1935
|
};
|
|
1591
1936
|
function DevAutoLogin({ actions, devUser, children }) {
|
|
@@ -1606,13 +1951,21 @@ function DevAutoLogin({ actions, devUser, children }) {
|
|
|
1606
1951
|
}
|
|
1607
1952
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1608
1953
|
0 && (module.exports = {
|
|
1954
|
+
CoreServiceBuilder,
|
|
1609
1955
|
CoreServiceContext,
|
|
1610
1956
|
DevAutoLogin,
|
|
1611
1957
|
FederatedBridge,
|
|
1958
|
+
FetchHttpAdapter,
|
|
1959
|
+
NullCoreService,
|
|
1960
|
+
NullHttpController,
|
|
1961
|
+
NullObservabilityAdapter,
|
|
1962
|
+
NullToastService,
|
|
1612
1963
|
RecursoDisplayer,
|
|
1613
1964
|
StandaloneProvider,
|
|
1965
|
+
TracingHttpAdapter,
|
|
1614
1966
|
addDays,
|
|
1615
1967
|
branchLevelReducer,
|
|
1968
|
+
buildTraceparent,
|
|
1616
1969
|
capitalize,
|
|
1617
1970
|
clearBranchLevelForm,
|
|
1618
1971
|
clearPicker,
|
|
@@ -1620,6 +1973,9 @@ function DevAutoLogin({ actions, devUser, children }) {
|
|
|
1620
1973
|
daysBetween,
|
|
1621
1974
|
formatDate,
|
|
1622
1975
|
formatDateTime,
|
|
1976
|
+
generateSpanId,
|
|
1977
|
+
generateTraceId,
|
|
1978
|
+
initWebVitals,
|
|
1623
1979
|
isBlank,
|
|
1624
1980
|
isDateAfter,
|
|
1625
1981
|
isDateBefore,
|
|
@@ -1648,6 +2004,7 @@ function DevAutoLogin({ actions, devUser, children }) {
|
|
|
1648
2004
|
useMatchingObject,
|
|
1649
2005
|
useNavigator,
|
|
1650
2006
|
useNotifications,
|
|
2007
|
+
useObservability,
|
|
1651
2008
|
usePostData,
|
|
1652
2009
|
useSmartSearch,
|
|
1653
2010
|
useToast,
|