@memberjunction/ng-conversations 6.3.0-edge.0 → 6.3.0-edge.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/README.md +60 -22
- package/dist/assets/edge-ai.worker.js +35168 -0
- package/dist/lib/components/agent/agent-instance-editor-modal.component.d.ts +186 -0
- package/dist/lib/components/agent/agent-instance-editor-modal.component.d.ts.map +1 -0
- package/dist/lib/components/agent/agent-instance-editor-modal.component.js +2202 -0
- package/dist/lib/components/agent/agent-instance-editor-modal.component.js.map +1 -0
- package/dist/lib/components/artifact/artifact-share-modal.component.d.ts +39 -6
- package/dist/lib/components/artifact/artifact-share-modal.component.d.ts.map +1 -1
- package/dist/lib/components/artifact/artifact-share-modal.component.js +773 -204
- package/dist/lib/components/artifact/artifact-share-modal.component.js.map +1 -1
- package/dist/lib/components/collection/collection-tree.component.d.ts.map +1 -1
- package/dist/lib/components/collection/collection-tree.component.js +19 -18
- package/dist/lib/components/collection/collection-tree.component.js.map +1 -1
- package/dist/lib/components/collection/collection-view.component.d.ts +6 -4
- package/dist/lib/components/collection/collection-view.component.d.ts.map +1 -1
- package/dist/lib/components/collection/collection-view.component.js +35 -17
- package/dist/lib/components/collection/collection-view.component.js.map +1 -1
- package/dist/lib/components/collection/collections-full-view.component.d.ts +1 -0
- package/dist/lib/components/collection/collections-full-view.component.d.ts.map +1 -1
- package/dist/lib/components/collection/collections-full-view.component.js +108 -106
- package/dist/lib/components/collection/collections-full-view.component.js.map +1 -1
- package/dist/lib/components/composer/ai-composer.component.d.ts +15 -1
- package/dist/lib/components/composer/ai-composer.component.d.ts.map +1 -1
- package/dist/lib/components/composer/ai-composer.component.js +43 -4
- package/dist/lib/components/composer/ai-composer.component.js.map +1 -1
- package/dist/lib/components/conversation/conversation-agent-picker.component.d.ts +20 -2
- package/dist/lib/components/conversation/conversation-agent-picker.component.d.ts.map +1 -1
- package/dist/lib/components/conversation/conversation-agent-picker.component.js +378 -62
- package/dist/lib/components/conversation/conversation-agent-picker.component.js.map +1 -1
- package/dist/lib/components/conversation/conversation-chat-area.component.d.ts +94 -18
- package/dist/lib/components/conversation/conversation-chat-area.component.d.ts.map +1 -1
- package/dist/lib/components/conversation/conversation-chat-area.component.js +732 -439
- package/dist/lib/components/conversation/conversation-chat-area.component.js.map +1 -1
- package/dist/lib/components/conversation/conversation-list.component.d.ts +19 -1
- package/dist/lib/components/conversation/conversation-list.component.d.ts.map +1 -1
- package/dist/lib/components/conversation/conversation-list.component.js +184 -89
- package/dist/lib/components/conversation/conversation-list.component.js.map +1 -1
- package/dist/lib/components/export/export-modal.component.d.ts +7 -2
- package/dist/lib/components/export/export-modal.component.d.ts.map +1 -1
- package/dist/lib/components/export/export-modal.component.js +13 -2
- package/dist/lib/components/export/export-modal.component.js.map +1 -1
- package/dist/lib/components/library/library-create-dialog.component.d.ts +136 -0
- package/dist/lib/components/library/library-create-dialog.component.d.ts.map +1 -0
- package/dist/lib/components/library/library-create-dialog.component.js +1620 -0
- package/dist/lib/components/library/library-create-dialog.component.js.map +1 -0
- package/dist/lib/components/library/library-full-view.component.d.ts +10 -4
- package/dist/lib/components/library/library-full-view.component.d.ts.map +1 -1
- package/dist/lib/components/library/library-full-view.component.js +216 -40
- package/dist/lib/components/library/library-full-view.component.js.map +1 -1
- package/dist/lib/components/library/library-remote-drive-pane.component.d.ts +97 -0
- package/dist/lib/components/library/library-remote-drive-pane.component.d.ts.map +1 -0
- package/dist/lib/components/library/library-remote-drive-pane.component.js +1229 -0
- package/dist/lib/components/library/library-remote-drive-pane.component.js.map +1 -0
- package/dist/lib/components/library/library-workspace.component.d.ts +293 -0
- package/dist/lib/components/library/library-workspace.component.d.ts.map +1 -0
- package/dist/lib/components/library/library-workspace.component.js +5121 -0
- package/dist/lib/components/library/library-workspace.component.js.map +1 -0
- package/dist/lib/components/library/library.models.d.ts +192 -0
- package/dist/lib/components/library/library.models.d.ts.map +1 -0
- package/dist/lib/components/library/library.models.js +2 -0
- package/dist/lib/components/library/library.models.js.map +1 -0
- package/dist/lib/components/message/agent-handoff-card.component.js +1 -1
- package/dist/lib/components/message/agent-handoff-card.component.js.map +1 -1
- package/dist/lib/components/message/conversation-message-rating.component.d.ts +5 -0
- package/dist/lib/components/message/conversation-message-rating.component.d.ts.map +1 -1
- package/dist/lib/components/message/conversation-message-rating.component.js +72 -16
- package/dist/lib/components/message/conversation-message-rating.component.js.map +1 -1
- package/dist/lib/components/message/message-input.component.d.ts +33 -14
- package/dist/lib/components/message/message-input.component.d.ts.map +1 -1
- package/dist/lib/components/message/message-input.component.js +142 -75
- package/dist/lib/components/message/message-input.component.js.map +1 -1
- package/dist/lib/components/message/message-item.component.d.ts +51 -4
- package/dist/lib/components/message/message-item.component.d.ts.map +1 -1
- package/dist/lib/components/message/message-item.component.js +640 -399
- package/dist/lib/components/message/message-item.component.js.map +1 -1
- package/dist/lib/components/message/message-list.component.d.ts +15 -1
- package/dist/lib/components/message/message-list.component.d.ts.map +1 -1
- package/dist/lib/components/message/message-list.component.js +75 -3
- package/dist/lib/components/message/message-list.component.js.map +1 -1
- package/dist/lib/components/navigation/conversation-navigation.component.js +9 -9
- package/dist/lib/components/navigation/conversation-navigation.component.js.map +1 -1
- package/dist/lib/components/overlay/chat-overlay.component.d.ts +94 -6
- package/dist/lib/components/overlay/chat-overlay.component.d.ts.map +1 -1
- package/dist/lib/components/overlay/chat-overlay.component.js +249 -59
- package/dist/lib/components/overlay/chat-overlay.component.js.map +1 -1
- package/dist/lib/components/project/project-form-modal.component.d.ts +6 -0
- package/dist/lib/components/project/project-form-modal.component.d.ts.map +1 -1
- package/dist/lib/components/project/project-form-modal.component.js +81 -61
- package/dist/lib/components/project/project-form-modal.component.js.map +1 -1
- package/dist/lib/components/project/project-selector.component.d.ts +5 -0
- package/dist/lib/components/project/project-selector.component.d.ts.map +1 -1
- package/dist/lib/components/project/project-selector.component.js +11 -4
- package/dist/lib/components/project/project-selector.component.js.map +1 -1
- package/dist/lib/components/realtime/artifact-workspace/artifact-workspace-channel.d.ts +55 -0
- package/dist/lib/components/realtime/artifact-workspace/artifact-workspace-channel.d.ts.map +1 -0
- package/dist/lib/components/realtime/artifact-workspace/artifact-workspace-channel.js +974 -0
- package/dist/lib/components/realtime/artifact-workspace/artifact-workspace-channel.js.map +1 -0
- package/dist/lib/components/realtime/artifact-workspace/artifact-workspace-engine.d.ts +66 -0
- package/dist/lib/components/realtime/artifact-workspace/artifact-workspace-engine.d.ts.map +1 -0
- package/dist/lib/components/realtime/artifact-workspace/artifact-workspace-engine.js +253 -0
- package/dist/lib/components/realtime/artifact-workspace/artifact-workspace-engine.js.map +1 -0
- package/dist/lib/components/realtime/artifact-workspace/artifact-workspace-types.d.ts +80 -0
- package/dist/lib/components/realtime/artifact-workspace/artifact-workspace-types.d.ts.map +1 -0
- package/dist/lib/components/realtime/artifact-workspace/artifact-workspace-types.js +49 -0
- package/dist/lib/components/realtime/artifact-workspace/artifact-workspace-types.js.map +1 -0
- package/dist/lib/components/realtime/artifact-workspace/realtime-artifact-workspace-surface.component.d.ts +54 -0
- package/dist/lib/components/realtime/artifact-workspace/realtime-artifact-workspace-surface.component.d.ts.map +1 -0
- package/dist/lib/components/realtime/artifact-workspace/realtime-artifact-workspace-surface.component.js +386 -0
- package/dist/lib/components/realtime/artifact-workspace/realtime-artifact-workspace-surface.component.js.map +1 -0
- package/dist/lib/components/realtime/capture/realtime-capture-channel.d.ts +28 -1
- package/dist/lib/components/realtime/capture/realtime-capture-channel.d.ts.map +1 -1
- package/dist/lib/components/realtime/capture/realtime-capture-channel.js +53 -1
- package/dist/lib/components/realtime/capture/realtime-capture-channel.js.map +1 -1
- package/dist/lib/components/realtime/channels/client-context-channel.d.ts.map +1 -1
- package/dist/lib/components/realtime/channels/client-context-channel.js +23 -7
- package/dist/lib/components/realtime/channels/client-context-channel.js.map +1 -1
- package/dist/lib/components/realtime/interactive-component/interactive-component-channel.d.ts +1 -0
- package/dist/lib/components/realtime/interactive-component/interactive-component-channel.d.ts.map +1 -1
- package/dist/lib/components/realtime/interactive-component/interactive-component-channel.js +15 -2
- package/dist/lib/components/realtime/interactive-component/interactive-component-channel.js.map +1 -1
- package/dist/lib/components/realtime/media/media-channel.d.ts +32 -11
- package/dist/lib/components/realtime/media/media-channel.d.ts.map +1 -1
- package/dist/lib/components/realtime/media/media-channel.js +186 -23
- package/dist/lib/components/realtime/media/media-channel.js.map +1 -1
- package/dist/lib/components/realtime/media/realtime-media-surface.component.d.ts +9 -1
- package/dist/lib/components/realtime/media/realtime-media-surface.component.d.ts.map +1 -1
- package/dist/lib/components/realtime/media/realtime-media-surface.component.js +33 -10
- package/dist/lib/components/realtime/media/realtime-media-surface.component.js.map +1 -1
- package/dist/lib/components/realtime/realtime-agent-banner.component.js +3 -3
- package/dist/lib/components/realtime/realtime-agent-banner.component.js.map +1 -1
- package/dist/lib/components/realtime/realtime-agent-picker.component.d.ts.map +1 -1
- package/dist/lib/components/realtime/realtime-agent-picker.component.js +3 -3
- package/dist/lib/components/realtime/realtime-agent-picker.component.js.map +1 -1
- package/dist/lib/components/realtime/realtime-composer.component.js +6 -4
- package/dist/lib/components/realtime/realtime-composer.component.js.map +1 -1
- package/dist/lib/components/realtime/realtime-session-overlay.component.d.ts +82 -33
- package/dist/lib/components/realtime/realtime-session-overlay.component.d.ts.map +1 -1
- package/dist/lib/components/realtime/realtime-session-overlay.component.js +521 -191
- package/dist/lib/components/realtime/realtime-session-overlay.component.js.map +1 -1
- package/dist/lib/components/realtime/realtime-session-state.d.ts.map +1 -1
- package/dist/lib/components/realtime/realtime-session-state.js +1 -1
- package/dist/lib/components/realtime/realtime-session-state.js.map +1 -1
- package/dist/lib/components/realtime/realtime-session-thread.component.d.ts.map +1 -1
- package/dist/lib/components/realtime/realtime-session-thread.component.js +90 -5
- package/dist/lib/components/realtime/realtime-session-thread.component.js.map +1 -1
- package/dist/lib/components/realtime/realtime-surface-stage.model.d.ts.map +1 -1
- package/dist/lib/components/realtime/realtime-surface-stage.model.js +2 -1
- package/dist/lib/components/realtime/realtime-surface-stage.model.js.map +1 -1
- package/dist/lib/components/realtime/realtime-surface-tab-style.d.ts +11 -4
- package/dist/lib/components/realtime/realtime-surface-tab-style.d.ts.map +1 -1
- package/dist/lib/components/realtime/realtime-surface-tab-style.js +24 -5
- package/dist/lib/components/realtime/realtime-surface-tab-style.js.map +1 -1
- package/dist/lib/components/realtime/realtime-surface-tabs.model.d.ts +7 -9
- package/dist/lib/components/realtime/realtime-surface-tabs.model.d.ts.map +1 -1
- package/dist/lib/components/realtime/realtime-surface-tabs.model.js +25 -15
- package/dist/lib/components/realtime/realtime-surface-tabs.model.js.map +1 -1
- package/dist/lib/components/realtime/remote-browser/remote-browser-channel.d.ts +30 -1
- package/dist/lib/components/realtime/remote-browser/remote-browser-channel.d.ts.map +1 -1
- package/dist/lib/components/realtime/remote-browser/remote-browser-channel.js +150 -2
- package/dist/lib/components/realtime/remote-browser/remote-browser-channel.js.map +1 -1
- package/dist/lib/components/realtime/remote-browser/remote-browser-surface.component.d.ts +101 -3
- package/dist/lib/components/realtime/remote-browser/remote-browser-surface.component.d.ts.map +1 -1
- package/dist/lib/components/realtime/remote-browser/remote-browser-surface.component.js +503 -55
- package/dist/lib/components/realtime/remote-browser/remote-browser-surface.component.js.map +1 -1
- package/dist/lib/components/realtime/whiteboard/whiteboard-artifact-viewer.component.d.ts +48 -5
- package/dist/lib/components/realtime/whiteboard/whiteboard-artifact-viewer.component.d.ts.map +1 -1
- package/dist/lib/components/realtime/whiteboard/whiteboard-artifact-viewer.component.js +249 -53
- package/dist/lib/components/realtime/whiteboard/whiteboard-artifact-viewer.component.js.map +1 -1
- package/dist/lib/components/realtime/whiteboard/whiteboard-channel.d.ts.map +1 -1
- package/dist/lib/components/realtime/whiteboard/whiteboard-channel.js +1 -1
- package/dist/lib/components/realtime/whiteboard/whiteboard-channel.js.map +1 -1
- package/dist/lib/components/search/search-panel.component.d.ts +10 -0
- package/dist/lib/components/search/search-panel.component.d.ts.map +1 -1
- package/dist/lib/components/search/search-panel.component.js +25 -3
- package/dist/lib/components/search/search-panel.component.js.map +1 -1
- package/dist/lib/components/share/share-modal.component.d.ts.map +1 -1
- package/dist/lib/components/share/share-modal.component.js +181 -127
- package/dist/lib/components/share/share-modal.component.js.map +1 -1
- package/dist/lib/components/sidebar/conversation-sidebar.component.d.ts +14 -1
- package/dist/lib/components/sidebar/conversation-sidebar.component.d.ts.map +1 -1
- package/dist/lib/components/sidebar/conversation-sidebar.component.js +50 -11
- package/dist/lib/components/sidebar/conversation-sidebar.component.js.map +1 -1
- package/dist/lib/components/sidebar/my-agents-section.component.d.ts +78 -0
- package/dist/lib/components/sidebar/my-agents-section.component.d.ts.map +1 -0
- package/dist/lib/components/sidebar/my-agents-section.component.js +450 -0
- package/dist/lib/components/sidebar/my-agents-section.component.js.map +1 -0
- package/dist/lib/components/task/tasks-full-view.component.d.ts +31 -8
- package/dist/lib/components/task/tasks-full-view.component.d.ts.map +1 -1
- package/dist/lib/components/task/tasks-full-view.component.js +701 -497
- package/dist/lib/components/task/tasks-full-view.component.js.map +1 -1
- package/dist/lib/components/workspace/conversation-workspace.component.d.ts.map +1 -1
- package/dist/lib/components/workspace/conversation-workspace.component.js +15 -2
- package/dist/lib/components/workspace/conversation-workspace.component.js.map +1 -1
- package/dist/lib/composer-plugins/base-conversation-mention.provider.d.ts +1 -0
- package/dist/lib/composer-plugins/base-conversation-mention.provider.d.ts.map +1 -1
- package/dist/lib/composer-plugins/base-conversation-mention.provider.js +13 -1
- package/dist/lib/composer-plugins/base-conversation-mention.provider.js.map +1 -1
- package/dist/lib/conversations.module.d.ts +78 -71
- package/dist/lib/conversations.module.d.ts.map +1 -1
- package/dist/lib/conversations.module.js +68 -1
- package/dist/lib/conversations.module.js.map +1 -1
- package/dist/lib/models/agent-turn.model.d.ts +7 -1
- package/dist/lib/models/agent-turn.model.d.ts.map +1 -1
- package/dist/lib/models/agent-turn.model.js.map +1 -1
- package/dist/lib/services/agent-state.service.d.ts.map +1 -1
- package/dist/lib/services/agent-state.service.js +14 -3
- package/dist/lib/services/agent-state.service.js.map +1 -1
- package/dist/lib/services/artifact-permission.service.d.ts.map +1 -1
- package/dist/lib/services/artifact-permission.service.js +14 -3
- package/dist/lib/services/artifact-permission.service.js.map +1 -1
- package/dist/lib/services/artifact-state.service.d.ts.map +1 -1
- package/dist/lib/services/artifact-state.service.js +43 -11
- package/dist/lib/services/artifact-state.service.js.map +1 -1
- package/dist/lib/services/conversation-agent.service.d.ts +31 -21
- package/dist/lib/services/conversation-agent.service.d.ts.map +1 -1
- package/dist/lib/services/conversation-agent.service.js +84 -35
- package/dist/lib/services/conversation-agent.service.js.map +1 -1
- package/dist/lib/services/conversation-tasks-filter.d.ts +59 -2
- package/dist/lib/services/conversation-tasks-filter.d.ts.map +1 -1
- package/dist/lib/services/conversation-tasks-filter.js +222 -18
- package/dist/lib/services/conversation-tasks-filter.js.map +1 -1
- package/dist/lib/services/edge-ai/edge-agent-pre-discovery.service.d.ts +85 -0
- package/dist/lib/services/edge-ai/edge-agent-pre-discovery.service.d.ts.map +1 -0
- package/dist/lib/services/edge-ai/edge-agent-pre-discovery.service.js +257 -0
- package/dist/lib/services/edge-ai/edge-agent-pre-discovery.service.js.map +1 -0
- package/dist/lib/services/edge-ai/edge-ai-protocol.d.ts +85 -0
- package/dist/lib/services/edge-ai/edge-ai-protocol.d.ts.map +1 -0
- package/dist/lib/services/edge-ai/edge-ai-protocol.js +10 -0
- package/dist/lib/services/edge-ai/edge-ai-protocol.js.map +1 -0
- package/dist/lib/services/edge-ai/edge-ai-worker-host.d.ts +90 -0
- package/dist/lib/services/edge-ai/edge-ai-worker-host.d.ts.map +1 -0
- package/dist/lib/services/edge-ai/edge-ai-worker-host.js +386 -0
- package/dist/lib/services/edge-ai/edge-ai-worker-host.js.map +1 -0
- package/dist/lib/services/edge-ai/edge-ai.worker.d.ts +13 -0
- package/dist/lib/services/edge-ai/edge-ai.worker.d.ts.map +1 -0
- package/dist/lib/services/edge-ai/edge-ai.worker.js +201 -0
- package/dist/lib/services/edge-ai/edge-ai.worker.js.map +1 -0
- package/dist/lib/services/export.service.d.ts +64 -0
- package/dist/lib/services/export.service.d.ts.map +1 -1
- package/dist/lib/services/export.service.js +185 -6
- package/dist/lib/services/export.service.js.map +1 -1
- package/dist/lib/services/library-creation.service.d.ts +304 -0
- package/dist/lib/services/library-creation.service.d.ts.map +1 -0
- package/dist/lib/services/library-creation.service.js +1244 -0
- package/dist/lib/services/library-creation.service.js.map +1 -0
- package/dist/lib/services/realtime-pairing.d.ts +3 -3
- package/dist/lib/services/realtime-pairing.js +4 -4
- package/dist/lib/services/realtime-pairing.js.map +1 -1
- package/dist/lib/services/realtime-session-review.service.d.ts +14 -0
- package/dist/lib/services/realtime-session-review.service.d.ts.map +1 -1
- package/dist/lib/services/realtime-session-review.service.js +46 -4
- package/dist/lib/services/realtime-session-review.service.js.map +1 -1
- package/dist/lib/services/realtime-session.service.d.ts.map +1 -1
- package/dist/lib/services/realtime-session.service.js +2 -1
- package/dist/lib/services/realtime-session.service.js.map +1 -1
- package/dist/lib/services/search.service.d.ts +19 -2
- package/dist/lib/services/search.service.d.ts.map +1 -1
- package/dist/lib/services/search.service.js +99 -36
- package/dist/lib/services/search.service.js.map +1 -1
- package/dist/lib/utils/agent-handoff-map.js +1 -1
- package/dist/lib/utils/agent-handoff-map.js.map +1 -1
- package/dist/lib/utils/agent-turn-routing.js +1 -1
- package/dist/lib/utils/agent-turn-routing.js.map +1 -1
- package/dist/lib/utils/decision-routing.d.ts +5 -2
- package/dist/lib/utils/decision-routing.d.ts.map +1 -1
- package/dist/lib/utils/decision-routing.js +9 -4
- package/dist/lib/utils/decision-routing.js.map +1 -1
- package/dist/public-api.d.ts +15 -0
- package/dist/public-api.d.ts.map +1 -1
- package/dist/public-api.js +17 -1
- package/dist/public-api.js.map +1 -1
- package/package.json +42 -37
|
@@ -0,0 +1,1244 @@
|
|
|
1
|
+
import { Injectable, inject } from '@angular/core';
|
|
2
|
+
import { Metadata, RunView } from '@memberjunction/core';
|
|
3
|
+
import { ArtifactMetadataEngine, ArtifactPermissionEngine, BuildArtifactVersionConfigurationWithPreview, GetConnectedDriveLinkFromConfig, MergeConnectedDriveLinkIntoConfig, MJEnvironmentEntityExtended, SlideDeckEngine, SpreadsheetEngine, SynthesizeArtifactFromSourcesOperation, } from '@memberjunction/core-entities';
|
|
4
|
+
import { EscapeSQLString, UUIDsEqual } from '@memberjunction/global';
|
|
5
|
+
import { GraphQLDataProvider, GraphQLFileStorageClient } from '@memberjunction/graphql-dataprovider';
|
|
6
|
+
import { ArtifactFileService, DocumentImportExportService, SlideDeckExportService } from '@memberjunction/ng-artifacts';
|
|
7
|
+
import { CollectionPermissionService } from './collection-permission.service';
|
|
8
|
+
import { GraphQLAttachmentBlobStore } from './graphql-attachment-blob-store';
|
|
9
|
+
import * as i0 from "@angular/core";
|
|
10
|
+
/**
|
|
11
|
+
* Thrown by {@link LibraryCreationService.PublishArtifactVersionToConnectedDrive} when a file with the
|
|
12
|
+
* target name already exists in the remote folder and `AllowOverwrite` has not been confirmed.
|
|
13
|
+
*/
|
|
14
|
+
export class RemoteDriveFileExistsError extends Error {
|
|
15
|
+
ObjectPath;
|
|
16
|
+
constructor(objectPath, fileName) {
|
|
17
|
+
super(`A file named "${fileName}" already exists at "${objectPath}".`);
|
|
18
|
+
this.name = 'RemoteDriveFileExistsError';
|
|
19
|
+
this.ObjectPath = objectPath;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Thrown by {@link LibraryCreationService.PushVersionToConnectedDrive} when the remote file ETag
|
|
24
|
+
* changed since the last sync and `ForceOverwrite` is false.
|
|
25
|
+
*/
|
|
26
|
+
export class RemoteDriveConflictError extends Error {
|
|
27
|
+
ObjectPath;
|
|
28
|
+
ExpectedETag;
|
|
29
|
+
ActualETag;
|
|
30
|
+
constructor(objectPath, expectedETag, actualETag) {
|
|
31
|
+
super(`Remote file "${objectPath}" has changed on Connected Drive since last sync` +
|
|
32
|
+
(expectedETag && actualETag ? ` (expected ETag "${expectedETag}", found "${actualETag}")` : '') +
|
|
33
|
+
'. Pull latest or confirm overwrite.');
|
|
34
|
+
this.name = 'RemoteDriveConflictError';
|
|
35
|
+
this.ObjectPath = objectPath;
|
|
36
|
+
this.ExpectedETag = expectedETag;
|
|
37
|
+
this.ActualETag = actualETag;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const CONVERTIBLE_EXTENSIONS = new Set(['docx', 'md', 'markdown', 'txt', 'xlsx', 'csv', 'sql', 'json']);
|
|
41
|
+
/**
|
|
42
|
+
* Service encapsulating native Library artifact creation, local file upload/conversion,
|
|
43
|
+
* and stateless conversions/exports between Native Library and external Connected Drives.
|
|
44
|
+
*
|
|
45
|
+
* Architectural invariant:
|
|
46
|
+
* - External Connected Drive operations (`ConvertRemoteDriveObjectToNativeArtifact` and
|
|
47
|
+
* `PublishArtifactVersionToConnectedDrive`) NEVER create `MJ: Files` database records.
|
|
48
|
+
* - `MJ: Files` is created ONLY when a user uploads a binary file directly into Native Library
|
|
49
|
+
* (`ImportLocalFileToLibrary` with `ConvertToEditable = false` or non-convertible binary).
|
|
50
|
+
*/
|
|
51
|
+
export class LibraryCreationService {
|
|
52
|
+
docImportExport = inject(DocumentImportExportService);
|
|
53
|
+
slideExport = inject(SlideDeckExportService);
|
|
54
|
+
collectionPermissions = inject(CollectionPermissionService);
|
|
55
|
+
artifactFileService = inject(ArtifactFileService, { optional: true });
|
|
56
|
+
blobStoreOverride = null;
|
|
57
|
+
/**
|
|
58
|
+
* Optional test seam to override the attachment blob store used for binary `ContentMode = 'File'` uploads.
|
|
59
|
+
*/
|
|
60
|
+
SetBlobStoreOverride(store) {
|
|
61
|
+
this.blobStoreOverride = store;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Returns `true` when a filename extension can be converted into an inline collaborative MJ artifact (`ContentMode = 'Text'`).
|
|
65
|
+
*/
|
|
66
|
+
IsConvertibleFileName(fileName) {
|
|
67
|
+
const ext = this.extractExtension(fileName);
|
|
68
|
+
return CONVERTIBLE_EXTENSIONS.has(ext);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Loads enabled `MJ: Artifact Types` via `ArtifactMetadataEngine` (falling back to `RunView` if cache is empty).
|
|
72
|
+
*/
|
|
73
|
+
async LoadEnabledArtifactTypes(user, provider) {
|
|
74
|
+
const md = provider ?? Metadata.Provider;
|
|
75
|
+
try {
|
|
76
|
+
await ArtifactMetadataEngine.Instance.Config(false, user, md);
|
|
77
|
+
const cached = ArtifactMetadataEngine.Instance.ArtifactTypes.filter((t) => t.IsEnabled !== false);
|
|
78
|
+
if (cached.length > 0) {
|
|
79
|
+
return cached;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
// Fall back to direct RunView below
|
|
84
|
+
}
|
|
85
|
+
const rv = RunView.FromMetadataProvider(md);
|
|
86
|
+
const result = await rv.RunView({
|
|
87
|
+
EntityName: 'MJ: Artifact Types',
|
|
88
|
+
ExtraFilter: 'IsEnabled=1',
|
|
89
|
+
OrderBy: 'Name ASC',
|
|
90
|
+
ResultType: 'entity_object',
|
|
91
|
+
}, user);
|
|
92
|
+
return result.Success && result.Results ? result.Results : [];
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Resolves the canonical `MJ: Artifact Types` record for one of the four Hub starter tiles.
|
|
96
|
+
*/
|
|
97
|
+
FindStarterArtifactType(kind, types) {
|
|
98
|
+
switch (kind) {
|
|
99
|
+
case 'document':
|
|
100
|
+
return (types.find((t) => t.DriverClass === 'MarkdownArtifactViewerPlugin') ??
|
|
101
|
+
types.find((t) => t.Name.toLowerCase() === 'markdown document' || t.Name.toLowerCase() === 'markdown'));
|
|
102
|
+
case 'spreadsheet':
|
|
103
|
+
return (types.find((t) => t.DriverClass === 'SpreadsheetArtifactViewerPlugin') ??
|
|
104
|
+
types.find((t) => t.Name.toLowerCase() === 'excel spreadsheet' || t.Name.toLowerCase() === 'spreadsheet'));
|
|
105
|
+
case 'presentation':
|
|
106
|
+
return (types.find((t) => t.DriverClass === 'SlideDeckArtifactViewerPlugin') ??
|
|
107
|
+
types.find((t) => t.Name.toLowerCase() === 'presentation' || t.Name.toLowerCase() === 'slide deck'));
|
|
108
|
+
case 'query':
|
|
109
|
+
return (types.find((t) => t.Name.toLowerCase() === 'sql') ??
|
|
110
|
+
types.find((t) => t.ContentType?.toLowerCase() === 'application/sql'));
|
|
111
|
+
default: {
|
|
112
|
+
const exhaustiveCheck = kind;
|
|
113
|
+
return exhaustiveCheck;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Generates starter `Content` for a newly created blank native artifact.
|
|
119
|
+
*/
|
|
120
|
+
BuildStarterContent(kind, title) {
|
|
121
|
+
const cleanTitle = title.trim() || this.defaultTitleForStarter(kind);
|
|
122
|
+
switch (kind) {
|
|
123
|
+
case 'document':
|
|
124
|
+
return [
|
|
125
|
+
`# ${cleanTitle}`,
|
|
126
|
+
'',
|
|
127
|
+
'Start writing here, switch to **Suggesting** mode for tracked word-level edits, or embed a live governed **MJ Entity View / Saved Query** block.',
|
|
128
|
+
'',
|
|
129
|
+
'## Key Notes',
|
|
130
|
+
'',
|
|
131
|
+
'- Collaborative real-time editing powered by Yjs CRDTs',
|
|
132
|
+
'- Viewer-scoped Row-Level and Field-Level Security on live blocks',
|
|
133
|
+
].join('\n');
|
|
134
|
+
case 'spreadsheet': {
|
|
135
|
+
const wb = SpreadsheetEngine.Instance.CreateEmptyWorkbook(cleanTitle, ['Sheet 1']);
|
|
136
|
+
return JSON.stringify(wb, null, 2);
|
|
137
|
+
}
|
|
138
|
+
case 'presentation': {
|
|
139
|
+
const deck = SlideDeckEngine.Instance.CreateDefaultDeck(cleanTitle, `deck-${Date.now().toString(36)}`);
|
|
140
|
+
return JSON.stringify(deck, null, 2);
|
|
141
|
+
}
|
|
142
|
+
case 'query':
|
|
143
|
+
return [
|
|
144
|
+
`-- ${cleanTitle}`,
|
|
145
|
+
'-- Author your analytical SQL query below',
|
|
146
|
+
'SELECT TOP 25',
|
|
147
|
+
' Name,',
|
|
148
|
+
' SchemaName,',
|
|
149
|
+
' __mj_UpdatedAt',
|
|
150
|
+
'FROM [__mj].[vwEntities]',
|
|
151
|
+
'ORDER BY __mj_UpdatedAt DESC;',
|
|
152
|
+
].join('\n');
|
|
153
|
+
default: {
|
|
154
|
+
const exhaustiveCheck = kind;
|
|
155
|
+
return exhaustiveCheck;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Creates a new blank collaborative Document, Spreadsheet, Presentation, or SQL Query in Native Library.
|
|
161
|
+
*/
|
|
162
|
+
async CreateBlankArtifact(options) {
|
|
163
|
+
const md = options.Provider ?? Metadata.Provider;
|
|
164
|
+
const types = await this.LoadEnabledArtifactTypes(options.CurrentUser, md);
|
|
165
|
+
const matchedType = this.FindStarterArtifactType(options.Kind, types);
|
|
166
|
+
if (!matchedType) {
|
|
167
|
+
throw new Error(`No enabled MJ Artifact Type is registered for starter "${options.Kind}".`);
|
|
168
|
+
}
|
|
169
|
+
const cleanTitle = options.Title.trim() || this.defaultTitleForStarter(options.Kind);
|
|
170
|
+
const content = this.BuildStarterContent(options.Kind, cleanTitle);
|
|
171
|
+
return this.persistArtifactAndVersion({
|
|
172
|
+
Title: cleanTitle,
|
|
173
|
+
Description: options.Description?.trim() || null,
|
|
174
|
+
ArtifactType: matchedType,
|
|
175
|
+
ContentMode: 'Text',
|
|
176
|
+
Content: content,
|
|
177
|
+
FileID: null,
|
|
178
|
+
MimeType: matchedType.ContentType || null,
|
|
179
|
+
FileName: null,
|
|
180
|
+
ContentSizeBytes: new TextEncoder().encode(content).byteLength,
|
|
181
|
+
CollectionID: options.CollectionID ?? null,
|
|
182
|
+
EnvironmentID: options.EnvironmentID || MJEnvironmentEntityExtended.DefaultEnvironmentID,
|
|
183
|
+
CurrentUser: options.CurrentUser,
|
|
184
|
+
Provider: md,
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Creates a custom text artifact with an explicit `ArtifactTypeID` and raw `Content`.
|
|
189
|
+
*/
|
|
190
|
+
async CreateCustomTextArtifact(options) {
|
|
191
|
+
const md = options.Provider ?? Metadata.Provider;
|
|
192
|
+
const types = await this.LoadEnabledArtifactTypes(options.CurrentUser, md);
|
|
193
|
+
const matchedType = types.find((t) => UUIDsEqual(t.ID, options.ArtifactTypeID));
|
|
194
|
+
if (!matchedType) {
|
|
195
|
+
throw new Error('Selected Artifact Type was not found or is disabled.');
|
|
196
|
+
}
|
|
197
|
+
const cleanTitle = options.Title.trim() || 'Untitled Artifact';
|
|
198
|
+
const content = options.Content;
|
|
199
|
+
return this.persistArtifactAndVersion({
|
|
200
|
+
Title: cleanTitle,
|
|
201
|
+
Description: options.Description?.trim() || null,
|
|
202
|
+
ArtifactType: matchedType,
|
|
203
|
+
ContentMode: 'Text',
|
|
204
|
+
Content: content,
|
|
205
|
+
FileID: null,
|
|
206
|
+
MimeType: matchedType.ContentType || null,
|
|
207
|
+
FileName: null,
|
|
208
|
+
ContentSizeBytes: new TextEncoder().encode(content).byteLength,
|
|
209
|
+
CollectionID: options.CollectionID ?? null,
|
|
210
|
+
EnvironmentID: options.EnvironmentID || MJEnvironmentEntityExtended.DefaultEnvironmentID,
|
|
211
|
+
CurrentUser: options.CurrentUser,
|
|
212
|
+
Provider: md,
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Imports a local browser `File` into Native Library:
|
|
217
|
+
* - When `ConvertToEditable` is `true` and the extension is convertible, converts `.docx`/`.md`/`.xlsx`/`.csv`/`.sql`/`.json`
|
|
218
|
+
* into an editable `ContentMode = 'Text'` artifact (zero `MJ: Files` row).
|
|
219
|
+
* - Otherwise uploads the binary via `GraphQLAttachmentBlobStore` into MJ Storage and creates a `ContentMode = 'File'`
|
|
220
|
+
* artifact version referencing `FileID`.
|
|
221
|
+
*/
|
|
222
|
+
async ImportLocalFileToLibrary(options) {
|
|
223
|
+
const md = options.Provider ?? Metadata.Provider;
|
|
224
|
+
if (options.CollectionID) {
|
|
225
|
+
await this.assertCanWriteCollection(options.CollectionID, options.CurrentUser, md);
|
|
226
|
+
}
|
|
227
|
+
const types = await this.LoadEnabledArtifactTypes(options.CurrentUser, md);
|
|
228
|
+
const ext = this.extractExtension(options.File.name);
|
|
229
|
+
const defaultTitle = options.Title?.trim() || this.stripExtension(options.File.name) || 'Uploaded File';
|
|
230
|
+
if (options.ConvertToEditable && CONVERTIBLE_EXTENSIONS.has(ext)) {
|
|
231
|
+
const buffer = await options.File.arrayBuffer();
|
|
232
|
+
const converted = await this.convertBytesToNativeText(buffer, ext, defaultTitle, types);
|
|
233
|
+
return this.persistArtifactAndVersion({
|
|
234
|
+
Title: defaultTitle,
|
|
235
|
+
Description: options.Description?.trim() || `Imported from ${options.File.name}`,
|
|
236
|
+
ArtifactType: converted.ArtifactType,
|
|
237
|
+
ContentMode: 'Text',
|
|
238
|
+
Content: converted.Content,
|
|
239
|
+
FileID: null,
|
|
240
|
+
MimeType: converted.ArtifactType.ContentType || null,
|
|
241
|
+
FileName: options.File.name,
|
|
242
|
+
ContentSizeBytes: new TextEncoder().encode(converted.Content).byteLength,
|
|
243
|
+
CollectionID: options.CollectionID ?? null,
|
|
244
|
+
EnvironmentID: options.EnvironmentID || MJEnvironmentEntityExtended.DefaultEnvironmentID,
|
|
245
|
+
CurrentUser: options.CurrentUser,
|
|
246
|
+
Provider: md,
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
const mimeType = options.File.type || this.inferMimeFromExtension(ext);
|
|
250
|
+
const fileType = this.resolveBinaryArtifactType(mimeType, ext, types);
|
|
251
|
+
if (!fileType) {
|
|
252
|
+
throw new Error(`No Artifact Type is available for MIME type "${mimeType}".`);
|
|
253
|
+
}
|
|
254
|
+
// Binary file path: upload bytes to MJ Storage (creates governed MJ: Files record for Native Library)
|
|
255
|
+
const buffer = await options.File.arrayBuffer();
|
|
256
|
+
const base64Data = this.arrayBufferToBase64(buffer);
|
|
257
|
+
const store = this.blobStoreOverride ?? new GraphQLAttachmentBlobStore();
|
|
258
|
+
const uploadResult = await store.Upload({
|
|
259
|
+
FileName: options.File.name,
|
|
260
|
+
Base64Data: base64Data,
|
|
261
|
+
MimeType: mimeType,
|
|
262
|
+
}, options.CurrentUser, md);
|
|
263
|
+
if (!uploadResult.Success || !uploadResult.FileID) {
|
|
264
|
+
throw new Error(uploadResult.Error || `Failed to upload "${options.File.name}" to MJ Storage.`);
|
|
265
|
+
}
|
|
266
|
+
return this.persistArtifactAndVersion({
|
|
267
|
+
Title: defaultTitle,
|
|
268
|
+
Description: options.Description?.trim() || null,
|
|
269
|
+
ArtifactType: fileType,
|
|
270
|
+
ContentMode: 'File',
|
|
271
|
+
Content: null,
|
|
272
|
+
FileID: uploadResult.FileID,
|
|
273
|
+
MimeType: mimeType,
|
|
274
|
+
FileName: options.File.name,
|
|
275
|
+
ContentSizeBytes: options.File.size,
|
|
276
|
+
CollectionID: options.CollectionID ?? null,
|
|
277
|
+
EnvironmentID: options.EnvironmentID || MJEnvironmentEntityExtended.DefaultEnvironmentID,
|
|
278
|
+
CurrentUser: options.CurrentUser,
|
|
279
|
+
Provider: md,
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Streams an external Connected Drive file via a short-lived pre-authenticated URL and converts it
|
|
284
|
+
* in memory into a collaborative `ContentMode = 'Text'` native MJ Artifact.
|
|
285
|
+
*
|
|
286
|
+
* **Zero `MJ: Files` database records are created.**
|
|
287
|
+
*/
|
|
288
|
+
async ConvertRemoteDriveObjectToNativeArtifact(options) {
|
|
289
|
+
const md = options.Provider ?? Metadata.Provider;
|
|
290
|
+
if (options.CollectionID) {
|
|
291
|
+
await this.assertCanWriteCollection(options.CollectionID, options.CurrentUser, md);
|
|
292
|
+
}
|
|
293
|
+
const ext = this.extractExtension(options.FileName);
|
|
294
|
+
if (!CONVERTIBLE_EXTENSIONS.has(ext)) {
|
|
295
|
+
throw new Error(`"${options.FileName}" cannot be converted to an editable native document or spreadsheet. Use Preview or Download instead.`);
|
|
296
|
+
}
|
|
297
|
+
const storageClient = options.StorageClientOverride ?? this.createGraphQLFileStorageClient(md);
|
|
298
|
+
const downloadUrl = await storageClient.CreatePreAuthDownloadUrl(options.AccountID, options.ObjectPath);
|
|
299
|
+
const fetchBytes = options.FetchBytesOverride ??
|
|
300
|
+
(async (url) => {
|
|
301
|
+
const resp = await fetch(url);
|
|
302
|
+
if (!resp.ok) {
|
|
303
|
+
throw new Error(`Failed to read remote file (${resp.status} ${resp.statusText}).`);
|
|
304
|
+
}
|
|
305
|
+
return resp.arrayBuffer();
|
|
306
|
+
});
|
|
307
|
+
const buffer = await fetchBytes(downloadUrl);
|
|
308
|
+
const types = await this.LoadEnabledArtifactTypes(options.CurrentUser, md);
|
|
309
|
+
const cleanTitle = options.Title?.trim() || this.stripExtension(options.FileName) || 'Imported Copy';
|
|
310
|
+
const converted = await this.convertBytesToNativeText(buffer, ext, cleanTitle, types);
|
|
311
|
+
const driveLinkMeta = {
|
|
312
|
+
ExternalFileID: options.ObjectPath,
|
|
313
|
+
ProviderType: options.ProviderType ?? 'ConnectedDrive',
|
|
314
|
+
ProviderIntegrationID: options.AccountID,
|
|
315
|
+
FolderID: options.FolderID,
|
|
316
|
+
FileName: options.FileName,
|
|
317
|
+
WebUrl: options.WebUrl,
|
|
318
|
+
MimeType: converted.ArtifactType.ContentType || this.inferMimeFromExtension(ext),
|
|
319
|
+
ETag: options.ETag,
|
|
320
|
+
RemoteModifiedAt: options.RemoteModifiedAt,
|
|
321
|
+
SyncedVersionNumber: 1,
|
|
322
|
+
LastSyncedAt: new Date().toISOString(),
|
|
323
|
+
LastSyncDirection: 'pull',
|
|
324
|
+
LastSyncedByUserID: options.CurrentUser.ID,
|
|
325
|
+
};
|
|
326
|
+
return this.persistArtifactAndVersion({
|
|
327
|
+
Title: cleanTitle,
|
|
328
|
+
Description: `Editable copy imported from Connected Drive (${options.ObjectPath})`,
|
|
329
|
+
ArtifactType: converted.ArtifactType,
|
|
330
|
+
ContentMode: 'Text',
|
|
331
|
+
Content: converted.Content,
|
|
332
|
+
FileID: null,
|
|
333
|
+
MimeType: converted.ArtifactType.ContentType || null,
|
|
334
|
+
FileName: options.FileName,
|
|
335
|
+
ContentSizeBytes: new TextEncoder().encode(converted.Content).byteLength,
|
|
336
|
+
CollectionID: options.CollectionID ?? null,
|
|
337
|
+
EnvironmentID: options.EnvironmentID || MJEnvironmentEntityExtended.DefaultEnvironmentID,
|
|
338
|
+
CurrentUser: options.CurrentUser,
|
|
339
|
+
Provider: md,
|
|
340
|
+
InitialConfigurationJson: MergeConnectedDriveLinkIntoConfig(null, driveLinkMeta),
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* 1-Click Connected Drive Round-Trip Push (§6.1): serializes the current artifact version
|
|
345
|
+
* back to its linked Connected Drive path after verifying the remote ETag has not drifted
|
|
346
|
+
* (zero `MJ: Files` rows created).
|
|
347
|
+
*/
|
|
348
|
+
async PushVersionToConnectedDrive(options) {
|
|
349
|
+
const md = options.Provider ?? Metadata.Provider;
|
|
350
|
+
const artifact = await md.GetEntityObject('MJ: Artifacts', options.CurrentUser);
|
|
351
|
+
if (!(await artifact.Load(options.ArtifactID))) {
|
|
352
|
+
throw new Error(`Artifact "${options.ArtifactID}" was not found.`);
|
|
353
|
+
}
|
|
354
|
+
const permissions = await ArtifactPermissionEngine.Instance.ResolvePermissions(md, artifact.ID, options.CurrentUser);
|
|
355
|
+
if (!permissions.CanEdit) {
|
|
356
|
+
throw new Error(`Permission denied: you do not have Edit access to "${artifact.Name}".`);
|
|
357
|
+
}
|
|
358
|
+
const versions = await this.loadArtifactVersionsDesc(artifact.ID, options.CurrentUser, md);
|
|
359
|
+
const targetVersion = (options.VersionID ? versions.find((v) => UUIDsEqual(v.ID, options.VersionID)) : undefined) ??
|
|
360
|
+
versions[0];
|
|
361
|
+
if (!targetVersion) {
|
|
362
|
+
throw new Error(`No versions found for artifact "${artifact.Name}".`);
|
|
363
|
+
}
|
|
364
|
+
const existingLink = GetConnectedDriveLinkFromConfig(targetVersion.Configuration);
|
|
365
|
+
const accountId = options.AccountID || existingLink?.ProviderIntegrationID;
|
|
366
|
+
const objectPath = options.ObjectPath || existingLink?.ExternalFileID;
|
|
367
|
+
if (!accountId || !objectPath) {
|
|
368
|
+
throw new Error('This artifact version is not linked to a Connected Drive destination.');
|
|
369
|
+
}
|
|
370
|
+
const storageClient = options.StorageClientOverride ?? this.createGraphQLFileStorageClient(md);
|
|
371
|
+
const mustVerifyEtag = !options.ForceOverwrite && Boolean(existingLink?.ETag);
|
|
372
|
+
const remoteBefore = await this.findRemoteObjectMetadata(storageClient, accountId, objectPath, {
|
|
373
|
+
throwOnError: mustVerifyEtag,
|
|
374
|
+
});
|
|
375
|
+
if (!options.ForceOverwrite &&
|
|
376
|
+
existingLink?.ETag &&
|
|
377
|
+
remoteBefore?.ETag &&
|
|
378
|
+
remoteBefore.ETag !== existingLink.ETag) {
|
|
379
|
+
throw new RemoteDriveConflictError(objectPath, existingLink.ETag, remoteBefore.ETag);
|
|
380
|
+
}
|
|
381
|
+
const { prefix, fileName } = this.splitObjectPath(objectPath);
|
|
382
|
+
const format = options.Format ??
|
|
383
|
+
this.inferExportFormat(fileName, targetVersion.ContentMode, targetVersion.Content);
|
|
384
|
+
const published = await this.PublishArtifactVersionToConnectedDrive({
|
|
385
|
+
ArtifactName: artifact.Name,
|
|
386
|
+
VersionContent: targetVersion.Content ?? '',
|
|
387
|
+
VersionConfiguration: targetVersion.Configuration ?? null,
|
|
388
|
+
VersionContentMode: targetVersion.ContentMode,
|
|
389
|
+
ArtifactVersionID: targetVersion.ID,
|
|
390
|
+
VersionFileID: targetVersion.FileID ?? null,
|
|
391
|
+
VersionMimeType: targetVersion.MimeType ?? null,
|
|
392
|
+
VersionFileName: targetVersion.FileName ?? fileName,
|
|
393
|
+
Format: format,
|
|
394
|
+
AccountID: accountId,
|
|
395
|
+
TargetFolderPrefix: prefix,
|
|
396
|
+
TargetFileName: fileName,
|
|
397
|
+
AllowOverwrite: true,
|
|
398
|
+
CurrentUser: options.CurrentUser,
|
|
399
|
+
Provider: md,
|
|
400
|
+
StorageClientOverride: storageClient,
|
|
401
|
+
UploadBytesOverride: options.UploadBytesOverride,
|
|
402
|
+
DownloadFileBytesOverride: options.DownloadFileBytesOverride,
|
|
403
|
+
});
|
|
404
|
+
const remoteAfter = await this.findRemoteObjectMetadata(storageClient, accountId, published.ObjectPath);
|
|
405
|
+
const nextETag = remoteAfter?.ETag ?? existingLink?.ETag;
|
|
406
|
+
const nextLink = {
|
|
407
|
+
...(existingLink ?? {
|
|
408
|
+
ExternalFileID: published.ObjectPath,
|
|
409
|
+
ProviderType: 'ConnectedDrive',
|
|
410
|
+
ProviderIntegrationID: accountId,
|
|
411
|
+
}),
|
|
412
|
+
ExternalFileID: published.ObjectPath,
|
|
413
|
+
ProviderIntegrationID: accountId,
|
|
414
|
+
FileName: fileName,
|
|
415
|
+
MimeType: published.MimeType,
|
|
416
|
+
ETag: nextETag,
|
|
417
|
+
RemoteModifiedAt: remoteAfter?.LastModified ?? new Date().toISOString(),
|
|
418
|
+
SyncedVersionNumber: targetVersion.VersionNumber,
|
|
419
|
+
LastSyncedAt: new Date().toISOString(),
|
|
420
|
+
LastSyncDirection: 'push',
|
|
421
|
+
LastSyncedByUserID: options.CurrentUser.ID,
|
|
422
|
+
};
|
|
423
|
+
const updatedConfig = MergeConnectedDriveLinkIntoConfig(targetVersion.Configuration, nextLink);
|
|
424
|
+
targetVersion.Configuration = updatedConfig;
|
|
425
|
+
if (!(await targetVersion.Save())) {
|
|
426
|
+
throw new Error(targetVersion.LatestResult?.Message || 'Failed to update Connected Drive sync metadata.');
|
|
427
|
+
}
|
|
428
|
+
await this.recordConnectedDriveAuditLog({
|
|
429
|
+
Direction: 'push',
|
|
430
|
+
ArtifactID: artifact.ID,
|
|
431
|
+
VersionID: targetVersion.ID,
|
|
432
|
+
VersionNumber: targetVersion.VersionNumber,
|
|
433
|
+
ObjectPath: published.ObjectPath,
|
|
434
|
+
ETag: nextETag,
|
|
435
|
+
CurrentUser: options.CurrentUser,
|
|
436
|
+
Provider: md,
|
|
437
|
+
});
|
|
438
|
+
return {
|
|
439
|
+
ArtifactID: artifact.ID,
|
|
440
|
+
VersionID: targetVersion.ID,
|
|
441
|
+
VersionNumber: targetVersion.VersionNumber,
|
|
442
|
+
ObjectPath: published.ObjectPath,
|
|
443
|
+
ByteLength: published.ByteLength,
|
|
444
|
+
ETag: nextETag,
|
|
445
|
+
UpdatedConfiguration: updatedConfig,
|
|
446
|
+
};
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* 1-Click Connected Drive Round-Trip Pull (§6.1): downloads the latest remote bytes
|
|
450
|
+
* from a linked Connected Drive file and creates `vN+1` in MJ Library without creating
|
|
451
|
+
* any `MJ: Files` row, returning version numbers so the host can open the diff view.
|
|
452
|
+
*/
|
|
453
|
+
async PullLatestFromConnectedDriveAsNewVersion(options) {
|
|
454
|
+
const md = options.Provider ?? Metadata.Provider;
|
|
455
|
+
const artifact = await md.GetEntityObject('MJ: Artifacts', options.CurrentUser);
|
|
456
|
+
if (!(await artifact.Load(options.ArtifactID))) {
|
|
457
|
+
throw new Error(`Artifact "${options.ArtifactID}" was not found.`);
|
|
458
|
+
}
|
|
459
|
+
const permissions = await ArtifactPermissionEngine.Instance.ResolvePermissions(md, artifact.ID, options.CurrentUser);
|
|
460
|
+
if (!permissions.CanEdit) {
|
|
461
|
+
throw new Error(`Permission denied: you do not have Edit access to "${artifact.Name}".`);
|
|
462
|
+
}
|
|
463
|
+
const versions = await this.loadArtifactVersionsDesc(artifact.ID, options.CurrentUser, md);
|
|
464
|
+
const latestVersion = versions[0];
|
|
465
|
+
const requestedVersion = (options.VersionID ? versions.find((v) => UUIDsEqual(v.ID, options.VersionID)) : undefined) ??
|
|
466
|
+
latestVersion;
|
|
467
|
+
if (!requestedVersion || !latestVersion) {
|
|
468
|
+
throw new Error(`No versions found for artifact "${artifact.Name}".`);
|
|
469
|
+
}
|
|
470
|
+
const existingLink = GetConnectedDriveLinkFromConfig(requestedVersion.Configuration);
|
|
471
|
+
const accountId = options.AccountID || existingLink?.ProviderIntegrationID;
|
|
472
|
+
const objectPath = options.ObjectPath || existingLink?.ExternalFileID;
|
|
473
|
+
if (!accountId || !objectPath) {
|
|
474
|
+
throw new Error('This artifact version is not linked to a Connected Drive source.');
|
|
475
|
+
}
|
|
476
|
+
const storageClient = options.StorageClientOverride ?? this.createGraphQLFileStorageClient(md);
|
|
477
|
+
const remoteMeta = await this.findRemoteObjectMetadata(storageClient, accountId, objectPath);
|
|
478
|
+
const downloadUrl = await storageClient.CreatePreAuthDownloadUrl(accountId, objectPath);
|
|
479
|
+
const fetchBytes = options.FetchBytesOverride ??
|
|
480
|
+
(async (url) => {
|
|
481
|
+
const resp = await fetch(url);
|
|
482
|
+
if (!resp.ok) {
|
|
483
|
+
throw new Error(`Failed to read remote file (${resp.status} ${resp.statusText}).`);
|
|
484
|
+
}
|
|
485
|
+
return resp.arrayBuffer();
|
|
486
|
+
});
|
|
487
|
+
const buffer = await fetchBytes(downloadUrl);
|
|
488
|
+
const { fileName } = this.splitObjectPath(objectPath);
|
|
489
|
+
const effectiveFileName = existingLink?.FileName || fileName;
|
|
490
|
+
const ext = this.extractExtension(effectiveFileName);
|
|
491
|
+
if (!CONVERTIBLE_EXTENSIONS.has(ext)) {
|
|
492
|
+
throw new Error(`Cannot pull "${effectiveFileName}" into an editable native version (unsupported extension ".${ext}").`);
|
|
493
|
+
}
|
|
494
|
+
const types = await this.LoadEnabledArtifactTypes(options.CurrentUser, md);
|
|
495
|
+
const converted = await this.convertBytesToNativeText(buffer, ext, artifact.Name, types);
|
|
496
|
+
const previousVersionNumber = requestedVersion.VersionNumber;
|
|
497
|
+
const nextVersionNumber = (latestVersion.VersionNumber ?? 0) + 1;
|
|
498
|
+
const nextLink = {
|
|
499
|
+
...(existingLink ?? {
|
|
500
|
+
ExternalFileID: objectPath,
|
|
501
|
+
ProviderType: 'ConnectedDrive',
|
|
502
|
+
ProviderIntegrationID: accountId,
|
|
503
|
+
}),
|
|
504
|
+
ExternalFileID: objectPath,
|
|
505
|
+
ProviderIntegrationID: accountId,
|
|
506
|
+
FileName: effectiveFileName,
|
|
507
|
+
ETag: remoteMeta?.ETag ?? existingLink?.ETag,
|
|
508
|
+
RemoteModifiedAt: remoteMeta?.LastModified ?? new Date().toISOString(),
|
|
509
|
+
SyncedVersionNumber: nextVersionNumber,
|
|
510
|
+
LastSyncedAt: new Date().toISOString(),
|
|
511
|
+
LastSyncDirection: 'pull',
|
|
512
|
+
LastSyncedByUserID: options.CurrentUser.ID,
|
|
513
|
+
};
|
|
514
|
+
const baseConfig = MergeConnectedDriveLinkIntoConfig(requestedVersion.Configuration, nextLink);
|
|
515
|
+
const allTypes = ArtifactMetadataEngine.Instance.ArtifactTypes ?? types;
|
|
516
|
+
const nextConfig = BuildArtifactVersionConfigurationWithPreview(baseConfig, converted.Content, converted.ArtifactType.DriverClass ?? null, artifact.Name, {
|
|
517
|
+
ArtifactType: converted.ArtifactType,
|
|
518
|
+
AllArtifactTypes: allTypes,
|
|
519
|
+
}) ?? baseConfig;
|
|
520
|
+
const newVersion = await md.GetEntityObject('MJ: Artifact Versions', options.CurrentUser);
|
|
521
|
+
newVersion.ArtifactID = artifact.ID;
|
|
522
|
+
newVersion.VersionNumber = nextVersionNumber;
|
|
523
|
+
newVersion.Name = artifact.Name;
|
|
524
|
+
newVersion.Description = `Pulled latest from Connected Drive (${objectPath})`;
|
|
525
|
+
newVersion.UserID = options.CurrentUser.ID;
|
|
526
|
+
newVersion.ContentMode = 'Text';
|
|
527
|
+
newVersion.Content = converted.Content;
|
|
528
|
+
newVersion.FileID = null;
|
|
529
|
+
newVersion.MimeType = converted.ArtifactType.ContentType || requestedVersion.MimeType || null;
|
|
530
|
+
newVersion.FileName = effectiveFileName;
|
|
531
|
+
newVersion.ContentSizeBytes = new TextEncoder().encode(converted.Content).byteLength;
|
|
532
|
+
newVersion.Configuration = nextConfig;
|
|
533
|
+
if (!(await newVersion.Save())) {
|
|
534
|
+
throw new Error(newVersion.LatestResult?.Message || 'Failed to save pulled Connected Drive version.');
|
|
535
|
+
}
|
|
536
|
+
await this.recordConnectedDriveAuditLog({
|
|
537
|
+
Direction: 'pull',
|
|
538
|
+
ArtifactID: artifact.ID,
|
|
539
|
+
VersionID: newVersion.ID,
|
|
540
|
+
VersionNumber: nextVersionNumber,
|
|
541
|
+
ObjectPath: objectPath,
|
|
542
|
+
ETag: nextLink.ETag,
|
|
543
|
+
CurrentUser: options.CurrentUser,
|
|
544
|
+
Provider: md,
|
|
545
|
+
});
|
|
546
|
+
return {
|
|
547
|
+
ArtifactID: artifact.ID,
|
|
548
|
+
PreviousVersionNumber: previousVersionNumber,
|
|
549
|
+
NewVersionID: newVersion.ID,
|
|
550
|
+
NewVersionNumber: nextVersionNumber,
|
|
551
|
+
ObjectPath: objectPath,
|
|
552
|
+
ETag: nextLink.ETag,
|
|
553
|
+
UpdatedConfiguration: nextConfig,
|
|
554
|
+
};
|
|
555
|
+
}
|
|
556
|
+
/**
|
|
557
|
+
* Executes the `Artifact.SynthesizeFromSources` remote operation (`SynthesizeArtifactFromSourcesOperation`)
|
|
558
|
+
* to read multiple governed artifacts, synthesize a brand-new `Presentation`, `Markdown Document`, or
|
|
559
|
+
* `Excel Spreadsheet` with live chart/range links, enforce `CanRead` / `CanEdit` permissions, stream
|
|
560
|
+
* progress updates, and save v1.
|
|
561
|
+
*/
|
|
562
|
+
async SynthesizeArtifactFromSources(options) {
|
|
563
|
+
const op = new SynthesizeArtifactFromSourcesOperation();
|
|
564
|
+
const opInput = {
|
|
565
|
+
TargetKind: options.TargetKind,
|
|
566
|
+
Goal: options.Goal,
|
|
567
|
+
SourceArtifactIds: Array.from(options.SourceArtifactIds),
|
|
568
|
+
CollectionId: options.CollectionID || null,
|
|
569
|
+
Title: options.Title?.trim() || null,
|
|
570
|
+
AgentHandle: options.AgentHandle?.trim() || null,
|
|
571
|
+
LinkChartsAndRanges: options.LinkChartsAndRanges !== false,
|
|
572
|
+
};
|
|
573
|
+
const result = await op.Execute(opInput, {
|
|
574
|
+
provider: options.Provider ?? GraphQLDataProvider.Instance,
|
|
575
|
+
mode: 'attached',
|
|
576
|
+
onProgress: options.OnProgress,
|
|
577
|
+
});
|
|
578
|
+
if (!result.Success || !result.Output?.ArtifactID) {
|
|
579
|
+
throw new Error(result.ErrorMessage || 'Artifact synthesis failed.');
|
|
580
|
+
}
|
|
581
|
+
const payload = result.Output;
|
|
582
|
+
return {
|
|
583
|
+
Success: true,
|
|
584
|
+
AccessDenied: result.ResultCode === 'ACCESS_DENIED' || result.ResultCode === 'FORBIDDEN',
|
|
585
|
+
ErrorMessage: result.ErrorMessage,
|
|
586
|
+
ArtifactID: payload.ArtifactID,
|
|
587
|
+
VersionID: payload.VersionID ?? '',
|
|
588
|
+
VersionNumber: payload.VersionNumber ?? 1,
|
|
589
|
+
Title: payload.Title ?? options.Title?.trim() ?? 'Synthesized Artifact',
|
|
590
|
+
ArtifactTypeName: payload.ArtifactTypeName ?? 'Presentation',
|
|
591
|
+
LinkedChartCount: payload.LinkedChartCount ?? 0,
|
|
592
|
+
SourceCount: payload.SourceCount ?? options.SourceArtifactIds.length,
|
|
593
|
+
Warnings: Array.isArray(payload.Warnings) ? payload.Warnings : [],
|
|
594
|
+
UsedFallback: Boolean(payload.UsedFallback),
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
/**
|
|
598
|
+
* Exports a native MJ Artifact version into `.docx`, `.md`, `.xlsx`, `.csv`, `.pptx`, `.json`, `.sql`, `.txt`,
|
|
599
|
+
* or its original binary file bytes (`ContentMode === 'File'`), checks for target path collisions,
|
|
600
|
+
* and uploads directly to an external Connected Drive path via `CreatePreAuthUploadUrl`.
|
|
601
|
+
*
|
|
602
|
+
* **Zero `MJ: Files` database records are created.**
|
|
603
|
+
*/
|
|
604
|
+
async PublishArtifactVersionToConnectedDrive(options) {
|
|
605
|
+
const isFileMode = options.VersionContentMode === 'File' &&
|
|
606
|
+
Boolean(options.VersionFileID || options.ArtifactVersionID);
|
|
607
|
+
let bytes;
|
|
608
|
+
let mimeType;
|
|
609
|
+
let extension;
|
|
610
|
+
if (isFileMode) {
|
|
611
|
+
bytes = await this.downloadFileVersionBytes(options);
|
|
612
|
+
extension =
|
|
613
|
+
this.extractExtension(options.VersionFileName ?? '') ||
|
|
614
|
+
this.extractExtension(options.TargetFileName ?? '') ||
|
|
615
|
+
this.extensionFromMime(options.VersionMimeType) ||
|
|
616
|
+
(options.Format !== 'original' ? options.Format : 'bin');
|
|
617
|
+
mimeType = options.VersionMimeType || this.inferMimeFromExtension(extension);
|
|
618
|
+
}
|
|
619
|
+
else {
|
|
620
|
+
const serialized = await this.serializeExportPayload(options.ArtifactName, options.VersionContent, options.VersionConfiguration ?? null, options.Format, options.CurrentUser);
|
|
621
|
+
bytes = serialized.bytes;
|
|
622
|
+
mimeType = serialized.mimeType;
|
|
623
|
+
extension = serialized.extension;
|
|
624
|
+
}
|
|
625
|
+
const rawBaseName = options.TargetFileName?.trim() ||
|
|
626
|
+
(isFileMode && options.VersionFileName ? this.stripExtension(options.VersionFileName) : '') ||
|
|
627
|
+
this.sanitizeFileName(options.ArtifactName);
|
|
628
|
+
const cleanExt = extension ? `.${extension.toLowerCase()}` : '';
|
|
629
|
+
const baseFileName = cleanExt && rawBaseName.toLowerCase().endsWith(cleanExt)
|
|
630
|
+
? rawBaseName.slice(0, rawBaseName.length - cleanExt.length)
|
|
631
|
+
: rawBaseName;
|
|
632
|
+
const finalFileName = extension ? `${baseFileName}.${extension}` : baseFileName;
|
|
633
|
+
const rawPrefix = options.TargetFolderPrefix ?? '';
|
|
634
|
+
let prefixStart = 0;
|
|
635
|
+
while (prefixStart < rawPrefix.length && rawPrefix[prefixStart] === '/') {
|
|
636
|
+
prefixStart++;
|
|
637
|
+
}
|
|
638
|
+
let prefixEnd = rawPrefix.length;
|
|
639
|
+
while (prefixEnd > prefixStart && rawPrefix[prefixEnd - 1] === '/') {
|
|
640
|
+
prefixEnd--;
|
|
641
|
+
}
|
|
642
|
+
const cleanPrefix = rawPrefix.slice(prefixStart, prefixEnd);
|
|
643
|
+
const objectPath = cleanPrefix ? `${cleanPrefix}/${finalFileName}` : finalFileName;
|
|
644
|
+
const storageClient = options.StorageClientOverride ?? this.createGraphQLFileStorageClient(options.Provider);
|
|
645
|
+
if (!options.AllowOverwrite) {
|
|
646
|
+
const alreadyExists = await this.remoteObjectExists(storageClient, options.AccountID, cleanPrefix, finalFileName, objectPath);
|
|
647
|
+
if (alreadyExists) {
|
|
648
|
+
throw new RemoteDriveFileExistsError(objectPath, finalFileName);
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
const uploadTarget = await storageClient.CreatePreAuthUploadUrl(options.AccountID, objectPath, mimeType);
|
|
652
|
+
if (!uploadTarget.success || !uploadTarget.uploadUrl) {
|
|
653
|
+
throw new Error('Storage provider did not return a pre-authenticated upload URL for this Connected Drive.');
|
|
654
|
+
}
|
|
655
|
+
const uploadFn = options.UploadBytesOverride ??
|
|
656
|
+
(async (url, payload, contentType) => {
|
|
657
|
+
const bodyBuffer = payload.buffer.slice(payload.byteOffset, payload.byteOffset + payload.byteLength);
|
|
658
|
+
const response = await fetch(url, {
|
|
659
|
+
method: 'PUT',
|
|
660
|
+
headers: { 'Content-Type': contentType },
|
|
661
|
+
body: bodyBuffer,
|
|
662
|
+
});
|
|
663
|
+
if (!response.ok) {
|
|
664
|
+
throw new Error(`Connected Drive upload failed (${response.status} ${response.statusText}).`);
|
|
665
|
+
}
|
|
666
|
+
});
|
|
667
|
+
await uploadFn(uploadTarget.uploadUrl, bytes, mimeType);
|
|
668
|
+
return {
|
|
669
|
+
ObjectPath: objectPath,
|
|
670
|
+
ByteLength: bytes.byteLength,
|
|
671
|
+
MimeType: mimeType,
|
|
672
|
+
};
|
|
673
|
+
}
|
|
674
|
+
/**
|
|
675
|
+
* Returns recommended Connected Drive export formats for a given `DriverClass`, `ArtifactType` name,
|
|
676
|
+
* or binary `ContentMode = 'File'` artifact.
|
|
677
|
+
*/
|
|
678
|
+
GetSupportedDriveExportFormats(driverClass, typeName, contentMode, fileName) {
|
|
679
|
+
if (contentMode === 'File') {
|
|
680
|
+
const ext = this.extractExtension(fileName ?? '');
|
|
681
|
+
return [
|
|
682
|
+
{
|
|
683
|
+
Format: 'original',
|
|
684
|
+
Label: ext ? `Original File (.${ext})` : 'Original Binary File',
|
|
685
|
+
},
|
|
686
|
+
];
|
|
687
|
+
}
|
|
688
|
+
const dc = (driverClass ?? '').trim();
|
|
689
|
+
const tn = (typeName ?? '').trim().toLowerCase();
|
|
690
|
+
if (dc === 'MarkdownArtifactViewerPlugin' || tn.includes('markdown')) {
|
|
691
|
+
return [
|
|
692
|
+
{ Format: 'docx', Label: 'Microsoft Word (.docx)' },
|
|
693
|
+
{ Format: 'md', Label: 'Markdown (.md)' },
|
|
694
|
+
];
|
|
695
|
+
}
|
|
696
|
+
if (dc === 'SpreadsheetArtifactViewerPlugin' || tn.includes('spreadsheet') || tn === 'csv') {
|
|
697
|
+
return [
|
|
698
|
+
{ Format: 'xlsx', Label: 'Microsoft Excel (.xlsx)' },
|
|
699
|
+
{ Format: 'csv', Label: 'CSV (.csv)' },
|
|
700
|
+
];
|
|
701
|
+
}
|
|
702
|
+
if (dc === 'SlideDeckArtifactViewerPlugin' || tn.includes('presentation')) {
|
|
703
|
+
return [
|
|
704
|
+
{ Format: 'pptx', Label: 'Microsoft PowerPoint (.pptx)' },
|
|
705
|
+
{ Format: 'json', Label: 'SlideDeck JSON (.json)' },
|
|
706
|
+
];
|
|
707
|
+
}
|
|
708
|
+
if (tn === 'sql') {
|
|
709
|
+
return [{ Format: 'sql', Label: 'SQL Script (.sql)' }];
|
|
710
|
+
}
|
|
711
|
+
if (dc === 'JsonArtifactViewerPlugin' || dc === 'ComponentArtifactViewerPlugin' || tn.includes('json')) {
|
|
712
|
+
return [{ Format: 'json', Label: 'JSON (.json)' }];
|
|
713
|
+
}
|
|
714
|
+
return [{ Format: 'txt', Label: 'Plain Text (.txt)' }];
|
|
715
|
+
}
|
|
716
|
+
// ---------------------------------------------------------------------------
|
|
717
|
+
// Private helpers
|
|
718
|
+
// ---------------------------------------------------------------------------
|
|
719
|
+
async persistArtifactAndVersion(params) {
|
|
720
|
+
const { Provider: md, CurrentUser: user } = params;
|
|
721
|
+
if (params.CollectionID) {
|
|
722
|
+
await this.assertCanWriteCollection(params.CollectionID, user, md);
|
|
723
|
+
}
|
|
724
|
+
const artifact = await md.GetEntityObject('MJ: Artifacts', user);
|
|
725
|
+
artifact.Name = params.Title;
|
|
726
|
+
artifact.Description = params.Description;
|
|
727
|
+
artifact.TypeID = params.ArtifactType.ID;
|
|
728
|
+
artifact.EnvironmentID = params.EnvironmentID;
|
|
729
|
+
artifact.UserID = user.ID;
|
|
730
|
+
const artifactSaved = await artifact.Save();
|
|
731
|
+
if (!artifactSaved) {
|
|
732
|
+
throw new Error(artifact.LatestResult?.Message || 'Failed to save MJ: Artifacts record.');
|
|
733
|
+
}
|
|
734
|
+
const version = await md.GetEntityObject('MJ: Artifact Versions', user);
|
|
735
|
+
version.ArtifactID = artifact.ID;
|
|
736
|
+
version.VersionNumber = 1;
|
|
737
|
+
version.Name = params.Title;
|
|
738
|
+
version.Description = params.Description;
|
|
739
|
+
version.UserID = user.ID;
|
|
740
|
+
version.ContentMode = params.ContentMode;
|
|
741
|
+
version.Content = params.Content;
|
|
742
|
+
version.FileID = params.FileID;
|
|
743
|
+
version.MimeType = params.MimeType;
|
|
744
|
+
version.FileName = params.FileName;
|
|
745
|
+
version.ContentSizeBytes = params.ContentSizeBytes;
|
|
746
|
+
const initialConfig = BuildArtifactVersionConfigurationWithPreview(params.InitialConfigurationJson ?? null, params.Content, params.ArtifactType?.DriverClass ?? null, params.Title, {
|
|
747
|
+
ArtifactType: params.ArtifactType ?? null,
|
|
748
|
+
AllArtifactTypes: ArtifactMetadataEngine.Instance.ArtifactTypes ?? [],
|
|
749
|
+
});
|
|
750
|
+
if (initialConfig) {
|
|
751
|
+
version.Configuration = initialConfig;
|
|
752
|
+
}
|
|
753
|
+
const versionSaved = await version.Save();
|
|
754
|
+
if (!versionSaved) {
|
|
755
|
+
await artifact.Delete();
|
|
756
|
+
throw new Error(version.LatestResult?.Message || 'Failed to save MJ: Artifact Versions record.');
|
|
757
|
+
}
|
|
758
|
+
let collectionLink = null;
|
|
759
|
+
if (params.CollectionID) {
|
|
760
|
+
const link = await md.GetEntityObject('MJ: Collection Artifacts', user);
|
|
761
|
+
link.CollectionID = params.CollectionID;
|
|
762
|
+
link.ArtifactVersionID = version.ID;
|
|
763
|
+
const linkSaved = await link.Save();
|
|
764
|
+
if (!linkSaved) {
|
|
765
|
+
await version.Delete();
|
|
766
|
+
await artifact.Delete();
|
|
767
|
+
throw new Error(link.LatestResult?.Message || 'Failed to link artifact into the target Collection.');
|
|
768
|
+
}
|
|
769
|
+
collectionLink = link;
|
|
770
|
+
}
|
|
771
|
+
return {
|
|
772
|
+
Artifact: artifact,
|
|
773
|
+
Version: version,
|
|
774
|
+
ArtifactType: params.ArtifactType,
|
|
775
|
+
CollectionLink: collectionLink,
|
|
776
|
+
};
|
|
777
|
+
}
|
|
778
|
+
async assertCanWriteCollection(collectionId, user, provider) {
|
|
779
|
+
const collection = await provider.GetEntityObject('MJ: Collections', user);
|
|
780
|
+
const loaded = await collection.Load(collectionId);
|
|
781
|
+
if (!loaded) {
|
|
782
|
+
throw new Error('Target collection was not found.');
|
|
783
|
+
}
|
|
784
|
+
if (collection.OwnerID && !UUIDsEqual(collection.OwnerID, user.ID)) {
|
|
785
|
+
this.collectionPermissions.Provider = provider;
|
|
786
|
+
const perm = await this.collectionPermissions.CheckPermission(collectionId, user.ID, user);
|
|
787
|
+
if (!perm?.canEdit) {
|
|
788
|
+
throw new Error('You do not have Edit permission to add items to this collection.');
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
async convertBytesToNativeText(buffer, extension, title, types) {
|
|
793
|
+
const decoder = new TextDecoder('utf-8');
|
|
794
|
+
switch (extension) {
|
|
795
|
+
case 'docx': {
|
|
796
|
+
const mdContent = await this.docImportExport.ConvertDocxBytesToMarkdown(buffer);
|
|
797
|
+
const docType = this.FindStarterArtifactType('document', types);
|
|
798
|
+
if (!docType) {
|
|
799
|
+
throw new Error('Markdown Document artifact type is not available.');
|
|
800
|
+
}
|
|
801
|
+
return { Content: mdContent || `# ${title}\n`, ArtifactType: docType };
|
|
802
|
+
}
|
|
803
|
+
case 'md':
|
|
804
|
+
case 'markdown':
|
|
805
|
+
case 'txt': {
|
|
806
|
+
const text = await this.docImportExport.ImportMarkdown(decoder.decode(buffer));
|
|
807
|
+
const docType = this.FindStarterArtifactType('document', types) ??
|
|
808
|
+
types.find((t) => t.Name.toLowerCase().includes('text'));
|
|
809
|
+
if (!docType) {
|
|
810
|
+
throw new Error('Document artifact type is not available.');
|
|
811
|
+
}
|
|
812
|
+
return { Content: text, ArtifactType: docType };
|
|
813
|
+
}
|
|
814
|
+
case 'xlsx': {
|
|
815
|
+
const wb = SpreadsheetEngine.Instance.ImportFromXlsxBytes(buffer);
|
|
816
|
+
wb.Title = title;
|
|
817
|
+
const sheetType = this.FindStarterArtifactType('spreadsheet', types);
|
|
818
|
+
if (!sheetType) {
|
|
819
|
+
throw new Error('Spreadsheet artifact type is not available.');
|
|
820
|
+
}
|
|
821
|
+
return { Content: JSON.stringify(wb, null, 2), ArtifactType: sheetType };
|
|
822
|
+
}
|
|
823
|
+
case 'csv': {
|
|
824
|
+
const csvText = decoder.decode(buffer);
|
|
825
|
+
const wb = SpreadsheetEngine.Instance.ImportFromCsv(csvText, 'Sheet 1', title);
|
|
826
|
+
const sheetType = this.FindStarterArtifactType('spreadsheet', types);
|
|
827
|
+
if (!sheetType) {
|
|
828
|
+
throw new Error('Spreadsheet artifact type is not available.');
|
|
829
|
+
}
|
|
830
|
+
return { Content: JSON.stringify(wb, null, 2), ArtifactType: sheetType };
|
|
831
|
+
}
|
|
832
|
+
case 'sql': {
|
|
833
|
+
const sqlType = this.FindStarterArtifactType('query', types);
|
|
834
|
+
if (!sqlType) {
|
|
835
|
+
throw new Error('SQL artifact type is not available.');
|
|
836
|
+
}
|
|
837
|
+
return { Content: decoder.decode(buffer), ArtifactType: sqlType };
|
|
838
|
+
}
|
|
839
|
+
case 'json': {
|
|
840
|
+
const jsonType = types.find((t) => t.Name.toLowerCase() === 'json') ??
|
|
841
|
+
this.FindStarterArtifactType('document', types);
|
|
842
|
+
if (!jsonType) {
|
|
843
|
+
throw new Error('JSON artifact type is not available.');
|
|
844
|
+
}
|
|
845
|
+
return { Content: decoder.decode(buffer), ArtifactType: jsonType };
|
|
846
|
+
}
|
|
847
|
+
default:
|
|
848
|
+
throw new Error(`Unsupported conversion extension ".${extension}".`);
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
async serializeExportPayload(artifactName, content, configuration, format, user) {
|
|
852
|
+
const encoder = new TextEncoder();
|
|
853
|
+
switch (format) {
|
|
854
|
+
case 'docx': {
|
|
855
|
+
const bytes = await this.docImportExport.ConvertMarkdownToDocxBytes(content, artifactName);
|
|
856
|
+
return {
|
|
857
|
+
bytes,
|
|
858
|
+
mimeType: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
859
|
+
extension: 'docx',
|
|
860
|
+
};
|
|
861
|
+
}
|
|
862
|
+
case 'md':
|
|
863
|
+
return {
|
|
864
|
+
bytes: encoder.encode(content),
|
|
865
|
+
mimeType: 'text/markdown',
|
|
866
|
+
extension: 'md',
|
|
867
|
+
};
|
|
868
|
+
case 'xlsx': {
|
|
869
|
+
const wb = SpreadsheetEngine.Instance.ParseWorkbook(content, configuration);
|
|
870
|
+
const bytes = SpreadsheetEngine.Instance.ExportToXlsxBytes(wb);
|
|
871
|
+
return {
|
|
872
|
+
bytes,
|
|
873
|
+
mimeType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
874
|
+
extension: 'xlsx',
|
|
875
|
+
};
|
|
876
|
+
}
|
|
877
|
+
case 'csv': {
|
|
878
|
+
const wb = SpreadsheetEngine.Instance.ParseWorkbook(content, configuration);
|
|
879
|
+
const csvText = SpreadsheetEngine.Instance.ExportToCsv(wb);
|
|
880
|
+
return {
|
|
881
|
+
bytes: encoder.encode(csvText),
|
|
882
|
+
mimeType: 'text/csv',
|
|
883
|
+
extension: 'csv',
|
|
884
|
+
};
|
|
885
|
+
}
|
|
886
|
+
case 'pptx': {
|
|
887
|
+
const deck = SlideDeckEngine.Instance.ParseDeckSpec(content, artifactName);
|
|
888
|
+
const pkg = this.slideExport.ExportToPptxPackage(deck, new Map(), {
|
|
889
|
+
ID: user.ID,
|
|
890
|
+
Name: user.Name,
|
|
891
|
+
});
|
|
892
|
+
return {
|
|
893
|
+
bytes: pkg.Bytes,
|
|
894
|
+
mimeType: 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
|
895
|
+
extension: 'pptx',
|
|
896
|
+
};
|
|
897
|
+
}
|
|
898
|
+
case 'json':
|
|
899
|
+
return {
|
|
900
|
+
bytes: encoder.encode(content),
|
|
901
|
+
mimeType: 'application/json',
|
|
902
|
+
extension: 'json',
|
|
903
|
+
};
|
|
904
|
+
case 'sql':
|
|
905
|
+
return {
|
|
906
|
+
bytes: encoder.encode(content),
|
|
907
|
+
mimeType: 'application/sql',
|
|
908
|
+
extension: 'sql',
|
|
909
|
+
};
|
|
910
|
+
case 'original':
|
|
911
|
+
case 'txt':
|
|
912
|
+
return {
|
|
913
|
+
bytes: encoder.encode(content),
|
|
914
|
+
mimeType: 'text/plain',
|
|
915
|
+
extension: 'txt',
|
|
916
|
+
};
|
|
917
|
+
default: {
|
|
918
|
+
const exhaustiveCheck = format;
|
|
919
|
+
return exhaustiveCheck;
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
async downloadFileVersionBytes(options) {
|
|
924
|
+
if (options.DownloadFileBytesOverride) {
|
|
925
|
+
return options.DownloadFileBytesOverride({
|
|
926
|
+
ArtifactVersionID: options.ArtifactVersionID,
|
|
927
|
+
FileID: options.VersionFileID,
|
|
928
|
+
});
|
|
929
|
+
}
|
|
930
|
+
let downloadUrl = null;
|
|
931
|
+
if (options.ArtifactVersionID && this.artifactFileService) {
|
|
932
|
+
try {
|
|
933
|
+
downloadUrl = await this.artifactFileService.GetDownloadUrl(options.ArtifactVersionID);
|
|
934
|
+
}
|
|
935
|
+
catch {
|
|
936
|
+
downloadUrl = null;
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
if (!downloadUrl && options.VersionFileID) {
|
|
940
|
+
const store = this.blobStoreOverride ?? new GraphQLAttachmentBlobStore();
|
|
941
|
+
downloadUrl = await store.GetDownloadUrl(options.VersionFileID, options.CurrentUser, options.Provider);
|
|
942
|
+
}
|
|
943
|
+
if (!downloadUrl) {
|
|
944
|
+
throw new Error('Could not obtain a pre-authenticated download URL for this file artifact.');
|
|
945
|
+
}
|
|
946
|
+
const response = await fetch(downloadUrl);
|
|
947
|
+
if (!response.ok) {
|
|
948
|
+
throw new Error(`Failed to download file artifact bytes (${response.status} ${response.statusText}).`);
|
|
949
|
+
}
|
|
950
|
+
return new Uint8Array(await response.arrayBuffer());
|
|
951
|
+
}
|
|
952
|
+
createGraphQLFileStorageClient(provider) {
|
|
953
|
+
const targetProvider = (provider ?? Metadata.Provider ?? GraphQLDataProvider.Instance);
|
|
954
|
+
return new GraphQLFileStorageClient(targetProvider);
|
|
955
|
+
}
|
|
956
|
+
async remoteObjectExists(storageClient, accountId, cleanPrefix, fileName, objectPath) {
|
|
957
|
+
const lowerFileName = fileName.toLowerCase();
|
|
958
|
+
const lowerObjectPath = objectPath.toLowerCase();
|
|
959
|
+
if (typeof storageClient.ListObjects === 'function') {
|
|
960
|
+
const folderPrefix = cleanPrefix ? `${cleanPrefix}/` : '';
|
|
961
|
+
const listing = await storageClient.ListObjects(accountId, folderPrefix, '/');
|
|
962
|
+
const objects = listing.objects ?? [];
|
|
963
|
+
const foundInFolder = objects.some((obj) => !obj.isDirectory &&
|
|
964
|
+
(obj.name.toLowerCase() === lowerFileName || obj.fullPath.toLowerCase() === lowerObjectPath));
|
|
965
|
+
if (foundInFolder) {
|
|
966
|
+
return true;
|
|
967
|
+
}
|
|
968
|
+
// If the folder listing was truncated at provider page boundaries (>= 100 items),
|
|
969
|
+
// consult SearchFiles as well so case-insensitive collisions beyond page 1 are caught.
|
|
970
|
+
if (objects.length >= 100 && typeof storageClient.SearchFiles === 'function') {
|
|
971
|
+
const searchResponse = await storageClient.SearchFiles([accountId], fileName, {
|
|
972
|
+
maxResultsPerAccount: 100,
|
|
973
|
+
});
|
|
974
|
+
for (const accountResult of searchResponse?.accountResults ?? []) {
|
|
975
|
+
if (accountResult.success === false) {
|
|
976
|
+
throw new Error(accountResult.errorMessage || 'Failed to verify existing files in remote storage.');
|
|
977
|
+
}
|
|
978
|
+
for (const hit of accountResult.results ?? []) {
|
|
979
|
+
const hitName = (hit.name ?? '').toLowerCase();
|
|
980
|
+
const hitPath = (hit.path ?? '').replace(/^\/+/, '').toLowerCase();
|
|
981
|
+
if (hitName === lowerFileName && (!cleanPrefix || hitPath === lowerObjectPath || hitPath === lowerFileName)) {
|
|
982
|
+
return true;
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
return false;
|
|
988
|
+
}
|
|
989
|
+
if (typeof storageClient.ObjectExists === 'function') {
|
|
990
|
+
return storageClient.ObjectExists(accountId, objectPath);
|
|
991
|
+
}
|
|
992
|
+
return false;
|
|
993
|
+
}
|
|
994
|
+
extensionFromMime(mimeType) {
|
|
995
|
+
const lower = (mimeType ?? '').trim().toLowerCase();
|
|
996
|
+
if (lower === 'application/pdf')
|
|
997
|
+
return 'pdf';
|
|
998
|
+
if (lower === 'application/vnd.openxmlformats-officedocument.wordprocessingml.document')
|
|
999
|
+
return 'docx';
|
|
1000
|
+
if (lower === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
|
|
1001
|
+
return 'xlsx';
|
|
1002
|
+
if (lower === 'application/vnd.openxmlformats-officedocument.presentationml.presentation')
|
|
1003
|
+
return 'pptx';
|
|
1004
|
+
if (lower === 'image/png')
|
|
1005
|
+
return 'png';
|
|
1006
|
+
if (lower === 'image/jpeg')
|
|
1007
|
+
return 'jpg';
|
|
1008
|
+
if (lower === 'image/gif')
|
|
1009
|
+
return 'gif';
|
|
1010
|
+
if (lower === 'image/webp')
|
|
1011
|
+
return 'webp';
|
|
1012
|
+
if (lower === 'image/svg+xml')
|
|
1013
|
+
return 'svg';
|
|
1014
|
+
if (lower === 'video/mp4')
|
|
1015
|
+
return 'mp4';
|
|
1016
|
+
if (lower === 'audio/mpeg')
|
|
1017
|
+
return 'mp3';
|
|
1018
|
+
if (lower === 'text/csv')
|
|
1019
|
+
return 'csv';
|
|
1020
|
+
if (lower === 'text/markdown')
|
|
1021
|
+
return 'md';
|
|
1022
|
+
if (lower === 'application/json')
|
|
1023
|
+
return 'json';
|
|
1024
|
+
if (lower === 'application/sql')
|
|
1025
|
+
return 'sql';
|
|
1026
|
+
if (lower === 'text/plain')
|
|
1027
|
+
return 'txt';
|
|
1028
|
+
return '';
|
|
1029
|
+
}
|
|
1030
|
+
resolveBinaryArtifactType(mimeType, extension, types) {
|
|
1031
|
+
const fromEngine = ArtifactMetadataEngine.Instance.GetArtifactTypeByMimeType(mimeType, extension);
|
|
1032
|
+
if (fromEngine) {
|
|
1033
|
+
return fromEngine;
|
|
1034
|
+
}
|
|
1035
|
+
const lowerMime = mimeType.toLowerCase();
|
|
1036
|
+
return (types.find((t) => t.ContentType?.toLowerCase() === lowerMime) ??
|
|
1037
|
+
types.find((t) => {
|
|
1038
|
+
const ct = t.ContentType?.toLowerCase() ?? '';
|
|
1039
|
+
return ct.endsWith('/*') && lowerMime.startsWith(ct.slice(0, -1));
|
|
1040
|
+
}) ??
|
|
1041
|
+
types.find((t) => t.Name.toLowerCase().includes('binary') || t.ContentType === 'application/octet-stream') ??
|
|
1042
|
+
types[0]);
|
|
1043
|
+
}
|
|
1044
|
+
defaultTitleForStarter(kind) {
|
|
1045
|
+
switch (kind) {
|
|
1046
|
+
case 'document':
|
|
1047
|
+
return 'Untitled Document';
|
|
1048
|
+
case 'spreadsheet':
|
|
1049
|
+
return 'Untitled Spreadsheet';
|
|
1050
|
+
case 'presentation':
|
|
1051
|
+
return 'Untitled Presentation';
|
|
1052
|
+
case 'query':
|
|
1053
|
+
return 'Untitled Data Query';
|
|
1054
|
+
default: {
|
|
1055
|
+
const exhaustiveCheck = kind;
|
|
1056
|
+
return exhaustiveCheck;
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
extractExtension(fileName) {
|
|
1061
|
+
const dot = fileName.lastIndexOf('.');
|
|
1062
|
+
return dot >= 0 ? fileName.slice(dot + 1).trim().toLowerCase() : '';
|
|
1063
|
+
}
|
|
1064
|
+
stripExtension(fileName) {
|
|
1065
|
+
const dot = fileName.lastIndexOf('.');
|
|
1066
|
+
return (dot > 0 ? fileName.slice(0, dot) : fileName).trim();
|
|
1067
|
+
}
|
|
1068
|
+
sanitizeFileName(name) {
|
|
1069
|
+
return (name
|
|
1070
|
+
.replace(/[/\\?%*:|"<>]+/g, '-')
|
|
1071
|
+
.replace(/\s+/g, ' ')
|
|
1072
|
+
.trim() || 'Artifact');
|
|
1073
|
+
}
|
|
1074
|
+
inferMimeFromExtension(ext) {
|
|
1075
|
+
switch (ext) {
|
|
1076
|
+
case 'pdf':
|
|
1077
|
+
return 'application/pdf';
|
|
1078
|
+
case 'docx':
|
|
1079
|
+
return 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
|
|
1080
|
+
case 'xlsx':
|
|
1081
|
+
return 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
|
|
1082
|
+
case 'pptx':
|
|
1083
|
+
return 'application/vnd.openxmlformats-officedocument.presentationml.presentation';
|
|
1084
|
+
case 'png':
|
|
1085
|
+
return 'image/png';
|
|
1086
|
+
case 'jpg':
|
|
1087
|
+
case 'jpeg':
|
|
1088
|
+
return 'image/jpeg';
|
|
1089
|
+
case 'gif':
|
|
1090
|
+
return 'image/gif';
|
|
1091
|
+
case 'webp':
|
|
1092
|
+
return 'image/webp';
|
|
1093
|
+
case 'svg':
|
|
1094
|
+
return 'image/svg+xml';
|
|
1095
|
+
case 'mp4':
|
|
1096
|
+
return 'video/mp4';
|
|
1097
|
+
case 'mp3':
|
|
1098
|
+
return 'audio/mpeg';
|
|
1099
|
+
case 'csv':
|
|
1100
|
+
return 'text/csv';
|
|
1101
|
+
case 'md':
|
|
1102
|
+
case 'markdown':
|
|
1103
|
+
return 'text/markdown';
|
|
1104
|
+
case 'json':
|
|
1105
|
+
return 'application/json';
|
|
1106
|
+
case 'sql':
|
|
1107
|
+
return 'application/sql';
|
|
1108
|
+
case 'txt':
|
|
1109
|
+
return 'text/plain';
|
|
1110
|
+
default:
|
|
1111
|
+
return 'application/octet-stream';
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
arrayBufferToBase64(buffer) {
|
|
1115
|
+
const bytes = new Uint8Array(buffer);
|
|
1116
|
+
const chunkSize = 0x8000;
|
|
1117
|
+
const chunks = [];
|
|
1118
|
+
for (let i = 0; i < bytes.length; i += chunkSize) {
|
|
1119
|
+
const slice = bytes.subarray(i, i + chunkSize);
|
|
1120
|
+
chunks.push(String.fromCharCode(...slice));
|
|
1121
|
+
}
|
|
1122
|
+
return btoa(chunks.join(''));
|
|
1123
|
+
}
|
|
1124
|
+
async loadArtifactVersionsDesc(artifactId, user, provider) {
|
|
1125
|
+
const rv = RunView.FromMetadataProvider(provider);
|
|
1126
|
+
const res = await rv.RunView({
|
|
1127
|
+
EntityName: 'MJ: Artifact Versions',
|
|
1128
|
+
ExtraFilter: `ArtifactID='${EscapeSQLString(artifactId)}'`,
|
|
1129
|
+
OrderBy: 'VersionNumber DESC',
|
|
1130
|
+
ResultType: 'entity_object',
|
|
1131
|
+
}, user);
|
|
1132
|
+
return res.Success && res.Results ? res.Results : [];
|
|
1133
|
+
}
|
|
1134
|
+
splitObjectPath(objectPath) {
|
|
1135
|
+
const normalized = objectPath.replace(/^\/+/, '');
|
|
1136
|
+
const slash = normalized.lastIndexOf('/');
|
|
1137
|
+
if (slash < 0) {
|
|
1138
|
+
return { prefix: '', fileName: normalized };
|
|
1139
|
+
}
|
|
1140
|
+
return {
|
|
1141
|
+
prefix: normalized.slice(0, slash),
|
|
1142
|
+
fileName: normalized.slice(slash + 1),
|
|
1143
|
+
};
|
|
1144
|
+
}
|
|
1145
|
+
inferExportFormat(fileName, contentMode, content) {
|
|
1146
|
+
const ext = this.extractExtension(fileName);
|
|
1147
|
+
if (ext === 'docx' || ext === 'md' || ext === 'xlsx' || ext === 'csv' || ext === 'pptx' || ext === 'json' || ext === 'sql' || ext === 'txt') {
|
|
1148
|
+
return ext;
|
|
1149
|
+
}
|
|
1150
|
+
if (contentMode === 'File') {
|
|
1151
|
+
return 'original';
|
|
1152
|
+
}
|
|
1153
|
+
const trimmed = (content ?? '').trim();
|
|
1154
|
+
if (trimmed.startsWith('{') && trimmed.includes('"sheets"')) {
|
|
1155
|
+
return 'xlsx';
|
|
1156
|
+
}
|
|
1157
|
+
if (trimmed.startsWith('{') && trimmed.includes('"slides"')) {
|
|
1158
|
+
return 'pptx';
|
|
1159
|
+
}
|
|
1160
|
+
return 'md';
|
|
1161
|
+
}
|
|
1162
|
+
async findRemoteObjectMetadata(storageClient, accountId, objectPath, options) {
|
|
1163
|
+
if (typeof storageClient.ListObjects !== 'function') {
|
|
1164
|
+
return null;
|
|
1165
|
+
}
|
|
1166
|
+
const normalizedPath = objectPath.replace(/^\/+/, '');
|
|
1167
|
+
const { prefix, fileName } = this.splitObjectPath(normalizedPath);
|
|
1168
|
+
const folderPrefix = prefix ? `${prefix}/` : '';
|
|
1169
|
+
const prefixesToProbe = normalizedPath && normalizedPath !== folderPrefix
|
|
1170
|
+
? [normalizedPath, folderPrefix]
|
|
1171
|
+
: [folderPrefix];
|
|
1172
|
+
let lastError = null;
|
|
1173
|
+
let succeededOnce = false;
|
|
1174
|
+
for (const probePrefix of prefixesToProbe) {
|
|
1175
|
+
try {
|
|
1176
|
+
const listing = await storageClient.ListObjects(accountId, probePrefix, '/');
|
|
1177
|
+
succeededOnce = true;
|
|
1178
|
+
const match = (listing.objects ?? []).find((obj) => !obj.isDirectory &&
|
|
1179
|
+
(obj.fullPath.replace(/^\/+/, '').toLowerCase() === normalizedPath.toLowerCase() ||
|
|
1180
|
+
obj.name.toLowerCase() === fileName.toLowerCase()));
|
|
1181
|
+
if (match) {
|
|
1182
|
+
return {
|
|
1183
|
+
ETag: match.etag || undefined,
|
|
1184
|
+
LastModified: match.lastModified instanceof Date
|
|
1185
|
+
? match.lastModified.toISOString()
|
|
1186
|
+
: typeof match.lastModified === 'string'
|
|
1187
|
+
? match.lastModified
|
|
1188
|
+
: undefined,
|
|
1189
|
+
};
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
catch (err) {
|
|
1193
|
+
lastError = err instanceof Error ? err : new Error(String(err));
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
if (!succeededOnce && lastError && options?.throwOnError) {
|
|
1197
|
+
throw lastError;
|
|
1198
|
+
}
|
|
1199
|
+
return null;
|
|
1200
|
+
}
|
|
1201
|
+
async recordConnectedDriveAuditLog(params) {
|
|
1202
|
+
try {
|
|
1203
|
+
const rv = RunView.FromMetadataProvider(params.Provider);
|
|
1204
|
+
const typeRes = await rv.RunView({
|
|
1205
|
+
EntityName: 'MJ: Audit Log Types',
|
|
1206
|
+
ExtraFilter: `Name='Artifact Connected Drive Sync'`,
|
|
1207
|
+
MaxRows: 1,
|
|
1208
|
+
ResultType: 'entity_object',
|
|
1209
|
+
}, params.CurrentUser);
|
|
1210
|
+
const auditTypeId = typeRes.Success ? typeRes.Results?.[0]?.ID : undefined;
|
|
1211
|
+
if (!auditTypeId) {
|
|
1212
|
+
return;
|
|
1213
|
+
}
|
|
1214
|
+
const log = await params.Provider.GetEntityObject('MJ: Audit Logs', params.CurrentUser);
|
|
1215
|
+
log.AuditLogTypeID = auditTypeId;
|
|
1216
|
+
log.UserID = params.CurrentUser.ID;
|
|
1217
|
+
log.Status = 'Success';
|
|
1218
|
+
log.Description = `${params.Direction === 'push' ? 'Pushed' : 'Pulled'} artifact version v${params.VersionNumber} (${params.ObjectPath})`;
|
|
1219
|
+
log.Details = JSON.stringify({
|
|
1220
|
+
Direction: params.Direction,
|
|
1221
|
+
ArtifactID: params.ArtifactID,
|
|
1222
|
+
VersionID: params.VersionID,
|
|
1223
|
+
VersionNumber: params.VersionNumber,
|
|
1224
|
+
ObjectPath: params.ObjectPath,
|
|
1225
|
+
ETag: params.ETag ?? null,
|
|
1226
|
+
Timestamp: new Date().toISOString(),
|
|
1227
|
+
});
|
|
1228
|
+
log.RecordID = params.ArtifactID;
|
|
1229
|
+
await log.Save();
|
|
1230
|
+
}
|
|
1231
|
+
catch {
|
|
1232
|
+
// Best-effort client audit trail; never fails sync if client lacks audit table write rights.
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
static ɵfac = function LibraryCreationService_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || LibraryCreationService)(); };
|
|
1236
|
+
static ɵprov = /*@__PURE__*/ i0.ɵɵdefineInjectable({ token: LibraryCreationService, factory: LibraryCreationService.ɵfac, providedIn: 'root' });
|
|
1237
|
+
}
|
|
1238
|
+
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(LibraryCreationService, [{
|
|
1239
|
+
type: Injectable,
|
|
1240
|
+
args: [{
|
|
1241
|
+
providedIn: 'root',
|
|
1242
|
+
}]
|
|
1243
|
+
}], null, null); })();
|
|
1244
|
+
//# sourceMappingURL=library-creation.service.js.map
|