@wopr-network/platform-core 1.0.0 → 1.0.2
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/coverage/coverage-summary.json +119 -0
- package/dist/admin/index.d.ts +1 -1
- package/dist/auth/better-auth.d.ts +45 -0
- package/dist/auth/better-auth.js +70 -47
- package/dist/auth/index.d.ts +12 -0
- package/dist/auth/index.js +7 -0
- package/dist/billing/drizzle-webhook-seen-repository.d.ts +1 -1
- package/dist/billing/index.d.ts +4 -4
- package/dist/billing/index.js +4 -4
- package/dist/billing/payram/webhook.test.js +1 -1
- package/dist/billing/stripe/index.d.ts +5 -5
- package/dist/billing/stripe/index.js +2 -2
- package/dist/billing/stripe/stripe-payment-processor.js +1 -1
- package/dist/credits/auto-topup-charge.d.ts +2 -2
- package/dist/credits/auto-topup-charge.test.js +1 -1
- package/dist/credits/auto-topup-schedule.d.ts +1 -1
- package/dist/credits/auto-topup-schedule.test.js +1 -1
- package/dist/credits/auto-topup-settings-repository.test.js +1 -1
- package/dist/credits/auto-topup-usage.d.ts +1 -1
- package/dist/credits/auto-topup-usage.test.js +1 -1
- package/dist/credits/index.d.ts +1 -1
- package/dist/credits/index.js +1 -1
- package/dist/db/schema/index.d.ts +1 -1
- package/dist/db/schema/index.js +1 -1
- package/dist/email/index.d.ts +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +4 -3
- package/dist/metering/aggregator.test.js +1 -1
- package/dist/metering/emitter.test.js +1 -1
- package/dist/metering/load-test.bench.js +1 -1
- package/dist/metering/metering.test.js +1 -1
- package/dist/metering/reconciliation-cron.test.js +2 -2
- package/dist/metering/reconciliation-repository.test.js +1 -1
- package/dist/middleware/index.d.ts +3 -3
- package/dist/middleware/index.js +2 -2
- package/dist/security/credential-vault/index.d.ts +2 -2
- package/dist/security/index.d.ts +7 -7
- package/dist/security/index.js +7 -7
- package/dist/security/redirect-allowlist.js +10 -8
- package/dist/security/tenant-keys/index.d.ts +6 -6
- package/dist/security/tenant-keys/index.js +3 -3
- package/dist/tenancy/index.d.ts +3 -3
- package/dist/tenancy/org-service.d.ts +1 -1
- package/dist/tenancy/org-service.test.js +1 -1
- package/dist/trpc/index.d.ts +1 -1
- package/dist/trpc/index.js +1 -1
- package/dist/trpc/init.test.js +3 -5
- package/package.json +2 -1
- package/src/admin/index.ts +1 -1
- package/src/auth/better-auth.ts +129 -48
- package/src/auth/index.ts +31 -0
- package/src/billing/drizzle-webhook-seen-repository.ts +1 -1
- package/src/billing/index.ts +11 -13
- package/src/billing/payram/webhook.test.ts +1 -1
- package/src/billing/stripe/index.ts +17 -5
- package/src/billing/stripe/stripe-payment-processor.test.ts +2 -3
- package/src/billing/stripe/stripe-payment-processor.ts +1 -1
- package/src/credits/auto-topup-charge.test.ts +2 -2
- package/src/credits/auto-topup-charge.ts +2 -2
- package/src/credits/auto-topup-schedule.test.ts +1 -1
- package/src/credits/auto-topup-schedule.ts +1 -1
- package/src/credits/auto-topup-settings-repository.test.ts +1 -1
- package/src/credits/auto-topup-usage.test.ts +1 -1
- package/src/credits/auto-topup-usage.ts +1 -1
- package/src/credits/index.ts +1 -1
- package/src/db/schema/index.ts +1 -1
- package/src/email/index.ts +3 -3
- package/src/index.ts +13 -17
- package/src/metering/aggregator.test.ts +1 -1
- package/src/metering/emitter.test.ts +1 -1
- package/src/metering/load-test.bench.ts +1 -1
- package/src/metering/metering.test.ts +1 -1
- package/src/metering/reconciliation-cron.test.ts +2 -2
- package/src/metering/reconciliation-repository.test.ts +2 -2
- package/src/middleware/index.ts +5 -5
- package/src/middleware/rate-limit.test.ts +1 -1
- package/src/middleware/rate-limit.ts +1 -1
- package/src/security/credential-vault/index.ts +2 -2
- package/src/security/index.ts +43 -38
- package/src/security/redirect-allowlist.ts +11 -8
- package/src/security/tenant-keys/index.ts +10 -6
- package/src/tenancy/index.ts +3 -3
- package/src/tenancy/org-service.test.ts +1 -1
- package/src/tenancy/org-service.ts +1 -1
- package/src/trpc/index.ts +5 -5
- package/src/trpc/init.test.ts +8 -10
- package/vitest.config.ts +4 -0
|
@@ -3,9 +3,9 @@ import Stripe from "stripe";
|
|
|
3
3
|
import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
|
4
4
|
import { creditAutoTopup } from "../db/schema/credit-auto-topup.js";
|
|
5
5
|
import { createTestDb, truncateAllTables } from "../test/db.js";
|
|
6
|
-
import { Credit } from "./credit.js";
|
|
7
6
|
import { chargeAutoTopup, MAX_CONSECUTIVE_FAILURES } from "./auto-topup-charge.js";
|
|
8
7
|
import { DrizzleAutoTopupEventLogRepository } from "./auto-topup-event-log-repository.js";
|
|
8
|
+
import { Credit } from "./credit.js";
|
|
9
9
|
import { CreditLedger } from "./credit-ledger.js";
|
|
10
10
|
function mockStripe(overrides) {
|
|
11
11
|
const piId = overrides?.paymentIntentId ?? `pi_${crypto.randomUUID()}`;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Credit } from "./credit.js";
|
|
2
1
|
import type { AutoTopupChargeResult } from "./auto-topup-charge.js";
|
|
3
2
|
import type { IAutoTopupSettingsRepository } from "./auto-topup-settings-repository.js";
|
|
3
|
+
import type { Credit } from "./credit.js";
|
|
4
4
|
export interface ScheduleTopupDeps {
|
|
5
5
|
settingsRepo: IAutoTopupSettingsRepository;
|
|
6
6
|
chargeAutoTopup: (tenantId: string, amount: Credit, source: string) => Promise<AutoTopupChargeResult>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
2
|
import { beginTestTransaction, createTestDb, endTestTransaction, rollbackTestTransaction } from "../test/db.js";
|
|
3
|
-
import { Credit } from "./credit.js";
|
|
4
3
|
import { runScheduledTopups } from "./auto-topup-schedule.js";
|
|
5
4
|
import { DrizzleAutoTopupSettingsRepository } from "./auto-topup-settings-repository.js";
|
|
5
|
+
import { Credit } from "./credit.js";
|
|
6
6
|
describe("runScheduledTopups", () => {
|
|
7
7
|
let pool;
|
|
8
8
|
let db;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { afterAll, beforeAll, beforeEach, describe, expect, it } from "vitest";
|
|
2
2
|
import { beginTestTransaction, createTestDb, endTestTransaction, rollbackTestTransaction } from "../test/db.js";
|
|
3
|
-
import { Credit } from "./credit.js";
|
|
4
3
|
import { DrizzleAutoTopupSettingsRepository } from "./auto-topup-settings-repository.js";
|
|
4
|
+
import { Credit } from "./credit.js";
|
|
5
5
|
describe("DrizzleAutoTopupSettingsRepository", () => {
|
|
6
6
|
let pool;
|
|
7
7
|
let db;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Credit } from "./credit.js";
|
|
2
1
|
import type { AutoTopupChargeResult } from "./auto-topup-charge.js";
|
|
3
2
|
import type { IAutoTopupSettingsRepository } from "./auto-topup-settings-repository.js";
|
|
3
|
+
import type { Credit } from "./credit.js";
|
|
4
4
|
import type { ICreditLedger } from "./credit-ledger.js";
|
|
5
5
|
export interface UsageTopupDeps {
|
|
6
6
|
settingsRepo: IAutoTopupSettingsRepository;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
2
|
import { createTestDb, truncateAllTables } from "../test/db.js";
|
|
3
|
-
import { Credit } from "./credit.js";
|
|
4
3
|
import { DrizzleAutoTopupSettingsRepository } from "./auto-topup-settings-repository.js";
|
|
5
4
|
import { maybeTriggerUsageTopup } from "./auto-topup-usage.js";
|
|
5
|
+
import { Credit } from "./credit.js";
|
|
6
6
|
import { CreditLedger } from "./credit-ledger.js";
|
|
7
7
|
describe("maybeTriggerUsageTopup", () => {
|
|
8
8
|
let pool;
|
package/dist/credits/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export type { AutoTopupSettings, IAutoTopupSettingsRepository, } from "./auto-topup-settings-repository.js";
|
|
2
2
|
export { ALLOWED_SCHEDULE_INTERVALS, ALLOWED_THRESHOLDS, ALLOWED_TOPUP_AMOUNTS, computeNextScheduleAt, DrizzleAutoTopupSettingsRepository, } from "./auto-topup-settings-repository.js";
|
|
3
|
+
export { Credit } from "./credit.js";
|
|
3
4
|
export type { CreditExpiryCronConfig, CreditExpiryCronResult } from "./credit-expiry-cron.js";
|
|
4
5
|
export { runCreditExpiryCron } from "./credit-expiry-cron.js";
|
|
5
6
|
export type { CreditTransaction, CreditType, DebitType, HistoryOptions, ICreditLedger, TransactionType, } from "./credit-ledger.js";
|
|
6
7
|
export { CreditLedger, DrizzleCreditLedger, InsufficientBalanceError } from "./credit-ledger.js";
|
|
7
8
|
export { grantSignupCredits, SIGNUP_GRANT } from "./signup-grant.js";
|
|
8
|
-
export { Credit } from "./credit.js";
|
|
9
9
|
export type { ITenantCustomerRepository, TenantCustomerRow } from "./tenant-customer-repository.js";
|
package/dist/credits/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { ALLOWED_SCHEDULE_INTERVALS, ALLOWED_THRESHOLDS, ALLOWED_TOPUP_AMOUNTS, computeNextScheduleAt, DrizzleAutoTopupSettingsRepository, } from "./auto-topup-settings-repository.js";
|
|
2
|
+
export { Credit } from "./credit.js";
|
|
2
3
|
export { runCreditExpiryCron } from "./credit-expiry-cron.js";
|
|
3
4
|
export { CreditLedger, DrizzleCreditLedger, InsufficientBalanceError } from "./credit-ledger.js";
|
|
4
5
|
export { grantSignupCredits, SIGNUP_GRANT } from "./signup-grant.js";
|
|
5
|
-
export { Credit } from "./credit.js";
|
|
@@ -5,9 +5,9 @@ export * from "./admin-users.js";
|
|
|
5
5
|
export * from "./affiliate.js";
|
|
6
6
|
export * from "./affiliate-fraud.js";
|
|
7
7
|
export * from "./coupon-codes.js";
|
|
8
|
-
export * from "./credits.js";
|
|
9
8
|
export * from "./credit-auto-topup.js";
|
|
10
9
|
export * from "./credit-auto-topup-settings.js";
|
|
10
|
+
export * from "./credits.js";
|
|
11
11
|
export * from "./dividend-distributions.js";
|
|
12
12
|
export * from "./email-notifications.js";
|
|
13
13
|
export * from "./meter-events.js";
|
package/dist/db/schema/index.js
CHANGED
|
@@ -5,9 +5,9 @@ export * from "./admin-users.js";
|
|
|
5
5
|
export * from "./affiliate.js";
|
|
6
6
|
export * from "./affiliate-fraud.js";
|
|
7
7
|
export * from "./coupon-codes.js";
|
|
8
|
-
export * from "./credits.js";
|
|
9
8
|
export * from "./credit-auto-topup.js";
|
|
10
9
|
export * from "./credit-auto-topup-settings.js";
|
|
10
|
+
export * from "./credits.js";
|
|
11
11
|
export * from "./dividend-distributions.js";
|
|
12
12
|
export * from "./email-notifications.js";
|
|
13
13
|
export * from "./meter-events.js";
|
package/dist/email/index.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export type { INotificationPreferencesRepository } from "./notification-preferen
|
|
|
18
18
|
export { DrizzleNotificationPreferencesStore } from "./notification-preferences-store.js";
|
|
19
19
|
export type { INotificationQueueRepository } from "./notification-queue-store.js";
|
|
20
20
|
export { DrizzleNotificationQueueStore } from "./notification-queue-store.js";
|
|
21
|
-
export type {
|
|
21
|
+
export type { NotificationEmailType, NotificationInput, NotificationPrefs, NotificationRow, NotificationStatus, QueuedNotification, } from "./notification-repository-types.js";
|
|
22
22
|
export { NotificationService } from "./notification-service.js";
|
|
23
23
|
export type { TemplateName as NotificationTemplateName } from "./notification-templates.js";
|
|
24
24
|
export { renderNotificationTemplate } from "./notification-templates.js";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export type { PlatformDb, PlatformSchema } from "./db/index.js";
|
|
2
|
-
export { createDb, schema } from "./db/index.js";
|
|
3
1
|
export * from "./admin/index.js";
|
|
4
2
|
export * from "./auth/index.js";
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
3
|
+
export { type ChargeOpts, type ChargeResult, type CheckoutOpts, type CheckoutSession, DrizzleWebhookSeenRepository, type Invoice, type IPaymentProcessor, type IWebhookSeenRepository, noOpReplayGuard, PaymentMethodOwnershipError, type PortalOpts, type SavedPaymentMethod, type SetupResult, type WebhookResult, } from "./billing/index.js";
|
|
4
|
+
export { billingConfigSchema, config, type PlatformConfig } from "./config/index.js";
|
|
7
5
|
export * from "./credits/index.js";
|
|
6
|
+
export type { PlatformDb, PlatformSchema } from "./db/index.js";
|
|
7
|
+
export { createDb, schema } from "./db/index.js";
|
|
8
8
|
export * from "./email/index.js";
|
|
9
9
|
export * from "./metering/index.js";
|
|
10
10
|
export * from "./middleware/index.js";
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
// Database
|
|
2
2
|
// Admin
|
|
3
3
|
export * from "./admin/index.js";
|
|
4
4
|
// Auth
|
|
5
5
|
export * from "./auth/index.js";
|
|
6
6
|
// Billing (selective — ITenantCustomerRepository/TenantCustomerRow also in credits)
|
|
7
|
-
export {
|
|
7
|
+
export { DrizzleWebhookSeenRepository, noOpReplayGuard, PaymentMethodOwnershipError, } from "./billing/index.js";
|
|
8
8
|
// Config
|
|
9
|
-
export {
|
|
9
|
+
export { billingConfigSchema, config } from "./config/index.js";
|
|
10
10
|
// Credits
|
|
11
11
|
export * from "./credits/index.js";
|
|
12
|
+
export { createDb, schema } from "./db/index.js";
|
|
12
13
|
// Email
|
|
13
14
|
export * from "./email/index.js";
|
|
14
15
|
// Metering
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import crypto from "node:crypto";
|
|
2
2
|
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
3
|
+
import { Credit } from "../credits/credit.js";
|
|
3
4
|
import { meterEvents, usageSummaries } from "../db/schema/meter-events.js";
|
|
4
5
|
import { createTestDb } from "../test/db.js";
|
|
5
|
-
import { Credit } from "../credits/credit.js";
|
|
6
6
|
import { DrizzleMeterAggregator } from "./aggregator.js";
|
|
7
7
|
import { DrizzleUsageSummaryRepository } from "./drizzle-usage-summary-repository.js";
|
|
8
8
|
const WINDOW_MS = 60_000; // 1-minute windows
|
|
@@ -2,8 +2,8 @@ import { mkdirSync, rmSync } from "node:fs";
|
|
|
2
2
|
import { tmpdir } from "node:os";
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
5
|
-
import { beginTestTransaction, createTestDb, endTestTransaction, rollbackTestTransaction } from "../test/db.js";
|
|
6
5
|
import { Credit } from "../credits/credit.js";
|
|
6
|
+
import { beginTestTransaction, createTestDb, endTestTransaction, rollbackTestTransaction } from "../test/db.js";
|
|
7
7
|
import { MeterDLQ } from "./dlq.js";
|
|
8
8
|
import { DrizzleMeterEmitter } from "./emitter.js";
|
|
9
9
|
import { DrizzleMeterEventRepository } from "./meter-event-repository.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { unlinkSync } from "node:fs";
|
|
2
2
|
import { afterEach, beforeEach, bench, describe } from "vitest";
|
|
3
|
-
import { createTestDb } from "../test/db.js";
|
|
4
3
|
import { Credit } from "../credits/credit.js";
|
|
4
|
+
import { createTestDb } from "../test/db.js";
|
|
5
5
|
import { MeterAggregator } from "./aggregator.js";
|
|
6
6
|
import { DrizzleUsageSummaryRepository } from "./drizzle-usage-summary-repository.js";
|
|
7
7
|
import { MeterEmitter } from "./emitter.js";
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { existsSync, readFileSync, unlinkSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { eq, sql } from "drizzle-orm";
|
|
3
3
|
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
|
|
4
|
+
import { Credit } from "../credits/credit.js";
|
|
4
5
|
import { meterEvents } from "../db/schema/meter-events.js";
|
|
5
6
|
import { createTestDb, truncateAllTables } from "../test/db.js";
|
|
6
|
-
import { Credit } from "../credits/credit.js";
|
|
7
7
|
import { MeterAggregator } from "./aggregator.js";
|
|
8
8
|
import { DrizzleUsageSummaryRepository } from "./drizzle-usage-summary-repository.js";
|
|
9
9
|
import { MeterEmitter } from "./emitter.js";
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import crypto from "node:crypto";
|
|
2
2
|
import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
-
import { usageSummaries } from "../db/schema/meter-events.js";
|
|
4
|
-
import { createTestDb, truncateAllTables } from "../test/db.js";
|
|
5
3
|
import { Credit } from "../credits/credit.js";
|
|
6
4
|
import { CreditLedger } from "../credits/credit-ledger.js";
|
|
5
|
+
import { usageSummaries } from "../db/schema/meter-events.js";
|
|
6
|
+
import { createTestDb, truncateAllTables } from "../test/db.js";
|
|
7
7
|
import { runReconciliation } from "./reconciliation-cron.js";
|
|
8
8
|
import { DrizzleAdapterUsageRepository, DrizzleUsageSummaryRepository } from "./reconciliation-repository.js";
|
|
9
9
|
/** Today's date as YYYY-MM-DD (UTC). We use "today" as targetDate since the
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import crypto from "node:crypto";
|
|
2
2
|
import { afterAll, beforeAll, beforeEach, describe, expect, it } from "vitest";
|
|
3
|
-
import { createTestDb, seedUsageSummary, truncateAllTables } from "../test/db.js";
|
|
4
3
|
import { Credit } from "../credits/credit.js";
|
|
5
4
|
import { CreditLedger } from "../credits/credit-ledger.js";
|
|
5
|
+
import { createTestDb, seedUsageSummary, truncateAllTables } from "../test/db.js";
|
|
6
6
|
import { DrizzleAdapterUsageRepository, DrizzleUsageSummaryRepository } from "./reconciliation-repository.js";
|
|
7
7
|
let pool;
|
|
8
8
|
let db;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export type
|
|
1
|
+
export { type CsrfOptions, csrfProtection, validateCsrfOrigin } from "./csrf.js";
|
|
2
2
|
export { DrizzleRateLimitRepository } from "./drizzle-rate-limit-repository.js";
|
|
3
|
-
export { rateLimit, rateLimitByRoute, getClientIp, parseTrustedProxies, type RateLimitConfig, type RateLimitRule, } from "./rate-limit.js";
|
|
4
3
|
export { getClientIpFromContext } from "./get-client-ip.js";
|
|
5
|
-
export {
|
|
4
|
+
export { getClientIp, parseTrustedProxies, type RateLimitConfig, type RateLimitRule, rateLimit, rateLimitByRoute, } from "./rate-limit.js";
|
|
5
|
+
export type { IRateLimitRepository, RateLimitEntry } from "./rate-limit-repository.js";
|
package/dist/middleware/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
+
export { csrfProtection, validateCsrfOrigin } from "./csrf.js";
|
|
1
2
|
export { DrizzleRateLimitRepository } from "./drizzle-rate-limit-repository.js";
|
|
2
|
-
export { rateLimit, rateLimitByRoute, getClientIp, parseTrustedProxies, } from "./rate-limit.js";
|
|
3
3
|
export { getClientIpFromContext } from "./get-client-ip.js";
|
|
4
|
-
export {
|
|
4
|
+
export { getClientIp, parseTrustedProxies, rateLimit, rateLimitByRoute, } from "./rate-limit.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export type {
|
|
1
|
+
export type { ISecretAuditRepository, SecretAuditEvent } from "./audit-repository.js";
|
|
2
2
|
export { DrizzleSecretAuditRepository } from "./audit-repository.js";
|
|
3
|
-
export type { CredentialRow, CredentialSummaryRow,
|
|
3
|
+
export type { CredentialRow, CredentialSummaryRow, ICredentialMigrationAccess, ICredentialRepository, IMigrationTenantKeyAccess, InsertCredentialRow, } from "./credential-repository.js";
|
|
4
4
|
export { DrizzleCredentialRepository, DrizzleMigrationTenantKeyAccess } from "./credential-repository.js";
|
|
5
5
|
export type { RotationResult } from "./key-rotation.js";
|
|
6
6
|
export { reEncryptAllCredentials } from "./key-rotation.js";
|
package/dist/security/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export type
|
|
2
|
-
export {
|
|
3
|
-
export { deriveInstanceKey, generateInstanceKey, encrypt, decrypt } from "./encryption.js";
|
|
1
|
+
export { type AuthType, auditCredentialEncryption, type CreateCredentialInput, type CredentialRow, type CredentialSummary, type CredentialSummaryRow, CredentialVaultStore, type DecryptedCredential, DrizzleCredentialRepository, DrizzleMigrationTenantKeyAccess, DrizzleSecretAuditRepository, getVaultEncryptionKey, type ICredentialMigrationAccess, type ICredentialRepository, type ICredentialVaultStore, type IMigrationTenantKeyAccess, type InsertCredentialRow, type ISecretAuditRepository, type MigrationResult, migratePlaintextCredentials, type PlaintextFinding, type RotateCredentialInput, type RotationResult, reEncryptAllCredentials, type SecretAuditEvent, } from "./credential-vault/index.js";
|
|
2
|
+
export { decrypt, deriveInstanceKey, encrypt, generateInstanceKey } from "./encryption.js";
|
|
4
3
|
export { validateNodeHost } from "./host-validation.js";
|
|
5
|
-
export { assertSafeRedirectUrl } from "./redirect-allowlist.js";
|
|
6
4
|
export type { KeyLeakMatch } from "./key-audit.js";
|
|
7
5
|
export { scanForKeyLeaks } from "./key-audit.js";
|
|
8
|
-
export {
|
|
6
|
+
export { forwardSecretsToInstance, writeEncryptedSeed } from "./key-injection.js";
|
|
9
7
|
export { PROVIDER_ENDPOINTS, validateProviderKey } from "./key-validation.js";
|
|
10
|
-
export {
|
|
11
|
-
export {
|
|
8
|
+
export { assertSafeRedirectUrl } from "./redirect-allowlist.js";
|
|
9
|
+
export { ALL_CAPABILITIES, buildPooledKeysMap, type CapabilityName, CapabilitySettingsStore, DrizzleKeyResolutionRepository, DrizzleOrgMembershipRepository, type ICapabilitySettingsRepository, type IKeyResolutionRepository, type IOrgMembershipRepository, type ITenantKeyRepository, type OrgResolvedKey, type ResolvedKey, resolveApiKey, resolveApiKeyWithOrgFallback, type TenantApiKey, type TenantCapabilitySetting, TenantKeyRepository, } from "./tenant-keys/index.js";
|
|
10
|
+
export type { EncryptedPayload, Provider, ProviderEndpoint, ValidateKeyRequest, ValidateKeyResponse, WriteSecretsRequest, } from "./types.js";
|
|
11
|
+
export { providerSchema, validateKeyRequestSchema, writeSecretsRequestSchema } from "./types.js";
|
package/dist/security/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
1
|
+
// Credential vault
|
|
2
|
+
export { auditCredentialEncryption, CredentialVaultStore, DrizzleCredentialRepository, DrizzleMigrationTenantKeyAccess, DrizzleSecretAuditRepository, getVaultEncryptionKey, migratePlaintextCredentials, reEncryptAllCredentials, } from "./credential-vault/index.js";
|
|
3
|
+
export { decrypt, deriveInstanceKey, encrypt, generateInstanceKey } from "./encryption.js";
|
|
3
4
|
export { validateNodeHost } from "./host-validation.js";
|
|
4
|
-
export { assertSafeRedirectUrl } from "./redirect-allowlist.js";
|
|
5
5
|
export { scanForKeyLeaks } from "./key-audit.js";
|
|
6
|
-
export {
|
|
6
|
+
export { forwardSecretsToInstance, writeEncryptedSeed } from "./key-injection.js";
|
|
7
7
|
export { PROVIDER_ENDPOINTS, validateProviderKey } from "./key-validation.js";
|
|
8
|
-
|
|
9
|
-
export { DrizzleSecretAuditRepository, DrizzleCredentialRepository, DrizzleMigrationTenantKeyAccess, reEncryptAllCredentials, migratePlaintextCredentials, auditCredentialEncryption, CredentialVaultStore, getVaultEncryptionKey, } from "./credential-vault/index.js";
|
|
8
|
+
export { assertSafeRedirectUrl } from "./redirect-allowlist.js";
|
|
10
9
|
// Tenant keys
|
|
11
|
-
export {
|
|
10
|
+
export { ALL_CAPABILITIES, buildPooledKeysMap, CapabilitySettingsStore, DrizzleKeyResolutionRepository, DrizzleOrgMembershipRepository, resolveApiKey, resolveApiKeyWithOrgFallback, TenantKeyRepository, } from "./tenant-keys/index.js";
|
|
11
|
+
export { providerSchema, validateKeyRequestSchema, writeSecretsRequestSchema } from "./types.js";
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
]
|
|
1
|
+
const STATIC_ORIGINS = ["https://app.wopr.bot", "https://wopr.network"];
|
|
2
|
+
function getAllowedOrigins() {
|
|
3
|
+
return [
|
|
4
|
+
...STATIC_ORIGINS,
|
|
5
|
+
...(process.env.NODE_ENV !== "production" ? ["http://localhost:3000", "http://localhost:3001"] : []),
|
|
6
|
+
...(process.env.PLATFORM_UI_URL ? [process.env.PLATFORM_UI_URL] : []),
|
|
7
|
+
...(process.env.NODE_ENV !== "production" ? ["https://example.com"] : []),
|
|
8
|
+
];
|
|
9
|
+
}
|
|
8
10
|
/**
|
|
9
11
|
* Throws if `url` is not rooted at one of the allowed origins.
|
|
10
12
|
* Comparison is scheme + host (origin), not prefix string match,
|
|
@@ -22,7 +24,7 @@ export function assertSafeRedirectUrl(url) {
|
|
|
22
24
|
throw new Error("Invalid redirect URL");
|
|
23
25
|
}
|
|
24
26
|
const origin = parsed.origin;
|
|
25
|
-
const allowed =
|
|
27
|
+
const allowed = getAllowedOrigins().some((o) => {
|
|
26
28
|
try {
|
|
27
29
|
return origin === new URL(o).origin;
|
|
28
30
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
export type { CapabilityName, ICapabilitySettingsRepository, TenantCapabilitySetting, } from "./capability-settings-store.js";
|
|
2
|
+
export { ALL_CAPABILITIES, CapabilitySettingsStore } from "./capability-settings-store.js";
|
|
3
|
+
export type { ResolvedKey } from "./key-resolution.js";
|
|
4
|
+
export { buildPooledKeysMap, resolveApiKey } from "./key-resolution.js";
|
|
1
5
|
export type { IKeyResolutionRepository } from "./key-resolution-repository.js";
|
|
2
6
|
export { DrizzleKeyResolutionRepository } from "./key-resolution-repository.js";
|
|
3
|
-
export type { ResolvedKey } from "./key-resolution.js";
|
|
4
|
-
export { resolveApiKey, buildPooledKeysMap } from "./key-resolution.js";
|
|
5
|
-
export type { TenantApiKey, ITenantKeyRepository } from "./tenant-key-repository.js";
|
|
6
|
-
export { TenantKeyRepository } from "./tenant-key-repository.js";
|
|
7
|
-
export type { CapabilityName, TenantCapabilitySetting, ICapabilitySettingsRepository } from "./capability-settings-store.js";
|
|
8
|
-
export { ALL_CAPABILITIES, CapabilitySettingsStore } from "./capability-settings-store.js";
|
|
9
7
|
export type { IOrgMembershipRepository, OrgResolvedKey } from "./org-key-resolution.js";
|
|
10
8
|
export { DrizzleOrgMembershipRepository, resolveApiKeyWithOrgFallback } from "./org-key-resolution.js";
|
|
9
|
+
export type { ITenantKeyRepository, TenantApiKey } from "./tenant-key-repository.js";
|
|
10
|
+
export { TenantKeyRepository } from "./tenant-key-repository.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { DrizzleKeyResolutionRepository } from "./key-resolution-repository.js";
|
|
2
|
-
export { resolveApiKey, buildPooledKeysMap } from "./key-resolution.js";
|
|
3
|
-
export { TenantKeyRepository } from "./tenant-key-repository.js";
|
|
4
1
|
export { ALL_CAPABILITIES, CapabilitySettingsStore } from "./capability-settings-store.js";
|
|
2
|
+
export { buildPooledKeysMap, resolveApiKey } from "./key-resolution.js";
|
|
3
|
+
export { DrizzleKeyResolutionRepository } from "./key-resolution-repository.js";
|
|
5
4
|
export { DrizzleOrgMembershipRepository, resolveApiKeyWithOrgFallback } from "./org-key-resolution.js";
|
|
5
|
+
export { TenantKeyRepository } from "./tenant-key-repository.js";
|
package/dist/tenancy/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export type {
|
|
1
|
+
export type { IOrgRepository, Tenant } from "./drizzle-org-repository.js";
|
|
2
2
|
export { DrizzleOrgRepository } from "./drizzle-org-repository.js";
|
|
3
|
-
export type {
|
|
3
|
+
export type { IOrgMemberRepository, OrgInviteRow, OrgMemberRow } from "./org-member-repository.js";
|
|
4
4
|
export { DrizzleOrgMemberRepository } from "./org-member-repository.js";
|
|
5
|
-
export type {
|
|
5
|
+
export type { OrgInvitePublic, OrgMemberWithUser, OrgServiceOptions, OrgWithMembers } from "./org-service.js";
|
|
6
6
|
export { OrgService } from "./org-service.js";
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* IOrgMemberRepository (members/invites data).
|
|
5
5
|
*/
|
|
6
6
|
import type { PlatformDb } from "../db/index.js";
|
|
7
|
-
import type { IOrgMemberRepository, OrgInviteRow } from "./org-member-repository.js";
|
|
8
7
|
import type { IOrgRepository, Tenant } from "./drizzle-org-repository.js";
|
|
8
|
+
import type { IOrgMemberRepository, OrgInviteRow } from "./org-member-repository.js";
|
|
9
9
|
export interface OrgWithMembers extends Tenant {
|
|
10
10
|
members: OrgMemberWithUser[];
|
|
11
11
|
invites: OrgInvitePublic[];
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { TRPCError } from "@trpc/server";
|
|
2
2
|
import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
-
import { DrizzleOrgMemberRepository } from "./org-member-repository.js";
|
|
4
3
|
import { createTestDb, truncateAllTables } from "../test/db.js";
|
|
5
4
|
import { DrizzleOrgRepository } from "./drizzle-org-repository.js";
|
|
5
|
+
import { DrizzleOrgMemberRepository } from "./org-member-repository.js";
|
|
6
6
|
import { OrgService } from "./org-service.js";
|
|
7
7
|
async function setup(db) {
|
|
8
8
|
const orgRepo = new DrizzleOrgRepository(db);
|
package/dist/trpc/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { adminProcedure, createCallerFactory, orgMemberProcedure, protectedProcedure, publicProcedure, router, setTrpcOrgMemberRepo, type TRPCContext, tenantProcedure, } from "./init.js";
|
package/dist/trpc/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { adminProcedure, createCallerFactory, orgMemberProcedure, protectedProcedure, publicProcedure, router, setTrpcOrgMemberRepo, tenantProcedure, } from "./init.js";
|
package/dist/trpc/init.test.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { describe, expect, it, vi
|
|
2
|
-
import {
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { adminProcedure, createCallerFactory, orgMemberProcedure, protectedProcedure, publicProcedure, router, setTrpcOrgMemberRepo, tenantProcedure, } from "./init.js";
|
|
3
3
|
// ---------------------------------------------------------------------------
|
|
4
4
|
// Helpers
|
|
5
5
|
// ---------------------------------------------------------------------------
|
|
@@ -28,9 +28,7 @@ const appRouter = router({
|
|
|
28
28
|
protectedHello: protectedProcedure.query(() => "protected-ok"),
|
|
29
29
|
adminHello: adminProcedure.query(() => "admin-ok"),
|
|
30
30
|
tenantHello: tenantProcedure.query(() => "tenant-ok"),
|
|
31
|
-
orgAction: orgMemberProcedure
|
|
32
|
-
.input((v) => v)
|
|
33
|
-
.mutation(() => "org-ok"),
|
|
31
|
+
orgAction: orgMemberProcedure.input((v) => v).mutation(() => "org-ok"),
|
|
34
32
|
});
|
|
35
33
|
const createCaller = createCallerFactory(appRouter);
|
|
36
34
|
// ---------------------------------------------------------------------------
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wopr-network/platform-core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"@trpc/server": "^11.12.0",
|
|
46
46
|
"@types/node": "^25.4.0",
|
|
47
47
|
"@types/pg": "^8.18.0",
|
|
48
|
+
"@vitest/coverage-v8": "^4.0.18",
|
|
48
49
|
"@wopr-network/semantic-release-config": "^1.0.0",
|
|
49
50
|
"better-auth": "^1.5.4",
|
|
50
51
|
"drizzle-kit": "^0.31.9",
|
package/src/admin/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export type { IAdminAuditLogRepository } from "./admin-audit-log-repository.js";
|
|
2
2
|
export { DrizzleAdminAuditLogRepository } from "./admin-audit-log-repository.js";
|
|
3
|
-
export type { AuditCategory, AuditEntry,
|
|
3
|
+
export type { AdminAuditLogRow, AuditCategory, AuditEntry, AuditFilters } from "./audit-log.js";
|
|
4
4
|
export { AdminAuditLog } from "./audit-log.js";
|
|
5
5
|
export type { Role, UserRoleRow } from "./role-store.js";
|
|
6
6
|
export { isValidRole, RoleStore } from "./role-store.js";
|