@communecter/cocolight-api-client 1.0.0 → 1.0.1
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
CHANGED
|
@@ -46,6 +46,36 @@ import ApiClient from "@communecter/cocolight-api-client";
|
|
|
46
46
|
const { default: ApiClient } = require("@communecter/cocolight-api-client");
|
|
47
47
|
```
|
|
48
48
|
|
|
49
|
+
### 🔗 Intégration via CDN
|
|
50
|
+
|
|
51
|
+
Vous pouvez inclure le client directement dans une page HTML :
|
|
52
|
+
|
|
53
|
+
```html
|
|
54
|
+
<script src="https://cdn.jsdelivr.net/npm/@communecter/cocolight-api-client/dist/cocolight-api-client.browser.js"></script>
|
|
55
|
+
<script>
|
|
56
|
+
const client = new CocolightApiClient({
|
|
57
|
+
baseURL: "https://www.communecter.org"
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
client.callEndpoint("AUTHENTICATE_URL", {
|
|
61
|
+
email: "EMAIL",
|
|
62
|
+
password: "PASSWORD"
|
|
63
|
+
}).then(res => {
|
|
64
|
+
const { accessToken, refreshToken, user } = res.data;
|
|
65
|
+
console.log("✅ Authentifié :", user.username);
|
|
66
|
+
})
|
|
67
|
+
.then(() => {
|
|
68
|
+
return client.callEndpoint("ME_INFO_URL");
|
|
69
|
+
})
|
|
70
|
+
.then(res => {
|
|
71
|
+
console.log("👤 Profil utilisateur :", res.data);
|
|
72
|
+
})
|
|
73
|
+
.then(() => {
|
|
74
|
+
console.log("userId :", client.userId);
|
|
75
|
+
})
|
|
76
|
+
.catch(err => console.error("Erreur :", err));
|
|
77
|
+
</script>
|
|
78
|
+
```
|
|
49
79
|
|
|
50
80
|
## 🔧 Utilisation de base
|
|
51
81
|
|
|
@@ -53,20 +83,29 @@ const { default: ApiClient } = require("@communecter/cocolight-api-client");
|
|
|
53
83
|
import ApiClient from "@communecter/cocolight-api-client";
|
|
54
84
|
|
|
55
85
|
const client = new ApiClient({
|
|
56
|
-
baseURL: "https://mon-api.com"
|
|
57
|
-
accessToken: "token-jwt",
|
|
58
|
-
refreshToken: "token-refresh"
|
|
86
|
+
baseURL: "https://mon-api.com"
|
|
59
87
|
});
|
|
60
88
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
89
|
+
try {
|
|
90
|
+
const authResponse = await client.callEndpoint("AUTHENTICATE_URL", {
|
|
91
|
+
email: "EMAIL",
|
|
92
|
+
password: "PASSWORD"
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
const { accessToken, refreshToken, user } = authResponse.data;
|
|
96
|
+
|
|
97
|
+
console.log("✅ Authentifié :", user.username);
|
|
98
|
+
|
|
99
|
+
const meResponse = await client.callEndpoint("ME_INFO_URL");
|
|
100
|
+
|
|
101
|
+
console.log("👤 Profil utilisateur :", meResponse.data);
|
|
102
|
+
|
|
103
|
+
console.log("userId :", client.userId);
|
|
104
|
+
} catch (error) {
|
|
105
|
+
console.error("❌ Erreur durant la session :", error.message, error.details);
|
|
106
|
+
}
|
|
64
107
|
|
|
65
|
-
const res = await client.callEndpoint("GET_USER_INFO", {
|
|
66
|
-
pathParams: { userId: "@userId" }
|
|
67
|
-
});
|
|
68
108
|
|
|
69
|
-
console.log(res.data);
|
|
70
109
|
```
|
|
71
110
|
|
|
72
111
|
## 📜 API détaillée
|