-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexample-client.ts
More file actions
108 lines (97 loc) · 3.23 KB
/
example-client.ts
File metadata and controls
108 lines (97 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/* eslint-disable no-console */
/**
* Copyright 2025 Adobe. All Rights Reserved.
*
* This file is licensed to you under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, either express or implied. See the License for
* the specific language governing permissions and limitations under the License.
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) using custom templates.
* Generator configuration can be found in the /generator directory.
*
* Do not edit this file manually!
*/
import { config } from 'dotenv';
import { createClient, Client } from './src/client';
import {
ClientConfig,
Region,
Environment,
FeedProduct,
FeedProductStatusEnum,
FeedProductVisibleInEnum,
} from './src/types';
// Load environment variables from .env file
config();
// Validate required environment variables
const requiredEnvVars = ['IMS_CLIENT_ID', 'IMS_CLIENT_SECRET', 'TENANT_ID', 'REGION', 'ENVIRONMENT'];
for (const envVar of requiredEnvVars) {
if (!process.env[envVar]) {
throw new Error(`Missing required environment variable: ${envVar}`);
}
}
async function main(): Promise<void> {
// Define your configuration
const config: ClientConfig = {
credentials: {
clientId: process.env.IMS_CLIENT_ID!,
clientSecret: process.env.IMS_CLIENT_SECRET!,
},
tenantId: process.env.TENANT_ID!,
region: process.env.REGION as Region,
environment: process.env.ENVIRONMENT as Environment,
};
// Initialize the client instance
const client: Client = createClient(config);
// Define a couple of products
const product1: FeedProduct = {
sku: 'EXAMPLE-SKU-001',
source: { locale: 'en-US' },
name: 'Example Product 1',
slug: 'example-product-1',
description: 'This is an example product created via the SDK',
status: FeedProductStatusEnum.Enabled,
visibleIn: [FeedProductVisibleInEnum.Catalog, FeedProductVisibleInEnum.Search],
attributes: [
{
code: 'brand',
values: ['Example Brand'],
},
{
code: 'category',
values: ['Electronics'],
},
],
};
const product2: FeedProduct = {
sku: 'EXAMPLE-SKU-002',
source: { locale: 'en-US' },
name: 'Example Product 2',
slug: 'example-product-2',
description: 'This is another example product created via the SDK',
status: FeedProductStatusEnum.Enabled,
visibleIn: [FeedProductVisibleInEnum.Catalog, FeedProductVisibleInEnum.Search],
attributes: [
{
code: 'brand',
values: ['Example Brand'],
},
{
code: 'category',
values: ['Electronics'],
},
],
};
// Create the products
try {
const response = await client.createProducts([product1, product2]);
console.log('Product created successfully:', response);
} catch (error) {
console.error('Error creating product:', error);
}
}
// Run the example
main().catch(console.error);