push neon reactor

This commit is contained in:
2026-07-12 15:11:38 +02:00
parent 172e72dbcd
commit aeab5f7820
9597 changed files with 2407488 additions and 0 deletions
@@ -0,0 +1,4 @@
/*!
* Copyright (C) Microsoft Corporation. All rights reserved.
*/
export { powerApps } from './plugin/index.js';
@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,9 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.powerApps = void 0;
/*!
* Copyright (C) Microsoft Corporation. All rights reserved.
*/
var index_js_1 = require("./plugin/index.js");
Object.defineProperty(exports, "powerApps", { enumerable: true, get: function () { return index_js_1.powerApps; } });
//# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,8CAA8C;AAArC,qGAAA,SAAS,OAAA"}
@@ -0,0 +1,4 @@
/*!
* Copyright (C) Microsoft Corporation. All rights reserved.
*/
export { powerApps } from './powerApps.js';
@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugin/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,9 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.powerApps = void 0;
/*!
* Copyright (C) Microsoft Corporation. All rights reserved.
*/
var powerApps_js_1 = require("./powerApps.js");
Object.defineProperty(exports, "powerApps", { enumerable: true, get: function () { return powerApps_js_1.powerApps; } });
//# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/plugin/index.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,+CAA2C;AAAlC,yGAAA,SAAS,OAAA"}
@@ -0,0 +1,5 @@
/*!
* Copyright (C) Microsoft Corporation. All rights reserved.
*/
import type { Plugin } from 'vite';
export declare function powerApps(): Plugin;
@@ -0,0 +1 @@
{"version":3,"file":"powerApps.d.ts","sourceRoot":"","sources":["../../src/plugin/powerApps.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,MAAM,EAAiB,MAAM,MAAM,CAAC;AAOlD,wBAAgB,SAAS,IAAI,MAAM,CAqBlC"}
@@ -0,0 +1,190 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.powerApps = void 0;
var picocolors_1 = __importDefault(require("picocolors"));
var node_fs_1 = require("node:fs");
var node_path_1 = require("node:path");
var utils_js_1 = require("./utils.js");
function powerApps() {
return {
name: 'powerApps',
config: function () {
return {
// Needed for publishing static assets correctly
base: './',
// Automatically inject CORS configuration needed for Vite 7+
server: {
cors: {
origin: utils_js_1.powerAppsCorsOrigins,
},
},
};
},
configureServer: function (server) {
printLocalPlayUrl(server);
servePowerConfig(server);
watchPowerConfig(server);
},
};
}
exports.powerApps = powerApps;
function getLocalBaseUrl(server) {
var _a, _b;
// Vite 6+
if ((_b = (_a = server.resolvedUrls) === null || _a === void 0 ? void 0 : _a.local) === null || _b === void 0 ? void 0 : _b[0]) {
return server.resolvedUrls.local[0];
}
// In Vite 5 and below, resolvedUrls may not be available, fallback to httpServer address
var address = server.httpServer.address();
if (typeof address === 'string') {
return address;
}
if (typeof address === 'object' && address !== null) {
var rawHost = address.address, port = address.port;
var host = rawHost === '::1' ? 'localhost' : rawHost;
var https = server.config.server.https;
return "".concat(https ? 'https' : 'http', "://").concat(host, ":").concat(port, "/");
}
return null;
}
// Cache for power config to avoid repeated file reads
var cachedPowerConfig = null;
function getPowerConfig(server) {
if (cachedPowerConfig) {
return cachedPowerConfig;
}
var configPath = (0, node_path_1.join)(server.config.root, 'power.config.json');
try {
var configContent = (0, node_fs_1.readFileSync)(configPath, 'utf-8');
var parsed = JSON.parse(configContent);
if (!(0, utils_js_1.isPowerConfig)(parsed)) {
throw new Error('Invalid power.config.json structure. Missing environmentId.');
}
cachedPowerConfig = parsed;
return parsed;
}
catch (error) {
// Handle specific error types
if (error.code === 'ENOENT') {
throw new Error("Missing file. Ensure you have run 'pac code init' first. power.config.json expected at ".concat(configPath, "."));
}
if (error instanceof SyntaxError) {
throw new Error("Invalid JSON in power.config.json: ".concat(error.message));
}
throw error;
}
}
function watchPowerConfig(server) {
var configPath = (0, node_path_1.join)(server.config.root, 'power.config.json');
server.watcher.add(configPath);
server.watcher.on('change', function (file) {
if (file === configPath) {
server.config.logger.info(picocolors_1.default.yellow('[powerApps] power.config.json changed, restarting server...'));
// Clear cache so new config is loaded
cachedPowerConfig = null;
server.restart();
}
});
}
function getWebPlayerBaseUrl(region) {
if (!region) {
return 'https://apps.powerapps.com';
}
region = region.toLowerCase();
switch (region) {
case 'public':
case 'prod':
return 'https://apps.powerapps.com';
case 'preprod':
return 'https://apps.preprod.powerapps.com';
case 'test':
return 'https://apps.test.powerapps.com';
case 'preview':
return 'https://apps.preview.powerapps.com';
case 'usgov':
case 'gccmoderate':
return 'https://apps.gov.powerapps.us';
case 'usgovhigh':
case 'gcchigh':
return 'https://apps.high.powerapps.us';
case 'usgovdod':
case 'dod':
return 'https://play.apps.appsplatform.us';
case 'china':
case 'mooncake':
return 'https://apps.powerapps.cn';
default:
return 'https://apps.powerapps.com';
}
}
// Prints the apps.powerapps.com play URL to the console
function printLocalPlayUrl(server) {
var _a;
(_a = server.httpServer) === null || _a === void 0 ? void 0 : _a.on('listening', function () {
var _a;
var powerConfig;
try {
powerConfig = getPowerConfig(server);
}
catch (error) {
server.config.logger.error(picocolors_1.default.red("[powerApps] Error loading power.config.json:\n \u2937".concat((_a = error.message) !== null && _a !== void 0 ? _a : error)));
return;
}
var environmentId = powerConfig.environmentId;
if (!environmentId) {
server.config.logger.error('[powerApps] environmentId is not defined in power.config.json');
return;
}
var baseUrl = getLocalBaseUrl(server);
if (!baseUrl) {
server.config.logger.error('[powerApps] Unable to determine vite dev server URL');
return;
}
var localAppUrl = "".concat(baseUrl);
var localConnectionUrl = "".concat(baseUrl).concat(utils_js_1.powerConfigPath);
var playUrl = "".concat(picocolors_1.default.magenta("".concat(getWebPlayerBaseUrl(powerConfig.region || 'prod'), "/play/e/")) +
picocolors_1.default.magentaBright(environmentId) +
picocolors_1.default.magenta('/a/local')) +
"".concat(picocolors_1.default.magenta('?_localAppUrl=') + picocolors_1.default.magentaBright(localAppUrl)) +
"".concat(picocolors_1.default.magenta('&_localConnectionUrl=') + picocolors_1.default.magentaBright(localConnectionUrl)) +
"".concat(picocolors_1.default.reset(''));
// Nicely formatted console output
server.config.logger.info(" ".concat(picocolors_1.default.magentaBright('Power Apps Vite Plugin'), "\n"));
server.config.logger.info(" ".concat(picocolors_1.default.magenta('➜'), " Local Play: ").concat(playUrl));
});
}
// Serves the power.config.json content at a specific path to be accessed by apps.powerapps.com
function servePowerConfig(server) {
server.middlewares.use("/".concat(utils_js_1.powerConfigPath), function (req, res) {
var _a;
// Manual CORS headers are needed for Vite 6 and below
var origin = req.headers.origin;
if (origin && (0, utils_js_1.isOriginAllowed)(origin)) {
res.setHeader('Access-Control-Allow-Origin', origin);
res.setHeader('Access-Control-Allow-Methods', 'GET, OPTIONS');
res.setHeader('Access-Control-Allow-Headers', '*');
}
if (req.method === 'OPTIONS') {
res.statusCode = 204;
res.end();
return;
}
res.setHeader('Content-Type', 'application/json; charset=utf-8');
res.setHeader('Cache-Control', 'no-store');
var powerConfig;
try {
powerConfig = getPowerConfig(server);
}
catch (error) {
server.config.logger.error(picocolors_1.default.red("[powerApps] Error serving power.config.json:\n \u2937".concat((_a = error.message) !== null && _a !== void 0 ? _a : error)));
// Player can sometimes work without power.config.json
res.end();
return;
}
res.end(JSON.stringify(powerConfig));
});
}
//# sourceMappingURL=powerApps.js.map
File diff suppressed because one or more lines are too long
@@ -0,0 +1,48 @@
/*!
* Copyright (C) Microsoft Corporation. All rights reserved.
*/
/**
* Power Apps config file structure from pac cli
*/
export interface PowerConfig {
appId?: string;
appDisplayName?: string;
description?: string | null;
environmentId: string;
buildPath?: string;
buildEntryPoint?: string;
logoPath?: string;
localAppUrl?: string;
connectionReferences?: unknown;
databaseReferences?: unknown;
region?: string;
}
/**
* CORS origin patterns for Power Apps domains
*/
export declare const powerAppsCorsOrigins: RegExp[];
/**
* Path used to serve power.config.json content
*/
export declare const powerConfigPath = "__vite_powerapps_plugin__/power.config.json";
/**
* Type guard to validate PowerConfig structure
*/
export declare function isPowerConfig(obj: unknown): obj is PowerConfig;
/**
* Check if an origin is allowed by the CORS patterns
*/
export declare function isOriginAllowed(origin: string): boolean;
/**
* Generate the Power Apps local play URL
*/
export declare function generatePlayUrl(environmentId: string, localAppUrl: string, localConnectionUrl: string): string;
/**
* Parse power.config.json content and validate it
* @throws Error if the content is invalid
*/
export declare function parsePowerConfig(content: string): PowerConfig;
/**
* Generate the local connection URL from a base URL
*/
export declare function getLocalConnectionUrl(baseUrl: string): string;
@@ -0,0 +1 @@
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/plugin/utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,eAAO,MAAM,oBAAoB,EAAE,MAAM,EAoBxC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,eAAe,gDAAgD,CAAC;AAE7E;;GAEG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,WAAW,CAO9D;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAEvD;AAED;;GAEG;AACH,wBAAgB,eAAe,CAC7B,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,MAAM,EACnB,kBAAkB,EAAE,MAAM,GACzB,MAAM,CAMR;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,WAAW,CAgB7D;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAI7D"}
@@ -0,0 +1,91 @@
"use strict";
/*!
* Copyright (C) Microsoft Corporation. All rights reserved.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.getLocalConnectionUrl = exports.parsePowerConfig = exports.generatePlayUrl = exports.isOriginAllowed = exports.isPowerConfig = exports.powerConfigPath = exports.powerAppsCorsOrigins = void 0;
/**
* CORS origin patterns for Power Apps domains
*/
exports.powerAppsCorsOrigins = [
// vite default localhost origins
// eslint-disable-next-line security/detect-unsafe-regex -- input bounded by origin header length
/^https?:\/\/(?:(?:[^:]+\.)?localhost|127\.0\.0\.1|\[::1\])(?::\d+)?$/,
// apps.powerapps.com
/^https:\/\/apps\.powerapps\.com$/,
// apps.*.powerapps.com
// eslint-disable-next-line security/detect-unsafe-regex -- input bounded by origin header length
/^https:\/\/apps\.(?:[^.]+\.)*powerapps\.com$/,
// apps.*.powerapps.us
// eslint-disable-next-line security/detect-unsafe-regex -- input bounded by origin header length
/^https:\/\/apps\.(?:[^.]+\.)*powerapps\.us$/,
// play.apps.appsplatform.us
/^https:\/\/play\.apps\.appsplatform\.us$/,
// apps.powerapps.cn
/^https:\/\/apps\.powerapps\.cn$/,
// apps.powerapps.eaglex.ic.gov
/^https:\/\/apps\.powerapps\.eaglex\.ic\.gov$/,
// apps.powerapps.microsoft.scloud
/^https:\/\/apps\.powerapps\.microsoft\.scloud$/,
];
/**
* Path used to serve power.config.json content
*/
exports.powerConfigPath = '__vite_powerapps_plugin__/power.config.json';
/**
* Type guard to validate PowerConfig structure
*/
function isPowerConfig(obj) {
return (typeof obj === 'object' &&
obj !== null &&
'environmentId' in obj &&
typeof obj.environmentId === 'string');
}
exports.isPowerConfig = isPowerConfig;
/**
* Check if an origin is allowed by the CORS patterns
*/
function isOriginAllowed(origin) {
return exports.powerAppsCorsOrigins.some(function (pattern) { return pattern.test(origin); });
}
exports.isOriginAllowed = isOriginAllowed;
/**
* Generate the Power Apps local play URL
*/
function generatePlayUrl(environmentId, localAppUrl, localConnectionUrl) {
return ("https://apps.powerapps.com/play/e/".concat(environmentId, "/a/local") +
"?_localAppUrl=".concat(encodeURIComponent(localAppUrl)) +
"&_localConnectionUrl=".concat(encodeURIComponent(localConnectionUrl)));
}
exports.generatePlayUrl = generatePlayUrl;
/**
* Parse power.config.json content and validate it
* @throws Error if the content is invalid
*/
function parsePowerConfig(content) {
var parsed;
try {
parsed = JSON.parse(content);
}
catch (error) {
if (error instanceof SyntaxError) {
throw new Error("Invalid JSON in power.config.json: ".concat(error.message));
}
throw error;
}
if (!isPowerConfig(parsed)) {
throw new Error('Invalid power.config.json structure. Missing environmentId.');
}
return parsed;
}
exports.parsePowerConfig = parsePowerConfig;
/**
* Generate the local connection URL from a base URL
*/
function getLocalConnectionUrl(baseUrl) {
// Ensure base URL ends with /
var normalizedBase = baseUrl.endsWith('/') ? baseUrl : "".concat(baseUrl, "/");
return "".concat(normalizedBase).concat(exports.powerConfigPath);
}
exports.getLocalConnectionUrl = getLocalConnectionUrl;
//# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
{"version":3,"file":"utils.js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