mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) updates from grist-core
This commit is contained in:
@@ -72,6 +72,8 @@ export interface SandboxActionBundle {
|
||||
// Represents a unique call to the Python REQUEST function
|
||||
export interface SandboxRequest {
|
||||
url: string;
|
||||
method: string;
|
||||
body?: string;
|
||||
params: Record<string, string> | null;
|
||||
headers: Record<string, string> | null;
|
||||
deps: unknown; // pass back to the sandbox unchanged in the response
|
||||
|
||||
@@ -11,10 +11,10 @@ import {getAuthorizedUserId, getUserId, getUserProfiles, RequestWithLogin} from
|
||||
import {getSessionUser, linkOrgWithEmail} from 'app/server/lib/BrowserSession';
|
||||
import {expressWrap} from 'app/server/lib/expressWrap';
|
||||
import {RequestWithOrg} from 'app/server/lib/extractOrg';
|
||||
import {getTemplateOrg} from 'app/server/lib/gristSettings';
|
||||
import log from 'app/server/lib/log';
|
||||
import {addPermit, clearSessionCacheIfNeeded, getDocScope, getScope, integerParam,
|
||||
isParameterOn, optStringParam, sendOkReply, sendReply, stringParam} from 'app/server/lib/requestUtils';
|
||||
import {getTemplateOrg} from 'app/server/lib/sendAppPage';
|
||||
import {IWidgetRepository} from 'app/server/lib/WidgetRepository';
|
||||
|
||||
import {User} from './entity/User';
|
||||
|
||||
@@ -66,6 +66,11 @@ export async function main() {
|
||||
process.env.GRIST_EXPERIMENTAL_PLUGINS = "1";
|
||||
}
|
||||
|
||||
// Experimental plugins are enabled by default for devs
|
||||
if (!process.env.GRIST_ENABLE_REQUEST_FUNCTION) {
|
||||
process.env.GRIST_ENABLE_REQUEST_FUNCTION = "1";
|
||||
}
|
||||
|
||||
// For tests, it is useful to start with the database in a known state.
|
||||
// If TEST_CLEAN_DATABASE is set, we reset the database before starting.
|
||||
if (process.env.TEST_CLEAN_DATABASE) {
|
||||
|
||||
@@ -89,6 +89,7 @@ import {Authorizer} from 'app/server/lib/Authorizer';
|
||||
import {checksumFile} from 'app/server/lib/checksumFile';
|
||||
import {Client} from 'app/server/lib/Client';
|
||||
import {DEFAULT_CACHE_TTL, DocManager} from 'app/server/lib/DocManager';
|
||||
import {getTemplateOrg} from 'app/server/lib/gristSettings';
|
||||
import {ICreateActiveDocOptions} from 'app/server/lib/ICreate';
|
||||
import {makeForkIds} from 'app/server/lib/idUtils';
|
||||
import {GRIST_DOC_SQL, GRIST_DOC_WITH_TABLE1_SQL} from 'app/server/lib/initialDocSql';
|
||||
@@ -97,7 +98,6 @@ import log from 'app/server/lib/log';
|
||||
import {LogMethods} from "app/server/lib/LogMethods";
|
||||
import {NullSandbox, UnavailableSandboxMethodError} from 'app/server/lib/NullSandbox';
|
||||
import {DocRequests} from 'app/server/lib/Requests';
|
||||
import {getTemplateOrg} from 'app/server/lib/sendAppPage';
|
||||
import {shortDesc} from 'app/server/lib/shortDesc';
|
||||
import {TableMetadataLoader} from 'app/server/lib/TableMetadataLoader';
|
||||
import {DocTriggers} from "app/server/lib/Triggers";
|
||||
|
||||
@@ -20,10 +20,11 @@ import {DocStatus, IDocWorkerMap} from 'app/server/lib/DocWorkerMap';
|
||||
import {expressWrap} from 'app/server/lib/expressWrap';
|
||||
import {DocTemplate, GristServer} from 'app/server/lib/GristServer';
|
||||
import {getCookieDomain} from 'app/server/lib/gristSessions';
|
||||
import {getTemplateOrg} from 'app/server/lib/gristSettings';
|
||||
import {getAssignmentId} from 'app/server/lib/idUtils';
|
||||
import log from 'app/server/lib/log';
|
||||
import {adaptServerUrl, addOrgToPathIfNeeded, pruneAPIResult, trustOrigin} from 'app/server/lib/requestUtils';
|
||||
import {getTemplateOrg, ISendAppPageOptions} from 'app/server/lib/sendAppPage';
|
||||
import {ISendAppPageOptions} from 'app/server/lib/sendAppPage';
|
||||
|
||||
export interface AttachOptions {
|
||||
app: express.Application; // Express app to which to add endpoints
|
||||
|
||||
@@ -80,16 +80,21 @@ export class DocRequests {
|
||||
|
||||
private async _handleSingleRequestRaw(request: SandboxRequest): Promise<Response> {
|
||||
try {
|
||||
if (process.env.GRIST_EXPERIMENTAL_PLUGINS != '1') {
|
||||
if (process.env.GRIST_ENABLE_REQUEST_FUNCTION != '1') {
|
||||
throw new Error("REQUEST is not enabled");
|
||||
}
|
||||
const {url, params, headers} = request;
|
||||
const {url, method, body, params, headers} = request;
|
||||
const urlObj = new URL(url);
|
||||
log.rawInfo("Handling sandbox request", {host: urlObj.host, docId: this._activeDoc.docName});
|
||||
for (const [param, value] of Object.entries(params || {})) {
|
||||
urlObj.searchParams.append(param, value);
|
||||
}
|
||||
const response = await fetch(urlObj.toString(), {headers: headers || {}, agent: proxyAgent(urlObj)});
|
||||
const response = await fetch(urlObj.toString(), {
|
||||
headers: headers || {},
|
||||
agent: proxyAgent(urlObj),
|
||||
method,
|
||||
body
|
||||
});
|
||||
const content = await response.buffer();
|
||||
const {status, statusText} = response;
|
||||
const encoding = httpEncoding(response.headers.get('content-type'), content);
|
||||
|
||||
13
app/server/lib/gristSettings.ts
Normal file
13
app/server/lib/gristSettings.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import {appSettings} from 'app/server/lib/AppSettings';
|
||||
|
||||
export function getTemplateOrg() {
|
||||
let org = appSettings.section('templates').flag('org').readString({
|
||||
envVar: 'GRIST_TEMPLATE_ORG',
|
||||
});
|
||||
if (!org) { return null; }
|
||||
|
||||
if (process.env.GRIST_ID_PREFIX) {
|
||||
org += `-${process.env.GRIST_ID_PREFIX}`;
|
||||
}
|
||||
return org;
|
||||
}
|
||||
@@ -3,10 +3,10 @@ import {isAffirmative} from 'app/common/gutil';
|
||||
import {getTagManagerSnippet} from 'app/common/tagManager';
|
||||
import {Document} from 'app/common/UserAPI';
|
||||
import {SUPPORT_EMAIL} from 'app/gen-server/lib/HomeDBManager';
|
||||
import {appSettings} from 'app/server/lib/AppSettings';
|
||||
import {isAnonymousUser, isSingleUserMode, RequestWithLogin} from 'app/server/lib/Authorizer';
|
||||
import {RequestWithOrg} from 'app/server/lib/extractOrg';
|
||||
import {GristServer} from 'app/server/lib/GristServer';
|
||||
import {getTemplateOrg} from 'app/server/lib/gristSettings';
|
||||
import {getSupportedEngineChoices} from 'app/server/lib/serverUtils';
|
||||
import {readLoadedLngs, readLoadedNamespaces} from 'app/server/localization';
|
||||
import * as express from 'express';
|
||||
@@ -154,18 +154,6 @@ export function makeSendAppPage(opts: {
|
||||
};
|
||||
}
|
||||
|
||||
export function getTemplateOrg() {
|
||||
let org = appSettings.section('templates').flag('org').readString({
|
||||
envVar: 'GRIST_TEMPLATE_ORG',
|
||||
});
|
||||
if (!org) { return null; }
|
||||
|
||||
if (process.env.GRIST_ID_PREFIX) {
|
||||
org += `-${process.env.GRIST_ID_PREFIX}`;
|
||||
}
|
||||
return org;
|
||||
}
|
||||
|
||||
function shouldSupportAnon() {
|
||||
// Enable UI for anonymous access if a flag is explicitly set in the environment
|
||||
return process.env.GRIST_SUPPORT_ANON === "true";
|
||||
|
||||
Reference in New Issue
Block a user