connectbase-client 1.4.2 → 1.6.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/CHANGELOG.md +37 -0
- package/dist/cli.js +27 -5
- package/dist/connect-base.umd.js +3 -3
- package/dist/index.d.mts +147 -131
- package/dist/index.d.ts +147 -131
- package/dist/index.js +58 -22
- package/dist/index.mjs +58 -22
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -361,18 +361,6 @@ var HttpClient = class {
|
|
|
361
361
|
|
|
362
362
|
// src/api/auth.ts
|
|
363
363
|
var GUEST_MEMBER_TOKEN_KEY_PREFIX = "cb_guest_";
|
|
364
|
-
function notifyVisitorTracker(memberId) {
|
|
365
|
-
if (typeof window === "undefined") return;
|
|
366
|
-
if (memberId) {
|
|
367
|
-
if (typeof window.__cbSetMember === "function") {
|
|
368
|
-
window.__cbSetMember(memberId);
|
|
369
|
-
}
|
|
370
|
-
} else {
|
|
371
|
-
if (typeof window.__cbClearMember === "function") {
|
|
372
|
-
window.__cbClearMember();
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
364
|
function credentialToStorageKeyHash(credential) {
|
|
377
365
|
let hash = 0;
|
|
378
366
|
for (let i = 0; i < credential.length; i++) {
|
|
@@ -387,6 +375,30 @@ var AuthAPI = class {
|
|
|
387
375
|
this.http = http;
|
|
388
376
|
this.guestMemberLoginPromise = null;
|
|
389
377
|
this.cachedGuestMemberTokenKey = null;
|
|
378
|
+
this.analytics = null;
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* AnalyticsAPI 주입 — 로그인/가입/로그아웃 시 방문자 트래커에 member_id 를 전달하여
|
|
382
|
+
* 게스트 방문자를 회원과 연결한다. ConnectBase 컨스트럭터에서 내부적으로 호출된다.
|
|
383
|
+
*/
|
|
384
|
+
_attachAnalytics(analytics) {
|
|
385
|
+
this.analytics = analytics;
|
|
386
|
+
}
|
|
387
|
+
notifyVisitorTracker(memberId) {
|
|
388
|
+
if (this.analytics) {
|
|
389
|
+
this.analytics.setMemberId(memberId);
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
if (typeof window === "undefined") return;
|
|
393
|
+
if (memberId) {
|
|
394
|
+
if (typeof window.__cbSetMember === "function") {
|
|
395
|
+
window.__cbSetMember(memberId);
|
|
396
|
+
}
|
|
397
|
+
} else {
|
|
398
|
+
if (typeof window.__cbClearMember === "function") {
|
|
399
|
+
window.__cbClearMember();
|
|
400
|
+
}
|
|
401
|
+
}
|
|
390
402
|
}
|
|
391
403
|
/**
|
|
392
404
|
* 앱의 인증 설정 조회
|
|
@@ -431,7 +443,7 @@ var AuthAPI = class {
|
|
|
431
443
|
{ skipAuth: true }
|
|
432
444
|
);
|
|
433
445
|
this.http.setTokens(response.access_token, response.refresh_token);
|
|
434
|
-
notifyVisitorTracker(response.member_id);
|
|
446
|
+
this.notifyVisitorTracker(response.member_id);
|
|
435
447
|
return response;
|
|
436
448
|
}
|
|
437
449
|
/**
|
|
@@ -454,7 +466,7 @@ var AuthAPI = class {
|
|
|
454
466
|
{ skipAuth: true }
|
|
455
467
|
);
|
|
456
468
|
this.http.setTokens(response.access_token, response.refresh_token);
|
|
457
|
-
notifyVisitorTracker(response.member_id);
|
|
469
|
+
this.notifyVisitorTracker(response.member_id);
|
|
458
470
|
return response;
|
|
459
471
|
}
|
|
460
472
|
/**
|
|
@@ -525,7 +537,7 @@ var AuthAPI = class {
|
|
|
525
537
|
await this.http.post("/v1/auth/logout");
|
|
526
538
|
} finally {
|
|
527
539
|
this.http.clearTokens();
|
|
528
|
-
notifyVisitorTracker(null);
|
|
540
|
+
this.notifyVisitorTracker(null);
|
|
529
541
|
}
|
|
530
542
|
}
|
|
531
543
|
/**
|
|
@@ -547,7 +559,7 @@ var AuthAPI = class {
|
|
|
547
559
|
"/v1/public/app-members/me"
|
|
548
560
|
);
|
|
549
561
|
if (memberInfo.is_active) {
|
|
550
|
-
notifyVisitorTracker(memberInfo.member_id);
|
|
562
|
+
this.notifyVisitorTracker(memberInfo.member_id);
|
|
551
563
|
return {
|
|
552
564
|
member_id: memberInfo.member_id,
|
|
553
565
|
access_token: storedData.accessToken,
|
|
@@ -568,7 +580,7 @@ var AuthAPI = class {
|
|
|
568
580
|
);
|
|
569
581
|
this.http.setTokens(refreshed.access_token, refreshed.refresh_token);
|
|
570
582
|
this.storeGuestMemberTokens(refreshed.access_token, refreshed.refresh_token, storedData.memberId);
|
|
571
|
-
notifyVisitorTracker(storedData.memberId);
|
|
583
|
+
this.notifyVisitorTracker(storedData.memberId);
|
|
572
584
|
return {
|
|
573
585
|
member_id: storedData.memberId,
|
|
574
586
|
access_token: refreshed.access_token,
|
|
@@ -588,7 +600,7 @@ var AuthAPI = class {
|
|
|
588
600
|
);
|
|
589
601
|
this.http.setTokens(response.access_token, response.refresh_token);
|
|
590
602
|
this.storeGuestMemberTokens(response.access_token, response.refresh_token, response.member_id);
|
|
591
|
-
notifyVisitorTracker(response.member_id);
|
|
603
|
+
this.notifyVisitorTracker(response.member_id);
|
|
592
604
|
return response;
|
|
593
605
|
}
|
|
594
606
|
isTokenExpired(token) {
|
|
@@ -7786,6 +7798,7 @@ function parseUTM() {
|
|
|
7786
7798
|
var AnalyticsAPI = class {
|
|
7787
7799
|
constructor(http) {
|
|
7788
7800
|
this.storageWebId = null;
|
|
7801
|
+
this.memberId = null;
|
|
7789
7802
|
this.eventQueue = [];
|
|
7790
7803
|
this.batchTimer = null;
|
|
7791
7804
|
this.isInitialized = false;
|
|
@@ -7919,13 +7932,33 @@ var AnalyticsAPI = class {
|
|
|
7919
7932
|
}
|
|
7920
7933
|
/**
|
|
7921
7934
|
* 사용자 식별 (로그인 시)
|
|
7935
|
+
* 이후 모든 방문 배치에 `app_member_id`가 첨부되어 게스트 방문자가 회원으로 연결됩니다.
|
|
7922
7936
|
*/
|
|
7923
7937
|
identify(memberId) {
|
|
7924
|
-
|
|
7925
|
-
|
|
7926
|
-
|
|
7938
|
+
this.setMemberId(memberId);
|
|
7939
|
+
}
|
|
7940
|
+
/**
|
|
7941
|
+
* 방문자 트래커에 현재 회원 ID 설정 (로그인/게스트 가입 시 호출)
|
|
7942
|
+
* null 을 넘기면 익명 상태로 복귀 (로그아웃).
|
|
7943
|
+
*/
|
|
7944
|
+
setMemberId(memberId) {
|
|
7945
|
+
this.memberId = memberId || null;
|
|
7946
|
+
if (typeof window !== "undefined") {
|
|
7947
|
+
if (memberId) {
|
|
7948
|
+
if (typeof window.__cbSetMember === "function") {
|
|
7949
|
+
window.__cbSetMember(memberId);
|
|
7950
|
+
}
|
|
7951
|
+
} else {
|
|
7952
|
+
if (typeof window.__cbClearMember === "function") {
|
|
7953
|
+
window.__cbClearMember();
|
|
7954
|
+
}
|
|
7955
|
+
}
|
|
7927
7956
|
}
|
|
7928
|
-
this.log("
|
|
7957
|
+
this.log("Member id set", { memberId });
|
|
7958
|
+
}
|
|
7959
|
+
/** 현재 설정된 회원 ID 조회 (미설정 시 null) */
|
|
7960
|
+
getMemberId() {
|
|
7961
|
+
return this.memberId;
|
|
7929
7962
|
}
|
|
7930
7963
|
/**
|
|
7931
7964
|
* 히트맵 수집 활성화 (opt-in)
|
|
@@ -8038,6 +8071,7 @@ var AnalyticsAPI = class {
|
|
|
8038
8071
|
`${prefix}/storages/web/${this.storageWebId}/visitors/batch`,
|
|
8039
8072
|
{
|
|
8040
8073
|
visitor_uid: this.session.visitorUid,
|
|
8074
|
+
...this.memberId ? { app_member_id: this.memberId } : {},
|
|
8041
8075
|
events: events.map((e) => ({
|
|
8042
8076
|
timestamp: e.timestamp,
|
|
8043
8077
|
page_path: e.page_path || "",
|
|
@@ -8078,6 +8112,7 @@ var AnalyticsAPI = class {
|
|
|
8078
8112
|
const url = `${baseUrl}${prefix}/storages/web/${this.storageWebId}/visitors/batch`;
|
|
8079
8113
|
const body = JSON.stringify({
|
|
8080
8114
|
visitor_uid: this.session.visitorUid,
|
|
8115
|
+
...this.memberId ? { app_member_id: this.memberId } : {},
|
|
8081
8116
|
events: events.map((e) => ({
|
|
8082
8117
|
timestamp: e.timestamp,
|
|
8083
8118
|
page_path: e.page_path || "",
|
|
@@ -8941,6 +8976,7 @@ var ConnectBase = class {
|
|
|
8941
8976
|
this.ai = new AIAPI(this.http);
|
|
8942
8977
|
this.queue = new QueueAPI(this.http);
|
|
8943
8978
|
this.analytics = new AnalyticsAPI(this.http);
|
|
8979
|
+
this.auth._attachAnalytics(this.analytics);
|
|
8944
8980
|
}
|
|
8945
8981
|
/**
|
|
8946
8982
|
* 수동으로 토큰 설정 (기존 토큰으로 세션 복원 시)
|
package/dist/index.mjs
CHANGED
|
@@ -323,18 +323,6 @@ var HttpClient = class {
|
|
|
323
323
|
|
|
324
324
|
// src/api/auth.ts
|
|
325
325
|
var GUEST_MEMBER_TOKEN_KEY_PREFIX = "cb_guest_";
|
|
326
|
-
function notifyVisitorTracker(memberId) {
|
|
327
|
-
if (typeof window === "undefined") return;
|
|
328
|
-
if (memberId) {
|
|
329
|
-
if (typeof window.__cbSetMember === "function") {
|
|
330
|
-
window.__cbSetMember(memberId);
|
|
331
|
-
}
|
|
332
|
-
} else {
|
|
333
|
-
if (typeof window.__cbClearMember === "function") {
|
|
334
|
-
window.__cbClearMember();
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
326
|
function credentialToStorageKeyHash(credential) {
|
|
339
327
|
let hash = 0;
|
|
340
328
|
for (let i = 0; i < credential.length; i++) {
|
|
@@ -349,6 +337,30 @@ var AuthAPI = class {
|
|
|
349
337
|
this.http = http;
|
|
350
338
|
this.guestMemberLoginPromise = null;
|
|
351
339
|
this.cachedGuestMemberTokenKey = null;
|
|
340
|
+
this.analytics = null;
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* AnalyticsAPI 주입 — 로그인/가입/로그아웃 시 방문자 트래커에 member_id 를 전달하여
|
|
344
|
+
* 게스트 방문자를 회원과 연결한다. ConnectBase 컨스트럭터에서 내부적으로 호출된다.
|
|
345
|
+
*/
|
|
346
|
+
_attachAnalytics(analytics) {
|
|
347
|
+
this.analytics = analytics;
|
|
348
|
+
}
|
|
349
|
+
notifyVisitorTracker(memberId) {
|
|
350
|
+
if (this.analytics) {
|
|
351
|
+
this.analytics.setMemberId(memberId);
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
if (typeof window === "undefined") return;
|
|
355
|
+
if (memberId) {
|
|
356
|
+
if (typeof window.__cbSetMember === "function") {
|
|
357
|
+
window.__cbSetMember(memberId);
|
|
358
|
+
}
|
|
359
|
+
} else {
|
|
360
|
+
if (typeof window.__cbClearMember === "function") {
|
|
361
|
+
window.__cbClearMember();
|
|
362
|
+
}
|
|
363
|
+
}
|
|
352
364
|
}
|
|
353
365
|
/**
|
|
354
366
|
* 앱의 인증 설정 조회
|
|
@@ -393,7 +405,7 @@ var AuthAPI = class {
|
|
|
393
405
|
{ skipAuth: true }
|
|
394
406
|
);
|
|
395
407
|
this.http.setTokens(response.access_token, response.refresh_token);
|
|
396
|
-
notifyVisitorTracker(response.member_id);
|
|
408
|
+
this.notifyVisitorTracker(response.member_id);
|
|
397
409
|
return response;
|
|
398
410
|
}
|
|
399
411
|
/**
|
|
@@ -416,7 +428,7 @@ var AuthAPI = class {
|
|
|
416
428
|
{ skipAuth: true }
|
|
417
429
|
);
|
|
418
430
|
this.http.setTokens(response.access_token, response.refresh_token);
|
|
419
|
-
notifyVisitorTracker(response.member_id);
|
|
431
|
+
this.notifyVisitorTracker(response.member_id);
|
|
420
432
|
return response;
|
|
421
433
|
}
|
|
422
434
|
/**
|
|
@@ -487,7 +499,7 @@ var AuthAPI = class {
|
|
|
487
499
|
await this.http.post("/v1/auth/logout");
|
|
488
500
|
} finally {
|
|
489
501
|
this.http.clearTokens();
|
|
490
|
-
notifyVisitorTracker(null);
|
|
502
|
+
this.notifyVisitorTracker(null);
|
|
491
503
|
}
|
|
492
504
|
}
|
|
493
505
|
/**
|
|
@@ -509,7 +521,7 @@ var AuthAPI = class {
|
|
|
509
521
|
"/v1/public/app-members/me"
|
|
510
522
|
);
|
|
511
523
|
if (memberInfo.is_active) {
|
|
512
|
-
notifyVisitorTracker(memberInfo.member_id);
|
|
524
|
+
this.notifyVisitorTracker(memberInfo.member_id);
|
|
513
525
|
return {
|
|
514
526
|
member_id: memberInfo.member_id,
|
|
515
527
|
access_token: storedData.accessToken,
|
|
@@ -530,7 +542,7 @@ var AuthAPI = class {
|
|
|
530
542
|
);
|
|
531
543
|
this.http.setTokens(refreshed.access_token, refreshed.refresh_token);
|
|
532
544
|
this.storeGuestMemberTokens(refreshed.access_token, refreshed.refresh_token, storedData.memberId);
|
|
533
|
-
notifyVisitorTracker(storedData.memberId);
|
|
545
|
+
this.notifyVisitorTracker(storedData.memberId);
|
|
534
546
|
return {
|
|
535
547
|
member_id: storedData.memberId,
|
|
536
548
|
access_token: refreshed.access_token,
|
|
@@ -550,7 +562,7 @@ var AuthAPI = class {
|
|
|
550
562
|
);
|
|
551
563
|
this.http.setTokens(response.access_token, response.refresh_token);
|
|
552
564
|
this.storeGuestMemberTokens(response.access_token, response.refresh_token, response.member_id);
|
|
553
|
-
notifyVisitorTracker(response.member_id);
|
|
565
|
+
this.notifyVisitorTracker(response.member_id);
|
|
554
566
|
return response;
|
|
555
567
|
}
|
|
556
568
|
isTokenExpired(token) {
|
|
@@ -7748,6 +7760,7 @@ function parseUTM() {
|
|
|
7748
7760
|
var AnalyticsAPI = class {
|
|
7749
7761
|
constructor(http) {
|
|
7750
7762
|
this.storageWebId = null;
|
|
7763
|
+
this.memberId = null;
|
|
7751
7764
|
this.eventQueue = [];
|
|
7752
7765
|
this.batchTimer = null;
|
|
7753
7766
|
this.isInitialized = false;
|
|
@@ -7881,13 +7894,33 @@ var AnalyticsAPI = class {
|
|
|
7881
7894
|
}
|
|
7882
7895
|
/**
|
|
7883
7896
|
* 사용자 식별 (로그인 시)
|
|
7897
|
+
* 이후 모든 방문 배치에 `app_member_id`가 첨부되어 게스트 방문자가 회원으로 연결됩니다.
|
|
7884
7898
|
*/
|
|
7885
7899
|
identify(memberId) {
|
|
7886
|
-
|
|
7887
|
-
|
|
7888
|
-
|
|
7900
|
+
this.setMemberId(memberId);
|
|
7901
|
+
}
|
|
7902
|
+
/**
|
|
7903
|
+
* 방문자 트래커에 현재 회원 ID 설정 (로그인/게스트 가입 시 호출)
|
|
7904
|
+
* null 을 넘기면 익명 상태로 복귀 (로그아웃).
|
|
7905
|
+
*/
|
|
7906
|
+
setMemberId(memberId) {
|
|
7907
|
+
this.memberId = memberId || null;
|
|
7908
|
+
if (typeof window !== "undefined") {
|
|
7909
|
+
if (memberId) {
|
|
7910
|
+
if (typeof window.__cbSetMember === "function") {
|
|
7911
|
+
window.__cbSetMember(memberId);
|
|
7912
|
+
}
|
|
7913
|
+
} else {
|
|
7914
|
+
if (typeof window.__cbClearMember === "function") {
|
|
7915
|
+
window.__cbClearMember();
|
|
7916
|
+
}
|
|
7917
|
+
}
|
|
7889
7918
|
}
|
|
7890
|
-
this.log("
|
|
7919
|
+
this.log("Member id set", { memberId });
|
|
7920
|
+
}
|
|
7921
|
+
/** 현재 설정된 회원 ID 조회 (미설정 시 null) */
|
|
7922
|
+
getMemberId() {
|
|
7923
|
+
return this.memberId;
|
|
7891
7924
|
}
|
|
7892
7925
|
/**
|
|
7893
7926
|
* 히트맵 수집 활성화 (opt-in)
|
|
@@ -8000,6 +8033,7 @@ var AnalyticsAPI = class {
|
|
|
8000
8033
|
`${prefix}/storages/web/${this.storageWebId}/visitors/batch`,
|
|
8001
8034
|
{
|
|
8002
8035
|
visitor_uid: this.session.visitorUid,
|
|
8036
|
+
...this.memberId ? { app_member_id: this.memberId } : {},
|
|
8003
8037
|
events: events.map((e) => ({
|
|
8004
8038
|
timestamp: e.timestamp,
|
|
8005
8039
|
page_path: e.page_path || "",
|
|
@@ -8040,6 +8074,7 @@ var AnalyticsAPI = class {
|
|
|
8040
8074
|
const url = `${baseUrl}${prefix}/storages/web/${this.storageWebId}/visitors/batch`;
|
|
8041
8075
|
const body = JSON.stringify({
|
|
8042
8076
|
visitor_uid: this.session.visitorUid,
|
|
8077
|
+
...this.memberId ? { app_member_id: this.memberId } : {},
|
|
8043
8078
|
events: events.map((e) => ({
|
|
8044
8079
|
timestamp: e.timestamp,
|
|
8045
8080
|
page_path: e.page_path || "",
|
|
@@ -8903,6 +8938,7 @@ var ConnectBase = class {
|
|
|
8903
8938
|
this.ai = new AIAPI(this.http);
|
|
8904
8939
|
this.queue = new QueueAPI(this.http);
|
|
8905
8940
|
this.analytics = new AnalyticsAPI(this.http);
|
|
8941
|
+
this.auth._attachAnalytics(this.analytics);
|
|
8906
8942
|
}
|
|
8907
8943
|
/**
|
|
8908
8944
|
* 수동으로 토큰 설정 (기존 토큰으로 세션 복원 시)
|