@lowdefy/api 7.1.0 → 7.2.0

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.
Files changed (119) hide show
  1. package/dist/context/createAuthorizeOutcome.js +1 -1
  2. package/dist/context/createEvaluateOperators.js +2 -1
  3. package/dist/context/isWebSocketOriginAllowed.js +3 -1
  4. package/dist/context/readMemberships.js +10 -4
  5. package/dist/context/resolveAuthentication.js +95 -21
  6. package/dist/email/renderAuthEmail.js +3 -2
  7. package/dist/index.js +7 -1
  8. package/dist/response/redactErrorResponse.js +8 -4
  9. package/dist/routes/agent/callAgent.js +20 -2
  10. package/dist/routes/agent/redactMessages.js +136 -0
  11. package/dist/routes/auth/createAuthLogger.js +23 -6
  12. package/dist/routes/auth/createMcpAccessTokenClaims.js +8 -6
  13. package/dist/routes/auth/createOnAPIError.js +15 -5
  14. package/dist/routes/auth/createSendEmail.js +15 -5
  15. package/dist/routes/auth/getBetterAuth.js +3 -3
  16. package/dist/routes/auth/getBetterAuthConfig.js +163 -92
  17. package/dist/routes/auth/hooks/buildEngineHooks.js +15 -1
  18. package/dist/routes/auth/hooks/createUserAfterHook.js +17 -2
  19. package/dist/routes/auth/hooks/createUserBeforeHook.js +20 -4
  20. package/dist/routes/auth/mobile/buildBearerPlugin.js +45 -0
  21. package/dist/routes/auth/mobile/buildOneTimeTokenPlugin.js +50 -0
  22. package/dist/routes/auth/mobile/createCodeVerifierCheck.js +57 -0
  23. package/dist/routes/auth/mobile/createKnownDeviceHook.js +76 -0
  24. package/dist/routes/auth/mobile/createMobileAuthPageResponse.js +79 -0
  25. package/dist/routes/auth/mobile/createMobileSessionCreateHook.js +41 -0
  26. package/dist/routes/auth/mobile/createMobileSessionRefreshHook.js +40 -0
  27. package/dist/routes/auth/mobile/createMobileSignInCsrfToken.js +32 -0
  28. package/dist/routes/auth/mobile/createPhoneSession.js +59 -0
  29. package/dist/routes/auth/mobile/escapeHtml.js +26 -0
  30. package/dist/routes/auth/mobile/getCodeHolderIdentifier.js +20 -0
  31. package/dist/routes/auth/mobile/getKnownDeviceIdentifier.js +20 -0
  32. package/dist/routes/auth/mobile/getMobileSessionExpiry.js +18 -0
  33. package/dist/routes/auth/mobile/getMobileSignInReturnUrl.js +31 -0
  34. package/dist/routes/auth/mobile/getOneTimeTokenIdentifiers.js +26 -0
  35. package/dist/routes/auth/mobile/handleMobileSignIn.js +303 -0
  36. package/dist/routes/auth/mobile/handleMobileSignInCallback.js +30 -0
  37. package/dist/routes/auth/mobile/isNativeAuthRequest.js +33 -0
  38. package/dist/routes/auth/mobile/matchesCodeChallenge.js +29 -0
  39. package/dist/routes/auth/mobile/mintOneTimeToken.js +41 -0
  40. package/dist/routes/auth/mobile/readDeviceKeyHash.js +34 -0
  41. package/dist/routes/auth/mobile/readMobileSignInParams.js +90 -0
  42. package/dist/routes/auth/mobile/sha256Base64Url.js +22 -0
  43. package/dist/routes/auth/mobile/storeCodeChallenge.js +29 -0
  44. package/dist/routes/auth/organizations/buildOrganizationPlugin.js +43 -6
  45. package/dist/routes/auth/organizations/createAcceptExistingMemberHook.js +7 -2
  46. package/dist/routes/auth/organizations/createActiveOrgPolicyHook.js +41 -189
  47. package/dist/routes/auth/organizations/createAdmissionGateHook.js +5 -5
  48. package/dist/routes/auth/organizations/createBeforeCreateInvitationHook.js +62 -0
  49. package/dist/routes/auth/organizations/createBeforeUpdateMemberRoleHook.js +45 -0
  50. package/dist/routes/auth/organizations/createSuspendedMemberGate.js +146 -0
  51. package/dist/routes/auth/organizations/createSuspendedOrganizationsFilter.js +44 -0
  52. package/dist/routes/auth/organizations/ensureAuthIndexes.js +11 -10
  53. package/dist/routes/auth/organizations/getOrganizationBinding.js +4 -2
  54. package/dist/routes/auth/organizations/isActiveMember.js +26 -0
  55. package/dist/routes/auth/organizations/isEmailAdmitted.js +12 -5
  56. package/dist/routes/auth/organizations/memberRowsLimit.js +19 -0
  57. package/dist/routes/auth/organizations/mintOrganization.js +258 -0
  58. package/dist/routes/auth/organizations/organizationAccessControl.js +5 -1
  59. package/dist/routes/auth/organizations/provisionOrganization.js +117 -0
  60. package/dist/routes/auth/organizations/readSuspendedOrganizationIds.js +36 -0
  61. package/dist/routes/auth/requestHooks/buildRequestHooks.js +72 -0
  62. package/dist/routes/auth/requestHooks/createEmailCodeHolderGate.js +58 -0
  63. package/dist/routes/auth/requestHooks/createEmailSendLimit.js +116 -0
  64. package/dist/routes/auth/requestHooks/createSignInRefusedRedirectHook.js +75 -0
  65. package/dist/routes/auth/requestHooks/holdEmailCode.js +80 -0
  66. package/dist/routes/auth/requestHooks/reserveSendSlot.js +70 -0
  67. package/dist/routes/auth/runReportingFaults.js +32 -0
  68. package/dist/routes/connections/resolveUnwalledReach.js +14 -16
  69. package/dist/routes/endpoints/callEndpoint.js +6 -3
  70. package/dist/routes/endpoints/control/controlFor.js +9 -6
  71. package/dist/routes/endpoints/control/controlIf.js +8 -3
  72. package/dist/routes/endpoints/control/controlLog.js +3 -1
  73. package/dist/routes/endpoints/control/controlParallelFor.js +9 -6
  74. package/dist/routes/endpoints/control/controlReturn.js +3 -2
  75. package/dist/routes/endpoints/control/controlSetState.js +1 -1
  76. package/dist/routes/endpoints/control/controlSwitch.js +6 -3
  77. package/dist/routes/endpoints/control/controlWhile.js +6 -3
  78. package/dist/routes/endpoints/createLinkAnswer.js +76 -0
  79. package/dist/routes/endpoints/dispatchDetached.js +38 -0
  80. package/dist/routes/endpoints/forwardScheduledEndpoint.js +32 -11
  81. package/dist/routes/endpoints/handleAgentCall.js +1 -1
  82. package/dist/routes/endpoints/handleAuthStep.js +19 -4
  83. package/dist/routes/endpoints/handleEndpointCall.js +6 -4
  84. package/dist/routes/endpoints/handleRequest.js +3 -2
  85. package/dist/routes/endpoints/handleValidateDynamic.js +1 -1
  86. package/dist/routes/endpoints/matchLinkEndpoint.js +30 -0
  87. package/dist/routes/endpoints/runLinkEndpoint.js +148 -0
  88. package/dist/routes/endpoints/runRoutine.js +5 -5
  89. package/dist/routes/endpoints/scheduleBackground.js +13 -11
  90. package/dist/routes/endpoints/test/runTest.js +30 -11
  91. package/dist/routes/mcp/createMcpServer.js +2 -7
  92. package/dist/routes/mcp/runAfterToolCall.js +9 -3
  93. package/dist/routes/mobile/createAppleAppSiteAssociation.js +51 -0
  94. package/dist/routes/mobile/createAssetLinks.js +38 -0
  95. package/dist/routes/mobile/filterMobileMenus.js +31 -0
  96. package/dist/routes/mobile/getMobileAppEvents.js +23 -0
  97. package/dist/routes/mobile/getMobileRootConfig.js +109 -0
  98. package/dist/routes/mobile/getOpenablePageIds.js +21 -0
  99. package/dist/routes/page/dynamic/policy/checkAction.js +67 -2
  100. package/dist/routes/page/dynamic/policy/checkEvents.js +8 -2
  101. package/dist/routes/page/dynamic/policy/checkPolicy.js +86 -6
  102. package/dist/routes/page/dynamic/policy/checkValue.js +97 -6
  103. package/dist/routes/page/dynamic/policy/collectSchemaKinds.js +173 -0
  104. package/dist/routes/page/dynamic/policy/findDataRows.js +94 -0
  105. package/dist/routes/page/dynamic/policy/findEmbeddedUrls.js +24 -12
  106. package/dist/routes/page/dynamic/policy/findHtmlUrls.js +64 -0
  107. package/dist/routes/page/dynamic/policy/overlapsStatePath.js +28 -0
  108. package/dist/routes/page/dynamic/resolveDynamicContent.js +23 -17
  109. package/dist/routes/page/getPageConfig.js +25 -1
  110. package/dist/routes/request/callRequestResolver.js +29 -36
  111. package/dist/routes/request/stampTypedError.js +37 -0
  112. package/dist/routes/request/summarisedError.js +62 -0
  113. package/dist/routes/request/wrapResolverError.js +61 -0
  114. package/dist/routes/websocket/createChannelRegistry.js +13 -15
  115. package/dist/routes/websocket/createWebSocketConnection.js +5 -8
  116. package/dist/test/createMemoryAuth.js +125 -0
  117. package/package.json +20 -22
  118. package/dist/routes/page/dynamic/policy/collectUrlKinds.js +0 -117
  119. package/dist/routes/request/maskCredentialProperties.js +0 -34
@@ -0,0 +1,37 @@
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 summarisedError from './summarisedError.js';
16
+ // A connection that already typed its error (a ServiceError on a time limit, a ConfigError)
17
+ // passes through the interface layer without a new wrapper, which would nest causes. It still
18
+ // leaves with the step's ids and its cause summarised, like a wrapped error: the cause is the
19
+ // connection's own error, which can quote every document of a failed bulk write. Ids an inner
20
+ // step already set (an error from a nested CallApi) are kept, since they name where it failed,
21
+ // and a cause already summarised there keeps the devCause it was given.
22
+ function stampTypedError(error, { fields }) {
23
+ Object.entries(fields).forEach(([key, value])=>{
24
+ if (error[key] === undefined) {
25
+ error[key] = value;
26
+ }
27
+ });
28
+ if (error.devCause !== undefined || typeof error.cause?.message !== 'string') {
29
+ return;
30
+ }
31
+ Object.defineProperty(error, 'devCause', {
32
+ value: error.cause,
33
+ configurable: true
34
+ });
35
+ error.cause = summarisedError(error.cause);
36
+ }
37
+ export default stampTypedError;
@@ -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 { errorSummaryForLog, readErrorCodes } from '@lowdefy/errors';
16
+ // Stack frames name code, never data, so they are kept. The stack's opening lines repeat the
17
+ // message, so they are rebuilt from the summary's; they are dropped by count, not by shape,
18
+ // since a message can hold a line that looks like a frame.
19
+ function stackFrames(error) {
20
+ if (typeof error.stack !== 'string') return [];
21
+ const headerLineCount = String(error).split('\n').length;
22
+ return error.stack.split('\n').slice(headerLineCount).filter((line)=>/^\s+at /.test(line));
23
+ }
24
+ // An error from another realm, such as a DOMException in a VM context, fails instanceof Error.
25
+ function isError(value) {
26
+ if (value instanceof Error) return true;
27
+ return typeof value === 'object' && value !== null && typeof value.stack === 'string' && typeof value.message === 'string';
28
+ }
29
+ function fromSummary(summary, original) {
30
+ const message = summary.message ?? `${summary.name} (message withheld from logs).`;
31
+ const error = new Error(message);
32
+ error.name = summary.name;
33
+ error.stack = [
34
+ `${summary.name}: ${message}`,
35
+ ...stackFrames(original)
36
+ ].join('\n');
37
+ if (summary.code !== undefined) error.code = summary.code;
38
+ if (summary.statusCode !== undefined) error.statusCode = summary.statusCode;
39
+ const cause = original.lastError ?? original.cause;
40
+ if (summary.cause !== undefined && isError(cause)) {
41
+ error.cause = fromSummary(summary.cause, cause);
42
+ }
43
+ return error;
44
+ }
45
+ // A request resolver's error rebuilt from its log summary: the name, code, status code and
46
+ // message cut to 500 characters, with the stack frames, for the error and three causes. A
47
+ // connection's error can carry the request's inputs in its other fields - a MongoDB write
48
+ // error the document it rejected, an HTTP client's error the request body - and every log
49
+ // and error report writes the error it is given, so none of them is kept.
50
+ function summarisedError(error) {
51
+ if (!isError(error)) {
52
+ const { code, statusCode } = readErrorCodes(error);
53
+ return fromSummary({
54
+ name: 'Error',
55
+ message: `Request resolver threw a value of type ${typeof error}, not an error.`,
56
+ code,
57
+ statusCode
58
+ }, {});
59
+ }
60
+ return fromSummary(errorSummaryForLog(error), error);
61
+ }
62
+ export default summarisedError;
@@ -0,0 +1,61 @@
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 { RequestError, ServiceError } from '@lowdefy/errors';
17
+ import summarisedError from './summarisedError.js';
18
+ // The interface layer's wrap of a connection's error, for a request step and a websocket source
19
+ // alike. The error that leaves here is logged whole at error level and sent to Sentry, so it
20
+ // carries ids (`fields`) and the connection's error summarised - never the evaluated properties
21
+ // (an agent chat's save-thread step holds the whole thread there) or the connection's error
22
+ // itself, which can embed the document it rejected. The dev tools still show that error: it is
23
+ // kept as devCause, which is not enumerable, so no log or error report walks it, and only the dev
24
+ // error payload reads it.
25
+ function wrapResolverError(error, { configKey, fields, location, service, typeName }) {
26
+ const cause = summarisedError(error);
27
+ let wrapped;
28
+ if (ServiceError.isServiceError(error)) {
29
+ // ServiceError reads the code, HTTP status, Retry-After and hint from its cause, wherever the
30
+ // client put them, so it is built over the connection's error with only the message cut, then
31
+ // given the summary as its cause. A Proxy, not a copy: a DOMException's fields are getters
32
+ // that only work on the exception itself.
33
+ wrapped = new ServiceError(undefined, {
34
+ cause: new Proxy(error, {
35
+ get: (target, key)=>key === 'message' ? cause.message : target[key]
36
+ }),
37
+ service,
38
+ configKey
39
+ });
40
+ wrapped.cause = cause;
41
+ } else {
42
+ wrapped = new RequestError(cause.message, {
43
+ cause,
44
+ typeName,
45
+ location,
46
+ configKey
47
+ });
48
+ // A connection that refuses a request says what to do about it in `hint` (a MongoDB
49
+ // duplicate key), which the summary does not keep.
50
+ if (type.isString(error?.hint)) {
51
+ wrapped.hint = error.hint;
52
+ }
53
+ }
54
+ Object.assign(wrapped, fields);
55
+ Object.defineProperty(wrapped, 'devCause', {
56
+ value: error,
57
+ configurable: true
58
+ });
59
+ return wrapped;
60
+ }
61
+ export default wrapResolverError;
@@ -14,9 +14,10 @@
14
14
  limitations under the License.
15
15
  */ import crypto from 'crypto';
16
16
  import { serializer } from '@lowdefy/helpers';
17
- import { ConfigError, PluginError, ServiceError } from '@lowdefy/errors';
17
+ import { ConfigError } from '@lowdefy/errors';
18
18
  import createWireProjection from '../../response/createWireProjection.js';
19
19
  import prepareChannel from './prepareChannel.js';
20
+ import wrapResolverError from '../request/wrapResolverError.js';
20
21
  const MAX_RETRIES = 5;
21
22
  const RETRY_BASE_MS = 1000;
22
23
  const HEALTHY_RESET_MS = 60 * 1000;
@@ -62,26 +63,23 @@ function createChannelRegistry() {
62
63
  }));
63
64
  });
64
65
  }
65
- function wrapResolverError({ channel, error }) {
66
+ // Wrapped like a request step's error: the evaluated properties stay out of it, and the
67
+ // source's own error is summarised, since both are logged and sent to Sentry.
68
+ function wrapSourceError({ channel, error }) {
66
69
  if (!error.configKey) {
67
70
  error.configKey = channel.websocketConfig['~k'];
68
71
  }
69
72
  if (error.isLowdefyError) {
70
73
  return error;
71
74
  }
72
- if (ServiceError.isServiceError(error)) {
73
- return new ServiceError(undefined, {
74
- cause: error,
75
- service: channel.websocketConfig.connectionId ?? channel.websocketConfig.type,
76
- configKey: channel.websocketConfig['~k']
77
- });
78
- }
79
- return new PluginError(error.message, {
80
- cause: error,
81
- typeName: channel.websocketConfig.type,
82
- received: channel.properties,
75
+ return wrapResolverError(error, {
76
+ configKey: channel.websocketConfig['~k'],
77
+ fields: {
78
+ connectionId: channel.websocketConfig.connectionId
79
+ },
83
80
  location: channel.websocketConfig.websocketId,
84
- configKey: channel.websocketConfig['~k']
81
+ service: channel.websocketConfig.connectionId ?? channel.websocketConfig.type,
82
+ typeName: channel.websocketConfig.type
85
83
  });
86
84
  }
87
85
  function removeChannel(channel) {
@@ -101,7 +99,7 @@ function createChannelRegistry() {
101
99
  }, error.message);
102
100
  return;
103
101
  }
104
- const wrapped = wrapResolverError({
102
+ const wrapped = wrapSourceError({
105
103
  channel,
106
104
  error
107
105
  });
@@ -12,7 +12,8 @@
12
12
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
- */ import { type } from '@lowdefy/helpers';
15
+ */ import { isExpectedError } from '@lowdefy/errors';
16
+ import { type } from '@lowdefy/helpers';
16
17
  import { runInCredentialScope } from '@lowdefy/node-utils';
17
18
  import getCallerFingerprint from './getCallerFingerprint.js';
18
19
  import redactErrorResponse from '../../response/redactErrorResponse.js';
@@ -187,13 +188,9 @@ function createWebSocketConnection(context, { closeSocket, headers, registry, se
187
188
  logger.debug({
188
189
  err: error
189
190
  }, error.message);
190
- // Authentication and authorization refusals are expected traffic - one
191
- // warn line, no error log or Sentry report, but the client is still told.
192
- if ([
193
- 'AuthenticationError',
194
- 'AuthorizationError',
195
- 'TwoFactorEnrolmentRequiredError'
196
- ].includes(error.name)) {
191
+ // Expected outcomes - an auth refusal, a UserError - are one warn line, as over HTTP:
192
+ // no error log or Sentry report, but the client is still told.
193
+ if (isExpectedError(error)) {
197
194
  logger.warn({
198
195
  event: 'ws_refused',
199
196
  frameType: frame.type
@@ -0,0 +1,125 @@
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 { vi } from 'vitest';
16
+ // An in-memory auth database holding the unique indexes ensureAuthIndexes
17
+ // creates - one organization per slug, one member row per (user, org) - so the
18
+ // mint's recovery from a lost race runs against the same rejection a real
19
+ // database gives. `before` pauses an operation until the test releases it,
20
+ // which fixes the interleaving of two concurrent sessions.
21
+ function createMemoryAuth({ organizations = [], members = [], ensureUniqueIndexes } = {}) {
22
+ const db = {
23
+ organization: [
24
+ ...organizations
25
+ ],
26
+ member: [
27
+ ...members
28
+ ]
29
+ };
30
+ const pauses = [];
31
+ let ids = 0;
32
+ function matches(row, where) {
33
+ return where.every(({ field, value, operator })=>operator === 'ne' ? row[field] !== value : row[field] === value);
34
+ }
35
+ async function pause(operation, args) {
36
+ const found = pauses.find((entry)=>entry.match(operation, args));
37
+ if (found) {
38
+ pauses.splice(pauses.indexOf(found), 1);
39
+ found.reached();
40
+ await found.released;
41
+ }
42
+ }
43
+ const adapter = {
44
+ options: {
45
+ ensureUniqueIndexes: ensureUniqueIndexes ?? vi.fn(async ()=>{})
46
+ },
47
+ findOne: vi.fn(async ({ model, where })=>{
48
+ await pause('findOne', {
49
+ model,
50
+ where
51
+ });
52
+ return db[model].find((row)=>matches(row, where)) ?? null;
53
+ }),
54
+ findMany: vi.fn(async ({ model, where })=>{
55
+ if (model === 'invitation') return [];
56
+ return db[model].filter((row)=>matches(row, where));
57
+ }),
58
+ create: vi.fn(async ({ model, data })=>{
59
+ await pause('create', {
60
+ model,
61
+ data
62
+ });
63
+ const duplicate = model === 'organization' ? db.organization.some((row)=>row.slug === data.slug) : db.member.some((row)=>row.userId === data.userId && row.organizationId === data.organizationId);
64
+ if (duplicate) {
65
+ throw new Error(`E11000 duplicate key error collection: ${model}`);
66
+ }
67
+ ids += 1;
68
+ const row = {
69
+ id: `${model}_${ids}`,
70
+ ...data
71
+ };
72
+ db[model].push(row);
73
+ return {
74
+ ...row
75
+ };
76
+ }),
77
+ count: vi.fn(async ({ model, where })=>db[model].filter((row)=>matches(row, where)).length),
78
+ update: vi.fn(async ({ model, where, update })=>{
79
+ const row = db[model].find((candidate)=>matches(candidate, where));
80
+ Object.assign(row, update);
81
+ return {
82
+ ...row
83
+ };
84
+ })
85
+ };
86
+ const internalAdapter = {
87
+ findUserById: vi.fn(async (id)=>({
88
+ id,
89
+ email: `${id}@example.com`,
90
+ name: 'User One'
91
+ }))
92
+ };
93
+ const auth = {
94
+ $context: Promise.resolve({
95
+ adapter,
96
+ internalAdapter
97
+ })
98
+ };
99
+ // Pause the next operation matching `match` until release() is called;
100
+ // reached resolves once a session is waiting there.
101
+ function before(match) {
102
+ const entry = {
103
+ match
104
+ };
105
+ const reached = new Promise((resolve)=>{
106
+ entry.reached = resolve;
107
+ });
108
+ let release;
109
+ entry.released = new Promise((resolve)=>{
110
+ release = resolve;
111
+ });
112
+ pauses.push(entry);
113
+ return {
114
+ reached,
115
+ release
116
+ };
117
+ }
118
+ return {
119
+ auth,
120
+ adapter,
121
+ db,
122
+ before
123
+ };
124
+ }
125
+ export default createMemoryAuth;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/api",
3
- "version": "7.1.0",
3
+ "version": "7.2.0",
4
4
  "license": "Apache-2.0",
5
5
  "description": "",
6
6
  "homepage": "https://lowdefy.com",
@@ -38,33 +38,31 @@
38
38
  "@better-auth/cimd": "1.7.7",
39
39
  "@better-auth/oauth-provider": "1.7.7",
40
40
  "@better-auth/passkey": "1.7.7",
41
- "@lowdefy/ajv": "7.1.0",
42
- "@lowdefy/build": "7.1.0",
43
- "@lowdefy/connection-smtp": "7.1.0",
44
- "@lowdefy/email-templates": "7.1.0",
45
- "@lowdefy/errors": "7.1.0",
46
- "@lowdefy/helpers": "7.1.0",
47
- "@lowdefy/node-utils": "7.1.0",
48
- "@lowdefy/nunjucks": "7.1.0",
49
- "@lowdefy/operators": "7.1.0",
50
- "@lowdefy/operators-js": "7.1.0",
51
- "@modelcontextprotocol/sdk": "1.31.0",
41
+ "@lowdefy/ajv": "7.2.0",
42
+ "@lowdefy/build": "7.2.0",
43
+ "@lowdefy/connection-smtp": "7.2.0",
44
+ "@lowdefy/email-templates": "7.2.0",
45
+ "@lowdefy/errors": "7.2.0",
46
+ "@lowdefy/helpers": "7.2.0",
47
+ "@lowdefy/node-utils": "7.2.0",
48
+ "@lowdefy/nunjucks": "7.2.0",
49
+ "@lowdefy/operators": "7.2.0",
50
+ "@lowdefy/operators-js": "7.2.0",
51
+ "@modelcontextprotocol/sdk": "1.32.2",
52
52
  "better-auth": "1.7.7",
53
53
  "jose": "^6.2.3",
54
54
  "mongodb-connection-string-url": "^7.0.2",
55
- "nodemailer": "10.0.13"
55
+ "nodemailer": "10.1.7"
56
56
  },
57
57
  "devDependencies": {
58
- "@jest/globals": "28.1.3",
59
- "@lowdefy/connection-mongodb": "7.1.0",
60
- "@lowdefy/plugin-better-auth": "7.1.0",
58
+ "@lowdefy/connection-mongodb": "7.2.0",
59
+ "@lowdefy/plugin-better-auth": "7.2.0",
61
60
  "@opentelemetry/api": "1.9.1",
62
- "@shelf/jest-mongodb": "4.3.2",
63
61
  "@swc/cli": "0.8.1",
64
62
  "@swc/core": "1.15.32",
65
- "@swc/jest": "0.2.39",
66
- "jest": "28.1.3",
67
- "mongodb": "7.2.0"
63
+ "mongodb": "7.2.0",
64
+ "mongodb-memory-server-core": "9.2.0",
65
+ "vitest": "4.1.12"
68
66
  },
69
67
  "publishConfig": {
70
68
  "access": "public"
@@ -72,7 +70,7 @@
72
70
  "scripts": {
73
71
  "build": "swc src --out-dir dist --config-file ../../.swcrc --cli-config-file ../../.swc-cli.json",
74
72
  "clean": "rm -rf dist",
75
- "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
76
- "test:mongodb": "node --experimental-vm-modules node_modules/jest/bin/jest.js --config jest.mongodb.config.js"
73
+ "test": "vitest run",
74
+ "test:mongodb": "vitest run --config vitest.mongodb.config.js"
77
75
  }
78
76
  }
@@ -1,117 +0,0 @@
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 schemas that can describe a value: the schema itself and its oneOf,
17
- // anyOf and allOf branches, however nested.
18
- function expandSchema(schema) {
19
- const schemas = [];
20
- const pending = [
21
- schema
22
- ];
23
- while(pending.length > 0){
24
- const candidate = pending.pop();
25
- if (type.isObject(candidate)) {
26
- schemas.push(candidate);
27
- [
28
- ...candidate.oneOf ?? [],
29
- ...candidate.anyOf ?? [],
30
- ...candidate.allOf ?? []
31
- ].forEach((branch)=>pending.push(branch));
32
- }
33
- }
34
- return schemas;
35
- }
36
- function childSchemas({ schemas, key }) {
37
- return schemas.flatMap((schema)=>{
38
- if (type.isObject(schema.properties?.[key])) {
39
- return [
40
- schema.properties[key]
41
- ];
42
- }
43
- if (type.isObject(schema.additionalProperties)) {
44
- return [
45
- schema.additionalProperties
46
- ];
47
- }
48
- return [];
49
- });
50
- }
51
- // The urlKind the schemas give a value: a string when one marks it as a URL,
52
- // null when one opts it out with urlKind: false, undefined when none says.
53
- function findUrlKind(schemas) {
54
- const marked = schemas.find((candidate)=>type.isString(candidate.urlKind));
55
- if (marked) {
56
- return marked.urlKind;
57
- }
58
- if (schemas.some((candidate)=>candidate.urlKind === false)) {
59
- return null;
60
- }
61
- return undefined;
62
- }
63
- // Records, by path, the urlKind a block schema gives the value there. A block
64
- // marks each URL-valued property with urlKind ('url' and 'href' navigate, 'url'
65
- // the way the engine's link resolver does; 'src' loads; 'srcSet' lists
66
- // sources), so the policy judges URLs by what a property is, not by what it is
67
- // called; a marked array holds one URL per item. urlKind: false records null,
68
- // for a property whose name looks like a URL key but whose value is not a URL.
69
- // A value no schema marks either way is not recorded, so the policy falls back
70
- // to judging it by its key name.
71
- function collectUrlKinds({ value, schema, path }) {
72
- const kinds = new Map();
73
- const pending = [
74
- {
75
- value,
76
- schema,
77
- path
78
- }
79
- ];
80
- while(pending.length > 0){
81
- const item = pending.pop();
82
- const schemas = expandSchema(item.schema);
83
- const urlKind = findUrlKind(schemas);
84
- if (urlKind === null) {
85
- // Another schema branch may already have marked it as a URL.
86
- if (!kinds.has(item.path)) {
87
- kinds.set(item.path, null);
88
- }
89
- } else if (type.isString(urlKind)) {
90
- if (type.isArray(item.value)) {
91
- item.value.forEach((_, index)=>kinds.set(`${item.path}.${index}`, urlKind));
92
- } else {
93
- kinds.set(item.path, urlKind);
94
- }
95
- } else if (type.isArray(item.value)) {
96
- const itemSchemas = schemas.map((candidate)=>candidate.items).filter(type.isObject);
97
- item.value.forEach((child, index)=>itemSchemas.forEach((itemSchema)=>pending.push({
98
- value: child,
99
- schema: itemSchema,
100
- path: `${item.path}.${index}`
101
- })));
102
- } else if (type.isObject(item.value)) {
103
- Object.keys(item.value).forEach((key)=>{
104
- childSchemas({
105
- schemas,
106
- key
107
- }).forEach((childSchema)=>pending.push({
108
- value: item.value[key],
109
- schema: childSchema,
110
- path: `${item.path}.${key}`
111
- }));
112
- });
113
- }
114
- }
115
- return kinds;
116
- }
117
- export default collectUrlKinds;
@@ -1,34 +0,0 @@
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
- */ // A request type names in meta.credentialProperties the request properties that carry a
16
- // credential the secret scrub cannot recognise, such as a presigned link, whose signature is
17
- // derived from a secret rather than being one. Their values are masked in the request properties
18
- // an error keeps as received, so the error log never holds them.
19
- function maskCredentialProperties({ requestProperties, requestResolver }) {
20
- const credentialProperties = requestResolver.meta.credentialProperties ?? [];
21
- if (credentialProperties.length === 0) {
22
- return requestProperties;
23
- }
24
- const masked = {
25
- ...requestProperties
26
- };
27
- credentialProperties.forEach((property)=>{
28
- if (Object.hasOwn(masked, property)) {
29
- masked[property] = '[REDACTED]';
30
- }
31
- });
32
- return masked;
33
- }
34
- export default maskCredentialProperties;