@hot-updater/firebase 0.28.0 → 0.29.0

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/index.cjs CHANGED
@@ -1,4 +1,5 @@
1
- //#region rolldown:runtime
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region \0rolldown/runtime.js
2
3
  var __create = Object.create;
3
4
  var __defProp = Object.defineProperty;
4
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -19,18 +20,40 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
19
20
  value: mod,
20
21
  enumerable: true
21
22
  }) : target, mod));
22
-
23
23
  //#endregion
24
- let __hot_updater_plugin_core = require("@hot-updater/plugin-core");
25
- __hot_updater_plugin_core = __toESM(__hot_updater_plugin_core);
24
+ let _hot_updater_core = require("@hot-updater/core");
25
+ let _hot_updater_plugin_core = require("@hot-updater/plugin-core");
26
26
  let firebase_admin = require("firebase-admin");
27
27
  firebase_admin = __toESM(firebase_admin);
28
28
  let fs_promises = require("fs/promises");
29
29
  fs_promises = __toESM(fs_promises);
30
30
  let path = require("path");
31
31
  path = __toESM(path);
32
-
33
32
  //#region src/firebaseDatabase.ts
33
+ const bundleMatchesQueryWhere = (bundle, where) => {
34
+ if (!where) return true;
35
+ if (where.channel !== void 0 && bundle.channel !== where.channel) return false;
36
+ if (where.platform !== void 0 && bundle.platform !== where.platform) return false;
37
+ if (where.enabled !== void 0 && bundle.enabled !== where.enabled) return false;
38
+ if (where.id?.eq !== void 0 && bundle.id !== where.id.eq) return false;
39
+ if (where.id?.gt !== void 0 && bundle.id.localeCompare(where.id.gt) <= 0) return false;
40
+ if (where.id?.gte !== void 0 && bundle.id.localeCompare(where.id.gte) < 0) return false;
41
+ if (where.id?.lt !== void 0 && bundle.id.localeCompare(where.id.lt) >= 0) return false;
42
+ if (where.id?.lte !== void 0 && bundle.id.localeCompare(where.id.lte) > 0) return false;
43
+ if (where.id?.in && !where.id.in.includes(bundle.id)) return false;
44
+ if (where.targetAppVersionNotNull && bundle.targetAppVersion === null) return false;
45
+ if (where.targetAppVersion !== void 0 && bundle.targetAppVersion !== where.targetAppVersion) return false;
46
+ if (where.targetAppVersionIn && !where.targetAppVersionIn.includes(bundle.targetAppVersion ?? "")) return false;
47
+ if (where.fingerprintHash !== void 0 && bundle.fingerprintHash !== where.fingerprintHash) return false;
48
+ return true;
49
+ };
50
+ const sortBundles = (bundles, orderBy) => {
51
+ const direction = orderBy?.direction ?? "desc";
52
+ return bundles.slice().sort((a, b) => {
53
+ const result = a.id.localeCompare(b.id);
54
+ return direction === "asc" ? result : -result;
55
+ });
56
+ };
34
57
  const convertToBundle = (firestoreData) => ({
35
58
  channel: firestoreData.channel,
36
59
  enabled: Boolean(firestoreData.enabled),
@@ -43,19 +66,21 @@ const convertToBundle = (firestoreData) => ({
43
66
  targetAppVersion: firestoreData.target_app_version,
44
67
  storageUri: firestoreData.storage_uri,
45
68
  fingerprintHash: firestoreData.fingerprint_hash,
46
- metadata: firestoreData?.metadata ?? {}
69
+ metadata: firestoreData?.metadata ?? {},
70
+ rolloutCohortCount: firestoreData.rollout_cohort_count ?? _hot_updater_core.DEFAULT_ROLLOUT_COHORT_COUNT,
71
+ targetCohorts: firestoreData.target_cohorts ?? null
47
72
  });
48
- const firebaseDatabase = (0, __hot_updater_plugin_core.createDatabasePlugin)({
73
+ const firebaseDatabase = (0, _hot_updater_plugin_core.createDatabasePlugin)({
49
74
  name: "firebaseDatabase",
50
75
  factory: (config) => {
51
76
  let bundles = [];
52
77
  let app;
53
78
  try {
54
- app = firebase_admin.app();
79
+ app = firebase_admin.default.app();
55
80
  } catch {
56
- app = firebase_admin.initializeApp(config);
81
+ app = firebase_admin.default.initializeApp(config);
57
82
  }
58
- const db = firebase_admin.firestore(app);
83
+ const db = firebase_admin.default.firestore(app);
59
84
  const bundlesCollection = db.collection("bundles");
60
85
  return {
61
86
  async getBundleById(bundleId) {
@@ -66,18 +91,26 @@ const firebaseDatabase = (0, __hot_updater_plugin_core.createDatabasePlugin)({
66
91
  return convertToBundle(bundleSnap.data());
67
92
  },
68
93
  async getBundles(options) {
69
- const { where, limit, offset } = options;
94
+ const { where, limit, offset, orderBy } = options;
70
95
  let query = bundlesCollection;
71
96
  if (where?.channel) query = query.where("channel", "==", where.channel);
72
97
  if (where?.platform) query = query.where("platform", "==", where.platform);
73
- query = query.orderBy("id", "desc");
98
+ if (where?.enabled !== void 0) query = query.where("enabled", "==", where.enabled);
99
+ if (where?.fingerprintHash !== void 0 && where.fingerprintHash !== null) query = query.where("fingerprint_hash", "==", where.fingerprintHash);
100
+ if (where?.targetAppVersion !== void 0 && where.targetAppVersion !== null) query = query.where("target_app_version", "==", where.targetAppVersion);
101
+ if (where?.id?.eq) query = query.where("id", "==", where.id.eq);
102
+ if (where?.id?.gt) query = query.where("id", ">", where.id.gt);
103
+ if (where?.id?.gte) query = query.where("id", ">=", where.id.gte);
104
+ if (where?.id?.lt) query = query.where("id", "<", where.id.lt);
105
+ if (where?.id?.lte) query = query.where("id", "<=", where.id.lte);
106
+ query = query.orderBy("id", orderBy?.direction === "asc" ? "asc" : "desc");
74
107
  const total = (await query.get()).size;
75
108
  if (offset > 0) query = query.offset(offset);
76
109
  if (limit) query = query.limit(limit);
77
- bundles = (await query.get()).docs.map((doc) => convertToBundle(doc.data()));
110
+ bundles = sortBundles((await query.get()).docs.map((doc) => convertToBundle(doc.data())).filter((bundle) => bundleMatchesQueryWhere(bundle, where)), orderBy);
78
111
  return {
79
112
  data: bundles,
80
- pagination: (0, __hot_updater_plugin_core.calculatePagination)(total, {
113
+ pagination: (0, _hot_updater_plugin_core.calculatePagination)(total, {
81
114
  limit,
82
115
  offset
83
116
  })
@@ -118,7 +151,9 @@ const firebaseDatabase = (0, __hot_updater_plugin_core.createDatabasePlugin)({
118
151
  target_app_version: data.targetAppVersion,
119
152
  storage_uri: data.storageUri,
120
153
  fingerprint_hash: data.fingerprintHash,
121
- metadata: data.metadata ?? {}
154
+ metadata: data.metadata ?? {},
155
+ rollout_cohort_count: data.rolloutCohortCount ?? _hot_updater_core.DEFAULT_ROLLOUT_COHORT_COUNT,
156
+ target_cohorts: data.targetCohorts ?? null
122
157
  };
123
158
  const channelRef = db.collection("channels").doc(data.channel);
124
159
  transaction.set(channelRef, { name: data.channel }, { merge: true });
@@ -153,7 +188,9 @@ const firebaseDatabase = (0, __hot_updater_plugin_core.createDatabasePlugin)({
153
188
  target_app_version: data.targetAppVersion || null,
154
189
  storage_uri: data.storageUri,
155
190
  fingerprint_hash: data.fingerprintHash,
156
- metadata: data.metadata ?? {}
191
+ metadata: data.metadata ?? {},
192
+ rollout_cohort_count: data.rolloutCohortCount ?? _hot_updater_core.DEFAULT_ROLLOUT_COHORT_COUNT,
193
+ target_cohorts: data.targetCohorts ?? null
157
194
  }, { merge: true });
158
195
  if (data.targetAppVersion) {
159
196
  const versionDocId = `${data.platform}_${data.channel}_${data.targetAppVersion}`;
@@ -176,24 +213,23 @@ const firebaseDatabase = (0, __hot_updater_plugin_core.createDatabasePlugin)({
176
213
  };
177
214
  }
178
215
  });
179
-
180
216
  //#endregion
181
217
  //#region src/firebaseStorage.ts
182
- const firebaseStorage = (0, __hot_updater_plugin_core.createStoragePlugin)({
218
+ const firebaseStorage = (0, _hot_updater_plugin_core.createStoragePlugin)({
183
219
  name: "firebaseStorage",
184
220
  supportedProtocol: "gs",
185
221
  factory: (config) => {
186
222
  let app;
187
223
  try {
188
- app = firebase_admin.app();
224
+ app = firebase_admin.default.app();
189
225
  } catch {
190
- app = firebase_admin.initializeApp(config);
226
+ app = firebase_admin.default.initializeApp(config);
191
227
  }
192
228
  const bucket = app.storage().bucket(config.storageBucket);
193
- const getStorageKey = (0, __hot_updater_plugin_core.createStorageKeyBuilder)(config.basePath);
229
+ const getStorageKey = (0, _hot_updater_plugin_core.createStorageKeyBuilder)(config.basePath);
194
230
  return {
195
231
  async delete(storageUri) {
196
- const { bucket: bucketName, key } = (0, __hot_updater_plugin_core.parseStorageUri)(storageUri, "gs");
232
+ const { bucket: bucketName, key } = (0, _hot_updater_plugin_core.parseStorageUri)(storageUri, "gs");
197
233
  if (bucketName !== config.storageBucket) throw new Error(`Bucket name mismatch: expected "${config.storageBucket}", but found "${bucketName}".`);
198
234
  try {
199
235
  const [files] = await bucket.getFiles({ prefix: key });
@@ -206,7 +242,7 @@ const firebaseStorage = (0, __hot_updater_plugin_core.createStoragePlugin)({
206
242
  async upload(key, filePath) {
207
243
  try {
208
244
  const fileContent = await fs_promises.default.readFile(filePath);
209
- const contentType = (0, __hot_updater_plugin_core.getContentType)(filePath);
245
+ const contentType = (0, _hot_updater_plugin_core.getContentType)(filePath);
210
246
  const storageKey = getStorageKey(key, path.default.basename(filePath));
211
247
  await bucket.file(storageKey).save(fileContent, { metadata: {
212
248
  contentType,
@@ -234,7 +270,6 @@ const firebaseStorage = (0, __hot_updater_plugin_core.createStoragePlugin)({
234
270
  };
235
271
  }
236
272
  });
237
-
238
273
  //#endregion
239
274
  exports.firebaseDatabase = firebaseDatabase;
240
- exports.firebaseStorage = firebaseStorage;
275
+ exports.firebaseStorage = firebaseStorage;
package/dist/index.d.cts CHANGED
@@ -1,8 +1,8 @@
1
- import * as _hot_updater_plugin_core1 from "@hot-updater/plugin-core";
2
- import * as admin from "firebase-admin";
1
+ import * as _$_hot_updater_plugin_core0 from "@hot-updater/plugin-core";
2
+ import admin from "firebase-admin";
3
3
 
4
4
  //#region src/firebaseDatabase.d.ts
5
- declare const firebaseDatabase: (config: admin.AppOptions, hooks?: _hot_updater_plugin_core1.DatabasePluginHooks) => (() => _hot_updater_plugin_core1.DatabasePlugin);
5
+ declare const firebaseDatabase: (config: admin.AppOptions, hooks?: _$_hot_updater_plugin_core0.DatabasePluginHooks) => () => _$_hot_updater_plugin_core0.DatabasePlugin<unknown>;
6
6
  //#endregion
7
7
  //#region src/firebaseStorage.d.ts
8
8
  interface FirebaseStorageConfig extends admin.AppOptions {
@@ -12,6 +12,6 @@ interface FirebaseStorageConfig extends admin.AppOptions {
12
12
  */
13
13
  basePath?: string;
14
14
  }
15
- declare const firebaseStorage: (config: FirebaseStorageConfig, hooks?: _hot_updater_plugin_core1.StoragePluginHooks) => () => _hot_updater_plugin_core1.StoragePlugin;
15
+ declare const firebaseStorage: (config: FirebaseStorageConfig, hooks?: _$_hot_updater_plugin_core0.StoragePluginHooks) => () => _$_hot_updater_plugin_core0.StoragePlugin<unknown>;
16
16
  //#endregion
17
17
  export { FirebaseStorageConfig, firebaseDatabase, firebaseStorage };
@@ -1,8 +1,8 @@
1
- import * as _hot_updater_plugin_core1 from "@hot-updater/plugin-core";
2
- import * as admin from "firebase-admin";
1
+ import * as _$_hot_updater_plugin_core0 from "@hot-updater/plugin-core";
2
+ import admin from "firebase-admin";
3
3
 
4
4
  //#region src/firebaseDatabase.d.ts
5
- declare const firebaseDatabase: (config: admin.AppOptions, hooks?: _hot_updater_plugin_core1.DatabasePluginHooks) => (() => _hot_updater_plugin_core1.DatabasePlugin);
5
+ declare const firebaseDatabase: (config: admin.AppOptions, hooks?: _$_hot_updater_plugin_core0.DatabasePluginHooks) => () => _$_hot_updater_plugin_core0.DatabasePlugin<unknown>;
6
6
  //#endregion
7
7
  //#region src/firebaseStorage.d.ts
8
8
  interface FirebaseStorageConfig extends admin.AppOptions {
@@ -12,6 +12,6 @@ interface FirebaseStorageConfig extends admin.AppOptions {
12
12
  */
13
13
  basePath?: string;
14
14
  }
15
- declare const firebaseStorage: (config: FirebaseStorageConfig, hooks?: _hot_updater_plugin_core1.StoragePluginHooks) => () => _hot_updater_plugin_core1.StoragePlugin;
15
+ declare const firebaseStorage: (config: FirebaseStorageConfig, hooks?: _$_hot_updater_plugin_core0.StoragePluginHooks) => () => _$_hot_updater_plugin_core0.StoragePlugin<unknown>;
16
16
  //#endregion
17
17
  export { FirebaseStorageConfig, firebaseDatabase, firebaseStorage };
@@ -1,9 +1,33 @@
1
+ import { DEFAULT_ROLLOUT_COHORT_COUNT } from "@hot-updater/core";
1
2
  import { calculatePagination, createDatabasePlugin, createStorageKeyBuilder, createStoragePlugin, getContentType, parseStorageUri } from "@hot-updater/plugin-core";
2
- import * as admin from "firebase-admin";
3
+ import admin from "firebase-admin";
3
4
  import fs from "fs/promises";
4
5
  import path from "path";
5
-
6
6
  //#region src/firebaseDatabase.ts
7
+ const bundleMatchesQueryWhere = (bundle, where) => {
8
+ if (!where) return true;
9
+ if (where.channel !== void 0 && bundle.channel !== where.channel) return false;
10
+ if (where.platform !== void 0 && bundle.platform !== where.platform) return false;
11
+ if (where.enabled !== void 0 && bundle.enabled !== where.enabled) return false;
12
+ if (where.id?.eq !== void 0 && bundle.id !== where.id.eq) return false;
13
+ if (where.id?.gt !== void 0 && bundle.id.localeCompare(where.id.gt) <= 0) return false;
14
+ if (where.id?.gte !== void 0 && bundle.id.localeCompare(where.id.gte) < 0) return false;
15
+ if (where.id?.lt !== void 0 && bundle.id.localeCompare(where.id.lt) >= 0) return false;
16
+ if (where.id?.lte !== void 0 && bundle.id.localeCompare(where.id.lte) > 0) return false;
17
+ if (where.id?.in && !where.id.in.includes(bundle.id)) return false;
18
+ if (where.targetAppVersionNotNull && bundle.targetAppVersion === null) return false;
19
+ if (where.targetAppVersion !== void 0 && bundle.targetAppVersion !== where.targetAppVersion) return false;
20
+ if (where.targetAppVersionIn && !where.targetAppVersionIn.includes(bundle.targetAppVersion ?? "")) return false;
21
+ if (where.fingerprintHash !== void 0 && bundle.fingerprintHash !== where.fingerprintHash) return false;
22
+ return true;
23
+ };
24
+ const sortBundles = (bundles, orderBy) => {
25
+ const direction = orderBy?.direction ?? "desc";
26
+ return bundles.slice().sort((a, b) => {
27
+ const result = a.id.localeCompare(b.id);
28
+ return direction === "asc" ? result : -result;
29
+ });
30
+ };
7
31
  const convertToBundle = (firestoreData) => ({
8
32
  channel: firestoreData.channel,
9
33
  enabled: Boolean(firestoreData.enabled),
@@ -16,7 +40,9 @@ const convertToBundle = (firestoreData) => ({
16
40
  targetAppVersion: firestoreData.target_app_version,
17
41
  storageUri: firestoreData.storage_uri,
18
42
  fingerprintHash: firestoreData.fingerprint_hash,
19
- metadata: firestoreData?.metadata ?? {}
43
+ metadata: firestoreData?.metadata ?? {},
44
+ rolloutCohortCount: firestoreData.rollout_cohort_count ?? DEFAULT_ROLLOUT_COHORT_COUNT,
45
+ targetCohorts: firestoreData.target_cohorts ?? null
20
46
  });
21
47
  const firebaseDatabase = createDatabasePlugin({
22
48
  name: "firebaseDatabase",
@@ -39,15 +65,23 @@ const firebaseDatabase = createDatabasePlugin({
39
65
  return convertToBundle(bundleSnap.data());
40
66
  },
41
67
  async getBundles(options) {
42
- const { where, limit, offset } = options;
68
+ const { where, limit, offset, orderBy } = options;
43
69
  let query = bundlesCollection;
44
70
  if (where?.channel) query = query.where("channel", "==", where.channel);
45
71
  if (where?.platform) query = query.where("platform", "==", where.platform);
46
- query = query.orderBy("id", "desc");
72
+ if (where?.enabled !== void 0) query = query.where("enabled", "==", where.enabled);
73
+ if (where?.fingerprintHash !== void 0 && where.fingerprintHash !== null) query = query.where("fingerprint_hash", "==", where.fingerprintHash);
74
+ if (where?.targetAppVersion !== void 0 && where.targetAppVersion !== null) query = query.where("target_app_version", "==", where.targetAppVersion);
75
+ if (where?.id?.eq) query = query.where("id", "==", where.id.eq);
76
+ if (where?.id?.gt) query = query.where("id", ">", where.id.gt);
77
+ if (where?.id?.gte) query = query.where("id", ">=", where.id.gte);
78
+ if (where?.id?.lt) query = query.where("id", "<", where.id.lt);
79
+ if (where?.id?.lte) query = query.where("id", "<=", where.id.lte);
80
+ query = query.orderBy("id", orderBy?.direction === "asc" ? "asc" : "desc");
47
81
  const total = (await query.get()).size;
48
82
  if (offset > 0) query = query.offset(offset);
49
83
  if (limit) query = query.limit(limit);
50
- bundles = (await query.get()).docs.map((doc) => convertToBundle(doc.data()));
84
+ bundles = sortBundles((await query.get()).docs.map((doc) => convertToBundle(doc.data())).filter((bundle) => bundleMatchesQueryWhere(bundle, where)), orderBy);
51
85
  return {
52
86
  data: bundles,
53
87
  pagination: calculatePagination(total, {
@@ -91,7 +125,9 @@ const firebaseDatabase = createDatabasePlugin({
91
125
  target_app_version: data.targetAppVersion,
92
126
  storage_uri: data.storageUri,
93
127
  fingerprint_hash: data.fingerprintHash,
94
- metadata: data.metadata ?? {}
128
+ metadata: data.metadata ?? {},
129
+ rollout_cohort_count: data.rolloutCohortCount ?? DEFAULT_ROLLOUT_COHORT_COUNT,
130
+ target_cohorts: data.targetCohorts ?? null
95
131
  };
96
132
  const channelRef = db.collection("channels").doc(data.channel);
97
133
  transaction.set(channelRef, { name: data.channel }, { merge: true });
@@ -126,7 +162,9 @@ const firebaseDatabase = createDatabasePlugin({
126
162
  target_app_version: data.targetAppVersion || null,
127
163
  storage_uri: data.storageUri,
128
164
  fingerprint_hash: data.fingerprintHash,
129
- metadata: data.metadata ?? {}
165
+ metadata: data.metadata ?? {},
166
+ rollout_cohort_count: data.rolloutCohortCount ?? DEFAULT_ROLLOUT_COHORT_COUNT,
167
+ target_cohorts: data.targetCohorts ?? null
130
168
  }, { merge: true });
131
169
  if (data.targetAppVersion) {
132
170
  const versionDocId = `${data.platform}_${data.channel}_${data.targetAppVersion}`;
@@ -149,7 +187,6 @@ const firebaseDatabase = createDatabasePlugin({
149
187
  };
150
188
  }
151
189
  });
152
-
153
190
  //#endregion
154
191
  //#region src/firebaseStorage.ts
155
192
  const firebaseStorage = createStoragePlugin({
@@ -207,6 +244,5 @@ const firebaseStorage = createStoragePlugin({
207
244
  };
208
245
  }
209
246
  });
210
-
211
247
  //#endregion
212
- export { firebaseDatabase, firebaseStorage };
248
+ export { firebaseDatabase, firebaseStorage };
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "@hot-updater/firebase",
3
3
  "type": "module",
4
- "version": "0.28.0",
4
+ "version": "0.29.0",
5
5
  "description": "React Native OTA solution for self-hosted",
6
6
  "main": "dist/index.cjs",
7
- "types": "dist/index.d.ts",
8
- "module": "dist/index.js",
7
+ "types": "dist/index.d.cts",
8
+ "module": "dist/index.mjs",
9
9
  "exports": {
10
10
  ".": {
11
- "types": "./dist/index.d.ts",
12
- "import": "./dist/index.js",
11
+ "types": "./dist/index.d.cts",
12
+ "import": "./dist/index.mjs",
13
13
  "require": "./dist/index.cjs"
14
14
  },
15
15
  "./iac": {
16
- "types": "./dist/iac/index.d.ts",
17
- "import": "./dist/iac/index.js",
16
+ "types": "./dist/iac/index.d.cts",
17
+ "import": "./dist/iac/index.mjs",
18
18
  "require": "./dist/iac/index.cjs"
19
19
  },
20
20
  "./functions": {
@@ -35,9 +35,11 @@
35
35
  ],
36
36
  "dependencies": {
37
37
  "firebase": "^11.3.1",
38
- "@hot-updater/plugin-core": "0.28.0",
39
- "@hot-updater/cli-tools": "0.28.0",
40
- "@hot-updater/core": "0.28.0"
38
+ "hono": "4.12.9",
39
+ "@hot-updater/cli-tools": "0.29.0",
40
+ "@hot-updater/core": "0.29.0",
41
+ "@hot-updater/plugin-core": "0.29.0",
42
+ "@hot-updater/server": "0.29.0"
41
43
  },
42
44
  "publishConfig": {
43
45
  "access": "public"
@@ -51,17 +53,21 @@
51
53
  "firebase-functions-test": "^3.4.0",
52
54
  "firebase-tools": "^13.32.0",
53
55
  "fkill": "^9.0.0",
54
- "hono": "^4.6.3",
55
56
  "mime": "^4.0.4",
56
- "@hot-updater/js": "0.28.0",
57
- "@hot-updater/test-utils": "0.28.0"
57
+ "@hot-updater/js": "0.29.0",
58
+ "@hot-updater/mock": "0.29.0",
59
+ "@hot-updater/test-utils": "0.29.0"
58
60
  },
59
61
  "peerDependencies": {
60
- "firebase-admin": "*"
62
+ "firebase-admin": "*",
63
+ "firebase-functions": "*"
61
64
  },
62
65
  "peerDependenciesMeta": {
63
66
  "firebase-admin": {
64
67
  "optional": false
68
+ },
69
+ "firebase-functions": {
70
+ "optional": false
65
71
  }
66
72
  },
67
73
  "scripts": {
File without changes