@daffodil/auth 0.94.1-rc.0 → 0.95.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/fesm2022/daffodil-auth-driver-in-memory.mjs +356 -249
- package/fesm2022/daffodil-auth-driver-in-memory.mjs.map +1 -1
- package/fesm2022/daffodil-auth-driver-magento-2.4.7.mjs +459 -0
- package/fesm2022/daffodil-auth-driver-magento-2.4.7.mjs.map +1 -0
- package/fesm2022/daffodil-auth-driver-magento-auto.mjs +7 -0
- package/fesm2022/daffodil-auth-driver-magento-auto.mjs.map +1 -0
- package/fesm2022/daffodil-auth-driver-testing.mjs +220 -126
- package/fesm2022/daffodil-auth-driver-testing.mjs.map +1 -1
- package/fesm2022/daffodil-auth-driver.mjs +99 -126
- package/fesm2022/daffodil-auth-driver.mjs.map +1 -1
- package/fesm2022/daffodil-auth-routing.mjs +392 -257
- package/fesm2022/daffodil-auth-routing.mjs.map +1 -1
- package/fesm2022/daffodil-auth-state-testing.mjs +209 -106
- package/fesm2022/daffodil-auth-state-testing.mjs.map +1 -1
- package/fesm2022/daffodil-auth-state.mjs +867 -852
- package/fesm2022/daffodil-auth-state.mjs.map +1 -1
- package/fesm2022/daffodil-auth-testing.mjs +132 -76
- package/fesm2022/daffodil-auth-testing.mjs.map +1 -1
- package/fesm2022/daffodil-auth.mjs +65 -57
- package/fesm2022/daffodil-auth.mjs.map +1 -1
- package/package.json +1 -1
- package/types/daffodil-auth-driver-in-memory.d.ts +62 -62
- package/types/daffodil-auth-driver-magento-2.4.7.d.ts +119 -0
- package/types/daffodil-auth-driver-magento-auto.d.ts +1 -0
- package/types/daffodil-auth-driver-testing.d.ts +37 -36
- package/types/daffodil-auth-driver.d.ts +93 -112
- package/types/daffodil-auth-routing.d.ts +100 -104
- package/types/daffodil-auth-state-testing.d.ts +44 -43
- package/types/daffodil-auth-state.d.ts +265 -306
- package/types/daffodil-auth-testing.d.ts +28 -33
- package/types/daffodil-auth.d.ts +51 -62
- package/fesm2022/daffodil-auth-driver-magento.mjs +0 -385
- package/fesm2022/daffodil-auth-driver-magento.mjs.map +0 -1
- package/types/daffodil-auth-driver-magento.d.ts +0 -135
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"daffodil-auth-driver-in-memory.mjs","sources":["../../../libs/auth/driver/in-memory/src/collection-name.const.ts","../../../libs/auth/driver/in-memory/src/drivers/auth/auth.service.ts","../../../libs/auth/driver/in-memory/src/drivers/login/login.service.ts","../../../libs/auth/driver/in-memory/src/drivers/register/register.service.ts","../../../libs/auth/driver/in-memory/src/drivers/reset-password/service.ts","../../../libs/auth/driver/in-memory/src/backend/auth.service.ts","../../../libs/auth/driver/in-memory/src/drivers/auth-driver.module.ts","../../../libs/auth/driver/in-memory/src/daffodil-auth-driver-in-memory.ts"],"sourcesContent":["export const DAFF_AUTH_IN_MEMORY_COLLECTION_NAME = 'auth';\n","import { HttpClient } from '@angular/common/http';\nimport { Injectable } from '@angular/core';\nimport { InMemoryBackendConfig } from 'angular-in-memory-web-api';\nimport { Observable } from 'rxjs';\nimport { map } from 'rxjs/operators';\n\nimport { DaffAuthServiceInterface } from '@daffodil/auth/driver';\nimport { DaffInMemoryDriverBase } from '@daffodil/driver/in-memory';\n\nimport { DAFF_AUTH_IN_MEMORY_COLLECTION_NAME } from '../../collection-name.const';\n\n/**\n * @inheritdoc DaffAuthServiceInterface\n */\n@Injectable({\n providedIn: 'root',\n})\nexport class DaffInMemoryAuthService extends DaffInMemoryDriverBase implements DaffAuthServiceInterface {\n constructor(\n private http: HttpClient,\n config: InMemoryBackendConfig,\n ) {\n super(config, DAFF_AUTH_IN_MEMORY_COLLECTION_NAME);\n }\n\n check(): Observable<void> {\n return this.http.post(`${this.url}/check`, {}).pipe(\n map(() => undefined),\n );\n }\n}\n","import { HttpClient } from '@angular/common/http';\nimport { Injectable } from '@angular/core';\nimport { InMemoryBackendConfig } from 'angular-in-memory-web-api';\nimport {\n Observable,\n of,\n throwError,\n} from 'rxjs';\nimport { switchMap } from 'rxjs/operators';\n\nimport {\n DaffLoginInfo,\n DaffAuthToken,\n} from '@daffodil/auth';\nimport { DaffLoginServiceInterface } from '@daffodil/auth/driver';\nimport { DaffInMemoryDriverBase } from '@daffodil/driver/in-memory';\n\nimport { DAFF_AUTH_IN_MEMORY_COLLECTION_NAME } from '../../collection-name.const';\n\n/**\n * @inheritdoc\n */\n@Injectable({\n providedIn: 'root',\n})\nexport class DaffInMemoryLoginService extends DaffInMemoryDriverBase implements DaffLoginServiceInterface {\n constructor(\n private http: HttpClient,\n config: InMemoryBackendConfig,\n ) {\n super(config, DAFF_AUTH_IN_MEMORY_COLLECTION_NAME);\n }\n\n login(request: DaffLoginInfo): Observable<DaffAuthToken> {\n return this.http.post<DaffAuthToken>(`${this.url}/login`, request);\n }\n\n logout(): Observable<void> {\n return this.http.post<{success: boolean}>(`${this.url}/logout`, {}).pipe(\n switchMap(({ success }) => success ? of(undefined) : throwError(() => new Error('Logout failed'))),\n );\n }\n}\n","import { HttpClient } from '@angular/common/http';\nimport { Injectable } from '@angular/core';\nimport { InMemoryBackendConfig } from 'angular-in-memory-web-api';\nimport { Observable } from 'rxjs';\nimport {\n map,\n switchMap,\n} from 'rxjs/operators';\n\nimport { DaffAccountRegistration } from '@daffodil/auth';\nimport { DaffRegisterServiceInterface } from '@daffodil/auth/driver';\nimport { DaffInMemoryDriverBase } from '@daffodil/driver/in-memory';\n\nimport { DAFF_AUTH_IN_MEMORY_COLLECTION_NAME } from '../../collection-name.const';\nimport { DaffInMemoryLoginService } from '../login/login.service';\n\n/**\n * @inheritdoc\n */\n@Injectable({\n providedIn: 'root',\n})\nexport class DaffInMemoryRegisterService extends DaffInMemoryDriverBase implements DaffRegisterServiceInterface {\n constructor(\n private http: HttpClient,\n private loginService: DaffInMemoryLoginService,\n config: InMemoryBackendConfig,\n ) {\n super(config, DAFF_AUTH_IN_MEMORY_COLLECTION_NAME);\n }\n\n register(registration: DaffAccountRegistration): Observable<string> {\n return this.registerOnly(registration).pipe(\n switchMap(() => this.loginService.login({ email: registration.email, password: registration.password })),\n map(({ token }) => token),\n );\n }\n\n registerOnly(registration: DaffAccountRegistration): Observable<void> {\n return this.http.post<void>(`${this.url}/register`, registration);\n }\n}\n","import { HttpClient } from '@angular/common/http';\nimport { Injectable } from '@angular/core';\nimport { InMemoryBackendConfig } from 'angular-in-memory-web-api';\nimport { Observable } from 'rxjs';\nimport {\n map,\n switchMap,\n} from 'rxjs/operators';\n\nimport { DaffAuthResetPasswordInfo } from '@daffodil/auth';\nimport { DaffResetPasswordServiceInterface } from '@daffodil/auth/driver';\nimport { DaffInMemoryDriverBase } from '@daffodil/driver/in-memory';\n\nimport { DAFF_AUTH_IN_MEMORY_COLLECTION_NAME } from '../../collection-name.const';\nimport { DaffInMemoryLoginService } from '../login/login.service';\n\n/**\n * @inheritdoc\n */\n@Injectable({\n providedIn: 'root',\n})\nexport class DaffInMemoryResetPasswordService extends DaffInMemoryDriverBase implements DaffResetPasswordServiceInterface {\n constructor(\n private http: HttpClient,\n private loginService: DaffInMemoryLoginService,\n config: InMemoryBackendConfig,\n ) {\n super(config, DAFF_AUTH_IN_MEMORY_COLLECTION_NAME);\n }\n\n resetPassword(info: DaffAuthResetPasswordInfo): Observable<string> {\n return this.resetPasswordOnly(info).pipe(\n switchMap(() => this.loginService.login({ email: info.email, password: info.password })),\n map(({ token }) => token),\n );\n }\n\n resetPasswordOnly(info: DaffAuthResetPasswordInfo): Observable<void> {\n return this.http.post<void>(`${this.url}/resetPassword`, info);\n }\n\n sendResetEmail(email: string): Observable<void> {\n return this.http.post<void>(`${this.url}/sendResetEmail`, { email });\n }\n}\n","import { Injectable } from '@angular/core';\nimport { faker } from '@faker-js/faker/locale/en_US';\nimport {\n InMemoryDbService,\n STATUS,\n} from 'angular-in-memory-web-api';\n\nimport { DaffInMemorySingleRouteableBackend } from '@daffodil/driver/in-memory';\n\nimport { DAFF_AUTH_IN_MEMORY_COLLECTION_NAME } from '../collection-name.const';\nimport { DaffInMemoryDbCustomer } from '../models/db-customer.type';\n\n/**\n * @inheritdoc DaffInMemorySingleRouteableBackend\n */\n@Injectable({\n providedIn: 'root',\n})\nexport class DaffInMemoryBackendAuthService implements InMemoryDbService, DaffInMemorySingleRouteableBackend {\n readonly collectionName = DAFF_AUTH_IN_MEMORY_COLLECTION_NAME;\n\n customers: Record<DaffInMemoryDbCustomer['email'], DaffInMemoryDbCustomer> = {};\n\n private generateToken(): string {\n return faker.string.alphanumeric(16);\n }\n\n createDb() {\n return {\n auth: this.customers,\n };\n }\n\n post(reqInfo) {\n if (reqInfo.id === 'login') {\n return this.login(reqInfo);\n } else if (reqInfo.id === 'register') {\n return this.register(reqInfo);\n } else if (reqInfo.id === 'logout') {\n return this.logout(reqInfo);\n } else if (reqInfo.id === 'check') {\n return this.check(reqInfo);\n } else if (reqInfo.id === 'resetPassword') {\n return this.resetPassword(reqInfo);\n } else if (reqInfo.id === 'sendResetEmail') {\n return this.sendResetEmail(reqInfo);\n }\n }\n\n private login(reqInfo: any) {\n const {\n email,\n password,\n } = reqInfo.utils.getJsonBody(reqInfo.req);\n const customer = this.customers[email];\n\n if (password && customer?.password === password) {\n this.customers[email].token = this.generateToken();\n\n return reqInfo.utils.createResponse$(() => ({\n body: {\n token: customer.token,\n },\n status: STATUS.OK,\n }));\n }\n\n return reqInfo.utils.createResponse$(() => ({\n status: STATUS.UNAUTHORIZED,\n }));\n }\n\n private register(reqInfo) {\n const {\n email,\n password,\n } = reqInfo.utils.getJsonBody(reqInfo.req);\n\n this.customers[email] = {\n email,\n password,\n };\n\n return reqInfo.utils.createResponse$(() => ({\n status: STATUS.CREATED,\n }));\n }\n\n private logout(reqInfo) {\n const {\n email,\n } = reqInfo.utils.getJsonBody(reqInfo.req);\n\n if (this.customers[email]) {\n this.customers[email].token = null;\n }\n\n return reqInfo.utils.createResponse$(() => ({\n body: { success: true },\n status: STATUS.OK,\n }));\n }\n\n private check(reqInfo) {\n return reqInfo.utils.createResponse$(() => ({\n body: {},\n status: STATUS.OK,\n }));\n }\n\n private resetPassword(reqInfo) {\n const {\n email,\n password,\n } = reqInfo.utils.getJsonBody(reqInfo.req);\n\n if (this.customers[email]) {\n this.customers[email].password = password;\n\n return reqInfo.utils.createResponse$(() => ({\n status: STATUS.OK,\n }));\n }\n\n return reqInfo.utils.createResponse$(() => ({\n status: STATUS.UNAUTHORIZED,\n }));\n }\n\n private sendResetEmail(reqInfo) {\n return reqInfo.utils.createResponse$(() => ({\n body: {},\n status: STATUS.OK,\n }));\n }\n}\n","import { CommonModule } from '@angular/common';\nimport {\n NgModule,\n ModuleWithProviders,\n} from '@angular/core';\n\nimport {\n provideDaffLoginDriver,\n provideDaffRegisterDriver,\n provideDaffAuthDriver,\n provideDaffResetPasswordDriver,\n} from '@daffodil/auth/driver';\nimport { provideDaffInMemoryBackends } from '@daffodil/driver/in-memory';\n\nimport { DaffInMemoryAuthService } from './auth/auth.service';\nimport { DaffInMemoryLoginService } from './login/login.service';\nimport { DaffInMemoryRegisterService } from './register/register.service';\nimport { DaffInMemoryResetPasswordService } from './reset-password/service';\nimport { DaffInMemoryBackendAuthService } from '../backend/auth.service';\n\n@NgModule({\n imports: [\n CommonModule,\n ],\n})\nexport class DaffAuthInMemoryDriverModule {\n static forRoot(): ModuleWithProviders<DaffAuthInMemoryDriverModule> {\n return {\n ngModule: DaffAuthInMemoryDriverModule,\n providers: [\n provideDaffLoginDriver(DaffInMemoryLoginService),\n provideDaffRegisterDriver(DaffInMemoryRegisterService),\n provideDaffAuthDriver(DaffInMemoryAuthService),\n provideDaffResetPasswordDriver(DaffInMemoryResetPasswordService),\n provideDaffInMemoryBackends(\n DaffInMemoryBackendAuthService,\n ),\n ],\n };\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":["i2.DaffInMemoryLoginService","i3"],"mappings":";;;;;;;;;;;;AAAO,MAAM,mCAAmC,GAAG,MAAM;;ACWzD;;AAEG;AAIG,MAAO,uB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","i3","i2.DaffInMemoryLoginService","i3"],"sources":["../../../libs/auth/driver/in-memory/src/collection-name.const.ts","../../../libs/auth/driver/in-memory/src/backend/auth.service.ts","../../../libs/auth/driver/in-memory/src/drivers/auth/auth.service.ts","../../../libs/auth/driver/in-memory/src/drivers/login/login.service.ts","../../../libs/auth/driver/in-memory/src/drivers/register/register.service.ts","../../../libs/auth/driver/in-memory/src/drivers/reset-password/service.ts","../../../libs/auth/driver/in-memory/src/provider.ts","../../../libs/auth/driver/in-memory/src/drivers/auth-driver.module.ts"],"sourcesContent":["export const DAFF_AUTH_IN_MEMORY_COLLECTION_NAME = 'auth';\n","import { Injectable } from '@angular/core';\nimport { faker } from '@faker-js/faker/locale/en_US';\nimport {\n InMemoryDbService,\n STATUS,\n} from 'angular-in-memory-web-api';\n\nimport { DaffInMemorySingleRouteableBackend } from '@daffodil/driver/in-memory';\n\nimport { DAFF_AUTH_IN_MEMORY_COLLECTION_NAME } from '../collection-name.const';\nimport { DaffInMemoryDbCustomer } from '../models/db-customer.type';\n\n/**\n * @inheritdoc DaffInMemorySingleRouteableBackend\n */\n@Injectable({\n providedIn: 'root',\n})\nexport class DaffInMemoryBackendAuthService implements InMemoryDbService, DaffInMemorySingleRouteableBackend {\n readonly collectionName = DAFF_AUTH_IN_MEMORY_COLLECTION_NAME;\n\n customers: Record<DaffInMemoryDbCustomer['email'], DaffInMemoryDbCustomer> = {};\n\n private generateToken(): string {\n return faker.string.alphanumeric(16);\n }\n\n createDb() {\n return {\n auth: this.customers,\n };\n }\n\n post(reqInfo) {\n if (reqInfo.id === 'login') {\n return this.login(reqInfo);\n } else if (reqInfo.id === 'register') {\n return this.register(reqInfo);\n } else if (reqInfo.id === 'logout') {\n return this.logout(reqInfo);\n } else if (reqInfo.id === 'check') {\n return this.check(reqInfo);\n } else if (reqInfo.id === 'resetPassword') {\n return this.resetPassword(reqInfo);\n } else if (reqInfo.id === 'sendResetEmail') {\n return this.sendResetEmail(reqInfo);\n }\n }\n\n private login(reqInfo: any) {\n const {\n email,\n password,\n } = reqInfo.utils.getJsonBody(reqInfo.req);\n const customer = this.customers[email];\n\n if (password && customer?.password === password) {\n this.customers[email].token = this.generateToken();\n\n return reqInfo.utils.createResponse$(() => ({\n body: {\n token: customer.token,\n },\n status: STATUS.OK,\n }));\n }\n\n return reqInfo.utils.createResponse$(() => ({\n status: STATUS.UNAUTHORIZED,\n }));\n }\n\n private register(reqInfo) {\n const {\n email,\n password,\n } = reqInfo.utils.getJsonBody(reqInfo.req);\n\n this.customers[email] = {\n email,\n password,\n };\n\n return reqInfo.utils.createResponse$(() => ({\n status: STATUS.CREATED,\n }));\n }\n\n private logout(reqInfo) {\n const {\n email,\n } = reqInfo.utils.getJsonBody(reqInfo.req);\n\n if (this.customers[email]) {\n this.customers[email].token = null;\n }\n\n return reqInfo.utils.createResponse$(() => ({\n body: { success: true },\n status: STATUS.OK,\n }));\n }\n\n private check(reqInfo) {\n return reqInfo.utils.createResponse$(() => ({\n body: {},\n status: STATUS.OK,\n }));\n }\n\n private resetPassword(reqInfo) {\n const {\n email,\n password,\n } = reqInfo.utils.getJsonBody(reqInfo.req);\n\n if (this.customers[email]) {\n this.customers[email].password = password;\n\n return reqInfo.utils.createResponse$(() => ({\n status: STATUS.OK,\n }));\n }\n\n return reqInfo.utils.createResponse$(() => ({\n status: STATUS.UNAUTHORIZED,\n }));\n }\n\n private sendResetEmail(reqInfo) {\n return reqInfo.utils.createResponse$(() => ({\n body: {},\n status: STATUS.OK,\n }));\n }\n}\n","import { HttpClient } from '@angular/common/http';\nimport { Injectable } from '@angular/core';\nimport { InMemoryBackendConfig } from 'angular-in-memory-web-api';\nimport { Observable } from 'rxjs';\nimport { map } from 'rxjs/operators';\n\nimport { DaffAuthServiceInterface } from '@daffodil/auth/driver';\nimport { DaffInMemoryDriverBase } from '@daffodil/driver/in-memory';\n\nimport { DAFF_AUTH_IN_MEMORY_COLLECTION_NAME } from '../../collection-name.const';\n\n/**\n * @inheritdoc DaffAuthServiceInterface\n */\n@Injectable({\n providedIn: 'root',\n})\nexport class DaffInMemoryAuthService extends DaffInMemoryDriverBase implements DaffAuthServiceInterface {\n constructor(\n private http: HttpClient,\n config: InMemoryBackendConfig,\n ) {\n super(config, DAFF_AUTH_IN_MEMORY_COLLECTION_NAME);\n }\n\n check(): Observable<void> {\n return this.http.post(`${this.url}/check`, {}).pipe(\n map(() => undefined),\n );\n }\n}\n","import { HttpClient } from '@angular/common/http';\nimport { Injectable } from '@angular/core';\nimport { InMemoryBackendConfig } from 'angular-in-memory-web-api';\nimport {\n Observable,\n of,\n throwError,\n} from 'rxjs';\nimport { switchMap } from 'rxjs/operators';\n\nimport {\n DaffLoginInfo,\n DaffAuthToken,\n} from '@daffodil/auth';\nimport { DaffLoginServiceInterface } from '@daffodil/auth/driver';\nimport { DaffInMemoryDriverBase } from '@daffodil/driver/in-memory';\n\nimport { DAFF_AUTH_IN_MEMORY_COLLECTION_NAME } from '../../collection-name.const';\n\n/**\n * @inheritdoc\n */\n@Injectable({\n providedIn: 'root',\n})\nexport class DaffInMemoryLoginService extends DaffInMemoryDriverBase implements DaffLoginServiceInterface {\n constructor(\n private http: HttpClient,\n config: InMemoryBackendConfig,\n ) {\n super(config, DAFF_AUTH_IN_MEMORY_COLLECTION_NAME);\n }\n\n login(request: DaffLoginInfo): Observable<DaffAuthToken> {\n return this.http.post<DaffAuthToken>(`${this.url}/login`, request);\n }\n\n logout(): Observable<void> {\n return this.http.post<{success: boolean}>(`${this.url}/logout`, {}).pipe(\n switchMap(({ success }) => success ? of(undefined) : throwError(() => new Error('Logout failed'))),\n );\n }\n}\n","import { HttpClient } from '@angular/common/http';\nimport { Injectable } from '@angular/core';\nimport { InMemoryBackendConfig } from 'angular-in-memory-web-api';\nimport { Observable } from 'rxjs';\nimport {\n map,\n switchMap,\n} from 'rxjs/operators';\n\nimport { DaffAccountRegistration } from '@daffodil/auth';\nimport { DaffRegisterServiceInterface } from '@daffodil/auth/driver';\nimport { DaffInMemoryDriverBase } from '@daffodil/driver/in-memory';\n\nimport { DAFF_AUTH_IN_MEMORY_COLLECTION_NAME } from '../../collection-name.const';\nimport { DaffInMemoryLoginService } from '../login/login.service';\n\n/**\n * @inheritdoc\n */\n@Injectable({\n providedIn: 'root',\n})\nexport class DaffInMemoryRegisterService extends DaffInMemoryDriverBase implements DaffRegisterServiceInterface {\n constructor(\n private http: HttpClient,\n private loginService: DaffInMemoryLoginService,\n config: InMemoryBackendConfig,\n ) {\n super(config, DAFF_AUTH_IN_MEMORY_COLLECTION_NAME);\n }\n\n register(registration: DaffAccountRegistration): Observable<string> {\n return this.registerOnly(registration).pipe(\n switchMap(() => this.loginService.login({ email: registration.email, password: registration.password })),\n map(({ token }) => token),\n );\n }\n\n registerOnly(registration: DaffAccountRegistration): Observable<void> {\n return this.http.post<void>(`${this.url}/register`, registration);\n }\n}\n","import { HttpClient } from '@angular/common/http';\nimport { Injectable } from '@angular/core';\nimport { InMemoryBackendConfig } from 'angular-in-memory-web-api';\nimport { Observable } from 'rxjs';\nimport {\n map,\n switchMap,\n} from 'rxjs/operators';\n\nimport { DaffAuthResetPasswordInfo } from '@daffodil/auth';\nimport { DaffResetPasswordServiceInterface } from '@daffodil/auth/driver';\nimport { DaffInMemoryDriverBase } from '@daffodil/driver/in-memory';\n\nimport { DAFF_AUTH_IN_MEMORY_COLLECTION_NAME } from '../../collection-name.const';\nimport { DaffInMemoryLoginService } from '../login/login.service';\n\n/**\n * @inheritdoc\n */\n@Injectable({\n providedIn: 'root',\n})\nexport class DaffInMemoryResetPasswordService extends DaffInMemoryDriverBase implements DaffResetPasswordServiceInterface {\n constructor(\n private http: HttpClient,\n private loginService: DaffInMemoryLoginService,\n config: InMemoryBackendConfig,\n ) {\n super(config, DAFF_AUTH_IN_MEMORY_COLLECTION_NAME);\n }\n\n resetPassword(info: DaffAuthResetPasswordInfo): Observable<string> {\n return this.resetPasswordOnly(info).pipe(\n switchMap(() => this.loginService.login({ email: info.email, password: info.password })),\n map(({ token }) => token),\n );\n }\n\n resetPasswordOnly(info: DaffAuthResetPasswordInfo): Observable<void> {\n return this.http.post<void>(`${this.url}/resetPassword`, info);\n }\n\n sendResetEmail(email: string): Observable<void> {\n return this.http.post<void>(`${this.url}/sendResetEmail`, { email });\n }\n}\n","import {\n EnvironmentProviders,\n makeEnvironmentProviders,\n} from '@angular/core';\n\nimport {\n provideDaffLoginDriver,\n provideDaffRegisterDriver,\n provideDaffAuthDriver,\n provideDaffResetPasswordDriver,\n} from '@daffodil/auth/driver';\nimport { provideDaffInMemoryBackends } from '@daffodil/driver/in-memory';\n\nimport { DaffInMemoryBackendAuthService } from './backend/auth.service';\nimport { DaffInMemoryAuthService } from './drivers/auth/auth.service';\nimport { DaffInMemoryLoginService } from './drivers/login/login.service';\nimport { DaffInMemoryRegisterService } from './drivers/register/register.service';\nimport { DaffInMemoryResetPasswordService } from './drivers/reset-password/service';\n\n/**\n * Provides the in-memory implementations of the `@daffodil/auth/driver` interfaces.\n */\nexport const provideDaffAuthInMemoryDriver = (): EnvironmentProviders => makeEnvironmentProviders([\n provideDaffLoginDriver(DaffInMemoryLoginService),\n provideDaffRegisterDriver(DaffInMemoryRegisterService),\n provideDaffAuthDriver(DaffInMemoryAuthService),\n provideDaffResetPasswordDriver(DaffInMemoryResetPasswordService),\n provideDaffInMemoryBackends(\n DaffInMemoryBackendAuthService,\n ),\n]);\n","import { CommonModule } from '@angular/common';\nimport {\n NgModule,\n ModuleWithProviders,\n} from '@angular/core';\n\nimport { provideDaffAuthInMemoryDriver } from '../provider';\n\n/**\n * @deprecated in favor of {@link provideDaffAuthInMemoryDriver} Deprecated in version 0.95.0. Will be removed in version 0.98.0.\n */\n@NgModule({\n imports: [\n CommonModule,\n ],\n})\nexport class DaffAuthInMemoryDriverModule {\n static forRoot(): ModuleWithProviders<DaffAuthInMemoryDriverModule> {\n return {\n ngModule: DaffAuthInMemoryDriverModule,\n providers: [\n provideDaffAuthInMemoryDriver(),\n ],\n };\n }\n}\n"],"mappings":";;;;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EAAA,KAAA,OAAA,GAAA,mBAAA;GAAA,YAAA;GAAA,SAAA;GAAA,UAAA;GAAA,MAAA;GAA4B,MAAA,CAAA;GAAA,QAAA,GAAA,gBAAA;EAAA,CAAA;CAAA;CAA5B;EAAA,KAAA,OAAA,GAAA,oBAAA;GAAA,YAAA;GAAA,SAAA;GAAA,UAAA;GAAA,MAAA;GAA4B,SAAA,CAHrC,YAAY;EAAA,CAAA;CAAA;CAGH;EAAA,KAAA,OAAA,GAAA,oBAAA;GAAA,YAAA;GAAA,SAAA;GAAA,UAAA;GAAA,MAAA;GAA4B,SAAA,CAHrC,YAAY;EAAA,CAAA;CAAA;;AAGH,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAA4B,YAAA,CAAA;EALxC,MAAA;EAAS,MAAA,CAAA,EACR,SAAS,CACP,YACD,EACF,CAAA"}
|
|
@@ -0,0 +1,459 @@
|
|
|
1
|
+
import { CommonModule } from "@angular/common";
|
|
2
|
+
import * as i0 from "@angular/core";
|
|
3
|
+
import { Injectable, NgModule, inject, makeEnvironmentProviders } from "@angular/core";
|
|
4
|
+
import { DaffAuthInvalidAPIResponseError, DaffAuthenticationFailedError, DaffRegistrationFailedError, DaffUnauthorizedError, provideDaffAuthDriver, provideDaffLoginDriver, provideDaffRegisterDriver, provideDaffResetPasswordDriver } from "@daffodil/auth/driver";
|
|
5
|
+
import * as i1$2 from "apollo-angular";
|
|
6
|
+
import { gql } from "apollo-angular";
|
|
7
|
+
import { throwError } from "rxjs";
|
|
8
|
+
import { catchError, map, switchMap } from "rxjs/operators";
|
|
9
|
+
import { daffTransformMagentoError, makeMagentoDriverFeature } from "@daffodil/driver/magento/2.4.7";
|
|
10
|
+
import { DaffBadInputError } from "@daffodil/driver";
|
|
11
|
+
import * as i1$1 from "@daffodil/core/graphql";
|
|
12
|
+
import { getApolloOperationHeaders, provideDaffApolloHeaderProviders } from "@daffodil/core/graphql";
|
|
13
|
+
import { HttpHeaders } from "@angular/common/http";
|
|
14
|
+
import { ApolloLink } from "@apollo/client";
|
|
15
|
+
import * as i1 from "@daffodil/auth";
|
|
16
|
+
import { DaffAuthStorageService } from "@daffodil/auth";
|
|
17
|
+
var MagentoAuthGraphQlErrorCode;
|
|
18
|
+
(function(MagentoAuthGraphQlErrorCode) {
|
|
19
|
+
MagentoAuthGraphQlErrorCode["UNAUTHORIZED"] = "graphql-authorization";
|
|
20
|
+
MagentoAuthGraphQlErrorCode["AUTHENTICATION_FAILED"] = "graphql-authentication";
|
|
21
|
+
MagentoAuthGraphQlErrorCode["BAD_INPUT"] = "graphql-input";
|
|
22
|
+
})(MagentoAuthGraphQlErrorCode || (MagentoAuthGraphQlErrorCode = {}));
|
|
23
|
+
const DaffAuthMagentoErrorMap = {
|
|
24
|
+
[MagentoAuthGraphQlErrorCode.UNAUTHORIZED]: DaffUnauthorizedError,
|
|
25
|
+
[MagentoAuthGraphQlErrorCode.AUTHENTICATION_FAILED]: DaffAuthenticationFailedError,
|
|
26
|
+
[MagentoAuthGraphQlErrorCode.BAD_INPUT]: DaffBadInputError
|
|
27
|
+
};
|
|
28
|
+
const transformMagentoAuthError = (error) => daffTransformMagentoError(error, DaffAuthMagentoErrorMap) || new DaffAuthInvalidAPIResponseError(error.message);
|
|
29
|
+
const checkTokenQuery = gql`
|
|
30
|
+
query MagentoCheckToken {
|
|
31
|
+
customer {
|
|
32
|
+
email
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
`;
|
|
36
|
+
const createCustomerMutation = gql`
|
|
37
|
+
mutation MagentoCreateCustomer(
|
|
38
|
+
$email: String!,
|
|
39
|
+
$password: String!,
|
|
40
|
+
$subscribe: Boolean!,
|
|
41
|
+
$firstname: String!,
|
|
42
|
+
$lastname: String!,
|
|
43
|
+
) {
|
|
44
|
+
createCustomerV2(input: {
|
|
45
|
+
firstname: $firstname,
|
|
46
|
+
lastname: $lastname,
|
|
47
|
+
email: $email,
|
|
48
|
+
password: $password,
|
|
49
|
+
is_subscribed: $subscribe
|
|
50
|
+
}) {
|
|
51
|
+
customer {
|
|
52
|
+
email
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
`;
|
|
57
|
+
const generateTokenMutation = gql`
|
|
58
|
+
mutation MagentoGenerateToken($email: String!, $password: String!) {
|
|
59
|
+
generateCustomerToken(
|
|
60
|
+
email: $email,
|
|
61
|
+
password: $password
|
|
62
|
+
) {
|
|
63
|
+
token
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
`;
|
|
67
|
+
const revokeCustomerTokenMutation = gql`
|
|
68
|
+
mutation revokeCustomerToken {
|
|
69
|
+
revokeCustomerToken {
|
|
70
|
+
result
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
`;
|
|
74
|
+
const sendPasswordResetEmailMutation = gql`
|
|
75
|
+
mutation MagentoSendPasswordResetEmail($email: String!) {
|
|
76
|
+
requestPasswordResetEmail(
|
|
77
|
+
email: $email,
|
|
78
|
+
)
|
|
79
|
+
}
|
|
80
|
+
`;
|
|
81
|
+
const resetPasswordMutation = gql`
|
|
82
|
+
mutation MagentoResetPassword($email: String!, $password: String!, $token: String!) {
|
|
83
|
+
resetPassword(
|
|
84
|
+
email: $email,
|
|
85
|
+
newPassword: $password
|
|
86
|
+
resetPasswordToken: $token
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
`;
|
|
90
|
+
const validateCheckTokenResponse = (response) => {
|
|
91
|
+
if (response.data.customer.email) return response;
|
|
92
|
+
else throw new DaffAuthInvalidAPIResponseError("Check token response does not contain a valid customer email.");
|
|
93
|
+
};
|
|
94
|
+
const validateGenerateTokenResponse = (response) => {
|
|
95
|
+
if (response.data.generateCustomerToken.token) return response;
|
|
96
|
+
else throw new DaffAuthInvalidAPIResponseError("Generate token response does not contain an auth token.");
|
|
97
|
+
};
|
|
98
|
+
const validateRevokeTokenResponse = (response) => {
|
|
99
|
+
if (response.data.revokeCustomerToken.result) return response;
|
|
100
|
+
else throw new DaffAuthInvalidAPIResponseError("Revoke token response does not contain a successful result.");
|
|
101
|
+
};
|
|
102
|
+
const validateSendResetEmailResponse = (response) => {
|
|
103
|
+
if (response.data.requestPasswordResetEmail) return response;
|
|
104
|
+
else throw new DaffAuthInvalidAPIResponseError("The reset password email was not sent successfully.");
|
|
105
|
+
};
|
|
106
|
+
const validateResetPasswordResponse = (response) => {
|
|
107
|
+
if (response.data.resetPassword) return response;
|
|
108
|
+
else throw new DaffAuthInvalidAPIResponseError("The password was not reset.");
|
|
109
|
+
};
|
|
110
|
+
var DaffMagentoAuthService = class DaffMagentoAuthService {
|
|
111
|
+
constructor(apollo) {
|
|
112
|
+
this.apollo = apollo;
|
|
113
|
+
}
|
|
114
|
+
check() {
|
|
115
|
+
return this.apollo.query({
|
|
116
|
+
query: checkTokenQuery,
|
|
117
|
+
fetchPolicy: "no-cache"
|
|
118
|
+
}).pipe(map(validateCheckTokenResponse), map(() => void 0), catchError((err) => throwError(() => transformMagentoAuthError(err))));
|
|
119
|
+
}
|
|
120
|
+
static {
|
|
121
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
122
|
+
minVersion: "12.0.0",
|
|
123
|
+
version: "22.2.4",
|
|
124
|
+
ngImport: i0,
|
|
125
|
+
type: DaffMagentoAuthService,
|
|
126
|
+
deps: [{ token: i1$2.Apollo }],
|
|
127
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
static {
|
|
131
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
132
|
+
minVersion: "12.0.0",
|
|
133
|
+
version: "22.2.4",
|
|
134
|
+
ngImport: i0,
|
|
135
|
+
type: DaffMagentoAuthService,
|
|
136
|
+
providedIn: "root"
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
141
|
+
minVersion: "12.0.0",
|
|
142
|
+
version: "22.2.4",
|
|
143
|
+
ngImport: i0,
|
|
144
|
+
type: DaffMagentoAuthService,
|
|
145
|
+
decorators: [{
|
|
146
|
+
type: Injectable,
|
|
147
|
+
args: [{ providedIn: "root" }]
|
|
148
|
+
}],
|
|
149
|
+
ctorParameters: () => [{ type: i1$2.Apollo }]
|
|
150
|
+
});
|
|
151
|
+
var DaffMagentoAuthTransformerService = class DaffMagentoAuthTransformerService {
|
|
152
|
+
transform(auth) {
|
|
153
|
+
return { token: auth.token };
|
|
154
|
+
}
|
|
155
|
+
static {
|
|
156
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
157
|
+
minVersion: "12.0.0",
|
|
158
|
+
version: "22.2.4",
|
|
159
|
+
ngImport: i0,
|
|
160
|
+
type: DaffMagentoAuthTransformerService,
|
|
161
|
+
deps: [],
|
|
162
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
static {
|
|
166
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
167
|
+
minVersion: "12.0.0",
|
|
168
|
+
version: "22.2.4",
|
|
169
|
+
ngImport: i0,
|
|
170
|
+
type: DaffMagentoAuthTransformerService,
|
|
171
|
+
providedIn: "root"
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
176
|
+
minVersion: "12.0.0",
|
|
177
|
+
version: "22.2.4",
|
|
178
|
+
ngImport: i0,
|
|
179
|
+
type: DaffMagentoAuthTransformerService,
|
|
180
|
+
decorators: [{
|
|
181
|
+
type: Injectable,
|
|
182
|
+
args: [{ providedIn: "root" }]
|
|
183
|
+
}]
|
|
184
|
+
});
|
|
185
|
+
var DaffMagentoLoginService = class DaffMagentoLoginService {
|
|
186
|
+
constructor(apollo, authTransformer) {
|
|
187
|
+
this.apollo = apollo;
|
|
188
|
+
this.authTransformer = authTransformer;
|
|
189
|
+
}
|
|
190
|
+
login({ email, password }) {
|
|
191
|
+
return this.apollo.mutate({
|
|
192
|
+
mutation: generateTokenMutation,
|
|
193
|
+
variables: {
|
|
194
|
+
email,
|
|
195
|
+
password
|
|
196
|
+
}
|
|
197
|
+
}).pipe(map(validateGenerateTokenResponse), map((res) => this.authTransformer.transform(res.data.generateCustomerToken)), catchError((err) => throwError(() => transformMagentoAuthError(err))));
|
|
198
|
+
}
|
|
199
|
+
logout() {
|
|
200
|
+
return this.apollo.mutate({ mutation: revokeCustomerTokenMutation }).pipe(map(validateRevokeTokenResponse), map(() => void 0), catchError((err) => throwError(() => transformMagentoAuthError(err))));
|
|
201
|
+
}
|
|
202
|
+
static {
|
|
203
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
204
|
+
minVersion: "12.0.0",
|
|
205
|
+
version: "22.2.4",
|
|
206
|
+
ngImport: i0,
|
|
207
|
+
type: DaffMagentoLoginService,
|
|
208
|
+
deps: [{ token: i1$1.DaffQueuedApollo }, { token: DaffMagentoAuthTransformerService }],
|
|
209
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
static {
|
|
213
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
214
|
+
minVersion: "12.0.0",
|
|
215
|
+
version: "22.2.4",
|
|
216
|
+
ngImport: i0,
|
|
217
|
+
type: DaffMagentoLoginService,
|
|
218
|
+
providedIn: "root"
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
223
|
+
minVersion: "12.0.0",
|
|
224
|
+
version: "22.2.4",
|
|
225
|
+
ngImport: i0,
|
|
226
|
+
type: DaffMagentoLoginService,
|
|
227
|
+
decorators: [{
|
|
228
|
+
type: Injectable,
|
|
229
|
+
args: [{ providedIn: "root" }]
|
|
230
|
+
}],
|
|
231
|
+
ctorParameters: () => [{ type: i1$1.DaffQueuedApollo }, { type: DaffMagentoAuthTransformerService }]
|
|
232
|
+
});
|
|
233
|
+
var DaffMagentoRegisterService = class DaffMagentoRegisterService {
|
|
234
|
+
constructor(apollo, loginService) {
|
|
235
|
+
this.apollo = apollo;
|
|
236
|
+
this.loginService = loginService;
|
|
237
|
+
}
|
|
238
|
+
register(registration) {
|
|
239
|
+
return this.registerOnly(registration).pipe(switchMap(() => this.loginService.login({
|
|
240
|
+
email: registration.email,
|
|
241
|
+
password: registration.password
|
|
242
|
+
})), map(({ token }) => token));
|
|
243
|
+
}
|
|
244
|
+
registerOnly({ email, password, subscribe, firstName, lastName }) {
|
|
245
|
+
return this.apollo.mutate({
|
|
246
|
+
mutation: createCustomerMutation,
|
|
247
|
+
variables: {
|
|
248
|
+
email,
|
|
249
|
+
password,
|
|
250
|
+
firstname: firstName || "temp",
|
|
251
|
+
lastname: lastName || "temp",
|
|
252
|
+
subscribe
|
|
253
|
+
}
|
|
254
|
+
}).pipe(map((resp) => {
|
|
255
|
+
if (!resp.data.createCustomerV2.customer.email) throw new DaffRegistrationFailedError(`The account for email ${email} was not successful.`);
|
|
256
|
+
}), catchError((err) => throwError(() => transformMagentoAuthError(err))));
|
|
257
|
+
}
|
|
258
|
+
static {
|
|
259
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
260
|
+
minVersion: "12.0.0",
|
|
261
|
+
version: "22.2.4",
|
|
262
|
+
ngImport: i0,
|
|
263
|
+
type: DaffMagentoRegisterService,
|
|
264
|
+
deps: [{ token: i1$1.DaffQueuedApollo }, { token: DaffMagentoLoginService }],
|
|
265
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
static {
|
|
269
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
270
|
+
minVersion: "12.0.0",
|
|
271
|
+
version: "22.2.4",
|
|
272
|
+
ngImport: i0,
|
|
273
|
+
type: DaffMagentoRegisterService,
|
|
274
|
+
providedIn: "root"
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
279
|
+
minVersion: "12.0.0",
|
|
280
|
+
version: "22.2.4",
|
|
281
|
+
ngImport: i0,
|
|
282
|
+
type: DaffMagentoRegisterService,
|
|
283
|
+
decorators: [{
|
|
284
|
+
type: Injectable,
|
|
285
|
+
args: [{ providedIn: "root" }]
|
|
286
|
+
}],
|
|
287
|
+
ctorParameters: () => [{ type: i1$1.DaffQueuedApollo }, { type: DaffMagentoLoginService }]
|
|
288
|
+
});
|
|
289
|
+
var DaffMagentoResetPasswordService = class DaffMagentoResetPasswordService {
|
|
290
|
+
constructor(apollo, loginService) {
|
|
291
|
+
this.apollo = apollo;
|
|
292
|
+
this.loginService = loginService;
|
|
293
|
+
}
|
|
294
|
+
resetPassword(info) {
|
|
295
|
+
return this.resetPasswordOnly(info).pipe(switchMap(() => this.loginService.login({
|
|
296
|
+
email: info.email,
|
|
297
|
+
password: info.password
|
|
298
|
+
})), map(({ token }) => token));
|
|
299
|
+
}
|
|
300
|
+
resetPasswordOnly({ email, password, token }) {
|
|
301
|
+
return this.apollo.mutate({
|
|
302
|
+
mutation: resetPasswordMutation,
|
|
303
|
+
variables: {
|
|
304
|
+
email,
|
|
305
|
+
password,
|
|
306
|
+
token
|
|
307
|
+
}
|
|
308
|
+
}).pipe(map(validateResetPasswordResponse), map(() => void 0), catchError((err) => throwError(() => transformMagentoAuthError(err))));
|
|
309
|
+
}
|
|
310
|
+
sendResetEmail(email) {
|
|
311
|
+
return this.apollo.mutate({
|
|
312
|
+
mutation: sendPasswordResetEmailMutation,
|
|
313
|
+
variables: { email }
|
|
314
|
+
}).pipe(map(validateSendResetEmailResponse), map(() => void 0), catchError((err) => throwError(() => transformMagentoAuthError(err))));
|
|
315
|
+
}
|
|
316
|
+
static {
|
|
317
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
318
|
+
minVersion: "12.0.0",
|
|
319
|
+
version: "22.2.4",
|
|
320
|
+
ngImport: i0,
|
|
321
|
+
type: DaffMagentoResetPasswordService,
|
|
322
|
+
deps: [{ token: i1$1.DaffQueuedApollo }, { token: DaffMagentoLoginService }],
|
|
323
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
static {
|
|
327
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
328
|
+
minVersion: "12.0.0",
|
|
329
|
+
version: "22.2.4",
|
|
330
|
+
ngImport: i0,
|
|
331
|
+
type: DaffMagentoResetPasswordService,
|
|
332
|
+
providedIn: "root"
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
337
|
+
minVersion: "12.0.0",
|
|
338
|
+
version: "22.2.4",
|
|
339
|
+
ngImport: i0,
|
|
340
|
+
type: DaffMagentoResetPasswordService,
|
|
341
|
+
decorators: [{
|
|
342
|
+
type: Injectable,
|
|
343
|
+
args: [{ providedIn: "root" }]
|
|
344
|
+
}],
|
|
345
|
+
ctorParameters: () => [{ type: i1$1.DaffQueuedApollo }, { type: DaffMagentoLoginService }]
|
|
346
|
+
});
|
|
347
|
+
const provideDaffAuthMagentoDriver = () => makeEnvironmentProviders([
|
|
348
|
+
provideDaffRegisterDriver(DaffMagentoRegisterService),
|
|
349
|
+
provideDaffLoginDriver(DaffMagentoLoginService),
|
|
350
|
+
provideDaffAuthDriver(DaffMagentoAuthService),
|
|
351
|
+
provideDaffResetPasswordDriver(DaffMagentoResetPasswordService)
|
|
352
|
+
]);
|
|
353
|
+
var DaffAuthMagentoDriverModule = class DaffAuthMagentoDriverModule {
|
|
354
|
+
static forRoot() {
|
|
355
|
+
return {
|
|
356
|
+
ngModule: DaffAuthMagentoDriverModule,
|
|
357
|
+
providers: [provideDaffAuthMagentoDriver()]
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
static {
|
|
361
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
362
|
+
minVersion: "12.0.0",
|
|
363
|
+
version: "22.2.4",
|
|
364
|
+
ngImport: i0,
|
|
365
|
+
type: DaffAuthMagentoDriverModule,
|
|
366
|
+
deps: [],
|
|
367
|
+
target: i0.ɵɵFactoryTarget.NgModule
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
static {
|
|
371
|
+
this.ɵmod = i0.ɵɵngDeclareNgModule({
|
|
372
|
+
minVersion: "14.0.0",
|
|
373
|
+
version: "22.2.4",
|
|
374
|
+
ngImport: i0,
|
|
375
|
+
type: DaffAuthMagentoDriverModule,
|
|
376
|
+
imports: [CommonModule]
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
static {
|
|
380
|
+
this.ɵinj = i0.ɵɵngDeclareInjector({
|
|
381
|
+
minVersion: "12.0.0",
|
|
382
|
+
version: "22.2.4",
|
|
383
|
+
ngImport: i0,
|
|
384
|
+
type: DaffAuthMagentoDriverModule,
|
|
385
|
+
imports: [CommonModule]
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
390
|
+
minVersion: "12.0.0",
|
|
391
|
+
version: "22.2.4",
|
|
392
|
+
ngImport: i0,
|
|
393
|
+
type: DaffAuthMagentoDriverModule,
|
|
394
|
+
decorators: [{
|
|
395
|
+
type: NgModule,
|
|
396
|
+
args: [{ imports: [CommonModule] }]
|
|
397
|
+
}]
|
|
398
|
+
});
|
|
399
|
+
function withAuth() {
|
|
400
|
+
return makeMagentoDriverFeature("MagentoAuthApolloBearerToken", [provideMagentoAuthApolloBearerToken()]);
|
|
401
|
+
}
|
|
402
|
+
function provideMagentoAuthApolloBearerToken() {
|
|
403
|
+
return makeEnvironmentProviders([provideDaffApolloHeaderProviders(() => {
|
|
404
|
+
const storage = inject(DaffAuthStorageService);
|
|
405
|
+
let token = null;
|
|
406
|
+
try {
|
|
407
|
+
token = storage.getAuthToken();
|
|
408
|
+
} catch (e) {}
|
|
409
|
+
return new HttpHeaders(token ? { authorization: `Bearer ${token}` } : {});
|
|
410
|
+
})]);
|
|
411
|
+
}
|
|
412
|
+
var MagentoAuthApolloBearerTokenLinkGenerator = class MagentoAuthApolloBearerTokenLinkGenerator {
|
|
413
|
+
constructor(storage) {
|
|
414
|
+
this.storage = storage;
|
|
415
|
+
}
|
|
416
|
+
getLink() {
|
|
417
|
+
return new ApolloLink((operation, forward) => {
|
|
418
|
+
let token = null;
|
|
419
|
+
try {
|
|
420
|
+
token = this.storage.getAuthToken();
|
|
421
|
+
} catch (e) {}
|
|
422
|
+
if (token) operation.setContext({ headers: getApolloOperationHeaders(operation).append("authorization", `Bearer ${token}`) });
|
|
423
|
+
return forward(operation);
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
static {
|
|
427
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
428
|
+
minVersion: "12.0.0",
|
|
429
|
+
version: "22.2.4",
|
|
430
|
+
ngImport: i0,
|
|
431
|
+
type: MagentoAuthApolloBearerTokenLinkGenerator,
|
|
432
|
+
deps: [{ token: i1.DaffAuthStorageService }],
|
|
433
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
static {
|
|
437
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
438
|
+
minVersion: "12.0.0",
|
|
439
|
+
version: "22.2.4",
|
|
440
|
+
ngImport: i0,
|
|
441
|
+
type: MagentoAuthApolloBearerTokenLinkGenerator,
|
|
442
|
+
providedIn: "root"
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
};
|
|
446
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
447
|
+
minVersion: "12.0.0",
|
|
448
|
+
version: "22.2.4",
|
|
449
|
+
ngImport: i0,
|
|
450
|
+
type: MagentoAuthApolloBearerTokenLinkGenerator,
|
|
451
|
+
decorators: [{
|
|
452
|
+
type: Injectable,
|
|
453
|
+
args: [{ providedIn: "root" }]
|
|
454
|
+
}],
|
|
455
|
+
ctorParameters: () => [{ type: i1.DaffAuthStorageService }]
|
|
456
|
+
});
|
|
457
|
+
export { DaffAuthMagentoDriverModule, DaffMagentoAuthService, DaffMagentoAuthTransformerService, DaffMagentoLoginService, DaffMagentoRegisterService, MagentoAuthApolloBearerTokenLinkGenerator, checkTokenQuery, createCustomerMutation, generateTokenMutation, provideDaffAuthMagentoDriver, provideMagentoAuthApolloBearerToken, resetPasswordMutation, revokeCustomerTokenMutation, sendPasswordResetEmailMutation, withAuth };
|
|
458
|
+
|
|
459
|
+
//# sourceMappingURL=daffodil-auth-driver-magento-2.4.7.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"daffodil-auth-driver-magento-2.4.7.mjs","names":["i1","i1","i2.DaffMagentoAuthTransformerService","i1","i2.DaffMagentoLoginService","i1","i2.DaffMagentoLoginService"],"sources":["../../../libs/auth/driver/magento/2.4.7/src/errors/codes.ts","../../../libs/auth/driver/magento/2.4.7/src/errors/map.ts","../../../libs/auth/driver/magento/2.4.7/src/errors/transform.ts","../../../libs/auth/driver/magento/2.4.7/src/queries/check-token.ts","../../../libs/auth/driver/magento/2.4.7/src/queries/create-customer.ts","../../../libs/auth/driver/magento/2.4.7/src/queries/generate-token.ts","../../../libs/auth/driver/magento/2.4.7/src/queries/revoke-customer-token.ts","../../../libs/auth/driver/magento/2.4.7/src/queries/send-reset-email.ts","../../../libs/auth/driver/magento/2.4.7/src/queries/reset-password.ts","../../../libs/auth/driver/magento/2.4.7/src/validators/check-token.ts","../../../libs/auth/driver/magento/2.4.7/src/validators/generate-token.ts","../../../libs/auth/driver/magento/2.4.7/src/validators/revoke-token.ts","../../../libs/auth/driver/magento/2.4.7/src/validators/send-reset-email.ts","../../../libs/auth/driver/magento/2.4.7/src/validators/reset-password.ts","../../../libs/auth/driver/magento/2.4.7/src/auth.service.ts","../../../libs/auth/driver/magento/2.4.7/src/transforms/auth-transformer.service.ts","../../../libs/auth/driver/magento/2.4.7/src/login.service.ts","../../../libs/auth/driver/magento/2.4.7/src/register.service.ts","../../../libs/auth/driver/magento/2.4.7/src/reset-password.service.ts","../../../libs/auth/driver/magento/2.4.7/src/provider.ts","../../../libs/auth/driver/magento/2.4.7/src/auth-driver.module.ts","../../../libs/auth/driver/magento/2.4.7/src/apollo-bearer-token-link-generator.ts"],"sourcesContent":["export enum MagentoAuthGraphQlErrorCode {\n UNAUTHORIZED = 'graphql-authorization',\n AUTHENTICATION_FAILED = 'graphql-authentication',\n BAD_INPUT = 'graphql-input'\n}\n","import {\n DaffUnauthorizedError,\n DaffAuthenticationFailedError,\n} from '@daffodil/auth/driver';\nimport { DaffErrorCodeMap } from '@daffodil/core';\nimport { DaffBadInputError } from '@daffodil/driver';\n\nimport { MagentoAuthGraphQlErrorCode } from './codes';\n\nexport const DaffAuthMagentoErrorMap: DaffErrorCodeMap = {\n [MagentoAuthGraphQlErrorCode.UNAUTHORIZED]: DaffUnauthorizedError,\n [MagentoAuthGraphQlErrorCode.AUTHENTICATION_FAILED]: DaffAuthenticationFailedError,\n [MagentoAuthGraphQlErrorCode.BAD_INPUT]: DaffBadInputError,\n};\n","import { DaffAuthInvalidAPIResponseError } from '@daffodil/auth/driver';\nimport { daffTransformMagentoError } from '@daffodil/driver/magento/2.4.7';\n\nimport { DaffAuthMagentoErrorMap } from './map';\n\nexport const transformMagentoAuthError = (error: any): Error => daffTransformMagentoError(error, DaffAuthMagentoErrorMap) || new DaffAuthInvalidAPIResponseError(error.message);\n","import { gql } from 'apollo-angular';\n\n\nexport const checkTokenQuery = gql`\n query MagentoCheckToken {\n customer {\n email\n }\n }\n`;\n","import { gql } from 'apollo-angular';\n\n\nexport const createCustomerMutation = gql`\n mutation MagentoCreateCustomer(\n $email: String!,\n $password: String!,\n $subscribe: Boolean!,\n $firstname: String!,\n $lastname: String!,\n ) {\n createCustomerV2(input: {\n firstname: $firstname,\n lastname: $lastname,\n email: $email,\n password: $password,\n is_subscribed: $subscribe\n }) {\n customer {\n email\n }\n }\n }\n`;\n","import { gql } from 'apollo-angular';\n\n\nexport const generateTokenMutation = gql`\n mutation MagentoGenerateToken($email: String!, $password: String!) {\n generateCustomerToken(\n email: $email,\n password: $password\n ) {\n token\n }\n }\n`;\n","import { gql } from 'apollo-angular';\n\n\nexport const revokeCustomerTokenMutation = gql`\n mutation revokeCustomerToken {\n revokeCustomerToken {\n result\n }\n }\n`;\n","import { gql } from 'apollo-angular';\n\n\nexport const sendPasswordResetEmailMutation = gql`\n mutation MagentoSendPasswordResetEmail($email: String!) {\n requestPasswordResetEmail(\n email: $email,\n )\n }\n`;\n","import { gql } from 'apollo-angular';\n\n\nexport const resetPasswordMutation = gql`\n mutation MagentoResetPassword($email: String!, $password: String!, $token: String!) {\n resetPassword(\n email: $email,\n newPassword: $password\n resetPasswordToken: $token\n )\n }\n`;\n","import { Apollo } from 'apollo-angular';\n\nimport { DaffAuthInvalidAPIResponseError } from '@daffodil/auth/driver';\n\nimport { MagentoCheckTokenResponse } from '../queries/public_api';\n\nexport const validateCheckTokenResponse = (response: Apollo.QueryResult<MagentoCheckTokenResponse>) => {\n if (response.data.customer.email) {\n return response;\n } else {\n throw new DaffAuthInvalidAPIResponseError('Check token response does not contain a valid customer email.');\n }\n};\n","import { Apollo } from 'apollo-angular';\n\nimport { DaffAuthInvalidAPIResponseError } from '@daffodil/auth/driver';\n\nimport { MagentoGenerateTokenResponse } from '../queries/public_api';\n\nexport const validateGenerateTokenResponse = (response: Apollo.QueryResult<MagentoGenerateTokenResponse>) => {\n if (response.data.generateCustomerToken.token) {\n return response;\n } else {\n throw new DaffAuthInvalidAPIResponseError('Generate token response does not contain an auth token.');\n }\n};\n","import { Apollo } from 'apollo-angular';\n\nimport { DaffAuthInvalidAPIResponseError } from '@daffodil/auth/driver';\n\nimport { MagentoRevokeCustomerTokenResponse } from '../queries/public_api';\n\nexport const validateRevokeTokenResponse = (response: Apollo.QueryResult<MagentoRevokeCustomerTokenResponse>) => {\n if (response.data.revokeCustomerToken.result) {\n return response;\n } else {\n throw new DaffAuthInvalidAPIResponseError('Revoke token response does not contain a successful result.');\n }\n};\n","import { Apollo } from 'apollo-angular';\n\nimport { DaffAuthInvalidAPIResponseError } from '@daffodil/auth/driver';\n\nimport { MagentoSendResetEmailResponse } from '../models/public_api';\n\nexport const validateSendResetEmailResponse = (response: Apollo.QueryResult<MagentoSendResetEmailResponse>) => {\n if (response.data.requestPasswordResetEmail) {\n return response;\n } else {\n throw new DaffAuthInvalidAPIResponseError('The reset password email was not sent successfully.');\n }\n};\n","import { Apollo } from 'apollo-angular';\n\nimport { DaffAuthInvalidAPIResponseError } from '@daffodil/auth/driver';\n\nimport { MagentoResetPasswordResponse } from '../models/public_api';\n\nexport const validateResetPasswordResponse = (response: Apollo.QueryResult<MagentoResetPasswordResponse>) => {\n if (response.data.resetPassword) {\n return response;\n } else {\n throw new DaffAuthInvalidAPIResponseError('The password was not reset.');\n }\n};\n","import { Injectable } from '@angular/core';\nimport { Apollo } from 'apollo-angular';\nimport {\n Observable,\n throwError,\n} from 'rxjs';\nimport {\n catchError,\n map,\n} from 'rxjs/operators';\n\nimport { DaffAuthServiceInterface } from '@daffodil/auth/driver';\n\nimport { transformMagentoAuthError } from './errors/transform';\nimport {\n checkTokenQuery,\n MagentoCheckTokenResponse,\n} from './queries/public_api';\nimport { validateCheckTokenResponse } from './validators/public_api';\n\n/**\n * @inheritdoc\n */\n@Injectable({\n providedIn: 'root',\n})\nexport class DaffMagentoAuthService implements DaffAuthServiceInterface {\n constructor(private apollo: Apollo) {}\n\n check(): Observable<void> {\n return this.apollo.query<MagentoCheckTokenResponse>({\n query: checkTokenQuery,\n fetchPolicy: 'no-cache',\n }).pipe(\n map(validateCheckTokenResponse),\n map(() => undefined),\n catchError(err => throwError(() => transformMagentoAuthError(err))),\n );\n }\n}\n","import { Injectable } from '@angular/core';\n\nimport { DaffAuthToken } from '@daffodil/auth';\n\nimport { MagentoAuth } from '../models/response/auth';\n\n/**\n * Transforms magento auths into an object usable by daffodil.\n */\n@Injectable({\n providedIn: 'root',\n})\nexport class DaffMagentoAuthTransformerService {\n\n /**\n * Transforms the magento AuthNode from the magento auth query into a DaffAuthToken.\n *\n * @param auth the auth from a magento auth query.\n */\n transform(auth: MagentoAuth): DaffAuthToken {\n return {\n token: auth.token,\n };\n }\n}\n","import { Injectable } from '@angular/core';\nimport {\n Observable,\n throwError,\n} from 'rxjs';\nimport {\n map,\n catchError,\n} from 'rxjs/operators';\n\nimport {\n DaffLoginInfo,\n DaffAuthToken,\n} from '@daffodil/auth';\nimport { DaffLoginServiceInterface } from '@daffodil/auth/driver';\nimport { DaffQueuedApollo } from '@daffodil/core/graphql';\n\nimport { transformMagentoAuthError } from './errors/transform';\nimport {\n MagentoRevokeCustomerTokenResponse,\n MagentoGenerateTokenResponse,\n generateTokenMutation,\n revokeCustomerTokenMutation,\n} from './queries/public_api';\nimport { DaffMagentoAuthTransformerService } from './transforms/auth-transformer.service';\nimport {\n validateRevokeTokenResponse,\n validateGenerateTokenResponse,\n} from './validators/public_api';\n\n/**\n * @inheritdoc\n */\n@Injectable({\n providedIn: 'root',\n})\nexport class DaffMagentoLoginService implements DaffLoginServiceInterface {\n constructor(\n private apollo: DaffQueuedApollo,\n public authTransformer: DaffMagentoAuthTransformerService,\n ) {}\n\n login({ email, password }: DaffLoginInfo): Observable<DaffAuthToken> {\n return this.apollo.mutate<MagentoGenerateTokenResponse>({\n mutation: generateTokenMutation,\n variables: {\n email,\n password,\n },\n }).pipe(\n map(validateGenerateTokenResponse),\n map(res => this.authTransformer.transform(res.data.generateCustomerToken)),\n catchError(err => throwError(() => transformMagentoAuthError(err))),\n );\n }\n\n logout() {\n return this.apollo.mutate<MagentoRevokeCustomerTokenResponse>({ mutation: revokeCustomerTokenMutation }).pipe(\n map(validateRevokeTokenResponse),\n map(() => undefined),\n catchError(err => throwError(() => transformMagentoAuthError(err))),\n );\n }\n}\n","import { Injectable } from '@angular/core';\nimport {\n Observable,\n throwError,\n} from 'rxjs';\nimport {\n map,\n catchError,\n switchMap,\n} from 'rxjs/operators';\n\nimport { DaffAccountRegistration } from '@daffodil/auth';\nimport {\n DaffRegisterServiceInterface,\n DaffRegistrationFailedError,\n} from '@daffodil/auth/driver';\nimport { DaffQueuedApollo } from '@daffodil/core/graphql';\n\nimport { transformMagentoAuthError } from './errors/transform';\nimport { DaffMagentoLoginService } from './login.service';\nimport { MagentoRegisterResponse } from './models/public_api';\nimport { createCustomerMutation } from './queries/public_api';\n\n/**\n * @inheritdoc\n */\n@Injectable({\n providedIn: 'root',\n})\nexport class DaffMagentoRegisterService implements DaffRegisterServiceInterface {\n constructor(\n private apollo: DaffQueuedApollo,\n private loginService: DaffMagentoLoginService,\n ) {}\n\n register(registration: DaffAccountRegistration): Observable<string> {\n return this.registerOnly(registration).pipe(\n switchMap(() => this.loginService.login({ email: registration.email, password: registration.password })),\n map(({ token }) => token),\n );\n }\n\n registerOnly({ email, password, subscribe, firstName, lastName }: DaffAccountRegistration): Observable<void> {\n return this.apollo.mutate<MagentoRegisterResponse>({\n mutation: createCustomerMutation,\n variables: {\n email,\n password,\n firstname: firstName || 'temp',\n lastname: lastName || 'temp',\n subscribe,\n },\n }).pipe(\n map((resp) => {\n if (!resp.data.createCustomerV2.customer.email) {\n throw new DaffRegistrationFailedError(`The account for email ${email} was not successful.`);\n }\n\n return;\n }),\n catchError(err => throwError(() => transformMagentoAuthError(err))),\n );\n }\n}\n","import { Injectable } from '@angular/core';\nimport {\n Observable,\n throwError,\n} from 'rxjs';\nimport {\n map,\n catchError,\n switchMap,\n} from 'rxjs/operators';\n\nimport { DaffAuthResetPasswordInfo } from '@daffodil/auth';\nimport { DaffResetPasswordServiceInterface } from '@daffodil/auth/driver';\nimport { DaffQueuedApollo } from '@daffodil/core/graphql';\n\nimport { transformMagentoAuthError } from './errors/transform';\nimport { DaffMagentoLoginService } from './login.service';\nimport {\n MagentoResetPasswordResponse,\n MagentoSendResetEmailResponse,\n} from './models/public_api';\nimport {\n resetPasswordMutation,\n sendPasswordResetEmailMutation,\n} from './queries/public_api';\nimport {\n validateResetPasswordResponse,\n validateSendResetEmailResponse,\n} from './validators/public_api';\n\n/**\n * @inheritdoc\n */\n@Injectable({\n providedIn: 'root',\n})\nexport class DaffMagentoResetPasswordService implements DaffResetPasswordServiceInterface {\n constructor(\n private apollo: DaffQueuedApollo,\n private loginService: DaffMagentoLoginService,\n ) {}\n\n resetPassword(info: DaffAuthResetPasswordInfo): Observable<string> {\n return this.resetPasswordOnly(info).pipe(\n switchMap(() => this.loginService.login({ email: info.email, password: info.password })),\n map(({ token }) => token),\n );\n }\n\n resetPasswordOnly({ email, password, token }: DaffAuthResetPasswordInfo): Observable<void> {\n return this.apollo.mutate<MagentoResetPasswordResponse>({\n mutation: resetPasswordMutation,\n variables: {\n email,\n password,\n token,\n },\n }).pipe(\n map(validateResetPasswordResponse),\n map(() => undefined),\n catchError(err => throwError(() => transformMagentoAuthError(err))),\n );\n }\n\n sendResetEmail(email: string): Observable<void> {\n return this.apollo.mutate<MagentoSendResetEmailResponse>({\n mutation: sendPasswordResetEmailMutation,\n variables: {\n email,\n },\n }).pipe(\n map(validateSendResetEmailResponse),\n map(() => undefined),\n catchError(err => throwError(() => transformMagentoAuthError(err))),\n );\n }\n}\n","import {\n EnvironmentProviders,\n makeEnvironmentProviders,\n} from '@angular/core';\n\nimport {\n provideDaffRegisterDriver,\n provideDaffLoginDriver,\n provideDaffAuthDriver,\n provideDaffResetPasswordDriver,\n} from '@daffodil/auth/driver';\n\nimport { DaffMagentoAuthService } from './auth.service';\nimport { DaffMagentoLoginService } from './login.service';\nimport { DaffMagentoRegisterService } from './register.service';\nimport { DaffMagentoResetPasswordService } from './reset-password.service';\n\n/**\n * Provides the Magento implementations of the `@daffodil/auth/driver` interfaces.\n */\nexport const provideDaffAuthMagentoDriver = (): EnvironmentProviders => makeEnvironmentProviders([\n provideDaffRegisterDriver(DaffMagentoRegisterService),\n provideDaffLoginDriver(DaffMagentoLoginService),\n provideDaffAuthDriver(DaffMagentoAuthService),\n provideDaffResetPasswordDriver(DaffMagentoResetPasswordService),\n]);\n","import { CommonModule } from '@angular/common';\nimport {\n NgModule,\n ModuleWithProviders,\n} from '@angular/core';\n\nimport { provideDaffAuthMagentoDriver } from './provider';\n\n/**\n * @deprecated in favor of {@link provideDaffAuthMagentoDriver} Deprecated in version 0.95.0. Will be removed in version 0.98.0.\n */\n@NgModule({\n imports: [\n CommonModule,\n ],\n})\nexport class DaffAuthMagentoDriverModule {\n static forRoot(): ModuleWithProviders<DaffAuthMagentoDriverModule> {\n return {\n ngModule: DaffAuthMagentoDriverModule,\n providers: [\n provideDaffAuthMagentoDriver(),\n ],\n };\n }\n}\n","import { HttpHeaders } from '@angular/common/http';\nimport {\n inject,\n Injectable,\n makeEnvironmentProviders,\n} from '@angular/core';\nimport { ApolloLink } from '@apollo/client';\n\nimport { DaffAuthStorageService } from '@daffodil/auth';\nimport {\n DaffApolloLinkGenerator,\n getApolloOperationHeaders,\n provideDaffApolloHeaderProviders,\n} from '@daffodil/core/graphql';\nimport {\n makeMagentoDriverFeature,\n MagentoDriverFeature,\n} from '@daffodil/driver/magento/2.4.7';\n\nexport function withAuth(): MagentoDriverFeature {\n return makeMagentoDriverFeature('MagentoAuthApolloBearerToken', [\n provideMagentoAuthApolloBearerToken(),\n ]);\n}\n\nexport function provideMagentoAuthApolloBearerToken() {\n return makeEnvironmentProviders([\n provideDaffApolloHeaderProviders(() => {\n const storage = inject(DaffAuthStorageService);\n let token = null;\n\n try {\n token = storage.getAuthToken();\n } catch(e){}\n\n return new HttpHeaders(token\n ? {\n authorization: `Bearer ${token}`,\n }\n : {});\n }),\n ]);\n}\n\n/**\n * A service that will convert cacheable apollo operations into a format that Magento will understand as cacheable.\n *\n * @inheritdoc\n */\n@Injectable({\n providedIn: 'root',\n})\nexport class MagentoAuthApolloBearerTokenLinkGenerator implements DaffApolloLinkGenerator {\n constructor(\n private storage: DaffAuthStorageService,\n ) {}\n\n getLink(): ApolloLink {\n return new ApolloLink((operation, forward) => {\n let token = null;\n\n try {\n token = this.storage.getAuthToken();\n } catch(e){}\n\n if (token) {\n operation.setContext({\n headers: getApolloOperationHeaders(operation).append('authorization', `Bearer ${token}`),\n });\n }\n return forward(operation);\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA,IAAY;CAAZ,SAAY,6BAA2B;CACrC,4BAAA,kBAAA;CACA,4BAAA,2BAAA;CACA,4BAAA,eAAA;AACF,EAAA,CAJY,gCAAA,8BAA2B,CAAA,EAAA;ACSvC,MAAa,0BAA4C;EACtD,4BAA4B,eAAe;EAC3C,4BAA4B,wBAAwB;EACpD,4BAA4B,YAAY;AAC1C;ACRD,MAAa,6BAA6B,UAAsB,0BAA0B,OAAO,uBAAuB,KAAK,IAAI,gCAAgC,MAAM,OAAO;ACF9K,MAAa,kBAAkB,GAAG;;;;;;;ACAlC,MAAa,yBAAyB,GAAG;;;;;;;;;;;;;;;;;;;;;ACAzC,MAAa,wBAAwB,GAAG;;;;;;;;;;ACAxC,MAAa,8BAA8B,GAAG;;;;;;;ACA9C,MAAa,iCAAiC,GAAG;;;;;;;ACAjD,MAAa,wBAAwB,GAAG;;;;;;;;;ACGxC,MAAa,8BAA8B,aAA2D;CACpG,IAAI,SAAS,KAAK,SAAS,OACzB,OAAO;MAEP,MAAM,IAAI,gCAAgC,+DAA+D;AAE7G;ACNA,MAAa,iCAAiC,aAA8D;CAC1G,IAAI,SAAS,KAAK,sBAAsB,OACtC,OAAO;MAEP,MAAM,IAAI,gCAAgC,yDAAyD;AAEvG;ACNA,MAAa,+BAA+B,aAAoE;CAC9G,IAAI,SAAS,KAAK,oBAAoB,QACpC,OAAO;MAEP,MAAM,IAAI,gCAAgC,6DAA6D;AAE3G;ACNA,MAAa,kCAAkC,aAA+D;CAC5G,IAAI,SAAS,KAAK,2BAChB,OAAO;MAEP,MAAM,IAAI,gCAAgC,qDAAqD;AAEnG;ACNA,MAAa,iCAAiC,aAA8D;CAC1G,IAAI,SAAS,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AS;EAC1B,CAAC;CACH;CApBW;EAAA,KAAA,OAAA,GAAA,mBAAA;GAAA,YAAA;GAAA,SAAA;GAAA,UAAA;GAAA,MAAA;GAAyC,MAAA,CAAA,EAAA,OAAA,GAAA,uBAAA,CAAA;GAAA,QAAA,GAAA,gBAAA;EAAA,CAAA;CAAA;CAAzC;EAAA,KAAA,QAAA,GAAA,sBAAA;GAAA,YAAA;GAAA,SAAA;GAAA,UAAA;GAAA,MAAA;GAAyC,YAFxC;EAAM,CAAA;CAAA;;AAEP,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAyC,YAAA,CAAA;EAHrD,MAAA;EAAW,MAAA,CAAA,EACV,YAAY,OACb,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { isDevMode } from "@angular/core";
|
|
2
|
+
import { daffAutoDriverErrorMessage } from "@daffodil/driver";
|
|
3
|
+
const MESSAGE = daffAutoDriverErrorMessage("auth");
|
|
4
|
+
if (isDevMode()) throw new Error(MESSAGE);
|
|
5
|
+
else console.error(MESSAGE);
|
|
6
|
+
|
|
7
|
+
//# sourceMappingURL=daffodil-auth-driver-magento-auto.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"daffodil-auth-driver-magento-auto.mjs","names":[],"sources":["../../../libs/auth/driver/magento/auto/src/index.ts"],"sourcesContent":["import { isDevMode } from '@angular/core';\n\nimport { daffAutoDriverErrorMessage } from '@daffodil/driver';\n\nconst MESSAGE = daffAutoDriverErrorMessage('auth');\n\nif (isDevMode()) {\n throw new Error(MESSAGE);\n} else {\n console.error(MESSAGE);\n}\n\nexport {};\n"],"mappings":";;AAIA,MAAM,UAAU,2BAA2B,MAAM;AAEjD,IAAI,UAAS,GACX,MAAM,IAAI,MAAM,OAAO;KAEvB,QAAQ,MAAM,OAAO"}
|