@friendofsvelte/django-kit
Advanced tools
Comparing version 0.0.1-alpha.5 to 0.0.1-alpha.101
@@ -12,3 +12,11 @@ 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; | ||
type Options = { | ||
django_base_api?: string; | ||
allow_cookies?: boolean; | ||
}; | ||
type PrefixOptions = { | ||
prefix?: string; | ||
} & Options; | ||
export declare const via_route_name: (proxy_paths: string | string[] | NamedActionInfo[], opt_?: Options) => Actions; | ||
export declare const via_route: (proxy_paths: string[] | PathActionInfo[], opt_?: PrefixOptions) => Actions; | ||
export {}; |
import { fail } from '@sveltejs/kit'; | ||
import { SECRET_BASE_API } from "$env/static/private"; | ||
function assign_cookies(event, response) { | ||
const default_options = { | ||
django_base_api: SECRET_BASE_API, | ||
allow_cookies: false | ||
}; | ||
const assign_cookies = (event, response) => { | ||
const cookies = response.headers.get('set-cookie'); | ||
@@ -24,3 +28,3 @@ if (cookies) { | ||
} | ||
} | ||
}; | ||
/* | ||
@@ -31,3 +35,4 @@ This function is used to create action triggers for django's api endpoints' name; | ||
*/ | ||
export const via_route_name = (proxy_paths, django_base_api = SECRET_BASE_API, allow_cookies = false) => { | ||
export const via_route_name = (proxy_paths, opt_ = {}) => { | ||
opt_ = { ...default_options, ...opt_ }; | ||
let actions = {}; | ||
@@ -45,3 +50,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 }; | ||
@@ -55,3 +60,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); | ||
@@ -84,3 +89,4 @@ } | ||
*/ | ||
export const via_route = (proxy_paths, prefix = "", django_base_api = SECRET_BASE_API, allow_cookies = false) => { | ||
export const via_route = (proxy_paths, opt_ = {}) => { | ||
opt_ = { ...default_options, ...opt_ }; | ||
let actions = {}; | ||
@@ -91,6 +97,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 = { | ||
@@ -100,3 +106,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 }; | ||
@@ -110,3 +116,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); | ||
@@ -113,0 +119,0 @@ } |
{ | ||
"name": "@friendofsvelte/django-kit", | ||
"version": "0.0.1-alpha.5", | ||
"version": "0.0.1-alpha.101", | ||
"scripts": { | ||
@@ -5,0 +5,0 @@ "dev": "vite dev", |
11628
201