@numericoach/gskills-admin-cli 0.1.25 → 0.1.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -165,6 +165,7 @@ gskills-admin skills install --name gskills-customer-playbooks --target ~/.codex
|
|
|
165
165
|
gskills-admin skills install --name gskills-feedback-db-ops --target ~/.codex/skills
|
|
166
166
|
gskills-admin skills install --name gskills-source-id-repair --target ~/.codex/skills
|
|
167
167
|
gskills-admin skills install --name gskills-user-session-invalidation --target ~/.codex/skills
|
|
168
|
+
gskills-admin skills install --name gskills-admin-cli-publishing --target ~/.codex/skills
|
|
168
169
|
```
|
|
169
170
|
|
|
170
171
|
## Output
|
package/dist/gskills-admin.js
CHANGED
|
@@ -186,6 +186,9 @@ var loginWithGSkills = async (input) => {
|
|
|
186
186
|
if (callback.state !== state) {
|
|
187
187
|
throw new CliError("GSkills auth state mismatch", 403);
|
|
188
188
|
}
|
|
189
|
+
if (!callback.code) {
|
|
190
|
+
throw new CliError("GSkills CLI login callback did not include an auth code", 403);
|
|
191
|
+
}
|
|
189
192
|
const tokenResponse = await fetch(new URL("/api/cli/auth/token", baseUrl), {
|
|
190
193
|
method: "POST",
|
|
191
194
|
headers: {
|
|
@@ -214,6 +217,36 @@ var loginWithGSkills = async (input) => {
|
|
|
214
217
|
user: payload.user
|
|
215
218
|
};
|
|
216
219
|
};
|
|
220
|
+
var waitForGoogleSheetsOAuth = async (input) => {
|
|
221
|
+
const baseUrl = normalizeBaseUrl(input.baseUrl);
|
|
222
|
+
const host = input.host ?? "127.0.0.1";
|
|
223
|
+
const state = randomUUID();
|
|
224
|
+
const callback = await waitForLocalCallback(host, input.port ?? 0, async (redirectUri) => {
|
|
225
|
+
const startUrl = new URL("/api/cli/imported-sheets/oauth/start", baseUrl);
|
|
226
|
+
startUrl.searchParams.set("redirect_uri", redirectUri);
|
|
227
|
+
startUrl.searchParams.set("state", state);
|
|
228
|
+
startUrl.searchParams.set("instanceId", input.instanceId);
|
|
229
|
+
startUrl.searchParams.set("lang", input.lang ?? "fr");
|
|
230
|
+
if (input.ownerEmail)
|
|
231
|
+
startUrl.searchParams.set("ownerEmail", input.ownerEmail);
|
|
232
|
+
const opened = await openUrl(startUrl.toString());
|
|
233
|
+
if (opened) {
|
|
234
|
+
process.stderr.write(`Opened ${startUrl.toString()}
|
|
235
|
+
`);
|
|
236
|
+
}
|
|
237
|
+
}, {
|
|
238
|
+
timeoutMs: input.timeoutMs,
|
|
239
|
+
successMessage: "Google Sheets access connected. You can go back to Codex now.",
|
|
240
|
+
errorPrefix: "Google Sheets OAuth failed"
|
|
241
|
+
});
|
|
242
|
+
if (callback.state !== state) {
|
|
243
|
+
throw new CliError("Google Sheets OAuth state mismatch", 403);
|
|
244
|
+
}
|
|
245
|
+
return {
|
|
246
|
+
connected: true,
|
|
247
|
+
userEmail: callback.userEmail
|
|
248
|
+
};
|
|
249
|
+
};
|
|
217
250
|
var getApiSession = async () => {
|
|
218
251
|
const session = await readSession();
|
|
219
252
|
if (!session) {
|
|
@@ -235,32 +268,42 @@ var whoami = async () => {
|
|
|
235
268
|
}
|
|
236
269
|
return payload;
|
|
237
270
|
};
|
|
238
|
-
var waitForLocalCallback = async (host, port, onReady) => {
|
|
271
|
+
var waitForLocalCallback = async (host, port, onReady, options = {}) => {
|
|
239
272
|
return new Promise((resolve, reject) => {
|
|
273
|
+
const timeout = options.timeoutMs ? setTimeout(() => {
|
|
274
|
+
server.close();
|
|
275
|
+
reject(new CliError("Timed out waiting for browser OAuth callback", 408));
|
|
276
|
+
}, options.timeoutMs) : null;
|
|
277
|
+
const finish = (callback) => {
|
|
278
|
+
if (timeout)
|
|
279
|
+
clearTimeout(timeout);
|
|
280
|
+
server.close();
|
|
281
|
+
callback();
|
|
282
|
+
};
|
|
240
283
|
const server = createServer((request, response) => {
|
|
241
284
|
try {
|
|
242
285
|
const url = new URL(request.url ?? "/", `http://${host}`);
|
|
243
286
|
const code = url.searchParams.get("code");
|
|
244
287
|
const state = url.searchParams.get("state");
|
|
288
|
+
const status = url.searchParams.get("status");
|
|
289
|
+
const userEmail = url.searchParams.get("userEmail") ?? undefined;
|
|
245
290
|
const error = url.searchParams.get("error");
|
|
246
291
|
if (error) {
|
|
247
|
-
response.writeHead(403, { "content-type": "text/
|
|
248
|
-
response.end(
|
|
249
|
-
|
|
250
|
-
reject(new CliError(`GSkills CLI login failed: ${error}`, 403));
|
|
292
|
+
response.writeHead(403, { "content-type": "text/html; charset=utf-8" });
|
|
293
|
+
response.end(callbackHtml("Google Sheets access failed", `Error: ${escapeHtml(error)}`));
|
|
294
|
+
finish(() => reject(new CliError(`${options.errorPrefix ?? "GSkills CLI login failed"}: ${error}`, 403)));
|
|
251
295
|
return;
|
|
252
296
|
}
|
|
253
|
-
if (!
|
|
297
|
+
if (!state) {
|
|
254
298
|
response.writeHead(400, { "content-type": "text/plain" });
|
|
255
|
-
response.end("Missing
|
|
299
|
+
response.end("Missing callback state.");
|
|
256
300
|
return;
|
|
257
301
|
}
|
|
258
|
-
response.writeHead(200, { "content-type": "text/
|
|
259
|
-
response.end("GSkills CLI login complete. You can close this tab.");
|
|
260
|
-
|
|
261
|
-
resolve({ code, state });
|
|
302
|
+
response.writeHead(200, { "content-type": "text/html; charset=utf-8" });
|
|
303
|
+
response.end(callbackHtml("All good", options.successMessage ?? "GSkills CLI login complete. You can close this tab."));
|
|
304
|
+
finish(() => resolve({ code: code ?? undefined, state, status: status ?? undefined, userEmail }));
|
|
262
305
|
} catch (error) {
|
|
263
|
-
reject(error);
|
|
306
|
+
finish(() => reject(error));
|
|
264
307
|
}
|
|
265
308
|
});
|
|
266
309
|
server.on("error", reject);
|
|
@@ -279,6 +322,29 @@ var waitForLocalCallback = async (host, port, onReady) => {
|
|
|
279
322
|
});
|
|
280
323
|
});
|
|
281
324
|
};
|
|
325
|
+
var callbackHtml = (title, message) => `<!doctype html>
|
|
326
|
+
<html lang="en">
|
|
327
|
+
<head>
|
|
328
|
+
<meta charset="utf-8" />
|
|
329
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
330
|
+
<title>${escapeHtml(title)}</title>
|
|
331
|
+
<style>
|
|
332
|
+
body { margin: 0; min-height: 100vh; display: grid; place-items: center; font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: #f8fafc; color: #0f172a; }
|
|
333
|
+
main { width: min(520px, calc(100vw - 32px)); }
|
|
334
|
+
img { width: 40px; height: 40px; display: block; margin-bottom: 20px; }
|
|
335
|
+
h1 { margin: 0 0 10px; font-size: 24px; line-height: 1.2; }
|
|
336
|
+
p { margin: 0; color: #475569; font-size: 15px; line-height: 1.6; }
|
|
337
|
+
</style>
|
|
338
|
+
</head>
|
|
339
|
+
<body>
|
|
340
|
+
<main>
|
|
341
|
+
<img src="https://storage.googleapis.com/public-gskills/applications-icons/google-sheets-icon-2026.png" alt="" />
|
|
342
|
+
<h1>${escapeHtml(title)}</h1>
|
|
343
|
+
<p>${escapeHtml(message)}</p>
|
|
344
|
+
</main>
|
|
345
|
+
</body>
|
|
346
|
+
</html>`;
|
|
347
|
+
var escapeHtml = (value) => value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
282
348
|
var normalizeBaseUrl = (value) => {
|
|
283
349
|
const url = new URL(value);
|
|
284
350
|
url.pathname = "";
|
|
@@ -324,7 +390,7 @@ var requestApi = async (path, init = {}) => {
|
|
|
324
390
|
});
|
|
325
391
|
const payload = await response.json().catch(() => null);
|
|
326
392
|
if (!response.ok) {
|
|
327
|
-
throw new CliError(payload?.error ?? `GSkills API request failed with ${response.status}`, response.status);
|
|
393
|
+
throw new CliError(payload?.error ?? `GSkills API request failed with ${response.status}`, response.status, payload?.details ?? undefined);
|
|
328
394
|
}
|
|
329
395
|
return payload;
|
|
330
396
|
};
|
|
@@ -1775,7 +1841,10 @@ var runImportedSheetsCommand = async (action, importedSheetId, ctx) => {
|
|
|
1775
1841
|
"attach-page",
|
|
1776
1842
|
"set-source",
|
|
1777
1843
|
"delete",
|
|
1778
|
-
"runs"
|
|
1844
|
+
"runs",
|
|
1845
|
+
"connect-google",
|
|
1846
|
+
"oauth",
|
|
1847
|
+
"reconnect-google"
|
|
1779
1848
|
].includes(action);
|
|
1780
1849
|
if (needsInstance && !instanceId)
|
|
1781
1850
|
throw new CliError("Missing --instance", 2);
|
|
@@ -1860,10 +1929,10 @@ var runImportedSheetsCommand = async (action, importedSheetId, ctx) => {
|
|
|
1860
1929
|
};
|
|
1861
1930
|
if (hasFlag(ctx, "dry-run"))
|
|
1862
1931
|
return { operation: "imported-sheets.set-source", importedSheetId, ...payload };
|
|
1863
|
-
return requestApi(`/api/cli/imported-sheets/${importedSheetId}/source`, {
|
|
1932
|
+
return requestImportedSheetApi(ctx, instanceId, "set-source", () => requestApi(`/api/cli/imported-sheets/${importedSheetId}/source`, {
|
|
1864
1933
|
method: "POST",
|
|
1865
1934
|
body: JSON.stringify(payload)
|
|
1866
|
-
});
|
|
1935
|
+
}));
|
|
1867
1936
|
}
|
|
1868
1937
|
if (action === "runs") {
|
|
1869
1938
|
const searchParams = importedSheetSearchParams(ctx);
|
|
@@ -1874,10 +1943,13 @@ var runImportedSheetsCommand = async (action, importedSheetId, ctx) => {
|
|
|
1874
1943
|
const sourceInput = getStringFlag(ctx, "source");
|
|
1875
1944
|
if (!sourceInput)
|
|
1876
1945
|
throw new CliError("Missing --source", 2);
|
|
1877
|
-
return requestApi("/api/cli/imported-sheets/resolve", {
|
|
1946
|
+
return requestImportedSheetApi(ctx, instanceId, "resolve", () => requestApi("/api/cli/imported-sheets/resolve", {
|
|
1878
1947
|
method: "POST",
|
|
1879
1948
|
body: JSON.stringify({ instanceId, sourceInput })
|
|
1880
|
-
});
|
|
1949
|
+
}));
|
|
1950
|
+
}
|
|
1951
|
+
if (action === "connect-google" || action === "oauth" || action === "reconnect-google") {
|
|
1952
|
+
return openImportedSheetGoogleOAuthHandoff(ctx, instanceId, getStringFlag(ctx, "owner-email") ?? getStringFlag(ctx, "account-email"));
|
|
1881
1953
|
}
|
|
1882
1954
|
if (["create", "update", "sync", "enable-locales", "translate", "retranslate", "replace-grid", "patch-cells", "vectorize", "repair-french", "delete"].includes(action)) {
|
|
1883
1955
|
requireWriteConfirmation("Imported sheet operation writes production data. Add --yes or use --dry-run.", ctx);
|
|
@@ -1886,27 +1958,34 @@ var runImportedSheetsCommand = async (action, importedSheetId, ctx) => {
|
|
|
1886
1958
|
const payload = await importedSheetCreatePayload(ctx);
|
|
1887
1959
|
if (hasFlag(ctx, "dry-run"))
|
|
1888
1960
|
return { dryRun: true, operation: "imported-sheets.create", payload };
|
|
1889
|
-
return requestApi("/api/cli/imported-sheets", {
|
|
1961
|
+
return requestImportedSheetApi(ctx, instanceId, "create", () => requestApi("/api/cli/imported-sheets", {
|
|
1890
1962
|
method: "POST",
|
|
1891
1963
|
body: JSON.stringify(payload)
|
|
1892
|
-
});
|
|
1964
|
+
}), importedSheetOwnerEmailFromPayload(payload));
|
|
1893
1965
|
}
|
|
1894
1966
|
if (!importedSheetId)
|
|
1895
1967
|
throw new CliError("Missing imported sheet id", 2);
|
|
1896
1968
|
if (action === "update") {
|
|
1969
|
+
const data = await parseJsonObjectFlag(ctx, "data", "data-file");
|
|
1970
|
+
const ownerUserId = getStringFlag(ctx, "owner-user") ?? getStringFlag(ctx, "owner-user-id");
|
|
1971
|
+
const ownerEmail = getStringFlag(ctx, "owner-email") ?? getStringFlag(ctx, "account-email");
|
|
1972
|
+
if (ownerUserId)
|
|
1973
|
+
data.ownerUserId = ownerUserId;
|
|
1974
|
+
if (ownerEmail)
|
|
1975
|
+
data.ownerEmail = ownerEmail;
|
|
1897
1976
|
const payload = {
|
|
1898
1977
|
instanceId,
|
|
1899
|
-
data
|
|
1978
|
+
data,
|
|
1900
1979
|
dryRun: hasFlag(ctx, "dry-run")
|
|
1901
1980
|
};
|
|
1902
1981
|
if (Object.keys(payload.data).length === 0)
|
|
1903
1982
|
throw new CliError("Missing --data or --data-file JSON", 2);
|
|
1904
1983
|
if (hasFlag(ctx, "dry-run"))
|
|
1905
1984
|
return { operation: "imported-sheets.update", importedSheetId, ...payload };
|
|
1906
|
-
return requestApi(`/api/cli/imported-sheets/${importedSheetId}`, {
|
|
1985
|
+
return requestImportedSheetApi(ctx, instanceId, "update", () => requestApi(`/api/cli/imported-sheets/${importedSheetId}`, {
|
|
1907
1986
|
method: "PATCH",
|
|
1908
1987
|
body: JSON.stringify(payload)
|
|
1909
|
-
});
|
|
1988
|
+
}), importedSheetOwnerEmailFromPayload(data));
|
|
1910
1989
|
}
|
|
1911
1990
|
if (action === "sync") {
|
|
1912
1991
|
const payload = {
|
|
@@ -1916,10 +1995,10 @@ var runImportedSheetsCommand = async (action, importedSheetId, ctx) => {
|
|
|
1916
1995
|
};
|
|
1917
1996
|
if (hasFlag(ctx, "dry-run"))
|
|
1918
1997
|
return { operation: "imported-sheets.sync", importedSheetId, ...payload };
|
|
1919
|
-
return requestApi(`/api/cli/imported-sheets/${importedSheetId}/sync`, {
|
|
1998
|
+
return requestImportedSheetApi(ctx, instanceId, "sync", () => requestApi(`/api/cli/imported-sheets/${importedSheetId}/sync`, {
|
|
1920
1999
|
method: "POST",
|
|
1921
2000
|
body: JSON.stringify(payload)
|
|
1922
|
-
});
|
|
2001
|
+
}));
|
|
1923
2002
|
}
|
|
1924
2003
|
if (action === "enable-locales" || action === "translate") {
|
|
1925
2004
|
const locales = splitCsv(getStringFlag(ctx, "locales") ?? getStringFlag(ctx, "languages") ?? getStringFlag(ctx, "to"));
|
|
@@ -1935,10 +2014,10 @@ var runImportedSheetsCommand = async (action, importedSheetId, ctx) => {
|
|
|
1935
2014
|
};
|
|
1936
2015
|
if (hasFlag(ctx, "dry-run"))
|
|
1937
2016
|
return { operation: `imported-sheets.${action}`, importedSheetId, ...payload };
|
|
1938
|
-
return requestApi(`/api/cli/imported-sheets/${importedSheetId}/translate`, {
|
|
2017
|
+
return requestImportedSheetApi(ctx, instanceId, action, () => requestApi(`/api/cli/imported-sheets/${importedSheetId}/translate`, {
|
|
1939
2018
|
method: "POST",
|
|
1940
2019
|
body: JSON.stringify(payload)
|
|
1941
|
-
});
|
|
2020
|
+
}));
|
|
1942
2021
|
}
|
|
1943
2022
|
if (action === "retranslate") {
|
|
1944
2023
|
const locales = splitCsv(getStringFlag(ctx, "locales") ?? getStringFlag(ctx, "languages") ?? getStringFlag(ctx, "to"));
|
|
@@ -1956,10 +2035,10 @@ var runImportedSheetsCommand = async (action, importedSheetId, ctx) => {
|
|
|
1956
2035
|
};
|
|
1957
2036
|
if (hasFlag(ctx, "dry-run"))
|
|
1958
2037
|
return { operation: "imported-sheets.retranslate", importedSheetId, ...payload };
|
|
1959
|
-
return requestApi(`/api/cli/imported-sheets/${importedSheetId}/retranslate`, {
|
|
2038
|
+
return requestImportedSheetApi(ctx, instanceId, "retranslate", () => requestApi(`/api/cli/imported-sheets/${importedSheetId}/retranslate`, {
|
|
1960
2039
|
method: "POST",
|
|
1961
2040
|
body: JSON.stringify(payload)
|
|
1962
|
-
});
|
|
2041
|
+
}));
|
|
1963
2042
|
}
|
|
1964
2043
|
if (action === "replace-grid") {
|
|
1965
2044
|
const locale = getStringFlag(ctx, "locale") ?? getStringFlag(ctx, "language");
|
|
@@ -1978,10 +2057,10 @@ var runImportedSheetsCommand = async (action, importedSheetId, ctx) => {
|
|
|
1978
2057
|
};
|
|
1979
2058
|
if (hasFlag(ctx, "dry-run"))
|
|
1980
2059
|
return { operation: "imported-sheets.replace-grid", importedSheetId, ...payload };
|
|
1981
|
-
return requestApi(`/api/cli/imported-sheets/${importedSheetId}/replace-grid`, {
|
|
2060
|
+
return requestImportedSheetApi(ctx, instanceId, "replace-grid", () => requestApi(`/api/cli/imported-sheets/${importedSheetId}/replace-grid`, {
|
|
1982
2061
|
method: "POST",
|
|
1983
2062
|
body: JSON.stringify(payload)
|
|
1984
|
-
});
|
|
2063
|
+
}));
|
|
1985
2064
|
}
|
|
1986
2065
|
if (action === "patch-cells") {
|
|
1987
2066
|
const data = await parseJsonObjectFlag(ctx, "data", "data-file");
|
|
@@ -1996,10 +2075,10 @@ var runImportedSheetsCommand = async (action, importedSheetId, ctx) => {
|
|
|
1996
2075
|
cacheScope: getStringFlag(ctx, "cache-scope") ?? data.cacheScope,
|
|
1997
2076
|
dryRun: hasFlag(ctx, "dry-run")
|
|
1998
2077
|
};
|
|
1999
|
-
return requestApi(`/api/cli/imported-sheets/${importedSheetId}/patch-cells`, {
|
|
2078
|
+
return requestImportedSheetApi(ctx, instanceId, "patch-cells", () => requestApi(`/api/cli/imported-sheets/${importedSheetId}/patch-cells`, {
|
|
2000
2079
|
method: "POST",
|
|
2001
2080
|
body: JSON.stringify(payload)
|
|
2002
|
-
});
|
|
2081
|
+
}));
|
|
2003
2082
|
}
|
|
2004
2083
|
if (action === "vectorize") {
|
|
2005
2084
|
const payload = {
|
|
@@ -2009,10 +2088,10 @@ var runImportedSheetsCommand = async (action, importedSheetId, ctx) => {
|
|
|
2009
2088
|
};
|
|
2010
2089
|
if (hasFlag(ctx, "dry-run"))
|
|
2011
2090
|
return { operation: "imported-sheets.vectorize", importedSheetId, ...payload };
|
|
2012
|
-
return requestApi(`/api/cli/imported-sheets/${importedSheetId}/vectorize`, {
|
|
2091
|
+
return requestImportedSheetApi(ctx, instanceId, "vectorize", () => requestApi(`/api/cli/imported-sheets/${importedSheetId}/vectorize`, {
|
|
2013
2092
|
method: "POST",
|
|
2014
2093
|
body: JSON.stringify(payload)
|
|
2015
|
-
});
|
|
2094
|
+
}));
|
|
2016
2095
|
}
|
|
2017
2096
|
if (action === "repair-french") {
|
|
2018
2097
|
const payload = {
|
|
@@ -2023,10 +2102,10 @@ var runImportedSheetsCommand = async (action, importedSheetId, ctx) => {
|
|
|
2023
2102
|
};
|
|
2024
2103
|
if (hasFlag(ctx, "dry-run"))
|
|
2025
2104
|
return { operation: "imported-sheets.repair-french", importedSheetId, ...payload };
|
|
2026
|
-
return requestApi(`/api/cli/imported-sheets/${importedSheetId}/repair-french`, {
|
|
2105
|
+
return requestImportedSheetApi(ctx, instanceId, "repair-french", () => requestApi(`/api/cli/imported-sheets/${importedSheetId}/repair-french`, {
|
|
2027
2106
|
method: "POST",
|
|
2028
2107
|
body: JSON.stringify(payload)
|
|
2029
|
-
});
|
|
2108
|
+
}));
|
|
2030
2109
|
}
|
|
2031
2110
|
if (action === "delete") {
|
|
2032
2111
|
const expectedConfirmation = `imported-sheets:${importedSheetId}`;
|
|
@@ -2247,9 +2326,82 @@ var importedSheetSearchParams = (ctx) => {
|
|
|
2247
2326
|
searchParams.set("pageSize", pageSize);
|
|
2248
2327
|
return searchParams;
|
|
2249
2328
|
};
|
|
2329
|
+
var requestImportedSheetApi = async (ctx, instanceId, operation, request, ownerEmail) => {
|
|
2330
|
+
try {
|
|
2331
|
+
return await request();
|
|
2332
|
+
} catch (error) {
|
|
2333
|
+
if (!isCliError(error) || !isGoogleSheetsPermissionError(error.message))
|
|
2334
|
+
throw error;
|
|
2335
|
+
const handoff = await runImportedSheetGoogleOAuth(ctx, instanceId, ownerEmail);
|
|
2336
|
+
if (handoff.waited) {
|
|
2337
|
+
return request();
|
|
2338
|
+
}
|
|
2339
|
+
throw new CliError(error.message, error.exitCode, {
|
|
2340
|
+
...error.details ?? {},
|
|
2341
|
+
googleOAuth: {
|
|
2342
|
+
...handoff,
|
|
2343
|
+
operation,
|
|
2344
|
+
retry: "Complete the browser Google flow, then run the same CLI command again."
|
|
2345
|
+
}
|
|
2346
|
+
});
|
|
2347
|
+
}
|
|
2348
|
+
};
|
|
2349
|
+
var runImportedSheetGoogleOAuth = async (ctx, instanceId, ownerEmail) => {
|
|
2350
|
+
if (hasFlag(ctx, "dry-run") || hasFlag(ctx, "no-open") || hasFlag(ctx, "no-oauth-wait")) {
|
|
2351
|
+
return openImportedSheetGoogleOAuthHandoff(ctx, instanceId, ownerEmail);
|
|
2352
|
+
}
|
|
2353
|
+
const session = await getApiSession();
|
|
2354
|
+
const timeoutMs = getNumberFlag(ctx, "oauth-timeout-ms") ?? 5 * 60 * 1000;
|
|
2355
|
+
const result = await waitForGoogleSheetsOAuth({
|
|
2356
|
+
baseUrl: session.baseUrl,
|
|
2357
|
+
instanceId,
|
|
2358
|
+
ownerEmail,
|
|
2359
|
+
lang: getStringFlag(ctx, "lang") ?? getStringFlag(ctx, "language") ?? "fr",
|
|
2360
|
+
timeoutMs
|
|
2361
|
+
});
|
|
2362
|
+
return {
|
|
2363
|
+
operation: "imported-sheets.connect-google",
|
|
2364
|
+
instanceId,
|
|
2365
|
+
opened: true,
|
|
2366
|
+
waited: true,
|
|
2367
|
+
connected: result.connected,
|
|
2368
|
+
userEmail: result.userEmail,
|
|
2369
|
+
note: "Google Sheets access was granted in the browser.",
|
|
2370
|
+
retry: "OAuth completed in the browser. Retrying the CLI operation now."
|
|
2371
|
+
};
|
|
2372
|
+
};
|
|
2373
|
+
var openImportedSheetGoogleOAuthHandoff = async (ctx, instanceId, ownerEmail) => {
|
|
2374
|
+
const url = await buildImportedSheetGoogleOAuthUrl(ctx, instanceId, ownerEmail);
|
|
2375
|
+
const opened = hasFlag(ctx, "dry-run") || hasFlag(ctx, "no-open") ? false : await openUrl(url);
|
|
2376
|
+
return {
|
|
2377
|
+
operation: "imported-sheets.connect-google",
|
|
2378
|
+
instanceId,
|
|
2379
|
+
url,
|
|
2380
|
+
opened,
|
|
2381
|
+
waited: false,
|
|
2382
|
+
note: "This opens the GSkills browser flow that asks Google for Sheets access. The browser user must be the owner account you pass to imported-sheets create/update."
|
|
2383
|
+
};
|
|
2384
|
+
};
|
|
2385
|
+
var buildImportedSheetGoogleOAuthUrl = async (ctx, instanceId, ownerEmail) => {
|
|
2386
|
+
const baseUrl = getStringFlag(ctx, "base-url") ?? process.env.GSKILLS_CLI_BASE_URL ?? (hasFlag(ctx, "dry-run") ? "https://g-skills.fr" : (await getApiSession()).baseUrl);
|
|
2387
|
+
const lang = getStringFlag(ctx, "lang") ?? getStringFlag(ctx, "language") ?? "fr";
|
|
2388
|
+
const reconnectUrl = new URL(`/${lang}/super-admin/${instanceId}/imported-sheets`, baseUrl);
|
|
2389
|
+
reconnectUrl.searchParams.set("googleSheetsOAuth", "1");
|
|
2390
|
+
if (ownerEmail)
|
|
2391
|
+
reconnectUrl.searchParams.set("ownerEmail", ownerEmail);
|
|
2392
|
+
return reconnectUrl.toString();
|
|
2393
|
+
};
|
|
2394
|
+
var importedSheetOwnerEmailFromPayload = (payload) => getObjectString(payload, "ownerEmail") ?? getObjectString(payload, "accountEmail") ?? getObjectString(payload, "googleAccountEmail");
|
|
2395
|
+
var isGoogleSheetsPermissionError = (message) => {
|
|
2396
|
+
const normalized = message.toLowerCase();
|
|
2397
|
+
return normalized.includes("google sheets permission is missing") || normalized.includes("google account not connected") || normalized.includes("grant sheets access");
|
|
2398
|
+
};
|
|
2250
2399
|
var importedSheetCreatePayload = async (ctx) => {
|
|
2251
2400
|
const data = await parseJsonObjectFlag(ctx, "data", "data-file");
|
|
2252
2401
|
if (Object.keys(data).length > 0) {
|
|
2402
|
+
if (!hasImportedSheetOwnerInput(data)) {
|
|
2403
|
+
throw new CliError("Imported sheet creation needs a Google owner account. Pass ownerEmail/ownerUserId in --data or use --owner-email / --owner-user.", 2);
|
|
2404
|
+
}
|
|
2253
2405
|
return {
|
|
2254
2406
|
...data,
|
|
2255
2407
|
dryRun: hasFlag(ctx, "dry-run")
|
|
@@ -2264,6 +2416,11 @@ var importedSheetCreatePayload = async (ctx) => {
|
|
|
2264
2416
|
throw new CliError("Missing --source", 2);
|
|
2265
2417
|
if (!tabName)
|
|
2266
2418
|
throw new CliError("Missing --tab", 2);
|
|
2419
|
+
const ownerUserId = getStringFlag(ctx, "owner-user") ?? getStringFlag(ctx, "owner-user-id");
|
|
2420
|
+
const ownerEmail = getStringFlag(ctx, "owner-email") ?? getStringFlag(ctx, "account-email");
|
|
2421
|
+
if (!ownerUserId && !ownerEmail) {
|
|
2422
|
+
throw new CliError("Imported sheet creation needs a Google owner account. Pass --owner-email or --owner-user.", 2);
|
|
2423
|
+
}
|
|
2267
2424
|
return {
|
|
2268
2425
|
instanceId,
|
|
2269
2426
|
displayName: getStringFlag(ctx, "display-name"),
|
|
@@ -2274,11 +2431,18 @@ var importedSheetCreatePayload = async (ctx) => {
|
|
|
2274
2431
|
sourceInput,
|
|
2275
2432
|
tabName
|
|
2276
2433
|
},
|
|
2434
|
+
ownerUserId,
|
|
2435
|
+
ownerEmail,
|
|
2277
2436
|
enableVectorization: hasFlag(ctx, "enable-vectorization"),
|
|
2278
2437
|
vectorHeaders: splitCsv(getStringFlag(ctx, "vector-headers") ?? getStringFlag(ctx, "vector-columns")),
|
|
2279
2438
|
dryRun: hasFlag(ctx, "dry-run")
|
|
2280
2439
|
};
|
|
2281
2440
|
};
|
|
2441
|
+
var hasImportedSheetOwnerInput = (data) => Boolean(getObjectString(data, "ownerUserId") || getObjectString(data, "ownerUser") || getObjectString(data, "accountUserId") || getObjectString(data, "ownerEmail") || getObjectString(data, "accountEmail") || getObjectString(data, "googleAccountEmail"));
|
|
2442
|
+
var getObjectString = (data, key) => {
|
|
2443
|
+
const value = data[key];
|
|
2444
|
+
return typeof value === "string" && value.trim() ? value.trim() : undefined;
|
|
2445
|
+
};
|
|
2282
2446
|
var splitCsv = (value) => value ? value.split(",").map((item) => item.trim()).filter(Boolean) : [];
|
|
2283
2447
|
var setWhereValue = (where, fieldPath, value) => {
|
|
2284
2448
|
const parts = fieldPath.split(".").map((part) => part.trim()).filter(Boolean);
|
|
@@ -2384,7 +2548,7 @@ var rootHelp = () => ({
|
|
|
2384
2548
|
"gskills-admin sync run --target <instanceId> --only pages,quizzes --yes",
|
|
2385
2549
|
"gskills-admin sync repair-source-links --target <instanceId> --dry-run",
|
|
2386
2550
|
"gskills-admin translate pages <id> --to en,es --dry-run",
|
|
2387
|
-
"gskills-admin imported-sheets create --instance <id> --source <url> --tab <name> --locales fr,en --enable-vectorization --dry-run",
|
|
2551
|
+
"gskills-admin imported-sheets create --instance <id> --source <url> --tab <name> --default-locale en --locales fr,en --owner-email admin@example.com --enable-vectorization --dry-run",
|
|
2388
2552
|
`gskills-admin internal-knowledge create --instance <instanceId> --upload-file ./video.mp4 --data '{"title":"...","language":"fr"}' --yes`,
|
|
2389
2553
|
`gskills-admin resources create --instance <instanceId> --upload-file ./webinar.mp4 --data '{"title":"...","type":"WEBINAR","language":"fr"}' --yes`,
|
|
2390
2554
|
"gskills-admin internal-knowledge sync-media --since today --languages fr --all-targets --dry-run",
|
|
@@ -2429,9 +2593,10 @@ var schemaHelp = () => ({
|
|
|
2429
2593
|
{ name: "imported-sheets locales", args: ["id"], required: ["--instance"], writes: false },
|
|
2430
2594
|
{ name: "imported-sheets runs", args: ["id?"], required: ["--instance"], flags: ["--take"], writes: false },
|
|
2431
2595
|
{ name: "imported-sheets resolve", required: ["--instance", "--source"], writes: false },
|
|
2432
|
-
{ name: "imported-sheets
|
|
2433
|
-
{ name: "imported-sheets
|
|
2434
|
-
{ name: "imported-sheets
|
|
2596
|
+
{ name: "imported-sheets connect-google", required: ["--instance"], flags: ["--base-url", "--lang", "--owner-email", "--no-open", "--dry-run"], writes: false },
|
|
2597
|
+
{ name: "imported-sheets create", required: ["--instance", "--source", "--tab", "--owner-email or --owner-user"], flags: ["--display-name", "--locales", "--mode", "--default-locale", "--owner-email", "--owner-user", "--enable-vectorization", "--vector-headers", "--data", "--data-file", "--oauth-timeout-ms", "--no-oauth-wait", "--yes", "--dry-run"], writes: true },
|
|
2598
|
+
{ name: "imported-sheets update", args: ["id"], required: ["--instance", "--data or --data-file or --owner-email"], flags: ["--owner-email", "--owner-user", "--oauth-timeout-ms", "--no-oauth-wait", "--yes", "--dry-run"], writes: true },
|
|
2599
|
+
{ name: "imported-sheets sync", args: ["id"], required: ["--instance"], flags: ["--locales", "--oauth-timeout-ms", "--no-oauth-wait", "--yes", "--dry-run"], writes: true },
|
|
2435
2600
|
{ name: "imported-sheets enable-locales", args: ["id"], required: ["--instance", "--locales"], flags: ["--yes", "--dry-run"], writes: true },
|
|
2436
2601
|
{ name: "imported-sheets translate", args: ["id"], required: ["--instance", "--to"], flags: ["--yes", "--dry-run"], writes: true },
|
|
2437
2602
|
{ name: "imported-sheets retranslate", args: ["id"], required: ["--instance", "--to"], flags: ["--from", "--revectorize", "--yes", "--dry-run"], writes: true },
|
|
@@ -2574,8 +2739,10 @@ var importedSheetsHelp = () => ({
|
|
|
2574
2739
|
usage: [
|
|
2575
2740
|
"gskills-admin imported-sheets list --instance <instanceId>",
|
|
2576
2741
|
"gskills-admin imported-sheets get <sheetId> --instance <instanceId> --locale en --page-size 100",
|
|
2742
|
+
"gskills-admin imported-sheets connect-google --instance <instanceId> --base-url https://g-skills.fr",
|
|
2577
2743
|
"gskills-admin imported-sheets resolve --instance <instanceId> --source <sheet-url>",
|
|
2578
|
-
"gskills-admin imported-sheets create --instance <instanceId> --source <sheet-url> --tab
|
|
2744
|
+
"gskills-admin imported-sheets create --instance <instanceId> --source <sheet-url> --tab EN --default-locale en --display-name 'Use cases' --locales fr,en --owner-email admin@example.com --enable-vectorization --vector-headers 'Use case,Description,Full prompt' --dry-run",
|
|
2745
|
+
"gskills-admin imported-sheets update <sheetId> --instance <instanceId> --owner-email admin@example.com --dry-run",
|
|
2579
2746
|
"gskills-admin imported-sheets update <sheetId> --instance <instanceId> --data-file ./settings.json --dry-run",
|
|
2580
2747
|
"gskills-admin imported-sheets sync <sheetId> --instance <instanceId> --dry-run",
|
|
2581
2748
|
"gskills-admin imported-sheets translate <sheetId> --instance <instanceId> --to en,es --dry-run",
|
|
@@ -2590,6 +2757,7 @@ var importedSheetsHelp = () => ({
|
|
|
2590
2757
|
"gskills-admin imported-sheets delete <sheetId> --instance <instanceId> --force --confirm-delete imported-sheets:<sheetId> --dry-run"
|
|
2591
2758
|
],
|
|
2592
2759
|
writes: "create, update, sync, translate, retranslate, replace-grid, patch-cells, vectorize, repair-french, copy-to, attach-page, set-source and delete require --yes or --dry-run.",
|
|
2760
|
+
oauth: "When Google Sheets access is missing, create/update/sync open the browser OAuth flow, wait for completion, then retry automatically. Use --no-oauth-wait to only print/open the reconnect URL.",
|
|
2593
2761
|
patchCellsDataShape: {
|
|
2594
2762
|
patches: [
|
|
2595
2763
|
{
|
|
@@ -2612,12 +2780,14 @@ var importedSheetsHelp = () => ({
|
|
|
2612
2780
|
enabledLocales: ["fr", "en", "es"],
|
|
2613
2781
|
multilangMode: "AI_TRANSLATION",
|
|
2614
2782
|
defaultLocaleSource: { locale: "fr", sourceInput: "https://docs.google.com/spreadsheets/d/...", tabName: "FR" },
|
|
2615
|
-
localeSources: [{ locale: "
|
|
2783
|
+
localeSources: [{ locale: "fr", sourceInput: "https://docs.google.com/spreadsheets/d/...", tabName: "FR" }],
|
|
2784
|
+
ownerEmail: "admin@example.com",
|
|
2616
2785
|
enableVectorization: true,
|
|
2617
2786
|
vectorHeaders: ["Titre", "Description", "Prompt"]
|
|
2618
2787
|
},
|
|
2619
2788
|
updateDataShape: {
|
|
2620
2789
|
displayName: "Cas d'usage Gemini",
|
|
2790
|
+
ownerEmail: "admin@example.com",
|
|
2621
2791
|
viewMode: "LINE",
|
|
2622
2792
|
enableVectorization: true,
|
|
2623
2793
|
columns: [{ id: "column_id", isVisible: true, includeInVectorization: true, displayType: "TITLE", showLabel: false, displayOrder: 0 }],
|
package/package.json
CHANGED
|
@@ -13,6 +13,7 @@ Also install and use the companion skills:
|
|
|
13
13
|
|
|
14
14
|
- `gskills-vocabulary` when explaining work to admins or writing user-facing summaries.
|
|
15
15
|
- `gskills-customer-playbooks` when the task names a recurring GSkills customer.
|
|
16
|
+
- `gskills-admin-cli-publishing` when publishing the npm package or sharing the publish recipe with another teammate.
|
|
16
17
|
|
|
17
18
|
## Install
|
|
18
19
|
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: gskills-admin-cli-publishing
|
|
3
|
+
description: Use when publishing the @numericoach/gskills-admin-cli npm package or refreshing the team publish recipe.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# GSkills Admin CLI Publishing
|
|
7
|
+
|
|
8
|
+
Use this skill when publishing `@numericoach/gskills-admin-cli`.
|
|
9
|
+
|
|
10
|
+
The package lives in `packages/gskills-admin-cli`. It is public, but publishing still needs a Numericoach npm token with publish rights.
|
|
11
|
+
|
|
12
|
+
## Token Storage
|
|
13
|
+
|
|
14
|
+
Never commit an npm token and never write it into a repo `.npmrc`.
|
|
15
|
+
|
|
16
|
+
On macOS, store each teammate's own token in Keychain:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
read -rsp "npm token: " NPM_TOKEN
|
|
20
|
+
printf "\n"
|
|
21
|
+
security add-generic-password \
|
|
22
|
+
-s numericoach-npm-publish-token \
|
|
23
|
+
-a registry.npmjs.org \
|
|
24
|
+
-w "$NPM_TOKEN" \
|
|
25
|
+
-U
|
|
26
|
+
unset NPM_TOKEN
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Check that the Keychain item exists without printing the token:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
security find-generic-password \
|
|
33
|
+
-s numericoach-npm-publish-token \
|
|
34
|
+
-a registry.npmjs.org >/dev/null
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Publish Flow
|
|
38
|
+
|
|
39
|
+
From the repo root:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
npm view @numericoach/gskills-admin-cli version --registry=https://registry.npmjs.org/
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Bump `packages/gskills-admin-cli/package.json` to the next patch version.
|
|
46
|
+
|
|
47
|
+
Build and inspect the package:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
cd packages/gskills-admin-cli
|
|
51
|
+
bun run build
|
|
52
|
+
node dist/gskills-admin.js schema --output json >/tmp/gskills-admin-schema.json
|
|
53
|
+
bun pm pack --dry-run
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Publish with a temporary npm config generated from Keychain:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
cd packages/gskills-admin-cli
|
|
60
|
+
NPM_TOKEN="$(security find-generic-password -s numericoach-npm-publish-token -a registry.npmjs.org -w)"
|
|
61
|
+
NPM_CONFIG_FILE="$(mktemp)"
|
|
62
|
+
trap 'rm -f "$NPM_CONFIG_FILE"' EXIT
|
|
63
|
+
{
|
|
64
|
+
printf 'registry=https://registry.npmjs.org/\n'
|
|
65
|
+
printf '//registry.npmjs.org/:_authToken=%s\n' "$NPM_TOKEN"
|
|
66
|
+
} > "$NPM_CONFIG_FILE"
|
|
67
|
+
unset NPM_TOKEN
|
|
68
|
+
NPM_CONFIG_USERCONFIG="$NPM_CONFIG_FILE" npm whoami
|
|
69
|
+
NPM_CONFIG_USERCONFIG="$NPM_CONFIG_FILE" npm publish --access public
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Verify the exact version after publish:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
npm view @numericoach/gskills-admin-cli@<version> version --registry=https://registry.npmjs.org/
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Rules
|
|
79
|
+
|
|
80
|
+
- Publish from `packages/gskills-admin-cli`, not the app root.
|
|
81
|
+
- Use `NPM_CONFIG_USERCONFIG` with a temp file for publish. Plain `NPM_TOKEN` can be ignored by npm in this setup.
|
|
82
|
+
- Keep the token in the OS credential store, not in shell rc files, repo files, command logs, or documentation.
|
|
83
|
+
- Commit the version bump, bundled skills, README updates, and rebuilt `dist/gskills-admin.js` after validation.
|
|
84
|
+
- Do not call the package published until `npm view @numericoach/gskills-admin-cli@<version> version` returns the new version.
|