@helium/blockchain-api 0.1.1 → 0.1.3

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.
Files changed (52) hide show
  1. package/README.md +24 -2
  2. package/package.json +31 -31
  3. package/types/README.md +24 -2
  4. package/types/generated/index.d.mts +2481 -0
  5. package/types/generated/index.d.ts +2481 -0
  6. package/types/generated/index.js +723 -0
  7. package/types/generated/index.mjs +614 -0
  8. package/types/index.ts +11 -8
  9. package/src/server/api/errors.ts +0 -152
  10. package/src/server/api/index.ts +0 -40
  11. package/src/server/api/procedures.ts +0 -144
  12. package/src/server/api/routers/fiat/router.ts +0 -709
  13. package/src/server/api/routers/fiat/schemas.ts +0 -157
  14. package/src/server/api/routers/health/router.ts +0 -41
  15. package/src/server/api/routers/hotspots/procedures/claimRewards.ts +0 -258
  16. package/src/server/api/routers/hotspots/procedures/createSplit.ts +0 -253
  17. package/src/server/api/routers/hotspots/procedures/deleteSplit.ts +0 -156
  18. package/src/server/api/routers/hotspots/procedures/getHotspots.ts +0 -31
  19. package/src/server/api/routers/hotspots/procedures/getPendingRewards.ts +0 -44
  20. package/src/server/api/routers/hotspots/procedures/getSplit.ts +0 -88
  21. package/src/server/api/routers/hotspots/procedures/transferHotspot.ts +0 -204
  22. package/src/server/api/routers/hotspots/procedures/updateRewardsDestination.ts +0 -201
  23. package/src/server/api/routers/hotspots/router.ts +0 -30
  24. package/src/server/api/routers/hotspots/schemas.ts +0 -182
  25. package/src/server/api/routers/swap/procedures/getInstructions.ts +0 -152
  26. package/src/server/api/routers/swap/procedures/getQuote.ts +0 -53
  27. package/src/server/api/routers/swap/procedures/getTokens.ts +0 -88
  28. package/src/server/api/routers/swap/router.ts +0 -15
  29. package/src/server/api/routers/swap/schemas.ts +0 -96
  30. package/src/server/api/routers/tokens/procedures/createHntAccount.ts +0 -87
  31. package/src/server/api/routers/tokens/procedures/getBalances.ts +0 -27
  32. package/src/server/api/routers/tokens/procedures/transfer.ts +0 -159
  33. package/src/server/api/routers/tokens/router.ts +0 -15
  34. package/src/server/api/routers/tokens/schemas.ts +0 -80
  35. package/src/server/api/routers/transactions/procedures/get.ts +0 -46
  36. package/src/server/api/routers/transactions/procedures/getByPayer.ts +0 -111
  37. package/src/server/api/routers/transactions/procedures/getByPayerAndTag.ts +0 -119
  38. package/src/server/api/routers/transactions/procedures/resubmit.ts +0 -68
  39. package/src/server/api/routers/transactions/procedures/submit.ts +0 -216
  40. package/src/server/api/routers/transactions/router.ts +0 -21
  41. package/src/server/api/routers/transactions/schemas.ts +0 -119
  42. package/src/server/api/routers/webhooks/router.ts +0 -75
  43. package/src/server/api/routers/welcomePacks/procedures/claim.ts +0 -157
  44. package/src/server/api/routers/welcomePacks/procedures/create.ts +0 -247
  45. package/src/server/api/routers/welcomePacks/procedures/deletePack.ts +0 -118
  46. package/src/server/api/routers/welcomePacks/procedures/get.ts +0 -36
  47. package/src/server/api/routers/welcomePacks/procedures/getByAddress.ts +0 -26
  48. package/src/server/api/routers/welcomePacks/procedures/invite.ts +0 -44
  49. package/src/server/api/routers/welcomePacks/procedures/list.ts +0 -27
  50. package/src/server/api/routers/welcomePacks/router.ts +0 -27
  51. package/src/server/api/routers/welcomePacks/schemas.ts +0 -135
  52. package/src/server/api/schemas.ts +0 -281
@@ -1,152 +0,0 @@
1
- import { z } from "zod";
2
-
3
- /**
4
- * Global error definitions for the ORPC API.
5
- * These can be used across all routers for consistent error handling.
6
- */
7
-
8
- /** Authentication required error */
9
- export const UNAUTHORIZED = {
10
- status: 401,
11
- message: "Authentication required. Please sign in to continue.",
12
- } as const;
13
-
14
- /** Insufficient permissions error */
15
- export const FORBIDDEN = {
16
- status: 403,
17
- message: "You do not have permission to access this resource.",
18
- } as const;
19
-
20
- /** Resource not found error */
21
- export const NOT_FOUND = {
22
- status: 404,
23
- message: "The requested resource was not found.",
24
- } as const;
25
-
26
- /** Input validation failed error */
27
- export const VALIDATION_ERROR = {
28
- status: 400,
29
- message: "Invalid input data provided.",
30
- data: z.object({
31
- fields: z.array(z.string()).optional(),
32
- }),
33
- } as const;
34
-
35
- /** Insufficient Solana balance error */
36
- export const INSUFFICIENT_FUNDS = {
37
- status: 400,
38
- message: "Insufficient SOL balance to complete this transaction.",
39
- data: z.object({
40
- required: z.number(),
41
- available: z.number(),
42
- }),
43
- } as const;
44
-
45
- /** Solana transaction failed error */
46
- export const TRANSACTION_FAILED = {
47
- status: 500,
48
- message: "Transaction failed to execute.",
49
- data: z.object({
50
- logs: z.array(z.string()).optional(),
51
- signature: z.string().optional(),
52
- }),
53
- } as const;
54
-
55
- /** Transaction simulation failed error */
56
- export const SIMULATION_FAILED = {
57
- status: 400,
58
- message: "Transaction simulation failed.",
59
- data: z.object({
60
- logs: z.array(z.string()).optional(),
61
- link: z.string().optional(),
62
- }),
63
- } as const;
64
-
65
- /** External API error (Jupiter, Bridge, Oracle, etc.) */
66
- export const EXTERNAL_API_ERROR = {
67
- status: 502,
68
- message: "External service request failed.",
69
- data: z.object({
70
- service: z.string(),
71
- statusCode: z.number().optional(),
72
- details: z.string().optional(),
73
- }),
74
- } as const;
75
-
76
- /** Rate limit exceeded error */
77
- export const RATE_LIMITED = {
78
- status: 429,
79
- message: "Too many requests. Please try again later.",
80
- } as const;
81
-
82
- /** Duplicate resource error */
83
- export const CONFLICT = {
84
- status: 409,
85
- message: "A resource with this identifier already exists.",
86
- data: z.object({
87
- existingId: z.string().optional(),
88
- }),
89
- } as const;
90
-
91
- /** Asset not owned by wallet error */
92
- export const NOT_OWNER = {
93
- status: 403,
94
- message: "You do not own this asset.",
95
- data: z.object({
96
- owner: z.string(),
97
- wallet: z.string(),
98
- }),
99
- } as const;
100
-
101
- /** Invalid Helium hotspot error */
102
- export const INVALID_HOTSPOT = {
103
- status: 400,
104
- message: "The specified asset is not a valid Helium hotspot.",
105
- } as const;
106
-
107
- /** KYC/Compliance error */
108
- export const KYC_REQUIRED = {
109
- status: 403,
110
- message: "KYC verification is required to perform this action.",
111
- data: z.object({
112
- kycStatus: z.string(),
113
- kycLink: z.string().optional(),
114
- }),
115
- } as const;
116
-
117
- /**
118
- * Common error definitions that can be spread into procedure error configs.
119
- * Usage: .errors({ ...commonErrors, CUSTOM_ERROR: { ... } })
120
- */
121
- export const commonErrors = {
122
- UNAUTHORIZED,
123
- FORBIDDEN,
124
- NOT_FOUND,
125
- VALIDATION_ERROR,
126
- } as const;
127
-
128
- /**
129
- * Solana-specific error definitions for transaction-related procedures.
130
- */
131
- export const solanaErrors = {
132
- INSUFFICIENT_FUNDS,
133
- TRANSACTION_FAILED,
134
- SIMULATION_FAILED,
135
- } as const;
136
-
137
- /**
138
- * Hotspot-specific error definitions.
139
- */
140
- export const hotspotErrors = {
141
- NOT_OWNER,
142
- INVALID_HOTSPOT,
143
- NOT_FOUND,
144
- } as const;
145
-
146
- /**
147
- * Fiat/offramp-specific error definitions.
148
- */
149
- export const fiatErrors = {
150
- KYC_REQUIRED,
151
- EXTERNAL_API_ERROR,
152
- } as const;
@@ -1,40 +0,0 @@
1
- import { createRouterClient } from "@orpc/server";
2
- import { healthRouter } from "./routers/health/router";
3
- import { hotspotsRouter } from "./routers/hotspots/router";
4
- import { tokensRouter } from "./routers/tokens/router";
5
- import { swapRouter } from "./routers/swap/router";
6
- import { transactionsRouter } from "./routers/transactions/router";
7
- import { welcomePacksRouter } from "./routers/welcomePacks/router";
8
- import { fiatRouter } from "./routers/fiat/router";
9
- import { webhooksRouter } from "./routers/webhooks/router";
10
-
11
- /**
12
- * Main ORPC router combining all domain-specific routers.
13
- *
14
- * This router provides both REST endpoints (via OpenAPIHandler) and
15
- * RPC endpoints (via RPCHandler) from the same procedure definitions.
16
- */
17
- export const appRouter = {
18
- /** Health check procedures */
19
- health: healthRouter,
20
- /** Hotspot management procedures */
21
- hotspots: hotspotsRouter,
22
- /** Token balance and transfer procedures */
23
- tokens: tokensRouter,
24
- /** Token swap procedures via Jupiter */
25
- swap: swapRouter,
26
- /** Transaction submission and tracking procedures */
27
- transactions: transactionsRouter,
28
- /** Welcome pack management procedures */
29
- welcomePacks: welcomePacksRouter,
30
- /** Fiat offramp and bank account procedures */
31
- fiat: fiatRouter,
32
- /** Webhook handler procedures */
33
- webhooks: webhooksRouter,
34
- };
35
-
36
- /** Type of the main router for client-side type inference */
37
- export type ORPCRouter = typeof appRouter;
38
-
39
- /** Server-side router client for direct procedure calls */
40
- export const api = createRouterClient(appRouter);
@@ -1,144 +0,0 @@
1
- import { ORPCError, os } from "@orpc/server";
2
- import { cookies } from "next/headers";
3
- import { privy } from "@/lib/privy";
4
- import { env } from "@/lib/env";
5
- import type { User } from "@privy-io/server-auth";
6
-
7
- /**
8
- * Session context provided to authenticated procedures.
9
- */
10
- export interface SessionContext {
11
- /** Privy user ID */
12
- userId: string;
13
- /** User's wallet address (if available) */
14
- walletAddress: string | null;
15
- /** Full Privy user object */
16
- user: User;
17
- }
18
-
19
- /**
20
- * Base context available to all procedures.
21
- */
22
- export interface BaseContext {
23
- /** Session data (null if not authenticated) */
24
- session: SessionContext | null;
25
- }
26
-
27
- /**
28
- * Context available to authenticated procedures.
29
- */
30
- export interface AuthenticatedContext extends BaseContext {
31
- session: SessionContext;
32
- }
33
-
34
- /**
35
- * Middleware for timing procedure execution and adding an artificial delay in development.
36
- *
37
- * You can remove this if you don't like it, but it can help catch unwanted waterfalls by simulating
38
- * network latency that would occur in production but not in local development.
39
- */
40
- const timingMiddleware = os.middleware(async ({ next, path }) => {
41
- const start = Date.now();
42
-
43
- if (env.NODE_ENV === "development") {
44
- // artificial delay in dev
45
- const waitMs = Math.floor(Math.random() * 400) + 100;
46
- await new Promise((resolve) => setTimeout(resolve, waitMs));
47
- }
48
-
49
- const result = await next();
50
-
51
- const end = Date.now();
52
- console.log(`[ORPC] ${path.join(".")} took ${end - start}ms to execute`);
53
-
54
- return result;
55
- });
56
-
57
- /**
58
- * Authentication middleware that extracts Privy session from cookies.
59
- * Sets session to null if not authenticated (allows public procedures to check auth status).
60
- */
61
- const authMiddleware = os.middleware(async ({ next }) => {
62
- let session: SessionContext | null = null;
63
-
64
- try {
65
- const cookieStore = await cookies();
66
- const idToken = cookieStore.get("privy-id-token")?.value;
67
-
68
- if (idToken) {
69
- const privyUser = await privy.getUser({ idToken });
70
-
71
- if (privyUser) {
72
- session = {
73
- userId: privyUser.id,
74
- walletAddress: privyUser.wallet?.address ?? null,
75
- user: privyUser,
76
- };
77
- }
78
- }
79
- } catch (error) {
80
- // Auth failed - session remains null
81
- console.error("[ORPC] Auth middleware error:", error);
82
- }
83
-
84
- return next({
85
- context: {
86
- session,
87
- } satisfies BaseContext,
88
- });
89
- });
90
-
91
- /**
92
- * Public (unauthenticated) procedure
93
- *
94
- * This is the base piece you use to build new queries and mutations on your API. It does not
95
- * guarantee that a user querying is authorized, but you can still access user session data if they
96
- * are logged in.
97
- */
98
- export const publicProcedure = os.use(timingMiddleware).use(authMiddleware);
99
-
100
- /**
101
- * Protected (authenticated) procedure
102
- *
103
- * If you want a query or mutation to ONLY be accessible to logged in users, use this. It verifies
104
- * the session is valid and guarantees `context.session` is not null.
105
- */
106
- export const protectedProcedure = publicProcedure.use(
107
- async ({ context, next }) => {
108
- if (!context.session) {
109
- throw new ORPCError("UNAUTHORIZED", {
110
- message: "You must be logged in to access this resource.",
111
- });
112
- }
113
-
114
- return next({
115
- context: {
116
- ...context,
117
- session: context.session,
118
- } satisfies AuthenticatedContext,
119
- });
120
- },
121
- );
122
-
123
- /**
124
- * Wallet-required procedure
125
- *
126
- * Use this for procedures that require the user to have a connected wallet.
127
- * Extends protectedProcedure and additionally verifies wallet is present.
128
- */
129
- export const walletProcedure = protectedProcedure.use(
130
- async ({ context, next }) => {
131
- if (!context.session.walletAddress) {
132
- throw new ORPCError("FORBIDDEN", {
133
- message: "A connected wallet is required to perform this action.",
134
- });
135
- }
136
-
137
- return next({
138
- context: {
139
- ...context,
140
- walletAddress: context.session.walletAddress,
141
- },
142
- });
143
- },
144
- );