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
11 changes: 7 additions & 4 deletions scripts/build-release.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ import { releaseSettings } from "./build-release";
import { buildAccountFunction,currentRouting,HTTP_PATHS } from "./package-tidebound-review";

test("only production builds receive explicitly allowlisted public account settings",()=>{
expect(releaseSettings({})).toEqual({appId:"",clientId:"",sealedNote:false});
expect(releaseSettings({VERCEL_ENV:"preview",PRIVY_APP_ID:"prod-app",VITE_PRIVY_CLIENT_ID:"prod-client",VITE_SEALED_NOTE_ENABLED:"true"})).toEqual({appId:"",clientId:"",sealedNote:false});
expect(releaseSettings({VERCEL_ENV:"production",PRIVY_APP_ID:"existing-app"})).toEqual({appId:"existing-app",clientId:"",sealedNote:false});
expect(releaseSettings({})).toEqual({appId:"",clientId:"",sealedNote:false,records:false});
expect(releaseSettings({VERCEL_ENV:"preview",PRIVY_APP_ID:"prod-app",VITE_PRIVY_CLIENT_ID:"prod-client",VITE_SEALED_NOTE_ENABLED:"true"})).toEqual({appId:"",clientId:"",sealedNote:false,records:false});
expect(releaseSettings({VERCEL_ENV:"production",PRIVY_APP_ID:"existing-app"})).toEqual({appId:"existing-app",clientId:"",sealedNote:false,records:false});
expect(releaseSettings({VERCEL_ENV:"production",PRIVY_APP_ID:"existing-app",VITE_SEALED_NOTE_ENABLED:"1"}).sealedNote).toBe(false);
expect(releaseSettings({VERCEL_ENV:"production",PRIVY_APP_ID:"existing-app",VITE_SEALED_NOTE_ENABLED:"true"}).sealedNote).toBe(true);
expect(releaseSettings({VERCEL_ENV:"production",VITE_PRIVY_APP_ID:"public-app",PRIVY_APP_ID:"fallback",VITE_PRIVY_CLIENT_ID:"public-client"})).toEqual({appId:"public-app",clientId:"public-client",sealedNote:false});
expect(releaseSettings({VERCEL_ENV:"production",PRIVY_APP_ID:"existing-app",VITE_RECORDS_ENABLED:"true"}).records).toBe(true);
expect(releaseSettings({VERCEL_ENV:"production",PRIVY_APP_ID:"existing-app",VITE_RECORDS_ENABLED:"yes"}).records).toBe(false);
expect(releaseSettings({VERCEL_ENV:"preview",PRIVY_APP_ID:"existing-app",VITE_RECORDS_ENABLED:"true"}).records).toBe(false);
expect(releaseSettings({VERCEL_ENV:"production",VITE_PRIVY_APP_ID:"public-app",PRIVY_APP_ID:"fallback",VITE_PRIVY_CLIENT_ID:"public-client"})).toEqual({appId:"public-app",clientId:"public-client",sealedNote:false,records:false});
for(const id of ["","invalid id", "a".repeat(129)])
expect(()=>releaseSettings({VERCEL_ENV:"production",PRIVY_APP_ID:id})).toThrow();
expect(()=>releaseSettings({VERCEL_ENV:"production",PRIVY_APP_SECRET:"never-an-app-id"})).toThrow();
Expand Down
7 changes: 4 additions & 3 deletions scripts/build-release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import { join,resolve } from "node:path";
import { buildAccountFunction,buildGameSite,currentRouting } from "./package-tidebound-review";

export function releaseSettings(env:Record<string,string|undefined>){
if(env.VERCEL_ENV!=="production")return {appId:"",clientId:"",sealedNote:false};
if(env.VERCEL_ENV!=="production")return {appId:"",clientId:"",sealedNote:false,records:false};
const appId=env.VITE_PRIVY_APP_ID??env.PRIVY_APP_ID??"",clientId=env.VITE_PRIVY_CLIENT_ID??"";
const id=/^[A-Za-z0-9_-]{1,128}$/;
if(!id.test(appId)||(clientId&&!id.test(clientId)))throw Error("Production requires a valid public Privy app ID and, if supplied, a valid public client ID.");
// Mochi's sealed note needs the account endpoints, so it is off unless production explicitly opts in.
return {appId,clientId,sealedNote:env.VITE_SEALED_NOTE_ENABLED==="true"};
// Harbor records read public chain state for a signed-in player; also explicit opt-in.
return {appId,clientId,sealedNote:env.VITE_SEALED_NOTE_ENABLED==="true",records:env.VITE_RECORDS_ENABLED==="true"};
}

export async function buildRelease(source:string,settings:ReturnType<typeof releaseSettings>){
Expand All @@ -19,7 +20,7 @@ export async function buildRelease(source:string,settings:ReturnType<typeof rele
try{
const site=join(staged,"static");
await mkdir(site);
await buildGameSite(source,site,settings.appId,settings.clientId,settings.sealedNote);
await buildGameSite(source,site,settings.appId,settings.clientId,settings.sealedNote,settings.records);
if(settings.appId)await buildAccountFunction(source,staged);
await writeFile(join(staged,"config.json"),JSON.stringify(currentRouting(),null,2)+"\n");
await rm(output,{recursive:true,force:true});
Expand Down
3 changes: 2 additions & 1 deletion scripts/package-tidebound-review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export async function buildAccountFunction(source:string,output:string){
return installFunctionAliases(output);
}

export async function buildGameSite(source:string,site:string,appId:string,clientId:string,sealedNote=false){
export async function buildGameSite(source:string,site:string,appId:string,clientId:string,sealedNote=false,records=false){
const overlay=await mkdtemp(join(tmpdir(),"familiar-game-static-"));
try{
await build({configFile:false,plugins:[react()],root:join(source,"web"),envDir:false,envPrefix:[],publicDir:false,define:{
Expand All @@ -140,6 +140,7 @@ export async function buildGameSite(source:string,site:string,appId:string,clien
"import.meta.env.VITE_NEAR_RPC_URL":JSON.stringify("https://test.rpc.fastnear.com"),"import.meta.env.VITE_RELAYER_URL":JSON.stringify("/api"),
"import.meta.env.VITE_TIDEBOUND_ENABLED":JSON.stringify(appId?"true":"false"),
"import.meta.env.VITE_SEALED_NOTE_ENABLED":JSON.stringify(appId&&sealedNote?"true":"false"),
"import.meta.env.VITE_RECORDS_ENABLED":JSON.stringify(appId&&records?"true":"false"),
},build:{outDir:overlay,rollupOptions:{input:{home:join(source,"web/index.html"),outing:join(source,"web/outing/index.html")},output:{manualChunks:id=>id.includes("/phaser/")?"phaser":undefined}}}});
const staticReport=await copyGameStatic(overlay,site);
const runtimeAssets=await copyRuntimeAssets(join(source,"web/public"),site);
Expand Down