@requence/service 0.8.6 → 0.9.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 +73 -0
- package/README.md +3 -3
- package/build/index.js +76 -12
- package/build/index.js.map +12 -11
- package/build/types/helpers/src/jsonschema/types.d.ts +1 -0
- package/build/types/helpers/src/jsonschema/types.d.ts.map +1 -1
- package/build/types/helpers/src/jsonschema/validate.d.ts.map +1 -1
- package/build/types/helpers/src/protocol/treeNodes.d.ts.map +1 -1
- package/build/types/helpers/src/utils/variableRef.d.ts +56 -0
- package/build/types/helpers/src/utils/variableRef.d.ts.map +1 -1
- package/build/types/service/src/createAmqpConnection.d.ts +1 -1
- package/build/types/service/src/createAmqpConnection.d.ts.map +1 -1
- package/build/types/service/src/devSession.d.ts +13 -0
- package/build/types/service/src/devSession.d.ts.map +1 -0
- package/build/types/service/src/durableCallback.d.ts +7 -7
- package/build/types/service/src/helpers.d.ts +4 -4
- package/build/types/service/src/index.d.ts +11 -3
- package/build/types/service/src/index.d.ts.map +1 -1
- package/build/types/service/src/store.d.ts +5 -0
- package/build/types/service/src/store.d.ts.map +1 -1
- package/build/types/service/src/ui.d.ts +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,78 @@
|
|
|
1
1
|
# @requence/service
|
|
2
2
|
|
|
3
|
+
## 0.9.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 78c4a1f: A restarted automation can now continue where it stopped.
|
|
8
|
+
|
|
9
|
+
The store has a third binding, `automation`:
|
|
10
|
+
`context.store.shared('lastMailUid', 'automation')`. Its data is kept across
|
|
11
|
+
every start of ONE automation. Two automations on the same trigger template
|
|
12
|
+
never see each other's data, and deleting the automation deletes it. The
|
|
13
|
+
trigger's nodes and the action's nodes reach the same slots. In a task that no
|
|
14
|
+
automation started (a plain task, a run from the editor, a rerun) the call
|
|
15
|
+
fails with a `400` (`StoreRequestError` / `StoreRequestException`). It never
|
|
16
|
+
falls back to another binding.
|
|
17
|
+
|
|
18
|
+
Before, every start of an automation was a new task, so `task` data was gone,
|
|
19
|
+
and `taskTemplate` data was one slot for every automation on the trigger
|
|
20
|
+
template. A mail cursor there let one user's mailbox position skip another
|
|
21
|
+
user's mail.
|
|
22
|
+
|
|
23
|
+
A retry of a CONTINUOUS node now runs its configuration functions again, as a
|
|
24
|
+
reconnect does. This is true for the service's own `ctx.retry()` and for the
|
|
25
|
+
node's Retry setting. Before, a retry sent the first dispatch again, with the
|
|
26
|
+
configuration from the start of the task, so a cursor read in a configuration
|
|
27
|
+
function went back to where the task started. The node's remaining retry count
|
|
28
|
+
is kept, so a node that always fails still runs out of retries.
|
|
29
|
+
|
|
30
|
+
The task page of an automation shows an "Automation stored data" section in its
|
|
31
|
+
info popover: what the automation keeps, grouped by node, read-only and live.
|
|
32
|
+
|
|
33
|
+
- 350091b: A service version is now called a service variant.
|
|
34
|
+
|
|
35
|
+
The UI and the docs say "variant" where they said "version". Nothing else
|
|
36
|
+
changes: routes, the GraphQL API and the wire format are the same.
|
|
37
|
+
|
|
38
|
+
Both service SDKs take the new name. Write `createService({ variant: '1.0.0' }, …)`
|
|
39
|
+
in TypeScript and `Service({"variant": "1.0.0"}, …)` in Python. A plain string as
|
|
40
|
+
the first argument is the variant, as before.
|
|
41
|
+
|
|
42
|
+
`version` still works, but it is deprecated: TypeScript marks it `@deprecated`,
|
|
43
|
+
and Python emits a `DeprecationWarning`. Give only one of the two; different
|
|
44
|
+
values for both are refused. A worker on an older SDK keeps working, because
|
|
45
|
+
what it sends to the broker and the operator has not changed.
|
|
46
|
+
|
|
47
|
+
### Patch Changes
|
|
48
|
+
|
|
49
|
+
- 5010cd5: A service started with a dev token now checks that token with its Requence
|
|
50
|
+
instance and stops with the instance's reason if it is refused — for example
|
|
51
|
+
"the dev token is not known to this Requence instance". Before, an unknown,
|
|
52
|
+
expired or non-personal token started a worker on a dev-overlay queue that
|
|
53
|
+
nothing ever sent to, so every task stopped at that service, shown as not
|
|
54
|
+
connected. The service API (`/api/service/*`, used by `generate-types` and its
|
|
55
|
+
watch mode) also refuses such a token now instead of quietly answering for the
|
|
56
|
+
live branch. The check needs the Requence API to be reachable from the dev
|
|
57
|
+
process; a service without a dev token makes no such call.
|
|
58
|
+
- 3af42ca: A RabbitMQ restart no longer ends a running CONTINUOUS task as SUCCESSFUL.
|
|
59
|
+
|
|
60
|
+
A service keeps its connection id across an AMQP reconnect, so after a broker
|
|
61
|
+
restart the operator re-dispatched the message to the same process while the
|
|
62
|
+
old generator still ran there. The new run overwrote the old run's terminator,
|
|
63
|
+
and the `stop` meant for the old run ended the new one. Its `done` was
|
|
64
|
+
accepted, the task ended, and the old generator kept running.
|
|
65
|
+
|
|
66
|
+
A `stop` now names the attempt (epoch) it is meant for, and both SDKs keep one
|
|
67
|
+
terminator per attempt. The old run is stopped, the new run keeps going, and at
|
|
68
|
+
most one value is emitted twice. A `stop` without an epoch, sent when a node
|
|
69
|
+
fails or a task ends, still stops every attempt.
|
|
70
|
+
|
|
71
|
+
- b57d194: `return ctx.toOutput(…)` now compiles in a handler whose version has only named
|
|
72
|
+
outputs. Before, a version without a default output typed the handler's return
|
|
73
|
+
as `void`, so the documented way to send to a named output was a type error
|
|
74
|
+
there. Returning a bare value still needs a default output.
|
|
75
|
+
|
|
3
76
|
## 0.8.6
|
|
4
77
|
|
|
5
78
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -31,7 +31,7 @@ REQUENCE_SERVICE_ACCESS_TOKEN=your-token bun run index.ts
|
|
|
31
31
|
## Your first service
|
|
32
32
|
|
|
33
33
|
Create the service in the Requence UI first — its input schema, configuration schema and
|
|
34
|
-
outputs. Then implement the
|
|
34
|
+
outputs. Then implement the variant:
|
|
35
35
|
|
|
36
36
|
```typescript
|
|
37
37
|
import { createService } from '@requence/service'
|
|
@@ -41,7 +41,7 @@ createService('1.0.0', (ctx) => {
|
|
|
41
41
|
})
|
|
42
42
|
```
|
|
43
43
|
|
|
44
|
-
The
|
|
44
|
+
The first argument to `createService` is the **variant** of the service definition you are
|
|
45
45
|
implementing. When Requence dispatches a message, the handler runs and the return value is sent
|
|
46
46
|
back as the result.
|
|
47
47
|
|
|
@@ -62,7 +62,7 @@ npx requence-service generate-types
|
|
|
62
62
|
| `service.open()`, `service.close()` | [Starting & Stopping][lifecycle] |
|
|
63
63
|
| Generator handlers and `ctx.terminated` | [Continuous Mode][continuous] |
|
|
64
64
|
| `ctx.store` — what a node remembers past this message | [The Store][store] · [`ctx.store`][context-store] |
|
|
65
|
-
| `createDurableCallback`, `.for(…)`, the per-
|
|
65
|
+
| `createDurableCallback`, `.for(…)`, the per-variant queue | [Callbacks][callbacks] |
|
|
66
66
|
| `createUI`, `ctx.render`, handler props | [Surfaces][surfaces] |
|
|
67
67
|
| `ctx.defer()` → `service.act()` | [Deferred Delivery][deferred] |
|
|
68
68
|
| `wrapIterable`, `asyncEventEmitter` | [Utility Helpers][utilities] |
|
package/build/index.js
CHANGED
|
@@ -1942,7 +1942,8 @@ var backchannelMessageSchema = z11.object({
|
|
|
1942
1942
|
})).pipe(z11.object({
|
|
1943
1943
|
content: z11.discriminatedUnion("type", [
|
|
1944
1944
|
z11.object({
|
|
1945
|
-
type: z11.literal("stop")
|
|
1945
|
+
type: z11.literal("stop"),
|
|
1946
|
+
epoch: z11.string().optional()
|
|
1946
1947
|
}),
|
|
1947
1948
|
z11.object({
|
|
1948
1949
|
type: z11.literal("callback"),
|
|
@@ -2039,7 +2040,7 @@ function createConnection({
|
|
|
2039
2040
|
clientProperties: {
|
|
2040
2041
|
...connectionOptions?.clientProperties,
|
|
2041
2042
|
...buildServiceClientProperties({
|
|
2042
|
-
libVersion: "javascript@0.
|
|
2043
|
+
libVersion: "javascript@0.9.0",
|
|
2043
2044
|
serviceVersion: version,
|
|
2044
2045
|
connectionId,
|
|
2045
2046
|
prefetch,
|
|
@@ -2124,7 +2125,10 @@ function createConnection({
|
|
|
2124
2125
|
const backchannelMessage = result.data;
|
|
2125
2126
|
switch (backchannelMessage.payload.type) {
|
|
2126
2127
|
case "stop": {
|
|
2127
|
-
generatorTerminators.get(backchannelMessage.messageId)
|
|
2128
|
+
const attempts = generatorTerminators.get(backchannelMessage.messageId);
|
|
2129
|
+
const { epoch } = backchannelMessage.payload;
|
|
2130
|
+
const terminators = epoch === undefined ? [...attempts?.values() ?? []] : [attempts?.get(epoch)];
|
|
2131
|
+
terminators.forEach((terminate) => terminate?.("task stopped"));
|
|
2128
2132
|
break;
|
|
2129
2133
|
}
|
|
2130
2134
|
case "callback": {
|
|
@@ -2601,7 +2605,7 @@ function createConnection({
|
|
|
2601
2605
|
begin: true,
|
|
2602
2606
|
epoch,
|
|
2603
2607
|
...buildServiceIdentityHeaders({
|
|
2604
|
-
libVersion: "javascript@0.
|
|
2608
|
+
libVersion: "javascript@0.9.0",
|
|
2605
2609
|
name,
|
|
2606
2610
|
holdsSlot: !(isGeneratorHandler && mode === "CONTINUOUS")
|
|
2607
2611
|
})
|
|
@@ -2613,7 +2617,12 @@ function createConnection({
|
|
|
2613
2617
|
}
|
|
2614
2618
|
const generator = messageHandler(extendedContext);
|
|
2615
2619
|
const terminationPromise = Promise.withResolvers();
|
|
2616
|
-
generatorTerminators.
|
|
2620
|
+
let attempts = generatorTerminators.get(messageId);
|
|
2621
|
+
if (!attempts) {
|
|
2622
|
+
attempts = new Map;
|
|
2623
|
+
generatorTerminators.set(messageId, attempts);
|
|
2624
|
+
}
|
|
2625
|
+
attempts.set(epoch, (reason) => {
|
|
2617
2626
|
terminated = true;
|
|
2618
2627
|
generator.return().catch((error) => {
|
|
2619
2628
|
if (terminated && error instanceof Error && error.name === "AbortError" && !(error instanceof AbortError)) {
|
|
@@ -2814,7 +2823,11 @@ function createConnection({
|
|
|
2814
2823
|
}
|
|
2815
2824
|
} finally {
|
|
2816
2825
|
if (messageIdForCleanup) {
|
|
2817
|
-
generatorTerminators.
|
|
2826
|
+
const attempts = generatorTerminators.get(messageIdForCleanup);
|
|
2827
|
+
attempts?.delete(epoch);
|
|
2828
|
+
if (attempts?.size === 0) {
|
|
2829
|
+
generatorTerminators.delete(messageIdForCleanup);
|
|
2830
|
+
}
|
|
2818
2831
|
messageCodecs.delete(messageIdForCleanup);
|
|
2819
2832
|
}
|
|
2820
2833
|
registeredCallbackIds.forEach((id) => callbacks.delete(id));
|
|
@@ -2948,6 +2961,33 @@ function createConnection({
|
|
|
2948
2961
|
};
|
|
2949
2962
|
return api;
|
|
2950
2963
|
}
|
|
2964
|
+
|
|
2965
|
+
// src/devSession.ts
|
|
2966
|
+
class DevSessionError extends Error {
|
|
2967
|
+
constructor(message) {
|
|
2968
|
+
super(message);
|
|
2969
|
+
this.name = "DevSessionError";
|
|
2970
|
+
}
|
|
2971
|
+
}
|
|
2972
|
+
async function assertDevSession(params, fetchImpl = fetch) {
|
|
2973
|
+
const url = `${params.serverUrl}/service/dev-session`;
|
|
2974
|
+
let response;
|
|
2975
|
+
try {
|
|
2976
|
+
response = await fetchImpl(url, {
|
|
2977
|
+
headers: {
|
|
2978
|
+
Authorization: `Bearer ${params.connectionString}`,
|
|
2979
|
+
"x-dev-authorization": params.devKey
|
|
2980
|
+
}
|
|
2981
|
+
});
|
|
2982
|
+
} catch (error) {
|
|
2983
|
+
throw new DevSessionError(`Requence: the dev token cannot be checked — ${url} is not reachable (${error instanceof Error ? error.message : String(error)}). A dev overlay needs the Requence API.`);
|
|
2984
|
+
}
|
|
2985
|
+
if (response.ok) {
|
|
2986
|
+
return await response.json();
|
|
2987
|
+
}
|
|
2988
|
+
const reason = (await response.text().catch(() => "")).trim();
|
|
2989
|
+
throw new DevSessionError(`Requence: the dev token was refused by ${params.serverUrl} (${response.status})${reason ? `: ${reason}` : ""}`);
|
|
2990
|
+
}
|
|
2951
2991
|
// src/ui.ts
|
|
2952
2992
|
import { createHash as createHash3 } from "node:crypto";
|
|
2953
2993
|
import fs2 from "node:fs";
|
|
@@ -3090,18 +3130,25 @@ function loadPkgJson() {
|
|
|
3090
3130
|
return pkgJson;
|
|
3091
3131
|
}
|
|
3092
3132
|
var didWarnDevToken = false;
|
|
3093
|
-
function createService(
|
|
3133
|
+
function createService(optionsOrVariant, optionalMessageHandler) {
|
|
3094
3134
|
let options;
|
|
3095
3135
|
let messageHandler;
|
|
3096
|
-
if (typeof
|
|
3136
|
+
if (typeof optionsOrVariant === "string") {
|
|
3097
3137
|
options = {
|
|
3098
|
-
|
|
3138
|
+
variant: optionsOrVariant
|
|
3099
3139
|
};
|
|
3100
3140
|
messageHandler = optionalMessageHandler;
|
|
3101
3141
|
} else {
|
|
3102
|
-
options =
|
|
3142
|
+
options = optionsOrVariant;
|
|
3103
3143
|
messageHandler = optionalMessageHandler;
|
|
3104
3144
|
}
|
|
3145
|
+
if (options.variant !== undefined && options.version !== undefined && options.variant !== options.version) {
|
|
3146
|
+
throw new Error("conflicting service options: give `variant` only (`version` is its deprecated name)");
|
|
3147
|
+
}
|
|
3148
|
+
const variant = options.variant ?? options.version;
|
|
3149
|
+
if (typeof variant !== "string") {
|
|
3150
|
+
throw new Error("no service variant provided");
|
|
3151
|
+
}
|
|
3105
3152
|
let token = options.accessToken ?? process.env.REQUENCE_SERVICE_ACCESS_TOKEN ?? process.env.REQUENCE_ACCESS_TOKEN;
|
|
3106
3153
|
if (!token) {
|
|
3107
3154
|
try {
|
|
@@ -3125,6 +3172,7 @@ function createService(optionsOrVersion, optionalMessageHandler) {
|
|
|
3125
3172
|
}
|
|
3126
3173
|
const url = parts[1];
|
|
3127
3174
|
let devOverlay;
|
|
3175
|
+
let devSessionCheck;
|
|
3128
3176
|
if (devToken) {
|
|
3129
3177
|
const devParts = deobfuscate(devToken);
|
|
3130
3178
|
if (devParts[0] !== "api") {
|
|
@@ -3134,15 +3182,24 @@ function createService(optionsOrVersion, optionalMessageHandler) {
|
|
|
3134
3182
|
throw new Error("invalid dev token: access token and dev token belong to different requence instances");
|
|
3135
3183
|
}
|
|
3136
3184
|
devOverlay = devParts[1];
|
|
3185
|
+
if (!parts[2]) {
|
|
3186
|
+
throw new Error("invalid access token: it names no Requence API, so the dev token cannot be checked");
|
|
3187
|
+
}
|
|
3188
|
+
devSessionCheck = {
|
|
3189
|
+
serverUrl: parts[2],
|
|
3190
|
+
connectionString: parts[1],
|
|
3191
|
+
devKey: devParts[1]
|
|
3192
|
+
};
|
|
3137
3193
|
if (!didWarnDevToken) {
|
|
3138
3194
|
didWarnDevToken = true;
|
|
3139
3195
|
simple_default.warn("Requence: started with a |dev token| — this worker consumes a personal dev-overlay queue instead of the deployed version, and that queue is deleted shortly after the process stops. Do not deploy with one: unset |REQUENCE_DEV_TOKEN| / |REQUENCE_SERVICE_DEV_TOKEN|, or remove |requence.devToken| from package.json.");
|
|
3140
3196
|
}
|
|
3141
3197
|
}
|
|
3142
3198
|
const envMaxMessageSize = process.env.REQUENCE_MAX_MESSAGE_SIZE ? Number(process.env.REQUENCE_MAX_MESSAGE_SIZE) : undefined;
|
|
3143
|
-
|
|
3199
|
+
const api = createConnection({
|
|
3144
3200
|
...connectionOptionsSchema.parse({
|
|
3145
3201
|
...options,
|
|
3202
|
+
version: variant,
|
|
3146
3203
|
connectionOptions: resolveConnectionOptions(options.connectionOptions),
|
|
3147
3204
|
maxMessageSize: options.maxMessageSize ?? envMaxMessageSize,
|
|
3148
3205
|
url,
|
|
@@ -3150,6 +3207,13 @@ function createService(optionsOrVersion, optionalMessageHandler) {
|
|
|
3150
3207
|
}),
|
|
3151
3208
|
onConnectionStateChange: options.onConnectionStateChange
|
|
3152
3209
|
}, messageHandler);
|
|
3210
|
+
if (devSessionCheck) {
|
|
3211
|
+
assertDevSession(devSessionCheck).catch((error) => {
|
|
3212
|
+
simple_default.error(error instanceof Error ? error.message : String(error));
|
|
3213
|
+
process.exit(1);
|
|
3214
|
+
});
|
|
3215
|
+
}
|
|
3216
|
+
return api;
|
|
3153
3217
|
}
|
|
3154
3218
|
export {
|
|
3155
3219
|
PayloadTooLargeError2 as PayloadTooLargeError,
|
|
@@ -3178,5 +3242,5 @@ export {
|
|
|
3178
3242
|
wrapIterable
|
|
3179
3243
|
};
|
|
3180
3244
|
|
|
3181
|
-
//# debugId=
|
|
3245
|
+
//# debugId=9BAB68E67A971CC664756E2164756E21
|
|
3182
3246
|
//# sourceMappingURL=index.js.map
|