@capgo/capacitor-rudderstack 8.1.2

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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["var __rest = (this && this.__rest) || function (s, e) {\n var t = {};\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\n t[p] = s[p];\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\n t[p[i]] = s[p[i]];\n }\n return t;\n};\nimport { registerPlugin } from '@capacitor/core';\nconst nativePlugin = registerPlugin('RudderStack', {\n web: () => import('./web').then((m) => new m.RudderStackWeb()),\n});\nexport const RudderLogLevel = Object.freeze({\n VERBOSE: 5,\n DEBUG: 4,\n INFO: 3,\n WARN: 2,\n ERROR: 1,\n NONE: 0,\n});\nfunction isValidString(value) {\n return typeof value === 'string' && value.trim().length > 0;\n}\nfunction isValidBoolean(value) {\n return typeof value === 'boolean';\n}\nfunction isRecord(value) {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\nfunction isRudderOptions(value) {\n return isRecord(value) && ('externalIds' in value || 'integrations' in value);\n}\nfunction sanitizeConfig(config) {\n if (!config) {\n return undefined;\n }\n if (Array.isArray(config.factories) && config.factories.length > 0) {\n console.warn('config.factories is ignored by @capgo/capacitor-rudderstack. Native Rudder destination factories are not implemented yet.');\n }\n const { factories } = config, safeConfig = __rest(config, [\"factories\"]);\n void factories;\n return safeConfig;\n}\nasync function callIfValid(value, errorMessage, action) {\n if (value === undefined) {\n console.log(errorMessage);\n return;\n }\n await action();\n}\nconst RudderClient = {\n async initialize(writeKey, config, options) {\n if (!isValidString(writeKey)) {\n const message = 'WriteKey is Invalid, Aborting SDK Initialization';\n console.log(message);\n throw new Error(message);\n }\n let resolvedConfig = config;\n let resolvedOptions = options;\n if (isRudderOptions(config)) {\n resolvedOptions = config;\n resolvedConfig = undefined;\n }\n if (resolvedOptions !== undefined && !isRudderOptions(resolvedOptions)) {\n console.log('Options is invalid, setting it to null');\n resolvedOptions = undefined;\n }\n await nativePlugin.initialize({\n writeKey,\n config: sanitizeConfig(resolvedConfig),\n options: resolvedOptions,\n });\n },\n async identify(userId, traits, options) {\n if (!isValidString(userId)) {\n console.log('userId is Invalid, dropping identify call');\n return;\n }\n let resolvedTraits = traits;\n let resolvedOptions = options;\n if (isRudderOptions(traits)) {\n resolvedOptions = traits;\n resolvedTraits = undefined;\n }\n if (resolvedOptions !== undefined && !isRudderOptions(resolvedOptions)) {\n console.log('Options is invalid, setting it to null');\n resolvedOptions = undefined;\n }\n await nativePlugin.identify({\n userId,\n traits: resolvedTraits,\n options: resolvedOptions,\n });\n },\n async group(groupId, groupTraits, options) {\n if (!isValidString(groupId)) {\n console.log('groupId is Invalid, dropping group call');\n return;\n }\n let resolvedTraits = groupTraits;\n let resolvedOptions = options;\n if (isRudderOptions(groupTraits)) {\n resolvedOptions = groupTraits;\n resolvedTraits = undefined;\n }\n if (resolvedOptions !== undefined && !isRudderOptions(resolvedOptions)) {\n console.log('Options is invalid, setting it to null');\n resolvedOptions = undefined;\n }\n await nativePlugin.group({\n groupId,\n groupTraits: resolvedTraits,\n options: resolvedOptions,\n });\n },\n async track(eventName, properties, options) {\n if (!isValidString(eventName)) {\n console.log('eventName is Invalid, dropping track call');\n return;\n }\n let resolvedProperties = properties;\n let resolvedOptions = options;\n if (isRudderOptions(properties)) {\n resolvedOptions = properties;\n resolvedProperties = undefined;\n }\n if (resolvedOptions !== undefined && !isRudderOptions(resolvedOptions)) {\n console.log('Options is invalid, setting it to null');\n resolvedOptions = undefined;\n }\n await nativePlugin.track({\n eventName,\n properties: resolvedProperties,\n options: resolvedOptions,\n });\n },\n async screen(screenName, properties, options) {\n if (!isValidString(screenName)) {\n console.log('screenName is Invalid, dropping screen call');\n return;\n }\n let resolvedProperties = properties;\n let resolvedOptions = options;\n if (isRudderOptions(properties)) {\n resolvedOptions = properties;\n resolvedProperties = undefined;\n }\n if (resolvedOptions !== undefined && !isRudderOptions(resolvedOptions)) {\n console.log('Options is invalid, setting it to null');\n resolvedOptions = undefined;\n }\n await nativePlugin.screen({\n screenName,\n properties: resolvedProperties,\n options: resolvedOptions,\n });\n },\n async alias(newId, options) {\n if (!isValidString(newId)) {\n console.log('newId is Invalid, dropping alias call');\n return;\n }\n const resolvedOptions = options !== undefined && !isRudderOptions(options) ? undefined : options;\n if (options !== undefined && resolvedOptions === undefined) {\n console.log('Options is invalid, setting it to null');\n }\n await nativePlugin.alias({\n newId,\n options: resolvedOptions,\n });\n },\n async reset() {\n await nativePlugin.reset();\n },\n async flush() {\n await nativePlugin.flush();\n },\n async putDeviceToken(deviceToken) {\n await callIfValid(isValidString(deviceToken) ? deviceToken : undefined, 'deviceToken is Invalid, dropping putDeviceToken call', () => nativePlugin.putDeviceToken({ deviceToken }));\n },\n async setAdvertisingId(advertisingId) {\n await this.putAdvertisingId(advertisingId);\n },\n async putAdvertisingId(advertisingId) {\n await callIfValid(isValidString(advertisingId) ? advertisingId : undefined, 'advertisingId is Invalid, dropping putAdvertisingId call', () => nativePlugin.putAdvertisingId({ advertisingId }));\n },\n async setAnonymousId(anonymousId) {\n await this.putAnonymousId(anonymousId);\n },\n async putAnonymousId(anonymousId) {\n await callIfValid(isValidString(anonymousId) ? anonymousId : undefined, 'anonymousId is Invalid, dropping putAnonymousId call', () => nativePlugin.putAnonymousId({ anonymousId }));\n },\n async optOut(optOut) {\n if (!isValidBoolean(optOut)) {\n console.log('optOut is Invalid, dropping optOut call');\n return;\n }\n await nativePlugin.optOut({ optOut });\n },\n async getPluginVersion() {\n return nativePlugin.getPluginVersion();\n },\n LogLevel: RudderLogLevel,\n};\nconst RudderStack = RudderClient;\nexport * from './definitions';\nexport { RudderClient, RudderStack };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class RudderStackWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.initialized = false;\n }\n async initialize(options) {\n if (!options.writeKey) {\n throw new Error('writeKey is required');\n }\n this.initialized = true;\n }\n async identify(options) {\n this.ensureInitialized();\n void options;\n }\n async group(options) {\n this.ensureInitialized();\n void options;\n }\n async track(options) {\n this.ensureInitialized();\n void options;\n }\n async screen(options) {\n this.ensureInitialized();\n void options;\n }\n async alias(options) {\n this.ensureInitialized();\n void options;\n }\n async reset() {\n this.ensureInitialized();\n }\n async flush() {\n this.ensureInitialized();\n }\n async putDeviceToken(options) {\n void options.deviceToken;\n }\n async setAdvertisingId(options) {\n await this.putAdvertisingId(options);\n }\n async putAdvertisingId(options) {\n void options.advertisingId;\n }\n async setAnonymousId(options) {\n await this.putAnonymousId(options);\n }\n async putAnonymousId(options) {\n void options.anonymousId;\n }\n async optOut(options) {\n this.ensureInitialized();\n void options.optOut;\n }\n async getPluginVersion() {\n return {\n version: 'web',\n };\n }\n ensureInitialized() {\n if (!this.initialized) {\n throw new Error('RudderStack SDK is not initialized');\n }\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["this","registerPlugin","WebPlugin"],"mappings":";;;;AAAA,IAAI,MAAM,GAAG,CAACA,SAAI,IAAIA,SAAI,CAAC,MAAM,KAAK,UAAU,CAAC,EAAE,CAAC,EAAE;AACtD,IAAI,IAAI,CAAC,GAAG,EAAE;AACd,IAAI,KAAK,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC;AACvF,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AACnB,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,OAAO,MAAM,CAAC,qBAAqB,KAAK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+ var capacitorRudderStack = (function (exports, core) {
2
+ 'use strict';
3
+
4
+ var __rest = (undefined && undefined.__rest) || function (s, e) {
5
+ var t = {};
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
7
+ t[p] = s[p];
8
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
9
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
10
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
11
+ t[p[i]] = s[p[i]];
12
+ }
13
+ return t;
14
+ };
15
+ const nativePlugin = core.registerPlugin('RudderStack', {
16
+ web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.RudderStackWeb()),
17
+ });
18
+ const RudderLogLevel = Object.freeze({
19
+ VERBOSE: 5,
20
+ DEBUG: 4,
21
+ INFO: 3,
22
+ WARN: 2,
23
+ ERROR: 1,
24
+ NONE: 0,
25
+ });
26
+ function isValidString(value) {
27
+ return typeof value === 'string' && value.trim().length > 0;
28
+ }
29
+ function isValidBoolean(value) {
30
+ return typeof value === 'boolean';
31
+ }
32
+ function isRecord(value) {
33
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
34
+ }
35
+ function isRudderOptions(value) {
36
+ return isRecord(value) && ('externalIds' in value || 'integrations' in value);
37
+ }
38
+ function sanitizeConfig(config) {
39
+ if (!config) {
40
+ return undefined;
41
+ }
42
+ if (Array.isArray(config.factories) && config.factories.length > 0) {
43
+ console.warn('config.factories is ignored by @capgo/capacitor-rudderstack. Native Rudder destination factories are not implemented yet.');
44
+ }
45
+ const { factories } = config, safeConfig = __rest(config, ["factories"]);
46
+ return safeConfig;
47
+ }
48
+ async function callIfValid(value, errorMessage, action) {
49
+ if (value === undefined) {
50
+ console.log(errorMessage);
51
+ return;
52
+ }
53
+ await action();
54
+ }
55
+ const RudderClient = {
56
+ async initialize(writeKey, config, options) {
57
+ if (!isValidString(writeKey)) {
58
+ const message = 'WriteKey is Invalid, Aborting SDK Initialization';
59
+ console.log(message);
60
+ throw new Error(message);
61
+ }
62
+ let resolvedConfig = config;
63
+ let resolvedOptions = options;
64
+ if (isRudderOptions(config)) {
65
+ resolvedOptions = config;
66
+ resolvedConfig = undefined;
67
+ }
68
+ if (resolvedOptions !== undefined && !isRudderOptions(resolvedOptions)) {
69
+ console.log('Options is invalid, setting it to null');
70
+ resolvedOptions = undefined;
71
+ }
72
+ await nativePlugin.initialize({
73
+ writeKey,
74
+ config: sanitizeConfig(resolvedConfig),
75
+ options: resolvedOptions,
76
+ });
77
+ },
78
+ async identify(userId, traits, options) {
79
+ if (!isValidString(userId)) {
80
+ console.log('userId is Invalid, dropping identify call');
81
+ return;
82
+ }
83
+ let resolvedTraits = traits;
84
+ let resolvedOptions = options;
85
+ if (isRudderOptions(traits)) {
86
+ resolvedOptions = traits;
87
+ resolvedTraits = undefined;
88
+ }
89
+ if (resolvedOptions !== undefined && !isRudderOptions(resolvedOptions)) {
90
+ console.log('Options is invalid, setting it to null');
91
+ resolvedOptions = undefined;
92
+ }
93
+ await nativePlugin.identify({
94
+ userId,
95
+ traits: resolvedTraits,
96
+ options: resolvedOptions,
97
+ });
98
+ },
99
+ async group(groupId, groupTraits, options) {
100
+ if (!isValidString(groupId)) {
101
+ console.log('groupId is Invalid, dropping group call');
102
+ return;
103
+ }
104
+ let resolvedTraits = groupTraits;
105
+ let resolvedOptions = options;
106
+ if (isRudderOptions(groupTraits)) {
107
+ resolvedOptions = groupTraits;
108
+ resolvedTraits = undefined;
109
+ }
110
+ if (resolvedOptions !== undefined && !isRudderOptions(resolvedOptions)) {
111
+ console.log('Options is invalid, setting it to null');
112
+ resolvedOptions = undefined;
113
+ }
114
+ await nativePlugin.group({
115
+ groupId,
116
+ groupTraits: resolvedTraits,
117
+ options: resolvedOptions,
118
+ });
119
+ },
120
+ async track(eventName, properties, options) {
121
+ if (!isValidString(eventName)) {
122
+ console.log('eventName is Invalid, dropping track call');
123
+ return;
124
+ }
125
+ let resolvedProperties = properties;
126
+ let resolvedOptions = options;
127
+ if (isRudderOptions(properties)) {
128
+ resolvedOptions = properties;
129
+ resolvedProperties = undefined;
130
+ }
131
+ if (resolvedOptions !== undefined && !isRudderOptions(resolvedOptions)) {
132
+ console.log('Options is invalid, setting it to null');
133
+ resolvedOptions = undefined;
134
+ }
135
+ await nativePlugin.track({
136
+ eventName,
137
+ properties: resolvedProperties,
138
+ options: resolvedOptions,
139
+ });
140
+ },
141
+ async screen(screenName, properties, options) {
142
+ if (!isValidString(screenName)) {
143
+ console.log('screenName is Invalid, dropping screen call');
144
+ return;
145
+ }
146
+ let resolvedProperties = properties;
147
+ let resolvedOptions = options;
148
+ if (isRudderOptions(properties)) {
149
+ resolvedOptions = properties;
150
+ resolvedProperties = undefined;
151
+ }
152
+ if (resolvedOptions !== undefined && !isRudderOptions(resolvedOptions)) {
153
+ console.log('Options is invalid, setting it to null');
154
+ resolvedOptions = undefined;
155
+ }
156
+ await nativePlugin.screen({
157
+ screenName,
158
+ properties: resolvedProperties,
159
+ options: resolvedOptions,
160
+ });
161
+ },
162
+ async alias(newId, options) {
163
+ if (!isValidString(newId)) {
164
+ console.log('newId is Invalid, dropping alias call');
165
+ return;
166
+ }
167
+ const resolvedOptions = options !== undefined && !isRudderOptions(options) ? undefined : options;
168
+ if (options !== undefined && resolvedOptions === undefined) {
169
+ console.log('Options is invalid, setting it to null');
170
+ }
171
+ await nativePlugin.alias({
172
+ newId,
173
+ options: resolvedOptions,
174
+ });
175
+ },
176
+ async reset() {
177
+ await nativePlugin.reset();
178
+ },
179
+ async flush() {
180
+ await nativePlugin.flush();
181
+ },
182
+ async putDeviceToken(deviceToken) {
183
+ await callIfValid(isValidString(deviceToken) ? deviceToken : undefined, 'deviceToken is Invalid, dropping putDeviceToken call', () => nativePlugin.putDeviceToken({ deviceToken }));
184
+ },
185
+ async setAdvertisingId(advertisingId) {
186
+ await this.putAdvertisingId(advertisingId);
187
+ },
188
+ async putAdvertisingId(advertisingId) {
189
+ await callIfValid(isValidString(advertisingId) ? advertisingId : undefined, 'advertisingId is Invalid, dropping putAdvertisingId call', () => nativePlugin.putAdvertisingId({ advertisingId }));
190
+ },
191
+ async setAnonymousId(anonymousId) {
192
+ await this.putAnonymousId(anonymousId);
193
+ },
194
+ async putAnonymousId(anonymousId) {
195
+ await callIfValid(isValidString(anonymousId) ? anonymousId : undefined, 'anonymousId is Invalid, dropping putAnonymousId call', () => nativePlugin.putAnonymousId({ anonymousId }));
196
+ },
197
+ async optOut(optOut) {
198
+ if (!isValidBoolean(optOut)) {
199
+ console.log('optOut is Invalid, dropping optOut call');
200
+ return;
201
+ }
202
+ await nativePlugin.optOut({ optOut });
203
+ },
204
+ async getPluginVersion() {
205
+ return nativePlugin.getPluginVersion();
206
+ },
207
+ LogLevel: RudderLogLevel,
208
+ };
209
+ const RudderStack = RudderClient;
210
+
211
+ class RudderStackWeb extends core.WebPlugin {
212
+ constructor() {
213
+ super(...arguments);
214
+ this.initialized = false;
215
+ }
216
+ async initialize(options) {
217
+ if (!options.writeKey) {
218
+ throw new Error('writeKey is required');
219
+ }
220
+ this.initialized = true;
221
+ }
222
+ async identify(options) {
223
+ this.ensureInitialized();
224
+ }
225
+ async group(options) {
226
+ this.ensureInitialized();
227
+ }
228
+ async track(options) {
229
+ this.ensureInitialized();
230
+ }
231
+ async screen(options) {
232
+ this.ensureInitialized();
233
+ }
234
+ async alias(options) {
235
+ this.ensureInitialized();
236
+ }
237
+ async reset() {
238
+ this.ensureInitialized();
239
+ }
240
+ async flush() {
241
+ this.ensureInitialized();
242
+ }
243
+ async putDeviceToken(options) {
244
+ void options.deviceToken;
245
+ }
246
+ async setAdvertisingId(options) {
247
+ await this.putAdvertisingId(options);
248
+ }
249
+ async putAdvertisingId(options) {
250
+ void options.advertisingId;
251
+ }
252
+ async setAnonymousId(options) {
253
+ await this.putAnonymousId(options);
254
+ }
255
+ async putAnonymousId(options) {
256
+ void options.anonymousId;
257
+ }
258
+ async optOut(options) {
259
+ this.ensureInitialized();
260
+ void options.optOut;
261
+ }
262
+ async getPluginVersion() {
263
+ return {
264
+ version: 'web',
265
+ };
266
+ }
267
+ ensureInitialized() {
268
+ if (!this.initialized) {
269
+ throw new Error('RudderStack SDK is not initialized');
270
+ }
271
+ }
272
+ }
273
+
274
+ var web = /*#__PURE__*/Object.freeze({
275
+ __proto__: null,
276
+ RudderStackWeb: RudderStackWeb
277
+ });
278
+
279
+ exports.RudderClient = RudderClient;
280
+ exports.RudderLogLevel = RudderLogLevel;
281
+ exports.RudderStack = RudderStack;
282
+
283
+ return exports;
284
+
285
+ })({}, capacitorExports);
286
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["var __rest = (this && this.__rest) || function (s, e) {\n var t = {};\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\n t[p] = s[p];\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\n t[p[i]] = s[p[i]];\n }\n return t;\n};\nimport { registerPlugin } from '@capacitor/core';\nconst nativePlugin = registerPlugin('RudderStack', {\n web: () => import('./web').then((m) => new m.RudderStackWeb()),\n});\nexport const RudderLogLevel = Object.freeze({\n VERBOSE: 5,\n DEBUG: 4,\n INFO: 3,\n WARN: 2,\n ERROR: 1,\n NONE: 0,\n});\nfunction isValidString(value) {\n return typeof value === 'string' && value.trim().length > 0;\n}\nfunction isValidBoolean(value) {\n return typeof value === 'boolean';\n}\nfunction isRecord(value) {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\nfunction isRudderOptions(value) {\n return isRecord(value) && ('externalIds' in value || 'integrations' in value);\n}\nfunction sanitizeConfig(config) {\n if (!config) {\n return undefined;\n }\n if (Array.isArray(config.factories) && config.factories.length > 0) {\n console.warn('config.factories is ignored by @capgo/capacitor-rudderstack. Native Rudder destination factories are not implemented yet.');\n }\n const { factories } = config, safeConfig = __rest(config, [\"factories\"]);\n void factories;\n return safeConfig;\n}\nasync function callIfValid(value, errorMessage, action) {\n if (value === undefined) {\n console.log(errorMessage);\n return;\n }\n await action();\n}\nconst RudderClient = {\n async initialize(writeKey, config, options) {\n if (!isValidString(writeKey)) {\n const message = 'WriteKey is Invalid, Aborting SDK Initialization';\n console.log(message);\n throw new Error(message);\n }\n let resolvedConfig = config;\n let resolvedOptions = options;\n if (isRudderOptions(config)) {\n resolvedOptions = config;\n resolvedConfig = undefined;\n }\n if (resolvedOptions !== undefined && !isRudderOptions(resolvedOptions)) {\n console.log('Options is invalid, setting it to null');\n resolvedOptions = undefined;\n }\n await nativePlugin.initialize({\n writeKey,\n config: sanitizeConfig(resolvedConfig),\n options: resolvedOptions,\n });\n },\n async identify(userId, traits, options) {\n if (!isValidString(userId)) {\n console.log('userId is Invalid, dropping identify call');\n return;\n }\n let resolvedTraits = traits;\n let resolvedOptions = options;\n if (isRudderOptions(traits)) {\n resolvedOptions = traits;\n resolvedTraits = undefined;\n }\n if (resolvedOptions !== undefined && !isRudderOptions(resolvedOptions)) {\n console.log('Options is invalid, setting it to null');\n resolvedOptions = undefined;\n }\n await nativePlugin.identify({\n userId,\n traits: resolvedTraits,\n options: resolvedOptions,\n });\n },\n async group(groupId, groupTraits, options) {\n if (!isValidString(groupId)) {\n console.log('groupId is Invalid, dropping group call');\n return;\n }\n let resolvedTraits = groupTraits;\n let resolvedOptions = options;\n if (isRudderOptions(groupTraits)) {\n resolvedOptions = groupTraits;\n resolvedTraits = undefined;\n }\n if (resolvedOptions !== undefined && !isRudderOptions(resolvedOptions)) {\n console.log('Options is invalid, setting it to null');\n resolvedOptions = undefined;\n }\n await nativePlugin.group({\n groupId,\n groupTraits: resolvedTraits,\n options: resolvedOptions,\n });\n },\n async track(eventName, properties, options) {\n if (!isValidString(eventName)) {\n console.log('eventName is Invalid, dropping track call');\n return;\n }\n let resolvedProperties = properties;\n let resolvedOptions = options;\n if (isRudderOptions(properties)) {\n resolvedOptions = properties;\n resolvedProperties = undefined;\n }\n if (resolvedOptions !== undefined && !isRudderOptions(resolvedOptions)) {\n console.log('Options is invalid, setting it to null');\n resolvedOptions = undefined;\n }\n await nativePlugin.track({\n eventName,\n properties: resolvedProperties,\n options: resolvedOptions,\n });\n },\n async screen(screenName, properties, options) {\n if (!isValidString(screenName)) {\n console.log('screenName is Invalid, dropping screen call');\n return;\n }\n let resolvedProperties = properties;\n let resolvedOptions = options;\n if (isRudderOptions(properties)) {\n resolvedOptions = properties;\n resolvedProperties = undefined;\n }\n if (resolvedOptions !== undefined && !isRudderOptions(resolvedOptions)) {\n console.log('Options is invalid, setting it to null');\n resolvedOptions = undefined;\n }\n await nativePlugin.screen({\n screenName,\n properties: resolvedProperties,\n options: resolvedOptions,\n });\n },\n async alias(newId, options) {\n if (!isValidString(newId)) {\n console.log('newId is Invalid, dropping alias call');\n return;\n }\n const resolvedOptions = options !== undefined && !isRudderOptions(options) ? undefined : options;\n if (options !== undefined && resolvedOptions === undefined) {\n console.log('Options is invalid, setting it to null');\n }\n await nativePlugin.alias({\n newId,\n options: resolvedOptions,\n });\n },\n async reset() {\n await nativePlugin.reset();\n },\n async flush() {\n await nativePlugin.flush();\n },\n async putDeviceToken(deviceToken) {\n await callIfValid(isValidString(deviceToken) ? deviceToken : undefined, 'deviceToken is Invalid, dropping putDeviceToken call', () => nativePlugin.putDeviceToken({ deviceToken }));\n },\n async setAdvertisingId(advertisingId) {\n await this.putAdvertisingId(advertisingId);\n },\n async putAdvertisingId(advertisingId) {\n await callIfValid(isValidString(advertisingId) ? advertisingId : undefined, 'advertisingId is Invalid, dropping putAdvertisingId call', () => nativePlugin.putAdvertisingId({ advertisingId }));\n },\n async setAnonymousId(anonymousId) {\n await this.putAnonymousId(anonymousId);\n },\n async putAnonymousId(anonymousId) {\n await callIfValid(isValidString(anonymousId) ? anonymousId : undefined, 'anonymousId is Invalid, dropping putAnonymousId call', () => nativePlugin.putAnonymousId({ anonymousId }));\n },\n async optOut(optOut) {\n if (!isValidBoolean(optOut)) {\n console.log('optOut is Invalid, dropping optOut call');\n return;\n }\n await nativePlugin.optOut({ optOut });\n },\n async getPluginVersion() {\n return nativePlugin.getPluginVersion();\n },\n LogLevel: RudderLogLevel,\n};\nconst RudderStack = RudderClient;\nexport * from './definitions';\nexport { RudderClient, RudderStack };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class RudderStackWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.initialized = false;\n }\n async initialize(options) {\n if (!options.writeKey) {\n throw new Error('writeKey is required');\n }\n this.initialized = true;\n }\n async identify(options) {\n this.ensureInitialized();\n void options;\n }\n async group(options) {\n this.ensureInitialized();\n void options;\n }\n async track(options) {\n this.ensureInitialized();\n void options;\n }\n async screen(options) {\n this.ensureInitialized();\n void options;\n }\n async alias(options) {\n this.ensureInitialized();\n void options;\n }\n async reset() {\n this.ensureInitialized();\n }\n async flush() {\n this.ensureInitialized();\n }\n async putDeviceToken(options) {\n void options.deviceToken;\n }\n async setAdvertisingId(options) {\n await this.putAdvertisingId(options);\n }\n async putAdvertisingId(options) {\n void options.advertisingId;\n }\n async setAnonymousId(options) {\n await this.putAnonymousId(options);\n }\n async putAnonymousId(options) {\n void options.anonymousId;\n }\n async optOut(options) {\n this.ensureInitialized();\n void options.optOut;\n }\n async getPluginVersion() {\n return {\n version: 'web',\n };\n }\n ensureInitialized() {\n if (!this.initialized) {\n throw new Error('RudderStack SDK is not initialized');\n }\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["this","registerPlugin","WebPlugin"],"mappings":";;;IAAA,IAAI,MAAM,GAAG,CAACA,SAAI,IAAIA,SAAI,CAAC,MAAM,KAAK,UAAU,CAAC,EAAE,CAAC,EAAE;IACtD,IAAI,IAAI,CAAC,GAAG,EAAE;IACd,IAAI,KAAK,IAAI,CAAC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GAAG;IAC7B,QAAQ,OAAO;IACf,YAAY,OAAO,EAAE,KAAK;IAC1B,SAAS;IACT,IAAI;IACJ,IAAI,iBAAiB,GAAG;IACxB,QAAQ,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE;IAC/B,YAAY,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC;IACjE,QAAQ;IACR,IAAI;IACJ;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,244 @@
1
+ import Foundation
2
+ import Rudder
3
+
4
+ enum RudderStackBridgeError: LocalizedError {
5
+ case initializationFailed
6
+ case notInitialized
7
+
8
+ var errorDescription: String? {
9
+ switch self {
10
+ case .initializationFailed:
11
+ return "Failed to initialize RudderStack SDK"
12
+ case .notInitialized:
13
+ return "RudderStack SDK is not initialized"
14
+ }
15
+ }
16
+ }
17
+
18
+ final class RudderStackBridge {
19
+ private let pluginVersion = "8.0.0"
20
+ private var initialized = false
21
+
22
+ var version: String {
23
+ pluginVersion
24
+ }
25
+
26
+ func initialize(writeKey: String, config: [String: Any]?, options: [String: Any]?) throws {
27
+ let rudderConfig = buildConfig(writeKey: writeKey, from: config)
28
+ let rudderOptions = buildOptions(from: options)
29
+ let client = RSClient.sharedInstance()
30
+ client.configure(with: rudderConfig)
31
+ if let rudderOptions {
32
+ client.setOption(rudderOptions)
33
+ }
34
+ initialized = true
35
+ }
36
+
37
+ func identify(userId: String, traits: [String: Any]?, options: [String: Any]?) throws {
38
+ let client = try requireClient()
39
+ let option = buildOptions(from: options)
40
+
41
+ if let option, let traits {
42
+ client.identify(userId, traits: traits, option: option)
43
+ } else if let traits {
44
+ client.identify(userId, traits: traits)
45
+ } else if let option {
46
+ client.identify(userId, traits: [:], option: option)
47
+ } else {
48
+ client.identify(userId)
49
+ }
50
+ }
51
+
52
+ func group(groupId: String, groupTraits: [String: Any]?, options: [String: Any]?) throws {
53
+ let client = try requireClient()
54
+ let option = buildOptions(from: options)
55
+ let traits = stringifyMap(groupTraits)
56
+
57
+ if let option, let traits {
58
+ client.group(groupId, traits: traits, option: option)
59
+ } else if let traits {
60
+ client.group(groupId, traits: traits)
61
+ } else if let option {
62
+ client.group(groupId, traits: [:], option: option)
63
+ } else {
64
+ client.group(groupId)
65
+ }
66
+ }
67
+
68
+ func track(eventName: String, properties: [String: Any]?, options: [String: Any]?) throws {
69
+ let client = try requireClient()
70
+ let option = buildOptions(from: options)
71
+
72
+ if let option, let properties {
73
+ client.track(eventName, properties: properties, option: option)
74
+ } else if let properties {
75
+ client.track(eventName, properties: properties)
76
+ } else if let option {
77
+ client.track(eventName, properties: [:], option: option)
78
+ } else {
79
+ client.track(eventName)
80
+ }
81
+ }
82
+
83
+ func screen(screenName: String, properties: [String: Any]?, options: [String: Any]?) throws {
84
+ let client = try requireClient()
85
+ let option = buildOptions(from: options)
86
+
87
+ if let option, let properties {
88
+ client.screen(screenName, category: "", properties: properties, option: option)
89
+ } else if let properties {
90
+ client.screen(screenName, properties: properties)
91
+ } else if let option {
92
+ client.screen(screenName, category: "", properties: [:], option: option)
93
+ } else {
94
+ client.screen(screenName)
95
+ }
96
+ }
97
+
98
+ func alias(newId: String, options: [String: Any]?) throws {
99
+ let client = try requireClient()
100
+ if let option = buildOptions(from: options) {
101
+ client.alias(newId, option: option)
102
+ } else {
103
+ client.alias(newId)
104
+ }
105
+ }
106
+
107
+ func reset() throws {
108
+ try requireClient().reset()
109
+ }
110
+
111
+ func flush() throws {
112
+ try requireClient().flush()
113
+ }
114
+
115
+ func putDeviceToken(_ deviceToken: String) {
116
+ RSClient.sharedInstance().setDeviceToken(deviceToken)
117
+ }
118
+
119
+ func putAdvertisingId(_ advertisingId: String) {
120
+ RSClient.sharedInstance().setAdvertisingId(advertisingId)
121
+ }
122
+
123
+ func putAnonymousId(_ anonymousId: String) {
124
+ RSClient.sharedInstance().setAnonymousId(anonymousId)
125
+ }
126
+
127
+ func optOut(_ optOut: Bool) throws {
128
+ try requireClient().setOptOutStatus(optOut)
129
+ }
130
+
131
+ private func requireClient() throws -> RSClient {
132
+ guard initialized else {
133
+ throw RudderStackBridgeError.notInitialized
134
+ }
135
+ return RSClient.sharedInstance()
136
+ }
137
+
138
+ private func buildConfig(writeKey: String, from config: [String: Any]?) -> RSConfig {
139
+ let configuration = RSConfig(writeKey: writeKey)
140
+
141
+ if let value = string(from: config?["dataPlaneUrl"]) {
142
+ configuration.dataPlaneURL(value)
143
+ }
144
+ if let value = int(from: config?["flushQueueSize"]) {
145
+ configuration.flushQueueSize(value)
146
+ }
147
+ if let value = int(from: config?["dbCountThreshold"]) {
148
+ configuration.dbCountThreshold(value)
149
+ }
150
+ if let value = int(from: config?["sleepTimeOut"]) {
151
+ configuration.sleepTimeOut(value)
152
+ }
153
+ if let value = int(from: config?["logLevel"]), let logLevel = RSLogLevel(rawValue: value) {
154
+ configuration.loglevel(logLevel)
155
+ }
156
+ if let value = bool(from: config?["trackLifecycleEvents"]) {
157
+ configuration.trackLifecycleEvents(value)
158
+ }
159
+ if let value = bool(from: config?["recordScreenViews"]) {
160
+ configuration.recordScreenViews(value)
161
+ }
162
+ if let value = string(from: config?["controlPlaneUrl"]) {
163
+ configuration.controlPlaneURL(value)
164
+ }
165
+
166
+ return configuration
167
+ }
168
+
169
+ private func buildOptions(from options: [String: Any]?) -> RSOption? {
170
+ guard let options else {
171
+ return nil
172
+ }
173
+
174
+ let rudderOption = RSOption()
175
+
176
+ if let externalIds = options["externalIds"] as? [String: Any] {
177
+ for (key, value) in externalIds {
178
+ if let id = string(from: value) {
179
+ rudderOption.putExternalId(key, withId: id)
180
+ }
181
+ }
182
+ }
183
+
184
+ if let integrations = options["integrations"] as? [String: Any] {
185
+ for (key, value) in integrations {
186
+ if let enabled = bool(from: value) {
187
+ rudderOption.putIntegration(key, isEnabled: enabled)
188
+ }
189
+ }
190
+ }
191
+
192
+ return rudderOption
193
+ }
194
+
195
+ private func string(from value: Any?) -> String? {
196
+ switch value {
197
+ case let value as String:
198
+ return value
199
+ case let value as NSNumber:
200
+ return value.stringValue
201
+ default:
202
+ return nil
203
+ }
204
+ }
205
+
206
+ private func int(from value: Any?) -> Int? {
207
+ switch value {
208
+ case let value as NSNumber:
209
+ return value.intValue
210
+ case let value as String:
211
+ return Int(value)
212
+ default:
213
+ return nil
214
+ }
215
+ }
216
+
217
+ private func bool(from value: Any?) -> Bool? {
218
+ switch value {
219
+ case let value as Bool:
220
+ return value
221
+ case let value as NSNumber:
222
+ return value.boolValue
223
+ case let value as String:
224
+ return Bool(value)
225
+ default:
226
+ return nil
227
+ }
228
+ }
229
+
230
+ private func stringifyMap(_ value: [String: Any]?) -> [String: String]? {
231
+ guard let value else {
232
+ return nil
233
+ }
234
+
235
+ var result: [String: String] = [:]
236
+ for (key, rawValue) in value {
237
+ if let stringValue = string(from: rawValue) {
238
+ result[key] = stringValue
239
+ }
240
+ }
241
+
242
+ return result
243
+ }
244
+ }