Skip to content

Commit

Permalink
Merge branch 'main' into samsung-pay
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanskar2001 committed Oct 29, 2024
2 parents d7e156c + 6b665db commit 30bd83f
Show file tree
Hide file tree
Showing 40 changed files with 639 additions and 156 deletions.
2 changes: 1 addition & 1 deletion android
Submodule android updated 137 files
2 changes: 1 addition & 1 deletion ios
Submodule ios updated from e6e36b to 25cb4e
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hyperswitch",
"version": "1.0.0",
"version": "1.0.1",
"private": true,
"scripts": {
"start": "react-native start --reset-cache",
Expand All @@ -9,7 +9,7 @@
"re:format": "rescript format -all",
"web": "webpack serve --mode=development --config reactNativeWeb/webpack.config.js",
"ios": "cd ios && rm -rf build && pod install && cd .. && react-native run-ios",
"android": "react-native run-android && yarn run adb",
"android": "react-native run-android --appIdSuffix demoapp --main-activity .demoapp.MainActivity && yarn run adb",
"web:next": "next",
"bundle:android": "react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/hyperswitch.bundle",
"bundle:ios": "react-native bundle --platform ios --dev false --entry-file index.js --bundle-output ios/hyperswitchSDK/Core/Resources/hyperswitch.bundle",
Expand All @@ -26,6 +26,7 @@
"clean:pod": "cd ios && pod deintegrate && cd ..",
"clean:gradle:cache": "rm -rf ~/.gradle",
"clean:pod:cache": "pod cache clean --all",
"deploy-to-s3": "node ./scripts/pushToS3.js",
"lint": "eslint .",
"test": "jest",
"prepare": "husky"
Expand Down
36 changes: 36 additions & 0 deletions patches/@react-native+assets-registry+0.75.4.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
diff --git a/node_modules/@react-native/assets-registry/registry.js b/node_modules/@react-native/assets-registry/registry.js
index 02470da..3851d92 100644
--- a/node_modules/@react-native/assets-registry/registry.js
+++ b/node_modules/@react-native/assets-registry/registry.js
@@ -10,28 +10,15 @@

'use strict';

-export type PackagerAsset = {
- +__packager_asset: boolean,
- +fileSystemLocation: string,
- +httpServerLocation: string,
- +width: ?number,
- +height: ?number,
- +scales: Array<number>,
- +hash: string,
- +name: string,
- +type: string,
- ...
-};
+const assets = [];

-const assets: Array<PackagerAsset> = [];
-
-function registerAsset(asset: PackagerAsset): number {
+function registerAsset(asset) {
// `push` returns new array length, so the first asset will
// get id 1 (not 0) to make the value truthy
return assets.push(asset);
}

-function getAssetByID(assetId: number): PackagerAsset {
+function getAssetByID(assetId) {
return assets[assetId - 1];
}

9 changes: 7 additions & 2 deletions react-native.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
module.exports = {
assets:['./assets/fonts/'],
}
assets: ['./assets/fonts/'],
project: {
android: {
appName: 'demo-app',
},
},
};
3 changes: 3 additions & 0 deletions reactNativeWeb/version.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"version": "1.0.7"
}
11 changes: 8 additions & 3 deletions reactNativeWeb/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ const HtmlWebpackPlugin = require('html-webpack-plugin');
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
const appDirectory = path.resolve(__dirname);
const {presets, plugins} = require(`${appDirectory}/babel.config.js`);
const isDevelopment = process.env.NODE_ENV !== 'production';
console.log('dev mode --- >', isDevelopment);
// const isDevelopment = process.env.NODE_ENV !== 'production';
const isDevelopment = false;
const repoVersion = require("./version.json").version;
const majorVersion = "v" + repoVersion.split(".")[0];
const repoPublicPath = `/mobile/${repoVersion}/mobile/${majorVersion}`;

// console.log('dev mode --- >', isDevelopment);
const compileNodeModules = [
// Add every react-native package that needs compiling
// 'react-native-gesture-handler',
Expand Down Expand Up @@ -79,8 +84,8 @@ module.exports = {
},
output: {
path: path.resolve(appDirectory, 'dist'),
publicPath: '/',
filename: 'index.bundle.js',
publicPath: `${repoPublicPath}/`,
},
devtool: 'source-map',
devServer: {
Expand Down
209 changes: 209 additions & 0 deletions scripts/prepareS3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
const { PutObjectCommand } = require("@aws-sdk/client-s3");
const {
CreateInvalidationCommand,
GetDistributionConfigCommand,
UpdateDistributionCommand,
GetInvalidationCommand,
CloudFrontClient,
} = require("@aws-sdk/client-cloudfront");
const FileSystem = require("fs");
const { globSync } = require("fast-glob");
const Mime = require("mime-types");
const { S3Client } = require("@aws-sdk/client-s3");

const CACHE_CONTROL = "max-age=315360000";
const EXPIRATION_DATE = "Thu, 31 Dec 2037 23:55:55 GMT";

function withSlash(str) {
return typeof str === "string" ? `/${str}` : "";
}

function withHyphen(str) {
return typeof str === "string" ? `${str}-` : "";
}

function createCloudFrontClient(region) {
return new CloudFrontClient({ region });
}

function createS3Client(region) {
return new S3Client({ region });
}

async function doInvalidation(distributionId, urlPrefix, region, s3Bucket) {
const cloudfrontClient = createCloudFrontClient(region);
const cloudfrontInvalidationRef = new Date().toISOString();

const cfParams = {
DistributionId: distributionId,
InvalidationBatch: {
CallerReference: cloudfrontInvalidationRef,
Paths: {
Quantity: s3Bucket === process.env.S3_SANDBOX_BUCKET ? 2 : 1,
Items:
s3Bucket === process.env.S3_SANDBOX_BUCKET
? [`/mobile${withSlash(urlPrefix)}/*`, `/mobile${withSlash("v0")}/*`]
: [`/mobile${withSlash(urlPrefix)}/*`],
},
},
};

const command = new CreateInvalidationCommand(cfParams);
let response = await cloudfrontClient.send(command);
const invalidationId = response.Invalidation.Id;
let retryCounter = 0;

while (response.Invalidation.Status === "InProgress" && retryCounter < 100) {
await new Promise((resolve) => setTimeout(resolve, 3000));
const getInvalidationParams = {
DistributionId: distributionId,
Id: invalidationId,
};
const statusCommand = new GetInvalidationCommand(getInvalidationParams);
response = await cloudfrontClient.send(statusCommand);
retryCounter++;
}

if (retryCounter >= 100) {
console.log(`Still InProgress after ${retryCounter} retries`);
}
}

async function getDistribution(distributionId, region) {
const getDistributionConfigCmd = new GetDistributionConfigCommand({
Id: distributionId,
});

const cloudfrontClient = createCloudFrontClient(region);
const { DistributionConfig, ETag } = await cloudfrontClient.send(
getDistributionConfigCmd
);

return { DistributionConfig, ETag };
}

async function updateDistribution({
urlPrefix,
distributionId,
version,
DistributionConfig,
ETag,
region,
}) {
const cloudfrontClient = createCloudFrontClient(region);
let matchingItem;
matchingItem = DistributionConfig.Origins.Items.find((item) =>
item.Id.startsWith("mobile-v1")
);
if (matchingItem) {
matchingItem.OriginPath = `/${version}`;
} else {
const defaultItem =
DistributionConfig.Origins.Items.find((item) => item.OriginPath === "") ||
DistributionConfig.Origins.Items[0];

if (defaultItem) {
const clonedOrigin = JSON.parse(JSON.stringify(defaultItem));
clonedOrigin.Id = `${withHyphen(urlPrefix)}${clonedOrigin.Id}`;
clonedOrigin.OriginPath = `/${version}`;

DistributionConfig.Origins.Items.unshift(clonedOrigin);
DistributionConfig.Origins.Quantity += 1;

if (DistributionConfig.CacheBehaviors.Items.length > 0) {
const clonedBehavior = JSON.parse(
JSON.stringify(DistributionConfig.CacheBehaviors.Items[0])
);
if (urlPrefix) clonedBehavior.PathPattern = `${urlPrefix}/*`;
clonedBehavior.TargetOriginId = clonedOrigin.Id;

DistributionConfig.CacheBehaviors.Items.unshift(clonedBehavior);
DistributionConfig.CacheBehaviors.Quantity += 1;
}
}
}

const updateDistributionCmd = new UpdateDistributionCommand({
DistributionConfig,
Id: distributionId,
IfMatch: ETag,
});

await cloudfrontClient.send(updateDistributionCmd);
}

async function uploadFile(s3Bucket, version, urlPrefix, distFolder, region) {
const entries = globSync(`${distFolder}/**/*`);
const s3Client = createS3Client(region);

for (const val of entries) {
const fileName = val.replace(`${distFolder}/`, "");
const bufferData = FileSystem.readFileSync(val);
const mimeType = Mime.lookup(val);

const params = {
Bucket: s3Bucket,
Key: `${version}/mobile${withSlash(urlPrefix)}/${fileName}`,
Body: bufferData,
Metadata: {
"Cache-Control": CACHE_CONTROL,
Expires: EXPIRATION_DATE,
},
ContentType: mimeType,
};

await s3Client.send(new PutObjectCommand(params));

if (s3Bucket === process.env.S3_SANDBOX_BUCKET) {
const sandboxParams = {
...params,
Key: `${version}/mobile${withSlash("v0")}/${fileName}`,
};
await s3Client.send(new PutObjectCommand(sandboxParams));
}

console.log(`Successfully uploaded to ${params.Key}`);
}
}

const run = async (params) => {
console.log("run parameters ---", params);
let { s3Bucket, distributionId, urlPrefix, version, distFolder, region } =
params;
try {
const isVersioned = urlPrefix === "v0" || urlPrefix === "v1";

if (isVersioned) {
await uploadFile(s3Bucket, version, "v0", distFolder, region);
await uploadFile(s3Bucket, version, "v1", distFolder, region);
} else {
await uploadFile(s3Bucket, version, urlPrefix, distFolder, region);
}
if (s3Bucket !== process.env.S3_PROD_BUCKET) {
const distributionInfo = await getDistribution(distributionId, region);
console.log("distributionInfo completed");
await updateDistribution({
...distributionInfo,
distributionId,
urlPrefix,
version,
region,
});
console.log("updateDistribution completed");
if (isVersioned) {
await doInvalidation(distributionId, "v0", region, s3Bucket);
await doInvalidation(distributionId, "v1", region, s3Bucket);
} else {
await doInvalidation(distributionId, urlPrefix, region, s3Bucket);
}
console.log("doInvalidation completed");
}
} catch (err) {
console.error("Error", err);
throw err;
}
};

module.exports = {
run,
};
15 changes: 15 additions & 0 deletions scripts/pushToS3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const { run } = require("./prepareS3.js");
const { version } = require("../reactNativeWeb/version.json");
const path = require("path");
const BASE_PATH = "mobile";

let params = {
s3Bucket: process.env.BUCKET_NAME,
distributionId: process.env.DIST_ID,
urlPrefix: `v${version.split(".")[0]}`,
version: `${BASE_PATH}/${version}`,
distFolder: path.resolve(__dirname, "..", "reactNativeWeb/dist"),
region: process.env.AWS_REGION,
};

run(params);
30 changes: 30 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,36 @@ app.get('/create-ephemeral-key', async (req, res) => {
}
});

app.get('/payment_methods', async (req, res) => {
try {
const response = await fetch(
`https://sandbox.hyperswitch.io/payment_methods`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
'api-key': process.env.HYPERSWITCH_SECRET_KEY,
},
body: JSON.stringify({customer_id: 'hyperswitch_sdk_demo_id'}),
},
);
const json = await response.json();

res.send({
customerId: json.customer_id,
paymentMethodId: json.payment_method_id,
clientSecret: json.client_secret,
publishableKey: process.env.HYPERSWITCH_PUBLISHABLE_KEY,
});
} catch (err) {
return res.status(400).send({
error: {
message: err.message,
},
});
}
});

app.listen(5252, () =>
console.log(`Node server listening at http://localhost:5252`),
);
11 changes: 1 addition & 10 deletions src/components/common/CustomInput.res
Original file line number Diff line number Diff line change
Expand Up @@ -211,16 +211,7 @@ let make = (
placeholderTextColor={placeholderTextColor->Option.getOr(placeholderColor)}
value={state}
?onKeyPress
onChangeText={text => {
logger(
~logType=INFO,
~value=text,
~category=USER_EVENT,
~eventName=INPUT_FIELD_CHANGED,
(),
)
setState(text)
}}
onChangeText={text => setState(text)}
keyboardType
autoFocus
autoComplete={#off}
Expand Down
Loading

0 comments on commit 30bd83f

Please sign in to comment.