@arkebcacy/beacon-cli-temp 0.1.5 → 0.1.6

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 (37) hide show
  1. package/dist/cs/labels/Label.d.ts +8 -0
  2. package/dist/cs/labels/Label.d.ts.map +1 -0
  3. package/dist/cs/labels/Label.js +7 -0
  4. package/dist/cs/labels/Label.js.map +1 -0
  5. package/dist/cs/labels/getAllLabels.d.ts +2 -1
  6. package/dist/cs/labels/getAllLabels.d.ts.map +1 -1
  7. package/dist/cs/labels/getAllLabels.js +24 -4
  8. package/dist/cs/labels/getAllLabels.js.map +1 -1
  9. package/dist/dto/labels/NormalizedLabels.d.ts +13 -0
  10. package/dist/dto/labels/NormalizedLabels.d.ts.map +1 -0
  11. package/dist/dto/labels/NormalizedLabels.js +25 -0
  12. package/dist/dto/labels/NormalizedLabels.js.map +1 -0
  13. package/dist/dto/labels/flatten.d.ts +4 -0
  14. package/dist/dto/labels/flatten.d.ts.map +1 -0
  15. package/dist/dto/labels/flatten.js +18 -0
  16. package/dist/dto/labels/flatten.js.map +1 -0
  17. package/dist/dto/labels/organize.d.ts +4 -0
  18. package/dist/dto/labels/organize.d.ts.map +1 -0
  19. package/dist/dto/labels/organize.js +40 -0
  20. package/dist/dto/labels/organize.js.map +1 -0
  21. package/dist/schema/labels/toContentstack.d.ts.map +1 -1
  22. package/dist/schema/labels/toContentstack.js +33 -10
  23. package/dist/schema/labels/toContentstack.js.map +1 -1
  24. package/dist/schema/labels/toFilesystem.d.ts.map +1 -1
  25. package/dist/schema/labels/toFilesystem.js +5 -6
  26. package/dist/schema/labels/toFilesystem.js.map +1 -1
  27. package/dist/tsconfig.tsbuildinfo +1 -1
  28. package/package.json +1 -1
  29. package/src/cs/labels/Label.ts +16 -0
  30. package/src/cs/labels/getAllLabels.ts +30 -5
  31. package/src/dto/labels/NormalizedLabels.ts +47 -0
  32. package/src/dto/labels/flatten.test.ts +118 -0
  33. package/src/dto/labels/flatten.ts +27 -0
  34. package/src/dto/labels/organize.test.ts +131 -0
  35. package/src/dto/labels/organize.ts +57 -0
  36. package/src/schema/labels/toContentstack.ts +33 -11
  37. package/src/schema/labels/toFilesystem.ts +6 -7
@@ -0,0 +1,8 @@
1
+ import type OmitIndex from '../../util/OmitIndex.js';
2
+ import type { Item } from '../Types.js';
3
+ export default interface Label extends OmitIndex<Item> {
4
+ readonly name: string;
5
+ readonly parent_uid: string | null;
6
+ }
7
+ export declare function isLabel(o: unknown): o is Label;
8
+ //# sourceMappingURL=Label.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Label.d.ts","sourceRoot":"","sources":["../../../src/cs/labels/Label.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,yBAAyB,CAAC;AACrD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAGxC,MAAM,CAAC,OAAO,WAAW,KAAM,SAAQ,SAAS,CAAC,IAAI,CAAC;IACrD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;CACnC;AAED,wBAAgB,OAAO,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,KAAK,CAM9C"}
@@ -0,0 +1,7 @@
1
+ import { isItem } from '../Types.js';
2
+ export function isLabel(o) {
3
+ return (isItem(o) &&
4
+ typeof o.name === 'string' &&
5
+ (o.parent_uid === null || typeof o.parent_uid === 'string'));
6
+ }
7
+ //# sourceMappingURL=Label.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Label.js","sourceRoot":"","sources":["../../../src/cs/labels/Label.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAOrC,MAAM,UAAU,OAAO,CAAC,CAAU;IACjC,OAAO,CACN,MAAM,CAAC,CAAC,CAAC;QACT,OAAO,CAAC,CAAC,IAAI,KAAK,QAAQ;QAC1B,CAAC,CAAC,CAAC,UAAU,KAAK,IAAI,IAAI,OAAO,CAAC,CAAC,UAAU,KAAK,QAAQ,CAAC,CAC3D,CAAC;AACH,CAAC","sourcesContent":["import type OmitIndex from '../../util/OmitIndex.js';\nimport type { Item } from '../Types.js';\nimport { isItem } from '../Types.js';\n\nexport default interface Label extends OmitIndex<Item> {\n\treadonly name: string;\n\treadonly parent_uid: string | null;\n}\n\nexport function isLabel(o: unknown): o is Label {\n\treturn (\n\t\tisItem(o) &&\n\t\ttypeof o.name === 'string' &&\n\t\t(o.parent_uid === null || typeof o.parent_uid === 'string')\n\t);\n}\n"]}
@@ -1,3 +1,4 @@
1
1
  import type Client from '../api/Client.js';
2
- export default function getAllLabels(client: Client): Promise<unknown[]>;
2
+ import type Label from './Label.js';
3
+ export default function getAllLabels(client: Client): Promise<Label[]>;
3
4
  //# sourceMappingURL=getAllLabels.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getAllLabels.d.ts","sourceRoot":"","sources":["../../../src/cs/labels/getAllLabels.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,MAAM,kBAAkB,CAAC;AAG3C,wBAA8B,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAa7E"}
1
+ {"version":3,"file":"getAllLabels.d.ts","sourceRoot":"","sources":["../../../src/cs/labels/getAllLabels.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,MAAM,kBAAkB,CAAC;AAE3C,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AAGpC,wBAA8B,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC,CAoC3E"}
@@ -1,17 +1,37 @@
1
1
  import ContentstackError from '../api/ContentstackError.js';
2
2
  import isRecord from '#cli/util/isRecord.js';
3
+ import { isLabel } from './Label.js';
3
4
  export default async function getAllLabels(client) {
4
5
  const res = (await client.GET('/v3/labels'));
5
6
  const data = res?.data;
6
7
  const error = res?.error;
7
8
  const msg = `Failed to fetch labels`;
8
9
  ContentstackError.throwIfError(error, msg);
10
+ let rawLabels = [];
9
11
  if (isRecord(data) && Array.isArray(data.labels)) {
10
- return data.labels;
12
+ rawLabels = data.labels;
11
13
  }
12
- if (Array.isArray(data)) {
13
- return data;
14
+ else if (Array.isArray(data)) {
15
+ rawLabels = data;
14
16
  }
15
- return [];
17
+ // Transform raw labels to ensure they have parent_uid (null if not present)
18
+ const labels = [];
19
+ for (const raw of rawLabels) {
20
+ if (isRecord(raw) &&
21
+ typeof raw.uid === 'string' &&
22
+ typeof raw.name === 'string') {
23
+ // Preserve all fields from the remote label
24
+ const label = {
25
+ ...raw,
26
+ name: raw.name,
27
+ parent_uid: typeof raw.parent_uid === 'string' ? raw.parent_uid : null,
28
+ uid: raw.uid,
29
+ };
30
+ if (isLabel(label)) {
31
+ labels.push(label);
32
+ }
33
+ }
34
+ }
35
+ return labels;
16
36
  }
17
37
  //# sourceMappingURL=getAllLabels.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"getAllLabels.js","sourceRoot":"","sources":["../../../src/cs/labels/getAllLabels.ts"],"names":[],"mappings":"AAAA,OAAO,iBAAiB,MAAM,6BAA6B,CAAC;AAE5D,OAAO,QAAQ,MAAM,uBAAuB,CAAC;AAE7C,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,YAAY,CAAC,MAAc;IACxD,MAAM,GAAG,GAAG,CAAC,MAAM,MAAM,CAAC,GAAG,CAAC,YAAY,CAAC,CAAY,CAAC;IACxD,MAAM,IAAI,GAAI,GAAsC,EAAE,IAAI,CAAC;IAC3D,MAAM,KAAK,GAAI,GAAuC,EAAE,KAAK,CAAC;IAC9D,MAAM,GAAG,GAAG,wBAAwB,CAAC;IACrC,iBAAiB,CAAC,YAAY,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAC3C,IAAI,QAAQ,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;QAClD,OAAO,IAAI,CAAC,MAAmB,CAAC;IACjC,CAAC;IACD,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QACzB,OAAO,IAAiB,CAAC;IAC1B,CAAC;IACD,OAAO,EAAE,CAAC;AACX,CAAC","sourcesContent":["import ContentstackError from '../api/ContentstackError.js';\nimport type Client from '../api/Client.js';\nimport isRecord from '#cli/util/isRecord.js';\n\nexport default async function getAllLabels(client: Client): Promise<unknown[]> {\n\tconst res = (await client.GET('/v3/labels')) as unknown;\n\tconst data = (res as { data?: unknown } | undefined)?.data;\n\tconst error = (res as { error?: unknown } | undefined)?.error;\n\tconst msg = `Failed to fetch labels`;\n\tContentstackError.throwIfError(error, msg);\n\tif (isRecord(data) && Array.isArray(data.labels)) {\n\t\treturn data.labels as unknown[];\n\t}\n\tif (Array.isArray(data)) {\n\t\treturn data as unknown[];\n\t}\n\treturn [];\n}\n"]}
1
+ {"version":3,"file":"getAllLabels.js","sourceRoot":"","sources":["../../../src/cs/labels/getAllLabels.ts"],"names":[],"mappings":"AAAA,OAAO,iBAAiB,MAAM,6BAA6B,CAAC;AAE5D,OAAO,QAAQ,MAAM,uBAAuB,CAAC;AAE7C,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,YAAY,CAAC,MAAc;IACxD,MAAM,GAAG,GAAG,CAAC,MAAM,MAAM,CAAC,GAAG,CAAC,YAAY,CAAC,CAAY,CAAC;IACxD,MAAM,IAAI,GAAI,GAAsC,EAAE,IAAI,CAAC;IAC3D,MAAM,KAAK,GAAI,GAAuC,EAAE,KAAK,CAAC;IAC9D,MAAM,GAAG,GAAG,wBAAwB,CAAC;IACrC,iBAAiB,CAAC,YAAY,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAE3C,IAAI,SAAS,GAAc,EAAE,CAAC;IAC9B,IAAI,QAAQ,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;QAClD,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC;IACzB,CAAC;SAAM,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QAChC,SAAS,GAAG,IAAI,CAAC;IAClB,CAAC;IAED,4EAA4E;IAC5E,MAAM,MAAM,GAAY,EAAE,CAAC;IAC3B,KAAK,MAAM,GAAG,IAAI,SAAS,EAAE,CAAC;QAC7B,IACC,QAAQ,CAAC,GAAG,CAAC;YACb,OAAO,GAAG,CAAC,GAAG,KAAK,QAAQ;YAC3B,OAAO,GAAG,CAAC,IAAI,KAAK,QAAQ,EAC3B,CAAC;YACF,4CAA4C;YAC5C,MAAM,KAAK,GAAU;gBACpB,GAAG,GAAG;gBACN,IAAI,EAAE,GAAG,CAAC,IAAI;gBACd,UAAU,EAAE,OAAO,GAAG,CAAC,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI;gBACtE,GAAG,EAAE,GAAG,CAAC,GAAG;aACZ,CAAC;YACF,IAAI,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;gBACpB,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACpB,CAAC;QACF,CAAC;IACF,CAAC;IAED,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["import ContentstackError from '../api/ContentstackError.js';\nimport type Client from '../api/Client.js';\nimport isRecord from '#cli/util/isRecord.js';\nimport type Label from './Label.js';\nimport { isLabel } from './Label.js';\n\nexport default async function getAllLabels(client: Client): Promise<Label[]> {\n\tconst res = (await client.GET('/v3/labels')) as unknown;\n\tconst data = (res as { data?: unknown } | undefined)?.data;\n\tconst error = (res as { error?: unknown } | undefined)?.error;\n\tconst msg = `Failed to fetch labels`;\n\tContentstackError.throwIfError(error, msg);\n\n\tlet rawLabels: unknown[] = [];\n\tif (isRecord(data) && Array.isArray(data.labels)) {\n\t\trawLabels = data.labels;\n\t} else if (Array.isArray(data)) {\n\t\trawLabels = data;\n\t}\n\n\t// Transform raw labels to ensure they have parent_uid (null if not present)\n\tconst labels: Label[] = [];\n\tfor (const raw of rawLabels) {\n\t\tif (\n\t\t\tisRecord(raw) &&\n\t\t\ttypeof raw.uid === 'string' &&\n\t\t\ttypeof raw.name === 'string'\n\t\t) {\n\t\t\t// Preserve all fields from the remote label\n\t\t\tconst label: Label = {\n\t\t\t\t...raw,\n\t\t\t\tname: raw.name,\n\t\t\t\tparent_uid: typeof raw.parent_uid === 'string' ? raw.parent_uid : null,\n\t\t\t\tuid: raw.uid,\n\t\t\t};\n\t\t\tif (isLabel(label)) {\n\t\t\t\tlabels.push(label);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn labels;\n}\n"]}
@@ -0,0 +1,13 @@
1
+ import type Label from '#cli/cs/labels/Label.js';
2
+ export default interface NormalizedLabels {
3
+ readonly labels: readonly LabelTreeNode[];
4
+ }
5
+ export interface LabelTreeNode {
6
+ readonly [key: string]: unknown;
7
+ readonly uid: Label['uid'];
8
+ readonly name: Label['name'];
9
+ readonly children?: readonly LabelTreeNode[];
10
+ }
11
+ export declare function key(): string;
12
+ export declare function isNormalizedLabels(value: unknown): value is NormalizedLabels & Record<string, unknown>;
13
+ //# sourceMappingURL=NormalizedLabels.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NormalizedLabels.d.ts","sourceRoot":"","sources":["../../../src/dto/labels/NormalizedLabels.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,yBAAyB,CAAC;AAGjD,MAAM,CAAC,OAAO,WAAW,gBAAgB;IACxC,QAAQ,CAAC,MAAM,EAAE,SAAS,aAAa,EAAE,CAAC;CAC1C;AAED,MAAM,WAAW,aAAa;IAE7B,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;IAChC,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC7B,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,aAAa,EAAE,CAAC;CAC7C;AAED,wBAAgB,GAAG,WAElB;AAED,wBAAgB,kBAAkB,CACjC,KAAK,EAAE,OAAO,GACZ,KAAK,IAAI,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAMrD"}
@@ -0,0 +1,25 @@
1
+ import isRecord from '#cli/util/isRecord.js';
2
+ import { isItem } from '#cli/cs/Types.js';
3
+ export function key() {
4
+ return 'labels';
5
+ }
6
+ export function isNormalizedLabels(value) {
7
+ if (!isRecord(value)) {
8
+ return false;
9
+ }
10
+ return Array.isArray(value.labels) && value.labels.every(isLabelTreeNode);
11
+ }
12
+ function isLabelTreeNode(value) {
13
+ if (!isItem(value)) {
14
+ return false;
15
+ }
16
+ if (typeof value.name !== 'string') {
17
+ return false;
18
+ }
19
+ if (!('children' in value)) {
20
+ return true;
21
+ }
22
+ const { children } = value;
23
+ return Array.isArray(children) && children.every(isLabelTreeNode);
24
+ }
25
+ //# sourceMappingURL=NormalizedLabels.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NormalizedLabels.js","sourceRoot":"","sources":["../../../src/dto/labels/NormalizedLabels.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,uBAAuB,CAAC;AAE7C,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAc1C,MAAM,UAAU,GAAG;IAClB,OAAO,QAAQ,CAAC;AACjB,CAAC;AAED,MAAM,UAAU,kBAAkB,CACjC,KAAc;IAEd,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QACtB,OAAO,KAAK,CAAC;IACd,CAAC;IAED,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;AAC3E,CAAC;AAED,SAAS,eAAe,CAAC,KAAc;IACtC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QACpB,OAAO,KAAK,CAAC;IACd,CAAC;IAED,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QACpC,OAAO,KAAK,CAAC;IACd,CAAC;IAED,IAAI,CAAC,CAAC,UAAU,IAAI,KAAK,CAAC,EAAE,CAAC;QAC5B,OAAO,IAAI,CAAC;IACb,CAAC;IAED,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IAE3B,OAAO,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;AACnE,CAAC","sourcesContent":["import isRecord from '#cli/util/isRecord.js';\nimport type Label from '#cli/cs/labels/Label.js';\nimport { isItem } from '#cli/cs/Types.js';\n\nexport default interface NormalizedLabels {\n\treadonly labels: readonly LabelTreeNode[];\n}\n\nexport interface LabelTreeNode {\n\t// Allow any additional fields from the label\n\treadonly [key: string]: unknown;\n\treadonly uid: Label['uid'];\n\treadonly name: Label['name'];\n\treadonly children?: readonly LabelTreeNode[];\n}\n\nexport function key() {\n\treturn 'labels';\n}\n\nexport function isNormalizedLabels(\n\tvalue: unknown,\n): value is NormalizedLabels & Record<string, unknown> {\n\tif (!isRecord(value)) {\n\t\treturn false;\n\t}\n\n\treturn Array.isArray(value.labels) && value.labels.every(isLabelTreeNode);\n}\n\nfunction isLabelTreeNode(value: unknown): value is LabelTreeNode {\n\tif (!isItem(value)) {\n\t\treturn false;\n\t}\n\n\tif (typeof value.name !== 'string') {\n\t\treturn false;\n\t}\n\n\tif (!('children' in value)) {\n\t\treturn true;\n\t}\n\n\tconst { children } = value;\n\n\treturn Array.isArray(children) && children.every(isLabelTreeNode);\n}\n"]}
@@ -0,0 +1,4 @@
1
+ import type Label from '#cli/cs/labels/Label.js';
2
+ import type { LabelTreeNode } from './NormalizedLabels.js';
3
+ export default function flatten(labels: readonly LabelTreeNode[]): readonly Label[];
4
+ //# sourceMappingURL=flatten.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flatten.d.ts","sourceRoot":"","sources":["../../../src/dto/labels/flatten.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,yBAAyB,CAAC;AACjD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAE3D,MAAM,CAAC,OAAO,UAAU,OAAO,CAC9B,MAAM,EAAE,SAAS,aAAa,EAAE,GAC9B,SAAS,KAAK,EAAE,CAqBlB"}
@@ -0,0 +1,18 @@
1
+ export default function flatten(labels) {
2
+ const result = [];
3
+ function traverse(nodes, parentUid) {
4
+ for (const node of nodes) {
5
+ const { children, ...label } = node;
6
+ result.push({
7
+ ...label,
8
+ parent_uid: parentUid,
9
+ });
10
+ if (children) {
11
+ traverse(children, node.uid);
12
+ }
13
+ }
14
+ }
15
+ traverse(labels, null);
16
+ return result;
17
+ }
18
+ //# sourceMappingURL=flatten.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flatten.js","sourceRoot":"","sources":["../../../src/dto/labels/flatten.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,OAAO,UAAU,OAAO,CAC9B,MAAgC;IAEhC,MAAM,MAAM,GAAY,EAAE,CAAC;IAE3B,SAAS,QAAQ,CAAC,KAA+B,EAAE,SAAwB;QAC1E,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YAC1B,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,GAAG,IAAI,CAAC;YAEpC,MAAM,CAAC,IAAI,CAAC;gBACX,GAAG,KAAK;gBACR,UAAU,EAAE,SAAS;aACZ,CAAC,CAAC;YAEZ,IAAI,QAAQ,EAAE,CAAC;gBACd,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;YAC9B,CAAC;QACF,CAAC;IACF,CAAC;IAED,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAEvB,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["import type Label from '#cli/cs/labels/Label.js';\nimport type { LabelTreeNode } from './NormalizedLabels.js';\n\nexport default function flatten(\n\tlabels: readonly LabelTreeNode[],\n): readonly Label[] {\n\tconst result: Label[] = [];\n\n\tfunction traverse(nodes: readonly LabelTreeNode[], parentUid: string | null) {\n\t\tfor (const node of nodes) {\n\t\t\tconst { children, ...label } = node;\n\n\t\t\tresult.push({\n\t\t\t\t...label,\n\t\t\t\tparent_uid: parentUid,\n\t\t\t} as Label);\n\n\t\t\tif (children) {\n\t\t\t\ttraverse(children, node.uid);\n\t\t\t}\n\t\t}\n\t}\n\n\ttraverse(labels, null);\n\n\treturn result;\n}\n"]}
@@ -0,0 +1,4 @@
1
+ import type Label from '#cli/cs/labels/Label.js';
2
+ import type { LabelTreeNode } from './NormalizedLabels.js';
3
+ export default function organize(labels: readonly Label[]): readonly LabelTreeNode[];
4
+ //# sourceMappingURL=organize.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"organize.d.ts","sourceRoot":"","sources":["../../../src/dto/labels/organize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,yBAAyB,CAAC;AACjD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAW3D,MAAM,CAAC,OAAO,UAAU,QAAQ,CAC/B,MAAM,EAAE,SAAS,KAAK,EAAE,GACtB,SAAS,aAAa,EAAE,CAmC1B"}
@@ -0,0 +1,40 @@
1
+ // Labels have a tree structure defined by uid/parent_uid.
2
+ //
3
+ // The API returns a flat array that includes uid/parent_uid, but
4
+ // leaves it up to the client to reconstruct the tree.
5
+ //
6
+ // We organize labels into a tree structure for serialization.
7
+ //
8
+ // The sort order amongst siblings is maintained equal to the order
9
+ // as it appears in the array.
10
+ export default function organize(labels) {
11
+ const byUid = new Map();
12
+ const topLevel = [];
13
+ for (const label of labels) {
14
+ const { parent_uid, ...labelWithoutParent } = label;
15
+ // Preserve all fields except parent_uid (which is represented by the tree structure)
16
+ byUid.set(label.uid, {
17
+ ...labelWithoutParent,
18
+ name: label.name,
19
+ uid: label.uid,
20
+ });
21
+ }
22
+ for (const { uid, parent_uid } of labels) {
23
+ const label = byUid.get(uid);
24
+ if (!label) {
25
+ throw new Error(`Label ${uid} not found`);
26
+ }
27
+ if (!parent_uid) {
28
+ topLevel.push(label);
29
+ continue;
30
+ }
31
+ const parent = byUid.get(parent_uid);
32
+ if (!parent) {
33
+ const msg = `Orphaned label ${uid} with parent ${parent_uid}`;
34
+ throw new Error(msg);
35
+ }
36
+ (parent.children ??= []).push(label);
37
+ }
38
+ return topLevel;
39
+ }
40
+ //# sourceMappingURL=organize.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"organize.js","sourceRoot":"","sources":["../../../src/dto/labels/organize.ts"],"names":[],"mappings":"AAGA,0DAA0D;AAC1D,EAAE;AACF,iEAAiE;AACjE,sDAAsD;AACtD,EAAE;AACF,8DAA8D;AAC9D,EAAE;AACF,mEAAmE;AACnE,8BAA8B;AAC9B,MAAM,CAAC,OAAO,UAAU,QAAQ,CAC/B,MAAwB;IAExB,MAAM,KAAK,GAAG,IAAI,GAAG,EAAuB,CAAC;IAC7C,MAAM,QAAQ,GAAkB,EAAE,CAAC;IAEnC,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC5B,MAAM,EAAE,UAAU,EAAE,GAAG,kBAAkB,EAAE,GAAG,KAAK,CAAC;QACpD,qFAAqF;QACrF,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE;YACpB,GAAG,kBAAkB;YACrB,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,GAAG,EAAE,KAAK,CAAC,GAAG;SACd,CAAC,CAAC;IACJ,CAAC;IAED,KAAK,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,IAAI,MAAM,EAAE,CAAC;QAC1C,MAAM,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC7B,IAAI,CAAC,KAAK,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CAAC,SAAS,GAAG,YAAY,CAAC,CAAC;QAC3C,CAAC;QAED,IAAI,CAAC,UAAU,EAAE,CAAC;YACjB,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACrB,SAAS;QACV,CAAC;QAED,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QACrC,IAAI,CAAC,MAAM,EAAE,CAAC;YACb,MAAM,GAAG,GAAG,kBAAkB,GAAG,gBAAgB,UAAU,EAAE,CAAC;YAC9D,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC;QACtB,CAAC;QAED,CAAC,MAAM,CAAC,QAAQ,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACtC,CAAC;IAED,OAAO,QAAQ,CAAC;AACjB,CAAC","sourcesContent":["import type Label from '#cli/cs/labels/Label.js';\nimport type { LabelTreeNode } from './NormalizedLabels.js';\n\n// Labels have a tree structure defined by uid/parent_uid.\n//\n// The API returns a flat array that includes uid/parent_uid, but\n// leaves it up to the client to reconstruct the tree.\n//\n// We organize labels into a tree structure for serialization.\n//\n// The sort order amongst siblings is maintained equal to the order\n// as it appears in the array.\nexport default function organize(\n\tlabels: readonly Label[],\n): readonly LabelTreeNode[] {\n\tconst byUid = new Map<string, MutableNode>();\n\tconst topLevel: MutableNode[] = [];\n\n\tfor (const label of labels) {\n\t\tconst { parent_uid, ...labelWithoutParent } = label;\n\t\t// Preserve all fields except parent_uid (which is represented by the tree structure)\n\t\tbyUid.set(label.uid, {\n\t\t\t...labelWithoutParent,\n\t\t\tname: label.name,\n\t\t\tuid: label.uid,\n\t\t});\n\t}\n\n\tfor (const { uid, parent_uid } of labels) {\n\t\tconst label = byUid.get(uid);\n\t\tif (!label) {\n\t\t\tthrow new Error(`Label ${uid} not found`);\n\t\t}\n\n\t\tif (!parent_uid) {\n\t\t\ttopLevel.push(label);\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst parent = byUid.get(parent_uid);\n\t\tif (!parent) {\n\t\t\tconst msg = `Orphaned label ${uid} with parent ${parent_uid}`;\n\t\t\tthrow new Error(msg);\n\t\t}\n\n\t\t(parent.children ??= []).push(label);\n\t}\n\n\treturn topLevel;\n}\n\ninterface MutableNode {\n\t[key: string]: unknown;\n\treadonly uid: string;\n\treadonly name: string;\n\tchildren?: MutableNode[];\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"toContentstack.d.ts","sourceRoot":"","sources":["../../../src/schema/labels/toContentstack.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,GAAG,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAIpE,wBAA8B,cAAc,CAAC,GAAG,EAAE,GAAG,mCAiCpD"}
1
+ {"version":3,"file":"toContentstack.d.ts","sourceRoot":"","sources":["../../../src/schema/labels/toContentstack.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,GAAG,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAOpE,wBAA8B,cAAc,CAAC,GAAG,EAAE,GAAG,mCAuCpD"}
@@ -4,6 +4,8 @@ import ContentstackError from '#cli/cs/api/ContentstackError.js';
4
4
  import { MutableTransferResults } from '../xfer/TransferResults.js';
5
5
  import getUi from '../lib/SchemaUi.js';
6
6
  import isRecord from '#cli/util/isRecord.js';
7
+ import flatten from '#cli/dto/labels/flatten.js';
8
+ import { isNormalizedLabels } from '#cli/dto/labels/NormalizedLabels.js';
7
9
  export default async function toContentstack(ctx) {
8
10
  const directory = schemaDirectory();
9
11
  const path = `${directory}/labels.yaml`;
@@ -16,14 +18,23 @@ export default async function toContentstack(ctx) {
16
18
  ui.info(`Labels: no file at ${path}, skipping`);
17
19
  return new MutableTransferResults();
18
20
  }
19
- const labels = isRecord(data) && Array.isArray(data.labels)
20
- ? data.labels
21
- : Array.isArray(data)
22
- ? data
23
- : [];
24
- ui.info(`Labels: read ${labels.length} label(s) from ${path}`);
21
+ // Support both hierarchical and flat label structures
22
+ let flatLabels = [];
23
+ if (isNormalizedLabels(data)) {
24
+ // Hierarchical structure - flatten it first
25
+ flatLabels = [...flatten(data.labels)];
26
+ }
27
+ else if (isRecord(data) && Array.isArray(data.labels)) {
28
+ // Legacy flat array format
29
+ flatLabels = data.labels;
30
+ }
31
+ else if (Array.isArray(data)) {
32
+ // Direct array format
33
+ flatLabels = data;
34
+ }
35
+ ui.info(`Labels: read ${flatLabels.length} label(s) from ${path}`);
25
36
  const results = new MutableTransferResults();
26
- for (const labelRaw of labels) {
37
+ for (const labelRaw of flatLabels) {
27
38
  if (!isRecord(labelRaw))
28
39
  continue;
29
40
  // keep per-label logic in helper to reduce complexity of this function
@@ -40,6 +51,9 @@ function canonicalize(value) {
40
51
  for (const key of Object.keys(obj).sort()) {
41
52
  if (key === 'uid' || key === 'created_at' || key === 'updated_at')
42
53
  continue;
54
+ // Normalize parent_uid: skip if null or undefined
55
+ if (key === 'parent_uid' && (obj[key] === null || obj[key] === undefined))
56
+ continue;
43
57
  out[key] = canonicalize(obj[key]);
44
58
  }
45
59
  return out;
@@ -54,7 +68,7 @@ async function updateIfNecessary(ctx, uid, localLabel, results) {
54
68
  if (!isRecord(remoteData) || !isRecord(remoteData.label)) {
55
69
  // If we can't parse remote data, err on the side of updating
56
70
  const res = (await ctx.cs.client.PUT('/v3/labels/{label_uid}', {
57
- body: { label: localLabel },
71
+ body: { label: prepareLabel(localLabel) },
58
72
  params: { path: { label_uid: uid } },
59
73
  }));
60
74
  const putError = res?.error;
@@ -75,7 +89,7 @@ async function updateIfNecessary(ctx, uid, localLabel, results) {
75
89
  if (!shouldUpdate)
76
90
  return;
77
91
  const res = (await ctx.cs.client.PUT('/v3/labels/{label_uid}', {
78
- body: { label: localLabel },
92
+ body: { label: prepareLabel(localLabel) },
79
93
  params: { path: { label_uid: uid } },
80
94
  }));
81
95
  const putError = res?.error;
@@ -84,7 +98,7 @@ async function updateIfNecessary(ctx, uid, localLabel, results) {
84
98
  }
85
99
  async function createLabel(ctx, localLabel, results) {
86
100
  const res = (await ctx.cs.client.POST('/v3/labels', {
87
- body: { label: localLabel },
101
+ body: { label: prepareLabel(localLabel) },
88
102
  }));
89
103
  const postError = res?.error;
90
104
  ContentstackError.throwIfError(postError, `Failed to create label`);
@@ -102,6 +116,15 @@ async function createLabel(ctx, localLabel, results) {
102
116
  }
103
117
  results.created.add(createdUid ?? '<created>');
104
118
  }
119
+ // Prepare label for API by removing parent_uid if null
120
+ function prepareLabel(label) {
121
+ const { parent_uid, ...rest } = label;
122
+ // Only include parent_uid if it's a non-null string
123
+ if (typeof parent_uid === 'string') {
124
+ return { ...rest, parent_uid };
125
+ }
126
+ return rest;
127
+ }
105
128
  async function handleLabel(ctx, labelRaw, results) {
106
129
  const uid = typeof labelRaw.uid === 'string' ? labelRaw.uid : '';
107
130
  if (uid.length) {
@@ -1 +1 @@
1
- {"version":3,"file":"toContentstack.js","sourceRoot":"","sources":["../../../src/schema/labels/toContentstack.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,qBAAqB,CAAC;AAC3C,OAAO,eAAe,MAAM,qCAAqC,CAAC;AAClE,OAAO,iBAAiB,MAAM,kCAAkC,CAAC;AAEjE,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,KAAK,MAAM,oBAAoB,CAAC;AACvC,OAAO,QAAQ,MAAM,uBAAuB,CAAC;AAE7C,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,cAAc,CAAC,GAAQ;IACpD,MAAM,SAAS,GAAG,eAAe,EAAE,CAAC;IACpC,MAAM,IAAI,GAAG,GAAG,SAAS,cAAc,CAAC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;QACxB,MAAM,EAAE,GAAG,QAAQ,CAAC;QACpB,IAAI,QAAQ,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC;YACxB,MAAM,QAAQ,GAAG,EAAE,CAAC,KAAK,CAAC;YAC1B,IAAI,OAAO,QAAQ,CAAC,GAAG,KAAK,QAAQ;gBAAE,UAAU,GAAG,QAAQ,CAAC,GAAG,CAAC;QACjE,CAAC;QACD,IAAI,UAAU,KAAK,IAAI,IAAI,OAAO,EAAE,CAAC,GAAG,KAAK,QAAQ;YAAE,UAAU,GAAG,EAAE,CAAC,GAAG,CAAC;IAC5E,CAAC;IACD,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,IAAI,WAAW,CAAC,CAAC;AAChD,CAAC;AAED,KAAK,UAAU,WAAW,CACzB,GAAQ,EACR,QAAiC,EACjC,OAA+B;IAE/B,MAAM,GAAG,GAAG,OAAO,QAAQ,CAAC,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IAEjE,IAAI,GAAG,CAAC,MAAM,EAAE,CAAC;QAChB,MAAM,iBAAiB,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;QACrD,OAAO;IACR,CAAC;IAED,MAAM,WAAW,CAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;AAC3C,CAAC","sourcesContent":["import readYaml from '#cli/fs/readYaml.js';\nimport schemaDirectory from '../content-types/schemaDirectory.js';\nimport ContentstackError from '#cli/cs/api/ContentstackError.js';\nimport type Ctx from '../ctx/Ctx.js';\nimport { MutableTransferResults } from '../xfer/TransferResults.js';\nimport getUi from '../lib/SchemaUi.js';\nimport isRecord from '#cli/util/isRecord.js';\n\nexport default async function toContentstack(ctx: Ctx) {\n\tconst directory = schemaDirectory();\n\tconst path = `${directory}/labels.yaml`;\n\n\tconst ui = getUi();\n\n\tlet data: unknown;\n\ttry {\n\t\tdata = await readYaml(path);\n\t} catch {\n\t\tui.info(`Labels: no file at ${path}, skipping`);\n\t\treturn new MutableTransferResults();\n\t}\n\n\tconst labels =\n\t\tisRecord(data) && Array.isArray(data.labels)\n\t\t\t? data.labels\n\t\t\t: Array.isArray(data)\n\t\t\t\t? (data as unknown[])\n\t\t\t\t: [];\n\n\tui.info(`Labels: read ${labels.length} label(s) from ${path}`);\n\n\tconst results = new MutableTransferResults();\n\n\tfor (const labelRaw of labels) {\n\t\tif (!isRecord(labelRaw)) continue;\n\t\t// keep per-label logic in helper to reduce complexity of this function\n\n\t\tawait handleLabel(ctx, labelRaw, results);\n\t}\n\n\treturn results;\n}\n\nfunction canonicalize(value: unknown): unknown {\n\tif (Array.isArray(value)) return value.map(canonicalize);\n\tif (isRecord(value)) {\n\t\tconst obj = value;\n\t\tconst out: Record<string, unknown> = {};\n\t\tfor (const key of Object.keys(obj).sort()) {\n\t\t\tif (key === 'uid' || key === 'created_at' || key === 'updated_at')\n\t\t\t\tcontinue;\n\t\t\tout[key] = canonicalize(obj[key]);\n\t\t}\n\t\treturn out;\n\t}\n\treturn value;\n}\n\nasync function updateIfNecessary(\n\tctx: Ctx,\n\tuid: string,\n\tlocalLabel: Record<string, unknown>,\n\tresults: MutableTransferResults,\n) {\n\tconst remoteRes = (await ctx.cs.client.GET('/v3/labels/{label_uid}', {\n\t\tparams: { path: { label_uid: uid } },\n\t})) as unknown;\n\tconst remoteData = (remoteRes as { data?: unknown } | undefined)?.data;\n\n\tif (!isRecord(remoteData) || !isRecord(remoteData.label)) {\n\t\t// If we can't parse remote data, err on the side of updating\n\t\tconst res = (await ctx.cs.client.PUT('/v3/labels/{label_uid}', {\n\t\t\tbody: { label: localLabel },\n\t\t\tparams: { path: { label_uid: uid } },\n\t\t})) as unknown;\n\t\tconst putError = (res as { error?: unknown } | undefined)?.error;\n\t\tContentstackError.throwIfError(putError, `Failed to update label: ${uid}`);\n\t\tresults.updated.add(uid);\n\t\treturn;\n\t}\n\n\tconst remoteLabel = remoteData.label;\n\tlet shouldUpdate = true;\n\ttry {\n\t\tshouldUpdate =\n\t\t\tJSON.stringify(canonicalize(localLabel)) !==\n\t\t\tJSON.stringify(canonicalize(remoteLabel));\n\t} catch {\n\t\tshouldUpdate = true;\n\t}\n\n\tif (!shouldUpdate) return;\n\n\tconst res = (await ctx.cs.client.PUT('/v3/labels/{label_uid}', {\n\t\tbody: { label: localLabel },\n\t\tparams: { path: { label_uid: uid } },\n\t})) as unknown;\n\tconst putError = (res as { error?: unknown } | undefined)?.error;\n\tContentstackError.throwIfError(putError, `Failed to update label: ${uid}`);\n\tresults.updated.add(uid);\n}\n\nasync function createLabel(\n\tctx: Ctx,\n\tlocalLabel: Record<string, unknown>,\n\tresults: MutableTransferResults,\n) {\n\tconst res = (await ctx.cs.client.POST('/v3/labels', {\n\t\tbody: { label: localLabel },\n\t})) as unknown;\n\tconst postError = (res as { error?: unknown } | undefined)?.error;\n\tContentstackError.throwIfError(postError, `Failed to create label`);\n\tconst postData = (res as { data?: unknown } | undefined)?.data;\n\tlet createdUid: string | null = null;\n\tif (isRecord(postData)) {\n\t\tconst pd = postData;\n\t\tif (isRecord(pd.label)) {\n\t\t\tconst labelObj = pd.label;\n\t\t\tif (typeof labelObj.uid === 'string') createdUid = labelObj.uid;\n\t\t}\n\t\tif (createdUid === null && typeof pd.uid === 'string') createdUid = pd.uid;\n\t}\n\tresults.created.add(createdUid ?? '<created>');\n}\n\nasync function handleLabel(\n\tctx: Ctx,\n\tlabelRaw: Record<string, unknown>,\n\tresults: MutableTransferResults,\n) {\n\tconst uid = typeof labelRaw.uid === 'string' ? labelRaw.uid : '';\n\n\tif (uid.length) {\n\t\tawait updateIfNecessary(ctx, uid, labelRaw, results);\n\t\treturn;\n\t}\n\n\tawait createLabel(ctx, labelRaw, results);\n}\n"]}
1
+ {"version":3,"file":"toContentstack.js","sourceRoot":"","sources":["../../../src/schema/labels/toContentstack.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ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,EAAE,CAAC,GAAG,KAAK,QAAQ;YAAE,UAAU,GAAG,EAAE,CAAC,GAAG,CAAC;IAC5E,CAAC;IACD,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,IAAI,WAAW,CAAC,CAAC;AAChD,CAAC;AAED,uDAAuD;AACvD,SAAS,YAAY,CAAC,KAA8B;IACnD,MAAM,EAAE,UAAU,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC;IACtC,oDAAoD;IACpD,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;QACpC,OAAO,EAAE,GAAG,IAAI,EAAE,UAAU,EAAE,CAAC;IAChC,CAAC;IACD,OAAO,IAAI,CAAC;AACb,CAAC;AAED,KAAK,UAAU,WAAW,CACzB,GAAQ,EACR,QAAiC,EACjC,OAA+B;IAE/B,MAAM,GAAG,GAAG,OAAO,QAAQ,CAAC,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IAEjE,IAAI,GAAG,CAAC,MAAM,EAAE,CAAC;QAChB,MAAM,iBAAiB,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;QACrD,OAAO;IACR,CAAC;IAED,MAAM,WAAW,CAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;AAC3C,CAAC","sourcesContent":["import readYaml from '#cli/fs/readYaml.js';\nimport schemaDirectory from '../content-types/schemaDirectory.js';\nimport ContentstackError from '#cli/cs/api/ContentstackError.js';\nimport type Ctx from '../ctx/Ctx.js';\nimport { MutableTransferResults } from '../xfer/TransferResults.js';\nimport getUi from '../lib/SchemaUi.js';\nimport isRecord from '#cli/util/isRecord.js';\nimport flatten from '#cli/dto/labels/flatten.js';\nimport { isNormalizedLabels } from '#cli/dto/labels/NormalizedLabels.js';\nimport type Label from '#cli/cs/labels/Label.js';\n\nexport default async function toContentstack(ctx: Ctx) {\n\tconst directory = schemaDirectory();\n\tconst path = `${directory}/labels.yaml`;\n\n\tconst ui = getUi();\n\n\tlet data: unknown;\n\ttry {\n\t\tdata = await readYaml(path);\n\t} catch {\n\t\tui.info(`Labels: no file at ${path}, skipping`);\n\t\treturn new MutableTransferResults();\n\t}\n\n\t// Support both hierarchical and flat label structures\n\tlet flatLabels: Label[] = [];\n\tif (isNormalizedLabels(data)) {\n\t\t// Hierarchical structure - flatten it first\n\t\tflatLabels = [...flatten(data.labels)];\n\t} else if (isRecord(data) && Array.isArray(data.labels)) {\n\t\t// Legacy flat array format\n\t\tflatLabels = data.labels as Label[];\n\t} else if (Array.isArray(data)) {\n\t\t// Direct array format\n\t\tflatLabels = data as Label[];\n\t}\n\n\tui.info(`Labels: read ${flatLabels.length} label(s) from ${path}`);\n\n\tconst results = new MutableTransferResults();\n\n\tfor (const labelRaw of flatLabels) {\n\t\tif (!isRecord(labelRaw)) continue;\n\t\t// keep per-label logic in helper to reduce complexity of this function\n\n\t\tawait handleLabel(ctx, labelRaw, results);\n\t}\n\n\treturn results;\n}\n\nfunction canonicalize(value: unknown): unknown {\n\tif (Array.isArray(value)) return value.map(canonicalize);\n\tif (isRecord(value)) {\n\t\tconst obj = value;\n\t\tconst out: Record<string, unknown> = {};\n\t\tfor (const key of Object.keys(obj).sort()) {\n\t\t\tif (key === 'uid' || key === 'created_at' || key === 'updated_at')\n\t\t\t\tcontinue;\n\t\t\t// Normalize parent_uid: skip if null or undefined\n\t\t\tif (key === 'parent_uid' && (obj[key] === null || obj[key] === undefined))\n\t\t\t\tcontinue;\n\t\t\tout[key] = canonicalize(obj[key]);\n\t\t}\n\t\treturn out;\n\t}\n\treturn value;\n}\n\nasync function updateIfNecessary(\n\tctx: Ctx,\n\tuid: string,\n\tlocalLabel: Record<string, unknown>,\n\tresults: MutableTransferResults,\n) {\n\tconst remoteRes = (await ctx.cs.client.GET('/v3/labels/{label_uid}', {\n\t\tparams: { path: { label_uid: uid } },\n\t})) as unknown;\n\tconst remoteData = (remoteRes as { data?: unknown } | undefined)?.data;\n\n\tif (!isRecord(remoteData) || !isRecord(remoteData.label)) {\n\t\t// If we can't parse remote data, err on the side of updating\n\t\tconst res = (await ctx.cs.client.PUT('/v3/labels/{label_uid}', {\n\t\t\tbody: { label: prepareLabel(localLabel) },\n\t\t\tparams: { path: { label_uid: uid } },\n\t\t})) as unknown;\n\t\tconst putError = (res as { error?: unknown } | undefined)?.error;\n\t\tContentstackError.throwIfError(putError, `Failed to update label: ${uid}`);\n\t\tresults.updated.add(uid);\n\t\treturn;\n\t}\n\n\tconst remoteLabel = remoteData.label;\n\tlet shouldUpdate = true;\n\ttry {\n\t\tshouldUpdate =\n\t\t\tJSON.stringify(canonicalize(localLabel)) !==\n\t\t\tJSON.stringify(canonicalize(remoteLabel));\n\t} catch {\n\t\tshouldUpdate = true;\n\t}\n\n\tif (!shouldUpdate) return;\n\n\tconst res = (await ctx.cs.client.PUT('/v3/labels/{label_uid}', {\n\t\tbody: { label: prepareLabel(localLabel) },\n\t\tparams: { path: { label_uid: uid } },\n\t})) as unknown;\n\tconst putError = (res as { error?: unknown } | undefined)?.error;\n\tContentstackError.throwIfError(putError, `Failed to update label: ${uid}`);\n\tresults.updated.add(uid);\n}\n\nasync function createLabel(\n\tctx: Ctx,\n\tlocalLabel: Record<string, unknown>,\n\tresults: MutableTransferResults,\n) {\n\tconst res = (await ctx.cs.client.POST('/v3/labels', {\n\t\tbody: { label: prepareLabel(localLabel) },\n\t})) as unknown;\n\tconst postError = (res as { error?: unknown } | undefined)?.error;\n\tContentstackError.throwIfError(postError, `Failed to create label`);\n\tconst postData = (res as { data?: unknown } | undefined)?.data;\n\tlet createdUid: string | null = null;\n\tif (isRecord(postData)) {\n\t\tconst pd = postData;\n\t\tif (isRecord(pd.label)) {\n\t\t\tconst labelObj = pd.label;\n\t\t\tif (typeof labelObj.uid === 'string') createdUid = labelObj.uid;\n\t\t}\n\t\tif (createdUid === null && typeof pd.uid === 'string') createdUid = pd.uid;\n\t}\n\tresults.created.add(createdUid ?? '<created>');\n}\n\n// Prepare label for API by removing parent_uid if null\nfunction prepareLabel(label: Record<string, unknown>): Record<string, unknown> {\n\tconst { parent_uid, ...rest } = label;\n\t// Only include parent_uid if it's a non-null string\n\tif (typeof parent_uid === 'string') {\n\t\treturn { ...rest, parent_uid };\n\t}\n\treturn rest;\n}\n\nasync function handleLabel(\n\tctx: Ctx,\n\tlabelRaw: Record<string, unknown>,\n\tresults: MutableTransferResults,\n) {\n\tconst uid = typeof labelRaw.uid === 'string' ? labelRaw.uid : '';\n\n\tif (uid.length) {\n\t\tawait updateIfNecessary(ctx, uid, labelRaw, results);\n\t\treturn;\n\t}\n\n\tawait createLabel(ctx, labelRaw, results);\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"toFilesystem.d.ts","sourceRoot":"","sources":["../../../src/schema/labels/toFilesystem.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAEpE,OAAO,KAAK,GAAG,MAAM,eAAe,CAAC;AAErC,wBAA8B,YAAY,CAAC,GAAG,EAAE,GAAG,mCAclD"}
1
+ {"version":3,"file":"toFilesystem.d.ts","sourceRoot":"","sources":["../../../src/schema/labels/toFilesystem.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAEpE,OAAO,KAAK,GAAG,MAAM,eAAe,CAAC;AAErC,wBAA8B,YAAY,CAAC,GAAG,EAAE,GAAG,mCAclD"}
@@ -1,20 +1,19 @@
1
1
  import getAllLabels from '#cli/cs/labels/getAllLabels.js';
2
2
  import writeYaml from '#cli/fs/writeYaml.js';
3
+ import organize from '#cli/dto/labels/organize.js';
3
4
  import schemaDirectory from '../content-types/schemaDirectory.js';
4
5
  import { MutableTransferResults } from '../xfer/TransferResults.js';
5
6
  import createProgressBar from '../lib/createProgressBar.js';
6
7
  export default async function toFilesystem(ctx) {
7
8
  const directory = schemaDirectory();
8
9
  const bar = createProgressBar('Labels', 1, 0);
9
- // Fetch labels and write them directly. processPlan shortcuts when the
10
- // merge plan is empty, so for a single-file resource we write and return
11
- // a simple TransferResults object.
12
- const labels = await getAllLabels(ctx.cs.client);
13
- await writeYaml(`${directory}/labels.yaml`, { labels });
10
+ // Fetch labels and organize them into a hierarchical structure
11
+ const flatLabels = await getAllLabels(ctx.cs.client);
12
+ const hierarchicalLabels = organize(flatLabels);
13
+ await writeYaml(`${directory}/labels.yaml`, { labels: hierarchicalLabels });
14
14
  const result = new MutableTransferResults();
15
15
  result.created.add('labels.yaml');
16
16
  bar.increment();
17
17
  return result;
18
18
  }
19
- //# sourceMappingURL=toFilesystem.js.map
20
19
  //# sourceMappingURL=toFilesystem.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"toFilesystem.js","sourceRoot":"","sources":["../../../src/schema/labels/toFilesystem.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,gCAAgC,CAAC;AAC1D,OAAO,SAAS,MAAM,sBAAsB,CAAC;AAC7C,OAAO,eAAe,MAAM,qCAAqC,CAAC;AAClE,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,iBAAiB,MAAM,6BAA6B,CAAC;AAG5D,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,YAAY,CAAC,GAAQ;IAClD,MAAM,SAAS,GAAG,eAAe,EAAE,CAAC;IACpC,MAAM,GAAG,GAAG,iBAAiB,CAAC,QAAQ,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAE9C,uEAAuE;IACvE,yEAAyE;IACzE,mCAAmC;IACnC,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC;IACjD,MAAM,SAAS,CAAC,GAAG,SAAS,cAAc,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;IAExD,MAAM,MAAM,GAAG,IAAI,sBAAsB,EAAE,CAAC;IAC5C,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;IAClC,GAAG,CAAC,SAAS,EAAE,CAAC;IAChB,OAAO,MAAM,CAAC;AACf,CAAC;AAED,wCAAwC","sourcesContent":["import getAllLabels from '#cli/cs/labels/getAllLabels.js';\nimport writeYaml from '#cli/fs/writeYaml.js';\nimport schemaDirectory from '../content-types/schemaDirectory.js';\nimport { MutableTransferResults } from '../xfer/TransferResults.js';\nimport createProgressBar from '../lib/createProgressBar.js';\nimport type Ctx from '../ctx/Ctx.js';\n\nexport default async function toFilesystem(ctx: Ctx) {\n\tconst directory = schemaDirectory();\n\tconst bar = createProgressBar('Labels', 1, 0);\n\n\t// Fetch labels and write them directly. processPlan shortcuts when the\n\t// merge plan is empty, so for a single-file resource we write and return\n\t// a simple TransferResults object.\n\tconst labels = await getAllLabels(ctx.cs.client);\n\tawait writeYaml(`${directory}/labels.yaml`, { labels });\n\n\tconst result = new MutableTransferResults();\n\tresult.created.add('labels.yaml');\n\tbar.increment();\n\treturn result;\n}\n\n//# sourceMappingURL=toFilesystem.js.map\n"]}
1
+ {"version":3,"file":"toFilesystem.js","sourceRoot":"","sources":["../../../src/schema/labels/toFilesystem.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,gCAAgC,CAAC;AAC1D,OAAO,SAAS,MAAM,sBAAsB,CAAC;AAC7C,OAAO,QAAQ,MAAM,6BAA6B,CAAC;AACnD,OAAO,eAAe,MAAM,qCAAqC,CAAC;AAClE,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,iBAAiB,MAAM,6BAA6B,CAAC;AAG5D,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,YAAY,CAAC,GAAQ;IAClD,MAAM,SAAS,GAAG,eAAe,EAAE,CAAC;IACpC,MAAM,GAAG,GAAG,iBAAiB,CAAC,QAAQ,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAE9C,+DAA+D;IAC/D,MAAM,UAAU,GAAG,MAAM,YAAY,CAAC,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC;IACrD,MAAM,kBAAkB,GAAG,QAAQ,CAAC,UAAU,CAAC,CAAC;IAEhD,MAAM,SAAS,CAAC,GAAG,SAAS,cAAc,EAAE,EAAE,MAAM,EAAE,kBAAkB,EAAE,CAAC,CAAC;IAE5E,MAAM,MAAM,GAAG,IAAI,sBAAsB,EAAE,CAAC;IAC5C,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;IAClC,GAAG,CAAC,SAAS,EAAE,CAAC;IAChB,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["import getAllLabels from '#cli/cs/labels/getAllLabels.js';\nimport writeYaml from '#cli/fs/writeYaml.js';\nimport organize from '#cli/dto/labels/organize.js';\nimport schemaDirectory from '../content-types/schemaDirectory.js';\nimport { MutableTransferResults } from '../xfer/TransferResults.js';\nimport createProgressBar from '../lib/createProgressBar.js';\nimport type Ctx from '../ctx/Ctx.js';\n\nexport default async function toFilesystem(ctx: Ctx) {\n\tconst directory = schemaDirectory();\n\tconst bar = createProgressBar('Labels', 1, 0);\n\n\t// Fetch labels and organize them into a hierarchical structure\n\tconst flatLabels = await getAllLabels(ctx.cs.client);\n\tconst hierarchicalLabels = organize(flatLabels);\n\n\tawait writeYaml(`${directory}/labels.yaml`, { labels: hierarchicalLabels });\n\n\tconst result = new MutableTransferResults();\n\tresult.created.add('labels.yaml');\n\tbar.increment();\n\treturn result;\n}\n"]}