@protontech/drive-sdk 0.6.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/diagnostic/diagnostic.d.ts +7 -4
- package/dist/diagnostic/diagnostic.js +16 -8
- package/dist/diagnostic/diagnostic.js.map +1 -1
- package/dist/diagnostic/index.d.ts +1 -1
- package/dist/diagnostic/index.js +9 -1
- package/dist/diagnostic/index.js.map +1 -1
- package/dist/diagnostic/interface.d.ts +24 -9
- package/dist/diagnostic/nodeUtils.d.ts +13 -0
- package/dist/diagnostic/nodeUtils.js +90 -0
- package/dist/diagnostic/nodeUtils.js.map +1 -0
- package/dist/diagnostic/sdkDiagnosticBase.d.ts +36 -0
- package/dist/diagnostic/sdkDiagnosticBase.js +305 -0
- package/dist/diagnostic/sdkDiagnosticBase.js.map +1 -0
- package/dist/diagnostic/sdkDiagnosticMain.d.ts +16 -0
- package/dist/diagnostic/sdkDiagnosticMain.js +79 -0
- package/dist/diagnostic/sdkDiagnosticMain.js.map +1 -0
- package/dist/diagnostic/sdkDiagnosticPhotos.d.ts +13 -0
- package/dist/diagnostic/sdkDiagnosticPhotos.js +65 -0
- package/dist/diagnostic/sdkDiagnosticPhotos.js.map +1 -0
- package/dist/internal/devices/interface.d.ts +1 -1
- package/dist/internal/devices/manager.js +1 -1
- package/dist/internal/devices/manager.js.map +1 -1
- package/dist/internal/devices/manager.test.js +3 -3
- package/dist/internal/devices/manager.test.js.map +1 -1
- package/dist/internal/errors.d.ts +5 -0
- package/dist/internal/errors.js +23 -0
- package/dist/internal/errors.js.map +1 -1
- package/dist/internal/errors.test.js +53 -2
- package/dist/internal/errors.test.js.map +1 -1
- package/dist/internal/nodes/cryptoReporter.js +3 -0
- package/dist/internal/nodes/cryptoReporter.js.map +1 -1
- package/dist/internal/nodes/index.test.js +1 -1
- package/dist/internal/nodes/index.test.js.map +1 -1
- package/dist/internal/nodes/interface.d.ts +1 -1
- package/dist/internal/nodes/nodesAccess.d.ts +1 -1
- package/dist/internal/nodes/nodesAccess.js +4 -4
- package/dist/internal/nodes/nodesAccess.js.map +1 -1
- package/dist/internal/nodes/nodesAccess.test.js +2 -2
- package/dist/internal/nodes/nodesAccess.test.js.map +1 -1
- package/dist/internal/photos/albums.js +1 -1
- package/dist/internal/photos/albums.js.map +1 -1
- package/dist/internal/photos/apiService.d.ts +6 -0
- package/dist/internal/photos/apiService.js +16 -0
- package/dist/internal/photos/apiService.js.map +1 -1
- package/dist/internal/photos/index.d.ts +1 -1
- package/dist/internal/photos/index.js +2 -2
- package/dist/internal/photos/index.js.map +1 -1
- package/dist/internal/photos/interface.d.ts +4 -1
- package/dist/internal/photos/shares.d.ts +1 -1
- package/dist/internal/photos/shares.js +3 -3
- package/dist/internal/photos/shares.js.map +1 -1
- package/dist/internal/photos/timeline.d.ts +8 -1
- package/dist/internal/photos/timeline.js +36 -2
- package/dist/internal/photos/timeline.js.map +1 -1
- package/dist/internal/photos/timeline.test.d.ts +1 -0
- package/dist/internal/photos/timeline.test.js +99 -0
- package/dist/internal/photos/timeline.test.js.map +1 -0
- package/dist/internal/shares/cryptoService.js +3 -0
- package/dist/internal/shares/cryptoService.js.map +1 -1
- package/dist/internal/shares/manager.d.ts +1 -1
- package/dist/internal/shares/manager.js +4 -4
- package/dist/internal/shares/manager.js.map +1 -1
- package/dist/internal/shares/manager.test.js +7 -7
- package/dist/internal/shares/manager.test.js.map +1 -1
- package/dist/internal/sharing/interface.d.ts +1 -1
- package/dist/internal/sharing/sharingAccess.js +1 -1
- package/dist/internal/sharing/sharingAccess.js.map +1 -1
- package/dist/internal/sharing/sharingAccess.test.js +1 -1
- package/dist/internal/sharing/sharingAccess.test.js.map +1 -1
- package/dist/internal/sharing/sharingManagement.js +32 -14
- package/dist/internal/sharing/sharingManagement.js.map +1 -1
- package/dist/internal/sharing/sharingManagement.test.js +46 -1
- package/dist/internal/sharing/sharingManagement.test.js.map +1 -1
- package/dist/internal/sharingPublic/cryptoReporter.js +3 -0
- package/dist/internal/sharingPublic/cryptoReporter.js.map +1 -1
- package/dist/internal/sharingPublic/index.d.ts +3 -0
- package/dist/internal/sharingPublic/index.js +3 -0
- package/dist/internal/sharingPublic/index.js.map +1 -1
- package/dist/internal/sharingPublic/shares.d.ts +1 -1
- package/dist/internal/sharingPublic/shares.js +1 -2
- package/dist/internal/sharingPublic/shares.js.map +1 -1
- package/dist/protonDrivePhotosClient.d.ts +19 -0
- package/dist/protonDrivePhotosClient.js +23 -1
- package/dist/protonDrivePhotosClient.js.map +1 -1
- package/dist/protonDrivePublicLinkClient.d.ts +33 -1
- package/dist/protonDrivePublicLinkClient.js +51 -2
- package/dist/protonDrivePublicLinkClient.js.map +1 -1
- package/package.json +1 -1
- package/src/diagnostic/diagnostic.ts +27 -8
- package/src/diagnostic/index.ts +17 -2
- package/src/diagnostic/interface.ts +35 -9
- package/src/diagnostic/nodeUtils.ts +100 -0
- package/src/diagnostic/{sdkDiagnostic.ts → sdkDiagnosticBase.ts} +204 -204
- package/src/diagnostic/sdkDiagnosticMain.ts +95 -0
- package/src/diagnostic/sdkDiagnosticPhotos.ts +70 -0
- package/src/internal/devices/interface.ts +1 -1
- package/src/internal/devices/manager.test.ts +3 -3
- package/src/internal/devices/manager.ts +1 -1
- package/src/internal/errors.test.ts +62 -1
- package/src/internal/errors.ts +27 -0
- package/src/internal/nodes/cryptoReporter.ts +6 -5
- package/src/internal/nodes/index.test.ts +1 -1
- package/src/internal/nodes/interface.ts +1 -1
- package/src/internal/nodes/nodesAccess.test.ts +2 -2
- package/src/internal/nodes/nodesAccess.ts +5 -5
- package/src/internal/photos/albums.ts +1 -1
- package/src/internal/photos/apiService.ts +40 -0
- package/src/internal/photos/index.ts +9 -1
- package/src/internal/photos/interface.ts +4 -1
- package/src/internal/photos/shares.ts +3 -3
- package/src/internal/photos/timeline.test.ts +116 -0
- package/src/internal/photos/timeline.ts +47 -2
- package/src/internal/shares/cryptoService.ts +5 -1
- package/src/internal/shares/manager.test.ts +7 -7
- package/src/internal/shares/manager.ts +4 -4
- package/src/internal/sharing/interface.ts +1 -1
- package/src/internal/sharing/sharingAccess.test.ts +1 -1
- package/src/internal/sharing/sharingAccess.ts +1 -1
- package/src/internal/sharing/sharingManagement.test.ts +59 -1
- package/src/internal/sharing/sharingManagement.ts +33 -14
- package/src/internal/sharingPublic/cryptoReporter.ts +5 -1
- package/src/internal/sharingPublic/index.ts +3 -0
- package/src/internal/sharingPublic/shares.ts +1 -2
- package/src/protonDrivePhotosClient.ts +24 -1
- package/src/protonDrivePublicLinkClient.ts +77 -2
- package/dist/diagnostic/sdkDiagnostic.d.ts +0 -23
- package/dist/diagnostic/sdkDiagnostic.js +0 -320
- package/dist/diagnostic/sdkDiagnostic.js.map +0 -1
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { MaybeNode } from '../interface';
|
|
2
2
|
import { ProtonDriveClient } from '../protonDriveClient';
|
|
3
|
+
import { ProtonDrivePhotosClient } from '../protonDrivePhotosClient';
|
|
3
4
|
import { DiagnosticHTTPClient } from './httpClient';
|
|
4
|
-
import { DiagnosticOptions, DiagnosticResult } from './interface';
|
|
5
|
-
import {
|
|
5
|
+
import { DiagnosticOptions, DiagnosticProgressCallback, DiagnosticResult } from './interface';
|
|
6
|
+
import { SDKDiagnosticMain } from './sdkDiagnosticMain';
|
|
7
|
+
import { SDKDiagnosticPhotos } from './sdkDiagnosticPhotos';
|
|
6
8
|
import { DiagnosticTelemetry } from './telemetry';
|
|
7
9
|
import { zipGenerators } from './zipGenerators';
|
|
8
10
|
|
|
@@ -15,20 +17,37 @@ export class Diagnostic {
|
|
|
15
17
|
private telemetry: DiagnosticTelemetry,
|
|
16
18
|
private httpClient: DiagnosticHTTPClient,
|
|
17
19
|
private protonDriveClient: ProtonDriveClient,
|
|
20
|
+
private protonDrivePhotosClient: ProtonDrivePhotosClient,
|
|
18
21
|
) {
|
|
19
22
|
this.telemetry = telemetry;
|
|
20
23
|
this.httpClient = httpClient;
|
|
21
24
|
this.protonDriveClient = protonDriveClient;
|
|
25
|
+
this.protonDrivePhotosClient = protonDrivePhotosClient;
|
|
22
26
|
}
|
|
23
27
|
|
|
24
|
-
async *verifyMyFiles(
|
|
25
|
-
|
|
26
|
-
|
|
28
|
+
async *verifyMyFiles(
|
|
29
|
+
options?: DiagnosticOptions,
|
|
30
|
+
onProgress?: DiagnosticProgressCallback,
|
|
31
|
+
): AsyncGenerator<DiagnosticResult> {
|
|
32
|
+
const diagnostic = new SDKDiagnosticMain(this.protonDriveClient, options, onProgress);
|
|
33
|
+
yield* this.yieldEvents(diagnostic.verifyMyFiles(options?.expectedStructure));
|
|
27
34
|
}
|
|
28
35
|
|
|
29
|
-
async *verifyNodeTree(
|
|
30
|
-
|
|
31
|
-
|
|
36
|
+
async *verifyNodeTree(
|
|
37
|
+
node: MaybeNode,
|
|
38
|
+
options?: DiagnosticOptions,
|
|
39
|
+
onProgress?: DiagnosticProgressCallback,
|
|
40
|
+
): AsyncGenerator<DiagnosticResult> {
|
|
41
|
+
const diagnostic = new SDKDiagnosticMain(this.protonDriveClient, options, onProgress);
|
|
42
|
+
yield* this.yieldEvents(diagnostic.verifyNodeTree(node, options?.expectedStructure));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async *verifyPhotosTimeline(
|
|
46
|
+
options?: DiagnosticOptions,
|
|
47
|
+
onProgress?: DiagnosticProgressCallback,
|
|
48
|
+
): AsyncGenerator<DiagnosticResult> {
|
|
49
|
+
const diagnostic = new SDKDiagnosticPhotos(this.protonDrivePhotosClient, options, onProgress);
|
|
50
|
+
yield* this.yieldEvents(diagnostic.verifyTimeline(options?.expectedStructure));
|
|
32
51
|
}
|
|
33
52
|
|
|
34
53
|
private async *yieldEvents(generator: AsyncGenerator<DiagnosticResult>): AsyncGenerator<DiagnosticResult> {
|
package/src/diagnostic/index.ts
CHANGED
|
@@ -5,8 +5,15 @@ import { Diagnostic as DiagnosticClass } from './diagnostic';
|
|
|
5
5
|
import { Diagnostic } from './interface';
|
|
6
6
|
import { DiagnosticHTTPClient } from './httpClient';
|
|
7
7
|
import { DiagnosticTelemetry } from './telemetry';
|
|
8
|
+
import { ProtonDrivePhotosClient } from '../protonDrivePhotosClient';
|
|
8
9
|
|
|
9
|
-
export type {
|
|
10
|
+
export type {
|
|
11
|
+
Diagnostic,
|
|
12
|
+
DiagnosticOptions,
|
|
13
|
+
ExpectedTreeNode,
|
|
14
|
+
DiagnosticProgressCallback,
|
|
15
|
+
DiagnosticResult,
|
|
16
|
+
} from './interface';
|
|
10
17
|
|
|
11
18
|
/**
|
|
12
19
|
* Initializes the diagnostic tool. It creates the instance of
|
|
@@ -34,5 +41,13 @@ export function initDiagnostic(
|
|
|
34
41
|
telemetry,
|
|
35
42
|
});
|
|
36
43
|
|
|
37
|
-
|
|
44
|
+
const protonDrivePhotosClient = new ProtonDrivePhotosClient({
|
|
45
|
+
...options,
|
|
46
|
+
httpClient,
|
|
47
|
+
entitiesCache: new NullCache(),
|
|
48
|
+
cryptoCache: new MemoryCache(),
|
|
49
|
+
telemetry,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
return new DiagnosticClass(telemetry, httpClient, protonDriveClient, protonDrivePhotosClient);
|
|
38
53
|
}
|
|
@@ -2,24 +2,48 @@ import { Author, MaybeNode, MetricEvent, NodeType, AnonymousUser } from '../inte
|
|
|
2
2
|
import { LogRecord } from '../telemetry';
|
|
3
3
|
|
|
4
4
|
export interface Diagnostic {
|
|
5
|
-
verifyMyFiles(
|
|
6
|
-
|
|
5
|
+
verifyMyFiles(
|
|
6
|
+
options?: DiagnosticOptions,
|
|
7
|
+
onProgress?: DiagnosticProgressCallback,
|
|
8
|
+
): AsyncGenerator<DiagnosticResult>;
|
|
9
|
+
verifyNodeTree(
|
|
10
|
+
node: MaybeNode,
|
|
11
|
+
options?: DiagnosticOptions,
|
|
12
|
+
onProgress?: DiagnosticProgressCallback,
|
|
13
|
+
): AsyncGenerator<DiagnosticResult>;
|
|
14
|
+
verifyPhotosTimeline(
|
|
15
|
+
options?: DiagnosticOptions,
|
|
16
|
+
onProgress?: DiagnosticProgressCallback,
|
|
17
|
+
): AsyncGenerator<DiagnosticResult>;
|
|
7
18
|
}
|
|
8
19
|
|
|
9
20
|
export type DiagnosticOptions = {
|
|
10
|
-
verifyContent?: boolean;
|
|
21
|
+
verifyContent?: boolean | 'peakOnly';
|
|
11
22
|
verifyThumbnails?: boolean;
|
|
12
|
-
expectedStructure?:
|
|
23
|
+
expectedStructure?: ExpectedTreeNode;
|
|
13
24
|
};
|
|
14
25
|
|
|
15
26
|
// Tree structure of the expected node tree.
|
|
16
|
-
export type
|
|
27
|
+
export type ExpectedTreeNode = {
|
|
17
28
|
name: string;
|
|
29
|
+
expectedMediaType?: string;
|
|
18
30
|
expectedSha1?: string;
|
|
19
31
|
expectedSizeInBytes?: number;
|
|
20
|
-
|
|
32
|
+
// If expectedAuthors is provided, it will be used to verify authors.
|
|
33
|
+
// If it's a string, it will be used to verify all authors match the same email.
|
|
34
|
+
// If it's an object, it will be used to verify specific authors by type.
|
|
35
|
+
expectedAuthors?: ExpectedAuthor | { key?: ExpectedAuthor; name?: ExpectedAuthor; content?: ExpectedAuthor };
|
|
36
|
+
children?: ExpectedTreeNode[];
|
|
21
37
|
};
|
|
22
38
|
|
|
39
|
+
export type ExpectedAuthor = string | 'anonymous';
|
|
40
|
+
|
|
41
|
+
export type DiagnosticProgressCallback = (progress: {
|
|
42
|
+
allNodesLoaded: boolean;
|
|
43
|
+
loadedNodes: number;
|
|
44
|
+
checkedNodes: number;
|
|
45
|
+
}) => void;
|
|
46
|
+
|
|
23
47
|
export type DiagnosticResult =
|
|
24
48
|
| FatalErrorResult
|
|
25
49
|
| SdkErrorResult
|
|
@@ -138,7 +162,7 @@ export type ThumbnailsErrorResult = {
|
|
|
138
162
|
// the expected structure.
|
|
139
163
|
export type ExpectedStructureMissingNode = {
|
|
140
164
|
type: 'expected_structure_missing_node';
|
|
141
|
-
expectedNode:
|
|
165
|
+
expectedNode: ExpectedTreeNode;
|
|
142
166
|
parentNodeUid: string;
|
|
143
167
|
};
|
|
144
168
|
|
|
@@ -155,7 +179,7 @@ export type ExpectedStructureUnexpectedNode = {
|
|
|
155
179
|
// the claimed values with the real content.
|
|
156
180
|
export type ExpectedStructureIntegrityError = {
|
|
157
181
|
type: 'expected_structure_integrity_error';
|
|
158
|
-
expectedNode:
|
|
182
|
+
expectedNode: ExpectedTreeNode;
|
|
159
183
|
claimedSha1?: string;
|
|
160
184
|
claimedSizeInBytes?: number;
|
|
161
185
|
} & NodeDetails;
|
|
@@ -181,11 +205,13 @@ export type MetricResult = {
|
|
|
181
205
|
export type NodeDetails = {
|
|
182
206
|
safeNodeDetails: {
|
|
183
207
|
nodeUid: string;
|
|
184
|
-
revisionUid
|
|
208
|
+
revisionUid: string | undefined;
|
|
185
209
|
nodeType: NodeType;
|
|
210
|
+
mediaType: string | undefined;
|
|
186
211
|
nodeCreationTime: Date;
|
|
187
212
|
keyAuthor: Author;
|
|
188
213
|
nameAuthor: Author;
|
|
214
|
+
contentAuthor: Author | undefined;
|
|
189
215
|
errors: {
|
|
190
216
|
field: string;
|
|
191
217
|
error: unknown;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { MaybeNode, NodeType, Revision } from '../interface';
|
|
2
|
+
import {
|
|
3
|
+
NodeDetails,
|
|
4
|
+
ExpectedTreeNode,
|
|
5
|
+
} from './interface';
|
|
6
|
+
|
|
7
|
+
export function getNodeDetails(node: MaybeNode): NodeDetails {
|
|
8
|
+
const errors: {
|
|
9
|
+
field: string;
|
|
10
|
+
error: unknown;
|
|
11
|
+
}[] = [];
|
|
12
|
+
|
|
13
|
+
if (!node.ok) {
|
|
14
|
+
const degradedNode = node.error;
|
|
15
|
+
if (!degradedNode.name.ok) {
|
|
16
|
+
errors.push({
|
|
17
|
+
field: 'name',
|
|
18
|
+
error: degradedNode.name.error,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
if (degradedNode.activeRevision?.ok === false) {
|
|
22
|
+
errors.push({
|
|
23
|
+
field: 'activeRevision',
|
|
24
|
+
error: degradedNode.activeRevision.error,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
for (const error of degradedNode.errors ?? []) {
|
|
28
|
+
if (error instanceof Error) {
|
|
29
|
+
errors.push({
|
|
30
|
+
field: 'error',
|
|
31
|
+
error,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
safeNodeDetails: {
|
|
39
|
+
...getNodeUids(node),
|
|
40
|
+
nodeType: getNodeType(node),
|
|
41
|
+
mediaType: getMediaType(node),
|
|
42
|
+
nodeCreationTime: node.ok ? node.value.creationTime : node.error.creationTime,
|
|
43
|
+
keyAuthor: node.ok ? node.value.keyAuthor : node.error.keyAuthor,
|
|
44
|
+
nameAuthor: node.ok ? node.value.nameAuthor : node.error.nameAuthor,
|
|
45
|
+
contentAuthor: getActiveRevision(node)?.contentAuthor,
|
|
46
|
+
errors,
|
|
47
|
+
},
|
|
48
|
+
sensitiveNodeDetails: node,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function getNodeUids(node: MaybeNode): { nodeUid: string; revisionUid: string | undefined } {
|
|
53
|
+
const activeRevision = getActiveRevision(node);
|
|
54
|
+
return {
|
|
55
|
+
nodeUid: node.ok ? node.value.uid : node.error.uid,
|
|
56
|
+
revisionUid: activeRevision?.uid,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function getNodeType(node: MaybeNode): NodeType {
|
|
61
|
+
return node.ok ? node.value.type : node.error.type;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function getMediaType(node: MaybeNode): string | undefined {
|
|
65
|
+
return node.ok ? node.value.mediaType : node.error.mediaType;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function getActiveRevision(node: MaybeNode): Revision | undefined {
|
|
69
|
+
if (node.ok) {
|
|
70
|
+
return node.value.activeRevision;
|
|
71
|
+
}
|
|
72
|
+
if (node.error.activeRevision?.ok) {
|
|
73
|
+
return node.error.activeRevision.value;
|
|
74
|
+
}
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function getNodeName(node: MaybeNode): string {
|
|
79
|
+
if (node.ok) {
|
|
80
|
+
return node.value.name;
|
|
81
|
+
}
|
|
82
|
+
if (node.error.name.ok) {
|
|
83
|
+
return node.error.name.value;
|
|
84
|
+
}
|
|
85
|
+
return 'N/A';
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function getExpectedTreeNodeDetails(expectedNode: ExpectedTreeNode): ExpectedTreeNode {
|
|
89
|
+
return {
|
|
90
|
+
...expectedNode,
|
|
91
|
+
children: undefined,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function getTreeNodeChildByNodeName(
|
|
96
|
+
expectedSubtree: ExpectedTreeNode | undefined,
|
|
97
|
+
nodeName: string,
|
|
98
|
+
): ExpectedTreeNode | undefined {
|
|
99
|
+
return expectedSubtree?.children?.find((expectedNode) => expectedNode.name === nodeName);
|
|
100
|
+
}
|