@nascentdigital/funnel-services 4.4.18
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/README.md +7 -0
- package/dist/analytics/Analytics.d.ts +11 -0
- package/dist/analytics/Analytics.js +48 -0
- package/dist/analytics/GoogleAnalytics.d.ts +16 -0
- package/dist/analytics/GoogleAnalytics.js +92 -0
- package/dist/analytics/index.d.ts +2 -0
- package/dist/analytics/index.js +18 -0
- package/dist/api/ApiClient.d.ts +18 -0
- package/dist/api/ApiClient.js +43 -0
- package/dist/api/index.d.ts +1 -0
- package/dist/api/index.js +17 -0
- package/dist/captcha/MockHumanVerification.d.ts +4 -0
- package/dist/captcha/MockHumanVerification.js +11 -0
- package/dist/captcha/RecaptchaAdapter.d.ts +18 -0
- package/dist/captcha/RecaptchaAdapter.js +43 -0
- package/dist/captcha/errors/CaptchaError.d.ts +12 -0
- package/dist/captcha/errors/CaptchaError.js +19 -0
- package/dist/captcha/errors/CaptchaErrors.d.ts +8 -0
- package/dist/captcha/errors/CaptchaErrors.js +31 -0
- package/dist/captcha/errors/CaptchaVerificationError.d.ts +5 -0
- package/dist/captcha/errors/CaptchaVerificationError.js +11 -0
- package/dist/captcha/errors/index.d.ts +3 -0
- package/dist/captcha/errors/index.js +24 -0
- package/dist/captcha/index.d.ts +3 -0
- package/dist/captcha/index.js +19 -0
- package/dist/consent/ConsentActions.d.ts +5 -0
- package/dist/consent/ConsentActions.js +41 -0
- package/dist/consent/ConsentData.d.ts +13 -0
- package/dist/consent/ConsentData.js +35 -0
- package/dist/consent/CookieConsent.d.ts +19 -0
- package/dist/consent/CookieConsent.js +161 -0
- package/dist/consent/index.d.ts +2 -0
- package/dist/consent/index.js +18 -0
- package/dist/identity/actions.d.ts +4 -0
- package/dist/identity/actions.js +22 -0
- package/dist/identity/api/Identity.d.ts +11 -0
- package/dist/identity/api/Identity.js +2 -0
- package/dist/identity/api/IdentityService.d.ts +9 -0
- package/dist/identity/api/IdentityService.js +27 -0
- package/dist/identity/api/Profile.d.ts +10 -0
- package/dist/identity/api/Profile.js +2 -0
- package/dist/identity/api/ProfileService.d.ts +12 -0
- package/dist/identity/api/ProfileService.js +27 -0
- package/dist/identity/api/index.d.ts +4 -0
- package/dist/identity/api/index.js +20 -0
- package/dist/identity/auth0/Auth0IdentityService.d.ts +9 -0
- package/dist/identity/auth0/Auth0IdentityService.js +27 -0
- package/dist/identity/auth0/Auth0Profile.d.ts +30 -0
- package/dist/identity/auth0/Auth0Profile.js +57 -0
- package/dist/identity/auth0/Auth0ProfileService.d.ts +21 -0
- package/dist/identity/auth0/Auth0ProfileService.js +69 -0
- package/dist/identity/auth0/index.d.ts +2 -0
- package/dist/identity/auth0/index.js +18 -0
- package/dist/identity/client/ClientProfile.d.ts +27 -0
- package/dist/identity/client/ClientProfile.js +31 -0
- package/dist/identity/client/IdentityContainer.d.ts +12 -0
- package/dist/identity/client/IdentityContainer.js +23 -0
- package/dist/identity/client/IdentityContext.d.ts +8 -0
- package/dist/identity/client/IdentityContext.js +6 -0
- package/dist/identity/client/index.d.ts +3 -0
- package/dist/identity/client/index.js +19 -0
- package/dist/identity/client/useIdentity.d.ts +2 -0
- package/dist/identity/client/useIdentity.js +9 -0
- package/dist/identity/client/useProfile.d.ts +2 -0
- package/dist/identity/client/useProfile.js +9 -0
- package/dist/identity/index.d.ts +3 -0
- package/dist/identity/index.js +19 -0
- package/dist/identity/server/IdentityProvider.d.ts +5 -0
- package/dist/identity/server/IdentityProvider.js +29 -0
- package/dist/identity/server/index.d.ts +1 -0
- package/dist/identity/server/index.js +17 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +21 -0
- package/dist/ip/index.d.ts +1 -0
- package/dist/ip/index.js +17 -0
- package/dist/ip/useIpAddress.d.ts +1 -0
- package/dist/ip/useIpAddress.js +69 -0
- package/dist/leadgen/AbstractPipeDriveAdapter.d.ts +27 -0
- package/dist/leadgen/AbstractPipeDriveAdapter.js +43 -0
- package/dist/leadgen/ConfigPipeDriveAdapter.d.ts +18 -0
- package/dist/leadgen/ConfigPipeDriveAdapter.js +60 -0
- package/dist/leadgen/MockPipedrive.d.ts +16 -0
- package/dist/leadgen/MockPipedrive.js +32 -0
- package/dist/leadgen/PipedriveClient.d.ts +40 -0
- package/dist/leadgen/PipedriveClient.js +223 -0
- package/dist/leadgen/index.d.ts +4 -0
- package/dist/leadgen/index.js +20 -0
- package/dist/server.d.ts +4 -0
- package/dist/server.js +20 -0
- package/package.json +52 -0
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
"use strict";
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
+
var ownKeys = function(o) {
|
|
21
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
+
var ar = [];
|
|
23
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
+
return ar;
|
|
25
|
+
};
|
|
26
|
+
return ownKeys(o);
|
|
27
|
+
};
|
|
28
|
+
return function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
36
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
exports.CookieConsent = CookieConsent;
|
|
38
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
39
|
+
const funnel_core_1 = require("@nascentdigital/funnel-core");
|
|
40
|
+
const client_1 = require("@nascentdigital/funnel-ui/client");
|
|
41
|
+
const react_1 = require("react");
|
|
42
|
+
const rxjs_1 = require("rxjs");
|
|
43
|
+
const Consent = __importStar(require("vanilla-cookieconsent"));
|
|
44
|
+
const ip_1 = require("../ip");
|
|
45
|
+
// components
|
|
46
|
+
function CookieConsent({ consentAction, copy }) {
|
|
47
|
+
// bind hooks
|
|
48
|
+
const ip = (0, ip_1.useIpAddress)();
|
|
49
|
+
const language = (0, client_1.useLanguage)();
|
|
50
|
+
// bind consent plugin
|
|
51
|
+
(0, react_1.useEffect)(() => {
|
|
52
|
+
// skip if ip isn't resolved
|
|
53
|
+
if (ip === undefined) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
// mount
|
|
57
|
+
const mount = async () => {
|
|
58
|
+
console.debug('[CookieConsent] mounting plugin');
|
|
59
|
+
await Consent.run(createConsentConfig({ ip, consentAction, copy, language }));
|
|
60
|
+
};
|
|
61
|
+
mount().catch(console.error);
|
|
62
|
+
}, [ip, consentAction, copy, language]);
|
|
63
|
+
// helpers
|
|
64
|
+
const onShowDialog = () => {
|
|
65
|
+
Consent.show(true);
|
|
66
|
+
};
|
|
67
|
+
// render
|
|
68
|
+
return ((0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)("button", { onClick: onShowDialog, children: copy.cta }) }));
|
|
69
|
+
}
|
|
70
|
+
// extension
|
|
71
|
+
const _consentState$ = new rxjs_1.BehaviorSubject(undefined);
|
|
72
|
+
(function (CookieConsent) {
|
|
73
|
+
// methods
|
|
74
|
+
function state$() {
|
|
75
|
+
return _consentState$
|
|
76
|
+
.pipe((0, rxjs_1.filter)(funnel_core_1.Value.isDefined));
|
|
77
|
+
}
|
|
78
|
+
CookieConsent.state$ = state$;
|
|
79
|
+
})(CookieConsent || (exports.CookieConsent = CookieConsent = {}));
|
|
80
|
+
function createConsentConfig({ ip, consentAction, copy, language }) {
|
|
81
|
+
const syncConsent = async (log) => {
|
|
82
|
+
console.debug('[CookieConsent] syncing consent');
|
|
83
|
+
// update global state
|
|
84
|
+
const preferences = Consent.getUserPreferences();
|
|
85
|
+
const state = {
|
|
86
|
+
categories: [
|
|
87
|
+
...preferences.acceptedCategories.map(category => ({
|
|
88
|
+
category: category,
|
|
89
|
+
accepted: true
|
|
90
|
+
})),
|
|
91
|
+
...preferences.rejectedCategories.map(category => ({
|
|
92
|
+
category: category,
|
|
93
|
+
accepted: false
|
|
94
|
+
}))
|
|
95
|
+
],
|
|
96
|
+
services: [
|
|
97
|
+
...Object.entries(preferences.acceptedServices)
|
|
98
|
+
.flatMap(([category, services]) => services.map(service => ({
|
|
99
|
+
category: category,
|
|
100
|
+
service: service,
|
|
101
|
+
accepted: true
|
|
102
|
+
}))),
|
|
103
|
+
...Object.entries(preferences.rejectedServices)
|
|
104
|
+
.flatMap(([category, services]) => services.map(service => ({
|
|
105
|
+
category: category,
|
|
106
|
+
service: service,
|
|
107
|
+
accepted: false
|
|
108
|
+
})))
|
|
109
|
+
]
|
|
110
|
+
};
|
|
111
|
+
_consentState$.next(state);
|
|
112
|
+
// log (if required)
|
|
113
|
+
if (log) {
|
|
114
|
+
await logConsent(preferences, state);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
const logConsent = async (preferences, state) => {
|
|
118
|
+
// create consent payload
|
|
119
|
+
const cookie = Consent.getCookie();
|
|
120
|
+
const consent = Object.assign({ ip: ip !== null && ip !== void 0 ? ip : undefined, url: window.location.href, userId: cookie.consentId, choice: preferences.acceptType }, state);
|
|
121
|
+
// submit consent
|
|
122
|
+
try {
|
|
123
|
+
console.debug('[CookieConsent] updating consent', consent);
|
|
124
|
+
await consentAction(consent);
|
|
125
|
+
console.debug('[CookieConsent] consent captured');
|
|
126
|
+
}
|
|
127
|
+
catch (e) {
|
|
128
|
+
console.error('[CookieConsent] failed to capture consent', e);
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
// return configuration
|
|
132
|
+
return {
|
|
133
|
+
// bind categories
|
|
134
|
+
categories: funnel_core_1.ConsentCategory.values.reduce((categories, category) => {
|
|
135
|
+
// setup services
|
|
136
|
+
const services = funnel_core_1.ConsentService.groupedValues[category].reduce((services, service) => {
|
|
137
|
+
// bind service
|
|
138
|
+
services[service] = {};
|
|
139
|
+
// keep reducing
|
|
140
|
+
return services;
|
|
141
|
+
}, {});
|
|
142
|
+
// bind category
|
|
143
|
+
categories[category] = category === 'necessary'
|
|
144
|
+
? { enabled: true, readOnly: true, services }
|
|
145
|
+
: { services };
|
|
146
|
+
// keep reducing
|
|
147
|
+
return categories;
|
|
148
|
+
}, {}),
|
|
149
|
+
// callbacks
|
|
150
|
+
onFirstConsent: () => syncConsent(true),
|
|
151
|
+
onConsent: () => syncConsent(false),
|
|
152
|
+
onChange: () => syncConsent(true),
|
|
153
|
+
// copy
|
|
154
|
+
language: {
|
|
155
|
+
default: language,
|
|
156
|
+
translations: {
|
|
157
|
+
[language]: copy
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./CookieConsent"), exports);
|
|
18
|
+
__exportStar(require("./ConsentData"), exports);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IdentityActions = void 0;
|
|
4
|
+
const funnel_core_1 = require("@nascentdigital/funnel-core");
|
|
5
|
+
const api_1 = require("./api");
|
|
6
|
+
// actions
|
|
7
|
+
var IdentityActions;
|
|
8
|
+
(function (IdentityActions) {
|
|
9
|
+
async function setProfileData(key, value) {
|
|
10
|
+
'use server';
|
|
11
|
+
// get current profile
|
|
12
|
+
const profile = await api_1.ProfileService.get().current();
|
|
13
|
+
if (!profile) {
|
|
14
|
+
throw new funnel_core_1.IllegalStateError('Cannot get current profile');
|
|
15
|
+
}
|
|
16
|
+
// update profile
|
|
17
|
+
await profile.set(key, value);
|
|
18
|
+
// return latest profile data
|
|
19
|
+
return profile.data;
|
|
20
|
+
}
|
|
21
|
+
IdentityActions.setProfileData = setProfileData;
|
|
22
|
+
})(IdentityActions || (exports.IdentityActions = IdentityActions = {}));
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Tagged } from 'type-fest';
|
|
2
|
+
export interface Identity {
|
|
3
|
+
id: Identity.Id;
|
|
4
|
+
level: Identity.Level;
|
|
5
|
+
name?: string;
|
|
6
|
+
email?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare namespace Identity {
|
|
9
|
+
type Id = Tagged<string, 'funnel.Identity.Id'>;
|
|
10
|
+
type Level = 'unidentified' | 'identified' | 'authenticated' | 'verified';
|
|
11
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Identity } from './Identity';
|
|
2
|
+
export interface IdentityService {
|
|
3
|
+
current(): Promise<Identity | undefined>;
|
|
4
|
+
}
|
|
5
|
+
export declare namespace IdentityService {
|
|
6
|
+
function tryGet(): IdentityService | undefined;
|
|
7
|
+
function get(): IdentityService;
|
|
8
|
+
function set(identityService: IdentityService): void;
|
|
9
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IdentityService = void 0;
|
|
4
|
+
const funnel_core_1 = require("@nascentdigital/funnel-core");
|
|
5
|
+
// extension
|
|
6
|
+
var IdentityService;
|
|
7
|
+
(function (IdentityService) {
|
|
8
|
+
function tryGet() {
|
|
9
|
+
return _identityService;
|
|
10
|
+
}
|
|
11
|
+
IdentityService.tryGet = tryGet;
|
|
12
|
+
function get() {
|
|
13
|
+
// throw if not set
|
|
14
|
+
if (!_identityService) {
|
|
15
|
+
throw new funnel_core_1.IllegalStateError('Attempt to access Identity service before first call to IdentityService.set()');
|
|
16
|
+
}
|
|
17
|
+
// return
|
|
18
|
+
return _identityService;
|
|
19
|
+
}
|
|
20
|
+
IdentityService.get = get;
|
|
21
|
+
function set(identityService) {
|
|
22
|
+
_identityService = identityService;
|
|
23
|
+
}
|
|
24
|
+
IdentityService.set = set;
|
|
25
|
+
})(IdentityService || (exports.IdentityService = IdentityService = {}));
|
|
26
|
+
// storage
|
|
27
|
+
let _identityService = undefined;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Identity } from './Identity';
|
|
2
|
+
export interface Profile extends Identity {
|
|
3
|
+
data: Readonly<Profile.Data>;
|
|
4
|
+
get<TValue>(key: string): TValue;
|
|
5
|
+
set<TValue>(key: string, value: TValue): Promise<void>;
|
|
6
|
+
delete(key: string): Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
export declare namespace Profile {
|
|
9
|
+
type Data = Record<string, unknown>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Identity } from './Identity';
|
|
2
|
+
import type { Profile } from './Profile';
|
|
3
|
+
export interface ProfileService {
|
|
4
|
+
current(): Promise<Profile | undefined>;
|
|
5
|
+
all(): Promise<Profile[]>;
|
|
6
|
+
get(id: Identity.Id): Promise<Profile>;
|
|
7
|
+
}
|
|
8
|
+
export declare namespace ProfileService {
|
|
9
|
+
function tryGet(): ProfileService | undefined;
|
|
10
|
+
function get(): ProfileService;
|
|
11
|
+
function set(profileService: ProfileService): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProfileService = void 0;
|
|
4
|
+
const funnel_core_1 = require("@nascentdigital/funnel-core");
|
|
5
|
+
// extension
|
|
6
|
+
var ProfileService;
|
|
7
|
+
(function (ProfileService) {
|
|
8
|
+
function tryGet() {
|
|
9
|
+
return _profileService;
|
|
10
|
+
}
|
|
11
|
+
ProfileService.tryGet = tryGet;
|
|
12
|
+
function get() {
|
|
13
|
+
// throw if not set
|
|
14
|
+
if (!_profileService) {
|
|
15
|
+
throw new funnel_core_1.IllegalStateError('Attempt to access Profile service before first call to ProfileService.set()');
|
|
16
|
+
}
|
|
17
|
+
// return
|
|
18
|
+
return _profileService;
|
|
19
|
+
}
|
|
20
|
+
ProfileService.get = get;
|
|
21
|
+
function set(profileService) {
|
|
22
|
+
_profileService = profileService;
|
|
23
|
+
}
|
|
24
|
+
ProfileService.set = set;
|
|
25
|
+
})(ProfileService || (exports.ProfileService = ProfileService = {}));
|
|
26
|
+
// storage
|
|
27
|
+
let _profileService = undefined;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./Identity"), exports);
|
|
18
|
+
__exportStar(require("./IdentityService"), exports);
|
|
19
|
+
__exportStar(require("./Profile"), exports);
|
|
20
|
+
__exportStar(require("./ProfileService"), exports);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Identity, IdentityService } from '../api';
|
|
2
|
+
export declare class Auth0IdentityService implements IdentityService {
|
|
3
|
+
private _client;
|
|
4
|
+
constructor(args: Auth0IdentityService.ConstructorArgs);
|
|
5
|
+
current(): Promise<Identity | undefined>;
|
|
6
|
+
}
|
|
7
|
+
export declare namespace Auth0IdentityService {
|
|
8
|
+
type ConstructorArgs = {};
|
|
9
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Auth0IdentityService = void 0;
|
|
4
|
+
const server_1 = require("@auth0/nextjs-auth0/server");
|
|
5
|
+
// service
|
|
6
|
+
class Auth0IdentityService {
|
|
7
|
+
constructor(args) {
|
|
8
|
+
this._client = new server_1.Auth0Client();
|
|
9
|
+
}
|
|
10
|
+
async current() {
|
|
11
|
+
// get current session
|
|
12
|
+
const session = await this._client.getSession();
|
|
13
|
+
// bail if no session or user
|
|
14
|
+
if (!session || !session.user) {
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
// return identity
|
|
18
|
+
const { user } = session;
|
|
19
|
+
return {
|
|
20
|
+
id: user.sub,
|
|
21
|
+
level: 'authenticated',
|
|
22
|
+
name: user.name,
|
|
23
|
+
email: user.email
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.Auth0IdentityService = Auth0IdentityService;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ManagementClient } from 'auth0';
|
|
2
|
+
import { Identity, Profile } from '../api';
|
|
3
|
+
export declare class Auth0Profile implements Profile {
|
|
4
|
+
readonly brand: string;
|
|
5
|
+
readonly id: Identity.Id;
|
|
6
|
+
readonly level: Identity.Level;
|
|
7
|
+
readonly name?: string;
|
|
8
|
+
readonly email?: string;
|
|
9
|
+
private _data;
|
|
10
|
+
private readonly _managementClient;
|
|
11
|
+
constructor(args: Auth0Profile.ConstructorArgs);
|
|
12
|
+
get data(): Readonly<Profile.Data>;
|
|
13
|
+
private get dataKeyPrefix();
|
|
14
|
+
get<TValue>(key: string): TValue;
|
|
15
|
+
set<TValue>(key: string, value: TValue): Promise<void>;
|
|
16
|
+
delete(key: string): Promise<void>;
|
|
17
|
+
private brandDataKey;
|
|
18
|
+
private profileDataForBrand;
|
|
19
|
+
}
|
|
20
|
+
export declare namespace Auth0Profile {
|
|
21
|
+
type ConstructorArgs = {
|
|
22
|
+
brand: string;
|
|
23
|
+
id: Identity.Id;
|
|
24
|
+
level: Identity.Level;
|
|
25
|
+
name?: string;
|
|
26
|
+
email?: string;
|
|
27
|
+
data?: Profile.Data;
|
|
28
|
+
managementClient: ManagementClient;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Auth0Profile = void 0;
|
|
4
|
+
// class
|
|
5
|
+
class Auth0Profile {
|
|
6
|
+
constructor(args) {
|
|
7
|
+
this.brand = args.brand;
|
|
8
|
+
this.id = args.id;
|
|
9
|
+
this.level = args.level;
|
|
10
|
+
this.name = args.name;
|
|
11
|
+
this.email = args.email;
|
|
12
|
+
this._data = this.profileDataForBrand(args.data);
|
|
13
|
+
this._managementClient = args.managementClient;
|
|
14
|
+
}
|
|
15
|
+
get data() {
|
|
16
|
+
return this._data;
|
|
17
|
+
}
|
|
18
|
+
get dataKeyPrefix() {
|
|
19
|
+
return `nd-${this.brand}-`;
|
|
20
|
+
}
|
|
21
|
+
get(key) {
|
|
22
|
+
// create branded key
|
|
23
|
+
const brandedKey = this.brandDataKey(key);
|
|
24
|
+
// return value
|
|
25
|
+
return this._data[brandedKey];
|
|
26
|
+
}
|
|
27
|
+
async set(key, value) {
|
|
28
|
+
// create branded key
|
|
29
|
+
const brandedKey = this.brandDataKey(key);
|
|
30
|
+
// update user's metadata
|
|
31
|
+
const result = await this._managementClient.users.update(this.id, {
|
|
32
|
+
app_metadata: { [brandedKey]: value }
|
|
33
|
+
});
|
|
34
|
+
// update local state
|
|
35
|
+
this._data = this.profileDataForBrand(result.app_metadata);
|
|
36
|
+
}
|
|
37
|
+
async delete(key) {
|
|
38
|
+
// set value to null to delete
|
|
39
|
+
await this.set(key, null);
|
|
40
|
+
}
|
|
41
|
+
brandDataKey(key) {
|
|
42
|
+
return `${this.dataKeyPrefix}${key}`;
|
|
43
|
+
}
|
|
44
|
+
profileDataForBrand(data) {
|
|
45
|
+
// return empty object if nothing
|
|
46
|
+
if (!data) {
|
|
47
|
+
return {};
|
|
48
|
+
}
|
|
49
|
+
// get key prefix to filter properties
|
|
50
|
+
const keyPrefix = this.dataKeyPrefix;
|
|
51
|
+
// return new object with only properties that start with prefix
|
|
52
|
+
return Object.fromEntries(Object.entries(data)
|
|
53
|
+
.filter(([key]) => key.startsWith(keyPrefix))
|
|
54
|
+
.map(([key, value]) => [key.slice(keyPrefix.length), value]));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.Auth0Profile = Auth0Profile;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ManagementClient } from 'auth0';
|
|
2
|
+
import { AsyncReturnType } from 'type-fest';
|
|
3
|
+
import { Identity, Profile, ProfileService } from '../api';
|
|
4
|
+
export declare class Auth0ProfileService implements ProfileService {
|
|
5
|
+
readonly brand: string;
|
|
6
|
+
private readonly _managementClient;
|
|
7
|
+
constructor(args: Auth0ProfileService.ConstructorArgs);
|
|
8
|
+
current(): Promise<Profile | undefined>;
|
|
9
|
+
all(): Promise<Profile[]>;
|
|
10
|
+
get(id: Identity.Id): Promise<Profile>;
|
|
11
|
+
}
|
|
12
|
+
export declare namespace Auth0ProfileService {
|
|
13
|
+
type ConstructorArgs = {
|
|
14
|
+
brand: string;
|
|
15
|
+
domain: string;
|
|
16
|
+
clientId: string;
|
|
17
|
+
clientSecret: string;
|
|
18
|
+
};
|
|
19
|
+
type Auth0UserData = AsyncReturnType<ManagementClient['users']['get']>;
|
|
20
|
+
function getLevel(data: Auth0UserData): Identity.Level;
|
|
21
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Auth0ProfileService = void 0;
|
|
4
|
+
const auth0_1 = require("auth0");
|
|
5
|
+
const api_1 = require("../api");
|
|
6
|
+
const Auth0Profile_1 = require("./Auth0Profile");
|
|
7
|
+
// service
|
|
8
|
+
class Auth0ProfileService {
|
|
9
|
+
constructor(args) {
|
|
10
|
+
// set instance variables
|
|
11
|
+
this.brand = args.brand;
|
|
12
|
+
this._managementClient = new auth0_1.ManagementClient({
|
|
13
|
+
domain: args.domain,
|
|
14
|
+
clientId: args.clientId,
|
|
15
|
+
clientSecret: args.clientSecret
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
async current() {
|
|
19
|
+
// get current identity if any
|
|
20
|
+
const identity = await api_1.IdentityService.get().current();
|
|
21
|
+
// bail if there is no identity
|
|
22
|
+
if (!identity) {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
// get profile based on identity
|
|
26
|
+
return this.get(identity.id);
|
|
27
|
+
}
|
|
28
|
+
async all() {
|
|
29
|
+
// get first page
|
|
30
|
+
// FIXME: handle pagination
|
|
31
|
+
const page = await this._managementClient.users.list({
|
|
32
|
+
per_page: 100
|
|
33
|
+
});
|
|
34
|
+
// create profile instances
|
|
35
|
+
return page.data.map(user => new Auth0Profile_1.Auth0Profile({
|
|
36
|
+
brand: this.brand,
|
|
37
|
+
id: user.user_id,
|
|
38
|
+
level: Auth0ProfileService.getLevel(user),
|
|
39
|
+
name: user.name,
|
|
40
|
+
email: user.email,
|
|
41
|
+
data: user.app_metadata,
|
|
42
|
+
managementClient: this._managementClient
|
|
43
|
+
}));
|
|
44
|
+
}
|
|
45
|
+
async get(id) {
|
|
46
|
+
// fetch user by id
|
|
47
|
+
const user = await this._managementClient.users.get(id);
|
|
48
|
+
// create new profile
|
|
49
|
+
return new Auth0Profile_1.Auth0Profile({
|
|
50
|
+
brand: this.brand,
|
|
51
|
+
id,
|
|
52
|
+
level: Auth0ProfileService.getLevel(user),
|
|
53
|
+
name: user.name,
|
|
54
|
+
email: user.email,
|
|
55
|
+
data: user.app_metadata,
|
|
56
|
+
managementClient: this._managementClient
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.Auth0ProfileService = Auth0ProfileService;
|
|
61
|
+
// extension
|
|
62
|
+
(function (Auth0ProfileService) {
|
|
63
|
+
function getLevel(data) {
|
|
64
|
+
return data.email_verified || data.phone_verified
|
|
65
|
+
? 'verified'
|
|
66
|
+
: 'authenticated';
|
|
67
|
+
}
|
|
68
|
+
Auth0ProfileService.getLevel = getLevel;
|
|
69
|
+
})(Auth0ProfileService || (exports.Auth0ProfileService = Auth0ProfileService = {}));
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./Auth0IdentityService"), exports);
|
|
18
|
+
__exportStar(require("./Auth0ProfileService"), exports);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Identity, Profile } from '../api';
|
|
2
|
+
export declare class ClientProfile implements Profile {
|
|
3
|
+
readonly brand: string;
|
|
4
|
+
readonly id: Identity.Id;
|
|
5
|
+
readonly level: Identity.Level;
|
|
6
|
+
readonly name?: string;
|
|
7
|
+
readonly email?: string;
|
|
8
|
+
private _data;
|
|
9
|
+
private readonly _onSetProfileData;
|
|
10
|
+
constructor(args: ClientProfile.ConstructorArgs);
|
|
11
|
+
get data(): Readonly<Profile.Data>;
|
|
12
|
+
get<TValue>(key: string): TValue;
|
|
13
|
+
set<TValue>(key: string, value: TValue): Promise<void>;
|
|
14
|
+
delete(key: string): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
export declare namespace ClientProfile {
|
|
17
|
+
type ConstructorArgs = {
|
|
18
|
+
brand: string;
|
|
19
|
+
id: Identity.Id;
|
|
20
|
+
level: Identity.Level;
|
|
21
|
+
name?: string;
|
|
22
|
+
email?: string;
|
|
23
|
+
data?: Profile.Data;
|
|
24
|
+
onSetProfileData: SetProfileDataMethod;
|
|
25
|
+
};
|
|
26
|
+
type SetProfileDataMethod = (key: string, value: unknown) => Promise<Readonly<Profile.Data>>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ClientProfile = void 0;
|
|
4
|
+
// class
|
|
5
|
+
class ClientProfile {
|
|
6
|
+
constructor(args) {
|
|
7
|
+
var _a;
|
|
8
|
+
this.brand = args.brand;
|
|
9
|
+
this.id = args.id;
|
|
10
|
+
this.level = args.level;
|
|
11
|
+
this.name = args.name;
|
|
12
|
+
this.email = args.email;
|
|
13
|
+
this._data = (_a = args.data) !== null && _a !== void 0 ? _a : {};
|
|
14
|
+
this._onSetProfileData = args.onSetProfileData;
|
|
15
|
+
}
|
|
16
|
+
get data() {
|
|
17
|
+
return this._data;
|
|
18
|
+
}
|
|
19
|
+
get(key) {
|
|
20
|
+
return this._data[key];
|
|
21
|
+
}
|
|
22
|
+
async set(key, value) {
|
|
23
|
+
// update profile and update data
|
|
24
|
+
this._data = await this._onSetProfileData(key, value);
|
|
25
|
+
}
|
|
26
|
+
async delete(key) {
|
|
27
|
+
// set value to null to delete
|
|
28
|
+
await this.set(key, null);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.ClientProfile = ClientProfile;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { PropsWithChildren } from 'react';
|
|
2
|
+
import { Identity, Profile } from '../api';
|
|
3
|
+
import { ClientProfile } from './ClientProfile';
|
|
4
|
+
export declare function IdentityContainer({ brand, identity, profileData, onSetProfileData, children }: IdentityContainer.Props): import("react/jsx-runtime").JSX.Element;
|
|
5
|
+
export declare namespace IdentityContainer {
|
|
6
|
+
type Props = PropsWithChildren & {
|
|
7
|
+
brand: string;
|
|
8
|
+
identity?: Identity;
|
|
9
|
+
profileData?: Profile.Data;
|
|
10
|
+
onSetProfileData: ClientProfile.SetProfileDataMethod;
|
|
11
|
+
};
|
|
12
|
+
}
|