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,5 @@
/*!
* Copyright (C) Microsoft Corporation. All rights reserved.
*/
export { powerApps } from './powerApps.js';
//# sourceMappingURL=index.d.ts.map
@@ -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,5 @@
/*!
* Copyright (C) Microsoft Corporation. All rights reserved.
*/
export { powerApps } from './powerApps.js';
//# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/plugin/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,6 @@
/*!
* Copyright (C) Microsoft Corporation. All rights reserved.
*/
import type { Plugin } from 'vite';
export declare function powerApps(): Plugin;
//# sourceMappingURL=powerApps.d.ts.map
@@ -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,183 @@
import pc from 'picocolors';
import { readFileSync } from 'node:fs';
import { join } from 'node:path';
import { isOriginAllowed, isPowerConfig, powerAppsCorsOrigins, powerConfigPath } from './utils.js';
export function powerApps() {
return {
name: 'powerApps',
config() {
return {
// Needed for publishing static assets correctly
base: './',
// Automatically inject CORS configuration needed for Vite 7+
server: {
cors: {
origin: powerAppsCorsOrigins,
},
},
};
},
configureServer(server) {
printLocalPlayUrl(server);
servePowerConfig(server);
watchPowerConfig(server);
},
};
}
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
const address = server.httpServer.address();
if (typeof address === 'string') {
return address;
}
if (typeof address === 'object' && address !== null) {
const { address: rawHost, port } = address;
const host = rawHost === '::1' ? 'localhost' : rawHost;
const https = server.config.server.https;
return `${https ? 'https' : 'http'}://${host}:${port}/`;
}
return null;
}
// Cache for power config to avoid repeated file reads
let cachedPowerConfig = null;
function getPowerConfig(server) {
if (cachedPowerConfig) {
return cachedPowerConfig;
}
const configPath = join(server.config.root, 'power.config.json');
try {
const configContent = readFileSync(configPath, 'utf-8');
const parsed = JSON.parse(configContent);
if (!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 ${configPath}.`);
}
if (error instanceof SyntaxError) {
throw new Error(`Invalid JSON in power.config.json: ${error.message}`);
}
throw error;
}
}
function watchPowerConfig(server) {
const configPath = join(server.config.root, 'power.config.json');
server.watcher.add(configPath);
server.watcher.on('change', (file) => {
if (file === configPath) {
server.config.logger.info(pc.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', () => {
var _a;
let powerConfig;
try {
powerConfig = getPowerConfig(server);
}
catch (error) {
server.config.logger.error(pc.red(`[powerApps] Error loading power.config.json:\n${(_a = error.message) !== null && _a !== void 0 ? _a : error}`));
return;
}
const environmentId = powerConfig.environmentId;
if (!environmentId) {
server.config.logger.error('[powerApps] environmentId is not defined in power.config.json');
return;
}
const baseUrl = getLocalBaseUrl(server);
if (!baseUrl) {
server.config.logger.error('[powerApps] Unable to determine vite dev server URL');
return;
}
const localAppUrl = `${baseUrl}`;
const localConnectionUrl = `${baseUrl}${powerConfigPath}`;
const playUrl = `${pc.magenta(`${getWebPlayerBaseUrl(powerConfig.region || 'prod')}/play/e/`) +
pc.magentaBright(environmentId) +
pc.magenta('/a/local')}` +
`${pc.magenta('?_localAppUrl=') + pc.magentaBright(localAppUrl)}` +
`${pc.magenta('&_localConnectionUrl=') + pc.magentaBright(localConnectionUrl)}` +
`${pc.reset('')}`;
// Nicely formatted console output
server.config.logger.info(` ${pc.magentaBright('Power Apps Vite Plugin')}\n`);
server.config.logger.info(` ${pc.magenta('➜')} Local Play: ${playUrl}`);
});
}
// Serves the power.config.json content at a specific path to be accessed by apps.powerapps.com
function servePowerConfig(server) {
server.middlewares.use(`/${powerConfigPath}`, (req, res) => {
var _a;
// Manual CORS headers are needed for Vite 6 and below
const origin = req.headers.origin;
if (origin && 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');
let powerConfig;
try {
powerConfig = getPowerConfig(server);
}
catch (error) {
server.config.logger.error(pc.red(`[powerApps] Error serving power.config.json:\n${(_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,49 @@
/*!
* 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;
//# sourceMappingURL=utils.d.ts.map
@@ -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,83 @@
/*!
* Copyright (C) Microsoft Corporation. All rights reserved.
*/
/**
* CORS origin patterns for Power Apps domains
*/
export const 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
*/
export const powerConfigPath = '__vite_powerapps_plugin__/power.config.json';
/**
* Type guard to validate PowerConfig structure
*/
export function isPowerConfig(obj) {
return (typeof obj === 'object' &&
obj !== null &&
'environmentId' in obj &&
typeof obj.environmentId === 'string');
}
/**
* Check if an origin is allowed by the CORS patterns
*/
export function isOriginAllowed(origin) {
return powerAppsCorsOrigins.some((pattern) => pattern.test(origin));
}
/**
* Generate the Power Apps local play URL
*/
export function generatePlayUrl(environmentId, localAppUrl, localConnectionUrl) {
return (`https://apps.powerapps.com/play/e/${environmentId}/a/local` +
`?_localAppUrl=${encodeURIComponent(localAppUrl)}` +
`&_localConnectionUrl=${encodeURIComponent(localConnectionUrl)}`);
}
/**
* Parse power.config.json content and validate it
* @throws Error if the content is invalid
*/
export function parsePowerConfig(content) {
let parsed;
try {
parsed = JSON.parse(content);
}
catch (error) {
if (error instanceof SyntaxError) {
throw new Error(`Invalid JSON in power.config.json: ${error.message}`);
}
throw error;
}
if (!isPowerConfig(parsed)) {
throw new Error('Invalid power.config.json structure. Missing environmentId.');
}
return parsed;
}
/**
* Generate the local connection URL from a base URL
*/
export function getLocalConnectionUrl(baseUrl) {
// Ensure base URL ends with /
const normalizedBase = baseUrl.endsWith('/') ? baseUrl : `${baseUrl}/`;
return `${normalizedBase}${powerConfigPath}`;
}
//# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/plugin/utils.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