@feelflow/ffid-sdk 5.25.0 → 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.
@@ -118,6 +118,16 @@ function normalizeEntitlements(raw) {
118
118
  return trimmed.length > 0 ? [trimmed] : [];
119
119
  });
120
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
+ }
121
131
  function normalizeUserinfo(raw) {
122
132
  const hasOrganizationId = hasOwnKey(raw, "organization_id");
123
133
  const hasOrganizationName = hasOwnKey(raw, "organization_name");
@@ -151,6 +161,11 @@ function normalizeUserinfo(raw) {
151
161
  organizationId: raw.subscription.organization_id ?? null,
152
162
  organizationName: hasOwnKey(raw.subscription, "organization_name") ? raw.subscription.organization_name ?? null : null,
153
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,
154
169
  // #3464: legacy FFID (< this issue) omits the field on the wire.
155
170
  // The "unknown" axis is unused — no consumer differentiates "server
156
171
  // didn't tell us" from "definitely not scheduled" because the
@@ -449,6 +464,7 @@ function createVerifyAccessToken(deps) {
449
464
  organization_id: introspectResponse.subscription.organization_id,
450
465
  organization_name: introspectResponse.subscription.organization_name ?? null,
451
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 } : {},
452
468
  // #4333: forward pack entitlement codes through the introspect →
453
469
  // userinfo normalization boundary. normalizeUserinfo guards the
454
470
  // value, so an older FFID that omits it degrades to `[]`.
@@ -823,6 +839,213 @@ function createSubscriptionMethods(deps) {
823
839
  };
824
840
  }
825
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
+
826
1049
  // src/client/members-methods.ts
827
1050
  var EXT_MEMBERS_ENDPOINT = "/api/v1/organizations/ext/members";
828
1051
  function createMembersMethods(deps) {
@@ -1265,7 +1488,7 @@ function validateTokenResponse(tokenResponse) {
1265
1488
  }
1266
1489
 
1267
1490
  // src/client/version-check.ts
1268
- var SDK_VERSION = "5.25.0";
1491
+ var SDK_VERSION = "5.27.0";
1269
1492
  var SDK_USER_AGENT = `FFID-SDK/${SDK_VERSION} (TypeScript)`;
1270
1493
  var SDK_VERSION_HEADER = "X-FFID-SDK-Version";
1271
1494
  function sdkHeaders() {
@@ -2709,39 +2932,7 @@ var BLOCKING_EFFECTIVE_STATUSES = [
2709
2932
  "trial_expired"
2710
2933
  ];
2711
2934
 
2712
- // src/client/error-codes.ts
2713
- var FFID_ERROR_CODES = {
2714
- NETWORK_ERROR: "NETWORK_ERROR",
2715
- PARSE_ERROR: "PARSE_ERROR",
2716
- UNKNOWN_ERROR: "UNKNOWN_ERROR",
2717
- TOKEN_EXCHANGE_ERROR: "TOKEN_EXCHANGE_ERROR",
2718
- TOKEN_REFRESH_ERROR: "TOKEN_REFRESH_ERROR",
2719
- NO_TOKENS: "NO_TOKENS",
2720
- TOKEN_VERIFICATION_ERROR: "TOKEN_VERIFICATION_ERROR",
2721
- TOKEN_EXPIRED: "TOKEN_EXPIRED",
2722
- STATE_MISMATCH_ERROR: "STATE_MISMATCH_ERROR"
2723
- };
2724
-
2725
- // src/client/ffid-client.ts
2726
- var UNAUTHORIZED_STATUS2 = 401;
2727
- var SDK_LOG_PREFIX = "[FFID SDK]";
2728
- var noopLogger = {
2729
- debug: () => {
2730
- },
2731
- info: () => {
2732
- },
2733
- warn: () => {
2734
- },
2735
- error: () => {
2736
- }
2737
- };
2738
- var consoleLogger = {
2739
- debug: (...args) => console.debug(SDK_LOG_PREFIX, ...args),
2740
- info: (...args) => console.info(SDK_LOG_PREFIX, ...args),
2741
- warn: (...args) => console.warn(SDK_LOG_PREFIX, ...args),
2742
- error: (...args) => console.error(SDK_LOG_PREFIX, ...args)
2743
- };
2744
- var EXT_CHECK_ENDPOINT = "/api/v1/subscriptions/ext/check";
2935
+ // src/client/service-access-decision.ts
2745
2936
  var DEFAULT_ALLOW_GRACE = true;
2746
2937
  var DEFAULT_SERVICE_ACCESS_FAIL_POLICY = "failClosed";
2747
2938
  var SERVICE_ACCESS_DENIED_CODE = "SERVICE_ACCESS_DENIED";
@@ -2808,6 +2999,40 @@ function failClosedServiceAccessDecision(params, error) {
2808
2999
  error
2809
3000
  };
2810
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";
2811
3036
  function resolveRedirectUri(raw, logger) {
2812
3037
  if (raw === null) return null;
2813
3038
  try {
@@ -3125,6 +3350,10 @@ function createFFIDClient(config) {
3125
3350
  fetchWithAuth,
3126
3351
  createError
3127
3352
  });
3353
+ const { getPublishedCatalog } = createCatalogMethods({
3354
+ fetchWithAuth,
3355
+ createError
3356
+ });
3128
3357
  const { listMembers, addMember, updateMemberRole, removeMember } = createMembersMethods({
3129
3358
  fetchWithAuth,
3130
3359
  createError,
@@ -3251,6 +3480,7 @@ function createFFIDClient(config) {
3251
3480
  assignSeats,
3252
3481
  unassignSeat,
3253
3482
  listPlans,
3483
+ getPublishedCatalog,
3254
3484
  getSubscription,
3255
3485
  subscribe,
3256
3486
  changePlan,
@@ -1,4 +1,4 @@
1
- import { k as FFIDClient, e as FFIDOAuthUserInfo } from '../../ffid-client-BZERrMAF.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-CFZPX5ej.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.25.0",
3
+ "version": "5.27.0",
4
4
  "description": "FeelFlow ID Platform SDK for React/Next.js applications",
5
5
  "keywords": [
6
6
  "feelflow",