@putiikkipalvelu/storefront-sdk 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +44 -7
- package/dist/index.cjs +1314 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2267 -155
- package/dist/index.d.ts +2267 -155
- package/dist/index.js +1313 -4
- package/dist/index.js.map +1 -1
- package/package.json +6 -7
package/README.md
CHANGED
|
@@ -13,15 +13,15 @@ npm install @putiikkipalvelu/storefront-sdk
|
|
|
13
13
|
## Quick Start
|
|
14
14
|
|
|
15
15
|
```typescript
|
|
16
|
-
import {
|
|
16
|
+
import { createStorefrontClient } from '@putiikkipalvelu/storefront-sdk';
|
|
17
17
|
|
|
18
|
-
const
|
|
18
|
+
const storefront = createStorefrontClient({
|
|
19
19
|
apiKey: process.env.STOREFRONT_API_KEY!,
|
|
20
|
-
baseUrl: 'https://putiikkipalvelu.fi',
|
|
20
|
+
baseUrl: 'https://putiikkipalvelu.fi/api/storefront/v1',
|
|
21
21
|
});
|
|
22
22
|
|
|
23
23
|
// Get store configuration
|
|
24
|
-
const config = await
|
|
24
|
+
const config = await storefront.store.getConfig();
|
|
25
25
|
console.log(config.store.name);
|
|
26
26
|
```
|
|
27
27
|
|
|
@@ -29,9 +29,9 @@ console.log(config.store.name);
|
|
|
29
29
|
|
|
30
30
|
```typescript
|
|
31
31
|
// lib/storefront.ts
|
|
32
|
-
import {
|
|
32
|
+
import { createStorefrontClient } from '@putiikkipalvelu/storefront-sdk';
|
|
33
33
|
|
|
34
|
-
export const storefront =
|
|
34
|
+
export const storefront = createStorefrontClient({
|
|
35
35
|
apiKey: process.env.STOREFRONT_API_KEY!,
|
|
36
36
|
baseUrl: process.env.NEXT_PUBLIC_STOREFRONT_API_URL!,
|
|
37
37
|
});
|
|
@@ -41,10 +41,47 @@ export const storefront = new StorefrontClient({
|
|
|
41
41
|
|
|
42
42
|
```typescript
|
|
43
43
|
const config = await storefront.store.getConfig({
|
|
44
|
-
next: { revalidate: 300
|
|
44
|
+
next: { revalidate: 300, tags: ['store-config'] }
|
|
45
45
|
});
|
|
46
46
|
```
|
|
47
47
|
|
|
48
|
+
## Error Handling
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
import {
|
|
52
|
+
createStorefrontClient,
|
|
53
|
+
AuthError,
|
|
54
|
+
NotFoundError,
|
|
55
|
+
StorefrontError
|
|
56
|
+
} from '@putiikkipalvelu/storefront-sdk';
|
|
57
|
+
|
|
58
|
+
try {
|
|
59
|
+
const config = await storefront.store.getConfig();
|
|
60
|
+
} catch (error) {
|
|
61
|
+
if (error instanceof AuthError) {
|
|
62
|
+
// Invalid API key
|
|
63
|
+
} else if (error instanceof NotFoundError) {
|
|
64
|
+
// Resource not found
|
|
65
|
+
} else if (error instanceof StorefrontError) {
|
|
66
|
+
// Other API error
|
|
67
|
+
console.error(error.code, error.message);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## TypeScript
|
|
73
|
+
|
|
74
|
+
All types are exported for use in your application:
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
import type {
|
|
78
|
+
StoreConfig,
|
|
79
|
+
StoreInfo,
|
|
80
|
+
Product,
|
|
81
|
+
Campaign
|
|
82
|
+
} from '@putiikkipalvelu/storefront-sdk';
|
|
83
|
+
```
|
|
84
|
+
|
|
48
85
|
## Available Resources
|
|
49
86
|
|
|
50
87
|
- `store.getConfig()` - Store configuration, SEO, payments, campaigns
|