@workos-inc/widgets 1.16.1 → 1.17.0-next.1787251821623

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.
@@ -1,8 +1,8 @@
1
1
  import { AuthToken } from './api/api-provider.js';
2
2
  export { PipesError, PipesErrorProps, PipesLoading, PipesLoadingProps } from './lib/pipes.js';
3
+ import { DataIntegration } from './api/endpoint.js';
3
4
  import { WidgetRootDomProps } from './lib/utils.js';
4
5
  import 'react';
5
- import './api/endpoint.js';
6
6
  import '@tanstack/react-query';
7
7
  import './api/widgets-api-client.js';
8
8
  import './lib/elements.js';
@@ -17,9 +17,56 @@ import '@radix-ui/themes/components/dropdown-menu';
17
17
  import './select-KR89Qnvm.js';
18
18
  import '@radix-ui/themes/components/select';
19
19
 
20
+ /** An auth method a provider advertises (defaults to `oauth` when unset). */
21
+ type PipesAuthMethod = NonNullable<DataIntegration["authMethods"]>[number];
22
+ /**
23
+ * Serializable criteria for narrowing which integrations render. All provided
24
+ * criteria are ANDed; an absent criterion is ignored. Safe to pass from a
25
+ * Server Component, since props cross the server/client boundary.
26
+ */
27
+ interface PipesFilterCriteria {
28
+ /** Render only integrations whose `slug` is in this list. */
29
+ slugs?: string[];
30
+ /** Render only integrations whose `integrationType` is in this list. */
31
+ integrationTypes?: string[];
32
+ /** Render only integrations that advertise at least one of these methods. */
33
+ authMethods?: PipesAuthMethod[];
34
+ }
35
+ /**
36
+ * Narrows which enabled integrations the widget renders. Either a predicate
37
+ * (use from a Client Component host) or serializable criteria (use from a
38
+ * Server Component host, where props must cross the server/client boundary).
39
+ */
40
+ type PipesFilter = PipesFilterCriteria | ((integration: DataIntegration) => boolean);
20
41
  interface PipesProps extends WidgetRootDomProps {
21
42
  authToken: AuthToken;
43
+ /**
44
+ * Optional filter that narrows which enabled integrations the widget
45
+ * renders. The widget still fetches the full set of integrations the user's
46
+ * organization has enabled (plus any the user is still connected to so they
47
+ * can disconnect); this prop only controls which of those rows are shown.
48
+ *
49
+ * Accepts either form:
50
+ *
51
+ * - **Serializable criteria** (`{ slugs, integrationTypes, authMethods }`),
52
+ * ANDed together. This is the form to use when `<Pipes>` is embedded in a
53
+ * Server Component (the documented token-minting pattern), because props
54
+ * must be serializable across the server/client boundary and plain objects
55
+ * survive it. e.g. `filter={{ slugs: ["google-drive"] }}`.
56
+ *
57
+ * - **A predicate** `((integration) => boolean)` for arbitrary filtering by any
58
+ * field on the integration (`authMethods`, `integrationType`,
59
+ * `installation.state`, etc.). A function is **not serializable across the
60
+ * server/client boundary**: the predicate must be defined inside client
61
+ * code and must never be passed in from a Server Component. Concretely, a
62
+ * host using the App Router server-component pattern that needs a predicate
63
+ * must author its own `"use client"` wrapper that *owns* the predicate and
64
+ * receives only serializable props (e.g. `authToken`) from the server page.
65
+ *
66
+ * Undefined renders every enabled integration (the default).
67
+ */
68
+ filter?: PipesFilter;
22
69
  }
23
70
  declare const Pipes: React.FC<PipesProps>;
24
71
 
25
- export { Pipes, type PipesProps };
72
+ export { Pipes, type PipesAuthMethod, type PipesFilter, type PipesFilterCriteria, type PipesProps };
@@ -20,6 +20,21 @@ const Pipes = ({ authToken, ...domProps }) => {
20
20
  }
21
21
  );
22
22
  };
23
+ function matchesPipesFilterCriteria(integration, criteria) {
24
+ if (criteria.slugs && !criteria.slugs.includes(integration.slug)) {
25
+ return false;
26
+ }
27
+ if (criteria.integrationTypes && !criteria.integrationTypes.includes(integration.integrationType)) {
28
+ return false;
29
+ }
30
+ if (criteria.authMethods) {
31
+ const methods = integration.authMethods ?? ["oauth"];
32
+ if (!criteria.authMethods.some((method) => methods.includes(method))) {
33
+ return false;
34
+ }
35
+ }
36
+ return true;
37
+ }
23
38
  const PipesImpl = (props) => {
24
39
  const isHydrated = useIsHydrated();
25
40
  const integrations = useMyDataIntegrations();
@@ -30,7 +45,12 @@ const PipesImpl = (props) => {
30
45
  return /* @__PURE__ */ jsx(PipesError, { error: integrations.error, ...props });
31
46
  }
32
47
  if (integrations.isSuccess) {
33
- return /* @__PURE__ */ jsx(PipesPresentational, { integrations: integrations.data.data, ...props });
48
+ const all = integrations.data.data;
49
+ const { filter } = props;
50
+ const visible = filter ? typeof filter === "function" ? all.filter(filter) : all.filter(
51
+ (integration) => matchesPipesFilterCriteria(integration, filter)
52
+ ) : all;
53
+ return /* @__PURE__ */ jsx(PipesPresentational, { integrations: visible, ...props });
34
54
  }
35
55
  return /* @__PURE__ */ jsx(PipesError, { error: integrations.error, ...props });
36
56
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/pipes.client.tsx"],"sourcesContent":["\"use client\";\nimport { ApiProvider, AuthToken } from \"./api/api-provider.js\";\nimport { useWorkOsApiUrl } from \"./lib/widgets-context.js\";\nimport {\n Pipes as PipesPresentational,\n PipesError,\n PipesLoading,\n} from \"./lib/pipes.js\";\nimport type { PipesErrorProps, PipesLoadingProps } from \"./lib/pipes.js\";\nimport { useMyDataIntegrations } from \"./api/endpoint.js\";\nimport { useIsHydrated } from \"./lib/use-is-hydrated.js\";\nimport { ErrorBoundary } from \"./lib/error-boundary.js\";\nimport { WidgetRootDomProps } from \"./lib/utils.js\";\n\ninterface PipesProps extends WidgetRootDomProps {\n authToken: AuthToken;\n}\n\nconst Pipes: React.FC<PipesProps> = ({ authToken, ...domProps }) => {\n const baseUrl = useWorkOsApiUrl();\n\n return (\n <ErrorBoundary\n fallbackRender={({ error }) => <PipesError {...domProps} error={error} />}\n >\n <ApiProvider widgetType=\"pipes\" authToken={authToken} baseUrl={baseUrl}>\n <PipesImpl {...domProps} />\n </ApiProvider>\n </ErrorBoundary>\n );\n};\n\nconst PipesImpl = (props: Omit<PipesProps, \"authToken\">) => {\n const isHydrated = useIsHydrated();\n const integrations = useMyDataIntegrations();\n\n if (!isHydrated || integrations.isLoading) {\n return <PipesLoading count={6} {...props} />;\n }\n\n if (integrations.isError) {\n return <PipesError error={integrations.error} {...props} />;\n }\n\n if (integrations.isSuccess) {\n return (\n <PipesPresentational integrations={integrations.data.data} {...props} />\n );\n }\n\n return <PipesError error={integrations.error} {...props} />;\n};\n\nexport type { PipesProps, PipesLoadingProps, PipesErrorProps };\nexport { Pipes, PipesLoading, PipesError };\n"],"mappings":";AAuBqC;AAtBrC,SAAS,mBAA8B;AACvC,SAAS,uBAAuB;AAChC;AAAA,EACE,SAAS;AAAA,EACT;AAAA,EACA;AAAA,OACK;AAEP,SAAS,6BAA6B;AACtC,SAAS,qBAAqB;AAC9B,SAAS,qBAAqB;AAO9B,MAAM,QAA8B,CAAC,EAAE,WAAW,GAAG,SAAS,MAAM;AAClE,QAAM,UAAU,gBAAgB;AAEhC,SACE;AAAA,IAAC;AAAA;AAAA,MACC,gBAAgB,CAAC,EAAE,MAAM,MAAM,oBAAC,cAAY,GAAG,UAAU,OAAc;AAAA,MAEvE,8BAAC,eAAY,YAAW,SAAQ,WAAsB,SACpD,8BAAC,aAAW,GAAG,UAAU,GAC3B;AAAA;AAAA,EACF;AAEJ;AAEA,MAAM,YAAY,CAAC,UAAyC;AAC1D,QAAM,aAAa,cAAc;AACjC,QAAM,eAAe,sBAAsB;AAE3C,MAAI,CAAC,cAAc,aAAa,WAAW;AACzC,WAAO,oBAAC,gBAAa,OAAO,GAAI,GAAG,OAAO;AAAA,EAC5C;AAEA,MAAI,aAAa,SAAS;AACxB,WAAO,oBAAC,cAAW,OAAO,aAAa,OAAQ,GAAG,OAAO;AAAA,EAC3D;AAEA,MAAI,aAAa,WAAW;AAC1B,WACE,oBAAC,uBAAoB,cAAc,aAAa,KAAK,MAAO,GAAG,OAAO;AAAA,EAE1E;AAEA,SAAO,oBAAC,cAAW,OAAO,aAAa,OAAQ,GAAG,OAAO;AAC3D;","names":[]}
1
+ {"version":3,"sources":["../../src/pipes.client.tsx"],"sourcesContent":["\"use client\";\nimport { ApiProvider, AuthToken } from \"./api/api-provider.js\";\nimport { useWorkOsApiUrl } from \"./lib/widgets-context.js\";\nimport {\n Pipes as PipesPresentational,\n PipesError,\n PipesLoading,\n} from \"./lib/pipes.js\";\nimport type { PipesErrorProps, PipesLoadingProps } from \"./lib/pipes.js\";\nimport { DataIntegration, useMyDataIntegrations } from \"./api/endpoint.js\";\nimport { useIsHydrated } from \"./lib/use-is-hydrated.js\";\nimport { ErrorBoundary } from \"./lib/error-boundary.js\";\nimport { WidgetRootDomProps } from \"./lib/utils.js\";\n\n/** An auth method a provider advertises (defaults to `oauth` when unset). */\ntype PipesAuthMethod = NonNullable<DataIntegration[\"authMethods\"]>[number];\n\n/**\n * Serializable criteria for narrowing which integrations render. All provided\n * criteria are ANDed; an absent criterion is ignored. Safe to pass from a\n * Server Component, since props cross the server/client boundary.\n */\ninterface PipesFilterCriteria {\n /** Render only integrations whose `slug` is in this list. */\n slugs?: string[];\n /** Render only integrations whose `integrationType` is in this list. */\n integrationTypes?: string[];\n /** Render only integrations that advertise at least one of these methods. */\n authMethods?: PipesAuthMethod[];\n}\n\n/**\n * Narrows which enabled integrations the widget renders. Either a predicate\n * (use from a Client Component host) or serializable criteria (use from a\n * Server Component host, where props must cross the server/client boundary).\n */\ntype PipesFilter =\n | PipesFilterCriteria\n | ((integration: DataIntegration) => boolean);\n\ninterface PipesProps extends WidgetRootDomProps {\n authToken: AuthToken;\n /**\n * Optional filter that narrows which enabled integrations the widget\n * renders. The widget still fetches the full set of integrations the user's\n * organization has enabled (plus any the user is still connected to so they\n * can disconnect); this prop only controls which of those rows are shown.\n *\n * Accepts either form:\n *\n * - **Serializable criteria** (`{ slugs, integrationTypes, authMethods }`),\n * ANDed together. This is the form to use when `<Pipes>` is embedded in a\n * Server Component (the documented token-minting pattern), because props\n * must be serializable across the server/client boundary and plain objects\n * survive it. e.g. `filter={{ slugs: [\"google-drive\"] }}`.\n *\n * - **A predicate** `((integration) => boolean)` for arbitrary filtering by any\n * field on the integration (`authMethods`, `integrationType`,\n * `installation.state`, etc.). A function is **not serializable across the\n * server/client boundary**: the predicate must be defined inside client\n * code and must never be passed in from a Server Component. Concretely, a\n * host using the App Router server-component pattern that needs a predicate\n * must author its own `\"use client\"` wrapper that *owns* the predicate and\n * receives only serializable props (e.g. `authToken`) from the server page.\n *\n * Undefined renders every enabled integration (the default).\n */\n filter?: PipesFilter;\n}\n\nconst Pipes: React.FC<PipesProps> = ({ authToken, ...domProps }) => {\n const baseUrl = useWorkOsApiUrl();\n\n return (\n <ErrorBoundary\n fallbackRender={({ error }) => <PipesError {...domProps} error={error} />}\n >\n <ApiProvider widgetType=\"pipes\" authToken={authToken} baseUrl={baseUrl}>\n <PipesImpl {...domProps} />\n </ApiProvider>\n </ErrorBoundary>\n );\n};\n\n/**\n * Evaluates serializable {@link PipesFilterCriteria} against an integration.\n * Provided criteria are ANDed; an integration with no declared `authMethods`\n * is treated as `oauth` (matching the widget's connect-method defaults).\n */\nfunction matchesPipesFilterCriteria(\n integration: DataIntegration,\n criteria: PipesFilterCriteria,\n): boolean {\n if (criteria.slugs && !criteria.slugs.includes(integration.slug)) {\n return false;\n }\n if (\n criteria.integrationTypes &&\n !criteria.integrationTypes.includes(integration.integrationType)\n ) {\n return false;\n }\n if (criteria.authMethods) {\n const methods = integration.authMethods ?? [\"oauth\"];\n if (!criteria.authMethods.some((method) => methods.includes(method))) {\n return false;\n }\n }\n return true;\n}\n\nconst PipesImpl = (props: Omit<PipesProps, \"authToken\">) => {\n const isHydrated = useIsHydrated();\n const integrations = useMyDataIntegrations();\n\n if (!isHydrated || integrations.isLoading) {\n return <PipesLoading count={6} {...props} />;\n }\n\n if (integrations.isError) {\n return <PipesError error={integrations.error} {...props} />;\n }\n\n if (integrations.isSuccess) {\n const all = integrations.data.data;\n const { filter } = props;\n const visible = filter\n ? typeof filter === \"function\"\n ? all.filter(filter)\n : all.filter((integration) =>\n matchesPipesFilterCriteria(integration, filter),\n )\n : all;\n\n return <PipesPresentational integrations={visible} {...props} />;\n }\n\n return <PipesError error={integrations.error} {...props} />;\n};\n\nexport type {\n PipesProps,\n PipesFilter,\n PipesFilterCriteria,\n PipesAuthMethod,\n PipesLoadingProps,\n PipesErrorProps,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AAa,KAAK;AAC9B,UAAM,EAAE,OAAO,IAAI;AACnB,UAAM,UAAU,SACZ,OAAO,WAAW,aAChB,IAAI,OAAO,MAAM,IACjB,IAAI;AAAA,MAAO,CAAC,gBACV,2BAA2B,aAAa,MAAM;AAAA,IAChD,IACF;AAEJ,WAAO,oBAAC,uBAAoB,cAAc,SAAU,GAAG,OAAO;AAAA,EAChE;AAEA,SAAO,oBAAC,cAAW,OAAO,aAAa,OAAQ,GAAG,OAAO;AAC3D;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workos-inc/widgets",
3
- "version": "1.16.1",
3
+ "version": "1.17.0-next.1787251821623",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",