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:
@@ -6,7 +6,8 @@ export type BootProbeIds =
|
||||
'reachable' |
|
||||
'host-header' |
|
||||
'sandboxing' |
|
||||
'system-user'
|
||||
'system-user' |
|
||||
'authentication'
|
||||
;
|
||||
|
||||
export interface BootProbeResult {
|
||||
|
||||
@@ -780,11 +780,11 @@ export class UserAPIImpl extends BaseAPI implements UserAPI {
|
||||
}
|
||||
|
||||
public async getWorker(key: string): Promise<string> {
|
||||
const json = await this.requestJson(`${this._url}/api/worker/${key}`, {
|
||||
const json = (await this.requestJson(`${this._url}/api/worker/${key}`, {
|
||||
method: 'GET',
|
||||
credentials: 'include'
|
||||
});
|
||||
return getDocWorkerUrl(this._homeUrl, json);
|
||||
})) as PublicDocWorkerUrlInfo;
|
||||
return getPublicDocWorkerUrl(this._homeUrl, json);
|
||||
}
|
||||
|
||||
public async getWorkerAPI(key: string): Promise<DocWorkerAPI> {
|
||||
@@ -1163,6 +1163,27 @@ export class DocAPIImpl extends BaseAPI implements DocAPI {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents information to build public doc worker url.
|
||||
*
|
||||
* Structure that may contain either **exclusively**:
|
||||
* - a selfPrefix when no pool of doc worker exist.
|
||||
* - a public doc worker url otherwise.
|
||||
*/
|
||||
export type PublicDocWorkerUrlInfo = {
|
||||
selfPrefix: string;
|
||||
docWorkerUrl: null;
|
||||
} | {
|
||||
selfPrefix: null;
|
||||
docWorkerUrl: string;
|
||||
}
|
||||
|
||||
export function getUrlFromPrefix(homeUrl: string, prefix: string) {
|
||||
const url = new URL(homeUrl);
|
||||
url.pathname = prefix + url.pathname;
|
||||
return url.href;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a docWorkerUrl from information returned from backend. When the backend
|
||||
* is fully configured, and there is a pool of workers, this is straightforward,
|
||||
@@ -1171,19 +1192,13 @@ export class DocAPIImpl extends BaseAPI implements DocAPI {
|
||||
* use the homeUrl of the backend, with extra path prefix information
|
||||
* given by selfPrefix. At the time of writing, the selfPrefix contains a
|
||||
* doc-worker id, and a tag for the codebase (used in consistency checks).
|
||||
*
|
||||
* @param {string} homeUrl
|
||||
* @param {string} docWorkerInfo The information to build the public doc worker url
|
||||
* (result of the call to /api/worker/:docId)
|
||||
*/
|
||||
export function getDocWorkerUrl(homeUrl: string, docWorkerInfo: {
|
||||
docWorkerUrl: string|null,
|
||||
selfPrefix?: string,
|
||||
}): string {
|
||||
if (!docWorkerInfo.docWorkerUrl) {
|
||||
if (!docWorkerInfo.selfPrefix) {
|
||||
// This should never happen.
|
||||
throw new Error('missing selfPrefix for docWorkerUrl');
|
||||
}
|
||||
const url = new URL(homeUrl);
|
||||
url.pathname = docWorkerInfo.selfPrefix + url.pathname;
|
||||
return url.href;
|
||||
}
|
||||
return docWorkerInfo.docWorkerUrl;
|
||||
export function getPublicDocWorkerUrl(homeUrl: string, docWorkerInfo: PublicDocWorkerUrlInfo) {
|
||||
return docWorkerInfo.selfPrefix !== null ?
|
||||
getUrlFromPrefix(homeUrl, docWorkerInfo.selfPrefix) :
|
||||
docWorkerInfo.docWorkerUrl;
|
||||
}
|
||||
|
||||
@@ -91,6 +91,7 @@ export const commonUrls = {
|
||||
helpAPI: 'https://support.getgrist.com/api',
|
||||
freeCoachingCall: getFreeCoachingCallUrl(),
|
||||
contactSupport: getContactSupportUrl(),
|
||||
termsOfService: getTermsOfServiceUrl(),
|
||||
plans: "https://www.getgrist.com/pricing",
|
||||
sproutsProgram: "https://www.getgrist.com/sprouts-program",
|
||||
contact: "https://www.getgrist.com/contact",
|
||||
@@ -187,10 +188,23 @@ export interface OrgUrlInfo {
|
||||
orgInPath?: string; // If /o/{orgInPath} should be used to access the requested org.
|
||||
}
|
||||
|
||||
function isDocInternalUrl(host: string) {
|
||||
if (!process.env.APP_DOC_INTERNAL_URL) { return false; }
|
||||
const internalUrl = new URL('/', process.env.APP_DOC_INTERNAL_URL);
|
||||
return internalUrl.host === host;
|
||||
function hostMatchesUrl(host?: string, url?: string) {
|
||||
return host !== undefined && url !== undefined && new URL(url).host === host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if:
|
||||
* - the server is a home worker and the host matches APP_HOME_INTERNAL_URL;
|
||||
* - or the server is a doc worker and the host matches APP_DOC_INTERNAL_URL;
|
||||
*
|
||||
* @param {string?} host The host to check
|
||||
*/
|
||||
function isOwnInternalUrlHost(host?: string) {
|
||||
// Note: APP_HOME_INTERNAL_URL may also be defined in doc worker as well as in home worker
|
||||
if (process.env.APP_HOME_INTERNAL_URL && hostMatchesUrl(host, process.env.APP_HOME_INTERNAL_URL)) {
|
||||
return true;
|
||||
}
|
||||
return Boolean(process.env.APP_DOC_INTERNAL_URL) && hostMatchesUrl(host, process.env.APP_DOC_INTERNAL_URL);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -210,7 +224,11 @@ export function getHostType(host: string, options: {
|
||||
|
||||
const hostname = host.split(":")[0];
|
||||
if (!options.baseDomain) { return 'native'; }
|
||||
if (hostname === 'localhost' || isDocInternalUrl(host) || hostname.endsWith(options.baseDomain)) {
|
||||
if (
|
||||
hostname === 'localhost' ||
|
||||
isOwnInternalUrlHost(host) ||
|
||||
hostname.endsWith(options.baseDomain)
|
||||
) {
|
||||
return 'native';
|
||||
}
|
||||
return 'custom';
|
||||
@@ -676,6 +694,9 @@ export interface GristLoadConfig {
|
||||
// Url for support for the browser client to use.
|
||||
helpCenterUrl?: string;
|
||||
|
||||
// Url for terms of service for the browser client to use
|
||||
termsOfServiceUrl?: string;
|
||||
|
||||
// Url for free coaching call scheduling for the browser client to use.
|
||||
freeCoachingCallUrl?: string;
|
||||
|
||||
@@ -887,6 +908,15 @@ export function getHelpCenterUrl(): string {
|
||||
}
|
||||
}
|
||||
|
||||
export function getTermsOfServiceUrl(): string|undefined {
|
||||
if(isClient()) {
|
||||
const gristConfig: GristLoadConfig = (window as any).gristConfig;
|
||||
return gristConfig && gristConfig.termsOfServiceUrl || undefined;
|
||||
} else {
|
||||
return process.env.GRIST_TERMS_OF_SERVICE_URL || undefined;
|
||||
}
|
||||
}
|
||||
|
||||
export function getFreeCoachingCallUrl(): string {
|
||||
const defaultUrl = "https://calendly.com/grist-team/grist-free-coaching-call";
|
||||
if(isClient()) {
|
||||
|
||||
Reference in New Issue
Block a user