@sqliteai/todoapp 1.0.5 → 1.0.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/.env.example +3 -4
- package/README.md +2 -2
- package/components/SyncContext.js +8 -4
- package/hooks/useCategories.js +6 -6
- package/package.json +1 -1
- package/plugins/CloudSyncSetup.js +1 -1
package/.env.example
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
# Copy from the
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
API_TOKEN =
|
|
1
|
+
# Copy from the OffSync page on the SQLiteCloud Dashboard
|
|
2
|
+
MANAGED_DATABASE_ID = "<your-managed-database-id>"
|
|
3
|
+
API_TOKEN =
|
package/README.md
CHANGED
|
@@ -24,10 +24,10 @@ cd MyApp
|
|
|
24
24
|
|
|
25
25
|
Rename the `.env.example` into `.env` and fill with your values.
|
|
26
26
|
|
|
27
|
-
> **⚠️ SECURITY WARNING**: This example puts database
|
|
27
|
+
> **⚠️ SECURITY WARNING**: This example puts database API Keys directly in `.env` files for demonstration purposes only. **Do not use this pattern in production.**
|
|
28
28
|
>
|
|
29
29
|
> **Why this is unsafe:**
|
|
30
|
-
> -
|
|
30
|
+
> - API Keys allow access to sensitive credentials
|
|
31
31
|
> - Client-side apps expose all environment variables to users
|
|
32
32
|
> - Anyone can inspect your app and extract database credentials
|
|
33
33
|
>
|
|
@@ -58,10 +58,14 @@ export const SyncProvider = ({ children }) => {
|
|
|
58
58
|
|
|
59
59
|
const result = await Promise.race([queryPromise, timeoutPromise]);
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
const raw = result.rows?.[0]?.['cloudsync_network_check_changes()'];
|
|
62
|
+
if (raw) {
|
|
63
|
+
const { receive } = JSON.parse(raw);
|
|
64
|
+
if (receive.rows > 0) {
|
|
65
|
+
console.log(`${receive.rows} changes detected in [${receive.tables}], triggering refresh`);
|
|
66
|
+
// Defer refresh to next tick to avoid blocking current interaction
|
|
67
|
+
setTimeout(() => triggerRefresh(), 0);
|
|
68
|
+
}
|
|
65
69
|
}
|
|
66
70
|
} catch (error) {
|
|
67
71
|
console.error('Error checking for changes:', error);
|
package/hooks/useCategories.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useState, useEffect } from 'react'
|
|
2
2
|
import { Platform } from 'react-native';
|
|
3
3
|
import { db } from "../db/dbConnection";
|
|
4
|
-
import {
|
|
4
|
+
import { MANAGED_DATABASE_ID, API_TOKEN } from "@env";
|
|
5
5
|
import { getDylibPath } from "@op-engineering/op-sqlite";
|
|
6
6
|
import { randomUUID } from 'expo-crypto';
|
|
7
7
|
import { useSyncContext } from '../components/SyncContext';
|
|
@@ -69,14 +69,14 @@ const useCategories = () => {
|
|
|
69
69
|
await db.execute(`SELECT cloudsync_init('tags');`);
|
|
70
70
|
await db.execute(`SELECT cloudsync_init('tasks_tags');`);
|
|
71
71
|
|
|
72
|
-
await db.execute('INSERT OR IGNORE INTO tags (uuid, name) VALUES (?, ?)', [
|
|
73
|
-
await db.execute('INSERT OR IGNORE INTO tags (uuid, name) VALUES (?, ?)', [
|
|
72
|
+
await db.execute('INSERT OR IGNORE INTO tags (uuid, name) VALUES (?, ?)', ['work', 'Work'])
|
|
73
|
+
await db.execute('INSERT OR IGNORE INTO tags (uuid, name) VALUES (?, ?)', ['personal', 'Personal'])
|
|
74
74
|
|
|
75
|
-
if (
|
|
76
|
-
await db.execute(`SELECT cloudsync_network_init('${
|
|
75
|
+
if (MANAGED_DATABASE_ID && API_TOKEN) {
|
|
76
|
+
await db.execute(`SELECT cloudsync_network_init('${MANAGED_DATABASE_ID}');`);
|
|
77
77
|
await db.execute(`SELECT cloudsync_network_set_token('${API_TOKEN}');`)
|
|
78
78
|
} else {
|
|
79
|
-
throw new Error('No valid
|
|
79
|
+
throw new Error('No valid MANAGED_DATABASE_ID or API_TOKEN provided, cloudsync_network_init will not be called');
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
db.execute('SELECT cloudsync_network_sync(100, 10);')
|
package/package.json
CHANGED
|
@@ -50,7 +50,7 @@ async function getLatestReleaseUrl(asset_pattern) {
|
|
|
50
50
|
return new Promise((resolve, reject) => {
|
|
51
51
|
const options = {
|
|
52
52
|
hostname: 'api.github.com',
|
|
53
|
-
path: '/repos/sqliteai/sqlite-sync
|
|
53
|
+
path: '/repos/sqliteai/sqlite-sync/releases/latest',
|
|
54
54
|
headers: {
|
|
55
55
|
'User-Agent': 'expo-cloudsync-plugin'
|
|
56
56
|
}
|