zitejs 0.10.0-start.22 → 0.10.0-start.23
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/cjs/start/provider.d.ts +2 -2
- package/dist/cjs/start/provider.js +3 -3
- package/dist/cjs/start/types.d.ts +29 -47
- package/dist/cjs/sync/lib.js +23 -50
- package/dist/cjs/sync/sdkNames.d.ts +65 -7
- package/dist/cjs/sync/sdkNames.js +76 -12
- package/dist/cjs/sync/sdkNames.test.js +38 -0
- package/dist/esm/start/airtable/built.d.ts +2 -0
- package/dist/esm/start/airtable/built.js +3 -0
- package/dist/esm/start/airtable/index.d.ts +3 -5
- package/dist/esm/start/airtable/index.js +4 -25
- package/dist/esm/start/airtable/settings.d.ts +31 -0
- package/dist/esm/start/airtable/settings.js +110 -0
- package/dist/esm/start/data/index.d.ts +21 -9
- package/dist/esm/start/data/index.js +26 -20
- package/dist/esm/start/data/names.d.ts +7 -0
- package/dist/esm/start/data/names.js +15 -0
- package/dist/esm/start/data/types.d.ts +4 -1
- package/dist/esm/start/direct.d.ts +16 -12
- package/dist/esm/start/direct.js +185 -56
- package/dist/esm/start/outbound.d.ts +1 -2
- package/dist/esm/start/outbound.js +8 -19
- package/dist/esm/start/provider.d.ts +2 -2
- package/dist/esm/start/provider.js +3 -3
- package/dist/esm/start/server.d.ts +17 -13
- package/dist/esm/start/server.js +41 -43
- package/dist/esm/start/telemetry.d.ts +4 -1
- package/dist/esm/start/telemetry.js +13 -16
- package/dist/esm/start/types.d.ts +29 -47
- package/dist/esm/start/version.d.ts +1 -1
- package/dist/esm/start/version.js +1 -1
- package/dist/esm/start/vite.d.ts +7 -1
- package/dist/esm/start/vite.js +68 -21
- package/dist/esm/start/workspaceSchema.d.ts +2 -1
- package/dist/esm/start/workspaceSchema.js +3 -3
- package/dist/esm/sync/lib.js +23 -50
- package/dist/esm/sync/sdkNames.d.ts +65 -7
- package/dist/esm/sync/sdkNames.js +73 -11
- package/dist/esm/sync/sdkNames.test.js +38 -0
- package/package.json +2 -2
|
@@ -1,33 +1,16 @@
|
|
|
1
|
+
import { builtAirtableSettings } from "./built.js";
|
|
1
2
|
import { executeAirtableCall } from "./dispatch.js";
|
|
2
|
-
import { INTEGRATIONS_PLATFORM_ID } from "../credentials.js";
|
|
3
3
|
import { ZiteError, isZiteErrorCode } from "../errors.js";
|
|
4
4
|
import { rememberConnection } from "../outbound.js";
|
|
5
5
|
const AIRTABLE_API = "https://api.airtable.com";
|
|
6
|
-
// A build's integrations don't change, so per isolate: only answers, never a pending call.
|
|
7
|
-
const settingsHeld = new Map();
|
|
8
6
|
/** The build's Airtable integration `integrationId`, or undefined when it isn't one. */
|
|
9
|
-
export const airtableSettingsOf =
|
|
10
|
-
if (settingsHeld.has(integrationId))
|
|
11
|
-
return settingsHeld.get(integrationId) ?? undefined;
|
|
12
|
-
const answer = await session.integrationSettings(integrationId);
|
|
13
|
-
const settings = answer?.serviceType === "airtable" && typeof answer.baseId === "string"
|
|
14
|
-
? { baseId: answer.baseId, nameMappings: answer.nameMappings ?? null }
|
|
15
|
-
: null;
|
|
16
|
-
settingsHeld.set(integrationId, settings);
|
|
17
|
-
return settings ?? undefined;
|
|
18
|
-
};
|
|
7
|
+
export const airtableSettingsOf = (integrationId) => builtAirtableSettings && Object.hasOwn(builtAirtableSettings, integrationId) ? builtAirtableSettings[integrationId] : undefined;
|
|
19
8
|
/** One generated Airtable table call, run here with the connection's token, which the outbound fetch refreshes on a 401. */
|
|
20
|
-
export async function runAirtableCall(host,
|
|
9
|
+
export async function runAirtableCall(host, connectionOf, integrationId, settings, methodName, params) {
|
|
21
10
|
// As classic: a demo reaches no connected account.
|
|
22
11
|
if (host.mode === "demo")
|
|
23
12
|
throw new ZiteError("FORBIDDEN", "This action is not available in demo mode");
|
|
24
|
-
const connection = await
|
|
25
|
-
integrationId: INTEGRATIONS_PLATFORM_ID,
|
|
26
|
-
className: "Connections",
|
|
27
|
-
methodName: "get",
|
|
28
|
-
params: { name: integrationId },
|
|
29
|
-
access,
|
|
30
|
-
});
|
|
13
|
+
const connection = await connectionOf();
|
|
31
14
|
if ("error" in connection) {
|
|
32
15
|
const { code, message, userFacingMessage } = connection.error;
|
|
33
16
|
throw new ZiteError({ code: isZiteErrorCode(code) ? code : "INTERNAL_ERROR", message, userFacingMessage });
|
|
@@ -48,7 +31,3 @@ export async function runAirtableCall(host, session, integrationId, settings, me
|
|
|
48
31
|
}),
|
|
49
32
|
}, methodName, params);
|
|
50
33
|
}
|
|
51
|
-
/** For tests: forget what this isolate learned. */
|
|
52
|
-
export const resetAirtableSettings = () => {
|
|
53
|
-
settingsHeld.clear();
|
|
54
|
-
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { AirtableNameMappings } from "./dispatch.js";
|
|
2
|
+
type ConfigEntry = {
|
|
3
|
+
type?: unknown;
|
|
4
|
+
base?: unknown;
|
|
5
|
+
} & Record<string, unknown>;
|
|
6
|
+
type ConfigFile = {
|
|
7
|
+
integrations?: Record<string, ConfigEntry>;
|
|
8
|
+
integrationSettings?: Record<string, unknown>;
|
|
9
|
+
};
|
|
10
|
+
type LockFile = {
|
|
11
|
+
integrations?: Record<string, {
|
|
12
|
+
idMappings?: unknown;
|
|
13
|
+
} | undefined>;
|
|
14
|
+
};
|
|
15
|
+
/** An Airtable integration as the build declares it, in the platform's shape. */
|
|
16
|
+
export type BuiltAirtableSettings = {
|
|
17
|
+
serviceType: "airtable";
|
|
18
|
+
baseId: string;
|
|
19
|
+
nameMappings: AirtableNameMappings | null;
|
|
20
|
+
};
|
|
21
|
+
export type AirtableSources = {
|
|
22
|
+
appConfig?: ConfigFile;
|
|
23
|
+
appLock?: LockFile;
|
|
24
|
+
workspaceConfig?: ConfigFile;
|
|
25
|
+
workspaceLock?: LockFile;
|
|
26
|
+
/** With zite.schema.json the workspace database is the schema's, and an app's own `databases` entry is dropped. */
|
|
27
|
+
hasSchema: boolean;
|
|
28
|
+
};
|
|
29
|
+
/** Each Airtable integration the build can call, by name, as the platform's `startIntegrationSettings` answers. */
|
|
30
|
+
export declare const airtableSettingsFrom: ({ appConfig, appLock, workspaceConfig, workspaceLock, hasSchema }: AirtableSources) => Record<string, BuiltAirtableSettings>;
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// A build's Airtable integrations, from the repo files the platform derives them from (restly's
|
|
2
|
+
// `getEffectiveAppIntegrations`, through `startIntegrationSettings`): the app's own entries, then the workspace's it
|
|
3
|
+
// has settings for, each read against the app's zite.lock. Keep the two in step.
|
|
4
|
+
import { isCredentialServiceType, NON_CREDENTIAL_SERVICE_TYPES, normalizeIntegrationServiceType } from "../../integrations/rules.js";
|
|
5
|
+
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
6
|
+
const hasOwn = (record, key) => Object.prototype.hasOwnProperty.call(record, key);
|
|
7
|
+
// Airtable base ids look like `appXYZ…`; anything else is a display name, which only the lock resolves.
|
|
8
|
+
const isAirtableBaseId = (value) => /^app[A-Za-z0-9]{14}$/.test(String(value));
|
|
9
|
+
/** An Airtable entry with its base and the lock's mappings; throws on a legacy lock with no base, as the platform does. */
|
|
10
|
+
const convert = (name, base, lock) => {
|
|
11
|
+
const lockData = lock?.integrations?.[name]?.idMappings;
|
|
12
|
+
let baseId = base ?? "";
|
|
13
|
+
const lockIsForBase = (lockBase) => !isAirtableBaseId(baseId) || lockBase === baseId;
|
|
14
|
+
const tables = {};
|
|
15
|
+
const enriched = isRecord(lockData) && Array.isArray(lockData.tables);
|
|
16
|
+
if (enriched && lockIsForBase(lockData.base)) {
|
|
17
|
+
baseId = lockData.base;
|
|
18
|
+
for (const table of lockData.tables) {
|
|
19
|
+
tables[table.id] = {
|
|
20
|
+
mapping: { sdkName: table.sdkName },
|
|
21
|
+
primaryFieldId: table.primaryFieldId,
|
|
22
|
+
fields: Object.fromEntries(table.fields.map((field) => [
|
|
23
|
+
field.id,
|
|
24
|
+
{
|
|
25
|
+
mapping: { sdkName: field.sdkName },
|
|
26
|
+
fieldType: field.type,
|
|
27
|
+
fieldName: field.name,
|
|
28
|
+
...(field.config ? { fieldOptions: field.config } : {}),
|
|
29
|
+
},
|
|
30
|
+
])),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else if (lockData && !enriched) {
|
|
35
|
+
const legacy = lockData;
|
|
36
|
+
if (!legacy.base)
|
|
37
|
+
throw new Error(`Airtable lock missing base ID for integration "${name}"`);
|
|
38
|
+
if (lockIsForBase(legacy.base)) {
|
|
39
|
+
baseId = legacy.base;
|
|
40
|
+
for (const [sdkName, tableId] of Object.entries(legacy.tables ?? {})) {
|
|
41
|
+
tables[tableId] = {
|
|
42
|
+
mapping: { sdkName },
|
|
43
|
+
fields: Object.fromEntries(Object.entries(legacy.fields?.[sdkName] ?? {}).map(([fieldSdkName, fieldId]) => [fieldId, { mapping: { sdkName: fieldSdkName } }])),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return { baseId, nameMappings: { bases: { [String(baseId)]: { mapping: { sdkName: base }, tables } } } };
|
|
49
|
+
};
|
|
50
|
+
const isAirtable = (entry) => entry?.type === "airtable";
|
|
51
|
+
const isServiceType = (type) => {
|
|
52
|
+
const normalized = typeof type === "string" ? normalizeIntegrationServiceType(type) : undefined;
|
|
53
|
+
return normalized !== undefined && (isCredentialServiceType(normalized) || NON_CREDENTIAL_SERVICE_TYPES.includes(normalized));
|
|
54
|
+
};
|
|
55
|
+
const isOptionalString = (value) => value === undefined || value === null || typeof value === "string";
|
|
56
|
+
/**
|
|
57
|
+
* Whether the platform's conversion of an entry gets past what any type checks (`convertConfigToIntegrationTemplate`
|
|
58
|
+
* throws on an unknown or missing type, a connectionId that isn't a string, and an email sender that isn't one).
|
|
59
|
+
* The platform skips an entry it can't read, whatever its type.
|
|
60
|
+
*/
|
|
61
|
+
const platformReads = (entry) => isRecord(entry) &&
|
|
62
|
+
isServiceType(entry.type) &&
|
|
63
|
+
(!entry.connectionId || typeof entry.connectionId === "string") &&
|
|
64
|
+
(normalizeIntegrationServiceType(String(entry.type)) !== "email" || (isOptionalString(entry.fromName) && isOptionalString(entry.fromEmail)));
|
|
65
|
+
/** Each Airtable integration the build can call, by name, as the platform's `startIntegrationSettings` answers. */
|
|
66
|
+
export const airtableSettingsFrom = ({ appConfig, appLock, workspaceConfig, workspaceLock, hasSchema }) => {
|
|
67
|
+
// The app's own entries, each shadowing the workspace's of its name: only those the platform could read.
|
|
68
|
+
const own = {};
|
|
69
|
+
const effective = [];
|
|
70
|
+
for (const [name, entry] of Object.entries(appConfig?.integrations ?? {})) {
|
|
71
|
+
if ((hasSchema && entry?.type === "databases") || !platformReads(entry))
|
|
72
|
+
continue;
|
|
73
|
+
if (isAirtable(entry)) {
|
|
74
|
+
try {
|
|
75
|
+
effective.push([name, convert(name, entry.base, appLock)]);
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
own[name] = entry;
|
|
82
|
+
}
|
|
83
|
+
const settings = isRecord(appConfig?.integrationSettings) ? appConfig.integrationSettings : undefined;
|
|
84
|
+
for (const [name, entry] of Object.entries(workspaceConfig?.integrations ?? {})) {
|
|
85
|
+
// A workspace Airtable is the app's only once the app names it in its settings.
|
|
86
|
+
if (!isAirtable(entry) || !platformReads(entry) || hasOwn(own, name) || !settings || !hasOwn(settings, name))
|
|
87
|
+
continue;
|
|
88
|
+
let workspace;
|
|
89
|
+
try {
|
|
90
|
+
workspace = convert(name, entry.base, workspaceLock);
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
let applied = workspace;
|
|
96
|
+
const appSettings = settings[name];
|
|
97
|
+
if (appSettings) {
|
|
98
|
+
const base = isRecord(appSettings) && hasOwn(appSettings, "base") ? appSettings.base : workspace.baseId;
|
|
99
|
+
try {
|
|
100
|
+
applied = convert(name, base, appLock);
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
applied = workspace;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (applied.baseId)
|
|
107
|
+
effective.push([name, applied]);
|
|
108
|
+
}
|
|
109
|
+
return Object.fromEntries(effective.flatMap(([name, { baseId, nameMappings }]) => typeof baseId === "string" ? [[name, { serviceType: "airtable", baseId, nameMappings }]] : []));
|
|
110
|
+
};
|
|
@@ -1,15 +1,27 @@
|
|
|
1
|
-
import type { DataNameMappings } from "./types.js";
|
|
2
|
-
import
|
|
1
|
+
import type { BaseTable, DataNameMappings } from "./types.js";
|
|
2
|
+
import { type SchemaNames } from "../../sync/sdkNames.js";
|
|
3
|
+
import type { HostMode } from "../types.js";
|
|
3
4
|
/** What generated `zite.*` calls go out under. */
|
|
4
5
|
export declare const DATA_INTEGRATION_ID = "databases";
|
|
5
|
-
|
|
6
|
+
/** Sends one base-runner request on the app's token. */
|
|
7
|
+
export type DataTransport = {
|
|
8
|
+
dataFetch(request: {
|
|
9
|
+
method: string;
|
|
10
|
+
path: string;
|
|
11
|
+
body?: string;
|
|
12
|
+
}): Promise<Response>;
|
|
13
|
+
};
|
|
14
|
+
/** The build's base, and the SDK names it was built with. */
|
|
15
|
+
export type DataTarget = {
|
|
6
16
|
baseId: string | null;
|
|
7
|
-
|
|
17
|
+
names: SchemaNames | null;
|
|
8
18
|
};
|
|
9
|
-
/**
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
19
|
+
/**
|
|
20
|
+
* The build's names for the base's tables as they are now: the ones it was built with, locked, and for anything added
|
|
21
|
+
* since, the name `zitejs generate` would give it. Worked out once per read of the tables.
|
|
22
|
+
*/
|
|
23
|
+
export declare const nameMappingsFor: (live: readonly BaseTable[], names: SchemaNames | null) => DataNameMappings;
|
|
24
|
+
/** One `zite.*` call, translated here and sent to base-runner on the app token. */
|
|
25
|
+
export declare function runDataCall(session: DataTransport, target: DataTarget, mode: HostMode, methodName: string, sent: unknown): Promise<unknown>;
|
|
13
26
|
/** For tests: forget what this isolate learned. */
|
|
14
27
|
export declare const resetDataDispatch: () => void;
|
|
15
|
-
export {};
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { createBaseRunner } from "./baseRunner.js";
|
|
2
2
|
import { asZiteClientError, executeDatabasesCall } from "./dispatch.js";
|
|
3
|
+
import { nameMappingsOf } from "./names.js";
|
|
4
|
+
import { allocateLiveNames } from "../../sync/sdkNames.js";
|
|
3
5
|
/** What generated `zite.*` calls go out under. */
|
|
4
6
|
export const DATA_INTEGRATION_ID = "databases";
|
|
5
7
|
// Schema changes aren't redeployed, so a new table or field reaches calls within this, as on the host.
|
|
6
8
|
const TABLES_REUSE_MS = 60_000;
|
|
7
|
-
// One build per script, so per isolate:
|
|
8
|
-
//
|
|
9
|
-
let context;
|
|
9
|
+
// One build per script, so per isolate: its base's tables. Only answers are kept, never a pending call: one request's
|
|
10
|
+
// I/O mustn't hold up another's.
|
|
10
11
|
let tables;
|
|
11
12
|
const tablesOf = async (baseRunner, baseId) => {
|
|
12
13
|
if (tables?.baseId === baseId && Date.now() - tables.at < TABLES_REUSE_MS)
|
|
@@ -15,44 +16,49 @@ const tablesOf = async (baseRunner, baseId) => {
|
|
|
15
16
|
tables = { baseId, tables: base.tables, at: Date.now() };
|
|
16
17
|
return base.tables;
|
|
17
18
|
};
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
const completed = new WeakMap();
|
|
20
|
+
/**
|
|
21
|
+
* The build's names for the base's tables as they are now: the ones it was built with, locked, and for anything added
|
|
22
|
+
* since, the name `zitejs generate` would give it. Worked out once per read of the tables.
|
|
23
|
+
*/
|
|
24
|
+
export const nameMappingsFor = (live, names) => {
|
|
25
|
+
const held = completed.get(live);
|
|
26
|
+
if (held?.names === names)
|
|
27
|
+
return held.mappings;
|
|
28
|
+
const mappings = nameMappingsOf(allocateLiveNames(live, names ?? undefined).names);
|
|
29
|
+
completed.set(live, { names, mappings });
|
|
30
|
+
return mappings;
|
|
25
31
|
};
|
|
26
32
|
/**
|
|
27
33
|
* The table id classic's generated client sends: its SDK name mapped through the
|
|
28
34
|
* build's name mappings, which on classic the client does from the run's config.
|
|
29
35
|
*/
|
|
30
36
|
const tableIdOf = (nameMappings, sent) => {
|
|
31
|
-
for (const [id, table] of Object.entries(nameMappings
|
|
37
|
+
for (const [id, table] of Object.entries(nameMappings.tables)) {
|
|
32
38
|
if (table.mapping?.sdkName === sent)
|
|
33
39
|
return id;
|
|
34
40
|
}
|
|
35
41
|
return sent;
|
|
36
42
|
};
|
|
37
|
-
/** One `zite.*` call, translated here and sent to base-runner
|
|
38
|
-
export async function runDataCall(session,
|
|
39
|
-
|
|
40
|
-
? { ...sent, tableId: tableIdOf(found.nameMappings, sent.tableId) }
|
|
41
|
-
: sent;
|
|
42
|
-
if (!found.baseId)
|
|
43
|
+
/** One `zite.*` call, translated here and sent to base-runner on the app token. */
|
|
44
|
+
export async function runDataCall(session, target, mode, methodName, sent) {
|
|
45
|
+
if (!target.baseId)
|
|
43
46
|
throw asZiteClientError(Object.assign(new Error("This app has no database"), { statusCode: 404 }));
|
|
44
47
|
const baseRunner = createBaseRunner((request) => session.dataFetch(request));
|
|
45
48
|
let baseTables;
|
|
46
49
|
try {
|
|
47
|
-
baseTables = await tablesOf(baseRunner,
|
|
50
|
+
baseTables = await tablesOf(baseRunner, target.baseId);
|
|
48
51
|
}
|
|
49
52
|
catch (error) {
|
|
50
53
|
throw asZiteClientError(error);
|
|
51
54
|
}
|
|
52
|
-
|
|
55
|
+
const nameMappings = nameMappingsFor(baseTables, target.names);
|
|
56
|
+
const params = sent && typeof sent === "object" && typeof sent.tableId === "string"
|
|
57
|
+
? { ...sent, tableId: tableIdOf(nameMappings, sent.tableId) }
|
|
58
|
+
: sent;
|
|
59
|
+
return executeDatabasesCall({ baseRunner, baseId: target.baseId, nameMappings, tables: baseTables, readOnly: mode === "demo" }, methodName, params);
|
|
53
60
|
}
|
|
54
61
|
/** For tests: forget what this isolate learned. */
|
|
55
62
|
export const resetDataDispatch = () => {
|
|
56
|
-
context = undefined;
|
|
57
63
|
tables = undefined;
|
|
58
64
|
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type SchemaNames } from "../../sync/sdkNames.js";
|
|
2
|
+
import type { DataNameMappings } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Names as the platform's `nameMappings` keep them: each table under the class name its generated client sends
|
|
5
|
+
* (`createTableClient('Orders')`), each field under its own.
|
|
6
|
+
*/
|
|
7
|
+
export declare const nameMappingsOf: (names: SchemaNames) => DataNameMappings;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { toPascalCase } from "../../sync/sdkNames.js";
|
|
2
|
+
/**
|
|
3
|
+
* Names as the platform's `nameMappings` keep them: each table under the class name its generated client sends
|
|
4
|
+
* (`createTableClient('Orders')`), each field under its own.
|
|
5
|
+
*/
|
|
6
|
+
export const nameMappingsOf = (names) => ({
|
|
7
|
+
mapping: { sdkName: "Database" },
|
|
8
|
+
tables: Object.fromEntries(names.tables.map((table) => [
|
|
9
|
+
table.id,
|
|
10
|
+
{
|
|
11
|
+
mapping: { sdkName: toPascalCase(table.sdkName) },
|
|
12
|
+
fields: Object.fromEntries(table.fields.map((field) => [field.id, { mapping: { sdkName: field.sdkName } }])),
|
|
13
|
+
},
|
|
14
|
+
])),
|
|
15
|
+
});
|
|
@@ -56,8 +56,11 @@ export interface DatabaseRecord {
|
|
|
56
56
|
id: string;
|
|
57
57
|
[key: string]: unknown;
|
|
58
58
|
}
|
|
59
|
-
/** The build's tables' and fields' SDK names, by id
|
|
59
|
+
/** The build's tables' and fields' SDK names, by id, as `projectConfig.nameMappings` keeps them. */
|
|
60
60
|
export type DataNameMappings = {
|
|
61
|
+
mapping?: {
|
|
62
|
+
sdkName: string;
|
|
63
|
+
};
|
|
61
64
|
tables: Record<string, {
|
|
62
65
|
mapping: {
|
|
63
66
|
sdkName: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { HostRequestState, PagePlan, PlatformCallInput, PlatformCallResult,
|
|
1
|
+
import type { HostRequestState, PagePlan, PlatformCallInput, PlatformCallResult, PlatformUrls } from "./types.js";
|
|
2
2
|
export type DirectAccess = {
|
|
3
3
|
token: string;
|
|
4
4
|
urls: PlatformUrls;
|
|
@@ -7,14 +7,18 @@ type Connection = Record<string, unknown> & {
|
|
|
7
7
|
status?: unknown;
|
|
8
8
|
message?: unknown;
|
|
9
9
|
userFacingMessage?: unknown;
|
|
10
|
+
connectUrl?: unknown;
|
|
10
11
|
};
|
|
11
12
|
type Connections = {
|
|
12
13
|
connections: Record<string, Connection>;
|
|
13
14
|
env: Record<string, string>;
|
|
14
15
|
envConnections: Record<string, string>;
|
|
15
16
|
};
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
/** Thrown for a platform call on a request that has no token or no platform URLs. */
|
|
18
|
+
export declare class NoPlatformError extends Error {
|
|
19
|
+
constructor();
|
|
20
|
+
}
|
|
21
|
+
/** The request's token and where to send it, renewed first if it's about to expire; undefined without either. */
|
|
18
22
|
export declare const directAccess: (host: HostRequestState) => Promise<DirectAccess | undefined>;
|
|
19
23
|
/** At most `max` at once, the rest in turn; each take resolves with its release. */
|
|
20
24
|
export declare const limiter: (max: number) => () => Promise<() => void>;
|
|
@@ -24,17 +28,17 @@ export declare const directDataFetch: (host: HostRequestState) => ({ method, pat
|
|
|
24
28
|
path: string;
|
|
25
29
|
body?: string;
|
|
26
30
|
}) => Promise<Response>;
|
|
27
|
-
/**
|
|
28
|
-
|
|
31
|
+
/**
|
|
32
|
+
* The backend's `GET connections` on the token, once per reuse window: all `local` has, and what an app on Zite asks
|
|
33
|
+
* when the host didn't hand them over. Stale if the backend didn't answer.
|
|
34
|
+
*/
|
|
35
|
+
export declare const connectionsOnToken: (access: DirectAccess) => Promise<Connections>;
|
|
29
36
|
/** The build's page settings for `local`, which has no host to send them; null when the backend has none to give. */
|
|
30
37
|
export declare const localPagePlan: (access: DirectAccess) => Promise<PagePlan | null>;
|
|
31
38
|
/** For tests: forget what this isolate learned. */
|
|
32
39
|
export declare const resetLocalConnections: () => void;
|
|
33
|
-
/**
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
export declare const directCall: (host: HostRequestState, input: PlatformCallInput) => Promise<PlatformCallResult | undefined>;
|
|
38
|
-
/** After a provider answered 401: the connection refreshed by the backend, or by the host's session without a token. */
|
|
39
|
-
export declare const refreshConnection: (host: HostRequestState, name: string) => Promise<PlatformCallResult | undefined>;
|
|
40
|
+
/** A platform call on the token; a throw without one. Errors come back as values, as the relay's did. */
|
|
41
|
+
export declare const directCall: (host: HostRequestState, input: PlatformCallInput) => Promise<PlatformCallResult>;
|
|
42
|
+
/** After a provider answered 401: the connection refreshed by the backend. */
|
|
43
|
+
export declare const refreshConnection: (host: HostRequestState, name: string) => Promise<PlatformCallResult>;
|
|
40
44
|
export {};
|