From b66b9593a18a7a249b526144c5dc1162e42f6e48 Mon Sep 17 00:00:00 2001 From: Miro Benicio Date: Wed, 16 Aug 2023 11:08:44 -0300 Subject: [PATCH 01/12] fix:create retailer login verification fix: enum of retailers --- example/package-lock.json | 3 +- package-lock.json | 4 +- src/service/receipt/receipt-account-type.ts | 68 ++++++++++++--------- src/service/receipt/receipt-service.ts | 21 +++++-- 4 files changed, 60 insertions(+), 36 deletions(-) diff --git a/example/package-lock.json b/example/package-lock.json index 223d25c7..7a37efd8 100644 --- a/example/package-lock.json +++ b/example/package-lock.json @@ -46,7 +46,7 @@ }, "..": { "name": "@mytiki/tiki-receipt-capacitor", - "version": "0.1.0", + "version": "0.1.2", "license": "MIT", "dependencies": { "@mytiki/tiki-capture-receipt-capacitor": "^0.2.1", @@ -73,6 +73,7 @@ "eslint-plugin-vue": "^9.16.0", "path": "^0.12.7", "rollup-plugin-typescript2": "^0.35.0", + "typedoc": "^0.24.8", "typescript": "^5.1.6", "vite": "^4.4.9", "vite-plugin-dts": "^3.5.2", diff --git a/package-lock.json b/package-lock.json index c4a41d5e..f6f91c05 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@mytiki/tiki-receipt-capacitor", - "version": "0.1.1", + "version": "0.1.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@mytiki/tiki-receipt-capacitor", - "version": "0.1.1", + "version": "0.1.2", "license": "MIT", "dependencies": { "@mytiki/tiki-capture-receipt-capacitor": "^0.2.1", diff --git a/src/service/receipt/receipt-account-type.ts b/src/service/receipt/receipt-account-type.ts index 86dccf13..578009da 100644 --- a/src/service/receipt/receipt-account-type.ts +++ b/src/service/receipt/receipt-account-type.ts @@ -4,30 +4,34 @@ */ import GmailIcon from "@/assets/images/gmail.png"; +import AmazonIcon from "@assets/images/amazon.png"; import { AccountProvider } from "@mytiki/tiki-capture-receipt-capacitor"; /** * Enumeration of the supported account types. */ export enum ReceiptAccountType { - // ACME = "ACME", + // ACME_MARKETS = "ACME", // ALBERTSONS = "Albertsons", - // AMAZON = "Amazon", - // AOL = "AOL", - // BBB = "Bed Bath & Beyond", + AMAZON = "Amazon", + AMAZON_CA = "Amazon Canada", + AMAZON_UK = "Amazon United Kingdom", + //BED_BATH_AND_BEYOND = "Bed Bath & Beyond", + //AOL = "AOL", + //BBB = "Bed Bath & Beyond", /** * Gmail account type. */ GMAIL = "Gmail", - // BEST_BUY = "Best Buy", - // BJS = "BJ’s Wholesale Club", + // BESTBUY = "Best Buy", + // BJS_WHOLESALE = "BJ’s Wholesale Club", // CHEWY = "Chewy", // COSTCO = "Costco", // CVS = "CVS", - // DICKS = "Dick’s Sporting Goods", + // DICKS_SPORTING_GOODS = "Dick’s Sporting Goods", // DOLLAR_GENERAL = "Dollar General", // DOLLAR_TREE = "DollarTree", - // DOMINOS = "Domino’s Pizza", + // DOMINOS_PIZZA = "Domino’s Pizza", // DOOR_DASH = "DoorDash", // DRIZLY = "Drizly", // FAMILY_DOLLAR = "Family Dollar", @@ -40,7 +44,7 @@ export enum ReceiptAccountType { // HARRIS_TEETER = "Harris Teeter", // HEB = "H.E.B", // HOME_DEPOT = "Home Depot", - // HY_VEE = "HyVee", + // HYVEE = "HyVee", // INSTACART = "Instacart", // JEWEL_OSCO = "Jewel Osco", // KOHLS = "Kohl’s", @@ -58,10 +62,10 @@ export enum ReceiptAccountType { // SEAMLESS = "Seamless", // SEPHORA = "Sephora", // SHIPT = "Shipt", - // SHOP_RITE = "ShopRite", + // SHOPRITE = "ShopRite", // SPROUTS = "Sprouts", // STAPLES = "Staples", - // STAPLES_CANADA = "Staples Canada", + // STAPLES_CA = "Staples Canada", // STARBUCKS = "Starbucks", // TACO_BELL = "Taco Bell", // TARGET = "Target", @@ -71,7 +75,7 @@ export enum ReceiptAccountType { // VONS = "Vons", // WALGREENS = "Walgreens", // WALMART = "Walmart", - // WALMART_CANADA = "Walmart Canada", + // WALMART_CA = "Walmart Canada", // WEGMANS = "Wegman’s", } @@ -85,6 +89,9 @@ export const all: Map = new Map( ), ); +export const toString = (type: string): string => { + return Object.keys(ReceiptAccountType).find((val) => {type.toLowerCase() === val})! +} /** * Gets the icon (image src) associated with a {@link ReceiptAccountType}. * @param type - The receipt account type. @@ -93,19 +100,23 @@ export const all: Map = new Map( */ export const icon = (type: ReceiptAccountType): string => { switch (type) { - // case ReceiptAccountType.ACME: + // case ReceiptAccountType.ACME_MARKETS: // return AcmeIcon; // case ReceiptAccountType.ALBERTSONS: // return AlbertsonsIcon; - // case ReceiptAccountType.AMAZON: - // return AmazonIcon; + case ReceiptAccountType.AMAZON: + return AmazonIcon; + case ReceiptAccountType.AMAZON_CA: + return AmazonIcon; + case ReceiptAccountType.AMAZON_UK: + return AmazonIcon; // case ReceiptAccountType.AOL: // return AolIcon; // case ReceiptAccountType.BBB: // return BedBathBeyondIcon; - // case ReceiptAccountType.BEST_BUY: + // case ReceiptAccountType.BESTBUY: // return BestBuyIcon; - // case ReceiptAccountType.BJS: + // case ReceiptAccountType.BJS_WHOLESALE: // return BJSIcon; // case ReceiptAccountType.CHEWY: // return ChewyIcon; @@ -113,13 +124,13 @@ export const icon = (type: ReceiptAccountType): string => { // return CostcoIcon; // case ReceiptAccountType.CVS: // return CVSIcon; - // case ReceiptAccountType.DICKS: + // case ReceiptAccountType.DICKS_SPORTING_GOODS: // return DicksIcon; // case ReceiptAccountType.DOLLAR_GENERAL: // return DollarGeneralIcon; // case ReceiptAccountType.DOLLAR_TREE: // return DollarTreeIcon; - // case ReceiptAccountType.DOMINOS: + // case ReceiptAccountType.DOMINOS_PIZZA: // return DominosIcon; // case ReceiptAccountType.DOOR_DASH: // return DoorDashIcon; @@ -135,19 +146,19 @@ export const icon = (type: ReceiptAccountType): string => { // return FredMeyerIcon; // case ReceiptAccountType.GAP: // return GapIcon; - // case ReceiptAccountType.GIANT_EAGLE: - // return GiantEagleIcon; + // case ReceiptAccountType.GIANT_EAGLE: + // return GiantEagleIcon; case ReceiptAccountType.GMAIL: return GmailIcon; - // case ReceiptAccountType.GRUBHUB: - // return GrubHubIcon; + //case ReceiptAccountType.GRUBHUB: + // return GrubHubIcon; // case ReceiptAccountType.HARRIS_TEETER: // return HarrisTeeterIcon; // case ReceiptAccountType.HEB: // return HEBIcon; // case ReceiptAccountType.HOME_DEPOT: // return HomeDepotIcon; - // case ReceiptAccountType.HY_VEE: + // case ReceiptAccountType.HYVEE: // return HyVeeIcon; // case ReceiptAccountType.INSTACART: // return InstacartIcon; @@ -183,13 +194,13 @@ export const icon = (type: ReceiptAccountType): string => { // return SephoraIcon; // case ReceiptAccountType.SHIPT: // return ShiptIcon; - // case ReceiptAccountType.SHOP_RITE: + // case ReceiptAccountType.SHOPRITE: // return ShopRiteIcon; // case ReceiptAccountType.SPROUTS: // return SproutsIcon; // case ReceiptAccountType.STAPLES: // return StaplesIcon; - // case ReceiptAccountType.STAPLES_CANADA: + // case ReceiptAccountType.STAPLES_CA: // return StaplesCanadaIcon; // case ReceiptAccountType.STARBUCKS: // return StarbucksIcon; @@ -209,12 +220,13 @@ export const icon = (type: ReceiptAccountType): string => { // return WalgreensIcon; // case ReceiptAccountType.WALMART: // return WalmartIcon; - // case ReceiptAccountType.WALMART_CANADA: + // case ReceiptAccountType.WALMART_CA: // return WalmartCanadaIcon; // case ReceiptAccountType.WEGMANS: // return WegmansIcon; default: - throw Error("Unsupported ReceiptAccountType"); + return '' + //throw Error("Unsupported ReceiptAccountType"); } }; diff --git a/src/service/receipt/receipt-service.ts b/src/service/receipt/receipt-service.ts index d5f743e7..6bc28198 100644 --- a/src/service/receipt/receipt-service.ts +++ b/src/service/receipt/receipt-service.ts @@ -10,6 +10,7 @@ import { TikiService } from "@/service/tiki-service"; import { ReceiptAccount } from "@/service/receipt/receipt-account"; import { ReceiptEvent } from "@/service/receipt/receipt-event"; import { HistoryEvent } from "@/service/history/history-event"; +import { toString, ReceiptAccountType } from "./receipt-account-type"; /** * Service responsible for handling receipt-related operations and events. @@ -97,11 +98,21 @@ export class ReceiptService { * @param account - The receipt account to log in. */ async login(account: ReceiptAccount): Promise { - await this.plugin.loginWithEmail( - account.username, - account.password!, - account.provider!, - ); + if(account.type == 'Gmail') { + await this.plugin.loginWithEmail( + account.username, + account.password!, + account.provider!, + ); + } else { + console.log('retailer breakpoint') + // const acct = await this.plugin.loginWithRetailer( + // account.username, + // account.password!, + // toString(account.type!), + // ); + } + debugger account.verified = true; this.addAccount(account); await this.process(ReceiptEvent.LINK, { From 388d12b8014c5e2482f767cdb6d6fa5ea8dba67d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Gon=C3=A7alves?= Date: Wed, 16 Aug 2023 11:15:46 -0300 Subject: [PATCH 02/12] fix: merge temporary local deps --- example/android/capacitor.settings.gradle | 4 +-- package-lock.json | 35 ++++++++++++++++++----- package.json | 2 +- src/service/receipt/receipt-service.ts | 21 +++++++++++--- 4 files changed, 48 insertions(+), 14 deletions(-) diff --git a/example/android/capacitor.settings.gradle b/example/android/capacitor.settings.gradle index 2ecf7654..300552a1 100644 --- a/example/android/capacitor.settings.gradle +++ b/example/android/capacitor.settings.gradle @@ -3,7 +3,7 @@ include ':capacitor-android' project(':capacitor-android').projectDir = new File('../node_modules/@capacitor/android/capacitor') include ':mytiki-tiki-capture-receipt-capacitor' -project(':mytiki-tiki-capture-receipt-capacitor').projectDir = new File('../node_modules/@mytiki/tiki-capture-receipt-capacitor/android') +project(':mytiki-tiki-capture-receipt-capacitor').projectDir = new File('../../../tiki-capture-receipt-capacitor/android') include ':mytiki-tiki-sdk-capacitor' -project(':mytiki-tiki-sdk-capacitor').projectDir = new File('../node_modules/@mytiki/tiki-sdk-capacitor/android') +project(':mytiki-tiki-sdk-capacitor').projectDir = new File('../../node_modules/@mytiki/tiki-sdk-capacitor/android') diff --git a/package-lock.json b/package-lock.json index f6f91c05..9c0a8e7a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "0.1.2", "license": "MIT", "dependencies": { - "@mytiki/tiki-capture-receipt-capacitor": "^0.2.1", + "@mytiki/tiki-capture-receipt-capacitor": "file:../tiki-capture-receipt-capacitor", "@mytiki/tiki-sdk-capacitor": "^0.2.1", "hammerjs": "^2.0.8", "vue": "^3.3.4", @@ -49,6 +49,31 @@ "@mytiki/tiki-sdk-capacitor": "^0.2.1" } }, + "../tiki-capture-receipt-capacitor": { + "name": "@mytiki/tiki-capture-receipt-capacitor", + "version": "0.2.0", + "license": "MIT", + "devDependencies": { + "@capacitor/android": "^5.2.2", + "@capacitor/core": "^5.2.2", + "@capacitor/docgen": "^0.2.1", + "@capacitor/ios": "^5.2.2", + "@ionic/eslint-config": "^0.3.0", + "@ionic/prettier-config": "^4.0.0", + "@ionic/swiftlint-config": "^1.1.2", + "@typescript-eslint/eslint-plugin": "^6.3.0", + "eslint": "^7.32.0", + "prettier": "~3.0.1", + "prettier-plugin-java": "~2.2.0", + "rimraf": "^5.0.1", + "rollup": "^3.28.0", + "swiftlint": "^1.0.2", + "typescript": "~5.1.6" + }, + "peerDependencies": { + "@capacitor/core": "^5.0.0" + } + }, "node_modules/@aashutoshrathi/word-wrap": { "version": "1.2.6", "resolved": "https://registry.npmjs.org/@aashutoshrathi/word-wrap/-/word-wrap-1.2.6.tgz", @@ -690,12 +715,8 @@ } }, "node_modules/@mytiki/tiki-capture-receipt-capacitor": { - "version": "0.2.1", - "resolved": "https://registry.npmjs.org/@mytiki/tiki-capture-receipt-capacitor/-/tiki-capture-receipt-capacitor-0.2.1.tgz", - "integrity": "sha512-zF2M/IyPIvUN53wzi7GZJUk/9p7LVt0CD3eQwUTDZHgnSQjBkKpYwkDqlP6HfB7iGNPEDettk+81U/3cRiUL7A==", - "peerDependencies": { - "@capacitor/core": "^5.0.0" - } + "resolved": "../tiki-capture-receipt-capacitor", + "link": true }, "node_modules/@mytiki/tiki-sdk-capacitor": { "version": "0.2.1", diff --git a/package.json b/package.json index e48efac2..2c51d5ae 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "author": "", "license": "MIT", "dependencies": { - "@mytiki/tiki-capture-receipt-capacitor": "^0.2.1", + "@mytiki/tiki-capture-receipt-capacitor": "file:../tiki-capture-receipt-capacitor", "@mytiki/tiki-sdk-capacitor": "^0.2.1", "hammerjs": "^2.0.8", "vue": "^3.3.4", diff --git a/src/service/receipt/receipt-service.ts b/src/service/receipt/receipt-service.ts index 6bc28198..502b510a 100644 --- a/src/service/receipt/receipt-service.ts +++ b/src/service/receipt/receipt-service.ts @@ -93,10 +93,23 @@ export class ReceiptService { ); } - /** - * Log in with a {@link ReceiptAccount}. - * @param account - The receipt account to log in. - */ +// /** +// * Log in with a {@link ReceiptAccount}. +// * @param account - The receipt account to log in. +// */ +// async login(account: ReceiptAccount): Promise { +// await this.plugin.loginWithEmail( +// account.username, +// account.password!, +// account.provider!, +// ); +// account.verified = true; +// this.addAccount(account); +// await this.process(ReceiptEvent.LINK, { +// account: account, +// }); +// } + async login(account: ReceiptAccount): Promise { if(account.type == 'Gmail') { await this.plugin.loginWithEmail( From 27fcc117dd043bf92af1e0737267a91d86559a13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Gon=C3=A7alves?= Date: Wed, 16 Aug 2023 11:22:02 -0300 Subject: [PATCH 03/12] fix(vue): amazon icomn import --- src/service/receipt/receipt-account-type.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/service/receipt/receipt-account-type.ts b/src/service/receipt/receipt-account-type.ts index 578009da..aa6d0020 100644 --- a/src/service/receipt/receipt-account-type.ts +++ b/src/service/receipt/receipt-account-type.ts @@ -4,7 +4,7 @@ */ import GmailIcon from "@/assets/images/gmail.png"; -import AmazonIcon from "@assets/images/amazon.png"; +import AmazonIcon from "@/assets/images/amazon.png"; import { AccountProvider } from "@mytiki/tiki-capture-receipt-capacitor"; /** From 653f3ac6e3fd534f814f2e49b7f87ba183d85dff Mon Sep 17 00:00:00 2001 From: Miro Benicio Date: Wed, 16 Aug 2023 14:35:49 -0300 Subject: [PATCH 04/12] fix: link account working, but with wrong return from the api --- src/service/receipt/receipt-account-type.ts | 2 +- src/service/receipt/receipt-service.ts | 43 +++++++++++++++------ 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/service/receipt/receipt-account-type.ts b/src/service/receipt/receipt-account-type.ts index aa6d0020..ee1218de 100644 --- a/src/service/receipt/receipt-account-type.ts +++ b/src/service/receipt/receipt-account-type.ts @@ -90,7 +90,7 @@ export const all: Map = new Map( ); export const toString = (type: string): string => { - return Object.keys(ReceiptAccountType).find((val) => {type.toLowerCase() === val})! + return Object.keys(ReceiptAccountType).find((val) => type.toLowerCase() === val.toLowerCase())!.toLowerCase() } /** * Gets the icon (image src) associated with a {@link ReceiptAccountType}. diff --git a/src/service/receipt/receipt-service.ts b/src/service/receipt/receipt-service.ts index 502b510a..cd9c334c 100644 --- a/src/service/receipt/receipt-service.ts +++ b/src/service/receipt/receipt-service.ts @@ -118,14 +118,14 @@ export class ReceiptService { account.provider!, ); } else { - console.log('retailer breakpoint') - // const acct = await this.plugin.loginWithRetailer( - // account.username, - // account.password!, - // toString(account.type!), - // ); + let accountSigned = await this.plugin.loginWithRetailer( + account.username, + account.password!, + toString(account.type!), + ); + console.log(accountSigned) } - debugger + account.verified = true; this.addAccount(account); await this.process(ReceiptEvent.LINK, { @@ -138,11 +138,17 @@ export class ReceiptService { * @param account - The receipt account to log out. */ async logout(account: ReceiptAccount): Promise { + if(account.type == 'Gmail') { await this.plugin.removeEmail( account.username, account.password!, account.provider!, - ); + );} else { + await this.plugin.removeRetailer( + account.username, + toString(account.type!), + ); + } this.removeAccount(account); await this.process(ReceiptEvent.UNLINK, { account: account, @@ -158,7 +164,14 @@ export class ReceiptService { async (account: Capture.Account, receipts: Capture.Receipt[]) => receipts.forEach((receipt) => this.addReceipt(receipt, account)), ); - + + + // orders = async (): Promise => + // this.plugin.orders( + // async (account: Capture.Account, orders: Capture.Order[]) =>{ + // orders.forEach((order)=> this.addReceipt(order, account)) + // } + // ) /** * Load and verify previously logged-in accounts. */ @@ -169,9 +182,15 @@ export class ReceiptService { private addAccount(account: ReceiptAccount): void { this._accounts.push(account); - this._onAccountListeners.forEach((listener) => listener(account)); - this.scrape(); - } + if(account.type === "Gmail") { + this._onAccountListeners.forEach((listener) => listener(account)); + this.scrape(); + } + // else { + // this._onAccountListeners.forEach((listener) => listener(account)); + // this.orders(); + // } + } private removeAccount(account: ReceiptAccount): void { this._accounts = this._accounts.filter( From 29314d732d50b21bd6099aeff6bde6dbaff6abc4 Mon Sep 17 00:00:00 2001 From: Miro Benicio Date: Wed, 16 Aug 2023 16:55:51 -0300 Subject: [PATCH 05/12] fix: link account and grab orders --- src/service/receipt/receipt-service.ts | 33 +++++++++++++------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/service/receipt/receipt-service.ts b/src/service/receipt/receipt-service.ts index cd9c334c..0bc9bff6 100644 --- a/src/service/receipt/receipt-service.ts +++ b/src/service/receipt/receipt-service.ts @@ -111,22 +111,23 @@ export class ReceiptService { // } async login(account: ReceiptAccount): Promise { - if(account.type == 'Gmail') { + if(account.provider) { await this.plugin.loginWithEmail( account.username, account.password!, account.provider!, ); } else { - let accountSigned = await this.plugin.loginWithRetailer( + let accountSigned = await this.plugin.loginWithRetailer( account.username, account.password!, toString(account.type!), ); - console.log(accountSigned) + console.log('retorno', accountSigned) + if(accountSigned.isVerified) account.verified = true } - - account.verified = true; + console.log('account', account) + //account.verified = true; this.addAccount(account); await this.process(ReceiptEvent.LINK, { account: account, @@ -144,10 +145,11 @@ export class ReceiptService { account.password!, account.provider!, );} else { - await this.plugin.removeRetailer( + const removedRetailer = await this.plugin.removeRetailer( account.username, toString(account.type!), ); + console.log('removed Retailer', removedRetailer) } this.removeAccount(account); await this.process(ReceiptEvent.UNLINK, { @@ -166,12 +168,11 @@ export class ReceiptService { ); - // orders = async (): Promise => - // this.plugin.orders( - // async (account: Capture.Account, orders: Capture.Order[]) =>{ - // orders.forEach((order)=> this.addReceipt(order, account)) - // } - // ) + orders = async (): Promise =>{ + const orders = await this.plugin.orders() + console.log(orders) + } + /** * Load and verify previously logged-in accounts. */ @@ -186,10 +187,10 @@ export class ReceiptService { this._onAccountListeners.forEach((listener) => listener(account)); this.scrape(); } - // else { - // this._onAccountListeners.forEach((listener) => listener(account)); - // this.orders(); - // } + else { + this._onAccountListeners.forEach((listener) => listener(account)); + this.orders(); + } } private removeAccount(account: ReceiptAccount): void { From 48607188bf43973dfc7df2738c42ecbb5a2e233e Mon Sep 17 00:00:00 2001 From: Miro Benicio Date: Wed, 16 Aug 2023 17:38:48 -0300 Subject: [PATCH 06/12] fix: hiding the error message of the link account --- src/components/account/account-link.vue | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/account/account-link.vue b/src/components/account/account-link.vue index 0d24d6cf..9fd577fa 100644 --- a/src/components/account/account-link.vue +++ b/src/components/account/account-link.vue @@ -34,6 +34,7 @@ const submit = async () => { form.value.password?.length > 0 ) { try { + error.value = '' await tiki?.receipt.login(form.value); form.value = new ReceiptAccount("", ReceiptAccountType.GMAIL, ""); } catch (err: any) { From eeac7c96b203b319128dcbb67ef3400486708387 Mon Sep 17 00:00:00 2001 From: Miro Benicio Date: Wed, 16 Aug 2023 18:50:44 -0300 Subject: [PATCH 07/12] fix: Load retailers accounts saved in the id --- src/service/receipt/receipt-account-type.ts | 3 +- src/service/receipt/receipt-service.ts | 37 ++++++++------------- 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/src/service/receipt/receipt-account-type.ts b/src/service/receipt/receipt-account-type.ts index ee1218de..65637b10 100644 --- a/src/service/receipt/receipt-account-type.ts +++ b/src/service/receipt/receipt-account-type.ts @@ -99,7 +99,8 @@ export const toString = (type: string): string => { * @throws Error if the receipt account type is not supported. */ export const icon = (type: ReceiptAccountType): string => { - switch (type) { + const retailer = (Object.values(ReceiptAccountType)).find((retailer)=> type.toLowerCase() === retailer.toLowerCase()) + switch (retailer) { // case ReceiptAccountType.ACME_MARKETS: // return AcmeIcon; // case ReceiptAccountType.ALBERTSONS: diff --git a/src/service/receipt/receipt-service.ts b/src/service/receipt/receipt-service.ts index 0bc9bff6..8c927169 100644 --- a/src/service/receipt/receipt-service.ts +++ b/src/service/receipt/receipt-service.ts @@ -10,7 +10,7 @@ import { TikiService } from "@/service/tiki-service"; import { ReceiptAccount } from "@/service/receipt/receipt-account"; import { ReceiptEvent } from "@/service/receipt/receipt-event"; import { HistoryEvent } from "@/service/history/history-event"; -import { toString, ReceiptAccountType } from "./receipt-account-type"; +import { toString, ReceiptAccountType, icon } from "./receipt-account-type"; /** * Service responsible for handling receipt-related operations and events. @@ -92,24 +92,6 @@ export class ReceiptService { `No license found for ${this.tiki.sdk.id}. User must first consent to the program.`, ); } - -// /** -// * Log in with a {@link ReceiptAccount}. -// * @param account - The receipt account to log in. -// */ -// async login(account: ReceiptAccount): Promise { -// await this.plugin.loginWithEmail( -// account.username, -// account.password!, -// account.provider!, -// ); -// account.verified = true; -// this.addAccount(account); -// await this.process(ReceiptEvent.LINK, { -// account: account, -// }); -// } - async login(account: ReceiptAccount): Promise { if(account.provider) { await this.plugin.loginWithEmail( @@ -123,11 +105,8 @@ export class ReceiptService { account.password!, toString(account.type!), ); - console.log('retorno', accountSigned) if(accountSigned.isVerified) account.verified = true } - console.log('account', account) - //account.verified = true; this.addAccount(account); await this.process(ReceiptEvent.LINK, { account: account, @@ -176,10 +155,20 @@ export class ReceiptService { /** * Load and verify previously logged-in accounts. */ - load = async (): Promise => + load = async (): Promise =>{ + (await this.plugin.retailers()).forEach((retailer=> + this.addAccount({ + username: retailer.username, + type: retailer.retailer, + verified: retailer.isVerified, + icon: icon(retailer.retailer), + provider: retailer.retailer + }) + )) (await this.plugin.verifyEmail()).forEach((account) => this.addAccount(ReceiptAccount.fromCapture(account)), - ); + ) + } private addAccount(account: ReceiptAccount): void { this._accounts.push(account); From 6e6843ead201bd1b7f73e5b41c88c78ee986b089 Mon Sep 17 00:00:00 2001 From: Miro Benicio Date: Wed, 16 Aug 2023 19:47:51 -0300 Subject: [PATCH 08/12] fix:orders requests --- src/service/receipt/receipt-service.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/service/receipt/receipt-service.ts b/src/service/receipt/receipt-service.ts index 8c927169..5f6a773f 100644 --- a/src/service/receipt/receipt-service.ts +++ b/src/service/receipt/receipt-service.ts @@ -128,7 +128,6 @@ export class ReceiptService { account.username, toString(account.type!), ); - console.log('removed Retailer', removedRetailer) } this.removeAccount(account); await this.process(ReceiptEvent.UNLINK, { @@ -147,9 +146,10 @@ export class ReceiptService { ); - orders = async (): Promise =>{ + orders = async (account: ReceiptAccount): Promise =>{ const orders = await this.plugin.orders() console.log(orders) + orders.forEach((order)=> this.addReceipt(order, account)) } /** @@ -164,7 +164,7 @@ export class ReceiptService { icon: icon(retailer.retailer), provider: retailer.retailer }) - )) + )); (await this.plugin.verifyEmail()).forEach((account) => this.addAccount(ReceiptAccount.fromCapture(account)), ) @@ -178,7 +178,7 @@ export class ReceiptService { } else { this._onAccountListeners.forEach((listener) => listener(account)); - this.orders(); + this.orders(account); } } From 3d76b6c6d77c04cb8707a6bc0c90fe5de555d488 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Gon=C3=A7alves?= Date: Wed, 16 Aug 2023 21:48:29 -0300 Subject: [PATCH 09/12] fix(vue): get orders --- example/android/capacitor.settings.gradle | 2 +- example/ios/App/Podfile.lock | 8 ++++---- example/package-lock.json | 13 +++++-------- example/package.json | 2 +- package-lock.json | 4 ++-- package.json | 3 ++- src/service/receipt/receipt-service.ts | 11 +++++------ 7 files changed, 20 insertions(+), 23 deletions(-) diff --git a/example/android/capacitor.settings.gradle b/example/android/capacitor.settings.gradle index 300552a1..2d9a67bf 100644 --- a/example/android/capacitor.settings.gradle +++ b/example/android/capacitor.settings.gradle @@ -6,4 +6,4 @@ include ':mytiki-tiki-capture-receipt-capacitor' project(':mytiki-tiki-capture-receipt-capacitor').projectDir = new File('../../../tiki-capture-receipt-capacitor/android') include ':mytiki-tiki-sdk-capacitor' -project(':mytiki-tiki-sdk-capacitor').projectDir = new File('../../node_modules/@mytiki/tiki-sdk-capacitor/android') +project(':mytiki-tiki-sdk-capacitor').projectDir = new File('../node_modules/@mytiki/tiki-sdk-capacitor/android') diff --git a/example/ios/App/Podfile.lock b/example/ios/App/Podfile.lock index fd91bb33..0988a8de 100644 --- a/example/ios/App/Podfile.lock +++ b/example/ios/App/Podfile.lock @@ -2,9 +2,9 @@ PODS: - Capacitor (5.2.3): - CapacitorCordova - CapacitorCordova (5.2.3) - - MytikiTikiCaptureReceiptCapacitor (0.2.0): + - MytikiTikiCaptureReceiptCapacitor (0.2.1): - Capacitor - - MytikiTikiSdkCapacitor (0.2.0): + - MytikiTikiSdkCapacitor (0.2.1): - Capacitor DEPENDENCIES: @@ -26,8 +26,8 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: Capacitor: 6f44cbc33839b8a4202b8eac97041fe584083417 CapacitorCordova: 35def3ebfdef491f0a7b652816eb873ff4b20bbf - MytikiTikiCaptureReceiptCapacitor: 7c942a9e13964f165046f5dc5244383203d1e060 - MytikiTikiSdkCapacitor: 337e2494af6b6c34a1483100da4d4b5cf283d53d + MytikiTikiCaptureReceiptCapacitor: 85f962a88bffcf35cecf2d8abff2dcddc694e8be + MytikiTikiSdkCapacitor: d15dcdc1796fcdd184e2df2980157a2cb2246ec5 PODFILE CHECKSUM: 2f9a0f322694e9fc6ea5b4ef01d7ecdb29338094 diff --git a/example/package-lock.json b/example/package-lock.json index 7a37efd8..2820247e 100644 --- a/example/package-lock.json +++ b/example/package-lock.json @@ -12,7 +12,7 @@ "@capacitor/android": "^5.2.3", "@capacitor/core": "^5.2.3", "@capacitor/ios": "^5.2.3", - "@mytiki/tiki-capture-receipt-capacitor": "^0.2.1", + "@mytiki/tiki-capture-receipt-capacitor": "file:../tiki-capture-receipt-capacitor", "@mytiki/tiki-receipt-capacitor": "file:..", "@mytiki/tiki-sdk-capacitor": "^0.2.1", "uuid": "^9.0.0", @@ -49,7 +49,7 @@ "version": "0.1.2", "license": "MIT", "dependencies": { - "@mytiki/tiki-capture-receipt-capacitor": "^0.2.1", + "@mytiki/tiki-capture-receipt-capacitor": "file:../tiki-capture-receipt-capacitor", "@mytiki/tiki-sdk-capacitor": "^0.2.1", "hammerjs": "^2.0.8", "vue": "^3.3.4", @@ -89,6 +89,7 @@ "@mytiki/tiki-sdk-capacitor": "^0.2.1" } }, + "../tiki-capture-receipt-capacitor": {}, "node_modules/@aashutoshrathi/word-wrap": { "version": "1.2.6", "resolved": "https://registry.npmjs.org/@aashutoshrathi/word-wrap/-/word-wrap-1.2.6.tgz", @@ -736,12 +737,8 @@ "integrity": "sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==" }, "node_modules/@mytiki/tiki-capture-receipt-capacitor": { - "version": "0.2.1", - "resolved": "https://registry.npmjs.org/@mytiki/tiki-capture-receipt-capacitor/-/tiki-capture-receipt-capacitor-0.2.1.tgz", - "integrity": "sha512-zF2M/IyPIvUN53wzi7GZJUk/9p7LVt0CD3eQwUTDZHgnSQjBkKpYwkDqlP6HfB7iGNPEDettk+81U/3cRiUL7A==", - "peerDependencies": { - "@capacitor/core": "^5.0.0" - } + "resolved": "../tiki-capture-receipt-capacitor", + "link": true }, "node_modules/@mytiki/tiki-receipt-capacitor": { "resolved": "..", diff --git a/example/package.json b/example/package.json index fbfc28e9..a57eb05b 100644 --- a/example/package.json +++ b/example/package.json @@ -16,7 +16,7 @@ "@capacitor/android": "^5.2.3", "@capacitor/core": "^5.2.3", "@capacitor/ios": "^5.2.3", - "@mytiki/tiki-capture-receipt-capacitor": "^0.2.1", + "@mytiki/tiki-capture-receipt-capacitor": "file:../tiki-capture-receipt-capacitor", "@mytiki/tiki-receipt-capacitor": "file:..", "@mytiki/tiki-sdk-capacitor": "^0.2.1", "uuid": "^9.0.0", diff --git a/package-lock.json b/package-lock.json index 9c0a8e7a..da10d867 100644 --- a/package-lock.json +++ b/package-lock.json @@ -51,7 +51,7 @@ }, "../tiki-capture-receipt-capacitor": { "name": "@mytiki/tiki-capture-receipt-capacitor", - "version": "0.2.0", + "version": "0.2.2", "license": "MIT", "devDependencies": { "@capacitor/android": "^5.2.2", @@ -62,7 +62,7 @@ "@ionic/prettier-config": "^4.0.0", "@ionic/swiftlint-config": "^1.1.2", "@typescript-eslint/eslint-plugin": "^6.3.0", - "eslint": "^7.32.0", + "eslint": "^8.47.0", "prettier": "~3.0.1", "prettier-plugin-java": "~2.2.0", "rimraf": "^5.0.1", diff --git a/package.json b/package.json index 2c51d5ae..1ce696b6 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,8 @@ }, "scripts": { "build": "rimraf dist && vue-tsc --declaration --emitDeclarationOnly; vite build", - "example:android": "npm run build && cd example && npm run build-only && npx cap run android" + "example:android": "npm run build && cd example && npm run build-only && npx cap run android", + "build:locally" : "cd .. && cd tiki-capture-receipt-capacitor && npm install && npm run verify:android && npm run build && cd example && npm run build && cd ../.. && cd tiki-receipt-capacitor && npm install && cd example && npm install && cd .. && npm run example:android" }, "keywords": [], "author": "", diff --git a/src/service/receipt/receipt-service.ts b/src/service/receipt/receipt-service.ts index 5f6a773f..e08f624d 100644 --- a/src/service/receipt/receipt-service.ts +++ b/src/service/receipt/receipt-service.ts @@ -147,9 +147,8 @@ export class ReceiptService { orders = async (account: ReceiptAccount): Promise =>{ - const orders = await this.plugin.orders() - console.log(orders) - orders.forEach((order)=> this.addReceipt(order, account)) + const order = await this.plugin.orders() + this.addReceipt(order.scan) } /** @@ -159,10 +158,10 @@ export class ReceiptService { (await this.plugin.retailers()).forEach((retailer=> this.addAccount({ username: retailer.username, - type: retailer.retailer, + type: retailer.provider, verified: retailer.isVerified, - icon: icon(retailer.retailer), - provider: retailer.retailer + icon: icon(retailer.provider), + provider: retailer.provider }) )); (await this.plugin.verifyEmail()).forEach((account) => From 2a88d5fe84a8cb7c88088dc5bcca2c4f04a5ac0d Mon Sep 17 00:00:00 2001 From: Mike Audi Date: Thu, 17 Aug 2023 03:12:55 -0500 Subject: [PATCH 10/12] fix: use record timestamps --- example/ios/App/Podfile.lock | 8 +- example/package-lock.json | 30 +- example/package.json | 4 +- package-lock.json | 26 +- package.json | 8 +- src/service/history/history-event.ts | 4 +- src/service/receipt/receipt-account-type.ts | 696 +++++++++++++++----- src/service/receipt/receipt-service.ts | 68 +- src/service/tiki-service.ts | 15 +- 9 files changed, 623 insertions(+), 236 deletions(-) diff --git a/example/ios/App/Podfile.lock b/example/ios/App/Podfile.lock index 3f7b63bd..a14a334d 100644 --- a/example/ios/App/Podfile.lock +++ b/example/ios/App/Podfile.lock @@ -2,9 +2,9 @@ PODS: - Capacitor (5.2.3): - CapacitorCordova - CapacitorCordova (5.2.3) - - MytikiTikiCaptureReceiptCapacitor (0.2.6): + - MytikiTikiCaptureReceiptCapacitor (0.3.0): - Capacitor - - MytikiTikiSdkCapacitor (0.3.0): + - MytikiTikiSdkCapacitor (0.3.1): - Capacitor DEPENDENCIES: @@ -26,8 +26,8 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: Capacitor: 6f44cbc33839b8a4202b8eac97041fe584083417 CapacitorCordova: 35def3ebfdef491f0a7b652816eb873ff4b20bbf - MytikiTikiCaptureReceiptCapacitor: f2c39fcd7289674b51b4c4eb139461e56b9b3a6d - MytikiTikiSdkCapacitor: a2c4dcd954f2f8e4fec9fa21aea8cbad58a8f0f6 + MytikiTikiCaptureReceiptCapacitor: 33e80ff6f86c5c93998d9da1f84f0096a56d1721 + MytikiTikiSdkCapacitor: 7fb71c6099dd3bba5c75ee7ec1dd30bd90c78c9c PODFILE CHECKSUM: 2f9a0f322694e9fc6ea5b4ef01d7ecdb29338094 diff --git a/example/package-lock.json b/example/package-lock.json index 24260e25..968b36a8 100644 --- a/example/package-lock.json +++ b/example/package-lock.json @@ -12,9 +12,9 @@ "@capacitor/android": "^5.2.3", "@capacitor/core": "^5.2.3", "@capacitor/ios": "^5.2.3", - "@mytiki/tiki-capture-receipt-capacitor": "^0.2.6", + "@mytiki/tiki-capture-receipt-capacitor": "^0.3.0", "@mytiki/tiki-receipt-capacitor": "file:..", - "@mytiki/tiki-sdk-capacitor": "^0.3.0", + "@mytiki/tiki-sdk-capacitor": "^0.3.1", "uuid": "^9.0.0", "vue": "^3.3.4" }, @@ -41,8 +41,8 @@ "version": "0.1.2", "license": "MIT", "dependencies": { - "@mytiki/tiki-capture-receipt-capacitor": "^0.2.6", - "@mytiki/tiki-sdk-capacitor": "^0.3.0", + "@mytiki/tiki-capture-receipt-capacitor": "^0.3.0", + "@mytiki/tiki-sdk-capacitor": "^0.3.1", "hammerjs": "^2.0.8", "vue": "^3.3.4", "vue-confetti-explosion": "^1.0.2", @@ -77,8 +77,8 @@ "@capacitor/android": "^5.2.2", "@capacitor/core": "^5.2.2", "@capacitor/ios": "^5.2.2", - "@mytiki/tiki-capture-receipt-capacitor": "^0.2.6", - "@mytiki/tiki-sdk-capacitor": "^0.3.0" + "@mytiki/tiki-capture-receipt-capacitor": "^0.3.0", + "@mytiki/tiki-sdk-capacitor": "^0.3.1" } }, "node_modules/@aashutoshrathi/word-wrap": { @@ -728,9 +728,9 @@ "integrity": "sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==" }, "node_modules/@mytiki/tiki-capture-receipt-capacitor": { - "version": "0.2.6", - "resolved": "https://registry.npmjs.org/@mytiki/tiki-capture-receipt-capacitor/-/tiki-capture-receipt-capacitor-0.2.6.tgz", - "integrity": "sha512-Ti6QtIFX5r5eGS5Jf1cis7IUZQpaC4ULcDRLvgaQkwSUgCf2G4X/uv++wif/CJ8fq/h2sU3ez/hJg2AIBXIEfg==", + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/@mytiki/tiki-capture-receipt-capacitor/-/tiki-capture-receipt-capacitor-0.3.0.tgz", + "integrity": "sha512-eR+kpD+/60ykcB5cm6TG0WCWKcf7R+wkHBSEeA1uQd2m3zLXj2CSq96hmb5t2WnOGRkddOd49lq/jsJTNkKVRQ==", "peerDependencies": { "@capacitor/core": "^5.0.0" } @@ -740,9 +740,9 @@ "link": true }, "node_modules/@mytiki/tiki-sdk-capacitor": { - "version": "0.3.0", - "resolved": "https://registry.npmjs.org/@mytiki/tiki-sdk-capacitor/-/tiki-sdk-capacitor-0.3.0.tgz", - "integrity": "sha512-e5QkBwHXBgQTuvtUidBgMCIWMpzxGBnE3raZ/qss/XCKobjQw+qo2OPraJTZm+VNm6UNJe53/daIZ1gxoXmlCA==", + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/@mytiki/tiki-sdk-capacitor/-/tiki-sdk-capacitor-0.3.1.tgz", + "integrity": "sha512-Y4waq6Jo5HewmYBs91P90PLgPz/04z0y5oRimO6LgQTPs9ZkDBg+sQzD32IuuCh+Ar6JyUF3WHWqd775SPo0ug==", "peerDependencies": { "@capacitor/core": "^5.2.2" } @@ -1072,9 +1072,9 @@ } }, "node_modules/@vitejs/plugin-vue": { - "version": "4.2.3", - "resolved": "https://registry.npmjs.org/@vitejs/plugin-vue/-/plugin-vue-4.2.3.tgz", - "integrity": "sha512-R6JDUfiZbJA9cMiguQ7jxALsgiprjBeHL5ikpXfJCH62pPHtI+JdJ5xWj6Ev73yXSlYl86+blXn1kZHQ7uElxw==", + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/@vitejs/plugin-vue/-/plugin-vue-4.3.0.tgz", + "integrity": "sha512-EvZ4KZGzf9G9Ir593f2hmQFJNPrLeC6XSzqvLJXWr6uTDAA1IyhB3ZVDhmqQ7jYx186ABddHLYoVqN9Eb9GGgg==", "dev": true, "engines": { "node": "^14.18.0 || >=16.0.0" diff --git a/example/package.json b/example/package.json index a057802e..2926c137 100644 --- a/example/package.json +++ b/example/package.json @@ -16,9 +16,9 @@ "@capacitor/android": "^5.2.3", "@capacitor/core": "^5.2.3", "@capacitor/ios": "^5.2.3", - "@mytiki/tiki-capture-receipt-capacitor": "^0.2.6", + "@mytiki/tiki-capture-receipt-capacitor": "^0.3.0", "@mytiki/tiki-receipt-capacitor": "file:..", - "@mytiki/tiki-sdk-capacitor": "^0.3.0", + "@mytiki/tiki-sdk-capacitor": "^0.3.1", "uuid": "^9.0.0", "vue": "^3.3.4" }, diff --git a/package-lock.json b/package-lock.json index a5fcfc27..427749ac 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,8 +9,8 @@ "version": "0.1.2", "license": "MIT", "dependencies": { - "@mytiki/tiki-capture-receipt-capacitor": "^0.2.6", - "@mytiki/tiki-sdk-capacitor": "^0.3.0", + "@mytiki/tiki-capture-receipt-capacitor": "^0.3.0", + "@mytiki/tiki-sdk-capacitor": "^0.3.1", "hammerjs": "^2.0.8", "vue": "^3.3.4", "vue-confetti-explosion": "^1.0.2", @@ -45,8 +45,8 @@ "@capacitor/android": "^5.2.2", "@capacitor/core": "^5.2.2", "@capacitor/ios": "^5.2.2", - "@mytiki/tiki-capture-receipt-capacitor": "^0.2.6", - "@mytiki/tiki-sdk-capacitor": "^0.3.0" + "@mytiki/tiki-capture-receipt-capacitor": "^0.3.0", + "@mytiki/tiki-sdk-capacitor": "^0.3.1" } }, "node_modules/@aashutoshrathi/word-wrap": { @@ -690,17 +690,17 @@ } }, "node_modules/@mytiki/tiki-capture-receipt-capacitor": { - "version": "0.2.6", - "resolved": "https://registry.npmjs.org/@mytiki/tiki-capture-receipt-capacitor/-/tiki-capture-receipt-capacitor-0.2.6.tgz", - "integrity": "sha512-Ti6QtIFX5r5eGS5Jf1cis7IUZQpaC4ULcDRLvgaQkwSUgCf2G4X/uv++wif/CJ8fq/h2sU3ez/hJg2AIBXIEfg==", + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/@mytiki/tiki-capture-receipt-capacitor/-/tiki-capture-receipt-capacitor-0.3.0.tgz", + "integrity": "sha512-eR+kpD+/60ykcB5cm6TG0WCWKcf7R+wkHBSEeA1uQd2m3zLXj2CSq96hmb5t2WnOGRkddOd49lq/jsJTNkKVRQ==", "peerDependencies": { "@capacitor/core": "^5.0.0" } }, "node_modules/@mytiki/tiki-sdk-capacitor": { - "version": "0.3.0", - "resolved": "https://registry.npmjs.org/@mytiki/tiki-sdk-capacitor/-/tiki-sdk-capacitor-0.3.0.tgz", - "integrity": "sha512-e5QkBwHXBgQTuvtUidBgMCIWMpzxGBnE3raZ/qss/XCKobjQw+qo2OPraJTZm+VNm6UNJe53/daIZ1gxoXmlCA==", + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/@mytiki/tiki-sdk-capacitor/-/tiki-sdk-capacitor-0.3.1.tgz", + "integrity": "sha512-Y4waq6Jo5HewmYBs91P90PLgPz/04z0y5oRimO6LgQTPs9ZkDBg+sQzD32IuuCh+Ar6JyUF3WHWqd775SPo0ug==", "peerDependencies": { "@capacitor/core": "^5.2.2" } @@ -1127,9 +1127,9 @@ } }, "node_modules/@vitejs/plugin-vue": { - "version": "4.2.3", - "resolved": "https://registry.npmjs.org/@vitejs/plugin-vue/-/plugin-vue-4.2.3.tgz", - "integrity": "sha512-R6JDUfiZbJA9cMiguQ7jxALsgiprjBeHL5ikpXfJCH62pPHtI+JdJ5xWj6Ev73yXSlYl86+blXn1kZHQ7uElxw==", + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/@vitejs/plugin-vue/-/plugin-vue-4.3.0.tgz", + "integrity": "sha512-EvZ4KZGzf9G9Ir593f2hmQFJNPrLeC6XSzqvLJXWr6uTDAA1IyhB3ZVDhmqQ7jYx186ABddHLYoVqN9Eb9GGgg==", "dev": true, "engines": { "node": "^14.18.0 || >=16.0.0" diff --git a/package.json b/package.json index 05e22ede..0e477c56 100644 --- a/package.json +++ b/package.json @@ -23,8 +23,8 @@ "author": "", "license": "MIT", "dependencies": { - "@mytiki/tiki-capture-receipt-capacitor": "^0.2.6", - "@mytiki/tiki-sdk-capacitor": "^0.3.0", + "@mytiki/tiki-capture-receipt-capacitor": "^0.3.0", + "@mytiki/tiki-sdk-capacitor": "^0.3.1", "hammerjs": "^2.0.8", "vue": "^3.3.4", "vue-confetti-explosion": "^1.0.2", @@ -59,7 +59,7 @@ "@capacitor/android": "^5.2.2", "@capacitor/core": "^5.2.2", "@capacitor/ios": "^5.2.2", - "@mytiki/tiki-capture-receipt-capacitor": "^0.2.6", - "@mytiki/tiki-sdk-capacitor": "^0.3.0" + "@mytiki/tiki-capture-receipt-capacitor": "^0.3.0", + "@mytiki/tiki-sdk-capacitor": "^0.3.1" } } diff --git a/src/service/history/history-event.ts b/src/service/history/history-event.ts index dc50bf60..2e7a401e 100644 --- a/src/service/history/history-event.ts +++ b/src/service/history/history-event.ts @@ -137,7 +137,7 @@ export class HistoryEvent { return new HistoryEvent( payable.description, Number(payable.amount), - new Date(), + payable.timestamp != undefined ? new Date(payable.timestamp) : new Date(), type, ); } @@ -151,7 +151,7 @@ export class HistoryEvent { return new HistoryEvent( receipt.description ?? HistoryEvent.REDEEM_NAME_POSTFIX, Number(receipt.amount), - new Date(), + receipt.timestamp != undefined ? new Date(receipt.timestamp) : new Date(), ReceiptEvent.REDEEM, ); } diff --git a/src/service/receipt/receipt-account-type.ts b/src/service/receipt/receipt-account-type.ts index 86dccf13..1bb52395 100644 --- a/src/service/receipt/receipt-account-type.ts +++ b/src/service/receipt/receipt-account-type.ts @@ -3,76 +3,391 @@ * MIT license. See LICENSE file in root directory. */ +import AcmeIcon from "@/assets/images/acme.png"; +import AlbertsonsIcon from "@/assets/images/albertsons.png"; +import AmazonIcon from "@/assets/images/amazon.png"; +import AolIcon from "@/assets/images/aol.png"; +import BedBathAndBeyondIcon from "@/assets/images/bed-bath-beyond.png"; +import BestBuyIcon from "@/assets/images/best-buy.png"; +import BJsIcon from "@/assets/images/bjs.png"; +import ChewyIcon from "@/assets/images/chewy.png"; +import CostcoIcon from "@/assets/images/costco.png"; +import CVSIcon from "@/assets/images/cvs.png"; +import DicksIcon from "@/assets/images/dicks.png"; +import DollarGeneralIcon from "@/assets/images/dollar-general.png"; +import DollarTreeIcon from "@/assets/images/dollar-tree.png"; +import DominosIcon from "@/assets/images/dominos.png"; +import DoorDashIcon from "@/assets/images/door-dash.png"; +import DrizlyIcon from "@/assets/images/drizly.png"; +import FamilyDollarIcon from "@/assets/images/family-dollar.png"; +import Food4LessIcon from "@/assets/images/food-4-less.png"; +import FoodLionIcon from "@/assets/images/food-lion.png"; +import FredMeyerIcon from "@/assets/images/fred-meyer.png"; +import GapIcon from "@/assets/images/gap.png"; +import GiantEagleIcon from "@/assets/images/giant-eagle.png"; import GmailIcon from "@/assets/images/gmail.png"; +import GrubHubIcon from "@/assets/images/grubhub.png"; +import HarrisTeeterIcon from "@/assets/images/harris-teeter.png"; +import HEBIcon from "@/assets/images/heb.png"; +import HomeDepotIcon from "@/assets/images/home-depot.png"; +import HyVeeIcon from "@/assets/images/hy-vee.png"; +import InstacartIcon from "@/assets/images/instacart.png"; +import JewelOscoIcon from "@/assets/images/jewel-osco.png"; +import KohlsIcon from "@/assets/images/kohls.png"; +import KrogerIcon from "@/assets/images/kroger.png"; +import LowesIcon from "@/assets/images/lowes.png"; +import MacysIcon from "@/assets/images/macys.png"; +import MarshallsIcon from "@/assets/images/marshalls.png"; +import MeijerIcon from "@/assets/images/meijer.png"; +import NikeIcon from "@/assets/images/nike.png"; +import OutlookIcon from "@/assets/images/outlook.png"; +import PublixIcon from "@/assets/images/publix.png"; +import RalphsIcon from "@/assets/images/ralphs.png"; +import RiteAidIcon from "@/assets/images/rite-aid.png"; +import SafewayIcon from "@/assets/images/safeway.png"; +import SamsClubIcon from "@/assets/images/sams-club.png"; +import SeamlessIcon from "@/assets/images/seamless.png"; +import SephoraIcon from "@/assets/images/sephora.png"; +import ShiptIcon from "@/assets/images/shipt.png"; +import ShopRiteIcon from "@/assets/images/shop-rite.png"; +import SproutsIcon from "@/assets/images/sprouts.png"; +import StaplesIcon from "@/assets/images/staples.png"; +import StaplesCanadaIcon from "@/assets/images/staples-canada.png"; +import StarbucksIcon from "@/assets/images/starbucks.png"; +import TacoBellIcon from "@/assets/images/tacobell.png"; +import TargetIcon from "@/assets/images/target.png"; +import TJMaxxIcon from "@/assets/images/tj-maxx.png"; +import UberEatsIcon from "@/assets/images/uber-eats.png"; +import UltaIcon from "@/assets/images/ulta.png"; +import VonsIcon from "@/assets/images/vons.png"; +import WalgreensIcon from "@/assets/images/walgreens.png"; +import WalmartIcon from "@/assets/images/walmart.png"; +import WalmartCanadaIcon from "@/assets/images/walmart-canada.png"; +import WegmansIcon from "@/assets/images/wegmans.png"; +import YahooIcon from "@/assets/images/yahoo.png"; + import { AccountProvider } from "@mytiki/tiki-capture-receipt-capacitor"; /** * Enumeration of the supported account types. */ export enum ReceiptAccountType { - // ACME = "ACME", - // ALBERTSONS = "Albertsons", - // AMAZON = "Amazon", - // AOL = "AOL", - // BBB = "Bed Bath & Beyond", + /** + * ACME Markets account type. + */ + ACME_MARKETS = "ACME", + + /** + * Albertsons account type. + */ + ALBERTSONS = "Albertsons", + + /** + * Amazon account type. + */ + AMAZON = "Amazon", + + /** + * Amazon Canada account type. + */ + AMAZON_CA = "Amazon Canada", + + /** + * Amazon United Kingdom account type. + */ + AMAZON_UK = "Amazon United Kingdom", + + /** + * AOL account type. + */ + AOL = "AOL", + + /** + * Bed Bath & Beyond account type. + */ + BED_BATH_AND_BEYOND = "Bed Bath & Beyond", + /** * Gmail account type. */ GMAIL = "Gmail", - // BEST_BUY = "Best Buy", - // BJS = "BJ’s Wholesale Club", - // CHEWY = "Chewy", - // COSTCO = "Costco", - // CVS = "CVS", - // DICKS = "Dick’s Sporting Goods", - // DOLLAR_GENERAL = "Dollar General", - // DOLLAR_TREE = "DollarTree", - // DOMINOS = "Domino’s Pizza", - // DOOR_DASH = "DoorDash", - // DRIZLY = "Drizly", - // FAMILY_DOLLAR = "Family Dollar", - // FOOD_4_LESS = "Food 4 Less", - // FOOD_LION = "Food Lion", - // FRED_MEYER = "Fred Meyer", - // GAP = "GAP", - // GIANT_EAGLE = "Giant Eagle", - // GRUBHUB = "Grubhub", - // HARRIS_TEETER = "Harris Teeter", - // HEB = "H.E.B", - // HOME_DEPOT = "Home Depot", - // HY_VEE = "HyVee", - // INSTACART = "Instacart", - // JEWEL_OSCO = "Jewel Osco", - // KOHLS = "Kohl’s", - // KROGER = "Kroger", - // LOWES = "Lowe’s", - // MACYS = "Macy’s", - // MARSHALLS = "Marshalls", - // MEIJER = "Meijer", - // NIKE = "Nike", - // PUBLIX = "Publix", - // RALPHS = "Ralphs", - // RITE_AID = "RiteAid", - // SAFEWAY = "Safeway", - // SAMS_CLUB = "Sam’s Club", - // SEAMLESS = "Seamless", - // SEPHORA = "Sephora", - // SHIPT = "Shipt", - // SHOP_RITE = "ShopRite", - // SPROUTS = "Sprouts", - // STAPLES = "Staples", - // STAPLES_CANADA = "Staples Canada", - // STARBUCKS = "Starbucks", - // TACO_BELL = "Taco Bell", - // TARGET = "Target", - // TJ_MAXX = "T.J.Maxx", - // UBER_EATS = "UberEats", - // ULTA = "Ulta", - // VONS = "Vons", - // WALGREENS = "Walgreens", - // WALMART = "Walmart", - // WALMART_CANADA = "Walmart Canada", - // WEGMANS = "Wegman’s", + + /** + * Best Buy account type. + */ + BESTBUY = "Best Buy", + + /** + * BJ’s Wholesale Club account type. + */ + BJS_WHOLESALE = "BJ’s Wholesale Club", + + /** + * Chewy account type. + */ + CHEWY = "Chewy", + + /** + * Costco account type. + */ + COSTCO = "Costco", + + /** + * CVS account type. + */ + CVS = "CVS", + + /** + * Dick’s Sporting Goods account type. + */ + DICKS_SPORTING_GOODS = "Dick’s Sporting Goods", + + /** + * Dollar General account type. + */ + DOLLAR_GENERAL = "Dollar General", + + /** + * DollarTree account type. + */ + DOLLAR_TREE = "DollarTree", + + /** + * Domino’s Pizza account type. + */ + DOMINOS_PIZZA = "Domino’s Pizza", + + /** + * DoorDash account type. + */ + DOOR_DASH = "DoorDash", + + /** + * Drizly account type. + */ + DRIZLY = "Drizly", + + /** + * Family Dollar account type. + */ + FAMILY_DOLLAR = "Family Dollar", + /** + * Food 4 Less account type. + */ + FOOD_4_LESS = "Food 4 Less", + + /** + * Food Lion account type. + */ + FOOD_LION = "Food Lion", + + /** + * Fred Meyer account type. + */ + FRED_MEYER = "Fred Meyer", + + /** + * GAP account type. + */ + GAP = "GAP", + + /** + * Giant Eagle account type. + */ + GIANT_EAGLE = "Giant Eagle", + + /** + * Grubhub account type. + */ + GRUBHUB = "Grubhub", + + /** + * Harris Teeter account type. + */ + HARRIS_TEETER = "Harris Teeter", + + /** + * H.E.B account type. + */ + HEB = "H.E.B", + + /** + * Home Depot account type. + */ + HOME_DEPOT = "Home Depot", + + /** + * HyVee account type. + */ + HYVEE = "HyVee", + + /** + * Instacart account type. + */ + INSTACART = "Instacart", + + /** + * Jewel Osco account type. + */ + JEWEL_OSCO = "Jewel Osco", + + /** + * Kohl’s account type. + */ + KOHLS = "Kohl’s", + + /** + * Kroger account type. + */ + KROGER = "Kroger", + + /** + * Lowe’s account type. + */ + LOWES = "Lowe’s", + + /** + * Macy’s account type. + */ + MACYS = "Macy’s", + + /** + * Marshalls account type. + */ + MARSHALLS = "Marshalls", + + /** + * Meijer account type. + */ + MEIJER = "Meijer", + + /** + * Nike account type. + */ + NIKE = "Nike", + /** + * Microsoft Outlook account type. + */ + OUTLOOK = "Outlook", + + /** + * Publix account type. + */ + PUBLIX = "Publix", + + /** + * Ralphs account type. + */ + RALPHS = "Ralphs", + + /** + * RiteAid account type. + */ + RITE_AID = "RiteAid", + + /** + * Safeway account type. + */ + SAFEWAY = "Safeway", + + /** + * Sam’s Club account type. + */ + SAMS_CLUB = "Sam’s Club", + + /** + * Seamless account type. + */ + SEAMLESS = "Seamless", + + /** + * Sephora account type. + */ + SEPHORA = "Sephora", + + /** + * Shipt account type. + */ + SHIPT = "Shipt", + + /** + * ShopRite account type. + */ + SHOPRITE = "ShopRite", + + /** + * Sprouts account type. + */ + SPROUTS = "Sprouts", + + /** + * Staples account type. + */ + STAPLES = "Staples", + + /** + * Staples Canada account type. + */ + STAPLES_CA = "Staples Canada", + + /** + * Starbucks account type. + */ + STARBUCKS = "Starbucks", + + /** + * Taco Bell account type. + */ + TACO_BELL = "Taco Bell", + + /** + * Target account type. + */ + TARGET = "Target", + + /** + * T.J.Maxx account type. + */ + TJ_MAXX = "T.J.Maxx", + + /** + * UberEats account type. + */ + UBER_EATS = "UberEats", + + /** + * Ulta account type. + */ + ULTA = "Ulta", + + /** + * Vons account type. + */ + VONS = "Vons", + /** + * Walgreens account type. + */ + WALGREENS = "Walgreens", + + /** + * Walmart account type. + */ + WALMART = "Walmart", + + /** + * Walmart Canada account type. + */ + WALMART_CA = "Walmart Canada", + + /** + * Wegman’s account type. + */ + WEGMANS = "Wegman’s", + + /** + * Yahoo account type. + */ + YAHOO = "Yahoo", } /** @@ -85,6 +400,11 @@ export const all: Map = new Map( ), ); +export const toString = (type: string): string => { + return Object.keys(ReceiptAccountType) + .find((val) => type.toLowerCase() === val.toLowerCase())! + .toLowerCase(); +}; /** * Gets the icon (image src) associated with a {@link ReceiptAccountType}. * @param type - The receipt account type. @@ -92,129 +412,141 @@ export const all: Map = new Map( * @throws Error if the receipt account type is not supported. */ export const icon = (type: ReceiptAccountType): string => { - switch (type) { - // case ReceiptAccountType.ACME: - // return AcmeIcon; - // case ReceiptAccountType.ALBERTSONS: - // return AlbertsonsIcon; - // case ReceiptAccountType.AMAZON: - // return AmazonIcon; - // case ReceiptAccountType.AOL: - // return AolIcon; - // case ReceiptAccountType.BBB: - // return BedBathBeyondIcon; - // case ReceiptAccountType.BEST_BUY: - // return BestBuyIcon; - // case ReceiptAccountType.BJS: - // return BJSIcon; - // case ReceiptAccountType.CHEWY: - // return ChewyIcon; - // case ReceiptAccountType.COSTCO: - // return CostcoIcon; - // case ReceiptAccountType.CVS: - // return CVSIcon; - // case ReceiptAccountType.DICKS: - // return DicksIcon; - // case ReceiptAccountType.DOLLAR_GENERAL: - // return DollarGeneralIcon; - // case ReceiptAccountType.DOLLAR_TREE: - // return DollarTreeIcon; - // case ReceiptAccountType.DOMINOS: - // return DominosIcon; - // case ReceiptAccountType.DOOR_DASH: - // return DoorDashIcon; - // case ReceiptAccountType.DRIZLY: - // return DrizlyIcon; - // case ReceiptAccountType.FAMILY_DOLLAR: - // return FamilyDollarIcon; - // case ReceiptAccountType.FOOD_4_LESS: - // return Food4LessIcon; - // case ReceiptAccountType.FOOD_LION: - // return FoodLionIcon; - // case ReceiptAccountType.FRED_MEYER: - // return FredMeyerIcon; - // case ReceiptAccountType.GAP: - // return GapIcon; - // case ReceiptAccountType.GIANT_EAGLE: - // return GiantEagleIcon; + const retailer = Object.values(ReceiptAccountType).find( + (retailer) => type.toLowerCase() === retailer.toLowerCase(), + ); + switch (retailer) { + case ReceiptAccountType.ACME_MARKETS: + return AcmeIcon; + case ReceiptAccountType.ALBERTSONS: + return AlbertsonsIcon; + case ReceiptAccountType.AMAZON: + return AmazonIcon; + case ReceiptAccountType.AMAZON_CA: + return AmazonIcon; + case ReceiptAccountType.AMAZON_UK: + return AmazonIcon; + case ReceiptAccountType.AOL: + return AolIcon; + case ReceiptAccountType.BED_BATH_AND_BEYOND: + return BedBathAndBeyondIcon; + case ReceiptAccountType.BESTBUY: + return BestBuyIcon; + case ReceiptAccountType.BJS_WHOLESALE: + return BJsIcon; + case ReceiptAccountType.CHEWY: + return ChewyIcon; + case ReceiptAccountType.COSTCO: + return CostcoIcon; + case ReceiptAccountType.CVS: + return CVSIcon; + case ReceiptAccountType.DICKS_SPORTING_GOODS: + return DicksIcon; + case ReceiptAccountType.DOLLAR_GENERAL: + return DollarGeneralIcon; + case ReceiptAccountType.DOLLAR_TREE: + return DollarTreeIcon; + case ReceiptAccountType.DOMINOS_PIZZA: + return DominosIcon; + case ReceiptAccountType.DOOR_DASH: + return DoorDashIcon; + case ReceiptAccountType.DRIZLY: + return DrizlyIcon; + case ReceiptAccountType.FAMILY_DOLLAR: + return FamilyDollarIcon; + case ReceiptAccountType.FOOD_4_LESS: + return Food4LessIcon; + case ReceiptAccountType.FOOD_LION: + return FoodLionIcon; + case ReceiptAccountType.FRED_MEYER: + return FredMeyerIcon; + case ReceiptAccountType.GAP: + return GapIcon; + case ReceiptAccountType.GIANT_EAGLE: + return GiantEagleIcon; case ReceiptAccountType.GMAIL: return GmailIcon; - // case ReceiptAccountType.GRUBHUB: - // return GrubHubIcon; - // case ReceiptAccountType.HARRIS_TEETER: - // return HarrisTeeterIcon; - // case ReceiptAccountType.HEB: - // return HEBIcon; - // case ReceiptAccountType.HOME_DEPOT: - // return HomeDepotIcon; - // case ReceiptAccountType.HY_VEE: - // return HyVeeIcon; - // case ReceiptAccountType.INSTACART: - // return InstacartIcon; - // case ReceiptAccountType.JEWEL_OSCO: - // return JewelOscoIcon; - // case ReceiptAccountType.KOHLS: - // return KohlsIcon; - // case ReceiptAccountType.KROGER: - // return KrogerIcon; - // case ReceiptAccountType.LOWES: - // return LowesIcon; - // case ReceiptAccountType.MACYS: - // return MacysIcon; - // case ReceiptAccountType.MARSHALLS: - // return MarshallsIcon; - // case ReceiptAccountType.MEIJER: - // return MeijerIcon; - // case ReceiptAccountType.NIKE: - // return NikeIcon; - // case ReceiptAccountType.PUBLIX: - // return PublixIcon; - // case ReceiptAccountType.RALPHS: - // return RalphsIcon; - // case ReceiptAccountType.RITE_AID: - // return RiteAidIcon; - // case ReceiptAccountType.SAFEWAY: - // return SafewayIcon; - // case ReceiptAccountType.SAMS_CLUB: - // return SamsClubIcon; - // case ReceiptAccountType.SEAMLESS: - // return SeamlessIcon; - // case ReceiptAccountType.SEPHORA: - // return SephoraIcon; - // case ReceiptAccountType.SHIPT: - // return ShiptIcon; - // case ReceiptAccountType.SHOP_RITE: - // return ShopRiteIcon; - // case ReceiptAccountType.SPROUTS: - // return SproutsIcon; - // case ReceiptAccountType.STAPLES: - // return StaplesIcon; - // case ReceiptAccountType.STAPLES_CANADA: - // return StaplesCanadaIcon; - // case ReceiptAccountType.STARBUCKS: - // return StarbucksIcon; - // case ReceiptAccountType.TACO_BELL: - // return TacoBellIcon; - // case ReceiptAccountType.TARGET: - // return TargetIcon; - // case ReceiptAccountType.TJ_MAXX: - // return TJMaxxIcon; - // case ReceiptAccountType.UBER_EATS: - // return UberEatsIcon; - // case ReceiptAccountType.ULTA: - // return UltaIcon; - // case ReceiptAccountType.VONS: - // return VonsIcon; - // case ReceiptAccountType.WALGREENS: - // return WalgreensIcon; - // case ReceiptAccountType.WALMART: - // return WalmartIcon; - // case ReceiptAccountType.WALMART_CANADA: - // return WalmartCanadaIcon; - // case ReceiptAccountType.WEGMANS: - // return WegmansIcon; + case ReceiptAccountType.GRUBHUB: + return GrubHubIcon; + case ReceiptAccountType.HARRIS_TEETER: + return HarrisTeeterIcon; + case ReceiptAccountType.HEB: + return HEBIcon; + case ReceiptAccountType.HOME_DEPOT: + return HomeDepotIcon; + case ReceiptAccountType.HYVEE: + return HyVeeIcon; + case ReceiptAccountType.INSTACART: + return InstacartIcon; + case ReceiptAccountType.JEWEL_OSCO: + return JewelOscoIcon; + case ReceiptAccountType.KOHLS: + return KohlsIcon; + case ReceiptAccountType.KROGER: + return KrogerIcon; + case ReceiptAccountType.LOWES: + return LowesIcon; + case ReceiptAccountType.MACYS: + return MacysIcon; + case ReceiptAccountType.MARSHALLS: + return MarshallsIcon; + case ReceiptAccountType.MEIJER: + return MeijerIcon; + case ReceiptAccountType.NIKE: + return NikeIcon; + case ReceiptAccountType.OUTLOOK: + return OutlookIcon; + case ReceiptAccountType.PUBLIX: + return PublixIcon; + case ReceiptAccountType.RALPHS: + return RalphsIcon; + case ReceiptAccountType.RITE_AID: + return RiteAidIcon; + case ReceiptAccountType.SAFEWAY: + return SafewayIcon; + case ReceiptAccountType.SAMS_CLUB: + return SamsClubIcon; + case ReceiptAccountType.SEAMLESS: + return SeamlessIcon; + case ReceiptAccountType.SEPHORA: + return SephoraIcon; + case ReceiptAccountType.SHIPT: + return ShiptIcon; + case ReceiptAccountType.SHOPRITE: + return ShopRiteIcon; + case ReceiptAccountType.SPROUTS: + return SproutsIcon; + case ReceiptAccountType.STAPLES: + return StaplesIcon; + case ReceiptAccountType.STAPLES_CA: + return StaplesCanadaIcon; + case ReceiptAccountType.STARBUCKS: + return StarbucksIcon; + case ReceiptAccountType.TACO_BELL: + return TacoBellIcon; + case ReceiptAccountType.TARGET: + return TargetIcon; + case ReceiptAccountType.TJ_MAXX: + return TJMaxxIcon; + case ReceiptAccountType.UBER_EATS: + return UberEatsIcon; + case ReceiptAccountType.ULTA: + return UltaIcon; + case ReceiptAccountType.VONS: + return VonsIcon; + case ReceiptAccountType.WALGREENS: + return WalgreensIcon; + case ReceiptAccountType.WALMART: + return WalmartIcon; + case ReceiptAccountType.WALMART_CA: + return WalmartCanadaIcon; + case ReceiptAccountType.WEGMANS: + return WegmansIcon; + case ReceiptAccountType.YAHOO: + return YahooIcon; default: - throw Error("Unsupported ReceiptAccountType"); + return ""; + //throw Error("Unsupported ReceiptAccountType"); } }; @@ -230,6 +562,12 @@ export const fromEmailProvider = ( switch (provider) { case AccountProvider.GMAIL: return ReceiptAccountType.GMAIL; + // case AccountProvider.AOL: + // return ReceiptAccountType.AOL; + // case AccountProvider.YAHOO: + // return ReceiptAccountType.YAHOO; + // case AccountProvider.OUTLOOK: + // return ReceiptAccountType.YAHOO; default: return undefined; } diff --git a/src/service/receipt/receipt-service.ts b/src/service/receipt/receipt-service.ts index b41e9ec0..517d36b6 100644 --- a/src/service/receipt/receipt-service.ts +++ b/src/service/receipt/receipt-service.ts @@ -97,12 +97,20 @@ export class ReceiptService { * @param account - The receipt account to log in. */ async login(account: ReceiptAccount): Promise { - await this.plugin.loginWithEmail( - account.username, - account.password!, - account.provider!, - ); - account.verified = true; + if (account.provider) { + await this.plugin.loginWithEmail( + account.username, + account.password!, + account.provider!, + ); + } else { + let accountSigned = await this.plugin.loginWithRetailer( + account.username, + account.password!, + toString(account.type!), + ); + if (accountSigned.isVerified) account.verified = true; + } this.addAccount(account); await this.process(ReceiptEvent.LINK, { account: account, @@ -114,11 +122,18 @@ export class ReceiptService { * @param account - The receipt account to log out. */ async logout(account: ReceiptAccount): Promise { - await this.plugin.removeEmail( - account.username, - account.password!, - account.provider!, - ); + if (account.type == "Gmail") { + await this.plugin.removeEmail( + account.username, + account.password!, + account.provider!, + ); + } else { + const removedRetailer = await this.plugin.removeRetailer( + account.username, + toString(account.type!), + ); + } this.removeAccount(account); await this.process(ReceiptEvent.UNLINK, { account: account, @@ -135,18 +150,41 @@ export class ReceiptService { receipts.forEach((receipt) => this.addReceipt(receipt, account)), ); + orders = async (): Promise => { + const order = await this.plugin.orders(); + this.addReceipt(order.scan); + }; + /** * Load and verify previously logged-in accounts. */ - load = async (): Promise => - (await this.plugin.verifyEmail()).forEach((account) => + load = async (): Promise => { + const retailAccounts = await this.plugin.retailers(); + retailAccounts.forEach((account) => + this.addAccount( + ReceiptAccount.fromValue( + account.username, + account.provider, + undefined, + account.isVerified, + ), + ), + ); + const emailAccounts = await this.plugin.verifyEmail(); + emailAccounts.forEach((account) => this.addAccount(ReceiptAccount.fromCapture(account)), ); + }; private addAccount(account: ReceiptAccount): void { this._accounts.push(account); - this._onAccountListeners.forEach((listener) => listener(account)); - this.scrape(); + if (account.type === "Gmail") { + this._onAccountListeners.forEach((listener) => listener(account)); + this.scrape(); + } else { + this._onAccountListeners.forEach((listener) => listener(account)); + this.orders(); + } } private removeAccount(account: ReceiptAccount): void { diff --git a/src/service/tiki-service.ts b/src/service/tiki-service.ts index 631a120e..98c34c9b 100644 --- a/src/service/tiki-service.ts +++ b/src/service/tiki-service.ts @@ -72,7 +72,18 @@ export class TikiService { ); this._isInitialized = true; this.history.load(); - await this.receipt.load(); - await this.receipt.scrape(); + this.receipt.load(); + this.receipt.scrape(); + this.receipt.orders(); + } + + /** + * Logs the user out of all linked accounts and removes credentials + * from the local cache. + * @returns A Promise that resolves when the logout is complete. + */ + async logout(): Promise { + await this.receipt.plugin.flushEmail(); + await this.receipt.plugin.flushRetailer(); } } From fe3bfd7b5eb2675e17542b5bf80b94b26962a881 Mon Sep 17 00:00:00 2001 From: GH Action Date: Thu, 17 Aug 2023 08:15:47 +0000 Subject: [PATCH 11/12] version bump --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0e477c56..9809c57c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@mytiki/tiki-receipt-capacitor", - "version": "0.1.2", + "version": "0.2.0", "description": "pineapple", "files": [ "dist" From 50dc3bbd6099abdc13c2ff6d0243459a2c73b48e Mon Sep 17 00:00:00 2001 From: Mike Audi Date: Thu, 17 Aug 2023 03:32:05 -0500 Subject: [PATCH 12/12] fix: logout also remove currently unsupported accounts aol, yahoo, outlook --- example/android/capacitor.settings.gradle | 2 +- example/src/app.vue | 2 +- src/service/history/history-service.ts | 8 +++++++ src/service/receipt/receipt-account-type.ts | 24 ++++++++++----------- src/service/receipt/receipt-service.ts | 13 ++++++++++- src/service/tiki-service.ts | 4 ++-- 6 files changed, 36 insertions(+), 17 deletions(-) diff --git a/example/android/capacitor.settings.gradle b/example/android/capacitor.settings.gradle index 2d9a67bf..2ecf7654 100644 --- a/example/android/capacitor.settings.gradle +++ b/example/android/capacitor.settings.gradle @@ -3,7 +3,7 @@ include ':capacitor-android' project(':capacitor-android').projectDir = new File('../node_modules/@capacitor/android/capacitor') include ':mytiki-tiki-capture-receipt-capacitor' -project(':mytiki-tiki-capture-receipt-capacitor').projectDir = new File('../../../tiki-capture-receipt-capacitor/android') +project(':mytiki-tiki-capture-receipt-capacitor').projectDir = new File('../node_modules/@mytiki/tiki-capture-receipt-capacitor/android') include ':mytiki-tiki-sdk-capacitor' project(':mytiki-tiki-sdk-capacitor').projectDir = new File('../node_modules/@mytiki/tiki-sdk-capacitor/android') diff --git a/example/src/app.vue b/example/src/app.vue index 98f9199c..000958f4 100644 --- a/example/src/app.vue +++ b/example/src/app.vue @@ -11,7 +11,7 @@ import { v4 as uuidv4 } from "uuid"; const tiki: TikiService | undefined = inject("Tiki"); const id: string = uuidv4(); -tiki?.initialize(id); +tiki?.initialize(id).then(() => tiki?.logout()); const present = ref(false); diff --git a/src/service/history/history-service.ts b/src/service/history/history-service.ts index 4fa4adea..da7f619d 100644 --- a/src/service/history/history-service.ts +++ b/src/service/history/history-service.ts @@ -106,4 +106,12 @@ export class HistoryService { } } } + + /** + * Clears all in-mem history and balance totals + */ + clear = (): void => { + this._history = []; + this._total = 0; + }; } diff --git a/src/service/receipt/receipt-account-type.ts b/src/service/receipt/receipt-account-type.ts index 1bb52395..6af39736 100644 --- a/src/service/receipt/receipt-account-type.ts +++ b/src/service/receipt/receipt-account-type.ts @@ -6,7 +6,7 @@ import AcmeIcon from "@/assets/images/acme.png"; import AlbertsonsIcon from "@/assets/images/albertsons.png"; import AmazonIcon from "@/assets/images/amazon.png"; -import AolIcon from "@/assets/images/aol.png"; +//import AolIcon from "@/assets/images/aol.png"; import BedBathAndBeyondIcon from "@/assets/images/bed-bath-beyond.png"; import BestBuyIcon from "@/assets/images/best-buy.png"; import BJsIcon from "@/assets/images/bjs.png"; @@ -40,7 +40,7 @@ import MacysIcon from "@/assets/images/macys.png"; import MarshallsIcon from "@/assets/images/marshalls.png"; import MeijerIcon from "@/assets/images/meijer.png"; import NikeIcon from "@/assets/images/nike.png"; -import OutlookIcon from "@/assets/images/outlook.png"; +//import OutlookIcon from "@/assets/images/outlook.png"; import PublixIcon from "@/assets/images/publix.png"; import RalphsIcon from "@/assets/images/ralphs.png"; import RiteAidIcon from "@/assets/images/rite-aid.png"; @@ -64,7 +64,7 @@ import WalgreensIcon from "@/assets/images/walgreens.png"; import WalmartIcon from "@/assets/images/walmart.png"; import WalmartCanadaIcon from "@/assets/images/walmart-canada.png"; import WegmansIcon from "@/assets/images/wegmans.png"; -import YahooIcon from "@/assets/images/yahoo.png"; +//import YahooIcon from "@/assets/images/yahoo.png"; import { AccountProvider } from "@mytiki/tiki-capture-receipt-capacitor"; @@ -100,7 +100,7 @@ export enum ReceiptAccountType { /** * AOL account type. */ - AOL = "AOL", + // AOL = "AOL", /** * Bed Bath & Beyond account type. @@ -268,7 +268,7 @@ export enum ReceiptAccountType { /** * Microsoft Outlook account type. */ - OUTLOOK = "Outlook", + // OUTLOOK = "Outlook", /** * Publix account type. @@ -387,7 +387,7 @@ export enum ReceiptAccountType { /** * Yahoo account type. */ - YAHOO = "Yahoo", + // YAHOO = "Yahoo", } /** @@ -426,8 +426,8 @@ export const icon = (type: ReceiptAccountType): string => { return AmazonIcon; case ReceiptAccountType.AMAZON_UK: return AmazonIcon; - case ReceiptAccountType.AOL: - return AolIcon; + // case ReceiptAccountType.AOL: + // return AolIcon; case ReceiptAccountType.BED_BATH_AND_BEYOND: return BedBathAndBeyondIcon; case ReceiptAccountType.BESTBUY: @@ -494,8 +494,8 @@ export const icon = (type: ReceiptAccountType): string => { return MeijerIcon; case ReceiptAccountType.NIKE: return NikeIcon; - case ReceiptAccountType.OUTLOOK: - return OutlookIcon; + // case ReceiptAccountType.OUTLOOK: + // return OutlookIcon; case ReceiptAccountType.PUBLIX: return PublixIcon; case ReceiptAccountType.RALPHS: @@ -542,8 +542,8 @@ export const icon = (type: ReceiptAccountType): string => { return WalmartCanadaIcon; case ReceiptAccountType.WEGMANS: return WegmansIcon; - case ReceiptAccountType.YAHOO: - return YahooIcon; + // case ReceiptAccountType.YAHOO: + // return YahooIcon; default: return ""; //throw Error("Unsupported ReceiptAccountType"); diff --git a/src/service/receipt/receipt-service.ts b/src/service/receipt/receipt-service.ts index a6d2a195..e5417a09 100644 --- a/src/service/receipt/receipt-service.ts +++ b/src/service/receipt/receipt-service.ts @@ -99,6 +99,7 @@ export class ReceiptService { account.password!, account.provider!, ); + account.verified = true; } else { let accountSigned = await this.plugin.loginWithRetailer( account.username, @@ -145,7 +146,6 @@ export class ReceiptService { async (account: Capture.Account, receipts: Capture.Receipt[]) => receipts.forEach((receipt) => this.addReceipt(receipt, account)), ); - orders = async (): Promise => { const order = await this.plugin.orders(); @@ -173,6 +173,17 @@ export class ReceiptService { ); }; + /** + * Logs the user out of all linked accounts and removes credentials + * from the local cache. + * @returns A Promise that resolves when the logout is complete. + */ + logoutAll = async (): Promise => { + await this.plugin.flushRetailer(); + await this.plugin.flushEmail(); + this._accounts = []; + }; + private addAccount(account: ReceiptAccount): void { this._accounts.push(account); if (account.type === "Gmail") { diff --git a/src/service/tiki-service.ts b/src/service/tiki-service.ts index 98c34c9b..c9ca5eeb 100644 --- a/src/service/tiki-service.ts +++ b/src/service/tiki-service.ts @@ -83,7 +83,7 @@ export class TikiService { * @returns A Promise that resolves when the logout is complete. */ async logout(): Promise { - await this.receipt.plugin.flushEmail(); - await this.receipt.plugin.flushRetailer(); + await this.receipt.logoutAll(); + this.history.clear(); } }