dwh-fetch 1.3.3

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.
@@ -0,0 +1,149 @@
1
+ /// <reference types="node" />
2
+ import superagent from 'superagent';
3
+ import { Logger } from 'tslog';
4
+ export declare const VALUE_ERROR_MASK = 4294967232;
5
+ export declare const WEB_BUS_PIN_ERR = 2147483648;
6
+ export declare function isErrorValue(val: any): boolean;
7
+ export declare function isValidValue(val: any): boolean;
8
+ export interface FileInfo {
9
+ directory: string;
10
+ name: string;
11
+ filePath: string;
12
+ size: number;
13
+ lastModified: Date;
14
+ isDirectory: boolean;
15
+ isReadOnly: boolean;
16
+ }
17
+ export declare type DownloadFileOptions = {
18
+ /**
19
+ * if set to true, the parameter RAW=1 will be added to the downloaded path
20
+ * For a digiweb that means all interpretations on this file will be disabled
21
+ * with this you can get a .req files source code instead of the executed result
22
+ *
23
+ * Defaults to true
24
+ */
25
+ raw: boolean;
26
+ };
27
+ /**
28
+ * Parses 'Dec 18 2020' or 'Apr 13 14:25' to valid JavaScript date objects.
29
+ * @param dateTime Date time string returned from '##GETDIRLINE()'.
30
+ * @returns Date object or throws error.
31
+ */
32
+ export declare function parseTimeString(timeString: string): Date;
33
+ export declare function parseFileInfoOrThrow(directory: string, line: string): FileInfo;
34
+ export declare function parseFileInfo(directory: string, line: string): FileInfo | undefined;
35
+ export declare class DwhLine {
36
+ value: string;
37
+ success: boolean;
38
+ expression: string;
39
+ constructor(value: string, success?: boolean, expression?: string);
40
+ static fromString(line: string, expression?: string): DwhLine;
41
+ toInt(): number;
42
+ }
43
+ export declare class DwhResponse {
44
+ accessRights: number;
45
+ lines: DwhLine[];
46
+ constructor(accessRights?: number, lines?: DwhLine[]);
47
+ }
48
+ export interface DwhFetchOptions {
49
+ authFallbackHandler?: (dwh: DwhFetch) => Promise<void>;
50
+ log?: Logger;
51
+ /**
52
+ * Timeout in milliseconds. If no timeout is set superagent will wait for response forever:
53
+ * https://github.com/visionmedia/superagent/issues/17#issuecomment-207742985
54
+ */
55
+ timeoutResponse?: number;
56
+ /**
57
+ * Timeout for max running response e.G when download takes to long it will abort after deadline time.
58
+ */
59
+ timeoutDeadline?: number;
60
+ /**
61
+ * Passing RSA keys via constructor options.
62
+ */
63
+ rsaKeys?: string;
64
+ /**
65
+ * these headers will be passed to every request
66
+ */
67
+ headers?: {
68
+ [P: string]: string;
69
+ };
70
+ }
71
+ export declare class DwhFetch {
72
+ private options?;
73
+ static readonly DEFAULT_TIMEOUT_RESPONSE = 7000;
74
+ static readonly DEFAULT_TIMEOUT_DEADLINE: number;
75
+ private headers;
76
+ url: string;
77
+ authorityToken: number;
78
+ currentlyHandlingAuthFailure: boolean;
79
+ rsaKeys: string;
80
+ constructor(url?: string, options?: DwhFetchOptions | undefined);
81
+ private removeDwhFile;
82
+ createPostBody(expressions: string[]): string;
83
+ isMultiLineRequest(expression: string): boolean;
84
+ toIntOrThrow(str: string): number;
85
+ parseBody(expressions: string[], body: string): DwhResponse;
86
+ dwhUrl(): string;
87
+ fetchOrThrow(expressions: string[]): Promise<DwhResponse>;
88
+ responseToText(response: superagent.Response): string;
89
+ fetch(expressions: string[]): Promise<DwhResponse>;
90
+ sendPostBodyOrThrow(postBody: string): Promise<string>;
91
+ isAuthFailure(result: DwhResponse): boolean;
92
+ fetchRsa(): Promise<string | undefined>;
93
+ initRsa(): Promise<void>;
94
+ fetchString(expression: string): Promise<string | undefined>;
95
+ fetchStringOrThrow(expression: string): Promise<string>;
96
+ wrapDefault<T>(call: () => Promise<T>, defaultValueOnFailure: T): Promise<T>;
97
+ fetchNumber(expression: string): Promise<number | undefined>;
98
+ throwFailure(lineWithError: DwhLine): void;
99
+ fetchNumberOrThrow(expression: string): Promise<number>;
100
+ login(user: string, password: string): Promise<boolean>;
101
+ setAuthorityToken(token: number): void;
102
+ logout(): Promise<boolean>;
103
+ private isErrorInMultiLineResult;
104
+ private getErrorCodeOfGResult;
105
+ private decodeBackdoorKey;
106
+ executePostAndReturnFirstLine(requestBody: string): Promise<string>;
107
+ useBackdoor(): Promise<boolean>;
108
+ getCurrentRights(): Promise<number>;
109
+ hasError(result: DwhResponse): boolean;
110
+ throwOnError(result: DwhResponse): void;
111
+ fetchDirectoryLines(pathWithPattern: string, options?: {
112
+ startLines?: number;
113
+ }): Promise<string[]>;
114
+ files(pathWithPattern: string, options?: {
115
+ startLines?: number;
116
+ }): Promise<FileInfo[]>;
117
+ uploadFile(path: string, content: Buffer | Blob): Promise<boolean>;
118
+ downloadFile(path: string, options?: DownloadFileOptions): superagent.Request;
119
+ private createFileUrl;
120
+ downloadFileAsString(path: string, options?: DownloadFileOptions): Promise<string>;
121
+ mkdir(path: string): Promise<boolean>;
122
+ /**
123
+ * Removes an EMPTY directory from digiweb.
124
+ * @param path empty directory to remove
125
+ * @returns 0 when success.
126
+ */
127
+ removeDir(path: string): Promise<boolean>;
128
+ /**
129
+ * Removes directory recursive. Aborts when error occur
130
+ * trying to delete file or directory inside path.
131
+ * @param path directory to remove
132
+ * @returns 0 when success.
133
+ */
134
+ removeDirRecursively(path: string): Promise<boolean>;
135
+ deleteFile(file: string): Promise<boolean>;
136
+ getFileInfo(file: string): Promise<FileInfo | undefined>;
137
+ exists(digiwebFilename: string): Promise<boolean>;
138
+ isFile(digiwebFilename: string): Promise<boolean>;
139
+ isDirectory(digiwebFilename: string): Promise<boolean>;
140
+ restart(): Promise<void>;
141
+ /**
142
+ * Creates timeout for superagent.
143
+ * @returns timeout in ms.
144
+ */
145
+ getTimeout(): {
146
+ deadline: number;
147
+ response: number;
148
+ };
149
+ }