@hot-updater/js 0.16.7-0 → 0.18.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.
@@ -0,0 +1,98 @@
1
+ import { Bundle, GetBundlesArgs, UpdateInfo } from "@hot-updater/core";
2
+
3
+ //#region src/getUpdateInfo.d.ts
4
+ declare const getUpdateInfo: (bundles: Bundle[], args: GetBundlesArgs) => Promise<UpdateInfo | null>;
5
+
6
+ //#endregion
7
+ //#region src/semverSatisfies.d.ts
8
+ declare const semverSatisfies: (targetAppVersion: string, currentVersion: string) => boolean;
9
+
10
+ //#endregion
11
+ //#region src/filterCompatibleAppVersions.d.ts
12
+ /**
13
+ * Filters target app versions that are compatible with the current app version.
14
+ * Returns only versions that are compatible with the current version according to semver rules.
15
+ *
16
+ * @param targetAppVersionList - List of target app versions to filter
17
+ * @param currentVersion - Current app version
18
+ * @returns Array of target app versions compatible with the current version
19
+ */
20
+ declare const filterCompatibleAppVersions: (targetAppVersionList: string[], currentVersion: string) => string[];
21
+
22
+ //#endregion
23
+ //#region src/withJwtSignedUrl.d.ts
24
+ /**
25
+ * Creates a JWT-signed download URL based on the provided update information.
26
+ *
27
+ * @param {Object} options - Function options
28
+ * @param {T|null} options.data - Update information (null if none)
29
+ * @param {string} options.reqUrl - Request URL (base URL for token generation)
30
+ * @param {string} options.jwtSecret - Secret key for JWT signing
31
+ * @returns {Promise<T|null>} - Update response object with fileUrl or null
32
+ */
33
+ declare const withJwtSignedUrl: <T extends {
34
+ id: string;
35
+ storageUri: string | null;
36
+ }>({
37
+ data,
38
+ reqUrl,
39
+ jwtSecret
40
+ }: {
41
+ data: T | null;
42
+ reqUrl: string;
43
+ jwtSecret: string;
44
+ }) => Promise<(Omit<T, "storageUri"> & {
45
+ fileUrl: string | null;
46
+ }) | null>;
47
+ declare const signToken: (key: string, jwtSecret: string) => Promise<string>;
48
+
49
+ //#endregion
50
+ //#region src/verifyJwtSignedUrl.d.ts
51
+ type SuccessResponse = {
52
+ status: 200;
53
+ responseHeaders?: Record<string, string>;
54
+ responseBody: any;
55
+ };
56
+ type ErrorResponse = {
57
+ status: 400 | 403 | 404;
58
+ error: string;
59
+ };
60
+ type VerifyJwtSignedUrlResponse = SuccessResponse | ErrorResponse;
61
+ /**
62
+ * Verifies JWT token only and returns the file key (path with leading slashes removed) if valid.
63
+ */
64
+ declare const verifyJwtToken: ({
65
+ path,
66
+ token,
67
+ jwtSecret
68
+ }: {
69
+ path: string;
70
+ token: string | undefined;
71
+ jwtSecret: string;
72
+ }) => Promise<{
73
+ valid: boolean;
74
+ key?: string;
75
+ error?: string;
76
+ }>;
77
+ /**
78
+ * Integrated function for JWT verification and file handling.
79
+ * - Returns error response if token is missing or validation fails.
80
+ * - On success, retrieves file data through the handler and constructs a response object.
81
+ */
82
+ declare const verifyJwtSignedUrl: ({
83
+ path,
84
+ token,
85
+ jwtSecret,
86
+ handler
87
+ }: {
88
+ path: string;
89
+ token: string | undefined;
90
+ jwtSecret: string;
91
+ handler: (key: string) => Promise<{
92
+ body: any;
93
+ contentType?: string;
94
+ } | null>;
95
+ }) => Promise<VerifyJwtSignedUrlResponse>;
96
+
97
+ //#endregion
98
+ export { ErrorResponse, SuccessResponse, VerifyJwtSignedUrlResponse, filterCompatibleAppVersions, getUpdateInfo, semverSatisfies, signToken, verifyJwtSignedUrl, verifyJwtToken, withJwtSignedUrl };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,98 @@
1
- export * from "./getUpdateInfo";
2
- export * from "./semverSatisfies";
3
- export * from "./filterCompatibleAppVersions";
4
- export * from "./withJwtSignedUrl";
5
- export * from "./verifyJwtSignedUrl";
1
+ import { Bundle, GetBundlesArgs, UpdateInfo } from "@hot-updater/core";
2
+
3
+ //#region src/getUpdateInfo.d.ts
4
+ declare const getUpdateInfo: (bundles: Bundle[], args: GetBundlesArgs) => Promise<UpdateInfo | null>;
5
+
6
+ //#endregion
7
+ //#region src/semverSatisfies.d.ts
8
+ declare const semverSatisfies: (targetAppVersion: string, currentVersion: string) => boolean;
9
+
10
+ //#endregion
11
+ //#region src/filterCompatibleAppVersions.d.ts
12
+ /**
13
+ * Filters target app versions that are compatible with the current app version.
14
+ * Returns only versions that are compatible with the current version according to semver rules.
15
+ *
16
+ * @param targetAppVersionList - List of target app versions to filter
17
+ * @param currentVersion - Current app version
18
+ * @returns Array of target app versions compatible with the current version
19
+ */
20
+ declare const filterCompatibleAppVersions: (targetAppVersionList: string[], currentVersion: string) => string[];
21
+
22
+ //#endregion
23
+ //#region src/withJwtSignedUrl.d.ts
24
+ /**
25
+ * Creates a JWT-signed download URL based on the provided update information.
26
+ *
27
+ * @param {Object} options - Function options
28
+ * @param {T|null} options.data - Update information (null if none)
29
+ * @param {string} options.reqUrl - Request URL (base URL for token generation)
30
+ * @param {string} options.jwtSecret - Secret key for JWT signing
31
+ * @returns {Promise<T|null>} - Update response object with fileUrl or null
32
+ */
33
+ declare const withJwtSignedUrl: <T extends {
34
+ id: string;
35
+ storageUri: string | null;
36
+ }>({
37
+ data,
38
+ reqUrl,
39
+ jwtSecret
40
+ }: {
41
+ data: T | null;
42
+ reqUrl: string;
43
+ jwtSecret: string;
44
+ }) => Promise<(Omit<T, "storageUri"> & {
45
+ fileUrl: string | null;
46
+ }) | null>;
47
+ declare const signToken: (key: string, jwtSecret: string) => Promise<string>;
48
+
49
+ //#endregion
50
+ //#region src/verifyJwtSignedUrl.d.ts
51
+ type SuccessResponse = {
52
+ status: 200;
53
+ responseHeaders?: Record<string, string>;
54
+ responseBody: any;
55
+ };
56
+ type ErrorResponse = {
57
+ status: 400 | 403 | 404;
58
+ error: string;
59
+ };
60
+ type VerifyJwtSignedUrlResponse = SuccessResponse | ErrorResponse;
61
+ /**
62
+ * Verifies JWT token only and returns the file key (path with leading slashes removed) if valid.
63
+ */
64
+ declare const verifyJwtToken: ({
65
+ path,
66
+ token,
67
+ jwtSecret
68
+ }: {
69
+ path: string;
70
+ token: string | undefined;
71
+ jwtSecret: string;
72
+ }) => Promise<{
73
+ valid: boolean;
74
+ key?: string;
75
+ error?: string;
76
+ }>;
77
+ /**
78
+ * Integrated function for JWT verification and file handling.
79
+ * - Returns error response if token is missing or validation fails.
80
+ * - On success, retrieves file data through the handler and constructs a response object.
81
+ */
82
+ declare const verifyJwtSignedUrl: ({
83
+ path,
84
+ token,
85
+ jwtSecret,
86
+ handler
87
+ }: {
88
+ path: string;
89
+ token: string | undefined;
90
+ jwtSecret: string;
91
+ handler: (key: string) => Promise<{
92
+ body: any;
93
+ contentType?: string;
94
+ } | null>;
95
+ }) => Promise<VerifyJwtSignedUrlResponse>;
96
+
97
+ //#endregion
98
+ export { ErrorResponse, SuccessResponse, VerifyJwtSignedUrlResponse, filterCompatibleAppVersions, getUpdateInfo, semverSatisfies, signToken, verifyJwtSignedUrl, verifyJwtToken, withJwtSignedUrl };