Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions .github/workflows/mirror.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ jobs:
runs-on: ubuntu-latest
name: Mirror main branch to sandbox and gigabugs branch
steps:
- name: Mirror main to sandbox
id: mirror-sandbox
uses: google/mirror-branch-action@v2.0
with:
github-token: ${{ secrets.PERSONAL_GITHUB_TOKEN }}
source: 'main'
dest: 'sandbox'
- name: Mirror main to gigabugs
id: mirror-gigabugs
uses: google/mirror-branch-action@v2.0
with:
github-token: ${{ secrets.PERSONAL_GITHUB_TOKEN }}
source: 'main'
dest: 'gigabugs'
- name: Mirror main to sandbox
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was just the output of running prettier across all GH workflow defs

id: mirror-sandbox
uses: google/mirror-branch-action@v2.0
with:
github-token: ${{ secrets.PERSONAL_GITHUB_TOKEN }}
source: 'main'
dest: 'sandbox'
- name: Mirror main to gigabugs
id: mirror-gigabugs
uses: google/mirror-branch-action@v2.0
with:
github-token: ${{ secrets.PERSONAL_GITHUB_TOKEN }}
source: 'main'
dest: 'gigabugs'
8 changes: 4 additions & 4 deletions .github/workflows/sst-gigabugs-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ jobs:
env:
ZERO_UPSTREAM_DB: ${{ secrets.GIGABUGS_ZERO_UPSTREAM_DB }}
ZERO_ENABLE_QUERY_PLANNER: 'true'
ZERO_PUSH_URL: ${{ vars.GIGABUGS_ZERO_PUSH_URL }}
ZERO_GET_QUERIES_URL: ${{ vars.GIGABUGS_ZERO_PULL_URL }}
ZERO_MUTATE_URL: ${{ vars.GIGABUGS_ZERO_PUSH_URL }}
ZERO_QUERY_URL: ${{ vars.GIGABUGS_ZERO_PULL_URL }}
ZERO_CVR_DB: ${{ secrets.GIGABUGS_ZERO_CVR_DB }}
ZERO_CHANGE_DB: ${{ secrets.GIGABUGS_ZERO_CHANGE_DB }}
ZERO_AUTH_JWK: ${{ secrets.GIGABUGS_ZERO_AUTH_JWK }}
Expand All @@ -100,8 +100,8 @@ jobs:
ZERO_APP_ID: 'gigabugs1'
ZERO_UPSTREAM_DB: ${{ secrets.GIGABUGS_ZERO_UPSTREAM_DB }}
ZERO_ENABLE_QUERY_PLANNER: 'true'
ZERO_PUSH_URL: ${{ vars.GIGABUGS_ZERO_PUSH_URL }}
ZERO_GET_QUERIES_URL: ${{ vars.GIGABUGS_ZERO_PULL_URL }}
ZERO_MUTATE_URL: ${{ vars.GIGABUGS_ZERO_PUSH_URL }}
ZERO_QUERY_URL: ${{ vars.GIGABUGS_ZERO_PULL_URL }}
ZERO_CVR_DB: ${{ secrets.GIGABUGS_ZERO_CVR_DB }}2
ZERO_CHANGE_DB: ${{ secrets.GIGABUGS_ZERO_CHANGE_DB }}2
ZERO_AUTH_JWK: ${{ secrets.GIGABUGS_ZERO_AUTH_JWK }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/sst-prod-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ jobs:
ZERO_UPSTREAM_DB: ${{ secrets.PROD_ZERO_UPSTREAM_DB }}
ZERO_ENABLE_QUERY_PLANNER: 'true'
ZERO_ADMIN_PASSWORD: ${{ secrets.ZERO_ADMIN_PASSWORD }}
ZERO_PUSH_URL: ${{ vars.PROD_ZERO_PUSH_URL }}
ZERO_GET_QUERIES_URL: ${{ vars.PROD_ZERO_PULL_URL }}
ZERO_MUTATE_URL: ${{ vars.PROD_ZERO_PUSH_URL }}
ZERO_QUERY_URL: ${{ vars.PROD_ZERO_PULL_URL }}
ZERO_CVR_DB: ${{ secrets.PROD_ZERO_CVR_DB }}
ZERO_CHANGE_DB: ${{ secrets.PROD_ZERO_CHANGE_DB }}
ZERO_AUTH_JWK: ${{ secrets.PROD_ZERO_AUTH_JWK }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/sst-sandbox-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ jobs:
env:
ZERO_UPSTREAM_DB: ${{ secrets.SANDBOX_ZERO_UPSTREAM_DB }}
ZERO_ENABLE_QUERY_PLANNER: 'true'
ZERO_PUSH_URL: ${{ vars.SANDBOX_ZERO_PUSH_URL }}
ZERO_GET_QUERIES_URL: ${{ vars.SANDBOX_ZERO_PULL_URL }}
ZERO_MUTATE_URL: ${{ vars.SANDBOX_ZERO_PUSH_URL }}
ZERO_QUERY_URL: ${{ vars.SANDBOX_ZERO_PULL_URL }}
ZERO_CVR_DB: ${{ secrets.SANDBOX_ZERO_CVR_DB }}
ZERO_CHANGE_DB: ${{ secrets.SANDBOX_ZERO_CHANGE_DB }}
ZERO_AUTH_JWK: ${{ secrets.SANDBOX_ZERO_AUTH_JWK }}
Expand Down
2 changes: 1 addition & 1 deletion apps/zbugs/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ZERO_UPSTREAM_DB = "postgresql://user:password@127.0.0.1:6434/postgres"

# Where to send custom mutations
ZERO_MUTATE_URL = "http://localhost:5173/api/mutate"
ZERO_GET_QUERIES_URL= "http://localhost:5173/api/get-queries"
ZERO_QUERY_URL = "http://localhost:5173/api/query"

ZERO_LOG_LEVEL = "info"

Expand Down
8 changes: 5 additions & 3 deletions apps/zbugs/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,17 +203,19 @@ async function mutateHandler(
reply.send(response);
}

// this endpoint was kept for backwards compatibility
// in the transition to /query
fastify.post<{
Querystring: Record<string, string>;
Body: ReadonlyJSONValue;
}>('/api/pull', getQueriesHandler);
}>('/api/get-queries', queryHandler);

fastify.post<{
Querystring: Record<string, string>;
Body: ReadonlyJSONValue;
}>('/api/get-queries', getQueriesHandler);
}>('/api/query', queryHandler);

async function getQueriesHandler(
async function queryHandler(
request: FastifyRequest<{
Querystring: Record<string, string>;
Body: ReadonlyJSONValue;
Expand Down
2 changes: 1 addition & 1 deletion apps/zbugs/src/zero-init.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function ZeroInit({children}: {children: ReactNode}) {
// changing the auth token will cause ZeroProvider to call connection.connect
auth: login.loginState?.encoded,
mutateURL: `${window.location.origin}/api/mutate`,
getQueriesURL: `${window.location.origin}/api/get-queries`,
queryURL: `${window.location.origin}/api/query`,
context: login.loginState?.decoded,
}}
>
Expand Down
6 changes: 5 additions & 1 deletion packages/zero-cache/src/auth/jwt.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import {
createRemoteJWKSet,
exportJWK,
generateKeyPair,
jwtVerify,
type JWK,
type JWTClaimVerificationOptions,
type JWTPayload,
type KeyLike,
} from 'jose';
import type {AuthConfig} from '../config/zero-config.ts';
import {exportJWK, generateKeyPair} from 'jose';

/** @deprecated */
export async function createJwkPair() {
const {publicKey, privateKey} = await generateKeyPair('PS256');

Expand All @@ -35,6 +37,7 @@ function getRemoteKeyset(jwksUrl: string) {
return remoteKeyset;
}

/** @deprecated */
export const tokenConfigOptions = (config: AuthConfig) => {
const tokenOptions = (['jwk', 'secret', 'jwksUrl'] as const).filter(
key => config[key] !== undefined,
Expand All @@ -43,6 +46,7 @@ export const tokenConfigOptions = (config: AuthConfig) => {
return tokenOptions;
};

/** @deprecated */
export async function verifyToken(
config: AuthConfig,
token: string,
Expand Down
50 changes: 49 additions & 1 deletion packages/zero-cache/src/config/zero-config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ test('zero-cache --help', () => {

--get-queries-url string[] optional
ZERO_GET_QUERIES_URL env
DEPRECATED. Use query-url instead.
The URL of the API server to which zero-cache will send synced queries.

IMPORTANT: URLs are matched using URLPattern, a standard Web API.
Expand Down Expand Up @@ -186,6 +186,54 @@ test('zero-cache --help', () => {
This is useful for passing authentication cookies to the API server.
If false, cookies are not forwarded.

--query-url string[] optional
ZERO_QUERY_URL env

The URL of the API server to which zero-cache will send synced queries.

IMPORTANT: URLs are matched using URLPattern, a standard Web API.

Pattern Syntax:
URLPattern uses a simple and intuitive syntax similar to Express routes.
Wildcards and named parameters make it easy to match multiple URLs.

Basic Examples:
Exact URL match:
"https://api.example.com/mutate"
Any subdomain using wildcard:
"https://*.example.com/mutate"
Multiple subdomain levels:
"https://*.*.example.com/mutate"
Any path under a domain:
"https://api.example.com/*"
Named path parameters:
"https://api.example.com/:version/mutate"
↳ Matches "https://api.example.com/v1/mutate", "https://api.example.com/v2/mutate", etc.

Advanced Patterns:
Optional path segments:
"https://api.example.com/:path?"
Regex in segments (for specific patterns):
"https://api.example.com/:version(v\\d+)/mutate"
↳ Matches only "v" followed by digits

Multiple patterns:
["https://api1.example.com/mutate", "https://api2.example.com/mutate"]

Note: Query parameters and URL fragments (#) are automatically ignored during matching.

For full URLPattern syntax, see: https://developer.mozilla.org/en-US/docs/Web/API/URLPattern

--query-api-key string optional
ZERO_QUERY_API_KEY env
An optional secret used to authorize zero-cache to call the API server handling writes.

--query-forward-cookies boolean default: false
ZERO_QUERY_FORWARD_COOKIES env
If true, zero-cache will forward cookies from the request.
This is useful for passing authentication cookies to the API server.
If false, cookies are not forwarded.

--cvr-db string optional
ZERO_CVR_DB env
The Postgres database used to store CVRs. CVRs (client view records) keep track
Expand Down
12 changes: 11 additions & 1 deletion packages/zero-cache/src/config/zero-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@ const makeMutatorQueryOptions = (
const mutateOptions = makeMutatorQueryOptions(undefined, 'push mutations');
const pushOptions = makeMutatorQueryOptions('mutate-url', 'push mutations');
const queryOptions = makeMutatorQueryOptions(undefined, 'send synced queries');
const getQueriesOptions = makeMutatorQueryOptions(
'query-url',
'send synced queries',
);

export type AuthConfig = Config<typeof authOptions>;

Expand Down Expand Up @@ -276,9 +280,12 @@ export const zeroOptions = {
},
},

/** @deprecated */
push: pushOptions,
mutate: mutateOptions,
getQueries: queryOptions,
/** @deprecated */
getQueries: getQueriesOptions,
query: queryOptions,

cvr: {
db: {
Expand Down Expand Up @@ -429,6 +436,7 @@ export const zeroOptions = {
],
},

/** @deprecated */
address: {
type: v.string().optional(),
deprecated: [
Expand All @@ -437,6 +445,7 @@ export const zeroOptions = {
hidden: true,
},

/** @deprecated */
protocol: {
type: v.literalUnion('ws', 'wss').default('ws'),
deprecated: [
Expand Down Expand Up @@ -667,6 +676,7 @@ export const zeroOptions = {
},
},

/** @deprecated */
targetClientRowCount: {
type: v.number().default(20_000),
deprecated: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ describe('CustomQueryTransformer', () => {
// fetchFromAPIServer will throw a regular Error (not ProtocolError) for disallowed URLs
mockFetchFromAPIServer.mockRejectedValue(
new Error(
`URL "${disallowedUrl}" is not allowed by the ZERO_MUTATE/GET_QUERIES_URL configuration`,
`URL "${disallowedUrl}" is not allowed by the ZERO_MUTATE/QUERY_URL configuration`,
),
);

Expand All @@ -690,7 +690,7 @@ describe('CustomQueryTransformer', () => {
origin: ErrorOrigin.ZeroCache,
reason: ErrorReason.Internal,
message: expect.stringContaining(
`URL "${disallowedUrl}" is not allowed by the ZERO_MUTATE/GET_QUERIES_URL configuration`,
`URL "${disallowedUrl}" is not allowed by the ZERO_MUTATE/QUERY_URL configuration`,
),
queryIDs: ['query1'],
});
Expand Down
2 changes: 1 addition & 1 deletion packages/zero-cache/src/custom-queries/transform-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class CustomQueryTransformer {
userQueryURL ??
must(
this.#config.url[0],
'A ZERO_GET_QUERIES_URL must be configured for custom queries',
'A ZERO_QUERY_URL must be configured for custom queries',
),
this.#urlPatterns,
this.#shard,
Expand Down
2 changes: 1 addition & 1 deletion packages/zero-cache/src/custom/fetch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ describe('fetchFromAPIServer', () => {
body,
),
).rejects.toThrow(
'URL "https://evil.example.com/endpoint" is not allowed by the ZERO_GET_QUERIES_URL configuration',
'URL "https://evil.example.com/endpoint" is not allowed by the ZERO_QUERY_URL configuration',
);
expect(mockFetch).not.toHaveBeenCalled();
});
Expand Down
Loading
Loading