sekisho 0.2.0 → 0.2.1

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/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use client";Object.defineProperty(exports,"__esModule",{value:!0});var r=require("foxact/use-isomorphic-layout-effect"),e=require("foxact/nullthrow"),t=require("react"),s=require("foxact/use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired"),o=require("react/jsx-runtime");let i=Object.getOwnPropertyDescriptor(Error,"stackTraceLimit"),n=i?.writable&&"number"==typeof i.value;function c(r){let e=Error.stackTraceLimit;n&&(Error.stackTraceLimit=0);let t=r();return n&&(Error.stackTraceLimit=e),t}class u extends Error{constructor(...r){super(...r),this.name="NotAuthenticatedError",this.notAuthenticated=!0,this.$sekishoError=!0}}function a(r){return!!r&&"object"==typeof r&&"notAuthenticated"in r&&!0===r.notAuthenticated&&"$sekishoError"in r&&!0===r.$sekishoError}let h=t.createContext(null);function d({error:o,children:i}){let{onNeedLogin:n}=e.nullthrow(t.useContext(h),"useSekishoOptions must be used within a SekishoOptionsProvider"),c=a(o),u=s.useStableHandler(n);return(r.useLayoutEffect(()=>{c&&u()},[c,u]),c)?null:i}class l extends t.Component{constructor(r){super(r),this.state={needLoginErrorObject:null}}static getDerivedStateFromError(r){if(a(r))return{needLoginErrorObject:r};throw r}render(){return this.state.needLoginErrorObject?o.jsx(d,{error:this.state.needLoginErrorObject,children:this.props.children}):this.props.children}}class p extends Error{constructor(...r){super(...r),this.name="AccessRestrictedError",this.accessRestricted=!0,this.$sekishoError=!0}}function E(r){return!!r&&"object"==typeof r&&"accessRestricted"in r&&!0===r.accessRestricted&&"$sekishoError"in r&&!0===r.$sekishoError}class x extends t.Component{constructor(r){super(r),this.state={restricted:!1}}static getDerivedStateFromError(r){if(E(r))return{restricted:!0};throw r}render(){return this.state.restricted?this.props.fallback:this.props.children}}exports.AccessRestrictedError=p,exports.NotAuthenticatedError=u,exports.SekishoAccessContainer=x,exports.SekishoErrorBoundary=l,exports.SekishoErrorWrapper=d,exports.SekishoProvider=function({children:r,...e}){return o.jsx(h.Provider,{value:e,children:o.jsx(l,{children:r})})},exports.accessRestricted=function(r){throw c(()=>new p(r))},exports.isAccessRestrictedError=E,exports.isNeedLoginError=a,exports.needLogin=function(r){throw c(()=>new u(r))};
1
+ "use client";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("foxact/create-stackless-error"),r=require("foxact/use-isomorphic-layout-effect"),t=require("foxact/nullthrow"),s=require("react"),o=require("foxact/use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired"),i=require("react/jsx-runtime");class n extends Error{constructor(...e){super(...e),this.name="NotAuthenticatedError",this.notAuthenticated=!0,this.$sekishoError=!0,this.digest="BAILOUT_TO_CLIENT_SIDE_RENDERING"}}function c(e){return!!e&&"object"==typeof e&&"notAuthenticated"in e&&!0===e.notAuthenticated&&"$sekishoError"in e&&!0===e.$sekishoError}let u=s.createContext(null);function a({error:e,children:i}){let{onNeedLogin:n}=t.nullthrow(s.useContext(u),"useSekishoOptions must be used within a SekishoOptionsProvider"),h=c(e),d=o.useStableHandler(n);return(r.useLayoutEffect(()=>{h&&d()},[h,d]),h)?null:i}class h extends s.Component{constructor(e){super(e),this.state={needLoginErrorObject:null}}static getDerivedStateFromError(e){if(c(e))return{needLoginErrorObject:e};throw e}render(){return this.state.needLoginErrorObject?i.jsx(a,{error:this.state.needLoginErrorObject,children:this.props.children}):this.props.children}}class d extends Error{constructor(...e){super(...e),this.name="AccessRestrictedError",this.accessRestricted=!0,this.$sekishoError=!0,this.digest="BAILOUT_TO_CLIENT_SIDE_RENDERING"}}function l(e){return!!e&&"object"==typeof e&&"accessRestricted"in e&&!0===e.accessRestricted&&"$sekishoError"in e&&!0===e.$sekishoError}class p extends s.Component{constructor(e){super(e),this.state={restricted:!1}}static getDerivedStateFromError(e){if(l(e))return{restricted:!0};throw e}render(){return this.state.restricted?this.props.fallback:this.props.children}}exports.AccessRestrictedError=d,exports.NotAuthenticatedError=n,exports.SekishoAccessContainer=p,exports.SekishoErrorBoundary=h,exports.SekishoErrorWrapper=a,exports.SekishoProvider=function({children:e,...r}){return i.jsx(u.Provider,{value:r,children:i.jsx(h,{children:e})})},exports.accessRestricted=function(r){throw e.createStacklessError(()=>new d(r))},exports.isAccessRestrictedError=l,exports.isNeedLoginError=c,exports.needLogin=function(r){throw e.createStacklessError(()=>new n(r))};
package/dist/index.d.ts CHANGED
@@ -6,6 +6,24 @@ declare class NotAuthenticatedError extends Error {
6
6
  readonly name = "NotAuthenticatedError";
7
7
  readonly notAuthenticated = true;
8
8
  readonly $sekishoError = true;
9
+ /**
10
+ * Normally, when React encounters an error during rendering in the server,
11
+ * it will find the nearest Suspense boundary and render its fallback (on
12
+ * the client it would find the nearest error boundary instead).
13
+ *
14
+ * For various purposes, Next.js also uses this mechanism to bail out of
15
+ * server-side rendering to do client-side rendering only. Thus Next.js
16
+ * create this magic digest 'BAILOUT_TO_CLIENT_SIDE_RENDERING' that does
17
+ * nothing but allow every error report (console, reportError, etc.) to
18
+ * skip this error
19
+ *
20
+ * Next.js doesn't handle this error in any special way. It is React itself
21
+ * who contains the "special handling".
22
+ *
23
+ * So we can safely re-use this digest to make sure that the error is not
24
+ * reported by Next.js
25
+ */
26
+ readonly digest = "BAILOUT_TO_CLIENT_SIDE_RENDERING";
9
27
  }
10
28
  declare function isNeedLoginError(error: unknown): error is NotAuthenticatedError;
11
29
  /**
@@ -54,6 +72,24 @@ declare class AccessRestrictedError extends Error {
54
72
  readonly name = "AccessRestrictedError";
55
73
  readonly accessRestricted = true;
56
74
  readonly $sekishoError = true;
75
+ /**
76
+ * Normally, when React encounters an error during rendering in the server,
77
+ * it will find the nearest Suspense boundary and render its fallback (on
78
+ * the client it would find the nearest error boundary instead).
79
+ *
80
+ * For various purposes, Next.js also uses this mechanism to bail out of
81
+ * server-side rendering to do client-side rendering only. Thus Next.js
82
+ * create this magic digest 'BAILOUT_TO_CLIENT_SIDE_RENDERING' that does
83
+ * nothing but allow every error report (console, reportError, etc.) to
84
+ * skip this error
85
+ *
86
+ * Next.js doesn't handle this error in any special way. It is React itself
87
+ * who contains the "special handling".
88
+ *
89
+ * So we can safely re-use this digest to make sure that the error is not
90
+ * reported by Next.js
91
+ */
92
+ readonly digest = "BAILOUT_TO_CLIENT_SIDE_RENDERING";
57
93
  }
58
94
  declare function isAccessRestrictedError(error: unknown): error is AccessRestrictedError;
59
95
  /**
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- "use client";import{useLayoutEffect as r}from"foxact/use-isomorphic-layout-effect";import{nullthrow as e}from"foxact/nullthrow";import{createContext as t,useContext as o,Component as s}from"react";import{useStableHandler as i}from"foxact/use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired";import{jsx as n}from"react/jsx-runtime";let c=Object.getOwnPropertyDescriptor(Error,"stackTraceLimit"),a=c?.writable&&"number"==typeof c.value;function h(r){let e=Error.stackTraceLimit;a&&(Error.stackTraceLimit=0);let t=r();return a&&(Error.stackTraceLimit=e),t}class u extends Error{constructor(...r){super(...r),this.name="NotAuthenticatedError",this.notAuthenticated=!0,this.$sekishoError=!0}}function d(r){return!!r&&"object"==typeof r&&"notAuthenticated"in r&&!0===r.notAuthenticated&&"$sekishoError"in r&&!0===r.$sekishoError}function l(r){throw h(()=>new u(r))}let p=t(null);function E({error:t,children:s}){let{onNeedLogin:n}=e(o(p),"useSekishoOptions must be used within a SekishoOptionsProvider"),c=d(t),a=i(n);return(r(()=>{c&&a()},[c,a]),c)?null:s}class f extends s{constructor(r){super(r),this.state={needLoginErrorObject:null}}static getDerivedStateFromError(r){if(d(r))return{needLoginErrorObject:r};throw r}render(){return this.state.needLoginErrorObject?n(E,{error:this.state.needLoginErrorObject,children:this.props.children}):this.props.children}}function m({children:r,...e}){return n(p.Provider,{value:e,children:n(f,{children:r})})}class k extends Error{constructor(...r){super(...r),this.name="AccessRestrictedError",this.accessRestricted=!0,this.$sekishoError=!0}}function w(r){return!!r&&"object"==typeof r&&"accessRestricted"in r&&!0===r.accessRestricted&&"$sekishoError"in r&&!0===r.$sekishoError}function b(r){throw h(()=>new k(r))}class g extends s{constructor(r){super(r),this.state={restricted:!1}}static getDerivedStateFromError(r){if(w(r))return{restricted:!0};throw r}render(){return this.state.restricted?this.props.fallback:this.props.children}}export{k as AccessRestrictedError,u as NotAuthenticatedError,g as SekishoAccessContainer,f as SekishoErrorBoundary,E as SekishoErrorWrapper,m as SekishoProvider,b as accessRestricted,w as isAccessRestrictedError,d as isNeedLoginError,l as needLogin};
1
+ "use client";import{createStacklessError as r}from"foxact/create-stackless-error";import{useLayoutEffect as e}from"foxact/use-isomorphic-layout-effect";import{nullthrow as t}from"foxact/nullthrow";import{createContext as o,useContext as s,Component as i}from"react";import{useStableHandler as n}from"foxact/use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired";import{jsx as c}from"react/jsx-runtime";class h extends Error{constructor(...r){super(...r),this.name="NotAuthenticatedError",this.notAuthenticated=!0,this.$sekishoError=!0,this.digest="BAILOUT_TO_CLIENT_SIDE_RENDERING"}}function d(r){return!!r&&"object"==typeof r&&"notAuthenticated"in r&&!0===r.notAuthenticated&&"$sekishoError"in r&&!0===r.$sekishoError}function a(e){throw r(()=>new h(e))}let u=o(null);function l({error:r,children:o}){let{onNeedLogin:i}=t(s(u),"useSekishoOptions must be used within a SekishoOptionsProvider"),c=d(r),h=n(i);return(e(()=>{c&&h()},[c,h]),c)?null:o}class E extends i{constructor(r){super(r),this.state={needLoginErrorObject:null}}static getDerivedStateFromError(r){if(d(r))return{needLoginErrorObject:r};throw r}render(){return this.state.needLoginErrorObject?c(l,{error:this.state.needLoginErrorObject,children:this.props.children}):this.props.children}}function p({children:r,...e}){return c(u.Provider,{value:e,children:c(E,{children:r})})}class f extends Error{constructor(...r){super(...r),this.name="AccessRestrictedError",this.accessRestricted=!0,this.$sekishoError=!0,this.digest="BAILOUT_TO_CLIENT_SIDE_RENDERING"}}function m(r){return!!r&&"object"==typeof r&&"accessRestricted"in r&&!0===r.accessRestricted&&"$sekishoError"in r&&!0===r.$sekishoError}function k(e){throw r(()=>new f(e))}class w extends i{constructor(r){super(r),this.state={restricted:!1}}static getDerivedStateFromError(r){if(m(r))return{restricted:!0};throw r}render(){return this.state.restricted?this.props.fallback:this.props.children}}export{f as AccessRestrictedError,h as NotAuthenticatedError,w as SekishoAccessContainer,E as SekishoErrorBoundary,l as SekishoErrorWrapper,p as SekishoProvider,k as accessRestricted,m as isAccessRestrictedError,d as isNeedLoginError,a as needLogin};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sekisho",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Authentication and Access Control for any React app",
5
5
  "repository": {
6
6
  "type": "git",
@@ -26,10 +26,10 @@
26
26
  "author": "Sukka <https://skk.moe>",
27
27
  "license": "MIT",
28
28
  "dependencies": {
29
- "foxact": "^0.3.0"
29
+ "foxact": "^0.3.1"
30
30
  },
31
31
  "devDependencies": {
32
- "@swc/core": "^1.15.30",
32
+ "@swc/core": "^1.15.32",
33
33
  "@types/react": "^19.2.14",
34
34
  "bunchee": "^6.10.0"
35
35
  },