mirror of
https://github.com/supabase/supabase.git
synced 2026-07-04 15:24:24 +08:00
* add initial installation flow of stripe sync engine * update docs link * Add supabase_vault extension dep * Add stripe logo to sync engine integration * Move overview content to bottom of integration pages * Add sync state to stripe sync page * only check sync state if stripe integration is installed * Use proper stripe-sync package and setup flows * Improve sync engine installation ux * Remove unused hardcoded dep * Add alpha status to stripe sync engine integration * fix typo * run format * fix types * Rename the stripe-sync path to remove the 'integration". The path needs to have BASE_PATH to work on prod. * Design tidy up (#41337) UI tidy up * update to latest sync engine package * Add stripe key verification * Remove noop try/catch * Add integration isntallation telelemtry * Add basic settings page * Address coderabbit comments * remove unused dep * Remove state setting on render * s/description/comment * Cleanup settings screen UI * Improve settings screen design * update schema test snapshot * Use latest stripe-sync-engine package * Update repo url to new official location * revert marketing change * Update stripe sync engine package * Add link to table from overview page * Add feature flag and improve telemetry * Fix missing useMemo dep * add uninstall telemetry note --------- Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com> Co-authored-by: Saxon Fletcher <saxonafletcher@gmail.com>
65 lines
1.9 KiB
TypeScript
65 lines
1.9 KiB
TypeScript
import { QueryClient, useQuery, UseQueryOptions } from '@tanstack/react-query'
|
|
import { z } from 'zod'
|
|
|
|
import { executeSql, ExecuteSqlError } from 'data/sql/execute-sql-query'
|
|
import { stripeSyncKeys } from './keys'
|
|
|
|
export type DbConnection = {
|
|
projectRef: string
|
|
connectionString?: string | null
|
|
}
|
|
|
|
const StripeSyncStateSchema = z
|
|
.object({
|
|
started_at: z.string().nullable(),
|
|
closed_at: z.string().nullable(),
|
|
status: z.enum(['running', 'pending', 'complete', 'error']).nullable(),
|
|
})
|
|
.nullable()
|
|
|
|
export type StripeSyncState = z.infer<typeof StripeSyncStateSchema>
|
|
|
|
export type StripeSyncStateData = z.infer<typeof StripeSyncStateSchema>
|
|
export type StripeSyncStateError = ExecuteSqlError
|
|
|
|
export async function getStripeSyncState(
|
|
{ projectRef, connectionString }: DbConnection,
|
|
signal?: AbortSignal
|
|
) {
|
|
const { result } = await executeSql(
|
|
{
|
|
projectRef,
|
|
connectionString,
|
|
sql: `
|
|
SELECT started_at, closed_at, status FROM stripe.sync_runs WHERE status != 'pending' ORDER BY started_at DESC LIMIT 1;
|
|
`,
|
|
queryKey: stripeSyncKeys.syncState(projectRef),
|
|
},
|
|
signal
|
|
)
|
|
|
|
return result.length > 0 ? StripeSyncStateSchema.parse(result[0]) : null
|
|
}
|
|
|
|
export const useStripeSyncingState = <TData = StripeSyncStateData>(
|
|
{ projectRef, connectionString }: DbConnection,
|
|
{
|
|
enabled = true,
|
|
...options
|
|
}: Omit<
|
|
UseQueryOptions<StripeSyncStateData, StripeSyncStateError, TData>,
|
|
'queryKey' | 'queryFn'
|
|
> = {}
|
|
) => {
|
|
return useQuery<StripeSyncStateData, StripeSyncStateError, TData>({
|
|
queryKey: stripeSyncKeys.syncState(projectRef),
|
|
queryFn: ({ signal }) => getStripeSyncState({ projectRef, connectionString }, signal),
|
|
enabled: enabled && typeof projectRef !== 'undefined',
|
|
...options,
|
|
})
|
|
}
|
|
|
|
export function invalidateStripeSyncStateQuery(client: QueryClient, projectRef: string) {
|
|
return client.invalidateQueries({ queryKey: stripeSyncKeys.syncState(projectRef) })
|
|
}
|