@embedreach/components 0.1.87 → 0.1.88

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.
@@ -5887,6 +5887,117 @@ var ReactQueryDevtools2 = process.env.NODE_ENV !== "development" ? function() {
5887
5887
  process.env.NODE_ENV !== "development" ? function() {
5888
5888
  return null;
5889
5889
  } : ReactQueryDevtoolsPanel;
5890
+ class InvalidTokenError extends Error {
5891
+ }
5892
+ InvalidTokenError.prototype.name = "InvalidTokenError";
5893
+ function b64DecodeUnicode(str) {
5894
+ return decodeURIComponent(atob(str).replace(/(.)/g, (m4, p2) => {
5895
+ let code = p2.charCodeAt(0).toString(16).toUpperCase();
5896
+ if (code.length < 2) {
5897
+ code = "0" + code;
5898
+ }
5899
+ return "%" + code;
5900
+ }));
5901
+ }
5902
+ function base64UrlDecode(str) {
5903
+ let output = str.replace(/-/g, "+").replace(/_/g, "/");
5904
+ switch (output.length % 4) {
5905
+ case 0:
5906
+ break;
5907
+ case 2:
5908
+ output += "==";
5909
+ break;
5910
+ case 3:
5911
+ output += "=";
5912
+ break;
5913
+ default:
5914
+ throw new Error("base64 string is not of the correct length");
5915
+ }
5916
+ try {
5917
+ return b64DecodeUnicode(output);
5918
+ } catch (err) {
5919
+ return atob(output);
5920
+ }
5921
+ }
5922
+ function jwtDecode(token, options) {
5923
+ if (typeof token !== "string") {
5924
+ throw new InvalidTokenError("Invalid token specified: must be a string");
5925
+ }
5926
+ options || (options = {});
5927
+ const pos = options.header === true ? 0 : 1;
5928
+ const part = token.split(".")[pos];
5929
+ if (typeof part !== "string") {
5930
+ throw new InvalidTokenError(`Invalid token specified: missing part #${pos + 1}`);
5931
+ }
5932
+ let decoded;
5933
+ try {
5934
+ decoded = base64UrlDecode(part);
5935
+ } catch (e4) {
5936
+ throw new InvalidTokenError(`Invalid token specified: invalid base64 for part #${pos + 1} (${e4.message})`);
5937
+ }
5938
+ try {
5939
+ return JSON.parse(decoded);
5940
+ } catch (e4) {
5941
+ throw new InvalidTokenError(`Invalid token specified: invalid json for part #${pos + 1} (${e4.message})`);
5942
+ }
5943
+ }
5944
+ const ErrorFallback = ({ error: error2 }) => /* @__PURE__ */ jsxs("div", { className: "p-6 max-w-lg mx-auto mt-10 bg-white rounded-lg shadow-md", children: [
5945
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-row items-center justify-start gap-4", children: [
5946
+ /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center h-12 w-12 rounded-full bg-red-100 text-red-600 mb-4", children: /* @__PURE__ */ jsx(
5947
+ "svg",
5948
+ {
5949
+ xmlns: "http://www.w3.org/2000/svg",
5950
+ className: "h-6 w-6",
5951
+ fill: "none",
5952
+ viewBox: "0 0 24 24",
5953
+ stroke: "currentColor",
5954
+ children: /* @__PURE__ */ jsx(
5955
+ "path",
5956
+ {
5957
+ strokeLinecap: "round",
5958
+ strokeLinejoin: "round",
5959
+ strokeWidth: 2,
5960
+ d: "M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"
5961
+ }
5962
+ )
5963
+ }
5964
+ ) }),
5965
+ /* @__PURE__ */ jsx("h2", { className: "text-xl font-semibold text-gray-900 mb-2", children: "Oops! Something went wrong." })
5966
+ ] }),
5967
+ /* @__PURE__ */ jsx("p", { className: "text-gray-600 mb-4", children: "We have encountered a critical error and cannot continue. Please try refreshing the page." }),
5968
+ error2 && /* @__PURE__ */ jsx("div", { className: "mt-4 p-3 bg-gray-50 rounded border border-gray-200", children: /* @__PURE__ */ jsx("p", { className: "text-sm text-gray-700 font-mono", children: error2.toString() }) })
5969
+ ] });
5970
+ class ErrorBoundary extends React__default.Component {
5971
+ constructor(props) {
5972
+ super(props);
5973
+ this.state = { hasError: false, error: null, errorInfo: null };
5974
+ }
5975
+ static getDerivedStateFromError(error2) {
5976
+ return { hasError: true, error: error2 };
5977
+ }
5978
+ componentDidCatch(error2, errorInfo) {
5979
+ console.error("ErrorBoundary caught an error", error2, errorInfo);
5980
+ this.setState({ errorInfo });
5981
+ }
5982
+ render() {
5983
+ const { fallback, children: children2 } = this.props;
5984
+ const { hasError, error: error2, errorInfo } = this.state;
5985
+ if (hasError) {
5986
+ if (fallback) {
5987
+ return typeof fallback === "function" ? fallback(error2, errorInfo) : fallback;
5988
+ }
5989
+ return /* @__PURE__ */ jsxs("div", { className: "p-4 border border-red-300 rounded-md bg-red-50 text-red-800", children: [
5990
+ /* @__PURE__ */ jsx("h2", { className: "text-lg font-semibold mb-2", children: "Something went wrong" }),
5991
+ /* @__PURE__ */ jsxs("details", { className: "whitespace-pre-wrap text-sm", children: [
5992
+ /* @__PURE__ */ jsx("summary", { children: "See error details" }),
5993
+ /* @__PURE__ */ jsx("p", { className: "mt-2", children: error2?.toString() }),
5994
+ /* @__PURE__ */ jsx("p", { className: "mt-2", children: errorInfo?.componentStack })
5995
+ ] })
5996
+ ] });
5997
+ }
5998
+ return children2;
5999
+ }
6000
+ }
5890
6001
  function e(e4) {
5891
6002
  function t3(e5, t4) {
5892
6003
  Error.captureStackTrace && Error.captureStackTrace(this, this.constructor), this.message = e5, this.code = t4;
@@ -8077,6 +8188,36 @@ const oe = (e4) => {
8077
8188
  const { ldClient: t3 } = useContext$1(u$1.reactContext);
8078
8189
  return t3;
8079
8190
  };
8191
+ const LaunchDarklyProvider = ({
8192
+ children: children2,
8193
+ tenantExternalId,
8194
+ partnerId
8195
+ }) => {
8196
+ const key = tenantExternalId && partnerId ? `${tenantExternalId}:${partnerId}` : "anonymous";
8197
+ return /* @__PURE__ */ jsx(
8198
+ D$1,
8199
+ {
8200
+ clientSideID: "67a3c277012e1f09c67de499",
8201
+ context: {
8202
+ kind: "user",
8203
+ key,
8204
+ custom: {
8205
+ tenantExternalId,
8206
+ partnerId
8207
+ }
8208
+ },
8209
+ options: {
8210
+ streaming: false
8211
+ },
8212
+ timeout: 2,
8213
+ reactOptions: {
8214
+ useCamelCaseFlagKeys: false,
8215
+ sendEventsOnFlagRead: true
8216
+ },
8217
+ children: children2
8218
+ }
8219
+ );
8220
+ };
8080
8221
  const TOAST_LIMIT = 1;
8081
8222
  const TOAST_REMOVE_DELAY = 1e6;
8082
8223
  let count$6 = 0;
@@ -35053,6 +35194,7 @@ const configDefaults = {
35053
35194
  };
35054
35195
  const Observability = ({
35055
35196
  tenantExternalId,
35197
+ partnerId,
35056
35198
  debug
35057
35199
  }) => {
35058
35200
  const ldClient = oe();
@@ -35093,7 +35235,8 @@ const Observability = ({
35093
35235
  })
35094
35236
  ],
35095
35237
  resourceAttributes: {
35096
- ["tenant.externalId"]: tenantExternalId
35238
+ ["tenant.externalId"]: tenantExternalId,
35239
+ ["partner.id"]: partnerId
35097
35240
  }
35098
35241
  });
35099
35242
  sdk.start();
@@ -35114,7 +35257,6 @@ const Observability = ({
35114
35257
  };
35115
35258
  const ReachProvider = ({
35116
35259
  authToken: authToken2,
35117
- tenantExternalId,
35118
35260
  language,
35119
35261
  children: children2,
35120
35262
  theme: theme2,
@@ -35126,38 +35268,52 @@ const ReachProvider = ({
35126
35268
  }
35127
35269
  return createQueryClient();
35128
35270
  });
35129
- return /* @__PURE__ */ jsx("div", { "data-reach-root": true, className: "h-full w-full", children: /* @__PURE__ */ jsxs(QueryClientProvider, { client: queryClient, children: [
35271
+ let tenantExternalId;
35272
+ let partnerId;
35273
+ try {
35274
+ const decodedToken = jwtDecode(authToken2);
35275
+ tenantExternalId = decodedToken?.tenantExternalId;
35276
+ partnerId = decodedToken?.partnerId || decodedToken?.platformId;
35277
+ if (!tenantExternalId || !partnerId) {
35278
+ throw new Error("Invalid authentication token");
35279
+ }
35280
+ } catch (error2) {
35281
+ return /* @__PURE__ */ jsxs("div", { className: "p-6 max-w-lg mx-auto mt-10 bg-white rounded-lg shadow-md", children: [
35282
+ /* @__PURE__ */ jsx("h2", { className: "text-xl font-semibold text-red-600 mb-4", children: "Authentication Error" }),
35283
+ /* @__PURE__ */ jsx("p", { className: "text-gray-700", children: "The provided authentication token is invalid. Please ensure you're using a valid token." })
35284
+ ] });
35285
+ }
35286
+ return /* @__PURE__ */ jsx(ErrorBoundary, { fallback: /* @__PURE__ */ jsx(ErrorFallback, {}), children: /* @__PURE__ */ jsx("div", { "data-reach-root": true, className: "h-full w-full", children: /* @__PURE__ */ jsxs(QueryClientProvider, { client: queryClient, children: [
35130
35287
  /* @__PURE__ */ jsxs(
35131
- D$1,
35288
+ LaunchDarklyProvider,
35132
35289
  {
35133
- clientSideID: "67a3c277012e1f09c67de499",
35134
- context: {
35135
- kind: "user",
35136
- key: tenantExternalId || "anonymous",
35137
- custom: {
35138
- businessId: tenantExternalId
35139
- // Add any other custom attributes
35140
- }
35141
- },
35142
- options: {
35143
- streaming: false
35144
- },
35145
- timeout: 2,
35146
- reactOptions: {
35147
- useCamelCaseFlagKeys: false,
35148
- sendEventsOnFlagRead: true
35149
- },
35290
+ tenantExternalId,
35291
+ partnerId,
35150
35292
  children: [
35151
- /* @__PURE__ */ jsx(Observability, { tenantExternalId, debug }),
35152
- /* @__PURE__ */ jsx(I18nProvider, { language, initialLanguage: language?.default, children: /* @__PURE__ */ jsx(Provider$1, { initialTheme: theme2, children: /* @__PURE__ */ jsxs(Provider$2, { children: [
35153
- children2,
35154
- /* @__PURE__ */ jsx(Toaster, {})
35155
- ] }) }) })
35293
+ /* @__PURE__ */ jsx(
35294
+ Observability,
35295
+ {
35296
+ tenantExternalId,
35297
+ partnerId,
35298
+ debug
35299
+ }
35300
+ ),
35301
+ /* @__PURE__ */ jsx(
35302
+ I18nProvider,
35303
+ {
35304
+ language,
35305
+ initialLanguage: language?.default,
35306
+ children: /* @__PURE__ */ jsx(Provider$1, { initialTheme: theme2, children: /* @__PURE__ */ jsxs(Provider$2, { children: [
35307
+ children2,
35308
+ /* @__PURE__ */ jsx(Toaster, {})
35309
+ ] }) })
35310
+ }
35311
+ )
35156
35312
  ]
35157
35313
  }
35158
35314
  ),
35159
35315
  debug && /* @__PURE__ */ jsx(ReactQueryDevtools2, {})
35160
- ] }) });
35316
+ ] }) }) });
35161
35317
  };
35162
35318
  function setRef$3(ref, value) {
35163
35319
  if (typeof ref === "function") {
@@ -45161,16 +45317,14 @@ const BasicLoader = ({
45161
45317
  ] });
45162
45318
  };
45163
45319
  const BlurDiv = ({ children: children2, className: className2 }) => {
45164
- return /* @__PURE__ */ jsx(
45165
- motion.div,
45166
- {
45167
- initial: { opacity: 0, filter: "blur(8px)" },
45168
- animate: { opacity: 1, filter: "blur(0px)" },
45169
- exit: { opacity: 0, filter: "blur(8px)" },
45170
- transition: { duration: 0.3, ease: "easeInOut" },
45171
- className: className2,
45172
- children: children2
45173
- }
45320
+ return (
45321
+ // <motion.div
45322
+ // initial={{ opacity: 0, filter: 'blur(8px)' }}
45323
+ // animate={{ opacity: 1, filter: 'blur(0px)' }}
45324
+ // exit={{ opacity: 0, filter: 'blur(8px)' }}
45325
+ // transition={{ duration: 0.3, ease: 'easeInOut' }}
45326
+ // className={className}>
45327
+ /* @__PURE__ */ jsx("div", { className: className2, children: children2 })
45174
45328
  );
45175
45329
  };
45176
45330
  const IconDefinitions = {
package/dist/index.d.ts CHANGED
@@ -117,9 +117,8 @@ declare interface LanguageConfig {
117
117
  * @interface ReachConfig
118
118
  */
119
119
  export declare interface ReachConfig {
120
- theme?: ThemeConfig;
121
120
  authToken: string;
122
- tenantExternalId: string;
121
+ theme?: ThemeConfig;
123
122
  /** Event callbacks */
124
123
  callbacks?: SDKCallbacks;
125
124
  /** Initial feature to load */
@@ -168,7 +167,6 @@ declare type ReauthCallback = () => Promise<string> | void;
168
167
  declare interface SDKCallbacks {
169
168
  /** Called when reauthentication is required */
170
169
  onReauthRequested: ReauthCallback;
171
- /** Called when tenant information is requested */
172
170
  onTenantInformationRequested?: () => void;
173
171
  }
174
172