@mgamadeus/ddd-site-insights 0.0.0-stage → 0.1.0-rc.2
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/LICENSE +21 -0
- package/README.md +37 -2
- package/dist/index.d.ts +180 -0
- package/dist/index.js +69 -0
- package/dist/index.js.map +1 -0
- package/package.json +64 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ddd-framework
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,38 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @mgamadeus/ddd-site-insights
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Frontend of the site insights module for backends built with [mgamadeus/ddd](https://github.com/ddd-framework/ddd)
|
|
4
|
+
(Composer package [`mgamadeus/ddd-site-insights`](https://github.com/ddd-framework/ddd-site-insights), same version).
|
|
5
|
+
|
|
6
|
+
Entry `.` holds the TypeScript types generated from the module's API and pure window logic. It loads no React and no
|
|
7
|
+
stylesheet and can run on a server. The API factory and the screens follow in later versions.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @mgamadeus/ddd-site-insights
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
ESM only. Peer dependencies: `@mgamadeus/ddd-web` `>=0.13.0 <1`, `@reduxjs/toolkit` `^2.6.0`, `react` `^19.0.0`,
|
|
16
|
+
`react-redux` `^9.0.0`.
|
|
17
|
+
|
|
18
|
+
## Window logic
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { buildWindowLabel, computePresetWindow, windowPresets } from '@mgamadeus/ddd-site-insights';
|
|
22
|
+
|
|
23
|
+
const window = computePresetWindow('28d', '2026-11-13', '2025-07-19');
|
|
24
|
+
// { from: '2026-10-17', to: '2026-11-13', days: 28, preset: '28d', windowClamped: false }
|
|
25
|
+
buildWindowLabel(window); // 'Last 28 days · 2026-10-17 – 2026-11-13'
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Days are `YYYY-MM-DD` in the provider's day zone; the arithmetic matches the backend's.
|
|
29
|
+
|
|
30
|
+
## Generated types
|
|
31
|
+
|
|
32
|
+
`src/generated/` is generated from `schema/site-insights.openapi.json`, which the PHP schema test writes. After an API
|
|
33
|
+
change: `SITE_INSIGHTS_WRITE_SCHEMA=1 vendor/bin/phpunit tests/Schema` in the repository root, then `pnpm generate`.
|
|
34
|
+
CI fails when the two drift (`check:generated`).
|
|
35
|
+
|
|
36
|
+
## License
|
|
37
|
+
|
|
38
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure window logic of the site insights screens, the same arithmetic as the PHP `SearchDays` / `SearchWindowsService`:
|
|
3
|
+
* days are `YYYY-MM-DD` strings in the provider's day zone, computed on UTC dates (no local time zone involved), both
|
|
4
|
+
* ends inclusive. Server-callable: no React, no DOM.
|
|
5
|
+
*/
|
|
6
|
+
/** A window preset of the API (`preset` query parameter). */
|
|
7
|
+
type WindowPresetKey = '7d' | '28d' | '90d' | '6m' | '12m' | '16m';
|
|
8
|
+
interface WindowPreset {
|
|
9
|
+
key: WindowPresetKey;
|
|
10
|
+
/** `days`: the last N days; `months`: the same day M months earlier plus one day */
|
|
11
|
+
unit: 'days' | 'months';
|
|
12
|
+
amount: number;
|
|
13
|
+
/** Short English label; hosts translate by `key` */
|
|
14
|
+
label: string;
|
|
15
|
+
}
|
|
16
|
+
/** The presets in the order a picker shows them. */
|
|
17
|
+
declare const windowPresets: readonly WindowPreset[];
|
|
18
|
+
/** The default preset of the API. */
|
|
19
|
+
declare const DEFAULT_WINDOW_PRESET: WindowPresetKey;
|
|
20
|
+
/** A window as the API returns it (`SearchWindow`) or as {@link computePresetWindow} builds it. */
|
|
21
|
+
interface WindowDays {
|
|
22
|
+
from: string;
|
|
23
|
+
to: string;
|
|
24
|
+
days: number;
|
|
25
|
+
preset?: string | null;
|
|
26
|
+
windowClamped?: boolean;
|
|
27
|
+
}
|
|
28
|
+
/** Whether `value` is an existing day written `YYYY-MM-DD`. */
|
|
29
|
+
declare function isValidDay(value: string): boolean;
|
|
30
|
+
/** The day `days` days after `day` (negative: before). */
|
|
31
|
+
declare function addDays(day: string, days: number): string;
|
|
32
|
+
/** The same day of the month `months` months earlier, clamped to the last day of a shorter month. */
|
|
33
|
+
declare function subtractMonthsClamped(day: string, months: number): string;
|
|
34
|
+
/** Days from `from` to `to`, both included. */
|
|
35
|
+
declare function daysInclusive(from: string, to: string): number;
|
|
36
|
+
/**
|
|
37
|
+
* The window of a preset ending on `lastDay` (the last final day, or today for fresh data), raised to `earliestDay`
|
|
38
|
+
* when given — the window the API answers for the same preset.
|
|
39
|
+
*/
|
|
40
|
+
declare function computePresetWindow(preset: WindowPresetKey, lastDay: string, earliestDay?: string): WindowDays;
|
|
41
|
+
/**
|
|
42
|
+
* A one-line label of a window, e.g. `Last 28 days · 2026-10-17 – 2026-11-13`; a clamped window says so
|
|
43
|
+
* (`… (from the earliest day kept)`), explicit days show their count.
|
|
44
|
+
*/
|
|
45
|
+
declare function buildWindowLabel(window: WindowDays): string;
|
|
46
|
+
|
|
47
|
+
type InsightsPageGroup = {
|
|
48
|
+
/** Key of the group within its site */
|
|
49
|
+
key?: string;
|
|
50
|
+
/** Label shown in the admin */
|
|
51
|
+
label?: string;
|
|
52
|
+
/** RE2 patterns on the URL path (no lookarounds, no backreferences) */
|
|
53
|
+
pathPatterns?: string[];
|
|
54
|
+
/** The fully qualified class name of the object */
|
|
55
|
+
objectType?: string | null;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
type InsightsPageGroups = {
|
|
59
|
+
elements?: InsightsPageGroup[];
|
|
60
|
+
/** The fully qualified class name of the object */
|
|
61
|
+
objectType?: string | null;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
type InsightsProviderCapabilities = {
|
|
65
|
+
/** Provider key, e.g. google-search-console */
|
|
66
|
+
provider?: string;
|
|
67
|
+
/** Dimensions rows can be grouped by */
|
|
68
|
+
dimensions?: string[];
|
|
69
|
+
/** Filter operators */
|
|
70
|
+
filterOperators?: string[];
|
|
71
|
+
/** Metrics of every row */
|
|
72
|
+
metrics?: string[];
|
|
73
|
+
/** Search types */
|
|
74
|
+
searchTypes?: string[];
|
|
75
|
+
/** Data states (final: settled days only; all: fresh days that may still change) */
|
|
76
|
+
dataStates?: string[];
|
|
77
|
+
/** Aggregations */
|
|
78
|
+
aggregations?: string[];
|
|
79
|
+
/** Time zone the provider counts its days in */
|
|
80
|
+
dayTimeZone?: string;
|
|
81
|
+
/** Months of data the provider keeps */
|
|
82
|
+
retentionMonths?: number;
|
|
83
|
+
/** Most rows one call may ask for */
|
|
84
|
+
maxRowsPerCall?: number;
|
|
85
|
+
/** Whether hourly data is available (not used in version 1) */
|
|
86
|
+
hasHourlyData?: boolean;
|
|
87
|
+
/** The fully qualified class name of the object */
|
|
88
|
+
objectType?: string | null;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
type InsightsSite = {
|
|
92
|
+
/** Key of the site (`^[a-z0-9][a-z0-9-]{0,62}$`), used in URLs and commands */
|
|
93
|
+
key?: string;
|
|
94
|
+
/** Label shown in the admin */
|
|
95
|
+
label?: string;
|
|
96
|
+
/** Provider key, e.g. google-search-console */
|
|
97
|
+
provider?: string;
|
|
98
|
+
/** Search Console property: `https://example.test/` (URL prefix) or `sc-domain:example.test` */
|
|
99
|
+
property?: string;
|
|
100
|
+
/** Name of the credentials entry that reads the property; a name, never a secret */
|
|
101
|
+
credentialsEntryName?: string;
|
|
102
|
+
/** Revision of the credentials entry (part of every cache identity) */
|
|
103
|
+
credentialsRevision?: number;
|
|
104
|
+
/** RE2 patterns of brand queries */
|
|
105
|
+
brandQueryPatterns?: string[];
|
|
106
|
+
pageGroups?: InsightsPageGroups;
|
|
107
|
+
capabilities?: InsightsProviderCapabilities;
|
|
108
|
+
/** The fully qualified class name of the object */
|
|
109
|
+
objectType?: string | null;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
type InsightsSites = {
|
|
113
|
+
elements?: InsightsSite[];
|
|
114
|
+
/** The fully qualified class name of the object */
|
|
115
|
+
objectType?: string | null;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
type SiteInsightsAccessCheck = {
|
|
119
|
+
/** Key of the site */
|
|
120
|
+
siteKey?: string;
|
|
121
|
+
/** The capability checked
|
|
122
|
+
Allowed Values:
|
|
123
|
+
- `keyReadable`
|
|
124
|
+
- `tokenObtained`
|
|
125
|
+
- `propertyListed`
|
|
126
|
+
- `permissionLevel`
|
|
127
|
+
- `searchAnalytics`
|
|
128
|
+
- `sitemaps`
|
|
129
|
+
- `urlInspection`
|
|
130
|
+
- `budgetCountersShared`
|
|
131
|
+
*/
|
|
132
|
+
capability?: "keyReadable" | "tokenObtained" | "propertyListed" | "permissionLevel" | "searchAnalytics" | "sitemaps" | "urlInspection" | "budgetCountersShared";
|
|
133
|
+
/** ok, failed, or skipped because a prerequisite failed
|
|
134
|
+
Allowed Values:
|
|
135
|
+
- `ok`
|
|
136
|
+
- `failed`
|
|
137
|
+
- `skipped`
|
|
138
|
+
*/
|
|
139
|
+
state?: "ok" | "failed" | "skipped";
|
|
140
|
+
/** A SiteInsightsErrorCause value; set when failed */
|
|
141
|
+
cause?: string | null;
|
|
142
|
+
/** What failed or what was found (e.g. the permission level), without secrets */
|
|
143
|
+
detail?: string | null;
|
|
144
|
+
/** The fully qualified class name of the object */
|
|
145
|
+
objectType?: string | null;
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
type SiteInsightsAccessChecks = {
|
|
149
|
+
elements?: SiteInsightsAccessCheck[];
|
|
150
|
+
/** The fully qualified class name of the object */
|
|
151
|
+
objectType?: string | null;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
type SiteInsightsSitesGetResponseDto = {
|
|
155
|
+
insightsSites: InsightsSites;
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
type SiteInsightsAccessChecksGetResponseDto = {
|
|
159
|
+
siteInsightsAccessChecks: SiteInsightsAccessChecks;
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
type GetAdminSiteInsightsSitesApiArg = void;
|
|
163
|
+
|
|
164
|
+
type GetAdminSiteInsightsSitesApiResponse =
|
|
165
|
+
/** status 200 */ SiteInsightsSitesGetResponseDto;
|
|
166
|
+
|
|
167
|
+
type PostAdminSiteInsightsSitesAccessChecksBySiteKeyApiArg = {
|
|
168
|
+
/** Key of the site (config SiteInsights.sites) */
|
|
169
|
+
siteKey: string;
|
|
170
|
+
/** Common request parameter — see "Shared request parameters". */
|
|
171
|
+
noCache?: boolean;
|
|
172
|
+
/** Common request parameter — see "Shared request parameters". */
|
|
173
|
+
outputFormat?: string;
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
type PostAdminSiteInsightsSitesAccessChecksBySiteKeyApiResponse =
|
|
177
|
+
/** status 200 */ SiteInsightsAccessChecksGetResponseDto;
|
|
178
|
+
|
|
179
|
+
export { DEFAULT_WINDOW_PRESET, addDays, buildWindowLabel, computePresetWindow, daysInclusive, isValidDay, subtractMonthsClamped, windowPresets };
|
|
180
|
+
export type { GetAdminSiteInsightsSitesApiArg, GetAdminSiteInsightsSitesApiResponse, InsightsPageGroup, InsightsPageGroups, InsightsProviderCapabilities, InsightsSite, InsightsSites, PostAdminSiteInsightsSitesAccessChecksBySiteKeyApiArg, PostAdminSiteInsightsSitesAccessChecksBySiteKeyApiResponse, SiteInsightsAccessCheck, SiteInsightsAccessChecks, SiteInsightsAccessChecksGetResponseDto, SiteInsightsSitesGetResponseDto, WindowDays, WindowPreset, WindowPresetKey };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// src/logic/windows.ts
|
|
2
|
+
var windowPresets = [
|
|
3
|
+
{ key: "7d", unit: "days", amount: 7, label: "Last 7 days" },
|
|
4
|
+
{ key: "28d", unit: "days", amount: 28, label: "Last 28 days" },
|
|
5
|
+
{ key: "90d", unit: "days", amount: 90, label: "Last 3 months" },
|
|
6
|
+
{ key: "6m", unit: "months", amount: 6, label: "Last 6 months" },
|
|
7
|
+
{ key: "12m", unit: "months", amount: 12, label: "Last 12 months" },
|
|
8
|
+
{ key: "16m", unit: "months", amount: 16, label: "Last 16 months" }
|
|
9
|
+
];
|
|
10
|
+
var DEFAULT_WINDOW_PRESET = "28d";
|
|
11
|
+
var DAY_PATTERN = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
12
|
+
var MILLISECONDS_PER_DAY = 864e5;
|
|
13
|
+
function isValidDay(value) {
|
|
14
|
+
const match = DAY_PATTERN.exec(value);
|
|
15
|
+
if (!match) return false;
|
|
16
|
+
const [, year, month, day] = match.map(Number);
|
|
17
|
+
const date = new Date(Date.UTC(year, month - 1, day));
|
|
18
|
+
return date.getUTCFullYear() === year && date.getUTCMonth() === month - 1 && date.getUTCDate() === day;
|
|
19
|
+
}
|
|
20
|
+
function parseDay(day) {
|
|
21
|
+
if (!isValidDay(day)) throw new RangeError(`Not a day written YYYY-MM-DD: ${day}`);
|
|
22
|
+
const [, year, month, dayOfMonth] = DAY_PATTERN.exec(day).map(Number);
|
|
23
|
+
return Date.UTC(year, month - 1, dayOfMonth);
|
|
24
|
+
}
|
|
25
|
+
function formatDay(timestamp) {
|
|
26
|
+
return new Date(timestamp).toISOString().slice(0, 10);
|
|
27
|
+
}
|
|
28
|
+
function addDays(day, days) {
|
|
29
|
+
return formatDay(parseDay(day) + days * MILLISECONDS_PER_DAY);
|
|
30
|
+
}
|
|
31
|
+
function subtractMonthsClamped(day, months) {
|
|
32
|
+
const date = new Date(parseDay(day));
|
|
33
|
+
const targetMonthIndex = date.getUTCFullYear() * 12 + date.getUTCMonth() - months;
|
|
34
|
+
const targetYear = Math.floor(targetMonthIndex / 12);
|
|
35
|
+
const targetMonth = targetMonthIndex - targetYear * 12;
|
|
36
|
+
const daysInTargetMonth = new Date(Date.UTC(targetYear, targetMonth + 1, 0)).getUTCDate();
|
|
37
|
+
return formatDay(Date.UTC(targetYear, targetMonth, Math.min(date.getUTCDate(), daysInTargetMonth)));
|
|
38
|
+
}
|
|
39
|
+
function daysInclusive(from, to) {
|
|
40
|
+
return Math.round((parseDay(to) - parseDay(from)) / MILLISECONDS_PER_DAY) + 1;
|
|
41
|
+
}
|
|
42
|
+
function computePresetWindow(preset, lastDay, earliestDay) {
|
|
43
|
+
const windowPreset = windowPresets.find((candidate) => candidate.key === preset);
|
|
44
|
+
if (!windowPreset) throw new RangeError(`Unknown preset: ${preset}`);
|
|
45
|
+
let from = windowPreset.unit === "days" ? addDays(lastDay, -(windowPreset.amount - 1)) : addDays(subtractMonthsClamped(lastDay, windowPreset.amount), 1);
|
|
46
|
+
let windowClamped = false;
|
|
47
|
+
if (earliestDay !== void 0 && from < earliestDay) {
|
|
48
|
+
from = earliestDay;
|
|
49
|
+
windowClamped = true;
|
|
50
|
+
}
|
|
51
|
+
return { from, to: lastDay, days: daysInclusive(from, lastDay), preset, windowClamped };
|
|
52
|
+
}
|
|
53
|
+
function buildWindowLabel(window) {
|
|
54
|
+
const windowPreset = windowPresets.find((candidate) => candidate.key === window.preset);
|
|
55
|
+
const range = window.from === window.to ? window.from : `${window.from} \u2013 ${window.to}`;
|
|
56
|
+
const name = windowPreset ? windowPreset.label : `${window.days} ${window.days === 1 ? "day" : "days"}`;
|
|
57
|
+
return `${name} \xB7 ${range}${window.windowClamped ? " (from the earliest day kept)" : ""}`;
|
|
58
|
+
}
|
|
59
|
+
export {
|
|
60
|
+
DEFAULT_WINDOW_PRESET,
|
|
61
|
+
addDays,
|
|
62
|
+
buildWindowLabel,
|
|
63
|
+
computePresetWindow,
|
|
64
|
+
daysInclusive,
|
|
65
|
+
isValidDay,
|
|
66
|
+
subtractMonthsClamped,
|
|
67
|
+
windowPresets
|
|
68
|
+
};
|
|
69
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/logic/windows.ts"],"sourcesContent":["/**\n * Pure window logic of the site insights screens, the same arithmetic as the PHP `SearchDays` / `SearchWindowsService`:\n * days are `YYYY-MM-DD` strings in the provider's day zone, computed on UTC dates (no local time zone involved), both\n * ends inclusive. Server-callable: no React, no DOM.\n */\n\n/** A window preset of the API (`preset` query parameter). */\nexport type WindowPresetKey = '7d' | '28d' | '90d' | '6m' | '12m' | '16m';\n\nexport interface WindowPreset {\n key: WindowPresetKey;\n /** `days`: the last N days; `months`: the same day M months earlier plus one day */\n unit: 'days' | 'months';\n amount: number;\n /** Short English label; hosts translate by `key` */\n label: string;\n}\n\n/** The presets in the order a picker shows them. */\nexport const windowPresets: readonly WindowPreset[] = [\n { key: '7d', unit: 'days', amount: 7, label: 'Last 7 days' },\n { key: '28d', unit: 'days', amount: 28, label: 'Last 28 days' },\n { key: '90d', unit: 'days', amount: 90, label: 'Last 3 months' },\n { key: '6m', unit: 'months', amount: 6, label: 'Last 6 months' },\n { key: '12m', unit: 'months', amount: 12, label: 'Last 12 months' },\n { key: '16m', unit: 'months', amount: 16, label: 'Last 16 months' },\n];\n\n/** The default preset of the API. */\nexport const DEFAULT_WINDOW_PRESET: WindowPresetKey = '28d';\n\n/** A window as the API returns it (`SearchWindow`) or as {@link computePresetWindow} builds it. */\nexport interface WindowDays {\n from: string;\n to: string;\n days: number;\n preset?: string | null;\n windowClamped?: boolean;\n}\n\nconst DAY_PATTERN = /^(\\d{4})-(\\d{2})-(\\d{2})$/;\nconst MILLISECONDS_PER_DAY = 86_400_000;\n\n/** Whether `value` is an existing day written `YYYY-MM-DD`. */\nexport function isValidDay(value: string): boolean {\n const match = DAY_PATTERN.exec(value);\n if (!match) return false;\n const [, year, month, day] = match.map(Number);\n const date = new Date(Date.UTC(year, month - 1, day));\n return date.getUTCFullYear() === year && date.getUTCMonth() === month - 1 && date.getUTCDate() === day;\n}\n\nfunction parseDay(day: string): number {\n if (!isValidDay(day)) throw new RangeError(`Not a day written YYYY-MM-DD: ${day}`);\n const [, year, month, dayOfMonth] = DAY_PATTERN.exec(day)!.map(Number);\n return Date.UTC(year, month - 1, dayOfMonth);\n}\n\nfunction formatDay(timestamp: number): string {\n return new Date(timestamp).toISOString().slice(0, 10);\n}\n\n/** The day `days` days after `day` (negative: before). */\nexport function addDays(day: string, days: number): string {\n return formatDay(parseDay(day) + days * MILLISECONDS_PER_DAY);\n}\n\n/** The same day of the month `months` months earlier, clamped to the last day of a shorter month. */\nexport function subtractMonthsClamped(day: string, months: number): string {\n const date = new Date(parseDay(day));\n const targetMonthIndex = date.getUTCFullYear() * 12 + date.getUTCMonth() - months;\n const targetYear = Math.floor(targetMonthIndex / 12);\n const targetMonth = targetMonthIndex - targetYear * 12;\n const daysInTargetMonth = new Date(Date.UTC(targetYear, targetMonth + 1, 0)).getUTCDate();\n return formatDay(Date.UTC(targetYear, targetMonth, Math.min(date.getUTCDate(), daysInTargetMonth)));\n}\n\n/** Days from `from` to `to`, both included. */\nexport function daysInclusive(from: string, to: string): number {\n return Math.round((parseDay(to) - parseDay(from)) / MILLISECONDS_PER_DAY) + 1;\n}\n\n/**\n * The window of a preset ending on `lastDay` (the last final day, or today for fresh data), raised to `earliestDay`\n * when given — the window the API answers for the same preset.\n */\nexport function computePresetWindow(preset: WindowPresetKey, lastDay: string, earliestDay?: string): WindowDays {\n const windowPreset = windowPresets.find((candidate) => candidate.key === preset);\n if (!windowPreset) throw new RangeError(`Unknown preset: ${preset}`);\n let from =\n windowPreset.unit === 'days'\n ? addDays(lastDay, -(windowPreset.amount - 1))\n : addDays(subtractMonthsClamped(lastDay, windowPreset.amount), 1);\n let windowClamped = false;\n if (earliestDay !== undefined && from < earliestDay) {\n from = earliestDay;\n windowClamped = true;\n }\n return { from, to: lastDay, days: daysInclusive(from, lastDay), preset, windowClamped };\n}\n\n/**\n * A one-line label of a window, e.g. `Last 28 days · 2026-10-17 – 2026-11-13`; a clamped window says so\n * (`… (from the earliest day kept)`), explicit days show their count.\n */\nexport function buildWindowLabel(window: WindowDays): string {\n const windowPreset = windowPresets.find((candidate) => candidate.key === window.preset);\n const range = window.from === window.to ? window.from : `${window.from} – ${window.to}`;\n const name = windowPreset ? windowPreset.label : `${window.days} ${window.days === 1 ? 'day' : 'days'}`;\n return `${name} · ${range}${window.windowClamped ? ' (from the earliest day kept)' : ''}`;\n}\n"],"mappings":";AAmBO,IAAM,gBAAyC;AAAA,EACpD,EAAE,KAAK,MAAM,MAAM,QAAQ,QAAQ,GAAG,OAAO,cAAc;AAAA,EAC3D,EAAE,KAAK,OAAO,MAAM,QAAQ,QAAQ,IAAI,OAAO,eAAe;AAAA,EAC9D,EAAE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GED
|
@@ -1,6 +1,67 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mgamadeus/ddd-site-insights",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0-rc.2",
|
|
4
|
+
"description": "Frontend of the site insights module for backends built with mgamadeus/ddd (Composer package mgamadeus/ddd-site-insights): types generated from the module's API and pure window logic for Search Console data.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"ddd",
|
|
7
|
+
"mgamadeus",
|
|
8
|
+
"search-console",
|
|
9
|
+
"seo",
|
|
10
|
+
"site-insights",
|
|
11
|
+
"rtk-query"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://github.com/ddd-framework/ddd-site-insights/tree/main/web#readme",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/ddd-framework/ddd-site-insights/issues"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/ddd-framework/ddd-site-insights.git",
|
|
20
|
+
"directory": "web"
|
|
21
|
+
},
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"author": "Marius-Eugen Gerdan <marius@gerdan.net>",
|
|
24
|
+
"type": "module",
|
|
25
|
+
"sideEffects": false,
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"import": "./dist/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./package.json": "./package.json"
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"dist",
|
|
35
|
+
"README.md",
|
|
36
|
+
"LICENSE"
|
|
37
|
+
],
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=20"
|
|
40
|
+
},
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
},
|
|
44
|
+
"peerDependencies": {
|
|
45
|
+
"@mgamadeus/ddd-web": ">=0.13.0 <1.0.0",
|
|
46
|
+
"@reduxjs/toolkit": "^2.6.0",
|
|
47
|
+
"react": "^19.0.0",
|
|
48
|
+
"react-redux": "^9.0.0"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@mgamadeus/ddd-web": "^0.14.0",
|
|
52
|
+
"@reduxjs/toolkit": "^2.13.0",
|
|
53
|
+
"@types/node": "^24.0.0",
|
|
54
|
+
"@types/react": "^19.3.0",
|
|
55
|
+
"react": "^19.3.1",
|
|
56
|
+
"react-redux": "^9.3.1",
|
|
57
|
+
"tsup": "^9.0.0",
|
|
58
|
+
"typescript": "^6.0.3"
|
|
59
|
+
},
|
|
60
|
+
"scripts": {
|
|
61
|
+
"build": "node scripts/clean.mjs && tsup && node scripts/check-package.mjs .",
|
|
62
|
+
"typecheck": "tsc -p .",
|
|
63
|
+
"test": "node --experimental-strip-types --no-warnings --test \"src/**/*.test.ts\"",
|
|
64
|
+
"generate": "ddd-web-sdk --config openapi-config.ts",
|
|
65
|
+
"check:generated": "pnpm generate && git diff --exit-code -- src/generated && test -z \"$(git status --porcelain -- src/generated)\""
|
|
66
|
+
}
|
|
6
67
|
}
|