@pinecall/pinecall-booking-sdk 1.0.2 → 1.0.3

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.
Files changed (2) hide show
  1. package/package.json +5 -3
  2. package/src/index.cjs +59 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pinecall/pinecall-booking-sdk",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Simple, elegant SDK for Pinecall Booking API. Zero dependencies.",
5
5
  "main": "src/index.js",
6
6
  "types": "src/index.d.ts",
@@ -8,9 +8,11 @@
8
8
  "exports": {
9
9
  ".": {
10
10
  "import": "./src/index.js",
11
- "require": "./src/index.cjs"
11
+ "require": "./src/index.js",
12
+ "default": "./src/index.js"
12
13
  }
13
14
  },
15
+ "module": "./src/index.js",
14
16
  "scripts": {
15
17
  "test": "node --test test/*.test.js",
16
18
  "test:watch": "node --test --watch test/*.test.js",
@@ -45,4 +47,4 @@
45
47
  "README.md",
46
48
  "LICENSE"
47
49
  ]
48
- }
50
+ }
package/src/index.cjs ADDED
@@ -0,0 +1,59 @@
1
+ /**
2
+ * @pinecall/pinecall-booking-sdk - CommonJS Entry Point
3
+ *
4
+ * Re-exports the ESM module for CommonJS environments.
5
+ * This uses createRequire to properly load the ESM version.
6
+ */
7
+
8
+ 'use strict';
9
+
10
+ const { createRequire } = require('module');
11
+ const { pathToFileURL } = require('url');
12
+ const path = require('path');
13
+
14
+ // Create a require function that can load ESM
15
+ const esmPath = path.join(__dirname, 'index.js');
16
+
17
+ // For Node.js 18+ with ESM interop
18
+ let mod;
19
+
20
+ try {
21
+ // Try dynamic import via synchronous wrapper
22
+ // This works because we're in an async context when the module loads
23
+ const importPromise = import(pathToFileURL(esmPath).href);
24
+
25
+ // Export a promise-based API for CJS consumers
26
+ module.exports = {
27
+ __esModule: true,
28
+ ready: importPromise.then(m => {
29
+ Object.assign(module.exports, m);
30
+ return m;
31
+ }),
32
+ // Placeholder until ready
33
+ Pinecall: null,
34
+ PinecallError: null,
35
+ ValidationError: null,
36
+ NotFoundError: null,
37
+ ConflictError: null,
38
+ BOOKING_STATUS: null,
39
+ BUSINESS_TYPES: null
40
+ };
41
+
42
+ // Immediately populate exports when loaded
43
+ importPromise.then(m => {
44
+ module.exports.Pinecall = m.Pinecall;
45
+ module.exports.PinecallError = m.PinecallError;
46
+ module.exports.ValidationError = m.ValidationError;
47
+ module.exports.NotFoundError = m.NotFoundError;
48
+ module.exports.ConflictError = m.ConflictError;
49
+ module.exports.BOOKING_STATUS = m.BOOKING_STATUS;
50
+ module.exports.BUSINESS_TYPES = m.BUSINESS_TYPES;
51
+ });
52
+ } catch (e) {
53
+ // Fallback error
54
+ const error = new Error(
55
+ '@pinecall/pinecall-booking-sdk requires ESM support. ' +
56
+ 'Please use dynamic import: const { Pinecall } = await import("@pinecall/pinecall-booking-sdk")'
57
+ );
58
+ throw error;
59
+ }