@pierre/storage 1.2.2 → 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/dist/index.cjs +84 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +51 -4
- package/dist/index.d.ts +51 -4
- package/dist/index.js +84 -4
- package/dist/index.js.map +1 -1
- package/package.json +43 -43
- package/src/index.ts +104 -3
- package/src/types.ts +49 -3
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.
|
|
533
|
+
version: "1.3.2"};
|
|
534
534
|
|
|
535
535
|
// src/version.ts
|
|
536
536
|
var PACKAGE_NAME = "code-storage-sdk";
|
|
@@ -2466,11 +2466,15 @@ var GitStorage = class _GitStorage {
|
|
|
2466
2466
|
...baseRepo.sha ? { sha: baseRepo.sha } : {}
|
|
2467
2467
|
};
|
|
2468
2468
|
} else {
|
|
2469
|
+
const syncRepo = baseRepo;
|
|
2470
|
+
const { provider: _p, ...restSnakecased } = snakecaseKeys__default.default(
|
|
2471
|
+
baseRepo
|
|
2472
|
+
);
|
|
2469
2473
|
baseRepoOptions = {
|
|
2470
|
-
provider: "github",
|
|
2471
|
-
...
|
|
2474
|
+
provider: syncRepo.provider ?? "github",
|
|
2475
|
+
...restSnakecased
|
|
2472
2476
|
};
|
|
2473
|
-
resolvedDefaultBranch =
|
|
2477
|
+
resolvedDefaultBranch = syncRepo.defaultBranch;
|
|
2474
2478
|
}
|
|
2475
2479
|
}
|
|
2476
2480
|
if (!resolvedDefaultBranch) {
|
|
@@ -2592,6 +2596,82 @@ var GitStorage = class _GitStorage {
|
|
|
2592
2596
|
message: body.message
|
|
2593
2597
|
};
|
|
2594
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
|
+
}
|
|
2595
2675
|
/**
|
|
2596
2676
|
* Get the current configuration
|
|
2597
2677
|
* @returns The client configuration
|