@gscdump/sdk 1.3.2 → 1.4.0
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/period.mjs +26 -24
- package/dist/v1/index.d.mts +3 -3
- package/dist/v1/index.mjs +2 -2
- package/package.json +6 -7
package/dist/period.mjs
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import "./gsc-constants.mjs";
|
|
2
2
|
import { resolveWindow } from "@gscdump/engine/period";
|
|
3
|
-
import {
|
|
4
|
-
import { format } from "date-fns/format";
|
|
5
|
-
import { startOfMonth } from "date-fns/startOfMonth";
|
|
6
|
-
import { startOfQuarter } from "date-fns/startOfQuarter";
|
|
7
|
-
import { startOfWeek } from "date-fns/startOfWeek";
|
|
8
|
-
import { subDays } from "date-fns/subDays";
|
|
9
|
-
import { subMonths } from "date-fns/subMonths";
|
|
3
|
+
import { addDays } from "gscdump/dates";
|
|
10
4
|
function isCustomPeriod(p) {
|
|
11
5
|
return typeof p === "string" && p.startsWith("custom:");
|
|
12
6
|
}
|
|
@@ -26,13 +20,14 @@ function parseCustomPeriod(p) {
|
|
|
26
20
|
};
|
|
27
21
|
}
|
|
28
22
|
function todayInTimezone(timezone = "America/Los_Angeles", now = /* @__PURE__ */ new Date()) {
|
|
29
|
-
const
|
|
23
|
+
const parts = new Intl.DateTimeFormat("en-CA", {
|
|
30
24
|
timeZone: timezone,
|
|
31
25
|
year: "numeric",
|
|
32
26
|
month: "2-digit",
|
|
33
27
|
day: "2-digit"
|
|
34
|
-
}).
|
|
35
|
-
|
|
28
|
+
}).formatToParts(now);
|
|
29
|
+
const value = (type) => parts.find((part) => part.type === type).value;
|
|
30
|
+
return `${value("year")}-${value("month")}-${value("day")}`;
|
|
36
31
|
}
|
|
37
32
|
const ROLLING_TO_UPSTREAM = {
|
|
38
33
|
"7d": "last-7d",
|
|
@@ -45,8 +40,19 @@ const CALENDAR_TO_UPSTREAM = {
|
|
|
45
40
|
"this-month": "mtd",
|
|
46
41
|
"this-year": "ytd"
|
|
47
42
|
};
|
|
48
|
-
function
|
|
49
|
-
return
|
|
43
|
+
function startOfMonth(date) {
|
|
44
|
+
return `${date.slice(0, 7)}-01`;
|
|
45
|
+
}
|
|
46
|
+
function endOfMonth(date) {
|
|
47
|
+
return addDays(startOfMonth(addDays(startOfMonth(date), 32)), -1);
|
|
48
|
+
}
|
|
49
|
+
function startOfQuarter(date) {
|
|
50
|
+
const [year, month] = date.split("-").map(Number);
|
|
51
|
+
const quarterMonth = Math.floor((month - 1) / 3) * 3 + 1;
|
|
52
|
+
return `${year}-${String(quarterMonth).padStart(2, "0")}-01`;
|
|
53
|
+
}
|
|
54
|
+
function startOfWeek(date) {
|
|
55
|
+
return addDays(date, -(((/* @__PURE__ */ new Date(`${date}T00:00:00Z`)).getUTCDay() + 6) % 7));
|
|
50
56
|
}
|
|
51
57
|
function buildResultFromIso(start, end) {
|
|
52
58
|
const startDate = /* @__PURE__ */ new Date(`${start}T00:00:00`);
|
|
@@ -89,9 +95,7 @@ function periodToDateRange(period, stableDataOrOptions = true) {
|
|
|
89
95
|
};
|
|
90
96
|
return result;
|
|
91
97
|
}
|
|
92
|
-
const
|
|
93
|
-
const end = stableData ? subDays(today, 3) : subDays(today, 1);
|
|
94
|
-
const endIso = fmt(end);
|
|
98
|
+
const endIso = addDays(todayInTimezone(options.timezone, options.now), -(stableData ? 3 : 1));
|
|
95
99
|
const upstreamPreset = ROLLING_TO_UPSTREAM[period] ?? CALENDAR_TO_UPSTREAM[period];
|
|
96
100
|
if (upstreamPreset) {
|
|
97
101
|
const win = resolveWindow({
|
|
@@ -103,18 +107,18 @@ function periodToDateRange(period, stableDataOrOptions = true) {
|
|
|
103
107
|
let start;
|
|
104
108
|
switch (period) {
|
|
105
109
|
case "this-week":
|
|
106
|
-
start = startOfWeek(
|
|
110
|
+
start = startOfWeek(endIso);
|
|
107
111
|
break;
|
|
108
112
|
case "last-month": {
|
|
109
|
-
const
|
|
110
|
-
return buildResultFromIso(
|
|
113
|
+
const previousMonth = addDays(startOfMonth(endIso), -1);
|
|
114
|
+
return buildResultFromIso(startOfMonth(previousMonth), endOfMonth(previousMonth));
|
|
111
115
|
}
|
|
112
116
|
case "this-quarter":
|
|
113
|
-
start = startOfQuarter(
|
|
117
|
+
start = startOfQuarter(endIso);
|
|
114
118
|
break;
|
|
115
|
-
default: start =
|
|
119
|
+
default: start = addDays(endIso, -27);
|
|
116
120
|
}
|
|
117
|
-
return buildResultFromIso(
|
|
121
|
+
return buildResultFromIso(start, endIso);
|
|
118
122
|
}
|
|
119
123
|
function periodToDays(period, stableDataOrOptions = true) {
|
|
120
124
|
return periodToDateRange(period, stableDataOrOptions).days;
|
|
@@ -131,8 +135,6 @@ function compareRange(range, mode) {
|
|
|
131
135
|
};
|
|
132
136
|
}
|
|
133
137
|
function getGscUnstableCutoffDate() {
|
|
134
|
-
|
|
135
|
-
const cutoff = new Date(y, m - 1, d - 3);
|
|
136
|
-
return `${cutoff.getFullYear()}-${String(cutoff.getMonth() + 1).padStart(2, "0")}-${String(cutoff.getDate()).padStart(2, "0")}`;
|
|
138
|
+
return addDays(todayInTimezone(), -3);
|
|
137
139
|
}
|
|
138
140
|
export { compareRange, getGscUnstableCutoffDate, isCustomPeriod, parseCustomPeriod, periodToDateRange, periodToDays };
|
package/dist/v1/index.d.mts
CHANGED
|
@@ -58,7 +58,7 @@ interface GscdumpV1ErrorOptions {
|
|
|
58
58
|
}
|
|
59
59
|
/** One stable, tagged failure shape for validation, transport, and API errors. */
|
|
60
60
|
declare class GscdumpV1Error extends Error {
|
|
61
|
-
readonly tag:
|
|
61
|
+
readonly tag: 'GscdumpV1Error';
|
|
62
62
|
readonly code: GscdumpV1SdkErrorCode;
|
|
63
63
|
readonly status?: number;
|
|
64
64
|
readonly requestId?: string;
|
|
@@ -124,7 +124,7 @@ interface GscdumpV1Client {
|
|
|
124
124
|
/** Create one framework-neutral client whose behavior is driven by the v1 registry. */
|
|
125
125
|
declare function createGscdumpV1Client(options: CreateGscdumpV1ClientOptions): GscdumpV1Client;
|
|
126
126
|
type MaybePromise<T> = T | Promise<T>;
|
|
127
|
-
declare const GSCDUMP_REALTIME_V1_SDK_VERSION:
|
|
127
|
+
declare const GSCDUMP_REALTIME_V1_SDK_VERSION: '1.4.0';
|
|
128
128
|
type GscdumpRealtimeV1TransportState = 'idle' | 'ticketing' | 'connecting' | 'handshaking' | 'replaying' | 'live' | 'waiting' | 'stopped' | 'terminal';
|
|
129
129
|
type GscdumpRealtimeV1Freshness = 'unknown' | 'stale' | 'applying' | 'fresh' | 'resyncing' | 'degraded';
|
|
130
130
|
type GscdumpRealtimeV1ErrorCode = 'cursor_store_failed' | 'effect_failed' | 'heartbeat_stale' | 'integration_failed' | 'protocol_error' | 'resync_failed' | 'runtime_unavailable' | 'socket_error' | 'ticket_invalid' | 'ticket_provider_failed' | 'upgrade_rejected';
|
|
@@ -137,7 +137,7 @@ interface GscdumpRealtimeV1ErrorOptions {
|
|
|
137
137
|
cause?: unknown;
|
|
138
138
|
}
|
|
139
139
|
declare class GscdumpRealtimeV1Error extends Error {
|
|
140
|
-
readonly tag:
|
|
140
|
+
readonly tag: 'GscdumpRealtimeV1Error';
|
|
141
141
|
readonly code: GscdumpRealtimeV1ErrorCode;
|
|
142
142
|
readonly retryable: boolean;
|
|
143
143
|
readonly terminal: boolean;
|
package/dist/v1/index.mjs
CHANGED
|
@@ -428,7 +428,7 @@ function utf8Size(value) {
|
|
|
428
428
|
}
|
|
429
429
|
return bytes;
|
|
430
430
|
}
|
|
431
|
-
const GSCDUMP_REALTIME_V1_SDK_VERSION = "1.
|
|
431
|
+
const GSCDUMP_REALTIME_V1_SDK_VERSION = "1.4.0";
|
|
432
432
|
var GscdumpRealtimeV1Error = class extends Error {
|
|
433
433
|
tag = "GscdumpRealtimeV1Error";
|
|
434
434
|
code;
|
|
@@ -515,7 +515,7 @@ function createGscdumpRealtimeV1Client(options) {
|
|
|
515
515
|
const protocol = createGscdumpV1Protocol();
|
|
516
516
|
const runtime = options.runtime ?? defaultRuntime();
|
|
517
517
|
const cursorStore = options.cursorStore ?? createMemoryCursorStore();
|
|
518
|
-
const sdkVersion = options.sdkVersion ?? "1.
|
|
518
|
+
const sdkVersion = options.sdkVersion ?? "1.4.0";
|
|
519
519
|
if (!sdkVersion) throw new TypeError("sdkVersion cannot be empty.");
|
|
520
520
|
let running = false;
|
|
521
521
|
let epoch = 0;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gscdump/sdk",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.4.0",
|
|
5
5
|
"description": "Consumer SDK for hosted gscdump.com integrations.",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Harlan Wilton",
|
|
@@ -146,16 +146,15 @@
|
|
|
146
146
|
"node": ">=22"
|
|
147
147
|
},
|
|
148
148
|
"dependencies": {
|
|
149
|
-
"date-fns": "^4.4.0",
|
|
150
149
|
"ofetch": "^1.5.1",
|
|
151
150
|
"zod": "^4.4.3",
|
|
152
|
-
"@gscdump/analysis": "^1.
|
|
153
|
-
"@gscdump/
|
|
154
|
-
"
|
|
155
|
-
"gscdump": "^1.
|
|
151
|
+
"@gscdump/analysis": "^1.4.0",
|
|
152
|
+
"@gscdump/engine": "^1.4.0",
|
|
153
|
+
"gscdump": "^1.4.0",
|
|
154
|
+
"@gscdump/contracts": "^1.4.0"
|
|
156
155
|
},
|
|
157
156
|
"devDependencies": {
|
|
158
|
-
"typescript": "^
|
|
157
|
+
"typescript": "^7.0.2",
|
|
159
158
|
"vitest": "^4.1.10"
|
|
160
159
|
},
|
|
161
160
|
"scripts": {
|