@wirecat/cli-core 0.606.0 → 0.608.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/CHANGELOG.md +196 -0
- package/dist/calendar/index.d.ts +1 -0
- package/dist/calendar/index.js +1 -0
- package/dist/calendar/reads.js +5 -0
- package/dist/cli/app-mcp-command.d.ts +6 -2
- package/dist/cli/app-mcp-command.js +11 -2
- package/dist/cli/csv.d.ts +10 -0
- package/dist/cli/csv.js +22 -0
- package/dist/cli/early-refusal.d.ts +10 -0
- package/dist/cli/early-refusal.js +19 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.js +3 -0
- package/dist/cli/profile-token.d.ts +29 -0
- package/dist/cli/profile-token.js +65 -0
- package/dist/cli/program.js +4 -2
- package/dist/crm/cli/csv.d.ts +23 -0
- package/dist/crm/cli/csv.js +135 -0
- package/dist/crm/cli/index.d.ts +1 -1
- package/dist/crm/cli/index.js +33 -21
- package/dist/crm/cli/pipeline-view.d.ts +3 -0
- package/dist/crm/cli/pipeline-view.js +36 -0
- package/dist/crm/writes.d.ts +6 -4
- package/dist/crm/writes.js +17 -13
- package/dist/documents.d.ts +2 -0
- package/dist/documents.js +2 -0
- package/dist/domain/business.d.ts +79 -0
- package/dist/domain/business.js +42 -0
- package/dist/domain/finance.d.ts +2 -0
- package/dist/domain/finance.js +2 -2
- package/dist/domain/google-documents.d.ts +2 -0
- package/dist/domain/google-documents.js +3 -1
- package/dist/domain/money.d.ts +2 -0
- package/dist/domain/money.js +11 -3
- package/dist/domain/providers.d.ts +36 -1
- package/dist/domain/providers.js +69 -7
- package/dist/domain/record-fields.d.ts +42 -0
- package/dist/domain/record-fields.js +122 -0
- package/dist/domain/record-types.d.ts +489 -16
- package/dist/domain/record-types.js +374 -7
- package/dist/domain/records.d.ts +96 -5
- package/dist/domain/records.js +178 -32
- package/dist/domain/ref-summaries.js +5 -0
- package/dist/domain/references.d.ts +1 -1
- package/dist/domain/references.js +5 -0
- package/dist/domain/vcard.d.ts +25 -0
- package/dist/domain/vcard.js +267 -0
- package/dist/entities/deal.d.ts +14 -0
- package/dist/entities/deal.js +3 -0
- package/dist/entities/index.d.ts +12 -0
- package/dist/errors/reasons.js +63 -4
- package/dist/fetch/addresses.d.ts +5 -0
- package/dist/fetch/addresses.js +76 -0
- package/dist/fetch/page.d.ts +64 -0
- package/dist/fetch/page.js +256 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.js +5 -3
- package/dist/meetings/calendar-text.d.ts +1 -1
- package/dist/meetings/calendar-text.js +4 -0
- package/dist/meetings/event-store.d.ts +2 -2
- package/dist/search/account-list.d.ts +4 -0
- package/dist/search/account-list.js +19 -8
- package/dist/search/query.js +2 -2
- package/dist/services/events-search.js +2 -2
- package/dist/services/index.d.ts +1 -1
- package/dist/services/index.js +1 -1
- package/dist/services/ingest.d.ts +56 -8
- package/dist/services/ingest.js +95 -61
- package/dist/services/messages-search.js +3 -2
- package/dist/services/metadata.d.ts +1 -1
- package/dist/services/notes-search.js +1 -0
- package/dist/services/proposals/kinds/contracts.d.ts +4 -0
- package/dist/services/proposals/kinds/contracts.js +9 -0
- package/dist/services/proposals/kinds/finance.d.ts +4 -0
- package/dist/services/proposals/kinds/finance.js +14 -35
- package/dist/services/proposals/kinds/orders.js +7 -30
- package/dist/services/proposals/kinds/shared.d.ts +27 -1
- package/dist/services/proposals/kinds/shared.js +34 -0
- package/dist/services/proposals/kinds/source-review.d.ts +4 -0
- package/dist/services/proposals/kinds/source-review.js +45 -0
- package/dist/services/proposals/kinds/subscriptions.d.ts +9 -0
- package/dist/services/proposals/kinds/subscriptions.js +24 -0
- package/dist/services/proposals/kinds/transactions.d.ts +4 -0
- package/dist/services/proposals/kinds/transactions.js +10 -0
- package/dist/services/proposals/registry.js +9 -0
- package/dist/services/search-all-meetings.js +2 -2
- package/dist/services/search-all.js +4 -3
- package/dist/services/search-kind.js +3 -3
- package/dist/store/decisions.js +5 -1
- package/dist/store/index.d.ts +14 -3
- package/dist/store/index.js +3 -0
- package/dist/store/people.js +1 -1
- package/dist/store/source-review.d.ts +64 -0
- package/dist/store/source-review.js +7 -0
- package/dist/store/sqlite/accounts.d.ts +1 -1
- package/dist/store/sqlite/accounts.js +24 -1
- package/dist/store/sqlite/added-sources.d.ts +82 -0
- package/dist/store/sqlite/added-sources.js +237 -0
- package/dist/store/sqlite/business-contracts.d.ts +90 -0
- package/dist/store/sqlite/business-contracts.js +182 -0
- package/dist/store/sqlite/calendar-events.js +7 -3
- package/dist/store/sqlite/calendar-forget.js +3 -0
- package/dist/store/sqlite/calendar.d.ts +21 -1
- package/dist/store/sqlite/calendar.js +27 -7
- package/dist/store/sqlite/chat-rekey.js +7 -0
- package/dist/store/sqlite/chats.d.ts +3 -1
- package/dist/store/sqlite/chats.js +15 -1
- package/dist/store/sqlite/crm-rows.d.ts +44 -0
- package/dist/store/sqlite/crm-rows.js +195 -0
- package/dist/store/sqlite/crm.d.ts +2 -11
- package/dist/store/sqlite/crm.js +11 -166
- package/dist/store/sqlite/deals.d.ts +4 -8
- package/dist/store/sqlite/deals.js +5 -3
- package/dist/store/sqlite/document-transfer/snapshot.js +2 -2
- package/dist/store/sqlite/emails.js +2 -0
- package/dist/store/sqlite/entity-types.d.ts +14 -9
- package/dist/store/sqlite/entity-types.js +4 -10
- package/dist/store/sqlite/evidence-signature.d.ts +114 -0
- package/dist/store/sqlite/evidence-signature.js +349 -0
- package/dist/store/sqlite/evidence-sources.d.ts +2 -1
- package/dist/store/sqlite/evidence-sources.js +7 -3
- package/dist/store/sqlite/facts.d.ts +7 -2
- package/dist/store/sqlite/facts.js +21 -5
- package/dist/store/sqlite/finance.d.ts +18 -105
- package/dist/store/sqlite/finance.js +100 -219
- package/dist/store/sqlite/knowledge.d.ts +8 -2
- package/dist/store/sqlite/knowledge.js +65 -71
- package/dist/store/sqlite/labelled.d.ts +3 -0
- package/dist/store/sqlite/labelled.js +11 -0
- package/dist/store/sqlite/link-kinds.d.ts +2 -0
- package/dist/store/sqlite/link-kinds.js +2 -0
- package/dist/store/sqlite/manifest.js +2 -0
- package/dist/store/sqlite/memories.d.ts +23 -9
- package/dist/store/sqlite/memories.js +41 -13
- package/dist/store/sqlite/messages.js +2 -0
- package/dist/store/sqlite/migrations.generated.js +103 -0
- package/dist/store/sqlite/money-lines.d.ts +48 -0
- package/dist/store/sqlite/money-lines.js +76 -0
- package/dist/store/sqlite/money-transactions.d.ts +132 -0
- package/dist/store/sqlite/money-transactions.js +295 -0
- package/dist/store/sqlite/notes.d.ts +11 -2
- package/dist/store/sqlite/notes.js +20 -25
- package/dist/store/sqlite/orders.d.ts +36 -6
- package/dist/store/sqlite/orders.js +126 -46
- package/dist/store/sqlite/payment-facts.js +1 -1
- package/dist/store/sqlite/private-people.js +2 -0
- package/dist/store/sqlite/products.d.ts +78 -0
- package/dist/store/sqlite/products.js +131 -0
- package/dist/store/sqlite/project-transfer/records.js +26 -1
- package/dist/store/sqlite/project-transfer/snapshot.js +5 -3
- package/dist/store/sqlite/proposed-actions.d.ts +1 -1
- package/dist/store/sqlite/proposed-actions.js +24 -7
- package/dist/store/sqlite/providers.d.ts +0 -4
- package/dist/store/sqlite/providers.js +20 -2
- package/dist/store/sqlite/record-matching.d.ts +80 -0
- package/dist/store/sqlite/record-matching.js +264 -0
- package/dist/store/sqlite/record-projection.d.ts +89 -0
- package/dist/store/sqlite/record-projection.js +50 -0
- package/dist/store/sqlite/record-projectors-direct.d.ts +17 -0
- package/dist/store/sqlite/record-projectors-direct.js +125 -0
- package/dist/store/sqlite/record-projectors-money.d.ts +26 -0
- package/dist/store/sqlite/record-projectors-money.js +214 -0
- package/dist/store/sqlite/record-projectors-phone.d.ts +28 -0
- package/dist/store/sqlite/record-projectors-phone.js +212 -0
- package/dist/store/sqlite/record-projectors.d.ts +3 -44
- package/dist/store/sqlite/record-projectors.js +7 -67
- package/dist/store/sqlite/record-relations.d.ts +24 -0
- package/dist/store/sqlite/record-relations.js +92 -0
- package/dist/store/sqlite/record-remap.d.ts +12 -0
- package/dist/store/sqlite/record-remap.js +92 -0
- package/dist/store/sqlite/record-run.d.ts +71 -0
- package/dist/store/sqlite/record-run.js +179 -0
- package/dist/store/sqlite/record-settling.d.ts +9 -0
- package/dist/store/sqlite/record-settling.js +74 -0
- package/dist/store/sqlite/record-stamps.d.ts +13 -0
- package/dist/store/sqlite/record-stamps.js +30 -0
- package/dist/store/sqlite/record-writes.d.ts +43 -0
- package/dist/store/sqlite/record-writes.js +307 -0
- package/dist/store/sqlite/records.d.ts +52 -42
- package/dist/store/sqlite/records.js +123 -353
- package/dist/store/sqlite/ref-summaries.d.ts +6 -5
- package/dist/store/sqlite/ref-summaries.js +60 -8
- package/dist/store/sqlite/refunds.d.ts +31 -0
- package/dist/store/sqlite/refunds.js +112 -0
- package/dist/store/sqlite/reviewed.d.ts +109 -0
- package/dist/store/sqlite/reviewed.js +173 -0
- package/dist/store/sqlite/schema.d.ts +2840 -83
- package/dist/store/sqlite/schema.js +256 -1
- package/dist/store/sqlite/source-review-marks.d.ts +54 -0
- package/dist/store/sqlite/source-review-marks.js +143 -0
- package/dist/store/sqlite/source-review.d.ts +54 -0
- package/dist/store/sqlite/source-review.js +221 -0
- package/dist/store/sqlite/stage-amounts.d.ts +14 -0
- package/dist/store/sqlite/stage-amounts.js +23 -0
- package/dist/store/sqlite/subscriptions.d.ts +135 -0
- package/dist/store/sqlite/subscriptions.js +294 -0
- package/dist/store/sqlite/text-input.d.ts +3 -0
- package/dist/store/sqlite/text-input.js +13 -0
- package/dist/store/sqlite/things.js +2 -9
- package/dist/store/sqlite/transaction.d.ts +15 -0
- package/dist/store/sqlite/transaction.js +57 -0
- package/dist/store/sqlite/wallets.d.ts +88 -0
- package/dist/store/sqlite/wallets.js +143 -0
- package/dist/store/store-errors.d.ts +1 -0
- package/dist/store/store-errors.js +45 -0
- package/dist/store/store.d.ts +16 -1
- package/dist/store/store.js +30 -6
- package/package.json +5 -2
- package/schemas/examples/records-business.jsonl +11 -0
- package/schemas/records-envelope.v1.schema.json +1160 -5
package/dist/entities/deal.d.ts
CHANGED
|
@@ -145,6 +145,13 @@ export declare const pipeline: v.StrictObjectSchema<{
|
|
|
145
145
|
/** With a funnel: rows that got this far, and the share of them that reached the next stage. */
|
|
146
146
|
readonly reached: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, undefined>;
|
|
147
147
|
readonly conversion: v.OptionalSchema<v.NullableSchema<v.NumberSchema<undefined>, undefined>, undefined>;
|
|
148
|
+
/** With a funnel: rows standing in it now, and their sum per currency, never converted. */
|
|
149
|
+
readonly items: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, undefined>;
|
|
150
|
+
readonly amounts: v.OptionalSchema<v.ArraySchema<v.StrictObjectSchema<{
|
|
151
|
+
readonly amount: v.StringSchema<undefined>;
|
|
152
|
+
readonly currency: v.StringSchema<undefined>;
|
|
153
|
+
readonly items: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
154
|
+
}, undefined>, undefined>, undefined>;
|
|
148
155
|
}, undefined>, undefined>;
|
|
149
156
|
readonly created_at: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, "an ISO 8601 time in UTC">, v.EndsWithAction<string, "Z", "an ISO 8601 time in UTC, ending in `Z`">]>;
|
|
150
157
|
readonly totals: v.OptionalSchema<v.StrictObjectSchema<{
|
|
@@ -168,6 +175,13 @@ export declare const stage: v.StrictObjectSchema<{
|
|
|
168
175
|
/** With a funnel: rows that got this far, and the share of them that reached the next stage. */
|
|
169
176
|
readonly reached: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, undefined>;
|
|
170
177
|
readonly conversion: v.OptionalSchema<v.NullableSchema<v.NumberSchema<undefined>, undefined>, undefined>;
|
|
178
|
+
/** With a funnel: rows standing in it now, and their sum per currency, never converted. */
|
|
179
|
+
readonly items: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, undefined>;
|
|
180
|
+
readonly amounts: v.OptionalSchema<v.ArraySchema<v.StrictObjectSchema<{
|
|
181
|
+
readonly amount: v.StringSchema<undefined>;
|
|
182
|
+
readonly currency: v.StringSchema<undefined>;
|
|
183
|
+
readonly items: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
184
|
+
}, undefined>, undefined>, undefined>;
|
|
171
185
|
readonly pipeline: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "a reference such as `note:42`">]>;
|
|
172
186
|
readonly pipeline_name: v.StringSchema<undefined>;
|
|
173
187
|
readonly kind: v.PicklistSchema<["deal", "lead"], undefined>;
|
package/dist/entities/deal.js
CHANGED
|
@@ -70,6 +70,9 @@ const pipelineStage = v.strictObject({
|
|
|
70
70
|
/** With a funnel: rows that got this far, and the share of them that reached the next stage. */
|
|
71
71
|
reached: v.optional(count),
|
|
72
72
|
conversion: v.optional(v.nullable(v.number())),
|
|
73
|
+
/** With a funnel: rows standing in it now, and their sum per currency, never converted. */
|
|
74
|
+
items: v.optional(count),
|
|
75
|
+
amounts: v.optional(v.array(v.strictObject({ amount: text, currency: text, items: count }))),
|
|
73
76
|
});
|
|
74
77
|
/** A pipeline (`pipeline:<id>`) with its stages in order; `pipelines show` adds the funnel. */
|
|
75
78
|
export const pipeline = v.strictObject({
|
package/dist/entities/index.d.ts
CHANGED
|
@@ -363,6 +363,12 @@ export declare const ENTITIES: {
|
|
|
363
363
|
readonly open: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
364
364
|
readonly reached: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, undefined>;
|
|
365
365
|
readonly conversion: v.OptionalSchema<v.NullableSchema<v.NumberSchema<undefined>, undefined>, undefined>;
|
|
366
|
+
readonly items: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, undefined>;
|
|
367
|
+
readonly amounts: v.OptionalSchema<v.ArraySchema<v.StrictObjectSchema<{
|
|
368
|
+
readonly amount: v.StringSchema<undefined>;
|
|
369
|
+
readonly currency: v.StringSchema<undefined>;
|
|
370
|
+
readonly items: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
371
|
+
}, undefined>, undefined>, undefined>;
|
|
366
372
|
}, undefined>, undefined>;
|
|
367
373
|
readonly created_at: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, "an ISO 8601 time in UTC">, v.EndsWithAction<string, "Z", "an ISO 8601 time in UTC, ending in `Z`">]>;
|
|
368
374
|
readonly totals: v.OptionalSchema<v.StrictObjectSchema<{
|
|
@@ -383,6 +389,12 @@ export declare const ENTITIES: {
|
|
|
383
389
|
readonly open: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
384
390
|
readonly reached: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, undefined>;
|
|
385
391
|
readonly conversion: v.OptionalSchema<v.NullableSchema<v.NumberSchema<undefined>, undefined>, undefined>;
|
|
392
|
+
readonly items: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, undefined>;
|
|
393
|
+
readonly amounts: v.OptionalSchema<v.ArraySchema<v.StrictObjectSchema<{
|
|
394
|
+
readonly amount: v.StringSchema<undefined>;
|
|
395
|
+
readonly currency: v.StringSchema<undefined>;
|
|
396
|
+
readonly items: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
397
|
+
}, undefined>, undefined>, undefined>;
|
|
386
398
|
readonly pipeline: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "a reference such as `note:42`">]>;
|
|
387
399
|
readonly pipeline_name: v.StringSchema<undefined>;
|
|
388
400
|
readonly kind: v.PicklistSchema<["deal", "lead"], undefined>;
|
package/dist/errors/reasons.js
CHANGED
|
@@ -19,7 +19,8 @@ const SIGN_IN = [
|
|
|
19
19
|
["oauth.declined", "authentication_error", "the provider's consent was declined"],
|
|
20
20
|
["oauth.timeout", "timeout", "the sign-in was not finished in time"],
|
|
21
21
|
["oauth.mismatch", "authentication_error", "the pasted sign-in result belongs to another sign-in"],
|
|
22
|
-
["oauth.missing", "authentication_error", "this profile is not signed in"],
|
|
22
|
+
["oauth.missing", "authentication_error", "this profile is not signed in to the provider"],
|
|
23
|
+
["session.missing", "authentication_error", "this profile has no API token saved"],
|
|
23
24
|
["oauth.locked", "provider_unavailable", "another process holds this sign-in's lock"],
|
|
24
25
|
["oauth.no-response", "outcome_unknown", "the token request did not finish"],
|
|
25
26
|
["oauth.unavailable", "provider_unavailable", "the provider's token endpoint is unavailable"],
|
|
@@ -62,6 +63,11 @@ const OTHERS = [
|
|
|
62
63
|
validation("mail-findings.partial", "a cited email is not stored whole yet; cite it once it is"),
|
|
63
64
|
validation("evidence-findings.dedicated-review", "review evidence findings through the dedicated findings command"),
|
|
64
65
|
validation("mail-findings.dedicated-review", "review mail findings through the dedicated findings command"),
|
|
66
|
+
validation("source-review.dedicated-review", "decide a source review through the review of memories and facts"),
|
|
67
|
+
validation("source-review.reason-required", "a challenge says why in 1–2000 characters"),
|
|
68
|
+
validation("source-review.evidence-required", "a challenge cites 1–20 references that contradict it"),
|
|
69
|
+
validation("source-review.suggestion-length", "a suggestion with a challenge takes 1–2000 characters"),
|
|
70
|
+
validation("source-review.not-holding", "the memory or fact no longer holds, so there is nothing to challenge"),
|
|
65
71
|
validation("mail-findings.invalid", "a checked mail findings batch would be refused; details.problems names why, finding by finding"),
|
|
66
72
|
validation("mail-findings.key-used", "the findings batch key was already used for different input"),
|
|
67
73
|
validation("finding.unknown-field", "a finding has a field its kind does not take"),
|
|
@@ -128,6 +134,21 @@ const OTHERS = [
|
|
|
128
134
|
["feed.gone", "not_found", "the feed's server has no feed at this address any more"],
|
|
129
135
|
["feed.timeout", "timeout", "the feed's server did not answer in time"],
|
|
130
136
|
["feed.unreachable", "network_error", "the feed's server could not be reached"],
|
|
137
|
+
validation("source.url-refused", "the link is not an http or https page on the public internet"),
|
|
138
|
+
["source.url-status", "provider_error", "the page's server answered with an error status"],
|
|
139
|
+
["source.url-timeout", "timeout", "the page did not arrive in time"],
|
|
140
|
+
["source.url-redirects", "provider_error", "the page sent the request on too many times"],
|
|
141
|
+
["source.url-unreachable", "network_error", "the page's server could not be found or reached"],
|
|
142
|
+
[
|
|
143
|
+
"source.needs-sign-in",
|
|
144
|
+
"authentication_error",
|
|
145
|
+
"the page asks for a sign-in; a private Google document is read through Drive",
|
|
146
|
+
],
|
|
147
|
+
validation("source.too-large", "the source is larger than one read takes"),
|
|
148
|
+
validation("source.unsupported", "no reader takes this kind of source"),
|
|
149
|
+
validation("source.no-text", "the source holds no text to keep"),
|
|
150
|
+
validation("source.unreadable", "the reader could not read the source"),
|
|
151
|
+
["source.engine-missing", "configuration_error", "reading this source needs a reader package that is not installed"],
|
|
131
152
|
validation("busy.feed", "a feed calendar has no busy times to ask; read its events with events list"),
|
|
132
153
|
["calendar.unsynced", "not_found", "the calendar account has no synced calendar in the store"],
|
|
133
154
|
["calendar.sync-incomplete", "not_found", "a synced calendar's sync never finished or is mid-round"],
|
|
@@ -185,6 +206,8 @@ const OTHERS = [
|
|
|
185
206
|
["store.vector-extension-failed", "configuration_error", "the sqlite-vec extension did not load; reinstall the CLI"],
|
|
186
207
|
validation("store.vector-invalid", "a vector to store had a non-finite value"),
|
|
187
208
|
validation("catalog.scope-limit", "the selected catalog exceeds its entry limit"),
|
|
209
|
+
validation("evidence.quote-length", "a quote from the evidence is empty or over 500 characters"),
|
|
210
|
+
validation("evidence.quote-not-found", "the cited source does not say the quoted words"),
|
|
188
211
|
validation("evidence.row-too-large", "one evidence row is over its size limit"),
|
|
189
212
|
validation("index.not-ready", "the search index is still being built"),
|
|
190
213
|
validation("input.closed", "the input closed before the answer"),
|
|
@@ -198,18 +221,29 @@ const OTHERS = [
|
|
|
198
221
|
validation("finance.allocate", "the invoice or payment cannot take an allocation in its state"),
|
|
199
222
|
validation("finance.currency", "the payment and the invoice are in different currencies; nothing is converted"),
|
|
200
223
|
validation("finance.field", "a field of the invoice or payment is not valid"),
|
|
201
|
-
validation("finance.line-amount", "
|
|
224
|
+
validation("finance.line-amount", "an invoice line's amount is not its quantity times its unit price"),
|
|
202
225
|
validation("finance.lines", "the invoice's lines are not valid"),
|
|
203
226
|
["finance.not-allocated", "not_found", "the payment is not allocated to that invoice"],
|
|
204
227
|
validation("finance.over-invoice", "the allocation would settle more than the invoice's total"),
|
|
205
228
|
validation("finance.over-payment", "the allocation would use more than the payment's amount"),
|
|
206
229
|
["finance.owner-only", "permission_error", "only the owner does this with money"],
|
|
230
|
+
validation("finance.over-refund", "the refunds would take back more than the payment, or than it gave an invoice"),
|
|
207
231
|
validation("finance.party", "a party is a person: or organization: reference"),
|
|
208
232
|
validation("finance.ref", "the reference names no invoice or payment"),
|
|
233
|
+
validation("finance.refund", "a refund goes the other way in the same currency, of a live payment confirmed first, to an invoice it paid"),
|
|
234
|
+
validation("finance.refunded", "a refund of the payment still stands; reject it or take it back first"),
|
|
209
235
|
validation("finance.status", "the invoice's status does not allow this"),
|
|
210
236
|
validation("finance.total", "the invoice's total is not the sum of its lines"),
|
|
211
237
|
validation("finance.unallocate", "a rejected or deleted payment's allocations are not taken back"),
|
|
212
|
-
validation("record.entity", "the
|
|
238
|
+
validation("record.entity", "the entity or proposal the record stands for was refused"),
|
|
239
|
+
validation("record.provider-not-imported", "SMS and calls are imported only under an import-only provider, such as phone"),
|
|
240
|
+
validation("record.chat", "the chat an SMS names is not an imported one: a sync owns it"),
|
|
241
|
+
validation("record.moved", "an SMS stays in its thread: delete it and send it again under a new external_id"),
|
|
242
|
+
validation("record.phone-region", "a phone without + is read only in the envelope's phone_region; kept as data"),
|
|
243
|
+
validation("record.separated", "the owner told the one entity these identifiers match apart from them"),
|
|
244
|
+
["store.dry-run", "conflict", "a dry run of an import holds the store; the read or write waits for it to end"],
|
|
245
|
+
validation("record.ambiguous", "the record's identifiers point at more than one entity; the owner says which"),
|
|
246
|
+
validation("record.identifier", "a free-mail domain names no organization: anyone has an address there"),
|
|
213
247
|
["record.map-owner-only", "permission_error", "only the owner says which entity a source record is"],
|
|
214
248
|
validation("record.map-type", "a record maps only to an entity of its own type"),
|
|
215
249
|
validation("record.mapped", "the record already stands for another entity"),
|
|
@@ -236,7 +270,7 @@ const OTHERS = [
|
|
|
236
270
|
["pipeline.not-found", "not_found", "no stored pipeline has that name or reference"],
|
|
237
271
|
validation("crm.stage-unknown", "a CRM item stands in a stage the store does not hold; it was not kept"),
|
|
238
272
|
validation("crm.item-invalid", "a CRM item has a field the store refuses, such as a currency it does not keep"),
|
|
239
|
-
validation("crm.pipeline-required", "the CRM has more than one pipeline of the kind; the
|
|
273
|
+
validation("crm.pipeline-required", "the CRM has more than one pipeline of the kind; the command names one"),
|
|
240
274
|
validation("field.unknown", "no custom field of the kind has that code or label; `fields list` lists them"),
|
|
241
275
|
validation("field.ambiguous", "more than one custom field has that label; name one by its code"),
|
|
242
276
|
validation("field.unknown-option", "the list field has no option with that id or label"),
|
|
@@ -250,6 +284,31 @@ const OTHERS = [
|
|
|
250
284
|
validation("crm.own-unknown", "no own company of the CRM account is stored, so its users are no one's employees yet"),
|
|
251
285
|
validation("relationship.reference-unknown", "a reported relationship names something the store does not hold"),
|
|
252
286
|
validation("relationship.invalid", "a reported relationship joins ends or takes a role the registry refuses"),
|
|
287
|
+
validation("contract.field", "a field of the contract is not valid"),
|
|
288
|
+
validation("contract.ref", "the reference names no contract, or no deal for it"),
|
|
289
|
+
validation("order.currency", "the product is priced in another currency than the order"),
|
|
290
|
+
validation("order.line", "an order keeps at least one line: reject or cancel it instead"),
|
|
291
|
+
validation("order.line-amount", "an order line's amount is not its quantity times its unit price"),
|
|
292
|
+
validation("order.lines", "the order's lines are not valid"),
|
|
293
|
+
["order.no-line", "not_found", "the order has no line at that position"],
|
|
294
|
+
["order.owner-only", "permission_error", "only the owner changes a confirmed order's lines"],
|
|
295
|
+
validation("order.total", "an order with lines names its currency and totals their sum"),
|
|
296
|
+
validation("product.duplicate", "a product with that code is already stored for that supplier"),
|
|
297
|
+
validation("product.field", "a field of the product is not valid"),
|
|
298
|
+
validation("product.ref", "the reference names no product"),
|
|
299
|
+
validation("subscription.field", "a field of the subscription is not valid"),
|
|
300
|
+
validation("subscription.interval", "an interval is a count and a unit, such as 1-month"),
|
|
301
|
+
["subscription.no-price", "not_found", "no stored subscription price has that id"],
|
|
302
|
+
validation("subscription.price", "a price is never changed: reject it and add a new one, after its subscription"),
|
|
303
|
+
validation("subscription.ref", "the reference names no subscription, product or contract for it"),
|
|
304
|
+
validation("transaction.field", "a field of the transaction is not valid"),
|
|
305
|
+
validation("transaction.payment", "the payment is not the same money: currency, direction and amount differ"),
|
|
306
|
+
validation("transaction.ref", "the reference names no transaction or wallet"),
|
|
307
|
+
["transaction.no-split", "not_found", "the transaction has no split at that position"],
|
|
308
|
+
validation("transaction.split", "the splits come to more than the transaction, or name no category"),
|
|
309
|
+
validation("wallet.field", "a field of the wallet is not valid"),
|
|
310
|
+
validation("wallet.number", "a wallet keeps only the last 4 characters of a number"),
|
|
311
|
+
validation("wallet.ref", "the reference names no wallet"),
|
|
253
312
|
validation("order.duplicate", "the shop's order with this number is already stored; change its status instead"),
|
|
254
313
|
validation("order.proposed", "the shop's order with this number already waits for the owner in a findings batch"),
|
|
255
314
|
validation("order.field", "a field of the order is not valid"),
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether an IP address is on the public internet: not loopback, private, link-local, CGNAT, ULA, multicast,
|
|
3
|
+
* unspecified, documentation or reserved, nor one of those carried in an IPv6 form (`::ffff:10.0.0.1`).
|
|
4
|
+
*/
|
|
5
|
+
export declare const isPublicAddress: (address: string) => boolean;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { isIP } from "node:net";
|
|
2
|
+
const within = (address, [prefix, bits]) => {
|
|
3
|
+
for (let bit = 0; bit < bits; bit++) {
|
|
4
|
+
const mask = 0x80 >> (bit % 8);
|
|
5
|
+
if (((address[bit >> 3] ?? 0) & mask) !== ((prefix[bit >> 3] ?? 0) & mask))
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
return true;
|
|
9
|
+
};
|
|
10
|
+
/** Not the public internet (RFC 6890 and its updates); 240/4 holds the broadcast address. */
|
|
11
|
+
const V4_PRIVATE = [
|
|
12
|
+
[[0], 8],
|
|
13
|
+
[[10], 8],
|
|
14
|
+
[[100, 64], 10],
|
|
15
|
+
[[127], 8],
|
|
16
|
+
[[169, 254], 16],
|
|
17
|
+
[[172, 16], 12],
|
|
18
|
+
[[192, 0, 0], 24],
|
|
19
|
+
[[192, 0, 2], 24],
|
|
20
|
+
[[192, 88, 99], 24],
|
|
21
|
+
[[192, 168], 16],
|
|
22
|
+
[[198, 18], 15],
|
|
23
|
+
[[198, 51, 100], 24],
|
|
24
|
+
[[203, 0, 113], 24],
|
|
25
|
+
[[224], 4],
|
|
26
|
+
[[240], 4],
|
|
27
|
+
];
|
|
28
|
+
/** Inside global unicast (2000::/3), the blocks that are not the public internet. */
|
|
29
|
+
const V6_PRIVATE = [
|
|
30
|
+
[[0x20, 0x01, 0x00, 0x00], 23],
|
|
31
|
+
[[0x20, 0x01, 0x0d, 0xb8], 32],
|
|
32
|
+
[[0x3f, 0xff], 20],
|
|
33
|
+
];
|
|
34
|
+
/** Forms that carry an IPv4 address, and where it sits: mapped, NAT64 and 6to4. */
|
|
35
|
+
const V6_CARRIERS = [
|
|
36
|
+
[[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff], 96], 12],
|
|
37
|
+
[[[0x00, 0x64, 0xff, 0x9b, 0, 0, 0, 0, 0, 0, 0, 0], 96], 12],
|
|
38
|
+
[[[0x20, 0x02], 16], 2],
|
|
39
|
+
];
|
|
40
|
+
const v4Bytes = (text) => new Uint8Array(text.split(".").map(Number));
|
|
41
|
+
const v6Bytes = (text) => {
|
|
42
|
+
const bytes = new Uint8Array(16);
|
|
43
|
+
let address = text.replace(/%.*$/, "");
|
|
44
|
+
const dotted = /(\d+\.\d+\.\d+\.\d+)$/.exec(address);
|
|
45
|
+
if (dotted?.[1]) {
|
|
46
|
+
const [a, b, c, d] = v4Bytes(dotted[1]);
|
|
47
|
+
address = `${address.slice(0, dotted.index)}${(((a ?? 0) << 8) | (b ?? 0)).toString(16)}:${(((c ?? 0) << 8) | (d ?? 0)).toString(16)}`;
|
|
48
|
+
}
|
|
49
|
+
const [head = "", tail] = address.split("::");
|
|
50
|
+
const groups = (part) => (part ? part.split(":").map((group) => Number.parseInt(group, 16)) : []);
|
|
51
|
+
const left = groups(head);
|
|
52
|
+
const right = tail === undefined ? [] : groups(tail);
|
|
53
|
+
const all = [...left, ...new Array(8 - left.length - right.length).fill(0), ...right];
|
|
54
|
+
all.forEach((group, at) => {
|
|
55
|
+
bytes[at * 2] = group >> 8;
|
|
56
|
+
bytes[at * 2 + 1] = group & 0xff;
|
|
57
|
+
});
|
|
58
|
+
return bytes;
|
|
59
|
+
};
|
|
60
|
+
const publicV4 = (bytes) => !V4_PRIVATE.some((prefix) => within(bytes, prefix));
|
|
61
|
+
/**
|
|
62
|
+
* Whether an IP address is on the public internet: not loopback, private, link-local, CGNAT, ULA, multicast,
|
|
63
|
+
* unspecified, documentation or reserved, nor one of those carried in an IPv6 form (`::ffff:10.0.0.1`).
|
|
64
|
+
*/
|
|
65
|
+
export const isPublicAddress = (address) => {
|
|
66
|
+
const family = isIP(address);
|
|
67
|
+
if (family === 4)
|
|
68
|
+
return publicV4(v4Bytes(address));
|
|
69
|
+
if (family !== 6)
|
|
70
|
+
return false;
|
|
71
|
+
const bytes = v6Bytes(address);
|
|
72
|
+
for (const [prefix, at] of V6_CARRIERS)
|
|
73
|
+
if (within(bytes, prefix))
|
|
74
|
+
return publicV4(bytes.subarray(at, at + 4));
|
|
75
|
+
return within(bytes, [[0x20], 3]) && !V6_PRIVATE.some((prefix) => within(bytes, prefix));
|
|
76
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { LoadEngine, Section } from "../readers/types.js";
|
|
2
|
+
export interface PageLimits {
|
|
3
|
+
/** Bytes of the body as sent: the request asks for no compression, so this is what is read. */
|
|
4
|
+
maxBytes: number;
|
|
5
|
+
/** For the whole read: every redirect and the body. */
|
|
6
|
+
timeoutMs: number;
|
|
7
|
+
redirects: number;
|
|
8
|
+
}
|
|
9
|
+
export declare const PAGE_LIMITS: PageLimits;
|
|
10
|
+
export interface ResolvedAddress {
|
|
11
|
+
address: string;
|
|
12
|
+
family: 4 | 6;
|
|
13
|
+
}
|
|
14
|
+
export type PageLookup = (hostname: string) => Promise<ResolvedAddress[]>;
|
|
15
|
+
export interface PageRequest {
|
|
16
|
+
url: URL;
|
|
17
|
+
/** The checked address the connection must go to, whatever the name resolves to by then. */
|
|
18
|
+
address: ResolvedAddress;
|
|
19
|
+
headers: Readonly<Record<string, string>>;
|
|
20
|
+
signal: AbortSignal;
|
|
21
|
+
}
|
|
22
|
+
export interface PageResponse {
|
|
23
|
+
status: number;
|
|
24
|
+
header(name: string): string | null;
|
|
25
|
+
body: AsyncIterable<Uint8Array>;
|
|
26
|
+
/** Drops the rest of the body and the connection. */
|
|
27
|
+
cancel(): void;
|
|
28
|
+
}
|
|
29
|
+
/** Sends one GET to the pinned address and answers once the headers arrive; follows no redirect. */
|
|
30
|
+
export type PageTransport = (request: PageRequest) => Promise<PageResponse>;
|
|
31
|
+
export interface FetchPageOptions {
|
|
32
|
+
limits?: Partial<PageLimits>;
|
|
33
|
+
signal?: AbortSignal;
|
|
34
|
+
lookup?: PageLookup;
|
|
35
|
+
transport?: PageTransport;
|
|
36
|
+
load?: LoadEngine;
|
|
37
|
+
}
|
|
38
|
+
export interface FetchedPage {
|
|
39
|
+
/** The address as given: what a caller keeps as the source's address. */
|
|
40
|
+
requestedUrl: string;
|
|
41
|
+
/** Where the redirects ended; it may carry a token a redirect signed, so it is never stored or logged. */
|
|
42
|
+
finalUrl: string;
|
|
43
|
+
status: number;
|
|
44
|
+
contentType: string | null;
|
|
45
|
+
bytes: number;
|
|
46
|
+
/** Empty when `read` is `no-text`: an image, whose words a reader of the owner's choice may read later. */
|
|
47
|
+
text: string;
|
|
48
|
+
extractor: string | null;
|
|
49
|
+
read: "extracted" | "no-text";
|
|
50
|
+
/** The reader kept only the first part of the text. */
|
|
51
|
+
truncated: boolean;
|
|
52
|
+
metadata?: Record<string, string | string[]>;
|
|
53
|
+
sections?: Section[];
|
|
54
|
+
}
|
|
55
|
+
/** Names the tool, never the owner. */
|
|
56
|
+
export declare const PAGE_USER_AGENT = "Mozilla/5.0 (compatible; WireCat)";
|
|
57
|
+
/** node's own client, so the connection goes to the checked address and the TLS name stays the page's. */
|
|
58
|
+
export declare const nodeTransport: PageTransport;
|
|
59
|
+
/**
|
|
60
|
+
* One page read from the internet, for a source the owner adds by hand: http(s) only, every hop's address checked to
|
|
61
|
+
* be public and connected to as checked, at most `redirects` redirects followed by hand, no cookies, no credentials,
|
|
62
|
+
* and the reader chosen by the content type. Errors name the host only: an address may carry a token.
|
|
63
|
+
*/
|
|
64
|
+
export declare const fetchPage: (address: string, options?: FetchPageOptions) => Promise<FetchedPage>;
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import { lookup as dnsLookup } from "node:dns/promises";
|
|
2
|
+
import { request as httpRequest } from "node:http";
|
|
3
|
+
import { request as httpsRequest } from "node:https";
|
|
4
|
+
import { isIP } from "node:net";
|
|
5
|
+
import { CliError, isCliError } from "@wirecat/cli-base";
|
|
6
|
+
import { importEngine } from "../attachments/extract.js";
|
|
7
|
+
import { MAX_FILE_BYTES } from "../attachments/limits.js";
|
|
8
|
+
import { isGoogleDocumentHost } from "../domain/google-documents.js";
|
|
9
|
+
import { timeLimit } from "../http/time-limit.js";
|
|
10
|
+
import { readWithRegistry } from "../readers/registry.js";
|
|
11
|
+
import { isPublicAddress } from "./addresses.js";
|
|
12
|
+
export const PAGE_LIMITS = { maxBytes: MAX_FILE_BYTES, timeoutMs: 30_000, redirects: 5 };
|
|
13
|
+
/** Names the tool, never the owner. */
|
|
14
|
+
export const PAGE_USER_AGENT = "Mozilla/5.0 (compatible; WireCat)";
|
|
15
|
+
const HEADERS = {
|
|
16
|
+
"user-agent": PAGE_USER_AGENT,
|
|
17
|
+
accept: "text/html,application/xhtml+xml,application/pdf;q=0.9,text/plain;q=0.9,*/*;q=0.5",
|
|
18
|
+
"accept-encoding": "identity",
|
|
19
|
+
};
|
|
20
|
+
const REDIRECTS = new Set([301, 302, 303, 307, 308]);
|
|
21
|
+
const refused = (message) => new CliError("validation_error", message, { reason: "source.url-refused" });
|
|
22
|
+
/** The address checked for its scheme and login: what every hop is checked by. */
|
|
23
|
+
const pageUrl = (address, base) => {
|
|
24
|
+
let url;
|
|
25
|
+
try {
|
|
26
|
+
url = new URL(address, base);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
throw refused("the link is not an address");
|
|
30
|
+
}
|
|
31
|
+
if (url.protocol !== "http:" && url.protocol !== "https:")
|
|
32
|
+
throw refused(`only http and https pages are read, not ${url.protocol.replace(/:$/, "")}`);
|
|
33
|
+
if (url.username || url.password)
|
|
34
|
+
throw refused("a link with a user name or password in it is not read");
|
|
35
|
+
return url;
|
|
36
|
+
};
|
|
37
|
+
const systemLookup = async (hostname) => (await dnsLookup(hostname, { all: true, verbatim: true })).map(({ address, family }) => ({
|
|
38
|
+
address,
|
|
39
|
+
family: family === 6 ? 6 : 4,
|
|
40
|
+
}));
|
|
41
|
+
/** Every address the name has must be public: the first is the one connected to. */
|
|
42
|
+
const checkedAddress = async (url, lookup) => {
|
|
43
|
+
const host = url.hostname.replace(/^\[(.*)\]$/, "$1");
|
|
44
|
+
const family = isIP(host);
|
|
45
|
+
let found;
|
|
46
|
+
try {
|
|
47
|
+
found = family ? [{ address: host, family: family === 6 ? 6 : 4 }] : await lookup(host);
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
throw new CliError("network_error", `${url.hostname} could not be found`, {
|
|
51
|
+
reason: "source.url-unreachable",
|
|
52
|
+
retryable: true,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
const [first] = found;
|
|
56
|
+
if (!first || found.some(({ address }) => !isPublicAddress(address)))
|
|
57
|
+
throw refused(`${url.hostname} is not on the public internet, so it is not read`);
|
|
58
|
+
return first;
|
|
59
|
+
};
|
|
60
|
+
const pinnedTo = ({ address, family }) => (_hostname, options, callback) => {
|
|
61
|
+
if (options.all)
|
|
62
|
+
callback(null, [{ address, family }]);
|
|
63
|
+
else
|
|
64
|
+
callback(null, address, family);
|
|
65
|
+
};
|
|
66
|
+
const headerOf = (message) => (name) => {
|
|
67
|
+
const value = message.headers[name.toLowerCase()];
|
|
68
|
+
return Array.isArray(value) ? value.join(", ") : (value ?? null);
|
|
69
|
+
};
|
|
70
|
+
/** node's own client, so the connection goes to the checked address and the TLS name stays the page's. */
|
|
71
|
+
export const nodeTransport = ({ url, address, headers, signal }) => new Promise((resolve, reject) => {
|
|
72
|
+
const send = url.protocol === "https:" ? httpsRequest : httpRequest;
|
|
73
|
+
const request = send(url, { method: "GET", headers, signal, agent: false, lookup: pinnedTo(address) }, (message) => resolve({
|
|
74
|
+
status: message.statusCode ?? 0,
|
|
75
|
+
header: headerOf(message),
|
|
76
|
+
body: message,
|
|
77
|
+
cancel: () => message.destroy(),
|
|
78
|
+
}));
|
|
79
|
+
request.on("error", reject);
|
|
80
|
+
request.end();
|
|
81
|
+
});
|
|
82
|
+
const tooLarge = (limit) => new CliError("validation_error", `the page is larger than ${Math.round(limit / 1024 / 1024)} MiB`, {
|
|
83
|
+
reason: "source.too-large",
|
|
84
|
+
});
|
|
85
|
+
const readBody = async (response, limit) => {
|
|
86
|
+
const declared = Number(response.header("content-length"));
|
|
87
|
+
if (Number.isFinite(declared) && declared > limit) {
|
|
88
|
+
response.cancel();
|
|
89
|
+
throw tooLarge(limit);
|
|
90
|
+
}
|
|
91
|
+
const chunks = [];
|
|
92
|
+
let size = 0;
|
|
93
|
+
for await (const chunk of response.body) {
|
|
94
|
+
size += chunk.byteLength;
|
|
95
|
+
if (size > limit) {
|
|
96
|
+
response.cancel();
|
|
97
|
+
throw tooLarge(limit);
|
|
98
|
+
}
|
|
99
|
+
chunks.push(chunk);
|
|
100
|
+
}
|
|
101
|
+
const bytes = new Uint8Array(size);
|
|
102
|
+
let at = 0;
|
|
103
|
+
for (const chunk of chunks) {
|
|
104
|
+
bytes.set(chunk, at);
|
|
105
|
+
at += chunk.byteLength;
|
|
106
|
+
}
|
|
107
|
+
return bytes;
|
|
108
|
+
};
|
|
109
|
+
const needsSignIn = (url) => new CliError("authentication_error", `${url.hostname} asks for a sign-in: read a private Google document through Drive`, {
|
|
110
|
+
reason: "source.needs-sign-in",
|
|
111
|
+
});
|
|
112
|
+
/**
|
|
113
|
+
* Google's sign-in page, as a private document may answer with 200: a form that posts to accounts.google.com's sign-in.
|
|
114
|
+
* Only both markers together count, so a page that merely links to a sign-in is read.
|
|
115
|
+
*/
|
|
116
|
+
const isSignInPage = (bytes, contentType) => {
|
|
117
|
+
if (!contentType?.toLowerCase().includes("html"))
|
|
118
|
+
return false;
|
|
119
|
+
const head = new TextDecoder().decode(bytes.subarray(0, 256 * 1024));
|
|
120
|
+
return /<form[^>]+action="https:\/\/accounts\.google\.com\/[^"]*/i.test(head) && /ServiceLogin|\/signin\//.test(head);
|
|
121
|
+
};
|
|
122
|
+
const nameOf = (url) => {
|
|
123
|
+
const raw = url.pathname.split("/").pop() ?? "";
|
|
124
|
+
let last = raw;
|
|
125
|
+
try {
|
|
126
|
+
last = decodeURIComponent(raw);
|
|
127
|
+
}
|
|
128
|
+
catch { }
|
|
129
|
+
return last || null;
|
|
130
|
+
};
|
|
131
|
+
const readPage = async (bytes, url, contentType, load, signal) => {
|
|
132
|
+
const mime = contentType?.split(";")[0]?.trim().toLowerCase() || null;
|
|
133
|
+
const found = await readWithRegistry(bytes, { kind: "file", name: nameOf(url), mime, path: url.pathname }, { load, signal });
|
|
134
|
+
switch (found.status) {
|
|
135
|
+
case "extracted":
|
|
136
|
+
if (!found.text.trim())
|
|
137
|
+
throw new CliError("validation_error", "the page holds no text to keep", { reason: "source.no-text" });
|
|
138
|
+
return {
|
|
139
|
+
text: found.text,
|
|
140
|
+
extractor: found.extractor,
|
|
141
|
+
read: "extracted",
|
|
142
|
+
truncated: found.truncated ?? false,
|
|
143
|
+
...(found.metadata ? { metadata: found.metadata } : {}),
|
|
144
|
+
...(found.sections ? { sections: found.sections } : {}),
|
|
145
|
+
};
|
|
146
|
+
case "needs-agent":
|
|
147
|
+
return { text: "", extractor: found.extractor ?? null, read: "no-text", truncated: false };
|
|
148
|
+
case "unsupported":
|
|
149
|
+
throw new CliError("validation_error", `no reader takes ${mime ?? "this kind of page"}`, {
|
|
150
|
+
reason: "source.unsupported",
|
|
151
|
+
});
|
|
152
|
+
case "unreadable":
|
|
153
|
+
throw new CliError("validation_error", `the ${found.extractor} reader could not read the page`, {
|
|
154
|
+
reason: "source.unreadable",
|
|
155
|
+
});
|
|
156
|
+
case "engine-missing":
|
|
157
|
+
throw new CliError("configuration_error", `reading this page needs ${found.engine}, which is not installed`, {
|
|
158
|
+
reason: "source.engine-missing",
|
|
159
|
+
});
|
|
160
|
+
case "too-large":
|
|
161
|
+
throw new CliError("validation_error", "the page is larger than its reader reads", { reason: "source.too-large" });
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
/**
|
|
165
|
+
* One page read from the internet, for a source the owner adds by hand: http(s) only, every hop's address checked to
|
|
166
|
+
* be public and connected to as checked, at most `redirects` redirects followed by hand, no cookies, no credentials,
|
|
167
|
+
* and the reader chosen by the content type. Errors name the host only: an address may carry a token.
|
|
168
|
+
*/
|
|
169
|
+
export const fetchPage = async (address, options = {}) => {
|
|
170
|
+
const limits = { ...PAGE_LIMITS, ...options.limits };
|
|
171
|
+
const { lookup = systemLookup, transport = nodeTransport, load = importEngine } = options;
|
|
172
|
+
const deadline = timeLimit(limits.timeoutMs);
|
|
173
|
+
const signal = options.signal ? AbortSignal.any([options.signal, deadline.signal]) : deadline.signal;
|
|
174
|
+
const timedOut = () => new CliError("timeout", `the page did not arrive within ${Math.round(limits.timeoutMs / 1000)} s`, {
|
|
175
|
+
reason: "source.url-timeout",
|
|
176
|
+
retryable: true,
|
|
177
|
+
});
|
|
178
|
+
const cancelled = new Promise((_, reject) => {
|
|
179
|
+
const stop = () => reject(signal.reason);
|
|
180
|
+
if (signal.aborted)
|
|
181
|
+
stop();
|
|
182
|
+
else
|
|
183
|
+
signal.addEventListener("abort", stop, { once: true });
|
|
184
|
+
});
|
|
185
|
+
cancelled.catch(() => { });
|
|
186
|
+
let url = pageUrl(address);
|
|
187
|
+
const requested = url.href;
|
|
188
|
+
const google = isGoogleDocumentHost(url.hostname);
|
|
189
|
+
try {
|
|
190
|
+
for (let hop = 0;; hop++) {
|
|
191
|
+
const pinned = await Promise.race([checkedAddress(url, lookup), cancelled]);
|
|
192
|
+
const response = await Promise.race([transport({ url, address: pinned, headers: HEADERS, signal }), cancelled]);
|
|
193
|
+
const location = response.header("location");
|
|
194
|
+
if (REDIRECTS.has(response.status) && location) {
|
|
195
|
+
response.cancel();
|
|
196
|
+
const next = pageUrl(location, url);
|
|
197
|
+
if (google && next.hostname === "accounts.google.com")
|
|
198
|
+
throw needsSignIn(url);
|
|
199
|
+
if (url.protocol === "https:" && next.protocol === "http:")
|
|
200
|
+
throw new CliError("validation_error", `${url.hostname} sent the request on from https to plain http`, {
|
|
201
|
+
reason: "source.url-refused",
|
|
202
|
+
kind: "downgrade",
|
|
203
|
+
});
|
|
204
|
+
if (hop >= limits.redirects)
|
|
205
|
+
throw new CliError("provider_error", `${url.hostname} sent the request on more than ${limits.redirects} times`, {
|
|
206
|
+
reason: "source.url-redirects",
|
|
207
|
+
});
|
|
208
|
+
url = next;
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
if (google && (response.status === 401 || response.status === 403)) {
|
|
212
|
+
response.cancel();
|
|
213
|
+
throw needsSignIn(url);
|
|
214
|
+
}
|
|
215
|
+
if (response.status < 200 || response.status > 299) {
|
|
216
|
+
response.cancel();
|
|
217
|
+
throw new CliError("provider_error", `${url.hostname} answered HTTP ${response.status}`, {
|
|
218
|
+
reason: "source.url-status",
|
|
219
|
+
status: response.status,
|
|
220
|
+
retryable: response.status >= 500 || response.status === 429,
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
const contentType = response.header("content-type");
|
|
224
|
+
const bytes = await Promise.race([readBody(response, limits.maxBytes), cancelled]);
|
|
225
|
+
if (google && isSignInPage(bytes, contentType))
|
|
226
|
+
throw needsSignIn(url);
|
|
227
|
+
const page = await Promise.race([readPage(bytes, url, contentType, load, signal), cancelled]);
|
|
228
|
+
return {
|
|
229
|
+
requestedUrl: requested,
|
|
230
|
+
finalUrl: url.href,
|
|
231
|
+
status: response.status,
|
|
232
|
+
contentType,
|
|
233
|
+
bytes: bytes.byteLength,
|
|
234
|
+
...page,
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
catch (error) {
|
|
239
|
+
if (deadline.signal.aborted && !(isCliError(error) && error.code !== "cancelled"))
|
|
240
|
+
throw timedOut();
|
|
241
|
+
if (isCliError(error))
|
|
242
|
+
throw error;
|
|
243
|
+
if (options.signal?.aborted)
|
|
244
|
+
throw new CliError("cancelled", "reading the page was cancelled");
|
|
245
|
+
// The cause's code only: a fetch error's message may quote the address.
|
|
246
|
+
const cause = error.code ??
|
|
247
|
+
error.cause?.code;
|
|
248
|
+
throw new CliError("network_error", `${url.hostname} could not be reached${typeof cause === "string" ? ` (${cause})` : ""}`, {
|
|
249
|
+
reason: "source.url-unreachable",
|
|
250
|
+
retryable: true,
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
finally {
|
|
254
|
+
deadline.clear();
|
|
255
|
+
}
|
|
256
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { CATALOG_KINDS, type CatalogKind, CONTRACT_KINDS, CONTRACT_STATUSES, type ContractKind, type ContractStatus, type Interval, intervalOf, intervalText, ORDER_DIRECTIONS, type OrderDirection, PERIOD_UNITS, type PeriodUnit, SUBSCRIPTION_STATUSES, type SubscriptionStatus, TRANSACTION_STATUSES, type TransactionStatus, WALLET_KINDS, type WalletKind, } from "./domain/business.js";
|
|
1
2
|
export { bareCheck, type CheckWords, checkWords } from "./domain/checks.js";
|
|
2
3
|
export type { CounterField, CounterObservation, CounterObservations, CounterState } from "./domain/counters.js";
|
|
3
4
|
export { COUNTER_FIELDS, counterValue, observedCounters } from "./domain/counters.js";
|
|
@@ -10,17 +11,18 @@ export { type Markup, parseMarkdown } from "./domain/markdown.js";
|
|
|
10
11
|
export { parseMarkdownSpans } from "./domain/markdown-spans.js";
|
|
11
12
|
export type { MessageLink, MessagePermalink } from "./domain/message-link.js";
|
|
12
13
|
export type * from "./domain/models.js";
|
|
13
|
-
export { CURRENCY_SCALES, currencyOf, type Money, minorUnits, moneyLabel, moneyOf, } from "./domain/money.js";
|
|
14
|
+
export { CURRENCY_SCALES, currencyOf, formatDecimal, type Money, minorUnits, moneyLabel, moneyOf, signedMinorUnits, } from "./domain/money.js";
|
|
14
15
|
export { ORDER_PURPOSES, ORDER_STATUSES, type OrderPurpose, type OrderStatus, } from "./domain/orders.js";
|
|
15
16
|
export { countedPoll } from "./domain/polls.js";
|
|
16
|
-
export { CRM_OPENS, FOLDER_PROVIDERS, isFolderProvider, isKind, KINDS, type Kind, kindIn, kindOf, PROVIDERS, type ProviderEntry, providerNamed, providers, UNKNOWN_PROVIDER, useProviders, } from "./domain/providers.js";
|
|
17
|
+
export { ADDED_ACCOUNT, ADDED_PROVIDER, CRM_OPENS, FOLDER_PROVIDERS, holdsKind, isFolderProvider, isKind, KINDS, type Kind, kindIn, kindOf, kindsIn, PROVIDERS, type ProviderEntry, providerNamed, providers, UNKNOWN_PROVIDER, useProviders, } from "./domain/providers.js";
|
|
17
18
|
export type { RankingGraphEvidence, RankingGraphLink } from "./domain/rankings-graph.js";
|
|
18
19
|
export type { RankingComponent, RankingInput, RankingMeasure, RankingOptions, RankingTarget, RankingWeights, ScorePreset, } from "./domain/rankings-options.js";
|
|
19
20
|
export { rankingOptions } from "./domain/rankings-options.js";
|
|
20
|
-
export { type EnvelopeRecord, type EnvelopeSource, envelopeOfJsonl, type IngestError, RECORD_ENTITY_TYPES, RECORD_OPERATIONS, RECORDS_ENVELOPE_SCHEMA, RECORDS_SCHEMA_VERSION, type RecordEntityType, type RecordOperation, type RecordRelation, type RecordsEnvelope, } from "./domain/records.js";
|
|
21
|
+
export { type EnvelopeOptions, type EnvelopeRecord, type EnvelopeSource, envelopeOfJsonl, envelopeOfText, type IngestError, RECORD_ENTITY_TYPES, RECORD_OPERATIONS, RECORDS_ENVELOPE_SCHEMA, RECORDS_SCHEMA_VERSION, type RecordEntityType, type RecordOperation, type RecordRelation, type RecordsEnvelope, } from "./domain/records.js";
|
|
21
22
|
export { canonicalReference, formatReference, looksLikeReference, parseReference, REF_KINDS, type Reference, type RefKindName, type RefKindSpec, } from "./domain/references.js";
|
|
22
23
|
export { inverseOf, isUsable, ORGANIZATION_ROLES, PROJECT_ROLES, RELATION_KINDS, RELATIONS, type RelationKind, ROLE_LISTS, type RoleList, rolesOf, STANDINGS, type Standing, standingOf, usableLink, } from "./domain/relations.js";
|
|
23
24
|
export { normalizeTag, TAG_TYPES, type TagType } from "./domain/tags.js";
|
|
25
|
+
export { envelopeOfVcard, isVcard, type VcardIssue, type VcardOptions } from "./domain/vcard.js";
|
|
24
26
|
export { type AppErrors, DETAILS as CORE_DETAILS, failureContext, REASONS as CORE_REASONS } from "./errors/reasons.js";
|
|
25
27
|
export { canonicalMeetingReference, formatMeetingReference, type MeetingReference, parseMeetingReference, } from "./meetings/index.js";
|
|
26
28
|
export type { CheckRow, Finding, Moderator } from "./moderation/check.js";
|