@pontive/pontkit-core 1.40.0 → 1.41.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/catalog.json +1 -1
- package/custom-elements.json +1 -1
- package/dist/index.js +1283 -873
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +13084 -10797
- package/dist/index.mjs.map +1 -1
- package/dist/pont2/core/format.d.ts +46 -0
- package/dist/pont2/core/icons.d.ts +5 -0
- package/dist/pont2/core/index.d.ts +1 -0
- package/dist/pont2/core/messages.d.ts +107 -2
- package/dist/pont2/custom-elements.json +20404 -14583
- package/dist/pont2/index.mjs +4800 -2651
- package/dist/pont2/index.mjs.map +1 -1
- package/dist/pont2/kit/account-menu/account-menu.d.ts +115 -0
- package/dist/pont2/kit/account-settings/account-settings.d.ts +157 -0
- package/dist/pont2/kit/account-settings/profile.d.ts +74 -0
- package/dist/pont2/kit/index.d.ts +4 -0
- package/dist/pont2/kit/member-management/errors.d.ts +60 -0
- package/dist/pont2/kit/member-management/member-management.d.ts +237 -0
- package/dist/pont2/kit/member-management/roles.d.ts +42 -0
- package/dist/pont2/kit/organization-switcher/organization-switcher.d.ts +111 -0
- package/dist/pont2/kit/provider/account-client.d.ts +355 -0
- package/dist/pont2/kit/provider/account-controller.d.ts +47 -0
- package/dist/pont2/kit/provider/account-user.d.ts +16 -0
- package/dist/pont2/kit/provider/provider.d.ts +43 -9
- package/dist/pont2/kit/provider/sdk.d.ts +14 -0
- package/dist/pont2/styles.css +482 -0
- package/dist/styles.css +482 -0
- package/package.json +2 -2
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { nothing, PropertyDeclarations, PropertyValues } from 'lit';
|
|
2
|
+
import { MessagesController } from '../../core/messages';
|
|
3
|
+
import { DropdownMenu } from '../../primitives/dropdown-menu/dropdown-menu';
|
|
4
|
+
import { AccountClient, SessionUser } from '../provider/account-client';
|
|
5
|
+
import { AccountController } from '../provider/account-controller';
|
|
6
|
+
/** One extra entry of the account menu (legacy `menuItems`). */
|
|
7
|
+
export interface AccountMenuItem {
|
|
8
|
+
/** Identifies the item in events and keeps its toggle/select state (default: `label`). */
|
|
9
|
+
id?: string;
|
|
10
|
+
label: string;
|
|
11
|
+
/** `action` (default) runs `onClick` or follows `href`; `toggle` is a checkbox item; `select` a submenu of options. */
|
|
12
|
+
type?: "action" | "toggle" | "select";
|
|
13
|
+
/** An icon shown before the label: a Lit template (an `<svg>`). */
|
|
14
|
+
icon?: unknown;
|
|
15
|
+
/** `destructive` for an action that deletes or leaves. */
|
|
16
|
+
variant?: "default" | "destructive";
|
|
17
|
+
disabled?: boolean;
|
|
18
|
+
href?: string;
|
|
19
|
+
onClick?: (event: Event, item: AccountMenuItem) => void;
|
|
20
|
+
checked?: boolean;
|
|
21
|
+
onToggle?: (checked: boolean) => void;
|
|
22
|
+
options?: {
|
|
23
|
+
value: string;
|
|
24
|
+
label: string;
|
|
25
|
+
}[];
|
|
26
|
+
value?: string;
|
|
27
|
+
onSelect?: (value: string) => void;
|
|
28
|
+
}
|
|
29
|
+
/** Detail of `pont2-menu-item-click`. */
|
|
30
|
+
export interface MenuItemClickDetail {
|
|
31
|
+
item: AccountMenuItem;
|
|
32
|
+
/** A toggle's new state. */
|
|
33
|
+
checked?: boolean;
|
|
34
|
+
/** A select's chosen value. */
|
|
35
|
+
value?: string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* # `<pont2-account-menu>`: who is signed in, account settings, log out
|
|
39
|
+
*
|
|
40
|
+
* ```html
|
|
41
|
+
* <pont2-provider app-id="app_123" domain="auth.acme.com" api-base-url="https://api.us.pontive.com">
|
|
42
|
+
* <pont2-account-menu account-settings-url="/account"></pont2-account-menu>
|
|
43
|
+
* </pont2-provider>
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* The legacy `pont-account-menu` (with its `pont-user-snippet`), as shadcn's
|
|
47
|
+
* "nav user": a ghost button with the user's avatar, name and email opening a
|
|
48
|
+
* Dropdown Menu with the same header, **Account settings**, the app's own
|
|
49
|
+
* `items`, and **Log out**. It **is** the Dropdown Menu primitive's root
|
|
50
|
+
* (`extends DropdownMenu`), so keyboard, focus and dismissal are the menu's.
|
|
51
|
+
*
|
|
52
|
+
* - **Data** comes from the account client (`pont2:account-client`, or its own
|
|
53
|
+
* `client`): the user is `client.getUser()`, read again on every session
|
|
54
|
+
* change. It never calls the SDK itself.
|
|
55
|
+
* - **Nothing renders** until the provider has resolved the auth state, nor
|
|
56
|
+
* for a signed-out visitor.
|
|
57
|
+
* - **Account settings** fires `pont2-account-settings` (cancelable: cancel it
|
|
58
|
+
* to navigate with a client-side router). Otherwise it goes to
|
|
59
|
+
* `account-settings-url` (not when that is the page already open), else it
|
|
60
|
+
* asks an account-settings dialog to open (`pont2-open-account-settings` on
|
|
61
|
+
* `document`).
|
|
62
|
+
* - **Log out** fires `pont2-logout` (cancelable: cancel it to sign out
|
|
63
|
+
* yourself), then `client.signOut()`.
|
|
64
|
+
* - **Items** fire `pont2-menu-item-click` (`{ item, checked?, value? }`); an
|
|
65
|
+
* action item then runs `onClick`, else follows `href` unless the event was
|
|
66
|
+
* cancelled.
|
|
67
|
+
*
|
|
68
|
+
* Words: `account_settings`, `log_out` (branding-svc Account messages).
|
|
69
|
+
*
|
|
70
|
+
* @tag pont2-account-menu
|
|
71
|
+
* @attr account-settings-url - where "Account settings" goes when nothing cancels `pont2-account-settings`
|
|
72
|
+
* @prop client - its own `AccountClient` (default: the provider's)
|
|
73
|
+
* @prop items - `AccountMenuItem[]`: entries between "Account settings" and "Log out"
|
|
74
|
+
* @fires pont2-account-settings - cancelable, `{}`: "Account settings" was chosen
|
|
75
|
+
* @fires pont2-logout - cancelable, `{}`: "Log out" was chosen
|
|
76
|
+
* @fires pont2-menu-item-click - cancelable `{ item, checked?, value? }`: one of `items` was chosen
|
|
77
|
+
* @fires pont2-open-change - cancelable `{ open, reason }` (the menu's)
|
|
78
|
+
*/
|
|
79
|
+
export declare class AccountMenu extends DropdownMenu {
|
|
80
|
+
static composite: boolean;
|
|
81
|
+
static properties: PropertyDeclarations;
|
|
82
|
+
client: AccountClient | undefined;
|
|
83
|
+
items: AccountMenuItem[];
|
|
84
|
+
accountSettingsUrl: string;
|
|
85
|
+
/** Who is signed in, as last read from the client (null: nobody, or not known yet). */
|
|
86
|
+
user: SessionUser | null;
|
|
87
|
+
protected readonly messages: MessagesController;
|
|
88
|
+
protected readonly account: AccountController;
|
|
89
|
+
/** Toggle and select states, by item key. */
|
|
90
|
+
private itemState;
|
|
91
|
+
constructor();
|
|
92
|
+
private readUser;
|
|
93
|
+
protected willUpdate(changed: PropertyValues): void;
|
|
94
|
+
private onAccountSettings;
|
|
95
|
+
private onLogout;
|
|
96
|
+
private onAction;
|
|
97
|
+
private onToggle;
|
|
98
|
+
private onSelect;
|
|
99
|
+
private snippet;
|
|
100
|
+
private renderItem;
|
|
101
|
+
render(): import('lit-html').TemplateResult<1> | typeof nothing;
|
|
102
|
+
}
|
|
103
|
+
declare global {
|
|
104
|
+
interface HTMLElementTagNameMap {
|
|
105
|
+
"pont2-account-menu": AccountMenu;
|
|
106
|
+
}
|
|
107
|
+
interface HTMLElementEventMap {
|
|
108
|
+
"pont2-account-settings": CustomEvent<Record<string, never>>;
|
|
109
|
+
"pont2-logout": CustomEvent<Record<string, never>>;
|
|
110
|
+
"pont2-menu-item-click": CustomEvent<MenuItemClickDetail>;
|
|
111
|
+
}
|
|
112
|
+
interface DocumentEventMap {
|
|
113
|
+
"pont2-open-account-settings": CustomEvent<void>;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { nothing, PropertyDeclarations, PropertyValues, TemplateResult } from 'lit';
|
|
2
|
+
import { HostElement } from '../../core/host-element';
|
|
3
|
+
import { MessagesController } from '../../core/messages';
|
|
4
|
+
import { BrandingController } from '../block/branding';
|
|
5
|
+
import { AccountClient, AccountProfile } from '../provider/account-client';
|
|
6
|
+
import { AccountController } from '../provider/account-controller';
|
|
7
|
+
import { ProfileSection, SectionErrors, SectionValues } from './profile';
|
|
8
|
+
export type AccountSettingsMode = "page" | "modal";
|
|
9
|
+
export type AccountSettingsOrientation = "horizontal" | "vertical";
|
|
10
|
+
export type AccountSettingsLayout = "row" | "column";
|
|
11
|
+
/** A card's own title and icon (legacy `IProfileWidgetCustomization`). */
|
|
12
|
+
export interface AccountSettingsCardContent {
|
|
13
|
+
title?: string;
|
|
14
|
+
/** Shown before the title: a Lit template or an element. */
|
|
15
|
+
icon?: unknown;
|
|
16
|
+
}
|
|
17
|
+
/** The cards' titles and icons (legacy `IProfileContentCustomizations`, same keys). */
|
|
18
|
+
export interface AccountSettingsContent {
|
|
19
|
+
account?: AccountSettingsCardContent;
|
|
20
|
+
personalInfo?: AccountSettingsCardContent;
|
|
21
|
+
locations?: AccountSettingsCardContent;
|
|
22
|
+
urls?: AccountSettingsCardContent;
|
|
23
|
+
}
|
|
24
|
+
/** Detail of `pont2-profile-updated`. */
|
|
25
|
+
export interface ProfileUpdatedDetail {
|
|
26
|
+
section: ProfileSection;
|
|
27
|
+
profile: AccountProfile;
|
|
28
|
+
}
|
|
29
|
+
type LoadState = "idle" | "loading" | "ready" | "error";
|
|
30
|
+
/**
|
|
31
|
+
* # `<pont2-account-settings>`: the signed-in user's own profile
|
|
32
|
+
*
|
|
33
|
+
* ```html
|
|
34
|
+
* <pont2-provider app-id="app_123" domain="auth.acme.com" api-base-url="https://api.us.pontive.com">
|
|
35
|
+
* <pont2-account-menu></pont2-account-menu>
|
|
36
|
+
* <pont2-account-settings mode="modal"></pont2-account-settings>
|
|
37
|
+
* </pont2-provider>
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* The legacy `pont-account-settings`: a Profile tab (Login info with the
|
|
41
|
+
* photo, email and phone; Personal info; Location; Links) and a Security tab
|
|
42
|
+
* (coming soon), each profile card edited and saved on its own.
|
|
43
|
+
*
|
|
44
|
+
* - **Data** comes from the account client (`pont2:account-client`, or its own
|
|
45
|
+
* `client`): `getProfile()` (`GET /mgmt/v1/me`) and `updateProfile()`
|
|
46
|
+
* (`PATCH /mgmt/v1/me`). A client without `getProfile` gets a "not available"
|
|
47
|
+
* state; one without `updateProfile` shows the profile read-only.
|
|
48
|
+
* - **Nothing renders** until the auth state is resolved, nor for a
|
|
49
|
+
* signed-out visitor. Signing in as someone else reads the profile again.
|
|
50
|
+
* - **`mode="page"`** (default) shows it in place (a skeleton while the
|
|
51
|
+
* profile loads). **`mode="modal"`** shows it in a Dialog, opened by `open`,
|
|
52
|
+
* `show()`, or the account menu's "Account settings": this element answers
|
|
53
|
+
* the menu's `pont2-open-account-settings` (on `document`) with
|
|
54
|
+
* `preventDefault()` and opens. `pont2-close-account-settings` on `document`
|
|
55
|
+
* closes it.
|
|
56
|
+
* - **Labels wrap** (carry-over §4): a long translated label keeps a gap from
|
|
57
|
+
* its value and wraps instead of running into it; below 30rem the label
|
|
58
|
+
* sits above the value.
|
|
59
|
+
* - **Errors** are said in the card, in the page's language: a refused save
|
|
60
|
+
* keeps the form open with the section's own failure (`instance_unavailable`
|
|
61
|
+
* for a stopped instance, `connection_failed` with no answer), never the
|
|
62
|
+
* server's English.
|
|
63
|
+
*
|
|
64
|
+
* @tag pont2-account-settings
|
|
65
|
+
* @attr mode - `page` (default) | `modal` (legacy `PAGE` / `MODAL`)
|
|
66
|
+
* @attr orientation - `horizontal` (default: the tabs beside the content) | `vertical` (the tabs above it)
|
|
67
|
+
* @attr widgets-layout - `row` (default: label beside value) | `column` (label above value)
|
|
68
|
+
* @attr open - modal mode: whether the dialog is open
|
|
69
|
+
* @prop client - its own `AccountClient` (default: the provider's)
|
|
70
|
+
* @prop content - `AccountSettingsContent`: the cards' own titles and icons
|
|
71
|
+
* @prop profile - `AccountProfile | null` (read-only): the profile shown
|
|
72
|
+
* @fires pont2-profile-updated - `{ section, profile }`, after a section was saved
|
|
73
|
+
* @fires pont2-open-change - modal mode: cancelable `{ open, reason }` (the dialog's)
|
|
74
|
+
*/
|
|
75
|
+
export declare class AccountSettings extends HostElement {
|
|
76
|
+
static composite: boolean;
|
|
77
|
+
static properties: PropertyDeclarations;
|
|
78
|
+
client: AccountClient | undefined;
|
|
79
|
+
mode: AccountSettingsMode;
|
|
80
|
+
orientation: AccountSettingsOrientation;
|
|
81
|
+
widgetsLayout: AccountSettingsLayout;
|
|
82
|
+
open: boolean;
|
|
83
|
+
content: AccountSettingsContent | null;
|
|
84
|
+
profile: AccountProfile | null;
|
|
85
|
+
protected loadState: LoadState;
|
|
86
|
+
protected loadProblem: {
|
|
87
|
+
message: string;
|
|
88
|
+
retry: boolean;
|
|
89
|
+
} | null;
|
|
90
|
+
/** The section being edited (one at a time). */
|
|
91
|
+
protected editing: ProfileSection | null;
|
|
92
|
+
protected draft: SectionValues;
|
|
93
|
+
protected errors: SectionErrors;
|
|
94
|
+
protected saving: boolean;
|
|
95
|
+
protected saveError: string | null;
|
|
96
|
+
protected readonly messages: MessagesController;
|
|
97
|
+
protected readonly branding: BrandingController;
|
|
98
|
+
protected readonly account: AccountController;
|
|
99
|
+
private readonly ids;
|
|
100
|
+
private loadSeq;
|
|
101
|
+
/** Who the profile was read for (`sub`). */
|
|
102
|
+
private loadedFor;
|
|
103
|
+
private zones;
|
|
104
|
+
constructor();
|
|
105
|
+
connectedCallback(): void;
|
|
106
|
+
disconnectedCallback(): void;
|
|
107
|
+
/** Modal mode: opens the dialog. */
|
|
108
|
+
show(): void;
|
|
109
|
+
/** Modal mode: closes the dialog. */
|
|
110
|
+
close(): void;
|
|
111
|
+
/** Reads the profile again. */
|
|
112
|
+
reload(): Promise<void>;
|
|
113
|
+
/** `pont2-open-account-settings`: the menu's "Account settings" had no URL and nothing cancelled it. */
|
|
114
|
+
private onOpenRequest;
|
|
115
|
+
private onCloseRequest;
|
|
116
|
+
private refresh;
|
|
117
|
+
private whoAmI;
|
|
118
|
+
private get available();
|
|
119
|
+
private get editable();
|
|
120
|
+
private load;
|
|
121
|
+
private startEdit;
|
|
122
|
+
private cancelEdit;
|
|
123
|
+
private setDraft;
|
|
124
|
+
private save;
|
|
125
|
+
private timeZoneList;
|
|
126
|
+
protected willUpdate(changed: PropertyValues): void;
|
|
127
|
+
private fieldId;
|
|
128
|
+
private onDialogOpenChange;
|
|
129
|
+
render(): TemplateResult<1> | typeof nothing;
|
|
130
|
+
private renderBody;
|
|
131
|
+
private renderSkeleton;
|
|
132
|
+
private renderWatermark;
|
|
133
|
+
private cardHeader;
|
|
134
|
+
/** A label / value pair; wraps (carry-over §4). */
|
|
135
|
+
private row;
|
|
136
|
+
private shown;
|
|
137
|
+
private renderLoginInfo;
|
|
138
|
+
private renderSection;
|
|
139
|
+
private displayValue;
|
|
140
|
+
private control;
|
|
141
|
+
private onSubmit;
|
|
142
|
+
private formButtons;
|
|
143
|
+
private renderSaveError;
|
|
144
|
+
private renderSecurity;
|
|
145
|
+
}
|
|
146
|
+
declare global {
|
|
147
|
+
interface HTMLElementTagNameMap {
|
|
148
|
+
"pont2-account-settings": AccountSettings;
|
|
149
|
+
}
|
|
150
|
+
interface HTMLElementEventMap {
|
|
151
|
+
"pont2-profile-updated": CustomEvent<ProfileUpdatedDetail>;
|
|
152
|
+
}
|
|
153
|
+
interface DocumentEventMap {
|
|
154
|
+
"pont2-close-account-settings": CustomEvent<void>;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
export {};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { KitMessageCode } from '../../core/messages';
|
|
2
|
+
import { AccountProfile, AccountProfileUpdate } from '../provider/account-client';
|
|
3
|
+
/**
|
|
4
|
+
* # Account settings' profile sections: values, rules, updates (W-8)
|
|
5
|
+
*
|
|
6
|
+
* Pure, so the rules can be unit-tested (`profile.test.ts`). The four cards
|
|
7
|
+
* of the legacy profile tab, each edited and saved on its own:
|
|
8
|
+
*
|
|
9
|
+
* | Section | Fields (`/mgmt/v1/me`) |
|
|
10
|
+
* |---|---|
|
|
11
|
+
* | `photo` (in the Login info card) | `picture` |
|
|
12
|
+
* | `personal` | `username`, `given_name`, `middle_name`, `family_name`, `nickname`, `gender`, `profile` (bio) |
|
|
13
|
+
* | `location` | `address.locality`, `zoneinfo` |
|
|
14
|
+
* | `links` | `website` |
|
|
15
|
+
*
|
|
16
|
+
* Email and phone show in the Login info card, read-only (they are
|
|
17
|
+
* identifiers, changed through a verification flow, not here).
|
|
18
|
+
*/
|
|
19
|
+
export type ProfileSection = "photo" | "personal" | "location" | "links";
|
|
20
|
+
export type FieldKey = "picture" | "username" | "given_name" | "middle_name" | "family_name" | "nickname" | "gender" | "profile" | "locality" | "zoneinfo" | "website";
|
|
21
|
+
export type SectionValues = Partial<Record<FieldKey, string>>;
|
|
22
|
+
export type SectionErrors = Partial<Record<FieldKey, string>>;
|
|
23
|
+
export declare const SECTION_FIELDS: Record<ProfileSection, FieldKey[]>;
|
|
24
|
+
/** Each field's label. */
|
|
25
|
+
export declare const FIELD_LABELS: Record<FieldKey, KitMessageCode>;
|
|
26
|
+
/**
|
|
27
|
+
* The longest value each text field takes (`maxlength`; the server's limits). The legacy cards
|
|
28
|
+
* said "X cannot be longer than 100 characters" in English; the input simply stops there instead,
|
|
29
|
+
* which needs no words (account text takes no placeholders).
|
|
30
|
+
*/
|
|
31
|
+
export declare const MAX_LENGTH: Partial<Record<FieldKey, number>>;
|
|
32
|
+
/** Where a failed save says why. */
|
|
33
|
+
export declare const SAVE_FAILED: Record<ProfileSection, KitMessageCode>;
|
|
34
|
+
/** The stored gender values (the legacy options' values) and their words. */
|
|
35
|
+
export declare const GENDERS: {
|
|
36
|
+
value: string;
|
|
37
|
+
label: KitMessageCode;
|
|
38
|
+
}[];
|
|
39
|
+
/** A stored gender in the page's language; a value from elsewhere shows as stored. */
|
|
40
|
+
export declare function genderLabel(value: string | undefined): string;
|
|
41
|
+
/** What a field shows (and its edit box starts with) for `profile`. */
|
|
42
|
+
export declare function fieldValue(profile: AccountProfile | null | undefined, key: FieldKey): string;
|
|
43
|
+
/** A section's values from `profile`, for its edit form. */
|
|
44
|
+
export declare function sectionValues(profile: AccountProfile | null | undefined, section: ProfileSection): SectionValues;
|
|
45
|
+
/** IANA time zone names, from the browser's own tz database (with the user's zone and UTC at least). */
|
|
46
|
+
export declare function timeZones(): string[];
|
|
47
|
+
/** Why an http(s) URL field is wrong (`url_hint`, `url_scheme_invalid`), or undefined when it is fine or empty. */
|
|
48
|
+
export declare function urlProblem(raw: string): KitMessageCode | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* The rules the server applies anyway, run here so a refusal is a message beside the field. Every
|
|
51
|
+
* field is optional: a rule only fires on a value typed. `zones` is the time zone list the select
|
|
52
|
+
* offers (a stored value from before the select may be free text: `timezone_hint`).
|
|
53
|
+
*/
|
|
54
|
+
export declare function validateSection(section: ProfileSection, values: SectionValues, zones?: string[]): SectionErrors;
|
|
55
|
+
/** The `PATCH /me` body for a section: its fields, trimmed (the address merged, so the rest of it is kept). */
|
|
56
|
+
export declare function sectionUpdate(section: ProfileSection, values: SectionValues, profile: AccountProfile | null | undefined): AccountProfileUpdate;
|
|
57
|
+
/**
|
|
58
|
+
* A stored website as a link target: absolute http(s) only (carry-over §7's rule), a bare
|
|
59
|
+
* "example.com" from before the field was validated taken as https. `null`: show it as text.
|
|
60
|
+
*/
|
|
61
|
+
export declare function websiteHref(value: string | undefined): string | null;
|
|
62
|
+
/** A stored picture URL fit for an `<img src>`: absolute http(s) or a data:image URL, else `null`. */
|
|
63
|
+
export declare function pictureSrc(value: string | undefined): string | null;
|
|
64
|
+
/**
|
|
65
|
+
* Why a save failed, in the person's words: a stopped instance says so (§6), no answer is
|
|
66
|
+
* `connection_failed`, anything else the section's own failure. Never the server's English
|
|
67
|
+
* (`/me` is the management API, whose refusals are English only).
|
|
68
|
+
*/
|
|
69
|
+
export declare function describeProfileError(error: unknown, fallback: KitMessageCode): string;
|
|
70
|
+
/** Why the profile couldn't be read, and whether trying again could help. */
|
|
71
|
+
export declare function describeProfileLoadError(error: unknown): {
|
|
72
|
+
message: string;
|
|
73
|
+
retry: boolean;
|
|
74
|
+
};
|
|
@@ -34,3 +34,7 @@ export * from './data-table/data-table';
|
|
|
34
34
|
export * from './badge-selector/badge-selector';
|
|
35
35
|
export * from './multi-email-input/multi-email-input';
|
|
36
36
|
export * from './multi-select-filter/multi-select-filter';
|
|
37
|
+
export * from './account-menu/account-menu';
|
|
38
|
+
export * from './organization-switcher/organization-switcher';
|
|
39
|
+
export * from './account-settings/account-settings';
|
|
40
|
+
export * from './member-management/member-management';
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { isNetworkFailure, tokenErrorCode } from '../provider/account-client';
|
|
2
|
+
export { isNetworkFailure, tokenErrorCode };
|
|
3
|
+
/**
|
|
4
|
+
* # Member management's errors, in the person's words (carry-over §5, §6)
|
|
5
|
+
*
|
|
6
|
+
* A failure is said, never shown as an empty table. The legacy
|
|
7
|
+
* `pont-member-management/errors.ts`, ported onto the account client: the
|
|
8
|
+
* management token's refusals come from `getManagementScopes()` (the SDK's
|
|
9
|
+
* `ManagementTokenError`, which has a `code`), the API's from the request
|
|
10
|
+
* methods (`AccountApiError`, `status` + `code`). Pure: what the widget
|
|
11
|
+
* would need from the session is passed in. Unit-tested in `errors.test.ts`.
|
|
12
|
+
*/
|
|
13
|
+
/** The organization-member scopes (`ORGANIZATION_MEMBER_SCOPES` in `@pontive/oidc-client`). */
|
|
14
|
+
export declare const MEMBER_SCOPES: {
|
|
15
|
+
/** List members and invitations, list the assignable roles. */
|
|
16
|
+
readonly read: "pontive:org:member:read";
|
|
17
|
+
/** Remove a member, change a member's roles. */
|
|
18
|
+
readonly manage: "pontive:org:member:manage";
|
|
19
|
+
/** Send, resend and revoke invitations. */
|
|
20
|
+
readonly invite: "pontive:org:member:invite";
|
|
21
|
+
};
|
|
22
|
+
/** What the widget shows instead of its tables when it cannot show them. */
|
|
23
|
+
export interface LoadProblem {
|
|
24
|
+
message: string;
|
|
25
|
+
/** Whether trying again could help (a "Try again" button). */
|
|
26
|
+
retry: boolean;
|
|
27
|
+
/** For the app's developer, logged with `console.warn`: the setup the app is missing. */
|
|
28
|
+
hint?: string;
|
|
29
|
+
}
|
|
30
|
+
/** What `describeLoadError` needs to know about the app. */
|
|
31
|
+
export interface LoadErrorContext {
|
|
32
|
+
/** The scopes the app requests at sign-in (`client.requestedScopes()`); undefined when the client can't say. */
|
|
33
|
+
requestedScopes?: string[];
|
|
34
|
+
}
|
|
35
|
+
/** The SDK says the session changed (signed out, in again, switched) while the token was being drawn: ask again. */
|
|
36
|
+
export declare function isSessionChanged(error: unknown): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Why loading failed, for the person on the page; and, where the cause is the app's setup rather
|
|
39
|
+
* than the person, a `hint` for its developer (the widget logs it).
|
|
40
|
+
*/
|
|
41
|
+
export declare function describeLoadError(error: unknown, context?: LoadErrorContext): LoadProblem;
|
|
42
|
+
/**
|
|
43
|
+
* The refusals of a member change the server names (pontive-spec 41 §6), each with its own
|
|
44
|
+
* message: a role change of one's own, the role ceiling, roles changed meanwhile, giving / changing
|
|
45
|
+
* / removing `owner` without the right to transfer ownership, and leaving (removing oneself) an
|
|
46
|
+
* organization that doesn't let members leave.
|
|
47
|
+
*/
|
|
48
|
+
export declare const ACTION_CODES: readonly ["self_role_change", "role_ceiling", "member_roles_changed", "owner_transfer_required", "leave_disabled"];
|
|
49
|
+
/** The failure messages a member change can fall back to. */
|
|
50
|
+
export type ActionFailure = "invite_failed" | "update_roles_failed" | "remove_member_failed" | "resend_invitation_failed" | "revoke_invitation_failed";
|
|
51
|
+
/**
|
|
52
|
+
* Why an action failed, in the person's words; `fallback` when there is no better one.
|
|
53
|
+
*
|
|
54
|
+
* A 403 the widget has no message for is "You don't have permission…" only when the session holds
|
|
55
|
+
* no member write scope (`mayWrite`: the management token's manage or invite scope). Someone who
|
|
56
|
+
* can manage members was refused this one change, so they are told that (`member_change_refused`).
|
|
57
|
+
*/
|
|
58
|
+
export declare function describeActionError(error: unknown, fallback: ActionFailure, mayWrite: boolean): string;
|
|
59
|
+
/** The server refused a role change because the member's roles moved meanwhile: read them again. */
|
|
60
|
+
export declare function isRolesChanged(error: unknown): boolean;
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { nothing, PropertyDeclarations, PropertyValues, TemplateResult } from 'lit';
|
|
2
|
+
import { HostElement } from '../../core/host-element';
|
|
3
|
+
import { MessagesController } from '../../core/messages';
|
|
4
|
+
import { BrandingController } from '../block/branding';
|
|
5
|
+
import { AccountClient, AccountMembersApi, AssignableRole, OrganizationInvitation, OrganizationMember } from '../provider/account-client';
|
|
6
|
+
import { AccountController } from '../provider/account-controller';
|
|
7
|
+
import { LoadProblem } from './errors';
|
|
8
|
+
export type MemberManagementMode = "page" | "modal";
|
|
9
|
+
/** Detail of `pont2-members-invited`. */
|
|
10
|
+
export interface MembersInvitedDetail {
|
|
11
|
+
organizationId: string;
|
|
12
|
+
emails: string[];
|
|
13
|
+
roles: string[];
|
|
14
|
+
invitations: OrganizationInvitation[];
|
|
15
|
+
}
|
|
16
|
+
/** Detail of `pont2-member-roles-updated`. */
|
|
17
|
+
export interface MemberRolesUpdatedDetail {
|
|
18
|
+
organizationId: string;
|
|
19
|
+
userId: string;
|
|
20
|
+
roles: string[];
|
|
21
|
+
}
|
|
22
|
+
/** Detail of `pont2-member-removed`. */
|
|
23
|
+
export interface MemberRemovedDetail {
|
|
24
|
+
organizationId: string;
|
|
25
|
+
userId: string;
|
|
26
|
+
}
|
|
27
|
+
/** Detail of `pont2-invitation-resent` and `pont2-invitation-revoked`. */
|
|
28
|
+
export interface InvitationChangedDetail {
|
|
29
|
+
organizationId: string;
|
|
30
|
+
invitationId: string;
|
|
31
|
+
email: string;
|
|
32
|
+
/** Revoke only: whether the invitee was told. */
|
|
33
|
+
notifyInvitee?: boolean;
|
|
34
|
+
}
|
|
35
|
+
/** The page sizes offered ("Rows per page"). */
|
|
36
|
+
export declare const PAGE_SIZES: readonly [5, 10, 25];
|
|
37
|
+
/** The most addresses one invitation request takes (the legacy form's limit). */
|
|
38
|
+
export declare const MAX_INVITE_EMAILS = 10;
|
|
39
|
+
interface ListState<T> {
|
|
40
|
+
rows: T[];
|
|
41
|
+
page: number;
|
|
42
|
+
totalPages: number;
|
|
43
|
+
total: number;
|
|
44
|
+
loading: boolean;
|
|
45
|
+
search: string;
|
|
46
|
+
roles: string[];
|
|
47
|
+
}
|
|
48
|
+
type Confirm = {
|
|
49
|
+
kind: "remove";
|
|
50
|
+
member: OrganizationMember;
|
|
51
|
+
} | {
|
|
52
|
+
kind: "resend";
|
|
53
|
+
invitation: OrganizationInvitation;
|
|
54
|
+
} | {
|
|
55
|
+
kind: "revoke";
|
|
56
|
+
invitation: OrganizationInvitation;
|
|
57
|
+
};
|
|
58
|
+
type Form = {
|
|
59
|
+
kind: "invite";
|
|
60
|
+
} | {
|
|
61
|
+
kind: "roles";
|
|
62
|
+
member: OrganizationMember;
|
|
63
|
+
};
|
|
64
|
+
/** Whether `client` has the member-management part (an app's own client may not). */
|
|
65
|
+
export declare function hasMembersApi(client: AccountClient | undefined): client is AccountClient & AccountMembersApi;
|
|
66
|
+
/** "6–10 / 23": which rows of how many, numbers and punctuation only (account text takes no placeholders). */
|
|
67
|
+
export declare function pageRange(page: number, pageSize: number, total: number, locale?: string): string;
|
|
68
|
+
/**
|
|
69
|
+
* # `<pont2-member-management>`: an organization's members and invitations
|
|
70
|
+
*
|
|
71
|
+
* ```html
|
|
72
|
+
* <pont2-provider app-id="app_123" domain="auth.acme.com" api-base-url="https://api.us.pontive.com"
|
|
73
|
+
* scope="openid email profile offline_access pontive:org:member:read pontive:org:member:manage pontive:org:member:invite">
|
|
74
|
+
* <pont2-organization-switcher></pont2-organization-switcher>
|
|
75
|
+
* <pont2-member-management></pont2-member-management>
|
|
76
|
+
* </pont2-provider>
|
|
77
|
+
* ```
|
|
78
|
+
*
|
|
79
|
+
* The legacy `pont-member-management` (pontive-spec 41 §5.4–§5.6), with every
|
|
80
|
+
* rule of carry-over §5:
|
|
81
|
+
*
|
|
82
|
+
* - **Data** through the account client's members part (`listMembers`,
|
|
83
|
+
* `listInvitations`, `listAssignableRoles`, `inviteMembers`,
|
|
84
|
+
* `updateMemberRoles`, `removeMember`, `resendInvitation`,
|
|
85
|
+
* `revokeInvitation`), each drawing a **management-API token** per request
|
|
86
|
+
* (the default client does; never the session's token). A client without
|
|
87
|
+
* that part gets a "not available" state.
|
|
88
|
+
* - **Controls by scope**, from the management token (`getManagementScopes`):
|
|
89
|
+
* the lists need `…:read`; changing roles and removing need `…:manage`;
|
|
90
|
+
* inviting, resending and revoking need `…:invite`.
|
|
91
|
+
* - **The role ceiling:** roles the caller may not assign or remove are
|
|
92
|
+
* locked in the pickers; "Remove member" is hidden on a row holding one;
|
|
93
|
+
* "Manage roles" is hidden on the caller's own row and on every row when
|
|
94
|
+
* the caller may assign no role.
|
|
95
|
+
* - **Errors are said, never shown as empty tables** (`errors.ts`), with the
|
|
96
|
+
* management token's `SESSION_CHANGED` retried once; a dialog's failure is
|
|
97
|
+
* said inside the dialog.
|
|
98
|
+
* - **The organization:** `organization-id`, else the session's, read again
|
|
99
|
+
* when the session moves to another organization (the switcher's
|
|
100
|
+
* `pont2-organization-changed`, or a session change from another tab).
|
|
101
|
+
*
|
|
102
|
+
* @tag pont2-member-management
|
|
103
|
+
* @attr organization-id - the organization to manage (default: the session's)
|
|
104
|
+
* @attr mode - `page` (default) | `modal` (legacy `PAGE` / `MODAL`)
|
|
105
|
+
* @attr open - modal mode: whether the dialog is open
|
|
106
|
+
* @attr heading - overrides the title (`msg("member_management_title")`); legacy `title`
|
|
107
|
+
* @attr description - overrides the subtitle (`msg("member_management_subtitle")`)
|
|
108
|
+
* @attr page-size - rows per page: 5 (default), 10 or 25
|
|
109
|
+
* @prop client - its own `AccountClient` (default: the provider's)
|
|
110
|
+
* @fires pont2-members-invited - `{ organizationId, emails, roles, invitations }`
|
|
111
|
+
* @fires pont2-member-roles-updated - `{ organizationId, userId, roles }`
|
|
112
|
+
* @fires pont2-member-removed - `{ organizationId, userId }`
|
|
113
|
+
* @fires pont2-invitation-resent - `{ organizationId, invitationId, email }`
|
|
114
|
+
* @fires pont2-invitation-revoked - `{ organizationId, invitationId, email, notifyInvitee }`
|
|
115
|
+
*/
|
|
116
|
+
export declare class MemberManagement extends HostElement {
|
|
117
|
+
static composite: boolean;
|
|
118
|
+
static properties: PropertyDeclarations;
|
|
119
|
+
client: AccountClient | undefined;
|
|
120
|
+
organizationId: string;
|
|
121
|
+
mode: MemberManagementMode;
|
|
122
|
+
open: boolean;
|
|
123
|
+
heading: string;
|
|
124
|
+
description: string;
|
|
125
|
+
pageSize: number;
|
|
126
|
+
/** Set until the first load settles. */
|
|
127
|
+
protected loading: boolean;
|
|
128
|
+
protected problem: LoadProblem | null;
|
|
129
|
+
protected canRead: boolean;
|
|
130
|
+
protected canManage: boolean;
|
|
131
|
+
protected canInvite: boolean;
|
|
132
|
+
protected roles: AssignableRole[];
|
|
133
|
+
protected members: ListState<OrganizationMember>;
|
|
134
|
+
protected invitations: ListState<OrganizationInvitation>;
|
|
135
|
+
/** The invite or manage-roles dialog. */
|
|
136
|
+
protected form: Form | null;
|
|
137
|
+
/** The confirmation dialog (remove, resend, revoke). */
|
|
138
|
+
protected confirm: Confirm | null;
|
|
139
|
+
protected busy: boolean;
|
|
140
|
+
protected dialogError: string | null;
|
|
141
|
+
protected inviteErrors: {
|
|
142
|
+
emails?: string;
|
|
143
|
+
roles?: string;
|
|
144
|
+
};
|
|
145
|
+
protected notifyInvitee: boolean;
|
|
146
|
+
protected readonly messages: MessagesController;
|
|
147
|
+
protected readonly branding: BrandingController;
|
|
148
|
+
protected readonly account: AccountController;
|
|
149
|
+
private readonly ids;
|
|
150
|
+
/** Which load is current; a later one makes an earlier one's answer stale. */
|
|
151
|
+
private loadSeq;
|
|
152
|
+
/** The organization (and user) the current answer is for. */
|
|
153
|
+
private loadedFor;
|
|
154
|
+
private loadedBy;
|
|
155
|
+
private searchTimers;
|
|
156
|
+
/** The manage-roles picker's selection while its dialog is open. */
|
|
157
|
+
private rolesValue;
|
|
158
|
+
/** What a dialog last showed, kept while it animates closed; bumped per opening so a form starts fresh. */
|
|
159
|
+
private lastForm;
|
|
160
|
+
private lastConfirm;
|
|
161
|
+
private dialogSeq;
|
|
162
|
+
constructor();
|
|
163
|
+
connectedCallback(): void;
|
|
164
|
+
disconnectedCallback(): void;
|
|
165
|
+
/** Modal mode: opens the dialog. */
|
|
166
|
+
show(): void;
|
|
167
|
+
/** Modal mode: closes the dialog. */
|
|
168
|
+
close(): void;
|
|
169
|
+
/** Everything again: the scopes, roles, members and invitations. */
|
|
170
|
+
reload(): Promise<void>;
|
|
171
|
+
/** The organization acted on: `organization-id`, else the session's. */
|
|
172
|
+
get effectiveOrganizationId(): string;
|
|
173
|
+
private onOpenRequest;
|
|
174
|
+
private onCloseRequest;
|
|
175
|
+
/** The switcher moved the session: an explicit `organization-id` stays put. */
|
|
176
|
+
private onOrganizationChanged;
|
|
177
|
+
private whoAmI;
|
|
178
|
+
private refresh;
|
|
179
|
+
protected willUpdate(changed: PropertyValues): void;
|
|
180
|
+
protected updated(changed: PropertyValues): void;
|
|
181
|
+
private get api();
|
|
182
|
+
/** The management token first (what the session may do here), then the roles and both lists. */
|
|
183
|
+
private load;
|
|
184
|
+
private fail;
|
|
185
|
+
private params;
|
|
186
|
+
private withPage;
|
|
187
|
+
/** One list again, as filtered and paged now. A failure replaces the tables (it is said, not an empty table). */
|
|
188
|
+
private loadList;
|
|
189
|
+
private setList;
|
|
190
|
+
private onSearch;
|
|
191
|
+
private onFilter;
|
|
192
|
+
private onPage;
|
|
193
|
+
private onPageSize;
|
|
194
|
+
private get mayWrite();
|
|
195
|
+
private onMemberAction;
|
|
196
|
+
private onInvitationAction;
|
|
197
|
+
private openInvite;
|
|
198
|
+
private openRoles;
|
|
199
|
+
private openConfirm;
|
|
200
|
+
/** A dialog root changed `open` (Escape, the overlay, Cancel): follow it. */
|
|
201
|
+
private onDialogOpenChange;
|
|
202
|
+
private sendInvitations;
|
|
203
|
+
private saveRoles;
|
|
204
|
+
private rereadMember;
|
|
205
|
+
private confirmAction;
|
|
206
|
+
render(): TemplateResult<1> | typeof nothing;
|
|
207
|
+
private renderHeader;
|
|
208
|
+
private renderWatermark;
|
|
209
|
+
private renderBody;
|
|
210
|
+
private renderToolbar;
|
|
211
|
+
private renderPager;
|
|
212
|
+
private roleBadges;
|
|
213
|
+
private when;
|
|
214
|
+
private renderMembers;
|
|
215
|
+
private renderInvitations;
|
|
216
|
+
private dialogAlert;
|
|
217
|
+
private submitButton;
|
|
218
|
+
private renderForm;
|
|
219
|
+
private renderConfirm;
|
|
220
|
+
}
|
|
221
|
+
declare global {
|
|
222
|
+
interface HTMLElementTagNameMap {
|
|
223
|
+
"pont2-member-management": MemberManagement;
|
|
224
|
+
}
|
|
225
|
+
interface HTMLElementEventMap {
|
|
226
|
+
"pont2-members-invited": CustomEvent<MembersInvitedDetail>;
|
|
227
|
+
"pont2-member-roles-updated": CustomEvent<MemberRolesUpdatedDetail>;
|
|
228
|
+
"pont2-member-removed": CustomEvent<MemberRemovedDetail>;
|
|
229
|
+
"pont2-invitation-resent": CustomEvent<InvitationChangedDetail>;
|
|
230
|
+
"pont2-invitation-revoked": CustomEvent<InvitationChangedDetail>;
|
|
231
|
+
}
|
|
232
|
+
interface DocumentEventMap {
|
|
233
|
+
"pont2-open-member-management": CustomEvent<void>;
|
|
234
|
+
"pont2-close-member-management": CustomEvent<void>;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
export {};
|