@hot-updater/standalone 0.10.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Sungyu Kang
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.cjs ADDED
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = function(exports1, definition) {
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = function(obj, prop) {
13
+ return Object.prototype.hasOwnProperty.call(obj, prop);
14
+ };
15
+ })();
16
+ (()=>{
17
+ __webpack_require__.r = function(exports1) {
18
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
19
+ value: 'Module'
20
+ });
21
+ Object.defineProperty(exports1, '__esModule', {
22
+ value: true
23
+ });
24
+ };
25
+ })();
26
+ var __webpack_exports__ = {};
27
+ __webpack_require__.r(__webpack_exports__);
28
+ __webpack_require__.d(__webpack_exports__, {
29
+ standaloneRepository: ()=>standaloneRepository
30
+ });
31
+ const defaultRoutes = {
32
+ upsert: ()=>({
33
+ path: "/bundles"
34
+ }),
35
+ list: ()=>({
36
+ path: "/bundles",
37
+ headers: {
38
+ "Cache-Control": "no-cache"
39
+ }
40
+ }),
41
+ retrieve: (bundleId)=>({
42
+ path: `/bundles/${bundleId}`,
43
+ headers: {
44
+ Accept: "application/json"
45
+ }
46
+ })
47
+ };
48
+ const createRoute = (defaultRoute, customRoute)=>({
49
+ path: customRoute?.path ?? defaultRoute.path,
50
+ headers: {
51
+ ...defaultRoute.headers,
52
+ ...customRoute?.headers
53
+ }
54
+ });
55
+ const standaloneRepository = (config, hooks)=>(_)=>{
56
+ const routes = {
57
+ upsert: ()=>createRoute(defaultRoutes.upsert(), config.routes?.upsert?.()),
58
+ list: ()=>createRoute(defaultRoutes.list(), config.routes?.list?.()),
59
+ retrieve: (bundleId)=>createRoute(defaultRoutes.retrieve(bundleId), config.routes?.retrieve?.(bundleId))
60
+ };
61
+ const getHeaders = (routeHeaders)=>({
62
+ "Content-Type": "application/json",
63
+ ...config.commonHeaders,
64
+ ...routeHeaders
65
+ });
66
+ let bundles = [];
67
+ const changedIds = new Set();
68
+ function markChanged(id) {
69
+ changedIds.add(id);
70
+ }
71
+ return {
72
+ name: "standalone-repository",
73
+ async commitBundle () {
74
+ if (0 === changedIds.size) return;
75
+ const changedBundles = bundles.filter((b)=>changedIds.has(b.id));
76
+ if (0 === changedBundles.length) return;
77
+ const { path, headers: routeHeaders } = routes.upsert();
78
+ const response = await fetch(`${config.baseUrl}${path}`, {
79
+ method: "POST",
80
+ headers: getHeaders(routeHeaders),
81
+ body: JSON.stringify(changedBundles)
82
+ });
83
+ if (!response.ok) throw new Error(`API Error: ${response.statusText}`);
84
+ const result = await response.json();
85
+ if (!result.success) throw new Error("Failed to commit bundles");
86
+ changedIds.clear();
87
+ hooks?.onDatabaseUpdated?.();
88
+ },
89
+ async updateBundle (targetBundleId, newBundle) {
90
+ bundles = await this.getBundles();
91
+ const targetIndex = bundles.findIndex((u)=>u.id === targetBundleId);
92
+ if (-1 === targetIndex) throw new Error("target bundle version not found");
93
+ Object.assign(bundles[targetIndex], newBundle);
94
+ markChanged(targetBundleId);
95
+ },
96
+ async appendBundle (inputBundle) {
97
+ bundles = await this.getBundles();
98
+ bundles.unshift(inputBundle);
99
+ markChanged(inputBundle.id);
100
+ },
101
+ async getBundleById (bundleId) {
102
+ try {
103
+ const { path, headers: routeHeaders } = routes.retrieve(bundleId);
104
+ const response = await fetch(`${config.baseUrl}${path}`, {
105
+ method: "GET",
106
+ headers: getHeaders(routeHeaders)
107
+ });
108
+ if (!response.ok) return null;
109
+ return await response.json();
110
+ } catch (error) {
111
+ return null;
112
+ }
113
+ },
114
+ async getBundles (refresh = false) {
115
+ if (bundles.length > 0 && !refresh) return bundles;
116
+ const { path, headers: routeHeaders } = routes.list();
117
+ const response = await fetch(`${config.baseUrl}${path}`, {
118
+ method: "GET",
119
+ headers: getHeaders(routeHeaders)
120
+ });
121
+ if (!response.ok) throw new Error(`API Error: ${response.statusText}`);
122
+ bundles = await response.json();
123
+ return bundles;
124
+ }
125
+ };
126
+ };
127
+ var __webpack_export_target__ = exports;
128
+ for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
129
+ if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
130
+ value: true
131
+ });
@@ -0,0 +1 @@
1
+ export * from "./standaloneRepository";
package/dist/index.js ADDED
@@ -0,0 +1,97 @@
1
+ const defaultRoutes = {
2
+ upsert: ()=>({
3
+ path: "/bundles"
4
+ }),
5
+ list: ()=>({
6
+ path: "/bundles",
7
+ headers: {
8
+ "Cache-Control": "no-cache"
9
+ }
10
+ }),
11
+ retrieve: (bundleId)=>({
12
+ path: `/bundles/${bundleId}`,
13
+ headers: {
14
+ Accept: "application/json"
15
+ }
16
+ })
17
+ };
18
+ const createRoute = (defaultRoute, customRoute)=>({
19
+ path: customRoute?.path ?? defaultRoute.path,
20
+ headers: {
21
+ ...defaultRoute.headers,
22
+ ...customRoute?.headers
23
+ }
24
+ });
25
+ const standaloneRepository = (config, hooks)=>(_)=>{
26
+ const routes = {
27
+ upsert: ()=>createRoute(defaultRoutes.upsert(), config.routes?.upsert?.()),
28
+ list: ()=>createRoute(defaultRoutes.list(), config.routes?.list?.()),
29
+ retrieve: (bundleId)=>createRoute(defaultRoutes.retrieve(bundleId), config.routes?.retrieve?.(bundleId))
30
+ };
31
+ const getHeaders = (routeHeaders)=>({
32
+ "Content-Type": "application/json",
33
+ ...config.commonHeaders,
34
+ ...routeHeaders
35
+ });
36
+ let bundles = [];
37
+ const changedIds = new Set();
38
+ function markChanged(id) {
39
+ changedIds.add(id);
40
+ }
41
+ return {
42
+ name: "standalone-repository",
43
+ async commitBundle () {
44
+ if (0 === changedIds.size) return;
45
+ const changedBundles = bundles.filter((b)=>changedIds.has(b.id));
46
+ if (0 === changedBundles.length) return;
47
+ const { path, headers: routeHeaders } = routes.upsert();
48
+ const response = await fetch(`${config.baseUrl}${path}`, {
49
+ method: "POST",
50
+ headers: getHeaders(routeHeaders),
51
+ body: JSON.stringify(changedBundles)
52
+ });
53
+ if (!response.ok) throw new Error(`API Error: ${response.statusText}`);
54
+ const result = await response.json();
55
+ if (!result.success) throw new Error("Failed to commit bundles");
56
+ changedIds.clear();
57
+ hooks?.onDatabaseUpdated?.();
58
+ },
59
+ async updateBundle (targetBundleId, newBundle) {
60
+ bundles = await this.getBundles();
61
+ const targetIndex = bundles.findIndex((u)=>u.id === targetBundleId);
62
+ if (-1 === targetIndex) throw new Error("target bundle version not found");
63
+ Object.assign(bundles[targetIndex], newBundle);
64
+ markChanged(targetBundleId);
65
+ },
66
+ async appendBundle (inputBundle) {
67
+ bundles = await this.getBundles();
68
+ bundles.unshift(inputBundle);
69
+ markChanged(inputBundle.id);
70
+ },
71
+ async getBundleById (bundleId) {
72
+ try {
73
+ const { path, headers: routeHeaders } = routes.retrieve(bundleId);
74
+ const response = await fetch(`${config.baseUrl}${path}`, {
75
+ method: "GET",
76
+ headers: getHeaders(routeHeaders)
77
+ });
78
+ if (!response.ok) return null;
79
+ return await response.json();
80
+ } catch (error) {
81
+ return null;
82
+ }
83
+ },
84
+ async getBundles (refresh = false) {
85
+ if (bundles.length > 0 && !refresh) return bundles;
86
+ const { path, headers: routeHeaders } = routes.list();
87
+ const response = await fetch(`${config.baseUrl}${path}`, {
88
+ method: "GET",
89
+ headers: getHeaders(routeHeaders)
90
+ });
91
+ if (!response.ok) throw new Error(`API Error: ${response.statusText}`);
92
+ bundles = await response.json();
93
+ return bundles;
94
+ }
95
+ };
96
+ };
97
+ export { standaloneRepository };
@@ -0,0 +1,16 @@
1
+ import type { BasePluginArgs, DatabasePlugin, DatabasePluginHooks } from "@hot-updater/plugin-core";
2
+ export interface RouteConfig {
3
+ path: string;
4
+ headers?: Record<string, string>;
5
+ }
6
+ export interface Routes {
7
+ upsert: () => RouteConfig;
8
+ list: () => RouteConfig;
9
+ retrieve: (bundleId: string) => RouteConfig;
10
+ }
11
+ export interface StandaloneRepositoryConfig {
12
+ baseUrl: string;
13
+ commonHeaders?: Record<string, string>;
14
+ routes?: Routes;
15
+ }
16
+ export declare const standaloneRepository: (config: StandaloneRepositoryConfig, hooks?: DatabasePluginHooks) => (_: BasePluginArgs) => DatabasePlugin;
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@hot-updater/standalone",
3
+ "version": "0.10.1",
4
+ "type": "module",
5
+ "description": "React Native OTA solution for self-hosted",
6
+ "sideEffects": false,
7
+ "main": "dist/index.cjs",
8
+ "module": "dist/index.js",
9
+ "types": "dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "import": "./dist/index.js",
13
+ "require": "./dist/index.cjs"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist",
18
+ "package.json"
19
+ ],
20
+ "keywords": [
21
+ "react-native",
22
+ "react-native-code-push",
23
+ "code-push",
24
+ "eas",
25
+ "eas-update",
26
+ "expo",
27
+ "expo-update",
28
+ "self-hosted"
29
+ ],
30
+ "license": "MIT",
31
+ "repository": "https://github.com/gronxb/hot-updater",
32
+ "author": "gronxb <gron1gh1@gmail.com> (https://github.com/gronxb)",
33
+ "bugs": {
34
+ "url": "https://github.com/gronxb/hot-updater/issues"
35
+ },
36
+ "homepage": "https://github.com/gronxb/hot-updater#readme",
37
+ "publishConfig": {
38
+ "access": "public"
39
+ },
40
+ "dependencies": {
41
+ "@hot-updater/core": "0.10.1",
42
+ "@hot-updater/plugin-core": "0.10.1"
43
+ },
44
+ "devDependencies": {
45
+ "@types/node": "^20.9.4",
46
+ "@types/semver": "^7.5.8",
47
+ "msw": "^2.7.0",
48
+ "semver": "^7.6.3",
49
+ "vitest": "^3.0.6"
50
+ },
51
+ "scripts": {
52
+ "build": "rslib build",
53
+ "test:type": "tsc --noEmit"
54
+ }
55
+ }