From e87c8f25afaf1a68491d67e762db2d699c5eae13 Mon Sep 17 00:00:00 2001 From: Mike Audi Date: Mon, 2 Oct 2023 14:39:25 -0500 Subject: [PATCH 1/6] fix: add the publish sdk methods --- src/config/config.ts | 5 +- src/service/index.ts | 1 + .../service/publish/index.ts | 115 ++++++++---------- src/service/publish/publish-service.ts | 4 - src/service/tiki/index.ts | 19 ++- 5 files changed, 63 insertions(+), 81 deletions(-) rename bkup/sdk-service.ts => src/service/publish/index.ts (68%) delete mode 100644 src/service/publish/publish-service.ts diff --git a/src/config/config.ts b/src/config/config.ts index e44eb516..aff804a4 100644 --- a/src/config/config.ts +++ b/src/config/config.ts @@ -10,6 +10,7 @@ import type { Theme } from "@/config/theme"; import type { Key } from "@/config/key"; import type { Offer } from "@/config/offer"; import type { Options } from "@/config/options"; +import type { Usecase } from "@mytiki/tiki-sdk-capacitor"; export class Config { readonly theme?: Theme; @@ -17,7 +18,9 @@ export class Config { readonly terms: string = Terms; readonly learn: string = LearnMore; readonly callback: (total: number) => number | undefined; - + readonly tags: string[] = [""]; + readonly uses: Usecase[] = []; + readonly payableType: string = "cash"; readonly offer: Offer = { image: ProgramImage, description: diff --git a/src/service/index.ts b/src/service/index.ts index b3b7fc86..c442aa46 100644 --- a/src/service/index.ts +++ b/src/service/index.ts @@ -6,3 +6,4 @@ export * from "./tiki"; export * from "./store"; export * from "./capture"; +export * from "./publish"; diff --git a/bkup/sdk-service.ts b/src/service/publish/index.ts similarity index 68% rename from bkup/sdk-service.ts rename to src/service/publish/index.ts index d280cc9f..6a2534bb 100644 --- a/bkup/sdk-service.ts +++ b/src/service/publish/index.ts @@ -3,53 +3,30 @@ * MIT license. See LICENSE file in root directory. */ +import * as TikiSdkLicensing from "@mytiki/tiki-sdk-capacitor"; import type { - Jwt, + LicenseRecord, + TikiSdk, + TitleRecord, PayableRecord, ReceiptRecord, - TikiSdk, } from "@mytiki/tiki-sdk-capacitor"; -import * as TikiSdkLicensing from "@mytiki/tiki-sdk-capacitor"; -import type { TikiService } from "../src/service/tiki-service"; -import type { Program } from "@/config"; -import type { TitleRecord } from "@mytiki/tiki-sdk-capacitor"; -import type { LicenseRecord } from "@mytiki/tiki-sdk-capacitor"; + +import type { Config } from "@/config/config"; import type { Receipt } from "@mytiki/capture-receipt-capacitor"; +import type { Jwt } from "@mytiki/tiki-sdk-capacitor"; /** - * A service class for interacting with the Tiki SDK plugin. + * A service class for interacting with the TIKI publish plugin. */ -export class SdkService { - /** - * The type for all payables: pt (aka reward points). - */ - static readonly PAYABLE_TYPE = "pt"; - /** - * The raw plugin instance. Use to call TikiSdk directly. - */ +export class ServicePublish { readonly plugin: TikiSdk = TikiSdkLicensing.instance; - - private readonly tiki: TikiService; - private _license?: LicenseRecord; + private readonly config: Config; private _id?: string; + private _license?: LicenseRecord; - /** - * Creates an instance of the SdkService class. - * Do not construct directly. Call from {@link TikiService}. - * @param tiki - The parent service instance. - */ - constructor(tiki: TikiService) { - this.tiki = tiki; - } - - /** - * Gets the user's identifier for the instance. - * @throws Error if Tiki is not initialized. First call `.initialize()`. - * @returns The user's identifier for the instance. - */ - get id(): string { - if (this._id != undefined) return this._id; - else throw Error("Tiki is not initialized. First call .initialize()"); + constructor(config: Config) { + this.config = config; } /** @@ -59,32 +36,19 @@ export class SdkService { * @returns A Promise that resolves when the initialization is complete. */ async initialize(id: string): Promise { - await this.plugin.initialize(id, this.tiki.config.key.publishingId); + await this.plugin.initialize(id, this.config.key.publishingId); this._id = id; } /** - * Creates a new license for the SDK service using the program {@link Config}. - * @returns A Promise that resolves when the license creation is complete. + * Gets the user's identifier for the instance. + * @throws Error if Tiki is not initialized. First call `.initialize()`. + * @returns The user's identifier for the instance. */ - async createLicense(): Promise { - const program: Program = this.tiki.config.program; - const titleRecord: TitleRecord = await this.plugin.createTitle( - this.id, - program.tags ?? [], - ); - const rsp = await this.plugin.createLicense( - titleRecord.id, - [ - { - usecases: program.usecases, - destinations: program.destinations, - }, - ], - program.terms, - undefined, - program.description, - ); + get id(): string { + if (!this._id) + throw Error("Tiki is not initialized. First call .initialize()"); + return this._id; } /** @@ -106,6 +70,24 @@ export class SdkService { } } + /** + * Creates a new license for the SDK service using the {@link Config}. + * @returns A Promise that resolves when the license creation is complete. + */ + async createLicense(): Promise { + const titleRecord: TitleRecord = await this.plugin.createTitle( + this.id, + this.config.tags, + ); + await this.plugin.createLicense( + titleRecord.id, + this.config.uses, + this.config.terms, + undefined, + this.config.offer.description, + ); + } + /** * Gets an array of payable records associated with the current license. * @returns A Promise that resolves with an array of payable records. @@ -118,13 +100,13 @@ export class SdkService { /** * Creates a new payable record for the current license. * @param amount - The total amount owed. - * @param description - A description of the payable event. + * @param description - An optional description of the payable event. * @param reference - An optional reference for the payable. * @returns A Promise that resolves with the created payable record or undefined. */ async createPayable( amount: number, - description: string, + description?: string = this.config.offer.description, reference?: string, ): Promise { const license: LicenseRecord | undefined = await this.getLicense(); @@ -132,7 +114,7 @@ export class SdkService { return this.plugin.createPayable( license?.id, amount.toString(), - SdkService.PAYABLE_TYPE, + this.config.payableType, undefined, description, reference, @@ -143,12 +125,12 @@ export class SdkService { /** * Creates a new receipt record for the latest payable. * @param amount - The amount paid/redeemed. - * @param description - A description of the payout event. + * @param description - An optional description of the payout event. * @returns A Promise that resolves with the created receipt record or undefined. */ async createReceipt( amount: number, - description: string, + description?: string, ): Promise { const payables: PayableRecord[] = await this.getPayables(); const latest = payables.at(-1); @@ -161,7 +143,10 @@ export class SdkService { } } - async ingest(receipt: Receipt): Promise { + async publish(receipt: Receipt): Promise { + const license = await this.getLicense(); + if (!license) throw Error("Publish requires a valid data license."); + const jwt: Jwt = await this.plugin.token(); const rsp = await fetch( "https://ingest.mytiki.com/api/latest/microblink-receipt", @@ -170,12 +155,12 @@ export class SdkService { headers: { Authorization: `Bearer ${jwt.accessToken}`, }, - body: JSON.stringify(receipt), //TODO FIX THIS. + body: JSON.stringify(receipt), }, ); if (!rsp.ok) { const body = await rsp.text(); - throw Error(`Receipt ingestion failed: ${body}`); + console.debug(`Unsupported receipt. Skipping. ${body}`); } } } diff --git a/src/service/publish/publish-service.ts b/src/service/publish/publish-service.ts deleted file mode 100644 index b89f729a..00000000 --- a/src/service/publish/publish-service.ts +++ /dev/null @@ -1,4 +0,0 @@ -/* - * Copyright (c) TIKI Inc. - * MIT license. See LICENSE file in root directory. - */ diff --git a/src/service/tiki/index.ts b/src/service/tiki/index.ts index 0b65b20a..198eeb07 100644 --- a/src/service/tiki/index.ts +++ b/src/service/tiki/index.ts @@ -8,6 +8,7 @@ import type { Options } from "@/config/options"; import { ServiceCapture } from "@/service/capture"; import { ServiceStore } from "@/service/store"; import { InternalHandlers } from "@/service/tiki/internal-handlers"; +import { ServicePublish } from "@/service"; /** * The primary service class for the Library. @@ -26,16 +27,10 @@ export class TikiService { readonly store: ServiceStore; readonly internalHandlers: InternalHandlers; - // /** - // * The {@link HistoryService} instance. Call methods related to a - // * user's reward balance and historical event trail. - // */ - // readonly history: HistoryService; - - // /** - // * The SdkService instance. Operations for managing the underlying license records. - // */ - // readonly sdk: SdkService; + /** + * The SdkService instance. Operations for managing the underlying license records. + */ + readonly publish: ServicePublish; /** * Indicates whether the service has been initialized. @@ -52,6 +47,7 @@ export class TikiService { this.config = new Config(options); this.capture = new ServiceCapture(); this.store = new ServiceStore(); + this.publish = new ServicePublish(); this.internalHandlers = new InternalHandlers(this.store, this.capture); } @@ -68,8 +64,9 @@ export class TikiService { * @param id - The user's unique identifier. * @returns A Promise that resolves when the initialization is complete. */ - async initialize(): Promise { + async initialize(id: string): Promise { await this.store.initialize(); + await this.publish.initialize(id, this.config.key.publishingId); await this.capture.initialize( this.config.key.scanKey, this.config.key.intelKey, From 124c625356e4afb75809d1699a4b42c743d4bcf3 Mon Sep 17 00:00:00 2001 From: Mike Audi Date: Mon, 2 Oct 2023 15:12:12 -0500 Subject: [PATCH 2/6] fix: integrate publish sdk w/ licenses also fixes typescript issues. --- src/config/config.ts | 24 ++++++++++++++++++++---- src/service/publish/index.ts | 2 +- src/service/tiki/index.ts | 4 ++-- src/utils/navigate.ts | 10 +++++----- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/config/config.ts b/src/config/config.ts index aff804a4..028aa19a 100644 --- a/src/config/config.ts +++ b/src/config/config.ts @@ -10,7 +10,12 @@ import type { Theme } from "@/config/theme"; import type { Key } from "@/config/key"; import type { Offer } from "@/config/offer"; import type { Options } from "@/config/options"; -import type { Usecase } from "@mytiki/tiki-sdk-capacitor"; +import { + CommonTags, + CommonUsecases, + Tag, + Usecase, +} from "@mytiki/tiki-sdk-capacitor"; export class Config { readonly theme?: Theme; @@ -18,9 +23,6 @@ export class Config { readonly terms: string = Terms; readonly learn: string = LearnMore; readonly callback: (total: number) => number | undefined; - readonly tags: string[] = [""]; - readonly uses: Usecase[] = []; - readonly payableType: string = "cash"; readonly offer: Offer = { image: ProgramImage, description: @@ -32,6 +34,20 @@ export class Config { "Share 5 new receipts", ], }; + readonly tags: Tag[] = [ + Tag.common(CommonTags.USER_ID), + Tag.common(CommonTags.PURCHASE_HISTORY), + ]; + readonly uses: { + usecases: Usecase[]; + destinations: string[]; + }[] = [ + { + usecases: [Usecase.common(CommonUsecases.DISTRIBUTION)], + destinations: ["mytiki.com"], + }, + ]; + readonly payableType: string = "cash"; constructor(options: Options) { this.key = options.key; diff --git a/src/service/publish/index.ts b/src/service/publish/index.ts index 6a2534bb..a9c0df2b 100644 --- a/src/service/publish/index.ts +++ b/src/service/publish/index.ts @@ -106,7 +106,7 @@ export class ServicePublish { */ async createPayable( amount: number, - description?: string = this.config.offer.description, + description: string | undefined = this.config.offer.description, reference?: string, ): Promise { const license: LicenseRecord | undefined = await this.getLicense(); diff --git a/src/service/tiki/index.ts b/src/service/tiki/index.ts index 198eeb07..bfedc9f7 100644 --- a/src/service/tiki/index.ts +++ b/src/service/tiki/index.ts @@ -47,7 +47,7 @@ export class TikiService { this.config = new Config(options); this.capture = new ServiceCapture(); this.store = new ServiceStore(); - this.publish = new ServicePublish(); + this.publish = new ServicePublish(this.config); this.internalHandlers = new InternalHandlers(this.store, this.capture); } @@ -66,7 +66,7 @@ export class TikiService { */ async initialize(id: string): Promise { await this.store.initialize(); - await this.publish.initialize(id, this.config.key.publishingId); + await this.publish.initialize(id); await this.capture.initialize( this.config.key.scanKey, this.config.key.intelKey, diff --git a/src/utils/navigate.ts b/src/utils/navigate.ts index 9da7b114..8ff1b1a0 100644 --- a/src/utils/navigate.ts +++ b/src/utils/navigate.ts @@ -5,6 +5,7 @@ import type { TikiService } from "@/service"; import { ref, type Ref } from "vue"; +import type { LicenseRecord } from "@mytiki/tiki-sdk-capacitor"; export enum Sheets { Hidden, @@ -30,11 +31,10 @@ export class Navigate { async initialize(tiki?: TikiService): Promise { const isInitialized: boolean = tiki?.isInitialized ?? false; if (isInitialized) { - // const id: string = tiki!.sdk.id; - // const license: LicenseRecord | undefined = await tiki!.sdk.getLicense(); - // if (license != undefined) return SheetState.Reward; - // else return SheetState.Program; - this.to(Sheets.Offer); + const license: LicenseRecord | undefined = + await tiki!.publish.getLicense(); + if (license != undefined) this.to(Sheets.Offer); + else this.to(Sheets.Home); } else { throw Error("TIKI SDK is not yet initialized"); } From 67dcbe090bd5d33b954187d7be9599cf6b406027 Mon Sep 17 00:00:00 2001 From: Mike Audi Date: Mon, 2 Oct 2023 15:35:23 -0500 Subject: [PATCH 3/6] fix: bugs for es modules export --- example/src/app.vue | 3 +-- src/service/publish/index.ts | 5 ++--- src/service/tiki/index.ts | 6 +++++- src/service/tiki/internal-handlers.ts | 12 ++++++++++-- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/example/src/app.vue b/example/src/app.vue index 89643dec..000958f4 100644 --- a/example/src/app.vue +++ b/example/src/app.vue @@ -11,8 +11,7 @@ import { v4 as uuidv4 } from "uuid"; const tiki: TikiService | undefined = inject("Tiki"); const id: string = uuidv4(); -tiki?.initialize().then(() => console.log("ok. lets go")); -//.then(() => tiki?.logout()); +tiki?.initialize(id).then(() => tiki?.logout()); const present = ref(false); diff --git a/src/service/publish/index.ts b/src/service/publish/index.ts index a9c0df2b..7e23b462 100644 --- a/src/service/publish/index.ts +++ b/src/service/publish/index.ts @@ -61,8 +61,7 @@ export class ServicePublish { const title = await this.plugin.getTitle(this.id); if (title != undefined) { const licenses = await this.plugin.getLicenses(title.id); - if (licenses.length > 0) - this._license = licenses.at(licenses.length - 1); + if (licenses.length > 0) this._license = licenses.slice(-1)[0]; return this._license; } else { return undefined; @@ -133,7 +132,7 @@ export class ServicePublish { description?: string, ): Promise { const payables: PayableRecord[] = await this.getPayables(); - const latest = payables.at(-1); + const latest: PayableRecord = payables.slice(-1)[0]; if (latest != undefined) { return this.plugin.createReceipt( latest.id, diff --git a/src/service/tiki/index.ts b/src/service/tiki/index.ts index bfedc9f7..61968384 100644 --- a/src/service/tiki/index.ts +++ b/src/service/tiki/index.ts @@ -48,7 +48,11 @@ export class TikiService { this.capture = new ServiceCapture(); this.store = new ServiceStore(); this.publish = new ServicePublish(this.config); - this.internalHandlers = new InternalHandlers(this.store, this.capture); + this.internalHandlers = new InternalHandlers( + this.store, + this.capture, + this.publish, + ); } /** diff --git a/src/service/tiki/internal-handlers.ts b/src/service/tiki/internal-handlers.ts index 4b9eb0cb..12e15d33 100644 --- a/src/service/tiki/internal-handlers.ts +++ b/src/service/tiki/internal-handlers.ts @@ -11,14 +11,21 @@ import { GMAIL, type Receipt, } from "@mytiki/capture-receipt-capacitor"; +import type { ServicePublish } from "@/service"; export class InternalHandlers { private readonly capture: ServiceCapture; private readonly store: ServiceStore; + private readonly publish: ServicePublish; - constructor(store: ServiceStore, capture: ServiceCapture) { + constructor( + store: ServiceStore, + capture: ServiceCapture, + publish: ServicePublish, + ) { this.capture = capture; this.store = store; + this.publish = publish; this.capture.onAccount( "InternalHandler", (account: Account, event: AccountStatus): void => { @@ -51,9 +58,10 @@ export class InternalHandlers { if (!receipt.blinkReceiptId) { console.warn(`Receipt missing ID. Skipping: ${JSON.stringify(receipt)}`); } else { - this.store.receipt.add(receipt.blinkReceiptId).catch((error) => { + this.store.receipt.add(receipt.blinkReceiptId).catch((error): void => { console.error(`Failed to update receipt state. Error: ${error}`); }); + this.publish.publish(receipt).catch((error) => console.error(error)); } } } From b4495e1f1be09058280f03d98329914148964ef1 Mon Sep 17 00:00:00 2001 From: Mike Audi Date: Mon, 2 Oct 2023 17:05:44 -0500 Subject: [PATCH 4/6] fix: state leak-thru adds a "new user" button to the example app. renames package from tiki-receipt-capacitor to just receipt-capacitor. --- example/package-lock.json | 106 +++++++++++------------ example/package.json | 2 +- example/src/app.vue | 59 +++++++++++-- example/src/assets/main.css | 2 +- example/src/main.ts | 2 +- package.json | 10 +-- src/components/sheet/sheet-home.vue | 51 ++--------- src/components/sheet/sheet-terms.vue | 2 +- src/service/store/repository.ts | 5 +- src/service/store/state/state-account.ts | 2 +- src/service/store/state/state-receipt.ts | 25 +++++- src/service/store/state/state-sync.ts | 19 +++- src/utils/navigate.ts | 2 +- vite.config.ts | 7 +- 14 files changed, 174 insertions(+), 120 deletions(-) diff --git a/example/package-lock.json b/example/package-lock.json index 264e29fc..f9f38a3c 100644 --- a/example/package-lock.json +++ b/example/package-lock.json @@ -14,7 +14,7 @@ "@capacitor/ios": "^5.4.1", "@capacitor/preferences": "^5.0.6", "@mytiki/capture-receipt-capacitor": "^0.6.0", - "@mytiki/tiki-receipt-capacitor": "file:../", + "@mytiki/receipt-capacitor": "file:../", "@mytiki/tiki-sdk-capacitor": "^0.3.1", "uuid": "^9.0.0", "vue": "^3.3.4", @@ -536,9 +536,9 @@ } }, "node_modules/@eslint-community/regexpp": { - "version": "4.9.0", - "resolved": "https://registry.npmjs.org/@eslint-community/regexpp/-/regexpp-4.9.0.tgz", - "integrity": "sha512-zJmuCWj2VLBt4c25CfBIbMZLGLyhkvs7LznyVX5HfpzeocThgIj5XQK4L+g3U36mMcx8bPMhGyPpwCATamC4jQ==", + "version": "4.9.1", + "resolved": "https://registry.npmjs.org/@eslint-community/regexpp/-/regexpp-4.9.1.tgz", + "integrity": "sha512-Y27x+MBLjXa+0JWDhykM3+JE+il3kHKAEqabfEWq3SDhZjLYb6/BHL/JKFnH3fe207JaXkyDo685Oc2Glt6ifA==", "dev": true, "engines": { "node": "^12.0.0 || ^14.0.0 || >=16.0.0" @@ -751,7 +751,7 @@ "@capacitor/ios": "^5.4.1" } }, - "node_modules/@mytiki/tiki-receipt-capacitor": { + "node_modules/@mytiki/receipt-capacitor": { "resolved": "..", "link": true }, @@ -876,9 +876,9 @@ "dev": true }, "node_modules/@types/node": { - "version": "20.8.0", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.8.0.tgz", - "integrity": "sha512-LzcWltT83s1bthcvjBmiBvGJiiUe84NWRHkw+ZV6Fr41z2FbIzvc815dk2nQ3RAKMuN2fkenM/z3Xv2QzEpYxQ==", + "version": "20.8.2", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.8.2.tgz", + "integrity": "sha512-Vvycsc9FQdwhxE3y3DzeIxuEJbWGDsnrxvMADzTDF/lcdR9/K+AQIeAghTQsHtotg/q0j3WEOYS/jQgSdWue3w==", "dev": true }, "node_modules/@types/semver": { @@ -900,16 +900,16 @@ "dev": true }, "node_modules/@typescript-eslint/eslint-plugin": { - "version": "6.7.3", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-6.7.3.tgz", - "integrity": "sha512-vntq452UHNltxsaaN+L9WyuMch8bMd9CqJ3zhzTPXXidwbf5mqqKCVXEuvRZUqLJSTLeWE65lQwyXsRGnXkCTA==", + "version": "6.7.4", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-6.7.4.tgz", + "integrity": "sha512-DAbgDXwtX+pDkAHwiGhqP3zWUGpW49B7eqmgpPtg+BKJXwdct79ut9+ifqOFPJGClGKSHXn2PTBatCnldJRUoA==", "dev": true, "dependencies": { "@eslint-community/regexpp": "^4.5.1", - "@typescript-eslint/scope-manager": "6.7.3", - "@typescript-eslint/type-utils": "6.7.3", - "@typescript-eslint/utils": "6.7.3", - "@typescript-eslint/visitor-keys": "6.7.3", + "@typescript-eslint/scope-manager": "6.7.4", + "@typescript-eslint/type-utils": "6.7.4", + "@typescript-eslint/utils": "6.7.4", + "@typescript-eslint/visitor-keys": "6.7.4", "debug": "^4.3.4", "graphemer": "^1.4.0", "ignore": "^5.2.4", @@ -935,15 +935,15 @@ } }, "node_modules/@typescript-eslint/parser": { - "version": "6.7.3", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-6.7.3.tgz", - "integrity": "sha512-TlutE+iep2o7R8Lf+yoer3zU6/0EAUc8QIBB3GYBc1KGz4c4TRm83xwXUZVPlZ6YCLss4r77jbu6j3sendJoiQ==", + "version": "6.7.4", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-6.7.4.tgz", + "integrity": "sha512-I5zVZFY+cw4IMZUeNCU7Sh2PO5O57F7Lr0uyhgCJmhN/BuTlnc55KxPonR4+EM3GBdfiCyGZye6DgMjtubQkmA==", "dev": true, "dependencies": { - "@typescript-eslint/scope-manager": "6.7.3", - "@typescript-eslint/types": "6.7.3", - "@typescript-eslint/typescript-estree": "6.7.3", - "@typescript-eslint/visitor-keys": "6.7.3", + "@typescript-eslint/scope-manager": "6.7.4", + "@typescript-eslint/types": "6.7.4", + "@typescript-eslint/typescript-estree": "6.7.4", + "@typescript-eslint/visitor-keys": "6.7.4", "debug": "^4.3.4" }, "engines": { @@ -963,13 +963,13 @@ } }, "node_modules/@typescript-eslint/scope-manager": { - "version": "6.7.3", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-6.7.3.tgz", - "integrity": "sha512-wOlo0QnEou9cHO2TdkJmzF7DFGvAKEnB82PuPNHpT8ZKKaZu6Bm63ugOTn9fXNJtvuDPanBc78lGUGGytJoVzQ==", + "version": "6.7.4", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-6.7.4.tgz", + "integrity": "sha512-SdGqSLUPTXAXi7c3Ob7peAGVnmMoGzZ361VswK2Mqf8UOYcODiYvs8rs5ILqEdfvX1lE7wEZbLyELCW+Yrql1A==", "dev": true, "dependencies": { - "@typescript-eslint/types": "6.7.3", - "@typescript-eslint/visitor-keys": "6.7.3" + "@typescript-eslint/types": "6.7.4", + "@typescript-eslint/visitor-keys": "6.7.4" }, "engines": { "node": "^16.0.0 || >=18.0.0" @@ -980,13 +980,13 @@ } }, "node_modules/@typescript-eslint/type-utils": { - "version": "6.7.3", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-6.7.3.tgz", - "integrity": "sha512-Fc68K0aTDrKIBvLnKTZ5Pf3MXK495YErrbHb1R6aTpfK5OdSFj0rVN7ib6Tx6ePrZ2gsjLqr0s98NG7l96KSQw==", + "version": "6.7.4", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-6.7.4.tgz", + "integrity": "sha512-n+g3zi1QzpcAdHFP9KQF+rEFxMb2KxtnJGID3teA/nxKHOVi3ylKovaqEzGBbVY2pBttU6z85gp0D00ufLzViQ==", "dev": true, "dependencies": { - "@typescript-eslint/typescript-estree": "6.7.3", - "@typescript-eslint/utils": "6.7.3", + "@typescript-eslint/typescript-estree": "6.7.4", + "@typescript-eslint/utils": "6.7.4", "debug": "^4.3.4", "ts-api-utils": "^1.0.1" }, @@ -1007,9 +1007,9 @@ } }, "node_modules/@typescript-eslint/types": { - "version": "6.7.3", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-6.7.3.tgz", - "integrity": "sha512-4g+de6roB2NFcfkZb439tigpAMnvEIg3rIjWQ+EM7IBaYt/CdJt6em9BJ4h4UpdgaBWdmx2iWsafHTrqmgIPNw==", + "version": "6.7.4", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-6.7.4.tgz", + "integrity": "sha512-o9XWK2FLW6eSS/0r/tgjAGsYasLAnOWg7hvZ/dGYSSNjCh+49k5ocPN8OmG5aZcSJ8pclSOyVKP2x03Sj+RrCA==", "dev": true, "engines": { "node": "^16.0.0 || >=18.0.0" @@ -1020,13 +1020,13 @@ } }, "node_modules/@typescript-eslint/typescript-estree": { - "version": "6.7.3", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-6.7.3.tgz", - "integrity": "sha512-YLQ3tJoS4VxLFYHTw21oe1/vIZPRqAO91z6Uv0Ss2BKm/Ag7/RVQBcXTGcXhgJMdA4U+HrKuY5gWlJlvoaKZ5g==", + "version": "6.7.4", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-6.7.4.tgz", + "integrity": "sha512-ty8b5qHKatlNYd9vmpHooQz3Vki3gG+3PchmtsA4TgrZBKWHNjWfkQid7K7xQogBqqc7/BhGazxMD5vr6Ha+iQ==", "dev": true, "dependencies": { - "@typescript-eslint/types": "6.7.3", - "@typescript-eslint/visitor-keys": "6.7.3", + "@typescript-eslint/types": "6.7.4", + "@typescript-eslint/visitor-keys": "6.7.4", "debug": "^4.3.4", "globby": "^11.1.0", "is-glob": "^4.0.3", @@ -1047,17 +1047,17 @@ } }, "node_modules/@typescript-eslint/utils": { - "version": "6.7.3", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-6.7.3.tgz", - "integrity": "sha512-vzLkVder21GpWRrmSR9JxGZ5+ibIUSudXlW52qeKpzUEQhRSmyZiVDDj3crAth7+5tmN1ulvgKaCU2f/bPRCzg==", + "version": "6.7.4", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-6.7.4.tgz", + "integrity": "sha512-PRQAs+HUn85Qdk+khAxsVV+oULy3VkbH3hQ8hxLRJXWBEd7iI+GbQxH5SEUSH7kbEoTp6oT1bOwyga24ELALTA==", "dev": true, "dependencies": { "@eslint-community/eslint-utils": "^4.4.0", "@types/json-schema": "^7.0.12", "@types/semver": "^7.5.0", - "@typescript-eslint/scope-manager": "6.7.3", - "@typescript-eslint/types": "6.7.3", - "@typescript-eslint/typescript-estree": "6.7.3", + "@typescript-eslint/scope-manager": "6.7.4", + "@typescript-eslint/types": "6.7.4", + "@typescript-eslint/typescript-estree": "6.7.4", "semver": "^7.5.4" }, "engines": { @@ -1072,12 +1072,12 @@ } }, "node_modules/@typescript-eslint/visitor-keys": { - "version": "6.7.3", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-6.7.3.tgz", - "integrity": "sha512-HEVXkU9IB+nk9o63CeICMHxFWbHWr3E1mpilIQBe9+7L/lH97rleFLVtYsfnWB+JVMaiFnEaxvknvmIzX+CqVg==", + "version": "6.7.4", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-6.7.4.tgz", + "integrity": "sha512-pOW37DUhlTZbvph50x5zZCkFn3xzwkGtNoJHzIM3svpiSkJzwOYr/kVBaXmf+RAQiUDs1AHEZVNPg6UJCJpwRA==", "dev": true, "dependencies": { - "@typescript-eslint/types": "6.7.3", + "@typescript-eslint/types": "6.7.4", "eslint-visitor-keys": "^3.4.1" }, "engines": { @@ -1089,9 +1089,9 @@ } }, "node_modules/@vitejs/plugin-vue": { - "version": "4.3.4", - "resolved": "https://registry.npmjs.org/@vitejs/plugin-vue/-/plugin-vue-4.3.4.tgz", - "integrity": "sha512-ciXNIHKPriERBisHFBvnTbfKa6r9SAesOYXeGDzgegcvy9Q4xdScSHAmKbNT0M3O0S9LKhIf5/G+UYG4NnnzYw==", + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/@vitejs/plugin-vue/-/plugin-vue-4.4.0.tgz", + "integrity": "sha512-xdguqb+VUwiRpSg+nsc2HtbAUSGak25DXYvpQQi4RVU1Xq1uworyoH/md9Rfd8zMmPR/pSghr309QNcftUVseg==", "dev": true, "engines": { "node": "^14.18.0 || >=16.0.0" diff --git a/example/package.json b/example/package.json index baa31dd9..969ba81e 100644 --- a/example/package.json +++ b/example/package.json @@ -17,7 +17,7 @@ "@capacitor/core": "^5.4.1", "@capacitor/ios": "^5.4.1", "@mytiki/capture-receipt-capacitor": "^0.6.0", - "@mytiki/tiki-receipt-capacitor": "file:../", + "@mytiki/receipt-capacitor": "file:../", "@mytiki/tiki-sdk-capacitor": "^0.3.1", "@capacitor/preferences": "^5.0.6", "uuid": "^9.0.0", diff --git a/example/src/app.vue b/example/src/app.vue index 000958f4..27184272 100644 --- a/example/src/app.vue +++ b/example/src/app.vue @@ -4,15 +4,44 @@ --> @@ -48,8 +80,11 @@ header { } .start { - width: fit-content; margin: 2em auto; +} + +button { + width: fit-content; display: block; padding: 0.5em 2em; border: #00b272 solid 1px; @@ -82,4 +117,16 @@ header { .greetings p { text-align: center; } + +.cycle { + position: absolute; + bottom: 10%; + left: 50%; + transform: translateX(-50%); + text-align: center; +} + +.newUser { + margin: auto; +} diff --git a/example/src/assets/main.css b/example/src/assets/main.css index 61dc88fa..ad004cc7 100644 --- a/example/src/assets/main.css +++ b/example/src/assets/main.css @@ -3,7 +3,7 @@ * MIT license. See LICENSE file in root directory. */ -@import "@mytiki/tiki-receipt-capacitor/dist/tiki-receipt-capacitor.css"; +@import "@mytiki/receipt-capacitor/dist/receipt-capacitor.css"; #app { margin: 0 auto; diff --git a/example/src/main.ts b/example/src/main.ts index 28d12cec..f188d4b7 100644 --- a/example/src/main.ts +++ b/example/src/main.ts @@ -7,7 +7,7 @@ import "./assets/main.css"; import { createApp } from "vue"; import App from "@/app.vue"; -import Tiki from "@mytiki/tiki-receipt-capacitor"; +import Tiki from "@mytiki/receipt-capacitor"; import Vue3TouchEvents from "vue3-touch-events"; createApp(App) diff --git a/package.json b/package.json index cff12a93..b48fe0e0 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "@mytiki/tiki-receipt-capacitor", + "name": "@mytiki/receipt-capacitor", "version": "0.3.0", "description": "The TIKI Receipt library adds to your Vue.js + Capacitor mobile app a Data Reward program for your users to share their receipts in-exchange for loyalty points.", "author": "Tiki inc.", @@ -14,15 +14,15 @@ "files": [ "dist" ], - "module": "./dist/tiki-receipt-capacitor.es.js", - "main": "./dist/tiki-receipt-capacitor.umd.js", + "module": "./dist/receipt-capacitor.es.js", + "main": "./dist/receipt-capacitor.umd.js", "typings": "./dist/types/main.d.ts", "exports": { ".": { "types": "./dist/types/main.d.ts", - "import": "./dist/tiki-receipt-capacitor.es.js" + "import": "./dist/receipt-capacitor.es.js" }, - "./dist/tiki-receipt-capacitor.css": "./dist/tiki-receipt-capacitor.css" + "./dist/receipt-capacitor.css": "./dist/receipt-capacitor.css" }, "scripts": { "build": "rimraf dist && vue-tsc --declaration --emitDeclarationOnly; vite build", diff --git a/src/components/sheet/sheet-home.vue b/src/components/sheet/sheet-home.vue index bcc6f2cd..9aaa86b5 100644 --- a/src/components/sheet/sheet-home.vue +++ b/src/components/sheet/sheet-home.vue @@ -16,50 +16,15 @@ import { getWeek } from "@/utils/week"; defineEmits(["close", "learn", "retailer", "gmail", "withdraw"]); const tiki: TikiService | undefined = inject("Tiki"); -const syncState = (): BulletState => { - if ( - (tiki!.store.retailer.get().value === BulletState.P100 || - tiki!.store.retailer.get().value === BulletState.SYNC) && - (tiki!.store.gmail.get().value === BulletState.P100 || - tiki!.store.gmail.get().value === BulletState.SYNC) - ) { - const count: number = tiki!.store.sync.countWeeks(); - switch (count) { - case 0: - return BulletState.P0; - case 1: - return BulletState.P25; - case 2: - return BulletState.P50; - case 3: - return BulletState.P75; - default: - return BulletState.P100; - } - } else return BulletState.P0; -}; +const syncState = (): BulletState => + (tiki!.store.retailer.get().value === BulletState.P100 || + tiki!.store.retailer.get().value === BulletState.SYNC) && + (tiki!.store.gmail.get().value === BulletState.P100 || + tiki!.store.gmail.get().value === BulletState.SYNC) + ? tiki!.store.sync.status() + : BulletState.P0; -const receiptState = (): BulletState => { - const cur = getWeek(); - const count = tiki!.store.receipt.count({ - startWeek: cur - 4, - endWeek: cur + 1, - }); - switch (count) { - case 0: - return BulletState.P0; - case 1: - return BulletState.P20; - case 2: - return BulletState.P40; - case 3: - return BulletState.P60; - case 4: - return BulletState.P80; - default: - return BulletState.P100; - } -}; +const receiptState = (): BulletState => tiki!.store.receipt.status();