@insforge/sdk 1.3.0 → 1.3.2-razorpay.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.
@@ -0,0 +1,27 @@
1
+ # Contributing to InsForge SDK
2
+
3
+ Thanks for helping improve the InsForge JavaScript SDK.
4
+
5
+ ## Development Setup
6
+
7
+ 1. Fork and clone this repository.
8
+ 2. Install dependencies:
9
+
10
+ ```bash
11
+ npm install
12
+ ```
13
+
14
+ 3. Run the relevant checks before opening a pull request:
15
+
16
+ ```bash
17
+ npm run typecheck
18
+ npm run lint
19
+ npm run test:run
20
+ ```
21
+
22
+ ## Pull Requests
23
+
24
+ - Keep changes focused and describe the user-facing impact.
25
+ - Add or update tests when changing SDK behavior.
26
+ - Update `README.md` or `SDK-REFERENCE.md` when changing public APIs.
27
+ - Link related issues in the pull request description.
package/README.md CHANGED
@@ -74,10 +74,13 @@ const { data, error } = await insforge.auth.signInWithPassword({
74
74
  });
75
75
 
76
76
  // OAuth authentication (built-in or custom provider key)
77
- await insforge.auth.signInWithOAuth({
78
- provider: "google", // e.g. built-in: "google", custom: "auth0-acme"
77
+ await insforge.auth.signInWithOAuth("google", {
79
78
  redirectTo: "http://localhost:3000/dashboard",
79
+ additionalParams: { prompt: "select_account" },
80
80
  });
81
+ // additionalParams is for provider-specific hints only.
82
+ // Do not pass client_id, scope, redirect_uri, code_challenge, state, or response_type;
83
+ // InsForge sets server-owned OAuth fields and ignores colliding client-provided keys.
81
84
 
82
85
  // Get current user (call this during browser app startup)
83
86
  const { data: currentUser } = await insforge.auth.getCurrentUser();
@@ -203,13 +206,16 @@ const { data, error } = await insforge.functions.invoke("my-function", {
203
206
 
204
207
  ```javascript
205
208
  // Create and redirect to a Stripe Checkout Session
206
- const { data, error } = await insforge.payments.createCheckoutSession("test", {
207
- mode: "payment",
208
- lineItems: [{ stripePriceId: "price_123", quantity: 1 }],
209
- successUrl: `${window.location.origin}/success`,
210
- cancelUrl: `${window.location.origin}/pricing`,
211
- idempotencyKey: "cart_123",
212
- });
209
+ const { data, error } = await insforge.payments.stripe.createCheckoutSession(
210
+ "test",
211
+ {
212
+ mode: "payment",
213
+ lineItems: [{ priceId: "price_123", quantity: 1 }],
214
+ successUrl: `${window.location.origin}/success`,
215
+ cancelUrl: `${window.location.origin}/pricing`,
216
+ idempotencyKey: "cart_123",
217
+ },
218
+ );
213
219
 
214
220
  if (!error && data?.checkoutSession.url) {
215
221
  window.location.assign(data.checkoutSession.url);
@@ -217,10 +223,10 @@ if (!error && data?.checkoutSession.url) {
217
223
 
218
224
  // Create a subscription checkout for an app billing subject
219
225
  const { data: subscriptionCheckout } =
220
- await insforge.payments.createCheckoutSession("test", {
226
+ await insforge.payments.stripe.createCheckoutSession("test", {
221
227
  mode: "subscription",
222
228
  subject: { type: "team", id: "team_123" },
223
- lineItems: [{ stripePriceId: "price_monthly_123", quantity: 1 }],
229
+ lineItems: [{ priceId: "price_monthly_123", quantity: 1 }],
224
230
  successUrl: `${window.location.origin}/billing/success`,
225
231
  cancelUrl: `${window.location.origin}/billing`,
226
232
  });
@@ -230,33 +236,82 @@ if (subscriptionCheckout?.checkoutSession.url) {
230
236
  }
231
237
 
232
238
  // Let an authenticated customer manage their subscription in Stripe Billing Portal
233
- const { data: portal } = await insforge.payments.createCustomerPortalSession(
234
- "test",
235
- {
239
+ const { data: portal } =
240
+ await insforge.payments.stripe.createCustomerPortalSession("test", {
236
241
  subject: { type: "team", id: "team_123" },
237
242
  returnUrl: `${window.location.origin}/billing`,
238
- },
239
- );
243
+ });
240
244
 
241
245
  if (portal?.customerPortalSession.url) {
242
246
  window.location.assign(portal.customerPortalSession.url);
243
247
  }
248
+
249
+ // Create a Razorpay order, then pass checkoutOptions to Razorpay Checkout.js
250
+ const { data: order } = await insforge.payments.razorpay.createOrder("test", {
251
+ amount: 200000,
252
+ currency: "INR",
253
+ subject: { type: "team", id: "team_123" },
254
+ customerEmail: "ada@example.com",
255
+ });
256
+
257
+ if (order) {
258
+ const checkout = new Razorpay({
259
+ ...order.checkoutOptions,
260
+ handler: async (response) => {
261
+ await insforge.payments.razorpay.verifyOrder("test", {
262
+ orderId: response.razorpay_order_id,
263
+ paymentId: response.razorpay_payment_id,
264
+ signature: response.razorpay_signature,
265
+ });
266
+ },
267
+ });
268
+ checkout.open();
269
+ }
270
+
271
+ // Create a Razorpay subscription checkout for an app billing subject
272
+ const { data: subscription } =
273
+ await insforge.payments.razorpay.createSubscription("test", {
274
+ planId: "plan_123",
275
+ totalCount: 12,
276
+ subject: { type: "team", id: "team_123" },
277
+ });
244
278
  ```
245
279
 
246
280
  ### AI Integration
247
281
 
282
+ AI methods return an OpenAI-like response object directly (not the `{ data, error }` envelope used by the other modules) and throw on failure.
283
+
248
284
  ```javascript
249
- // Generate text completion
250
- const { data, error } = await insforge.ai.completion({
251
- model: "gpt-3.5-turbo",
252
- prompt: "Write a hello world program",
285
+ // Chat completion
286
+ const completion = await insforge.ai.chat.completions.create({
287
+ model: "anthropic/claude-3.5-haiku",
288
+ messages: [{ role: "user", content: "Write a hello world program" }],
289
+ });
290
+ console.log(completion.choices[0].message.content);
291
+
292
+ // Streaming chat — returns an async iterable of chunks
293
+ const stream = await insforge.ai.chat.completions.create({
294
+ model: "anthropic/claude-3.5-haiku",
295
+ messages: [{ role: "user", content: "Tell me a story" }],
296
+ stream: true,
297
+ });
298
+ for await (const chunk of stream) {
299
+ process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
300
+ }
301
+
302
+ // Generate an image — returns base64-encoded image data
303
+ const image = await insforge.ai.images.generate({
304
+ model: "google/gemini-3-pro-image-preview",
305
+ prompt: "A sunset over mountains",
253
306
  });
307
+ const base64Png = image.data[0].b64_json;
254
308
 
255
- // Analyze an image
256
- const { data, error } = await insforge.ai.vision({
257
- imageUrl: "https://example.com/image.jpg",
258
- prompt: "Describe this image",
309
+ // Create embeddings
310
+ const embeddings = await insforge.ai.embeddings.create({
311
+ model: "openai/text-embedding-3-small",
312
+ input: "Hello world",
259
313
  });
314
+ console.log(embeddings.data[0].embedding); // number[]
260
315
  ```
261
316
 
262
317
  ## Documentation