@algocare/react-native-code-push 9.0.0-beta.3 → 9.0.0-beta.4

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.
Files changed (2) hide show
  1. package/code-push.config.ts +120 -0
  2. package/package.json +4 -2
@@ -0,0 +1,120 @@
1
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2
+ // @ts-nocheck
3
+
4
+ import {
5
+ CliConfigInterface,
6
+ ReleaseHistoryInterface,
7
+ } from '@algocare/react-native-code-push'
8
+ import * as fs from 'fs'
9
+ import axios from 'axios'
10
+ import { S3Client, PutObjectCommand } from '@aws-sdk/client-s3' // AWS SDK v3
11
+
12
+ const s3Client = new S3Client({
13
+ region: process.env.AWS_REGION,
14
+ credentials: {
15
+ accessKeyId: process.env.AWS_ACCESS_KEY_ID!,
16
+ secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY!,
17
+ },
18
+ })
19
+
20
+ const BUCKET_NAME = process.env.AWS_S3_BUCKET || 'codepush-bucket'
21
+ const CDN_URL = process.env.CDN_URL || `https://${BUCKET_NAME}.s3.amazonaws.com`
22
+
23
+ function historyJsonFileRemotePath(
24
+ platform: 'ios' | 'android',
25
+ identifier: string,
26
+ binaryVersion: string
27
+ ) {
28
+ return `histories/${platform}/${identifier}/${binaryVersion}.json`
29
+ }
30
+
31
+ function bundleFileRemotePath(
32
+ platform: 'ios' | 'android',
33
+ identifier: string,
34
+ fileName: string
35
+ ) {
36
+ return `bundles/${platform}/${identifier}/${fileName}`
37
+ }
38
+
39
+ const Config: CliConfigInterface = {
40
+ bundleUploader: async (
41
+ source: string,
42
+ platform: 'ios' | 'android',
43
+ identifier = 'staging'
44
+ ): Promise<{ downloadUrl: string }> => {
45
+ const fileName = source.split('/').pop()
46
+ const fileContent = fs.readFileSync(source)
47
+ const remotePath = bundleFileRemotePath(platform, identifier, fileName!)
48
+
49
+ try {
50
+ await s3Client.send(
51
+ new PutObjectCommand({
52
+ Bucket: BUCKET_NAME,
53
+ Key: remotePath,
54
+ Body: fileContent,
55
+ ContentType: 'application/zip',
56
+ })
57
+ )
58
+
59
+ console.log('Bundle File uploaded:', `${CDN_URL}/${remotePath}`)
60
+
61
+ return {
62
+ downloadUrl: `${CDN_URL}/${remotePath}`,
63
+ }
64
+ } catch (error) {
65
+ console.error('Error uploading bundle:', error)
66
+ throw error
67
+ }
68
+ },
69
+
70
+ getReleaseHistory: async (
71
+ targetBinaryVersion: string,
72
+ platform: 'ios' | 'android',
73
+ identifier = 'staging'
74
+ ): Promise<ReleaseHistoryInterface> => {
75
+ const remoteJsonPath = historyJsonFileRemotePath(
76
+ platform,
77
+ identifier,
78
+ targetBinaryVersion
79
+ )
80
+ const { data } = await axios.get(`${CDN_URL}/${remoteJsonPath}`)
81
+ return data as ReleaseHistoryInterface
82
+ },
83
+
84
+ setReleaseHistory: async (
85
+ targetBinaryVersion: string,
86
+ jsonFilePath: string,
87
+ releaseInfo: ReleaseHistoryInterface,
88
+ platform: 'ios' | 'android',
89
+ identifier = 'staging'
90
+ ): Promise<void> => {
91
+ const fileContent = fs.readFileSync(jsonFilePath, 'utf8')
92
+ const remoteJsonPath = historyJsonFileRemotePath(
93
+ platform,
94
+ identifier,
95
+ targetBinaryVersion
96
+ )
97
+
98
+ try {
99
+ await s3Client.send(
100
+ new PutObjectCommand({
101
+ Bucket: BUCKET_NAME,
102
+ Key: remoteJsonPath,
103
+ Body: fileContent,
104
+ ContentType: 'application/json',
105
+ CacheControl: 'max-age=5',
106
+ })
107
+ )
108
+
109
+ console.log(
110
+ 'Release history File uploaded:',
111
+ `${CDN_URL}/${remoteJsonPath}`
112
+ )
113
+ } catch (error) {
114
+ console.error('Error uploading release history:', error)
115
+ throw error
116
+ }
117
+ },
118
+ }
119
+
120
+ module.exports = Config
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@algocare/react-native-code-push",
3
- "version": "9.0.0-beta.3",
3
+ "version": "9.0.0-beta.4",
4
4
  "description": "React Native plugin for the CodePush service",
5
5
  "main": "CodePush.js",
6
6
  "typings": "typings/react-native-code-push.d.ts",
@@ -38,9 +38,11 @@
38
38
  },
39
39
  "repository": {
40
40
  "type": "git",
41
- "url": "git+https://github.com/Soomgo-Mobile/react-native-code-push.git"
41
+ "url": "git+https://github.com/algo-care/react-native-code-push.git"
42
42
  },
43
43
  "dependencies": {
44
+ "@aws-sdk/client-s3": "^3.744.0",
45
+ "axios": "^1.7.9",
44
46
  "commander": "^12.1.0",
45
47
  "hoist-non-react-statics": "^3.3.2",
46
48
  "semver": "^7.3.5",