teraprox-core-sdk 0.3.5 → 0.3.6
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/index.d.mts +136 -13
- package/dist/index.d.ts +136 -13
- package/dist/index.js +51 -19
- package/dist/index.mjs +51 -19
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -58,7 +58,8 @@ declare const CoreServiceContext: React.Context<CoreService | null>;
|
|
|
58
58
|
|
|
59
59
|
declare class FetchHttpAdapter implements HttpController {
|
|
60
60
|
private endpoint;
|
|
61
|
-
|
|
61
|
+
private extraHeaders?;
|
|
62
|
+
constructor(endpoint: string, extraHeaders?: Record<string, string> | undefined);
|
|
62
63
|
private request;
|
|
63
64
|
get(path?: string): Promise<any>;
|
|
64
65
|
post(path?: string, data?: any): Promise<any>;
|
|
@@ -101,17 +102,138 @@ declare class NullToastService implements ToastService {
|
|
|
101
102
|
}
|
|
102
103
|
declare class NullHttpController implements HttpController {
|
|
103
104
|
private logAndResolve;
|
|
104
|
-
get(path?: string): Promise<
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
105
|
+
get(path?: string): Promise<{
|
|
106
|
+
id: number;
|
|
107
|
+
nome: string;
|
|
108
|
+
branchLevel: {
|
|
109
|
+
level: number;
|
|
110
|
+
};
|
|
111
|
+
status: string;
|
|
112
|
+
}[]> | Promise<{
|
|
113
|
+
id: number;
|
|
114
|
+
level: number;
|
|
115
|
+
nome: string;
|
|
116
|
+
}[]>;
|
|
117
|
+
post(path?: string): Promise<{
|
|
118
|
+
id: number;
|
|
119
|
+
nome: string;
|
|
120
|
+
branchLevel: {
|
|
121
|
+
level: number;
|
|
122
|
+
};
|
|
123
|
+
status: string;
|
|
124
|
+
}[]> | Promise<{
|
|
125
|
+
id: number;
|
|
126
|
+
level: number;
|
|
127
|
+
nome: string;
|
|
128
|
+
}[]>;
|
|
129
|
+
put(path?: string): Promise<{
|
|
130
|
+
id: number;
|
|
131
|
+
nome: string;
|
|
132
|
+
branchLevel: {
|
|
133
|
+
level: number;
|
|
134
|
+
};
|
|
135
|
+
status: string;
|
|
136
|
+
}[]> | Promise<{
|
|
137
|
+
id: number;
|
|
138
|
+
level: number;
|
|
139
|
+
nome: string;
|
|
140
|
+
}[]>;
|
|
141
|
+
patch(path?: string): Promise<{
|
|
142
|
+
id: number;
|
|
143
|
+
nome: string;
|
|
144
|
+
branchLevel: {
|
|
145
|
+
level: number;
|
|
146
|
+
};
|
|
147
|
+
status: string;
|
|
148
|
+
}[]> | Promise<{
|
|
149
|
+
id: number;
|
|
150
|
+
level: number;
|
|
151
|
+
nome: string;
|
|
152
|
+
}[]>;
|
|
153
|
+
delete(path?: string, id?: string | number): Promise<{
|
|
154
|
+
id: number;
|
|
155
|
+
nome: string;
|
|
156
|
+
branchLevel: {
|
|
157
|
+
level: number;
|
|
158
|
+
};
|
|
159
|
+
status: string;
|
|
160
|
+
}[]> | Promise<{
|
|
161
|
+
id: number;
|
|
162
|
+
level: number;
|
|
163
|
+
nome: string;
|
|
164
|
+
}[]>;
|
|
165
|
+
deleteSimple(path?: string): Promise<{
|
|
166
|
+
id: number;
|
|
167
|
+
nome: string;
|
|
168
|
+
branchLevel: {
|
|
169
|
+
level: number;
|
|
170
|
+
};
|
|
171
|
+
status: string;
|
|
172
|
+
}[]> | Promise<{
|
|
173
|
+
id: number;
|
|
174
|
+
level: number;
|
|
175
|
+
nome: string;
|
|
176
|
+
}[]>;
|
|
177
|
+
save(path?: string): Promise<{
|
|
178
|
+
id: number;
|
|
179
|
+
nome: string;
|
|
180
|
+
branchLevel: {
|
|
181
|
+
level: number;
|
|
182
|
+
};
|
|
183
|
+
status: string;
|
|
184
|
+
}[]> | Promise<{
|
|
185
|
+
id: number;
|
|
186
|
+
level: number;
|
|
187
|
+
nome: string;
|
|
188
|
+
}[]>;
|
|
189
|
+
read(path?: string, id?: string | number): Promise<{
|
|
190
|
+
id: number;
|
|
191
|
+
nome: string;
|
|
192
|
+
branchLevel: {
|
|
193
|
+
level: number;
|
|
194
|
+
};
|
|
195
|
+
status: string;
|
|
196
|
+
}[]> | Promise<{
|
|
197
|
+
id: number;
|
|
198
|
+
level: number;
|
|
199
|
+
nome: string;
|
|
200
|
+
}[]>;
|
|
201
|
+
readAll(path?: string): Promise<{
|
|
202
|
+
id: number;
|
|
203
|
+
nome: string;
|
|
204
|
+
branchLevel: {
|
|
205
|
+
level: number;
|
|
206
|
+
};
|
|
207
|
+
status: string;
|
|
208
|
+
}[]> | Promise<{
|
|
209
|
+
id: number;
|
|
210
|
+
level: number;
|
|
211
|
+
nome: string;
|
|
212
|
+
}[]>;
|
|
213
|
+
readAllwithPage(path?: string): Promise<{
|
|
214
|
+
id: number;
|
|
215
|
+
nome: string;
|
|
216
|
+
branchLevel: {
|
|
217
|
+
level: number;
|
|
218
|
+
};
|
|
219
|
+
status: string;
|
|
220
|
+
}[]> | Promise<{
|
|
221
|
+
id: number;
|
|
222
|
+
level: number;
|
|
223
|
+
nome: string;
|
|
224
|
+
}[]>;
|
|
225
|
+
bulkDelete(path?: string): Promise<{
|
|
226
|
+
id: number;
|
|
227
|
+
nome: string;
|
|
228
|
+
branchLevel: {
|
|
229
|
+
level: number;
|
|
230
|
+
};
|
|
231
|
+
status: string;
|
|
232
|
+
}[]> | Promise<{
|
|
233
|
+
id: number;
|
|
234
|
+
level: number;
|
|
235
|
+
nome: string;
|
|
236
|
+
}[]>;
|
|
115
237
|
}
|
|
116
238
|
declare const NullCoreService: CoreService;
|
|
117
239
|
|
|
@@ -144,9 +266,10 @@ declare class NullObservabilityAdapter implements IObservabilityPort {
|
|
|
144
266
|
*/
|
|
145
267
|
declare class TracingHttpAdapter implements HttpController {
|
|
146
268
|
private readonly endpoint;
|
|
269
|
+
private readonly extraHeaders?;
|
|
147
270
|
/** Identificador único desta cadeia de spans — compartilhado por todas as reqs do controller. */
|
|
148
271
|
private readonly traceId;
|
|
149
|
-
constructor(endpoint: string);
|
|
272
|
+
constructor(endpoint: string, extraHeaders?: Record<string, string> | undefined);
|
|
150
273
|
private mergeHeaders;
|
|
151
274
|
private request;
|
|
152
275
|
get(path?: string): Promise<any>;
|
package/dist/index.d.ts
CHANGED
|
@@ -58,7 +58,8 @@ declare const CoreServiceContext: React.Context<CoreService | null>;
|
|
|
58
58
|
|
|
59
59
|
declare class FetchHttpAdapter implements HttpController {
|
|
60
60
|
private endpoint;
|
|
61
|
-
|
|
61
|
+
private extraHeaders?;
|
|
62
|
+
constructor(endpoint: string, extraHeaders?: Record<string, string> | undefined);
|
|
62
63
|
private request;
|
|
63
64
|
get(path?: string): Promise<any>;
|
|
64
65
|
post(path?: string, data?: any): Promise<any>;
|
|
@@ -101,17 +102,138 @@ declare class NullToastService implements ToastService {
|
|
|
101
102
|
}
|
|
102
103
|
declare class NullHttpController implements HttpController {
|
|
103
104
|
private logAndResolve;
|
|
104
|
-
get(path?: string): Promise<
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
105
|
+
get(path?: string): Promise<{
|
|
106
|
+
id: number;
|
|
107
|
+
nome: string;
|
|
108
|
+
branchLevel: {
|
|
109
|
+
level: number;
|
|
110
|
+
};
|
|
111
|
+
status: string;
|
|
112
|
+
}[]> | Promise<{
|
|
113
|
+
id: number;
|
|
114
|
+
level: number;
|
|
115
|
+
nome: string;
|
|
116
|
+
}[]>;
|
|
117
|
+
post(path?: string): Promise<{
|
|
118
|
+
id: number;
|
|
119
|
+
nome: string;
|
|
120
|
+
branchLevel: {
|
|
121
|
+
level: number;
|
|
122
|
+
};
|
|
123
|
+
status: string;
|
|
124
|
+
}[]> | Promise<{
|
|
125
|
+
id: number;
|
|
126
|
+
level: number;
|
|
127
|
+
nome: string;
|
|
128
|
+
}[]>;
|
|
129
|
+
put(path?: string): Promise<{
|
|
130
|
+
id: number;
|
|
131
|
+
nome: string;
|
|
132
|
+
branchLevel: {
|
|
133
|
+
level: number;
|
|
134
|
+
};
|
|
135
|
+
status: string;
|
|
136
|
+
}[]> | Promise<{
|
|
137
|
+
id: number;
|
|
138
|
+
level: number;
|
|
139
|
+
nome: string;
|
|
140
|
+
}[]>;
|
|
141
|
+
patch(path?: string): Promise<{
|
|
142
|
+
id: number;
|
|
143
|
+
nome: string;
|
|
144
|
+
branchLevel: {
|
|
145
|
+
level: number;
|
|
146
|
+
};
|
|
147
|
+
status: string;
|
|
148
|
+
}[]> | Promise<{
|
|
149
|
+
id: number;
|
|
150
|
+
level: number;
|
|
151
|
+
nome: string;
|
|
152
|
+
}[]>;
|
|
153
|
+
delete(path?: string, id?: string | number): Promise<{
|
|
154
|
+
id: number;
|
|
155
|
+
nome: string;
|
|
156
|
+
branchLevel: {
|
|
157
|
+
level: number;
|
|
158
|
+
};
|
|
159
|
+
status: string;
|
|
160
|
+
}[]> | Promise<{
|
|
161
|
+
id: number;
|
|
162
|
+
level: number;
|
|
163
|
+
nome: string;
|
|
164
|
+
}[]>;
|
|
165
|
+
deleteSimple(path?: string): Promise<{
|
|
166
|
+
id: number;
|
|
167
|
+
nome: string;
|
|
168
|
+
branchLevel: {
|
|
169
|
+
level: number;
|
|
170
|
+
};
|
|
171
|
+
status: string;
|
|
172
|
+
}[]> | Promise<{
|
|
173
|
+
id: number;
|
|
174
|
+
level: number;
|
|
175
|
+
nome: string;
|
|
176
|
+
}[]>;
|
|
177
|
+
save(path?: string): Promise<{
|
|
178
|
+
id: number;
|
|
179
|
+
nome: string;
|
|
180
|
+
branchLevel: {
|
|
181
|
+
level: number;
|
|
182
|
+
};
|
|
183
|
+
status: string;
|
|
184
|
+
}[]> | Promise<{
|
|
185
|
+
id: number;
|
|
186
|
+
level: number;
|
|
187
|
+
nome: string;
|
|
188
|
+
}[]>;
|
|
189
|
+
read(path?: string, id?: string | number): Promise<{
|
|
190
|
+
id: number;
|
|
191
|
+
nome: string;
|
|
192
|
+
branchLevel: {
|
|
193
|
+
level: number;
|
|
194
|
+
};
|
|
195
|
+
status: string;
|
|
196
|
+
}[]> | Promise<{
|
|
197
|
+
id: number;
|
|
198
|
+
level: number;
|
|
199
|
+
nome: string;
|
|
200
|
+
}[]>;
|
|
201
|
+
readAll(path?: string): Promise<{
|
|
202
|
+
id: number;
|
|
203
|
+
nome: string;
|
|
204
|
+
branchLevel: {
|
|
205
|
+
level: number;
|
|
206
|
+
};
|
|
207
|
+
status: string;
|
|
208
|
+
}[]> | Promise<{
|
|
209
|
+
id: number;
|
|
210
|
+
level: number;
|
|
211
|
+
nome: string;
|
|
212
|
+
}[]>;
|
|
213
|
+
readAllwithPage(path?: string): Promise<{
|
|
214
|
+
id: number;
|
|
215
|
+
nome: string;
|
|
216
|
+
branchLevel: {
|
|
217
|
+
level: number;
|
|
218
|
+
};
|
|
219
|
+
status: string;
|
|
220
|
+
}[]> | Promise<{
|
|
221
|
+
id: number;
|
|
222
|
+
level: number;
|
|
223
|
+
nome: string;
|
|
224
|
+
}[]>;
|
|
225
|
+
bulkDelete(path?: string): Promise<{
|
|
226
|
+
id: number;
|
|
227
|
+
nome: string;
|
|
228
|
+
branchLevel: {
|
|
229
|
+
level: number;
|
|
230
|
+
};
|
|
231
|
+
status: string;
|
|
232
|
+
}[]> | Promise<{
|
|
233
|
+
id: number;
|
|
234
|
+
level: number;
|
|
235
|
+
nome: string;
|
|
236
|
+
}[]>;
|
|
115
237
|
}
|
|
116
238
|
declare const NullCoreService: CoreService;
|
|
117
239
|
|
|
@@ -144,9 +266,10 @@ declare class NullObservabilityAdapter implements IObservabilityPort {
|
|
|
144
266
|
*/
|
|
145
267
|
declare class TracingHttpAdapter implements HttpController {
|
|
146
268
|
private readonly endpoint;
|
|
269
|
+
private readonly extraHeaders?;
|
|
147
270
|
/** Identificador único desta cadeia de spans — compartilhado por todas as reqs do controller. */
|
|
148
271
|
private readonly traceId;
|
|
149
|
-
constructor(endpoint: string);
|
|
272
|
+
constructor(endpoint: string, extraHeaders?: Record<string, string> | undefined);
|
|
150
273
|
private mergeHeaders;
|
|
151
274
|
private request;
|
|
152
275
|
get(path?: string): Promise<any>;
|
package/dist/index.js
CHANGED
|
@@ -128,49 +128,71 @@ var NullToastService = class {
|
|
|
128
128
|
}
|
|
129
129
|
};
|
|
130
130
|
var NullHttpController = class {
|
|
131
|
-
logAndResolve(method, path) {
|
|
132
|
-
console.warn(`[Http Fallback] MOCK ${method} requisitado para ${path} (
|
|
131
|
+
logAndResolve(method, path, context) {
|
|
132
|
+
console.warn(`[Http Fallback] MOCK ${method} requisitado para ${path} (Contexto: ${context})`);
|
|
133
|
+
if (process.env.NODE_ENV !== "production") {
|
|
134
|
+
if (context === "arvoreEstrutural" && path && path.includes("branchByBranchLevel")) {
|
|
135
|
+
return Promise.resolve([
|
|
136
|
+
{
|
|
137
|
+
id: 1,
|
|
138
|
+
nome: "Planta Industrial Mock",
|
|
139
|
+
branchLevel: { level: 1 },
|
|
140
|
+
status: "Ativo"
|
|
141
|
+
}
|
|
142
|
+
]);
|
|
143
|
+
}
|
|
144
|
+
if (context === "branchLevel" && method === "READ_ALL") {
|
|
145
|
+
return Promise.resolve([
|
|
146
|
+
{ id: 1, level: 1, nome: "Empresa" },
|
|
147
|
+
{ id: 2, level: 2, nome: "Unidade" },
|
|
148
|
+
{ id: 3, level: 3, nome: "\xC1rea" },
|
|
149
|
+
{ id: 4, level: 4, nome: "M\xE1quina" }
|
|
150
|
+
]);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
133
153
|
return Promise.resolve([]);
|
|
134
154
|
}
|
|
135
155
|
get(path) {
|
|
136
|
-
return this.logAndResolve("GET", path);
|
|
156
|
+
return this.logAndResolve("GET", path, this.context);
|
|
137
157
|
}
|
|
138
158
|
post(path) {
|
|
139
|
-
return this.logAndResolve("POST", path);
|
|
159
|
+
return this.logAndResolve("POST", path, this.context);
|
|
140
160
|
}
|
|
141
161
|
put(path) {
|
|
142
|
-
return this.logAndResolve("PUT", path);
|
|
162
|
+
return this.logAndResolve("PUT", path, this.context);
|
|
143
163
|
}
|
|
144
164
|
patch(path) {
|
|
145
|
-
return this.logAndResolve("PATCH", path);
|
|
165
|
+
return this.logAndResolve("PATCH", path, this.context);
|
|
146
166
|
}
|
|
147
167
|
delete(path, id) {
|
|
148
|
-
return this.logAndResolve("DELETE", `${path}/${id}
|
|
168
|
+
return this.logAndResolve("DELETE", `${path}/${id}`, this.context);
|
|
149
169
|
}
|
|
150
170
|
deleteSimple(path) {
|
|
151
|
-
return this.logAndResolve("DELETE", path);
|
|
171
|
+
return this.logAndResolve("DELETE", path, this.context);
|
|
152
172
|
}
|
|
153
173
|
save(path) {
|
|
154
|
-
return this.logAndResolve("SAVE", path);
|
|
174
|
+
return this.logAndResolve("SAVE", path, this.context);
|
|
155
175
|
}
|
|
156
176
|
read(path, id) {
|
|
157
|
-
return this.logAndResolve("READ", `${path}/${id}
|
|
177
|
+
return this.logAndResolve("READ", `${path}/${id}`, this.context);
|
|
158
178
|
}
|
|
159
179
|
readAll(path) {
|
|
160
|
-
return this.logAndResolve("READ_ALL", path);
|
|
180
|
+
return this.logAndResolve("READ_ALL", path, this.context);
|
|
161
181
|
}
|
|
162
182
|
readAllwithPage(path) {
|
|
163
|
-
return this.logAndResolve("READ_ALL_PAGE", path);
|
|
183
|
+
return this.logAndResolve("READ_ALL_PAGE", path, this.context);
|
|
164
184
|
}
|
|
165
185
|
bulkDelete(path) {
|
|
166
|
-
return this.logAndResolve("BULK_DELETE", path);
|
|
186
|
+
return this.logAndResolve("BULK_DELETE", path, this.context);
|
|
167
187
|
}
|
|
168
188
|
};
|
|
169
189
|
var NullCoreService = {
|
|
170
190
|
toast: new NullToastService(),
|
|
171
191
|
createController: (context) => {
|
|
172
192
|
console.warn(`[CoreService Fallback] createController chamado para "${context}" sem Adapter. Usando NullHttpController.`);
|
|
173
|
-
|
|
193
|
+
const controller = new NullHttpController();
|
|
194
|
+
controller.context = context;
|
|
195
|
+
return controller;
|
|
174
196
|
},
|
|
175
197
|
subscribe: (mo) => console.log(`[CoreService Fallback] Inscri\xE7\xE3o simulada RTDB: ${mo.context}`),
|
|
176
198
|
unsubscribe: (mo) => console.log(`[CoreService Fallback] Desinscri\xE7\xE3o simulada RTDB: ${mo.context}`),
|
|
@@ -201,14 +223,16 @@ function buildTraceparent(traceId, spanId, sampled = true) {
|
|
|
201
223
|
|
|
202
224
|
// src/adapters/TracingHttpAdapter.ts
|
|
203
225
|
var TracingHttpAdapter = class {
|
|
204
|
-
constructor(endpoint) {
|
|
226
|
+
constructor(endpoint, extraHeaders) {
|
|
205
227
|
this.endpoint = endpoint;
|
|
228
|
+
this.extraHeaders = extraHeaders;
|
|
206
229
|
this.traceId = generateTraceId();
|
|
207
230
|
}
|
|
208
231
|
mergeHeaders(extraHeaders, withContentType = false) {
|
|
209
232
|
const spanId = generateSpanId();
|
|
210
233
|
const headers = {
|
|
211
234
|
traceparent: buildTraceparent(this.traceId, spanId),
|
|
235
|
+
...this.extraHeaders,
|
|
212
236
|
...extraHeaders
|
|
213
237
|
};
|
|
214
238
|
if (withContentType && !headers["Content-Type"]) {
|
|
@@ -270,15 +294,19 @@ var TracingHttpAdapter = class {
|
|
|
270
294
|
|
|
271
295
|
// src/factories/CoreServiceBuilder.ts
|
|
272
296
|
var FetchHttpAdapter = class {
|
|
273
|
-
constructor(endpoint) {
|
|
297
|
+
constructor(endpoint, extraHeaders) {
|
|
274
298
|
this.endpoint = endpoint;
|
|
299
|
+
this.extraHeaders = extraHeaders;
|
|
275
300
|
}
|
|
276
301
|
async request(method, extraPath, data) {
|
|
277
302
|
const url = extraPath ? `${this.endpoint}/${extraPath}` : this.endpoint;
|
|
278
303
|
try {
|
|
279
304
|
const res = await fetch(url, {
|
|
280
305
|
method,
|
|
281
|
-
headers:
|
|
306
|
+
headers: {
|
|
307
|
+
...this.extraHeaders,
|
|
308
|
+
...data ? { "Content-Type": "application/json" } : {}
|
|
309
|
+
},
|
|
282
310
|
body: data ? JSON.stringify(data) : void 0
|
|
283
311
|
});
|
|
284
312
|
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
@@ -365,9 +393,13 @@ var CoreServiceBuilder = class {
|
|
|
365
393
|
const endpoint = baseEndPoint != null ? baseEndPoint : this._httpEndpoint ? `${this._httpEndpoint}/${context}` : null;
|
|
366
394
|
if (!endpoint) {
|
|
367
395
|
console.warn(`[CoreServiceBuilder] HttpEndpoint nulo para "${context}". Usando NullHttpController.`);
|
|
368
|
-
|
|
396
|
+
const controller = new NullHttpController();
|
|
397
|
+
controller.context = context;
|
|
398
|
+
return controller;
|
|
369
399
|
}
|
|
370
|
-
|
|
400
|
+
const xTeraproxHost = context === "solicitacaoDeServico" || context === "manutencao" ? "manutencao" : context;
|
|
401
|
+
const extraHeaders = { "x-teraprox-host": xTeraproxHost };
|
|
402
|
+
return this._tracing ? new TracingHttpAdapter(endpoint, extraHeaders) : new FetchHttpAdapter(endpoint, extraHeaders);
|
|
371
403
|
},
|
|
372
404
|
subscribe: (mo) => {
|
|
373
405
|
console.log(`[CoreServiceBuilder RTDB] Subscribe > ${mo.context}`);
|
package/dist/index.mjs
CHANGED
|
@@ -23,49 +23,71 @@ var NullToastService = class {
|
|
|
23
23
|
}
|
|
24
24
|
};
|
|
25
25
|
var NullHttpController = class {
|
|
26
|
-
logAndResolve(method, path) {
|
|
27
|
-
console.warn(`[Http Fallback] MOCK ${method} requisitado para ${path} (
|
|
26
|
+
logAndResolve(method, path, context) {
|
|
27
|
+
console.warn(`[Http Fallback] MOCK ${method} requisitado para ${path} (Contexto: ${context})`);
|
|
28
|
+
if (process.env.NODE_ENV !== "production") {
|
|
29
|
+
if (context === "arvoreEstrutural" && path && path.includes("branchByBranchLevel")) {
|
|
30
|
+
return Promise.resolve([
|
|
31
|
+
{
|
|
32
|
+
id: 1,
|
|
33
|
+
nome: "Planta Industrial Mock",
|
|
34
|
+
branchLevel: { level: 1 },
|
|
35
|
+
status: "Ativo"
|
|
36
|
+
}
|
|
37
|
+
]);
|
|
38
|
+
}
|
|
39
|
+
if (context === "branchLevel" && method === "READ_ALL") {
|
|
40
|
+
return Promise.resolve([
|
|
41
|
+
{ id: 1, level: 1, nome: "Empresa" },
|
|
42
|
+
{ id: 2, level: 2, nome: "Unidade" },
|
|
43
|
+
{ id: 3, level: 3, nome: "\xC1rea" },
|
|
44
|
+
{ id: 4, level: 4, nome: "M\xE1quina" }
|
|
45
|
+
]);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
28
48
|
return Promise.resolve([]);
|
|
29
49
|
}
|
|
30
50
|
get(path) {
|
|
31
|
-
return this.logAndResolve("GET", path);
|
|
51
|
+
return this.logAndResolve("GET", path, this.context);
|
|
32
52
|
}
|
|
33
53
|
post(path) {
|
|
34
|
-
return this.logAndResolve("POST", path);
|
|
54
|
+
return this.logAndResolve("POST", path, this.context);
|
|
35
55
|
}
|
|
36
56
|
put(path) {
|
|
37
|
-
return this.logAndResolve("PUT", path);
|
|
57
|
+
return this.logAndResolve("PUT", path, this.context);
|
|
38
58
|
}
|
|
39
59
|
patch(path) {
|
|
40
|
-
return this.logAndResolve("PATCH", path);
|
|
60
|
+
return this.logAndResolve("PATCH", path, this.context);
|
|
41
61
|
}
|
|
42
62
|
delete(path, id) {
|
|
43
|
-
return this.logAndResolve("DELETE", `${path}/${id}
|
|
63
|
+
return this.logAndResolve("DELETE", `${path}/${id}`, this.context);
|
|
44
64
|
}
|
|
45
65
|
deleteSimple(path) {
|
|
46
|
-
return this.logAndResolve("DELETE", path);
|
|
66
|
+
return this.logAndResolve("DELETE", path, this.context);
|
|
47
67
|
}
|
|
48
68
|
save(path) {
|
|
49
|
-
return this.logAndResolve("SAVE", path);
|
|
69
|
+
return this.logAndResolve("SAVE", path, this.context);
|
|
50
70
|
}
|
|
51
71
|
read(path, id) {
|
|
52
|
-
return this.logAndResolve("READ", `${path}/${id}
|
|
72
|
+
return this.logAndResolve("READ", `${path}/${id}`, this.context);
|
|
53
73
|
}
|
|
54
74
|
readAll(path) {
|
|
55
|
-
return this.logAndResolve("READ_ALL", path);
|
|
75
|
+
return this.logAndResolve("READ_ALL", path, this.context);
|
|
56
76
|
}
|
|
57
77
|
readAllwithPage(path) {
|
|
58
|
-
return this.logAndResolve("READ_ALL_PAGE", path);
|
|
78
|
+
return this.logAndResolve("READ_ALL_PAGE", path, this.context);
|
|
59
79
|
}
|
|
60
80
|
bulkDelete(path) {
|
|
61
|
-
return this.logAndResolve("BULK_DELETE", path);
|
|
81
|
+
return this.logAndResolve("BULK_DELETE", path, this.context);
|
|
62
82
|
}
|
|
63
83
|
};
|
|
64
84
|
var NullCoreService = {
|
|
65
85
|
toast: new NullToastService(),
|
|
66
86
|
createController: (context) => {
|
|
67
87
|
console.warn(`[CoreService Fallback] createController chamado para "${context}" sem Adapter. Usando NullHttpController.`);
|
|
68
|
-
|
|
88
|
+
const controller = new NullHttpController();
|
|
89
|
+
controller.context = context;
|
|
90
|
+
return controller;
|
|
69
91
|
},
|
|
70
92
|
subscribe: (mo) => console.log(`[CoreService Fallback] Inscri\xE7\xE3o simulada RTDB: ${mo.context}`),
|
|
71
93
|
unsubscribe: (mo) => console.log(`[CoreService Fallback] Desinscri\xE7\xE3o simulada RTDB: ${mo.context}`),
|
|
@@ -96,14 +118,16 @@ function buildTraceparent(traceId, spanId, sampled = true) {
|
|
|
96
118
|
|
|
97
119
|
// src/adapters/TracingHttpAdapter.ts
|
|
98
120
|
var TracingHttpAdapter = class {
|
|
99
|
-
constructor(endpoint) {
|
|
121
|
+
constructor(endpoint, extraHeaders) {
|
|
100
122
|
this.endpoint = endpoint;
|
|
123
|
+
this.extraHeaders = extraHeaders;
|
|
101
124
|
this.traceId = generateTraceId();
|
|
102
125
|
}
|
|
103
126
|
mergeHeaders(extraHeaders, withContentType = false) {
|
|
104
127
|
const spanId = generateSpanId();
|
|
105
128
|
const headers = {
|
|
106
129
|
traceparent: buildTraceparent(this.traceId, spanId),
|
|
130
|
+
...this.extraHeaders,
|
|
107
131
|
...extraHeaders
|
|
108
132
|
};
|
|
109
133
|
if (withContentType && !headers["Content-Type"]) {
|
|
@@ -165,15 +189,19 @@ var TracingHttpAdapter = class {
|
|
|
165
189
|
|
|
166
190
|
// src/factories/CoreServiceBuilder.ts
|
|
167
191
|
var FetchHttpAdapter = class {
|
|
168
|
-
constructor(endpoint) {
|
|
192
|
+
constructor(endpoint, extraHeaders) {
|
|
169
193
|
this.endpoint = endpoint;
|
|
194
|
+
this.extraHeaders = extraHeaders;
|
|
170
195
|
}
|
|
171
196
|
async request(method, extraPath, data) {
|
|
172
197
|
const url = extraPath ? `${this.endpoint}/${extraPath}` : this.endpoint;
|
|
173
198
|
try {
|
|
174
199
|
const res = await fetch(url, {
|
|
175
200
|
method,
|
|
176
|
-
headers:
|
|
201
|
+
headers: {
|
|
202
|
+
...this.extraHeaders,
|
|
203
|
+
...data ? { "Content-Type": "application/json" } : {}
|
|
204
|
+
},
|
|
177
205
|
body: data ? JSON.stringify(data) : void 0
|
|
178
206
|
});
|
|
179
207
|
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
@@ -260,9 +288,13 @@ var CoreServiceBuilder = class {
|
|
|
260
288
|
const endpoint = baseEndPoint != null ? baseEndPoint : this._httpEndpoint ? `${this._httpEndpoint}/${context}` : null;
|
|
261
289
|
if (!endpoint) {
|
|
262
290
|
console.warn(`[CoreServiceBuilder] HttpEndpoint nulo para "${context}". Usando NullHttpController.`);
|
|
263
|
-
|
|
291
|
+
const controller = new NullHttpController();
|
|
292
|
+
controller.context = context;
|
|
293
|
+
return controller;
|
|
264
294
|
}
|
|
265
|
-
|
|
295
|
+
const xTeraproxHost = context === "solicitacaoDeServico" || context === "manutencao" ? "manutencao" : context;
|
|
296
|
+
const extraHeaders = { "x-teraprox-host": xTeraproxHost };
|
|
297
|
+
return this._tracing ? new TracingHttpAdapter(endpoint, extraHeaders) : new FetchHttpAdapter(endpoint, extraHeaders);
|
|
266
298
|
},
|
|
267
299
|
subscribe: (mo) => {
|
|
268
300
|
console.log(`[CoreServiceBuilder RTDB] Subscribe > ${mo.context}`);
|
package/package.json
CHANGED