@pierre/storage 0.2.2 → 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.
package/dist/index.d.cts CHANGED
@@ -448,6 +448,7 @@ interface GetRemoteURLOptions {
448
448
  interface Repo {
449
449
  id: string;
450
450
  getRemoteURL(options?: GetRemoteURLOptions): Promise<string>;
451
+ getEphemeralRemoteURL(options?: GetRemoteURLOptions): Promise<string>;
451
452
  getFileStream(options: GetFileOptions): Promise<Response>;
452
453
  listFiles(options?: ListFilesOptions): Promise<ListFilesResult>;
453
454
  listBranches(options?: ListBranchesOptions): Promise<ListBranchesResult>;
@@ -493,6 +494,7 @@ interface GetFileOptions extends GitStorageInvocationOptions {
493
494
  path: string;
494
495
  ref?: string;
495
496
  ephemeral?: boolean;
497
+ ephemeralBase?: boolean;
496
498
  }
497
499
  interface PullUpstreamOptions extends GitStorageInvocationOptions {
498
500
  ref?: string;
@@ -561,6 +563,8 @@ interface ListCommitsResult {
561
563
  interface GetBranchDiffOptions extends GitStorageInvocationOptions {
562
564
  branch: string;
563
565
  base?: string;
566
+ ephemeral?: boolean;
567
+ ephemeralBase?: boolean;
564
568
  }
565
569
  type GetBranchDiffResponse = GetBranchDiffResponseRaw;
566
570
  interface GetBranchDiffResult {
@@ -572,6 +576,7 @@ interface GetBranchDiffResult {
572
576
  }
573
577
  interface GetCommitDiffOptions extends GitStorageInvocationOptions {
574
578
  sha: string;
579
+ baseSha?: string;
575
580
  }
576
581
  type GetCommitDiffResponse = GetCommitDiffResponseRaw;
577
582
  interface GetCommitDiffResult {
@@ -861,11 +866,11 @@ declare function validateWebhook(payload: string | Buffer, headers: Record<strin
861
866
  */
862
867
 
863
868
  declare class GitStorage {
864
- private static overrides;
865
869
  private options;
866
870
  private api;
867
871
  constructor(options: GitStorageOptions);
868
- static override(options: OverrideableGitStorageOptions): void;
872
+ static getDefaultAPIBaseUrl(name: string): string;
873
+ static getDefaultStorageBaseUrl(name: string): string;
869
874
  /**
870
875
  * Create a new repository
871
876
  * @returns The created repository
@@ -889,6 +894,7 @@ declare class GitStorage {
889
894
  private generateJWT;
890
895
  }
891
896
  declare function createClient(options: GitStorageOptions): GitStorage;
897
+
892
898
  type StorageOptions = GitStorageOptions;
893
899
 
894
- export { ApiError, type BaseRepo, type BlobLike, type BranchInfo, type CommitBuilder, type CommitFileOptions, type CommitFileSource, type CommitInfo, type CommitResult, type CommitSignature, type CommitTextFileOptions, type CreateBranchOptions, type CreateBranchResponse, type CreateBranchResult, type CreateCommitBranchOptions, type CreateCommitFromDiffOptions, type CreateCommitOptions, type CreateRepoOptions, type DiffFileBase, type DiffFileState, type DiffSource, type DiffStats, type FileDiff, type FileLike, type FilteredFile, type FindOneOptions, type GetBranchDiffOptions, type GetBranchDiffResponse, type GetBranchDiffResult, type GetCommitDiffOptions, type GetCommitDiffResponse, type GetCommitDiffResult, type GetFileOptions, type GetRemoteURLOptions, type GitFileMode, GitStorage, type GitStorageOptions, type LegacyCreateCommitOptions, type ListBranchesOptions, type ListBranchesResponse, type ListBranchesResult, type ListCommitsOptions, type ListCommitsResponse, type ListCommitsResult, type ListFilesOptions, type ListFilesResponse, type ListFilesResult, type OverrideableGitStorageOptions, type ParsedWebhookSignature, type PullUpstreamOptions, type RawBranchInfo, type RawCommitInfo, type RawFileDiff, type RawFilteredFile, type RawWebhookPushEvent, type ReadableStreamLike, type ReadableStreamReaderLike, type RefUpdate, RefUpdateError, type RefUpdateReason, type Repo, type RestoreCommitOptions, type RestoreCommitResult, type StorageOptions, type SupportedRepoProvider, type TextEncoding, type ValidAPIVersion, type ValidMethod, type ValidPath, type WebhookEventPayload, type WebhookPushEvent, type WebhookUnknownEvent, type WebhookValidationOptions, type WebhookValidationResult, createClient, parseSignatureHeader, validateWebhook, validateWebhookSignature };
900
+ export { ApiError, type BaseRepo, type BlobLike, type BranchInfo, GitStorage as CodeStorage, type CommitBuilder, type CommitFileOptions, type CommitFileSource, type CommitInfo, type CommitResult, type CommitSignature, type CommitTextFileOptions, type CreateBranchOptions, type CreateBranchResponse, type CreateBranchResult, type CreateCommitBranchOptions, type CreateCommitFromDiffOptions, type CreateCommitOptions, type CreateRepoOptions, type DiffFileBase, type DiffFileState, type DiffSource, type DiffStats, type FileDiff, type FileLike, type FilteredFile, type FindOneOptions, type GetBranchDiffOptions, type GetBranchDiffResponse, type GetBranchDiffResult, type GetCommitDiffOptions, type GetCommitDiffResponse, type GetCommitDiffResult, type GetFileOptions, type GetRemoteURLOptions, type GitFileMode, GitStorage, type GitStorageOptions, type LegacyCreateCommitOptions, type ListBranchesOptions, type ListBranchesResponse, type ListBranchesResult, type ListCommitsOptions, type ListCommitsResponse, type ListCommitsResult, type ListFilesOptions, type ListFilesResponse, type ListFilesResult, type OverrideableGitStorageOptions, type ParsedWebhookSignature, type PullUpstreamOptions, type RawBranchInfo, type RawCommitInfo, type RawFileDiff, type RawFilteredFile, type RawWebhookPushEvent, type ReadableStreamLike, type ReadableStreamReaderLike, type RefUpdate, RefUpdateError, type RefUpdateReason, type Repo, type RestoreCommitOptions, type RestoreCommitResult, type StorageOptions, type SupportedRepoProvider, type TextEncoding, type ValidAPIVersion, type ValidMethod, type ValidPath, type WebhookEventPayload, type WebhookPushEvent, type WebhookUnknownEvent, type WebhookValidationOptions, type WebhookValidationResult, createClient, parseSignatureHeader, validateWebhook, validateWebhookSignature };
package/dist/index.d.ts CHANGED
@@ -448,6 +448,7 @@ interface GetRemoteURLOptions {
448
448
  interface Repo {
449
449
  id: string;
450
450
  getRemoteURL(options?: GetRemoteURLOptions): Promise<string>;
451
+ getEphemeralRemoteURL(options?: GetRemoteURLOptions): Promise<string>;
451
452
  getFileStream(options: GetFileOptions): Promise<Response>;
452
453
  listFiles(options?: ListFilesOptions): Promise<ListFilesResult>;
453
454
  listBranches(options?: ListBranchesOptions): Promise<ListBranchesResult>;
@@ -493,6 +494,7 @@ interface GetFileOptions extends GitStorageInvocationOptions {
493
494
  path: string;
494
495
  ref?: string;
495
496
  ephemeral?: boolean;
497
+ ephemeralBase?: boolean;
496
498
  }
497
499
  interface PullUpstreamOptions extends GitStorageInvocationOptions {
498
500
  ref?: string;
@@ -561,6 +563,8 @@ interface ListCommitsResult {
561
563
  interface GetBranchDiffOptions extends GitStorageInvocationOptions {
562
564
  branch: string;
563
565
  base?: string;
566
+ ephemeral?: boolean;
567
+ ephemeralBase?: boolean;
564
568
  }
565
569
  type GetBranchDiffResponse = GetBranchDiffResponseRaw;
566
570
  interface GetBranchDiffResult {
@@ -572,6 +576,7 @@ interface GetBranchDiffResult {
572
576
  }
573
577
  interface GetCommitDiffOptions extends GitStorageInvocationOptions {
574
578
  sha: string;
579
+ baseSha?: string;
575
580
  }
576
581
  type GetCommitDiffResponse = GetCommitDiffResponseRaw;
577
582
  interface GetCommitDiffResult {
@@ -861,11 +866,11 @@ declare function validateWebhook(payload: string | Buffer, headers: Record<strin
861
866
  */
862
867
 
863
868
  declare class GitStorage {
864
- private static overrides;
865
869
  private options;
866
870
  private api;
867
871
  constructor(options: GitStorageOptions);
868
- static override(options: OverrideableGitStorageOptions): void;
872
+ static getDefaultAPIBaseUrl(name: string): string;
873
+ static getDefaultStorageBaseUrl(name: string): string;
869
874
  /**
870
875
  * Create a new repository
871
876
  * @returns The created repository
@@ -889,6 +894,7 @@ declare class GitStorage {
889
894
  private generateJWT;
890
895
  }
891
896
  declare function createClient(options: GitStorageOptions): GitStorage;
897
+
892
898
  type StorageOptions = GitStorageOptions;
893
899
 
894
- export { ApiError, type BaseRepo, type BlobLike, type BranchInfo, type CommitBuilder, type CommitFileOptions, type CommitFileSource, type CommitInfo, type CommitResult, type CommitSignature, type CommitTextFileOptions, type CreateBranchOptions, type CreateBranchResponse, type CreateBranchResult, type CreateCommitBranchOptions, type CreateCommitFromDiffOptions, type CreateCommitOptions, type CreateRepoOptions, type DiffFileBase, type DiffFileState, type DiffSource, type DiffStats, type FileDiff, type FileLike, type FilteredFile, type FindOneOptions, type GetBranchDiffOptions, type GetBranchDiffResponse, type GetBranchDiffResult, type GetCommitDiffOptions, type GetCommitDiffResponse, type GetCommitDiffResult, type GetFileOptions, type GetRemoteURLOptions, type GitFileMode, GitStorage, type GitStorageOptions, type LegacyCreateCommitOptions, type ListBranchesOptions, type ListBranchesResponse, type ListBranchesResult, type ListCommitsOptions, type ListCommitsResponse, type ListCommitsResult, type ListFilesOptions, type ListFilesResponse, type ListFilesResult, type OverrideableGitStorageOptions, type ParsedWebhookSignature, type PullUpstreamOptions, type RawBranchInfo, type RawCommitInfo, type RawFileDiff, type RawFilteredFile, type RawWebhookPushEvent, type ReadableStreamLike, type ReadableStreamReaderLike, type RefUpdate, RefUpdateError, type RefUpdateReason, type Repo, type RestoreCommitOptions, type RestoreCommitResult, type StorageOptions, type SupportedRepoProvider, type TextEncoding, type ValidAPIVersion, type ValidMethod, type ValidPath, type WebhookEventPayload, type WebhookPushEvent, type WebhookUnknownEvent, type WebhookValidationOptions, type WebhookValidationResult, createClient, parseSignatureHeader, validateWebhook, validateWebhookSignature };
900
+ export { ApiError, type BaseRepo, type BlobLike, type BranchInfo, GitStorage as CodeStorage, type CommitBuilder, type CommitFileOptions, type CommitFileSource, type CommitInfo, type CommitResult, type CommitSignature, type CommitTextFileOptions, type CreateBranchOptions, type CreateBranchResponse, type CreateBranchResult, type CreateCommitBranchOptions, type CreateCommitFromDiffOptions, type CreateCommitOptions, type CreateRepoOptions, type DiffFileBase, type DiffFileState, type DiffSource, type DiffStats, type FileDiff, type FileLike, type FilteredFile, type FindOneOptions, type GetBranchDiffOptions, type GetBranchDiffResponse, type GetBranchDiffResult, type GetCommitDiffOptions, type GetCommitDiffResponse, type GetCommitDiffResult, type GetFileOptions, type GetRemoteURLOptions, type GitFileMode, GitStorage, type GitStorageOptions, type LegacyCreateCommitOptions, type ListBranchesOptions, type ListBranchesResponse, type ListBranchesResult, type ListCommitsOptions, type ListCommitsResponse, type ListCommitsResult, type ListFilesOptions, type ListFilesResponse, type ListFilesResult, type OverrideableGitStorageOptions, type ParsedWebhookSignature, type PullUpstreamOptions, type RawBranchInfo, type RawCommitInfo, type RawFileDiff, type RawFilteredFile, type RawWebhookPushEvent, type ReadableStreamLike, type ReadableStreamReaderLike, type RefUpdate, RefUpdateError, type RefUpdateReason, type Repo, type RestoreCommitOptions, type RestoreCommitResult, type StorageOptions, type SupportedRepoProvider, type TextEncoding, type ValidAPIVersion, type ValidMethod, type ValidPath, type WebhookEventPayload, type WebhookPushEvent, type WebhookUnknownEvent, type WebhookValidationOptions, type WebhookValidationResult, createClient, parseSignatureHeader, validateWebhook, validateWebhookSignature };
package/dist/index.js CHANGED
@@ -442,6 +442,17 @@ function concatChunks(a, b) {
442
442
  return merged;
443
443
  }
444
444
 
445
+ // package.json
446
+ var package_default = {
447
+ version: "0.3.0"};
448
+
449
+ // src/version.ts
450
+ var PACKAGE_NAME = "code-storage-sdk";
451
+ var PACKAGE_VERSION = package_default.version;
452
+ function getUserAgent() {
453
+ return `${PACKAGE_NAME}/${PACKAGE_VERSION}`;
454
+ }
455
+
445
456
  // src/commit.ts
446
457
  var DEFAULT_TTL_SECONDS = 60 * 60;
447
458
  var HEADS_REF_PREFIX = "refs/heads/";
@@ -614,7 +625,8 @@ var FetchCommitTransport = class {
614
625
  headers: {
615
626
  Authorization: `Bearer ${request.authorization}`,
616
627
  "Content-Type": "application/x-ndjson",
617
- Accept: "application/json"
628
+ Accept: "application/json",
629
+ "Code-Storage-Agent": getUserAgent()
618
630
  },
619
631
  body,
620
632
  signal: request.signal
@@ -844,7 +856,8 @@ var FetchDiffCommitTransport = class {
844
856
  headers: {
845
857
  Authorization: `Bearer ${request.authorization}`,
846
858
  "Content-Type": "application/x-ndjson",
847
- Accept: "application/json"
859
+ Accept: "application/json",
860
+ "Code-Storage-Agent": getUserAgent()
848
861
  },
849
862
  body,
850
863
  signal: request.signal
@@ -981,7 +994,8 @@ var ApiFetcher = class {
981
994
  method,
982
995
  headers: {
983
996
  Authorization: `Bearer ${jwt}`,
984
- "Content-Type": "application/json"
997
+ "Content-Type": "application/json",
998
+ "Code-Storage-Agent": getUserAgent()
985
999
  }
986
1000
  };
987
1001
  if (method !== "GET" && typeof path !== "string" && path.body) {
@@ -1277,8 +1291,8 @@ function isRecord(value) {
1277
1291
  }
1278
1292
 
1279
1293
  // src/index.ts
1280
- var API_BASE_URL = "https://api.code.storage";
1281
- var STORAGE_BASE_URL = "code.storage";
1294
+ var API_BASE_URL = "https://api.{{org}}.code.storage";
1295
+ var STORAGE_BASE_URL = "{{org}}.code.storage";
1282
1296
  var API_VERSION = 1;
1283
1297
  var apiInstanceMap = /* @__PURE__ */ new Map();
1284
1298
  var DEFAULT_TOKEN_TTL_SECONDS = 60 * 60;
@@ -1505,14 +1519,19 @@ var RepoImpl = class {
1505
1519
  this.options = options;
1506
1520
  this.generateJWT = generateJWT;
1507
1521
  this.api = getApiInstance(
1508
- this.options.apiBaseUrl ?? API_BASE_URL,
1522
+ this.options.apiBaseUrl ?? GitStorage.getDefaultAPIBaseUrl(options.name),
1509
1523
  this.options.apiVersion ?? API_VERSION
1510
1524
  );
1511
1525
  }
1512
1526
  api;
1513
1527
  async getRemoteURL(urlOptions) {
1514
- const storageBaseUrl = this.options.storageBaseUrl ?? STORAGE_BASE_URL;
1515
- const url = new URL(`https://${this.options.name}.${storageBaseUrl}/${this.id}.git`);
1528
+ const url = new URL(`https://${this.options.storageBaseUrl}/${this.id}.git`);
1529
+ url.username = `t`;
1530
+ url.password = await this.generateJWT(this.id, urlOptions);
1531
+ return url.toString();
1532
+ }
1533
+ async getEphemeralRemoteURL(urlOptions) {
1534
+ const url = new URL(`https://${this.options.storageBaseUrl}/${this.id}+ephemeral.git`);
1516
1535
  url.username = `t`;
1517
1536
  url.password = await this.generateJWT(this.id, urlOptions);
1518
1537
  return url.toString();
@@ -1532,6 +1551,9 @@ var RepoImpl = class {
1532
1551
  if (typeof options.ephemeral === "boolean") {
1533
1552
  params.ephemeral = String(options.ephemeral);
1534
1553
  }
1554
+ if (typeof options.ephemeralBase === "boolean") {
1555
+ params.ephemeral_base = String(options.ephemeralBase);
1556
+ }
1535
1557
  return this.api.get({ path: "repos/file", params }, jwt);
1536
1558
  }
1537
1559
  async listFiles(options) {
@@ -1617,6 +1639,12 @@ var RepoImpl = class {
1617
1639
  if (options.base) {
1618
1640
  params.base = options.base;
1619
1641
  }
1642
+ if (typeof options.ephemeral === "boolean") {
1643
+ params.ephemeral = String(options.ephemeral);
1644
+ }
1645
+ if (typeof options.ephemeralBase === "boolean") {
1646
+ params.ephemeral_base = String(options.ephemeralBase);
1647
+ }
1620
1648
  const response = await this.api.get({ path: "repos/branches/diff", params }, jwt);
1621
1649
  const raw = branchDiffResponseSchema.parse(await response.json());
1622
1650
  return transformBranchDiffResult(raw);
@@ -1630,6 +1658,9 @@ var RepoImpl = class {
1630
1658
  const params = {
1631
1659
  sha: options.sha
1632
1660
  };
1661
+ if (options.baseSha) {
1662
+ params.baseSha = options.baseSha;
1663
+ }
1633
1664
  const response = await this.api.get({ path: "repos/diff", params }, jwt);
1634
1665
  const raw = commitDiffResponseSchema.parse(await response.json());
1635
1666
  return transformCommitDiffResult(raw);
@@ -1749,7 +1780,7 @@ var RepoImpl = class {
1749
1780
  }
1750
1781
  createCommit(options) {
1751
1782
  const version = this.options.apiVersion ?? API_VERSION;
1752
- const baseUrl = this.options.apiBaseUrl ?? API_BASE_URL;
1783
+ const baseUrl = this.options.apiBaseUrl ?? GitStorage.getDefaultAPIBaseUrl(this.options.name);
1753
1784
  const transport = new FetchCommitTransport({ baseUrl, version });
1754
1785
  const ttl = resolveCommitTtlSeconds(options);
1755
1786
  const builderOptions = {
@@ -1768,7 +1799,7 @@ var RepoImpl = class {
1768
1799
  }
1769
1800
  async createCommitFromDiff(options) {
1770
1801
  const version = this.options.apiVersion ?? API_VERSION;
1771
- const baseUrl = this.options.apiBaseUrl ?? API_BASE_URL;
1802
+ const baseUrl = this.options.apiBaseUrl ?? GitStorage.getDefaultAPIBaseUrl(this.options.name);
1772
1803
  const transport = new FetchDiffCommitTransport({ baseUrl, version });
1773
1804
  const ttl = resolveCommitTtlSeconds(options);
1774
1805
  const requestOptions = {
@@ -1787,7 +1818,6 @@ var RepoImpl = class {
1787
1818
  }
1788
1819
  };
1789
1820
  var GitStorage = class _GitStorage {
1790
- static overrides = {};
1791
1821
  options;
1792
1822
  api;
1793
1823
  constructor(options) {
@@ -1802,10 +1832,10 @@ var GitStorage = class _GitStorage {
1802
1832
  if (typeof options.key !== "string" || options.key.trim() === "") {
1803
1833
  throw new Error("GitStorage key must be a non-empty string.");
1804
1834
  }
1805
- const resolvedApiBaseUrl = options.apiBaseUrl ?? _GitStorage.overrides.apiBaseUrl ?? API_BASE_URL;
1806
- const resolvedApiVersion = options.apiVersion ?? _GitStorage.overrides.apiVersion ?? API_VERSION;
1807
- const resolvedStorageBaseUrl = options.storageBaseUrl ?? _GitStorage.overrides.storageBaseUrl ?? STORAGE_BASE_URL;
1808
- const resolvedDefaultTtl = options.defaultTTL ?? _GitStorage.overrides.defaultTTL;
1835
+ const resolvedApiBaseUrl = options.apiBaseUrl ?? _GitStorage.getDefaultAPIBaseUrl(options.name);
1836
+ const resolvedApiVersion = options.apiVersion ?? API_VERSION;
1837
+ const resolvedStorageBaseUrl = options.storageBaseUrl ?? _GitStorage.getDefaultStorageBaseUrl(options.name);
1838
+ const resolvedDefaultTtl = options.defaultTTL;
1809
1839
  this.api = getApiInstance(resolvedApiBaseUrl, resolvedApiVersion);
1810
1840
  this.options = {
1811
1841
  key: options.key,
@@ -1816,8 +1846,11 @@ var GitStorage = class _GitStorage {
1816
1846
  defaultTTL: resolvedDefaultTtl
1817
1847
  };
1818
1848
  }
1819
- static override(options) {
1820
- this.overrides = Object.assign({}, this.overrides, options);
1849
+ static getDefaultAPIBaseUrl(name) {
1850
+ return API_BASE_URL.replace("{{org}}", name);
1851
+ }
1852
+ static getDefaultStorageBaseUrl(name) {
1853
+ return STORAGE_BASE_URL.replace("{{org}}", name);
1821
1854
  }
1822
1855
  /**
1823
1856
  * Create a new repository
@@ -1896,6 +1929,6 @@ function createClient(options) {
1896
1929
  return new GitStorage(options);
1897
1930
  }
1898
1931
 
1899
- export { ApiError, GitStorage, RefUpdateError, createClient, parseSignatureHeader, validateWebhook, validateWebhookSignature };
1932
+ export { ApiError, GitStorage as CodeStorage, GitStorage, RefUpdateError, createClient, parseSignatureHeader, validateWebhook, validateWebhookSignature };
1900
1933
  //# sourceMappingURL=index.js.map
1901
1934
  //# sourceMappingURL=index.js.map