@pierre/storage 0.2.3 → 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
@@ -494,6 +494,7 @@ interface GetFileOptions extends GitStorageInvocationOptions {
494
494
  path: string;
495
495
  ref?: string;
496
496
  ephemeral?: boolean;
497
+ ephemeralBase?: boolean;
497
498
  }
498
499
  interface PullUpstreamOptions extends GitStorageInvocationOptions {
499
500
  ref?: string;
@@ -562,6 +563,8 @@ interface ListCommitsResult {
562
563
  interface GetBranchDiffOptions extends GitStorageInvocationOptions {
563
564
  branch: string;
564
565
  base?: string;
566
+ ephemeral?: boolean;
567
+ ephemeralBase?: boolean;
565
568
  }
566
569
  type GetBranchDiffResponse = GetBranchDiffResponseRaw;
567
570
  interface GetBranchDiffResult {
@@ -573,6 +576,7 @@ interface GetBranchDiffResult {
573
576
  }
574
577
  interface GetCommitDiffOptions extends GitStorageInvocationOptions {
575
578
  sha: string;
579
+ baseSha?: string;
576
580
  }
577
581
  type GetCommitDiffResponse = GetCommitDiffResponseRaw;
578
582
  interface GetCommitDiffResult {
@@ -862,11 +866,11 @@ declare function validateWebhook(payload: string | Buffer, headers: Record<strin
862
866
  */
863
867
 
864
868
  declare class GitStorage {
865
- private static overrides;
866
869
  private options;
867
870
  private api;
868
871
  constructor(options: GitStorageOptions);
869
- static override(options: OverrideableGitStorageOptions): void;
872
+ static getDefaultAPIBaseUrl(name: string): string;
873
+ static getDefaultStorageBaseUrl(name: string): string;
870
874
  /**
871
875
  * Create a new repository
872
876
  * @returns The created repository
@@ -890,6 +894,7 @@ declare class GitStorage {
890
894
  private generateJWT;
891
895
  }
892
896
  declare function createClient(options: GitStorageOptions): GitStorage;
897
+
893
898
  type StorageOptions = GitStorageOptions;
894
899
 
895
- 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
@@ -494,6 +494,7 @@ interface GetFileOptions extends GitStorageInvocationOptions {
494
494
  path: string;
495
495
  ref?: string;
496
496
  ephemeral?: boolean;
497
+ ephemeralBase?: boolean;
497
498
  }
498
499
  interface PullUpstreamOptions extends GitStorageInvocationOptions {
499
500
  ref?: string;
@@ -562,6 +563,8 @@ interface ListCommitsResult {
562
563
  interface GetBranchDiffOptions extends GitStorageInvocationOptions {
563
564
  branch: string;
564
565
  base?: string;
566
+ ephemeral?: boolean;
567
+ ephemeralBase?: boolean;
565
568
  }
566
569
  type GetBranchDiffResponse = GetBranchDiffResponseRaw;
567
570
  interface GetBranchDiffResult {
@@ -573,6 +576,7 @@ interface GetBranchDiffResult {
573
576
  }
574
577
  interface GetCommitDiffOptions extends GitStorageInvocationOptions {
575
578
  sha: string;
579
+ baseSha?: string;
576
580
  }
577
581
  type GetCommitDiffResponse = GetCommitDiffResponseRaw;
578
582
  interface GetCommitDiffResult {
@@ -862,11 +866,11 @@ declare function validateWebhook(payload: string | Buffer, headers: Record<strin
862
866
  */
863
867
 
864
868
  declare class GitStorage {
865
- private static overrides;
866
869
  private options;
867
870
  private api;
868
871
  constructor(options: GitStorageOptions);
869
- static override(options: OverrideableGitStorageOptions): void;
872
+ static getDefaultAPIBaseUrl(name: string): string;
873
+ static getDefaultStorageBaseUrl(name: string): string;
870
874
  /**
871
875
  * Create a new repository
872
876
  * @returns The created repository
@@ -890,6 +894,7 @@ declare class GitStorage {
890
894
  private generateJWT;
891
895
  }
892
896
  declare function createClient(options: GitStorageOptions): GitStorage;
897
+
893
898
  type StorageOptions = GitStorageOptions;
894
899
 
895
- 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,21 +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`);
1516
1529
  url.username = `t`;
1517
1530
  url.password = await this.generateJWT(this.id, urlOptions);
1518
1531
  return url.toString();
1519
1532
  }
1520
1533
  async getEphemeralRemoteURL(urlOptions) {
1521
- const storageBaseUrl = this.options.storageBaseUrl ?? STORAGE_BASE_URL;
1522
- const url = new URL(`https://${this.options.name}.${storageBaseUrl}/${this.id}+ephemeral.git`);
1534
+ const url = new URL(`https://${this.options.storageBaseUrl}/${this.id}+ephemeral.git`);
1523
1535
  url.username = `t`;
1524
1536
  url.password = await this.generateJWT(this.id, urlOptions);
1525
1537
  return url.toString();
@@ -1539,6 +1551,9 @@ var RepoImpl = class {
1539
1551
  if (typeof options.ephemeral === "boolean") {
1540
1552
  params.ephemeral = String(options.ephemeral);
1541
1553
  }
1554
+ if (typeof options.ephemeralBase === "boolean") {
1555
+ params.ephemeral_base = String(options.ephemeralBase);
1556
+ }
1542
1557
  return this.api.get({ path: "repos/file", params }, jwt);
1543
1558
  }
1544
1559
  async listFiles(options) {
@@ -1624,6 +1639,12 @@ var RepoImpl = class {
1624
1639
  if (options.base) {
1625
1640
  params.base = options.base;
1626
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
+ }
1627
1648
  const response = await this.api.get({ path: "repos/branches/diff", params }, jwt);
1628
1649
  const raw = branchDiffResponseSchema.parse(await response.json());
1629
1650
  return transformBranchDiffResult(raw);
@@ -1637,6 +1658,9 @@ var RepoImpl = class {
1637
1658
  const params = {
1638
1659
  sha: options.sha
1639
1660
  };
1661
+ if (options.baseSha) {
1662
+ params.baseSha = options.baseSha;
1663
+ }
1640
1664
  const response = await this.api.get({ path: "repos/diff", params }, jwt);
1641
1665
  const raw = commitDiffResponseSchema.parse(await response.json());
1642
1666
  return transformCommitDiffResult(raw);
@@ -1756,7 +1780,7 @@ var RepoImpl = class {
1756
1780
  }
1757
1781
  createCommit(options) {
1758
1782
  const version = this.options.apiVersion ?? API_VERSION;
1759
- const baseUrl = this.options.apiBaseUrl ?? API_BASE_URL;
1783
+ const baseUrl = this.options.apiBaseUrl ?? GitStorage.getDefaultAPIBaseUrl(this.options.name);
1760
1784
  const transport = new FetchCommitTransport({ baseUrl, version });
1761
1785
  const ttl = resolveCommitTtlSeconds(options);
1762
1786
  const builderOptions = {
@@ -1775,7 +1799,7 @@ var RepoImpl = class {
1775
1799
  }
1776
1800
  async createCommitFromDiff(options) {
1777
1801
  const version = this.options.apiVersion ?? API_VERSION;
1778
- const baseUrl = this.options.apiBaseUrl ?? API_BASE_URL;
1802
+ const baseUrl = this.options.apiBaseUrl ?? GitStorage.getDefaultAPIBaseUrl(this.options.name);
1779
1803
  const transport = new FetchDiffCommitTransport({ baseUrl, version });
1780
1804
  const ttl = resolveCommitTtlSeconds(options);
1781
1805
  const requestOptions = {
@@ -1794,7 +1818,6 @@ var RepoImpl = class {
1794
1818
  }
1795
1819
  };
1796
1820
  var GitStorage = class _GitStorage {
1797
- static overrides = {};
1798
1821
  options;
1799
1822
  api;
1800
1823
  constructor(options) {
@@ -1809,10 +1832,10 @@ var GitStorage = class _GitStorage {
1809
1832
  if (typeof options.key !== "string" || options.key.trim() === "") {
1810
1833
  throw new Error("GitStorage key must be a non-empty string.");
1811
1834
  }
1812
- const resolvedApiBaseUrl = options.apiBaseUrl ?? _GitStorage.overrides.apiBaseUrl ?? API_BASE_URL;
1813
- const resolvedApiVersion = options.apiVersion ?? _GitStorage.overrides.apiVersion ?? API_VERSION;
1814
- const resolvedStorageBaseUrl = options.storageBaseUrl ?? _GitStorage.overrides.storageBaseUrl ?? STORAGE_BASE_URL;
1815
- 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;
1816
1839
  this.api = getApiInstance(resolvedApiBaseUrl, resolvedApiVersion);
1817
1840
  this.options = {
1818
1841
  key: options.key,
@@ -1823,8 +1846,11 @@ var GitStorage = class _GitStorage {
1823
1846
  defaultTTL: resolvedDefaultTtl
1824
1847
  };
1825
1848
  }
1826
- static override(options) {
1827
- 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);
1828
1854
  }
1829
1855
  /**
1830
1856
  * Create a new repository
@@ -1903,6 +1929,6 @@ function createClient(options) {
1903
1929
  return new GitStorage(options);
1904
1930
  }
1905
1931
 
1906
- export { ApiError, GitStorage, RefUpdateError, createClient, parseSignatureHeader, validateWebhook, validateWebhookSignature };
1932
+ export { ApiError, GitStorage as CodeStorage, GitStorage, RefUpdateError, createClient, parseSignatureHeader, validateWebhook, validateWebhookSignature };
1907
1933
  //# sourceMappingURL=index.js.map
1908
1934
  //# sourceMappingURL=index.js.map