Skip to content

Commit ad1994e

Browse files
authored
chore (examples): Rename source_secret to secret (#2758)
This PR modifies the examples to use the secret parameter when interacting with Electric instead of the deprecated source_secret. Fixes #2732 This PR is the same as #2756 but in the other one the SST state seems to be stuck.
1 parent ca329d3 commit ad1994e

15 files changed

Lines changed: 58 additions & 51 deletions

File tree

.github/workflows/teardown_examples_pr_stack.yml

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,21 +67,17 @@ jobs:
6767
export PR_NUMBER=${{ github.event.number }}
6868
echo "Removing stage pr-$PR_NUMBER"
6969
70-
# If we fail to remove the stage, the app might not have been deployed
71-
# so check the output to see if that's the case
72-
# and if that's the case, exit with a 0 exit code (success)
73-
output=$(pnpm sst remove --stage "pr-$PR_NUMBER" 2>&1)
74-
exit_code=$?
75-
76-
if [ $exit_code -ne 0 ]; then
70+
# Run the command and capture both stdout and stderr
71+
if ! output=$(pnpm sst remove --stage "pr-$PR_NUMBER" 2>&1); then
72+
# Check if the error is because the stage doesn't exist
7773
if echo "$output" | grep -q "Stage not found"; then
7874
echo "Example was not deployed."
7975
exit 0
80-
else
81-
echo "$output" >&2
82-
exit $exit_code
8376
fi
77+
# If it's a different error, print it and fail
78+
echo "Error removing stage: $output" >&2
79+
exit 1
8480
fi
8581
86-
# If we get here, the command succeeded normally
82+
echo "Successfully removed stage"
8783
exit 0

examples/.shared/lib/neon.ts

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,39 @@ export function createNeonDb({
5252

5353
const ownerName = `neondb_owner`
5454

55-
const createCommand = `curl -f -s "https://console.neon.tech/api/v2/projects/$PROJECT_ID/branches/$BRANCH_ID/databases" \
56-
-H 'Accept: application/json' \
57-
-H "Authorization: Bearer $NEON_API_KEY" \
58-
-H 'Content-Type: application/json' \
59-
-d '{
60-
"database": {
61-
"name": "'$DATABASE_NAME'",
62-
"owner_name": "${ownerName}"
63-
}
64-
}' \
65-
&& echo " SUCCESS" || echo " FAILURE"`
55+
const createCommand = `
56+
max_retries=10
57+
retry_count=0
58+
59+
while [ $retry_count -lt $max_retries ]; do
60+
response=$(curl -f -s -w "\\n%{http_code}" "https://console.neon.tech/api/v2/projects/$PROJECT_ID/branches/$BRANCH_ID/databases" \
61+
-H 'Accept: application/json' \
62+
-H "Authorization: Bearer $NEON_API_KEY" \
63+
-H 'Content-Type: application/json' \
64+
-d '{
65+
"database": {
66+
"name": "'$DATABASE_NAME'",
67+
"owner_name": "${ownerName}"
68+
}
69+
}' 2>/dev/null)
70+
71+
status_code=$(echo "$response" | tail -n1)
72+
73+
if [ "$status_code" = "423" ]; then
74+
retry_count=$((retry_count + 1))
75+
if [ $retry_count -eq $max_retries ]; then
76+
echo " Max retries reached"
77+
echo " FAILURE"
78+
exit 1
79+
fi
80+
# Random sleep between 1-5 seconds
81+
sleep $((RANDOM % 5 + 1))
82+
continue
83+
fi
84+
85+
echo " SUCCESS"
86+
exit 0
87+
done`
6688

6789
const updateCommand = `echo "Cannot update Neon database with this provisioning method SUCCESS"`
6890

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export const baseUrl = import.meta.env.VITE_ELECTRIC_URL
22
? new URL(import.meta.env.VITE_ELECTRIC_URL).origin
33
: `http://localhost:3000`
4-
export const source_secret = import.meta.env.VITE_ELECTRIC_SOURCE_SECRET ?? ``
4+
export const secret = import.meta.env.VITE_ELECTRIC_SOURCE_SECRET ?? ``
55
export const source_id = import.meta.env.VITE_ELECTRIC_SOURCE_ID ?? ``

examples/linearlite-read-only/src/pages/Issue/Comments.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { formatDate } from '../../utils/date'
88
import { showWarning } from '../../utils/notification'
99
import { Comment, Issue } from '../../types/types'
1010
import { useShape } from '@electric-sql/react'
11-
import { baseUrl, source_id, source_secret } from '../../electric'
11+
import { baseUrl, source_id, secret } from '../../electric'
1212

1313
export interface CommentsProps {
1414
issue: Issue
@@ -19,7 +19,7 @@ function Comments(commentProps: CommentsProps) {
1919
const allComments = useShape({
2020
url: `${baseUrl}/v1/shape`,
2121
params: {
22-
source_secret,
22+
secret,
2323
source_id,
2424
table: `comment`,
2525
},
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { ShapeStreamOptions } from '@electric-sql/client'
2-
import { baseUrl, source_id, source_secret } from './electric'
2+
import { baseUrl, source_id, secret } from './electric'
33

44
export const issueShape: ShapeStreamOptions = {
55
url: `${baseUrl}/v1/shape/`,
66
params: {
77
table: `issue`,
8-
source_secret,
8+
secret,
99
source_id,
1010
},
1111
}

examples/linearlite/src/sync.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ async function startSyncToDatabase(pg: PGliteWithExtensions) {
5858

5959
const issueUrl = new URL(`${ELECTRIC_URL}/v1/shape`)
6060
if (ELECTRIC_SOURCE_SECRET) {
61-
issueUrl.searchParams.set('source_secret', ELECTRIC_SOURCE_SECRET)
61+
issueUrl.searchParams.set('secret', ELECTRIC_SOURCE_SECRET)
6262
}
6363

6464
// Issues Sync
@@ -94,7 +94,7 @@ async function startSyncToDatabase(pg: PGliteWithExtensions) {
9494

9595
const commentUrl = new URL(`${ELECTRIC_URL}/v1/shape`)
9696
if (ELECTRIC_SOURCE_SECRET) {
97-
commentUrl.searchParams.set('source_secret', ELECTRIC_SOURCE_SECRET)
97+
commentUrl.searchParams.set('secret', ELECTRIC_SOURCE_SECRET)
9898
}
9999

100100
// Comments Sync

examples/linearlite/sst.config.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ export default $config({
6363

6464
return {
6565
databaseUri,
66-
// source_id: electricInfo.id,
67-
// source_secret: electricInfo.source_secret,
6866
website: website.url,
6967
}
7068
} catch (e) {

examples/proxy-auth/app/shape-proxy/route.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ export async function GET(request: Request) {
1313
}
1414

1515
if (process.env.ELECTRIC_SOURCE_SECRET) {
16-
originUrl.searchParams.set(
17-
`source_secret`,
18-
process.env.ELECTRIC_SOURCE_SECRET
19-
)
16+
originUrl.searchParams.set(`secret`, process.env.ELECTRIC_SOURCE_SECRET)
2017
}
2118

2219
// authentication and authorization

examples/react/src/Example.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const Example = () => {
1111
params: {
1212
table: `items`,
1313
source_id: import.meta.env.VITE_ELECTRIC_SOURCE_ID,
14-
source_secret: import.meta.env.VITE_ELECTRIC_SOURCE_SECRET,
14+
secret: import.meta.env.VITE_ELECTRIC_SOURCE_SECRET,
1515
},
1616
})
1717

examples/remix/app/routes/shape-proxy.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ export async function loader({ request }: LoaderFunctionArgs) {
1313
})
1414

1515
originUrl.searchParams.set(`source_id`, process.env.ELECTRIC_SOURCE_ID!)
16-
originUrl.searchParams.set(
17-
`source_secret`,
18-
process.env.ELECTRIC_SOURCE_SECRET!
19-
)
16+
originUrl.searchParams.set(`secret`, process.env.ELECTRIC_SOURCE_SECRET!)
2017

2118
const response = await fetch(originUrl)
2219

0 commit comments

Comments
 (0)