@basetime/a2w-api-ts
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -20,5 +20,5 @@ "use strict"; | ||
// dist/index.js | ||
var dist_exports = {}; | ||
__export(dist_exports, { | ||
// src/index.ts | ||
var src_exports = {}; | ||
__export(src_exports, { | ||
CampaignsEndpoint: () => CampaignsEndpoint, | ||
@@ -29,5 +29,8 @@ ClaimsEndpoint: () => ClaimsEndpoint, | ||
KeysProvider: () => KeysProvider, | ||
OAuthProvider: () => OAuthProvider | ||
OAuthProvider: () => OAuthProvider, | ||
StoredProvider: () => StoredProvider | ||
}); | ||
module.exports = __toCommonJS(dist_exports); | ||
module.exports = __toCommonJS(src_exports); | ||
// src/Endpoint.ts | ||
var Endpoint = class { | ||
@@ -43,2 +46,4 @@ /** | ||
}; | ||
// src/CampaignsEndpoint.ts | ||
var CampaignsEndpoint = class _CampaignsEndpoint extends Endpoint { | ||
@@ -123,2 +128,4 @@ /** | ||
}; | ||
// src/ClaimsEndpoint.ts | ||
var ClaimsEndpoint = class _ClaimsEndpoint extends Endpoint { | ||
@@ -159,2 +166,4 @@ /** | ||
}; | ||
// src/NoopLogger.ts | ||
var NoopLogger = class { | ||
@@ -177,3 +186,7 @@ /** | ||
}; | ||
// src/constants.ts | ||
var baseUrl = process.env.NODE_ENV === "development" ? "https://local.addtowallet.io:5009/api/v1" : "https://app.addtowallet.io/api/v1"; | ||
// src/Client.ts | ||
var Client = class { | ||
@@ -275,2 +288,4 @@ /** | ||
}; | ||
// src/KeysProvider.ts | ||
var KeysProvider = class { | ||
@@ -298,5 +313,3 @@ /** | ||
/** | ||
* Sets the logger to use. | ||
* | ||
* @param logger The logger to use. | ||
* @inheritdoc | ||
*/ | ||
@@ -307,8 +320,3 @@ setLogger = (logger) => { | ||
/** | ||
* Returns the last authentication. | ||
* | ||
* This method is used to retrieve the last successful authentication. In | ||
* includes the id token, refresh token, and the expiration time. | ||
* | ||
* @returns The last authentication. | ||
* @inheritdoc | ||
*/ | ||
@@ -319,9 +327,3 @@ getAuthed = () => { | ||
/** | ||
* Retreives an id token from the a2w API. | ||
* | ||
* This method will authenticate with the a2w API and return the id token. It | ||
* stores the response in the `authed` property. Use the getAuthed method to | ||
* retrieve the last successful authentication. | ||
* | ||
* @returns The id token. | ||
* @inheritdoc | ||
*/ | ||
@@ -371,2 +373,4 @@ authenticate = async () => { | ||
}; | ||
// src/OAuthProvider.ts | ||
var e = encodeURIComponent; | ||
@@ -395,5 +399,3 @@ var OAuthProvider = class { | ||
/** | ||
* Sets the logger to use. | ||
* | ||
* @param logger The logger to use. | ||
* @inheritdoc | ||
*/ | ||
@@ -404,8 +406,3 @@ setLogger = (logger) => { | ||
/** | ||
* Returns the last authentication. | ||
* | ||
* This method is used to retrieve the last successful authentication. In | ||
* includes the id token, refresh token, and the expiration time. | ||
* | ||
* @returns The last authentication. | ||
* @inheritdoc | ||
*/ | ||
@@ -427,3 +424,3 @@ getAuthed = () => { | ||
/** | ||
* Exchanges an oauth code for an id token. | ||
* @inheritdoc | ||
*/ | ||
@@ -473,2 +470,42 @@ authenticate = async () => { | ||
}; | ||
// src/StoredProvider.ts | ||
var StoredProvider = class { | ||
/** | ||
* Constructor. | ||
* | ||
* @param authed The auth credentials. | ||
* @param logger The logger to use. | ||
*/ | ||
constructor(authed, logger) { | ||
this.authed = authed; | ||
this.logger = logger || new NoopLogger(); | ||
} | ||
/** | ||
* The logger. | ||
*/ | ||
logger; | ||
/** | ||
* @inheritdoc | ||
*/ | ||
setLogger = (logger) => { | ||
this.logger = logger; | ||
}; | ||
/** | ||
* @inheritdoc | ||
*/ | ||
getAuthed = () => { | ||
return this.authed; | ||
}; | ||
/** | ||
* @inheritdoc | ||
*/ | ||
authenticate = async () => { | ||
if (this.authed && this.authed.expiresAt > Date.now() / 1e3) { | ||
return this.authed.idToken; | ||
} | ||
this.logger.error("StoredProvider: No valid authed found"); | ||
throw new Error("StoredProvider: No valid authed found"); | ||
}; | ||
}; | ||
// Annotate the CommonJS export names for ESM import in node: | ||
@@ -481,3 +518,4 @@ 0 && (module.exports = { | ||
KeysProvider, | ||
OAuthProvider | ||
OAuthProvider, | ||
StoredProvider | ||
}); |
@@ -6,2 +6,3 @@ export { default as Client } from './Client'; | ||
export { default as OAuthProvider } from './OAuthProvider'; | ||
export { default as StoredProvider } from './StoredProvider'; | ||
export { default as Endpoint } from './Endpoint'; | ||
@@ -8,0 +9,0 @@ export type { Logger } from './Logger'; |
@@ -274,5 +274,3 @@ // src/Endpoint.ts | ||
/** | ||
* Sets the logger to use. | ||
* | ||
* @param logger The logger to use. | ||
* @inheritdoc | ||
*/ | ||
@@ -283,8 +281,3 @@ setLogger = (logger) => { | ||
/** | ||
* Returns the last authentication. | ||
* | ||
* This method is used to retrieve the last successful authentication. In | ||
* includes the id token, refresh token, and the expiration time. | ||
* | ||
* @returns The last authentication. | ||
* @inheritdoc | ||
*/ | ||
@@ -295,9 +288,3 @@ getAuthed = () => { | ||
/** | ||
* Retreives an id token from the a2w API. | ||
* | ||
* This method will authenticate with the a2w API and return the id token. It | ||
* stores the response in the `authed` property. Use the getAuthed method to | ||
* retrieve the last successful authentication. | ||
* | ||
* @returns The id token. | ||
* @inheritdoc | ||
*/ | ||
@@ -372,5 +359,3 @@ authenticate = async () => { | ||
/** | ||
* Sets the logger to use. | ||
* | ||
* @param logger The logger to use. | ||
* @inheritdoc | ||
*/ | ||
@@ -381,8 +366,3 @@ setLogger = (logger) => { | ||
/** | ||
* Returns the last authentication. | ||
* | ||
* This method is used to retrieve the last successful authentication. In | ||
* includes the id token, refresh token, and the expiration time. | ||
* | ||
* @returns The last authentication. | ||
* @inheritdoc | ||
*/ | ||
@@ -404,3 +384,3 @@ getAuthed = () => { | ||
/** | ||
* Exchanges an oauth code for an id token. | ||
* @inheritdoc | ||
*/ | ||
@@ -450,2 +430,42 @@ authenticate = async () => { | ||
}; | ||
// src/StoredProvider.ts | ||
var StoredProvider = class { | ||
/** | ||
* Constructor. | ||
* | ||
* @param authed The auth credentials. | ||
* @param logger The logger to use. | ||
*/ | ||
constructor(authed, logger) { | ||
this.authed = authed; | ||
this.logger = logger || new NoopLogger(); | ||
} | ||
/** | ||
* The logger. | ||
*/ | ||
logger; | ||
/** | ||
* @inheritdoc | ||
*/ | ||
setLogger = (logger) => { | ||
this.logger = logger; | ||
}; | ||
/** | ||
* @inheritdoc | ||
*/ | ||
getAuthed = () => { | ||
return this.authed; | ||
}; | ||
/** | ||
* @inheritdoc | ||
*/ | ||
authenticate = async () => { | ||
if (this.authed && this.authed.expiresAt > Date.now() / 1e3) { | ||
return this.authed.idToken; | ||
} | ||
this.logger.error("StoredProvider: No valid authed found"); | ||
throw new Error("StoredProvider: No valid authed found"); | ||
}; | ||
}; | ||
export { | ||
@@ -457,3 +477,4 @@ CampaignsEndpoint, | ||
KeysProvider, | ||
OAuthProvider | ||
OAuthProvider, | ||
StoredProvider | ||
}; |
@@ -30,26 +30,13 @@ import { AuthProvider } from './AuthProvider'; | ||
/** | ||
* Sets the logger to use. | ||
* | ||
* @param logger The logger to use. | ||
* @inheritdoc | ||
*/ | ||
setLogger: (logger: Logger) => void; | ||
/** | ||
* Returns the last authentication. | ||
* | ||
* This method is used to retrieve the last successful authentication. In | ||
* includes the id token, refresh token, and the expiration time. | ||
* | ||
* @returns The last authentication. | ||
* @inheritdoc | ||
*/ | ||
getAuthed: () => Authed | undefined; | ||
/** | ||
* Retreives an id token from the a2w API. | ||
* | ||
* This method will authenticate with the a2w API and return the id token. It | ||
* stores the response in the `authed` property. Use the getAuthed method to | ||
* retrieve the last successful authentication. | ||
* | ||
* @returns The id token. | ||
* @inheritdoc | ||
*/ | ||
authenticate: () => Promise<string>; | ||
} |
@@ -27,14 +27,7 @@ import { AuthProvider } from './AuthProvider'; | ||
/** | ||
* Sets the logger to use. | ||
* | ||
* @param logger The logger to use. | ||
* @inheritdoc | ||
*/ | ||
setLogger: (logger: Logger) => void; | ||
/** | ||
* Returns the last authentication. | ||
* | ||
* This method is used to retrieve the last successful authentication. In | ||
* includes the id token, refresh token, and the expiration time. | ||
* | ||
* @returns The last authentication. | ||
* @inheritdoc | ||
*/ | ||
@@ -51,5 +44,5 @@ getAuthed: () => Authed | undefined; | ||
/** | ||
* Exchanges an oauth code for an id token. | ||
* @inheritdoc | ||
*/ | ||
authenticate: () => Promise<string>; | ||
} |
{ | ||
"name": "@basetime/a2w-api-ts", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"private": false, | ||
@@ -30,3 +30,3 @@ "description": "Client library that communicates with the addtowallet API.", | ||
"build:es": "pnpm esbuild --bundle --platform=node --target=node14 --outdir=dist --sourcemap=external --format=esm src/index.ts && tsc", | ||
"build:cjs": "pnpm esbuild --bundle --platform=node --target=node14 --outfile=dist/index.cjs.js --format=cjs dist/index.js", | ||
"build:cjs": "pnpm esbuild --bundle --platform=node --target=node14 --outfile=dist/index.cjs.js --format=cjs src/index.ts", | ||
"clean": "rm -rf dist", | ||
@@ -33,0 +33,0 @@ "prepare": "pnpm clean && pnpm build", |
Sorry, the diff of this file is not supported yet
85335
35
2443