{"id":17677445,"url":"https://github.com/unadlib/origin-storage","last_synced_at":"2025-04-13T21:36:42.304Z","repository":{"id":44968314,"uuid":"281744502","full_name":"unadlib/origin-storage","owner":"unadlib","description":"A same-origin storage(IndexedDB/WebSQL/localStorage) for cross-domain access","archived":false,"fork":false,"pushed_at":"2025-04-08T15:19:47.000Z","size":797,"stargazers_count":22,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-08T16:28:07.612Z","etag":null,"topics":["cross-database","indexeddb","localforage","localstorage","websql"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/unadlib.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2020-07-22T17:43:10.000Z","updated_at":"2025-04-08T15:19:51.000Z","dependencies_parsed_at":"2023-02-08T02:18:06.331Z","dependency_job_id":"4b046f96-1d37-4033-9d2f-4f3e58a23e5f","html_url":"https://github.com/unadlib/origin-storage","commit_stats":{"total_commits":49,"total_committers":2,"mean_commits":24.5,"dds":0.1428571428571429,"last_synced_commit":"9d046919de9d412dbb317207a87890df44ed377b"},"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unadlib%2Forigin-storage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unadlib%2Forigin-storage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unadlib%2Forigin-storage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unadlib%2Forigin-storage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/unadlib","download_url":"https://codeload.github.com/unadlib/origin-storage/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248788571,"owners_count":21161725,"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":["cross-database","indexeddb","localforage","localstorage","websql"],"created_at":"2024-10-24T07:28:42.688Z","updated_at":"2025-04-13T21:36:42.275Z","avatar_url":"https://github.com/unadlib.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# origin-storage\n\n![Node CI](https://github.com/unadlib/origin-storage/workflows/Node%20CI/badge.svg)\n[![npm version](https://badge.fury.io/js/origin-storage.svg)](http://badge.fury.io/js/origin-storage)\n\nA same-origin storage for cross-domain access, it is based on localForage and supports IndexedDB, WebSQL and localStorage.\n\n\u003e `origin-storage` uses localStorage in browsers with no IndexedDB or WebSQL support. And Safari is not supported.\n\n## Table of Contents\n\n- [Motivation](#motivation)\n- [Installation](#installation)\n- [Usage and Example](#usage-and-example)\n- [API](#api)\n  - [OriginStorage](#originstorage)\n  - [OriginStorageClient](#originstorageclient)\n\n## Motivation\n\nWhen different Website domains need a same-origin storage container, we have to use iframe's same-origin policy Web local storage solution. `localForage` is an excellent storage library, it supports IndexedDB, WebSQL and localStorage, but it can't solve this problem directly.\n\nThat's why we have this library for same-origin storage based on `localForage`.\n\n## Installation\n\n```sh\nyarn add origin-storage\n```\n\n## Usage and Example\n\n- Use `OriginStorage` on `http://localhost:9000/storage.js`:\n\n```ts\nimport { OriginStorage } from 'origin-storage';\n\nconst originStorage = new OriginStorage();\n```\n\n\u003e If you need to set up a more secure origin control, you can set `targetOrigin` like this.\n\n```ts\nconst originStorage = new OriginStorage({\n  targetOrigin: 'http://example.com',\n});\n```\n\n- Create and host a Web page(`http://localhost:9000/storage.html`) containing JavaScript file `storage.js`.\n\n- Use `OriginStorageClient` on a cross-domain page:\n\n```ts\nimport { OriginStorageClient } from 'origin-storage';\n\nconst originStorageClient = new OriginStorageClient({\n  uri: 'http://localhost:9000/storage.html',\n});\n```\n\n## API\n\n### `OriginStorage`\n\n- `new OriginStorage(options)`\n\n```ts\ninterface OriginStorageOptions extends IFrameTransportInternalOptions {\n  /**\n   * Enable read access to OriginStorage.\n   */\n  read?: boolean;\n  /**\n   * Enable write access to OriginStorage.\n   */\n  write?: boolean;\n  /**\n   * Enable broadcast data changes on OriginStorage.\n   */\n  broadcastChanges?: boolean;\n  /**\n   * Specify broadcastChannel name.\n   */\n  broadcastChannelName?: string;\n}\n```\n\n### `OriginStorageClient`\n\n- `new OriginStorageClient(options)`\n\n```ts\ninterface OriginStorageClientOptions extends IFrameMainTransportOptions {\n  /**\n   * Specify the uri of an OriginStorage container.\n   */\n  uri: string;\n  /**\n   * Set storage options for localforage.\n   */\n  storageOptions?: LocalForageOptions;\n}\n```\n\n- `OriginStorageClient` instance methods.\n\n```ts\ninterface IOriginStorageClient {\n  /**\n   * The callback will be called when the iframe is connected.\n   */\n  onConnect(callback: () =\u003e void): void;\n  /**\n   * The callback will be called when the storage is changed.\n   */\n  onChange(callback: (data: IChangeData) =\u003e void): Promise\u003c{\n    off: () =\u003e void;\n    broadcastChanges: boolean;\n  }\u003e;\n  /**\n   * Get the value of the specified key.\n   */\n  getItem(key: string): Promise\u003cany\u003e;\n  /**\n   * Set the value of the specified key.\n   */\n  setItem(key: string, value: any): Promise\u003cvoid\u003e;\n  /**\n   * Remove the value of the specified key.\n   */\n  removeItem(key: string): Promise\u003cvoid\u003e;\n  /**\n   * Clear all key/value pairs in the storage.\n   */\n  clear(): Promise\u003cvoid\u003e;\n  /**\n   * Get the number of key/value pairs in the storage.\n   */\n  length(): Promise\u003cnumber\u003e;\n  /**\n   * Get the name of the nth key in the storage.\n   */\n  key(index: number): Promise\u003cstring\u003e;\n  /**\n   * Get all keys in the storage.\n   */\n  keys(): Promise\u003cstring[]\u003e;\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funadlib%2Forigin-storage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Funadlib%2Forigin-storage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funadlib%2Forigin-storage/lists"}