@azure-net/kit 5.0.2 → 5.0.4

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.
@@ -1,4 +1,4 @@
1
1
  export { createApp, type AppClientErrorCallback, type AppClientErrorContext, type AppClientInitLifecycleCallback, type AppClientInitLifecycleContext, type AppClientLifecycleCallback, type AppClientLifecycleContext, type AppContainer, type AppRegistrar, type AppServerErrorCallback, type AppServerErrorContext, type AppServerInitLifecycleCallback, type AppServerInitLifecycleContext, type AppServerLifecycleCallback, type AppServerLifecycleContext, type AppUniversalLifecycleCallback, type AppUniversalLifecycleContext, type CreateAppInstance } from './App.js';
2
2
  export type { IClientMiddleware } from './middleware/ClientMiddleware.js';
3
3
  export type { IServerMiddleware } from './middleware/ServerMiddleware.js';
4
- export type { EnsureRoute, EnsureRouteSource, EnsureRouteTarget, RedirectStatus } from './middleware/Shared.js';
4
+ export type { EnsureRoute, EnsureRouteSource, EnsureRouteTarget } from './middleware/Shared.js';
@@ -1,5 +1,6 @@
1
1
  import { type BeforeNavigate } from '@sveltejs/kit';
2
- import { type EnsureRoute, type RedirectStatus } from './Shared.js';
2
+ import { type EnsureRoute } from './Shared.js';
3
+ import type { RedirectStatus } from '../../redirect/index.js';
3
4
  export type IClientMiddleware = (middlewareData: {
4
5
  to: URL;
5
6
  from?: URL;
@@ -1,5 +1,6 @@
1
1
  import { type RequestEvent } from '@sveltejs/kit';
2
- import { type EnsureRoute, type RedirectStatus } from './Shared.js';
2
+ import { type EnsureRoute } from './Shared.js';
3
+ import type { RedirectStatus } from '../../redirect/index.js';
3
4
  export type IServerMiddleware = (middlewareData: {
4
5
  to: RequestEvent['url'];
5
6
  from?: RequestEvent['url'];
@@ -1,4 +1,3 @@
1
- export type RedirectStatus = 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308;
2
1
  export type EnsureRouteSource = string | readonly string[];
3
2
  export type EnsureRouteTarget = string | URL;
4
3
  export type EnsureRoute = (route: EnsureRouteSource, target: EnsureRouteTarget) => boolean;
@@ -66,4 +66,5 @@ export declare class UniversalCookie {
66
66
  * @returns {void}
67
67
  */
68
68
  static clear(options?: CookieOptions): void;
69
+ static toCredentials(): string;
69
70
  }
@@ -151,4 +151,10 @@ export class UniversalCookie {
151
151
  }
152
152
  }
153
153
  }
154
+ static toCredentials() {
155
+ const all = this.getAll() ?? {};
156
+ return Object.entries(all)
157
+ .map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`)
158
+ .join('; ');
159
+ }
154
160
  }
@@ -4,3 +4,4 @@ export { ClassMirror } from './class-mirror/index.js';
4
4
  export { createBoundaryProvider, cleanupProvider, type ProviderSettings } from './boundary-provider/index.js';
5
5
  export { createApp, type AppContainer, type CreateAppInstance, type IServerMiddleware, type IClientMiddleware } from './app/index.js';
6
6
  export { useLogger, LoggerErrors, type ILoggerError, type ILoggerSettings } from './logger/index.js';
7
+ export { useRedirect, type IRedirectSettings, type RedirectStatus } from './redirect/index.js';
@@ -4,3 +4,4 @@ export { ClassMirror } from './class-mirror/index.js';
4
4
  export { createBoundaryProvider, cleanupProvider } from './boundary-provider/index.js';
5
5
  export { createApp } from './app/index.js';
6
6
  export { useLogger, LoggerErrors } from './logger/index.js';
7
+ export { useRedirect } from './redirect/index.js';
@@ -0,0 +1,16 @@
1
+ export type RedirectStatus = 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308;
2
+ export interface IRedirectSettings {
3
+ clientRedirectSettings?: {
4
+ replaceState?: boolean | undefined;
5
+ noScroll?: boolean | undefined;
6
+ keepFocus?: boolean | undefined;
7
+ invalidateAll?: boolean | undefined;
8
+ invalidate?: (string | URL | ((url: URL) => boolean))[] | undefined;
9
+ state?: App.PageState | undefined;
10
+ };
11
+ serverRedirectSettings?: {
12
+ status?: RedirectStatus;
13
+ };
14
+ type?: 'server' | 'client' | 'universal';
15
+ }
16
+ export declare const useRedirect: (path: string, settings?: IRedirectSettings) => Promise<void>;
@@ -0,0 +1,18 @@
1
+ import { goto } from '$app/navigation';
2
+ import { redirect } from '@sveltejs/kit';
3
+ import { BROWSER } from '@azure-net/tools/environment';
4
+ export const useRedirect = (path, settings) => {
5
+ const { type = 'universal', serverRedirectSettings = { status: 301 }, clientRedirectSettings } = settings ?? {};
6
+ const clientRedirect = () => goto(path, clientRedirectSettings);
7
+ const serverRedirected = () => redirect(serverRedirectSettings.status ?? 301, path);
8
+ switch (type) {
9
+ case 'server':
10
+ return serverRedirected();
11
+ case 'client':
12
+ return clientRedirect();
13
+ case 'universal':
14
+ return BROWSER ? clientRedirect() : serverRedirected();
15
+ default:
16
+ return BROWSER ? clientRedirect() : serverRedirected();
17
+ }
18
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azure-net/kit",
3
- "version": "5.0.2",
3
+ "version": "5.0.4",
4
4
  "license": "MIT",
5
5
  "author": "Pixel1917",
6
6
  "description": "Universal toolkit and library collection, developed as part of the Azure-net ecosystem",