@layers/amba 4.0.3 → 4.0.4

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.
@@ -277,6 +277,9 @@ export interface FunctionDeploymentRow {
277
277
  bundle_sha: string;
278
278
  status: 'active' | 'superseded' | 'disabled';
279
279
  created_at: string;
280
+ /** Opt-in public flag (#17). True = X-Api-Key gate skipped for this
281
+ * function so external webhook senders can reach it. Default false. */
282
+ is_public?: boolean;
280
283
  }
281
284
  export declare function recordFunctionDeployment(projectId: string, input: {
282
285
  name: string;
@@ -310,6 +313,13 @@ export declare function deployFunctionViaApi(projectId: string, input: {
310
313
  max: number;
311
314
  key: 'user_id' | 'ip';
312
315
  } | null;
316
+ /**
317
+ * Opt-in public flag (#17). When true, the edge runtime skips the
318
+ * X-Api-Key gate for this function so third-party webhook senders can
319
+ * reach it. Default false (private). The customer verifies the webhook
320
+ * HMAC inside the handler.
321
+ */
322
+ public?: boolean;
313
323
  }): Promise<DeployFunctionResult>;
314
324
  export declare function listFunctionDeployments(projectId: string, options?: {
315
325
  activeOnly?: boolean;
@@ -379,6 +389,7 @@ export declare function getFunctionLogs(projectId: string, functionName: string,
379
389
  since?: string;
380
390
  until?: string;
381
391
  limit?: number;
392
+ requestId?: string;
382
393
  }): Promise<ApiResponse<FunctionLogsResponse>>;
383
394
  export interface QueueBinding {
384
395
  queue_name: string;
@@ -757,6 +768,27 @@ export declare function updateSiteDomain(projectId: string, siteName: string, ho
757
768
  export declare function detachSiteDomain(projectId: string, siteName: string, hostname: string): Promise<ApiResponse<{
758
769
  deleted: boolean;
759
770
  }>>;
771
+ /** A declarative promotion bundle. Section keys are all optional. */
772
+ export interface PromotionBundleWire {
773
+ version: number;
774
+ exported_at: string;
775
+ [section: string]: unknown;
776
+ }
777
+ /** `{ created, updated, skipped }` counts for one bundle section. */
778
+ export interface PromotionSectionSummary {
779
+ created: number;
780
+ updated: number;
781
+ skipped: number;
782
+ }
783
+ export type PromotionImportMode = 'merge' | 'skip_existing';
784
+ export interface PromotionImportResult {
785
+ mode: PromotionImportMode;
786
+ summary: Record<string, PromotionSectionSummary>;
787
+ }
788
+ /** GET the current project's declarative configuration bundle. */
789
+ export declare function exportPromotionBundle(projectId: string): Promise<ApiResponse<PromotionBundleWire>>;
790
+ /** POST a declarative bundle to import it into the project. */
791
+ export declare function importPromotionBundle(projectId: string, bundle: PromotionBundleWire, mode: PromotionImportMode): Promise<ApiResponse<PromotionImportResult>>;
760
792
  export declare function validateApiKey(apiKey: string): Promise<{
761
793
  valid: false;
762
794
  error: string;
package/dist/bundle.d.ts CHANGED
@@ -23,6 +23,25 @@
23
23
  * empty; customer code is expected to be self-contained.
24
24
  */
25
25
  import { type BuildOptions } from 'esbuild';
26
+ /**
27
+ * Conventional entry-point filenames probed (in order) when
28
+ * `amba functions deploy <dir>` is pointed at a directory rather than a
29
+ * single file. Mirrors the Node / bundler convention (`index.*`) so a
30
+ * developer can `amba functions deploy ./my-fn` with an `index.ts` inside.
31
+ */
32
+ export declare const FUNCTION_ENTRY_CANDIDATES: readonly string[];
33
+ /**
34
+ * Resolve the bundler entry point from a deploy target that may be either a
35
+ * single file OR a directory.
36
+ *
37
+ * - File → returned as-is (single-file back-compat path).
38
+ * - Dir → resolved by convention to `index.{ts,js,mjs}`, or to an
39
+ * explicit `entry` (relative to the directory) when provided.
40
+ *
41
+ * Throws an actionable error when the target doesn't exist, or when a
42
+ * directory has no resolvable entry point (and no `--entry` was passed).
43
+ */
44
+ export declare function resolveFunctionEntry(target: string, explicitEntry?: string): Promise<string>;
26
45
  /**
27
46
  * Modules the bundler treats as `external` by default. The Amba
28
47
  * function runtime exposes zero npm packages — there is no "platform
@@ -46,6 +65,62 @@ export declare class BundleSizeError extends Error {
46
65
  readonly maxBytes: number;
47
66
  constructor(sizeBytes: number, maxBytes: number);
48
67
  }
68
+ /**
69
+ * The single source-of-truth message for the wrong-handler-shape failure.
70
+ * Shared between the CLI bundler (pre-upload), the local `dev` runner, and
71
+ * the server-side deploy hint so dev / deploy / prod all describe the fix
72
+ * identically. Customer functions run as Module Workers; the legacy
73
+ * service-worker shape (`export default async function (req) { … }`) is
74
+ * rejected by the runtime at upload, so we reject it before the round-trip.
75
+ */
76
+ export declare const HANDLER_SHAPE_FIX_MESSAGE: string;
77
+ /** Message used when the entry file has no `export default` at all. */
78
+ export declare const HANDLER_SHAPE_MISSING_DEFAULT_MESSAGE: string;
79
+ /** Message used when the default export is present but has no `fetch` method. */
80
+ export declare const HANDLER_SHAPE_NO_FETCH_MESSAGE: string;
81
+ /**
82
+ * Thrown when the bundled entry's `export default` is not the Module Worker
83
+ * shape (`{ fetch(req, env, ctx) }`). Raised BEFORE any upload so a wrong
84
+ * handler shape fails fast on the developer's machine with an actionable
85
+ * message instead of an opaque upstream rejection at deploy time.
86
+ */
87
+ export declare class HandlerShapeError extends Error {
88
+ readonly kind: 'plain-function' | 'missing-default' | 'no-fetch';
89
+ constructor(message: string, kind: 'plain-function' | 'missing-default' | 'no-fetch');
90
+ }
91
+ /**
92
+ * Inspect an already-imported module namespace and assert it has the
93
+ * Module Worker handler shape: a default export that is an object (or
94
+ * function-with-properties) carrying a callable `fetch`.
95
+ *
96
+ * Pure + side-effect free — it only reads the shape of `mod.default`, never
97
+ * invokes `fetch`. This is the unit-testable core; `assertModuleWorkerShape`
98
+ * wraps the import-from-code plumbing around it.
99
+ *
100
+ * Throws `HandlerShapeError` on:
101
+ * - no default export (`missing-default`)
102
+ * - a default-exported plain function — the legacy service-worker shape
103
+ * (`plain-function`)
104
+ * - a default export with no callable `fetch` (`no-fetch`)
105
+ */
106
+ export declare function assertHandlerShape(mod: {
107
+ default?: unknown;
108
+ }): void;
109
+ /**
110
+ * Validate that the bundled customer code exports the Module Worker handler
111
+ * shape, by importing it in isolation and inspecting `mod.default`.
112
+ *
113
+ * Mechanism: write the bundle to a throwaway temp `.mjs` and dynamic-import
114
+ * it, then hand the namespace to `assertHandlerShape`. This is the same
115
+ * import-and-inspect approach the local `dev` runner uses
116
+ * (`functions.ts` DEV_RUNNER_SOURCE) — reused here so the pre-upload check
117
+ * and the dev runner agree on what "valid shape" means. Importing runs the
118
+ * module's top-level code (unavoidable to read the export), but the handler
119
+ * itself is NEVER invoked — we only read the shape of the exported object.
120
+ *
121
+ * The temp file is always cleaned up (best-effort) before returning.
122
+ */
123
+ export declare function assertModuleWorkerShape(code: string): Promise<void>;
49
124
  export interface BundleResult {
50
125
  /** The bundled JS source (UTF-8). */
51
126
  code: string;
@@ -67,6 +142,17 @@ export interface BundleOptions {
67
142
  extraExternals?: string[];
68
143
  /** Source map handling. Default: inline. */
69
144
  sourcemap?: BuildOptions['sourcemap'];
145
+ /**
146
+ * Validate the bundled entry exports the Module Worker handler shape
147
+ * (`export default { async fetch(req, env, ctx) { … } }`) before
148
+ * returning, throwing `HandlerShapeError` if not. Default: true.
149
+ *
150
+ * The check imports the bundle in isolation to inspect `mod.default`;
151
+ * it never invokes the handler. Both `deploy` and `dev` leave this on so
152
+ * a function that bundles in `dev` cannot fail the shape check in
153
+ * `deploy` (dev / prod parity).
154
+ */
155
+ validateHandlerShape?: boolean;
70
156
  }
71
157
  /**
72
158
  * Bundle a customer function file for upload to a Workers dispatch
@@ -26,5 +26,7 @@ export interface FunctionsLogsOptions {
26
26
  tail?: boolean;
27
27
  /** NDJSON output. */
28
28
  json?: boolean;
29
+ /** Only show events whose log/exception text mentions this request id (`r_...`). */
30
+ requestId?: string;
29
31
  }
30
32
  export declare function functionsLogsCommand(functionName: string, options?: FunctionsLogsOptions): Promise<void>;
@@ -9,8 +9,19 @@
9
9
  */
10
10
  import { type RateLimitConfig } from '../_internal/shared.js';
11
11
  export interface DeployOptions {
12
- /** Override the function name. Default: filename without extension. */
12
+ /**
13
+ * Override the function name. Default: when a file is deployed, the
14
+ * filename without extension; when a directory is deployed, the
15
+ * directory's leaf name (NOT the resolved `index` entry's name).
16
+ */
13
17
  name?: string;
18
+ /**
19
+ * Entry file when the deploy target is a DIRECTORY (relative to it).
20
+ * Only valid with a directory target; ignored for single-file deploys.
21
+ * When omitted, a directory resolves its entry by convention
22
+ * (`index.ts` / `index.js` / `index.mjs`).
23
+ */
24
+ entry?: string;
14
25
  /** Print bundle report but skip the CF API + DB write. Useful for size triage. */
15
26
  dryRun?: boolean;
16
27
  /**
@@ -23,8 +34,16 @@ export interface DeployOptions {
23
34
  rateLimitWindow?: string;
24
35
  rateLimitMax?: number;
25
36
  rateLimitKey?: string;
37
+ /**
38
+ * Opt-in public flag (#17). Deploy the function WITHOUT the X-Api-Key
39
+ * gate so third-party webhook senders (Stripe, RevenueCat, GitHub,
40
+ * Slack) that can't attach a custom header can reach it. Default false
41
+ * (private). The customer MUST verify the webhook HMAC signature inside
42
+ * the handler — public skips the credential gate only.
43
+ */
44
+ public?: boolean;
26
45
  }
27
- export declare function functionsDeployCommand(entryPoint: string, options?: DeployOptions): Promise<void>;
46
+ export declare function functionsDeployCommand(target: string, options?: DeployOptions): Promise<void>;
28
47
  export declare function functionsListCommand(): Promise<void>;
29
48
  export declare function functionsDeleteCommand(name: string, options?: {
30
49
  confirm?: string;
@@ -0,0 +1,116 @@
1
+ /**
2
+ * `amba apply` / `amba diff` / `amba export` — declarative
3
+ * infrastructure-as-code for a project's reusable configuration.
4
+ *
5
+ * A declarative bundle (default `amba.config.json`) captures the entities a
6
+ * developer hand-builds once and wants to stand up identically elsewhere:
7
+ * remote configs, collection schemas, content libraries + items, currencies,
8
+ * achievements, streaks, challenges, leaderboards, and xp_rules. It carries
9
+ * CONFIGURATION ONLY — no secrets, no per-user data.
10
+ *
11
+ * These commands wrap the platform's promotion endpoints:
12
+ * GET /v1/admin/projects/:p/promotion/export
13
+ * POST /v1/admin/projects/:p/promotion/import (mode=skip_existing|merge)
14
+ *
15
+ * - `amba export [file]` writes the current project's bundle to disk.
16
+ * - `amba apply [file]` POSTs the local bundle to the import endpoint and
17
+ * prints a `{ created, updated, skipped }` summary
18
+ * per section (the server's authoritative result).
19
+ * - `amba diff [file]` shows what `apply` WOULD change without writing.
20
+ * The import route has NO server-side dry-run, so
21
+ * `diff` exports the current project and computes the
22
+ * created/updated/skipped per section LOCALLY.
23
+ */
24
+ import { type PromotionBundleWire, type PromotionImportMode } from '../api-client.js';
25
+ /** Default declarative bundle filename when no `[file]` is passed. */
26
+ export declare const DEFAULT_BUNDLE_FILE = "amba.config.json";
27
+ export interface ApplyOptions {
28
+ project?: string;
29
+ /** `skip_existing` (default) no-ops on conflict; `merge` refreshes. */
30
+ mode?: PromotionImportMode;
31
+ }
32
+ export interface DiffOptions {
33
+ project?: string;
34
+ mode?: PromotionImportMode;
35
+ }
36
+ export interface ExportOptions {
37
+ project?: string;
38
+ }
39
+ /** Per-section, per-key diff outcome. */
40
+ export interface SectionDiff {
41
+ created: number;
42
+ updated: number;
43
+ skipped: number;
44
+ }
45
+ export type LocalDiff = Record<string, SectionDiff>;
46
+ /**
47
+ * Read + parse a declarative bundle from disk. JSON only — we deliberately
48
+ * don't pull in a YAML dependency the CLI doesn't already ship (the package
49
+ * has no YAML lib), so `.yaml`/`.yml` files are rejected with a clear hint
50
+ * rather than silently mis-parsed.
51
+ */
52
+ export declare function readBundleFile(file: string): Promise<PromotionBundleWire>;
53
+ /**
54
+ * Pure section-by-section diff of a desired bundle against the current
55
+ * project's exported bundle. The classification MIRRORS the server's import
56
+ * (`apps/api/src/lib/promotion-bundle.ts`) so `amba diff` agrees with what
57
+ * `amba apply` will report:
58
+ * - created — natural key absent in current.
59
+ * - updated — natural key present AND `mode === 'merge'`. The server runs an
60
+ * UNCONDITIONAL update for every existing key in merge mode and
61
+ * increments `updated` — it does NOT compare field values, so we
62
+ * don't either (a local field comparison made `diff` under-report).
63
+ * - skipped — natural key present under `skip_existing`; OR an existing
64
+ * collection (always — collections are create-if-absent, never
65
+ * merged); OR a `remote_configs` row flagged `is_system: true`
66
+ * (the server always skips those before any existence check); OR
67
+ * a desired row with no valid natural key (can't be matched
68
+ * against the export, and the server import dedups by that key —
69
+ * so it is never a reliable create).
70
+ *
71
+ * Within one bundle section, the server walks rows sequentially and each
72
+ * insert mutates the DB, so a SECOND row sharing a natural key already created
73
+ * by an EARLIER row in the same section is seen as existing (→ skip under
74
+ * skip_existing, update under merge) rather than created a second time. We
75
+ * track already-seen keys per section to mirror that, so duplicate-keyed local
76
+ * rows don't inflate the `created` total versus what `apply` does.
77
+ */
78
+ export declare function computeLocalDiff(desired: PromotionBundleWire, current: PromotionBundleWire, mode: PromotionImportMode): LocalDiff;
79
+ declare function totalOf(s: {
80
+ created: number;
81
+ updated: number;
82
+ skipped: number;
83
+ }): number;
84
+ /** Roll a per-section diff up into grand totals across every section. */
85
+ export declare function summarizeDiff(diff: Record<string, SectionDiff>): SectionDiff;
86
+ /**
87
+ * `amba export [file]` — write the current project's declarative bundle to
88
+ * disk so it can be checked in, diffed, and re-applied.
89
+ */
90
+ export declare function exportConfigCommand(file?: string, options?: ExportOptions): Promise<void>;
91
+ /**
92
+ * `amba apply [file]` — read a local declarative bundle and POST it to the
93
+ * import endpoint. Prints the server's authoritative `{ created, updated,
94
+ * skipped }` per section.
95
+ */
96
+ export declare function applyConfigCommand(file?: string, options?: ApplyOptions): Promise<void>;
97
+ /**
98
+ * `amba diff [file]` — show what `apply` WOULD change without writing.
99
+ *
100
+ * The import route has no server-side dry-run, so this fetches the current
101
+ * project's exported bundle and computes the diff LOCALLY. Output mirrors the
102
+ * `apply` summary shape so the two read identically.
103
+ */
104
+ export declare function diffConfigCommand(file?: string, options?: DiffOptions): Promise<void>;
105
+ /** Test-only re-export of internal helpers. Not a public API. */
106
+ export declare const __testHelpers: {
107
+ computeLocalDiff: typeof computeLocalDiff;
108
+ summarizeDiff: typeof summarizeDiff;
109
+ readBundleFile: typeof readBundleFile;
110
+ BUNDLE_SECTIONS: readonly {
111
+ key: string;
112
+ naturalKey: string;
113
+ }[];
114
+ totalOf: typeof totalOf;
115
+ };
116
+ export {};
@@ -0,0 +1,36 @@
1
+ /**
2
+ * `amba monetization *` subcommands — CLI access to the monetization control
3
+ * plane behind `/v1/admin/projects/:id/monetization/*`.
4
+ *
5
+ * amba monetization plan — three-way diff (declared vs adopted baseline
6
+ * vs live provider) + store-floor preflight +
7
+ * drift. READ-ONLY — previews; applies nothing.
8
+ * amba monetization drift — out-of-band changes to Amba-managed objects.
9
+ * amba monetization export — snapshot the live config to a declarative
10
+ * bundle (the `monetization` section), to stdout
11
+ * or a file.
12
+ * amba monetization adopt — record the live config as the managed baseline
13
+ * so the next plan is a no-op. Writes ONLY Amba's
14
+ * own state — never the provider. Idempotent.
15
+ * amba monetization apply — push the declared config to the provider.
16
+ * ADDITIVE only: create entitlements/offerings/
17
+ * packages/paywall-drafts + attach products.
18
+ * Refuses if the provider drifted since the plan;
19
+ * never does destructive changes.
20
+ *
21
+ * Project is resolved via `loadProjectConfig` — same pattern as the other
22
+ * project-scoped CLI commands.
23
+ */
24
+ export declare function monetizationPlanCommand(): Promise<void>;
25
+ export declare function monetizationDriftCommand(): Promise<void>;
26
+ export declare function monetizationExportCommand(options?: {
27
+ file?: string;
28
+ }): Promise<void>;
29
+ export declare function monetizationAdoptCommand(options?: {
30
+ all?: boolean;
31
+ }): Promise<void>;
32
+ export declare function monetizationApplyCommand(options?: {
33
+ confirm?: boolean;
34
+ allowDetachLive?: boolean;
35
+ reconcile?: string;
36
+ }): Promise<void>;
@@ -0,0 +1,33 @@
1
+ /**
2
+ * `amba payments *` subcommands — CLI access to the Amba Payments (Stripe
3
+ * Connect platform) surface at `/v1/admin/projects/:id/payments/*`
4
+ * (tracker #10).
5
+ *
6
+ * Amba is the payments rail for the developer's app: the app is the seller,
7
+ * Amba takes a platform fee, Stripe carries money-transmission. This is the
8
+ * developer-facing onboarding + config + reporting surface, so naming Stripe
9
+ * here is by intent (same as `amba billing`).
10
+ *
11
+ * amba payments setup — create the connected account +
12
+ * print the hosted onboarding URL.
13
+ * amba payments status — onboarding stage + capability flags.
14
+ * amba payments set-fee <bps|off> — default platform fee (basis points).
15
+ * amba payments balance — connected-account balance.
16
+ * amba payments payouts — recent payouts.
17
+ *
18
+ * Every live call is gated by the platform's PAYMENTS_CONNECT_LIVE
19
+ * kill-switch — when off the API returns PAYMENTS_NOT_ENABLED, surfaced
20
+ * verbatim here. Project resolved via loadProjectConfig (same as billing).
21
+ */
22
+ export declare function paymentsSetupCommand(input: {
23
+ country?: string;
24
+ email?: string;
25
+ }): Promise<void>;
26
+ export declare function paymentsStatusCommand(): Promise<void>;
27
+ export declare function paymentsSetFeeCommand(input: {
28
+ bps: number | null;
29
+ }): Promise<void>;
30
+ export declare function paymentsBalanceCommand(): Promise<void>;
31
+ export declare function paymentsPayoutsCommand(input: {
32
+ limit?: number;
33
+ }): Promise<void>;