@fyul/embed-sdk 1.2.1
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/README.md +198 -0
- package/dist/cjs/helpers/messageLogger.d.ts +20 -0
- package/dist/cjs/helpers/messageLogger.js +73 -0
- package/dist/cjs/helpers/responseHandler.d.ts +6 -0
- package/dist/cjs/helpers/responseHandler.js +28 -0
- package/dist/cjs/helpers/typeHelper.types.d.ts +10 -0
- package/dist/cjs/helpers/typeHelper.types.js +2 -0
- package/dist/cjs/index.d.ts +44 -0
- package/dist/cjs/index.js +157 -0
- package/dist/cjs/modules/baseModule.d.ts +7 -0
- package/dist/cjs/modules/baseModule.js +10 -0
- package/dist/cjs/modules/baseModuleService.d.ts +10 -0
- package/dist/cjs/modules/baseModuleService.js +11 -0
- package/dist/cjs/modules/catalog/catalogModule.d.ts +9 -0
- package/dist/cjs/modules/catalog/catalogModule.js +26 -0
- package/dist/cjs/modules/catalog/catalogService.d.ts +7 -0
- package/dist/cjs/modules/catalog/catalogService.js +23 -0
- package/dist/cjs/modules/catalog/events.d.ts +26 -0
- package/dist/cjs/modules/catalog/events.js +23 -0
- package/dist/cjs/modules/catalog/helpers/variantUtils.d.ts +7 -0
- package/dist/cjs/modules/catalog/helpers/variantUtils.js +38 -0
- package/dist/cjs/modules/catalog/types/data.types.d.ts +87 -0
- package/dist/cjs/modules/catalog/types/data.types.js +2 -0
- package/dist/cjs/modules/catalog/types/event/actionEvent.types.d.ts +7 -0
- package/dist/cjs/modules/catalog/types/event/actionEvent.types.js +2 -0
- package/dist/cjs/modules/catalog/types/event/actionEventPayload.types.d.ts +11 -0
- package/dist/cjs/modules/catalog/types/event/actionEventPayload.types.js +2 -0
- package/dist/cjs/modules/catalog/types/event/resultEvent.types.d.ts +7 -0
- package/dist/cjs/modules/catalog/types/event/resultEvent.types.js +2 -0
- package/dist/cjs/modules/catalog/types/event/resultEventPayload.types.d.ts +14 -0
- package/dist/cjs/modules/catalog/types/event/resultEventPayload.types.js +2 -0
- package/dist/cjs/modules/catalog/types/index.d.ts +7 -0
- package/dist/cjs/modules/catalog/types/index.js +26 -0
- package/dist/cjs/modules/catalog/types/moduleConfig.types.d.ts +9 -0
- package/dist/cjs/modules/catalog/types/moduleConfig.types.js +2 -0
- package/dist/cjs/modules/eventTypes.d.ts +9 -0
- package/dist/cjs/modules/eventTypes.js +20 -0
- package/dist/cjs/modules/events.d.ts +44 -0
- package/dist/cjs/modules/events.js +63 -0
- package/dist/cjs/modules/mockup-generation/events.d.ts +14 -0
- package/dist/cjs/modules/mockup-generation/events.js +17 -0
- package/dist/cjs/modules/mockup-generation/mockupGenerationModule.d.ts +7 -0
- package/dist/cjs/modules/mockup-generation/mockupGenerationModule.js +13 -0
- package/dist/cjs/modules/mockup-generation/mockupService.d.ts +6 -0
- package/dist/cjs/modules/mockup-generation/mockupService.js +15 -0
- package/dist/cjs/modules/mockup-generation/types/data.types.d.ts +31 -0
- package/dist/cjs/modules/mockup-generation/types/data.types.js +2 -0
- package/dist/cjs/modules/mockup-generation/types/event/actionEvent.types.d.ts +5 -0
- package/dist/cjs/modules/mockup-generation/types/event/actionEvent.types.js +2 -0
- package/dist/cjs/modules/mockup-generation/types/event/actionEventPayload.types.d.ts +11 -0
- package/dist/cjs/modules/mockup-generation/types/event/actionEventPayload.types.js +2 -0
- package/dist/cjs/modules/mockup-generation/types/event/resultEvent.types.d.ts +5 -0
- package/dist/cjs/modules/mockup-generation/types/event/resultEvent.types.js +2 -0
- package/dist/cjs/modules/mockup-generation/types/event/resultEventPayload.types.d.ts +5 -0
- package/dist/cjs/modules/mockup-generation/types/event/resultEventPayload.types.js +2 -0
- package/dist/cjs/modules/mockup-generation/types/index.d.ts +7 -0
- package/dist/cjs/modules/mockup-generation/types/index.js +27 -0
- package/dist/cjs/modules/mockup-generation/types/moduleConfig.types.d.ts +2 -0
- package/dist/cjs/modules/mockup-generation/types/moduleConfig.types.js +2 -0
- package/dist/cjs/modules/modules.d.ts +16 -0
- package/dist/cjs/modules/modules.js +19 -0
- package/dist/cjs/modules/product-publish/events.d.ts +14 -0
- package/dist/cjs/modules/product-publish/events.js +17 -0
- package/dist/cjs/modules/product-publish/productPublishModule.d.ts +7 -0
- package/dist/cjs/modules/product-publish/productPublishModule.js +13 -0
- package/dist/cjs/modules/product-publish/productPublishService.d.ts +6 -0
- package/dist/cjs/modules/product-publish/productPublishService.js +15 -0
- package/dist/cjs/modules/product-publish/types/event/actionEvent.types.d.ts +5 -0
- package/dist/cjs/modules/product-publish/types/event/actionEvent.types.js +2 -0
- package/dist/cjs/modules/product-publish/types/event/actionEventPayload.types.d.ts +8 -0
- package/dist/cjs/modules/product-publish/types/event/actionEventPayload.types.js +2 -0
- package/dist/cjs/modules/product-publish/types/event/resultEvent.types.d.ts +5 -0
- package/dist/cjs/modules/product-publish/types/event/resultEvent.types.js +2 -0
- package/dist/cjs/modules/product-publish/types/event/resultEventPayload.types.d.ts +4 -0
- package/dist/cjs/modules/product-publish/types/event/resultEventPayload.types.js +2 -0
- package/dist/cjs/modules/product-publish/types/index.d.ts +6 -0
- package/dist/cjs/modules/product-publish/types/index.js +25 -0
- package/dist/cjs/modules/product-publish/types/moduleConfig.types.d.ts +2 -0
- package/dist/cjs/modules/product-publish/types/moduleConfig.types.js +2 -0
- package/dist/cjs/modules/sdk/events.d.ts +13 -0
- package/dist/cjs/modules/sdk/events.js +16 -0
- package/dist/cjs/modules/sdk/sdkModule.d.ts +7 -0
- package/dist/cjs/modules/sdk/sdkModule.js +11 -0
- package/dist/cjs/modules/sdk/types/data.types.d.ts +10 -0
- package/dist/cjs/modules/sdk/types/data.types.js +2 -0
- package/dist/cjs/modules/sdk/types/event/actionEvent.types.d.ts +6 -0
- package/dist/cjs/modules/sdk/types/event/actionEvent.types.js +2 -0
- package/dist/cjs/modules/sdk/types/event/actionEventPayload.types.d.ts +6 -0
- package/dist/cjs/modules/sdk/types/event/actionEventPayload.types.js +2 -0
- package/dist/cjs/modules/sdk/types/index.d.ts +5 -0
- package/dist/cjs/modules/sdk/types/index.js +25 -0
- package/dist/cjs/modules/sdk/types/moduleConfig.types.d.ts +2 -0
- package/dist/cjs/modules/sdk/types/moduleConfig.types.js +2 -0
- package/dist/cjs/services/embedCommunicator.d.ts +21 -0
- package/dist/cjs/services/embedCommunicator.js +108 -0
- package/dist/cjs/services/iFrameManager.d.ts +15 -0
- package/dist/cjs/services/iFrameManager.js +70 -0
- package/dist/cjs/services/messageBroker.d.ts +19 -0
- package/dist/cjs/services/messageBroker.js +64 -0
- package/dist/cjs/services/moduleLoaderService.d.ts +16 -0
- package/dist/cjs/services/moduleLoaderService.js +50 -0
- package/dist/cjs/types/event/action/actionEvent.types.d.ts +11 -0
- package/dist/cjs/types/event/action/actionEvent.types.js +2 -0
- package/dist/cjs/types/event/action/actionEventPayload.types.d.ts +5 -0
- package/dist/cjs/types/event/action/actionEventPayload.types.js +2 -0
- package/dist/cjs/types/event/event.types.d.ts +15 -0
- package/dist/cjs/types/event/event.types.js +2 -0
- package/dist/cjs/types/event/eventPayload.types.d.ts +4 -0
- package/dist/cjs/types/event/eventPayload.types.js +2 -0
- package/dist/cjs/types/event/notification/notificationEvent.types.d.ts +6 -0
- package/dist/cjs/types/event/notification/notificationEvent.types.js +2 -0
- package/dist/cjs/types/event/notification/notificationEventPayload.types.d.ts +5 -0
- package/dist/cjs/types/event/notification/notificationEventPayload.types.js +2 -0
- package/dist/cjs/types/event/result/resultEvent.types.d.ts +10 -0
- package/dist/cjs/types/event/result/resultEvent.types.js +2 -0
- package/dist/cjs/types/event/result/resultEventPayload.types.d.ts +11 -0
- package/dist/cjs/types/event/result/resultEventPayload.types.js +2 -0
- package/dist/cjs/types/module/module.types.d.ts +22 -0
- package/dist/cjs/types/module/module.types.js +2 -0
- package/dist/cjs/types/module/moduleConfig.types.d.ts +10 -0
- package/dist/cjs/types/module/moduleConfig.types.js +2 -0
- package/dist/cjs/version.d.ts +1 -0
- package/dist/cjs/version.js +5 -0
- package/dist/esm/helpers/messageLogger.d.ts +20 -0
- package/dist/esm/helpers/messageLogger.js +68 -0
- package/dist/esm/helpers/responseHandler.d.ts +6 -0
- package/dist/esm/helpers/responseHandler.js +23 -0
- package/dist/esm/helpers/typeHelper.types.d.ts +10 -0
- package/dist/esm/helpers/typeHelper.types.js +1 -0
- package/dist/esm/index.d.ts +44 -0
- package/dist/esm/index.js +101 -0
- package/dist/esm/modules/baseModule.d.ts +7 -0
- package/dist/esm/modules/baseModule.js +6 -0
- package/dist/esm/modules/baseModuleService.d.ts +10 -0
- package/dist/esm/modules/baseModuleService.js +7 -0
- package/dist/esm/modules/catalog/catalogModule.d.ts +9 -0
- package/dist/esm/modules/catalog/catalogModule.js +22 -0
- package/dist/esm/modules/catalog/catalogService.d.ts +7 -0
- package/dist/esm/modules/catalog/catalogService.js +19 -0
- package/dist/esm/modules/catalog/events.d.ts +26 -0
- package/dist/esm/modules/catalog/events.js +20 -0
- package/dist/esm/modules/catalog/helpers/variantUtils.d.ts +7 -0
- package/dist/esm/modules/catalog/helpers/variantUtils.js +33 -0
- package/dist/esm/modules/catalog/types/data.types.d.ts +87 -0
- package/dist/esm/modules/catalog/types/data.types.js +1 -0
- package/dist/esm/modules/catalog/types/event/actionEvent.types.d.ts +7 -0
- package/dist/esm/modules/catalog/types/event/actionEvent.types.js +1 -0
- package/dist/esm/modules/catalog/types/event/actionEventPayload.types.d.ts +11 -0
- package/dist/esm/modules/catalog/types/event/actionEventPayload.types.js +1 -0
- package/dist/esm/modules/catalog/types/event/resultEvent.types.d.ts +7 -0
- package/dist/esm/modules/catalog/types/event/resultEvent.types.js +1 -0
- package/dist/esm/modules/catalog/types/event/resultEventPayload.types.d.ts +14 -0
- package/dist/esm/modules/catalog/types/event/resultEventPayload.types.js +1 -0
- package/dist/esm/modules/catalog/types/index.d.ts +7 -0
- package/dist/esm/modules/catalog/types/index.js +10 -0
- package/dist/esm/modules/catalog/types/moduleConfig.types.d.ts +9 -0
- package/dist/esm/modules/catalog/types/moduleConfig.types.js +1 -0
- package/dist/esm/modules/eventTypes.d.ts +9 -0
- package/dist/esm/modules/eventTypes.js +14 -0
- package/dist/esm/modules/events.d.ts +44 -0
- package/dist/esm/modules/events.js +27 -0
- package/dist/esm/modules/mockup-generation/events.d.ts +14 -0
- package/dist/esm/modules/mockup-generation/events.js +14 -0
- package/dist/esm/modules/mockup-generation/mockupGenerationModule.d.ts +7 -0
- package/dist/esm/modules/mockup-generation/mockupGenerationModule.js +9 -0
- package/dist/esm/modules/mockup-generation/mockupService.d.ts +6 -0
- package/dist/esm/modules/mockup-generation/mockupService.js +11 -0
- package/dist/esm/modules/mockup-generation/types/data.types.d.ts +31 -0
- package/dist/esm/modules/mockup-generation/types/data.types.js +1 -0
- package/dist/esm/modules/mockup-generation/types/event/actionEvent.types.d.ts +5 -0
- package/dist/esm/modules/mockup-generation/types/event/actionEvent.types.js +1 -0
- package/dist/esm/modules/mockup-generation/types/event/actionEventPayload.types.d.ts +11 -0
- package/dist/esm/modules/mockup-generation/types/event/actionEventPayload.types.js +1 -0
- package/dist/esm/modules/mockup-generation/types/event/resultEvent.types.d.ts +5 -0
- package/dist/esm/modules/mockup-generation/types/event/resultEvent.types.js +1 -0
- package/dist/esm/modules/mockup-generation/types/event/resultEventPayload.types.d.ts +5 -0
- package/dist/esm/modules/mockup-generation/types/event/resultEventPayload.types.js +1 -0
- package/dist/esm/modules/mockup-generation/types/index.d.ts +7 -0
- package/dist/esm/modules/mockup-generation/types/index.js +11 -0
- package/dist/esm/modules/mockup-generation/types/moduleConfig.types.d.ts +2 -0
- package/dist/esm/modules/mockup-generation/types/moduleConfig.types.js +1 -0
- package/dist/esm/modules/modules.d.ts +16 -0
- package/dist/esm/modules/modules.js +16 -0
- package/dist/esm/modules/product-publish/events.d.ts +14 -0
- package/dist/esm/modules/product-publish/events.js +14 -0
- package/dist/esm/modules/product-publish/productPublishModule.d.ts +7 -0
- package/dist/esm/modules/product-publish/productPublishModule.js +9 -0
- package/dist/esm/modules/product-publish/productPublishService.d.ts +6 -0
- package/dist/esm/modules/product-publish/productPublishService.js +11 -0
- package/dist/esm/modules/product-publish/types/event/actionEvent.types.d.ts +5 -0
- package/dist/esm/modules/product-publish/types/event/actionEvent.types.js +1 -0
- package/dist/esm/modules/product-publish/types/event/actionEventPayload.types.d.ts +8 -0
- package/dist/esm/modules/product-publish/types/event/actionEventPayload.types.js +1 -0
- package/dist/esm/modules/product-publish/types/event/resultEvent.types.d.ts +5 -0
- package/dist/esm/modules/product-publish/types/event/resultEvent.types.js +1 -0
- package/dist/esm/modules/product-publish/types/event/resultEventPayload.types.d.ts +4 -0
- package/dist/esm/modules/product-publish/types/event/resultEventPayload.types.js +1 -0
- package/dist/esm/modules/product-publish/types/index.d.ts +6 -0
- package/dist/esm/modules/product-publish/types/index.js +9 -0
- package/dist/esm/modules/product-publish/types/moduleConfig.types.d.ts +2 -0
- package/dist/esm/modules/product-publish/types/moduleConfig.types.js +1 -0
- package/dist/esm/modules/sdk/events.d.ts +13 -0
- package/dist/esm/modules/sdk/events.js +13 -0
- package/dist/esm/modules/sdk/sdkModule.d.ts +7 -0
- package/dist/esm/modules/sdk/sdkModule.js +7 -0
- package/dist/esm/modules/sdk/types/data.types.d.ts +10 -0
- package/dist/esm/modules/sdk/types/data.types.js +1 -0
- package/dist/esm/modules/sdk/types/event/actionEvent.types.d.ts +6 -0
- package/dist/esm/modules/sdk/types/event/actionEvent.types.js +1 -0
- package/dist/esm/modules/sdk/types/event/actionEventPayload.types.d.ts +6 -0
- package/dist/esm/modules/sdk/types/event/actionEventPayload.types.js +1 -0
- package/dist/esm/modules/sdk/types/index.d.ts +5 -0
- package/dist/esm/modules/sdk/types/index.js +9 -0
- package/dist/esm/modules/sdk/types/moduleConfig.types.d.ts +2 -0
- package/dist/esm/modules/sdk/types/moduleConfig.types.js +1 -0
- package/dist/esm/services/embedCommunicator.d.ts +21 -0
- package/dist/esm/services/embedCommunicator.js +104 -0
- package/dist/esm/services/iFrameManager.d.ts +15 -0
- package/dist/esm/services/iFrameManager.js +66 -0
- package/dist/esm/services/messageBroker.d.ts +19 -0
- package/dist/esm/services/messageBroker.js +60 -0
- package/dist/esm/services/moduleLoaderService.d.ts +16 -0
- package/dist/esm/services/moduleLoaderService.js +46 -0
- package/dist/esm/types/event/action/actionEvent.types.d.ts +11 -0
- package/dist/esm/types/event/action/actionEvent.types.js +1 -0
- package/dist/esm/types/event/action/actionEventPayload.types.d.ts +5 -0
- package/dist/esm/types/event/action/actionEventPayload.types.js +1 -0
- package/dist/esm/types/event/event.types.d.ts +15 -0
- package/dist/esm/types/event/event.types.js +1 -0
- package/dist/esm/types/event/eventPayload.types.d.ts +4 -0
- package/dist/esm/types/event/eventPayload.types.js +1 -0
- package/dist/esm/types/event/notification/notificationEvent.types.d.ts +6 -0
- package/dist/esm/types/event/notification/notificationEvent.types.js +1 -0
- package/dist/esm/types/event/notification/notificationEventPayload.types.d.ts +5 -0
- package/dist/esm/types/event/notification/notificationEventPayload.types.js +1 -0
- package/dist/esm/types/event/result/resultEvent.types.d.ts +10 -0
- package/dist/esm/types/event/result/resultEvent.types.js +1 -0
- package/dist/esm/types/event/result/resultEventPayload.types.d.ts +11 -0
- package/dist/esm/types/event/result/resultEventPayload.types.js +1 -0
- package/dist/esm/types/module/module.types.d.ts +22 -0
- package/dist/esm/types/module/module.types.js +1 -0
- package/dist/esm/types/module/moduleConfig.types.d.ts +10 -0
- package/dist/esm/types/module/moduleConfig.types.js +1 -0
- package/dist/esm/version.d.ts +1 -0
- package/dist/esm/version.js +2 -0
- package/package.json +55 -0
- package/tsconfig.cjs.json +8 -0
- package/tsconfig.esm.json +8 -0
package/README.md
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
# @fyulorg/embed-sdk
|
|
2
|
+
|
|
3
|
+
A TypeScript SDK for integrating with Printful services via iframe-based cross-origin communication. The SDK provides a modular architecture for catalog browsing, mockup generation, and other Printful services through secure iframe messaging.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🎯 **Modular Architecture**: Separate modules for different services (Catalog, Mockup Generation, SDK core)
|
|
8
|
+
- 🔒 **Secure Communication**: iframe-based cross-origin messaging with correlation ID tracking
|
|
9
|
+
- 📦 **Dual Package Support**: Both ESM and CommonJS builds included
|
|
10
|
+
- 🧪 **Fully Tested**: Comprehensive Jest test suite with 130+ tests and ~90% coverage
|
|
11
|
+
- 🎨 **TypeScript First**: Complete type safety with extensive type definitions
|
|
12
|
+
- 🔧 **Development Ready**: ESLint, Prettier, and modern tooling configured
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @fyulorg/embed-sdk
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Quick Start
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import { Embed } from '@fyulorg/embed-sdk';
|
|
24
|
+
|
|
25
|
+
// Create SDK instance with your authentication nonce
|
|
26
|
+
const embedSdk = new Embed('your-nonce-here', {
|
|
27
|
+
targetOrigin: 'https://your-domain.com',
|
|
28
|
+
modules: [
|
|
29
|
+
{ name: 'catalog', data: { apiKey: 'your-api-key' } },
|
|
30
|
+
{ name: 'mockupGeneration', data: { timeout: 30000 } }
|
|
31
|
+
]
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// Initialize connection
|
|
35
|
+
await embedSdk.init();
|
|
36
|
+
|
|
37
|
+
// Use catalog service
|
|
38
|
+
const products = await embedSdk.catalog.getProducts(123);
|
|
39
|
+
console.log('Products:', products);
|
|
40
|
+
|
|
41
|
+
// Use mockup service
|
|
42
|
+
const imageFile = new File(['...'], 'design.png', { type: 'image/png' });
|
|
43
|
+
const mockups = await embedSdk.mockup.getMockups(imageFile, [1, 2, 3]);
|
|
44
|
+
console.log('Generated mockups:', mockups);
|
|
45
|
+
|
|
46
|
+
// Clean up when done
|
|
47
|
+
embedSdk.destroy();
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## API Reference
|
|
51
|
+
|
|
52
|
+
### `new Embed(nonce, config?)`
|
|
53
|
+
|
|
54
|
+
Creates a new SDK instance.
|
|
55
|
+
|
|
56
|
+
**Parameters:**
|
|
57
|
+
- `nonce` (string): Authentication token from your backend
|
|
58
|
+
- `config` (optional): Configuration object
|
|
59
|
+
- `targetOrigin` (string): Target origin for iframe messages
|
|
60
|
+
- `modules` (array): Module configurations to initialize
|
|
61
|
+
|
|
62
|
+
### Core Methods
|
|
63
|
+
|
|
64
|
+
#### `embed.init(): Promise<void>`
|
|
65
|
+
Initializes the SDK, creates iframe, and establishes communication channel.
|
|
66
|
+
|
|
67
|
+
#### `embed.destroy(): void`
|
|
68
|
+
Cleans up resources, removes iframe, and clears all pending messages.
|
|
69
|
+
|
|
70
|
+
### Services
|
|
71
|
+
|
|
72
|
+
#### Catalog Service (`embed.catalog`)
|
|
73
|
+
```typescript
|
|
74
|
+
// Get products by category
|
|
75
|
+
const products = await embed.catalog.getProducts(categoryId);
|
|
76
|
+
|
|
77
|
+
// Get all categories
|
|
78
|
+
const categories = await embed.catalog.getCategories();
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
#### Mockup Service (`embed.mockup`)
|
|
82
|
+
```typescript
|
|
83
|
+
// Generate mockups from design file
|
|
84
|
+
const mockups = await embed.mockup.getMockups(
|
|
85
|
+
designFile, // Blob | File
|
|
86
|
+
productIds // number[] (optional)
|
|
87
|
+
);
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Module System
|
|
91
|
+
|
|
92
|
+
The SDK uses a modular architecture where different services are loaded as separate modules:
|
|
93
|
+
|
|
94
|
+
- **SDK Module**: Core functionality and initialization
|
|
95
|
+
- **Catalog Module**: Product and category browsing
|
|
96
|
+
- **Mockup Generation Module**: Design-to-mockup conversion
|
|
97
|
+
|
|
98
|
+
Each module can be configured independently and loaded on-demand.
|
|
99
|
+
|
|
100
|
+
## Event System
|
|
101
|
+
|
|
102
|
+
The SDK implements a comprehensive event system for iframe communication:
|
|
103
|
+
|
|
104
|
+
- **Action Events**: Commands sent to the iframe (e.g., initialize, load module)
|
|
105
|
+
- **Result Events**: Successful responses from iframe operations
|
|
106
|
+
- **Notification Events**: Status updates and error notifications
|
|
107
|
+
|
|
108
|
+
All events include correlation IDs for request/response tracking.
|
|
109
|
+
|
|
110
|
+
## TypeScript Support
|
|
111
|
+
|
|
112
|
+
Full TypeScript support with extensive type definitions:
|
|
113
|
+
|
|
114
|
+
```typescript
|
|
115
|
+
import {
|
|
116
|
+
Embed,
|
|
117
|
+
CatalogModule,
|
|
118
|
+
MockupGenerationModule,
|
|
119
|
+
NotificationEvent,
|
|
120
|
+
ResultEvent,
|
|
121
|
+
handleResponse
|
|
122
|
+
} from '@fyulorg/embed-sdk';
|
|
123
|
+
|
|
124
|
+
// All types are fully typed
|
|
125
|
+
const embed = new Embed('nonce');
|
|
126
|
+
const result: CatalogModule.GetProductsResult = await embed.catalog.getProducts(1);
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Development
|
|
130
|
+
|
|
131
|
+
### Setup
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
# Install dependencies
|
|
135
|
+
npm install
|
|
136
|
+
|
|
137
|
+
# Run tests
|
|
138
|
+
npm test
|
|
139
|
+
npm run test:watch
|
|
140
|
+
npm run test:coverage
|
|
141
|
+
|
|
142
|
+
# Build
|
|
143
|
+
npm run build
|
|
144
|
+
|
|
145
|
+
# Lint and format
|
|
146
|
+
npm run lint
|
|
147
|
+
npm run prettier
|
|
148
|
+
npm run lint:fix
|
|
149
|
+
npm run prettier:fix
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### Project Structure
|
|
153
|
+
|
|
154
|
+
```
|
|
155
|
+
src/
|
|
156
|
+
├── index.ts # Main SDK export
|
|
157
|
+
├── services/ # Core services
|
|
158
|
+
│ ├── embedCommunicator.ts
|
|
159
|
+
│ ├── iFrameManager.ts
|
|
160
|
+
│ ├── messagebroker.ts
|
|
161
|
+
│ └── moduleLoaderService.ts
|
|
162
|
+
├── modules/ # Feature modules
|
|
163
|
+
│ ├── catalog/
|
|
164
|
+
│ ├── mockup-generation/
|
|
165
|
+
│ └── sdk/
|
|
166
|
+
├── types/ # Shared type definitions
|
|
167
|
+
│ ├── event/
|
|
168
|
+
│ └── module/
|
|
169
|
+
└── helpers/ # Utility functions
|
|
170
|
+
|
|
171
|
+
tests/ # Test files (mirrors src structure)
|
|
172
|
+
├── services/
|
|
173
|
+
├── modules/
|
|
174
|
+
└── helpers/
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### Import Aliases
|
|
178
|
+
|
|
179
|
+
The project uses `~` aliases for clean imports:
|
|
180
|
+
|
|
181
|
+
```typescript
|
|
182
|
+
import { EmbedCommunicator } from '~/services/embedCommunicator';
|
|
183
|
+
import { CatalogModule } from '~/modules/catalog/catalogModule';
|
|
184
|
+
import { Event } from '~/types/event/event.types';
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## Building
|
|
188
|
+
|
|
189
|
+
The project builds to both ESM and CommonJS formats:
|
|
190
|
+
|
|
191
|
+
- **ESM**: `dist/esm/` - Modern ES modules
|
|
192
|
+
- **CJS**: `dist/cjs/` - Compatible CommonJS modules
|
|
193
|
+
|
|
194
|
+
The build process uses TypeScript compilation followed by `tsc-alias` for path resolution.
|
|
195
|
+
|
|
196
|
+
## License
|
|
197
|
+
|
|
198
|
+
ISC
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare const LOG_TYPES: {
|
|
2
|
+
readonly LOG: "log";
|
|
3
|
+
readonly INFO: "info";
|
|
4
|
+
readonly WARN: "warn";
|
|
5
|
+
readonly ERROR: "error";
|
|
6
|
+
};
|
|
7
|
+
export declare const SOURCES: {
|
|
8
|
+
readonly HOST: "Host";
|
|
9
|
+
readonly SDK: "SDK";
|
|
10
|
+
};
|
|
11
|
+
export interface MessageLoggerState {
|
|
12
|
+
isLoggerEnabled: boolean;
|
|
13
|
+
source: (typeof SOURCES)[keyof typeof SOURCES];
|
|
14
|
+
}
|
|
15
|
+
export declare const messageLoggerState: MessageLoggerState;
|
|
16
|
+
export declare function setLoggerState(isLoggerEnabled: boolean, source: MessageLoggerState['source']): void;
|
|
17
|
+
export declare function logEmbedMessage({ message, logType, }: {
|
|
18
|
+
message: string | unknown[];
|
|
19
|
+
logType?: (typeof LOG_TYPES)[keyof typeof LOG_TYPES];
|
|
20
|
+
}): void;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.messageLoggerState = exports.SOURCES = exports.LOG_TYPES = void 0;
|
|
4
|
+
exports.setLoggerState = setLoggerState;
|
|
5
|
+
exports.logEmbedMessage = logEmbedMessage;
|
|
6
|
+
exports.LOG_TYPES = {
|
|
7
|
+
LOG: 'log',
|
|
8
|
+
INFO: 'info',
|
|
9
|
+
WARN: 'warn',
|
|
10
|
+
ERROR: 'error',
|
|
11
|
+
};
|
|
12
|
+
exports.SOURCES = {
|
|
13
|
+
HOST: 'Host',
|
|
14
|
+
SDK: 'SDK',
|
|
15
|
+
};
|
|
16
|
+
exports.messageLoggerState = {
|
|
17
|
+
isLoggerEnabled: true,
|
|
18
|
+
source: exports.SOURCES.SDK,
|
|
19
|
+
};
|
|
20
|
+
function setLoggerState(isLoggerEnabled, source) {
|
|
21
|
+
exports.messageLoggerState.isLoggerEnabled = isLoggerEnabled;
|
|
22
|
+
exports.messageLoggerState.source = source;
|
|
23
|
+
}
|
|
24
|
+
function getSourceStyle(source) {
|
|
25
|
+
switch (source) {
|
|
26
|
+
case exports.SOURCES.HOST:
|
|
27
|
+
return `
|
|
28
|
+
background: #dc2626;
|
|
29
|
+
color: white;
|
|
30
|
+
padding: 2px 6px;
|
|
31
|
+
border-radius: 12px;
|
|
32
|
+
font-weight: bold;
|
|
33
|
+
`;
|
|
34
|
+
case exports.SOURCES.SDK:
|
|
35
|
+
return `
|
|
36
|
+
background: #3a82f6;
|
|
37
|
+
color: white;
|
|
38
|
+
padding: 2px 6px;
|
|
39
|
+
border-radius: 12px;
|
|
40
|
+
font-weight: bold;
|
|
41
|
+
`;
|
|
42
|
+
default:
|
|
43
|
+
return '';
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function logEmbedMessage({ message, logType = exports.LOG_TYPES.LOG, }) {
|
|
47
|
+
if (!exports.messageLoggerState.isLoggerEnabled && logType !== exports.LOG_TYPES.ERROR) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const src = exports.messageLoggerState.source;
|
|
51
|
+
const style = getSourceStyle(src);
|
|
52
|
+
const prefix = `%c${src}%c`;
|
|
53
|
+
// Normalize message to array
|
|
54
|
+
const msgArray = Array.isArray(message) ? message : [message];
|
|
55
|
+
// Arguments: prefix, styles, and the message parts
|
|
56
|
+
const args = [prefix, style, '', ...msgArray];
|
|
57
|
+
switch (logType) {
|
|
58
|
+
case 'log':
|
|
59
|
+
console.log(...args);
|
|
60
|
+
break;
|
|
61
|
+
case 'info':
|
|
62
|
+
console.info(...args);
|
|
63
|
+
break;
|
|
64
|
+
case 'warn':
|
|
65
|
+
console.warn(...args);
|
|
66
|
+
break;
|
|
67
|
+
case 'error':
|
|
68
|
+
console.error(...args);
|
|
69
|
+
break;
|
|
70
|
+
default:
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { HandledResponse } from '../types/event/result/resultEventPayload.types';
|
|
2
|
+
import { NotificationEventPayload } from '../types/event/notification/notificationEventPayload.types';
|
|
3
|
+
import { ResultEventPayload } from '../types/event/result/resultEventPayload.types';
|
|
4
|
+
export declare function isNotificationPayload(payload: ResultEventPayload | NotificationEventPayload): payload is NotificationEventPayload;
|
|
5
|
+
export declare function isErrorNotification(payload: NotificationEventPayload): boolean;
|
|
6
|
+
export declare function handleResponse<T extends ResultEventPayload>(response: T | NotificationEventPayload, context?: string): HandledResponse<T, Error>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isNotificationPayload = isNotificationPayload;
|
|
4
|
+
exports.isErrorNotification = isErrorNotification;
|
|
5
|
+
exports.handleResponse = handleResponse;
|
|
6
|
+
function isNotificationPayload(payload) {
|
|
7
|
+
return 'status' in payload && ('error' in payload || 'message' in payload);
|
|
8
|
+
}
|
|
9
|
+
function isErrorNotification(payload) {
|
|
10
|
+
return payload.status === 'error';
|
|
11
|
+
}
|
|
12
|
+
function handleResponse(response, context) {
|
|
13
|
+
if (isNotificationPayload(response)) {
|
|
14
|
+
if (isErrorNotification(response)) {
|
|
15
|
+
const errorMessage = context
|
|
16
|
+
? `${context}: ${response.message}`
|
|
17
|
+
: response.message;
|
|
18
|
+
const error = response.error || new Error(errorMessage);
|
|
19
|
+
error.message = errorMessage;
|
|
20
|
+
return { error, data: null };
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
error: new Error(`Unexpected success notification in request context: ${response.message}`),
|
|
24
|
+
data: null,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
return { error: null, data: response };
|
|
28
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { HandledResponse } from '../types/event/result/resultEventPayload.types';
|
|
2
|
+
/** Wraps all method returns in promises */
|
|
3
|
+
export type PromisifyMethods<T> = {
|
|
4
|
+
[K in keyof T]: T[K] extends (this: infer TThis, ...args: infer A) => infer R ? (this: TThis, ...args: A) => Promise<R> : T[K];
|
|
5
|
+
};
|
|
6
|
+
type AwaitedLike<T> = T extends PromiseLike<infer U> ? U : T;
|
|
7
|
+
export type WithHandledResponses<T, E extends Error = Error> = {
|
|
8
|
+
[K in keyof T]: T[K] extends (this: infer TThis, ...args: infer A) => infer R ? (this: TThis, ...args: A) => Promise<HandledResponse<AwaitedLike<R>, E>> : T[K] /** If not a method, remains unchanged **/;
|
|
9
|
+
};
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { SdkConfig } from './modules/sdk/types';
|
|
2
|
+
import { CatalogService } from './modules/catalog/catalogService';
|
|
3
|
+
import { MockupService } from './modules/mockup-generation/mockupService';
|
|
4
|
+
import { ProductPublishService } from './modules/product-publish/productPublishService';
|
|
5
|
+
export declare class Embed {
|
|
6
|
+
private config?;
|
|
7
|
+
static BASE_URL: string;
|
|
8
|
+
private nonce;
|
|
9
|
+
private iFrameManager;
|
|
10
|
+
private communicator;
|
|
11
|
+
private moduleLoader;
|
|
12
|
+
private initialized;
|
|
13
|
+
readonly catalog: CatalogService;
|
|
14
|
+
readonly mockup: MockupService;
|
|
15
|
+
readonly publish: ProductPublishService;
|
|
16
|
+
constructor(nonce: string, config?: SdkConfig | undefined);
|
|
17
|
+
init(): Promise<void>;
|
|
18
|
+
destroy(): void;
|
|
19
|
+
}
|
|
20
|
+
export * from './types/event/event.types';
|
|
21
|
+
export * from './types/event/eventPayload.types';
|
|
22
|
+
export * from './types/event/action/actionEvent.types';
|
|
23
|
+
export * from './types/event/action/actionEventPayload.types';
|
|
24
|
+
export * from './types/event/notification/notificationEvent.types';
|
|
25
|
+
export * from './types/event/notification/notificationEventPayload.types';
|
|
26
|
+
export * from './types/event/result/resultEvent.types';
|
|
27
|
+
export * from './types/event/result/resultEventPayload.types';
|
|
28
|
+
export * from './types/module/module.types';
|
|
29
|
+
export * from './types/module/moduleConfig.types';
|
|
30
|
+
export * as CatalogModule from './modules/catalog/types';
|
|
31
|
+
export * as MockupGenerationModule from './modules/mockup-generation/types';
|
|
32
|
+
export * as ProductPublishModule from './modules/product-publish/types';
|
|
33
|
+
export * as SdkModule from './modules/sdk/types';
|
|
34
|
+
export { ALL_EVENTS } from './modules/events';
|
|
35
|
+
export { MODULE_NAMES } from './modules/modules';
|
|
36
|
+
export { EVENT_TYPES } from './modules/eventTypes';
|
|
37
|
+
export { VERSION } from './version';
|
|
38
|
+
export { logEmbedMessage, setLoggerState, LOG_TYPES, SOURCES, } from './helpers/messageLogger';
|
|
39
|
+
export { handleResponse, isNotificationPayload, isErrorNotification, } from './helpers/responseHandler';
|
|
40
|
+
export { getSortedVariantList, getVariantImageGallery, } from './modules/catalog/helpers/variantUtils';
|
|
41
|
+
export { CatalogService } from './modules/catalog/catalogService';
|
|
42
|
+
export { MockupService } from './modules/mockup-generation/mockupService';
|
|
43
|
+
export { ProductPublishService } from './modules/product-publish/productPublishService';
|
|
44
|
+
export { PromisifyMethods } from './helpers/typeHelper.types';
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
19
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
20
|
+
};
|
|
21
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
22
|
+
var ownKeys = function(o) {
|
|
23
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
24
|
+
var ar = [];
|
|
25
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
26
|
+
return ar;
|
|
27
|
+
};
|
|
28
|
+
return ownKeys(o);
|
|
29
|
+
};
|
|
30
|
+
return function (mod) {
|
|
31
|
+
if (mod && mod.__esModule) return mod;
|
|
32
|
+
var result = {};
|
|
33
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
34
|
+
__setModuleDefault(result, mod);
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
})();
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.ProductPublishService = exports.MockupService = exports.CatalogService = exports.getVariantImageGallery = exports.getSortedVariantList = exports.isErrorNotification = exports.isNotificationPayload = exports.handleResponse = exports.SOURCES = exports.LOG_TYPES = exports.setLoggerState = exports.logEmbedMessage = exports.VERSION = exports.EVENT_TYPES = exports.MODULE_NAMES = exports.ALL_EVENTS = exports.SdkModule = exports.ProductPublishModule = exports.MockupGenerationModule = exports.CatalogModule = exports.Embed = void 0;
|
|
40
|
+
const iFrameManager_1 = require("./services/iFrameManager");
|
|
41
|
+
const embedCommunicator_1 = require("./services/embedCommunicator");
|
|
42
|
+
const moduleLoaderService_1 = require("./services/moduleLoaderService");
|
|
43
|
+
const modules_1 = require("./modules/modules");
|
|
44
|
+
const catalogService_1 = require("./modules/catalog/catalogService");
|
|
45
|
+
const mockupService_1 = require("./modules/mockup-generation/mockupService");
|
|
46
|
+
const productPublishService_1 = require("./modules/product-publish/productPublishService");
|
|
47
|
+
const version_1 = require("./version");
|
|
48
|
+
const messageLogger_1 = require("./helpers/messageLogger");
|
|
49
|
+
class Embed {
|
|
50
|
+
config;
|
|
51
|
+
static BASE_URL = 'https://www.printful.com/embed-sdk';
|
|
52
|
+
nonce;
|
|
53
|
+
iFrameManager = null;
|
|
54
|
+
communicator = embedCommunicator_1.EmbedCommunicator.getInstance();
|
|
55
|
+
moduleLoader = moduleLoaderService_1.ModuleLoaderService.getInstance();
|
|
56
|
+
initialized = false;
|
|
57
|
+
// Service composition
|
|
58
|
+
catalog;
|
|
59
|
+
mockup;
|
|
60
|
+
publish;
|
|
61
|
+
constructor(nonce, config) {
|
|
62
|
+
this.config = config;
|
|
63
|
+
this.nonce = nonce;
|
|
64
|
+
(0, messageLogger_1.setLoggerState)(config?.debug ?? false, messageLogger_1.SOURCES.SDK);
|
|
65
|
+
// Initialize services
|
|
66
|
+
this.catalog = new catalogService_1.CatalogService();
|
|
67
|
+
this.mockup = new mockupService_1.MockupService();
|
|
68
|
+
this.publish = new productPublishService_1.ProductPublishService();
|
|
69
|
+
}
|
|
70
|
+
async init() {
|
|
71
|
+
if (this.initialized) {
|
|
72
|
+
(0, messageLogger_1.logEmbedMessage)({
|
|
73
|
+
message: 'Embed SDK already initialized',
|
|
74
|
+
logType: messageLogger_1.LOG_TYPES.WARN,
|
|
75
|
+
});
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
// Client mode: Create iframe and setup communication
|
|
79
|
+
this.iFrameManager = new iFrameManager_1.iFrameManager({
|
|
80
|
+
baseUrl: Embed.BASE_URL,
|
|
81
|
+
nonce: this.nonce,
|
|
82
|
+
});
|
|
83
|
+
await this.iFrameManager.create();
|
|
84
|
+
// Setup communicator with iframe manager
|
|
85
|
+
this.communicator.setIFrameManager(this.iFrameManager);
|
|
86
|
+
this.communicator.setupListener();
|
|
87
|
+
// Get SDK module and setup
|
|
88
|
+
const sdkModule = this.moduleLoader.getModule(modules_1.MODULE_NAMES.SDK);
|
|
89
|
+
const notification = await sdkModule.setup({
|
|
90
|
+
...this.config,
|
|
91
|
+
clientVersion: version_1.VERSION,
|
|
92
|
+
});
|
|
93
|
+
(0, messageLogger_1.logEmbedMessage)({
|
|
94
|
+
message: ['SDK (Main) module setup notification', notification],
|
|
95
|
+
logType: messageLogger_1.LOG_TYPES.LOG,
|
|
96
|
+
});
|
|
97
|
+
this.initialized = true;
|
|
98
|
+
}
|
|
99
|
+
destroy() {
|
|
100
|
+
if (this.iFrameManager) {
|
|
101
|
+
this.iFrameManager.destroy();
|
|
102
|
+
this.iFrameManager = null;
|
|
103
|
+
}
|
|
104
|
+
this.communicator.cleanup();
|
|
105
|
+
this.moduleLoader.clearCache();
|
|
106
|
+
this.initialized = false;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
exports.Embed = Embed;
|
|
110
|
+
/* EXPORTS */
|
|
111
|
+
// TODO: properly foldered exports?
|
|
112
|
+
// Common types
|
|
113
|
+
__exportStar(require("./types/event/event.types"), exports);
|
|
114
|
+
__exportStar(require("./types/event/eventPayload.types"), exports);
|
|
115
|
+
__exportStar(require("./types/event/action/actionEvent.types"), exports);
|
|
116
|
+
__exportStar(require("./types/event/action/actionEventPayload.types"), exports);
|
|
117
|
+
__exportStar(require("./types/event/notification/notificationEvent.types"), exports);
|
|
118
|
+
__exportStar(require("./types/event/notification/notificationEventPayload.types"), exports);
|
|
119
|
+
__exportStar(require("./types/event/result/resultEvent.types"), exports);
|
|
120
|
+
__exportStar(require("./types/event/result/resultEventPayload.types"), exports);
|
|
121
|
+
__exportStar(require("./types/module/module.types"), exports);
|
|
122
|
+
__exportStar(require("./types/module/moduleConfig.types"), exports);
|
|
123
|
+
// Barrel module exports
|
|
124
|
+
exports.CatalogModule = __importStar(require("./modules/catalog/types"));
|
|
125
|
+
exports.MockupGenerationModule = __importStar(require("./modules/mockup-generation/types"));
|
|
126
|
+
exports.ProductPublishModule = __importStar(require("./modules/product-publish/types"));
|
|
127
|
+
exports.SdkModule = __importStar(require("./modules/sdk/types"));
|
|
128
|
+
// Constants
|
|
129
|
+
var events_1 = require("./modules/events");
|
|
130
|
+
Object.defineProperty(exports, "ALL_EVENTS", { enumerable: true, get: function () { return events_1.ALL_EVENTS; } });
|
|
131
|
+
var modules_2 = require("./modules/modules");
|
|
132
|
+
Object.defineProperty(exports, "MODULE_NAMES", { enumerable: true, get: function () { return modules_2.MODULE_NAMES; } });
|
|
133
|
+
var eventTypes_1 = require("./modules/eventTypes");
|
|
134
|
+
Object.defineProperty(exports, "EVENT_TYPES", { enumerable: true, get: function () { return eventTypes_1.EVENT_TYPES; } });
|
|
135
|
+
// Internals
|
|
136
|
+
var version_2 = require("./version");
|
|
137
|
+
Object.defineProperty(exports, "VERSION", { enumerable: true, get: function () { return version_2.VERSION; } });
|
|
138
|
+
var messageLogger_2 = require("./helpers/messageLogger");
|
|
139
|
+
Object.defineProperty(exports, "logEmbedMessage", { enumerable: true, get: function () { return messageLogger_2.logEmbedMessage; } });
|
|
140
|
+
Object.defineProperty(exports, "setLoggerState", { enumerable: true, get: function () { return messageLogger_2.setLoggerState; } });
|
|
141
|
+
Object.defineProperty(exports, "LOG_TYPES", { enumerable: true, get: function () { return messageLogger_2.LOG_TYPES; } });
|
|
142
|
+
Object.defineProperty(exports, "SOURCES", { enumerable: true, get: function () { return messageLogger_2.SOURCES; } });
|
|
143
|
+
// Helper utilities
|
|
144
|
+
var responseHandler_1 = require("./helpers/responseHandler");
|
|
145
|
+
Object.defineProperty(exports, "handleResponse", { enumerable: true, get: function () { return responseHandler_1.handleResponse; } });
|
|
146
|
+
Object.defineProperty(exports, "isNotificationPayload", { enumerable: true, get: function () { return responseHandler_1.isNotificationPayload; } });
|
|
147
|
+
Object.defineProperty(exports, "isErrorNotification", { enumerable: true, get: function () { return responseHandler_1.isErrorNotification; } });
|
|
148
|
+
var variantUtils_1 = require("./modules/catalog/helpers/variantUtils");
|
|
149
|
+
Object.defineProperty(exports, "getSortedVariantList", { enumerable: true, get: function () { return variantUtils_1.getSortedVariantList; } });
|
|
150
|
+
Object.defineProperty(exports, "getVariantImageGallery", { enumerable: true, get: function () { return variantUtils_1.getVariantImageGallery; } });
|
|
151
|
+
// Service classes (for type annotations)
|
|
152
|
+
var catalogService_2 = require("./modules/catalog/catalogService");
|
|
153
|
+
Object.defineProperty(exports, "CatalogService", { enumerable: true, get: function () { return catalogService_2.CatalogService; } });
|
|
154
|
+
var mockupService_2 = require("./modules/mockup-generation/mockupService");
|
|
155
|
+
Object.defineProperty(exports, "MockupService", { enumerable: true, get: function () { return mockupService_2.MockupService; } });
|
|
156
|
+
var productPublishService_2 = require("./modules/product-publish/productPublishService");
|
|
157
|
+
Object.defineProperty(exports, "ProductPublishService", { enumerable: true, get: function () { return productPublishService_2.ProductPublishService; } });
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ActionEventName } from '../types/event/action/actionEvent.types';
|
|
2
|
+
import { ActionEventPayload } from '../types/event/action/actionEventPayload.types';
|
|
3
|
+
import { ResultEventPayload } from '../types/event/result/resultEventPayload.types';
|
|
4
|
+
import { NotificationEventPayload } from '../types/event/notification/notificationEventPayload.types';
|
|
5
|
+
export declare abstract class BaseModule {
|
|
6
|
+
protected sendRequest<T extends ResultEventPayload | NotificationEventPayload>(eventName: ActionEventName, eventPayload?: ActionEventPayload): Promise<T>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseModule = void 0;
|
|
4
|
+
const embedCommunicator_1 = require("../services/embedCommunicator");
|
|
5
|
+
class BaseModule {
|
|
6
|
+
async sendRequest(eventName, eventPayload) {
|
|
7
|
+
return await embedCommunicator_1.EmbedCommunicator.getInstance().sendCorrelatedRequest(eventName, eventPayload);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.BaseModule = BaseModule;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ModuleLoaderService } from '../services/moduleLoaderService';
|
|
2
|
+
import { ModuleName } from '../types/module/module.types';
|
|
3
|
+
import { ModuleConfigData } from '../types/module/moduleConfig.types';
|
|
4
|
+
import { MODULES } from './modules';
|
|
5
|
+
type ModuleInstance = InstanceType<(typeof MODULES)[keyof typeof MODULES]>;
|
|
6
|
+
export declare abstract class BaseModuleService {
|
|
7
|
+
protected moduleLoader: ModuleLoaderService;
|
|
8
|
+
protected ensureModuleLoaded<T extends ModuleInstance>(moduleName: ModuleName, config?: ModuleConfigData): Promise<T>;
|
|
9
|
+
}
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseModuleService = void 0;
|
|
4
|
+
const moduleLoaderService_1 = require("../services/moduleLoaderService");
|
|
5
|
+
class BaseModuleService {
|
|
6
|
+
moduleLoader = moduleLoaderService_1.ModuleLoaderService.getInstance();
|
|
7
|
+
async ensureModuleLoaded(moduleName, config) {
|
|
8
|
+
return this.moduleLoader.ensureModuleLoaded(moduleName, config);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.BaseModuleService = BaseModuleService;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ICatalogModule } from '../../types/module/module.types';
|
|
2
|
+
import { BaseModule } from '../../modules/baseModule';
|
|
3
|
+
import { GetCatalogCategoriesResultPayload, GetCatalogProductsResultPayload, GetSingleCatalogProductResultPayload } from './types';
|
|
4
|
+
import { WithHandledResponses } from '../../helpers/typeHelper.types';
|
|
5
|
+
export declare class CatalogModule extends BaseModule implements WithHandledResponses<ICatalogModule> {
|
|
6
|
+
getProducts(categoryId: number, page?: number): Promise<import("../..").HandledResponse<GetCatalogProductsResultPayload, Error>>;
|
|
7
|
+
getProduct(productId: number): Promise<import("../..").HandledResponse<GetSingleCatalogProductResultPayload, Error>>;
|
|
8
|
+
getCategories(): Promise<import("../..").HandledResponse<GetCatalogCategoriesResultPayload, Error>>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CatalogModule = void 0;
|
|
4
|
+
const baseModule_1 = require("../../modules/baseModule");
|
|
5
|
+
const types_1 = require("./types");
|
|
6
|
+
const responseHandler_1 = require("../../helpers/responseHandler");
|
|
7
|
+
class CatalogModule extends baseModule_1.BaseModule {
|
|
8
|
+
async getProducts(categoryId, page = 1) {
|
|
9
|
+
const response = await this.sendRequest(types_1.EVENTS_ACTION.GET_CATALOG_PRODUCTS, {
|
|
10
|
+
categoryId,
|
|
11
|
+
page,
|
|
12
|
+
}).catch((e) => e);
|
|
13
|
+
return (0, responseHandler_1.handleResponse)(response, 'Failed to get catalog products');
|
|
14
|
+
}
|
|
15
|
+
async getProduct(productId) {
|
|
16
|
+
const response = await this.sendRequest(types_1.EVENTS_ACTION.GET_SINGLE_CATALOG_PRODUCT, {
|
|
17
|
+
productId,
|
|
18
|
+
}).catch((e) => e);
|
|
19
|
+
return (0, responseHandler_1.handleResponse)(response, 'Failed to get catalog products');
|
|
20
|
+
}
|
|
21
|
+
async getCategories() {
|
|
22
|
+
const response = await this.sendRequest(types_1.EVENTS_ACTION.GET_CATALOG_CATEGORIES).catch((e) => e);
|
|
23
|
+
return (0, responseHandler_1.handleResponse)(response, 'Failed to get catalog categories');
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.CatalogModule = CatalogModule;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { BaseModuleService } from '../../modules/baseModuleService';
|
|
2
|
+
export declare class CatalogService extends BaseModuleService {
|
|
3
|
+
private getCatalogModule;
|
|
4
|
+
getCategories(): Promise<import("../..").HandledResponse<import("./types").GetCatalogCategoriesResultPayload, Error>>;
|
|
5
|
+
getProducts(categoryId: number, page?: number): Promise<import("../..").HandledResponse<import("./types").GetCatalogProductsResultPayload, Error>>;
|
|
6
|
+
getProduct(productId: number): Promise<import("../..").HandledResponse<import("./types").GetSingleCatalogProductResultPayload, Error>>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CatalogService = void 0;
|
|
4
|
+
const baseModuleService_1 = require("../../modules/baseModuleService");
|
|
5
|
+
const modules_1 = require("../../modules/modules");
|
|
6
|
+
class CatalogService extends baseModuleService_1.BaseModuleService {
|
|
7
|
+
async getCatalogModule() {
|
|
8
|
+
return this.ensureModuleLoaded(modules_1.MODULE_NAMES.CATALOG);
|
|
9
|
+
}
|
|
10
|
+
async getCategories() {
|
|
11
|
+
const module = await this.getCatalogModule();
|
|
12
|
+
return module.getCategories();
|
|
13
|
+
}
|
|
14
|
+
async getProducts(categoryId, page = 1) {
|
|
15
|
+
const module = await this.getCatalogModule();
|
|
16
|
+
return module.getProducts(categoryId, page);
|
|
17
|
+
}
|
|
18
|
+
async getProduct(productId) {
|
|
19
|
+
const module = await this.getCatalogModule();
|
|
20
|
+
return module.getProduct(productId);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.CatalogService = CatalogService;
|