@cirrobio/sdk 0.12.9 → 0.12.12

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 (56) hide show
  1. package/dist/index.esm.js.map +1 -1
  2. package/dist/index.js.map +1 -1
  3. package/package.json +3 -2
  4. package/src/api/config.ts +17 -0
  5. package/src/api/error-handler.ts +28 -0
  6. package/src/api/error.ts +8 -0
  7. package/src/api.ts +2 -0
  8. package/src/auth/authentication-provider.ts +26 -0
  9. package/src/auth/current-user.ts +26 -0
  10. package/src/auth/static-token-auth.ts +29 -0
  11. package/src/auth.ts +3 -0
  12. package/src/data/data.service.ts +128 -0
  13. package/src/data.ts +1 -0
  14. package/src/file/__test__/credentials-mutex.spec.ts +44 -0
  15. package/src/file/__test__/extensions.spec.ts +36 -0
  16. package/src/file/__test__/manifest-parser.spec.ts +67 -0
  17. package/src/file/__test__/s3-utils.spec.ts +17 -0
  18. package/src/file/__test__/utils.spec.ts +9 -0
  19. package/src/file/actions/delete.fn.ts +18 -0
  20. package/src/file/actions/sign-url.fn.ts +58 -0
  21. package/src/file/actions/upload.fn.ts +33 -0
  22. package/src/file/calculate-size.ts +14 -0
  23. package/src/file/extensions.fn.ts +88 -0
  24. package/src/file/file.service.ts +90 -0
  25. package/src/file/manifest-parser.ts +63 -0
  26. package/src/file/models/assets.ts +27 -0
  27. package/src/file/models/file-object.model.ts +61 -0
  28. package/src/file/models/file.ts +43 -0
  29. package/src/file/models/folder.ts +27 -0
  30. package/src/file/project-access-context.ts +26 -0
  31. package/src/file/shared.ts +9 -0
  32. package/src/file/util/credentials-mutex.so.ts +33 -0
  33. package/src/file/util/get-display.fn.ts +6 -0
  34. package/src/file/util/get-parent.fn.ts +7 -0
  35. package/src/file/util/s3-client.ts +43 -0
  36. package/src/file/util/s3-utils.ts +14 -0
  37. package/src/file.ts +16 -0
  38. package/src/formatters/__tests__/formatters.spec.ts +101 -0
  39. package/src/formatters/bytes-to-string.ts +32 -0
  40. package/src/formatters/json-pretty-print.ts +8 -0
  41. package/src/formatters/normalize-date.ts +10 -0
  42. package/src/formatters/normalize-string.ts +8 -0
  43. package/src/formatters/slash.ts +18 -0
  44. package/src/formatters/to-date-format.ts +12 -0
  45. package/src/formatters/to-friendly-name.ts +14 -0
  46. package/src/formatters/to-money.ts +13 -0
  47. package/src/formatters/to-pascal-case.ts +16 -0
  48. package/src/formatters/to-title-case.ts +9 -0
  49. package/src/formatters.ts +10 -0
  50. package/src/index.ts +6 -0
  51. package/src/util/__tests__/extract-from-object.spec.ts +29 -0
  52. package/src/util/download.ts +18 -0
  53. package/src/util/extract-from-object.ts +11 -0
  54. package/src/util/get-resource-name.ts +7 -0
  55. package/src/util/handle-promise.ts +7 -0
  56. package/src/util.ts +4 -0
@@ -0,0 +1,14 @@
1
+ import { toTitleCase } from './to-title-case';
2
+
3
+ /**
4
+ * Converts a field name to a more human-readable format.
5
+ * Ex., "helloWorld" -> "Hello World"
6
+ * @param value The value to convert.
7
+ */
8
+ export function toFriendlyName(value: string): string {
9
+ let _value = value.split(/(?=[A-Z])/).join(' ');
10
+ _value = _value.split('_').join(' ');
11
+ _value = _value.split('|').join(' ');
12
+ _value = _value.replace(/ +/g, ' ');
13
+ return toTitleCase(_value);
14
+ }
@@ -0,0 +1,13 @@
1
+ const money = new Intl.NumberFormat('en-US', {
2
+ style: 'currency',
3
+ currency: 'USD',
4
+ });
5
+
6
+ /**
7
+ * Converts a number or bigint to a formatted money string.
8
+ * Ex., 1234.56 -> $1,234.56
9
+ * @param value Input number or bigint value.
10
+ */
11
+ export function toMoney(value: number | bigint): string {
12
+ return money.format(value as number);
13
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Converts a string to PascalCase.
3
+ * Ex., "hello world" -> "HelloWorld"
4
+ * @param value The string to convert.
5
+ */
6
+ export function toPascalCase(value: string): string {
7
+ return value
8
+ // Split on non-alphanumeric characters and spaces
9
+ .split(/[^a-zA-Z0-9]+/)
10
+ // Filter out empty strings
11
+ .filter(word => word.length > 0)
12
+ // Capitalize first letter and lowercase the rest
13
+ .map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
14
+ // Join all words together
15
+ .join('');
16
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Converts a string to Title case.
3
+ * Ex., "hello world" -> "Hello world"
4
+ * @param value
5
+ */
6
+ export function toTitleCase(value: string): string {
7
+ if (!value) return null;
8
+ return value[0].toUpperCase() + value.slice(1).toLowerCase();
9
+ }
@@ -0,0 +1,10 @@
1
+ export { jsonPrettyPrint } from './formatters/json-pretty-print';
2
+ export { bytesToString } from './formatters/bytes-to-string';
3
+ export { normalizeDate } from './formatters/normalize-date';
4
+ export { normalizeString } from './formatters/normalize-string';
5
+ export { removeStartingSlash, removeEndingSlash } from './formatters/slash';
6
+ export { toDateFormat } from './formatters/to-date-format';
7
+ export { toFriendlyName } from './formatters/to-friendly-name';
8
+ export { toMoney } from './formatters/to-money';
9
+ export { toPascalCase } from './formatters/to-pascal-case';
10
+ export { toTitleCase } from './formatters/to-title-case';
package/src/index.ts ADDED
@@ -0,0 +1,6 @@
1
+ export * from './file';
2
+ export * from './api';
3
+ export * from './auth';
4
+ export * from './data';
5
+ export * from './formatters';
6
+ export * from './util';
@@ -0,0 +1,29 @@
1
+ import { extractFromObject } from "../extract-from-object";
2
+
3
+ describe("extractFromObject", () => {
4
+ const obj = {
5
+ user: {
6
+ name: "Cirro",
7
+ age: 30
8
+ },
9
+ test: 'test'
10
+ };
11
+
12
+ it("basic path extraction", () => {
13
+ expect(extractFromObject("$.user.name", obj)).toBe("Cirro");
14
+ expect(extractFromObject("$.user.age", obj)).toBe(30);
15
+ expect(extractFromObject("$.test", obj)).toBe("test");
16
+ });
17
+
18
+ it("should extract entire nested object", () => {
19
+ expect(extractFromObject("$.user", obj)).toEqual(obj.user);
20
+ });
21
+
22
+ it("should return undefined for non-existent property", () => {
23
+ expect(extractFromObject("$.bad", obj)).toBeUndefined();
24
+ });
25
+
26
+ it("should handle empty object", () => {
27
+ expect(extractFromObject("$.name", {})).toBeUndefined();
28
+ });
29
+ });
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Download a blob as a file with the specified file name.
3
+ */
4
+ export function downloadBlob(blob: Blob, fileName: string): void {
5
+ const url = window.URL.createObjectURL(blob);
6
+ const a = document.createElement('a');
7
+ a.href = url;
8
+ a.download = fileName;
9
+ a.click();
10
+ }
11
+
12
+ /**
13
+ * Downloads the specified content as a file with the specified file name and type.
14
+ */
15
+ export function downloadContent(content: any, fileName: string, fileType = 'text/plain'): void {
16
+ const blob = new Blob([content], { type: fileType });
17
+ downloadBlob(blob, fileName);
18
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Extracts a value from an object using the json path notation, i.e. $.test.id
3
+ * @param path JSON path to the value
4
+ * @param obj Object to extract the value from
5
+ */
6
+ export function extractFromObject(path: string, obj: object): any {
7
+ const pathParts = path.slice(2).split('.')
8
+ return pathParts.reduce(function(o, k) {
9
+ return o && o[k];
10
+ }, obj);
11
+ }
@@ -0,0 +1,7 @@
1
+
2
+ const resourcePrefix = 'project-';
3
+
4
+ export function getResourceName(projectId: string): string {
5
+ return `${resourcePrefix}${projectId}`;
6
+ }
7
+
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Ignores dangling promise rejections.
3
+ * @param err The error to ignore.
4
+ */
5
+ export function handlePromiseError(err): void {
6
+ console.warn(err);
7
+ }
package/src/util.ts ADDED
@@ -0,0 +1,4 @@
1
+ export { extractFromObject } from './util/extract-from-object'
2
+ export { handlePromiseError } from './util/handle-promise'
3
+ export { downloadBlob, downloadContent } from './util/download';
4
+ export { getResourceName } from './util/get-resource-name';