deepspace 0.5.0 → 0.5.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/dist/server.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import { LanguageModel, ToolSet, ModelMessage } from 'ai';
2
2
  import * as Y from 'yjs';
3
+ import * as zod_v4_core from 'zod/v4/core';
4
+ import * as zod from 'zod';
3
5
  import * as better_auth from 'better-auth';
4
6
  import { betterAuth } from 'better-auth';
5
7
  import * as better_auth_plugins from 'better-auth/plugins';
@@ -649,11 +651,11 @@ declare function composioTools(env: ApiWorkerEnv, options: ComposioToolsOptions)
649
651
  * `null` on any non-2xx — callers should treat as "no preview available"
650
652
  * and surface their own fallback UX.
651
653
  *
652
- * Auth is the same HMAC-of-appName pattern `/internal/files` uses:
653
- * x-app-identity-token = hmac(PLATFORM_IDENTITY_SECRET, APP_NAME)
654
- * x-app-name = APP_NAME
654
+ * Auth is the same HMAC-of-appId pattern `/internal/files` uses:
655
+ * x-app-identity-token = hmac(PLATFORM_IDENTITY_SECRET, DEEPSPACE_APP_ID)
656
+ * x-app-id = DEEPSPACE_APP_ID
655
657
  *
656
- * Apps already have both as bindings (APP_IDENTITY_TOKEN + APP_NAME),
658
+ * Apps already have both as bindings (APP_IDENTITY_TOKEN + DEEPSPACE_APP_ID),
657
659
  * so this helper is a thin wrapper — no extra secrets to manage.
658
660
  */
659
661
 
@@ -668,8 +670,10 @@ interface ScreenshotOptions {
668
670
  fullPage?: boolean;
669
671
  }
670
672
  interface ScreenshotEnv extends PlatformWorkerEnv {
671
- APP_NAME: string;
672
- APP_IDENTITY_TOKEN: string;
673
+ /** Immutable app id — the identity the platform verifies (HMAC input). */
674
+ DEEPSPACE_APP_ID: string;
675
+ /** Absent until the app's first deploy registers it — see appendAppIdentity. */
676
+ APP_IDENTITY_TOKEN?: string;
673
677
  }
674
678
  interface ScreenshotResult {
675
679
  /** PNG bytes. */
@@ -3050,9 +3054,42 @@ declare function verifyJwt(config: JwtVerifierConfig, token: string | null | und
3050
3054
  */
3051
3055
  declare function computeHmacHex(secret: string, payload: string): Promise<string>;
3052
3056
  declare function timingSafeEqualHex(a: string, b: string): Promise<boolean>;
3057
+ /**
3058
+ * Constant-time equality for arbitrary strings (hash-then-compare: SHA-256
3059
+ * normalizes lengths so neither length nor content short-circuits). The one
3060
+ * implementation every worker's bearer/secret checks share.
3061
+ */
3062
+ declare function timingSafeEqualStrings(a: string, b: string): Promise<boolean>;
3053
3063
 
3054
3064
  declare function decodeJwtPayload(token: string | null | undefined): TokenDebugInfo | undefined;
3055
3065
 
3066
+ /**
3067
+ * Test-account identification, shared by every platform worker.
3068
+ *
3069
+ * Test accounts (created via `deepspace test-accounts`) are real Better Auth
3070
+ * users demarcated three ways, and a caller may present as any of them
3071
+ * depending on where the check runs:
3072
+ * - their email always ends with @deepspace.test (enforced at creation)
3073
+ * - their JWTs carry `isTestAccount: true` (minted by the auth-worker,
3074
+ * the source of truth)
3075
+ * - their billing profile's subscription tier is 'test' (mirrored by the
3076
+ * api-worker on every authenticated request)
3077
+ *
3078
+ * Gate anything a test account must not do with these helpers rather than
3079
+ * hand-rolled string comparisons, so the policy stays in one place. Prefer
3080
+ * checking the claim when a verified JWT is at hand, and the tier as the
3081
+ * fallback for persisted state that may outlive a claim (e.g. rows written
3082
+ * before a guard existed).
3083
+ */
3084
+
3085
+ declare const TEST_ACCOUNT_EMAIL_SUFFIX = "@deepspace.test";
3086
+ /** True when the email belongs to a test account (case-insensitive). */
3087
+ declare function isTestAccountEmail(email: string | null | undefined): boolean;
3088
+ /** True when verified JWT claims identify the caller as a test account. */
3089
+ declare function isTestAccountClaims(claims: JwtClaims | Record<string, unknown> | null | undefined): boolean;
3090
+ /** True when a billing subscription tier marks a test account. */
3091
+ declare function isTestAccountTier(tier: string | null | undefined): boolean;
3092
+
3056
3093
  interface DeepSpaceAuthConfig {
3057
3094
  /** D1 database binding */
3058
3095
  database: D1Database;
@@ -3094,6 +3131,7 @@ interface DeepSpaceAuthConfig {
3094
3131
  declare function createDeepSpaceAuth(config: DeepSpaceAuthConfig): better_auth.Auth<{
3095
3132
  plugins: [{
3096
3133
  id: "organization";
3134
+ version: string;
3097
3135
  endpoints: better_auth_plugins.OrganizationEndpoints<better_auth_plugins.OrganizationOptions & {
3098
3136
  teams: {
3099
3137
  enabled: true;
@@ -3230,6 +3268,7 @@ declare function createDeepSpaceAuth(config: DeepSpaceAuthConfig): better_auth.A
3230
3268
  INVITATION_NOT_FOUND: better_auth.RawError<"INVITATION_NOT_FOUND">;
3231
3269
  YOU_ARE_NOT_THE_RECIPIENT_OF_THE_INVITATION: better_auth.RawError<"YOU_ARE_NOT_THE_RECIPIENT_OF_THE_INVITATION">;
3232
3270
  EMAIL_VERIFICATION_REQUIRED_BEFORE_ACCEPTING_OR_REJECTING_INVITATION: better_auth.RawError<"EMAIL_VERIFICATION_REQUIRED_BEFORE_ACCEPTING_OR_REJECTING_INVITATION">;
3271
+ EMAIL_VERIFICATION_REQUIRED_FOR_INVITATION: better_auth.RawError<"EMAIL_VERIFICATION_REQUIRED_FOR_INVITATION">;
3233
3272
  YOU_ARE_NOT_ALLOWED_TO_CANCEL_THIS_INVITATION: better_auth.RawError<"YOU_ARE_NOT_ALLOWED_TO_CANCEL_THIS_INVITATION">;
3234
3273
  INVITER_IS_NO_LONGER_A_MEMBER_OF_THE_ORGANIZATION: better_auth.RawError<"INVITER_IS_NO_LONGER_A_MEMBER_OF_THE_ORGANIZATION">;
3235
3274
  YOU_ARE_NOT_ALLOWED_TO_INVITE_USER_WITH_THIS_ROLE: better_auth.RawError<"YOU_ARE_NOT_ALLOWED_TO_INVITE_USER_WITH_THIS_ROLE">;
@@ -3264,6 +3303,7 @@ declare function createDeepSpaceAuth(config: DeepSpaceAuthConfig): better_auth.A
3264
3303
  ROLE_NAME_IS_ALREADY_TAKEN: better_auth.RawError<"ROLE_NAME_IS_ALREADY_TAKEN">;
3265
3304
  CANNOT_DELETE_A_PRE_DEFINED_ROLE: better_auth.RawError<"CANNOT_DELETE_A_PRE_DEFINED_ROLE">;
3266
3305
  ROLE_IS_ASSIGNED_TO_MEMBERS: better_auth.RawError<"ROLE_IS_ASSIGNED_TO_MEMBERS">;
3306
+ INVALID_TEAM_ID: better_auth.RawError<"INVALID_TEAM_ID">;
3267
3307
  };
3268
3308
  options: NoInfer<better_auth_plugins.OrganizationOptions & {
3269
3309
  teams: {
@@ -3275,13 +3315,17 @@ declare function createDeepSpaceAuth(config: DeepSpaceAuthConfig): better_auth.A
3275
3315
  }>;
3276
3316
  }, {
3277
3317
  id: "two-factor";
3318
+ version: string;
3278
3319
  endpoints: {
3279
3320
  enableTwoFactor: better_auth.StrictEndpoint<"/two-factor/enable", {
3280
3321
  method: "POST";
3281
- body: better_auth.ZodObject<{
3282
- password: better_auth.ZodString;
3283
- issuer: better_auth.ZodOptional<better_auth.ZodString>;
3284
- }, better_auth.$strip>;
3322
+ body: zod.ZodObject<{
3323
+ password: zod.ZodOptional<zod.ZodString>;
3324
+ issuer: zod.ZodOptional<zod.ZodString>;
3325
+ }, zod_v4_core.$strip> | zod.ZodObject<{
3326
+ password: zod.ZodString;
3327
+ issuer: zod.ZodOptional<zod.ZodString>;
3328
+ }, zod_v4_core.$strip>;
3285
3329
  use: ((inputContext: better_auth.MiddlewareInputContext<better_auth.MiddlewareOptions>) => Promise<{
3286
3330
  session: {
3287
3331
  session: Record<string, any> & {
@@ -3342,9 +3386,11 @@ declare function createDeepSpaceAuth(config: DeepSpaceAuthConfig): better_auth.A
3342
3386
  }>;
3343
3387
  disableTwoFactor: better_auth.StrictEndpoint<"/two-factor/disable", {
3344
3388
  method: "POST";
3345
- body: better_auth.ZodObject<{
3346
- password: better_auth.ZodString;
3347
- }, better_auth.$strip>;
3389
+ body: zod.ZodObject<{
3390
+ password: zod.ZodOptional<zod.ZodString>;
3391
+ }, zod_v4_core.$strip> | zod.ZodObject<{
3392
+ password: zod.ZodString;
3393
+ }, zod_v4_core.$strip>;
3348
3394
  use: ((inputContext: better_auth.MiddlewareInputContext<better_auth.MiddlewareOptions>) => Promise<{
3349
3395
  session: {
3350
3396
  session: Record<string, any> & {
@@ -3396,11 +3442,11 @@ declare function createDeepSpaceAuth(config: DeepSpaceAuthConfig): better_auth.A
3396
3442
  }>;
3397
3443
  verifyBackupCode: better_auth.StrictEndpoint<"/two-factor/verify-backup-code", {
3398
3444
  method: "POST";
3399
- body: better_auth.ZodObject<{
3400
- code: better_auth.ZodString;
3401
- disableSession: better_auth.ZodOptional<better_auth.ZodBoolean>;
3402
- trustDevice: better_auth.ZodOptional<better_auth.ZodBoolean>;
3403
- }, better_auth.$strip>;
3445
+ body: zod.ZodObject<{
3446
+ code: zod.ZodString;
3447
+ disableSession: zod.ZodOptional<zod.ZodBoolean>;
3448
+ trustDevice: zod.ZodOptional<zod.ZodBoolean>;
3449
+ }, zod_v4_core.$strip>;
3404
3450
  metadata: {
3405
3451
  openapi: {
3406
3452
  description: string;
@@ -3507,9 +3553,11 @@ declare function createDeepSpaceAuth(config: DeepSpaceAuthConfig): better_auth.A
3507
3553
  }>;
3508
3554
  generateBackupCodes: better_auth.StrictEndpoint<"/two-factor/generate-backup-codes", {
3509
3555
  method: "POST";
3510
- body: better_auth.ZodObject<{
3511
- password: better_auth.ZodString;
3512
- }, better_auth.$strip>;
3556
+ body: zod.ZodObject<{
3557
+ password: zod.ZodOptional<zod.ZodString>;
3558
+ }, zod_v4_core.$strip> | zod.ZodObject<{
3559
+ password: zod.ZodString;
3560
+ }, zod_v4_core.$strip>;
3513
3561
  use: ((inputContext: better_auth.MiddlewareInputContext<better_auth.MiddlewareOptions>) => Promise<{
3514
3562
  session: {
3515
3563
  session: Record<string, any> & {
@@ -3571,18 +3619,18 @@ declare function createDeepSpaceAuth(config: DeepSpaceAuthConfig): better_auth.A
3571
3619
  }>;
3572
3620
  viewBackupCodes: better_auth.StrictEndpoint<string, {
3573
3621
  method: "POST";
3574
- body: better_auth.ZodObject<{
3575
- userId: better_auth.ZodCoercedString<unknown>;
3576
- }, better_auth.$strip>;
3622
+ body: zod.ZodObject<{
3623
+ userId: zod.ZodCoercedString<unknown>;
3624
+ }, zod_v4_core.$strip>;
3577
3625
  }, {
3578
3626
  status: boolean;
3579
3627
  backupCodes: string[];
3580
3628
  }>;
3581
3629
  sendTwoFactorOTP: better_auth.StrictEndpoint<"/two-factor/send-otp", {
3582
3630
  method: "POST";
3583
- body: better_auth.ZodOptional<better_auth.ZodObject<{
3584
- trustDevice: better_auth.ZodOptional<better_auth.ZodBoolean>;
3585
- }, better_auth.$strip>>;
3631
+ body: zod.ZodOptional<zod.ZodObject<{
3632
+ trustDevice: zod.ZodOptional<zod.ZodBoolean>;
3633
+ }, zod_v4_core.$strip>>;
3586
3634
  metadata: {
3587
3635
  openapi: {
3588
3636
  summary: string;
@@ -3611,10 +3659,10 @@ declare function createDeepSpaceAuth(config: DeepSpaceAuthConfig): better_auth.A
3611
3659
  }>;
3612
3660
  verifyTwoFactorOTP: better_auth.StrictEndpoint<"/two-factor/verify-otp", {
3613
3661
  method: "POST";
3614
- body: better_auth.ZodObject<{
3615
- code: better_auth.ZodString;
3616
- trustDevice: better_auth.ZodOptional<better_auth.ZodBoolean>;
3617
- }, better_auth.$strip>;
3662
+ body: zod.ZodObject<{
3663
+ code: zod.ZodString;
3664
+ trustDevice: zod.ZodOptional<zod.ZodBoolean>;
3665
+ }, zod_v4_core.$strip>;
3618
3666
  metadata: {
3619
3667
  openapi: {
3620
3668
  summary: string;
@@ -3700,9 +3748,9 @@ declare function createDeepSpaceAuth(config: DeepSpaceAuthConfig): better_auth.A
3700
3748
  }>;
3701
3749
  generateTOTP: better_auth.StrictEndpoint<string, {
3702
3750
  method: "POST";
3703
- body: better_auth.ZodObject<{
3704
- secret: better_auth.ZodString;
3705
- }, better_auth.$strip>;
3751
+ body: zod.ZodObject<{
3752
+ secret: zod.ZodString;
3753
+ }, zod_v4_core.$strip>;
3706
3754
  metadata: {
3707
3755
  openapi: {
3708
3756
  summary: string;
@@ -3754,9 +3802,11 @@ declare function createDeepSpaceAuth(config: DeepSpaceAuthConfig): better_auth.A
3754
3802
  };
3755
3803
  };
3756
3804
  }>)[];
3757
- body: better_auth.ZodObject<{
3758
- password: better_auth.ZodString;
3759
- }, better_auth.$strip>;
3805
+ body: zod.ZodObject<{
3806
+ password: zod.ZodOptional<zod.ZodString>;
3807
+ }, zod_v4_core.$strip> | zod.ZodObject<{
3808
+ password: zod.ZodString;
3809
+ }, zod_v4_core.$strip>;
3760
3810
  metadata: {
3761
3811
  openapi: {
3762
3812
  summary: string;
@@ -3785,10 +3835,10 @@ declare function createDeepSpaceAuth(config: DeepSpaceAuthConfig): better_auth.A
3785
3835
  }>;
3786
3836
  verifyTOTP: better_auth.StrictEndpoint<"/two-factor/verify-totp", {
3787
3837
  method: "POST";
3788
- body: better_auth.ZodObject<{
3789
- code: better_auth.ZodString;
3790
- trustDevice: better_auth.ZodOptional<better_auth.ZodBoolean>;
3791
- }, better_auth.$strip>;
3838
+ body: zod.ZodObject<{
3839
+ code: zod.ZodString;
3840
+ trustDevice: zod.ZodOptional<zod.ZodBoolean>;
3841
+ }, zod_v4_core.$strip>;
3792
3842
  metadata: {
3793
3843
  openapi: {
3794
3844
  summary: string;
@@ -3834,6 +3884,7 @@ declare function createDeepSpaceAuth(config: DeepSpaceAuthConfig): better_auth.A
3834
3884
  matcher(context: better_auth.HookEndpointContext): boolean;
3835
3885
  handler: (inputContext: better_auth.MiddlewareInputContext<better_auth.MiddlewareOptions>) => Promise<{
3836
3886
  twoFactorRedirect: boolean;
3887
+ twoFactorMethods: string[];
3837
3888
  } | undefined>;
3838
3889
  }[];
3839
3890
  };
@@ -3871,6 +3922,25 @@ declare function createDeepSpaceAuth(config: DeepSpaceAuthConfig): better_auth.A
3871
3922
  };
3872
3923
  index: true;
3873
3924
  };
3925
+ verified: {
3926
+ type: "boolean";
3927
+ required: false;
3928
+ defaultValue: true;
3929
+ input: false;
3930
+ };
3931
+ failedVerificationCount: {
3932
+ type: "number";
3933
+ required: false;
3934
+ defaultValue: number;
3935
+ input: false;
3936
+ returned: false;
3937
+ };
3938
+ lockedUntil: {
3939
+ type: "date";
3940
+ required: false;
3941
+ input: false;
3942
+ returned: false;
3943
+ };
3874
3944
  };
3875
3945
  };
3876
3946
  };
@@ -3888,6 +3958,7 @@ declare function createDeepSpaceAuth(config: DeepSpaceAuthConfig): better_auth.A
3888
3958
  INVALID_BACKUP_CODE: better_auth.RawError<"INVALID_BACKUP_CODE">;
3889
3959
  INVALID_CODE: better_auth.RawError<"INVALID_CODE">;
3890
3960
  TOO_MANY_ATTEMPTS_REQUEST_NEW_CODE: better_auth.RawError<"TOO_MANY_ATTEMPTS_REQUEST_NEW_CODE">;
3961
+ ACCOUNT_TEMPORARILY_LOCKED: better_auth.RawError<"ACCOUNT_TEMPORARILY_LOCKED">;
3891
3962
  INVALID_TWO_FACTOR_COOKIE: better_auth.RawError<"INVALID_TWO_FACTOR_COOKIE">;
3892
3963
  };
3893
3964
  }];
@@ -3961,8 +4032,10 @@ interface SubscriptionRead {
3961
4032
  plans: PlanInfo[];
3962
4033
  }
3963
4034
  interface StarterAppEnv$1 extends ApiWorkerEnv {
3964
- APP_IDENTITY_TOKEN: string;
3965
- APP_NAME: string;
4035
+ /** Absent until the app's first deploy registers it — see appendAppIdentity. */
4036
+ APP_IDENTITY_TOKEN?: string;
4037
+ /** Immutable app id — the identity the platform verifies (HMAC input). */
4038
+ DEEPSPACE_APP_ID: string;
3966
4039
  }
3967
4040
  declare function getSubscription(c: Context<{
3968
4041
  Bindings: StarterAppEnv$1;
@@ -4048,8 +4121,10 @@ declare class CancelSubscriptionError extends Error {
4048
4121
  }
4049
4122
 
4050
4123
  interface StarterAppEnv extends ApiWorkerEnv {
4051
- APP_IDENTITY_TOKEN: string;
4052
- APP_NAME: string;
4124
+ /** Absent until the app's first deploy registers it — see appendAppIdentity. */
4125
+ APP_IDENTITY_TOKEN?: string;
4126
+ /** Immutable app id — the identity the platform verifies (HMAC input). */
4127
+ DEEPSPACE_APP_ID: string;
4053
4128
  }
4054
4129
  interface RefundResult {
4055
4130
  success: boolean;
@@ -4071,4 +4146,4 @@ declare class RefundError extends Error {
4071
4146
  constructor(message: string, status: number);
4072
4147
  }
4073
4148
 
4074
- export { AI_CHATS_SCHEMA, AI_MESSAGES_SCHEMA, ALLOWED_BINDING_TYPES, APP_NAME_RULES, AUTO_PROVISIONABLE_TYPES, AUTO_PROVISION_SENTINEL, type ActionContext, type ActionHandler, type ActionResult, type ActionTools, type ApiWorkerEnv, type AppNameResolution, type AppNameValidation, type AuthWorkerEnv, BASE_USERS_SCHEMA, BUILT_IN_TOOLS, BaseRoom, CHANNELS_SCHEMA, CHANNEL_INVITATIONS_SCHEMA, CHANNEL_MEMBERS_SCHEMA, CONVERSATION_SCHEMAS, COST_RATES, CancelSubscriptionError, type CancelSubscriptionOpts, type CancelSubscriptionResult, CanvasRoom, type CanvasShape, type ChatContextConfig, type ChatMessageRow, type ChatRow, type ChatTurn, type CollectionPermissionSummary, type CollectionSchema, type ColumnDefinition, type ColumnInterpretation, type ComposioToolsOptions, type ConvMemberData, type ConvMessageData, type ConvReactionData, type ConvReadCursorData, type ConvVoteData, type ConversationStateData, type CronContext, type CronExecution, CronRoom, type CronRoomConfig, type CronTask, type CustomBinding, type CustomBindingManifest, DEFAULT_CONTEXT_CONFIG, DEFAULT_DO_MANIFEST, DEFAULT_QUERY_LIMIT, DIRECTORY_SCHEMAS, type DOBindings, type DOManifest, type DOManifestEntry, type DebugApiContext, type DeepSpaceAIEnv, type DeepSpaceAIOptions, type DeepSpaceAuth, type DeepSpaceAuthConfig, type DirectoryCommunityData, type DirectoryConversationData, type DirectoryMembershipData, type DirectoryPostData, type DoMigrationDirective, type DoMigrationPlan, type ExistingDOBinding, GLOBAL_DO_TYPES, GLOBAL_DO_TYPE_NAMES, type GameInput, GameRoom, type GameRoomConfig, type GetActionData, type GlobalDOType, type Job, type JobContext, JobRoom, type JobRoomConfig, type JobStatus, type JwtClaims, type JwtVerifierConfig, MESSAGES_SCHEMA, type MutateActionData, type PermissionAnalysis, type PermissionContext, type PermissionLevel, type PermissionSource, type PlanInfo, type PlatformWorkerEnv, type Player, type PrefixResult, type PresencePeer, PresenceRoom, type QueryActionData, REACTIONS_SCHEMA, READ_RECEIPTS_SCHEMA, RESERVED_BINDING_NAMES, RESERVED_COLLECTION_NAMES, type RecordContext, RecordRoom, type RecordRoomConfig, RefundError, type RefundOpts, type RefundResult, type ResolvedColumn, type ResolvedPermission, type RolePermissions, type RunMigrationsResult, SYSTEM_COLLECTION_SCHEMAS, SYSTEM_MANAGED_COLUMNS, SchemaRegistry, type ScopeContext, type ScopedR2Auth, type ScopedR2Config, type ScopedR2Handler, type ScreenshotEnv, type ScreenshotOptions, type ScreenshotResult, type SharedConnection, type StoredRecord, SubscriptionAuthError, type SubscriptionContext, type SubscriptionRead, SubscriptionRequiredError, type SubscriptionStatus, type Summarizer, type TokenDebugInfo, type ToolResult, type ToolSchema, type ToolsApiContext, USERS_COLUMNS, type User, type UserAttachment, type UserContext, VOTING_SCHEMAS, type ValidationError, type VerifiedAuth, type VerifyOutcome, type VerifyResult, type Viewport, WORKSPACE_SCHEMAS, type YjsContext, YjsRoom, analyzePermissions, apiWorkerFetch, appendMessage, applyAiToolDefaults, applySlidingWindow, authWorkerFetch, bindingManifestFromOutputConfig, broadcastChange, broadcastYjsUpdate, buildCronContext, buildTableSelect, buildUiParts, canCreate, canDelete, canRead, canUpdate, cancelSubscription, capToolResultSize, captureScreenshot, checkFieldPermissions, coerceValue, collectionTableName, columnId, composioTools, computeDoMigration, computeHmacHex, createChat, createDeepSpaceAI, createDeepSpaceAuth, createScopedR2Handler, dataToColumnValues, decodeJwtPayload, deleteChatCascade, deleteRecord, enqueueJob, executeQuery, getAllUsers, getChat, getGlobalDOSchemas, getGlobalDOType, getOrCreateYjsDoc, getRecord, getRolePermissions, getSubscription, getUser, getYjsDocKey, handleApiRequest, handleDelete, handlePut, handleSetRole, handleSubscribe, handleToolsRequest, handleUnsubscribe, handleUserList, handleUserUpdate, handleYjsBinaryMessage, handleYjsJoin, handleYjsLeave, isAutoProvision, isOwner, lintSchema, loadMessages, makeDefaultSummarizer, meterAi, meterUsage, meterVectorize, noopPermissionContext, platformWorkerFetch, prepareMessagesWithCompaction, priceBindingUsageEvent, putRecord, readRecord, recordMatchesSubscription, refundInvoice, registerUser, requireSubscription, resolveAppName, resolveColumn, rowToData, runMigrations, saveYjsDoc, timingSafeEqualHex, totalChars, truncateOldToolResults, turnsToCoreMessages, unwrapToolOutput, updateChat, validateAppName, validateBindingManifest, validateDoManifest, verifyJwt, workspaceAccountsSchema, workspaceContentSharesSchema, workspaceEmailHandlesSchema, workspaceFormResponsesSchema, workspacePeopleSchema, workspaceProjectsSchema, workspaceTagsSchema, workspaceTasksSchema, workspaceTeamMembersSchema, workspaceTeamsSchema, workspaceTransactionsSchema };
4149
+ export { AI_CHATS_SCHEMA, AI_MESSAGES_SCHEMA, ALLOWED_BINDING_TYPES, APP_NAME_RULES, AUTO_PROVISIONABLE_TYPES, AUTO_PROVISION_SENTINEL, type ActionContext, type ActionHandler, type ActionResult, type ActionTools, type ApiWorkerEnv, type AppNameResolution, type AppNameValidation, type AuthWorkerEnv, BASE_USERS_SCHEMA, BUILT_IN_TOOLS, BaseRoom, CHANNELS_SCHEMA, CHANNEL_INVITATIONS_SCHEMA, CHANNEL_MEMBERS_SCHEMA, CONVERSATION_SCHEMAS, COST_RATES, CancelSubscriptionError, type CancelSubscriptionOpts, type CancelSubscriptionResult, CanvasRoom, type CanvasShape, type ChatContextConfig, type ChatMessageRow, type ChatRow, type ChatTurn, type CollectionPermissionSummary, type CollectionSchema, type ColumnDefinition, type ColumnInterpretation, type ComposioToolsOptions, type ConvMemberData, type ConvMessageData, type ConvReactionData, type ConvReadCursorData, type ConvVoteData, type ConversationStateData, type CronContext, type CronExecution, CronRoom, type CronRoomConfig, type CronTask, type CustomBinding, type CustomBindingManifest, DEFAULT_CONTEXT_CONFIG, DEFAULT_DO_MANIFEST, DEFAULT_QUERY_LIMIT, DIRECTORY_SCHEMAS, type DOBindings, type DOManifest, type DOManifestEntry, type DebugApiContext, type DeepSpaceAIEnv, type DeepSpaceAIOptions, type DeepSpaceAuth, type DeepSpaceAuthConfig, type DirectoryCommunityData, type DirectoryConversationData, type DirectoryMembershipData, type DirectoryPostData, type DoMigrationDirective, type DoMigrationPlan, type ExistingDOBinding, GLOBAL_DO_TYPES, GLOBAL_DO_TYPE_NAMES, type GameInput, GameRoom, type GameRoomConfig, type GetActionData, type GlobalDOType, type Job, type JobContext, JobRoom, type JobRoomConfig, type JobStatus, type JwtClaims, type JwtVerifierConfig, MESSAGES_SCHEMA, type MutateActionData, type PermissionAnalysis, type PermissionContext, type PermissionLevel, type PermissionSource, type PlanInfo, type PlatformWorkerEnv, type Player, type PrefixResult, type PresencePeer, PresenceRoom, type QueryActionData, REACTIONS_SCHEMA, READ_RECEIPTS_SCHEMA, RESERVED_BINDING_NAMES, RESERVED_COLLECTION_NAMES, type RecordContext, RecordRoom, type RecordRoomConfig, RefundError, type RefundOpts, type RefundResult, type ResolvedColumn, type ResolvedPermission, type RolePermissions, type RunMigrationsResult, SYSTEM_COLLECTION_SCHEMAS, SYSTEM_MANAGED_COLUMNS, SchemaRegistry, type ScopeContext, type ScopedR2Auth, type ScopedR2Config, type ScopedR2Handler, type ScreenshotEnv, type ScreenshotOptions, type ScreenshotResult, type SharedConnection, type StoredRecord, SubscriptionAuthError, type SubscriptionContext, type SubscriptionRead, SubscriptionRequiredError, type SubscriptionStatus, type Summarizer, TEST_ACCOUNT_EMAIL_SUFFIX, type TokenDebugInfo, type ToolResult, type ToolSchema, type ToolsApiContext, USERS_COLUMNS, type User, type UserAttachment, type UserContext, VOTING_SCHEMAS, type ValidationError, type VerifiedAuth, type VerifyOutcome, type VerifyResult, type Viewport, WORKSPACE_SCHEMAS, type YjsContext, YjsRoom, analyzePermissions, apiWorkerFetch, appendMessage, applyAiToolDefaults, applySlidingWindow, authWorkerFetch, bindingManifestFromOutputConfig, broadcastChange, broadcastYjsUpdate, buildCronContext, buildTableSelect, buildUiParts, canCreate, canDelete, canRead, canUpdate, cancelSubscription, capToolResultSize, captureScreenshot, checkFieldPermissions, coerceValue, collectionTableName, columnId, composioTools, computeDoMigration, computeHmacHex, createChat, createDeepSpaceAI, createDeepSpaceAuth, createScopedR2Handler, dataToColumnValues, decodeJwtPayload, deleteChatCascade, deleteRecord, enqueueJob, executeQuery, getAllUsers, getChat, getGlobalDOSchemas, getGlobalDOType, getOrCreateYjsDoc, getRecord, getRolePermissions, getSubscription, getUser, getYjsDocKey, handleApiRequest, handleDelete, handlePut, handleSetRole, handleSubscribe, handleToolsRequest, handleUnsubscribe, handleUserList, handleUserUpdate, handleYjsBinaryMessage, handleYjsJoin, handleYjsLeave, isAutoProvision, isOwner, isTestAccountClaims, isTestAccountEmail, isTestAccountTier, lintSchema, loadMessages, makeDefaultSummarizer, meterAi, meterUsage, meterVectorize, noopPermissionContext, platformWorkerFetch, prepareMessagesWithCompaction, priceBindingUsageEvent, putRecord, readRecord, recordMatchesSubscription, refundInvoice, registerUser, requireSubscription, resolveAppName, resolveColumn, rowToData, runMigrations, saveYjsDoc, timingSafeEqualHex, timingSafeEqualStrings, totalChars, truncateOldToolResults, turnsToCoreMessages, unwrapToolOutput, updateChat, validateAppName, validateBindingManifest, validateDoManifest, verifyJwt, workspaceAccountsSchema, workspaceContentSharesSchema, workspaceEmailHandlesSchema, workspaceFormResponsesSchema, workspacePeopleSchema, workspaceProjectsSchema, workspaceTagsSchema, workspaceTasksSchema, workspaceTeamMembersSchema, workspaceTeamsSchema, workspaceTransactionsSchema };
package/dist/server.js CHANGED
@@ -669,13 +669,19 @@ async function composioTools(env, options) {
669
669
  return tools;
670
670
  }
671
671
 
672
+ // src/server/utils/app-identity.ts
673
+ function appendAppIdentity(headers, env) {
674
+ headers.delete("x-app-identity-token");
675
+ headers.delete("x-app-id");
676
+ if (!env.APP_IDENTITY_TOKEN) return;
677
+ headers.set("x-app-identity-token", env.APP_IDENTITY_TOKEN);
678
+ headers.set("x-app-id", env.DEEPSPACE_APP_ID);
679
+ }
680
+
672
681
  // src/server/utils/screenshot.ts
673
682
  async function captureScreenshot(env, opts) {
674
- const headers = new Headers({
675
- "content-type": "application/json",
676
- "x-app-identity-token": env.APP_IDENTITY_TOKEN,
677
- "x-app-name": env.APP_NAME
678
- });
683
+ const headers = new Headers({ "content-type": "application/json" });
684
+ appendAppIdentity(headers, env);
679
685
  const res = await platformWorkerFetch(
680
686
  env,
681
687
  new Request("https://platform-internal/internal/screenshot", {
@@ -6839,6 +6845,30 @@ async function timingSafeEqualHex(a, b) {
6839
6845
  }
6840
6846
  return diff === 0;
6841
6847
  }
6848
+ async function timingSafeEqualStrings(a, b) {
6849
+ const encoder = new TextEncoder();
6850
+ const [aHash, bHash] = await Promise.all([
6851
+ crypto.subtle.digest("SHA-256", encoder.encode(a)),
6852
+ crypto.subtle.digest("SHA-256", encoder.encode(b))
6853
+ ]);
6854
+ const aBytes = new Uint8Array(aHash);
6855
+ const bBytes = new Uint8Array(bHash);
6856
+ let diff = 0;
6857
+ for (let i = 0; i < aBytes.length; i++) diff |= aBytes[i] ^ bBytes[i];
6858
+ return diff === 0;
6859
+ }
6860
+
6861
+ // src/server/auth/testAccounts.ts
6862
+ var TEST_ACCOUNT_EMAIL_SUFFIX = "@deepspace.test";
6863
+ function isTestAccountEmail(email) {
6864
+ return !!email && email.trim().toLowerCase().endsWith(TEST_ACCOUNT_EMAIL_SUFFIX);
6865
+ }
6866
+ function isTestAccountClaims(claims) {
6867
+ return claims?.isTestAccount === true;
6868
+ }
6869
+ function isTestAccountTier(tier) {
6870
+ return tier === "test";
6871
+ }
6842
6872
 
6843
6873
  // src/server/auth/betterAuth.ts
6844
6874
  import { betterAuth } from "better-auth";
@@ -6927,11 +6957,8 @@ function isEntitled(tier, status) {
6927
6957
 
6928
6958
  // src/server/subscription.ts
6929
6959
  function appIdentityHeaders(c, extra) {
6930
- const h = new Headers({
6931
- "x-app-identity-token": c.env.APP_IDENTITY_TOKEN,
6932
- "x-app-name": c.env.APP_NAME,
6933
- ...extra ?? {}
6934
- });
6960
+ const h = new Headers(extra ?? {});
6961
+ appendAppIdentity(h, c.env);
6935
6962
  const authz = c.req.header("authorization");
6936
6963
  if (authz) h.set("authorization", authz);
6937
6964
  return h;
@@ -7000,7 +7027,7 @@ async function cancelSubscription(c, opts) {
7000
7027
  authorization: authz
7001
7028
  },
7002
7029
  body: JSON.stringify({
7003
- appName: c.env.APP_NAME,
7030
+ appId: c.env.DEEPSPACE_APP_ID,
7004
7031
  userId: opts.userId,
7005
7032
  planSlug: opts.planSlug,
7006
7033
  atPeriodEnd: opts.atPeriodEnd,
@@ -7029,12 +7056,9 @@ var CancelSubscriptionError = class extends Error {
7029
7056
  async function refundInvoice(c, opts) {
7030
7057
  const authz = c.req.header("authorization");
7031
7058
  const nonce = opts.requestNonce ?? crypto.randomUUID();
7032
- const headers = {
7033
- "Content-Type": "application/json",
7034
- "x-app-identity-token": c.env.APP_IDENTITY_TOKEN,
7035
- "x-app-name": c.env.APP_NAME
7036
- };
7037
- if (authz) headers["authorization"] = authz;
7059
+ const headers = new Headers({ "Content-Type": "application/json" });
7060
+ appendAppIdentity(headers, c.env);
7061
+ if (authz) headers.set("authorization", authz);
7038
7062
  const res = await apiWorkerFetch(c.env, "/api/refunds/create", {
7039
7063
  method: "POST",
7040
7064
  headers,
@@ -7098,6 +7122,7 @@ export {
7098
7122
  SchemaRegistry,
7099
7123
  SubscriptionAuthError,
7100
7124
  SubscriptionRequiredError,
7125
+ TEST_ACCOUNT_EMAIL_SUFFIX,
7101
7126
  USERS_COLUMNS,
7102
7127
  VOTING_SCHEMAS,
7103
7128
  WORKSPACE_SCHEMAS,
@@ -7162,6 +7187,9 @@ export {
7162
7187
  handleYjsLeave,
7163
7188
  isAutoProvision,
7164
7189
  isOwner,
7190
+ isTestAccountClaims,
7191
+ isTestAccountEmail,
7192
+ isTestAccountTier,
7165
7193
  lintSchema,
7166
7194
  loadMessages,
7167
7195
  makeDefaultSummarizer,
@@ -7184,6 +7212,7 @@ export {
7184
7212
  runMigrations,
7185
7213
  saveYjsDoc,
7186
7214
  timingSafeEqualHex,
7215
+ timingSafeEqualStrings,
7187
7216
  totalChars,
7188
7217
  truncateOldToolResults,
7189
7218
  turnsToCoreMessages,