@feelflow/ffid-sdk 5.24.3 → 5.27.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.
@@ -110,6 +110,24 @@ function isSessionEligibleSubscriptionStatus(value) {
110
110
  function hasOwnKey(value, key) {
111
111
  return Object.prototype.hasOwnProperty.call(value, key);
112
112
  }
113
+ function normalizeEntitlements(raw) {
114
+ if (!Array.isArray(raw)) return [];
115
+ return raw.flatMap((code) => {
116
+ if (typeof code !== "string") return [];
117
+ const trimmed = code.trim();
118
+ return trimmed.length > 0 ? [trimmed] : [];
119
+ });
120
+ }
121
+ function normalizeSeatAssignmentClaim(raw, organizationId, subscriptionId) {
122
+ if (!raw || typeof raw !== "object") return null;
123
+ const { organization_id, subscription_id, status } = raw;
124
+ if (typeof organization_id !== "string" || typeof subscription_id !== "string" || typeof status !== "string" || !["active", "revoking", "revoked"].includes(status) || organization_id !== organizationId || subscription_id !== subscriptionId) return null;
125
+ return {
126
+ organizationId: organization_id,
127
+ subscriptionId: subscription_id,
128
+ status
129
+ };
130
+ }
113
131
  function normalizeUserinfo(raw) {
114
132
  const hasOrganizationId = hasOwnKey(raw, "organization_id");
115
133
  const hasOrganizationName = hasOwnKey(raw, "organization_name");
@@ -143,6 +161,11 @@ function normalizeUserinfo(raw) {
143
161
  organizationId: raw.subscription.organization_id ?? null,
144
162
  organizationName: hasOwnKey(raw.subscription, "organization_name") ? raw.subscription.organization_name ?? null : null,
145
163
  hasSeatAssignment: raw.subscription.has_seat_assignment ?? false,
164
+ seatAssignment: hasOwnKey(raw.subscription, "seat_assignment") ? normalizeSeatAssignmentClaim(
165
+ raw.subscription.seat_assignment,
166
+ raw.subscription.organization_id ?? null,
167
+ raw.subscription.subscription_id ?? null
168
+ ) : void 0,
146
169
  // #3464: legacy FFID (< this issue) omits the field on the wire.
147
170
  // The "unknown" axis is unused — no consumer differentiates "server
148
171
  // didn't tell us" from "definitely not scheduled" because the
@@ -150,7 +173,10 @@ function normalizeUserinfo(raw) {
150
173
  // `'active_canceling'`) for legacy backends. Defaulting to `false`
151
174
  // here keeps the downstream contract a plain boolean.
152
175
  cancelAtPeriodEnd: raw.subscription.cancel_at_period_end ?? false,
153
- currentPeriodEnd: raw.subscription.current_period_end ?? null
176
+ currentPeriodEnd: raw.subscription.current_period_end ?? null,
177
+ // #4333: legacy FFID (< this issue) omits the field on the wire; the
178
+ // guard defaults to `[]` so consumers always get a plain string[].
179
+ entitlements: normalizeEntitlements(raw.subscription.entitlements)
154
180
  } : void 0
155
181
  };
156
182
  }
@@ -437,7 +463,12 @@ function createVerifyAccessToken(deps) {
437
463
  member_role: introspectResponse.subscription.member_role,
438
464
  organization_id: introspectResponse.subscription.organization_id,
439
465
  organization_name: introspectResponse.subscription.organization_name ?? null,
440
- has_seat_assignment: introspectResponse.subscription.has_seat_assignment ?? false
466
+ has_seat_assignment: introspectResponse.subscription.has_seat_assignment ?? false,
467
+ ...Object.prototype.hasOwnProperty.call(introspectResponse.subscription, "seat_assignment") ? { seat_assignment: introspectResponse.subscription.seat_assignment } : {},
468
+ // #4333: forward pack entitlement codes through the introspect →
469
+ // userinfo normalization boundary. normalizeUserinfo guards the
470
+ // value, so an older FFID that omits it degrades to `[]`.
471
+ entitlements: introspectResponse.subscription.entitlements
441
472
  }
442
473
  } : base;
443
474
  const userinfo = normalizeUserinfo(raw);
@@ -808,6 +839,213 @@ function createSubscriptionMethods(deps) {
808
839
  };
809
840
  }
810
841
 
842
+ // src/types/published-catalog.ts
843
+ var FFID_CATALOG_ENVIRONMENTS = ["staging", "production"];
844
+ var FFID_CATALOG_PUBLICATION_STATUSES = [
845
+ "approved",
846
+ "superseded",
847
+ "revoking",
848
+ "revoked"
849
+ ];
850
+
851
+ // src/shared/catalog-hash.ts
852
+ var CATALOG_HASH_PATTERN = /^[0-9a-f]{64}$/;
853
+
854
+ // src/client/catalog-methods.ts
855
+ var EXT_CATALOG_ENDPOINT = "/api/v1/subscriptions/ext/catalog";
856
+ var MALFORMED_CATALOG_CODE = "MALFORMED_PUBLISHED_CATALOG";
857
+ var PUBLICATION_STATUSES = new Set(
858
+ FFID_CATALOG_PUBLICATION_STATUSES
859
+ );
860
+ var CATALOG_ENVIRONMENTS = new Set(FFID_CATALOG_ENVIRONMENTS);
861
+ var BILLING_INTERVALS = /* @__PURE__ */ new Set(["monthly", "yearly"]);
862
+ var TAX_BEHAVIORS = /* @__PURE__ */ new Set(["inclusive", "exclusive"]);
863
+ var PUBLICATION_HASH_FIELDS = [
864
+ "praxisCopyHash",
865
+ "ffidCheckoutCopyHash",
866
+ "legalDisclosureHash",
867
+ "taxConfigurationHash",
868
+ "paymentConfigurationHash",
869
+ "scopeHash"
870
+ ];
871
+ var PUBLICATION_REQUIRED_TIMESTAMP_FIELDS = ["reviewedAt", "effectiveAt"];
872
+ var PUBLICATION_NULLABLE_TIMESTAMP_FIELDS = [
873
+ "supersededAt",
874
+ "sellThroughUntil",
875
+ "revocationEffectiveAt"
876
+ ];
877
+ function malformed(detail) {
878
+ return new FFIDSDKError(
879
+ MALFORMED_CATALOG_CODE,
880
+ `SDK: server returned malformed PublishedCatalog \u2014 ${detail}`
881
+ );
882
+ }
883
+ function isNullableIsoString(value) {
884
+ return value === null || typeof value === "string" && value.trim() !== "";
885
+ }
886
+ function isNonNegativeIntOrNull(value) {
887
+ return value === null || typeof value === "number" && Number.isInteger(value) && value >= 0;
888
+ }
889
+ function validatePublishedPlan(plan, index) {
890
+ if (plan === null || typeof plan !== "object") {
891
+ throw malformed(`plans[${index}] must be an object`);
892
+ }
893
+ const record = plan;
894
+ for (const key of Object.keys(record)) {
895
+ if (/stripe/i.test(key)) {
896
+ throw malformed(
897
+ `plans[${index}] contains a Stripe identifier field (${JSON.stringify(key)}) \u2014 published catalogs must never expose Stripe IDs`
898
+ );
899
+ }
900
+ }
901
+ if (isBlankString(record.code)) {
902
+ throw malformed(`plans[${index}].code must be a non-empty string`);
903
+ }
904
+ if (isBlankString(record.name)) {
905
+ throw malformed(`plans[${index}].name must be a non-empty string`);
906
+ }
907
+ if (record.description !== null && typeof record.description !== "string") {
908
+ throw malformed(`plans[${index}].description must be string or null`);
909
+ }
910
+ if (isBlankString(record.currency)) {
911
+ throw malformed(`plans[${index}].currency must be a non-empty string`);
912
+ }
913
+ if (!isNonNegativeIntOrNull(record.priceMonthly)) {
914
+ throw malformed(`plans[${index}].priceMonthly must be a non-negative integer or null`);
915
+ }
916
+ if (!isNonNegativeIntOrNull(record.priceYearly)) {
917
+ throw malformed(`plans[${index}].priceYearly must be a non-negative integer or null`);
918
+ }
919
+ if (typeof record.taxBehavior !== "string" || !TAX_BEHAVIORS.has(record.taxBehavior)) {
920
+ throw malformed(
921
+ `plans[${index}].taxBehavior must be inclusive | exclusive (got ${JSON.stringify(record.taxBehavior)})`
922
+ );
923
+ }
924
+ const intervals = record.billingIntervals;
925
+ if (!Array.isArray(intervals) || intervals.length === 0 || intervals.some((interval) => typeof interval !== "string" || !BILLING_INTERVALS.has(interval))) {
926
+ throw malformed(
927
+ `plans[${index}].billingIntervals must be a non-empty array of monthly | yearly`
928
+ );
929
+ }
930
+ if (intervals.includes("monthly") && record.priceMonthly === null) {
931
+ throw malformed(`plans[${index}] offers monthly billing but priceMonthly is null`);
932
+ }
933
+ if (intervals.includes("yearly") && record.priceYearly === null) {
934
+ throw malformed(`plans[${index}] offers yearly billing but priceYearly is null`);
935
+ }
936
+ if (typeof record.minSeats !== "number" || !Number.isInteger(record.minSeats) || record.minSeats < 1) {
937
+ throw malformed(`plans[${index}].minSeats must be a positive integer`);
938
+ }
939
+ if (record.maxSeats !== null && (typeof record.maxSeats !== "number" || !Number.isInteger(record.maxSeats) || record.maxSeats < 1)) {
940
+ throw malformed(`plans[${index}].maxSeats must be a positive integer or null`);
941
+ }
942
+ if (record.maxSeats !== null && record.maxSeats < record.minSeats) {
943
+ throw malformed(`plans[${index}].maxSeats must be >= minSeats`);
944
+ }
945
+ if (typeof record.displayOrder !== "number" || !Number.isInteger(record.displayOrder)) {
946
+ throw malformed(`plans[${index}].displayOrder must be an integer`);
947
+ }
948
+ }
949
+ function validatePublishedCatalog(catalog) {
950
+ if (catalog === null || typeof catalog !== "object") {
951
+ throw malformed(
952
+ `expected object, got ${catalog === null ? "null" : typeof catalog}`
953
+ );
954
+ }
955
+ const c = catalog;
956
+ const service = c.service;
957
+ if (service === null || typeof service !== "object") {
958
+ throw malformed("service must be an object");
959
+ }
960
+ const s = service;
961
+ if (isBlankString(s.code)) {
962
+ throw malformed("service.code must be a non-empty string");
963
+ }
964
+ if (isBlankString(s.name)) {
965
+ throw malformed("service.name must be a non-empty string");
966
+ }
967
+ if (isBlankString(c.catalogVersion)) {
968
+ throw malformed("catalogVersion must be a non-empty string");
969
+ }
970
+ const publication = c.publication;
971
+ if (publication === null || typeof publication !== "object") {
972
+ throw malformed("publication must be an object");
973
+ }
974
+ const p = publication;
975
+ if (isBlankString(p.serviceCode)) {
976
+ throw malformed("publication.serviceCode must be a non-empty string");
977
+ }
978
+ if (typeof p.environment !== "string" || !CATALOG_ENVIRONMENTS.has(p.environment)) {
979
+ throw malformed(
980
+ `publication.environment must be staging | production (got ${JSON.stringify(p.environment)})`
981
+ );
982
+ }
983
+ if (p.catalogVersion !== c.catalogVersion) {
984
+ throw malformed(
985
+ `publication.catalogVersion (${JSON.stringify(p.catalogVersion)}) does not match top-level catalogVersion (${JSON.stringify(c.catalogVersion)})`
986
+ );
987
+ }
988
+ if (typeof p.status !== "string" || !PUBLICATION_STATUSES.has(p.status)) {
989
+ throw malformed(
990
+ `publication.status must be one of approved | superseded | revoking | revoked (got ${JSON.stringify(p.status)})`
991
+ );
992
+ }
993
+ for (const field of PUBLICATION_HASH_FIELDS) {
994
+ const value = p[field];
995
+ if (typeof value !== "string" || !CATALOG_HASH_PATTERN.test(value)) {
996
+ throw malformed(`publication.${field} must be lowercase SHA-256 hex (64 chars)`);
997
+ }
998
+ }
999
+ if (typeof p.salesEpoch !== "number" || !Number.isInteger(p.salesEpoch) || p.salesEpoch < 1) {
1000
+ throw malformed(
1001
+ `publication.salesEpoch must be a positive integer (got ${JSON.stringify(p.salesEpoch)})`
1002
+ );
1003
+ }
1004
+ if (isBlankString(p.approvalId)) {
1005
+ throw malformed("publication.approvalId must be a non-empty string");
1006
+ }
1007
+ for (const field of PUBLICATION_REQUIRED_TIMESTAMP_FIELDS) {
1008
+ if (isBlankString(p[field])) {
1009
+ throw malformed(`publication.${field} must be a non-empty ISO 8601 string`);
1010
+ }
1011
+ }
1012
+ for (const field of PUBLICATION_NULLABLE_TIMESTAMP_FIELDS) {
1013
+ if (!isNullableIsoString(p[field])) {
1014
+ throw malformed(`publication.${field} must be a non-empty ISO 8601 string or null`);
1015
+ }
1016
+ }
1017
+ if (!Array.isArray(c.plans)) {
1018
+ throw malformed(`plans must be an array (got ${typeof c.plans})`);
1019
+ }
1020
+ for (const [index, plan] of c.plans.entries()) {
1021
+ validatePublishedPlan(plan, index);
1022
+ }
1023
+ }
1024
+ function createCatalogMethods(deps) {
1025
+ const { fetchWithAuth, createError } = deps;
1026
+ async function getPublishedCatalog(serviceCode) {
1027
+ if (isBlankString(serviceCode)) {
1028
+ return {
1029
+ error: createError("VALIDATION_ERROR", "serviceCode \u306F\u5FC5\u9808\u3067\u3059")
1030
+ };
1031
+ }
1032
+ const requestedCode = serviceCode.trim();
1033
+ const response = await fetchWithAuth(
1034
+ `${EXT_CATALOG_ENDPOINT}/${encodeURIComponent(requestedCode)}`
1035
+ );
1036
+ if (response.data !== void 0) {
1037
+ validatePublishedCatalog(response.data);
1038
+ if (response.data.service.code !== requestedCode || response.data.publication.serviceCode !== requestedCode) {
1039
+ throw malformed(
1040
+ `response is for service ${JSON.stringify(response.data.service.code)} (publication: ${JSON.stringify(response.data.publication.serviceCode)}) but ${JSON.stringify(requestedCode)} was requested`
1041
+ );
1042
+ }
1043
+ }
1044
+ return response;
1045
+ }
1046
+ return { getPublishedCatalog };
1047
+ }
1048
+
811
1049
  // src/client/members-methods.ts
812
1050
  var EXT_MEMBERS_ENDPOINT = "/api/v1/organizations/ext/members";
813
1051
  function createMembersMethods(deps) {
@@ -1250,7 +1488,7 @@ function validateTokenResponse(tokenResponse) {
1250
1488
  }
1251
1489
 
1252
1490
  // src/client/version-check.ts
1253
- var SDK_VERSION = "5.24.3";
1491
+ var SDK_VERSION = "5.27.0";
1254
1492
  var SDK_USER_AGENT = `FFID-SDK/${SDK_VERSION} (TypeScript)`;
1255
1493
  var SDK_VERSION_HEADER = "X-FFID-SDK-Version";
1256
1494
  function sdkHeaders() {
@@ -2694,39 +2932,7 @@ var BLOCKING_EFFECTIVE_STATUSES = [
2694
2932
  "trial_expired"
2695
2933
  ];
2696
2934
 
2697
- // src/client/error-codes.ts
2698
- var FFID_ERROR_CODES = {
2699
- NETWORK_ERROR: "NETWORK_ERROR",
2700
- PARSE_ERROR: "PARSE_ERROR",
2701
- UNKNOWN_ERROR: "UNKNOWN_ERROR",
2702
- TOKEN_EXCHANGE_ERROR: "TOKEN_EXCHANGE_ERROR",
2703
- TOKEN_REFRESH_ERROR: "TOKEN_REFRESH_ERROR",
2704
- NO_TOKENS: "NO_TOKENS",
2705
- TOKEN_VERIFICATION_ERROR: "TOKEN_VERIFICATION_ERROR",
2706
- TOKEN_EXPIRED: "TOKEN_EXPIRED",
2707
- STATE_MISMATCH_ERROR: "STATE_MISMATCH_ERROR"
2708
- };
2709
-
2710
- // src/client/ffid-client.ts
2711
- var UNAUTHORIZED_STATUS2 = 401;
2712
- var SDK_LOG_PREFIX = "[FFID SDK]";
2713
- var noopLogger = {
2714
- debug: () => {
2715
- },
2716
- info: () => {
2717
- },
2718
- warn: () => {
2719
- },
2720
- error: () => {
2721
- }
2722
- };
2723
- var consoleLogger = {
2724
- debug: (...args) => console.debug(SDK_LOG_PREFIX, ...args),
2725
- info: (...args) => console.info(SDK_LOG_PREFIX, ...args),
2726
- warn: (...args) => console.warn(SDK_LOG_PREFIX, ...args),
2727
- error: (...args) => console.error(SDK_LOG_PREFIX, ...args)
2728
- };
2729
- var EXT_CHECK_ENDPOINT = "/api/v1/subscriptions/ext/check";
2935
+ // src/client/service-access-decision.ts
2730
2936
  var DEFAULT_ALLOW_GRACE = true;
2731
2937
  var DEFAULT_SERVICE_ACCESS_FAIL_POLICY = "failClosed";
2732
2938
  var SERVICE_ACCESS_DENIED_CODE = "SERVICE_ACCESS_DENIED";
@@ -2793,6 +2999,40 @@ function failClosedServiceAccessDecision(params, error) {
2793
2999
  error
2794
3000
  };
2795
3001
  }
3002
+
3003
+ // src/client/error-codes.ts
3004
+ var FFID_ERROR_CODES = {
3005
+ NETWORK_ERROR: "NETWORK_ERROR",
3006
+ PARSE_ERROR: "PARSE_ERROR",
3007
+ UNKNOWN_ERROR: "UNKNOWN_ERROR",
3008
+ TOKEN_EXCHANGE_ERROR: "TOKEN_EXCHANGE_ERROR",
3009
+ TOKEN_REFRESH_ERROR: "TOKEN_REFRESH_ERROR",
3010
+ NO_TOKENS: "NO_TOKENS",
3011
+ TOKEN_VERIFICATION_ERROR: "TOKEN_VERIFICATION_ERROR",
3012
+ TOKEN_EXPIRED: "TOKEN_EXPIRED",
3013
+ STATE_MISMATCH_ERROR: "STATE_MISMATCH_ERROR"
3014
+ };
3015
+
3016
+ // src/client/ffid-client.ts
3017
+ var UNAUTHORIZED_STATUS2 = 401;
3018
+ var SDK_LOG_PREFIX = "[FFID SDK]";
3019
+ var noopLogger = {
3020
+ debug: () => {
3021
+ },
3022
+ info: () => {
3023
+ },
3024
+ warn: () => {
3025
+ },
3026
+ error: () => {
3027
+ }
3028
+ };
3029
+ var consoleLogger = {
3030
+ debug: (...args) => console.debug(SDK_LOG_PREFIX, ...args),
3031
+ info: (...args) => console.info(SDK_LOG_PREFIX, ...args),
3032
+ warn: (...args) => console.warn(SDK_LOG_PREFIX, ...args),
3033
+ error: (...args) => console.error(SDK_LOG_PREFIX, ...args)
3034
+ };
3035
+ var EXT_CHECK_ENDPOINT = "/api/v1/subscriptions/ext/check";
2796
3036
  function resolveRedirectUri(raw, logger) {
2797
3037
  if (raw === null) return null;
2798
3038
  try {
@@ -3110,6 +3350,10 @@ function createFFIDClient(config) {
3110
3350
  fetchWithAuth,
3111
3351
  createError
3112
3352
  });
3353
+ const { getPublishedCatalog } = createCatalogMethods({
3354
+ fetchWithAuth,
3355
+ createError
3356
+ });
3113
3357
  const { listMembers, addMember, updateMemberRole, removeMember } = createMembersMethods({
3114
3358
  fetchWithAuth,
3115
3359
  createError,
@@ -3236,6 +3480,7 @@ function createFFIDClient(config) {
3236
3480
  assignSeats,
3237
3481
  unassignSeat,
3238
3482
  listPlans,
3483
+ getPublishedCatalog,
3239
3484
  getSubscription,
3240
3485
  subscribe,
3241
3486
  changePlan,
@@ -1,4 +1,4 @@
1
- import { k as FFIDClient, e as FFIDOAuthUserInfo } from '../../ffid-client-BjZphrz9.cjs';
1
+ import { k as FFIDClient, e as FFIDOAuthUserInfo } from '../../ffid-client-BlVuH6ja.cjs';
2
2
  import '../../types-Cjb9J0rL.cjs';
3
3
 
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { k as FFIDClient, e as FFIDOAuthUserInfo } from '../../ffid-client-B-xjtrCb.js';
1
+ import { k as FFIDClient, e as FFIDOAuthUserInfo } from '../../ffid-client-BqnzUmG7.js';
2
2
  import '../../types-Cjb9J0rL.js';
3
3
 
4
4
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@feelflow/ffid-sdk",
3
- "version": "5.24.3",
3
+ "version": "5.27.0",
4
4
  "description": "FeelFlow ID Platform SDK for React/Next.js applications",
5
5
  "keywords": [
6
6
  "feelflow",