@tacoreai/web-sdk 1.24.1-beta.1 → 1.24.1-beta.4

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.
@@ -7,7 +7,11 @@ const DEFAULT_FILE_SIZE_LIMIT = 100 * 1024 * 1024;
7
7
  const DEFAULT_MAX_FILES = 20;
8
8
 
9
9
  const isPreviewMode = () => process.env.TACORE_APPSERVER_PREVIEW_MODE === "true";
10
- const isLocalDeploymentMode = () => process.env.TACORE_APPSERVER_LOCAL_DEPLOYMENT_MODE === "true";
10
+ const isLocalDeploymentMode = (env = {}) =>
11
+ env.localDeployment === true ||
12
+ env.localAppServer === true ||
13
+ env.appServerDeploymentMode === "local" ||
14
+ process.env.TACORE_APPSERVER_LOCAL_DEPLOYMENT_MODE === "true";
11
15
 
12
16
  const isValidInternalToken = (incomingValue, expectedValue) => {
13
17
  return Boolean(expectedValue) && Boolean(incomingValue) && incomingValue === expectedValue;
@@ -310,7 +314,7 @@ export const createAppServerRuntime = async (options = {}) => {
310
314
 
311
315
  if (!isPlatformProxyRequest && !isSchedulerRequest) {
312
316
  if (!requestApiKey) {
313
- if (isLocalDeploymentMode() && requestAccessToken) {
317
+ if (isLocalDeploymentMode(env) && requestAccessToken) {
314
318
  try {
315
319
  const isValidAccessToken = await validateLocalDeploymentAccessToken(env, requestAccessToken);
316
320
  if (!isValidAccessToken) {
@@ -121,6 +121,59 @@ const clearPreviewSessionToken = (appId) => {
121
121
  previewSessionPromiseCache.delete(appId);
122
122
  };
123
123
 
124
+ const getBrowserWindowCandidates = () => {
125
+ if (typeof window === "undefined") {
126
+ return [];
127
+ }
128
+
129
+ const candidates = [window];
130
+ for (const candidate of [window.parent, window.top, window.opener]) {
131
+ if (candidate && !candidates.includes(candidate)) {
132
+ candidates.push(candidate);
133
+ }
134
+ }
135
+ return candidates;
136
+ };
137
+
138
+ const readBrowserPreviewBridgeValue = (key) => {
139
+ for (const candidate of getBrowserWindowCandidates()) {
140
+ try {
141
+ const value = String(candidate?.[key] || "").trim();
142
+ if (value) {
143
+ return value;
144
+ }
145
+ } catch (error) {
146
+ // Ignore cross-origin window access.
147
+ }
148
+ }
149
+ return "";
150
+ };
151
+
152
+ const getBrowserPreviewBridgeBaseUrl = () => {
153
+ return readBrowserPreviewBridgeValue("__TACORE_APPSERVER_PREVIEW_BRIDGE_BASE_URL__").replace(/\/$/, "");
154
+ };
155
+
156
+ const getBrowserPreviewBridgeInvokeUrl = () => {
157
+ const rawUrl = readBrowserPreviewBridgeValue("__TACORE_APPSERVER_PREVIEW_BRIDGE_URL__");
158
+ if (!rawUrl) {
159
+ return "";
160
+ }
161
+
162
+ try {
163
+ const url = new URL(rawUrl, typeof window !== "undefined" ? window.location.origin : "http://localhost");
164
+ return url.pathname.endsWith("/appserver-preview/invokeAppServerAPI") ? url.toString() : "";
165
+ } catch (error) {
166
+ return "";
167
+ }
168
+ };
169
+
170
+ const appendPreviewInvokeParams = (rawUrl, appId, apiName) => {
171
+ const url = new URL(rawUrl, typeof window !== "undefined" ? window.location.origin : "http://localhost");
172
+ url.searchParams.set("appId", appId);
173
+ url.searchParams.set("apiName", apiName);
174
+ return url.toString();
175
+ };
176
+
124
177
  const getPreviewSessionToken = async function(options = {}) {
125
178
  const { forceRefresh = false } = options;
126
179
  const appServerOwnerAppId = getAppServerOwnerAppId.call(this);
@@ -139,7 +192,10 @@ const getPreviewSessionToken = async function(options = {}) {
139
192
  }
140
193
 
141
194
  const requestPromise = (async () => {
142
- const endpoint = `/appserver-preview/session?appId=${encodeURIComponent(appServerOwnerAppId)}`;
195
+ const bridgeBaseUrl = getBrowserPreviewBridgeBaseUrl();
196
+ const endpoint = bridgeBaseUrl
197
+ ? `${bridgeBaseUrl}/appserver-preview/session?appId=${encodeURIComponent(appServerOwnerAppId)}`
198
+ : `/appserver-preview/session?appId=${encodeURIComponent(appServerOwnerAppId)}`;
143
199
  const response = await fetch(endpoint, {
144
200
  method: "GET",
145
201
  headers: {
@@ -404,7 +460,13 @@ const invokeByPlatformProxy = async function(appServerAPIName, payload, options
404
460
 
405
461
  const invokeByPreviewProxyOnce = async function(appServerAPIName, payload, options = {}, previewToken) {
406
462
  const appServerOwnerAppId = getAppServerOwnerAppId.call(this);
407
- const endpoint = `/appserver-preview/invokeAppServerAPI?appId=${encodeURIComponent(appServerOwnerAppId)}&apiName=${encodeURIComponent(appServerAPIName)}`;
463
+ const bridgeInvokeUrl = getBrowserPreviewBridgeInvokeUrl();
464
+ const bridgeBaseUrl = getBrowserPreviewBridgeBaseUrl();
465
+ const endpoint = bridgeInvokeUrl
466
+ ? appendPreviewInvokeParams(bridgeInvokeUrl, appServerOwnerAppId, appServerAPIName)
467
+ : bridgeBaseUrl
468
+ ? `${bridgeBaseUrl}/appserver-preview/invokeAppServerAPI?appId=${encodeURIComponent(appServerOwnerAppId)}&apiName=${encodeURIComponent(appServerAPIName)}`
469
+ : `/appserver-preview/invokeAppServerAPI?appId=${encodeURIComponent(appServerOwnerAppId)}&apiName=${encodeURIComponent(appServerAPIName)}`;
408
470
  const response = await fetch(
409
471
  endpoint,
410
472
  buildRemoteRequestInit.call(this, payload, options, {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tacoreai/web-sdk",
3
3
  "description": "This file is for app server package, not the real npm package",
4
- "version": "1.24.1-beta.1",
4
+ "version": "1.24.1-beta.4",
5
5
  "type": "module",
6
6
  "publishConfig": {
7
7
  "access": "public",