@rechargeapps/storefront-client 0.0.14

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.
Files changed (41) hide show
  1. package/README.md +47 -0
  2. package/dist/cjs/api/bundle.js +100 -0
  3. package/dist/cjs/api/bundle.js.map +1 -0
  4. package/dist/cjs/api/cdn.js +109 -0
  5. package/dist/cjs/api/cdn.js.map +1 -0
  6. package/dist/cjs/constants/api.js +8 -0
  7. package/dist/cjs/constants/api.js.map +1 -0
  8. package/dist/cjs/index.js +23 -0
  9. package/dist/cjs/index.js.map +1 -0
  10. package/dist/cjs/mappers/cdn.js +67 -0
  11. package/dist/cjs/mappers/cdn.js.map +1 -0
  12. package/dist/cjs/mappers/utils.js +38 -0
  13. package/dist/cjs/mappers/utils.js.map +1 -0
  14. package/dist/cjs/utils/init.js +33 -0
  15. package/dist/cjs/utils/init.js.map +1 -0
  16. package/dist/cjs/utils/options.js +18 -0
  17. package/dist/cjs/utils/options.js.map +1 -0
  18. package/dist/cjs/utils/request.js +95 -0
  19. package/dist/cjs/utils/request.js.map +1 -0
  20. package/dist/esm/api/bundle.js +95 -0
  21. package/dist/esm/api/bundle.js.map +1 -0
  22. package/dist/esm/api/cdn.js +98 -0
  23. package/dist/esm/api/cdn.js.map +1 -0
  24. package/dist/esm/constants/api.js +4 -0
  25. package/dist/esm/constants/api.js.map +1 -0
  26. package/dist/esm/index.js +4 -0
  27. package/dist/esm/index.js.map +1 -0
  28. package/dist/esm/mappers/cdn.js +57 -0
  29. package/dist/esm/mappers/cdn.js.map +1 -0
  30. package/dist/esm/mappers/utils.js +34 -0
  31. package/dist/esm/mappers/utils.js.map +1 -0
  32. package/dist/esm/utils/init.js +28 -0
  33. package/dist/esm/utils/init.js.map +1 -0
  34. package/dist/esm/utils/options.js +13 -0
  35. package/dist/esm/utils/options.js.map +1 -0
  36. package/dist/esm/utils/request.js +86 -0
  37. package/dist/esm/utils/request.js.map +1 -0
  38. package/dist/index.d.ts +419 -0
  39. package/dist/umd/recharge-storefront-client.min.js +24 -0
  40. package/dist/umd/recharge-storefront-client.min.js.map +1 -0
  41. package/package.json +66 -0
@@ -0,0 +1,419 @@
1
+ declare type Method = 'get' | 'post' | 'put' | 'delete';
2
+ declare type Request = <T>(method: Method, url: string, options?: RequestOptions) => Promise<T>;
3
+ interface GetRequestOptions {
4
+ id?: string;
5
+ query?: unknown;
6
+ }
7
+ interface CRUDRequestOptions {
8
+ id?: string;
9
+ data?: unknown;
10
+ }
11
+ /** Custom headers we use within our storefront client */
12
+ interface CustomHeaders {
13
+ ['X-Recharge-App']?: 'storefront-client';
14
+ }
15
+ /** We only support headers with an object syntax */
16
+ declare type RequestHeaders = Record<string, string> & CustomHeaders;
17
+ interface RequestOptionsHeaders {
18
+ headers?: RequestHeaders;
19
+ }
20
+ declare type RequestOptions = GetRequestOptions & CRUDRequestOptions & RequestOptionsHeaders;
21
+
22
+ interface BundleSelection {
23
+ collectionId: string;
24
+ externalProductId: string;
25
+ externalVariantId: string;
26
+ quantity: number;
27
+ }
28
+ interface Bundle {
29
+ externalVariantId: string;
30
+ externalProductId: string;
31
+ selections: BundleSelection[];
32
+ }
33
+
34
+ /** HEXA, RGBA, HSLA */
35
+ declare type ColorString = string;
36
+ /** HTML String */
37
+ declare type HTMLString = string;
38
+ /** ISO 8601 date time */
39
+ declare type IsoDateString = string;
40
+
41
+ declare type FirstOption = 'onetime' | 'autodeliver';
42
+ declare type IntervalUnit = 'day' | 'week' | 'month';
43
+ declare type PriceAdjustmentsType = 'percentage';
44
+ declare type StorefrontPurchaseOption = 'subscription_and_onetime' | 'subscription_only' | 'onetime_only' | 'inactive';
45
+ interface BundleTranslations {
46
+ cpb_add: string;
47
+ cpb_add_items_to_continue: string;
48
+ cpb_add_more_items: string;
49
+ cpb_apply_filters: string;
50
+ cpb_cancel: string;
51
+ cpb_clear_all_filters: string;
52
+ cpb_contents_for: string;
53
+ cpb_day: string;
54
+ cpb_filters: string;
55
+ cpb_frequency: string;
56
+ cpb_frequency_values: string;
57
+ cpb_items_selected: string;
58
+ cpb_items_selected_filters: string;
59
+ cpb_month: string;
60
+ cpb_remove: string;
61
+ cpb_remove_items_to_continue: string;
62
+ cpb_remove_some_items: string;
63
+ cpb_save_button_text: string;
64
+ cpb_saved_message: string;
65
+ cpb_saving_message: string;
66
+ cpb_select_bundle_contents: string;
67
+ cpb_select_your_contents_to_continue_message_modal: string;
68
+ cpb_select_your_contents_to_continue_title_modal: string;
69
+ cpb_selection_count_alert: string;
70
+ cpb_update_bundle_contents: string;
71
+ cpb_week: string;
72
+ cpb_your: string;
73
+ cpb_your_next_order: string;
74
+ pdp_add: string;
75
+ pdp_add_items_to_continue: string;
76
+ 'pdp_add_one-off_extras': string;
77
+ 'pdp_add_one-off_extras_description': string;
78
+ 'pdp_add_repeating_add-ons': string;
79
+ 'pdp_add_repeating_add-ons_description': string;
80
+ pdp_add_to_cart: string;
81
+ pdp_add_to_cart_alert: string;
82
+ pdp_add_to_cart_extras: string;
83
+ pdp_add_to_cart_failed: string;
84
+ pdp_apply_filters: string;
85
+ pdp_back: string;
86
+ pdp_bundle_contents: string;
87
+ pdp_cancel: string;
88
+ pdp_choose_items: string;
89
+ pdp_choose_items_alert: string;
90
+ pdp_choose_maximum: string;
91
+ pdp_choose_range: string;
92
+ pdp_clear_all_filters: string;
93
+ pdp_day: string;
94
+ pdp_filters: string;
95
+ pdp_frequency: string;
96
+ pdp_frequency_value: string;
97
+ pdp_items_selected: string;
98
+ pdp_items_selected_filters: string;
99
+ pdp_max_per_item_reached_alert: string;
100
+ pdp_month: string;
101
+ pdp_next: string;
102
+ 'pdp_one-off_extras': string;
103
+ pdp_only_once: string;
104
+ pdp_order_summary: string;
105
+ pdp_plan_changed_alert: string;
106
+ pdp_proceed_to_cart: string;
107
+ pdp_product_added: string;
108
+ pdp_regular_delivery: string;
109
+ pdp_remove: string;
110
+ pdp_remove_items_alert: string;
111
+ pdp_remove_items_to_continue: string;
112
+ 'pdp_repeating_add-ons': string;
113
+ pdp_selection_completed_alert: string;
114
+ pdp_selection_count_alert: string;
115
+ pdp_sold_out: string;
116
+ pdp_subscribe: string;
117
+ pdp_total: string;
118
+ pdp_update_your_selections_to_continue: string;
119
+ pdp_week: string;
120
+ }
121
+ interface Translations {
122
+ days: string;
123
+ week: string;
124
+ weeks: string;
125
+ month: string;
126
+ months: string;
127
+ }
128
+ declare type WidgetTemplateType = 'radio' | 'checkbox' | 'button_group' | 'radio_group';
129
+ declare type WidgetIconColor = '#191D48' | 'white' | 'black' | '#ffffff';
130
+ /****************** 2020-12 **********************/
131
+ interface CDNProductResource {
132
+ product: CDNProductRaw;
133
+ meta: {
134
+ version: '2020-12';
135
+ };
136
+ }
137
+ interface CDNProductKeyObject {
138
+ [key: string]: CDNProduct;
139
+ }
140
+ interface CDNProductsAndSettingsResource {
141
+ products: {
142
+ [key: string]: CDNProductRaw;
143
+ }[];
144
+ widget_settings: CDNWidgetSettingsRaw;
145
+ store_settings: CDNStoreSettings;
146
+ meta?: {
147
+ status: string;
148
+ message: string;
149
+ };
150
+ }
151
+ interface CDNSellingPlan {
152
+ order_interval_frequency: string | number;
153
+ created_at?: IsoDateString;
154
+ order_interval_unit_type: IntervalUnit;
155
+ updated_at?: IsoDateString;
156
+ id: number;
157
+ selling_plan_id: number;
158
+ selling_plan_name: string;
159
+ price_adjustments_value_type: PriceAdjustmentsType;
160
+ price_adjustments_value: number;
161
+ }
162
+ interface CDNSellingPlanGroup {
163
+ selling_plan_group_id: string | number;
164
+ selling_plans: CDNSellingPlan[];
165
+ subscription_product_id: number;
166
+ }
167
+ interface CDNSubscriptionOption {
168
+ storefront_purchase_options: StorefrontPurchaseOption;
169
+ updated_at: IsoDateString;
170
+ is_prepaid?: boolean;
171
+ }
172
+ interface CDNSellingPlanAllocations {
173
+ selling_plan_group_id: string | number;
174
+ selling_plan_id: number;
175
+ discounted_price: string;
176
+ }
177
+ interface CDNPrices {
178
+ compare_at_price: string | null;
179
+ unit_price: string;
180
+ discounted_price: string;
181
+ zero_decimal_currency: boolean;
182
+ }
183
+ interface CDNVariantOptionValue {
184
+ id: number;
185
+ label: string;
186
+ }
187
+ interface CDNVariant {
188
+ id: number;
189
+ option_values: CDNVariantOptionValue[];
190
+ prices: CDNPrices;
191
+ selling_plan_allocations: CDNSellingPlanAllocations[];
192
+ }
193
+ interface CDNProductOptionValue {
194
+ id?: number | null;
195
+ label: string;
196
+ position: number;
197
+ }
198
+ interface CDNProductOption {
199
+ id: number;
200
+ name: string;
201
+ position: number;
202
+ values: CDNProductOptionValue[];
203
+ }
204
+ interface CDNProductRaw {
205
+ id: number | null;
206
+ bundle_product?: CDNBundleSettings | null;
207
+ external_product_id: number;
208
+ in_recharge: boolean;
209
+ options: CDNProductOption[];
210
+ variants: CDNVariant[];
211
+ subscription_options: CDNSubscriptionOption;
212
+ selling_plan_groups: CDNSellingPlanGroup[];
213
+ }
214
+ interface CDNProduct extends CDNProductRaw {
215
+ /** @deprecated */
216
+ isSubscriptionOnly: boolean;
217
+ is_subscription_only: boolean;
218
+ }
219
+ interface CDNProductAndSettings {
220
+ product: CDNProduct;
221
+ widget_settings: CDNWidgetSettings;
222
+ store_settings: CDNStoreSettings;
223
+ /** @deprecated */
224
+ widgetSettings: CDNWidgetSettings;
225
+ /** @deprecated */
226
+ storeSettings: CDNStoreSettings;
227
+ }
228
+ interface CDNProductsAndSettings {
229
+ products: CDNProductKeyObject[];
230
+ widget_settings: CDNWidgetSettings;
231
+ store_settings: CDNStoreSettings;
232
+ }
233
+ interface CDNBaseWidgetSettings {
234
+ active_color: ColorString;
235
+ auto_inject?: boolean;
236
+ background_color: ColorString;
237
+ bundle_translations?: BundleTranslations;
238
+ delivery_dropdown_label: string;
239
+ display_on: string[];
240
+ first_option: FirstOption;
241
+ font_color: ColorString;
242
+ form_type: string;
243
+ how_it_works: HTMLString;
244
+ learnmore_url: string;
245
+ learnmore_verbiage: string;
246
+ onetime_message: string;
247
+ popup_background_color: ColorString;
248
+ popup_link_color: ColorString;
249
+ popup_text_color: ColorString;
250
+ poweredby_url: string;
251
+ published: boolean;
252
+ select_subscription_first: boolean;
253
+ show_learnmore: boolean;
254
+ show_poweredby: boolean;
255
+ show_subscription_details: boolean;
256
+ show_subscription_details_icon: boolean;
257
+ sub_and_save_ext_label: string;
258
+ subscribe_message: string;
259
+ subscribe_without_discount_message: string;
260
+ subscription_details_verbiage: string;
261
+ translations: Translations;
262
+ widget_charge_every: string;
263
+ widget_deliver_every: string;
264
+ widget_icon: WidgetIconColor;
265
+ widget_template_type: WidgetTemplateType;
266
+ }
267
+ declare type CDNExcludedWidgetSettings = 'display_on' | 'first_option';
268
+ interface CDNWidgetSettings extends Omit<CDNBaseWidgetSettings, CDNExcludedWidgetSettings> {
269
+ /** @deprecated */
270
+ autoInject: boolean;
271
+ /** @deprecated */
272
+ validPages: string[];
273
+ /** @deprecated */
274
+ isSubscriptionFirst: boolean;
275
+ auto_inject: boolean;
276
+ valid_pages: string[];
277
+ is_subscription_first: boolean;
278
+ }
279
+ declare type CDNWidgetSettingsRaw = {
280
+ [key in keyof CDNBaseWidgetSettings]: string;
281
+ };
282
+ interface CDNWidgetSettingsResource {
283
+ widget_settings: CDNWidgetSettingsRaw;
284
+ meta: {
285
+ version: string;
286
+ };
287
+ }
288
+ interface CDNStoreSettings {
289
+ store_currency: {
290
+ currency_code: string;
291
+ currency_symbol: string;
292
+ decimal_separator: string;
293
+ thousands_separator: string;
294
+ currency_symbol_location: string;
295
+ zero_decimal_currency?: boolean;
296
+ };
297
+ }
298
+ /****************** 2021-08 **********************/
299
+ /**************** Bundles ****************/
300
+ interface CDNBundleStepOption {
301
+ content: string;
302
+ defaultImage: string;
303
+ }
304
+ interface CDNBundleStep {
305
+ data?: {
306
+ optionsMeta: {
307
+ [key: string]: CDNBundleStepOption;
308
+ };
309
+ };
310
+ disable: boolean;
311
+ index: string;
312
+ name: string;
313
+ title: string;
314
+ type: 'variantSelector' | 'all-collections' | 'addons' | 'summary' | 'cross-sells';
315
+ }
316
+ interface CDNBundleLayoutSettings {
317
+ addToCartCallback: {
318
+ type: 'none';
319
+ value: string;
320
+ };
321
+ addons: {
322
+ collectionHandle: string;
323
+ collectionId: string;
324
+ enabled: boolean;
325
+ };
326
+ collapsibleSections: boolean;
327
+ crossSells: {
328
+ collectionId: string;
329
+ enabled: boolean;
330
+ collectionHandle: string;
331
+ };
332
+ defaultFrequency: string;
333
+ defaultVariantId: string;
334
+ description: string;
335
+ filters: any[];
336
+ learnMoreModal: boolean;
337
+ published: boolean;
338
+ showVariants: boolean;
339
+ template: 'one-page' | 'multi-step';
340
+ templateSettings: {
341
+ onePage: {
342
+ frequencySelector: 'dropdown';
343
+ };
344
+ multiStep?: {
345
+ steps: CDNBundleStep[];
346
+ optionImages: string;
347
+ };
348
+ };
349
+ title: string;
350
+ visibility: {
351
+ portal: boolean;
352
+ signup: boolean;
353
+ };
354
+ }
355
+ interface CDNBundleVariantOptionSource {
356
+ id: number;
357
+ collection_id: string;
358
+ quantity_max: number | null;
359
+ quantity_min: number | null;
360
+ }
361
+ interface CDNBundleVariantSelectionDefault {
362
+ id: number;
363
+ quantity: number;
364
+ external_variant_id: string;
365
+ }
366
+ interface CDNBundleVariant {
367
+ enabled: boolean;
368
+ external_variant_id: string;
369
+ id: number;
370
+ items_count: number;
371
+ option_sources: CDNBundleVariantOptionSource[];
372
+ selection_defaults?: CDNBundleVariantSelectionDefault[];
373
+ }
374
+ interface CDNBundleSettings {
375
+ customization_window_disabled_message: string | null;
376
+ customization_window?: number;
377
+ default_bundle_variant_id?: number;
378
+ description: string | null;
379
+ external_product_id: string;
380
+ id: number;
381
+ is_customizable?: boolean;
382
+ layout_settings: CDNBundleLayoutSettings;
383
+ layout_settings_version: '2021-11';
384
+ max_quantity_per_variant: number | null;
385
+ reset_box_contents?: boolean;
386
+ variants: CDNBundleVariant[];
387
+ }
388
+
389
+ declare type StorefrontEnvironment = 'stage' | 'prod';
390
+ interface StorefrontOptions {
391
+ storeIdentifier: string;
392
+ environment: StorefrontEnvironment;
393
+ }
394
+
395
+ declare const getProduct: (externalProductId: string | number) => Promise<CDNProduct>;
396
+ declare const getStoreSettings: () => Promise<CDNStoreSettings>;
397
+ declare const getWidgetSettings: () => Promise<CDNWidgetSettings>;
398
+ declare const getProductsAndSettings: () => Promise<CDNProductsAndSettings>;
399
+ declare const getProducts: () => Promise<CDNProductKeyObject[]>;
400
+ declare const getProductAndSettings: (externalProductId: string | number) => Promise<CDNProductAndSettings>;
401
+ declare const getBundleSettings: (externalProductId: string | number) => Promise<CDNBundleSettings | null | undefined>;
402
+ declare const resetCache: () => void;
403
+
404
+ declare const getBundleId: (bundle: Bundle) => Promise<string>;
405
+ declare const validateBundle: (bundle: Bundle) => Promise<boolean>;
406
+
407
+ interface InitOptions extends Omit<StorefrontOptions, 'environment'> {
408
+ /** This is only for internal use. Sets the environment where data is fetched from. */
409
+ environment?: StorefrontOptions['environment'];
410
+ }
411
+ declare const api: {
412
+ get<T>(url: string, requestOptions?: GetRequestOptions): Promise<T>;
413
+ post<T_1>(url: string, requestOptions?: CRUDRequestOptions): Promise<T_1>;
414
+ put<T_2>(url: string, requestOptions?: CRUDRequestOptions): Promise<T_2>;
415
+ delete<T_3>(url: string, requestOptions?: CRUDRequestOptions): Promise<T_3>;
416
+ };
417
+ declare function initRecharge(opt: InitOptions): void;
418
+
419
+ export { Bundle, BundleSelection, BundleTranslations, CDNBaseWidgetSettings, CDNBundleLayoutSettings, CDNBundleSettings, CDNBundleStep, CDNBundleStepOption, CDNBundleVariant, CDNBundleVariantOptionSource, CDNBundleVariantSelectionDefault, CDNPrices, CDNProduct, CDNProductAndSettings, CDNProductKeyObject, CDNProductOption, CDNProductOptionValue, CDNProductRaw, CDNProductResource, CDNProductsAndSettings, CDNProductsAndSettingsResource, CDNSellingPlan, CDNSellingPlanAllocations, CDNSellingPlanGroup, CDNStoreSettings, CDNSubscriptionOption, CDNVariant, CDNVariantOptionValue, CDNWidgetSettings, CDNWidgetSettingsRaw, CDNWidgetSettingsResource, CRUDRequestOptions, FirstOption, GetRequestOptions, InitOptions, IntervalUnit, Method, PriceAdjustmentsType, Request, RequestHeaders, RequestOptions, RequestOptionsHeaders, StorefrontEnvironment, StorefrontOptions, StorefrontPurchaseOption, Translations, WidgetIconColor, WidgetTemplateType, api, getBundleId, getBundleSettings, getProduct, getProductAndSettings, getProducts, getProductsAndSettings, getStoreSettings, getWidgetSettings, initRecharge, resetCache, validateBundle };