@livechat/developer-studio-api 1.0.7 → 1.0.8

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.mts CHANGED
@@ -2097,6 +2097,15 @@ declare const api: {
2097
2097
  createRepositoryBuildHook(repositoryName: string, authorization?: GithubClientInstanceAuthorization | undefined): Promise<{
2098
2098
  keys: GitHubRepositoryHook[];
2099
2099
  } | undefined>;
2100
+ commitFiles(data: {
2101
+ repositoryName: string;
2102
+ repositoryBranch: string;
2103
+ message: string;
2104
+ files: {
2105
+ path: string;
2106
+ content: string | null;
2107
+ }[];
2108
+ }, authorization?: GithubClientInstanceAuthorization | undefined): Promise<void>;
2100
2109
  };
2101
2110
  getToken(code: string, clientId: string, clientSecret: string, redirectUrl: string): Promise<string>;
2102
2111
  };
package/dist/index.d.ts CHANGED
@@ -2097,6 +2097,15 @@ declare const api: {
2097
2097
  createRepositoryBuildHook(repositoryName: string, authorization?: GithubClientInstanceAuthorization | undefined): Promise<{
2098
2098
  keys: GitHubRepositoryHook[];
2099
2099
  } | undefined>;
2100
+ commitFiles(data: {
2101
+ repositoryName: string;
2102
+ repositoryBranch: string;
2103
+ message: string;
2104
+ files: {
2105
+ path: string;
2106
+ content: string | null;
2107
+ }[];
2108
+ }, authorization?: GithubClientInstanceAuthorization | undefined): Promise<void>;
2100
2109
  };
2101
2110
  getToken(code: string, clientId: string, clientSecret: string, redirectUrl: string): Promise<string>;
2102
2111
  };
package/dist/index.js CHANGED
@@ -547,6 +547,73 @@ var gitHubRepositoryApi = {
547
547
  } catch (e) {
548
548
  }
549
549
  });
550
+ },
551
+ commitFiles(data, authorization) {
552
+ return __async(this, null, function* () {
553
+ var _a, _b, _c, _d, _e;
554
+ const MODES = { FILE: "100644", FOLDER: "040000" };
555
+ const TYPE = { BLOB: "blob", TREE: "tree" };
556
+ const {
557
+ data: {
558
+ object: { sha: currentCommitSha }
559
+ }
560
+ } = yield githubClientInstance.get(
561
+ `/repos/${data.repositoryName}/git/refs/heads/${data.repositoryBranch}`,
562
+ getGithubClientRequestConfig({
563
+ token: (_a = authorization == null ? void 0 : authorization.tokens) == null ? void 0 : _a.app,
564
+ ensureAuthorizationToken: true
565
+ })
566
+ );
567
+ const {
568
+ data: {
569
+ tree: { sha: treeSha }
570
+ }
571
+ } = yield githubClientInstance.get(
572
+ `/repos/${data.repositoryName}/git/commits/${currentCommitSha}`,
573
+ getGithubClientRequestConfig({
574
+ token: (_b = authorization == null ? void 0 : authorization.tokens) == null ? void 0 : _b.app,
575
+ ensureAuthorizationToken: true
576
+ })
577
+ );
578
+ const {
579
+ data: { sha: newTreeSha }
580
+ } = yield githubClientInstance.post(
581
+ `/repos/${data.repositoryName}/git/trees`,
582
+ {
583
+ base_tree: treeSha,
584
+ tree: data.files.map(
585
+ ({ content, path }) => content ? { path, content, mode: MODES.FILE, type: TYPE.BLOB } : { path, sha: null, mode: MODES.FILE, type: TYPE.BLOB }
586
+ // If sha is null => the file gets deleted
587
+ )
588
+ },
589
+ getGithubClientRequestConfig({
590
+ token: (_c = authorization == null ? void 0 : authorization.tokens) == null ? void 0 : _c.app,
591
+ ensureAuthorizationToken: true
592
+ })
593
+ );
594
+ const {
595
+ data: { sha: newCommitSha }
596
+ } = yield githubClientInstance.post(
597
+ `/repos/${data.repositoryName}/git/commits`,
598
+ {
599
+ message: data.message,
600
+ tree: newTreeSha,
601
+ parents: [currentCommitSha]
602
+ },
603
+ getGithubClientRequestConfig({
604
+ token: (_d = authorization == null ? void 0 : authorization.tokens) == null ? void 0 : _d.app,
605
+ ensureAuthorizationToken: true
606
+ })
607
+ );
608
+ yield githubClientInstance.post(
609
+ `/repos/${data.repositoryName}/git/refs/heads/${data.repositoryBranch}`,
610
+ { sha: newCommitSha },
611
+ getGithubClientRequestConfig({
612
+ token: (_e = authorization == null ? void 0 : authorization.tokens) == null ? void 0 : _e.app,
613
+ ensureAuthorizationToken: true
614
+ })
615
+ );
616
+ });
550
617
  }
551
618
  };
552
619
 
package/dist/index.mjs CHANGED
@@ -463,6 +463,73 @@ var gitHubRepositoryApi = {
463
463
  } catch (e) {
464
464
  }
465
465
  });
466
+ },
467
+ commitFiles(data, authorization) {
468
+ return __async(this, null, function* () {
469
+ var _a, _b, _c, _d, _e;
470
+ const MODES = { FILE: "100644", FOLDER: "040000" };
471
+ const TYPE = { BLOB: "blob", TREE: "tree" };
472
+ const {
473
+ data: {
474
+ object: { sha: currentCommitSha }
475
+ }
476
+ } = yield githubClientInstance.get(
477
+ `/repos/${data.repositoryName}/git/refs/heads/${data.repositoryBranch}`,
478
+ getGithubClientRequestConfig({
479
+ token: (_a = authorization == null ? void 0 : authorization.tokens) == null ? void 0 : _a.app,
480
+ ensureAuthorizationToken: true
481
+ })
482
+ );
483
+ const {
484
+ data: {
485
+ tree: { sha: treeSha }
486
+ }
487
+ } = yield githubClientInstance.get(
488
+ `/repos/${data.repositoryName}/git/commits/${currentCommitSha}`,
489
+ getGithubClientRequestConfig({
490
+ token: (_b = authorization == null ? void 0 : authorization.tokens) == null ? void 0 : _b.app,
491
+ ensureAuthorizationToken: true
492
+ })
493
+ );
494
+ const {
495
+ data: { sha: newTreeSha }
496
+ } = yield githubClientInstance.post(
497
+ `/repos/${data.repositoryName}/git/trees`,
498
+ {
499
+ base_tree: treeSha,
500
+ tree: data.files.map(
501
+ ({ content, path }) => content ? { path, content, mode: MODES.FILE, type: TYPE.BLOB } : { path, sha: null, mode: MODES.FILE, type: TYPE.BLOB }
502
+ // If sha is null => the file gets deleted
503
+ )
504
+ },
505
+ getGithubClientRequestConfig({
506
+ token: (_c = authorization == null ? void 0 : authorization.tokens) == null ? void 0 : _c.app,
507
+ ensureAuthorizationToken: true
508
+ })
509
+ );
510
+ const {
511
+ data: { sha: newCommitSha }
512
+ } = yield githubClientInstance.post(
513
+ `/repos/${data.repositoryName}/git/commits`,
514
+ {
515
+ message: data.message,
516
+ tree: newTreeSha,
517
+ parents: [currentCommitSha]
518
+ },
519
+ getGithubClientRequestConfig({
520
+ token: (_d = authorization == null ? void 0 : authorization.tokens) == null ? void 0 : _d.app,
521
+ ensureAuthorizationToken: true
522
+ })
523
+ );
524
+ yield githubClientInstance.post(
525
+ `/repos/${data.repositoryName}/git/refs/heads/${data.repositoryBranch}`,
526
+ { sha: newCommitSha },
527
+ getGithubClientRequestConfig({
528
+ token: (_e = authorization == null ? void 0 : authorization.tokens) == null ? void 0 : _e.app,
529
+ ensureAuthorizationToken: true
530
+ })
531
+ );
532
+ });
466
533
  }
467
534
  };
468
535
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@livechat/developer-studio-api",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "This project is API for LiveChat Developer Studio.",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -18,8 +18,8 @@
18
18
  "tsup": "^7.1.0",
19
19
  "typescript": "^5.1.6",
20
20
  "config": "0.0.0",
21
- "tsconfig": "0.0.0",
22
21
  "eslint-config-custom-lib": "0.0.1",
22
+ "tsconfig": "0.0.0",
23
23
  "types": "0.0.1"
24
24
  },
25
25
  "scripts": {