@namiml/sdk-core 3.4.0-dev.202604031805 → 3.4.0-dev.202604032229
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 +26 -40
- package/dist/index.d.ts +2 -0
- package/dist/index.mjs +26 -40
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,23 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
let _adapters = null;
|
|
4
|
-
const __coreAdaptersInstanceId = Math.random().toString(16).slice(2);
|
|
5
4
|
function registerPlatformAdapters(adapters) {
|
|
6
5
|
_adapters = adapters;
|
|
7
|
-
try {
|
|
8
|
-
globalThis.__NAMI_CORE_LAST_REGISTER_INSTANCE_ID = __coreAdaptersInstanceId;
|
|
9
|
-
globalThis.__NAMI_CORE_LAST_REGISTERED_AT = Date.now();
|
|
10
|
-
}
|
|
11
|
-
catch {
|
|
12
|
-
// ignore
|
|
13
|
-
}
|
|
14
|
-
// Vega/Metro debugging: confirms which core module instance is registering adapters.
|
|
15
|
-
console.warn('[NamiCore] registerPlatformAdapters', {
|
|
16
|
-
instanceId: __coreAdaptersInstanceId,
|
|
17
|
-
hasDeviceAdapter: Boolean(adapters?.device),
|
|
18
|
-
hasStorageAdapter: Boolean(adapters?.storage),
|
|
19
|
-
hasUIAdapter: Boolean(adapters?.ui),
|
|
20
|
-
});
|
|
21
6
|
}
|
|
22
7
|
const _fallback = {
|
|
23
8
|
storage: {
|
|
@@ -42,23 +27,6 @@ const _fallback = {
|
|
|
42
27
|
},
|
|
43
28
|
};
|
|
44
29
|
function getPlatformAdapters() {
|
|
45
|
-
let lastRegisterInstanceId;
|
|
46
|
-
let lastRegisteredAt;
|
|
47
|
-
try {
|
|
48
|
-
lastRegisterInstanceId = globalThis.__NAMI_CORE_LAST_REGISTER_INSTANCE_ID;
|
|
49
|
-
lastRegisteredAt = globalThis.__NAMI_CORE_LAST_REGISTERED_AT;
|
|
50
|
-
}
|
|
51
|
-
catch {
|
|
52
|
-
// ignore
|
|
53
|
-
}
|
|
54
|
-
// Vega/Metro debugging: if you see different instanceIds across calls, core is loaded twice (CJS+ESM).
|
|
55
|
-
console.warn('[NamiCore] getPlatformAdapters', {
|
|
56
|
-
instanceId: __coreAdaptersInstanceId,
|
|
57
|
-
lastRegisterInstanceId,
|
|
58
|
-
lastRegisteredAt,
|
|
59
|
-
hasAdapters: Boolean(_adapters),
|
|
60
|
-
usingFallback: !_adapters,
|
|
61
|
-
});
|
|
62
30
|
return _adapters ?? _fallback;
|
|
63
31
|
}
|
|
64
32
|
|
|
@@ -123,7 +91,7 @@ const {
|
|
|
123
91
|
// version — stamped by scripts/version.sh
|
|
124
92
|
NAMI_SDK_VERSION: exports.NAMI_SDK_VERSION = "3.4.0",
|
|
125
93
|
// full package version including dev suffix — stamped by scripts/version.sh
|
|
126
|
-
NAMI_SDK_PACKAGE_VERSION: exports.NAMI_SDK_PACKAGE_VERSION = "3.4.0-dev.
|
|
94
|
+
NAMI_SDK_PACKAGE_VERSION: exports.NAMI_SDK_PACKAGE_VERSION = "3.4.0-dev.202604032229",
|
|
127
95
|
// environments
|
|
128
96
|
PRODUCTION: exports.PRODUCTION = "production", DEVELOPMENT: exports.DEVELOPMENT = "development",
|
|
129
97
|
// error messages
|
|
@@ -7049,10 +7017,7 @@ const hasGetRandomValues = typeof cryptoObj?.getRandomValues === 'function';
|
|
|
7049
7017
|
const FALLBACK_BASE = 16;
|
|
7050
7018
|
const FALLBACK_BASE_RECIPROCAL = 1 / FALLBACK_BASE;
|
|
7051
7019
|
const getDeviceData = (namiCommands) => {
|
|
7052
|
-
|
|
7053
|
-
const data = getPlatformAdapters().device.getDeviceData(namiCommands);
|
|
7054
|
-
console.log('[NamiCore] getDeviceData data', data);
|
|
7055
|
-
return data;
|
|
7020
|
+
return getPlatformAdapters().device.getDeviceData(namiCommands);
|
|
7056
7021
|
};
|
|
7057
7022
|
const getDeviceFormFactor = () => {
|
|
7058
7023
|
const config = storageService.getNamiConfig();
|
|
@@ -7976,7 +7941,7 @@ class CampaignRuleRepository {
|
|
|
7976
7941
|
}
|
|
7977
7942
|
// get campaign rules according to device's form_factor
|
|
7978
7943
|
campaignRules = campaignRules?.filter((cRule) => (cRule.paywall && cRule.form_factors.some((f) => f.form_factor === this.currentFormFactor)) ||
|
|
7979
|
-
(cRule.flow && cRule.
|
|
7944
|
+
(cRule.flow && cRule.form_factors?.some((f) => f.form_factor === this.currentFormFactor)));
|
|
7980
7945
|
// Keep only those campaign rules whose corresponding paywall is available
|
|
7981
7946
|
campaignRules = campaignRules?.filter((cRule) => {
|
|
7982
7947
|
if (cRule.paywall) {
|
|
@@ -8003,11 +7968,14 @@ class CampaignRuleRepository {
|
|
|
8003
7968
|
if (campaign.page_urls) {
|
|
8004
7969
|
urls.push(...Object.values(campaign.page_urls));
|
|
8005
7970
|
}
|
|
7971
|
+
if (campaign.flow?.page_urls) {
|
|
7972
|
+
urls.push(...Object.values(campaign.flow.page_urls));
|
|
7973
|
+
}
|
|
8006
7974
|
}
|
|
8007
7975
|
return urls;
|
|
8008
7976
|
}
|
|
8009
7977
|
static hasPaywallUrls(campaigns) {
|
|
8010
|
-
return campaigns.some((c) => c.paywall_url || c.page_urls);
|
|
7978
|
+
return campaigns.some((c) => c.paywall_url || c.page_urls || c.flow?.page_urls);
|
|
8011
7979
|
}
|
|
8012
7980
|
async fetchCampaignRulesRaw() {
|
|
8013
7981
|
const authDevice = storageService.getDevice();
|
|
@@ -8023,7 +7991,7 @@ class CampaignRuleRepository {
|
|
|
8023
7991
|
campaignRules = await this.getCampaigns(authDevice.id);
|
|
8024
7992
|
}
|
|
8025
7993
|
campaignRules = campaignRules?.filter((cRule) => (cRule.paywall && cRule.form_factors.some((f) => f.form_factor === this.currentFormFactor)) ||
|
|
8026
|
-
(cRule.flow && cRule.
|
|
7994
|
+
(cRule.flow && cRule.form_factors?.some((f) => f.form_factor === this.currentFormFactor)));
|
|
8027
7995
|
return campaignRules;
|
|
8028
7996
|
}
|
|
8029
7997
|
finalizeCampaignRules(campaignRules, paywalls) {
|
|
@@ -11701,6 +11669,24 @@ class NamiRefs {
|
|
|
11701
11669
|
const campaignRulesStartTime = Date.now();
|
|
11702
11670
|
const rawCampaigns = await campaignRepo.fetchCampaignRulesRaw();
|
|
11703
11671
|
const campaignRulesDuration = Date.now() - campaignRulesStartTime;
|
|
11672
|
+
// Hydrate flow objects: fetch flow JSON from flow.url for campaigns that
|
|
11673
|
+
// use the new URL-based format (3.4.0+) instead of inline flow.object
|
|
11674
|
+
await Promise.all(rawCampaigns
|
|
11675
|
+
.filter((c) => c.flow?.url && !c.flow.object)
|
|
11676
|
+
.map(async (c) => {
|
|
11677
|
+
try {
|
|
11678
|
+
const res = await fetch(c.flow.url, { cache: 'no-cache' });
|
|
11679
|
+
if (res.ok) {
|
|
11680
|
+
c.flow.object = await res.json();
|
|
11681
|
+
}
|
|
11682
|
+
else {
|
|
11683
|
+
logger.warn(`Failed to fetch flow object from ${c.flow.url}: ${res.status}`);
|
|
11684
|
+
}
|
|
11685
|
+
}
|
|
11686
|
+
catch (err) {
|
|
11687
|
+
logger.warn(`Error fetching flow object from ${c.flow.url}: ${err}`);
|
|
11688
|
+
}
|
|
11689
|
+
}));
|
|
11704
11690
|
const useIndividual = !campaignRepo.useLegacyPaywallFetch &&
|
|
11705
11691
|
CampaignRuleRepository.hasPaywallUrls(rawCampaigns);
|
|
11706
11692
|
let paywalls;
|
package/dist/index.d.ts
CHANGED
|
@@ -138,6 +138,8 @@ interface NamiFlowDTO {
|
|
|
138
138
|
flow_id?: string;
|
|
139
139
|
object_id?: string;
|
|
140
140
|
object?: NamiFlowObjectDTO;
|
|
141
|
+
url?: string;
|
|
142
|
+
page_urls?: Record<string, string>;
|
|
141
143
|
}
|
|
142
144
|
type NamiFlowWithObject = Omit<NamiFlowDTO, 'object'> & {
|
|
143
145
|
object: NamiFlowObjectDTO;
|
package/dist/index.mjs
CHANGED
|
@@ -1,21 +1,6 @@
|
|
|
1
1
|
let _adapters = null;
|
|
2
|
-
const __coreAdaptersInstanceId = Math.random().toString(16).slice(2);
|
|
3
2
|
function registerPlatformAdapters(adapters) {
|
|
4
3
|
_adapters = adapters;
|
|
5
|
-
try {
|
|
6
|
-
globalThis.__NAMI_CORE_LAST_REGISTER_INSTANCE_ID = __coreAdaptersInstanceId;
|
|
7
|
-
globalThis.__NAMI_CORE_LAST_REGISTERED_AT = Date.now();
|
|
8
|
-
}
|
|
9
|
-
catch {
|
|
10
|
-
// ignore
|
|
11
|
-
}
|
|
12
|
-
// Vega/Metro debugging: confirms which core module instance is registering adapters.
|
|
13
|
-
console.warn('[NamiCore] registerPlatformAdapters', {
|
|
14
|
-
instanceId: __coreAdaptersInstanceId,
|
|
15
|
-
hasDeviceAdapter: Boolean(adapters?.device),
|
|
16
|
-
hasStorageAdapter: Boolean(adapters?.storage),
|
|
17
|
-
hasUIAdapter: Boolean(adapters?.ui),
|
|
18
|
-
});
|
|
19
4
|
}
|
|
20
5
|
const _fallback = {
|
|
21
6
|
storage: {
|
|
@@ -40,23 +25,6 @@ const _fallback = {
|
|
|
40
25
|
},
|
|
41
26
|
};
|
|
42
27
|
function getPlatformAdapters() {
|
|
43
|
-
let lastRegisterInstanceId;
|
|
44
|
-
let lastRegisteredAt;
|
|
45
|
-
try {
|
|
46
|
-
lastRegisterInstanceId = globalThis.__NAMI_CORE_LAST_REGISTER_INSTANCE_ID;
|
|
47
|
-
lastRegisteredAt = globalThis.__NAMI_CORE_LAST_REGISTERED_AT;
|
|
48
|
-
}
|
|
49
|
-
catch {
|
|
50
|
-
// ignore
|
|
51
|
-
}
|
|
52
|
-
// Vega/Metro debugging: if you see different instanceIds across calls, core is loaded twice (CJS+ESM).
|
|
53
|
-
console.warn('[NamiCore] getPlatformAdapters', {
|
|
54
|
-
instanceId: __coreAdaptersInstanceId,
|
|
55
|
-
lastRegisterInstanceId,
|
|
56
|
-
lastRegisteredAt,
|
|
57
|
-
hasAdapters: Boolean(_adapters),
|
|
58
|
-
usingFallback: !_adapters,
|
|
59
|
-
});
|
|
60
28
|
return _adapters ?? _fallback;
|
|
61
29
|
}
|
|
62
30
|
|
|
@@ -121,7 +89,7 @@ const {
|
|
|
121
89
|
// version — stamped by scripts/version.sh
|
|
122
90
|
NAMI_SDK_VERSION = "3.4.0",
|
|
123
91
|
// full package version including dev suffix — stamped by scripts/version.sh
|
|
124
|
-
NAMI_SDK_PACKAGE_VERSION = "3.4.0-dev.
|
|
92
|
+
NAMI_SDK_PACKAGE_VERSION = "3.4.0-dev.202604032229",
|
|
125
93
|
// environments
|
|
126
94
|
PRODUCTION = "production", DEVELOPMENT = "development",
|
|
127
95
|
// error messages
|
|
@@ -7047,10 +7015,7 @@ const hasGetRandomValues = typeof cryptoObj?.getRandomValues === 'function';
|
|
|
7047
7015
|
const FALLBACK_BASE = 16;
|
|
7048
7016
|
const FALLBACK_BASE_RECIPROCAL = 1 / FALLBACK_BASE;
|
|
7049
7017
|
const getDeviceData = (namiCommands) => {
|
|
7050
|
-
|
|
7051
|
-
const data = getPlatformAdapters().device.getDeviceData(namiCommands);
|
|
7052
|
-
console.log('[NamiCore] getDeviceData data', data);
|
|
7053
|
-
return data;
|
|
7018
|
+
return getPlatformAdapters().device.getDeviceData(namiCommands);
|
|
7054
7019
|
};
|
|
7055
7020
|
const getDeviceFormFactor = () => {
|
|
7056
7021
|
const config = storageService.getNamiConfig();
|
|
@@ -7974,7 +7939,7 @@ class CampaignRuleRepository {
|
|
|
7974
7939
|
}
|
|
7975
7940
|
// get campaign rules according to device's form_factor
|
|
7976
7941
|
campaignRules = campaignRules?.filter((cRule) => (cRule.paywall && cRule.form_factors.some((f) => f.form_factor === this.currentFormFactor)) ||
|
|
7977
|
-
(cRule.flow && cRule.
|
|
7942
|
+
(cRule.flow && cRule.form_factors?.some((f) => f.form_factor === this.currentFormFactor)));
|
|
7978
7943
|
// Keep only those campaign rules whose corresponding paywall is available
|
|
7979
7944
|
campaignRules = campaignRules?.filter((cRule) => {
|
|
7980
7945
|
if (cRule.paywall) {
|
|
@@ -8001,11 +7966,14 @@ class CampaignRuleRepository {
|
|
|
8001
7966
|
if (campaign.page_urls) {
|
|
8002
7967
|
urls.push(...Object.values(campaign.page_urls));
|
|
8003
7968
|
}
|
|
7969
|
+
if (campaign.flow?.page_urls) {
|
|
7970
|
+
urls.push(...Object.values(campaign.flow.page_urls));
|
|
7971
|
+
}
|
|
8004
7972
|
}
|
|
8005
7973
|
return urls;
|
|
8006
7974
|
}
|
|
8007
7975
|
static hasPaywallUrls(campaigns) {
|
|
8008
|
-
return campaigns.some((c) => c.paywall_url || c.page_urls);
|
|
7976
|
+
return campaigns.some((c) => c.paywall_url || c.page_urls || c.flow?.page_urls);
|
|
8009
7977
|
}
|
|
8010
7978
|
async fetchCampaignRulesRaw() {
|
|
8011
7979
|
const authDevice = storageService.getDevice();
|
|
@@ -8021,7 +7989,7 @@ class CampaignRuleRepository {
|
|
|
8021
7989
|
campaignRules = await this.getCampaigns(authDevice.id);
|
|
8022
7990
|
}
|
|
8023
7991
|
campaignRules = campaignRules?.filter((cRule) => (cRule.paywall && cRule.form_factors.some((f) => f.form_factor === this.currentFormFactor)) ||
|
|
8024
|
-
(cRule.flow && cRule.
|
|
7992
|
+
(cRule.flow && cRule.form_factors?.some((f) => f.form_factor === this.currentFormFactor)));
|
|
8025
7993
|
return campaignRules;
|
|
8026
7994
|
}
|
|
8027
7995
|
finalizeCampaignRules(campaignRules, paywalls) {
|
|
@@ -11699,6 +11667,24 @@ class NamiRefs {
|
|
|
11699
11667
|
const campaignRulesStartTime = Date.now();
|
|
11700
11668
|
const rawCampaigns = await campaignRepo.fetchCampaignRulesRaw();
|
|
11701
11669
|
const campaignRulesDuration = Date.now() - campaignRulesStartTime;
|
|
11670
|
+
// Hydrate flow objects: fetch flow JSON from flow.url for campaigns that
|
|
11671
|
+
// use the new URL-based format (3.4.0+) instead of inline flow.object
|
|
11672
|
+
await Promise.all(rawCampaigns
|
|
11673
|
+
.filter((c) => c.flow?.url && !c.flow.object)
|
|
11674
|
+
.map(async (c) => {
|
|
11675
|
+
try {
|
|
11676
|
+
const res = await fetch(c.flow.url, { cache: 'no-cache' });
|
|
11677
|
+
if (res.ok) {
|
|
11678
|
+
c.flow.object = await res.json();
|
|
11679
|
+
}
|
|
11680
|
+
else {
|
|
11681
|
+
logger.warn(`Failed to fetch flow object from ${c.flow.url}: ${res.status}`);
|
|
11682
|
+
}
|
|
11683
|
+
}
|
|
11684
|
+
catch (err) {
|
|
11685
|
+
logger.warn(`Error fetching flow object from ${c.flow.url}: ${err}`);
|
|
11686
|
+
}
|
|
11687
|
+
}));
|
|
11702
11688
|
const useIndividual = !campaignRepo.useLegacyPaywallFetch &&
|
|
11703
11689
|
CampaignRuleRepository.hasPaywallUrls(rawCampaigns);
|
|
11704
11690
|
let paywalls;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@namiml/sdk-core",
|
|
3
|
-
"version": "3.4.0-dev.
|
|
3
|
+
"version": "3.4.0-dev.202604032229",
|
|
4
4
|
"description": "Platform-agnostic core for the Nami SDK — business logic, API, types, and state management",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|