@apifuse/provider-sdk 2.2.0-beta.54 → 2.2.0-beta.56

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.
Files changed (47) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/bin/apifuse-pack-types.ts +121 -0
  3. package/dist/cli/migrate-operation-declaration.d.ts +5 -1
  4. package/dist/cli/migrate-operation-declaration.js +645 -46
  5. package/dist/index.d.ts +2 -1
  6. package/dist/index.js +1 -0
  7. package/dist/runtime/proxy-telemetry.d.ts +53 -2
  8. package/dist/runtime/proxy-telemetry.js +106 -65
  9. package/dist/runtime/request-telemetry.d.ts +70 -0
  10. package/dist/runtime/request-telemetry.js +228 -0
  11. package/dist/server/index.d.ts +3 -1
  12. package/dist/server/index.js +1 -0
  13. package/dist/server/serve-implementation.js +58 -20
  14. package/package.json +1 -1
  15. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-ambiguous-a.ts.txt +3 -0
  16. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-ambiguous-b.ts.txt +3 -0
  17. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-ambiguous-barrel.ts.txt +2 -0
  18. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-ambiguous-index.ts.txt +3 -0
  19. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-computed.ts.txt +6 -0
  20. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-cycle-a.ts.txt +1 -0
  21. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-cycle-b.ts.txt +1 -0
  22. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-cycle-index.ts.txt +3 -0
  23. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-daiso-barrel.ts.txt +7 -0
  24. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-daiso-catalog.ts.txt +19 -0
  25. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-daiso-docs.ts.txt +6 -0
  26. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-daiso-index.ts.txt +3 -0
  27. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-daiso-stores.ts.txt +8 -0
  28. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-indirect-config.ts.txt +5 -0
  29. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-nonstatic.ts.txt +4 -0
  30. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-package-index.ts.txt +3 -0
  31. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-reexport-index.ts.txt +3 -0
  32. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-reexport-leaf.ts.txt +10 -0
  33. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-reexport-one.ts.txt +1 -0
  34. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-reexport-two.ts.txt +1 -0
  35. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-star-package-barrel.ts.txt +2 -0
  36. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-star-package-index.ts.txt +3 -0
  37. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-star-package-leaf.ts.txt +3 -0
  38. package/src/cli/__tests__/fixtures/migrate-operation-declaration/factory-duplicate-provider.ts.txt +11 -0
  39. package/src/cli/__tests__/fixtures/migrate-operation-declaration/factory-id-unresolved.ts.txt +7 -0
  40. package/src/cli/__tests__/fixtures/migrate-operation-declaration/factory-one-to-many.ts.txt +18 -0
  41. package/src/cli/__tests__/fixtures/migrate-operation-declaration/factory-one-to-one.ts.txt +13 -0
  42. package/src/cli/migrate-operation-declaration.ts +844 -49
  43. package/src/index.ts +13 -0
  44. package/src/runtime/proxy-telemetry.ts +160 -74
  45. package/src/runtime/request-telemetry.ts +376 -0
  46. package/src/server/index.ts +14 -0
  47. package/src/server/serve-implementation.ts +93 -21
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @apifuse/provider-sdk Changelog
2
2
 
3
+ ## 2.2.0-beta.56
4
+
5
+ - Release candidate for main commit 390167b3f51488be0beba25a1ea5eb425d3bf839.
6
+
7
+ ## 2.2.0-beta.55
8
+
9
+ - Release candidate for main commit 1c495af089940a4c666e6baf58dc0dd577771a40.
10
+
3
11
  ## 2.2.0-beta.54
4
12
 
5
13
  - Release candidate for main commit 4dccd0cd9d3443cde4edebf98ffc6c11beecb9ea.
@@ -292,6 +292,115 @@ const NEGATIVE_CONTROLS = [
292
292
  "",
293
293
  ].join("\n"),
294
294
  },
295
+ {
296
+ filename: "negative-control-telemetry-header-vendor.ts",
297
+ expectedCode: "TS2322",
298
+ description: "gateway telemetry headers reject an unbranded vendor string",
299
+ source: [
300
+ 'import type { TelemetryContributor } from "@apifuse/provider-sdk";',
301
+ "",
302
+ "const bad: TelemetryContributor<{}, { vendor: string }> = {",
303
+ '\tkey: "resolver",',
304
+ "\ttoLogPayload: () => ({}),",
305
+ '\ttoHeaderPayload: () => ({ vendor: "free-text" }),',
306
+ "};",
307
+ "",
308
+ ].join("\n"),
309
+ },
310
+ {
311
+ filename: "negative-control-telemetry-header-host.ts",
312
+ expectedCode: "TS2322",
313
+ description: "gateway telemetry headers reject an unbranded host string",
314
+ source: [
315
+ 'import type { TelemetryContributor } from "@apifuse/provider-sdk";',
316
+ "",
317
+ "const bad: TelemetryContributor<{}, { host: string }> = {",
318
+ '\tkey: "http",',
319
+ "\ttoLogPayload: () => ({}),",
320
+ '\ttoHeaderPayload: () => ({ host: "x.example" }),',
321
+ "};",
322
+ "",
323
+ ].join("\n"),
324
+ },
325
+ {
326
+ filename: "negative-control-telemetry-tenant-vendor.ts",
327
+ expectedCode: "TS2322",
328
+ description: "tenant-neutral projections reject vendor identities",
329
+ source: [
330
+ 'import type { TenantNeutral } from "@apifuse/provider-sdk";',
331
+ "",
332
+ 'export const bad: TenantNeutral<{ vendorUsed: "smartproxy" }> = { vendorUsed: "smartproxy" };',
333
+ "",
334
+ ].join("\n"),
335
+ },
336
+ {
337
+ filename: "negative-control-telemetry-header-any.ts",
338
+ expectedCode: "TS2322",
339
+ description: "gateway telemetry projections reject any-valued properties",
340
+ source: [
341
+ 'import type { GatewayIngestible } from "@apifuse/provider-sdk";',
342
+ "",
343
+ 'export const bad: GatewayIngestible<{ x: any }> = { x: "free-text" };',
344
+ "",
345
+ ].join("\n"),
346
+ },
347
+ {
348
+ filename: "negative-control-telemetry-header-union-array.ts",
349
+ expectedCode: "TS2322",
350
+ description: "gateway telemetry projections reject arrays mixing numbers and strings",
351
+ source: [
352
+ 'import type { TelemetryContributor } from "@apifuse/provider-sdk";',
353
+ "",
354
+ "const bad: TelemetryContributor<{}, { values: (number | string)[] }> = {",
355
+ '\tkey: "resolver",',
356
+ "\ttoLogPayload: () => ({}),",
357
+ '\ttoHeaderPayload: () => ({ values: [1, "free prose"] }),',
358
+ "};",
359
+ "",
360
+ ].join("\n"),
361
+ },
362
+ {
363
+ filename: "negative-control-telemetry-opaque-identity.ts",
364
+ expectedCode: "TS2322",
365
+ description: "tenant opaque array brands are not accepted outside the cache keys property",
366
+ source: [
367
+ 'import type { TenantNeutral } from "@apifuse/provider-sdk";',
368
+ "",
369
+ "type LocalOpaque = string[] & { readonly __tenantOpaqueCacheKeys: true };",
370
+ "declare const opaque: LocalOpaque;",
371
+ "export const bad: TenantNeutral<{ identity: LocalOpaque }> = { identity: opaque };",
372
+ "",
373
+ ].join("\n"),
374
+ },
375
+ {
376
+ filename: "negative-control-telemetry-meta-vendor.ts",
377
+ expectedCode: "TS2322",
378
+ description: "success metadata rejects tenant-visible vendor identity keys",
379
+ source: [
380
+ 'import { closedEnum, type ClosedEnum, type TenantNeutral } from "@apifuse/provider-sdk";',
381
+ "",
382
+ 'type Meta = { cached: boolean; detail: { vendorUsed: ClosedEnum<"smartproxy"> } };',
383
+ 'export const bad: TenantNeutral<Meta> = { cached: false, detail: { vendorUsed: closedEnum("smartproxy") } };',
384
+ "",
385
+ ].join("\n"),
386
+ },
387
+ {
388
+ filename: "positive-control-proxy-telemetry-contributor.ts",
389
+ expectedCode: "",
390
+ description: "proxy telemetry contributor satisfies the public contributor contract",
391
+ source: [
392
+ 'import { closedEnum, type ClosedEnum, type GatewayIngestible, type ProxyTelemetryHeaderPayload, type ProxyTelemetryLogPayload, type TelemetryContributor } from "@apifuse/provider-sdk";',
393
+ "",
394
+ "export const proxy: TelemetryContributor<ProxyTelemetryLogPayload, ProxyTelemetryHeaderPayload> = {",
395
+ '\tkey: "proxy",',
396
+ '\ttoLogPayload: () => ({ kind: "unresolved", vendors: [] }),',
397
+ '\ttoHeaderPayload: () => ({ kind: closedEnum("unresolved"), vendors: [] }),',
398
+ "};",
399
+ 'type Values = { values: ClosedEnum<"a" | "b">[] };',
400
+ 'export const values: GatewayIngestible<Values> = { values: [closedEnum("a"), closedEnum("b")] };',
401
+ "",
402
+ ].join("\n"),
403
+ },
295
404
  ] as const;
296
405
 
297
406
  const tempRoot = mkdtempSync(join(tmpdir(), "apifuse-provider-sdk-pack-types-"));
@@ -513,6 +622,15 @@ function assertNegativeControlFails(consumerDir: string): void {
513
622
  ],
514
623
  { cwd: consumerDir, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] },
515
624
  );
625
+ if (negativeControl.expectedCode === "") {
626
+ if (result.status !== 0) {
627
+ throw new Error(
628
+ `Positive control "${negativeControl.description}" failed to compile:\n${result.stdout}\n${result.stderr}`,
629
+ );
630
+ }
631
+ console.log(`Positive control accepted: ${negativeControl.description}`);
632
+ continue;
633
+ }
516
634
  if (result.status === 0) {
517
635
  throw new Error(
518
636
  'Negative control "' +
@@ -528,6 +646,9 @@ function assertNegativeControlFails(consumerDir: string): void {
528
646
  `Negative control "${negativeControl.description}" (${negativeControl.filename}) failed for an unexpected reason (wanted ${negativeControl.expectedCode}):\n${output}`,
529
647
  );
530
648
  }
649
+ console.log(
650
+ `Negative control rejected (${negativeControl.expectedCode}): ${negativeControl.description}`,
651
+ );
531
652
  }
532
653
  }
533
654
 
@@ -1,4 +1,4 @@
1
- export type OperationDeclarationRefusalReason = "no_safety" | "safety_conflict" | "locale_key_conflict" | "connection_mode_conflict" | "execution_conflict" | "approval_conflict" | "non_literal" | "unsupported_member" | "factory_composed_operations" | "source_syntax" | "codemod_syntax" | "missing_english_locale" | "operation_id_unresolved" | "examples_conflict" | "invalid_locale_key" | "locale_todo_conflict";
1
+ export type OperationDeclarationRefusalReason = "no_safety" | "safety_conflict" | "locale_key_conflict" | "connection_mode_conflict" | "execution_conflict" | "approval_conflict" | "non_literal" | "unsupported_member" | "factory_composed_operations" | "source_syntax" | "codemod_syntax" | "missing_english_locale" | "operation_id_unresolved" | "factory_operation_id_ambiguous" | "no_operations_discovered" | "examples_conflict" | "invalid_locale_key" | "locale_todo_conflict";
2
2
  export type OperationDeclarationRefusal = {
3
3
  readonly file: string;
4
4
  readonly operationKey: string;
@@ -51,6 +51,10 @@ export type OperationDeclarationRepositoryResult = {
51
51
  readonly status: "refused";
52
52
  readonly providerRoot: string;
53
53
  readonly refusals: readonly OperationDeclarationRefusal[];
54
+ /** Operations that were independently migratable before repository-atomic refusal. */
55
+ readonly operationCount: number;
56
+ readonly changedFiles: readonly string[];
57
+ readonly localeTodoCount: number;
54
58
  };
55
59
  /** Run the file transform repository-wide, committing writes only if every file is provable. */
56
60
  export declare function migrateOperationDeclarationRepository(providerRootInput: string, options?: {