@oxygen-agent/cli 1.45.4
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 +25 -0
- package/dist/browser-login.d.ts +8 -0
- package/dist/browser-login.d.ts.map +1 -0
- package/dist/browser-login.js +181 -0
- package/dist/browser-login.js.map +1 -0
- package/dist/credentials.d.ts +28 -0
- package/dist/credentials.d.ts.map +1 -0
- package/dist/credentials.js +470 -0
- package/dist/credentials.js.map +1 -0
- package/dist/http-client.d.ts +12 -0
- package/dist/http-client.d.ts.map +1 -0
- package/dist/http-client.js +218 -0
- package/dist/http-client.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3523 -0
- package/dist/index.js.map +1 -0
- package/dist/local-custom-http-column.d.ts +9 -0
- package/dist/local-custom-http-column.d.ts.map +1 -0
- package/dist/local-custom-http-column.js +571 -0
- package/dist/local-custom-http-column.js.map +1 -0
- package/dist/session.d.ts +57 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +194 -0
- package/dist/session.js.map +1 -0
- package/node_modules/@oxygen/recipe-sdk/dist/index.d.ts +136 -0
- package/node_modules/@oxygen/recipe-sdk/dist/index.d.ts.map +1 -0
- package/node_modules/@oxygen/recipe-sdk/dist/index.js +43 -0
- package/node_modules/@oxygen/recipe-sdk/dist/index.js.map +1 -0
- package/node_modules/@oxygen/recipe-sdk/package.json +15 -0
- package/node_modules/@oxygen/shared/dist/billing.d.ts +124 -0
- package/node_modules/@oxygen/shared/dist/billing.d.ts.map +1 -0
- package/node_modules/@oxygen/shared/dist/billing.js +296 -0
- package/node_modules/@oxygen/shared/dist/billing.js.map +1 -0
- package/node_modules/@oxygen/shared/dist/column-types.d.ts +55 -0
- package/node_modules/@oxygen/shared/dist/column-types.d.ts.map +1 -0
- package/node_modules/@oxygen/shared/dist/column-types.js +161 -0
- package/node_modules/@oxygen/shared/dist/column-types.js.map +1 -0
- package/node_modules/@oxygen/shared/dist/credit-guidance.d.ts +15 -0
- package/node_modules/@oxygen/shared/dist/credit-guidance.d.ts.map +1 -0
- package/node_modules/@oxygen/shared/dist/credit-guidance.js +60 -0
- package/node_modules/@oxygen/shared/dist/credit-guidance.js.map +1 -0
- package/node_modules/@oxygen/shared/dist/file-import.d.ts +22 -0
- package/node_modules/@oxygen/shared/dist/file-import.d.ts.map +1 -0
- package/node_modules/@oxygen/shared/dist/file-import.js +232 -0
- package/node_modules/@oxygen/shared/dist/file-import.js.map +1 -0
- package/node_modules/@oxygen/shared/dist/index.d.ts +45 -0
- package/node_modules/@oxygen/shared/dist/index.d.ts.map +1 -0
- package/node_modules/@oxygen/shared/dist/index.js +49 -0
- package/node_modules/@oxygen/shared/dist/index.js.map +1 -0
- package/node_modules/@oxygen/shared/dist/log.d.ts +22 -0
- package/node_modules/@oxygen/shared/dist/log.d.ts.map +1 -0
- package/node_modules/@oxygen/shared/dist/log.js +58 -0
- package/node_modules/@oxygen/shared/dist/log.js.map +1 -0
- package/node_modules/@oxygen/shared/dist/redaction.d.ts +4 -0
- package/node_modules/@oxygen/shared/dist/redaction.d.ts.map +1 -0
- package/node_modules/@oxygen/shared/dist/redaction.js +106 -0
- package/node_modules/@oxygen/shared/dist/redaction.js.map +1 -0
- package/node_modules/@oxygen/shared/dist/telemetry.d.ts +9 -0
- package/node_modules/@oxygen/shared/dist/telemetry.d.ts.map +1 -0
- package/node_modules/@oxygen/shared/dist/telemetry.js +98 -0
- package/node_modules/@oxygen/shared/dist/telemetry.js.map +1 -0
- package/node_modules/@oxygen/shared/dist/version.d.ts +2 -0
- package/node_modules/@oxygen/shared/dist/version.d.ts.map +1 -0
- package/node_modules/@oxygen/shared/dist/version.js +2 -0
- package/node_modules/@oxygen/shared/dist/version.js.map +1 -0
- package/node_modules/@oxygen/shared/package.json +21 -0
- package/node_modules/@oxygen/workflows/dist/index.d.ts +680 -0
- package/node_modules/@oxygen/workflows/dist/index.d.ts.map +1 -0
- package/node_modules/@oxygen/workflows/dist/index.js +983 -0
- package/node_modules/@oxygen/workflows/dist/index.js.map +1 -0
- package/node_modules/@oxygen/workflows/package.json +15 -0
- package/package.json +44 -0
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
export const WEEKLY_USAGE_WINDOW_DAYS = 7;
|
|
2
|
+
export const BILLING_CURRENCIES = ["usd"];
|
|
3
|
+
export const DEFAULT_BILLING_CURRENCY = "usd";
|
|
4
|
+
export const CONTACT_SALES_URL = "https://cal.com/tim-scheuer-mxbib9/45";
|
|
5
|
+
export const BASE_PRICING_PLANS = {
|
|
6
|
+
free: {
|
|
7
|
+
tier: "free",
|
|
8
|
+
name: "Free",
|
|
9
|
+
monthlyPriceCents: 0,
|
|
10
|
+
monthlyCredits: 500,
|
|
11
|
+
weeklyCreditsLimit: 500,
|
|
12
|
+
rolloverCap: 500,
|
|
13
|
+
byokEnabled: false,
|
|
14
|
+
description: "Try OXYGEN with managed email, phone enrichment, and AI credits.",
|
|
15
|
+
ctaLabel: "Start free",
|
|
16
|
+
features: [
|
|
17
|
+
"All integrations",
|
|
18
|
+
"Workflows",
|
|
19
|
+
"No card required",
|
|
20
|
+
],
|
|
21
|
+
},
|
|
22
|
+
starter: {
|
|
23
|
+
tier: "starter",
|
|
24
|
+
name: "Starter",
|
|
25
|
+
monthlyPriceCents: 9_900,
|
|
26
|
+
monthlyCredits: 5_000,
|
|
27
|
+
weeklyCreditsLimit: 2_000,
|
|
28
|
+
rolloverCap: 5_000,
|
|
29
|
+
byokEnabled: true,
|
|
30
|
+
description: "For founders running focused managed enrichment and AI columns.",
|
|
31
|
+
ctaLabel: "Choose Starter",
|
|
32
|
+
features: [
|
|
33
|
+
"All integrations",
|
|
34
|
+
"Bring your own keys",
|
|
35
|
+
"Workflows",
|
|
36
|
+
"Standard support",
|
|
37
|
+
],
|
|
38
|
+
},
|
|
39
|
+
pro: {
|
|
40
|
+
tier: "pro",
|
|
41
|
+
name: "Pro",
|
|
42
|
+
monthlyPriceCents: 24_900,
|
|
43
|
+
monthlyCredits: 12_500,
|
|
44
|
+
weeklyCreditsLimit: 5_000,
|
|
45
|
+
rolloverCap: 12_500,
|
|
46
|
+
byokEnabled: true,
|
|
47
|
+
description: "For recurring GTM enrichment and AI-column workflows on managed credits.",
|
|
48
|
+
badge: "Most popular",
|
|
49
|
+
highlighted: true,
|
|
50
|
+
ctaLabel: "Choose Pro",
|
|
51
|
+
features: [
|
|
52
|
+
"All integrations",
|
|
53
|
+
"Bring your own keys",
|
|
54
|
+
"Workflows",
|
|
55
|
+
"Standard support",
|
|
56
|
+
],
|
|
57
|
+
},
|
|
58
|
+
team: {
|
|
59
|
+
tier: "team",
|
|
60
|
+
name: "Team",
|
|
61
|
+
monthlyPriceCents: 74_900,
|
|
62
|
+
monthlyCredits: 37_500,
|
|
63
|
+
weeklyCreditsLimit: 15_000,
|
|
64
|
+
rolloverCap: 37_500,
|
|
65
|
+
byokEnabled: true,
|
|
66
|
+
description: "For small GTM teams and agencies running shared workflows with their own AI keys.",
|
|
67
|
+
ctaLabel: "Choose Team",
|
|
68
|
+
features: [
|
|
69
|
+
"All integrations",
|
|
70
|
+
"Bring your own keys",
|
|
71
|
+
"Workflows",
|
|
72
|
+
"Premium support",
|
|
73
|
+
],
|
|
74
|
+
},
|
|
75
|
+
scale: {
|
|
76
|
+
tier: "scale",
|
|
77
|
+
name: "Scale",
|
|
78
|
+
monthlyPriceCents: null,
|
|
79
|
+
monthlyCredits: 500_000,
|
|
80
|
+
weeklyCreditsLimit: 500_000,
|
|
81
|
+
rolloverCap: 500_000,
|
|
82
|
+
byokEnabled: true,
|
|
83
|
+
description: "For high-volume GTM teams that need custom limits and rollout support.",
|
|
84
|
+
ctaLabel: "Contact sales",
|
|
85
|
+
contactHref: CONTACT_SALES_URL,
|
|
86
|
+
features: [
|
|
87
|
+
"500,000+ managed credits / month",
|
|
88
|
+
"Phone number enrichment on managed credits",
|
|
89
|
+
"Custom provider routing and BYOK policies",
|
|
90
|
+
"Dedicated onboarding",
|
|
91
|
+
],
|
|
92
|
+
},
|
|
93
|
+
enterprise: {
|
|
94
|
+
tier: "enterprise",
|
|
95
|
+
name: "Enterprise",
|
|
96
|
+
monthlyPriceCents: null,
|
|
97
|
+
monthlyCredits: null,
|
|
98
|
+
weeklyCreditsLimit: null,
|
|
99
|
+
rolloverCap: null,
|
|
100
|
+
byokEnabled: true,
|
|
101
|
+
description: "Custom procurement, invoicing, limits, and rollout support.",
|
|
102
|
+
ctaLabel: "Talk to us",
|
|
103
|
+
contactHref: CONTACT_SALES_URL,
|
|
104
|
+
features: [
|
|
105
|
+
"Custom monthly usage pool",
|
|
106
|
+
"Phone number enrichment",
|
|
107
|
+
"Custom AI-key and provider routing policies",
|
|
108
|
+
"SSO, invoicing, and procurement support",
|
|
109
|
+
],
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
export const PUBLIC_PLAN_ORDER = [
|
|
113
|
+
"starter",
|
|
114
|
+
"pro",
|
|
115
|
+
"team",
|
|
116
|
+
];
|
|
117
|
+
export const SELF_SERVE_PLAN_TIERS = [
|
|
118
|
+
"starter",
|
|
119
|
+
"pro",
|
|
120
|
+
"team",
|
|
121
|
+
];
|
|
122
|
+
export const CONTACT_SALES_PLAN_TIERS = [
|
|
123
|
+
"scale",
|
|
124
|
+
"enterprise",
|
|
125
|
+
];
|
|
126
|
+
export const ACTIVE_SUBSCRIPTION_STATUSES = [
|
|
127
|
+
"active",
|
|
128
|
+
"trialing",
|
|
129
|
+
"past_due",
|
|
130
|
+
];
|
|
131
|
+
const LEGACY_PRICING_PLAN_OVERRIDES = {
|
|
132
|
+
launch_50: {
|
|
133
|
+
...BASE_PRICING_PLANS.starter,
|
|
134
|
+
name: "Legacy Launch",
|
|
135
|
+
monthlyPriceCents: 5_000,
|
|
136
|
+
monthlyCredits: 10_000,
|
|
137
|
+
weeklyCreditsLimit: 10_000,
|
|
138
|
+
rolloverCap: 10_000,
|
|
139
|
+
description: "Legacy Launch plan.",
|
|
140
|
+
},
|
|
141
|
+
starter_50: {
|
|
142
|
+
...BASE_PRICING_PLANS.starter,
|
|
143
|
+
name: "Legacy Starter",
|
|
144
|
+
monthlyPriceCents: 5_000,
|
|
145
|
+
monthlyCredits: 10_000,
|
|
146
|
+
weeklyCreditsLimit: 10_000,
|
|
147
|
+
rolloverCap: 10_000,
|
|
148
|
+
description: "Legacy Starter plan.",
|
|
149
|
+
},
|
|
150
|
+
pro_149: {
|
|
151
|
+
...BASE_PRICING_PLANS.pro,
|
|
152
|
+
name: "Legacy Pro",
|
|
153
|
+
monthlyPriceCents: 14_900,
|
|
154
|
+
monthlyCredits: 50_000,
|
|
155
|
+
weeklyCreditsLimit: 50_000,
|
|
156
|
+
rolloverCap: 50_000,
|
|
157
|
+
description: "Legacy Pro plan.",
|
|
158
|
+
},
|
|
159
|
+
team_399: {
|
|
160
|
+
...BASE_PRICING_PLANS.team,
|
|
161
|
+
name: "Legacy Team",
|
|
162
|
+
monthlyPriceCents: 39_900,
|
|
163
|
+
monthlyCredits: 150_000,
|
|
164
|
+
weeklyCreditsLimit: 150_000,
|
|
165
|
+
rolloverCap: 150_000,
|
|
166
|
+
description: "Legacy Team plan.",
|
|
167
|
+
},
|
|
168
|
+
growth_250: {
|
|
169
|
+
...BASE_PRICING_PLANS.pro,
|
|
170
|
+
monthlyPriceCents: 25_000,
|
|
171
|
+
monthlyCredits: 12_500,
|
|
172
|
+
weeklyCreditsLimit: 5_000,
|
|
173
|
+
rolloverCap: 12_500,
|
|
174
|
+
description: "Legacy Growth plan.",
|
|
175
|
+
},
|
|
176
|
+
scale_750: {
|
|
177
|
+
...BASE_PRICING_PLANS.team,
|
|
178
|
+
name: "Legacy Scale",
|
|
179
|
+
monthlyPriceCents: 75_000,
|
|
180
|
+
monthlyCredits: 37_500,
|
|
181
|
+
weeklyCreditsLimit: 15_000,
|
|
182
|
+
rolloverCap: 37_500,
|
|
183
|
+
description: "Legacy Scale plan.",
|
|
184
|
+
},
|
|
185
|
+
starter_legacy: {
|
|
186
|
+
...BASE_PRICING_PLANS.starter,
|
|
187
|
+
monthlyPriceCents: null,
|
|
188
|
+
monthlyCredits: 10_000,
|
|
189
|
+
weeklyCreditsLimit: BASE_PRICING_PLANS.starter.weeklyCreditsLimit,
|
|
190
|
+
rolloverCap: 10_000,
|
|
191
|
+
description: "Legacy Starter plan.",
|
|
192
|
+
},
|
|
193
|
+
scale_legacy: {
|
|
194
|
+
...BASE_PRICING_PLANS.scale,
|
|
195
|
+
monthlyPriceCents: null,
|
|
196
|
+
monthlyCredits: 60_000,
|
|
197
|
+
weeklyCreditsLimit: BASE_PRICING_PLANS.scale.weeklyCreditsLimit,
|
|
198
|
+
rolloverCap: 120_000,
|
|
199
|
+
description: "Legacy Scale plan.",
|
|
200
|
+
},
|
|
201
|
+
};
|
|
202
|
+
export function resolveBasePricingPlan(tier) {
|
|
203
|
+
if (!tier)
|
|
204
|
+
return null;
|
|
205
|
+
if (tier in BASE_PRICING_PLANS) {
|
|
206
|
+
return BASE_PRICING_PLANS[tier];
|
|
207
|
+
}
|
|
208
|
+
const legacy = LEGACY_PRICING_PLAN_OVERRIDES[tier];
|
|
209
|
+
return legacy ?? null;
|
|
210
|
+
}
|
|
211
|
+
export function applyPricingPlanMetadataOverrides(plan, metadata) {
|
|
212
|
+
const record = readRecord(metadata);
|
|
213
|
+
if (!record)
|
|
214
|
+
return plan;
|
|
215
|
+
const config = readRecord(record.billing_plan)
|
|
216
|
+
?? readRecord(record.custom_plan)
|
|
217
|
+
?? readRecord(record.custom_limits)
|
|
218
|
+
?? readRecord(record.plan_limits)
|
|
219
|
+
?? record;
|
|
220
|
+
const name = readString(config, "name")
|
|
221
|
+
?? readString(config, "plan_name")
|
|
222
|
+
?? readString(record, "plan_name")
|
|
223
|
+
?? readString(record, "custom_plan_name");
|
|
224
|
+
const description = readString(config, "description")
|
|
225
|
+
?? readString(record, "plan_description")
|
|
226
|
+
?? readString(record, "custom_plan_description");
|
|
227
|
+
const monthlyCredits = readCreditLimit(config, "monthlyCredits", "monthly_credits", "monthly_credit_limit");
|
|
228
|
+
const weeklyCreditsLimit = readCreditLimit(config, "weeklyCreditsLimit", "weekly_credits_limit", "weekly_credit_limit");
|
|
229
|
+
const rolloverCap = readCreditLimit(config, "rolloverCap", "rollover_cap", "rollover_credits");
|
|
230
|
+
const byokEnabled = readBoolean(config, "byokEnabled")
|
|
231
|
+
?? readBoolean(config, "byok_enabled");
|
|
232
|
+
return {
|
|
233
|
+
...plan,
|
|
234
|
+
name: name ?? plan.name,
|
|
235
|
+
monthlyCredits: monthlyCredits ?? plan.monthlyCredits,
|
|
236
|
+
weeklyCreditsLimit: weeklyCreditsLimit ?? plan.weeklyCreditsLimit,
|
|
237
|
+
rolloverCap: rolloverCap ?? plan.rolloverCap,
|
|
238
|
+
byokEnabled: byokEnabled ?? plan.byokEnabled,
|
|
239
|
+
description: description ?? plan.description,
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
export function isSelfServePlanTier(value) {
|
|
243
|
+
return SELF_SERVE_PLAN_TIERS.includes(value);
|
|
244
|
+
}
|
|
245
|
+
export function isBillingCurrency(value) {
|
|
246
|
+
return BILLING_CURRENCIES.includes(value);
|
|
247
|
+
}
|
|
248
|
+
export function normalizeBillingCurrency(value) {
|
|
249
|
+
return value && isBillingCurrency(value) ? value : DEFAULT_BILLING_CURRENCY;
|
|
250
|
+
}
|
|
251
|
+
function readRecord(value) {
|
|
252
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
253
|
+
return null;
|
|
254
|
+
return value;
|
|
255
|
+
}
|
|
256
|
+
function readString(record, key) {
|
|
257
|
+
const value = record[key];
|
|
258
|
+
return typeof value === "string" && value.trim() ? value.trim() : null;
|
|
259
|
+
}
|
|
260
|
+
function readBoolean(record, key) {
|
|
261
|
+
const value = record[key];
|
|
262
|
+
return typeof value === "boolean" ? value : null;
|
|
263
|
+
}
|
|
264
|
+
function readCreditLimit(record, ...keys) {
|
|
265
|
+
for (const key of keys) {
|
|
266
|
+
const value = record[key];
|
|
267
|
+
if (value === null)
|
|
268
|
+
return null;
|
|
269
|
+
if (typeof value === "number" && Number.isFinite(value) && value >= 0) {
|
|
270
|
+
return Math.trunc(value);
|
|
271
|
+
}
|
|
272
|
+
if (typeof value === "string" && value.trim()) {
|
|
273
|
+
const parsed = Number(value);
|
|
274
|
+
if (Number.isFinite(parsed) && parsed >= 0)
|
|
275
|
+
return Math.trunc(parsed);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
return null;
|
|
279
|
+
}
|
|
280
|
+
export function getCurrentFreeTierCycleKey(date = new Date()) {
|
|
281
|
+
const year = date.getUTCFullYear();
|
|
282
|
+
const month = String(date.getUTCMonth() + 1).padStart(2, "0");
|
|
283
|
+
return `free:${year}-${month}`;
|
|
284
|
+
}
|
|
285
|
+
export function evaluateWeeklyQuota(usedCredits, requestedCredits, weeklyCreditsLimit) {
|
|
286
|
+
const projectedCredits = usedCredits + requestedCredits;
|
|
287
|
+
return {
|
|
288
|
+
usedCredits,
|
|
289
|
+
requestedCredits,
|
|
290
|
+
weeklyCreditsLimit,
|
|
291
|
+
remainingCredits: Math.max(0, weeklyCreditsLimit - usedCredits),
|
|
292
|
+
projectedRemainingCredits: Math.max(0, weeklyCreditsLimit - projectedCredits),
|
|
293
|
+
exceedsLimit: projectedCredits > weeklyCreditsLimit,
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
//# sourceMappingURL=billing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"billing.js","sourceRoot":"","sources":["../src/billing.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,CAAC;AAE1C,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,KAAK,CAAU,CAAC;AAGnD,MAAM,CAAC,MAAM,wBAAwB,GAAoB,KAAK,CAAC;AAyB/D,MAAM,CAAC,MAAM,iBAAiB,GAAG,uCAAuC,CAAC;AAEzE,MAAM,CAA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C,KAAK,CAAC,CAAC;YAC7B,IAAI,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,MAAM,IAAI,CAAC;gBAAE,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QACxE,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,0BAA0B,CAAC,OAAa,IAAI,IAAI,EAAE;IAChE,MAAM,IAAI,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;IACnC,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAC9D,OAAO,QAAQ,IAAI,IAAI,KAAK,EAAE,CAAC;AACjC,CAAC;AAED,MAAM,UAAU,mBAAmB,CACjC,WAAmB,EACnB,gBAAwB,EACxB,kBAA0B;IAE1B,MAAM,gBAAgB,GAAG,WAAW,GAAG,gBAAgB,CAAC;IACxD,OAAO;QACL,WAAW;QACX,gBAAgB;QAChB,kBAAkB;QAClB,gBAAgB,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,kBAAkB,GAAG,WAAW,CAAC;QAC/D,yBAAyB,EAAE,IAAI,CAAC,GAAG,CACjC,CAAC,EACD,kBAAkB,GAAG,gBAAgB,CACtC;QACD,YAAY,EAAE,gBAAgB,GAAG,kBAAkB;KACpD,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared column data-type detection and value coercion.
|
|
3
|
+
*
|
|
4
|
+
* This is the single source of truth for two related problems:
|
|
5
|
+
* 1. Import inference — deciding a freshly uploaded column is a date column
|
|
6
|
+
* instead of dumping everything as `text` (see `inferImportColumnDataType`).
|
|
7
|
+
* 2. Column retype — converting an existing `text` column's raw values into a
|
|
8
|
+
* stronger type without losing data (see `coerceValueForDataType`).
|
|
9
|
+
*
|
|
10
|
+
* Both paths must agree on what "looks like a date" means, otherwise an import
|
|
11
|
+
* would type a column one way and a manual retype another.
|
|
12
|
+
*/
|
|
13
|
+
/** Data types an import can infer for a brand-new column. Dates-only by design. */
|
|
14
|
+
export type ImportColumnDataType = "text" | "timestamptz";
|
|
15
|
+
/** Data types a `text` column can be explicitly retyped into. */
|
|
16
|
+
export type RetypeableDataType = "text" | "numeric" | "boolean" | "timestamptz";
|
|
17
|
+
export declare const RETYPEABLE_DATA_TYPES: readonly RetypeableDataType[];
|
|
18
|
+
export declare const EXCEL_SERIAL_MIN = 10000;
|
|
19
|
+
export declare const EXCEL_SERIAL_MAX = 80000;
|
|
20
|
+
/** Convert an Excel/Sheets date serial to an ISO timestamp, or null if implausible. */
|
|
21
|
+
export declare function excelSerialToIso(serial: number): string | null;
|
|
22
|
+
/** Return the canonical ISO form of an ISO-8601-ish date string, or null. */
|
|
23
|
+
export declare function parseIsoDateString(value: string): string | null;
|
|
24
|
+
/** True when a column label/key implies it holds dates. */
|
|
25
|
+
export declare function looksLikeDateColumnName(label: string): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Best-effort conversion of a single cell value to an ISO timestamp.
|
|
28
|
+
* `allowExcelSerial` controls whether bare numbers (and numeric strings) are
|
|
29
|
+
* treated as Excel date serials — only enable it when the column name hints at
|
|
30
|
+
* a date or the user explicitly opted in via a retype.
|
|
31
|
+
*/
|
|
32
|
+
export declare function parseDateValueToIso(value: unknown, options?: {
|
|
33
|
+
allowExcelSerial: boolean;
|
|
34
|
+
}): string | null;
|
|
35
|
+
/**
|
|
36
|
+
* Infer the data type of a brand-new imported column from its label and sampled
|
|
37
|
+
* values. Conservative and dates-only: a column becomes `timestamptz` only when
|
|
38
|
+
* every non-empty value is an ISO date string, or (when the name hints at a
|
|
39
|
+
* date) every non-empty value is an Excel serial. Anything else stays `text`.
|
|
40
|
+
*/
|
|
41
|
+
export declare function inferImportColumnDataType(label: string, values: Iterable<unknown>): ImportColumnDataType;
|
|
42
|
+
export type CoercionResult = {
|
|
43
|
+
ok: true;
|
|
44
|
+
value: string | number | boolean | null;
|
|
45
|
+
} | {
|
|
46
|
+
ok: false;
|
|
47
|
+
reason: string;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Coerce a raw cell value into the representation a target data type expects.
|
|
51
|
+
* Used by column retype: every value must coerce or the retype is rejected so
|
|
52
|
+
* the table is never left half-converted.
|
|
53
|
+
*/
|
|
54
|
+
export declare function coerceValueForDataType(value: unknown, dataType: RetypeableDataType): CoercionResult;
|
|
55
|
+
//# sourceMappingURL=column-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"column-types.d.ts","sourceRoot":"","sources":["../src/column-types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,mFAAmF;AACnF,MAAM,MAAM,oBAAoB,GAAG,MAAM,GAAG,aAAa,CAAC;AAE1D,iEAAiE;AACjE,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,SAAS,GAAG,SAAS,GAAG,aAAa,CAAC;AAEhF,eAAO,MAAM,qBAAqB,EAAE,SAAS,kBAAkB,EAK9D,CAAC;AAWF,eAAO,MAAM,gBAAgB,QAAS,CAAC;AACvC,eAAO,MAAM,gBAAgB,QAAS,CAAC;AAavC,uFAAuF;AACvF,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAM9D;AAED,6EAA6E;AAC7E,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAK/D;AAED,2DAA2D;AAC3D,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAE9D;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,OAAO,EACd,OAAO,GAAE;IAAE,gBAAgB,EAAE,OAAO,CAAA;CAAgC,GACnE,MAAM,GAAG,IAAI,CAkBf;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,QAAQ,CAAC,OAAO,CAAC,GACxB,oBAAoB,CAsBtB;AAWD,MAAM,MAAM,cAAc,GACtB;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAA;CAAE,GACrD;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAElC;;;;GAIG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,OAAO,EACd,QAAQ,EAAE,kBAAkB,GAC3B,cAAc,CA+BhB"}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared column data-type detection and value coercion.
|
|
3
|
+
*
|
|
4
|
+
* This is the single source of truth for two related problems:
|
|
5
|
+
* 1. Import inference — deciding a freshly uploaded column is a date column
|
|
6
|
+
* instead of dumping everything as `text` (see `inferImportColumnDataType`).
|
|
7
|
+
* 2. Column retype — converting an existing `text` column's raw values into a
|
|
8
|
+
* stronger type without losing data (see `coerceValueForDataType`).
|
|
9
|
+
*
|
|
10
|
+
* Both paths must agree on what "looks like a date" means, otherwise an import
|
|
11
|
+
* would type a column one way and a manual retype another.
|
|
12
|
+
*/
|
|
13
|
+
export const RETYPEABLE_DATA_TYPES = [
|
|
14
|
+
"text",
|
|
15
|
+
"numeric",
|
|
16
|
+
"boolean",
|
|
17
|
+
"timestamptz",
|
|
18
|
+
];
|
|
19
|
+
// Excel/Sheets store dates as a serial number of days since 1899-12-30.
|
|
20
|
+
// Day 25569 of that system is the Unix epoch (1970-01-01).
|
|
21
|
+
const EXCEL_EPOCH_DAY_OFFSET = 25_569;
|
|
22
|
+
const MS_PER_DAY = 86_400_000;
|
|
23
|
+
// A bare number is only treated as an Excel date serial when it lands inside
|
|
24
|
+
// this window. ~10000 is 1927-05-18, ~80000 is 2119-01-?? — wide enough for any
|
|
25
|
+
// realistic business date, narrow enough to reject years ("2024"), small
|
|
26
|
+
// counters, and short identifiers that happen to sit in a date-named column.
|
|
27
|
+
export const EXCEL_SERIAL_MIN = 10_000;
|
|
28
|
+
export const EXCEL_SERIAL_MAX = 80_000;
|
|
29
|
+
// Strict ISO-8601-ish date (optionally with time and zone). Deliberately strict:
|
|
30
|
+
// `new Date()` alone would happily parse "46148" or "Acme" into garbage.
|
|
31
|
+
const ISO_DATE_PATTERN = /^\d{4}-\d{2}-\d{2}([T ]\d{2}:\d{2}(:\d{2})?(\.\d+)?\s*(Z|[+-]\d{2}:?\d{2})?)?$/;
|
|
32
|
+
// Column whose name implies a date. Used only as a guardrail for the ambiguous
|
|
33
|
+
// "bare number" case — ISO strings are unambiguous and never need a name hint.
|
|
34
|
+
const DATE_NAME_PATTERN = /(^|[^a-z])(date|datetime|timestamp)([^a-z]|$)|_at$|_on$/i;
|
|
35
|
+
const NUMERIC_STRING_PATTERN = /^-?\d+(\.\d+)?$/;
|
|
36
|
+
/** Convert an Excel/Sheets date serial to an ISO timestamp, or null if implausible. */
|
|
37
|
+
export function excelSerialToIso(serial) {
|
|
38
|
+
if (!Number.isFinite(serial) || serial < EXCEL_SERIAL_MIN || serial > EXCEL_SERIAL_MAX) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
const date = new Date(Math.round((serial - EXCEL_EPOCH_DAY_OFFSET) * MS_PER_DAY));
|
|
42
|
+
return Number.isFinite(date.getTime()) ? date.toISOString() : null;
|
|
43
|
+
}
|
|
44
|
+
/** Return the canonical ISO form of an ISO-8601-ish date string, or null. */
|
|
45
|
+
export function parseIsoDateString(value) {
|
|
46
|
+
const trimmed = value.trim();
|
|
47
|
+
if (!ISO_DATE_PATTERN.test(trimmed))
|
|
48
|
+
return null;
|
|
49
|
+
const date = new Date(trimmed);
|
|
50
|
+
return Number.isFinite(date.getTime()) ? date.toISOString() : null;
|
|
51
|
+
}
|
|
52
|
+
/** True when a column label/key implies it holds dates. */
|
|
53
|
+
export function looksLikeDateColumnName(label) {
|
|
54
|
+
return DATE_NAME_PATTERN.test(label.trim());
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Best-effort conversion of a single cell value to an ISO timestamp.
|
|
58
|
+
* `allowExcelSerial` controls whether bare numbers (and numeric strings) are
|
|
59
|
+
* treated as Excel date serials — only enable it when the column name hints at
|
|
60
|
+
* a date or the user explicitly opted in via a retype.
|
|
61
|
+
*/
|
|
62
|
+
export function parseDateValueToIso(value, options = { allowExcelSerial: false }) {
|
|
63
|
+
if (value === null || value === undefined)
|
|
64
|
+
return null;
|
|
65
|
+
if (value instanceof Date) {
|
|
66
|
+
return Number.isFinite(value.getTime()) ? value.toISOString() : null;
|
|
67
|
+
}
|
|
68
|
+
if (typeof value === "number") {
|
|
69
|
+
return options.allowExcelSerial ? excelSerialToIso(value) : null;
|
|
70
|
+
}
|
|
71
|
+
if (typeof value === "string") {
|
|
72
|
+
const trimmed = value.trim();
|
|
73
|
+
if (trimmed === "")
|
|
74
|
+
return null;
|
|
75
|
+
const iso = parseIsoDateString(trimmed);
|
|
76
|
+
if (iso)
|
|
77
|
+
return iso;
|
|
78
|
+
if (options.allowExcelSerial && NUMERIC_STRING_PATTERN.test(trimmed)) {
|
|
79
|
+
return excelSerialToIso(Number(trimmed));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Infer the data type of a brand-new imported column from its label and sampled
|
|
86
|
+
* values. Conservative and dates-only: a column becomes `timestamptz` only when
|
|
87
|
+
* every non-empty value is an ISO date string, or (when the name hints at a
|
|
88
|
+
* date) every non-empty value is an Excel serial. Anything else stays `text`.
|
|
89
|
+
*/
|
|
90
|
+
export function inferImportColumnDataType(label, values) {
|
|
91
|
+
const nameHintsDate = looksLikeDateColumnName(label);
|
|
92
|
+
let sawNonEmpty = false;
|
|
93
|
+
let allIsoStrings = true;
|
|
94
|
+
let allExcelSerials = true;
|
|
95
|
+
for (const value of values) {
|
|
96
|
+
if (value === null || value === undefined || value === "")
|
|
97
|
+
continue;
|
|
98
|
+
sawNonEmpty = true;
|
|
99
|
+
if (parseDateValueToIso(value, { allowExcelSerial: false }) === null) {
|
|
100
|
+
allIsoStrings = false;
|
|
101
|
+
}
|
|
102
|
+
if (!isExcelSerialValue(value)) {
|
|
103
|
+
allExcelSerials = false;
|
|
104
|
+
}
|
|
105
|
+
if (!allIsoStrings && !allExcelSerials)
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
if (!sawNonEmpty)
|
|
109
|
+
return "text";
|
|
110
|
+
if (allIsoStrings)
|
|
111
|
+
return "timestamptz";
|
|
112
|
+
if (allExcelSerials && nameHintsDate)
|
|
113
|
+
return "timestamptz";
|
|
114
|
+
return "text";
|
|
115
|
+
}
|
|
116
|
+
function isExcelSerialValue(value) {
|
|
117
|
+
if (typeof value === "number")
|
|
118
|
+
return excelSerialToIso(value) !== null;
|
|
119
|
+
if (typeof value === "string") {
|
|
120
|
+
const trimmed = value.trim();
|
|
121
|
+
return NUMERIC_STRING_PATTERN.test(trimmed) && excelSerialToIso(Number(trimmed)) !== null;
|
|
122
|
+
}
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Coerce a raw cell value into the representation a target data type expects.
|
|
127
|
+
* Used by column retype: every value must coerce or the retype is rejected so
|
|
128
|
+
* the table is never left half-converted.
|
|
129
|
+
*/
|
|
130
|
+
export function coerceValueForDataType(value, dataType) {
|
|
131
|
+
if (value === null || value === undefined || value === "") {
|
|
132
|
+
return { ok: true, value: null };
|
|
133
|
+
}
|
|
134
|
+
switch (dataType) {
|
|
135
|
+
case "text":
|
|
136
|
+
return { ok: true, value: typeof value === "string" ? value : String(value) };
|
|
137
|
+
case "timestamptz": {
|
|
138
|
+
const iso = parseDateValueToIso(value, { allowExcelSerial: true });
|
|
139
|
+
return iso
|
|
140
|
+
? { ok: true, value: iso }
|
|
141
|
+
: { ok: false, reason: "not an ISO date or Excel date serial" };
|
|
142
|
+
}
|
|
143
|
+
case "numeric": {
|
|
144
|
+
const numeric = typeof value === "number" ? value : Number(String(value).trim());
|
|
145
|
+
return Number.isFinite(numeric)
|
|
146
|
+
? { ok: true, value: numeric }
|
|
147
|
+
: { ok: false, reason: "not a finite number" };
|
|
148
|
+
}
|
|
149
|
+
case "boolean": {
|
|
150
|
+
const normalized = String(value).trim().toLowerCase();
|
|
151
|
+
if (["true", "t", "yes", "y", "1"].includes(normalized)) {
|
|
152
|
+
return { ok: true, value: true };
|
|
153
|
+
}
|
|
154
|
+
if (["false", "f", "no", "n", "0"].includes(normalized)) {
|
|
155
|
+
return { ok: true, value: false };
|
|
156
|
+
}
|
|
157
|
+
return { ok: false, reason: "not a recognized boolean" };
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=column-types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"column-types.js","sourceRoot":"","sources":["../src/column-types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAQH,MAAM,CAAC,MAAM,qBAAqB,GAAkC;IAClE,MAAM;IACN,SAAS;IACT,SAAS;IACT,aAAa;CACd,CAAC;AAEF,wEAAwE;AACxE,2DAA2D;AAC3D,MAAM,sBAAsB,GAAG,MAAM,CAAC;AACtC,MAAM,UAAU,GAAG,UAAU,CAAC;AAE9B,6EAA6E;AAC7E,gFAAgF;AAChF,yEAAyE;AACzE,6EAA6E;AAC7E,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC;AACvC,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAEvC,iFAAiF;AACjF,yEAAyE;AACzE,MAAM,gBAAgB,GACpB,gFAAgF,CAAC;AAEnF,+EAA+E;AAC/E,+EAA+E;AAC/E,MAAM,iBAAiB,GAAG,0DAA0D,CAAC;AAErF,MAAM,sBAAsB,GAAG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AC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;gBACxD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;YACpC,CAAC;YACD,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,0BAA0B,EAAE,CAAC;QAC3D,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type CreditPosture = "sufficient" | "tight" | "unknown";
|
|
2
|
+
export type CreditGuidance = {
|
|
3
|
+
estimated_credits: number | null;
|
|
4
|
+
recommended_max_credits: number | null;
|
|
5
|
+
available_credits: number | null;
|
|
6
|
+
credit_posture: CreditPosture;
|
|
7
|
+
credit_guidance: string;
|
|
8
|
+
};
|
|
9
|
+
export declare function buildCreditGuidance(input: {
|
|
10
|
+
estimatedCredits: number | null | undefined;
|
|
11
|
+
availableCredits: number | null | undefined;
|
|
12
|
+
headroomMultiplier?: number;
|
|
13
|
+
}): CreditGuidance;
|
|
14
|
+
export declare function recommendedCreditCeiling(estimatedCredits: number | null | undefined, headroomMultiplier?: number): number | null;
|
|
15
|
+
//# sourceMappingURL=credit-guidance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credit-guidance.d.ts","sourceRoot":"","sources":["../src/credit-guidance.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GAAG,YAAY,GAAG,OAAO,GAAG,SAAS,CAAC;AAE/D,MAAM,MAAM,cAAc,GAAG;IAC3B,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,uBAAuB,EAAE,MAAM,GAAG,IAAI,CAAC;IACvC,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,cAAc,EAAE,aAAa,CAAC;IAC9B,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AAIF,wBAAgB,mBAAmB,CAAC,KAAK,EAAE;IACzC,gBAAgB,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAC5C,gBAAgB,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAC5C,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B,GAAG,cAAc,CAgDjB;AAED,wBAAgB,wBAAwB,CACtC,gBAAgB,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAC3C,kBAAkB,SAA8B,GAC/C,MAAM,GAAG,IAAI,CAQf"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
const DEFAULT_HEADROOM_MULTIPLIER = 1.25;
|
|
2
|
+
export function buildCreditGuidance(input) {
|
|
3
|
+
const estimatedCredits = normalizeCreditValue(input.estimatedCredits);
|
|
4
|
+
const availableCredits = normalizeCreditValue(input.availableCredits);
|
|
5
|
+
const recommendedMaxCredits = recommendedCreditCeiling(estimatedCredits, input.headroomMultiplier ?? DEFAULT_HEADROOM_MULTIPLIER);
|
|
6
|
+
if (estimatedCredits === null) {
|
|
7
|
+
return {
|
|
8
|
+
estimated_credits: null,
|
|
9
|
+
recommended_max_credits: null,
|
|
10
|
+
available_credits: availableCredits,
|
|
11
|
+
credit_posture: "unknown",
|
|
12
|
+
credit_guidance: "Credit estimate is unavailable; require an explicit max_credits before running paid work.",
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
if (availableCredits === null) {
|
|
16
|
+
return {
|
|
17
|
+
estimated_credits: estimatedCredits,
|
|
18
|
+
recommended_max_credits: recommendedMaxCredits,
|
|
19
|
+
available_credits: null,
|
|
20
|
+
credit_posture: "unknown",
|
|
21
|
+
credit_guidance: "Credit estimate is available, but balance is unknown. Use recommended_max_credits only after confirming available credits. Unused credits are not spent.",
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
if (recommendedMaxCredits !== null && recommendedMaxCredits <= availableCredits) {
|
|
25
|
+
return {
|
|
26
|
+
estimated_credits: estimatedCredits,
|
|
27
|
+
recommended_max_credits: recommendedMaxCredits,
|
|
28
|
+
available_credits: availableCredits,
|
|
29
|
+
credit_posture: "sufficient",
|
|
30
|
+
credit_guidance: "Credits are sufficient; use recommended_max_credits as a safety ceiling. Unused credits are not spent.",
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
estimated_credits: estimatedCredits,
|
|
35
|
+
recommended_max_credits: availableCredits > 0 ? roundCreditValue(availableCredits) : null,
|
|
36
|
+
available_credits: availableCredits,
|
|
37
|
+
credit_posture: "tight",
|
|
38
|
+
credit_guidance: "Credits are tight for the recommended ceiling; ask before running, reduce scope, or top up credits.",
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export function recommendedCreditCeiling(estimatedCredits, headroomMultiplier = DEFAULT_HEADROOM_MULTIPLIER) {
|
|
42
|
+
const normalized = normalizeCreditValue(estimatedCredits);
|
|
43
|
+
if (normalized === null)
|
|
44
|
+
return null;
|
|
45
|
+
if (normalized === 0)
|
|
46
|
+
return 0;
|
|
47
|
+
const multiplier = Number.isFinite(headroomMultiplier) && headroomMultiplier > 0
|
|
48
|
+
? headroomMultiplier
|
|
49
|
+
: DEFAULT_HEADROOM_MULTIPLIER;
|
|
50
|
+
return Math.max(1, Math.ceil(normalized * multiplier));
|
|
51
|
+
}
|
|
52
|
+
function normalizeCreditValue(value) {
|
|
53
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value < 0)
|
|
54
|
+
return null;
|
|
55
|
+
return roundCreditValue(value);
|
|
56
|
+
}
|
|
57
|
+
function roundCreditValue(value) {
|
|
58
|
+
return Math.round(value * 1000) / 1000;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=credit-guidance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credit-guidance.js","sourceRoot":"","sources":["../src/credit-guidance.ts"],"names":[],"mappings":"AAUA,MAAM,2BAA2B,GAAG,IAAI,CAAC;AAEzC,MAAM,UAAU,mBAAmB,CAAC,KAInC;IACC,MAAM,gBAAgB,GAAG,oBAAoB,CAAC,K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oBAAoB,CAAC,gBAAgB,CAAC,CAAC;IAC1D,IAAI,UAAU,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IACrC,IAAI,UAAU,KAAK,CAAC;QAAE,OAAO,CAAC,CAAC;IAC/B,MAAM,UAAU,GAAG,MAAM,CAAC,QAAQ,CAAC,kBAAkB,CAAC,IAAI,kBAAkB,GAAG,CAAC;QAC9E,CAAC,CAAC,kBAAkB;QACpB,CAAC,CAAC,2BAA2B,CAAC;IAChC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC,CAAC,CAAC;AACzD,CAAC;AAED,SAAS,oBAAoB,CAAC,KAAgC;IAC5D,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IACnF,OAAO,gBAAgB,CAAC,KAAK,CAAC,CAAC;AACjC,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAa;IACrC,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;AACzC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type ImportColumnDataType } from "./column-types.js";
|
|
2
|
+
export type RowsFileFormat = "json" | "jsonl" | "csv" | "xlsx";
|
|
3
|
+
export type ImportTableColumn = {
|
|
4
|
+
label: string;
|
|
5
|
+
key: string;
|
|
6
|
+
data_type: ImportColumnDataType;
|
|
7
|
+
};
|
|
8
|
+
export type NewTableImportRows = {
|
|
9
|
+
columns: ImportTableColumn[];
|
|
10
|
+
rows: Record<string, unknown>[];
|
|
11
|
+
keyBySource: Record<string, string>;
|
|
12
|
+
};
|
|
13
|
+
export declare function inferRowsFileFormat(path: string): RowsFileFormat;
|
|
14
|
+
export declare function normalizeRowsFormat(value: string | undefined, fallback: RowsFileFormat): RowsFileFormat;
|
|
15
|
+
export declare function parseRowsFileBuffer(buffer: Buffer, format: RowsFileFormat, options?: {
|
|
16
|
+
sheet?: string;
|
|
17
|
+
}): Promise<Record<string, unknown>[]>;
|
|
18
|
+
export declare function parseRowsText(text: string, format: Exclude<RowsFileFormat, "xlsx">): Record<string, unknown>[];
|
|
19
|
+
export declare function inferImportColumnLabels(rows: Record<string, unknown>[]): string[];
|
|
20
|
+
export declare function normalizeRowsForNewTable(rows: Record<string, unknown>[]): NewTableImportRows;
|
|
21
|
+
export declare function normalizeImportColumnKey(value: string): string;
|
|
22
|
+
//# sourceMappingURL=file-import.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-import.d.ts","sourceRoot":"","sources":["../src/file-import.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,oBAAoB,EAG1B,MAAM,mBAAmB,CAAC;AAG3B,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,OAAO,GAAG,KAAK,GAAG,MAAM,CAAC;AAE/D,MAAM,MAAM,iBAAiB,GAAG;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,oBAAoB,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,EAAE,iBAAiB,EAAE,CAAC;IAC7B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;IAChC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACrC,CAAC;AAIF,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,CAMhE;AAED,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,QAAQ,EAAE,cAAc,GACvB,cAAc,CAchB;AAED,wBAAsB,mBAAmB,CACvC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,cAAc,EACtB,OAAO,GAA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