1
0
Fork 0

[breaking]: FreeSewing v4 (#7297)

Refer to the CHANGELOG for all info.

---------

Co-authored-by: Wouter van Wageningen <wouter.vdub@yahoo.com>
Co-authored-by: Josh Munic <jpmunic@gmail.com>
Co-authored-by: Jonathan Haas <haasjona@gmail.com>
This commit is contained in:
Joost De Cock 2025-04-01 16:15:20 +02:00 committed by GitHub
parent d22fbe78d9
commit 51dc1d9732
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6626 changed files with 142053 additions and 150606 deletions

View file

@ -0,0 +1,136 @@
/**
* A simple HTTP REST client
*
* We use this in the useBackend hook, but it's also possible to use this with
* any other REST API.
* This uses the fetch API, so it has no dependencies.
* However, that means you cannot use this with a REST API using a non-trusted X.509 certificate, since fetch does not provide an escape hatch for that.
* If that's your use-case, use Axios instead.
*
* @param {string} baseUrl - The base URL of the API that will be used as a prefix for all calls
* @param {string} baseHeaders - Any headers to add to each request. Eg for authentication
* @return {object} client - An object with get, post, and put methods
*/
export function RestClient(baseUrl = '', baseHeaders = {}) {
this.baseUrl = baseUrl
this.baseHeaders = baseHeaders
this.delete = async function (url, headers, raw, log) {
return withoutBody('DELETE', baseUrl + url, { ...baseHeaders, ...headers }, raw, log)
}
this.get = async function (url, headers, raw, log) {
return withoutBody('GET', baseUrl + url, { ...baseHeaders, ...headers }, raw, log)
}
this.head = async function (url, headers, raw, log) {
return withoutBody('HEAD', baseUrl + url, { ...baseHeaders, ...headers }, raw, log)
}
this.patch = async function (url, data, headers, raw, log) {
return withBody('PATCH', baseUrl + url, data, { ...baseHeaders, ...headers }, raw, log)
}
this.post = async function (url, data, headers, raw, log) {
return withBody('POST', baseUrl + url, data, { ...baseHeaders, ...headers }, raw, log)
}
this.put = async function (url, data, headers, raw, log) {
return withBody('PUT', baseUrl + url, data, { ...baseHeaders, headers }, raw, log)
}
return this
}
/*
* General purpose method to call a REST API without a body (eg: GET or DELETE requests)
*
* @param {string} url - The URL to call
* @param {object} headers - Any request headers to add
* @param {bool} raw - Set this to something truthy to not parse the result as JSON
* @param {function} log - Optional custom logging method to log errors
* @return {response} array - An array with status code followed by either the result parse as JSON, the raw result, or false in case of trouble
*/
async function withoutBody(method = 'GET', url, headers = {}, raw = false, log = console.log) {
let response
try {
response = await fetch(url, { method, headers })
} catch (err) {
if (log) console.log({ url, err })
}
if (!response) return [false, false]
/*
* Can we parse the response as JSON?
*/
let body
try {
body = raw ? await response.text() : await response.json()
} catch (err) {
try {
body = await response.text()
} catch (err) {
body = false
}
}
return [response.status || false, body]
}
/*
* General purpose method to call a REST API with a body (eg: PATCH, PUT, or POST requests)
*
* @param {url} string - The URL to call
* @param {data} string - The data to send
* @param {object} headers - Any request headers to add
* @param {raw} string - Set this to something truthy to not parse the result as JSON
* @param {function} log - Optional logging method to log errors
* @return {response} array - An array with status code followed by either the result parse as JSON, the raw result, or false in case of trouble
*/
async function withBody(method = 'POST', url, data, headers, raw = false, log = console.log) {
const request = { method, headers }
if (data && typeof data === 'object' && Object.keys(data).length > 0) {
request.body = JSON.stringify(data)
request.headers['Content-Type'] = 'application/json'
}
let response
try {
response = await fetch(url, request)
} catch (err) {
if (log) log(err)
}
/*
* Some status codes have no response body
*/
if (response.status && [204].includes(response.status)) return [response.status, {}]
else if (response.status && response.status < 400) {
let data
try {
data = raw ? await response.text() : await response.json()
} catch (err) {
if (log) log(err)
return raw ? [response.status, { err }] : [response.status, data]
}
return [response.status, data]
}
/*
* If we end up here, status code is 400 or higher so it's an error
* We still attempt to parse the body though
*/
let body
try {
body = raw ? await response.text() : await response.json()
} catch (err) {
try {
body = await response.text()
} catch (err) {
body = false
}
}
return [response.status || 500, body]
}

View file

@ -0,0 +1,121 @@
import { Aaron as aaron } from '@freesewing/aaron'
import { Albert as albert } from '@freesewing/albert'
import { Bee as bee } from '@freesewing/bee'
import { Bella as bella } from '@freesewing/bella'
import { Benjamin as benjamin } from '@freesewing/benjamin'
import { Bent as bent } from '@freesewing/bent'
import { Bibi as bibi } from '@freesewing/bibi'
import { Bob as bob } from '@freesewing/bob'
import { Breanna as breanna } from '@freesewing/breanna'
import { Brian as brian } from '@freesewing/brian'
import { Bruce as bruce } from '@freesewing/bruce'
import { Carlita as carlita } from '@freesewing/carlita'
import { Carlton as carlton } from '@freesewing/carlton'
import { Cathrin as cathrin } from '@freesewing/cathrin'
import { Charlie as charlie } from '@freesewing/charlie'
import { Cornelius as cornelius } from '@freesewing/cornelius'
import { Diana as diana } from '@freesewing/diana'
import { Florence as florence } from '@freesewing/florence'
import { Florent as florent } from '@freesewing/florent'
import { Gozer as gozer } from '@freesewing/gozer'
import { Hi as hi } from '@freesewing/hi'
import { Holmes as holmes } from '@freesewing/holmes'
import { Hortensia as hortensia } from '@freesewing/hortensia'
import { Huey as huey } from '@freesewing/huey'
import { Hugo as hugo } from '@freesewing/hugo'
import { Jaeger as jaeger } from '@freesewing/jaeger'
import { Jane as jane } from '@freesewing/jane'
import { Lucy as lucy } from '@freesewing/lucy'
import { Lumina as lumina } from '@freesewing/lumina'
import { Lumira as lumira } from '@freesewing/lumira'
import { Lunetius as lunetius } from '@freesewing/lunetius'
import { Noble as noble } from '@freesewing/noble'
import { Octoplushy as octoplushy } from '@freesewing/octoplushy'
import { Onyx as onyx } from '@freesewing/onyx'
import { Opal as opal } from '@freesewing/opal'
import { Otis as otis } from '@freesewing/otis'
import { Paco as paco } from '@freesewing/paco'
import { Penelope as penelope } from '@freesewing/penelope'
import { Sandy as sandy } from '@freesewing/sandy'
import { Shelly as shelly } from '@freesewing/shelly'
import { Shin as shin } from '@freesewing/shin'
import { Simon as simon } from '@freesewing/simon'
import { Simone as simone } from '@freesewing/simone'
import { Skully as skully } from '@freesewing/skully'
import { Sven as sven } from '@freesewing/sven'
import { Tamiko as tamiko } from '@freesewing/tamiko'
import { Teagan as teagan } from '@freesewing/teagan'
import { Tiberius as tiberius } from '@freesewing/tiberius'
import { Titan as titan } from '@freesewing/titan'
import { Trayvon as trayvon } from '@freesewing/trayvon'
import { Tristan as tristan } from '@freesewing/tristan'
import { Uma as uma } from '@freesewing/uma'
import { Umbra as umbra } from '@freesewing/umbra'
import { Wahid as wahid } from '@freesewing/wahid'
import { Walburga as walburga } from '@freesewing/walburga'
import { Waralee as waralee } from '@freesewing/waralee'
import { Yuri as yuri } from '@freesewing/yuri'
import { Lily as lily } from '@freesewing/lily'
export const designs = {
aaron,
albert,
bee,
bella,
benjamin,
bent,
bibi,
bob,
breanna,
brian,
bruce,
carlita,
carlton,
cathrin,
charlie,
cornelius,
diana,
florence,
florent,
gozer,
hi,
holmes,
hortensia,
huey,
hugo,
jaeger,
jane,
lucy,
lumina,
lumira,
lunetius,
noble,
octoplushy,
onyx,
opal,
otis,
paco,
penelope,
sandy,
shelly,
shin,
simon,
simone,
skully,
sven,
tamiko,
teagan,
tiberius,
titan,
trayvon,
tristan,
uma,
umbra,
wahid,
walburga,
waralee,
yuri,
lily,
}
export const collection = Object.keys(designs)

View file

@ -0,0 +1,14 @@
import React from 'react'
const html = (
<>
<button className="tw-btn-ghost">
<span className="tw-px-1 tw-text-sm tw-font-medium tw-whitespace-nowrap tw-border-2 tw-border-solid tw-rounded-l-lg tw-text-primary-content tw-bg-primary tw-border-primary ">
Code
</span>
<span className="tw-px-1 tw-text-sm tw-font-medium tw-whitespace-nowrap tw-border-2 tw-border-solid tw-rounded-r-lg tw-text-primary tw-bg-base-100 tw-border-primary ">
Joost De Cock
</span>
</button>
</>
)