@lowdefy/client-core 0.0.0-experimental-20261019052246
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/LICENSE +201 -0
- package/README.md +9 -0
- package/dist/auth/createAuthFetchOptions.js +56 -0
- package/dist/auth/createAuthMethods.js +1070 -0
- package/dist/auth/createPkceChallenge.js +57 -0
- package/dist/auth/endBearerSession.js +26 -0
- package/dist/auth/getAuthorizationHeaders.js +31 -0
- package/dist/auth/validateAuthTransport.js +41 -0
- package/dist/claimCallerReload.js +41 -0
- package/dist/createCallAPI.js +39 -0
- package/dist/createCallRequest.js +34 -0
- package/dist/createHandleError.js +90 -0
- package/dist/createLowdefyCore.js +124 -0
- package/dist/createPageLifecycleManager.js +173 -0
- package/dist/getActiveLocale.js +26 -0
- package/dist/getContextKey.js +29 -0
- package/dist/hasOtherRoles.js +30 -0
- package/dist/index.js +32 -0
- package/dist/isOtherCaller.js +29 -0
- package/dist/recordCallerStamp.js +31 -0
- package/dist/recorder/buildEngineRecord.js +34 -0
- package/dist/recorder/buildInteractionRecord.js +60 -0
- package/dist/recorder/buildTraceEvent.js +62 -0
- package/dist/recorder/chunkRecords.js +78 -0
- package/dist/recorder/collectEventActions.js +22 -0
- package/dist/recorder/collectEventEndpoints.js +39 -0
- package/dist/recorder/collectEventRequests.js +38 -0
- package/dist/recorder/createPairingBuffer.js +177 -0
- package/dist/recorder/createPasswordRedactor.js +64 -0
- package/dist/recorder/createRecordBatcher.js +50 -0
- package/dist/recorder/createRecordingSession.js +60 -0
- package/dist/recorder/diffStateWrites.js +86 -0
- package/dist/recorder/isEventCall.js +26 -0
- package/dist/recorder/jsonType.js +35 -0
- package/dist/recorder/sendRecords.js +39 -0
- package/dist/recorder/toJsonSafe.js +26 -0
- package/dist/request.js +127 -0
- package/dist/setLowdefyUser.js +32 -0
- package/dist/shouldReloadForAuthError.js +39 -0
- package/dist/shouldReloadForBuild.js +45 -0
- package/dist/shouldReloadForCaller.js +50 -0
- package/dist/storage/clearUserStorage.js +36 -0
- package/dist/storage/clearUserStorageOnOwnerChange.js +42 -0
- package/dist/storage/createStorage.js +51 -0
- package/dist/storage/listUserStorageKeys.js +36 -0
- package/dist/storage/userStorageKey.js +24 -0
- package/dist/storage/userStoragePrefix.js +25 -0
- package/dist/test/createMemoryStore.js +40 -0
- package/dist/updateLowdefyPage.js +44 -0
- package/dist/url.js +29 -0
- package/dist/websocket/createWebSocketClient.js +428 -0
- package/package.json +57 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import { type } from '@lowdefy/helpers';
|
|
16
|
+
// A language tag: a 2–3 letter language and optional subtags ("en", "en-US",
|
|
17
|
+
// "zh-Hant-TW"). Intl throws on anything else, such as "en_US".
|
|
18
|
+
const LANGUAGE_TAG = /^[A-Za-z]{2,3}(-[A-Za-z0-9]{1,8})*$/;
|
|
19
|
+
// The app's active locale, as the renderer publishes it, for formatting HTML
|
|
20
|
+
// dates and numbers. Undefined (the platform's locale) when the app has no i18n
|
|
21
|
+
// or the code is not a language tag Intl accepts.
|
|
22
|
+
function getActiveLocale(locale) {
|
|
23
|
+
if (!type.isString(locale) || !LANGUAGE_TAG.test(locale)) return undefined;
|
|
24
|
+
return locale;
|
|
25
|
+
}
|
|
26
|
+
export default getActiveLocale;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ const contextKeys = new WeakMap();
|
|
16
|
+
let lastKey = 0;
|
|
17
|
+
// A React key per engine context object. A page context rebuilt in place - an
|
|
18
|
+
// organization switch, a dev config reset - is a new object under the same
|
|
19
|
+
// instance key, and keying the page tree by it remounts the tree onto the new
|
|
20
|
+
// context rather than reconciling mounted blocks against it, which React can
|
|
21
|
+
// silently drop.
|
|
22
|
+
function getContextKey(context) {
|
|
23
|
+
if (!contextKeys.has(context)) {
|
|
24
|
+
lastKey += 1;
|
|
25
|
+
contextKeys.set(context, lastKey);
|
|
26
|
+
}
|
|
27
|
+
return contextKeys.get(context);
|
|
28
|
+
}
|
|
29
|
+
export default getContextKey;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import { rolesHash, type } from '@lowdefy/helpers';
|
|
16
|
+
// True when the server answered the rendered caller with other roles than the
|
|
17
|
+
// page renders - a role was granted or taken away since the page loaded - so
|
|
18
|
+
// _user.roles and role-gated blocks would show access the person no longer
|
|
19
|
+
// holds, or hide access they now have. stamp is the response's parsed
|
|
20
|
+
// x-lowdefy-caller header, user the rendered caller. A stamp that names no
|
|
21
|
+
// roles (no header, or an anonymous caller) claims none.
|
|
22
|
+
function hasOtherRoles({ stamp, user }) {
|
|
23
|
+
if (type.isNone(user) || type.isNone(stamp?.roles)) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
return stamp.roles !== rolesHash({
|
|
27
|
+
user
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
export default hasOtherRoles;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ export { default as claimCallerReload } from './claimCallerReload.js';
|
|
16
|
+
export { default as createAuthFetchOptions } from './auth/createAuthFetchOptions.js';
|
|
17
|
+
export { default as createLowdefyCore } from './createLowdefyCore.js';
|
|
18
|
+
export { default as createPageLifecycleManager } from './createPageLifecycleManager.js';
|
|
19
|
+
export { default as createPairingBuffer } from './recorder/createPairingBuffer.js';
|
|
20
|
+
export { default as createPasswordRedactor } from './recorder/createPasswordRedactor.js';
|
|
21
|
+
export { default as createPkceChallenge } from './auth/createPkceChallenge.js';
|
|
22
|
+
export { default as createRecordBatcher } from './recorder/createRecordBatcher.js';
|
|
23
|
+
export { default as createRecordingSession } from './recorder/createRecordingSession.js';
|
|
24
|
+
export { createUrl, serializeQuery } from './url.js';
|
|
25
|
+
export { default as getActiveLocale } from './getActiveLocale.js';
|
|
26
|
+
export { default as getAuthorizationHeaders } from './auth/getAuthorizationHeaders.js';
|
|
27
|
+
export { default as getContextKey } from './getContextKey.js';
|
|
28
|
+
export { default as recordCallerStamp } from './recordCallerStamp.js';
|
|
29
|
+
export { default as sendRecords } from './recorder/sendRecords.js';
|
|
30
|
+
export { default as shouldReloadForBuild } from './shouldReloadForBuild.js';
|
|
31
|
+
export { default as shouldReloadForCaller } from './shouldReloadForCaller.js';
|
|
32
|
+
export { default as updateLowdefyPage } from './updateLowdefyPage.js';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import { callerHash, type } from '@lowdefy/helpers';
|
|
16
|
+
// True when the server answered as another caller than the one this page
|
|
17
|
+
// renders: stamp is the response's parsed x-lowdefy-caller header (see the
|
|
18
|
+
// server's stampCaller and parseCallerStamp), user the rendered caller.
|
|
19
|
+
function isOtherCaller({ stamp, user }) {
|
|
20
|
+
// A response with no header was not answered by a route that resolved a
|
|
21
|
+
// caller (it failed before, or came from a proxy), so it claims no caller.
|
|
22
|
+
if (type.isNone(stamp)) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
return stamp.caller !== callerHash({
|
|
26
|
+
user
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
export default isOtherCaller;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import { parseCallerStamp, type } from '@lowdefy/helpers';
|
|
16
|
+
// Keeps the last caller stamp a response carried (see the server's stampCaller)
|
|
17
|
+
// on lowdefy._internal.callerStamp, as { caller, session, roles, memberships }:
|
|
18
|
+
// who the server last answered as, in full. A response with no header claims
|
|
19
|
+
// no caller and leaves the last stamp in place.
|
|
20
|
+
function recordCallerStamp({ lowdefy, serverCaller }) {
|
|
21
|
+
const stamp = parseCallerStamp(serverCaller);
|
|
22
|
+
if (type.isNone(stamp)) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
// The dev server fetches the first page config before the page context exists
|
|
26
|
+
// (initLowdefyContext), which carries this stamp over when it builds
|
|
27
|
+
// _internal.
|
|
28
|
+
lowdefy._internal = lowdefy._internal ?? {};
|
|
29
|
+
lowdefy._internal.callerStamp = stamp;
|
|
30
|
+
}
|
|
31
|
+
export default recordCallerStamp;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ // An engine event no interaction caused (a mount event, an app event, a
|
|
16
|
+
// programmatic or off-path event) as a v1 trace record of kind engine. The
|
|
17
|
+
// compiler decides what each compiles to.
|
|
18
|
+
function buildEngineRecord({ engineEvent, session, roles }) {
|
|
19
|
+
return {
|
|
20
|
+
v: 1,
|
|
21
|
+
session,
|
|
22
|
+
t: new Date(engineEvent.startTimestamp).toISOString(),
|
|
23
|
+
kind: 'engine',
|
|
24
|
+
scope: engineEvent.scope,
|
|
25
|
+
page_id: engineEvent.pageId,
|
|
26
|
+
roles: roles ?? [],
|
|
27
|
+
person: null,
|
|
28
|
+
org: null,
|
|
29
|
+
target: null,
|
|
30
|
+
event: engineEvent.traceEvent,
|
|
31
|
+
build: engineEvent.build ?? null
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export default buildEngineRecord;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import { type } from '@lowdefy/helpers';
|
|
16
|
+
// describeElement's result without what a record keeps elsewhere: the page
|
|
17
|
+
// sits on the record and the enclosing block ids feed pairing only.
|
|
18
|
+
function recordTarget(target) {
|
|
19
|
+
if (type.isNone(target)) return null;
|
|
20
|
+
const { page_id: _pageId, block_ids: _blockIds, ...rest } = target;
|
|
21
|
+
return rest;
|
|
22
|
+
}
|
|
23
|
+
// An interaction (a DOM event on the web, a block pressed or changed on a
|
|
24
|
+
// phone) as a v1 trace record. `paired` are the trace events the
|
|
25
|
+
// pairing rule gave it, innermost first: the first is `event`, the rest go to
|
|
26
|
+
// `also`. `build` is the build of the page config the interaction happened
|
|
27
|
+
// on; `source` and `run` are stamped by the dev server, never the page.
|
|
28
|
+
function buildInteractionRecord({ interaction, paired = [], session, roles }) {
|
|
29
|
+
const record = {
|
|
30
|
+
v: 1,
|
|
31
|
+
session,
|
|
32
|
+
t: new Date(interaction.t).toISOString(),
|
|
33
|
+
kind: interaction.kind,
|
|
34
|
+
scope: 'page',
|
|
35
|
+
page_id: interaction.target?.page_id ?? interaction.pageId,
|
|
36
|
+
roles: roles ?? [],
|
|
37
|
+
person: null,
|
|
38
|
+
org: null,
|
|
39
|
+
target: recordTarget(interaction.target),
|
|
40
|
+
event: paired[0] ?? null,
|
|
41
|
+
build: interaction.build ?? null
|
|
42
|
+
};
|
|
43
|
+
if (paired.length > 1) {
|
|
44
|
+
record.also = paired.slice(1);
|
|
45
|
+
}
|
|
46
|
+
if (interaction.kind === 'pageview') {
|
|
47
|
+
record.url = interaction.url;
|
|
48
|
+
if (!type.isNone(interaction.pathParams)) {
|
|
49
|
+
record.path_params = interaction.pathParams;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (interaction.kind === 'change') {
|
|
53
|
+
record.value = interaction.value ?? null;
|
|
54
|
+
}
|
|
55
|
+
if (interaction.kind === 'key') {
|
|
56
|
+
record.key = interaction.key;
|
|
57
|
+
}
|
|
58
|
+
return record;
|
|
59
|
+
}
|
|
60
|
+
export default buildInteractionRecord;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import { type } from '@lowdefy/helpers';
|
|
16
|
+
import collectEventActions from './collectEventActions.js';
|
|
17
|
+
import collectEventEndpoints from './collectEventEndpoints.js';
|
|
18
|
+
import collectEventRequests from './collectEventRequests.js';
|
|
19
|
+
import diffStateWrites from './diffStateWrites.js';
|
|
20
|
+
// One completed engine event as a trace record's `event` (or `also` entry),
|
|
21
|
+
// built from the engine's trace payload the moment it arrives: the state the
|
|
22
|
+
// event wrote is the difference between the copy taken before its actions ran
|
|
23
|
+
// and the state now, which later events would change.
|
|
24
|
+
function buildTraceEvent({ payload, urlAfter }) {
|
|
25
|
+
const { context, failure, record } = payload;
|
|
26
|
+
const responses = record?.responses ?? {};
|
|
27
|
+
const event = {
|
|
28
|
+
name: payload.eventName,
|
|
29
|
+
block_id: payload.blockId,
|
|
30
|
+
success: payload.success,
|
|
31
|
+
actions: collectEventActions({
|
|
32
|
+
responses
|
|
33
|
+
}),
|
|
34
|
+
requests: collectEventRequests({
|
|
35
|
+
blockId: payload.blockId,
|
|
36
|
+
context,
|
|
37
|
+
responses
|
|
38
|
+
}),
|
|
39
|
+
endpoints: collectEventEndpoints({
|
|
40
|
+
blockId: payload.blockId,
|
|
41
|
+
context,
|
|
42
|
+
responses
|
|
43
|
+
}),
|
|
44
|
+
state_writes: diffStateWrites({
|
|
45
|
+
before: payload.stateBefore,
|
|
46
|
+
after: context?.state,
|
|
47
|
+
values: true
|
|
48
|
+
}),
|
|
49
|
+
url_after: urlAfter ?? null
|
|
50
|
+
};
|
|
51
|
+
if (!type.isNone(failure)) {
|
|
52
|
+
event.error = {
|
|
53
|
+
name: failure.errorName ?? 'Error',
|
|
54
|
+
config_key: failure.configKey ?? null,
|
|
55
|
+
action_type: failure.actionType ?? null,
|
|
56
|
+
action_id: failure.actionId ?? null
|
|
57
|
+
};
|
|
58
|
+
event.invalid_blocks = failure.invalidBlocks ?? [];
|
|
59
|
+
}
|
|
60
|
+
return event;
|
|
61
|
+
}
|
|
62
|
+
export default buildTraceEvent;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ // Keepalive fetches share a 64 KB in-flight budget per page, so each POST body
|
|
16
|
+
// stays under 48 KB.
|
|
17
|
+
const MAX_CHUNK_BYTES = 48 * 1024;
|
|
18
|
+
function utf8Length(text) {
|
|
19
|
+
let bytes = 0;
|
|
20
|
+
for (const character of text){
|
|
21
|
+
const code = character.codePointAt(0);
|
|
22
|
+
if (code < 0x80) {
|
|
23
|
+
bytes += 1;
|
|
24
|
+
} else if (code < 0x800) {
|
|
25
|
+
bytes += 2;
|
|
26
|
+
} else if (code < 0x10000) {
|
|
27
|
+
bytes += 3;
|
|
28
|
+
} else {
|
|
29
|
+
bytes += 4;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return bytes;
|
|
33
|
+
}
|
|
34
|
+
// The bytes of `{"session":…,"records":[]}` before any record is added.
|
|
35
|
+
function emptyBodyLength(session) {
|
|
36
|
+
return utf8Length(JSON.stringify({
|
|
37
|
+
session,
|
|
38
|
+
records: []
|
|
39
|
+
}));
|
|
40
|
+
}
|
|
41
|
+
// Splits records into POST bodies of { session, records }, one session per
|
|
42
|
+
// body (the route names the file by it) and each body under maxBytes. A
|
|
43
|
+
// single record too large for a body on its own is dropped.
|
|
44
|
+
function chunkRecords({ records, maxBytes = MAX_CHUNK_BYTES }) {
|
|
45
|
+
const chunks = [];
|
|
46
|
+
let current = null;
|
|
47
|
+
records.forEach((record)=>{
|
|
48
|
+
const recordLength = utf8Length(JSON.stringify(record));
|
|
49
|
+
if (current !== null && current.session === record.session) {
|
|
50
|
+
// One comma joins the record to the ones before it.
|
|
51
|
+
const length = current.length + 1 + recordLength;
|
|
52
|
+
if (length <= maxBytes) {
|
|
53
|
+
current.records.push(record);
|
|
54
|
+
current.length = length;
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (current !== null) chunks.push({
|
|
59
|
+
session: current.session,
|
|
60
|
+
records: current.records
|
|
61
|
+
});
|
|
62
|
+
const length = emptyBodyLength(record.session) + recordLength;
|
|
63
|
+
current = length <= maxBytes ? {
|
|
64
|
+
session: record.session,
|
|
65
|
+
records: [
|
|
66
|
+
record
|
|
67
|
+
],
|
|
68
|
+
length
|
|
69
|
+
} : null;
|
|
70
|
+
});
|
|
71
|
+
if (current !== null) chunks.push({
|
|
72
|
+
session: current.session,
|
|
73
|
+
records: current.records
|
|
74
|
+
});
|
|
75
|
+
return chunks;
|
|
76
|
+
}
|
|
77
|
+
export { MAX_CHUNK_BYTES };
|
|
78
|
+
export default chunkRecords;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import { type } from '@lowdefy/helpers';
|
|
16
|
+
// The types of the actions this event ran, in the order they ran: every
|
|
17
|
+
// response entry the engine kept, without the actions a skip or a control
|
|
18
|
+
// passed over.
|
|
19
|
+
function collectEventActions({ responses }) {
|
|
20
|
+
return Object.values(responses).filter((response)=>type.isObject(response) && response.skipped !== true).filter((response)=>type.isString(response.type)).sort((a, b)=>(a.index ?? 0) - (b.index ?? 0)).map((response)=>response.type);
|
|
21
|
+
}
|
|
22
|
+
export default collectEventActions;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import { type } from '@lowdefy/helpers';
|
|
16
|
+
import isEventCall from './isEventCall.js';
|
|
17
|
+
// The API endpoints this event's CallAPI actions called, as trace record
|
|
18
|
+
// entries. `apiResponses[endpointId]` is a newest-first call history whose
|
|
19
|
+
// entries carry the block and the id of the action that made the call, read
|
|
20
|
+
// as collectEventRequests reads request calls.
|
|
21
|
+
function collectEventEndpoints({ blockId, context, responses }) {
|
|
22
|
+
const apiResponses = context?._internal?.lowdefy?.apiResponses ?? {};
|
|
23
|
+
const endpoints = [];
|
|
24
|
+
Object.keys(apiResponses).forEach((endpointId)=>{
|
|
25
|
+
const call = (apiResponses[endpointId] ?? [])[0];
|
|
26
|
+
if (!isEventCall({
|
|
27
|
+
blockId,
|
|
28
|
+
call,
|
|
29
|
+
responses
|
|
30
|
+
})) return;
|
|
31
|
+
endpoints.push({
|
|
32
|
+
id: endpointId,
|
|
33
|
+
ok: call.success === true,
|
|
34
|
+
ms: type.isNumber(call.responseTime) ? call.responseTime : null
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
return endpoints;
|
|
38
|
+
}
|
|
39
|
+
export default collectEventEndpoints;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import { type } from '@lowdefy/helpers';
|
|
16
|
+
import isEventCall from './isEventCall.js';
|
|
17
|
+
// The requests this event's actions fired, as trace record entries.
|
|
18
|
+
// `context.requests[requestId]` is a newest-first call history whose entries
|
|
19
|
+
// carry the block and the id of the action that made the call, so the newest
|
|
20
|
+
// call of a request belongs to this event when isEventCall says so.
|
|
21
|
+
function collectEventRequests({ blockId, context, responses }) {
|
|
22
|
+
const requests = [];
|
|
23
|
+
Object.keys(context?.requests ?? {}).forEach((requestId)=>{
|
|
24
|
+
const call = (context.requests[requestId] ?? [])[0];
|
|
25
|
+
if (!isEventCall({
|
|
26
|
+
blockId,
|
|
27
|
+
call,
|
|
28
|
+
responses
|
|
29
|
+
})) return;
|
|
30
|
+
requests.push({
|
|
31
|
+
id: requestId,
|
|
32
|
+
ok: type.isNone(call.error),
|
|
33
|
+
ms: type.isNumber(call.responseTime) ? call.responseTime : null
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
return requests;
|
|
37
|
+
}
|
|
38
|
+
export default collectEventRequests;
|