sunuid-sdk 1.0.51 → 1.0.53

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.
@@ -0,0 +1,190 @@
1
+ # ========================================
2
+ # PROTECTION DES FICHIERS SENSIBLES
3
+ # ========================================
4
+ # Copiez ce fichier vers .htaccess à la racine de votre projet
5
+
6
+ # Protection des fichiers de configuration sensibles
7
+ <Files ".env">
8
+ Order Allow,Deny
9
+ Deny from all
10
+ </Files>
11
+
12
+ # Note: secure-init.php doit être accessible pour l'initialisation sécurisée
13
+ # mais protégez-le avec une authentification appropriée en production
14
+ <Files "secure-init.php">
15
+ # En production, utilisez une authentification appropriée
16
+ # Order Allow,Deny
17
+ # Deny from all
18
+ </Files>
19
+
20
+ <Files "*.log">
21
+ Order Allow,Deny
22
+ Deny from all
23
+ </Files>
24
+
25
+ # Protection des fichiers de développement
26
+ <Files "package.json">
27
+ Order Allow,Deny
28
+ Deny from all
29
+ </Files>
30
+
31
+ <Files "package-lock.json">
32
+ Order Allow,Deny
33
+ Deny from all
34
+ </Files>
35
+
36
+ <Files "package.json">
37
+ Order Allow,Deny
38
+ Deny from all
39
+ </Files>
40
+
41
+ <Files "package-lock.json">
42
+ Order Allow,Deny
43
+ Deny from all
44
+ </Files>
45
+
46
+ # Protection des fichiers de documentation
47
+ <Files "README.md">
48
+ Order Allow,Deny
49
+ Deny from all
50
+ </Files>
51
+
52
+ <Files "*.md">
53
+ Order Allow,Deny
54
+ Deny from all
55
+ </Files>
56
+
57
+ # Protection des fichiers de test
58
+ <Files "*.test.js">
59
+ Order Allow,Deny
60
+ Deny from all
61
+ </Files>
62
+
63
+ <Files "tests/*">
64
+ Order Allow,Deny
65
+ Deny from all
66
+ </Files>
67
+
68
+ # Protection des fichiers de source
69
+ <Files "src/*.js">
70
+ Order Allow,Deny
71
+ Deny from all
72
+ </Files>
73
+
74
+ # Autoriser uniquement les fichiers nécessaires
75
+ <Files "*.html">
76
+ Order Allow,Deny
77
+ Allow from all
78
+ </Files>
79
+
80
+ <Files "*.js">
81
+ Order Allow,Deny
82
+ Allow from all
83
+ </Files>
84
+
85
+ <Files "*.css">
86
+ Order Allow,Deny
87
+ Allow from all
88
+ </Files>
89
+
90
+ <Files "*.png">
91
+ Order Allow,Deny
92
+ Allow from all
93
+ </Files>
94
+
95
+ <Files "*.jpg">
96
+ Order Allow,Deny
97
+ Allow from all
98
+ </Files>
99
+
100
+ <Files "*.svg">
101
+ Order Allow,Deny
102
+ Allow from all
103
+ </Files>
104
+
105
+ # Configuration de sécurité générale
106
+ # Désactiver l'affichage du contenu des répertoires
107
+ Options -Indexes
108
+
109
+ # Masquer les informations du serveur
110
+ ServerTokens Prod
111
+ ServerSignature Off
112
+
113
+ # Protection contre les attaques XSS
114
+ <IfModule mod_headers.c>
115
+ Header always set X-Content-Type-Options nosniff
116
+ Header always set X-Frame-Options DENY
117
+ Header always set X-XSS-Protection "1; mode=block"
118
+ Header always set Referrer-Policy "strict-origin-when-cross-origin"
119
+ </IfModule>
120
+
121
+ # Protection contre les injections de fichiers
122
+ <FilesMatch "\.(php|php3|php4|php5|phtml|pl|py|jsp|asp|sh|cgi)$">
123
+ Order Deny,Allow
124
+ Deny from all
125
+ </FilesMatch>
126
+
127
+ # Autoriser uniquement les fichiers PHP spécifiques
128
+ <Files "secure-init.php">
129
+ Order Allow,Deny
130
+ Allow from all
131
+ </Files>
132
+
133
+ # Protection contre les accès aux fichiers cachés
134
+ <FilesMatch "^\.">
135
+ Order Allow,Deny
136
+ Deny from all
137
+ </FilesMatch>
138
+
139
+ # Protection contre les accès aux fichiers de sauvegarde
140
+ <FilesMatch "\.(bak|backup|old|tmp|temp)$">
141
+ Order Allow,Deny
142
+ Deny from all
143
+ </FilesMatch>
144
+
145
+ # ========================================
146
+ # CONFIGURATION CORS (si nécessaire)
147
+ # ========================================
148
+
149
+ # Autoriser les requêtes CORS pour l'API
150
+ <IfModule mod_headers.c>
151
+ <Files "secure-init.php">
152
+ Header always set Access-Control-Allow-Origin "*"
153
+ Header always set Access-Control-Allow-Methods "POST, GET, OPTIONS"
154
+ Header always set Access-Control-Allow-Headers "Content-Type, Authorization"
155
+ </Files>
156
+ </IfModule>
157
+
158
+ # Gestion des requêtes OPTIONS (preflight)
159
+ <IfModule mod_rewrite.c>
160
+ RewriteEngine On
161
+ RewriteCond %{REQUEST_METHOD} OPTIONS
162
+ RewriteRule ^(.*)$ $1 [R=200,L]
163
+ </IfModule>
164
+
165
+ # ========================================
166
+ # INSTRUCTIONS D'UTILISATION
167
+ # ========================================
168
+
169
+ # 1. Copiez ce fichier vers .htaccess
170
+ # cp .htaccess.example .htaccess
171
+
172
+ # 2. Ajustez les permissions selon vos besoins
173
+ # - Autorisez l'accès aux fichiers nécessaires
174
+ # - Protégez les fichiers sensibles
175
+ # - Configurez CORS si nécessaire
176
+
177
+ # 3. Testez la configuration
178
+ # - Vérifiez que les fichiers sensibles sont protégés
179
+ # - Vérifiez que les fichiers publics sont accessibles
180
+ # - Testez les requêtes CORS si nécessaire
181
+
182
+ # ========================================
183
+ # SÉCURITÉ
184
+ # ========================================
185
+
186
+ # ⚠️ IMPORTANT : Testez toujours la configuration avant la mise en production
187
+ # ⚠️ IMPORTANT : Vérifiez que les fichiers nécessaires sont accessibles
188
+ # ⚠️ IMPORTANT : Surveillez les logs d'erreur après déploiement
189
+ # ⚠️ IMPORTANT : Ajustez les permissions selon votre architecture
190
+
@@ -0,0 +1,192 @@
1
+ # 🚀 Intégration Minimale SunuID SDK
2
+
3
+ Exemples de code minimal pour intégrer le SDK SunuID dans votre application.
4
+
5
+ ## 📁 Fichiers disponibles
6
+
7
+ - **`minimal-integration.html`** - Exemple complet avec interface utilisateur
8
+ - **`minimal-code.js`** - Code JavaScript minimal avec différents exemples
9
+ - **`auto-integration.html`** - **🚀 Initialisation et génération automatique** (Recommandé)
10
+ - **`auto-code.js`** - Code JavaScript pour l'initialisation automatique
11
+
12
+ ## 🎯 Code minimal (3 lignes)
13
+
14
+ ```javascript
15
+ const sunuid = new SunuID({
16
+ clientId: 'your-client-id',
17
+ secretId: 'your-secret-id',
18
+ type: 2
19
+ });
20
+
21
+ await sunuid.init();
22
+ const result = await sunuid.generateQR('qr-container');
23
+ ```
24
+
25
+ ## 🚀 Code automatique (0 ligne de code manuel)
26
+
27
+ ```javascript
28
+ // Initialisation automatique au chargement de la page
29
+ document.addEventListener('DOMContentLoaded', function() {
30
+ const sunuid = new SunuID(config);
31
+ sunuid.init().then(() => sunuid.generateQR('qr-container'));
32
+ });
33
+ ```
34
+
35
+ ## 📋 Prérequis
36
+
37
+ ### 1. Inclure les scripts
38
+ ```html
39
+ <!-- Socket.IO (requis) -->
40
+ <script src="https://cdn.socket.io/4.7.4/socket.io.min.js"></script>
41
+
42
+ <!-- SunuID SDK -->
43
+ <script src="https://unpkg.com/sunuid-sdk@1.0.34/dist/sunuid-sdk.min.js"></script>
44
+ ```
45
+
46
+ ### 2. Conteneur HTML
47
+ ```html
48
+ <div id="qr-container">
49
+ <!-- Le QR code sera affiché ici -->
50
+ </div>
51
+ ```
52
+
53
+ ## 🔧 Configuration minimale
54
+
55
+ ```javascript
56
+ const config = {
57
+ clientId: '1754166754_221A57B46843D755',
58
+ secretId: '56d40fe70507228b27f2640ae65894177c2fedbf246e2b30978fde1fc43953c5',
59
+ type: 2, // 1=KYC, 2=AUTH, 3=SIGNATURE
60
+ autoRefresh: false // Désactivé pour éviter les appels répétitifs
61
+ };
62
+ ```
63
+
64
+ ## 📱 Types de services
65
+
66
+ | Type | Description | Utilisation |
67
+ |------|-------------|-------------|
68
+ | `1` | **KYC** | Vérification d'identité |
69
+ | `2` | **AUTH** | Authentification (défaut) |
70
+ | `3` | **SIGNATURE** | Signature électronique |
71
+
72
+ ## 🚀 Exemples d'utilisation
73
+
74
+ ### Exemple 1 : Intégration automatique (Recommandé)
75
+ ```javascript
76
+ // Initialisation automatique au chargement de la page
77
+ document.addEventListener('DOMContentLoaded', function() {
78
+ const sunuid = new SunuID(config);
79
+ sunuid.init().then(() => sunuid.generateQR('qr-container'));
80
+ });
81
+ ```
82
+
83
+ ### Exemple 2 : Intégration basique
84
+ ```javascript
85
+ async function initSunuID() {
86
+ const sunuid = new SunuID(config);
87
+ await sunuid.init();
88
+ return await sunuid.generateQR('qr-container');
89
+ }
90
+
91
+ // Utilisation
92
+ initSunuID().then(result => console.log('QR généré:', result));
93
+ ```
94
+
95
+ ### Exemple 3 : Avec gestion d'événements
96
+ ```javascript
97
+ const sunuid = new SunuID({
98
+ ...config,
99
+ onSuccess: (data) => console.log('🎉 Succès:', data),
100
+ onError: (error) => console.error('💥 Erreur:', error),
101
+ onStatusUpdate: (status) => console.log('📊 Statut:', status)
102
+ });
103
+ ```
104
+
105
+ ### Exemple 4 : Avec rafraîchissement automatique
106
+ ```javascript
107
+ const sunuid = new SunuID({
108
+ ...config,
109
+ autoRefresh: true,
110
+ refreshInterval: 30000 // 30 secondes
111
+ });
112
+ ```
113
+
114
+ ### Exemple 5 : Avec gestion d'erreurs avancée
115
+ ```javascript
116
+ async function initWithRetry() {
117
+ let retryCount = 0;
118
+ const maxRetries = 3;
119
+
120
+ while (retryCount < maxRetries) {
121
+ try {
122
+ const sunuid = new SunuID(config);
123
+ await sunuid.init();
124
+ return await sunuid.generateQR('qr-container');
125
+ } catch (error) {
126
+ retryCount++;
127
+ if (retryCount >= maxRetries) throw error;
128
+ await new Promise(resolve => setTimeout(resolve, 2000));
129
+ }
130
+ }
131
+ }
132
+ ```
133
+
134
+ ## 🧪 Test rapide
135
+
136
+ ### Test manuel
137
+ 1. Ouvrir `minimal-integration.html` dans votre navigateur
138
+ 2. Cliquer sur "Initialiser SDK"
139
+ 3. Cliquer sur "Générer QR Code"
140
+ 4. Vérifier la console pour les logs
141
+
142
+ ### Test automatique (Recommandé)
143
+ 1. Ouvrir `auto-integration.html` dans votre navigateur
144
+ 2. Le QR code se génère automatiquement
145
+ 3. Aucune action manuelle requise
146
+ 4. Interface moderne avec animations
147
+
148
+ ## 🔍 Dépannage
149
+
150
+ ### Erreur : "SDK non initialisé"
151
+ ```javascript
152
+ // Assurez-vous d'attendre l'initialisation
153
+ await sunuid.init();
154
+ ```
155
+
156
+ ### Erreur : "Socket.IO non chargé"
157
+ ```html
158
+ <!-- Vérifiez que Socket.IO est inclus avant le SDK -->
159
+ <script src="https://cdn.socket.io/4.7.4/socket.io.min.js"></script>
160
+ <script src="https://unpkg.com/sunuid-sdk@1.0.34/dist/sunuid-sdk.min.js"></script>
161
+ ```
162
+
163
+ ### Appels répétitifs à l'API
164
+ ```javascript
165
+ // Désactivez le rafraîchissement automatique
166
+ const config = {
167
+ autoRefresh: false,
168
+ // ... autres options
169
+ };
170
+ ```
171
+
172
+ ## 📊 Résultat attendu
173
+
174
+ Après une intégration réussie, vous devriez voir :
175
+ - ✅ Un QR code affiché dans le conteneur
176
+ - ✅ Des logs dans la console confirmant la génération
177
+ - ✅ Un objet `result` avec l'URL du QR code
178
+
179
+ ## 🔗 Liens utiles
180
+
181
+ - **Documentation complète** : [README.md](../README.md)
182
+ - **Changelog** : [CHANGELOG.md](../CHANGELOG.md)
183
+ - **Page de test avancée** : [test-sdk-simple.html](../test-sdk-simple.html)
184
+
185
+ ---
186
+
187
+ **Intégration en 3 étapes :**
188
+ 1. Inclure les scripts
189
+ 2. Créer le conteneur HTML
190
+ 3. Initialiser et générer le QR code
191
+
192
+ C'est tout ! 🎉
@@ -0,0 +1,234 @@
1
+ // ========================================
2
+ // INTÉGRATION AUTOMATIQUE SUNUID SDK
3
+ // ========================================
4
+
5
+ // 1. INCLUSION DES SCRIPTS (dans le HTML)
6
+ /*
7
+ <script src="https://cdn.socket.io/4.7.4/socket.io.min.js"></script>
8
+ <script src="https://unpkg.com/sunuid-sdk@1.0.34/dist/sunuid-sdk.min.js"></script>
9
+ */
10
+
11
+ // 2. CONFIGURATION AUTOMATIQUE
12
+ const autoConfig = {
13
+ clientId: '1754166754_221A57B46843D755',
14
+ secretId: '56d40fe70507228b27f2640ae65894177c2fedbf246e2b30978fde1fc43953c5',
15
+ type: 2, // 1=KYC, 2=AUTH, 3=SIGNATURE
16
+ autoRefresh: false, // Désactivé pour éviter les appels répétitifs
17
+ // Callbacks automatiques
18
+ onSuccess: (data) => console.log('🎉 Succès:', data),
19
+ onError: (error) => console.error('💥 Erreur:', error),
20
+ onStatusUpdate: (status) => console.log('📊 Statut:', status)
21
+ };
22
+
23
+ // 3. CODE D'INITIALISATION AUTOMATIQUE
24
+ async function initAutoSunuID() {
25
+ try {
26
+ console.log('🚀 Initialisation automatique...');
27
+
28
+ // Créer l'instance SDK
29
+ const sunuid = new SunuID(autoConfig);
30
+
31
+ // Initialiser automatiquement
32
+ await sunuid.init();
33
+
34
+ // Générer le QR code automatiquement
35
+ const result = await sunuid.generateQR('qr-container');
36
+
37
+ console.log('✅ QR Code généré automatiquement:', result);
38
+ return result;
39
+
40
+ } catch (error) {
41
+ console.error('❌ Erreur d\'initialisation automatique:', error);
42
+ throw error;
43
+ }
44
+ }
45
+
46
+ // 4. INITIALISATION AUTOMATIQUE AU CHARGEMENT
47
+ document.addEventListener('DOMContentLoaded', function() {
48
+ console.log('🚀 Démarrage automatique...');
49
+
50
+ // Attendre que tout soit chargé
51
+ setTimeout(() => {
52
+ initAutoSunuID().catch(error => {
53
+ console.error('❌ Échec de l\'initialisation automatique:', error);
54
+ });
55
+ }, 500);
56
+ });
57
+
58
+ // ========================================
59
+ // VERSION AVEC GESTION D'ÉTAT
60
+ // ========================================
61
+
62
+ let sunuidInstance = null;
63
+
64
+ async function initAutoSunuIDWithState() {
65
+ if (sunuidInstance) {
66
+ console.log('SDK déjà initialisé');
67
+ return sunuidInstance;
68
+ }
69
+
70
+ try {
71
+ sunuidInstance = new SunuID(autoConfig);
72
+ await sunuidInstance.init();
73
+
74
+ const result = await sunuidInstance.generateQR('qr-container');
75
+ console.log('✅ QR Code généré:', result);
76
+
77
+ return sunuidInstance;
78
+
79
+ } catch (error) {
80
+ sunuidInstance = null;
81
+ throw error;
82
+ }
83
+ }
84
+
85
+ // ========================================
86
+ // VERSION AVEC ÉVÉNEMENTS WEBSOCKET
87
+ // ========================================
88
+
89
+ async function initAutoSunuIDWithEvents() {
90
+ const sunuid = new SunuID({
91
+ ...autoConfig,
92
+ onSuccess: (data) => {
93
+ console.log('🎉 Authentification réussie:', data);
94
+ // Rediriger ou afficher un message de succès
95
+ },
96
+ onError: (error) => {
97
+ console.error('💥 Erreur d\'authentification:', error);
98
+ // Afficher un message d'erreur
99
+ }
100
+ });
101
+
102
+ await sunuid.init();
103
+ const result = await sunuid.generateQR('qr-container');
104
+
105
+ // Écouter les événements WebSocket
106
+ if (sunuid.socket) {
107
+ sunuid.socket.on('qr_scanned', (data) => {
108
+ console.log('📱 QR code scanné:', data);
109
+ });
110
+
111
+ sunuid.socket.on('auth_success', (data) => {
112
+ console.log('🎉 Authentification réussie:', data);
113
+ });
114
+
115
+ sunuid.socket.on('auth_error', (data) => {
116
+ console.error('❌ Erreur d\'authentification:', data);
117
+ });
118
+ }
119
+
120
+ return result;
121
+ }
122
+
123
+ // ========================================
124
+ // VERSION AVEC RAFRAÎCHISSEMENT AUTOMATIQUE
125
+ // ========================================
126
+
127
+ async function initAutoSunuIDWithRefresh() {
128
+ const sunuid = new SunuID({
129
+ ...autoConfig,
130
+ autoRefresh: true, // Activer le rafraîchissement
131
+ refreshInterval: 30000 // 30 secondes
132
+ });
133
+
134
+ await sunuid.init();
135
+ const result = await sunuid.generateQR('qr-container');
136
+
137
+ // Arrêter le rafraîchissement après 2 minutes
138
+ setTimeout(() => {
139
+ sunuid.stopAutoRefresh();
140
+ console.log('🔄 Rafraîchissement arrêté');
141
+ }, 120000);
142
+
143
+ return result;
144
+ }
145
+
146
+ // ========================================
147
+ // VERSION AVEC GESTION D'ERREURS AVANCÉE
148
+ // ========================================
149
+
150
+ async function initAutoSunuIDWithErrorHandling() {
151
+ let retryCount = 0;
152
+ const maxRetries = 3;
153
+
154
+ while (retryCount < maxRetries) {
155
+ try {
156
+ console.log(`🔄 Tentative ${retryCount + 1}/${maxRetries}`);
157
+
158
+ const sunuid = new SunuID(autoConfig);
159
+ await sunuid.init();
160
+ const result = await sunuid.generateQR('qr-container');
161
+
162
+ console.log('✅ QR Code généré avec succès');
163
+ return result;
164
+
165
+ } catch (error) {
166
+ retryCount++;
167
+ console.error(`❌ Tentative ${retryCount} échouée:`, error.message);
168
+
169
+ if (retryCount >= maxRetries) {
170
+ console.error('❌ Nombre maximum de tentatives atteint');
171
+ throw new Error('Impossible d\'initialiser le SDK après plusieurs tentatives');
172
+ }
173
+
174
+ // Attendre avant de réessayer
175
+ await new Promise(resolve => setTimeout(resolve, 2000 * retryCount));
176
+ }
177
+ }
178
+ }
179
+
180
+ // ========================================
181
+ // VERSION AVEC DIFFÉRENTS TYPES
182
+ // ========================================
183
+
184
+ // Authentification automatique
185
+ async function initAuthAuto() {
186
+ const config = { ...autoConfig, type: 2 };
187
+ const sunuid = new SunuID(config);
188
+ await sunuid.init();
189
+ return await sunuid.generateQR('qr-container');
190
+ }
191
+
192
+ // KYC automatique
193
+ async function initKYCAuto() {
194
+ const config = { ...autoConfig, type: 1 };
195
+ const sunuid = new SunuID(config);
196
+ await sunuid.init();
197
+ return await sunuid.generateQR('qr-container');
198
+ }
199
+
200
+ // Signature automatique
201
+ async function initSignatureAuto() {
202
+ const config = { ...autoConfig, type: 3 };
203
+ const sunuid = new SunuID(config);
204
+ await sunuid.init();
205
+ return await sunuid.generateQR('qr-container');
206
+ }
207
+
208
+ // ========================================
209
+ // HTML MINIMAL REQUIS
210
+ // ========================================
211
+
212
+ /*
213
+ <div id="qr-container">
214
+ <!-- Le QR code sera affiché ici automatiquement -->
215
+ </div>
216
+ */
217
+
218
+ // ========================================
219
+ // EXPORT POUR UTILISATION MODULE
220
+ // ========================================
221
+
222
+ if (typeof module !== 'undefined' && module.exports) {
223
+ module.exports = {
224
+ initAutoSunuID,
225
+ initAutoSunuIDWithState,
226
+ initAutoSunuIDWithEvents,
227
+ initAutoSunuIDWithRefresh,
228
+ initAutoSunuIDWithErrorHandling,
229
+ initAuthAuto,
230
+ initKYCAuto,
231
+ initSignatureAuto,
232
+ autoConfig
233
+ };
234
+ }