@pikku/lambda 0.12.5 → 0.12.7
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 +296 -0
- package/LICENSE +21 -0
- package/README.md +26 -1
- package/dist/http/index.d.ts +0 -2
- package/dist/http/index.js +0 -2
- package/dist/http/index.js.map +1 -1
- package/dist/lambda-deployment-service.js +2 -22
- package/dist/lambda-deployment-service.js.map +1 -1
- package/dist/websocket/utils.js +1 -1
- package/dist/websocket/utils.js.map +1 -1
- package/package.json +3 -2
- package/src/http/index.ts +0 -2
- package/src/lambda-deployment-service.ts +8 -27
- package/src/websocket/utils.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,299 @@
|
|
|
1
|
+
## 0.12.7
|
|
2
|
+
|
|
3
|
+
### Patch Changes
|
|
4
|
+
|
|
5
|
+
- fd9d834: Stop publishing internals that only their own package or file used. The declarations stay; only the entrypoint re-export is removed, so nothing that imported a name from where it is declared is affected.
|
|
6
|
+
- Updated dependencies [063f43a]
|
|
7
|
+
- Updated dependencies [ce66bf8]
|
|
8
|
+
- Updated dependencies [d0307a8]
|
|
9
|
+
- Updated dependencies [ce66bf8]
|
|
10
|
+
- Updated dependencies [3ad2131]
|
|
11
|
+
- Updated dependencies [b930dca]
|
|
12
|
+
- Updated dependencies [b95e77d]
|
|
13
|
+
- Updated dependencies [fd9d834]
|
|
14
|
+
- Updated dependencies [8978fbd]
|
|
15
|
+
- @pikku/core@0.12.82
|
|
16
|
+
|
|
17
|
+
## 0.12.6
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- afef587: Close eleven security weaknesses found in a review of `@pikku/core`. Most are
|
|
22
|
+
breaking, and two invalidate data or credentials already in the wild — read the
|
|
23
|
+
migration notes before upgrading.
|
|
24
|
+
|
|
25
|
+
**Breaking: AI agent thread ownership now fails closed.** Reading, listing,
|
|
26
|
+
resuming or approving an existing thread or run requires a resolved session
|
|
27
|
+
principal (`userId`, or `orgId` for `sessionScope: 'org'`), regardless of the
|
|
28
|
+
agent's `auth` setting. Previously a request without a session had no ownership
|
|
29
|
+
model at all: the caller-supplied `resourceId` was accepted as the ownership
|
|
30
|
+
key, so any caller could read or resume another party's thread by naming its
|
|
31
|
+
`resourceId`. Worse, `threadOwnerConstraint` returned `undefined` for a
|
|
32
|
+
sessionless caller, and `undefined` means _no filter_ rather than _no rows_ —
|
|
33
|
+
so `getAgentThreads` returned every thread in the deployment. It now returns
|
|
34
|
+
`string[]`, empty for a sessionless caller, which every storage backend already
|
|
35
|
+
treats as matching nothing. Sessionless agents still run one-shot conversations,
|
|
36
|
+
each with a fresh unguessable owner; what they lose is cross-request continuity.
|
|
37
|
+
Wire a session to restore it.
|
|
38
|
+
|
|
39
|
+
**Breaking: stored secrets and credentials must be re-entered.** `deriveKey` ran
|
|
40
|
+
a single unsalted round of SHA-256 over the passphrase and used the digest
|
|
41
|
+
directly as the AES-GCM key — roughly one hash per brute-force guess, with one
|
|
42
|
+
rainbow table working against every deployment. It is now PBKDF2-HMAC-SHA256 at
|
|
43
|
+
600,000 iterations over a random salt. There is no compatibility path: every
|
|
44
|
+
value held by the kysely, mongodb and redis secret services and the kysely
|
|
45
|
+
credential service becomes undecryptable. They fail loud, naming the key and
|
|
46
|
+
`key_version`, so the app hard-fails on first secret read until each is re-set.
|
|
47
|
+
|
|
48
|
+
The KEK salt is scoped to the key version and stored alongside it, rather than
|
|
49
|
+
per secret, so a bulk read costs one derivation instead of N — `getSecrets` over
|
|
50
|
+
50 secrets went from ~2.3s to ~48ms, and rotation from ~4.6s to ~94ms. This adds
|
|
51
|
+
a salt table (kysely), hash field (redis) or collection (mongodb), created
|
|
52
|
+
automatically on first use.
|
|
53
|
+
|
|
54
|
+
**Breaking: `PIKKU_REMOTE_SECRET` must be at least 32 characters.** The
|
|
55
|
+
remote-RPC session envelope moved from PBKDF2 to HKDF, which expands
|
|
56
|
+
high-entropy key material rather than stretching a low-entropy passphrase. That
|
|
57
|
+
took a remote hop from ~269ms to ~0.4ms — PBKDF2 was running twice per request —
|
|
58
|
+
but HKDF supplies no brute-force resistance, so the secret must carry the
|
|
59
|
+
entropy itself. A shorter secret now throws `WeakKeyMaterialError` at both ends.
|
|
60
|
+
Generate one with `openssl rand -base64 32` and roll it out to every service in
|
|
61
|
+
the mesh together: existing bearer tokens are format-incompatible, so a partial
|
|
62
|
+
rollout produces 401s until every instance is updated. The Cloudflare, Lambda
|
|
63
|
+
and Azure deployment services each hand-rolled a copy of `buildRemoteHeaders`
|
|
64
|
+
and now call the shared one, which is what keeps the two sides in step.
|
|
65
|
+
|
|
66
|
+
**Breaking: previously signed content URLs stop verifying.** `LocalContent`
|
|
67
|
+
signed only `{signedAt, expiresAt, notBefore}`, so a signature proved when a URL
|
|
68
|
+
was issued but never what it was issued for — any valid token was a skeleton
|
|
69
|
+
key, and swapping the pathname from a public thumbnail to a private document
|
|
70
|
+
still verified. The signature now binds the request path. Separately, the
|
|
71
|
+
verifier returned "valid" when no JWT service was wired, which is how
|
|
72
|
+
`pikku serve` ran: a forged `?signedAt=0&expiresAt=99999999999999` was accepted.
|
|
73
|
+
It now rejects with 403, `LocalContent` requires a `JWTService`, and
|
|
74
|
+
`pikku serve`/`pikku dev` mint an ephemeral per-process signing key so local
|
|
75
|
+
development works without shipping a fail-open path. In-flight signed URLs must
|
|
76
|
+
be re-issued.
|
|
77
|
+
|
|
78
|
+
**Request body size limits now apply to every adapter.** The `maxBodySize` cap
|
|
79
|
+
existed only in `PikkuFetchHTTPRequest`. The real hole was uWebSockets, which
|
|
80
|
+
drove `res.onData` itself and concatenated every chunk with no bound and nothing
|
|
81
|
+
downstream able to intervene; it now drops chunks past the limit and replies 413
|
|
82
|
+
before routing. Fastify delegates to its native `bodyLimit` (set only when
|
|
83
|
+
`maxBodySize` is configured, so fastify's stricter 1 MB default is never
|
|
84
|
+
loosened), and `PikkuExpressServer` feeds the limit into its body parsers. Two
|
|
85
|
+
paths can only reject rather than prevent, and are documented as such:
|
|
86
|
+
`express-middleware` mounted on your own app receives an already-parsed body, so
|
|
87
|
+
that deployment must bound its own parser; Next server actions bottom out at
|
|
88
|
+
`experimental.serverActions.bodySizeLimit`.
|
|
89
|
+
|
|
90
|
+
**Breaking: the console addon's privileged functions are gated by default.**
|
|
91
|
+
`wireAddon` gains a `scopes` option that applies to every function in the
|
|
92
|
+
addon's namespace, and the console scaffold now generates
|
|
93
|
+
`wireAddon({ name: 'console', package: '@pikku/addon-console', scopes: ['admin'] })`.
|
|
94
|
+
Previously the console's entire privileged surface — around 54 functions
|
|
95
|
+
including `credentialGet`, which returns a resolved OAuth token for an arbitrary
|
|
96
|
+
`userId`, `updateFunctionBody`, and `installAddon`, which shells out to a
|
|
97
|
+
package install — was protected only by an optional host-registered
|
|
98
|
+
`addGlobalPermission`. `resolveGlobalPermissions` returns `[]` when none is
|
|
99
|
+
registered and permission checking then no-ops, so an app that never registered
|
|
100
|
+
one served those functions to anyone, and with the template's default
|
|
101
|
+
`scaffold.rpc: "no-auth"` that meant unauthenticated. All of them now return 403
|
|
102
|
+
`MissingScopeError` without an `admin`, `admin:*` or `*` scope. **Regenerating
|
|
103
|
+
is required** — an app holding an old `console.gen.ts` stays open.
|
|
104
|
+
`installAddon` and `installOpenapiAddon` additionally declare their own
|
|
105
|
+
`auth: true, scopes: ['admin']`, and `getAgentThreads` now scopes its listing to
|
|
106
|
+
the session's own threads unless the caller holds admin.
|
|
107
|
+
|
|
108
|
+
Addon scopes are enforced in `runPikkuFunc` rather than at the RPC boundary,
|
|
109
|
+
because a wiring can reference an addon function directly — the inspector
|
|
110
|
+
records the addon's `packageName` on HTTP, channel, schedule, queue, CLI,
|
|
111
|
+
trigger, gateway and MCP wirings — and those paths never call `resolveNamespace`.
|
|
112
|
+
Enforcing at the RPC seam would have covered only the `namespace:function` form
|
|
113
|
+
while reading as complete.
|
|
114
|
+
|
|
115
|
+
**Breaking: `wireAddon`'s `auth` and `tags` now apply on direct wirings too.**
|
|
116
|
+
Both were read only by `resolveAddonFunction`, so they had exactly the hole
|
|
117
|
+
scopes had: `wireAddon({ name: 'console', package: '@pikku/addon-console', auth:
|
|
118
|
+
true, tags: ['admin'] })` gated `rpc('console:credentialGet')` and gated nothing
|
|
119
|
+
at all on an HTTP route wired straight to `credentialGet`. A consumer who
|
|
120
|
+
reached for the documented way to lock an addon down got a control that was
|
|
121
|
+
silently inert on every wiring except one. Both now resolve in `runPikkuFunc`.
|
|
122
|
+
`auth` merges as an OR — `auth: false` from an addon is ignored on a direct
|
|
123
|
+
wiring, because an addon may require a session the wiring did not but must never
|
|
124
|
+
waive one it did. Addon tags resolve to concrete middleware against the **root**
|
|
125
|
+
tag groups before the call rather than being folded into the function's
|
|
126
|
+
inherited middleware: `addTagMiddleware('admin', …)` is written by the consuming
|
|
127
|
+
app and registers under the root package, whereas `combineMiddleware` would look
|
|
128
|
+
the tag up under the addon's own `packageName`, where it does not exist.
|
|
129
|
+
|
|
130
|
+
One consequence worth naming: an addon that wires `auth: true` and also runs its
|
|
131
|
+
own sessionless internal work — a scheduled task or queue worker inside the
|
|
132
|
+
addon calling a sibling function — is now gated where it previously was not,
|
|
133
|
+
because a bare `rpc('fn')` from inside the addon reaches `runPikkuFunc` with the
|
|
134
|
+
addon's `packageName` like any other call. This reverses a decision that
|
|
135
|
+
deliberately scoped the gate to the namespaced boundary; that reasoning held
|
|
136
|
+
only while the boundary was real, and a direct wiring can enter an addon without
|
|
137
|
+
crossing it, so "already inside" is not something the runtime can infer. Such an
|
|
138
|
+
addon should carry authorization on the function via
|
|
139
|
+
`pikkuFunc({ permissions })`, which has always been enforced on every path. A
|
|
140
|
+
follow-up will add execution provenance so an intra-addon call can be
|
|
141
|
+
distinguished from an external one and skip the addon-level check; that needs a
|
|
142
|
+
marker no caller outside the process can set, which is its own design problem
|
|
143
|
+
and does not belong in a security fix.
|
|
144
|
+
|
|
145
|
+
**Codegen now warns when an exposed function has no gate (PKU574).** The
|
|
146
|
+
generated `POST /rpc/:rpcName` dispatcher forwards to `rpc.exposed`, which
|
|
147
|
+
refuses anything without `expose: true` — but nothing checked whether the
|
|
148
|
+
target was gated, because a dispatcher cannot know what it dispatches to. The
|
|
149
|
+
console shipped ~54 privileged functions through that gap and the toolchain was
|
|
150
|
+
silent. The inspector now reports every function that is exposed, sessionless,
|
|
151
|
+
and carries no `auth`, `scopes` or `permissions` of its own and none from a
|
|
152
|
+
governing `wireAddon`. It is a `warn`, not a critical: `expose: true` on an
|
|
153
|
+
ungated sessionless function is correct for a genuinely public endpoint, so it
|
|
154
|
+
blocks a build only under `--fail-on-warn`.
|
|
155
|
+
|
|
156
|
+
Two pieces of metadata were missing for this to be answerable statically, and
|
|
157
|
+
both are now recorded. A `pikkuSessionlessFunc`'s own `auth: true` was read at
|
|
158
|
+
runtime but never written to function meta, so a self-gated function was
|
|
159
|
+
indistinguishable from an ungated one — `sessionless` carries the baseline, and
|
|
160
|
+
`auth` now carries the tightening. And `wireAddon`'s `scopes`, `auth` and `tags`
|
|
161
|
+
were not parsed at all: the inspector recorded the addon's `rpcEndpoint` and its
|
|
162
|
+
secret, variable and credential overrides, and dropped every one of its gates.
|
|
163
|
+
An addon whose gates are not statically knowable is treated as gated, because a
|
|
164
|
+
false positive on a correctly-secured addon costs more than the one case it
|
|
165
|
+
would catch.
|
|
166
|
+
|
|
167
|
+
**Breaking: an application's global permissions now apply inside addons.**
|
|
168
|
+
`resolveGlobalPermissions` read only the bucket matching the function's own
|
|
169
|
+
package, but the generated `addGlobalPermission` wrapper takes no package
|
|
170
|
+
argument and always registers under the root. An app-wide rule like "every
|
|
171
|
+
request needs a signed-in user" therefore stopped at the addon boundary, and the
|
|
172
|
+
bucket an addon's functions did read was one no host could write to — which is
|
|
173
|
+
why the console addon's recommended `addGlobalPermission([isAdmin],
|
|
174
|
+
'@pikku/addon-console')` was never a gate anybody could actually install. A
|
|
175
|
+
function now resolves the root bucket and its own package's, root first.
|
|
176
|
+
Unioning is safe in a way nothing else here would be: globals AND, so adding the
|
|
177
|
+
root ones can only tighten. Package buckets stay one-way — a package's globals
|
|
178
|
+
never reach root functions, or an installed addon could gate the whole
|
|
179
|
+
application. Apps with both a root global and addon-provided functions will see
|
|
180
|
+
those functions gated where they previously were not.
|
|
181
|
+
|
|
182
|
+
**Codegen now records whether each HTTP route requires a session, and warns
|
|
183
|
+
about inert addon tags (PKU575).** Four separate things can demand a session —
|
|
184
|
+
the function's `sessionless`, its own `auth`, the route's (or its group's)
|
|
185
|
+
`auth`, and the addon it belongs to — and answering "which routes are open?"
|
|
186
|
+
meant joining all four by hand and knowing which wins. Each route's meta now
|
|
187
|
+
carries the resolved `requiresSession` alongside the route's own `auth`. Scopes
|
|
188
|
+
count as requiring one, since they are matched against the session's and fail
|
|
189
|
+
closed. Anything not statically knowable resolves to `true`, matching PKU574:
|
|
190
|
+
a route that looks stricter than it is costs less than one that looks open and
|
|
191
|
+
isn't. Separately, `wireAddon({ tags: ['admin'] })` reads like a gate and is
|
|
192
|
+
applied like one right up until no `addTagMiddleware('admin', …)` exists, at
|
|
193
|
+
which point it resolves to an empty list and gates nothing; that now warns.
|
|
194
|
+
Only addon tags are reported — a tag on a function is as likely to be
|
|
195
|
+
organizational, and warning about those would bury the case that matters.
|
|
196
|
+
|
|
197
|
+
**Object-shorthand permissions were missing from meta.** The inspector visited
|
|
198
|
+
`ts.PropertyAssignment` but not `ts.ShorthandPropertyAssignment`, so
|
|
199
|
+
`permissions: { canAdminOrg }` — enforced identically to the longhand form at
|
|
200
|
+
runtime, since `verifyPermissions` has a non-array branch — was recorded as _no
|
|
201
|
+
permissions at all_. That is the most dangerous direction for meta to be wrong
|
|
202
|
+
in: an audit reading it sees an open door where one is shut. It cost this review
|
|
203
|
+
a false IDOR report across ~35 billing and org functions before the source
|
|
204
|
+
contradicted the metadata.
|
|
205
|
+
|
|
206
|
+
**Functions that authorize in their own body can say so.** A webhook receiver
|
|
207
|
+
verifying a signature, or a handler redeeming a signed invite, is genuinely
|
|
208
|
+
closed while carrying no session, scope or permission — indistinguishable in
|
|
209
|
+
meta from one nobody remembered to gate, and so warned about forever by PKU574.
|
|
210
|
+
`selfAuthenticated: true` on the function config records the claim and silences
|
|
211
|
+
the warning for that function. It is declarative only: nothing at runtime reads
|
|
212
|
+
it and it grants nothing. Detection was rejected deliberately — inferring it
|
|
213
|
+
from the body means a function that _looks_ like it checks something silences
|
|
214
|
+
the warning while checking nothing, and a warning that is usually wrong stops
|
|
215
|
+
being read.
|
|
216
|
+
|
|
217
|
+
**Breaking: `scaffold.<feature>` is now `boolean | { auth?, path? }`, and `true`
|
|
218
|
+
means authenticated.** The old `'auth' | 'no-auth' | false` read like a
|
|
219
|
+
starter-file preference while being a live authorization decision, set three
|
|
220
|
+
directories from the functions it governed — the shape the console incident
|
|
221
|
+
took. A surface now becomes public only by writing `{ auth: false }`, so
|
|
222
|
+
omitting a field can never open anything: the failure mode of a forgotten flag
|
|
223
|
+
is a locked door. `{ path }` additionally overrides where the file is
|
|
224
|
+
generated, which previously could only be set for all features at once via
|
|
225
|
+
`pikkuDir`.
|
|
226
|
+
|
|
227
|
+
The legacy strings are **refused, not coerced**. `resolveScaffoldFeature` throws
|
|
228
|
+
naming the key and its replacement (`"rpc": "no-auth"` → `"rpc": { "auth":
|
|
229
|
+
false }`), and it does so at config load, not downstream. An earlier design used
|
|
230
|
+
a bare `string` for the output path, under which `"no-auth"` would have parsed
|
|
231
|
+
as a file named `no-auth` and every unmigrated config would have silently
|
|
232
|
+
produced nonsense; the object form makes any string invalid, so the failure is
|
|
233
|
+
loud.
|
|
234
|
+
|
|
235
|
+
The collapse is deliberately not uniform in effect. For `rpc` the flag was a
|
|
236
|
+
blanket "no anonymous RPC in this app" set on a dispatcher that cannot know what
|
|
237
|
+
it dispatches to; for `userAdmin` it was redundant, since the generated
|
|
238
|
+
functions are already `pikkuFunc` with `scopes: ['admin:users:list']`. But for
|
|
239
|
+
`agent`, `workflow`, `events` and `scenarios` it is the only gate — those
|
|
240
|
+
generate real endpoints the app never authors — so `true` keeps them
|
|
241
|
+
authenticated rather than opening them as a side effect of a config cleanup.
|
|
242
|
+
`webhook` and `remoteRpc` have no auth dimension at all (`serialize-remote-rpc.ts`
|
|
243
|
+
hardcodes `auth: false`), so an `{ auth }` on them is ignored. The three
|
|
244
|
+
configs in this repo are migrated preserving their current behaviour exactly.
|
|
245
|
+
|
|
246
|
+
**Queue job identities are signed.** A job carried the producer's `pikkuUserId`
|
|
247
|
+
as a plain string and the worker resolved a session from it with no
|
|
248
|
+
verification, so write access to the queue backend was act-as-any-user. The
|
|
249
|
+
identity is now `pq1.<claim>.<hmac>`, HMAC-SHA256 over the claim and the
|
|
250
|
+
canonicalized job payload, keyed by HKDF expansion of a new
|
|
251
|
+
`PIKKU_QUEUE_IDENTITY_SECRET`. Producers opt in by wrapping their queue service
|
|
252
|
+
with `SignedQueueService`. This fails safe rather than closed: with no secret
|
|
253
|
+
configured the identity is dropped and jobs still process, warning once per
|
|
254
|
+
process, so no existing deployment breaks on upgrade — it simply loses queue
|
|
255
|
+
identity until the secret is set. The payload rather than the job id is bound
|
|
256
|
+
because SQS, Cloudflare Queues, Azure and the in-memory service all mint ids
|
|
257
|
+
after `add` returns.
|
|
258
|
+
|
|
259
|
+
**Workflow inline state is read from the run record.** `isInline` consulted a
|
|
260
|
+
process-local `Map`, while `WorkflowRun.inline` is durable. Any instance that
|
|
261
|
+
did not start a run disagreed with the record, so one instance could dispatch a
|
|
262
|
+
queued job for a workflow another was already executing in-process. It is now
|
|
263
|
+
async and resolves through the durable identity, cached only when a context
|
|
264
|
+
already exists so a passive reader allocates nothing. The same `Map` also leaked:
|
|
265
|
+
`nextStepKey` fabricated replay state on every step, and `releaseContext`
|
|
266
|
+
refused to free anything carrying it, so runs whose steps executed outside a
|
|
267
|
+
`beginReplay` bracket — the step-worker queue path — stranded their context and
|
|
268
|
+
step state for the process lifetime. Contexts are now released by an explicit
|
|
269
|
+
execution counter. Step ordinals reset per execution rather than accumulating
|
|
270
|
+
across step-worker invocations in one process, which makes step naming
|
|
271
|
+
independent of how work was distributed.
|
|
272
|
+
|
|
273
|
+
**Secret reads fail loud in every store.** `MongoDBSecretService.getSecrets`
|
|
274
|
+
skipped rows that failed to decrypt, and the redis equivalent dropped every
|
|
275
|
+
rejection via `Promise.allSettled`, including the "No KEK available for
|
|
276
|
+
key_version N" configuration error. Both now throw, naming the key and its key
|
|
277
|
+
version, matching the kysely behaviour. This matters most alongside the KEK
|
|
278
|
+
change above: without it, an upgrade surfaces as a partial secrets map and an
|
|
279
|
+
opaque downstream failure instead of an error naming the secret to re-enter.
|
|
280
|
+
|
|
281
|
+
**A second middleware registration for a pattern no longer erases the first.**
|
|
282
|
+
`addHTTPMiddleware`, `addTagMiddleware` and `addChannelMiddleware` groups are
|
|
283
|
+
keyed by pattern or tag and held one source file each, so a second file's call
|
|
284
|
+
overwrote the first's. Codegen emits its imports from what is stored, so the
|
|
285
|
+
losing file was never imported and its middleware never registered — the
|
|
286
|
+
runtime composes repeated registrations for a pattern happily, and only codegen
|
|
287
|
+
dropped one. Adding an unrelated `addHTTPMiddleware('*', …)` to an app was
|
|
288
|
+
enough to silently unregister the generated better-auth session bridge, which
|
|
289
|
+
fails open and gives no sign until a request arrives without a session. A group
|
|
290
|
+
now carries every registration made for it, and all of them are imported.
|
|
291
|
+
|
|
292
|
+
- Updated dependencies [6a307f0]
|
|
293
|
+
- Updated dependencies [afef587]
|
|
294
|
+
- Updated dependencies [8075f6a]
|
|
295
|
+
- @pikku/core@0.12.74
|
|
296
|
+
|
|
1
297
|
## 0.12.5
|
|
2
298
|
|
|
3
299
|
### Patch Changes
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 - present Yasser Fadl and Pikku contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,28 @@
|
|
|
1
1
|
# @pikku/lambda
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
AWS Lambda runtime for Pikku — HTTP (API Gateway v1 and v2), WebSocket, SQS
|
|
4
|
+
queue and scheduled handlers, plus `SQSQueueService`.
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
npm install @pikku/lambda
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
import { runFetchV2 } from '@pikku/lambda'
|
|
16
|
+
import type { APIGatewayProxyEventV2 } from 'aws-lambda'
|
|
17
|
+
|
|
18
|
+
import './.pikku/pikku-bootstrap.gen.js'
|
|
19
|
+
|
|
20
|
+
export const handler = async (event: APIGatewayProxyEventV2) =>
|
|
21
|
+
runFetchV2(event)
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Use `@pikku/deploy-serverless` to generate the matching `serverless.yml`.
|
|
25
|
+
|
|
26
|
+
## Docs
|
|
27
|
+
|
|
28
|
+
https://pikku.dev/docs
|
package/dist/http/index.d.ts
CHANGED
package/dist/http/index.js
CHANGED
package/dist/http/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/http/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,mBAAmB,CAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/http/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,mBAAmB,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LambdaClient, InvokeCommand } from '@aws-sdk/client-lambda';
|
|
2
|
-
import {
|
|
2
|
+
import { buildRemoteHeaders } from '@pikku/core/remote';
|
|
3
3
|
export class LambdaDeploymentService {
|
|
4
4
|
jwt;
|
|
5
5
|
secrets;
|
|
@@ -20,27 +20,7 @@ export class LambdaDeploymentService {
|
|
|
20
20
|
throw new Error(`No Lambda binding for function '${funcName}'. ` +
|
|
21
21
|
`Available bindings: ${[...this.bindings.keys()].join(', ')}`);
|
|
22
22
|
}
|
|
23
|
-
const headers =
|
|
24
|
-
'content-type': 'application/json',
|
|
25
|
-
...(traceId && { 'x-request-id': traceId }),
|
|
26
|
-
};
|
|
27
|
-
let secret;
|
|
28
|
-
try {
|
|
29
|
-
secret = await this.secrets.getSecret('PIKKU_REMOTE_SECRET');
|
|
30
|
-
}
|
|
31
|
-
catch { }
|
|
32
|
-
if (secret && this.jwt) {
|
|
33
|
-
const sessionEnc = session
|
|
34
|
-
? await encryptJSON(secret, { session })
|
|
35
|
-
: undefined;
|
|
36
|
-
const token = await this.jwt.encode({ value: 5, unit: 'minute' }, {
|
|
37
|
-
aud: 'pikku-remote',
|
|
38
|
-
fn: funcName,
|
|
39
|
-
iat: Math.floor(Date.now() / 1000),
|
|
40
|
-
session: sessionEnc,
|
|
41
|
-
});
|
|
42
|
-
headers.authorization = `Bearer ${token}`;
|
|
43
|
-
}
|
|
23
|
+
const headers = await buildRemoteHeaders(this.jwt, this.secrets, funcName, session, traceId);
|
|
44
24
|
const rpcPath = `/remote/rpc/${encodeURIComponent(funcName)}`;
|
|
45
25
|
const apiGatewayEvent = {
|
|
46
26
|
httpMethod: 'POST',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lambda-deployment-service.js","sourceRoot":"","sources":["../src/lambda-deployment-service.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AAIpE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"lambda-deployment-service.js","sourceRoot":"","sources":["../src/lambda-deployment-service.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AAIpE,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AAEvD,MAAM,OAAO,uBAAuB;IAKxB;IACA;IALF,MAAM,CAAc;IACpB,QAAQ,CAAqB;IAErC,YACU,GAA2B,EAC3B,OAAsB,EAC9B,gBAAwC;QAFhC,QAAG,GAAH,GAAG,CAAwB;QAC3B,YAAO,GAAP,OAAO,CAAe;QAG9B,IAAI,CAAC,MAAM,GAAG,IAAI,YAAY,CAAC,EAAE,CAAC,CAAA;QAClC,IAAI,CAAC,QAAQ,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAA;IAC3D,CAAC;IAED,KAAK,CAAC,IAAI,KAAmB,CAAC;IAC9B,KAAK,CAAC,KAAK,CAAC,OAAyB,IAAkB,CAAC;IACxD,KAAK,CAAC,IAAI,KAA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,IAAI,QAAQ,CAAC,aAAa,EAAE,CAAC;YAC3B,MAAM,YAAY,GAAG,QAAQ,CAAC,OAAO;gBACnC,CAAC,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC;gBAC5C,CAAC,CAAC,eAAe,CAAA;YACnB,MAAM,IAAI,KAAK,CACb,uBAAuB,QAAQ,2BAA2B,YAAY,EAAE,CACzE,CAAA;QACH,CAAC;QAED,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CAAC,uBAAuB,QAAQ,uBAAuB,CAAC,CAAA;QACzE,CAAC;QAGD,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAA;QAE3E,IAAI,YAAY,CAAC,UAAU,IAAI,YAAY,CAAC,UAAU,IAAI,GAAG,EAAE,CAAC;YAC9D,MAAM,IAAI,KAAK,CACb,uBAAuB,QAAQ,aAAa,YAAY,CAAC,UAAU,IAAI,YAAY,CAAC,IAAI,EAAE,CAC3F,CAAA;QACH,CAAC;QAGD,MAAM,IAAI,GAAG,YAAY,CAAC,IAAI,CAAA;QAC9B,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;QACzB,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,IAAI,CAAA;QACb,CAAC;IACH,CAAC;CACF"}
|
package/dist/websocket/utils.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ApiGatewayManagementApiClient, PostToConnectionCommand, } from '@aws-sdk/client-apigatewaymanagementapi';
|
|
2
|
-
import { getSingletonServices } from '@pikku/core';
|
|
2
|
+
import { getSingletonServices } from '@pikku/core/ecosystem';
|
|
3
3
|
import { createLambdaChannelHandlerFactory } from './lambda-channel-handler.js';
|
|
4
4
|
export const sendMessage = async (logger, callbackAPI, ConnectionId, Data) => {
|
|
5
5
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/websocket/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,6BAA6B,EAC7B,uBAAuB,GACxB,MAAM,yCAAyC,CAAA;AAEhD,OAAO,EAAE,oBAAoB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/websocket/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,6BAA6B,EAC7B,uBAAuB,GACxB,MAAM,yCAAyC,CAAA;AAEhD,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAA;AAE5D,OAAO,EAAE,iCAAiC,EAAE,MAAM,6BAA6B,CAAA;AAG/E,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,EAC9B,MAAc,EACd,WAA0C,EAC1C,YAAoB,EACpB,IAAY,EACM,EAAE;IACpB,IAAI,CAAC;QACH,MAAM,WAAW,CAAC,IAAI,CAAC,IAAI,uBAAuB,CAAC,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;QAC3E,OAAO,IAAI,CAAA;IACb,CAAC;IAAC,OAAO,CAAM,EAAE,CAAC;QAGhB,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAA;QACvB,OAAO,KAAK,CAAA;IACd,CAAC;AACH,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,EAC/B,MAAc,EACd,YAA0B,EAC1B,WAA0C,EAC1C,aAAqB,EACrB,UAAoB,EACpB,IAAa,EACb,QAAkB,EACH,EAAE;IACjB,IAAI,QAAQ,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAA;IACvE,CAAC;IACD,MAAM,eAAe,GAAa,EAAE,CAAA;IACpC,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAA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,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,yBAAyB,GAAG,CACvC,YAA0B,EAC1B,KAAsB,EACtB,EAAE;IACF,MAAM,EAAE,MAAM,EAAE,GAAG,oBAAoB,EAAE,CAAA;IACzC,MAAM,SAAS,GAAG,KAAK,CAAC,cAAc,CAAC,YAAY,CAAA;IACnD,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAA;IAC5D,CAAC;IACD,MAAM,WAAW,GAAG,gCAAgC,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;IACnE,MAAM,qBAAqB,GAAG,iCAAiC,CAC7D,MAAM,EACN,YAAY,EACZ,WAAW,CACZ,CAAA;IACD,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,qBAAqB,EAAE,YAAY,EAAE,CAAA;AACxE,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pikku/lambda",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.7",
|
|
4
|
+
"description": "AWS Lambda runtime for Pikku — HTTP, WebSocket, SQS queue and scheduled handlers",
|
|
4
5
|
"license": "MIT",
|
|
5
6
|
"author": "yasser.fadl@gmail.com",
|
|
6
7
|
"module": "dist/index.js",
|
|
@@ -27,7 +28,7 @@
|
|
|
27
28
|
"@aws-sdk/client-apigatewaymanagementapi": "^3.713.0",
|
|
28
29
|
"@aws-sdk/client-lambda": "^3.713.0",
|
|
29
30
|
"@aws-sdk/client-sqs": "^3.713.0",
|
|
30
|
-
"@pikku/core": "^0.12.
|
|
31
|
+
"@pikku/core": "^0.12.82",
|
|
31
32
|
"@types/aws-lambda": "^8.10.161"
|
|
32
33
|
},
|
|
33
34
|
"devDependencies": {
|
package/src/http/index.ts
CHANGED
|
@@ -13,7 +13,7 @@ import { LambdaClient, InvokeCommand } from '@aws-sdk/client-lambda'
|
|
|
13
13
|
import type { DeploymentService, DeploymentConfig } from '@pikku/core/services'
|
|
14
14
|
import type { JWTService } from '@pikku/core/services'
|
|
15
15
|
import type { SecretService } from '@pikku/core/services'
|
|
16
|
-
import {
|
|
16
|
+
import { buildRemoteHeaders } from '@pikku/core/remote'
|
|
17
17
|
|
|
18
18
|
export class LambdaDeploymentService implements DeploymentService {
|
|
19
19
|
private client: LambdaClient
|
|
@@ -46,32 +46,13 @@ export class LambdaDeploymentService implements DeploymentService {
|
|
|
46
46
|
)
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
const headers
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
try {
|
|
57
|
-
secret = await this.secrets.getSecret('PIKKU_REMOTE_SECRET')
|
|
58
|
-
} catch {}
|
|
59
|
-
|
|
60
|
-
if (secret && this.jwt) {
|
|
61
|
-
const sessionEnc = session
|
|
62
|
-
? await encryptJSON(secret, { session })
|
|
63
|
-
: undefined
|
|
64
|
-
const token = await this.jwt.encode(
|
|
65
|
-
{ value: 5, unit: 'minute' },
|
|
66
|
-
{
|
|
67
|
-
aud: 'pikku-remote',
|
|
68
|
-
fn: funcName,
|
|
69
|
-
iat: Math.floor(Date.now() / 1000),
|
|
70
|
-
session: sessionEnc,
|
|
71
|
-
}
|
|
72
|
-
)
|
|
73
|
-
headers.authorization = `Bearer ${token}`
|
|
74
|
-
}
|
|
49
|
+
const headers = await buildRemoteHeaders(
|
|
50
|
+
this.jwt,
|
|
51
|
+
this.secrets,
|
|
52
|
+
funcName,
|
|
53
|
+
session,
|
|
54
|
+
traceId
|
|
55
|
+
)
|
|
75
56
|
|
|
76
57
|
// Build an API Gateway v2 event for the target Lambda
|
|
77
58
|
const rpcPath = `/remote/rpc/${encodeURIComponent(funcName)}`
|
package/src/websocket/utils.ts
CHANGED
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
PostToConnectionCommand,
|
|
4
4
|
} from '@aws-sdk/client-apigatewaymanagementapi'
|
|
5
5
|
import type { Logger } from '@pikku/core/services'
|
|
6
|
-
import { getSingletonServices } from '@pikku/core'
|
|
6
|
+
import { getSingletonServices } from '@pikku/core/ecosystem'
|
|
7
7
|
import type { APIGatewayEvent } from 'aws-lambda'
|
|
8
8
|
import { createLambdaChannelHandlerFactory } from './lambda-channel-handler.js'
|
|
9
9
|
import type { ChannelStore } from '@pikku/core/channel'
|