@apifuse/provider-sdk 2.2.0-beta.53 → 2.2.0-beta.55
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/CHANGELOG.md +8 -0
- package/dist/cli/migrate-operation-declaration.d.ts +5 -1
- package/dist/cli/migrate-operation-declaration.js +645 -46
- package/dist/runtime/auth-flow.d.ts +1 -0
- package/dist/runtime/auth-flow.js +2 -0
- package/dist/runtime/trace.d.ts +7 -0
- package/dist/runtime/trace.js +24 -1
- package/dist/server/serve-implementation.d.ts +4 -0
- package/dist/server/serve-implementation.js +576 -321
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-ambiguous-a.ts.txt +3 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-ambiguous-b.ts.txt +3 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-ambiguous-barrel.ts.txt +2 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-ambiguous-index.ts.txt +3 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-computed.ts.txt +6 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-cycle-a.ts.txt +1 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-cycle-b.ts.txt +1 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-cycle-index.ts.txt +3 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-daiso-barrel.ts.txt +7 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-daiso-catalog.ts.txt +19 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-daiso-docs.ts.txt +6 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-daiso-index.ts.txt +3 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-daiso-stores.ts.txt +8 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-indirect-config.ts.txt +5 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-nonstatic.ts.txt +4 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-package-index.ts.txt +3 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-reexport-index.ts.txt +3 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-reexport-leaf.ts.txt +10 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-reexport-one.ts.txt +1 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-reexport-two.ts.txt +1 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-star-package-barrel.ts.txt +2 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-star-package-index.ts.txt +3 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-star-package-leaf.ts.txt +3 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/factory-duplicate-provider.ts.txt +11 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/factory-id-unresolved.ts.txt +7 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/factory-one-to-many.ts.txt +18 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/factory-one-to-one.ts.txt +13 -0
- package/src/cli/migrate-operation-declaration.ts +844 -49
- package/src/runtime/auth-flow.ts +3 -0
- package/src/runtime/trace.ts +37 -1
- package/src/server/serve-implementation.ts +759 -586
- package/src/types.ts +1 -0
package/src/runtime/auth-flow.ts
CHANGED
|
@@ -13,6 +13,7 @@ import type {
|
|
|
13
13
|
import { createUnsupportedOcrClient } from "./ocr.js";
|
|
14
14
|
import { createUnsupportedResolverClient } from "./resolver-shared.js";
|
|
15
15
|
import { createUnsupportedSttClient } from "./stt.js";
|
|
16
|
+
import { createTraceContext } from "./trace.js";
|
|
16
17
|
|
|
17
18
|
function normalizeAllowedKeys(allowedKeys: string[]): Set<string> {
|
|
18
19
|
return new Set(allowedKeys.filter((key) => key.trim().length > 0));
|
|
@@ -66,6 +67,7 @@ export function createFlowContext(options: {
|
|
|
66
67
|
initialContext?: Record<string, unknown>;
|
|
67
68
|
ocr?: OcrContext;
|
|
68
69
|
stt?: SttContext;
|
|
70
|
+
trace?: FlowContext["trace"];
|
|
69
71
|
}): FlowContext {
|
|
70
72
|
return {
|
|
71
73
|
flowId: options.flowId,
|
|
@@ -73,6 +75,7 @@ export function createFlowContext(options: {
|
|
|
73
75
|
externalRef: options.externalRef,
|
|
74
76
|
tenantId: options.tenantId,
|
|
75
77
|
providerId: options.providerId,
|
|
78
|
+
trace: options.trace ?? createTraceContext(),
|
|
76
79
|
http: options.http,
|
|
77
80
|
state: options.state,
|
|
78
81
|
stealth: options.stealth,
|
package/src/runtime/trace.ts
CHANGED
|
@@ -21,6 +21,8 @@ export interface CreateTraceContextOptions {
|
|
|
21
21
|
onSpan?: (span: Span) => void;
|
|
22
22
|
exportOptions?: OTLPExportOptions;
|
|
23
23
|
resourceAttributes?: Record<string, string>;
|
|
24
|
+
/** W3C-compatible 32-character lowercase hexadecimal trace id used for export. */
|
|
25
|
+
traceId?: string;
|
|
24
26
|
/**
|
|
25
27
|
* Applied to a detached copy of each span immediately before OTLP export; never touches
|
|
26
28
|
* getSpans() or onSpan. Returning nothing (or throwing) drops that export batch.
|
|
@@ -55,11 +57,33 @@ export interface TraceRecorder {
|
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
export const TRACE_RECORDER = Symbol.for("@apifuse/provider-sdk/runtime/trace-recorder");
|
|
60
|
+
const TRACE_EXPORT_METADATA = Symbol.for(
|
|
61
|
+
"@apifuse/provider-sdk/runtime/trace-export-metadata",
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
type TraceExportMetadata = {
|
|
65
|
+
update(input: { traceId?: string; resourceAttributes?: Record<string, string> }): void;
|
|
66
|
+
};
|
|
58
67
|
|
|
59
68
|
type InternalTraceContext = TraceContext & {
|
|
60
69
|
[TRACE_RECORDER]: TraceRecorder;
|
|
70
|
+
[TRACE_EXPORT_METADATA]: TraceExportMetadata;
|
|
61
71
|
};
|
|
62
72
|
|
|
73
|
+
function assertValidTraceId(traceId: string): void {
|
|
74
|
+
if (!/^[0-9a-f]{32}$/.test(traceId) || /^0{32}$/.test(traceId)) {
|
|
75
|
+
throw new TypeError("traceId must be 32 lowercase hexadecimal characters and non-zero");
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Updates request metadata before its pending root span completes and exports. */
|
|
80
|
+
export function updateTraceContextExportMetadata(
|
|
81
|
+
trace: BaseTraceContext,
|
|
82
|
+
input: { traceId?: string; resourceAttributes?: Record<string, string> },
|
|
83
|
+
): void {
|
|
84
|
+
(trace as Partial<InternalTraceContext>)[TRACE_EXPORT_METADATA]?.update(input);
|
|
85
|
+
}
|
|
86
|
+
|
|
63
87
|
function buildOTLPExportOptions(config?: TraceConfig): OTLPExportOptions | undefined {
|
|
64
88
|
if (config?.exporter !== "otlp") {
|
|
65
89
|
return undefined;
|
|
@@ -148,6 +172,7 @@ export function getTraceRecorder(trace: BaseTraceContext): TraceRecorder | null
|
|
|
148
172
|
}
|
|
149
173
|
|
|
150
174
|
export function createTraceContext(options: CreateTraceContextOptions = {}): TraceContext {
|
|
175
|
+
if (options.traceId !== undefined) assertValidTraceId(options.traceId);
|
|
151
176
|
const maxSpans = options.maxSpans ?? 1000;
|
|
152
177
|
const completed: CompletedSpanEntry[] = [];
|
|
153
178
|
const activeSpanStorage = new AsyncLocalStorage<PendingSpan | undefined>();
|
|
@@ -160,7 +185,7 @@ export function createTraceContext(options: CreateTraceContextOptions = {}): Tra
|
|
|
160
185
|
: undefined;
|
|
161
186
|
// One trace id per context so every export batch of this request shares it and
|
|
162
187
|
// two processes can never mint the same id.
|
|
163
|
-
|
|
188
|
+
let exportTraceId = options.traceId ?? crypto.randomUUID().replace(/-/g, "");
|
|
164
189
|
let exportScheduled = false;
|
|
165
190
|
|
|
166
191
|
// One pending batch per context: roots completing before the flush share it, and a span is
|
|
@@ -265,6 +290,17 @@ export function createTraceContext(options: CreateTraceContextOptions = {}): Tra
|
|
|
265
290
|
return completed.map((entry) => ({ ...entry.span }));
|
|
266
291
|
},
|
|
267
292
|
[TRACE_RECORDER]: recorder,
|
|
293
|
+
[TRACE_EXPORT_METADATA]: {
|
|
294
|
+
update(input) {
|
|
295
|
+
if (input.traceId !== undefined) {
|
|
296
|
+
assertValidTraceId(input.traceId);
|
|
297
|
+
exportTraceId = input.traceId;
|
|
298
|
+
}
|
|
299
|
+
if (input.resourceAttributes !== undefined && exportResourceAttributes) {
|
|
300
|
+
Object.assign(exportResourceAttributes, input.resourceAttributes);
|
|
301
|
+
}
|
|
302
|
+
},
|
|
303
|
+
},
|
|
268
304
|
};
|
|
269
305
|
|
|
270
306
|
return traceContext;
|