@hot-updater/standalone 0.21.10 → 0.21.12

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
@@ -51,91 +51,93 @@ const createRoute$1 = (defaultRoute, customRoute) => ({
51
51
  ...customRoute?.headers
52
52
  }
53
53
  });
54
- const standaloneRepository = (config, hooks) => {
55
- const routes = {
56
- upsert: () => createRoute$1(defaultRoutes$1.upsert(), config.routes?.upsert?.()),
57
- list: () => createRoute$1(defaultRoutes$1.list(), config.routes?.list?.()),
58
- retrieve: (bundleId) => createRoute$1(defaultRoutes$1.retrieve(bundleId), config.routes?.retrieve?.(bundleId)),
59
- delete: (bundleId) => createRoute$1(defaultRoutes$1.delete(bundleId), config.routes?.delete?.(bundleId))
60
- };
61
- const buildUrl = (path$2) => `${config.baseUrl}${path$2}`;
62
- const getHeaders = (routeHeaders) => ({
63
- "Content-Type": "application/json",
64
- ...config.commonHeaders,
65
- ...routeHeaders
66
- });
67
- return (0, __hot_updater_plugin_core.createDatabasePlugin)("standalone-repository", {
68
- async getBundleById(_, bundleId) {
69
- try {
70
- const { path: path$2, headers: routeHeaders } = routes.retrieve(bundleId);
54
+ const standaloneRepository = (0, __hot_updater_plugin_core.createDatabasePlugin)({
55
+ name: "standalone-repository",
56
+ factory: (config) => {
57
+ const routes = {
58
+ upsert: () => createRoute$1(defaultRoutes$1.upsert(), config.routes?.upsert?.()),
59
+ list: () => createRoute$1(defaultRoutes$1.list(), config.routes?.list?.()),
60
+ retrieve: (bundleId) => createRoute$1(defaultRoutes$1.retrieve(bundleId), config.routes?.retrieve?.(bundleId)),
61
+ delete: (bundleId) => createRoute$1(defaultRoutes$1.delete(bundleId), config.routes?.delete?.(bundleId))
62
+ };
63
+ const buildUrl = (path$2) => `${config.baseUrl}${path$2}`;
64
+ const getHeaders = (routeHeaders) => ({
65
+ "Content-Type": "application/json",
66
+ ...config.commonHeaders,
67
+ ...routeHeaders
68
+ });
69
+ return {
70
+ async getBundleById(bundleId) {
71
+ try {
72
+ const { path: path$2, headers: routeHeaders } = routes.retrieve(bundleId);
73
+ const response = await fetch(buildUrl(path$2), {
74
+ method: "GET",
75
+ headers: getHeaders(routeHeaders)
76
+ });
77
+ if (!response.ok) return null;
78
+ return await response.json();
79
+ } catch {
80
+ return null;
81
+ }
82
+ },
83
+ async getBundles(options) {
84
+ const { where, limit, offset = 0 } = options ?? {};
85
+ const { path: path$2, headers: routeHeaders } = routes.list();
71
86
  const response = await fetch(buildUrl(path$2), {
72
87
  method: "GET",
73
88
  headers: getHeaders(routeHeaders)
74
89
  });
75
- if (!response.ok) return null;
76
- return await response.json();
77
- } catch {
78
- return null;
79
- }
80
- },
81
- async getBundles(_, options) {
82
- const { where, limit, offset = 0 } = options ?? {};
83
- const { path: path$2, headers: routeHeaders } = routes.list();
84
- const response = await fetch(buildUrl(path$2), {
85
- method: "GET",
86
- headers: getHeaders(routeHeaders)
87
- });
88
- if (!response.ok) throw new Error(`API Error: ${response.statusText}`);
89
- let filteredBundles = await response.json();
90
- if (where?.channel) filteredBundles = filteredBundles.filter((b) => b.channel === where.channel);
91
- if (where?.platform) filteredBundles = filteredBundles.filter((b) => b.platform === where.platform);
92
- const total = filteredBundles.length;
93
- return {
94
- data: limit ? filteredBundles.slice(offset, offset + limit) : filteredBundles,
95
- pagination: (0, __hot_updater_plugin_core.calculatePagination)(total, {
96
- limit,
97
- offset
98
- })
99
- };
100
- },
101
- async getChannels(_) {
102
- const result = await this.getBundles(_, {
103
- limit: 50,
104
- offset: 0
105
- });
106
- return [...new Set(result.data.map((b) => b.channel))];
107
- },
108
- async commitBundle(_, { changedSets }) {
109
- if (changedSets.length === 0) return;
110
- for (const op of changedSets) if (op.operation === "delete") {
111
- const { path: path$2, headers: routeHeaders } = routes.delete(op.data.id);
112
- const response = await fetch(buildUrl(path$2), {
113
- method: "DELETE",
114
- headers: getHeaders(routeHeaders)
90
+ if (!response.ok) throw new Error(`API Error: ${response.statusText}`);
91
+ let filteredBundles = await response.json();
92
+ if (where?.channel) filteredBundles = filteredBundles.filter((b) => b.channel === where.channel);
93
+ if (where?.platform) filteredBundles = filteredBundles.filter((b) => b.platform === where.platform);
94
+ const total = filteredBundles.length;
95
+ return {
96
+ data: limit ? filteredBundles.slice(offset, offset + limit) : filteredBundles,
97
+ pagination: (0, __hot_updater_plugin_core.calculatePagination)(total, {
98
+ limit,
99
+ offset
100
+ })
101
+ };
102
+ },
103
+ async getChannels() {
104
+ const result = await this.getBundles({
105
+ limit: 50,
106
+ offset: 0
115
107
  });
116
- if (!response.ok) {
117
- if (response.status === 404) throw new Error(`Bundle with id ${op.data.id} not found`);
118
- throw new Error(`API Error: ${response.status} ${response.statusText}`);
119
- }
120
- if (response.headers.get("content-type")?.includes("application/json")) try {
121
- await response.json();
122
- } catch (_jsonError) {
123
- if (!response.ok) throw new Error("Failed to parse response");
108
+ return [...new Set(result.data.map((b) => b.channel))];
109
+ },
110
+ async commitBundle({ changedSets }) {
111
+ if (changedSets.length === 0) return;
112
+ for (const op of changedSets) if (op.operation === "delete") {
113
+ const { path: path$2, headers: routeHeaders } = routes.delete(op.data.id);
114
+ const response = await fetch(buildUrl(path$2), {
115
+ method: "DELETE",
116
+ headers: getHeaders(routeHeaders)
117
+ });
118
+ if (!response.ok) {
119
+ if (response.status === 404) throw new Error(`Bundle with id ${op.data.id} not found`);
120
+ throw new Error(`API Error: ${response.status} ${response.statusText}`);
121
+ }
122
+ if (response.headers.get("content-type")?.includes("application/json")) try {
123
+ await response.json();
124
+ } catch (_jsonError) {
125
+ if (!response.ok) throw new Error("Failed to parse response");
126
+ }
127
+ } else if (op.operation === "insert" || op.operation === "update") {
128
+ const { path: path$2, headers: routeHeaders } = routes.upsert();
129
+ const response = await fetch(buildUrl(path$2), {
130
+ method: "POST",
131
+ headers: getHeaders(routeHeaders),
132
+ body: JSON.stringify([op.data])
133
+ });
134
+ if (!response.ok) throw new Error(`API Error: ${response.statusText}`);
135
+ if (!(await response.json()).success) throw new Error("Failed to commit bundle");
124
136
  }
125
- } else if (op.operation === "insert" || op.operation === "update") {
126
- const { path: path$2, headers: routeHeaders } = routes.upsert();
127
- const response = await fetch(buildUrl(path$2), {
128
- method: "POST",
129
- headers: getHeaders(routeHeaders),
130
- body: JSON.stringify([op.data])
131
- });
132
- if (!response.ok) throw new Error(`API Error: ${response.statusText}`);
133
- if (!(await response.json()).success) throw new Error("Failed to commit bundle");
134
137
  }
135
- hooks?.onDatabaseUpdated?.();
136
- }
137
- }, hooks);
138
- };
138
+ };
139
+ }
140
+ });
139
141
 
140
142
  //#endregion
141
143
  //#region ../../node_modules/.pnpm/mime@2.6.0/node_modules/mime/Mime.js
@@ -1457,7 +1459,7 @@ const createRoute = (defaultRoute, customRoute) => ({
1457
1459
  ...customRoute?.headers
1458
1460
  }
1459
1461
  });
1460
- const standaloneStorage = (config, hooks) => (_) => {
1462
+ const standaloneStorage = (config, hooks) => () => {
1461
1463
  const routes = {
1462
1464
  upload: (key, filePath) => createRoute(defaultRoutes.upload(key, filePath), config.routes?.upload?.(key, filePath)),
1463
1465
  delete: (storageUri) => createRoute(defaultRoutes.delete(storageUri), config.routes?.delete?.(storageUri)),
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _hot_updater_plugin_core0 from "@hot-updater/plugin-core";
2
- import { BasePluginArgs, DatabasePluginHooks, StoragePlugin, StoragePluginHooks } from "@hot-updater/plugin-core";
2
+ import { StoragePlugin, StoragePluginHooks } from "@hot-updater/plugin-core";
3
3
 
4
4
  //#region src/standaloneRepository.d.ts
5
5
  interface RouteConfig {
@@ -17,7 +17,7 @@ interface StandaloneRepositoryConfig {
17
17
  commonHeaders?: Record<string, string>;
18
18
  routes?: Routes;
19
19
  }
20
- declare const standaloneRepository: (config: StandaloneRepositoryConfig, hooks?: DatabasePluginHooks) => (options: _hot_updater_plugin_core0.BasePluginArgs) => _hot_updater_plugin_core0.DatabasePlugin;
20
+ declare const standaloneRepository: (config: StandaloneRepositoryConfig, hooks?: _hot_updater_plugin_core0.DatabasePluginHooks) => (() => _hot_updater_plugin_core0.DatabasePlugin);
21
21
  //#endregion
22
22
  //#region src/standaloneStorage.d.ts
23
23
  interface StorageRoutes {
@@ -30,6 +30,6 @@ interface StandaloneStorageConfig {
30
30
  commonHeaders?: Record<string, string>;
31
31
  routes?: StorageRoutes;
32
32
  }
33
- declare const standaloneStorage: (config: StandaloneStorageConfig, hooks?: StoragePluginHooks) => (_: BasePluginArgs) => StoragePlugin;
33
+ declare const standaloneStorage: (config: StandaloneStorageConfig, hooks?: StoragePluginHooks) => () => StoragePlugin;
34
34
  //#endregion
35
35
  export { RouteConfig, Routes, StandaloneRepositoryConfig, StandaloneStorageConfig, StorageRoutes, standaloneRepository, standaloneStorage };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _hot_updater_plugin_core0 from "@hot-updater/plugin-core";
2
- import { BasePluginArgs, DatabasePluginHooks, StoragePlugin, StoragePluginHooks } from "@hot-updater/plugin-core";
2
+ import { StoragePlugin, StoragePluginHooks } from "@hot-updater/plugin-core";
3
3
 
4
4
  //#region src/standaloneRepository.d.ts
5
5
  interface RouteConfig {
@@ -17,7 +17,7 @@ interface StandaloneRepositoryConfig {
17
17
  commonHeaders?: Record<string, string>;
18
18
  routes?: Routes;
19
19
  }
20
- declare const standaloneRepository: (config: StandaloneRepositoryConfig, hooks?: DatabasePluginHooks) => (options: _hot_updater_plugin_core0.BasePluginArgs) => _hot_updater_plugin_core0.DatabasePlugin;
20
+ declare const standaloneRepository: (config: StandaloneRepositoryConfig, hooks?: _hot_updater_plugin_core0.DatabasePluginHooks) => (() => _hot_updater_plugin_core0.DatabasePlugin);
21
21
  //#endregion
22
22
  //#region src/standaloneStorage.d.ts
23
23
  interface StorageRoutes {
@@ -30,6 +30,6 @@ interface StandaloneStorageConfig {
30
30
  commonHeaders?: Record<string, string>;
31
31
  routes?: StorageRoutes;
32
32
  }
33
- declare const standaloneStorage: (config: StandaloneStorageConfig, hooks?: StoragePluginHooks) => (_: BasePluginArgs) => StoragePlugin;
33
+ declare const standaloneStorage: (config: StandaloneStorageConfig, hooks?: StoragePluginHooks) => () => StoragePlugin;
34
34
  //#endregion
35
35
  export { RouteConfig, Routes, StandaloneRepositoryConfig, StandaloneStorageConfig, StorageRoutes, standaloneRepository, standaloneStorage };
package/dist/index.js CHANGED
@@ -48,91 +48,93 @@ const createRoute$1 = (defaultRoute, customRoute) => ({
48
48
  ...customRoute?.headers
49
49
  }
50
50
  });
51
- const standaloneRepository = (config, hooks) => {
52
- const routes = {
53
- upsert: () => createRoute$1(defaultRoutes$1.upsert(), config.routes?.upsert?.()),
54
- list: () => createRoute$1(defaultRoutes$1.list(), config.routes?.list?.()),
55
- retrieve: (bundleId) => createRoute$1(defaultRoutes$1.retrieve(bundleId), config.routes?.retrieve?.(bundleId)),
56
- delete: (bundleId) => createRoute$1(defaultRoutes$1.delete(bundleId), config.routes?.delete?.(bundleId))
57
- };
58
- const buildUrl = (path$1) => `${config.baseUrl}${path$1}`;
59
- const getHeaders = (routeHeaders) => ({
60
- "Content-Type": "application/json",
61
- ...config.commonHeaders,
62
- ...routeHeaders
63
- });
64
- return createDatabasePlugin("standalone-repository", {
65
- async getBundleById(_, bundleId) {
66
- try {
67
- const { path: path$1, headers: routeHeaders } = routes.retrieve(bundleId);
51
+ const standaloneRepository = createDatabasePlugin({
52
+ name: "standalone-repository",
53
+ factory: (config) => {
54
+ const routes = {
55
+ upsert: () => createRoute$1(defaultRoutes$1.upsert(), config.routes?.upsert?.()),
56
+ list: () => createRoute$1(defaultRoutes$1.list(), config.routes?.list?.()),
57
+ retrieve: (bundleId) => createRoute$1(defaultRoutes$1.retrieve(bundleId), config.routes?.retrieve?.(bundleId)),
58
+ delete: (bundleId) => createRoute$1(defaultRoutes$1.delete(bundleId), config.routes?.delete?.(bundleId))
59
+ };
60
+ const buildUrl = (path$1) => `${config.baseUrl}${path$1}`;
61
+ const getHeaders = (routeHeaders) => ({
62
+ "Content-Type": "application/json",
63
+ ...config.commonHeaders,
64
+ ...routeHeaders
65
+ });
66
+ return {
67
+ async getBundleById(bundleId) {
68
+ try {
69
+ const { path: path$1, headers: routeHeaders } = routes.retrieve(bundleId);
70
+ const response = await fetch(buildUrl(path$1), {
71
+ method: "GET",
72
+ headers: getHeaders(routeHeaders)
73
+ });
74
+ if (!response.ok) return null;
75
+ return await response.json();
76
+ } catch {
77
+ return null;
78
+ }
79
+ },
80
+ async getBundles(options) {
81
+ const { where, limit, offset = 0 } = options ?? {};
82
+ const { path: path$1, headers: routeHeaders } = routes.list();
68
83
  const response = await fetch(buildUrl(path$1), {
69
84
  method: "GET",
70
85
  headers: getHeaders(routeHeaders)
71
86
  });
72
- if (!response.ok) return null;
73
- return await response.json();
74
- } catch {
75
- return null;
76
- }
77
- },
78
- async getBundles(_, options) {
79
- const { where, limit, offset = 0 } = options ?? {};
80
- const { path: path$1, headers: routeHeaders } = routes.list();
81
- const response = await fetch(buildUrl(path$1), {
82
- method: "GET",
83
- headers: getHeaders(routeHeaders)
84
- });
85
- if (!response.ok) throw new Error(`API Error: ${response.statusText}`);
86
- let filteredBundles = await response.json();
87
- if (where?.channel) filteredBundles = filteredBundles.filter((b) => b.channel === where.channel);
88
- if (where?.platform) filteredBundles = filteredBundles.filter((b) => b.platform === where.platform);
89
- const total = filteredBundles.length;
90
- return {
91
- data: limit ? filteredBundles.slice(offset, offset + limit) : filteredBundles,
92
- pagination: calculatePagination(total, {
93
- limit,
94
- offset
95
- })
96
- };
97
- },
98
- async getChannels(_) {
99
- const result = await this.getBundles(_, {
100
- limit: 50,
101
- offset: 0
102
- });
103
- return [...new Set(result.data.map((b) => b.channel))];
104
- },
105
- async commitBundle(_, { changedSets }) {
106
- if (changedSets.length === 0) return;
107
- for (const op of changedSets) if (op.operation === "delete") {
108
- const { path: path$1, headers: routeHeaders } = routes.delete(op.data.id);
109
- const response = await fetch(buildUrl(path$1), {
110
- method: "DELETE",
111
- headers: getHeaders(routeHeaders)
87
+ if (!response.ok) throw new Error(`API Error: ${response.statusText}`);
88
+ let filteredBundles = await response.json();
89
+ if (where?.channel) filteredBundles = filteredBundles.filter((b) => b.channel === where.channel);
90
+ if (where?.platform) filteredBundles = filteredBundles.filter((b) => b.platform === where.platform);
91
+ const total = filteredBundles.length;
92
+ return {
93
+ data: limit ? filteredBundles.slice(offset, offset + limit) : filteredBundles,
94
+ pagination: calculatePagination(total, {
95
+ limit,
96
+ offset
97
+ })
98
+ };
99
+ },
100
+ async getChannels() {
101
+ const result = await this.getBundles({
102
+ limit: 50,
103
+ offset: 0
112
104
  });
113
- if (!response.ok) {
114
- if (response.status === 404) throw new Error(`Bundle with id ${op.data.id} not found`);
115
- throw new Error(`API Error: ${response.status} ${response.statusText}`);
116
- }
117
- if (response.headers.get("content-type")?.includes("application/json")) try {
118
- await response.json();
119
- } catch (_jsonError) {
120
- if (!response.ok) throw new Error("Failed to parse response");
105
+ return [...new Set(result.data.map((b) => b.channel))];
106
+ },
107
+ async commitBundle({ changedSets }) {
108
+ if (changedSets.length === 0) return;
109
+ for (const op of changedSets) if (op.operation === "delete") {
110
+ const { path: path$1, headers: routeHeaders } = routes.delete(op.data.id);
111
+ const response = await fetch(buildUrl(path$1), {
112
+ method: "DELETE",
113
+ headers: getHeaders(routeHeaders)
114
+ });
115
+ if (!response.ok) {
116
+ if (response.status === 404) throw new Error(`Bundle with id ${op.data.id} not found`);
117
+ throw new Error(`API Error: ${response.status} ${response.statusText}`);
118
+ }
119
+ if (response.headers.get("content-type")?.includes("application/json")) try {
120
+ await response.json();
121
+ } catch (_jsonError) {
122
+ if (!response.ok) throw new Error("Failed to parse response");
123
+ }
124
+ } else if (op.operation === "insert" || op.operation === "update") {
125
+ const { path: path$1, headers: routeHeaders } = routes.upsert();
126
+ const response = await fetch(buildUrl(path$1), {
127
+ method: "POST",
128
+ headers: getHeaders(routeHeaders),
129
+ body: JSON.stringify([op.data])
130
+ });
131
+ if (!response.ok) throw new Error(`API Error: ${response.statusText}`);
132
+ if (!(await response.json()).success) throw new Error("Failed to commit bundle");
121
133
  }
122
- } else if (op.operation === "insert" || op.operation === "update") {
123
- const { path: path$1, headers: routeHeaders } = routes.upsert();
124
- const response = await fetch(buildUrl(path$1), {
125
- method: "POST",
126
- headers: getHeaders(routeHeaders),
127
- body: JSON.stringify([op.data])
128
- });
129
- if (!response.ok) throw new Error(`API Error: ${response.statusText}`);
130
- if (!(await response.json()).success) throw new Error("Failed to commit bundle");
131
134
  }
132
- hooks?.onDatabaseUpdated?.();
133
- }
134
- }, hooks);
135
- };
135
+ };
136
+ }
137
+ });
136
138
 
137
139
  //#endregion
138
140
  //#region ../../node_modules/.pnpm/mime@2.6.0/node_modules/mime/Mime.js
@@ -1454,7 +1456,7 @@ const createRoute = (defaultRoute, customRoute) => ({
1454
1456
  ...customRoute?.headers
1455
1457
  }
1456
1458
  });
1457
- const standaloneStorage = (config, hooks) => (_) => {
1459
+ const standaloneStorage = (config, hooks) => () => {
1458
1460
  const routes = {
1459
1461
  upload: (key, filePath) => createRoute(defaultRoutes.upload(key, filePath), config.routes?.upload?.(key, filePath)),
1460
1462
  delete: (storageUri) => createRoute(defaultRoutes.delete(storageUri), config.routes?.delete?.(storageUri)),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hot-updater/standalone",
3
- "version": "0.21.10",
3
+ "version": "0.21.12",
4
4
  "type": "module",
5
5
  "description": "React Native OTA solution for self-hosted",
6
6
  "sideEffects": false,
@@ -39,8 +39,8 @@
39
39
  "access": "public"
40
40
  },
41
41
  "dependencies": {
42
- "@hot-updater/core": "0.21.10",
43
- "@hot-updater/plugin-core": "0.21.10"
42
+ "@hot-updater/core": "0.21.12",
43
+ "@hot-updater/plugin-core": "0.21.12"
44
44
  },
45
45
  "devDependencies": {
46
46
  "mime": "2.6.0",