@geonosis/document 0.9.3 → 0.10.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/CHANGELOG.md +53 -0
- package/README.md +78 -13
- package/dist/core/actor.d.cts +0 -1
- package/dist/core/actor.d.ts +0 -1
- package/dist/core/body-version.d.cts +0 -9
- package/dist/core/body-version.d.ts +0 -9
- package/dist/core/canonical.cjs +2 -3
- package/dist/core/canonical.d.cts +0 -4
- package/dist/core/canonical.d.ts +0 -4
- package/dist/core/canonical.js +2 -3
- package/dist/core/document.cjs +28 -25
- package/dist/core/document.d.cts +3 -22
- package/dist/core/document.d.ts +3 -22
- package/dist/core/document.js +28 -25
- package/dist/core/entities.d.cts +0 -19
- package/dist/core/entities.d.ts +0 -19
- package/dist/core/naming.d.cts +0 -5
- package/dist/core/naming.d.ts +0 -5
- package/dist/core/numbering.d.cts +0 -4
- package/dist/core/numbering.d.ts +0 -4
- package/dist/core/ports.d.cts +0 -6
- package/dist/core/ports.d.ts +0 -6
- package/dist/core/schema.cjs +44 -76
- package/dist/core/schema.d.cts +1 -13
- package/dist/core/schema.d.ts +1 -13
- package/dist/core/schema.js +44 -76
- package/dist/core/status.d.cts +0 -1
- package/dist/core/status.d.ts +0 -1
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -0
- package/dist/store/ddl.cjs +35 -38
- package/dist/store/ddl.d.cts +6 -6
- package/dist/store/ddl.d.ts +6 -6
- package/dist/store/ddl.js +37 -39
- package/dist/store/hash.d.cts +0 -1
- package/dist/store/hash.d.ts +0 -1
- package/dist/store/number-for.cjs +52 -0
- package/dist/store/number-for.d.cts +11 -0
- package/dist/store/number-for.d.ts +11 -0
- package/dist/store/number-for.js +12 -0
- package/dist/store/store.cjs +188 -162
- package/dist/store/store.d.cts +57 -16
- package/dist/store/store.d.ts +57 -16
- package/dist/store/store.js +190 -163
- package/dist/store.cjs +2 -0
- package/dist/store.d.cts +3 -2
- package/dist/store.d.ts +3 -2
- package/dist/store.js +2 -0
- package/dist/surface/table.cjs +129 -66
- package/dist/surface/table.d.cts +20 -28
- package/dist/surface/table.d.ts +20 -28
- package/dist/surface/table.js +132 -66
- package/dist/workflows/bindings.cjs +48 -0
- package/dist/workflows/bindings.d.cts +15 -0
- package/dist/workflows/bindings.d.ts +15 -0
- package/dist/workflows/bindings.js +10 -0
- package/dist/workflows/document-workflows.cjs +29 -40
- package/dist/workflows/document-workflows.d.cts +0 -12
- package/dist/workflows/document-workflows.d.ts +0 -12
- package/dist/workflows/document-workflows.js +29 -40
- package/dist/workflows/effects.d.cts +0 -12
- package/dist/workflows/effects.d.ts +0 -12
- package/dist/workflows/ports.d.cts +0 -17
- package/dist/workflows/ports.d.ts +0 -17
- package/dist/workflows/refusals.cjs +30 -0
- package/dist/workflows/refusals.d.cts +37 -9
- package/dist/workflows/refusals.d.ts +37 -9
- package/dist/workflows/refusals.js +30 -0
- package/dist/workflows/shared.cjs +93 -0
- package/dist/workflows/shared.d.cts +28 -0
- package/dist/workflows/shared.d.ts +28 -0
- package/dist/workflows/shared.js +60 -0
- package/dist/workflows.cjs +16 -1
- package/dist/workflows.d.cts +3 -1
- package/dist/workflows.d.ts +3 -1
- package/dist/workflows.js +31 -1
- package/package.json +4 -4
|
@@ -26,7 +26,8 @@ var defaultActor = (ctx, workflowName) => {
|
|
|
26
26
|
};
|
|
27
27
|
var documentWorkflows = (entity, options) => {
|
|
28
28
|
const { effects, ports } = options;
|
|
29
|
-
const
|
|
29
|
+
const entityName = entity.name;
|
|
30
|
+
const name = entityName;
|
|
30
31
|
const article = withArticle(entity.noun);
|
|
31
32
|
const noun = capitalised(entity.noun);
|
|
32
33
|
const actorOf = ports.actor ?? defaultActor;
|
|
@@ -53,10 +54,10 @@ var documentWorkflows = (entity, options) => {
|
|
|
53
54
|
return written;
|
|
54
55
|
};
|
|
55
56
|
const stored = async (ctx, at) => {
|
|
56
|
-
const found = await ports.door(ctx,
|
|
57
|
+
const found = await ports.door(ctx, entityName).get({ ref: at.ref });
|
|
57
58
|
if (!found) {
|
|
58
59
|
throw new DocumentNotFound({
|
|
59
|
-
entity:
|
|
60
|
+
entity: entityName,
|
|
60
61
|
message: `no ${entity.noun} is stored as ${at.ref}`,
|
|
61
62
|
ref: at.ref
|
|
62
63
|
});
|
|
@@ -64,7 +65,7 @@ var documentWorkflows = (entity, options) => {
|
|
|
64
65
|
return found;
|
|
65
66
|
};
|
|
66
67
|
const refuseTaken = async (ctx, at) => {
|
|
67
|
-
const owner = at.entity ??
|
|
68
|
+
const owner = at.entity ?? entityName;
|
|
68
69
|
if (await ports.door(ctx, owner).get({ ref: at.ref })) {
|
|
69
70
|
throw new DocumentTaken({
|
|
70
71
|
entity: owner,
|
|
@@ -78,7 +79,7 @@ var documentWorkflows = (entity, options) => {
|
|
|
78
79
|
if (numbering.mode === "given") {
|
|
79
80
|
if (given === undefined) {
|
|
80
81
|
throw new NumberingRefused({
|
|
81
|
-
entity:
|
|
82
|
+
entity: entityName,
|
|
82
83
|
message: `${article} is numbered by whoever creates it`,
|
|
83
84
|
mode: "given"
|
|
84
85
|
});
|
|
@@ -88,14 +89,14 @@ var documentWorkflows = (entity, options) => {
|
|
|
88
89
|
}
|
|
89
90
|
if (given !== undefined) {
|
|
90
91
|
throw new NumberingRefused({
|
|
91
|
-
entity:
|
|
92
|
+
entity: entityName,
|
|
92
93
|
message: `${article} is numbered by the organisation`,
|
|
93
94
|
mode: "counter"
|
|
94
95
|
});
|
|
95
96
|
}
|
|
96
97
|
if (ports.counter === undefined) {
|
|
97
98
|
throw new NumberingRefused({
|
|
98
|
-
entity:
|
|
99
|
+
entity: entityName,
|
|
99
100
|
message: `${article} is numbered from a counter and this host declares no counter port`,
|
|
100
101
|
mode: "counter"
|
|
101
102
|
});
|
|
@@ -104,18 +105,24 @@ var documentWorkflows = (entity, options) => {
|
|
|
104
105
|
const { number: sequence } = await ports.counter(ctx, numbering.counter);
|
|
105
106
|
return { ref: numbering.format(series, sequence), minted: { sequence } };
|
|
106
107
|
};
|
|
107
|
-
const shareLink = createStep({ name: "create-share-link", noCompensation: true }, (input, ctx) => ports.link(ctx, { entity:
|
|
108
|
+
const shareLink = createStep({ name: "create-share-link", noCompensation: true }, (input, ctx) => ports.link(ctx, { entity: entityName, ...input }));
|
|
108
109
|
const sendMail = createStep({ name: "send-email", noCompensation: true }, async (input, ctx) => {
|
|
109
110
|
const sent = await ports.mail(ctx, input);
|
|
110
111
|
if (sent.isErr())
|
|
111
112
|
throw sent.error;
|
|
112
113
|
return { to: input.to };
|
|
113
114
|
});
|
|
115
|
+
const linkFor = (input) => shareLink({
|
|
116
|
+
ref: input.ref,
|
|
117
|
+
now: input.now,
|
|
118
|
+
...input.ttlDays === undefined ? {} : { ttlDays: input.ttlDays }
|
|
119
|
+
});
|
|
120
|
+
const linkShape = { now: positiveInt, ref: nonEmptyString, ttlDays: optional(positiveInt) };
|
|
114
121
|
const createName = `${name}.create`;
|
|
115
122
|
const create = createWorkflow(createName, async (input, ctx) => {
|
|
116
123
|
await guard(ctx);
|
|
117
124
|
const draft = await validate(entity.draft, await seed(ctx, {
|
|
118
|
-
entity:
|
|
125
|
+
entity: entityName,
|
|
119
126
|
templateId: input.templateId,
|
|
120
127
|
input: input.body
|
|
121
128
|
}));
|
|
@@ -146,7 +153,7 @@ var documentWorkflows = (entity, options) => {
|
|
|
146
153
|
const from = entity.statusOf(current.body);
|
|
147
154
|
if (!canTransition(entity.statuses, from, input.to)) {
|
|
148
155
|
throw new TransitionRefused({
|
|
149
|
-
entity:
|
|
156
|
+
entity: entityName,
|
|
150
157
|
from,
|
|
151
158
|
message: `${article} cannot go from ${from} to ${input.to}`,
|
|
152
159
|
ref: input.ref,
|
|
@@ -168,20 +175,15 @@ var documentWorkflows = (entity, options) => {
|
|
|
168
175
|
const remove = createWorkflow(deleteName, async (input, ctx) => {
|
|
169
176
|
if (!entity.removable) {
|
|
170
177
|
throw new DocumentNotRemovable({
|
|
171
|
-
entity:
|
|
178
|
+
entity: entityName,
|
|
172
179
|
message: `deleting is not something ${article} does`
|
|
173
180
|
});
|
|
174
181
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
message: `no ${entity.noun} is stored as ${input.ref}`,
|
|
181
|
-
ref: input.ref
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
await door.retire({ actor: actorOf(ctx, deleteName), ref: input.ref });
|
|
182
|
+
await stored(ctx, input);
|
|
183
|
+
await ports.door(ctx, entityName).retire({
|
|
184
|
+
actor: actorOf(ctx, deleteName),
|
|
185
|
+
ref: input.ref
|
|
186
|
+
});
|
|
185
187
|
return { number: input.ref };
|
|
186
188
|
}, {
|
|
187
189
|
announce: (removed) => announce({ kind: "deleted", number: removed.number }),
|
|
@@ -190,11 +192,7 @@ var documentWorkflows = (entity, options) => {
|
|
|
190
192
|
const sendName = `${name}.send`;
|
|
191
193
|
const send = createWorkflow(sendName, async (input, ctx) => {
|
|
192
194
|
const current = await stored(ctx, input);
|
|
193
|
-
const link = await
|
|
194
|
-
ref: input.ref,
|
|
195
|
-
now: input.now,
|
|
196
|
-
...input.ttlDays === undefined ? {} : { ttlDays: input.ttlDays }
|
|
197
|
-
});
|
|
195
|
+
const link = await linkFor(input);
|
|
198
196
|
const marked = entity.onSent(current.body);
|
|
199
197
|
const written = marked === current.body ? { entity: name, number: input.ref, body: current.body } : await write(ctx, { entity: name, number: input.ref, body: marked }, sendName);
|
|
200
198
|
const words = mailWords(input.ref);
|
|
@@ -208,19 +206,14 @@ var documentWorkflows = (entity, options) => {
|
|
|
208
206
|
announce: ({ to, url, expiresAt, ...written }) => announce({ kind: "sent", written, to, url, expiresAt }),
|
|
209
207
|
execution: "durable",
|
|
210
208
|
idempotent: (input) => `${sendName}:${input.ref}:${input.to}`,
|
|
211
|
-
input: typed(objectOf({
|
|
212
|
-
now: positiveInt,
|
|
213
|
-
ref: nonEmptyString,
|
|
214
|
-
to: nonEmptyString,
|
|
215
|
-
ttlDays: optional(positiveInt)
|
|
216
|
-
}))
|
|
209
|
+
input: typed(objectOf({ ...linkShape, to: nonEmptyString }))
|
|
217
210
|
});
|
|
218
211
|
const convertName = `${name}.convert`;
|
|
219
212
|
const convert = createWorkflow(convertName, async (input, ctx) => {
|
|
220
213
|
const conversion = effects.conversion;
|
|
221
214
|
if (conversion === undefined) {
|
|
222
215
|
throw new ConversionRefused({
|
|
223
|
-
entity:
|
|
216
|
+
entity: entityName,
|
|
224
217
|
message: `converting is not something ${article} does`,
|
|
225
218
|
ref: input.ref
|
|
226
219
|
});
|
|
@@ -229,7 +222,7 @@ var documentWorkflows = (entity, options) => {
|
|
|
229
222
|
const refusal = conversion.refuse(source.body);
|
|
230
223
|
if (refusal !== null) {
|
|
231
224
|
throw new ConversionRefused({
|
|
232
|
-
entity:
|
|
225
|
+
entity: entityName,
|
|
233
226
|
message: `${input.ref} ${refusal}`,
|
|
234
227
|
ref: input.ref
|
|
235
228
|
});
|
|
@@ -264,15 +257,11 @@ var documentWorkflows = (entity, options) => {
|
|
|
264
257
|
});
|
|
265
258
|
const share = createWorkflow(`${name}.share`, async (input, ctx) => {
|
|
266
259
|
await stored(ctx, input);
|
|
267
|
-
const link = await
|
|
268
|
-
ref: input.ref,
|
|
269
|
-
now: input.now,
|
|
270
|
-
...input.ttlDays === undefined ? {} : { ttlDays: input.ttlDays }
|
|
271
|
-
});
|
|
260
|
+
const link = await linkFor(input);
|
|
272
261
|
return { number: input.ref, token: link.token, url: link.url, expiresAt: link.expiresAt };
|
|
273
262
|
}, {
|
|
274
263
|
announce: (link) => announce({ kind: "shared", number: link.number, url: link.url, expiresAt: link.expiresAt }),
|
|
275
|
-
input: typed(objectOf(
|
|
264
|
+
input: typed(objectOf(linkShape))
|
|
276
265
|
});
|
|
277
266
|
return { entity, create, save, setStatus, remove, send, convert, duplicate, share };
|
|
278
267
|
};
|
|
@@ -1,16 +1,10 @@
|
|
|
1
1
|
import type { Announcement } from '@geonosis/workflows';
|
|
2
2
|
import type { BodyOf, NameOf } from '../core/document.cjs';
|
|
3
|
-
/** What a write left behind: the entity, the number the document carries, and its body. */
|
|
4
3
|
export type Written<E> = {
|
|
5
4
|
entity: NameOf<E>;
|
|
6
5
|
number: string;
|
|
7
6
|
body: BodyOf<E>;
|
|
8
7
|
};
|
|
9
|
-
/**
|
|
10
|
-
* What a workflow did, as the entity is asked to announce it: one function per entity turns
|
|
11
|
-
* these into the product's own events — or into nothing, which is a decision too. `sent` and
|
|
12
|
-
* `shared` carry the link so a product that publishes a shared-link event can say so from either.
|
|
13
|
-
*/
|
|
14
8
|
export type DocumentFact<E> = {
|
|
15
9
|
kind: 'created';
|
|
16
10
|
written: Written<E>;
|
|
@@ -43,18 +37,12 @@ export type DocumentFact<E> = {
|
|
|
43
37
|
number: string;
|
|
44
38
|
to: string;
|
|
45
39
|
};
|
|
46
|
-
/** One entity's conversion into another: what refuses it, the target's body, how the source is marked. */
|
|
47
40
|
export type DocumentConversion<E, To> = {
|
|
48
41
|
to: To;
|
|
49
42
|
refuse: (body: BodyOf<E>) => string | null;
|
|
50
43
|
bodyFor: (body: BodyOf<E>, number: string) => BodyOf<To>;
|
|
51
44
|
markSource: (body: BodyOf<E>, number: string) => BodyOf<E>;
|
|
52
45
|
};
|
|
53
|
-
/**
|
|
54
|
-
* What an entity decides with a side effect. `announce` is the one decision every entity makes —
|
|
55
|
-
* the events are the product's, and the kit cannot guess their names. The rest default: no
|
|
56
|
-
* `beforeCreate`, no `conversion`, and mail words made of the entity's noun and the number.
|
|
57
|
-
*/
|
|
58
46
|
export type DocumentEffects<E, Ctx> = {
|
|
59
47
|
announce: (fact: DocumentFact<E>) => Announcement | readonly Announcement[] | null;
|
|
60
48
|
beforeCreate?: (ctx: Ctx, body: BodyOf<E>) => Promise<BodyOf<E>>;
|
|
@@ -1,16 +1,10 @@
|
|
|
1
1
|
import type { Announcement } from '@geonosis/workflows';
|
|
2
2
|
import type { BodyOf, NameOf } from '../core/document.js';
|
|
3
|
-
/** What a write left behind: the entity, the number the document carries, and its body. */
|
|
4
3
|
export type Written<E> = {
|
|
5
4
|
entity: NameOf<E>;
|
|
6
5
|
number: string;
|
|
7
6
|
body: BodyOf<E>;
|
|
8
7
|
};
|
|
9
|
-
/**
|
|
10
|
-
* What a workflow did, as the entity is asked to announce it: one function per entity turns
|
|
11
|
-
* these into the product's own events — or into nothing, which is a decision too. `sent` and
|
|
12
|
-
* `shared` carry the link so a product that publishes a shared-link event can say so from either.
|
|
13
|
-
*/
|
|
14
8
|
export type DocumentFact<E> = {
|
|
15
9
|
kind: 'created';
|
|
16
10
|
written: Written<E>;
|
|
@@ -43,18 +37,12 @@ export type DocumentFact<E> = {
|
|
|
43
37
|
number: string;
|
|
44
38
|
to: string;
|
|
45
39
|
};
|
|
46
|
-
/** One entity's conversion into another: what refuses it, the target's body, how the source is marked. */
|
|
47
40
|
export type DocumentConversion<E, To> = {
|
|
48
41
|
to: To;
|
|
49
42
|
refuse: (body: BodyOf<E>) => string | null;
|
|
50
43
|
bodyFor: (body: BodyOf<E>, number: string) => BodyOf<To>;
|
|
51
44
|
markSource: (body: BodyOf<E>, number: string) => BodyOf<E>;
|
|
52
45
|
};
|
|
53
|
-
/**
|
|
54
|
-
* What an entity decides with a side effect. `announce` is the one decision every entity makes —
|
|
55
|
-
* the events are the product's, and the kit cannot guess their names. The rest default: no
|
|
56
|
-
* `beforeCreate`, no `conversion`, and mail words made of the entity's noun and the number.
|
|
57
|
-
*/
|
|
58
46
|
export type DocumentEffects<E, Ctx> = {
|
|
59
47
|
announce: (fact: DocumentFact<E>) => Announcement | readonly Announcement[] | null;
|
|
60
48
|
beforeCreate?: (ctx: Ctx, body: BodyOf<E>) => Promise<BodyOf<E>>;
|
|
@@ -1,21 +1,11 @@
|
|
|
1
1
|
import { type Result } from 'better-result';
|
|
2
2
|
export declare const MAIL_UNDELIVERED_TAG = "DocumentMailUndelivered";
|
|
3
3
|
declare const MailUndelivered_base: import("better-result").TaggedErrorClass<"DocumentMailUndelivered">;
|
|
4
|
-
/**
|
|
5
|
-
* What a mail port answers with when the message did not leave; the step it runs in fails on it.
|
|
6
|
-
* `TaggedError` is aliased the way observability aliases it: oxlint reads the bare call as an
|
|
7
|
-
* error thrown without `new`.
|
|
8
|
-
*/
|
|
9
4
|
export declare class MailUndelivered extends /* @__PURE__ */ MailUndelivered_base<{
|
|
10
5
|
to: string;
|
|
11
6
|
cause: unknown;
|
|
12
7
|
}> {
|
|
13
8
|
}
|
|
14
|
-
/**
|
|
15
|
-
* One entity's rows, bound to the run's organisation by the host: `stepsOf` over a store door is
|
|
16
|
-
* the shape, so every call is a journalled step in a durable run. `body` is `never` on purpose —
|
|
17
|
-
* the factory writes what the entity decided and a door typed to one body still fits.
|
|
18
|
-
*/
|
|
19
9
|
export type DocumentDoorPort = {
|
|
20
10
|
get: (params: {
|
|
21
11
|
ref: string;
|
|
@@ -32,13 +22,6 @@ export type DocumentDoorPort = {
|
|
|
32
22
|
ref: string;
|
|
33
23
|
}) => Promise<unknown>;
|
|
34
24
|
};
|
|
35
|
-
/**
|
|
36
|
-
* What a host answers the generic body with. Three are the host's alone — its doors, its links,
|
|
37
|
-
* its mail — and the rest default: `counter` is asked for only by an entity numbered from one,
|
|
38
|
-
* `actor` reads a string `actor` off the context or names the system, `guard` allows, `now` is
|
|
39
|
-
* the clock, and `seed` refuses a template. Plain functions — the factory makes the steps of the
|
|
40
|
-
* two that reach the outside world, so the durable-body law holds on every host.
|
|
41
|
-
*/
|
|
42
25
|
export type DocumentWorkflowPorts<Ctx> = {
|
|
43
26
|
door: (ctx: Ctx, entity: string) => DocumentDoorPort;
|
|
44
27
|
link: (ctx: Ctx, link: {
|
|
@@ -1,21 +1,11 @@
|
|
|
1
1
|
import { type Result } from 'better-result';
|
|
2
2
|
export declare const MAIL_UNDELIVERED_TAG = "DocumentMailUndelivered";
|
|
3
3
|
declare const MailUndelivered_base: import("better-result").TaggedErrorClass<"DocumentMailUndelivered">;
|
|
4
|
-
/**
|
|
5
|
-
* What a mail port answers with when the message did not leave; the step it runs in fails on it.
|
|
6
|
-
* `TaggedError` is aliased the way observability aliases it: oxlint reads the bare call as an
|
|
7
|
-
* error thrown without `new`.
|
|
8
|
-
*/
|
|
9
4
|
export declare class MailUndelivered extends /* @__PURE__ */ MailUndelivered_base<{
|
|
10
5
|
to: string;
|
|
11
6
|
cause: unknown;
|
|
12
7
|
}> {
|
|
13
8
|
}
|
|
14
|
-
/**
|
|
15
|
-
* One entity's rows, bound to the run's organisation by the host: `stepsOf` over a store door is
|
|
16
|
-
* the shape, so every call is a journalled step in a durable run. `body` is `never` on purpose —
|
|
17
|
-
* the factory writes what the entity decided and a door typed to one body still fits.
|
|
18
|
-
*/
|
|
19
9
|
export type DocumentDoorPort = {
|
|
20
10
|
get: (params: {
|
|
21
11
|
ref: string;
|
|
@@ -32,13 +22,6 @@ export type DocumentDoorPort = {
|
|
|
32
22
|
ref: string;
|
|
33
23
|
}) => Promise<unknown>;
|
|
34
24
|
};
|
|
35
|
-
/**
|
|
36
|
-
* What a host answers the generic body with. Three are the host's alone — its doors, its links,
|
|
37
|
-
* its mail — and the rest default: `counter` is asked for only by an entity numbered from one,
|
|
38
|
-
* `actor` reads a string `actor` off the context or names the system, `guard` allows, `now` is
|
|
39
|
-
* the clock, and `seed` refuses a template. Plain functions — the factory makes the steps of the
|
|
40
|
-
* two that reach the outside world, so the durable-body law holds on every host.
|
|
41
|
-
*/
|
|
42
25
|
export type DocumentWorkflowPorts<Ctx> = {
|
|
43
26
|
door: (ctx: Ctx, entity: string) => DocumentDoorPort;
|
|
44
27
|
link: (ctx: Ctx, link: {
|
|
@@ -47,6 +47,16 @@ __export(exports_refusals, {
|
|
|
47
47
|
DocumentNotFound: () => DocumentNotFound,
|
|
48
48
|
DocumentNotRemovable: () => DocumentNotRemovable,
|
|
49
49
|
DocumentTaken: () => DocumentTaken,
|
|
50
|
+
LINK_EXPIRED_TAG: () => LINK_EXPIRED_TAG,
|
|
51
|
+
LINK_INVALID_TAG: () => LINK_INVALID_TAG,
|
|
52
|
+
LINK_NOT_A_DOCUMENT_TAG: () => LINK_NOT_A_DOCUMENT_TAG,
|
|
53
|
+
LINK_RETIRED_TAG: () => LINK_RETIRED_TAG,
|
|
54
|
+
LINK_WRONG_ORG_TAG: () => LINK_WRONG_ORG_TAG,
|
|
55
|
+
LinkExpired: () => LinkExpired,
|
|
56
|
+
LinkInvalid: () => LinkInvalid,
|
|
57
|
+
LinkNotADocument: () => LinkNotADocument,
|
|
58
|
+
LinkRetired: () => LinkRetired,
|
|
59
|
+
LinkWrongOrg: () => LinkWrongOrg,
|
|
50
60
|
NUMBERING_REFUSED_TAG: () => NUMBERING_REFUSED_TAG,
|
|
51
61
|
NumberingRefused: () => NumberingRefused,
|
|
52
62
|
TRANSITION_REFUSED_TAG: () => TRANSITION_REFUSED_TAG,
|
|
@@ -60,6 +70,11 @@ var NUMBERING_REFUSED_TAG = "NumberingRefused";
|
|
|
60
70
|
var TRANSITION_REFUSED_TAG = "TransitionRefused";
|
|
61
71
|
var DOCUMENT_NOT_REMOVABLE_TAG = "DocumentNotRemovable";
|
|
62
72
|
var CONVERSION_REFUSED_TAG = "ConversionRefused";
|
|
73
|
+
var LINK_INVALID_TAG = "DocumentLinkInvalid";
|
|
74
|
+
var LINK_EXPIRED_TAG = "DocumentLinkExpired";
|
|
75
|
+
var LINK_WRONG_ORG_TAG = "DocumentLinkWrongOrg";
|
|
76
|
+
var LINK_NOT_A_DOCUMENT_TAG = "DocumentLinkNotADocument";
|
|
77
|
+
var LINK_RETIRED_TAG = "DocumentLinkRetired";
|
|
63
78
|
|
|
64
79
|
class DocumentNotFound extends (/* @__PURE__ */ import_better_result.TaggedError(DOCUMENT_NOT_FOUND_TAG)) {
|
|
65
80
|
}
|
|
@@ -78,3 +93,18 @@ class DocumentNotRemovable extends (/* @__PURE__ */ import_better_result.TaggedE
|
|
|
78
93
|
|
|
79
94
|
class ConversionRefused extends (/* @__PURE__ */ import_better_result.TaggedError(CONVERSION_REFUSED_TAG)) {
|
|
80
95
|
}
|
|
96
|
+
|
|
97
|
+
class LinkInvalid extends (/* @__PURE__ */ import_better_result.TaggedError(LINK_INVALID_TAG)) {
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
class LinkExpired extends (/* @__PURE__ */ import_better_result.TaggedError(LINK_EXPIRED_TAG)) {
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
class LinkWrongOrg extends (/* @__PURE__ */ import_better_result.TaggedError(LINK_WRONG_ORG_TAG)) {
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
class LinkNotADocument extends (/* @__PURE__ */ import_better_result.TaggedError(LINK_NOT_A_DOCUMENT_TAG)) {
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
class LinkRetired extends (/* @__PURE__ */ import_better_result.TaggedError(LINK_RETIRED_TAG)) {
|
|
110
|
+
}
|
|
@@ -4,14 +4,12 @@ export declare const NUMBERING_REFUSED_TAG = "NumberingRefused";
|
|
|
4
4
|
export declare const TRANSITION_REFUSED_TAG = "TransitionRefused";
|
|
5
5
|
export declare const DOCUMENT_NOT_REMOVABLE_TAG = "DocumentNotRemovable";
|
|
6
6
|
export declare const CONVERSION_REFUSED_TAG = "ConversionRefused";
|
|
7
|
+
export declare const LINK_INVALID_TAG = "DocumentLinkInvalid";
|
|
8
|
+
export declare const LINK_EXPIRED_TAG = "DocumentLinkExpired";
|
|
9
|
+
export declare const LINK_WRONG_ORG_TAG = "DocumentLinkWrongOrg";
|
|
10
|
+
export declare const LINK_NOT_A_DOCUMENT_TAG = "DocumentLinkNotADocument";
|
|
11
|
+
export declare const LINK_RETIRED_TAG = "DocumentLinkRetired";
|
|
7
12
|
declare const DocumentNotFound_base: import("better-result").TaggedErrorClass<"DocumentNotFound">;
|
|
8
|
-
/**
|
|
9
|
-
* What a document workflow refuses, named. The engine wraps whatever a body throws in its own
|
|
10
|
-
* `RunFailedError` with the refusal as `cause`, so a host reads the name off the cause and answers
|
|
11
|
-
* with it — 404 for a document that is not there, 409 for a ref that is taken or a move the machine
|
|
12
|
-
* refuses, 400 for a numbering it cannot honour — instead of a 500 with the sentence inside it.
|
|
13
|
-
* Aliased the way `MailUndelivered` is: oxlint reads the bare call as an error thrown without `new`.
|
|
14
|
-
*/
|
|
15
13
|
export declare class DocumentNotFound extends /* @__PURE__ */ DocumentNotFound_base<{
|
|
16
14
|
entity: string;
|
|
17
15
|
message: string;
|
|
@@ -26,7 +24,6 @@ export declare class DocumentTaken extends /* @__PURE__ */ DocumentTaken_base<{
|
|
|
26
24
|
}> {
|
|
27
25
|
}
|
|
28
26
|
declare const NumberingRefused_base: import("better-result").TaggedErrorClass<"NumberingRefused">;
|
|
29
|
-
/** `given` — a number the caller had to supply and did not; `counter` — one the caller supplied to an entity that mints its own, or the host declares no counter. */
|
|
30
27
|
export declare class NumberingRefused extends /* @__PURE__ */ NumberingRefused_base<{
|
|
31
28
|
entity: string;
|
|
32
29
|
message: string;
|
|
@@ -55,5 +52,36 @@ export declare class ConversionRefused extends /* @__PURE__ */ ConversionRefused
|
|
|
55
52
|
ref: string;
|
|
56
53
|
}> {
|
|
57
54
|
}
|
|
58
|
-
|
|
55
|
+
declare const LinkInvalid_base: import("better-result").TaggedErrorClass<"DocumentLinkInvalid">;
|
|
56
|
+
export declare class LinkInvalid extends /* @__PURE__ */ LinkInvalid_base<{
|
|
57
|
+
message: string;
|
|
58
|
+
}> {
|
|
59
|
+
}
|
|
60
|
+
declare const LinkExpired_base: import("better-result").TaggedErrorClass<"DocumentLinkExpired">;
|
|
61
|
+
export declare class LinkExpired extends /* @__PURE__ */ LinkExpired_base<{
|
|
62
|
+
expiredAt: number;
|
|
63
|
+
message: string;
|
|
64
|
+
}> {
|
|
65
|
+
}
|
|
66
|
+
declare const LinkWrongOrg_base: import("better-result").TaggedErrorClass<"DocumentLinkWrongOrg">;
|
|
67
|
+
export declare class LinkWrongOrg extends /* @__PURE__ */ LinkWrongOrg_base<{
|
|
68
|
+
expected: string;
|
|
69
|
+
found: string;
|
|
70
|
+
message: string;
|
|
71
|
+
}> {
|
|
72
|
+
}
|
|
73
|
+
declare const LinkNotADocument_base: import("better-result").TaggedErrorClass<"DocumentLinkNotADocument">;
|
|
74
|
+
export declare class LinkNotADocument extends /* @__PURE__ */ LinkNotADocument_base<{
|
|
75
|
+
entity: string;
|
|
76
|
+
message: string;
|
|
77
|
+
}> {
|
|
78
|
+
}
|
|
79
|
+
declare const LinkRetired_base: import("better-result").TaggedErrorClass<"DocumentLinkRetired">;
|
|
80
|
+
export declare class LinkRetired extends /* @__PURE__ */ LinkRetired_base<{
|
|
81
|
+
entity: string;
|
|
82
|
+
message: string;
|
|
83
|
+
ref: string;
|
|
84
|
+
}> {
|
|
85
|
+
}
|
|
86
|
+
export type DocumentRefusal = ConversionRefused | LinkExpired | LinkInvalid | LinkNotADocument | LinkRetired | LinkWrongOrg | DocumentNotFound | DocumentNotRemovable | DocumentTaken | NumberingRefused | TransitionRefused;
|
|
59
87
|
export {};
|
|
@@ -4,14 +4,12 @@ export declare const NUMBERING_REFUSED_TAG = "NumberingRefused";
|
|
|
4
4
|
export declare const TRANSITION_REFUSED_TAG = "TransitionRefused";
|
|
5
5
|
export declare const DOCUMENT_NOT_REMOVABLE_TAG = "DocumentNotRemovable";
|
|
6
6
|
export declare const CONVERSION_REFUSED_TAG = "ConversionRefused";
|
|
7
|
+
export declare const LINK_INVALID_TAG = "DocumentLinkInvalid";
|
|
8
|
+
export declare const LINK_EXPIRED_TAG = "DocumentLinkExpired";
|
|
9
|
+
export declare const LINK_WRONG_ORG_TAG = "DocumentLinkWrongOrg";
|
|
10
|
+
export declare const LINK_NOT_A_DOCUMENT_TAG = "DocumentLinkNotADocument";
|
|
11
|
+
export declare const LINK_RETIRED_TAG = "DocumentLinkRetired";
|
|
7
12
|
declare const DocumentNotFound_base: import("better-result").TaggedErrorClass<"DocumentNotFound">;
|
|
8
|
-
/**
|
|
9
|
-
* What a document workflow refuses, named. The engine wraps whatever a body throws in its own
|
|
10
|
-
* `RunFailedError` with the refusal as `cause`, so a host reads the name off the cause and answers
|
|
11
|
-
* with it — 404 for a document that is not there, 409 for a ref that is taken or a move the machine
|
|
12
|
-
* refuses, 400 for a numbering it cannot honour — instead of a 500 with the sentence inside it.
|
|
13
|
-
* Aliased the way `MailUndelivered` is: oxlint reads the bare call as an error thrown without `new`.
|
|
14
|
-
*/
|
|
15
13
|
export declare class DocumentNotFound extends /* @__PURE__ */ DocumentNotFound_base<{
|
|
16
14
|
entity: string;
|
|
17
15
|
message: string;
|
|
@@ -26,7 +24,6 @@ export declare class DocumentTaken extends /* @__PURE__ */ DocumentTaken_base<{
|
|
|
26
24
|
}> {
|
|
27
25
|
}
|
|
28
26
|
declare const NumberingRefused_base: import("better-result").TaggedErrorClass<"NumberingRefused">;
|
|
29
|
-
/** `given` — a number the caller had to supply and did not; `counter` — one the caller supplied to an entity that mints its own, or the host declares no counter. */
|
|
30
27
|
export declare class NumberingRefused extends /* @__PURE__ */ NumberingRefused_base<{
|
|
31
28
|
entity: string;
|
|
32
29
|
message: string;
|
|
@@ -55,5 +52,36 @@ export declare class ConversionRefused extends /* @__PURE__ */ ConversionRefused
|
|
|
55
52
|
ref: string;
|
|
56
53
|
}> {
|
|
57
54
|
}
|
|
58
|
-
|
|
55
|
+
declare const LinkInvalid_base: import("better-result").TaggedErrorClass<"DocumentLinkInvalid">;
|
|
56
|
+
export declare class LinkInvalid extends /* @__PURE__ */ LinkInvalid_base<{
|
|
57
|
+
message: string;
|
|
58
|
+
}> {
|
|
59
|
+
}
|
|
60
|
+
declare const LinkExpired_base: import("better-result").TaggedErrorClass<"DocumentLinkExpired">;
|
|
61
|
+
export declare class LinkExpired extends /* @__PURE__ */ LinkExpired_base<{
|
|
62
|
+
expiredAt: number;
|
|
63
|
+
message: string;
|
|
64
|
+
}> {
|
|
65
|
+
}
|
|
66
|
+
declare const LinkWrongOrg_base: import("better-result").TaggedErrorClass<"DocumentLinkWrongOrg">;
|
|
67
|
+
export declare class LinkWrongOrg extends /* @__PURE__ */ LinkWrongOrg_base<{
|
|
68
|
+
expected: string;
|
|
69
|
+
found: string;
|
|
70
|
+
message: string;
|
|
71
|
+
}> {
|
|
72
|
+
}
|
|
73
|
+
declare const LinkNotADocument_base: import("better-result").TaggedErrorClass<"DocumentLinkNotADocument">;
|
|
74
|
+
export declare class LinkNotADocument extends /* @__PURE__ */ LinkNotADocument_base<{
|
|
75
|
+
entity: string;
|
|
76
|
+
message: string;
|
|
77
|
+
}> {
|
|
78
|
+
}
|
|
79
|
+
declare const LinkRetired_base: import("better-result").TaggedErrorClass<"DocumentLinkRetired">;
|
|
80
|
+
export declare class LinkRetired extends /* @__PURE__ */ LinkRetired_base<{
|
|
81
|
+
entity: string;
|
|
82
|
+
message: string;
|
|
83
|
+
ref: string;
|
|
84
|
+
}> {
|
|
85
|
+
}
|
|
86
|
+
export type DocumentRefusal = ConversionRefused | LinkExpired | LinkInvalid | LinkNotADocument | LinkRetired | LinkWrongOrg | DocumentNotFound | DocumentNotRemovable | DocumentTaken | NumberingRefused | TransitionRefused;
|
|
59
87
|
export {};
|
|
@@ -6,6 +6,11 @@ var NUMBERING_REFUSED_TAG = "NumberingRefused";
|
|
|
6
6
|
var TRANSITION_REFUSED_TAG = "TransitionRefused";
|
|
7
7
|
var DOCUMENT_NOT_REMOVABLE_TAG = "DocumentNotRemovable";
|
|
8
8
|
var CONVERSION_REFUSED_TAG = "ConversionRefused";
|
|
9
|
+
var LINK_INVALID_TAG = "DocumentLinkInvalid";
|
|
10
|
+
var LINK_EXPIRED_TAG = "DocumentLinkExpired";
|
|
11
|
+
var LINK_WRONG_ORG_TAG = "DocumentLinkWrongOrg";
|
|
12
|
+
var LINK_NOT_A_DOCUMENT_TAG = "DocumentLinkNotADocument";
|
|
13
|
+
var LINK_RETIRED_TAG = "DocumentLinkRetired";
|
|
9
14
|
|
|
10
15
|
class DocumentNotFound extends (/* @__PURE__ */ tagged(DOCUMENT_NOT_FOUND_TAG)) {
|
|
11
16
|
}
|
|
@@ -24,6 +29,21 @@ class DocumentNotRemovable extends (/* @__PURE__ */ tagged(DOCUMENT_NOT_REMOVABL
|
|
|
24
29
|
|
|
25
30
|
class ConversionRefused extends (/* @__PURE__ */ tagged(CONVERSION_REFUSED_TAG)) {
|
|
26
31
|
}
|
|
32
|
+
|
|
33
|
+
class LinkInvalid extends (/* @__PURE__ */ tagged(LINK_INVALID_TAG)) {
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
class LinkExpired extends (/* @__PURE__ */ tagged(LINK_EXPIRED_TAG)) {
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
class LinkWrongOrg extends (/* @__PURE__ */ tagged(LINK_WRONG_ORG_TAG)) {
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
class LinkNotADocument extends (/* @__PURE__ */ tagged(LINK_NOT_A_DOCUMENT_TAG)) {
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
class LinkRetired extends (/* @__PURE__ */ tagged(LINK_RETIRED_TAG)) {
|
|
46
|
+
}
|
|
27
47
|
export {
|
|
28
48
|
CONVERSION_REFUSED_TAG,
|
|
29
49
|
ConversionRefused,
|
|
@@ -33,6 +53,16 @@ export {
|
|
|
33
53
|
DocumentNotFound,
|
|
34
54
|
DocumentNotRemovable,
|
|
35
55
|
DocumentTaken,
|
|
56
|
+
LINK_EXPIRED_TAG,
|
|
57
|
+
LINK_INVALID_TAG,
|
|
58
|
+
LINK_NOT_A_DOCUMENT_TAG,
|
|
59
|
+
LINK_RETIRED_TAG,
|
|
60
|
+
LINK_WRONG_ORG_TAG,
|
|
61
|
+
LinkExpired,
|
|
62
|
+
LinkInvalid,
|
|
63
|
+
LinkNotADocument,
|
|
64
|
+
LinkRetired,
|
|
65
|
+
LinkWrongOrg,
|
|
36
66
|
NUMBERING_REFUSED_TAG,
|
|
37
67
|
NumberingRefused,
|
|
38
68
|
TRANSITION_REFUSED_TAG,
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
function __accessProp(key) {
|
|
6
|
+
return this[key];
|
|
7
|
+
}
|
|
8
|
+
var __toCommonJS = (from) => {
|
|
9
|
+
var entry = (__moduleCache ??= new WeakMap).get(from), desc;
|
|
10
|
+
if (entry)
|
|
11
|
+
return entry;
|
|
12
|
+
entry = __defProp({}, "__esModule", { value: true });
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (var key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(entry, key))
|
|
16
|
+
__defProp(entry, key, {
|
|
17
|
+
get: __accessProp.bind(from, key),
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
__moduleCache.set(from, entry);
|
|
22
|
+
return entry;
|
|
23
|
+
};
|
|
24
|
+
var __moduleCache;
|
|
25
|
+
var __returnValue = (v) => v;
|
|
26
|
+
function __exportSetter(name, newValue) {
|
|
27
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
28
|
+
}
|
|
29
|
+
var __export = (target, all) => {
|
|
30
|
+
for (var name in all)
|
|
31
|
+
__defProp(target, name, {
|
|
32
|
+
get: all[name],
|
|
33
|
+
enumerable: true,
|
|
34
|
+
configurable: true,
|
|
35
|
+
set: __exportSetter.bind(all, name)
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// src/workflows/shared.ts
|
|
40
|
+
var exports_shared = {};
|
|
41
|
+
__export(exports_shared, {
|
|
42
|
+
documentShared: () => documentShared
|
|
43
|
+
});
|
|
44
|
+
module.exports = __toCommonJS(exports_shared);
|
|
45
|
+
var import_workflows = require("@geonosis/workflows");
|
|
46
|
+
var import_schema = require("../core/schema.cjs");
|
|
47
|
+
var import_refusals = require("./refusals.cjs");
|
|
48
|
+
var inputSchema = import_schema.schemaOf((input) => {
|
|
49
|
+
const token = typeof input === "object" && input !== null && "token" in input ? input.token : undefined;
|
|
50
|
+
return typeof token === "string" && token !== "" ? { value: { token } } : { issues: [{ message: "expected a token" }] };
|
|
51
|
+
});
|
|
52
|
+
var documentShared = (registry, ports) => import_workflows.createWorkflow("document.shared", async (input, ctx) => {
|
|
53
|
+
const claims = await ports.verifier.verify(input.token);
|
|
54
|
+
if (claims === null) {
|
|
55
|
+
throw new import_refusals.LinkInvalid({ message: "this link is not one this door signed, or was altered" });
|
|
56
|
+
}
|
|
57
|
+
const now = (ports.now ?? Date.now)();
|
|
58
|
+
if (claims.exp <= now) {
|
|
59
|
+
throw new import_refusals.LinkExpired({ expiredAt: claims.exp, message: "this link has expired" });
|
|
60
|
+
}
|
|
61
|
+
const scoped = ports.org?.(ctx);
|
|
62
|
+
if (scoped !== undefined && scoped !== claims.org) {
|
|
63
|
+
throw new import_refusals.LinkWrongOrg({
|
|
64
|
+
expected: scoped,
|
|
65
|
+
found: claims.org,
|
|
66
|
+
message: "this link was issued by another organisation"
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
const entity = registry.names.find((name) => name === claims.entity);
|
|
70
|
+
if (entity === undefined) {
|
|
71
|
+
throw new import_refusals.LinkNotADocument({
|
|
72
|
+
entity: claims.entity,
|
|
73
|
+
message: `this link points at a ${claims.entity}, which is not a document`
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
const door = ports.door(ctx, { entity, org: claims.org });
|
|
77
|
+
const view = await door.render({ ref: claims.ref });
|
|
78
|
+
if (view === null) {
|
|
79
|
+
if (await door.retired({ ref: claims.ref })) {
|
|
80
|
+
throw new import_refusals.LinkRetired({
|
|
81
|
+
entity,
|
|
82
|
+
message: "the document this link points at has been retired",
|
|
83
|
+
ref: claims.ref
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
throw new import_refusals.DocumentNotFound({
|
|
87
|
+
entity,
|
|
88
|
+
message: `no ${entity} is stored as ${claims.ref}`,
|
|
89
|
+
ref: claims.ref
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
return { entity, view };
|
|
93
|
+
}, { input: inputSchema });
|