@xano/cli 1.3.2 → 1.3.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/README.md CHANGED
@@ -369,6 +369,7 @@ xano function run <name> --json @payload.json --data env=staging # base payloa
369
369
  echo '{"email":"jo@x.com"}' | xano function run <name> --stdin -o json | jq .result
370
370
  xano function run <name> --branch dev --logs # run on a branch, show execution logs
371
371
  xano function run <name> --datasource test # run against the 'test' data source
372
+ xano function run <name> --tenant my-tenant # run on a tenant instead of the workspace
372
373
  ```
373
374
 
374
375
  Input flexibility for `function run` (assembled into one JSON `input` object):
@@ -386,6 +387,9 @@ Input flexibility for `function run` (assembled into one JSON `input` object):
386
387
  to run against `live`; an unknown label is rejected by the server with
387
388
  `Invalid data source.`
388
389
 
390
+ `-t/--tenant <name>` runs the function on that tenant instead of the workspace by sending
391
+ the `X-Tenant` header (also used when reading the function's declared inputs).
392
+
389
393
  Merge order is JSON base first, then `--data` overrides. Missing required inputs are
390
394
  prompted for on an interactive terminal; in a non-TTY (CI) context the command fails
391
395
  listing them. Output defaults to the raw `result` (`-o json`); the exit code is non-zero
@@ -15,6 +15,7 @@ export default class FunctionRun extends BaseCommand {
15
15
  'no-input-check': import("@oclif/core/interfaces").BooleanFlag<boolean>;
16
16
  output: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
17
17
  stdin: import("@oclif/core/interfaces").BooleanFlag<boolean>;
18
+ tenant: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
18
19
  workspace: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
19
20
  config: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
20
21
  profile: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
@@ -19,6 +19,8 @@ export default class FunctionRun extends BaseCommand {
19
19
  `$ xano function:run calcScore --branch dev --logs`,
20
20
  `$ xano function:run calcScore --datasource test
21
21
  # Runs against the 'test' data source instead of 'live'`,
22
+ `$ xano function:run calcScore --tenant my-tenant
23
+ # Runs the function on the tenant instead of the workspace`,
22
24
  ];
23
25
  static flags = {
24
26
  ...BaseCommand.baseFlags,
@@ -70,6 +72,11 @@ export default class FunctionRun extends BaseCommand {
70
72
  exclusive: ['json'],
71
73
  required: false,
72
74
  }),
75
+ tenant: Flags.string({
76
+ char: 't',
77
+ description: 'Tenant name to run the function on (defaults to the workspace)',
78
+ required: false,
79
+ }),
73
80
  workspace: Flags.string({
74
81
  char: 'w',
75
82
  description: 'Workspace ID (optional if set in profile)',
@@ -96,6 +103,7 @@ export default class FunctionRun extends BaseCommand {
96
103
  branch,
97
104
  name: functionName,
98
105
  profile,
106
+ tenant: flags.tenant,
99
107
  verbose: flags.verbose,
100
108
  workspaceId,
101
109
  });
@@ -124,6 +132,9 @@ export default class FunctionRun extends BaseCommand {
124
132
  const dataSource = flags.datasource?.trim();
125
133
  if (dataSource)
126
134
  headers['X-Data-Source'] = dataSource;
135
+ // X-Tenant runs the function on that tenant instead of the workspace.
136
+ if (flags.tenant)
137
+ headers['X-Tenant'] = flags.tenant;
127
138
  const response = await this.verboseFetch(apiUrl, {
128
139
  body: JSON.stringify(body),
129
140
  headers,
@@ -166,13 +177,16 @@ export default class FunctionRun extends BaseCommand {
166
177
  * transient introspection problem never blocks an otherwise-valid run.
167
178
  */
168
179
  async fetchFunctionByName(opts) {
169
- const { branch, name, profile, verbose, workspaceId } = opts;
180
+ const { branch, name, profile, tenant, verbose, workspaceId } = opts;
170
181
  const params = new URLSearchParams({ per_page: '100', search: name });
171
182
  if (branch)
172
183
  params.set('branch', branch);
173
184
  const url = `${profile.instance_origin}/api:meta/workspace/${workspaceId}/function?${params.toString()}`;
185
+ const headers = { accept: 'application/json', Authorization: `Bearer ${profile.access_token}` };
186
+ if (tenant)
187
+ headers['X-Tenant'] = tenant;
174
188
  try {
175
- const response = await this.verboseFetch(url, { headers: { accept: 'application/json', Authorization: `Bearer ${profile.access_token}` }, method: 'GET' }, verbose, profile.access_token);
189
+ const response = await this.verboseFetch(url, { headers, method: 'GET' }, verbose, profile.access_token);
176
190
  if (!response.ok)
177
191
  return undefined;
178
192
  const page = (await response.json());