@xstbot/cloudku-s3 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.
Files changed (3) hide show
  1. package/README.md +42 -0
  2. package/index.js +41 -0
  3. package/package.json +20 -0
package/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # Cloudku SDK
2
+
3
+ Library Node.js untuk memudahkan pengiriman data ke API Cloudku.
4
+
5
+ ## Instalasi
6
+
7
+ ```bash
8
+ npm install cloudku-sdk
9
+
10
+ CARA PENGGUNAAN
11
+ const CloudkuDB = require('cloudku-sdk');
12
+ const db = new CloudkuDB();
13
+
14
+ // 1. Simpan Data User
15
+ db.postUser('dev', 'admin')
16
+ .then(res => console.log('Sukses:', res))
17
+ .catch(err => console.error(err));
18
+
19
+ // 2. Simpan Data Sensor IoT
20
+ db.postSensor('DHT22', 25.5, 'OK')
21
+ .then(res => console.log('Sukses:', res))
22
+ .catch(err => console.error(err));
23
+
24
+ ---
25
+
26
+ ### Langkah Publikasi ke NPM
27
+
28
+ 1. **Buka Terminal** di dalam folder tersebut.
29
+ 2. **Instal Dependency**: Jalankan `npm install` untuk membuat file `package-lock.json`.
30
+ 3. **Login ke NPM**:
31
+ ```bash
32
+ npm login
33
+ ```
34
+ (Masukkan username, password, dan email NPM Anda).
35
+ 4. **Publish**:
36
+ ```bash
37
+ npm publish
38
+ ```
39
+
40
+ **Tips Penting**: Jika muncul error saat publish karena nama package sudah ada yang punya, ganti bagian `"name": "cloudku-sdk"` di `package.json` dengan nama lain yang lebih spesifik, misalnya `"name": "cloudku-db-client"`.
41
+
42
+ Apakah Anda ingin saya bantu membuatkan file testing (`test.js`) untuk mencoba kodenya sebelum di-upload?
package/index.js ADDED
@@ -0,0 +1,41 @@
1
+ const axios = require('axios');
2
+
3
+ class CloudkuDB {
4
+
5
+ constructor(baseURL = 'https://db.cloudku.sbs/api/db/cloudku/sbs') {
6
+ this.api = axios.create({
7
+ baseURL: baseURL,
8
+ headers: {
9
+ 'Content-Type': 'application/json',
10
+ 'Accept': 'application/json'
11
+ }
12
+ });
13
+ }
14
+
15
+ async postUser(user, role) {
16
+ try {
17
+ const response = await this.api.post('', { user, role });
18
+ return response.data;
19
+ } catch (error) {
20
+ this._handleError(error);
21
+ }
22
+ }
23
+
24
+ async postSensor(id, temp, status) {
25
+ try {
26
+ const response = await this.api.post('', { id, temp, status });
27
+ return response.data;
28
+ } catch (error) {
29
+ this._handleError(error);
30
+ }
31
+ }
32
+
33
+ _handleError(error) {
34
+ if (error.response) {
35
+ throw new Error(`API Error: ${error.response.status} - ${JSON.stringify(error.response.data)}`);
36
+ }
37
+ throw new Error(`Network Error: ${error.message}`);
38
+ }
39
+ }
40
+
41
+ module.exports = CloudkuDB;
package/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "@xstbot/cloudku-s3",
3
+ "version": "1.0.0",
4
+ "description": "SDK S3 untuk akses Database Cloudku",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "keywords": [
10
+ "cloudku",
11
+ "database",
12
+ "iot",
13
+ "sdk"
14
+ ],
15
+ "author": "Arsyilla Official",
16
+ "license": "MIT",
17
+ "dependencies": {
18
+ "axios": "^1.13.2"
19
+ }
20
+ }