@pierre/storage 1.2.2 → 1.4.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/index.js CHANGED
@@ -162,6 +162,25 @@ var createBranchResponseSchema = z.object({
162
162
  target_is_ephemeral: z.boolean(),
163
163
  commit_sha: z.string().nullable().optional()
164
164
  });
165
+ var tagInfoSchema = z.object({
166
+ cursor: z.string(),
167
+ name: z.string(),
168
+ sha: z.string()
169
+ });
170
+ var listTagsResponseSchema = z.object({
171
+ tags: z.array(tagInfoSchema),
172
+ next_cursor: z.string().nullable().optional(),
173
+ has_more: z.boolean()
174
+ });
175
+ var createTagResponseSchema = z.object({
176
+ name: z.string(),
177
+ sha: z.string(),
178
+ message: z.string()
179
+ });
180
+ var deleteTagResponseSchema = z.object({
181
+ name: z.string(),
182
+ message: z.string()
183
+ });
165
184
  var refUpdateResultSchema = z.object({
166
185
  branch: z.string(),
167
186
  old_sha: z.string(),
@@ -524,7 +543,7 @@ function concatChunks(a, b) {
524
543
 
525
544
  // package.json
526
545
  var package_default = {
527
- version: "1.2.2"};
546
+ version: "1.4.0"};
528
547
 
529
548
  // src/version.ts
530
549
  var PACKAGE_NAME = "code-storage-sdk";
@@ -1678,6 +1697,33 @@ function transformCreateBranchResult(raw) {
1678
1697
  commitSha: raw.commit_sha ?? void 0
1679
1698
  };
1680
1699
  }
1700
+ function transformTagInfo(raw) {
1701
+ return {
1702
+ cursor: raw.cursor,
1703
+ name: raw.name,
1704
+ sha: raw.sha
1705
+ };
1706
+ }
1707
+ function transformListTagsResult(raw) {
1708
+ return {
1709
+ tags: raw.tags.map(transformTagInfo),
1710
+ nextCursor: raw.next_cursor ?? void 0,
1711
+ hasMore: raw.has_more
1712
+ };
1713
+ }
1714
+ function transformCreateTagResult(raw) {
1715
+ return {
1716
+ name: raw.name,
1717
+ sha: raw.sha,
1718
+ message: raw.message
1719
+ };
1720
+ }
1721
+ function transformDeleteTagResult(raw) {
1722
+ return {
1723
+ name: raw.name,
1724
+ message: raw.message
1725
+ };
1726
+ }
1681
1727
  function transformListReposResult(raw) {
1682
1728
  return {
1683
1729
  repos: raw.repos.map((repo) => ({
@@ -1950,6 +1996,31 @@ var RepoImpl = class {
1950
1996
  next_cursor: raw.next_cursor ?? void 0
1951
1997
  });
1952
1998
  }
1999
+ async listTags(options) {
2000
+ const ttl = resolveInvocationTtlSeconds(options, DEFAULT_TOKEN_TTL_SECONDS);
2001
+ const jwt = await this.generateJWT(this.id, {
2002
+ permissions: ["git:read"],
2003
+ ttl
2004
+ });
2005
+ const cursor = options?.cursor;
2006
+ const limit = options?.limit;
2007
+ let params;
2008
+ if (typeof cursor === "string" || typeof limit === "number") {
2009
+ params = {};
2010
+ if (typeof cursor === "string") {
2011
+ params.cursor = cursor;
2012
+ }
2013
+ if (typeof limit === "number") {
2014
+ params.limit = limit.toString();
2015
+ }
2016
+ }
2017
+ const response = await this.api.get({ path: "repos/tags", params }, jwt);
2018
+ const raw = listTagsResponseSchema.parse(await response.json());
2019
+ return transformListTagsResult({
2020
+ ...raw,
2021
+ next_cursor: raw.next_cursor ?? void 0
2022
+ });
2023
+ }
1953
2024
  async listCommits(options) {
1954
2025
  const ttl = resolveInvocationTtlSeconds(options, DEFAULT_TOKEN_TTL_SECONDS);
1955
2026
  const jwt = await this.generateJWT(this.id, {
@@ -2282,6 +2353,50 @@ var RepoImpl = class {
2282
2353
  const raw = createBranchResponseSchema.parse(await response.json());
2283
2354
  return transformCreateBranchResult(raw);
2284
2355
  }
2356
+ async createTag(options) {
2357
+ const name = options?.name?.trim();
2358
+ if (!name) {
2359
+ throw new Error("createTag name is required");
2360
+ }
2361
+ if (name.startsWith("refs/")) {
2362
+ throw new Error("createTag name must not start with refs/");
2363
+ }
2364
+ const target = options?.target?.trim();
2365
+ if (!target) {
2366
+ throw new Error("createTag target is required");
2367
+ }
2368
+ const ttl = resolveInvocationTtlSeconds(options, DEFAULT_TOKEN_TTL_SECONDS);
2369
+ const jwt = await this.generateJWT(this.id, {
2370
+ permissions: ["git:write"],
2371
+ ttl
2372
+ });
2373
+ const response = await this.api.post(
2374
+ { path: "repos/tags", body: { name, target } },
2375
+ jwt
2376
+ );
2377
+ const raw = createTagResponseSchema.parse(await response.json());
2378
+ return transformCreateTagResult(raw);
2379
+ }
2380
+ async deleteTag(options) {
2381
+ const name = options?.name?.trim();
2382
+ if (!name) {
2383
+ throw new Error("deleteTag name is required");
2384
+ }
2385
+ if (name.startsWith("refs/")) {
2386
+ throw new Error("deleteTag name must not start with refs/");
2387
+ }
2388
+ const ttl = resolveInvocationTtlSeconds(options, DEFAULT_TOKEN_TTL_SECONDS);
2389
+ const jwt = await this.generateJWT(this.id, {
2390
+ permissions: ["git:read", "git:write"],
2391
+ ttl
2392
+ });
2393
+ const response = await this.api.delete(
2394
+ { path: "repos/tags", body: { name } },
2395
+ jwt
2396
+ );
2397
+ const raw = deleteTagResponseSchema.parse(await response.json());
2398
+ return transformDeleteTagResult(raw);
2399
+ }
2285
2400
  async restoreCommit(options) {
2286
2401
  const targetBranch = options?.targetBranch?.trim();
2287
2402
  if (!targetBranch) {
@@ -2460,11 +2575,15 @@ var GitStorage = class _GitStorage {
2460
2575
  ...baseRepo.sha ? { sha: baseRepo.sha } : {}
2461
2576
  };
2462
2577
  } else {
2578
+ const syncRepo = baseRepo;
2579
+ const { provider: _p, ...restSnakecased } = snakecaseKeys(
2580
+ baseRepo
2581
+ );
2463
2582
  baseRepoOptions = {
2464
- provider: "github",
2465
- ...snakecaseKeys(baseRepo)
2583
+ provider: syncRepo.provider ?? "github",
2584
+ ...restSnakecased
2466
2585
  };
2467
- resolvedDefaultBranch = baseRepo.defaultBranch;
2586
+ resolvedDefaultBranch = syncRepo.defaultBranch;
2468
2587
  }
2469
2588
  }
2470
2589
  if (!resolvedDefaultBranch) {
@@ -2586,6 +2705,82 @@ var GitStorage = class _GitStorage {
2586
2705
  message: body.message
2587
2706
  };
2588
2707
  }
2708
+ /**
2709
+ * Create a generic git credential for a repository.
2710
+ * Used to authenticate sync operations for non-GitHub providers (GitLab, Bitbucket, etc.)
2711
+ */
2712
+ async createGitCredential(options) {
2713
+ const ttl = resolveInvocationTtlSeconds(options, DEFAULT_TOKEN_TTL_SECONDS);
2714
+ const jwt = await this.generateJWT(options.repoId, {
2715
+ permissions: ["repo:write"],
2716
+ ttl
2717
+ });
2718
+ const body = {
2719
+ repo_id: options.repoId,
2720
+ password: options.password
2721
+ };
2722
+ if (options.username !== void 0) {
2723
+ body.username = options.username;
2724
+ }
2725
+ const resp = await this.api.post(
2726
+ { path: "repos/git-credentials", body },
2727
+ jwt,
2728
+ { allowedStatus: [409] }
2729
+ );
2730
+ if (resp.status === 409) {
2731
+ throw new Error("A credential already exists for this repository");
2732
+ }
2733
+ const data = await resp.json();
2734
+ return { id: data.id };
2735
+ }
2736
+ /**
2737
+ * Update an existing generic git credential.
2738
+ */
2739
+ async updateGitCredential(options) {
2740
+ const ttl = resolveInvocationTtlSeconds(options, DEFAULT_TOKEN_TTL_SECONDS);
2741
+ const jwt = await this.generateJWT("org", {
2742
+ permissions: ["repo:write"],
2743
+ ttl
2744
+ });
2745
+ const body = {
2746
+ id: options.id,
2747
+ password: options.password
2748
+ };
2749
+ if (options.username !== void 0) {
2750
+ body.username = options.username;
2751
+ }
2752
+ const resp = await this.api.put(
2753
+ { path: "repos/git-credentials", body },
2754
+ jwt,
2755
+ { allowedStatus: [404] }
2756
+ );
2757
+ if (resp.status === 404) {
2758
+ throw new Error("Credential not found");
2759
+ }
2760
+ const data = await resp.json();
2761
+ return {
2762
+ id: data.id,
2763
+ ...data.created_at ? { createdAt: data.created_at } : {}
2764
+ };
2765
+ }
2766
+ /**
2767
+ * Delete a generic git credential.
2768
+ */
2769
+ async deleteGitCredential(options) {
2770
+ const ttl = resolveInvocationTtlSeconds(options, DEFAULT_TOKEN_TTL_SECONDS);
2771
+ const jwt = await this.generateJWT("org", {
2772
+ permissions: ["repo:write"],
2773
+ ttl
2774
+ });
2775
+ const resp = await this.api.delete(
2776
+ { path: "repos/git-credentials", body: { id: options.id } },
2777
+ jwt,
2778
+ { allowedStatus: [404] }
2779
+ );
2780
+ if (resp.status === 404) {
2781
+ throw new Error("Credential not found");
2782
+ }
2783
+ }
2589
2784
  /**
2590
2785
  * Get the current configuration
2591
2786
  * @returns The client configuration