sunuid-sdk 1.0.51 → 1.0.52

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,187 @@
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
+ <Files "secure-init.php">
13
+ Order Allow,Deny
14
+ Deny from all
15
+ </Files>
16
+
17
+ <Files "*.log">
18
+ Order Allow,Deny
19
+ Deny from all
20
+ </Files>
21
+
22
+ # Protection des fichiers de développement
23
+ <Files "composer.json">
24
+ Order Allow,Deny
25
+ Deny from all
26
+ </Files>
27
+
28
+ <Files "composer.lock">
29
+ Order Allow,Deny
30
+ Deny from all
31
+ </Files>
32
+
33
+ <Files "package.json">
34
+ Order Allow,Deny
35
+ Deny from all
36
+ </Files>
37
+
38
+ <Files "package-lock.json">
39
+ Order Allow,Deny
40
+ Deny from all
41
+ </Files>
42
+
43
+ # Protection des fichiers de documentation
44
+ <Files "README.md">
45
+ Order Allow,Deny
46
+ Deny from all
47
+ </Files>
48
+
49
+ <Files "*.md">
50
+ Order Allow,Deny
51
+ Deny from all
52
+ </Files>
53
+
54
+ # Protection des fichiers de test
55
+ <Files "phpunit.xml">
56
+ Order Allow,Deny
57
+ Deny from all
58
+ </Files>
59
+
60
+ <Files "tests/*">
61
+ Order Allow,Deny
62
+ Deny from all
63
+ </Files>
64
+
65
+ # Protection des fichiers de source
66
+ <Files "src/*.php">
67
+ Order Allow,Deny
68
+ Deny from all
69
+ </Files>
70
+
71
+ # Autoriser uniquement les fichiers nécessaires
72
+ <Files "*.html">
73
+ Order Allow,Deny
74
+ Allow from all
75
+ </Files>
76
+
77
+ <Files "*.js">
78
+ Order Allow,Deny
79
+ Allow from all
80
+ </Files>
81
+
82
+ <Files "*.css">
83
+ Order Allow,Deny
84
+ Allow from all
85
+ </Files>
86
+
87
+ <Files "*.png">
88
+ Order Allow,Deny
89
+ Allow from all
90
+ </Files>
91
+
92
+ <Files "*.jpg">
93
+ Order Allow,Deny
94
+ Allow from all
95
+ </Files>
96
+
97
+ <Files "*.svg">
98
+ Order Allow,Deny
99
+ Allow from all
100
+ </Files>
101
+
102
+ # Configuration de sécurité générale
103
+ # Désactiver l'affichage du contenu des répertoires
104
+ Options -Indexes
105
+
106
+ # Masquer les informations du serveur
107
+ ServerTokens Prod
108
+ ServerSignature Off
109
+
110
+ # Protection contre les attaques XSS
111
+ <IfModule mod_headers.c>
112
+ Header always set X-Content-Type-Options nosniff
113
+ Header always set X-Frame-Options DENY
114
+ Header always set X-XSS-Protection "1; mode=block"
115
+ Header always set Referrer-Policy "strict-origin-when-cross-origin"
116
+ </IfModule>
117
+
118
+ # Protection contre les injections de fichiers
119
+ <FilesMatch "\.(php|php3|php4|php5|phtml|pl|py|jsp|asp|sh|cgi)$">
120
+ Order Deny,Allow
121
+ Deny from all
122
+ </FilesMatch>
123
+
124
+ # Autoriser uniquement les fichiers PHP spécifiques
125
+ <Files "secure-init.php">
126
+ Order Allow,Deny
127
+ Allow from all
128
+ </Files>
129
+
130
+ # Protection contre les accès aux fichiers cachés
131
+ <FilesMatch "^\.">
132
+ Order Allow,Deny
133
+ Deny from all
134
+ </FilesMatch>
135
+
136
+ # Protection contre les accès aux fichiers de sauvegarde
137
+ <FilesMatch "\.(bak|backup|old|tmp|temp)$">
138
+ Order Allow,Deny
139
+ Deny from all
140
+ </FilesMatch>
141
+
142
+ # ========================================
143
+ # CONFIGURATION CORS (si nécessaire)
144
+ # ========================================
145
+
146
+ # Autoriser les requêtes CORS pour l'API
147
+ <IfModule mod_headers.c>
148
+ <Files "secure-init.php">
149
+ Header always set Access-Control-Allow-Origin "*"
150
+ Header always set Access-Control-Allow-Methods "POST, GET, OPTIONS"
151
+ Header always set Access-Control-Allow-Headers "Content-Type, Authorization"
152
+ </Files>
153
+ </IfModule>
154
+
155
+ # Gestion des requêtes OPTIONS (preflight)
156
+ <IfModule mod_rewrite.c>
157
+ RewriteEngine On
158
+ RewriteCond %{REQUEST_METHOD} OPTIONS
159
+ RewriteRule ^(.*)$ $1 [R=200,L]
160
+ </IfModule>
161
+
162
+ # ========================================
163
+ # INSTRUCTIONS D'UTILISATION
164
+ # ========================================
165
+
166
+ # 1. Copiez ce fichier vers .htaccess
167
+ # cp .htaccess.example .htaccess
168
+
169
+ # 2. Ajustez les permissions selon vos besoins
170
+ # - Autorisez l'accès aux fichiers nécessaires
171
+ # - Protégez les fichiers sensibles
172
+ # - Configurez CORS si nécessaire
173
+
174
+ # 3. Testez la configuration
175
+ # - Vérifiez que les fichiers sensibles sont protégés
176
+ # - Vérifiez que les fichiers publics sont accessibles
177
+ # - Testez les requêtes CORS si nécessaire
178
+
179
+ # ========================================
180
+ # SÉCURITÉ
181
+ # ========================================
182
+
183
+ # ⚠️ IMPORTANT : Testez toujours la configuration avant la mise en production
184
+ # ⚠️ IMPORTANT : Vérifiez que les fichiers nécessaires sont accessibles
185
+ # ⚠️ IMPORTANT : Surveillez les logs d'erreur après déploiement
186
+ # ⚠️ IMPORTANT : Ajustez les permissions selon votre architecture
187
+
@@ -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
+ }