Skip to content

High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.

867 B
Raw Blame
package schema

import (
	_ "embed"
	"encoding/json"
	"fmt"
)

// ConfigJSON is the PinchTab config JSON Schema bundled with this build.
//
//go:embed config.json
var ConfigJSON []byte

// ConfigJSONForURL returns ConfigJSON with its public identifier rewritten to
// the URL generated by this build.
func ConfigJSONForURL(schemaURL string) ([]byte, error) {
	var raw map[string]any
	if err := json.Unmarshal(ConfigJSON, &raw); err != nil {
		return nil, fmt.Errorf("parse embedded schema: %w", err)
	}

	raw["$id"] = schemaURL
	properties, _ := raw["properties"].(map[string]any)
	schemaProperty, _ := properties["$schema"].(map[string]any)
	if schemaProperty != nil {
		schemaProperty["default"] = schemaURL
	}

	data, err := json.MarshalIndent(raw, "", "  ")
	if err != nil {
		return nil, fmt.Errorf("render schema: %w", err)
	}
	return append(data, '\n'), nil
}