@assembly-js/app-foundation 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -17,6 +17,9 @@ bullets ship. Write `[fix]`, `[behavior]` and `[action]` bullets for the app's o
17
17
  A patch release never changes what an app's build requires; a minor release may add or change a
18
18
  `bin/check-*.mjs` script. CI fails a PR that changes a check script without a minor bump over main.
19
19
 
20
+ ## 0.2.1
21
+ - [new] Add `@assembly-js/app-foundation/scripts`, which exports `getOfflineAssembly` without `server-only`, for seed and backfill scripts that run outside Next.
22
+
20
23
  ## 0.2.0
21
24
  - [behavior] At the end of every turn the platform compares the operations documented in `.assembly/openapi.json` with the app's API routes and warns the build agent on its next turn about any it cannot find. Nothing in the app changes and the build is unaffected.
22
25
 
@@ -0,0 +1,8 @@
1
+ import { type AssemblyAPI } from '@assembly-js/node-sdk';
2
+ /**
3
+ * The script-side counterpart of `getOfflineAssembly` from `/server`: mints a
4
+ * short-lived app-scoped bearer from `ASSEMBLY_API_KEY` and returns a bearer-only
5
+ * client. There is no request here, so the viewer-identity guard `/server` applies
6
+ * does not exist; use this only from scripts, never from code under `app/`.
7
+ */
8
+ export declare function getOfflineAssembly(): Promise<AssemblyAPI>;
@@ -0,0 +1,24 @@
1
+ // Entry point for standalone scripts (seed, backfill, one-off jobs) run with plain
2
+ // `bun`/`node` outside Next. It must not import './server.js', './assembly' or anything
3
+ // else that reaches `server-only` or `next/*`, which throw outside a Next bundle.
4
+ import { assemblyApi } from '@assembly-js/node-sdk';
5
+ import { mintBearerFromAppKey } from './mint-bearer.js';
6
+ /**
7
+ * The script-side counterpart of `getOfflineAssembly` from `/server`: mints a
8
+ * short-lived app-scoped bearer from `ASSEMBLY_API_KEY` and returns a bearer-only
9
+ * client. There is no request here, so the viewer-identity guard `/server` applies
10
+ * does not exist; use this only from scripts, never from code under `app/`.
11
+ */
12
+ export async function getOfflineAssembly() {
13
+ if (!process.env.ASSEMBLY_API_KEY) {
14
+ throw new Error('getOfflineAssembly: ASSEMBLY_API_KEY is not set — cannot mint an app-scoped bearer');
15
+ }
16
+ const minted = await mintBearerFromAppKey();
17
+ if (!minted) {
18
+ throw new Error('getOfflineAssembly: failed to mint an app-scoped bearer from the app API key');
19
+ }
20
+ return assemblyApi({
21
+ bearer: minted.bearer,
22
+ baseUrl: process.env.ASSEMBLY_API_BASE_URL || undefined,
23
+ });
24
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@assembly-js/app-foundation",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Versioned foundation helpers and build context for Assembly generated apps",
5
5
  "type": "module",
6
6
  "files": [
@@ -24,6 +24,10 @@
24
24
  "types": "./dist/lib-client.d.ts",
25
25
  "default": "./dist/lib-client.js"
26
26
  },
27
+ "./scripts": {
28
+ "types": "./dist/scripts.d.ts",
29
+ "default": "./dist/scripts.js"
30
+ },
27
31
  "./next": {
28
32
  "types": "./dist/next.d.ts",
29
33
  "default": "./dist/next.js"