flit-baas 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Flit Technologies
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,177 @@
1
+ # flit-baas
2
+
3
+ Official TypeScript & JavaScript Client SDK for **Flit BaaS** (Backend-as-a-Service) and **Mobile Money** payments across Africa.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/flit-baas.svg)](https://www.npmjs.com/package/flit-baas)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
7
+
8
+ ---
9
+
10
+ ## Features
11
+
12
+ - ⚡ **Zero-Config Database**: Instant document store powered by ACID PostgreSQL.
13
+ - 📱 **Native Mobile Money**: Orange Money, MTN MoMo, Wave, Airtel Money, Moov, M-Pesa.
14
+ - 🔒 **Zero-Leak Security**: Authenticate with public Anon Keys or private Service Role keys.
15
+ - 🍪 **HttpOnly Encrypted Cookies**: AES-256-GCM authenticated session encryption (immunized against XSS).
16
+ - 📦 **Universal Runtime**: Works in Browser (React, Vue, Svelte), Node.js, Next.js, and Edge runtimes.
17
+ - 🚀 **Zero Dependencies**: Lightweight (< 22 KB), built on modern standard `fetch`.
18
+
19
+ ---
20
+
21
+ ## Installation
22
+
23
+ ```bash
24
+ npm install flit-baas
25
+ # or
26
+ pnpm add flit-baas
27
+ # or
28
+ yarn add flit-baas
29
+ ```
30
+
31
+ ---
32
+
33
+ ## Quickstart
34
+
35
+ ### 1. Initialize the client
36
+
37
+ ```typescript
38
+ import { createClient } from 'flit-baas';
39
+
40
+ export const flit = createClient({
41
+ appId: process.env.NEXT_PUBLIC_FLIT_APP_ID!,
42
+ apiKey: process.env.NEXT_PUBLIC_FLIT_API_KEY!,
43
+ // endpoint: 'https://api.flit.site' (default)
44
+ });
45
+ ```
46
+
47
+ ### 2. Database Operations (Collections)
48
+
49
+ ```typescript
50
+ interface Product {
51
+ id: string;
52
+ name: string;
53
+ price: number;
54
+ category: string;
55
+ stock: number;
56
+ }
57
+
58
+ const products = flit.collection<Product>('products');
59
+
60
+ // Query documents
61
+ const items = await products.find({ category: 'shoes' }, { limit: 20, orderBy: 'price', order: 'desc' });
62
+
63
+ // Get a single document by ID
64
+ const shoe = await products.findById('rec_abc123');
65
+
66
+ // Insert a new document
67
+ const newItem = await products.insert({
68
+ name: 'Sneakers Pro',
69
+ price: 35000,
70
+ category: 'shoes',
71
+ stock: 10,
72
+ });
73
+
74
+ // Update a document
75
+ await products.update(newItem.id, {
76
+ stock: 9,
77
+ });
78
+
79
+ // Delete a document
80
+ await products.delete(newItem.id);
81
+ ```
82
+
83
+ ### 3. Mobile Money Payments (STK Push)
84
+
85
+ Trigger instant Mobile Money payment prompts directly on customer smartphones in Central and West Africa:
86
+
87
+ ```typescript
88
+ // Initiate STK Push payment
89
+ const payment = await flit.payments.initiate({
90
+ operator: 'ORANGE', // 'ORANGE' | 'MTN' | 'WAVE' | 'AIRTEL' | 'MOOV' | 'MPESA'
91
+ phone: '+237690000000',
92
+ amount: 35000,
93
+ currency: 'XAF', // 'XAF' | 'XOF' | 'KES' | 'GHS' | 'USD'
94
+ title: 'Commande #1042',
95
+ customerName: 'Jean Dupont',
96
+ metadata: { orderId: 'ord_1042' },
97
+ });
98
+
99
+ console.log('Transaction started:', payment.transactionId);
100
+
101
+ // Option A: Check status on demand
102
+ const status = await flit.payments.getStatus(payment.transactionId);
103
+
104
+ // Option B: Poll until user enters PIN and payment completes
105
+ const finalResult = await flit.payments.waitForStatus(payment.transactionId, {
106
+ timeoutMs: 60000, // wait up to 1 minute
107
+ intervalMs: 3000, // check every 3 seconds
108
+ });
109
+
110
+ if (finalResult.status === 'SUCCESS') {
111
+ console.log('Payment completed successfully!');
112
+ }
113
+ ```
114
+
115
+ ### 4. User Authentication
116
+
117
+ ```typescript
118
+ // Register a new customer
119
+ const { user, session } = await flit.auth.signUp({
120
+ email: 'client@example.com',
121
+ password: 'SecurePassword123!',
122
+ name: 'Moussa Diop',
123
+ phone: '+221770000000',
124
+ });
125
+
126
+ // Sign in
127
+ await flit.auth.signInWithPassword({
128
+ email: 'client@example.com',
129
+ password: 'SecurePassword123!',
130
+ });
131
+
132
+ // Get current session
133
+ const currentUser = flit.auth.getUser();
134
+ ```
135
+
136
+ ### 5. Secure Session Management with Encrypted HttpOnly Cookies
137
+
138
+ To protect against XSS (Cross-Site Scripting) and CSRF attacks, Flit SDK provides native server-side helpers for **AES-256-GCM encrypted `HttpOnly` cookies**:
139
+
140
+ ```typescript
141
+ // In a Next.js 15 Route Handler, Server Action, or Node.js server:
142
+
143
+ // 1. Create an encrypted HttpOnly Set-Cookie header upon login
144
+ const setCookieHeader = await flit.auth.createSessionCookie(session);
145
+ // Response header: flit_session=<aes-256-gcm-cipher>; Path=/; HttpOnly; Secure; SameSite=Lax
146
+
147
+ // 2. Decrypt and verify session on incoming requests
148
+ const sessionPayload = await flit.auth.verifySessionCookie(req.headers.get('cookie'));
149
+ if (sessionPayload) {
150
+ console.log('Authenticated user:', sessionPayload.userId);
151
+ }
152
+
153
+ // 3. Destroy cookie upon logout
154
+ const clearHeader = flit.auth.clearSessionCookie();
155
+ ```
156
+
157
+ In browser environments, the client automatically configures `credentials: 'include'` on all requests, so `HttpOnly` cookies are forwarded transparently without ever exposing tokens to `document.cookie` or `localStorage`.
158
+
159
+ ---
160
+
161
+ ## Deployment & VPS Hosting
162
+
163
+ When exporting your application from Flit to your personal VPS or GitHub:
164
+
165
+ 1. Add your credentials to `.env`:
166
+ ```env
167
+ NEXT_PUBLIC_FLIT_APP_ID="your-application-uuid"
168
+ NEXT_PUBLIC_FLIT_API_KEY="flit_pk_live_your_public_key"
169
+ ```
170
+ 2. Run your project natively with `npm run dev` or `docker compose up -d`.
171
+ 3. Your data and payment processing remain active without needing to configure or maintain your own PostgreSQL server.
172
+
173
+ ---
174
+
175
+ ## License
176
+
177
+ MIT © [Flit Platform](https://flit.site)