@pierre/storage 1.3.2 → 1.4.1
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 +18 -0
- package/dist/index.cjs +122 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +117 -1
- package/dist/index.d.ts +117 -1
- package/dist/index.js +122 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +127 -0
- package/src/schemas.ts +27 -0
- package/src/types.ts +61 -0
package/README.md
CHANGED
|
@@ -214,6 +214,24 @@ const branches = await repo.listBranches({
|
|
|
214
214
|
});
|
|
215
215
|
console.log(branches.branches);
|
|
216
216
|
|
|
217
|
+
// List tags
|
|
218
|
+
const tags = await repo.listTags({
|
|
219
|
+
limit: 10,
|
|
220
|
+
cursor: undefined, // for pagination
|
|
221
|
+
});
|
|
222
|
+
console.log(tags.tags);
|
|
223
|
+
|
|
224
|
+
// Create a lightweight tag at a commit SHA
|
|
225
|
+
const createdTag = await repo.createTag({
|
|
226
|
+
name: 'v1.0.0',
|
|
227
|
+
target: '0123456789abcdef0123456789abcdef01234567',
|
|
228
|
+
});
|
|
229
|
+
console.log(createdTag.message);
|
|
230
|
+
|
|
231
|
+
// Delete a tag
|
|
232
|
+
const deletedTag = await repo.deleteTag({ name: 'v1.0.0' });
|
|
233
|
+
console.log(deletedTag.message);
|
|
234
|
+
|
|
217
235
|
// List commits
|
|
218
236
|
const commits = await repo.listCommits({
|
|
219
237
|
branch: 'main', // optional
|
package/dist/index.cjs
CHANGED
|
@@ -168,6 +168,25 @@ var createBranchResponseSchema = zod.z.object({
|
|
|
168
168
|
target_is_ephemeral: zod.z.boolean(),
|
|
169
169
|
commit_sha: zod.z.string().nullable().optional()
|
|
170
170
|
});
|
|
171
|
+
var tagInfoSchema = zod.z.object({
|
|
172
|
+
cursor: zod.z.string(),
|
|
173
|
+
name: zod.z.string(),
|
|
174
|
+
sha: zod.z.string()
|
|
175
|
+
});
|
|
176
|
+
var listTagsResponseSchema = zod.z.object({
|
|
177
|
+
tags: zod.z.array(tagInfoSchema),
|
|
178
|
+
next_cursor: zod.z.string().nullable().optional(),
|
|
179
|
+
has_more: zod.z.boolean()
|
|
180
|
+
});
|
|
181
|
+
var createTagResponseSchema = zod.z.object({
|
|
182
|
+
name: zod.z.string(),
|
|
183
|
+
sha: zod.z.string(),
|
|
184
|
+
message: zod.z.string()
|
|
185
|
+
});
|
|
186
|
+
var deleteTagResponseSchema = zod.z.object({
|
|
187
|
+
name: zod.z.string(),
|
|
188
|
+
message: zod.z.string()
|
|
189
|
+
});
|
|
171
190
|
var refUpdateResultSchema = zod.z.object({
|
|
172
191
|
branch: zod.z.string(),
|
|
173
192
|
old_sha: zod.z.string(),
|
|
@@ -530,7 +549,7 @@ function concatChunks(a, b) {
|
|
|
530
549
|
|
|
531
550
|
// package.json
|
|
532
551
|
var package_default = {
|
|
533
|
-
version: "1.
|
|
552
|
+
version: "1.4.1"};
|
|
534
553
|
|
|
535
554
|
// src/version.ts
|
|
536
555
|
var PACKAGE_NAME = "code-storage-sdk";
|
|
@@ -1168,6 +1187,9 @@ var ApiFetcher = class {
|
|
|
1168
1187
|
}
|
|
1169
1188
|
};
|
|
1170
1189
|
|
|
1190
|
+
// src/types.ts
|
|
1191
|
+
var OP_NO_FORCE_PUSH = "no-force-push";
|
|
1192
|
+
|
|
1171
1193
|
// src/util.ts
|
|
1172
1194
|
function timingSafeEqual(a, b) {
|
|
1173
1195
|
const bufferA = typeof a === "string" ? new TextEncoder().encode(a) : a;
|
|
@@ -1684,6 +1706,33 @@ function transformCreateBranchResult(raw) {
|
|
|
1684
1706
|
commitSha: raw.commit_sha ?? void 0
|
|
1685
1707
|
};
|
|
1686
1708
|
}
|
|
1709
|
+
function transformTagInfo(raw) {
|
|
1710
|
+
return {
|
|
1711
|
+
cursor: raw.cursor,
|
|
1712
|
+
name: raw.name,
|
|
1713
|
+
sha: raw.sha
|
|
1714
|
+
};
|
|
1715
|
+
}
|
|
1716
|
+
function transformListTagsResult(raw) {
|
|
1717
|
+
return {
|
|
1718
|
+
tags: raw.tags.map(transformTagInfo),
|
|
1719
|
+
nextCursor: raw.next_cursor ?? void 0,
|
|
1720
|
+
hasMore: raw.has_more
|
|
1721
|
+
};
|
|
1722
|
+
}
|
|
1723
|
+
function transformCreateTagResult(raw) {
|
|
1724
|
+
return {
|
|
1725
|
+
name: raw.name,
|
|
1726
|
+
sha: raw.sha,
|
|
1727
|
+
message: raw.message
|
|
1728
|
+
};
|
|
1729
|
+
}
|
|
1730
|
+
function transformDeleteTagResult(raw) {
|
|
1731
|
+
return {
|
|
1732
|
+
name: raw.name,
|
|
1733
|
+
message: raw.message
|
|
1734
|
+
};
|
|
1735
|
+
}
|
|
1687
1736
|
function transformListReposResult(raw) {
|
|
1688
1737
|
return {
|
|
1689
1738
|
repos: raw.repos.map((repo) => ({
|
|
@@ -1956,6 +2005,31 @@ var RepoImpl = class {
|
|
|
1956
2005
|
next_cursor: raw.next_cursor ?? void 0
|
|
1957
2006
|
});
|
|
1958
2007
|
}
|
|
2008
|
+
async listTags(options) {
|
|
2009
|
+
const ttl = resolveInvocationTtlSeconds(options, DEFAULT_TOKEN_TTL_SECONDS);
|
|
2010
|
+
const jwt = await this.generateJWT(this.id, {
|
|
2011
|
+
permissions: ["git:read"],
|
|
2012
|
+
ttl
|
|
2013
|
+
});
|
|
2014
|
+
const cursor = options?.cursor;
|
|
2015
|
+
const limit = options?.limit;
|
|
2016
|
+
let params;
|
|
2017
|
+
if (typeof cursor === "string" || typeof limit === "number") {
|
|
2018
|
+
params = {};
|
|
2019
|
+
if (typeof cursor === "string") {
|
|
2020
|
+
params.cursor = cursor;
|
|
2021
|
+
}
|
|
2022
|
+
if (typeof limit === "number") {
|
|
2023
|
+
params.limit = limit.toString();
|
|
2024
|
+
}
|
|
2025
|
+
}
|
|
2026
|
+
const response = await this.api.get({ path: "repos/tags", params }, jwt);
|
|
2027
|
+
const raw = listTagsResponseSchema.parse(await response.json());
|
|
2028
|
+
return transformListTagsResult({
|
|
2029
|
+
...raw,
|
|
2030
|
+
next_cursor: raw.next_cursor ?? void 0
|
|
2031
|
+
});
|
|
2032
|
+
}
|
|
1959
2033
|
async listCommits(options) {
|
|
1960
2034
|
const ttl = resolveInvocationTtlSeconds(options, DEFAULT_TOKEN_TTL_SECONDS);
|
|
1961
2035
|
const jwt = await this.generateJWT(this.id, {
|
|
@@ -2288,6 +2362,50 @@ var RepoImpl = class {
|
|
|
2288
2362
|
const raw = createBranchResponseSchema.parse(await response.json());
|
|
2289
2363
|
return transformCreateBranchResult(raw);
|
|
2290
2364
|
}
|
|
2365
|
+
async createTag(options) {
|
|
2366
|
+
const name = options?.name?.trim();
|
|
2367
|
+
if (!name) {
|
|
2368
|
+
throw new Error("createTag name is required");
|
|
2369
|
+
}
|
|
2370
|
+
if (name.startsWith("refs/")) {
|
|
2371
|
+
throw new Error("createTag name must not start with refs/");
|
|
2372
|
+
}
|
|
2373
|
+
const target = options?.target?.trim();
|
|
2374
|
+
if (!target) {
|
|
2375
|
+
throw new Error("createTag target is required");
|
|
2376
|
+
}
|
|
2377
|
+
const ttl = resolveInvocationTtlSeconds(options, DEFAULT_TOKEN_TTL_SECONDS);
|
|
2378
|
+
const jwt = await this.generateJWT(this.id, {
|
|
2379
|
+
permissions: ["git:write"],
|
|
2380
|
+
ttl
|
|
2381
|
+
});
|
|
2382
|
+
const response = await this.api.post(
|
|
2383
|
+
{ path: "repos/tags", body: { name, target } },
|
|
2384
|
+
jwt
|
|
2385
|
+
);
|
|
2386
|
+
const raw = createTagResponseSchema.parse(await response.json());
|
|
2387
|
+
return transformCreateTagResult(raw);
|
|
2388
|
+
}
|
|
2389
|
+
async deleteTag(options) {
|
|
2390
|
+
const name = options?.name?.trim();
|
|
2391
|
+
if (!name) {
|
|
2392
|
+
throw new Error("deleteTag name is required");
|
|
2393
|
+
}
|
|
2394
|
+
if (name.startsWith("refs/")) {
|
|
2395
|
+
throw new Error("deleteTag name must not start with refs/");
|
|
2396
|
+
}
|
|
2397
|
+
const ttl = resolveInvocationTtlSeconds(options, DEFAULT_TOKEN_TTL_SECONDS);
|
|
2398
|
+
const jwt = await this.generateJWT(this.id, {
|
|
2399
|
+
permissions: ["git:read", "git:write"],
|
|
2400
|
+
ttl
|
|
2401
|
+
});
|
|
2402
|
+
const response = await this.api.delete(
|
|
2403
|
+
{ path: "repos/tags", body: { name } },
|
|
2404
|
+
jwt
|
|
2405
|
+
);
|
|
2406
|
+
const raw = deleteTagResponseSchema.parse(await response.json());
|
|
2407
|
+
return transformDeleteTagResult(raw);
|
|
2408
|
+
}
|
|
2291
2409
|
async restoreCommit(options) {
|
|
2292
2410
|
const targetBranch = options?.targetBranch?.trim();
|
|
2293
2411
|
if (!targetBranch) {
|
|
@@ -2696,7 +2814,8 @@ var GitStorage = class _GitStorage {
|
|
|
2696
2814
|
repo: repoId,
|
|
2697
2815
|
scopes: permissions,
|
|
2698
2816
|
iat: now,
|
|
2699
|
-
exp: now + ttl
|
|
2817
|
+
exp: now + ttl,
|
|
2818
|
+
...options?.ops && options.ops.length > 0 ? { ops: options.ops } : {}
|
|
2700
2819
|
};
|
|
2701
2820
|
const key = await jose.importPKCS8(this.options.key, "ES256");
|
|
2702
2821
|
const jwt = await new jose.SignJWT(payload).setProtectedHeader({ alg: "ES256", typ: "JWT" }).sign(key);
|
|
@@ -2710,6 +2829,7 @@ function createClient(options) {
|
|
|
2710
2829
|
exports.ApiError = ApiError;
|
|
2711
2830
|
exports.CodeStorage = GitStorage;
|
|
2712
2831
|
exports.GitStorage = GitStorage;
|
|
2832
|
+
exports.OP_NO_FORCE_PUSH = OP_NO_FORCE_PUSH;
|
|
2713
2833
|
exports.RefUpdateError = RefUpdateError;
|
|
2714
2834
|
exports.createClient = createClient;
|
|
2715
2835
|
exports.parseSignatureHeader = parseSignatureHeader;
|