bypilot-business-signup-sdk 0.1.0-beta.1 → 0.1.0-beta.7
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 +198 -0
- package/README.tr.md +198 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
# ByPilot Business Signup SDK
|
|
2
|
+
|
|
3
|
+
**[🇹🇷 Türkçe](README.tr.md) | 🇺🇸 English**
|
|
4
|
+
|
|
5
|
+
OAuth and Embedded Signup SDK for business accounts (WhatsApp, Instagram, Facebook, etc.)
|
|
6
|
+
|
|
7
|
+
## 🚀 Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install bypilot-business-signup-sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## 📝 Quick Start
|
|
14
|
+
|
|
15
|
+
### WhatsApp Provider
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { WhatsAppProvider } from "bypilot-business-signup-sdk";
|
|
19
|
+
|
|
20
|
+
// Initialize the provider
|
|
21
|
+
const whatsapp = new WhatsAppProvider({
|
|
22
|
+
clientId: "your_meta_app_id",
|
|
23
|
+
configId: "your_embedded_signup_config_id",
|
|
24
|
+
redirectUri: window.location.origin,
|
|
25
|
+
storage: "localStorage", // or 'sessionStorage'
|
|
26
|
+
graphApiVersion: "v21.0", // optional
|
|
27
|
+
sdkVersion: "v21.0", // optional
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// Login with popup
|
|
31
|
+
try {
|
|
32
|
+
const result = await whatsapp.loginWithPopup();
|
|
33
|
+
|
|
34
|
+
if (result.success) {
|
|
35
|
+
console.log("Access Token:", result.token.accessToken);
|
|
36
|
+
console.log("Session Info:", result.sessionInfo);
|
|
37
|
+
}
|
|
38
|
+
} catch (error) {
|
|
39
|
+
console.error("Login failed:", error);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Get current session
|
|
43
|
+
const token = whatsapp.getAccessToken();
|
|
44
|
+
const isAuthenticated = whatsapp.isAuthenticated();
|
|
45
|
+
|
|
46
|
+
// Logout
|
|
47
|
+
whatsapp.logout();
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## 🔧 Configuration
|
|
51
|
+
|
|
52
|
+
### WhatsApp Provider Options
|
|
53
|
+
|
|
54
|
+
| Option | Type | Required | Description |
|
|
55
|
+
| ----------------- | -------------------------------------- | -------- | --------------------------------------------- |
|
|
56
|
+
| `clientId` | string | ✅ | Your Meta App ID |
|
|
57
|
+
| `configId` | string | ✅ | Embedded Signup Configuration ID |
|
|
58
|
+
| `redirectUri` | string | ✅ | Redirect URI (must be registered in Meta App) |
|
|
59
|
+
| `storage` | `'localStorage'` \| `'sessionStorage'` | ❌ | Token storage type (default: `localStorage`) |
|
|
60
|
+
| `graphApiVersion` | string | ❌ | Graph API version (default: `v21.0`) |
|
|
61
|
+
| `sdkVersion` | string | ❌ | Facebook SDK version (default: `v21.0`) |
|
|
62
|
+
|
|
63
|
+
## 📚 API Reference
|
|
64
|
+
|
|
65
|
+
### WhatsAppProvider
|
|
66
|
+
|
|
67
|
+
#### Methods
|
|
68
|
+
|
|
69
|
+
##### `loginWithPopup(): Promise<AuthResult>`
|
|
70
|
+
|
|
71
|
+
Opens a popup for WhatsApp Business authentication.
|
|
72
|
+
|
|
73
|
+
**Returns:** Promise that resolves to an `AuthResult` object.
|
|
74
|
+
|
|
75
|
+
##### `logout(): void`
|
|
76
|
+
|
|
77
|
+
Clears stored tokens and session data.
|
|
78
|
+
|
|
79
|
+
##### `getAccessToken(): string | null`
|
|
80
|
+
|
|
81
|
+
Returns the current access token or null if not authenticated.
|
|
82
|
+
|
|
83
|
+
##### `isAuthenticated(): boolean`
|
|
84
|
+
|
|
85
|
+
Returns true if user is currently authenticated.
|
|
86
|
+
|
|
87
|
+
##### `getSessionInfoListener(callback: (info: WhatsAppSessionInfo) => void): () => void`
|
|
88
|
+
|
|
89
|
+
Listens for session information updates.
|
|
90
|
+
|
|
91
|
+
**Returns:** Unsubscribe function.
|
|
92
|
+
|
|
93
|
+
#### Events
|
|
94
|
+
|
|
95
|
+
The provider emits the following events:
|
|
96
|
+
|
|
97
|
+
- `auth:start` - Authentication process started
|
|
98
|
+
- `auth:success` - Authentication completed successfully
|
|
99
|
+
- `auth:error` - Authentication failed
|
|
100
|
+
- `auth:cancel` - User cancelled authentication
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
// Listen to events
|
|
104
|
+
const unsubscribe = whatsapp.on("auth:success", (result) => {
|
|
105
|
+
console.log("Authentication successful!", result);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
// Don't forget to unsubscribe
|
|
109
|
+
unsubscribe();
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Type Definitions
|
|
113
|
+
|
|
114
|
+
#### AuthResult
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
interface AuthResult {
|
|
118
|
+
success: boolean;
|
|
119
|
+
token?: {
|
|
120
|
+
accessToken: string;
|
|
121
|
+
expiresIn?: number;
|
|
122
|
+
};
|
|
123
|
+
sessionInfo?: WhatsAppSessionInfo;
|
|
124
|
+
error?: string;
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
#### WhatsAppSessionInfo
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
interface WhatsAppSessionInfo {
|
|
132
|
+
wabaId?: string; // WhatsApp Business Account ID
|
|
133
|
+
phoneNumberId?: string; // Phone Number ID
|
|
134
|
+
phoneNumber?: string; // Phone Number
|
|
135
|
+
businessId?: string; // Business Manager ID
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## 🏗️ Setup Guide
|
|
140
|
+
|
|
141
|
+
### 1. Create Meta App
|
|
142
|
+
|
|
143
|
+
1. Go to [Meta for Developers](https://developers.facebook.com/)
|
|
144
|
+
2. Create a new app
|
|
145
|
+
3. Add WhatsApp Business Platform product
|
|
146
|
+
|
|
147
|
+
### 2. Configure Embedded Signup
|
|
148
|
+
|
|
149
|
+
1. In your Meta app, go to WhatsApp → Configuration
|
|
150
|
+
2. Set up Embedded Signup
|
|
151
|
+
3. Add your domain to the allowlist
|
|
152
|
+
4. Get your Configuration ID
|
|
153
|
+
|
|
154
|
+
### 3. Set Redirect URI
|
|
155
|
+
|
|
156
|
+
Add your redirect URI to your Meta app settings:
|
|
157
|
+
|
|
158
|
+
- For development: `http://localhost:3000`
|
|
159
|
+
- For production: `https://yourdomain.com`
|
|
160
|
+
|
|
161
|
+
### 4. Implementation
|
|
162
|
+
|
|
163
|
+
```typescript
|
|
164
|
+
const whatsapp = new WhatsAppProvider({
|
|
165
|
+
clientId: "YOUR_META_APP_ID",
|
|
166
|
+
configId: "YOUR_CONFIG_ID",
|
|
167
|
+
redirectUri: window.location.origin,
|
|
168
|
+
});
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## 🔍 Error Handling
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
try {
|
|
175
|
+
const result = await whatsapp.loginWithPopup();
|
|
176
|
+
|
|
177
|
+
if (!result.success) {
|
|
178
|
+
console.error("Authentication failed:", result.error);
|
|
179
|
+
}
|
|
180
|
+
} catch (error) {
|
|
181
|
+
console.error("Unexpected error:", error);
|
|
182
|
+
}
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## 🎯 Browser Support
|
|
186
|
+
|
|
187
|
+
- Chrome 80+
|
|
188
|
+
- Firefox 74+
|
|
189
|
+
- Safari 13.1+
|
|
190
|
+
- Edge 80+
|
|
191
|
+
|
|
192
|
+
## 📄 License
|
|
193
|
+
|
|
194
|
+
MIT License - see [LICENSE](../LICENSE) for details.
|
|
195
|
+
|
|
196
|
+
## 🤝 Contributing
|
|
197
|
+
|
|
198
|
+
See the main [repository README](../README.md) for contribution guidelines.
|
package/README.tr.md
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
# ByPilot Business Signup SDK
|
|
2
|
+
|
|
3
|
+
**🇹🇷 Türkçe | [🇺🇸 English](README.md)**
|
|
4
|
+
|
|
5
|
+
Business hesaplar için OAuth ve Embedded Signup SDK'sı (WhatsApp, Instagram, Facebook vb.)
|
|
6
|
+
|
|
7
|
+
## 🚀 Kurulum
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install bypilot-business-signup-sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## 📝 Hızlı Başlangıç
|
|
14
|
+
|
|
15
|
+
### WhatsApp Provider
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { WhatsAppProvider } from "bypilot-business-signup-sdk";
|
|
19
|
+
|
|
20
|
+
// Provider'ı başlat
|
|
21
|
+
const whatsapp = new WhatsAppProvider({
|
|
22
|
+
clientId: "meta_app_id_niz",
|
|
23
|
+
configId: "embedded_signup_config_id_niz",
|
|
24
|
+
redirectUri: window.location.origin,
|
|
25
|
+
storage: "localStorage", // veya 'sessionStorage'
|
|
26
|
+
graphApiVersion: "v21.0", // isteğe bağlı
|
|
27
|
+
sdkVersion: "v21.0", // isteğe bağlı
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// Popup ile giriş yap
|
|
31
|
+
try {
|
|
32
|
+
const result = await whatsapp.loginWithPopup();
|
|
33
|
+
|
|
34
|
+
if (result.success) {
|
|
35
|
+
console.log("Access Token:", result.token.accessToken);
|
|
36
|
+
console.log("Session Bilgisi:", result.sessionInfo);
|
|
37
|
+
}
|
|
38
|
+
} catch (error) {
|
|
39
|
+
console.error("Giriş başarısız:", error);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Mevcut session'ı al
|
|
43
|
+
const token = whatsapp.getAccessToken();
|
|
44
|
+
const isAuthenticated = whatsapp.isAuthenticated();
|
|
45
|
+
|
|
46
|
+
// Çıkış yap
|
|
47
|
+
whatsapp.logout();
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## 🔧 Yapılandırma
|
|
51
|
+
|
|
52
|
+
### WhatsApp Provider Seçenekleri
|
|
53
|
+
|
|
54
|
+
| Seçenek | Tip | Gerekli | Açıklama |
|
|
55
|
+
| ----------------- | -------------------------------------- | ------- | ----------------------------------------------- |
|
|
56
|
+
| `clientId` | string | ✅ | Meta App ID'niz |
|
|
57
|
+
| `configId` | string | ✅ | Embedded Signup Configuration ID |
|
|
58
|
+
| `redirectUri` | string | ✅ | Yönlendirme URI'si (Meta App'te kayıtlı olmalı) |
|
|
59
|
+
| `storage` | `'localStorage'` \| `'sessionStorage'` | ❌ | Token saklama türü (varsayılan: `localStorage`) |
|
|
60
|
+
| `graphApiVersion` | string | ❌ | Graph API versiyonu (varsayılan: `v21.0`) |
|
|
61
|
+
| `sdkVersion` | string | ❌ | Facebook SDK versiyonu (varsayılan: `v21.0`) |
|
|
62
|
+
|
|
63
|
+
## 📚 API Referansı
|
|
64
|
+
|
|
65
|
+
### WhatsAppProvider
|
|
66
|
+
|
|
67
|
+
#### Metodlar
|
|
68
|
+
|
|
69
|
+
##### `loginWithPopup(): Promise<AuthResult>`
|
|
70
|
+
|
|
71
|
+
WhatsApp Business kimlik doğrulama için popup açar.
|
|
72
|
+
|
|
73
|
+
**Dönüş:** `AuthResult` nesnesine çözümlenen Promise.
|
|
74
|
+
|
|
75
|
+
##### `logout(): void`
|
|
76
|
+
|
|
77
|
+
Saklanan token'ları ve session verilerini temizler.
|
|
78
|
+
|
|
79
|
+
##### `getAccessToken(): string | null`
|
|
80
|
+
|
|
81
|
+
Mevcut access token'ı döndürür, kimlik doğrulanmamışsa null.
|
|
82
|
+
|
|
83
|
+
##### `isAuthenticated(): boolean`
|
|
84
|
+
|
|
85
|
+
Kullanıcı şu anda kimlik doğrulanmışsa true döndürür.
|
|
86
|
+
|
|
87
|
+
##### `getSessionInfoListener(callback: (info: WhatsAppSessionInfo) => void): () => void`
|
|
88
|
+
|
|
89
|
+
Session bilgisi güncellemelerini dinler.
|
|
90
|
+
|
|
91
|
+
**Dönüş:** Abonelikten çıkma fonksiyonu.
|
|
92
|
+
|
|
93
|
+
#### Olaylar
|
|
94
|
+
|
|
95
|
+
Provider şu olayları yayar:
|
|
96
|
+
|
|
97
|
+
- `auth:start` - Kimlik doğrulama süreci başlatıldı
|
|
98
|
+
- `auth:success` - Kimlik doğrulama başarıyla tamamlandı
|
|
99
|
+
- `auth:error` - Kimlik doğrulama başarısız
|
|
100
|
+
- `auth:cancel` - Kullanıcı kimlik doğrulamayı iptal etti
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
// Olayları dinle
|
|
104
|
+
const unsubscribe = whatsapp.on("auth:success", (result) => {
|
|
105
|
+
console.log("Kimlik doğrulama başarılı!", result);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
// Dinlemeyi durdurmayı unutmayın
|
|
109
|
+
unsubscribe();
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Tip Tanımlamaları
|
|
113
|
+
|
|
114
|
+
#### AuthResult
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
interface AuthResult {
|
|
118
|
+
success: boolean;
|
|
119
|
+
token?: {
|
|
120
|
+
accessToken: string;
|
|
121
|
+
expiresIn?: number;
|
|
122
|
+
};
|
|
123
|
+
sessionInfo?: WhatsAppSessionInfo;
|
|
124
|
+
error?: string;
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
#### WhatsAppSessionInfo
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
interface WhatsAppSessionInfo {
|
|
132
|
+
wabaId?: string; // WhatsApp Business Account ID
|
|
133
|
+
phoneNumberId?: string; // Telefon Numarası ID
|
|
134
|
+
phoneNumber?: string; // Telefon Numarası
|
|
135
|
+
businessId?: string; // Business Manager ID
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## 🏗️ Kurulum Rehberi
|
|
140
|
+
|
|
141
|
+
### 1. Meta App Oluştur
|
|
142
|
+
|
|
143
|
+
1. [Meta for Developers](https://developers.facebook.com/)'a git
|
|
144
|
+
2. Yeni bir app oluştur
|
|
145
|
+
3. WhatsApp Business Platform ürününü ekle
|
|
146
|
+
|
|
147
|
+
### 2. Embedded Signup Yapılandır
|
|
148
|
+
|
|
149
|
+
1. Meta app'inde WhatsApp → Configuration'a git
|
|
150
|
+
2. Embedded Signup'ı ayarla
|
|
151
|
+
3. Domain'ini allowlist'e ekle
|
|
152
|
+
4. Configuration ID'ni al
|
|
153
|
+
|
|
154
|
+
### 3. Redirect URI Ayarla
|
|
155
|
+
|
|
156
|
+
Meta app ayarlarına redirect URI'nizi ekleyin:
|
|
157
|
+
|
|
158
|
+
- Geliştirme için: `http://localhost:3000`
|
|
159
|
+
- Production için: `https://yourdomain.com`
|
|
160
|
+
|
|
161
|
+
### 4. Uygulama
|
|
162
|
+
|
|
163
|
+
```typescript
|
|
164
|
+
const whatsapp = new WhatsAppProvider({
|
|
165
|
+
clientId: "META_APP_ID_NIZ",
|
|
166
|
+
configId: "CONFIG_ID_NIZ",
|
|
167
|
+
redirectUri: window.location.origin,
|
|
168
|
+
});
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## 🔍 Hata Yönetimi
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
try {
|
|
175
|
+
const result = await whatsapp.loginWithPopup();
|
|
176
|
+
|
|
177
|
+
if (!result.success) {
|
|
178
|
+
console.error("Kimlik doğrulama başarısız:", result.error);
|
|
179
|
+
}
|
|
180
|
+
} catch (error) {
|
|
181
|
+
console.error("Beklenmeyen hata:", error);
|
|
182
|
+
}
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## 🎯 Tarayıcı Desteği
|
|
186
|
+
|
|
187
|
+
- Chrome 80+
|
|
188
|
+
- Firefox 74+
|
|
189
|
+
- Safari 13.1+
|
|
190
|
+
- Edge 80+
|
|
191
|
+
|
|
192
|
+
## 📄 Lisans
|
|
193
|
+
|
|
194
|
+
MIT License - detaylar için [LICENSE](../LICENSE) dosyasına bakın.
|
|
195
|
+
|
|
196
|
+
## 🤝 Katkıda Bulunma
|
|
197
|
+
|
|
198
|
+
Katkı rehberi için ana [repository README](../README.md) dosyasına bakın.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bypilot-business-signup-sdk",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.7",
|
|
4
4
|
"description": "Business hesaplar için OAuth ve Embedded Signup SDK'sı (WhatsApp, Instagram, Facebook vb.)",
|
|
5
5
|
"author": "",
|
|
6
6
|
"license": "MIT",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
],
|
|
59
59
|
"repository": {
|
|
60
60
|
"type": "git",
|
|
61
|
-
"url": ""
|
|
61
|
+
"url": "https://github.com/EmrullahAlku/bypilot-business-signup-sdk.git"
|
|
62
62
|
},
|
|
63
63
|
"engines": {
|
|
64
64
|
"node": ">=18.0.0"
|