@granular-software/sdk 0.4.73 → 0.4.74

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.
@@ -16430,13 +16430,15 @@ var Environment = class _Environment {
16430
16430
  _apiEndpoint;
16431
16431
  _tokenProvider;
16432
16432
  _beforeMutationSend;
16433
- constructor(granular, envData, apiKey, apiEndpoint, tokenProvider, beforeMutationSend) {
16433
+ _graphqlIdempotencyKey;
16434
+ constructor(granular, envData, apiKey, apiEndpoint, tokenProvider, beforeMutationSend, graphqlIdempotencyKey) {
16434
16435
  this.granular = granular;
16435
16436
  this.envData = envData;
16436
16437
  this._apiKey = apiKey;
16437
16438
  this._apiEndpoint = apiEndpoint;
16438
16439
  this._tokenProvider = tokenProvider;
16439
16440
  this._beforeMutationSend = beforeMutationSend;
16441
+ this._graphqlIdempotencyKey = graphqlIdempotencyKey;
16440
16442
  }
16441
16443
  /** The environment ID */
16442
16444
  get environmentId() {
@@ -16979,11 +16981,13 @@ var Environment = class _Environment {
16979
16981
  if (this._beforeMutationSend && isGraphQLMutationDocument(query)) {
16980
16982
  this._beforeMutationSend?.();
16981
16983
  }
16984
+ const idempotencyKey = this._graphqlIdempotencyKey?.(query, variables);
16982
16985
  const response = await fetch(this._apiEndpoint, {
16983
16986
  method: "POST",
16984
16987
  headers: {
16985
16988
  "Content-Type": "application/json",
16986
- Authorization: `Bearer ${authToken}`
16989
+ Authorization: `Bearer ${authToken}`,
16990
+ ...idempotencyKey ? { "Idempotency-Key": idempotencyKey } : {}
16987
16991
  },
16988
16992
  body: JSON.stringify({
16989
16993
  environmentId: this.environmentId,
@@ -18557,6 +18561,7 @@ var Granular = class _Granular {
18557
18561
  onUnexpectedClose;
18558
18562
  onReconnectError;
18559
18563
  effectHostUrl;
18564
+ graphqlIdempotencyKey;
18560
18565
  debugHttp = process.env.GRANULAR_DEBUG_HTTP === "1";
18561
18566
  /** Sandbox-level effect registry: sandboxId → (effectKey@selector → ToolWithHandler) */
18562
18567
  sandboxEffects = /* @__PURE__ */ new Map();
@@ -18586,6 +18591,7 @@ var Granular = class _Granular {
18586
18591
  this.onUnexpectedClose = options.onUnexpectedClose;
18587
18592
  this.onReconnectError = options.onReconnectError;
18588
18593
  this.effectHostUrl = options.effectHostUrl;
18594
+ this.graphqlIdempotencyKey = options.graphqlIdempotencyKey;
18589
18595
  this.httpUrl = this.apiUrl.replace(/^wss:\/\//, "https://").replace(/^ws:\/\//, "http://").replace(/\/ws$/, "");
18590
18596
  }
18591
18597
  /**
@@ -19601,7 +19607,9 @@ var Granular = class _Granular {
19601
19607
  envData,
19602
19608
  this.apiKey,
19603
19609
  graphqlEndpoint,
19604
- this.tokenProvider
19610
+ this.tokenProvider,
19611
+ void 0,
19612
+ this.graphqlIdempotencyKey
19605
19613
  );
19606
19614
  }
19607
19615
  async bindWebSocketEnvironmentSession(environment, clientId, session, transportOptions = {}) {