Commit 41d9c76d authored by Emmanuel Raviart's avatar Emmanuel Raviart
Browse files

Remove API routing. Migrate code to @progedo/lib.

parent 35c7a32e
......@@ -25,7 +25,7 @@
"@auditors/json5": "^0.3.0",
"@eraviart/svelte-json-tree": "^0.2.0",
"@iconify/svelte": "^2.1.2",
"@progedo/lib": "^0.1.0",
"@progedo/lib": "^0.3.0",
"@sveltejs/adapter-node": "^1.0.0-next.78",
"@sveltejs/kit": "^1.0.0-next.354",
"@tailwindcss/forms": "^0.5.0",
......@@ -697,9 +697,9 @@
}
},
"node_modules/@progedo/lib": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/@progedo/lib/-/lib-0.1.0.tgz",
"integrity": "sha512-YI3u1XChrlw8xwF8R1rW7+41OAJuyiVyzNbZuqsF/lSvVP7JYCt4inlOoSlX98Wj5xy95AlfatLCKbCDhljNQQ==",
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/@progedo/lib/-/lib-0.3.0.tgz",
"integrity": "sha512-qniJd5JmeX+fNrX1tm6pLVHTW0Kzrzh0RYSBWqWzjFkyq3l9LoLALuytEoim2lOsjAPfaGhGbBcfeCq2YvPBcQ==",
"dev": true,
"dependencies": {
"core-js": "^3.12.1",
......@@ -5880,9 +5880,9 @@
"dev": true
},
"@progedo/lib": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/@progedo/lib/-/lib-0.1.0.tgz",
"integrity": "sha512-YI3u1XChrlw8xwF8R1rW7+41OAJuyiVyzNbZuqsF/lSvVP7JYCt4inlOoSlX98Wj5xy95AlfatLCKbCDhljNQQ==",
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/@progedo/lib/-/lib-0.3.0.tgz",
"integrity": "sha512-qniJd5JmeX+fNrX1tm6pLVHTW0Kzrzh0RYSBWqWzjFkyq3l9LoLALuytEoim2lOsjAPfaGhGbBcfeCq2YvPBcQ==",
"dev": true,
"requires": {
"core-js": "^3.12.1",
......
......@@ -13,7 +13,7 @@ declare namespace App {
OpenIdConnectLocals {
/// The server session stored in database
session: {
language?: import("$lib/data").Language
language?: import("@progedo/lib").Language
/// Random token used for authentication
nonce?: string
/// URL to redirect to after authentication (or logout)
......@@ -39,7 +39,7 @@ declare namespace App {
cart: string[]
commit: string
debugMenu: boolean
language: import("$lib/data").Language
language: import("@progedo/lib").Language
matomo?: import("$lib/server/config").MatomoConfig
redirectUrl?: string
title: string
......
import { Language } from "@progedo/lib"
import type { GetSession, Handle } from "@sveltejs/kit"
import { sequence } from "@sveltejs/kit/hooks"
import { execSync } from "child_process"
import dedent from "dedent-js"
import { Language } from "$lib/data"
import config from "$lib/server/config"
import { cookiesHandler } from "$lib/server/cookies_handler"
import { db } from "$lib/server/database"
......
This diff is collapsed.
......@@ -25,7 +25,7 @@
to access to this page.
</div>
{:else}
<div class="card ~critical @high">
<div class="~critical card @high">
<p>
<strong>Access restricted!</strong>
Your credentials don't allow you to access to this page.
......@@ -34,7 +34,7 @@
<i class="italic">You don't have any role.</i>
{:else}
<p>Your roles:</p>
<ul class="list-disc list-inside">
<ul class="list-inside list-disc">
{#each roles as role}
<li>{role}</li>
{/each}
......
<script lang="ts">
import type { Demand } from "@progedo/lib"
import { t } from "svelte-intl-precompile"
import type { Demand } from "$lib/data"
export let demand: Demand
const dateFormat = new Intl.DateTimeFormat("fr-FR", {
......
<script lang="ts">
import {
type Organization,
type Study,
StudyOrganizationRelation,
} from "@progedo/lib"
import { t } from "svelte-intl-precompile"
import { session } from "$app/stores"
import type { Organization, Study } from "$lib/data"
import { StudyOrganizationRelation } from "$lib/data"
import List from "./List.svelte"
import OrganizationName from "./OrganizationName.svelte"
......
......@@ -40,7 +40,7 @@
on:click={() => (state = "less")}>-- {$t("Show less")} --</button
>
{:else if realState === "more"}
<ul class="list-inside max-h-64 overflow-y-auto text-xs text-gray-700">
<ul class="max-h-64 list-inside overflow-y-auto text-xs text-gray-700">
{#each items
.filter((item) => countGetter(item) > 1)
.sort(expandedComparison) as item}
......@@ -49,7 +49,7 @@
</li>
{/each}
</ul>
<div class="flex justify-between mt-2">
<div class="mt-2 flex justify-between">
<button class="text-xs text-red-400" on:click={() => (state = "all")}
>-- {$t("Show all")} --</button
>
......@@ -67,12 +67,12 @@
</ul>
{#if hasMore}
<button
class="w-full text-xs text-red-400 mt-2 text-right "
class="mt-2 w-full text-right text-xs text-red-400 "
on:click={() => (state = "more")}>-- {$t("Show more")} --</button
>
{:else if hasAll}
<button
class="w-full text-xs text-red-400 mt-2 text-right "
class="mt-2 w-full text-right text-xs text-red-400 "
on:click={() => (state = "all")}>-- {$t("Show all")} --</button
>
{/if}
......
......@@ -14,35 +14,35 @@
>{/if}
</h1>
{:else if level === 2}
<h2 class="font-bold mt-8 text-gray-500 text-lg" class:uppercase>
<h2 class="mt-8 text-lg font-bold text-gray-500" class:uppercase>
<slot />
{#if $debugMode && titleDebug}<span class="text-gray-300"
>({titleDebug})</span
>{/if}
</h2>
{:else if level === 3}
<h3 class="font-bold mt-6 text-gray-700 text-base" class:uppercase>
<h3 class="mt-6 text-base font-bold text-gray-700" class:uppercase>
<slot />
{#if $debugMode && titleDebug}<span class="text-gray-300"
>({titleDebug})</span
>{/if}
</h3>
{:else if level === 4}
<h4 class="font-bold italic text-gray-700 text-sm" class:uppercase>
<h4 class="text-sm font-bold italic text-gray-700" class:uppercase>
<slot />
{#if $debugMode && titleDebug}<span class="text-gray-300"
>({titleDebug})</span
>{/if}
</h4>
{:else if level === 5}
<h5 class="font-bold italic text-gray-400 text-sm" class:uppercase>
<h5 class="text-sm font-bold italic text-gray-400" class:uppercase>
<slot />
{#if $debugMode && titleDebug}<span class="text-gray-300"
>({titleDebug})</span
>{/if}
</h5>
{:else}
<h6 class="font-bold italic text-gray-400 text-sm" class:uppercase>
<h6 class="text-sm font-bold italic text-gray-400" class:uppercase>
<slot />
{#if $debugMode && titleDebug}<span class="text-gray-300"
>({titleDebug})</span
......
<script lang="ts">
import { Language } from "@progedo/lib"
import { locale, t } from "svelte-intl-precompile"
import { page, session } from "$app/stores"
import { validateJsonResponse } from "$lib/auditors/responses"
import type { Language } from "$lib/data"
import { debugMode, shoppingCart } from "$lib/stores"
export let display: string
......@@ -34,13 +34,13 @@
$session.language = newLanguage
$locale = newLanguage
const headers = {
"Content-Type": "application/json; charset=utf-8",
}
const response = await fetch("/api/language", {
const response = await fetch("/language", {
body: JSON.stringify({ language: newLanguage }, null, 2),
credentials: "include",
headers,
headers: {
Accept: "application/json",
"Content-Type": "application/json; charset=utf-8",
},
method: "PUT",
})
const [result, error] = await validateJsonResponse(null)(response)
......@@ -166,7 +166,7 @@
{$t("Sign In")}
</a>
{:else}
<div class="group inline-block relative">
<div class="group relative inline-block">
<button
class="portal mx-2"
on:click={() => (userMenuOpen = !userMenuOpen)}
......@@ -180,24 +180,24 @@
</button>
{#if userMenuOpen}
<ul
class="absolute bg-white text-slate-600 pt-1 group-hover:block shadow-sm z-10"
class="absolute z-10 bg-white pt-1 text-slate-600 shadow-sm group-hover:block"
>
<li class="text-sm px-4 py-2">
<li class="px-4 py-2 text-sm">
<a href="/me/profile" on:click={() => (userMenuOpen = false)}
>{$t("My Profile")}</a
>
</li>
<li class="text-sm px-4 py-2">
<li class="px-4 py-2 text-sm">
<a href="/me/cart" on:click={() => (userMenuOpen = false)}
>{$t("My Bucket")}</a
>
</li>
<li class="text-sm px-4 py-2">
<li class="px-4 py-2 text-sm">
<a href="/me/demands" on:click={() => (userMenuOpen = false)}
>{$t("My Requests")}</a
>
</li>
<li class="text-sm px-4 py-2">
<li class="px-4 py-2 text-sm">
<a href={logoutUrl} rel="external">
{$t("Sign Out")}
</a>
......
<script lang="ts">
import type { Organization } from "$lib/data"
import type { Organization } from "@progedo/lib"
export let organization: Organization | undefined
</script>
......
<script lang="ts">
import type { SearchQuery, ValidSearchQuery } from "@progedo/lib"
import { t } from "svelte-intl-precompile"
import type { SearchQuery, ValidSearchQuery } from "$lib/data"
import { newSearchUrl } from "$lib/urls"
export let count: number | undefined // Count is not always known.
......@@ -76,8 +76,8 @@
</a>
{:else}
<span
class="relative inline-flex items-center px-4 py-2 border
border-gray-300 text-sm leading-5 font-medium rounded-md text-gray-700"
class="relative inline-flex items-center rounded-md border border-gray-300
px-4 py-2 text-sm font-medium leading-5 text-gray-700"
>
{$t("Previous")}
</span>
......@@ -95,8 +95,8 @@
</a>
{:else}
<span
class="relative inline-flex items-center px-4 py-2 border
border-gray-300 text-sm leading-5 font-medium rounded-md text-gray-700"
class="relative inline-flex items-center rounded-md border border-gray-300
px-4 py-2 text-sm font-medium leading-5 text-gray-700"
>
{$t("Next")}
</span>
......@@ -144,8 +144,8 @@
</a>
{:else}
<span
class="-ml-px relative inline-flex items-center px-4 py-2 border
border-gray-300 bg-white text-sm leading-5 font-medium text-gray-700"
class="relative -ml-px inline-flex items-center border border-gray-300 bg-white
px-4 py-2 text-sm font-medium leading-5 text-gray-700"
>
<svg class="h-5 w-5" fill="currentColor" viewBox="0 0 20 20">
<path
......@@ -212,8 +212,8 @@
</a>
{:else}
<span
class="-ml-px relative inline-flex items-center px-4 py-2 border
border-gray-300 bg-white text-sm leading-5 font-medium text-gray-700"
class="relative -ml-px inline-flex items-center border border-gray-300 bg-white
px-4 py-2 text-sm font-medium leading-5 text-gray-700"
>
<svg class="h-5 w-5" fill="currentColor" viewBox="0 0 20 20">
<path
......
<script lang="ts">
import type { ValidSearchQuery, WordAutocompletion } from "@progedo/lib"
import { t } from "svelte-intl-precompile"
import { goto } from "$app/navigation"
import { page, session } from "$app/stores"
import Autocomplete from "$lib/components/Autocomplete.svelte"
import type { ValidSearchQuery, WordAutocompletion } from "$lib/data"
import { retrieveWords } from "$lib/data_retrievers"
import { newSearchUrl } from "$lib/urls"
......@@ -49,7 +49,7 @@
}
// Autocomplete found word.
const [result, error] = await retrieveWords(fetch, "/api/words", {
const [result, error] = await retrieveWords(fetch, "/words", {
language,
limit: 10,
term: word,
......
<script lang="ts">
import { t } from "svelte-intl-precompile"
import { session } from "$app/stores"
import {
iterSeriesDistributors,
iterSeriesProducers,
iterSeriesTopicsClass,
iterSeriesYears,
} from "$lib/accessors"
type Series,
} from "@progedo/lib"
import { t } from "svelte-intl-precompile"
import { session } from "$app/stores"
import { validateJsonResponse } from "$lib/auditors/responses"
import OrganizationName from "./OrganizationName.svelte"
import type { Series } from "$lib/data"
import { shoppingCart } from "$lib/stores"
export let series: Series
......@@ -43,10 +43,11 @@
localStorage.setItem("shoppingCart", JSON.stringify(cart))
}
if (user !== undefined) {
const response = await fetch("/api/carts", {
const response = await fetch("/carts", {
body: JSON.stringify({ paths: cart }, null, 2),
credentials: "include",
headers: {
Accept: "application/json",
"Content-Type": "application/json; charset=utf-8",
},
method: "PUT",
......
<script lang="ts">
import { t } from "svelte-intl-precompile"
import { session } from "$app/stores"
import {
iterCodeBookDistributors,
iterCodeBookProducers,
} from "$lib/accessors"
type Series,
type Study,
} from "@progedo/lib"
import { t } from "svelte-intl-precompile"
import { session } from "$app/stores"
import { validateJsonResponse } from "$lib/auditors/responses"
import List from "./List.svelte"
import OrganizationName from "./OrganizationName.svelte"
import StudyListItemSeriesPage from "./StudyListItemSeriesPage.svelte"
import type { Series, Study } from "$lib/data"
import { shoppingCart } from "$lib/stores"
export let series: Series
......@@ -74,10 +75,11 @@
localStorage.setItem("shoppingCart", JSON.stringify(cart))
}
if (user !== undefined) {
const response = await fetch("/api/carts", {
const response = await fetch("/carts", {
body: JSON.stringify({ paths: cart }, null, 2),
credentials: "include",
headers: {
Accept: "application/json",
"Content-Type": "application/json; charset=utf-8",
},
method: "PUT",
......
<script lang="ts">
import { t } from "svelte-intl-precompile"
import { session } from "$app/stores"
import {
iterStudyDistributors,
iterStudyProducers,
iterStudyTopicsClass,
} from "$lib/accessors"
type Study,
} from "@progedo/lib"
import { t } from "svelte-intl-precompile"
import { session } from "$app/stores"
import { validateJsonResponse } from "$lib/auditors/responses"
import OrganizationName from "./OrganizationName.svelte"
import type { Study } from "$lib/data"
import { shoppingCart } from "$lib/stores"
import { newStudyUrlPath } from "$lib/urls"
......@@ -37,10 +37,11 @@
localStorage.setItem("shoppingCart", JSON.stringify(cart))
}
if (user !== undefined) {
const response = await fetch("/api/carts", {
const response = await fetch("/carts", {
body: JSON.stringify({ paths: cart }, null, 2),
credentials: "include",
headers: {
Accept: "application/json",
"Content-Type": "application/json; charset=utf-8",
},
method: "PUT",
......
<script lang="ts">
import type { Study } from "@progedo/lib"
import { createEventDispatcher } from "svelte"
import type { Study } from "$lib/data"
import { newStudyUrlPath } from "$lib/urls"
const dispatch = createEventDispatcher()
......
<script lang="ts">
import { t } from "svelte-intl-precompile"
import { session } from "$app/stores"
import {
iterStudyDistributors,
iterStudyProducers,
iterStudyTopicsClass,
} from "$lib/accessors"
type Study,
} from "@progedo/lib"
import { t } from "svelte-intl-precompile"
import { session } from "$app/stores"
import { validateJsonResponse } from "$lib/auditors/responses"
import OrganizationName from "./OrganizationName.svelte"
import type { Study } from "$lib/data"
import { shoppingCart } from "$lib/stores"
import { newStudyUrlPath } from "$lib/urls"
......@@ -37,10 +37,11 @@
localStorage.setItem("shoppingCart", JSON.stringify(cart))
}
if (user !== undefined) {
const response = await fetch("/api/carts", {
const response = await fetch("/carts", {
body: JSON.stringify({ paths: cart }, null, 2),
credentials: "include",
headers: {
Accept: "application/json",
"Content-Type": "application/json; charset=utf-8",
},
method: "PUT",
......
<script lang="ts">
import type {
// iterStudyDistributors,
// iterStudyProducers,
// iterStudyTopicsClass,
Study,
} from "@progedo/lib"
import { t } from "svelte-intl-precompile"
import { session } from "$app/stores"
// import {
// iterStudyDistributors,
// iterStudyProducers,
// iterStudyTopicsClass,
// } from "$lib/accessors"
import { validateJsonResponse } from "$lib/auditors/responses"
//import OrganizationName from "./OrganizationName.svelte"
import type { Study } from "$lib/data"
import { shoppingCart } from "$lib/stores"
import { newStudyUrlPath } from "$lib/urls"
......@@ -35,10 +35,11 @@
localStorage.setItem("shoppingCart", JSON.stringify(cart))
}
if (user !== undefined) {
const response = await fetch("/api/carts", {
const response = await fetch("/carts", {
body: JSON.stringify({ paths: cart }, null, 2),
credentials: "include",
headers: {
Accept: "application/json",
"Content-Type": "application/json; charset=utf-8",
},
method: "PUT",
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment