mira-form-sdk 1.0.4 → 1.2.4
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/dist/index.cjs +97 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +77 -1
- package/dist/index.d.ts +77 -1
- package/dist/index.mjs +94 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -20,7 +20,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var src_exports = {};
|
|
22
22
|
__export(src_exports, {
|
|
23
|
-
|
|
23
|
+
MiraCMS: () => MiraCMS,
|
|
24
|
+
MiraFormSDK: () => MiraFormSDK,
|
|
25
|
+
MiraResource: () => MiraResource
|
|
24
26
|
});
|
|
25
27
|
module.exports = __toCommonJS(src_exports);
|
|
26
28
|
|
|
@@ -86,8 +88,101 @@ var MiraFormSDK = class {
|
|
|
86
88
|
}
|
|
87
89
|
}
|
|
88
90
|
};
|
|
91
|
+
|
|
92
|
+
// src/constants.ts
|
|
93
|
+
var CMS_ENDPOINTS = {
|
|
94
|
+
CATEGORIES: "/api/v1/cms/categories",
|
|
95
|
+
ARTICLES_INDEXES: "/api/v1/cms/articles-indexes"
|
|
96
|
+
};
|
|
97
|
+
var DEFAULT_HEADERS = {
|
|
98
|
+
"Content-Type": "application/json"
|
|
99
|
+
};
|
|
100
|
+
var DEFAULT_ERROR_MESSAGE = "Unknown error";
|
|
101
|
+
|
|
102
|
+
// src/request.ts
|
|
103
|
+
async function sendRequest(endpoint, body, options) {
|
|
104
|
+
const url = `${options.baseUrl}${endpoint}`;
|
|
105
|
+
try {
|
|
106
|
+
const res = await fetch(url, {
|
|
107
|
+
method: "POST",
|
|
108
|
+
headers: {
|
|
109
|
+
...DEFAULT_HEADERS,
|
|
110
|
+
"Authorization": `Bearer ${options.apiKey}`
|
|
111
|
+
},
|
|
112
|
+
body: JSON.stringify(body)
|
|
113
|
+
});
|
|
114
|
+
const data = await res.json();
|
|
115
|
+
return {
|
|
116
|
+
success: res.ok,
|
|
117
|
+
data,
|
|
118
|
+
errors: !res.ok ? [data?.message || DEFAULT_ERROR_MESSAGE] : void 0
|
|
119
|
+
};
|
|
120
|
+
} catch (e) {
|
|
121
|
+
return { success: false, errors: [e.message] };
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// src/cms.ts
|
|
126
|
+
var MiraResource = class {
|
|
127
|
+
constructor(resourceId, apiKey, options) {
|
|
128
|
+
this.resourceId = resourceId;
|
|
129
|
+
this.apiKey = apiKey;
|
|
130
|
+
this.options = options;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Gets categories for the resource.
|
|
134
|
+
*
|
|
135
|
+
* @param {string} key - The key to identify the categories.
|
|
136
|
+
* @param {string} [lang] - Optional language code.
|
|
137
|
+
* @return {Promise<CMSResponse>} A promise that resolves to the categories data.
|
|
138
|
+
*/
|
|
139
|
+
async getCategories(key, lang) {
|
|
140
|
+
return sendRequest(
|
|
141
|
+
CMS_ENDPOINTS.CATEGORIES,
|
|
142
|
+
{ resourceId: this.resourceId, key, lang },
|
|
143
|
+
{ baseUrl: this.options.baseUrl, apiKey: this.apiKey }
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Gets articles indexes for the resource.
|
|
148
|
+
*
|
|
149
|
+
* @param {string} key - The key to identify the articles index (e.g., 'blog/articles-index.json').
|
|
150
|
+
* @param {string} [lang] - Optional language code (e.g., 'en').
|
|
151
|
+
* @return {Promise<CMSResponse>} A promise that resolves to the articles indexes data.
|
|
152
|
+
*/
|
|
153
|
+
async getArticlesIndexes(key, lang) {
|
|
154
|
+
return sendRequest(
|
|
155
|
+
CMS_ENDPOINTS.ARTICLES_INDEXES,
|
|
156
|
+
{ resourceId: this.resourceId, key, lang },
|
|
157
|
+
{ baseUrl: this.options.baseUrl, apiKey: this.apiKey }
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
var MiraCMS = class {
|
|
162
|
+
/**
|
|
163
|
+
* Creates a new MiraCMS instance.
|
|
164
|
+
*
|
|
165
|
+
* @param {string} apiKey - The API key for authentication.
|
|
166
|
+
* @param {MiraCMSOptions} [options] - Optional configuration options.
|
|
167
|
+
*/
|
|
168
|
+
constructor(apiKey, options) {
|
|
169
|
+
this.apiKey = apiKey;
|
|
170
|
+
this.options = options || {};
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Initializes a resource instance for the given resource ID.
|
|
174
|
+
*
|
|
175
|
+
* @param {string} resourceId - The UUID of the resource.
|
|
176
|
+
* @return {MiraResource} A resource instance with methods to interact with CMS content.
|
|
177
|
+
*/
|
|
178
|
+
initResource(resourceId) {
|
|
179
|
+
return new MiraResource(resourceId, this.apiKey, this.options);
|
|
180
|
+
}
|
|
181
|
+
};
|
|
89
182
|
// Annotate the CommonJS export names for ESM import in node:
|
|
90
183
|
0 && (module.exports = {
|
|
91
|
-
|
|
184
|
+
MiraCMS,
|
|
185
|
+
MiraFormSDK,
|
|
186
|
+
MiraResource
|
|
92
187
|
});
|
|
93
188
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/sdk.ts"],"sourcesContent":["export { MiraFormSDK } from './sdk';\nexport type { MiraFormSDKOptions } from './types';\n\n","import { MiraFormSDKOptions } from './types';\nimport {\n PrepareFormDataParams,\n PreparedFormData,\n SendFormResponse,\n} from './types';\n\n\n/**\n * A class to interact with the MiraForm API for creating and sending form data.\n */\nexport class MiraFormSDK {\n private readonly apiKey: string;\n private options: MiraFormSDKOptions;\n\n constructor(apiKey: string, options?: MiraFormSDKOptions) {\n this.apiKey = apiKey;\n this.options = options || {};\n }\n\n\n /**\n * Prepares form data for submission by validating the input parameters and appending them to a FormData object.\n *\n * @param {PrepareFormDataParams} params - The input parameters for preparing the form data.\n * - resourceId: The ID of the resource (required).\n * - formId: The ID of the form (required).\n * - content: The content object to include (optional, must be a valid object).\n * - files: An array of files to include in the form data (optional).\n *\n * @return {PreparedFormData} An object containing the prepared FormData object or error messages if validation fails.\n */\n public prepareFormData(params: PrepareFormDataParams): PreparedFormData {\n const { resourceId, formId, content, files } = params;\n const errors: string[] = [];\n if (!resourceId) errors.push('resourceId is required');\n if (!formId) errors.push('formId is required');\n if (content && typeof content !== 'object') errors.push('content must be a valid object');\n if (errors.length) return { formData: null as any, errors };\n\n const formData = new FormData();\n formData.append('resourceId', params.resourceId);\n formData.append('formId', params.formId);\n formData.append('content', JSON.stringify(params.content));\n\n if (files) {\n for (const file of files) {\n formData.append('files', file as any);\n }\n }\n\n return { formData };\n }\n\n /**\n * Sends a form to the specified API endpoint.\n *\n * @param {FormData} formData - The form data to be sent to the server.\n * @return {Promise<SendFormResponse>} A promise that resolves to an object indicating the success of the operation, the server response data, and any errors encountered.\n */\n public async sendForm(formData: FormData): Promise<SendFormResponse> {\n const url = `${this.options.baseUrl}/api/v1/send`;\n try {\n const res = await fetch(url, {\n method: 'POST',\n headers: {\n 'Authorization': `Bearer ${this.apiKey}`,\n },\n body: formData,\n });\n const data = await res.json();\n return { success: res.ok, data, errors: !res.ok ? [data?.message || 'Unknown error'] : undefined };\n } catch (e: any) {\n return { success: false, errors: [e.message] };\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACWO,IAAM,cAAN,MAAkB;AAAA,EAIvB,YAAY,QAAgB,SAA8B;AACxD,SAAK,SAAS;AACd,SAAK,UAAU,WAAW,CAAC;AAAA,EAC7B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAcO,gBAAgB,QAAiD;AACtE,UAAM,EAAE,YAAY,QAAQ,SAAS,MAAM,IAAI;AAC/C,UAAM,SAAmB,CAAC;AAC1B,QAAI,CAAC;AAAY,aAAO,KAAK,wBAAwB;AACrD,QAAI,CAAC;AAAQ,aAAO,KAAK,oBAAoB;AAC7C,QAAI,WAAW,OAAO,YAAY;AAAU,aAAO,KAAK,gCAAgC;AACxF,QAAI,OAAO;AAAQ,aAAO,EAAE,UAAU,MAAa,OAAO;AAE1D,UAAM,WAAW,IAAI,SAAS;AAC9B,aAAS,OAAO,cAAc,OAAO,UAAU;AAC/C,aAAS,OAAO,UAAU,OAAO,MAAM;AACvC,aAAS,OAAO,WAAW,KAAK,UAAU,OAAO,OAAO,CAAC;AAEzD,QAAI,OAAO;AACT,iBAAW,QAAQ,OAAO;AACxB,iBAAS,OAAO,SAAS,IAAW;AAAA,MACtC;AAAA,IACF;AAEA,WAAO,EAAE,SAAS;AAAA,EACpB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAa,SAAS,UAA+C;AACnE,UAAM,MAAM,GAAG,KAAK,QAAQ,OAAO;AACnC,QAAI;AACF,YAAM,MAAM,MAAM,MAAM,KAAK;AAAA,QAC3B,QAAQ;AAAA,QACR,SAAS;AAAA,UACP,iBAAiB,UAAU,KAAK,MAAM;AAAA,QACxC;AAAA,QACA,MAAM;AAAA,MACR,CAAC;AACD,YAAM,OAAO,MAAM,IAAI,KAAK;AAC5B,aAAO,EAAE,SAAS,IAAI,IAAI,MAAM,QAAQ,CAAC,IAAI,KAAK,CAAC,MAAM,WAAW,eAAe,IAAI,OAAU;AAAA,IACnG,SAAS,GAAQ;AACf,aAAO,EAAE,SAAS,OAAO,QAAQ,CAAC,EAAE,OAAO,EAAE;AAAA,IAC/C;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/sdk.ts","../src/constants.ts","../src/request.ts","../src/cms.ts"],"sourcesContent":["export { MiraFormSDK } from './sdk';\nexport { MiraCMS, MiraResource } from './cms';\nexport type {\n MiraFormSDKOptions,\n MiraCMSOptions,\n CMSResponse,\n GetArticlesIndexesParams,\n GetCategoriesParams,\n PrepareFormDataParams,\n PreparedFormData,\n SendFormResponse\n} from './types';\n","import { MiraFormSDKOptions } from './types';\nimport {\n PrepareFormDataParams,\n PreparedFormData,\n SendFormResponse,\n} from './types';\n\n\n/**\n * A class to interact with the MiraForm API for creating and sending form data.\n */\nexport class MiraFormSDK {\n private readonly apiKey: string;\n private options: MiraFormSDKOptions;\n\n constructor(apiKey: string, options?: MiraFormSDKOptions) {\n this.apiKey = apiKey;\n this.options = options || {};\n }\n\n\n /**\n * Prepares form data for submission by validating the input parameters and appending them to a FormData object.\n *\n * @param {PrepareFormDataParams} params - The input parameters for preparing the form data.\n * - resourceId: The ID of the resource (required).\n * - formId: The ID of the form (required).\n * - content: The content object to include (optional, must be a valid object).\n * - files: An array of files to include in the form data (optional).\n *\n * @return {PreparedFormData} An object containing the prepared FormData object or error messages if validation fails.\n */\n public prepareFormData(params: PrepareFormDataParams): PreparedFormData {\n const { resourceId, formId, content, files } = params;\n const errors: string[] = [];\n if (!resourceId) errors.push('resourceId is required');\n if (!formId) errors.push('formId is required');\n if (content && typeof content !== 'object') errors.push('content must be a valid object');\n if (errors.length) return { formData: null as any, errors };\n\n const formData = new FormData();\n formData.append('resourceId', params.resourceId);\n formData.append('formId', params.formId);\n formData.append('content', JSON.stringify(params.content));\n\n if (files) {\n for (const file of files) {\n formData.append('files', file as any);\n }\n }\n\n return { formData };\n }\n\n /**\n * Sends a form to the specified API endpoint.\n *\n * @param {FormData} formData - The form data to be sent to the server.\n * @return {Promise<SendFormResponse>} A promise that resolves to an object indicating the success of the operation, the server response data, and any errors encountered.\n */\n public async sendForm(formData: FormData): Promise<SendFormResponse> {\n const url = `${this.options.baseUrl}/api/v1/send`;\n try {\n const res = await fetch(url, {\n method: 'POST',\n headers: {\n 'Authorization': `Bearer ${this.apiKey}`,\n },\n body: formData,\n });\n const data = await res.json();\n return { success: res.ok, data, errors: !res.ok ? [data?.message || 'Unknown error'] : undefined };\n } catch (e: any) {\n return { success: false, errors: [e.message] };\n }\n }\n}\n","/**\n * CMS API endpoints constants.\n */\nexport const CMS_ENDPOINTS = {\n CATEGORIES: '/api/v1/cms/categories',\n ARTICLES_INDEXES: '/api/v1/cms/articles-indexes',\n} as const;\n\n/**\n * Default HTTP headers for CMS API requests.\n */\nexport const DEFAULT_HEADERS = {\n 'Content-Type': 'application/json',\n} as const;\n\n/**\n * Default error message when API response doesn't contain one.\n */\nexport const DEFAULT_ERROR_MESSAGE = 'Unknown error';\n\n","import { CMSResponse } from './types';\nimport { DEFAULT_HEADERS, DEFAULT_ERROR_MESSAGE } from './constants';\n\nexport interface RequestOptions {\n baseUrl: string;\n apiKey: string;\n}\n\nexport interface RequestBody {\n resourceId: string;\n key: string;\n lang?: string;\n}\n\n/**\n * Sends a POST request to the CMS API.\n *\n * @param {string} endpoint - The API endpoint path.\n * @param {RequestBody} body - The request body.\n * @param {RequestOptions} options - Request configuration options.\n * @return {Promise<CMSResponse>} A promise that resolves to the API response.\n */\nexport async function sendRequest(\n endpoint: string,\n body: RequestBody,\n options: RequestOptions\n): Promise<CMSResponse> {\n const url = `${options.baseUrl}${endpoint}`;\n try {\n const res = await fetch(url, {\n method: 'POST',\n headers: {\n ...DEFAULT_HEADERS,\n 'Authorization': `Bearer ${options.apiKey}`,\n },\n body: JSON.stringify(body),\n });\n const data = await res.json();\n return {\n success: res.ok,\n data,\n errors: !res.ok ? [data?.message || DEFAULT_ERROR_MESSAGE] : undefined,\n };\n } catch (e: any) {\n return { success: false, errors: [e.message] };\n }\n}\n","import { MiraCMSOptions, CMSResponse } from './types';\nimport { CMS_ENDPOINTS } from './constants';\nimport { sendRequest } from './request';\n\n/**\n * Represents a resource instance for interacting with CMS content.\n */\nexport class MiraResource {\n private readonly resourceId: string;\n private readonly apiKey: string;\n private readonly options: MiraCMSOptions;\n\n constructor(resourceId: string, apiKey: string, options: MiraCMSOptions) {\n this.resourceId = resourceId;\n this.apiKey = apiKey;\n this.options = options;\n }\n\n /**\n * Gets categories for the resource.\n *\n * @param {string} key - The key to identify the categories.\n * @param {string} [lang] - Optional language code.\n * @return {Promise<CMSResponse>} A promise that resolves to the categories data.\n */\n public async getCategories(key: string, lang?: string): Promise<CMSResponse> {\n return sendRequest(\n CMS_ENDPOINTS.CATEGORIES,\n { resourceId: this.resourceId, key, lang },\n { baseUrl: this.options.baseUrl!, apiKey: this.apiKey }\n );\n }\n\n /**\n * Gets articles indexes for the resource.\n *\n * @param {string} key - The key to identify the articles index (e.g., 'blog/articles-index.json').\n * @param {string} [lang] - Optional language code (e.g., 'en').\n * @return {Promise<CMSResponse>} A promise that resolves to the articles indexes data.\n */\n public async getArticlesIndexes(key: string, lang?: string): Promise<CMSResponse> {\n return sendRequest(\n CMS_ENDPOINTS.ARTICLES_INDEXES,\n { resourceId: this.resourceId, key, lang },\n { baseUrl: this.options.baseUrl!, apiKey: this.apiKey }\n );\n }\n}\n\n/**\n * MiraCMS SDK for interacting with CMS content like categories and articles.\n */\nexport class MiraCMS {\n private readonly apiKey: string;\n private readonly options: MiraCMSOptions;\n\n /**\n * Creates a new MiraCMS instance.\n *\n * @param {string} apiKey - The API key for authentication.\n * @param {MiraCMSOptions} [options] - Optional configuration options.\n */\n constructor(apiKey: string, options?: MiraCMSOptions) {\n this.apiKey = apiKey;\n this.options = options || {};\n }\n\n /**\n * Initializes a resource instance for the given resource ID.\n *\n * @param {string} resourceId - The UUID of the resource.\n * @return {MiraResource} A resource instance with methods to interact with CMS content.\n */\n public initResource(resourceId: string): MiraResource {\n return new MiraResource(resourceId, this.apiKey, this.options);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACWO,IAAM,cAAN,MAAkB;AAAA,EAIvB,YAAY,QAAgB,SAA8B;AACxD,SAAK,SAAS;AACd,SAAK,UAAU,WAAW,CAAC;AAAA,EAC7B;AAAA;AAAA;AAAA;AAAA;AAAA;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;AAAA,IACxD;AAAA,EACF;AACF;AAKO,IAAM,UAAN,MAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUnB,YAAY,QAAgB,SAA0B;AACpD,SAAK,SAAS;AACd,SAAK,UAAU,WAAW,CAAC;AAAA,EAC7B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQO,aAAa,YAAkC;AACpD,WAAO,IAAI,aAAa,YAAY,KAAK,QAAQ,KAAK,OAAO;AAAA,EAC/D;AACF;","names":[]}
|
package/dist/index.d.mts
CHANGED
|
@@ -59,6 +59,35 @@ interface SendFormResponse {
|
|
|
59
59
|
data?: any;
|
|
60
60
|
errors?: string[];
|
|
61
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Configuration options for the MiraCMS SDK.
|
|
64
|
+
*/
|
|
65
|
+
interface MiraCMSOptions {
|
|
66
|
+
baseUrl?: string;
|
|
67
|
+
timeout?: number;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Parameters for getting articles indexes.
|
|
71
|
+
*/
|
|
72
|
+
interface GetArticlesIndexesParams {
|
|
73
|
+
key: string;
|
|
74
|
+
lang?: string;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Parameters for getting categories.
|
|
78
|
+
*/
|
|
79
|
+
interface GetCategoriesParams {
|
|
80
|
+
key: string;
|
|
81
|
+
lang?: string;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Response from CMS API requests.
|
|
85
|
+
*/
|
|
86
|
+
interface CMSResponse<T = any> {
|
|
87
|
+
success: boolean;
|
|
88
|
+
data?: T;
|
|
89
|
+
errors?: string[];
|
|
90
|
+
}
|
|
62
91
|
|
|
63
92
|
/**
|
|
64
93
|
* A class to interact with the MiraForm API for creating and sending form data.
|
|
@@ -88,4 +117,51 @@ declare class MiraFormSDK {
|
|
|
88
117
|
sendForm(formData: FormData): Promise<SendFormResponse>;
|
|
89
118
|
}
|
|
90
119
|
|
|
91
|
-
|
|
120
|
+
/**
|
|
121
|
+
* Represents a resource instance for interacting with CMS content.
|
|
122
|
+
*/
|
|
123
|
+
declare class MiraResource {
|
|
124
|
+
private readonly resourceId;
|
|
125
|
+
private readonly apiKey;
|
|
126
|
+
private readonly options;
|
|
127
|
+
constructor(resourceId: string, apiKey: string, options: MiraCMSOptions);
|
|
128
|
+
/**
|
|
129
|
+
* Gets categories for the resource.
|
|
130
|
+
*
|
|
131
|
+
* @param {string} key - The key to identify the categories.
|
|
132
|
+
* @param {string} [lang] - Optional language code.
|
|
133
|
+
* @return {Promise<CMSResponse>} A promise that resolves to the categories data.
|
|
134
|
+
*/
|
|
135
|
+
getCategories(key: string, lang?: string): Promise<CMSResponse>;
|
|
136
|
+
/**
|
|
137
|
+
* Gets articles indexes for the resource.
|
|
138
|
+
*
|
|
139
|
+
* @param {string} key - The key to identify the articles index (e.g., 'blog/articles-index.json').
|
|
140
|
+
* @param {string} [lang] - Optional language code (e.g., 'en').
|
|
141
|
+
* @return {Promise<CMSResponse>} A promise that resolves to the articles indexes data.
|
|
142
|
+
*/
|
|
143
|
+
getArticlesIndexes(key: string, lang?: string): Promise<CMSResponse>;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* MiraCMS SDK for interacting with CMS content like categories and articles.
|
|
147
|
+
*/
|
|
148
|
+
declare class MiraCMS {
|
|
149
|
+
private readonly apiKey;
|
|
150
|
+
private readonly options;
|
|
151
|
+
/**
|
|
152
|
+
* Creates a new MiraCMS instance.
|
|
153
|
+
*
|
|
154
|
+
* @param {string} apiKey - The API key for authentication.
|
|
155
|
+
* @param {MiraCMSOptions} [options] - Optional configuration options.
|
|
156
|
+
*/
|
|
157
|
+
constructor(apiKey: string, options?: MiraCMSOptions);
|
|
158
|
+
/**
|
|
159
|
+
* Initializes a resource instance for the given resource ID.
|
|
160
|
+
*
|
|
161
|
+
* @param {string} resourceId - The UUID of the resource.
|
|
162
|
+
* @return {MiraResource} A resource instance with methods to interact with CMS content.
|
|
163
|
+
*/
|
|
164
|
+
initResource(resourceId: string): MiraResource;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export { CMSResponse, GetArticlesIndexesParams, GetCategoriesParams, MiraCMS, MiraCMSOptions, MiraFormSDK, MiraFormSDKOptions, MiraResource, PrepareFormDataParams, PreparedFormData, SendFormResponse };
|
package/dist/index.d.ts
CHANGED
|
@@ -59,6 +59,35 @@ interface SendFormResponse {
|
|
|
59
59
|
data?: any;
|
|
60
60
|
errors?: string[];
|
|
61
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Configuration options for the MiraCMS SDK.
|
|
64
|
+
*/
|
|
65
|
+
interface MiraCMSOptions {
|
|
66
|
+
baseUrl?: string;
|
|
67
|
+
timeout?: number;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Parameters for getting articles indexes.
|
|
71
|
+
*/
|
|
72
|
+
interface GetArticlesIndexesParams {
|
|
73
|
+
key: string;
|
|
74
|
+
lang?: string;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Parameters for getting categories.
|
|
78
|
+
*/
|
|
79
|
+
interface GetCategoriesParams {
|
|
80
|
+
key: string;
|
|
81
|
+
lang?: string;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Response from CMS API requests.
|
|
85
|
+
*/
|
|
86
|
+
interface CMSResponse<T = any> {
|
|
87
|
+
success: boolean;
|
|
88
|
+
data?: T;
|
|
89
|
+
errors?: string[];
|
|
90
|
+
}
|
|
62
91
|
|
|
63
92
|
/**
|
|
64
93
|
* A class to interact with the MiraForm API for creating and sending form data.
|
|
@@ -88,4 +117,51 @@ declare class MiraFormSDK {
|
|
|
88
117
|
sendForm(formData: FormData): Promise<SendFormResponse>;
|
|
89
118
|
}
|
|
90
119
|
|
|
91
|
-
|
|
120
|
+
/**
|
|
121
|
+
* Represents a resource instance for interacting with CMS content.
|
|
122
|
+
*/
|
|
123
|
+
declare class MiraResource {
|
|
124
|
+
private readonly resourceId;
|
|
125
|
+
private readonly apiKey;
|
|
126
|
+
private readonly options;
|
|
127
|
+
constructor(resourceId: string, apiKey: string, options: MiraCMSOptions);
|
|
128
|
+
/**
|
|
129
|
+
* Gets categories for the resource.
|
|
130
|
+
*
|
|
131
|
+
* @param {string} key - The key to identify the categories.
|
|
132
|
+
* @param {string} [lang] - Optional language code.
|
|
133
|
+
* @return {Promise<CMSResponse>} A promise that resolves to the categories data.
|
|
134
|
+
*/
|
|
135
|
+
getCategories(key: string, lang?: string): Promise<CMSResponse>;
|
|
136
|
+
/**
|
|
137
|
+
* Gets articles indexes for the resource.
|
|
138
|
+
*
|
|
139
|
+
* @param {string} key - The key to identify the articles index (e.g., 'blog/articles-index.json').
|
|
140
|
+
* @param {string} [lang] - Optional language code (e.g., 'en').
|
|
141
|
+
* @return {Promise<CMSResponse>} A promise that resolves to the articles indexes data.
|
|
142
|
+
*/
|
|
143
|
+
getArticlesIndexes(key: string, lang?: string): Promise<CMSResponse>;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* MiraCMS SDK for interacting with CMS content like categories and articles.
|
|
147
|
+
*/
|
|
148
|
+
declare class MiraCMS {
|
|
149
|
+
private readonly apiKey;
|
|
150
|
+
private readonly options;
|
|
151
|
+
/**
|
|
152
|
+
* Creates a new MiraCMS instance.
|
|
153
|
+
*
|
|
154
|
+
* @param {string} apiKey - The API key for authentication.
|
|
155
|
+
* @param {MiraCMSOptions} [options] - Optional configuration options.
|
|
156
|
+
*/
|
|
157
|
+
constructor(apiKey: string, options?: MiraCMSOptions);
|
|
158
|
+
/**
|
|
159
|
+
* Initializes a resource instance for the given resource ID.
|
|
160
|
+
*
|
|
161
|
+
* @param {string} resourceId - The UUID of the resource.
|
|
162
|
+
* @return {MiraResource} A resource instance with methods to interact with CMS content.
|
|
163
|
+
*/
|
|
164
|
+
initResource(resourceId: string): MiraResource;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export { CMSResponse, GetArticlesIndexesParams, GetCategoriesParams, MiraCMS, MiraCMSOptions, MiraFormSDK, MiraFormSDKOptions, MiraResource, PrepareFormDataParams, PreparedFormData, SendFormResponse };
|
package/dist/index.mjs
CHANGED
|
@@ -60,7 +60,100 @@ var MiraFormSDK = class {
|
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
};
|
|
63
|
+
|
|
64
|
+
// src/constants.ts
|
|
65
|
+
var CMS_ENDPOINTS = {
|
|
66
|
+
CATEGORIES: "/api/v1/cms/categories",
|
|
67
|
+
ARTICLES_INDEXES: "/api/v1/cms/articles-indexes"
|
|
68
|
+
};
|
|
69
|
+
var DEFAULT_HEADERS = {
|
|
70
|
+
"Content-Type": "application/json"
|
|
71
|
+
};
|
|
72
|
+
var DEFAULT_ERROR_MESSAGE = "Unknown error";
|
|
73
|
+
|
|
74
|
+
// src/request.ts
|
|
75
|
+
async function sendRequest(endpoint, body, options) {
|
|
76
|
+
const url = `${options.baseUrl}${endpoint}`;
|
|
77
|
+
try {
|
|
78
|
+
const res = await fetch(url, {
|
|
79
|
+
method: "POST",
|
|
80
|
+
headers: {
|
|
81
|
+
...DEFAULT_HEADERS,
|
|
82
|
+
"Authorization": `Bearer ${options.apiKey}`
|
|
83
|
+
},
|
|
84
|
+
body: JSON.stringify(body)
|
|
85
|
+
});
|
|
86
|
+
const data = await res.json();
|
|
87
|
+
return {
|
|
88
|
+
success: res.ok,
|
|
89
|
+
data,
|
|
90
|
+
errors: !res.ok ? [data?.message || DEFAULT_ERROR_MESSAGE] : void 0
|
|
91
|
+
};
|
|
92
|
+
} catch (e) {
|
|
93
|
+
return { success: false, errors: [e.message] };
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// src/cms.ts
|
|
98
|
+
var MiraResource = class {
|
|
99
|
+
constructor(resourceId, apiKey, options) {
|
|
100
|
+
this.resourceId = resourceId;
|
|
101
|
+
this.apiKey = apiKey;
|
|
102
|
+
this.options = options;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Gets categories for the resource.
|
|
106
|
+
*
|
|
107
|
+
* @param {string} key - The key to identify the categories.
|
|
108
|
+
* @param {string} [lang] - Optional language code.
|
|
109
|
+
* @return {Promise<CMSResponse>} A promise that resolves to the categories data.
|
|
110
|
+
*/
|
|
111
|
+
async getCategories(key, lang) {
|
|
112
|
+
return sendRequest(
|
|
113
|
+
CMS_ENDPOINTS.CATEGORIES,
|
|
114
|
+
{ resourceId: this.resourceId, key, lang },
|
|
115
|
+
{ baseUrl: this.options.baseUrl, apiKey: this.apiKey }
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Gets articles indexes for the resource.
|
|
120
|
+
*
|
|
121
|
+
* @param {string} key - The key to identify the articles index (e.g., 'blog/articles-index.json').
|
|
122
|
+
* @param {string} [lang] - Optional language code (e.g., 'en').
|
|
123
|
+
* @return {Promise<CMSResponse>} A promise that resolves to the articles indexes data.
|
|
124
|
+
*/
|
|
125
|
+
async getArticlesIndexes(key, lang) {
|
|
126
|
+
return sendRequest(
|
|
127
|
+
CMS_ENDPOINTS.ARTICLES_INDEXES,
|
|
128
|
+
{ resourceId: this.resourceId, key, lang },
|
|
129
|
+
{ baseUrl: this.options.baseUrl, apiKey: this.apiKey }
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
var MiraCMS = class {
|
|
134
|
+
/**
|
|
135
|
+
* Creates a new MiraCMS instance.
|
|
136
|
+
*
|
|
137
|
+
* @param {string} apiKey - The API key for authentication.
|
|
138
|
+
* @param {MiraCMSOptions} [options] - Optional configuration options.
|
|
139
|
+
*/
|
|
140
|
+
constructor(apiKey, options) {
|
|
141
|
+
this.apiKey = apiKey;
|
|
142
|
+
this.options = options || {};
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Initializes a resource instance for the given resource ID.
|
|
146
|
+
*
|
|
147
|
+
* @param {string} resourceId - The UUID of the resource.
|
|
148
|
+
* @return {MiraResource} A resource instance with methods to interact with CMS content.
|
|
149
|
+
*/
|
|
150
|
+
initResource(resourceId) {
|
|
151
|
+
return new MiraResource(resourceId, this.apiKey, this.options);
|
|
152
|
+
}
|
|
153
|
+
};
|
|
63
154
|
export {
|
|
64
|
-
|
|
155
|
+
MiraCMS,
|
|
156
|
+
MiraFormSDK,
|
|
157
|
+
MiraResource
|
|
65
158
|
};
|
|
66
159
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/sdk.ts"],"sourcesContent":["import { MiraFormSDKOptions } from './types';\nimport {\n PrepareFormDataParams,\n PreparedFormData,\n SendFormResponse,\n} from './types';\n\n\n/**\n * A class to interact with the MiraForm API for creating and sending form data.\n */\nexport class MiraFormSDK {\n private readonly apiKey: string;\n private options: MiraFormSDKOptions;\n\n constructor(apiKey: string, options?: MiraFormSDKOptions) {\n this.apiKey = apiKey;\n this.options = options || {};\n }\n\n\n /**\n * Prepares form data for submission by validating the input parameters and appending them to a FormData object.\n *\n * @param {PrepareFormDataParams} params - The input parameters for preparing the form data.\n * - resourceId: The ID of the resource (required).\n * - formId: The ID of the form (required).\n * - content: The content object to include (optional, must be a valid object).\n * - files: An array of files to include in the form data (optional).\n *\n * @return {PreparedFormData} An object containing the prepared FormData object or error messages if validation fails.\n */\n public prepareFormData(params: PrepareFormDataParams): PreparedFormData {\n const { resourceId, formId, content, files } = params;\n const errors: string[] = [];\n if (!resourceId) errors.push('resourceId is required');\n if (!formId) errors.push('formId is required');\n if (content && typeof content !== 'object') errors.push('content must be a valid object');\n if (errors.length) return { formData: null as any, errors };\n\n const formData = new FormData();\n formData.append('resourceId', params.resourceId);\n formData.append('formId', params.formId);\n formData.append('content', JSON.stringify(params.content));\n\n if (files) {\n for (const file of files) {\n formData.append('files', file as any);\n }\n }\n\n return { formData };\n }\n\n /**\n * Sends a form to the specified API endpoint.\n *\n * @param {FormData} formData - The form data to be sent to the server.\n * @return {Promise<SendFormResponse>} A promise that resolves to an object indicating the success of the operation, the server response data, and any errors encountered.\n */\n public async sendForm(formData: FormData): Promise<SendFormResponse> {\n const url = `${this.options.baseUrl}/api/v1/send`;\n try {\n const res = await fetch(url, {\n method: 'POST',\n headers: {\n 'Authorization': `Bearer ${this.apiKey}`,\n },\n body: formData,\n });\n const data = await res.json();\n return { success: res.ok, data, errors: !res.ok ? [data?.message || 'Unknown error'] : undefined };\n } catch (e: any) {\n return { success: false, errors: [e.message] };\n }\n }\n}\n"],"mappings":";AAWO,IAAM,cAAN,MAAkB;AAAA,EAIvB,YAAY,QAAgB,SAA8B;AACxD,SAAK,SAAS;AACd,SAAK,UAAU,WAAW,CAAC;AAAA,EAC7B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAcO,gBAAgB,QAAiD;AACtE,UAAM,EAAE,YAAY,QAAQ,SAAS,MAAM,IAAI;AAC/C,UAAM,SAAmB,CAAC;AAC1B,QAAI,CAAC;AAAY,aAAO,KAAK,wBAAwB;AACrD,QAAI,CAAC;AAAQ,aAAO,KAAK,oBAAoB;AAC7C,QAAI,WAAW,OAAO,YAAY;AAAU,aAAO,KAAK,gCAAgC;AACxF,QAAI,OAAO;AAAQ,aAAO,EAAE,UAAU,MAAa,OAAO;AAE1D,UAAM,WAAW,IAAI,SAAS;AAC9B,aAAS,OAAO,cAAc,OAAO,UAAU;AAC/C,aAAS,OAAO,UAAU,OAAO,MAAM;AACvC,aAAS,OAAO,WAAW,KAAK,UAAU,OAAO,OAAO,CAAC;AAEzD,QAAI,OAAO;AACT,iBAAW,QAAQ,OAAO;AACxB,iBAAS,OAAO,SAAS,IAAW;AAAA,MACtC;AAAA,IACF;AAEA,WAAO,EAAE,SAAS;AAAA,EACpB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAa,SAAS,UAA+C;AACnE,UAAM,MAAM,GAAG,KAAK,QAAQ,OAAO;AACnC,QAAI;AACF,YAAM,MAAM,MAAM,MAAM,KAAK;AAAA,QAC3B,QAAQ;AAAA,QACR,SAAS;AAAA,UACP,iBAAiB,UAAU,KAAK,MAAM;AAAA,QACxC;AAAA,QACA,MAAM;AAAA,MACR,CAAC;AACD,YAAM,OAAO,MAAM,IAAI,KAAK;AAC5B,aAAO,EAAE,SAAS,IAAI,IAAI,MAAM,QAAQ,CAAC,IAAI,KAAK,CAAC,MAAM,WAAW,eAAe,IAAI,OAAU;AAAA,IACnG,SAAS,GAAQ;AACf,aAAO,EAAE,SAAS,OAAO,QAAQ,CAAC,EAAE,OAAO,EAAE;AAAA,IAC/C;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/sdk.ts","../src/constants.ts","../src/request.ts","../src/cms.ts"],"sourcesContent":["import { MiraFormSDKOptions } from './types';\nimport {\n PrepareFormDataParams,\n PreparedFormData,\n SendFormResponse,\n} from './types';\n\n\n/**\n * A class to interact with the MiraForm API for creating and sending form data.\n */\nexport class MiraFormSDK {\n private readonly apiKey: string;\n private options: MiraFormSDKOptions;\n\n constructor(apiKey: string, options?: MiraFormSDKOptions) {\n this.apiKey = apiKey;\n this.options = options || {};\n }\n\n\n /**\n * Prepares form data for submission by validating the input parameters and appending them to a FormData object.\n *\n * @param {PrepareFormDataParams} params - The input parameters for preparing the form data.\n * - resourceId: The ID of the resource (required).\n * - formId: The ID of the form (required).\n * - content: The content object to include (optional, must be a valid object).\n * - files: An array of files to include in the form data (optional).\n *\n * @return {PreparedFormData} An object containing the prepared FormData object or error messages if validation fails.\n */\n public prepareFormData(params: PrepareFormDataParams): PreparedFormData {\n const { resourceId, formId, content, files } = params;\n const errors: string[] = [];\n if (!resourceId) errors.push('resourceId is required');\n if (!formId) errors.push('formId is required');\n if (content && typeof content !== 'object') errors.push('content must be a valid object');\n if (errors.length) return { formData: null as any, errors };\n\n const formData = new FormData();\n formData.append('resourceId', params.resourceId);\n formData.append('formId', params.formId);\n formData.append('content', JSON.stringify(params.content));\n\n if (files) {\n for (const file of files) {\n formData.append('files', file as any);\n }\n }\n\n return { formData };\n }\n\n /**\n * Sends a form to the specified API endpoint.\n *\n * @param {FormData} formData - The form data to be sent to the server.\n * @return {Promise<SendFormResponse>} A promise that resolves to an object indicating the success of the operation, the server response data, and any errors encountered.\n */\n public async sendForm(formData: FormData): Promise<SendFormResponse> {\n const url = `${this.options.baseUrl}/api/v1/send`;\n try {\n const res = await fetch(url, {\n method: 'POST',\n headers: {\n 'Authorization': `Bearer ${this.apiKey}`,\n },\n body: formData,\n });\n const data = await res.json();\n return { success: res.ok, data, errors: !res.ok ? [data?.message || 'Unknown error'] : undefined };\n } catch (e: any) {\n return { success: false, errors: [e.message] };\n }\n }\n}\n","/**\n * CMS API endpoints constants.\n */\nexport const CMS_ENDPOINTS = {\n CATEGORIES: '/api/v1/cms/categories',\n ARTICLES_INDEXES: '/api/v1/cms/articles-indexes',\n} as const;\n\n/**\n * Default HTTP headers for CMS API requests.\n */\nexport const DEFAULT_HEADERS = {\n 'Content-Type': 'application/json',\n} as const;\n\n/**\n * Default error message when API response doesn't contain one.\n */\nexport const DEFAULT_ERROR_MESSAGE = 'Unknown error';\n\n","import { CMSResponse } from './types';\nimport { DEFAULT_HEADERS, DEFAULT_ERROR_MESSAGE } from './constants';\n\nexport interface RequestOptions {\n baseUrl: string;\n apiKey: string;\n}\n\nexport interface RequestBody {\n resourceId: string;\n key: string;\n lang?: string;\n}\n\n/**\n * Sends a POST request to the CMS API.\n *\n * @param {string} endpoint - The API endpoint path.\n * @param {RequestBody} body - The request body.\n * @param {RequestOptions} options - Request configuration options.\n * @return {Promise<CMSResponse>} A promise that resolves to the API response.\n */\nexport async function sendRequest(\n endpoint: string,\n body: RequestBody,\n options: RequestOptions\n): Promise<CMSResponse> {\n const url = `${options.baseUrl}${endpoint}`;\n try {\n const res = await fetch(url, {\n method: 'POST',\n headers: {\n ...DEFAULT_HEADERS,\n 'Authorization': `Bearer ${options.apiKey}`,\n },\n body: JSON.stringify(body),\n });\n const data = await res.json();\n return {\n success: res.ok,\n data,\n errors: !res.ok ? [data?.message || DEFAULT_ERROR_MESSAGE] : undefined,\n };\n } catch (e: any) {\n return { success: false, errors: [e.message] };\n }\n}\n","import { MiraCMSOptions, CMSResponse } from './types';\nimport { CMS_ENDPOINTS } from './constants';\nimport { sendRequest } from './request';\n\n/**\n * Represents a resource instance for interacting with CMS content.\n */\nexport class MiraResource {\n private readonly resourceId: string;\n private readonly apiKey: string;\n private readonly options: MiraCMSOptions;\n\n constructor(resourceId: string, apiKey: string, options: MiraCMSOptions) {\n this.resourceId = resourceId;\n this.apiKey = apiKey;\n this.options = options;\n }\n\n /**\n * Gets categories for the resource.\n *\n * @param {string} key - The key to identify the categories.\n * @param {string} [lang] - Optional language code.\n * @return {Promise<CMSResponse>} A promise that resolves to the categories data.\n */\n public async getCategories(key: string, lang?: string): Promise<CMSResponse> {\n return sendRequest(\n CMS_ENDPOINTS.CATEGORIES,\n { resourceId: this.resourceId, key, lang },\n { baseUrl: this.options.baseUrl!, apiKey: this.apiKey }\n );\n }\n\n /**\n * Gets articles indexes for the resource.\n *\n * @param {string} key - The key to identify the articles index (e.g., 'blog/articles-index.json').\n * @param {string} [lang] - Optional language code (e.g., 'en').\n * @return {Promise<CMSResponse>} A promise that resolves to the articles indexes data.\n */\n public async getArticlesIndexes(key: string, lang?: string): Promise<CMSResponse> {\n return sendRequest(\n CMS_ENDPOINTS.ARTICLES_INDEXES,\n { resourceId: this.resourceId, key, lang },\n { baseUrl: this.options.baseUrl!, apiKey: this.apiKey }\n );\n }\n}\n\n/**\n * MiraCMS SDK for interacting with CMS content like categories and articles.\n */\nexport class MiraCMS {\n private readonly apiKey: string;\n private readonly options: MiraCMSOptions;\n\n /**\n * Creates a new MiraCMS instance.\n *\n * @param {string} apiKey - The API key for authentication.\n * @param {MiraCMSOptions} [options] - Optional configuration options.\n */\n constructor(apiKey: string, options?: MiraCMSOptions) {\n this.apiKey = apiKey;\n this.options = options || {};\n }\n\n /**\n * Initializes a resource instance for the given resource ID.\n *\n * @param {string} resourceId - The UUID of the resource.\n * @return {MiraResource} A resource instance with methods to interact with CMS content.\n */\n public initResource(resourceId: string): MiraResource {\n return new MiraResource(resourceId, this.apiKey, this.options);\n }\n}\n"],"mappings":";AAWO,IAAM,cAAN,MAAkB;AAAA,EAIvB,YAAY,QAAgB,SAA8B;AACxD,SAAK,SAAS;AACd,SAAK,UAAU,WAAW,CAAC;AAAA,EAC7B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAcO,gBAAgB,QAAiD;AACtE,UAAM,EAAE,YAAY,QAAQ,SAAS,MAAM,IAAI;AAC/C,UAAM,SAAmB,CAAC;AAC1B,QAAI,CAAC;AAAY,aAAO,KAAK,wBAAwB;AACrD,QAAI,CAAC;AAAQ,aAAO,KAAK,oBAAoB;AAC7C,QAAI,WAAW,OAAO,YAAY;AAAU,aAAO,KAAK,gCAAgC;AACxF,QAAI,OAAO;AAAQ,aAAO,EAAE,UAAU,MAAa,OAAO;AAE1D,UAAM,WAAW,IAAI,SAAS;AAC9B,aAAS,OAAO,cAAc,OAAO,UAAU;AAC/C,aAAS,OAAO,UAAU,OAAO,MAAM;AACvC,aAAS,OAAO,WAAW,KAAK,UAAU,OAAO,OAAO,CAAC;AAEzD,QAAI,OAAO;AACT,iBAAW,QAAQ,OAAO;AACxB,iBAAS,OAAO,SAAS,IAAW;AAAA,MACtC;AAAA,IACF;AAEA,WAAO,EAAE,SAAS;AAAA,EACpB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAa,SAAS,UAA+C;AACnE,UAAM,MAAM,GAAG,KAAK,QAAQ,OAAO;AACnC,QAAI;AACF,YAAM,MAAM,MAAM,MAAM,KAAK;AAAA,QAC3B,QAAQ;AAAA,QACR,SAAS;AAAA,UACP,iBAAiB,UAAU,KAAK,MAAM;AAAA,QACxC;AAAA,Q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