Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 4b001fd

Browse files
authored
feat(application keys): adds Application Keys endpoint (#725)
* feat(application keys): adds Application Keys endpoint * Types file for application keys * Adds application keys to moltin js file * moltin.d.ts file * Remove unneeded crudqueryresource
1 parent 73a2501 commit 4b001fd

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-0
lines changed

src/endpoints/application-keys.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import CRUDExtend from '../extends/crud'
2+
import { buildURL } from '../utils/helpers'
3+
4+
class ApplicationKeysEndpoint extends CRUDExtend {
5+
constructor(endpoint) {
6+
super(endpoint)
7+
this.endpoint = 'application-keys'
8+
}
9+
10+
Create(body) {
11+
return this.request.send(this.endpoint, 'POST', body)
12+
}
13+
14+
All(token = null, headers = {}) {
15+
const { limit, offset, filter } = this
16+
17+
this.call = this.request.send(
18+
buildURL(this.endpoint, {
19+
limit,
20+
offset,
21+
filter
22+
}),
23+
'GET',
24+
undefined,
25+
token,
26+
this,
27+
headers
28+
)
29+
30+
return this.call
31+
}
32+
33+
Delete(id) {
34+
return this.request.send(`${this.endpoint}/${id}`, 'DELETE')
35+
}
36+
}
37+
38+
export default ApplicationKeysEndpoint

src/moltin.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import { DataEntriesEndpoint } from './types/data-entries'
5353
import { ErasureRequestsEndpoint } from './types/erasure-requests'
5454
import { PriceBookPriceModifierEndpoint } from './types/price-book-price-modifiers'
5555
import { AccountMembershipSettingsEndpoint } from './types/account-membership-settings'
56+
import { ApplicationKeysEndpoint } from './types/application-keys'
5657

5758
export * from './types/config'
5859
export * from './types/storage'
@@ -116,6 +117,7 @@ export * from './types/user-authentication-info'
116117
export * from './types/user-authentication-password-profile'
117118
export * from './types/locales'
118119
export * from './types/extensions'
120+
export * from './types/application-keys'
119121

120122
// UMD
121123
export as namespace moltin
@@ -171,6 +173,7 @@ export class Moltin {
171173
DataEntries: DataEntriesEndpoint
172174
ErasureRequests: ErasureRequestsEndpoint
173175
PriceBookPriceModifier: PriceBookPriceModifierEndpoint
176+
ApplicationKeys: ApplicationKeysEndpoint
174177

175178
Cart(id?: string): CartEndpoint // This optional cart id is super worrying when using the SDK in a node server :/
176179
constructor(config: Config)

src/moltin.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import PersonalDataEndpoint from './endpoints/personal-data'
4646
import DataEntriesEndpoint from './endpoints/data-entry'
4747
import AccountMembershipSettingsEndpoint from './endpoints/account-membership-settings'
4848
import ErasureRequestsEndpoint from './endpoints/erasure-requests'
49+
import ApplicationKeysEndpoint from './endpoints/application-keys'
4950

5051
import {cartIdentifier, tokenInvalid, getCredentials, resolveCredentialsStorageKey} from './utils/helpers'
5152
import CatalogsEndpoint from './endpoints/catalogs'
@@ -110,6 +111,7 @@ export default class Moltin {
110111
this.UserAuthenticationPasswordProfile =
111112
new UserAuthenticationPasswordProfileEndpoint(config)
112113
this.Metrics = new MetricsEndpoint(config)
114+
this.ApplicationKeys = new ApplicationKeysEndpoint(config)
113115
}
114116

115117
// Expose `Cart` class on Moltin class

src/types/application-keys.d.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { Identifiable, Resource, ResourcePage } from './core'
2+
3+
export interface ApplicationKeyBase {
4+
name: string
5+
type: 'application_key'
6+
}
7+
8+
export interface ApplicationKey extends ApplicationKeyBase, Identifiable {
9+
id: string
10+
client_id: string
11+
client_secret?: string
12+
meta: {
13+
timestamps: {
14+
created_at: string
15+
updated_at: string
16+
}
17+
}
18+
}
19+
export interface ApplicationKeyResponse extends Resource<ApplicationKey> {
20+
links: {
21+
self: string
22+
}
23+
}
24+
25+
export interface ApplicationKeysEndpoint {
26+
All(): Promise<ResourcePage<ApplicationKey>>
27+
Create(body: ApplicationKeyBase): Promise<ApplicationKeyResponse>
28+
Delete(id: string): void
29+
}

0 commit comments

Comments
 (0)