Skip to content

Commit 9264e15

Browse files
gyosheviignatov
andauthored
feat: port to TypeScript, provide type definitions (#29)
* chore: convert code to TypeScript - rename files - add missing declarations - update webpack, add build rules - remove dead code * WIP: successfully build TS, tests fail * chore: reexport Leanplum global Different bundles can be stored in src/bundles * chore: use webpack build for ServiceWorker * chore: remove build step for e2e test * chore: revert string repeat in serviceWorker * chore: generate type definitions for library * feat: add root-level method signatures * chore: update bump_version script * chore: update copyright Co-Authored-By: Ignat Ignatov <[email protected]> * chore: clean up dependencies * chore: update copyright notices Co-authored-by: Ignat Ignatov <[email protected]>
1 parent 64b01d1 commit 9264e15

37 files changed

+1175
-6626
lines changed

.arcconfig

-4
This file was deleted.

.babelrc

-12
This file was deleted.

Gruntfile.js

+1-13
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ module.exports = function (grunt) {
55
grunt.loadNpmTasks('grunt-contrib-uglify')
66
grunt.loadNpmTasks('grunt-mocha-test')
77
grunt.loadNpmTasks('grunt-webpack')
8-
grunt.loadNpmTasks('grunt-babel')
98

109
grunt.initConfig({
1110
eslint: {
@@ -20,17 +19,6 @@ module.exports = function (grunt) {
2019
watch: true
2120
}, webpackConfig)
2221
},
23-
babel: {
24-
options: {
25-
sourceMap: true
26-
},
27-
dist: {
28-
files: {
29-
'dist/sw/sw.js': 'src/PushServiceWorker.js',
30-
'test/e2e/js/index.js': 'test/e2e/js/index.es6.js'
31-
}
32-
}
33-
},
3422
uglify: {
3523
my_target: {
3624
files: {
@@ -65,7 +53,7 @@ module.exports = function (grunt) {
6553
})
6654

6755
grunt.registerTask('lint', ['eslint'])
68-
grunt.registerTask('build', ['webpack:prod', 'babel', 'uglify'])
56+
grunt.registerTask('build', ['webpack:prod', 'uglify'])
6957
grunt.registerTask('test', ['mochaTest'])
7058
grunt.registerTask('default', ['webpack:dev'])
7159
}

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright 2017 Leanplum, Inc.
189+
Copyright 2020 Leanplum, Inc.
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

bump_version.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22
#
33
# LPM | Author: Ben Marten
4-
# Copyright (c) 2017 Leanplum Inc. All rights reserved.
4+
# Copyright (c) 2020 Leanplum Inc. All rights reserved.
55
# Bumps the version in the constants file to a desired version.
66
#
77

@@ -25,4 +25,4 @@ replace() {
2525
}
2626

2727
replace package.json "version\": \"$1\"" "version\": \"$2\""
28-
replace src/Constants.js "SDK_VERSION: '$1'" "SDK_VERSION: '$2'"
28+
replace src/Constants.ts "SDK_VERSION: '$1'" "SDK_VERSION: '$2'"

dist/leanplum.d.ts

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
*
3+
* Copyright 2020 Leanplum Inc. All rights reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* https://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License
16+
**/
17+
18+
type StatusHandler = (success: boolean) => void;
19+
type SimpleHandler = () => void;
20+
type UserAttributes = any;
21+
export default class Leanplum {
22+
static _email: string;
23+
static _deviceName: string;
24+
static _deviceModel: string;
25+
static _systemName: string;
26+
static _systemVersion: string;
27+
static setApiPath(apiPath: string): void;
28+
static setEmail(email: string): void;
29+
/**
30+
* Sets the network timeout.
31+
* @param {number} seconds The timeout in seconds.
32+
*/
33+
static setNetworkTimeout(seconds: number): void;
34+
static setVariantDebugInfoEnabled(variantDebugInfoEnabled: boolean): void;
35+
static getVariantDebugInfo(): {};
36+
static setAppIdForDevelopmentMode(appId: string, accessKey: string): void;
37+
static setAppIdForProductionMode(appId: string, accessKey: string): void;
38+
static setSocketHost(host: string): void;
39+
static setDeviceId(deviceId: string): void;
40+
static setAppVersion(versionName: string): void;
41+
static setDeviceName(deviceName: string): void;
42+
static setDeviceModel(deviceModel: string): void;
43+
static setSystemName(systemName: string): void;
44+
static setSystemVersion(systemVersion: string): void;
45+
static setVariables(variables: Object): void;
46+
static setRequestBatching(batchEnabled: boolean, cooldownSeconds: number): void;
47+
static getVariables(): any;
48+
static getVariable(...args: string[]): any;
49+
static getVariants(): any[];
50+
static addStartResponseHandler(handler: StatusHandler): void;
51+
static addVariablesChangedHandler(handler: SimpleHandler): void;
52+
static removeStartResponseHandler(handler: StatusHandler): void;
53+
static removeVariablesChangedHandler(handler: SimpleHandler): void;
54+
static forceContentUpdate(callback: StatusHandler): void;
55+
static start(userId: string, callback: StatusHandler): void;
56+
static start(userAttributes?: UserAttributes, callback?: StatusHandler): void;
57+
static startFromCache(userId: string, callback: StatusHandler): void;
58+
static startFromCache(userAttributes?: UserAttributes, callback?: StatusHandler): void;
59+
static stop(): void;
60+
static pauseSession(): void;
61+
static resumeSession(): void;
62+
static pauseState(): void;
63+
static resumeState(): void;
64+
static setUserId(userId: string): void;
65+
static setUserAttributes(userId: string, userAttributes?: UserAttributes): void;
66+
static track(event: string, value: number, params: Object): void;
67+
static track(event: string, params: Object): void;
68+
static advanceTo(state: string, params?: Object): void;
69+
/**
70+
* Determines if web push is supported in the browser.
71+
* @return {Boolean} True if supported, else false.
72+
*/
73+
static isWebPushSupported(): boolean;
74+
/**
75+
* Determines if web push is subscribed.
76+
* @return {Promise} Resolves if true, rejects if false.
77+
*/
78+
static isWebPushSubscribed(): Promise<boolean>;
79+
/**
80+
* Register the browser for web push.
81+
* @param {string} serviceWorkerUrl The url on your server that hosts the
82+
* /sw.min.js service worker js file.
83+
* @return {Promise} Resolves if registration successful,
84+
* otherwise fails.
85+
*/
86+
static registerForWebPush(serviceWorkerUrl: string): Promise<boolean>;
87+
/**
88+
* Unregisters the browser form web push.
89+
* @return {Promise} Resolves on success, otherwise rejects.
90+
*/
91+
static unregisterFromWebPush(): Promise<string>;
92+
/**
93+
* Clears cached values for messages, variables and test assignments.
94+
* Use sparingly as if the app is updated, you'll have to deal with potentially
95+
* inconsistent state or user experience.
96+
*/
97+
static clearUserContent(): void;
98+
}
99+
export {};
100+

0 commit comments

Comments
 (0)