@spacelr/sdk 0.1.9 → 0.1.10

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
@@ -1741,24 +1741,31 @@ var FunctionsModule = class {
1741
1741
  }
1742
1742
  /**
1743
1743
  * Invoke a function.
1744
- * Calls POST /api/v1/functions/:projectId/:functionId/invoke
1744
+ * Calls POST `/functions/:projectId/:functionId/invoke`, resolved against
1745
+ * `config.apiUrl` (which already carries the `/api/v1` prefix).
1745
1746
  *
1746
- * Provide `secret` for webhook/hybrid functions, `authenticated: true` for
1747
- * JWT-based invocation, or both for hybrid (JWT wins). Public mode needs
1748
- * neither, though `authenticated: true` still populates `event.auth` inside
1749
- * the function.
1747
+ * Auth defaults, based on `invokeMode` semantics:
1748
+ * - webhook: pass `secret` Authorization is NOT attached
1749
+ * - authenticated: pass nothing → Authorization IS attached (from token manager)
1750
+ * - public: pass nothing → Authorization is attached if logged in, else omitted
1751
+ * - hybrid: pass both `secret` and `authenticated: true`
1752
+ *
1753
+ * To force a specific behaviour, set `authenticated` explicitly — it wins
1754
+ * over the `secret`-based default.
1750
1755
  */
1751
1756
  async invoke(projectId, functionId, options = {}) {
1757
+ const hasSecret = (options.secret?.length ?? 0) > 0;
1752
1758
  const headers = {};
1753
- if (options.secret) {
1759
+ if (hasSecret) {
1754
1760
  headers["X-Webhook-Secret"] = options.secret;
1755
1761
  }
1762
+ const authenticated = options.authenticated ?? !hasSecret;
1756
1763
  return this.http.request({
1757
1764
  method: "POST",
1758
- path: `/api/v1/functions/${encodeURIComponent(projectId)}/${encodeURIComponent(functionId)}/invoke`,
1765
+ path: `/functions/${encodeURIComponent(projectId)}/${encodeURIComponent(functionId)}/invoke`,
1759
1766
  headers,
1760
1767
  body: options.payload ?? {},
1761
- authenticated: options.authenticated ?? false
1768
+ authenticated
1762
1769
  });
1763
1770
  }
1764
1771
  };