@dereekb/model 13.0.7 → 13.1.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/index.cjs.js +745 -421
- package/index.cjs.js.map +1 -1
- package/index.esm.js +730 -402
- package/index.esm.js.map +1 -1
- package/package.json +3 -6
- package/src/lib/data/address/address.d.ts +36 -15
- package/src/lib/data/website/link.d.ts +38 -9
- package/src/lib/data/website/link.file.d.ts +97 -18
- package/src/lib/data/website/link.website.d.ts +254 -3
- package/src/lib/index.d.ts +1 -0
- package/src/lib/service/permission/permission.d.ts +37 -1
- package/src/lib/service/permission/role.d.ts +71 -9
- package/src/lib/service/sync/sync.entity.d.ts +32 -3
- package/src/lib/service/sync/sync.entity.synchronizer.basic.d.ts +15 -0
- package/src/lib/service/sync/sync.entity.synchronizer.d.ts +20 -0
- package/src/lib/transform/index.d.ts +0 -2
- package/src/lib/transform/transform.d.ts +54 -25
- package/src/lib/transform/transform.function.d.ts +22 -2
- package/src/lib/transform/transform.result.d.ts +10 -2
- package/src/lib/type/index.d.ts +2 -0
- package/src/lib/type/model.d.ts +20 -0
- package/src/lib/type/type.d.ts +21 -0
- package/src/lib/validator/date.d.ts +2 -4
- package/src/lib/validator/number.d.ts +2 -4
- package/src/lib/validator/phone.d.ts +6 -14
- package/src/lib/validator/unique.d.ts +11 -4
- package/src/lib/validator/url.d.ts +4 -6
- package/src/lib/transform/type.annotation.d.ts +0 -5
- package/src/lib/transform/type.d.ts +0 -6
|
@@ -1,104 +1,355 @@
|
|
|
1
1
|
import { type E164PhoneNumber, type EmailAddress, type IsolateWebsitePathFunction, type ModelKey, type WebsiteUrl } from '@dereekb/util';
|
|
2
2
|
import { type WebsiteLink, type WebsiteLinkType } from './link';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Isolates a username from a URL where the username is the first path segment after the domain.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* Strips trailing slashes and query parameters. Used by social platforms like Facebook, Instagram, and Twitter
|
|
7
|
+
* where the profile URL pattern is `https://domain.com/{username}`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* WEBSITE_LINK_ISOLATE_BASE_URL_PROFILE_ID('https://www.facebook.com/myuser');
|
|
12
|
+
* // returns 'myuser'
|
|
13
|
+
* ```
|
|
8
14
|
*/
|
|
9
15
|
export declare const WEBSITE_LINK_ISOLATE_BASE_URL_PROFILE_ID: IsolateWebsitePathFunction;
|
|
16
|
+
/**
|
|
17
|
+
* Extracts a username from either a raw username string or a full profile URL where the username is the first path segment.
|
|
18
|
+
*
|
|
19
|
+
* Optionally prepends a prefix (e.g., "@" for TikTok, "$" for Cash App).
|
|
20
|
+
*
|
|
21
|
+
* @param input - a username or full profile URL
|
|
22
|
+
* @param prefix - optional prefix to prepend to the extracted username
|
|
23
|
+
* @returns the isolated username, optionally prefixed
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* usernameFromUsernameOrWebsiteWithBaseUrlUsername('https://facebook.com/myuser');
|
|
28
|
+
* // returns 'myuser'
|
|
29
|
+
*
|
|
30
|
+
* usernameFromUsernameOrWebsiteWithBaseUrlUsername('myuser', '@');
|
|
31
|
+
* // returns '@myuser'
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
10
34
|
export declare function usernameFromUsernameOrWebsiteWithBaseUrlUsername(input: ModelKey | WebsiteUrl, prefix?: string): string;
|
|
35
|
+
/**
|
|
36
|
+
* Extracts a username from either a raw username string or a full profile URL using a custom path isolation function.
|
|
37
|
+
*
|
|
38
|
+
* Used for platforms with non-standard URL patterns (e.g., Snapchat's `/add/{username}`, YouTube's `/c/{username}`).
|
|
39
|
+
*
|
|
40
|
+
* @param input - a username or full profile URL
|
|
41
|
+
* @param isolateFn - custom function that extracts the relevant path segment from the URL
|
|
42
|
+
* @returns the isolated username
|
|
43
|
+
*/
|
|
11
44
|
export declare function usernameFromUsernameOrWebsiteWithOneOffBaseUrlUsername(input: ModelKey | WebsiteUrl, isolateFn: IsolateWebsitePathFunction): string;
|
|
45
|
+
/**
|
|
46
|
+
* Normalizes a string that may be either a plain username or a full website URL into a consistent URL format.
|
|
47
|
+
*
|
|
48
|
+
* If the input has a website domain, it is returned as-is. Otherwise, it is treated as a path and converted to an absolute slash path.
|
|
49
|
+
*
|
|
50
|
+
* @param input - a username or website URL
|
|
51
|
+
* @returns a normalized website URL
|
|
52
|
+
*/
|
|
12
53
|
export declare function usernameOrWebsiteUrlToWebsiteUrl(input: string): WebsiteUrl;
|
|
54
|
+
/**
|
|
55
|
+
* {@link WebsiteLinkType} code for generic website URLs.
|
|
56
|
+
*/
|
|
13
57
|
export declare const WEBSITE_URL_WEBSITE_LINK_TYPE = "w";
|
|
58
|
+
/**
|
|
59
|
+
* Converts a generic website URL into a {@link WebsiteLink}, stripping the HTTP/HTTPS protocol.
|
|
60
|
+
*
|
|
61
|
+
* @param input - the full website URL
|
|
62
|
+
* @returns a WebsiteLink with the protocol removed from the data
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* const link = websiteUrlToWebsiteLink('https://example.com/page');
|
|
67
|
+
* // link.t === 'w', link.d === 'example.com/page'
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
14
70
|
export declare function websiteUrlToWebsiteLink(input: WebsiteUrl): WebsiteLink;
|
|
71
|
+
/**
|
|
72
|
+
* {@link WebsiteLinkType} code for email addresses.
|
|
73
|
+
*/
|
|
15
74
|
export declare const EMAIL_URL_WEBSITE_LINK_TYPE = "e";
|
|
75
|
+
/**
|
|
76
|
+
* Converts an email address into a {@link WebsiteLink}.
|
|
77
|
+
*
|
|
78
|
+
* @param input - the email address
|
|
79
|
+
* @returns a WebsiteLink storing the email as data
|
|
80
|
+
*/
|
|
16
81
|
export declare function emailAddressToWebsiteLink(input: EmailAddress): WebsiteLink;
|
|
82
|
+
/**
|
|
83
|
+
* {@link WebsiteLinkType} code for phone numbers.
|
|
84
|
+
*/
|
|
17
85
|
export declare const PHONE_URL_WEBSITE_LINK_TYPE = "p";
|
|
86
|
+
/**
|
|
87
|
+
* Converts an E.164 phone number into a {@link WebsiteLink}.
|
|
88
|
+
*
|
|
89
|
+
* @param input - the phone number in E.164 format
|
|
90
|
+
* @returns a WebsiteLink storing the phone number as data
|
|
91
|
+
*/
|
|
18
92
|
export declare function phoneNumberToWebsiteLink(input: E164PhoneNumber): WebsiteLink;
|
|
93
|
+
/** Base URL for Facebook profiles. */
|
|
19
94
|
export declare const FACEBOOK_BASE_URL = "https://www.facebook.com";
|
|
95
|
+
/** {@link WebsiteLinkType} code for Facebook. */
|
|
20
96
|
export declare const FACEBOOK_WEBSITE_LINK_TYPE: WebsiteLinkType;
|
|
21
97
|
export type FacebookBaseUrl = typeof FACEBOOK_BASE_URL;
|
|
22
98
|
export type FacebookProfileUrl<P extends FacebookProfileId> = `${FacebookBaseUrl}/${P}`;
|
|
23
99
|
export type FacebookProfileId = string;
|
|
24
100
|
export type FacebookWebsiteLinkType = typeof FACEBOOK_WEBSITE_LINK_TYPE;
|
|
101
|
+
/**
|
|
102
|
+
* Converts a Facebook profile ID or URL into a {@link WebsiteLink}.
|
|
103
|
+
*
|
|
104
|
+
* Accepts either a raw username or a full Facebook profile URL.
|
|
105
|
+
*
|
|
106
|
+
* @param input - a Facebook profile ID or full profile URL
|
|
107
|
+
* @returns a WebsiteLink with the isolated username as data
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* facebookProfileUrlToWebsiteLink('https://www.facebook.com/myuser');
|
|
112
|
+
* // { t: 'fb', d: 'myuser' }
|
|
113
|
+
*
|
|
114
|
+
* facebookProfileUrlToWebsiteLink('myuser');
|
|
115
|
+
* // { t: 'fb', d: 'myuser' }
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
25
118
|
export declare function facebookProfileUrlToWebsiteLink(input: FacebookProfileId | WebsiteUrl): WebsiteLink;
|
|
119
|
+
/**
|
|
120
|
+
* Constructs a full Facebook profile URL from a profile ID.
|
|
121
|
+
*
|
|
122
|
+
* @param profileId - the Facebook profile ID or username
|
|
123
|
+
* @returns the full profile URL
|
|
124
|
+
*/
|
|
26
125
|
export declare function facebookProfileUrl<P extends FacebookProfileId>(profileId: P): FacebookProfileUrl<P>;
|
|
126
|
+
/** Base URL for Instagram profiles. */
|
|
27
127
|
export declare const INSTAGRAM_BASE_URL = "https://www.instagram.com";
|
|
128
|
+
/** {@link WebsiteLinkType} code for Instagram. */
|
|
28
129
|
export declare const INSTAGRAM_WEBSITE_LINK_TYPE: WebsiteLinkType;
|
|
29
130
|
export type InstagramBaseUrl = typeof INSTAGRAM_BASE_URL;
|
|
30
131
|
export type InstagramProfileUrl<P extends InstagramProfileId> = `${InstagramBaseUrl}/${P}`;
|
|
31
132
|
export type InstagramProfileId = string;
|
|
32
133
|
export type InstagramWebsiteLinkType = typeof INSTAGRAM_WEBSITE_LINK_TYPE;
|
|
134
|
+
/**
|
|
135
|
+
* Converts an Instagram profile ID or URL into a {@link WebsiteLink}.
|
|
136
|
+
*
|
|
137
|
+
* @param input - an Instagram username or full profile URL
|
|
138
|
+
* @returns a WebsiteLink with the isolated username as data
|
|
139
|
+
*/
|
|
33
140
|
export declare function instagramProfileUrlToWebsiteLink(input: InstagramProfileId | WebsiteUrl): WebsiteLink;
|
|
141
|
+
/**
|
|
142
|
+
* Constructs a full Instagram profile URL from a profile ID.
|
|
143
|
+
*
|
|
144
|
+
* @param profileId - the Instagram username
|
|
145
|
+
* @returns the full profile URL
|
|
146
|
+
*/
|
|
34
147
|
export declare function instagramProfileUrl<P extends InstagramProfileId>(profileId: P): InstagramProfileUrl<P>;
|
|
148
|
+
/** Base URL for Twitter profiles. */
|
|
35
149
|
export declare const TWITTER_BASE_URL = "https://www.twitter.com";
|
|
150
|
+
/** {@link WebsiteLinkType} code for Twitter. */
|
|
36
151
|
export declare const TWITTER_WEBSITE_LINK_TYPE: WebsiteLinkType;
|
|
37
152
|
export type TwitterBaseUrl = typeof TWITTER_BASE_URL;
|
|
38
153
|
export type TwitterProfileUrl<P extends TwitterProfileId> = `${TwitterBaseUrl}/${P}`;
|
|
39
154
|
export type TwitterProfileId = string;
|
|
40
155
|
export type TwitterWebsiteLinkType = typeof TWITTER_WEBSITE_LINK_TYPE;
|
|
156
|
+
/**
|
|
157
|
+
* Converts a Twitter profile ID or URL into a {@link WebsiteLink}.
|
|
158
|
+
*
|
|
159
|
+
* @param input - a Twitter username or full profile URL
|
|
160
|
+
* @returns a WebsiteLink with the isolated username as data
|
|
161
|
+
*/
|
|
41
162
|
export declare function twitterProfileUrlToWebsiteLink(input: TwitterProfileId | WebsiteUrl): WebsiteLink;
|
|
163
|
+
/**
|
|
164
|
+
* Constructs a full Twitter profile URL from a profile ID.
|
|
165
|
+
*
|
|
166
|
+
* @param profileId - the Twitter username
|
|
167
|
+
* @returns the full profile URL
|
|
168
|
+
*/
|
|
42
169
|
export declare function twitterProfileUrl<P extends TwitterProfileId>(profileId: P): TwitterProfileUrl<P>;
|
|
170
|
+
/** Base URL for TikTok profiles. */
|
|
43
171
|
export declare const TIKTOK_BASE_URL = "https://tiktok.com";
|
|
172
|
+
/** TikTok usernames are prefixed with "@" in URLs and stored data. */
|
|
44
173
|
export declare const TIKTOK_USERNAME_PREFIX = "@";
|
|
174
|
+
/** {@link WebsiteLinkType} code for TikTok. */
|
|
45
175
|
export declare const TIKTOK_WEBSITE_LINK_TYPE: WebsiteLinkType;
|
|
46
176
|
export type TikTokBaseUrl = typeof TIKTOK_BASE_URL;
|
|
47
177
|
export type TikTokProfileUrl<P extends TikTokProfileId> = `${TikTokBaseUrl}/@${P}`;
|
|
48
178
|
export type TikTokProfileId = string;
|
|
49
179
|
export type TikTokWebsiteLinkType = typeof TIKTOK_WEBSITE_LINK_TYPE;
|
|
180
|
+
/**
|
|
181
|
+
* Converts a TikTok profile ID or URL into a {@link WebsiteLink}.
|
|
182
|
+
*
|
|
183
|
+
* Automatically prepends the "@" prefix if not already present.
|
|
184
|
+
*
|
|
185
|
+
* @param input - a TikTok username (with or without "@") or full profile URL
|
|
186
|
+
* @returns a WebsiteLink with the "@"-prefixed username as data
|
|
187
|
+
*/
|
|
50
188
|
export declare function tiktokProfileUrlToWebsiteLink(input: TikTokProfileId | WebsiteUrl): WebsiteLink;
|
|
189
|
+
/**
|
|
190
|
+
* Constructs a full TikTok profile URL from a profile ID.
|
|
191
|
+
*
|
|
192
|
+
* @param profileId - the TikTok username (without "@" prefix)
|
|
193
|
+
* @returns the full profile URL with "@" prefix
|
|
194
|
+
*/
|
|
51
195
|
export declare function tiktokProfileUrl<P extends TikTokProfileId>(profileId: P): TikTokProfileUrl<P>;
|
|
196
|
+
/** Base URL for Snapchat profiles. */
|
|
52
197
|
export declare const SNAPCHAT_BASE_URL = "https://snapchat.com";
|
|
198
|
+
/** {@link WebsiteLinkType} code for Snapchat. */
|
|
53
199
|
export declare const SNAPCHAT_WEBSITE_LINK_TYPE: WebsiteLinkType;
|
|
54
200
|
export type SnapchatBaseUrl = typeof SNAPCHAT_BASE_URL;
|
|
55
201
|
export type SnapchatProfileUrl<P extends SnapchatProfileId> = `${SnapchatBaseUrl}/add/${P}`;
|
|
56
202
|
export type SnapchatProfileId = string;
|
|
57
203
|
export type SnapchatWebsiteLinkType = typeof SNAPCHAT_WEBSITE_LINK_TYPE;
|
|
204
|
+
/**
|
|
205
|
+
* Isolates a Snapchat username from a URL, ignoring the `/add/` base path segment.
|
|
206
|
+
*/
|
|
58
207
|
export declare const SNAPCHAT_WEBSITE_LINK_ISOLATE_PROFILE_ID: IsolateWebsitePathFunction;
|
|
208
|
+
/**
|
|
209
|
+
* Converts a Snapchat profile ID or URL into a {@link WebsiteLink}.
|
|
210
|
+
*
|
|
211
|
+
* Handles Snapchat's `/add/{username}` URL pattern.
|
|
212
|
+
*
|
|
213
|
+
* @param input - a Snapchat username or full profile URL
|
|
214
|
+
* @returns a WebsiteLink with the isolated username as data
|
|
215
|
+
*/
|
|
59
216
|
export declare function snapchatProfileUrlToWebsiteLink(input: SnapchatProfileId | WebsiteUrl): WebsiteLink;
|
|
217
|
+
/**
|
|
218
|
+
* Constructs a full Snapchat profile URL from a profile ID.
|
|
219
|
+
*
|
|
220
|
+
* @param profileId - the Snapchat username
|
|
221
|
+
* @returns the full profile URL with `/add/` path
|
|
222
|
+
*/
|
|
60
223
|
export declare function snapchatProfileUrl<P extends SnapchatProfileId>(profileId: P): SnapchatProfileUrl<P>;
|
|
224
|
+
/** Base URL for YouTube channels. */
|
|
61
225
|
export declare const YOUTUBE_BASE_URL = "https://youtube.com";
|
|
226
|
+
/** {@link WebsiteLinkType} code for YouTube. */
|
|
62
227
|
export declare const YOUTUBE_WEBSITE_LINK_TYPE: WebsiteLinkType;
|
|
63
228
|
export type YouTubeBaseUrl = typeof YOUTUBE_BASE_URL;
|
|
64
229
|
export type YouTubeProfileUrl<P extends YouTubeProfileId> = `${YouTubeBaseUrl}/c/${P}`;
|
|
65
230
|
export type YouTubeProfileId = string;
|
|
66
231
|
export type YouTubeWebsiteLinkType = typeof YOUTUBE_WEBSITE_LINK_TYPE;
|
|
232
|
+
/**
|
|
233
|
+
* Isolates a YouTube channel name from a URL, ignoring the `/c/` base path segment.
|
|
234
|
+
*/
|
|
67
235
|
export declare const YOUTUBE_WEBSITE_LINK_ISOLATE_PROFILE_ID: IsolateWebsitePathFunction;
|
|
236
|
+
/**
|
|
237
|
+
* Converts a YouTube channel ID or URL into a {@link WebsiteLink}.
|
|
238
|
+
*
|
|
239
|
+
* Handles YouTube's `/c/{channel}` URL pattern.
|
|
240
|
+
*
|
|
241
|
+
* @param input - a YouTube channel name or full channel URL
|
|
242
|
+
* @returns a WebsiteLink with the isolated channel name as data
|
|
243
|
+
*/
|
|
68
244
|
export declare function youtubeProfileUrlToWebsiteLink(input: YouTubeProfileId | WebsiteUrl): WebsiteLink;
|
|
245
|
+
/**
|
|
246
|
+
* Constructs a full YouTube channel URL from a profile ID.
|
|
247
|
+
*
|
|
248
|
+
* @param profileId - the YouTube channel name
|
|
249
|
+
* @returns the full channel URL with `/c/` path
|
|
250
|
+
*/
|
|
69
251
|
export declare function youtubeProfileUrl<P extends YouTubeProfileId>(profileId: P): YouTubeProfileUrl<P>;
|
|
252
|
+
/** Base URL for PayPal.me profiles. */
|
|
70
253
|
export declare const PAYPAL_BASE_URL = "https://paypal.me";
|
|
254
|
+
/** {@link WebsiteLinkType} code for PayPal. */
|
|
71
255
|
export declare const PAYPAL_WEBSITE_LINK_TYPE: WebsiteLinkType;
|
|
72
256
|
export type PayPalBaseUrl = typeof PAYPAL_BASE_URL;
|
|
73
257
|
export type PayPalProfileUrl<P extends PayPalProfileId> = `${PayPalBaseUrl}/${P}`;
|
|
74
258
|
export type PayPalProfileId = string;
|
|
75
259
|
export type PayPalWebsiteLinkType = typeof PAYPAL_WEBSITE_LINK_TYPE;
|
|
260
|
+
/**
|
|
261
|
+
* Converts a PayPal profile ID or URL into a {@link WebsiteLink}.
|
|
262
|
+
*
|
|
263
|
+
* @param input - a PayPal username or full PayPal.me URL
|
|
264
|
+
* @returns a WebsiteLink with the isolated username as data
|
|
265
|
+
*/
|
|
76
266
|
export declare function paypalProfileUrlToWebsiteLink(input: PayPalProfileId | WebsiteUrl): WebsiteLink;
|
|
267
|
+
/**
|
|
268
|
+
* Constructs a full PayPal.me profile URL from a profile ID.
|
|
269
|
+
*
|
|
270
|
+
* @param profileId - the PayPal username
|
|
271
|
+
* @returns the full PayPal.me URL
|
|
272
|
+
*/
|
|
77
273
|
export declare function paypalProfileUrl<P extends PayPalProfileId>(profileId: P): PayPalProfileUrl<P>;
|
|
274
|
+
/** Base URL for Cash App profiles. */
|
|
78
275
|
export declare const CASHAPP_BASE_URL = "https://cash.app";
|
|
276
|
+
/** Cash App usernames are prefixed with "$" (cashtag). */
|
|
79
277
|
export declare const CASHAPP_USERNAME_PREFIX = "$";
|
|
278
|
+
/** {@link WebsiteLinkType} code for Cash App. */
|
|
80
279
|
export declare const CASHAPP_WEBSITE_LINK_TYPE: WebsiteLinkType;
|
|
81
280
|
export type CashappBaseUrl = typeof CASHAPP_BASE_URL;
|
|
82
281
|
export type CashappProfileUrl<P extends CashappProfileId> = `${CashappBaseUrl}/$${P}`;
|
|
83
282
|
export type CashappProfileId = string;
|
|
84
283
|
export type CashappWebsiteLinkType = typeof CASHAPP_WEBSITE_LINK_TYPE;
|
|
284
|
+
/**
|
|
285
|
+
* Converts a Cash App profile ID or URL into a {@link WebsiteLink}.
|
|
286
|
+
*
|
|
287
|
+
* Automatically prepends the "$" prefix if not already present.
|
|
288
|
+
*
|
|
289
|
+
* @param input - a Cash App username (with or without "$") or full profile URL
|
|
290
|
+
* @returns a WebsiteLink with the "$"-prefixed username as data
|
|
291
|
+
*/
|
|
85
292
|
export declare function cashappProfileUrlToWebsiteLink(input: CashappProfileId | WebsiteUrl): WebsiteLink;
|
|
293
|
+
/**
|
|
294
|
+
* Constructs a full Cash App profile URL from a profile ID.
|
|
295
|
+
*
|
|
296
|
+
* @param profileId - the Cash App username (without "$" prefix)
|
|
297
|
+
* @returns the full Cash App URL with "$" prefix
|
|
298
|
+
*/
|
|
86
299
|
export declare function cashappProfileUrl<P extends CashappProfileId>(profileId: P): CashappProfileUrl<P>;
|
|
300
|
+
/** Base URL for Venmo profiles. */
|
|
87
301
|
export declare const VENMO_BASE_URL = "https://account.venmo.com";
|
|
302
|
+
/** {@link WebsiteLinkType} code for Venmo. */
|
|
88
303
|
export declare const VENMO_WEBSITE_LINK_TYPE: WebsiteLinkType;
|
|
89
304
|
export type VenmoBaseUrl = typeof VENMO_BASE_URL;
|
|
90
305
|
export type VenmoProfileUrl<P extends VenmoProfileId> = `${VenmoBaseUrl}/u/${P}`;
|
|
91
306
|
export type VenmoProfileId = string;
|
|
92
307
|
export type VenmoWebsiteLinkType = typeof VENMO_WEBSITE_LINK_TYPE;
|
|
308
|
+
/**
|
|
309
|
+
* Isolates a Venmo username from a URL, ignoring the `/u/` base path segment.
|
|
310
|
+
*/
|
|
93
311
|
export declare const VENMO_WEBSITE_LINK_ISOLATE_PROFILE_ID: IsolateWebsitePathFunction;
|
|
312
|
+
/**
|
|
313
|
+
* Converts a Venmo profile ID or URL into a {@link WebsiteLink}.
|
|
314
|
+
*
|
|
315
|
+
* Handles Venmo's `/u/{username}` URL pattern.
|
|
316
|
+
*
|
|
317
|
+
* @param input - a Venmo username or full profile URL
|
|
318
|
+
* @returns a WebsiteLink with the isolated username as data
|
|
319
|
+
*/
|
|
94
320
|
export declare function venmoProfileUrlToWebsiteLink(input: VenmoProfileId | WebsiteUrl): WebsiteLink;
|
|
321
|
+
/**
|
|
322
|
+
* Constructs a full Venmo profile URL from a profile ID.
|
|
323
|
+
*
|
|
324
|
+
* @param profileId - the Venmo username
|
|
325
|
+
* @returns the full profile URL with `/u/` path
|
|
326
|
+
*/
|
|
95
327
|
export declare function venmoProfileUrl<P extends VenmoProfileId>(profileId: P): VenmoProfileUrl<P>;
|
|
328
|
+
/** Base URL for Spotify profiles. */
|
|
96
329
|
export declare const SPOTIFY_BASE_URL = "https://open.spotify.com/";
|
|
330
|
+
/** {@link WebsiteLinkType} code for Spotify. */
|
|
97
331
|
export declare const SPOTIFY_WEBSITE_LINK_TYPE: WebsiteLinkType;
|
|
98
332
|
export type SpotifyBaseUrl = typeof SPOTIFY_BASE_URL;
|
|
99
333
|
export type SpotifyProfileUrl<P extends SpotifyProfileId> = `${SpotifyBaseUrl}/user/${P}`;
|
|
100
334
|
export type SpotifyProfileId = string;
|
|
101
335
|
export type SpotifyWebsiteLinkType = typeof SPOTIFY_WEBSITE_LINK_TYPE;
|
|
336
|
+
/**
|
|
337
|
+
* Isolates a Spotify username from a URL, ignoring the `/user/` base path segment.
|
|
338
|
+
*/
|
|
102
339
|
export declare const SPOTIFY_WEBSITE_LINK_ISOLATE_PROFILE_ID: IsolateWebsitePathFunction;
|
|
340
|
+
/**
|
|
341
|
+
* Converts a Spotify profile ID or URL into a {@link WebsiteLink}.
|
|
342
|
+
*
|
|
343
|
+
* Handles Spotify's `/user/{username}` URL pattern.
|
|
344
|
+
*
|
|
345
|
+
* @param input - a Spotify username or full profile URL
|
|
346
|
+
* @returns a WebsiteLink with the isolated username as data
|
|
347
|
+
*/
|
|
103
348
|
export declare function spotifyProfileUrlToWebsiteLink(input: SpotifyProfileId | WebsiteUrl): WebsiteLink;
|
|
349
|
+
/**
|
|
350
|
+
* Constructs a full Spotify profile URL from a profile ID.
|
|
351
|
+
*
|
|
352
|
+
* @param profileId - the Spotify username
|
|
353
|
+
* @returns the full profile URL with `/user/` path
|
|
354
|
+
*/
|
|
104
355
|
export declare function spotifyProfileUrl<P extends SpotifyProfileId>(profileId: P): SpotifyProfileUrl<P>;
|
package/src/lib/index.d.ts
CHANGED
|
@@ -1,13 +1,49 @@
|
|
|
1
1
|
import { type Maybe } from '@dereekb/util';
|
|
2
2
|
import { type GrantedRoleMap } from './role';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Container that associates a model's data, the context in which roles were evaluated, and the resulting granted role map.
|
|
5
|
+
*
|
|
6
|
+
* Returned by permission services after evaluating what roles a given context has for a specific model.
|
|
5
7
|
*/
|
|
6
8
|
export interface ContextGrantedModelRoles<O, C = unknown, R extends string = string> {
|
|
7
9
|
readonly data: Maybe<O>;
|
|
8
10
|
readonly context: C;
|
|
9
11
|
readonly roleMap: GrantedRoleMap<R>;
|
|
10
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Creates a {@link ContextGrantedModelRoles} with a no-access role map, indicating the context has no permissions.
|
|
15
|
+
*
|
|
16
|
+
* @param context - the context that was evaluated
|
|
17
|
+
* @param data - optional model data, if it was loaded
|
|
18
|
+
* @returns a ContextGrantedModelRoles with no access
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const result = noAccessContextGrantedModelRoles(userContext);
|
|
23
|
+
* // result.roleMap contains the no-access marker
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
11
26
|
export declare function noAccessContextGrantedModelRoles<O, C = unknown, R extends string = string>(context: C, data?: Maybe<O>): ContextGrantedModelRoles<O, C, R>;
|
|
27
|
+
/**
|
|
28
|
+
* Creates a {@link ContextGrantedModelRoles} with a full-access role map, granting all permissions.
|
|
29
|
+
*
|
|
30
|
+
* @param context - the context that was evaluated
|
|
31
|
+
* @param data - optional model data
|
|
32
|
+
* @returns a ContextGrantedModelRoles with full access
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* const result = fullAccessGrantedModelRoles(adminContext, modelData);
|
|
37
|
+
* // result.roleMap contains the full-access marker
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
12
40
|
export declare function fullAccessGrantedModelRoles<O, C = unknown, R extends string = string>(context: C, data?: Maybe<O>): ContextGrantedModelRoles<O, C, R>;
|
|
41
|
+
/**
|
|
42
|
+
* Creates a {@link ContextGrantedModelRoles} with the given role map, data, and context.
|
|
43
|
+
*
|
|
44
|
+
* @param context - the context that was evaluated
|
|
45
|
+
* @param data - the model data, if loaded
|
|
46
|
+
* @param roles - the granted role map
|
|
47
|
+
* @returns a ContextGrantedModelRoles combining all inputs
|
|
48
|
+
*/
|
|
13
49
|
export declare function contextGrantedModelRoles<O, C = unknown, R extends string = string>(context: C, data: Maybe<O>, roles: GrantedRoleMap<R>): ContextGrantedModelRoles<O, C, R>;
|
|
@@ -19,10 +19,17 @@ export declare const GRANTED_OWNER_ROLE_KEY = "owner";
|
|
|
19
19
|
export type GrantedAdminRole = typeof GRANTED_ADMIN_ROLE_KEY;
|
|
20
20
|
export declare const GRANTED_ADMIN_ROLE_KEY = "admin";
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
22
|
+
* Checks whether the given role represents an admin-level permission (either "admin" or "owner").
|
|
23
23
|
*
|
|
24
|
-
* @param role
|
|
25
|
-
* @returns
|
|
24
|
+
* @param role - the role to check
|
|
25
|
+
* @returns true if the role is an admin or owner role
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* isGrantedAdminLevelRole('admin'); // true
|
|
30
|
+
* isGrantedAdminLevelRole('owner'); // true
|
|
31
|
+
* isGrantedAdminLevelRole('read'); // false
|
|
32
|
+
* ```
|
|
26
33
|
*/
|
|
27
34
|
export declare function isGrantedAdminLevelRole(role: GrantedRole): boolean;
|
|
28
35
|
/**
|
|
@@ -51,12 +58,46 @@ export type NoAccessGrantedRole = typeof NO_ACCESS_ROLE_KEY;
|
|
|
51
58
|
export type NoAccessRoleMap = {
|
|
52
59
|
[NO_ACCESS_ROLE_KEY]: true;
|
|
53
60
|
};
|
|
61
|
+
/**
|
|
62
|
+
* Creates a {@link GrantedRoleMap} that explicitly denies all access.
|
|
63
|
+
*
|
|
64
|
+
* @returns a role map with only the no-access marker set
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* const map = noAccessRoleMap();
|
|
69
|
+
* isNoAccessRoleMap(map); // true
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
54
72
|
export declare function noAccessRoleMap<R extends string = string>(): GrantedRoleMap<R>;
|
|
73
|
+
/**
|
|
74
|
+
* Type guard that checks whether a role map is a no-access map.
|
|
75
|
+
*
|
|
76
|
+
* @param input - the role map to check
|
|
77
|
+
* @returns true if the map has the no-access marker
|
|
78
|
+
*/
|
|
55
79
|
export declare function isNoAccessRoleMap<R extends string = string>(input: GrantedRoleMap<R> | NoAccessRoleMap): input is NoAccessRoleMap;
|
|
56
80
|
export type FullAccessRoleMap = {
|
|
57
81
|
[FULL_ACCESS_ROLE_KEY]: true;
|
|
58
82
|
};
|
|
83
|
+
/**
|
|
84
|
+
* Creates a {@link GrantedRoleMap} that grants full access to all roles.
|
|
85
|
+
*
|
|
86
|
+
* @returns a role map with the full-access marker set
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```typescript
|
|
90
|
+
* const map = fullAccessRoleMap();
|
|
91
|
+
* isFullAccessRoleMap(map); // true
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
59
94
|
export declare function fullAccessRoleMap<R extends string = string>(): GrantedRoleMap<R>;
|
|
95
|
+
/**
|
|
96
|
+
* Type guard that checks whether a role map is a full-access map.
|
|
97
|
+
*
|
|
98
|
+
* @param input - the role map to check
|
|
99
|
+
* @returns true if the map has the full-access marker
|
|
100
|
+
*/
|
|
60
101
|
export declare function isFullAccessRoleMap<R extends string = string>(input: GrantedRoleMap<R> | FullAccessRoleMap): input is FullAccessRoleMap;
|
|
61
102
|
export type GrantedRoleMap<R extends GrantedRole = string> = NoAccessRoleMap | FullAccessRoleMap | GrantedRoleKeysMap<R>;
|
|
62
103
|
export type GrantedRoleKeysMap<R extends GrantedRole = string> = {
|
|
@@ -102,10 +143,24 @@ export interface GrantedRoleMapReader<R extends GrantedRole = GrantedRole> {
|
|
|
102
143
|
containsRoles(setIncludes: SetIncludesMode, roles: ArrayOrValue<R> | IterableOrValue<R>): boolean;
|
|
103
144
|
}
|
|
104
145
|
/**
|
|
105
|
-
* Creates a GrantedRoleMapReader.
|
|
146
|
+
* Creates a {@link GrantedRoleMapReader} for querying granted roles from a role map.
|
|
106
147
|
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
148
|
+
* The reader handles full-access and no-access maps as special cases, and provides methods
|
|
149
|
+
* for checking individual roles or sets of roles.
|
|
150
|
+
*
|
|
151
|
+
* @param map - the granted role map to read from
|
|
152
|
+
* @returns a reader instance for querying the map
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* ```typescript
|
|
156
|
+
* const roleMap: GrantedRoleMap = { read: true, first: true };
|
|
157
|
+
* const reader = grantedRoleMapReader(roleMap);
|
|
158
|
+
*
|
|
159
|
+
* reader.hasRole('read'); // true
|
|
160
|
+
* reader.hasRole('delete'); // false
|
|
161
|
+
* reader.containsRoles('any', ['read']); // true
|
|
162
|
+
* reader.containsRoles('all', ['read', 'delete']); // false
|
|
163
|
+
* ```
|
|
109
164
|
*/
|
|
110
165
|
export declare function grantedRoleMapReader<R extends GrantedRole = string>(map: GrantedRoleMap<R>): GrantedRoleMapReader<R>;
|
|
111
166
|
export declare class GrantedRoleMapReaderInstance<R extends GrantedRole = string> implements GrantedRoleMapReader<R> {
|
|
@@ -120,9 +175,16 @@ export declare class GrantedRoleMapReaderInstance<R extends GrantedRole = string
|
|
|
120
175
|
containsEachRole(roles: ArrayOrValue<R>): boolean;
|
|
121
176
|
}
|
|
122
177
|
/**
|
|
123
|
-
* Converts
|
|
178
|
+
* Converts an array of role strings into a {@link GrantedRoleKeysMap} where each role is mapped to the given boolean value.
|
|
179
|
+
*
|
|
180
|
+
* @param roles - the role strings to include
|
|
181
|
+
* @param value - the boolean value to assign to each role (defaults to true)
|
|
182
|
+
* @returns a map of roles to boolean values
|
|
124
183
|
*
|
|
125
|
-
* @
|
|
126
|
-
*
|
|
184
|
+
* @example
|
|
185
|
+
* ```typescript
|
|
186
|
+
* const map = grantedRoleKeysMapFromArray(['read', 'update']);
|
|
187
|
+
* // { read: true, update: true }
|
|
188
|
+
* ```
|
|
127
189
|
*/
|
|
128
190
|
export declare function grantedRoleKeysMapFromArray<R extends GrantedRole = string>(roles: R[], value?: boolean): GrantedRoleKeysMap<R>;
|
|
@@ -23,6 +23,22 @@ export interface SyncEntityCommonTypeIdPair {
|
|
|
23
23
|
}
|
|
24
24
|
export type SyncEntityCommonTypeIdPairFactoryInput = SyncEntityCommonTypeIdPair | SyncEntityCommonId;
|
|
25
25
|
export type SyncEntityCommonTypeIdPairFactory = (input: SyncEntityCommonTypeIdPairFactoryInput) => SyncEntityCommonTypeIdPair;
|
|
26
|
+
/**
|
|
27
|
+
* Creates a factory that normalizes a {@link SyncEntityCommonTypeIdPairFactoryInput} into a full {@link SyncEntityCommonTypeIdPair}.
|
|
28
|
+
*
|
|
29
|
+
* If the input is a string, it is treated as a commonId and paired with the given commonType.
|
|
30
|
+
* If the input is already a pair, it is returned as-is.
|
|
31
|
+
*
|
|
32
|
+
* @param commonType - the default common type to use when input is a plain string
|
|
33
|
+
* @returns a factory function that produces SyncEntityCommonTypeIdPair instances
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* const factory = syncEntityCommonTypeIdPairFactory('user');
|
|
38
|
+
* factory('abc123'); // { commonType: 'user', commonId: 'abc123' }
|
|
39
|
+
* factory({ commonType: 'user', commonId: 'abc123' }); // passed through as-is
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
26
42
|
export declare function syncEntityCommonTypeIdPairFactory(commonType: SyncEntityCommonType): SyncEntityCommonTypeIdPairFactory;
|
|
27
43
|
/**
|
|
28
44
|
* Represents a single entity that can be synchronized between different servers.
|
|
@@ -55,9 +71,22 @@ export interface SyncEntityFactoryConfig {
|
|
|
55
71
|
*/
|
|
56
72
|
export type SyncEntityFactory = FactoryWithRequiredInput<SyncEntity, SyncEntityCommonTypeIdPair>;
|
|
57
73
|
/**
|
|
58
|
-
* Creates a SyncEntityFactory.
|
|
74
|
+
* Creates a {@link SyncEntityFactory} that produces {@link SyncEntity} instances from a common type/id pair.
|
|
75
|
+
*
|
|
76
|
+
* The factory attaches the configured source info and optionally transforms the commonId into an entity id
|
|
77
|
+
* using the provided idFactory (defaults to identity).
|
|
78
|
+
*
|
|
79
|
+
* @param config - source info and optional id factory
|
|
80
|
+
* @returns a factory that creates SyncEntity instances
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* const factory = syncEntityFactory({
|
|
85
|
+
* sourceInfo: { id: 'api', name: 'External API' }
|
|
86
|
+
* });
|
|
59
87
|
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
88
|
+
* const entity = factory({ commonType: 'user', commonId: 'abc123' });
|
|
89
|
+
* // entity.id === 'abc123', entity.sourceInfo.id === 'api'
|
|
90
|
+
* ```
|
|
62
91
|
*/
|
|
63
92
|
export declare function syncEntityFactory(config: SyncEntityFactoryConfig): SyncEntityFactory;
|
|
@@ -114,4 +114,19 @@ export interface BasicSyncEntityCommonTypeSynchronizerConfig {
|
|
|
114
114
|
*/
|
|
115
115
|
readonly entitySourceContextLoader: BasicSyncEntityCommonTypeSynchronizerEntitySourceContextLoader;
|
|
116
116
|
}
|
|
117
|
+
/**
|
|
118
|
+
* Creates a {@link BasicSyncEntityCommonTypeSynchronizer} that orchestrates synchronization across multiple sources
|
|
119
|
+
* for a specific entity common type.
|
|
120
|
+
*
|
|
121
|
+
* The synchronizer follows a primary/secondary/replica flow:
|
|
122
|
+
* 1. The primary source is synchronized first (exactly one required).
|
|
123
|
+
* 2. Secondary sources are synchronized sequentially; if a secondary reports deletion while primary did not, the sync restarts once.
|
|
124
|
+
* 3. Replica sources are synchronized concurrently (up to 3 in parallel).
|
|
125
|
+
*
|
|
126
|
+
* @param config - common type, sources, and context loader
|
|
127
|
+
* @returns a synchronizer for the configured common type
|
|
128
|
+
* @throws {NoPrimarySyncSourceError} when no primary source is found
|
|
129
|
+
* @throws {MultiplePrimarySyncSourceError} when more than one primary source is found
|
|
130
|
+
* @throws {SynchronizationFailedError} when primary or secondary sync returns failed/error
|
|
131
|
+
*/
|
|
117
132
|
export declare function basicSyncEntityCommonTypeSynchronizerInstanceFactory(config: BasicSyncEntityCommonTypeSynchronizerConfig): BasicSyncEntityCommonTypeSynchronizer;
|
|
@@ -50,6 +50,26 @@ export interface SyncEntitySynchronizer {
|
|
|
50
50
|
export interface SyncEntitySynchronizerConfig {
|
|
51
51
|
readonly commonTypeSynchronizers: SyncEntityCommonTypeSynchronizer[];
|
|
52
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Creates a {@link SyncEntitySynchronizer} from the given configuration.
|
|
55
|
+
*
|
|
56
|
+
* Registers common type synchronizers and provides lookup by common type. Throws
|
|
57
|
+
* {@link UnregisteredSyncEntityCommonTypeError} if an unregistered common type is requested.
|
|
58
|
+
*
|
|
59
|
+
* @param config - contains the list of common type synchronizers to register
|
|
60
|
+
* @returns a synchronizer that delegates to the appropriate common type synchronizer
|
|
61
|
+
* @throws {UnregisteredSyncEntityCommonTypeError} when requesting an unregistered common type
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* const synchronizer = syncEntitySynchronizer({
|
|
66
|
+
* commonTypeSynchronizers: [userSynchronizer, orderSynchronizer]
|
|
67
|
+
* });
|
|
68
|
+
*
|
|
69
|
+
* const instance = await synchronizer.synchronizeInstance({ commonType: 'user', commonId: '123' });
|
|
70
|
+
* const result = await instance.synchronize();
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
53
73
|
export declare function syncEntitySynchronizer(config: SyncEntitySynchronizerConfig): SyncEntitySynchronizer;
|
|
54
74
|
export type SyncEntityCommonTypeSynchronizerInstanceInput = SyncEntityCommonTypeIdPairFactoryInput;
|
|
55
75
|
export type SyncEntityCommonTypeSynchronizerInstanceFunction = (input: SyncEntityCommonTypeSynchronizerInstanceInput) => Promise<SyncEntityCommonTypeSynchronizerInstance>;
|