@apifuse/provider-sdk 2.2.0-beta.26 → 2.2.0-beta.28

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 (90) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/bin/apifuse-dev.ts +2 -2
  3. package/bin/apifuse-pack-smoke.ts +1 -1
  4. package/bin/apifuse-pack-types.ts +2 -1
  5. package/bin/apifuse-perf.ts +2 -4
  6. package/bin/apifuse-record.ts +1 -1
  7. package/dist/auth-turn/index.d.ts +1 -1
  8. package/dist/auth-turn/index.js +1 -1
  9. package/dist/ceremonies/index.js +52 -11
  10. package/dist/config/loader.d.ts +1 -1
  11. package/dist/config/loader.js +4 -2
  12. package/dist/contract-serialization.d.ts +1 -20
  13. package/dist/contract-serialization.js +8 -587
  14. package/dist/contract.d.ts +0 -2
  15. package/dist/contract.js +5 -9
  16. package/dist/index.d.ts +9 -8
  17. package/dist/index.js +6 -8
  18. package/dist/provider.d.ts +3 -2
  19. package/dist/provider.js +2 -2
  20. package/dist/runtime/auth-flow.js +1 -1
  21. package/dist/runtime/http.d.ts +1 -0
  22. package/dist/runtime/http.js +135 -12
  23. package/dist/runtime/instrumentation.js +1 -1
  24. package/dist/runtime/native-network-errors.d.ts +33 -0
  25. package/dist/runtime/native-network-errors.js +69 -0
  26. package/dist/runtime/native-network.d.ts +2 -33
  27. package/dist/runtime/native-network.js +2 -68
  28. package/dist/runtime/redis.d.ts +1 -1
  29. package/dist/runtime/redis.js +4 -2
  30. package/dist/runtime/resolver-config.d.ts +6 -0
  31. package/dist/runtime/resolver-config.js +6 -0
  32. package/dist/runtime/resolver-shared.d.ts +3 -0
  33. package/dist/runtime/resolver-shared.js +12 -0
  34. package/dist/runtime/resolver-vendors/twocaptcha.d.ts +2 -1
  35. package/dist/runtime/resolver-vendors/twocaptcha.js +80 -43
  36. package/dist/runtime/resolver-vendors/types.d.ts +1 -1
  37. package/dist/runtime/resolver.d.ts +6 -10
  38. package/dist/runtime/resolver.js +19 -18
  39. package/dist/runtime/state.js +5 -115
  40. package/dist/runtime/stealth-cookies.d.ts +20 -0
  41. package/dist/runtime/stealth-cookies.js +111 -0
  42. package/dist/runtime/stealth.js +7 -130
  43. package/dist/schema.d.ts +0 -63
  44. package/dist/schema.js +8 -808
  45. package/dist/serve.d.ts +1 -1
  46. package/dist/serve.js +1 -1
  47. package/dist/server/index.d.ts +1 -1
  48. package/dist/server/index.js +1 -1
  49. package/dist/server/self-test.d.ts +13 -0
  50. package/dist/server/self-test.js +124 -46
  51. package/dist/server/serve-implementation.d.ts +199 -0
  52. package/dist/server/serve-implementation.js +2054 -0
  53. package/dist/server/serve.d.ts +1 -187
  54. package/dist/server/serve.js +1 -1827
  55. package/dist/stateful/errors.d.ts +5 -0
  56. package/dist/stateful/errors.js +10 -0
  57. package/dist/stateful/stateful-provider-session-routing.d.ts +1 -5
  58. package/dist/stateful/stateful-provider-session-routing.js +2 -10
  59. package/dist/stream.js +7 -1
  60. package/package.json +27 -2
  61. package/src/auth-turn/index.ts +1 -1
  62. package/src/ceremonies/index.ts +68 -18
  63. package/src/config/loader.ts +5 -2
  64. package/src/contract-serialization.ts +8 -859
  65. package/src/contract.ts +5 -16
  66. package/src/index.ts +18 -34
  67. package/src/provider.ts +12 -24
  68. package/src/runtime/auth-flow.ts +1 -1
  69. package/src/runtime/http.ts +155 -11
  70. package/src/runtime/instrumentation.ts +1 -1
  71. package/src/runtime/native-network-errors.ts +99 -0
  72. package/src/runtime/native-network.ts +16 -97
  73. package/src/runtime/redis.ts +7 -2
  74. package/src/runtime/resolver-config.ts +6 -0
  75. package/src/runtime/resolver-shared.ts +17 -0
  76. package/src/runtime/resolver-vendors/twocaptcha.ts +100 -49
  77. package/src/runtime/resolver-vendors/types.ts +1 -0
  78. package/src/runtime/resolver.ts +47 -22
  79. package/src/runtime/state.ts +5 -144
  80. package/src/runtime/stealth-cookies.ts +132 -0
  81. package/src/runtime/stealth.ts +14 -157
  82. package/src/schema.ts +9 -1060
  83. package/src/serve.ts +6 -1
  84. package/src/server/index.ts +1 -0
  85. package/src/server/self-test.ts +184 -59
  86. package/src/server/serve-implementation.ts +3024 -0
  87. package/src/server/serve.ts +1 -2661
  88. package/src/stateful/errors.ts +12 -0
  89. package/src/stateful/stateful-provider-session-routing.ts +2 -11
  90. package/src/stream.ts +8 -1
@@ -1,5 +1,17 @@
1
1
  export type StatefulControlPlaneOperation = "resolve" | "acquire" | "renew" | "release";
2
2
 
3
+ export class StatefulRoutingDeadlineError extends Error {
4
+ readonly requestId: string;
5
+ readonly deadlineAt: string;
6
+
7
+ constructor(requestId: string, deadlineAt: string) {
8
+ super(`Stateful operation request ${requestId} deadline has expired.`);
9
+ this.name = "StatefulRoutingDeadlineError";
10
+ this.requestId = requestId;
11
+ this.deadlineAt = deadlineAt;
12
+ }
13
+ }
14
+
3
15
  export class StatefulControlPlaneError extends Error {
4
16
  readonly code: string;
5
17
  readonly operation: StatefulControlPlaneOperation;
@@ -1,4 +1,5 @@
1
1
  import type { SessionKey } from "./session-key.js";
2
+ import { StatefulRoutingDeadlineError } from "./errors.js";
2
3
  import {
3
4
  NOOP_STATEFUL_PROVIDER_METRIC_EMITTER,
4
5
  type StatefulProviderMetricEmitter,
@@ -82,17 +83,7 @@ type DeadlineSignal = {
82
83
  readonly cleanup: () => void;
83
84
  };
84
85
 
85
- export class StatefulRoutingDeadlineError extends Error {
86
- readonly requestId: string;
87
- readonly deadlineAt: string;
88
-
89
- constructor(requestId: string, deadlineAt: string) {
90
- super(`Stateful operation request ${requestId} deadline has expired.`);
91
- this.name = "StatefulRoutingDeadlineError";
92
- this.requestId = requestId;
93
- this.deadlineAt = deadlineAt;
94
- }
95
- }
86
+ export { StatefulRoutingDeadlineError } from "./errors.js";
96
87
 
97
88
  export class StatefulRoutingOwnershipError extends Error {
98
89
  readonly requestId: string;
package/src/stream.ts CHANGED
@@ -85,13 +85,20 @@ function sseFieldValue(value: string, field: "event" | "id"): string {
85
85
 
86
86
  export async function* readableBytes(body: ReadableStream<Uint8Array>): AsyncIterable<Uint8Array> {
87
87
  const reader = body.getReader();
88
+ let completed = false;
88
89
  try {
89
90
  for (;;) {
90
91
  const { value, done } = await reader.read();
91
- if (done) return;
92
+ if (done) {
93
+ completed = true;
94
+ return;
95
+ }
92
96
  if (value) yield value;
93
97
  }
94
98
  } finally {
99
+ if (!completed) {
100
+ await reader.cancel().catch(() => undefined);
101
+ }
95
102
  reader.releaseLock();
96
103
  }
97
104
  }