@cmssy/core 11.9.0 → 12.1.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.cjs CHANGED
@@ -499,6 +499,19 @@ var fields = {
499
499
  }
500
500
  };
501
501
 
502
+ // src/media.ts
503
+ function mediaUrl(value) {
504
+ if (typeof value === "string") return value || null;
505
+ return value?.url ?? null;
506
+ }
507
+ function mediaUrls(value) {
508
+ if (!Array.isArray(value)) return [];
509
+ return value.map((item) => mediaUrl(item)).filter((url) => url !== null);
510
+ }
511
+ function mediaAlt(value) {
512
+ return typeof value === "string" ? void 0 : value?.alt;
513
+ }
514
+
502
515
  // src/data/localize-href.ts
503
516
  var PROTOCOL_OR_RELATIVE = /^([a-z][a-z0-9+.-]*:|\/\/)/i;
504
517
  function isExternalHref(href) {
@@ -879,6 +892,9 @@ exports.graphqlRequest = graphqlRequest;
879
892
  exports.isProtocolCompatible = isProtocolCompatible;
880
893
  exports.isVerifiedEditUrl = isVerifiedEditUrl;
881
894
  exports.localizeHref = localizeHref;
895
+ exports.mediaAlt = mediaAlt;
896
+ exports.mediaUrl = mediaUrl;
897
+ exports.mediaUrls = mediaUrls;
882
898
  exports.normalizeOrigin = normalizeOrigin;
883
899
  exports.parseEditorMessage = parseEditorMessage;
884
900
  exports.postToEditor = postToEditor;
package/dist/index.d.cts CHANGED
@@ -2,7 +2,7 @@ export { A as AppToEditorMessage, B as BoundsMessage, C as ClickMessage, a as Cm
2
2
  export { C as CMSSY_LOCALE_HEADER, G as GraphqlRequestOptions, g as graphqlRequest, l as localizeHref, r as resolveCmssyLocale } from './locale-BS61R-fF.cjs';
3
3
  export { C as CmssyRequestError, D as DEFAULT_CMSSY_API_URL, F as FetchLike, a as FetchLikeResponse, b as FetchPageOptions, R as RetryPolicy } from './content-client-BPpRfq0h.cjs';
4
4
  import * as _cmssy_types from '@cmssy/types';
5
- import { FieldOptions, TypedField, MediaFieldValue, BlockPropsSchema, InferBlockContent, RelationMode, CmssyModelRecord, VerifyCmssyWebhookOptions, CmssyWebhookEvent } from '@cmssy/types';
5
+ import { FieldOptions, TypedField, ResolvedMediaValue, BlockPropsSchema, InferBlockContent, RelationMode, CmssyModelRecord, ResolvedMedia, VerifyCmssyWebhookOptions, CmssyWebhookEvent } from '@cmssy/types';
6
6
  export { BlockMeta, BlockPropsSchema, BlockRect, BlockSchema, BuildBlockContextExtra, CmssyBlockAuthContext, CmssyBlockContext, CmssyBlockMember, CmssyBlockPage, CmssyBlockWorkspace, CmssyBranding, CmssyClientConfig, CmssyFormDefinition, CmssyFormField, CmssyFormSettings, CmssyFormSubmitResponse, CmssyLayoutGroup, CmssyLayoutSettings, CmssyLocaleContext, CmssyLocalizedValue, CmssyModelDefinition, CmssyModelRecord, CmssyPageData, CmssyPageMeta, CmssyPageSummary, CmssyRecordList, CmssySiteConfig, CmssyWebhookEvent, CmssyWebhookOrder, FieldCondition, FieldConditionGroup, FieldConditionLogic, FieldControl, FieldDefinition, FieldOptions, FieldType, InferBlockContent, LayoutPosition, RawBlock, RawLayoutBlock, SubmitFormInput, TypedField, VerifyCmssyWebhookOptions, evaluateFieldConditionGroup, layoutPositionValues } from '@cmssy/types';
7
7
 
8
8
  type Declared<O> = O extends {
@@ -11,7 +11,7 @@ type Declared<O> = O extends {
11
11
  type OptionValue<O> = O extends {
12
12
  options: readonly (infer Option extends string)[];
13
13
  } ? Option : string;
14
- type MediaValue<O> = MediaFieldValue<O extends {
14
+ type MediaValue<O> = ResolvedMediaValue<O extends {
15
15
  multiple: true;
16
16
  } ? true : false>;
17
17
  type RepeaterValue<O> = O extends {
@@ -54,6 +54,18 @@ declare const fields: {
54
54
  relation: <const O extends RelationFieldOptions>(opts: O) => TypedField<RelationValue<O>, Declared<O>>;
55
55
  };
56
56
 
57
+ /**
58
+ * A media value as it can reach a block during the CMS-1149 transition: the
59
+ * resolved object a current API returns, or the bare URL string an API that
60
+ * has not been upgraded yet still returns. The string arm exists so a site can
61
+ * upgrade its SDK and its cmssy independently; it goes away once no supported
62
+ * cmssy serves strings.
63
+ */
64
+ type MediaLike = ResolvedMedia | string | null | undefined;
65
+ declare function mediaUrl(value: MediaLike): string | null;
66
+ declare function mediaUrls(value: readonly MediaLike[] | null | undefined): string[];
67
+ declare function mediaAlt(value: MediaLike): string | undefined;
68
+
57
69
  declare const CMSSY_EDIT_HEADER = "x-cmssy-edit";
58
70
  declare const CMSSY_EDIT_QUERY_PARAM = "cmssyEdit";
59
71
  declare const CMSSY_SECRET_QUERY_PARAM = "cmssySecret";
@@ -72,4 +84,4 @@ declare class CmssyWebhookError extends Error {
72
84
  }
73
85
  declare function verifyCmssyWebhook(options: VerifyCmssyWebhookOptions): Promise<CmssyWebhookEvent>;
74
86
 
75
- export { CMSSY_EDIT_HEADER, CMSSY_EDIT_QUERY_PARAM, CMSSY_SECRET_QUERY_PARAM, CmssyWebhookError, fields, isVerifiedEditUrl, verifyCmssyWebhook };
87
+ export { CMSSY_EDIT_HEADER, CMSSY_EDIT_QUERY_PARAM, CMSSY_SECRET_QUERY_PARAM, CmssyWebhookError, type MediaLike, fields, isVerifiedEditUrl, mediaAlt, mediaUrl, mediaUrls, verifyCmssyWebhook };
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ export { A as AppToEditorMessage, B as BoundsMessage, C as ClickMessage, a as Cm
2
2
  export { C as CMSSY_LOCALE_HEADER, G as GraphqlRequestOptions, g as graphqlRequest, l as localizeHref, r as resolveCmssyLocale } from './locale-DQZ80cew.js';
3
3
  export { C as CmssyRequestError, D as DEFAULT_CMSSY_API_URL, F as FetchLike, a as FetchLikeResponse, b as FetchPageOptions, R as RetryPolicy } from './content-client-BPpRfq0h.js';
4
4
  import * as _cmssy_types from '@cmssy/types';
5
- import { FieldOptions, TypedField, MediaFieldValue, BlockPropsSchema, InferBlockContent, RelationMode, CmssyModelRecord, VerifyCmssyWebhookOptions, CmssyWebhookEvent } from '@cmssy/types';
5
+ import { FieldOptions, TypedField, ResolvedMediaValue, BlockPropsSchema, InferBlockContent, RelationMode, CmssyModelRecord, ResolvedMedia, VerifyCmssyWebhookOptions, CmssyWebhookEvent } from '@cmssy/types';
6
6
  export { BlockMeta, BlockPropsSchema, BlockRect, BlockSchema, BuildBlockContextExtra, CmssyBlockAuthContext, CmssyBlockContext, CmssyBlockMember, CmssyBlockPage, CmssyBlockWorkspace, CmssyBranding, CmssyClientConfig, CmssyFormDefinition, CmssyFormField, CmssyFormSettings, CmssyFormSubmitResponse, CmssyLayoutGroup, CmssyLayoutSettings, CmssyLocaleContext, CmssyLocalizedValue, CmssyModelDefinition, CmssyModelRecord, CmssyPageData, CmssyPageMeta, CmssyPageSummary, CmssyRecordList, CmssySiteConfig, CmssyWebhookEvent, CmssyWebhookOrder, FieldCondition, FieldConditionGroup, FieldConditionLogic, FieldControl, FieldDefinition, FieldOptions, FieldType, InferBlockContent, LayoutPosition, RawBlock, RawLayoutBlock, SubmitFormInput, TypedField, VerifyCmssyWebhookOptions, evaluateFieldConditionGroup, layoutPositionValues } from '@cmssy/types';
7
7
 
8
8
  type Declared<O> = O extends {
@@ -11,7 +11,7 @@ type Declared<O> = O extends {
11
11
  type OptionValue<O> = O extends {
12
12
  options: readonly (infer Option extends string)[];
13
13
  } ? Option : string;
14
- type MediaValue<O> = MediaFieldValue<O extends {
14
+ type MediaValue<O> = ResolvedMediaValue<O extends {
15
15
  multiple: true;
16
16
  } ? true : false>;
17
17
  type RepeaterValue<O> = O extends {
@@ -54,6 +54,18 @@ declare const fields: {
54
54
  relation: <const O extends RelationFieldOptions>(opts: O) => TypedField<RelationValue<O>, Declared<O>>;
55
55
  };
56
56
 
57
+ /**
58
+ * A media value as it can reach a block during the CMS-1149 transition: the
59
+ * resolved object a current API returns, or the bare URL string an API that
60
+ * has not been upgraded yet still returns. The string arm exists so a site can
61
+ * upgrade its SDK and its cmssy independently; it goes away once no supported
62
+ * cmssy serves strings.
63
+ */
64
+ type MediaLike = ResolvedMedia | string | null | undefined;
65
+ declare function mediaUrl(value: MediaLike): string | null;
66
+ declare function mediaUrls(value: readonly MediaLike[] | null | undefined): string[];
67
+ declare function mediaAlt(value: MediaLike): string | undefined;
68
+
57
69
  declare const CMSSY_EDIT_HEADER = "x-cmssy-edit";
58
70
  declare const CMSSY_EDIT_QUERY_PARAM = "cmssyEdit";
59
71
  declare const CMSSY_SECRET_QUERY_PARAM = "cmssySecret";
@@ -72,4 +84,4 @@ declare class CmssyWebhookError extends Error {
72
84
  }
73
85
  declare function verifyCmssyWebhook(options: VerifyCmssyWebhookOptions): Promise<CmssyWebhookEvent>;
74
86
 
75
- export { CMSSY_EDIT_HEADER, CMSSY_EDIT_QUERY_PARAM, CMSSY_SECRET_QUERY_PARAM, CmssyWebhookError, fields, isVerifiedEditUrl, verifyCmssyWebhook };
87
+ export { CMSSY_EDIT_HEADER, CMSSY_EDIT_QUERY_PARAM, CMSSY_SECRET_QUERY_PARAM, CmssyWebhookError, type MediaLike, fields, isVerifiedEditUrl, mediaAlt, mediaUrl, mediaUrls, verifyCmssyWebhook };
package/dist/index.js CHANGED
@@ -497,6 +497,19 @@ var fields = {
497
497
  }
498
498
  };
499
499
 
500
+ // src/media.ts
501
+ function mediaUrl(value) {
502
+ if (typeof value === "string") return value || null;
503
+ return value?.url ?? null;
504
+ }
505
+ function mediaUrls(value) {
506
+ if (!Array.isArray(value)) return [];
507
+ return value.map((item) => mediaUrl(item)).filter((url) => url !== null);
508
+ }
509
+ function mediaAlt(value) {
510
+ return typeof value === "string" ? void 0 : value?.alt;
511
+ }
512
+
500
513
  // src/data/localize-href.ts
501
514
  var PROTOCOL_OR_RELATIVE = /^([a-z][a-z0-9+.-]*:|\/\/)/i;
502
515
  function isExternalHref(href) {
@@ -852,4 +865,4 @@ async function verifyCmssyWebhook(options) {
852
865
  return parsed;
853
866
  }
854
867
 
855
- export { CMSSY_EDIT_HEADER, CMSSY_EDIT_QUERY_PARAM, CMSSY_LOCALE_HEADER, CMSSY_SECRET_QUERY_PARAM, CmssyRequestError, CmssyWebhookError, DEFAULT_CMSSY_API_URL, DEFAULT_CMSSY_EDITOR_ORIGINS, PROTOCOL_VERSION, applyCmssyCsp, createCmssyClient, defineCmssyConfig, fields, graphqlRequest, isProtocolCompatible, isVerifiedEditUrl, localizeHref, normalizeOrigin, parseEditorMessage, postToEditor, resolveCmssyLocale, resolveEditorOrigin, verifyCmssyWebhook };
868
+ export { CMSSY_EDIT_HEADER, CMSSY_EDIT_QUERY_PARAM, CMSSY_LOCALE_HEADER, CMSSY_SECRET_QUERY_PARAM, CmssyRequestError, CmssyWebhookError, DEFAULT_CMSSY_API_URL, DEFAULT_CMSSY_EDITOR_ORIGINS, PROTOCOL_VERSION, applyCmssyCsp, createCmssyClient, defineCmssyConfig, fields, graphqlRequest, isProtocolCompatible, isVerifiedEditUrl, localizeHref, mediaAlt, mediaUrl, mediaUrls, normalizeOrigin, parseEditorMessage, postToEditor, resolveCmssyLocale, resolveEditorOrigin, verifyCmssyWebhook };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmssy/core",
3
- "version": "11.9.0",
3
+ "version": "12.1.0",
4
4
  "description": "Framework-agnostic cmssy gateway: GraphQL client, block/field system, editor protocol. No React, no Next.",
5
5
  "keywords": [
6
6
  "cmssy",
@@ -87,7 +87,7 @@
87
87
  "vitest": "^2.1.0"
88
88
  },
89
89
  "dependencies": {
90
- "@cmssy/types": "0.34.0",
90
+ "@cmssy/types": "0.35.0",
91
91
  "jose": "^6.2.3"
92
92
  },
93
93
  "scripts": {