{"id":18770093,"url":"https://github.com/yaroslaff/locker-js","last_synced_at":"2025-08-01T14:04:31.575Z","repository":{"id":47550963,"uuid":"346739513","full_name":"yaroslaff/locker-js","owner":"yaroslaff","description":null,"archived":false,"fork":false,"pushed_at":"2022-02-15T14:01:55.000Z","size":34,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-13T16:37:18.356Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/yaroslaff.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}},"created_at":"2021-03-11T15:00:45.000Z","updated_at":"2022-07-21T00:22:48.000Z","dependencies_parsed_at":"2022-09-23T13:11:14.711Z","dependency_job_id":null,"html_url":"https://github.com/yaroslaff/locker-js","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/yaroslaff/locker-js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yaroslaff%2Flocker-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yaroslaff%2Flocker-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yaroslaff%2Flocker-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yaroslaff%2Flocker-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yaroslaff","download_url":"https://codeload.github.com/yaroslaff/locker-js/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yaroslaff%2Flocker-js/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268240336,"owners_count":24218356,"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","status":"online","status_checked_at":"2025-08-01T02:00:08.611Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-11-07T19:18:07.717Z","updated_at":"2025-08-01T14:04:31.512Z","avatar_url":"https://github.com/yaroslaff.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# locker-js\n\nLocker-js is frontend library for working with locker server\n\n## Developers documentation (draft)\n\n### Quickstart\n~~~js\nlocker_addr = 'https://myapp-myname.locker.server.address'\nlocker = new Locker(locker_addr)\n\nwindow.onload = async () =\u003e {\n  locker.hook_login = load_data\n  locker.check_login()\n}\n\nasync function load_data(){\n    /* your code */\n}\n~~~\n\n### Reference\n\n#### check_login()\n`check_login()` asks locker server, if user authenticated or not and updates page accordingly using `update_page()` and calls proper hook (`hook_after_check_login`). \n\ncheck_login uses local cache in localStorage(), cache lifetime is limited by `authenticated_cachetime` attribute, set it to -1 to disable cacheing\n\n#### update_page()\n`update_page()` uses naming convention to automatically update pages to current login status (show different content for authenticated and non-authenticated users).\n\nFor elements with classes `locker-login-link-${provider}` (e.g. `locker-login-link-google`) it creates proper onclick js code to perform authentication.\n\nApplication could be in three states: `unauthenticated`, `authenticated` and `authenticating`. For all elements with class name `locker-${state}` update_page() either sets `display` attribute to `block` or `none`.\n\n\n#### get(path)\nFetches (downloads) user data file from locker server:\n~~~js\n  locker.get('~/rw/notebook.txt')\n    .then(response =\u003e {\n      return response.text()\n    })\n    .then(text =\u003e {\n      document.getElementById(\"notebook\").value = text\n    })\n    .catch(e =\u003e {\n      console.log(\"no notebook\", e)\n    })\n~~~\n\n#### put(path, data)\nUploads data from application to user file on locker server:\n~~~~js\n  data = document.getElementById(\"notebook\").value\n  locker.put('~/rw/notebook.txt', data)\n~~~~\n\n#### get_json_file(path, code)\n~~~js\n  locker.get_json_file('~/r/userinfo.json', data =\u003e {\n    document.getElementById(\"profile\").innerText = `Hello, ${data['name']} \u003c${data['email']}\u003e!`\n  })\n~~~\n\n#### set_flag(flag, path='/var/flags.json')\nSets flag *name* in flag file *path*.\n~~~js\nlocker.set_flag('myflag')\n~~~\n\nEach flag automatically includes userid and timestamp which are added on server.\n\n#### drop_flag(flag, path, timestamp=null)\nDrop flag *name* in flag file *path*. If timestamp is specified, flag is dropped only if it's older then timestamp.\n\n#### Hooks\n\n##### hook_after_check_login\ncalled with login_status structure as argument, example:\n~~~js\nlogin_status = {\n    messages: ['Reuse cached value from localStorage'],\n    status: true\n}\n~~~\n\nProgrammer may use this hook to perform custom actions after login checks\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyaroslaff%2Flocker-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyaroslaff%2Flocker-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyaroslaff%2Flocker-js/lists"}