Skip to content

Commit

Permalink
Merge branch 'main' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
lfleischmann authored Aug 2, 2024
2 parents 9d2e0a6 + a0aaf53 commit a9dbf0d
Show file tree
Hide file tree
Showing 16 changed files with 64 additions and 21 deletions.
21 changes: 21 additions & 0 deletions backend/config/webhook_config.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package config

import (
"encoding/json"
"fmt"
"github.com/teamhanko/hanko/backend/webhooks/events"
"net/url"
"strings"
)

type WebhookSettings struct {
Expand All @@ -27,6 +29,25 @@ func (ws *WebhookSettings) Validate() error {

type Webhooks []Webhook

// Decode is an implementation of the envconfig.Decoder interface.
// Assumes that environment variables (for the WEBHOOKS_HOOKS key) have the following format:
// {"callback":"http://app.com/usercb","events":["user"]};{"callback":"http://app.com/emailcb","events":["email.send"]}
func (wd *Webhooks) Decode(value string) error {
webhooks := Webhooks{}
hooks := strings.Split(value, ";")
for _, hook := range hooks {
webhook := Webhook{}
err := json.Unmarshal([]byte(hook), &webhook)
if err != nil {
return fmt.Errorf("invalid map json: %w", err)
}
webhooks = append(webhooks, webhook)

}
*wd = webhooks
return nil
}

type Webhook struct {
Callback string `yaml:"callback" json:"callback,omitempty" koanf:"callback"`
Events events.Events `yaml:"events" json:"events,omitempty" koanf:"events"`
Expand Down
18 changes: 18 additions & 0 deletions backend/config/webhook_config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package config

import (
"github.com/stretchr/testify/assert"
"testing"
)

func TestWebhooks_Decode(t *testing.T) {
webhooks := Webhooks{}
value := "{\"callback\":\"http://app.com/usercb\",\"events\":[\"user\"]};{\"callback\":\"http://app.com/callback\",\"events\":[\"email.send\"]}"
err := webhooks.Decode(value)

assert.NoError(t, err)
assert.Len(t, webhooks, 2, "has 2 elements")
for _, webhook := range webhooks {
assert.IsType(t, Webhook{}, webhook)
}
}
4 changes: 4 additions & 0 deletions backend/docs/Config.md
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,10 @@ webhooks:
#
# Callback - Endpoint URL to which the change data will be sent
#
# NOTE: When using environment variables hooks must be defined as in the following example:
#
# WEBHOOKS_HOOKS={"callback":"http://app.com/usercb","events":["user"]};{"callback":"http://app.com/emailcb","events":["email.send"]}
#
- callback: "<YOUR WEBHOOK ENDPOINT URL>"
##
#
Expand Down
2 changes: 1 addition & 1 deletion docs/static/spec/admin.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
openapi: 3.0.0
info:
version: "0.11.0"
version: "0.12.0"
title: "Hanko Admin API"
description: |
## Introduction
Expand Down
2 changes: 1 addition & 1 deletion docs/static/spec/public.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

openapi: 3.0.0
info:
version: '0.11.0'
version: '0.12.0'
title: 'Hanko Public API'
description: |
## Introduction
Expand Down
4 changes: 2 additions & 2 deletions frontend/elements/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@teamhanko/hanko-elements",
"version": "0.11.0",
"version": "0.12.0",
"type": "module",
"private": false,
"publishConfig": {
Expand Down Expand Up @@ -132,7 +132,7 @@
},
"dependencies": {
"@denysvuika/preact-translate": "^0.5.0",
"@teamhanko/hanko-frontend-sdk": "^0.11.0",
"@teamhanko/hanko-frontend-sdk": "^0.12.0",
"@teamhanko/preact-custom-element": "^4.2.2",
"classnames": "^2.3.2",
"preact": "^10.13.1"
Expand Down
2 changes: 1 addition & 1 deletion frontend/examples/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"rxjs": "~7.8.0",
"tslib": "^2.6.2",
"zone.js": "~0.13.0",
"@teamhanko/hanko-elements": "^0.11.0"
"@teamhanko/hanko-elements": "^0.12.0"
},
"devDependencies": {
"@angular-devkit/build-angular": "^15.2.4",
Expand Down
2 changes: 1 addition & 1 deletion frontend/examples/fresh/islands/Login.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { HANKO_API_URL } from "../config.ts";

const code = `
import { register } from 'https://esm.sh/@teamhanko/hanko-elements@0.11.0';
import { register } from 'https://esm.sh/@teamhanko/hanko-elements@0.12.0';
register('${HANKO_API_URL}', { shadow: true });
document.addEventListener('hankoAuthSuccess', (event) => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/examples/fresh/islands/LogoutButton.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { HANKO_API_URL } from "../config.ts";

const code = `
import { register, Hanko } from 'https://esm.sh/@teamhanko/hanko-elements@0.11.0';
import { register, Hanko } from 'https://esm.sh/@teamhanko/hanko-elements@0.12.0';
register('${HANKO_API_URL}', { shadow: true });
window.addEventListener('logout', () => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/examples/fresh/islands/Profile.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { HANKO_API_URL } from "../config.ts";

const code = `
import { register } from 'https://esm.sh/@teamhanko/hanko-elements@0.11.0';
import { register } from 'https://esm.sh/@teamhanko/hanko-elements@0.12.0';
register('${HANKO_API_URL}', { shadow: true });
`;

Expand Down
2 changes: 1 addition & 1 deletion frontend/examples/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"build": "next build"
},
"dependencies": {
"@teamhanko/hanko-elements": "^0.11.0",
"@teamhanko/hanko-elements": "^0.12.0",
"next": "^14.0.1",
"react": "^18.2.0",
"react-dom": "^18.2.0"
Expand Down
2 changes: 1 addition & 1 deletion frontend/examples/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "example-react",
"private": true,
"dependencies": {
"@teamhanko/hanko-elements": "^0.11.0",
"@teamhanko/hanko-elements": "^0.12.0",
"@types/react": "^18.2.32",
"@types/react-dom": "^18.2.7",
"react": "^18.2.0",
Expand Down
2 changes: 1 addition & 1 deletion frontend/examples/svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"vite": "^4.4.12"
},
"dependencies": {
"@teamhanko/hanko-elements": "^0.11.0",
"@teamhanko/hanko-elements": "^0.12.0",
"svelte-navigator": "^3.2.2"
}
}
2 changes: 1 addition & 1 deletion frontend/examples/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"build": "vite build"
},
"dependencies": {
"@teamhanko/hanko-elements": "^0.11.0",
"@teamhanko/hanko-elements": "^0.12.0",
"vue": "^3.3.8",
"vue-router": "^4.1.6"
},
Expand Down
2 changes: 1 addition & 1 deletion frontend/frontend-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@teamhanko/hanko-frontend-sdk",
"version": "0.11.0",
"version": "0.12.0",
"private": false,
"publishConfig": {
"access": "public"
Expand Down
16 changes: 8 additions & 8 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a9dbf0d

Please sign in to comment.