@react-native-firebase/storage 17.3.1 → 17.4.0

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,16 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [17.4.0](https://github.com/invertase/react-native-firebase/compare/v17.3.2...v17.4.0) (2023-03-25)
7
+
8
+ ### Features
9
+
10
+ - **storage:** Firebase JS SDK v9 modular API ([#6958](https://github.com/invertase/react-native-firebase/issues/6958)) ([02df92e](https://github.com/invertase/react-native-firebase/commit/02df92e8d76a60e7cfaa80d65d98f4c905a89937))
11
+
12
+ ### [17.3.2](https://github.com/invertase/react-native-firebase/compare/v17.3.1...v17.3.2) (2023-03-05)
13
+
14
+ **Note:** Version bump only for package @react-native-firebase/storage
15
+
6
16
  ### [17.3.1](https://github.com/invertase/react-native-firebase/compare/v17.3.0...v17.3.1) (2023-02-23)
7
17
 
8
18
  **Note:** Version bump only for package @react-native-firebase/storage
package/lib/index.d.ts CHANGED
@@ -924,6 +924,21 @@ export namespace FirebaseStorageTypes {
924
924
  error?: NativeFirebaseError;
925
925
  }
926
926
 
927
+ /**
928
+ * Result returned from a non-resumable upload.
929
+ */
930
+ export interface TaskResult {
931
+ /**
932
+ * The metadata of the tasks via a {@link storage.FullMetadata} interface.
933
+ */
934
+ metadata: FullMetadata;
935
+
936
+ /**
937
+ * The {@link storage.Reference} of the task.
938
+ */
939
+ ref: Reference;
940
+ }
941
+
927
942
  /**
928
943
  * The options `list()` accepts.
929
944
  */
@@ -961,6 +976,16 @@ export namespace FirebaseStorageTypes {
961
976
  prefixes: Reference[];
962
977
  }
963
978
 
979
+ /**
980
+ * Storage Emulator options. Web only.
981
+ */
982
+ export interface EmulatorMockTokenOptions {
983
+ /**
984
+ * the mock auth token to use for unit testing Security Rules.
985
+ */
986
+ mockUserToken?: string;
987
+ }
988
+
964
989
  /**
965
990
  * The Cloud Storage service is available for the default app, a given app or a specific storage bucket.
966
991
  *
package/lib/index.js CHANGED
@@ -26,6 +26,31 @@ import StorageStatics from './StorageStatics';
26
26
  import { getGsUrlParts, getHttpUrlParts, handleStorageEvent } from './utils';
27
27
  import version from './version';
28
28
 
29
+ export {
30
+ getStorage,
31
+ connectStorageEmulator,
32
+ ref,
33
+ deleteObject,
34
+ getBlob,
35
+ getBytes,
36
+ getDownloadURL,
37
+ getMetadata,
38
+ getStream,
39
+ list,
40
+ listAll,
41
+ updateMetadata,
42
+ putFile,
43
+ writeToFile,
44
+ toString,
45
+ child,
46
+ setMaxDownloadRetryTime,
47
+ setMaxOperationRetryTime,
48
+ setMaxUploadRetryTime,
49
+ refFromURL,
50
+ uploadString,
51
+ uploadBytesResumable,
52
+ } from '../modular/index';
53
+
29
54
  const namespace = 'storage';
30
55
  const nativeEvents = ['storage_event'];
31
56
  const nativeModuleName = 'RNFBStorageModule';
package/lib/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // Generated by genversion.
2
- module.exports = '17.3.1';
2
+ module.exports = '17.4.0';
@@ -0,0 +1,268 @@
1
+ /*
2
+ * Copyright (c) 2016-present Invertase Limited & Contributors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this library except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ */
17
+
18
+ import { firebase } from '..';
19
+
20
+ /**
21
+ * Returns a Storage instance for the given app.
22
+ * @param app - FirebaseApp. Optional.
23
+ * @param bucketUrl - Storage bucket URL. Optional.
24
+ * @returns {Storage}
25
+ */
26
+ export function getStorage(app, bucketUrl) {
27
+ if (app) {
28
+ if (bucketUrl != null) {
29
+ return firebase.app(app.name).storage(bucketUrl);
30
+ }
31
+
32
+ return firebase.app(app.name).storage();
33
+ }
34
+
35
+ if (bucketUrl != null) {
36
+ return firebase.app().storage(bucketUrl);
37
+ }
38
+
39
+ return firebase.app().storage();
40
+ }
41
+
42
+ /**
43
+ * Modify this Storage instance to communicate with the Firebase Storage emulator.
44
+ * @param storage - Storage instance.
45
+ * @param host - emulator host (e.g. - 'localhost')
46
+ * @param port - emulator port (e.g. - 9199)
47
+ * @param options - `EmulatorMockTokenOptions` instance. Optional. Web only.
48
+ * @returns {void}
49
+ */
50
+ export function connectStorageEmulator(storage, host, port, options) {
51
+ return storage.useEmulator(host, port, options);
52
+ }
53
+
54
+ /**
55
+ * Modify this Storage instance to communicate with the Firebase Storage emulator.
56
+ * @param storage - Storage instance.
57
+ * @param path An optional string pointing to a location on the storage bucket. If no path
58
+ * is provided, the returned reference will be the bucket root path. Optional.
59
+ * @returns {Storage.Reference}
60
+ */
61
+ export function ref(storage, path) {
62
+ return storage.ref(path);
63
+ }
64
+
65
+ /**
66
+ * Deletes the object at this reference's location.
67
+ * @param storageRef - Storage `Reference` instance.
68
+ * @returns {Promise<void>}
69
+ */
70
+ export function deleteObject(storageRef) {
71
+ return storageRef.delete();
72
+ }
73
+
74
+ /**
75
+ * Downloads the data at the object's location. Returns an error if the object is not found.
76
+ * @param storageRef - Storage `Reference` instance.
77
+ * @returns {Promise<Blob>}
78
+ */
79
+ // eslint-disable-next-line
80
+ export function getBlob(storageRef) {
81
+ throw new Error('`getBlob()` is not implemented');
82
+ }
83
+
84
+ /**
85
+ * Downloads the data at the object's location. Returns an error if the object is not found.
86
+ * @param storageRef - Storage `Reference` instance.
87
+ * @param maxDownloadSizeBytes - The maximum allowed size in bytes to retrieve. Web only.
88
+ * @returns {Promise<ArrayBuffer>}
89
+ */
90
+ // eslint-disable-next-line
91
+ export function getBytes(storageRef, maxDownloadSizeBytes) {
92
+ throw new Error('`getBytes()` is not implemented');
93
+ }
94
+
95
+ /**
96
+ * Deletes the object at this reference's location.
97
+ * @param storageRef - Storage `Reference` instance.
98
+ * @returns {Promise<string>}
99
+ */
100
+ export function getDownloadURL(storageRef) {
101
+ return storageRef.getDownloadURL();
102
+ }
103
+
104
+ /**
105
+ * Fetches metadata for the object at this location, if one exists.
106
+ * @param storageRef - Storage `Reference` instance.
107
+ * @returns {Promise<FullMetadata>}
108
+ */
109
+ export function getMetadata(storageRef) {
110
+ return storageRef.getMetadata();
111
+ }
112
+
113
+ /**
114
+ * Downloads the data at the object's location. This API is only available in Nodejs.
115
+ * @param storageRef - Storage `Reference` instance.
116
+ * @param maxDownloadSizeBytes - The maximum allowed size in bytes to retrieve. Web only.
117
+ * @returns {NodeJS.ReadableStream;}
118
+ */
119
+ // eslint-disable-next-line
120
+ export function getStream(storageRef, maxDownloadSizeBytes) {
121
+ throw new Error('`getStream()` is not implemented');
122
+ }
123
+
124
+ /**
125
+ * List items (files) and prefixes (folders) under this storage reference
126
+ * @param storageRef - Storage `Reference` instance.
127
+ * @param options - Storage `ListOptions` instance. The options list() accepts.
128
+ * @returns {Promise<ListResult>}
129
+ */
130
+ export function list(storageRef, options) {
131
+ return storageRef.list(options);
132
+ }
133
+
134
+ /**
135
+ * List all items (files) and prefixes (folders) under this storage reference.
136
+ * @param storageRef - Storage `Reference` instance.
137
+ * @returns {Promise<ListResult>}
138
+ */
139
+ export function listAll(storageRef) {
140
+ return storageRef.listAll();
141
+ }
142
+
143
+ /**
144
+ * Updates the metadata for this object.
145
+ * @param storageRef - Storage `Reference` instance.
146
+ * @param metadata - A Storage `SettableMetadata` instance to update.
147
+ * @returns {Promise<FullMetadata>}
148
+ */
149
+ export function updateMetadata(storageRef, metadata) {
150
+ return storageRef.updateMetadata(metadata);
151
+ }
152
+
153
+ /**
154
+ * Uploads data to this object's location. The upload is not resumable.
155
+ * @param storageRef - Storage `Reference` instance.
156
+ * @param data - The data (Blob | Uint8Array | ArrayBuffer) to upload to the storage bucket at the reference location.
157
+ * @param metadata - A Storage `SettableMetadata` instance to update. Optional.
158
+ * @returns {Promise<TaskResult>}
159
+ */
160
+ // eslint-disable-next-line
161
+ export async function uploadBytes(storageRef, data, metadata) {
162
+ throw new Error('`uploadBytes()` is not implemented');
163
+ }
164
+
165
+ /**
166
+ * Uploads data to this object's location. The upload is not resumable.
167
+ * @param storageRef - Storage `Reference` instance.
168
+ * @param data - The data (Blob | Uint8Array | ArrayBuffer) to upload to the storage bucket at the reference location.
169
+ * @param metadata - A Storage `SettableMetadata` instance to update. Optional.
170
+ * @returns {Task}
171
+ */
172
+ export function uploadBytesResumable(storageRef, data, metadata) {
173
+ return storageRef.put(data, metadata);
174
+ }
175
+
176
+ /**
177
+ * Uploads data to this object's location. The upload is not resumable.
178
+ * @param storageRef - Storage `Reference` instance.
179
+ * @param value - The string to upload.
180
+ * @param format - The format of the string to upload ('raw' | 'base64' | 'base64url' | 'data_url'). Optional.
181
+ * @param metadata - A Storage `SettableMetadata` instance to update. Optional.
182
+ * @returns {Task}
183
+ */
184
+ export function uploadString(storageRef, data, format, metadata) {
185
+ return storageRef.putString(data, format, metadata);
186
+ }
187
+
188
+ // Methods not on the Firebase JS SDK below
189
+
190
+ /**
191
+ * Returns a new Storage `Reference` instance from a storage bucket URL.
192
+ * @param storage - Storage instance.
193
+ * @param url - A storage bucket URL pointing to a single file or location. Must be either a `gs://` url or an `http` url. Not available on web.
194
+ * @returns {Reference}
195
+ */
196
+ export function refFromURL(storage, url) {
197
+ return storage.refFromURL(url);
198
+ }
199
+
200
+ /**
201
+ * Sets the maximum time in milliseconds to retry a download if a failure occurs.. android & iOS only.
202
+ * @param storage - Storage instance.
203
+ * @param time - The new maximum operation retry time in milliseconds.
204
+ * @returns {Promise<void>}
205
+ */
206
+ export function setMaxOperationRetryTime(storage, time) {
207
+ return storage.setMaxOperationRetryTime(time);
208
+ }
209
+
210
+ /**
211
+ * Sets the maximum time in milliseconds to retry an upload if a failure occurs. android & iOS only.
212
+ * @param storage - Storage instance.
213
+ * @param time - The new maximum operation retry time in milliseconds.
214
+ * @returns {Promise<void>}
215
+ */
216
+ export function setMaxUploadRetryTime(storage, time) {
217
+ return storage.setMaxUploadRetryTime(time);
218
+ }
219
+
220
+ /**
221
+ * Puts a file from local disk onto the storage bucket.
222
+ * @param storageRef - Storage Reference instance.
223
+ * @param localFilePath The local file path to upload to the bucket at the reference location.
224
+ * @param metadata Any additional `SettableMetadata` for this task.
225
+ * @returns {Task}
226
+ */
227
+ export function putFile(storageRef, filePath, metadata) {
228
+ return storageRef.putFile(filePath, metadata);
229
+ }
230
+
231
+ /**
232
+ * Downloads a file to the specified local file path on the device.
233
+ * @param storageRef - Storage Reference instance.
234
+ * @param localFilePath The local file path to upload to on the device.
235
+ * @returns {Task}
236
+ */
237
+ export function writeToFile(storageRef, filePath) {
238
+ return storageRef.writeToFile(filePath);
239
+ }
240
+
241
+ /**
242
+ * Returns a gs:// URL for this object in the form `gs://<bucket>/<path>/<to>/<object>`.
243
+ * @param storageRef - Storage Reference instance.
244
+ * @returns {String}
245
+ */
246
+ export function toString(storageRef) {
247
+ return storageRef.toString();
248
+ }
249
+
250
+ /**
251
+ * Returns a reference to a relative path from this reference.
252
+ * @param storageRef - Storage Reference instance.
253
+ * @param path - The relative path from this reference. Leading, trailing, and consecutive slashes are removed.
254
+ * @returns {String}
255
+ */
256
+ export function child(storageRef, path) {
257
+ return storageRef.child(path);
258
+ }
259
+
260
+ /**
261
+ * Sets the maximum time in milliseconds to retry a download if a failure occurs.
262
+ * @param storage - Storage instance.
263
+ * @param time - The new maximum download retry time in milliseconds.
264
+ * @returns {Promise<void>}
265
+ */
266
+ export function setMaxDownloadRetryTime(storage, time) {
267
+ return storage.setMaxDownloadRetryTime(time);
268
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native-firebase/storage",
3
- "version": "17.3.1",
3
+ "version": "17.4.0",
4
4
  "author": "Invertase <oss@invertase.io> (http://invertase.io)",
5
5
  "description": "React Native Firebase - React Native Firebase provides native integration with Cloud Storage, providing support to upload and download files directly from your device and from your Firebase Cloud Storage bucket.",
6
6
  "main": "lib/index.js",
@@ -29,10 +29,10 @@
29
29
  "download"
30
30
  ],
31
31
  "peerDependencies": {
32
- "@react-native-firebase/app": "17.3.1"
32
+ "@react-native-firebase/app": "17.4.0"
33
33
  },
34
34
  "publishConfig": {
35
35
  "access": "public"
36
36
  },
37
- "gitHead": "8c57bbb3d9c397fc472b78e9853b671ed41e30ca"
37
+ "gitHead": "2a79509bb34278bf9919aceeb58a6ef74ab36520"
38
38
  }