@nymbalhq/platform 0.2.0 → 1.0.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/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { NymbalConfig } from '@nymbalhq/config';
2
- import { Logger, DocumentStoreAdapter, EventBusAdapter, 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, PutOptions, QueryParams, QueryResult, EventHandler, SubscriptionConfig, Subscription, NymbalEnvironment, NymbalEventType, NymbalEventMap, SecurityAdapter, PaymentsAdapter, EmailAdapter, SearchAdapter, ReviewsAdapter, AnalyticsAdapter, ShippingAdapter, TaxAdapter, AiAdapter, ProductSnapshot, CartItem, StockStatus, PaymentIntent, CheckoutPayment, SearchParams, SearchResult, OrderPayment, Refund, HttpAdapter, RateLimitAction, SecurityConfigLike } from '@nymbalhq/types';
2
+ import { Logger, DocumentStoreAdapter, EventBusAdapter, 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, PutOptions, QueryParams, QueryResult, EventHandler, SubscriptionConfig, Subscription, NymbalEnvironment, NymbalEventType, NymbalEventMap, PaymentsAdapter, EmailAdapter, ReviewsAdapter, SearchAdapter, AnalyticsAdapter, ShippingAdapter, TaxAdapter, AiAdapter, SecurityAdapter, ProductSnapshot, CartItem, StockStatus, PaymentIntent, CheckoutPayment, SearchParams, SearchResult, OrderPayment, Refund, HttpAdapter, CommerceSlot, RateLimitAction, SecurityConfigLike } from '@nymbalhq/types';
3
3
  import BetterSqlite3 from 'better-sqlite3';
4
4
  import pg from 'pg';
5
5
  import { BetterSQLite3Database } from 'drizzle-orm/better-sqlite3';
@@ -597,6 +597,7 @@ interface InMemoryDocumentStoreOptions {
597
597
  declare class InMemoryDocumentStore implements DocumentStoreAdapter {
598
598
  #private;
599
599
  constructor(options?: InMemoryDocumentStoreOptions);
600
+ capabilities(): readonly string[];
600
601
  get<T>(collection: string, key: string): Promise<T | null>;
601
602
  put<T>(collection: string, key: string, document: T, options?: PutOptions): Promise<void>;
602
603
  delete(collection: string, key: string): Promise<void>;
@@ -614,6 +615,7 @@ interface InProcessEventBusOptions {
614
615
  declare class InProcessEventBus implements EventBusAdapter {
615
616
  #private;
616
617
  constructor(options?: InProcessEventBusOptions);
618
+ capabilities(): readonly string[];
617
619
  publish<T>(event: NymbalEvent<T>): Promise<void>;
618
620
  publishBatch(events: NymbalEvent<unknown>[]): Promise<void>;
619
621
  replay(events: NymbalEvent<unknown>[]): Promise<void>;
@@ -688,28 +690,33 @@ interface IdempotencyOptions {
688
690
  }
689
691
  declare function withIdempotency<T = unknown>(handlerName: string, handler: EventHandler<T>, { repo, logger }: IdempotencyOptions): EventHandler<T>;
690
692
 
691
- interface AdapterRegistry {
692
- security: SecurityAdapter;
693
+ /** One adapter per commerce slot. */
694
+ interface CommerceAdapters {
693
695
  payments: PaymentsAdapter;
694
696
  email: EmailAdapter;
695
- search: SearchAdapter;
696
697
  reviews: ReviewsAdapter;
698
+ search: SearchAdapter;
697
699
  analytics: AnalyticsAdapter;
698
700
  shipping: ShippingAdapter;
699
701
  tax: TaxAdapter;
700
702
  ai: AiAdapter;
701
703
  }
704
+ /** Adapters a project hands `createApp`, each for a slot whose provider is `custom`. */
705
+ type InjectedAdapters = Partial<CommerceAdapters>;
706
+ interface AdapterRegistry extends Omit<CommerceAdapters, 'ai'> {
707
+ security: SecurityAdapter;
708
+ /** `null` when the config's ai provider is `none`. */
709
+ ai: AiAdapter | null;
710
+ }
702
711
  interface BuildAdaptersDeps {
703
712
  config: NymbalConfig;
704
713
  logger: Logger;
705
714
  documentStore: DocumentStoreAdapter;
706
715
  repos: Repositories;
716
+ injected?: InjectedAdapters;
717
+ /** The payments adapter `createApp` resolved before it opened the store. */
718
+ payments: PaymentsAdapter;
707
719
  }
708
- /**
709
- * The `providerName` of the payments adapter a configured provider resolves to. A provider with no adapter of its
710
- * own falls back to the stub, which verifies no webhook signature.
711
- */
712
- declare function paymentsAdapterFor(provider: string): 'stripe' | 'native-stub';
713
720
  declare function buildAdapters(deps: BuildAdaptersDeps): Promise<AdapterRegistry>;
714
721
 
715
722
  interface RegisterHandlersDeps {
@@ -1143,13 +1150,23 @@ interface NymbalApp {
1143
1150
  * or null for a 404 that says how to build it) or `NYMBAL_ADMIN_DIST` is set.
1144
1151
  */
1145
1152
  attachHttp(adapter: HttpAdapter, options?: AttachHttpOptions): Promise<void>;
1153
+ /** Each slot's provider and its adapter's own `capabilities()`; an ai slot of `none` offers nothing. */
1154
+ capabilities(): CapabilitiesReport;
1146
1155
  stop(): Promise<void>;
1147
1156
  }
1157
+ type CapabilitySlot = CommerceSlot | 'security' | 'documentStore' | 'eventBus' | 'media';
1158
+ interface SlotCapabilities {
1159
+ provider: string;
1160
+ capabilities: readonly string[];
1161
+ }
1162
+ type CapabilitiesReport = Record<CapabilitySlot, SlotCapabilities>;
1148
1163
  interface AttachHttpOptions {
1149
1164
  adminRoot?: string | null;
1150
1165
  }
1151
1166
  interface CreateAppOptions extends CreatePlatformOptions {
1152
1167
  version?: string;
1168
+ /** The project's own adapters, one per slot whose provider is `custom`. */
1169
+ adapters?: InjectedAdapters;
1153
1170
  }
1154
1171
  declare function createApp(config: NymbalConfig, options?: CreateAppOptions): Promise<NymbalApp>;
1155
1172
 
@@ -1202,6 +1219,18 @@ interface EventRetentionSweeperDeps {
1202
1219
  /** Deletes delivered events and processed-event records older than the window; undelivered and dead events stay. */
1203
1220
  declare function startEventRetentionSweeper(deps: EventRetentionSweeperDeps): SweeperHandle;
1204
1221
 
1222
+ interface ProviderPackage {
1223
+ /** The adapter package, which exports `createAdapter(ctx: AdapterContext)`. */
1224
+ package: string;
1225
+ /** The provider SDK the package peers, which the project installs beside it. */
1226
+ sdk: string;
1227
+ }
1228
+ /**
1229
+ * The providers that live in their own package, by slot then provider. The kernel imports a package only when the
1230
+ * config names its provider; `native`, `none` and `custom` have no entry.
1231
+ */
1232
+ declare const PROVIDER_PACKAGES: Readonly<Partial<Record<CommerceSlot, Readonly<Record<string, ProviderPackage>>>>>;
1233
+
1205
1234
  /**
1206
1235
  * v0.1 security adapter.
1207
1236
  *
@@ -1234,22 +1263,6 @@ declare function buildSecurityHeaders(security: SecurityConfigLike): Record<stri
1234
1263
  declare const CSRF_COOKIE = "nymbal.csrf";
1235
1264
  declare const CSRF_HEADER = "x-csrf-token";
1236
1265
 
1237
- interface StripePaymentsConfig {
1238
- secretKey: string;
1239
- webhookSecret: string;
1240
- apiVersion?: string;
1241
- /** Override the Stripe API host (for stripe-mock style test servers). Omit in production. */
1242
- host?: string;
1243
- /** Override the Stripe API port. Only used together with `host`. */
1244
- port?: number;
1245
- /** Override the Stripe API protocol. Defaults to https when omitted. */
1246
- protocol?: 'http' | 'https';
1247
- }
1248
- declare function createStripePaymentsAdapter(deps: {
1249
- logger: Logger;
1250
- config: StripePaymentsConfig;
1251
- }): PaymentsAdapter;
1252
-
1253
1266
  /**
1254
1267
  * Deterministic payments adapter for local development without Stripe keys.
1255
1268
  * Every intent succeeds at creation unless the receipt email asks otherwise (`statusFor`); webhook verification is a
@@ -1260,16 +1273,10 @@ declare function createNativeStubPaymentsAdapter(deps: {
1260
1273
  logger: Logger;
1261
1274
  }): PaymentsAdapter;
1262
1275
 
1276
+ /** The native provider logs mail to the console; SMTP is the `smtp` provider (@nymbalhq/adapter-smtp). */
1263
1277
  interface NativeEmailAdapterConfig {
1264
- transport?: 'console' | 'smtp';
1278
+ transport?: 'console';
1265
1279
  from?: string;
1266
- smtp?: {
1267
- host: string;
1268
- port: number;
1269
- user?: string;
1270
- pass?: string;
1271
- secure?: boolean;
1272
- };
1273
1280
  }
1274
1281
  declare function createNativeEmailAdapter(deps: {
1275
1282
  logger: Logger;
@@ -1294,13 +1301,6 @@ declare function createNativeTaxAdapter(logger: Logger, defaultRate?: number): T
1294
1301
 
1295
1302
  declare function createNativeAiAdapter(_logger: Logger): AiAdapter;
1296
1303
 
1297
- interface AnthropicAiAdapterConfig {
1298
- apiKey: string;
1299
- model?: string;
1300
- logger: Logger;
1301
- }
1302
- declare function createAnthropicAiAdapter(config: AnthropicAiAdapterConfig): AiAdapter;
1303
-
1304
1304
  interface CreateLoggerOptions {
1305
1305
  level?: string;
1306
1306
  pretty?: boolean;
@@ -1358,6 +1358,7 @@ declare const seedCategories: SeedCategory[];
1358
1358
  declare const seedProducts: SeedProduct[];
1359
1359
 
1360
1360
  interface MediaStorage {
1361
+ capabilities(): readonly string[];
1361
1362
  put(key: string, body: Uint8Array, contentType: string): Promise<{
1362
1363
  url: string;
1363
1364
  }>;
@@ -1369,4 +1370,4 @@ interface LocalFsMediaStorageOptions {
1369
1370
  }
1370
1371
  declare function createLocalFsMediaStorage(options: LocalFsMediaStorageOptions): MediaStorage;
1371
1372
 
1372
- export { type AbandonedCart, type AbandonedWindow, type AdapterRegistry, type AnthropicAiAdapterConfig, type AttachHttpOptions, type AuthService, type AuthTokens, type BeginCheckoutInput, type BeginCheckoutResult, type BuildAdaptersDeps, type BuildServicesDeps, CSRF_COOKIE, CSRF_HEADER, type CapturedPayment, type CartRepository, type CartService, type CategoryCreateInput, type CategoryInsert, type CategoryRepository, type CategoryService, type CategoryUpdate, type CategoryUpdateInput, type CheckoutService, type CommandStore, type CreateAppOptions, type CreateAuthServiceDeps, type CreateCartServiceDeps, type CreateCheckoutServiceDeps, type CreateInventoryServiceDeps, type CreateLoggerOptions, type CreateOrderServiceDeps, type CreatePlatformOptions, type CreateProductServiceDeps, type CreatePublisherOptions, type CreateRefundServiceDeps, type CreateRelayOptions, type CustomerInsert, type CustomerJwtPayload, type CustomerRepository, type CustomerService, type CustomerUpdate, type CustomerWithHash, type EventBuilderContext, type EventLogRepository, type EventPublisher, type EventRetentionSweeperDeps, type FinalizeResult, type IdempotencyOptions, type ImportCustomerInput, InMemoryDocumentStore, type InMemoryDocumentStoreOptions, InProcessEventBus, type InProcessEventBusOptions, type InventoryReservationRepository, type InventoryService, type CategoryInsert$1 as LegacyCategoryInsert, type CategoryRow as LegacyCategoryRow, type ProductInsert$1 as LegacyProductInsert, type ProductRow as LegacyProductRow, type LocalFsMediaStorageOptions, type LoggedEvent, type MakeEventOptions, type ManualPayments, type MediaStorage, type MigrateOptions, type NativeEmailAdapterConfig, type NymbalApp, type OrderCapture, type OrderCreateDraftInput, type OrderHistoryInsert, type OrderHistoryRepository, type OrderImportInput, type OrderInsert, type OrderRefundInsert, type OrderRefundRepository, type OrderRepository, type OrderSequenceRepository, type OrderService, PROVIDER_REFUND_REASON, type Platform, type PostgresClient, type ProcessedEventRepository, type ProductCategoryRepository, type ProductCreateInput, type ProductInsert, type ProductRepository, type ProductService, type ProductUpdate, type ProductUpdateInput, type ProfileUpdate, type PublishOptions, RateLimiter, type RawClients, type ReadTx, type RefreshTokenInsert, type RefreshTokenRepository, type RefreshTokenRow, type RefundInput, type RefundResult, type RefundService, type RegisterAllRoutesDeps, type RegisterHandlersDeps, type RegisterInput, type Relay, type Repositories, type ReservationInsert, type ReserveStockResult, type ReviewInsert, type ReviewRepository, type RouteSchema, type SearchService, type SeedCategory, type SeedDeps, type SeedProduct, type SeedResult, type ServiceRegistry, type Settlement, type SqliteClient, type StockAdjustmentInsert, type StockAdjustmentRepository, type StoreRepository, type StripePaymentsConfig, type SweeperHandle, type Tx, type VariantInsert, type VariantRepository, type VariantUpdate, type WarmDocumentStoreDeps, type WarmResult, buildAdapters, buildRepositories, buildSecurityHeaders, buildServices, createAnthropicAiAdapter, createApp, createAuthService, createCartRepository, createCartService, createCategoryRepository, createCategoryService, createCheckoutService, createCommandStore, createCustomerRepository, createCustomerService, createDocumentStore, createEventBuilder, createEventBus, createEventLogRepository, createEventPublisher, createInventoryReservationRepository, createInventoryService, createCategoryRepository$1 as createLegacyCategoryRepository, createProductRepository$1 as createLegacyProductRepository, createLocalFsMediaStorage, createLogger, createMiddlewareSecurityAdapter, createNativeAiAdapter, createNativeAnalyticsAdapter, createNativeEmailAdapter, createNativeReviewsAdapter, createNativeSearchAdapter, createNativeShippingAdapter, createNativeStubPaymentsAdapter, createNativeTaxAdapter, createOrderHistoryRepository, createOrderRefundRepository, createOrderRepository, createOrderSequenceRepository, createOrderService, createPlatform, createProcessedEventRepository, createProductCategoryRepository, createProductRepository, createProductService, createRefreshTokenRepository, createRefundService, createRelay, createReviewRepository, createSearchService, createStockAdjustmentRepository, createStripePaymentsAdapter, createVariantRepository, orderPayment, paymentsAdapterFor, rawClients, refreshRefunded, registerAdminStaticRoute, registerAllRoutes, registerHandlers, routeSchemas, runMigrations, runSeed, seedCategories, seedProducts, settlementOf, startCartAbandonmentSweeper, startEventRetentionSweeper, startInventoryReservationSweeper, warmDocumentStore, withIdempotency };
1373
+ export { type AbandonedCart, type AbandonedWindow, type AdapterRegistry, type AttachHttpOptions, type AuthService, type AuthTokens, type BeginCheckoutInput, type BeginCheckoutResult, type BuildAdaptersDeps, type BuildServicesDeps, CSRF_COOKIE, CSRF_HEADER, type CapabilitiesReport, type CapabilitySlot, type CapturedPayment, type CartRepository, type CartService, type CategoryCreateInput, type CategoryInsert, type CategoryRepository, type CategoryService, type CategoryUpdate, type CategoryUpdateInput, type CheckoutService, type CommandStore, type CommerceAdapters, type CreateAppOptions, type CreateAuthServiceDeps, type CreateCartServiceDeps, type CreateCheckoutServiceDeps, type CreateInventoryServiceDeps, type CreateLoggerOptions, type CreateOrderServiceDeps, type CreatePlatformOptions, type CreateProductServiceDeps, type CreatePublisherOptions, type CreateRefundServiceDeps, type CreateRelayOptions, type CustomerInsert, type CustomerJwtPayload, type CustomerRepository, type CustomerService, type CustomerUpdate, type CustomerWithHash, type EventBuilderContext, type EventLogRepository, type EventPublisher, type EventRetentionSweeperDeps, type FinalizeResult, type IdempotencyOptions, type ImportCustomerInput, InMemoryDocumentStore, type InMemoryDocumentStoreOptions, InProcessEventBus, type InProcessEventBusOptions, type InjectedAdapters, type InventoryReservationRepository, type InventoryService, type CategoryInsert$1 as LegacyCategoryInsert, type CategoryRow as LegacyCategoryRow, type ProductInsert$1 as LegacyProductInsert, type ProductRow as LegacyProductRow, type LocalFsMediaStorageOptions, type LoggedEvent, type MakeEventOptions, type ManualPayments, type MediaStorage, type MigrateOptions, type NativeEmailAdapterConfig, type NymbalApp, type OrderCapture, type OrderCreateDraftInput, type OrderHistoryInsert, type OrderHistoryRepository, type OrderImportInput, type OrderInsert, type OrderRefundInsert, type OrderRefundRepository, type OrderRepository, type OrderSequenceRepository, type OrderService, PROVIDER_PACKAGES, PROVIDER_REFUND_REASON, type Platform, type PostgresClient, type ProcessedEventRepository, type ProductCategoryRepository, type ProductCreateInput, type ProductInsert, type ProductRepository, type ProductService, type ProductUpdate, type ProductUpdateInput, type ProfileUpdate, type ProviderPackage, type PublishOptions, RateLimiter, type RawClients, type ReadTx, type RefreshTokenInsert, type RefreshTokenRepository, type RefreshTokenRow, type RefundInput, type RefundResult, type RefundService, type RegisterAllRoutesDeps, type RegisterHandlersDeps, type RegisterInput, type Relay, type Repositories, type ReservationInsert, type ReserveStockResult, type ReviewInsert, type ReviewRepository, type RouteSchema, type SearchService, type SeedCategory, type SeedDeps, type SeedProduct, type SeedResult, type ServiceRegistry, type Settlement, type SlotCapabilities, type SqliteClient, type StockAdjustmentInsert, type StockAdjustmentRepository, type StoreRepository, type SweeperHandle, type Tx, type VariantInsert, type VariantRepository, type VariantUpdate, type WarmDocumentStoreDeps, type WarmResult, buildAdapters, buildRepositories, buildSecurityHeaders, buildServices, createApp, createAuthService, createCartRepository, createCartService, createCategoryRepository, createCategoryService, createCheckoutService, createCommandStore, createCustomerRepository, createCustomerService, createDocumentStore, createEventBuilder, createEventBus, createEventLogRepository, createEventPublisher, createInventoryReservationRepository, createInventoryService, createCategoryRepository$1 as createLegacyCategoryRepository, createProductRepository$1 as createLegacyProductRepository, createLocalFsMediaStorage, createLogger, createMiddlewareSecurityAdapter, createNativeAiAdapter, createNativeAnalyticsAdapter, createNativeEmailAdapter, createNativeReviewsAdapter, createNativeSearchAdapter, createNativeShippingAdapter, createNativeStubPaymentsAdapter, createNativeTaxAdapter, createOrderHistoryRepository, createOrderRefundRepository, createOrderRepository, createOrderSequenceRepository, createOrderService, createPlatform, createProcessedEventRepository, createProductCategoryRepository, createProductRepository, createProductService, createRefreshTokenRepository, createRefundService, createRelay, createReviewRepository, createSearchService, createStockAdjustmentRepository, createVariantRepository, orderPayment, rawClients, refreshRefunded, registerAdminStaticRoute, registerAllRoutes, registerHandlers, routeSchemas, runMigrations, runSeed, seedCategories, seedProducts, settlementOf, startCartAbandonmentSweeper, startEventRetentionSweeper, startInventoryReservationSweeper, warmDocumentStore, withIdempotency };