@salefony/api-sdk 1.0.7 → 1.0.8

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 CHANGED
@@ -506,12 +506,8 @@ const { total, page, limit, totalPages, hasNextPage } = meta ?? {};
506
506
  Connect Google Analytics, Facebook Business, TikTok Pixel, etc. OAuth flow runs on the backend.
507
507
 
508
508
  ```typescript
509
- // Start OAuth – redirect user
510
- const url = sdk.admin.integrations.getAuthorizeUrl(
511
- 'google-analytics',
512
- 'https://app.example.com/admin/analytics'
513
- );
514
- window.location.href = url; // React/Next.js
509
+ // Start OAuth – URL oluşturur ve otomatik yönlendirir
510
+ sdk.admin.integrations.authorize('google-analytics', '/admin/analytics');
515
511
 
516
512
  // Check connection status
517
513
  const { data } = await sdk.admin.integrations.getStatus('google-analytics');
@@ -524,9 +520,9 @@ await sdk.admin.integrations.disconnect('google-analytics');
524
520
 
525
521
  | Platform | Flow |
526
522
  |--------------------|--------------------------------------------------------------|
527
- | React / Next.js | `window.location.href = getAuthorizeUrl(...)` |
528
- | Expo / React Native| `Linking.openURL(url)` or WebView with `redirect_uri`: `myapp://` |
529
- | Node.js | Return URL or `res.redirect(url)` |
523
+ | React / Next.js | `authorize('google-analytics', '/admin/analytics')` – otomatik redirect |
524
+ | Expo / React Native| `url = authorize(...)` + `Linking.openURL(url)` sadece URL döner |
525
+ | Node.js | `url = authorize(...)` – sadece URL döner, `res.redirect(url)` |
530
526
 
531
527
  Full guide: [Integrations Documentation](./docs/INTEGRATIONS.md)
532
528
 
package/dist/index.d.mts CHANGED
@@ -1253,21 +1253,30 @@ interface IntegrationConnectionStatus {
1253
1253
  * Tüm OAuth akışları backend üzerinden yönetilir - proxy yok.
1254
1254
  *
1255
1255
  * Kullanım:
1256
- * - Bağlantı başlat: window.location.href = sdk.admin.integrations.getAuthorizeUrl('google-analytics', redirectUri)
1256
+ * - Bağlantı başlat: sdk.admin.integrations.authorize('google-analytics', '/admin/analytics')
1257
1257
  * - Durum: sdk.admin.integrations.getStatus('google-analytics')
1258
1258
  * - Bağlantı kes: sdk.admin.integrations.disconnect('google-analytics')
1259
1259
  */
1260
1260
  declare class IntegrationsResource extends BaseResource {
1261
1261
  constructor(httpClient: AxiosInstance);
1262
1262
  /**
1263
- * OAuth başlatma URL'ini döner.
1264
- * Frontend bu URL'e yönlendirir (window.location.href = url).
1265
- * Cookie/Authorization ile backend'e gidilir, backend Google'a redirect eder.
1263
+ * OAuth başlatır: URL üretir ve tarayıcıda yönlendirir.
1264
+ * Kullanıcının URL oluşturup window.location atamasına gerek kalmaz.
1265
+ *
1266
+ * @param provider - Provider ID (google-analytics, facebook-business, vb.)
1267
+ * @param redirectUriOrPath - Tam URL veya path (örn: '/admin/analytics'). Verilmezse mevcut sayfa kullanılır.
1268
+ * @returns Oluşturulan URL (Node.js / Expo gibi ortamlarda manuel kullanım için)
1269
+ */
1270
+ authorize(provider: IntegrationProviderId | string, redirectUriOrPath?: string): string;
1271
+ /**
1272
+ * OAuth başlatma URL'ini döner (redirect yapmaz).
1273
+ * Tarayıcıda otomatik yönlendirme için `authorize()` kullanın.
1266
1274
  *
1267
1275
  * @param provider - Provider ID (google-analytics, facebook-business, vb.)
1268
1276
  * @param redirectUri - OAuth tamamlandıktan sonra dönülecek URL (opsiyonel)
1269
1277
  */
1270
1278
  getAuthorizeUrl(provider: IntegrationProviderId | string, redirectUri?: string): string;
1279
+ private resolveRedirectUri;
1271
1280
  /**
1272
1281
  * Bağlantı durumunu sorgular
1273
1282
  */
package/dist/index.d.ts CHANGED
@@ -1253,21 +1253,30 @@ interface IntegrationConnectionStatus {
1253
1253
  * Tüm OAuth akışları backend üzerinden yönetilir - proxy yok.
1254
1254
  *
1255
1255
  * Kullanım:
1256
- * - Bağlantı başlat: window.location.href = sdk.admin.integrations.getAuthorizeUrl('google-analytics', redirectUri)
1256
+ * - Bağlantı başlat: sdk.admin.integrations.authorize('google-analytics', '/admin/analytics')
1257
1257
  * - Durum: sdk.admin.integrations.getStatus('google-analytics')
1258
1258
  * - Bağlantı kes: sdk.admin.integrations.disconnect('google-analytics')
1259
1259
  */
1260
1260
  declare class IntegrationsResource extends BaseResource {
1261
1261
  constructor(httpClient: AxiosInstance);
1262
1262
  /**
1263
- * OAuth başlatma URL'ini döner.
1264
- * Frontend bu URL'e yönlendirir (window.location.href = url).
1265
- * Cookie/Authorization ile backend'e gidilir, backend Google'a redirect eder.
1263
+ * OAuth başlatır: URL üretir ve tarayıcıda yönlendirir.
1264
+ * Kullanıcının URL oluşturup window.location atamasına gerek kalmaz.
1265
+ *
1266
+ * @param provider - Provider ID (google-analytics, facebook-business, vb.)
1267
+ * @param redirectUriOrPath - Tam URL veya path (örn: '/admin/analytics'). Verilmezse mevcut sayfa kullanılır.
1268
+ * @returns Oluşturulan URL (Node.js / Expo gibi ortamlarda manuel kullanım için)
1269
+ */
1270
+ authorize(provider: IntegrationProviderId | string, redirectUriOrPath?: string): string;
1271
+ /**
1272
+ * OAuth başlatma URL'ini döner (redirect yapmaz).
1273
+ * Tarayıcıda otomatik yönlendirme için `authorize()` kullanın.
1266
1274
  *
1267
1275
  * @param provider - Provider ID (google-analytics, facebook-business, vb.)
1268
1276
  * @param redirectUri - OAuth tamamlandıktan sonra dönülecek URL (opsiyonel)
1269
1277
  */
1270
1278
  getAuthorizeUrl(provider: IntegrationProviderId | string, redirectUri?: string): string;
1279
+ private resolveRedirectUri;
1271
1280
  /**
1272
1281
  * Bağlantı durumunu sorgular
1273
1282
  */
package/dist/index.js CHANGED
@@ -1340,9 +1340,24 @@ var IntegrationsResource = class extends BaseResource {
1340
1340
  super(httpClient);
1341
1341
  }
1342
1342
  /**
1343
- * OAuth başlatma URL'ini döner.
1344
- * Frontend bu URL'e yönlendirir (window.location.href = url).
1345
- * Cookie/Authorization ile backend'e gidilir, backend Google'a redirect eder.
1343
+ * OAuth başlatır: URL üretir ve tarayıcıda yönlendirir.
1344
+ * Kullanıcının URL oluşturup window.location atamasına gerek kalmaz.
1345
+ *
1346
+ * @param provider - Provider ID (google-analytics, facebook-business, vb.)
1347
+ * @param redirectUriOrPath - Tam URL veya path (örn: '/admin/analytics'). Verilmezse mevcut sayfa kullanılır.
1348
+ * @returns Oluşturulan URL (Node.js / Expo gibi ortamlarda manuel kullanım için)
1349
+ */
1350
+ authorize(provider, redirectUriOrPath) {
1351
+ const redirectUri = this.resolveRedirectUri(redirectUriOrPath);
1352
+ const url = this.getAuthorizeUrl(provider, redirectUri);
1353
+ if (typeof window !== "undefined") {
1354
+ window.location.href = url;
1355
+ }
1356
+ return url;
1357
+ }
1358
+ /**
1359
+ * OAuth başlatma URL'ini döner (redirect yapmaz).
1360
+ * Tarayıcıda otomatik yönlendirme için `authorize()` kullanın.
1346
1361
  *
1347
1362
  * @param provider - Provider ID (google-analytics, facebook-business, vb.)
1348
1363
  * @param redirectUri - OAuth tamamlandıktan sonra dönülecek URL (opsiyonel)
@@ -1353,6 +1368,21 @@ var IntegrationsResource = class extends BaseResource {
1353
1368
  const params = redirectUri ? `?redirect_uri=${encodeURIComponent(redirectUri)}` : "";
1354
1369
  return `${baseUrl}${path}${params}`;
1355
1370
  }
1371
+ resolveRedirectUri(redirectUriOrPath) {
1372
+ if (redirectUriOrPath) {
1373
+ if (redirectUriOrPath.startsWith("http://") || redirectUriOrPath.startsWith("https://")) {
1374
+ return redirectUriOrPath;
1375
+ }
1376
+ if (typeof window !== "undefined") {
1377
+ const path = redirectUriOrPath.startsWith("/") ? redirectUriOrPath : `/${redirectUriOrPath}`;
1378
+ return `${window.location.origin}${path}`;
1379
+ }
1380
+ }
1381
+ if (typeof window !== "undefined") {
1382
+ return window.location.href;
1383
+ }
1384
+ return void 0;
1385
+ }
1356
1386
  /**
1357
1387
  * Bağlantı durumunu sorgular
1358
1388
  */
package/dist/index.mjs CHANGED
@@ -1277,9 +1277,24 @@ var IntegrationsResource = class extends BaseResource {
1277
1277
  super(httpClient);
1278
1278
  }
1279
1279
  /**
1280
- * OAuth başlatma URL'ini döner.
1281
- * Frontend bu URL'e yönlendirir (window.location.href = url).
1282
- * Cookie/Authorization ile backend'e gidilir, backend Google'a redirect eder.
1280
+ * OAuth başlatır: URL üretir ve tarayıcıda yönlendirir.
1281
+ * Kullanıcının URL oluşturup window.location atamasına gerek kalmaz.
1282
+ *
1283
+ * @param provider - Provider ID (google-analytics, facebook-business, vb.)
1284
+ * @param redirectUriOrPath - Tam URL veya path (örn: '/admin/analytics'). Verilmezse mevcut sayfa kullanılır.
1285
+ * @returns Oluşturulan URL (Node.js / Expo gibi ortamlarda manuel kullanım için)
1286
+ */
1287
+ authorize(provider, redirectUriOrPath) {
1288
+ const redirectUri = this.resolveRedirectUri(redirectUriOrPath);
1289
+ const url = this.getAuthorizeUrl(provider, redirectUri);
1290
+ if (typeof window !== "undefined") {
1291
+ window.location.href = url;
1292
+ }
1293
+ return url;
1294
+ }
1295
+ /**
1296
+ * OAuth başlatma URL'ini döner (redirect yapmaz).
1297
+ * Tarayıcıda otomatik yönlendirme için `authorize()` kullanın.
1283
1298
  *
1284
1299
  * @param provider - Provider ID (google-analytics, facebook-business, vb.)
1285
1300
  * @param redirectUri - OAuth tamamlandıktan sonra dönülecek URL (opsiyonel)
@@ -1290,6 +1305,21 @@ var IntegrationsResource = class extends BaseResource {
1290
1305
  const params = redirectUri ? `?redirect_uri=${encodeURIComponent(redirectUri)}` : "";
1291
1306
  return `${baseUrl}${path}${params}`;
1292
1307
  }
1308
+ resolveRedirectUri(redirectUriOrPath) {
1309
+ if (redirectUriOrPath) {
1310
+ if (redirectUriOrPath.startsWith("http://") || redirectUriOrPath.startsWith("https://")) {
1311
+ return redirectUriOrPath;
1312
+ }
1313
+ if (typeof window !== "undefined") {
1314
+ const path = redirectUriOrPath.startsWith("/") ? redirectUriOrPath : `/${redirectUriOrPath}`;
1315
+ return `${window.location.origin}${path}`;
1316
+ }
1317
+ }
1318
+ if (typeof window !== "undefined") {
1319
+ return window.location.href;
1320
+ }
1321
+ return void 0;
1322
+ }
1293
1323
  /**
1294
1324
  * Bağlantı durumunu sorgular
1295
1325
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salefony/api-sdk",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "Salefony API SDK - Official SDK for Salefony Backend API. Full TypeScript support, SSR-ready, Admin & Frontstore resources.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",