picnic-api-fix 3.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 MRVDH
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,68 @@
1
+ # Picnic-API
2
+
3
+ [![npm version](https://img.shields.io/npm/v/picnic-api.svg?style=flat-square)](https://www.npmjs.org/package/picnic-api) [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](https://github.com/MRVDH/picnic-api/blob/master/LICENSE) [![Buy me an Affligem blond](https://img.shields.io/badge/buy%20me%20an-affligem%20blond-orange?style=flat-square)](https://www.buymeacoffee.com/MRVDH) [![MAAR3267](https://img.shields.io/badge/picnic%20discount-MAAR3267-E1171E?style=flat-square)](https://picnic.app/nl/vriendenkorting/MAAR3267)
4
+
5
+ Unofficial and unaffiliated Node.js npm package as a wrapper for the API of the online supermarket Picnic.
6
+
7
+ ## Getting started
8
+
9
+ Using `npm`:
10
+
11
+ ```bash
12
+ npm install picnic-api
13
+ ```
14
+
15
+ Then import the package into your project. `PicnicClient` is the default export.
16
+
17
+ ```js
18
+ import PicnicClient from "picnic-api";
19
+
20
+ // or
21
+
22
+ const PicnicClient = require("picnic-api");
23
+ ```
24
+
25
+ Now initialize the Picnic client with an optional options object.
26
+
27
+ ```js
28
+ const picnicClient = new PicnicClient();
29
+
30
+ // or
31
+
32
+ const picnicClient = new PicnicClient({
33
+ countryCode: "NL", // The country code for the requests. Can be NL or DE. Untested for other countries.
34
+ apiVersion: "15", // default 15 as this is what the app currently uses. The api version for the requests. The effect of this version numbering is unknown to me.
35
+ authKey: "long string here", // default null. The code for the x-picnic-auth header to make authenticated requests. If not supplied then login() needs to be called before making any other requests.
36
+ url: "url here" // default https://storefront-prod.nl.picnicinternational.com/api/15. The url to send requests to.
37
+ });
38
+ ```
39
+
40
+ If no authKey was given in the options use the `login` method. Empty response if successful, otherwise an error.
41
+
42
+ ```js
43
+ await picnicClient.login("email", "password");
44
+ // and then send an authenticated request...
45
+ ```
46
+
47
+ Example of a `GET` request:
48
+
49
+ ```js
50
+ const searchResults = await picnicClient.search("Affligem blond");
51
+ ```
52
+
53
+ Example of a `POST` request:
54
+
55
+ ```js
56
+ await picnicClient.addProductToShoppingCart(11295810, 2);
57
+ ```
58
+
59
+ Examples of a custom (unimplemented) request:
60
+
61
+ ```js
62
+ picnicClient.sendRequest("GET", "/unknown/route");
63
+ picnicClient.sendRequest("POST", "/invite/friend", { email: "email@email.email" });
64
+ ```
65
+
66
+ ## Contributing
67
+
68
+ If you want to contribute to this project then please read the [CONTRIBUTING.md](./CONTRIBUTING.md) file, and if you like this library then please consider using my discount code [MAAR3267](https://picnic.app/nl/vriendenkorting/MAAR3267) so that we both get a 10 euro discount on our orders. 😄
package/lib/index.d.ts ADDED
@@ -0,0 +1,216 @@
1
+ import { ApiConfig, ApiError, Article, Category, ConsentSetting, CountryCode, CustomerServiceContactInfo, Delivery, DeliveryPosition, DeliveryScenario, DeliveryStatus, GetDeliverySlotsResult, ImageSize, LoginResult, MgmDetails, MyStore, Order, OrderStatus, PaymentProfile, ProfileMenu, SearchResult, SetConsentSettingsInput, SetConsentSettingsResult, SingleArticle, SubCategory, SuggestionResult, User, UserInfo, WalletTransaction, WalletTransactionDetails } from "./types/picnic-api";
2
+ declare const _default: {
3
+ new (options?: ApiConfig): {
4
+ countryCode: CountryCode;
5
+ apiVersion: string;
6
+ authKey: string | null;
7
+ url: string;
8
+ /**
9
+ * Logs the user into picnic to be able to send requests.
10
+ * @param {string} username The username of the Picnic account.
11
+ * @param {string} password The password of the Picnic account.
12
+ */
13
+ login(username: string, password: string): Promise<LoginResult>;
14
+ /**
15
+ * Generates a 2FA code for the user to verify.
16
+ * @param {string} channel The channel to send the code to. Can be 'SMS' or possibly something else.
17
+ */
18
+ generate2FACode(channel: string): Promise<null>;
19
+ /**
20
+ * Verifies the 2FA code from the user.
21
+ * @param {string} code The code to verify.
22
+ */
23
+ verify2FACode(code: string): Promise<ApiError | null>;
24
+ /**
25
+ * Gets the details of the current logged in user.
26
+ */
27
+ getUserDetails(): Promise<User>;
28
+ /**
29
+ * Gets information about the user such as toggled features.
30
+ */
31
+ getUserInfo(): Promise<UserInfo>;
32
+ /**
33
+ * Gets information to display on the profile section.
34
+ */
35
+ getProfileMenu(): Promise<ProfileMenu>;
36
+ /**
37
+ * Searches in picnic products.
38
+ * @param {string} query The keywords to search for.
39
+ */
40
+ search(query: string): Promise<SearchResult[]>;
41
+ /**
42
+ * @deprecated This endpoint seems to be deprecated.
43
+ */
44
+ getBundleArticleIds(soleArticleId: string): Promise<string[]>;
45
+ /**
46
+ * Returns the full product page. Some digging is required to get the properties you want. The response is not typed as the content seems to be quite dynamic. Good luck!
47
+ * @param {string} productId The product ID to fetch the page for.
48
+ */
49
+ getProductDetailsPage(productId: string): Promise<any>;
50
+ /**
51
+ * returns a suggestion on Picnic products matching the query.
52
+ * @param {string} query The keywords for suggestions.
53
+ */
54
+ getSuggestions(query: string): Promise<SuggestionResult[]>;
55
+ /**
56
+ * Returns the details of a specific product.
57
+ * @param {string} productId The id of the product to get.
58
+ */
59
+ getArticle(productId: string): Promise<Article>;
60
+ /**
61
+ * Retreives product images from the server as an arrayBuffer.
62
+ * @param {string} imageId The image id to retreive.
63
+ * @param {ImageSize} size The size of the image to return.
64
+ */
65
+ getImage(imageId: string, size: ImageSize): Promise<string>;
66
+ /**
67
+ * Retreives product images from the server ad a DataUri.
68
+ * @param {string} imageId The image id to retreive.
69
+ * @param {ImageSize} size The size of the image to return.
70
+ */
71
+ getImageAsDataUri(imageId: string, size: ImageSize): Promise<string>;
72
+ /**
73
+ * Returns the catgories.
74
+ * @param {number} [depth=0] The category depth of items to retrieve.
75
+ */
76
+ getCategories(depth?: number): Promise<MyStore>;
77
+ /**
78
+ * Returns the shopping cart information of the user and contents.
79
+ */
80
+ getShoppingCart(): Promise<Order>;
81
+ /**
82
+ * Adds a product to the shopping cart.
83
+ * @param {string} productId The id of the product to add.
84
+ * @param {number} [count=1] The amount of this product to add.
85
+ */
86
+ addProductToShoppingCart(productId: string, count?: number): Promise<Order>;
87
+ /**
88
+ * Removes a product from the shopping cart.
89
+ * @param {string} productId The id of the product to remove.
90
+ * @param {number} [count=1] The amount of this product to remove.
91
+ */
92
+ removeProductFromShoppingCart(productId: string, count?: number): Promise<Order>;
93
+ /**
94
+ * Clears the shopping cart of the user.
95
+ */
96
+ clearShoppingCart(): Promise<Order>;
97
+ /**
98
+ * Get all the delivery slots.
99
+ */
100
+ getDeliverySlots(): Promise<GetDeliverySlotsResult>;
101
+ /**
102
+ * Selects a delivery slot.
103
+ * @param {string} slotId The id of the delivery slot to be selected.
104
+ */
105
+ setDeliverySlot(slotId: string): Promise<Order>;
106
+ /**
107
+ * Returns all past and current deliveries of the user.
108
+ * @param {DeliveryStatus[]} [filter=[]] An array with the statusses of the deliveries to filter on.
109
+ */
110
+ getDeliveries(filter?: DeliveryStatus[]): Promise<Delivery[]>;
111
+ /**
112
+ * Get the details of one specific delivery.
113
+ * @param {string} deliveryId The id of the delivery to look up.
114
+ */
115
+ getDelivery(deliveryId: string): Promise<Delivery>;
116
+ /**
117
+ * Get the position data of one specific delivery. For the route and delivery information, use the scenario call.
118
+ * @param {string} deliveryId The id of the delivery to look up.
119
+ */
120
+ getDeliveryPosition(deliveryId: string): Promise<DeliveryPosition>;
121
+ /**
122
+ * Get the driver and route information of the delivery.
123
+ * @param {string} deliveryId The id of the delivery to look up.
124
+ */
125
+ getDeliveryScenario(deliveryId: string): Promise<DeliveryScenario>;
126
+ /**
127
+ * Cancels the order with the given delivery id.
128
+ * @param {string} deliveryId
129
+ */
130
+ cancelDelivery(deliveryId: string): Promise<any>;
131
+ /**
132
+ * Sets a rating for the delivery from 0 to 10. Will return 400 if a delivery already has a rating.
133
+ * @param {string} deliveryId
134
+ * @param {number} rating
135
+ */
136
+ setDeliveryRating(deliveryId: string, rating: number): Promise<string>;
137
+ /**
138
+ * (Re)sends the invoice email of the delivery.
139
+ * @param {string} deliveryId
140
+ */
141
+ sendDeliveryInvoiceEmail(deliveryId: string): Promise<string>;
142
+ /**
143
+ * Returns the status of the order (not delivery) with the given id.
144
+ * @param {string} orderId
145
+ */
146
+ getOrderStatus(orderId: string): Promise<OrderStatus>;
147
+ /**
148
+ * Returns all the lists and sublists.
149
+ * @param {number} [depth=0] The category depth of items to retrieve.
150
+ */
151
+ getLists(depth?: number): Promise<Category[]>;
152
+ /**
153
+ * Returns the sublists of a list, the articles of a sublist if the subListId is given.
154
+ * @param {string} listId The id of the list to get.
155
+ * @param {string} [subListId] The id of the sub list to get.
156
+ * @param {number} [depth=0] The category depth of items to retrieve.
157
+ */
158
+ getList(listId: string, subListId?: string, depth?: number): Promise<SubCategory[] | SingleArticle[]>;
159
+ /**
160
+ * Returns the MGM details. This are the friends discount data.
161
+ */
162
+ getMgmDetails(): Promise<MgmDetails>;
163
+ /**
164
+ * Returns the list of consent settings.
165
+ * @param {boolean} [general=false] Returns only the 'general' consent settings.
166
+ */
167
+ getConsentSettings(general?: boolean): Promise<ConsentSetting[]>;
168
+ /**
169
+ * Sets one or multiple consent options to true or false.
170
+ * @param {SetConsentSettingsInput} consentSettingsInput An array of objects of consent items.
171
+ */
172
+ setConsentSettings(consentSettingsInput: SetConsentSettingsInput): Promise<SetConsentSettingsResult>;
173
+ /**
174
+ * Returns the popup messages in the app. For example, the message after a delivery, asking if the delivery was satisfactory.
175
+ */
176
+ getMessages(): Promise<any>;
177
+ /**
178
+ * Returns the reminders.
179
+ */
180
+ getReminders(): Promise<any>;
181
+ /**
182
+ * Gets payment information.
183
+ */
184
+ getPaymentProfile(): Promise<PaymentProfile>;
185
+ /**
186
+ * Gets transactions made.
187
+ * @param {number} pageNumber The page number to get the transactions from.
188
+ */
189
+ getWalletTransactions(pageNumber: number): Promise<WalletTransaction[]>;
190
+ /**
191
+ * Gets payment information.
192
+ * @param {string} walletTransactionId The id of the transaction to get the details from.
193
+ */
194
+ getWalletTransactionDetails(walletTransactionId: string): Promise<WalletTransactionDetails>;
195
+ /**
196
+ * Gets payment information.
197
+ */
198
+ getCustomerServiceContactInfo(): Promise<CustomerServiceContactInfo>;
199
+ /**
200
+ * Gets parcels.
201
+ * @todo Implement return type once known.
202
+ */
203
+ getParcels(): Promise<any[]>;
204
+ /**
205
+ * Can be used to send custom requests that are not implemented but do need authentication for it.
206
+ * @param {string} method The HTTP method to use, such as GET, POST, PUT and DELETE.
207
+ * @param {string} path The path, possibly including query params. Example: '/cart/set_delivery_slot' or '/my_store?depth=0'.
208
+ * @param {TRequestData|null} [data=null] The request body, usually in case of a POST or PUT request.
209
+ * @param {boolean} [includePicnicHeaders=false] If it should include x-picnic-agent and x-picnic-did headers.
210
+ * @param {boolean} [isImageRequest=false] Will add the arrayBuffer response type if true.
211
+ */
212
+ sendRequest<TRequestData, TResponseData>(method: "GET" | "POST" | "PUT" | "DELETE", path: string, data?: TRequestData | null, includePicnicHeaders?: boolean, isImageRequest?: boolean): Promise<TResponseData>;
213
+ };
214
+ };
215
+ export = _default;
216
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,SAAS,EACT,QAAQ,EACR,OAAO,EACP,QAAQ,EACR,cAAc,EACd,WAAW,EACX,0BAA0B,EAC1B,QAAQ,EACR,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,EAEd,sBAAsB,EACtB,SAAS,EAET,WAAW,EACX,UAAU,EACV,OAAO,EACP,KAAK,EACL,WAAW,EACX,cAAc,EACd,WAAW,EACX,YAAY,EACZ,uBAAuB,EACvB,wBAAwB,EAExB,aAAa,EACb,WAAW,EACX,gBAAgB,EAChB,IAAI,EACJ,QAAQ,EAER,iBAAiB,EACjB,wBAAwB,EAEzB,MAAM,oBAAoB,CAAC;;mBAiBJ,SAAS;qBAblB,WAAW;oBACZ,MAAM;iBACT,MAAM,GAAG,IAAI;aACjB,MAAM;QAiBX;;;;WAIG;wBACmB,MAAM,YAAY,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;QAmCrE;;;WAGG;iCACsB,MAAM;QAI/B;;;WAGG;4BACiB,MAAM;QAI1B;;WAEG;0BACe,OAAO,CAAC,IAAI,CAAC;QAI/B;;WAEG;uBACY,OAAO,CAAC,QAAQ,CAAC;QAIhC;;WAEG;0BACe,OAAO,CAAC,WAAW,CAAC;QAItC;;;WAGG;sBACiB,MAAM,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;QAKpD;;WAEG;2CACsC,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;QAyBnE;;;WAGG;yCACoC,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;QAS5D;;;WAGG;8BACmB,MAAM,GAAG,OAAO,CAAC,gBAAgB,EAAE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