{"id":22428394,"url":"https://github.com/momsfriendlydevco/latch","last_synced_at":"2025-03-27T06:43:42.181Z","repository":{"id":189061100,"uuid":"621157068","full_name":"MomsFriendlyDevCo/Latch","owner":"MomsFriendlyDevCo","description":"Permission parsing, masking, verification","archived":false,"fork":false,"pushed_at":"2023-03-30T05:50:24.000Z","size":35,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-25T12:50:54.910Z","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/MomsFriendlyDevCo.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}},"created_at":"2023-03-30T05:20:19.000Z","updated_at":"2023-03-30T05:21:20.000Z","dependencies_parsed_at":"2023-08-18T04:42:47.069Z","dependency_job_id":"2acd72a7-cabf-4a04-a945-3d841c756a95","html_url":"https://github.com/MomsFriendlyDevCo/Latch","commit_stats":null,"previous_names":["momsfriendlydevco/latch"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MomsFriendlyDevCo%2FLatch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MomsFriendlyDevCo%2FLatch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MomsFriendlyDevCo%2FLatch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MomsFriendlyDevCo%2FLatch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MomsFriendlyDevCo","download_url":"https://codeload.github.com/MomsFriendlyDevCo/Latch/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245798538,"owners_count":20673901,"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":[],"created_at":"2024-12-05T20:14:42.024Z","updated_at":"2025-03-27T06:43:42.156Z","avatar_url":"https://github.com/MomsFriendlyDevCo.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"@MomsFriendlyDevCo/Latch\n========================\nPermission parsing, masking, verification.\n\nThis module provides a simple, extendable permissions language.\n\nFeatures:\n* Chainable - (almost) all functions return the original Latch or LatchSet instance making chainable composition easier\n* Paranoia-by-default - No member settings are available outside of getters / setters\n\n\n```javascript\nimport {LatchSet} from '@momsfriendlydevco/latch';\n\nlet latchSet = new LatchSet();\n\n// ADDING MEMBERS\n// --------------\n// Add basic members with strings\nlatchSet.add('foo::bar::one');\n\n// or Latches\nlatchSet.add(new Latch('foo::bar::two'));\n\n// or Objects\nlatchSet.add({source: 'foo', noun: 'bar', verb: 'three'});\n\n\n// QUERYING MEMBERS\n// ----------------\n// Simple querying for presence\nlatchSet.has('foo::bar::one') //= true\n\n// ... or by sets\nlatchSet.hasAll('foo::bar::two', 'foo::bar::three') //= true\n\n\n// MASKING\n// -------\n// Fill in missing information for wildcard permissions\nlatchSet\n    .add('mySource::myNoun::@') // Setup a generic permission where '@' signifies any verb\n    .mask('...:...:create') // Patch in the 'create' verb - returning a new LatchSet instance (original latch remains as-is)\n    .has('mySource::myNoun::create') //= true\n```\n\n\nAPI\n===\n\nnew LatchSet()\n--------------\nCreate a new LatchSet.\n\n\nLatchSet.setOption(option, value)\n---------------------------------\nSet a single setting or overwrite existing settings.\nIf given a key + val that single setting is set, if an object is provided this is merged in with the settings.\nReturns the LatchSet instance.\n\n\nLatchSet.add(member)\n--------------------\nAdd a member to the set. Can be string, object or existing Latch instance (which will be reparented).\nReturns the LatchSet instance.\n\n\nLatchSet.clear()\n----------------\nRemove all existing members from a set.\nReturns the LatchSet instance.\n\n\n\nLatchSet.grant(existing, members...)\n------------------------------------\nGrant additional members if the `existing` member is already present.\nThis provides hierarchical permissioning.\nReturns the LatchSet instance.\n\n\nLatchSet.has(member)\n--------------------\nReturns a boolean if the provided member (which can be a string or Latch instance) exists.\n\n\nLatchSet.hasAll(members)\n------------------------\nReturns a boolean indicating if ALL provided members exist.\n\n\nLatchSet.hasAny(members)\n------------------------\nReturns a boolean indicating if ANY of the provided members exist.\n\n\nLatchSet.toArray()\n------------------\nReturn all member, stringified Latch instances as an array.\n\n\nLatchSet.mask(mask)\n-------------------\nApply a permission mask, returning a new clone of the LatchSet and all member Latch instances.\n\n\nLatchSet.maskFromRequest(mask)\n------------------------------\nCompute + apply a mask based on an incoming ExpressRequest(-like) object.\n\nOptions are:\n\n| Option    | Type       | Default                 | Description                                                                                               |\n|-----------|------------|-------------------------|-----------------------------------------------------------------------------------------------------------|\n| `context` | `Function` | `req =\u003e req.params?.id` | Function to extract the document being referred to, if any. Usually `req.params.id` but can be repurposed |\n| `maskKey` | `String`   | `'verb'`                | Key to set to the eventual extracted verb, prior to masking                                               |\n\nReturns a LatchSet clone with all members masked.\n\n\nLatchSet.setHandler / setParser / setStringify\n----------------------------------------------\nSet entire set handler functions. See Latch for documentation on these.\nReturns the LatchSet instance.\n\n\nLatchSet.clone(options)\n-----------------------\nClone the current LatchSet with optional settings.\n\n| Option     | Type      | Default | Description                              |\n|------------|-----------|---------|------------------------------------------|\n| `members`  | `Boolean` | `true`  | Copy + reparent all Latch members        |\n| `settings` | `Boolean` | `true`  | Copy all associated LatchSet permissions |\n\n\n\nnew Latch(id)\n-------------\nCreate a new, single latch object.\nThe optional ID is passed to `Latch.set()` if present.\nReturns the Latch instance.\n\n\nLatch.setParent(latchSet)\n-------------------------\nSet the latch parent of the current latch.\nThis will also overwrite `#handlers` with any `LatchSet.handlers` it finds.\nReturns the Latch instance.\n\n\nLatch.set(id)\n-------------\nSet the ID of the latch.a\nThe ID can be an optional string or object parts.\nReturns the Latch instance.\n\n\nLatch.toString()\n----------------\nOutput the current Latch state as a string.\n\n\nLatch.toObject()\n----------------\nOutput the disected Latch state as a object.\n\n\nLatch.matches(subject)\n----------------------\nReturn a boolean if the given latch matches an expression.\nSubject can be a string or other Latch.\n\n\nLatch.mask(mask)\n----------------\nReturn a clone of this Latch instance patching in masks data.\n\n\nLatch.clone(id)\n---------------\nClone this match, setting the parent and state.\n\n\nLatch.setHandler(handler, func)\n--------------------------------\nSet a local handler function by its string name.\nReturns the Latch instance.\n\n\nLatch.setParser(parser)\n-----------------------\nHelper function to set the 'fromString' handler.\nReturns the Latch instance.\n\n\nLatch.setStringify(stringifier)\n-------------------------------\nHelper function to set the 'toString' handler.\nReturns the Latch instance.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmomsfriendlydevco%2Flatch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmomsfriendlydevco%2Flatch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmomsfriendlydevco%2Flatch/lists"}