@friendofsvelte/django-kit
Advanced tools
Comparing version 0.0.1-alpha.5 to 0.0.1-alpha.601
@@ -12,3 +12,10 @@ import { type Actions } from '@sveltejs/kit'; | ||
}; | ||
export declare const via_route_name: (proxy_paths: string | string[] | NamedActionInfo[], django_base_api?: string, allow_cookies?: boolean) => Actions; | ||
export declare const via_route: (proxy_paths: string[] | PathActionInfo[], prefix?: string, django_base_api?: string, allow_cookies?: boolean) => Actions; | ||
export declare const via_route_name: (proxy_paths: string | string[] | NamedActionInfo[], opt_?: { | ||
django_base_api: any; | ||
allow_cookies: boolean; | ||
}) => Actions; | ||
export declare const via_route: (proxy_paths: string[] | PathActionInfo[], opt_?: { | ||
prefix: string; | ||
django_base_api: any; | ||
allow_cookies: boolean; | ||
}) => Actions; |
import { fail } from '@sveltejs/kit'; | ||
import { SECRET_BASE_API } from "$env/static/private"; | ||
const default_options = { | ||
django_base_api: SECRET_BASE_API, | ||
allow_cookies: false | ||
}; | ||
function assign_cookies(event, response) { | ||
@@ -30,3 +34,3 @@ const cookies = response.headers.get('set-cookie'); | ||
*/ | ||
export const via_route_name = (proxy_paths, django_base_api = SECRET_BASE_API, allow_cookies = false) => { | ||
export const via_route_name = (proxy_paths, opt_ = default_options) => { | ||
let actions = {}; | ||
@@ -44,3 +48,3 @@ if (typeof proxy_paths === 'string') { | ||
const form_data = await event.request.formData(); | ||
let url = `${django_base_api}/trvun/?url_name=${proxy_action.name}`; | ||
let url = `${opt_.django_base_api}/trvun/?url_name=${proxy_action.name}`; | ||
let options = { method: proxy_action.method }; | ||
@@ -54,3 +58,3 @@ if (proxy_action.method === 'GET') { | ||
const response = await event.fetch(url, options); | ||
if (proxy_action.allow_cookies || allow_cookies) { | ||
if (proxy_action.allow_cookies || opt_.allow_cookies) { | ||
assign_cookies(event, response); | ||
@@ -83,3 +87,3 @@ } | ||
*/ | ||
export const via_route = (proxy_paths, prefix = "", django_base_api = SECRET_BASE_API, allow_cookies = false) => { | ||
export const via_route = (proxy_paths, opt_ = { ...default_options, prefix: '' }) => { | ||
let actions = {}; | ||
@@ -90,6 +94,6 @@ proxy_paths.map((proxy_action) => { | ||
} | ||
if (prefix && !prefix.endsWith("/")) { | ||
prefix += "/"; | ||
if (opt_.prefix && !opt_.prefix.endsWith("/")) { | ||
opt_.prefix += "/"; | ||
} | ||
proxy_action.path = prefix + proxy_action.path; | ||
proxy_action.path = opt_.prefix + proxy_action.path; | ||
const action = { | ||
@@ -99,3 +103,3 @@ [proxy_action.path]: async (event) => { | ||
const form_data = await event.request.formData(); | ||
let url = `${django_base_api}/${proxy_action.path}`; | ||
let url = `${opt_.django_base_api}/${proxy_action.path}`; | ||
let options = { method: proxy_action.method }; | ||
@@ -109,3 +113,3 @@ if (proxy_action.method === 'GET') { | ||
const response = await event.fetch(url, options); | ||
if (proxy_action.allow_cookies || allow_cookies) { | ||
if (proxy_action.allow_cookies || opt_.allow_cookies) { | ||
assign_cookies(event, response); | ||
@@ -112,0 +116,0 @@ } |
{ | ||
"name": "@friendofsvelte/django-kit", | ||
"version": "0.0.1-alpha.5", | ||
"version": "0.0.1-alpha.601", | ||
"scripts": { | ||
@@ -5,0 +5,0 @@ "dev": "vite dev", |
11548
198