effect-inngest 0.3.0-beta.1 → 0.3.0-beta.3
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/Function.d.ts +6 -4
- package/dist/Group.d.ts +1 -1
- package/dist/internal/serve/Signature.js +9 -6
- package/package.json +4 -4
- package/src/Function.ts +8 -3
- package/src/Group.ts +1 -1
- package/src/internal/serve/Signature.ts +20 -7
package/dist/Function.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ declare const TypeId: unique symbol;
|
|
|
18
18
|
*/
|
|
19
19
|
type TypeId = typeof TypeId;
|
|
20
20
|
type EventSchema = EventDefinition;
|
|
21
|
+
type EventEnvelope<Event extends EventSchema> = EventType<Event>;
|
|
21
22
|
/**
|
|
22
23
|
* An event-based trigger configuration.
|
|
23
24
|
*
|
|
@@ -395,10 +396,11 @@ declare namespace InngestFunction {
|
|
|
395
396
|
type Tag<F> = F extends InngestFunction<infer T, any, any, any> ? T : never;
|
|
396
397
|
type Triggers<F> = F extends InngestFunction<any, infer T, any, any> ? T : never;
|
|
397
398
|
type Events<F> = F extends InngestFunction<any, infer T, any, any> ? (T extends EventTrigger<infer E> ? E : never) : never;
|
|
398
|
-
type EventPayload<F> =
|
|
399
|
-
type
|
|
400
|
-
readonly batchEvents:
|
|
401
|
-
} ?
|
|
399
|
+
type EventPayload<F> = EventEnvelope<Events<F>>;
|
|
400
|
+
type HasBatchEvents<O> = O extends {
|
|
401
|
+
readonly batchEvents: infer BatchEvents;
|
|
402
|
+
} ? Exclude<BatchEvents, undefined> extends BatchEventsOption ? true : false : false;
|
|
403
|
+
type EventType<F> = HasBatchEvents<Options<F>> extends true ? ReadonlyArray<EventPayload<F>> : EventPayload<F>;
|
|
402
404
|
type SuccessSchema<F> = F extends InngestFunction<any, any, infer S, any> ? S : never;
|
|
403
405
|
type Success<F> = Schema.Schema.Type<SuccessSchema<F>>;
|
|
404
406
|
type Options<F> = F extends InngestFunction<any, any, any, infer O> ? O : never;
|
package/dist/Group.d.ts
CHANGED
|
@@ -29,7 +29,7 @@ type HandlerFn<F extends InngestFunction.Any> = (context: HandlerContext<F>) =>
|
|
|
29
29
|
* @since 0.1.0
|
|
30
30
|
* @category models
|
|
31
31
|
*/
|
|
32
|
-
type HandlersFrom<Fns extends InngestFunction.Any> = { readonly [
|
|
32
|
+
type HandlersFrom<Fns extends InngestFunction.Any> = { readonly [Tag in InngestFunction.Tag<Fns>]: HandlerFrom<Fns, Tag> };
|
|
33
33
|
/**
|
|
34
34
|
* @since 0.1.0
|
|
35
35
|
* @category models
|
|
@@ -70,13 +70,13 @@ const SignatureParams = Schema.Struct({
|
|
|
70
70
|
});
|
|
71
71
|
const hashSigningKey = (signingKey) => Encoding.encodeHex(NodeCrypto.createHash("sha256").update(signingKey.replace(/^signkey-\w+-/, "")).digest());
|
|
72
72
|
var Signature = class extends Context.Service()("effect-inngest/Signature", { make: (config) => Effect.gen(function* () {
|
|
73
|
-
const signingKey = config.signingKey.pipe(Option.flatMap(PreparedSigningKey.decode));
|
|
74
|
-
const fallbackSigningKey = config.signingKeyFallback.pipe(Option.flatMap(PreparedSigningKey.decode));
|
|
75
|
-
if (Option.isSome(config.signingKey) && Option.isNone(signingKey)) return yield* SignatureError.make({
|
|
73
|
+
const signingKey = config.verification === "disabled" ? Option.none() : config.signingKey.pipe(Option.flatMap(PreparedSigningKey.decode));
|
|
74
|
+
const fallbackSigningKey = config.verification === "disabled" ? Option.none() : config.signingKeyFallback.pipe(Option.flatMap(PreparedSigningKey.decode));
|
|
75
|
+
if (config.verification === "required" && Option.isSome(config.signingKey) && Option.isNone(signingKey)) return yield* SignatureError.make({
|
|
76
76
|
reason: "invalid_format",
|
|
77
77
|
message: "Invalid signing key"
|
|
78
78
|
});
|
|
79
|
-
if (Option.isSome(config.signingKeyFallback) && Option.isNone(fallbackSigningKey)) return yield* SignatureError.make({
|
|
79
|
+
if (config.verification === "required" && Option.isSome(config.signingKeyFallback) && Option.isNone(fallbackSigningKey)) return yield* SignatureError.make({
|
|
80
80
|
reason: "invalid_format",
|
|
81
81
|
message: "Invalid signing key"
|
|
82
82
|
});
|
|
@@ -96,12 +96,15 @@ var Signature = class extends Context.Service()("effect-inngest/Signature", { ma
|
|
|
96
96
|
});
|
|
97
97
|
}),
|
|
98
98
|
sign: Effect.fn("effect-inngest/Signature/sign")(function* (body) {
|
|
99
|
-
const key = yield* Option.match(signingKey, {
|
|
99
|
+
const key = yield* Option.match(config.signingKey, {
|
|
100
100
|
onNone: () => SignatureError.make({
|
|
101
101
|
reason: "missing_signing_key",
|
|
102
102
|
message: "No signing key configured for signing"
|
|
103
103
|
}),
|
|
104
|
-
onSome: Effect.
|
|
104
|
+
onSome: (key) => Effect.fromOption(PreparedSigningKey.decode(key)).pipe(Effect.mapError(() => SignatureError.make({
|
|
105
|
+
reason: "invalid_format",
|
|
106
|
+
message: "Invalid signing key"
|
|
107
|
+
})))
|
|
105
108
|
});
|
|
106
109
|
const now = yield* DateTime.now;
|
|
107
110
|
const timestampSeconds = Math.floor(now.epochMilliseconds / 1e3);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "effect-inngest",
|
|
3
|
-
"version": "0.3.0-beta.
|
|
3
|
+
"version": "0.3.0-beta.3",
|
|
4
4
|
"description": "Native Effect client library for Inngest - build durable, type-safe workflows",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"background-jobs",
|
|
@@ -116,13 +116,13 @@
|
|
|
116
116
|
"@ast-grep/cli": "^0.43.0",
|
|
117
117
|
"@changesets/changelog-github": "^0.6.0",
|
|
118
118
|
"@changesets/cli": "^2.31.0",
|
|
119
|
-
"@effect/platform-bun": "4.0.0-beta.
|
|
119
|
+
"@effect/platform-bun": "4.0.0-beta.85",
|
|
120
120
|
"@effect/tsgo": "0.14.3",
|
|
121
|
-
"@effect/vitest": "4.0.0-beta.
|
|
121
|
+
"@effect/vitest": "4.0.0-beta.85",
|
|
122
122
|
"@types/bun": "1.3.12",
|
|
123
123
|
"@typescript/native-preview": "^7.0.0-dev.20260420.1",
|
|
124
124
|
"@vitest/coverage-v8": "4.1.5",
|
|
125
|
-
"effect": "4.0.0-beta.
|
|
125
|
+
"effect": "4.0.0-beta.85",
|
|
126
126
|
"inngest": "^4.5.1",
|
|
127
127
|
"mockttp": "^4.4.2",
|
|
128
128
|
"typescript": "^5.9.3",
|
package/src/Function.ts
CHANGED
|
@@ -23,6 +23,7 @@ export const TypeId: unique symbol = Symbol.for("effect-inngest/Function");
|
|
|
23
23
|
export type TypeId = typeof TypeId;
|
|
24
24
|
|
|
25
25
|
export type EventSchema = InngestEvent.EventDefinition;
|
|
26
|
+
type EventEnvelope<Event extends EventSchema> = InngestEvent.EventType<Event>;
|
|
26
27
|
|
|
27
28
|
/**
|
|
28
29
|
* An event-based trigger configuration.
|
|
@@ -443,9 +444,13 @@ export declare namespace InngestFunction {
|
|
|
443
444
|
export type Triggers<F> = F extends InngestFunction<any, infer T, any, any> ? T : never;
|
|
444
445
|
export type Events<F> =
|
|
445
446
|
F extends InngestFunction<any, infer T, any, any> ? (T extends EventTrigger<infer E> ? E : never) : never;
|
|
446
|
-
export type EventPayload<F> =
|
|
447
|
-
export type
|
|
448
|
-
|
|
447
|
+
export type EventPayload<F> = EventEnvelope<Events<F>>;
|
|
448
|
+
export type HasBatchEvents<O> = O extends { readonly batchEvents: infer BatchEvents }
|
|
449
|
+
? Exclude<BatchEvents, undefined> extends BatchEventsOption
|
|
450
|
+
? true
|
|
451
|
+
: false
|
|
452
|
+
: false;
|
|
453
|
+
export type EventType<F> = HasBatchEvents<Options<F>> extends true ? ReadonlyArray<EventPayload<F>> : EventPayload<F>;
|
|
449
454
|
|
|
450
455
|
export type SuccessSchema<F> = F extends InngestFunction<any, any, infer S, any> ? S : never;
|
|
451
456
|
export type Success<F> = Schema.Schema.Type<SuccessSchema<F>>;
|
package/src/Group.ts
CHANGED
|
@@ -41,7 +41,7 @@ export type HandlerFn<F extends InngestFunction.Any> = (
|
|
|
41
41
|
* @category models
|
|
42
42
|
*/
|
|
43
43
|
export type HandlersFrom<Fns extends InngestFunction.Any> = {
|
|
44
|
-
readonly [
|
|
44
|
+
readonly [Tag in InngestFunction.Tag<Fns>]: HandlerFrom<Fns, Tag>;
|
|
45
45
|
};
|
|
46
46
|
|
|
47
47
|
/**
|
|
@@ -100,13 +100,23 @@ export const hashSigningKey = (signingKey: string): string =>
|
|
|
100
100
|
export class Signature extends Context.Service<Signature, SignatureService>()("effect-inngest/Signature", {
|
|
101
101
|
make: (config: SignatureConfig) =>
|
|
102
102
|
Effect.gen(function* () {
|
|
103
|
-
const signingKey =
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
103
|
+
const signingKey =
|
|
104
|
+
config.verification === "disabled"
|
|
105
|
+
? Option.none<PreparedSigningKey>()
|
|
106
|
+
: config.signingKey.pipe(Option.flatMap(PreparedSigningKey.decode));
|
|
107
|
+
const fallbackSigningKey =
|
|
108
|
+
config.verification === "disabled"
|
|
109
|
+
? Option.none<PreparedSigningKey>()
|
|
110
|
+
: config.signingKeyFallback.pipe(Option.flatMap(PreparedSigningKey.decode));
|
|
111
|
+
|
|
112
|
+
if (config.verification === "required" && Option.isSome(config.signingKey) && Option.isNone(signingKey)) {
|
|
107
113
|
return yield* SignatureError.make({ reason: "invalid_format", message: "Invalid signing key" });
|
|
108
114
|
}
|
|
109
|
-
if (
|
|
115
|
+
if (
|
|
116
|
+
config.verification === "required" &&
|
|
117
|
+
Option.isSome(config.signingKeyFallback) &&
|
|
118
|
+
Option.isNone(fallbackSigningKey)
|
|
119
|
+
) {
|
|
110
120
|
return yield* SignatureError.make({ reason: "invalid_format", message: "Invalid signing key" });
|
|
111
121
|
}
|
|
112
122
|
|
|
@@ -134,13 +144,16 @@ export class Signature extends Context.Service<Signature, SignatureService>()("e
|
|
|
134
144
|
});
|
|
135
145
|
|
|
136
146
|
const sign = Effect.fn("effect-inngest/Signature/sign")(function* (body: Uint8Array) {
|
|
137
|
-
const key = yield* Option.match(signingKey, {
|
|
147
|
+
const key = yield* Option.match(config.signingKey, {
|
|
138
148
|
onNone: () =>
|
|
139
149
|
SignatureError.make({
|
|
140
150
|
reason: "missing_signing_key",
|
|
141
151
|
message: "No signing key configured for signing",
|
|
142
152
|
}),
|
|
143
|
-
onSome:
|
|
153
|
+
onSome: (key) =>
|
|
154
|
+
Effect.fromOption(PreparedSigningKey.decode(key)).pipe(
|
|
155
|
+
Effect.mapError(() => SignatureError.make({ reason: "invalid_format", message: "Invalid signing key" })),
|
|
156
|
+
),
|
|
144
157
|
});
|
|
145
158
|
|
|
146
159
|
const now = yield* DateTime.now;
|