Skip to content

Commit 3565bf2

Browse files
committed
more clean up
- remove redundant environment constants
1 parent 0ea6f3e commit 3565bf2

6 files changed

Lines changed: 17 additions & 25 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
},
8383
{
8484
"path": "./build/releases/OneSignalSDK.page.es6.js",
85-
"limit": "52.245 kB",
85+
"limit": "52.2 kB",
8686
"gzip": true
8787
},
8888
{

src/page/services/DynamicResourceLoader.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { EnvironmentKind } from 'src/shared/environment/constants';
21
import { EnumOutOfRangeArgumentError } from 'src/shared/errors/common';
32
import {
43
BUILD_ORIGIN,
@@ -38,11 +37,11 @@ const getOneSignalCssFileName = () => {
3837
const baseFileName = 'OneSignalSDK.page.styles.css';
3938

4039
// using if statements to have better dead code elimination
41-
if (BUILD_TYPE === EnvironmentKind.Development) return `Dev-${baseFileName}`;
40+
if (BUILD_TYPE === 'development') return `Dev-${baseFileName}`;
4241

43-
if (BUILD_TYPE === EnvironmentKind.Staging) return `Staging-${baseFileName}`;
42+
if (BUILD_TYPE === 'staging') return `Staging-${baseFileName}`;
4443

45-
if (BUILD_TYPE === EnvironmentKind.Production) return baseFileName;
44+
if (BUILD_TYPE === 'production') return baseFileName;
4645
};
4746

4847
const RESOURCE_HTTP_PORT = 4000;
@@ -54,13 +53,13 @@ const getOneSignalResourceUrlPath = () => {
5453
let origin: string;
5554

5655
// using if statements to have better dead code elimination
57-
if (BUILD_TYPE === EnvironmentKind.Development) {
56+
if (BUILD_TYPE === 'development') {
5857
origin = NO_DEV_PORT
5958
? `${protocol}://${BUILD_ORIGIN}`
6059
: `${protocol}://${BUILD_ORIGIN}:${port}`;
61-
} else if (BUILD_TYPE === EnvironmentKind.Staging) {
60+
} else if (BUILD_TYPE === 'staging') {
6261
origin = `https://${BUILD_ORIGIN}`;
63-
} else if (BUILD_TYPE === EnvironmentKind.Production) {
62+
} else if (BUILD_TYPE === 'production') {
6463
origin = 'https://onesignal.com';
6564
} else {
6665
throw EnumOutOfRangeArgumentError('buildEnv');

src/shared/environment/constants.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/shared/environment/detect.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import type { SubscriptionTypeValue } from '../subscriptions/types';
77
import { Browser } from '../useragent/constants';
88
import { getBrowserName, getBrowserVersion } from '../useragent/detect';
99
import { API_ORIGIN, API_TYPE, IS_SERVICE_WORKER } from '../utils/EnvVariables';
10-
import { EnvironmentKind } from './constants';
1110

1211
export const isBrowser = typeof window !== 'undefined';
1312

@@ -46,16 +45,15 @@ export const getOneSignalApiUrl = ({
4645
legacy?: boolean;
4746
} = {}): URL => {
4847
// using if statements to have better dead code elimination
49-
if (API_TYPE === EnvironmentKind.Development) {
48+
if (API_TYPE === 'development') {
5049
return isTurbineEndpoint(action)
5150
? new URL(`http://${API_ORIGIN}:${TURBINE_API_URL_PORT}/api/v1/`)
5251
: new URL(`http://${API_ORIGIN}:${API_URL_PORT}/api/v1/`);
5352
}
5453

55-
if (API_TYPE === EnvironmentKind.Staging)
56-
return new URL(`https://${API_ORIGIN}/api/v1/`);
54+
if (API_TYPE === 'staging') return new URL(`https://${API_ORIGIN}/api/v1/`);
5755

58-
if (API_TYPE === EnvironmentKind.Production)
56+
if (API_TYPE === 'production')
5957
return new URL(
6058
legacy ? 'https://onesignal.com/api/v1/' : 'https://api.onesignal.com/',
6159
);

src/shared/helpers/NetworkUtils.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// Implements logic similar to Android SDK's NetworkUtils
22
// Reference: https://github.com/OneSignal/OneSignal-Android-SDK/blob/5.1.31/OneSignalSDK/onesignal/core/src/main/java/com/onesignal/common/NetworkUtils.kt
33
export const ResponseStatusType = {
4-
INVALID: 'INVALID',
5-
RETRYABLE: 'RETRYABLE',
6-
UNAUTHORIZED: 'UNAUTHORIZED',
7-
MISSING: 'MISSING',
8-
CONFLICT: 'CONFLICT',
4+
INVALID: 0,
5+
RETRYABLE: 1,
6+
UNAUTHORIZED: 2,
7+
MISSING: 3,
8+
CONFLICT: 4,
99
} as const;
1010

1111
type ResponseStatusValue =

src/vite-env.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ declare const __API_ORIGIN__: string;
1717
/**
1818
* Which API environment to use (development, staging, production)
1919
*/
20-
declare const __API_TYPE__: string;
20+
declare const __API_TYPE__: 'development' | 'staging' | 'production';
2121

2222
/**
2323
* Whether or not a dev port should be used
@@ -32,7 +32,7 @@ declare const __BUILD_ORIGIN__: string;
3232
/**
3333
* Which build environment to use (development, staging, production)
3434
*/
35-
declare const __BUILD_TYPE__: string;
35+
declare const __BUILD_TYPE__: 'development' | 'staging' | 'production';
3636

3737
/**
3838
* Whether the current build is for a service worker

0 commit comments

Comments
 (0)