@sitecore-content-sdk/core 0.2.0-beta.2 → 0.2.0-beta.21
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/content.d.ts +1 -0
- package/content.js +1 -0
- package/dist/cjs/client/graphql-edge-proxy.js +3 -3
- package/dist/cjs/client/sitecore-client.js +34 -17
- package/dist/cjs/config/define-config.js +6 -5
- package/dist/cjs/constants.js +12 -1
- package/dist/cjs/content/content-client.js +148 -0
- package/dist/cjs/content/index.js +13 -0
- package/dist/cjs/content/locales.js +32 -0
- package/dist/cjs/content/taxonomies.js +78 -0
- package/dist/cjs/content/utils.js +16 -0
- package/dist/cjs/debug.js +1 -0
- package/dist/cjs/editing/design-library.js +2 -1
- package/dist/cjs/editing/rest-component-layout-service.js +26 -45
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/layout/content-styles.js +2 -1
- package/dist/cjs/layout/themes.js +2 -1
- package/dist/cjs/site/graphql-robots-service.js +3 -2
- package/dist/cjs/tools/auth/encryption.js +141 -0
- package/dist/cjs/tools/auth/fetcher.js +34 -0
- package/dist/cjs/tools/auth/flow.js +123 -0
- package/dist/cjs/tools/auth/index.js +27 -0
- package/dist/cjs/tools/auth/models.js +2 -0
- package/dist/cjs/tools/auth/renewal.js +130 -0
- package/dist/cjs/tools/auth/tenant-state.js +110 -0
- package/dist/cjs/tools/auth/tenant-store.js +250 -0
- package/dist/cjs/tools/index.js +26 -1
- package/dist/cjs/utils/normalize-url.js +5 -0
- package/dist/cjs/utils/utils.js +5 -3
- package/dist/esm/client/graphql-edge-proxy.js +1 -1
- package/dist/esm/client/sitecore-client.js +34 -17
- package/dist/esm/config/define-config.js +6 -5
- package/dist/esm/constants.js +11 -0
- package/dist/esm/content/content-client.js +141 -0
- package/dist/esm/content/index.js +4 -0
- package/dist/esm/content/locales.js +29 -0
- package/dist/esm/content/taxonomies.js +75 -0
- package/dist/esm/content/utils.js +13 -0
- package/dist/esm/debug.js +1 -0
- package/dist/esm/editing/design-library.js +2 -1
- package/dist/esm/editing/rest-component-layout-service.js +23 -45
- package/dist/esm/index.js +2 -0
- package/dist/esm/layout/content-styles.js +2 -1
- package/dist/esm/layout/themes.js +2 -1
- package/dist/esm/site/graphql-robots-service.js +3 -2
- package/dist/esm/tools/auth/encryption.js +101 -0
- package/dist/esm/tools/auth/fetcher.js +31 -0
- package/dist/esm/tools/auth/flow.js +118 -0
- package/dist/esm/tools/auth/index.js +5 -0
- package/dist/esm/tools/auth/models.js +1 -0
- package/dist/esm/tools/auth/renewal.js +124 -0
- package/dist/esm/tools/auth/tenant-state.js +73 -0
- package/dist/esm/tools/auth/tenant-store.js +213 -0
- package/dist/esm/tools/index.js +3 -0
- package/dist/esm/utils/normalize-url.js +1 -0
- package/dist/esm/utils/utils.js +5 -3
- package/package.json +19 -18
- package/types/client/index.d.ts +1 -1
- package/types/client/models.d.ts +17 -1
- package/types/client/sitecore-client.d.ts +50 -22
- package/types/config/index.d.ts +1 -1
- package/types/config/models.d.ts +12 -2
- package/types/constants.d.ts +10 -0
- package/types/content/content-client.d.ts +92 -0
- package/types/content/index.d.ts +4 -0
- package/types/content/locales.d.ts +38 -0
- package/types/content/taxonomies.d.ts +125 -0
- package/types/content/utils.d.ts +15 -0
- package/types/debug.d.ts +1 -0
- package/types/editing/rest-component-layout-service.d.ts +23 -58
- package/types/index.d.ts +2 -0
- package/types/native-fetcher.d.ts +0 -7
- package/types/site/graphql-robots-service.d.ts +3 -2
- package/types/tools/auth/encryption.d.ts +34 -0
- package/types/tools/auth/fetcher.d.ts +13 -0
- package/types/tools/auth/flow.d.ts +40 -0
- package/types/tools/auth/index.d.ts +5 -0
- package/types/tools/auth/models.d.ts +233 -0
- package/types/tools/auth/renewal.d.ts +36 -0
- package/types/tools/auth/tenant-state.d.ts +21 -0
- package/types/tools/auth/tenant-store.d.ts +63 -0
- package/types/tools/index.d.ts +3 -0
- package/types/utils/normalize-url.d.ts +1 -0
- package/dist/cjs/data-fetcher.js +0 -22
- package/dist/esm/data-fetcher.js +0 -17
- package/form.d.ts +0 -1
- package/form.js +0 -1
- package/types/data-fetcher.d.ts +0 -34
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GraphQLClient } from '../client';
|
|
1
|
+
import { FetchOptions, GraphQLClient } from '../client';
|
|
2
2
|
import { GraphQLRequestClientFactory } from '../graphql-request-client';
|
|
3
3
|
export type GraphQLRobotsServiceConfig = {
|
|
4
4
|
/**
|
|
@@ -35,10 +35,11 @@ export declare class GraphQLRobotsService {
|
|
|
35
35
|
protected get query(): string;
|
|
36
36
|
/**
|
|
37
37
|
* Fetch a data of robots.txt from API
|
|
38
|
+
* @param {FetchOptions} fetchOptions - The fetch options to be used for the request.
|
|
38
39
|
* @returns text of robots.txt
|
|
39
40
|
* @throws {Error} if the siteName is empty.
|
|
40
41
|
*/
|
|
41
|
-
fetchRobots(): Promise<string>;
|
|
42
|
+
fetchRobots(fetchOptions?: FetchOptions): Promise<string>;
|
|
42
43
|
/**
|
|
43
44
|
* Gets a GraphQL client that can make requests to the API. Uses graphql-request as the default
|
|
44
45
|
* library for fetching graphql data (@see GraphQLRequestClient). Override this method if you
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { EncryptedPayload } from './models';
|
|
2
|
+
/**
|
|
3
|
+
* Encrypts plaintext using AES-256-GCM for a given tenant.
|
|
4
|
+
* @param {string} plaintext
|
|
5
|
+
* @param {string} tenantId
|
|
6
|
+
*/
|
|
7
|
+
export declare let encryptData: typeof _encryptData;
|
|
8
|
+
/**
|
|
9
|
+
* Decrypts encrypted payload using AES-256-GCM for a specific tenant.
|
|
10
|
+
* If key is corrupted or invalid, optionally clears both key and tenant data.
|
|
11
|
+
* @param {EncryptedPayload} payload
|
|
12
|
+
* @param {string} tenantId
|
|
13
|
+
* @param {string} cleanupOnFailure
|
|
14
|
+
*/
|
|
15
|
+
export declare let decryptData: typeof _decryptData;
|
|
16
|
+
/**
|
|
17
|
+
* Deletes the encryption key for a tenant (useful for cleanup).
|
|
18
|
+
* @param {string} tenantId
|
|
19
|
+
*/
|
|
20
|
+
export declare let deleteKey: typeof _deleteKey;
|
|
21
|
+
export declare const unitMocks: {
|
|
22
|
+
encryptData: typeof _encryptData;
|
|
23
|
+
decryptData: typeof _decryptData;
|
|
24
|
+
deleteKey: typeof _deleteKey;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Generates or retrieves a 32-byte AES key for a specific tenant.
|
|
28
|
+
* @param {string} tenantId
|
|
29
|
+
*/
|
|
30
|
+
export declare function getKey(tenantId: string): Promise<Buffer>;
|
|
31
|
+
declare function _encryptData(plaintext: string, tenantId: string): Promise<EncryptedPayload>;
|
|
32
|
+
declare function _decryptData(payload: EncryptedPayload, tenantId: string, cleanupOnFailure?: boolean): Promise<string | null>;
|
|
33
|
+
declare function _deleteKey(tenantId: string): Promise<void>;
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare const unitMocks: {
|
|
2
|
+
sendPostRequest: typeof _sendPostRequest;
|
|
3
|
+
};
|
|
4
|
+
/**
|
|
5
|
+
* Performs a POST request with application/x-www-form-urlencoded headers.
|
|
6
|
+
* @param {string} url - The endpoint to post to.
|
|
7
|
+
* @param { URLSearchParams} params - A URLSearchParams instance representing the body.
|
|
8
|
+
* @returns Parsed JSON response.
|
|
9
|
+
* @throws Error if response is not OK.
|
|
10
|
+
*/
|
|
11
|
+
export declare let sendPostRequest: typeof _sendPostRequest;
|
|
12
|
+
declare function _sendPostRequest<T>(url: string, params: URLSearchParams, throwOnError?: boolean): Promise<T>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { DeviceAuthRequest, DeviceAuthResponse, DeviceTokenPollRequest, TenantArgs, AuthResponse } from './models';
|
|
2
|
+
/**
|
|
3
|
+
* Performs the OAuth 2.0 client credentials flow to obtain a JWT access token
|
|
4
|
+
* from the Sitecore Identity Provider using the provided client credentials.
|
|
5
|
+
* @param {TenantArgs} params - Parameters including clientId, clientSecret, organizationId, tenantId, audience, authority, and baseUrl.
|
|
6
|
+
* @returns A Promise that resolves to the access token response (including access token, token type, expiry, etc.)
|
|
7
|
+
* @throws Will log and exit the process if the request fails or returns a non-OK status
|
|
8
|
+
*/
|
|
9
|
+
export declare let clientCredentialsFlow: typeof _clientCredentialsFlow;
|
|
10
|
+
/**
|
|
11
|
+
* Initiates the OAuth 2.0 Device Authorization flow by requesting a device and user code.
|
|
12
|
+
* This flow is typically used by devices or CLI apps that cannot input credentials directly.
|
|
13
|
+
* @param {DeviceAuthRequest} params - Parameters including clientId, audience, authority, and baseUrl.
|
|
14
|
+
* @returns {Promise<DeviceAuthResponse>} A promise resolving to device authorization metadata needed for polling.
|
|
15
|
+
* @throws {Error} If the device authorization request fails or returns an error response.
|
|
16
|
+
*/
|
|
17
|
+
export declare let startDeviceAuthFlow: typeof _startDeviceAuthFlow;
|
|
18
|
+
/**
|
|
19
|
+
* Polls the OAuth 2.0 device token endpoint to retrieve the access token once the user has authorized the device.
|
|
20
|
+
* This is typically used to continue the device authorization process after a user enters a code on a browser.
|
|
21
|
+
* @param {DeviceTokenPollRequest} params - Parameters for polling including clientId, deviceCode, interval, and authority.
|
|
22
|
+
* @returns {Promise<any>} A promise resolving to the device token response including access token and refresh token.
|
|
23
|
+
* @throws {Error} If polling fails or exceeds the timeout period.
|
|
24
|
+
*/
|
|
25
|
+
export declare let pollForDeviceToken: typeof _pollForDeviceToken;
|
|
26
|
+
export declare const unitMocks: {
|
|
27
|
+
clientCredentialsFlow: typeof _clientCredentialsFlow;
|
|
28
|
+
startDeviceAuthFlow: typeof _startDeviceAuthFlow;
|
|
29
|
+
pollForDeviceToken: typeof _pollForDeviceToken;
|
|
30
|
+
};
|
|
31
|
+
declare function _clientCredentialsFlow({ clientId, clientSecret, organizationId, tenantId, audience, authority, baseUrl, }: TenantArgs): Promise<{
|
|
32
|
+
data: AuthResponse;
|
|
33
|
+
tokenOrgId: any;
|
|
34
|
+
tokenTenantId: any;
|
|
35
|
+
tokenTenantName: any;
|
|
36
|
+
accessToken: string;
|
|
37
|
+
}>;
|
|
38
|
+
export declare function _startDeviceAuthFlow({ clientId, audience, authority, baseUrl, }: DeviceAuthRequest): Promise<DeviceAuthResponse>;
|
|
39
|
+
export declare function _pollForDeviceToken({ clientId, device_code, interval, authority, }: DeviceTokenPollRequest): Promise<AuthResponse>;
|
|
40
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { clientCredentialsFlow, startDeviceAuthFlow, pollForDeviceToken } from './flow';
|
|
2
|
+
export { renewClientToken, validateAndRenewAuthIfExpired, validateAuthInfo, getRefreshAccessToken, } from './renewal';
|
|
3
|
+
export { getActiveTenant, setActiveTenant, clearActiveTenant } from './tenant-state';
|
|
4
|
+
export { writeTenantAuthInfo, readTenantAuthInfo, deleteTenantAuthInfo, readTenantInfo, getAllTenantsInfo, writeTenantInfo, } from './tenant-store';
|
|
5
|
+
export { encryptData, decryptData, deleteKey } from './encryption';
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI arguments used for authentication and tenant identification.
|
|
3
|
+
*/
|
|
4
|
+
export interface TenantArgs {
|
|
5
|
+
/**
|
|
6
|
+
* OAuth2 client ID used to identify the application
|
|
7
|
+
*/
|
|
8
|
+
clientId: string;
|
|
9
|
+
/**
|
|
10
|
+
* Client secret used for client credentials flow
|
|
11
|
+
*/
|
|
12
|
+
clientSecret?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Organization ID associated with the tenant
|
|
15
|
+
*/
|
|
16
|
+
organizationId?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Tenant ID used for scoping the login
|
|
19
|
+
*/
|
|
20
|
+
tenantId?: string;
|
|
21
|
+
/**
|
|
22
|
+
* OAuth2 audience (e.g., API base URL the token is intended for)
|
|
23
|
+
*/
|
|
24
|
+
audience?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Auth authority/issuer URL (e.g., Sitecore identity endpoint)
|
|
27
|
+
*/
|
|
28
|
+
authority?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Base URL for the target Sitecore Content Management API
|
|
31
|
+
*/
|
|
32
|
+
baseUrl?: string;
|
|
33
|
+
}
|
|
34
|
+
export interface TenantSettings {
|
|
35
|
+
/**
|
|
36
|
+
* Currently active tenant ID tracked by the CLI
|
|
37
|
+
*/
|
|
38
|
+
activeTenant?: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Auth configuration stored per tenant for accessing Sitecore APIs.
|
|
42
|
+
*/
|
|
43
|
+
export interface TenantAuthInfo {
|
|
44
|
+
/**
|
|
45
|
+
* Access token issued by the identity provider
|
|
46
|
+
*/
|
|
47
|
+
access_token: string;
|
|
48
|
+
/**
|
|
49
|
+
* Token expiration duration in seconds
|
|
50
|
+
*/
|
|
51
|
+
expires_in: number;
|
|
52
|
+
/**
|
|
53
|
+
* Exact ISO timestamp when the token expires
|
|
54
|
+
*/
|
|
55
|
+
expires_at: string;
|
|
56
|
+
/**
|
|
57
|
+
* Secret used for client credentials flow and re-authenticate
|
|
58
|
+
*/
|
|
59
|
+
clientSecret?: string;
|
|
60
|
+
refresh_token?: string;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Public metadata for a known tenant.
|
|
64
|
+
*/
|
|
65
|
+
export interface TenantInfo {
|
|
66
|
+
/**
|
|
67
|
+
* Unique ID of the tenant
|
|
68
|
+
*/
|
|
69
|
+
tenantId: string;
|
|
70
|
+
/**
|
|
71
|
+
* Human-readable name of the tenant
|
|
72
|
+
*/
|
|
73
|
+
tenantName: string;
|
|
74
|
+
/**
|
|
75
|
+
* Organization ID the tenant belongs to
|
|
76
|
+
*/
|
|
77
|
+
organizationId: string;
|
|
78
|
+
/**
|
|
79
|
+
* Client ID associated with this tenant's authentication
|
|
80
|
+
*/
|
|
81
|
+
clientId: string;
|
|
82
|
+
/**
|
|
83
|
+
* OAuth2 audience (e.g., API base URL the token is intended for)
|
|
84
|
+
*/
|
|
85
|
+
audience: string;
|
|
86
|
+
/**
|
|
87
|
+
* Auth authority/issuer URL (e.g., Sitecore identity endpoint)
|
|
88
|
+
*/
|
|
89
|
+
authority: string;
|
|
90
|
+
/**
|
|
91
|
+
* Base URL for the target Sitecore Content Management API
|
|
92
|
+
*/
|
|
93
|
+
baseUrl: string;
|
|
94
|
+
}
|
|
95
|
+
export type EncryptedPayload = {
|
|
96
|
+
iv: string;
|
|
97
|
+
/**
|
|
98
|
+
* Authentication tag for integrity verification
|
|
99
|
+
*/
|
|
100
|
+
authTag: string;
|
|
101
|
+
/**
|
|
102
|
+
* Base64-encoded encrypted data
|
|
103
|
+
*/
|
|
104
|
+
encryptedData: string;
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* Input parameters for exchanging a refresh token for a new access token.
|
|
108
|
+
*/
|
|
109
|
+
export interface RefreshTokenRequest {
|
|
110
|
+
/**
|
|
111
|
+
* OAuth 2.0 client identifier.
|
|
112
|
+
*/
|
|
113
|
+
clientId: string;
|
|
114
|
+
/**
|
|
115
|
+
* Refresh token previously issued by the authorization server.
|
|
116
|
+
*/
|
|
117
|
+
refreshToken: string;
|
|
118
|
+
/**
|
|
119
|
+
* Tenant identifier to bind the request to a specific tenant context.
|
|
120
|
+
*/
|
|
121
|
+
tenantId: string;
|
|
122
|
+
/**
|
|
123
|
+
* Organization identifier for multi-tenant authorization scope.
|
|
124
|
+
*/
|
|
125
|
+
organizationId: string;
|
|
126
|
+
/**
|
|
127
|
+
* Optional OAuth 2.0 authority endpoint (token issuer URL).
|
|
128
|
+
* Defaults to the Sitecore standard authority if not provided.
|
|
129
|
+
*/
|
|
130
|
+
authority?: string;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Input parameters for initiating the OAuth 2.0 Device Authorization flow.
|
|
134
|
+
*/
|
|
135
|
+
export interface DeviceAuthRequest {
|
|
136
|
+
/**
|
|
137
|
+
* OAuth 2.0 client identifier.
|
|
138
|
+
*/
|
|
139
|
+
clientId: string;
|
|
140
|
+
/**
|
|
141
|
+
* The intended recipient of the token (usually your protected resource or API).
|
|
142
|
+
*/
|
|
143
|
+
audience: string;
|
|
144
|
+
/**
|
|
145
|
+
* OAuth 2.0 authority URL (token issuer).
|
|
146
|
+
*/
|
|
147
|
+
authority: string;
|
|
148
|
+
/**
|
|
149
|
+
* Base URL for your API, used to build custom claims or context if needed.
|
|
150
|
+
*/
|
|
151
|
+
baseUrl: string;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Response structure returned after initiating the device authorization flow.
|
|
155
|
+
*/
|
|
156
|
+
export interface DeviceAuthResponse {
|
|
157
|
+
/**
|
|
158
|
+
* Code the device will use to poll the token endpoint.
|
|
159
|
+
*/
|
|
160
|
+
device_code: string;
|
|
161
|
+
/**
|
|
162
|
+
* Code shown to the user for manual input during verification.
|
|
163
|
+
*/
|
|
164
|
+
user_code: string;
|
|
165
|
+
/**
|
|
166
|
+
* URI where the user should go to complete authentication.
|
|
167
|
+
*/
|
|
168
|
+
verification_uri: string;
|
|
169
|
+
/**
|
|
170
|
+
* Optional URI that includes the user code, allowing for a streamlined login experience.
|
|
171
|
+
*/
|
|
172
|
+
verification_uri_complete?: string;
|
|
173
|
+
/**
|
|
174
|
+
* Time (in seconds) until the device code expires.
|
|
175
|
+
*/
|
|
176
|
+
expires_in: number;
|
|
177
|
+
/**
|
|
178
|
+
* Recommended polling interval (in seconds) for token requests.
|
|
179
|
+
*/
|
|
180
|
+
interval: number;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Input parameters for polling the OAuth 2.0 device token endpoint.
|
|
184
|
+
*/
|
|
185
|
+
export interface DeviceTokenPollRequest {
|
|
186
|
+
/**
|
|
187
|
+
* OAuth 2.0 client identifier.
|
|
188
|
+
*/
|
|
189
|
+
clientId: string;
|
|
190
|
+
/**
|
|
191
|
+
* Device code previously obtained from the device authorization flow.
|
|
192
|
+
*/
|
|
193
|
+
device_code: string;
|
|
194
|
+
/**
|
|
195
|
+
* Optional polling interval in seconds. If not provided, a default is used.
|
|
196
|
+
*/
|
|
197
|
+
interval?: number;
|
|
198
|
+
/**
|
|
199
|
+
* Optional OAuth 2.0 authority endpoint for token polling.
|
|
200
|
+
*/
|
|
201
|
+
authority?: string;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Represents the raw OAuth token response returned by the authorization server.
|
|
205
|
+
* This includes the access token, refresh token, and optional ID token and scope.
|
|
206
|
+
*/
|
|
207
|
+
export interface TokenResponse {
|
|
208
|
+
/** The access token used for authenticating API requests */
|
|
209
|
+
access_token: string;
|
|
210
|
+
/** The refresh token used to obtain a new access token when it expires */
|
|
211
|
+
refresh_token: string;
|
|
212
|
+
/** The number of seconds until the access token expires */
|
|
213
|
+
expires_in: number;
|
|
214
|
+
/** The type of token issued, typically "Bearer" */
|
|
215
|
+
token_type: string;
|
|
216
|
+
/** An optional ID token containing user identity claims (usually JWT) */
|
|
217
|
+
id_token?: string;
|
|
218
|
+
/** The scopes granted for the access token, space-delimited */
|
|
219
|
+
scope?: string;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Represents the application-specific token response returned by `_getRefreshAccessToken`.
|
|
223
|
+
* In addition to the raw OAuth tokens, it includes the decoded `tenantName` for convenience.
|
|
224
|
+
*/
|
|
225
|
+
export interface RefreshAccessTokenResponse extends TokenResponse {
|
|
226
|
+
/** The tenant name extracted from the decoded access token payload */
|
|
227
|
+
tenantName?: string;
|
|
228
|
+
}
|
|
229
|
+
export interface AuthResponse {
|
|
230
|
+
[key: string]: any;
|
|
231
|
+
access_token: string;
|
|
232
|
+
expires_in: number;
|
|
233
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { RefreshAccessTokenResponse, RefreshTokenRequest, TenantAuthInfo, TenantInfo } from './models';
|
|
2
|
+
/**
|
|
3
|
+
* Requests a new access token using the OAuth 2.0 refresh token grant type.
|
|
4
|
+
* This is used to "upgrade" an initial device flow token by including tenant-specific context.
|
|
5
|
+
* @param {RefreshTokenRequest} options - Configuration for the refresh token request.
|
|
6
|
+
* @returns {Promise<any>} A promise that resolves to the refreshed token data including tenant context.
|
|
7
|
+
* @throws {Error} If the token request fails or returns an error response.
|
|
8
|
+
*/
|
|
9
|
+
export declare let getRefreshAccessToken: typeof _getRefreshAccessToken;
|
|
10
|
+
export declare const unitMocks: {
|
|
11
|
+
getRefreshAccessToken: typeof _getRefreshAccessToken;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Validates whether a given auth config is still valid (i.e., not expired).
|
|
15
|
+
* @param {TenantAuth} authInfo - The tenant auth configuration.
|
|
16
|
+
* @returns True if the token is still valid, false if expired.
|
|
17
|
+
*/
|
|
18
|
+
export declare function validateAuthInfo(authInfo: TenantAuthInfo): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Renews the token for a given tenant using stored credentials.
|
|
21
|
+
* @param {TenantAuth} authInfo - Current authentication info for the tenant.
|
|
22
|
+
* @param {TenantInfo} tenantInfo - Public metadata about the tenant (e.g., clientId).
|
|
23
|
+
* @returns {Promise<void>} resolving when the token is successfully renewed.
|
|
24
|
+
* @throws If credentials are missing or renewal fails.
|
|
25
|
+
*/
|
|
26
|
+
export declare function renewClientToken(authInfo: TenantAuthInfo, tenantInfo: TenantInfo): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Ensures a valid token exists, renews it if expired.
|
|
29
|
+
* @returns {Promise<{ tenantId: string } | null>} returns tenant context if successful, otherwise null.
|
|
30
|
+
* @throws If renewal fails or credentials are missing.
|
|
31
|
+
*/
|
|
32
|
+
export declare function validateAndRenewAuthIfExpired(): Promise<{
|
|
33
|
+
tenantId: string;
|
|
34
|
+
} | null>;
|
|
35
|
+
declare function _getRefreshAccessToken({ clientId, refreshToken, tenantId, organizationId, authority, }: RefreshTokenRequest): Promise<RefreshAccessTokenResponse>;
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gets the ID of the currently active tenant from settings.json.
|
|
3
|
+
* @returns The active tenant ID if present, otherwise null.
|
|
4
|
+
*/
|
|
5
|
+
export declare let getActiveTenant: typeof _getActiveTenant;
|
|
6
|
+
/**
|
|
7
|
+
* Clears the currently active tenant from settings.json by deleting the file.
|
|
8
|
+
*/
|
|
9
|
+
export declare let clearActiveTenant: typeof _clearActiveTenant;
|
|
10
|
+
export declare const unitMocks: {
|
|
11
|
+
clearActiveTenant: typeof _clearActiveTenant;
|
|
12
|
+
getActiveTenant: typeof _getActiveTenant;
|
|
13
|
+
};
|
|
14
|
+
declare function _getActiveTenant(): string | null;
|
|
15
|
+
/**
|
|
16
|
+
* Sets the currently active tenant by writing to settings.json.
|
|
17
|
+
* @param {string} tenantId - The tenant ID to set as active.
|
|
18
|
+
*/
|
|
19
|
+
export declare function setActiveTenant(tenantId: string): void;
|
|
20
|
+
declare function _clearActiveTenant(): void;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { TenantAuthInfo, TenantInfo } from './models';
|
|
2
|
+
/**
|
|
3
|
+
* Decodes a JWT without verifying its signature.
|
|
4
|
+
* @param {string} token - The access token string.
|
|
5
|
+
* @returns Decoded payload object or null if invalid.
|
|
6
|
+
*/
|
|
7
|
+
export declare let decodeJwtPayload: typeof _decodeJwtPayload;
|
|
8
|
+
/**
|
|
9
|
+
* Write the authentication configuration for a tenant.
|
|
10
|
+
* @param {string} tenantId - The tenant ID.
|
|
11
|
+
* @param {TenantAuth} authInfo - The tenant's auth data.
|
|
12
|
+
*/
|
|
13
|
+
export declare let writeTenantAuthInfo: typeof _writeTenantAuthInfo;
|
|
14
|
+
/**
|
|
15
|
+
* Read the authentication configuration for a tenant.
|
|
16
|
+
* @param {string} tenantId - The tenant ID.
|
|
17
|
+
* @returns Parsed auth config or null if not found or failed to read.
|
|
18
|
+
*/
|
|
19
|
+
export declare let readTenantAuthInfo: typeof _readTenantAuthInfo;
|
|
20
|
+
/**
|
|
21
|
+
* Write the public metadata information for a tenant.
|
|
22
|
+
* @param {TenantInfo} info - The tenant info object.
|
|
23
|
+
*/
|
|
24
|
+
export declare let writeTenantInfo: typeof _writeTenantInfo;
|
|
25
|
+
/**
|
|
26
|
+
* Read the public metadata information for a tenant.
|
|
27
|
+
* @param {string} tenantId - The tenant ID.
|
|
28
|
+
* @returns Parsed tenant info or null if not found or failed to read.
|
|
29
|
+
*/
|
|
30
|
+
export declare let readTenantInfo: typeof _readTenantInfo;
|
|
31
|
+
/**
|
|
32
|
+
* Deletes the stored auth.json file for the given tenant.
|
|
33
|
+
* @param {string} tenantId - The tenant ID.
|
|
34
|
+
*/
|
|
35
|
+
export declare let deleteTenantAuthInfo: typeof _deleteTenantAuthInfo;
|
|
36
|
+
/**
|
|
37
|
+
* Scans the CLI root directory and returns all valid tenant infos.
|
|
38
|
+
* @returns A list of TenantInfo objects found in {tenant-id}/info.json files.
|
|
39
|
+
*/
|
|
40
|
+
export declare let getAllTenantsInfo: typeof _getAllTenantsInfo;
|
|
41
|
+
export declare const unitMocks: {
|
|
42
|
+
decodeJwtPayload: typeof _decodeJwtPayload;
|
|
43
|
+
writeTenantAuthInfo: typeof _writeTenantAuthInfo;
|
|
44
|
+
readTenantAuthInfo: typeof _readTenantAuthInfo;
|
|
45
|
+
writeTenantInfo: typeof _writeTenantInfo;
|
|
46
|
+
readTenantInfo: typeof _readTenantInfo;
|
|
47
|
+
deleteTenantAuthInfo: typeof _deleteTenantAuthInfo;
|
|
48
|
+
getAllTenantsInfo: typeof _getAllTenantsInfo;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Get the full path to the tenant-specific folder.
|
|
52
|
+
* @param {string} tenantId - The tenant ID.
|
|
53
|
+
* @returns The absolute path to the tenant directory.
|
|
54
|
+
*/
|
|
55
|
+
export declare function getTenantPath(tenantId: string): string;
|
|
56
|
+
declare function _writeTenantAuthInfo(tenantId: string, authInfo: TenantAuthInfo): Promise<void>;
|
|
57
|
+
declare function _readTenantAuthInfo(tenantId: string): Promise<TenantAuthInfo | null>;
|
|
58
|
+
declare function _writeTenantInfo(info: TenantInfo): Promise<void>;
|
|
59
|
+
declare function _readTenantInfo(tenantId: string): Promise<TenantInfo | null>;
|
|
60
|
+
declare function _deleteTenantAuthInfo(tenantId: string): Promise<void>;
|
|
61
|
+
declare function _getAllTenantsInfo(): TenantInfo[];
|
|
62
|
+
declare function _decodeJwtPayload(token: string): Record<string, any> | null;
|
|
63
|
+
export {};
|
package/types/tools/index.d.ts
CHANGED
|
@@ -2,3 +2,6 @@ export { generateSites, GenerateSitesConfig } from './generateSites';
|
|
|
2
2
|
export { generateMetadata } from './generateMetadata';
|
|
3
3
|
export { scaffoldComponent } from './scaffold';
|
|
4
4
|
export * from './templating';
|
|
5
|
+
export * from './auth/models';
|
|
6
|
+
import * as auth from './auth';
|
|
7
|
+
export { auth };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const normalizeUrl: (url: string) => string;
|
package/dist/cjs/data-fetcher.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ResponseError = void 0;
|
|
4
|
-
exports.fetchData = fetchData;
|
|
5
|
-
const utils_1 = require("./utils/utils");
|
|
6
|
-
class ResponseError extends Error {
|
|
7
|
-
constructor(message, response) {
|
|
8
|
-
super(message);
|
|
9
|
-
Object.setPrototypeOf(this, ResponseError.prototype);
|
|
10
|
-
this.response = response;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
exports.ResponseError = ResponseError;
|
|
14
|
-
/**
|
|
15
|
-
* @param {string} url the URL to request; may include query string
|
|
16
|
-
* @param {HttpDataFetcher<T> | NativeDataFetcherFunction<T>} fetcher the fetcher to use to perform the request
|
|
17
|
-
* @param {ParsedUrlQueryInput} params the query string parameters to send with the request
|
|
18
|
-
*/
|
|
19
|
-
async function fetchData(url, fetcher, params = {}) {
|
|
20
|
-
const response = await fetcher((0, utils_1.resolveUrl)(url, params));
|
|
21
|
-
return response.data;
|
|
22
|
-
}
|
package/dist/esm/data-fetcher.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { resolveUrl } from './utils/utils';
|
|
2
|
-
export class ResponseError extends Error {
|
|
3
|
-
constructor(message, response) {
|
|
4
|
-
super(message);
|
|
5
|
-
Object.setPrototypeOf(this, ResponseError.prototype);
|
|
6
|
-
this.response = response;
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* @param {string} url the URL to request; may include query string
|
|
11
|
-
* @param {HttpDataFetcher<T> | NativeDataFetcherFunction<T>} fetcher the fetcher to use to perform the request
|
|
12
|
-
* @param {ParsedUrlQueryInput} params the query string parameters to send with the request
|
|
13
|
-
*/
|
|
14
|
-
export async function fetchData(url, fetcher, params = {}) {
|
|
15
|
-
const response = await fetcher(resolveUrl(url, params));
|
|
16
|
-
return response.data;
|
|
17
|
-
}
|
package/form.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './types/form/index';
|
package/form.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require('./dist/cjs/form/index');
|
package/types/data-fetcher.d.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { NativeDataFetcherFunction } from './native-fetcher';
|
|
2
|
-
import { ParsedUrlQueryInput } from 'querystring';
|
|
3
|
-
/**
|
|
4
|
-
* Response data for an HTTP request sent to an API
|
|
5
|
-
* @template T the type of data model requested
|
|
6
|
-
*/
|
|
7
|
-
export interface HttpResponse<T> {
|
|
8
|
-
/** HTTP status code of the response (i.e. 200, 404) */
|
|
9
|
-
status: number;
|
|
10
|
-
/** HTTP status text of the response (i.e. 'OK', 'Bad Request') */
|
|
11
|
-
statusText: string;
|
|
12
|
-
/** Response content */
|
|
13
|
-
data: T;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Describes functions that fetch data asynchronously (i.e. from an API endpoint).
|
|
17
|
-
* This interface conforms to 'fetch' public API, but is adaptable to other HTTP libraries and
|
|
18
|
-
* fetch polyfills.
|
|
19
|
-
* The interface implementation must:
|
|
20
|
-
* - Support SSR
|
|
21
|
-
* - Comply with the rules of REST by returning appropriate response status codes when there is an error instead of throwing exceptions.
|
|
22
|
-
* - Send HTTP POST requests if `data` param is specified; GET is suggested but not required for data-less requests
|
|
23
|
-
*/
|
|
24
|
-
export type HttpDataFetcher<T> = (url: string, data?: unknown) => Promise<HttpResponse<T>>;
|
|
25
|
-
export declare class ResponseError extends Error {
|
|
26
|
-
response: HttpResponse<unknown>;
|
|
27
|
-
constructor(message: string, response: HttpResponse<unknown>);
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* @param {string} url the URL to request; may include query string
|
|
31
|
-
* @param {HttpDataFetcher<T> | NativeDataFetcherFunction<T>} fetcher the fetcher to use to perform the request
|
|
32
|
-
* @param {ParsedUrlQueryInput} params the query string parameters to send with the request
|
|
33
|
-
*/
|
|
34
|
-
export declare function fetchData<T>(url: string, fetcher: HttpDataFetcher<T> | NativeDataFetcherFunction<T>, params?: ParsedUrlQueryInput): Promise<T>;
|