@burdenoff/microfe-semanticfed 2026.1030.1 → 2026.1031.1

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.
@@ -0,0 +1,44 @@
1
+ //#region src/semanticfed/api/quotaRefusal.ts
2
+ var e = "burdenoff:upgrade-prompt", t = ["QUOTA_EXHAUSTED", "QUOTA_NOT_PROVISIONED"], n = {
3
+ semCreateConnector: "semanticfed.connectors.count",
4
+ semCreateDataSource: "semanticfed.sources.count",
5
+ semCreateModel: "semanticfed.models.count",
6
+ semPublishQuery: "semanticfed.queries.published",
7
+ semRunQuery: "semanticfed.query_runs.monthly"
8
+ };
9
+ function r(e) {
10
+ return typeof e == "string" && t.includes(e);
11
+ }
12
+ function i(e) {
13
+ for (let t of e ?? []) {
14
+ let e = t.extensions;
15
+ if (!e || !r(e.code)) continue;
16
+ let i = typeof e.field == "string" ? e.field : void 0, a = typeof e.quotaName == "string" ? e.quotaName : i === void 0 ? void 0 : n[i];
17
+ return {
18
+ code: e.code,
19
+ field: i,
20
+ quotaName: a,
21
+ limitLeft: typeof e.limitLeft == "number" ? e.limitLeft : void 0
22
+ };
23
+ }
24
+ return null;
25
+ }
26
+ function a(t) {
27
+ typeof window > "u" || window.dispatchEvent(new CustomEvent(e, { detail: { extensions: {
28
+ code: t.code,
29
+ field: t.field,
30
+ quotaName: t.quotaName,
31
+ resource: t.quotaName ?? t.field,
32
+ limitLeft: t.limitLeft
33
+ } } }));
34
+ }
35
+ var o = class extends Error {
36
+ refusal;
37
+ constructor(e, t) {
38
+ super(e), this.name = "SemQuotaError", this.refusal = t;
39
+ }
40
+ };
41
+ //#endregion
42
+ export { o as SemQuotaError, a as announceQuotaRefusal, i as findQuotaRefusal };
43
+
44
+ //# sourceMappingURL=quotaRefusal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quotaRefusal.js","names":[],"sources":["../../../src/semanticfed/api/quotaRefusal.ts"],"sourcesContent":["/**\n * Plan-limit refusals from the workspace gateway (BOFF-3172).\n *\n * SemanticFed's billable mutations carry `@usage(checkQuota: true)`. When a\n * workspace has used up its plan's allowance the gateway refuses the call\n * before the resolver runs, with HTTP 429 and a GraphQL error whose\n * `extensions.code` is `QUOTA_EXHAUSTED` (or `QUOTA_NOT_PROVISIONED` when the\n * workspace holds no SemanticFed plan rows at all). The refusal names the\n * mutation in `extensions.field`, not the quota, so this module maps the field\n * back to its quota name.\n *\n * The refusal is announced on the shell's `burdenoff:upgrade-prompt` window\n * event, which the host shell answers with the shared `UpgradePromptModal`\n * (its CTA leads to the plan picker). The event is a plain DOM contract, so the\n * microfrontend does not import the modal or depend on the host's fe-libs\n * version.\n */\n\n/** Window event the host shell's `UpgradePromptModal` listens for. */\nconst UPGRADE_PROMPT_EVENT = 'burdenoff:upgrade-prompt';\n\nconst QUOTA_REFUSAL_CODES = ['QUOTA_EXHAUSTED', 'QUOTA_NOT_PROVISIONED'] as const;\n\ntype QuotaRefusalCode = (typeof QUOTA_REFUSAL_CODES)[number];\n\n/**\n * Billable SemanticFed mutation -> the quota its `@usage` directive charges.\n * Must match `wspace-semanticfed-svc` (src/utils/usage-billing.ts).\n */\nconst SEMANTICFED_QUOTA_BY_FIELD: Readonly<Record<string, string>> = {\n semCreateConnector: 'semanticfed.connectors.count',\n semCreateDataSource: 'semanticfed.sources.count',\n semCreateModel: 'semanticfed.models.count',\n semPublishQuery: 'semanticfed.queries.published',\n semRunQuery: 'semanticfed.query_runs.monthly',\n};\n\nexport interface QuotaRefusal {\n code: QuotaRefusalCode;\n /** Mutation the gateway refused, when it said. */\n field?: string;\n /** Quota the refused mutation charges, when the field is a known one. */\n quotaName?: string;\n /** Units left on the quota (absent when the quota was never provisioned). */\n limitLeft?: number;\n}\n\ninterface GraphQLErrorLike {\n message?: string;\n extensions?: Record<string, unknown> | null;\n}\n\nfunction isQuotaRefusalCode(value: unknown): value is QuotaRefusalCode {\n return typeof value === 'string' && (QUOTA_REFUSAL_CODES as readonly string[]).includes(value);\n}\n\n/** The first plan-limit refusal among GraphQL errors, or null. */\nexport function findQuotaRefusal(\n errors: readonly GraphQLErrorLike[] | undefined\n): QuotaRefusal | null {\n for (const error of errors ?? []) {\n const ext = error.extensions;\n if (!ext || !isQuotaRefusalCode(ext.code)) continue;\n const field = typeof ext.field === 'string' ? ext.field : undefined;\n const quotaName =\n typeof ext.quotaName === 'string'\n ? ext.quotaName\n : field !== undefined\n ? SEMANTICFED_QUOTA_BY_FIELD[field]\n : undefined;\n return {\n code: ext.code,\n field,\n quotaName,\n limitLeft: typeof ext.limitLeft === 'number' ? ext.limitLeft : undefined,\n };\n }\n return null;\n}\n\n/**\n * Ask the host shell to show its upgrade prompt for a refusal. The quota name\n * is passed as the `resource`, which the shell translates into the limited\n * resource's name. Safe no-op outside a browser.\n */\nexport function announceQuotaRefusal(refusal: QuotaRefusal): void {\n if (typeof window === 'undefined') return;\n window.dispatchEvent(\n new CustomEvent(UPGRADE_PROMPT_EVENT, {\n detail: {\n extensions: {\n code: refusal.code,\n field: refusal.field,\n quotaName: refusal.quotaName,\n resource: refusal.quotaName ?? refusal.field,\n limitLeft: refusal.limitLeft,\n },\n },\n })\n );\n}\n\n/** Error thrown by `semRequest` for a plan-limit refusal. */\nexport class SemQuotaError extends Error {\n readonly refusal: QuotaRefusal;\n\n constructor(message: string, refusal: QuotaRefusal) {\n super(message);\n this.name = 'SemQuotaError';\n this.refusal = refusal;\n }\n}\n"],"mappings":";AAmBA,IAAM,IAAuB,4BAEvB,IAAsB,CAAC,mBAAmB,wBAAwB,EAQlE,IAA+D;CACnE,oBAAoB;CACpB,qBAAqB;CACrB,gBAAgB;CAChB,iBAAiB;CACjB,aAAa;CACd;AAiBD,SAAS,EAAmB,GAA2C;AACrE,QAAO,OAAO,KAAU,YAAa,EAA0C,SAAS,EAAM;;AAIhG,SAAgB,EACd,GACqB;AACrB,MAAK,IAAM,KAAS,KAAU,EAAE,EAAE;EAChC,IAAM,IAAM,EAAM;AAClB,MAAI,CAAC,KAAO,CAAC,EAAmB,EAAI,KAAK,CAAE;EAC3C,IAAM,IAAQ,OAAO,EAAI,SAAU,WAAW,EAAI,QAAQ,KAAA,GACpD,IACJ,OAAO,EAAI,aAAc,WACrB,EAAI,YACJ,MAAU,KAAA,IAER,KAAA,IADA,EAA2B;AAEnC,SAAO;GACL,MAAM,EAAI;GACV;GACA;GACA,WAAW,OAAO,EAAI,aAAc,WAAW,EAAI,YAAY,KAAA;GAChE;;AAEH,QAAO;;AAQT,SAAgB,EAAqB,GAA6B;AAC5D,QAAO,SAAW,OACtB,OAAO,cACL,IAAI,YAAY,GAAsB,EACpC,QAAQ,EACN,YAAY;EACV,MAAM,EAAQ;EACd,OAAO,EAAQ;EACf,WAAW,EAAQ;EACnB,UAAU,EAAQ,aAAa,EAAQ;EACvC,WAAW,EAAQ;EACpB,EACF,EACF,CAAC,CACH;;AAIH,IAAa,IAAb,cAAmC,MAAM;CACvC;CAEA,YAAY,GAAiB,GAAuB;AAGlD,EAFA,MAAM,EAAQ,EACd,KAAK,OAAO,iBACZ,KAAK,UAAU"}
@@ -1,22 +1,26 @@
1
- import { graphqlFetch as e } from "@burdenoff/fe-libs/shared/graphql";
1
+ import { SemQuotaError as e, announceQuotaRefusal as t, findQuotaRefusal as n } from "./quotaRefusal.js";
2
+ import { graphqlFetch as r } from "@burdenoff/fe-libs/shared/graphql";
2
3
  //#region src/semanticfed/api/semanticfedGraphql.ts
3
- function t() {
4
+ function i() {
4
5
  let e = globalThis;
5
6
  e.__graphqlFetchResponseCache?.clear(), e.__graphqlFetchPendingResponses?.clear(), e.__boffGraphQLResponseCache?.clear();
6
7
  }
7
- async function n(n, r = {}, i) {
8
- let a = await e({
8
+ async function a(a, o = {}, s) {
9
+ let c = await r({
9
10
  gateway: "workspace",
10
- baseUrl: i,
11
- query: n,
12
- variables: r,
11
+ baseUrl: s,
12
+ query: a,
13
+ variables: o,
13
14
  workspaceToken: !0
14
15
  });
15
- if (a.errors?.length) throw Error(a.errors[0]?.message ?? "GraphQL request failed");
16
- if (!a.data) throw Error("GraphQL response did not include data");
17
- return /^\s*mutation\b/.test(n) && t(), a.data;
16
+ if (c.errors?.length) {
17
+ let r = n(c.errors);
18
+ throw r ? (t(r), new e(c.errors[0]?.message ?? "Plan limit reached", r)) : Error(c.errors[0]?.message ?? "GraphQL request failed");
19
+ }
20
+ if (!c.data) throw Error("GraphQL response did not include data");
21
+ return /^\s*mutation\b/.test(a) && i(), c.data;
18
22
  }
19
23
  //#endregion
20
- export { n as semRequest };
24
+ export { a as semRequest };
21
25
 
22
26
  //# sourceMappingURL=semanticfedGraphql.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"semanticfedGraphql.js","names":[],"sources":["../../../src/semanticfed/api/semanticfedGraphql.ts"],"sourcesContent":["/**\n * SemanticFed GraphQL transport.\n *\n * Every call goes to the workspace gateway with a workspace-scoped token,\n * both supplied by the host shell (`graphqlFetch({ gateway: 'workspace',\n * workspaceToken: true })`). Operations are inline documents whose fields\n * match the `wspace-semanticfed-svc` subgraph schema exactly.\n */\nimport { graphqlFetch } from '@burdenoff/fe-libs/shared/graphql';\n\n/**\n * fe-libs `graphqlFetch` coalesces query responses in short-lived in-memory\n * caches. A read issued right after a write would otherwise return the\n * pre-mutation response, so every mutation clears those caches.\n */\ntype GraphqlReadCacheGlobals = {\n __graphqlFetchResponseCache?: { clear: () => void };\n __graphqlFetchPendingResponses?: { clear: () => void };\n __boffGraphQLResponseCache?: { clear: () => void };\n};\n\nexport function clearGraphqlReadCaches(): void {\n const g = globalThis as GraphqlReadCacheGlobals;\n g.__graphqlFetchResponseCache?.clear();\n g.__graphqlFetchPendingResponses?.clear();\n g.__boffGraphQLResponseCache?.clear();\n}\n\nexport async function semRequest<TData>(\n query: string,\n variables: Record<string, unknown> = {},\n baseUrl?: string\n): Promise<TData> {\n const response = await graphqlFetch<TData>({\n gateway: 'workspace',\n baseUrl,\n query,\n variables,\n workspaceToken: true,\n });\n\n if (response.errors?.length) {\n throw new Error(response.errors[0]?.message ?? 'GraphQL request failed');\n }\n if (!response.data) {\n throw new Error('GraphQL response did not include data');\n }\n if (/^\\s*mutation\\b/.test(query)) {\n clearGraphqlReadCaches();\n }\n return response.data;\n}\n"],"mappings":";;AAqBA,SAAgB,IAA+B;CAC7C,IAAM,IAAI;AAGV,CAFA,EAAE,6BAA6B,OAAO,EACtC,EAAE,gCAAgC,OAAO,EACzC,EAAE,4BAA4B,OAAO;;AAGvC,eAAsB,EACpB,GACA,IAAqC,EAAE,EACvC,GACgB;CAChB,IAAM,IAAW,MAAM,EAAoB;EACzC,SAAS;EACT;EACA;EACA;EACA,gBAAgB;EACjB,CAAC;AAEF,KAAI,EAAS,QAAQ,OACnB,OAAU,MAAM,EAAS,OAAO,IAAI,WAAW,yBAAyB;AAE1E,KAAI,CAAC,EAAS,KACZ,OAAU,MAAM,wCAAwC;AAK1D,QAHI,iBAAiB,KAAK,EAAM,IAC9B,GAAwB,EAEnB,EAAS"}
1
+ {"version":3,"file":"semanticfedGraphql.js","names":[],"sources":["../../../src/semanticfed/api/semanticfedGraphql.ts"],"sourcesContent":["/**\n * SemanticFed GraphQL transport.\n *\n * Every call goes to the workspace gateway with a workspace-scoped token,\n * both supplied by the host shell (`graphqlFetch({ gateway: 'workspace',\n * workspaceToken: true })`). Operations are inline documents whose fields\n * match the `wspace-semanticfed-svc` subgraph schema exactly.\n */\nimport { graphqlFetch } from '@burdenoff/fe-libs/shared/graphql';\n\nimport { announceQuotaRefusal, findQuotaRefusal, SemQuotaError } from './quotaRefusal';\n\n/**\n * fe-libs `graphqlFetch` coalesces query responses in short-lived in-memory\n * caches. A read issued right after a write would otherwise return the\n * pre-mutation response, so every mutation clears those caches.\n */\ntype GraphqlReadCacheGlobals = {\n __graphqlFetchResponseCache?: { clear: () => void };\n __graphqlFetchPendingResponses?: { clear: () => void };\n __boffGraphQLResponseCache?: { clear: () => void };\n};\n\nexport function clearGraphqlReadCaches(): void {\n const g = globalThis as GraphqlReadCacheGlobals;\n g.__graphqlFetchResponseCache?.clear();\n g.__graphqlFetchPendingResponses?.clear();\n g.__boffGraphQLResponseCache?.clear();\n}\n\nexport async function semRequest<TData>(\n query: string,\n variables: Record<string, unknown> = {},\n baseUrl?: string\n): Promise<TData> {\n const response = await graphqlFetch<TData>({\n gateway: 'workspace',\n baseUrl,\n query,\n variables,\n workspaceToken: true,\n });\n\n if (response.errors?.length) {\n // A plan-limit refusal (BOFF-3172) opens the shell's upgrade prompt and\n // throws a typed error, so callers can tell it apart from a failure.\n const refusal = findQuotaRefusal(response.errors);\n if (refusal) {\n announceQuotaRefusal(refusal);\n throw new SemQuotaError(response.errors[0]?.message ?? 'Plan limit reached', refusal);\n }\n throw new Error(response.errors[0]?.message ?? 'GraphQL request failed');\n }\n if (!response.data) {\n throw new Error('GraphQL response did not include data');\n }\n if (/^\\s*mutation\\b/.test(query)) {\n clearGraphqlReadCaches();\n }\n return response.data;\n}\n"],"mappings":";;;AAuBA,SAAgB,IAA+B;CAC7C,IAAM,IAAI;AAGV,CAFA,EAAE,6BAA6B,OAAO,EACtC,EAAE,gCAAgC,OAAO,EACzC,EAAE,4BAA4B,OAAO;;AAGvC,eAAsB,EACpB,GACA,IAAqC,EAAE,EACvC,GACgB;CAChB,IAAM,IAAW,MAAM,EAAoB;EACzC,SAAS;EACT;EACA;EACA;EACA,gBAAgB;EACjB,CAAC;AAEF,KAAI,EAAS,QAAQ,QAAQ;EAG3B,IAAM,IAAU,EAAiB,EAAS,OAAO;AAKjD,QAJI,KACF,EAAqB,EAAQ,EACvB,IAAI,EAAc,EAAS,OAAO,IAAI,WAAW,sBAAsB,EAAQ,IAE7E,MAAM,EAAS,OAAO,IAAI,WAAW,yBAAyB;;AAE1E,KAAI,CAAC,EAAS,KACZ,OAAU,MAAM,wCAAwC;AAK1D,QAHI,iBAAiB,KAAK,EAAM,IAC9B,GAAwB,EAEnB,EAAS"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@burdenoff/microfe-semanticfed",
3
- "version": "2026.1030.1",
3
+ "version": "2026.1031.1",
4
4
  "description": "Burdenoff SemanticFed Microfrontend",
5
5
  "type": "module",
6
6
  "files": [