@salable/sdk 1.0.41 → 1.0.43

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.js CHANGED
@@ -409,21 +409,21 @@ const deserializeIntoUntypedNode = (untypedNode = {}) => {
409
409
  * @param node The object to check.
410
410
  * @returns boolean indicating if the node is an UntypedNumber.
411
411
  */
412
- function isUntypedNumber(node) {
412
+ const isUntypedNumber = (node) => {
413
413
  const proposedNode = node;
414
414
  return proposedNode && typeof proposedNode.value === "number";
415
- }
415
+ };
416
416
  /**
417
417
  * Factory to create an UntypedNumber from a number.
418
418
  * @param value The number value to create from.
419
419
  * @returns The created UntypedNumber.
420
420
  */
421
- function createUntypedNumber(value) {
421
+ const createUntypedNumber = (value) => {
422
422
  return {
423
423
  value,
424
424
  getValue: () => value,
425
425
  };
426
- }
426
+ };
427
427
 
428
428
  /**
429
429
  * -------------------------------------------------------------------------------------------
@@ -457,19 +457,19 @@ const createUntypedArray = (value) => {
457
457
  * @param node The object to check.
458
458
  * @returns boolean indicating if the node is an UntypedNull.
459
459
  */
460
- function isUntypedNull(node) {
460
+ const isUntypedNull = (node) => {
461
461
  return node.value === null;
462
- }
462
+ };
463
463
  /**
464
- * Factory to create an UntypedNull from a boolean.
464
+ * Factory to create an UntypedNull.
465
465
  * @returns The created UntypedNull.
466
466
  */
467
- function createUntypedNull() {
467
+ const createUntypedNull = () => {
468
468
  return {
469
469
  value: null,
470
470
  getValue: () => null,
471
471
  };
472
- }
472
+ };
473
473
 
474
474
  /**
475
475
  * -------------------------------------------------------------------------------------------
@@ -503,42 +503,42 @@ const createUntypedObject = (value) => {
503
503
  * @param node The object to check.
504
504
  * @returns boolean indicating if the node is an UntypedString.
505
505
  */
506
- function isUntypedString(node) {
506
+ const isUntypedString = (node) => {
507
507
  const proposedNode = node;
508
508
  return proposedNode && typeof proposedNode.value === "string";
509
- }
509
+ };
510
510
  /**
511
511
  * Factory to create an UntypedString from a string.
512
512
  * @param value The string value to create from.
513
513
  * @returns The created UntypedString.
514
514
  */
515
- function createUntypedString(value) {
515
+ const createUntypedString = (value) => {
516
516
  return {
517
517
  value,
518
518
  getValue: () => value,
519
519
  };
520
- }
520
+ };
521
521
 
522
522
  /**
523
523
  * Type guard to assert that an UntypedNode instance is an UntypedBoolean.
524
524
  * @param node The UntypedNode to check.
525
525
  * @returns boolean indicating if the node is an UntypedBoolean.
526
526
  */
527
- function isUntypedBoolean(node) {
527
+ const isUntypedBoolean = (node) => {
528
528
  const proposedNode = node;
529
529
  return proposedNode && typeof proposedNode.value === "boolean";
530
- }
530
+ };
531
531
  /**
532
532
  * Factory to create an UntypedBoolean from a boolean.
533
533
  * @param value The boolean value to create from.
534
534
  * @returns The created UntypedBoolean.
535
535
  */
536
- function createUntypedBoolean(value) {
536
+ const createUntypedBoolean = (value) => {
537
537
  return {
538
538
  value,
539
539
  getValue: () => value,
540
540
  };
541
- }
541
+ };
542
542
 
543
543
  /**
544
544
  * -------------------------------------------------------------------------------------------
@@ -792,10 +792,10 @@ const BackingStoreKey = "backingStoreEnabled";
792
792
  * @param fields The fields of the object
793
793
  * @returns boolean indicating if the object is a BackedModel
794
794
  */
795
- function isBackingStoreEnabled(fields) {
795
+ const isBackingStoreEnabled = (fields) => {
796
796
  // Check if the fields contain the backing store key
797
797
  return Object.keys(fields).includes(BackingStoreKey);
798
- }
798
+ };
799
799
 
800
800
  /**
801
801
  * -------------------------------------------------------------------------------------------
@@ -810,7 +810,7 @@ function isBackingStoreEnabled(fields) {
810
810
  * @param original The serialization writer to enable the backing store on.
811
811
  * @returns A new serialization writer with the backing store enabled.
812
812
  */
813
- function enableBackingStoreForSerializationWriterFactory(serializationWriterFactoryRegistry, parseNodeFactoryRegistry, original) {
813
+ const enableBackingStoreForSerializationWriterFactory = (serializationWriterFactoryRegistry, parseNodeFactoryRegistry, original) => {
814
814
  if (!original)
815
815
  throw new Error("Original must be specified");
816
816
  let result = original;
@@ -823,14 +823,14 @@ function enableBackingStoreForSerializationWriterFactory(serializationWriterFact
823
823
  enableBackingStoreForSerializationRegistry(serializationWriterFactoryRegistry);
824
824
  enableBackingStoreForParseNodeRegistry(parseNodeFactoryRegistry);
825
825
  return result;
826
- }
826
+ };
827
827
  /**
828
828
  * Enables the backing store on default parse node factories and the given parse node factory.
829
829
  * @param parseNodeFactoryRegistry The parse node factory registry to enable the backing store on.
830
830
  * @param original The parse node factory to enable the backing store on.
831
831
  * @returns A new parse node factory with the backing store enabled.
832
832
  */
833
- function enableBackingStoreForParseNodeFactory(parseNodeFactoryRegistry, original) {
833
+ const enableBackingStoreForParseNodeFactory = (parseNodeFactoryRegistry, original) => {
834
834
  if (!original)
835
835
  throw new Error("Original must be specified");
836
836
  let result = original;
@@ -842,29 +842,29 @@ function enableBackingStoreForParseNodeFactory(parseNodeFactoryRegistry, origina
842
842
  }
843
843
  enableBackingStoreForParseNodeRegistry(parseNodeFactoryRegistry);
844
844
  return result;
845
- }
845
+ };
846
846
  /**
847
847
  * Enables the backing store on the given parse node factory registry.
848
848
  * @param registry The parse node factory registry to enable the backing store on.
849
849
  */
850
- function enableBackingStoreForParseNodeRegistry(registry) {
850
+ const enableBackingStoreForParseNodeRegistry = (registry) => {
851
851
  for (const [k, v] of registry.contentTypeAssociatedFactories) {
852
852
  if (!(v instanceof BackingStoreParseNodeFactory || v instanceof ParseNodeFactoryRegistry)) {
853
853
  registry.contentTypeAssociatedFactories.set(k, new BackingStoreParseNodeFactory(v));
854
854
  }
855
855
  }
856
- }
856
+ };
857
857
  /**
858
858
  * Enables the backing store on the given serialization factory registry.
859
859
  * @param registry The serialization factory registry to enable the backing store on.
860
860
  */
861
- function enableBackingStoreForSerializationRegistry(registry) {
861
+ const enableBackingStoreForSerializationRegistry = (registry) => {
862
862
  for (const [k, v] of registry.contentTypeAssociatedFactories) {
863
863
  if (!(v instanceof BackingStoreSerializationWriterProxyFactory || v instanceof SerializationWriterFactoryRegistry)) {
864
864
  registry.contentTypeAssociatedFactories.set(k, new BackingStoreSerializationWriterProxyFactory(v));
865
865
  }
866
866
  }
867
- }
867
+ };
868
868
 
869
869
  /*
870
870
  * Copyright The OpenTelemetry Authors
@@ -2637,9 +2637,9 @@ class DateOnly {
2637
2637
  * @param digits The number of digits to pad
2638
2638
  * @returns The formatted segment
2639
2639
  */
2640
- function formatSegment(segment, digits = 2) {
2640
+ const formatSegment = (segment, digits = 2) => {
2641
2641
  return segment.toString().padStart(digits, "0");
2642
- }
2642
+ };
2643
2643
 
2644
2644
  var dist = {};
2645
2645
 
@@ -2870,7 +2870,7 @@ class Duration {
2870
2870
  * @param canon The function that canonicalizes the property name.
2871
2871
  * @returns A new object that can be used as a dictionary with case-insensitive keys.
2872
2872
  */
2873
- function dictionaryWithCanonicalKeys(canon) {
2873
+ const dictionaryWithCanonicalKeys = (canon) => {
2874
2874
  const keysNormalizationMap = new Map();
2875
2875
  return new Proxy({}, {
2876
2876
  /**
@@ -2879,7 +2879,7 @@ function dictionaryWithCanonicalKeys(canon) {
2879
2879
  * @param prop The property to get.
2880
2880
  * @returns The value of the property.
2881
2881
  */
2882
- get(target, prop) {
2882
+ get: (target, prop) => {
2883
2883
  const normalKey = canon(prop);
2884
2884
  return Reflect.get(target, normalKey);
2885
2885
  },
@@ -2890,7 +2890,7 @@ function dictionaryWithCanonicalKeys(canon) {
2890
2890
  * @param value The value to set.
2891
2891
  * @returns A boolean indicating whether the property was set.
2892
2892
  */
2893
- set(target, prop, value) {
2893
+ set: (target, prop, value) => {
2894
2894
  const nonNormalKey = prop.toString();
2895
2895
  const normalKey = canon(prop);
2896
2896
  keysNormalizationMap.set(normalKey, nonNormalKey);
@@ -2902,7 +2902,7 @@ function dictionaryWithCanonicalKeys(canon) {
2902
2902
  * @param prop The property to check.
2903
2903
  * @returns A boolean indicating whether the property exists.
2904
2904
  */
2905
- has(_, prop) {
2905
+ has: (_, prop) => {
2906
2906
  const normalKey = canon(prop);
2907
2907
  return keysNormalizationMap.has(normalKey);
2908
2908
  },
@@ -2913,7 +2913,7 @@ function dictionaryWithCanonicalKeys(canon) {
2913
2913
  * @param attribs The attributes of the property.
2914
2914
  * @returns A boolean indicating whether the property was defined.
2915
2915
  */
2916
- defineProperty(target, prop, attribs) {
2916
+ defineProperty: (target, prop, attribs) => {
2917
2917
  const nonNormalKey = prop.toString();
2918
2918
  const normalKey = canon(prop);
2919
2919
  keysNormalizationMap.set(normalKey, nonNormalKey);
@@ -2925,7 +2925,7 @@ function dictionaryWithCanonicalKeys(canon) {
2925
2925
  * @param prop The property to delete.
2926
2926
  * @returns A boolean indicating whether the property was deleted.
2927
2927
  */
2928
- deleteProperty(target, prop) {
2928
+ deleteProperty: (target, prop) => {
2929
2929
  const normalKey = canon(prop);
2930
2930
  keysNormalizationMap.delete(normalKey);
2931
2931
  return Reflect.deleteProperty(target, normalKey);
@@ -2936,19 +2936,19 @@ function dictionaryWithCanonicalKeys(canon) {
2936
2936
  * @param prop The property to gets its descriptor.
2937
2937
  * @returns The property descriptor.
2938
2938
  */
2939
- getOwnPropertyDescriptor(target, prop) {
2939
+ getOwnPropertyDescriptor: (target, prop) => {
2940
2940
  return Reflect.getOwnPropertyDescriptor(target, canon(prop));
2941
2941
  },
2942
- ownKeys() {
2942
+ ownKeys: () => {
2943
2943
  return [...keysNormalizationMap.values()];
2944
2944
  },
2945
2945
  });
2946
- }
2946
+ };
2947
2947
  /**
2948
2948
  * A wrapper for type Record that creates a Record with case insensitive keys
2949
2949
  * @returns A new object that can be used as a dictionary with case-insensitive keys.
2950
2950
  */
2951
- function createRecordWithCaseInsensitiveKeys() {
2951
+ const createRecordWithCaseInsensitiveKeys = () => {
2952
2952
  /**
2953
2953
  * A function that takes a property name and returns its canonical form.
2954
2954
  * @param prop The property name to be canonicalized.
@@ -2956,7 +2956,7 @@ function createRecordWithCaseInsensitiveKeys() {
2956
2956
  */
2957
2957
  const record = dictionaryWithCanonicalKeys((p) => (typeof p === "string" ? p.toLowerCase() : p.toString().toLowerCase()));
2958
2958
  return record;
2959
- }
2959
+ };
2960
2960
 
2961
2961
  /**
2962
2962
  * -------------------------------------------------------------------------------------------
@@ -3056,6 +3056,7 @@ class Headers extends Map {
3056
3056
  * @param callbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each header in the dictionary.
3057
3057
  * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
3058
3058
  */
3059
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3059
3060
  forEach(callbackfn, thisArg) {
3060
3061
  for (const header in this.headers) {
3061
3062
  if (Object.prototype.hasOwnProperty.call(this.headers, header)) {
@@ -3337,10 +3338,10 @@ const serializeMultipartBody = (writer, multipartBody = new MultipartBody()) =>
3337
3338
  writer.writeStringValue(undefined, part.content);
3338
3339
  }
3339
3340
  else if (part.content instanceof ArrayBuffer) {
3340
- writer.writeByteArrayValue(undefined, new Uint8Array(part.content));
3341
+ writer.writeByteArrayValue(undefined, new Uint8Array(part.content).buffer);
3341
3342
  }
3342
3343
  else if (part.content instanceof Uint8Array) {
3343
- writer.writeByteArrayValue(undefined, part.content);
3344
+ writer.writeByteArrayValue(undefined, part.content.buffer);
3344
3345
  }
3345
3346
  else if (part.serializationCallback) {
3346
3347
  if (!multipartBody.requestAdapter) {
@@ -3356,7 +3357,7 @@ const serializeMultipartBody = (writer, multipartBody = new MultipartBody()) =>
3356
3357
  }
3357
3358
  partSerializationWriter.writeObjectValue(undefined, part.content, part.serializationCallback);
3358
3359
  const partContent = partSerializationWriter.getSerializedContent();
3359
- writer.writeByteArrayValue(undefined, new Uint8Array(partContent));
3360
+ writer.writeByteArrayValue(undefined, new Uint8Array(partContent).buffer);
3360
3361
  }
3361
3362
  else {
3362
3363
  throw new Error("unsupported content type for multipart body: " + typeof part.content);
@@ -4020,6 +4021,10 @@ const apiClientProxifier = (requestAdapter, pathParameters, navigationMetadata,
4020
4021
  return apiClientProxifier(requestAdapter, downWardPathParameters, navigationCandidate.navigationMetadata, navigationCandidate.requestsMetadata);
4021
4022
  };
4022
4023
  }
4024
+ if (name === "then") {
4025
+ // handle returning proxy from an async method
4026
+ return undefined;
4027
+ }
4023
4028
  throw new Error(`couldn't find navigation property ${name} data: ${JSON.stringify(navigationMetadata)}`);
4024
4029
  }
4025
4030
  },
@@ -4057,7 +4062,7 @@ class AllowedHostsValidator {
4057
4062
  */
4058
4063
  constructor(allowedHosts = new Set()) {
4059
4064
  this.validateHosts(allowedHosts);
4060
- this.allowedHosts = allowedHosts !== null && allowedHosts !== void 0 ? allowedHosts : new Set();
4065
+ this.allowedHosts = this.normalizeHosts(allowedHosts);
4061
4066
  }
4062
4067
  /**
4063
4068
  * Gets the list of valid hosts. If the list is empty, all hosts are valid.
@@ -4072,7 +4077,7 @@ class AllowedHostsValidator {
4072
4077
  */
4073
4078
  setAllowedHosts(allowedHosts) {
4074
4079
  this.validateHosts(allowedHosts);
4075
- this.allowedHosts = allowedHosts;
4080
+ this.allowedHosts = this.normalizeHosts(allowedHosts);
4076
4081
  }
4077
4082
  /**
4078
4083
  * Checks whether the provided host is valid.
@@ -4080,7 +4085,7 @@ class AllowedHostsValidator {
4080
4085
  * @returns True if the host is valid, false otherwise.
4081
4086
  */
4082
4087
  isUrlHostValid(url) {
4083
- var _a, _b;
4088
+ var _a;
4084
4089
  if (!url)
4085
4090
  return false;
4086
4091
  if (this.allowedHosts.size === 0)
@@ -4097,7 +4102,7 @@ class AllowedHostsValidator {
4097
4102
  return this.isHostAndPathValid(url);
4098
4103
  }
4099
4104
  if ((_a = window === null || window === void 0 ? void 0 : window.location) === null || _a === void 0 ? void 0 : _a.host) {
4100
- return this.allowedHosts.has((_b = window.location.host) === null || _b === void 0 ? void 0 : _b.toLowerCase());
4105
+ return this.isHostValid(window.location.host);
4101
4106
  }
4102
4107
  return false;
4103
4108
  }
@@ -4106,11 +4111,21 @@ class AllowedHostsValidator {
4106
4111
  if (hostAndRest.length >= 2) {
4107
4112
  const host = hostAndRest[0];
4108
4113
  if (host) {
4109
- return this.allowedHosts.has(host.toLowerCase());
4114
+ return this.isHostValid(host.split(":")[0]);
4110
4115
  }
4111
4116
  }
4112
4117
  return false;
4113
4118
  }
4119
+ isHostValid(host) {
4120
+ const normalizedHost = host.toLowerCase();
4121
+ if (this.allowedHosts.has(normalizedHost)) {
4122
+ return true;
4123
+ }
4124
+ return Array.from(this.allowedHosts).some((allowedHost) => allowedHost.startsWith(".") && normalizedHost.endsWith(allowedHost));
4125
+ }
4126
+ normalizeHosts(hostsToNormalize) {
4127
+ return new Set(Array.from(hostsToNormalize, (host) => host.toLowerCase()));
4128
+ }
4114
4129
  validateHosts(hostsToValidate) {
4115
4130
  if (!hostsToValidate) {
4116
4131
  throw new Error("hostsToValidate cannot be null");
@@ -4134,27 +4149,27 @@ const localhostStrings = new Set(["localhost", "[::1]", "::1", "127.0.0.1"]);
4134
4149
  * Validates the protocol of the url.
4135
4150
  * @param url - The url to validate.
4136
4151
  */
4137
- function validateProtocol(url) {
4152
+ const validateProtocol = (url) => {
4138
4153
  if (!isLocalhostUrl(url) && !url.toLocaleLowerCase().startsWith("https://") && !windowUrlStartsWithHttps()) {
4139
4154
  throw new Error("Authentication scheme can only be used with https requests");
4140
4155
  }
4141
- }
4156
+ };
4142
4157
  /**
4143
4158
  * Checks if the window url starts with https.
4144
4159
  * @returns True if the window url starts with https, false otherwise.
4145
4160
  */
4146
- function windowUrlStartsWithHttps() {
4161
+ const windowUrlStartsWithHttps = () => {
4147
4162
  if (!inNodeEnv()) {
4148
4163
  return window.location.protocol.toLocaleLowerCase() === "https:";
4149
4164
  }
4150
4165
  return false;
4151
- }
4166
+ };
4152
4167
  /**
4153
4168
  * Checks if the url is a localhost url.
4154
4169
  * @param urlString - The url to check.
4155
4170
  * @returns True if the url is a localhost url, false otherwise.
4156
4171
  */
4157
- function isLocalhostUrl(urlString) {
4172
+ const isLocalhostUrl = (urlString) => {
4158
4173
  try {
4159
4174
  const url = new URL(urlString);
4160
4175
  return localhostStrings.has(url.hostname);
@@ -4162,7 +4177,7 @@ function isLocalhostUrl(urlString) {
4162
4177
  catch (_a) {
4163
4178
  return false;
4164
4179
  }
4165
- }
4180
+ };
4166
4181
 
4167
4182
  /** Authenticate a request by using an API Key */
4168
4183
  class ApiKeyAuthenticationProvider {
@@ -4287,14 +4302,9 @@ class HttpClient {
4287
4302
  middlewares = (middlewares === null || middlewares === void 0 ? void 0 : middlewares.length) && middlewares[0] ? middlewares : MiddlewareFactory.getDefaultMiddlewares(customFetch);
4288
4303
  // If a custom fetch function is provided, add a CustomFetchHandler to the end of the middleware chain
4289
4304
  if (this.customFetch) {
4290
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
4291
- middlewares.push(new CustomFetchHandler(customFetch));
4292
- }
4293
- // eslint-disable-next-line no-console
4294
- console.debug("Registered middlewares: " + middlewares.map((m) => m.constructor.name).join(", "));
4295
- // eslint-disable-next-line no-console
4296
- console.debug("Hint: To improve performance, use MiddlewareFactory.getPerformanceMiddlewares(customFetch) instead of MiddlewareFactory.getDefaultMiddlewares(customFetch)");
4297
- // Set the middleware chain
4305
+ middlewares.push(new CustomFetchHandler(this.customFetch));
4306
+ }
4307
+ // Set the middleware handlers chain
4298
4308
  this.setMiddleware(...middlewares);
4299
4309
  }
4300
4310
  /**
@@ -4349,7 +4359,7 @@ class ObservabilityOptionsImpl {
4349
4359
  * @param requestOptions The request options
4350
4360
  * @returns The observability options
4351
4361
  */
4352
- function getObservabilityOptionsFromRequest(requestOptions) {
4362
+ const getObservabilityOptionsFromRequest = (requestOptions) => {
4353
4363
  if (requestOptions) {
4354
4364
  const observabilityOptions = requestOptions[ObservabilityOptionKey];
4355
4365
  if (observabilityOptions instanceof ObservabilityOptionsImpl) {
@@ -4357,7 +4367,7 @@ function getObservabilityOptionsFromRequest(requestOptions) {
4357
4367
  }
4358
4368
  }
4359
4369
  return undefined;
4360
- }
4370
+ };
4361
4371
 
4362
4372
  /**
4363
4373
  * -------------------------------------------------------------------------------------------
@@ -4432,31 +4442,34 @@ class FetchRequestAdapter {
4432
4442
  case "number":
4433
4443
  case "boolean":
4434
4444
  case "Date":
4445
+ case "Duration":
4446
+ case "DateOnly":
4447
+ case "TimeOnly":
4435
4448
  // eslint-disable-next-line no-case-declarations
4436
4449
  const rootNode = await this.getRootParseNode(response);
4437
4450
  return trace.getTracer(this.observabilityOptions.getTracerInstrumentationName()).startActiveSpan(`getCollectionOf${responseType}Value`, (deserializeSpan) => {
4438
4451
  try {
4439
4452
  span.setAttribute(FetchRequestAdapter.responseTypeAttributeKey, responseType);
4440
4453
  if (responseType === "string") {
4441
- return rootNode.getCollectionOfPrimitiveValues();
4454
+ return rootNode.getCollectionOfPrimitiveValues(responseType);
4442
4455
  }
4443
4456
  else if (responseType === "number") {
4444
- return rootNode.getCollectionOfPrimitiveValues();
4457
+ return rootNode.getCollectionOfPrimitiveValues(responseType);
4445
4458
  }
4446
4459
  else if (responseType === "boolean") {
4447
- return rootNode.getCollectionOfPrimitiveValues();
4460
+ return rootNode.getCollectionOfPrimitiveValues(responseType);
4448
4461
  }
4449
4462
  else if (responseType === "Date") {
4450
- return rootNode.getCollectionOfPrimitiveValues();
4463
+ return rootNode.getCollectionOfPrimitiveValues(responseType);
4451
4464
  }
4452
4465
  else if (responseType === "Duration") {
4453
- return rootNode.getCollectionOfPrimitiveValues();
4466
+ return rootNode.getCollectionOfPrimitiveValues(responseType);
4454
4467
  }
4455
4468
  else if (responseType === "DateOnly") {
4456
- return rootNode.getCollectionOfPrimitiveValues();
4469
+ return rootNode.getCollectionOfPrimitiveValues(responseType);
4457
4470
  }
4458
4471
  else if (responseType === "TimeOnly") {
4459
- return rootNode.getCollectionOfPrimitiveValues();
4472
+ return rootNode.getCollectionOfPrimitiveValues(responseType);
4460
4473
  }
4461
4474
  else {
4462
4475
  throw new Error("unexpected type to deserialize");
@@ -4987,7 +5000,7 @@ FetchRequestAdapter.authenticateChallengedEventKey = "com.microsoft.kiota.authen
4987
5000
  * @returns A header value for the given key from the request
4988
5001
  */
4989
5002
  const getRequestHeader = (options, key) => {
4990
- if (options && options.headers) {
5003
+ if (options === null || options === void 0 ? void 0 : options.headers) {
4991
5004
  return options.headers[key];
4992
5005
  }
4993
5006
  return undefined;
@@ -5208,7 +5221,7 @@ class CompressionHandler {
5208
5221
  }
5209
5222
  const uint8ArrayToStream = (uint8Array) => {
5210
5223
  return new ReadableStream({
5211
- start(controller) {
5224
+ start: (controller) => {
5212
5225
  controller.enqueue(uint8Array);
5213
5226
  controller.close();
5214
5227
  },
@@ -5465,6 +5478,47 @@ class ParametersNameDecodingHandler {
5465
5478
  * -------------------------------------------------------------------------------------------
5466
5479
  */
5467
5480
  const RedirectHandlerOptionKey = "RedirectHandlerOption";
5481
+ /**
5482
+ * The default implementation for scrubbing sensitive headers during redirects.
5483
+ * This function removes Authorization, Cookie, and Proxy-Authorization headers when the host or scheme changes.
5484
+ *
5485
+ * It is exported so that consumers providing a custom {@link ScrubSensitiveHeaders} callback can call it to
5486
+ * retain the default behavior and then layer additional logic on top (e.g. removing custom headers such as
5487
+ * `X-Api-Key`), matching the composable pattern available in the .NET and Python Kiota SDKs.
5488
+ *
5489
+ * Note: In browser environments, `Proxy-Authorization` is a forbidden header name and typically cannot be set;
5490
+ * it is still removed here if present (e.g. in Node.js or other non-browser runtimes).
5491
+ * @param headers - The headers object to modify
5492
+ * @param originalUrl - The original request URL
5493
+ * @param newUrl - The new redirect URL
5494
+ */
5495
+ const defaultScrubSensitiveHeaders = (headers, originalUrl, newUrl) => {
5496
+ if (!headers || !originalUrl || !newUrl) {
5497
+ return;
5498
+ }
5499
+ try {
5500
+ const originalUri = new URL(originalUrl);
5501
+ const newUri = new URL(newUrl);
5502
+ // Remove Authorization, Cookie, and Proxy-Authorization headers if the request's scheme or host changes.
5503
+ // Header keys must be matched case-insensitively because FetchRequestAdapter.getRequestFromRequestInformation
5504
+ // lower-cases every header key before the headers object reaches this middleware, so PascalCase
5505
+ // property deletes such as `delete headers.Authorization` would otherwise be a no-op.
5506
+ const isDifferentHostOrScheme = originalUri.host.toLowerCase() !== newUri.host.toLowerCase() || originalUri.protocol.toLowerCase() !== newUri.protocol.toLowerCase();
5507
+ if (isDifferentHostOrScheme) {
5508
+ for (const key of Object.keys(headers)) {
5509
+ const lower = key.toLowerCase();
5510
+ if (lower === "authorization" || lower === "cookie" || lower === "proxy-authorization") {
5511
+ delete headers[key];
5512
+ }
5513
+ }
5514
+ }
5515
+ }
5516
+ catch (_a) {
5517
+ // If URL parsing fails, don't modify headers
5518
+ // This handles cases where invalid URLs are passed
5519
+ return;
5520
+ }
5521
+ };
5468
5522
  /**
5469
5523
  * MiddlewareOptions
5470
5524
  * A class representing RedirectHandlerOptions
@@ -5479,7 +5533,7 @@ class RedirectHandlerOptions {
5479
5533
  * @example const options = new RedirectHandlerOptions({ maxRedirects: 5 });
5480
5534
  */
5481
5535
  constructor(options = {}) {
5482
- var _a, _b;
5536
+ var _a, _b, _c;
5483
5537
  if (options.maxRedirects && options.maxRedirects > RedirectHandlerOptions.MAX_MAX_REDIRECTS) {
5484
5538
  const error = new Error(`MaxRedirects should not be more than ${RedirectHandlerOptions.MAX_MAX_REDIRECTS}`);
5485
5539
  error.name = "MaxLimitExceeded";
@@ -5492,6 +5546,7 @@ class RedirectHandlerOptions {
5492
5546
  }
5493
5547
  this.maxRedirects = (_a = options.maxRedirects) !== null && _a !== void 0 ? _a : RedirectHandlerOptions.DEFAULT_MAX_REDIRECTS;
5494
5548
  this.shouldRedirect = (_b = options.shouldRedirect) !== null && _b !== void 0 ? _b : RedirectHandlerOptions.defaultShouldRetry;
5549
+ this.scrubSensitiveHeaders = (_c = options.scrubSensitiveHeaders) !== null && _c !== void 0 ? _c : RedirectHandlerOptions.defaultScrubSensitiveHeaders;
5495
5550
  }
5496
5551
  getKey() {
5497
5552
  return RedirectHandlerOptionKey;
@@ -5511,6 +5566,11 @@ RedirectHandlerOptions.MAX_MAX_REDIRECTS = 20;
5511
5566
  * @returns true
5512
5567
  */
5513
5568
  RedirectHandlerOptions.defaultShouldRetry = () => true;
5569
+ /**
5570
+ * The default {@link ScrubSensitiveHeaders} callback used when none is supplied.
5571
+ * Delegates to the exported {@link defaultScrubSensitiveHeaders} function.
5572
+ */
5573
+ RedirectHandlerOptions.defaultScrubSensitiveHeaders = defaultScrubSensitiveHeaders;
5514
5574
 
5515
5575
  /**
5516
5576
  * -------------------------------------------------------------------------------------------
@@ -5577,27 +5637,6 @@ class RedirectHandler {
5577
5637
  isRelativeURL(url) {
5578
5638
  return !url.includes("://");
5579
5639
  }
5580
- /**
5581
- *
5582
- * To check whether the authorization header in the request should be dropped for consequent redirected requests
5583
- * @param requestUrl - The request url value
5584
- * @param redirectUrl - The redirect url value
5585
- * @returns A boolean representing whether the authorization header in the request should be dropped for consequent redirected requests
5586
- */
5587
- shouldDropAuthorizationHeader(requestUrl, redirectUrl) {
5588
- const schemeHostRegex = /^[A-Za-z].+?:\/\/.+?(?=\/|$)/;
5589
- const requestMatches = schemeHostRegex.exec(requestUrl);
5590
- let requestAuthority;
5591
- let redirectAuthority;
5592
- if (requestMatches !== null) {
5593
- requestAuthority = requestMatches[0];
5594
- }
5595
- const redirectMatches = schemeHostRegex.exec(redirectUrl);
5596
- if (redirectMatches !== null) {
5597
- redirectAuthority = redirectMatches[0];
5598
- }
5599
- return typeof requestAuthority !== "undefined" && typeof redirectAuthority !== "undefined" && requestAuthority !== redirectAuthority;
5600
- }
5601
5640
  /**
5602
5641
  * To execute the next middleware and to handle in case of redirect response returned by the server
5603
5642
  * @param url - The url string value
@@ -5616,19 +5655,22 @@ class RedirectHandler {
5616
5655
  }
5617
5656
  if (redirectCount < currentOptions.maxRedirects && this.isRedirect(response) && this.hasLocationHeader(response) && currentOptions.shouldRedirect(response)) {
5618
5657
  ++redirectCount;
5658
+ const redirectUrl = this.getLocationHeader(response);
5659
+ if (!redirectUrl) {
5660
+ return response;
5661
+ }
5662
+ // Resolve relative URLs
5663
+ const newUrl = this.isRelativeURL(redirectUrl) ? new URL(redirectUrl, url).toString() : redirectUrl;
5664
+ // Scrub sensitive headers before following the redirect
5665
+ if (fetchRequestInit.headers) {
5666
+ currentOptions.scrubSensitiveHeaders(fetchRequestInit.headers, url, newUrl);
5667
+ }
5668
+ // Handle 303 See Other: change POST to GET
5619
5669
  if (response.status === RedirectHandler.STATUS_CODE_SEE_OTHER) {
5620
5670
  fetchRequestInit.method = HttpMethod.GET;
5621
5671
  delete fetchRequestInit.body;
5622
5672
  }
5623
- else {
5624
- const redirectUrl = this.getLocationHeader(response);
5625
- if (redirectUrl) {
5626
- if (fetchRequestInit.headers && !this.isRelativeURL(redirectUrl) && this.shouldDropAuthorizationHeader(url, redirectUrl)) {
5627
- delete fetchRequestInit.headers[RedirectHandler.AUTHORIZATION_HEADER];
5628
- }
5629
- url = redirectUrl;
5630
- }
5631
- }
5673
+ url = newUrl;
5632
5674
  if (tracerName) {
5633
5675
  return trace.getTracer(tracerName).startActiveSpan(`redirectHandler - redirect ${redirectCount}`, (span) => {
5634
5676
  try {
@@ -5694,10 +5736,6 @@ RedirectHandler.STATUS_CODE_SEE_OTHER = 303;
5694
5736
  * A member holding the name of the location header
5695
5737
  */
5696
5738
  RedirectHandler.LOCATION_HEADER = "Location";
5697
- /**
5698
- * A member representing the authorization header name
5699
- */
5700
- RedirectHandler.AUTHORIZATION_HEADER = "Authorization";
5701
5739
  /**
5702
5740
  * A member holding the manual redirect value
5703
5741
  */
@@ -6194,7 +6232,6 @@ class MiddlewareFactory {
6194
6232
  * Returns the default middleware chain an array with the middleware handlers
6195
6233
  * @returns an array of the middleware handlers of the default middleware chain
6196
6234
  */
6197
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
6198
6235
  static getDefaultMiddlewares(customFetch = (...args) => fetch(...args)) {
6199
6236
  return [new RetryHandler(), new RedirectHandler(), new ParametersNameDecodingHandler(), new UserAgentHandler(), new HeadersInspectionHandler(), new UrlReplaceHandler(), new CustomFetchHandler(customFetch)];
6200
6237
  }
@@ -6203,7 +6240,6 @@ class MiddlewareFactory {
6203
6240
  * Returns the default middleware chain + performance middleware
6204
6241
  * @returns an array of the middleware handlers of the default + performance middleware chain
6205
6242
  */
6206
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
6207
6243
  static getPerformanceMiddlewares(customFetch = (...args) => fetch(...args)) {
6208
6244
  const middlewares = MiddlewareFactory.getDefaultMiddlewares(customFetch);
6209
6245
  middlewares.splice(middlewares.length - 3, 0, new CompressionHandler()); // insert CompressionHandler before HeadersInspectionHandler
@@ -6584,6 +6620,24 @@ function createGenerateCheckoutLinkSchema_dataFromDiscriminatorValue(parseNode)
6584
6620
  function createGenerateCheckoutLinkSchemaFromDiscriminatorValue(parseNode) {
6585
6621
  return deserializeIntoGenerateCheckoutLinkSchema;
6586
6622
  }
6623
+ /**
6624
+ * Creates a new instance of the appropriate class based on discriminator value
6625
+ * @param parseNode The parse node to use to read the discriminator value and create the object
6626
+ * @returns {GenerateOnboardingLinkResponseSchema_data}
6627
+ */
6628
+ // @ts-ignore
6629
+ function createGenerateOnboardingLinkResponseSchema_dataFromDiscriminatorValue(parseNode) {
6630
+ return deserializeIntoGenerateOnboardingLinkResponseSchema_data;
6631
+ }
6632
+ /**
6633
+ * Creates a new instance of the appropriate class based on discriminator value
6634
+ * @param parseNode The parse node to use to read the discriminator value and create the object
6635
+ * @returns {GenerateOnboardingLinkResponseSchema}
6636
+ */
6637
+ // @ts-ignore
6638
+ function createGenerateOnboardingLinkResponseSchemaFromDiscriminatorValue(parseNode) {
6639
+ return deserializeIntoGenerateOnboardingLinkResponseSchema;
6640
+ }
6587
6641
  /**
6588
6642
  * Creates a new instance of the appropriate class based on discriminator value
6589
6643
  * @param parseNode The parse node to use to read the discriminator value and create the object
@@ -9693,6 +9747,32 @@ function deserializeIntoGenerateCheckoutLinkSchema_data(generateCheckoutLinkSche
9693
9747
  "url": n => { generateCheckoutLinkSchema_data.url = n.getStringValue(); },
9694
9748
  };
9695
9749
  }
9750
+ /**
9751
+ * The deserialization information for the current model
9752
+ * @param GenerateOnboardingLinkResponseSchema The instance to deserialize into.
9753
+ * @returns {Record<string, (node: ParseNode) => void>}
9754
+ */
9755
+ // @ts-ignore
9756
+ function deserializeIntoGenerateOnboardingLinkResponseSchema(generateOnboardingLinkResponseSchema = {}) {
9757
+ return {
9758
+ "data": n => { generateOnboardingLinkResponseSchema.data = n.getObjectValue(createGenerateOnboardingLinkResponseSchema_dataFromDiscriminatorValue); },
9759
+ "type": n => { generateOnboardingLinkResponseSchema.type = n.getStringValue(); },
9760
+ };
9761
+ }
9762
+ /**
9763
+ * The deserialization information for the current model
9764
+ * @param GenerateOnboardingLinkResponseSchema_data The instance to deserialize into.
9765
+ * @returns {Record<string, (node: ParseNode) => void>}
9766
+ */
9767
+ // @ts-ignore
9768
+ function deserializeIntoGenerateOnboardingLinkResponseSchema_data(generateOnboardingLinkResponseSchema_data = {}) {
9769
+ return {
9770
+ "completionUrl": n => { generateOnboardingLinkResponseSchema_data.completionUrl = n.getStringValue(); },
9771
+ "refreshUrl": n => { generateOnboardingLinkResponseSchema_data.refreshUrl = n.getStringValue(); },
9772
+ "returnUrl": n => { generateOnboardingLinkResponseSchema_data.returnUrl = n.getStringValue(); },
9773
+ "url": n => { generateOnboardingLinkResponseSchema_data.url = n.getStringValue(); },
9774
+ };
9775
+ }
9696
9776
  /**
9697
9777
  * The deserialization information for the current model
9698
9778
  * @param GetAIConversationDetailSchema The instance to deserialize into.
@@ -12274,7 +12354,7 @@ function deserializeIntoGetPlanListSchema_data_tierTag(getPlanListSchema_data_ti
12274
12354
  // @ts-ignore
12275
12355
  function deserializeIntoGetPlanListSchema_filterOptions(getPlanListSchema_filterOptions = {}) {
12276
12356
  return {
12277
- "currencies": n => { getPlanListSchema_filterOptions.currencies = n.getCollectionOfPrimitiveValues(); },
12357
+ "currencies": n => { getPlanListSchema_filterOptions.currencies = n.getCollectionOfPrimitiveValues("string"); },
12278
12358
  "intervals": n => { getPlanListSchema_filterOptions.intervals = n.getCollectionOfObjectValues(createGetPlanListSchema_filterOptions_intervalsFromDiscriminatorValue); },
12279
12359
  };
12280
12360
  }
@@ -13123,7 +13203,7 @@ function deserializeIntoGetSubscriptionInvoicesSchema_data_lines_data_parent_sub
13123
13203
  function deserializeIntoGetSubscriptionInvoicesSchema_data_lines_data_parent_subscription_item_details_proration_details_credited_items(getSubscriptionInvoicesSchema_data_lines_data_parent_subscription_item_details_proration_details_credited_items = {}) {
13124
13204
  return {
13125
13205
  "invoice": n => { getSubscriptionInvoicesSchema_data_lines_data_parent_subscription_item_details_proration_details_credited_items.invoice = n.getStringValue(); },
13126
- "invoice_line_items": n => { getSubscriptionInvoicesSchema_data_lines_data_parent_subscription_item_details_proration_details_credited_items.invoiceLineItems = n.getCollectionOfPrimitiveValues(); },
13206
+ "invoice_line_items": n => { getSubscriptionInvoicesSchema_data_lines_data_parent_subscription_item_details_proration_details_credited_items.invoiceLineItems = n.getCollectionOfPrimitiveValues("string"); },
13127
13207
  };
13128
13208
  }
13129
13209
  /**
@@ -13276,7 +13356,7 @@ function deserializeIntoGetSubscriptionInvoicesSchema_data_lines_data_proration_
13276
13356
  function deserializeIntoGetSubscriptionInvoicesSchema_data_lines_data_proration_details_credited_items(getSubscriptionInvoicesSchema_data_lines_data_proration_details_credited_items = {}) {
13277
13357
  return {
13278
13358
  "invoice": n => { getSubscriptionInvoicesSchema_data_lines_data_proration_details_credited_items.invoice = n.getStringValue(); },
13279
- "invoice_line_items": n => { getSubscriptionInvoicesSchema_data_lines_data_proration_details_credited_items.invoiceLineItems = n.getCollectionOfPrimitiveValues(); },
13359
+ "invoice_line_items": n => { getSubscriptionInvoicesSchema_data_lines_data_proration_details_credited_items.invoiceLineItems = n.getCollectionOfPrimitiveValues("string"); },
13280
13360
  };
13281
13361
  }
13282
13362
  /**
@@ -17166,8 +17246,8 @@ const OnboardingRequestBuilderRequestsMetadata = {
17166
17246
  429: createErrorResponseBodyFromDiscriminatorValue,
17167
17247
  500: createErrorResponseBodyFromDiscriminatorValue,
17168
17248
  },
17169
- adapterMethodName: "sendPrimitive",
17170
- responseBodyFactory: "ArrayBuffer",
17249
+ adapterMethodName: "send",
17250
+ responseBodyFactory: createGenerateOnboardingLinkResponseSchemaFromDiscriminatorValue,
17171
17251
  },
17172
17252
  };
17173
17253
  /* tslint:enable */
@@ -19959,58 +20039,40 @@ class FormParseNode {
19959
20039
  this._rawString = _rawString;
19960
20040
  this.backingStoreFactory = backingStoreFactory;
19961
20041
  this._fields = {};
19962
- this.normalizeKey = (key) => decodeURIComponent(key).trim();
19963
- this.getStringValue = () => decodeURIComponent(this._rawString);
20042
+ this.getStringValue = () => this.getStringValueFromRaw(this._rawString);
19964
20043
  this.getChildNode = (identifier) => {
19965
20044
  if (this._fields[identifier]) {
19966
20045
  return new FormParseNode(this._fields[identifier], this.backingStoreFactory);
19967
20046
  }
19968
20047
  return undefined;
19969
20048
  };
19970
- this.getBooleanValue = () => {
19971
- var _a;
19972
- const value = (_a = this.getStringValue()) === null || _a === void 0 ? void 0 : _a.toLowerCase();
19973
- if (value === "true" || value === "1") {
19974
- return true;
19975
- }
19976
- else if (value === "false" || value === "0") {
19977
- return false;
19978
- }
19979
- return undefined;
19980
- };
19981
- this.getNumberValue = () => parseFloat(this.getStringValue());
19982
- this.getGuidValue = () => parseGuidString(this.getStringValue());
19983
- this.getDateValue = () => new Date(Date.parse(this.getStringValue()));
19984
- this.getDateOnlyValue = () => DateOnly.parse(this.getStringValue());
19985
- this.getTimeOnlyValue = () => TimeOnly.parse(this.getStringValue());
19986
- this.getDurationValue = () => Duration.parse(this.getStringValue());
19987
- this.getCollectionOfPrimitiveValues = () => {
19988
- return this._rawString.split(",").map((x) => {
19989
- const currentParseNode = new FormParseNode(x, this.backingStoreFactory);
19990
- const typeOfX = typeof x;
19991
- if (typeOfX === "boolean") {
19992
- return currentParseNode.getBooleanValue();
19993
- }
19994
- else if (typeOfX === "string") {
19995
- return currentParseNode.getStringValue();
19996
- }
19997
- else if (typeOfX === "number") {
19998
- return currentParseNode.getNumberValue();
19999
- }
20000
- else if (x instanceof Date) {
20001
- return currentParseNode.getDateValue();
20002
- }
20003
- else if (x instanceof DateOnly) {
20004
- return currentParseNode.getDateValue();
20005
- }
20006
- else if (x instanceof TimeOnly) {
20007
- return currentParseNode.getDateValue();
20008
- }
20009
- else if (x instanceof Duration) {
20010
- return currentParseNode.getDateValue();
20011
- }
20012
- else {
20013
- throw new Error(`encountered an unknown type during deserialization ${typeof x}`);
20049
+ this.getBooleanValue = () => this.getBooleanValueFromRaw(this._rawString);
20050
+ this.getNumberValue = () => this.getNumberValueFromRaw(this._rawString);
20051
+ this.getGuidValue = () => this.getGuidValueFromRaw(this._rawString);
20052
+ this.getDateValue = () => this.getDateValueFromRaw(this._rawString);
20053
+ this.getDateOnlyValue = () => this.getDateOnlyValueFromRaw(this._rawString);
20054
+ this.getTimeOnlyValue = () => this.getTimeOnlyValueFromRaw(this._rawString);
20055
+ this.getDurationValue = () => this.getDurationValueFromRaw(this._rawString);
20056
+ this.getCollectionOfPrimitiveValues = (primitiveType) => {
20057
+ const values = this._rawString.split(",");
20058
+ return values.map((x) => {
20059
+ switch (primitiveType) {
20060
+ case "boolean":
20061
+ return this.getBooleanValueFromRaw(x);
20062
+ case "number":
20063
+ return this.getNumberValueFromRaw(x);
20064
+ case "Date":
20065
+ return this.getDateValueFromRaw(x);
20066
+ case "DateOnly":
20067
+ return this.getDateOnlyValueFromRaw(x);
20068
+ case "TimeOnly":
20069
+ return this.getTimeOnlyValueFromRaw(x);
20070
+ case "Duration":
20071
+ return this.getDurationValueFromRaw(x);
20072
+ case "string":
20073
+ return this.getStringValueFromRaw(x);
20074
+ default:
20075
+ throw new Error(`encountered an unsupported type during deserialization ${primitiveType}`);
20014
20076
  }
20015
20077
  });
20016
20078
  };
@@ -20037,7 +20099,6 @@ class FormParseNode {
20037
20099
  if (!rawValues) {
20038
20100
  return [];
20039
20101
  }
20040
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
20041
20102
  return rawValues.split(",").map((x) => getEnumValueFromStringValue(x, type));
20042
20103
  };
20043
20104
  this.getEnumValue = (type) => {
@@ -20047,20 +20108,6 @@ class FormParseNode {
20047
20108
  }
20048
20109
  return getEnumValueFromStringValue(rawValue, type);
20049
20110
  };
20050
- this.assignFieldValues = (model, parsableFactory) => {
20051
- const fields = parsableFactory(this)(model);
20052
- Object.entries(this._fields)
20053
- .filter((x) => !/^null$/i.test(x[1]))
20054
- .forEach(([k, v]) => {
20055
- const deserializer = fields[k];
20056
- if (deserializer) {
20057
- deserializer(new FormParseNode(v, this.backingStoreFactory));
20058
- }
20059
- else {
20060
- model[k] = v;
20061
- }
20062
- });
20063
- };
20064
20111
  if (!_rawString) {
20065
20112
  throw new Error("rawString cannot be undefined");
20066
20113
  }
@@ -20078,9 +20125,57 @@ class FormParseNode {
20078
20125
  }
20079
20126
  });
20080
20127
  }
20128
+ normalizeKey(key) {
20129
+ return decodeURIComponent(key).trim();
20130
+ }
20131
+ getStringValueFromRaw(value) {
20132
+ return decodeURIComponent(value);
20133
+ }
20134
+ getBooleanValueFromRaw(value) {
20135
+ const decoded = this.getStringValueFromRaw(value).toLowerCase();
20136
+ if (decoded === "true" || decoded === "1") {
20137
+ return true;
20138
+ }
20139
+ else if (decoded === "false" || decoded === "0") {
20140
+ return false;
20141
+ }
20142
+ return undefined;
20143
+ }
20144
+ getNumberValueFromRaw(value) {
20145
+ return parseFloat(this.getStringValueFromRaw(value));
20146
+ }
20147
+ getGuidValueFromRaw(value) {
20148
+ return parseGuidString(this.getStringValueFromRaw(value));
20149
+ }
20150
+ getDateValueFromRaw(value) {
20151
+ return new Date(Date.parse(this.getStringValueFromRaw(value)));
20152
+ }
20153
+ getDateOnlyValueFromRaw(value) {
20154
+ return DateOnly.parse(this.getStringValueFromRaw(value));
20155
+ }
20156
+ getTimeOnlyValueFromRaw(value) {
20157
+ return TimeOnly.parse(this.getStringValueFromRaw(value));
20158
+ }
20159
+ getDurationValueFromRaw(value) {
20160
+ return Duration.parse(this.getStringValueFromRaw(value));
20161
+ }
20081
20162
  getByteArrayValue() {
20082
20163
  throw new Error("serialization of byt arrays is not supported with URI encoding");
20083
20164
  }
20165
+ assignFieldValues(model, parsableFactory) {
20166
+ const fields = parsableFactory(this)(model);
20167
+ Object.entries(this._fields)
20168
+ .filter((x) => !/^null$/i.test(x[1]))
20169
+ .forEach(([k, v]) => {
20170
+ const deserializer = fields[k];
20171
+ if (deserializer) {
20172
+ deserializer(new FormParseNode(v, this.backingStoreFactory));
20173
+ }
20174
+ else {
20175
+ model[k] = v;
20176
+ }
20177
+ });
20178
+ }
20084
20179
  }
20085
20180
 
20086
20181
  /**
@@ -20163,6 +20258,7 @@ class FormSerializationWriter {
20163
20258
  throw new Error(`serialization of collections is not supported with URI encoding`);
20164
20259
  };
20165
20260
  this.writeObjectValue = (key, value, serializerMethod) => {
20261
+ var _a, _b, _c;
20166
20262
  if (++this.depth > 0) {
20167
20263
  throw new Error(`serialization of nested objects is not supported with URI encoding`);
20168
20264
  }
@@ -20173,10 +20269,10 @@ class FormSerializationWriter {
20173
20269
  if (key) {
20174
20270
  this.writePropertyName(key);
20175
20271
  }
20176
- this.onBeforeObjectSerialization && this.onBeforeObjectSerialization(value);
20177
- this.onStartObjectSerialization && this.onStartObjectSerialization(value, this);
20272
+ (_a = this.onBeforeObjectSerialization) === null || _a === void 0 ? void 0 : _a.call(this, value);
20273
+ (_b = this.onStartObjectSerialization) === null || _b === void 0 ? void 0 : _b.call(this, value, this);
20178
20274
  serializerMethod(this, value);
20179
- this.onAfterObjectSerialization && this.onAfterObjectSerialization(value);
20275
+ (_c = this.onAfterObjectSerialization) === null || _c === void 0 ? void 0 : _c.call(this, value);
20180
20276
  if (this.writer.length > 0 && this.writer[this.writer.length - 1] === FormSerializationWriter.propertySeparator) {
20181
20277
  // removing the last separator
20182
20278
  this.writer.pop();
@@ -20335,47 +20431,52 @@ class JsonParseNode {
20335
20431
  constructor(_jsonNode, backingStoreFactory) {
20336
20432
  this._jsonNode = _jsonNode;
20337
20433
  this.backingStoreFactory = backingStoreFactory;
20338
- this.getStringValue = () => (typeof this._jsonNode === "string" ? this._jsonNode : undefined);
20434
+ this.getStringValue = () => this.getStringValueFromRaw(this._jsonNode);
20339
20435
  this.getChildNode = (identifier) => (this._jsonNode && typeof this._jsonNode === "object" && this._jsonNode[identifier] !== undefined ? new JsonParseNode(this._jsonNode[identifier], this.backingStoreFactory) : undefined);
20340
20436
  this.getBooleanValue = () => (typeof this._jsonNode === "boolean" ? this._jsonNode : undefined);
20341
20437
  this.getNumberValue = () => (typeof this._jsonNode === "number" ? this._jsonNode : undefined);
20342
- this.getGuidValue = () => parseGuidString(this.getStringValue());
20343
- this.getDateValue = () => (this._jsonNode ? new Date(this._jsonNode) : undefined);
20344
- this.getDateOnlyValue = () => DateOnly.parse(this.getStringValue());
20345
- this.getTimeOnlyValue = () => TimeOnly.parse(this.getStringValue());
20346
- this.getDurationValue = () => Duration.parse(this.getStringValue());
20347
- this.getCollectionOfPrimitiveValues = () => {
20438
+ this.getGuidValue = () => this.getGuidValueFromRaw(this._jsonNode);
20439
+ this.getDateValue = () => this.getDateValueFromRaw(this._jsonNode);
20440
+ this.getDateOnlyValue = () => this.getDateOnlyValueFromRaw(this._jsonNode);
20441
+ this.getTimeOnlyValue = () => this.getTimeOnlyValueFromRaw(this._jsonNode);
20442
+ this.getDurationValue = () => this.getDurationValueFromRaw(this._jsonNode);
20443
+ this.getCollectionOfPrimitiveValues = (primitiveType) => {
20348
20444
  if (!Array.isArray(this._jsonNode)) {
20349
20445
  return undefined;
20350
20446
  }
20351
- return this._jsonNode.map((x) => {
20352
- const currentParseNode = new JsonParseNode(x, this.backingStoreFactory);
20353
- const typeOfX = typeof x;
20354
- if (typeOfX === "boolean") {
20355
- return currentParseNode.getBooleanValue();
20356
- }
20357
- else if (typeOfX === "string") {
20358
- return currentParseNode.getStringValue();
20359
- }
20360
- else if (typeOfX === "number") {
20361
- return currentParseNode.getNumberValue();
20362
- }
20363
- else if (x instanceof Date) {
20364
- return currentParseNode.getDateValue();
20365
- }
20366
- else if (x instanceof DateOnly) {
20367
- return currentParseNode.getDateValue();
20368
- }
20369
- else if (x instanceof TimeOnly) {
20370
- return currentParseNode.getDateValue();
20371
- }
20372
- else if (x instanceof Duration) {
20373
- return currentParseNode.getDateValue();
20374
- }
20375
- else {
20376
- throw new Error(`encountered an unknown type during deserialization ${typeof x}`);
20377
- }
20378
- });
20447
+ return this._jsonNode.map((x) => this.getPrimitiveValue(x, primitiveType));
20448
+ };
20449
+ this.getPrimitiveValue = (value, primitiveType) => {
20450
+ if (value === null) {
20451
+ return null;
20452
+ }
20453
+ switch (primitiveType) {
20454
+ case "boolean":
20455
+ if (typeof value !== "boolean") {
20456
+ throw new Error(`encountered an unsupported type during deserialization ${typeof value}`);
20457
+ }
20458
+ return value;
20459
+ case "number":
20460
+ if (typeof value !== "number") {
20461
+ throw new Error(`encountered an unsupported type during deserialization ${typeof value}`);
20462
+ }
20463
+ return value;
20464
+ case "Date":
20465
+ return this.getDateValueFromRaw(value);
20466
+ case "DateOnly":
20467
+ return this.getDateOnlyValueFromRaw(value);
20468
+ case "TimeOnly":
20469
+ return this.getTimeOnlyValueFromRaw(value);
20470
+ case "Duration":
20471
+ return this.getDurationValueFromRaw(value);
20472
+ case "string":
20473
+ if (typeof value !== "string") {
20474
+ throw new Error(`encountered an unsupported type during deserialization ${typeof value}`);
20475
+ }
20476
+ return value;
20477
+ default:
20478
+ throw new Error(`encountered an unsupported type during deserialization ${primitiveType}`);
20479
+ }
20379
20480
  };
20380
20481
  this.getCollectionOfObjectValues = (method) => {
20381
20482
  if (!Array.isArray(this._jsonNode)) {
@@ -20450,10 +20551,12 @@ class JsonParseNode {
20450
20551
  if (Array.isArray(this._jsonNode)) {
20451
20552
  return this._jsonNode
20452
20553
  .map((x) => {
20453
- const node = new JsonParseNode(x, this.backingStoreFactory);
20454
- return node.getEnumValue(type);
20554
+ if (typeof x === "string") {
20555
+ return getEnumValueFromStringValue(x, type);
20556
+ }
20557
+ return undefined;
20455
20558
  })
20456
- .filter(Boolean);
20559
+ .filter((value) => value !== undefined);
20457
20560
  }
20458
20561
  return [];
20459
20562
  };
@@ -20465,6 +20568,33 @@ class JsonParseNode {
20465
20568
  return getEnumValueFromStringValue(rawValue, type);
20466
20569
  };
20467
20570
  }
20571
+ getStringValueFromRaw(value) {
20572
+ return typeof value === "string" ? value : undefined;
20573
+ }
20574
+ getGuidValueFromRaw(value) {
20575
+ return parseGuidString(this.getStringValueFromRaw(value));
20576
+ }
20577
+ getDateValueFromRaw(value) {
20578
+ if (value instanceof Date) {
20579
+ return new Date(value.getTime());
20580
+ }
20581
+ if (typeof value === "number") {
20582
+ return new Date(value);
20583
+ }
20584
+ if (typeof value === "string") {
20585
+ return new Date(value);
20586
+ }
20587
+ return undefined;
20588
+ }
20589
+ getDateOnlyValueFromRaw(value) {
20590
+ return value instanceof DateOnly ? value : DateOnly.parse(this.getStringValueFromRaw(value));
20591
+ }
20592
+ getTimeOnlyValueFromRaw(value) {
20593
+ return value instanceof TimeOnly ? value : TimeOnly.parse(this.getStringValueFromRaw(value));
20594
+ }
20595
+ getDurationValueFromRaw(value) {
20596
+ return value instanceof Duration ? value : Duration.parse(this.getStringValueFromRaw(value));
20597
+ }
20468
20598
  getByteArrayValue() {
20469
20599
  const strValue = this.getStringValue();
20470
20600
  if (strValue && strValue.length > 0) {
@@ -20480,7 +20610,7 @@ class JsonParseNode {
20480
20610
  * TODO: Consider standardizing on a cross-platform UInt8Array.fromBase64 (after the API is stabilized across browsers)
20481
20611
  * in the future instead of the current environment-specific approach
20482
20612
  */
20483
- return inNodeEnv() ? new Uint8Array(Buffer.from(strValue, "base64")).buffer : new TextEncoder().encode(strValue);
20613
+ return inNodeEnv() ? new Uint8Array(Buffer.from(strValue, "base64")).buffer : new TextEncoder().encode(strValue).buffer;
20484
20614
  }
20485
20615
  return undefined;
20486
20616
  }
@@ -20542,7 +20672,6 @@ class JsonSerializationWriter {
20542
20672
  }
20543
20673
  if (this.shouldWriteValueOrNull(key, value)) {
20544
20674
  key && this.writePropertyName(key);
20545
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
20546
20675
  this.writer.push(`"${value}"`);
20547
20676
  key && this.writer.push(JsonSerializationWriter.propertySeparator);
20548
20677
  }
@@ -20647,10 +20776,9 @@ class JsonSerializationWriter {
20647
20776
  }
20648
20777
  };
20649
20778
  this.writeNonParsableObjectValue = (key, value) => {
20650
- if (key) {
20651
- this.writePropertyName(key);
20652
- }
20653
- this.writer.push(JSON.stringify(value), JsonSerializationWriter.propertySeparator);
20779
+ key && this.writePropertyName(key);
20780
+ this.writer.push(JSON.stringify(value));
20781
+ key && this.writer.push(JsonSerializationWriter.propertySeparator);
20654
20782
  };
20655
20783
  // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
20656
20784
  this.writeAnyValue = (key, value) => {
@@ -20701,6 +20829,7 @@ class JsonSerializationWriter {
20701
20829
  this.writeStringValue(key, b64);
20702
20830
  }
20703
20831
  writeObjectValue(key, value, serializerMethod) {
20832
+ var _a, _b, _c;
20704
20833
  if (value === undefined) {
20705
20834
  return;
20706
20835
  }
@@ -20759,11 +20888,11 @@ class JsonSerializationWriter {
20759
20888
  }
20760
20889
  if (key)
20761
20890
  this.writePropertyName(key);
20762
- this.onBeforeObjectSerialization && this.onBeforeObjectSerialization(value);
20891
+ (_a = this.onBeforeObjectSerialization) === null || _a === void 0 ? void 0 : _a.call(this, value);
20763
20892
  this.startObject();
20764
- this.onStartObjectSerialization && this.onStartObjectSerialization(value, this);
20765
- serializerMethod && serializerMethod(this, value);
20766
- this.onAfterObjectSerialization && this.onAfterObjectSerialization(value);
20893
+ (_b = this.onStartObjectSerialization) === null || _b === void 0 ? void 0 : _b.call(this, value, this);
20894
+ serializerMethod === null || serializerMethod === void 0 ? void 0 : serializerMethod(this, value);
20895
+ (_c = this.onAfterObjectSerialization) === null || _c === void 0 ? void 0 : _c.call(this, value);
20767
20896
  this.removeLastSeparator();
20768
20897
  this.endObject();
20769
20898
  if (key)
@@ -20836,7 +20965,6 @@ class JsonSerializationWriterFactory {
20836
20965
  * See License in the project root for license information.
20837
20966
  * -------------------------------------------------------------------------------------------
20838
20967
  */
20839
- /* eslint-disable @typescript-eslint/no-unused-expressions */
20840
20968
  /** Serialization writer for multipart/form-data */
20841
20969
  class MultipartSerializationWriter {
20842
20970
  constructor() {
@@ -20896,6 +21024,7 @@ class MultipartSerializationWriter {
20896
21024
  throw new Error(`serialization of collections is not supported with multipart`);
20897
21025
  };
20898
21026
  this.writeObjectValue = (key, value, serializerMethod) => {
21027
+ var _a, _b, _c;
20899
21028
  if (!value) {
20900
21029
  throw new Error(`value cannot be undefined`);
20901
21030
  }
@@ -20905,10 +21034,10 @@ class MultipartSerializationWriter {
20905
21034
  if (!serializerMethod) {
20906
21035
  throw new Error(`serializer method cannot be undefined`);
20907
21036
  }
20908
- this.onBeforeObjectSerialization && this.onBeforeObjectSerialization(value);
20909
- this.onStartObjectSerialization && this.onStartObjectSerialization(value, this);
21037
+ (_a = this.onBeforeObjectSerialization) === null || _a === void 0 ? void 0 : _a.call(this, value);
21038
+ (_b = this.onStartObjectSerialization) === null || _b === void 0 ? void 0 : _b.call(this, value, this);
20910
21039
  serializerMethod(this, value);
20911
- this.onAfterObjectSerialization && this.onAfterObjectSerialization(value);
21040
+ (_c = this.onAfterObjectSerialization) === null || _c === void 0 ? void 0 : _c.call(this, value);
20912
21041
  };
20913
21042
  this.writeEnumValue = (
20914
21043
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -21000,8 +21129,28 @@ class TextParseNode {
21000
21129
  this.getDateOnlyValue = () => DateOnly.parse(this.getStringValue());
21001
21130
  this.getTimeOnlyValue = () => TimeOnly.parse(this.getStringValue());
21002
21131
  this.getDurationValue = () => Duration.parse(this.getStringValue());
21003
- this.getCollectionOfPrimitiveValues = () => {
21004
- throw new Error(TextParseNode.noStructuredDataMessage);
21132
+ this.getCollectionOfPrimitiveValues = (primitiveType) => {
21133
+ return this.text.split(",").map((x) => {
21134
+ const node = new TextParseNode(x);
21135
+ switch (primitiveType) {
21136
+ case "boolean":
21137
+ return node.getBooleanValue();
21138
+ case "number":
21139
+ return node.getNumberValue();
21140
+ case "Date":
21141
+ return node.getDateValue();
21142
+ case "DateOnly":
21143
+ return node.getDateOnlyValue();
21144
+ case "TimeOnly":
21145
+ return node.getTimeOnlyValue();
21146
+ case "Duration":
21147
+ return node.getDurationValue();
21148
+ case "string":
21149
+ return node.getStringValue();
21150
+ default:
21151
+ throw new Error(`encountered an unsupported type during deserialization ${primitiveType}`);
21152
+ }
21153
+ });
21005
21154
  };
21006
21155
  this.getCollectionOfEnumValues = (type) => {
21007
21156
  throw new Error(TextParseNode.noStructuredDataMessage);
@@ -21032,7 +21181,7 @@ class TextParseNode {
21032
21181
  * TODO: Consider standardizing on a cross-platform UInt8Array.fromBase64 (after the API is stabilized across browsers)
21033
21182
  * in the future instead of the current environment-specific approach
21034
21183
  */
21035
- return inNodeEnv() ? new Uint8Array(Buffer.from(strValue, "base64")).buffer : new TextEncoder().encode(strValue);
21184
+ return inNodeEnv() ? new Uint8Array(Buffer.from(strValue, "base64")).buffer : new TextEncoder().encode(strValue).buffer;
21036
21185
  }
21037
21186
  return undefined;
21038
21187
  }
@@ -21089,7 +21238,6 @@ class TextSerializationWriter {
21089
21238
  return this.writeNullValue(key);
21090
21239
  }
21091
21240
  if (value) {
21092
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
21093
21241
  this.writeStringValue(key, `"${value}"`);
21094
21242
  }
21095
21243
  };
@@ -21273,12 +21421,69 @@ const SalableNavigationMetadata = {
21273
21421
  /* tslint:enable */
21274
21422
  /* eslint-enable */
21275
21423
 
21424
+ /**
21425
+ * Kiota's JsonSerializationWriter stringifies null enum values, producing
21426
+ * `"interval": "null"` instead of `"interval": null`, which the API rejects
21427
+ * with an invalid_enum_value error. Unlike every other write method, its
21428
+ * writeEnumValue/writeCollectionOfEnumValues only filter out undefined before
21429
+ * template-stringifying, so null slips through as the string "null".
21430
+ * See https://github.com/microsoft/kiota-typescript — present up to at least
21431
+ * 1.0.0-preview.107. This subclass emits a proper JSON null instead.
21432
+ */
21433
+ class NullSafeJsonSerializationWriter extends JsonSerializationWriter {
21434
+ writeEnumValue = (key, ...values) => {
21435
+ const provided = values.filter((x) => x !== undefined);
21436
+ if (provided.length === 0) {
21437
+ return;
21438
+ }
21439
+ const rawValues = provided.filter((x) => x !== null).map((x) => `${x}`);
21440
+ if (rawValues.length === 0) {
21441
+ this.writeNullValue(key);
21442
+ return;
21443
+ }
21444
+ this.writeStringValue(key, rawValues.join(', '));
21445
+ };
21446
+ writeCollectionOfEnumValues = (key, values) => {
21447
+ if (values === null) {
21448
+ this.writeNullValue(key);
21449
+ return;
21450
+ }
21451
+ if (!values || values.length === 0) {
21452
+ return;
21453
+ }
21454
+ const rawValues = values
21455
+ .filter((x) => x !== undefined)
21456
+ .map((x) => (x === null ? null : `${x}`));
21457
+ if (rawValues.length === 0) {
21458
+ return;
21459
+ }
21460
+ this.writeCollectionOfPrimitiveValues(key, rawValues);
21461
+ };
21462
+ }
21463
+ class NullSafeJsonSerializationWriterFactory extends JsonSerializationWriterFactory {
21464
+ getSerializationWriter(contentType) {
21465
+ if (!contentType) {
21466
+ throw new Error('content type cannot be undefined or empty');
21467
+ }
21468
+ if (this.getValidContentType() !== contentType) {
21469
+ throw new Error(`expected a ${this.getValidContentType()} content type`);
21470
+ }
21471
+ return new NullSafeJsonSerializationWriter();
21472
+ }
21473
+ }
21474
+
21276
21475
  class Salable {
21277
21476
  api;
21278
21477
  constructor(apiKey) {
21279
21478
  const authProvider = new ApiKeyAuthenticationProvider('Bearer ' + apiKey, 'Authorization', ApiKeyLocation.Header);
21280
21479
  const adapter = new FetchRequestAdapter(authProvider);
21281
21480
  this.api = createSalable(adapter).api;
21481
+ // Must run after createSalable, which registers the stock JSON serializer;
21482
+ // re-registering replaces the application/json factory with the null-safe one.
21483
+ const writerRegistry = adapter.getSerializationWriterFactory();
21484
+ if (writerRegistry.registerDefaultSerializer) {
21485
+ writerRegistry.registerDefaultSerializer(NullSafeJsonSerializationWriterFactory);
21486
+ }
21282
21487
  }
21283
21488
  }
21284
21489