@bitblit/ratchet-node-only 6.0.145-alpha → 6.0.147-alpha

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.
Files changed (42) hide show
  1. package/package.json +4 -3
  2. package/src/build/ratchet-node-only-info.ts +19 -0
  3. package/src/ci/apply-ci-env-variables-to-files.spec.ts +30 -0
  4. package/src/ci/apply-ci-env-variables-to-files.ts +98 -0
  5. package/src/ci/ci-run-information-util.ts +48 -0
  6. package/src/ci/ci-run-information.ts +9 -0
  7. package/src/cli/abstract-ratchet-cli-handler.ts +33 -0
  8. package/src/cli/cli-ratchet.ts +34 -0
  9. package/src/cli/ratchet-cli-handler.ts +24 -0
  10. package/src/csv/csv-ratchet.spec.ts +59 -0
  11. package/src/csv/csv-ratchet.ts +211 -0
  12. package/src/export-builder/export-map-builder-config.ts +10 -0
  13. package/src/export-builder/export-map-builder-target-config.ts +5 -0
  14. package/src/export-builder/export-map-builder.spec.ts +22 -0
  15. package/src/export-builder/export-map-builder.ts +157 -0
  16. package/src/files/files-to-static-class.spec.ts +26 -0
  17. package/src/files/files-to-static-class.ts +101 -0
  18. package/src/files/unique-file-rename.ts +80 -0
  19. package/src/http/local-file-server.ts +129 -0
  20. package/src/http/local-server-cert.ts +72 -0
  21. package/src/jwt/jwt-ratchet-config.ts +18 -0
  22. package/src/jwt/jwt-ratchet-like.ts +19 -0
  23. package/src/jwt/jwt-ratchet.spec.ts +85 -0
  24. package/src/jwt/jwt-ratchet.ts +204 -0
  25. package/src/stream/buffer-writable.ts +16 -0
  26. package/src/stream/multi-stream.ts +15 -0
  27. package/src/stream/node-stream-ratchet.spec.ts +19 -0
  28. package/src/stream/node-stream-ratchet.ts +70 -0
  29. package/src/stream/string-writable.spec.ts +16 -0
  30. package/src/stream/string-writable.ts +14 -0
  31. package/src/third-party/angular/angular-aot-rollup-plugin.ts +18 -0
  32. package/src/third-party/common-crawl/common-crawl-service.ts +220 -0
  33. package/src/third-party/common-crawl/model/common-crawl-fetch-options.ts +12 -0
  34. package/src/third-party/common-crawl/model/common-crawl-scan.ts +11 -0
  35. package/src/third-party/common-crawl/model/domain-index-entry-raw.ts +14 -0
  36. package/src/third-party/common-crawl/model/index-entry-raw.ts +8 -0
  37. package/src/third-party/common-crawl/model/warc-entry-raw.ts +5 -0
  38. package/src/third-party/common-crawl/model/warc-entry.ts +5 -0
  39. package/src/third-party/git/git-ratchet.spec.ts +11 -0
  40. package/src/third-party/git/git-ratchet.ts +107 -0
  41. package/src/third-party/slack/publish-ci-release-to-slack.spec.ts +28 -0
  42. package/src/third-party/slack/publish-ci-release-to-slack.ts +84 -0
@@ -0,0 +1,12 @@
1
+ export interface CommonCrawlFetchOptions {
2
+ url: string;
3
+ index?: string;
4
+ from?: string;
5
+ to?: string;
6
+ showNumPages?: boolean;
7
+ matchType?: 'exact' | 'prefix' | 'host' | 'domain';
8
+ limit?: number;
9
+ sort?: 'asc' | 'desc';
10
+ page?: number;
11
+ pageSize?: number;
12
+ }
@@ -0,0 +1,11 @@
1
+ import { WarcEntry } from './warc-entry.js';
2
+ import { DomainIndexEntryRaw } from './domain-index-entry-raw.js';
3
+ import { CommonCrawlFetchOptions } from './common-crawl-fetch-options.js';
4
+
5
+ export interface CommonCrawlScan {
6
+ options: CommonCrawlFetchOptions;
7
+ //indexes: IndexEntryRaw[];
8
+ pageIndexes: DomainIndexEntryRaw[];
9
+ parsed: WarcEntry[];
10
+ errors: any[];
11
+ }
@@ -0,0 +1,14 @@
1
+ export interface DomainIndexEntryRaw {
2
+ urlkey: string;
3
+ timestamp: string; // number
4
+ url: string;
5
+ mime: string;
6
+ 'mime-detected': string;
7
+ status: string; //number
8
+ digest: string;
9
+ length: string; //number,
10
+ offset: string; //number
11
+ filename: string;
12
+ languages: string;
13
+ encoding: string;
14
+ }
@@ -0,0 +1,8 @@
1
+ export interface IndexEntryRaw {
2
+ id: string;
3
+ name: string;
4
+ timegate: string; // url
5
+ 'cdx-api': string; // url
6
+ from: string; // timestamp (ISO)
7
+ to: string; // timestamp (ISO)
8
+ }
@@ -0,0 +1,5 @@
1
+ export interface WarcEntryRaw {
2
+ protocol: string;
3
+ headers: Record<string, string>;
4
+ content: Buffer;
5
+ }
@@ -0,0 +1,5 @@
1
+ export interface WarcEntry {
2
+ protocol: string;
3
+ headers: Record<string, string>;
4
+ content: string;
5
+ }
@@ -0,0 +1,11 @@
1
+ import { GitRatchet } from './git-ratchet.js';
2
+ import { describe, expect, test } from 'vitest';
3
+ import { Logger } from '@bitblit/ratchet-common/logger/logger';
4
+
5
+ describe('#gitRatchet', function () {
6
+ test('should fetch last commit data', async () => {
7
+ const res: any = await GitRatchet.getLastCommitSwallowException();
8
+ expect(res).toBeTruthy();
9
+ Logger.info('Got: %j', res);
10
+ }, 10_000); // Ever so often this is slow... and it is really an integration test anyway
11
+ });
@@ -0,0 +1,107 @@
1
+ import process from 'child_process';
2
+ import { EsmRatchet } from '@bitblit/ratchet-common/lang/esm-ratchet';
3
+ import { Logger } from '@bitblit/ratchet-common/logger/logger';
4
+
5
+ // Mainly ripped from https://raw.githubusercontent.com/seymen/git-last-commit/master/source/index.js
6
+ // All credit due to https://github.com/seymen
7
+ export class GitRatchet {
8
+ private static readonly SPLIT_CHARACTER: string = '<##>';
9
+ private static readonly PRETTY_FORMAT: string[] = ['%h', '%H', '%s', '%f', '%b', '%at', '%ct', '%an', '%ae', '%cn', '%ce', '%N', ''];
10
+
11
+ public static async executeCommand(command: string, options: any): Promise<string> {
12
+ let dst: string = EsmRatchet.fetchDirName(import.meta.url);
13
+
14
+ if (!!options && !!options.dst) {
15
+ dst = options.dst;
16
+ }
17
+
18
+ return new Promise<string>((res, rej) => {
19
+ process.exec(command, { cwd: dst }, (err, stdout, stderr) => {
20
+ if (stdout === '') {
21
+ rej('this does not look like a git repo');
22
+ }
23
+
24
+ if (stderr) {
25
+ rej(stderr);
26
+ }
27
+
28
+ res(stdout);
29
+ });
30
+ });
31
+ }
32
+
33
+ private static getCommandString(splitChar: string): string {
34
+ return (
35
+ 'git log -1 --pretty=format:"' +
36
+ GitRatchet.PRETTY_FORMAT.join(splitChar) +
37
+ '"' +
38
+ ' && git rev-parse --abbrev-ref HEAD' +
39
+ ' && git tag --contains HEAD'
40
+ );
41
+ }
42
+
43
+ public static async getLastCommitSwallowException(options: any = {}): Promise<GitCommitData> {
44
+ let rval: GitCommitData = null;
45
+ try {
46
+ rval = await this.getLastCommit(options);
47
+ } catch (err) {
48
+ Logger.warn('Failed to fetch git data : %s', err, err);
49
+ }
50
+ return rval;
51
+ }
52
+
53
+ public static async getLastCommit(options: any = {}): Promise<GitCommitData> {
54
+ const command: string = GitRatchet.getCommandString(GitRatchet.SPLIT_CHARACTER);
55
+
56
+ const res: string = await GitRatchet.executeCommand(command, options);
57
+
58
+ const a: string[] = res.split(GitRatchet.SPLIT_CHARACTER);
59
+
60
+ // e.g. master\n or master\nv1.1\n or master\nv1.1\nv1.2\n
61
+ const branchAndTags: string[] = a[a.length - 1].split('\n').filter((n) => n);
62
+ const branch: string = branchAndTags[0];
63
+ const tags: string[] = branchAndTags.slice(1);
64
+
65
+ const rval: GitCommitData = {
66
+ shortHash: a[0],
67
+ hash: a[1],
68
+ subject: a[2],
69
+ sanitizedSubject: a[3],
70
+ body: a[4],
71
+ authoredOn: a[5],
72
+ committedOn: a[6],
73
+ author: {
74
+ name: a[7],
75
+ email: a[8],
76
+ },
77
+ committer: {
78
+ name: a[9],
79
+ email: a[10],
80
+ },
81
+ notes: a[11],
82
+ branch,
83
+ tags,
84
+ };
85
+ return rval;
86
+ }
87
+ }
88
+
89
+ export interface GitCommitData {
90
+ shortHash: string;
91
+ hash: string;
92
+ subject: string;
93
+ sanitizedSubject: string;
94
+ body: string;
95
+ authoredOn: string;
96
+ committedOn: string;
97
+ author: GitCommitDataPerson;
98
+ committer: GitCommitDataPerson;
99
+ notes: string;
100
+ branch: string;
101
+ tags: string[];
102
+ }
103
+
104
+ export interface GitCommitDataPerson {
105
+ name: string;
106
+ email: string;
107
+ }
@@ -0,0 +1,28 @@
1
+ import { PublishCiReleaseToSlack } from './publish-ci-release-to-slack.js';
2
+ import { describe, expect, test } from 'vitest';
3
+ import { Logger } from '@bitblit/ratchet-common/logger/logger';
4
+ import { GlobalRatchet } from '@bitblit/ratchet-common/lang/global-ratchet';
5
+
6
+ describe('#publishCircleCiReleaseToSlack', function () {
7
+ test.skip('should fail if not in a circle ci environment', async () => {
8
+ try {
9
+ const _result: string = await PublishCiReleaseToSlack.process('https://testslack.erigir.com');
10
+ this.bail();
11
+ } catch (err) {
12
+ Logger.debug('Caught expected error : %s', err);
13
+ // Expected, return ok
14
+ }
15
+ });
16
+
17
+ test.skip('should not fail if in a circle ci environment', async () => {
18
+ GlobalRatchet.setGlobalEnvVar('CIRCLE_BUILD_NUM', '1');
19
+ GlobalRatchet.setGlobalEnvVar('CIRCLE_BRANCH', 'B');
20
+ GlobalRatchet.setGlobalEnvVar('CIRCLE_TAG', 'T');
21
+ GlobalRatchet.setGlobalEnvVar('CIRCLE_SHA1', 'S');
22
+ GlobalRatchet.setGlobalEnvVar('CIRCLE_USERNAME', 'cweiss');
23
+ GlobalRatchet.setGlobalEnvVar('CIRCLE_PROJECT_REPONAME', 'tester');
24
+
25
+ const result: string = await PublishCiReleaseToSlack.process('slackUrlHere');
26
+ expect(result).toEqual('ok');
27
+ });
28
+ });
@@ -0,0 +1,84 @@
1
+ import { DateTime } from 'luxon';
2
+ import fetch from 'cross-fetch';
3
+ import { GitCommitData, GitRatchet } from '../git/git-ratchet.js';
4
+ import { CiRunInformation } from '../../ci/ci-run-information.js';
5
+ import { CiRunInformationUtil } from '../../ci/ci-run-information-util.js';
6
+ import { ErrorRatchet } from '@bitblit/ratchet-common/lang/error-ratchet';
7
+ import { Logger } from '@bitblit/ratchet-common/logger/logger';
8
+ import { StringRatchet } from '@bitblit/ratchet-common/lang/string-ratchet';
9
+
10
+ export class PublishCiReleaseToSlack {
11
+ public static async process(slackHookUrl: string, timezone = 'America/Los_Angeles'): Promise<string> {
12
+ if (!slackHookUrl) {
13
+ throw new Error('slackHookUrl must be defined');
14
+ }
15
+
16
+ const github: CiRunInformation = CiRunInformationUtil.createDefaultGithubActionsRunInformation();
17
+ const circle: CiRunInformation = CiRunInformationUtil.createDefaultCircleCiRunInformation();
18
+ const testing: CiRunInformation = CiRunInformationUtil.createTestingCiRunInformation();
19
+
20
+ const buildNum: string = github.buildNumber || circle.buildNumber || testing.buildNumber;
21
+ const userName: string = github.userName || circle.userName || testing.userName;
22
+ const projectName: string = github.projectName || circle.projectName || testing.projectName;
23
+ const branch: string = github.branch || circle.branch || testing.branch || '';
24
+ const tag: string = github.tag || circle.tag || testing.tag || '';
25
+ const commitHash: string = github.commitHash || circle.commitHash || testing.commitHash || '';
26
+ const localTime: string = DateTime.local().setZone(timezone).toFormat('MMMM Do yyyy, h:mm:ss a z');
27
+ const gitData: GitCommitData = await GitRatchet.getLastCommitSwallowException();
28
+
29
+ if (!buildNum || !userName || !projectName) {
30
+ throw ErrorRatchet.fErr(
31
+ 'Missing at least one of build number, username, or repo name environmental variables : Github : %j CircleCi: %j Testing: %j',
32
+ github,
33
+ circle,
34
+ testing,
35
+ );
36
+ }
37
+
38
+ let message: string = StringRatchet.format('%s performed release %s on %s at %s', userName, tag + ' ' + branch, projectName, localTime);
39
+ if (!!gitData && !!gitData.subject) {
40
+ message += '\n\n' + gitData.subject;
41
+ }
42
+
43
+ Logger.info(
44
+ 'Sending slack notification "%s" with build %s, branch %s, tag %s, sha %s, time: %s, url: %s',
45
+ message,
46
+ buildNum,
47
+ branch,
48
+ tag,
49
+ commitHash,
50
+ localTime,
51
+ StringRatchet.obscure(slackHookUrl, 2),
52
+ );
53
+
54
+ const response: Response = await fetch(slackHookUrl, {
55
+ method: 'POST', // *GET, POST, PUT, DELETE, etc.
56
+ mode: 'cors', // no-cors, cors, *same-origin
57
+ cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
58
+ headers: {
59
+ 'Content-Type': 'application/json',
60
+ },
61
+ redirect: 'follow', // manual, *follow, error
62
+ body: JSON.stringify({ text: message }), // body data type must match "Content-Type" header
63
+ });
64
+ const bodyOut: string = await response.text();
65
+
66
+ Logger.info('Slack returned : %s', bodyOut);
67
+ return bodyOut;
68
+ }
69
+
70
+ /**
71
+ And, in case you are running this command line...
72
+ TODO: should use switches to allow setting the various non-filename params
73
+ **/
74
+ public static async runFromCliArgs(args: string[]): Promise<string> {
75
+ Logger.info('Running PublishCiReleaseToSlack from command line arguments');
76
+ const hook: string = args?.length ? args[0] : null;
77
+ if (hook) {
78
+ return PublishCiReleaseToSlack.process(hook);
79
+ } else {
80
+ Logger.infoP('Usage : ratchet-publish-circle-ci-release-to-slack {hookUrl} ...');
81
+ return null;
82
+ }
83
+ }
84
+ }