Skip to content

Commit

Permalink
add core build to CDN output
Browse files Browse the repository at this point in the history
  • Loading branch information
kochis committed Jun 13, 2024
1 parent 5b96c9e commit 84911cb
Show file tree
Hide file tree
Showing 7 changed files with 256 additions and 12 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Radar.initialize('prj_test_pk_...', { /* options */ });
Add the following script in your `html` file
```html
<script src="https://js.radar.com/v4.3.0/radar.min.js"></script>
<script src="https://js.radar.com/v4.3.2-beta.0/radar.min.js"></script>
```

Then initialize the Radar SDK
Expand All @@ -73,8 +73,8 @@ To create a map, first initialize the Radar SDK with your publishable key. Then
```html
<html>
<head>
<link href="https://js.radar.com/v4.3.0/radar.css" rel="stylesheet">
<script src="https://js.radar.com/v4.3.0/radar.min.js"></script>
<link href="https://js.radar.com/v4.3.2-beta.0/radar.css" rel="stylesheet">
<script src="https://js.radar.com/v4.3.2-beta.0/radar.min.js"></script>
</head>

<body>
Expand All @@ -98,8 +98,8 @@ To create an autocomplete input, first initialize the Radar SDK with your publis
```html
<html>
<head>
<link href="https://js.radar.com/v4.3.0/radar.css" rel="stylesheet">
<script src="https://js.radar.com/v4.3.0/radar.min.js"></script>
<link href="https://js.radar.com/v4.3.2-beta.0/radar.css" rel="stylesheet">
<script src="https://js.radar.com/v4.3.2-beta.0/radar.min.js"></script>
</head>

<body>
Expand Down Expand Up @@ -130,8 +130,8 @@ To power [geofencing](https://radar.com/documentation/geofencing/overview) exper
```html
<html>
<head>
<link href="https://js.radar.com/v4.3.0/radar.css" rel="stylesheet">
<script src="https://js.radar.com/v4.3.0/radar.min.js"></script>
<link href="https://js.radar.com/v4.3.2-beta.0/radar.css" rel="stylesheet">
<script src="https://js.radar.com/v4.3.2-beta.0/radar.min.js"></script>
</head>

<body>
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "radar-sdk-js",
"version": "4.3.0",
"version": "4.3.2-beta.0",
"description": "Web Javascript SDK for Radar, location infrastructure for mobile and web apps.",
"homepage": "https://radar.com",
"type": "module",
Expand Down
29 changes: 29 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,34 @@ export default [
minimize: true,
}),
],
},

// IIFE (core SDK feature - no maps)
{
input: 'src/core.ts',
output: [
{
file: 'cdn/radar-core.js',
format: 'iife',
name: 'Radar',
plugins: [onlyEmitFile()],
},
{
file: 'cdn/radar-core.min.js',
format: 'iife',
name: 'Radar',
plugins: [terser(), onlyEmitFile()],
},
],
plugins: [
typescript(),
nodeResolve(),
commonjs(),
json(),
postcss({
extract: 'radar.css',
minimize: true,
}),
],
}
];
4 changes: 2 additions & 2 deletions scripts/check-beta-tag.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ if (!tagVersion.startsWith('v')) {
console.error('Tag must start with "v"');
process.exit(1);
}
if (!tagVersion.includes('-beta')) {
console.error('Prelease version should contiain a "-beta" suffix');
if (!tagVersion.includes('-beta') && !tagVersion.includes('-core')) {
console.error('Prelease version should contiain a "-beta" or "-core" suffix');
process.exit(1);
}
tagVersion = tagVersion.slice(1); // remove "v"
Expand Down
215 changes: 215 additions & 0 deletions src/core.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
import Config from './config';
import Logger from './logger';
import Storage from './storage';
import Navigator from './navigator';
import { RadarPublishableKeyError } from './errors';

import AddressesAPI from './api/addresses';
import ConfigAPI from './api/config';
import ContextAPI from './api/context';
import ConversionsAPI from './api/conversions';
import GeocodingAPI from './api/geocoding';
import RoutingAPI from './api/routing';
import SearchAPI from './api/search';
import TrackAPI from './api/track';
import TripsAPI from './api/trips';
import VerifyAPI from './api/verify';

import SDK_VERSION from './version';

import type {
Location,
RadarAutocompleteParams,
RadarConversionParams,
RadarDistanceParams,
RadarForwardGeocodeParams,
RadarMatrixParams,
RadarMetadata,
RadarOptions,
RadarReverseGeocodeParams,
RadarSearchGeofencesParams,
RadarSearchPlacesParams,
RadarTrackParams,
RadarTripOptions,
RadarValidateAddressParams,
} from './types';

import '../styles/radar.css';


const isSecretKey = (key: string): boolean => (
key.includes('_sk_')
);
const isLiveKey = (key: string): boolean => (
key.includes('_live_')
);

class Radar {
public static get VERSION() {
return SDK_VERSION;
}

public static initialize(publishableKey: string, options: RadarOptions = {}) {
if (!publishableKey) {
throw new RadarPublishableKeyError('Publishable key required in initialization.');
}

if (isSecretKey(publishableKey)) {
throw new RadarPublishableKeyError('Secret keys are not allowed. Please use your Radar publishable key.');
}

// store settings in global config
const live = isLiveKey(publishableKey);
const logLevel = live ? 'error' : 'info';
const debug = !live;
const radarOptions = Object.assign(
Config.defaultOptions,
{
publishableKey,
live,
logLevel,
debug,
},
options,
);
Config.setup(radarOptions);

Logger.info(`initialized with ${live ? 'live' : 'test'} publishableKey.`);
if (options.debug) {
Logger.info(`using options: ${JSON.stringify(options)}`);
}

// NOTE(jasonl): this allows us to run jest tests
// without having to mock the ConfigAPI.getConfig call
if (!(window as any)?.RADAR_TEST_ENV) {
ConfigAPI.getConfig();
}
}

public static clear() {
Config.clear();
}

///////////////////////
// geofencing platform
///////////////////////

public static setUserId(userId?: string) {
if (!userId) {
Storage.removeItem(Storage.USER_ID);
return;
}
Storage.setItem(Storage.USER_ID, String(userId).trim());
}

public static setDescription(description?: string) {
if (!description) {
Storage.removeItem(Storage.DESCRIPTION);
return;
}
Storage.setItem(Storage.DESCRIPTION, String(description).trim());
}

public static setMetadata(metadata?: RadarMetadata) {
if (!metadata) {
Storage.removeItem(Storage.METADATA);
return;
}
Storage.setItem(Storage.METADATA, JSON.stringify(metadata));
}

public static getLocation() {
return Navigator.getCurrentPosition();
}

public static trackOnce(params: RadarTrackParams = {}) {
try {
return TrackAPI.trackOnce(params);
} finally {
ConfigAPI.getConfig(params); // call with updated permissions
}
}

public static trackVerified(params: RadarTrackParams = {}) {
return VerifyAPI.trackVerified(params);
}

public static getContext(params: Location) {
return ContextAPI.getContext(params);
}

public static setTripOptions(tripOptions?: RadarTripOptions) {
TripsAPI.setTripOptions(tripOptions);
}

public static clearTripOptions() {
TripsAPI.clearTripOptions();
}

public static getTripOptions() {
return TripsAPI.getTripOptions();
}

public static startTrip(tripOptions: RadarTripOptions) {
return TripsAPI.startTrip(tripOptions);
}

public static updateTrip(tripOptions: RadarTripOptions) {
return TripsAPI.updateTrip(tripOptions);
}

public static completeTrip() {
return TripsAPI.completeTrip();
}

public static cancelTrip() {
return TripsAPI.cancelTrip();
}

public static logConversion(params: RadarConversionParams) {
return ConversionsAPI.logConversion(params);
}


/////////////////
// maps platform
/////////////////

public static forwardGeocode(params: RadarForwardGeocodeParams) {
return GeocodingAPI.forwardGeocode(params);
}

public static reverseGeocode(params: RadarReverseGeocodeParams) {
return GeocodingAPI.reverseGeocode(params);
}

public static ipGeocode() {
return GeocodingAPI.ipGeocode();
}

public static autocomplete(params: RadarAutocompleteParams) {
return SearchAPI.autocomplete(params);
}

public static searchGeofences(params: RadarSearchGeofencesParams) {
return SearchAPI.searchGeofences(params);
}

public static searchPlaces(params: RadarSearchPlacesParams) {
return SearchAPI.searchPlaces(params);
}

public static validateAddress(params: RadarValidateAddressParams) {
return AddressesAPI.validateAddress(params);
}

public static distance(params: RadarDistanceParams) {
return RoutingAPI.distance(params);
}

public static matrix(params: RadarMatrixParams) {
return RoutingAPI.matrix(params);
}
}

export default Radar;
2 changes: 1 addition & 1 deletion src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default '4.3.0';
export default '4.3.2-beta.0';

0 comments on commit 84911cb

Please sign in to comment.