MCPcopy
hub / github.com/CapSoftware/Cap / resolveTinybirdAuth

Function resolveTinybirdAuth

scripts/analytics/shared.js:103–137  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

101}
102
103function resolveTinybirdAuth() {
104 const envHost = process.env.TINYBIRD_HOST?.trim();
105 const envToken =
106 process.env.TINYBIRD_ADMIN_TOKEN?.trim() ||
107 process.env.TINYBIRD_TOKEN?.trim();
108 if (envHost && envToken) {
109 return {
110 host: formatHost(envHost),
111 token: envToken,
112 source: "env",
113 };
114 }
115
116 const tinyb = loadTinybFile();
117 if (tinyb) {
118 if (!tinyb.data?.token) {
119 throw new Error(
120 `Tinybird auth file at ${tinyb.path} is missing a token.`,
121 );
122 }
123 return {
124 host: formatHost(tinyb.data.host ?? DEFAULT_TINYBIRD_HOST),
125 token: tinyb.data.token,
126 workspaceId: tinyb.data.id,
127 workspaceName: tinyb.data.name,
128 userToken: tinyb.data.user_token,
129 tinybPath: tinyb.path,
130 source: "tinyb",
131 };
132 }
133
134 throw new Error(
135 "Tinybird credentials not found. Set TINYBIRD_TOKEN/TINYBIRD_HOST or run `tb login` to create a .tinyb file.",
136 );
137}
138
139function createTinybirdClient(authOverride) {
140 const auth = authOverride ?? resolveTinybirdAuth();

Callers 4

deleteAllDataFunction · 0.90
mainFunction · 0.90
mainFunction · 0.90
createTinybirdClientFunction · 0.85

Calls 2

formatHostFunction · 0.85
loadTinybFileFunction · 0.85

Tested by

no test coverage detected