@youversion/platform-core 0.4.2 → 0.4.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.
package/dist/index.cjs CHANGED
@@ -50,18 +50,23 @@ var ApiClient = class {
50
50
  /**
51
51
  * Creates an instance of ApiClient.
52
52
  *
53
- * @param config - The API configuration object containing baseUrl, timeout, and appId.
53
+ * @param config - The API configuration object containing baseUrl, timeout, and appKey.
54
54
  */
55
55
  constructor(config) {
56
56
  this.config = {
57
- version: config.version || "v1",
58
57
  ...config
59
58
  };
60
- this.baseURL = config.baseUrl || "https://api-dev.youversion.com";
59
+ const apiHost = config.apiHost ?? process.env.YVP_API_HOST ?? "api.youversion.com";
60
+ if (!apiHost) {
61
+ throw new Error(
62
+ "ApiClient requires a host name. Provide an apiHost in the config or set the YVP_API_HOST environment variable."
63
+ );
64
+ }
65
+ this.baseURL = "https://" + apiHost;
61
66
  this.timeout = config.timeout || 1e4;
62
67
  this.defaultHeaders = {
63
68
  "Content-Type": "application/json",
64
- "X-YVP-App-Key": this.config.appId,
69
+ "X-YVP-App-Key": this.config.appKey,
65
70
  "X-YVP-Installation-Id": this.config.installationId || "web-sdk-default"
66
71
  };
67
72
  }
@@ -203,9 +208,6 @@ var BibleClient = class {
203
208
  constructor(client) {
204
209
  this.client = client;
205
210
  }
206
- get rootPath() {
207
- return `/${this.client.config.version}`;
208
- }
209
211
  /**
210
212
  * Fetches a collection of Bible versions filtered by language ranges.
211
213
  *
@@ -221,7 +223,7 @@ var BibleClient = class {
221
223
  if (license_id !== void 0) {
222
224
  params.license_id = license_id;
223
225
  }
224
- return this.client.get(`${this.rootPath}/bibles`, params);
226
+ return this.client.get(`/v1/bibles`, params);
225
227
  }
226
228
  /**
227
229
  * Fetches a Bible version by its ID.
@@ -230,7 +232,7 @@ var BibleClient = class {
230
232
  */
231
233
  async getVersion(id) {
232
234
  this.versionIdSchema.parse(id);
233
- return this.client.get(`${this.rootPath}/bibles/${id}`);
235
+ return this.client.get(`/v1/bibles/${id}`);
234
236
  }
235
237
  /**
236
238
  * Fetches all books for a given Bible version.
@@ -240,7 +242,7 @@ var BibleClient = class {
240
242
  */
241
243
  async getBooks(versionId, canon) {
242
244
  this.versionIdSchema.parse(versionId);
243
- return this.client.get(`${this.rootPath}/bibles/${versionId}/books`, {
245
+ return this.client.get(`/v1/bibles/${versionId}/books`, {
244
246
  ...canon && { canon }
245
247
  });
246
248
  }
@@ -253,7 +255,7 @@ var BibleClient = class {
253
255
  async getBook(versionId, book) {
254
256
  this.versionIdSchema.parse(versionId);
255
257
  this.bookSchema.parse(book);
256
- return this.client.get(`${this.rootPath}/bibles/${versionId}/books/${book}`);
258
+ return this.client.get(`/v1/bibles/${versionId}/books/${book}`);
257
259
  }
258
260
  /**
259
261
  * Fetches all chapters for a specific book in a version.
@@ -265,7 +267,7 @@ var BibleClient = class {
265
267
  this.versionIdSchema.parse(versionId);
266
268
  this.bookSchema.parse(book);
267
269
  return this.client.get(
268
- `${this.rootPath}/bibles/${versionId}/books/${book}/chapters`
270
+ `/v1/bibles/${versionId}/books/${book}/chapters`
269
271
  );
270
272
  }
271
273
  /**
@@ -280,7 +282,7 @@ var BibleClient = class {
280
282
  this.bookSchema.parse(book);
281
283
  this.chapterSchema.parse(chapter);
282
284
  return this.client.get(
283
- `${this.rootPath}/bibles/${versionId}/books/${book}/chapters/${chapter}`
285
+ `/v1/bibles/${versionId}/books/${book}/chapters/${chapter}`
284
286
  );
285
287
  }
286
288
  /**
@@ -295,7 +297,7 @@ var BibleClient = class {
295
297
  this.bookSchema.parse(book);
296
298
  this.chapterSchema.parse(chapter);
297
299
  return this.client.get(
298
- `${this.rootPath}/bibles/${versionId}/books/${book}/chapters/${chapter}/verses`
300
+ `/v1/bibles/${versionId}/books/${book}/chapters/${chapter}/verses`
299
301
  );
300
302
  }
301
303
  /**
@@ -312,7 +314,7 @@ var BibleClient = class {
312
314
  this.chapterSchema.parse(chapter);
313
315
  this.verseSchema.parse(verse);
314
316
  return this.client.get(
315
- `${this.rootPath}/bibles/${versionId}/books/${book}/chapters/${chapter}/verses/${verse}`
317
+ `/v1/bibles/${versionId}/books/${book}/chapters/${chapter}/verses/${verse}`
316
318
  );
317
319
  }
318
320
  /**
@@ -353,10 +355,7 @@ var BibleClient = class {
353
355
  if (include_notes !== void 0) {
354
356
  params.include_notes = include_notes;
355
357
  }
356
- return this.client.get(
357
- `${this.rootPath}/bibles/${versionId}/passages/${usfm}`,
358
- params
359
- );
358
+ return this.client.get(`/v1/bibles/${versionId}/passages/${usfm}`, params);
360
359
  }
361
360
  /**
362
361
  * Fetches the indexing structure for a Bible version.
@@ -365,14 +364,14 @@ var BibleClient = class {
365
364
  */
366
365
  async getIndex(versionId) {
367
366
  this.versionIdSchema.parse(versionId);
368
- return this.client.get(`${this.rootPath}/bibles/${versionId}/index`);
367
+ return this.client.get(`/v1/bibles/${versionId}/index`);
369
368
  }
370
369
  /**
371
370
  * Fetches the verse of the day calendar for an entire year.
372
371
  * @returns A collection of VOTD objects for all days of the year.
373
372
  */
374
373
  async getAllVOTDs() {
375
- return this.client.get(`${this.rootPath}/verse_of_the_days`);
374
+ return this.client.get(`/v1/verse_of_the_days`);
376
375
  }
377
376
  /**
378
377
  * Fetches the passage_id for the Verse Of The Day.
@@ -390,7 +389,7 @@ var BibleClient = class {
390
389
  async getVOTD(day) {
391
390
  const daySchema = import_zod.z.number().int().min(1).max(366);
392
391
  daySchema.parse(day);
393
- return this.client.get(`${this.rootPath}/verse_of_the_days/${day}`);
392
+ return this.client.get(`/v1/verse_of_the_days/${day}`);
394
393
  }
395
394
  };
396
395
 
@@ -410,9 +409,6 @@ var LanguagesClient = class {
410
409
  constructor(client) {
411
410
  this.client = client;
412
411
  }
413
- get rootPath() {
414
- return `/${this.client.config.version}`;
415
- }
416
412
  /**
417
413
  * Fetches a collection of languages supported in the Platform.
418
414
  * @param options Query parameters for pagination and filtering (country is required).
@@ -430,7 +426,7 @@ var LanguagesClient = class {
430
426
  if (options.page_token !== void 0) {
431
427
  params.page_token = options.page_token;
432
428
  }
433
- return this.client.get(`${this.rootPath}/languages`, params);
429
+ return this.client.get(`/v1/languages`, params);
434
430
  }
435
431
  /**
436
432
  * Fetches details about a specific language in the Platform.
@@ -439,7 +435,7 @@ var LanguagesClient = class {
439
435
  */
440
436
  async getLanguage(languageId) {
441
437
  this.languageIdSchema.parse(languageId);
442
- return this.client.get(`${this.rootPath}/languages/${languageId}`);
438
+ return this.client.get(`/v1/languages/${languageId}`);
443
439
  }
444
440
  };
445
441
 
@@ -448,10 +444,10 @@ var import_zod3 = require("zod");
448
444
 
449
445
  // src/YouVersionPlatformConfiguration.ts
450
446
  var YouVersionPlatformConfiguration = class {
451
- static _appId = null;
447
+ static _appKey = null;
452
448
  static _installationId = null;
453
449
  static _accessToken = null;
454
- static _apiHost = "api-dev.youversion.com";
450
+ static _apiHost = "api.youversion.com";
455
451
  static _isPreviewMode = false;
456
452
  static _previewUserInfo = null;
457
453
  static getOrSetInstallationId() {
@@ -466,11 +462,11 @@ var YouVersionPlatformConfiguration = class {
466
462
  localStorage.setItem("x-yvp-installation-id", newId);
467
463
  return newId;
468
464
  }
469
- static get appId() {
470
- return this._appId;
465
+ static get appKey() {
466
+ return this._appKey;
471
467
  }
472
- static set appId(value) {
473
- this._appId = value;
468
+ static set appKey(value) {
469
+ this._appKey = value;
474
470
  }
475
471
  static get installationId() {
476
472
  if (!this._installationId) {
@@ -523,9 +519,6 @@ var HighlightsClient = class {
523
519
  constructor(client) {
524
520
  this.client = client;
525
521
  }
526
- get rootPath() {
527
- return `/${this.client.config.version}`;
528
- }
529
522
  /**
530
523
  * Gets the authentication token, either from the provided parameter or from the platform configuration.
531
524
  * @param lat Optional explicit long access token. If not provided, retrieves from YouVersionPlatformConfiguration.
@@ -595,7 +588,7 @@ var HighlightsClient = class {
595
588
  this.validatePassageId(options.passage_id);
596
589
  params.passage_id = options.passage_id;
597
590
  }
598
- return this.client.get(`${this.rootPath}/highlights`, params);
591
+ return this.client.get(`/v1/highlights`, params);
599
592
  }
600
593
  /**
601
594
  * Creates or updates a highlight on a passage.
@@ -610,7 +603,7 @@ var HighlightsClient = class {
610
603
  this.validatePassageId(data.passage_id);
611
604
  this.validateColor(data.color);
612
605
  const token = this.getAuthToken(lat);
613
- return this.client.post(`${this.rootPath}/highlights`, data, { lat: token });
606
+ return this.client.post(`/v1/highlights`, data, { lat: token });
614
607
  }
615
608
  /**
616
609
  * Clears highlights for a passage.
@@ -630,7 +623,7 @@ var HighlightsClient = class {
630
623
  this.validateVersionId(options.version_id);
631
624
  params.version_id = options.version_id;
632
625
  }
633
- await this.client.delete(`${this.rootPath}/highlights/${passageId}`, params);
626
+ await this.client.delete(`/v1/highlights/${passageId}`, params);
634
627
  }
635
628
  };
636
629
 
@@ -928,13 +921,13 @@ var YouVersionAPI = class {
928
921
  Accept: "application/json",
929
922
  "Content-Type": "application/json"
930
923
  };
931
- const appId = YouVersionPlatformConfiguration.appId;
932
- if (appId) {
933
- headers["X-App-Id"] = appId;
924
+ const appKey = YouVersionPlatformConfiguration.appKey;
925
+ if (appKey) {
926
+ headers["X-YVP-App-Key"] = appKey;
934
927
  }
935
928
  const installationId = YouVersionPlatformConfiguration.installationId;
936
929
  if (installationId) {
937
- headers["x-yvp-installation-id"] = installationId;
930
+ headers["X-YVP-Installation-ID"] = installationId;
938
931
  }
939
932
  const request = new Request(url.toString(), {
940
933
  headers
@@ -948,15 +941,15 @@ var URLBuilder = class {
948
941
  static get baseURL() {
949
942
  return new URL(`https://${YouVersionPlatformConfiguration.apiHost}`);
950
943
  }
951
- static authURL(appId, requiredPermissions = /* @__PURE__ */ new Set(), optionalPermissions = /* @__PURE__ */ new Set()) {
952
- if (typeof appId !== "string" || appId.trim().length === 0) {
953
- throw new Error("appId must be a non-empty string");
944
+ static authURL(appKey, requiredPermissions = /* @__PURE__ */ new Set(), optionalPermissions = /* @__PURE__ */ new Set()) {
945
+ if (typeof appKey !== "string" || appKey.trim().length === 0) {
946
+ throw new Error("appKey must be a non-empty string");
954
947
  }
955
948
  try {
956
949
  const url = new URL(this.baseURL);
957
950
  url.pathname = "/auth/login";
958
951
  const searchParams = new URLSearchParams();
959
- searchParams.append("app_id", appId);
952
+ searchParams.append("APP_KEY", appKey);
960
953
  searchParams.append("language", "en");
961
954
  if (requiredPermissions.size > 0) {
962
955
  const requiredList = Array.from(requiredPermissions).map((p) => p.toString());
@@ -1020,11 +1013,11 @@ var YouVersionAPIUsers = class {
1020
1013
  if (!optionalPermissions || !(optionalPermissions instanceof Set)) {
1021
1014
  throw new Error("Invalid optionalPermissions: must be a Set");
1022
1015
  }
1023
- const appId = YouVersionPlatformConfiguration.appId;
1024
- if (!appId) {
1025
- throw new Error("YouVersionPlatformConfiguration.appId must be set before calling signIn");
1016
+ const appKey = YouVersionPlatformConfiguration.appKey;
1017
+ if (!appKey) {
1018
+ throw new Error("YouVersionPlatformConfiguration.appKey must be set before calling signIn");
1026
1019
  }
1027
- const url = URLBuilder.authURL(appId, requiredPermissions, optionalPermissions);
1020
+ const url = URLBuilder.authURL(appKey, requiredPermissions, optionalPermissions);
1028
1021
  const strategy = AuthenticationStrategyRegistry.get();
1029
1022
  const callbackUrl = await strategy.authenticate(url);
1030
1023
  const result = new SignInWithYouVersionResult(callbackUrl);
package/dist/index.d.cts CHANGED
@@ -179,11 +179,9 @@ type Collection<T> = {
179
179
  };
180
180
 
181
181
  interface ApiConfig {
182
- baseUrl?: string;
183
- appId: string;
182
+ apiHost?: string;
183
+ appKey: string;
184
184
  timeout?: number;
185
- hostEnv?: string;
186
- version?: string;
187
185
  installationId?: string;
188
186
  redirectUri?: string;
189
187
  }
@@ -237,7 +235,7 @@ declare class ApiClient {
237
235
  /**
238
236
  * Creates an instance of ApiClient.
239
237
  *
240
- * @param config - The API configuration object containing baseUrl, timeout, and appId.
238
+ * @param config - The API configuration object containing baseUrl, timeout, and appKey.
241
239
  */
242
240
  constructor(config: ApiConfig);
243
241
  /**
@@ -294,7 +292,6 @@ declare class BibleClient {
294
292
  * @param client The API client to use for requests.
295
293
  */
296
294
  constructor(client: ApiClient);
297
- private get rootPath();
298
295
  /**
299
296
  * Fetches a collection of Bible versions filtered by language ranges.
300
297
  *
@@ -424,7 +421,6 @@ declare class LanguagesClient {
424
421
  * @param client The API client to use for requests.
425
422
  */
426
423
  constructor(client: ApiClient);
427
- private get rootPath();
428
424
  /**
429
425
  * Fetches a collection of languages supported in the Platform.
430
426
  * @param options Query parameters for pagination and filtering (country is required).
@@ -466,7 +462,6 @@ declare class HighlightsClient {
466
462
  * @param client The API client to use for requests.
467
463
  */
468
464
  constructor(client: ApiClient);
469
- private get rootPath();
470
465
  /**
471
466
  * Gets the authentication token, either from the provided parameter or from the platform configuration.
472
467
  * @param lat Optional explicit long access token. If not provided, retrieves from YouVersionPlatformConfiguration.
@@ -701,20 +696,20 @@ declare class YouVersionAPI {
701
696
 
702
697
  declare class URLBuilder {
703
698
  private static get baseURL();
704
- static authURL(appId: string, requiredPermissions?: Set<SignInWithYouVersionPermissionValues>, optionalPermissions?: Set<SignInWithYouVersionPermissionValues>): URL;
699
+ static authURL(appKey: string, requiredPermissions?: Set<SignInWithYouVersionPermissionValues>, optionalPermissions?: Set<SignInWithYouVersionPermissionValues>): URL;
705
700
  static userURL(accessToken: string): URL;
706
701
  }
707
702
 
708
703
  declare class YouVersionPlatformConfiguration {
709
- private static _appId;
704
+ private static _appKey;
710
705
  private static _installationId;
711
706
  private static _accessToken;
712
707
  private static _apiHost;
713
708
  private static _isPreviewMode;
714
709
  private static _previewUserInfo;
715
710
  private static getOrSetInstallationId;
716
- static get appId(): string | null;
717
- static set appId(value: string | null);
711
+ static get appKey(): string | null;
712
+ static set appKey(value: string | null);
718
713
  static get installationId(): string;
719
714
  static set installationId(value: string | null);
720
715
  static setAccessToken(token: string | null): void;
package/dist/index.d.ts CHANGED
@@ -179,11 +179,9 @@ type Collection<T> = {
179
179
  };
180
180
 
181
181
  interface ApiConfig {
182
- baseUrl?: string;
183
- appId: string;
182
+ apiHost?: string;
183
+ appKey: string;
184
184
  timeout?: number;
185
- hostEnv?: string;
186
- version?: string;
187
185
  installationId?: string;
188
186
  redirectUri?: string;
189
187
  }
@@ -237,7 +235,7 @@ declare class ApiClient {
237
235
  /**
238
236
  * Creates an instance of ApiClient.
239
237
  *
240
- * @param config - The API configuration object containing baseUrl, timeout, and appId.
238
+ * @param config - The API configuration object containing baseUrl, timeout, and appKey.
241
239
  */
242
240
  constructor(config: ApiConfig);
243
241
  /**
@@ -294,7 +292,6 @@ declare class BibleClient {
294
292
  * @param client The API client to use for requests.
295
293
  */
296
294
  constructor(client: ApiClient);
297
- private get rootPath();
298
295
  /**
299
296
  * Fetches a collection of Bible versions filtered by language ranges.
300
297
  *
@@ -424,7 +421,6 @@ declare class LanguagesClient {
424
421
  * @param client The API client to use for requests.
425
422
  */
426
423
  constructor(client: ApiClient);
427
- private get rootPath();
428
424
  /**
429
425
  * Fetches a collection of languages supported in the Platform.
430
426
  * @param options Query parameters for pagination and filtering (country is required).
@@ -466,7 +462,6 @@ declare class HighlightsClient {
466
462
  * @param client The API client to use for requests.
467
463
  */
468
464
  constructor(client: ApiClient);
469
- private get rootPath();
470
465
  /**
471
466
  * Gets the authentication token, either from the provided parameter or from the platform configuration.
472
467
  * @param lat Optional explicit long access token. If not provided, retrieves from YouVersionPlatformConfiguration.
@@ -701,20 +696,20 @@ declare class YouVersionAPI {
701
696
 
702
697
  declare class URLBuilder {
703
698
  private static get baseURL();
704
- static authURL(appId: string, requiredPermissions?: Set<SignInWithYouVersionPermissionValues>, optionalPermissions?: Set<SignInWithYouVersionPermissionValues>): URL;
699
+ static authURL(appKey: string, requiredPermissions?: Set<SignInWithYouVersionPermissionValues>, optionalPermissions?: Set<SignInWithYouVersionPermissionValues>): URL;
705
700
  static userURL(accessToken: string): URL;
706
701
  }
707
702
 
708
703
  declare class YouVersionPlatformConfiguration {
709
- private static _appId;
704
+ private static _appKey;
710
705
  private static _installationId;
711
706
  private static _accessToken;
712
707
  private static _apiHost;
713
708
  private static _isPreviewMode;
714
709
  private static _previewUserInfo;
715
710
  private static getOrSetInstallationId;
716
- static get appId(): string | null;
717
- static set appId(value: string | null);
711
+ static get appKey(): string | null;
712
+ static set appKey(value: string | null);
718
713
  static get installationId(): string;
719
714
  static set installationId(value: string | null);
720
715
  static setAccessToken(token: string | null): void;