@opexa/portal-sdk 0.17.0 → 0.18.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/dist/index.cjs +84 -74
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -4
- package/dist/index.d.ts +3 -4
- package/dist/index.js +84 -74
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -4113,6 +4113,49 @@ var AdManager = class {
|
|
|
4113
4113
|
}
|
|
4114
4114
|
};
|
|
4115
4115
|
|
|
4116
|
+
// src/sdk/domain.manager.ts
|
|
4117
|
+
var DomainManager = class {
|
|
4118
|
+
logger;
|
|
4119
|
+
platform;
|
|
4120
|
+
constructor(config) {
|
|
4121
|
+
this.logger = config.logger;
|
|
4122
|
+
this.platform = config.platform;
|
|
4123
|
+
}
|
|
4124
|
+
get domain() {
|
|
4125
|
+
if (this.isServer) {
|
|
4126
|
+
this.logger.warn("Cannot determine domain on the server.");
|
|
4127
|
+
return null;
|
|
4128
|
+
}
|
|
4129
|
+
if (this.isIOS) return `ios/${this.platform}`;
|
|
4130
|
+
if (this.isAndroid) return `android/${this.platform}`;
|
|
4131
|
+
const url = new URL(window.location.href);
|
|
4132
|
+
if (url.searchParams.has("m")) return `${url.hostname}/${url.searchParams.get("m")}`;
|
|
4133
|
+
const map = {
|
|
4134
|
+
"crazywin.ph": "587374767622209",
|
|
4135
|
+
"crazywin.asia": "587374767622209",
|
|
4136
|
+
"happybingo.ph": "617045164450475"
|
|
4137
|
+
};
|
|
4138
|
+
return map[url.hostname] ? map[url.hostname] : url.hostname;
|
|
4139
|
+
}
|
|
4140
|
+
get isServer() {
|
|
4141
|
+
return typeof window === "undefined";
|
|
4142
|
+
}
|
|
4143
|
+
get isIOS() {
|
|
4144
|
+
return [
|
|
4145
|
+
//
|
|
4146
|
+
"iPad Simulator",
|
|
4147
|
+
"iPhone Simulator",
|
|
4148
|
+
"iPod Simulator",
|
|
4149
|
+
"iPad",
|
|
4150
|
+
"iPhone",
|
|
4151
|
+
"iPod"
|
|
4152
|
+
].includes(navigator.platform) || navigator.userAgent.includes("Mac") && "ontouchend" in document;
|
|
4153
|
+
}
|
|
4154
|
+
get isAndroid() {
|
|
4155
|
+
return /Android/i.test(navigator.userAgent);
|
|
4156
|
+
}
|
|
4157
|
+
};
|
|
4158
|
+
|
|
4116
4159
|
// src/sdk/logger.ts
|
|
4117
4160
|
var Logger = class {
|
|
4118
4161
|
enabled;
|
|
@@ -4133,46 +4176,6 @@ var Logger = class {
|
|
|
4133
4176
|
}
|
|
4134
4177
|
};
|
|
4135
4178
|
|
|
4136
|
-
// src/sdk/meta-pixel.manager.ts
|
|
4137
|
-
var MetaPixelManager = class {
|
|
4138
|
-
logger;
|
|
4139
|
-
domain;
|
|
4140
|
-
metaPixelId = null;
|
|
4141
|
-
constructor(config) {
|
|
4142
|
-
this.logger = config.logger;
|
|
4143
|
-
this.domain = this.getDomain();
|
|
4144
|
-
this.metaPixelId = this.getMetaPixelId(this.domain);
|
|
4145
|
-
}
|
|
4146
|
-
getDomain() {
|
|
4147
|
-
if (this.isServer) {
|
|
4148
|
-
this.logger.warn("Cannot determine domain on the server.");
|
|
4149
|
-
return "";
|
|
4150
|
-
}
|
|
4151
|
-
const url = new URL(window.location.href);
|
|
4152
|
-
const rootDomain = url.hostname;
|
|
4153
|
-
const mQueryParam = url.searchParams.get("m");
|
|
4154
|
-
return mQueryParam ? `${rootDomain}/${mQueryParam}` : rootDomain;
|
|
4155
|
-
}
|
|
4156
|
-
getMetaPixelId(domain) {
|
|
4157
|
-
const domainMapping = {
|
|
4158
|
-
"crazywin.ph": "587374767622209",
|
|
4159
|
-
"crazywin.asia": "587374767622209",
|
|
4160
|
-
"happybingo.ph": "617045164450475"
|
|
4161
|
-
};
|
|
4162
|
-
const rootDomain = domain.split("/")[0];
|
|
4163
|
-
return domainMapping[rootDomain] || null;
|
|
4164
|
-
}
|
|
4165
|
-
getMetaPixel() {
|
|
4166
|
-
return this.metaPixelId;
|
|
4167
|
-
}
|
|
4168
|
-
getDomainUrl() {
|
|
4169
|
-
return this.domain;
|
|
4170
|
-
}
|
|
4171
|
-
get isServer() {
|
|
4172
|
-
return typeof window === "undefined";
|
|
4173
|
-
}
|
|
4174
|
-
};
|
|
4175
|
-
|
|
4176
4179
|
// src/utils/sleep.ts
|
|
4177
4180
|
function sleep(ms) {
|
|
4178
4181
|
return new Promise((resolve) => {
|
|
@@ -5428,6 +5431,10 @@ var Transformer = class {
|
|
|
5428
5431
|
};
|
|
5429
5432
|
|
|
5430
5433
|
// src/sdk/sdk.ts
|
|
5434
|
+
var defaultConfig = {
|
|
5435
|
+
environment: "development",
|
|
5436
|
+
logs: false
|
|
5437
|
+
};
|
|
5431
5438
|
var Sdk = class {
|
|
5432
5439
|
cmsPortalService;
|
|
5433
5440
|
authService;
|
|
@@ -5440,7 +5447,7 @@ var Sdk = class {
|
|
|
5440
5447
|
triggerService;
|
|
5441
5448
|
sessionManager;
|
|
5442
5449
|
adManager;
|
|
5443
|
-
|
|
5450
|
+
domainManager;
|
|
5444
5451
|
transformer;
|
|
5445
5452
|
logger;
|
|
5446
5453
|
cache;
|
|
@@ -5450,15 +5457,18 @@ var Sdk = class {
|
|
|
5450
5457
|
site,
|
|
5451
5458
|
sitePlatform,
|
|
5452
5459
|
platform,
|
|
5453
|
-
environment
|
|
5460
|
+
environment,
|
|
5454
5461
|
logs
|
|
5455
|
-
} = config;
|
|
5462
|
+
} = Object.assign(defaultConfig, config);
|
|
5456
5463
|
const production = environment === "production";
|
|
5457
5464
|
const logger = new Logger({
|
|
5458
|
-
enabled: logs
|
|
5465
|
+
enabled: logs
|
|
5459
5466
|
});
|
|
5460
5467
|
const adManager = new AdManager({ logger });
|
|
5461
|
-
const
|
|
5468
|
+
const domainManager = new DomainManager({
|
|
5469
|
+
logger,
|
|
5470
|
+
platform
|
|
5471
|
+
});
|
|
5462
5472
|
const transformer = new Transformer();
|
|
5463
5473
|
const authUrl = ENDPOINTS[environment].auth;
|
|
5464
5474
|
const walletUrl = ENDPOINTS[environment].wallet;
|
|
@@ -5478,15 +5488,13 @@ var Sdk = class {
|
|
|
5478
5488
|
middlewares: [
|
|
5479
5489
|
/**/
|
|
5480
5490
|
this.authMiddleware,
|
|
5481
|
-
this.
|
|
5482
|
-
this.
|
|
5491
|
+
this.domainMiddleware,
|
|
5492
|
+
this.miscMiddleware
|
|
5483
5493
|
],
|
|
5484
5494
|
fetchOptions: {
|
|
5485
5495
|
headers: {
|
|
5486
5496
|
Role: "MEMBER",
|
|
5487
|
-
"Platform-Code": platform
|
|
5488
|
-
Domain: metaPixelManager.getDomainUrl()
|
|
5489
|
-
// dk if this is where I should set the Meta Pixel domain.
|
|
5497
|
+
"Platform-Code": platform
|
|
5490
5498
|
}
|
|
5491
5499
|
}
|
|
5492
5500
|
};
|
|
@@ -5516,7 +5524,7 @@ var Sdk = class {
|
|
|
5516
5524
|
});
|
|
5517
5525
|
this.logger = logger;
|
|
5518
5526
|
this.adManager = adManager;
|
|
5519
|
-
this.
|
|
5527
|
+
this.domainManager = domainManager;
|
|
5520
5528
|
this.transformer = transformer;
|
|
5521
5529
|
this.authService = authService;
|
|
5522
5530
|
this.gameService = gameService;
|
|
@@ -5541,28 +5549,6 @@ var Sdk = class {
|
|
|
5541
5549
|
get adClickId() {
|
|
5542
5550
|
return this.adManager.clickId;
|
|
5543
5551
|
}
|
|
5544
|
-
get miscMiddleware() {
|
|
5545
|
-
return async (request) => {
|
|
5546
|
-
const adClickId = this.adManager.clickId;
|
|
5547
|
-
if (adClickId) request.headers.append("Ad-Click-Id", adClickId);
|
|
5548
|
-
return request;
|
|
5549
|
-
};
|
|
5550
|
-
}
|
|
5551
|
-
/*
|
|
5552
|
-
*=============================================
|
|
5553
|
-
* META PIXEL ID
|
|
5554
|
-
*=============================================
|
|
5555
|
-
*/
|
|
5556
|
-
get metaPixelId() {
|
|
5557
|
-
return this.metaPixelManager.getMetaPixel();
|
|
5558
|
-
}
|
|
5559
|
-
get metaPixelMiddleware() {
|
|
5560
|
-
return async (request) => {
|
|
5561
|
-
const metaPixelId = this.metaPixelId;
|
|
5562
|
-
if (metaPixelId) request.headers.append("Domain", metaPixelId);
|
|
5563
|
-
return request;
|
|
5564
|
-
};
|
|
5565
|
-
}
|
|
5566
5552
|
/*
|
|
5567
5553
|
*=============================================
|
|
5568
5554
|
* LOCALE
|
|
@@ -5586,7 +5572,7 @@ var Sdk = class {
|
|
|
5586
5572
|
}
|
|
5587
5573
|
/*
|
|
5588
5574
|
*=============================================
|
|
5589
|
-
* AUTH
|
|
5575
|
+
* AUTH MIDDLEWARE
|
|
5590
5576
|
*=============================================
|
|
5591
5577
|
*/
|
|
5592
5578
|
get authMiddleware() {
|
|
@@ -5603,6 +5589,30 @@ var Sdk = class {
|
|
|
5603
5589
|
return request;
|
|
5604
5590
|
};
|
|
5605
5591
|
}
|
|
5592
|
+
/*
|
|
5593
|
+
*=============================================
|
|
5594
|
+
* DOMAIN MIDDLEWARE
|
|
5595
|
+
*=============================================
|
|
5596
|
+
*/
|
|
5597
|
+
get domainMiddleware() {
|
|
5598
|
+
return async (request) => {
|
|
5599
|
+
const domain = this.domainManager.domain;
|
|
5600
|
+
if (domain) request.headers.append("Domain", domain);
|
|
5601
|
+
return request;
|
|
5602
|
+
};
|
|
5603
|
+
}
|
|
5604
|
+
/*
|
|
5605
|
+
*=============================================
|
|
5606
|
+
* MISCELLANEOUS MIDDLEWARE
|
|
5607
|
+
*=============================================
|
|
5608
|
+
*/
|
|
5609
|
+
get miscMiddleware() {
|
|
5610
|
+
return async (request) => {
|
|
5611
|
+
const adClickId = this.adManager.clickId;
|
|
5612
|
+
if (adClickId) request.headers.append("Ad-Click-Id", adClickId);
|
|
5613
|
+
return request;
|
|
5614
|
+
};
|
|
5615
|
+
}
|
|
5606
5616
|
async signIn(input) {
|
|
5607
5617
|
if (input.type === "TOKEN") {
|
|
5608
5618
|
console.warn("'TOKEN (signIn)' is deprecated. Please use 'SOCIALS' instead.");
|