@mindstudio-ai/agent 0.1.34 → 0.1.36
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/cli.js +188 -47
- package/dist/index.d.ts +55 -11
- package/dist/index.js +180 -41
- package/dist/index.js.map +1 -1
- package/dist/postinstall.js +188 -47
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -249,6 +249,16 @@ interface AppDatabase {
|
|
|
249
249
|
interface AppContextResult {
|
|
250
250
|
auth: AppAuthContext;
|
|
251
251
|
databases: AppDatabase[];
|
|
252
|
+
authConfig?: AuthTableConfig;
|
|
253
|
+
}
|
|
254
|
+
/** Auth table config from the app manifest. Tells the SDK which table/columns are platform-managed. */
|
|
255
|
+
interface AuthTableConfig {
|
|
256
|
+
table: string;
|
|
257
|
+
columns: {
|
|
258
|
+
email?: string;
|
|
259
|
+
phone?: string;
|
|
260
|
+
roles?: string;
|
|
261
|
+
};
|
|
252
262
|
}
|
|
253
263
|
/** An OAuth connector service with its available actions. Third-party integration from the MindStudio Connector Registry. */
|
|
254
264
|
interface ConnectorService {
|
|
@@ -642,6 +652,21 @@ interface TableConfig {
|
|
|
642
652
|
* Explicit values in the input override defaults.
|
|
643
653
|
*/
|
|
644
654
|
defaults?: Record<string, unknown>;
|
|
655
|
+
/**
|
|
656
|
+
* Platform-managed auth columns. Set when this table is the app's auth
|
|
657
|
+
* table. Writes to email/phone columns throw; roles writes are allowed.
|
|
658
|
+
*/
|
|
659
|
+
managedColumns?: {
|
|
660
|
+
email?: string;
|
|
661
|
+
phone?: string;
|
|
662
|
+
roles?: string;
|
|
663
|
+
};
|
|
664
|
+
/**
|
|
665
|
+
* Sync role changes to the platform after a successful auth table write.
|
|
666
|
+
* Fire-and-forget: failures are caught and logged internally.
|
|
667
|
+
* @internal Provided by the agent instance; has closure over HTTP config.
|
|
668
|
+
*/
|
|
669
|
+
syncRoles?: (userId: string, roles: unknown) => Promise<void>;
|
|
645
670
|
/**
|
|
646
671
|
* Execute one or more SQL queries against the managed database in a
|
|
647
672
|
* single round trip. All queries run on the same SQLite connection,
|
|
@@ -700,19 +725,22 @@ interface SqlResult {
|
|
|
700
725
|
* performance optimization.
|
|
701
726
|
*/
|
|
702
727
|
|
|
703
|
-
declare class Query<T> implements PromiseLike<
|
|
728
|
+
declare class Query<T, TResult = T[]> implements PromiseLike<TResult> {
|
|
704
729
|
private readonly _predicates;
|
|
705
730
|
private readonly _sortAccessor;
|
|
706
731
|
private readonly _reversed;
|
|
707
732
|
private readonly _limit;
|
|
708
733
|
private readonly _offset;
|
|
709
734
|
private readonly _config;
|
|
735
|
+
/** @internal Post-process transform applied after row deserialization. */
|
|
736
|
+
readonly _postProcess: ((rows: T[]) => TResult) | undefined;
|
|
710
737
|
constructor(config: TableConfig, options?: {
|
|
711
738
|
predicates?: Predicate<T>[];
|
|
712
739
|
sortAccessor?: Accessor<T>;
|
|
713
740
|
reversed?: boolean;
|
|
714
741
|
limit?: number;
|
|
715
742
|
offset?: number;
|
|
743
|
+
postProcess?: (rows: T[]) => TResult;
|
|
716
744
|
});
|
|
717
745
|
private _clone;
|
|
718
746
|
filter(predicate: Predicate<T>): Query<T>;
|
|
@@ -720,13 +748,13 @@ declare class Query<T> implements PromiseLike<T[]> {
|
|
|
720
748
|
reverse(): Query<T>;
|
|
721
749
|
take(n: number): Query<T>;
|
|
722
750
|
skip(n: number): Query<T>;
|
|
723
|
-
first():
|
|
724
|
-
last():
|
|
751
|
+
first(): Query<T, T | null>;
|
|
752
|
+
last(): Query<T, T | null>;
|
|
725
753
|
count(): Promise<number>;
|
|
726
754
|
some(): Promise<boolean>;
|
|
727
755
|
every(): Promise<boolean>;
|
|
728
|
-
min(accessor: Accessor<T, number>):
|
|
729
|
-
max(accessor: Accessor<T, number>):
|
|
756
|
+
min(accessor: Accessor<T, number>): Query<T, T | null>;
|
|
757
|
+
max(accessor: Accessor<T, number>): Query<T, T | null>;
|
|
730
758
|
groupBy<K extends string | number>(accessor: Accessor<T, K>): Promise<Map<K, T[]>>;
|
|
731
759
|
/**
|
|
732
760
|
* @internal Compile this query into a SqlQuery for batch execution.
|
|
@@ -736,7 +764,7 @@ declare class Query<T> implements PromiseLike<T[]> {
|
|
|
736
764
|
* `SELECT *` is returned as `fallbackQuery` so the batch can fetch
|
|
737
765
|
* all rows and this query can filter them in JS post-fetch.
|
|
738
766
|
*/
|
|
739
|
-
_compile(): CompiledQuery<T>;
|
|
767
|
+
_compile(): CompiledQuery<T, TResult>;
|
|
740
768
|
/**
|
|
741
769
|
* @internal Process raw SQL results into typed rows. Used by db.batch()
|
|
742
770
|
* after executing the compiled query.
|
|
@@ -744,9 +772,9 @@ declare class Query<T> implements PromiseLike<T[]> {
|
|
|
744
772
|
* For SQL-compiled queries: just deserialize the rows.
|
|
745
773
|
* For JS-fallback queries: filter, sort, and slice in JS.
|
|
746
774
|
*/
|
|
747
|
-
static _processResults<T>(result: SqlResult, compiled: CompiledQuery<T>):
|
|
748
|
-
then<TResult1 =
|
|
749
|
-
catch<TResult2 = never>(onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<
|
|
775
|
+
static _processResults<T, R = T[]>(result: SqlResult, compiled: CompiledQuery<T, R>): R;
|
|
776
|
+
then<TResult1 = TResult, TResult2 = never>(onfulfilled?: ((value: TResult) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
|
|
777
|
+
catch<TResult2 = never>(onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult | TResult2>;
|
|
750
778
|
private _execute;
|
|
751
779
|
private _compilePredicates;
|
|
752
780
|
private _fetchAndFilterInJs;
|
|
@@ -756,7 +784,7 @@ declare class Query<T> implements PromiseLike<T[]> {
|
|
|
756
784
|
* Result of Query._compile(). Contains either a compiled SQL query
|
|
757
785
|
* (fast path) or a fallback SELECT * with JS processing metadata.
|
|
758
786
|
*/
|
|
759
|
-
interface CompiledQuery<T> {
|
|
787
|
+
interface CompiledQuery<T, TResult = T[]> {
|
|
760
788
|
type: 'query';
|
|
761
789
|
/** Compiled SQL query, or null if JS fallback needed. */
|
|
762
790
|
query: SqlQuery | null;
|
|
@@ -774,6 +802,8 @@ interface CompiledQuery<T> {
|
|
|
774
802
|
limit?: number;
|
|
775
803
|
/** Offset (only for fallback). */
|
|
776
804
|
offset?: number;
|
|
805
|
+
/** Post-process transform (e.g. first() extracts [0] ?? null). */
|
|
806
|
+
postProcess?: (rows: T[]) => TResult;
|
|
777
807
|
}
|
|
778
808
|
|
|
779
809
|
/**
|
|
@@ -903,6 +933,14 @@ declare class Table<T> {
|
|
|
903
933
|
* @param data - Row data to insert (or update on conflict). Defaults apply.
|
|
904
934
|
*/
|
|
905
935
|
upsert(conflictKey: (keyof Omit<T, SystemFields> & string) | (keyof Omit<T, SystemFields> & string)[], data: PushInput<T>): Mutation<T>;
|
|
936
|
+
/** @internal Throw if data includes a platform-managed email/phone column. */
|
|
937
|
+
private _checkManagedColumns;
|
|
938
|
+
/**
|
|
939
|
+
* @internal Fire role sync for rows that wrote to the roles column.
|
|
940
|
+
* Called inside processResult (runs after SQL execution in both
|
|
941
|
+
* standalone and batch paths). Fire-and-forget.
|
|
942
|
+
*/
|
|
943
|
+
private _syncRolesIfNeeded;
|
|
906
944
|
/** @internal Validate that the given columns match a declared unique constraint. */
|
|
907
945
|
private _validateUniqueConstraint;
|
|
908
946
|
}
|
|
@@ -1365,6 +1403,12 @@ declare class MindStudioAgent$1 {
|
|
|
1365
1403
|
* enabling RETURNING clauses and multi-statement batches.
|
|
1366
1404
|
*/
|
|
1367
1405
|
private _executeDbBatch;
|
|
1406
|
+
/**
|
|
1407
|
+
* @internal Sync a user's roles to the platform after a successful
|
|
1408
|
+
* auth table write. Calls POST /_internal/v2/auth/sync-user.
|
|
1409
|
+
* Fire-and-forget: errors are caught and logged, never propagated.
|
|
1410
|
+
*/
|
|
1411
|
+
private _syncRoles;
|
|
1368
1412
|
/**
|
|
1369
1413
|
* @internal Create a lazy Db proxy that auto-hydrates context.
|
|
1370
1414
|
*
|
|
@@ -7950,4 +7994,4 @@ declare const stream: (data: string | Record<string, unknown>) => Promise<void>;
|
|
|
7950
7994
|
*/
|
|
7951
7995
|
declare const resolveUser: (userId: string) => Promise<ResolvedUser | null>;
|
|
7952
7996
|
|
|
7953
|
-
export { type Accessor, type ActiveCampaignAddNoteStepInput, type ActiveCampaignAddNoteStepOutput, type ActiveCampaignCreateContactStepInput, type ActiveCampaignCreateContactStepOutput, type AddSubtitlesToVideoStepInput, type AddSubtitlesToVideoStepOutput, type AgentInfo, type AgentOptions, type AirtableCreateUpdateRecordStepInput, type AirtableCreateUpdateRecordStepOutput, type AirtableDeleteRecordStepInput, type AirtableDeleteRecordStepOutput, type AirtableGetRecordStepInput, type AirtableGetRecordStepOutput, type AirtableGetTableRecordsStepInput, type AirtableGetTableRecordsStepOutput, type AnalyzeImageStepInput, type AnalyzeImageStepOutput, type AnalyzeVideoStepInput, type AnalyzeVideoStepOutput, type AppAuthContext, type AppContextResult, type AppDatabase, type AppDatabaseColumnSchema, type AppDatabaseTable, type AppRoleAssignment, AuthContext, type BatchStepInput, type BatchStepResult, type CaptureThumbnailStepInput, type CaptureThumbnailStepOutput, type CheckAppRoleStepInput, type CheckAppRoleStepOutput, type CodaCreateUpdatePageStepInput, type CodaCreateUpdatePageStepOutput, type CodaCreateUpdateRowStepInput, type CodaCreateUpdateRowStepOutput, type CodaFindRowStepInput, type CodaFindRowStepOutput, type CodaGetPageStepInput, type CodaGetPageStepOutput, type CodaGetTableRowsStepInput, type CodaGetTableRowsStepOutput, type Connection, type ConnectorActionDetail, type ConnectorService, type ConvertPdfToImagesStepInput, type ConvertPdfToImagesStepOutput, type CreateDataSourceStepInput, type CreateDataSourceStepOutput, type CreateGmailDraftStepInput, type CreateGmailDraftStepOutput, type CreateGoogleCalendarEventStepInput, type CreateGoogleCalendarEventStepOutput, type CreateGoogleDocStepInput, type CreateGoogleDocStepOutput, type CreateGoogleSheetStepInput, type CreateGoogleSheetStepOutput, type Db, type DefineTableOptions, type DeleteDataSourceDocumentStepInput, type DeleteDataSourceDocumentStepOutput, type DeleteDataSourceStepInput, type DeleteDataSourceStepOutput, type DeleteGmailEmailStepInput, type DeleteGmailEmailStepOutput, type DeleteGoogleCalendarEventStepInput, type DeleteGoogleCalendarEventStepOutput, type DeleteGoogleSheetRowsStepInput, type DeleteGoogleSheetRowsStepOutput, type DetectChangesStepInput, type DetectChangesStepOutput, type DetectPIIStepInput, type DetectPIIStepOutput, type DiscordEditMessageStepInput, type DiscordEditMessageStepOutput, type DiscordSendFollowUpStepInput, type DiscordSendFollowUpStepOutput, type DiscordSendMessageStepInput, type DiscordSendMessageStepOutput, type DownloadVideoStepInput, type DownloadVideoStepOutput, type EnhanceImageGenerationPromptStepInput, type EnhanceImageGenerationPromptStepOutput, type EnhanceVideoGenerationPromptStepInput, type EnhanceVideoGenerationPromptStepOutput, type EnrichPersonStepInput, type EnrichPersonStepOutput, type ExecuteStepBatchOptions, type ExecuteStepBatchResult, type ExtractAudioFromVideoStepInput, type ExtractAudioFromVideoStepOutput, type ExtractTextStepInput, type ExtractTextStepOutput, type FetchDataSourceDocumentStepInput, type FetchDataSourceDocumentStepOutput, type FetchGoogleDocStepInput, type FetchGoogleDocStepOutput, type FetchGoogleSheetStepInput, type FetchGoogleSheetStepOutput, type FetchSlackChannelHistoryStepInput, type FetchSlackChannelHistoryStepOutput, type FetchYoutubeCaptionsStepInput, type FetchYoutubeCaptionsStepOutput, type FetchYoutubeChannelStepInput, type FetchYoutubeChannelStepOutput, type FetchYoutubeCommentsStepInput, type FetchYoutubeCommentsStepOutput, type FetchYoutubeVideoStepInput, type FetchYoutubeVideoStepOutput, type GenerateAssetStepInput, type GenerateAssetStepOutput, type GenerateChartStepInput, type GenerateChartStepOutput, type GenerateImageStepInput, type GenerateImageStepOutput, type GenerateLipsyncStepInput, type GenerateLipsyncStepOutput, type GenerateMusicStepInput, type GenerateMusicStepOutput, type GeneratePdfStepInput, type GeneratePdfStepOutput, type GenerateStaticVideoFromImageStepInput, type GenerateStaticVideoFromImageStepOutput, type GenerateTextStepInput, type GenerateTextStepOutput, type GenerateVideoStepInput, type GenerateVideoStepOutput, type GetGmailAttachmentsStepInput, type GetGmailAttachmentsStepOutput, type GetGmailDraftStepInput, type GetGmailDraftStepOutput, type GetGmailEmailStepInput, type GetGmailEmailStepOutput, type GetGmailUnreadCountStepInput, type GetGmailUnreadCountStepOutput, type GetGoogleCalendarEventStepInput, type GetGoogleCalendarEventStepOutput, type GetGoogleDriveFileStepInput, type GetGoogleDriveFileStepOutput, type GetGoogleSheetInfoStepInput, type GetGoogleSheetInfoStepOutput, type GetMediaMetadataStepInput, type GetMediaMetadataStepOutput, type HttpRequestStepInput, type HttpRequestStepOutput, type HubspotCreateCompanyStepInput, type HubspotCreateCompanyStepOutput, type HubspotCreateContactStepInput, type HubspotCreateContactStepOutput, type HubspotGetCompanyStepInput, type HubspotGetCompanyStepOutput, type HubspotGetContactStepInput, type HubspotGetContactStepOutput, type HunterApiCompanyEnrichmentStepInput, type HunterApiCompanyEnrichmentStepOutput, type HunterApiDomainSearchStepInput, type HunterApiDomainSearchStepOutput, type HunterApiEmailFinderStepInput, type HunterApiEmailFinderStepOutput, type HunterApiEmailVerificationStepInput, type HunterApiEmailVerificationStepOutput, type HunterApiPersonEnrichmentStepInput, type HunterApiPersonEnrichmentStepOutput, type ImageFaceSwapStepInput, type ImageFaceSwapStepOutput, type ImageRemoveWatermarkStepInput, type ImageRemoveWatermarkStepOutput, type InsertVideoClipsStepInput, type InsertVideoClipsStepOutput, type ListAgentsResult, type ListDataSourcesStepInput, type ListDataSourcesStepOutput, type ListGmailDraftsStepInput, type ListGmailDraftsStepOutput, type ListGmailLabelsStepInput, type ListGmailLabelsStepOutput, type ListGoogleCalendarEventsStepInput, type ListGoogleCalendarEventsStepOutput, type ListGoogleDriveFilesStepInput, type ListGoogleDriveFilesStepOutput, type ListRecentGmailEmailsStepInput, type ListRecentGmailEmailsStepOutput, type LogicStepInput, type LogicStepOutput, type MakeDotComRunScenarioStepInput, type MakeDotComRunScenarioStepOutput, type MergeAudioStepInput, type MergeAudioStepOutput, type MergeVideosStepInput, type MergeVideosStepOutput, MindStudioAgent, MindStudioError, type MindStudioModel, type MindStudioModelSummary, type MixAudioIntoVideoStepInput, type MixAudioIntoVideoStepOutput, type ModelType, type MonacoSnippet, type MonacoSnippetField, type MonacoSnippetFieldType, type MuteVideoStepInput, type MuteVideoStepOutput, type N8nRunNodeStepInput, type N8nRunNodeStepOutput, type NotionCreatePageStepInput, type NotionCreatePageStepOutput, type NotionUpdatePageStepInput, type NotionUpdatePageStepOutput, type PeopleSearchStepInput, type PeopleSearchStepOutput, type PostToLinkedInStepInput, type PostToLinkedInStepOutput, type PostToSlackChannelStepInput, type PostToSlackChannelStepOutput, type PostToXStepInput, type PostToXStepOutput, type PostToZapierStepInput, type PostToZapierStepOutput, type Predicate, type PushInput, Query, type QueryAppDatabaseStepInput, type QueryAppDatabaseStepOutput, type QueryDataSourceStepInput, type QueryDataSourceStepOutput, type QueryExternalDatabaseStepInput, type QueryExternalDatabaseStepOutput, type RedactPIIStepInput, type RedactPIIStepOutput, type RemoveBackgroundFromImageStepInput, type RemoveBackgroundFromImageStepOutput, type ReplyToGmailEmailStepInput, type ReplyToGmailEmailStepOutput, type ResizeVideoStepInput, type ResizeVideoStepOutput, type ResolvedUser, Roles, type RunAgentOptions, type RunAgentResult, type RunFromConnectorRegistryStepInput, type RunFromConnectorRegistryStepOutput, type RunPackagedWorkflowStepInput, type RunPackagedWorkflowStepOutput, type ScrapeFacebookPageStepInput, type ScrapeFacebookPageStepOutput, type ScrapeFacebookPostsStepInput, type ScrapeFacebookPostsStepOutput, type ScrapeInstagramCommentsStepInput, type ScrapeInstagramCommentsStepOutput, type ScrapeInstagramMentionsStepInput, type ScrapeInstagramMentionsStepOutput, type ScrapeInstagramPostsStepInput, type ScrapeInstagramPostsStepOutput, type ScrapeInstagramProfileStepInput, type ScrapeInstagramProfileStepOutput, type ScrapeInstagramReelsStepInput, type ScrapeInstagramReelsStepOutput, type ScrapeLinkedInCompanyStepInput, type ScrapeLinkedInCompanyStepOutput, type ScrapeLinkedInProfileStepInput, type ScrapeLinkedInProfileStepOutput, type ScrapeMetaThreadsProfileStepInput, type ScrapeMetaThreadsProfileStepOutput, type ScrapeUrlStepInput, type ScrapeUrlStepOutput, type ScrapeXPostStepInput, type ScrapeXPostStepOutput, type ScrapeXProfileStepInput, type ScrapeXProfileStepOutput, type ScreenshotUrlStepInput, type ScreenshotUrlStepOutput, type SearchGmailEmailsStepInput, type SearchGmailEmailsStepOutput, type SearchGoogleCalendarEventsStepInput, type SearchGoogleCalendarEventsStepOutput, type SearchGoogleDriveStepInput, type SearchGoogleDriveStepOutput, type SearchGoogleImagesStepInput, type SearchGoogleImagesStepOutput, type SearchGoogleNewsStepInput, type SearchGoogleNewsStepOutput, type SearchGoogleStepInput, type SearchGoogleStepOutput, type SearchGoogleTrendsStepInput, type SearchGoogleTrendsStepOutput, type SearchPerplexityStepInput, type SearchPerplexityStepOutput, type SearchXPostsStepInput, type SearchXPostsStepOutput, type SearchYoutubeStepInput, type SearchYoutubeStepOutput, type SearchYoutubeTrendsStepInput, type SearchYoutubeTrendsStepOutput, type SendEmailStepInput, type SendEmailStepOutput, type SendGmailDraftStepInput, type SendGmailDraftStepOutput, type SendGmailMessageStepInput, type SendGmailMessageStepOutput, type SendSMSStepInput, type SendSMSStepOutput, type SetGmailReadStatusStepInput, type SetGmailReadStatusStepOutput, type SetRunTitleStepInput, type SetRunTitleStepOutput, type SetVariableStepInput, type SetVariableStepOutput, type StepCostEstimateEntry, type StepExecutionMeta, type StepExecutionOptions, type StepExecutionResult, type StepInputMap, type StepLogEvent, type StepMetadata, type StepMethods, type StepName, type StepOutputMap, type SystemFields, Table, type TelegramEditMessageStepInput, type TelegramEditMessageStepOutput, type TelegramReplyToMessageStepInput, type TelegramReplyToMessageStepOutput, type TelegramSendAudioStepInput, type TelegramSendAudioStepOutput, type TelegramSendFileStepInput, type TelegramSendFileStepOutput, type TelegramSendImageStepInput, type TelegramSendImageStepOutput, type TelegramSendMessageStepInput, type TelegramSendMessageStepOutput, type TelegramSendVideoStepInput, type TelegramSendVideoStepOutput, type TelegramSetTypingStepInput, type TelegramSetTypingStepOutput, type TextToSpeechStepInput, type TextToSpeechStepOutput, type TranscribeAudioStepInput, type TranscribeAudioStepOutput, type TrimMediaStepInput, type TrimMediaStepOutput, type UpdateGmailLabelsStepInput, type UpdateGmailLabelsStepOutput, type UpdateGoogleCalendarEventStepInput, type UpdateGoogleCalendarEventStepOutput, type UpdateGoogleDocStepInput, type UpdateGoogleDocStepOutput, type UpdateGoogleSheetStepInput, type UpdateGoogleSheetStepOutput, type UpdateInput, type UploadDataSourceDocumentStepInput, type UploadDataSourceDocumentStepOutput, type UploadFileResult, type UpscaleImageStepInput, type UpscaleImageStepOutput, type UpscaleVideoStepInput, type UpscaleVideoStepOutput, type User, type UserInfoResult, type UserMessageStepInput, type UserMessageStepOutput, type VideoFaceSwapStepInput, type VideoFaceSwapStepOutput, type VideoRemoveBackgroundStepInput, type VideoRemoveBackgroundStepOutput, type VideoRemoveWatermarkStepInput, type VideoRemoveWatermarkStepOutput, type WatermarkImageStepInput, type WatermarkImageStepOutput, type WatermarkVideoStepInput, type WatermarkVideoStepOutput, auth, blockTypeAliases, db, mindstudio as default, mindstudio, monacoSnippets, resolveUser, stepMetadata, stream };
|
|
7997
|
+
export { type Accessor, type ActiveCampaignAddNoteStepInput, type ActiveCampaignAddNoteStepOutput, type ActiveCampaignCreateContactStepInput, type ActiveCampaignCreateContactStepOutput, type AddSubtitlesToVideoStepInput, type AddSubtitlesToVideoStepOutput, type AgentInfo, type AgentOptions, type AirtableCreateUpdateRecordStepInput, type AirtableCreateUpdateRecordStepOutput, type AirtableDeleteRecordStepInput, type AirtableDeleteRecordStepOutput, type AirtableGetRecordStepInput, type AirtableGetRecordStepOutput, type AirtableGetTableRecordsStepInput, type AirtableGetTableRecordsStepOutput, type AnalyzeImageStepInput, type AnalyzeImageStepOutput, type AnalyzeVideoStepInput, type AnalyzeVideoStepOutput, type AppAuthContext, type AppContextResult, type AppDatabase, type AppDatabaseColumnSchema, type AppDatabaseTable, type AppRoleAssignment, AuthContext, type AuthTableConfig, type BatchStepInput, type BatchStepResult, type CaptureThumbnailStepInput, type CaptureThumbnailStepOutput, type CheckAppRoleStepInput, type CheckAppRoleStepOutput, type CodaCreateUpdatePageStepInput, type CodaCreateUpdatePageStepOutput, type CodaCreateUpdateRowStepInput, type CodaCreateUpdateRowStepOutput, type CodaFindRowStepInput, type CodaFindRowStepOutput, type CodaGetPageStepInput, type CodaGetPageStepOutput, type CodaGetTableRowsStepInput, type CodaGetTableRowsStepOutput, type Connection, type ConnectorActionDetail, type ConnectorService, type ConvertPdfToImagesStepInput, type ConvertPdfToImagesStepOutput, type CreateDataSourceStepInput, type CreateDataSourceStepOutput, type CreateGmailDraftStepInput, type CreateGmailDraftStepOutput, type CreateGoogleCalendarEventStepInput, type CreateGoogleCalendarEventStepOutput, type CreateGoogleDocStepInput, type CreateGoogleDocStepOutput, type CreateGoogleSheetStepInput, type CreateGoogleSheetStepOutput, type Db, type DefineTableOptions, type DeleteDataSourceDocumentStepInput, type DeleteDataSourceDocumentStepOutput, type DeleteDataSourceStepInput, type DeleteDataSourceStepOutput, type DeleteGmailEmailStepInput, type DeleteGmailEmailStepOutput, type DeleteGoogleCalendarEventStepInput, type DeleteGoogleCalendarEventStepOutput, type DeleteGoogleSheetRowsStepInput, type DeleteGoogleSheetRowsStepOutput, type DetectChangesStepInput, type DetectChangesStepOutput, type DetectPIIStepInput, type DetectPIIStepOutput, type DiscordEditMessageStepInput, type DiscordEditMessageStepOutput, type DiscordSendFollowUpStepInput, type DiscordSendFollowUpStepOutput, type DiscordSendMessageStepInput, type DiscordSendMessageStepOutput, type DownloadVideoStepInput, type DownloadVideoStepOutput, type EnhanceImageGenerationPromptStepInput, type EnhanceImageGenerationPromptStepOutput, type EnhanceVideoGenerationPromptStepInput, type EnhanceVideoGenerationPromptStepOutput, type EnrichPersonStepInput, type EnrichPersonStepOutput, type ExecuteStepBatchOptions, type ExecuteStepBatchResult, type ExtractAudioFromVideoStepInput, type ExtractAudioFromVideoStepOutput, type ExtractTextStepInput, type ExtractTextStepOutput, type FetchDataSourceDocumentStepInput, type FetchDataSourceDocumentStepOutput, type FetchGoogleDocStepInput, type FetchGoogleDocStepOutput, type FetchGoogleSheetStepInput, type FetchGoogleSheetStepOutput, type FetchSlackChannelHistoryStepInput, type FetchSlackChannelHistoryStepOutput, type FetchYoutubeCaptionsStepInput, type FetchYoutubeCaptionsStepOutput, type FetchYoutubeChannelStepInput, type FetchYoutubeChannelStepOutput, type FetchYoutubeCommentsStepInput, type FetchYoutubeCommentsStepOutput, type FetchYoutubeVideoStepInput, type FetchYoutubeVideoStepOutput, type GenerateAssetStepInput, type GenerateAssetStepOutput, type GenerateChartStepInput, type GenerateChartStepOutput, type GenerateImageStepInput, type GenerateImageStepOutput, type GenerateLipsyncStepInput, type GenerateLipsyncStepOutput, type GenerateMusicStepInput, type GenerateMusicStepOutput, type GeneratePdfStepInput, type GeneratePdfStepOutput, type GenerateStaticVideoFromImageStepInput, type GenerateStaticVideoFromImageStepOutput, type GenerateTextStepInput, type GenerateTextStepOutput, type GenerateVideoStepInput, type GenerateVideoStepOutput, type GetGmailAttachmentsStepInput, type GetGmailAttachmentsStepOutput, type GetGmailDraftStepInput, type GetGmailDraftStepOutput, type GetGmailEmailStepInput, type GetGmailEmailStepOutput, type GetGmailUnreadCountStepInput, type GetGmailUnreadCountStepOutput, type GetGoogleCalendarEventStepInput, type GetGoogleCalendarEventStepOutput, type GetGoogleDriveFileStepInput, type GetGoogleDriveFileStepOutput, type GetGoogleSheetInfoStepInput, type GetGoogleSheetInfoStepOutput, type GetMediaMetadataStepInput, type GetMediaMetadataStepOutput, type HttpRequestStepInput, type HttpRequestStepOutput, type HubspotCreateCompanyStepInput, type HubspotCreateCompanyStepOutput, type HubspotCreateContactStepInput, type HubspotCreateContactStepOutput, type HubspotGetCompanyStepInput, type HubspotGetCompanyStepOutput, type HubspotGetContactStepInput, type HubspotGetContactStepOutput, type HunterApiCompanyEnrichmentStepInput, type HunterApiCompanyEnrichmentStepOutput, type HunterApiDomainSearchStepInput, type HunterApiDomainSearchStepOutput, type HunterApiEmailFinderStepInput, type HunterApiEmailFinderStepOutput, type HunterApiEmailVerificationStepInput, type HunterApiEmailVerificationStepOutput, type HunterApiPersonEnrichmentStepInput, type HunterApiPersonEnrichmentStepOutput, type ImageFaceSwapStepInput, type ImageFaceSwapStepOutput, type ImageRemoveWatermarkStepInput, type ImageRemoveWatermarkStepOutput, type InsertVideoClipsStepInput, type InsertVideoClipsStepOutput, type ListAgentsResult, type ListDataSourcesStepInput, type ListDataSourcesStepOutput, type ListGmailDraftsStepInput, type ListGmailDraftsStepOutput, type ListGmailLabelsStepInput, type ListGmailLabelsStepOutput, type ListGoogleCalendarEventsStepInput, type ListGoogleCalendarEventsStepOutput, type ListGoogleDriveFilesStepInput, type ListGoogleDriveFilesStepOutput, type ListRecentGmailEmailsStepInput, type ListRecentGmailEmailsStepOutput, type LogicStepInput, type LogicStepOutput, type MakeDotComRunScenarioStepInput, type MakeDotComRunScenarioStepOutput, type MergeAudioStepInput, type MergeAudioStepOutput, type MergeVideosStepInput, type MergeVideosStepOutput, MindStudioAgent, MindStudioError, type MindStudioModel, type MindStudioModelSummary, type MixAudioIntoVideoStepInput, type MixAudioIntoVideoStepOutput, type ModelType, type MonacoSnippet, type MonacoSnippetField, type MonacoSnippetFieldType, type MuteVideoStepInput, type MuteVideoStepOutput, type N8nRunNodeStepInput, type N8nRunNodeStepOutput, type NotionCreatePageStepInput, type NotionCreatePageStepOutput, type NotionUpdatePageStepInput, type NotionUpdatePageStepOutput, type PeopleSearchStepInput, type PeopleSearchStepOutput, type PostToLinkedInStepInput, type PostToLinkedInStepOutput, type PostToSlackChannelStepInput, type PostToSlackChannelStepOutput, type PostToXStepInput, type PostToXStepOutput, type PostToZapierStepInput, type PostToZapierStepOutput, type Predicate, type PushInput, Query, type QueryAppDatabaseStepInput, type QueryAppDatabaseStepOutput, type QueryDataSourceStepInput, type QueryDataSourceStepOutput, type QueryExternalDatabaseStepInput, type QueryExternalDatabaseStepOutput, type RedactPIIStepInput, type RedactPIIStepOutput, type RemoveBackgroundFromImageStepInput, type RemoveBackgroundFromImageStepOutput, type ReplyToGmailEmailStepInput, type ReplyToGmailEmailStepOutput, type ResizeVideoStepInput, type ResizeVideoStepOutput, type ResolvedUser, Roles, type RunAgentOptions, type RunAgentResult, type RunFromConnectorRegistryStepInput, type RunFromConnectorRegistryStepOutput, type RunPackagedWorkflowStepInput, type RunPackagedWorkflowStepOutput, type ScrapeFacebookPageStepInput, type ScrapeFacebookPageStepOutput, type ScrapeFacebookPostsStepInput, type ScrapeFacebookPostsStepOutput, type ScrapeInstagramCommentsStepInput, type ScrapeInstagramCommentsStepOutput, type ScrapeInstagramMentionsStepInput, type ScrapeInstagramMentionsStepOutput, type ScrapeInstagramPostsStepInput, type ScrapeInstagramPostsStepOutput, type ScrapeInstagramProfileStepInput, type ScrapeInstagramProfileStepOutput, type ScrapeInstagramReelsStepInput, type ScrapeInstagramReelsStepOutput, type ScrapeLinkedInCompanyStepInput, type ScrapeLinkedInCompanyStepOutput, type ScrapeLinkedInProfileStepInput, type ScrapeLinkedInProfileStepOutput, type ScrapeMetaThreadsProfileStepInput, type ScrapeMetaThreadsProfileStepOutput, type ScrapeUrlStepInput, type ScrapeUrlStepOutput, type ScrapeXPostStepInput, type ScrapeXPostStepOutput, type ScrapeXProfileStepInput, type ScrapeXProfileStepOutput, type ScreenshotUrlStepInput, type ScreenshotUrlStepOutput, type SearchGmailEmailsStepInput, type SearchGmailEmailsStepOutput, type SearchGoogleCalendarEventsStepInput, type SearchGoogleCalendarEventsStepOutput, type SearchGoogleDriveStepInput, type SearchGoogleDriveStepOutput, type SearchGoogleImagesStepInput, type SearchGoogleImagesStepOutput, type SearchGoogleNewsStepInput, type SearchGoogleNewsStepOutput, type SearchGoogleStepInput, type SearchGoogleStepOutput, type SearchGoogleTrendsStepInput, type SearchGoogleTrendsStepOutput, type SearchPerplexityStepInput, type SearchPerplexityStepOutput, type SearchXPostsStepInput, type SearchXPostsStepOutput, type SearchYoutubeStepInput, type SearchYoutubeStepOutput, type SearchYoutubeTrendsStepInput, type SearchYoutubeTrendsStepOutput, type SendEmailStepInput, type SendEmailStepOutput, type SendGmailDraftStepInput, type SendGmailDraftStepOutput, type SendGmailMessageStepInput, type SendGmailMessageStepOutput, type SendSMSStepInput, type SendSMSStepOutput, type SetGmailReadStatusStepInput, type SetGmailReadStatusStepOutput, type SetRunTitleStepInput, type SetRunTitleStepOutput, type SetVariableStepInput, type SetVariableStepOutput, type StepCostEstimateEntry, type StepExecutionMeta, type StepExecutionOptions, type StepExecutionResult, type StepInputMap, type StepLogEvent, type StepMetadata, type StepMethods, type StepName, type StepOutputMap, type SystemFields, Table, type TelegramEditMessageStepInput, type TelegramEditMessageStepOutput, type TelegramReplyToMessageStepInput, type TelegramReplyToMessageStepOutput, type TelegramSendAudioStepInput, type TelegramSendAudioStepOutput, type TelegramSendFileStepInput, type TelegramSendFileStepOutput, type TelegramSendImageStepInput, type TelegramSendImageStepOutput, type TelegramSendMessageStepInput, type TelegramSendMessageStepOutput, type TelegramSendVideoStepInput, type TelegramSendVideoStepOutput, type TelegramSetTypingStepInput, type TelegramSetTypingStepOutput, type TextToSpeechStepInput, type TextToSpeechStepOutput, type TranscribeAudioStepInput, type TranscribeAudioStepOutput, type TrimMediaStepInput, type TrimMediaStepOutput, type UpdateGmailLabelsStepInput, type UpdateGmailLabelsStepOutput, type UpdateGoogleCalendarEventStepInput, type UpdateGoogleCalendarEventStepOutput, type UpdateGoogleDocStepInput, type UpdateGoogleDocStepOutput, type UpdateGoogleSheetStepInput, type UpdateGoogleSheetStepOutput, type UpdateInput, type UploadDataSourceDocumentStepInput, type UploadDataSourceDocumentStepOutput, type UploadFileResult, type UpscaleImageStepInput, type UpscaleImageStepOutput, type UpscaleVideoStepInput, type UpscaleVideoStepOutput, type User, type UserInfoResult, type UserMessageStepInput, type UserMessageStepOutput, type VideoFaceSwapStepInput, type VideoFaceSwapStepOutput, type VideoRemoveBackgroundStepInput, type VideoRemoveBackgroundStepOutput, type VideoRemoveWatermarkStepInput, type VideoRemoveWatermarkStepOutput, type WatermarkImageStepInput, type WatermarkImageStepOutput, type WatermarkVideoStepInput, type WatermarkVideoStepOutput, auth, blockTypeAliases, db, mindstudio as default, mindstudio, monacoSnippets, resolveUser, stepMetadata, stream };
|
package/dist/index.js
CHANGED
|
@@ -37,13 +37,26 @@ async function requestWithRetry(config, method, url, body, attempt) {
|
|
|
37
37
|
return requestWithRetry(config, method, url, body, attempt + 1);
|
|
38
38
|
}
|
|
39
39
|
if (!res.ok) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
res.
|
|
45
|
-
|
|
46
|
-
|
|
40
|
+
let message = `${res.status} ${res.statusText}`;
|
|
41
|
+
let code = "api_error";
|
|
42
|
+
let details;
|
|
43
|
+
try {
|
|
44
|
+
const text = await res.text();
|
|
45
|
+
try {
|
|
46
|
+
const body2 = JSON.parse(text);
|
|
47
|
+
details = body2;
|
|
48
|
+
const errMsg = (typeof body2.error === "string" ? body2.error : void 0) ?? (typeof body2.message === "string" ? body2.message : void 0) ?? (typeof body2.details === "string" ? body2.details : void 0);
|
|
49
|
+
if (errMsg) message = errMsg;
|
|
50
|
+
else if (body2.error || body2.message || body2.details) {
|
|
51
|
+
message = JSON.stringify(body2.error ?? body2.message ?? body2.details);
|
|
52
|
+
}
|
|
53
|
+
if (body2.code) code = body2.code;
|
|
54
|
+
} catch {
|
|
55
|
+
if (text && text.length < 500) message = text;
|
|
56
|
+
}
|
|
57
|
+
} catch {
|
|
58
|
+
}
|
|
59
|
+
throw new MindStudioError(message, code, res.status, details);
|
|
47
60
|
}
|
|
48
61
|
const data = await res.json();
|
|
49
62
|
return { data, headers: res.headers };
|
|
@@ -234,6 +247,7 @@ function escapeValue(val) {
|
|
|
234
247
|
}
|
|
235
248
|
var USER_PREFIX = "@@user@@";
|
|
236
249
|
function deserializeRow(row, columns) {
|
|
250
|
+
if (row == null) return row;
|
|
237
251
|
const result = {};
|
|
238
252
|
for (const [key, value] of Object.entries(row)) {
|
|
239
253
|
const col = columns.find((c) => c.name === key);
|
|
@@ -828,6 +842,8 @@ var Query = class _Query {
|
|
|
828
842
|
_limit;
|
|
829
843
|
_offset;
|
|
830
844
|
_config;
|
|
845
|
+
/** @internal Post-process transform applied after row deserialization. */
|
|
846
|
+
_postProcess;
|
|
831
847
|
constructor(config, options) {
|
|
832
848
|
this._config = config;
|
|
833
849
|
this._predicates = options?.predicates ?? [];
|
|
@@ -835,6 +851,7 @@ var Query = class _Query {
|
|
|
835
851
|
this._reversed = options?.reversed ?? false;
|
|
836
852
|
this._limit = options?.limit;
|
|
837
853
|
this._offset = options?.offset;
|
|
854
|
+
this._postProcess = options?.postProcess;
|
|
838
855
|
}
|
|
839
856
|
_clone(overrides) {
|
|
840
857
|
return new _Query(this._config, {
|
|
@@ -842,7 +859,8 @@ var Query = class _Query {
|
|
|
842
859
|
sortAccessor: overrides.sortAccessor ?? this._sortAccessor,
|
|
843
860
|
reversed: overrides.reversed ?? this._reversed,
|
|
844
861
|
limit: overrides.limit ?? this._limit,
|
|
845
|
-
offset: overrides.offset ?? this._offset
|
|
862
|
+
offset: overrides.offset ?? this._offset,
|
|
863
|
+
postProcess: overrides.postProcess
|
|
846
864
|
});
|
|
847
865
|
}
|
|
848
866
|
// -------------------------------------------------------------------------
|
|
@@ -866,13 +884,18 @@ var Query = class _Query {
|
|
|
866
884
|
// -------------------------------------------------------------------------
|
|
867
885
|
// Terminal methods
|
|
868
886
|
// -------------------------------------------------------------------------
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
887
|
+
first() {
|
|
888
|
+
return this._clone({
|
|
889
|
+
limit: 1,
|
|
890
|
+
postProcess: (rows) => rows[0] ?? null
|
|
891
|
+
});
|
|
872
892
|
}
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
893
|
+
last() {
|
|
894
|
+
return this._clone({
|
|
895
|
+
limit: 1,
|
|
896
|
+
reversed: !this._reversed,
|
|
897
|
+
postProcess: (rows) => rows[0] ?? null
|
|
898
|
+
});
|
|
876
899
|
}
|
|
877
900
|
async count() {
|
|
878
901
|
const compiled = this._compilePredicates();
|
|
@@ -921,10 +944,10 @@ var Query = class _Query {
|
|
|
921
944
|
(row) => this._predicates.every((pred) => pred(row))
|
|
922
945
|
);
|
|
923
946
|
}
|
|
924
|
-
|
|
947
|
+
min(accessor) {
|
|
925
948
|
return this.sortBy(accessor).first();
|
|
926
949
|
}
|
|
927
|
-
|
|
950
|
+
max(accessor) {
|
|
928
951
|
return this.sortBy(accessor).reverse().first();
|
|
929
952
|
}
|
|
930
953
|
async groupBy(accessor) {
|
|
@@ -963,7 +986,7 @@ var Query = class _Query {
|
|
|
963
986
|
limit: this._limit,
|
|
964
987
|
offset: this._offset
|
|
965
988
|
});
|
|
966
|
-
return { type: "query", query, fallbackQuery: null, config: this._config };
|
|
989
|
+
return { type: "query", query, fallbackQuery: null, config: this._config, postProcess: this._postProcess };
|
|
967
990
|
}
|
|
968
991
|
const fallbackQuery = buildSelect(this._config.tableName);
|
|
969
992
|
return {
|
|
@@ -975,7 +998,8 @@ var Query = class _Query {
|
|
|
975
998
|
sortAccessor: this._sortAccessor,
|
|
976
999
|
reversed: this._reversed,
|
|
977
1000
|
limit: this._limit,
|
|
978
|
-
offset: this._offset
|
|
1001
|
+
offset: this._offset,
|
|
1002
|
+
postProcess: this._postProcess
|
|
979
1003
|
};
|
|
980
1004
|
}
|
|
981
1005
|
/**
|
|
@@ -992,7 +1016,9 @@ var Query = class _Query {
|
|
|
992
1016
|
compiled.config.columns
|
|
993
1017
|
)
|
|
994
1018
|
);
|
|
995
|
-
if (compiled.query)
|
|
1019
|
+
if (compiled.query) {
|
|
1020
|
+
return compiled.postProcess ? compiled.postProcess(rows) : rows;
|
|
1021
|
+
}
|
|
996
1022
|
let filtered = compiled.predicates ? rows.filter((row) => compiled.predicates.every((pred) => pred(row))) : rows;
|
|
997
1023
|
if (compiled.sortAccessor) {
|
|
998
1024
|
const accessor = compiled.sortAccessor;
|
|
@@ -1010,16 +1036,19 @@ var Query = class _Query {
|
|
|
1010
1036
|
const end = compiled.limit != null ? start + compiled.limit : void 0;
|
|
1011
1037
|
filtered = filtered.slice(start, end);
|
|
1012
1038
|
}
|
|
1013
|
-
return filtered;
|
|
1039
|
+
return compiled.postProcess ? compiled.postProcess(filtered) : filtered;
|
|
1014
1040
|
}
|
|
1015
1041
|
// -------------------------------------------------------------------------
|
|
1016
1042
|
// PromiseLike
|
|
1017
1043
|
// -------------------------------------------------------------------------
|
|
1018
1044
|
then(onfulfilled, onrejected) {
|
|
1019
|
-
|
|
1045
|
+
const promise = this._execute().then(
|
|
1046
|
+
(rows) => this._postProcess ? this._postProcess(rows) : rows
|
|
1047
|
+
);
|
|
1048
|
+
return promise.then(onfulfilled, onrejected);
|
|
1020
1049
|
}
|
|
1021
1050
|
catch(onrejected) {
|
|
1022
|
-
return this.
|
|
1051
|
+
return this.then(void 0, onrejected);
|
|
1023
1052
|
}
|
|
1024
1053
|
// -------------------------------------------------------------------------
|
|
1025
1054
|
// Execution internals
|
|
@@ -1248,6 +1277,9 @@ var Table = class {
|
|
|
1248
1277
|
const items = (isArray ? data : [data]).map(
|
|
1249
1278
|
(item) => this._config.defaults ? { ...this._config.defaults, ...item } : item
|
|
1250
1279
|
);
|
|
1280
|
+
for (const item of items) {
|
|
1281
|
+
this._checkManagedColumns(item);
|
|
1282
|
+
}
|
|
1251
1283
|
const queries = items.map(
|
|
1252
1284
|
(item) => buildInsert(
|
|
1253
1285
|
this._config.tableName,
|
|
@@ -1265,7 +1297,13 @@ var Table = class {
|
|
|
1265
1297
|
}
|
|
1266
1298
|
return void 0;
|
|
1267
1299
|
});
|
|
1268
|
-
|
|
1300
|
+
const result = isArray ? rows : rows[0];
|
|
1301
|
+
this._syncRolesIfNeeded(
|
|
1302
|
+
items,
|
|
1303
|
+
result,
|
|
1304
|
+
isArray
|
|
1305
|
+
);
|
|
1306
|
+
return result;
|
|
1269
1307
|
});
|
|
1270
1308
|
}
|
|
1271
1309
|
/**
|
|
@@ -1273,20 +1311,25 @@ var Table = class {
|
|
|
1273
1311
|
* Returns the updated row via `UPDATE ... RETURNING *`.
|
|
1274
1312
|
*/
|
|
1275
1313
|
update(id, data) {
|
|
1314
|
+
this._checkManagedColumns(data);
|
|
1276
1315
|
const query = buildUpdate(
|
|
1277
1316
|
this._config.tableName,
|
|
1278
1317
|
id,
|
|
1279
1318
|
data,
|
|
1280
1319
|
this._config.columns
|
|
1281
1320
|
);
|
|
1282
|
-
return new Mutation(
|
|
1283
|
-
|
|
1284
|
-
[query],
|
|
1285
|
-
(results) => deserializeRow(
|
|
1321
|
+
return new Mutation(this._config, [query], (results) => {
|
|
1322
|
+
const result = deserializeRow(
|
|
1286
1323
|
results[0].rows[0],
|
|
1287
1324
|
this._config.columns
|
|
1288
|
-
)
|
|
1289
|
-
|
|
1325
|
+
);
|
|
1326
|
+
this._syncRolesIfNeeded(
|
|
1327
|
+
[data],
|
|
1328
|
+
result,
|
|
1329
|
+
false
|
|
1330
|
+
);
|
|
1331
|
+
return result;
|
|
1332
|
+
});
|
|
1290
1333
|
}
|
|
1291
1334
|
remove(id) {
|
|
1292
1335
|
const query = buildDelete(this._config.tableName, `id = ?`, [id]);
|
|
@@ -1341,24 +1384,65 @@ var Table = class {
|
|
|
1341
1384
|
const conflictColumns = Array.isArray(conflictKey) ? conflictKey : [conflictKey];
|
|
1342
1385
|
this._validateUniqueConstraint(conflictColumns);
|
|
1343
1386
|
const withDefaults = this._config.defaults ? { ...this._config.defaults, ...data } : data;
|
|
1387
|
+
this._checkManagedColumns(withDefaults);
|
|
1344
1388
|
const query = buildUpsert(
|
|
1345
1389
|
this._config.tableName,
|
|
1346
1390
|
withDefaults,
|
|
1347
1391
|
conflictColumns,
|
|
1348
1392
|
this._config.columns
|
|
1349
1393
|
);
|
|
1350
|
-
return new Mutation(
|
|
1351
|
-
|
|
1352
|
-
[query],
|
|
1353
|
-
(results) => deserializeRow(
|
|
1394
|
+
return new Mutation(this._config, [query], (results) => {
|
|
1395
|
+
const result = deserializeRow(
|
|
1354
1396
|
results[0].rows[0],
|
|
1355
1397
|
this._config.columns
|
|
1356
|
-
)
|
|
1357
|
-
|
|
1398
|
+
);
|
|
1399
|
+
this._syncRolesIfNeeded([withDefaults], result, false);
|
|
1400
|
+
return result;
|
|
1401
|
+
});
|
|
1358
1402
|
}
|
|
1359
1403
|
// -------------------------------------------------------------------------
|
|
1360
1404
|
// Internal helpers
|
|
1361
1405
|
// -------------------------------------------------------------------------
|
|
1406
|
+
/** @internal Throw if data includes a platform-managed email/phone column. */
|
|
1407
|
+
_checkManagedColumns(data) {
|
|
1408
|
+
const mc = this._config.managedColumns;
|
|
1409
|
+
if (!mc) return;
|
|
1410
|
+
const keys = Object.keys(data);
|
|
1411
|
+
for (const key of keys) {
|
|
1412
|
+
if (mc.email && key === mc.email || mc.phone && key === mc.phone) {
|
|
1413
|
+
throw new MindStudioError(
|
|
1414
|
+
`Cannot write to "${key}" \u2014 this column is managed by auth. Use the auth API to change a user's ${key === mc.email ? "email" : "phone"}.`,
|
|
1415
|
+
"managed_column_write",
|
|
1416
|
+
400
|
|
1417
|
+
);
|
|
1418
|
+
}
|
|
1419
|
+
}
|
|
1420
|
+
}
|
|
1421
|
+
/**
|
|
1422
|
+
* @internal Fire role sync for rows that wrote to the roles column.
|
|
1423
|
+
* Called inside processResult (runs after SQL execution in both
|
|
1424
|
+
* standalone and batch paths). Fire-and-forget.
|
|
1425
|
+
*/
|
|
1426
|
+
_syncRolesIfNeeded(inputItems, result, isArray) {
|
|
1427
|
+
const rolesCol = this._config.managedColumns?.roles;
|
|
1428
|
+
const syncRoles = this._config.syncRoles;
|
|
1429
|
+
if (!rolesCol || !syncRoles) return;
|
|
1430
|
+
if (!inputItems.some((item) => rolesCol in item)) return;
|
|
1431
|
+
if (isArray) {
|
|
1432
|
+
for (const row of result) {
|
|
1433
|
+
if (row?.id) {
|
|
1434
|
+
syncRoles(row.id, row[rolesCol]).catch(() => {
|
|
1435
|
+
});
|
|
1436
|
+
}
|
|
1437
|
+
}
|
|
1438
|
+
} else {
|
|
1439
|
+
const row = result;
|
|
1440
|
+
if (row?.id) {
|
|
1441
|
+
syncRoles(row.id, row[rolesCol]).catch(() => {
|
|
1442
|
+
});
|
|
1443
|
+
}
|
|
1444
|
+
}
|
|
1445
|
+
}
|
|
1362
1446
|
/** @internal Validate that the given columns match a declared unique constraint. */
|
|
1363
1447
|
_validateUniqueConstraint(columns) {
|
|
1364
1448
|
if (!this._config.unique?.length) {
|
|
@@ -1383,7 +1467,7 @@ var Table = class {
|
|
|
1383
1467
|
};
|
|
1384
1468
|
|
|
1385
1469
|
// src/db/index.ts
|
|
1386
|
-
function createDb(databases, executeBatch) {
|
|
1470
|
+
function createDb(databases, executeBatch, authConfig, syncRoles) {
|
|
1387
1471
|
return {
|
|
1388
1472
|
defineTable(name, options) {
|
|
1389
1473
|
const resolved = resolveTable(databases, name, options?.database);
|
|
@@ -1393,6 +1477,8 @@ function createDb(databases, executeBatch) {
|
|
|
1393
1477
|
columns: resolved.columns,
|
|
1394
1478
|
unique: options?.unique,
|
|
1395
1479
|
defaults: options?.defaults,
|
|
1480
|
+
managedColumns: authConfig?.table === name ? authConfig.columns : void 0,
|
|
1481
|
+
syncRoles: authConfig?.table === name && authConfig.columns.roles ? syncRoles : void 0,
|
|
1396
1482
|
executeBatch: (queries) => executeBatch(resolved.databaseId, queries)
|
|
1397
1483
|
};
|
|
1398
1484
|
return new Table(config);
|
|
@@ -3759,6 +3845,12 @@ var MindStudioAgent = class {
|
|
|
3759
3845
|
* ```
|
|
3760
3846
|
*/
|
|
3761
3847
|
get auth() {
|
|
3848
|
+
if (this._authType === "internal") {
|
|
3849
|
+
const ai = globalThis.ai;
|
|
3850
|
+
if (ai?.auth) {
|
|
3851
|
+
return new AuthContext(ai.auth);
|
|
3852
|
+
}
|
|
3853
|
+
}
|
|
3762
3854
|
if (!this._auth) {
|
|
3763
3855
|
this._trySandboxHydration();
|
|
3764
3856
|
}
|
|
@@ -3847,7 +3939,9 @@ var MindStudioAgent = class {
|
|
|
3847
3939
|
this._auth = new AuthContext(context.auth);
|
|
3848
3940
|
this._db = createDb(
|
|
3849
3941
|
context.databases,
|
|
3850
|
-
this._executeDbBatch.bind(this)
|
|
3942
|
+
this._executeDbBatch.bind(this),
|
|
3943
|
+
context.authConfig,
|
|
3944
|
+
this._syncRoles.bind(this)
|
|
3851
3945
|
);
|
|
3852
3946
|
}
|
|
3853
3947
|
/**
|
|
@@ -3863,7 +3957,8 @@ var MindStudioAgent = class {
|
|
|
3863
3957
|
if (ai?.auth && ai?.databases) {
|
|
3864
3958
|
this._applyContext({
|
|
3865
3959
|
auth: ai.auth,
|
|
3866
|
-
databases: ai.databases
|
|
3960
|
+
databases: ai.databases,
|
|
3961
|
+
authConfig: ai.authConfig
|
|
3867
3962
|
});
|
|
3868
3963
|
}
|
|
3869
3964
|
}
|
|
@@ -3892,8 +3987,11 @@ var MindStudioAgent = class {
|
|
|
3892
3987
|
const text = await res.text();
|
|
3893
3988
|
try {
|
|
3894
3989
|
const body = JSON.parse(text);
|
|
3895
|
-
const errMsg = body.error ?? body.message ?? body.details;
|
|
3990
|
+
const errMsg = (typeof body.error === "string" ? body.error : void 0) ?? (typeof body.message === "string" ? body.message : void 0) ?? (typeof body.details === "string" ? body.details : void 0);
|
|
3896
3991
|
if (errMsg) message = errMsg;
|
|
3992
|
+
else if (body.error || body.message || body.details) {
|
|
3993
|
+
message = JSON.stringify(body.error ?? body.message ?? body.details);
|
|
3994
|
+
}
|
|
3897
3995
|
if (body.code) code = body.code;
|
|
3898
3996
|
} catch {
|
|
3899
3997
|
if (text && text.length < 500) message = text;
|
|
@@ -3909,6 +4007,39 @@ var MindStudioAgent = class {
|
|
|
3909
4007
|
const data = await res.json();
|
|
3910
4008
|
return data.results;
|
|
3911
4009
|
}
|
|
4010
|
+
/**
|
|
4011
|
+
* @internal Sync a user's roles to the platform after a successful
|
|
4012
|
+
* auth table write. Calls POST /_internal/v2/auth/sync-user.
|
|
4013
|
+
* Fire-and-forget: errors are caught and logged, never propagated.
|
|
4014
|
+
*/
|
|
4015
|
+
async _syncRoles(userId, roles) {
|
|
4016
|
+
try {
|
|
4017
|
+
const url = `${this._httpConfig.baseUrl}/_internal/v2/auth/sync-user`;
|
|
4018
|
+
const res = await fetch(url, {
|
|
4019
|
+
method: "POST",
|
|
4020
|
+
headers: {
|
|
4021
|
+
"Content-Type": "application/json",
|
|
4022
|
+
Authorization: this._token
|
|
4023
|
+
},
|
|
4024
|
+
body: JSON.stringify({
|
|
4025
|
+
appId: this._appId,
|
|
4026
|
+
userId,
|
|
4027
|
+
roles
|
|
4028
|
+
})
|
|
4029
|
+
});
|
|
4030
|
+
if (!res.ok) {
|
|
4031
|
+
const text = await res.text().catch(() => "");
|
|
4032
|
+
console.warn(
|
|
4033
|
+
`[mindstudio] Failed to sync roles for user ${userId}: ${res.status} ${text}`
|
|
4034
|
+
);
|
|
4035
|
+
}
|
|
4036
|
+
} catch (err) {
|
|
4037
|
+
console.warn(
|
|
4038
|
+
`[mindstudio] Failed to sync roles for user ${userId}:`,
|
|
4039
|
+
err
|
|
4040
|
+
);
|
|
4041
|
+
}
|
|
4042
|
+
}
|
|
3912
4043
|
/**
|
|
3913
4044
|
* @internal Create a lazy Db proxy that auto-hydrates context.
|
|
3914
4045
|
*
|
|
@@ -3921,7 +4052,7 @@ var MindStudioAgent = class {
|
|
|
3921
4052
|
return {
|
|
3922
4053
|
defineTable(name, options) {
|
|
3923
4054
|
const databaseHint = options?.database;
|
|
3924
|
-
|
|
4055
|
+
const tableConfig = {
|
|
3925
4056
|
databaseId: "",
|
|
3926
4057
|
tableName: name,
|
|
3927
4058
|
columns: [],
|
|
@@ -3929,6 +4060,13 @@ var MindStudioAgent = class {
|
|
|
3929
4060
|
defaults: options?.defaults,
|
|
3930
4061
|
executeBatch: async (queries) => {
|
|
3931
4062
|
await agent.ensureContext();
|
|
4063
|
+
const ac = agent._context.authConfig;
|
|
4064
|
+
if (ac && ac.table === name && !tableConfig.managedColumns) {
|
|
4065
|
+
tableConfig.managedColumns = ac.columns;
|
|
4066
|
+
if (ac.columns.roles) {
|
|
4067
|
+
tableConfig.syncRoles = agent._syncRoles.bind(agent);
|
|
4068
|
+
}
|
|
4069
|
+
}
|
|
3932
4070
|
const databases = agent._context.databases;
|
|
3933
4071
|
let targetDb;
|
|
3934
4072
|
if (databaseHint) {
|
|
@@ -3943,7 +4081,8 @@ var MindStudioAgent = class {
|
|
|
3943
4081
|
const databaseId = targetDb?.id ?? databases[0]?.id ?? "";
|
|
3944
4082
|
return agent._executeDbBatch(databaseId, queries);
|
|
3945
4083
|
}
|
|
3946
|
-
}
|
|
4084
|
+
};
|
|
4085
|
+
return new Table(tableConfig);
|
|
3947
4086
|
},
|
|
3948
4087
|
// Time helpers work without context
|
|
3949
4088
|
now: () => Date.now(),
|