@beep-it/sdk-core 0.1.0-beta.0

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 ADDED
@@ -0,0 +1,358 @@
1
+ # The BEEP SDK: Turn Your Cool Sh*t into Cash 💸
2
+
3
+ Alright, let's be real. You made something awesome. A game, an app, a digital masterpiece. And now you wanna get paid for it. As you should! But dealing with payments is a whole vibe killer. That's where we come in.
4
+
5
+ ## 🤔 So, like, what even *is* this?
6
+
7
+ Think of this SDK as your personal cheat code for money. It's a box of pre-written code that you can just drop into your project to handle all the boring payment stuff.
8
+
9
+ No, you don't need to know what an "SDK" is. Just know this: **this is the easy button.**
10
+
11
+ With this, you can:
12
+
13
+ * **Give your users a "wallet"**: It's not a real wallet. It's just a secure spot online for them to keep their digital cash to pay you with. We handle all the scary security stuff.
14
+ * **Ask for money (nicely)**: Create an "invoice," which is just a fancy word for a bill. It's like sending a Venmo request, but for your app.
15
+ * **Actually get paid**: Process the payment and see the money roll in. Cha-ching.
16
+
17
+ Basically, we're the ✨ unpaid intern ✨ who handles your finances so you can get back to creating.
18
+
19
+ ---
20
+
21
+ ## 🚀 Let's Get This Bread: Your 3-Step Setup
22
+
23
+ This is probably easier than picking an Instagram filter. No cap.
24
+
25
+ ### Step 1: Download the Magic
26
+
27
+ In your project's command line thingy (the black box where you type stuff), paste this:
28
+
29
+ ```bash
30
+ npm install @beep-it/sdk-core
31
+ ```
32
+ This basically downloads our toolkit and puts it in your project's folder.
33
+
34
+ ### Step 2: Get Your Secret Handshake (aka API Key)
35
+
36
+ An API Key is just a super long, secret password. It's how our system knows it's you. You'll find yours on your BEEP dashboard.
37
+
38
+ > **Seriously, don't share this.** It's like giving someone the keys to your house. Don't do it.
39
+
40
+ ### Step 3: Wake Up the BEEP-Bot
41
+
42
+ Time to write, like, one line of code. This tells your project to start using the BEEP toolkit.
43
+
44
+ ```typescript
45
+ // This line just says, "Hey, I wanna use that beep-sdk thing I just downloaded."
46
+ import { BeepClient, SupportedToken } from '@beep-it/sdk-core';
47
+
48
+ // This line creates your BEEP-Bot. It's now ready for your commands.
49
+ const beep = new BeepClient({
50
+ // Just paste that secret key you got from the dashboard right here.
51
+ apiKey: 'your_super_secret_api_key_goes_here'
52
+ });
53
+
54
+ console.log('Ok, your BEEP-Bot is ready. Slay.');
55
+ ```
56
+
57
+ Bet. You're all set up. Now for the fun part.
58
+
59
+ ---
60
+
61
+ ## ⚙️ How to Actually Make Money with This
62
+
63
+ Let's say you want to charge someone 5 USDT for a pack of 100 magic crystals in your game. Here's how to make that money move! 💸
64
+
65
+ ### Step 1: Ask for the Money
66
+
67
+ You just need to tell your BEEP-Bot how much you want to charge and in what currency. We'll generate a unique QR code and a payment link for your customer.
68
+
69
+ #### The Whole Payment Flow Explained (as if you were 5... but like, a cool 5-year-old)
70
+
71
+ 1. **You create an invoice** - This is literally just you telling our servers "hey, I want $X for Y reason"
72
+ 2. **We create an invoice** - Think of this as a digital receipt that says "pay this amount pls"
73
+ 3. **We give you back payment details** - This includes:
74
+ - A `paymentUrl` (a link you can send to your customer)
75
+ - A `qrCode` (same link but as a scannable QR code for mobile)
76
+ - A `referenceKey` (a unique ID to track this specific payment)
77
+ - An `invoiceId` (the invoice ID you can use to check payment status later)
78
+ 4. **Your user pays** - They click the link or scan the code and pay using their crypto wallet
79
+ 5. **We handle the crypto magic** - All the blockchain validation, token transfers, etc.
80
+ 6. **You get notified** - Either through webhooks (if you set those up) or by checking the status
81
+ 7. **Money lands in your account** - Cha-ching! 🤑
82
+
83
+ Seriously, all *you* need to worry about is step 1. We handle 2-7 because we're nice like that.
84
+
85
+ ```typescript
86
+ // Just describe what you're charging for.
87
+ const invoiceDetails = {
88
+ description: 'A pack of 100 magic crystals',
89
+ amount: '5.00', // Amount as string
90
+ token: SupportedToken.USDT, // Much cleaner than a long address, right?
91
+ payerType: 'customer_wallet' as const, // Who's paying
92
+ };
93
+
94
+ try {
95
+ // Tell your BEEP-Bot to create an invoice for payment.
96
+ // This creates a bill and gets everything ready behind the scenes.
97
+ const invoice = await beep.invoices.createInvoice(invoiceDetails);
98
+
99
+ // Now you have everything you need to get paid!
100
+ console.log('QR Code:', invoice.qrCode);
101
+ console.log('Payment Link:', invoice.paymentUrl);
102
+ console.log('Reference Key:', invoice.referenceKey);
103
+
104
+ // What you do next is up to you:
105
+ // 1. Render the `qrCode` in your UI for the user to scan.
106
+ // 2. Redirect the user to the `paymentUrl`.
107
+ // BEEP will handle the rest on the backend once the user approves the transaction.
108
+
109
+ } catch (error) {
110
+ console.error('Oof. Something went wrong creating the invoice:', error.message);
111
+ }
112
+ ```
113
+
114
+ And that's literally it. Once the user pays, the money appears in your account. You just made money.
115
+
116
+ ---
117
+
118
+ ## 🤓 For the true DIYers (The API Deets)
119
+
120
+ If you're the type of person who likes to take things apart just so you can put them back together, this is for you. Here are the technical specs. Everyone else, you can ignore this.
121
+
122
+ ### `BeepClient`
123
+
124
+ Initializes the client. Takes an `options` object.
125
+
126
+ ```typescript
127
+ new BeepClient(options: {
128
+ apiKey: string; // Required. Your secret API key.
129
+ serverUrl?: string; // Optional. For testing. Defaults to production.
130
+ })
131
+ ```
132
+
133
+ **High-Level Methods:**
134
+
135
+ #### Creating Invoices for Payment
136
+
137
+ ```typescript
138
+ // The money maker - create an invoice for payment!
139
+ const invoice = await beep.invoices.createInvoice({
140
+ amount: '19.99', // Amount as string
141
+ token: SupportedToken.USDT, // Enum magic!
142
+ description: 'VIP Battle Pass - Summer Season',
143
+ payerType: 'customer_wallet' // Customer pays
144
+ });
145
+
146
+ // Now you have everything you need for the user to pay
147
+ console.log('Payment URL:', invoice.paymentUrl);
148
+ console.log('Reference Key:', invoice.referenceKey);
149
+ console.log('Invoice ID:', invoice.id);
150
+
151
+ // IMPORTANT PART: What to do with this info!
152
+ // Option 1: Redirect your user to the payment page
153
+ window.location.href = invoice.paymentUrl;
154
+
155
+ // OR Option 2: Show a QR code on your page
156
+ renderQRCode(invoice.qrCode); // Use your favorite QR library
157
+
158
+ // OR Option 3: Just give them the link
159
+ displayToUser(`Pay here: ${invoice.paymentUrl}`);
160
+
161
+ // After payment (could be seconds or minutes later):
162
+ // Check if they've paid yet
163
+ const updatedInvoice = await beep.invoices.getInvoice(invoice.id);
164
+
165
+ if (updatedInvoice.status === 'paid') {
166
+ // Woohoo! Give them their digital goodies!
167
+ unlockAwesomeContent();
168
+ doHappyDance();
169
+ } else if (updatedInvoice.status === 'pending') {
170
+ // Still waiting for payment
171
+ showSpinnyWaitingAnimation();
172
+ } else if (updatedInvoice.status === 'expired') {
173
+ // Oof, they took too long
174
+ showSadTromboneSound();
175
+ }
176
+ ```
177
+
178
+ #### Health Check
179
+
180
+ ```typescript
181
+ // Make sure our servers aren't on fire
182
+ const health = await beep.healthCheck();
183
+ console.log('Server health:', health); // Should return health status
184
+ ```
185
+
186
+ **Low-Level Modules:**
187
+
188
+ For when you need more control.
189
+
190
+ ### `SupportedToken`
191
+
192
+ Our shiny new enum for supported tokens! Way easier than remembering addresses.
193
+
194
+ ```typescript
195
+ // Import it like this
196
+ import { SupportedToken } from '@beep-it/sdk-core';
197
+
198
+ // Use it like this
199
+ const token = SupportedToken.USDT; // Currently supported
200
+ // SupportedToken.USDC coming soon!
201
+ ```
202
+
203
+ ### `beep.invoices`
204
+
205
+ Handle invoice operations - create, retrieve, and manage payment invoices.
206
+
207
+ ```typescript
208
+ // Create invoices for payment
209
+ const invoice = await beep.invoices.createInvoice({
210
+ description: 'Premium service',
211
+ amount: '29.99',
212
+ token: SupportedToken.USDT,
213
+ payerType: 'customer_wallet'
214
+ });
215
+
216
+ // Get all your invoices
217
+ const invoices = await beep.invoices.listInvoices();
218
+
219
+ // Look up a specific invoice
220
+ const invoice = await beep.invoices.getInvoice('inv_123abc');
221
+
222
+ // Delete an invoice
223
+ await beep.invoices.deleteInvoice('inv_123abc');
224
+ ```
225
+
226
+ ### `beep.products`
227
+
228
+ Manage your products - create reusable payment configurations with sweet token enum support! 🎉
229
+
230
+ #### Creating Products
231
+
232
+ ```typescript
233
+ // Creating a one-time purchase product
234
+ const product = await beep.products.createProduct({
235
+ name: 'Magic Sword of Destiny',
236
+ description: 'Gives +10 attack and looks cool as heck',
237
+ price: '9.99', // Just regular numbers as strings
238
+ token: SupportedToken.USDT, // So much cleaner than a crazy address
239
+ isSubscription: false // One-time purchase
240
+ });
241
+
242
+ console.log(`Created product with ID: ${product.id}`);
243
+
244
+ // Creating a subscription product
245
+ const subscriptionProduct = await beep.products.createProduct({
246
+ name: 'Premium Battle Pass',
247
+ description: 'Monthly subscription with exclusive skins and perks',
248
+ price: '14.99', // Monthly price
249
+ token: SupportedToken.USDT,
250
+ isSubscription: true // This makes it recurring - monthly subscription!
251
+ });
252
+
253
+ console.log(`Created subscription with ID: ${subscriptionProduct.id}`);
254
+
255
+ // Creating a one-time purchase product (pay-per-use)
256
+ const oneTimeProduct = await beep.products.createProduct({
257
+ name: 'API Usage Credit',
258
+ description: 'Credits for API calls',
259
+ price: '0.001', // Price per credit
260
+ token: SupportedToken.USDT,
261
+ isSubscription: false // One-time purchase
262
+ });
263
+
264
+ console.log(`Created one-time product with ID: ${oneTimeProduct.id}`);
265
+ ```
266
+
267
+ #### Getting a Product
268
+
269
+ ```typescript
270
+ // Fetch a product by ID
271
+ const product = await beep.products.getProduct('prod_123abc456def');
272
+ console.log(`Found product: ${product.name} for ${product.price}`);
273
+ ```
274
+
275
+ #### Listing All Products
276
+
277
+ ```typescript
278
+ // Get all your amazing products
279
+ const products = await beep.products.listProducts();
280
+ console.log(`You have ${products.length} products`);
281
+
282
+ // Loop through them if you're feeling fancy
283
+ products.forEach(product => {
284
+ console.log(`${product.name}: ${product.price} ${product.token || 'tokens'}`);
285
+ });
286
+ ```
287
+
288
+ #### Updating a Product
289
+
290
+ ```typescript
291
+ // Change your mind about pricing? No problemo!
292
+ const updatedProduct = await beep.products.updateProduct('prod_123abc456def', {
293
+ price: '14.99', // Price increase! Cha-ching!
294
+ description: 'Now with extra sparkles ✨',
295
+ token: SupportedToken.USDT
296
+ });
297
+
298
+ console.log('Product updated with new price:', updatedProduct.price);
299
+ ```
300
+
301
+ #### Deleting a Product
302
+
303
+ ```typescript
304
+ // That product is so last season - delete it!
305
+ await beep.products.deleteProduct('prod_123abc456def');
306
+ console.log('Poof! Product deleted.');
307
+ ```
308
+
309
+ ### `beep.payments`
310
+
311
+ Handle low-level payment operations like asset purchasing and transaction signing.
312
+
313
+ ```typescript
314
+ // Request payment for assets
315
+ const payment = await beep.payments.requestAndPurchaseAsset({
316
+ paymentReference: 'premium_subscription_123',
317
+ assetIds: ['asset_1', 'asset_2']
318
+ });
319
+
320
+ // Sign Solana transactions directly
321
+ const signedTx = await beep.payments.signSolanaTransaction({
322
+ senderAddress: 'sender_wallet_address',
323
+ recipientAddress: 'recipient_wallet_address',
324
+ tokenMintAddress: 'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB',
325
+ amount: 1000000, // 1.0 USDT in base units
326
+ decimals: 6
327
+ });
328
+ ```
329
+
330
+ ### `TokenUtils`
331
+
332
+ For the super nerds who want to play with token addresses:
333
+
334
+ ```typescript
335
+ import { TokenUtils, SupportedToken } from '@beep-it/sdk-core';
336
+
337
+ // Get the address from a token enum
338
+ const address = TokenUtils.getTokenAddress(SupportedToken.USDT);
339
+ console.log(address); // 'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB'
340
+
341
+ // Check if we support a token
342
+ const isSupported = TokenUtils.isTokenSupported(SupportedToken.USDT); // true
343
+ const isUsdtSupported = TokenUtils.isTokenSupported('USDT'); // false (coming soon™)
344
+
345
+ // Get a token enum from an address (reverse lookup)
346
+ const token = TokenUtils.getTokenFromAddress('Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB');
347
+ console.log(token); // SupportedToken.USDT
348
+
349
+ // Get the default token if none specified
350
+ const defaultToken = TokenUtils.getDefaultToken();
351
+ console.log(defaultToken); // SupportedToken.USDT
352
+ ```
353
+
354
+ ---
355
+
356
+ ## License
357
+
358
+ MIT. Go wild.
@@ -0,0 +1,73 @@
1
+ /**
2
+ * @fileoverview Main entry point for the BEEP SDK
3
+ * Provides a unified client for interacting with the BEEP payment and invoice API
4
+ */
5
+ import { InvoicesModule } from './modules/invoices';
6
+ import { PaymentsModule } from './modules/payments';
7
+ import { ProductsModule } from './modules/products';
8
+ /**
9
+ * Configuration options for initializing the BeepClient
10
+ */
11
+ export interface BeepClientOptions {
12
+ /** Your BEEP API key - keep this secure and never expose it in client-side code */
13
+ apiKey: string;
14
+ /**
15
+ * Optional server URL override for development/testing
16
+ * @default 'https://api.beep.com'
17
+ */
18
+ serverUrl?: string;
19
+ }
20
+ /**
21
+ * The main BEEP SDK client for interacting with the BEEP API
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * import { BeepClient, SupportedToken } from '@beep-it/sdk-core';
26
+ *
27
+ * const beep = new BeepClient({
28
+ * apiKey: 'your_api_key_here'
29
+ * });
30
+ *
31
+ * // Create a payment request
32
+ * const payment = await beep.requestPayment({
33
+ * amount: 10.00,
34
+ * token: SupportedToken.USDT,
35
+ * description: 'Premium subscription'
36
+ * });
37
+ * ```
38
+ */
39
+ export declare class BeepClient {
40
+ private client;
41
+ /** Access to product management functionality */
42
+ readonly products: ProductsModule;
43
+ /** Access to invoice management functionality */
44
+ readonly invoices: InvoicesModule;
45
+ /** Access to payment processing functionality */
46
+ readonly payments: PaymentsModule;
47
+ /**
48
+ * Creates a new BEEP client instance
49
+ *
50
+ * @param options - Configuration options including API key and optional server URL
51
+ * @throws {Error} When API key is missing or invalid
52
+ */
53
+ constructor(options: BeepClientOptions);
54
+ /**
55
+ * Checks the health status of the BEEP API server
56
+ *
57
+ * @returns Promise that resolves to the server health status
58
+ * @throws {Error} When the API is unreachable or returns an error
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * const status = await beep.healthCheck();
63
+ * console.log('Server status:', status);
64
+ * ```
65
+ */
66
+ healthCheck(): Promise<string>;
67
+ }
68
+ export type { PaymentRequestData, RequestPaymentPayload } from './types/payment';
69
+ export type { CreateCustomInvoicePayload, CreateInvoiceFromProductPayload, CreateInvoicePayload, Invoice, InvoiceStatus, PayerType, } from './types/invoice';
70
+ export type { CreateProductPayload, Product, UpdateProductPayload } from './types/product';
71
+ export { SupportedToken, TokenUtils } from './types/token';
72
+ export type { BeepResponse } from './types';
73
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,mFAAmF;IACnF,MAAM,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,MAAM,CAAgB;IAE9B,iDAAiD;IACjD,SAAgB,QAAQ,EAAE,cAAc,CAAC;IAEzC,iDAAiD;IACjD,SAAgB,QAAQ,EAAE,cAAc,CAAC;IAEzC,iDAAiD;IACjD,SAAgB,QAAQ,EAAE,cAAc,CAAC;IAEzC;;;;;OAKG;gBACS,OAAO,EAAE,iBAAiB;IAmBtC;;;;;;;;;;;OAWG;IACU,WAAW,IAAI,OAAO,CAAC,MAAM,CAAC;CAW5C;AAOD,YAAY,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAGjF,YAAY,EACV,0BAA0B,EAC1B,+BAA+B,EAC/B,oBAAoB,EACpB,OAAO,EACP,aAAa,EACb,SAAS,GACV,MAAM,iBAAiB,CAAC;AAGzB,YAAY,EAAE,oBAAoB,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAG3F,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3D,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC"}