@wefunder/sdk 0.1.0-beta.3 → 0.1.0-beta.5
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/README.md +3 -3
- package/dist/index.cjs +28 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -4
- package/dist/index.d.ts +6 -4
- package/dist/index.js +27 -16
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -102,10 +102,10 @@ const wf = new Wefunder({
|
|
|
102
102
|
|
|
103
103
|
OAuth uses two hosts, independently overridable:
|
|
104
104
|
|
|
105
|
-
- **
|
|
106
|
-
- **
|
|
105
|
+
- **token host** — `/token` + refresh (`fromClientCredentials`, `exchangeCode`, refresh). Defaults to `https://api.wefunder.com/oauth`. The edge gateway routes by the credential's mode (a `pk_test_` grant mints in sandbox, `pk_live_` in live), so one host serves both. Override via `tokenBaseUrl` (or set both with `oauthBaseUrl`).
|
|
106
|
+
- **authorize host** — the browser consent redirect (`createAuthorizationUrl`). Picked from the `client_id`: `pk_test_` → `https://oauth.wefunder-sandbox.com/oauth` (sandbox consent), otherwise `https://wefunder.com/oauth` (live). Override via `authorizeBaseUrl`.
|
|
107
107
|
|
|
108
|
-
The **API base** is `WefunderOptions.baseUrl` (default `https://api.wefunder.com
|
|
108
|
+
The **API base** is `WefunderOptions.baseUrl` (default `https://api.wefunder.com`, version-free). The API version is pinned by the `Wefunder-Version` header, not the path; `/api/v2` remains a working back-compat alias.
|
|
109
109
|
|
|
110
110
|
## Pagination
|
|
111
111
|
|
package/dist/index.cjs
CHANGED
|
@@ -28,6 +28,7 @@ __export(index_exports, {
|
|
|
28
28
|
DELIVERY_ID_HEADER: () => DELIVERY_ID_HEADER,
|
|
29
29
|
EVENT_HEADER: () => EVENT_HEADER,
|
|
30
30
|
REQUEST_ID_HEADER: () => REQUEST_ID_HEADER,
|
|
31
|
+
SANDBOX_AUTHORIZE_BASE_URL: () => SANDBOX_AUTHORIZE_BASE_URL,
|
|
31
32
|
SIGNATURE_HEADER: () => SIGNATURE_HEADER,
|
|
32
33
|
TIMESTAMP_HEADER: () => TIMESTAMP_HEADER,
|
|
33
34
|
Wefunder: () => Wefunder,
|
|
@@ -880,13 +881,6 @@ function backoffMs(attempt, opts, random) {
|
|
|
880
881
|
const jitter = exp * 0.5 * random();
|
|
881
882
|
return Math.min(exp + jitter, opts.maxDelayMs);
|
|
882
883
|
}
|
|
883
|
-
function withBearer(input, init, token) {
|
|
884
|
-
const headers = new Headers(
|
|
885
|
-
init?.headers ?? (input instanceof Request ? input.headers : void 0)
|
|
886
|
-
);
|
|
887
|
-
headers.set("Authorization", `Bearer ${token}`);
|
|
888
|
-
return { ...init, headers };
|
|
889
|
-
}
|
|
890
884
|
function createFetch(deps) {
|
|
891
885
|
const baseFetch = deps.fetch ?? fetch;
|
|
892
886
|
const sleep = deps.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
@@ -900,21 +894,37 @@ function createFetch(deps) {
|
|
|
900
894
|
return async function wrappedFetch(input, init) {
|
|
901
895
|
const method = methodOf(input, init);
|
|
902
896
|
const idempotent = IDEMPOTENT.has(method);
|
|
897
|
+
const isRequest = input instanceof Request;
|
|
903
898
|
let refreshed = false;
|
|
904
899
|
let attempt = 0;
|
|
900
|
+
let retryToken;
|
|
901
|
+
const dispatch = (authToken) => {
|
|
902
|
+
if (isRequest) {
|
|
903
|
+
const fresh = input.clone();
|
|
904
|
+
if (authToken === void 0) return baseFetch(fresh);
|
|
905
|
+
const headers = new Headers(fresh.headers);
|
|
906
|
+
headers.set("Authorization", `Bearer ${authToken}`);
|
|
907
|
+
return baseFetch(new Request(fresh, { headers }));
|
|
908
|
+
}
|
|
909
|
+
const nextInit = authToken === void 0 ? init : (() => {
|
|
910
|
+
const headers = new Headers(init?.headers);
|
|
911
|
+
headers.set("Authorization", `Bearer ${authToken}`);
|
|
912
|
+
return { ...init, headers };
|
|
913
|
+
})();
|
|
914
|
+
return baseFetch(input, nextInit);
|
|
915
|
+
};
|
|
905
916
|
for (; ; ) {
|
|
906
917
|
let response;
|
|
907
918
|
let networkError;
|
|
908
919
|
try {
|
|
909
|
-
response = await
|
|
920
|
+
response = await dispatch(retryToken);
|
|
910
921
|
} catch (err) {
|
|
911
922
|
networkError = err;
|
|
912
923
|
}
|
|
913
|
-
|
|
914
|
-
if (response?.status === 401 && !refreshed && replayable && deps.tokenManager?.canRefresh) {
|
|
924
|
+
if (response?.status === 401 && !refreshed && deps.tokenManager?.canRefresh) {
|
|
915
925
|
refreshed = true;
|
|
916
926
|
const next = await deps.tokenManager.refresh();
|
|
917
|
-
|
|
927
|
+
retryToken = next.accessToken;
|
|
918
928
|
continue;
|
|
919
929
|
}
|
|
920
930
|
if (response?.status === 429 && attempt < retry.maxRetries) {
|
|
@@ -937,10 +947,11 @@ function createFetch(deps) {
|
|
|
937
947
|
// src/oauth.ts
|
|
938
948
|
var import_node_crypto = require("crypto");
|
|
939
949
|
var DEFAULT_AUTHORIZE_BASE_URL = "https://wefunder.com/oauth";
|
|
940
|
-
var
|
|
950
|
+
var SANDBOX_AUTHORIZE_BASE_URL = "https://oauth.wefunder-sandbox.com/oauth";
|
|
951
|
+
var DEFAULT_TOKEN_BASE_URL = "https://api.wefunder.com/oauth";
|
|
941
952
|
var DEFAULT_OAUTH_BASE_URL = DEFAULT_AUTHORIZE_BASE_URL;
|
|
942
|
-
function
|
|
943
|
-
return
|
|
953
|
+
function defaultAuthorizeBase(clientId) {
|
|
954
|
+
return clientId.startsWith("pk_test_") ? SANDBOX_AUTHORIZE_BASE_URL : DEFAULT_AUTHORIZE_BASE_URL;
|
|
944
955
|
}
|
|
945
956
|
function resolveTokenBase(o) {
|
|
946
957
|
return o.tokenBaseUrl ?? o.oauthBaseUrl ?? DEFAULT_TOKEN_BASE_URL;
|
|
@@ -980,7 +991,7 @@ function generatePkce() {
|
|
|
980
991
|
return { codeVerifier, codeChallenge, codeChallengeMethod: "S256" };
|
|
981
992
|
}
|
|
982
993
|
function createAuthorizationUrl(opts) {
|
|
983
|
-
const base =
|
|
994
|
+
const base = opts.authorizeBaseUrl ?? opts.oauthBaseUrl ?? defaultAuthorizeBase(opts.clientId);
|
|
984
995
|
const q = new URLSearchParams({
|
|
985
996
|
response_type: "code",
|
|
986
997
|
client_id: opts.clientId,
|
|
@@ -1494,7 +1505,7 @@ var revokePartnerInvite = (options) => (options.client ?? client).delete({
|
|
|
1494
1505
|
});
|
|
1495
1506
|
|
|
1496
1507
|
// src/client.ts
|
|
1497
|
-
var DEFAULT_API_BASE_URL = "https://api.wefunder.com
|
|
1508
|
+
var DEFAULT_API_BASE_URL = "https://api.wefunder.com";
|
|
1498
1509
|
var DEFAULT_API_VERSION = "2025-01-15";
|
|
1499
1510
|
function modeForToken(token) {
|
|
1500
1511
|
if (token.startsWith("at_live_")) return "live";
|
|
@@ -1719,6 +1730,7 @@ function constructEvent(payload, headers, secret, opts) {
|
|
|
1719
1730
|
DELIVERY_ID_HEADER,
|
|
1720
1731
|
EVENT_HEADER,
|
|
1721
1732
|
REQUEST_ID_HEADER,
|
|
1733
|
+
SANDBOX_AUTHORIZE_BASE_URL,
|
|
1722
1734
|
SIGNATURE_HEADER,
|
|
1723
1735
|
TIMESTAMP_HEADER,
|
|
1724
1736
|
Wefunder,
|