@teamvortexsoftware/vortex-react-native 0.0.8 → 0.0.10

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.
Files changed (42) hide show
  1. package/dist/components/ShareButtons.js +170 -0
  2. package/dist/hooks/useThemeStyles.js +39 -0
  3. package/dist/hooks/useVortexInvite.js +281 -0
  4. package/dist/index.js +5 -0
  5. package/dist/shared/InvitationResult.js +2 -0
  6. package/dist/shared/api.js +90 -0
  7. package/dist/tests/TestVortexInvite.js +134 -0
  8. package/dist/types/components/ShareButtons.d.ts +27 -0
  9. package/dist/types/components/ShareButtons.d.ts.map +1 -0
  10. package/dist/types/hooks/useThemeStyles.d.ts +34 -0
  11. package/dist/types/hooks/useThemeStyles.d.ts.map +1 -0
  12. package/dist/types/hooks/useVortexInvite.d.ts +41 -0
  13. package/dist/types/hooks/useVortexInvite.d.ts.map +1 -0
  14. package/dist/types/index.d.ts +2 -0
  15. package/dist/types/index.d.ts.map +1 -0
  16. package/dist/types/shared/InvitationResult.d.ts +24 -0
  17. package/dist/types/shared/InvitationResult.d.ts.map +1 -0
  18. package/dist/types/shared/api.d.ts +14 -0
  19. package/dist/types/shared/api.d.ts.map +1 -0
  20. package/dist/types/tests/TestVortexInvite.d.ts +4 -0
  21. package/dist/types/tests/TestVortexInvite.d.ts.map +1 -0
  22. package/dist/types/utils/formUtils.d.ts +85 -0
  23. package/dist/types/utils/formUtils.d.ts.map +1 -0
  24. package/dist/types/utils/themeUtils.d.ts +35 -0
  25. package/dist/types/utils/themeUtils.d.ts.map +1 -0
  26. package/dist/types/vortexInvite.d.ts +25 -0
  27. package/dist/types/vortexInvite.d.ts.map +1 -0
  28. package/dist/utils/formUtils.js +174 -0
  29. package/dist/utils/themeUtils.js +55 -0
  30. package/dist/vortexInvite.js +172 -0
  31. package/package.json +6 -4
  32. package/eslint.config.mjs +0 -4
  33. package/plugin/withVortexReactNative.js +0 -41
  34. package/plugin.js +0 -2
  35. package/src/components/ShareButtons.tsx +0 -172
  36. package/src/hooks/useThemeStyles.ts +0 -42
  37. package/src/hooks/useVortexInvite.ts +0 -278
  38. package/src/index.tsx +0 -2
  39. package/src/shared/api.ts +0 -67
  40. package/src/utils/themeUtils.ts +0 -85
  41. package/src/vortexInvite.tsx +0 -188
  42. package/tsconfig.json +0 -16
@@ -0,0 +1,170 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.ShareButton = ShareButton;
40
+ exports.ShareButtons = ShareButtons;
41
+ const react_1 = __importStar(require("react"));
42
+ const react_native_1 = require("react-native");
43
+ const FontAwesome6_1 = __importDefault(require("react-native-vector-icons/FontAwesome6"));
44
+ const react_native_qrcode_svg_1 = __importDefault(require("react-native-qrcode-svg"));
45
+ function ShareButton({ iconName, label, onPress, themeColors, themeStyles }) {
46
+ return (<react_native_1.View style={styles.shareButtonWrapper}>
47
+ <react_native_1.Pressable style={[styles.shareButton, themeStyles.secondaryButton]} onPress={onPress}>
48
+ <react_native_1.View style={styles.buttonContentContainer}>
49
+ <FontAwesome6_1.default name={iconName} size={24} color={themeColors.secondaryButtonForeground}/>
50
+ <react_native_1.Text style={[styles.shareButtonText, themeStyles.secondaryButtonText]}>{label}</react_native_1.Text>
51
+ </react_native_1.View>
52
+ </react_native_1.Pressable>
53
+ </react_native_1.View>);
54
+ }
55
+ function ShareButtons({ has, themeColors, themeStyles, handleShareLink, handleCopyLink, shareableLink, }) {
56
+ const [showQRCode, setShowQRCode] = (0, react_1.useState)(false);
57
+ // Define button configurations
58
+ const buttonConfigs = [
59
+ {
60
+ key: 'shareOptionsNativeShareSheet',
61
+ iconName: 'share-nodes',
62
+ label: 'Native Share',
63
+ onPress: handleShareLink,
64
+ isAvailable: has.shareOptionsNativeShareSheet,
65
+ },
66
+ {
67
+ key: 'shareOptionsCopyLink',
68
+ iconName: 'copy',
69
+ label: 'Copy',
70
+ onPress: handleCopyLink,
71
+ isAvailable: true, // Always available when share is enabled
72
+ isWithShowUrl: has.shareOptionsCopyLink, // Special handling only if specifically enabled
73
+ },
74
+ {
75
+ key: 'shareOptionsQRCode',
76
+ iconName: 'qrcode',
77
+ label: 'QR Code',
78
+ onPress: () => setShowQRCode(!showQRCode),
79
+ isAvailable: has.shareOptionsQrCode,
80
+ },
81
+ {
82
+ key: 'shareOptionsWhatsApp',
83
+ iconName: 'whatsapp',
84
+ label: 'WhatsApp',
85
+ onPress: () => { },
86
+ isAvailable: has.shareOptionsWhatsApp,
87
+ },
88
+ {
89
+ key: 'shareOptionsSms',
90
+ iconName: 'message',
91
+ label: 'SMS',
92
+ onPress: () => { },
93
+ isAvailable: has.shareOptionsSms,
94
+ },
95
+ // Add more share options as needed
96
+ // Example:
97
+ // {
98
+ // key: 'shareOptionsFacebookMessenger',
99
+ // iconName: 'facebook-messenger',
100
+ // label: 'Messenger',
101
+ // onPress: () => {},
102
+ // isAvailable: has.shareOptionsFacebookMessenger,
103
+ // },
104
+ ];
105
+ return (<>
106
+ {showQRCode && shareableLink && (<react_native_1.View style={styles.qrCodeContainer}>
107
+ <react_native_qrcode_svg_1.default value={shareableLink} size={200} color={themeColors.containerForeground} backgroundColor={themeColors.containerBackground}/>
108
+ </react_native_1.View>)}
109
+ {buttonConfigs
110
+ .filter((config) => config.isAvailable)
111
+ .map((config) => config.isWithShowUrl && config.key === 'shareOptionsCopyLink' && shareableLink ? (<react_native_1.View key={config.key} style={styles.copyLinkContainer}>
112
+ <react_native_1.TextInput style={[
113
+ styles.linkInput,
114
+ { color: themeColors.containerForeground, borderColor: themeColors.containerBorder },
115
+ ]} value={shareableLink} editable={false}/>
116
+ <react_native_1.Pressable style={[styles.copyButton, themeStyles.secondaryButton]} onPress={handleCopyLink}>
117
+ <FontAwesome6_1.default name="copy" size={20} color={themeColors.secondaryButtonForeground}/>
118
+ </react_native_1.Pressable>
119
+ </react_native_1.View>) : (<ShareButton key={config.key} iconName={config.iconName} label={config.label} onPress={config.onPress} themeColors={themeColors} themeStyles={themeStyles}/>))}
120
+ </>);
121
+ }
122
+ const styles = react_native_1.StyleSheet.create({
123
+ shareButtonWrapper: {
124
+ width: '48%',
125
+ margin: 5,
126
+ },
127
+ shareButton: {
128
+ flexDirection: 'row',
129
+ alignItems: 'center',
130
+ padding: 10,
131
+ borderWidth: 1,
132
+ borderRadius: 5,
133
+ justifyContent: 'center',
134
+ },
135
+ buttonContentContainer: {
136
+ flexDirection: 'row',
137
+ alignItems: 'center',
138
+ },
139
+ shareButtonText: {
140
+ marginLeft: 10,
141
+ },
142
+ qrCodeContainer: {
143
+ width: '100%',
144
+ alignItems: 'center',
145
+ justifyContent: 'center',
146
+ marginBottom: 20,
147
+ padding: 10,
148
+ },
149
+ copyLinkContainer: {
150
+ width: '100%',
151
+ flexDirection: 'row',
152
+ marginVertical: 5,
153
+ alignItems: 'center',
154
+ },
155
+ linkInput: {
156
+ flex: 1,
157
+ borderWidth: 1,
158
+ borderRadius: 5,
159
+ padding: 10,
160
+ marginRight: 5,
161
+ },
162
+ copyButton: {
163
+ width: 44,
164
+ height: 44,
165
+ alignItems: 'center',
166
+ justifyContent: 'center',
167
+ borderWidth: 1,
168
+ borderRadius: 5,
169
+ },
170
+ });
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useThemeStyles = useThemeStyles;
4
+ const react_1 = require("react");
5
+ /**
6
+ * Hook to generate dynamic styles based on theme colors
7
+ * @param themeColors The theme colors object
8
+ * @returns Object containing styled components based on the theme
9
+ */
10
+ function useThemeStyles(themeColors) {
11
+ const themeStyles = (0, react_1.useMemo)(() => ({
12
+ primaryButton: {
13
+ backgroundColor: themeColors.primaryButtonBackground,
14
+ borderColor: themeColors.primaryButtonBorder,
15
+ },
16
+ primaryButtonText: {
17
+ color: themeColors.primaryButtonForeground,
18
+ },
19
+ secondaryButton: {
20
+ backgroundColor: themeColors.secondaryButtonBackground,
21
+ borderColor: themeColors.secondaryButtonBorder,
22
+ },
23
+ secondaryButtonText: {
24
+ color: themeColors.secondaryButtonForeground,
25
+ },
26
+ containerStyles: {
27
+ backgroundColor: themeColors.containerBackground,
28
+ },
29
+ textStyles: {
30
+ color: themeColors.containerForeground,
31
+ },
32
+ inputStyles: {
33
+ borderColor: themeColors.containerBorder,
34
+ color: themeColors.containerForeground,
35
+ backgroundColor: themeColors.containerBackground,
36
+ },
37
+ }), [themeColors]);
38
+ return themeStyles;
39
+ }
@@ -0,0 +1,281 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.useVortexInvite = useVortexInvite;
16
+ const react_1 = require("react");
17
+ const react_native_1 = require("react-native");
18
+ const api_1 = __importDefault(require("../shared/api"));
19
+ const themeUtils_1 = require("../utils/themeUtils");
20
+ const useThemeStyles_1 = require("./useThemeStyles");
21
+ const expo_standard_web_crypto_1 = require("expo-standard-web-crypto");
22
+ const uuid_1 = require("uuid");
23
+ const formUtils_1 = require("../utils/formUtils");
24
+ (0, expo_standard_web_crypto_1.polyfillWebCrypto)();
25
+ function useVortexInvite({ widgetId, environmentId, vortexApiHost, isLoading = false, jwt, onSuccess, onError, }) {
26
+ const vortexClient = (0, react_1.useMemo)(() => new api_1.default(vortexApiHost, (0, uuid_1.v4)()), [vortexApiHost]);
27
+ const [widgetConfiguration, setWidgetConfiguration] = (0, react_1.useState)();
28
+ const [error, setError] = (0, react_1.useState)(null);
29
+ const [fetching, setFetching] = (0, react_1.useState)(isLoading);
30
+ const [loading, setLoading] = (0, react_1.useState)(true);
31
+ const [email, setEmail] = (0, react_1.useState)('');
32
+ const [shareableLink, setShareableLink] = (0, react_1.useState)();
33
+ const [inviteLoading, setInviteLoading] = (0, react_1.useState)(false);
34
+ const [showSuccessMessage, setShowSuccessMessage] = (0, react_1.useState)(false);
35
+ const opacity = new react_native_1.Animated.Value(0.3);
36
+ // Extract theme colors and feature flags using utility functions
37
+ const themeColors = (0, react_1.useMemo)(() => (0, themeUtils_1.extractThemeColors)(widgetConfiguration), [widgetConfiguration]);
38
+ // Extract form configuration
39
+ const formConfig = (0, react_1.useMemo)(() => (0, formUtils_1.extractFormConfiguration)(widgetConfiguration), [widgetConfiguration]);
40
+ // Get base theme styles
41
+ const baseThemeStyles = (0, useThemeStyles_1.useThemeStyles)(themeColors);
42
+ // Merge theme styles with component-specific styles from form configuration
43
+ const themeStyles = (0, react_1.useMemo)(() => (0, formUtils_1.mergeThemeAndComponentStyles)(baseThemeStyles, themeColors, formConfig), [baseThemeStyles, themeColors, formConfig]);
44
+ const options = (0, react_1.useMemo)(() => {
45
+ var _a;
46
+ return ((_a = widgetConfiguration === null || widgetConfiguration === void 0 ? void 0 : widgetConfiguration.configuration) === null || _a === void 0 ? void 0 : _a.props) || {};
47
+ }, [widgetConfiguration]);
48
+ // Extract form layout information
49
+ const formLayout = (0, react_1.useMemo)(() => ({
50
+ emailPlaceholder: (0, formUtils_1.getEmailPlaceholder)(formConfig),
51
+ submitButtonLabel: (0, formUtils_1.getSubmitButtonLabel)(formConfig),
52
+ isGridLayout: (0, formUtils_1.hasGridLayout)(formConfig),
53
+ hasSeparateColumns: (0, formUtils_1.hasEmailAndShareInSeparateColumns)(formConfig),
54
+ formConfig,
55
+ }), [formConfig]);
56
+ const has = (0, react_1.useMemo)(() => {
57
+ const flags = (0, themeUtils_1.extractFeatureFlags)(widgetConfiguration);
58
+ console.log('[Vortex] Invite has', flags);
59
+ return flags;
60
+ }, [widgetConfiguration]);
61
+ // Log the host only once when the hook mounts
62
+ (0, react_1.useEffect)(() => {
63
+ if (vortexApiHost.indexOf('localhost') > -1) {
64
+ console.warn('[Vortex] Invite Using localhost as host');
65
+ }
66
+ }, [vortexApiHost]);
67
+ // Loading animation effect
68
+ (0, react_1.useEffect)(() => {
69
+ const animation = react_native_1.Animated.loop(react_native_1.Animated.sequence([
70
+ react_native_1.Animated.timing(opacity, {
71
+ toValue: 1,
72
+ duration: 1000,
73
+ useNativeDriver: false,
74
+ }),
75
+ react_native_1.Animated.timing(opacity, {
76
+ toValue: 0.3,
77
+ duration: 1000,
78
+ useNativeDriver: false,
79
+ }),
80
+ ]));
81
+ animation.start();
82
+ setTimeout(() => {
83
+ setLoading(false);
84
+ animation.stop();
85
+ }, 2000);
86
+ }, [opacity]);
87
+ // Fetch widget configuration if needed
88
+ (0, react_1.useEffect)(() => {
89
+ // Case: If `widgetConfiguration` is already set, do nothing
90
+ if (widgetConfiguration) {
91
+ console.log('[Vortex] Invite Already has widgetConfiguration, skipping fetch');
92
+ return;
93
+ }
94
+ if (!jwt) {
95
+ console.log('[Vortex] Invite JWT is required');
96
+ return;
97
+ }
98
+ const fetchData = () => __awaiter(this, void 0, void 0, function* () {
99
+ var _a;
100
+ console.log('[Vortex] Invite Fetching Data...');
101
+ setFetching(true);
102
+ setLoading(true);
103
+ setError(null);
104
+ try {
105
+ const result = yield vortexClient.getWidgetConfiguration(widgetId, jwt, environmentId);
106
+ if ((_a = result === null || result === void 0 ? void 0 : result.data) === null || _a === void 0 ? void 0 : _a.widgetConfiguration) {
107
+ setWidgetConfiguration(result.data.widgetConfiguration);
108
+ console.log('[Vortex] Invite Successfully fetched widgetConfiguration', JSON.stringify(result.data.widgetConfiguration));
109
+ }
110
+ else {
111
+ const error = (result === null || result === void 0 ? void 0 : result.error) || 'No configuration data found.';
112
+ console.error(`[Vortex] Invite ${error}`);
113
+ throw new Error(error);
114
+ }
115
+ }
116
+ catch (err) {
117
+ if (err instanceof Error) {
118
+ const fetchError = err;
119
+ console.error('[Vortex] Invite Error Details:', {
120
+ message: fetchError.message,
121
+ status: fetchError.status || 'unknown',
122
+ statusText: fetchError.statusText,
123
+ body: fetchError.body,
124
+ stack: fetchError.stack,
125
+ });
126
+ }
127
+ console.error('[Vortex] Invite Error', err);
128
+ setError({
129
+ message: err.message || 'Something went wrong!',
130
+ });
131
+ }
132
+ finally {
133
+ setFetching(false);
134
+ setLoading(false);
135
+ }
136
+ });
137
+ fetchData();
138
+ }, [widgetId, jwt, environmentId, vortexClient, widgetConfiguration]);
139
+ const handleInviteClick = (contentTokens) => __awaiter(this, void 0, void 0, function* () {
140
+ try {
141
+ setInviteLoading(true);
142
+ setShowSuccessMessage(false);
143
+ if (!(widgetConfiguration === null || widgetConfiguration === void 0 ? void 0 : widgetConfiguration.id)) {
144
+ console.log('[Vortex Invite] Widget configuration ID is required');
145
+ return;
146
+ }
147
+ // const url = `${host}/api/v1/no-auth/components/widget-configuration/${widgetConfigurationId}/invite`; // TODO should we use options.widgetHost?.value ?
148
+ console.log('[Vortex] Invite Sending invitation', {
149
+ email,
150
+ widgetId,
151
+ environmentId,
152
+ });
153
+ if (!jwt) {
154
+ throw new Error('[Vortex Invite] JWT is required');
155
+ }
156
+ const payload = Object.assign(Object.assign({}, contentTokens), { email: {
157
+ value: email,
158
+ type: 'email',
159
+ } });
160
+ const body = yield vortexClient.createInvite(jwt, widgetConfiguration === null || widgetConfiguration === void 0 ? void 0 : widgetConfiguration.id, environmentId, payload);
161
+ console.log('[Vortex] Invite Response', body);
162
+ if (onSuccess) {
163
+ onSuccess({
164
+ type: 'invite',
165
+ data: 'Email invite sent',
166
+ });
167
+ }
168
+ setShowSuccessMessage(true);
169
+ // Auto-hide success message after 5 seconds
170
+ setTimeout(() => {
171
+ setShowSuccessMessage(false);
172
+ }, 5000);
173
+ return;
174
+ }
175
+ catch (error) {
176
+ console.error('[Vortex]', error);
177
+ if (onError) {
178
+ onError(error instanceof Error ? error : new Error(String(error)), 'invite');
179
+ }
180
+ throw error; // Re-throw the error to be caught by the component
181
+ }
182
+ finally {
183
+ setInviteLoading(false);
184
+ }
185
+ });
186
+ const getShareableLink = () => {
187
+ return vortexClient.getShareableLinkFormatted();
188
+ };
189
+ const getShareableInviteLink = () => __awaiter(this, void 0, void 0, function* () {
190
+ // if (this.isLoading || !this.vortex) {
191
+ // return;
192
+ // }
193
+ if (!jwt || !(widgetConfiguration === null || widgetConfiguration === void 0 ? void 0 : widgetConfiguration.id) || !vortexClient) {
194
+ return;
195
+ }
196
+ if (shareableLink) {
197
+ return shareableLink;
198
+ }
199
+ const invite = yield vortexClient.createShareableInvite(jwt, widgetConfiguration.id, environmentId);
200
+ if (!invite || !invite.data || !invite.data.invitation.id) {
201
+ console.error('No shareable link found');
202
+ onError === null || onError === void 0 ? void 0 : onError(new Error('No shareable link found'), 'share');
203
+ // this.error = {
204
+ // message: 'No sharable link found',
205
+ // };
206
+ // this.host.requestUpdate();
207
+ return;
208
+ }
209
+ const link = `${vortexApiHost}/noauth/invite/${invite.data.invitation.id}`;
210
+ console.log(`getShareableInviteLink: ${link}`);
211
+ setShareableLink(link); // TODO - need to differentiate invite host vs api host even though they are the same for now)
212
+ return link;
213
+ });
214
+ const handleShareLink = () => __awaiter(this, void 0, void 0, function* () {
215
+ try {
216
+ const shareableLink = yield getShareableInviteLink();
217
+ if (!shareableLink) {
218
+ throw new Error('No shareable link available');
219
+ }
220
+ yield react_native_1.Share.share({
221
+ message: shareableLink,
222
+ title: 'Share Invite Link',
223
+ });
224
+ console.log('[Vortex] handleShareLink', 'The invite link has been shared.');
225
+ if (onSuccess) {
226
+ onSuccess({
227
+ type: 'share',
228
+ data: 'Sharable link used',
229
+ });
230
+ }
231
+ }
232
+ catch (error) {
233
+ console.error('[Vortex] Failed to share link:', error);
234
+ if (onError) {
235
+ onError(error instanceof Error ? error : new Error(String(error)), 'share');
236
+ }
237
+ }
238
+ });
239
+ const handleCopyLink = () => __awaiter(this, void 0, void 0, function* () {
240
+ try {
241
+ const shareableLink = yield getShareableInviteLink();
242
+ if (!shareableLink) {
243
+ throw new Error('No shareable link available');
244
+ }
245
+ yield react_native_1.Clipboard.setString(shareableLink);
246
+ console.log('[Vortex] handleCopyLink', 'The invite link has been copied.');
247
+ if (onSuccess) {
248
+ onSuccess({
249
+ type: 'share',
250
+ data: 'Sharable copied',
251
+ });
252
+ }
253
+ }
254
+ catch (error) {
255
+ console.error('[Vortex] Failed to copy link:', error);
256
+ if (onError) {
257
+ onError(error instanceof Error ? error : new Error(String(error)), 'share');
258
+ }
259
+ }
260
+ });
261
+ return {
262
+ widgetConfiguration,
263
+ error,
264
+ fetching,
265
+ loading,
266
+ email,
267
+ setEmail,
268
+ opacity,
269
+ themeColors,
270
+ themeStyles,
271
+ has,
272
+ options,
273
+ inviteLoading,
274
+ showSuccessMessage,
275
+ handleInviteClick,
276
+ handleShareLink,
277
+ handleCopyLink,
278
+ getShareableLink,
279
+ formLayout,
280
+ };
281
+ }
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VortexInvite = void 0;
4
+ var vortexInvite_1 = require("./vortexInvite");
5
+ Object.defineProperty(exports, "VortexInvite", { enumerable: true, get: function () { return vortexInvite_1.VortexInvite; } });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ class VortexClient {
13
+ constructor(baseUrl, sessionId) {
14
+ this.sessionId = sessionId;
15
+ // trim ending /
16
+ this.baseUrl = baseUrl.replace(/\/+$/, '');
17
+ }
18
+ getWidgetConfiguration(widgetId, jwt, environmentId) {
19
+ return __awaiter(this, void 0, void 0, function* () {
20
+ const url = `${this.baseUrl}/api/v1/environment/${environmentId}/widgets/${widgetId}`;
21
+ console.log('[VortexClient] getWidgetConfiguration', { url });
22
+ const response = yield fetch(url, {
23
+ headers: {
24
+ Authorization: `Bearer ${jwt}`,
25
+ 'x-session-id': this.sessionId,
26
+ },
27
+ });
28
+ if (!response.ok) {
29
+ const body = yield response.text();
30
+ console.error('[VortexClient] getWidgetConfiguration', { status: response.status, body });
31
+ throw new Error(`Error fetching widget configuration from ${url}: ${response.status}`);
32
+ }
33
+ const data = yield response.json();
34
+ console.log('[VortexClient] getWidgetConfiguration', { data });
35
+ return data;
36
+ });
37
+ }
38
+ createInvite(jwt, widgetConfigurationId, environmentId, payload) {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ const response = yield fetch(`${this.baseUrl}/api/v1/environment/${environmentId}/widget-configuration/${widgetConfigurationId}/invite`, {
41
+ method: 'POST',
42
+ headers: {
43
+ 'Content-Type': 'application/json',
44
+ Authorization: `Bearer ${jwt}`,
45
+ 'x-session-id': this.sessionId,
46
+ },
47
+ body: JSON.stringify({
48
+ data: {
49
+ payload,
50
+ },
51
+ }),
52
+ });
53
+ if (!response.ok) {
54
+ const body = yield response.text();
55
+ console.error('[VortexClient] createInvite', { status: response.status, body });
56
+ throw new Error(`Error POSTing widget invite: ${response.status}`);
57
+ }
58
+ const data = yield response.json();
59
+ console.log('[VortexClient] createInvite', data);
60
+ return data;
61
+ });
62
+ }
63
+ getShareableLinkFormatted() {
64
+ return `${this.baseUrl}/noauth/invite/...`;
65
+ }
66
+ createShareableInvite(jwt, widgetConfigurationId, environmentId) {
67
+ return __awaiter(this, void 0, void 0, function* () {
68
+ console.debug('[VortexClient] createShareableInvite request', {
69
+ widgetConfigurationId,
70
+ environmentId,
71
+ jwt,
72
+ });
73
+ const response = yield fetch(`${this.baseUrl}/api/v1/environment/${environmentId}/widget-configuration/${widgetConfigurationId}/generate-shareable-link-invite`, {
74
+ method: 'POST',
75
+ headers: {
76
+ 'Content-Type': 'application/json',
77
+ Authorization: `Bearer ${jwt}`,
78
+ 'x-session-id': this.sessionId,
79
+ },
80
+ });
81
+ if (!response.ok) {
82
+ throw new Error(`Error POSTing widget invite: ${response.statusText}`);
83
+ }
84
+ const data = yield response.json();
85
+ console.debug(`[VortexClient] createShareableInvite response ${JSON.stringify(data)}`);
86
+ return data;
87
+ });
88
+ }
89
+ }
90
+ exports.default = VortexClient;