@tacoreai/web-sdk 1.23.0 → 1.24.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.
@@ -21,6 +21,29 @@ const isBrowserPreviewRuntime = () => {
21
21
  return pathname.startsWith("/app-run/");
22
22
  };
23
23
 
24
+ const normalizeAppId = value => String(value || "").trim();
25
+
26
+ const getAppServerOwnerAppId = function() {
27
+ const explicitOwnerAppId = normalizeAppId(this.config?.appServerOwnerAppId);
28
+ if (explicitOwnerAppId) {
29
+ return explicitOwnerAppId;
30
+ }
31
+
32
+ const shellAppId = normalizeAppId(this.config?.appId);
33
+ if (shellAppId) {
34
+ return shellAppId;
35
+ }
36
+
37
+ if (typeof this._getChannelAppId === "function") {
38
+ const channelAppId = normalizeAppId(this._getChannelAppId());
39
+ if (channelAppId) {
40
+ return channelAppId;
41
+ }
42
+ }
43
+
44
+ return normalizeAppId(this.appId);
45
+ };
46
+
24
47
  const hasOwn = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
25
48
 
26
49
  const isPlainObject = (value) => Object.prototype.toString.call(value) === "[object Object]";
@@ -100,22 +123,23 @@ const clearPreviewSessionToken = (appId) => {
100
123
 
101
124
  const getPreviewSessionToken = async function(options = {}) {
102
125
  const { forceRefresh = false } = options;
126
+ const appServerOwnerAppId = getAppServerOwnerAppId.call(this);
103
127
  if (forceRefresh) {
104
- clearPreviewSessionToken(this.appId);
128
+ clearPreviewSessionToken(appServerOwnerAppId);
105
129
  }
106
130
 
107
- const cachedToken = previewSessionTokenCache.get(this.appId);
131
+ const cachedToken = previewSessionTokenCache.get(appServerOwnerAppId);
108
132
  if (cachedToken) {
109
133
  return cachedToken;
110
134
  }
111
135
 
112
- const pendingRequest = previewSessionPromiseCache.get(this.appId);
136
+ const pendingRequest = previewSessionPromiseCache.get(appServerOwnerAppId);
113
137
  if (pendingRequest) {
114
138
  return pendingRequest;
115
139
  }
116
140
 
117
141
  const requestPromise = (async () => {
118
- const endpoint = `/appserver-preview/session?appId=${encodeURIComponent(this.appId)}`;
142
+ const endpoint = `/appserver-preview/session?appId=${encodeURIComponent(appServerOwnerAppId)}`;
119
143
  const response = await fetch(endpoint, {
120
144
  method: "GET",
121
145
  headers: {
@@ -138,15 +162,15 @@ const getPreviewSessionToken = async function(options = {}) {
138
162
  throw new Error("[AppServer-PreviewSession] Missing preview token in session response.");
139
163
  }
140
164
 
141
- previewSessionTokenCache.set(this.appId, previewToken);
165
+ previewSessionTokenCache.set(appServerOwnerAppId, previewToken);
142
166
  return previewToken;
143
167
  })();
144
168
 
145
- previewSessionPromiseCache.set(this.appId, requestPromise);
169
+ previewSessionPromiseCache.set(appServerOwnerAppId, requestPromise);
146
170
  try {
147
171
  return await requestPromise;
148
172
  } finally {
149
- previewSessionPromiseCache.delete(this.appId);
173
+ previewSessionPromiseCache.delete(appServerOwnerAppId);
150
174
  }
151
175
  };
152
176
 
@@ -367,7 +391,8 @@ const buildRemoteRequestInit = function(
367
391
  };
368
392
 
369
393
  const invokeByPlatformProxy = async function(appServerAPIName, payload, options = {}) {
370
- const endpoint = `/apps/invokeAppServerAPI?appId=${encodeURIComponent(this.appId)}&apiName=${encodeURIComponent(appServerAPIName)}`;
394
+ const appServerOwnerAppId = getAppServerOwnerAppId.call(this);
395
+ const endpoint = `/apps/invokeAppServerAPI?appId=${encodeURIComponent(appServerOwnerAppId)}&apiName=${encodeURIComponent(appServerAPIName)}`;
371
396
  const response = await fetch(
372
397
  `${this.config.apiBaseUrl}${endpoint}`,
373
398
  buildRemoteRequestInit.call(this, payload, options, {}, {
@@ -378,7 +403,8 @@ const invokeByPlatformProxy = async function(appServerAPIName, payload, options
378
403
  };
379
404
 
380
405
  const invokeByPreviewProxyOnce = async function(appServerAPIName, payload, options = {}, previewToken) {
381
- const endpoint = `/appserver-preview/invokeAppServerAPI?appId=${encodeURIComponent(this.appId)}&apiName=${encodeURIComponent(appServerAPIName)}`;
406
+ const appServerOwnerAppId = getAppServerOwnerAppId.call(this);
407
+ const endpoint = `/appserver-preview/invokeAppServerAPI?appId=${encodeURIComponent(appServerOwnerAppId)}&apiName=${encodeURIComponent(appServerAPIName)}`;
382
408
  const response = await fetch(
383
409
  endpoint,
384
410
  buildRemoteRequestInit.call(this, payload, options, {
@@ -398,7 +424,7 @@ const invokeByPreviewProxy = async function(appServerAPIName, payload, options =
398
424
  throw error;
399
425
  }
400
426
 
401
- clearPreviewSessionToken(this.appId);
427
+ clearPreviewSessionToken(getAppServerOwnerAppId.call(this));
402
428
  previewToken = await getPreviewSessionToken.call(this, { forceRefresh: true });
403
429
  return await invokeByPreviewProxyOnce.call(this, appServerAPIName, payload, options, previewToken);
404
430
  }
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.23.0",
4
+ "version": "1.24.0",
5
5
  "type": "module",
6
6
  "publishConfig": {
7
7
  "access": "public",
@@ -13,7 +13,7 @@
13
13
  "./app-server-runtime": "./database/core/apps/AppServerRuntime.js"
14
14
  },
15
15
  "scripts": {
16
- "release": "npm version minor && git commit -am \"web-sdk update version\" && git push && npm publish",
16
+ "release": "npm version minor && git commit -am \"web-sdk update version\" && npm publish && git push",
17
17
  "release:beta": "npm version prerelease --preid beta --no-git-tag-version && git commit -am \"web-sdk update beta version\" && npm publish --tag beta"
18
18
  }
19
19
  }