@plasius/auth 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,61 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on **[Keep a Changelog](https://keepachangelog.com/en/1.1.0/)**, and this project adheres to **[Semantic Versioning](https://semver.org/spec/v2.0.0.html)**.
6
+
7
+ ---
8
+
9
+ ## [Unreleased]
10
+
11
+ - **Added**
12
+ - (placeholder)
13
+
14
+ - **Changed**
15
+ - (placeholder)
16
+
17
+ - **Fixed**
18
+ - (placeholder)
19
+
20
+ - **Security**
21
+ - (placeholder)
22
+
23
+ ## [1.0.0] - 2026-02-10
24
+
25
+ - **Added**
26
+ - (placeholder)
27
+
28
+ - **Changed**
29
+ - (placeholder)
30
+
31
+ - **Fixed**
32
+ - (placeholder)
33
+
34
+ - **Security**
35
+ - (placeholder)
36
+
37
+ ---
38
+
39
+ ## [1.0.0] - 2026-02-10
40
+
41
+ - **Added**
42
+ - Initial standalone public release of `@plasius/auth`.
43
+ - React auth context provider and auth utility helpers (`login`, `logout`, `authorizedFetch`).
44
+ - CI/CD pipelines for npm publishing with provenance and Codecov integration.
45
+
46
+ ---
47
+
48
+ ## Release process (maintainers)
49
+
50
+ 1. Update `CHANGELOG.md` under **Unreleased** with user-visible changes.
51
+ 2. Bump version in `package.json` following SemVer (major/minor/patch).
52
+ 3. Move entries from **Unreleased** to a new version section with the current date.
53
+ 4. Tag the release in Git (`vX.Y.Z`) and push tags.
54
+ 5. Publish to npm (via CI/CD or `npm publish`).
55
+
56
+ > Tip: Use Conventional Commits in PR titles/bodies to make changelog updates easier.
57
+
58
+ ---
59
+
60
+ [Unreleased]: https://github.com/Plasius-LTD/auth/compare/v1.0.0...HEAD
61
+ [1.0.0]: https://github.com/Plasius-LTD/auth/releases/tag/v1.0.0
@@ -0,0 +1,79 @@
1
+ # Contributor Covenant Code of Conduct v2.1
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ - Demonstrating empathy and kindness toward other people
14
+ - Being respectful of differing opinions, viewpoints, and experiences
15
+ - Giving and gracefully accepting constructive feedback
16
+ - Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ - Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ - The use of sexualized language or imagery, and sexual attention or advances of any kind
22
+ - Trolling, insulting or derogatory comments, and personal or political attacks
23
+ - Public or private harassment
24
+ - Publishing others’ private information, such as a physical or email address, without their explicit permission
25
+ - Other conduct which could reasonably be considered inappropriate in a professional setting
26
+
27
+ ## Enforcement Responsibilities
28
+
29
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
30
+
31
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
32
+
33
+ ## Scope
34
+
35
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
36
+
37
+ ## Enforcement
38
+
39
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at [conduct@plasius.co.uk](mailto:conduct@plasius.co.uk). All complaints will be reviewed and investigated promptly and fairly.
40
+
41
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
42
+
43
+ ## Enforcement Guidelines
44
+
45
+ Community leaders will follow these Enforcement Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
46
+
47
+ ### 1. Correction
48
+
49
+ **Community Impact:** Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
50
+
51
+ **Consequence:** A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
52
+
53
+ ### 2. Warning
54
+
55
+ **Community Impact:** A violation through a single incident or series of actions.
56
+
57
+ **Consequence:** A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
58
+
59
+ ### 3. Temporary Ban
60
+
61
+ **Community Impact:** A serious violation of community standards, including sustained inappropriate behavior.
62
+
63
+ **Consequence:** A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
64
+
65
+ ### 4. Permanent Ban
66
+
67
+ **Community Impact:** Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
68
+
69
+ **Consequence:** A permanent ban from any sort of public interaction within the community.
70
+
71
+ ## Attribution
72
+
73
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.1, available at [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html](https://www.contributor-covenant.org/version/2/1/code_of_conduct.html)
74
+
75
+ For answers to common questions about this code of conduct, see the [FAQ](https://www.contributor-covenant.org/faq)
76
+
77
+ [homepage]: [https://www.contributor-covenant.org](https://www.contributor-covenant.org)
78
+
79
+ If you have any questions or concerns regarding this Code of Conduct, please contact us at [conduct@plasius.co.uk](mailto:conduct@plasius.co.uk).
@@ -0,0 +1,27 @@
1
+ # Contributing Guidelines
2
+
3
+ Thank you for considering contributing to this project! We welcome contributions that improve the code, documentation, and overall project quality.
4
+
5
+ ## Getting Started
6
+
7
+ - Fork the repository.
8
+ - Create a feature branch from `main`.
9
+ - Commit your changes with clear messages (we follow **Conventional Commits**).
10
+ - Push your branch and open a Pull Request (PR).
11
+
12
+ ## Requirements
13
+
14
+ - Write tests alongside code where possible.
15
+ - Ensure all tests pass before submitting a PR.
16
+ - Follow the repository’s coding style and linting rules.
17
+ - Update documentation (README, ADRs, etc.) when making significant changes.
18
+ - When making architectural changes, create a new ADR (Architecture Decision Record) that **succeeds** the previous one rather than modifying old ADRs. This preserves history and ensures decisions are traceable.
19
+ - Use the [ADR template](./docs/adrs/adr-template.md) when writing new ADRs to ensure consistency.
20
+ - Before your first contribution, sign the appropriate Contributor License Agreement (CLA). See [legal/CLA.md](legal/CLA.md) for details, then email the signed document to [contributors@plasius.co.uk](mailto:contributors@plasius.co.uk).
21
+
22
+ ## Communication
23
+
24
+ - Use GitHub Issues for bugs and feature requests.
25
+ - Pull Requests should describe the problem, solution, and trade-offs.
26
+
27
+ We appreciate your support in making this project better!
package/LICENSE ADDED
@@ -0,0 +1,203 @@
1
+ Copyright 2025 Plasius LTD
2
+
3
+ Apache License
4
+ Version 2.0, January 2004
5
+ http://www.apache.org/licenses/
6
+
7
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8
+
9
+ 1. Definitions.
10
+
11
+ "License" shall mean the terms and conditions for use, reproduction,
12
+ and distribution as defined by Sections 1 through 9 of this document.
13
+
14
+ "Licensor" shall mean the copyright owner or entity authorized by
15
+ the copyright owner that is granting the License.
16
+
17
+ "Legal Entity" shall mean the union of the acting entity and all
18
+ other entities that control, are controlled by, or are under common
19
+ control with that entity. For the purposes of this definition,
20
+ "control" means (i) the power, direct or indirect, to cause the
21
+ direction or management of such entity, whether by contract or
22
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
23
+ outstanding shares, or (iii) beneficial ownership of such entity.
24
+
25
+ "You" (or "Your") shall mean an individual or Legal Entity
26
+ exercising permissions granted by this License.
27
+
28
+ "Source" form shall mean the preferred form for making modifications,
29
+ including but not limited to software source code, documentation
30
+ source, and configuration files.
31
+
32
+ "Object" form shall mean any form resulting from mechanical
33
+ transformation or translation of a Source form, including but
34
+ not limited to compiled object code, generated documentation,
35
+ and conversions to other media types.
36
+
37
+ "Work" shall mean the work of authorship, whether in Source or
38
+ Object form, made available under the License, as indicated by a
39
+ copyright notice that is included in or attached to the work
40
+ (an example is provided in the Appendix below).
41
+
42
+ "Derivative Works" shall mean any work, whether in Source or Object
43
+ form, that is based on (or derived from) the Work and for which the
44
+ editorial revisions, annotations, elaborations, or other modifications
45
+ represent, as a whole, an original work of authorship. For the purposes
46
+ of this License, Derivative Works shall not include works that remain
47
+ separable from, or merely link (or bind by name) to the interfaces of,
48
+ the Work and Derivative Works thereof.
49
+
50
+ "Contribution" shall mean any work of authorship, including
51
+ the original version of the Work and any modifications or additions
52
+ to that Work or Derivative Works thereof, that is intentionally
53
+ submitted to Licensor for inclusion in the Work by the copyright owner
54
+ or by an individual or Legal Entity authorized to submit on behalf of
55
+ the copyright owner. For the purposes of this definition, "submitted"
56
+ means any form of electronic, verbal, or written communication sent
57
+ to the Licensor or its representatives, including but not limited to
58
+ communication on electronic mailing lists, source code control systems,
59
+ and issue tracking systems that are managed by, or on behalf of, the
60
+ Licensor for the purpose of discussing and improving the Work, but
61
+ excluding communication that is conspicuously marked or otherwise
62
+ designated in writing by the copyright owner as "Not a Contribution."
63
+
64
+ "Contributor" shall mean Licensor and any individual or Legal Entity
65
+ on behalf of whom a Contribution has been received by Licensor and
66
+ subsequently incorporated within the Work.
67
+
68
+ 2. Grant of Copyright License. Subject to the terms and conditions of
69
+ this License, each Contributor hereby grants to You a perpetual,
70
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
71
+ copyright license to reproduce, prepare Derivative Works of,
72
+ publicly display, publicly perform, sublicense, and distribute the
73
+ Work and such Derivative Works in Source or Object form.
74
+
75
+ 3. Grant of Patent License. Subject to the terms and conditions of
76
+ this License, each Contributor hereby grants to You a perpetual,
77
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
78
+ (except as stated in this section) patent license to make, have made,
79
+ use, offer to sell, sell, import, and otherwise transfer the Work,
80
+ where such license applies only to those patent claims licensable
81
+ by such Contributor that are necessarily infringed by their
82
+ Contribution(s) alone or by combination of their Contribution(s)
83
+ with the Work to which such Contribution(s) was submitted. If You
84
+ institute patent litigation against any entity (including a
85
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
86
+ or a Contribution incorporated within the Work constitutes direct
87
+ or contributory patent infringement, then any patent licenses
88
+ granted to You under this License for that Work shall terminate
89
+ as of the date such litigation is filed.
90
+
91
+ 4. Redistribution. You may reproduce and distribute copies of the
92
+ Work or Derivative Works thereof in any medium, with or without
93
+ modifications, and in Source or Object form, provided that You
94
+ meet the following conditions:
95
+
96
+ (a) You must give any other recipients of the Work or
97
+ Derivative Works a copy of this License; and
98
+
99
+ (b) You must cause any modified files to carry prominent notices
100
+ stating that You changed the files; and
101
+
102
+ (c) You must retain, in the Source form of any Derivative Works
103
+ that You distribute, all copyright, patent, trademark, and
104
+ attribution notices from the Source form of the Work,
105
+ excluding those notices that do not pertain to any part of
106
+ the Derivative Works; and
107
+
108
+ (d) If the Work includes a "NOTICE" text file as part of its
109
+ distribution, then any Derivative Works that You distribute must
110
+ include a readable copy of the attribution notices contained
111
+ within such NOTICE file, excluding those notices that do not
112
+ pertain to any part of the Derivative Works, in at least one
113
+ of the following places: within a NOTICE text file distributed
114
+ as part of the Derivative Works; within the Source form or
115
+ documentation, if provided along with the Derivative Works; or,
116
+ within a display generated by the Derivative Works, if and
117
+ wherever such third-party notices normally appear. The contents
118
+ of the NOTICE file are for informational purposes only and
119
+ do not modify the License. You may add Your own attribution
120
+ notices within Derivative Works that You distribute, alongside
121
+ or as an addendum to the NOTICE text from the Work, provided
122
+ that such additional attribution notices cannot be construed
123
+ as modifying the License.
124
+
125
+ You may add Your own copyright statement to Your modifications and
126
+ may provide additional or different license terms and conditions
127
+ for use, reproduction, or distribution of Your modifications, or
128
+ for any such Derivative Works as a whole, provided Your use,
129
+ reproduction, and distribution of the Work otherwise complies with
130
+ the conditions stated in this License.
131
+
132
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
133
+ any Contribution intentionally submitted for inclusion in the Work
134
+ by You to the Licensor shall be under the terms and conditions of
135
+ this License, without any additional terms or conditions.
136
+ Notwithstanding the above, nothing herein shall supersede or modify
137
+ the terms of any separate license agreement you may have executed
138
+ with Licensor regarding such Contributions.
139
+
140
+ 6. Trademarks. This License does not grant permission to use the trade
141
+ names, trademarks, service marks, or product names of the Licensor,
142
+ except as required for reasonable and customary use in describing the
143
+ origin of the Work and reproducing the content of the NOTICE file.
144
+
145
+ 7. Disclaimer of Warranty. Unless required by applicable law or
146
+ agreed to in writing, Licensor provides the Work (and each
147
+ Contributor provides its Contributions) on an "AS IS" BASIS,
148
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
149
+ implied, including, without limitation, any warranties or conditions
150
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
151
+ PARTICULAR PURPOSE. You are solely responsible for determining the
152
+ appropriateness of using or redistributing the Work and assume any
153
+ risks associated with Your exercise of permissions under this License.
154
+
155
+ 8. Limitation of Liability. In no event and under no legal theory,
156
+ whether in tort (including negligence), contract, or otherwise,
157
+ unless required by applicable law (such as deliberate and grossly
158
+ negligent acts) or agreed to in writing, shall any Contributor be
159
+ liable to You for damages, including any direct, indirect, special,
160
+ incidental, or consequential damages of any character arising as a
161
+ result of this License or out of the use or inability to use the
162
+ Work (including but not limited to damages for loss of goodwill,
163
+ work stoppage, computer failure or malfunction, or any and all
164
+ other commercial damages or losses), even if such Contributor
165
+ has been advised of the possibility of such damages.
166
+
167
+ 9. Accepting Warranty or Additional Liability. While redistributing
168
+ the Work or Derivative Works thereof, You may choose to offer,
169
+ and charge a fee for, acceptance of support, warranty, indemnity,
170
+ or other liability obligations and/or rights consistent with this
171
+ License. However, in accepting such obligations, You may act only
172
+ on Your own behalf and on Your sole responsibility, not on behalf
173
+ of any other Contributor, and only if You agree to indemnify,
174
+ defend, and hold each Contributor harmless for any liability
175
+ incurred by, or claims asserted against, such Contributor by reason
176
+ of your accepting any such warranty or additional liability.
177
+
178
+ END OF TERMS AND CONDITIONS
179
+
180
+ APPENDIX: How to apply the Apache License to your work.
181
+
182
+ To apply the Apache License to your work, attach the following
183
+ boilerplate notice, with the fields enclosed by brackets "[]"
184
+ replaced with your own identifying information. (Don't include
185
+ the brackets!) The text should be enclosed in the appropriate
186
+ comment syntax for the file format. We also recommend that a
187
+ file or class name and description of purpose be included on the
188
+ same "printed page" as the copyright notice for easier
189
+ identification within third-party archives.
190
+
191
+ Copyright [yyyy] [name of copyright owner]
192
+
193
+ Licensed under the Apache License, Version 2.0 (the "License");
194
+ you may not use this file except in compliance with the License.
195
+ You may obtain a copy of the License at
196
+
197
+ http://www.apache.org/licenses/LICENSE-2.0
198
+
199
+ Unless required by applicable law or agreed to in writing, software
200
+ distributed under the License is distributed on an "AS IS" BASIS,
201
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
202
+ See the License for the specific language governing permissions and
203
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # @plasius/auth
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@plasius/auth.svg)](https://www.npmjs.com/package/@plasius/auth)
4
+ [![CI](https://github.com/Plasius-LTD/auth/actions/workflows/ci.yml/badge.svg)](https://github.com/Plasius-LTD/auth/actions/workflows/ci.yml)
5
+ [![CD](https://github.com/Plasius-LTD/auth/actions/workflows/cd.yml/badge.svg)](https://github.com/Plasius-LTD/auth/actions/workflows/cd.yml)
6
+ [![License](https://img.shields.io/github/license/Plasius-LTD/auth)](https://github.com/Plasius-LTD/auth)
7
+
8
+ Authentication helpers and React context components for Plasius applications.
9
+
10
+ Apache-2.0. ESM + CJS builds. TypeScript types included.
11
+
12
+ ---
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ npm install @plasius/auth
18
+ ```
19
+
20
+ ---
21
+
22
+ ## Usage
23
+
24
+ ```ts
25
+ import { AuthProvider, useLogin, useLogout, useAuthorizedFetch } from "@plasius/auth";
26
+ ```
27
+
28
+ ---
29
+
30
+ ## Build Outputs
31
+
32
+ This package ships ESM and CJS builds with TypeScript types in `dist/`.
33
+
34
+ ---
35
+
36
+ ## Contributing
37
+
38
+ Open an issue or pull request at [Plasius-LTD/auth](https://github.com/Plasius-LTD/auth).
package/SECURITY.md ADDED
@@ -0,0 +1,17 @@
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+
5
+ We currently support the latest major version of this project. Older versions may not receive security updates.
6
+
7
+ ## Reporting a Vulnerability
8
+
9
+ If you discover a security vulnerability, please report it privately by emailing us at [security@plasius.co.uk](mailto:security@plasius.co.uk). Please do not create a public issue for security-related matters.
10
+
11
+ ## Response Timeline
12
+
13
+ We aim to acknowledge your report within 2 business days and to provide a more detailed response (including next steps and, if applicable, a timeline for a fix) within 7 business days.
14
+
15
+ ## Disclosure Policy
16
+
17
+ We request that you give us the opportunity to address the vulnerability before publicly disclosing it. We will coordinate with you on public disclosure once a fix is available and deployed.
package/dist/index.cjs ADDED
@@ -0,0 +1,156 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ AuthProvider: () => AuthProvider,
24
+ createAuthorizedFetch: () => createAuthorizedFetch,
25
+ useAuth: () => useAuth,
26
+ useAuthorizedFetch: () => useAuthorizedFetch,
27
+ useLogin: () => useLogin,
28
+ useLogout: () => useLogout
29
+ });
30
+ module.exports = __toCommonJS(index_exports);
31
+
32
+ // src/components/AuthContext.tsx
33
+ var import_react2 = require("react");
34
+
35
+ // src/lib/authorizedFetch.ts
36
+ var import_react = require("react");
37
+ var refreshPromise = null;
38
+ function useAuthorizedFetch() {
39
+ return (0, import_react.useCallback)(createAuthorizedFetch(), []);
40
+ }
41
+ function createAuthorizedFetch() {
42
+ const authorizedFetch = async (input, init = {}) => {
43
+ const csrfToken = document.cookie.split("; ").find((row) => row.startsWith("csrf-token="))?.split("=")[1];
44
+ let response = await fetch(input, {
45
+ ...init,
46
+ credentials: "include",
47
+ headers: {
48
+ ...init.headers,
49
+ ...csrfToken ? { "x-csrf-token": csrfToken } : {}
50
+ }
51
+ });
52
+ if (response.status !== 401) {
53
+ return response;
54
+ }
55
+ if (!refreshPromise) {
56
+ refreshPromise = fetch(`/oauth/refresh-token`, {
57
+ method: "POST",
58
+ credentials: "include"
59
+ }).finally(() => {
60
+ refreshPromise = null;
61
+ });
62
+ }
63
+ const refreshResponse = await refreshPromise;
64
+ if (!refreshResponse.ok) {
65
+ return response;
66
+ }
67
+ const retryAfter = parseInt(
68
+ refreshResponse.headers.get("Retry-After") ?? "0",
69
+ 10
70
+ );
71
+ if (!isNaN(retryAfter) && retryAfter > 0) {
72
+ await new Promise((resolve) => setTimeout(resolve, retryAfter * 1e3));
73
+ }
74
+ return await authorizedFetch(input, init);
75
+ };
76
+ return authorizedFetch;
77
+ }
78
+
79
+ // src/components/AuthContext.tsx
80
+ var import_jsx_runtime = require("react/jsx-runtime");
81
+ var validateSessionPromise = null;
82
+ var AuthContext = (0, import_react2.createContext)(void 0);
83
+ var AuthProvider = ({ children }) => {
84
+ const authorizedFetch = useAuthorizedFetch();
85
+ const [userId, setUserId] = (0, import_react2.useState)(null);
86
+ const validateSession = async () => {
87
+ if (validateSessionPromise) return validateSessionPromise;
88
+ validateSessionPromise = (async () => {
89
+ try {
90
+ console.log("Finding out who we are!");
91
+ const res = await authorizedFetch(`/oauth/me`);
92
+ if (!res.ok) throw new Error("Invalid session");
93
+ const data = await res.json();
94
+ if (data?.userId) {
95
+ console.log(`User found! ${data.userId}`);
96
+ setUserId(data.userId);
97
+ } else {
98
+ setUserId(null);
99
+ }
100
+ } catch {
101
+ setUserId(null);
102
+ } finally {
103
+ validateSessionPromise = null;
104
+ }
105
+ })();
106
+ return validateSessionPromise;
107
+ };
108
+ (0, import_react2.useEffect)(() => {
109
+ validateSession();
110
+ }, []);
111
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AuthContext.Provider, { value: { userId, setUserId, validateSession }, children });
112
+ };
113
+ var useAuth = () => {
114
+ const ctx = (0, import_react2.useContext)(AuthContext);
115
+ if (!ctx) throw new Error("useAuth must be used within AuthProvider");
116
+ return ctx;
117
+ };
118
+
119
+ // src/lib/login.ts
120
+ function useLogin() {
121
+ return async function loginWithProvider(provider) {
122
+ const returnTo = window.location.pathname;
123
+ const state = btoa(returnTo);
124
+ window.location.href = `/oauth/${provider}?state=${state}`;
125
+ };
126
+ }
127
+
128
+ // src/lib/logout.ts
129
+ function useLogout() {
130
+ const authorizedFetch = useAuthorizedFetch();
131
+ return async function logout() {
132
+ try {
133
+ const res = await authorizedFetch(`/oauth/logout`, {
134
+ method: "POST",
135
+ credentials: "include"
136
+ });
137
+ if (!res.ok) {
138
+ console.error("Logout failed", await res.text());
139
+ }
140
+ } catch (err) {
141
+ console.error("Logout error", err);
142
+ } finally {
143
+ window.location.href = "/";
144
+ }
145
+ };
146
+ }
147
+ // Annotate the CommonJS export names for ESM import in node:
148
+ 0 && (module.exports = {
149
+ AuthProvider,
150
+ createAuthorizedFetch,
151
+ useAuth,
152
+ useAuthorizedFetch,
153
+ useLogin,
154
+ useLogout
155
+ });
156
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/components/AuthContext.tsx","../src/lib/authorizedFetch.ts","../src/lib/login.ts","../src/lib/logout.ts"],"sourcesContent":["export * from \"./components/index.js\";\nexport * from \"./lib/index.js\";\n","import {\n createContext,\n useContext,\n useState,\n ReactNode,\n useEffect,\n} from \"react\";\nimport { useAuthorizedFetch } from \"../lib/authorizedFetch.js\";\n\nlet validateSessionPromise: Promise<void> | null = null;\n\ninterface AuthContextType {\n userId: string | null;\n setUserId: (userId: string | null) => void;\n validateSession: () => Promise<void>;\n}\n\nconst AuthContext = createContext<AuthContextType | undefined>(undefined);\n\nexport const AuthProvider = ({ children }: { children: ReactNode }) => {\n const authorizedFetch = useAuthorizedFetch();\n const [userId, setUserId] = useState<string | null>(null);\n\n const validateSession = async (): Promise<void> => {\n if (validateSessionPromise) return validateSessionPromise;\n\n validateSessionPromise = (async () => {\n try {\n console.log(\"Finding out who we are!\");\n const res = await authorizedFetch(`/oauth/me`);\n if (!res.ok) throw new Error(\"Invalid session\");\n\n const data = await res.json();\n if (data?.userId) {\n console.log(`User found! ${data.userId}`);\n setUserId(data.userId);\n } else {\n setUserId(null);\n }\n } catch {\n setUserId(null);\n } finally {\n validateSessionPromise = null;\n }\n })();\n return validateSessionPromise;\n };\n\n useEffect(() => {\n validateSession();\n }, []);\n\n return (\n <AuthContext.Provider value={{ userId, setUserId, validateSession }}>\n {children}\n </AuthContext.Provider>\n );\n};\n\nexport const useAuth = () => {\n const ctx = useContext(AuthContext);\n if (!ctx) throw new Error(\"useAuth must be used within AuthProvider\");\n return ctx;\n};\n","import { useCallback } from \"react\";\n\nlet refreshPromise: Promise<Response> | null = null;\n\nexport function useAuthorizedFetch() {\n return useCallback(createAuthorizedFetch(), []);\n}\n\nexport function createAuthorizedFetch() {\n const authorizedFetch = async (\n input: RequestInfo,\n init: RequestInit = {}\n ): Promise<Response> => {\n const csrfToken = document.cookie\n .split(\"; \")\n .find((row) => row.startsWith(\"csrf-token=\"))\n ?.split(\"=\")[1];\n\n let response = await fetch(input, {\n ...init,\n credentials: \"include\",\n headers: {\n ...init.headers,\n ...(csrfToken ? { \"x-csrf-token\": csrfToken } : {}),\n },\n });\n\n if (response.status !== 401) {\n return response;\n }\n\n if (!refreshPromise) {\n refreshPromise = fetch(`/oauth/refresh-token`, {\n method: \"POST\",\n credentials: \"include\",\n }).finally(() => {\n refreshPromise = null;\n });\n }\n\n const refreshResponse = await refreshPromise;\n\n if (!refreshResponse.ok) {\n return response;\n }\n\n const retryAfter = parseInt(\n refreshResponse.headers.get(\"Retry-After\") ?? \"0\",\n 10\n );\n\n if (!isNaN(retryAfter) && retryAfter > 0) {\n await new Promise((resolve) => setTimeout(resolve, retryAfter * 1000));\n }\n\n return await authorizedFetch(input, init);\n };\n\n return authorizedFetch;\n}\n","import type { AuthProvider } from \"@plasius/entity-manager\";\n\nexport function useLogin() {\n return async function loginWithProvider(provider: AuthProvider) {\n const returnTo = window.location.pathname;\n const state = btoa(returnTo);\n window.location.href = `/oauth/${provider}?state=${state}`;\n };\n}\n","import { useAuthorizedFetch } from \"./authorizedFetch.js\";\n\nexport function useLogout() {\n const authorizedFetch = useAuthorizedFetch();\n return async function logout() {\n try {\n const res = await authorizedFetch(`/oauth/logout`, {\n method: \"POST\",\n credentials: \"include\",\n });\n\n if (!res.ok) {\n console.error(\"Logout failed\", await res.text());\n }\n } catch (err) {\n console.error(\"Logout error\", err);\n } finally {\n window.location.href = \"/\";\n }\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,gBAMO;;;ACNP,mBAA4B;AAE5B,IAAI,iBAA2C;AAExC,SAAS,qBAAqB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AAAA,MACjD;AAAA,IACF,SAAS,KAAK;AACZ,cAAQ,MAAM,gBAAgB,GAAG;AAAA,IACnC,UAAE;AACA,aAAO,SAAS,OAAO;AAAA,IACzB;AAAA,EACF;AACF;","names":["import_react"]}
@@ -0,0 +1,22 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { ReactNode } from 'react';
3
+ import { AuthProvider as AuthProvider$1 } from '@plasius/entity-manager';
4
+
5
+ interface AuthContextType {
6
+ userId: string | null;
7
+ setUserId: (userId: string | null) => void;
8
+ validateSession: () => Promise<void>;
9
+ }
10
+ declare const AuthProvider: ({ children }: {
11
+ children: ReactNode;
12
+ }) => react_jsx_runtime.JSX.Element;
13
+ declare const useAuth: () => AuthContextType;
14
+
15
+ declare function useAuthorizedFetch(): (input: RequestInfo, init?: RequestInit) => Promise<Response>;
16
+ declare function createAuthorizedFetch(): (input: RequestInfo, init?: RequestInit) => Promise<Response>;
17
+
18
+ declare function useLogin(): (provider: AuthProvider$1) => Promise<void>;
19
+
20
+ declare function useLogout(): () => Promise<void>;
21
+
22
+ export { AuthProvider, createAuthorizedFetch, useAuth, useAuthorizedFetch, useLogin, useLogout };
@@ -0,0 +1,22 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { ReactNode } from 'react';
3
+ import { AuthProvider as AuthProvider$1 } from '@plasius/entity-manager';
4
+
5
+ interface AuthContextType {
6
+ userId: string | null;
7
+ setUserId: (userId: string | null) => void;
8
+ validateSession: () => Promise<void>;
9
+ }
10
+ declare const AuthProvider: ({ children }: {
11
+ children: ReactNode;
12
+ }) => react_jsx_runtime.JSX.Element;
13
+ declare const useAuth: () => AuthContextType;
14
+
15
+ declare function useAuthorizedFetch(): (input: RequestInfo, init?: RequestInit) => Promise<Response>;
16
+ declare function createAuthorizedFetch(): (input: RequestInfo, init?: RequestInit) => Promise<Response>;
17
+
18
+ declare function useLogin(): (provider: AuthProvider$1) => Promise<void>;
19
+
20
+ declare function useLogout(): () => Promise<void>;
21
+
22
+ export { AuthProvider, createAuthorizedFetch, useAuth, useAuthorizedFetch, useLogin, useLogout };
package/dist/index.js ADDED
@@ -0,0 +1,129 @@
1
+ // src/components/AuthContext.tsx
2
+ import {
3
+ createContext,
4
+ useContext,
5
+ useState,
6
+ useEffect
7
+ } from "react";
8
+
9
+ // src/lib/authorizedFetch.ts
10
+ import { useCallback } from "react";
11
+ var refreshPromise = null;
12
+ function useAuthorizedFetch() {
13
+ return useCallback(createAuthorizedFetch(), []);
14
+ }
15
+ function createAuthorizedFetch() {
16
+ const authorizedFetch = async (input, init = {}) => {
17
+ const csrfToken = document.cookie.split("; ").find((row) => row.startsWith("csrf-token="))?.split("=")[1];
18
+ let response = await fetch(input, {
19
+ ...init,
20
+ credentials: "include",
21
+ headers: {
22
+ ...init.headers,
23
+ ...csrfToken ? { "x-csrf-token": csrfToken } : {}
24
+ }
25
+ });
26
+ if (response.status !== 401) {
27
+ return response;
28
+ }
29
+ if (!refreshPromise) {
30
+ refreshPromise = fetch(`/oauth/refresh-token`, {
31
+ method: "POST",
32
+ credentials: "include"
33
+ }).finally(() => {
34
+ refreshPromise = null;
35
+ });
36
+ }
37
+ const refreshResponse = await refreshPromise;
38
+ if (!refreshResponse.ok) {
39
+ return response;
40
+ }
41
+ const retryAfter = parseInt(
42
+ refreshResponse.headers.get("Retry-After") ?? "0",
43
+ 10
44
+ );
45
+ if (!isNaN(retryAfter) && retryAfter > 0) {
46
+ await new Promise((resolve) => setTimeout(resolve, retryAfter * 1e3));
47
+ }
48
+ return await authorizedFetch(input, init);
49
+ };
50
+ return authorizedFetch;
51
+ }
52
+
53
+ // src/components/AuthContext.tsx
54
+ import { jsx } from "react/jsx-runtime";
55
+ var validateSessionPromise = null;
56
+ var AuthContext = createContext(void 0);
57
+ var AuthProvider = ({ children }) => {
58
+ const authorizedFetch = useAuthorizedFetch();
59
+ const [userId, setUserId] = useState(null);
60
+ const validateSession = async () => {
61
+ if (validateSessionPromise) return validateSessionPromise;
62
+ validateSessionPromise = (async () => {
63
+ try {
64
+ console.log("Finding out who we are!");
65
+ const res = await authorizedFetch(`/oauth/me`);
66
+ if (!res.ok) throw new Error("Invalid session");
67
+ const data = await res.json();
68
+ if (data?.userId) {
69
+ console.log(`User found! ${data.userId}`);
70
+ setUserId(data.userId);
71
+ } else {
72
+ setUserId(null);
73
+ }
74
+ } catch {
75
+ setUserId(null);
76
+ } finally {
77
+ validateSessionPromise = null;
78
+ }
79
+ })();
80
+ return validateSessionPromise;
81
+ };
82
+ useEffect(() => {
83
+ validateSession();
84
+ }, []);
85
+ return /* @__PURE__ */ jsx(AuthContext.Provider, { value: { userId, setUserId, validateSession }, children });
86
+ };
87
+ var useAuth = () => {
88
+ const ctx = useContext(AuthContext);
89
+ if (!ctx) throw new Error("useAuth must be used within AuthProvider");
90
+ return ctx;
91
+ };
92
+
93
+ // src/lib/login.ts
94
+ function useLogin() {
95
+ return async function loginWithProvider(provider) {
96
+ const returnTo = window.location.pathname;
97
+ const state = btoa(returnTo);
98
+ window.location.href = `/oauth/${provider}?state=${state}`;
99
+ };
100
+ }
101
+
102
+ // src/lib/logout.ts
103
+ function useLogout() {
104
+ const authorizedFetch = useAuthorizedFetch();
105
+ return async function logout() {
106
+ try {
107
+ const res = await authorizedFetch(`/oauth/logout`, {
108
+ method: "POST",
109
+ credentials: "include"
110
+ });
111
+ if (!res.ok) {
112
+ console.error("Logout failed", await res.text());
113
+ }
114
+ } catch (err) {
115
+ console.error("Logout error", err);
116
+ } finally {
117
+ window.location.href = "/";
118
+ }
119
+ };
120
+ }
121
+ export {
122
+ AuthProvider,
123
+ createAuthorizedFetch,
124
+ useAuth,
125
+ useAuthorizedFetch,
126
+ useLogin,
127
+ useLogout
128
+ };
129
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/components/AuthContext.tsx","../src/lib/authorizedFetch.ts","../src/lib/login.ts","../src/lib/logout.ts"],"sourcesContent":["import {\n createContext,\n useContext,\n useState,\n ReactNode,\n useEffect,\n} from \"react\";\nimport { useAuthorizedFetch } from \"../lib/authorizedFetch.js\";\n\nlet validateSessionPromise: Promise<void> | null = null;\n\ninterface AuthContextType {\n userId: string | null;\n setUserId: (userId: string | null) => void;\n validateSession: () => Promise<void>;\n}\n\nconst AuthContext = createContext<AuthContextType | undefined>(undefined);\n\nexport const AuthProvider = ({ children }: { children: ReactNode }) => {\n const authorizedFetch = useAuthorizedFetch();\n const [userId, setUserId] = useState<string | null>(null);\n\n const validateSession = async (): Promise<void> => {\n if (validateSessionPromise) return validateSessionPromise;\n\n validateSessionPromise = (async () => {\n try {\n console.log(\"Finding out who we are!\");\n const res = await authorizedFetch(`/oauth/me`);\n if (!res.ok) throw new Error(\"Invalid session\");\n\n const data = await res.json();\n if (data?.userId) {\n console.log(`User found! ${data.userId}`);\n setUserId(data.userId);\n } else {\n setUserId(null);\n }\n } catch {\n setUserId(null);\n } finally {\n validateSessionPromise = null;\n }\n })();\n return validateSessionPromise;\n };\n\n useEffect(() => {\n validateSession();\n }, []);\n\n return (\n <AuthContext.Provider value={{ userId, setUserId, validateSession }}>\n {children}\n </AuthContext.Provider>\n );\n};\n\nexport const useAuth = () => {\n const ctx = useContext(AuthContext);\n if (!ctx) throw new Error(\"useAuth must be used within AuthProvider\");\n return ctx;\n};\n","import { useCallback } from \"react\";\n\nlet refreshPromise: Promise<Response> | null = null;\n\nexport function useAuthorizedFetch() {\n return useCallback(createAuthorizedFetch(), []);\n}\n\nexport function createAuthorizedFetch() {\n const authorizedFetch = async (\n input: RequestInfo,\n init: RequestInit = {}\n ): Promise<Response> => {\n const csrfToken = document.cookie\n .split(\"; \")\n .find((row) => row.startsWith(\"csrf-token=\"))\n ?.split(\"=\")[1];\n\n let response = await fetch(input, {\n ...init,\n credentials: \"include\",\n headers: {\n ...init.headers,\n ...(csrfToken ? { \"x-csrf-token\": csrfToken } : {}),\n },\n });\n\n if (response.status !== 401) {\n return response;\n }\n\n if (!refreshPromise) {\n refreshPromise = fetch(`/oauth/refresh-token`, {\n method: \"POST\",\n credentials: \"include\",\n }).finally(() => {\n refreshPromise = null;\n });\n }\n\n const refreshResponse = await refreshPromise;\n\n if (!refreshResponse.ok) {\n return response;\n }\n\n const retryAfter = parseInt(\n refreshResponse.headers.get(\"Retry-After\") ?? \"0\",\n 10\n );\n\n if (!isNaN(retryAfter) && retryAfter > 0) {\n await new Promise((resolve) => setTimeout(resolve, retryAfter * 1000));\n }\n\n return await authorizedFetch(input, init);\n };\n\n return authorizedFetch;\n}\n","import type { AuthProvider } from \"@plasius/entity-manager\";\n\nexport function useLogin() {\n return async function loginWithProvider(provider: AuthProvider) {\n const returnTo = window.location.pathname;\n const state = btoa(returnTo);\n window.location.href = `/oauth/${provider}?state=${state}`;\n };\n}\n","import { useAuthorizedFetch } from \"./authorizedFetch.js\";\n\nexport function useLogout() {\n const authorizedFetch = useAuthorizedFetch();\n return async function logout() {\n try {\n const res = await authorizedFetch(`/oauth/logout`, {\n method: \"POST\",\n credentials: \"include\",\n });\n\n if (!res.ok) {\n console.error(\"Logout failed\", await res.text());\n }\n } catch (err) {\n console.error(\"Logout error\", err);\n } finally {\n window.location.href = \"/\";\n }\n };\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,OACK;;;ACNP,SAAS,mBAAmB;AAE5B,IAAI,iBAA2C;AAExC,SAAS,qBAAqB;AACnC,SAAO,YAAY,sBAAsB,GAAG,CAAC,CAAC;AAChD;AAEO,SAAS,wBAAwB;AACtC,QAAM,kBAAkB,OACtB,OACA,OAAoB,CAAC,MACC;AACtB,UAAM,YAAY,SAAS,OACxB,MAAM,IAAI,EACV,KAAK,CAAC,QAAQ,IAAI,WAAW,aAAa,CAAC,GAC1C,MAAM,GAAG,EAAE,CAAC;AAEhB,QAAI,WAAW,MAAM,MAAM,OAAO;AAAA,MAChC,GAAG;AAAA,MACH,aAAa;AAAA,MACb,SAAS;AAAA,QACP,GAAG,KAAK;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oBAAU,IAAI;AAAA,QAChB;AAAA,MACF,QAAQ;AACN,kBAAU,IAAI;AAAA,MAChB,UAAE;AACA,iCAAyB;AAAA,MAC3B;AAAA,IACF,GAAG;AACH,WAAO;AAAA,EACT;AAEA,YAAU,MAAM;AACd,oBAAgB;AAAA,EAClB,GAAG,CAAC,CAAC;AAEL,SACE,oBAAC,YAAY,UAAZ,EAAqB,OAAO,EAAE,QAAQ,WAAW,gBAAgB,GAC/D,UACH;AAEJ;AAEO,IAAM,UAAU,MAAM;AAC3B,QAAM,MAAM,WAAW,WAAW;AAClC,MAAI,CAAC,IAAK,OAAM,IAAI,MAAM,0CAA0C;AACpE,SAAO;AACT;;;AE7DO,SAAS,WAAW;AACzB,SAAO,eAAe,kBAAkB,UAAwB;AAC9D,UAAM,WAAW,OAAO,SAAS;AACjC,UAAM,QAAQ,KAAK,QAAQ;AAC3B,WAAO,SAAS,OAAO,UAAU,QAAQ,UAAU,KAAK;AAAA,EAC1D;AACF;;;ACNO,SAAS,YAAY;AAC1B,QAAM,kBAAkB,mBAAmB;AAC3C,SAAO,eAAe,SAAS;AAC7B,QAAI;AACF,YAAM,MAAM,MAAM,gBAAgB,iBAAiB;AAAA,QACjD,QAAQ;AAAA,QACR,aAAa;AAAA,MACf,CAAC;AAED,UAAI,CAAC,IAAI,IAAI;AACX,gBAAQ,MAAM,iBAAiB,MAAM,IAAI,KAAK,CAAC;AAAA,MACjD;AAAA,IACF,SAAS,KAAK;AACZ,cAAQ,MAAM,gBAAgB,GAAG;AAAA,IACnC,UAAE;AACA,aAAO,SAAS,OAAO;AAAA,IACzB;AAAA,EACF;AACF;","names":[]}
package/package.json ADDED
@@ -0,0 +1,86 @@
1
+ {
2
+ "name": "@plasius/auth",
3
+ "version": "1.0.0",
4
+ "description": "Authentication helpers and React context for Plasius applications.",
5
+ "type": "module",
6
+ "sideEffects": false,
7
+ "main": "./dist/index.cjs",
8
+ "module": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "files": [
11
+ "dist",
12
+ "README.md",
13
+ "CHANGELOG.md",
14
+ "LICENSE",
15
+ "SECURITY.md",
16
+ "CODE_OF_CONDUCT.md",
17
+ "CONTRIBUTORS.md"
18
+ ],
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/index.d.ts",
22
+ "import": "./dist/index.js",
23
+ "require": "./dist/index.cjs"
24
+ },
25
+ "./package.json": "./package.json"
26
+ },
27
+ "scripts": {
28
+ "build": "tsup",
29
+ "test": "vitest run",
30
+ "test:watch": "vitest",
31
+ "test:coverage": "vitest run --coverage",
32
+ "lint": "eslint .",
33
+ "prepare": "npm run build",
34
+ "clean": "rimraf dist"
35
+ },
36
+ "keywords": [
37
+ "auth",
38
+ "oauth",
39
+ "react",
40
+ "plasius"
41
+ ],
42
+ "author": "Plasius LTD <development@plasius.co.uk>",
43
+ "license": "Apache-2.0",
44
+ "repository": {
45
+ "type": "git",
46
+ "url": "git+https://github.com/Plasius-LTD/auth.git"
47
+ },
48
+ "bugs": {
49
+ "url": "https://github.com/Plasius-LTD/auth/issues"
50
+ },
51
+ "homepage": "https://github.com/Plasius-LTD/auth#readme",
52
+ "dependencies": {
53
+ "@plasius/entity-manager": "^1.0.4"
54
+ },
55
+ "peerDependencies": {
56
+ "react": "^19.1.0"
57
+ },
58
+ "devDependencies": {
59
+ "@types/node": "^24.3.1",
60
+ "@types/react": "^19.1.8",
61
+ "@typescript-eslint/eslint-plugin": "^8.43.0",
62
+ "@typescript-eslint/parser": "^8.43.0",
63
+ "@vitest/coverage-v8": "^3.2.4",
64
+ "eslint": "^9.35.0",
65
+ "react": "^19.1.0",
66
+ "rimraf": "^6.0.1",
67
+ "tsup": "^8.5.0",
68
+ "tsx": "^4.20.5",
69
+ "typescript": "^5.9.2",
70
+ "vitest": "^3.2.4"
71
+ },
72
+ "publishConfig": {
73
+ "access": "public"
74
+ },
75
+ "funding": [
76
+ {
77
+ "type": "patreon",
78
+ "url": "https://www.patreon.com/c/plasiusltd/membership"
79
+ },
80
+ {
81
+ "type": "github",
82
+ "url": "https://github.com/sponsors/Plasius-LTD"
83
+ }
84
+ ],
85
+ "private": false
86
+ }