@posty5/social-publisher-post 4.2.0 → 5.1.0

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.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import crypto from 'crypto';
2
- import url from 'url';
2
+ import url, { domainToASCII } from 'url';
3
3
  import http from 'http';
4
4
  import https from 'https';
5
5
  import http2 from 'http2';
@@ -11734,8 +11734,14 @@ var require_follow_redirects = __commonJS({
11734
11734
  RedirectableRequest.prototype._sanitizeOptions = function(options) {
11735
11735
  if (!options.headers) {
11736
11736
  options.headers = {};
11737
+ } else if (Array.isArray(options.headers)) {
11738
+ var headerList = options.headers;
11739
+ options.headers = {};
11740
+ for (var i = 0; i < headerList.length; i += 2) {
11741
+ options.headers[headerList[i]] = headerList[i + 1];
11742
+ }
11737
11743
  }
11738
- if (!isArray2(options.sensitiveHeaders)) {
11744
+ if (!Array.isArray(options.sensitiveHeaders)) {
11739
11745
  options.sensitiveHeaders = [];
11740
11746
  }
11741
11747
  if (options.host) {
@@ -11992,9 +11998,6 @@ var require_follow_redirects = __commonJS({
11992
11998
  var dot = subdomain.length - domain.length - 1;
11993
11999
  return dot > 0 && subdomain[dot] === "." && subdomain.endsWith(domain);
11994
12000
  }
11995
- function isArray2(value) {
11996
- return value instanceof Array;
11997
- }
11998
12001
  function isString2(value) {
11999
12002
  return typeof value === "string" || value instanceof String;
12000
12003
  }
@@ -12008,7 +12011,7 @@ var require_follow_redirects = __commonJS({
12008
12011
  return URL2 && value instanceof URL2;
12009
12012
  }
12010
12013
  function escapeRegex(regex) {
12011
- return regex.replace(/[\]\\/()*+?.$]/g, "\\$&");
12014
+ return regex.replace(/[[\]\\/()*+?.^$|]/g, "\\$&");
12012
12015
  }
12013
12016
  module.exports = wrap({ http: http3, https: https2 });
12014
12017
  module.exports.wrap = wrap;
@@ -12177,10 +12180,16 @@ var isPlainObject = (val) => {
12177
12180
  return false;
12178
12181
  }
12179
12182
  const prototype2 = getPrototypeOf(val);
12180
- return (prototype2 === null || prototype2 === Object.prototype || getPrototypeOf(prototype2) === null) && // Treat safe own/inherited Symbol.toStringTag or Symbol.iterator members as
12181
- // evidence the value is tagged/iterable, while ignoring members reachable
12182
- // only through shared or terminal prototype boundaries.
12183
- !hasOwnInPrototypeChain(val, toStringTag) && !hasOwnInPrototypeChain(val, iterator);
12183
+ return (prototype2 === null || prototype2 === Object.prototype || getPrototypeOf(prototype2) === null) && // Treat own Symbol.toStringTag or Symbol.iterator members as evidence the
12184
+ // value is tagged/iterable, ignoring members reachable only through shared
12185
+ // or terminal prototype boundaries. This is exactly what
12186
+ // hasOwnInPrototypeChain(val, prop) computes here: every prototype admitted
12187
+ // above (null, Object.prototype, or a terminal null-prototype template) is
12188
+ // a boundary, so the walk never inspects anything but `val`'s own members,
12189
+ // and stops before even those when `val` is itself the boundary
12190
+ // Object.prototype. Checking that inline avoids allocating the walker's
12191
+ // `seen` list twice per call on the mergeConfig / merge hot path.
12192
+ (isPrototypeBoundary(val, prototype2, true) || !hasOwnProperty(val, toStringTag) && !hasOwnProperty(val, iterator));
12184
12193
  };
12185
12194
  var isEmptyObject = (val) => {
12186
12195
  if (!isObject(val) || isBuffer(val)) {
@@ -12281,11 +12290,21 @@ var isContextDefined = (context) => !isUndefined(context) && context !== _global
12281
12290
  function merge(...objs) {
12282
12291
  const { caseless, skipUndefined } = isContextDefined(this) && this || {};
12283
12292
  const result = {};
12293
+ const lowerCaseKeys = caseless ? /* @__PURE__ */ Object.create(null) : null;
12284
12294
  const assignValue = (val, key) => {
12285
12295
  if (key === "__proto__" || key === "constructor" || key === "prototype") {
12286
12296
  return;
12287
12297
  }
12288
- const targetKey = caseless && typeof key === "string" && findKey(result, key) || key;
12298
+ let targetKey = key;
12299
+ if (lowerCaseKeys && typeof key === "string") {
12300
+ const lowerKey = key.toLowerCase();
12301
+ const knownKey = lowerCaseKeys[lowerKey];
12302
+ if (knownKey !== void 0 && hasOwnProperty(result, knownKey)) {
12303
+ targetKey = knownKey;
12304
+ } else {
12305
+ lowerCaseKeys[lowerKey] = key;
12306
+ }
12307
+ }
12289
12308
  const existing = hasOwnProperty(result, targetKey) ? result[targetKey] : void 0;
12290
12309
  if (isPlainObject(existing) && isPlainObject(val)) {
12291
12310
  result[targetKey] = merge(existing, val);
@@ -12303,7 +12322,7 @@ function merge(...objs) {
12303
12322
  continue;
12304
12323
  }
12305
12324
  forEach(source, assignValue);
12306
- if (typeof source !== "object" || isArray(source)) {
12325
+ if (typeof source !== "object" || isArray(source) || !Object.getOwnPropertySymbols) {
12307
12326
  continue;
12308
12327
  }
12309
12328
  const symbols = Object.getOwnPropertySymbols(source);
@@ -12399,7 +12418,24 @@ var toArray = (thing) => {
12399
12418
  if (!thing) return null;
12400
12419
  if (isArray(thing)) return thing;
12401
12420
  let i = thing.length;
12402
- if (!isNumber(i)) return null;
12421
+ if (!Number.isSafeInteger(i) || i < 0 || i > 4294967295) return null;
12422
+ const indexes = /* @__PURE__ */ new Set();
12423
+ const seen = /* @__PURE__ */ new Set();
12424
+ let source = thing;
12425
+ while (source != null && indexes.size < i) {
12426
+ if (seen.has(source)) return null;
12427
+ seen.add(source);
12428
+ const prototype2 = getPrototypeOf(source);
12429
+ if (isPrototypeBoundary(source, prototype2, source === thing)) break;
12430
+ Object.getOwnPropertyNames(source).forEach((key) => {
12431
+ const index = +key;
12432
+ if (Number.isInteger(index) && index >= 0 && index < i && String(index) === key && hasOwnProperty(source, key)) {
12433
+ indexes.add(index);
12434
+ }
12435
+ });
12436
+ source = prototype2;
12437
+ }
12438
+ if (indexes.size !== i) return null;
12403
12439
  const arr = new Array(i);
12404
12440
  while (i-- > 0) {
12405
12441
  arr[i] = thing[i];
@@ -12631,7 +12667,7 @@ var ignoreDuplicateOf = utils_default.toObjectSet([
12631
12667
  "user-agent"
12632
12668
  ]);
12633
12669
  var parseHeaders_default = (rawHeaders) => {
12634
- const parsed = {};
12670
+ const parsed = /* @__PURE__ */ Object.create(null);
12635
12671
  let key;
12636
12672
  let val;
12637
12673
  let i;
@@ -12799,9 +12835,11 @@ function parseParameters(value) {
12799
12835
  return parameters;
12800
12836
  }
12801
12837
  var isValidHeaderName = (str) => /^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(str.trim());
12838
+ var PROTO_HEADER_SLOT = "__Proto__";
12839
+ var headerSlot = (name) => name === "__proto__" ? PROTO_HEADER_SLOT : name;
12802
12840
  function matchHeaderValue(context, value, header, filter2, isHeaderNameFilter) {
12803
12841
  if (utils_default.isFunction(filter2)) {
12804
- return filter2.call(this, value, header);
12842
+ return filter2.call(context, value, header);
12805
12843
  }
12806
12844
  if (isHeaderNameFilter) {
12807
12845
  value = header;
@@ -12846,7 +12884,7 @@ var AxiosHeaders = class {
12846
12884
  }
12847
12885
  const key = utils_default.findKey(self2, lHeader);
12848
12886
  if (!key || self2[key] === void 0 || _rewrite === true || _rewrite === void 0 && self2[key] !== false) {
12849
- self2[key || _header] = normalizeValue(_value);
12887
+ self2[headerSlot(key || _header)] = normalizeValue(_value);
12850
12888
  }
12851
12889
  }
12852
12890
  const setHeaders = (headers, _rewrite) => utils_default.forEach(headers, (_value, _header) => setHeader(_value, _header, _rewrite));
@@ -12939,7 +12977,7 @@ var AxiosHeaders = class {
12939
12977
  }
12940
12978
  normalize(format) {
12941
12979
  const self2 = this;
12942
- const headers = {};
12980
+ const headers = /* @__PURE__ */ Object.create(null);
12943
12981
  utils_default.forEach(this, (value, header) => {
12944
12982
  const key = utils_default.findKey(headers, header);
12945
12983
  if (key) {
@@ -12947,7 +12985,7 @@ var AxiosHeaders = class {
12947
12985
  delete self2[header];
12948
12986
  return;
12949
12987
  }
12950
- const normalized = format ? formatHeader(header) : String(header).trim();
12988
+ const normalized = headerSlot(format ? formatHeader(header) : String(header).trim());
12951
12989
  if (normalized !== header) {
12952
12990
  delete self2[header];
12953
12991
  }
@@ -13097,6 +13135,28 @@ function aggregateErrorMessage(error) {
13097
13135
  }).filter(Boolean).join("; ");
13098
13136
  return message || error.name || "AggregateError";
13099
13137
  }
13138
+ var CAUSED_BY_SEPARATOR = "\nCaused by: ";
13139
+ var $causeStack = /* @__PURE__ */ Symbol("causeStack");
13140
+ function getCauseStackIndex(error, stack) {
13141
+ const causeStack = utils_default.hasOwnProp(error, $causeStack) && error[$causeStack];
13142
+ return causeStack && stack.endsWith(causeStack) ? stack.length - causeStack.length : -1;
13143
+ }
13144
+ function appendCauseStack(target, source) {
13145
+ try {
13146
+ const sourceStack = source && source.stack;
13147
+ if (typeof sourceStack !== "string" || !sourceStack) {
13148
+ return;
13149
+ }
13150
+ const targetStack = target.stack;
13151
+ if (typeof targetStack !== "string" || !targetStack) {
13152
+ return;
13153
+ }
13154
+ const causeStack = CAUSED_BY_SEPARATOR + sourceStack;
13155
+ target.stack = targetStack + causeStack;
13156
+ Object.defineProperty(target, $causeStack, { __proto__: null, value: causeStack });
13157
+ } catch (e) {
13158
+ }
13159
+ }
13100
13160
  var AxiosError = class _AxiosError extends Error {
13101
13161
  static from(error, code, config, request, response, customProps) {
13102
13162
  let message = error.message;
@@ -13112,6 +13172,7 @@ var AxiosError = class _AxiosError extends Error {
13112
13172
  configurable: true
13113
13173
  });
13114
13174
  axiosError.name = error.name;
13175
+ appendCauseStack(axiosError, error);
13115
13176
  if (error.status != null && axiosError.status == null) {
13116
13177
  axiosError.status = error.status;
13117
13178
  }
@@ -13423,6 +13484,12 @@ function trimHandlers(handlers) {
13423
13484
  handlers.pop();
13424
13485
  }
13425
13486
  }
13487
+ function normalizeHandlerId(id) {
13488
+ if (typeof id === "string" && id !== "" && String(Number(id)) === id) {
13489
+ return Number(id);
13490
+ }
13491
+ return id;
13492
+ }
13426
13493
  function syncHandlerEntries(manager, internals) {
13427
13494
  const handlers = manager.handlers;
13428
13495
  const length = countHandlers(handlers);
@@ -13493,9 +13560,10 @@ var InterceptorManager = class {
13493
13560
  eject(id) {
13494
13561
  const internals = this[$internals2];
13495
13562
  syncHandlerEntries(this, internals);
13496
- const entry = internals.handlerEntries.get(id);
13563
+ const handlerId = normalizeHandlerId(id);
13564
+ const entry = internals.handlerEntries.get(handlerId);
13497
13565
  if (entry) {
13498
- internals.handlerEntries.delete(id);
13566
+ internals.handlerEntries.delete(handlerId);
13499
13567
  if (this.handlers[entry.index] !== entry.handler) {
13500
13568
  return;
13501
13569
  }
@@ -13555,7 +13623,8 @@ var transitional_default = {
13555
13623
  clarifyTimeoutError: false,
13556
13624
  legacyInterceptorReqResOrdering: true,
13557
13625
  advertiseZstdAcceptEncoding: false,
13558
- validateStatusUndefinedResolves: true
13626
+ validateStatusUndefinedResolves: true,
13627
+ encodeBasicAuthUsername: false
13559
13628
  };
13560
13629
  var URLSearchParams_default = url.URLSearchParams;
13561
13630
 
@@ -13659,6 +13728,24 @@ function arrayToObject(arr) {
13659
13728
  }
13660
13729
  return obj;
13661
13730
  }
13731
+ function normalizeArray(value) {
13732
+ if (!utils_default.isArray(value)) return value;
13733
+ const keys = Object.keys(value);
13734
+ return keys.length !== value.length || keys.some((key, index) => key !== String(index)) ? arrayToObject(value) : value;
13735
+ }
13736
+ function normalizeArrays(obj) {
13737
+ const pending = [obj];
13738
+ while (pending.length) {
13739
+ const target = pending.pop();
13740
+ Object.keys(target).forEach((key) => {
13741
+ const value = target[key] = normalizeArray(target[key]);
13742
+ if (utils_default.isArray(value) || utils_default.isPlainObject(value)) {
13743
+ pending.push(value);
13744
+ }
13745
+ });
13746
+ }
13747
+ return obj;
13748
+ }
13662
13749
  function formDataToJSON(formData) {
13663
13750
  function buildPath(path, value, target, index) {
13664
13751
  throwIfDepthExceeded(index);
@@ -13669,6 +13756,7 @@ function formDataToJSON(formData) {
13669
13756
  name = !name && utils_default.isArray(target) ? target.length : name;
13670
13757
  if (isLast) {
13671
13758
  if (utils_default.hasOwnProp(target, name)) {
13759
+ target[name] = normalizeArray(target[name]);
13672
13760
  target[name] = utils_default.isArray(target[name]) ? target[name].concat(value) : [target[name], value];
13673
13761
  } else {
13674
13762
  target[name] = value;
@@ -13689,7 +13777,7 @@ function formDataToJSON(formData) {
13689
13777
  utils_default.forEachEntry(formData, (name, value) => {
13690
13778
  buildPath(parsePropPath(name), value, obj, 0);
13691
13779
  });
13692
- return obj;
13780
+ return normalizeArrays(obj);
13693
13781
  }
13694
13782
  return null;
13695
13783
  }
@@ -14031,16 +14119,16 @@ var import_https_proxy_agent = __toESM(require_dist());
14031
14119
  var import_follow_redirects = __toESM(require_follow_redirects());
14032
14120
 
14033
14121
  // ../node_modules/axios/lib/env/data.js
14034
- var VERSION = "1.20.0";
14122
+ var VERSION = "1.21.0";
14035
14123
 
14036
14124
  // ../node_modules/axios/lib/helpers/parseProtocol.js
14037
14125
  function parseProtocol(url2) {
14038
14126
  const match = /^([-+\w]{1,25}):(?:\/\/)?/.exec(url2);
14039
- return match && match[1] || "";
14127
+ return match && match[1].toLowerCase() || "";
14040
14128
  }
14041
14129
 
14042
14130
  // ../node_modules/axios/lib/helpers/fromDataURI.js
14043
- var DATA_URL_PATTERN = /^([^,;/]+\/[^,;/]+)?((?:;[^,;=]+=[^,;]+)*)(;base64)?,([\s\S]*)$/;
14131
+ var DATA_URL_PATTERN = /^([^,;/]+\/[^,;/]+)?((?:;[^,;=]+=[^,;]+)*)(;base64)?,([\s\S]*)$/i;
14044
14132
  function fromDataURI(uri, asBlob, options) {
14045
14133
  const _Blob = options && options.Blob || platform_default.classes.Blob;
14046
14134
  const protocol = parseProtocol(uri);
@@ -14063,7 +14151,10 @@ function fromDataURI(uri, asBlob, options) {
14063
14151
  } else if (params) {
14064
14152
  mime = "text/plain" + params;
14065
14153
  }
14066
- const buffer = encoding === "base64" ? Buffer.from(body, "base64") : Buffer.from(decodeURIComponent(body), encoding);
14154
+ const buffer = encoding === "base64" ? Buffer.from(
14155
+ body.replace(/%([\da-f]{2})/gi, (_, hex) => String.fromCharCode(parseInt(hex, 16))),
14156
+ "base64"
14157
+ ) : Buffer.from(decodeURIComponent(body), encoding);
14067
14158
  if (asBlob) {
14068
14159
  if (!_Blob) {
14069
14160
  throw new AxiosError_default("Blob is not supported", AxiosError_default.ERR_NOT_SUPPORT);
@@ -14143,7 +14234,10 @@ var AxiosTransformStream = class extends stream3.Transform {
14143
14234
  const timeWindow = internals.timeWindow;
14144
14235
  const divider = 1e3 / timeWindow;
14145
14236
  const bytesThreshold = maxRate / divider;
14146
- const minChunkSize = internals.minChunkSize !== false ? Math.max(internals.minChunkSize, bytesThreshold * 0.01) : 0;
14237
+ let minChunkSize = internals.minChunkSize !== false ? Math.max(internals.minChunkSize, bytesThreshold * 0.01) : 0;
14238
+ if (maxRate) {
14239
+ minChunkSize = Math.min(bytesThreshold, minChunkSize);
14240
+ }
14147
14241
  const pushChunk = (_chunk, _callback) => {
14148
14242
  const bytes = Buffer.byteLength(_chunk);
14149
14243
  internals.bytesSeen += bytes;
@@ -14159,6 +14253,9 @@ var AxiosTransformStream = class extends stream3.Transform {
14159
14253
  }
14160
14254
  };
14161
14255
  const transformChunk = (_chunk, _callback) => {
14256
+ if (this.destroyed) {
14257
+ return _callback();
14258
+ }
14162
14259
  const chunkSize = Buffer.byteLength(_chunk);
14163
14260
  let chunkRemainder = null;
14164
14261
  let maxChunkSize = readableHighWaterMark;
@@ -14181,7 +14278,7 @@ var AxiosTransformStream = class extends stream3.Transform {
14181
14278
  }, timeWindow - passed);
14182
14279
  }
14183
14280
  if (bytesLeft < maxChunkSize) {
14184
- maxChunkSize = bytesLeft;
14281
+ maxChunkSize = Math.max(1, Math.floor(bytesLeft));
14185
14282
  }
14186
14283
  }
14187
14284
  if (maxChunkSize && chunkSize > maxChunkSize && chunkSize - maxChunkSize > minChunkSize) {
@@ -14232,9 +14329,9 @@ var CRLF_BYTES = textEncoder.encode(CRLF);
14232
14329
  var CRLF_BYTES_COUNT = 2;
14233
14330
  var FormDataPart = class {
14234
14331
  constructor(name, value) {
14235
- const { escapeName } = this.constructor;
14332
+ const { escapeName: escapeName2 } = this.constructor;
14236
14333
  const isStringValue = utils_default.isString(value);
14237
- let headers = `Content-Disposition: form-data; name="${escapeName(name)}"${!isStringValue && value.name ? `; filename="${escapeName(value.name)}"` : ""}${CRLF}`;
14334
+ let headers = `Content-Disposition: form-data; name="${escapeName2(name)}"${!isStringValue && value.name ? `; filename="${escapeName2(value.name)}"` : ""}${CRLF}`;
14238
14335
  if (isStringValue) {
14239
14336
  value = textEncoder.encode(String(value).replace(/\r?\n|\r\n?/g, CRLF));
14240
14337
  } else {
@@ -14388,7 +14485,7 @@ var Http2Sessions = class {
14388
14485
  timer = null;
14389
14486
  }
14390
14487
  stream4.once("close", () => {
14391
- if (!--streamsCount) {
14488
+ if (!--streamsCount && !removed) {
14392
14489
  timer = setTimeout(() => {
14393
14490
  timer = null;
14394
14491
  removeSession();
@@ -14400,6 +14497,7 @@ var Http2Sessions = class {
14400
14497
  }
14401
14498
  session.once("close", removeSession);
14402
14499
  session.once("error", removeSession);
14500
+ session.once("goaway", removeSession);
14403
14501
  let entry = [session, options];
14404
14502
  authoritySessions ? authoritySessions.push(entry) : authoritySessions = this.sessions[authority] = [entry];
14405
14503
  return session;
@@ -14421,8 +14519,6 @@ var callbackify = (fn, reducer) => {
14421
14519
  } : fn;
14422
14520
  };
14423
14521
  var callbackify_default = callbackify;
14424
-
14425
- // ../node_modules/axios/lib/helpers/shouldBypassProxy.js
14426
14522
  var LOOPBACK_HOSTNAMES = /* @__PURE__ */ new Set(["localhost", "0.0.0.0"]);
14427
14523
  var trimTrailingDots = (value) => {
14428
14524
  let end = value.length;
@@ -14616,7 +14712,20 @@ var normalizeNoProxyHost = (hostname) => {
14616
14712
  if (hostname.charAt(0) === "[" && hostname.charAt(hostname.length - 1) === "]") {
14617
14713
  hostname = hostname.slice(1, -1);
14618
14714
  }
14619
- const trimmed = trimTrailingDots(hostname);
14715
+ let trimmed = trimTrailingDots(hostname);
14716
+ if (trimmed.indexOf(":") !== -1) {
14717
+ try {
14718
+ trimmed = new URL("http://[" + trimmed + "]/").hostname.slice(1, -1);
14719
+ } catch (_err) {
14720
+ return trimmed;
14721
+ }
14722
+ } else if (/[\u0080-\uffff]/.test(trimmed)) {
14723
+ const prefix = /^[*.]+/.exec(trimmed);
14724
+ const start = prefix ? prefix[0] : "";
14725
+ const ascii = domainToASCII(trimmed.slice(start.length));
14726
+ if (!ascii) return "";
14727
+ trimmed = start + trimTrailingDots(ascii);
14728
+ }
14620
14729
  const ipv4 = normalizeIPAddress(trimmed);
14621
14730
  if (ipv4 !== trimmed) {
14622
14731
  return ipv4;
@@ -14887,6 +14996,26 @@ var estimateBase64BufferAllocation = (body) => {
14887
14996
  }
14888
14997
  return Math.floor((len - padding) * 3 / 4);
14889
14998
  };
14999
+ var estimatePercentDecodedBase64BufferAllocation = (body) => {
15000
+ if (body.indexOf("%") === -1) {
15001
+ return estimateBase64BufferAllocation(body);
15002
+ }
15003
+ let length = 0;
15004
+ let previous = 0;
15005
+ let last = 0;
15006
+ for (let i = 0, len = body.length; i < len; i++) {
15007
+ let code = body.charCodeAt(i);
15008
+ if (code === 37 && isPercentEncodedByte(body, i, len)) {
15009
+ code = hexValue(body.charCodeAt(i + 1)) * 16 + hexValue(body.charCodeAt(i + 2));
15010
+ i += 2;
15011
+ }
15012
+ length++;
15013
+ previous = last;
15014
+ last = code;
15015
+ }
15016
+ const padding = last === 61 ? previous === 61 ? 2 : 1 : 0;
15017
+ return Math.floor((length - padding) * 3 / 4);
15018
+ };
14890
15019
  var estimatePercentDecodedBase64Bytes = (body) => {
14891
15020
  const len = body.length;
14892
15021
  let significant = 0;
@@ -14916,14 +15045,14 @@ var estimatePercentDecodedBase64Bytes = (body) => {
14916
15045
  }
14917
15046
  return base64Bytes(significant);
14918
15047
  };
14919
- var estimateDataURLBytes = (url2, estimateBase64) => {
15048
+ var estimateDataURLBytes = (url2, estimateBase64, base64Pattern) => {
14920
15049
  if (!url2 || typeof url2 !== "string") return 0;
14921
- if (!url2.startsWith("data:")) return 0;
15050
+ if (!/^data:/i.test(url2)) return 0;
14922
15051
  const comma = url2.indexOf(",");
14923
15052
  if (comma < 0) return 0;
14924
15053
  const meta = url2.slice(5, comma);
14925
15054
  const body = url2.slice(comma + 1);
14926
- const isBase64 = /;base64/i.test(meta);
15055
+ const isBase64 = base64Pattern.test(meta);
14927
15056
  if (isBase64) {
14928
15057
  return estimateBase64(body);
14929
15058
  }
@@ -14955,11 +15084,12 @@ function estimateDataURLDecodedBytes(url2) {
14955
15084
  const fragmentIndex = typeof url2 === "string" ? url2.indexOf("#") : -1;
14956
15085
  return estimateDataURLBytes(
14957
15086
  fragmentIndex === -1 ? url2 : url2.slice(0, fragmentIndex),
14958
- estimatePercentDecodedBase64Bytes
15087
+ estimatePercentDecodedBase64Bytes,
15088
+ /; *base64[\t\n\f\r ]*$/i
14959
15089
  );
14960
15090
  }
14961
15091
  function estimateDataURLBufferAllocation(url2) {
14962
- return estimateDataURLBytes(url2, estimateBase64BufferAllocation);
15092
+ return estimateDataURLBytes(url2, estimatePercentDecodedBase64BufferAllocation, /;base64$/i);
14963
15093
  }
14964
15094
 
14965
15095
  // ../node_modules/axios/lib/adapters/http.js
@@ -14993,6 +15123,18 @@ function handleSocketError(err) {
14993
15123
  var kAxiosInstalledTunnel = /* @__PURE__ */ Symbol("axios.http.installedTunnel");
14994
15124
  var tunnelingAgentCache = /* @__PURE__ */ new Map();
14995
15125
  var tunnelingAgentCacheUser = /* @__PURE__ */ new WeakMap();
15126
+ var directAgents = /* @__PURE__ */ new WeakMap();
15127
+ var directAgentHooks = ["createConnection", "getName"];
15128
+ var nativeAgentPoolHooks = [
15129
+ "addRequest",
15130
+ "createSocket",
15131
+ "removeSocket",
15132
+ "keepSocketAlive",
15133
+ "reuseSocket",
15134
+ "_getSession",
15135
+ "_cacheSession",
15136
+ "_evictSession"
15137
+ ];
14996
15138
  var NODE_NATIVE_ENV_PROXY_SUPPORT = {
14997
15139
  22: 21,
14998
15140
  24: 5
@@ -15022,6 +15164,49 @@ function isNodeEnvProxyEnabled(agent, nodeVersion = process.versions && process.
15022
15164
  function getProxyEnvAgent(options, configHttpAgent, configHttpsAgent) {
15023
15165
  return isHttps.test(options.protocol) ? configHttpsAgent || https.globalAgent : configHttpAgent || http.globalAgent;
15024
15166
  }
15167
+ function getDirectAgent(configuredAgent, transport) {
15168
+ if (!process.allowedNodeEnvironmentFlags || !process.allowedNodeEnvironmentFlags.has("--use-env-proxy")) {
15169
+ return configuredAgent;
15170
+ }
15171
+ const agent = configuredAgent || transport.globalAgent;
15172
+ const options = agent && agent.options;
15173
+ if (!(agent instanceof transport.Agent) || agent.protocol !== transport.globalAgent.protocol || !options || !utils_default.hasOwnProp(options, "proxyEnv") || typeof options.proxyEnv !== "object" || options.proxyEnv === null) {
15174
+ return configuredAgent;
15175
+ }
15176
+ for (const hook of nativeAgentPoolHooks) {
15177
+ if (utils_default.isFunction(transport.Agent.prototype[hook]) && agent[hook] !== transport.Agent.prototype[hook]) {
15178
+ throw new AxiosError_default(
15179
+ "proxy: false cannot adapt an agent overriding " + hook + "; use an agent constructed without proxyEnv",
15180
+ AxiosError_default.ERR_BAD_OPTION_VALUE
15181
+ );
15182
+ }
15183
+ }
15184
+ let direct = directAgents.get(agent);
15185
+ if (!direct) {
15186
+ direct = new transport.Agent({ ...options, proxyEnv: void 0 });
15187
+ const destroy = agent.destroy;
15188
+ agent.destroy = function destroyWithDirectAgent() {
15189
+ try {
15190
+ return destroy.apply(this, arguments);
15191
+ } finally {
15192
+ direct.destroy();
15193
+ }
15194
+ };
15195
+ directAgents.set(agent, direct);
15196
+ }
15197
+ for (const hook of directAgentHooks) {
15198
+ direct[hook] = agent[hook] === transport.Agent.prototype[hook] ? transport.Agent.prototype[hook] : bind(agent[hook], agent);
15199
+ }
15200
+ return direct;
15201
+ }
15202
+ function setDirectAgent(options, configHttpAgent, configHttpsAgent) {
15203
+ const secure = isHttps.test(options.protocol);
15204
+ const agent = getDirectAgent(secure ? configHttpsAgent : configHttpAgent, secure ? https : http);
15205
+ options.agent = agent;
15206
+ if (options.agents) {
15207
+ options.agents[secure ? "https" : "http"] = agent;
15208
+ }
15209
+ }
15025
15210
  function getTunnelingAgent(agentOptions, userHttpsAgent) {
15026
15211
  const key = agentOptions.protocol + "//" + agentOptions.hostname + ":" + (agentOptions.port || "") + "#" + (agentOptions.auth || "");
15027
15212
  const cache = userHttpsAgent ? tunnelingAgentCacheUser.get(userHttpsAgent) || tunnelingAgentCacheUser.set(userHttpsAgent, /* @__PURE__ */ new Map()).get(userHttpsAgent) : tunnelingAgentCache;
@@ -15029,13 +15214,12 @@ function getTunnelingAgent(agentOptions, userHttpsAgent) {
15029
15214
  if (agent) return agent;
15030
15215
  const merged = userHttpsAgent && userHttpsAgent.options ? { ...userHttpsAgent.options, ...agentOptions } : agentOptions;
15031
15216
  agent = new import_https_proxy_agent.default(merged);
15032
- if (userHttpsAgent && userHttpsAgent.options) {
15033
- const originTLSOptions = { ...userHttpsAgent.options };
15034
- const callback = agent.callback;
15035
- agent.callback = function axiosTunnelingAgentCallback(req, opts) {
15036
- return callback.call(this, req, { ...originTLSOptions, ...opts });
15037
- };
15038
- }
15217
+ const callback = agent.callback;
15218
+ agent.callback = function axiosTunnelingAgentCallback(req, opts) {
15219
+ const originTLSAgent = userHttpsAgent || https.globalAgent;
15220
+ const originTLSOptions = originTLSAgent && originTLSAgent.options;
15221
+ return callback.call(this, req, { ...originTLSOptions, ...opts });
15222
+ };
15039
15223
  agent[kAxiosInstalledTunnel] = true;
15040
15224
  cache.set(key, agent);
15041
15225
  return agent;
@@ -15059,6 +15243,10 @@ var flushOnFinish = (stream4, [throttled, flush]) => {
15059
15243
  };
15060
15244
  var http2Sessions = new Http2Sessions_default();
15061
15245
  function dispatchBeforeRedirect(options, responseDetails, requestDetails) {
15246
+ if (!isSameOriginRedirect(options, requestDetails)) {
15247
+ stripMatchingHeaders(options.headers, /* @__PURE__ */ new Set(["authorization", "cookie"]));
15248
+ delete options.auth;
15249
+ }
15062
15250
  if (options.beforeRedirects.proxy) {
15063
15251
  options.beforeRedirects.proxy(options);
15064
15252
  }
@@ -15068,6 +15256,9 @@ function dispatchBeforeRedirect(options, responseDetails, requestDetails) {
15068
15256
  if (options.beforeRedirects.sensitiveHeaders) {
15069
15257
  options.beforeRedirects.sensitiveHeaders(options, requestDetails);
15070
15258
  }
15259
+ if (options.beforeRedirects.direct) {
15260
+ options.beforeRedirects.direct(options);
15261
+ }
15071
15262
  if (options.beforeRedirects.config) {
15072
15263
  options.beforeRedirects.config(options, responseDetails, requestDetails);
15073
15264
  }
@@ -15113,6 +15304,9 @@ function setProxy(options, configProxy, location, isRedirect, configHttpsAgent,
15113
15304
  if (isRedirect && options.agent && options.agent[kAxiosInstalledTunnel]) {
15114
15305
  options.agent = void 0;
15115
15306
  }
15307
+ if (isRedirect && options.agents && options.agents.https && options.agents.https[kAxiosInstalledTunnel]) {
15308
+ options.agents.https = configHttpsAgent;
15309
+ }
15116
15310
  if (proxy) {
15117
15311
  const isProxyURL = proxy instanceof URL;
15118
15312
  const readProxyField = (key) => isProxyURL || utils_default.hasOwnProp(proxy, key) ? proxy[key] : void 0;
@@ -15293,9 +15487,9 @@ var http_default = isHttpAdapterSupported && function httpAdapter(config) {
15293
15487
  if (httpVersion === void 0) httpVersion = 1;
15294
15488
  const rawHttpVersion = httpVersion;
15295
15489
  let http2Options = own2("http2Options");
15490
+ const configProxy = own2("proxy");
15296
15491
  const httpAgent = own2("httpAgent");
15297
15492
  const httpsAgent = own2("httpsAgent");
15298
- const configProxy = own2("proxy");
15299
15493
  const responseType = own2("responseType");
15300
15494
  const responseEncoding = own2("responseEncoding");
15301
15495
  const socketPath = own2("socketPath");
@@ -15434,6 +15628,15 @@ var http_default = isHttpAdapterSupported && function httpAdapter(config) {
15434
15628
  } catch (err) {
15435
15629
  throw AxiosError_default.from(err, AxiosError_default.ERR_BAD_REQUEST, config);
15436
15630
  }
15631
+ if (maxContentLength > -1 && (responseType === "blob" ? convertedData.size : convertedData.length) > maxContentLength) {
15632
+ return reject(
15633
+ new AxiosError_default(
15634
+ "maxContentLength size of " + maxContentLength + " exceeded",
15635
+ AxiosError_default.ERR_BAD_RESPONSE,
15636
+ config
15637
+ )
15638
+ );
15639
+ }
15437
15640
  if (responseType === "text") {
15438
15641
  convertedData = convertedData.toString(responseEncoding);
15439
15642
  if (!responseEncoding || responseEncoding === "utf8") {
@@ -15635,9 +15838,13 @@ var http_default = isHttpAdapterSupported && function httpAdapter(config) {
15635
15838
  }
15636
15839
  let transport;
15637
15840
  let isNativeTransport = false;
15638
- let transportEnforcesMaxBodyLength = false;
15639
15841
  const isHttpsRequest = isHttps.test(options.protocol);
15640
- if (options.agent == null) {
15842
+ if (!isHttp2 && configProxy === false) {
15843
+ setDirectAgent(options, httpAgent, httpsAgent);
15844
+ options.beforeRedirects.direct = (redirectOptions) => {
15845
+ setDirectAgent(redirectOptions, httpAgent, httpsAgent);
15846
+ };
15847
+ } else if (options.agent == null) {
15641
15848
  options.agent = isHttpsRequest ? httpsAgent : httpAgent;
15642
15849
  }
15643
15850
  if (isHttp2) {
@@ -15659,7 +15866,6 @@ var http_default = isHttpAdapterSupported && function httpAdapter(config) {
15659
15866
  transport = isHttpsRequest ? https : http;
15660
15867
  isNativeTransport = true;
15661
15868
  } else {
15662
- transportEnforcesMaxBodyLength = true;
15663
15869
  options.sensitiveHeaders = [];
15664
15870
  if (maxRedirects) {
15665
15871
  options.maxRedirects = maxRedirects;
@@ -15945,7 +16151,7 @@ var http_default = isHttpAdapterSupported && function httpAdapter(config) {
15945
16151
  }
15946
16152
  });
15947
16153
  let uploadStream = data;
15948
- if (maxBodyLength > -1 && !transportEnforcesMaxBodyLength) {
16154
+ if (maxBodyLength > -1) {
15949
16155
  const limit = maxBodyLength;
15950
16156
  let bytesSent = 0;
15951
16157
  uploadStream = stream3.pipeline(
@@ -15982,16 +16188,14 @@ var http_default = isHttpAdapterSupported && function httpAdapter(config) {
15982
16188
  });
15983
16189
  };
15984
16190
 
15985
- // ../node_modules/axios/lib/helpers/isURLSameOrigin.js
15986
- var isURLSameOrigin_default = platform_default.hasStandardBrowserEnv ? /* @__PURE__ */ ((origin2, isMSIE) => (url2) => {
15987
- url2 = new URL(url2, platform_default.origin);
15988
- return origin2.protocol === url2.protocol && origin2.host === url2.host && (isMSIE || origin2.port === url2.port);
15989
- })(
15990
- new URL(platform_default.origin),
15991
- platform_default.navigator && /(msie|trident)/i.test(platform_default.navigator.userAgent)
15992
- ) : () => true;
15993
-
15994
16191
  // ../node_modules/axios/lib/helpers/cookies.js
16192
+ var decodeCookieValue = (value) => {
16193
+ try {
16194
+ return decodeURIComponent(value);
16195
+ } catch (e) {
16196
+ return value;
16197
+ }
16198
+ };
15995
16199
  var cookies_default = platform_default.hasStandardBrowserEnv ? (
15996
16200
  // Standard browser envs support document.cookie
15997
16201
  {
@@ -16017,20 +16221,29 @@ var cookies_default = platform_default.hasStandardBrowserEnv ? (
16017
16221
  },
16018
16222
  read(name) {
16019
16223
  if (typeof document === "undefined") return null;
16020
- const cookies = document.cookie.split(";");
16224
+ const cookieString = document.cookie;
16225
+ if (!cookieString) return null;
16226
+ const cookies = cookieString.split(";");
16021
16227
  for (let i = 0; i < cookies.length; i++) {
16022
16228
  const cookie = cookies[i].replace(/^\s+/, "");
16023
16229
  const eq = cookie.indexOf("=");
16024
16230
  if (eq !== -1 && cookie.slice(0, eq) === name) {
16025
- try {
16026
- return decodeURIComponent(cookie.slice(eq + 1));
16027
- } catch (e) {
16028
- return cookie.slice(eq + 1);
16029
- }
16231
+ return decodeCookieValue(cookie.slice(eq + 1));
16030
16232
  }
16031
16233
  }
16032
16234
  return null;
16033
16235
  },
16236
+ async readAsync(name) {
16237
+ try {
16238
+ const store = typeof window !== "undefined" && window.cookieStore;
16239
+ if (store && utils_default.isFunction(store.get)) {
16240
+ const cookie = await store.get(name);
16241
+ return cookie ? decodeCookieValue(cookie.value) : null;
16242
+ }
16243
+ } catch (e) {
16244
+ }
16245
+ return this.read(name);
16246
+ },
16034
16247
  remove(name) {
16035
16248
  this.write(name, "", Date.now() - 864e5, "/");
16036
16249
  }
@@ -16043,130 +16256,224 @@ var cookies_default = platform_default.hasStandardBrowserEnv ? (
16043
16256
  read() {
16044
16257
  return null;
16045
16258
  },
16259
+ async readAsync() {
16260
+ return null;
16261
+ },
16046
16262
  remove() {
16047
16263
  }
16048
16264
  }
16049
16265
  );
16050
16266
 
16267
+ // ../node_modules/axios/lib/helpers/isURLSameOrigin.js
16268
+ var isURLSameOrigin_default = platform_default.hasStandardBrowserEnv ? /* @__PURE__ */ ((origin2) => (url2) => {
16269
+ url2 = new URL(url2, document.baseURI || platform_default.origin);
16270
+ return origin2.protocol === url2.protocol && origin2.host === url2.host && origin2.port === url2.port;
16271
+ })(new URL(platform_default.origin)) : () => true;
16272
+
16273
+ // ../node_modules/axios/lib/core/assertParamsAcyclic.js
16274
+ function assertParamsAcyclic(params) {
16275
+ const pending = [{ value: params }];
16276
+ const active = /* @__PURE__ */ new WeakSet();
16277
+ const visited = /* @__PURE__ */ new WeakSet();
16278
+ while (pending.length) {
16279
+ const { value, done } = pending.pop();
16280
+ if (!utils_default.isPlainObject(value) && !utils_default.isArray(value)) continue;
16281
+ if (done) {
16282
+ active.delete(value);
16283
+ continue;
16284
+ }
16285
+ if (active.has(value)) {
16286
+ throw new AxiosError_default(
16287
+ "Circular reference detected in params",
16288
+ AxiosError_default.ERR_BAD_OPTION_VALUE
16289
+ );
16290
+ }
16291
+ if (visited.has(value)) continue;
16292
+ visited.add(value);
16293
+ active.add(value);
16294
+ pending.push({ value, done: true });
16295
+ const keys = Object.keys(value);
16296
+ if (Object.getOwnPropertySymbols && Object.getOwnPropertyDescriptor) {
16297
+ Object.getOwnPropertySymbols(value).forEach((key) => {
16298
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
16299
+ if (descriptor && descriptor.enumerable) keys.push(key);
16300
+ });
16301
+ }
16302
+ keys.forEach((key) => {
16303
+ if (key === "__proto__" || key === "constructor" || key === "prototype") {
16304
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
16305
+ if (descriptor && utils_default.hasOwnProp(descriptor, "value")) {
16306
+ pending.push({ value: descriptor.value });
16307
+ }
16308
+ } else {
16309
+ pending.push({ value: value[key] });
16310
+ }
16311
+ });
16312
+ }
16313
+ }
16314
+
16051
16315
  // ../node_modules/axios/lib/core/mergeConfig.js
16052
16316
  var headersToObject = (thing) => thing instanceof AxiosHeaders_default ? { ...thing } : thing;
16053
16317
  var ownEnumerableKeys = (thing) => {
16054
16318
  if (Object.getOwnPropertySymbols && Object.getOwnPropertyDescriptor) {
16055
16319
  return Object.keys(thing).concat(
16056
- Object.getOwnPropertySymbols(thing).filter(
16057
- (symbol) => Object.getOwnPropertyDescriptor(thing, symbol).enumerable
16058
- )
16320
+ Object.getOwnPropertySymbols(thing).filter((symbol) => {
16321
+ const descriptor = Object.getOwnPropertyDescriptor(thing, symbol);
16322
+ return descriptor && descriptor.enumerable;
16323
+ })
16059
16324
  );
16060
16325
  }
16061
16326
  return Object.keys(thing);
16062
16327
  };
16063
- function mergeConfig(config1, config2) {
16064
- config1 = config1 || {};
16065
- config2 = config2 || {};
16066
- const config = /* @__PURE__ */ Object.create(null);
16067
- Object.defineProperty(config, "hasOwnProperty", {
16068
- // Null-proto descriptor so a polluted Object.prototype.get cannot turn
16069
- // this data descriptor into an accessor descriptor on the way in.
16070
- __proto__: null,
16071
- value: Object.prototype.hasOwnProperty,
16072
- enumerable: false,
16073
- writable: true,
16074
- configurable: true
16075
- });
16076
- function getMergedValue(target, source, prop, caseless) {
16077
- if (utils_default.isPlainObject(target) && utils_default.isPlainObject(source)) {
16078
- return utils_default.merge.call({ caseless }, target, source);
16079
- } else if (utils_default.isPlainObject(source)) {
16080
- return utils_default.merge({}, source);
16081
- } else if (utils_default.isArray(source)) {
16082
- return source.slice();
16083
- }
16084
- return source;
16328
+ function mergeParams(a, b) {
16329
+ const pending = [];
16330
+ const copies = /* @__PURE__ */ new WeakMap();
16331
+ const empty = {};
16332
+ function copy(target, source) {
16333
+ if (!utils_default.isPlainObject(source)) {
16334
+ return utils_default.isArray(source) ? source.slice() : source;
16335
+ }
16336
+ const base = utils_default.isPlainObject(target) ? target : empty;
16337
+ let bases = copies.get(source);
16338
+ if (!bases) {
16339
+ bases = /* @__PURE__ */ new WeakMap();
16340
+ copies.set(source, bases);
16341
+ }
16342
+ if (bases.has(base)) return bases.get(base);
16343
+ const result2 = {};
16344
+ bases.set(base, result2);
16345
+ pending.push({ base, source, result: result2 });
16346
+ return result2;
16347
+ }
16348
+ const result = utils_default.isUndefined(b) ? copy(void 0, a) : copy(a, b);
16349
+ while (pending.length) {
16350
+ const { base, source, result: target } = pending.pop();
16351
+ const baseKeys = new Set(ownEnumerableKeys(base));
16352
+ const sourceKeys = new Set(ownEnumerableKeys(source));
16353
+ const keys = /* @__PURE__ */ new Set([...baseKeys, ...sourceKeys]);
16354
+ keys.forEach((key) => {
16355
+ if (key === "__proto__" || key === "constructor" || key === "prototype") return;
16356
+ const hasSource = sourceKeys.has(key);
16357
+ const value = hasSource ? source[key] : void 0;
16358
+ const previous = (!hasSource || utils_default.isPlainObject(value)) && baseKeys.has(key) ? base[key] : void 0;
16359
+ target[key] = hasSource ? copy(previous, value) : copy(void 0, previous);
16360
+ });
16085
16361
  }
16086
- function mergeDeepProperties(a, b, prop, caseless) {
16087
- if (!utils_default.isUndefined(b)) {
16088
- return getMergedValue(a, b, prop, caseless);
16089
- } else if (!utils_default.isUndefined(a)) {
16090
- return getMergedValue(void 0, a, prop, caseless);
16091
- }
16362
+ assertParamsAcyclic(result);
16363
+ return result;
16364
+ }
16365
+ function getMergedValue(target, source, prop, caseless) {
16366
+ if (utils_default.isPlainObject(target) && utils_default.isPlainObject(source)) {
16367
+ return utils_default.merge.call({ caseless }, target, source);
16368
+ } else if (utils_default.isPlainObject(source)) {
16369
+ return utils_default.merge({}, source);
16370
+ } else if (utils_default.isArray(source)) {
16371
+ return source.slice();
16372
+ }
16373
+ return source;
16374
+ }
16375
+ function mergeDeepProperties(a, b, prop, caseless) {
16376
+ if (!utils_default.isUndefined(b)) {
16377
+ return getMergedValue(a, b, prop, caseless);
16378
+ } else if (!utils_default.isUndefined(a)) {
16379
+ return getMergedValue(void 0, a, prop, caseless);
16092
16380
  }
16093
- function valueFromConfig2(a, b) {
16094
- if (!utils_default.isUndefined(b)) {
16095
- return getMergedValue(void 0, b);
16096
- }
16381
+ }
16382
+ function valueFromConfig2(a, b) {
16383
+ if (!utils_default.isUndefined(b)) {
16384
+ return getMergedValue(void 0, b);
16097
16385
  }
16098
- function defaultToConfig2(a, b) {
16099
- if (!utils_default.isUndefined(b)) {
16100
- return getMergedValue(void 0, b);
16101
- } else if (!utils_default.isUndefined(a)) {
16102
- return getMergedValue(void 0, a);
16103
- }
16386
+ }
16387
+ function defaultToConfig2(a, b) {
16388
+ if (!utils_default.isUndefined(b)) {
16389
+ return getMergedValue(void 0, b);
16390
+ } else if (!utils_default.isUndefined(a)) {
16391
+ return getMergedValue(void 0, a);
16104
16392
  }
16105
- function getMergedTransitionalOption(prop) {
16106
- const transitional2 = utils_default.hasOwnProp(config2, "transitional") ? config2.transitional : void 0;
16107
- if (!utils_default.isUndefined(transitional2)) {
16108
- if (utils_default.isPlainObject(transitional2)) {
16109
- if (utils_default.hasOwnProp(transitional2, prop)) {
16110
- return transitional2[prop];
16111
- }
16112
- } else {
16113
- return void 0;
16393
+ }
16394
+ function getMergedTransitionalOption(config1, config2, prop) {
16395
+ const transitional2 = utils_default.hasOwnProp(config2, "transitional") ? config2.transitional : void 0;
16396
+ if (!utils_default.isUndefined(transitional2)) {
16397
+ if (utils_default.isPlainObject(transitional2)) {
16398
+ if (utils_default.hasOwnProp(transitional2, prop)) {
16399
+ return transitional2[prop];
16114
16400
  }
16401
+ } else {
16402
+ return void 0;
16115
16403
  }
16116
- const transitional1 = utils_default.hasOwnProp(config1, "transitional") ? config1.transitional : void 0;
16117
- if (utils_default.isPlainObject(transitional1) && utils_default.hasOwnProp(transitional1, prop)) {
16118
- return transitional1[prop];
16119
- }
16120
- return void 0;
16121
16404
  }
16122
- function mergeDirectKeys(a, b, prop) {
16123
- if (utils_default.hasOwnProp(config2, prop)) {
16124
- return getMergedValue(a, b);
16125
- } else if (utils_default.hasOwnProp(config1, prop)) {
16126
- return getMergedValue(void 0, a);
16127
- }
16128
- }
16129
- const mergeMap = {
16130
- url: valueFromConfig2,
16131
- method: valueFromConfig2,
16132
- data: valueFromConfig2,
16133
- baseURL: defaultToConfig2,
16134
- transformRequest: defaultToConfig2,
16135
- transformResponse: defaultToConfig2,
16136
- paramsSerializer: defaultToConfig2,
16137
- timeout: defaultToConfig2,
16138
- timeoutErrorMessage: defaultToConfig2,
16139
- withCredentials: defaultToConfig2,
16140
- withXSRFToken: defaultToConfig2,
16141
- adapter: defaultToConfig2,
16142
- responseType: defaultToConfig2,
16143
- xsrfCookieName: defaultToConfig2,
16144
- xsrfHeaderName: defaultToConfig2,
16145
- onUploadProgress: defaultToConfig2,
16146
- onDownloadProgress: defaultToConfig2,
16147
- decompress: defaultToConfig2,
16148
- maxContentLength: defaultToConfig2,
16149
- maxBodyLength: defaultToConfig2,
16150
- beforeRedirect: defaultToConfig2,
16151
- transport: defaultToConfig2,
16152
- httpAgent: defaultToConfig2,
16153
- httpsAgent: defaultToConfig2,
16154
- cancelToken: defaultToConfig2,
16155
- socketPath: defaultToConfig2,
16156
- allowedSocketPaths: defaultToConfig2,
16157
- responseEncoding: defaultToConfig2,
16158
- validateStatus: mergeDirectKeys,
16159
- headers: (a, b, prop) => mergeDeepProperties(headersToObject(a), headersToObject(b), prop, true)
16160
- };
16161
- utils_default.forEach(ownEnumerableKeys({ ...config1, ...config2 }), function computeConfigValue(prop) {
16162
- if (prop === "__proto__" || prop === "constructor" || prop === "prototype") return;
16405
+ const transitional1 = utils_default.hasOwnProp(config1, "transitional") ? config1.transitional : void 0;
16406
+ if (utils_default.isPlainObject(transitional1) && utils_default.hasOwnProp(transitional1, prop)) {
16407
+ return transitional1[prop];
16408
+ }
16409
+ return void 0;
16410
+ }
16411
+ function mergeDirectKeys(a, b, prop, config1, config2) {
16412
+ if (utils_default.hasOwnProp(config2, prop)) {
16413
+ return getMergedValue(a, b);
16414
+ } else if (utils_default.hasOwnProp(config1, prop)) {
16415
+ return getMergedValue(void 0, a);
16416
+ }
16417
+ }
16418
+ function mergeHeaders(a, b, prop) {
16419
+ return mergeDeepProperties(headersToObject(a), headersToObject(b), prop, true);
16420
+ }
16421
+ var hasOwnPropertyDescriptor = Object.freeze({
16422
+ __proto__: null,
16423
+ value: Object.prototype.hasOwnProperty,
16424
+ enumerable: false,
16425
+ writable: true,
16426
+ configurable: true
16427
+ });
16428
+ var mergeMap = {
16429
+ url: valueFromConfig2,
16430
+ method: valueFromConfig2,
16431
+ data: valueFromConfig2,
16432
+ baseURL: defaultToConfig2,
16433
+ transformRequest: defaultToConfig2,
16434
+ transformResponse: defaultToConfig2,
16435
+ params: mergeParams,
16436
+ paramsSerializer: defaultToConfig2,
16437
+ timeout: defaultToConfig2,
16438
+ timeoutErrorMessage: defaultToConfig2,
16439
+ withCredentials: defaultToConfig2,
16440
+ withXSRFToken: defaultToConfig2,
16441
+ adapter: defaultToConfig2,
16442
+ responseType: defaultToConfig2,
16443
+ xsrfCookieName: defaultToConfig2,
16444
+ xsrfHeaderName: defaultToConfig2,
16445
+ onUploadProgress: defaultToConfig2,
16446
+ onDownloadProgress: defaultToConfig2,
16447
+ decompress: defaultToConfig2,
16448
+ maxContentLength: defaultToConfig2,
16449
+ maxBodyLength: defaultToConfig2,
16450
+ beforeRedirect: defaultToConfig2,
16451
+ transport: defaultToConfig2,
16452
+ httpAgent: defaultToConfig2,
16453
+ httpsAgent: defaultToConfig2,
16454
+ cancelToken: defaultToConfig2,
16455
+ socketPath: defaultToConfig2,
16456
+ allowedSocketPaths: defaultToConfig2,
16457
+ responseEncoding: defaultToConfig2,
16458
+ validateStatus: mergeDirectKeys,
16459
+ headers: mergeHeaders
16460
+ };
16461
+ function mergeConfig(config1, config2) {
16462
+ config1 = config1 || {};
16463
+ config2 = config2 || {};
16464
+ const config = /* @__PURE__ */ Object.create(null);
16465
+ Object.defineProperty(config, "hasOwnProperty", hasOwnPropertyDescriptor);
16466
+ const keys = ownEnumerableKeys({ ...config1, ...config2 });
16467
+ for (let i = 0, len = keys.length; i < len; i++) {
16468
+ const prop = keys[i];
16469
+ if (prop === "__proto__" || prop === "constructor" || prop === "prototype") continue;
16163
16470
  const merge2 = utils_default.hasOwnProp(mergeMap, prop) ? mergeMap[prop] : mergeDeepProperties;
16164
16471
  const a = utils_default.hasOwnProp(config1, prop) ? config1[prop] : void 0;
16165
16472
  const b = utils_default.hasOwnProp(config2, prop) ? config2[prop] : void 0;
16166
- const configValue = merge2(a, b, prop);
16473
+ const configValue = merge2 === mergeDirectKeys ? merge2(a, b, prop, config1, config2) : merge2(a, b, prop);
16167
16474
  utils_default.isUndefined(configValue) && merge2 !== mergeDirectKeys || (config[prop] = configValue);
16168
- });
16169
- if (utils_default.hasOwnProp(config2, "validateStatus") && utils_default.isUndefined(config2.validateStatus) && getMergedTransitionalOption("validateStatusUndefinedResolves") === false) {
16475
+ }
16476
+ if (utils_default.hasOwnProp(config2, "validateStatus") && utils_default.isUndefined(config2.validateStatus) && getMergedTransitionalOption(config1, config2, "validateStatusUndefinedResolves") === false) {
16170
16477
  if (utils_default.hasOwnProp(config1, "validateStatus")) {
16171
16478
  config.validateStatus = getMergedValue(void 0, config1.validateStatus);
16172
16479
  } else {
@@ -16181,7 +16488,8 @@ var encodeUTF8 = (str) => encodeURIComponent(str).replace(
16181
16488
  /%([0-9A-F]{2})/gi,
16182
16489
  (_, hex) => String.fromCharCode(parseInt(hex, 16))
16183
16490
  );
16184
- function resolveConfig(config) {
16491
+ var readCookie = (name) => cookies_default.read(name);
16492
+ function resolveConfig(config, readXsrfCookie = readCookie) {
16185
16493
  const newConfig = mergeConfig({}, config);
16186
16494
  const own2 = (key) => utils_default.hasOwnProp(newConfig, key) ? newConfig[key] : void 0;
16187
16495
  const data = own2("data");
@@ -16202,10 +16510,15 @@ function resolveConfig(config) {
16202
16510
  if (auth) {
16203
16511
  const username = utils_default.getSafeProp(auth, "username") || "";
16204
16512
  const password = utils_default.getSafeProp(auth, "password") || "";
16513
+ const transitional2 = own2("transitional");
16514
+ const encodeUsername = transitional2 && utils_default.hasOwnProp(transitional2, "encodeBasicAuthUsername") && transitional2.encodeBasicAuthUsername === true;
16205
16515
  try {
16206
16516
  headers.set(
16207
16517
  "Authorization",
16208
- "Basic " + btoa(username + ":" + (password ? encodeUTF8(password) : ""))
16518
+ // Preserve legacy username bytes unless the caller opts in to UTF-8.
16519
+ "Basic " + btoa(
16520
+ (encodeUsername ? encodeUTF8(username) : username) + ":" + (password ? encodeUTF8(password) : "")
16521
+ )
16209
16522
  );
16210
16523
  } catch (e) {
16211
16524
  throw AxiosError_default.from(e, AxiosError_default.ERR_BAD_OPTION_VALUE, config);
@@ -16225,7 +16538,7 @@ function resolveConfig(config) {
16225
16538
  }
16226
16539
  const shouldSendXSRF = withXSRFToken === true || withXSRFToken == null && isURLSameOrigin_default(newConfig.url);
16227
16540
  if (shouldSendXSRF) {
16228
- const xsrfValue = xsrfHeaderName && xsrfCookieName && cookies_default.read(xsrfCookieName);
16541
+ const xsrfValue = xsrfHeaderName && xsrfCookieName && readXsrfCookie(xsrfCookieName);
16229
16542
  if (xsrfValue) {
16230
16543
  headers.set(xsrfHeaderName, xsrfValue);
16231
16544
  }
@@ -16239,16 +16552,50 @@ var resolveConfig_default = resolveConfig;
16239
16552
  var isXHRAdapterSupported = typeof XMLHttpRequest !== "undefined";
16240
16553
  var xhr_default = isXHRAdapterSupported && function(config) {
16241
16554
  return new Promise(function dispatchXhrRequest(resolve, reject) {
16242
- const _config = resolveConfig_default(config);
16555
+ let useAsyncXsrf;
16556
+ try {
16557
+ const store = platform_default.hasStandardBrowserEnv && typeof window !== "undefined" && window.cookieStore;
16558
+ useAsyncXsrf = store && utils_default.isFunction(store.get);
16559
+ } catch (e) {
16560
+ }
16561
+ let xsrfCookieName;
16562
+ const _config = resolveConfig_default(
16563
+ config,
16564
+ useAsyncXsrf ? (name) => {
16565
+ xsrfCookieName = name;
16566
+ return null;
16567
+ } : void 0
16568
+ );
16243
16569
  let requestData = _config.data;
16244
16570
  const requestHeaders = AxiosHeaders_default.from(_config.headers).normalize();
16245
16571
  let { responseType, onUploadProgress, onDownloadProgress } = _config;
16246
16572
  let onCanceled;
16573
+ let timeoutId;
16247
16574
  let uploadThrottled, downloadThrottled;
16248
16575
  let flushUpload, flushDownload, flushDownloadWithEvent;
16249
16576
  function done() {
16250
- flushUpload && flushUpload();
16251
- flushDownload && flushDownload();
16577
+ clearTimeout(timeoutId);
16578
+ try {
16579
+ flushUpload && flushUpload();
16580
+ } catch (err) {
16581
+ setTimeout(() => {
16582
+ throw err;
16583
+ });
16584
+ }
16585
+ try {
16586
+ flushDownload && flushDownload();
16587
+ } catch (err) {
16588
+ setTimeout(() => {
16589
+ throw err;
16590
+ });
16591
+ }
16592
+ if (request) {
16593
+ downloadThrottled && request.removeEventListener("progress", downloadThrottled);
16594
+ if (request.upload) {
16595
+ uploadThrottled && request.upload.removeEventListener("progress", uploadThrottled);
16596
+ flushUpload && request.upload.removeEventListener("loadend", flushUpload);
16597
+ }
16598
+ }
16252
16599
  _config.cancelToken && _config.cancelToken.unsubscribe(onCanceled);
16253
16600
  _config.signal && _config.signal.removeEventListener("abort", onCanceled);
16254
16601
  }
@@ -16334,6 +16681,7 @@ var xhr_default = isXHRAdapterSupported && function(config) {
16334
16681
  request = null;
16335
16682
  };
16336
16683
  request.ontimeout = function handleTimeout() {
16684
+ if (!request) return;
16337
16685
  let timeoutErrorMessage = _config.timeout ? "timeout of " + _config.timeout + "ms exceeded" : "timeout exceeded";
16338
16686
  const transitional2 = _config.transitional || transitional_default;
16339
16687
  if (_config.timeoutErrorMessage) {
@@ -16351,11 +16699,6 @@ var xhr_default = isXHRAdapterSupported && function(config) {
16351
16699
  request = null;
16352
16700
  };
16353
16701
  requestData === void 0 && requestHeaders.setContentType(null);
16354
- if ("setRequestHeader" in request) {
16355
- utils_default.forEach(toByteStringHeaderObject(requestHeaders), function setRequestHeader(val, key) {
16356
- request.setRequestHeader(key, val);
16357
- });
16358
- }
16359
16702
  if (!utils_default.isUndefined(_config.withCredentials)) {
16360
16703
  request.withCredentials = !!_config.withCredentials;
16361
16704
  }
@@ -16380,15 +16723,18 @@ var xhr_default = isXHRAdapterSupported && function(config) {
16380
16723
  return;
16381
16724
  }
16382
16725
  reject(!cancel || cancel.type ? new CanceledError_default(null, config, request) : cancel);
16383
- request.abort();
16726
+ const xhr = request;
16384
16727
  done();
16385
16728
  request = null;
16729
+ xhr.abort();
16386
16730
  };
16387
16731
  _config.cancelToken && _config.cancelToken.subscribe(onCanceled);
16732
+ if (!request) return;
16388
16733
  if (_config.signal) {
16389
16734
  _config.signal.aborted ? onCanceled() : _config.signal.addEventListener("abort", onCanceled);
16390
16735
  }
16391
16736
  }
16737
+ if (!request) return;
16392
16738
  const protocol = parseProtocol(_config.url);
16393
16739
  if (protocol && !platform_default.protocols.includes(protocol)) {
16394
16740
  reject(
@@ -16401,7 +16747,58 @@ var xhr_default = isXHRAdapterSupported && function(config) {
16401
16747
  done();
16402
16748
  return;
16403
16749
  }
16404
- request.send(requestData || null);
16750
+ const sendRequest = () => {
16751
+ if (!request) return;
16752
+ if ("setRequestHeader" in request) {
16753
+ utils_default.forEach(
16754
+ toByteStringHeaderObject(requestHeaders),
16755
+ function setRequestHeader(val, key) {
16756
+ request.setRequestHeader(key, val);
16757
+ }
16758
+ );
16759
+ }
16760
+ request.send(requestData || null);
16761
+ };
16762
+ if (xsrfCookieName) {
16763
+ const now = typeof performance !== "undefined" && utils_default.isFunction(performance.now) ? () => performance.now() : Date.now;
16764
+ const deadline = request.timeout > 0 ? now() + Number(request.timeout) : void 0;
16765
+ const abortOnTimeout = () => {
16766
+ if (!request) return;
16767
+ const xhr = request;
16768
+ xhr.ontimeout();
16769
+ xhr.abort();
16770
+ };
16771
+ if (deadline !== void 0) {
16772
+ const scheduleTimeout = () => {
16773
+ const remaining = deadline - now();
16774
+ if (remaining > 0) {
16775
+ timeoutId = setTimeout(scheduleTimeout, Math.min(remaining, 2147483647));
16776
+ } else {
16777
+ abortOnTimeout();
16778
+ }
16779
+ };
16780
+ scheduleTimeout();
16781
+ }
16782
+ cookies_default.readAsync(xsrfCookieName).then((value) => {
16783
+ if (!request) return;
16784
+ if (deadline !== void 0 && now() >= deadline) {
16785
+ abortOnTimeout();
16786
+ return;
16787
+ }
16788
+ if (value) {
16789
+ const headerName = utils_default.hasOwnProp(_config, "xsrfHeaderName") && _config.xsrfHeaderName;
16790
+ requestHeaders.set(headerName, value);
16791
+ }
16792
+ sendRequest();
16793
+ }).catch((error) => {
16794
+ if (!request) return;
16795
+ reject(AxiosError_default.from(error, null, config, request));
16796
+ done();
16797
+ request = null;
16798
+ });
16799
+ } else {
16800
+ sendRequest();
16801
+ }
16405
16802
  });
16406
16803
  };
16407
16804
 
@@ -16434,7 +16831,8 @@ var composeSignals = (signals, timeout) => {
16434
16831
  timer && clearTimeout(timer);
16435
16832
  timer = null;
16436
16833
  signals.forEach((signal2) => {
16437
- signal2.unsubscribe ? signal2.unsubscribe(onabort) : signal2.removeEventListener("abort", onabort);
16834
+ const unsubscribeSignal = utils_default.getSafeProp(signal2, "unsubscribe");
16835
+ utils_default.isFunction(unsubscribeSignal) ? unsubscribeSignal.call(signal2, onabort) : signal2.removeEventListener("abort", onabort);
16438
16836
  });
16439
16837
  signals = null;
16440
16838
  };
@@ -16534,6 +16932,110 @@ var trackStream = (stream4, chunkSize, onProgress, onFinish) => {
16534
16932
  );
16535
16933
  };
16536
16934
 
16935
+ // ../node_modules/axios/lib/helpers/formDataToBlob.js
16936
+ var CRLF2 = "\r\n";
16937
+ var normalizeLines = (value) => String(value).replace(/\r\n|\r|\n/g, CRLF2);
16938
+ var escapeName = (value) => String(value).replace(
16939
+ /[\r\n"]/g,
16940
+ (char) => char === "\r" ? "%0D" : char === "\n" ? "%0A" : "%22"
16941
+ );
16942
+ var stringBytes = (value, normalize) => {
16943
+ let length = 0;
16944
+ for (let i = 0; i < value.length; i++) {
16945
+ const code = value.charCodeAt(i);
16946
+ if (normalize && (code === 13 || code === 10)) {
16947
+ if (code === 13 && value.charCodeAt(i + 1) === 10) i++;
16948
+ length += 2;
16949
+ } else if (code < 128) {
16950
+ length++;
16951
+ } else if (code < 2048) {
16952
+ length += 2;
16953
+ } else if (code >= 55296 && code <= 56319 && value.charCodeAt(i + 1) >= 56320 && value.charCodeAt(i + 1) <= 57343) {
16954
+ length += 4;
16955
+ i++;
16956
+ } else {
16957
+ length += 3;
16958
+ }
16959
+ }
16960
+ return length;
16961
+ };
16962
+ var FormDataError = class extends TypeError {
16963
+ constructor(message, reason) {
16964
+ super(message);
16965
+ this.name = "FormDataError";
16966
+ this.reason = reason;
16967
+ }
16968
+ };
16969
+ function formDataToBlob(form, Blob2, limit, limitError, boundary) {
16970
+ if (!utils_default.isFunction(Blob2)) {
16971
+ throw new FormDataError("Blob is not supported", "blob");
16972
+ }
16973
+ if (!utils_default.isString(boundary) || !/^[A-Za-z0-9'()+_,./:=? -]{1,70}$/.test(boundary) || / $/.test(boundary)) {
16974
+ throw new FormDataError("Invalid multipart boundary", "boundary");
16975
+ }
16976
+ const footer = "--" + boundary + "--" + CRLF2;
16977
+ let length = footer.length;
16978
+ const parts = [];
16979
+ const checkLength = (extra) => {
16980
+ if (length + extra > limit) throw limitError();
16981
+ };
16982
+ checkLength(0);
16983
+ for (const [name, value] of form) {
16984
+ const isString2 = utils_default.isString(value);
16985
+ const valueLength = isString2 ? stringBytes(value, true) : value.size;
16986
+ if (!Number.isFinite(valueLength) || valueLength < 0) {
16987
+ throw new FormDataError("Unsupported FormData part size", "part");
16988
+ }
16989
+ checkLength(
16990
+ valueLength + stringBytes(name, true) + (!isString2 && value.name ? stringBytes(value.name, false) : 0) + (!isString2 && value.type ? stringBytes(value.type, false) : 0)
16991
+ );
16992
+ let header = "--" + boundary + CRLF2 + 'Content-Disposition: form-data; name="' + escapeName(normalizeLines(name)) + '"';
16993
+ if (!isString2) {
16994
+ header += '; filename="' + escapeName(utils_default.isString(value.name) ? value.name : "blob") + '"' + CRLF2 + "Content-Type: " + String(value.type || "application/octet-stream").replace(/[\r\n]/g, "");
16995
+ }
16996
+ header += CRLF2 + CRLF2;
16997
+ const partLength = stringBytes(header, false) + valueLength + CRLF2.length;
16998
+ checkLength(partLength);
16999
+ length += partLength;
17000
+ parts.push({ header, value, isString: isString2 });
17001
+ }
17002
+ const blobParts = [];
17003
+ for (const part of parts) {
17004
+ blobParts.push(part.header, part.isString ? normalizeLines(part.value) : part.value, CRLF2);
17005
+ }
17006
+ blobParts.push(footer);
17007
+ return new Blob2(blobParts, { type: "multipart/form-data; boundary=" + boundary });
17008
+ }
17009
+
17010
+ // ../node_modules/axios/lib/core/createMultipartBody.js
17011
+ function createMultipartBody(form, Blob2, limit, limitError, boundary) {
17012
+ if (!utils_default.isFunction(Blob2)) {
17013
+ throw new AxiosError_default("Blob is not supported", AxiosError_default.ERR_NOT_SUPPORT);
17014
+ }
17015
+ if (boundary === void 0) {
17016
+ if (utils_default.isFunction(platform_default.generateString)) {
17017
+ boundary = "axios-" + platform_default.generateString(36, "0123456789abcdef");
17018
+ } else {
17019
+ const crypto2 = utils_default.global.crypto;
17020
+ if (!crypto2 || !utils_default.isFunction(crypto2.getRandomValues)) {
17021
+ throw new AxiosError_default("Random byte generation is not supported", AxiosError_default.ERR_NOT_SUPPORT);
17022
+ }
17023
+ const random = new Uint8Array(18);
17024
+ crypto2.getRandomValues(random);
17025
+ boundary = "axios-" + Array.from(random, (value) => ("0" + value.toString(16)).slice(-2)).join("");
17026
+ }
17027
+ }
17028
+ try {
17029
+ return formDataToBlob(form, Blob2, limit, limitError, boundary);
17030
+ } catch (error) {
17031
+ if (error instanceof FormDataError) {
17032
+ const code = error.reason === "boundary" ? AxiosError_default.ERR_BAD_OPTION_VALUE : AxiosError_default.ERR_BAD_REQUEST;
17033
+ throw new AxiosError_default(error.message, code);
17034
+ }
17035
+ throw error;
17036
+ }
17037
+ }
17038
+
16537
17039
  // ../node_modules/axios/lib/adapters/fetch.js
16538
17040
  var DEFAULT_CHUNK_SIZE = 64 * 1024;
16539
17041
  var DEFAULT_REQUEST_OPTIONS = {
@@ -16586,11 +17088,13 @@ var factory = (env) => {
16586
17088
  },
16587
17089
  {
16588
17090
  Request: globalObject.Request,
16589
- Response: globalObject.Response
17091
+ Response: globalObject.Response,
17092
+ Blob: globalObject.Blob
16590
17093
  },
16591
17094
  env
16592
17095
  );
16593
- const { fetch: envFetch, Request, Response } = env;
17096
+ const envFetch = utils_default.hasOwnProp(env, "fetch") ? env.fetch : void 0;
17097
+ const { Request, Response, Blob: Blob2 } = env;
16594
17098
  const isFetchSupported = envFetch ? isFunction2(envFetch) : typeof fetch === "function";
16595
17099
  const isRequestSupported = isFunction2(Request);
16596
17100
  const isResponseSupported = isFunction2(Response);
@@ -16616,6 +17120,13 @@ var factory = (env) => {
16616
17120
  return duplexAccessed && !hasContentType;
16617
17121
  });
16618
17122
  const supportsResponseStream = isResponseSupported && isReadableStreamSupported && test(() => utils_default.isReadableStream(new Response("").body));
17123
+ const requestDefaults = Object.assign(/* @__PURE__ */ Object.create(null), DEFAULT_REQUEST_OPTIONS);
17124
+ if (isRequestSupported && !test(() => new Request(platform_default.origin, requestDefaults))) {
17125
+ delete requestDefaults.cache;
17126
+ if (!test(() => new Request(platform_default.origin, requestDefaults))) {
17127
+ requestDefaults.cache = DEFAULT_REQUEST_OPTIONS.cache;
17128
+ }
17129
+ }
16619
17130
  const resolvers = {
16620
17131
  stream: supportsResponseStream && ((res) => res.body)
16621
17132
  };
@@ -16641,13 +17152,6 @@ var factory = (env) => {
16641
17152
  if (utils_default.isBlob(body)) {
16642
17153
  return body.size;
16643
17154
  }
16644
- if (utils_default.isSpecCompliantForm(body)) {
16645
- const _request = new Request(platform_default.origin, {
16646
- method: "POST",
16647
- body
16648
- });
16649
- return (await _request.arrayBuffer()).byteLength;
16650
- }
16651
17155
  if (utils_default.isArrayBufferView(body) || utils_default.isArrayBuffer(body)) {
16652
17156
  return body.byteLength;
16653
17157
  }
@@ -16695,6 +17199,7 @@ var factory = (env) => {
16695
17199
  });
16696
17200
  let requestContentLength;
16697
17201
  let pendingBodyError = null;
17202
+ let pendingResponseError = null;
16698
17203
  const maxBodyLengthError = () => new AxiosError_default(
16699
17204
  "Request body larger than maxBodyLength limit",
16700
17205
  AxiosError_default.ERR_BAD_REQUEST,
@@ -16712,8 +17217,9 @@ var factory = (env) => {
16712
17217
  password
16713
17218
  };
16714
17219
  }
17220
+ let parsedURL;
16715
17221
  if (maybeWithAuthCredentials(url2)) {
16716
- const parsedURL = new URL(url2, platform_default.origin);
17222
+ parsedURL = new URL(url2, platform_default.origin);
16717
17223
  if (!auth && (parsedURL.username || parsedURL.password)) {
16718
17224
  const urlUsername = decodeURIComponentSafe2(parsedURL.username);
16719
17225
  const urlPassword = decodeURIComponentSafe2(parsedURL.password);
@@ -16735,8 +17241,8 @@ var factory = (env) => {
16735
17241
  "Basic " + btoa(encodeUTF82((auth.username || "") + ":" + (auth.password || "")))
16736
17242
  );
16737
17243
  }
16738
- if (hasMaxContentLength && typeof url2 === "string" && url2.startsWith("data:")) {
16739
- const estimated = estimateDataURLDecodedBytes(url2);
17244
+ if (hasMaxContentLength && parsedURL && parsedURL.protocol === "data:") {
17245
+ const estimated = estimateDataURLDecodedBytes(parsedURL.href);
16740
17246
  if (estimated > maxContentLength) {
16741
17247
  throw new AxiosError_default(
16742
17248
  "maxContentLength size of " + maxContentLength + " exceeded",
@@ -16746,6 +17252,23 @@ var factory = (env) => {
16746
17252
  );
16747
17253
  }
16748
17254
  }
17255
+ const formContentType = utils_default.isSpecCompliantForm(data) && AxiosHeaders_default.from(own2("headers")).getContentType();
17256
+ let formBoundary;
17257
+ if (utils_default.isString(formContentType) && /^multipart\/form-data(?:\s*;|$)/i.test(formContentType.trim())) {
17258
+ const parameters = AxiosHeaders_default.parseParameters(formContentType);
17259
+ if (utils_default.hasOwnProp(parameters, "boundary")) formBoundary = parameters.boundary;
17260
+ }
17261
+ if (utils_default.isSpecCompliantForm(data) && method !== "get" && method !== "head" && (hasMaxBodyLength || onUploadProgress && supportsRequestStream || formBoundary !== void 0)) {
17262
+ data = createMultipartBody(
17263
+ data,
17264
+ Blob2,
17265
+ hasMaxBodyLength ? maxBodyLength : Infinity,
17266
+ maxBodyLengthError,
17267
+ formBoundary
17268
+ );
17269
+ headers.setContentType(formBoundary === void 0 ? data.type : formContentType);
17270
+ requestContentLength = data.size;
17271
+ }
16749
17272
  if (hasMaxBodyLength && method !== "get" && method !== "head") {
16750
17273
  const outboundLength = await getBodyLength(data);
16751
17274
  if (typeof outboundLength === "number" && isFinite(outboundLength)) {
@@ -16826,7 +17349,7 @@ var factory = (env) => {
16826
17349
  credentials: isCredentialsSupported ? withCredentials : void 0
16827
17350
  });
16828
17351
  if (isRequestSupported) {
16829
- utils_default.forEach(DEFAULT_REQUEST_OPTIONS, (value, key) => {
17352
+ utils_default.forEach(requestDefaults, (value, key) => {
16830
17353
  if (resolvedOptions[key] === void 0) {
16831
17354
  resolvedOptions[key] = value;
16832
17355
  }
@@ -16874,7 +17397,7 @@ var factory = (env) => {
16874
17397
  if (hasMaxContentLength) {
16875
17398
  bytesRead = loadedBytes;
16876
17399
  if (bytesRead > maxContentLength) {
16877
- throw new AxiosError_default(
17400
+ throw pendingResponseError = new AxiosError_default(
16878
17401
  "maxContentLength size of " + maxContentLength + " exceeded",
16879
17402
  AxiosError_default.ERR_BAD_RESPONSE,
16880
17403
  config,
@@ -16949,6 +17472,9 @@ var factory = (env) => {
16949
17472
  request && !pendingBodyError.request && (pendingBodyError.request = request);
16950
17473
  throw pendingBodyError;
16951
17474
  }
17475
+ if (pendingResponseError) {
17476
+ throw pendingResponseError;
17477
+ }
16952
17478
  if (err instanceof AxiosError_default) {
16953
17479
  request && !err.request && (err.request = request);
16954
17480
  throw err;
@@ -16976,9 +17502,15 @@ var factory = (env) => {
16976
17502
  };
16977
17503
  var seedCache = /* @__PURE__ */ new Map();
16978
17504
  var getFetch = (config) => {
16979
- let env = config && config.env || {};
16980
- const { fetch: fetch2, Request, Response } = env;
16981
- const seeds = [Request, Response, fetch2];
17505
+ const env = /* @__PURE__ */ Object.create(null);
17506
+ const configuredEnv = config && utils_default.hasOwnProp(config, "env") && config.env;
17507
+ ["fetch", "Request", "Response", "Blob"].forEach((key) => {
17508
+ if (configuredEnv && utils_default.hasOwnProp(configuredEnv, key)) {
17509
+ env[key] = configuredEnv[key];
17510
+ }
17511
+ });
17512
+ const { fetch: fetch2, Request, Response, Blob: Blob2 } = env;
17513
+ const seeds = [Request, Response, fetch2, Blob2];
16982
17514
  let len = seeds.length, i = len, seed, target, map = seedCache;
16983
17515
  while (i--) {
16984
17516
  seed = seeds[i];
@@ -17064,6 +17596,9 @@ function throwIfCancellationRequested(config) {
17064
17596
  throw new CanceledError_default(null, config);
17065
17597
  }
17066
17598
  }
17599
+ function elapsedSince(start) {
17600
+ return Math.max(0, Date.now() - start);
17601
+ }
17067
17602
  function dispatchRequest(_config) {
17068
17603
  const config = utils_default.toSafeFlatObject(_config);
17069
17604
  throwIfCancellationRequested(config);
@@ -17073,9 +17608,11 @@ function dispatchRequest(_config) {
17073
17608
  config.headers.setContentType("application/x-www-form-urlencoded", false);
17074
17609
  }
17075
17610
  const adapter2 = adapters_default.getAdapter(config.adapter || defaults_default.adapter, config);
17611
+ const start = Date.now();
17076
17612
  return adapter2(config).then(
17077
17613
  function onAdapterResolution(response) {
17078
17614
  throwIfCancellationRequested(config);
17615
+ response.duration = elapsedSince(start);
17079
17616
  config.response = response;
17080
17617
  try {
17081
17618
  response.data = transformData.call(config, config.transformResponse, response);
@@ -17089,6 +17626,7 @@ function dispatchRequest(_config) {
17089
17626
  if (!isCancel(reason)) {
17090
17627
  throwIfCancellationRequested(config);
17091
17628
  if (reason && reason.response) {
17629
+ reason.response.duration = elapsedSince(start);
17092
17630
  config.response = reason.response;
17093
17631
  try {
17094
17632
  reason.response.data = transformData.call(
@@ -17176,6 +17714,27 @@ var validator_default = {
17176
17714
 
17177
17715
  // ../node_modules/axios/lib/core/Axios.js
17178
17716
  var validators2 = validator_default.validators;
17717
+ var isHeadersBucket = (value) => {
17718
+ if (value == null || utils_default.isPlainObject(value) || value instanceof AxiosHeaders_default) {
17719
+ return true;
17720
+ }
17721
+ try {
17722
+ return utils_default.isObject(value) && utils_default.getSafeProp(value, Symbol.toStringTag) === "AxiosHeaders" && [
17723
+ "toJSON",
17724
+ "set",
17725
+ "get",
17726
+ "has",
17727
+ "delete",
17728
+ "clear",
17729
+ "normalize",
17730
+ "concat",
17731
+ "toString",
17732
+ Symbol.iterator
17733
+ ].every((method) => utils_default.isFunction(utils_default.getSafeProp(value, method)));
17734
+ } catch (e) {
17735
+ return false;
17736
+ }
17737
+ };
17179
17738
  var Axios = class {
17180
17739
  constructor(instanceConfig) {
17181
17740
  this.defaults = instanceConfig || {};
@@ -17211,9 +17770,13 @@ var Axios = class {
17211
17770
  } else if (stack) {
17212
17771
  const firstNewlineIndex = stack.indexOf("\n");
17213
17772
  const secondNewlineIndex = firstNewlineIndex === -1 ? -1 : stack.indexOf("\n", firstNewlineIndex + 1);
17214
- const stackWithoutTwoTopLines = secondNewlineIndex === -1 ? "" : stack.slice(secondNewlineIndex + 1);
17215
- if (!String(err.stack).endsWith(stackWithoutTwoTopLines)) {
17216
- err.stack += "\n" + stack;
17773
+ const duplicateCheckSuffix = secondNewlineIndex === -1 ? stack : stack.slice(secondNewlineIndex + 1);
17774
+ const currentStack = String(err.stack);
17775
+ const causeIndex = getCauseStackIndex(err, currentStack);
17776
+ const stackHead = causeIndex === -1 ? currentStack : currentStack.slice(0, causeIndex);
17777
+ const causeSection = causeIndex === -1 ? "" : currentStack.slice(causeIndex);
17778
+ if (!stackHead.endsWith(duplicateCheckSuffix)) {
17779
+ err.stack = stackHead + "\n" + stack + causeSection;
17217
17780
  }
17218
17781
  }
17219
17782
  } catch (e) {
@@ -17240,7 +17803,8 @@ var Axios = class {
17240
17803
  clarifyTimeoutError: validators2.transitional(validators2.boolean),
17241
17804
  legacyInterceptorReqResOrdering: validators2.transitional(validators2.boolean),
17242
17805
  advertiseZstdAcceptEncoding: validators2.transitional(validators2.boolean),
17243
- validateStatusUndefinedResolves: validators2.transitional(validators2.boolean)
17806
+ validateStatusUndefinedResolves: validators2.transitional(validators2.boolean),
17807
+ encodeBasicAuthUsername: validators2.transitional(validators2.boolean)
17244
17808
  },
17245
17809
  false
17246
17810
  );
@@ -17261,7 +17825,7 @@ var Axios = class {
17261
17825
  );
17262
17826
  }
17263
17827
  }
17264
- if (config.allowAbsoluteUrls !== void 0) ; else if (this.defaults.allowAbsoluteUrls !== void 0) {
17828
+ if (config.allowAbsoluteUrls !== void 0) ; else if (utils_default.hasOwnProp(this.defaults, "allowAbsoluteUrls") && this.defaults.allowAbsoluteUrls !== void 0) {
17265
17829
  config.allowAbsoluteUrls = this.defaults.allowAbsoluteUrls;
17266
17830
  } else {
17267
17831
  config.allowAbsoluteUrls = true;
@@ -17275,9 +17839,16 @@ var Axios = class {
17275
17839
  true
17276
17840
  );
17277
17841
  config.method = (utils_default.getSafeProp(config, "method") || utils_default.getSafeProp(this.defaults, "method") || "get").toLowerCase();
17278
- let contextHeaders = headers && utils_default.merge(headers.common, headers[config.method]);
17842
+ const commonHeaders = utils_default.getSafeProp(headers, "common");
17843
+ const methodHeaders = utils_default.getSafeProp(headers, config.method);
17844
+ const contextHeaders = headers && utils_default.merge(
17845
+ isHeadersBucket(commonHeaders) ? commonHeaders : void 0,
17846
+ isHeadersBucket(methodHeaders) ? methodHeaders : void 0
17847
+ );
17279
17848
  headers && utils_default.forEach(methodList_default.concat("common"), (method) => {
17280
- delete headers[method];
17849
+ if (isHeadersBucket(utils_default.getSafeProp(headers, method))) {
17850
+ delete headers[method];
17851
+ }
17281
17852
  });
17282
17853
  config.headers = AxiosHeaders_default.concat(contextHeaders, headers);
17283
17854
  const requestInterceptorChain = [];
@@ -17359,7 +17930,7 @@ var Axios = class {
17359
17930
  }
17360
17931
  };
17361
17932
  utils_default.forEach(["delete", "get", "head", "options"], function forEachMethodNoData(method) {
17362
- Axios.prototype[method] = function(url2, config) {
17933
+ Axios.prototype[method] = async function(url2, config) {
17363
17934
  return this.request(
17364
17935
  mergeConfig(config || {}, {
17365
17936
  method,
@@ -17371,7 +17942,7 @@ utils_default.forEach(["delete", "get", "head", "options"], function forEachMeth
17371
17942
  });
17372
17943
  utils_default.forEach(["post", "put", "patch", "query"], function forEachMethodWithData(method) {
17373
17944
  function generateHTTPMethod(isForm) {
17374
- return function httpMethod(url2, data, config) {
17945
+ return async function httpMethod(url2, data, config) {
17375
17946
  return this.request(
17376
17947
  mergeConfig(config || {}, {
17377
17948
  method,
@@ -17881,12 +18452,94 @@ var ServerError = class extends Posty5Error {
17881
18452
  this.name = "ServerError";
17882
18453
  }
17883
18454
  };
18455
+ var ConflictError = class extends Posty5Error {
18456
+ constructor(message = "The document was changed by someone else", currentVersion = -1, resourceId = "", details) {
18457
+ super(message, "VERSION_CONFLICT", 409, details);
18458
+ this.name = "ConflictError";
18459
+ this.currentVersion = currentVersion;
18460
+ this.resourceId = resourceId;
18461
+ }
18462
+ };
18463
+ var VersionRequiredError = class extends Posty5Error {
18464
+ constructor(message = "The document version is required", details) {
18465
+ super(message, "VERSION_REQUIRED", 428, details);
18466
+ this.name = "VersionRequiredError";
18467
+ }
18468
+ };
18469
+ var CORE_VERSION = "5.0.2";
18470
+ var DEFAULT_BASE_URL = "https://api.posty5.com";
18471
+ var DEFAULT_TIMEOUT_MS = 3e4;
18472
+ var DEFAULT_MAX_RETRIES = 3;
18473
+ var DEFAULT_RETRY_DELAY_MS = 1e3;
18474
+ var CLIENT_HEADER_NAME = "X-Posty5-Client";
18475
+ var SDK_CLIENT_NAME = "posty5-npm";
18476
+ var SDK_CLIENT_ID = `${SDK_CLIENT_NAME}/${CORE_VERSION}`;
18477
+ var DEFAULT_CREATED_FROM = "npmPackage";
18478
+ var IDEMPOTENT_METHODS = ["GET", "HEAD", "OPTIONS", "PUT", "DELETE"];
18479
+ var NEVER_CONNECTED_ERROR_CODES = ["ECONNREFUSED", "ENOTFOUND", "EAI_AGAIN", "ENETUNREACH", "EHOSTUNREACH"];
18480
+ var API_KEY_HEADER_NAME = "X-API-Key";
18481
+ var REDACTED_VALUE = "[REDACTED]";
18482
+ var LOOPBACK_HOSTNAMES2 = ["localhost", "127.0.0.1", "[::1]", "::1"];
18483
+ var DOT_SEGMENT_PATTERN = /^(?:\.|%2e){1,2}$/i;
18484
+ function assertNoDotSegments(url2) {
18485
+ const path = url2.split(/[?#]/)[0];
18486
+ if (path.split("/").some((segment) => DOT_SEGMENT_PATTERN.test(segment))) {
18487
+ throw new Posty5Error(`Invalid request path "${url2}": "." and ".." segments are not allowed`, "INVALID_PATH");
18488
+ }
18489
+ }
18490
+ function redactHeaders(headers) {
18491
+ if (!headers || typeof headers !== "object") return;
18492
+ for (const name of Object.keys(headers)) {
18493
+ if (name.toLowerCase() === API_KEY_HEADER_NAME.toLowerCase()) headers[name] = REDACTED_VALUE;
18494
+ }
18495
+ }
18496
+ function hideProperty(target, key) {
18497
+ if (!target || !(key in target)) return;
18498
+ Object.defineProperty(target, key, { value: target[key], enumerable: false, configurable: true, writable: true });
18499
+ }
18500
+ function redactApiKey(error) {
18501
+ const axiosError = error;
18502
+ if (!axiosError || typeof axiosError !== "object") return error;
18503
+ redactHeaders(axiosError.config?.headers);
18504
+ redactHeaders(axiosError.response?.config?.headers);
18505
+ hideProperty(axiosError, "request");
18506
+ hideProperty(axiosError.response, "request");
18507
+ return error;
18508
+ }
18509
+ function originOf(protocol, hostname, port) {
18510
+ const resolvedPort = port ? String(port) : protocol === "https:" ? "443" : "80";
18511
+ return `${protocol}//${hostname.toLowerCase()}:${resolvedPort}`;
18512
+ }
18513
+ function apiKeyRedirectGuard(baseUrl) {
18514
+ let baseOrigin;
18515
+ try {
18516
+ const base = new URL(baseUrl);
18517
+ baseOrigin = originOf(base.protocol, base.hostname, base.port);
18518
+ } catch {
18519
+ baseOrigin = void 0;
18520
+ }
18521
+ return (options) => {
18522
+ const target = originOf(String(options.protocol || ""), String(options.hostname || options.host || ""), options.port);
18523
+ if (target === baseOrigin) return;
18524
+ for (const name of Object.keys(options.headers || {})) {
18525
+ if (name.toLowerCase() === API_KEY_HEADER_NAME.toLowerCase()) delete options.headers[name];
18526
+ }
18527
+ };
18528
+ }
18529
+ function isInsecureBaseUrl(baseUrl) {
18530
+ try {
18531
+ const url2 = new URL(baseUrl);
18532
+ return url2.protocol === "http:" && !LOOPBACK_HOSTNAMES2.includes(url2.hostname.toLowerCase());
18533
+ } catch {
18534
+ return false;
18535
+ }
18536
+ }
17884
18537
  function transformError(error) {
17885
18538
  if (error instanceof Posty5Error) {
17886
18539
  return error;
17887
18540
  }
17888
18541
  if (error.isAxiosError) {
17889
- const axiosError = error;
18542
+ const axiosError = redactApiKey(error);
17890
18543
  if (!axiosError.response) {
17891
18544
  if (axiosError.code === "ECONNABORTED" || axiosError.message.includes("timeout")) {
17892
18545
  return new NetworkError("Request timeout", { originalError: error });
@@ -17905,6 +18558,22 @@ function transformError(error) {
17905
18558
  return new AuthorizationError(message, details);
17906
18559
  case 404:
17907
18560
  return new NotFoundError(message, details);
18561
+ case 409: {
18562
+ const body = data;
18563
+ if (body?.code === "VERSION_CONFLICT") {
18564
+ const result = body?.result ?? {};
18565
+ const current = Number(result.currentVersion ?? body?.currentVersion);
18566
+ return new ConflictError(
18567
+ message,
18568
+ Number.isFinite(current) ? current : -1,
18569
+ String(result._id ?? body?._id ?? ""),
18570
+ details
18571
+ );
18572
+ }
18573
+ return new Posty5Error(message, body?.code, status, details);
18574
+ }
18575
+ case 428:
18576
+ return new VersionRequiredError(message, details);
17908
18577
  case 429:
17909
18578
  const retryAfter2 = axiosError.response.headers["retry-after"];
17910
18579
  return new RateLimitError(
@@ -17926,6 +18595,69 @@ function transformError(error) {
17926
18595
  }
17927
18596
  return new Posty5Error("An unknown error occurred", void 0, void 0, { originalError: error });
17928
18597
  }
18598
+ var IF_MATCH_HEADER = "If-Match";
18599
+ var CONCURRENCY_REPORT_HEADER = "X-Posty5-Concurrency";
18600
+ var CONCURRENCY_REPORT_MISSING_VERSION = "missing-version";
18601
+ var NON_RETRYABLE_VERSION_STATUSES = [409, 428];
18602
+ function assertVersion(version, name = "version") {
18603
+ if (typeof version !== "number" || !Number.isInteger(version) || version < 0) {
18604
+ throw new TypeError(`Posty5: \`${name}\` must be a non-negative integer (the document's __v), got ${String(version)}`);
18605
+ }
18606
+ }
18607
+ function ifMatchHeader(version) {
18608
+ assertVersion(version);
18609
+ return `"${version}"`;
18610
+ }
18611
+ function hasIfMatch(headers) {
18612
+ if (!headers) return false;
18613
+ if (typeof headers.get === "function") {
18614
+ const value = headers.get(IF_MATCH_HEADER);
18615
+ if (value !== void 0 && value !== null) return true;
18616
+ }
18617
+ return Object.keys(headers).some((key) => key.toLowerCase() === IF_MATCH_HEADER.toLowerCase());
18618
+ }
18619
+ function withVersion(response, id) {
18620
+ const result = response.result && typeof response.result === "object" ? { ...response.result } : {};
18621
+ if (id !== void 0 && result._id === void 0) result._id = id;
18622
+ if (typeof response.version === "number") result.__v = response.version;
18623
+ return result;
18624
+ }
18625
+ var missingVersionWarned = false;
18626
+ function warnOnMissingVersion(headers, method, url2) {
18627
+ if (missingVersionWarned || !headers) return false;
18628
+ const value = typeof headers.get === "function" ? headers.get(CONCURRENCY_REPORT_HEADER) : headers[CONCURRENCY_REPORT_HEADER.toLowerCase()];
18629
+ if (String(value ?? "").toLowerCase() !== CONCURRENCY_REPORT_MISSING_VERSION) return false;
18630
+ missingVersionWarned = true;
18631
+ console.warn(
18632
+ `[Posty5 SDK] ${String(method || "").toUpperCase()} ${url2 ?? ""} was sent without a document version; the API will refuse it once versions are enforced. Please report this SDK bug.`
18633
+ );
18634
+ return true;
18635
+ }
18636
+ function shouldRetryRequest(error) {
18637
+ const method = String(error?.config?.method || "").toUpperCase();
18638
+ const idempotent = IDEMPOTENT_METHODS.includes(method);
18639
+ const status = error?.response?.status;
18640
+ if (hasIfMatch(error?.config?.headers)) return false;
18641
+ if (status !== void 0 && NON_RETRYABLE_VERSION_STATUSES.includes(status)) return false;
18642
+ if (status === void 0) {
18643
+ if (idempotent) return esm_default.isNetworkError(error);
18644
+ return NEVER_CONNECTED_ERROR_CODES.includes(String(error?.code || ""));
18645
+ }
18646
+ return idempotent && status >= 500;
18647
+ }
18648
+ function decodeBinaryErrorBody(error) {
18649
+ const response = error?.response;
18650
+ const data = response?.data;
18651
+ const isBytes = data instanceof ArrayBuffer || typeof Uint8Array !== "undefined" && data instanceof Uint8Array;
18652
+ if (!isBytes) return error;
18653
+ const text = new TextDecoder().decode(data).trim();
18654
+ if (!text) return error;
18655
+ try {
18656
+ response.data = JSON.parse(text);
18657
+ } catch {
18658
+ }
18659
+ return error;
18660
+ }
17929
18661
  function parseFileName(disposition) {
17930
18662
  if (!disposition) return void 0;
17931
18663
  const match = /filename\*?=(?:UTF-8'')?"?([^";]+)"?/i.exec(disposition);
@@ -17936,39 +18668,47 @@ function parseFileName(disposition) {
17936
18668
  return match[1];
17937
18669
  }
17938
18670
  }
18671
+ var apiKeys = /* @__PURE__ */ new WeakMap();
17939
18672
  var HttpClient = class {
17940
18673
  constructor(config = {}) {
18674
+ const { apiKey, ...publicConfig } = config;
18675
+ apiKeys.set(this, apiKey);
17941
18676
  this.config = {
17942
- timeout: 3e4,
17943
- maxRetries: 3,
17944
- retryDelay: 1e3,
17945
- ...config,
17946
- baseUrl: config.baseUrl || process.env.POSTY5_BASE_URL || "https://api.posty5.com"
18677
+ timeout: DEFAULT_TIMEOUT_MS,
18678
+ maxRetries: DEFAULT_MAX_RETRIES,
18679
+ retryDelay: DEFAULT_RETRY_DELAY_MS,
18680
+ ...publicConfig,
18681
+ baseUrl: config.baseUrl || process.env.POSTY5_BASE_URL || DEFAULT_BASE_URL
17947
18682
  };
18683
+ if (isInsecureBaseUrl(this.config.baseUrl)) {
18684
+ console.warn(`[Posty5 SDK] baseUrl ${this.config.baseUrl} is plain http: the API key travels unencrypted. Use https.`);
18685
+ }
17948
18686
  this.axiosInstance = axios_default.create({
17949
18687
  baseURL: this.config.baseUrl,
17950
18688
  timeout: this.config.timeout,
17951
18689
  headers: {
17952
18690
  "Content-Type": "application/json",
18691
+ [CLIENT_HEADER_NAME]: SDK_CLIENT_ID,
17953
18692
  ...this.config.headers
17954
- }
18693
+ },
18694
+ // A redirect to another origin must not carry the API key along.
18695
+ beforeRedirect: apiKeyRedirectGuard(this.config.baseUrl)
17955
18696
  });
17956
18697
  esm_default(this.axiosInstance, {
17957
- retries: this.config.maxRetries || 3,
18698
+ retries: this.config.maxRetries ?? DEFAULT_MAX_RETRIES,
17958
18699
  retryDelay: (retryCount) => {
17959
- return retryCount * (this.config.retryDelay || 1e3);
18700
+ return retryCount * (this.config.retryDelay ?? DEFAULT_RETRY_DELAY_MS);
17960
18701
  },
17961
- retryCondition: (error) => {
17962
- return esm_default.isNetworkOrIdempotentRequestError(error) || error.response?.status !== void 0 && error.response.status >= 500;
17963
- }
18702
+ retryCondition: shouldRetryRequest
17964
18703
  });
17965
18704
  this.axiosInstance.interceptors.request.use(
17966
18705
  (config2) => {
17967
- if (this.config.apiKey) {
17968
- config2.headers["X-API-Key"] = this.config.apiKey;
18706
+ const apiKey2 = apiKeys.get(this);
18707
+ if (apiKey2) {
18708
+ config2.headers[API_KEY_HEADER_NAME] = apiKey2;
17969
18709
  } else {
17970
18710
  if (process.env.POSTY5_API_KEY) {
17971
- config2.headers["X-API-Key"] = process.env.POSTY5_API_KEY;
18711
+ config2.headers[API_KEY_HEADER_NAME] = process.env.POSTY5_API_KEY;
17972
18712
  }
17973
18713
  }
17974
18714
  if (this.config.debug) {
@@ -17982,13 +18722,14 @@ var HttpClient = class {
17982
18722
  },
17983
18723
  (error) => {
17984
18724
  if (this.config.debug) {
17985
- console.log("[Posty5 SDK] Request Error:", error);
18725
+ console.log("[Posty5 SDK] Request Error:", error?.message);
17986
18726
  }
17987
18727
  return Promise.reject(transformError(error));
17988
18728
  }
17989
18729
  );
17990
18730
  this.axiosInstance.interceptors.response.use(
17991
18731
  (response) => {
18732
+ warnOnMissingVersion(response.headers, response.config?.method, response.config?.url);
17992
18733
  if (this.config.debug) {
17993
18734
  console.log("[Posty5 SDK] Response:", {
17994
18735
  status: response.status,
@@ -18001,27 +18742,32 @@ var HttpClient = class {
18001
18742
  if (this.config.debug) {
18002
18743
  console.error("[Posty5 SDK] Error:", JSON.stringify(error.response?.data || error.message));
18003
18744
  }
18004
- return Promise.reject(transformError(error));
18745
+ return Promise.reject(transformError(decodeBinaryErrorBody(error)));
18005
18746
  }
18006
18747
  );
18007
18748
  }
18749
+ /** The `createdFrom` label the clients stamp on records they create. */
18750
+ get createdFrom() {
18751
+ return this.config.createdFrom || DEFAULT_CREATED_FROM;
18752
+ }
18008
18753
  /**
18009
18754
  * Set or update the API key
18010
18755
  */
18011
18756
  setApiKey(apiKey) {
18012
- this.config.apiKey = apiKey;
18757
+ apiKeys.set(this, apiKey);
18013
18758
  }
18014
18759
  /**
18015
18760
  * Clear authentication credentials
18016
18761
  */
18017
18762
  clearAuth() {
18018
- this.config.apiKey = void 0;
18763
+ apiKeys.set(this, void 0);
18019
18764
  }
18020
18765
  /**
18021
18766
  * Make a GET request
18022
18767
  */
18023
18768
  async get(url2, config) {
18024
18769
  try {
18770
+ assertNoDotSegments(url2);
18025
18771
  const response = await this.axiosInstance.get(url2, this.buildConfig(config));
18026
18772
  return response.data;
18027
18773
  } catch (error) {
@@ -18033,6 +18779,7 @@ var HttpClient = class {
18033
18779
  */
18034
18780
  async post(url2, data, config) {
18035
18781
  try {
18782
+ assertNoDotSegments(url2);
18036
18783
  const response = await this.axiosInstance.post(url2, data, this.buildConfig(config));
18037
18784
  return response.data;
18038
18785
  } catch (error) {
@@ -18044,6 +18791,7 @@ var HttpClient = class {
18044
18791
  */
18045
18792
  async put(url2, data, config) {
18046
18793
  try {
18794
+ assertNoDotSegments(url2);
18047
18795
  const response = await this.axiosInstance.put(url2, data, this.buildConfig(config));
18048
18796
  return response.data;
18049
18797
  } catch (error) {
@@ -18055,11 +18803,12 @@ var HttpClient = class {
18055
18803
  */
18056
18804
  async patch(url2, data, config) {
18057
18805
  try {
18806
+ assertNoDotSegments(url2);
18058
18807
  const response = await this.axiosInstance.patch(url2, data, this.buildConfig(config));
18059
18808
  return response.data;
18060
18809
  } catch (error) {
18061
18810
  if (this.config.debug) {
18062
- console.log("[Posty5 SDK] PATCH Request Error:", error);
18811
+ console.log("[Posty5 SDK] PATCH Request Error:", error?.message);
18063
18812
  }
18064
18813
  throw transformError(error);
18065
18814
  }
@@ -18069,11 +18818,12 @@ var HttpClient = class {
18069
18818
  */
18070
18819
  async delete(url2, config) {
18071
18820
  try {
18821
+ assertNoDotSegments(url2);
18072
18822
  const response = await this.axiosInstance.delete(url2, this.buildConfig(config));
18073
18823
  return response.data;
18074
18824
  } catch (error) {
18075
18825
  if (this.config.debug) {
18076
- console.log("[Posty5 SDK] DELETE Request Error:", error);
18826
+ console.log("[Posty5 SDK] DELETE Request Error:", error?.message);
18077
18827
  }
18078
18828
  throw transformError(error);
18079
18829
  }
@@ -18087,6 +18837,7 @@ var HttpClient = class {
18087
18837
  */
18088
18838
  async getBinary(url2, config) {
18089
18839
  try {
18840
+ assertNoDotSegments(url2);
18090
18841
  const response = await this.axiosInstance.get(url2, {
18091
18842
  ...this.buildConfig(config),
18092
18843
  responseType: "arraybuffer"
@@ -18109,11 +18860,18 @@ var HttpClient = class {
18109
18860
  }
18110
18861
  const axiosConfig = {};
18111
18862
  if (config.headers) {
18112
- axiosConfig.headers = config.headers;
18863
+ axiosConfig.headers = { ...config.headers };
18864
+ }
18865
+ if (config.version !== void 0) {
18866
+ axiosConfig.headers = { ...axiosConfig.headers || {}, [IF_MATCH_HEADER]: ifMatchHeader(config.version) };
18867
+ axiosConfig["axios-retry"] = { retries: 0 };
18113
18868
  }
18114
18869
  if (config.params) {
18115
18870
  axiosConfig.params = config.params;
18116
18871
  }
18872
+ if (config.data !== void 0) {
18873
+ axiosConfig.data = config.data;
18874
+ }
18117
18875
  if (config.timeout) {
18118
18876
  axiosConfig.timeout = config.timeout;
18119
18877
  }
@@ -18371,7 +19129,7 @@ var SocialPublisherPostClient = class {
18371
19129
  * @param id - Post ID
18372
19130
  */
18373
19131
  async getStatus(id) {
18374
- const response = await this.http.get(`${this.basePath}/${id}/status`);
19132
+ const response = await this.http.get(`${this.basePath}/${encodeURIComponent(id)}/status`);
18375
19133
  return response.result;
18376
19134
  }
18377
19135
  /**
@@ -18393,24 +19151,27 @@ var SocialPublisherPostClient = class {
18393
19151
  * cannot be removed programmatically and no credits are charged.
18394
19152
  *
18395
19153
  * @param id - Post ID
18396
- * @returns Per-platform removal results
19154
+ * @param version - The post's `__v` as you read it. A stale one throws `ConflictError`.
19155
+ * @returns Per-platform removal results, `__v` set to the post's new version
18397
19156
  *
18398
19157
  * @example
18399
19158
  * ```ts
18400
- * const { results } = await client.removePost("post_123");
19159
+ * const post = await client.getStatus("post_123");
19160
+ * const { results } = await client.removePost("post_123", post.__v);
18401
19161
  * // results.youtube?.success === true
18402
19162
  * ```
18403
19163
  */
18404
- async removePost(id) {
18405
- const response = await this.http.post(`${this.basePath}/${id}/remove`, {});
18406
- return response.result;
19164
+ async removePost(id, version) {
19165
+ assertVersion(version);
19166
+ const response = await this.http.post(`${this.basePath}/${encodeURIComponent(id)}/remove`, {}, { version });
19167
+ return withVersion(response, id);
18407
19168
  }
18408
19169
  /**
18409
19170
  * Get next and previous post IDs
18410
19171
  * @param id - Current Post ID
18411
19172
  */
18412
19173
  async getNextAndPrevious(id) {
18413
- const response = await this.http.get(`${this.basePath}/${id}/next-previous`);
19174
+ const response = await this.http.get(`${this.basePath}/${encodeURIComponent(id)}/next-previous`);
18414
19175
  return response.result;
18415
19176
  }
18416
19177
  /**
@@ -18419,10 +19180,10 @@ var SocialPublisherPostClient = class {
18419
19180
  * @param id - Optional ID for updating/retrying? (Based on route :id?)
18420
19181
  */
18421
19182
  async createToWorkspaceByFile(data, id) {
18422
- const url2 = id ? `${this.basePath}/short-video/workspace/by-file/${id}` : `${this.basePath}/short-video/workspace/by-file`;
19183
+ const url2 = id ? `${this.basePath}/short-video/workspace/by-file/${encodeURIComponent(id)}` : `${this.basePath}/short-video/workspace/by-file`;
18423
19184
  const response = await this.http.post(url2, {
18424
19185
  ...data,
18425
- createdFrom: "npmPackage"
19186
+ createdFrom: this.http.createdFrom
18426
19187
  });
18427
19188
  return response.result?._id;
18428
19189
  }
@@ -18432,10 +19193,10 @@ var SocialPublisherPostClient = class {
18432
19193
  * @param id - Optional ID for updating/retrying? (Based on route :id?)
18433
19194
  */
18434
19195
  async createToWorkspaceByURL(data, id) {
18435
- const url2 = id ? `${this.basePath}/short-video/workspace/by-url/${id}` : `${this.basePath}/short-video/workspace/by-url`;
19196
+ const url2 = id ? `${this.basePath}/short-video/workspace/by-url/${encodeURIComponent(id)}` : `${this.basePath}/short-video/workspace/by-url`;
18436
19197
  const response = await this.http.post(url2, {
18437
19198
  ...data,
18438
- createdFrom: "npmPackage"
19199
+ createdFrom: this.http.createdFrom
18439
19200
  });
18440
19201
  return response.result?._id;
18441
19202
  }
@@ -18445,10 +19206,10 @@ var SocialPublisherPostClient = class {
18445
19206
  * @param id - Optional ID for updating/retrying?
18446
19207
  */
18447
19208
  async createToAccountByFile(data, id) {
18448
- const url2 = id ? `${this.basePath}/short-video/account/by-file/${id}` : `${this.basePath}/short-video/account/by-file`;
19209
+ const url2 = id ? `${this.basePath}/short-video/account/by-file/${encodeURIComponent(id)}` : `${this.basePath}/short-video/account/by-file`;
18449
19210
  const response = await this.http.post(url2, {
18450
19211
  ...data,
18451
- createdFrom: "npmPackage"
19212
+ createdFrom: this.http.createdFrom
18452
19213
  });
18453
19214
  return response.result?._id;
18454
19215
  }
@@ -18458,10 +19219,10 @@ var SocialPublisherPostClient = class {
18458
19219
  * @param id - Optional ID for updating/retrying?
18459
19220
  */
18460
19221
  async createToAccountByURL(data, id) {
18461
- const url2 = id ? `${this.basePath}/short-video/account/by-url/${id}` : `${this.basePath}/short-video/account/by-url`;
19222
+ const url2 = id ? `${this.basePath}/short-video/account/by-url/${encodeURIComponent(id)}` : `${this.basePath}/short-video/account/by-url`;
18462
19223
  const response = await this.http.post(url2, {
18463
19224
  ...data,
18464
- createdFrom: "npmPackage"
19225
+ createdFrom: this.http.createdFrom
18465
19226
  });
18466
19227
  return response.result?._id;
18467
19228
  }
@@ -18482,10 +19243,10 @@ var SocialPublisherPostClient = class {
18482
19243
  * ```
18483
19244
  */
18484
19245
  async createImagePostToWorkspace(data, id) {
18485
- const url2 = id ? `${this.basePath}/image/workspace/${id}` : `${this.basePath}/image/workspace`;
19246
+ const url2 = id ? `${this.basePath}/image/workspace/${encodeURIComponent(id)}` : `${this.basePath}/image/workspace`;
18486
19247
  const response = await this.http.post(url2, {
18487
19248
  ...data,
18488
- createdFrom: "npmPackage"
19249
+ createdFrom: this.http.createdFrom
18489
19250
  });
18490
19251
  return response.result?._id;
18491
19252
  }
@@ -18495,13 +19256,53 @@ var SocialPublisherPostClient = class {
18495
19256
  * platforms in the request are ignored.
18496
19257
  */
18497
19258
  async createImagePostToAccount(data, id) {
18498
- const url2 = id ? `${this.basePath}/image/account/${id}` : `${this.basePath}/image/account`;
19259
+ const url2 = id ? `${this.basePath}/image/account/${encodeURIComponent(id)}` : `${this.basePath}/image/account`;
18499
19260
  const response = await this.http.post(url2, {
18500
19261
  ...data,
18501
- createdFrom: "npmPackage"
19262
+ createdFrom: this.http.createdFrom
18502
19263
  });
18503
19264
  return response.result?._id;
18504
19265
  }
19266
+ /**
19267
+ * Publish a text-only post to every text-capable account in a workspace
19268
+ * (Facebook, Threads, X). Platforms that cannot take text are reported in
19269
+ * `skippedPlatforms`; X below the Pro plan is dropped into `refusedTargets`.
19270
+ */
19271
+ async createTextPostToWorkspace(data) {
19272
+ const response = await this.http.post(`${this.basePath}/text/workspace`, {
19273
+ ...data,
19274
+ createdFrom: this.http.createdFrom
19275
+ });
19276
+ return response.result;
19277
+ }
19278
+ /** Publish a text-only post to one account. */
19279
+ async createTextPostToAccount(data) {
19280
+ const response = await this.http.post(`${this.basePath}/text/account`, {
19281
+ ...data,
19282
+ createdFrom: this.http.createdFrom
19283
+ });
19284
+ return response.result;
19285
+ }
19286
+ /**
19287
+ * Publish a story to every story-capable account in a workspace. Media by URL
19288
+ * only in this release: `image: { source: "image-url", externalUrl }`, or
19289
+ * `source: "video-url"` with `videoURL`.
19290
+ */
19291
+ async createStoryPostToWorkspace(data) {
19292
+ const response = await this.http.post(`${this.basePath}/story/workspace`, {
19293
+ ...data,
19294
+ createdFrom: this.http.createdFrom
19295
+ });
19296
+ return response.result;
19297
+ }
19298
+ /** Publish a story to one account. Media by URL only, as for the workspace form. */
19299
+ async createStoryPostToAccount(data) {
19300
+ const response = await this.http.post(`${this.basePath}/story/account`, {
19301
+ ...data,
19302
+ createdFrom: this.http.createdFrom
19303
+ });
19304
+ return response.result;
19305
+ }
18505
19306
  /**
18506
19307
  * Handle thumbnail upload - accepts either File or URL string
18507
19308
  * @param thumb - Thumbnail as File (will be uploaded) or URL string (will be passed directly)
@@ -18848,8 +19649,8 @@ var SocialPublisherPostClient = class {
18848
19649
  };
18849
19650
  const target = isFile2 ? "by-file" : "by-url";
18850
19651
  const id = postId ?? thumb?.postId;
18851
- const url2 = id ? `${this.basePath}/long-video/workspace/${target}/${id}` : `${this.basePath}/long-video/workspace/${target}`;
18852
- const response = await this.http.post(url2, { ...body, createdFrom: "npmPackage" });
19652
+ const url2 = id ? `${this.basePath}/long-video/workspace/${target}/${encodeURIComponent(id)}` : `${this.basePath}/long-video/workspace/${target}`;
19653
+ const response = await this.http.post(url2, { ...body, createdFrom: this.http.createdFrom });
18853
19654
  return this.normaliseLongVideoResult(response.result);
18854
19655
  }
18855
19656
  /**
@@ -18900,8 +19701,8 @@ var SocialPublisherPostClient = class {
18900
19701
  };
18901
19702
  const target = isFile2 ? "by-file" : "by-url";
18902
19703
  const id = postId ?? thumb?.postId;
18903
- const url2 = id ? `${this.basePath}/long-video/account/${target}/${id}` : `${this.basePath}/long-video/account/${target}`;
18904
- const response = await this.http.post(url2, { ...body, createdFrom: "npmPackage" });
19704
+ const url2 = id ? `${this.basePath}/long-video/account/${target}/${encodeURIComponent(id)}` : `${this.basePath}/long-video/account/${target}`;
19705
+ const response = await this.http.post(url2, { ...body, createdFrom: this.http.createdFrom });
18905
19706
  return this.normaliseLongVideoResult(response.result);
18906
19707
  }
18907
19708
  /**
@@ -18913,18 +19714,29 @@ var SocialPublisherPostClient = class {
18913
19714
  *
18914
19715
  * @example
18915
19716
  * ```ts
18916
- * await client.reschedulePost("post_123", { schedule: new Date("2026-09-01T09:00:00Z") });
18917
- * await client.reschedulePost("post_123", { schedule: "now" });
19717
+ * const post = await client.getStatus("post_123");
19718
+ * const { __v } = await client.reschedulePost("post_123", { schedule: new Date("2026-09-01T09:00:00Z") }, post.__v);
19719
+ * await client.reschedulePost("post_123", { schedule: "now" }, __v);
18918
19720
  * ```
19721
+ *
19722
+ * @param version - The post's `__v` as you read it. A stale one throws `ConflictError`.
19723
+ * @returns `{ _id, __v }`, `__v` being the new version
18919
19724
  */
18920
- async reschedulePost(id, data) {
19725
+ async reschedulePost(id, data, version) {
18921
19726
  if (!id) {
18922
19727
  throw new Error("id is required");
18923
19728
  }
18924
- await this.http.put(`${this.basePath}/${id}`, {
18925
- schedule: this.buildSchedule(data.schedule),
18926
- ...data.caption !== void 0 ? { caption: data.caption } : {}
18927
- });
19729
+ assertVersion(version);
19730
+ const response = await this.http.put(
19731
+ `${this.basePath}/${encodeURIComponent(id)}`,
19732
+ {
19733
+ ...data.schedule === "now" ? { scheduleType: "now" } : { scheduleType: "schedule", scheduledAt: data.schedule.toISOString() },
19734
+ ...data.caption !== void 0 ? { caption: data.caption } : {}
19735
+ },
19736
+ { version }
19737
+ );
19738
+ const updated = withVersion(response, id);
19739
+ return { _id: updated._id, __v: updated.__v };
18928
19740
  }
18929
19741
  /**
18930
19742
  * Delete a post that has not published yet, releasing its uploaded media in
@@ -18936,14 +19748,17 @@ var SocialPublisherPostClient = class {
18936
19748
  *
18937
19749
  * @example
18938
19750
  * ```ts
18939
- * await client.deletePost("post_123");
19751
+ * await client.deletePost("post_123", post.__v);
18940
19752
  * ```
19753
+ *
19754
+ * @param version - The post's `__v` as you read it. A stale one throws `ConflictError`.
18941
19755
  */
18942
- async deletePost(id) {
19756
+ async deletePost(id, version) {
18943
19757
  if (!id) {
18944
19758
  throw new Error("id is required");
18945
19759
  }
18946
- await this.http.delete(`${this.basePath}/${id}`);
19760
+ assertVersion(version);
19761
+ await this.http.delete(`${this.basePath}/${encodeURIComponent(id)}`, { version });
18947
19762
  }
18948
19763
  /**
18949
19764
  * Upload a long video and return the URL to publish from.