Skip to content

Commit b8b50ca

Browse files
committed
Merge remote-tracking branch 'origin/main' into feature/new-theme
2 parents f460576 + 3ea103c commit b8b50ca

13 files changed

Lines changed: 300 additions & 41 deletions

File tree

CHANGELOG.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [2025-10-15]
9+
10+
### Changed
11+
- **BREAKING**: Configuration key `peek_app_key` has been renamed to `peek_api_key`
12+
- **BREAKING**: Configuration key `peek_api_url` has been deprecated in favor of `peek_api_base_url`
13+
- The new `peek_api_base_url` should contain only the base URL (e.g., `"https://apps.peekapis.com"`)
14+
- The SDK automatically appends appropriate paths (e.g., `/backoffice-gql`) for different API endpoints
15+
- **Migration path**:
16+
- Existing apps using `peek_api_url` will continue to work for backoffice calls with deprecation warnings
17+
- New features like `update_configuration_status` will fail with clear migration instructions if `peek_api_url` is configured
18+
- Update your configuration from:
19+
```elixir
20+
config :peek_app_sdk,
21+
peek_api_url: "https://apps.peekapis.com/backoffice-gql"
22+
```
23+
to:
24+
```elixir
25+
config :peek_app_sdk,
26+
peek_api_base_url: "https://apps.peekapis.com"
27+
```
28+
29+
### Added
30+
- Support for passing `x-peek-auth` token in request body parameters for scenarios where custom headers cannot be controlled (e.g., form submissions, third-party integrations)
31+
- Body parameters take precedence over headers when both are present
32+
- Enables authentication in form submission scenarios and legacy systems
33+
- Configuration validation that prevents use of deprecated `peek_api_url` with new features
34+
- Deprecation warnings when using legacy `peek_api_url` configuration for backoffice calls
35+
- Clear error messages with migration instructions for deprecated configuration
36+
37+
### Fixed
38+
- URL construction now properly handles base URLs without hardcoded paths

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ writing apps.
1111
config :peek_app_sdk,
1212
peek_app_secret: "APP_SECRET",
1313
peek_app_id: "APP_ID",
14-
peek_api_url: "https://apps.peekapis.com/backoffice-gql",
15-
peek_app_key: "APP_KEY"
14+
peek_api_base_url: "https://apps.peekapis.com/",
15+
peek_api_key: "API_KEY"
1616
```
1717

1818
### Multiple Application Configurations
@@ -24,8 +24,8 @@ PeekAppSDK supports multiple configurations, allowing different applications to
2424
config :peek_app_sdk,
2525
peek_app_secret: "DEFAULT_SECRET",
2626
peek_app_id: "DEFAULT_APP_ID",
27-
peek_api_url: "https://apps.peekapis.com/backoffice-gql",
28-
peek_app_key: "DEFAULT_APP_KEY",
27+
peek_api_base_url: "https://apps.peekapis.com/",
28+
peek_api_key: "DEFAULT_API_KEY",
2929
# Centralized app configurations
3030
apps: [
3131
project_name: [peek_app_id: "project_name_APP_ID", peek_app_secret: "project_name_APP_SECRET"],
@@ -43,7 +43,7 @@ PeekAppSDK.query_peek_pro("install_id", "query { test }")
4343
PeekAppSDK.query_peek_pro("install_id", "query { test }", %{}, :project_name)
4444
```
4545

46-
Note that `peek_api_url` and `peek_app_key` are always taken from the default configuration.
46+
Note that `peek_api_base_url` and `peek_api_key` are always taken from the default configuration.
4747

4848
## Some setup tips:
4949

config/test.exs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import Config
44
config :peek_app_sdk,
55
peek_app_secret: "test_secret",
66
peek_app_id: "test_app_id",
7-
peek_api_url: "https://apps.peekapis.com/backoffice-gql",
8-
peek_app_key: "test_app_key",
7+
peek_api_base_url: "https://apps.peekapis.com",
8+
peek_api_key: "test_api_key",
99
client_secret_token: "test_client_secret",
1010
# Centralized configuration structure
1111
apps: [
1212
project_name: [
1313
peek_app_id: "project_name_app_id",
14-
peek_app_key: "project_name_app_key",
14+
peek_api_key: "project_name_api_key",
1515
peek_app_secret: "project_name_app_secret",
1616
client_secret_token: "project_name_client_secret"
1717
],

lib/peek_app_sdk.ex

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@ defmodule PeekAppSDK do
2424
config :peek_app_sdk,
2525
peek_app_secret: "DEFAULT_SECRET",
2626
peek_app_id: "DEFAULT_APP_ID",
27-
peek_api_url: "https://apps.peekapis.com/backoffice-gql",
28-
peek_app_key: "APP_KEY",
27+
peek_api_base_url: "https://apps.peekapis.com/",
28+
peek_api_key: "API_KEY",
2929
# Centralized app configurations
3030
apps: [
3131
project_name: [peek_app_id: "project_name_APP_ID", peek_app_secret: "project_name_APP_SECRET"],
3232
another_app: [peek_app_id: "ANOTHER_APP_ID", peek_app_secret: "ANOTHER_APP_SECRET"]
3333
]
3434
```
3535
36-
Note that `peek_api_url` and `peek_app_key` are always taken from the default
36+
Note that `peek_api_base_url` and `peek_api_key` are always taken from the default
3737
`:peek_app_sdk` configuration, regardless of which application identifier is used.
3838
"""
3939

@@ -49,8 +49,8 @@ defmodule PeekAppSDK do
4949
%{
5050
peek_app_secret: "project_name_secret",
5151
peek_app_id: "project_name_app_id",
52-
peek_api_url: "https://apps.peekapis.com/backoffice-gql",
53-
peek_app_key: "default_app_key"
52+
peek_api_base_url: "https://apps.peekapis.com",
53+
peek_api_key: "default_api_key"
5454
}
5555
5656
Using the default configuration:
@@ -59,8 +59,8 @@ defmodule PeekAppSDK do
5959
%{
6060
peek_app_secret: "default_secret",
6161
peek_app_id: "default_app_id",
62-
peek_api_url: "https://apps.peekapis.com/backoffice-gql",
63-
peek_app_key: "default_app_key"
62+
peek_api_base_url: "https://apps.peekapis.com",
63+
peek_api_key: "default_api_key"
6464
}
6565
"""
6666
@spec get_config(atom() | nil) :: map()

lib/peek_app_sdk/client.ex

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,17 @@ defmodule PeekAppSDK.Client do
3939

4040
config = Config.get_config(config_id)
4141
peek_app_id = config.peek_app_id
42-
peek_app_key = config.peek_app_key
42+
peek_api_key = config.peek_api_key
4343

4444
operation_name = operation_name(gql_query)
45-
url = "#{config.peek_api_url |> String.trim()}/#{peek_app_id}/#{operation_name}"
45+
46+
url = build_backoffice_url(config, peek_app_id, operation_name)
4647

4748
case Tesla.request(client(),
4849
method: :post,
4950
url: url,
5051
body: body_params,
51-
headers: headers(install_id, config_id, peek_app_key)
52+
headers: headers(install_id, config_id, peek_api_key)
5253
) do
5354
# If we get back an error, fail the whole thing and return the error for now.
5455
{:ok, %Tesla.Env{status: 200, body: %{errors: [_error | _rest] = errors}}} ->
@@ -97,15 +98,39 @@ defmodule PeekAppSDK.Client do
9798
[x_peek_auth_header(install_id, config_id)]
9899
end
99100

100-
defp headers(install_id, config_id, peek_app_key) do
101+
defp headers(install_id, config_id, peek_api_key) do
101102
[
102103
x_peek_auth_header(install_id, config_id),
103-
{"pk-api-key", peek_app_key}
104+
{"pk-api-key", peek_api_key}
104105
]
105106
end
106107

107108
defp x_peek_auth_header(install_id, config_id),
108109
do:
109110
{"X-Peek-Auth",
110111
"Bearer #{PeekAppSDK.Token.new_for_app_installation!(install_id, nil, config_id)}"}
112+
113+
# Migration helper for building backoffice URLs
114+
defp build_backoffice_url(config, peek_app_id, operation_name) do
115+
# Check if legacy peek_api_url is configured
116+
legacy_url = Application.get_env(:peek_app_sdk, :peek_api_url)
117+
118+
if legacy_url do
119+
Logger.warning("""
120+
DEPRECATION WARNING: peek_api_url configuration is deprecated.
121+
Please update your configuration to use peek_api_base_url instead.
122+
123+
Current (deprecated): peek_api_url: "#{legacy_url}"
124+
Recommended: peek_api_base_url: "https://apps.peekapis.com"
125+
126+
Using legacy URL for backoffice calls: #{legacy_url}
127+
""")
128+
129+
# Use the legacy URL directly without appending /backoffice-gql
130+
"#{String.trim(legacy_url)}/#{peek_app_id}/#{operation_name}"
131+
else
132+
# Use the new base URL and append /backoffice-gql
133+
"#{String.trim(config.peek_api_base_url)}/backoffice-gql/#{peek_app_id}/#{operation_name}"
134+
end
135+
end
111136
end

lib/peek_app_sdk/config.ex

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,28 @@ defmodule PeekAppSDK.Config do
1313
config :peek_app_sdk,
1414
peek_app_secret: "DEFAULT_SECRET",
1515
peek_app_id: "DEFAULT_APP_ID",
16-
peek_api_url: "https://apps.peekapis.com/backoffice-gql",
17-
peek_app_key: "APP_KEY",
16+
peek_api_base_url: "https://apps.peekapis.com",
17+
peek_api_key: "API_KEY",
1818
client_secret_token: "CLIENT_SECRET_TOKEN",
1919
apps: [
2020
project_name: [peek_app_id: "project_name_app_id", peek_app_secret: "project_name_secret", client_secret_token: "base64_key"],
2121
another_app: [peek_app_id: "another_app_id", peek_app_secret: "another_app_secret"]
2222
]
2323
```
2424
25-
Note that `peek_api_url` and `peek_app_key` are always taken from the default
25+
Note that `peek_api_base_url` and `peek_api_key` are always taken from the default
2626
`:peek_app_sdk` configuration, regardless of which application identifier is used.
2727
"""
2828

29-
@default_peek_url "https://apps.peekapis.com/backoffice-gql"
29+
@default_peek_api_base_url "https://apps.peekapis.com"
3030

31+
@spec get_config() :: %{
32+
client_secret_token: any(),
33+
peek_api_base_url: any(),
34+
peek_app_id: any(),
35+
peek_api_key: any(),
36+
peek_app_secret: any()
37+
}
3138
@doc """
3239
Gets the configuration for the given identifier.
3340
If no identifier is provided, returns the default configuration from :peek_app_sdk.
@@ -40,8 +47,8 @@ defmodule PeekAppSDK.Config do
4047
%{
4148
peek_app_secret: "project_name_secret",
4249
peek_app_id: "project_name_app_id",
43-
peek_api_url: "https://apps.peekapis.com/backoffice-gql",
44-
peek_app_key: "default_app_key"
50+
peek_api_base_url: "https://apps.peekapis.com",
51+
peek_api_key: "default_api_key"
4552
}
4653
4754
Using the default configuration:
@@ -50,11 +57,11 @@ defmodule PeekAppSDK.Config do
5057
%{
5158
peek_app_secret: "default_secret",
5259
peek_app_id: "default_app_id",
53-
peek_api_url: "https://apps.peekapis.com/backoffice-gql",
54-
peek_app_key: "default_app_key"
60+
peek_api_base_url: "https://apps.peekapis.com",
61+
peek_api_key: "default_api_key"
5562
}
5663
57-
Note that `peek_api_url` and `peek_app_key` are always taken from the default
64+
Note that `peek_api_base_url` and `peek_api_key` are always taken from the default
5865
`:peek_app_sdk` configuration, regardless of which application identifier is used.
5966
"""
6067
@spec get_config(atom() | nil) :: map()
@@ -65,8 +72,9 @@ defmodule PeekAppSDK.Config do
6572
%{
6673
peek_app_secret: Application.get_env(:peek_app_sdk, :peek_app_secret),
6774
peek_app_id: Application.get_env(:peek_app_sdk, :peek_app_id),
68-
peek_api_url: Application.get_env(:peek_app_sdk, :peek_api_url, @default_peek_url),
69-
peek_app_key: Application.get_env(:peek_app_sdk, :peek_app_key),
75+
peek_api_base_url:
76+
Application.get_env(:peek_app_sdk, :peek_api_base_url, @default_peek_api_base_url),
77+
peek_api_key: Application.get_env(:peek_app_sdk, :peek_api_key),
7078
client_secret_token: Application.get_env(:peek_app_sdk, :client_secret_token)
7179
}
7280
end
@@ -81,13 +89,39 @@ defmodule PeekAppSDK.Config do
8189
%{
8290
peek_app_secret: Keyword.get(app_config, :peek_app_secret),
8391
peek_app_id: Keyword.get(app_config, :peek_app_id),
84-
peek_api_url: Application.get_env(:peek_app_sdk, :peek_api_url, @default_peek_url),
85-
peek_app_key: Keyword.get(app_config, :peek_app_key),
92+
peek_api_base_url:
93+
Application.get_env(:peek_app_sdk, :peek_api_base_url, @default_peek_api_base_url),
94+
peek_api_key: Keyword.get(app_config, :peek_api_key),
8695
client_secret_token: Keyword.get(app_config, :client_secret_token)
8796
}
8897
else
8998
# Fall back to default configuration if the app is not configured
9099
get_config(nil)
91100
end
92101
end
102+
103+
# Migration helper functions
104+
@doc """
105+
Checks for deprecated peek_api_url configuration and raises an error if found.
106+
This is called when using the update_configuration_status feature.
107+
"""
108+
def check_deprecated_config! do
109+
if Application.get_env(:peek_app_sdk, :peek_api_url) do
110+
raise """
111+
Configuration error: peek_api_url is deprecated and no longer supported.
112+
113+
Please update your configuration to use peek_api_base_url instead:
114+
115+
OLD (deprecated):
116+
config :peek_app_sdk,
117+
peek_api_url: "https://apps.peekapis.com/backoffice-gql"
118+
119+
NEW (required):
120+
config :peek_app_sdk,
121+
peek_api_base_url: "https://apps.peekapis.com"
122+
123+
The SDK will automatically append the appropriate path (/backoffice-gql) when making API calls.
124+
"""
125+
end
126+
end
93127
end

lib/peek_app_sdk/metrics.ex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ defmodule PeekAppSDK.Metrics do
99
defdelegate track_uninstall(external_refid, name, is_test, opts \\ []),
1010
to: PeekAppSDK.Metrics.Client
1111

12+
defdelegate update_configuration_status(install_id, status, notes \\ nil),
13+
to: PeekAppSDK.Metrics.Client
14+
1215
@doc """
1316
Tracks an event with the given event ID and payload.
1417

lib/peek_app_sdk/metrics/client.ex

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
defmodule PeekAppSDK.Metrics.Client do
2+
alias PeekAppSDK.Config
3+
24
@moduledoc """
35
Client for sending metrics to the Peek Pro metrics service.
46
"""
@@ -16,6 +18,32 @@ defmodule PeekAppSDK.Metrics.Client do
1618
Tesla.client(middleware)
1719
end
1820

21+
def update_configuration_status(install_id, status, notes \\ nil, config_id \\ nil) do
22+
# Check for deprecated configuration when using the new update_configuration_status feature
23+
Config.check_deprecated_config!()
24+
25+
body = %{
26+
status: status,
27+
notes: notes
28+
}
29+
30+
config = Config.get_config(config_id)
31+
peek_api_key = config.peek_api_key
32+
peek_app_id = config.peek_app_id
33+
peek_api_base_url = config.peek_api_base_url
34+
35+
url =
36+
"#{peek_api_base_url}/registry/installations/#{peek_app_id}/#{install_id}/configuration_status"
37+
38+
case Tesla.put!(client(), url, body, headers: headers(install_id, config_id, peek_api_key)) do
39+
%Tesla.Env{status: 200} ->
40+
:ok
41+
42+
%Tesla.Env{status: status, body: body} ->
43+
{:error, {status, body}}
44+
end
45+
end
46+
1947
@doc """
2048
Tracks an event with the given event ID and payload.
2149
@@ -136,4 +164,20 @@ defmodule PeekAppSDK.Metrics.Client do
136164
{:error, {status, body}}
137165
end
138166
end
167+
168+
defp headers(install_id, config_id, nil) do
169+
[x_peek_auth_header(install_id, config_id)]
170+
end
171+
172+
defp headers(install_id, config_id, peek_api_key) do
173+
[
174+
x_peek_auth_header(install_id, config_id),
175+
{"pk-api-key", peek_api_key}
176+
]
177+
end
178+
179+
defp x_peek_auth_header(install_id, config_id),
180+
do:
181+
{"X-Peek-Auth",
182+
"Bearer #{PeekAppSDK.Token.new_for_app_installation!(install_id, nil, config_id)}"}
139183
end

lib/peek_app_sdk/plugs/client_auth.ex

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,15 @@ defmodule PeekAppSDK.Plugs.ClientAuth do
2020
plug :set_peek_install_id_from_client, config_id: {:project, :project_name}
2121
"""
2222
def set_peek_install_id_from_client(conn, opts) do
23-
case Plug.Conn.get_req_header(conn, "x-peek-auth") do
24-
["Bearer " <> token] -> do_set(conn, token, opts)
25-
_ -> conn
23+
case conn.body_params do
24+
%{"x-peek-auth" => token} ->
25+
do_set(conn, token, opts)
26+
27+
_ ->
28+
case Plug.Conn.get_req_header(conn, "x-peek-auth") do
29+
["Bearer " <> token] -> do_set(conn, token, opts)
30+
_ -> conn
31+
end
2632
end
2733
end
2834

0 commit comments

Comments
 (0)