@uniformdev/project-map 19.134.3-alpha.10 → 19.135.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.mts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { ApiClient } from '@uniformdev/context/api';
2
+ import { RouteGetResponse } from '@uniformdev/canvas';
2
3
 
3
4
  /**
4
5
  * This file was auto-generated by openapi-typescript.
@@ -347,7 +348,7 @@ interface components {
347
348
  * @description The id of the projectMap entry
348
349
  */
349
350
  id: string;
350
- /** @description Dot delimited path representing the path to the current node */
351
+ /** @description Path representing the path to the current node */
351
352
  path: string;
352
353
  /** @description Ordering of the node, higher numbers go after lower numbers. */
353
354
  order?: number;
@@ -358,7 +359,7 @@ interface components {
358
359
  * @description The type of the projectMap entry
359
360
  * @enum {string}
360
361
  */
361
- type: "composition" | "redirect" | "placeholder";
362
+ type: "composition" | "placeholder";
362
363
  /**
363
364
  * Format: uuid
364
365
  * @description The composition id related to the projectMap entry
@@ -368,13 +369,34 @@ interface components {
368
369
  description?: string;
369
370
  /** @description Parent path of the current node, only included if requested with the expanded flag */
370
371
  parentPath?: string;
371
- /** @description Last segment of the url, only included if requested with the expanded flag */
372
+ /** @description Last segment of the url */
372
373
  pathSegment?: string;
373
374
  /** @description returns true if the node is a leaf node, meaning having no children, only included if requested with the expanded flag */
374
375
  isLeaf?: boolean;
375
376
  compositionData?: components["schemas"]["ProjectMapNodeCompositionData"];
376
377
  sourceRedirects?: components["schemas"]["ProjectMapSourceRedirectData"];
377
378
  targetRedirects?: components["schemas"]["ProjectMapTargetRedirectData"];
379
+ locales?: {
380
+ [key: string]: components["schemas"]["ProjectMapNodeLocale"];
381
+ };
382
+ };
383
+ ProjectMapNodeLocale: {
384
+ /** @description Name of node in the locale */
385
+ name?: string;
386
+ /** @description Full path to the current node in this locale, only included if requested with the expanded flag */
387
+ path?: string;
388
+ /** @description Last segment of the url in this locale */
389
+ pathSegment: string;
390
+ /**
391
+ * @description When false, the node explicitly defines a locale specific path segment.
392
+ *
393
+ * When true, an ancestor defines a locale specific path segment,
394
+ * which makes its descendants resolvable using that segment.
395
+ * This node does not define a locale specific path segment.
396
+ *
397
+ * Only included if requested with the expanded flag. Without the expanded flag, inherited locales are not included in the response.
398
+ */
399
+ inherited?: boolean;
378
400
  };
379
401
  ProjectMapSourceRedirectData: {
380
402
  /**
@@ -416,6 +438,8 @@ interface components {
416
438
  icon?: string;
417
439
  /** @description Friendly name of this Composition's Definition */
418
440
  typeName?: string;
441
+ /** @description List of locales that the composition is available in. If empty, available in all locales. */
442
+ locales: string[];
419
443
  };
420
444
  ProjectMapNodeUpdate: {
421
445
  /**
@@ -434,7 +458,7 @@ interface components {
434
458
  * @description The type of the projectMap entry
435
459
  * @enum {string}
436
460
  */
437
- type: "composition" | "redirect" | "placeholder";
461
+ type: "composition" | "placeholder";
438
462
  /**
439
463
  * Format: uuid
440
464
  * @description The composition id related to the projectMap entry
@@ -442,6 +466,15 @@ interface components {
442
466
  compositionId?: string;
443
467
  /** @description Description of the projectMap node */
444
468
  description?: string;
469
+ locales?: {
470
+ [key: string]: components["schemas"]["ProjectMapNodeLocaleUpdate"];
471
+ };
472
+ };
473
+ ProjectMapNodeLocaleUpdate: {
474
+ /** @description Name of node in the locale */
475
+ name?: string;
476
+ /** @description Locale specific path segment for this node (not a full path) */
477
+ pathSegment: string;
445
478
  };
446
479
  ProjectMapNodeData: {
447
480
  /** @description While performing a search if a node is a hit, this property will return true. If it's supporting structure, like a parent of a search hit, it will return false */
@@ -526,10 +559,12 @@ interface external {
526
559
 
527
560
  type ProjectMapNodeUpsertRequest = paths['/api/v1/project-map-nodes']['put']['requestBody']['content']['application/json'];
528
561
  type ProjectMapNodeUpsertRequestNode = ProjectMapNodeUpsertRequest['nodes'][0]['node'];
562
+ type ProjectMapNodeUpsertRequestNodeLocale = NonNullable<ProjectMapNodeUpsertRequestNode['locales']>[string];
529
563
  type ProjectMapNodeDeleteRequest = paths['/api/v1/project-map-nodes']['delete']['requestBody']['content']['application/json'];
530
564
  type ProjectMapNodeGetRequest = paths['/api/v1/project-map-nodes']['get']['parameters']['query'];
531
565
  type ProjectMapNodeGetResponse = paths['/api/v1/project-map-nodes']['get']['responses']['200']['content']['application/json'];
532
566
  type ProjectMapNode = NonNullable<ProjectMapNodeGetResponse['nodes']>[0];
567
+ type ProjectMapNodeLocale = NonNullable<ProjectMapNode['locales']>[string];
533
568
  type ProjectMapNodeWithId = ProjectMapNode & Required<Pick<ProjectMapNode, 'id' | 'name'>>;
534
569
  type ProjectMapGetRequest = paths$1['/api/v1/project-map']['get']['parameters']['query'];
535
570
  type ProjectMapGetResponse = paths$1['/api/v1/project-map']['get']['responses']['200']['content']['application/json'];
@@ -538,7 +573,7 @@ type ProjectMapDeleteRequest = paths$1['/api/v1/project-map']['delete']['request
538
573
  type ProjectMapDefinition = ProjectMapGetResponse['projectMaps'][0];
539
574
  type ProjectMapDefinitionWithId = ProjectMapDefinition & Required<Pick<ProjectMapDefinition, 'id'>>;
540
575
  type ProjectMapUpsertResponse = paths$1['/api/v1/project-map']['put']['responses']['200']['content']['application/json'];
541
- type NodeType = 'placeholder' | 'composition' | 'redirect';
576
+ type NodeType = ProjectMapNode['type'];
542
577
  type ProjectMapNodeWithProjectMapReference = ProjectMapNodeWithId & {
543
578
  projectMapId: string;
544
579
  };
@@ -630,6 +665,36 @@ declare class UncachedProjectMapClient extends ProjectMapClient {
630
665
  constructor(options: Omit<ProjectMapClientOptions, 'bypassCache'>);
631
666
  }
632
667
 
668
+ type LocalePathNode = Pick<ProjectMapNode, 'path'> & {
669
+ locales?: Record<string, {
670
+ path?: string | undefined;
671
+ }>;
672
+ };
673
+ /**
674
+ * Given a project map node and a locale, resolves the correct path for the locale
675
+ * This is computed as follows:
676
+ * - If the locale is unspecified, then use the fallback path
677
+ * - If the locale is specified, then use the locale-specific path if it exists, otherwise use the fallback path
678
+ */
679
+ declare function getNodeLocalePath(node: LocalePathNode, locale: string | undefined): string;
680
+ declare function getNodeLocalePath(node: LocalePathNode | undefined, locale: string | undefined): string | null;
681
+
682
+ type AlternateLocaleUrls = {
683
+ [locale: string]: string;
684
+ };
685
+ /**
686
+ * Gets all possible locale specific URLs for a composition route response
687
+ *
688
+ * This is appropriate for generating links to other locale versions of the current composition,
689
+ * such as for alternate language tags, language switchers, etc.
690
+ *
691
+ * The URLs will be:
692
+ * * Computed based on the attached project map node path
693
+ * * Not include a base URL from the project map, if one is set
694
+ * * If a dynamic locale path segment exists, it will be rewritten automatically to the target locale
695
+ */
696
+ declare function getRouteAlternateLocalesUrls(routeResponse: RouteGetResponse): AlternateLocaleUrls | undefined;
697
+
633
698
  type MatchedRoute = {
634
699
  match: true;
635
700
  dynamicSegmentCount: number;
@@ -664,4 +729,4 @@ declare class Route {
664
729
  static dynamicSegmentPrefix: string;
665
730
  }
666
731
 
667
- export { type ExpandOptions, type MatchedRoute, type NodeType, ProjectMapClient, type ProjectMapClientOptions, type ProjectMapDefinition, type ProjectMapDefinitionWithId, type ProjectMapDefinitions, type ProjectMapDeleteRequest, type ProjectMapGetRequest, type ProjectMapGetResponse, type ProjectMapNode, type ProjectMapNodeAllowedQueryString, type ProjectMapNodeData, type ProjectMapNodeDeleteRequest, type ProjectMapNodeGetRequest, type ProjectMapNodeGetResponse, type ProjectMapNodeUpsertRequest, type ProjectMapNodeUpsertRequestNode, type ProjectMapNodeWithId, type ProjectMapNodeWithProjectMapReference, type ProjectMapSubtree, type ProjectMapUpsertRequest, type ProjectMapUpsertResponse, ROOT_NODE_PATH, Route, UncachedProjectMapClient, type UnmatchedRoute };
732
+ export { type AlternateLocaleUrls, type ExpandOptions, type LocalePathNode, type MatchedRoute, type NodeType, ProjectMapClient, type ProjectMapClientOptions, type ProjectMapDefinition, type ProjectMapDefinitionWithId, type ProjectMapDefinitions, type ProjectMapDeleteRequest, type ProjectMapGetRequest, type ProjectMapGetResponse, type ProjectMapNode, type ProjectMapNodeAllowedQueryString, type ProjectMapNodeData, type ProjectMapNodeDeleteRequest, type ProjectMapNodeGetRequest, type ProjectMapNodeGetResponse, type ProjectMapNodeLocale, type ProjectMapNodeUpsertRequest, type ProjectMapNodeUpsertRequestNode, type ProjectMapNodeUpsertRequestNodeLocale, type ProjectMapNodeWithId, type ProjectMapNodeWithProjectMapReference, type ProjectMapSubtree, type ProjectMapUpsertRequest, type ProjectMapUpsertResponse, ROOT_NODE_PATH, Route, UncachedProjectMapClient, type UnmatchedRoute, getNodeLocalePath, getRouteAlternateLocalesUrls };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { ApiClient } from '@uniformdev/context/api';
2
+ import { RouteGetResponse } from '@uniformdev/canvas';
2
3
 
3
4
  /**
4
5
  * This file was auto-generated by openapi-typescript.
@@ -347,7 +348,7 @@ interface components {
347
348
  * @description The id of the projectMap entry
348
349
  */
349
350
  id: string;
350
- /** @description Dot delimited path representing the path to the current node */
351
+ /** @description Path representing the path to the current node */
351
352
  path: string;
352
353
  /** @description Ordering of the node, higher numbers go after lower numbers. */
353
354
  order?: number;
@@ -358,7 +359,7 @@ interface components {
358
359
  * @description The type of the projectMap entry
359
360
  * @enum {string}
360
361
  */
361
- type: "composition" | "redirect" | "placeholder";
362
+ type: "composition" | "placeholder";
362
363
  /**
363
364
  * Format: uuid
364
365
  * @description The composition id related to the projectMap entry
@@ -368,13 +369,34 @@ interface components {
368
369
  description?: string;
369
370
  /** @description Parent path of the current node, only included if requested with the expanded flag */
370
371
  parentPath?: string;
371
- /** @description Last segment of the url, only included if requested with the expanded flag */
372
+ /** @description Last segment of the url */
372
373
  pathSegment?: string;
373
374
  /** @description returns true if the node is a leaf node, meaning having no children, only included if requested with the expanded flag */
374
375
  isLeaf?: boolean;
375
376
  compositionData?: components["schemas"]["ProjectMapNodeCompositionData"];
376
377
  sourceRedirects?: components["schemas"]["ProjectMapSourceRedirectData"];
377
378
  targetRedirects?: components["schemas"]["ProjectMapTargetRedirectData"];
379
+ locales?: {
380
+ [key: string]: components["schemas"]["ProjectMapNodeLocale"];
381
+ };
382
+ };
383
+ ProjectMapNodeLocale: {
384
+ /** @description Name of node in the locale */
385
+ name?: string;
386
+ /** @description Full path to the current node in this locale, only included if requested with the expanded flag */
387
+ path?: string;
388
+ /** @description Last segment of the url in this locale */
389
+ pathSegment: string;
390
+ /**
391
+ * @description When false, the node explicitly defines a locale specific path segment.
392
+ *
393
+ * When true, an ancestor defines a locale specific path segment,
394
+ * which makes its descendants resolvable using that segment.
395
+ * This node does not define a locale specific path segment.
396
+ *
397
+ * Only included if requested with the expanded flag. Without the expanded flag, inherited locales are not included in the response.
398
+ */
399
+ inherited?: boolean;
378
400
  };
379
401
  ProjectMapSourceRedirectData: {
380
402
  /**
@@ -416,6 +438,8 @@ interface components {
416
438
  icon?: string;
417
439
  /** @description Friendly name of this Composition's Definition */
418
440
  typeName?: string;
441
+ /** @description List of locales that the composition is available in. If empty, available in all locales. */
442
+ locales: string[];
419
443
  };
420
444
  ProjectMapNodeUpdate: {
421
445
  /**
@@ -434,7 +458,7 @@ interface components {
434
458
  * @description The type of the projectMap entry
435
459
  * @enum {string}
436
460
  */
437
- type: "composition" | "redirect" | "placeholder";
461
+ type: "composition" | "placeholder";
438
462
  /**
439
463
  * Format: uuid
440
464
  * @description The composition id related to the projectMap entry
@@ -442,6 +466,15 @@ interface components {
442
466
  compositionId?: string;
443
467
  /** @description Description of the projectMap node */
444
468
  description?: string;
469
+ locales?: {
470
+ [key: string]: components["schemas"]["ProjectMapNodeLocaleUpdate"];
471
+ };
472
+ };
473
+ ProjectMapNodeLocaleUpdate: {
474
+ /** @description Name of node in the locale */
475
+ name?: string;
476
+ /** @description Locale specific path segment for this node (not a full path) */
477
+ pathSegment: string;
445
478
  };
446
479
  ProjectMapNodeData: {
447
480
  /** @description While performing a search if a node is a hit, this property will return true. If it's supporting structure, like a parent of a search hit, it will return false */
@@ -526,10 +559,12 @@ interface external {
526
559
 
527
560
  type ProjectMapNodeUpsertRequest = paths['/api/v1/project-map-nodes']['put']['requestBody']['content']['application/json'];
528
561
  type ProjectMapNodeUpsertRequestNode = ProjectMapNodeUpsertRequest['nodes'][0]['node'];
562
+ type ProjectMapNodeUpsertRequestNodeLocale = NonNullable<ProjectMapNodeUpsertRequestNode['locales']>[string];
529
563
  type ProjectMapNodeDeleteRequest = paths['/api/v1/project-map-nodes']['delete']['requestBody']['content']['application/json'];
530
564
  type ProjectMapNodeGetRequest = paths['/api/v1/project-map-nodes']['get']['parameters']['query'];
531
565
  type ProjectMapNodeGetResponse = paths['/api/v1/project-map-nodes']['get']['responses']['200']['content']['application/json'];
532
566
  type ProjectMapNode = NonNullable<ProjectMapNodeGetResponse['nodes']>[0];
567
+ type ProjectMapNodeLocale = NonNullable<ProjectMapNode['locales']>[string];
533
568
  type ProjectMapNodeWithId = ProjectMapNode & Required<Pick<ProjectMapNode, 'id' | 'name'>>;
534
569
  type ProjectMapGetRequest = paths$1['/api/v1/project-map']['get']['parameters']['query'];
535
570
  type ProjectMapGetResponse = paths$1['/api/v1/project-map']['get']['responses']['200']['content']['application/json'];
@@ -538,7 +573,7 @@ type ProjectMapDeleteRequest = paths$1['/api/v1/project-map']['delete']['request
538
573
  type ProjectMapDefinition = ProjectMapGetResponse['projectMaps'][0];
539
574
  type ProjectMapDefinitionWithId = ProjectMapDefinition & Required<Pick<ProjectMapDefinition, 'id'>>;
540
575
  type ProjectMapUpsertResponse = paths$1['/api/v1/project-map']['put']['responses']['200']['content']['application/json'];
541
- type NodeType = 'placeholder' | 'composition' | 'redirect';
576
+ type NodeType = ProjectMapNode['type'];
542
577
  type ProjectMapNodeWithProjectMapReference = ProjectMapNodeWithId & {
543
578
  projectMapId: string;
544
579
  };
@@ -630,6 +665,36 @@ declare class UncachedProjectMapClient extends ProjectMapClient {
630
665
  constructor(options: Omit<ProjectMapClientOptions, 'bypassCache'>);
631
666
  }
632
667
 
668
+ type LocalePathNode = Pick<ProjectMapNode, 'path'> & {
669
+ locales?: Record<string, {
670
+ path?: string | undefined;
671
+ }>;
672
+ };
673
+ /**
674
+ * Given a project map node and a locale, resolves the correct path for the locale
675
+ * This is computed as follows:
676
+ * - If the locale is unspecified, then use the fallback path
677
+ * - If the locale is specified, then use the locale-specific path if it exists, otherwise use the fallback path
678
+ */
679
+ declare function getNodeLocalePath(node: LocalePathNode, locale: string | undefined): string;
680
+ declare function getNodeLocalePath(node: LocalePathNode | undefined, locale: string | undefined): string | null;
681
+
682
+ type AlternateLocaleUrls = {
683
+ [locale: string]: string;
684
+ };
685
+ /**
686
+ * Gets all possible locale specific URLs for a composition route response
687
+ *
688
+ * This is appropriate for generating links to other locale versions of the current composition,
689
+ * such as for alternate language tags, language switchers, etc.
690
+ *
691
+ * The URLs will be:
692
+ * * Computed based on the attached project map node path
693
+ * * Not include a base URL from the project map, if one is set
694
+ * * If a dynamic locale path segment exists, it will be rewritten automatically to the target locale
695
+ */
696
+ declare function getRouteAlternateLocalesUrls(routeResponse: RouteGetResponse): AlternateLocaleUrls | undefined;
697
+
633
698
  type MatchedRoute = {
634
699
  match: true;
635
700
  dynamicSegmentCount: number;
@@ -664,4 +729,4 @@ declare class Route {
664
729
  static dynamicSegmentPrefix: string;
665
730
  }
666
731
 
667
- export { type ExpandOptions, type MatchedRoute, type NodeType, ProjectMapClient, type ProjectMapClientOptions, type ProjectMapDefinition, type ProjectMapDefinitionWithId, type ProjectMapDefinitions, type ProjectMapDeleteRequest, type ProjectMapGetRequest, type ProjectMapGetResponse, type ProjectMapNode, type ProjectMapNodeAllowedQueryString, type ProjectMapNodeData, type ProjectMapNodeDeleteRequest, type ProjectMapNodeGetRequest, type ProjectMapNodeGetResponse, type ProjectMapNodeUpsertRequest, type ProjectMapNodeUpsertRequestNode, type ProjectMapNodeWithId, type ProjectMapNodeWithProjectMapReference, type ProjectMapSubtree, type ProjectMapUpsertRequest, type ProjectMapUpsertResponse, ROOT_NODE_PATH, Route, UncachedProjectMapClient, type UnmatchedRoute };
732
+ export { type AlternateLocaleUrls, type ExpandOptions, type LocalePathNode, type MatchedRoute, type NodeType, ProjectMapClient, type ProjectMapClientOptions, type ProjectMapDefinition, type ProjectMapDefinitionWithId, type ProjectMapDefinitions, type ProjectMapDeleteRequest, type ProjectMapGetRequest, type ProjectMapGetResponse, type ProjectMapNode, type ProjectMapNodeAllowedQueryString, type ProjectMapNodeData, type ProjectMapNodeDeleteRequest, type ProjectMapNodeGetRequest, type ProjectMapNodeGetResponse, type ProjectMapNodeLocale, type ProjectMapNodeUpsertRequest, type ProjectMapNodeUpsertRequestNode, type ProjectMapNodeUpsertRequestNodeLocale, type ProjectMapNodeWithId, type ProjectMapNodeWithProjectMapReference, type ProjectMapSubtree, type ProjectMapUpsertRequest, type ProjectMapUpsertResponse, ROOT_NODE_PATH, Route, UncachedProjectMapClient, type UnmatchedRoute, getNodeLocalePath, getRouteAlternateLocalesUrls };
package/dist/index.esm.js CHANGED
@@ -177,7 +177,8 @@ var ProjectMapClient = class extends ApiClient {
177
177
  order: node.order,
178
178
  data: node.data,
179
179
  compositionId: node.compositionId,
180
- description: node.description
180
+ description: node.description,
181
+ locales: node.locales
181
182
  };
182
183
  }
183
184
  };
@@ -192,6 +193,14 @@ var cutReferences = (node) => node ? {
192
193
  children: void 0
193
194
  } : void 0;
194
195
 
196
+ // src/util/getNodeLocalePath.ts
197
+ function getNodeLocalePath(node, locale) {
198
+ var _a, _b;
199
+ if (!node)
200
+ return null;
201
+ return locale ? ((_b = (_a = node.locales) == null ? void 0 : _a[locale]) == null ? void 0 : _b.path) || node.path : node.path;
202
+ }
203
+
195
204
  // src/util/Route.ts
196
205
  import { createVariableReference, parseVariableExpression } from "@uniformdev/canvas";
197
206
  var _routeInfo, _parseRouteOrPath, parseRouteOrPath_fn, _isDynamicRouteSegment, isDynamicRouteSegment_fn;
@@ -293,6 +302,9 @@ parseRouteOrPath_fn = function(path) {
293
302
  };
294
303
  _isDynamicRouteSegment = new WeakSet();
295
304
  isDynamicRouteSegment_fn = function(segment) {
305
+ if (!segment) {
306
+ return false;
307
+ }
296
308
  return segment.startsWith(_Route.dynamicSegmentPrefix);
297
309
  };
298
310
  __privateAdd(_Route, _parseRouteOrPath);
@@ -313,9 +325,39 @@ function encodeRouteComponent(value, doNotEscapeVariables) {
313
325
  });
314
326
  return result.join("");
315
327
  }
328
+
329
+ // src/util/getRouteAlternateLocaleUrls.ts
330
+ function getRouteAlternateLocalesUrls(routeResponse) {
331
+ var _a;
332
+ if (routeResponse.type === "notFound" || routeResponse.type === "redirect") {
333
+ return void 0;
334
+ }
335
+ const enabledLocalesOnComposition = routeResponse.compositionApiResponse.composition._locales;
336
+ if (!enabledLocalesOnComposition) {
337
+ return void 0;
338
+ }
339
+ const projectMapNode = (_a = routeResponse.compositionApiResponse.composition.projectMapNodes) == null ? void 0 : _a[0];
340
+ if (!projectMapNode) {
341
+ return void 0;
342
+ }
343
+ return enabledLocalesOnComposition.reduce((acc, locale) => {
344
+ const path = getNodeLocalePath(projectMapNode, locale);
345
+ const dynamicInputsWithCurrentLocale = {
346
+ ...routeResponse.dynamicInputs,
347
+ locale
348
+ };
349
+ const alternateLocalePath = new Route(path).expand({
350
+ dynamicInputValues: dynamicInputsWithCurrentLocale
351
+ });
352
+ acc[locale] = alternateLocalePath;
353
+ return acc;
354
+ }, {});
355
+ }
316
356
  export {
317
357
  ProjectMapClient,
318
358
  ROOT_NODE_PATH,
319
359
  Route,
320
- UncachedProjectMapClient
360
+ UncachedProjectMapClient,
361
+ getNodeLocalePath,
362
+ getRouteAlternateLocalesUrls
321
363
  };
package/dist/index.js CHANGED
@@ -45,7 +45,9 @@ __export(src_exports, {
45
45
  ProjectMapClient: () => ProjectMapClient,
46
46
  ROOT_NODE_PATH: () => ROOT_NODE_PATH,
47
47
  Route: () => Route,
48
- UncachedProjectMapClient: () => UncachedProjectMapClient
48
+ UncachedProjectMapClient: () => UncachedProjectMapClient,
49
+ getNodeLocalePath: () => getNodeLocalePath,
50
+ getRouteAlternateLocalesUrls: () => getRouteAlternateLocalesUrls
49
51
  });
50
52
  module.exports = __toCommonJS(src_exports);
51
53
 
@@ -205,7 +207,8 @@ var ProjectMapClient = class extends import_api.ApiClient {
205
207
  order: node.order,
206
208
  data: node.data,
207
209
  compositionId: node.compositionId,
208
- description: node.description
210
+ description: node.description,
211
+ locales: node.locales
209
212
  };
210
213
  }
211
214
  };
@@ -220,6 +223,14 @@ var cutReferences = (node) => node ? {
220
223
  children: void 0
221
224
  } : void 0;
222
225
 
226
+ // src/util/getNodeLocalePath.ts
227
+ function getNodeLocalePath(node, locale) {
228
+ var _a, _b;
229
+ if (!node)
230
+ return null;
231
+ return locale ? ((_b = (_a = node.locales) == null ? void 0 : _a[locale]) == null ? void 0 : _b.path) || node.path : node.path;
232
+ }
233
+
223
234
  // src/util/Route.ts
224
235
  var import_canvas = require("@uniformdev/canvas");
225
236
  var _routeInfo, _parseRouteOrPath, parseRouteOrPath_fn, _isDynamicRouteSegment, isDynamicRouteSegment_fn;
@@ -321,6 +332,9 @@ parseRouteOrPath_fn = function(path) {
321
332
  };
322
333
  _isDynamicRouteSegment = new WeakSet();
323
334
  isDynamicRouteSegment_fn = function(segment) {
335
+ if (!segment) {
336
+ return false;
337
+ }
324
338
  return segment.startsWith(_Route.dynamicSegmentPrefix);
325
339
  };
326
340
  __privateAdd(_Route, _parseRouteOrPath);
@@ -341,10 +355,40 @@ function encodeRouteComponent(value, doNotEscapeVariables) {
341
355
  });
342
356
  return result.join("");
343
357
  }
358
+
359
+ // src/util/getRouteAlternateLocaleUrls.ts
360
+ function getRouteAlternateLocalesUrls(routeResponse) {
361
+ var _a;
362
+ if (routeResponse.type === "notFound" || routeResponse.type === "redirect") {
363
+ return void 0;
364
+ }
365
+ const enabledLocalesOnComposition = routeResponse.compositionApiResponse.composition._locales;
366
+ if (!enabledLocalesOnComposition) {
367
+ return void 0;
368
+ }
369
+ const projectMapNode = (_a = routeResponse.compositionApiResponse.composition.projectMapNodes) == null ? void 0 : _a[0];
370
+ if (!projectMapNode) {
371
+ return void 0;
372
+ }
373
+ return enabledLocalesOnComposition.reduce((acc, locale) => {
374
+ const path = getNodeLocalePath(projectMapNode, locale);
375
+ const dynamicInputsWithCurrentLocale = {
376
+ ...routeResponse.dynamicInputs,
377
+ locale
378
+ };
379
+ const alternateLocalePath = new Route(path).expand({
380
+ dynamicInputValues: dynamicInputsWithCurrentLocale
381
+ });
382
+ acc[locale] = alternateLocalePath;
383
+ return acc;
384
+ }, {});
385
+ }
344
386
  // Annotate the CommonJS export names for ESM import in node:
345
387
  0 && (module.exports = {
346
388
  ProjectMapClient,
347
389
  ROOT_NODE_PATH,
348
390
  Route,
349
- UncachedProjectMapClient
391
+ UncachedProjectMapClient,
392
+ getNodeLocalePath,
393
+ getRouteAlternateLocalesUrls
350
394
  });
package/dist/index.mjs CHANGED
@@ -177,7 +177,8 @@ var ProjectMapClient = class extends ApiClient {
177
177
  order: node.order,
178
178
  data: node.data,
179
179
  compositionId: node.compositionId,
180
- description: node.description
180
+ description: node.description,
181
+ locales: node.locales
181
182
  };
182
183
  }
183
184
  };
@@ -192,6 +193,14 @@ var cutReferences = (node) => node ? {
192
193
  children: void 0
193
194
  } : void 0;
194
195
 
196
+ // src/util/getNodeLocalePath.ts
197
+ function getNodeLocalePath(node, locale) {
198
+ var _a, _b;
199
+ if (!node)
200
+ return null;
201
+ return locale ? ((_b = (_a = node.locales) == null ? void 0 : _a[locale]) == null ? void 0 : _b.path) || node.path : node.path;
202
+ }
203
+
195
204
  // src/util/Route.ts
196
205
  import { createVariableReference, parseVariableExpression } from "@uniformdev/canvas";
197
206
  var _routeInfo, _parseRouteOrPath, parseRouteOrPath_fn, _isDynamicRouteSegment, isDynamicRouteSegment_fn;
@@ -293,6 +302,9 @@ parseRouteOrPath_fn = function(path) {
293
302
  };
294
303
  _isDynamicRouteSegment = new WeakSet();
295
304
  isDynamicRouteSegment_fn = function(segment) {
305
+ if (!segment) {
306
+ return false;
307
+ }
296
308
  return segment.startsWith(_Route.dynamicSegmentPrefix);
297
309
  };
298
310
  __privateAdd(_Route, _parseRouteOrPath);
@@ -313,9 +325,39 @@ function encodeRouteComponent(value, doNotEscapeVariables) {
313
325
  });
314
326
  return result.join("");
315
327
  }
328
+
329
+ // src/util/getRouteAlternateLocaleUrls.ts
330
+ function getRouteAlternateLocalesUrls(routeResponse) {
331
+ var _a;
332
+ if (routeResponse.type === "notFound" || routeResponse.type === "redirect") {
333
+ return void 0;
334
+ }
335
+ const enabledLocalesOnComposition = routeResponse.compositionApiResponse.composition._locales;
336
+ if (!enabledLocalesOnComposition) {
337
+ return void 0;
338
+ }
339
+ const projectMapNode = (_a = routeResponse.compositionApiResponse.composition.projectMapNodes) == null ? void 0 : _a[0];
340
+ if (!projectMapNode) {
341
+ return void 0;
342
+ }
343
+ return enabledLocalesOnComposition.reduce((acc, locale) => {
344
+ const path = getNodeLocalePath(projectMapNode, locale);
345
+ const dynamicInputsWithCurrentLocale = {
346
+ ...routeResponse.dynamicInputs,
347
+ locale
348
+ };
349
+ const alternateLocalePath = new Route(path).expand({
350
+ dynamicInputValues: dynamicInputsWithCurrentLocale
351
+ });
352
+ acc[locale] = alternateLocalePath;
353
+ return acc;
354
+ }, {});
355
+ }
316
356
  export {
317
357
  ProjectMapClient,
318
358
  ROOT_NODE_PATH,
319
359
  Route,
320
- UncachedProjectMapClient
360
+ UncachedProjectMapClient,
361
+ getNodeLocalePath,
362
+ getRouteAlternateLocalesUrls
321
363
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/project-map",
3
- "version": "19.134.3-alpha.10+ae656e8e4c",
3
+ "version": "19.135.0",
4
4
  "description": "Uniform Project Map",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "main": "./dist/index.js",
@@ -33,11 +33,11 @@
33
33
  "/dist"
34
34
  ],
35
35
  "dependencies": {
36
- "@uniformdev/canvas": "19.134.3-alpha.10+ae656e8e4c",
37
- "@uniformdev/context": "19.134.3-alpha.10+ae656e8e4c"
36
+ "@uniformdev/canvas": "19.135.0",
37
+ "@uniformdev/context": "19.135.0"
38
38
  },
39
39
  "publishConfig": {
40
40
  "access": "public"
41
41
  },
42
- "gitHead": "ae656e8e4c730dbf960ef43b6c5e9a0b8ba13193"
42
+ "gitHead": "741cd50843c92d550dbff2daffb3a6106a7a3f94"
43
43
  }