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

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,109 @@
1
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2
+ // @ts-nocheck
3
+
4
+ const { S3Client, PutObjectCommand } = require('@aws-sdk/client-s3')
5
+ const fs = require('fs')
6
+ const axios = require('axios')
7
+ require('dotenv').config()
8
+
9
+ const s3Client = new S3Client({
10
+ region: process.env.AWS_REGION,
11
+ credentials: {
12
+ accessKeyId: process.env.AWS_ACCESS_KEY_ID,
13
+ secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
14
+ },
15
+ })
16
+
17
+ const BUCKET_NAME = process.env.AWS_S3_BUCKET || 'codepush-bucket'
18
+ const CDN_URL = process.env.CDN_URL || `https://${BUCKET_NAME}.s3.amazonaws.com`
19
+
20
+ function historyJsonFileRemotePath(app, platform, identifier, binaryVersion) {
21
+ return `histories/${app}/${platform}/${identifier}/${binaryVersion}.json`
22
+ }
23
+
24
+ function bundleFileRemotePath(app, platform, identifier, fileName) {
25
+ return `bundles/${app}/${platform}/${identifier}/${fileName}`
26
+ }
27
+
28
+ const Config = {
29
+ bundleUploader: async (source, app, platform, identifier = 'staging') => {
30
+ const fileName = source.split('/').pop()
31
+ const fileContent = fs.readFileSync(source)
32
+ const remotePath = bundleFileRemotePath(app, platform, identifier, fileName)
33
+
34
+ try {
35
+ await s3Client.send(
36
+ new PutObjectCommand({
37
+ Bucket: BUCKET_NAME,
38
+ Key: remotePath,
39
+ Body: fileContent,
40
+ ContentType: 'application/zip',
41
+ })
42
+ )
43
+
44
+ console.log('Bundle File uploaded:', `${CDN_URL}/${remotePath}`)
45
+
46
+ return {
47
+ downloadUrl: `${CDN_URL}/${remotePath}`,
48
+ }
49
+ } catch (error) {
50
+ console.error('Error uploading bundle:', error)
51
+ throw error
52
+ }
53
+ },
54
+
55
+ getReleaseHistory: async (
56
+ targetBinaryVersion,
57
+ app,
58
+ platform,
59
+ identifier = 'staging'
60
+ ) => {
61
+ const remoteJsonPath = historyJsonFileRemotePath(
62
+ app,
63
+ platform,
64
+ identifier,
65
+ targetBinaryVersion
66
+ )
67
+ const { data } = await axios.get(`${CDN_URL}/${remoteJsonPath}`)
68
+ return data
69
+ },
70
+
71
+ setReleaseHistory: async (
72
+ targetBinaryVersion,
73
+ jsonFilePath,
74
+ releaseInfo,
75
+ app,
76
+ platform,
77
+ identifier = 'staging'
78
+ ) => {
79
+ const fileContent = fs.readFileSync(jsonFilePath, 'utf8')
80
+ const remoteJsonPath = historyJsonFileRemotePath(
81
+ app,
82
+ platform,
83
+ identifier,
84
+ targetBinaryVersion
85
+ )
86
+
87
+ try {
88
+ await s3Client.send(
89
+ new PutObjectCommand({
90
+ Bucket: BUCKET_NAME,
91
+ Key: remoteJsonPath,
92
+ Body: fileContent,
93
+ ContentType: 'application/json',
94
+ CacheControl: 'max-age=5',
95
+ })
96
+ )
97
+
98
+ console.log(
99
+ 'Release history File uploaded:',
100
+ `${CDN_URL}/${remoteJsonPath}`
101
+ )
102
+ } catch (error) {
103
+ console.error('Error uploading release history:', error)
104
+ throw error
105
+ }
106
+ },
107
+ }
108
+
109
+ module.exports = Config
@@ -0,0 +1,132 @@
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'
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
+ app: 'user' | 'device',
25
+ platform: 'ios' | 'android',
26
+ identifier: string,
27
+ binaryVersion: string
28
+ ) {
29
+ return `histories/${app}/${platform}/${identifier}/${binaryVersion}.json`
30
+ }
31
+
32
+ function bundleFileRemotePath(
33
+ app: 'user' | 'device',
34
+ platform: 'ios' | 'android',
35
+ identifier: string,
36
+ fileName: string
37
+ ) {
38
+ return `bundles/${app}/${platform}/${identifier}/${fileName}`
39
+ }
40
+
41
+ const Config: CliConfigInterface = {
42
+ bundleUploader: async (
43
+ source: string,
44
+ app: 'user' | 'device',
45
+ platform: 'ios' | 'android',
46
+ identifier = 'staging'
47
+ ): Promise<{ downloadUrl: string }> => {
48
+ const fileName = source.split('/').pop()
49
+ const fileContent = fs.readFileSync(source)
50
+ const remotePath = bundleFileRemotePath(
51
+ app,
52
+ platform,
53
+ identifier,
54
+ fileName!
55
+ )
56
+
57
+ try {
58
+ await s3Client.send(
59
+ new PutObjectCommand({
60
+ Bucket: BUCKET_NAME,
61
+ Key: remotePath,
62
+ Body: fileContent,
63
+ ContentType: 'application/zip',
64
+ })
65
+ )
66
+
67
+ console.log('Bundle File uploaded:', `${CDN_URL}/${remotePath}`)
68
+
69
+ return {
70
+ downloadUrl: `${CDN_URL}/${remotePath}`,
71
+ }
72
+ } catch (error) {
73
+ console.error('Error uploading bundle:', error)
74
+ throw error
75
+ }
76
+ },
77
+
78
+ getReleaseHistory: async (
79
+ app: 'user' | 'device',
80
+ targetBinaryVersion: string,
81
+ platform: 'ios' | 'android',
82
+ identifier = 'staging'
83
+ ): Promise<ReleaseHistoryInterface> => {
84
+ const remoteJsonPath = historyJsonFileRemotePath(
85
+ app,
86
+ platform,
87
+ identifier,
88
+ targetBinaryVersion
89
+ )
90
+ const { data } = await axios.get(`${CDN_URL}/${remoteJsonPath}`)
91
+ return data as ReleaseHistoryInterface
92
+ },
93
+
94
+ setReleaseHistory: async (
95
+ targetBinaryVersion: string,
96
+ jsonFilePath: string,
97
+ releaseInfo: ReleaseHistoryInterface,
98
+ app: 'user' | 'device',
99
+ platform: 'ios' | 'android',
100
+ identifier = 'staging'
101
+ ): Promise<void> => {
102
+ const fileContent = fs.readFileSync(jsonFilePath, 'utf8')
103
+ const remoteJsonPath = historyJsonFileRemotePath(
104
+ app,
105
+ platform,
106
+ identifier,
107
+ targetBinaryVersion
108
+ )
109
+
110
+ try {
111
+ await s3Client.send(
112
+ new PutObjectCommand({
113
+ Bucket: BUCKET_NAME,
114
+ Key: remoteJsonPath,
115
+ Body: fileContent,
116
+ ContentType: 'application/json',
117
+ CacheControl: 'max-age=5',
118
+ })
119
+ )
120
+
121
+ console.log(
122
+ 'Release history File uploaded:',
123
+ `${CDN_URL}/${remoteJsonPath}`
124
+ )
125
+ } catch (error) {
126
+ console.error('Error uploading release history:', error)
127
+ throw error
128
+ }
129
+ },
130
+ }
131
+
132
+ 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.5",
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,11 +38,14 @@
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",
48
+ "inquirer": "^12.4.2",
46
49
  "semver": "^7.3.5",
47
50
  "shelljs": "^0.8.5",
48
51
  "yazl": "^3.3.1"
@@ -54,7 +57,7 @@
54
57
  "@types/assert": "^1.5.2",
55
58
  "@types/mkdirp": "^1.0.1",
56
59
  "@types/mocha": "^9.0.0",
57
- "@types/node": "^14.0.27",
60
+ "@types/node": "^18.0.0",
58
61
  "@types/q": "^1.5.4",
59
62
  "@types/semver": "^7.5.8",
60
63
  "@types/shelljs": "^0.8.15",
package/tsconfig.json CHANGED
@@ -1,14 +1,20 @@
1
1
  {
2
+ "compilerOptions": {
3
+ "target": "ES5",
4
+ "module": "CommonJS",
5
+ "lib": ["es6"],
6
+ "noImplicitAny": true,
7
+ "noEmitOnError": true,
8
+ "moduleResolution": "node",
9
+ "sourceMap": true,
10
+ "rootDir": "test",
11
+ "outDir": "bin",
12
+ "removeComments": true,
13
+ "esModuleInterop": true
14
+ },
15
+ "ts-node": {
2
16
  "compilerOptions": {
3
- "target": "ES5",
4
- "module": "commonjs",
5
- "lib": ["es6"],
6
- "noImplicitAny": true,
7
- "noEmitOnError": true,
8
- "moduleResolution": "node",
9
- "sourceMap": true,
10
- "rootDir": "test",
11
- "outDir": "bin",
12
- "removeComments": true
17
+ "module": "commonjs"
13
18
  }
19
+ }
14
20
  }