Skip to content

Commit 11fdb8b

Browse files
authored
feat: add index.d.ts file with Typescript bindings (#182)
1 parent 1f542a5 commit 11fdb8b

File tree

1 file changed

+116
-0
lines changed

1 file changed

+116
-0
lines changed

index.d.ts

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
declare module "react-native-background-upload" {
2+
3+
export interface EventData {
4+
id: string;
5+
}
6+
7+
export interface ProgressData extends EventData {
8+
progress: number
9+
}
10+
11+
export interface ErrorData extends EventData {
12+
error: string
13+
}
14+
15+
export interface CompletedData extends EventData {
16+
17+
responseCode: string
18+
responseBody: string
19+
}
20+
export type FileInfo = {
21+
name: string
22+
exists: boolean
23+
size?: number
24+
extension?: string
25+
mimeType?: string
26+
}
27+
28+
29+
export type NotificationOptions = {
30+
/**
31+
* Enable or diasable notifications. Works only on Android version < 8.0 Oreo. On Android versions >= 8.0 Oreo is required by Google's policy to display a notification when a background service run { enabled: true }
32+
*/
33+
enabled: boolean
34+
/**
35+
* Autoclear notification on complete { autoclear: true }
36+
*/
37+
autoClear: boolean
38+
/**
39+
* Sets android notificaion channel { notificationChannel: "My-Upload-Service" }
40+
*/
41+
notificationChannel: string
42+
/**
43+
* Sets whether or not to enable the notification sound when the upload gets completed with success or error { enableRingTone: true }
44+
*/
45+
enableRingTone: boolean
46+
/**
47+
* Sets notification progress title { onProgressTitle: "Uploading" }
48+
*/
49+
onProgressTitle: string
50+
/**
51+
* Sets notification progress message { onProgressMessage: "Uploading new video" }
52+
*/
53+
onProgressMessage: string
54+
/**
55+
* Sets notification complete title { onCompleteTitle: "Upload finished" }
56+
*/
57+
onCompleteTitle: string
58+
/**
59+
* Sets notification complete message { onCompleteMessage: "Your video has been uploaded" }
60+
*/
61+
onCompleteMessage: string
62+
/**
63+
* Sets notification error title { onErrorTitle: "Upload error" }
64+
*/
65+
onErrorTitle: string
66+
/**
67+
* Sets notification error message { onErrorMessage: "An error occured while uploading a video" }
68+
*/
69+
onErrorMessage: string
70+
/**
71+
* Sets notification cancelled title { onCancelledTitle: "Upload cancelled" }
72+
*/
73+
onCancelledTitle: string
74+
/**
75+
* Sets notification cancelled message { onCancelledMessage: "Video upload was cancelled" }
76+
*/
77+
onCancelledMessage: string
78+
}
79+
80+
export interface UploadOptions {
81+
url: string;
82+
path: string;
83+
type?: 'raw' | 'multipart';
84+
method?: 'POST' | 'GET' | 'PUT' | 'PATCH' | 'DELETE';
85+
customUploadId?: string;
86+
headers?: {
87+
[index: string]: string
88+
};
89+
// Android notification settings
90+
notification?: Partial<NotificationOptions>
91+
}
92+
93+
export interface MultipartUploadOptions extends UploadOptions {
94+
type: 'multipart'
95+
field: string
96+
parameters?: {
97+
[index: string]: string
98+
}
99+
}
100+
101+
type uploadId = string
102+
103+
export type UploadListenerEvent = 'progress' | 'error' | 'completed' | 'cancelled'
104+
105+
export default class Upload {
106+
static startUpload(options: UploadOptions): Promise<uploadId>
107+
static addListener(event: UploadListenerEvent, uploadId: uploadId, data: object): void
108+
static addListener(event: 'progress', uploadId: uploadId, data: ProgressData): void
109+
static addListener(event: 'error', uploadId: uploadId, data: ErrorData): void
110+
static addListener(event: 'completed', uploadId: uploadId, data: CompletedData): void
111+
static addListener(event: 'cancelled', uploadId: uploadId, data: EventData): void
112+
static getFileInfo(path: string): Promise<FileInfo>
113+
static cancelUpload(uploadId: uploadId): Promise<boolean>
114+
}
115+
116+
}

0 commit comments

Comments
 (0)