@pylonsync/sdk 0.6.1 → 0.8.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.d.ts CHANGED
@@ -919,6 +919,27 @@ export type AuthConfig = {
919
919
  * management entirely in your own TypeScript functions.
920
920
  */
921
921
  disabled?: boolean;
922
+ /**
923
+ * Mirror org memberships from an upstream Pylon identity provider.
924
+ * On every login through `provider`, the IdP's `orgs` claim
925
+ * (`[{ id, name, slug?, role }]`) is reconciled against local Org
926
+ * rows keyed by `externalIdField`: orgs are created and joined,
927
+ * roles updated, and (with `removeMissing`) memberships absent from
928
+ * the claim removed. The org entity must declare `externalIdField`
929
+ * as `field.string().optional().unique()`.
930
+ */
931
+ federation?: {
932
+ /** OAuth provider id whose `orgs` claim is trusted, e.g. `"stack0"`. */
933
+ provider: string;
934
+ /** Field on the org entity holding the upstream org id. Default `"externalId"`. */
935
+ externalIdField?: string;
936
+ /** Drop mirrored memberships absent from the claim. Default `true`. */
937
+ removeMissing?: boolean;
938
+ /** Claim role → local role. Unknown roles fall back to `member`. */
939
+ roleMap?: Record<string, string>;
940
+ /** Refuse `POST /api/auth/orgs` with `403 ORG_FEDERATED`. Default `true`. */
941
+ disableLocalCreate?: boolean;
942
+ };
922
943
  };
923
944
  /**
924
945
  * Per-app trusted origins. Single declarative source for the three
@@ -1043,6 +1064,13 @@ export type ManifestAuthConfig = {
1043
1064
  member_entity: string;
1044
1065
  invite_entity: string;
1045
1066
  disabled: boolean;
1067
+ federation?: {
1068
+ provider: string;
1069
+ external_id_field: string;
1070
+ remove_missing: boolean;
1071
+ role_map?: Record<string, string>;
1072
+ disable_local_create: boolean;
1073
+ };
1046
1074
  };
1047
1075
  org_roles: string[];
1048
1076
  trusted_origins: string[];
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.6.1",
6
+ "version": "0.8.0",
7
7
  "type": "module",
8
8
  "main": "./src/index.ts",
9
9
  "types": "./dist/index.d.ts",
package/src/index.ts CHANGED
@@ -1747,6 +1747,27 @@ export type AuthConfig = {
1747
1747
  * management entirely in your own TypeScript functions.
1748
1748
  */
1749
1749
  disabled?: boolean;
1750
+ /**
1751
+ * Mirror org memberships from an upstream Pylon identity provider.
1752
+ * On every login through `provider`, the IdP's `orgs` claim
1753
+ * (`[{ id, name, slug?, role }]`) is reconciled against local Org
1754
+ * rows keyed by `externalIdField`: orgs are created and joined,
1755
+ * roles updated, and (with `removeMissing`) memberships absent from
1756
+ * the claim removed. The org entity must declare `externalIdField`
1757
+ * as `field.string().optional().unique()`.
1758
+ */
1759
+ federation?: {
1760
+ /** OAuth provider id whose `orgs` claim is trusted, e.g. `"stack0"`. */
1761
+ provider: string;
1762
+ /** Field on the org entity holding the upstream org id. Default `"externalId"`. */
1763
+ externalIdField?: string;
1764
+ /** Drop mirrored memberships absent from the claim. Default `true`. */
1765
+ removeMissing?: boolean;
1766
+ /** Claim role → local role. Unknown roles fall back to `member`. */
1767
+ roleMap?: Record<string, string>;
1768
+ /** Refuse `POST /api/auth/orgs` with `403 ORG_FEDERATED`. Default `true`. */
1769
+ disableLocalCreate?: boolean;
1770
+ };
1750
1771
  };
1751
1772
  /**
1752
1773
  * Per-app trusted origins. Single declarative source for the three
@@ -1900,6 +1921,13 @@ export type ManifestAuthConfig = {
1900
1921
  member_entity: string;
1901
1922
  invite_entity: string;
1902
1923
  disabled: boolean;
1924
+ federation?: {
1925
+ provider: string;
1926
+ external_id_field: string;
1927
+ remove_missing: boolean;
1928
+ role_map?: Record<string, string>;
1929
+ disable_local_create: boolean;
1930
+ };
1903
1931
  };
1904
1932
  org_roles: string[];
1905
1933
  trusted_origins: string[];
@@ -1957,6 +1985,19 @@ export function auth(cfg: AuthConfig = {}): ManifestAuthConfig {
1957
1985
  member_entity: cfg.org?.memberEntity ?? "OrgMember",
1958
1986
  invite_entity: cfg.org?.inviteEntity ?? "OrgInvite",
1959
1987
  disabled: cfg.org?.disabled ?? false,
1988
+ ...(cfg.org?.federation
1989
+ ? {
1990
+ federation: {
1991
+ provider: cfg.org.federation.provider,
1992
+ external_id_field: cfg.org.federation.externalIdField ?? "externalId",
1993
+ remove_missing: cfg.org.federation.removeMissing ?? true,
1994
+ ...(cfg.org.federation.roleMap && Object.keys(cfg.org.federation.roleMap).length > 0
1995
+ ? { role_map: cfg.org.federation.roleMap }
1996
+ : {}),
1997
+ disable_local_create: cfg.org.federation.disableLocalCreate ?? true,
1998
+ },
1999
+ }
2000
+ : {}),
1960
2001
  },
1961
2002
  org_roles: validateOrgRoles(cfg.orgRoles ?? []),
1962
2003
  trusted_origins: cfg.trustedOrigins ?? [],