Skip to content

Commit

Permalink
chore(dist): optimize size (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
pladaria authored Oct 14, 2024
1 parent 53bdd41 commit ca63977
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 39 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tef-novum/webview-bridge",
"version": "3.41.0",
"version": "3.42.0",
"description": "JavaScript library to access to native functionality. Requires a webview with a postMessage bridge.",
"main": "./dist/webview-bridge-cjs.js",
"module": "./dist/webview-bridge.mjs",
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/utils-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ test('fetch without bridge', async () => {
expect(res).toEqual({
status: 500,
headers: {},
body: 'Bridge not available',
body: 'Bridge call failed',
});
});
});
Expand Down
4 changes: 3 additions & 1 deletion src/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ export const sanitizeAnalyticsParams = (params: {
[key: string]: FirebaseValue;
}): {[key: string]: FirebaseValue} => {
const sanitizedParams: {[key: string]: FirebaseValue} = {};
Object.entries(params).forEach(([key, value]) => {
Object.entries(params).forEach((entry) => {
const key = entry[0];
const value = entry[1];
let sanitizedValue = value;
const sanitizedKey = key.slice(0, EVENT_PARAM_NAME_CHARS_LIMIT);
if (typeof value === 'string') {
Expand Down
35 changes: 18 additions & 17 deletions src/bottom-sheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,29 +85,30 @@ type SheetUI = Readonly<{

let sheetLock = false;

export const bottomSheet = async (payload: SheetUI): Promise<SheetResponse> => {
export const bottomSheet = (payload: SheetUI): Promise<SheetResponse> => {
if (sheetLock) {
throw {
return Promise.reject({
code: 423,
reason: 'BottomSheet is locked. You can only have one bottom sheet in the screen',
};
});
}

sheetLock = true;
const tid = setTimeout(() => {
sheetLock = false;
}, 1000);

try {
const response = await postMessageToNativeApp({type: 'SHEET', payload});
sheetLock = false;
clearTimeout(tid);
return response;
} catch (e) {
sheetLock = false;
clearTimeout(tid);
throw e;
}
return postMessageToNativeApp({type: 'SHEET', payload})
.then((response) => {
sheetLock = false;
clearTimeout(tid);
return response;
})
.catch((e) => {
sheetLock = false;
clearTimeout(tid);
throw e;
});
};

export const bottomSheetSingleSelector = ({
Expand Down Expand Up @@ -208,7 +209,7 @@ export const bottomSheetActionSelector = ({
}
});

export const bottomSheetInfo = async ({
export const bottomSheetInfo = ({
title,
subtitle,
description,
Expand All @@ -219,7 +220,7 @@ export const bottomSheetInfo = async ({
description?: string;
items: Array<SheetInfoItem>;
}): Promise<void> => {
await bottomSheet({
return bottomSheet({
title,
subtitle,
description,
Expand All @@ -233,10 +234,10 @@ export const bottomSheetInfo = async ({
items,
},
],
});
}).then(() => undefined);
};

export const bottomSheetActions = async ({
export const bottomSheetActions = ({
title,
subtitle,
description,
Expand Down
6 changes: 3 additions & 3 deletions src/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ const TIMEOUT = 200;
/** @deprecated */
export const requestSimIcc = (): Promise<string | null> =>
postMessageToNativeApp({type: 'SIM_ICC'}, TIMEOUT)
.then(({icc}) => icc)
.then((response) => response.icc)
.catch(() => null);

/** @deprecated */
export const requestSimImsi = (): Promise<string | null> =>
postMessageToNativeApp({type: 'IMSI'}, TIMEOUT)
.then(({imsi}) => imsi)
.then((response) => response.imsi)
.catch(() => null);

export const requestDeviceImei = (): Promise<string | null> =>
postMessageToNativeApp({type: 'IMEI'}, TIMEOUT)
.then(({imei}) => imei)
.then((response) => response.imei)
.catch(() => null);

type RoutesAvalaible = 'notification-settings' | 'contact-settings';
Expand Down
6 changes: 3 additions & 3 deletions src/sessions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const renewSession = (
payload: {accessToken: oldAccessToken || null},
},
options.timeout,
).then(({accessToken}) => accessToken);
).then((result) => result.accessToken);

/**
* This method is used to listen for session renewals made by native app. Whenever the native app
Expand All @@ -25,8 +25,8 @@ export const renewSession = (
export const onSessionRenewed = (
handler: (newAccessToken: string) => void,
): (() => void) =>
listenToNativeMessage('SESSION_RENEWED', ({accessToken}) =>
handler(accessToken),
listenToNativeMessage('SESSION_RENEWED', (result) =>
handler(result.accessToken),
);

/**
Expand Down
19 changes: 6 additions & 13 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,21 +216,14 @@ export const fetch = ({
headers: {[key: string]: string};
body: string;
}): Promise<NativeAppResponsePayload<'FETCH'>> => {
if (isWebViewBridgeAvailable()) {
return postMessageToNativeApp({
type: 'FETCH',
payload: {url, method, headers, body},
}).catch(() => ({
status: 500,
headers: {},
body: 'Bridge call failed',
}));
}
return Promise.resolve({
return postMessageToNativeApp({
type: 'FETCH',
payload: {url, method, headers, body},
}).catch(() => ({
status: 500,
headers: {},
body: 'Bridge not available',
});
body: 'Bridge call failed',
}));
};

type PermissionsStatus = 'notifications' | 'read-contacts' | 'write-contacts';
Expand Down

0 comments on commit ca63977

Please sign in to comment.