@wefunder/sdk 0.1.0-beta.10 → 0.1.0-beta.11
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.cjs +159 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +44 -1
- package/dist/index.d.ts +44 -1
- package/dist/index.js +157 -28
- package/dist/index.js.map +1 -1
- package/examples_manifest.json +2 -2
- package/package.json +1 -1
package/examples_manifest.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"manifestVersion": 1,
|
|
3
3
|
"lang": "JavaScript",
|
|
4
4
|
"label": "@wefunder/sdk",
|
|
5
|
-
"sdkVersion": "0.1.0-beta.
|
|
5
|
+
"sdkVersion": "0.1.0-beta.11",
|
|
6
6
|
"apiVersion": "2025-01-15",
|
|
7
7
|
"generatedBy": "scripts/build-examples-manifest.mjs",
|
|
8
8
|
"samples": {
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"getWebhookEndpoint": "const endpoint = await wf.webhookEndpoints.get(\"whe_8f3ExampleEndpoint00\");\nconsole.log(endpoint.attributes?.events, endpoint.attributes?.failing_since);",
|
|
33
33
|
"getWebhookSubscription": "const subscription = await wf.unwrap(\n wf.raw.getWebhookSubscription({ path: { campaign_id: 1234, webhook_id: 56 } }),\n);\nconsole.log(subscription.data);",
|
|
34
34
|
"guides/client-credentials": "const wf = await Wefunder.fromClientCredentials({\n clientId: process.env.WEFUNDER_CLIENT_ID!,\n clientSecret: process.env.WEFUNDER_CLIENT_SECRET!,\n scopes: [\"read:public\"],\n});\n\nconsole.log(\"mode:\", wf.mode); // \"live\" or \"test\", from the token prefix\n\n// client_credentials holds only read:public — browse public offerings.\n// (wf.users.me() would throw 403 insufficient_scope: it needs read:profile.)\nfor await (const offering of wf.offerings.all()) {\n console.log(offering.id);\n}",
|
|
35
|
-
"guides/install-target": "// 1. Which companies / syndicates may this user install on? (Only those — an investor's\n// empty list is not a failure.)\nconst targets = await wf.unwrap(\n wf.raw.listEligibleInstallTargets({ query: { target_type: \"syndicate\" } }),\n);\nfor (const t of targets.data ?? [])\n console.log(t.id, t.name, t.installed ? \"(already installed)\" : \"\");\n\n// 2. Install. The response carries the install (`data`) AND its token. If the app is\n// already installed here the API answers 409 `already_installed` — its `details.installation`\n// is the existing install's id, so mint a fresh token for that instead. Any other error\n// (revoked install, missing scope) still throws.\nlet installationToken: string | undefined;\ntry {\n const installed = await wf.unwrap(\n wf.raw.createInstallation({\n body: {\n target_type: \"syndicate\",\n target_id: syndicateId,\n scopes: [\"read:syndicates\"],\n },\n }),\n );\n installationToken = installed.token?.access_token;\n} catch (err) {\n if (!(err instanceof WefunderError) || err.type !== \"already_installed\")\n throw err;\n const existingId = (err.details as { installation?: string } | undefined)\n ?.installation;\n if (!existingId) throw err;\n const minted = await wf.unwrap(\n wf.raw.createInstallationToken({
|
|
35
|
+
"guides/install-target": "// 1. Which companies / syndicates may this user install on? (Only those — an investor's\n// empty list is not a failure.)\nconst targets = await wf.unwrap(\n wf.raw.listEligibleInstallTargets({ query: { target_type: \"syndicate\" } }),\n);\nfor (const t of targets.data ?? [])\n console.log(t.id, t.name, t.installed ? \"(already installed)\" : \"\");\n\n// 2. Install. The response carries the install (`data`) AND its token. If the app is\n// already installed here the API answers 409 `already_installed` — its `details.installation`\n// is the existing install's id, so mint a fresh token for that instead. Any other error\n// (revoked install, missing scope) still throws.\nlet installationToken: string | undefined;\ntry {\n const installed = await wf.unwrap(\n wf.raw.createInstallation({\n body: {\n target_type: \"syndicate\",\n target_id: syndicateId,\n scopes: [\"read:syndicates\"],\n },\n }),\n );\n installationToken = installed.token?.access_token;\n} catch (err) {\n if (!(err instanceof WefunderError) || err.type !== \"already_installed\")\n throw err;\n const existingId = (err.details as { installation?: string } | undefined)\n ?.installation;\n if (!existingId) throw err;\n const minted = await wf.unwrap(\n // same scopes as the create above — never widen on re-mint\n wf.raw.createInstallationToken({\n path: { external_id: existingId },\n body: { scopes: [\"read:syndicates\"] },\n }),\n );\n installationToken = minted.token?.access_token; // shown once — store it\n}\nif (!installationToken) throw new Error(\"no installation token returned\");\n\n// 3. First request AS the installation.\nconst asSyndicate = new Wefunder({ accessToken: installationToken });\nconst deals = await asSyndicate.unwrap(\n asSyndicate.raw.listSyndicateDeals({ path: { syndicate_id: syndicateId } }),\n);\nconsole.log(deals.data?.length, \"deals\");",
|
|
36
36
|
"guides/user-token": "// 1. Send the investor to consent. Keep state + the PKCE verifier in their session.\nconst pkce = generatePkce();\nconst state = crypto.randomUUID();\nawait saveAttempt(state, pkce.codeVerifier);\nconst authorizationUrl = createAuthorizationUrl({\n clientId: process.env.WEFUNDER_CLIENT_ID!,\n redirectUri: process.env.WEFUNDER_REDIRECT_URI!,\n scopes: [\"read:investments\"],\n state,\n pkce,\n});\n// redirect(authorizationUrl)\n\n// 2. On the callback, exchange the code (after checking `state` matches the session).\nconst tokens = await exchangeCode({\n clientId: process.env.WEFUNDER_CLIENT_ID!,\n clientSecret: process.env.WEFUNDER_CLIENT_SECRET, // omit for public clients\n code: \"AUTHORIZATION_CODE\",\n redirectUri: process.env.WEFUNDER_REDIRECT_URI!,\n codeVerifier: pkce.codeVerifier,\n});\n\n// 3. Read their holdings. The access token lasts two hours; the SDK rotates the refresh\n// token for you and hands every new set to `store.save` — persist the whole thing.\nconst wf = new Wefunder({\n tokens,\n clientId: process.env.WEFUNDER_CLIENT_ID!,\n clientSecret: process.env.WEFUNDER_CLIENT_SECRET,\n store: { save: (next: TokenSet) => persistTokens(next) },\n});\nconst portfolio = await wf.portfolio.get();\nconsole.log(portfolio.attributes?.total_current_value_cents);",
|
|
37
37
|
"listActivity": "// Everything my connected apps did to syndicate members, most recent first.\nconst activity = await wf.unwrap(\n wf.raw.listActivity({\n query: { action_pattern: \"syndicates.member.*\", status: \"success\" },\n }),\n);\nfor (const event of activity.data ?? []) {\n console.log(event.attributes?.action, event.attributes?.created_at);\n}",
|
|
38
38
|
"listAttributedInvestments": "const investments = await wf.unwrap(\n wf.raw.listAttributedInvestments({\n path: { campaign_id: 1234 },\n query: { start_date: \"2026-01-01\", detail_level: \"anonymized\" },\n }),\n);\nfor (const investment of investments.data ?? []) {\n if (\"amount_tier\" in investment) {\n // Anonymized row: opaque tokens + an amount tier, never exact values or PII.\n console.log(investment.investor_token, investment.amount_tier, investment.attribution?.utm_source);\n }\n}",
|