pubblue 0.2.0 → 0.3.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.
Files changed (2) hide show
  1. package/dist/index.js +39 -12
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -38,12 +38,27 @@ var PubApiClient = class {
38
38
  const data = await this.request(`/api/v1/publications/${encodeURIComponent(slug)}`);
39
39
  return data.publication;
40
40
  }
41
+ async listPage(cursor, limit) {
42
+ const params = new URLSearchParams();
43
+ if (cursor) params.set("cursor", cursor);
44
+ if (limit) params.set("limit", String(limit));
45
+ const qs = params.toString();
46
+ return this.request(`/api/v1/publications${qs ? `?${qs}` : ""}`);
47
+ }
41
48
  async list() {
42
- const data = await this.request("/api/v1/publications");
43
- return data.publications;
49
+ const all = [];
50
+ let cursor;
51
+ do {
52
+ const result = await this.listPage(cursor, 100);
53
+ all.push(...result.publications);
54
+ cursor = result.hasMore ? result.cursor : void 0;
55
+ } while (cursor);
56
+ return all;
44
57
  }
45
58
  async update(opts) {
46
- const { slug, ...body } = opts;
59
+ const { slug, newSlug, ...rest } = opts;
60
+ const body = { ...rest };
61
+ if (newSlug) body.slug = newSlug;
47
62
  return this.request(`/api/v1/publications/${encodeURIComponent(slug)}`, {
48
63
  method: "PATCH",
49
64
  body: JSON.stringify(body)
@@ -168,7 +183,7 @@ function readFile(filePath) {
168
183
  basename: path2.basename(resolved)
169
184
  };
170
185
  }
171
- program.name("pubblue").description("Publish static content and get shareable URLs").version("0.2.0");
186
+ program.name("pubblue").description("Publish static content and get shareable URLs").version("0.3.0");
172
187
  program.command("configure").description("Configure the CLI with your API key").option("--api-key <key>", "Your API key (less secure: appears in shell history)").option("--api-key-stdin", "Read API key from stdin").action(async (opts) => {
173
188
  try {
174
189
  const apiKey = await resolveConfigureApiKey(opts);
@@ -180,14 +195,13 @@ program.command("configure").description("Configure the CLI with your API key").
180
195
  process.exit(1);
181
196
  }
182
197
  });
183
- program.command("create").description("Create a new publication").argument("[file]", "Path to the file (reads stdin if omitted)").option("--slug <slug>", "Custom slug for the URL").option("--title <title>", "Title for the publication").option("--public", "Make the publication public (default: private)").option("--private", "Make the publication private (this is the default)").action(
198
+ program.command("create").description("Create a new publication").argument("[file]", "Path to the file (reads stdin if omitted)").option("--slug <slug>", "Custom slug for the URL").option("--title <title>", "Title for the publication").option("--public", "Make the publication public (default: private)").option("--private", "Make the publication private (this is the default)").option("--expires <duration>", "Auto-delete after duration (e.g. 1h, 24h, 7d)").action(
184
199
  async (fileArg, opts) => {
185
200
  const client = createClient();
186
- const filePath = fileArg;
187
201
  let content;
188
202
  let filename;
189
- if (filePath) {
190
- const file = readFile(filePath);
203
+ if (fileArg) {
204
+ const file = readFile(fileArg);
191
205
  content = file.content;
192
206
  filename = file.basename;
193
207
  } else {
@@ -198,9 +212,13 @@ program.command("create").description("Create a new publication").argument("[fil
198
212
  filename,
199
213
  title: opts.title,
200
214
  slug: opts.slug,
201
- isPublic: opts.public ?? false
215
+ isPublic: opts.public ?? false,
216
+ expiresIn: opts.expires
202
217
  });
203
218
  console.log(`Created: ${result.url}`);
219
+ if (result.expiresAt) {
220
+ console.log(` Expires: ${new Date(result.expiresAt).toISOString()}`);
221
+ }
204
222
  }
205
223
  );
206
224
  program.command("get").description("Get details of a publication").argument("<slug>", "Slug of the publication").option("--content", "Output raw content to stdout (no metadata, pipeable)").action(async (slug, opts) => {
@@ -214,11 +232,12 @@ program.command("get").description("Get details of a publication").argument("<sl
214
232
  console.log(` Type: ${pub.contentType}`);
215
233
  if (pub.title) console.log(` Title: ${pub.title}`);
216
234
  console.log(` Status: ${formatVisibility(pub.isPublic)}`);
235
+ if (pub.expiresAt) console.log(` Expires: ${new Date(pub.expiresAt).toISOString()}`);
217
236
  console.log(` Created: ${new Date(pub.createdAt).toLocaleDateString()}`);
218
237
  console.log(` Updated: ${new Date(pub.updatedAt).toLocaleDateString()}`);
219
238
  console.log(` Size: ${pub.content.length} bytes`);
220
239
  });
221
- program.command("update").description("Update a publication's content and/or metadata").argument("<slug>", "Slug of the publication to update").option("--file <file>", "New content from file").option("--title <title>", "New title").option("--public", "Make the publication public").option("--private", "Make the publication private").action(
240
+ program.command("update").description("Update a publication's content and/or metadata").argument("<slug>", "Slug of the publication to update").option("--file <file>", "New content from file").option("--title <title>", "New title").option("--public", "Make the publication public").option("--private", "Make the publication private").option("--slug <newSlug>", "Rename the slug").action(
222
241
  async (slug, opts) => {
223
242
  const client = createClient();
224
243
  let content;
@@ -231,7 +250,14 @@ program.command("update").description("Update a publication's content and/or met
231
250
  let isPublic;
232
251
  if (opts.public) isPublic = true;
233
252
  else if (opts.private) isPublic = false;
234
- const result = await client.update({ slug, content, filename, title: opts.title, isPublic });
253
+ const result = await client.update({
254
+ slug,
255
+ content,
256
+ filename,
257
+ title: opts.title,
258
+ isPublic,
259
+ newSlug: opts.slug
260
+ });
235
261
  console.log(`Updated: ${result.slug}`);
236
262
  if (result.title) console.log(` Title: ${result.title}`);
237
263
  console.log(` Status: ${formatVisibility(result.isPublic)}`);
@@ -246,8 +272,9 @@ program.command("list").description("List your publications").action(async () =>
246
272
  }
247
273
  for (const pub of pubs) {
248
274
  const date = new Date(pub.createdAt).toLocaleDateString();
275
+ const expires = pub.expiresAt ? ` expires:${new Date(pub.expiresAt).toISOString()}` : "";
249
276
  console.log(
250
- ` ${pub.slug} [${pub.contentType}] ${formatVisibility(pub.isPublic)} ${date}`
277
+ ` ${pub.slug} [${pub.contentType}] ${formatVisibility(pub.isPublic)} ${date}${expires}`
251
278
  );
252
279
  }
253
280
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pubblue",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "CLI tool for publishing static content via pub.blue",
5
5
  "type": "module",
6
6
  "bin": {