@pierre/storage 1.2.1 → 1.3.2

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
@@ -126,7 +126,7 @@ const readOnlyUrl = await repo.getRemoteURL({
126
126
  #### Ephemeral Branches
127
127
 
128
128
  For working with ephemeral branches (temporary branches isolated from the main
129
- repository), use `getEphemeralRemote()`:
129
+ repository), use `getEphemeralRemoteURL()`:
130
130
 
131
131
  ```typescript
132
132
  // Get ephemeral namespace remote URL
@@ -145,6 +145,23 @@ console.log(
145
145
  // The ephemeral remote supports all the same options and permission as regular remotes
146
146
  ```
147
147
 
148
+ #### Import Remote
149
+
150
+ For write-only history imports, use `getImportRemoteURL()`:
151
+
152
+ ```typescript
153
+ // Get import remote URL
154
+ const importUrl = await repo.getImportRemoteURL();
155
+ // Returns: https://t:JWT@your-name.code.storage/repo-id+import.git
156
+
157
+ console.log(`Run: git remote add import ${importUrl}`);
158
+
159
+ // Push imported history through the import remote
160
+ // git push import main
161
+
162
+ // Reads are disabled on +import remotes; use the repository remote for clone/fetch
163
+ ```
164
+
148
165
  ### Working with Repository Content
149
166
 
150
167
  Once you have a repository instance, you can perform various Git operations:
package/dist/index.cjs CHANGED
@@ -530,7 +530,7 @@ function concatChunks(a, b) {
530
530
 
531
531
  // package.json
532
532
  var package_default = {
533
- version: "1.2.1"};
533
+ version: "1.3.2"};
534
534
 
535
535
  // src/version.ts
536
536
  var PACKAGE_NAME = "code-storage-sdk";
@@ -1825,6 +1825,14 @@ var RepoImpl = class {
1825
1825
  url.password = await this.generateJWT(this.id, urlOptions);
1826
1826
  return url.toString();
1827
1827
  }
1828
+ async getImportRemoteURL(urlOptions) {
1829
+ const url = new URL(
1830
+ `https://${this.options.storageBaseUrl}/${this.id}+import.git`
1831
+ );
1832
+ url.username = `t`;
1833
+ url.password = await this.generateJWT(this.id, urlOptions);
1834
+ return url.toString();
1835
+ }
1828
1836
  async getFileStream(options) {
1829
1837
  const ttl = resolveInvocationTtlSeconds(options, DEFAULT_TOKEN_TTL_SECONDS);
1830
1838
  const jwt = await this.generateJWT(this.id, {
@@ -2458,11 +2466,15 @@ var GitStorage = class _GitStorage {
2458
2466
  ...baseRepo.sha ? { sha: baseRepo.sha } : {}
2459
2467
  };
2460
2468
  } else {
2469
+ const syncRepo = baseRepo;
2470
+ const { provider: _p, ...restSnakecased } = snakecaseKeys__default.default(
2471
+ baseRepo
2472
+ );
2461
2473
  baseRepoOptions = {
2462
- provider: "github",
2463
- ...snakecaseKeys__default.default(baseRepo)
2474
+ provider: syncRepo.provider ?? "github",
2475
+ ...restSnakecased
2464
2476
  };
2465
- resolvedDefaultBranch = baseRepo.defaultBranch;
2477
+ resolvedDefaultBranch = syncRepo.defaultBranch;
2466
2478
  }
2467
2479
  }
2468
2480
  if (!resolvedDefaultBranch) {
@@ -2584,6 +2596,82 @@ var GitStorage = class _GitStorage {
2584
2596
  message: body.message
2585
2597
  };
2586
2598
  }
2599
+ /**
2600
+ * Create a generic git credential for a repository.
2601
+ * Used to authenticate sync operations for non-GitHub providers (GitLab, Bitbucket, etc.)
2602
+ */
2603
+ async createGitCredential(options) {
2604
+ const ttl = resolveInvocationTtlSeconds(options, DEFAULT_TOKEN_TTL_SECONDS);
2605
+ const jwt = await this.generateJWT(options.repoId, {
2606
+ permissions: ["repo:write"],
2607
+ ttl
2608
+ });
2609
+ const body = {
2610
+ repo_id: options.repoId,
2611
+ password: options.password
2612
+ };
2613
+ if (options.username !== void 0) {
2614
+ body.username = options.username;
2615
+ }
2616
+ const resp = await this.api.post(
2617
+ { path: "repos/git-credentials", body },
2618
+ jwt,
2619
+ { allowedStatus: [409] }
2620
+ );
2621
+ if (resp.status === 409) {
2622
+ throw new Error("A credential already exists for this repository");
2623
+ }
2624
+ const data = await resp.json();
2625
+ return { id: data.id };
2626
+ }
2627
+ /**
2628
+ * Update an existing generic git credential.
2629
+ */
2630
+ async updateGitCredential(options) {
2631
+ const ttl = resolveInvocationTtlSeconds(options, DEFAULT_TOKEN_TTL_SECONDS);
2632
+ const jwt = await this.generateJWT("org", {
2633
+ permissions: ["repo:write"],
2634
+ ttl
2635
+ });
2636
+ const body = {
2637
+ id: options.id,
2638
+ password: options.password
2639
+ };
2640
+ if (options.username !== void 0) {
2641
+ body.username = options.username;
2642
+ }
2643
+ const resp = await this.api.put(
2644
+ { path: "repos/git-credentials", body },
2645
+ jwt,
2646
+ { allowedStatus: [404] }
2647
+ );
2648
+ if (resp.status === 404) {
2649
+ throw new Error("Credential not found");
2650
+ }
2651
+ const data = await resp.json();
2652
+ return {
2653
+ id: data.id,
2654
+ ...data.created_at ? { createdAt: data.created_at } : {}
2655
+ };
2656
+ }
2657
+ /**
2658
+ * Delete a generic git credential.
2659
+ */
2660
+ async deleteGitCredential(options) {
2661
+ const ttl = resolveInvocationTtlSeconds(options, DEFAULT_TOKEN_TTL_SECONDS);
2662
+ const jwt = await this.generateJWT("org", {
2663
+ permissions: ["repo:write"],
2664
+ ttl
2665
+ });
2666
+ const resp = await this.api.delete(
2667
+ { path: "repos/git-credentials", body: { id: options.id } },
2668
+ jwt,
2669
+ { allowedStatus: [404] }
2670
+ );
2671
+ if (resp.status === 404) {
2672
+ throw new Error("Credential not found");
2673
+ }
2674
+ }
2587
2675
  /**
2588
2676
  * Get the current configuration
2589
2677
  * @returns The client configuration