@kryptos_connect/mobile-sdk 1.0.6-dev.1 → 2.0.1-dev.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs ADDED
@@ -0,0 +1,367 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __defProps = Object.defineProperties;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
+ var __getProtoOf = Object.getPrototypeOf;
10
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
11
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
12
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13
+ var __spreadValues = (a, b) => {
14
+ for (var prop in b || (b = {}))
15
+ if (__hasOwnProp.call(b, prop))
16
+ __defNormalProp(a, prop, b[prop]);
17
+ if (__getOwnPropSymbols)
18
+ for (var prop of __getOwnPropSymbols(b)) {
19
+ if (__propIsEnum.call(b, prop))
20
+ __defNormalProp(a, prop, b[prop]);
21
+ }
22
+ return a;
23
+ };
24
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
25
+ var __export = (target, all) => {
26
+ for (var name in all)
27
+ __defProp(target, name, { get: all[name], enumerable: true });
28
+ };
29
+ var __copyProps = (to, from, except, desc) => {
30
+ if (from && typeof from === "object" || typeof from === "function") {
31
+ for (let key of __getOwnPropNames(from))
32
+ if (!__hasOwnProp.call(to, key) && key !== except)
33
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
34
+ }
35
+ return to;
36
+ };
37
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
38
+ // If the importer is in node compatibility mode or this is not an ESM
39
+ // file that has been converted to a CommonJS file using a Babel-
40
+ // compatible transform (i.e. "__esModule" has not been set), then set
41
+ // "default" to the CommonJS "module.exports" for node compatibility.
42
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
43
+ mod
44
+ ));
45
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
46
+
47
+ // src/index.tsx
48
+ var index_exports = {};
49
+ __export(index_exports, {
50
+ KryptosConnect: () => KryptosConnect,
51
+ KryptosConnectButton: () => KryptosConnectButton,
52
+ KryptosConnectProvider: () => KryptosConnectProvider
53
+ });
54
+ module.exports = __toCommonJS(index_exports);
55
+ var import_react = __toESM(require("react"), 1);
56
+ var import_react_native = require("react-native");
57
+ var import_react_native_webview = require("react-native-webview");
58
+ var _globalConfig = null;
59
+ var KryptosConnect = {
60
+ init(config) {
61
+ _globalConfig = config;
62
+ }
63
+ };
64
+ var DEFAULT_CDN = "http://app-connect.kryptos.io";
65
+ var BUTTON_LABELS = {
66
+ en: {
67
+ connectWith: "Connect with Kryptos",
68
+ connectAccount: "Connect {name} Account",
69
+ connecting: "Connecting..."
70
+ },
71
+ fr: {
72
+ connectWith: "Se connecter avec Kryptos",
73
+ connectAccount: "Connecter le compte {name}",
74
+ connecting: "Connexion..."
75
+ },
76
+ de: {
77
+ connectWith: "Mit Kryptos verbinden",
78
+ connectAccount: "{name}-Konto verbinden",
79
+ connecting: "Verbindung wird hergestellt..."
80
+ },
81
+ pt: {
82
+ connectWith: "Conectar com Kryptos",
83
+ connectAccount: "Conectar conta {name}",
84
+ connecting: "Conectando..."
85
+ },
86
+ sv: {
87
+ connectWith: "Anslut med Kryptos",
88
+ connectAccount: "Anslut {name}-konto",
89
+ connecting: "Ansluter..."
90
+ },
91
+ es: {
92
+ connectWith: "Conectar con Kryptos",
93
+ connectAccount: "Conectar cuenta {name}",
94
+ connecting: "Conectando..."
95
+ },
96
+ pl: {
97
+ connectWith: "Po\u0142\u0105cz z Kryptos",
98
+ connectAccount: "Po\u0142\u0105cz konto {name}",
99
+ connecting: "\u0141\u0105czenie..."
100
+ },
101
+ it: {
102
+ connectWith: "Connetti con Kryptos",
103
+ connectAccount: "Connetti account {name}",
104
+ connecting: "Connessione..."
105
+ }
106
+ };
107
+ function getButtonLabels(language) {
108
+ const lang = language in BUTTON_LABELS ? language : "en";
109
+ return BUTTON_LABELS[lang];
110
+ }
111
+ function b64Encode(str) {
112
+ if (typeof btoa === "function") return btoa(str);
113
+ if (typeof Buffer !== "undefined") return Buffer.from(str).toString("base64");
114
+ return encodeURIComponent(str);
115
+ }
116
+ function getConnectUrl(config, linkToken, integrationName, isAuthorized) {
117
+ var _a, _b;
118
+ const base = (_a = config.cdnBaseUrl) != null ? _a : DEFAULT_CDN;
119
+ const encoded = b64Encode(JSON.stringify(config));
120
+ const origin = encodeURIComponent((_b = config.baseUrl) != null ? _b : "https://kryptos.io");
121
+ let url = `${base}/connect?link_token=${encodeURIComponent(linkToken)}&config=${encodeURIComponent(encoded)}&origin=${origin}`;
122
+ if (integrationName) url += `&integrationName=${encodeURIComponent(integrationName)}`;
123
+ if (isAuthorized) url += `&is_authorized=1`;
124
+ return url;
125
+ }
126
+ var IOS_HIDE_ACCESSORY_JS = `
127
+ (function(){
128
+ function patch(el){
129
+ if((el.tagName==='INPUT'||el.tagName==='TEXTAREA')&&!el.dataset.kcPatched){
130
+ el.setAttribute('inputmode','text');
131
+ el.dataset.kcPatched='1';
132
+ }
133
+ }
134
+ document.querySelectorAll('input,textarea').forEach(patch);
135
+ new MutationObserver(function(ms){
136
+ ms.forEach(function(m){
137
+ m.addedNodes.forEach(function(n){
138
+ if(n.nodeType===1){
139
+ patch(n);
140
+ n.querySelectorAll&&n.querySelectorAll('input,textarea').forEach(patch);
141
+ }
142
+ });
143
+ });
144
+ }).observe(document.body,{childList:true,subtree:true});
145
+ true;
146
+ })();
147
+ `;
148
+ function KryptosConnectButton({
149
+ config: configProp,
150
+ generateLinkToken,
151
+ onConnectSuccess,
152
+ onConnectError,
153
+ buttonLabel,
154
+ buttonHeight = 56,
155
+ integrationName,
156
+ extraConfig,
157
+ style
158
+ }) {
159
+ var _a, _b, _c, _d;
160
+ const config = configProp != null ? configProp : _globalConfig;
161
+ const mergedConfig = config && extraConfig ? __spreadValues(__spreadValues({}, config), extraConfig) : config;
162
+ const labels = getButtonLabels(config == null ? void 0 : config.language);
163
+ const resolvedLabel = buttonLabel != null ? buttonLabel : integrationName ? labels.connectAccount.replace(
164
+ "{name}",
165
+ integrationName.charAt(0).toUpperCase() + integrationName.slice(1)
166
+ ) : labels.connectWith;
167
+ const webViewRef = (0, import_react.useRef)(null);
168
+ const [modalVisible, setModalVisible] = (0, import_react.useState)(false);
169
+ const [loading, setLoading] = (0, import_react.useState)(false);
170
+ const [connectUrl, setConnectUrl] = (0, import_react.useState)(null);
171
+ const [webViewReady, setWebViewReady] = (0, import_react.useState)(false);
172
+ const isDark = (config == null ? void 0 : config.theme) === "dark";
173
+ const loaderBg = isDark ? "#0f0f0f" : "#ffffff";
174
+ const btnBg = (_b = (_a = mergedConfig == null ? void 0 : mergedConfig.cssVars) == null ? void 0 : _a["--kc-primary"]) != null ? _b : "#00c693";
175
+ const btnText = (_d = (_c = mergedConfig == null ? void 0 : mergedConfig.cssVars) == null ? void 0 : _c["--kc-primary-text"]) != null ? _d : "#ffffff";
176
+ async function handlePress() {
177
+ if (!mergedConfig) {
178
+ onConnectError(
179
+ new Error("No config provided. Call KryptosConnect.init() or pass a config prop.")
180
+ );
181
+ return;
182
+ }
183
+ setLoading(true);
184
+ try {
185
+ const result = await generateLinkToken();
186
+ if (!(result == null ? void 0 : result.link_token)) {
187
+ onConnectError(new Error("Failed to generate link token"));
188
+ return;
189
+ }
190
+ const url = getConnectUrl(
191
+ mergedConfig,
192
+ result.link_token,
193
+ integrationName,
194
+ result.isAuthorized
195
+ );
196
+ console.log("[Kryptos] connect URL:", url);
197
+ setConnectUrl(url);
198
+ setWebViewReady(false);
199
+ setModalVisible(true);
200
+ } catch (err) {
201
+ onConnectError(
202
+ new Error(err instanceof Error ? err.message : "Failed to generate link token")
203
+ );
204
+ } finally {
205
+ setLoading(false);
206
+ }
207
+ }
208
+ function handleClose() {
209
+ setModalVisible(false);
210
+ setConnectUrl(null);
211
+ setWebViewReady(false);
212
+ }
213
+ const handleMessage = (0, import_react.useCallback)(
214
+ (event) => {
215
+ var _a2, _b2;
216
+ let data;
217
+ try {
218
+ data = JSON.parse(event.nativeEvent.data);
219
+ } catch (e) {
220
+ return;
221
+ }
222
+ if (!data.kryptos) return;
223
+ switch (data.type) {
224
+ case "success":
225
+ handleClose();
226
+ onConnectSuccess(data.payload);
227
+ break;
228
+ case "error":
229
+ handleClose();
230
+ onConnectError(
231
+ new Error((_b2 = (_a2 = data.payload) == null ? void 0 : _a2.message) != null ? _b2 : "Connect failed")
232
+ );
233
+ break;
234
+ case "close":
235
+ handleClose();
236
+ onConnectError(new Error("Connection closed"));
237
+ break;
238
+ case "openUrl": {
239
+ const url = data.payload.url;
240
+ import_react_native.Linking.openURL(url).catch(
241
+ (err) => console.warn("[Kryptos] openUrl failed:", err)
242
+ );
243
+ break;
244
+ }
245
+ // The connect page may ask for a fresh token if the pre-fetched one expired
246
+ case "GENERATE_LINK_TOKEN":
247
+ generateLinkToken().then((result) => {
248
+ var _a3;
249
+ (_a3 = webViewRef.current) == null ? void 0 : _a3.injectJavaScript(
250
+ `(function(){
251
+ var e = new MessageEvent('message', { data: ${JSON.stringify(JSON.stringify({ type: "LINK_TOKEN_RESPONSE", payload: result }))} });
252
+ window.dispatchEvent(e);
253
+ document.dispatchEvent(e);
254
+ })()`
255
+ );
256
+ }).catch((err) => {
257
+ var _a3, _b3;
258
+ (_b3 = webViewRef.current) == null ? void 0 : _b3.injectJavaScript(
259
+ `(function(){
260
+ var e = new MessageEvent('message', { data: ${JSON.stringify(JSON.stringify({ type: "LINK_TOKEN_RESPONSE", payload: { error: (_a3 = err == null ? void 0 : err.message) != null ? _a3 : "error" } }))} });
261
+ window.dispatchEvent(e);
262
+ document.dispatchEvent(e);
263
+ })()`
264
+ );
265
+ });
266
+ break;
267
+ }
268
+ },
269
+ [generateLinkToken, onConnectSuccess, onConnectError]
270
+ );
271
+ return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(
272
+ import_react_native.TouchableOpacity,
273
+ {
274
+ onPress: handlePress,
275
+ disabled: loading,
276
+ style: [styles.nativeButton, { height: buttonHeight, backgroundColor: btnBg }, style],
277
+ activeOpacity: 0.85
278
+ },
279
+ loading ? /* @__PURE__ */ import_react.default.createElement(import_react_native.Text, { style: [styles.nativeButtonText, { color: btnText }] }, labels.connecting) : /* @__PURE__ */ import_react.default.createElement(import_react_native.Text, { style: [styles.nativeButtonText, { color: btnText }] }, resolvedLabel)
280
+ ), /* @__PURE__ */ import_react.default.createElement(
281
+ import_react_native.Modal,
282
+ {
283
+ visible: modalVisible,
284
+ animationType: "none",
285
+ transparent: true,
286
+ onRequestClose: handleClose,
287
+ statusBarTranslucent: true
288
+ },
289
+ /* @__PURE__ */ import_react.default.createElement(import_react_native.View, { style: styles.sheet }, (!webViewReady || !connectUrl) && /* @__PURE__ */ import_react.default.createElement(import_react_native.View, { style: [styles.loader, { backgroundColor: loaderBg }] }, /* @__PURE__ */ import_react.default.createElement(import_react_native.ActivityIndicator, { color: "#00c693", size: "large" })), connectUrl && /* @__PURE__ */ import_react.default.createElement(
290
+ import_react_native_webview.WebView,
291
+ {
292
+ ref: webViewRef,
293
+ source: { uri: connectUrl },
294
+ onMessage: handleMessage,
295
+ onLoadEnd: () => setWebViewReady(true),
296
+ onError: (e) => {
297
+ console.log("[WebView onError]", e.nativeEvent);
298
+ handleClose();
299
+ onConnectError(new Error("Failed to load connect page"));
300
+ },
301
+ javaScriptEnabled: true,
302
+ domStorageEnabled: true,
303
+ originWhitelist: ["*"],
304
+ style: [styles.webview, !webViewReady && styles.hidden],
305
+ pointerEvents: webViewReady ? "auto" : "none",
306
+ setSupportMultipleWindows: false,
307
+ allowsInlineMediaPlayback: true,
308
+ mediaPlaybackRequiresUserAction: false,
309
+ automaticallyAdjustContentInsets: false,
310
+ automaticallyAdjustsScrollIndicatorInsets: false,
311
+ contentInsetAdjustmentBehavior: "never",
312
+ keyboardDisplayRequiresUserAction: false,
313
+ injectedJavaScript: import_react_native.Platform.OS === "ios" ? IOS_HIDE_ACCESSORY_JS : void 0,
314
+ backgroundColor: "transparent"
315
+ }
316
+ ))
317
+ ));
318
+ }
319
+ function KryptosConnectProvider({ children, style }) {
320
+ return /* @__PURE__ */ import_react.default.createElement(import_react_native.View, { style: [styles.providerContainer, style] }, children);
321
+ }
322
+ var styles = import_react_native.StyleSheet.create({
323
+ nativeButton: {
324
+ width: "100%",
325
+ borderRadius: 8,
326
+ backgroundColor: "#00c693",
327
+ alignItems: "center",
328
+ justifyContent: "center"
329
+ },
330
+ nativeButtonText: {
331
+ color: "#ffffff",
332
+ fontSize: 16,
333
+ fontWeight: "600"
334
+ },
335
+ sheet: {
336
+ position: "absolute",
337
+ bottom: 0,
338
+ left: 0,
339
+ right: 0,
340
+ top: 0,
341
+ backgroundColor: "transparent",
342
+ overflow: "hidden"
343
+ },
344
+ webview: {
345
+ flex: 1
346
+ },
347
+ loader: __spreadProps(__spreadValues({}, import_react_native.StyleSheet.absoluteFillObject), {
348
+ alignItems: "center",
349
+ justifyContent: "center",
350
+ zIndex: 1
351
+ }),
352
+ providerContainer: {
353
+ flex: 1
354
+ },
355
+ hidden: {
356
+ opacity: 0,
357
+ position: "absolute",
358
+ width: 0,
359
+ height: 0
360
+ }
361
+ });
362
+ // Annotate the CommonJS export names for ESM import in node:
363
+ 0 && (module.exports = {
364
+ KryptosConnect,
365
+ KryptosConnectButton,
366
+ KryptosConnectProvider
367
+ });
@@ -0,0 +1,44 @@
1
+ import type { StyleProp } from "react-native";
2
+ import type { ViewStyle } from "react-native";
3
+
4
+ export interface KryptosConfig {
5
+ appName: string;
6
+ appLogo?: string;
7
+ theme?: "light" | "dark" | "auto";
8
+ clientId?: string;
9
+ walletConnectProjectId?: string;
10
+ baseUrl?: string;
11
+ cdnBaseUrl?: string;
12
+ cssVars?: Record<string, string>;
13
+ [key: string]: unknown;
14
+ }
15
+
16
+ export type UserConsent = {
17
+ public_token: string;
18
+ [key: string]: unknown;
19
+ };
20
+
21
+ export interface KryptosConnectButtonProps {
22
+ config?: KryptosConfig;
23
+ generateLinkToken: () => Promise<{ link_token: string; isAuthorized?: boolean }>;
24
+ onConnectSuccess: (data: UserConsent | null) => void;
25
+ onConnectError: (error: Error) => void;
26
+ buttonLabel?: string;
27
+ buttonHeight?: number;
28
+ integrationName?: string;
29
+ extraConfig?: Record<string, unknown>;
30
+ style?: StyleProp<ViewStyle>;
31
+ }
32
+
33
+ export interface KryptosConnectProviderProps {
34
+ config?: KryptosConfig;
35
+ children: React.ReactNode;
36
+ style?: StyleProp<ViewStyle>;
37
+ }
38
+
39
+ export declare const KryptosConnect: {
40
+ init(config: KryptosConfig): void;
41
+ };
42
+
43
+ export declare function KryptosConnectButton(props: KryptosConnectButtonProps): JSX.Element;
44
+ export declare function KryptosConnectProvider(props: KryptosConnectProviderProps): JSX.Element;
package/dist/index.d.ts CHANGED
@@ -1,80 +1,44 @@
1
- import React, { ReactNode } from 'react';
2
- import { ImageSourcePropType } from 'react-native';
1
+ import type { StyleProp } from "react-native";
2
+ import type { ViewStyle } from "react-native";
3
3
 
4
- type KryptosConfig = {
5
- appName: string;
6
- appLogo?: ReactNode | string | ImageSourcePropType;
7
- theme?: "light" | "dark";
8
- clientId: string;
9
- walletConnectProjectId?: string;
10
- baseUrl?: string;
11
- };
12
- type ClientInfo = {
13
- name: string;
14
- description: string | null;
15
- scopes: string;
16
- project_stage: string;
17
- };
18
- type KryptosUser = {
19
- is_anonymous: boolean;
20
- user: {
21
- email: string | null;
22
- first_name: string | null;
23
- };
24
- user_id: string;
25
- workspace_id: string;
26
- workspace_name: string;
27
- };
28
- type UserConsent = {
29
- public_token: string;
4
+ export interface KryptosConfig {
5
+ appName: string;
6
+ appLogo?: string;
7
+ theme?: "light" | "dark" | "auto";
8
+ clientId?: string;
9
+ walletConnectProjectId?: string;
10
+ baseUrl?: string;
11
+ cdnBaseUrl?: string;
12
+ cssVars?: Record<string, string>;
13
+ [key: string]: unknown;
14
+ }
15
+
16
+ export type UserConsent = {
17
+ public_token: string;
18
+ [key: string]: unknown;
30
19
  };
31
- interface KryptosConnectButtonProps {
32
- onSuccess?: (userConsent: UserConsent | null) => void;
33
- onError?: () => void;
34
- generateLinkToken: () => Promise<{
35
- link_token: string;
36
- isAuthorized?: boolean;
37
- }>;
38
- children?: ReactNode;
39
- style?: object;
40
- buttonStyle?: object;
41
- integrationName?: string;
42
- textStyle?: object;
20
+
21
+ export interface KryptosConnectButtonProps {
22
+ config?: KryptosConfig;
23
+ generateLinkToken: () => Promise<{ link_token: string; isAuthorized?: boolean }>;
24
+ onConnectSuccess: (data: UserConsent | null) => void;
25
+ onConnectError: (error: Error) => void;
26
+ buttonLabel?: string;
27
+ buttonHeight?: number;
28
+ integrationName?: string;
29
+ extraConfig?: Record<string, unknown>;
30
+ style?: StyleProp<ViewStyle>;
43
31
  }
44
32
 
45
- declare const KryptosConnectButton: React.FC<KryptosConnectButtonProps>;
46
- interface KryptosConnectModalProps {
47
- open: boolean;
48
- setOpen: (open: boolean) => void;
49
- onSuccess?: (userConsent: UserConsent | null) => void;
50
- onError?: (error?: any) => void;
51
- generateLinkToken: () => Promise<{
52
- link_token: string;
53
- isAuthorized?: boolean;
54
- }>;
55
- integrationName?: string;
33
+ export interface KryptosConnectProviderProps {
34
+ config?: KryptosConfig;
35
+ children: React.ReactNode;
36
+ style?: StyleProp<ViewStyle>;
56
37
  }
57
- declare const KryptosConnectModal: React.FC<KryptosConnectModalProps>;
58
38
 
59
- type KryptosContextType = KryptosConfig & {
60
- isInitialized: boolean;
61
- setIsInitialized: (value: boolean) => void;
62
- linkToken: string;
63
- setLinkToken: (value: string) => void;
64
- user: KryptosUser | null;
65
- setUser: (value: KryptosUser | null) => void;
66
- email: string;
67
- setEmail: (value: string) => void;
68
- userConsent: UserConsent | null;
69
- setUserConsent: (value: UserConsent | null) => void;
70
- clientInfo: ClientInfo | null;
71
- isAuthorized: boolean;
72
- setIsAuthorized: (value: boolean) => void;
39
+ export declare const KryptosConnect: {
40
+ init(config: KryptosConfig): void;
73
41
  };
74
- declare const KryptosConnectProvider: React.FC<{
75
- children: React.ReactNode;
76
- config: KryptosConfig;
77
- }>;
78
- declare const useKryptosConnect: () => KryptosContextType;
79
42
 
80
- export { KryptosConnectButton, type KryptosConnectButtonProps, KryptosConnectModal, KryptosConnectProvider, useKryptosConnect };
43
+ export declare function KryptosConnectButton(props: KryptosConnectButtonProps): JSX.Element;
44
+ export declare function KryptosConnectProvider(props: KryptosConnectProviderProps): JSX.Element;