react-native-nami-sdk 3.5.0-dev.202611042127 → 3.5.0-dev.202611052201
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/android/build.gradle +2 -2
- package/android/src/main/java/com/namiml/reactnative/NamiBridgeModule.kt +12 -0
- package/dist/specs/NativeNami.d.ts +1 -0
- package/dist/src/Nami.d.ts +7 -0
- package/dist/src/NamiCampaignManager.d.ts +2 -16
- package/dist/src/transformers.d.ts +9 -2
- package/dist/src/types.d.ts +2 -0
- package/dist/src/version.d.ts +1 -1
- package/ios/Nami.m +1 -0
- package/ios/Nami.swift +8 -0
- package/package.json +1 -1
- package/react-native-nami-sdk.podspec +1 -1
- package/specs/NativeNami.ts +1 -0
- package/src/Nami.ts +9 -0
- package/src/NamiCampaignManager.ts +5 -6
- package/src/__tests__/Nami.registerExternalImpression.test.ts +45 -0
- package/src/__tests__/transformers.test.ts +40 -1
- package/src/transformers.ts +31 -2
- package/src/types.ts +2 -0
- package/src/version.ts +1 -1
package/android/build.gradle
CHANGED
|
@@ -90,8 +90,8 @@ dependencies {
|
|
|
90
90
|
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
91
91
|
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
|
92
92
|
|
|
93
|
-
playImplementation "com.namiml:sdk-android:3.5.0-dev.
|
|
94
|
-
amazonImplementation "com.namiml:sdk-amazon:3.5.0-dev.
|
|
93
|
+
playImplementation "com.namiml:sdk-android:3.5.0-dev.202611052201"
|
|
94
|
+
amazonImplementation "com.namiml:sdk-amazon:3.5.0-dev.202611052201"
|
|
95
95
|
|
|
96
96
|
implementation "com.facebook.react:react-native:+" // From node_modules
|
|
97
97
|
coreLibraryDesugaring "com.android.tools:desugar_jdk_libs:2.0.4"
|
|
@@ -131,6 +131,18 @@ class NamiBridgeModule internal constructor(
|
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
+
@ReactMethod
|
|
135
|
+
fun registerExternalImpression(promise: Promise) {
|
|
136
|
+
context.runOnUiQueueThread {
|
|
137
|
+
try {
|
|
138
|
+
Nami.registerExternalImpression()
|
|
139
|
+
promise.resolve(null)
|
|
140
|
+
} catch (e: Throwable) {
|
|
141
|
+
promise.reject("register_external_impression_failed", e)
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
134
146
|
@ReactMethod fun addListener(eventName: String?) {}
|
|
135
147
|
|
|
136
148
|
@ReactMethod fun removeListeners(count: Int?) {}
|
package/dist/src/Nami.d.ts
CHANGED
|
@@ -5,4 +5,11 @@ export declare const Nami: {
|
|
|
5
5
|
sdkVersion: () => Promise<string>;
|
|
6
6
|
sdkPackageVersion: () => Promise<string>;
|
|
7
7
|
reset: () => Promise<void>;
|
|
8
|
+
/**
|
|
9
|
+
* Tells Nami the app showed its own interstitial, promo or paywall outside Nami journeys.
|
|
10
|
+
* It counts toward the global journey session and day caps and starts the global cooldown,
|
|
11
|
+
* never toward a journey's own caps. Ignored before `configure`, and a no-op on a native SDK
|
|
12
|
+
* older than the method.
|
|
13
|
+
*/
|
|
14
|
+
registerExternalImpression: () => Promise<void>;
|
|
8
15
|
};
|
|
@@ -8,24 +8,10 @@ export declare const NamiCampaignManager: {
|
|
|
8
8
|
emitter: NativeEventEmitter;
|
|
9
9
|
launchSubscription: ReturnType<NativeEventEmitter["addListener"]> | undefined;
|
|
10
10
|
launch(label: string | null, withUrl: string | null, context: PaywallLaunchContext | null, resultCallback?: (success: boolean, error?: NamiError | null) => void, actionCallback?: (event: any) => void): void;
|
|
11
|
-
allCampaigns: () => Promise<
|
|
12
|
-
id?: string;
|
|
13
|
-
rule?: string;
|
|
14
|
-
segment?: string;
|
|
15
|
-
paywall?: string;
|
|
16
|
-
type: string;
|
|
17
|
-
value?: string;
|
|
18
|
-
}[]>;
|
|
11
|
+
allCampaigns: () => Promise<NamiCampaign[]>;
|
|
19
12
|
isCampaignAvailable: (campaignName: string | null) => Promise<boolean>;
|
|
20
13
|
isFlow: (label?: string | null, withUrl?: string | null) => Promise<boolean>;
|
|
21
|
-
refresh: () => Promise<
|
|
22
|
-
id?: string;
|
|
23
|
-
rule?: string;
|
|
24
|
-
segment?: string;
|
|
25
|
-
paywall?: string;
|
|
26
|
-
type: string;
|
|
27
|
-
value?: string;
|
|
28
|
-
}[]>;
|
|
14
|
+
refresh: () => Promise<NamiCampaign[]>;
|
|
29
15
|
registerAvailableCampaignsHandler: (callback: (campaigns: NamiCampaign[]) => void) => (() => void);
|
|
30
16
|
getProductGroups: (label?: string | null, withUrl?: string | null) => Promise<string[]>;
|
|
31
17
|
};
|
|
@@ -1,6 +1,13 @@
|
|
|
1
|
-
import type { NamiEntitlement, NamiPurchase, NamiSKUType } from './types';
|
|
2
|
-
import { NamiPaywallAction } from './types';
|
|
1
|
+
import type { NamiCampaign, NamiEntitlement, NamiPurchase, NamiSKUType } from './types';
|
|
2
|
+
import { NamiCampaignRuleType, NamiPaywallAction } from './types';
|
|
3
3
|
export declare function parsePurchaseDates(purchase: any): NamiPurchase;
|
|
4
4
|
export declare function coerceSkuType(raw: string): NamiSKUType;
|
|
5
|
+
/**
|
|
6
|
+
* Narrows a native rule type to the enum. Android lowercases enum names and iOS passes the raw
|
|
7
|
+
* string; anything this SDK doesn't know (or a missing value) reads as `UNKNOWN`.
|
|
8
|
+
*/
|
|
9
|
+
export declare function coerceCampaignRuleType(raw: unknown): NamiCampaignRuleType;
|
|
10
|
+
/** Native campaigns with `type` narrowed by {@link coerceCampaignRuleType}. */
|
|
11
|
+
export declare function parseCampaigns(campaigns: unknown): NamiCampaign[];
|
|
5
12
|
export declare function mapToNamiPaywallAction(action: string): NamiPaywallAction;
|
|
6
13
|
export declare function parseEntitlements(entitlements: any[]): NamiEntitlement[];
|
package/dist/src/types.d.ts
CHANGED
|
@@ -66,6 +66,8 @@ export type NamiCampaign = {
|
|
|
66
66
|
};
|
|
67
67
|
export declare enum NamiCampaignRuleType {
|
|
68
68
|
DEFAULT = "default",
|
|
69
|
+
/** A journey rule, delivered by the native SDK on its trigger; never launched by a placement. */
|
|
70
|
+
JOURNEY = "journey",
|
|
69
71
|
LABEL = "label",
|
|
70
72
|
UNKNOWN = "unknown",
|
|
71
73
|
URL = "url"
|
package/dist/src/version.d.ts
CHANGED
package/ios/Nami.m
CHANGED
|
@@ -18,6 +18,7 @@ RCT_EXTERN_METHOD(sdkConfigured:(RCTPromiseResolveBlock)resolve
|
|
|
18
18
|
RCT_EXTERN_METHOD(sdkVersion:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
|
|
19
19
|
|
|
20
20
|
RCT_EXTERN_METHOD(reset:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
|
|
21
|
+
RCT_EXTERN_METHOD(registerExternalImpression:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
|
|
21
22
|
|
|
22
23
|
+ (BOOL)requiresMainQueueSetup {
|
|
23
24
|
return NO;
|
package/ios/Nami.swift
CHANGED
|
@@ -103,6 +103,14 @@ class RNNami: NSObject {
|
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
+
@objc(registerExternalImpression:rejecter:)
|
|
107
|
+
func registerExternalImpression(resolve: @escaping RCTPromiseResolveBlock, reject _: @escaping RCTPromiseRejectBlock) {
|
|
108
|
+
Nami.registerExternalImpression()
|
|
109
|
+
DispatchQueue.main.async {
|
|
110
|
+
resolve(nil)
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
106
114
|
func isNewArchitectureEnabled() -> Bool {
|
|
107
115
|
#if RCT_NEW_ARCH_ENABLED
|
|
108
116
|
return true
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-nami-sdk",
|
|
3
|
-
"version": "3.5.0-dev.
|
|
3
|
+
"version": "3.5.0-dev.202611052201",
|
|
4
4
|
"description": "React Native SDK for Nami - No-code paywall and onboarding flows with A/B testing.",
|
|
5
5
|
"main": "index.ts",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -21,7 +21,7 @@ Pod::Spec.new do |s|
|
|
|
21
21
|
s.requires_arc = true
|
|
22
22
|
s.swift_version = '5.0' # or your supported version
|
|
23
23
|
|
|
24
|
-
s.dependency 'Nami', '3.5.0-dev.
|
|
24
|
+
s.dependency 'Nami', '3.5.0-dev.202611052201'
|
|
25
25
|
|
|
26
26
|
pod_target_xcconfig = {
|
|
27
27
|
'DEFINES_MODULE' => 'YES',
|
package/specs/NativeNami.ts
CHANGED
|
@@ -14,6 +14,7 @@ export interface Spec extends TurboModule {
|
|
|
14
14
|
sdkConfigured(): Promise<boolean>;
|
|
15
15
|
sdkVersion(): Promise<string>;
|
|
16
16
|
reset(): Promise<void>;
|
|
17
|
+
registerExternalImpression(): Promise<void>;
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
export default TurboModuleRegistry.getEnforcing<Spec>('RNNami');
|
package/src/Nami.ts
CHANGED
|
@@ -40,4 +40,13 @@ export const Nami = {
|
|
|
40
40
|
reset: async (): Promise<void> => {
|
|
41
41
|
return RNNami.reset();
|
|
42
42
|
},
|
|
43
|
+
/**
|
|
44
|
+
* Tells Nami the app showed its own interstitial, promo or paywall outside Nami journeys.
|
|
45
|
+
* It counts toward the global journey session and day caps and starts the global cooldown,
|
|
46
|
+
* never toward a journey's own caps. Ignored before `configure`, and a no-op on a native SDK
|
|
47
|
+
* older than the method.
|
|
48
|
+
*/
|
|
49
|
+
registerExternalImpression: async (): Promise<void> => {
|
|
50
|
+
await RNNami.registerExternalImpression?.();
|
|
51
|
+
},
|
|
43
52
|
};
|
|
@@ -10,7 +10,7 @@ import type {
|
|
|
10
10
|
NamiCampaign,
|
|
11
11
|
NamiError,
|
|
12
12
|
} from './types';
|
|
13
|
-
import { mapToNamiPaywallAction } from './transformers';
|
|
13
|
+
import { mapToNamiPaywallAction, parseCampaigns } from './transformers';
|
|
14
14
|
|
|
15
15
|
const RNNamiCampaignManager: Spec =
|
|
16
16
|
TurboModuleRegistry.getEnforcing<Spec>('RNNamiCampaignManager') ??
|
|
@@ -27,8 +27,7 @@ export const NamiCampaignManager = {
|
|
|
27
27
|
emitter,
|
|
28
28
|
|
|
29
29
|
launchSubscription: undefined as
|
|
30
|
-
|
|
31
|
-
| undefined,
|
|
30
|
+
ReturnType<NativeEventEmitter['addListener']> | undefined,
|
|
32
31
|
|
|
33
32
|
launch(
|
|
34
33
|
label: string | null,
|
|
@@ -79,7 +78,7 @@ export const NamiCampaignManager = {
|
|
|
79
78
|
},
|
|
80
79
|
|
|
81
80
|
allCampaigns: async () => {
|
|
82
|
-
return await RNNamiCampaignManager.allCampaigns();
|
|
81
|
+
return parseCampaigns(await RNNamiCampaignManager.allCampaigns());
|
|
83
82
|
},
|
|
84
83
|
|
|
85
84
|
isCampaignAvailable: async (campaignName: string | null) => {
|
|
@@ -93,7 +92,7 @@ export const NamiCampaignManager = {
|
|
|
93
92
|
},
|
|
94
93
|
|
|
95
94
|
refresh: async () => {
|
|
96
|
-
return await RNNamiCampaignManager.refresh();
|
|
95
|
+
return parseCampaigns(await RNNamiCampaignManager.refresh());
|
|
97
96
|
},
|
|
98
97
|
|
|
99
98
|
registerAvailableCampaignsHandler: (
|
|
@@ -101,7 +100,7 @@ export const NamiCampaignManager = {
|
|
|
101
100
|
): (() => void) => {
|
|
102
101
|
const sub = emitter.addListener(
|
|
103
102
|
NamiCampaignManagerEvents.AvailableCampaignsChanged,
|
|
104
|
-
callback,
|
|
103
|
+
(campaigns: unknown) => callback(parseCampaigns(campaigns)),
|
|
105
104
|
);
|
|
106
105
|
RNNamiCampaignManager.registerAvailableCampaignsHandler?.();
|
|
107
106
|
return () => sub.remove();
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// Mock react-native BEFORE importing the SDK — `../Nami` resolves
|
|
2
|
+
// the native module via TurboModuleRegistry at import time.
|
|
3
|
+
const native: Record<string, jest.Mock | undefined> = {
|
|
4
|
+
registerExternalImpression: jest.fn().mockResolvedValue(undefined),
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
jest.mock('react-native', () => ({
|
|
8
|
+
TurboModuleRegistry: { getEnforcing: jest.fn(() => native) },
|
|
9
|
+
NativeModules: { RNNami: native },
|
|
10
|
+
}));
|
|
11
|
+
|
|
12
|
+
import { Nami } from '../Nami';
|
|
13
|
+
|
|
14
|
+
// NAM-3241: journeys' external-impression API, bridged to the native SDKs.
|
|
15
|
+
describe('Nami.registerExternalImpression (React Native bridge)', () => {
|
|
16
|
+
const registerExternalImpression = native.registerExternalImpression!;
|
|
17
|
+
|
|
18
|
+
beforeEach(() => {
|
|
19
|
+
registerExternalImpression.mockClear();
|
|
20
|
+
native.registerExternalImpression = registerExternalImpression;
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('delegates to the native method once', async () => {
|
|
24
|
+
await Nami.registerExternalImpression();
|
|
25
|
+
expect(registerExternalImpression).toHaveBeenCalledTimes(1);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('resolves to undefined', async () => {
|
|
29
|
+
await expect(Nami.registerExternalImpression()).resolves.toBeUndefined();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('is a no-op on a native SDK without the method', async () => {
|
|
33
|
+
native.registerExternalImpression = undefined;
|
|
34
|
+
await expect(Nami.registerExternalImpression()).resolves.toBeUndefined();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('propagates a native rejection', async () => {
|
|
38
|
+
registerExternalImpression.mockRejectedValueOnce(
|
|
39
|
+
new Error('native failed'),
|
|
40
|
+
);
|
|
41
|
+
await expect(Nami.registerExternalImpression()).rejects.toThrow(
|
|
42
|
+
'native failed',
|
|
43
|
+
);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
@@ -3,8 +3,10 @@ import {
|
|
|
3
3
|
coerceSkuType,
|
|
4
4
|
mapToNamiPaywallAction,
|
|
5
5
|
parseEntitlements,
|
|
6
|
+
coerceCampaignRuleType,
|
|
7
|
+
parseCampaigns,
|
|
6
8
|
} from '../transformers';
|
|
7
|
-
import { NamiPaywallAction } from '../types';
|
|
9
|
+
import { NamiCampaignRuleType, NamiPaywallAction } from '../types';
|
|
8
10
|
|
|
9
11
|
describe('parsePurchaseDates', () => {
|
|
10
12
|
it('converts timestamp numbers to Date objects', () => {
|
|
@@ -196,3 +198,40 @@ describe('parseEntitlements', () => {
|
|
|
196
198
|
expect(result[1].activePurchases).toHaveLength(2);
|
|
197
199
|
});
|
|
198
200
|
});
|
|
201
|
+
|
|
202
|
+
// NAM-3241: journey rules arrive from both bridges; Android lowercases enum names.
|
|
203
|
+
describe('coerceCampaignRuleType', () => {
|
|
204
|
+
it.each([
|
|
205
|
+
['journey', NamiCampaignRuleType.JOURNEY],
|
|
206
|
+
['JOURNEY', NamiCampaignRuleType.JOURNEY],
|
|
207
|
+
['label', NamiCampaignRuleType.LABEL],
|
|
208
|
+
['url', NamiCampaignRuleType.URL],
|
|
209
|
+
['default', NamiCampaignRuleType.DEFAULT],
|
|
210
|
+
])('maps %s to its enum value', (raw, expected) => {
|
|
211
|
+
expect(coerceCampaignRuleType(raw)).toBe(expected);
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it.each([['segment'], [''], [null], [undefined], [3]])(
|
|
215
|
+
'reads %p as UNKNOWN',
|
|
216
|
+
(raw) => {
|
|
217
|
+
expect(coerceCampaignRuleType(raw)).toBe(NamiCampaignRuleType.UNKNOWN);
|
|
218
|
+
},
|
|
219
|
+
);
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
describe('parseCampaigns', () => {
|
|
223
|
+
it('narrows each type and keeps the other fields', () => {
|
|
224
|
+
const parsed = parseCampaigns([
|
|
225
|
+
{ rule: 'r1', type: 'journey', value: null },
|
|
226
|
+
{ rule: 'r2', type: 'brand_new', value: 'home' },
|
|
227
|
+
]);
|
|
228
|
+
expect(parsed).toEqual([
|
|
229
|
+
{ rule: 'r1', type: NamiCampaignRuleType.JOURNEY, value: null },
|
|
230
|
+
{ rule: 'r2', type: NamiCampaignRuleType.UNKNOWN, value: 'home' },
|
|
231
|
+
]);
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it('reads a non-array as no campaigns', () => {
|
|
235
|
+
expect(parseCampaigns(null)).toEqual([]);
|
|
236
|
+
});
|
|
237
|
+
});
|
package/src/transformers.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type {
|
|
2
|
+
NamiCampaign,
|
|
3
|
+
NamiEntitlement,
|
|
4
|
+
NamiPurchase,
|
|
5
|
+
NamiSKUType,
|
|
6
|
+
} from './types';
|
|
7
|
+
import { NamiCampaignRuleType, NamiPaywallAction } from './types';
|
|
3
8
|
|
|
4
9
|
export function parsePurchaseDates(purchase: any): NamiPurchase {
|
|
5
10
|
return {
|
|
@@ -21,6 +26,30 @@ export function coerceSkuType(raw: string): NamiSKUType {
|
|
|
21
26
|
: 'unknown';
|
|
22
27
|
}
|
|
23
28
|
|
|
29
|
+
const validCampaignRuleTypes = new Set<string>(
|
|
30
|
+
Object.values(NamiCampaignRuleType),
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Narrows a native rule type to the enum. Android lowercases enum names and iOS passes the raw
|
|
35
|
+
* string; anything this SDK doesn't know (or a missing value) reads as `UNKNOWN`.
|
|
36
|
+
*/
|
|
37
|
+
export function coerceCampaignRuleType(raw: unknown): NamiCampaignRuleType {
|
|
38
|
+
const value = typeof raw === 'string' ? raw.toLowerCase() : '';
|
|
39
|
+
return validCampaignRuleTypes.has(value)
|
|
40
|
+
? (value as NamiCampaignRuleType)
|
|
41
|
+
: NamiCampaignRuleType.UNKNOWN;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Native campaigns with `type` narrowed by {@link coerceCampaignRuleType}. */
|
|
45
|
+
export function parseCampaigns(campaigns: unknown): NamiCampaign[] {
|
|
46
|
+
if (!Array.isArray(campaigns)) return [];
|
|
47
|
+
return campaigns.map((campaign) => ({
|
|
48
|
+
...campaign,
|
|
49
|
+
type: coerceCampaignRuleType(campaign?.type),
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
|
|
24
53
|
const validPaywallActions = new Set(
|
|
25
54
|
Object.values(NamiPaywallAction) as NamiPaywallAction[],
|
|
26
55
|
);
|
package/src/types.ts
CHANGED
|
@@ -172,6 +172,8 @@ export type NamiCampaign = {
|
|
|
172
172
|
|
|
173
173
|
export enum NamiCampaignRuleType {
|
|
174
174
|
DEFAULT = 'default',
|
|
175
|
+
/** A journey rule, delivered by the native SDK on its trigger; never launched by a placement. */
|
|
176
|
+
JOURNEY = 'journey',
|
|
175
177
|
LABEL = 'label',
|
|
176
178
|
UNKNOWN = 'unknown',
|
|
177
179
|
URL = 'url',
|
package/src/version.ts
CHANGED