leap-capacitor 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LeapCapacitor.podspec +19 -0
- package/README.md +234 -0
- package/android/build.gradle +59 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/java/is/leap/capacitor/LeapPlugin.java +239 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +1069 -0
- package/dist/esm/definitions.d.ts +38 -0
- package/dist/esm/definitions.js +2 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/plugin.cjs.js +10 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +13 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Plugin/Info.plist +24 -0
- package/ios/Plugin/LeapPlugin.h +10 -0
- package/ios/Plugin/LeapPlugin.m +15 -0
- package/ios/Plugin/LeapPlugin.swift +126 -0
- package/package.json +78 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { PluginListenerHandle } from '@capacitor/core';
|
|
2
|
+
export interface UserProperty {
|
|
3
|
+
[key: string]: string | number;
|
|
4
|
+
}
|
|
5
|
+
export interface LeapCallbacks {
|
|
6
|
+
[key: string]: string;
|
|
7
|
+
}
|
|
8
|
+
export interface LeapElementActionCallbacks {
|
|
9
|
+
[key: string]: any;
|
|
10
|
+
}
|
|
11
|
+
export interface LeapPluginInterface {
|
|
12
|
+
start(options: {
|
|
13
|
+
apiKey: string;
|
|
14
|
+
}): Promise<void>;
|
|
15
|
+
startWithProperties(options: {
|
|
16
|
+
apiKey: string;
|
|
17
|
+
properties: UserProperty;
|
|
18
|
+
}): Promise<void>;
|
|
19
|
+
flushProperties(options: {
|
|
20
|
+
properties: UserProperty;
|
|
21
|
+
}): Promise<void>;
|
|
22
|
+
setUniqueUserId(options: {
|
|
23
|
+
uniqueUserId: string;
|
|
24
|
+
}): Promise<void>;
|
|
25
|
+
startProject(options: {
|
|
26
|
+
projectId: string;
|
|
27
|
+
resetProject?: boolean;
|
|
28
|
+
}): Promise<void>;
|
|
29
|
+
embedProject(options: {
|
|
30
|
+
projectId: string;
|
|
31
|
+
}): Promise<void>;
|
|
32
|
+
offlineSync(options: {
|
|
33
|
+
projectIds: Array<string>;
|
|
34
|
+
}): Promise<void>;
|
|
35
|
+
disable(): Promise<void>;
|
|
36
|
+
addListener(eventName: 'leapCallbacks', listenerFunc: (event: LeapCallbacks) => void): Promise<PluginListenerHandle> & PluginListenerHandle;
|
|
37
|
+
addListener(eventName: 'leapElementActionCallbacks', listenerFunc: (event: LeapElementActionCallbacks) => void): Promise<PluginListenerHandle> & PluginListenerHandle;
|
|
38
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["\nimport type { PluginListenerHandle } from '@capacitor/core';\n\nexport interface UserProperty {\n [key: string]: string | number\n}\n\nexport interface LeapCallbacks {\n [key: string]: string\n}\n\nexport interface LeapElementActionCallbacks {\n [key: string]: any\n}\n\nexport interface LeapPluginInterface {\n start(options: { apiKey: string }): Promise<void>;\n startWithProperties(options: { apiKey: string, properties: UserProperty }): Promise<void>;\n flushProperties(options: { properties: UserProperty }): Promise<void>;\n setUniqueUserId(options: { uniqueUserId: string }): Promise<void>;\n startProject(options: { projectId: string, resetProject?: boolean }): Promise<void>;\n embedProject(options: { projectId: string }): Promise<void>;\n offlineSync(options: { projectIds: Array<string> }): Promise<void>;\n disable(): Promise<void>;\n\n addListener(\n eventName: 'leapCallbacks',\n listenerFunc: (event: LeapCallbacks) => void,\n ): Promise<PluginListenerHandle> & PluginListenerHandle\n\n addListener(\n eventName: 'leapElementActionCallbacks',\n listenerFunc: (event: LeapElementActionCallbacks) => void,\n ): Promise<PluginListenerHandle> & PluginListenerHandle\n\n\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,UAAU,GAAG,cAAc,CAAsB,YAAY,CAAC,CAAC;AAErE,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,UAAU,EAAE,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { LeapPluginInterface } from './definitions';\n\nconst LeapPlugin = registerPlugin<LeapPluginInterface>('LeapPlugin');\n\nexport * from './definitions';\nexport { LeapPlugin };\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.cjs.js","sources":["esm/index.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst LeapPlugin = registerPlugin('LeapPlugin');\nexport * from './definitions';\nexport { LeapPlugin };\n//# sourceMappingURL=index.js.map"],"names":["registerPlugin"],"mappings":";;;;;;AACK,MAAC,UAAU,GAAGA,mBAAc,CAAC,YAAY;;;;"}
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
var capacitorLeapPlugin = (function (exports, core) {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const LeapPlugin = core.registerPlugin('LeapPlugin');
|
|
5
|
+
|
|
6
|
+
exports.LeapPlugin = LeapPlugin;
|
|
7
|
+
|
|
8
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
9
|
+
|
|
10
|
+
return exports;
|
|
11
|
+
|
|
12
|
+
})({}, capacitorExports);
|
|
13
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["esm/index.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst LeapPlugin = registerPlugin('LeapPlugin');\nexport * from './definitions';\nexport { LeapPlugin };\n//# sourceMappingURL=index.js.map"],"names":["registerPlugin"],"mappings":";;;AACK,OAAC,UAAU,GAAGA,mBAAc,CAAC,YAAY;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3
|
+
<plist version="1.0">
|
|
4
|
+
<dict>
|
|
5
|
+
<key>CFBundleDevelopmentRegion</key>
|
|
6
|
+
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
|
7
|
+
<key>CFBundleExecutable</key>
|
|
8
|
+
<string>$(EXECUTABLE_NAME)</string>
|
|
9
|
+
<key>CFBundleIdentifier</key>
|
|
10
|
+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
|
11
|
+
<key>CFBundleInfoDictionaryVersion</key>
|
|
12
|
+
<string>6.0</string>
|
|
13
|
+
<key>CFBundleName</key>
|
|
14
|
+
<string>$(PRODUCT_NAME)</string>
|
|
15
|
+
<key>CFBundlePackageType</key>
|
|
16
|
+
<string>FMWK</string>
|
|
17
|
+
<key>CFBundleShortVersionString</key>
|
|
18
|
+
<string>1.0</string>
|
|
19
|
+
<key>CFBundleVersion</key>
|
|
20
|
+
<string>$(CURRENT_PROJECT_VERSION)</string>
|
|
21
|
+
<key>NSPrincipalClass</key>
|
|
22
|
+
<string></string>
|
|
23
|
+
</dict>
|
|
24
|
+
</plist>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#import <UIKit/UIKit.h>
|
|
2
|
+
|
|
3
|
+
//! Project version number for Plugin.
|
|
4
|
+
FOUNDATION_EXPORT double PluginVersionNumber;
|
|
5
|
+
|
|
6
|
+
//! Project version string for Plugin.
|
|
7
|
+
FOUNDATION_EXPORT const unsigned char PluginVersionString[];
|
|
8
|
+
|
|
9
|
+
// In this header, you should import all the public headers of your framework using statements like #import <Plugin/PublicHeader.h>
|
|
10
|
+
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#import <Foundation/Foundation.h>
|
|
2
|
+
#import <Capacitor/Capacitor.h>
|
|
3
|
+
|
|
4
|
+
// Define the plugin using the CAP_PLUGIN Macro, and
|
|
5
|
+
// each method the plugin supports using the CAP_PLUGIN_METHOD macro.
|
|
6
|
+
CAP_PLUGIN(LeapPlugin, "LeapPlugin",
|
|
7
|
+
CAP_PLUGIN_METHOD(start, CAPPluginReturnPromise);
|
|
8
|
+
CAP_PLUGIN_METHOD(startWithProperties, CAPPluginReturnPromise);
|
|
9
|
+
CAP_PLUGIN_METHOD(flushProperties, CAPPluginReturnPromise);
|
|
10
|
+
CAP_PLUGIN_METHOD(startProject, CAPPluginReturnPromise);
|
|
11
|
+
CAP_PLUGIN_METHOD(embedProject, CAPPluginReturnPromise);
|
|
12
|
+
CAP_PLUGIN_METHOD(setUniqueUserId, CAPPluginReturnPromise);
|
|
13
|
+
CAP_PLUGIN_METHOD(offlineSync, CAPPluginReturnPromise);
|
|
14
|
+
CAP_PLUGIN_METHOD(disable, CAPPluginReturnPromise);
|
|
15
|
+
)
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import Capacitor
|
|
3
|
+
import LeapSDK
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Please read the Capacitor iOS Plugin Development Guide
|
|
7
|
+
* here: https://capacitorjs.com/docs/plugins/ios
|
|
8
|
+
*/
|
|
9
|
+
@objc(LeapPlugin)
|
|
10
|
+
|
|
11
|
+
public class LeapPlugin: CAPPlugin {
|
|
12
|
+
|
|
13
|
+
@objc public func start(_ call: CAPPluginCall) {
|
|
14
|
+
let apiKey = call.getString("apiKey") ?? ""
|
|
15
|
+
DispatchQueue.main.async {
|
|
16
|
+
Leap.shared.start(apiKey)
|
|
17
|
+
Leap.shared.callback = self
|
|
18
|
+
}
|
|
19
|
+
call.resolve()
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@objc public func startWithProperties(_ call: CAPPluginCall) {
|
|
23
|
+
let apiKey = call.getString("apiKey") ?? ""
|
|
24
|
+
let properties:[String:AnyHashable] = call.getObject("properties") as? [String:AnyHashable] ?? [:]
|
|
25
|
+
DispatchQueue.main.async {
|
|
26
|
+
let leapShared = Leap.shared.withBuilder(apiKey)
|
|
27
|
+
properties.forEach { key, value in
|
|
28
|
+
if let stringValue = value as? String {
|
|
29
|
+
if stringValue.hasPrefix("Date:") {
|
|
30
|
+
let dateValue = stringValue.components(separatedBy: "Date:").last ?? ""
|
|
31
|
+
if let date = self.getDateFromISOString(dateString: dateValue) {
|
|
32
|
+
leapShared?.addProperty(key, dateValue: date)
|
|
33
|
+
}
|
|
34
|
+
} else {
|
|
35
|
+
leapShared?.addProperty(key, stringValue: stringValue)
|
|
36
|
+
}
|
|
37
|
+
} else if let intValue = value as? Int {
|
|
38
|
+
leapShared?.addProperty(key, intValue: intValue)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
leapShared?.start()
|
|
42
|
+
}
|
|
43
|
+
call.resolve()
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@objc public func flushProperties(_ call: CAPPluginCall) {
|
|
47
|
+
let properties:[String:AnyHashable] = call.getObject("properties") as? [String:AnyHashable] ?? [:]
|
|
48
|
+
DispatchQueue.main.async {
|
|
49
|
+
let leapShared = Leap.shared
|
|
50
|
+
properties.forEach { key, value in
|
|
51
|
+
if let stringValue = value as? String {
|
|
52
|
+
if stringValue.hasPrefix("Date:") {
|
|
53
|
+
let dateValue = stringValue.components(separatedBy: "Date:").last ?? ""
|
|
54
|
+
if let date = self.getDateFromISOString(dateString: dateValue) {
|
|
55
|
+
leapShared.addProperty(key, dateValue: date)
|
|
56
|
+
}
|
|
57
|
+
} else {
|
|
58
|
+
leapShared.addProperty(key, stringValue: stringValue)
|
|
59
|
+
}
|
|
60
|
+
} else if let intValue = value as? Int {
|
|
61
|
+
leapShared.addProperty(key, intValue: intValue)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
leapShared.flush()
|
|
65
|
+
}
|
|
66
|
+
call.resolve()
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
@objc public func setUniqueUserId(_ call: CAPPluginCall) {
|
|
70
|
+
let uniqueUserId = call.getString("uniqueUserId") ?? ""
|
|
71
|
+
DispatchQueue.main.async {
|
|
72
|
+
Leap.shared.setUniqueUserId(uniqueUserId)
|
|
73
|
+
}
|
|
74
|
+
call.resolve()
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
@objc public func startProject(_ call: CAPPluginCall) {
|
|
78
|
+
let projectId = call.getString("projectId") ?? ""
|
|
79
|
+
let resetProject = call.getBool("resetProject") ?? false
|
|
80
|
+
DispatchQueue.main.async {
|
|
81
|
+
Leap.shared.startProject(projectId, resetProject: resetProject)
|
|
82
|
+
}
|
|
83
|
+
call.resolve()
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
@objc public func embedProject(_ call: CAPPluginCall) {
|
|
87
|
+
let projectId = call.getString("projectId") ?? ""
|
|
88
|
+
DispatchQueue.main.async {
|
|
89
|
+
Leap.shared.embedProject(projectId)
|
|
90
|
+
}
|
|
91
|
+
call.resolve()
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
@objc public func offlineSync(_ call: CAPPluginCall) {
|
|
95
|
+
let projectIds = call.getArray("projectIds")?.capacitor.replacingNullValues() as? [String] ?? []
|
|
96
|
+
DispatchQueue.main.async {
|
|
97
|
+
Leap.shared.offlineSync(projectIds)
|
|
98
|
+
}
|
|
99
|
+
call.resolve()
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
@objc public func disable(_ call: CAPPluginCall) {
|
|
103
|
+
DispatchQueue.main.async {
|
|
104
|
+
Leap.shared.disable()
|
|
105
|
+
}
|
|
106
|
+
call.resolve()
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
func getDateFromISOString(dateString:String) -> Date? {
|
|
110
|
+
let formatter = DateFormatter()
|
|
111
|
+
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"
|
|
112
|
+
let posix:Locale = Locale(identifier: "en_US_POSIX")
|
|
113
|
+
formatter.locale = posix
|
|
114
|
+
let date = formatter.date(from: dateString)
|
|
115
|
+
return date
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
extension LeapPlugin: LeapCallback {
|
|
120
|
+
|
|
121
|
+
public func eventNotification(eventInfo: Dictionary<String, Any>) {
|
|
122
|
+
DispatchQueue.main.async { [weak self] in
|
|
123
|
+
self?.notifyListeners("leapCallbacks", data: eventInfo)
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "leap-capacitor",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Plugin for Leap",
|
|
5
|
+
"main": "dist/plugin.cjs.js",
|
|
6
|
+
"module": "dist/esm/index.js",
|
|
7
|
+
"types": "dist/esm/index.d.ts",
|
|
8
|
+
"unpkg": "dist/plugin.js",
|
|
9
|
+
"files": [
|
|
10
|
+
"android/src/main/",
|
|
11
|
+
"android/build.gradle",
|
|
12
|
+
"dist/",
|
|
13
|
+
"ios/Plugin/",
|
|
14
|
+
"LeapCapacitor.podspec"
|
|
15
|
+
],
|
|
16
|
+
"author": "Leap",
|
|
17
|
+
"license": "Apache-2.0",
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "https://www.npmjs.com/package/leap-capacitor.git"
|
|
21
|
+
},
|
|
22
|
+
"bugs": {
|
|
23
|
+
"url": "https://www.npmjs.com/package/leap-capacitor/issues"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"capacitor",
|
|
27
|
+
"plugin",
|
|
28
|
+
"native"
|
|
29
|
+
],
|
|
30
|
+
"scripts": {
|
|
31
|
+
"verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
|
|
32
|
+
"verify:ios": "cd ios && pod install && xcodebuild -workspace Plugin.xcworkspace -scheme Plugin && cd ..",
|
|
33
|
+
"verify:android": "cd android && ./gradlew clean build test && cd ..",
|
|
34
|
+
"verify:web": "npm run build",
|
|
35
|
+
"lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
|
|
36
|
+
"fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
|
|
37
|
+
"eslint": "eslint . --ext ts",
|
|
38
|
+
"prettier": "prettier \"**/*.{css,html,ts,js,java}\"",
|
|
39
|
+
"swiftlint": "node-swiftlint",
|
|
40
|
+
"docgen": "docgen --api LeapPluginInterface --output-readme README.md --output-json dist/docs.json",
|
|
41
|
+
"build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.js",
|
|
42
|
+
"clean": "rimraf ./dist",
|
|
43
|
+
"watch": "tsc --watch",
|
|
44
|
+
"prepublishOnly": "npm run build"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@capacitor/android": "^3.0.0",
|
|
48
|
+
"@capacitor/core": "^3.0.0",
|
|
49
|
+
"@capacitor/docgen": "^0.0.18",
|
|
50
|
+
"@capacitor/ios": "^3.0.0",
|
|
51
|
+
"@ionic/eslint-config": "^0.3.0",
|
|
52
|
+
"@ionic/prettier-config": "^1.0.1",
|
|
53
|
+
"@ionic/swiftlint-config": "^1.1.2",
|
|
54
|
+
"eslint": "^7.11.0",
|
|
55
|
+
"prettier": "~2.2.0",
|
|
56
|
+
"prettier-plugin-java": "~1.0.0",
|
|
57
|
+
"rimraf": "^3.0.2",
|
|
58
|
+
"rollup": "^2.32.0",
|
|
59
|
+
"swiftlint": "^1.0.1",
|
|
60
|
+
"typescript": "~4.0.3"
|
|
61
|
+
},
|
|
62
|
+
"peerDependencies": {
|
|
63
|
+
"@capacitor/core": "^3.0.0"
|
|
64
|
+
},
|
|
65
|
+
"prettier": "@ionic/prettier-config",
|
|
66
|
+
"swiftlint": "@ionic/swiftlint-config",
|
|
67
|
+
"eslintConfig": {
|
|
68
|
+
"extends": "@ionic/eslint-config/recommended"
|
|
69
|
+
},
|
|
70
|
+
"capacitor": {
|
|
71
|
+
"ios": {
|
|
72
|
+
"src": "ios"
|
|
73
|
+
},
|
|
74
|
+
"android": {
|
|
75
|
+
"src": "android"
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|