@godaddy/gd-commerce-server 0.1.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/LICENSE.md ADDED
@@ -0,0 +1,3 @@
1
+ Copyright 2026 GoDaddy.com Operating Company, LLC
2
+
3
+ Licensed under the MIT License.
package/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # @godaddy/gd-commerce-server
2
+
3
+ An opinionated Express router for GoDaddy Commerce catalog, cart, and hosted checkout APIs.
4
+
5
+ ```ts
6
+ import express from 'express';
7
+ import { createCommerceRouter, createRuntimeCommerceConfiguration } from '@godaddy/gd-commerce-server';
8
+
9
+ const app = express();
10
+ app.use(express.json());
11
+ app.use('/api/commerce', createCommerceRouter({
12
+ configuration: createRuntimeCommerceConfiguration(),
13
+ checkoutReturnUrls: {
14
+ returnUrls: ['https://shop.example.com/shop'],
15
+ successUrls: ['https://shop.example.com/checkout/success'],
16
+ },
17
+ }));
18
+ ```
19
+
20
+ The default configuration reads these **server-only environment variables** on each request:
21
+
22
+ - `GODADDY_OAUTH_CLIENT_ID` and `GODADDY_OAUTH_CLIENT_SECRET`
23
+ - `GODADDY_STORE_ID` and `GODADDY_CHANNEL_ID`
24
+ - `GODADDY_CURRENCY_CODE`
25
+ - Optional `GODADDY_CHECKOUT_CONFIGURATION`: JSON with boolean `enablePromotionCodes`, `enableTaxCollection`, and `enableShipping` fields. All three default to false when this variable is absent or malformed so configuration discovery cannot prevent checkout creation. Optional `shipping` accepts the checkout API's `originAddress` or `fulfillmentLocationId`; omit it to use store configuration.
26
+
27
+ See [Checkout configuration](docs/checkout-configuration.md) for the temporary build-time synchronization flow and its eventual-consistency limitation.
28
+
29
+ The API origin defaults to `https://api.godaddy.com`. The package does not load files, provision merchants, or assign application attribution. Hosts own these concerns and any readiness checks or retries before invoking Commerce.
30
+
31
+ ## Host configuration
32
+
33
+ For an alternate API origin, pass an explicit server-controlled option. It must be an HTTPS origin without credentials, a path, query, or fragment. The host is responsible for trusting the destination, which receives OAuth credentials. Request bodies never select the API origin or attribution.
34
+
35
+ ```ts
36
+ const configuration = createRuntimeCommerceConfiguration({
37
+ apiBaseUrl: process.env.COMMERCE_API_ORIGIN, // undefined uses production
38
+ sourceApp: process.env.COMMERCE_SOURCE_APP,
39
+ owner: process.env.COMMERCE_ORDER_OWNER,
40
+ });
41
+ ```
42
+
43
+ `apiBaseUrl` controls catalog, order, and OAuth requests; checkout uses the corresponding `checkout.commerce.` subdomain. There is no built-in list of alternate environments. `sourceApp` and `owner` are optional host-owned attribution values: checkout uses both, while draft orders use `owner`. Supply values required by your Commerce integration; the package omits them by default.
44
+
45
+ Hosts with their own configuration service can implement `CommerceConfiguration` directly. `read()` returns `clientId`, `clientSecret`, `storeId`, `channelId`, `currencyCode`, `apiBaseUrl`, and optional attribution. `readCheckout()` returns the checkout flags and optional shipping settings. Return validated, ready-to-use settings from one consistent binding. Both functions run on the server; credentials must never reach browser code.
46
+
47
+ ## Routers and helpers
48
+
49
+ `createCommerceCatalogRouter(configuration)` installs catalog, public configuration, and cart routes. `createGoDaddyPaymentsRouter(configuration, checkoutReturnUrls)` installs checkout and read-only order-status routes without requiring catalog UI. `createCommerceRouter({ configuration })` installs both by default or accepts explicit feature flags.
50
+
51
+ The HTTP checkout route accepts an existing `draftOrderId` or a direct `skuId`; Commerce resolves catalog prices. It rejects `lineItemData`. For non-catalog charges such as fixed-price deposits, calculate the amount on the server and call `createCheckoutSession(params, configuration)` directly. Never forward browser-supplied prices to this trusted helper. Server callers can also use `getOrderStatus(orderId, configuration)` without an HTTP loopback.
52
+
53
+ ## Checkout return destinations
54
+
55
+ Configure `checkoutReturnUrls` on the router using trusted deployment settings. Both lists contain complete absolute HTTPS URLs; scheme, origin, port, path, and configured query parameters must match. Success URLs may add a single `orderId` query parameter. Additional query parameters, fragments, credentials, relative URLs, and unlisted destinations are rejected. Configure separate cancel and success destinations as shown above; do not derive the allowlist from request headers or request bodies.
56
+
57
+ Without this policy, HTTP checkout returns 503 before creating a session. Invalid request destinations return 400. This applies to both router presets that expose checkout. Trusted in-process callers of `createCheckoutSession()` own their return URLs and must construct or validate them server-side.
58
+
59
+ A return from hosted checkout is not proof of payment. The order-status route uses the authorized Orders REST API, which supports completed orders, and returns its payment status (for example `PAID` or `PENDING`; `unknown` if absent). The server OAuth client must be granted `commerce.order:read`. The helper verifies the returned order ID, store, and channel and returns a limited summary without customer contact data. Hosts must authenticate callers and authorize access to each requested order before exposing this route.
@@ -0,0 +1,146 @@
1
+ import { Router } from "express";
2
+
3
+ //#region src/lib/commerce/checkout-config.d.ts
4
+ /** Shipping options accepted by the hosted checkout API. Omit to use the store's configuration. */
5
+ interface CommerceCheckoutShippingConfiguration {
6
+ readonly originAddress?: Readonly<Record<string, unknown>>;
7
+ readonly fulfillmentLocationId?: string;
8
+ }
9
+ interface CommerceCheckoutConfiguration {
10
+ readonly enablePromotionCodes: boolean;
11
+ readonly enableTaxCollection: boolean;
12
+ readonly enableShipping: boolean;
13
+ readonly shipping?: CommerceCheckoutShippingConfiguration;
14
+ }
15
+ declare function parseCommerceCheckoutConfiguration(raw: string | undefined): CommerceCheckoutConfiguration;
16
+ //#endregion
17
+ //#region src/lib/commerce/checkout-return-urls.d.ts
18
+ /** Exact host-owned checkout destinations. Only success URLs may add an orderId query parameter. */
19
+ interface CheckoutReturnUrls {
20
+ returnUrls: readonly string[];
21
+ successUrls: readonly string[];
22
+ }
23
+ //#endregion
24
+ //#region src/lib/commerce/config.d.ts
25
+ interface CommerceConfig {
26
+ /** Public OAuth client id. */
27
+ clientId: string;
28
+ /** Server-only OAuth client secret. Never expose to the browser. */
29
+ clientSecret: string;
30
+ storeId: string;
31
+ /** Sales channel used for orders and checkout. */
32
+ channelId: string;
33
+ /** HTTPS API origin. The default configuration uses https://api.godaddy.com. */
34
+ apiBaseUrl: string;
35
+ /** ISO 4217 currency code used when seeding empty cart totals. */
36
+ currencyCode: string;
37
+ /** Optional host-owned checkout attribution. Never read from request bodies. */
38
+ sourceApp?: string;
39
+ /** Optional host-owned attribution shared by draft orders and checkout. */
40
+ owner?: string;
41
+ }
42
+ interface CommerceConfiguration {
43
+ read(): CommerceConfig;
44
+ readCheckout(): CommerceCheckoutConfiguration;
45
+ }
46
+ interface RuntimeCommerceConfigurationOptions {
47
+ /** Server environment containing credentials, store/channel IDs, currency, and checkout flags. */
48
+ environment?: NodeJS.ProcessEnv;
49
+ /** Explicit server-controlled API origin override. Defaults to production. */
50
+ apiBaseUrl?: string;
51
+ sourceApp?: string;
52
+ owner?: string;
53
+ }
54
+ /** Read server environment values on each call. Loading files or secret stores belongs to the host. */
55
+ declare function readCommerceConfig(options?: RuntimeCommerceConfigurationOptions): CommerceConfig;
56
+ declare function createRuntimeCommerceConfiguration(options?: RuntimeCommerceConfigurationOptions): CommerceConfiguration;
57
+ //#endregion
58
+ //#region src/lib/commerce/checkout-subgraph.d.ts
59
+
60
+ interface CheckoutSessionLineItemPriceDataInput {
61
+ /** Price per unit in the currency's smallest unit (e.g. cents for USD). */
62
+ unitAmount: number;
63
+ /** ISO 4217 currency code. If omitted, the server injects it from GODADDY_CURRENCY_CODE. */
64
+ currencyCode?: string;
65
+ }
66
+ interface CheckoutSessionLineItemDataInput {
67
+ name: string;
68
+ priceData: CheckoutSessionLineItemPriceDataInput;
69
+ }
70
+ //#endregion
71
+ //#region src/lib/commerce/create-checkout-session.d.ts
72
+ interface CreateCheckoutSessionParams {
73
+ /** Where the hosted checkout sends the shopper on cancel/back. */
74
+ returnUrl: string;
75
+ /** Where the hosted checkout sends the shopper after payment. */
76
+ successUrl: string;
77
+ /** Existing cart/draft order to convert to a checkout session. */
78
+ draftOrderId?: string;
79
+ /** Buy-Now path; checkout is built from a single SKU line item. */
80
+ skuId?: string;
81
+ /** Quantity for Buy-Now / non-catalog paths. Defaults to 1. */
82
+ quantity?: number;
83
+ /**
84
+ * Non-catalog path; price the customer pays directly without a SKU or
85
+ * catalog product. Mutually exclusive with `skuId` and `draftOrderId`.
86
+ */
87
+ lineItemData?: CheckoutSessionLineItemDataInput;
88
+ }
89
+ interface CheckoutSession {
90
+ /** Hosted checkout URL to redirect the shopper to. */
91
+ url: string;
92
+ /** Checkout session id (not the order id). */
93
+ id: string;
94
+ /**
95
+ * Draft order id when the API created one (cart + Buy-Now flows). `null` for
96
+ * non-catalog sessions, which have no draft order.
97
+ */
98
+ draftOrderId: string | null;
99
+ /** Store id returned by checkout-api after it accepts the session. */
100
+ storeId: string;
101
+ /** Sales channel id returned by checkout-api after it accepts the session. */
102
+ channelId: string;
103
+ /** Commerce business that owns the selected store. */
104
+ businessId: string | null;
105
+ /** Store display name returned by checkout-api. */
106
+ storeName: string | null;
107
+ /** Server-owned source identifier used for transaction attribution. */
108
+ sourceApp: string | null;
109
+ }
110
+ declare function createCheckoutSession(params: CreateCheckoutSessionParams, configuration?: CommerceConfiguration): Promise<CheckoutSession>;
111
+ //#endregion
112
+ //#region src/lib/commerce/get-order-status.d.ts
113
+ interface CommerceOrderStatus {
114
+ /** GoDaddy order id. */
115
+ id: string;
116
+ /** Payment status reported by Commerce, or 'unknown' when it is unavailable. */
117
+ status: string;
118
+ /** Total amount in the currency's smallest unit (cents for USD). */
119
+ amount: number;
120
+ /** ISO 4217 currency code (e.g. "USD"). */
121
+ currency: string;
122
+ /** ISO 8601 creation timestamp. */
123
+ createdAt?: string;
124
+ /** ISO 8601 last-updated timestamp. */
125
+ updatedAt?: string;
126
+ /** Line item summaries, excluding private order metadata. */
127
+ lineItems?: unknown[];
128
+ }
129
+ declare function getOrderStatus(orderId: string, configuration?: CommerceConfiguration): Promise<CommerceOrderStatus>;
130
+ //#endregion
131
+ //#region src/router.d.ts
132
+ interface CommerceRouterFeatures {
133
+ catalog?: boolean;
134
+ payments?: boolean;
135
+ }
136
+ interface CreateCommerceRouterOptions {
137
+ configuration?: CommerceConfiguration;
138
+ features?: CommerceRouterFeatures;
139
+ /** Required to enable browser checkout; never derived from request headers. */
140
+ checkoutReturnUrls?: CheckoutReturnUrls;
141
+ }
142
+ declare function createCommerceRouter(options?: CreateCommerceRouterOptions): Router;
143
+ declare function createCommerceCatalogRouter(configuration?: CommerceConfiguration): Router;
144
+ declare function createGoDaddyPaymentsRouter(configuration?: CommerceConfiguration, checkoutReturnUrls?: CheckoutReturnUrls): Router;
145
+ //#endregion
146
+ export { type CheckoutReturnUrls, type CheckoutSession, type CommerceCheckoutConfiguration, type CommerceCheckoutShippingConfiguration, type CommerceConfig, type CommerceConfiguration, type CommerceOrderStatus, type CommerceRouterFeatures, type CreateCheckoutSessionParams, type CreateCommerceRouterOptions, type RuntimeCommerceConfigurationOptions, createCheckoutSession, createCommerceCatalogRouter, createCommerceRouter, createGoDaddyPaymentsRouter, createRuntimeCommerceConfiguration, getOrderStatus, parseCommerceCheckoutConfiguration, readCommerceConfig };