@geophrase/core 1.0.5 → 1.0.6
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/package.json +1 -1
- package/src/index.js +14 -5
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -97,18 +97,27 @@ class Geophrase {
|
|
|
97
97
|
async _handleMessage(event) {
|
|
98
98
|
if (event.origin !== this.widgetOrigin) return;
|
|
99
99
|
|
|
100
|
-
|
|
100
|
+
let data = event.data;
|
|
101
|
+
if (typeof data === 'string') {
|
|
102
|
+
try {
|
|
103
|
+
data = JSON.parse(data);
|
|
104
|
+
} catch (e) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (data?.type === 'GEOPHRASE_CLOSE_WIDGET') {
|
|
101
110
|
this.close();
|
|
102
111
|
if (this.onClose) this.onClose();
|
|
103
112
|
}
|
|
104
113
|
|
|
105
|
-
if (
|
|
114
|
+
if (data?.type === 'GEOPHRASE_RESOLUTION_TOKEN') {
|
|
106
115
|
this.close();
|
|
107
116
|
try {
|
|
108
117
|
const response = await fetch(`${this.apiBase}/business/resolve/`, {
|
|
109
118
|
method: "POST",
|
|
110
119
|
headers: { "X-API-Key": this.apiKey, "Content-Type": "application/json" },
|
|
111
|
-
body: JSON.stringify({ token:
|
|
120
|
+
body: JSON.stringify({ token: data.token }),
|
|
112
121
|
});
|
|
113
122
|
|
|
114
123
|
if (!response.ok) {
|
|
@@ -123,8 +132,8 @@ class Geophrase {
|
|
|
123
132
|
return;
|
|
124
133
|
}
|
|
125
134
|
|
|
126
|
-
const
|
|
127
|
-
if (this.onSuccess) this.onSuccess(
|
|
135
|
+
const responseData = await response.json();
|
|
136
|
+
if (this.onSuccess) this.onSuccess(responseData);
|
|
128
137
|
|
|
129
138
|
} catch (error) {
|
|
130
139
|
console.error("Geophrase Resolution Error:", error);
|