polytomic 25.9.3 → 25.9.4

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 (117) hide show
  1. package/BaseClient.d.ts +15 -0
  2. package/BaseClient.js +17 -2
  3. package/api/errors/BadGatewayError.d.ts +1 -0
  4. package/api/errors/BadGatewayError.js +1 -1
  5. package/api/errors/BadRequestError.d.ts +1 -0
  6. package/api/errors/BadRequestError.js +1 -1
  7. package/api/errors/ConflictError.d.ts +1 -0
  8. package/api/errors/ConflictError.js +1 -1
  9. package/api/errors/ForbiddenError.d.ts +1 -0
  10. package/api/errors/ForbiddenError.js +1 -1
  11. package/api/errors/GatewayTimeoutError.d.ts +1 -0
  12. package/api/errors/GatewayTimeoutError.js +1 -1
  13. package/api/errors/InternalServerError.d.ts +1 -0
  14. package/api/errors/InternalServerError.js +1 -1
  15. package/api/errors/NotFoundError.d.ts +1 -0
  16. package/api/errors/NotFoundError.js +1 -1
  17. package/api/errors/RequestTimeoutError.d.ts +1 -0
  18. package/api/errors/RequestTimeoutError.js +1 -1
  19. package/api/errors/ServiceUnavailableError.d.ts +1 -0
  20. package/api/errors/ServiceUnavailableError.js +1 -1
  21. package/api/errors/TooManyRequestsError.d.ts +1 -0
  22. package/api/errors/TooManyRequestsError.js +1 -1
  23. package/api/errors/UnauthorizedError.d.ts +1 -0
  24. package/api/errors/UnauthorizedError.js +1 -1
  25. package/api/errors/UnprocessableEntityError.d.ts +1 -0
  26. package/api/errors/UnprocessableEntityError.js +1 -1
  27. package/api/resources/bulkSync/client/Client.d.ts +22 -0
  28. package/api/resources/bulkSync/client/Client.js +27 -4
  29. package/api/resources/bulkSync/resources/errorHandling/client/Client.d.ts +4 -0
  30. package/api/resources/bulkSync/resources/errorHandling/client/Client.js +6 -1
  31. package/api/resources/bulkSync/resources/executions/client/Client.d.ts +18 -0
  32. package/api/resources/bulkSync/resources/executions/client/Client.js +18 -0
  33. package/api/resources/bulkSync/resources/schedules/client/Client.d.ts +10 -0
  34. package/api/resources/bulkSync/resources/schedules/client/Client.js +13 -2
  35. package/api/resources/bulkSync/resources/schemas/client/Client.d.ts +10 -0
  36. package/api/resources/bulkSync/resources/schemas/client/Client.js +13 -2
  37. package/api/resources/bulkSync/resources/schemas/client/requests/SchemasListRequest.d.ts +1 -1
  38. package/api/resources/connections/client/Client.d.ts +26 -0
  39. package/api/resources/connections/client/Client.js +32 -5
  40. package/api/resources/connections/resources/proxy/client/Client.d.ts +8 -0
  41. package/api/resources/connections/resources/proxy/client/Client.js +11 -2
  42. package/api/resources/connections/resources/sharedConnections/client/Client.d.ts +6 -0
  43. package/api/resources/connections/resources/sharedConnections/client/Client.js +8 -1
  44. package/api/resources/entities/client/Client.d.ts +4 -0
  45. package/api/resources/entities/client/Client.js +4 -0
  46. package/api/resources/events/client/Client.d.ts +5 -0
  47. package/api/resources/events/client/Client.js +5 -0
  48. package/api/resources/harbors/client/Client.d.ts +67 -64
  49. package/api/resources/harbors/client/Client.js +77 -73
  50. package/api/resources/identity/client/Client.d.ts +2 -0
  51. package/api/resources/identity/client/Client.js +2 -0
  52. package/api/resources/jobs/client/Client.d.ts +2 -0
  53. package/api/resources/jobs/client/Client.js +2 -0
  54. package/api/resources/modelSync/client/Client.d.ts +24 -0
  55. package/api/resources/modelSync/client/Client.js +29 -4
  56. package/api/resources/modelSync/client/requests/ModelSyncGetSourceFieldsRequest.d.ts +1 -1
  57. package/api/resources/modelSync/client/requests/ModelSyncGetSourceRequest.d.ts +1 -1
  58. package/api/resources/modelSync/resources/errorHandling/client/Client.d.ts +4 -0
  59. package/api/resources/modelSync/resources/errorHandling/client/Client.js +6 -1
  60. package/api/resources/modelSync/resources/executions/client/Client.d.ts +14 -0
  61. package/api/resources/modelSync/resources/executions/client/Client.js +14 -0
  62. package/api/resources/modelSync/resources/targets/client/Client.d.ts +6 -0
  63. package/api/resources/modelSync/resources/targets/client/Client.js +6 -0
  64. package/api/resources/modelSync/resources/targets/client/requests/TargetsGetTargetFieldsRequest.d.ts +1 -1
  65. package/api/resources/models/client/Client.d.ts +18 -0
  66. package/api/resources/models/client/Client.js +23 -4
  67. package/api/resources/models/client/requests/ModelsGetEnrichmentSourceRequest.d.ts +1 -1
  68. package/api/resources/notifications/client/Client.d.ts +4 -0
  69. package/api/resources/notifications/client/Client.js +6 -1
  70. package/api/resources/organization/client/Client.d.ts +16 -0
  71. package/api/resources/organization/client/Client.js +20 -3
  72. package/api/resources/permissions/resources/policies/client/Client.d.ts +10 -0
  73. package/api/resources/permissions/resources/policies/client/Client.js +13 -2
  74. package/api/resources/permissions/resources/roles/client/Client.d.ts +10 -0
  75. package/api/resources/permissions/resources/roles/client/Client.js +13 -2
  76. package/api/resources/queryRunner/client/Client.d.ts +4 -0
  77. package/api/resources/queryRunner/client/Client.js +6 -1
  78. package/api/resources/recordViewLinks/client/Client.d.ts +4 -4
  79. package/api/resources/recordViewLinks/client/Client.js +6 -5
  80. package/api/resources/schemas/client/Client.d.ts +18 -0
  81. package/api/resources/schemas/client/Client.js +22 -3
  82. package/api/resources/temporaryCredentials/client/Client.d.ts +2 -2
  83. package/api/resources/temporaryCredentials/client/Client.js +4 -3
  84. package/api/resources/users/client/Client.d.ts +22 -0
  85. package/api/resources/users/client/Client.js +27 -4
  86. package/api/resources/webhooks/client/Client.d.ts +14 -0
  87. package/api/resources/webhooks/client/Client.js +17 -2
  88. package/api/types/ConnectionParameterValuesResponseEnvelope.d.ts +1 -1
  89. package/api/types/ConnectionProxyResponse.d.ts +1 -1
  90. package/api/types/HarborPipelineStatusResponse.d.ts +1 -1
  91. package/api/types/HarborSourceMappingResponse.d.ts +1 -1
  92. package/api/types/SyncSourceMetaResponse.d.ts +1 -1
  93. package/core/auth/AuthProvider.d.ts +1 -0
  94. package/core/auth/AuthProvider.js +7 -0
  95. package/core/auth/index.d.ts +1 -1
  96. package/core/auth/index.js +3 -1
  97. package/core/fetcher/Fetcher.js +9 -92
  98. package/core/fetcher/getResponseBody.js +11 -0
  99. package/core/fetcher/makePassthroughRequest.js +26 -4
  100. package/core/fetcher/redactUrl.d.ts +2 -0
  101. package/core/fetcher/redactUrl.js +88 -0
  102. package/core/fetcher/requestWithRetries.js +4 -1
  103. package/core/fetcher/signals.js +9 -1
  104. package/core/requestBody.d.ts +12 -0
  105. package/core/requestBody.js +26 -0
  106. package/core/runtime/index.d.ts +1 -1
  107. package/core/runtime/index.js +2 -1
  108. package/core/runtime/runtime.d.ts +19 -0
  109. package/core/runtime/runtime.js +74 -2
  110. package/core/url/qs.js +2 -2
  111. package/errors/PolytomicError.d.ts +1 -0
  112. package/errors/PolytomicError.js +5 -1
  113. package/errors/PolytomicTimeoutError.d.ts +2 -2
  114. package/errors/PolytomicTimeoutError.js +40 -6
  115. package/package.json +2 -2
  116. package/version.d.ts +1 -1
  117. package/version.js +1 -1
@@ -47,6 +47,7 @@ exports.WebhooksClient = void 0;
47
47
  const BaseClient_1 = require("../../../../BaseClient");
48
48
  const core = __importStar(require("../../../../core"));
49
49
  const headers_1 = require("../../../../core/headers");
50
+ const requestBody_1 = require("../../../../core/requestBody");
50
51
  const environments = __importStar(require("../../../../environments"));
51
52
  const handleNonStatusCodeError_1 = require("../../../../errors/handleNonStatusCodeError");
52
53
  const errors = __importStar(require("../../../../errors/index"));
@@ -68,6 +69,8 @@ class WebhooksClient {
68
69
  * @param {WebhooksClient.RequestOptions} requestOptions - Request-specific configuration.
69
70
  *
70
71
  * @throws {@link Polytomic.InternalServerError}
72
+ * @throws {@link errors.PolytomicError}
73
+ * @throws {@link errors.PolytomicTimeoutError}
71
74
  *
72
75
  * @example
73
76
  * await client.webhooks.list()
@@ -127,6 +130,8 @@ class WebhooksClient {
127
130
  * @throws {@link Polytomic.UnauthorizedError}
128
131
  * @throws {@link Polytomic.UnprocessableEntityError}
129
132
  * @throws {@link Polytomic.InternalServerError}
133
+ * @throws {@link errors.PolytomicError}
134
+ * @throws {@link errors.PolytomicTimeoutError}
130
135
  *
131
136
  * @example
132
137
  * await client.webhooks.create({
@@ -152,7 +157,7 @@ class WebhooksClient {
152
157
  contentType: "application/json",
153
158
  queryString: core.url.queryBuilder().mergeAdditional(requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams).build(),
154
159
  requestType: "json",
155
- body: request,
160
+ body: (0, requestBody_1.mergeAdditionalBodyParameters)(request, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.additionalBodyParameters),
156
161
  timeoutMs: ((_j = (_g = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _g !== void 0 ? _g : (_h = this._options) === null || _h === void 0 ? void 0 : _h.timeoutInSeconds) !== null && _j !== void 0 ? _j : 60) * 1000,
157
162
  maxRetries: (_k = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _k !== void 0 ? _k : (_l = this._options) === null || _l === void 0 ? void 0 : _l.maxRetries,
158
163
  abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
@@ -195,6 +200,8 @@ class WebhooksClient {
195
200
  * @param {WebhooksClient.RequestOptions} requestOptions - Request-specific configuration.
196
201
  *
197
202
  * @throws {@link Polytomic.NotFoundError}
203
+ * @throws {@link errors.PolytomicError}
204
+ * @throws {@link errors.PolytomicTimeoutError}
198
205
  *
199
206
  * @example
200
207
  * await client.webhooks.get("248df4b7-aa70-47b8-a036-33ac447e668d")
@@ -255,6 +262,8 @@ class WebhooksClient {
255
262
  * @throws {@link Polytomic.UnauthorizedError}
256
263
  * @throws {@link Polytomic.UnprocessableEntityError}
257
264
  * @throws {@link Polytomic.InternalServerError}
265
+ * @throws {@link errors.PolytomicError}
266
+ * @throws {@link errors.PolytomicTimeoutError}
258
267
  *
259
268
  * @example
260
269
  * await client.webhooks.update("248df4b7-aa70-47b8-a036-33ac447e668d", {
@@ -280,7 +289,7 @@ class WebhooksClient {
280
289
  contentType: "application/json",
281
290
  queryString: core.url.queryBuilder().mergeAdditional(requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams).build(),
282
291
  requestType: "json",
283
- body: request,
292
+ body: (0, requestBody_1.mergeAdditionalBodyParameters)(request, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.additionalBodyParameters),
284
293
  timeoutMs: ((_j = (_g = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _g !== void 0 ? _g : (_h = this._options) === null || _h === void 0 ? void 0 : _h.timeoutInSeconds) !== null && _j !== void 0 ? _j : 60) * 1000,
285
294
  maxRetries: (_k = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _k !== void 0 ? _k : (_l = this._options) === null || _l === void 0 ? void 0 : _l.maxRetries,
286
295
  abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
@@ -328,6 +337,8 @@ class WebhooksClient {
328
337
  *
329
338
  * @throws {@link Polytomic.NotFoundError}
330
339
  * @throws {@link Polytomic.InternalServerError}
340
+ * @throws {@link errors.PolytomicError}
341
+ * @throws {@link errors.PolytomicTimeoutError}
331
342
  *
332
343
  * @example
333
344
  * await client.webhooks.delete("248df4b7-aa70-47b8-a036-33ac447e668d")
@@ -395,6 +406,8 @@ class WebhooksClient {
395
406
  * @throws {@link Polytomic.UnauthorizedError}
396
407
  * @throws {@link Polytomic.NotFoundError}
397
408
  * @throws {@link Polytomic.InternalServerError}
409
+ * @throws {@link errors.PolytomicError}
410
+ * @throws {@link errors.PolytomicTimeoutError}
398
411
  *
399
412
  * @example
400
413
  * await client.webhooks.disable("248df4b7-aa70-47b8-a036-33ac447e668d")
@@ -462,6 +475,8 @@ class WebhooksClient {
462
475
  * @throws {@link Polytomic.UnauthorizedError}
463
476
  * @throws {@link Polytomic.NotFoundError}
464
477
  * @throws {@link Polytomic.InternalServerError}
478
+ * @throws {@link errors.PolytomicError}
479
+ * @throws {@link errors.PolytomicTimeoutError}
465
480
  *
466
481
  * @example
467
482
  * await client.webhooks.enable("248df4b7-aa70-47b8-a036-33ac447e668d")
@@ -1,4 +1,4 @@
1
1
  import type * as Polytomic from "../index";
2
2
  export interface ConnectionParameterValuesResponseEnvelope {
3
- data?: Record<string, Polytomic.ConnectionParameterValuesResp> | undefined;
3
+ data?: Record<string, Polytomic.ConnectionParameterValuesResp | undefined> | undefined;
4
4
  }
@@ -5,7 +5,7 @@ export interface ConnectionProxyResponse {
5
5
  /** Content-Type of the upstream response. */
6
6
  contentType?: string | undefined;
7
7
  /** Response headers returned by the upstream service. Headers listed in blockedResponseHeaders are removed. */
8
- headers?: Record<string, string> | undefined;
8
+ headers?: Record<string, string | undefined> | undefined;
9
9
  /** Identifier for the async proxy job when async is true. */
10
10
  jobId?: string | undefined;
11
11
  jobStatus?: Polytomic.WorkTaskStatus | undefined;
@@ -1,7 +1,7 @@
1
1
  import type * as Polytomic from "../index";
2
2
  export interface HarborPipelineStatusResponse {
3
3
  /** Dataset refresh evidence keyed by the effective destination name visible to Harbor queries. */
4
- datasets?: Record<string, Polytomic.HarborDatasetStatusResponse> | undefined;
4
+ datasets?: Record<string, Polytomic.HarborDatasetStatusResponse | undefined> | undefined;
5
5
  /** Unique identifier of the Polytomic pipeline. */
6
6
  id: string;
7
7
  /** Whether this pipeline is enabled. */
@@ -2,7 +2,7 @@ export interface HarborSourceMappingResponse {
2
2
  /** Qualified table name in the Harbor's backing Connection. Empty unless status is resolved. */
3
3
  destination_schema_id?: string | undefined;
4
4
  /** Requested source field identifiers mapped to their destination names. A requested field that was not materialized is absent. */
5
- fields?: Record<string, string> | undefined;
5
+ fields?: Record<string, string | undefined> | undefined;
6
6
  /** resolved when exactly one completed materialization was found, unresolved when none was, ambiguous when more than one was. */
7
7
  status?: string | undefined;
8
8
  }
@@ -3,7 +3,7 @@ export interface SyncSourceMetaResponse {
3
3
  /** Additional configuration fields available for this source, keyed by field name. */
4
4
  configuration?: Record<string, Polytomic.ConfigurationValue> | undefined;
5
5
  /** Map of configuration item name to its metadata (available values, required-one-of groups). */
6
- items?: Record<string, Polytomic.SourceMeta> | undefined;
6
+ items?: Record<string, Polytomic.SourceMeta | undefined> | undefined;
7
7
  /** Configuration items where exactly one must be selected by the caller. */
8
8
  requires_one_of?: string[] | undefined;
9
9
  }
@@ -5,3 +5,4 @@ export interface AuthProvider {
5
5
  endpointMetadata?: EndpointMetadata;
6
6
  }): Promise<AuthRequest>;
7
7
  }
8
+ export declare function isAuthProvider(value: unknown): value is AuthProvider;
@@ -1,2 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isAuthProvider = isAuthProvider;
4
+ function isAuthProvider(value) {
5
+ return (typeof value === "object" &&
6
+ value !== null &&
7
+ "getAuthRequest" in value &&
8
+ typeof value.getAuthRequest === "function");
9
+ }
@@ -1,4 +1,4 @@
1
- export type { AuthProvider } from "./AuthProvider";
1
+ export { type AuthProvider, isAuthProvider } from "./AuthProvider";
2
2
  export type { AuthRequest } from "./AuthRequest";
3
3
  export { BasicAuth } from "./BasicAuth";
4
4
  export { BearerToken } from "./BearerToken";
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NoOpAuthProvider = exports.BearerToken = exports.BasicAuth = void 0;
3
+ exports.NoOpAuthProvider = exports.BearerToken = exports.BasicAuth = exports.isAuthProvider = void 0;
4
+ var AuthProvider_1 = require("./AuthProvider");
5
+ Object.defineProperty(exports, "isAuthProvider", { enumerable: true, get: function () { return AuthProvider_1.isAuthProvider; } });
4
6
  var BasicAuth_1 = require("./BasicAuth");
5
7
  Object.defineProperty(exports, "BasicAuth", { enumerable: true, get: function () { return BasicAuth_1.BasicAuth; } });
6
8
  var BearerToken_1 = require("./BearerToken");
@@ -22,6 +22,7 @@ const getResponseBody_1 = require("./getResponseBody");
22
22
  const Headers_1 = require("./Headers");
23
23
  const makeRequest_1 = require("./makeRequest");
24
24
  const RawResponse_1 = require("./RawResponse");
25
+ const redactUrl_1 = require("./redactUrl");
25
26
  const requestWithRetries_1 = require("./requestWithRetries");
26
27
  const SENSITIVE_HEADERS = new Set([
27
28
  "authorization",
@@ -53,100 +54,16 @@ function redactHeaders(headers) {
53
54
  }
54
55
  return filtered;
55
56
  }
56
- const SENSITIVE_QUERY_PARAMS = new Set([
57
- "api_key",
58
- "api-key",
59
- "apikey",
60
- "token",
61
- "access_token",
62
- "access-token",
63
- "auth_token",
64
- "auth-token",
65
- "password",
66
- "passwd",
67
- "secret",
68
- "api_secret",
69
- "api-secret",
70
- "apisecret",
71
- "key",
72
- "session",
73
- "session_id",
74
- "session-id",
75
- ]);
76
57
  function redactQueryParameters(queryParameters) {
77
58
  if (queryParameters == null) {
78
59
  return undefined;
79
60
  }
80
61
  const redacted = {};
81
62
  for (const [key, value] of Object.entries(queryParameters)) {
82
- redacted[key] = SENSITIVE_QUERY_PARAMS.has(key.toLowerCase()) ? "[REDACTED]" : value;
63
+ redacted[key] = redactUrl_1.SENSITIVE_QUERY_PARAMS.has(key.toLowerCase()) ? "[REDACTED]" : value;
83
64
  }
84
65
  return redacted;
85
66
  }
86
- function redactUrl(url) {
87
- const protocolIndex = url.indexOf("://");
88
- if (protocolIndex === -1)
89
- return url;
90
- const afterProtocol = protocolIndex + 3;
91
- // Find the first delimiter that marks the end of the authority section
92
- const pathStart = url.indexOf("/", afterProtocol);
93
- let queryStart = url.indexOf("?", afterProtocol);
94
- let fragmentStart = url.indexOf("#", afterProtocol);
95
- const firstDelimiter = Math.min(pathStart === -1 ? url.length : pathStart, queryStart === -1 ? url.length : queryStart, fragmentStart === -1 ? url.length : fragmentStart);
96
- // Find the LAST @ before the delimiter (handles multiple @ in credentials)
97
- let atIndex = -1;
98
- for (let i = afterProtocol; i < firstDelimiter; i++) {
99
- if (url[i] === "@") {
100
- atIndex = i;
101
- }
102
- }
103
- if (atIndex !== -1) {
104
- url = `${url.slice(0, afterProtocol)}[REDACTED]@${url.slice(atIndex + 1)}`;
105
- }
106
- // Recalculate queryStart since url might have changed
107
- queryStart = url.indexOf("?");
108
- if (queryStart === -1)
109
- return url;
110
- fragmentStart = url.indexOf("#", queryStart);
111
- const queryEnd = fragmentStart !== -1 ? fragmentStart : url.length;
112
- const queryString = url.slice(queryStart + 1, queryEnd);
113
- if (queryString.length === 0)
114
- return url;
115
- // FAST PATH: Quick check if any sensitive keywords present
116
- // Using indexOf is faster than regex for simple substring matching
117
- const lower = queryString.toLowerCase();
118
- const hasSensitive = lower.includes("token") ||
119
- lower.includes("key") ||
120
- lower.includes("password") ||
121
- lower.includes("passwd") ||
122
- lower.includes("secret") ||
123
- lower.includes("session") ||
124
- lower.includes("auth");
125
- if (!hasSensitive) {
126
- return url;
127
- }
128
- // SLOW PATH: Parse and redact
129
- const redactedParams = [];
130
- const params = queryString.split("&");
131
- for (const param of params) {
132
- const equalIndex = param.indexOf("=");
133
- if (equalIndex === -1) {
134
- redactedParams.push(param);
135
- continue;
136
- }
137
- const key = param.slice(0, equalIndex);
138
- let shouldRedact = SENSITIVE_QUERY_PARAMS.has(key.toLowerCase());
139
- if (!shouldRedact && key.includes("%")) {
140
- try {
141
- const decodedKey = decodeURIComponent(key);
142
- shouldRedact = SENSITIVE_QUERY_PARAMS.has(decodedKey.toLowerCase());
143
- }
144
- catch (_a) { }
145
- }
146
- redactedParams.push(shouldRedact ? `${key}=[REDACTED]` : param);
147
- }
148
- return url.slice(0, queryStart + 1) + redactedParams.join("&") + url.slice(queryEnd);
149
- }
150
67
  function getHeaders(args) {
151
68
  return __awaiter(this, void 0, void 0, function* () {
152
69
  var _a;
@@ -198,7 +115,7 @@ function fetcherImpl(args) {
198
115
  if (logger.isDebug()) {
199
116
  const metadata = {
200
117
  method: args.method,
201
- url: redactUrl(url),
118
+ url: (0, redactUrl_1.redactUrl)(url),
202
119
  headers: redactHeaders(headers),
203
120
  queryParameters: redactQueryParameters(args.queryParameters),
204
121
  hasBody: requestBody != null,
@@ -213,7 +130,7 @@ function fetcherImpl(args) {
213
130
  if (logger.isDebug()) {
214
131
  const metadata = {
215
132
  method: args.method,
216
- url: redactUrl(url),
133
+ url: (0, redactUrl_1.redactUrl)(url),
217
134
  statusCode: response.status,
218
135
  responseHeaders: redactHeaders(response.headers),
219
136
  };
@@ -231,7 +148,7 @@ function fetcherImpl(args) {
231
148
  if (logger.isError()) {
232
149
  const metadata = {
233
150
  method: args.method,
234
- url: redactUrl(url),
151
+ url: (0, redactUrl_1.redactUrl)(url),
235
152
  statusCode: response.status,
236
153
  responseHeaders: redactHeaders(Object.fromEntries(response.headers.entries())),
237
154
  };
@@ -253,7 +170,7 @@ function fetcherImpl(args) {
253
170
  if (logger.isError()) {
254
171
  const metadata = {
255
172
  method: args.method,
256
- url: redactUrl(url),
173
+ url: (0, redactUrl_1.redactUrl)(url),
257
174
  };
258
175
  logger.error("HTTP request was aborted", metadata);
259
176
  }
@@ -271,7 +188,7 @@ function fetcherImpl(args) {
271
188
  if (logger.isError()) {
272
189
  const metadata = {
273
190
  method: args.method,
274
- url: redactUrl(url),
191
+ url: (0, redactUrl_1.redactUrl)(url),
275
192
  timeoutMs: args.timeoutMs,
276
193
  };
277
194
  logger.error("HTTP request timed out", metadata);
@@ -289,7 +206,7 @@ function fetcherImpl(args) {
289
206
  if (logger.isError()) {
290
207
  const metadata = {
291
208
  method: args.method,
292
- url: redactUrl(url),
209
+ url: (0, redactUrl_1.redactUrl)(url),
293
210
  errorMessage: error.message,
294
211
  };
295
212
  logger.error("HTTP request failed with error", metadata);
@@ -307,7 +224,7 @@ function fetcherImpl(args) {
307
224
  if (logger.isError()) {
308
225
  const metadata = {
309
226
  method: args.method,
310
- url: redactUrl(url),
227
+ url: (0, redactUrl_1.redactUrl)(url),
311
228
  error: (0, json_1.toJson)(error),
312
229
  };
313
230
  logger.error("HTTP request failed with unknown error", metadata);
@@ -12,6 +12,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.getResponseBody = getResponseBody;
13
13
  const json_1 = require("../json");
14
14
  const BinaryResponse_1 = require("./BinaryResponse");
15
+ // Pins the upstream Response so undici's FinalizationRegistry can't GC it and cancel the body stream.
16
+ function retainResponse(target, response) {
17
+ Object.defineProperty(target, "__fern_response_ref", {
18
+ value: response,
19
+ enumerable: false,
20
+ configurable: true,
21
+ writable: false,
22
+ });
23
+ }
15
24
  function getResponseBody(response, responseType) {
16
25
  return __awaiter(this, void 0, void 0, function* () {
17
26
  switch (responseType) {
@@ -31,6 +40,7 @@ function getResponseBody(response, responseType) {
31
40
  },
32
41
  };
33
42
  }
43
+ retainResponse(response.body, response);
34
44
  return response.body;
35
45
  case "streaming":
36
46
  if (response.body == null) {
@@ -42,6 +52,7 @@ function getResponseBody(response, responseType) {
42
52
  },
43
53
  };
44
54
  }
55
+ retainResponse(response.body, response);
45
56
  return response.body;
46
57
  case "text":
47
58
  return yield response.text();
@@ -15,6 +15,7 @@ const join_1 = require("../url/join");
15
15
  const EndpointSupplier_1 = require("./EndpointSupplier");
16
16
  const getFetchFn_1 = require("./getFetchFn");
17
17
  const makeRequest_1 = require("./makeRequest");
18
+ const redactUrl_1 = require("./redactUrl");
18
19
  const requestWithRetries_1 = require("./requestWithRetries");
19
20
  const Supplier_1 = require("./Supplier");
20
21
  /**
@@ -79,8 +80,10 @@ function makePassthroughRequest(input, init, clientOptions, requestOptions) {
79
80
  }
80
81
  }
81
82
  }
82
- // Apply auth headers
83
- if (clientOptions.getAuthHeaders != null) {
83
+ // Apply auth headers, but only when the resolved URL targets the configured base URL.
84
+ // This prevents the SDK's credentials from leaking to an unrelated host when a caller
85
+ // passes an absolute cross-origin URL into the passthrough fetch escape hatch.
86
+ if (clientOptions.getAuthHeaders != null && targetsBaseUrl(fullUrl, baseUrl)) {
84
87
  const authHeaders = yield clientOptions.getAuthHeaders();
85
88
  for (const [key, value] of Object.entries(authHeaders)) {
86
89
  mergedHeaders[key.toLowerCase()] = value;
@@ -115,7 +118,7 @@ function makePassthroughRequest(input, init, clientOptions, requestOptions) {
115
118
  if (logger.isDebug()) {
116
119
  logger.debug("Making passthrough HTTP request", {
117
120
  method,
118
- url: fullUrl,
121
+ url: (0, redactUrl_1.redactUrl)(fullUrl),
119
122
  hasBody: body != null,
120
123
  });
121
124
  }
@@ -126,10 +129,29 @@ function makePassthroughRequest(input, init, clientOptions, requestOptions) {
126
129
  if (logger.isDebug()) {
127
130
  logger.debug("Passthrough HTTP request completed", {
128
131
  method,
129
- url: fullUrl,
132
+ url: (0, redactUrl_1.redactUrl)(fullUrl),
130
133
  statusCode: response.status,
131
134
  });
132
135
  }
133
136
  return response;
134
137
  });
135
138
  }
139
+ /**
140
+ * Returns true when the resolved request URL points at the same origin as the
141
+ * configured base URL. Relative paths are always joined onto the base URL, so
142
+ * they resolve to the base origin and return true. Absolute URLs only match when
143
+ * their origin equals the base origin. When there is no base URL to compare
144
+ * against, or either value is not a parseable absolute URL, this returns false so
145
+ * auth headers are not attached.
146
+ */
147
+ function targetsBaseUrl(fullUrl, baseUrl) {
148
+ if (baseUrl == null) {
149
+ return false;
150
+ }
151
+ try {
152
+ return new URL(fullUrl).origin === new URL(baseUrl).origin;
153
+ }
154
+ catch (_a) {
155
+ return false;
156
+ }
157
+ }
@@ -0,0 +1,2 @@
1
+ export declare const SENSITIVE_QUERY_PARAMS: Set<string>;
2
+ export declare function redactUrl(url: string): string;
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SENSITIVE_QUERY_PARAMS = void 0;
4
+ exports.redactUrl = redactUrl;
5
+ exports.SENSITIVE_QUERY_PARAMS = new Set([
6
+ "api_key",
7
+ "api-key",
8
+ "apikey",
9
+ "token",
10
+ "access_token",
11
+ "access-token",
12
+ "auth_token",
13
+ "auth-token",
14
+ "password",
15
+ "passwd",
16
+ "secret",
17
+ "api_secret",
18
+ "api-secret",
19
+ "apisecret",
20
+ "key",
21
+ "session",
22
+ "session_id",
23
+ "session-id",
24
+ ]);
25
+ function redactUrl(url) {
26
+ const protocolIndex = url.indexOf("://");
27
+ if (protocolIndex === -1)
28
+ return url;
29
+ const afterProtocol = protocolIndex + 3;
30
+ // Find the first delimiter that marks the end of the authority section
31
+ const pathStart = url.indexOf("/", afterProtocol);
32
+ let queryStart = url.indexOf("?", afterProtocol);
33
+ let fragmentStart = url.indexOf("#", afterProtocol);
34
+ const firstDelimiter = Math.min(pathStart === -1 ? url.length : pathStart, queryStart === -1 ? url.length : queryStart, fragmentStart === -1 ? url.length : fragmentStart);
35
+ // Find the LAST @ before the delimiter (handles multiple @ in credentials)
36
+ let atIndex = -1;
37
+ for (let i = afterProtocol; i < firstDelimiter; i++) {
38
+ if (url[i] === "@") {
39
+ atIndex = i;
40
+ }
41
+ }
42
+ if (atIndex !== -1) {
43
+ url = `${url.slice(0, afterProtocol)}[REDACTED]@${url.slice(atIndex + 1)}`;
44
+ }
45
+ // Recalculate queryStart since url might have changed
46
+ queryStart = url.indexOf("?");
47
+ if (queryStart === -1)
48
+ return url;
49
+ fragmentStart = url.indexOf("#", queryStart);
50
+ const queryEnd = fragmentStart !== -1 ? fragmentStart : url.length;
51
+ const queryString = url.slice(queryStart + 1, queryEnd);
52
+ if (queryString.length === 0)
53
+ return url;
54
+ // FAST PATH: Quick check if any sensitive keywords present
55
+ // Using indexOf is faster than regex for simple substring matching
56
+ const lower = queryString.toLowerCase();
57
+ const hasSensitive = lower.includes("token") ||
58
+ lower.includes("key") ||
59
+ lower.includes("password") ||
60
+ lower.includes("passwd") ||
61
+ lower.includes("secret") ||
62
+ lower.includes("session") ||
63
+ lower.includes("auth");
64
+ if (!hasSensitive) {
65
+ return url;
66
+ }
67
+ // SLOW PATH: Parse and redact
68
+ const redactedParams = [];
69
+ const params = queryString.split("&");
70
+ for (const param of params) {
71
+ const equalIndex = param.indexOf("=");
72
+ if (equalIndex === -1) {
73
+ redactedParams.push(param);
74
+ continue;
75
+ }
76
+ const key = param.slice(0, equalIndex);
77
+ let shouldRedact = exports.SENSITIVE_QUERY_PARAMS.has(key.toLowerCase());
78
+ if (!shouldRedact && key.includes("%")) {
79
+ try {
80
+ const decodedKey = decodeURIComponent(key);
81
+ shouldRedact = exports.SENSITIVE_QUERY_PARAMS.has(decodedKey.toLowerCase());
82
+ }
83
+ catch (_a) { }
84
+ }
85
+ redactedParams.push(shouldRedact ? `${key}=[REDACTED]` : param);
86
+ }
87
+ return url.slice(0, queryStart + 1) + redactedParams.join("&") + url.slice(queryEnd);
88
+ }
@@ -14,6 +14,9 @@ const INITIAL_RETRY_DELAY = 1000; // in milliseconds
14
14
  const MAX_RETRY_DELAY = 60000; // in milliseconds
15
15
  const DEFAULT_MAX_RETRIES = 2;
16
16
  const JITTER_FACTOR = 0.2; // 20% random jitter
17
+ function isRetryableStatusCode(statusCode) {
18
+ return [408, 429].includes(statusCode) || statusCode >= 500;
19
+ }
17
20
  function addPositiveJitter(delay) {
18
21
  const jitterMultiplier = 1 + Math.random() * JITTER_FACTOR;
19
22
  return delay * jitterMultiplier;
@@ -53,7 +56,7 @@ function requestWithRetries(requestFn_1) {
53
56
  return __awaiter(this, arguments, void 0, function* (requestFn, maxRetries = DEFAULT_MAX_RETRIES) {
54
57
  let response = yield requestFn();
55
58
  for (let i = 0; i < maxRetries; ++i) {
56
- if ([408, 429].includes(response.status) || response.status >= 500) {
59
+ if (isRetryableStatusCode(response.status)) {
57
60
  const delay = getRetryDelayFromHeaders(response, i);
58
61
  yield new Promise((resolve) => setTimeout(resolve, delay));
59
62
  response = yield requestFn();
@@ -14,11 +14,19 @@ function anySignal(...args) {
14
14
  for (const signal of signals) {
15
15
  if (signal.aborted) {
16
16
  controller.abort(signal === null || signal === void 0 ? void 0 : signal.reason);
17
- break;
17
+ return controller.signal;
18
18
  }
19
19
  signal.addEventListener("abort", () => controller.abort(signal === null || signal === void 0 ? void 0 : signal.reason), {
20
20
  signal: controller.signal,
21
21
  });
22
+ // Re-check after adding listener: the signal may have aborted
23
+ // between the initial `signal.aborted` check and the `addEventListener`
24
+ // call above. If it did, the abort event was already dispatched and
25
+ // the listener will never fire — we must manually abort.
26
+ if (signal.aborted) {
27
+ controller.abort(signal === null || signal === void 0 ? void 0 : signal.reason);
28
+ return controller.signal;
29
+ }
22
30
  }
23
31
  return controller.signal;
24
32
  }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Spreads caller-supplied `additionalBodyParameters` (from `requestOptions.additionalBodyParameters`)
3
+ * on top of the request body. Caller-supplied properties win over the endpoint body. When no
4
+ * additional body parameters are provided, the original body is returned unchanged so serialization
5
+ * is unaffected.
6
+ *
7
+ * The merge only applies to plain-object (JSON object) bodies. When the body is `null`/`undefined`
8
+ * the additional parameters become the body; when the body is an array or a primitive JSON value it
9
+ * is returned unchanged, since object properties cannot be spread into it. This mirrors the Python
10
+ * SDK, which only merges additional body parameters into mapping bodies.
11
+ */
12
+ export declare function mergeAdditionalBodyParameters(body: unknown, additionalBodyParameters: Record<string, unknown> | undefined): unknown;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mergeAdditionalBodyParameters = mergeAdditionalBodyParameters;
4
+ /**
5
+ * Spreads caller-supplied `additionalBodyParameters` (from `requestOptions.additionalBodyParameters`)
6
+ * on top of the request body. Caller-supplied properties win over the endpoint body. When no
7
+ * additional body parameters are provided, the original body is returned unchanged so serialization
8
+ * is unaffected.
9
+ *
10
+ * The merge only applies to plain-object (JSON object) bodies. When the body is `null`/`undefined`
11
+ * the additional parameters become the body; when the body is an array or a primitive JSON value it
12
+ * is returned unchanged, since object properties cannot be spread into it. This mirrors the Python
13
+ * SDK, which only merges additional body parameters into mapping bodies.
14
+ */
15
+ function mergeAdditionalBodyParameters(body, additionalBodyParameters) {
16
+ if (additionalBodyParameters == null) {
17
+ return body;
18
+ }
19
+ if (body == null) {
20
+ return Object.assign({}, additionalBodyParameters);
21
+ }
22
+ if (typeof body === "object" && !Array.isArray(body)) {
23
+ return Object.assign(Object.assign({}, body), additionalBodyParameters);
24
+ }
25
+ return body;
26
+ }
@@ -1 +1 @@
1
- export { RUNTIME } from "./runtime";
1
+ export { getUserAgent, RUNTIME } from "./runtime";
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RUNTIME = void 0;
3
+ exports.RUNTIME = exports.getUserAgent = void 0;
4
4
  var runtime_1 = require("./runtime");
5
+ Object.defineProperty(exports, "getUserAgent", { enumerable: true, get: function () { return runtime_1.getUserAgent; } });
5
6
  Object.defineProperty(exports, "RUNTIME", { enumerable: true, get: function () { return runtime_1.RUNTIME; } });
@@ -6,4 +6,23 @@ export interface Runtime {
6
6
  type: "browser" | "web-worker" | "deno" | "bun" | "node" | "react-native" | "unknown" | "workerd" | "edge-runtime";
7
7
  version?: string;
8
8
  parsedVersion?: number;
9
+ /**
10
+ * The operating system the SDK is running on, when it can be determined
11
+ * (e.g. "linux", "darwin", "win32" on server runtimes). Undefined in
12
+ * environments where the OS is not observable (e.g. browsers).
13
+ */
14
+ os?: string;
15
+ /**
16
+ * The CPU architecture the SDK is running on, when it can be determined
17
+ * (e.g. "x64", "arm64" on server runtimes). Undefined in environments where
18
+ * the architecture is not observable (e.g. browsers).
19
+ */
20
+ arch?: string;
9
21
  }
22
+ /**
23
+ * Builds a structured User-Agent string of the form
24
+ * `{sdkName}/{sdkVersion} ({os}; {arch}) {runtime}/{runtimeVersion}`
25
+ * where the platform group and runtime segment are omitted gracefully when the
26
+ * underlying values cannot be determined (e.g. in a browser).
27
+ */
28
+ export declare function getUserAgent(sdkName: string, sdkVersion: string): string;