@canonmsg/backend-contracts 6.3.0 → 7.0.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.
- package/dist/cjs/communication.js +35 -0
- package/dist/cjs/index.js +1 -0
- package/dist/communication.d.ts +91 -0
- package/dist/communication.js +31 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readCommunicationRule = readCommunicationRule;
|
|
4
|
+
exports.parseDirectConversationSelection = parseDirectConversationSelection;
|
|
5
|
+
/** Missing or invalid policy never widens access. */
|
|
6
|
+
function readCommunicationRule(value) {
|
|
7
|
+
if (value === 'open' || value === 'approval-required' || value === 'closed') {
|
|
8
|
+
return value;
|
|
9
|
+
}
|
|
10
|
+
// Existing owner-only records have the same outsider-facing meaning as
|
|
11
|
+
// closed; the agent owner bypass remains a separate server-side rule.
|
|
12
|
+
if (value === 'owner-only')
|
|
13
|
+
return 'closed';
|
|
14
|
+
return 'approval-required';
|
|
15
|
+
}
|
|
16
|
+
function parseDirectConversationSelection(value) {
|
|
17
|
+
if (value == null)
|
|
18
|
+
return { mode: 'latest_or_new' };
|
|
19
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
20
|
+
throw new Error('selection must be an object');
|
|
21
|
+
}
|
|
22
|
+
const record = value;
|
|
23
|
+
if (record.mode === 'latest_or_new' || record.mode === 'new') {
|
|
24
|
+
return { mode: record.mode };
|
|
25
|
+
}
|
|
26
|
+
if (record.mode === 'specific') {
|
|
27
|
+
const conversationId = typeof record.conversationId === 'string'
|
|
28
|
+
? record.conversationId.trim()
|
|
29
|
+
: '';
|
|
30
|
+
if (!conversationId)
|
|
31
|
+
throw new Error('selection.conversationId is required');
|
|
32
|
+
return { mode: 'specific', conversationId };
|
|
33
|
+
}
|
|
34
|
+
throw new Error('selection.mode is invalid');
|
|
35
|
+
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -29,6 +29,7 @@ __exportStar(require("./verbContract.js"), exports);
|
|
|
29
29
|
__exportStar(require("./verbSchemas.js"), exports);
|
|
30
30
|
__exportStar(require("./verbWire.js"), exports);
|
|
31
31
|
__exportStar(require("./accessPolicy.js"), exports);
|
|
32
|
+
__exportStar(require("./communication.js"), exports);
|
|
32
33
|
__exportStar(require("./apiErrors.js"), exports);
|
|
33
34
|
__exportStar(require("./firestoreValues.js"), exports);
|
|
34
35
|
__exportStar(require("./moderation.js"), exports);
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/** The deliberately small policy vocabulary for principal communication. */
|
|
2
|
+
export type CommunicationRule = 'open' | 'approval-required' | 'closed';
|
|
3
|
+
/** Missing or invalid policy never widens access. */
|
|
4
|
+
export declare function readCommunicationRule(value: unknown): CommunicationRule;
|
|
5
|
+
/** Canon conversation selection is principal-neutral; a conversation is a runtime session boundary. */
|
|
6
|
+
export type DirectConversationSelection = {
|
|
7
|
+
mode: 'latest_or_new';
|
|
8
|
+
} | {
|
|
9
|
+
mode: 'new';
|
|
10
|
+
} | {
|
|
11
|
+
mode: 'specific';
|
|
12
|
+
conversationId: string;
|
|
13
|
+
};
|
|
14
|
+
export type CommunicateInput = {
|
|
15
|
+
action: 'message_existing';
|
|
16
|
+
conversationId: string;
|
|
17
|
+
text: string;
|
|
18
|
+
messageId?: string;
|
|
19
|
+
} | {
|
|
20
|
+
action: 'start_direct';
|
|
21
|
+
principalId: string;
|
|
22
|
+
text: string;
|
|
23
|
+
selection?: DirectConversationSelection;
|
|
24
|
+
messageId?: string;
|
|
25
|
+
} | {
|
|
26
|
+
action: 'create_group';
|
|
27
|
+
name: string;
|
|
28
|
+
memberIds: string[];
|
|
29
|
+
} | {
|
|
30
|
+
action: 'forward_message';
|
|
31
|
+
sourceConversationId: string;
|
|
32
|
+
targetConversationId: string;
|
|
33
|
+
messageId: string;
|
|
34
|
+
text?: string;
|
|
35
|
+
};
|
|
36
|
+
export type CommunicateResult = {
|
|
37
|
+
status: 'messaged';
|
|
38
|
+
conversationId: string;
|
|
39
|
+
messageId: string;
|
|
40
|
+
created?: boolean;
|
|
41
|
+
reused?: boolean;
|
|
42
|
+
} | {
|
|
43
|
+
status: 'requested' | 'pending';
|
|
44
|
+
requestId: string;
|
|
45
|
+
} | {
|
|
46
|
+
status: 'created';
|
|
47
|
+
conversationId: string;
|
|
48
|
+
added: string[];
|
|
49
|
+
pending: Array<{
|
|
50
|
+
userId: string;
|
|
51
|
+
requestId: string;
|
|
52
|
+
requirements: {
|
|
53
|
+
policyApproval: boolean;
|
|
54
|
+
ownerSessionSetup: boolean;
|
|
55
|
+
};
|
|
56
|
+
}>;
|
|
57
|
+
skipped: Array<{
|
|
58
|
+
userId: string;
|
|
59
|
+
reason: string;
|
|
60
|
+
}>;
|
|
61
|
+
} | {
|
|
62
|
+
status: 'forwarded';
|
|
63
|
+
messageId: string;
|
|
64
|
+
targetConversationId: string;
|
|
65
|
+
} | {
|
|
66
|
+
status: 'blocked' | 'unavailable';
|
|
67
|
+
reason: string;
|
|
68
|
+
};
|
|
69
|
+
/** Principal-neutral app/SDK command. Humans may open a composer before sending. */
|
|
70
|
+
export interface StartDirectInput {
|
|
71
|
+
targetUserId: string;
|
|
72
|
+
opener?: {
|
|
73
|
+
text: string;
|
|
74
|
+
messageId?: string;
|
|
75
|
+
} | null;
|
|
76
|
+
selection?: DirectConversationSelection;
|
|
77
|
+
}
|
|
78
|
+
export type StartDirectResult = {
|
|
79
|
+
status: 'opened' | 'messaged';
|
|
80
|
+
conversationId: string;
|
|
81
|
+
messageId?: string;
|
|
82
|
+
created?: boolean;
|
|
83
|
+
reused?: boolean;
|
|
84
|
+
} | {
|
|
85
|
+
status: 'requested' | 'pending';
|
|
86
|
+
requestId: string;
|
|
87
|
+
} | {
|
|
88
|
+
status: 'blocked' | 'unavailable';
|
|
89
|
+
reason: string;
|
|
90
|
+
};
|
|
91
|
+
export declare function parseDirectConversationSelection(value: unknown): DirectConversationSelection;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** Missing or invalid policy never widens access. */
|
|
2
|
+
export function readCommunicationRule(value) {
|
|
3
|
+
if (value === 'open' || value === 'approval-required' || value === 'closed') {
|
|
4
|
+
return value;
|
|
5
|
+
}
|
|
6
|
+
// Existing owner-only records have the same outsider-facing meaning as
|
|
7
|
+
// closed; the agent owner bypass remains a separate server-side rule.
|
|
8
|
+
if (value === 'owner-only')
|
|
9
|
+
return 'closed';
|
|
10
|
+
return 'approval-required';
|
|
11
|
+
}
|
|
12
|
+
export function parseDirectConversationSelection(value) {
|
|
13
|
+
if (value == null)
|
|
14
|
+
return { mode: 'latest_or_new' };
|
|
15
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
16
|
+
throw new Error('selection must be an object');
|
|
17
|
+
}
|
|
18
|
+
const record = value;
|
|
19
|
+
if (record.mode === 'latest_or_new' || record.mode === 'new') {
|
|
20
|
+
return { mode: record.mode };
|
|
21
|
+
}
|
|
22
|
+
if (record.mode === 'specific') {
|
|
23
|
+
const conversationId = typeof record.conversationId === 'string'
|
|
24
|
+
? record.conversationId.trim()
|
|
25
|
+
: '';
|
|
26
|
+
if (!conversationId)
|
|
27
|
+
throw new Error('selection.conversationId is required');
|
|
28
|
+
return { mode: 'specific', conversationId };
|
|
29
|
+
}
|
|
30
|
+
throw new Error('selection.mode is invalid');
|
|
31
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export * from './verbContract.js';
|
|
|
13
13
|
export * from './verbSchemas.js';
|
|
14
14
|
export * from './verbWire.js';
|
|
15
15
|
export * from './accessPolicy.js';
|
|
16
|
+
export * from './communication.js';
|
|
16
17
|
export * from './apiErrors.js';
|
|
17
18
|
export * from './firestoreValues.js';
|
|
18
19
|
export * from './moderation.js';
|
package/dist/index.js
CHANGED
|
@@ -13,6 +13,7 @@ export * from './verbContract.js';
|
|
|
13
13
|
export * from './verbSchemas.js';
|
|
14
14
|
export * from './verbWire.js';
|
|
15
15
|
export * from './accessPolicy.js';
|
|
16
|
+
export * from './communication.js';
|
|
16
17
|
export * from './apiErrors.js';
|
|
17
18
|
export * from './firestoreValues.js';
|
|
18
19
|
export * from './moderation.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@canonmsg/backend-contracts",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0",
|
|
4
4
|
"description": "Canon backend contract helpers shared by Functions and stream-service",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/cjs/index.js",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"access": "public"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@canonmsg/rich-cards": "^0.10.
|
|
46
|
+
"@canonmsg/rich-cards": "^0.10.3",
|
|
47
47
|
"@types/node": "^22.0.0",
|
|
48
48
|
"ajv": "^8.20.0",
|
|
49
49
|
"typescript": "~5.7.0",
|