@capybara-hq/kernel 0.1.0-rc.60 → 0.1.0-rc.62
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/admin/admin.module.js +3 -0
- package/dist/admin/extensions.controller.d.ts +32 -1
- package/dist/admin/extensions.controller.js +72 -3
- package/dist/admin/health.service.d.ts +2 -2
- package/dist/admin/health.service.js +6 -2
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/config/schema.d.ts +6 -0
- package/dist/config/schema.js +12 -0
- package/dist/conversations/attachments.controller.d.ts +11 -3
- package/dist/conversations/attachments.controller.js +18 -5
- package/dist/conversations/conversations.controller.d.ts +11 -2
- package/dist/conversations/conversations.controller.js +17 -4
- package/dist/conversations/conversations.schemas.d.ts +8 -0
- package/dist/conversations/conversations.schemas.js +6 -0
- package/dist/conversations/event-log.d.ts +12 -3
- package/dist/conversations/event-log.js +17 -5
- package/dist/ctx/secrets.d.ts +10 -5
- package/dist/ctx/secrets.js +16 -5
- package/dist/db/kernel-schema.d.ts +34 -2
- package/dist/errors.d.ts +7 -0
- package/dist/errors.js +7 -0
- package/dist/extensions/config-hash.d.ts +2 -0
- package/dist/extensions/config-hash.js +1 -1
- package/dist/extensions/guide-places.d.ts +5 -1
- package/dist/extensions/guide-places.js +9 -2
- package/dist/extensions/permission-view.d.ts +6 -4
- package/dist/extensions/permission-view.js +6 -3
- package/dist/extensions/plugin-guides.d.ts +20 -0
- package/dist/extensions/plugin-guides.js +49 -1
- package/dist/extensions/registry.js +1 -0
- package/dist/http/api.module.js +7 -0
- package/dist/http/meta.controller.d.ts +7 -1
- package/dist/http/meta.controller.js +14 -3
- package/dist/identity/accounts.js +5 -0
- package/dist/identity/sessions.d.ts +7 -0
- package/dist/identity/sessions.js +26 -4
- package/dist/inbox/platform-inbox.service.d.ts +21 -11
- package/dist/inbox/platform-inbox.service.js +27 -12
- package/dist/inbox/platform-notices.d.ts +15 -1
- package/dist/inbox/platform-notices.js +20 -0
- package/dist/infra/config/kernel-config.service.js +2 -0
- package/dist/infra/outbox/registry.d.ts +36 -0
- package/dist/infra/outbox/registry.js +30 -0
- package/dist/infra/queue/queue-names.d.ts +1 -1
- package/dist/infra/queue/queue-names.js +1 -0
- package/dist/orgs/offboarding.js +3 -0
- package/dist/overrides.d.ts +4 -0
- package/dist/overrides.js +2 -0
- package/dist/platform/exclusions.js +15 -0
- package/dist/platform/ops/extensions-admin.ops.d.ts +5 -1
- package/dist/platform/ops/extensions-admin.ops.js +97 -2
- package/dist/platform/ops/inbox.ops.d.ts +1 -1
- package/dist/platform/ops/inbox.ops.js +17 -7
- package/dist/platform/ops/platform.ops.d.ts +4 -2
- package/dist/platform/ops/platform.ops.js +55 -3
- package/dist/platform/platform-ops.module.js +2 -0
- package/dist/platform/route-schemas.js +3 -0
- package/dist/push/delivery.d.ts +88 -0
- package/dist/push/delivery.js +269 -0
- package/dist/push/fanout.d.ts +29 -0
- package/dist/push/fanout.js +95 -0
- package/dist/push/jobs.d.ts +43 -0
- package/dist/push/jobs.js +19 -0
- package/dist/push/preferences.service.d.ts +18 -0
- package/dist/push/preferences.service.js +82 -0
- package/dist/push/provider-host.d.ts +34 -0
- package/dist/push/provider-host.js +94 -0
- package/dist/push/push-owed.d.ts +33 -0
- package/dist/push/push-owed.js +93 -0
- package/dist/push/push-processor.d.ts +40 -0
- package/dist/push/push-processor.js +114 -0
- package/dist/push/push.controller.d.ts +28 -0
- package/dist/push/push.controller.js +92 -0
- package/dist/push/push.module.d.ts +6 -0
- package/dist/push/push.module.js +29 -0
- package/dist/push/push.schemas.d.ts +88 -0
- package/dist/push/push.schemas.js +53 -0
- package/dist/push/recipients.d.ts +29 -0
- package/dist/push/recipients.js +263 -0
- package/dist/push/registration-cleanup.d.ts +9 -0
- package/dist/push/registration-cleanup.js +16 -0
- package/dist/push/registrations.service.d.ts +55 -0
- package/dist/push/registrations.service.js +254 -0
- package/dist/push/stale.job.d.ts +25 -0
- package/dist/push/stale.job.js +76 -0
- package/dist/push/texts.d.ts +31 -0
- package/dist/push/texts.js +46 -0
- package/dist/push/token-store.d.ts +31 -0
- package/dist/push/token-store.js +52 -0
- package/dist/push/triggers.d.ts +19 -0
- package/dist/push/triggers.js +30 -0
- package/dist/roles/worker-role.d.ts +7 -4
- package/dist/roles/worker-role.js +12 -5
- package/dist/roles/worker.module.d.ts +1 -1
- package/dist/roles/worker.module.js +4 -1
- package/dist/schedules/run-tracker.d.ts +10 -2
- package/dist/schedules/run-tracker.js +18 -4
- package/dist/setup/setup-checks.schemas.d.ts +29 -0
- package/dist/setup/setup-checks.schemas.js +32 -0
- package/dist/setup/setup-checks.service.d.ts +36 -3
- package/dist/setup/setup-checks.service.js +137 -29
- package/package.json +4 -4
- package/src/migrations/0172_push.sql +40 -0
- package/src/migrations/0173_push_auth_notice.sql +10 -0
package/dist/ctx/secrets.d.ts
CHANGED
|
@@ -50,6 +50,8 @@ export interface RewrapResult {
|
|
|
50
50
|
initialPasswords: number;
|
|
51
51
|
/** Unexpired sealed Platform reveals (`platform_sealed_reveals`, invitation links) now sealed with it. */
|
|
52
52
|
sealedReveals: number;
|
|
53
|
+
/** Mobile app push tokens (`push_registrations`) now sealed with it. */
|
|
54
|
+
pushTokens: number;
|
|
53
55
|
}
|
|
54
56
|
/** Rows rewrapped per transaction by default. */
|
|
55
57
|
export declare const REWRAP_BATCH_SIZE = 500;
|
|
@@ -65,16 +67,19 @@ export declare const platformSealedInputAad: (approvalId: string, paths: readonl
|
|
|
65
67
|
* another subject fails to unwrap.
|
|
66
68
|
*/
|
|
67
69
|
export declare const platformSealedRevealAad: (id: string) => string;
|
|
70
|
+
/** The AAD binding a sealed push token to its registration (a row moved to another one fails). */
|
|
71
|
+
export declare const pushTokenAad: (registrationId: string) => string;
|
|
68
72
|
type RewrapHandles = {
|
|
69
73
|
db: Pick<KernelDb, "db">;
|
|
70
74
|
txHost: Pick<TransactionHost, "run">;
|
|
71
75
|
};
|
|
72
76
|
/**
|
|
73
|
-
* Rewraps everything sealed with a master key other than the keyring's current one (org data keys
|
|
74
|
-
*
|
|
75
|
-
* none is left. Checks first that the keyring holds every master key in use and
|
|
76
|
-
* ids and key ids, never key material) before writing anything when it does not.
|
|
77
|
-
* second run finds nothing; concurrent runs lock the same rows and skip the ones
|
|
77
|
+
* Rewraps everything sealed with a master key other than the keyring's current one (org data keys,
|
|
78
|
+
* unexpired initial passwords and sealed reveals, push tokens) with the current key, `batchSize` rows per
|
|
79
|
+
* transaction, until none is left. Checks first that the keyring holds every master key in use and
|
|
80
|
+
* throws (naming row ids and key ids, never key material) before writing anything when it does not.
|
|
81
|
+
* Idempotent: a second run finds nothing; concurrent runs lock the same rows and skip the ones
|
|
82
|
+
* already done.
|
|
78
83
|
*/
|
|
79
84
|
export declare function rewrapToCurrentMasterKey(handles: RewrapHandles, keyring: Keyring, opts?: {
|
|
80
85
|
batchSize?: number;
|
package/dist/ctx/secrets.js
CHANGED
|
@@ -157,6 +157,8 @@ export const platformSealedInputAad = (approvalId, paths) => `capybara:platform-
|
|
|
157
157
|
* another subject fails to unwrap.
|
|
158
158
|
*/
|
|
159
159
|
export const platformSealedRevealAad = (id) => `capybara:platform-sealed-reveal:${id}`;
|
|
160
|
+
/** The AAD binding a sealed push token to its registration (a row moved to another one fails). */
|
|
161
|
+
export const pushTokenAad = (registrationId) => `capybara:push-token:${registrationId}`;
|
|
160
162
|
const MASTER_KEYED = [
|
|
161
163
|
{
|
|
162
164
|
table: "org_data_keys",
|
|
@@ -179,6 +181,13 @@ const MASTER_KEYED = [
|
|
|
179
181
|
aad: platformSealedRevealAad,
|
|
180
182
|
hasExpiresAt: true,
|
|
181
183
|
},
|
|
184
|
+
{
|
|
185
|
+
table: "push_registrations",
|
|
186
|
+
idColumn: "id",
|
|
187
|
+
dataColumn: "token_ciphertext",
|
|
188
|
+
aad: pushTokenAad,
|
|
189
|
+
hasExpiresAt: false,
|
|
190
|
+
},
|
|
182
191
|
];
|
|
183
192
|
function staleRows(db, t, keyring) {
|
|
184
193
|
let q = db
|
|
@@ -197,11 +206,12 @@ function assertKnown(t, keyring, rows) {
|
|
|
197
206
|
throw new Error(`secrets: master key not in keyring for ${t.table}.${t.idColumn}: ${shown.join(", ")}`);
|
|
198
207
|
}
|
|
199
208
|
/**
|
|
200
|
-
* Rewraps everything sealed with a master key other than the keyring's current one (org data keys
|
|
201
|
-
*
|
|
202
|
-
* none is left. Checks first that the keyring holds every master key in use and
|
|
203
|
-
* ids and key ids, never key material) before writing anything when it does not.
|
|
204
|
-
* second run finds nothing; concurrent runs lock the same rows and skip the ones
|
|
209
|
+
* Rewraps everything sealed with a master key other than the keyring's current one (org data keys,
|
|
210
|
+
* unexpired initial passwords and sealed reveals, push tokens) with the current key, `batchSize` rows per
|
|
211
|
+
* transaction, until none is left. Checks first that the keyring holds every master key in use and
|
|
212
|
+
* throws (naming row ids and key ids, never key material) before writing anything when it does not.
|
|
213
|
+
* Idempotent: a second run finds nothing; concurrent runs lock the same rows and skip the ones
|
|
214
|
+
* already done.
|
|
205
215
|
*/
|
|
206
216
|
export async function rewrapToCurrentMasterKey(handles, keyring, opts = {}) {
|
|
207
217
|
const batchSize = opts.batchSize ?? REWRAP_BATCH_SIZE;
|
|
@@ -260,5 +270,6 @@ export async function rewrapToCurrentMasterKey(handles, keyring, opts = {}) {
|
|
|
260
270
|
dataKeys: counts.get("org_data_keys") ?? 0,
|
|
261
271
|
initialPasswords: counts.get("account_initial_passwords") ?? 0,
|
|
262
272
|
sealedReveals: counts.get("platform_sealed_reveals") ?? 0,
|
|
273
|
+
pushTokens: counts.get("push_registrations") ?? 0,
|
|
263
274
|
};
|
|
264
275
|
}
|
|
@@ -161,6 +161,33 @@ export interface PlatformSealedRevealsTable {
|
|
|
161
161
|
expires_at: Date | string;
|
|
162
162
|
created_at: Ts;
|
|
163
163
|
}
|
|
164
|
+
/** A person's mobile app push registration (migration 0172); the token is sealed. */
|
|
165
|
+
export interface PushRegistrationsTable {
|
|
166
|
+
id: string;
|
|
167
|
+
account_id: string;
|
|
168
|
+
/** The session that posted it; revoking that session deletes the registration. */
|
|
169
|
+
session_id: string | null;
|
|
170
|
+
platform: "ios" | "android";
|
|
171
|
+
app_id: string;
|
|
172
|
+
/** The push-provider extension (plugin name) the registration is delivered through. */
|
|
173
|
+
provider: string;
|
|
174
|
+
/** sha256 hex of the token, unique per (provider, app_id). */
|
|
175
|
+
token_hash: string;
|
|
176
|
+
master_key_id: string;
|
|
177
|
+
/** AES-256-GCM with the master keyring, AAD `pushTokenAad(id)`. */
|
|
178
|
+
token_ciphertext: Buffer;
|
|
179
|
+
locale: "zh" | "en";
|
|
180
|
+
device_name: string;
|
|
181
|
+
created_at: Ts;
|
|
182
|
+
last_seen_at: Ts;
|
|
183
|
+
}
|
|
184
|
+
/** A person's switch for one push category (migration 0172); an absent row is on. */
|
|
185
|
+
export interface PushPreferencesTable {
|
|
186
|
+
account_id: string;
|
|
187
|
+
category: "waiting" | "replies" | "tasks" | "schedules";
|
|
188
|
+
enabled: boolean;
|
|
189
|
+
updated_at: Ts;
|
|
190
|
+
}
|
|
164
191
|
export interface IdentitiesTable {
|
|
165
192
|
source: string;
|
|
166
193
|
external_id: string;
|
|
@@ -1662,6 +1689,8 @@ export interface KernelDatabase {
|
|
|
1662
1689
|
account_initial_passwords: AccountInitialPasswordsTable;
|
|
1663
1690
|
platform_sealed_inputs: PlatformSealedInputsTable;
|
|
1664
1691
|
platform_sealed_reveals: PlatformSealedRevealsTable;
|
|
1692
|
+
push_registrations: PushRegistrationsTable;
|
|
1693
|
+
push_preferences: PushPreferencesTable;
|
|
1665
1694
|
identities: IdentitiesTable;
|
|
1666
1695
|
local_passwords: LocalPasswordsTable;
|
|
1667
1696
|
orgs: OrgsTable;
|
|
@@ -1839,10 +1868,13 @@ export interface OrgNoticesTable {
|
|
|
1839
1868
|
dismissed_at: TsNullable;
|
|
1840
1869
|
dismissed_by: NullableCol<string>;
|
|
1841
1870
|
}
|
|
1842
|
-
/**
|
|
1871
|
+
/**
|
|
1872
|
+
* 0084: a notice for the super admins (platform inbox), until one of them dismisses it; 0173
|
|
1873
|
+
* added `push_auth_failed` (at most one open per plugin).
|
|
1874
|
+
*/
|
|
1843
1875
|
export interface PlatformNoticesTable {
|
|
1844
1876
|
id: string;
|
|
1845
|
-
kind: "ownership_transferred";
|
|
1877
|
+
kind: "ownership_transferred" | "push_auth_failed";
|
|
1846
1878
|
detail: Json<Record<string, unknown>>;
|
|
1847
1879
|
created_at: Ts;
|
|
1848
1880
|
dismissed_at: TsNullable;
|
package/dist/errors.d.ts
CHANGED
|
@@ -613,6 +613,13 @@ export declare const ERROR_CODES: {
|
|
|
613
613
|
/** An extension's `ctx.models.embed` call was denied by a `model.request` policy hook. */
|
|
614
614
|
readonly "model.hook_denied": 403;
|
|
615
615
|
readonly "eval.result_not_found": 404;
|
|
616
|
+
/**
|
|
617
|
+
* A push registration names a provider that is not loaded or whose credentials do not cover
|
|
618
|
+
* its app id (mobile app spec §9.2).
|
|
619
|
+
*/
|
|
620
|
+
readonly "push.provider_unavailable": 422;
|
|
621
|
+
/** No push registration of that id belongs to the caller. */
|
|
622
|
+
readonly "push.registration_not_found": 404;
|
|
616
623
|
};
|
|
617
624
|
export type ErrorCode = keyof typeof ERROR_CODES;
|
|
618
625
|
/** 业务代码抛出的 API 错误;由 HTTP 层的错误过滤器转成错误信封。 */
|
package/dist/errors.js
CHANGED
|
@@ -613,6 +613,13 @@ export const ERROR_CODES = {
|
|
|
613
613
|
/** An extension's `ctx.models.embed` call was denied by a `model.request` policy hook. */
|
|
614
614
|
"model.hook_denied": 403,
|
|
615
615
|
"eval.result_not_found": 404,
|
|
616
|
+
/**
|
|
617
|
+
* A push registration names a provider that is not loaded or whose credentials do not cover
|
|
618
|
+
* its app id (mobile app spec §9.2).
|
|
619
|
+
*/
|
|
620
|
+
"push.provider_unavailable": 422,
|
|
621
|
+
/** No push registration of that id belongs to the caller. */
|
|
622
|
+
"push.registration_not_found": 404,
|
|
616
623
|
};
|
|
617
624
|
/** 业务代码抛出的 API 错误;由 HTTP 层的错误过滤器转成错误信封。 */
|
|
618
625
|
export class ApiError extends Error {
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { core } from "zod";
|
|
2
|
+
/** 键排序后的 JSON(对象键顺序不影响结果);undefined 字段与 JSON.stringify 一样省略。 */
|
|
3
|
+
export declare const canonicalJson: (v: unknown) => string;
|
|
2
4
|
/**
|
|
3
5
|
* 插件部署配置(校验后)中非密钥部分的摘要:先把 schema 里所有 secret 叶子(`configFields` 可达路径,
|
|
4
6
|
* 加载时 `assertSecretsReachable` 已保证密钥都在这些路径上)换成固定占位值,再取 sha256(键排序 JSON) 前 16 位十六进制。
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { configFields, getPath, setPath } from "../config/fields.js";
|
|
3
3
|
/** 键排序后的 JSON(对象键顺序不影响结果);undefined 字段与 JSON.stringify 一样省略。 */
|
|
4
|
-
const canonicalJson = (v) => {
|
|
4
|
+
export const canonicalJson = (v) => {
|
|
5
5
|
if (Array.isArray(v))
|
|
6
6
|
return `[${v.map((x) => (x === undefined ? "null" : canonicalJson(x))).join(",")}]`;
|
|
7
7
|
if (v !== null && typeof v === "object") {
|
|
@@ -16,7 +16,11 @@ export type UnresolvedReason =
|
|
|
16
16
|
| "no_connector"
|
|
17
17
|
/** Rendered for the platform (the super admin's preview), not for an org. */
|
|
18
18
|
| "no_org";
|
|
19
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* The org action each audience of a place needs besides `catalog.read` (spec §9.1).
|
|
21
|
+
* `extension-deployment` has none: its guides are the super admin's (the admin extension routes),
|
|
22
|
+
* so an org route refuses them (`forbidden`).
|
|
23
|
+
*/
|
|
20
24
|
export declare const PLACE_ACTIONS: Readonly<Record<SetupGuidePlace, Readonly<Partial<Record<SetupGuideAudience, OrgAction>>>>>;
|
|
21
25
|
/** The object a guide is rendered for. */
|
|
22
26
|
export interface GuideTarget {
|
|
@@ -8,10 +8,15 @@ import { SETUP_GUIDE_PLACE_INFO, } from "@capybara-hq/plugin-sdk";
|
|
|
8
8
|
import { webhookBase, webhookUrlOf } from "../channels/webhook-url.js";
|
|
9
9
|
import { ApiError } from "../errors.js";
|
|
10
10
|
import { OAUTH_CALLBACK_PATH } from "../tools/oauth/flow-paths.js";
|
|
11
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* The org action each audience of a place needs besides `catalog.read` (spec §9.1).
|
|
13
|
+
* `extension-deployment` has none: its guides are the super admin's (the admin extension routes),
|
|
14
|
+
* so an org route refuses them (`forbidden`).
|
|
15
|
+
*/
|
|
12
16
|
export const PLACE_ACTIONS = {
|
|
13
17
|
"channel-connection": { admin: "channels.manage" },
|
|
14
18
|
"connector-template": { admin: "connectors.manage", member: "connectors.use" },
|
|
19
|
+
"extension-deployment": {},
|
|
15
20
|
};
|
|
16
21
|
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
17
22
|
const invalidQuery = (path, message) => new ApiError("validation_failed", "Request validation failed", [{ path, message }]);
|
|
@@ -19,6 +24,7 @@ const invalidQuery = (path, message) => new ApiError("validation_failed", "Reque
|
|
|
19
24
|
const TARGET_PARAMS = {
|
|
20
25
|
"channel-connection": ["connectionId", "name"],
|
|
21
26
|
"connector-template": ["connectorId"],
|
|
27
|
+
"extension-deployment": [],
|
|
22
28
|
};
|
|
23
29
|
/**
|
|
24
30
|
* The variable values of a place for one rendering (spec §6.3): the common ones, then the place's
|
|
@@ -64,7 +70,7 @@ export async function resolvePlace(ctx) {
|
|
|
64
70
|
storedMode = connection.inbound_mode;
|
|
65
71
|
}
|
|
66
72
|
}
|
|
67
|
-
else {
|
|
73
|
+
else if (place === "connector-template") {
|
|
68
74
|
const connector = ctx.query.connectorId === undefined
|
|
69
75
|
? undefined
|
|
70
76
|
: await liveConnector(ctx, ctx.query.connectorId);
|
|
@@ -77,6 +83,7 @@ export async function resolvePlace(ctx) {
|
|
|
77
83
|
if (connector !== undefined)
|
|
78
84
|
target = { kind: "connector", id: connector.id };
|
|
79
85
|
}
|
|
86
|
+
// `extension-deployment`: the common variables only, no org and no target (the deployment)
|
|
80
87
|
reasons.publicUrl = "public_url";
|
|
81
88
|
reasons.signInCallbackUrl = "public_url";
|
|
82
89
|
reasons.oauthCallbackUrl = "public_url";
|
|
@@ -30,7 +30,7 @@ export interface PermissionGroup {
|
|
|
30
30
|
* ({@link SENSITIVE_EXTENSION_POINTS}; the code is the extension point name without `@<major>`, with
|
|
31
31
|
* `-` replaced by `_`).
|
|
32
32
|
*/
|
|
33
|
-
export type SensitiveReason = "secrets" | "public_routes" | "embed_routes" | "tools" | "hooks" | "ui_embed" | "client_code" | "ui_component" | "channel" | "directory" | "identity_source" | "sandbox" | "object_store" | "context" | "migration_warnings";
|
|
33
|
+
export type SensitiveReason = "secrets" | "public_routes" | "embed_routes" | "tools" | "hooks" | "ui_embed" | "client_code" | "ui_component" | "channel" | "directory" | "identity_source" | "sandbox" | "object_store" | "context" | "push_provider" | "migration_warnings";
|
|
34
34
|
/** 权限清单里的一项(分组里的一项,或 `added` 里的一个权限键)。 */
|
|
35
35
|
export interface PermissionItem {
|
|
36
36
|
value: string;
|
|
@@ -44,9 +44,11 @@ export interface PermissionItem {
|
|
|
44
44
|
* receives the org's IM conversations (Ruling A33), `directory@1` can add people to orgs (creating
|
|
45
45
|
* their accounts and identities), `identity-source@1` decides who can sign in as which account;
|
|
46
46
|
* `context@1` adds text to the model's context in conversations of orgs that enable it (memory
|
|
47
|
-
* plugin spec §6.1)
|
|
48
|
-
*
|
|
49
|
-
* of
|
|
47
|
+
* plugin spec §6.1); `push-provider@1` receives the title and in-app path of every push
|
|
48
|
+
* notification and the device tokens it delivers to (mobile app spec §9). A plugin providing any
|
|
49
|
+
* of them has its "provides" group marked sensitive and `sensitive` true in the admin plugin
|
|
50
|
+
* list, for the super admin to approve. Display only: the keys of the permission snapshot do not
|
|
51
|
+
* change.
|
|
50
52
|
*/
|
|
51
53
|
export declare const SENSITIVE_EXTENSION_POINTS: readonly string[];
|
|
52
54
|
/**
|
|
@@ -23,9 +23,11 @@ export function reviewHash(set, warnings = []) {
|
|
|
23
23
|
* receives the org's IM conversations (Ruling A33), `directory@1` can add people to orgs (creating
|
|
24
24
|
* their accounts and identities), `identity-source@1` decides who can sign in as which account;
|
|
25
25
|
* `context@1` adds text to the model's context in conversations of orgs that enable it (memory
|
|
26
|
-
* plugin spec §6.1)
|
|
27
|
-
*
|
|
28
|
-
* of
|
|
26
|
+
* plugin spec §6.1); `push-provider@1` receives the title and in-app path of every push
|
|
27
|
+
* notification and the device tokens it delivers to (mobile app spec §9). A plugin providing any
|
|
28
|
+
* of them has its "provides" group marked sensitive and `sensitive` true in the admin plugin
|
|
29
|
+
* list, for the super admin to approve. Display only: the keys of the permission snapshot do not
|
|
30
|
+
* change.
|
|
29
31
|
*/
|
|
30
32
|
export const SENSITIVE_EXTENSION_POINTS = [
|
|
31
33
|
"channel@1",
|
|
@@ -34,6 +36,7 @@ export const SENSITIVE_EXTENSION_POINTS = [
|
|
|
34
36
|
"sandbox@2",
|
|
35
37
|
"object-store@1",
|
|
36
38
|
"context@1",
|
|
39
|
+
"push-provider@1",
|
|
37
40
|
];
|
|
38
41
|
/** The one item of the "client" group (client extensions spec §5.4). */
|
|
39
42
|
const CLIENT_ITEM = "client code";
|
|
@@ -275,6 +275,26 @@ export declare class PluginGuides {
|
|
|
275
275
|
renderForPlatform(itemId: string, guideId: string, q: {
|
|
276
276
|
locale?: "en" | "zh" | undefined;
|
|
277
277
|
}): Promise<RenderedSetupGuide>;
|
|
278
|
+
/**
|
|
279
|
+
* The `extension-deployment` guides of an extension, rendered for the platform (the super
|
|
280
|
+
* admin's extension page, `GET /admin/extensions/:name/guides`): the guides of that place in the
|
|
281
|
+
* latest version of the catalog item of the same name, admin audience, no org and no target.
|
|
282
|
+
* None when the extension has no catalog item; a guide that cannot be rendered is left out and
|
|
283
|
+
* logged.
|
|
284
|
+
*/
|
|
285
|
+
deploymentGuides(plugin: string, q: {
|
|
286
|
+
locale?: "en" | "zh" | undefined;
|
|
287
|
+
}): Promise<RenderedSetupGuide[]>;
|
|
288
|
+
/**
|
|
289
|
+
* One `extension-deployment` guide of an extension rendered for the platform (the deployment
|
|
290
|
+
* checks' guide). 404 `catalog.guide_not_found` when the extension's catalog item has no guide
|
|
291
|
+
* of that place with that id.
|
|
292
|
+
*/
|
|
293
|
+
renderForDeployment(plugin: string, guideId: string, q: {
|
|
294
|
+
locale?: "en" | "zh" | undefined;
|
|
295
|
+
}): Promise<RenderedSetupGuide>;
|
|
296
|
+
/** A guide rendered without an org: the admin audience, no target, `orgName` unresolved. */
|
|
297
|
+
private renderPlatformDoc;
|
|
278
298
|
/** The audience asked for, after checking `mode` and `audience` against the place. */
|
|
279
299
|
private checkQuery;
|
|
280
300
|
/** The rendered guide: the mode picked, the document rendered, the hash and the reasons. */
|
|
@@ -478,7 +478,55 @@ let PluginGuides = PluginGuides_1 = class PluginGuides {
|
|
|
478
478
|
const guide = guidesOf(row.manifest).guides.find((g) => g.id === guideId);
|
|
479
479
|
if (!guide)
|
|
480
480
|
throw guideNotFound();
|
|
481
|
-
|
|
481
|
+
return this.renderPlatformDoc(row, guide, q.locale ?? "en");
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* The `extension-deployment` guides of an extension, rendered for the platform (the super
|
|
485
|
+
* admin's extension page, `GET /admin/extensions/:name/guides`): the guides of that place in the
|
|
486
|
+
* latest version of the catalog item of the same name, admin audience, no org and no target.
|
|
487
|
+
* None when the extension has no catalog item; a guide that cannot be rendered is left out and
|
|
488
|
+
* logged.
|
|
489
|
+
*/
|
|
490
|
+
async deploymentGuides(plugin, q) {
|
|
491
|
+
const [row] = await this.latest("name", [plugin]);
|
|
492
|
+
if (!row)
|
|
493
|
+
return [];
|
|
494
|
+
this.warnSkipped(row);
|
|
495
|
+
const out = [];
|
|
496
|
+
for (const guide of guidesOf(row.manifest).guides) {
|
|
497
|
+
if (guide.place !== "extension-deployment")
|
|
498
|
+
continue;
|
|
499
|
+
try {
|
|
500
|
+
out.push(await this.renderPlatformDoc(row, guide, q.locale ?? "en"));
|
|
501
|
+
}
|
|
502
|
+
catch (err) {
|
|
503
|
+
if (!(err instanceof ApiError))
|
|
504
|
+
throw err;
|
|
505
|
+
this.log.warn("setup guide left out of the list", {
|
|
506
|
+
plugin,
|
|
507
|
+
guideId: guide.id,
|
|
508
|
+
code: err.code,
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
return out;
|
|
513
|
+
}
|
|
514
|
+
/**
|
|
515
|
+
* One `extension-deployment` guide of an extension rendered for the platform (the deployment
|
|
516
|
+
* checks' guide). 404 `catalog.guide_not_found` when the extension's catalog item has no guide
|
|
517
|
+
* of that place with that id.
|
|
518
|
+
*/
|
|
519
|
+
async renderForDeployment(plugin, guideId, q) {
|
|
520
|
+
const [row] = await this.latest("name", [plugin]);
|
|
521
|
+
const guide = row &&
|
|
522
|
+
guidesOf(row.manifest).guides.find((g) => g.id === guideId && g.place === "extension-deployment");
|
|
523
|
+
if (!row || !guide)
|
|
524
|
+
throw guideNotFound();
|
|
525
|
+
return this.renderPlatformDoc(row, guide, q.locale ?? "en");
|
|
526
|
+
}
|
|
527
|
+
/** A guide rendered without an org: the admin audience, no target, `orgName` unresolved. */
|
|
528
|
+
async renderPlatformDoc(row, guide, locale) {
|
|
529
|
+
const docs = await this.documents(row, guide, locale);
|
|
482
530
|
const resolution = await resolvePlace({
|
|
483
531
|
db: this.db,
|
|
484
532
|
config: this.config.get(),
|
package/dist/http/api.module.js
CHANGED
|
@@ -76,6 +76,9 @@ import { OrgsModule } from "../orgs/orgs.module.js";
|
|
|
76
76
|
import { OrgSettingsController } from "../orgs/settings.controller.js";
|
|
77
77
|
import { PlatformModule } from "../platform/platform.module.js";
|
|
78
78
|
import { SealedRevealsController } from "../platform/sealed-reveals.controller.js";
|
|
79
|
+
import { PushHostModule } from "../push/provider-host.js";
|
|
80
|
+
import { PushController } from "../push/push.controller.js";
|
|
81
|
+
import { PushModule } from "../push/push.module.js";
|
|
79
82
|
import { RuntimeModule } from "../runtime/runtime.module.js";
|
|
80
83
|
import { ConversationStreamController } from "../runtime/stream.controller.js";
|
|
81
84
|
import { SchedulesController } from "../schedules/schedules.controller.js";
|
|
@@ -117,6 +120,7 @@ const CONTROLLERS = [
|
|
|
117
120
|
MetaController,
|
|
118
121
|
MeController,
|
|
119
122
|
AccountAvatarController,
|
|
123
|
+
PushController,
|
|
120
124
|
InitialPasswordsController,
|
|
121
125
|
// the invitation link an org admin's agent created, read once by its approver (web parity §7.2)
|
|
122
126
|
SealedRevealsController,
|
|
@@ -223,6 +227,9 @@ ApiModule = __decorate([
|
|
|
223
227
|
PlatformModule,
|
|
224
228
|
AdminModule,
|
|
225
229
|
ExtensionsModule,
|
|
230
|
+
PushHostModule,
|
|
231
|
+
// push registrations and preferences under /api/v1/me
|
|
232
|
+
PushModule,
|
|
226
233
|
CatalogModule,
|
|
227
234
|
// a plugin's suggested appearance (its own module: it writes through the org settings)
|
|
228
235
|
AppearanceModule,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
3
|
+
import { PushProviderHost } from "../push/provider-host.js";
|
|
3
4
|
import { PlatformIconService } from "../themes/platform-icon.service.js";
|
|
4
5
|
/** Pre-sign-in discovery document native clients and the PWA manifest read. */
|
|
5
6
|
export declare const MetaResponseSchema: z.ZodObject<{
|
|
@@ -19,6 +20,10 @@ export declare const MetaResponseSchema: z.ZodObject<{
|
|
|
19
20
|
features: z.ZodObject<{
|
|
20
21
|
localDevices: z.ZodBoolean;
|
|
21
22
|
appSignIn: z.ZodBoolean;
|
|
23
|
+
push: z.ZodArray<z.ZodObject<{
|
|
24
|
+
appId: z.ZodString;
|
|
25
|
+
providers: z.ZodArray<z.ZodString>;
|
|
26
|
+
}, z.core.$strip>>;
|
|
22
27
|
}, z.core.$strip>;
|
|
23
28
|
appRedirectUris: z.ZodArray<z.ZodString>;
|
|
24
29
|
}, z.core.$strip>;
|
|
@@ -27,7 +32,8 @@ export type MetaResponse = z.infer<typeof MetaResponseSchema>;
|
|
|
27
32
|
export declare class MetaController {
|
|
28
33
|
private readonly config;
|
|
29
34
|
private readonly icons;
|
|
30
|
-
|
|
35
|
+
private readonly push;
|
|
36
|
+
constructor(config: KernelConfigService, icons: PlatformIconService, push: PushProviderHost);
|
|
31
37
|
meta(): Promise<MetaResponse>;
|
|
32
38
|
/** A customised platform icon's versioned URL (the one the manifest uses); null for the default. */
|
|
33
39
|
private iconUrl;
|
|
@@ -12,6 +12,7 @@ import { Controller, Get, Header, Inject } from "@nestjs/common";
|
|
|
12
12
|
import { z } from "zod";
|
|
13
13
|
import { Public } from "../identity/principal.js";
|
|
14
14
|
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
15
|
+
import { PushProviderHost } from "../push/provider-host.js";
|
|
15
16
|
import { PlatformIconService } from "../themes/platform-icon.service.js";
|
|
16
17
|
/** Pre-sign-in discovery document native clients and the PWA manifest read. */
|
|
17
18
|
export const MetaResponseSchema = z.object({
|
|
@@ -25,7 +26,12 @@ export const MetaResponseSchema = z.object({
|
|
|
25
26
|
protocols: z.object({
|
|
26
27
|
device: z.object({ min: z.number().int(), max: z.number().int() }),
|
|
27
28
|
}),
|
|
28
|
-
features: z.object({
|
|
29
|
+
features: z.object({
|
|
30
|
+
localDevices: z.boolean(),
|
|
31
|
+
appSignIn: z.boolean(),
|
|
32
|
+
/** App ids a push provider covers with the providers that do; `[]` without `http.publicUrl`. */
|
|
33
|
+
push: z.array(z.object({ appId: z.string(), providers: z.array(z.string()) })),
|
|
34
|
+
}),
|
|
29
35
|
/** The redirect URIs app sign-in accepts (`auth.appRedirectUris`); [] while appSignIn is off. */
|
|
30
36
|
appRedirectUris: z.array(z.string()),
|
|
31
37
|
});
|
|
@@ -33,9 +39,11 @@ export const MetaResponseSchema = z.object({
|
|
|
33
39
|
let MetaController = class MetaController {
|
|
34
40
|
config;
|
|
35
41
|
icons;
|
|
36
|
-
|
|
42
|
+
push;
|
|
43
|
+
constructor(config, icons, push) {
|
|
37
44
|
this.config = config;
|
|
38
45
|
this.icons = icons;
|
|
46
|
+
this.push = push;
|
|
39
47
|
}
|
|
40
48
|
async meta() {
|
|
41
49
|
const config = this.config.get();
|
|
@@ -54,6 +62,8 @@ let MetaController = class MetaController {
|
|
|
54
62
|
localDevices: true,
|
|
55
63
|
// The authorize route answers app_auth.unavailable without http.publicUrl.
|
|
56
64
|
appSignIn,
|
|
65
|
+
// A push message carries the deployment origin, which needs http.publicUrl.
|
|
66
|
+
push: config.http.publicUrl ? this.push.coverage() : [],
|
|
57
67
|
},
|
|
58
68
|
// Not secret: an app that finds its own URI missing says so before opening the browser.
|
|
59
69
|
appRedirectUris: appSignIn ? [...config.auth.appRedirectUris] : [],
|
|
@@ -72,6 +82,7 @@ __decorate([
|
|
|
72
82
|
MetaController = __decorate([
|
|
73
83
|
Controller("api/v1/meta"),
|
|
74
84
|
__param(0, Inject(KernelConfigService)),
|
|
75
|
-
__param(1, Inject(PlatformIconService))
|
|
85
|
+
__param(1, Inject(PlatformIconService)),
|
|
86
|
+
__param(2, Inject(PushProviderHost))
|
|
76
87
|
], MetaController);
|
|
77
88
|
export { MetaController };
|
|
@@ -15,6 +15,7 @@ import { ApiError } from "../errors.js";
|
|
|
15
15
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
16
16
|
import { TransactionHost, withOrderedLocks } from "../infra/database/transaction-host.js";
|
|
17
17
|
import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
18
|
+
import { deletePushRegistrationsForSessions } from "../push/registration-cleanup.js";
|
|
18
19
|
import { PermissionCeilingWritesModule } from "../sandbox/permission-authority.module.js";
|
|
19
20
|
import { PermissionCeilingWrites } from "../sandbox/permission-ceiling-writes.js";
|
|
20
21
|
import { assertThemeOnForAccount } from "../themes/theme-state.js";
|
|
@@ -331,6 +332,8 @@ let AccountsService = class AccountsService {
|
|
|
331
332
|
.where("id", "!=", exceptSessionId)
|
|
332
333
|
.returning("id")
|
|
333
334
|
.execute();
|
|
335
|
+
// the other devices stop receiving push; the current session's registrations stay
|
|
336
|
+
await deletePushRegistrationsForSessions(this.db.db, sessions.map((r) => r.id));
|
|
334
337
|
await this.db
|
|
335
338
|
.updateTable("api_tokens")
|
|
336
339
|
.set({ revoked_at: sql `now()` })
|
|
@@ -628,6 +631,8 @@ let AccountsService = class AccountsService {
|
|
|
628
631
|
.where("revoked_at", "is", null)
|
|
629
632
|
.execute();
|
|
630
633
|
revokedSessionIds = sessions.map((r) => r.id);
|
|
634
|
+
// a registration follows its session (push plan decision 3): a disabled account loses all
|
|
635
|
+
await deletePushRegistrationsForSessions(this.db.db, revokedSessionIds);
|
|
631
636
|
}
|
|
632
637
|
return { account: toAccount(row), revokedSessionIds };
|
|
633
638
|
}
|
|
@@ -65,8 +65,15 @@ export declare class SessionService {
|
|
|
65
65
|
sessionIdFromAccess(accessToken: string): Promise<string | undefined>;
|
|
66
66
|
/** 按 refresh token 吊销其当前会话(供登出使用);无匹配则什么都不做。 */
|
|
67
67
|
revokeByRefresh(refreshToken: string): Promise<void>;
|
|
68
|
+
/** Revokes one session and deletes the push registrations it posted, then writes the marker. */
|
|
68
69
|
revoke(sessionId: string): Promise<void>;
|
|
70
|
+
private revokeIn;
|
|
71
|
+
/**
|
|
72
|
+
* Revokes the account's sessions (but `exceptSessionId`) and deletes their push registrations
|
|
73
|
+
* in one transaction, then writes the markers.
|
|
74
|
+
*/
|
|
69
75
|
revokeAllForAccount(accountId: string, exceptSessionId?: string): Promise<number>;
|
|
76
|
+
private revokeAllIn;
|
|
70
77
|
/**
|
|
71
78
|
* 给已在 PG 中吊销的会话写 Redis 吊销标记(快速路径);任一写入失败即抛出。
|
|
72
79
|
* 鉴权以 PG `revoked_at` 为准,调用方可以把这一步当作尽力而为。
|
|
@@ -18,6 +18,7 @@ import { KernelDb } from "../infra/database/kernel-db.js";
|
|
|
18
18
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
19
19
|
import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
20
20
|
import { KEYRING, REDIS } from "../infra/tokens.js";
|
|
21
|
+
import { deletePushRegistrationsForSessions } from "../push/registration-cleanup.js";
|
|
21
22
|
import { ACCOUNT_COLUMNS, toAccount } from "./accounts.js";
|
|
22
23
|
import { sha256Hex } from "./hash.js";
|
|
23
24
|
/** 旧 refresh token 在被轮换后多久内重放视为并发刷新(不吊销会话)。 */
|
|
@@ -218,16 +219,31 @@ let SessionService = class SessionService {
|
|
|
218
219
|
if (row)
|
|
219
220
|
await this.revoke(row.id);
|
|
220
221
|
}
|
|
222
|
+
/** Revokes one session and deletes the push registrations it posted, then writes the marker. */
|
|
221
223
|
async revoke(sessionId) {
|
|
224
|
+
await this.revokeIn(sessionId);
|
|
225
|
+
await this.redis.set(revokedKey(sessionId), "1", "EX", REVOKED_MARKER_TTL_SECONDS);
|
|
226
|
+
}
|
|
227
|
+
async revokeIn(sessionId) {
|
|
222
228
|
await this.db
|
|
223
229
|
.updateTable("sessions")
|
|
224
230
|
.set({ revoked_at: sql `now()` })
|
|
225
231
|
.where("id", "=", sessionId)
|
|
226
232
|
.where("revoked_at", "is", null)
|
|
227
233
|
.execute();
|
|
228
|
-
|
|
234
|
+
// a registration follows its session (push plan decision 3); the row is kept, so delete them
|
|
235
|
+
await deletePushRegistrationsForSessions(this.db.db, [sessionId]);
|
|
229
236
|
}
|
|
237
|
+
/**
|
|
238
|
+
* Revokes the account's sessions (but `exceptSessionId`) and deletes their push registrations
|
|
239
|
+
* in one transaction, then writes the markers.
|
|
240
|
+
*/
|
|
230
241
|
async revokeAllForAccount(accountId, exceptSessionId) {
|
|
242
|
+
const ids = await this.revokeAllIn(accountId, exceptSessionId);
|
|
243
|
+
await this.markRevoked(ids);
|
|
244
|
+
return ids.length;
|
|
245
|
+
}
|
|
246
|
+
async revokeAllIn(accountId, exceptSessionId) {
|
|
231
247
|
let q = this.db
|
|
232
248
|
.updateTable("sessions")
|
|
233
249
|
.set({ revoked_at: sql `now()` })
|
|
@@ -235,9 +251,9 @@ let SessionService = class SessionService {
|
|
|
235
251
|
.where("revoked_at", "is", null);
|
|
236
252
|
if (exceptSessionId !== undefined)
|
|
237
253
|
q = q.where("id", "!=", exceptSessionId);
|
|
238
|
-
const
|
|
239
|
-
await this.
|
|
240
|
-
return
|
|
254
|
+
const ids = (await q.returning("id").execute()).map((r) => r.id);
|
|
255
|
+
await deletePushRegistrationsForSessions(this.db.db, ids);
|
|
256
|
+
return ids;
|
|
241
257
|
}
|
|
242
258
|
/**
|
|
243
259
|
* 给已在 PG 中吊销的会话写 Redis 吊销标记(快速路径);任一写入失败即抛出。
|
|
@@ -351,6 +367,12 @@ let SessionService = class SessionService {
|
|
|
351
367
|
};
|
|
352
368
|
}
|
|
353
369
|
};
|
|
370
|
+
__decorate([
|
|
371
|
+
Transactional()
|
|
372
|
+
], SessionService.prototype, "revokeIn", null);
|
|
373
|
+
__decorate([
|
|
374
|
+
Transactional()
|
|
375
|
+
], SessionService.prototype, "revokeAllIn", null);
|
|
354
376
|
__decorate([
|
|
355
377
|
Transactional()
|
|
356
378
|
], SessionService.prototype, "switchIn", null);
|