@antcde/connect-ts 0.4.32 → 0.4.33-rc.10
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 +5 -26
- package/build/AntConnect.d.ts +4 -0
- package/build/AntConnect.d.ts.map +1 -1
- package/build/AntConnect.js +4 -0
- package/build/comms/client.d.ts +3 -0
- package/build/comms/client.d.ts.map +1 -1
- package/build/comms/client.js +10 -7
- package/build/comms/dmsUpload.d.ts +19 -0
- package/build/comms/dmsUpload.d.ts.map +1 -0
- package/build/comms/dmsUpload.js +140 -0
- package/build/comms/dmsUpload.types.d.ts +46 -0
- package/build/comms/dmsUpload.types.d.ts.map +1 -0
- package/build/comms/dmsUpload.types.js +7 -0
- package/build/comms/dmsUploadClient.d.ts +13 -0
- package/build/comms/dmsUploadClient.d.ts.map +1 -0
- package/build/comms/dmsUploadClient.js +54 -0
- package/build/comms/dmsUploadErrors.d.ts +5 -0
- package/build/comms/dmsUploadErrors.d.ts.map +1 -0
- package/build/comms/dmsUploadErrors.js +27 -0
- package/build/comms/dmsUploadHost.d.ts +8 -0
- package/build/comms/dmsUploadHost.d.ts.map +1 -0
- package/build/comms/dmsUploadHost.js +43 -0
- package/build/comms/dmsUploadPut.d.ts +15 -0
- package/build/comms/dmsUploadPut.d.ts.map +1 -0
- package/build/comms/dmsUploadPut.js +29 -0
- package/build/comms/host.d.ts.map +1 -1
- package/build/comms/host.js +2 -0
- package/build/comms/hostAPI.d.ts +7 -0
- package/build/comms/hostAPI.d.ts.map +1 -1
- package/build/comms/hostAPI.js +4 -0
- package/build/comms/models.d.ts +3 -0
- package/build/comms/models.d.ts.map +1 -1
- package/build/comms/signalTypes.d.ts +12 -0
- package/build/comms/signalTypes.d.ts.map +1 -1
- package/build/index.d.ts +11 -2
- package/build/index.d.ts.map +1 -1
- package/build/index.js +3 -0
- package/build/service-types-app.d.ts +1 -1
- package/build/service-types-app.d.ts.map +1 -1
- package/build/service-types.d.ts +3 -2
- package/build/service-types.d.ts.map +1 -1
- package/build/services/AppService/factory/media.d.ts +5 -2
- package/build/services/AppService/factory/media.d.ts.map +1 -1
- package/build/services/AppService/factory/media.js +7 -2
- package/build/services/AppService/factory/publishers.d.ts +14 -0
- package/build/services/AppService/factory/publishers.d.ts.map +1 -0
- package/build/services/AppService/factory/publishers.js +15 -0
- package/build/services/AppService/factory/resourceAccess.d.ts +1 -1
- package/build/services/AppService/factory/resourceAccess.d.ts.map +1 -1
- package/build/services/AppService/factory/resourceAccess.js +7 -6
- package/build/services/AppService/factory/resourceAssignments.d.ts +0 -30
- package/build/services/AppService/factory/resourceAssignments.d.ts.map +1 -1
- package/build/services/AppService/factory/resourceAssignments.js +0 -2
- package/build/services/AppService/factory/resourceProjectActivations.d.ts +16 -0
- package/build/services/AppService/factory/resourceProjectActivations.d.ts.map +1 -0
- package/build/services/AppService/factory/resourceProjectActivations.js +23 -0
- package/build/services/AppService/factory/resources.d.ts +15 -6
- package/build/services/AppService/factory/resources.d.ts.map +1 -1
- package/build/services/AppService/factory/resources.js +3 -0
- package/build/services/AppService/factory/versions.d.ts +17 -0
- package/build/services/AppService/factory/versions.d.ts.map +1 -0
- package/build/services/AppService/factory/versions.js +12 -0
- package/build/services/AppService/index.d.ts +4 -8
- package/build/services/AppService/index.d.ts.map +1 -1
- package/build/services/AppService/index.js +4 -6
- package/build/services/AppService/types/accessRequests.d.ts +1 -4
- package/build/services/AppService/types/accessRequests.d.ts.map +1 -1
- package/build/services/AppService/types/app.d.ts +2 -7
- package/build/services/AppService/types/app.d.ts.map +1 -1
- package/build/services/AppService/types/appList.d.ts +3 -2
- package/build/services/AppService/types/appList.d.ts.map +1 -1
- package/build/services/AppService/types/appMedia.d.ts +24 -13
- package/build/services/AppService/types/appMedia.d.ts.map +1 -1
- package/build/services/AppService/types/publishers.d.ts +43 -0
- package/build/services/AppService/types/publishers.d.ts.map +1 -0
- package/build/services/AppService/types/resourceEntitlements.d.ts +8 -11
- package/build/services/AppService/types/resourceEntitlements.d.ts.map +1 -1
- package/build/services/AppService/types/resourceProjectActivations.d.ts +67 -0
- package/build/services/AppService/types/resourceProjectActivations.d.ts.map +1 -0
- package/build/services/AppService/types/resourceProjectActivations.js +3 -0
- package/build/services/AppService/types/resourceReleases.d.ts +29 -0
- package/build/services/AppService/types/resourceReleases.d.ts.map +1 -1
- package/build/services/AppService/types/resourceRequests.d.ts +2 -2
- package/build/services/AppService/types/sellableResources.d.ts +9 -27
- package/build/services/AppService/types/sellableResources.d.ts.map +1 -1
- package/build/services/AppService/types.d.ts +2 -0
- package/build/services/AppService/types.d.ts.map +1 -1
- package/build/services/AppService/types.js +2 -0
- package/build/services/ColumnService.d.ts +2 -0
- package/build/services/ColumnService.d.ts.map +1 -1
- package/build/services/FeatureService.d.ts +7 -0
- package/build/services/FeatureService.d.ts.map +1 -0
- package/build/services/FeatureService.js +5 -0
- package/build/services/LicenseService.d.ts +4 -0
- package/build/services/LicenseService.d.ts.map +1 -1
- package/build/services/ProjectService.d.ts +33 -9
- package/build/services/ProjectService.d.ts.map +1 -1
- package/build/services/PropagationService.js +1 -1
- package/build/services/RBAC/RoleService.d.ts +0 -1
- package/build/services/RBAC/RoleService.d.ts.map +1 -1
- package/build/services/RBAC/RoleService.js +0 -1
- package/build/services/ResourceTypeService.d.ts +3 -1
- package/build/services/ResourceTypeService.d.ts.map +1 -1
- package/build/services/SbsService.d.ts +2 -1
- package/build/services/SbsService.d.ts.map +1 -1
- package/build/services/TableService.types.d.ts +6 -0
- package/build/services/TableService.types.d.ts.map +1 -1
- package/build/services/TaskQuery.types.d.ts +32 -0
- package/build/services/TaskQuery.types.d.ts.map +1 -0
- package/build/services/TaskQuery.types.js +1 -0
- package/build/services/TaskService.d.ts +5 -0
- package/build/services/TaskService.d.ts.map +1 -1
- package/build/services/TaskService.js +1 -0
- package/build/services/TaskService.types.d.ts +6 -3
- package/build/services/TaskService.types.d.ts.map +1 -1
- package/build/services/TaskTemplate.types.d.ts +1 -1
- package/build/services/TaskTemplate.types.d.ts.map +1 -1
- package/build/services/UsageService.d.ts +94 -0
- package/build/services/UsageService.d.ts.map +1 -0
- package/build/services/UsageService.js +12 -0
- package/build/services/Webhook/EventService.d.ts +2 -0
- package/build/services/Webhook/EventService.d.ts.map +1 -1
- package/build/services/Webhook/TriggerCaller.types.d.ts +18 -0
- package/build/services/Webhook/TriggerCaller.types.d.ts.map +1 -0
- package/build/services/Webhook/TriggerCaller.types.js +1 -0
- package/build/services/Webhook/TriggerDispatchUrl.d.ts +9 -0
- package/build/services/Webhook/TriggerDispatchUrl.d.ts.map +1 -0
- package/build/services/Webhook/TriggerDispatchUrl.js +27 -0
- package/build/services/Webhook/TriggerFailedRuns.types.d.ts +3 -27
- package/build/services/Webhook/TriggerFailedRuns.types.d.ts.map +1 -1
- package/build/services/Webhook/TriggerHistoryService.d.ts +9 -1
- package/build/services/Webhook/TriggerHistoryService.d.ts.map +1 -1
- package/build/services/Webhook/TriggerHistoryService.js +1 -0
- package/build/services/Webhook/TriggerOwner.d.ts +5 -0
- package/build/services/Webhook/TriggerOwner.d.ts.map +1 -0
- package/build/services/Webhook/TriggerOwner.js +6 -0
- package/build/services/Webhook/TriggerRefresh.types.d.ts +15 -0
- package/build/services/Webhook/TriggerRefresh.types.d.ts.map +1 -0
- package/build/services/Webhook/TriggerRefresh.types.js +1 -0
- package/build/services/Webhook/TriggerRequest.types.d.ts +5 -24
- package/build/services/Webhook/TriggerRequest.types.d.ts.map +1 -1
- package/build/services/Webhook/TriggerSearch.types.d.ts +4 -7
- package/build/services/Webhook/TriggerSearch.types.d.ts.map +1 -1
- package/build/services/Webhook/TriggerService.d.ts +35 -54
- package/build/services/Webhook/TriggerService.d.ts.map +1 -1
- package/build/services/Webhook/TriggerService.js +3 -0
- package/build/services/Webhook/TriggerStats.types.d.ts +46 -0
- package/build/services/Webhook/TriggerStats.types.d.ts.map +1 -0
- package/build/services/Webhook/TriggerStats.types.js +1 -0
- package/build/services/Webhook/TriggerVersion.types.d.ts +9 -0
- package/build/services/Webhook/TriggerVersion.types.d.ts.map +1 -1
- package/package.json +1 -1
- package/build/services/Webhook/TriggerChaining.d.ts +0 -45
- package/build/services/Webhook/TriggerChaining.d.ts.map +0 -1
- /package/build/services/{Webhook/TriggerChaining.js → AppService/types/publishers.js} +0 -0
package/README.md
CHANGED
|
@@ -780,7 +780,7 @@ signal.with('cat').receive((cause) => {
|
|
|
780
780
|
|
|
781
781
|
### Recipe 2: Over Socket (Echo-backed) — backend broadcasts to all clients
|
|
782
782
|
|
|
783
|
-
|
|
783
|
+
Only types a backend module broadcasts arrive over the socket. For example, DHME's `DhmeResourceChanged` announces `production-location` and similar types on `App.License.{id}.Resources`. The backend has **no generic event** that broadcasts an app-defined type such as `cat`, so for those use Recipe 1 (local) or a topic. The examples below use `cat` only as a placeholder type name.
|
|
784
784
|
|
|
785
785
|
#### Receive (project-scoped)
|
|
786
786
|
|
|
@@ -807,35 +807,14 @@ watch(context, ({ project }, _, onCleanup) => {
|
|
|
807
807
|
4. Echo adapter receives it → sends signal back to the iframe client
|
|
808
808
|
5. `cause.meta.source` is `'timeseries'`
|
|
809
809
|
|
|
810
|
-
#### Backend
|
|
810
|
+
#### Backend side
|
|
811
811
|
|
|
812
|
-
|
|
813
|
-
// Project-scoped — broadcasts on App.Project.{id}.Resources
|
|
814
|
-
broadcast(ResourceChanged::forProject(
|
|
815
|
-
projectId: $projectId,
|
|
816
|
-
resource: 'cat',
|
|
817
|
-
id: $catId,
|
|
818
|
-
action: 'updated',
|
|
819
|
-
data: ['sound' => 'purrr'],
|
|
820
|
-
))->toOthers();
|
|
821
|
-
|
|
822
|
-
// License-scoped — broadcasts on App.License.{id}.Resources
|
|
823
|
-
broadcast(ResourceChanged::forLicense(
|
|
824
|
-
licenseId: $licenseId,
|
|
825
|
-
resource: 'cat',
|
|
826
|
-
id: $catId,
|
|
827
|
-
action: 'created',
|
|
828
|
-
data: ['sound' => 'meow'],
|
|
829
|
-
))->toOthers();
|
|
830
|
-
|
|
831
|
-
// broadcastAs() returns "resource.cat.updated" / "resource.cat.created"
|
|
832
|
-
// broadcastWith() returns { resource, id, action, data }
|
|
833
|
-
```
|
|
812
|
+
A backend module broadcasts an event on `App.{Project|License}.{id}.Resources` with `broadcastAs()` returning `resource.<type>.<action>` and a payload carrying the `id` and `action` (see `app/Modules/DHME/Realtime/DhmeResourceChanged.php` in ant-core). There is no shared event class for this, so adding a new broadcast type is a backend change.
|
|
834
813
|
|
|
835
814
|
### Summary
|
|
836
815
|
|
|
837
816
|
| Method | Distribution | Backend needed? | Use case |
|
|
838
817
|
|--------|-------------|----------------|----------|
|
|
839
818
|
| `signal.send()` + `signal.receive()` | Local (all split-screen apps) | No | App-to-app communication |
|
|
840
|
-
| `signal.with('cat').receive()` | Echo-backed | Yes — backend
|
|
841
|
-
| `signal.with('cat', ..., ['project']).receive()` | Echo-backed (project-scoped) | Yes | Backend-driven real-time updates |
|
|
819
|
+
| `signal.with('cat').receive()` | Echo-backed | Yes — a backend module must broadcast this type | Backend-driven (default scope) |
|
|
820
|
+
| `signal.with('cat', ..., ['project']).receive()` | Echo-backed (project-scoped) | Yes — a backend module must broadcast this type | Backend-driven real-time updates |
|
package/build/AntConnect.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import type ClientService from './services/ClientService';
|
|
|
5
5
|
import type ColumnService from './services/ColumnService';
|
|
6
6
|
import type DmsService from './services/DmsService';
|
|
7
7
|
import type DownloadService from './services/DownloadService';
|
|
8
|
+
import type { FeatureService } from './services/FeatureService';
|
|
8
9
|
import type { LabelService } from './services/LabelService';
|
|
9
10
|
import type LaravelQueueService from './services/LaravelQueueService';
|
|
10
11
|
import type LicenseService from './services/LicenseService';
|
|
@@ -31,6 +32,7 @@ import type { TaskQueryService } from './services/TaskQueryService';
|
|
|
31
32
|
import type TaskService from './services/TaskService';
|
|
32
33
|
import type { TaskTemplateService } from './services/TaskTemplateService';
|
|
33
34
|
import type { TokenService } from './services/TokenService';
|
|
35
|
+
import type { UsageService } from './services/UsageService';
|
|
34
36
|
import type UserService from './services/UserService';
|
|
35
37
|
import type { ConfigService } from './services/Webhook/ConfigService';
|
|
36
38
|
import type { EventService } from './services/Webhook/EventService';
|
|
@@ -86,6 +88,8 @@ export interface AntConnect {
|
|
|
86
88
|
readonly propagations: PropagationService;
|
|
87
89
|
readonly resourceTypes: ResourceTypeService;
|
|
88
90
|
readonly releases: ReleaseService;
|
|
91
|
+
readonly features: FeatureService;
|
|
92
|
+
readonly usage: UsageService;
|
|
89
93
|
}
|
|
90
94
|
export declare function newAntConnect(httpClient: AntHttpClient): AntConnect;
|
|
91
95
|
export declare function newCommunityAntConnect(httpClient: AntHttpClient): PartialAntConnect;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AntConnect.d.ts","sourceRoot":"","sources":["../src/AntConnect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AACpD,OAAO,KAAK,SAAS,MAAM,sBAAsB,CAAA;AACjD,OAAO,KAAK,UAAU,MAAM,uBAAuB,CAAA;AACnD,OAAO,KAAK,aAAa,MAAM,0BAA0B,CAAA;AACzD,OAAO,KAAK,aAAa,MAAM,0BAA0B,CAAA;AACzD,OAAO,KAAK,UAAU,MAAM,uBAAuB,CAAA;AACnD,OAAO,KAAK,eAAe,MAAM,4BAA4B,CAAA;AAC7D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAC3D,OAAO,KAAK,mBAAmB,MAAM,gCAAgC,CAAA;AACrE,OAAO,KAAK,cAAc,MAAM,2BAA2B,CAAA;AAC3D,OAAO,KAAK,mBAAmB,MAAM,8CAA8C,CAAA;AACnF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAA;AACvE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAA;AAC/E,OAAO,KAAK,cAAc,MAAM,2BAA2B,CAAA;AAC3D,OAAO,KAAK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AAC;KAAG,CAAC,IAAI,MAAM,UAAU,CAAC,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;CAAE,CAAC,EAAE,YAAY,CAAC,CAAA;AAEjH,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,GAAG;KAAG,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAAE,GAAG,CAAC,CAAA;AAE1F,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,CAAC,GAAG,iBAAiB,EAAE,EAAE,UAAU,CAAC,GAAG,UAAU,CAE1F;AAED,wBAAgB,QAAQ,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAU7E"}
|
package/build/AntConnect.js
CHANGED
|
@@ -4,6 +4,7 @@ import { newClientService } from './services/ClientService';
|
|
|
4
4
|
import { newColumnService } from './services/ColumnService';
|
|
5
5
|
import { newDmsService } from './services/DmsService';
|
|
6
6
|
import { newDownloadService } from './services/DownloadService';
|
|
7
|
+
import { newFeatureService } from './services/FeatureService';
|
|
7
8
|
import { createLabelService } from './services/LabelService';
|
|
8
9
|
import { newLaravelQueueService } from './services/LaravelQueueService';
|
|
9
10
|
import { newLicenseService } from './services/LicenseService';
|
|
@@ -30,6 +31,7 @@ import { newTaskQueryService } from './services/TaskQueryService';
|
|
|
30
31
|
import { newTaskService } from './services/TaskService';
|
|
31
32
|
import { newTaskTemplateService } from './services/TaskTemplateService';
|
|
32
33
|
import { newTokenService } from './services/TokenService';
|
|
34
|
+
import { newUsageService } from './services/UsageService';
|
|
33
35
|
import { newUserService } from './services/UserService';
|
|
34
36
|
import { createConfigService } from './services/Webhook/ConfigService';
|
|
35
37
|
import { createEventService } from './services/Webhook/EventService';
|
|
@@ -83,6 +85,8 @@ export function newAntConnect(httpClient) {
|
|
|
83
85
|
propagations: newPropagationService(httpClient),
|
|
84
86
|
resourceTypes: newResourceTypeService(httpClient),
|
|
85
87
|
releases: newReleaseService(httpClient),
|
|
88
|
+
features: newFeatureService(httpClient),
|
|
89
|
+
usage: newUsageService(httpClient),
|
|
86
90
|
};
|
|
87
91
|
}
|
|
88
92
|
export function newCommunityAntConnect(httpClient) {
|
package/build/comms/client.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AxiosRequestConfig } from 'axios';
|
|
2
2
|
import type { Observable } from 'rxjs';
|
|
3
|
+
import type { DmsUploadHandle, DmsUploadOptions } from './dmsUpload.types';
|
|
3
4
|
import type { Context, Notepad, Notifications, Toolbar } from './models';
|
|
4
5
|
import type { SignalReceiver, SignalSender } from './signal';
|
|
5
6
|
import type { AntConnect } from "../AntConnect";
|
|
@@ -34,6 +35,8 @@ export interface Client extends Subscription {
|
|
|
34
35
|
signal: SignalSender & SignalReceiver;
|
|
35
36
|
request: <T, R>(request: AxiosRequest<T>, controller?: AbortController) => Promise<R>;
|
|
36
37
|
deprecatedRequest: <T, R>(request: AxiosRequest<T>, controller?: AbortController) => Promise<R>;
|
|
38
|
+
/** DMS upload done by the OS (any app origin works); on an older OS it falls back to this frame. */
|
|
39
|
+
uploadDmsFiles: (files: File[], options: DmsUploadOptions) => DmsUploadHandle;
|
|
37
40
|
}
|
|
38
41
|
export declare function newCommsClient(params: ClientParams): Client;
|
|
39
42
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/comms/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAA;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,MAAM,CAAA;AACtC,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AACxE,OAAO,KAA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inctUntilChanged, map, shareReplay, Subject, Subscription, } from 'rxjs';
|
|
2
2
|
import { newHostConnection } from './connection';
|
|
3
|
+
import { newDmsUploader } from './dmsUploadClient';
|
|
3
4
|
import { notificationTypes } from './models';
|
|
4
5
|
import { newSignaler } from './signal';
|
|
5
6
|
import { clone, newScope, takeUntilClosed } from './utils';
|
|
@@ -54,16 +55,17 @@ export function newCommsClient(params) {
|
|
|
54
55
|
return Object.assign(promise, new Subscription());
|
|
55
56
|
},
|
|
56
57
|
}), {});
|
|
58
|
+
const connect = params.connect ?? new Proxy({}, {
|
|
59
|
+
get: (_, service) => new Proxy({}, {
|
|
60
|
+
get: (_, name) => typeof service === 'string' && typeof name === 'string'
|
|
61
|
+
? (...args) => host().then(p => p.connect(service, name, clone(args)))
|
|
62
|
+
: undefined,
|
|
63
|
+
}),
|
|
64
|
+
});
|
|
57
65
|
return Object.assign(subscription, {
|
|
58
66
|
notepad,
|
|
59
67
|
notifications,
|
|
60
|
-
connect
|
|
61
|
-
get: (_, service) => new Proxy({}, {
|
|
62
|
-
get: (_, name) => typeof service === 'string' && typeof name === 'string'
|
|
63
|
-
? (...args) => host().then(p => p.connect(service, name, clone(args)))
|
|
64
|
-
: undefined,
|
|
65
|
-
}),
|
|
66
|
-
}),
|
|
68
|
+
connect,
|
|
67
69
|
context: contextSubject.asObservable().pipe(shareReplay(1)),
|
|
68
70
|
toolbar: Object.assign(toolbarSubject.asObservable().pipe(takeUntilClosed(subscription)), {
|
|
69
71
|
set: (value) => {
|
|
@@ -80,5 +82,6 @@ export function newCommsClient(params) {
|
|
|
80
82
|
signal,
|
|
81
83
|
request: (req, _controller) => host().then(p => p.request(req)),
|
|
82
84
|
deprecatedRequest: (req, _controller) => host().then(p => p.deprecatedRequest(req)),
|
|
85
|
+
uploadDmsFiles: newDmsUploader({ host, connect, context: () => contextSubject.value }),
|
|
83
86
|
});
|
|
84
87
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { DmsUploadProgress, DmsUploadResult, DmsUploadWireOptions } from './dmsUpload.types';
|
|
2
|
+
import type { AntConnect } from "../AntConnect";
|
|
3
|
+
export interface DmsUploadRunInput extends DmsUploadWireOptions {
|
|
4
|
+
connect: Pick<AntConnect, 'dms'>;
|
|
5
|
+
scopeId: string;
|
|
6
|
+
files: File[];
|
|
7
|
+
emit: (progress: DmsUploadProgress) => void;
|
|
8
|
+
}
|
|
9
|
+
export interface DmsUploadRun {
|
|
10
|
+
done: Promise<DmsUploadResult[]>;
|
|
11
|
+
cancel: (index?: number) => void;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The presigned upload: upload URLs → PUT to storage → finish, per file, at most
|
|
15
|
+
* CONCURRENCY at a time. The same code runs in the OS host (normal case) and in the
|
|
16
|
+
* app's frame (fallback for an OS without the host method).
|
|
17
|
+
*/
|
|
18
|
+
export declare function startDmsUpload(input: DmsUploadRunInput): DmsUploadRun;
|
|
19
|
+
//# sourceMappingURL=dmsUpload.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dmsUpload.d.ts","sourceRoot":"","sources":["../../src/comms/dmsUpload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,eAAe,EAAkB,oBAAoB,EAAE,MAAM,mBAAmB,CAAA;AACjH,OAAO,KAAK,EAAE,UAAU,EAAE,sBAAoB;AAU9C,MAAM,WAAW,iBAAkB,SAAQ,oBAAoB;IAC7D,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE,KAAK,CAAC,CAAA;IAChC,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,IAAI,EAAE,CAAA;IACb,IAAI,EAAE,CAAC,QAAQ,EAAE,iBAAiB,KAAK,IAAI,CAAA;CAC5C;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,OAAO,CAAC,eAAe,EAAE,CAAC,CAAA;IAChC,MAAM,EAAE,CAAC,KAAK,CAAC,EAAE,MAAM,KAAK,IAAI,CAAA;CACjC;AAOD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,iBAAiB,GAAG,YAAY,CAmGrE"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { describePutFailure, unreadableReason } from './dmsUploadErrors';
|
|
2
|
+
import { putToStorage } from './dmsUploadPut';
|
|
3
|
+
const CONCURRENCY = 20;
|
|
4
|
+
/** The backend issues at most 50 upload URLs per request. */
|
|
5
|
+
const URLS_PER_REQUEST = 50;
|
|
6
|
+
const PROGRESS_INTERVAL_MS = 250;
|
|
7
|
+
/**
|
|
8
|
+
* The presigned upload: upload URLs → PUT to storage → finish, per file, at most
|
|
9
|
+
* CONCURRENCY at a time. The same code runs in the OS host (normal case) and in the
|
|
10
|
+
* app's frame (fallback for an OS without the host method).
|
|
11
|
+
*/
|
|
12
|
+
export function startDmsUpload(input) {
|
|
13
|
+
const { files, emit } = input;
|
|
14
|
+
const slots = files.map(() => ({ status: 'queued' }));
|
|
15
|
+
const results = files.map((file, index) => ({ index, filename: file.name, status: 'cancelled' }));
|
|
16
|
+
const requestUrl = newUrlBatcher(input.connect, input.scope, input.scopeId);
|
|
17
|
+
files.forEach((file, index) => emit({ index, status: 'queued', loaded: 0, total: file.size }));
|
|
18
|
+
async function uploadOne(index) {
|
|
19
|
+
const file = files[index];
|
|
20
|
+
const slot = slots[index];
|
|
21
|
+
let lastEmit = 0;
|
|
22
|
+
const settle = (result) => {
|
|
23
|
+
slot.status = result.status;
|
|
24
|
+
results[index] = { index, filename: file.name, ...result };
|
|
25
|
+
emit({ index, status: result.status, loaded: result.status === 'done' ? file.size : 0, total: file.size, file: result.file, error: result.error });
|
|
26
|
+
};
|
|
27
|
+
// A function, not an inline check: cancelOne changes the status while we await, and
|
|
28
|
+
// TypeScript would otherwise keep the narrowing from an earlier check.
|
|
29
|
+
const isCancelled = () => slot.status === 'cancelled';
|
|
30
|
+
try {
|
|
31
|
+
const unreadable = await unreadableReason(file);
|
|
32
|
+
// Cancelled while reading: cancelOne already emitted the final event.
|
|
33
|
+
if (isCancelled())
|
|
34
|
+
return;
|
|
35
|
+
if (unreadable)
|
|
36
|
+
return settle({ status: 'error', error: unreadable });
|
|
37
|
+
for (let attempt = 0;; attempt++) {
|
|
38
|
+
// URLs are requested only when a file is about to start: they expire 300 s after issue.
|
|
39
|
+
const target = await requestUrl(file.name);
|
|
40
|
+
if (isCancelled())
|
|
41
|
+
return;
|
|
42
|
+
slot.status = 'uploading';
|
|
43
|
+
emit({ index, status: 'uploading', loaded: 0, total: file.size });
|
|
44
|
+
const put = putToStorage(target.config.url, target.config.headers, file, (loaded) => {
|
|
45
|
+
const now = Date.now();
|
|
46
|
+
if (now - lastEmit >= PROGRESS_INTERVAL_MS || loaded === file.size) {
|
|
47
|
+
lastEmit = now;
|
|
48
|
+
emit({ index, status: 'uploading', loaded, total: file.size });
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
slot.abort = put.abort;
|
|
52
|
+
const status = await put.done;
|
|
53
|
+
slot.abort = undefined;
|
|
54
|
+
if (status === 'aborted')
|
|
55
|
+
return settle({ status: 'cancelled' });
|
|
56
|
+
// A 403 at start is an expired URL (a long queue); one fresh URL is worth a retry. Back to
|
|
57
|
+
// 'queued' while it is fetched, so a cancel in that window still emits its final event.
|
|
58
|
+
if (status === 403 && attempt === 0) {
|
|
59
|
+
slot.status = 'queued';
|
|
60
|
+
emit({ index, status: 'queued', loaded: 0, total: file.size });
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
if (status !== 'ok')
|
|
64
|
+
return settle({ status: 'error', error: describePutFailure(status, target.config.url, file.size) });
|
|
65
|
+
slot.status = 'finishing';
|
|
66
|
+
emit({ index, status: 'finishing', loaded: file.size, total: file.size });
|
|
67
|
+
const created = await finish(input, [{ key: target.key, filename: file.name }]);
|
|
68
|
+
return settle({ status: 'done', file: created[0] });
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
settle({ status: 'error', error: error instanceof Error ? error.message : String(error) });
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
async function worker(queue) {
|
|
76
|
+
for (let index = queue.shift(); index !== undefined; index = queue.shift()) {
|
|
77
|
+
if (slots[index].status === 'queued')
|
|
78
|
+
await uploadOne(index);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const queue = files.map((_, index) => index);
|
|
82
|
+
const done = Promise.all(Array.from({ length: Math.min(CONCURRENCY, files.length) }, () => worker(queue)))
|
|
83
|
+
.then(() => results);
|
|
84
|
+
function cancelOne(index) {
|
|
85
|
+
const slot = slots[index];
|
|
86
|
+
if (!slot)
|
|
87
|
+
return;
|
|
88
|
+
if (slot.status === 'queued') {
|
|
89
|
+
slot.status = 'cancelled';
|
|
90
|
+
emit({ index, status: 'cancelled', loaded: 0, total: files[index].size });
|
|
91
|
+
}
|
|
92
|
+
else if (slot.status === 'uploading') {
|
|
93
|
+
slot.status = 'cancelled';
|
|
94
|
+
slot.abort?.();
|
|
95
|
+
}
|
|
96
|
+
// 'finishing' and later: the file is already in storage, so let DMS register it.
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
done,
|
|
100
|
+
cancel: index => index === undefined ? slots.forEach((_, i) => cancelOne(i)) : cancelOne(index),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function finish(input, payload) {
|
|
104
|
+
const { connect, scope, scopeId, folderToken, duplicateAction } = input;
|
|
105
|
+
return scope === 'project'
|
|
106
|
+
? connect.dms.uploadFilesFinish(folderToken ?? null, scopeId, payload, duplicateAction)
|
|
107
|
+
: connect.dms.uploadLicenseFilesFinish(folderToken ?? null, scopeId, payload, duplicateAction);
|
|
108
|
+
}
|
|
109
|
+
// One URL request per tick. Responses are matched by filename, so a repeated name starts a new batch.
|
|
110
|
+
function newUrlBatcher(connect, scope, scopeId) {
|
|
111
|
+
let open = null;
|
|
112
|
+
async function flush(batch) {
|
|
113
|
+
try {
|
|
114
|
+
const names = batch.map(w => w.name);
|
|
115
|
+
const response = scope === 'project'
|
|
116
|
+
? await connect.dms.getUploadUrls(scopeId, names)
|
|
117
|
+
: await connect.dms.getLicenseUploadUrls(scopeId, names);
|
|
118
|
+
const byName = new Map(response.data.map(item => [item.filename, item]));
|
|
119
|
+
for (const waiter of batch) {
|
|
120
|
+
const item = byName.get(waiter.name);
|
|
121
|
+
item ? waiter.resolve(item) : waiter.reject(new Error(`No upload URL returned for ${waiter.name}`));
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
batch.forEach(waiter => waiter.reject(error));
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return (name) => new Promise((resolve, reject) => {
|
|
129
|
+
if (!open || open.length >= URLS_PER_REQUEST || open.some(w => w.name === name)) {
|
|
130
|
+
const batch = [];
|
|
131
|
+
open = batch;
|
|
132
|
+
setTimeout(() => {
|
|
133
|
+
if (open === batch)
|
|
134
|
+
open = null;
|
|
135
|
+
void flush(batch);
|
|
136
|
+
}, 0);
|
|
137
|
+
}
|
|
138
|
+
open.push({ name, resolve, reject });
|
|
139
|
+
});
|
|
140
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { DmsDuplicateAction, DmsFile } from "../services/DmsService";
|
|
2
|
+
export type DmsUploadScope = 'project' | 'license';
|
|
3
|
+
export type DmsUploadStatus = 'queued' | 'uploading' | 'finishing' | 'done' | 'error' | 'cancelled';
|
|
4
|
+
export interface DmsUploadProgress {
|
|
5
|
+
/** Position of the file in the array passed to `uploadDmsFiles`. */
|
|
6
|
+
index: number;
|
|
7
|
+
status: DmsUploadStatus;
|
|
8
|
+
loaded: number;
|
|
9
|
+
total: number;
|
|
10
|
+
file?: DmsFile;
|
|
11
|
+
error?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface DmsUploadResult {
|
|
14
|
+
index: number;
|
|
15
|
+
filename: string;
|
|
16
|
+
status: 'done' | 'error' | 'cancelled';
|
|
17
|
+
file?: DmsFile;
|
|
18
|
+
error?: string;
|
|
19
|
+
}
|
|
20
|
+
/** The part of the options that crosses to the host: plain JSON, no callbacks. */
|
|
21
|
+
export interface DmsUploadWireOptions {
|
|
22
|
+
/** The scope id is taken from the app's current context, never from the app. */
|
|
23
|
+
scope: DmsUploadScope;
|
|
24
|
+
/** Folder to upload into; `null` or omitted is the scope's root. */
|
|
25
|
+
folderToken?: string | null;
|
|
26
|
+
duplicateAction?: DmsDuplicateAction;
|
|
27
|
+
}
|
|
28
|
+
export interface DmsUploadOptions extends DmsUploadWireOptions {
|
|
29
|
+
onProgress?: (progress: DmsUploadProgress) => void;
|
|
30
|
+
}
|
|
31
|
+
export interface DmsUploadHandle {
|
|
32
|
+
/** One result per input file. Rejects only when nothing could start (no scope, read-only project). */
|
|
33
|
+
done: Promise<DmsUploadResult[]>;
|
|
34
|
+
/** Cancel one file by index, or every file. A file already being finished completes. */
|
|
35
|
+
cancel: (index?: number) => void;
|
|
36
|
+
/** `host`: the OS performed the upload. `local`: an older OS; the app's frame did. */
|
|
37
|
+
mode: Promise<'host' | 'local'>;
|
|
38
|
+
}
|
|
39
|
+
/** Advertised on the HostAPI so a client can tell whether this OS performs uploads. */
|
|
40
|
+
export declare const DMS_UPLOAD_CAPABILITY = "dms.upload";
|
|
41
|
+
export declare const DmsUploadError: {
|
|
42
|
+
readonly NoScope: "DMS_UPLOAD_NO_SCOPE";
|
|
43
|
+
readonly ReadOnly: "DMS_UPLOAD_READ_ONLY";
|
|
44
|
+
readonly InvalidFiles: "DMS_UPLOAD_INVALID_FILES";
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=dmsUpload.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dmsUpload.types.d.ts","sourceRoot":"","sources":["../../src/comms/dmsUpload.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,OAAO,EAAE,+BAA6B;AAExE,MAAM,MAAM,cAA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IjB,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Advertised on the HostAPI so a client can tell whether this OS performs uploads. */
|
|
2
|
+
export const DMS_UPLOAD_CAPABILITY = 'dms.upload';
|
|
3
|
+
export const DmsUploadError = {
|
|
4
|
+
NoScope: 'DMS_UPLOAD_NO_SCOPE',
|
|
5
|
+
ReadOnly: 'DMS_UPLOAD_READ_ONLY',
|
|
6
|
+
InvalidFiles: 'DMS_UPLOAD_INVALID_FILES',
|
|
7
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { DmsUploadHandle, DmsUploadOptions } from './dmsUpload.types';
|
|
2
|
+
import type { HostAPI } from './hostAPI';
|
|
3
|
+
import type { Context } from './models';
|
|
4
|
+
import type { AntConnect } from "../AntConnect";
|
|
5
|
+
import * as Comlink from 'comlink';
|
|
6
|
+
interface DmsUploadClientDeps {
|
|
7
|
+
host: () => Promise<Comlink.Remote<HostAPI>>;
|
|
8
|
+
connect: AntConnect;
|
|
9
|
+
context: () => Context;
|
|
10
|
+
}
|
|
11
|
+
export declare function newDmsUploader(deps: DmsUploadClientDeps): (input: File[], options: DmsUploadOptions) => DmsUploadHandle;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=dmsUploadClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dmsUploadClient.d.ts","sourceRoot":"","sources":["../../src/comms/dmsUploadClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAsC,MAAM,mBAAmB,CAAA;AAC9G,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACxC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AACvC,OAAO,KAAK,EAAE,UAAU,EAAE,sBAAoB;AAC9C,OAAO,KAAK,OAAO,MAAM,SAAS,CAAA;AAKlC,UAAU,mBAAmB;IAC3B,IAAI,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAA;IAC5C,OAAO,EAAE,UAAU,CAAA;IACnB,OAAO,EAAE,MAAM,OAAO,CAAA;CACvB;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,mBAAmB,IAc9C,OAAO,IAAI,EAAE,EAAE,SAAS,gBAAgB,KAAG,eAAe,CA8BnE"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import * as Comlink from 'comlink';
|
|
2
|
+
import { startDmsUpload } from './dmsUpload';
|
|
3
|
+
import { DMS_UPLOAD_CAPABILITY, DmsUploadError } from './dmsUpload.types';
|
|
4
|
+
import { newId } from './utils';
|
|
5
|
+
export function newDmsUploader(deps) {
|
|
6
|
+
// Per host proxy: a re-handshake can hand us a different (newer or older) OS.
|
|
7
|
+
const supported = new WeakMap();
|
|
8
|
+
const hostSupports = (proxy) => {
|
|
9
|
+
let known = supported.get(proxy);
|
|
10
|
+
if (!known) {
|
|
11
|
+
known = Promise.resolve(proxy.capabilities)
|
|
12
|
+
.then(capabilities => Array.isArray(capabilities) && capabilities.includes(DMS_UPLOAD_CAPABILITY))
|
|
13
|
+
.catch(() => false);
|
|
14
|
+
supported.set(proxy, known);
|
|
15
|
+
}
|
|
16
|
+
return known;
|
|
17
|
+
};
|
|
18
|
+
return (input, options) => {
|
|
19
|
+
// Plain array of plain Files: a Vue reactive array is a Proxy, and a Proxy can't be posted.
|
|
20
|
+
const files = Array.from(input);
|
|
21
|
+
const { onProgress, ...wire } = options;
|
|
22
|
+
const emit = (progress) => onProgress?.(progress);
|
|
23
|
+
const uploadId = newId();
|
|
24
|
+
let cancelNow = null;
|
|
25
|
+
const earlyCancels = [];
|
|
26
|
+
const cancel = (index) => cancelNow ? cancelNow(index) : earlyCancels.push(index);
|
|
27
|
+
const started = deps.host().then(async (proxy) => {
|
|
28
|
+
if (await hostSupports(proxy)) {
|
|
29
|
+
cancelNow = index => void proxy.cancelDmsUpload(uploadId, index).catch(() => { });
|
|
30
|
+
earlyCancels.forEach(cancelNow);
|
|
31
|
+
const done = proxy.uploadDmsFiles(uploadId, files, wire, Comlink.proxy(emit));
|
|
32
|
+
return { mode: 'host', done };
|
|
33
|
+
}
|
|
34
|
+
// An OS without the host method: upload from this frame, as apps did before.
|
|
35
|
+
const run = startDmsUpload({ ...wire, connect: deps.connect, scopeId: localScopeId(deps.context(), wire.scope), files, emit });
|
|
36
|
+
cancelNow = run.cancel;
|
|
37
|
+
earlyCancels.forEach(cancelNow);
|
|
38
|
+
return { mode: 'local', done: run.done };
|
|
39
|
+
});
|
|
40
|
+
return {
|
|
41
|
+
done: started.then(s => s.done),
|
|
42
|
+
mode: started.then(s => s.mode),
|
|
43
|
+
cancel,
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function localScopeId(context, scope) {
|
|
48
|
+
const id = scope === 'project' ? context.project?.id : context.license?.id;
|
|
49
|
+
if (!id)
|
|
50
|
+
throw new Error(DmsUploadError.NoScope);
|
|
51
|
+
if (scope === 'project' && context.projectReadOnly)
|
|
52
|
+
throw new Error(DmsUploadError.ReadOnly);
|
|
53
|
+
return id;
|
|
54
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { PutOutcome } from './dmsUploadPut';
|
|
2
|
+
export declare function describePutFailure(outcome: Exclude<PutOutcome, 'ok' | 'aborted'>, url: string, size: number): string;
|
|
3
|
+
/** A File handed across frames may not be readable on this side; find out before the PUT does. */
|
|
4
|
+
export declare function unreadableReason(file: File): Promise<string | null>;
|
|
5
|
+
//# sourceMappingURL=dmsUploadErrors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dmsUploadErrors.d.ts","sourceRoot":"","sources":["../../src/comms/dmsUploadErrors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAMhD,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,CAAC,UAAU,EAAE,IAAI,GAAG,SAAS,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAWpH;AAED,kGAAkG;AAClG,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAUzE"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// The browser never tells script why a request was blocked, so these messages say what the page
|
|
2
|
+
// can know (who sent it, how far it got) and point at the console that has the rest.
|
|
3
|
+
const here = () => globalThis.location?.origin ?? 'this page';
|
|
4
|
+
export function describePutFailure(outcome, url, size) {
|
|
5
|
+
const storage = new URL(url).host;
|
|
6
|
+
if (typeof outcome === 'number') {
|
|
7
|
+
const hint = outcome === 403 ? ' (expired or wrongly signed URL, or extra headers)' : '';
|
|
8
|
+
return `Storage ${storage} refused the PUT from ${here()}: HTTP ${outcome}${hint}`;
|
|
9
|
+
}
|
|
10
|
+
const phase = outcome.sentBytes > 0
|
|
11
|
+
? `after ${outcome.sentBytes} of ${size} bytes`
|
|
12
|
+
: 'before any data was sent (refused preflight or blocked request)';
|
|
13
|
+
return `No response from storage ${storage} for the PUT from ${here()}, ${phase}. `
|
|
14
|
+
+ `The console of ${here()} shows the browser's reason (CORS, CSP, extension or offline).`;
|
|
15
|
+
}
|
|
16
|
+
/** A File handed across frames may not be readable on this side; find out before the PUT does. */
|
|
17
|
+
export async function unreadableReason(file) {
|
|
18
|
+
try {
|
|
19
|
+
await file.slice(0, 1).arrayBuffer();
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
24
|
+
return `The file could not be read in ${here()}, the page uploading it for the app (it may have been moved, `
|
|
25
|
+
+ `changed or deleted since it was picked): ${reason}`;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { DmsUploadProgress, DmsUploadResult, DmsUploadWireOptions } from './dmsUpload.types';
|
|
2
|
+
import type { Box } from './host';
|
|
3
|
+
export interface DmsUploadHost {
|
|
4
|
+
upload: (uploadId: string, files: File[], options: DmsUploadWireOptions, onProgress: (progress: DmsUploadProgress) => void) => Promise<DmsUploadResult[]>;
|
|
5
|
+
cancel: (uploadId: string, index?: number) => void;
|
|
6
|
+
}
|
|
7
|
+
export declare function newDmsUploadHost(box: Box): DmsUploadHost;
|
|
8
|
+
//# sourceMappingURL=dmsUploadHost.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dmsUploadHost.d.ts","sourceRoot":"","sources":["../../src/comms/dmsUploadHost.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAA;AACjG,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAA;AAMjC,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,CACN,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,IAAI,EAAE,EACb,OAAO,EAAE,oBAAoB,EAC7B,UAAU,EAAE,CAAC,QAAQ,EAAE,iBAAiB,KAAK,IAAI,KAC9C,OAAO,CAAC,eAAe,EAAE,CAAC,CAAA;IAC/B,MAAM,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,KAAK,IAAI,CAAA;CACnD;AAGD,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,GAAG,GAAG,aAAa,CAoCxD"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import * as Comlink from 'comlink';
|
|
2
|
+
import { firstValueFrom } from 'rxjs';
|
|
3
|
+
import { startDmsUpload } from './dmsUpload';
|
|
4
|
+
import { DmsUploadError } from './dmsUpload.types';
|
|
5
|
+
// Runs the PUT in the OS so it leaves from the OS origin, whatever origin serves the app.
|
|
6
|
+
export function newDmsUploadHost(box) {
|
|
7
|
+
const running = new Map();
|
|
8
|
+
// Closing the pane aborts its uploads; files already finished stay.
|
|
9
|
+
box.scope.add(() => running.forEach(run => run.cancel()));
|
|
10
|
+
return {
|
|
11
|
+
async upload(uploadId, files, options, onProgress) {
|
|
12
|
+
// A File that went through a JSON clone arrives as `{}` and would upload nothing.
|
|
13
|
+
if (!Array.isArray(files) || !files.every(file => file instanceof Blob))
|
|
14
|
+
throw new Error(DmsUploadError.InvalidFiles);
|
|
15
|
+
// The scope comes from this pane's context, not from the app's arguments.
|
|
16
|
+
const context = await firstValueFrom(box.params.contextChanges);
|
|
17
|
+
const scopeId = options.scope === 'project' ? context.project?.id : context.license?.id;
|
|
18
|
+
if (!scopeId)
|
|
19
|
+
throw new Error(DmsUploadError.NoScope);
|
|
20
|
+
if (options.scope === 'project' && context.projectReadOnly)
|
|
21
|
+
throw new Error(DmsUploadError.ReadOnly);
|
|
22
|
+
// The callback lives in the app frame; a closed frame must not stall or fail the upload.
|
|
23
|
+
const emit = (progress) => {
|
|
24
|
+
void Promise.resolve(onProgress(progress)).catch(() => { });
|
|
25
|
+
};
|
|
26
|
+
const run = startDmsUpload({ ...options, connect: box.params.connect, scopeId, files, emit });
|
|
27
|
+
running.set(uploadId, run);
|
|
28
|
+
try {
|
|
29
|
+
return await run.done;
|
|
30
|
+
}
|
|
31
|
+
finally {
|
|
32
|
+
running.delete(uploadId);
|
|
33
|
+
releaseCallback(onProgress);
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
cancel: (uploadId, index) => running.get(uploadId)?.cancel(index),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function releaseCallback(callback) {
|
|
40
|
+
const release = typeof callback === 'function' ? Reflect.get(callback, Comlink.releaseProxy) : undefined;
|
|
41
|
+
if (typeof release === 'function')
|
|
42
|
+
release();
|
|
43
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** `network`: no HTTP response at all; `sentBytes` > 0 means the preflight passed and the body was going out. */
|
|
2
|
+
export type PutOutcome = 'ok' | 'aborted' | number | {
|
|
3
|
+
network: true;
|
|
4
|
+
sentBytes: number;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* PUT a file to a presigned storage URL. XHR rather than fetch for upload progress and abort.
|
|
8
|
+
* Sends exactly the headers the URL was signed with, minus Host (the browser owns it): extra
|
|
9
|
+
* unsigned `x-amz-*` headers would be refused.
|
|
10
|
+
*/
|
|
11
|
+
export declare function putToStorage(url: string, headers: Record<string, string[]>, file: File, onProgress: (loaded: number) => void): {
|
|
12
|
+
done: Promise<PutOutcome>;
|
|
13
|
+
abort: () => void;
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=dmsUploadPut.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dmsUploadPut.d.ts","sourceRoot":"","sources":["../../src/comms/dmsUploadPut.ts"],"names":[],"mappings":"AAAA,iHAAiH;AACjH,MAAM,MAAM,UAAU,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG;IAAE,OAAO,EAAE,IAAI,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAA;AAEzF;;;;GAIG;AACH,wBAAgB,YAAY,CAC1B,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,EACjC,IAAI,EAAE,IAAI,EACV,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,GACnC;IAAE,IAAI,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;IAAC,KAAK,EAAE,MAAM,IAAI,CAAA;CAAE,CA0BlD"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PUT a file to a presigned storage URL. XHR rather than fetch for upload progress and abort.
|
|
3
|
+
* Sends exactly the headers the URL was signed with, minus Host (the browser owns it): extra
|
|
4
|
+
* unsigned `x-amz-*` headers would be refused.
|
|
5
|
+
*/
|
|
6
|
+
export function putToStorage(url, headers, file, onProgress) {
|
|
7
|
+
const xhr = new XMLHttpRequest();
|
|
8
|
+
xhr.open('PUT', url, true);
|
|
9
|
+
Object.entries(headers)
|
|
10
|
+
.filter(([name]) => name.toLowerCase() !== 'host')
|
|
11
|
+
.forEach(([name, values]) => xhr.setRequestHeader(name, values.join(', ')));
|
|
12
|
+
let sentBytes = 0;
|
|
13
|
+
xhr.upload.onprogress = (event) => {
|
|
14
|
+
sentBytes = Math.max(sentBytes, event.loaded);
|
|
15
|
+
if (event.lengthComputable)
|
|
16
|
+
onProgress(event.loaded);
|
|
17
|
+
};
|
|
18
|
+
const done = new Promise((resolve) => {
|
|
19
|
+
xhr.onload = () => resolve(xhr.status >= 200 && xhr.status < 300 ? 'ok' : xhr.status);
|
|
20
|
+
// No response at all: offline, or the browser blocked it (CORS, CSP, an extension).
|
|
21
|
+
xhr.onerror = () => resolve({ network: true, sentBytes });
|
|
22
|
+
xhr.onabort = () => resolve('aborted');
|
|
23
|
+
});
|
|
24
|
+
// Send a slice, never the File itself. A File picked in another site's frame is backed by a disk
|
|
25
|
+
// path only that frame's process may read, so Chrome refuses it as a request body here
|
|
26
|
+
// (net::ERR_ACCESS_DENIED). A slice goes through the blob handle this page holds: no copy.
|
|
27
|
+
xhr.send(file.slice(0, file.size, file.type));
|
|
28
|
+
return { done, abort: () => xhr.abort() };
|
|
29
|
+
}
|