@salesforcedevs/docs-components 1.29.0-alpha1 → 1.29.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,186 +0,0 @@
1
- :host {
2
- display: block;
3
- }
4
-
5
- .playground-container {
6
- border: 1px solid var(--dx-g-color-border-primary, #e0e0e0);
7
- border-radius: 8px;
8
- padding: 20px;
9
- margin: 16px 0;
10
- background: var(--dx-g-color-surface-primary, #ffffff);
11
- }
12
-
13
- .playground-header {
14
- display: flex;
15
- align-items: center;
16
- gap: 12px;
17
- margin-bottom: 20px;
18
- }
19
-
20
- .method-badge {
21
- display: inline-block;
22
- padding: 4px 10px;
23
- border-radius: 4px;
24
- font-size: 12px;
25
- font-weight: 700;
26
- text-transform: uppercase;
27
- color: #fff;
28
- letter-spacing: 0.5px;
29
- }
30
-
31
- .method-get {
32
- background-color: #61affe;
33
- }
34
-
35
- .method-post {
36
- background-color: #49cc90;
37
- }
38
-
39
- .method-put {
40
- background-color: #fca130;
41
- }
42
-
43
- .method-delete {
44
- background-color: #f93e3e;
45
- }
46
-
47
- .method-patch {
48
- background-color: #50e3c2;
49
- }
50
-
51
- .method-options,
52
- .method-head {
53
- background-color: #9012fe;
54
- }
55
-
56
- .operation-path {
57
- font-family: var(--dx-g-font-family-mono, monospace);
58
- font-size: 14px;
59
- font-weight: 600;
60
- color: var(--dx-g-color-text-primary, #181818);
61
- }
62
-
63
- .params-section {
64
- margin-bottom: 16px;
65
- }
66
-
67
- .section-title {
68
- font-size: 13px;
69
- font-weight: 600;
70
- margin: 0 0 8px 0;
71
- color: var(--dx-g-color-text-secondary, #444);
72
- text-transform: uppercase;
73
- letter-spacing: 0.5px;
74
- }
75
-
76
- .field-group {
77
- margin-bottom: 12px;
78
- }
79
-
80
- .field-label {
81
- display: block;
82
- font-size: 13px;
83
- font-weight: 500;
84
- margin-bottom: 4px;
85
- color: var(--dx-g-color-text-primary, #181818);
86
- }
87
-
88
- .required-marker {
89
- color: #f93e3e;
90
- margin-left: 2px;
91
- }
92
-
93
- .field-input,
94
- .server-select {
95
- width: 100%;
96
- padding: 8px 12px;
97
- border: 1px solid var(--dx-g-color-border-primary, #e0e0e0);
98
- border-radius: 4px;
99
- font-size: 14px;
100
- font-family: var(--dx-g-font-family-mono, monospace);
101
- background: var(--dx-g-color-surface-primary, #ffffff);
102
- color: var(--dx-g-color-text-primary, #181818);
103
- box-sizing: border-box;
104
- }
105
-
106
- .field-input:focus,
107
- .server-select:focus {
108
- outline: none;
109
- border-color: var(--dx-g-color-brand, #0070d2);
110
- box-shadow: 0 0 0 1px var(--dx-g-color-brand, #0070d2);
111
- }
112
-
113
- .body-textarea {
114
- width: 100%;
115
- padding: 8px 12px;
116
- border: 1px solid var(--dx-g-color-border-primary, #e0e0e0);
117
- border-radius: 4px;
118
- font-size: 13px;
119
- font-family: var(--dx-g-font-family-mono, monospace);
120
- background: var(--dx-g-color-surface-primary, #ffffff);
121
- color: var(--dx-g-color-text-primary, #181818);
122
- resize: vertical;
123
- box-sizing: border-box;
124
- }
125
-
126
- .body-textarea:focus {
127
- outline: none;
128
- border-color: var(--dx-g-color-brand, #0070d2);
129
- box-shadow: 0 0 0 1px var(--dx-g-color-brand, #0070d2);
130
- }
131
-
132
- .actions {
133
- margin: 16px 0;
134
- }
135
-
136
- .error-display {
137
- margin-top: 16px;
138
- padding: 12px;
139
- border-radius: 4px;
140
- background-color: #fef0ef;
141
- border: 1px solid #f93e3e;
142
- }
143
-
144
- .error-message {
145
- color: #c23934;
146
- font-size: 13px;
147
- margin: 0;
148
- }
149
-
150
- .response-section {
151
- margin-top: 16px;
152
- }
153
-
154
- .response-header {
155
- display: flex;
156
- align-items: center;
157
- gap: 12px;
158
- margin-bottom: 8px;
159
- }
160
-
161
- .status-code {
162
- font-weight: 700;
163
- font-size: 14px;
164
- padding: 2px 8px;
165
- border-radius: 4px;
166
- }
167
-
168
- .status-success {
169
- color: #256029;
170
- background-color: #e6f9ec;
171
- }
172
-
173
- .status-client-error {
174
- color: #974b00;
175
- background-color: #fff3e0;
176
- }
177
-
178
- .status-server-error {
179
- color: #c23934;
180
- background-color: #fef0ef;
181
- }
182
-
183
- .response-duration {
184
- font-size: 12px;
185
- color: var(--dx-g-color-text-tertiary, #999);
186
- }
@@ -1,136 +0,0 @@
1
- <template>
2
- <div class="playground-container">
3
- <div class="playground-header">
4
- <span class={methodBadgeClass}>{operation.method}</span>
5
- <span class="operation-path">{operation.path}</span>
6
- </div>
7
-
8
- <template lwc:if={showServerSelector}>
9
- <div class="field-group">
10
- <label class="field-label" for="server-select">Server</label>
11
- <select id="server-select" class="server-select" aria-label="Server" onchange={handleServerChange}>
12
- <template for:each={serverOptions} for:item="server">
13
- <option key={server.value} value={server.value}>
14
- {server.label}
15
- </option>
16
- </template>
17
- </select>
18
- </div>
19
- </template>
20
-
21
- <template lwc:if={hasPathParams}>
22
- <div class="params-section">
23
- <h4 class="section-title">Path Parameters</h4>
24
- <template for:each={pathParams} for:item="param">
25
- <div class="field-group" key={param.name}>
26
- <label class="field-label">
27
- {param.name}
28
- <template lwc:if={param.required}>
29
- <span class="required-marker">*</span>
30
- </template>
31
- </label>
32
- <input
33
- type="text"
34
- class="field-input"
35
- data-param={param.name}
36
- value={param.value}
37
- placeholder={param.description}
38
- onchange={handleParamChange}
39
- />
40
- </div>
41
- </template>
42
- </div>
43
- </template>
44
-
45
- <template lwc:if={hasQueryParams}>
46
- <div class="params-section">
47
- <h4 class="section-title">Query Parameters</h4>
48
- <template for:each={queryParams} for:item="param">
49
- <div class="field-group" key={param.name}>
50
- <label class="field-label">
51
- {param.name}
52
- <template lwc:if={param.required}>
53
- <span class="required-marker">*</span>
54
- </template>
55
- </label>
56
- <input
57
- type="text"
58
- class="field-input"
59
- data-param={param.name}
60
- value={param.value}
61
- placeholder={param.description}
62
- onchange={handleParamChange}
63
- />
64
- </div>
65
- </template>
66
- </div>
67
- </template>
68
-
69
- <template lwc:if={hasHeaderParams}>
70
- <div class="params-section">
71
- <h4 class="section-title">Headers</h4>
72
- <template for:each={headerParams} for:item="param">
73
- <div class="field-group" key={param.name}>
74
- <label class="field-label">
75
- {param.name}
76
- <template lwc:if={param.required}>
77
- <span class="required-marker">*</span>
78
- </template>
79
- </label>
80
- <input
81
- type="text"
82
- class="field-input"
83
- data-param={param.name}
84
- value={param.value}
85
- placeholder={param.description}
86
- onchange={handleParamChange}
87
- />
88
- </div>
89
- </template>
90
- </div>
91
- </template>
92
-
93
- <template lwc:if={hasRequestBody}>
94
- <div class="params-section">
95
- <h4 class="section-title">Request Body</h4>
96
- <textarea
97
- class="body-textarea"
98
- value={requestBody}
99
- onchange={handleBodyChange}
100
- rows="8"
101
- ></textarea>
102
- </div>
103
- </template>
104
-
105
- <div class="actions">
106
- <dx-button
107
- variant="brand"
108
- onclick={handleSendRequest}
109
- disabled={loading}
110
- >
111
- <template lwc:if={loading}>Sending...</template>
112
- <template lwc:else>Send Request</template>
113
- </dx-button>
114
- </div>
115
-
116
- <template lwc:if={hasError}>
117
- <div class="error-display">
118
- <p class="error-message">{error}</p>
119
- </div>
120
- </template>
121
-
122
- <template lwc:if={hasResponse}>
123
- <div class="response-section">
124
- <div class="response-header">
125
- <span class={responseStatusClass}>
126
- {response.status} {response.statusText}
127
- </span>
128
- <span class="response-duration">{response.duration}ms</span>
129
- </div>
130
- <dx-code-block
131
- language={responseLanguage}
132
- >{formattedResponseBody}</dx-code-block>
133
- </div>
134
- </template>
135
- </div>
136
- </template>
@@ -1,240 +0,0 @@
1
- import { LightningElement, api, track } from "lwc";
2
- import type {
3
- OperationDefinition,
4
- ParameterDefinition
5
- } from "docUtils/openApiParser";
6
- import {
7
- generateSampleFromSchema,
8
- resolveRef
9
- } from "docUtils/openApiParser";
10
- import {
11
- buildRequestUrl,
12
- executeRequest
13
- } from "docUtils/apiRequestExecutor";
14
- import type { ApiResponse } from "docUtils/apiRequestExecutor";
15
-
16
- type ParamState = {
17
- name: string;
18
- in: string;
19
- value: string;
20
- required: boolean;
21
- description: string;
22
- };
23
-
24
- export default class ApiPlayground extends LightningElement {
25
- @api operation!: OperationDefinition;
26
- @api spec: any;
27
-
28
- @track paramStates: ParamState[] = [];
29
- @track requestBody = "";
30
- @track selectedServer = "";
31
- @track response: ApiResponse | null = null;
32
- @track error: string | null = null;
33
- @track loading = false;
34
-
35
- private initialized = false;
36
-
37
- renderedCallback(): void {
38
- if (!this.initialized && this.operation) {
39
- this.initialized = true;
40
- this.initializeState();
41
- }
42
- }
43
-
44
- private initializeState(): void {
45
- this.paramStates = (this.operation.parameters ?? []).map(
46
- (param: ParameterDefinition) => ({
47
- name: param.name,
48
- in: param.in,
49
- value: param.example !== undefined ? String(param.example) : "",
50
- required: param.required,
51
- description: param.description
52
- })
53
- );
54
-
55
- if (this.operation.requestBody) {
56
- const content = this.operation.requestBody.content;
57
- const jsonContent = content?.["application/json"];
58
- if (jsonContent?.schema) {
59
- const sample = generateSampleFromSchema(
60
- jsonContent.schema,
61
- this.spec
62
- );
63
- if (sample !== undefined) {
64
- this.requestBody = JSON.stringify(sample, null, 2);
65
- }
66
- }
67
- }
68
-
69
- if (this.servers.length > 0) {
70
- this.selectedServer = this.servers[0].url;
71
- }
72
- }
73
-
74
- get servers(): Array<{ url: string; description: string }> {
75
- return (this.spec?.servers ?? []).map((s: any) => ({
76
- url: s.url ?? "",
77
- description: s.description ?? s.url ?? ""
78
- }));
79
- }
80
-
81
- get showServerSelector(): boolean {
82
- return this.servers.length > 1;
83
- }
84
-
85
- get serverOptions(): Array<{ label: string; value: string }> {
86
- return this.servers.map((s) => ({
87
- label: s.description || s.url,
88
- value: s.url
89
- }));
90
- }
91
-
92
- get pathParams(): ParamState[] {
93
- return this.paramStates.filter((p) => p.in === "path");
94
- }
95
-
96
- get queryParams(): ParamState[] {
97
- return this.paramStates.filter((p) => p.in === "query");
98
- }
99
-
100
- get headerParams(): ParamState[] {
101
- return this.paramStates.filter((p) => p.in === "header");
102
- }
103
-
104
- get hasPathParams(): boolean {
105
- return this.pathParams.length > 0;
106
- }
107
-
108
- get hasQueryParams(): boolean {
109
- return this.queryParams.length > 0;
110
- }
111
-
112
- get hasHeaderParams(): boolean {
113
- return this.headerParams.length > 0;
114
- }
115
-
116
- get hasRequestBody(): boolean {
117
- return this.operation?.requestBody !== null && this.operation?.requestBody !== undefined;
118
- }
119
-
120
- get methodBadgeClass(): string {
121
- const method = this.operation?.method?.toLowerCase() ?? "get";
122
- return `method-badge method-${method}`;
123
- }
124
-
125
- get responseStatusClass(): string {
126
- if (!this.response) {
127
- return "status-code";
128
- }
129
- const status = this.response.status;
130
- if (status >= 200 && status < 300) {
131
- return "status-code status-success";
132
- }
133
- if (status >= 400 && status < 500) {
134
- return "status-code status-client-error";
135
- }
136
- if (status >= 500) {
137
- return "status-code status-server-error";
138
- }
139
- return "status-code";
140
- }
141
-
142
- get hasResponse(): boolean {
143
- return this.response !== null;
144
- }
145
-
146
- get hasError(): boolean {
147
- return this.error !== null;
148
- }
149
-
150
- get formattedResponseBody(): string {
151
- if (!this.response?.body) {
152
- return "";
153
- }
154
- try {
155
- return JSON.stringify(JSON.parse(this.response.body), null, 2);
156
- } catch {
157
- return this.response.body;
158
- }
159
- }
160
-
161
- get responseLanguage(): string {
162
- if (!this.response?.body) {
163
- return "text";
164
- }
165
- try {
166
- JSON.parse(this.response.body);
167
- return "json";
168
- } catch {
169
- return "text";
170
- }
171
- }
172
-
173
- handleParamChange(event: Event): void {
174
- const target = event.target as HTMLInputElement;
175
- const paramName = target.dataset.param;
176
- this.paramStates = this.paramStates.map((p) =>
177
- p.name === paramName ? { ...p, value: target.value } : p
178
- );
179
- }
180
-
181
- handleBodyChange(event: Event): void {
182
- const target = event.target as HTMLTextAreaElement;
183
- this.requestBody = target.value;
184
- }
185
-
186
- handleServerChange(event: Event): void {
187
- const target = event.target as HTMLSelectElement;
188
- this.selectedServer = target.value;
189
- }
190
-
191
- async handleSendRequest(): Promise<void> {
192
- this.loading = true;
193
- this.response = null;
194
- this.error = null;
195
-
196
- try {
197
- const pathParams: Record<string, string> = {};
198
- const queryParams: Record<string, string> = {};
199
- const headers: Record<string, string> = {};
200
-
201
- for (const param of this.paramStates) {
202
- if (param.in === "path") {
203
- pathParams[param.name] = param.value;
204
- } else if (param.in === "query") {
205
- queryParams[param.name] = param.value;
206
- } else if (param.in === "header") {
207
- headers[param.name] = param.value;
208
- }
209
- }
210
-
211
- const serverUrl =
212
- this.selectedServer || this.servers[0]?.url || "";
213
- const url = buildRequestUrl(
214
- serverUrl,
215
- this.operation.path,
216
- pathParams,
217
- queryParams
218
- );
219
-
220
- if (this.hasRequestBody && this.requestBody) {
221
- headers["Content-Type"] =
222
- headers["Content-Type"] || "application/json";
223
- }
224
-
225
- this.response = await executeRequest({
226
- url,
227
- method: this.operation.method,
228
- headers,
229
- body: this.hasRequestBody ? this.requestBody : undefined
230
- });
231
- } catch (err: any) {
232
- this.error =
233
- err?.message?.includes("fetch")
234
- ? "Network error: The request failed. This may be due to CORS restrictions or a network issue."
235
- : err?.message || "An unexpected error occurred.";
236
- } finally {
237
- this.loading = false;
238
- }
239
- }
240
- }
@@ -1,96 +0,0 @@
1
- export type ApiRequest = {
2
- url: string;
3
- method: string;
4
- headers: Record<string, string>;
5
- body?: string;
6
- };
7
-
8
- export type ApiResponse = {
9
- status: number;
10
- statusText: string;
11
- headers: Record<string, string>;
12
- body: string;
13
- duration: number;
14
- };
15
-
16
- export type RequestExecutor = (request: ApiRequest) => Promise<ApiResponse>;
17
-
18
- export function buildRequestUrl(
19
- serverUrl: string,
20
- pathTemplate: string,
21
- pathParams: Record<string, string>,
22
- queryParams: Record<string, string>
23
- ): string {
24
- let url = pathTemplate;
25
- for (const [key, value] of Object.entries(pathParams)) {
26
- url = url.replace(`{${key}}`, encodeURIComponent(value));
27
- }
28
-
29
- const fullUrl = `${serverUrl.replace(/\/$/, "")}${url}`;
30
-
31
- const queryEntries = Object.entries(queryParams).filter(
32
- ([, v]) => v !== ""
33
- );
34
- if (queryEntries.length === 0) {
35
- return fullUrl;
36
- }
37
-
38
- const searchParams = new URLSearchParams();
39
- for (const [key, value] of queryEntries) {
40
- searchParams.append(key, value);
41
- }
42
- return `${fullUrl}?${searchParams.toString()}`;
43
- }
44
-
45
- export const directFetchExecutor: RequestExecutor = async (
46
- request: ApiRequest
47
- ): Promise<ApiResponse> => {
48
- const start = performance.now();
49
-
50
- const fetchOptions: RequestInit = {
51
- method: request.method,
52
- headers: request.headers,
53
- mode: "cors"
54
- };
55
-
56
- if (
57
- request.body &&
58
- request.method !== "GET" &&
59
- request.method !== "HEAD"
60
- ) {
61
- fetchOptions.body = request.body;
62
- }
63
-
64
- const response = await fetch(request.url, fetchOptions);
65
- const duration = Math.round(performance.now() - start);
66
-
67
- const responseHeaders: Record<string, string> = {};
68
- response.headers.forEach((value, key) => {
69
- responseHeaders[key] = value;
70
- });
71
-
72
- let body: string;
73
- try {
74
- body = await response.text();
75
- } catch {
76
- body = "";
77
- }
78
-
79
- return {
80
- status: response.status,
81
- statusText: response.statusText,
82
- headers: responseHeaders,
83
- body,
84
- duration
85
- };
86
- };
87
-
88
- let currentExecutor: RequestExecutor = directFetchExecutor;
89
-
90
- export function setRequestExecutor(executor: RequestExecutor): void {
91
- currentExecutor = executor;
92
- }
93
-
94
- export function executeRequest(request: ApiRequest): Promise<ApiResponse> {
95
- return currentExecutor(request);
96
- }