@aglyn/shared-util-tools 1.0.0-beta.236 → 1.0.0-beta.238

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aglyn/shared-util-tools",
3
- "version": "1.0.0-beta.236",
3
+ "version": "1.0.0-beta.238",
4
4
  "license": "Apache-2.0",
5
5
  "homepage": "https://aglyn.com",
6
6
  "repository": {
@@ -25,7 +25,7 @@
25
25
  "./package.json": "./package.json"
26
26
  },
27
27
  "dependencies": {
28
- "@aglyn/shared-data-types": "1.0.0-beta.236",
28
+ "@aglyn/shared-data-types": "1.0.0-beta.238",
29
29
  "@swc/helpers": "0.5.23",
30
30
  "lodash-es": "^4.18.1",
31
31
  "php-serialize": "^5.1.3"
package/src/index.d.ts CHANGED
@@ -32,6 +32,7 @@ export * from './lib/noop';
32
32
  export * from './lib/normalized';
33
33
  export * from './lib/numeronym';
34
34
  export * from './lib/split-display-name';
35
+ export * from './lib/account-identity';
35
36
  export * from './lib/trim';
36
37
  export * from './lib/truthy';
37
38
  export * from './lib/array/array-copy-deep';
package/src/index.js CHANGED
@@ -31,6 +31,7 @@ export * from "./lib/noop.js";
31
31
  export * from "./lib/normalized.js";
32
32
  export * from "./lib/numeronym.js";
33
33
  export * from "./lib/split-display-name.js";
34
+ export * from "./lib/account-identity.js";
34
35
  export * from "./lib/trim.js";
35
36
  export * from "./lib/truthy.js";
36
37
  // ARRAY
package/src/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../libs/shared/util/tools/src/index.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport * from './lib/str'\nexport * from './lib/apply-mixins'\nexport * from './lib/copy'\nexport * from './lib/copy-shallow'\nexport * from './lib/create-chained-function'\nexport * from './lib/crud'\nexport * from './lib/css'\nexport * from './lib/falsy'\nexport * from './lib/get-display-name'\nexport * from './lib/get-property'\nexport * from './lib/get-static-field'\nexport * from './lib/interop-default'\nexport * from './lib/length'\nexport * from './lib/no-side-effects'\nexport * from './lib/noop'\nexport * from './lib/normalized'\nexport * from './lib/numeronym'\nexport * from './lib/split-display-name'\nexport * from './lib/trim'\nexport * from './lib/truthy'\n\n// ARRAY\n\nexport * from './lib/array/array-copy-deep'\nexport * from './lib/array/array-copy-shallow'\nexport * from './lib/array/array-from'\nexport * from './lib/array/array-from-length'\nexport * from './lib/array/array-move-at-index'\nexport * from './lib/array/array-of-entries-to-object'\nexport * from './lib/array/array-overrides'\nexport * from './lib/array/array-push-at-index'\nexport * from './lib/array/array-remove-at-index'\nexport * from './lib/array/array-remove-item'\nexport * from './lib/array/array-safe'\nexport * from './lib/array/array-sort-by'\nexport * from './lib/array/array-sort-by-deep-property'\nexport * from './lib/array/array-update'\nexport * from './lib/array/array-update-at-index'\n\n// BITWISE\n\nexport * from './lib/bitwise/bitwise-has-all-attributes'\nexport * from './lib/bitwise/bitwise-has-attribute'\nexport * from './lib/bitwise/bitwise-has-only-attributes'\n\n// GUARDS\n\nexport * from './lib/guards'\n\n// NUMBER\n\nexport * from './lib/number/to-num'\nexport * from './lib/number/number-to-hexadecimal'\nexport * from './lib/number/number-from-hexadecimal'\n\n// OBJECT\n\nexport * from './lib/object/object-clone'\nexport * from './lib/object/object-clone-deep'\nexport * from './lib/object/object-delete-property'\nexport * from './lib/object/object-get-deep-property'\nexport * from './lib/object/object-get-keys-and-symbol-properties'\nexport * from './lib/object/object-remap'\nexport * from './lib/object/object-safe'\nexport * from './lib/object/object-set-deep-property'\nexport * from './lib/object/object-update'\n\n// OPERATOR\n\nexport * from './lib/operator'\n\n// SERIALIZE\n\nexport * from './lib/serialize/base64-isomorphic-decode'\nexport * from './lib/serialize/base64-isomorphic-encode'\n// The three php-serial wrappers are NOT re-exported (AGL-2682), the same\n// removal AGL-2486 made in `shared-util-vendor` for `platform-identification`\n// and for the same reason: NOTHING in the repo imports them — not an app, not\n// a plugin, not a tool — so the only thing this line did was put\n// `php-serialize`'s parser in front of every file that takes anything at all\n// from this index, which on the tenant is every published page. Still\n// importable as `@aglyn/shared-util-tools/serialize/php-serial-<name>`.\nexport * from './lib/serialize/json-deserialize'\nexport * from './lib/serialize/json-serialize'\n"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,cAAc,eAAW;AACzB,cAAc,wBAAoB;AAClC,cAAc,gBAAY;AAC1B,cAAc,wBAAoB;AAClC,cAAc,mCAA+B;AAC7C,cAAc,gBAAY;AAC1B,cAAc,eAAW;AACzB,cAAc,iBAAa;AAC3B,cAAc,4BAAwB;AACtC,cAAc,wBAAoB;AAClC,cAAc,4BAAwB;AACtC,cAAc,2BAAuB;AACrC,cAAc,kBAAc;AAC5B,cAAc,2BAAuB;AACrC,cAAc,gBAAY;AAC1B,cAAc,sBAAkB;AAChC,cAAc,qBAAiB;AAC/B,cAAc,8BAA0B;AACxC,cAAc,gBAAY;AAC1B,cAAc,kBAAc;AAE5B,QAAQ;AAER,cAAc,iCAA6B;AAC3C,cAAc,oCAAgC;AAC9C,cAAc,4BAAwB;AACtC,cAAc,mCAA+B;AAC7C,cAAc,qCAAiC;AAC/C,cAAc,4CAAwC;AACtD,cAAc,iCAA6B;AAC3C,cAAc,qCAAiC;AAC/C,cAAc,uCAAmC;AACjD,cAAc,mCAA+B;AAC7C,cAAc,4BAAwB;AACtC,cAAc,+BAA2B;AACzC,cAAc,6CAAyC;AACvD,cAAc,8BAA0B;AACxC,cAAc,uCAAmC;AAEjD,UAAU;AAEV,cAAc,8CAA0C;AACxD,cAAc,yCAAqC;AACnD,cAAc,+CAA2C;AAEzD,SAAS;AAET,cAAc,wBAAc;AAE5B,SAAS;AAET,cAAc,yBAAqB;AACnC,cAAc,wCAAoC;AAClD,cAAc,0CAAsC;AAEpD,SAAS;AAET,cAAc,+BAA2B;AACzC,cAAc,oCAAgC;AAC9C,cAAc,yCAAqC;AACnD,cAAc,2CAAuC;AACrD,cAAc,wDAAoD;AAClE,cAAc,+BAA2B;AACzC,cAAc,8BAA0B;AACxC,cAAc,2CAAuC;AACrD,cAAc,gCAA4B;AAE1C,WAAW;AAEX,cAAc,0BAAgB;AAE9B,YAAY;AAEZ,cAAc,8CAA0C;AACxD,cAAc,8CAA0C;AACxD,yEAAyE;AACzE,8EAA8E;AAC9E,8EAA8E;AAC9E,iEAAiE;AACjE,6EAA6E;AAC7E,sEAAsE;AACtE,wEAAwE;AACxE,cAAc,sCAAkC;AAChD,cAAc,oCAAgC"}
1
+ {"version":3,"sources":["../../../../../../libs/shared/util/tools/src/index.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport * from './lib/str'\nexport * from './lib/apply-mixins'\nexport * from './lib/copy'\nexport * from './lib/copy-shallow'\nexport * from './lib/create-chained-function'\nexport * from './lib/crud'\nexport * from './lib/css'\nexport * from './lib/falsy'\nexport * from './lib/get-display-name'\nexport * from './lib/get-property'\nexport * from './lib/get-static-field'\nexport * from './lib/interop-default'\nexport * from './lib/length'\nexport * from './lib/no-side-effects'\nexport * from './lib/noop'\nexport * from './lib/normalized'\nexport * from './lib/numeronym'\nexport * from './lib/split-display-name'\nexport * from './lib/account-identity'\nexport * from './lib/trim'\nexport * from './lib/truthy'\n\n// ARRAY\n\nexport * from './lib/array/array-copy-deep'\nexport * from './lib/array/array-copy-shallow'\nexport * from './lib/array/array-from'\nexport * from './lib/array/array-from-length'\nexport * from './lib/array/array-move-at-index'\nexport * from './lib/array/array-of-entries-to-object'\nexport * from './lib/array/array-overrides'\nexport * from './lib/array/array-push-at-index'\nexport * from './lib/array/array-remove-at-index'\nexport * from './lib/array/array-remove-item'\nexport * from './lib/array/array-safe'\nexport * from './lib/array/array-sort-by'\nexport * from './lib/array/array-sort-by-deep-property'\nexport * from './lib/array/array-update'\nexport * from './lib/array/array-update-at-index'\n\n// BITWISE\n\nexport * from './lib/bitwise/bitwise-has-all-attributes'\nexport * from './lib/bitwise/bitwise-has-attribute'\nexport * from './lib/bitwise/bitwise-has-only-attributes'\n\n// GUARDS\n\nexport * from './lib/guards'\n\n// NUMBER\n\nexport * from './lib/number/to-num'\nexport * from './lib/number/number-to-hexadecimal'\nexport * from './lib/number/number-from-hexadecimal'\n\n// OBJECT\n\nexport * from './lib/object/object-clone'\nexport * from './lib/object/object-clone-deep'\nexport * from './lib/object/object-delete-property'\nexport * from './lib/object/object-get-deep-property'\nexport * from './lib/object/object-get-keys-and-symbol-properties'\nexport * from './lib/object/object-remap'\nexport * from './lib/object/object-safe'\nexport * from './lib/object/object-set-deep-property'\nexport * from './lib/object/object-update'\n\n// OPERATOR\n\nexport * from './lib/operator'\n\n// SERIALIZE\n\nexport * from './lib/serialize/base64-isomorphic-decode'\nexport * from './lib/serialize/base64-isomorphic-encode'\n// The three php-serial wrappers are NOT re-exported (AGL-2682), the same\n// removal AGL-2486 made in `shared-util-vendor` for `platform-identification`\n// and for the same reason: NOTHING in the repo imports them — not an app, not\n// a plugin, not a tool — so the only thing this line did was put\n// `php-serialize`'s parser in front of every file that takes anything at all\n// from this index, which on the tenant is every published page. Still\n// importable as `@aglyn/shared-util-tools/serialize/php-serial-<name>`.\nexport * from './lib/serialize/json-deserialize'\nexport * from './lib/serialize/json-serialize'\n"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,cAAc,eAAW;AACzB,cAAc,wBAAoB;AAClC,cAAc,gBAAY;AAC1B,cAAc,wBAAoB;AAClC,cAAc,mCAA+B;AAC7C,cAAc,gBAAY;AAC1B,cAAc,eAAW;AACzB,cAAc,iBAAa;AAC3B,cAAc,4BAAwB;AACtC,cAAc,wBAAoB;AAClC,cAAc,4BAAwB;AACtC,cAAc,2BAAuB;AACrC,cAAc,kBAAc;AAC5B,cAAc,2BAAuB;AACrC,cAAc,gBAAY;AAC1B,cAAc,sBAAkB;AAChC,cAAc,qBAAiB;AAC/B,cAAc,8BAA0B;AACxC,cAAc,4BAAwB;AACtC,cAAc,gBAAY;AAC1B,cAAc,kBAAc;AAE5B,QAAQ;AAER,cAAc,iCAA6B;AAC3C,cAAc,oCAAgC;AAC9C,cAAc,4BAAwB;AACtC,cAAc,mCAA+B;AAC7C,cAAc,qCAAiC;AAC/C,cAAc,4CAAwC;AACtD,cAAc,iCAA6B;AAC3C,cAAc,qCAAiC;AAC/C,cAAc,uCAAmC;AACjD,cAAc,mCAA+B;AAC7C,cAAc,4BAAwB;AACtC,cAAc,+BAA2B;AACzC,cAAc,6CAAyC;AACvD,cAAc,8BAA0B;AACxC,cAAc,uCAAmC;AAEjD,UAAU;AAEV,cAAc,8CAA0C;AACxD,cAAc,yCAAqC;AACnD,cAAc,+CAA2C;AAEzD,SAAS;AAET,cAAc,wBAAc;AAE5B,SAAS;AAET,cAAc,yBAAqB;AACnC,cAAc,wCAAoC;AAClD,cAAc,0CAAsC;AAEpD,SAAS;AAET,cAAc,+BAA2B;AACzC,cAAc,oCAAgC;AAC9C,cAAc,yCAAqC;AACnD,cAAc,2CAAuC;AACrD,cAAc,wDAAoD;AAClE,cAAc,+BAA2B;AACzC,cAAc,8BAA0B;AACxC,cAAc,2CAAuC;AACrD,cAAc,gCAA4B;AAE1C,WAAW;AAEX,cAAc,0BAAgB;AAE9B,YAAY;AAEZ,cAAc,8CAA0C;AACxD,cAAc,8CAA0C;AACxD,yEAAyE;AACzE,8EAA8E;AAC9E,8EAA8E;AAC9E,iEAAiE;AACjE,6EAA6E;AAC7E,sEAAsE;AACtE,wEAAwE;AACxE,cAAc,sCAAkC;AAChD,cAAc,oCAAgC"}
@@ -0,0 +1,121 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ /**
18
+ * ONE ANSWER TO "WHAT IS THIS ACCOUNT CALLED, AND WHAT DOES IT LOOK LIKE"
19
+ * (AGL-3721).
20
+ *
21
+ * The defect this closes: an SSO account's Firebase Auth record carries no
22
+ * `displayName` and no `photoURL` — GCIP leaves a SAML assertion's mapped
23
+ * attributes under `firebase.sign_in_attributes` on the token, and the
24
+ * provider entry is as blank as the record. The account menu never noticed,
25
+ * because it reads the person's own profile document (`users/{uid}`), which
26
+ * the sign-in seed fills from the IdP. The staff Users list and the staff
27
+ * user page read the Auth record alone, so the same person showed a photo
28
+ * and a name in the app bar and a grey initial and "—" on every staff
29
+ * surface. Several surfaces, several precedences, one person.
30
+ *
31
+ * Pure, no Firebase, no React — every surface that shows ANOTHER account's
32
+ * identity (staff list, staff user page, org rosters, the forum) hands this
33
+ * whatever sources it can legitimately read, and gets the same answer.
34
+ *
35
+ * ## The order
36
+ *
37
+ * 1. The Auth record — what the account itself, or staff, last set.
38
+ * 2. The profile document `users/{uid}` — what Manage Account edits and what
39
+ * the sign-in seed fills from the IdP (`firstName`/`lastName`, and
40
+ * `photoUrl` with that document's lowercase spelling).
41
+ * 3. The Auth record's `providerData` entries — Google keeps its avatar
42
+ * there when the top-level field was never mirrored.
43
+ * 4. Whatever the IdP sent at sign-in (SAML attributes / OIDC claims), as
44
+ * captured on the org roster row or resolved off a decoded token.
45
+ *
46
+ * A blank value never wins over a populated one further down: each field is
47
+ * resolved independently, so an account with an Auth name and only a profile
48
+ * photo gets both.
49
+ */
50
+ export type AccountIdentitySource = 'auth' | 'profile' | 'provider' | 'idp';
51
+ export interface AccountIdentityAuthSource {
52
+ displayName?: string | null;
53
+ photoURL?: string | null;
54
+ providerData?: ReadonlyArray<{
55
+ displayName?: string | null;
56
+ photoURL?: string | null;
57
+ } | null | undefined> | null;
58
+ }
59
+ export interface AccountIdentityProfileSource {
60
+ firstName?: unknown;
61
+ lastName?: unknown;
62
+ /** Legacy single-string name, read only when first/last are both blank. */
63
+ displayName?: unknown;
64
+ /** `users/{uid}` spells it `photoUrl`, not the roster's `photoURL`. */
65
+ photoUrl?: unknown;
66
+ }
67
+ export interface AccountIdentityIdpSource {
68
+ displayName?: string | null;
69
+ /** Accepts either spelling, so a roster row can be passed as-is. */
70
+ photoUrl?: string | null;
71
+ photoURL?: string | null;
72
+ }
73
+ export interface AccountIdentitySources {
74
+ auth?: AccountIdentityAuthSource | null;
75
+ profile?: AccountIdentityProfileSource | null;
76
+ idp?: AccountIdentityIdpSource | null;
77
+ /** Used only for `label` — an address is not a name. */
78
+ email?: string | null;
79
+ }
80
+ export interface ResolvedAccountIdentity {
81
+ /** The person's name, or null when no source holds one. */
82
+ displayName: string | null;
83
+ /** The avatar URL, or null — callers draw initials. */
84
+ photoUrl: string | null;
85
+ /** What to print when there is no name: the name, else the email. */
86
+ label: string | null;
87
+ displayNameSource: AccountIdentitySource | null;
88
+ photoUrlSource: AccountIdentitySource | null;
89
+ }
90
+ /**
91
+ * A photo value safe to put in an `<img src>`: `https:`/`http:` URLs and
92
+ * scheme-less paths (the media CDN stores `/media/...` paths) pass;
93
+ * `javascript:`, `data:` and every other scheme do not. These values reach
94
+ * other people's browsers, so a hostile one must not become stored script.
95
+ */
96
+ export declare function sanitizeAccountPhotoUrl(value: unknown): string;
97
+ export declare function resolveAccountIdentity(sources: AccountIdentitySources): ResolvedAccountIdentity;
98
+ /**
99
+ * Which of an Auth record's identity fields are blank and could be filled
100
+ * from what the IdP sent, without overwriting anything (AGL-3721).
101
+ *
102
+ * Absent-only by construction: a field the record already holds is never in
103
+ * the result, so a name or photo the person (or staff) set always survives.
104
+ * `photoErased` is the profile's `photoUrlErasedAt` marker — a person who
105
+ * removed their avatar has asked not to have the directory's put back.
106
+ */
107
+ export declare function authIdentityFillFromIdp(input: {
108
+ auth: {
109
+ displayName?: string | null;
110
+ photoURL?: string | null;
111
+ } | null | undefined;
112
+ idp: {
113
+ displayName?: string | null;
114
+ photoUrl?: string | null;
115
+ } | null | undefined;
116
+ photoErased?: boolean;
117
+ }): {
118
+ displayName?: string;
119
+ photoURL?: string;
120
+ };
121
+ export default resolveAccountIdentity;
@@ -0,0 +1,146 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */ /**
17
+ * ONE ANSWER TO "WHAT IS THIS ACCOUNT CALLED, AND WHAT DOES IT LOOK LIKE"
18
+ * (AGL-3721).
19
+ *
20
+ * The defect this closes: an SSO account's Firebase Auth record carries no
21
+ * `displayName` and no `photoURL` — GCIP leaves a SAML assertion's mapped
22
+ * attributes under `firebase.sign_in_attributes` on the token, and the
23
+ * provider entry is as blank as the record. The account menu never noticed,
24
+ * because it reads the person's own profile document (`users/{uid}`), which
25
+ * the sign-in seed fills from the IdP. The staff Users list and the staff
26
+ * user page read the Auth record alone, so the same person showed a photo
27
+ * and a name in the app bar and a grey initial and "—" on every staff
28
+ * surface. Several surfaces, several precedences, one person.
29
+ *
30
+ * Pure, no Firebase, no React — every surface that shows ANOTHER account's
31
+ * identity (staff list, staff user page, org rosters, the forum) hands this
32
+ * whatever sources it can legitimately read, and gets the same answer.
33
+ *
34
+ * ## The order
35
+ *
36
+ * 1. The Auth record — what the account itself, or staff, last set.
37
+ * 2. The profile document `users/{uid}` — what Manage Account edits and what
38
+ * the sign-in seed fills from the IdP (`firstName`/`lastName`, and
39
+ * `photoUrl` with that document's lowercase spelling).
40
+ * 3. The Auth record's `providerData` entries — Google keeps its avatar
41
+ * there when the top-level field was never mirrored.
42
+ * 4. Whatever the IdP sent at sign-in (SAML attributes / OIDC claims), as
43
+ * captured on the org roster row or resolved off a decoded token.
44
+ *
45
+ * A blank value never wins over a populated one further down: each field is
46
+ * resolved independently, so an account with an Auth name and only a profile
47
+ * photo gets both.
48
+ */ function text(value) {
49
+ return typeof value === 'string' ? value.replace(/\s+/g, ' ').trim() : '';
50
+ }
51
+ /**
52
+ * A photo value safe to put in an `<img src>`: `https:`/`http:` URLs and
53
+ * scheme-less paths (the media CDN stores `/media/...` paths) pass;
54
+ * `javascript:`, `data:` and every other scheme do not. These values reach
55
+ * other people's browsers, so a hostile one must not become stored script.
56
+ */ export function sanitizeAccountPhotoUrl(value) {
57
+ var _scheme_;
58
+ const candidate = text(value);
59
+ if (!candidate) return '';
60
+ const scheme = /^([a-z][a-z0-9+.-]*):/i.exec(candidate);
61
+ if (!scheme) return candidate.startsWith('/') ? candidate : '';
62
+ const name = ((_scheme_ = scheme[1]) != null ? _scheme_ : '').toLowerCase();
63
+ return name === 'https' || name === 'http' ? candidate : '';
64
+ }
65
+ function profileName(profile) {
66
+ if (!profile) return '';
67
+ const joined = [
68
+ text(profile.firstName),
69
+ text(profile.lastName)
70
+ ].filter(Boolean).join(' ');
71
+ return joined || text(profile.displayName);
72
+ }
73
+ export function resolveAccountIdentity(sources) {
74
+ var _ref, _providers_map_find, _providers_map_find1, _ref1, _ref2, _ref3, _ref4;
75
+ var _sources_auth, _sources_auth1, _sources_idp, _sources_auth2, _sources_profile, _sources_idp1, _sources_idp2;
76
+ const providers = ((_ref = (_sources_auth = sources.auth) == null ? void 0 : _sources_auth.providerData) != null ? _ref : []).filter((entry)=>Boolean(entry));
77
+ const nameCandidates = [
78
+ [
79
+ 'auth',
80
+ text((_sources_auth1 = sources.auth) == null ? void 0 : _sources_auth1.displayName)
81
+ ],
82
+ [
83
+ 'profile',
84
+ profileName(sources.profile)
85
+ ],
86
+ [
87
+ 'provider',
88
+ (_providers_map_find = providers.map((entry)=>text(entry.displayName)).find(Boolean)) != null ? _providers_map_find : ''
89
+ ],
90
+ [
91
+ 'idp',
92
+ text((_sources_idp = sources.idp) == null ? void 0 : _sources_idp.displayName)
93
+ ]
94
+ ];
95
+ const photoCandidates = [
96
+ [
97
+ 'auth',
98
+ sanitizeAccountPhotoUrl((_sources_auth2 = sources.auth) == null ? void 0 : _sources_auth2.photoURL)
99
+ ],
100
+ [
101
+ 'profile',
102
+ sanitizeAccountPhotoUrl((_sources_profile = sources.profile) == null ? void 0 : _sources_profile.photoUrl)
103
+ ],
104
+ [
105
+ 'provider',
106
+ (_providers_map_find1 = providers.map((entry)=>sanitizeAccountPhotoUrl(entry.photoURL)).find(Boolean)) != null ? _providers_map_find1 : ''
107
+ ],
108
+ [
109
+ 'idp',
110
+ sanitizeAccountPhotoUrl((_sources_idp1 = sources.idp) == null ? void 0 : _sources_idp1.photoUrl) || sanitizeAccountPhotoUrl((_sources_idp2 = sources.idp) == null ? void 0 : _sources_idp2.photoURL)
111
+ ]
112
+ ];
113
+ const name = nameCandidates.find(([, value])=>value);
114
+ const photo = photoCandidates.find(([, value])=>value);
115
+ const displayName = (_ref1 = name == null ? void 0 : name[1]) != null ? _ref1 : null;
116
+ return {
117
+ displayName,
118
+ photoUrl: (_ref2 = photo == null ? void 0 : photo[1]) != null ? _ref2 : null,
119
+ label: displayName != null ? displayName : text(sources.email) || null,
120
+ displayNameSource: (_ref3 = name == null ? void 0 : name[0]) != null ? _ref3 : null,
121
+ photoUrlSource: (_ref4 = photo == null ? void 0 : photo[0]) != null ? _ref4 : null
122
+ };
123
+ }
124
+ /**
125
+ * Which of an Auth record's identity fields are blank and could be filled
126
+ * from what the IdP sent, without overwriting anything (AGL-3721).
127
+ *
128
+ * Absent-only by construction: a field the record already holds is never in
129
+ * the result, so a name or photo the person (or staff) set always survives.
130
+ * `photoErased` is the profile's `photoUrlErasedAt` marker — a person who
131
+ * removed their avatar has asked not to have the directory's put back.
132
+ */ export function authIdentityFillFromIdp(input) {
133
+ var _input_idp, _input_auth, _input_idp1, _input_auth1;
134
+ const fill = {};
135
+ const idpName = text((_input_idp = input.idp) == null ? void 0 : _input_idp.displayName);
136
+ if (idpName && !text((_input_auth = input.auth) == null ? void 0 : _input_auth.displayName)) fill.displayName = idpName;
137
+ const idpPhoto = sanitizeAccountPhotoUrl((_input_idp1 = input.idp) == null ? void 0 : _input_idp1.photoUrl);
138
+ // An Auth record's photoURL must be an absolute URL; a CDN path is not one.
139
+ if (idpPhoto && /^https:\/\//i.test(idpPhoto) && !input.photoErased && !text((_input_auth1 = input.auth) == null ? void 0 : _input_auth1.photoURL)) {
140
+ fill.photoURL = idpPhoto;
141
+ }
142
+ return fill;
143
+ }
144
+ export default resolveAccountIdentity;
145
+
146
+ //# sourceMappingURL=account-identity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/shared/util/tools/src/lib/account-identity.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * ONE ANSWER TO \"WHAT IS THIS ACCOUNT CALLED, AND WHAT DOES IT LOOK LIKE\"\n * (AGL-3721).\n *\n * The defect this closes: an SSO account's Firebase Auth record carries no\n * `displayName` and no `photoURL` — GCIP leaves a SAML assertion's mapped\n * attributes under `firebase.sign_in_attributes` on the token, and the\n * provider entry is as blank as the record. The account menu never noticed,\n * because it reads the person's own profile document (`users/{uid}`), which\n * the sign-in seed fills from the IdP. The staff Users list and the staff\n * user page read the Auth record alone, so the same person showed a photo\n * and a name in the app bar and a grey initial and \"—\" on every staff\n * surface. Several surfaces, several precedences, one person.\n *\n * Pure, no Firebase, no React — every surface that shows ANOTHER account's\n * identity (staff list, staff user page, org rosters, the forum) hands this\n * whatever sources it can legitimately read, and gets the same answer.\n *\n * ## The order\n *\n * 1. The Auth record — what the account itself, or staff, last set.\n * 2. The profile document `users/{uid}` — what Manage Account edits and what\n * the sign-in seed fills from the IdP (`firstName`/`lastName`, and\n * `photoUrl` with that document's lowercase spelling).\n * 3. The Auth record's `providerData` entries — Google keeps its avatar\n * there when the top-level field was never mirrored.\n * 4. Whatever the IdP sent at sign-in (SAML attributes / OIDC claims), as\n * captured on the org roster row or resolved off a decoded token.\n *\n * A blank value never wins over a populated one further down: each field is\n * resolved independently, so an account with an Auth name and only a profile\n * photo gets both.\n */\n\nexport type AccountIdentitySource = 'auth' | 'profile' | 'provider' | 'idp'\n\nexport interface AccountIdentityAuthSource {\n displayName?: string | null\n photoURL?: string | null\n providerData?: ReadonlyArray<{\n displayName?: string | null\n photoURL?: string | null\n } | null | undefined> | null\n}\n\nexport interface AccountIdentityProfileSource {\n firstName?: unknown\n lastName?: unknown\n /** Legacy single-string name, read only when first/last are both blank. */\n displayName?: unknown\n /** `users/{uid}` spells it `photoUrl`, not the roster's `photoURL`. */\n photoUrl?: unknown\n}\n\nexport interface AccountIdentityIdpSource {\n displayName?: string | null\n /** Accepts either spelling, so a roster row can be passed as-is. */\n photoUrl?: string | null\n photoURL?: string | null\n}\n\nexport interface AccountIdentitySources {\n auth?: AccountIdentityAuthSource | null\n profile?: AccountIdentityProfileSource | null\n idp?: AccountIdentityIdpSource | null\n /** Used only for `label` — an address is not a name. */\n email?: string | null\n}\n\nexport interface ResolvedAccountIdentity {\n /** The person's name, or null when no source holds one. */\n displayName: string | null\n /** The avatar URL, or null — callers draw initials. */\n photoUrl: string | null\n /** What to print when there is no name: the name, else the email. */\n label: string | null\n displayNameSource: AccountIdentitySource | null\n photoUrlSource: AccountIdentitySource | null\n}\n\nfunction text(value: unknown): string {\n return typeof value === 'string' ? value.replace(/\\s+/g, ' ').trim() : ''\n}\n\n/**\n * A photo value safe to put in an `<img src>`: `https:`/`http:` URLs and\n * scheme-less paths (the media CDN stores `/media/...` paths) pass;\n * `javascript:`, `data:` and every other scheme do not. These values reach\n * other people's browsers, so a hostile one must not become stored script.\n */\nexport function sanitizeAccountPhotoUrl(value: unknown): string {\n const candidate = text(value)\n if (!candidate) return ''\n const scheme = /^([a-z][a-z0-9+.-]*):/i.exec(candidate)\n if (!scheme) return candidate.startsWith('/') ? candidate : ''\n const name = (scheme[1] ?? '').toLowerCase()\n return name === 'https' || name === 'http' ? candidate : ''\n}\n\nfunction profileName(profile: AccountIdentityProfileSource | null | undefined): string {\n if (!profile) return ''\n const joined = [text(profile.firstName), text(profile.lastName)]\n .filter(Boolean)\n .join(' ')\n return joined || text(profile.displayName)\n}\n\nexport function resolveAccountIdentity(\n sources: AccountIdentitySources,\n): ResolvedAccountIdentity {\n const providers = (sources.auth?.providerData ?? []).filter(\n (entry): entry is NonNullable<typeof entry> => Boolean(entry),\n )\n\n const nameCandidates: Array<[AccountIdentitySource, string]> = [\n ['auth', text(sources.auth?.displayName)],\n ['profile', profileName(sources.profile)],\n ['provider', providers.map((entry) => text(entry.displayName)).find(Boolean) ?? ''],\n ['idp', text(sources.idp?.displayName)],\n ]\n const photoCandidates: Array<[AccountIdentitySource, string]> = [\n ['auth', sanitizeAccountPhotoUrl(sources.auth?.photoURL)],\n ['profile', sanitizeAccountPhotoUrl(sources.profile?.photoUrl)],\n [\n 'provider',\n providers.map((entry) => sanitizeAccountPhotoUrl(entry.photoURL)).find(Boolean) ?? '',\n ],\n [\n 'idp',\n sanitizeAccountPhotoUrl(sources.idp?.photoUrl) ||\n sanitizeAccountPhotoUrl(sources.idp?.photoURL),\n ],\n ]\n\n const name = nameCandidates.find(([, value]) => value)\n const photo = photoCandidates.find(([, value]) => value)\n const displayName = name?.[1] ?? null\n return {\n displayName,\n photoUrl: photo?.[1] ?? null,\n label: displayName ?? (text(sources.email) || null),\n displayNameSource: name?.[0] ?? null,\n photoUrlSource: photo?.[0] ?? null,\n }\n}\n\n/**\n * Which of an Auth record's identity fields are blank and could be filled\n * from what the IdP sent, without overwriting anything (AGL-3721).\n *\n * Absent-only by construction: a field the record already holds is never in\n * the result, so a name or photo the person (or staff) set always survives.\n * `photoErased` is the profile's `photoUrlErasedAt` marker — a person who\n * removed their avatar has asked not to have the directory's put back.\n */\nexport function authIdentityFillFromIdp(input: {\n auth: { displayName?: string | null; photoURL?: string | null } | null | undefined\n idp: { displayName?: string | null; photoUrl?: string | null } | null | undefined\n photoErased?: boolean\n}): { displayName?: string; photoURL?: string } {\n const fill: { displayName?: string; photoURL?: string } = {}\n const idpName = text(input.idp?.displayName)\n if (idpName && !text(input.auth?.displayName)) fill.displayName = idpName\n const idpPhoto = sanitizeAccountPhotoUrl(input.idp?.photoUrl)\n // An Auth record's photoURL must be an absolute URL; a CDN path is not one.\n if (\n idpPhoto &&\n /^https:\\/\\//i.test(idpPhoto) &&\n !input.photoErased &&\n !text(input.auth?.photoURL)\n ) {\n fill.photoURL = idpPhoto\n }\n return fill\n}\n\nexport default resolveAccountIdentity\n"],"names":["text","value","replace","trim","sanitizeAccountPhotoUrl","scheme","candidate","exec","startsWith","name","toLowerCase","profileName","profile","joined","firstName","lastName","filter","Boolean","join","displayName","resolveAccountIdentity","sources","providers","auth","providerData","entry","nameCandidates","map","find","idp","photoCandidates","photoURL","photoUrl","photo","label","email","displayNameSource","photoUrlSource","authIdentityFillFromIdp","input","fill","idpName","idpPhoto","test","photoErased"],"mappings":"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"}