mira-form-sdk 1.2.4 → 1.3.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 CHANGED
@@ -178,6 +178,23 @@ var MiraCMS = class {
178
178
  initResource(resourceId) {
179
179
  return new MiraResource(resourceId, this.apiKey, this.options);
180
180
  }
181
+ /**
182
+ * Gets articles indexes for the resource.
183
+ *
184
+ * @param {string} key - The key to identify the articles index (e.g., 'blog/articles-index.json').
185
+ * @param {string} [lang] - Optional language code (e.g., 'en').
186
+ * @param {number} [page] - Optional page number for pagination.
187
+ * @param {number} [limit] - Optional limit of items per page.
188
+ * @param {string[]} resourceIds - The UUID of the resource.
189
+ * @return {Promise<CMSResponse>} A promise that resolves to the articles indexes data.
190
+ */
191
+ async getAllArticlesIndexes(resourceIds, key, page, limit, lang) {
192
+ return sendRequest(
193
+ CMS_ENDPOINTS.ARTICLES_INDEXES,
194
+ { resourceIds, key, lang, page, limit },
195
+ { baseUrl: this.options.baseUrl, apiKey: this.apiKey }
196
+ );
197
+ }
181
198
  };
182
199
  // Annotate the CommonJS export names for ESM import in node:
183
200
  0 && (module.exports = {
@@ -1 +1 @@
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;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,UAA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 {"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\nexport interface ResourceRequestBody {\n resourceIds: string[];\n key: string;\n lang?: string;\n [key: string]: any;\n}\n\n/**\n * Sends a POST request to the CMS API.\n *\n * @param {string} endpoint - The API endpoint path.\n * @param {RequestBody | ResourceRequestBody} 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 | ResourceRequestBody,\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\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 * @param {number} [page] - Optional page number for pagination.\n * @param {number} [limit] - Optional limit of items per page.\n * @param {string[]} resourceIds - The UUID of the resource.\n * @return {Promise<CMSResponse>} A promise that resolves to the articles indexes data.\n */\n public async getAllArticlesIndexes(resourceIds: string[], key: string, page?: number, limit?: number, lang?: string): Promise<CMSResponse> {\n return sendRequest(\n CMS_ENDPOINTS.ARTICLES_INDEXES,\n { resourceIds, key, lang, page, limit },\n { baseUrl: this.options.baseUrl!, apiKey: this.apiKey }\n );\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;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,OAA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OAAO;AAAA,IACxD;AAAA,EACF;AACF;","names":[]}
package/dist/index.d.mts CHANGED
@@ -162,6 +162,17 @@ declare class MiraCMS {
162
162
  * @return {MiraResource} A resource instance with methods to interact with CMS content.
163
163
  */
164
164
  initResource(resourceId: string): MiraResource;
165
+ /**
166
+ * Gets articles indexes for the resource.
167
+ *
168
+ * @param {string} key - The key to identify the articles index (e.g., 'blog/articles-index.json').
169
+ * @param {string} [lang] - Optional language code (e.g., 'en').
170
+ * @param {number} [page] - Optional page number for pagination.
171
+ * @param {number} [limit] - Optional limit of items per page.
172
+ * @param {string[]} resourceIds - The UUID of the resource.
173
+ * @return {Promise<CMSResponse>} A promise that resolves to the articles indexes data.
174
+ */
175
+ getAllArticlesIndexes(resourceIds: string[], key: string, page?: number, limit?: number, lang?: string): Promise<CMSResponse>;
165
176
  }
166
177
 
167
178
  export { CMSResponse, GetArticlesIndexesParams, GetCategoriesParams, MiraCMS, MiraCMSOptions, MiraFormSDK, MiraFormSDKOptions, MiraResource, PrepareFormDataParams, PreparedFormData, SendFormResponse };
package/dist/index.d.ts CHANGED
@@ -162,6 +162,17 @@ declare class MiraCMS {
162
162
  * @return {MiraResource} A resource instance with methods to interact with CMS content.
163
163
  */
164
164
  initResource(resourceId: string): MiraResource;
165
+ /**
166
+ * Gets articles indexes for the resource.
167
+ *
168
+ * @param {string} key - The key to identify the articles index (e.g., 'blog/articles-index.json').
169
+ * @param {string} [lang] - Optional language code (e.g., 'en').
170
+ * @param {number} [page] - Optional page number for pagination.
171
+ * @param {number} [limit] - Optional limit of items per page.
172
+ * @param {string[]} resourceIds - The UUID of the resource.
173
+ * @return {Promise<CMSResponse>} A promise that resolves to the articles indexes data.
174
+ */
175
+ getAllArticlesIndexes(resourceIds: string[], key: string, page?: number, limit?: number, lang?: string): Promise<CMSResponse>;
165
176
  }
166
177
 
167
178
  export { CMSResponse, GetArticlesIndexesParams, GetCategoriesParams, MiraCMS, MiraCMSOptions, MiraFormSDK, MiraFormSDKOptions, MiraResource, PrepareFormDataParams, PreparedFormData, SendFormResponse };
package/dist/index.mjs CHANGED
@@ -150,6 +150,23 @@ var MiraCMS = class {
150
150
  initResource(resourceId) {
151
151
  return new MiraResource(resourceId, this.apiKey, this.options);
152
152
  }
153
+ /**
154
+ * Gets articles indexes for the resource.
155
+ *
156
+ * @param {string} key - The key to identify the articles index (e.g., 'blog/articles-index.json').
157
+ * @param {string} [lang] - Optional language code (e.g., 'en').
158
+ * @param {number} [page] - Optional page number for pagination.
159
+ * @param {number} [limit] - Optional limit of items per page.
160
+ * @param {string[]} resourceIds - The UUID of the resource.
161
+ * @return {Promise<CMSResponse>} A promise that resolves to the articles indexes data.
162
+ */
163
+ async getAllArticlesIndexes(resourceIds, key, page, limit, lang) {
164
+ return sendRequest(
165
+ CMS_ENDPOINTS.ARTICLES_INDEXES,
166
+ { resourceIds, key, lang, page, limit },
167
+ { baseUrl: this.options.baseUrl, apiKey: this.apiKey }
168
+ );
169
+ }
153
170
  };
154
171
  export {
155
172
  MiraCMS,
@@ -1 +1 @@
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,EAQ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Y,YAAoB,QAAgB,SAAyB;AACvE,SAAK,aAAa;AAClB,SAAK,SAAS;AACd,SAAK,UAAU;AAAA,EACjB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAa,cAAc,KAAa,MAAqC;AAC3E,WAAO;AAAA,MACL,cAAc;AAAA,MACd,EAAE,YAAY,KAAK,YAAY,KAAK,KAAK;AAAA,MACzC,EAAE,SAAS,KAAK,QAAQ,SAAU,QAAQ,KAAK,OAAO;AAAA,IACxD;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAa,mBAAmB,KAAa,MAAqC;AAChF,WAAO;AAAA,MACL,cAAc;AAAA,MACd,EAAE,YAAY,KAAK,YAAY,KAAK,KAAK;AAAA,MACzC,EAAE,SAAS,KAAK,QAAQ,SAAU,QAAQ,KAAK,OAAO;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":[]}
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\nexport interface ResourceRequestBody {\n resourceIds: string[];\n key: string;\n lang?: string;\n [key: string]: any;\n}\n\n/**\n * Sends a POST request to the CMS API.\n *\n * @param {string} endpoint - The API endpoint path.\n * @param {RequestBody | ResourceRequestBody} 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 | ResourceRequestBody,\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\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 * @param {number} [page] - Optional page number for pagination.\n * @param {number} [limit] - Optional limit of items per page.\n * @param {string[]} resourceIds - The UUID of the resource.\n * @return {Promise<CMSResponse>} A promise that resolves to the articles indexes data.\n */\n public async getAllArticlesIndexes(resourceIds: string[], key: string, page?: number, limit?: number, lang?: string): Promise<CMSResponse> {\n return sendRequest(\n CMS_ENDPOINTS.ARTICLES_INDEXES,\n { resourceIds, key, lang, page, limit },\n { baseUrl: this.options.baseUrl!, apiKey: this.apiKey }\n );\n }\n}\n"],"mappings":";AAWO,IAAM,cAAN,MAAkB;AAAA,EAIvB,YAAY,QAAgB,SAA8B;AACxD,SAAK,SAAS;AACd,SAAK,UAAU,W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ACzC,EAAE,SAAS,KAAK,QAAQ,SAAU,QAAQ,KAAK,OAAO;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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaA,MAAa,sBAAsB,aAAuB,KAAa,MAAe,OAAgB,MAAqC;AACzI,WAAO;AAAA,MACL,cAAc;AAAA,MACd,EAAE,aAAa,KAAK,MAAM,MAAM,MAAM;AAAA,MACtC,EAAE,SAAS,KAAK,QAAQ,SAAU,QAAQ,KAAK,OAAO;AAAA,IACxD;AAAA,EACF;AACF;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mira-form-sdk",
3
- "version": "1.2.4",
3
+ "version": "1.3.4",
4
4
  "description": "Mira Form API SDK",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",