@cimplify/sdk 0.2.0 → 0.2.2

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 ADDED
@@ -0,0 +1,175 @@
1
+ # @cimplify/sdk
2
+
3
+ The official TypeScript SDK for building storefronts with the Cimplify Commerce Engine.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @cimplify/sdk
9
+ # or
10
+ yarn add @cimplify/sdk
11
+ # or
12
+ bun add @cimplify/sdk
13
+ ```
14
+
15
+ ## Quick Start
16
+
17
+ ```typescript
18
+ import { createCimplifyClient } from '@cimplify/sdk';
19
+
20
+ const cimplify = createCimplifyClient();
21
+
22
+ // Fetch products
23
+ const products = await cimplify.catalogue.getProducts();
24
+
25
+ // Add to cart
26
+ await cimplify.cart.addItem({ item_id: 'product-id', quantity: 1 });
27
+
28
+ // Get cart
29
+ const cart = await cimplify.cart.get();
30
+ ```
31
+
32
+ ## Services
33
+
34
+ ### Catalogue
35
+
36
+ ```typescript
37
+ // Products
38
+ const products = await cimplify.catalogue.getProducts();
39
+ const featured = await cimplify.catalogue.getProducts({ featured: true, limit: 10 });
40
+ const product = await cimplify.catalogue.getProduct('product-id');
41
+ const product = await cimplify.catalogue.getProductBySlug('my-product');
42
+
43
+ // Variants
44
+ const variants = await cimplify.catalogue.getVariants('product-id');
45
+ const variant = await cimplify.catalogue.getVariantByAxisSelections('product-id', {
46
+ Size: 'Large',
47
+ Color: 'Red',
48
+ });
49
+
50
+ // Categories & Collections
51
+ const categories = await cimplify.catalogue.getCategories();
52
+ const collections = await cimplify.catalogue.getCollections();
53
+
54
+ // Bundles & Composites
55
+ const bundles = await cimplify.catalogue.getBundles();
56
+ const composites = await cimplify.catalogue.getComposites();
57
+
58
+ // Search
59
+ const results = await cimplify.catalogue.search('coffee');
60
+ ```
61
+
62
+ ### Cart
63
+
64
+ ```typescript
65
+ const cart = await cimplify.cart.get();
66
+ const count = await cimplify.cart.getCount();
67
+
68
+ await cimplify.cart.addItem({
69
+ item_id: 'product-id',
70
+ quantity: 2,
71
+ configuration: {
72
+ variant: { variant_id: 'variant-id' },
73
+ add_ons: [{ add_on_id: 'addon-id', quantity: 1 }],
74
+ },
75
+ });
76
+
77
+ await cimplify.cart.updateQuantity('cart-item-id', 3);
78
+ await cimplify.cart.removeItem('cart-item-id');
79
+ await cimplify.cart.clear();
80
+
81
+ await cimplify.cart.applyCoupon('SUMMER20');
82
+ await cimplify.cart.removeCoupon();
83
+ ```
84
+
85
+ ### Orders
86
+
87
+ ```typescript
88
+ const orders = await cimplify.orders.getOrders();
89
+ const order = await cimplify.orders.getOrder('order-id');
90
+ ```
91
+
92
+ ### Authentication
93
+
94
+ ```typescript
95
+ const status = await cimplify.auth.getStatus();
96
+ const user = await cimplify.auth.getCurrentUser();
97
+
98
+ await cimplify.auth.requestOtp('+1234567890', 'phone');
99
+ const result = await cimplify.auth.verifyOtp('123456', '+1234567890');
100
+ await cimplify.auth.logout();
101
+ ```
102
+
103
+ ### Business & Locations
104
+
105
+ ```typescript
106
+ const business = await cimplify.business.getBusiness();
107
+ const locations = await cimplify.business.getLocations();
108
+ ```
109
+
110
+ ### Scheduling
111
+
112
+ ```typescript
113
+ const slots = await cimplify.scheduling.getAvailableSlots({
114
+ location_id: 'location-id',
115
+ date: '2025-01-15',
116
+ service_type: 'delivery',
117
+ });
118
+ ```
119
+
120
+ ### Inventory
121
+
122
+ ```typescript
123
+ const stock = await cimplify.inventory.checkStock('product-id', 'location-id');
124
+ ```
125
+
126
+ ## Price Utilities
127
+
128
+ ```typescript
129
+ import { formatPrice, formatPriceCompact, isOnSale, getDiscountPercentage } from '@cimplify/sdk';
130
+
131
+ formatPrice(29.99, 'USD'); // "$29.99"
132
+ formatPrice(29.99, 'GHS'); // "GH₵29.99"
133
+ formatPriceCompact(2500000, 'USD'); // "$2.5M"
134
+
135
+ if (isOnSale(product)) {
136
+ console.log(`${getDiscountPercentage(product)}% off!`);
137
+ }
138
+ ```
139
+
140
+ ## Error Handling
141
+
142
+ ```typescript
143
+ import { CimplifyError } from '@cimplify/sdk';
144
+
145
+ try {
146
+ await cimplify.cart.addItem({ item_id: 'invalid', quantity: 1 });
147
+ } catch (error) {
148
+ if (error instanceof CimplifyError) {
149
+ console.log(error.code); // "PRODUCT_NOT_FOUND"
150
+ console.log(error.message); // "Product not found"
151
+ }
152
+ }
153
+ ```
154
+
155
+ ## TypeScript
156
+
157
+ ```typescript
158
+ import type {
159
+ Product,
160
+ ProductWithDetails,
161
+ ProductVariant,
162
+ Category,
163
+ Collection,
164
+ Bundle,
165
+ Composite,
166
+ Cart,
167
+ CartItem,
168
+ Order,
169
+ Customer,
170
+ } from '@cimplify/sdk';
171
+ ```
172
+
173
+ ## License
174
+
175
+ MIT
package/dist/index.d.mts CHANGED
@@ -2329,7 +2329,11 @@ declare class SchedulingService {
2329
2329
  private client;
2330
2330
  constructor(client: CimplifyClient);
2331
2331
  getServices(): Promise<Service[]>;
2332
- getService(serviceId: string): Promise<Service>;
2332
+ /**
2333
+ * Get a specific service by ID
2334
+ * Note: Filters from all services client-side (no single-service endpoint)
2335
+ */
2336
+ getService(serviceId: string): Promise<Service | null>;
2333
2337
  getAvailableSlots(input: GetAvailableSlotsInput): Promise<AvailableSlot[]>;
2334
2338
  checkSlotAvailability(input: CheckSlotAvailabilityInput): Promise<{
2335
2339
  available: boolean;
package/dist/index.d.ts CHANGED
@@ -2329,7 +2329,11 @@ declare class SchedulingService {
2329
2329
  private client;
2330
2330
  constructor(client: CimplifyClient);
2331
2331
  getServices(): Promise<Service[]>;
2332
- getService(serviceId: string): Promise<Service>;
2332
+ /**
2333
+ * Get a specific service by ID
2334
+ * Note: Filters from all services client-side (no single-service endpoint)
2335
+ */
2336
+ getService(serviceId: string): Promise<Service | null>;
2333
2337
  getAvailableSlots(input: GetAvailableSlotsInput): Promise<AvailableSlot[]>;
2334
2338
  checkSlotAvailability(input: CheckSlotAvailabilityInput): Promise<{
2335
2339
  available: boolean;
package/dist/index.js CHANGED
@@ -871,27 +871,32 @@ var SchedulingService = class {
871
871
  async getServices() {
872
872
  return this.client.query("scheduling.services");
873
873
  }
874
+ /**
875
+ * Get a specific service by ID
876
+ * Note: Filters from all services client-side (no single-service endpoint)
877
+ */
874
878
  async getService(serviceId) {
875
- return this.client.query(`scheduling.services.${serviceId}`);
879
+ const services = await this.getServices();
880
+ return services.find((s) => s.id === serviceId) || null;
876
881
  }
877
882
  // --------------------------------------------------------------------------
878
883
  // AVAILABILITY
879
884
  // --------------------------------------------------------------------------
880
885
  async getAvailableSlots(input) {
881
886
  return this.client.query(
882
- "scheduling.available_slots",
887
+ "scheduling.slots",
883
888
  input
884
889
  );
885
890
  }
886
891
  async checkSlotAvailability(input) {
887
892
  return this.client.query(
888
- "scheduling.check_slot",
893
+ "scheduling.check_availability",
889
894
  input
890
895
  );
891
896
  }
892
897
  async getServiceAvailability(params) {
893
898
  return this.client.query(
894
- "scheduling.service_availability",
899
+ "scheduling.availability",
895
900
  params
896
901
  );
897
902
  }
@@ -899,19 +904,19 @@ var SchedulingService = class {
899
904
  // BOOKINGS
900
905
  // --------------------------------------------------------------------------
901
906
  async getBooking(bookingId) {
902
- return this.client.query(`scheduling.bookings.${bookingId}`);
907
+ return this.client.query(`scheduling.${bookingId}`);
903
908
  }
904
909
  async getCustomerBookings() {
905
- return this.client.query("scheduling.customer_bookings");
910
+ return this.client.query("scheduling");
906
911
  }
907
912
  async getUpcomingBookings() {
908
913
  return this.client.query(
909
- "scheduling.customer_bookings[?(@.status!='completed' && @.status!='cancelled')]#sort(start_time,asc)"
914
+ "scheduling[?(@.status!='completed' && @.status!='cancelled')]#sort(start_time,asc)"
910
915
  );
911
916
  }
912
917
  async getPastBookings(limit = 10) {
913
918
  return this.client.query(
914
- `scheduling.customer_bookings[?(@.status=='completed')]#sort(start_time,desc)#limit(${limit})`
919
+ `scheduling[?(@.status=='completed')]#sort(start_time,desc)#limit(${limit})`
915
920
  );
916
921
  }
917
922
  // --------------------------------------------------------------------------
package/dist/index.mjs CHANGED
@@ -869,27 +869,32 @@ var SchedulingService = class {
869
869
  async getServices() {
870
870
  return this.client.query("scheduling.services");
871
871
  }
872
+ /**
873
+ * Get a specific service by ID
874
+ * Note: Filters from all services client-side (no single-service endpoint)
875
+ */
872
876
  async getService(serviceId) {
873
- return this.client.query(`scheduling.services.${serviceId}`);
877
+ const services = await this.getServices();
878
+ return services.find((s) => s.id === serviceId) || null;
874
879
  }
875
880
  // --------------------------------------------------------------------------
876
881
  // AVAILABILITY
877
882
  // --------------------------------------------------------------------------
878
883
  async getAvailableSlots(input) {
879
884
  return this.client.query(
880
- "scheduling.available_slots",
885
+ "scheduling.slots",
881
886
  input
882
887
  );
883
888
  }
884
889
  async checkSlotAvailability(input) {
885
890
  return this.client.query(
886
- "scheduling.check_slot",
891
+ "scheduling.check_availability",
887
892
  input
888
893
  );
889
894
  }
890
895
  async getServiceAvailability(params) {
891
896
  return this.client.query(
892
- "scheduling.service_availability",
897
+ "scheduling.availability",
893
898
  params
894
899
  );
895
900
  }
@@ -897,19 +902,19 @@ var SchedulingService = class {
897
902
  // BOOKINGS
898
903
  // --------------------------------------------------------------------------
899
904
  async getBooking(bookingId) {
900
- return this.client.query(`scheduling.bookings.${bookingId}`);
905
+ return this.client.query(`scheduling.${bookingId}`);
901
906
  }
902
907
  async getCustomerBookings() {
903
- return this.client.query("scheduling.customer_bookings");
908
+ return this.client.query("scheduling");
904
909
  }
905
910
  async getUpcomingBookings() {
906
911
  return this.client.query(
907
- "scheduling.customer_bookings[?(@.status!='completed' && @.status!='cancelled')]#sort(start_time,asc)"
912
+ "scheduling[?(@.status!='completed' && @.status!='cancelled')]#sort(start_time,asc)"
908
913
  );
909
914
  }
910
915
  async getPastBookings(limit = 10) {
911
916
  return this.client.query(
912
- `scheduling.customer_bookings[?(@.status=='completed')]#sort(start_time,desc)#limit(${limit})`
917
+ `scheduling[?(@.status=='completed')]#sort(start_time,desc)#limit(${limit})`
913
918
  );
914
919
  }
915
920
  // --------------------------------------------------------------------------
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cimplify/sdk",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Cimplify Commerce SDK for storefronts",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -12,7 +12,9 @@
12
12
  "require": "./dist/index.js"
13
13
  }
14
14
  },
15
- "files": ["dist"],
15
+ "files": [
16
+ "dist"
17
+ ],
16
18
  "scripts": {
17
19
  "build": "tsup",
18
20
  "dev": "tsup --watch",
@@ -24,6 +26,11 @@
24
26
  "tsup": "^8.0.0",
25
27
  "typescript": "5.9.2"
26
28
  },
27
- "keywords": ["cimplify", "commerce", "sdk", "storefront"],
29
+ "keywords": [
30
+ "cimplify",
31
+ "commerce",
32
+ "sdk",
33
+ "storefront"
34
+ ],
28
35
  "license": "MIT"
29
36
  }