@benji-money/connect-sdk 1.1.4-beta.6 → 1.1.4-beta.7
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/README.md +2 -0
- package/dist/connect-sdk.umd.d.ts +14 -0
- package/dist/connect-sdk.umd.global.js +184 -129
- package/dist/connect-sdk.umd.global.js.map +1 -1
- package/dist/index.cjs +190 -135
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +190 -135
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// These are compile-time constants replaced by tsup's `define` option.
|
|
2
|
+
// Declaring them globally prevents TypeScript errors.
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
declare global {
|
|
6
|
+
const __VERSION__: string;
|
|
7
|
+
const __NAMESPACE__: string;
|
|
8
|
+
|
|
9
|
+
// Global browser exposure for UMD builds
|
|
10
|
+
interface Window {
|
|
11
|
+
// SDK main class (UMD builds attach this)
|
|
12
|
+
ConnectSDK?: any;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -110,7 +110,7 @@ var ConnectSDK = (() => {
|
|
|
110
110
|
// src/utils/config.ts
|
|
111
111
|
var buildContext = () => ({
|
|
112
112
|
namespace: "benji-connect-sdk" ? "benji-connect-sdk" : "benji-connect-sdk",
|
|
113
|
-
version: "1.1.4-beta.
|
|
113
|
+
version: "1.1.4-beta.7" ? String("1.1.4-beta.7") : "0.0.0"
|
|
114
114
|
});
|
|
115
115
|
function isBenjiConnectEnvironment(environment) {
|
|
116
116
|
return environment === "local" /* LOCAL */ || environment === "development" /* DEVELOPMENT */ || environment === "sandbox" /* SANDBOX */ || environment === "production" /* PRODUCTION */;
|
|
@@ -216,6 +216,16 @@ var ConnectSDK = (() => {
|
|
|
216
216
|
}
|
|
217
217
|
}
|
|
218
218
|
|
|
219
|
+
// src/constants/login.ts
|
|
220
|
+
var LOGIN_RETURN_STATE_SEPARATOR = ".benji_return.";
|
|
221
|
+
var LOGIN_RESUME_QUERY_FLAG = "login_resume";
|
|
222
|
+
var LOGIN_PENDING_STORAGE_KEY = "benji_login_pending";
|
|
223
|
+
var LOGIN_FORCE_REDIRECT_STORAGE_KEY = "benji_force_login_redirect";
|
|
224
|
+
var LOGIN_POPUP_CLOSED_POLL_MS = 500;
|
|
225
|
+
var LOGIN_IFRAME_DELIVERABILITY_POLL_MS = 100;
|
|
226
|
+
var LOGIN_SAME_TAB_AUTH_REDELIVERY_MS = 500;
|
|
227
|
+
var LOGIN_SAME_TAB_RESUME_TIMEOUT_MS = 45e3;
|
|
228
|
+
|
|
219
229
|
// src/utils/partnerAuthLink.ts
|
|
220
230
|
var LOGIN_POPUP_QUERY_FLAG = "benji_login_popup";
|
|
221
231
|
function ensureAuthLinkStateNonce(url, nonce) {
|
|
@@ -248,33 +258,80 @@ var ConnectSDK = (() => {
|
|
|
248
258
|
}
|
|
249
259
|
|
|
250
260
|
// src/utils/verifyAppUrl.ts
|
|
251
|
-
var
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
261
|
+
var VERIFYAPP_HOST = /^verifyapp(?:-[a-z0-9]+)?\.withbenji\.com$/i;
|
|
262
|
+
function safeDecode(value) {
|
|
263
|
+
try {
|
|
264
|
+
return decodeURIComponent(value);
|
|
265
|
+
} catch {
|
|
266
|
+
return value;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
function rewriteParsedUrl(raw, local) {
|
|
270
|
+
let parsed;
|
|
271
|
+
try {
|
|
272
|
+
parsed = new URL(raw);
|
|
273
|
+
} catch {
|
|
274
|
+
return raw;
|
|
275
|
+
}
|
|
276
|
+
let changed = false;
|
|
277
|
+
if (VERIFYAPP_HOST.test(parsed.hostname)) {
|
|
278
|
+
parsed.protocol = local.protocol;
|
|
279
|
+
parsed.hostname = local.hostname;
|
|
280
|
+
parsed.port = local.port;
|
|
281
|
+
changed = true;
|
|
282
|
+
}
|
|
283
|
+
for (const key of parsed.searchParams.keys()) {
|
|
284
|
+
const value = parsed.searchParams.get(key);
|
|
285
|
+
if (value == null) {
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
const decoded = safeDecode(value);
|
|
289
|
+
const nested = rewriteParsedUrl(decoded, local);
|
|
290
|
+
if (nested !== decoded) {
|
|
291
|
+
parsed.searchParams.set(key, nested);
|
|
292
|
+
changed = true;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
return changed ? parsed.toString() : raw;
|
|
296
|
+
}
|
|
297
|
+
function rewriteVerifyAppHostsInString(value, local) {
|
|
298
|
+
const localOrigin = local.origin;
|
|
299
|
+
const localHalfEncoded = `${local.protocol.replace(":", "")}%3A//${local.host}`;
|
|
300
|
+
const localFullyEncodedOrigin = encodeURIComponent(localOrigin);
|
|
301
|
+
let result = value;
|
|
302
|
+
result = result.replace(
|
|
303
|
+
/https:\/\/verifyapp(?:-[a-z0-9]+)?\.withbenji\.com/gi,
|
|
304
|
+
localOrigin
|
|
305
|
+
);
|
|
306
|
+
result = result.replace(
|
|
307
|
+
/https%3A\/\/verifyapp(?:-[a-z0-9]+)?\.withbenji\.com/gi,
|
|
308
|
+
localHalfEncoded
|
|
309
|
+
);
|
|
310
|
+
result = result.replace(
|
|
311
|
+
/https%3A%2F%2Fverifyapp(?:-[a-z0-9]+)?\.withbenji\.com/gi,
|
|
312
|
+
localFullyEncodedOrigin
|
|
313
|
+
);
|
|
314
|
+
return result;
|
|
315
|
+
}
|
|
316
|
+
function rewriteVerifyAppUrlForLocalConnect(partnerLoginLink, localOrigin) {
|
|
317
|
+
if (!partnerLoginLink || !localOrigin) {
|
|
259
318
|
return partnerLoginLink;
|
|
260
319
|
}
|
|
261
|
-
let
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
320
|
+
let local;
|
|
321
|
+
try {
|
|
322
|
+
local = new URL(localOrigin);
|
|
323
|
+
} catch {
|
|
324
|
+
return partnerLoginLink;
|
|
325
|
+
}
|
|
326
|
+
if (VERIFYAPP_HOST.test(local.hostname)) {
|
|
327
|
+
return partnerLoginLink;
|
|
269
328
|
}
|
|
270
|
-
|
|
329
|
+
let result = rewriteVerifyAppHostsInString(partnerLoginLink, local);
|
|
330
|
+
result = rewriteParsedUrl(result, local);
|
|
331
|
+
return result;
|
|
271
332
|
}
|
|
272
333
|
|
|
273
334
|
// src/utils/loginTransport.ts
|
|
274
|
-
var LOGIN_PENDING_STORAGE_KEY = "benji_login_pending";
|
|
275
|
-
var LOGIN_FORCE_REDIRECT_STORAGE_KEY = "benji_force_login_redirect";
|
|
276
|
-
var LOGIN_RESUME_QUERY_FLAG = "login_resume";
|
|
277
|
-
var LOGIN_RETURN_STATE_SEPARATOR = ".benji_return.";
|
|
278
335
|
function isIosSafari(userAgent, maxTouchPoints) {
|
|
279
336
|
const isIos = /iPhone|iPad|iPod/.test(userAgent) || userAgent.includes("Macintosh") && maxTouchPoints > 1;
|
|
280
337
|
const isSafari = /Safari/.test(userAgent) && !/CriOS|FxiOS|EdgiOS|OPiOS|Chrome/.test(userAgent);
|
|
@@ -385,10 +442,10 @@ var ConnectSDK = (() => {
|
|
|
385
442
|
args.returnOrigin
|
|
386
443
|
);
|
|
387
444
|
}
|
|
388
|
-
if (!args.rewriteForLocalConnect) {
|
|
445
|
+
if (!args.rewriteForLocalConnect || !args.localVerifyOrigin) {
|
|
389
446
|
return prepared;
|
|
390
447
|
}
|
|
391
|
-
return rewriteVerifyAppUrlForLocalConnect(prepared);
|
|
448
|
+
return rewriteVerifyAppUrlForLocalConnect(prepared, args.localVerifyOrigin);
|
|
392
449
|
}
|
|
393
450
|
|
|
394
451
|
// src/utils/placement.ts
|
|
@@ -884,7 +941,7 @@ var ConnectSDK = (() => {
|
|
|
884
941
|
return false;
|
|
885
942
|
}
|
|
886
943
|
}
|
|
887
|
-
function
|
|
944
|
+
function isLoginPopupOriginatedAuth(event, loginPopup, iframeWindow, connectOrigin) {
|
|
888
945
|
if (iframeWindow && event.source === iframeWindow) {
|
|
889
946
|
return false;
|
|
890
947
|
}
|
|
@@ -896,7 +953,7 @@ var ConnectSDK = (() => {
|
|
|
896
953
|
}
|
|
897
954
|
return isMessageWindow(event.source) && event.origin === connectOrigin && event.source !== iframeWindow;
|
|
898
955
|
}
|
|
899
|
-
function
|
|
956
|
+
function canDeliverLoginAuthToConnectIframe(iframe) {
|
|
900
957
|
var _a;
|
|
901
958
|
const iframeWindow = (_a = iframe == null ? void 0 : iframe.contentWindow) != null ? _a : null;
|
|
902
959
|
if (!iframeWindow) return false;
|
|
@@ -912,13 +969,13 @@ var ConnectSDK = (() => {
|
|
|
912
969
|
const type = data2.type;
|
|
913
970
|
return typeof type === "string" ? type : void 0;
|
|
914
971
|
}
|
|
915
|
-
function resolveLoginPartnerWindow(loginPopup,
|
|
972
|
+
function resolveLoginPartnerWindow(loginPopup, lastVerifiedLoginPopupSource) {
|
|
916
973
|
var _a;
|
|
917
974
|
const candidates = [];
|
|
918
|
-
if (
|
|
919
|
-
candidates.push(
|
|
975
|
+
if (lastVerifiedLoginPopupSource && !lastVerifiedLoginPopupSource.closed) {
|
|
976
|
+
candidates.push(lastVerifiedLoginPopupSource);
|
|
920
977
|
}
|
|
921
|
-
if (loginPopup && !loginPopup.closed && loginPopup !==
|
|
978
|
+
if (loginPopup && !loginPopup.closed && loginPopup !== lastVerifiedLoginPopupSource) {
|
|
922
979
|
candidates.push(loginPopup);
|
|
923
980
|
}
|
|
924
981
|
if (candidates.length === 0) {
|
|
@@ -936,9 +993,9 @@ var ConnectSDK = (() => {
|
|
|
936
993
|
}
|
|
937
994
|
return (_a = candidates[0]) != null ? _a : null;
|
|
938
995
|
}
|
|
939
|
-
function describeLoginPartnerWindowTarget(target, loginPopup,
|
|
996
|
+
function describeLoginPartnerWindowTarget(target, loginPopup, lastVerifiedLoginPopupSource) {
|
|
940
997
|
if (!target) return "none";
|
|
941
|
-
if (target ===
|
|
998
|
+
if (target === lastVerifiedLoginPopupSource) return "lastVerified";
|
|
942
999
|
if (target === loginPopup) return "loginPopup";
|
|
943
1000
|
return "named";
|
|
944
1001
|
}
|
|
@@ -1061,8 +1118,6 @@ var ConnectSDK = (() => {
|
|
|
1061
1118
|
};
|
|
1062
1119
|
|
|
1063
1120
|
// src/router/message.ts
|
|
1064
|
-
var IFRAME_DELIVERABILITY_POLL_MS = 100;
|
|
1065
|
-
var HOST_AUTH_REDELIVERY_MS = 500;
|
|
1066
1121
|
var _MessageRouter = class _MessageRouter {
|
|
1067
1122
|
static configureMessageRouter(config) {
|
|
1068
1123
|
this.onSuccess = config.onSuccess;
|
|
@@ -1079,10 +1134,10 @@ var ConnectSDK = (() => {
|
|
|
1079
1134
|
this.mode = context.mode;
|
|
1080
1135
|
this.connectOrigin = new URL(Endpoints.benji_connect_auth_url).origin;
|
|
1081
1136
|
if (this.canDeliverToConnectIframe()) {
|
|
1082
|
-
this.
|
|
1083
|
-
this.
|
|
1137
|
+
this.flushPendingLoginSameTabAuth();
|
|
1138
|
+
this.flushPendingLoginPopupAuth();
|
|
1084
1139
|
} else {
|
|
1085
|
-
this.
|
|
1140
|
+
this.startLoginConnectIframeDeliverabilityPoll();
|
|
1086
1141
|
}
|
|
1087
1142
|
}
|
|
1088
1143
|
static resetIframeReady() {
|
|
@@ -1091,7 +1146,7 @@ var ConnectSDK = (() => {
|
|
|
1091
1146
|
static setMode(mode) {
|
|
1092
1147
|
this.mode = mode;
|
|
1093
1148
|
if (mode !== 5 /* LOGIN */) {
|
|
1094
|
-
this.
|
|
1149
|
+
this.stopLoginConnectIframeDeliverabilityPoll();
|
|
1095
1150
|
}
|
|
1096
1151
|
}
|
|
1097
1152
|
static addEventListeners() {
|
|
@@ -1105,17 +1160,17 @@ var ConnectSDK = (() => {
|
|
|
1105
1160
|
window.removeEventListener("error", this.errorEventHandler);
|
|
1106
1161
|
window.removeEventListener("unhandledrejection", this.errorEventHandler);
|
|
1107
1162
|
window.removeEventListener("message", this.messageEventHandler);
|
|
1108
|
-
this.
|
|
1109
|
-
this.
|
|
1163
|
+
this.stopLoginConnectIframeDeliverabilityPoll();
|
|
1164
|
+
this.stopLoginSameTabAuthRedelivery();
|
|
1110
1165
|
this.configuredListeners = false;
|
|
1111
1166
|
this.iframe = null;
|
|
1112
1167
|
this.loginPopup = null;
|
|
1113
1168
|
this.mode = 1 /* CONNECT */;
|
|
1114
1169
|
this.connectOrigin = "";
|
|
1115
1170
|
this.isIframeReady = false;
|
|
1116
|
-
this.
|
|
1117
|
-
this.
|
|
1118
|
-
this.
|
|
1171
|
+
this.pendingLoginPopupAuth = [];
|
|
1172
|
+
this.pendingLoginSameTabAuth = [];
|
|
1173
|
+
this.lastVerifiedLoginPopupSource = null;
|
|
1119
1174
|
}
|
|
1120
1175
|
static handleErrorMessage(event) {
|
|
1121
1176
|
switch (event.type) {
|
|
@@ -1136,53 +1191,53 @@ var ConnectSDK = (() => {
|
|
|
1136
1191
|
}
|
|
1137
1192
|
}
|
|
1138
1193
|
static canDeliverToConnectIframe() {
|
|
1139
|
-
return
|
|
1194
|
+
return canDeliverLoginAuthToConnectIframe(this.iframe);
|
|
1140
1195
|
}
|
|
1141
|
-
static
|
|
1142
|
-
if (this.
|
|
1196
|
+
static startLoginConnectIframeDeliverabilityPoll() {
|
|
1197
|
+
if (this.loginConnectIframeDeliverabilityPoll !== null || this.mode !== 5 /* LOGIN */ || this.pendingLoginPopupAuth.length === 0) {
|
|
1143
1198
|
return;
|
|
1144
1199
|
}
|
|
1145
|
-
this.
|
|
1146
|
-
if (this.mode !== 5 /* LOGIN */ || this.
|
|
1147
|
-
this.
|
|
1200
|
+
this.loginConnectIframeDeliverabilityPoll = window.setInterval(() => {
|
|
1201
|
+
if (this.mode !== 5 /* LOGIN */ || this.pendingLoginPopupAuth.length === 0) {
|
|
1202
|
+
this.stopLoginConnectIframeDeliverabilityPoll();
|
|
1148
1203
|
return;
|
|
1149
1204
|
}
|
|
1150
1205
|
if (this.canDeliverToConnectIframe()) {
|
|
1151
|
-
this.
|
|
1206
|
+
this.flushPendingLoginPopupAuth();
|
|
1152
1207
|
}
|
|
1153
|
-
},
|
|
1208
|
+
}, LOGIN_IFRAME_DELIVERABILITY_POLL_MS);
|
|
1154
1209
|
}
|
|
1155
|
-
static
|
|
1156
|
-
if (this.
|
|
1157
|
-
window.clearInterval(this.
|
|
1158
|
-
this.
|
|
1210
|
+
static stopLoginConnectIframeDeliverabilityPoll() {
|
|
1211
|
+
if (this.loginConnectIframeDeliverabilityPoll === null) return;
|
|
1212
|
+
window.clearInterval(this.loginConnectIframeDeliverabilityPoll);
|
|
1213
|
+
this.loginConnectIframeDeliverabilityPoll = null;
|
|
1159
1214
|
}
|
|
1160
1215
|
// Forward popup/tab auth payloads into Connect. Queue until deliverable.
|
|
1161
|
-
static
|
|
1216
|
+
static relayToLoginConnectIframe(event) {
|
|
1162
1217
|
var _a;
|
|
1163
1218
|
const type = authMessageType(event.data);
|
|
1164
1219
|
const deliverable = this.canDeliverToConnectIframe();
|
|
1165
1220
|
const iframeWindow = (_a = this.iframe) == null ? void 0 : _a.contentWindow;
|
|
1166
1221
|
if (!iframeWindow || !deliverable) {
|
|
1167
|
-
this.
|
|
1168
|
-
this.
|
|
1169
|
-
console.debug("[Benji Connect SDK] LOGIN
|
|
1222
|
+
this.pendingLoginPopupAuth.push(event);
|
|
1223
|
+
this.startLoginConnectIframeDeliverabilityPoll();
|
|
1224
|
+
console.debug("[Benji Connect SDK] LOGIN relayToLoginConnectIframe queued", {
|
|
1170
1225
|
type,
|
|
1171
1226
|
queued: true,
|
|
1172
|
-
pendingCount: this.
|
|
1227
|
+
pendingCount: this.pendingLoginPopupAuth.length,
|
|
1173
1228
|
isIframeReady: this.isIframeReady,
|
|
1174
1229
|
deliverable
|
|
1175
1230
|
});
|
|
1176
1231
|
return;
|
|
1177
1232
|
}
|
|
1178
|
-
if (this.
|
|
1179
|
-
this.
|
|
1233
|
+
if (this.pendingLoginPopupAuth.length > 0) {
|
|
1234
|
+
this.flushPendingLoginPopupAuth();
|
|
1180
1235
|
}
|
|
1181
1236
|
iframeWindow.postMessage(event.data, this.connectOrigin);
|
|
1182
|
-
console.debug("[Benji Connect SDK] LOGIN
|
|
1237
|
+
console.debug("[Benji Connect SDK] LOGIN relayToLoginConnectIframe posted", {
|
|
1183
1238
|
type,
|
|
1184
1239
|
queued: false,
|
|
1185
|
-
pendingCount: this.
|
|
1240
|
+
pendingCount: this.pendingLoginPopupAuth.length,
|
|
1186
1241
|
isIframeReady: this.isIframeReady,
|
|
1187
1242
|
deliverable
|
|
1188
1243
|
});
|
|
@@ -1191,52 +1246,52 @@ var ConnectSDK = (() => {
|
|
|
1191
1246
|
* Same-tab LOGIN resume: post immediately, then re-post on an interval until
|
|
1192
1247
|
* FLOW_SUCCESS / onError / close stops redelivery. Connect dedupes repeats.
|
|
1193
1248
|
*/
|
|
1194
|
-
static
|
|
1195
|
-
this.
|
|
1196
|
-
this.
|
|
1197
|
-
this.
|
|
1198
|
-
this.
|
|
1199
|
-
if (!this.
|
|
1200
|
-
this.
|
|
1249
|
+
static startLoginSameTabAuthRedelivery(payload, intervalMs = LOGIN_SAME_TAB_AUTH_REDELIVERY_MS) {
|
|
1250
|
+
this.stopLoginSameTabAuthRedelivery();
|
|
1251
|
+
this.upsertPendingLoginSameTabAuth(payload);
|
|
1252
|
+
this.flushPendingLoginSameTabAuth();
|
|
1253
|
+
this.loginSameTabAuthRedeliveryId = window.setInterval(() => {
|
|
1254
|
+
if (!this.pendingLoginSameTabAuth.length) {
|
|
1255
|
+
this.stopLoginSameTabAuthRedelivery();
|
|
1201
1256
|
return;
|
|
1202
1257
|
}
|
|
1203
|
-
this.
|
|
1258
|
+
this.flushPendingLoginSameTabAuth();
|
|
1204
1259
|
}, intervalMs);
|
|
1205
1260
|
}
|
|
1206
|
-
static
|
|
1207
|
-
if (this.
|
|
1208
|
-
window.clearInterval(this.
|
|
1209
|
-
this.
|
|
1261
|
+
static stopLoginSameTabAuthRedelivery() {
|
|
1262
|
+
if (this.loginSameTabAuthRedeliveryId !== null) {
|
|
1263
|
+
window.clearInterval(this.loginSameTabAuthRedeliveryId);
|
|
1264
|
+
this.loginSameTabAuthRedeliveryId = null;
|
|
1210
1265
|
}
|
|
1211
|
-
this.
|
|
1266
|
+
this.pendingLoginSameTabAuth = [];
|
|
1212
1267
|
}
|
|
1213
|
-
static
|
|
1268
|
+
static upsertPendingLoginSameTabAuth(payload) {
|
|
1214
1269
|
const type = authMessageType(payload);
|
|
1215
1270
|
if (!type) {
|
|
1216
|
-
this.
|
|
1271
|
+
this.pendingLoginSameTabAuth.push(payload);
|
|
1217
1272
|
return;
|
|
1218
1273
|
}
|
|
1219
|
-
const existingIndex = this.
|
|
1274
|
+
const existingIndex = this.pendingLoginSameTabAuth.findIndex(
|
|
1220
1275
|
(item) => authMessageType(item) === type
|
|
1221
1276
|
);
|
|
1222
1277
|
if (existingIndex >= 0) {
|
|
1223
|
-
this.
|
|
1278
|
+
this.pendingLoginSameTabAuth[existingIndex] = payload;
|
|
1224
1279
|
} else {
|
|
1225
|
-
this.
|
|
1280
|
+
this.pendingLoginSameTabAuth.push(payload);
|
|
1226
1281
|
}
|
|
1227
1282
|
}
|
|
1228
|
-
static
|
|
1283
|
+
static flushPendingLoginSameTabAuth() {
|
|
1229
1284
|
var _a, _b;
|
|
1230
|
-
if (!this.
|
|
1285
|
+
if (!this.pendingLoginSameTabAuth.length) return;
|
|
1231
1286
|
const iframeWindow = (_b = (_a = this.iframe) == null ? void 0 : _a.contentWindow) != null ? _b : null;
|
|
1232
1287
|
if (!iframeWindow || !this.canDeliverToConnectIframe()) {
|
|
1233
1288
|
return;
|
|
1234
1289
|
}
|
|
1235
|
-
const queued = [...this.
|
|
1290
|
+
const queued = [...this.pendingLoginSameTabAuth];
|
|
1236
1291
|
for (const payload of queued) {
|
|
1237
1292
|
iframeWindow.postMessage(payload, this.connectOrigin);
|
|
1238
1293
|
}
|
|
1239
|
-
console.debug("[Benji Connect SDK] LOGIN
|
|
1294
|
+
console.debug("[Benji Connect SDK] LOGIN flushPendingLoginSameTabAuth", {
|
|
1240
1295
|
flushedCount: queued.length
|
|
1241
1296
|
});
|
|
1242
1297
|
}
|
|
@@ -1244,36 +1299,36 @@ var ConnectSDK = (() => {
|
|
|
1244
1299
|
if (this.iframe !== iframe) return;
|
|
1245
1300
|
this.isIframeReady = true;
|
|
1246
1301
|
console.debug("[Benji Connect SDK] LOGIN iframe_load");
|
|
1247
|
-
this.
|
|
1248
|
-
this.
|
|
1302
|
+
this.flushPendingLoginSameTabAuth();
|
|
1303
|
+
this.flushPendingLoginPopupAuth();
|
|
1249
1304
|
}
|
|
1250
|
-
static
|
|
1305
|
+
static flushPendingLoginPopupAuth() {
|
|
1251
1306
|
var _a, _b;
|
|
1252
1307
|
const iframeWindow = (_b = (_a = this.iframe) == null ? void 0 : _a.contentWindow) != null ? _b : null;
|
|
1253
|
-
if (!this.
|
|
1254
|
-
this.
|
|
1308
|
+
if (!this.pendingLoginPopupAuth.length) {
|
|
1309
|
+
this.stopLoginConnectIframeDeliverabilityPoll();
|
|
1255
1310
|
return;
|
|
1256
1311
|
}
|
|
1257
1312
|
if (!iframeWindow) {
|
|
1258
|
-
this.
|
|
1313
|
+
this.startLoginConnectIframeDeliverabilityPoll();
|
|
1259
1314
|
return;
|
|
1260
1315
|
}
|
|
1261
1316
|
if (!this.canDeliverToConnectIframe()) {
|
|
1262
|
-
this.
|
|
1263
|
-
console.debug("[Benji Connect SDK] LOGIN
|
|
1264
|
-
pendingCount: this.
|
|
1317
|
+
this.startLoginConnectIframeDeliverabilityPoll();
|
|
1318
|
+
console.debug("[Benji Connect SDK] LOGIN flushPendingLoginPopupAuth skipped", {
|
|
1319
|
+
pendingCount: this.pendingLoginPopupAuth.length,
|
|
1265
1320
|
isIframeReady: this.isIframeReady,
|
|
1266
1321
|
deliverable: false
|
|
1267
1322
|
});
|
|
1268
1323
|
return;
|
|
1269
1324
|
}
|
|
1270
1325
|
const expectedOrigin = this.connectOrigin || new URL(Endpoints.benji_connect_auth_url).origin;
|
|
1271
|
-
const queued = [...this.
|
|
1326
|
+
const queued = [...this.pendingLoginPopupAuth];
|
|
1272
1327
|
let flushedCount = 0;
|
|
1273
1328
|
let skippedNotOriginated = 0;
|
|
1274
1329
|
const remaining = [];
|
|
1275
1330
|
for (const event of queued) {
|
|
1276
|
-
if (!
|
|
1331
|
+
if (!isLoginPopupOriginatedAuth(
|
|
1277
1332
|
event,
|
|
1278
1333
|
this.loginPopup,
|
|
1279
1334
|
iframeWindow,
|
|
@@ -1289,45 +1344,45 @@ var ConnectSDK = (() => {
|
|
|
1289
1344
|
iframeWindow.postMessage(event.data, this.connectOrigin);
|
|
1290
1345
|
flushedCount += 1;
|
|
1291
1346
|
}
|
|
1292
|
-
this.
|
|
1293
|
-
if (this.
|
|
1294
|
-
this.
|
|
1347
|
+
this.pendingLoginPopupAuth = remaining;
|
|
1348
|
+
if (this.pendingLoginPopupAuth.length === 0) {
|
|
1349
|
+
this.stopLoginConnectIframeDeliverabilityPoll();
|
|
1295
1350
|
} else {
|
|
1296
|
-
this.
|
|
1351
|
+
this.startLoginConnectIframeDeliverabilityPoll();
|
|
1297
1352
|
}
|
|
1298
|
-
console.debug("[Benji Connect SDK] LOGIN
|
|
1353
|
+
console.debug("[Benji Connect SDK] LOGIN flushPendingLoginPopupAuth", {
|
|
1299
1354
|
pendingCount: queued.length,
|
|
1300
1355
|
flushedCount,
|
|
1301
1356
|
skippedNotOriginated,
|
|
1302
|
-
remainingCount: this.
|
|
1357
|
+
remainingCount: this.pendingLoginPopupAuth.length
|
|
1303
1358
|
});
|
|
1304
1359
|
}
|
|
1305
|
-
static
|
|
1360
|
+
static relayToLoginPopup(payload) {
|
|
1306
1361
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1307
1362
|
const type = authMessageType(payload);
|
|
1308
1363
|
const target = resolveLoginPartnerWindow(
|
|
1309
1364
|
this.loginPopup,
|
|
1310
|
-
this.
|
|
1365
|
+
this.lastVerifiedLoginPopupSource
|
|
1311
1366
|
);
|
|
1312
1367
|
const targetLabel = describeLoginPartnerWindowTarget(
|
|
1313
1368
|
target,
|
|
1314
1369
|
this.loginPopup,
|
|
1315
|
-
this.
|
|
1370
|
+
this.lastVerifiedLoginPopupSource
|
|
1316
1371
|
);
|
|
1317
1372
|
if (!target) {
|
|
1318
1373
|
console.warn("[Benji Connect SDK] Skipping login auth relay, no live partner window", {
|
|
1319
1374
|
type,
|
|
1320
1375
|
target: targetLabel,
|
|
1321
1376
|
loginPopupClosed: (_b = (_a = this.loginPopup) == null ? void 0 : _a.closed) != null ? _b : true,
|
|
1322
|
-
lastVerifiedClosed: (_d = (_c = this.
|
|
1377
|
+
lastVerifiedClosed: (_d = (_c = this.lastVerifiedLoginPopupSource) == null ? void 0 : _c.closed) != null ? _d : true
|
|
1323
1378
|
});
|
|
1324
1379
|
return;
|
|
1325
1380
|
}
|
|
1326
|
-
console.debug("[Benji Connect SDK] LOGIN
|
|
1381
|
+
console.debug("[Benji Connect SDK] LOGIN relayToLoginPopup", {
|
|
1327
1382
|
type,
|
|
1328
1383
|
target: targetLabel,
|
|
1329
1384
|
loginPopupClosed: (_f = (_e = this.loginPopup) == null ? void 0 : _e.closed) != null ? _f : true,
|
|
1330
|
-
lastVerifiedClosed: (_h = (_g = this.
|
|
1385
|
+
lastVerifiedClosed: (_h = (_g = this.lastVerifiedLoginPopupSource) == null ? void 0 : _g.closed) != null ? _h : true
|
|
1331
1386
|
});
|
|
1332
1387
|
try {
|
|
1333
1388
|
target.postMessage(payload, "*");
|
|
@@ -1355,19 +1410,19 @@ var ConnectSDK = (() => {
|
|
|
1355
1410
|
origin: event.origin,
|
|
1356
1411
|
direction: "iframe_to_popup"
|
|
1357
1412
|
});
|
|
1358
|
-
this.
|
|
1413
|
+
this.relayToLoginPopup(event.data);
|
|
1359
1414
|
return;
|
|
1360
1415
|
}
|
|
1361
|
-
if (
|
|
1416
|
+
if (isLoginPopupOriginatedAuth(event, this.loginPopup, iframeWindow != null ? iframeWindow : null, expectedOrigin2)) {
|
|
1362
1417
|
if (isMessageWindow(event.source)) {
|
|
1363
|
-
this.
|
|
1418
|
+
this.lastVerifiedLoginPopupSource = event.source;
|
|
1364
1419
|
}
|
|
1365
1420
|
console.debug("[Benji Connect SDK] LOGIN auth relay", {
|
|
1366
1421
|
type,
|
|
1367
1422
|
origin: event.origin,
|
|
1368
1423
|
direction: "popup_to_iframe"
|
|
1369
1424
|
});
|
|
1370
|
-
this.
|
|
1425
|
+
this.relayToLoginConnectIframe(event);
|
|
1371
1426
|
return;
|
|
1372
1427
|
}
|
|
1373
1428
|
console.warn("[Benji Connect SDK] LOGIN auth relay unclassified", {
|
|
@@ -1449,19 +1504,19 @@ var ConnectSDK = (() => {
|
|
|
1449
1504
|
_MessageRouter.mode = 1 /* CONNECT */;
|
|
1450
1505
|
_MessageRouter.connectOrigin = "";
|
|
1451
1506
|
_MessageRouter.isIframeReady = false;
|
|
1452
|
-
_MessageRouter.
|
|
1507
|
+
_MessageRouter.pendingLoginPopupAuth = [];
|
|
1453
1508
|
/**
|
|
1454
1509
|
* Sticky host→iframe auth (same-tab LOGIN resume). Kept after each post so
|
|
1455
1510
|
* redelivery can cover the window where the iframe is "deliverable" but
|
|
1456
1511
|
* Connect has not installed its message listener yet.
|
|
1457
|
-
* Invariant: only `
|
|
1512
|
+
* Invariant: only `startLoginSameTabAuthRedelivery` writes this queue, and it always
|
|
1458
1513
|
* owns a timer while the queue is non-empty. The deliverability poll is
|
|
1459
1514
|
* popup-only so it cannot double-post this payload.
|
|
1460
1515
|
*/
|
|
1461
|
-
_MessageRouter.
|
|
1462
|
-
_MessageRouter.
|
|
1463
|
-
_MessageRouter.
|
|
1464
|
-
_MessageRouter.
|
|
1516
|
+
_MessageRouter.pendingLoginSameTabAuth = [];
|
|
1517
|
+
_MessageRouter.loginSameTabAuthRedeliveryId = null;
|
|
1518
|
+
_MessageRouter.lastVerifiedLoginPopupSource = null;
|
|
1519
|
+
_MessageRouter.loginConnectIframeDeliverabilityPoll = null;
|
|
1465
1520
|
_MessageRouter.errorEventHandler = (event) => {
|
|
1466
1521
|
return _MessageRouter.handleErrorMessage(event);
|
|
1467
1522
|
};
|
|
@@ -1471,8 +1526,6 @@ var ConnectSDK = (() => {
|
|
|
1471
1526
|
var MessageRouter = _MessageRouter;
|
|
1472
1527
|
|
|
1473
1528
|
// src/connect-sdk.ts
|
|
1474
|
-
var POPUP_CLOSED_POLL_MS = 500;
|
|
1475
|
-
var SAME_TAB_RESUME_TIMEOUT_MS = 45e3;
|
|
1476
1529
|
var ConnectSDK = class {
|
|
1477
1530
|
constructor(config) {
|
|
1478
1531
|
this.iframe = null;
|
|
@@ -1557,11 +1610,13 @@ var ConnectSDK = (() => {
|
|
|
1557
1610
|
return;
|
|
1558
1611
|
}
|
|
1559
1612
|
const rewriteForLocalConnect = Environment === "local" /* LOCAL */;
|
|
1613
|
+
const localVerifyOrigin = rewriteForLocalConnect ? new URL(Endpoints.benji_connect_auth_url).origin : void 0;
|
|
1560
1614
|
const returnOrigin = window.location.origin;
|
|
1561
1615
|
const url = buildSameTabPartnerAuthUrl({
|
|
1562
1616
|
partnerAuthLink,
|
|
1563
1617
|
configToken: (_d = this.sdkConfig.tokenData) == null ? void 0 : _d.configToken,
|
|
1564
1618
|
rewriteForLocalConnect,
|
|
1619
|
+
localVerifyOrigin,
|
|
1565
1620
|
returnOrigin
|
|
1566
1621
|
});
|
|
1567
1622
|
try {
|
|
@@ -1595,7 +1650,7 @@ var ConnectSDK = (() => {
|
|
|
1595
1650
|
onSuccess: (token, metadata) => {
|
|
1596
1651
|
var _a, _b;
|
|
1597
1652
|
this.clearSameTabResumeTimeout();
|
|
1598
|
-
MessageRouter.
|
|
1653
|
+
MessageRouter.stopLoginSameTabAuthRedelivery();
|
|
1599
1654
|
(_b = (_a = this.sdkConfig).onSuccess) == null ? void 0 : _b.call(_a, token, metadata);
|
|
1600
1655
|
},
|
|
1601
1656
|
onError: (error, errorId, metadata) => {
|
|
@@ -1604,7 +1659,7 @@ var ConnectSDK = (() => {
|
|
|
1604
1659
|
this.close();
|
|
1605
1660
|
} else {
|
|
1606
1661
|
this.clearSameTabResumeTimeout();
|
|
1607
|
-
MessageRouter.
|
|
1662
|
+
MessageRouter.stopLoginSameTabAuthRedelivery();
|
|
1608
1663
|
}
|
|
1609
1664
|
(_b = (_a = this.sdkConfig).onError) == null ? void 0 : _b.call(_a, error, errorId, metadata);
|
|
1610
1665
|
},
|
|
@@ -1657,7 +1712,7 @@ var ConnectSDK = (() => {
|
|
|
1657
1712
|
if ((_a = this.loginPopup) == null ? void 0 : _a.closed) {
|
|
1658
1713
|
const live = resolveLoginPartnerWindow(
|
|
1659
1714
|
this.loginPopup,
|
|
1660
|
-
MessageRouter.
|
|
1715
|
+
MessageRouter.lastVerifiedLoginPopupSource
|
|
1661
1716
|
);
|
|
1662
1717
|
if (live) {
|
|
1663
1718
|
console.debug("[Benji Connect SDK] LOGIN popup_closed_poll skipped, live partner window remains");
|
|
@@ -1670,7 +1725,7 @@ var ConnectSDK = (() => {
|
|
|
1670
1725
|
});
|
|
1671
1726
|
this.close();
|
|
1672
1727
|
}
|
|
1673
|
-
},
|
|
1728
|
+
}, LOGIN_POPUP_CLOSED_POLL_MS);
|
|
1674
1729
|
}
|
|
1675
1730
|
stopPopupClosedPoll() {
|
|
1676
1731
|
if (this.popupClosedPollId != null) {
|
|
@@ -1748,7 +1803,7 @@ var ConnectSDK = (() => {
|
|
|
1748
1803
|
token: params.state,
|
|
1749
1804
|
redirectUri: (_a = params.redirectUri) != null ? _a : this.buildCallbackUrl(params.partnerId)
|
|
1750
1805
|
});
|
|
1751
|
-
MessageRouter.
|
|
1806
|
+
MessageRouter.startLoginSameTabAuthRedelivery(payload);
|
|
1752
1807
|
this.startSameTabResumeTimeout();
|
|
1753
1808
|
}
|
|
1754
1809
|
buildCallbackUrl(partnerId) {
|
|
@@ -1768,7 +1823,7 @@ var ConnectSDK = (() => {
|
|
|
1768
1823
|
{ context: buildContext() }
|
|
1769
1824
|
);
|
|
1770
1825
|
this.close();
|
|
1771
|
-
},
|
|
1826
|
+
}, LOGIN_SAME_TAB_RESUME_TIMEOUT_MS);
|
|
1772
1827
|
}
|
|
1773
1828
|
clearSameTabResumeTimeout() {
|
|
1774
1829
|
if (this.sameTabResumeTimeoutId === null) return;
|
|
@@ -1794,7 +1849,7 @@ var ConnectSDK = (() => {
|
|
|
1794
1849
|
applyOverlayBaseStyle(this.container);
|
|
1795
1850
|
}
|
|
1796
1851
|
console.debug("[Connect SDK] endpoints", Endpoints);
|
|
1797
|
-
console.
|
|
1852
|
+
console.debug("[Connect SDK] opening URL", Endpoints.benji_connect_auth_url);
|
|
1798
1853
|
const url = new URL(Endpoints.benji_connect_auth_url);
|
|
1799
1854
|
const connectToken = this.sdkConfig.token;
|
|
1800
1855
|
url.searchParams.set("connect_token", connectToken);
|
|
@@ -1884,7 +1939,7 @@ var ConnectSDK = (() => {
|
|
|
1884
1939
|
var _a, _b;
|
|
1885
1940
|
this.abortInflightOpen();
|
|
1886
1941
|
this.clearSameTabResumeTimeout();
|
|
1887
|
-
MessageRouter.
|
|
1942
|
+
MessageRouter.stopLoginSameTabAuthRedelivery();
|
|
1888
1943
|
this.isResumingSameTabLogin = false;
|
|
1889
1944
|
this.isClosing = true;
|
|
1890
1945
|
this.stopPopupClosedPoll();
|