@product7/product7-js 0.3.4 → 0.3.5

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@product7/product7-js",
3
- "version": "0.3.4",
3
+ "version": "0.3.5",
4
4
  "description": "JavaScript SDK for integrating Product7 feedback widgets into any website",
5
5
  "main": "dist/product7-js.js",
6
6
  "module": "src/index.js",
@@ -229,7 +229,7 @@ export class APIService extends BaseAPIService {
229
229
 
230
230
  if (this.mock) {
231
231
  await new Promise((r) => setTimeout(r, 300));
232
- return {
232
+ const mockResponse = {
233
233
  status: true,
234
234
  data: {
235
235
  contact_id: 'mock_contact_' + Date.now(),
@@ -238,9 +238,11 @@ export class APIService extends BaseAPIService {
238
238
  is_new: true,
239
239
  },
240
240
  };
241
+ this._storeContactIdentity(mockResponse.data, metadata);
242
+ return mockResponse;
241
243
  }
242
244
 
243
- return this._makeRequest('/widget/messenger/identify', {
245
+ const response = await this._makeRequest('/widget/messenger/identify', {
244
246
  method: 'POST',
245
247
  headers: {
246
248
  'Content-Type': 'application/json',
@@ -256,6 +258,56 @@ export class APIService extends BaseAPIService {
256
258
  metadata: metadata.custom_fields || {},
257
259
  }),
258
260
  });
261
+
262
+ if (response?.status && response?.data) {
263
+ this._storeContactIdentity(response.data, metadata);
264
+ }
265
+
266
+ return response;
267
+ }
268
+
269
+ _storeContactIdentity(data, metadata = {}) {
270
+ this.contactId = data.contact_id || null;
271
+ this.contactEmail = data.email || metadata.email || null;
272
+ this.contactName = data.name || metadata.name || null;
273
+
274
+ try {
275
+ localStorage.setItem(
276
+ 'product7_contact',
277
+ JSON.stringify({
278
+ contactId: this.contactId,
279
+ contactEmail: this.contactEmail,
280
+ contactName: this.contactName,
281
+ })
282
+ );
283
+ } catch (e) {
284
+ /* silent */
285
+ }
286
+ }
287
+
288
+ getContactIdentity() {
289
+ if (this.contactId) {
290
+ return {
291
+ contactId: this.contactId,
292
+ contactEmail: this.contactEmail,
293
+ contactName: this.contactName,
294
+ };
295
+ }
296
+
297
+ try {
298
+ const stored = localStorage.getItem('product7_contact');
299
+ if (stored) {
300
+ const parsed = JSON.parse(stored);
301
+ this.contactId = parsed.contactId;
302
+ this.contactEmail = parsed.contactEmail;
303
+ this.contactName = parsed.contactName;
304
+ return parsed;
305
+ }
306
+ } catch (e) {
307
+ /* silent */
308
+ }
309
+
310
+ return null;
259
311
  }
260
312
 
261
313
  async identifyContact(data) {
@@ -246,8 +246,12 @@ export class BaseAPIService {
246
246
  this.sessionToken = null;
247
247
  this.sessionExpiry = null;
248
248
  this.identitySyncedToken = null;
249
+ this.contactId = null;
250
+ this.contactEmail = null;
251
+ this.contactName = null;
249
252
  this._removeData('product7_session');
250
253
  this._removeData('product7_metadata');
254
+ this._removeData('product7_contact');
251
255
  }
252
256
 
253
257
  _storeSession() {
@@ -862,7 +862,7 @@ export class Product7 {
862
862
  metadata: null,
863
863
  position: 'right',
864
864
  theme: 'light',
865
- boardName: 'general',
865
+ boardName: 'feature-requests',
866
866
  autoShow: true,
867
867
  debug: false,
868
868
  mock: false,
@@ -58,6 +58,7 @@ export class MessengerWidget extends BaseWidget {
58
58
  initialView: options.initialView || 'home',
59
59
  previewData: options.previewData || null,
60
60
  featuredContent: options.featuredContent || null,
61
+ feedbackBoardName: options.feedbackBoardName || null,
61
62
  feedbackUrl: options.feedbackUrl || null,
62
63
  changelogUrl: options.changelogUrl || null,
63
64
  helpUrl: options.helpUrl || null,
@@ -109,7 +110,8 @@ export class MessengerWidget extends BaseWidget {
109
110
  const widget = this.sdk.createWidget('button', {
110
111
  trigger: false,
111
112
  displayMode: 'modal',
112
- boardName: this.sdk.config.boardName,
113
+ boardName:
114
+ this.messengerOptions.feedbackBoardName || this.sdk.config.boardName,
113
115
  primaryColor: this.messengerOptions.primaryColor,
114
116
  theme: this.messengerOptions.theme,
115
117
  });