@ixo/action-protocol 0.0.0-stage → 0.4.1

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.
@@ -0,0 +1,170 @@
1
+ const string = (minLength = 1, maxLength = 200) => ({
2
+ type: "string",
3
+ minLength,
4
+ maxLength,
5
+ });
6
+ const enumeration = (...values) => ({ enum: values });
7
+ const nullable = (schema) => ({ anyOf: [schema, { type: "null" }] });
8
+ const object = (properties) => ({
9
+ type: "object",
10
+ properties,
11
+ required: Object.keys(properties),
12
+ additionalProperties: false,
13
+ });
14
+ const fields = object({
15
+ id: { ...string(1, 40), pattern: "^[a-z][a-z0-9_]{0,39}$" },
16
+ label: string(1, 120),
17
+ type: enumeration("text", "email", "tel", "textarea"),
18
+ required: { type: "boolean" },
19
+ value: string(0, 1000),
20
+ source: enumeration("user", "record", "suggestion"),
21
+ });
22
+ const scopes = {
23
+ type: "array",
24
+ items: string(1, 300),
25
+ maxItems: 30,
26
+ uniqueItems: true,
27
+ };
28
+ const instant = {
29
+ ...string(20, 40),
30
+ pattern:
31
+ "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d{1,3})?(?:Z|[+-]\\d{2}:\\d{2})$",
32
+ };
33
+ const hex = { ...string(64, 64), pattern: "^[a-f0-9]{64}$" };
34
+ // One ASCII mailbox only; no display names, address lists or header characters.
35
+ const mailbox = {
36
+ ...string(3, 254),
37
+ pattern:
38
+ "^[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?\\.)+[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?$",
39
+ };
40
+ const registry = {
41
+ "form.submit.v1": {
42
+ formId: string(1, 120),
43
+ destination: string(1, 200),
44
+ fields: { type: "array", items: fields, minItems: 1, maxItems: 20 },
45
+ declaration: nullable(string(1, 120)),
46
+ },
47
+ "ixo.bank.send.v1": {
48
+ chainId: string(1, 100),
49
+ network: enumeration("ixo mainnet", "ixo testnet", "ixo devnet"),
50
+ fromAddress: string(),
51
+ toAddress: string(),
52
+ amountBaseUnits: { ...string(), pattern: "^[1-9][0-9]*$" },
53
+ denom: { const: "uixo" },
54
+ feeBaseUnits: { ...string(), pattern: "^(0|[1-9][0-9]*)$" },
55
+ memo: string(0, 256),
56
+ },
57
+ "resource.read.v1": {
58
+ resourceId: string(),
59
+ ownerDid: string(),
60
+ url: string(1, 2000),
61
+ version: string(),
62
+ contentDigest: hex,
63
+ },
64
+ "statement.sign.v1": {
65
+ statement: string(0, 8192),
66
+ purpose: string(1, 120),
67
+ audienceId: string(1, 100),
68
+ },
69
+ "gmail.connect.v1": {
70
+ purpose: string(1, 120),
71
+ connectionId: nullable(string(1, 100)),
72
+ accountLabel: nullable(mailbox),
73
+ scopes,
74
+ },
75
+ "gmail.disconnect.v1": {
76
+ connectionId: string(1, 100),
77
+ accountLabel: mailbox,
78
+ },
79
+ "gmail.message.send.v1": {
80
+ connectionId: string(1, 100),
81
+ accountLabel: mailbox,
82
+ to: mailbox,
83
+ subject: {
84
+ ...string(1, 200),
85
+ pattern: "^[^\\u0000-\\u001f\\u007f-\\u009f]+$(?![\\s\\S])",
86
+ },
87
+ body: { ...string(1, 8192), pattern: "^[^\\r\\u0000]+$(?![\\s\\S])" },
88
+ },
89
+ "calendar.connect.v1": {
90
+ purpose: string(1, 120),
91
+ connectionId: nullable(string(1, 100)),
92
+ accountLabel: nullable(string()),
93
+ scopes,
94
+ },
95
+ "calendar.disconnect.v1": {
96
+ connectionId: string(1, 100),
97
+ accountLabel: string(),
98
+ },
99
+ "calendar.event.create.v1": {
100
+ connectionId: string(1, 100),
101
+ accountLabel: string(),
102
+ calendarId: { const: "primary" },
103
+ title: string(1, 120),
104
+ description: string(0, 2000),
105
+ startsAt: instant,
106
+ endsAt: instant,
107
+ timeZone: string(1, 100),
108
+ },
109
+ "vfs.access.request.v1": {
110
+ targetId: string(1, 100),
111
+ title: string(),
112
+ ability: { const: "read" },
113
+ purpose: string(1, 500),
114
+ },
115
+ "vfs.text.save.v1": {
116
+ filename: {
117
+ ...string(5, 80),
118
+ pattern: "^[A-Za-z0-9][A-Za-z0-9 _.-]*\\.txt$",
119
+ },
120
+ text: string(0, 8192),
121
+ },
122
+ };
123
+ export const operationKinds = Object.freeze(Object.keys(registry));
124
+ export const operationJsonSchema = Object.freeze({
125
+ $schema: "https://json-schema.org/draft/2020-12/schema",
126
+ oneOf: Object.entries(registry).map(([kind, properties]) =>
127
+ object({ kind: { const: kind }, ...properties }),
128
+ ),
129
+ });
130
+ function matches(value, schema) {
131
+ if (schema.anyOf) return schema.anyOf.some((s) => matches(value, s));
132
+ if ("const" in schema) return value === schema.const;
133
+ if (schema.enum) return schema.enum.includes(value);
134
+ if (schema.type === "null") return value === null;
135
+ if (schema.type === "boolean") return typeof value === "boolean";
136
+ if (schema.type === "string")
137
+ return (
138
+ typeof value === "string" &&
139
+ value.length >= schema.minLength &&
140
+ value.length <= schema.maxLength &&
141
+ (!schema.pattern || new RegExp(schema.pattern).test(value))
142
+ );
143
+ if (schema.type === "array")
144
+ return (
145
+ Array.isArray(value) &&
146
+ value.length >= (schema.minItems ?? 0) &&
147
+ value.length <= schema.maxItems &&
148
+ (!schema.uniqueItems || new Set(value).size === value.length) &&
149
+ value.every((v) => matches(v, schema.items))
150
+ );
151
+ if (schema.type === "object")
152
+ return (
153
+ value !== null &&
154
+ typeof value === "object" &&
155
+ !Array.isArray(value) &&
156
+ Object.keys(value).every((k) => k in schema.properties) &&
157
+ schema.required.every(
158
+ (k) =>
159
+ Object.hasOwn(value, k) && matches(value[k], schema.properties[k]),
160
+ )
161
+ );
162
+ return false;
163
+ }
164
+ export function validateOperationSchema(value) {
165
+ const schema = operationJsonSchema.oneOf.find(
166
+ (s) => s.properties.kind.const === value.kind,
167
+ );
168
+ if (!schema || !matches(value, schema))
169
+ throw new TypeError("Invalid operation");
170
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.