* feat: add plugin system * fix db docker build * fix hammerhead readme, add strava subscription news to docs * fixes and sdk improvements * fix: reduce Meilisearch load, debounce federation sync (#1012) * optimize meili trail index * several fixes --------- Co-authored-by: Flomp <Flomp@users.noreply.github.com> * Bump svelte from 5.55.5 to 5.56.0 in /docs (#1032) Bumps [svelte](https://github.com/sveltejs/svelte/tree/HEAD/packages/svelte) from 5.55.5 to 5.56.0. - [Release notes](https://github.com/sveltejs/svelte/releases) - [Changelog](https://github.com/sveltejs/svelte/blob/main/packages/svelte/CHANGELOG.md) - [Commits](https://github.com/sveltejs/svelte/commits/svelte@5.56.0/packages/svelte) --- updated-dependencies: - dependency-name: svelte dependency-version: 5.56.0 dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Flomp <Flomp@users.noreply.github.com> * Release v0.19.2 (#1035) * chore: release v0.19.2 * add changelog --------- Co-authored-by: Flomp <26000991+Flomp@users.noreply.github.com> Co-authored-by: Christian Beutel <> * speed up plugin sync and several small fixes * concepts for security improvements and process stability * improve concept * security concept implemented * remove insecure TLS * worker concept implemented * fixes and cleanup * fixes * docu * mermaid, namings * WASM plugin host improvements, plugin logging * fix db migration * Improve plugin config and category mapping UI * fixes * further fixes * remove manual test sync * fix db migration and strava mapping * type added, UI improvements * fix plugin card toggle clickable area * optimize synch status card layout * plugin type 'trails' instead of 'integration' * session auth validation in UI * fix komoot date and waypoints * improve category mapping * fix send to hammerhead: trail name * plugin setup error handling improved * fix review findings * re-mapping added * rename remote_category --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Flomp <Flomp@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Flomp <26000991+Flomp@users.noreply.github.com>
155 lines
3.5 KiB
Go
155 lines
3.5 KiB
Go
//go:build tinygo
|
|
|
|
package sdk
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"encoding/json"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/extism/go-pdk"
|
|
)
|
|
|
|
//go:wasmimport wanderer http_request
|
|
func wandererHTTPRequest(uint64) uint64
|
|
|
|
//go:wasmimport wanderer log
|
|
func wandererLog(uint64)
|
|
|
|
func Log(level LogLevel, message string) {
|
|
entry := HostLogEntry{
|
|
Level: level,
|
|
Message: message,
|
|
}
|
|
memory, err := pdk.AllocateJSON(entry)
|
|
if err != nil {
|
|
return
|
|
}
|
|
defer memory.Free()
|
|
wandererLog(memory.Offset())
|
|
}
|
|
|
|
func LogDebug(message string) {
|
|
Log(LogLevelDebug, message)
|
|
}
|
|
|
|
func LogInfo(message string) {
|
|
Log(LogLevelInfo, message)
|
|
}
|
|
|
|
func LogWarn(message string) {
|
|
Log(LogLevelWarn, message)
|
|
}
|
|
|
|
func LogError(message string) {
|
|
Log(LogLevelError, message)
|
|
}
|
|
|
|
func HostRequest(spec HostRequestSpec) (HostResponse, []byte, error) {
|
|
requestMemory, err := pdk.AllocateJSON(spec)
|
|
if err != nil {
|
|
return HostResponse{}, nil, err
|
|
}
|
|
defer requestMemory.Free()
|
|
|
|
responsePointer := wandererHTTPRequest(requestMemory.Offset())
|
|
if responsePointer == 0 {
|
|
return HostResponse{}, nil, fmt.Errorf("host http request returned no response")
|
|
}
|
|
responseMemory := pdk.FindMemory(responsePointer)
|
|
var response HostResponse
|
|
if err := json.Unmarshal(responseMemory.ReadBytes(), &response); err != nil {
|
|
return HostResponse{}, nil, err
|
|
}
|
|
if response.Error != nil {
|
|
return response, nil, fmt.Errorf("%s: %s", response.Error.Code, response.Error.Message)
|
|
}
|
|
body, err := base64.StdEncoding.DecodeString(response.BodyBase64)
|
|
if err != nil {
|
|
return response, nil, err
|
|
}
|
|
return response, body, nil
|
|
}
|
|
|
|
func ConnectorRequest(method string, connector string, path string, query []QueryParam, headers map[string]string, expect ResponseExpect) (HostResponse, []byte, error) {
|
|
return HostRequest(HostRequestSpec{
|
|
Method: method,
|
|
Target: RequestTarget{
|
|
Type: "connector",
|
|
Connector: connector,
|
|
Path: path,
|
|
Query: query,
|
|
},
|
|
Headers: headers,
|
|
Expect: expect,
|
|
})
|
|
}
|
|
|
|
func Get(connector string, path string, query []QueryParam, headers map[string]string, expect ResponseExpect) (HostResponse, []byte, error) {
|
|
return ConnectorRequest("GET", connector, path, query, headers, expect)
|
|
}
|
|
|
|
func PostJSON(connector string, path string, query []QueryParam, headers map[string]string, body any, expect ResponseExpect) (HostResponse, []byte, error) {
|
|
return HostRequest(HostRequestSpec{
|
|
Method: "POST",
|
|
Target: RequestTarget{
|
|
Type: "connector",
|
|
Connector: connector,
|
|
Path: path,
|
|
Query: query,
|
|
},
|
|
Headers: headers,
|
|
Body: &HostRequestBody{
|
|
Type: HostRequestBodyTypeJSON,
|
|
JSON: body,
|
|
},
|
|
Expect: expect,
|
|
})
|
|
}
|
|
|
|
func PostForm(connector string, path string, query []QueryParam, headers map[string]string, form []FormField, expect ResponseExpect) (HostResponse, []byte, error) {
|
|
return HostRequest(HostRequestSpec{
|
|
Method: "POST",
|
|
Target: RequestTarget{
|
|
Type: "connector",
|
|
Connector: connector,
|
|
Path: path,
|
|
Query: query,
|
|
},
|
|
Headers: headers,
|
|
Body: &HostRequestBody{
|
|
Type: HostRequestBodyTypeForm,
|
|
Form: form,
|
|
},
|
|
Expect: expect,
|
|
})
|
|
}
|
|
|
|
func (r HostResponse) FirstHeader(name string) string {
|
|
values := r.HeaderValuesFor(name)
|
|
if len(values) == 0 {
|
|
return ""
|
|
}
|
|
return values[0]
|
|
}
|
|
|
|
func (r HostResponse) HeaderValuesFor(name string) []string {
|
|
if r.HeaderValues == nil {
|
|
return nil
|
|
}
|
|
if values, ok := r.HeaderValues[name]; ok {
|
|
return values
|
|
}
|
|
for key, values := range r.HeaderValues {
|
|
if strings.EqualFold(key, name) {
|
|
return values
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func Bool(value bool) *bool {
|
|
return &value
|
|
}
|