@temps-sdk/cli 0.1.17 → 0.1.18
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/dist/index.js +155 -12
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -96808,26 +96808,24 @@ init_sdk_gen();
|
|
|
96808
96808
|
init_output();
|
|
96809
96809
|
function parsePeriod(period) {
|
|
96810
96810
|
const now2 = new Date;
|
|
96811
|
-
const
|
|
96812
|
-
const endDate = fmt(now2);
|
|
96811
|
+
const endDate = now2.toISOString();
|
|
96813
96812
|
let start;
|
|
96814
96813
|
switch (period) {
|
|
96815
|
-
case "today":
|
|
96814
|
+
case "today":
|
|
96816
96815
|
start = new Date(now2.getFullYear(), now2.getMonth(), now2.getDate());
|
|
96817
|
-
return { startDate:
|
|
96818
|
-
}
|
|
96816
|
+
return { startDate: start.toISOString(), endDate, label: "today" };
|
|
96819
96817
|
case "24h":
|
|
96820
96818
|
start = new Date(now2.getTime() - 24 * 60 * 60 * 1000);
|
|
96821
|
-
return { startDate:
|
|
96819
|
+
return { startDate: start.toISOString(), endDate, label: "last 24 hours" };
|
|
96822
96820
|
case "7d":
|
|
96823
96821
|
start = new Date(now2.getTime() - 7 * 24 * 60 * 60 * 1000);
|
|
96824
|
-
return { startDate:
|
|
96822
|
+
return { startDate: start.toISOString(), endDate, label: "last 7 days" };
|
|
96825
96823
|
case "30d":
|
|
96826
96824
|
start = new Date(now2.getTime() - 30 * 24 * 60 * 60 * 1000);
|
|
96827
|
-
return { startDate:
|
|
96825
|
+
return { startDate: start.toISOString(), endDate, label: "last 30 days" };
|
|
96828
96826
|
case "90d":
|
|
96829
96827
|
start = new Date(now2.getTime() - 90 * 24 * 60 * 60 * 1000);
|
|
96830
|
-
return { startDate:
|
|
96828
|
+
return { startDate: start.toISOString(), endDate, label: "last 90 days" };
|
|
96831
96829
|
default:
|
|
96832
96830
|
throw new Error(`Invalid period "${period}". Use: today, 24h, 7d, 30d, 90d`);
|
|
96833
96831
|
}
|
|
@@ -97000,13 +96998,158 @@ async function overview(options) {
|
|
|
97000
96998
|
newline();
|
|
97001
96999
|
}
|
|
97002
97000
|
|
|
97001
|
+
// src/commands/analytics/breakdown.ts
|
|
97002
|
+
init_source();
|
|
97003
|
+
init_sdk_gen();
|
|
97004
|
+
init_output();
|
|
97005
|
+
var VALID_DIMENSIONS = [
|
|
97006
|
+
"pages",
|
|
97007
|
+
"referrers",
|
|
97008
|
+
"browsers",
|
|
97009
|
+
"os",
|
|
97010
|
+
"devices",
|
|
97011
|
+
"countries",
|
|
97012
|
+
"channels",
|
|
97013
|
+
"events",
|
|
97014
|
+
"languages",
|
|
97015
|
+
"utm_source",
|
|
97016
|
+
"utm_medium",
|
|
97017
|
+
"utm_campaign"
|
|
97018
|
+
];
|
|
97019
|
+
var DIMENSION_MAP = {
|
|
97020
|
+
pages: { groupBy: "page_path", label: "Top Pages" },
|
|
97021
|
+
referrers: { groupBy: "referrer_hostname", label: "Top Referrers" },
|
|
97022
|
+
browsers: { groupBy: "browser", label: "Browsers" },
|
|
97023
|
+
os: { groupBy: "operating_system", label: "Operating Systems" },
|
|
97024
|
+
devices: { groupBy: "device_type", label: "Devices" },
|
|
97025
|
+
countries: { groupBy: "country", label: "Countries" },
|
|
97026
|
+
channels: { groupBy: "channel", label: "Channels" },
|
|
97027
|
+
events: { groupBy: "event_name", label: "Events" },
|
|
97028
|
+
languages: { groupBy: "language", label: "Languages" },
|
|
97029
|
+
utm_source: { groupBy: "utm_source", label: "UTM Sources" },
|
|
97030
|
+
utm_medium: { groupBy: "utm_medium", label: "UTM Mediums" },
|
|
97031
|
+
utm_campaign: { groupBy: "utm_campaign", label: "UTM Campaigns" }
|
|
97032
|
+
};
|
|
97033
|
+
function parsePeriod2(period) {
|
|
97034
|
+
const now2 = new Date;
|
|
97035
|
+
const endDate = now2.toISOString();
|
|
97036
|
+
let start;
|
|
97037
|
+
switch (period) {
|
|
97038
|
+
case "today":
|
|
97039
|
+
start = new Date(now2.getFullYear(), now2.getMonth(), now2.getDate());
|
|
97040
|
+
return { startDate: start.toISOString(), endDate, label: "today" };
|
|
97041
|
+
case "24h":
|
|
97042
|
+
start = new Date(now2.getTime() - 24 * 60 * 60 * 1000);
|
|
97043
|
+
return { startDate: start.toISOString(), endDate, label: "last 24 hours" };
|
|
97044
|
+
case "7d":
|
|
97045
|
+
start = new Date(now2.getTime() - 7 * 24 * 60 * 60 * 1000);
|
|
97046
|
+
return { startDate: start.toISOString(), endDate, label: "last 7 days" };
|
|
97047
|
+
case "30d":
|
|
97048
|
+
start = new Date(now2.getTime() - 30 * 24 * 60 * 60 * 1000);
|
|
97049
|
+
return { startDate: start.toISOString(), endDate, label: "last 30 days" };
|
|
97050
|
+
case "90d":
|
|
97051
|
+
start = new Date(now2.getTime() - 90 * 24 * 60 * 60 * 1000);
|
|
97052
|
+
return { startDate: start.toISOString(), endDate, label: "last 90 days" };
|
|
97053
|
+
default:
|
|
97054
|
+
throw new Error(`Invalid period "${period}". Use: today, 24h, 7d, 30d, 90d`);
|
|
97055
|
+
}
|
|
97056
|
+
}
|
|
97057
|
+
function formatNumber2(n) {
|
|
97058
|
+
return n.toLocaleString("en-US");
|
|
97059
|
+
}
|
|
97060
|
+
async function breakdown(dimension, options) {
|
|
97061
|
+
const dim2 = DIMENSION_MAP[dimension];
|
|
97062
|
+
if (!dim2) {
|
|
97063
|
+
const valid = VALID_DIMENSIONS.join(", ");
|
|
97064
|
+
throw new Error(`Unknown dimension "${dimension}". Available: ${valid}`);
|
|
97065
|
+
}
|
|
97066
|
+
await requireAuth();
|
|
97067
|
+
await setupClient();
|
|
97068
|
+
const period = options.period ?? "24h";
|
|
97069
|
+
const limit = options.limit ? parseInt(options.limit, 10) : 20;
|
|
97070
|
+
const { startDate, endDate, label } = parsePeriod2(period);
|
|
97071
|
+
const resolved = await requireProjectSlug(options.project);
|
|
97072
|
+
if (resolved.source !== "flag") {
|
|
97073
|
+
info(`Using project ${colors.bold(resolved.slug)} (from ${resolved.source})`);
|
|
97074
|
+
}
|
|
97075
|
+
const { data: projectData, error: projectError } = await getProjectBySlug({
|
|
97076
|
+
client,
|
|
97077
|
+
path: { slug: resolved.slug }
|
|
97078
|
+
});
|
|
97079
|
+
if (projectError || !projectData) {
|
|
97080
|
+
throw new Error(`Project "${resolved.slug}" not found`);
|
|
97081
|
+
}
|
|
97082
|
+
const projectId = projectData.id;
|
|
97083
|
+
const data = await withSpinner(`Fetching ${dim2.label.toLowerCase()}...`, async () => {
|
|
97084
|
+
const { data: data2, error: error3 } = await getPropertyBreakdown({
|
|
97085
|
+
client,
|
|
97086
|
+
path: { project_id: projectId },
|
|
97087
|
+
query: {
|
|
97088
|
+
start_date: startDate,
|
|
97089
|
+
end_date: endDate,
|
|
97090
|
+
group_by: dim2.groupBy,
|
|
97091
|
+
limit
|
|
97092
|
+
}
|
|
97093
|
+
});
|
|
97094
|
+
if (error3)
|
|
97095
|
+
throw new Error(getErrorMessage(error3));
|
|
97096
|
+
return data2;
|
|
97097
|
+
});
|
|
97098
|
+
if (options.json) {
|
|
97099
|
+
json({
|
|
97100
|
+
project: resolved.slug,
|
|
97101
|
+
period,
|
|
97102
|
+
dimension,
|
|
97103
|
+
...data
|
|
97104
|
+
});
|
|
97105
|
+
return;
|
|
97106
|
+
}
|
|
97107
|
+
const items = data?.items ?? [];
|
|
97108
|
+
const total = data?.total ?? 0;
|
|
97109
|
+
const line = source_default.cyan("━".repeat(64));
|
|
97110
|
+
newline();
|
|
97111
|
+
console.log(line);
|
|
97112
|
+
console.log(` ${source_default.bold.white(dim2.label)} ${source_default.gray(`— ${resolved.slug} (${label})`)}`);
|
|
97113
|
+
console.log(line);
|
|
97114
|
+
newline();
|
|
97115
|
+
if (items.length === 0) {
|
|
97116
|
+
console.log(` ${source_default.gray("No data for this period.")}`);
|
|
97117
|
+
newline();
|
|
97118
|
+
console.log(line);
|
|
97119
|
+
newline();
|
|
97120
|
+
return;
|
|
97121
|
+
}
|
|
97122
|
+
const maxCount = Math.max(...items.map((i) => i.count), 1);
|
|
97123
|
+
const maxBarWidth = 30;
|
|
97124
|
+
console.log(` ${source_default.gray("#".padEnd(4))}${source_default.gray("Value".padEnd(32))}${source_default.gray("Count".padStart(10))}${source_default.gray("%".padStart(8))} ${source_default.gray("Distribution")}`);
|
|
97125
|
+
console.log(` ${source_default.gray("─".repeat(60))}`);
|
|
97126
|
+
items.forEach((item, i) => {
|
|
97127
|
+
const value = item.value || "(unknown)";
|
|
97128
|
+
const display = value.length > 30 ? value.slice(0, 27) + "..." : value;
|
|
97129
|
+
const barWidth = Math.max(1, Math.round(item.count / maxCount * maxBarWidth));
|
|
97130
|
+
const bar = source_default.cyan("█".repeat(barWidth));
|
|
97131
|
+
console.log(` ${source_default.gray(String(i + 1).padEnd(4))}${source_default.white(display.padEnd(32))}${formatNumber2(item.count).padStart(10)}${(item.percentage.toFixed(1) + "%").padStart(8)} ${bar}`);
|
|
97132
|
+
});
|
|
97133
|
+
newline();
|
|
97134
|
+
console.log(` ${source_default.gray("Total:")} ${formatNumber2(total)}`);
|
|
97135
|
+
newline();
|
|
97136
|
+
console.log(line);
|
|
97137
|
+
newline();
|
|
97138
|
+
}
|
|
97139
|
+
|
|
97003
97140
|
// src/commands/analytics/index.ts
|
|
97004
97141
|
function registerAnalyticsCommands(program2) {
|
|
97005
97142
|
const analytics = program2.command("analytics").alias("stats").description("View project analytics");
|
|
97006
97143
|
analytics.command("overview").alias("o").description("Show analytics dashboard overview").option("-p, --project <project>", "Project slug or ID").option("--period <period>", "Time period: today, 24h, 7d, 30d, 90d", "24h").option("--json", "Output in JSON format").action(overview);
|
|
97007
|
-
analytics.
|
|
97008
|
-
|
|
97009
|
-
|
|
97144
|
+
analytics.command("top <dimension>").description("Show breakdown by dimension: pages, referrers, browsers, os, devices, countries, channels, events, languages, utm_source, utm_medium, utm_campaign").option("-p, --project <project>", "Project slug or ID").option("--period <period>", "Time period: today, 24h, 7d, 30d, 90d", "24h").option("--limit <n>", "Number of results (default: 20, max: 100)").option("--json", "Output in JSON format").action(breakdown);
|
|
97145
|
+
analytics.addHelpText("after", `
|
|
97146
|
+
Examples:
|
|
97147
|
+
$ temps analytics Show overview (last 24h)
|
|
97148
|
+
$ temps analytics overview -p my-app --period 7d
|
|
97149
|
+
$ temps analytics top pages -p my-app --period 30d
|
|
97150
|
+
$ temps analytics top referrers --period 7d
|
|
97151
|
+
$ temps analytics top browsers --json
|
|
97152
|
+
$ temps analytics top countries --period 30d --limit 50`);
|
|
97010
97153
|
}
|
|
97011
97154
|
|
|
97012
97155
|
// src/commands/notification-preferences/index.ts
|