{"id":25216504,"url":"https://github.com/jrran90/vue-offline-sync","last_synced_at":"2025-10-06T05:03:47.448Z","repository":{"id":275471633,"uuid":"925186934","full_name":"jrran90/vue-offline-sync","owner":"jrran90","description":"A Vue 3 composable for offline-first syncing. Save data while offline and automatically sync it when back online. Uses IndexedDB for offline storage.","archived":false,"fork":false,"pushed_at":"2025-02-10T14:57:57.000Z","size":220,"stargazers_count":15,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-10T15:43:25.552Z","etag":null,"topics":["composable","indexeddb","offline-first","sync","vuejs"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jrran90.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-31T11:57:09.000Z","updated_at":"2025-02-10T14:57:56.000Z","dependencies_parsed_at":"2025-02-02T19:26:48.225Z","dependency_job_id":"d0d9df63-7ee6-423a-960c-01c5828084c9","html_url":"https://github.com/jrran90/vue-offline-sync","commit_stats":null,"previous_names":["jrran90/vue-offline-sync"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jrran90%2Fvue-offline-sync","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jrran90%2Fvue-offline-sync/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jrran90%2Fvue-offline-sync/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jrran90%2Fvue-offline-sync/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jrran90","download_url":"https://codeload.github.com/jrran90/vue-offline-sync/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238143191,"owners_count":19423506,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["composable","indexeddb","offline-first","sync","vuejs"],"created_at":"2025-02-10T19:18:23.962Z","updated_at":"2025-10-06T05:03:47.427Z","avatar_url":"https://github.com/jrran90.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Vue Offline Sync 🔄\n\nA **Vue 3 composable** for **offline-first syncing**. Save data while offline and automatically sync it when back\nonline.\nUses **IndexedDB** for offline storage.\n\n## 🚀 Features\n\n- Auto-sync when online\n- Custom API endpoint\n- Uses IndexedDB for offline storage\n- Bulk or individual syncing\n- Configurable retry policy for failed requests\n\n---\n\n## 📦 Installation\n\n```sh\nnpm install vue-offline-sync\n```\n\n## ⚡ Quick Start\n\n### 1️⃣ Basic Usage\n\nHere’s a basic implementation example\n\n```vue\n\n\u003cscript setup\u003e\nimport {ref} from 'vue';\n// 1. Import library\nimport {useOfflineSync} from 'vue-offline-sync';\n\nconst formData = ref({name: '', message: ''});\n\n// 2. Initialize\nconst {state, saveOfflineData} = useOfflineSync({\n  url: 'https://myapi.com/sync',\n  // method: 'POST',                                  // optional \n  // headers: {Authorization: 'Bearer your-token'},   // optional\n  // bulkSync: false,                                 // optional\n  // uniqueKeys: ['name'],                            // optional\n  // retryPolicy: { maxAttempts: 3, delayMs: 1000 },  // optional\n});\n\nconst submitData = async () =\u003e {\n  if (!formData.value.name || !formData.value.message) return;\n\n  // 3. Pass your data to this method.\n  await saveOfflineData({name: formData.value.name, message: formData.value.message});\n\n  formData.value = {name: '', message: ''};\n};\n\u003c/script\u003e\n\n\u003ctemplate\u003e\n  \u003cdiv\u003e\n    \u003ch2\u003eVue Offline Sync Example\u003c/h2\u003e\n    \u003cp\u003eStatus: \u003cstrong\u003e{{ state.isOnline ? 'Online' : 'Offline' }}\u003c/strong\u003e\u003c/p\u003e\n\n    \u003cform @submit.prevent=\"submitData\"\u003e\n      \u003cinput v-model=\"formData.name\" placeholder=\"Your Name\" required/\u003e\n      \u003ctextarea v-model=\"formData.message\" placeholder=\"Your Message\" required\u003e\u003c/textarea\u003e\n      \u003cbutton type=\"submit\"\u003eSave\u003c/button\u003e\n    \u003c/form\u003e\n  \u003c/div\u003e\n\u003c/template\u003e\n```\n\n### ⚙️ Options\n\n| Option        | Type     | Required | Default                               | Description                                                                                                                                                |\n|:--------------|:---------|:---------|:--------------------------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `url`         | String   | ✅ Yes    | `undefined`                           | API endpoint to sync data                                                                                                                                  |\n| `method`      | String   | ❌ No     | \"POST\"                                | HTTP method (e.g., \"POST\", \"PUT\", etc.)                                                                                                                    |\n| `headers`     | Object   | ❌ No     | {}                                    | Additional headers (e.g., authentication token)                                                                                                            |\n| `bulkSync`    | Boolean  | ❌ No     | false                                 | Set to true if your API accepts batch sync requests                                                                                                        |\n| `uniqueKeys`  | String[] | ❌ No     | `undefined`                           | Specifies the columns that must have unique values across all entries. If any of the defined columns contain duplicate values, the entry will be rejected. |\n| `retryPolicy` | Object   | ❌ No     | ```{maxAttempts: 1, delayMs: 1000}``` | Configures automatic retries for failed requests. See **[Retry Policy](#-retry-policy)** below.                                                            |\n\n### 📡 States\n\n| State                    | Type          | Description                                                                                       |\n|:-------------------------|---------------|:--------------------------------------------------------------------------------------------------|\n| `state.isOnline`         | Boolean       | `true` when online, `false` when offline                                                          |\n| `state.offlineData`      | Array\u003cObject\u003e | Data stored in IndexedDB during offline mode                                                      |\n| `state.isSyncInProgress` | Boolean       | Can be used to indicate a loading state in the UI, informing the user that syncing is in progress |\n\n### 🔄 Methods\n\n| Method                  | Description                                                         |\n|:------------------------|:--------------------------------------------------------------------|\n| saveOfflineData(object) | Saves data to IndexedDB when offline, or syncs directly when online |\n| syncOfflineData()       | Manually triggers syncing of offline data                           |\n\n### 🔄 Retry Policy\n\nThe `retryPolicy` option allows configuring **automatic retries** for failed API requests.\n\n| Property      | Type   | Default | Description                                    |\n|---------------|--------|---------|------------------------------------------------|\n| `maxAttempts` | Number | `1`     | Maximum number of retries before failing       |\n| `delayMs`     | Number | `1000`  | Delay (in milliseconds) between retry attempts |\n\n**Example Usage:**\n\n```js\nconst {state, saveOfflineData} = useOfflineSync({\n    url: 'https://myapi.com/sync',\n    retryPolicy: {\n        maxAttempts: 5,\n        delayMs: 2000,\n    }\n});\n```\n\n\u003e 💡 If a request fails, it will retry up to 5 times with a **2-second delay** between each attempt.\n\n\u003cbr /\u003e\n\n### 📌 Bulk vs Individual Syncing\n\n\u003e **Note:** The individual syncing is being used by default.\n\n#### 📥 Bulk Sync (bulkSync: true)\n\n✔ Sends all offline data as one request\u003cbr /\u003e\n✔ Recommended for APIs that support bulk inserts\n\n**Example Requests**\n\n```json\n[\n  {\n    \"name\": \"Name A\",\n    \"message\": \"Hello!\"\n  },\n  {\n    \"name\": \"Name B\",\n    \"message\": \"Hey there!\"\n  }\n]\n```\n\n#### 📤 Individual Sync (bulkSync: false)\n\n✔ Sends each offline entry separately\u003cbr /\u003e\n✔ Recommended for APIs that only accept single requests\n\n**Example Requests**\n\n```json\n{\n  \"name\": \"Name A\",\n  \"message\": \"Hello!\"\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjrran90%2Fvue-offline-sync","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjrran90%2Fvue-offline-sync","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjrran90%2Fvue-offline-sync/lists"}