@ptkl/toolkit 0.10.1 → 0.10.3
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/commands/forge.js +10 -9
- package/dist/lib/forgeDevKernelPlugin.js +84 -248
- package/package.json +1 -1
package/dist/commands/forge.js
CHANGED
|
@@ -132,9 +132,6 @@ class ForgeCommand {
|
|
|
132
132
|
type: type || 'platform', // default to 'platform' if not specified
|
|
133
133
|
ssrRenderer,
|
|
134
134
|
};
|
|
135
|
-
const client = Util.getClientForProfile();
|
|
136
|
-
// get base url of the platform cliente
|
|
137
|
-
const baseUrl = client.getPlatformBaseURL();
|
|
138
135
|
// Different build approach for public vs platform apps
|
|
139
136
|
if (type === 'public') {
|
|
140
137
|
// Public apps: standard SPA build with index.html
|
|
@@ -194,13 +191,13 @@ class ForgeCommand {
|
|
|
194
191
|
}
|
|
195
192
|
else {
|
|
196
193
|
// Platform apps: custom bundle format with views and scripts
|
|
197
|
-
const
|
|
194
|
+
const bundleBasePath = `/luma/appservice/v1/forge/static/bundle/${name}/${version}/`;
|
|
198
195
|
const buildViews = Object.keys(views).map(async (view) => {
|
|
199
196
|
manifest.views[view] = `${view}.bundle.js`;
|
|
200
197
|
try {
|
|
201
198
|
const result = await build({
|
|
202
199
|
root: path,
|
|
203
|
-
base,
|
|
200
|
+
base: bundleBasePath,
|
|
204
201
|
build: {
|
|
205
202
|
outDir: distPath,
|
|
206
203
|
emptyOutDir: false,
|
|
@@ -225,10 +222,12 @@ class ForgeCommand {
|
|
|
225
222
|
for (const fileName in bundle) {
|
|
226
223
|
const chunk = bundle[fileName];
|
|
227
224
|
if (chunk.type === 'chunk' && chunk.code) {
|
|
225
|
+
const runtimeBaseResolver = `const __ptklForgeBundleBase=()=>{const env=typeof window!=='undefined'&&window.__ENV_VARIABLES__?window.__ENV_VARIABLES__.API_HOST:'';const host=typeof env==='string'?env.replace(/\\/$/,''):'';return host+'${bundleBasePath}';};\n`;
|
|
226
|
+
chunk.code = runtimeBaseResolver + chunk.code;
|
|
228
227
|
// Transform dynamic imports in the final bundled code
|
|
229
|
-
chunk.code = chunk.code.replace(/import\(['"`]\.\/([^'"`]+)['"`]\)/g, `dynamicImport('$
|
|
228
|
+
chunk.code = chunk.code.replace(/import\(['"`]\.\/([^'"`]+)['"`]\)/g, `dynamicImport(__ptklForgeBundleBase() + '$1')`);
|
|
230
229
|
// Also handle relative paths without ./
|
|
231
|
-
chunk.code = chunk.code.replace(/import\(['"`]([^'"`\/]+\.js)['"`]\)/g, `dynamicImport('$
|
|
230
|
+
chunk.code = chunk.code.replace(/import\(['"`]([^'"`\/]+\.js)['"`]\)/g, `dynamicImport(__ptklForgeBundleBase() + '$1')`);
|
|
232
231
|
}
|
|
233
232
|
}
|
|
234
233
|
}
|
|
@@ -246,7 +245,7 @@ class ForgeCommand {
|
|
|
246
245
|
try {
|
|
247
246
|
const result = await build({
|
|
248
247
|
root: path,
|
|
249
|
-
base,
|
|
248
|
+
base: bundleBasePath,
|
|
250
249
|
build: {
|
|
251
250
|
outDir: distPath,
|
|
252
251
|
emptyOutDir: false,
|
|
@@ -335,6 +334,7 @@ class ForgeCommand {
|
|
|
335
334
|
const manifestPath = `${distPath}/manifest.json`;
|
|
336
335
|
writeFileSync(manifestPath, JSON.stringify(manifest, null, 4));
|
|
337
336
|
if (upload) {
|
|
337
|
+
const client = Util.getClientForProfile();
|
|
338
338
|
let buffer = Buffer.alloc(0);
|
|
339
339
|
const bufferStream = new Writable({
|
|
340
340
|
write(chunk, encoding, callback) {
|
|
@@ -398,10 +398,11 @@ class ForgeCommand {
|
|
|
398
398
|
API_HOST: host,
|
|
399
399
|
INTEGRATION_API: `${host}/luma/integrations`,
|
|
400
400
|
PROJECT_API_TOKEN: Util.getCurrentProfile().token,
|
|
401
|
+
PLATFORM_URL: platformUrl ? platformUrl : "https://platform.protokol.io"
|
|
401
402
|
}),
|
|
402
403
|
DEV_HUB_PORT
|
|
403
404
|
},
|
|
404
|
-
plugins: [forgeDevKernelPlugin(appName, platformUrl)],
|
|
405
|
+
plugins: [forgeDevKernelPlugin(appName, platformUrl ?? 'https://platform.protokol.io')],
|
|
405
406
|
});
|
|
406
407
|
await server.listen();
|
|
407
408
|
console.log('Current profile:', Util.getCurrentProfile().name);
|
|
@@ -9,12 +9,30 @@
|
|
|
9
9
|
*/
|
|
10
10
|
export function forgeDevKernelPlugin(appName, platformUrl) {
|
|
11
11
|
const appRef = appName ?? '';
|
|
12
|
-
const platUrl = platformUrl ? platformUrl.replace(/\/$/, '') :
|
|
13
|
-
const scriptContent =
|
|
14
|
-
? `(function(){
|
|
12
|
+
const platUrl = platformUrl ? platformUrl.replace(/\/$/, '') : '';
|
|
13
|
+
const scriptContent = `(function(){
|
|
15
14
|
var _appRef=${JSON.stringify(appRef)};
|
|
16
15
|
var _platformUrl=${JSON.stringify(platUrl)};
|
|
17
16
|
window.$forge=window.forge||{};
|
|
17
|
+
function openPlatformPopup(url){return window.open(url,'_blank');}
|
|
18
|
+
function showWaitingOverlay(message){
|
|
19
|
+
var overlay=document.createElement('div');
|
|
20
|
+
overlay.style.cssText='position:fixed;inset:0;z-index:99999;background:rgba(0,0,0,0.72);display:flex;align-items:center;justify-content:center;flex-direction:column;gap:1rem;';
|
|
21
|
+
var style=document.createElement('style');
|
|
22
|
+
style.textContent='@keyframes forge-spin{to{transform:rotate(360deg)}}';
|
|
23
|
+
overlay.appendChild(style);
|
|
24
|
+
var spinner=document.createElement('div');
|
|
25
|
+
spinner.style.cssText='width:40px;height:40px;border:3px solid rgba(255,255,255,0.15);border-top-color:#fff;border-radius:50%;animation:forge-spin 0.7s linear infinite;';
|
|
26
|
+
overlay.appendChild(spinner);
|
|
27
|
+
if(message){
|
|
28
|
+
var label=document.createElement('div');
|
|
29
|
+
label.textContent=message;
|
|
30
|
+
label.style.cssText='color:rgba(255,255,255,0.85);font-size:0.9rem;font-family:system-ui,sans-serif;text-align:center;max-width:320px;';
|
|
31
|
+
overlay.appendChild(label);
|
|
32
|
+
}
|
|
33
|
+
document.body.appendChild(overlay);
|
|
34
|
+
return{close:function(){overlay.remove();}};
|
|
35
|
+
}
|
|
18
36
|
window.$forge.requestPermissions=function(permissions,reason){
|
|
19
37
|
var appName=_appRef||sessionStorage.getItem('forge_app_name')||'';
|
|
20
38
|
var params=new URLSearchParams();
|
|
@@ -22,69 +40,22 @@ export function forgeDevKernelPlugin(appName, platformUrl) {
|
|
|
22
40
|
if(reason)params.set('reason',reason);
|
|
23
41
|
permissions.forEach(function(p){params.append('permissions[]',p);});
|
|
24
42
|
var consentUrl=_platformUrl+'/forge/consent?'+params.toString();
|
|
43
|
+
var popup=openPlatformPopup(consentUrl);
|
|
44
|
+
var waiting=showWaitingOverlay('Waiting for permission approval\u2026');
|
|
25
45
|
return new Promise(function(resolve,reject){
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
var dialog=document.createElement('div');
|
|
31
|
-
dialog.style.cssText='position:relative;width:520px;max-width:calc(100vw - 2rem);height:640px;max-height:calc(100vh - 4rem);border-radius:16px;overflow:hidden;box-shadow:0 32px 80px rgba(0,0,0,0.8);';
|
|
32
|
-
// Close button
|
|
33
|
-
var closeBtn=document.createElement('button');
|
|
34
|
-
closeBtn.textContent='\u00D7';
|
|
35
|
-
closeBtn.style.cssText='position:absolute;top:10px;right:12px;z-index:3;background:rgba(255,255,255,0.12);border:1px solid rgba(255,255,255,0.15);color:#fff;font-size:1.25rem;line-height:1;width:30px;height:30px;border-radius:50%;cursor:pointer;display:flex;align-items:center;justify-content:center;';
|
|
36
|
-
// Loader
|
|
37
|
-
var loader=document.createElement('div');
|
|
38
|
-
loader.style.cssText='position:absolute;inset:0;display:flex;align-items:center;justify-content:center;background:#0f0f10;z-index:2;pointer-events:none;';
|
|
39
|
-
var spinner=document.createElement('div');
|
|
40
|
-
spinner.style.cssText='width:36px;height:36px;border:3px solid rgba(255,255,255,0.12);border-top-color:#fff;border-radius:50%;animation:forge-spin 0.7s linear infinite;';
|
|
41
|
-
var style=document.createElement('style');
|
|
42
|
-
style.textContent='@keyframes forge-spin{to{transform:rotate(360deg)}}';
|
|
43
|
-
loader.appendChild(style);
|
|
44
|
-
loader.appendChild(spinner);
|
|
45
|
-
// iframe
|
|
46
|
-
var iframe=document.createElement('iframe');
|
|
47
|
-
iframe.style.cssText='width:100%;height:100%;border:none;display:block;';
|
|
48
|
-
iframe.addEventListener('load',function(){loader.style.display='none';});
|
|
49
|
-
dialog.appendChild(closeBtn);
|
|
50
|
-
dialog.appendChild(loader);
|
|
51
|
-
dialog.appendChild(iframe);
|
|
52
|
-
overlay.appendChild(dialog);
|
|
53
|
-
document.body.appendChild(overlay);
|
|
54
|
-
// Set src after DOM attach to prevent premature about:blank load event
|
|
55
|
-
setTimeout(function(){iframe.src=consentUrl;},0);
|
|
56
|
-
function cleanup(){
|
|
57
|
-
window.removeEventListener('message',onMessage);
|
|
58
|
-
overlay.remove();
|
|
59
|
-
}
|
|
46
|
+
var pollTimer=setInterval(function(){
|
|
47
|
+
if(popup&&popup.closed){cleanup();reject(new Error('[ptkl forge dev] Consent dialog closed without approving.'));}
|
|
48
|
+
},500);
|
|
49
|
+
function cleanup(){clearInterval(pollTimer);window.removeEventListener('message',onMessage);if(popup&&!popup.closed)popup.close();waiting.close();}
|
|
60
50
|
function onMessage(e){
|
|
61
51
|
if(e.origin!==_platformUrl)return;
|
|
62
52
|
if(!e.data)return;
|
|
63
|
-
if(e.data.type==='forge_consent_token'){
|
|
64
|
-
|
|
65
|
-
sessionStorage.setItem('forge_actor_token',e.data.token);
|
|
66
|
-
resolve(e.data.permissions||[]);
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
if(e.data.type==='forge_consent_denied'){
|
|
70
|
-
cleanup();
|
|
71
|
-
reject(new Error('[ptkl forge dev] Consent denied.'));
|
|
72
|
-
}
|
|
53
|
+
if(e.data.type==='forge_consent_token'){cleanup();sessionStorage.setItem('forge_actor_token',e.data.token);resolve(e.data.permissions||[]);return;}
|
|
54
|
+
if(e.data.type==='forge_consent_denied'){cleanup();reject(new Error('[ptkl forge dev] Consent denied.'));}
|
|
73
55
|
}
|
|
74
56
|
window.addEventListener('message',onMessage);
|
|
75
|
-
closeBtn.addEventListener('click',function(){
|
|
76
|
-
cleanup();
|
|
77
|
-
reject(new Error('[ptkl forge dev] Consent dialog closed without approving.'));
|
|
78
|
-
});
|
|
79
|
-
overlay.addEventListener('click',function(e){
|
|
80
|
-
if(e.target===overlay){
|
|
81
|
-
cleanup();
|
|
82
|
-
reject(new Error('[ptkl forge dev] Consent dialog closed without approving.'));
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
57
|
});
|
|
86
58
|
};
|
|
87
|
-
console.log('[ptkl forge dev] window.forge ready (platform: '+_platformUrl+')'); window.$forge.dynamicImport=function(url){return import(url).then(function(){});}; window.$forge.dynamicImportCSS=function(url){return new Promise(function(resolve,reject){var link=document.createElement('link');link.rel='stylesheet';link.href=url;link.onload=function(){resolve();};link.onerror=function(){reject(new Error('Failed to load CSS: '+url));};document.head.appendChild(link);});};
|
|
88
59
|
window.$forge.requestMarketplaceInstall=function(itemId,itemType,options){
|
|
89
60
|
var appName=(options&&options.initiator)||sessionStorage.getItem('forge_app_name')||'';
|
|
90
61
|
var params=new URLSearchParams();
|
|
@@ -92,226 +63,91 @@ export function forgeDevKernelPlugin(appName, platformUrl) {
|
|
|
92
63
|
params.set('type',itemType);
|
|
93
64
|
if(appName)params.set('initiator',appName);
|
|
94
65
|
var installUrl=_platformUrl+'/marketplace/install?'+params.toString();
|
|
66
|
+
var popup=openPlatformPopup(installUrl);
|
|
67
|
+
var waiting=showWaitingOverlay('Waiting for installation confirmation\u2026');
|
|
95
68
|
return new Promise(function(resolve,reject){
|
|
96
|
-
var
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
var closeBtn=document.createElement('button');
|
|
101
|
-
closeBtn.textContent='\u00D7';
|
|
102
|
-
closeBtn.style.cssText='position:absolute;top:10px;right:12px;z-index:3;background:rgba(255,255,255,0.12);border:1px solid rgba(255,255,255,0.15);color:#fff;font-size:1.25rem;line-height:1;width:30px;height:30px;border-radius:50%;cursor:pointer;display:flex;align-items:center;justify-content:center;';
|
|
103
|
-
var loader=document.createElement('div');
|
|
104
|
-
loader.style.cssText='position:absolute;inset:0;display:flex;align-items:center;justify-content:center;background:#0f0f10;z-index:2;pointer-events:none;';
|
|
105
|
-
var spinner=document.createElement('div');
|
|
106
|
-
spinner.style.cssText='width:36px;height:36px;border:3px solid rgba(255,255,255,0.12);border-top-color:#fff;border-radius:50%;animation:forge-spin 0.7s linear infinite;';
|
|
107
|
-
var style=document.createElement('style');
|
|
108
|
-
style.textContent='@keyframes forge-spin{to{transform:rotate(360deg)}}';
|
|
109
|
-
loader.appendChild(style);
|
|
110
|
-
loader.appendChild(spinner);
|
|
111
|
-
var iframe=document.createElement('iframe');
|
|
112
|
-
iframe.style.cssText='width:100%;height:100%;border:none;display:block;';
|
|
113
|
-
iframe.addEventListener('load',function(){loader.style.display='none';});
|
|
114
|
-
dialog.appendChild(closeBtn);
|
|
115
|
-
dialog.appendChild(loader);
|
|
116
|
-
dialog.appendChild(iframe);
|
|
117
|
-
overlay.appendChild(dialog);
|
|
118
|
-
document.body.appendChild(overlay);
|
|
119
|
-
setTimeout(function(){iframe.src=installUrl;},0);
|
|
120
|
-
function cleanup(){
|
|
121
|
-
window.removeEventListener('message',onMessage);
|
|
122
|
-
overlay.remove();
|
|
123
|
-
}
|
|
69
|
+
var pollTimer=setInterval(function(){
|
|
70
|
+
if(popup&&popup.closed){cleanup();reject(new Error('[ptkl forge dev] Marketplace install dialog closed.'));}
|
|
71
|
+
},500);
|
|
72
|
+
function cleanup(){clearInterval(pollTimer);window.removeEventListener('message',onMessage);if(popup&&!popup.closed)popup.close();waiting.close();}
|
|
124
73
|
function onMessage(e){
|
|
125
74
|
if(e.origin!==_platformUrl)return;
|
|
126
75
|
if(!e.data)return;
|
|
127
|
-
if(e.data.type==='marketplace_install_done'){
|
|
128
|
-
|
|
129
|
-
resolve({id:e.data.item_id,type:e.data.item_type,already_installed:e.data.already_installed||false});
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
if(e.data.type==='marketplace_install_denied'){
|
|
133
|
-
cleanup();
|
|
134
|
-
reject(new Error('[ptkl forge dev] Installation cancelled.'));
|
|
135
|
-
}
|
|
76
|
+
if(e.data.type==='marketplace_install_done'){cleanup();resolve({id:e.data.item_id,type:e.data.item_type,already_installed:e.data.already_installed||false});return;}
|
|
77
|
+
if(e.data.type==='marketplace_install_denied'){cleanup();reject(new Error('[ptkl forge dev] Installation cancelled.'));}
|
|
136
78
|
}
|
|
137
79
|
window.addEventListener('message',onMessage);
|
|
138
|
-
closeBtn.addEventListener('click',function(){
|
|
139
|
-
cleanup();
|
|
140
|
-
reject(new Error('[ptkl forge dev] Marketplace install dialog closed.'));
|
|
141
|
-
});
|
|
142
|
-
overlay.addEventListener('click',function(e){
|
|
143
|
-
if(e.target===overlay){
|
|
144
|
-
cleanup();
|
|
145
|
-
reject(new Error('[ptkl forge dev] Marketplace install dialog closed.'));
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
80
|
});
|
|
149
81
|
};
|
|
150
82
|
window.$forge.openDeveloperIntegrations=function(){
|
|
151
83
|
var integrationsUrl=_platformUrl+'/admin/developer/integrations';
|
|
84
|
+
var popup=openPlatformPopup(integrationsUrl);
|
|
85
|
+
var waiting=showWaitingOverlay('Managing integrations\u2026');
|
|
152
86
|
return new Promise(function(resolve){
|
|
153
|
-
var
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
dialog.style.cssText='position:relative;width:860px;max-width:calc(100vw - 2rem);height:80vh;max-height:calc(100vh - 4rem);border-radius:16px;overflow:hidden;box-shadow:0 32px 80px rgba(0,0,0,0.8);';
|
|
157
|
-
var closeBtn=document.createElement('button');
|
|
158
|
-
closeBtn.textContent='\u00D7';
|
|
159
|
-
closeBtn.style.cssText='position:absolute;top:10px;right:12px;z-index:3;background:rgba(255,255,255,0.12);border:1px solid rgba(255,255,255,0.15);color:#fff;font-size:1.25rem;line-height:1;width:30px;height:30px;border-radius:50%;cursor:pointer;display:flex;align-items:center;justify-content:center;';
|
|
160
|
-
var loader=document.createElement('div');
|
|
161
|
-
loader.style.cssText='position:absolute;inset:0;display:flex;align-items:center;justify-content:center;background:#0f0f10;z-index:2;pointer-events:none;';
|
|
162
|
-
var spinner=document.createElement('div');
|
|
163
|
-
spinner.style.cssText='width:36px;height:36px;border:3px solid rgba(255,255,255,0.12);border-top-color:#fff;border-radius:50%;animation:forge-spin 0.7s linear infinite;';
|
|
164
|
-
var style=document.createElement('style');
|
|
165
|
-
style.textContent='@keyframes forge-spin{to{transform:rotate(360deg)}}';
|
|
166
|
-
loader.appendChild(style);
|
|
167
|
-
loader.appendChild(spinner);
|
|
168
|
-
var iframe=document.createElement('iframe');
|
|
169
|
-
iframe.style.cssText='width:100%;height:100%;border:none;display:block;';
|
|
170
|
-
iframe.addEventListener('load',function(){loader.style.display='none';});
|
|
171
|
-
dialog.appendChild(closeBtn);
|
|
172
|
-
dialog.appendChild(loader);
|
|
173
|
-
dialog.appendChild(iframe);
|
|
174
|
-
overlay.appendChild(dialog);
|
|
175
|
-
document.body.appendChild(overlay);
|
|
176
|
-
setTimeout(function(){iframe.src=integrationsUrl;},0);
|
|
177
|
-
function cleanup(){overlay.remove();resolve();}
|
|
178
|
-
closeBtn.addEventListener('click',cleanup);
|
|
179
|
-
overlay.addEventListener('click',function(e){if(e.target===overlay)cleanup();});
|
|
87
|
+
var pollTimer=setInterval(function(){
|
|
88
|
+
if(popup&&popup.closed){clearInterval(pollTimer);waiting.close();resolve();}
|
|
89
|
+
},500);
|
|
180
90
|
});
|
|
181
91
|
};
|
|
182
92
|
window.$forge.openOnboarding=function(){
|
|
183
93
|
if(window!==window.top)return Promise.resolve({completed:false});
|
|
184
94
|
var onboardingUrl=_platformUrl+'/onboarding';
|
|
95
|
+
var popup=openPlatformPopup(onboardingUrl);
|
|
96
|
+
var waiting=showWaitingOverlay('Completing onboarding\u2026');
|
|
185
97
|
return new Promise(function(resolve){
|
|
186
|
-
var
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
var closeBtn=document.createElement('button');
|
|
191
|
-
closeBtn.textContent='\u00D7';
|
|
192
|
-
closeBtn.style.cssText='position:absolute;top:10px;right:12px;z-index:3;background:rgba(255,255,255,0.12);border:1px solid rgba(255,255,255,0.15);color:#fff;font-size:1.25rem;line-height:1;width:30px;height:30px;border-radius:50%;cursor:pointer;display:flex;align-items:center;justify-content:center;';
|
|
193
|
-
var loader=document.createElement('div');
|
|
194
|
-
loader.style.cssText='position:absolute;inset:0;display:flex;align-items:center;justify-content:center;background:#0f0f10;z-index:2;pointer-events:none;';
|
|
195
|
-
var spinner=document.createElement('div');
|
|
196
|
-
spinner.style.cssText='width:36px;height:36px;border:3px solid rgba(255,255,255,0.12);border-top-color:#fff;border-radius:50%;animation:forge-spin 0.7s linear infinite;';
|
|
197
|
-
var style=document.createElement('style');
|
|
198
|
-
style.textContent='@keyframes forge-spin{to{transform:rotate(360deg)}}';
|
|
199
|
-
loader.appendChild(style);
|
|
200
|
-
loader.appendChild(spinner);
|
|
201
|
-
var iframe=document.createElement('iframe');
|
|
202
|
-
iframe.style.cssText='width:100%;height:100%;border:none;display:block;';
|
|
203
|
-
iframe.addEventListener('load',function(){loader.style.display='none';});
|
|
204
|
-
dialog.appendChild(closeBtn);
|
|
205
|
-
dialog.appendChild(loader);
|
|
206
|
-
dialog.appendChild(iframe);
|
|
207
|
-
overlay.appendChild(dialog);
|
|
208
|
-
document.body.appendChild(overlay);
|
|
209
|
-
setTimeout(function(){iframe.src=onboardingUrl;},0);
|
|
210
|
-
function cleanup(){
|
|
211
|
-
window.removeEventListener('message',onMessage);
|
|
212
|
-
overlay.remove();
|
|
213
|
-
}
|
|
98
|
+
var pollTimer=setInterval(function(){
|
|
99
|
+
if(popup&&popup.closed){cleanup();resolve({completed:false});}
|
|
100
|
+
},500);
|
|
101
|
+
function cleanup(){clearInterval(pollTimer);window.removeEventListener('message',onMessage);if(popup&&!popup.closed)popup.close();waiting.close();}
|
|
214
102
|
function onMessage(e){
|
|
215
103
|
if(e.origin!==_platformUrl)return;
|
|
216
104
|
if(!e.data)return;
|
|
217
105
|
if(e.data.type==='forge_onboarding_complete'){cleanup();resolve({completed:true});}
|
|
218
106
|
}
|
|
219
107
|
window.addEventListener('message',onMessage);
|
|
220
|
-
closeBtn.addEventListener('click',function(){cleanup();resolve({completed:false});});
|
|
221
|
-
overlay.addEventListener('click',function(e){if(e.target===overlay){cleanup();resolve({completed:false});}});
|
|
222
108
|
});
|
|
223
109
|
};
|
|
224
|
-
var
|
|
110
|
+
var _supportTicketPopup=null;
|
|
225
111
|
var _supportTicketOnMessage=null;
|
|
112
|
+
var _supportTicketPollTimer=null;
|
|
226
113
|
window.$forge.closeSupportTicketDialog=function(){
|
|
227
|
-
if(_supportTicketOnMessage){
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
if(_supportTicketOverlay){
|
|
232
|
-
_supportTicketOverlay.remove();
|
|
233
|
-
_supportTicketOverlay=null;
|
|
234
|
-
}
|
|
114
|
+
if(_supportTicketOnMessage){window.removeEventListener('message',_supportTicketOnMessage);_supportTicketOnMessage=null;}
|
|
115
|
+
if(_supportTicketPollTimer){clearInterval(_supportTicketPollTimer);_supportTicketPollTimer=null;}
|
|
116
|
+
if(_supportTicketPopup&&!_supportTicketPopup.closed){_supportTicketPopup.close();}
|
|
117
|
+
_supportTicketPopup=null;
|
|
235
118
|
};
|
|
236
119
|
window.$forge.createSupportTicket=function(options){
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
iframe.addEventListener('load',function(){loader.style.display='none';});
|
|
265
|
-
dialog.appendChild(closeBtn);
|
|
266
|
-
dialog.appendChild(loader);
|
|
267
|
-
dialog.appendChild(iframe);
|
|
268
|
-
overlay.appendChild(dialog);
|
|
269
|
-
document.body.appendChild(overlay);
|
|
270
|
-
_supportTicketOverlay=overlay;
|
|
271
|
-
setTimeout(function(){iframe.src=ticketUrl;},0);
|
|
272
|
-
var settled=false;
|
|
273
|
-
function resolveOnce(result){if(settled)return;settled=true;resolve(result);}
|
|
274
|
-
function onMessage(e){
|
|
275
|
-
if(e.origin!==_platformUrl)return;
|
|
276
|
-
if(!e.data)return;
|
|
277
|
-
if(e.data.type==='support_ticket_close'){window.$forge.closeSupportTicketDialog();resolveOnce({created:false});return;}
|
|
278
|
-
if(e.data.type==='support_ticket_created'){resolveOnce({created:true,ticket:e.data.ticket||null});return;}
|
|
279
|
-
if(e.data.type==='support_ticket_denied'){window.$forge.closeSupportTicketDialog();resolveOnce({created:false});}
|
|
280
|
-
}
|
|
281
|
-
_supportTicketOnMessage=onMessage;
|
|
282
|
-
window.addEventListener('message',onMessage);
|
|
283
|
-
closeBtn.addEventListener('click',function(){window.$forge.closeSupportTicketDialog();resolveOnce({created:false});});
|
|
284
|
-
overlay.addEventListener('click',function(e){if(e.target===overlay){window.$forge.closeSupportTicketDialog();resolveOnce({created:false});}});
|
|
285
|
-
});
|
|
286
|
-
};
|
|
287
|
-
})();`
|
|
288
|
-
: `(function(){
|
|
289
|
-
window.$forge=window.forge||{};
|
|
290
|
-
window.$forge.requestPermissions=function(){
|
|
291
|
-
console.warn('[ptkl forge dev] window.$forge.requestPermissions unavailable — pass --platform-url <url> to enable.');
|
|
292
|
-
return Promise.reject(new Error('requestPermissions requires --platform-url in ptkl forge dev'));
|
|
293
|
-
};
|
|
294
|
-
window.$forge.requestMarketplaceInstall=function(){
|
|
295
|
-
console.warn('[ptkl forge dev] window.$forge.requestMarketplaceInstall unavailable — pass --platform-url <url> to enable.');
|
|
296
|
-
return Promise.reject(new Error('requestMarketplaceInstall requires --platform-url in ptkl forge dev'));
|
|
297
|
-
};
|
|
298
|
-
window.$forge.openDeveloperIntegrations=function(){
|
|
299
|
-
console.warn('[ptkl forge dev] window.$forge.openDeveloperIntegrations unavailable — pass --platform-url <url> to enable.');
|
|
300
|
-
return Promise.resolve();
|
|
301
|
-
};
|
|
302
|
-
window.$forge.openOnboarding=function(){
|
|
303
|
-
console.warn('[ptkl forge dev] window.$forge.openOnboarding unavailable — pass --platform-url <url> to enable.');
|
|
304
|
-
return Promise.resolve({completed:false});
|
|
305
|
-
};
|
|
306
|
-
window.$forge.createSupportTicket=function(){
|
|
307
|
-
console.warn('[ptkl forge dev] window.$forge.createSupportTicket unavailable — pass --platform-url <url> to enable.');
|
|
308
|
-
return Promise.reject(new Error('createSupportTicket requires --platform-url in ptkl forge dev'));
|
|
309
|
-
};
|
|
310
|
-
window.$forge.closeSupportTicketDialog=function(){
|
|
311
|
-
console.warn('[ptkl forge dev] window.$forge.closeSupportTicketDialog unavailable — pass --platform-url <url> to enable.');
|
|
120
|
+
var defaults=(options&&options.defaults)||{};
|
|
121
|
+
var params=new URLSearchParams();
|
|
122
|
+
if(defaults.subject)params.set('subject',defaults.subject);
|
|
123
|
+
if(defaults.description)params.set('description',defaults.description);
|
|
124
|
+
if(defaults.topic)params.set('topic',defaults.topic);
|
|
125
|
+
if(defaults.priority)params.set('priority',defaults.priority);
|
|
126
|
+
var qs=params.toString();
|
|
127
|
+
var ticketUrl=_platformUrl+'/support/create-ticket'+(qs?'?'+qs:'');
|
|
128
|
+
return new Promise(function(resolve){
|
|
129
|
+
window.$forge.closeSupportTicketDialog();
|
|
130
|
+
_supportTicketPopup=openPlatformPopup(ticketUrl);
|
|
131
|
+
var waiting=showWaitingOverlay('Creating support ticket\u2026');
|
|
132
|
+
var settled=false;
|
|
133
|
+
function resolveOnce(result){if(settled)return;settled=true;waiting.close();resolve(result);}
|
|
134
|
+
_supportTicketPollTimer=setInterval(function(){
|
|
135
|
+
if(_supportTicketPopup&&_supportTicketPopup.closed){window.$forge.closeSupportTicketDialog();resolveOnce({created:false});}
|
|
136
|
+
},500);
|
|
137
|
+
function onMessage(e){
|
|
138
|
+
if(e.origin!==_platformUrl)return;
|
|
139
|
+
if(!e.data)return;
|
|
140
|
+
if(e.data.type==='support_ticket_close'){window.$forge.closeSupportTicketDialog();resolveOnce({created:false});return;}
|
|
141
|
+
if(e.data.type==='support_ticket_created'){resolveOnce({created:true,ticket:e.data.ticket||null});return;}
|
|
142
|
+
if(e.data.type==='support_ticket_denied'){window.$forge.closeSupportTicketDialog();resolveOnce({created:false});}
|
|
143
|
+
}
|
|
144
|
+
_supportTicketOnMessage=onMessage;
|
|
145
|
+
window.addEventListener('message',onMessage);
|
|
146
|
+
});
|
|
312
147
|
};
|
|
313
|
-
window.$forge.dynamicImport=function(url){return import(url).then(function(){})};
|
|
314
|
-
window.$forge.dynamicImportCSS=function(url){return new Promise(function(resolve,reject){var link=document.createElement('link');link.rel='stylesheet';link.href=url;link.onload=function(){resolve();};link.onerror=function(){reject(new Error('Failed to load CSS: '+url));};document.head.appendChild(link);});};
|
|
148
|
+
window.$forge.dynamicImport=function(url){return import(url).then(function(){});};
|
|
149
|
+
window.$forge.dynamicImportCSS=function(url){return new Promise(function(resolve,reject){var link=document.createElement('link');link.rel='stylesheet';link.href=url;link.onload=function(){resolve();};link.onerror=function(){reject(new Error('Failed to load CSS: '+url));};document.head.appendChild(link);});};
|
|
150
|
+
console.log('[ptkl forge dev] window.forge ready (platform: '+_platformUrl+')');
|
|
315
151
|
})();`;
|
|
316
152
|
return {
|
|
317
153
|
name: 'ptkl-forge-dev-kernel',
|