@waffo/pancake-ts 0.1.9 → 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/dist/index.js CHANGED
@@ -1,6 +1,3 @@
1
- // src/http-client.ts
2
- import { createHash as createHash2 } from "crypto";
3
-
4
1
  // src/errors.ts
5
2
  var WaffoPancakeError = class extends Error {
6
3
  status;
@@ -14,6 +11,45 @@ var WaffoPancakeError = class extends Error {
14
11
  }
15
12
  };
16
13
 
14
+ // src/buyer-http-client.ts
15
+ var DEFAULT_BASE_URL = "https://api.waffo.ai";
16
+ var BuyerHttpClient = class {
17
+ token;
18
+ baseUrl;
19
+ _fetch;
20
+ constructor(token, config) {
21
+ this.token = token;
22
+ this.baseUrl = (config.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
23
+ this._fetch = config.fetch ?? fetch;
24
+ }
25
+ /**
26
+ * Send a Bearer-authenticated POST request and return the parsed `data` field.
27
+ *
28
+ * @param path - API path
29
+ * @param body - Request body object
30
+ * @returns Parsed `data` field from the response
31
+ * @throws {WaffoPancakeError} When the API returns errors
32
+ */
33
+ async post(path, body) {
34
+ const response = await this._fetch(`${this.baseUrl}${path}`, {
35
+ method: "POST",
36
+ headers: {
37
+ "Content-Type": "application/json",
38
+ "Authorization": `Bearer ${this.token}`
39
+ },
40
+ body: JSON.stringify(body)
41
+ });
42
+ const result = await response.json();
43
+ if ("errors" in result && result.errors) {
44
+ throw new WaffoPancakeError(response.status, result.errors);
45
+ }
46
+ return result.data;
47
+ }
48
+ };
49
+
50
+ // src/http-client.ts
51
+ import { createHash as createHash2 } from "crypto";
52
+
17
53
  // src/signing.ts
18
54
  import { createHash, createPrivateKey, createPublicKey, createSign } from "crypto";
19
55
  var PKCS8_HEADER = "-----BEGIN PRIVATE KEY-----";
@@ -126,7 +162,7 @@ ${bodyHash}`;
126
162
  }
127
163
 
128
164
  // src/http-client.ts
129
- var DEFAULT_BASE_URL = "https://api.waffo.ai";
165
+ var DEFAULT_BASE_URL2 = "https://api.waffo.ai";
130
166
  var HttpClient = class {
131
167
  merchantId;
132
168
  privateKey;
@@ -135,7 +171,7 @@ var HttpClient = class {
135
171
  constructor(config) {
136
172
  this.merchantId = config.merchantId;
137
173
  this.privateKey = normalizePrivateKey(config.privateKey);
138
- this.baseUrl = (config.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
174
+ this.baseUrl = (config.baseUrl ?? DEFAULT_BASE_URL2).replace(/\/+$/, "");
139
175
  this._fetch = config.fetch ?? fetch;
140
176
  }
141
177
  /**
@@ -196,6 +232,121 @@ var AuthResource = class {
196
232
  }
197
233
  };
198
234
 
235
+ // src/resources/buyer.ts
236
+ var BuyerSession = class {
237
+ constructor(http) {
238
+ this.http = http;
239
+ this.graphql = new BuyerGraphQL(http);
240
+ }
241
+ /** GraphQL query access scoped to the buyer's data. */
242
+ graphql;
243
+ /**
244
+ * Cancel a subscription order.
245
+ *
246
+ * @param params - Order to cancel
247
+ * @returns Order ID and resulting status
248
+ *
249
+ * @example
250
+ * const { orderId, status } = await buyer.cancelSubscription({ orderId: "ORD_xxx" });
251
+ * // status: "canceled" (was pending) or "canceling" (was active)
252
+ */
253
+ async cancelSubscription(params) {
254
+ return this.http.post(
255
+ "/v1/actions/subscription-order/cancel-order",
256
+ params
257
+ );
258
+ }
259
+ /**
260
+ * Cancel a one-time order (only while payment is still pending).
261
+ *
262
+ * @param params - Order to cancel
263
+ * @returns Order ID and resulting status
264
+ *
265
+ * @example
266
+ * const { orderId, status } = await buyer.cancelOnetimeOrder({ orderId: "ORD_xxx" });
267
+ */
268
+ async cancelOnetimeOrder(params) {
269
+ return this.http.post(
270
+ "/v1/actions/onetime-order/cancel-order",
271
+ params
272
+ );
273
+ }
274
+ /**
275
+ * Reactivate a subscription that is in `canceling` status.
276
+ *
277
+ * @param params - Order to reactivate
278
+ * @returns Order ID and resulting status
279
+ *
280
+ * @example
281
+ * const { orderId, status } = await buyer.reactivateSubscription({ orderId: "ORD_xxx" });
282
+ * // status: "active"
283
+ */
284
+ async reactivateSubscription(params) {
285
+ return this.http.post(
286
+ "/v1/actions/subscription-order/reactivate-order",
287
+ params
288
+ );
289
+ }
290
+ /**
291
+ * Submit a refund request for a payment.
292
+ *
293
+ * @param params - Refund ticket details
294
+ * @returns Created refund ticket
295
+ *
296
+ * @example
297
+ * const { ticket } = await buyer.createRefundTicket({
298
+ * paymentId: "PAY_xxx",
299
+ * reason: "Product not as described",
300
+ * requestedAmount: { amount: "29.00", currency: "USD" },
301
+ * });
302
+ */
303
+ async createRefundTicket(params) {
304
+ return this.http.post(
305
+ "/v1/actions/refund-ticket/create-ticket",
306
+ params
307
+ );
308
+ }
309
+ /**
310
+ * Resubmit a previously rejected refund ticket with updated details.
311
+ *
312
+ * @param params - Updated ticket details
313
+ * @returns Updated refund ticket
314
+ *
315
+ * @example
316
+ * const { ticket } = await buyer.resubmitRefundTicket({
317
+ * ticketId: "TKT_xxx",
318
+ * paymentId: "PAY_xxx",
319
+ * reason: "Updated reason with more detail",
320
+ * requestedAmount: { amount: "29.00", currency: "USD" },
321
+ * });
322
+ */
323
+ async resubmitRefundTicket(params) {
324
+ return this.http.post(
325
+ "/v1/actions/refund-ticket/resubmit-ticket",
326
+ params
327
+ );
328
+ }
329
+ };
330
+ var BuyerGraphQL = class {
331
+ constructor(http) {
332
+ this.http = http;
333
+ }
334
+ /**
335
+ * Execute a GraphQL query scoped to the buyer's data.
336
+ *
337
+ * @param params - GraphQL query and variables
338
+ * @returns GraphQL response
339
+ *
340
+ * @example
341
+ * const result = await buyer.graphql.query({
342
+ * query: `query { orders { id status } }`,
343
+ * });
344
+ */
345
+ async query(params) {
346
+ return this.http.post("/v1/graphql", params);
347
+ }
348
+ };
349
+
199
350
  // src/resources/checkout-anonymous.ts
200
351
  var CheckoutAnonymousResource = class {
201
352
  constructor(http) {
@@ -280,7 +431,7 @@ var CheckoutResource = class {
280
431
  this.anonymous = new CheckoutAnonymousResource(http);
281
432
  this.authenticated = new CheckoutAuthenticatedResource(http);
282
433
  }
283
- /** Anonymous checkout — visitor enters without a session token. */
434
+ /** Anonymous checkout — no buyer identity, empty form. */
284
435
  anonymous;
285
436
  /** Authenticated checkout — merchant provides buyer identity. */
286
437
  authenticated;
@@ -805,6 +956,7 @@ var WebhooksResource = class {
805
956
  // src/client.ts
806
957
  var WaffoPancake = class {
807
958
  http;
959
+ config;
808
960
  auth;
809
961
  stores;
810
962
  storeMerchants;
@@ -816,6 +968,7 @@ var WaffoPancake = class {
816
968
  graphql;
817
969
  webhooks;
818
970
  constructor(config) {
971
+ this.config = config;
819
972
  this.http = new HttpClient(config);
820
973
  this.auth = new AuthResource(this.http);
821
974
  this.stores = new StoresResource(this.http);
@@ -828,6 +981,31 @@ var WaffoPancake = class {
828
981
  this.graphql = new GraphQLResource(this.http);
829
982
  this.webhooks = new WebhooksResource(config.webhookPublicKey);
830
983
  }
984
+ /**
985
+ * Create a buyer session for self-service operations.
986
+ *
987
+ * The returned session uses Bearer token authentication and provides
988
+ * methods for order cancellation, subscription management, refund tickets,
989
+ * and scoped GraphQL queries.
990
+ *
991
+ * @param token - Session token from `client.auth.issueSessionToken()`
992
+ * @returns A buyer session with self-service methods
993
+ *
994
+ * @example
995
+ * const { token } = await client.auth.issueSessionToken({
996
+ * storeId: "STO_xxx",
997
+ * buyerIdentity: "customer@example.com",
998
+ * });
999
+ * const buyer = client.buyer(token);
1000
+ * await buyer.cancelSubscription({ orderId: "ORD_xxx" });
1001
+ */
1002
+ buyer(token) {
1003
+ const buyerHttp = new BuyerHttpClient(token, {
1004
+ baseUrl: this.config.baseUrl,
1005
+ fetch: this.config.fetch
1006
+ });
1007
+ return new BuyerSession(buyerHttp);
1008
+ }
831
1009
  };
832
1010
 
833
1011
  // src/types.ts