@nymbalhq/platform 1.3.0 → 1.5.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/{chunk-QN56IB4G.js → chunk-NNDIAIT6.js} +187 -5
- package/dist/chunk-NNDIAIT6.js.map +1 -0
- package/dist/{chunk-2PLYK5RU.js → chunk-TRLERRUI.js} +3559 -509
- package/dist/chunk-TRLERRUI.js.map +1 -0
- package/dist/db/schema/index.d.ts +5276 -3224
- package/dist/db/schema/index.js +1 -1
- package/dist/index.d.ts +428 -81
- package/dist/index.js +1200 -2254
- package/dist/index.js.map +1 -1
- package/dist/register-SBGUI2L5.js +8 -0
- package/migrations/postgres/0013_order_access_keys.sql +11 -0
- package/migrations/postgres/0014_alert_subscriptions.sql +22 -0
- package/migrations/postgres/0015_events_retry_at.sql +1 -0
- package/migrations/postgres/0016_email_suppressions.sql +7 -0
- package/migrations/postgres/0017_order_shipments.sql +14 -0
- package/migrations/postgres/0018_order_key_expiry.sql +8 -0
- package/migrations/postgres/meta/0013_snapshot.json +2000 -0
- package/migrations/postgres/meta/0014_snapshot.json +2185 -0
- package/migrations/postgres/meta/0015_snapshot.json +2191 -0
- package/migrations/postgres/meta/0016_snapshot.json +2233 -0
- package/migrations/postgres/meta/0017_snapshot.json +2300 -0
- package/migrations/postgres/meta/0018_snapshot.json +2306 -0
- package/migrations/postgres/meta/_journal.json +42 -0
- package/migrations/sqlite/0013_order_access_keys.sql +11 -0
- package/migrations/sqlite/0014_alert_subscriptions.sql +22 -0
- package/migrations/sqlite/0015_events_retry_at.sql +1 -0
- package/migrations/sqlite/0016_email_suppressions.sql +7 -0
- package/migrations/sqlite/0017_order_shipments.sql +9 -0
- package/migrations/sqlite/0018_order_key_expiry.sql +25 -0
- package/migrations/sqlite/meta/0013_snapshot.json +1788 -0
- package/migrations/sqlite/meta/0014_snapshot.json +1931 -0
- package/migrations/sqlite/meta/0015_snapshot.json +1938 -0
- package/migrations/sqlite/meta/0016_snapshot.json +1981 -0
- package/migrations/sqlite/meta/0017_snapshot.json +2041 -0
- package/migrations/sqlite/meta/0018_snapshot.json +2048 -0
- package/migrations/sqlite/meta/_journal.json +42 -0
- package/package.json +17 -47
- package/dist/chunk-2PLYK5RU.js.map +0 -1
- package/dist/chunk-QN56IB4G.js.map +0 -1
- package/dist/register-UUQ64HZP.js +0 -8
- /package/dist/{register-UUQ64HZP.js.map → register-SBGUI2L5.js.map} +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NymbalConfig } from '@nymbalhq/config';
|
|
2
|
-
import { Logger, DocumentStoreAdapter, EventBusAdapter, MediaStorage, Product, ProductStatus, ProductType, ProductMedia, Variant, VariantDimensions, VariantOption, VariantStatus, Category, Customer, Role, CustomerAddress, Order, OrderStatus, Address, OrderLineItem, CaptureMethod, OrderHistoryEntry, OrderRefundStatus, OrderRefund, InventoryReservation, StockAdjustmentReason, StockAdjustment, Review, ReviewModerationStatus, NymbalEvent, Cart, AuditSubject, AuditActor, AuditOutcome, AuditEntry, HealthReport, PutOptions, QueryParams, QueryResult, EventHandler, SubscriptionConfig, Subscription, NymbalEnvironment, NymbalEventType, NymbalEventMap, RequestAuth, AdapterSetting, CommerceSlotAdapters, SecurityAdapter, AiAdapter, PaymentsAdapter, ProductSnapshot, CartItem, StockStatus, PaymentIntent, CheckoutPayment, SearchParams, SearchResult, SearchAdapter, OrderPayment, Refund, CommerceSlot, HttpAdapter, Slot, ProviderPackageModule, RateLimitAction,
|
|
2
|
+
import { Logger, DocumentStoreAdapter, EventBusAdapter, MediaStorage, Product, ProductStatus, ProductType, ProductMedia, Variant, VariantDimensions, VariantOption, VariantStatus, Category, Customer, Role, CustomerAddress, Order, OrderStatus, Address, OrderLineItem, CaptureMethod, OrderHistoryEntry, OrderRefundStatus, OrderRefund, InventoryReservation, StockAdjustmentReason, StockAdjustment, Review, ReviewModerationStatus, NymbalEvent, Cart, AuditSubject, AuditActor, AuditOutcome, AuditEntry, AlertKind, AlertStatus, HealthReport, PutOptions, QueryParams, QueryResult, EventHandler, SubscriptionConfig, Subscription, NymbalEnvironment, NymbalEventType, NymbalEventMap, RequestAuth, AdapterSetting, CommerceSlotAdapters, SecurityAdapter, AiAdapter, PaymentsAdapter, EmailAdapter, ProductSnapshot, CartItem, StockStatus, PaymentIntent, CheckoutPayment, SearchParams, SearchResult, SearchAdapter, OrderPayment, Refund, RecentViewer, CommerceSlot, HttpAdapter, Slot, ProviderPackageModule, RateLimitAction, ReviewsAdapter, AnalyticsAdapter, ShippingAdapter, TaxAdapter, HealthStatus } from '@nymbalhq/types';
|
|
3
3
|
export { MediaStorage, buildSecurityHeaders, isValidCorrelationId } from '@nymbalhq/types';
|
|
4
4
|
import BetterSqlite3 from 'better-sqlite3';
|
|
5
5
|
import pg from 'pg';
|
|
@@ -104,7 +104,9 @@ declare const REDIS_DEFAULTS: {
|
|
|
104
104
|
};
|
|
105
105
|
/**
|
|
106
106
|
* The document store, event bus and media storage the config names. A primitive that lives in its own package is
|
|
107
|
-
* imported only when named
|
|
107
|
+
* imported only when named, from its block's `package` or `@nymbalhq/<slot>-<provider>`; a missing package fails
|
|
108
|
+
* `adapter.package_missing` with the install line. A provider whose connection the kernel does not build gets its
|
|
109
|
+
* block's `config`.
|
|
108
110
|
*/
|
|
109
111
|
declare function resolvePrimitives(config: NymbalConfig, options?: ResolvePrimitivesOptions): Promise<Primitives>;
|
|
110
112
|
declare function createPlatform(config: NymbalConfig, options: CreatePlatformOptions): Platform;
|
|
@@ -113,6 +115,17 @@ interface MigrateOptions {
|
|
|
113
115
|
migrationsRoot?: string;
|
|
114
116
|
}
|
|
115
117
|
declare function runMigrations(store: CommandStore, options?: MigrateOptions): Promise<void>;
|
|
118
|
+
interface MigrationState {
|
|
119
|
+
/** Rows in the store's migrations table. */
|
|
120
|
+
applied: number;
|
|
121
|
+
/** Journal entries `runMigrations` would apply. */
|
|
122
|
+
pending: number;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* What `runMigrations` would do to `store`, read without writing. Drizzle applies every journal entry created after the
|
|
126
|
+
* newest one its table records, so that is what counts as pending; a store with no table has every entry pending.
|
|
127
|
+
*/
|
|
128
|
+
declare function migrationState(store: CommandStore, options?: MigrateOptions): Promise<MigrationState>;
|
|
116
129
|
|
|
117
130
|
interface ProductInsert$1 {
|
|
118
131
|
id: string;
|
|
@@ -485,6 +498,28 @@ interface OrderSequenceRepository extends StoreRepository {
|
|
|
485
498
|
}
|
|
486
499
|
declare function createOrderSequenceRepository(store: CommandStore): OrderSequenceRepository;
|
|
487
500
|
|
|
501
|
+
/** Who minted the key: a checkout answer, or the order-placed email. */
|
|
502
|
+
type OrderAccessKeyPurpose = 'checkout' | 'email';
|
|
503
|
+
/** What a key does for an order: opens it, has expired, or is not one of its keys. */
|
|
504
|
+
type OrderKeyState = 'open' | 'expired' | 'none';
|
|
505
|
+
interface OrderAccessKeyInsert {
|
|
506
|
+
id: string;
|
|
507
|
+
orderId: string;
|
|
508
|
+
/** sha256 hex of the key; the key itself is never stored. */
|
|
509
|
+
keyHash: string;
|
|
510
|
+
purpose: OrderAccessKeyPurpose;
|
|
511
|
+
createdAt: Date;
|
|
512
|
+
expiresAt: Date;
|
|
513
|
+
}
|
|
514
|
+
interface OrderAccessKeyRepository extends StoreRepository {
|
|
515
|
+
insert(tx: Tx, k: OrderAccessKeyInsert): Promise<void>;
|
|
516
|
+
/** What a key with this hash does for this order at `now`: another order's key is `none` here. */
|
|
517
|
+
opens(tx: ReadTx, orderId: string, keyHash: string, now: Date): Promise<OrderKeyState>;
|
|
518
|
+
/** Deletes the order's oldest keys of `purpose`, by `(created_at, id)`, until at most `keep` remain. */
|
|
519
|
+
keepNewest(tx: Tx, orderId: string, purpose: OrderAccessKeyPurpose, keep: number): Promise<void>;
|
|
520
|
+
}
|
|
521
|
+
declare function createOrderAccessKeyRepository(store: CommandStore): OrderAccessKeyRepository;
|
|
522
|
+
|
|
488
523
|
interface ReservationInsert {
|
|
489
524
|
reservationId: string;
|
|
490
525
|
variantId: string;
|
|
@@ -558,6 +593,11 @@ interface ProcessedEventRepository extends StoreRepository {
|
|
|
558
593
|
seen(tx: ReadTx, handlerName: string, eventId: string): Promise<boolean>;
|
|
559
594
|
/** Idempotent on (handlerName, eventId): a second call keeps the first record. */
|
|
560
595
|
markProcessed(tx: Tx, handlerName: string, eventId: string, at: Date): Promise<void>;
|
|
596
|
+
/**
|
|
597
|
+
* Records (handlerName, eventId) before its work runs: true when this call inserted it, false when it was there.
|
|
598
|
+
* On Postgres a concurrent claim of the same key waits for this transaction, so only one of them does the work.
|
|
599
|
+
*/
|
|
600
|
+
claim(tx: Tx, handlerName: string, eventId: string, at: Date): Promise<boolean>;
|
|
561
601
|
/** Deletes records processed before `at`; returns how many. */
|
|
562
602
|
deleteBefore(tx: Tx, at: Date): Promise<number>;
|
|
563
603
|
}
|
|
@@ -590,11 +630,24 @@ interface EventLogFilter {
|
|
|
590
630
|
interface EventLogRepository extends StoreRepository {
|
|
591
631
|
/** Appends in array order, so `seq` follows publish order. */
|
|
592
632
|
append(tx: Tx, events: NymbalEvent<unknown>[]): Promise<void>;
|
|
593
|
-
/**
|
|
594
|
-
|
|
633
|
+
/**
|
|
634
|
+
* Neither delivered nor dead, by `seq`; `afterSeq` pages through one pass without re-reading rows it just tried.
|
|
635
|
+
* Given `now`, a row whose `retry_at` is after it is left out.
|
|
636
|
+
*/
|
|
637
|
+
listUndelivered(tx: ReadTx, limit: number, afterSeq?: number, now?: Date): Promise<LoggedEvent[]>;
|
|
595
638
|
markDelivered(tx: Tx, ids: string[], at: Date): Promise<void>;
|
|
596
|
-
/**
|
|
597
|
-
|
|
639
|
+
/**
|
|
640
|
+
* One more failed attempt; the event is dead (`dead_at = at`) once its attempts reach `maxAttempts`. `retryAt`, when
|
|
641
|
+
* given, is the earliest the next attempt may be made.
|
|
642
|
+
*/
|
|
643
|
+
recordFailure(tx: Tx, id: string, at: Date, maxAttempts: number, retryAt?: Date): Promise<void>;
|
|
644
|
+
/** A delivery that failed during an adapter outage: only the earliest next attempt moves, nothing is counted. */
|
|
645
|
+
recordOutage(tx: Tx, id: string, retryAt: Date): Promise<void>;
|
|
646
|
+
countDead(tx: ReadTx): Promise<number>;
|
|
647
|
+
/** Dead events, oldest first. */
|
|
648
|
+
listDead(tx: ReadTx, limit: number): Promise<LoggedEvent[]>;
|
|
649
|
+
/** Neither delivered nor dead, with at least one failed attempt. */
|
|
650
|
+
countRetrying(tx: ReadTx): Promise<number>;
|
|
598
651
|
/** Deletes delivered events delivered before `at`; returns how many. Undelivered and dead events are never deleted. */
|
|
599
652
|
deleteDeliveredBefore(tx: Tx, at: Date): Promise<number>;
|
|
600
653
|
listAll(tx: ReadTx): Promise<LoggedEvent[]>;
|
|
@@ -754,6 +807,91 @@ interface AuditEntryRepository extends StoreRepository {
|
|
|
754
807
|
}
|
|
755
808
|
declare function createAuditEntryRepository(store: CommandStore): AuditEntryRepository;
|
|
756
809
|
|
|
810
|
+
/** A row of `alert_subscriptions`: one address's alert of one kind on one variant. */
|
|
811
|
+
interface AlertSubscription {
|
|
812
|
+
id: string;
|
|
813
|
+
/** Trimmed and lower-cased. */
|
|
814
|
+
email: string;
|
|
815
|
+
kind: AlertKind;
|
|
816
|
+
variantId: string;
|
|
817
|
+
productId: string;
|
|
818
|
+
status: AlertStatus;
|
|
819
|
+
confirmToken: string;
|
|
820
|
+
unsubscribeToken: string;
|
|
821
|
+
/** The storefront origin its links point at. */
|
|
822
|
+
origin: string;
|
|
823
|
+
baselinePriceMinor: number | null;
|
|
824
|
+
createdAt: Date;
|
|
825
|
+
updatedAt: Date;
|
|
826
|
+
confirmedAt: Date | null;
|
|
827
|
+
}
|
|
828
|
+
/** A subscribe request: a new row's values, of which a row already there takes only what its status allows. */
|
|
829
|
+
interface AlertSubscriptionRequest {
|
|
830
|
+
id: string;
|
|
831
|
+
email: string;
|
|
832
|
+
kind: AlertKind;
|
|
833
|
+
variantId: string;
|
|
834
|
+
productId: string;
|
|
835
|
+
confirmToken: string;
|
|
836
|
+
unsubscribeToken: string;
|
|
837
|
+
origin: string;
|
|
838
|
+
/** A price-drop row's price at subscribe time; null for a back-in-stock row. */
|
|
839
|
+
baselinePriceMinor: number | null;
|
|
840
|
+
at: Date;
|
|
841
|
+
}
|
|
842
|
+
interface AlertSubscriptionPatch {
|
|
843
|
+
status: AlertStatus;
|
|
844
|
+
updatedAt: Date;
|
|
845
|
+
confirmedAt?: Date;
|
|
846
|
+
/** The price a price-drop row was last told. */
|
|
847
|
+
baselinePriceMinor?: number;
|
|
848
|
+
}
|
|
849
|
+
interface AlertSubscriptionRepository extends StoreRepository {
|
|
850
|
+
/**
|
|
851
|
+
* One write on the unique (email, variant, kind): a new row is `pending`; a `pending` row takes the request's origin;
|
|
852
|
+
* an `unsubscribed` or `fired` row returns to `pending` with the request's origin, confirm token and baseline (its
|
|
853
|
+
* unsubscribe token is kept); an `active` row only has `updated_at` touched. Answers the row after the write.
|
|
854
|
+
*/
|
|
855
|
+
upsertPending(tx: Tx, request: AlertSubscriptionRequest): Promise<AlertSubscription>;
|
|
856
|
+
findById(tx: ReadTx, id: string): Promise<AlertSubscription | null>;
|
|
857
|
+
findByConfirmToken(tx: ReadTx, token: string): Promise<AlertSubscription | null>;
|
|
858
|
+
findByUnsubscribeToken(tx: ReadTx, token: string): Promise<AlertSubscription | null>;
|
|
859
|
+
listActive(tx: ReadTx, variantId: string, kind: AlertKind): Promise<AlertSubscription[]>;
|
|
860
|
+
/** Applies `patch` when the row's status is one of `from`; the row after, or null when nothing changed. */
|
|
861
|
+
update(tx: Tx, id: string, patch: AlertSubscriptionPatch, from: readonly AlertStatus[]): Promise<AlertSubscription | null>;
|
|
862
|
+
}
|
|
863
|
+
declare function createAlertSubscriptionRepository(store: CommandStore): AlertSubscriptionRepository;
|
|
864
|
+
|
|
865
|
+
type EmailSuppressionReason = 'hard_bounce' | 'complaint';
|
|
866
|
+
interface EmailSuppressionInput {
|
|
867
|
+
email: string;
|
|
868
|
+
reason: EmailSuppressionReason;
|
|
869
|
+
/** The feedback event that suppresses the address. */
|
|
870
|
+
eventId: string;
|
|
871
|
+
at: Date;
|
|
872
|
+
}
|
|
873
|
+
/** Addresses that hard-bounced or complained. Each method normalises the address it is given. */
|
|
874
|
+
interface EmailSuppressionRepository extends StoreRepository {
|
|
875
|
+
/** True when this call suppressed the address; false when it already was, whose first reason stays. */
|
|
876
|
+
suppress(tx: Tx, input: EmailSuppressionInput): Promise<boolean>;
|
|
877
|
+
isSuppressed(tx: ReadTx, email: string): Promise<boolean>;
|
|
878
|
+
}
|
|
879
|
+
declare function createEmailSuppressionRepository(store: CommandStore): EmailSuppressionRepository;
|
|
880
|
+
|
|
881
|
+
interface OrderShipmentInput {
|
|
882
|
+
orderId: string;
|
|
883
|
+
carrier: string;
|
|
884
|
+
trackingNumber: string;
|
|
885
|
+
at: Date;
|
|
886
|
+
}
|
|
887
|
+
/** The parcel each shipped order went out in. Each method normalises the tracking number it is given. */
|
|
888
|
+
interface OrderShipmentRepository extends StoreRepository {
|
|
889
|
+
record(tx: Tx, input: OrderShipmentInput): Promise<void>;
|
|
890
|
+
/** The ids of every order shipped under the number, in no particular order. */
|
|
891
|
+
ordersByTrackingNumber(tx: ReadTx, trackingNumber: string): Promise<string[]>;
|
|
892
|
+
}
|
|
893
|
+
declare function createOrderShipmentRepository(store: CommandStore): OrderShipmentRepository;
|
|
894
|
+
|
|
757
895
|
interface Repositories {
|
|
758
896
|
product: ProductRepository;
|
|
759
897
|
variant: VariantRepository;
|
|
@@ -765,6 +903,7 @@ interface Repositories {
|
|
|
765
903
|
orderHistory: OrderHistoryRepository;
|
|
766
904
|
orderRefund: OrderRefundRepository;
|
|
767
905
|
orderSequence: OrderSequenceRepository;
|
|
906
|
+
orderAccessKey: OrderAccessKeyRepository;
|
|
768
907
|
inventoryReservation: InventoryReservationRepository;
|
|
769
908
|
stockAdjustment: StockAdjustmentRepository;
|
|
770
909
|
review: ReviewRepository;
|
|
@@ -773,6 +912,9 @@ interface Repositories {
|
|
|
773
912
|
cart: CartRepository;
|
|
774
913
|
settings: SettingsRepository;
|
|
775
914
|
auditEntry: AuditEntryRepository;
|
|
915
|
+
alertSubscription: AlertSubscriptionRepository;
|
|
916
|
+
emailSuppression: EmailSuppressionRepository;
|
|
917
|
+
orderShipment: OrderShipmentRepository;
|
|
776
918
|
}
|
|
777
919
|
declare function buildRepositories(commandStore: CommandStore, _documentStore: DocumentStoreAdapter): Repositories;
|
|
778
920
|
|
|
@@ -827,6 +969,15 @@ interface MakeEventOptions {
|
|
|
827
969
|
}
|
|
828
970
|
declare function createEventBuilder(ctx: EventBuilderContext): <T>(type: string, payload: T, options?: MakeEventOptions) => NymbalEvent<T>;
|
|
829
971
|
|
|
972
|
+
interface OutageReport {
|
|
973
|
+
/** True when any checked subject is down, threw or did not answer in time. */
|
|
974
|
+
outage: boolean;
|
|
975
|
+
down: readonly {
|
|
976
|
+
name: string;
|
|
977
|
+
detail: string;
|
|
978
|
+
}[];
|
|
979
|
+
}
|
|
980
|
+
|
|
830
981
|
/** Hands committed events from the log to the bus. */
|
|
831
982
|
interface Relay {
|
|
832
983
|
/** Delivers every undelivered, non-dead event in `seq` order. Never rejects. */
|
|
@@ -851,6 +1002,17 @@ interface CreateRelayOptions {
|
|
|
851
1002
|
/** Failed bus publishes after which an event is dead and never handed to the bus again. */
|
|
852
1003
|
maxAttempts?: number;
|
|
853
1004
|
intervalMs?: number;
|
|
1005
|
+
/** The wait before the first retry of a failed event (default `intervalMs`); each later wait doubles it. */
|
|
1006
|
+
retryDelayMs?: number;
|
|
1007
|
+
/** The clock failures and retry waits are read from. */
|
|
1008
|
+
now?: () => Date;
|
|
1009
|
+
/**
|
|
1010
|
+
* Asked once a pass, at its first failed delivery: a failure during an outage is not counted toward `maxAttempts`.
|
|
1011
|
+
* Absent, no failure is an outage.
|
|
1012
|
+
*/
|
|
1013
|
+
outage?: () => Promise<OutageReport>;
|
|
1014
|
+
/** How long the relay waits on `outage` before taking the pass as an outage (default the health check bound + 1 s). */
|
|
1015
|
+
outageTimeoutMs?: number;
|
|
854
1016
|
}
|
|
855
1017
|
declare function createRelay(opts: CreateRelayOptions): Relay;
|
|
856
1018
|
|
|
@@ -865,6 +1027,14 @@ interface EventPublisher {
|
|
|
865
1027
|
options?: PublishOptions;
|
|
866
1028
|
};
|
|
867
1029
|
}[NymbalEventType]>): Promise<void>;
|
|
1030
|
+
/**
|
|
1031
|
+
* Events of types the kernel does not declare (an adapter's own, already checked by the caller), with the same
|
|
1032
|
+
* append and drain as `publish`.
|
|
1033
|
+
*/
|
|
1034
|
+
publishUntyped(events: ReadonlyArray<{
|
|
1035
|
+
type: string;
|
|
1036
|
+
payload: unknown;
|
|
1037
|
+
}>, options?: PublishOptions): Promise<NymbalEvent<unknown>[]>;
|
|
868
1038
|
correlated(correlationId: string): EventPublisher;
|
|
869
1039
|
}
|
|
870
1040
|
interface CreatePublisherOptions {
|
|
@@ -948,16 +1118,138 @@ interface BuildAdaptersDeps {
|
|
|
948
1118
|
}
|
|
949
1119
|
declare function buildAdapters(deps: BuildAdaptersDeps): Promise<AdapterRegistry>;
|
|
950
1120
|
|
|
1121
|
+
interface AlertSubscribeInput {
|
|
1122
|
+
email: string;
|
|
1123
|
+
variantId: string;
|
|
1124
|
+
kind: AlertKind;
|
|
1125
|
+
/** The request's `Origin` header: the storefront the links in its emails point at. */
|
|
1126
|
+
origin: string | undefined;
|
|
1127
|
+
}
|
|
1128
|
+
interface AlertConfirmed {
|
|
1129
|
+
status: 'active';
|
|
1130
|
+
kind: AlertKind;
|
|
1131
|
+
product: {
|
|
1132
|
+
name: string;
|
|
1133
|
+
slug: string;
|
|
1134
|
+
};
|
|
1135
|
+
}
|
|
1136
|
+
interface AlertService {
|
|
1137
|
+
/**
|
|
1138
|
+
* Answers `pending` whatever the address's account or subscription, so the answer reveals neither; every accepted
|
|
1139
|
+
* request writes the row once. Only a row that is not `active` is (re)sent its confirmation.
|
|
1140
|
+
*/
|
|
1141
|
+
subscribe(input: AlertSubscribeInput): Promise<{
|
|
1142
|
+
status: 'pending';
|
|
1143
|
+
}>;
|
|
1144
|
+
confirm(token: string): Promise<AlertConfirmed>;
|
|
1145
|
+
unsubscribe(token: string): Promise<{
|
|
1146
|
+
status: 'unsubscribed';
|
|
1147
|
+
}>;
|
|
1148
|
+
/**
|
|
1149
|
+
* In the transaction that marks an alert's send: a back-in-stock row is `fired`, a price-drop row stays `active` with
|
|
1150
|
+
* the trigger's price as its baseline; `alert.sent.v1` names the trigger.
|
|
1151
|
+
*/
|
|
1152
|
+
recordSent(tx: Tx, subscription: AlertSubscription, trigger: NymbalEvent<unknown>): Promise<void>;
|
|
1153
|
+
}
|
|
1154
|
+
interface CreateAlertServiceDeps {
|
|
1155
|
+
store: CommandStore;
|
|
1156
|
+
repos: Repositories;
|
|
1157
|
+
publisher: EventPublisher;
|
|
1158
|
+
/** `http.cors.allowedOrigins`: the storefronts a subscribe may come from. A `*` entry matches no origin. */
|
|
1159
|
+
allowedOrigins: readonly string[];
|
|
1160
|
+
/** Whether the store's email reaches a mailbox; a store whose email only logs takes no subscription. */
|
|
1161
|
+
delivers(): boolean;
|
|
1162
|
+
}
|
|
1163
|
+
declare function createAlertService(deps: CreateAlertServiceDeps): AlertService;
|
|
1164
|
+
|
|
1165
|
+
interface OrderCreateDraftInput {
|
|
1166
|
+
orderId: string;
|
|
1167
|
+
customerId: string | null;
|
|
1168
|
+
email: string;
|
|
1169
|
+
billingAddress: Address;
|
|
1170
|
+
shippingAddress: Address;
|
|
1171
|
+
lineItems: OrderLineItem[];
|
|
1172
|
+
subtotalMinor: number;
|
|
1173
|
+
taxTotalMinor: number;
|
|
1174
|
+
shippingTotalMinor: number;
|
|
1175
|
+
discountTotalMinor: number;
|
|
1176
|
+
totalMinor: number;
|
|
1177
|
+
currency: string;
|
|
1178
|
+
notes?: string;
|
|
1179
|
+
metadata?: Record<string, unknown>;
|
|
1180
|
+
paymentIntentId?: string | null;
|
|
1181
|
+
cartToken?: string | null;
|
|
1182
|
+
}
|
|
1183
|
+
interface OrderImportInput extends OrderCreateDraftInput {
|
|
1184
|
+
orderNumber: string;
|
|
1185
|
+
status: OrderStatus;
|
|
1186
|
+
createdAt: Date;
|
|
1187
|
+
/** What the imported order was paid, taken as captured when it was placed; nothing when absent. */
|
|
1188
|
+
capturedMinor?: number;
|
|
1189
|
+
refundedMinor?: number;
|
|
1190
|
+
captureMethod?: CaptureMethod | null;
|
|
1191
|
+
}
|
|
1192
|
+
interface OrderService {
|
|
1193
|
+
createFromCheckout(input: OrderCreateDraftInput): Promise<Order>;
|
|
1194
|
+
importOrder(input: OrderImportInput): Promise<Order>;
|
|
1195
|
+
getById(id: string): Promise<Order>;
|
|
1196
|
+
getByOrderNumber(orderNumber: string): Promise<Order>;
|
|
1197
|
+
listByCustomer(customerId: string): Promise<Order[]>;
|
|
1198
|
+
/** Whether `key` opens the order now: one of its own keys, well formed and unexpired. */
|
|
1199
|
+
keyOpens(orderId: string, key: string): Promise<boolean>;
|
|
1200
|
+
/** What `key` does for the order at `now`: another order's key, or a malformed one, is `none`. */
|
|
1201
|
+
keyState(orderId: string, key: string, now?: Date): Promise<OrderKeyState>;
|
|
1202
|
+
/**
|
|
1203
|
+
* "Send me my order link": when the number and email name an order a confirmation is due for (confirmed or later),
|
|
1204
|
+
* its order-placed email is sent again, with a fresh link for a guest's order. Anything else does nothing, and the
|
|
1205
|
+
* caller is told nothing either way.
|
|
1206
|
+
*/
|
|
1207
|
+
requestLink(orderNumber: string, email: string): Promise<void>;
|
|
1208
|
+
updateStatus(id: string, toStatus: OrderStatus, actor: string, note?: string): Promise<Order>;
|
|
1209
|
+
markShipped(id: string, trackingNumber: string, carrier: string, actor: string): Promise<Order>;
|
|
1210
|
+
markDelivered(id: string, actor: string): Promise<Order>;
|
|
1211
|
+
/** Refuses with `order.paid` once anything is captured: a paid order is refunded, never cancelled. */
|
|
1212
|
+
cancel(id: string, reason: string, actor: string): Promise<Order>;
|
|
1213
|
+
/**
|
|
1214
|
+
* Asks for the order's confirmation email again; the email handler sends it. Refuses with `order.unpaid` for an
|
|
1215
|
+
* order no confirmation is due for (pending, or cancelled and so never paid). Changes nothing on the order.
|
|
1216
|
+
*/
|
|
1217
|
+
resendConfirmation(id: string): Promise<Order>;
|
|
1218
|
+
}
|
|
1219
|
+
interface CreateOrderServiceDeps {
|
|
1220
|
+
store: CommandStore;
|
|
1221
|
+
repos: Repositories;
|
|
1222
|
+
publisher: EventPublisher;
|
|
1223
|
+
logger: Logger;
|
|
1224
|
+
orderNumberPrefix: string;
|
|
1225
|
+
orderNumberStart: number;
|
|
1226
|
+
}
|
|
1227
|
+
declare function createOrderService(deps: CreateOrderServiceDeps): OrderService;
|
|
1228
|
+
|
|
951
1229
|
interface RegisterHandlersDeps {
|
|
952
1230
|
config: NymbalConfig;
|
|
953
1231
|
eventBus: EventBusAdapter;
|
|
954
1232
|
documentStore: DocumentStoreAdapter;
|
|
955
1233
|
repos: Repositories;
|
|
956
1234
|
adapters: AdapterRegistry;
|
|
1235
|
+
/** Records each alert's send: the row fired and `alert.sent.v1` published. */
|
|
1236
|
+
alerts: AlertService;
|
|
1237
|
+
/** Moves an order a tracking update reports delivered. */
|
|
1238
|
+
orders: OrderService;
|
|
957
1239
|
logger: Logger;
|
|
958
1240
|
}
|
|
959
1241
|
declare function registerHandlers(deps: RegisterHandlersDeps): Promise<void>;
|
|
960
1242
|
|
|
1243
|
+
interface RegisterAlertHandlerDeps {
|
|
1244
|
+
eventBus: EventBusAdapter;
|
|
1245
|
+
email: EmailAdapter;
|
|
1246
|
+
logger: Logger;
|
|
1247
|
+
repos: Pick<Repositories, 'alertSubscription' | 'emailSuppression' | 'processedEvent' | 'product'>;
|
|
1248
|
+
alerts: AlertService;
|
|
1249
|
+
storeName: string;
|
|
1250
|
+
}
|
|
1251
|
+
declare function registerAlertHandler(deps: RegisterAlertHandlerDeps): Promise<void>;
|
|
1252
|
+
|
|
961
1253
|
interface ProductCreateInput {
|
|
962
1254
|
slug: string;
|
|
963
1255
|
name: string;
|
|
@@ -974,8 +1266,16 @@ interface ProductCreateInput {
|
|
|
974
1266
|
id?: string;
|
|
975
1267
|
}>;
|
|
976
1268
|
}
|
|
1269
|
+
/** A variant's prices: `compareAtPriceMinor` omitted keeps the stored one, null clears it. */
|
|
1270
|
+
interface VariantPriceInput {
|
|
1271
|
+
id: string;
|
|
1272
|
+
priceMinor: number;
|
|
1273
|
+
compareAtPriceMinor?: number | null;
|
|
1274
|
+
}
|
|
977
1275
|
interface ProductUpdateInput extends Omit<ProductUpdate, 'updatedAt'> {
|
|
978
1276
|
categoryIds?: string[];
|
|
1277
|
+
/** Prices of some of the product's own variants; a variant left out is unchanged, and none is added or deleted. */
|
|
1278
|
+
variants?: VariantPriceInput[];
|
|
979
1279
|
}
|
|
980
1280
|
interface ProductService {
|
|
981
1281
|
create(input: ProductCreateInput): Promise<ProductSnapshot>;
|
|
@@ -996,6 +1296,8 @@ interface CreateProductServiceDeps {
|
|
|
996
1296
|
repos: Repositories;
|
|
997
1297
|
publisher: EventPublisher;
|
|
998
1298
|
logger: Logger;
|
|
1299
|
+
/** The store's currency, which a price event names. */
|
|
1300
|
+
currency: string;
|
|
999
1301
|
}
|
|
1000
1302
|
declare function createProductService(deps: CreateProductServiceDeps): ProductService;
|
|
1001
1303
|
|
|
@@ -1054,12 +1356,20 @@ interface ProfileUpdate {
|
|
|
1054
1356
|
lastName?: string;
|
|
1055
1357
|
phone?: string;
|
|
1056
1358
|
}
|
|
1359
|
+
/** An admin's note on a customer, kept in its metadata. */
|
|
1360
|
+
interface CustomerNote {
|
|
1361
|
+
body: string;
|
|
1362
|
+
actor: string;
|
|
1363
|
+
at: string;
|
|
1364
|
+
}
|
|
1057
1365
|
interface CustomerService {
|
|
1058
1366
|
getProfile(customerId: string): Promise<Customer>;
|
|
1059
1367
|
updateProfile(customerId: string, patch: ProfileUpdate): Promise<Customer>;
|
|
1060
1368
|
listAddresses(customerId: string): Promise<CustomerAddress[]>;
|
|
1061
1369
|
addAddress(customerId: string, addr: Omit<CustomerAddress, 'id'>): Promise<CustomerAddress>;
|
|
1062
1370
|
deleteAddress(customerId: string, addressId: string): Promise<void>;
|
|
1371
|
+
/** Appends `note` to the customer's admin notes. */
|
|
1372
|
+
addNote(customerId: string, note: CustomerNote): Promise<void>;
|
|
1063
1373
|
}
|
|
1064
1374
|
declare function createCustomerService(deps: {
|
|
1065
1375
|
repos: Repositories;
|
|
@@ -1117,57 +1427,9 @@ interface CreateAuthServiceDeps {
|
|
|
1117
1427
|
refreshTtl: string;
|
|
1118
1428
|
issuer?: string;
|
|
1119
1429
|
}
|
|
1430
|
+
declare function parseDurationToMs(s: string): number;
|
|
1120
1431
|
declare function createAuthService(deps: CreateAuthServiceDeps): AuthService;
|
|
1121
1432
|
|
|
1122
|
-
interface OrderCreateDraftInput {
|
|
1123
|
-
orderId: string;
|
|
1124
|
-
customerId: string | null;
|
|
1125
|
-
email: string;
|
|
1126
|
-
billingAddress: Address;
|
|
1127
|
-
shippingAddress: Address;
|
|
1128
|
-
lineItems: OrderLineItem[];
|
|
1129
|
-
subtotalMinor: number;
|
|
1130
|
-
taxTotalMinor: number;
|
|
1131
|
-
shippingTotalMinor: number;
|
|
1132
|
-
discountTotalMinor: number;
|
|
1133
|
-
totalMinor: number;
|
|
1134
|
-
currency: string;
|
|
1135
|
-
notes?: string;
|
|
1136
|
-
metadata?: Record<string, unknown>;
|
|
1137
|
-
paymentIntentId?: string | null;
|
|
1138
|
-
cartToken?: string | null;
|
|
1139
|
-
}
|
|
1140
|
-
interface OrderImportInput extends OrderCreateDraftInput {
|
|
1141
|
-
orderNumber: string;
|
|
1142
|
-
status: OrderStatus;
|
|
1143
|
-
createdAt: Date;
|
|
1144
|
-
/** What the imported order was paid, taken as captured when it was placed; nothing when absent. */
|
|
1145
|
-
capturedMinor?: number;
|
|
1146
|
-
refundedMinor?: number;
|
|
1147
|
-
captureMethod?: CaptureMethod | null;
|
|
1148
|
-
}
|
|
1149
|
-
interface OrderService {
|
|
1150
|
-
createFromCheckout(input: OrderCreateDraftInput): Promise<Order>;
|
|
1151
|
-
importOrder(input: OrderImportInput): Promise<Order>;
|
|
1152
|
-
getById(id: string): Promise<Order>;
|
|
1153
|
-
getByOrderNumber(orderNumber: string): Promise<Order>;
|
|
1154
|
-
listByCustomer(customerId: string): Promise<Order[]>;
|
|
1155
|
-
updateStatus(id: string, toStatus: OrderStatus, actor: string, note?: string): Promise<Order>;
|
|
1156
|
-
markShipped(id: string, trackingNumber: string, carrier: string, actor: string): Promise<Order>;
|
|
1157
|
-
markDelivered(id: string, actor: string): Promise<Order>;
|
|
1158
|
-
/** Refuses with `order.paid` once anything is captured: a paid order is refunded, never cancelled. */
|
|
1159
|
-
cancel(id: string, reason: string, actor: string): Promise<Order>;
|
|
1160
|
-
}
|
|
1161
|
-
interface CreateOrderServiceDeps {
|
|
1162
|
-
store: CommandStore;
|
|
1163
|
-
repos: Repositories;
|
|
1164
|
-
publisher: EventPublisher;
|
|
1165
|
-
logger: Logger;
|
|
1166
|
-
orderNumberPrefix: string;
|
|
1167
|
-
orderNumberStart: number;
|
|
1168
|
-
}
|
|
1169
|
-
declare function createOrderService(deps: CreateOrderServiceDeps): OrderService;
|
|
1170
|
-
|
|
1171
1433
|
interface ReserveStockResult {
|
|
1172
1434
|
reservationId: string;
|
|
1173
1435
|
expiresAt: string;
|
|
@@ -1213,6 +1475,11 @@ interface BeginCheckoutResult {
|
|
|
1213
1475
|
/** The order's status as the checkout answers. */
|
|
1214
1476
|
orderStatus: OrderStatus;
|
|
1215
1477
|
payment: CheckoutPayment;
|
|
1478
|
+
/**
|
|
1479
|
+
* A guest order's fresh key, which reads it with no session (`ORDER_KEY_HEADER`) until it expires. Only its hash is
|
|
1480
|
+
* stored. A signed-in customer's order has none: their account is its home.
|
|
1481
|
+
*/
|
|
1482
|
+
orderKey?: string;
|
|
1216
1483
|
}
|
|
1217
1484
|
/** What the payment provider captured. */
|
|
1218
1485
|
interface CapturedPayment {
|
|
@@ -1256,6 +1523,8 @@ interface CreateCheckoutServiceDeps {
|
|
|
1256
1523
|
inventory: InventoryService;
|
|
1257
1524
|
payments: PaymentsAdapter;
|
|
1258
1525
|
currency: string;
|
|
1526
|
+
/** How long a checkout's order key opens the order on its own; 48 hours when not given. */
|
|
1527
|
+
keyLifetimeMs?: number;
|
|
1259
1528
|
}
|
|
1260
1529
|
declare function createCheckoutService(deps: CreateCheckoutServiceDeps): CheckoutService & ManualPayments;
|
|
1261
1530
|
|
|
@@ -1308,13 +1577,37 @@ interface Settlement {
|
|
|
1308
1577
|
}
|
|
1309
1578
|
/** The provider's answer settles a refund row as succeeded only when it is for the row's amount and currency. */
|
|
1310
1579
|
declare function settlementOf(answer: Refund, row: Pick<OrderRefund, 'amountMinor' | 'currency'>): Settlement;
|
|
1311
|
-
/**
|
|
1580
|
+
/**
|
|
1581
|
+
* Writes `refunded_minor` as Σ of the order's succeeded refunds, when that moves it: a refund that moved no money (failed
|
|
1582
|
+
* or still pending) leaves the order row as it was, so it needs no order event. The caller holds the order's lock.
|
|
1583
|
+
*/
|
|
1312
1584
|
declare function refreshRefunded(repos: Repositories, tx: Tx, orderId: string, at: Date): Promise<{
|
|
1313
1585
|
refunds: OrderRefund[];
|
|
1314
1586
|
refundedMinor: number;
|
|
1315
1587
|
}>;
|
|
1316
1588
|
declare function createRefundService(deps: CreateRefundServiceDeps): RefundService;
|
|
1317
1589
|
|
|
1590
|
+
interface RecentlyViewedServiceDeps {
|
|
1591
|
+
store: CommandStore;
|
|
1592
|
+
repos: Pick<Repositories, 'product'>;
|
|
1593
|
+
publisher: EventPublisher;
|
|
1594
|
+
logger: Logger;
|
|
1595
|
+
/** The view's time, which its event carries. */
|
|
1596
|
+
now?: () => Date;
|
|
1597
|
+
}
|
|
1598
|
+
interface RecentlyViewedService {
|
|
1599
|
+
/** Logs a view of an active product; false, and nothing logged, for any other id. */
|
|
1600
|
+
record(viewer: RecentViewer, productId: string): Promise<boolean>;
|
|
1601
|
+
/** Moves a visitor's views to the customer who signed in carrying its cookie. */
|
|
1602
|
+
fold(visitorId: string, customerId: string): Promise<void>;
|
|
1603
|
+
}
|
|
1604
|
+
declare function createRecentlyViewedService(deps: RecentlyViewedServiceDeps): RecentlyViewedService;
|
|
1605
|
+
|
|
1606
|
+
/** A confirm or unsubscribe link's bearer credential: 32 random bytes, base64url (43 characters). */
|
|
1607
|
+
declare function newAlertToken(): string;
|
|
1608
|
+
|
|
1609
|
+
/** A `native` email adapter only logs; any other (`smtp`, a project's own) is taken to reach a mailbox. */
|
|
1610
|
+
declare function emailDelivers(email: EmailAdapter): boolean;
|
|
1318
1611
|
interface ServiceRegistry {
|
|
1319
1612
|
product: ProductService;
|
|
1320
1613
|
category: CategoryService;
|
|
@@ -1326,6 +1619,8 @@ interface ServiceRegistry {
|
|
|
1326
1619
|
checkout: CheckoutService & ManualPayments;
|
|
1327
1620
|
refund: RefundService;
|
|
1328
1621
|
search: SearchService;
|
|
1622
|
+
recentlyViewed: RecentlyViewedService;
|
|
1623
|
+
alert: AlertService;
|
|
1329
1624
|
}
|
|
1330
1625
|
interface BuildServicesDeps {
|
|
1331
1626
|
config: NymbalConfig;
|
|
@@ -1335,6 +1630,9 @@ interface BuildServicesDeps {
|
|
|
1335
1630
|
logger: Logger;
|
|
1336
1631
|
payments: PaymentsAdapter;
|
|
1337
1632
|
searchAdapter: SearchAdapter;
|
|
1633
|
+
email: EmailAdapter;
|
|
1634
|
+
/** The effective JWT secret (`resolveAuthSecret`), not the config's field. */
|
|
1635
|
+
jwtSecret: string;
|
|
1338
1636
|
}
|
|
1339
1637
|
declare function buildServices(deps: BuildServicesDeps): ServiceRegistry;
|
|
1340
1638
|
|
|
@@ -1358,11 +1656,18 @@ interface RegisterAllRoutesDeps {
|
|
|
1358
1656
|
publisher: EventPublisher;
|
|
1359
1657
|
/** The slots whose provider packages declare settings, as the store booted with them. */
|
|
1360
1658
|
settingsSlots: readonly DeclaredSlot[];
|
|
1659
|
+
/** The effective JWT secret (`resolveAuthSecret`), which signs the event-stream ticket as it signs tokens. */
|
|
1660
|
+
jwtSecret: string;
|
|
1361
1661
|
/** The admin's dist directory, or null for a 404 that says how to build it; undefined serves no admin. */
|
|
1362
1662
|
adminRoot?: string | null | undefined;
|
|
1363
1663
|
}
|
|
1364
1664
|
declare function registerAllRoutes(deps: RegisterAllRoutesDeps): void;
|
|
1365
1665
|
|
|
1666
|
+
interface RegisterAlertRoutesDeps {
|
|
1667
|
+
alerts: AlertService;
|
|
1668
|
+
}
|
|
1669
|
+
declare function registerAlertRoutes(adapter: HttpAdapter, deps: RegisterAlertRoutesDeps): void;
|
|
1670
|
+
|
|
1366
1671
|
/**
|
|
1367
1672
|
* The input of one route: what `registerAllRoutes` parses before the handler runs, and what a tool definition is
|
|
1368
1673
|
* generated from. Unknown keys are stripped, so a handler sees only what is declared here.
|
|
@@ -1417,9 +1722,22 @@ interface CreateAppOptions extends ResolvePrimitivesOptions {
|
|
|
1417
1722
|
version?: string;
|
|
1418
1723
|
/** The project's own adapters, one per slot whose provider is `custom`. */
|
|
1419
1724
|
adapters?: InjectedAdapters;
|
|
1725
|
+
/** How the event relay retries a failed delivery (`createRelay`). */
|
|
1726
|
+
relay?: Pick<CreateRelayOptions, 'maxAttempts' | 'retryDelayMs' | 'intervalMs' | 'now'>;
|
|
1420
1727
|
}
|
|
1421
1728
|
declare function createApp(config: NymbalConfig, options?: CreateAppOptions): Promise<NymbalApp>;
|
|
1422
1729
|
|
|
1730
|
+
interface AuthSecret {
|
|
1731
|
+
secret: string;
|
|
1732
|
+
source: 'config' | 'env' | 'default';
|
|
1733
|
+
}
|
|
1734
|
+
/**
|
|
1735
|
+
* The secret every token is signed with: the config's own, else NYMBAL_JWT_SECRET, else the schema default. Code that
|
|
1736
|
+
* names a secret wins, as it does over the environment for adapter settings. A set variable is checked first, so a
|
|
1737
|
+
* malformed one fails the boot even when the config's secret would win.
|
|
1738
|
+
*/
|
|
1739
|
+
declare function resolveAuthSecret(config: NymbalConfig, env: NodeJS.ProcessEnv): AuthSecret;
|
|
1740
|
+
|
|
1423
1741
|
/**
|
|
1424
1742
|
* Serves the admin's built files at /admin/ beside /api, one origin, so its relative API URLs and the refresh cookie
|
|
1425
1743
|
* work without a proxy. `root` is the admin's dist directory, or null when none is installed: then /admin/ answers 404
|
|
@@ -1478,31 +1796,50 @@ interface EventRetentionSweeperDeps {
|
|
|
1478
1796
|
*/
|
|
1479
1797
|
declare function startEventRetentionSweeper(deps: EventRetentionSweeperDeps): SweeperHandle;
|
|
1480
1798
|
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
sdk?: string;
|
|
1799
|
+
/** What the config names for a slot: its provider, and the package the adapter comes from when it says. */
|
|
1800
|
+
interface Choice {
|
|
1801
|
+
provider: string;
|
|
1802
|
+
package?: string | undefined;
|
|
1486
1803
|
}
|
|
1487
|
-
type Packages<P extends ProviderPackage> = Readonly<Record<string, P>>;
|
|
1488
1804
|
/**
|
|
1489
|
-
*
|
|
1490
|
-
*
|
|
1491
|
-
* `local-fs`) have no entry. Every package peers its provider's SDK but the security ones, which call an HTTP API.
|
|
1805
|
+
* Where a slot's adapter comes from: the one passed to `createApp` (`custom`), the kernel's own (`built-in`), or a
|
|
1806
|
+
* package, named by the config's `package` or by the convention, `@nymbalhq/<slot>-<provider>`.
|
|
1492
1807
|
*/
|
|
1493
|
-
|
|
1494
|
-
|
|
1808
|
+
type Resolution = {
|
|
1809
|
+
kind: 'custom';
|
|
1810
|
+
} | {
|
|
1811
|
+
kind: 'built-in';
|
|
1812
|
+
} | {
|
|
1813
|
+
kind: 'package';
|
|
1814
|
+
package: string;
|
|
1815
|
+
sdk?: string;
|
|
1816
|
+
named: 'package' | 'convention';
|
|
1495
1817
|
};
|
|
1818
|
+
/** The rule every caller shares: `custom`, then a built-in, then `package`, then the convention name. */
|
|
1819
|
+
declare function resolveChoice(slot: Slot, choice: Choice): Resolution;
|
|
1496
1820
|
/** The command that installs `packages` with the project's package manager, as `packageManager` picks it. */
|
|
1497
1821
|
declare function installLine(packages: readonly string[], env: NodeJS.ProcessEnv, cwd: string): string;
|
|
1498
|
-
type ProviderModule = ProviderPackageModule;
|
|
1499
1822
|
/**
|
|
1500
|
-
* The
|
|
1501
|
-
*
|
|
1502
|
-
* (`adapter.package_missing`) carrying the install line, a module with no `createAdapter` is `adapter.package_invalid`,
|
|
1503
|
-
* and any other load error is rethrown as it is.
|
|
1823
|
+
* The package Node could not find, when `error` is a missing package and not some other failure. A path (an installed
|
|
1824
|
+
* package's own missing file) is not a package to install, so it is `null` and the error stays as Node threw it.
|
|
1504
1825
|
*/
|
|
1505
|
-
declare function
|
|
1826
|
+
declare function missingPackage(error: unknown): string | null;
|
|
1827
|
+
/**
|
|
1828
|
+
* `mod` as the adapter module of `slot` and `provider`, from `pkg`: it must export `createAdapter`, `slot` equal to the
|
|
1829
|
+
* slot and, for any provider but `custom`, `provider` equal to it. A module for another slot is `adapter.wrong_slot`,
|
|
1830
|
+
* anything else wrong `adapter.package_invalid`, each naming the package, the export, the expected and actual value.
|
|
1831
|
+
*/
|
|
1832
|
+
declare function checkAdapterModule(mod: unknown, slot: Slot, provider: string, pkg: string): ProviderPackageModule;
|
|
1833
|
+
/**
|
|
1834
|
+
* The adapter module the slot's choice resolves to, imported and checked, or `undefined` for `custom` and a built-in.
|
|
1835
|
+
* The specifier is imported from the project root, `process.cwd()`. A package that is not installed is
|
|
1836
|
+
* `adapter.package_missing` with its install line, or `adapter.provider_unknown` (with a suggestion when one is near)
|
|
1837
|
+
* for a convention name no first-party package has; an adapter that resolves another copy of @nymbalhq/types than the
|
|
1838
|
+
* kernel's is `adapter.types_duplicate`; any other load error is rethrown as it is.
|
|
1839
|
+
*/
|
|
1840
|
+
declare function importAdapterModule(slot: Slot, choice: Choice, env: NodeJS.ProcessEnv, importer?: (specifier: string) => Promise<unknown>): Promise<ProviderPackageModule | undefined>;
|
|
1841
|
+
/** The fields a provider package lets Settings fill: its `settings` export, or none. */
|
|
1842
|
+
declare function declaredSettings(mod: ProviderPackageModule | undefined): readonly AdapterSetting[];
|
|
1506
1843
|
|
|
1507
1844
|
/**
|
|
1508
1845
|
* v0.1 security adapter.
|
|
@@ -1545,7 +1882,7 @@ declare function createNativeStubPaymentsAdapter(deps: {
|
|
|
1545
1882
|
logger: Logger;
|
|
1546
1883
|
}): PaymentsAdapter;
|
|
1547
1884
|
|
|
1548
|
-
/** The native provider logs mail to the console; SMTP is the `smtp` provider (@nymbalhq/
|
|
1885
|
+
/** The native provider logs mail to the console; SMTP is the `smtp` provider (@nymbalhq/email-smtp). */
|
|
1549
1886
|
interface NativeEmailAdapterConfig {
|
|
1550
1887
|
transport?: 'console';
|
|
1551
1888
|
from?: string;
|
|
@@ -1578,8 +1915,6 @@ declare function createNativeShippingAdapter(logger: Logger): ShippingAdapter;
|
|
|
1578
1915
|
|
|
1579
1916
|
declare function createNativeTaxAdapter(logger: Logger, defaultRate?: number): TaxAdapter;
|
|
1580
1917
|
|
|
1581
|
-
declare function createNativeAiAdapter(_logger: Logger): AiAdapter;
|
|
1582
|
-
|
|
1583
1918
|
interface CreateLoggerOptions {
|
|
1584
1919
|
level?: string;
|
|
1585
1920
|
pretty?: boolean;
|
|
@@ -1702,7 +2037,7 @@ interface DocumentWrite {
|
|
|
1702
2037
|
doc: unknown;
|
|
1703
2038
|
}
|
|
1704
2039
|
|
|
1705
|
-
type ReadModelName = 'catalogue' | 'orders' | 'customers' | 'search';
|
|
2040
|
+
type ReadModelName = 'catalogue' | 'orders' | 'customers' | 'search' | 'recently-viewed';
|
|
1706
2041
|
interface RebuildDeps {
|
|
1707
2042
|
config: NymbalConfig;
|
|
1708
2043
|
store: CommandStore;
|
|
@@ -1720,6 +2055,8 @@ interface RebuildDeps {
|
|
|
1720
2055
|
table: string;
|
|
1721
2056
|
page: number;
|
|
1722
2057
|
}) => void | Promise<void>;
|
|
2058
|
+
/** Awaited once every model is collected, before a model is caught up and swapped, and after its swap. */
|
|
2059
|
+
onPhase?: (phase: 'collected' | 'swapped', model: ReadModelName) => void | Promise<void>;
|
|
1723
2060
|
}
|
|
1724
2061
|
/** What a rebuilder reads with: the command store in pages, each page a read of its own. */
|
|
1725
2062
|
interface RebuildContext {
|
|
@@ -1727,6 +2064,13 @@ interface RebuildContext {
|
|
|
1727
2064
|
pages<T extends {
|
|
1728
2065
|
id: string;
|
|
1729
2066
|
}>(table: string, read: (tx: ReadTx, page: KeysetPage) => Promise<T[]>): AsyncIterable<T[]>;
|
|
2067
|
+
/**
|
|
2068
|
+
* The logged events of `types`, in seq pages, each page a read of its own (`onPage` names the table `events`). A model
|
|
2069
|
+
* that reads them is caught up only with events above the last one it read: re-applying one it already folded
|
|
2070
|
+
* would fold it twice. The bound is per model, not per collection: a model that reads both `pages()` and `events()`
|
|
2071
|
+
* would skip catch-up for the collections it builds from tables.
|
|
2072
|
+
*/
|
|
2073
|
+
events(types: readonly string[]): AsyncIterable<LoggedEvent[]>;
|
|
1730
2074
|
}
|
|
1731
2075
|
interface ReadModel {
|
|
1732
2076
|
name: ReadModelName;
|
|
@@ -1763,6 +2107,8 @@ interface RebuildReportEntry {
|
|
|
1763
2107
|
name: string;
|
|
1764
2108
|
documents: number;
|
|
1765
2109
|
}>;
|
|
2110
|
+
/** Logged events applied to the collected contents before the swap. */
|
|
2111
|
+
caughtUpBeforeSwap: number;
|
|
1766
2112
|
/** Logged events re-applied after the swap. */
|
|
1767
2113
|
caughtUpEvents: number;
|
|
1768
2114
|
/** Catch-up events a handler failed on: the model is swapped all the same. */
|
|
@@ -1778,8 +2124,9 @@ declare class RebuildError extends Error {
|
|
|
1778
2124
|
constructor(model: ReadModelName, cause: unknown);
|
|
1779
2125
|
}
|
|
1780
2126
|
/**
|
|
1781
|
-
* Rebuilds `names` from the command store's tables: every model is read first, then each is
|
|
1782
|
-
*
|
|
2127
|
+
* Rebuilds `names` from the command store's tables: every model is read first, then each is caught up in memory with
|
|
2128
|
+
* the events delivered since its read began, swapped in (atomically per collection) and caught up again, for the
|
|
2129
|
+
* events delivered while it was swapped. A rebuilder that throws rejects with
|
|
1783
2130
|
* a `RebuildError` before anything is swapped. Catch-up failures are in the report.
|
|
1784
2131
|
*/
|
|
1785
2132
|
declare function rebuild(names: readonly ReadModelName[], deps: RebuildDeps): Promise<RebuildReport>;
|
|
@@ -1839,5 +2186,5 @@ interface LocalFsMediaStorageOptions {
|
|
|
1839
2186
|
declare const LOCAL_FS_MEDIA_CAPABILITIES: readonly string[];
|
|
1840
2187
|
declare function createLocalFsMediaStorage(options: LocalFsMediaStorageOptions): MediaStorage;
|
|
1841
2188
|
|
|
1842
|
-
export { CATCH_UP_MARGIN_MS, CSRF_COOKIE, CSRF_HEADER, InMemoryDocumentStore, InProcessEventBus, LOCAL_FS_MEDIA_CAPABILITIES,
|
|
1843
|
-
export type { AbandonedCart, AbandonedWindow, Actor, AdapterRegistry, AppliedEntry, AttachHttpOptions, AuditCursor, AuditEntryInsert, AuditEntryRepository, AuditFilter, AuditQuery, AuthService, AuthTokens, BeginCheckoutInput, BeginCheckoutResult, BuildAdaptersDeps, BuildServicesDeps, CapabilitiesReport, CapabilitySlot, CapturedPayment, CartRepository, CartService, CatchUpFailure, CategoryCreateInput, CategoryInsert, CategoryRepository, CategoryService, CategoryUpdate, CategoryUpdateInput, CheckoutService, CollectionDiff, CommandStore, CommandStoreOptions, CommerceAdapters, CreateAppOptions, CreateAuthServiceDeps, CreateCartServiceDeps, CreateCheckoutServiceDeps, CreateInventoryServiceDeps, CreateLoggerOptions, CreateOrderServiceDeps, CreatePlatformOptions, CreateProductServiceDeps, CreatePublisherOptions, CreateRefundServiceDeps, CreateRelayOptions, CustomerInsert, CustomerJwtPayload, CustomerRepository, CustomerService, CustomerUpdate, CustomerWithHash, DiagnoseOptions, DiagnosisCheck, DiagnosisReport, DiagnosisStatus, EncryptedValue, EventArchiveWriter, EventBuilderContext, EventLogFilter, EventLogRepository, EventPublisher, EventRetentionSweeperDeps, FinalizeResult, IdempotencyOptions, ImportCustomerInput, InMemoryDocumentStoreOptions, InProcessEventBusOptions, InjectedAdapters, InventoryReservationRepository, InventoryService, KeysetPage, CategoryInsert$1 as LegacyCategoryInsert, CategoryRow as LegacyCategoryRow, ProductInsert$1 as LegacyProductInsert, ProductRow as LegacyProductRow, LocalFsMediaStorageOptions, LoggedEvent, MakeEventOptions, ManualPayments, MigrateOptions, NativeEmailAdapterConfig, NymbalApp, OpenReadModelsOptions, OrderCapture, OrderCreateDraftInput, OrderHistoryInsert, OrderHistoryRepository, OrderImportInput, OrderInsert, OrderRefundInsert, OrderRefundRepository, OrderRepository, OrderSequenceRepository, OrderService, Platform, PlatformConnectionOptions, PostgresClient, Primitives, ProcessedEventRepository, ProductCategoryRepository, ProductCreateInput, ProductInsert, ProductRepository, ProductService, ProductUpdate, ProductUpdateInput, ProfileUpdate,
|
|
2189
|
+
export { CATCH_UP_MARGIN_MS, CSRF_COOKIE, CSRF_HEADER, InMemoryDocumentStore, InProcessEventBus, LOCAL_FS_MEDIA_CAPABILITIES, PROVIDER_REFUND_REASON, READ_MODELS, READ_MODEL_NAMES, REDIS_DEFAULTS, RateLimiter, RebuildError, SECRETS_KEY_ENV, SECRETS_KEY_OLD_ENV, actorOf, appendAuditEntry, audit, auditEntriesInOrder, auditedCommand, buildAdapters, buildRepositories, buildServices, checkAdapterModule, createAlertService, createAlertSubscriptionRepository, createApp, createAuditEntryRepository, createAuthService, createCartRepository, createCartService, createCategoryRepository, createCategoryService, createCheckoutService, createCommandStore, createCustomerRepository, createCustomerService, createEmailSuppressionRepository, createEventBuilder, createEventLogRepository, createEventPublisher, createInventoryReservationRepository, createInventoryService, createCategoryRepository$1 as createLegacyCategoryRepository, createProductRepository$1 as createLegacyProductRepository, createLocalFsMediaStorage, createLogger, createMiddlewareSecurityAdapter, createNativeAnalyticsAdapter, createNativeEmailAdapter, createNativeReviewsAdapter, createNativeSearchAdapter, createNativeShippingAdapter, createNativeStubPaymentsAdapter, createNativeTaxAdapter, createOrderAccessKeyRepository, createOrderHistoryRepository, createOrderRefundRepository, createOrderRepository, createOrderSequenceRepository, createOrderService, createOrderShipmentRepository, createPlatform, createProcessedEventRepository, createProductCategoryRepository, createProductRepository, createProductService, createRecentlyViewedService, createRefreshTokenRepository, createRefundService, createRelay, createReviewRepository, createSearchService, createSettingsRepository, createStockAdjustmentRepository, createVariantRepository, currentActor, currentCorrelationId, declaredSettings, decrypt, diagnose, diffReadModel, emailDelivers, encodeSearchCursor, encrypt, fillFromSettings, findAppliedByKey, importAdapterModule, installLine, isMissingSettingsTable, keyId, keyProblem, listAuditEntries, migrationState, missingPackage, newAlertToken, newCorrelationId, openReadModels, orderPayment, parseDurationToMs, rawClients, readSecretsKey, rebuild, refreshRefunded, registerAdminStaticRoute, registerAlertHandler, registerAlertRoutes, registerAllRoutes, registerHandlers, resolveAuthSecret, resolveChoice, resolvePrimitives, routeSchemas, runAsActor, runMigrations, runSeed, runWithCorrelation, scrub, seedCategories, seedProducts, settingAad, settlementOf, sqliteFile, startCartAbandonmentSweeper, startEventRetentionSweeper, startInventoryReservationSweeper, withIdempotency };
|
|
2190
|
+
export type { AbandonedCart, AbandonedWindow, Actor, AdapterRegistry, AlertConfirmed, AlertService, AlertSubscribeInput, AlertSubscription, AlertSubscriptionPatch, AlertSubscriptionRepository, AlertSubscriptionRequest, AppliedEntry, AttachHttpOptions, AuditCursor, AuditEntryInsert, AuditEntryRepository, AuditFilter, AuditQuery, AuthSecret, AuthService, AuthTokens, BeginCheckoutInput, BeginCheckoutResult, BuildAdaptersDeps, BuildServicesDeps, CapabilitiesReport, CapabilitySlot, CapturedPayment, CartRepository, CartService, CatchUpFailure, CategoryCreateInput, CategoryInsert, CategoryRepository, CategoryService, CategoryUpdate, CategoryUpdateInput, CheckoutService, Choice, CollectionDiff, CommandStore, CommandStoreOptions, CommerceAdapters, CreateAlertServiceDeps, CreateAppOptions, CreateAuthServiceDeps, CreateCartServiceDeps, CreateCheckoutServiceDeps, CreateInventoryServiceDeps, CreateLoggerOptions, CreateOrderServiceDeps, CreatePlatformOptions, CreateProductServiceDeps, CreatePublisherOptions, CreateRefundServiceDeps, CreateRelayOptions, CustomerInsert, CustomerJwtPayload, CustomerNote, CustomerRepository, CustomerService, CustomerUpdate, CustomerWithHash, DiagnoseOptions, DiagnosisCheck, DiagnosisReport, DiagnosisStatus, EmailSuppressionInput, EmailSuppressionReason, EmailSuppressionRepository, EncryptedValue, EventArchiveWriter, EventBuilderContext, EventLogFilter, EventLogRepository, EventPublisher, EventRetentionSweeperDeps, FinalizeResult, IdempotencyOptions, ImportCustomerInput, InMemoryDocumentStoreOptions, InProcessEventBusOptions, InjectedAdapters, InventoryReservationRepository, InventoryService, KeysetPage, CategoryInsert$1 as LegacyCategoryInsert, CategoryRow as LegacyCategoryRow, ProductInsert$1 as LegacyProductInsert, ProductRow as LegacyProductRow, LocalFsMediaStorageOptions, LoggedEvent, MakeEventOptions, ManualPayments, MigrateOptions, MigrationState, NativeEmailAdapterConfig, NymbalApp, OpenReadModelsOptions, OrderAccessKeyInsert, OrderAccessKeyPurpose, OrderAccessKeyRepository, OrderCapture, OrderCreateDraftInput, OrderHistoryInsert, OrderHistoryRepository, OrderImportInput, OrderInsert, OrderKeyState, OrderRefundInsert, OrderRefundRepository, OrderRepository, OrderSequenceRepository, OrderService, OrderShipmentInput, OrderShipmentRepository, Platform, PlatformConnectionOptions, PostgresClient, Primitives, ProcessedEventRepository, ProductCategoryRepository, ProductCreateInput, ProductInsert, ProductRepository, ProductService, ProductUpdate, ProductUpdateInput, ProfileUpdate, PublishOptions, RawClients, ReadModel, ReadModelDiff, ReadModelName, ReadTx, RebuildDeps, RebuildReport, RebuildReportEntry, RecentlyViewedService, RecentlyViewedServiceDeps, RefreshTokenInsert, RefreshTokenRepository, RefreshTokenRow, RefundInput, RefundResult, RefundService, RegisterAlertHandlerDeps, RegisterAlertRoutesDeps, RegisterAllRoutesDeps, RegisterHandlersDeps, RegisterInput, Relay, Repositories, ReservationInsert, ReserveStockResult, Resolution, ResolvePrimitivesOptions, ReviewInsert, ReviewKey, ReviewRepository, RouteSchema, SearchService, SecretsKey, SeedCategory, SeedDeps, SeedProduct, SeedResult, ServiceRegistry, SettingRow, SettingSource, SettingValue, SettingsRepository, Settlement, SlotCapabilities, SqliteClient, StockAdjustmentInsert, StockAdjustmentRepository, StoreRepository, StoredCipher, SweeperHandle, Tx, VariantInsert, VariantPriceInput, VariantRepository, VariantUpdate };
|