@alva-ai/toolkit 0.14.0 → 0.15.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/dist/cli.d.ts CHANGED
@@ -188,6 +188,12 @@ interface CronjobCreateRequest {
188
188
  push_notify?: boolean;
189
189
  /** Override per-cronjob V8 heap limit (MB). Valid range 1–2046. */
190
190
  max_heap_size_mb?: number;
191
+ /**
192
+ * Run the cronjob under a restricted service-account identity (an SA id
193
+ * owned by the caller) instead of the owner (#602). Omitted ⇒ runs as owner.
194
+ * A string: SA ids are snowflake int64s that overflow JS number precision.
195
+ */
196
+ run_as_user_id?: string;
191
197
  }
192
198
  interface Cronjob {
193
199
  id: number;
@@ -199,6 +205,11 @@ interface Cronjob {
199
205
  push_notify: boolean;
200
206
  /** Per-cronjob V8 heap cap (MB). null when using the server default. */
201
207
  max_heap_size_mb: number | null;
208
+ /**
209
+ * SA id the cronjob runs as, or "0" when it runs as the owner (#602).
210
+ * A string: snowflake int64 ids overflow JS number precision.
211
+ */
212
+ run_as_user_id: string;
202
213
  created_at: string;
203
214
  updated_at: string;
204
215
  }
@@ -218,6 +229,12 @@ interface CronjobUpdateRequest {
218
229
  push_notify?: boolean;
219
230
  /** Override per-cronjob V8 heap limit (MB). Valid range 1–2046. */
220
231
  max_heap_size_mb?: number;
232
+ /**
233
+ * Re-point the cronjob at a service-account identity, or "0" to clear it back
234
+ * to the owner (#602). Omitted ⇒ run_as unchanged.
235
+ * A string: SA ids are snowflake int64s that overflow JS number precision.
236
+ */
237
+ run_as_user_id?: string;
221
238
  }
222
239
  interface CronjobRunsListParams {
223
240
  cronjob_id: number;
@@ -850,6 +867,27 @@ interface ChannelGroupSubscriptionMutationResponse {
850
867
  admin: ChannelGroupAdminInfo | null;
851
868
  subscriptions: ChannelGroupSubscription[];
852
869
  }
870
+ interface ServiceAccount {
871
+ id: string;
872
+ display_name: string;
873
+ username: string;
874
+ parent_user_id: string;
875
+ created_at?: number;
876
+ }
877
+ interface ServiceAccountCreateRequest {
878
+ display_name: string;
879
+ }
880
+ interface ServiceAccountCreateResponse {
881
+ service_account: ServiceAccount;
882
+ }
883
+ interface ServiceAccountListResponse {
884
+ service_accounts: ServiceAccount[];
885
+ }
886
+ interface ServiceAccountGrantRequest {
887
+ id: string;
888
+ path: string;
889
+ permission: string;
890
+ }
853
891
 
854
892
  declare class FsResource {
855
893
  private client;
@@ -923,6 +961,25 @@ declare class DeployResource {
923
961
  }): Promise<CronjobRunLogsResponse>;
924
962
  }
925
963
 
964
+ /**
965
+ * Service-account lifecycle: create a restricted run-as identity, list/delete
966
+ * the ones you own, and grant/revoke its ALFS paths. Set the resulting id as
967
+ * `--run-as-service-account` on a UDF or cronjob to run it under that scoped
968
+ * identity (billing/audit stay with you). See the service-accounts skill
969
+ * reference. Owner-gated by the backend — an SA cannot manage SAs.
970
+ */
971
+ declare class ServiceAccountResource {
972
+ private client;
973
+ constructor(client: AlvaClient);
974
+ create(params: ServiceAccountCreateRequest): Promise<ServiceAccountCreateResponse>;
975
+ list(): Promise<ServiceAccountListResponse>;
976
+ delete(params: {
977
+ id: string;
978
+ }): Promise<void>;
979
+ grant(params: ServiceAccountGrantRequest): Promise<void>;
980
+ revoke(params: ServiceAccountGrantRequest): Promise<void>;
981
+ }
982
+
926
983
  declare class ReleaseResource {
927
984
  private client;
928
985
  constructor(client: AlvaClient);
@@ -1455,6 +1512,13 @@ interface RegisterFunctionParams {
1455
1512
  entry_script_path: string;
1456
1513
  params_schema?: string;
1457
1514
  allow_charges?: boolean;
1515
+ /**
1516
+ * Run invocations of this function under a restricted service-account
1517
+ * identity (an SA id owned by the caller) instead of the owner (#602).
1518
+ * Omitted ⇒ runs as the owner. A string: SA ids are snowflake int64s that
1519
+ * overflow JS number precision.
1520
+ */
1521
+ run_as_user_id?: string;
1458
1522
  }
1459
1523
  interface RegisterFunctionResponse {
1460
1524
  function?: PlaybookFunction;
@@ -1573,6 +1637,7 @@ declare class AlvaClient {
1573
1637
  private _fs?;
1574
1638
  private _run?;
1575
1639
  private _deploy?;
1640
+ private _serviceAccount?;
1576
1641
  private _release?;
1577
1642
  private _feed?;
1578
1643
  private _playbooks?;
@@ -1598,6 +1663,7 @@ declare class AlvaClient {
1598
1663
  get fs(): FsResource;
1599
1664
  get run(): RunResource;
1600
1665
  get deploy(): DeployResource;
1666
+ get serviceAccount(): ServiceAccountResource;
1601
1667
  get release(): ReleaseResource;
1602
1668
  get feed(): FeedResource;
1603
1669
  get playbooks(): PlaybooksResource;
package/dist/cli.js CHANGED
@@ -9700,7 +9700,8 @@ var DeployResource = class {
9700
9700
  cron_expression: params.cron_expression,
9701
9701
  args: params.args,
9702
9702
  push_notify: params.push_notify,
9703
- max_heap_size_mb: params.max_heap_size_mb
9703
+ max_heap_size_mb: params.max_heap_size_mb,
9704
+ run_as_user_id: params.run_as_user_id
9704
9705
  }
9705
9706
  });
9706
9707
  }
@@ -9780,6 +9781,50 @@ var DeployResource = class {
9780
9781
  }
9781
9782
  };
9782
9783
 
9784
+ // src/resources/serviceAccount.ts
9785
+ var ServiceAccountResource = class {
9786
+ constructor(client) {
9787
+ this.client = client;
9788
+ }
9789
+ client;
9790
+ async create(params) {
9791
+ this.client._requireAuth();
9792
+ return this.client._request("POST", "/api/v1/service-account", {
9793
+ body: { display_name: params.display_name }
9794
+ });
9795
+ }
9796
+ async list() {
9797
+ this.client._requireAuth();
9798
+ return this.client._request(
9799
+ "GET",
9800
+ "/api/v1/service-accounts"
9801
+ );
9802
+ }
9803
+ async delete(params) {
9804
+ this.client._requireAuth();
9805
+ await this.client._request(
9806
+ "DELETE",
9807
+ `/api/v1/service-account/${params.id}`
9808
+ );
9809
+ }
9810
+ async grant(params) {
9811
+ this.client._requireAuth();
9812
+ await this.client._request(
9813
+ "POST",
9814
+ `/api/v1/service-account/${params.id}/grant`,
9815
+ { body: { path: params.path, permission: params.permission } }
9816
+ );
9817
+ }
9818
+ async revoke(params) {
9819
+ this.client._requireAuth();
9820
+ await this.client._request(
9821
+ "POST",
9822
+ `/api/v1/service-account/${params.id}/revoke`,
9823
+ { body: { path: params.path, permission: params.permission } }
9824
+ );
9825
+ }
9826
+ };
9827
+
9783
9828
  // src/resources/release.ts
9784
9829
  var ReleaseResource = class {
9785
9830
  constructor(client) {
@@ -11890,7 +11935,8 @@ var FunctionsResource = class {
11890
11935
  function_name: params.function_name,
11891
11936
  entry_script_path: params.entry_script_path,
11892
11937
  params_schema: params.params_schema,
11893
- allow_charges: params.allow_charges
11938
+ allow_charges: params.allow_charges,
11939
+ run_as_user_id: params.run_as_user_id
11894
11940
  }
11895
11941
  });
11896
11942
  }
@@ -12227,6 +12273,7 @@ var AlvaClient = class {
12227
12273
  _fs;
12228
12274
  _run;
12229
12275
  _deploy;
12276
+ _serviceAccount;
12230
12277
  _release;
12231
12278
  _feed;
12232
12279
  _playbooks;
@@ -12269,6 +12316,9 @@ var AlvaClient = class {
12269
12316
  get deploy() {
12270
12317
  return this._deploy ??= new DeployResource(this);
12271
12318
  }
12319
+ get serviceAccount() {
12320
+ return this._serviceAccount ??= new ServiceAccountResource(this);
12321
+ }
12272
12322
  get release() {
12273
12323
  return this._release ??= new ReleaseResource(this);
12274
12324
  }
@@ -12498,11 +12548,11 @@ var AlvaClient = class {
12498
12548
  if (response.status === 204) {
12499
12549
  return void 0;
12500
12550
  }
12501
- const contentType = response.headers.get("content-type") ?? "";
12502
- if (contentType.includes("application/octet-stream") || contentType.startsWith("text/") || contentType.includes("image/")) {
12503
- return response.arrayBuffer();
12551
+ const contentType = (response.headers.get("content-type") ?? "").toLowerCase();
12552
+ if (contentType.includes("application/json") || contentType.includes("+json")) {
12553
+ return response.json();
12504
12554
  }
12505
- return response.json();
12555
+ return response.arrayBuffer();
12506
12556
  }
12507
12557
  };
12508
12558
 
@@ -13316,7 +13366,7 @@ import * as fs2 from "fs";
13316
13366
  import * as os2 from "os";
13317
13367
  import * as fsPromises2 from "fs/promises";
13318
13368
  import { Agent, setGlobalDispatcher } from "undici";
13319
- var CLI_VERSION = true ? "0.14.0" : "dev";
13369
+ var CLI_VERSION = true ? "0.15.0" : "dev";
13320
13370
  var DEFAULT_RUN_TIMEOUT_MS = 6e5;
13321
13371
  var RUN_TIMEOUT_ENV = "ALVA_RUN_TIMEOUT_MS";
13322
13372
  var configuredRunFetchTimeoutMs;
@@ -13346,6 +13396,7 @@ Commands:
13346
13396
  fs Filesystem operations (read, write, stat, readdir, mkdir, remove, rename, copy, symlink, readlink, chmod, grant, revoke)
13347
13397
  run Execute code in the Alva runtime
13348
13398
  deploy Cronjob management (create, list, get, update, delete, pause, resume, runs, run-logs)
13399
+ service-account Restricted run-as identities (create, list, delete, grant, revoke)
13349
13400
  release Feed and playbook releases (feed, playbook-draft, playbook)
13350
13401
  lint Design-system lint (playbook)
13351
13402
  feed Feed lifecycle management (delete)
@@ -13631,6 +13682,11 @@ Create/Update flags:
13631
13682
  --push-notify Enable Telegram push notifications on completion
13632
13683
  --no-push-notify Disable push notifications
13633
13684
  --max-heap-size-mb <mb> Override per-cronjob V8 heap limit (1-2046, default uses server config)
13685
+ --run-as-service-account <id> Run the cronjob under a service-account identity
13686
+ (id from "alva service-account create"); restricts file
13687
+ access to the SA's grants. Omit on update \u21D2 unchanged (#602)
13688
+ --clear-run-as Clear run_as on update \u2014 run the cronjob as yourself
13689
+ again (mutually exclusive with --run-as-service-account)
13634
13690
 
13635
13691
  List flags:
13636
13692
  --limit <n> Max results per page (default: 20)
@@ -13681,6 +13737,28 @@ Build-time verify (fire once, then poll until your run completes):
13681
13737
  STATUS=$(echo "$ROW" | jq -r .status)
13682
13738
  [ "$STATUS" = completed ] || alva deploy run-logs --id 42 \\
13683
13739
  --run-id "$(echo "$ROW" | jq -r .id)"`,
13740
+ "service-account": `Usage: alva service-account <subcommand> [options]
13741
+
13742
+ Manage restricted run-as identities. A service account executes a UDF or
13743
+ cronjob with only the ALFS paths you grant it; billing/audit stay with you.
13744
+ Set the resulting id as --run-as-service-account on a UDF/cronjob. Opt-in:
13745
+ no run-as = run as owner. See the service-accounts skill reference.
13746
+
13747
+ Subcommands:
13748
+ create Create a service account (--name <label>)
13749
+ list List the service accounts you own
13750
+ delete Delete a service account (--id <id>); referencing jobs fail-close
13751
+ grant Grant an ALFS path (--id <id> --path <path> --permission read|write|import)
13752
+ revoke Revoke an ALFS path (--id <id> --path <path> --permission ...)
13753
+
13754
+ Examples:
13755
+ alva service-account create --name fintwit-bot
13756
+ alva service-account grant --id 90123 --path '~/feeds/x/v1/src/index.js' --permission read
13757
+ alva service-account grant --id 90123 --path '~/feeds/x/v1/' --permission read
13758
+ alva deploy create --name x-update --path '~/feeds/x/v1/src/index.js' \\
13759
+ --cron "0 */4 * * *" --run-as-service-account 90123
13760
+ alva service-account revoke --id 90123 --path '~/feeds/x/v1/' --permission read
13761
+ alva service-account delete --id 90123`,
13684
13762
  feed: `Usage: alva feed <subcommand> [options]
13685
13763
 
13686
13764
  Feed lifecycle management.
@@ -13786,6 +13864,12 @@ Register flags:
13786
13864
  --params-schema-file <path> Read JSON Schema from a local file
13787
13865
  --allow-charges Allow this function to charge viewer allowance
13788
13866
  --no-allow-charges Explicitly register as no-charge
13867
+ --run-as-service-account <id> Run invocations under a service-account identity
13868
+ (id from "alva service-account create"); scopes file
13869
+ access to the SA's grants. Omit on re-register \u21D2
13870
+ unchanged (#602)
13871
+ --clear-run-as Clear run_as on re-register \u2014 run as the owner again
13872
+ (mutually exclusive with --run-as-service-account)
13789
13873
 
13790
13874
  List flags:
13791
13875
  --playbook-id <id> Numeric playbook id (required)
@@ -14370,6 +14454,7 @@ var BOOLEAN_FLAGS = /* @__PURE__ */ new Set([
14370
14454
  "execute-latest",
14371
14455
  "dry-run",
14372
14456
  "allow-charges",
14457
+ "clear-run-as",
14373
14458
  "json",
14374
14459
  "compress",
14375
14460
  "bypass-lint",
@@ -14473,6 +14558,45 @@ function optionalBoundedIntegerFlag(flags, name, command, min, max) {
14473
14558
  }
14474
14559
  return n;
14475
14560
  }
14561
+ function optionalServiceAccountIdFlag(flags, command) {
14562
+ const raw = flags["run-as-service-account"];
14563
+ if (raw === void 0) return void 0;
14564
+ if (!/^[1-9]\d*$/.test(raw)) {
14565
+ throw new CliUsageError(
14566
+ `--run-as-service-account must be a positive service-account id for '${command}', got '${raw}'`,
14567
+ command.split(" ")[0]
14568
+ );
14569
+ }
14570
+ return raw;
14571
+ }
14572
+ function resolveRunAsFlag(flags, command) {
14573
+ const clear = boolFlag(flags["clear-run-as"]) ?? false;
14574
+ const setID = optionalServiceAccountIdFlag(flags, command);
14575
+ if (clear && setID !== void 0) {
14576
+ throw new CliUsageError(
14577
+ `--clear-run-as and --run-as-service-account are mutually exclusive for '${command}'`,
14578
+ command.split(" ")[0]
14579
+ );
14580
+ }
14581
+ if (clear) return "0";
14582
+ return setID;
14583
+ }
14584
+ function requireServiceAccountIdFlag(flags, command) {
14585
+ const raw = flags["id"];
14586
+ if (raw === void 0 || raw === "") {
14587
+ throw new CliUsageError(
14588
+ `Missing required flag --id for '${command}'`,
14589
+ command.split(" ")[0]
14590
+ );
14591
+ }
14592
+ if (!/^[1-9]\d*$/.test(raw)) {
14593
+ throw new CliUsageError(
14594
+ `--id must be a positive service-account id for '${command}', got '${raw}'`,
14595
+ command.split(" ")[0]
14596
+ );
14597
+ }
14598
+ return raw;
14599
+ }
14476
14600
  function parsePositiveIntegerValue(val, label, command) {
14477
14601
  const n = Number(val);
14478
14602
  if (!/^[1-9]\d*$/.test(val) || !Number.isSafeInteger(n)) {
@@ -14923,6 +15047,10 @@ async function dispatch(client, args, meta, deps) {
14923
15047
  "deploy create",
14924
15048
  1,
14925
15049
  2046
15050
+ ),
15051
+ run_as_user_id: optionalServiceAccountIdFlag(
15052
+ flags,
15053
+ "deploy create"
14926
15054
  )
14927
15055
  });
14928
15056
  case "list":
@@ -14947,7 +15075,8 @@ async function dispatch(client, args, meta, deps) {
14947
15075
  "deploy update",
14948
15076
  1,
14949
15077
  2046
14950
- )
15078
+ ),
15079
+ run_as_user_id: resolveRunAsFlag(flags, "deploy update")
14951
15080
  });
14952
15081
  case "delete":
14953
15082
  return client.deploy.delete({
@@ -14983,6 +15112,50 @@ async function dispatch(client, args, meta, deps) {
14983
15112
  );
14984
15113
  }
14985
15114
  }
15115
+ case "service-account": {
15116
+ if (!subcommand)
15117
+ throw new CliUsageError(
15118
+ "Missing subcommand for service-account",
15119
+ "service-account"
15120
+ );
15121
+ switch (subcommand) {
15122
+ case "create":
15123
+ return client.serviceAccount.create({
15124
+ display_name: requireFlag(flags, "name", "service-account create")
15125
+ });
15126
+ case "list":
15127
+ return client.serviceAccount.list();
15128
+ case "delete":
15129
+ return client.serviceAccount.delete({
15130
+ id: requireServiceAccountIdFlag(flags, "service-account delete")
15131
+ });
15132
+ case "grant":
15133
+ return client.serviceAccount.grant({
15134
+ id: requireServiceAccountIdFlag(flags, "service-account grant"),
15135
+ path: requireFlag(flags, "path", "service-account grant"),
15136
+ permission: requireFlag(
15137
+ flags,
15138
+ "permission",
15139
+ "service-account grant"
15140
+ )
15141
+ });
15142
+ case "revoke":
15143
+ return client.serviceAccount.revoke({
15144
+ id: requireServiceAccountIdFlag(flags, "service-account revoke"),
15145
+ path: requireFlag(flags, "path", "service-account revoke"),
15146
+ permission: requireFlag(
15147
+ flags,
15148
+ "permission",
15149
+ "service-account revoke"
15150
+ )
15151
+ });
15152
+ default:
15153
+ throw new CliUsageError(
15154
+ `Unknown subcommand: service-account ${subcommand}`,
15155
+ "service-account"
15156
+ );
15157
+ }
15158
+ }
14986
15159
  case "feed": {
14987
15160
  if (!subcommand)
14988
15161
  throw new CliUsageError("Missing subcommand for feed", "feed");
@@ -15156,7 +15329,8 @@ async function dispatch(client, args, meta, deps) {
15156
15329
  "functions register",
15157
15330
  deps
15158
15331
  ),
15159
- allow_charges: boolFlag(flags["allow-charges"])
15332
+ allow_charges: boolFlag(flags["allow-charges"]),
15333
+ run_as_user_id: resolveRunAsFlag(flags, "functions register")
15160
15334
  });
15161
15335
  case "list":
15162
15336
  return client.functions.list({