@bananacool467/authtics-host 0.1.4 → 0.1.5

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Authtics Host
2
2
 
3
- Version 0.1.4
3
+ Version 0.1.5
4
4
  License: MIT
5
5
 
6
6
  Authtics Host is a framework inspired by Next.js. Authtics Host supports SSR (Server-Side Rendering) and uses esbuild.
@@ -163,7 +163,17 @@ The information the Developer Panel shows outside of the tabs is just your **DAT
163
163
 
164
164
  **(NOTE: If you do not set DAT restriction (Which will be explained on how to set it up in the next section), you will only get access to the Console and Network tabs)**
165
165
 
166
- ## Developer Panel Notes And Warnings And DAT (Developer Access Token)
166
+ The Developer Panel also have remote buttons:
167
+
168
+ **Restart App** — Restarts the website.
169
+ **Shut Down App** — Stops the website.
170
+ **Pause Users**/**Resume Users** — Stops users from reaching a site and they will get a JSON error message like this when visiting if Pause Users is on:
171
+ ```json
172
+ { "message": "unhandled request" }
173
+ ```
174
+ unless you click **Resume Users**.
175
+
176
+ ## Developer Panel Notes And DAT (Developer Access Token)
167
177
 
168
178
  A DAT (Developer Access Token) is your token that is used to access the Developer Panel.
169
179
 
@@ -185,7 +195,7 @@ But if you have multiple DATs, then use:
185
195
 
186
196
  There isn't any limit of DATs you can add.
187
197
 
188
- **(Warning: Make sure `devMode` is set to `false` in production. If `devMode` is on and DAT restriction is disabled, anyone can access the restart and shutdown endpoints.)**
198
+ **(NOTE: Adding your DAT will give you access to Restart and Shutdown and Pause/Resume Users features)**
189
199
 
190
200
  ## Contacting The Developer Of Authtics Host
191
201
 
package/dist/cli.js CHANGED
@@ -9,6 +9,7 @@ let config_ = {};
9
9
  let uptime = 0;
10
10
  let totalRequests = 0;
11
11
  let users = 0;
12
+ let usersPaused = false;
12
13
  const jiti = createJiti(import.meta.url);
13
14
  const routes = new Map();
14
15
  const __filename = url.fileURLToPath(import.meta.url);
@@ -96,6 +97,48 @@ export default class App {
96
97
  server;
97
98
  constructor() {
98
99
  this.server = start();
100
+ this.get('/failed-to-handle', async (req, res) => {
101
+ if (!usersPaused) {
102
+ res.writeHead(302, {
103
+ 'Location': '/'
104
+ });
105
+ res.end();
106
+ return;
107
+ }
108
+ ;
109
+ res.writeHead(200, { "Content-Type": "application/json" });
110
+ res.end(JSON.stringify({
111
+ message: "unhandled request"
112
+ }));
113
+ });
114
+ this.post('/__authtics_host_apis__/set-users-paused', async (req, res) => {
115
+ const reqBody = (await getJsonBody(req));
116
+ let datMatched = false;
117
+ if (config_.dat && config_.dat == reqBody.dat)
118
+ datMatched = true;
119
+ if (config_.dat && Array.isArray(config_.dat) && config_.dat.includes(reqBody.dat))
120
+ datMatched = true;
121
+ if (datMatched) {
122
+ usersPaused = reqBody.paused;
123
+ res.writeHead(200, { "Content-Type": "application/json" });
124
+ res.end(JSON.stringify({
125
+ message: "ok"
126
+ }));
127
+ }
128
+ });
129
+ this.post('/__authtics_host_apis__/is-users-paused', async (req, res) => {
130
+ const reqBody = (await getJsonBody(req));
131
+ let datMatched = false;
132
+ if (config_.dat && config_.dat == reqBody.dat)
133
+ datMatched = true;
134
+ if (config_.dat && Array.isArray(config_.dat) && config_.dat.includes(reqBody.dat))
135
+ datMatched = true;
136
+ res.writeHead(200, { "Content-Type": "application/json" });
137
+ res.end(JSON.stringify({
138
+ paused: (datMatched ? false : usersPaused),
139
+ realInfo: usersPaused
140
+ }));
141
+ });
99
142
  this.post('/__authtics_host_apis__/get-dat-restriction-missing', async (req, res) => {
100
143
  const reqBody = (await getJsonBody(req));
101
144
  let datMatched = false;
@@ -345,10 +388,6 @@ async function start() {
345
388
  }
346
389
  catch {
347
390
  }
348
- if (config.autoPage == null)
349
- config.autoPage = true;
350
- if (config.autoFile == null)
351
- config.autoFile = true;
352
391
  const PORT = config.port ?? 3000;
353
392
  const showPanel = config.devMode !== false;
354
393
  const autoPaging = config.autoPage !== false;
package/dist/config.d.ts CHANGED
@@ -6,10 +6,10 @@ export interface AuthticsConfig {
6
6
  compilerType?: 'esbuild' | 'babel';
7
7
  hotReload?: boolean;
8
8
  dat?: string | string[];
9
- showError?: boolean | null;
10
- autoPage?: boolean | null;
9
+ showError?: boolean;
10
+ autoPage?: boolean;
11
11
  autoPageDir?: string;
12
- autoFile?: boolean | null;
12
+ autoFile?: boolean;
13
13
  autoFileDir?: string;
14
14
  }
15
15
  export declare function defineConfig(config: AuthticsConfig): AuthticsConfig;
package/dist/config.js CHANGED
@@ -1,7 +1,17 @@
1
1
  export function defineConfig(config) {
2
- if (config.autoPage == null)
2
+ if (config.autoPage == undefined)
3
3
  config.autoPage = true;
4
- if (config.autoFile == null)
4
+ if (config.autoFile == undefined)
5
5
  config.autoFile = true;
6
+ if (config.showError == undefined)
7
+ config.showError = true;
8
+ if (config.compilerType == undefined)
9
+ config.compilerType = 'esbuild';
10
+ if (config.ssr == undefined)
11
+ config.ssr = true;
12
+ if (config.port == undefined || config.port == 0)
13
+ config.port = 3000;
14
+ if (config.devMode == undefined)
15
+ config.devMode = true;
6
16
  return config;
7
17
  }
package/dist/devPanel.js CHANGED
@@ -221,21 +221,23 @@ function installNetworkInterceptor(onFetch, setFetch, onEventSource, setEventSou
221
221
  };
222
222
  window.EventSource.prototype = OriginalEventSource.prototype;
223
223
  Object.assign(window.EventSource, OriginalEventSource);
224
- const queryImg = document.querySelectorAll('img');
225
- const queryScript = document.querySelectorAll('script');
226
- const queryLink = document.querySelectorAll('link');
227
- queryImg.forEach((img) => {
228
- if (img.src)
229
- onResource({ url: img.src, type: 'img', id: fetchId++ });
230
- });
231
- queryScript.forEach((script) => {
232
- if (script.src)
233
- onResource({ url: script.src, type: 'script', id: fetchId++ });
234
- });
235
- queryLink.forEach((link) => {
236
- if (link.href)
237
- onResource({ url: link.href, type: 'link', id: fetchId++ });
238
- });
224
+ setTimeout(() => {
225
+ const queryImg = document.querySelectorAll('img');
226
+ const queryScript = document.querySelectorAll('script');
227
+ const queryLink = document.querySelectorAll('link');
228
+ queryImg.forEach((img) => {
229
+ if (img.src)
230
+ onResource({ url: img.src, type: 'img', id: fetchId++ });
231
+ });
232
+ queryScript.forEach((script) => {
233
+ if (script.src)
234
+ onResource({ url: script.src, type: 'script', id: fetchId++ });
235
+ });
236
+ queryLink.forEach((link) => {
237
+ if (link.href)
238
+ onResource({ url: link.href, type: 'link', id: fetchId++ });
239
+ });
240
+ }, 5000);
239
241
  }
240
242
  function installConsoleInterceptor() {
241
243
  if (window.__authtics_intercepted__)
@@ -308,6 +310,8 @@ export default function DevPanel() {
308
310
  const [ping__, setPing__] = useState(0);
309
311
  const [networkFetches, setNetworkFetches] = useState([]);
310
312
  const [eventSources, setEventSources] = useState([]);
313
+ const [usersPaused, setUsersPaused] = useState(false);
314
+ const [usersPausedRealInfo, setUsersPausedRealInfo] = useState(false);
311
315
  const [webSockets, setWebSockets] = useState([]);
312
316
  const [resourcesFound, setResourcesFound] = useState([]);
313
317
  const [status, setStatus] = useState(200);
@@ -393,7 +397,19 @@ export default function DevPanel() {
393
397
  if (resp.status === 200) {
394
398
  const data = await resp.json();
395
399
  setDatMatch(data.isMatching);
396
- if (!data.isMatching) {
400
+ const resp3 = await fetch('/__authtics_host_apis__/is-users-paused', {
401
+ method: 'POST',
402
+ headers: { 'Content-Type': 'application/json' },
403
+ body: JSON.stringify({ dat: localStorage.getItem('dat') })
404
+ });
405
+ let paused = false;
406
+ if (resp3.status === 200) {
407
+ const data = await resp3.json();
408
+ paused = data.paused;
409
+ setUsersPaused(paused);
410
+ setUsersPausedRealInfo(data.realInfo);
411
+ }
412
+ if (!data.isMatching && !paused) {
397
413
  doc?.getElementById('authtics-dev-panel-root')?.remove();
398
414
  }
399
415
  const resp2 = await fetch('/__authtics_host_apis__/get-dat-restriction-missing', {
@@ -732,6 +748,38 @@ export default function DevPanel() {
732
748
  }
733
749
  }));
734
750
  };
751
+ const pause_Resume_Users = async () => {
752
+ if (usersPausedRealInfo) {
753
+ const resp = await fetch('/__authtics_host_apis__/set-users-paused', {
754
+ method: 'POST',
755
+ headers: { 'Content-Type': 'application/json' },
756
+ body: JSON.stringify({
757
+ dat: localStorage.getItem('dat'),
758
+ paused: false
759
+ })
760
+ });
761
+ if (resp.status === 200) {
762
+ setUsersPausedRealInfo(false);
763
+ }
764
+ }
765
+ else {
766
+ const resp = await fetch('/__authtics_host_apis__/set-users-paused', {
767
+ method: 'POST',
768
+ headers: { 'Content-Type': 'application/json' },
769
+ body: JSON.stringify({
770
+ dat: localStorage.getItem('dat'),
771
+ paused: true
772
+ })
773
+ });
774
+ if (resp.status === 200) {
775
+ setUsersPausedRealInfo(true);
776
+ }
777
+ }
778
+ };
779
+ if (usersPaused) {
780
+ doc?.getElementById('root')?.remove();
781
+ window.location.href = '/failed-to-handle';
782
+ }
735
783
  return (_jsxs(_Fragment, { children: [_jsx("div", { style: {
736
784
  position: 'absolute',
737
785
  zIndex: 999999,
@@ -908,7 +956,7 @@ export default function DevPanel() {
908
956
  border: '1px solid #eee',
909
957
  fontSize: '11px',
910
958
  fontFamily: 'monospace'
911
- }, children: _jsxs("div", { style: { display: 'flex', justifyContent: 'space-between', gap: '8px', padding: '6px 10px' }, children: [_jsx("span", { style: { color: '#3b82f6', display: 'flex', gap: '4px', justifyContent: 'center', alignItems: 'center' }, children: r.type }), _jsx("span", { style: { flex: 1, overflow: 'hidden', color: '#333' }, children: r.url })] }) }, i)))] })] })) : routeOpen ? (_jsxs(_Fragment, { children: [_jsxs("div", { style: {
959
+ }, children: _jsxs("div", { style: { display: 'flex', justifyContent: 'space-between', gap: '8px', padding: '6px 10px' }, children: [_jsx("span", { style: { color: '#3b82f6', display: 'flex', gap: '4px', justifyContent: 'center', alignItems: 'center' }, children: r.type }), _jsx("span", { style: { flex: 1, color: '#333' }, children: r.url })] }) }, i)))] })] })) : routeOpen ? (_jsxs(_Fragment, { children: [_jsxs("div", { style: {
912
960
  padding: '6px 8px',
913
961
  borderBottom: '1px solid #ddd',
914
962
  background: '#fff',
@@ -1152,7 +1200,7 @@ export default function DevPanel() {
1152
1200
  gap: '6px',
1153
1201
  color: '#fff',
1154
1202
  flexDirection: 'row',
1155
- }, children: "Updates to security. Apps with version 0.0.1-beta.9 and over will now require DAT restriction to access remote features like restarting and shutting down the app." }) })) : (_jsx(_Fragment, {})), _jsx(PanelButton, { onClick: () => { restart(); }, fullWidth: true, style: { color: '#fff', justifyContent: 'center', height: '32px', background: '#ba4e4e' }, disabled: datRestrictionMissing, children: _jsx("span", { style: { display: 'flex', alignItems: 'center', gap: '6px', textAlign: 'center' }, children: "Restart App" }) }), datRestrictionMissing ? (_jsxs("span", { style: { display: 'flex', opacity: 0.5, fontSize: 10, justifyContent: 'center', alignItems: 'center', gap: '4px' }, children: [_jsx(Info, { size: 10 }), "Restarting the app is unavaliable. Set \"dat\" in the Authtics Host config to set restriction and then restart."] })) : (_jsx(_Fragment, {})), _jsx(PanelButton, { onClick: () => { shutDown(); }, fullWidth: true, style: { color: '#fff', justifyContent: 'center', height: '32px', background: '#ba4e4e' }, disabled: datRestrictionMissing, children: _jsx("span", { style: { display: 'flex', alignItems: 'center', gap: '6px', textAlign: 'center' }, children: "Shut Down App" }) }), datRestrictionMissing ? (_jsxs("span", { style: { display: 'flex', opacity: 0.5, fontSize: 10, justifyContent: 'center', alignItems: 'center', gap: '4px' }, children: [_jsx(Info, { size: 10 }), "Shutting down the app is unavaliable. Set \"dat\" in the Authtics Host config to set restriction and then restart."] })) : (_jsx(_Fragment, {}))] })] })) }) }), datMatch ? (_jsxs("div", { onClick: () => setOpen(o => !o), style: {
1203
+ }, children: "Updates to security. Apps with version 0.0.1-beta.9 and over will now require DAT restriction to access remote features like restarting and shutting down the app." }) })) : (_jsx(_Fragment, {})), _jsx(PanelButton, { onClick: () => { restart(); }, fullWidth: true, style: { color: '#fff', justifyContent: 'center', height: '32px', background: '#ba4e4e' }, disabled: datRestrictionMissing, children: _jsx("span", { style: { display: 'flex', alignItems: 'center', gap: '6px', textAlign: 'center' }, children: "Restart App" }) }), datRestrictionMissing ? (_jsxs("span", { style: { display: 'flex', opacity: 0.5, fontSize: 10, justifyContent: 'center', alignItems: 'center', gap: '4px' }, children: [_jsx(Info, { size: 10 }), "Restarting the app is unavaliable. Set \"dat\" in the Authtics Host config to set restriction and then restart."] })) : (_jsx(_Fragment, {})), _jsx(PanelButton, { onClick: () => { shutDown(); }, fullWidth: true, style: { color: '#fff', justifyContent: 'center', height: '32px', background: '#ba4e4e' }, disabled: datRestrictionMissing, children: _jsx("span", { style: { display: 'flex', alignItems: 'center', gap: '6px', textAlign: 'center' }, children: "Shut Down App" }) }), datRestrictionMissing ? (_jsxs("span", { style: { display: 'flex', opacity: 0.5, fontSize: 10, justifyContent: 'center', alignItems: 'center', gap: '4px' }, children: [_jsx(Info, { size: 10 }), "Shutting down the app is unavaliable. Set \"dat\" in the Authtics Host config to set restriction and then restart."] })) : (_jsx(_Fragment, {})), _jsx(PanelButton, { onClick: () => { pause_Resume_Users(); }, fullWidth: true, style: { color: '#fff', justifyContent: 'center', height: '32px', background: '#ba4e4e' }, disabled: datRestrictionMissing, children: _jsx("span", { style: { display: 'flex', alignItems: 'center', gap: '6px', textAlign: 'center' }, children: usersPausedRealInfo ? "Resume Users" : "Pause Users" }) }), datRestrictionMissing ? (_jsxs("span", { style: { display: 'flex', opacity: 0.5, fontSize: 10, justifyContent: 'center', alignItems: 'center', gap: '4px' }, children: [_jsx(Info, { size: 10 }), "Pausing users from accessing the app is unavaliable. Set \"dat\" in the Authtics Host config to set restriction and then restart."] })) : (_jsx(_Fragment, {}))] })] })) }) }), datMatch ? (_jsxs("div", { onClick: () => setOpen(o => !o), style: {
1156
1204
  display: 'flex',
1157
1205
  flexDirection: 'row',
1158
1206
  alignItems: 'center',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bananacool467/authtics-host",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "A Next.js-inspired SSR framework for Node.js with TypeScript and JSX support.",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -37,7 +37,8 @@
37
37
  "dev",
38
38
  "developer",
39
39
  "HostJS",
40
- "Host.js"
40
+ "Host.js",
41
+ "website"
41
42
  ],
42
43
  "author": "bananacool467",
43
44
  "license": "MIT",