@pitcher/cli-scripts 2.6.0 → 2.7.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/README.md CHANGED
@@ -394,3 +394,23 @@ p roles list --scope instance --api-key myapikey
394
394
  ```
395
395
 
396
396
  `list` returns a `{ items: [...] }` object; each item's `role_key` is **prefixed** (`org:admin`, `instance:editor`). Pass the **short** name (e.g. `editor`) to `set-role`, not the prefixed key. Like `set-role`, `roles list` currently needs an **org-admin** key: while the granular-permissions rollout is off (the production default), the endpoint 403s non-org-admin callers.
397
+
398
+ ## To run the `metadata-template` command:
399
+
400
+ Read and additively build an instance's metadata-field schema. `list` and `upsert` require `--instance-id` (`get` only needs `--id`; `scaffold` makes no request).
401
+
402
+ ```bash
403
+ # Read the schema for an instance (0 or 1 template — one per instance)
404
+ p metadata-template list --instance-id 01... --api-key myapikey
405
+
406
+ # Get one template by id (ids are ULIDs)
407
+ p metadata-template get --id 01TEMPLATEID... --api-key myapikey
408
+
409
+ # Print a starter schema to fill in (optionally to a file)
410
+ p metadata-template scaffold --out ./schema.json
411
+
412
+ # Additively upsert the schema (merges by section label)
413
+ p metadata-template upsert --instance-id 01... --sections-file ./schema.json --api-key myapikey
414
+ ```
415
+
416
+ `upsert` merges the incoming sections by section `label` — a section whose label matches an existing one is replaced, other sections are preserved. It **cannot remove** a section or field (that's a UI operation). `options` for `select`/`multi-select` fields are `{ label, value }` objects (bare strings are rejected). `upsert` requires an instance- or org-admin key; a non-admin member key is rejected (400 → `VALIDATION`).
package/dist/index.js CHANGED
@@ -23,6 +23,7 @@ import { createInvitationsCommand } from './src/commands/invitations.js';
23
23
  import { createMembershipsCommand } from './src/commands/memberships.js';
24
24
  import { createGroupsCommand } from './src/commands/groups.js';
25
25
  import { createRolesCommand } from './src/commands/roles.js';
26
+ import { createMetadataTemplateCommand } from './src/commands/metadataTemplate.js';
26
27
  const __filename = fileURLToPath(import.meta.url);
27
28
  const __dirname = dirname(__filename);
28
29
  const pkg = JSON.parse(readFileSync(join(__dirname, '..', 'package.json'), 'utf8'));
@@ -51,6 +52,7 @@ program.addCommand(createInvitationsCommand());
51
52
  program.addCommand(createMembershipsCommand());
52
53
  program.addCommand(createGroupsCommand());
53
54
  program.addCommand(createRolesCommand());
55
+ program.addCommand(createMetadataTemplateCommand());
54
56
  program.addCommand(createOrgCommand());
55
57
  program.addCommand(createAnalyticsCommand());
56
58
  program.parseAsync(process.argv);
@@ -67,14 +67,15 @@ export async function runGroupsAddUser(opts, deps = {}) {
67
67
  }
68
68
  export async function runGroupsListUsers(opts, deps = {}) {
69
69
  try {
70
+ if (!opts.groupId)
71
+ throw createCliError('VALIDATION', '--group-id is required for groups list-users');
70
72
  assertIntFlags(opts);
71
73
  const client = clientFor(opts, deps);
72
74
  const params = { ...listPageParams(opts) };
73
75
  // The list filterset is content_distribution_group_id (NOT the bare relation
74
76
  // name) — an unknown param is silently ignored by DjangoFilterBackend and the
75
77
  // endpoint returns every visible membership in the org.
76
- if (opts.groupId)
77
- params.content_distribution_group_id = opts.groupId;
78
+ params.content_distribution_group_id = opts.groupId;
78
79
  const res = await client.get(GROUP_MEMBERS, { params });
79
80
  return ok({ results: res.data.results, pagination: listPaginationEcho(opts, res.data) });
80
81
  }
@@ -114,7 +115,7 @@ export function createGroupsCommand() {
114
115
  emitEnvelope(await runGroupsAddUser({ ...options, quiet: globals.quiet }), globals);
115
116
  });
116
117
  withAuthFlags(cmd.command('list-users'))
117
- .option('--group-id <id>', 'Group whose members to list')
118
+ .option('--group-id <id>', 'Group whose members to list (required)')
118
119
  .option('--page <n>', 'Page number', (v) => parseInt(v, 10))
119
120
  .option('--page-size <n>', 'Page size (max 500)', (v) => parseInt(v, 10))
120
121
  .action(async (options, command) => {
@@ -0,0 +1,27 @@
1
+ import { Command } from 'commander';
2
+ import type { AxiosInstance } from 'axios';
3
+ import { type CommonOpts } from '../core/http.js';
4
+ import { type Envelope } from '../core/envelope.js';
5
+ export interface MetadataTemplateDeps {
6
+ client?: AxiosInstance;
7
+ }
8
+ export declare function runMetadataTemplateScaffold(opts: CommonOpts & {
9
+ out?: string;
10
+ }, _deps?: MetadataTemplateDeps): Promise<Envelope<unknown>>;
11
+ export declare function runMetadataTemplateList(opts: CommonOpts & {
12
+ instanceId?: string;
13
+ page?: number;
14
+ pageSize?: number;
15
+ }, deps?: MetadataTemplateDeps): Promise<Envelope<{
16
+ results: unknown[];
17
+ pagination: Record<string, unknown>;
18
+ }>>;
19
+ export declare function runMetadataTemplateGet(opts: CommonOpts & {
20
+ id?: string;
21
+ }, deps?: MetadataTemplateDeps): Promise<Envelope<unknown>>;
22
+ export declare function runMetadataTemplateUpsert(opts: CommonOpts & {
23
+ instanceId?: string;
24
+ sections?: string;
25
+ sectionsFile?: string;
26
+ }, deps?: MetadataTemplateDeps): Promise<Envelope<unknown>>;
27
+ export declare function createMetadataTemplateCommand(): Command;
@@ -0,0 +1,112 @@
1
+ import { Command } from 'commander';
2
+ import { clientFor, toCliError } from '../core/http.js';
3
+ import { ok, fail } from '../core/envelope.js';
4
+ import { createCliError } from '../core/errors.js';
5
+ import { emitEnvelope } from '../core/output.js';
6
+ import { listPageParams, listPaginationEcho } from '../core/pagination.js';
7
+ import { assertIntFlags, parseJsonArray } from '../schema/content.js';
8
+ import { readTextFile } from '../core/readInput.js';
9
+ import { withAuthFlags } from './withAuth.js';
10
+ import { emitScaffold, METADATA_TEMPLATE_SCAFFOLD_JSON } from './scaffolds.js';
11
+ const ENDPOINT = '/api/v1/metadata-templates/';
12
+ export async function runMetadataTemplateScaffold(opts, _deps = {}) {
13
+ return emitScaffold(METADATA_TEMPLATE_SCAFFOLD_JSON, opts.out);
14
+ }
15
+ export async function runMetadataTemplateList(opts, deps = {}) {
16
+ try {
17
+ if (!opts.instanceId)
18
+ throw createCliError('VALIDATION', '--instance-id is required for metadata-template list');
19
+ assertIntFlags(opts);
20
+ const client = clientFor(opts, deps);
21
+ const params = { instance_id: opts.instanceId, ...listPageParams(opts) };
22
+ const res = await client.get(ENDPOINT, {
23
+ params,
24
+ });
25
+ return ok({ results: res.data.results, pagination: listPaginationEcho(opts, res.data) });
26
+ }
27
+ catch (e) {
28
+ return fail(toCliError(e));
29
+ }
30
+ }
31
+ export async function runMetadataTemplateGet(opts, deps = {}) {
32
+ try {
33
+ if (!opts.id)
34
+ throw createCliError('VALIDATION', '--id is required for metadata-template get');
35
+ const client = clientFor(opts, deps);
36
+ const res = await client.get(`${ENDPOINT}${encodeURIComponent(opts.id)}`);
37
+ return ok(res.data);
38
+ }
39
+ catch (e) {
40
+ return fail(toCliError(e));
41
+ }
42
+ }
43
+ export async function runMetadataTemplateUpsert(opts, deps = {}) {
44
+ try {
45
+ if (!opts.instanceId)
46
+ throw createCliError('VALIDATION', '--instance-id is required for metadata-template upsert');
47
+ // Presence-based (not truthiness) so an explicit empty --sections '' is still
48
+ // counted as a source and can't silently coexist with --sections-file.
49
+ if (opts.sections !== undefined && opts.sectionsFile !== undefined)
50
+ throw createCliError('VALIDATION', 'pass exactly one of --sections or --sections-file');
51
+ // readTextFile → parseJsonArray (NOT readJsonFile, which would bypass the
52
+ // array-shape VALIDATION check). Both throw a VALIDATION CliError.
53
+ const raw = opts.sections !== undefined
54
+ ? opts.sections
55
+ : opts.sectionsFile !== undefined
56
+ ? readTextFile(opts.sectionsFile)
57
+ : undefined;
58
+ if (raw === undefined)
59
+ throw createCliError('VALIDATION', 'pass exactly one of --sections or --sections-file');
60
+ const sections = parseJsonArray(raw, 'sections');
61
+ const client = clientFor(opts, deps);
62
+ const res = await client.post(ENDPOINT, { instance_id: opts.instanceId, sections });
63
+ return ok(res.data);
64
+ }
65
+ catch (e) {
66
+ return fail(toCliError(e));
67
+ }
68
+ }
69
+ const UPSERT_HELP = `
70
+ Upserts the instance's metadata-field schema. POST is an upsert keyed by
71
+ instance that MERGES the incoming sections by section 'label' — a section whose
72
+ label matches an existing one is replaced, other sections are preserved. It
73
+ CANNOT remove a section or field (a full-replace / UI operation).
74
+ --instance-id the instance whose schema to upsert (required)
75
+ --sections inline JSON array of sections, OR
76
+ --sections-file path to a JSON file with the sections array (exactly one)
77
+ Run 'p metadata-template scaffold' for a starter. Requires an instance- or
78
+ org-admin key; a non-admin member key is rejected (400 -> VALIDATION).`;
79
+ export function createMetadataTemplateCommand() {
80
+ const cmd = new Command('metadata-template').description('read and additively build an instance metadata-field schema');
81
+ withAuthFlags(cmd.command('list'))
82
+ .option('--instance-id <id>', 'Instance ID (required)')
83
+ .option('--page <n>', 'Page number', (v) => parseInt(v, 10))
84
+ .option('--page-size <n>', 'Page size (max 500)', (v) => parseInt(v, 10))
85
+ .action(async (options, command) => {
86
+ const globals = command.optsWithGlobals();
87
+ emitEnvelope(await runMetadataTemplateList({ ...options, quiet: globals.quiet }), globals);
88
+ });
89
+ withAuthFlags(cmd.command('get'))
90
+ .option('--id <id>', 'Metadata template ID (ULID)')
91
+ .action(async (options, command) => {
92
+ const globals = command.optsWithGlobals();
93
+ emitEnvelope(await runMetadataTemplateGet({ ...options, quiet: globals.quiet }), globals);
94
+ });
95
+ withAuthFlags(cmd.command('upsert'))
96
+ .option('--instance-id <id>', 'Instance ID (required)')
97
+ .option('--sections <json>', 'Sections JSON array (inline)')
98
+ .option('--sections-file <path>', 'Path to a JSON file with the sections array')
99
+ .addHelpText('after', UPSERT_HELP)
100
+ .action(async (options, command) => {
101
+ const globals = command.optsWithGlobals();
102
+ emitEnvelope(await runMetadataTemplateUpsert({ ...options, quiet: globals.quiet }), globals);
103
+ });
104
+ withAuthFlags(cmd.command('scaffold'))
105
+ .description('print a starter metadata-field schema (sections array) to fill in and upsert')
106
+ .option('--out <path>', 'Write the scaffold to a file instead of stdout')
107
+ .action(async (options, command) => {
108
+ const globals = command.optsWithGlobals();
109
+ emitEnvelope(await runMetadataTemplateScaffold({ ...options, quiet: globals.quiet }), globals);
110
+ });
111
+ return cmd;
112
+ }
@@ -17,3 +17,4 @@ export declare const EMAIL_SCAFFOLD_HTML = "<!doctype html>\n<html lang=\"en\">\
17
17
  */
18
18
  export declare const DSR_SCAFFOLD_HTML = "<!doctype html>\n<html lang=\"en\">\n <head>\n <meta charset=\"utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n <title>Sample DSR Landing Page</title>\n </head>\n <body style=\"margin:0;padding:0;background-color:#f4f4f4;font-family:Arial,Helvetica,sans-serif;color:#212121;\">\n <table role=\"presentation\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" style=\"padding:32px 0;\">\n <tr>\n <td align=\"center\">\n <table role=\"presentation\" width=\"640\" cellpadding=\"0\" cellspacing=\"0\" style=\"background-color:#ffffff;border-radius:8px;overflow:hidden;\">\n <tr>\n <td style=\"background-color:var(--p-primary, #29335C);padding:28px;text-align:center;\">\n <!-- token: organization.name -> the sharing org's display name -->\n <span style=\"color:#ffffff;font-size:20px;font-weight:bold;\">{{organization.name}}</span>\n </td>\n </tr>\n <tr>\n <td style=\"padding:32px;\">\n <!-- token: recipient.firstName -> the recipient's first name -->\n <!-- token: customer.name -> the recipient's company name -->\n <h1 style=\"margin:0 0 8px 0;font-size:22px;\">Welcome, {{recipient.firstName}}</h1>\n <p style=\"margin:0 0 24px 0;color:#757575;font-size:14px;\">Prepared for {{customer.name}}</p>\n\n <!--\n Editable region: admins can edit this block's text in the DSR\n landing editor without touching markup. data-field-char-limit\n enforces a max length in that editor.\n -->\n <div\n data-field-id=\"welcome-message\"\n data-field-editable=\"true\"\n data-field-char-limit=\"120\"\n style=\"padding:16px;margin:0 0 24px 0;border-left:3px solid var(--p-primary, #29335C);background-color:#f7f8fb;font-size:15px;line-height:1.5;\"\n >\n Thanks for stopping by. Everything you need for this conversation is right here.\n </div>\n\n <!-- token: rep.name -> the sharing rep's display name -->\n <p style=\"margin:0 0 24px 0;font-size:14px;color:#757575;\">Shared by {{rep.name}}</p>\n\n <!--\n Required marker: the platform injects the email-gate form\n into this div at render time. It MUST be present verbatim\n (a literal data-pitcher-email-gate attribute) or the\n server rejects the template on create/update.\n -->\n <div data-pitcher-email-gate></div>\n </td>\n </tr>\n <tr>\n <td style=\"padding:16px 32px;border-top:1px solid #e0e2ed;text-align:center;color:#757575;font-size:12px;\">\n <!-- token: sharedLink.valid_until -> when this share expires, if the share sets an expiry -->\n This link is valid until {{sharedLink.valid_until}}.\n </td>\n </tr>\n </table>\n </td>\n </tr>\n </table>\n </body>\n</html>\n";
19
19
  export declare const ANNOUNCEMENT_SCAFFOLD_JSON: string;
20
+ export declare const METADATA_TEMPLATE_SCAFFOLD_JSON: string;
@@ -174,3 +174,98 @@ const ANNOUNCEMENT_SCAFFOLD_DATA = {
174
174
  popup_link_label: null,
175
175
  };
176
176
  export const ANNOUNCEMENT_SCAFFOLD_JSON = JSON.stringify(ANNOUNCEMENT_SCAFFOLD_DATA, null, 2);
177
+ /**
178
+ * Starter metadata-field schema for `p metadata-template scaffold`. A working
179
+ * example, not a blank template: one section demonstrating every field `type`
180
+ * (text/number/date/select/multi-select/checkbox/html) and every attribute the
181
+ * serializer accepts. NOTE: `options` (select/multi-select) MUST be
182
+ * { label, value } objects — bare strings are rejected 400. `multi-select`
183
+ * cannot be `is_sortable`. A select/multi-select `default` is an option `value`.
184
+ * Section-level `are_fields_dependent` and field-level `help_text` are optional.
185
+ */
186
+ const METADATA_TEMPLATE_SCAFFOLD_DATA = [
187
+ {
188
+ label: 'Product Info',
189
+ are_fields_dependent: false,
190
+ fields: [
191
+ {
192
+ name: 'product_name',
193
+ label: 'Product Name',
194
+ type: 'text',
195
+ is_required: true,
196
+ is_filterable: true,
197
+ is_sortable: true,
198
+ is_pitch_master: false,
199
+ help_text: 'Marketed product name',
200
+ default: '',
201
+ },
202
+ {
203
+ name: 'launch_date',
204
+ label: 'Launch Date',
205
+ type: 'date',
206
+ is_required: false,
207
+ is_filterable: true,
208
+ is_sortable: true,
209
+ is_pitch_master: false,
210
+ },
211
+ {
212
+ name: 'therapeutic_area',
213
+ label: 'Therapeutic Area',
214
+ type: 'select',
215
+ is_required: false,
216
+ is_filterable: true,
217
+ is_sortable: false,
218
+ is_pitch_master: false,
219
+ options: [
220
+ { label: 'Cardiology', value: 'cardiology' },
221
+ { label: 'Oncology', value: 'oncology' },
222
+ ],
223
+ default: 'cardiology',
224
+ },
225
+ {
226
+ name: 'audiences',
227
+ label: 'Audiences',
228
+ type: 'multi-select',
229
+ is_required: false,
230
+ is_filterable: true,
231
+ is_sortable: false,
232
+ is_pitch_master: false,
233
+ options: [
234
+ { label: 'HCP', value: 'hcp' },
235
+ { label: 'Payer', value: 'payer' },
236
+ { label: 'Patient', value: 'patient' },
237
+ ],
238
+ },
239
+ {
240
+ name: 'priority',
241
+ label: 'Priority',
242
+ type: 'number',
243
+ is_required: false,
244
+ is_filterable: false,
245
+ is_sortable: true,
246
+ is_pitch_master: false,
247
+ default: 0,
248
+ },
249
+ {
250
+ name: 'is_approved',
251
+ label: 'Approved',
252
+ type: 'checkbox',
253
+ is_required: false,
254
+ is_filterable: true,
255
+ is_sortable: false,
256
+ is_pitch_master: false,
257
+ default: false,
258
+ },
259
+ {
260
+ name: 'notes',
261
+ label: 'Notes',
262
+ type: 'html',
263
+ is_required: false,
264
+ is_filterable: false,
265
+ is_sortable: false,
266
+ is_pitch_master: false,
267
+ },
268
+ ],
269
+ },
270
+ ];
271
+ export const METADATA_TEMPLATE_SCAFFOLD_JSON = JSON.stringify(METADATA_TEMPLATE_SCAFFOLD_DATA, null, 2);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pitcher/cli-scripts",
3
- "version": "2.6.0",
3
+ "version": "2.7.0",
4
4
  "description": "The Pitcher CLI for various tasks in its ecosystem.",
5
5
  "author": "Pitcher AG",
6
6
  "license": "MIT",