{"id":21374551,"url":"https://github.com/brightspaceui/lms-context-provider","last_synced_at":"2026-02-16T14:19:17.245Z","repository":{"id":239782107,"uuid":"772679968","full_name":"BrightspaceUI/lms-context-provider","owner":"BrightspaceUI","description":"Provides LMS context and environment settings to UI components, applications and libraries","archived":false,"fork":false,"pushed_at":"2026-01-12T12:47:38.000Z","size":1420,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-01-12T19:47:56.017Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BrightspaceUI.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":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-03-15T17:10:32.000Z","updated_at":"2026-01-12T12:47:42.000Z","dependencies_parsed_at":"2024-11-07T13:36:31.869Z","dependency_job_id":"e86274ea-012a-42c9-99bc-251ae0031fa0","html_url":"https://github.com/BrightspaceUI/lms-context-provider","commit_stats":null,"previous_names":["brightspaceui/lms-context-provider"],"tags_count":29,"template":false,"template_full_name":null,"purl":"pkg:github/BrightspaceUI/lms-context-provider","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrightspaceUI%2Flms-context-provider","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrightspaceUI%2Flms-context-provider/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrightspaceUI%2Flms-context-provider/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrightspaceUI%2Flms-context-provider/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BrightspaceUI","download_url":"https://codeload.github.com/BrightspaceUI/lms-context-provider/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrightspaceUI%2Flms-context-provider/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28571556,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-19T12:50:50.164Z","status":"ssl_error","status_checked_at":"2026-01-19T12:50:42.704Z","response_time":67,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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-22T08:43:39.787Z","updated_at":"2026-01-19T14:02:56.834Z","avatar_url":"https://github.com/BrightspaceUI.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @brightspace-ui/lms-context-provider\n\nProvides LMS context and environment settings to UI components, applications and libraries.\n\n## Installation\n\nInstall from NPM:\n\n```shell\nnpm install @brightspace-ui/lms-context-provider\n```\n\n## Usage\n\n### Using a Client\n\n#### Requesting Data\n\nTo request data, import `tryGet` from the client and invoke it directly. The first argument should be a context type corresponding to a registered host plugin, while the second argument is an optional set of options to pass through to the host plugin. The third argument is an optional callback to allow a consumer to subscribe to future changes to the data they're requesting.\n\n```js\nimport { tryGet } from '@brightspace-ui/lms-context-provider/client.js';\n\nconst val = await tryGet(\n  'my-context-type',\n  { someProp: someVal },\n  (changedValues) =\u003e {\n    // This callback should accept a single argument:\n    // an object containing any relevant information from the host plugin\n\tif (changedValues.someChangedProp === 'someVal') {\n\t\tdoSomeWork(changedValues.someChangedProp);\n\t}\n  }\n);\ndoSomeWork(val);\n```\n\nIf no host plugin is registered to handle a request, or if the data being requested isn't available, the host will return `undefined`. The host plugin may also need to rely on asynchronous methods to return data, so client code should be resilient to receiving a promise that doesn't resolve or takes some time to resolve.\n\nIf no host has been initialized, `tryGet` will reject with an error.\n\n#### Performing an Action\n\nTo initiate an action on the host but doesn't require return data, import `tryPerform` from the client and invoke it directly. The first argument should be a context type corresponding to a registered host plugin, while the second argument is an optional set of options to pass through to the host plugin. It is not possible to subscribe to change events using this function.\n\n```js\nimport { tryPerform } from '@brightspace-ui/lms-context-provider/client.js;'\n\nawait tryPerform('my-context-type', { someProp: someVal });\n```\n\nIf no host plugin is registered to handle a request, or if the data being requested isn't available, this promise will immediately resolve and nothing will happen. As with the `tryGet` function, the host plugin may need to perform asynchronous actions to fulfill a request, so this promise may also never resolve, or may take some time to resolve.\n\nIf no host has been initialized, `tryPerform` will reject with an error.\n\n### Configuring a Host\n\n#### Initializing\n\nInitializing a host should rarely be necessary. Within a Brightspace instance, this will generally be handled by BSI via our MVC and legacy frameworks. To initialize a host, import and execute the `initialize` function.\n\n```js\nimport { initialize } from '@brightspace-ui/lms-context-provider/host.js';\n\ninitialize();\n```\n\n#### Registering Plugins\n\nTo register a host plugin, import and execute the `registerPlugin` function on a page where a host has already been initialized. The provided context type should be unique per page. If a plugin needs to return data to a client, it should provide a `tryGetCallback` as the second argument. If clients can be notified when the data changes, then it should provide a `subscribeCallback` as the third argument.\n\n```js\nimport { registerPlugin } from '@brightspace-ui/lms-context/provider/host.js';\n\nfunction tryGetCallback(options) {\n\t// This can be asynchronous.\n\tconst returnVal = doSomeWork(options);\n\treturn returnVal;\n}\n\nfunction subscribeCallback(onChange, options) {\n\t// this can be asynchronous.\n\tconst returnVal = doSomeWork(options);\n\n\t// Options are defined by the host, not the plugin. sendImmediate indicates the change handler should be invoked immediately.\n\tif (options.sendImmediate) {\n\t\t// Expects an object as its only argument.\n\t\tonChange({ val: returnVal });\n\t}\n\n\t// onChange event should be subscribed to future changes.\n\tregisterOnChangeEvent(onChange);\n}\n\nregisterPlugin('my-context-type', tryGetCallback, subscribeCallback);\n```\n\n#### Framed Clients\n\nWhen working with a client inside an iframe, the host page needs to explicitly allow that iframe. To do this, import and execute `allowFrame` from the host page (the host must already be initialized.). The first argument must be the iframe element itself. The second argument should be the expected origin. Requests from clients within iframes that have not explicitly been allowed or that come from a different origin will be rejected.\n\n```js\nimport { allowFrame } from '@brightspace-ui/lms-context-provider/host.js';\n\nconst myFrame = document.createElement('iframe');\ndocument.body.append(myFrame);\n\nallowFrame(myFrame, window.location.origin);\n```\n\n## Developing, Testing and Contributing\n\nAfter cloning the repo, run `npm install` to install dependencies.\n\n### Linting\n\n```shell\n# eslint\nnpm run lint\n```\n\n### Testing\n\n```shell\n# run tests\nnpm test\n```\n\n### Versioning and Releasing\n\nThis repo is configured to use `semantic-release`. Commits prefixed with `fix:` and `feat:` will trigger patch and minor releases when merged to `main`.\n\nTo learn how to create major releases and release from maintenance branches, refer to the [semantic-release GitHub Action](https://github.com/BrightspaceUI/actions/tree/main/semantic-release) documentation.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrightspaceui%2Flms-context-provider","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrightspaceui%2Flms-context-provider","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrightspaceui%2Flms-context-provider/lists"}