@nauth-toolkit/client 0.1.84 → 0.1.85

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.d.mts CHANGED
@@ -1729,6 +1729,10 @@ declare class NAuthClient {
1729
1729
  private buildUrl;
1730
1730
  /**
1731
1731
  * Build request headers for authentication.
1732
+ *
1733
+ * @param auth - Whether to include authentication headers
1734
+ * @param method - HTTP method (GET, POST, PUT, DELETE, PATCH)
1735
+ * @returns Headers object with auth, CSRF, and device trust headers
1732
1736
  * @private
1733
1737
  */
1734
1738
  private buildHeaders;
package/dist/index.d.ts CHANGED
@@ -1729,6 +1729,10 @@ declare class NAuthClient {
1729
1729
  private buildUrl;
1730
1730
  /**
1731
1731
  * Build request headers for authentication.
1732
+ *
1733
+ * @param auth - Whether to include authentication headers
1734
+ * @param method - HTTP method (GET, POST, PUT, DELETE, PATCH)
1735
+ * @returns Headers object with auth, CSRF, and device trust headers
1732
1736
  * @private
1733
1737
  */
1734
1738
  private buildHeaders;
package/dist/index.mjs CHANGED
@@ -1498,13 +1498,19 @@ var NAuthClient = class {
1498
1498
  }
1499
1499
  /**
1500
1500
  * Build request headers for authentication.
1501
+ *
1502
+ * @param auth - Whether to include authentication headers
1503
+ * @param method - HTTP method (GET, POST, PUT, DELETE, PATCH)
1504
+ * @returns Headers object with auth, CSRF, and device trust headers
1501
1505
  * @private
1502
1506
  */
1503
- async buildHeaders(auth) {
1507
+ async buildHeaders(auth, method = "GET") {
1504
1508
  const headers = {
1505
- "Content-Type": "application/json",
1506
1509
  ...this.config.headers
1507
1510
  };
1511
+ if (method !== "GET") {
1512
+ headers["Content-Type"] = "application/json";
1513
+ }
1508
1514
  if (auth && this.config.tokenDelivery === "json") {
1509
1515
  const accessToken = (await this.tokenManager.getTokens()).accessToken;
1510
1516
  if (accessToken) {
@@ -1520,7 +1526,8 @@ var NAuthClient = class {
1520
1526
  } catch {
1521
1527
  }
1522
1528
  }
1523
- if (this.config.tokenDelivery === "cookies" && hasWindow()) {
1529
+ const mutatingMethods = ["POST", "PUT", "PATCH", "DELETE"];
1530
+ if (this.config.tokenDelivery === "cookies" && hasWindow() && mutatingMethods.includes(method)) {
1524
1531
  const csrfToken = this.getCsrfToken();
1525
1532
  if (csrfToken) {
1526
1533
  headers[this.config.csrf.headerName] = csrfToken;
@@ -1543,7 +1550,7 @@ var NAuthClient = class {
1543
1550
  */
1544
1551
  async get(path, auth = false) {
1545
1552
  const url = this.buildUrl(path);
1546
- const headers = await this.buildHeaders(auth);
1553
+ const headers = await this.buildHeaders(auth, "GET");
1547
1554
  const credentials = this.config.tokenDelivery === "cookies" ? "include" : "omit";
1548
1555
  const response = await this.config.httpAdapter.request({
1549
1556
  method: "GET",
@@ -1559,7 +1566,7 @@ var NAuthClient = class {
1559
1566
  */
1560
1567
  async post(path, body, auth = false) {
1561
1568
  const url = this.buildUrl(path);
1562
- const headers = await this.buildHeaders(auth);
1569
+ const headers = await this.buildHeaders(auth, "POST");
1563
1570
  const credentials = this.config.tokenDelivery === "cookies" ? "include" : "omit";
1564
1571
  const response = await this.config.httpAdapter.request({
1565
1572
  method: "POST",
@@ -1576,7 +1583,7 @@ var NAuthClient = class {
1576
1583
  */
1577
1584
  async put(path, body, auth = false) {
1578
1585
  const url = this.buildUrl(path);
1579
- const headers = await this.buildHeaders(auth);
1586
+ const headers = await this.buildHeaders(auth, "PUT");
1580
1587
  const credentials = this.config.tokenDelivery === "cookies" ? "include" : "omit";
1581
1588
  const response = await this.config.httpAdapter.request({
1582
1589
  method: "PUT",
@@ -1593,7 +1600,7 @@ var NAuthClient = class {
1593
1600
  */
1594
1601
  async delete(path, auth = false) {
1595
1602
  const url = this.buildUrl(path);
1596
- const headers = await this.buildHeaders(auth);
1603
+ const headers = await this.buildHeaders(auth, "DELETE");
1597
1604
  const credentials = this.config.tokenDelivery === "cookies" ? "include" : "omit";
1598
1605
  const response = await this.config.httpAdapter.request({
1599
1606
  method: "DELETE",