@casual-simulation/aux-records 3.4.6-alpha.14668890889 → 3.5.0-alpha.15119114602
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/AIController.js +835 -890
- package/AIController.js.map +1 -1
- package/AIHumeInterface.js +43 -54
- package/AIHumeInterface.js.map +1 -1
- package/AIOpenAIRealtimeInterface.js +60 -71
- package/AIOpenAIRealtimeInterface.js.map +1 -1
- package/AnthropicAIChatInterface.js +96 -142
- package/AnthropicAIChatInterface.js.map +1 -1
- package/AuthController.d.ts +3 -2
- package/AuthController.js +1907 -1933
- package/AuthController.js.map +1 -1
- package/AuthStore.d.ts +1 -10
- package/BlockadeLabsGenerateSkyboxInterface.js +57 -72
- package/BlockadeLabsGenerateSkyboxInterface.js.map +1 -1
- package/CachingConfigStore.js +30 -45
- package/CachingConfigStore.js.map +1 -1
- package/CachingPolicyStore.d.ts +8 -2
- package/CachingPolicyStore.js +108 -135
- package/CachingPolicyStore.js.map +1 -1
- package/ComIdConfig.d.ts +18 -18
- package/ComIdConfig.js.map +1 -1
- package/ConsoleAuthMessenger.js +7 -20
- package/ConsoleAuthMessenger.js.map +1 -1
- package/DataRecordsController.d.ts +2 -2
- package/DataRecordsController.js +369 -377
- package/DataRecordsController.js.map +1 -1
- package/DataRecordsStore.d.ts +1 -1
- package/DataRecordsStore.js +1 -1
- package/DataRecordsStore.js.map +1 -1
- package/EventRecordsController.js +226 -240
- package/EventRecordsController.js.map +1 -1
- package/FileRecordsController.d.ts +13 -2
- package/FileRecordsController.js +458 -450
- package/FileRecordsController.js.map +1 -1
- package/GoogleAIChatInterface.js +133 -179
- package/GoogleAIChatInterface.js.map +1 -1
- package/LivekitController.js +43 -54
- package/LivekitController.js.map +1 -1
- package/LoomController.js +64 -75
- package/LoomController.js.map +1 -1
- package/MemoryAuthMessenger.js +10 -23
- package/MemoryAuthMessenger.js.map +1 -1
- package/MemoryCache.js +18 -35
- package/MemoryCache.js.map +1 -1
- package/MemoryFileRecordsLookup.js +105 -125
- package/MemoryFileRecordsLookup.js.map +1 -1
- package/MemoryModerationJobProvider.js +17 -30
- package/MemoryModerationJobProvider.js.map +1 -1
- package/MemoryRateLimiter.js +12 -27
- package/MemoryRateLimiter.js.map +1 -1
- package/MemoryStore.d.ts +18 -6
- package/MemoryStore.js +1879 -1997
- package/MemoryStore.js.map +1 -1
- package/MetricsStore.d.ts +2 -2
- package/ModerationController.js +186 -200
- package/ModerationController.js.map +1 -1
- package/OpenAIChatInterface.js +105 -135
- package/OpenAIChatInterface.js.map +1 -1
- package/OpenAIImageInterface.js +57 -51
- package/OpenAIImageInterface.js.map +1 -1
- package/PolicyController.d.ts +150 -10
- package/PolicyController.js +1546 -1299
- package/PolicyController.js.map +1 -1
- package/PolicyStore.d.ts +110 -2
- package/PolicyStore.js +36 -1
- package/PolicyStore.js.map +1 -1
- package/PrivoClient.js +398 -435
- package/PrivoClient.js.map +1 -1
- package/RateLimitController.js +25 -36
- package/RateLimitController.js.map +1 -1
- package/RecordsClient.js +51 -74
- package/RecordsClient.js.map +1 -1
- package/RecordsController.d.ts +2 -42
- package/RecordsController.js +1026 -1182
- package/RecordsController.js.map +1 -1
- package/RecordsServer.d.ts +196 -27
- package/RecordsServer.js +1701 -1343
- package/RecordsServer.js.map +1 -1
- package/RecordsStore.d.ts +1 -10
- package/RecordsStore.js.map +1 -1
- package/ServerConfig.d.ts +339 -195
- package/ServerConfig.js +13 -0
- package/ServerConfig.js.map +1 -1
- package/SloydInterface.js +62 -75
- package/SloydInterface.js.map +1 -1
- package/StabilityAIImageInterface.js +150 -167
- package/StabilityAIImageInterface.js.map +1 -1
- package/SubscriptionConfigBuilder.d.ts +6 -1
- package/SubscriptionConfigBuilder.js +22 -0
- package/SubscriptionConfigBuilder.js.map +1 -1
- package/SubscriptionConfiguration.d.ts +266 -169
- package/SubscriptionConfiguration.js +101 -79
- package/SubscriptionConfiguration.js.map +1 -1
- package/SubscriptionController.d.ts +2 -1
- package/SubscriptionController.js +643 -650
- package/SubscriptionController.js.map +1 -1
- package/SystemNotificationMessenger.d.ts +21 -4
- package/SystemNotificationMessenger.js +36 -30
- package/SystemNotificationMessenger.js.map +1 -1
- package/TestUtils.d.ts +9 -1
- package/TestUtils.js +105 -129
- package/TestUtils.js.map +1 -1
- package/Utils.d.ts +2 -16
- package/Utils.js +21 -22
- package/Utils.js.map +1 -1
- package/crud/CrudHelpers.js +17 -26
- package/crud/CrudHelpers.js.map +1 -1
- package/crud/CrudRecordsController.d.ts +1 -1
- package/crud/CrudRecordsController.js +259 -267
- package/crud/CrudRecordsController.js.map +1 -1
- package/crud/CrudRecordsControllerTests.js +174 -185
- package/crud/CrudRecordsControllerTests.js.map +1 -1
- package/crud/CrudRecordsStore.d.ts +7 -3
- package/crud/MemoryCrudRecordsStore.d.ts +4 -4
- package/crud/MemoryCrudRecordsStore.js +98 -118
- package/crud/MemoryCrudRecordsStore.js.map +1 -1
- package/crud/sub/MemorySubCrudRecordsStore.d.ts +24 -0
- package/crud/sub/MemorySubCrudRecordsStore.js +146 -0
- package/crud/sub/MemorySubCrudRecordsStore.js.map +1 -0
- package/crud/sub/SubCrudRecordsController.d.ts +182 -0
- package/crud/sub/SubCrudRecordsController.js +360 -0
- package/crud/sub/SubCrudRecordsController.js.map +1 -0
- package/crud/sub/SubCrudRecordsControllerTests.d.ts +39 -0
- package/crud/sub/SubCrudRecordsControllerTests.js +821 -0
- package/crud/sub/SubCrudRecordsControllerTests.js.map +1 -0
- package/crud/sub/SubCrudRecordsStore.d.ts +95 -0
- package/{forms/index.js → crud/sub/SubCrudRecordsStore.js} +2 -2
- package/crud/sub/SubCrudRecordsStore.js.map +1 -0
- package/crud/sub/index.d.ts +3 -0
- package/crud/sub/index.js +20 -0
- package/{forms → crud/sub}/index.js.map +1 -1
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/index.js.map +1 -1
- package/notifications/MemoryNotificationRecordsStore.js +189 -198
- package/notifications/MemoryNotificationRecordsStore.js.map +1 -1
- package/notifications/NotificationRecordsController.js +438 -460
- package/notifications/NotificationRecordsController.js.map +1 -1
- package/notifications/NotificationRecordsStore.d.ts +2 -1
- package/notifications/WebPushInterface.d.ts +0 -1
- package/notifications/WebPushInterface.js +0 -1
- package/notifications/WebPushInterface.js.map +1 -1
- package/package.json +6 -6
- package/packages/MemoryPackageRecordsStore.d.ts +10 -0
- package/packages/MemoryPackageRecordsStore.js +38 -0
- package/packages/MemoryPackageRecordsStore.js.map +1 -0
- package/packages/PackageRecordsController.d.ts +26 -0
- package/packages/PackageRecordsController.js +49 -0
- package/packages/PackageRecordsController.js.map +1 -0
- package/packages/PackageRecordsStore.d.ts +32 -0
- package/packages/PackageRecordsStore.js +19 -0
- package/packages/PackageRecordsStore.js.map +1 -0
- package/packages/index.d.ts +4 -0
- package/packages/index.js +21 -0
- package/packages/index.js.map +1 -0
- package/packages/version/MemoryPackageVersionRecordsStore.d.ts +21 -0
- package/packages/version/MemoryPackageVersionRecordsStore.js +177 -0
- package/packages/version/MemoryPackageVersionRecordsStore.js.map +1 -0
- package/packages/version/PackageVersionRecordsController.d.ts +144 -0
- package/packages/version/PackageVersionRecordsController.js +656 -0
- package/packages/version/PackageVersionRecordsController.js.map +1 -0
- package/packages/version/PackageVersionRecordsStore.d.ts +342 -0
- package/packages/version/PackageVersionRecordsStore.js +126 -0
- package/packages/version/PackageVersionRecordsStore.js.map +1 -0
- package/packages/version/index.d.ts +4 -0
- package/packages/version/index.js +21 -0
- package/packages/version/index.js.map +1 -0
- package/tracing/TracingDecorators.js +31 -40
- package/tracing/TracingDecorators.js.map +1 -1
- package/webhooks/MemoryWebhookRecordsStore.js +56 -72
- package/webhooks/MemoryWebhookRecordsStore.js.map +1 -1
- package/webhooks/WebhookEnvironment.d.ts +3 -3
- package/webhooks/WebhookRecordsController.d.ts +2 -1
- package/webhooks/WebhookRecordsController.js +389 -382
- package/webhooks/WebhookRecordsController.js.map +1 -1
- package/webhooks/WebhookRecordsStore.d.ts +2 -1
- package/websockets/InstRecordsStore.d.ts +50 -0
- package/websockets/InstRecordsStore.js +17 -0
- package/websockets/InstRecordsStore.js.map +1 -1
- package/websockets/MemoryTempInstRecordsStore.d.ts +5 -0
- package/websockets/MemoryTempInstRecordsStore.js +168 -179
- package/websockets/MemoryTempInstRecordsStore.js.map +1 -1
- package/websockets/MemoryWebsocketConnectionStore.js +98 -135
- package/websockets/MemoryWebsocketConnectionStore.js.map +1 -1
- package/websockets/MemoryWebsocketMessenger.js +29 -48
- package/websockets/MemoryWebsocketMessenger.js.map +1 -1
- package/websockets/SplitInstRecordsStore.d.ts +4 -1
- package/websockets/SplitInstRecordsStore.js +167 -185
- package/websockets/SplitInstRecordsStore.js.map +1 -1
- package/websockets/TemporaryInstRecordsStore.d.ts +19 -1
- package/websockets/TemporaryInstRecordsStore.js +17 -0
- package/websockets/TemporaryInstRecordsStore.js.map +1 -1
- package/websockets/WebsocketController.d.ts +147 -3
- package/websockets/WebsocketController.js +1735 -1391
- package/websockets/WebsocketController.js.map +1 -1
- package/websockets/index.d.ts +0 -1
- package/websockets/index.js +0 -1
- package/websockets/index.js.map +1 -1
- package/AAGUID.d.ts +0 -11
- package/AAGUID.js +0 -116
- package/AAGUID.js.map +0 -1
- package/AuthUtils.d.ts +0 -162
- package/AuthUtils.js +0 -327
- package/AuthUtils.js.map +0 -1
- package/forms/FormError.d.ts +0 -43
- package/forms/FormError.js +0 -56
- package/forms/FormError.js.map +0 -1
- package/forms/index.d.ts +0 -2
- package/websockets/Utils.d.ts +0 -33
- package/websockets/Utils.js +0 -82
- package/websockets/Utils.js.map +0 -1
package/PrivoClient.js
CHANGED
|
@@ -4,15 +4,6 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
8
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
9
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
10
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
11
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
12
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
13
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
14
|
-
});
|
|
15
|
-
};
|
|
16
7
|
import { Issuer, generators } from 'openid-client';
|
|
17
8
|
import { v4 as uuid } from 'uuid';
|
|
18
9
|
import axios from 'axios';
|
|
@@ -36,481 +27,453 @@ export class PrivoClient {
|
|
|
36
27
|
this._store = store;
|
|
37
28
|
this._config = configStore;
|
|
38
29
|
}
|
|
39
|
-
init() {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
response_types: ['code'],
|
|
49
|
-
});
|
|
30
|
+
async init() {
|
|
31
|
+
const config = await this._config.getPrivoConfiguration();
|
|
32
|
+
this._issuer = await Issuer.discover(config.publicEndpoint);
|
|
33
|
+
this._redirectUri = config.redirectUri;
|
|
34
|
+
this._openid = new this._issuer.Client({
|
|
35
|
+
client_id: config.clientId,
|
|
36
|
+
client_secret: config.clientSecret,
|
|
37
|
+
redirect_uris: [this._redirectUri],
|
|
38
|
+
response_types: ['code'],
|
|
50
39
|
});
|
|
51
40
|
}
|
|
52
|
-
resendConsentRequest(requesterServiceId, approverServiceId) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
console.error(`[PrivoClient] [resendConsentRequest] Error resending consent request: ${result.status} ${result.statusText}`, result.data);
|
|
69
|
-
return {
|
|
70
|
-
success: false,
|
|
71
|
-
errorCode: 'unacceptable_request',
|
|
72
|
-
errorMessage: 'The request contains one or more invalid fields.',
|
|
73
|
-
};
|
|
74
|
-
}
|
|
41
|
+
async resendConsentRequest(requesterServiceId, approverServiceId) {
|
|
42
|
+
const config = await this._config.getPrivoConfiguration();
|
|
43
|
+
if (!config) {
|
|
44
|
+
throw new Error('No Privo configuration found.');
|
|
45
|
+
}
|
|
46
|
+
const headers = await this._getRequestHeaders(config);
|
|
47
|
+
const url = `${config.gatewayEndpoint}/api/v1.0/consent/resend`;
|
|
48
|
+
const result = await axios.post(url, {
|
|
49
|
+
requester_service_id: requesterServiceId,
|
|
50
|
+
approver_service_id: approverServiceId,
|
|
51
|
+
}, {
|
|
52
|
+
headers,
|
|
53
|
+
validateStatus: (status) => status < 500,
|
|
54
|
+
});
|
|
55
|
+
if (result.status >= 400) {
|
|
56
|
+
console.error(`[PrivoClient] [resendConsentRequest] Error resending consent request: ${result.status} ${result.statusText}`, result.data);
|
|
75
57
|
return {
|
|
76
|
-
success:
|
|
58
|
+
success: false,
|
|
59
|
+
errorCode: 'unacceptable_request',
|
|
60
|
+
errorMessage: 'The request contains one or more invalid fields.',
|
|
77
61
|
};
|
|
78
|
-
}
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
success: true,
|
|
65
|
+
};
|
|
79
66
|
}
|
|
80
|
-
createChildAccount(request) {
|
|
67
|
+
async createChildAccount(request) {
|
|
81
68
|
var _a;
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
if (result.status === 412) {
|
|
118
|
-
return {
|
|
119
|
-
success: false,
|
|
120
|
-
errorCode: 'child_email_already_exists',
|
|
121
|
-
errorMessage: 'The child email already exists.',
|
|
122
|
-
};
|
|
123
|
-
}
|
|
69
|
+
const config = await this._config.getPrivoConfiguration();
|
|
70
|
+
if (!config) {
|
|
71
|
+
throw new Error('No Privo configuration found.');
|
|
72
|
+
}
|
|
73
|
+
const headers = await this._getRequestHeaders(config);
|
|
74
|
+
const url = `${config.gatewayEndpoint}/api/v1.0/account/parent`;
|
|
75
|
+
const result = await axios.post(url, {
|
|
76
|
+
role_identifier: config.roleIds.parent,
|
|
77
|
+
email: request.parentEmail,
|
|
78
|
+
send_congratulations_email: true,
|
|
79
|
+
minor_registrations: [
|
|
80
|
+
{
|
|
81
|
+
send_parent_email: true,
|
|
82
|
+
role_identifier: config.roleIds.child,
|
|
83
|
+
first_name: request.childFirstName,
|
|
84
|
+
email: request.childEmail,
|
|
85
|
+
birth_date_yyyymmdd: DateTime.fromJSDate(request.childDateOfBirth).toFormat('yyyyMMdd'),
|
|
86
|
+
features: request.featureIds.map((f) => ({
|
|
87
|
+
feature_identifier: f,
|
|
88
|
+
})),
|
|
89
|
+
attributes: [
|
|
90
|
+
{
|
|
91
|
+
name: 'displayName',
|
|
92
|
+
value: request.childDisplayName,
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
}, {
|
|
98
|
+
headers,
|
|
99
|
+
validateStatus: (status) => status < 500,
|
|
100
|
+
});
|
|
101
|
+
if (result.status >= 400) {
|
|
102
|
+
console.error(`[PrivoClient] [createChildAccount] Error creating child account: ${result.status} ${result.statusText}`, result.data);
|
|
103
|
+
if (result.status === 412) {
|
|
124
104
|
return {
|
|
125
105
|
success: false,
|
|
126
|
-
errorCode: '
|
|
127
|
-
errorMessage: 'The
|
|
106
|
+
errorCode: 'child_email_already_exists',
|
|
107
|
+
errorMessage: 'The child email already exists.',
|
|
128
108
|
};
|
|
129
109
|
}
|
|
130
|
-
const data = result.data;
|
|
131
|
-
const schema = z.object({
|
|
132
|
-
to: z.object({
|
|
133
|
-
service_id: z.string(),
|
|
134
|
-
connected_profiles: z
|
|
135
|
-
.array(z.object({
|
|
136
|
-
service_id: z.string(),
|
|
137
|
-
update_password_link: z.string(),
|
|
138
|
-
features: z.array(z.object({
|
|
139
|
-
feature_identifier: z.string(),
|
|
140
|
-
on: z.boolean(),
|
|
141
|
-
})),
|
|
142
|
-
consent_meta: z
|
|
143
|
-
.object({
|
|
144
|
-
consent_url: z
|
|
145
|
-
.string()
|
|
146
|
-
.optional()
|
|
147
|
-
.nullable(),
|
|
148
|
-
})
|
|
149
|
-
.optional()
|
|
150
|
-
.nullable(),
|
|
151
|
-
}))
|
|
152
|
-
.min(1),
|
|
153
|
-
}),
|
|
154
|
-
});
|
|
155
|
-
const validated = schema.parse(data);
|
|
156
110
|
return {
|
|
157
|
-
success:
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
updatePasswordLink: validated.to.connected_profiles[0].update_password_link,
|
|
161
|
-
features: validated.to.connected_profiles[0].features.map((f) => ({
|
|
162
|
-
featureId: f.feature_identifier,
|
|
163
|
-
on: f.on === true || f.on === 'true',
|
|
164
|
-
})),
|
|
165
|
-
consentUrl: (_a = validated.to.connected_profiles[0].consent_meta) === null || _a === void 0 ? void 0 : _a.consent_url,
|
|
111
|
+
success: false,
|
|
112
|
+
errorCode: 'unacceptable_request',
|
|
113
|
+
errorMessage: 'The request contains one or more invalid fields.',
|
|
166
114
|
};
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
throw new Error('No Privo configuration found.');
|
|
175
|
-
}
|
|
176
|
-
const headers = yield this._getRequestHeaders(config);
|
|
177
|
-
const url = `${config.gatewayEndpoint}/api/v1.0/account`;
|
|
178
|
-
const result = yield axios.post(url, {
|
|
179
|
-
role_identifier: config.roleIds.adult,
|
|
180
|
-
email: request.adultEmail,
|
|
181
|
-
send_registration_email: true,
|
|
182
|
-
send_congratulations_email: true,
|
|
183
|
-
birth_date_yyyymmdd: DateTime.fromJSDate(request.adultDateOfBirth).toFormat('yyyyMMdd'),
|
|
184
|
-
first_name: request.adultFirstName,
|
|
185
|
-
features: request.featureIds.map((f) => ({
|
|
186
|
-
feature_identifier: f,
|
|
187
|
-
})),
|
|
188
|
-
attributes: [
|
|
189
|
-
{
|
|
190
|
-
name: 'displayName',
|
|
191
|
-
value: request.adultDisplayName,
|
|
192
|
-
},
|
|
193
|
-
],
|
|
194
|
-
}, {
|
|
195
|
-
headers,
|
|
196
|
-
validateStatus: (status) => status < 500,
|
|
197
|
-
});
|
|
198
|
-
if (result.status >= 400) {
|
|
199
|
-
console.error(`[PrivoClient] [createAdultAccount] Error creating adult account: ${result.status} ${result.statusText}`, result.data);
|
|
200
|
-
if (result.status === 412) {
|
|
201
|
-
return {
|
|
202
|
-
success: false,
|
|
203
|
-
errorCode: 'email_already_exists',
|
|
204
|
-
errorMessage: 'The email already exists.',
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
return {
|
|
208
|
-
success: false,
|
|
209
|
-
errorCode: 'unacceptable_request',
|
|
210
|
-
errorMessage: 'The request contains one or more invalid fields.',
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
const data = result.data;
|
|
214
|
-
const schema = z.object({
|
|
215
|
-
to: z.object({
|
|
115
|
+
}
|
|
116
|
+
const data = result.data;
|
|
117
|
+
const schema = z.object({
|
|
118
|
+
to: z.object({
|
|
119
|
+
service_id: z.string(),
|
|
120
|
+
connected_profiles: z
|
|
121
|
+
.array(z.object({
|
|
216
122
|
service_id: z.string(),
|
|
123
|
+
update_password_link: z.string(),
|
|
217
124
|
features: z.array(z.object({
|
|
218
125
|
feature_identifier: z.string(),
|
|
219
126
|
on: z.boolean(),
|
|
220
127
|
})),
|
|
221
|
-
update_password_link: z.string(),
|
|
222
128
|
consent_meta: z
|
|
223
129
|
.object({
|
|
224
|
-
consent_url: z
|
|
130
|
+
consent_url: z
|
|
131
|
+
.string()
|
|
132
|
+
.optional()
|
|
133
|
+
.nullable(),
|
|
225
134
|
})
|
|
226
135
|
.optional()
|
|
227
136
|
.nullable(),
|
|
228
|
-
})
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
return {
|
|
232
|
-
success: true,
|
|
233
|
-
adultServiceId: validated.to.service_id,
|
|
234
|
-
updatePasswordLink: validated.to.update_password_link,
|
|
235
|
-
features: validated.to.features.map((f) => ({
|
|
236
|
-
featureId: f.feature_identifier,
|
|
237
|
-
on: f.on === true || f.on === 'true',
|
|
238
|
-
})),
|
|
239
|
-
consentUrl: (_a = validated.to.consent_meta) === null || _a === void 0 ? void 0 : _a.consent_url,
|
|
240
|
-
};
|
|
137
|
+
}))
|
|
138
|
+
.min(1),
|
|
139
|
+
}),
|
|
241
140
|
});
|
|
141
|
+
const validated = schema.parse(data);
|
|
142
|
+
return {
|
|
143
|
+
success: true,
|
|
144
|
+
parentServiceId: validated.to.service_id,
|
|
145
|
+
childServiceId: validated.to.connected_profiles[0].service_id,
|
|
146
|
+
updatePasswordLink: validated.to.connected_profiles[0].update_password_link,
|
|
147
|
+
features: validated.to.connected_profiles[0].features.map((f) => ({
|
|
148
|
+
featureId: f.feature_identifier,
|
|
149
|
+
on: f.on === true || f.on === 'true',
|
|
150
|
+
})),
|
|
151
|
+
consentUrl: (_a = validated.to.connected_profiles[0].consent_meta) === null || _a === void 0 ? void 0 : _a.consent_url,
|
|
152
|
+
};
|
|
242
153
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
154
|
+
async createAdultAccount(request) {
|
|
155
|
+
var _a;
|
|
156
|
+
const config = await this._config.getPrivoConfiguration();
|
|
157
|
+
if (!config) {
|
|
158
|
+
throw new Error('No Privo configuration found.');
|
|
159
|
+
}
|
|
160
|
+
const headers = await this._getRequestHeaders(config);
|
|
161
|
+
const url = `${config.gatewayEndpoint}/api/v1.0/account`;
|
|
162
|
+
const result = await axios.post(url, {
|
|
163
|
+
role_identifier: config.roleIds.adult,
|
|
164
|
+
email: request.adultEmail,
|
|
165
|
+
send_registration_email: true,
|
|
166
|
+
send_congratulations_email: true,
|
|
167
|
+
birth_date_yyyymmdd: DateTime.fromJSDate(request.adultDateOfBirth).toFormat('yyyyMMdd'),
|
|
168
|
+
first_name: request.adultFirstName,
|
|
169
|
+
features: request.featureIds.map((f) => ({
|
|
170
|
+
feature_identifier: f,
|
|
171
|
+
})),
|
|
172
|
+
attributes: [
|
|
173
|
+
{
|
|
174
|
+
name: 'displayName',
|
|
175
|
+
value: request.adultDisplayName,
|
|
254
176
|
},
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
177
|
+
],
|
|
178
|
+
}, {
|
|
179
|
+
headers,
|
|
180
|
+
validateStatus: (status) => status < 500,
|
|
181
|
+
});
|
|
182
|
+
if (result.status >= 400) {
|
|
183
|
+
console.error(`[PrivoClient] [createAdultAccount] Error creating adult account: ${result.status} ${result.statusText}`, result.data);
|
|
184
|
+
if (result.status === 412) {
|
|
185
|
+
return {
|
|
186
|
+
success: false,
|
|
187
|
+
errorCode: 'email_already_exists',
|
|
188
|
+
errorMessage: 'The email already exists.',
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
return {
|
|
192
|
+
success: false,
|
|
193
|
+
errorCode: 'unacceptable_request',
|
|
194
|
+
errorMessage: 'The request contains one or more invalid fields.',
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
const data = result.data;
|
|
198
|
+
const schema = z.object({
|
|
199
|
+
to: z.object({
|
|
200
|
+
service_id: z.string(),
|
|
201
|
+
features: z.array(z.object({
|
|
269
202
|
feature_identifier: z.string(),
|
|
270
|
-
|
|
271
|
-
active: z.boolean(),
|
|
203
|
+
on: z.boolean(),
|
|
272
204
|
})),
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
205
|
+
update_password_link: z.string(),
|
|
206
|
+
consent_meta: z
|
|
207
|
+
.object({
|
|
208
|
+
consent_url: z.string().optional().nullable(),
|
|
209
|
+
})
|
|
210
|
+
.optional()
|
|
211
|
+
.nullable(),
|
|
212
|
+
}),
|
|
213
|
+
});
|
|
214
|
+
const validated = schema.parse(data);
|
|
215
|
+
return {
|
|
216
|
+
success: true,
|
|
217
|
+
adultServiceId: validated.to.service_id,
|
|
218
|
+
updatePasswordLink: validated.to.update_password_link,
|
|
219
|
+
features: validated.to.features.map((f) => ({
|
|
220
|
+
featureId: f.feature_identifier,
|
|
221
|
+
on: f.on === true || f.on === 'true',
|
|
222
|
+
})),
|
|
223
|
+
consentUrl: (_a = validated.to.consent_meta) === null || _a === void 0 ? void 0 : _a.consent_url,
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
async getUserInfo(serviceId) {
|
|
227
|
+
const config = await this._config.getPrivoConfiguration();
|
|
228
|
+
if (!config) {
|
|
229
|
+
throw new Error('No Privo configuration found.');
|
|
230
|
+
}
|
|
231
|
+
const headers = await this._getRequestHeaders(config);
|
|
232
|
+
const url = `${config.gatewayEndpoint}/userinfo`;
|
|
233
|
+
const result = await axios.get(url, {
|
|
234
|
+
params: {
|
|
235
|
+
service_id: serviceId,
|
|
236
|
+
},
|
|
237
|
+
headers,
|
|
238
|
+
});
|
|
239
|
+
const data = result.data;
|
|
240
|
+
const schema = z.object({
|
|
241
|
+
sub: z.string(),
|
|
242
|
+
locale: z.string(),
|
|
243
|
+
given_name: z.string(),
|
|
244
|
+
email: z.string().optional().nullable(),
|
|
245
|
+
email_verified: z.boolean(),
|
|
246
|
+
role_identifier: z.string(),
|
|
247
|
+
display_name: z.string(),
|
|
248
|
+
permissions: z.array(z.object({
|
|
249
|
+
on: z.boolean(),
|
|
250
|
+
consent_date: z.number(),
|
|
251
|
+
feature_identifier: z.string(),
|
|
252
|
+
category: z.string(),
|
|
253
|
+
active: z.boolean(),
|
|
254
|
+
})),
|
|
255
|
+
});
|
|
256
|
+
const validated = schema.parse(data);
|
|
257
|
+
return {
|
|
258
|
+
serviceId: validated.sub,
|
|
259
|
+
locale: validated.locale,
|
|
260
|
+
givenName: validated.given_name,
|
|
261
|
+
email: validated.email,
|
|
262
|
+
emailVerified: validated.email_verified,
|
|
263
|
+
roleIdentifier: validated.role_identifier,
|
|
264
|
+
displayName: validated.display_name,
|
|
265
|
+
permissions: validated.permissions.map((p) => ({
|
|
266
|
+
on: p.on,
|
|
267
|
+
consentDateSeconds: p.consent_date,
|
|
268
|
+
featureId: p.feature_identifier,
|
|
269
|
+
category: p.category,
|
|
270
|
+
active: p.active,
|
|
271
|
+
})),
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
async lookupServiceId(request) {
|
|
275
|
+
const config = await this._config.getPrivoConfiguration();
|
|
276
|
+
if (!config) {
|
|
277
|
+
throw new Error('No Privo configuration found.');
|
|
278
|
+
}
|
|
279
|
+
const headers = await this._getRequestHeaders(config);
|
|
280
|
+
const url = `${config.gatewayEndpoint}/api/v1.0/account/lookup`;
|
|
281
|
+
const params = {};
|
|
282
|
+
if (request.userName) {
|
|
283
|
+
params.user_name = request.userName;
|
|
284
|
+
}
|
|
285
|
+
else if (request.displayName) {
|
|
286
|
+
params.display_name = request.displayName;
|
|
287
|
+
}
|
|
288
|
+
else if (request.email) {
|
|
289
|
+
params.email = request.email;
|
|
290
|
+
}
|
|
291
|
+
else if (request.phoneNumber) {
|
|
292
|
+
params.phone = request.phoneNumber;
|
|
293
|
+
}
|
|
294
|
+
else if (request.externalUserIdentifier) {
|
|
295
|
+
params.external_user_identifier = request.externalUserIdentifier;
|
|
296
|
+
}
|
|
297
|
+
const result = await axios.get(url, {
|
|
298
|
+
params,
|
|
299
|
+
headers,
|
|
300
|
+
});
|
|
301
|
+
if (result.status === 404) {
|
|
302
|
+
return null;
|
|
303
|
+
}
|
|
304
|
+
const data = result.data;
|
|
305
|
+
const schema = z.object({
|
|
306
|
+
sid: z.string(),
|
|
307
|
+
});
|
|
308
|
+
const validated = schema.parse(data);
|
|
309
|
+
return validated.sid;
|
|
310
|
+
}
|
|
311
|
+
async generateAuthorizationUrl(state) {
|
|
312
|
+
const codeVerifier = generators.codeVerifier();
|
|
313
|
+
const codeChallenge = generators.codeChallenge(codeVerifier);
|
|
314
|
+
const codeMethod = 'S256';
|
|
315
|
+
const config = await this._config.getPrivoConfiguration();
|
|
316
|
+
const scope = config.userTokenScopes;
|
|
317
|
+
const url = this._openid.authorizationUrl({
|
|
318
|
+
scope: scope,
|
|
319
|
+
code_challenge: codeChallenge,
|
|
320
|
+
code_challenge_method: codeMethod,
|
|
321
|
+
state,
|
|
322
|
+
});
|
|
323
|
+
return {
|
|
324
|
+
authorizationUrl: url,
|
|
325
|
+
redirectUrl: this._redirectUri,
|
|
326
|
+
codeMethod,
|
|
327
|
+
codeVerifier: codeVerifier,
|
|
328
|
+
scope: scope,
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
async processAuthorizationCallback(request) {
|
|
332
|
+
const tokens = await this._openid.callback(request.redirectUrl, {
|
|
333
|
+
code: request.code,
|
|
334
|
+
state: request.state,
|
|
335
|
+
}, {
|
|
336
|
+
state: request.state,
|
|
337
|
+
code_verifier: request.codeVerifier,
|
|
338
|
+
});
|
|
339
|
+
const data = await this._openid.userinfo(tokens.access_token);
|
|
340
|
+
const schema = z.object({
|
|
341
|
+
sub: z.string(),
|
|
342
|
+
locale: z.string(),
|
|
343
|
+
given_name: z.string().optional().nullable(),
|
|
344
|
+
email: z.string().optional().nullable(),
|
|
345
|
+
email_verified: z.boolean(),
|
|
346
|
+
role_identifier: z.string(),
|
|
347
|
+
preferred_username: z.string().optional().nullable(),
|
|
348
|
+
permissions: z
|
|
349
|
+
.array(z.object({
|
|
350
|
+
on: z.boolean(),
|
|
351
|
+
consent_time: z.number().nullable().optional(),
|
|
352
|
+
request_time: z.number(),
|
|
353
|
+
feature_identifier: z.string(),
|
|
354
|
+
feature_category: z.string(),
|
|
355
|
+
feature_active: z.boolean(),
|
|
356
|
+
}))
|
|
357
|
+
.optional()
|
|
358
|
+
.nullable(),
|
|
359
|
+
});
|
|
360
|
+
const validated = schema.parse(data);
|
|
361
|
+
return {
|
|
362
|
+
accessToken: tokens.access_token,
|
|
363
|
+
refreshToken: tokens.refresh_token,
|
|
364
|
+
idToken: tokens.id_token,
|
|
365
|
+
expiresIn: tokens.expires_in,
|
|
366
|
+
tokenType: tokens.token_type,
|
|
367
|
+
userInfo: {
|
|
276
368
|
serviceId: validated.sub,
|
|
277
369
|
locale: validated.locale,
|
|
278
370
|
givenName: validated.given_name,
|
|
279
371
|
email: validated.email,
|
|
280
372
|
emailVerified: validated.email_verified,
|
|
281
373
|
roleIdentifier: validated.role_identifier,
|
|
282
|
-
displayName: validated.
|
|
374
|
+
displayName: validated.preferred_username,
|
|
283
375
|
permissions: validated.permissions.map((p) => ({
|
|
284
376
|
on: p.on,
|
|
285
|
-
consentDateSeconds: p.
|
|
377
|
+
consentDateSeconds: p.consent_time,
|
|
286
378
|
featureId: p.feature_identifier,
|
|
287
|
-
category: p.
|
|
288
|
-
active: p.
|
|
379
|
+
category: p.feature_category,
|
|
380
|
+
active: p.feature_active,
|
|
289
381
|
})),
|
|
290
|
-
}
|
|
291
|
-
}
|
|
382
|
+
},
|
|
383
|
+
};
|
|
292
384
|
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
const params = {};
|
|
302
|
-
if (request.userName) {
|
|
303
|
-
params.user_name = request.userName;
|
|
304
|
-
}
|
|
305
|
-
else if (request.displayName) {
|
|
306
|
-
params.display_name = request.displayName;
|
|
307
|
-
}
|
|
308
|
-
else if (request.email) {
|
|
309
|
-
params.email = request.email;
|
|
310
|
-
}
|
|
311
|
-
else if (request.phoneNumber) {
|
|
312
|
-
params.phone = request.phoneNumber;
|
|
313
|
-
}
|
|
314
|
-
else if (request.externalUserIdentifier) {
|
|
315
|
-
params.external_user_identifier = request.externalUserIdentifier;
|
|
316
|
-
}
|
|
317
|
-
const result = yield axios.get(url, {
|
|
318
|
-
params,
|
|
319
|
-
headers,
|
|
320
|
-
});
|
|
321
|
-
if (result.status === 404) {
|
|
322
|
-
return null;
|
|
323
|
-
}
|
|
324
|
-
const data = result.data;
|
|
325
|
-
const schema = z.object({
|
|
326
|
-
sid: z.string(),
|
|
327
|
-
});
|
|
328
|
-
const validated = schema.parse(data);
|
|
329
|
-
return validated.sid;
|
|
330
|
-
});
|
|
385
|
+
async generateLogoutUrl(token) {
|
|
386
|
+
const config = await this._config.getPrivoConfiguration();
|
|
387
|
+
if (!config) {
|
|
388
|
+
throw new Error('No Privo configuration found.');
|
|
389
|
+
}
|
|
390
|
+
const url = new URL('/logout', config.publicEndpoint);
|
|
391
|
+
url.searchParams.set('id_token_hint', token);
|
|
392
|
+
return url.href;
|
|
331
393
|
}
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
return {
|
|
346
|
-
authorizationUrl: url,
|
|
347
|
-
redirectUrl: this._redirectUri,
|
|
348
|
-
codeMethod,
|
|
349
|
-
codeVerifier: codeVerifier,
|
|
350
|
-
scope: scope,
|
|
351
|
-
};
|
|
394
|
+
async checkEmail(email) {
|
|
395
|
+
const config = await this._config.getPrivoConfiguration();
|
|
396
|
+
if (!config) {
|
|
397
|
+
throw new Error('No Privo configuration found.');
|
|
398
|
+
}
|
|
399
|
+
const headers = await this._getRequestHeaders(config);
|
|
400
|
+
const url = `${config.gatewayEndpoint}/api/v1.0/account/check/email`;
|
|
401
|
+
const result = await axios.post(url, { email }, { headers });
|
|
402
|
+
const data = result.data;
|
|
403
|
+
// Privo's email API returns invalid profanity information.
|
|
404
|
+
const schema = z.object({
|
|
405
|
+
available: z.boolean(),
|
|
406
|
+
suggestions: z.array(z.string()).optional(),
|
|
352
407
|
});
|
|
408
|
+
const validated = schema.parse(data);
|
|
409
|
+
return {
|
|
410
|
+
available: validated.available,
|
|
411
|
+
suggestions: validated.suggestions,
|
|
412
|
+
};
|
|
353
413
|
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
role_identifier: z.string(),
|
|
371
|
-
preferred_username: z.string().optional().nullable(),
|
|
372
|
-
permissions: z
|
|
373
|
-
.array(z.object({
|
|
374
|
-
on: z.boolean(),
|
|
375
|
-
consent_time: z.number().nullable().optional(),
|
|
376
|
-
request_time: z.number(),
|
|
377
|
-
feature_identifier: z.string(),
|
|
378
|
-
feature_category: z.string(),
|
|
379
|
-
feature_active: z.boolean(),
|
|
380
|
-
}))
|
|
381
|
-
.optional()
|
|
382
|
-
.nullable(),
|
|
383
|
-
});
|
|
384
|
-
const validated = schema.parse(data);
|
|
385
|
-
return {
|
|
386
|
-
accessToken: tokens.access_token,
|
|
387
|
-
refreshToken: tokens.refresh_token,
|
|
388
|
-
idToken: tokens.id_token,
|
|
389
|
-
expiresIn: tokens.expires_in,
|
|
390
|
-
tokenType: tokens.token_type,
|
|
391
|
-
userInfo: {
|
|
392
|
-
serviceId: validated.sub,
|
|
393
|
-
locale: validated.locale,
|
|
394
|
-
givenName: validated.given_name,
|
|
395
|
-
email: validated.email,
|
|
396
|
-
emailVerified: validated.email_verified,
|
|
397
|
-
roleIdentifier: validated.role_identifier,
|
|
398
|
-
displayName: validated.preferred_username,
|
|
399
|
-
permissions: validated.permissions.map((p) => ({
|
|
400
|
-
on: p.on,
|
|
401
|
-
consentDateSeconds: p.consent_time,
|
|
402
|
-
featureId: p.feature_identifier,
|
|
403
|
-
category: p.feature_category,
|
|
404
|
-
active: p.feature_active,
|
|
405
|
-
})),
|
|
406
|
-
},
|
|
407
|
-
};
|
|
414
|
+
async checkDisplayName(displayName) {
|
|
415
|
+
const config = await this._config.getPrivoConfiguration();
|
|
416
|
+
if (!config) {
|
|
417
|
+
throw new Error('No Privo configuration found.');
|
|
418
|
+
}
|
|
419
|
+
const headers = await this._getRequestHeaders(config);
|
|
420
|
+
const url = `${config.gatewayEndpoint}/api/v1.0/account/check/display-name`;
|
|
421
|
+
const result = await axios.post(url, {
|
|
422
|
+
display_name: displayName,
|
|
423
|
+
suggest: true,
|
|
424
|
+
}, { headers });
|
|
425
|
+
const data = result.data;
|
|
426
|
+
const schema = z.object({
|
|
427
|
+
available: z.boolean(),
|
|
428
|
+
suggestions: z.array(z.string()).optional(),
|
|
429
|
+
profanity: z.boolean().optional(),
|
|
408
430
|
});
|
|
431
|
+
const validated = schema.parse(data);
|
|
432
|
+
return {
|
|
433
|
+
available: validated.available,
|
|
434
|
+
profanity: validated.profanity,
|
|
435
|
+
suggestions: validated.suggestions,
|
|
436
|
+
};
|
|
409
437
|
}
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
return url.href;
|
|
419
|
-
});
|
|
438
|
+
async _getRequestHeaders(config) {
|
|
439
|
+
const credentials = await this._getClientCredentials(config);
|
|
440
|
+
if (!credentials) {
|
|
441
|
+
throw new Error('No Privo credentials found.');
|
|
442
|
+
}
|
|
443
|
+
return {
|
|
444
|
+
Authorization: `Bearer ${credentials.accessToken}`,
|
|
445
|
+
};
|
|
420
446
|
}
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
const headers = yield this._getRequestHeaders(config);
|
|
428
|
-
const url = `${config.gatewayEndpoint}/api/v1.0/account/check/email`;
|
|
429
|
-
const result = yield axios.post(url, { email }, { headers });
|
|
430
|
-
const data = result.data;
|
|
431
|
-
// Privo's email API returns invalid profanity information.
|
|
432
|
-
const schema = z.object({
|
|
433
|
-
available: z.boolean(),
|
|
434
|
-
suggestions: z.array(z.string()).optional(),
|
|
435
|
-
});
|
|
436
|
-
const validated = schema.parse(data);
|
|
437
|
-
return {
|
|
438
|
-
available: validated.available,
|
|
439
|
-
suggestions: validated.suggestions,
|
|
440
|
-
};
|
|
441
|
-
});
|
|
442
|
-
}
|
|
443
|
-
checkDisplayName(displayName) {
|
|
444
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
445
|
-
const config = yield this._config.getPrivoConfiguration();
|
|
446
|
-
if (!config) {
|
|
447
|
-
throw new Error('No Privo configuration found.');
|
|
448
|
-
}
|
|
449
|
-
const headers = yield this._getRequestHeaders(config);
|
|
450
|
-
const url = `${config.gatewayEndpoint}/api/v1.0/account/check/display-name`;
|
|
451
|
-
const result = yield axios.post(url, {
|
|
452
|
-
display_name: displayName,
|
|
453
|
-
suggest: true,
|
|
454
|
-
}, { headers });
|
|
455
|
-
const data = result.data;
|
|
456
|
-
const schema = z.object({
|
|
457
|
-
available: z.boolean(),
|
|
458
|
-
suggestions: z.array(z.string()).optional(),
|
|
459
|
-
profanity: z.boolean().optional(),
|
|
460
|
-
});
|
|
461
|
-
const validated = schema.parse(data);
|
|
462
|
-
return {
|
|
463
|
-
available: validated.available,
|
|
464
|
-
profanity: validated.profanity,
|
|
465
|
-
suggestions: validated.suggestions,
|
|
466
|
-
};
|
|
467
|
-
});
|
|
468
|
-
}
|
|
469
|
-
_getRequestHeaders(config) {
|
|
470
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
471
|
-
const credentials = yield this._getClientCredentials(config);
|
|
472
|
-
if (!credentials) {
|
|
473
|
-
throw new Error('No Privo credentials found.');
|
|
474
|
-
}
|
|
475
|
-
return {
|
|
476
|
-
Authorization: `Bearer ${credentials.accessToken}`,
|
|
477
|
-
};
|
|
478
|
-
});
|
|
479
|
-
}
|
|
480
|
-
_getClientCredentials(config) {
|
|
481
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
482
|
-
const creds = yield this._store.getStoredCredentials();
|
|
483
|
-
if (creds) {
|
|
484
|
-
const expired = creds.expiresAtSeconds < Date.now() / 1000;
|
|
485
|
-
if (!expired) {
|
|
486
|
-
return creds;
|
|
487
|
-
}
|
|
488
|
-
else {
|
|
489
|
-
const tokens = yield this._openid.refresh(creds.refreshToken);
|
|
490
|
-
return this._saveTokenSet(tokens);
|
|
491
|
-
}
|
|
447
|
+
async _getClientCredentials(config) {
|
|
448
|
+
const creds = await this._store.getStoredCredentials();
|
|
449
|
+
if (creds) {
|
|
450
|
+
const expired = creds.expiresAtSeconds < Date.now() / 1000;
|
|
451
|
+
if (!expired) {
|
|
452
|
+
return creds;
|
|
492
453
|
}
|
|
493
454
|
else {
|
|
494
|
-
const tokens =
|
|
495
|
-
grant_type: 'client_credentials',
|
|
496
|
-
scope: config.clientTokenScopes,
|
|
497
|
-
});
|
|
455
|
+
const tokens = await this._openid.refresh(creds.refreshToken);
|
|
498
456
|
return this._saveTokenSet(tokens);
|
|
499
457
|
}
|
|
500
|
-
}
|
|
458
|
+
}
|
|
459
|
+
else {
|
|
460
|
+
const tokens = await this._openid.grant({
|
|
461
|
+
grant_type: 'client_credentials',
|
|
462
|
+
scope: config.clientTokenScopes,
|
|
463
|
+
});
|
|
464
|
+
return this._saveTokenSet(tokens);
|
|
465
|
+
}
|
|
501
466
|
}
|
|
502
|
-
_saveTokenSet(set) {
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
return creds;
|
|
513
|
-
});
|
|
467
|
+
async _saveTokenSet(set) {
|
|
468
|
+
const creds = {
|
|
469
|
+
id: uuid(),
|
|
470
|
+
accessToken: set.access_token,
|
|
471
|
+
expiresAtSeconds: set.expires_at,
|
|
472
|
+
refreshToken: set.refresh_token,
|
|
473
|
+
scope: set.scope,
|
|
474
|
+
};
|
|
475
|
+
await this._store.saveCredentials(creds);
|
|
476
|
+
return creds;
|
|
514
477
|
}
|
|
515
478
|
}
|
|
516
479
|
__decorate([
|