@encorekit/capacitor 0.1.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/EncorekitCapacitor.podspec +23 -0
- package/README.md +97 -0
- package/android/build.gradle +85 -0
- package/android/gradle.properties +1 -0
- package/android/settings.gradle +1 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/java/com/encorekit/capacitor/EncoreCapacitorPlugin.kt +225 -0
- package/dist/esm/definitions.d.ts +126 -0
- package/dist/esm/definitions.d.ts.map +1 -0
- package/dist/esm/definitions.js +4 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +7 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +55 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web.d.ts +27 -0
- package/dist/esm/web.d.ts.map +1 -0
- package/dist/esm/web.js +38 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +103 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +106 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Sources/EncoreCapacitorPlugin/EncoreCapacitorPlugin.swift +217 -0
- package/ios/Sources/EncoreCapacitorPluginObjC/EncoreCapacitorPlugin.m +17 -0
- package/package.json +95 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
import type { EncorePlugin, PlacementResult } from './definitions';
|
|
3
|
+
export declare class EncorePluginWeb extends WebPlugin implements EncorePlugin {
|
|
4
|
+
configure(): Promise<{
|
|
5
|
+
success: boolean;
|
|
6
|
+
}>;
|
|
7
|
+
identify(): Promise<{
|
|
8
|
+
success: boolean;
|
|
9
|
+
}>;
|
|
10
|
+
setUserAttributes(): Promise<{
|
|
11
|
+
success: boolean;
|
|
12
|
+
}>;
|
|
13
|
+
reset(): Promise<{
|
|
14
|
+
success: boolean;
|
|
15
|
+
}>;
|
|
16
|
+
show(): Promise<PlacementResult>;
|
|
17
|
+
setClaimEnabled(): Promise<{
|
|
18
|
+
success: boolean;
|
|
19
|
+
}>;
|
|
20
|
+
registerCallbacks(): Promise<{
|
|
21
|
+
success: boolean;
|
|
22
|
+
}>;
|
|
23
|
+
completePurchaseRequest(): Promise<{
|
|
24
|
+
success: boolean;
|
|
25
|
+
}>;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=web.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web.d.ts","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,KAAK,EACV,YAAY,EACZ,eAAe,EAChB,MAAM,eAAe,CAAC;AAEvB,qBAAa,eAAgB,SAAQ,SAAU,YAAW,YAAY;IAC9D,SAAS,IAAI,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC;IAK1C,QAAQ,IAAI,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC;IAKzC,iBAAiB,IAAI,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC;IAKlD,KAAK,IAAI,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC;IAKtC,IAAI,IAAI,OAAO,CAAC,eAAe,CAAC;IAKhC,eAAe,IAAI,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC;IAKhD,iBAAiB,IAAI,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC;IAKlD,uBAAuB,IAAI,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC;CAI/D"}
|
package/dist/esm/web.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// Web fallback — noop stubs with console warnings.
|
|
2
|
+
// Real web SDK is a separate product (web-sdk/).
|
|
3
|
+
import { WebPlugin } from '@capacitor/core';
|
|
4
|
+
export class EncorePluginWeb extends WebPlugin {
|
|
5
|
+
async configure() {
|
|
6
|
+
console.warn('[Encore] Capacitor plugin is not supported on web.');
|
|
7
|
+
return { success: false };
|
|
8
|
+
}
|
|
9
|
+
async identify() {
|
|
10
|
+
console.warn('[Encore] identify is not supported on web.');
|
|
11
|
+
return { success: false };
|
|
12
|
+
}
|
|
13
|
+
async setUserAttributes() {
|
|
14
|
+
console.warn('[Encore] setUserAttributes is not supported on web.');
|
|
15
|
+
return { success: false };
|
|
16
|
+
}
|
|
17
|
+
async reset() {
|
|
18
|
+
console.warn('[Encore] reset is not supported on web.');
|
|
19
|
+
return { success: false };
|
|
20
|
+
}
|
|
21
|
+
async show() {
|
|
22
|
+
console.warn('[Encore] show is not supported on web.');
|
|
23
|
+
return { status: 'not_granted', reason: 'web_unsupported' };
|
|
24
|
+
}
|
|
25
|
+
async setClaimEnabled() {
|
|
26
|
+
console.warn('[Encore] setClaimEnabled is not supported on web.');
|
|
27
|
+
return { success: false };
|
|
28
|
+
}
|
|
29
|
+
async registerCallbacks() {
|
|
30
|
+
console.warn('[Encore] registerCallbacks is not supported on web.');
|
|
31
|
+
return { success: false };
|
|
32
|
+
}
|
|
33
|
+
async completePurchaseRequest() {
|
|
34
|
+
console.warn('[Encore] completePurchaseRequest is not supported on web.');
|
|
35
|
+
return { success: false };
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=web.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,mDAAmD;AACnD,iDAAiD;AAEjD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAO5C,MAAM,OAAO,eAAgB,SAAQ,SAAS;IAC5C,KAAK,CAAC,SAAS;QACb,OAAO,CAAC,IAAI,CAAC,oDAAoD,CAAC,CAAC;QACnE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC5B,CAAC;IAED,KAAK,CAAC,QAAQ;QACZ,OAAO,CAAC,IAAI,CAAC,4CAA4C,CAAC,CAAC;QAC3D,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC5B,CAAC;IAED,KAAK,CAAC,iBAAiB;QACrB,OAAO,CAAC,IAAI,CAAC,qDAAqD,CAAC,CAAC;QACpE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC5B,CAAC;IAED,KAAK,CAAC,KAAK;QACT,OAAO,CAAC,IAAI,CAAC,yCAAyC,CAAC,CAAC;QACxD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC5B,CAAC;IAED,KAAK,CAAC,IAAI;QACR,OAAO,CAAC,IAAI,CAAC,wCAAwC,CAAC,CAAC;QACvD,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,iBAAiB,EAAE,CAAC;IAC9D,CAAC;IAED,KAAK,CAAC,eAAe;QACnB,OAAO,CAAC,IAAI,CAAC,mDAAmD,CAAC,CAAC;QAClE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC5B,CAAC;IAED,KAAK,CAAC,iBAAiB;QACrB,OAAO,CAAC,IAAI,CAAC,qDAAqD,CAAC,CAAC;QACpE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC5B,CAAC;IAED,KAAK,CAAC,uBAAuB;QAC3B,OAAO,CAAC,IAAI,CAAC,2DAA2D,CAAC,CAAC;QAC1E,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC5B,CAAC;CACF"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var core = require('@capacitor/core');
|
|
6
|
+
|
|
7
|
+
// Encore Capacitor SDK
|
|
8
|
+
// Bridge-only layer — delegates to native SDKs on each platform.
|
|
9
|
+
// iOS: encore-swift-sdk | Android: encore-android-sdk
|
|
10
|
+
const EncoreCapacitorPlugin = core.registerPlugin('EncoreCapacitorPlugin', {
|
|
11
|
+
web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.EncorePluginWeb()),
|
|
12
|
+
});
|
|
13
|
+
async function safeBridgeCall(method, call, fallback) {
|
|
14
|
+
try {
|
|
15
|
+
return await call();
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
console.warn(`[Encore] ${method} failed:`, error);
|
|
19
|
+
return fallback;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
// -- Typed Export --
|
|
23
|
+
const Encore = {
|
|
24
|
+
configure: (apiKey, options = {}) => safeBridgeCall('configure', () => EncoreCapacitorPlugin.configure({ apiKey, logLevel: options.logLevel }), { success: false }),
|
|
25
|
+
identify: (userId, attributes) => safeBridgeCall('identify', () => EncoreCapacitorPlugin.identify({ userId, attributes }), { success: false }),
|
|
26
|
+
setUserAttributes: (attributes) => safeBridgeCall('setUserAttributes', () => EncoreCapacitorPlugin.setUserAttributes({ attributes }), { success: false }),
|
|
27
|
+
reset: () => safeBridgeCall('reset', () => EncoreCapacitorPlugin.reset(), {
|
|
28
|
+
success: false,
|
|
29
|
+
}),
|
|
30
|
+
placement: (placementId) => ({
|
|
31
|
+
show: () => safeBridgeCall('show', () => EncoreCapacitorPlugin.show({ placementId }), { status: 'not_granted', reason: 'sdk_error' }),
|
|
32
|
+
}),
|
|
33
|
+
show: (placementId) => safeBridgeCall('show', () => EncoreCapacitorPlugin.show({ placementId }), { status: 'not_granted', reason: 'sdk_error' }),
|
|
34
|
+
placements: {
|
|
35
|
+
setClaimEnabled: (enabled) => safeBridgeCall('setClaimEnabled', () => EncoreCapacitorPlugin.setClaimEnabled({ enabled }), { success: false }),
|
|
36
|
+
},
|
|
37
|
+
registerCallbacks: () => safeBridgeCall('registerCallbacks', () => EncoreCapacitorPlugin.registerCallbacks(), { success: false }),
|
|
38
|
+
completePurchaseRequest: (success) => safeBridgeCall('completePurchaseRequest', () => EncoreCapacitorPlugin.completePurchaseRequest({ success }), { success: false }),
|
|
39
|
+
onPurchaseRequest: (handler) => {
|
|
40
|
+
const handle = EncoreCapacitorPlugin.addListener('onPurchaseRequest', handler);
|
|
41
|
+
return () => {
|
|
42
|
+
handle.then((h) => h.remove());
|
|
43
|
+
};
|
|
44
|
+
},
|
|
45
|
+
onPurchaseComplete: (handler) => {
|
|
46
|
+
const handle = EncoreCapacitorPlugin.addListener('onPurchaseComplete', handler);
|
|
47
|
+
return () => {
|
|
48
|
+
handle.then((h) => h.remove());
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
onPassthrough: (handler) => {
|
|
52
|
+
const handle = EncoreCapacitorPlugin.addListener('onPassthrough', handler);
|
|
53
|
+
return () => {
|
|
54
|
+
handle.then((h) => h.remove());
|
|
55
|
+
};
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// Web fallback — noop stubs with console warnings.
|
|
60
|
+
// Real web SDK is a separate product (web-sdk/).
|
|
61
|
+
class EncorePluginWeb extends core.WebPlugin {
|
|
62
|
+
async configure() {
|
|
63
|
+
console.warn('[Encore] Capacitor plugin is not supported on web.');
|
|
64
|
+
return { success: false };
|
|
65
|
+
}
|
|
66
|
+
async identify() {
|
|
67
|
+
console.warn('[Encore] identify is not supported on web.');
|
|
68
|
+
return { success: false };
|
|
69
|
+
}
|
|
70
|
+
async setUserAttributes() {
|
|
71
|
+
console.warn('[Encore] setUserAttributes is not supported on web.');
|
|
72
|
+
return { success: false };
|
|
73
|
+
}
|
|
74
|
+
async reset() {
|
|
75
|
+
console.warn('[Encore] reset is not supported on web.');
|
|
76
|
+
return { success: false };
|
|
77
|
+
}
|
|
78
|
+
async show() {
|
|
79
|
+
console.warn('[Encore] show is not supported on web.');
|
|
80
|
+
return { status: 'not_granted', reason: 'web_unsupported' };
|
|
81
|
+
}
|
|
82
|
+
async setClaimEnabled() {
|
|
83
|
+
console.warn('[Encore] setClaimEnabled is not supported on web.');
|
|
84
|
+
return { success: false };
|
|
85
|
+
}
|
|
86
|
+
async registerCallbacks() {
|
|
87
|
+
console.warn('[Encore] registerCallbacks is not supported on web.');
|
|
88
|
+
return { success: false };
|
|
89
|
+
}
|
|
90
|
+
async completePurchaseRequest() {
|
|
91
|
+
console.warn('[Encore] completePurchaseRequest is not supported on web.');
|
|
92
|
+
return { success: false };
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
var web = /*#__PURE__*/Object.freeze({
|
|
97
|
+
__proto__: null,
|
|
98
|
+
EncorePluginWeb: EncorePluginWeb
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
exports.EncoreCapacitorPlugin = EncoreCapacitorPlugin;
|
|
102
|
+
exports.default = Encore;
|
|
103
|
+
//# sourceMappingURL=plugin.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["// Encore Capacitor SDK\n// Bridge-only layer — delegates to native SDKs on each platform.\n// iOS: encore-swift-sdk | Android: encore-android-sdk\nimport { registerPlugin } from '@capacitor/core';\nconst EncoreCapacitorPlugin = registerPlugin('EncoreCapacitorPlugin', {\n web: () => import('./web').then((m) => new m.EncorePluginWeb()),\n});\nasync function safeBridgeCall(method, call, fallback) {\n try {\n return await call();\n }\n catch (error) {\n console.warn(`[Encore] ${method} failed:`, error);\n return fallback;\n }\n}\n// -- Typed Export --\nconst Encore = {\n configure: (apiKey, options = {}) => safeBridgeCall('configure', () => EncoreCapacitorPlugin.configure({ apiKey, logLevel: options.logLevel }), { success: false }),\n identify: (userId, attributes) => safeBridgeCall('identify', () => EncoreCapacitorPlugin.identify({ userId, attributes }), { success: false }),\n setUserAttributes: (attributes) => safeBridgeCall('setUserAttributes', () => EncoreCapacitorPlugin.setUserAttributes({ attributes }), { success: false }),\n reset: () => safeBridgeCall('reset', () => EncoreCapacitorPlugin.reset(), {\n success: false,\n }),\n placement: (placementId) => ({\n show: () => safeBridgeCall('show', () => EncoreCapacitorPlugin.show({ placementId }), { status: 'not_granted', reason: 'sdk_error' }),\n }),\n show: (placementId) => safeBridgeCall('show', () => EncoreCapacitorPlugin.show({ placementId }), { status: 'not_granted', reason: 'sdk_error' }),\n placements: {\n setClaimEnabled: (enabled) => safeBridgeCall('setClaimEnabled', () => EncoreCapacitorPlugin.setClaimEnabled({ enabled }), { success: false }),\n },\n registerCallbacks: () => safeBridgeCall('registerCallbacks', () => EncoreCapacitorPlugin.registerCallbacks(), { success: false }),\n completePurchaseRequest: (success) => safeBridgeCall('completePurchaseRequest', () => EncoreCapacitorPlugin.completePurchaseRequest({ success }), { success: false }),\n onPurchaseRequest: (handler) => {\n const handle = EncoreCapacitorPlugin.addListener('onPurchaseRequest', handler);\n return () => {\n handle.then((h) => h.remove());\n };\n },\n onPurchaseComplete: (handler) => {\n const handle = EncoreCapacitorPlugin.addListener('onPurchaseComplete', handler);\n return () => {\n handle.then((h) => h.remove());\n };\n },\n onPassthrough: (handler) => {\n const handle = EncoreCapacitorPlugin.addListener('onPassthrough', handler);\n return () => {\n handle.then((h) => h.remove());\n };\n },\n};\nexport default Encore;\nexport { EncoreCapacitorPlugin };\n//# sourceMappingURL=index.js.map","// Web fallback — noop stubs with console warnings.\n// Real web SDK is a separate product (web-sdk/).\nimport { WebPlugin } from '@capacitor/core';\nexport class EncorePluginWeb extends WebPlugin {\n async configure() {\n console.warn('[Encore] Capacitor plugin is not supported on web.');\n return { success: false };\n }\n async identify() {\n console.warn('[Encore] identify is not supported on web.');\n return { success: false };\n }\n async setUserAttributes() {\n console.warn('[Encore] setUserAttributes is not supported on web.');\n return { success: false };\n }\n async reset() {\n console.warn('[Encore] reset is not supported on web.');\n return { success: false };\n }\n async show() {\n console.warn('[Encore] show is not supported on web.');\n return { status: 'not_granted', reason: 'web_unsupported' };\n }\n async setClaimEnabled() {\n console.warn('[Encore] setClaimEnabled is not supported on web.');\n return { success: false };\n }\n async registerCallbacks() {\n console.warn('[Encore] registerCallbacks is not supported on web.');\n return { success: false };\n }\n async completePurchaseRequest() {\n console.warn('[Encore] completePurchaseRequest is not supported on web.');\n return { success: false };\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;;;AAAA;AACA;AACA;AAEK,MAAC,qBAAqB,GAAGA,mBAAc,CAAC,uBAAuB,EAAE;AACtE,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,eAAe,EAAE,CAAC;AACnE,CAAC;AACD,eAAe,cAAc,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE;AACtD,IAAI,IAAI;AACR,QAAQ,OAAO,MAAM,IAAI,EAAE;AAC3B,IAAI;AACJ,IAAI,OAAO,KAAK,EAAE;AAClB,QAAQ,OAAO,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,MAAM,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC;AACzD,QAAQ,OAAO,QAAQ;AACvB,IAAI;AACJ;AACA;AACK,MAAC,MAAM,GAAG;AACf,IAAI,SAAS,EAAE,CAAC,MAAM,EAAE,OAAO,GAAG,EAAE,KAAK,cAAc,CAAC,WAAW,EAAE,MAAM,qBAAqB,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;AACvK,IAAI,QAAQ,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,cAAc,CAAC,UAAU,EAAE,MAAM,qBAAqB,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;AAClJ,IAAI,iBAAiB,EAAE,CAAC,UAAU,KAAK,cA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,QAAQ,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE;AACjC,IAAI;AACJ,IAAI,MAAM,KAAK,GAAG;AAClB,QAAQ,OAAO,CAAC,IAAI,CAAC,yCAAyC,CAAC;AAC/D,QAAQ,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE;AACjC,IAAI;AACJ,IAAI,MAAM,IAAI,GAAG;AACjB,QAAQ,OAAO,CAAC,IAAI,CAAC,wCAAwC,CAAC;AAC9D,QAAQ,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,iBAAiB,EAAE;AACnE,IAAI;AACJ,IAAI,MAAM,eAAe,GAAG;AAC5B,QAAQ,OAAO,CAAC,IAAI,CAAC,mDAAmD,CAAC;AACzE,QAAQ,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE;AACjC,IAAI;AACJ,IAAI,MAAM,iBAAiB,GAAG;AAC9B,QAAQ,OAAO,CAAC,IAAI,CAAC,qDAAqD,CAAC;AAC3E,QAAQ,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE;AACjC,IAAI;AACJ,IAAI,MAAM,uBAAuB,GAAG;AACpC,QAAQ,OAAO,CAAC,IAAI,CAAC,2DAA2D,CAAC;AACjF,QAAQ,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE;AACjC,IAAI;AACJ;;;;;;;;;;"}
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
var capacitorEncorePlugin = (function (exports, core) {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
// Encore Capacitor SDK
|
|
5
|
+
// Bridge-only layer — delegates to native SDKs on each platform.
|
|
6
|
+
// iOS: encore-swift-sdk | Android: encore-android-sdk
|
|
7
|
+
const EncoreCapacitorPlugin = core.registerPlugin('EncoreCapacitorPlugin', {
|
|
8
|
+
web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.EncorePluginWeb()),
|
|
9
|
+
});
|
|
10
|
+
async function safeBridgeCall(method, call, fallback) {
|
|
11
|
+
try {
|
|
12
|
+
return await call();
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
console.warn(`[Encore] ${method} failed:`, error);
|
|
16
|
+
return fallback;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
// -- Typed Export --
|
|
20
|
+
const Encore = {
|
|
21
|
+
configure: (apiKey, options = {}) => safeBridgeCall('configure', () => EncoreCapacitorPlugin.configure({ apiKey, logLevel: options.logLevel }), { success: false }),
|
|
22
|
+
identify: (userId, attributes) => safeBridgeCall('identify', () => EncoreCapacitorPlugin.identify({ userId, attributes }), { success: false }),
|
|
23
|
+
setUserAttributes: (attributes) => safeBridgeCall('setUserAttributes', () => EncoreCapacitorPlugin.setUserAttributes({ attributes }), { success: false }),
|
|
24
|
+
reset: () => safeBridgeCall('reset', () => EncoreCapacitorPlugin.reset(), {
|
|
25
|
+
success: false,
|
|
26
|
+
}),
|
|
27
|
+
placement: (placementId) => ({
|
|
28
|
+
show: () => safeBridgeCall('show', () => EncoreCapacitorPlugin.show({ placementId }), { status: 'not_granted', reason: 'sdk_error' }),
|
|
29
|
+
}),
|
|
30
|
+
show: (placementId) => safeBridgeCall('show', () => EncoreCapacitorPlugin.show({ placementId }), { status: 'not_granted', reason: 'sdk_error' }),
|
|
31
|
+
placements: {
|
|
32
|
+
setClaimEnabled: (enabled) => safeBridgeCall('setClaimEnabled', () => EncoreCapacitorPlugin.setClaimEnabled({ enabled }), { success: false }),
|
|
33
|
+
},
|
|
34
|
+
registerCallbacks: () => safeBridgeCall('registerCallbacks', () => EncoreCapacitorPlugin.registerCallbacks(), { success: false }),
|
|
35
|
+
completePurchaseRequest: (success) => safeBridgeCall('completePurchaseRequest', () => EncoreCapacitorPlugin.completePurchaseRequest({ success }), { success: false }),
|
|
36
|
+
onPurchaseRequest: (handler) => {
|
|
37
|
+
const handle = EncoreCapacitorPlugin.addListener('onPurchaseRequest', handler);
|
|
38
|
+
return () => {
|
|
39
|
+
handle.then((h) => h.remove());
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
onPurchaseComplete: (handler) => {
|
|
43
|
+
const handle = EncoreCapacitorPlugin.addListener('onPurchaseComplete', handler);
|
|
44
|
+
return () => {
|
|
45
|
+
handle.then((h) => h.remove());
|
|
46
|
+
};
|
|
47
|
+
},
|
|
48
|
+
onPassthrough: (handler) => {
|
|
49
|
+
const handle = EncoreCapacitorPlugin.addListener('onPassthrough', handler);
|
|
50
|
+
return () => {
|
|
51
|
+
handle.then((h) => h.remove());
|
|
52
|
+
};
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
// Web fallback — noop stubs with console warnings.
|
|
57
|
+
// Real web SDK is a separate product (web-sdk/).
|
|
58
|
+
class EncorePluginWeb extends core.WebPlugin {
|
|
59
|
+
async configure() {
|
|
60
|
+
console.warn('[Encore] Capacitor plugin is not supported on web.');
|
|
61
|
+
return { success: false };
|
|
62
|
+
}
|
|
63
|
+
async identify() {
|
|
64
|
+
console.warn('[Encore] identify is not supported on web.');
|
|
65
|
+
return { success: false };
|
|
66
|
+
}
|
|
67
|
+
async setUserAttributes() {
|
|
68
|
+
console.warn('[Encore] setUserAttributes is not supported on web.');
|
|
69
|
+
return { success: false };
|
|
70
|
+
}
|
|
71
|
+
async reset() {
|
|
72
|
+
console.warn('[Encore] reset is not supported on web.');
|
|
73
|
+
return { success: false };
|
|
74
|
+
}
|
|
75
|
+
async show() {
|
|
76
|
+
console.warn('[Encore] show is not supported on web.');
|
|
77
|
+
return { status: 'not_granted', reason: 'web_unsupported' };
|
|
78
|
+
}
|
|
79
|
+
async setClaimEnabled() {
|
|
80
|
+
console.warn('[Encore] setClaimEnabled is not supported on web.');
|
|
81
|
+
return { success: false };
|
|
82
|
+
}
|
|
83
|
+
async registerCallbacks() {
|
|
84
|
+
console.warn('[Encore] registerCallbacks is not supported on web.');
|
|
85
|
+
return { success: false };
|
|
86
|
+
}
|
|
87
|
+
async completePurchaseRequest() {
|
|
88
|
+
console.warn('[Encore] completePurchaseRequest is not supported on web.');
|
|
89
|
+
return { success: false };
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
var web = /*#__PURE__*/Object.freeze({
|
|
94
|
+
__proto__: null,
|
|
95
|
+
EncorePluginWeb: EncorePluginWeb
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
exports.EncoreCapacitorPlugin = EncoreCapacitorPlugin;
|
|
99
|
+
exports.default = Encore;
|
|
100
|
+
|
|
101
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
102
|
+
|
|
103
|
+
return exports;
|
|
104
|
+
|
|
105
|
+
})({}, capacitorExports);
|
|
106
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["// Encore Capacitor SDK\n// Bridge-only layer — delegates to native SDKs on each platform.\n// iOS: encore-swift-sdk | Android: encore-android-sdk\nimport { registerPlugin } from '@capacitor/core';\nconst EncoreCapacitorPlugin = registerPlugin('EncoreCapacitorPlugin', {\n web: () => import('./web').then((m) => new m.EncorePluginWeb()),\n});\nasync function safeBridgeCall(method, call, fallback) {\n try {\n return await call();\n }\n catch (error) {\n console.warn(`[Encore] ${method} failed:`, error);\n return fallback;\n }\n}\n// -- Typed Export --\nconst Encore = {\n configure: (apiKey, options = {}) => safeBridgeCall('configure', () => EncoreCapacitorPlugin.configure({ apiKey, logLevel: options.logLevel }), { success: false }),\n identify: (userId, attributes) => safeBridgeCall('identify', () => EncoreCapacitorPlugin.identify({ userId, attributes }), { success: false }),\n setUserAttributes: (attributes) => safeBridgeCall('setUserAttributes', () => EncoreCapacitorPlugin.setUserAttributes({ attributes }), { success: false }),\n reset: () => safeBridgeCall('reset', () => EncoreCapacitorPlugin.reset(), {\n success: false,\n }),\n placement: (placementId) => ({\n show: () => safeBridgeCall('show', () => EncoreCapacitorPlugin.show({ placementId }), { status: 'not_granted', reason: 'sdk_error' }),\n }),\n show: (placementId) => safeBridgeCall('show', () => EncoreCapacitorPlugin.show({ placementId }), { status: 'not_granted', reason: 'sdk_error' }),\n placements: {\n setClaimEnabled: (enabled) => safeBridgeCall('setClaimEnabled', () => EncoreCapacitorPlugin.setClaimEnabled({ enabled }), { success: false }),\n },\n registerCallbacks: () => safeBridgeCall('registerCallbacks', () => EncoreCapacitorPlugin.registerCallbacks(), { success: false }),\n completePurchaseRequest: (success) => safeBridgeCall('completePurchaseRequest', () => EncoreCapacitorPlugin.completePurchaseRequest({ success }), { success: false }),\n onPurchaseRequest: (handler) => {\n const handle = EncoreCapacitorPlugin.addListener('onPurchaseRequest', handler);\n return () => {\n handle.then((h) => h.remove());\n };\n },\n onPurchaseComplete: (handler) => {\n const handle = EncoreCapacitorPlugin.addListener('onPurchaseComplete', handler);\n return () => {\n handle.then((h) => h.remove());\n };\n },\n onPassthrough: (handler) => {\n const handle = EncoreCapacitorPlugin.addListener('onPassthrough', handler);\n return () => {\n handle.then((h) => h.remove());\n };\n },\n};\nexport default Encore;\nexport { EncoreCapacitorPlugin };\n//# sourceMappingURL=index.js.map","// Web fallback — noop stubs with console warnings.\n// Real web SDK is a separate product (web-sdk/).\nimport { WebPlugin } from '@capacitor/core';\nexport class EncorePluginWeb extends WebPlugin {\n async configure() {\n console.warn('[Encore] Capacitor plugin is not supported on web.');\n return { success: false };\n }\n async identify() {\n console.warn('[Encore] identify is not supported on web.');\n return { success: false };\n }\n async setUserAttributes() {\n console.warn('[Encore] setUserAttributes is not supported on web.');\n return { success: false };\n }\n async reset() {\n console.warn('[Encore] reset is not supported on web.');\n return { success: false };\n }\n async show() {\n console.warn('[Encore] show is not supported on web.');\n return { status: 'not_granted', reason: 'web_unsupported' };\n }\n async setClaimEnabled() {\n console.warn('[Encore] setClaimEnabled is not supported on web.');\n return { success: false };\n }\n async registerCallbacks() {\n console.warn('[Encore] registerCallbacks is not supported on web.');\n return { success: false };\n }\n async completePurchaseRequest() {\n console.warn('[Encore] completePurchaseRequest is not supported on web.');\n return { success: false };\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;IAAA;IACA;IACA;AAEK,UAAC,qBAAqB,GAAGA,mBAAc,CAAC,uBAAuB,EAAE;IACtE,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,eAAe,EAAE,CAAC;IACnE,CAAC;IACD,eAAe,cAAc,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE;IACtD,IAAI,IAAI;IACR,QAAQ,OAAO,MAAM,IAAI,EAAE;IAC3B,IAAI;IACJ,IAAI,OAAO,KAAK,EAAE;IAClB,QAAQ,OAAO,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,MAAM,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC;IACzD,QAAQ,OAAO,QAAQ;IACvB,IAAI;IACJ;IACA;AACK,UAAC,MAAM,GAAG;IACf,IAAI,SAAS,EAAE,CAAC,MAAM,EAAE,OAAO,GAAG,EAAE,KAAK,cAAc,CAAC,WAAW,EAAE,MAAM,qBAAqB,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IACvK,IAAI,QAAQ,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,cAAc,CAAC,UAAU,EAAE,MAAM,qBAAqB,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAClJ,IAAI,iBAAiB,EAAE,CAAC,UAAU,KAAK,cAAc,CAAC,mBAAmB,EAAE,MAAM,qBAAqB,CAAC,iBAAiB,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC7J,IAA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C;IAC/D,QAAQ,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE;IACjC,IAAI;IACJ,IAAI,MAAM,IAAI,GAAG;IACjB,QAAQ,OAAO,CAAC,IAAI,CAAC,wCAAwC,CAAC;IAC9D,QAAQ,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,iBAAiB,EAAE;IACnE,IAAI;IACJ,IAAI,MAAM,eAAe,GAAG;IAC5B,QAAQ,OAAO,CAAC,IAAI,CAAC,mDAAmD,CAAC;IACzE,QAAQ,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE;IACjC,IAAI;IACJ,IAAI,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,OAAO,CAAC,IAAI,CAAC,qDAAqD,CAAC;IAC3E,QAAQ,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE;IACjC,IAAI;IACJ,IAAI,MAAM,uBAAuB,GAAG;IACpC,QAAQ,OAAO,CAAC,IAAI,CAAC,2DAA2D,CAAC;IACjF,QAAQ,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE;IACjC,IAAI;IACJ;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
// EncoreCapacitorPlugin.swift
|
|
2
|
+
// iOS bridge — delegates all calls to the native encore-swift-sdk.
|
|
3
|
+
|
|
4
|
+
import Foundation
|
|
5
|
+
import Capacitor
|
|
6
|
+
import Encore
|
|
7
|
+
|
|
8
|
+
@objc(EncoreCapacitorPlugin)
|
|
9
|
+
public class EncoreCapacitorPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
10
|
+
public let identifier = "EncoreCapacitorPlugin"
|
|
11
|
+
public let jsName = "EncoreCapacitorPlugin"
|
|
12
|
+
public let pluginMethods: [CAPPluginMethod] = [
|
|
13
|
+
CAPPluginMethod(name: "configure", returnType: CAPPluginReturnPromise),
|
|
14
|
+
CAPPluginMethod(name: "identify", returnType: CAPPluginReturnPromise),
|
|
15
|
+
CAPPluginMethod(name: "setUserAttributes", returnType: CAPPluginReturnPromise),
|
|
16
|
+
CAPPluginMethod(name: "reset", returnType: CAPPluginReturnPromise),
|
|
17
|
+
CAPPluginMethod(name: "show", returnType: CAPPluginReturnPromise),
|
|
18
|
+
CAPPluginMethod(name: "setClaimEnabled", returnType: CAPPluginReturnPromise),
|
|
19
|
+
CAPPluginMethod(name: "registerCallbacks", returnType: CAPPluginReturnPromise),
|
|
20
|
+
CAPPluginMethod(name: "completePurchaseRequest", returnType: CAPPluginReturnPromise),
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
private var currentContinuation: CheckedContinuation<Void, Error>?
|
|
24
|
+
private let lock = NSLock()
|
|
25
|
+
|
|
26
|
+
// MARK: - Configuration
|
|
27
|
+
|
|
28
|
+
@objc func configure(_ call: CAPPluginCall) {
|
|
29
|
+
guard let apiKey = call.getString("apiKey") else {
|
|
30
|
+
call.reject("Missing required parameter: apiKey")
|
|
31
|
+
return
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
let logLevel: Encore.LogLevel
|
|
35
|
+
switch call.getString("logLevel") {
|
|
36
|
+
case "error": logLevel = .error
|
|
37
|
+
case "warn": logLevel = .warn
|
|
38
|
+
case "info": logLevel = .info
|
|
39
|
+
case "debug": logLevel = .debug
|
|
40
|
+
default: logLevel = .none
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
DispatchQueue.main.async {
|
|
44
|
+
Encore.shared.configure(apiKey: apiKey, logLevel: logLevel)
|
|
45
|
+
call.resolve(["success": true])
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// MARK: - User Identity
|
|
50
|
+
|
|
51
|
+
@objc func identify(_ call: CAPPluginCall) {
|
|
52
|
+
guard let userId = call.getString("userId") else {
|
|
53
|
+
call.reject("Missing required parameter: userId")
|
|
54
|
+
return
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
let attrs = Self.parseAttributes(call.getObject("attributes"))
|
|
58
|
+
Encore.shared.identify(userId: userId, attributes: attrs)
|
|
59
|
+
call.resolve(["success": true])
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
@objc func setUserAttributes(_ call: CAPPluginCall) {
|
|
63
|
+
guard let attrsObj = call.getObject("attributes") else {
|
|
64
|
+
call.reject("Missing required parameter: attributes")
|
|
65
|
+
return
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if let attrs = Self.parseAttributes(attrsObj) {
|
|
69
|
+
Encore.shared.setUserAttributes(attrs)
|
|
70
|
+
}
|
|
71
|
+
call.resolve(["success": true])
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
@objc func reset(_ call: CAPPluginCall) {
|
|
75
|
+
cancelStalePurchase()
|
|
76
|
+
Encore.shared.reset()
|
|
77
|
+
call.resolve(["success": true])
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// MARK: - Claim Control
|
|
81
|
+
|
|
82
|
+
@objc func setClaimEnabled(_ call: CAPPluginCall) {
|
|
83
|
+
guard let enabled = call.getBool("enabled") else {
|
|
84
|
+
call.reject("Missing required parameter: enabled")
|
|
85
|
+
return
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
Encore.shared.placements.isClaimEnabled = enabled
|
|
89
|
+
call.resolve(["success": true])
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// MARK: - Offers
|
|
93
|
+
|
|
94
|
+
@objc func show(_ call: CAPPluginCall) {
|
|
95
|
+
let placementId = call.getString("placementId")
|
|
96
|
+
|
|
97
|
+
cancelStalePurchase()
|
|
98
|
+
Task {
|
|
99
|
+
do {
|
|
100
|
+
let result = try await Encore.placement(placementId).show()
|
|
101
|
+
switch result {
|
|
102
|
+
case .granted(let entitlement):
|
|
103
|
+
call.resolve(["status": "granted", "entitlement": "\(entitlement)"])
|
|
104
|
+
case .notGranted(let reason):
|
|
105
|
+
call.resolve(["status": "not_granted", "reason": reason.rawValue])
|
|
106
|
+
}
|
|
107
|
+
} catch {
|
|
108
|
+
call.reject("SHOW_FAILED", error.localizedDescription, error)
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// MARK: - Callbacks
|
|
114
|
+
|
|
115
|
+
@objc func registerCallbacks(_ call: CAPPluginCall) {
|
|
116
|
+
Encore.shared
|
|
117
|
+
.onPurchaseRequest { [weak self] request in
|
|
118
|
+
guard let self = self else { return }
|
|
119
|
+
|
|
120
|
+
self.cancelStalePurchase()
|
|
121
|
+
|
|
122
|
+
try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<Void, Error>) in
|
|
123
|
+
self.lock.lock()
|
|
124
|
+
self.currentContinuation = continuation
|
|
125
|
+
self.lock.unlock()
|
|
126
|
+
|
|
127
|
+
self.notifyListeners("onPurchaseRequest", data: [
|
|
128
|
+
"productId": request.productId,
|
|
129
|
+
"placementId": request.placementId as Any,
|
|
130
|
+
"promoOfferId": request.promoOfferId as Any,
|
|
131
|
+
])
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
.onPurchaseComplete { [weak self] transaction, productId in
|
|
135
|
+
guard let self = self else { return }
|
|
136
|
+
self.notifyListeners("onPurchaseComplete", data: [
|
|
137
|
+
"productId": productId,
|
|
138
|
+
"transactionId": "\(transaction.id)",
|
|
139
|
+
])
|
|
140
|
+
}
|
|
141
|
+
.onPassthrough { [weak self] placementId in
|
|
142
|
+
guard let self = self else { return }
|
|
143
|
+
self.notifyListeners("onPassthrough", data: [
|
|
144
|
+
"placementId": placementId as Any,
|
|
145
|
+
])
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
call.resolve(["success": true])
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
@objc func completePurchaseRequest(_ call: CAPPluginCall) {
|
|
152
|
+
let success = call.getBool("success") ?? false
|
|
153
|
+
|
|
154
|
+
lock.lock()
|
|
155
|
+
let continuation = currentContinuation
|
|
156
|
+
currentContinuation = nil
|
|
157
|
+
lock.unlock()
|
|
158
|
+
|
|
159
|
+
if let continuation {
|
|
160
|
+
if success {
|
|
161
|
+
continuation.resume()
|
|
162
|
+
} else {
|
|
163
|
+
continuation.resume(throwing: NSError(
|
|
164
|
+
domain: "EncoreCapacitorPlugin",
|
|
165
|
+
code: -2,
|
|
166
|
+
userInfo: [NSLocalizedDescriptionKey: "Purchase failed by JS handler"]
|
|
167
|
+
))
|
|
168
|
+
}
|
|
169
|
+
call.resolve(["success": true])
|
|
170
|
+
} else {
|
|
171
|
+
call.resolve(["success": false, "error": "No pending purchase request"])
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// MARK: - Internal
|
|
176
|
+
|
|
177
|
+
private func cancelStalePurchase() {
|
|
178
|
+
lock.lock()
|
|
179
|
+
let stale = currentContinuation
|
|
180
|
+
currentContinuation = nil
|
|
181
|
+
lock.unlock()
|
|
182
|
+
|
|
183
|
+
stale?.resume(throwing: NSError(
|
|
184
|
+
domain: "EncoreCapacitorPlugin",
|
|
185
|
+
code: -3,
|
|
186
|
+
userInfo: [NSLocalizedDescriptionKey: "Superseded by new SDK action"]
|
|
187
|
+
))
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// MARK: - Helpers
|
|
191
|
+
|
|
192
|
+
private static func parseAttributes(_ dict: [String: Any]?) -> UserAttributes? {
|
|
193
|
+
guard let dict = dict else { return nil }
|
|
194
|
+
return UserAttributes(
|
|
195
|
+
email: dict["email"] as? String,
|
|
196
|
+
firstName: dict["firstName"] as? String,
|
|
197
|
+
lastName: dict["lastName"] as? String,
|
|
198
|
+
phoneNumber: dict["phoneNumber"] as? String,
|
|
199
|
+
postalCode: dict["postalCode"] as? String,
|
|
200
|
+
city: dict["city"] as? String,
|
|
201
|
+
state: dict["state"] as? String,
|
|
202
|
+
countryCode: dict["countryCode"] as? String,
|
|
203
|
+
latitude: dict["latitude"] as? String,
|
|
204
|
+
longitude: dict["longitude"] as? String,
|
|
205
|
+
dateOfBirth: dict["dateOfBirth"] as? String,
|
|
206
|
+
gender: dict["gender"] as? String,
|
|
207
|
+
language: dict["language"] as? String,
|
|
208
|
+
subscriptionTier: dict["subscriptionTier"] as? String,
|
|
209
|
+
monthsSubscribed: dict["monthsSubscribed"] as? String,
|
|
210
|
+
billingCycle: dict["billingCycle"] as? String,
|
|
211
|
+
lastPaymentAmount: dict["lastPaymentAmount"] as? String,
|
|
212
|
+
lastActiveDate: dict["lastActiveDate"] as? String,
|
|
213
|
+
totalSessions: dict["totalSessions"] as? String,
|
|
214
|
+
custom: dict["custom"] as? [String: String] ?? [:]
|
|
215
|
+
)
|
|
216
|
+
}
|
|
217
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// EncoreCapacitorPlugin.m
|
|
2
|
+
// Objective-C bridge declarations for Capacitor.
|
|
3
|
+
// Each method here corresponds to a Swift method in EncoreCapacitorPlugin.swift.
|
|
4
|
+
|
|
5
|
+
#import <Foundation/Foundation.h>
|
|
6
|
+
#import <Capacitor/Capacitor.h>
|
|
7
|
+
|
|
8
|
+
CAP_PLUGIN(EncoreCapacitorPlugin, "EncoreCapacitorPlugin",
|
|
9
|
+
CAP_PLUGIN_METHOD(configure, CAPPluginReturnPromise);
|
|
10
|
+
CAP_PLUGIN_METHOD(identify, CAPPluginReturnPromise);
|
|
11
|
+
CAP_PLUGIN_METHOD(setUserAttributes, CAPPluginReturnPromise);
|
|
12
|
+
CAP_PLUGIN_METHOD(reset, CAPPluginReturnPromise);
|
|
13
|
+
CAP_PLUGIN_METHOD(show, CAPPluginReturnPromise);
|
|
14
|
+
CAP_PLUGIN_METHOD(setClaimEnabled, CAPPluginReturnPromise);
|
|
15
|
+
CAP_PLUGIN_METHOD(registerCallbacks, CAPPluginReturnPromise);
|
|
16
|
+
CAP_PLUGIN_METHOD(completePurchaseRequest, CAPPluginReturnPromise);
|
|
17
|
+
)
|
package/package.json
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@encorekit/capacitor",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"sdkVersions": {
|
|
5
|
+
"ios": {
|
|
6
|
+
"EncoreKit": "1.4.39"
|
|
7
|
+
},
|
|
8
|
+
"android": {
|
|
9
|
+
"com.encorekit:encore": "1.4.38"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"description": "Encore Capacitor bridge — thin native plugin layer delegating to encore-swift-sdk (iOS) and encore-android-sdk (Android)",
|
|
13
|
+
"main": "dist/plugin.cjs.js",
|
|
14
|
+
"module": "dist/esm/index.js",
|
|
15
|
+
"types": "dist/esm/index.d.ts",
|
|
16
|
+
"unpkg": "dist/plugin.js",
|
|
17
|
+
"files": [
|
|
18
|
+
"dist/",
|
|
19
|
+
"ios/",
|
|
20
|
+
"android/",
|
|
21
|
+
"*.podspec",
|
|
22
|
+
"!android/.gradle",
|
|
23
|
+
"!android/build",
|
|
24
|
+
"!android/gradle",
|
|
25
|
+
"!android/gradlew",
|
|
26
|
+
"!android/gradlew.bat",
|
|
27
|
+
"!android/local.properties",
|
|
28
|
+
"!**/__tests__",
|
|
29
|
+
"!**/.*"
|
|
30
|
+
],
|
|
31
|
+
"scripts": {
|
|
32
|
+
"test": "jest",
|
|
33
|
+
"typecheck": "tsc --noEmit",
|
|
34
|
+
"lint": "eslint \"src/**/*.ts\"",
|
|
35
|
+
"build": "npm run clean && tsc && rollup -c rollup.config.mjs",
|
|
36
|
+
"clean": "rimraf dist"
|
|
37
|
+
},
|
|
38
|
+
"keywords": [
|
|
39
|
+
"capacitor",
|
|
40
|
+
"capacitor-plugin",
|
|
41
|
+
"ios",
|
|
42
|
+
"android",
|
|
43
|
+
"encore",
|
|
44
|
+
"offers",
|
|
45
|
+
"sdk",
|
|
46
|
+
"monetization",
|
|
47
|
+
"entitlements"
|
|
48
|
+
],
|
|
49
|
+
"capacitor": {
|
|
50
|
+
"ios": {
|
|
51
|
+
"src": "ios"
|
|
52
|
+
},
|
|
53
|
+
"android": {
|
|
54
|
+
"src": "android"
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
"repository": {
|
|
58
|
+
"type": "git",
|
|
59
|
+
"url": "git+https://github.com/EncoreKit/capacitor-sdk.git"
|
|
60
|
+
},
|
|
61
|
+
"author": "Encore <support@encorekit.com>",
|
|
62
|
+
"license": "MIT",
|
|
63
|
+
"bugs": {
|
|
64
|
+
"url": "https://github.com/EncoreKit/capacitor-sdk/issues"
|
|
65
|
+
},
|
|
66
|
+
"homepage": "https://github.com/EncoreKit/capacitor-sdk#readme",
|
|
67
|
+
"publishConfig": {
|
|
68
|
+
"registry": "https://registry.npmjs.org/"
|
|
69
|
+
},
|
|
70
|
+
"peerDependencies": {
|
|
71
|
+
"@capacitor/core": "^6.0.0"
|
|
72
|
+
},
|
|
73
|
+
"devDependencies": {
|
|
74
|
+
"@capacitor/core": "^6.0.0",
|
|
75
|
+
"@rollup/plugin-node-resolve": "^16.0.0",
|
|
76
|
+
"@types/jest": "^29.5.0",
|
|
77
|
+
"eslint": "^8.57.1",
|
|
78
|
+
"jest": "^29.7.0",
|
|
79
|
+
"rimraf": "^6.0.0",
|
|
80
|
+
"rollup": "^4.0.0",
|
|
81
|
+
"ts-jest": "^29.2.0",
|
|
82
|
+
"typescript": "~5.5.0"
|
|
83
|
+
},
|
|
84
|
+
"jest": {
|
|
85
|
+
"preset": "ts-jest",
|
|
86
|
+
"testEnvironment": "node",
|
|
87
|
+
"roots": [
|
|
88
|
+
"<rootDir>/src"
|
|
89
|
+
],
|
|
90
|
+
"modulePathIgnorePatterns": [
|
|
91
|
+
"<rootDir>/example/",
|
|
92
|
+
"<rootDir>/dist/"
|
|
93
|
+
]
|
|
94
|
+
}
|
|
95
|
+
}
|