@capawesome/capacitor-wallet 0.0.1

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.
Files changed (36) hide show
  1. package/CapawesomeCapacitorWallet.podspec +17 -0
  2. package/LICENSE +21 -0
  3. package/Package.swift +28 -0
  4. package/README.md +215 -0
  5. package/android/build.gradle +58 -0
  6. package/android/src/main/AndroidManifest.xml +2 -0
  7. package/android/src/main/java/io/capawesome/capacitorjs/plugins/wallet/Wallet.java +30 -0
  8. package/android/src/main/java/io/capawesome/capacitorjs/plugins/wallet/WalletPlugin.java +78 -0
  9. package/android/src/main/java/io/capawesome/capacitorjs/plugins/wallet/classes/CustomException.java +20 -0
  10. package/android/src/main/java/io/capawesome/capacitorjs/plugins/wallet/classes/CustomExceptions.java +6 -0
  11. package/android/src/main/java/io/capawesome/capacitorjs/plugins/wallet/classes/options/SaveToGoogleWalletOptions.java +29 -0
  12. package/android/src/main/java/io/capawesome/capacitorjs/plugins/wallet/interfaces/Callback.java +5 -0
  13. package/android/src/main/java/io/capawesome/capacitorjs/plugins/wallet/interfaces/EmptyCallback.java +5 -0
  14. package/android/src/main/res/.gitkeep +0 -0
  15. package/dist/docs.json +157 -0
  16. package/dist/esm/definitions.d.ts +96 -0
  17. package/dist/esm/definitions.js +23 -0
  18. package/dist/esm/definitions.js.map +1 -0
  19. package/dist/esm/index.d.ts +4 -0
  20. package/dist/esm/index.js +7 -0
  21. package/dist/esm/index.js.map +1 -0
  22. package/dist/esm/web.d.ts +7 -0
  23. package/dist/esm/web.js +13 -0
  24. package/dist/esm/web.js.map +1 -0
  25. package/dist/plugin.cjs.js +50 -0
  26. package/dist/plugin.cjs.js.map +1 -0
  27. package/dist/plugin.js +53 -0
  28. package/dist/plugin.js.map +1 -0
  29. package/ios/Plugin/Classes/Options/AddPassesOptions.swift +17 -0
  30. package/ios/Plugin/Classes/Results/CanAddPassesResult.swift +16 -0
  31. package/ios/Plugin/Enums/CustomError.swift +34 -0
  32. package/ios/Plugin/Info.plist +24 -0
  33. package/ios/Plugin/Protocols/Result.swift +5 -0
  34. package/ios/Plugin/Wallet.swift +53 -0
  35. package/ios/Plugin/WalletPlugin.swift +80 -0
  36. package/package.json +91 -0
package/dist/docs.json ADDED
@@ -0,0 +1,157 @@
1
+ {
2
+ "api": {
3
+ "name": "WalletPlugin",
4
+ "slug": "walletplugin",
5
+ "docs": "",
6
+ "tags": [],
7
+ "methods": [
8
+ {
9
+ "name": "addPasses",
10
+ "signature": "(options: AddPassesOptions) => Promise<void>",
11
+ "parameters": [
12
+ {
13
+ "name": "options",
14
+ "docs": "",
15
+ "type": "AddPassesOptions"
16
+ }
17
+ ],
18
+ "returns": "Promise<void>",
19
+ "tags": [
20
+ {
21
+ "name": "since",
22
+ "text": "0.1.0"
23
+ }
24
+ ],
25
+ "docs": "Add one or more passes to Apple Wallet.\n\nThe passes must be created and signed on your server. This method only\npresents the system add-pass sheet with the provided passes.\n\nOnly available on iOS.",
26
+ "complexTypes": [
27
+ "AddPassesOptions"
28
+ ],
29
+ "slug": "addpasses"
30
+ },
31
+ {
32
+ "name": "canAddPasses",
33
+ "signature": "() => Promise<CanAddPassesResult>",
34
+ "parameters": [],
35
+ "returns": "Promise<CanAddPassesResult>",
36
+ "tags": [
37
+ {
38
+ "name": "since",
39
+ "text": "0.1.0"
40
+ }
41
+ ],
42
+ "docs": "Check whether passes can be added to Apple Wallet.\n\nThis may return `false` on some devices (e.g. certain iPads) or when adding\npasses is restricted. Use this to gate the UI that triggers `addPasses`.\n\nOnly available on iOS.",
43
+ "complexTypes": [
44
+ "CanAddPassesResult"
45
+ ],
46
+ "slug": "canaddpasses"
47
+ },
48
+ {
49
+ "name": "saveToGoogleWallet",
50
+ "signature": "(options: SaveToGoogleWalletOptions) => Promise<void>",
51
+ "parameters": [
52
+ {
53
+ "name": "options",
54
+ "docs": "",
55
+ "type": "SaveToGoogleWalletOptions"
56
+ }
57
+ ],
58
+ "returns": "Promise<void>",
59
+ "tags": [
60
+ {
61
+ "name": "since",
62
+ "text": "0.1.0"
63
+ }
64
+ ],
65
+ "docs": "Save a pass to Google Wallet.\n\nThis opens the Google Wallet \"Save to Wallet\" flow using the provided JWT.\nThe JWT must be created and signed on your server.\n\n**Note**: With the URL-based flow there is no completion signal, so the\npromise resolves as soon as the flow is launched, not when the pass is\nactually saved.\n\nOnly available on Android.",
66
+ "complexTypes": [
67
+ "SaveToGoogleWalletOptions"
68
+ ],
69
+ "slug": "savetogooglewallet"
70
+ }
71
+ ],
72
+ "properties": []
73
+ },
74
+ "interfaces": [
75
+ {
76
+ "name": "AddPassesOptions",
77
+ "slug": "addpassesoptions",
78
+ "docs": "",
79
+ "tags": [
80
+ {
81
+ "text": "0.1.0",
82
+ "name": "since"
83
+ }
84
+ ],
85
+ "methods": [],
86
+ "properties": [
87
+ {
88
+ "name": "passes",
89
+ "tags": [
90
+ {
91
+ "text": "0.1.0",
92
+ "name": "since"
93
+ }
94
+ ],
95
+ "docs": "The passes to add to Apple Wallet.\n\nEach entry must be a base64-encoded `.pkpass` file that was signed on your\nserver.",
96
+ "complexTypes": [],
97
+ "type": "string[]"
98
+ }
99
+ ]
100
+ },
101
+ {
102
+ "name": "CanAddPassesResult",
103
+ "slug": "canaddpassesresult",
104
+ "docs": "",
105
+ "tags": [
106
+ {
107
+ "text": "0.1.0",
108
+ "name": "since"
109
+ }
110
+ ],
111
+ "methods": [],
112
+ "properties": [
113
+ {
114
+ "name": "canAdd",
115
+ "tags": [
116
+ {
117
+ "text": "0.1.0",
118
+ "name": "since"
119
+ }
120
+ ],
121
+ "docs": "Whether passes can be added to Apple Wallet.",
122
+ "complexTypes": [],
123
+ "type": "boolean"
124
+ }
125
+ ]
126
+ },
127
+ {
128
+ "name": "SaveToGoogleWalletOptions",
129
+ "slug": "savetogooglewalletoptions",
130
+ "docs": "",
131
+ "tags": [
132
+ {
133
+ "text": "0.1.0",
134
+ "name": "since"
135
+ }
136
+ ],
137
+ "methods": [],
138
+ "properties": [
139
+ {
140
+ "name": "jwt",
141
+ "tags": [
142
+ {
143
+ "text": "0.1.0",
144
+ "name": "since"
145
+ }
146
+ ],
147
+ "docs": "The signed Google Wallet JWT that was created on your server.",
148
+ "complexTypes": [],
149
+ "type": "string"
150
+ }
151
+ ]
152
+ }
153
+ ],
154
+ "enums": [],
155
+ "typeAliases": [],
156
+ "pluginConfigs": []
157
+ }
@@ -0,0 +1,96 @@
1
+ export interface WalletPlugin {
2
+ /**
3
+ * Add one or more passes to Apple Wallet.
4
+ *
5
+ * The passes must be created and signed on your server. This method only
6
+ * presents the system add-pass sheet with the provided passes.
7
+ *
8
+ * Only available on iOS.
9
+ *
10
+ * @since 0.1.0
11
+ */
12
+ addPasses(options: AddPassesOptions): Promise<void>;
13
+ /**
14
+ * Check whether passes can be added to Apple Wallet.
15
+ *
16
+ * This may return `false` on some devices (e.g. certain iPads) or when adding
17
+ * passes is restricted. Use this to gate the UI that triggers `addPasses`.
18
+ *
19
+ * Only available on iOS.
20
+ *
21
+ * @since 0.1.0
22
+ */
23
+ canAddPasses(): Promise<CanAddPassesResult>;
24
+ /**
25
+ * Save a pass to Google Wallet.
26
+ *
27
+ * This opens the Google Wallet "Save to Wallet" flow using the provided JWT.
28
+ * The JWT must be created and signed on your server.
29
+ *
30
+ * **Note**: With the URL-based flow there is no completion signal, so the
31
+ * promise resolves as soon as the flow is launched, not when the pass is
32
+ * actually saved.
33
+ *
34
+ * Only available on Android.
35
+ *
36
+ * @since 0.1.0
37
+ */
38
+ saveToGoogleWallet(options: SaveToGoogleWalletOptions): Promise<void>;
39
+ }
40
+ /**
41
+ * @since 0.1.0
42
+ */
43
+ export interface AddPassesOptions {
44
+ /**
45
+ * The passes to add to Apple Wallet.
46
+ *
47
+ * Each entry must be a base64-encoded `.pkpass` file that was signed on your
48
+ * server.
49
+ *
50
+ * @since 0.1.0
51
+ */
52
+ passes: string[];
53
+ }
54
+ /**
55
+ * @since 0.1.0
56
+ */
57
+ export interface CanAddPassesResult {
58
+ /**
59
+ * Whether passes can be added to Apple Wallet.
60
+ *
61
+ * @since 0.1.0
62
+ */
63
+ canAdd: boolean;
64
+ }
65
+ /**
66
+ * @since 0.1.0
67
+ */
68
+ export interface SaveToGoogleWalletOptions {
69
+ /**
70
+ * The signed Google Wallet JWT that was created on your server.
71
+ *
72
+ * @since 0.1.0
73
+ */
74
+ jwt: string;
75
+ }
76
+ /**
77
+ * @since 0.1.0
78
+ */
79
+ export declare enum ErrorCode {
80
+ /**
81
+ * The passes could not be added to Apple Wallet.
82
+ *
83
+ * Only available on iOS.
84
+ *
85
+ * @since 0.1.0
86
+ */
87
+ AddFailed = "ADD_FAILED",
88
+ /**
89
+ * A pass could not be read because its data is invalid or not properly signed.
90
+ *
91
+ * Only available on iOS.
92
+ *
93
+ * @since 0.1.0
94
+ */
95
+ PassInvalid = "PASS_INVALID"
96
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @since 0.1.0
3
+ */
4
+ export var ErrorCode;
5
+ (function (ErrorCode) {
6
+ /**
7
+ * The passes could not be added to Apple Wallet.
8
+ *
9
+ * Only available on iOS.
10
+ *
11
+ * @since 0.1.0
12
+ */
13
+ ErrorCode["AddFailed"] = "ADD_FAILED";
14
+ /**
15
+ * A pass could not be read because its data is invalid or not properly signed.
16
+ *
17
+ * Only available on iOS.
18
+ *
19
+ * @since 0.1.0
20
+ */
21
+ ErrorCode["PassInvalid"] = "PASS_INVALID";
22
+ })(ErrorCode || (ErrorCode = {}));
23
+ //# sourceMappingURL=definitions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AA+EA;;GAEG;AACH,MAAM,CAAN,IAAY,SAiBX;AAjBD,WAAY,SAAS;IACnB;;;;;;OAMG;IACH,qCAAwB,CAAA;IACxB;;;;;;OAMG;IACH,yCAA4B,CAAA;AAC9B,CAAC,EAjBW,SAAS,KAAT,SAAS,QAiBpB","sourcesContent":["export interface WalletPlugin {\n /**\n * Add one or more passes to Apple Wallet.\n *\n * The passes must be created and signed on your server. This method only\n * presents the system add-pass sheet with the provided passes.\n *\n * Only available on iOS.\n *\n * @since 0.1.0\n */\n addPasses(options: AddPassesOptions): Promise<void>;\n /**\n * Check whether passes can be added to Apple Wallet.\n *\n * This may return `false` on some devices (e.g. certain iPads) or when adding\n * passes is restricted. Use this to gate the UI that triggers `addPasses`.\n *\n * Only available on iOS.\n *\n * @since 0.1.0\n */\n canAddPasses(): Promise<CanAddPassesResult>;\n /**\n * Save a pass to Google Wallet.\n *\n * This opens the Google Wallet \"Save to Wallet\" flow using the provided JWT.\n * The JWT must be created and signed on your server.\n *\n * **Note**: With the URL-based flow there is no completion signal, so the\n * promise resolves as soon as the flow is launched, not when the pass is\n * actually saved.\n *\n * Only available on Android.\n *\n * @since 0.1.0\n */\n saveToGoogleWallet(options: SaveToGoogleWalletOptions): Promise<void>;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface AddPassesOptions {\n /**\n * The passes to add to Apple Wallet.\n *\n * Each entry must be a base64-encoded `.pkpass` file that was signed on your\n * server.\n *\n * @since 0.1.0\n */\n passes: string[];\n}\n\n/**\n * @since 0.1.0\n */\nexport interface CanAddPassesResult {\n /**\n * Whether passes can be added to Apple Wallet.\n *\n * @since 0.1.0\n */\n canAdd: boolean;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface SaveToGoogleWalletOptions {\n /**\n * The signed Google Wallet JWT that was created on your server.\n *\n * @since 0.1.0\n */\n jwt: string;\n}\n\n/**\n * @since 0.1.0\n */\nexport enum ErrorCode {\n /**\n * The passes could not be added to Apple Wallet.\n *\n * Only available on iOS.\n *\n * @since 0.1.0\n */\n AddFailed = 'ADD_FAILED',\n /**\n * A pass could not be read because its data is invalid or not properly signed.\n *\n * Only available on iOS.\n *\n * @since 0.1.0\n */\n PassInvalid = 'PASS_INVALID',\n}\n"]}
@@ -0,0 +1,4 @@
1
+ import type { WalletPlugin } from './definitions';
2
+ declare const Wallet: WalletPlugin;
3
+ export * from './definitions';
4
+ export { Wallet };
@@ -0,0 +1,7 @@
1
+ import { registerPlugin } from '@capacitor/core';
2
+ const Wallet = registerPlugin('Wallet', {
3
+ web: () => import('./web').then(m => new m.WalletWeb()),
4
+ });
5
+ export * from './definitions';
6
+ export { Wallet };
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,MAAM,GAAG,cAAc,CAAe,QAAQ,EAAE;IACpD,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,CAAC;CACxD,CAAC,CAAC;AAEH,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,MAAM,EAAE,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { WalletPlugin } from './definitions';\n\nconst Wallet = registerPlugin<WalletPlugin>('Wallet', {\n web: () => import('./web').then(m => new m.WalletWeb()),\n});\n\nexport * from './definitions';\nexport { Wallet };\n"]}
@@ -0,0 +1,7 @@
1
+ import { WebPlugin } from '@capacitor/core';
2
+ import type { AddPassesOptions, CanAddPassesResult, SaveToGoogleWalletOptions, WalletPlugin } from './definitions';
3
+ export declare class WalletWeb extends WebPlugin implements WalletPlugin {
4
+ addPasses(_options: AddPassesOptions): Promise<void>;
5
+ canAddPasses(): Promise<CanAddPassesResult>;
6
+ saveToGoogleWallet(_options: SaveToGoogleWalletOptions): Promise<void>;
7
+ }
@@ -0,0 +1,13 @@
1
+ import { WebPlugin } from '@capacitor/core';
2
+ export class WalletWeb extends WebPlugin {
3
+ async addPasses(_options) {
4
+ throw this.unimplemented('Not implemented on web.');
5
+ }
6
+ async canAddPasses() {
7
+ throw this.unimplemented('Not implemented on web.');
8
+ }
9
+ async saveToGoogleWallet(_options) {
10
+ throw this.unimplemented('Not implemented on web.');
11
+ }
12
+ }
13
+ //# sourceMappingURL=web.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAS5C,MAAM,OAAO,SAAU,SAAQ,SAAS;IACtC,KAAK,CAAC,SAAS,CAAC,QAA0B;QACxC,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC;IACtD,CAAC;IAED,KAAK,CAAC,YAAY;QAChB,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC;IACtD,CAAC;IAED,KAAK,CAAC,kBAAkB,CAAC,QAAmC;QAC1D,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC;IACtD,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type {\n AddPassesOptions,\n CanAddPassesResult,\n SaveToGoogleWalletOptions,\n WalletPlugin,\n} from './definitions';\n\nexport class WalletWeb extends WebPlugin implements WalletPlugin {\n async addPasses(_options: AddPassesOptions): Promise<void> {\n throw this.unimplemented('Not implemented on web.');\n }\n\n async canAddPasses(): Promise<CanAddPassesResult> {\n throw this.unimplemented('Not implemented on web.');\n }\n\n async saveToGoogleWallet(_options: SaveToGoogleWalletOptions): Promise<void> {\n throw this.unimplemented('Not implemented on web.');\n }\n}\n"]}
@@ -0,0 +1,50 @@
1
+ 'use strict';
2
+
3
+ var core = require('@capacitor/core');
4
+
5
+ /**
6
+ * @since 0.1.0
7
+ */
8
+ exports.ErrorCode = void 0;
9
+ (function (ErrorCode) {
10
+ /**
11
+ * The passes could not be added to Apple Wallet.
12
+ *
13
+ * Only available on iOS.
14
+ *
15
+ * @since 0.1.0
16
+ */
17
+ ErrorCode["AddFailed"] = "ADD_FAILED";
18
+ /**
19
+ * A pass could not be read because its data is invalid or not properly signed.
20
+ *
21
+ * Only available on iOS.
22
+ *
23
+ * @since 0.1.0
24
+ */
25
+ ErrorCode["PassInvalid"] = "PASS_INVALID";
26
+ })(exports.ErrorCode || (exports.ErrorCode = {}));
27
+
28
+ const Wallet = core.registerPlugin('Wallet', {
29
+ web: () => Promise.resolve().then(function () { return web; }).then(m => new m.WalletWeb()),
30
+ });
31
+
32
+ class WalletWeb extends core.WebPlugin {
33
+ async addPasses(_options) {
34
+ throw this.unimplemented('Not implemented on web.');
35
+ }
36
+ async canAddPasses() {
37
+ throw this.unimplemented('Not implemented on web.');
38
+ }
39
+ async saveToGoogleWallet(_options) {
40
+ throw this.unimplemented('Not implemented on web.');
41
+ }
42
+ }
43
+
44
+ var web = /*#__PURE__*/Object.freeze({
45
+ __proto__: null,
46
+ WalletWeb: WalletWeb
47
+ });
48
+
49
+ exports.Wallet = Wallet;
50
+ //# sourceMappingURL=plugin.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.cjs.js","sources":["esm/definitions.js","esm/index.js","esm/web.js"],"sourcesContent":["/**\n * @since 0.1.0\n */\nexport var ErrorCode;\n(function (ErrorCode) {\n /**\n * The passes could not be added to Apple Wallet.\n *\n * Only available on iOS.\n *\n * @since 0.1.0\n */\n ErrorCode[\"AddFailed\"] = \"ADD_FAILED\";\n /**\n * A pass could not be read because its data is invalid or not properly signed.\n *\n * Only available on iOS.\n *\n * @since 0.1.0\n */\n ErrorCode[\"PassInvalid\"] = \"PASS_INVALID\";\n})(ErrorCode || (ErrorCode = {}));\n//# sourceMappingURL=definitions.js.map","import { registerPlugin } from '@capacitor/core';\nconst Wallet = registerPlugin('Wallet', {\n web: () => import('./web').then(m => new m.WalletWeb()),\n});\nexport * from './definitions';\nexport { Wallet };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class WalletWeb extends WebPlugin {\n async addPasses(_options) {\n throw this.unimplemented('Not implemented on web.');\n }\n async canAddPasses() {\n throw this.unimplemented('Not implemented on web.');\n }\n async saveToGoogleWallet(_options) {\n throw this.unimplemented('Not implemented on web.');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["ErrorCode","registerPlugin","WebPlugin"],"mappings":";;;;AAAA;AACA;AACA;AACWA;AACX,CAAC,UAAU,SAAS,EAAE;AACtB;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI,SAAS,CAAC,WAAW,CAAC,GAAG,YAAY;AACzC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI,SAAS,CAAC,aAAa,CAAC,GAAG,cAAc;AAC7C,CAAC,EAAEA,iBAAS,KAAKA,iBAAS,GAAG,EAAE,CAAC,CAAC;;ACpB5B,MAAC,MAAM,GAAGC,mBAAc,CAAC,QAAQ,EAAE;AACxC,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,SAAS,EAAE,CAAC;AAC3D,CAAC;;ACFM,MAAM,SAAS,SAASC,cAAS,CAAC;AACzC,IAAI,MAAM,SAAS,CAAC,QAAQ,EAAE;AAC9B,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;AAC3D,IAAI;AACJ,IAAI,MAAM,YAAY,GAAG;AACzB,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;AAC3D,IAAI;AACJ,IAAI,MAAM,kBAAkB,CAAC,QAAQ,EAAE;AACvC,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;AAC3D,IAAI;AACJ;;;;;;;;;"}
package/dist/plugin.js ADDED
@@ -0,0 +1,53 @@
1
+ var capacitorWallet = (function (exports, core) {
2
+ 'use strict';
3
+
4
+ /**
5
+ * @since 0.1.0
6
+ */
7
+ exports.ErrorCode = void 0;
8
+ (function (ErrorCode) {
9
+ /**
10
+ * The passes could not be added to Apple Wallet.
11
+ *
12
+ * Only available on iOS.
13
+ *
14
+ * @since 0.1.0
15
+ */
16
+ ErrorCode["AddFailed"] = "ADD_FAILED";
17
+ /**
18
+ * A pass could not be read because its data is invalid or not properly signed.
19
+ *
20
+ * Only available on iOS.
21
+ *
22
+ * @since 0.1.0
23
+ */
24
+ ErrorCode["PassInvalid"] = "PASS_INVALID";
25
+ })(exports.ErrorCode || (exports.ErrorCode = {}));
26
+
27
+ const Wallet = core.registerPlugin('Wallet', {
28
+ web: () => Promise.resolve().then(function () { return web; }).then(m => new m.WalletWeb()),
29
+ });
30
+
31
+ class WalletWeb extends core.WebPlugin {
32
+ async addPasses(_options) {
33
+ throw this.unimplemented('Not implemented on web.');
34
+ }
35
+ async canAddPasses() {
36
+ throw this.unimplemented('Not implemented on web.');
37
+ }
38
+ async saveToGoogleWallet(_options) {
39
+ throw this.unimplemented('Not implemented on web.');
40
+ }
41
+ }
42
+
43
+ var web = /*#__PURE__*/Object.freeze({
44
+ __proto__: null,
45
+ WalletWeb: WalletWeb
46
+ });
47
+
48
+ exports.Wallet = Wallet;
49
+
50
+ return exports;
51
+
52
+ })({}, capacitorExports);
53
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sources":["esm/definitions.js","esm/index.js","esm/web.js"],"sourcesContent":["/**\n * @since 0.1.0\n */\nexport var ErrorCode;\n(function (ErrorCode) {\n /**\n * The passes could not be added to Apple Wallet.\n *\n * Only available on iOS.\n *\n * @since 0.1.0\n */\n ErrorCode[\"AddFailed\"] = \"ADD_FAILED\";\n /**\n * A pass could not be read because its data is invalid or not properly signed.\n *\n * Only available on iOS.\n *\n * @since 0.1.0\n */\n ErrorCode[\"PassInvalid\"] = \"PASS_INVALID\";\n})(ErrorCode || (ErrorCode = {}));\n//# sourceMappingURL=definitions.js.map","import { registerPlugin } from '@capacitor/core';\nconst Wallet = registerPlugin('Wallet', {\n web: () => import('./web').then(m => new m.WalletWeb()),\n});\nexport * from './definitions';\nexport { Wallet };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class WalletWeb extends WebPlugin {\n async addPasses(_options) {\n throw this.unimplemented('Not implemented on web.');\n }\n async canAddPasses() {\n throw this.unimplemented('Not implemented on web.');\n }\n async saveToGoogleWallet(_options) {\n throw this.unimplemented('Not implemented on web.');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["ErrorCode","registerPlugin","WebPlugin"],"mappings":";;;IAAA;IACA;IACA;AACWA;IACX,CAAC,UAAU,SAAS,EAAE;IACtB;IACA;IACA;IACA;IACA;IACA;IACA;IACA,IAAI,SAAS,CAAC,WAAW,CAAC,GAAG,YAAY;IACzC;IACA;IACA;IACA;IACA;IACA;IACA;IACA,IAAI,SAAS,CAAC,aAAa,CAAC,GAAG,cAAc;IAC7C,CAAC,EAAEA,iBAAS,KAAKA,iBAAS,GAAG,EAAE,CAAC,CAAC;;ACpB5B,UAAC,MAAM,GAAGC,mBAAc,CAAC,QAAQ,EAAE;IACxC,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,SAAS,EAAE,CAAC;IAC3D,CAAC;;ICFM,MAAM,SAAS,SAASC,cAAS,CAAC;IACzC,IAAI,MAAM,SAAS,CAAC,QAAQ,EAAE;IAC9B,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;IAC3D,IAAI;IACJ,IAAI,MAAM,YAAY,GAAG;IACzB,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;IAC3D,IAAI;IACJ,IAAI,MAAM,kBAAkB,CAAC,QAAQ,EAAE;IACvC,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;IAC3D,IAAI;IACJ;;;;;;;;;;;;;;;"}
@@ -0,0 +1,17 @@
1
+ import Foundation
2
+ import Capacitor
3
+
4
+ @objc public class AddPassesOptions: NSObject {
5
+ let passes: [String]
6
+
7
+ init(_ call: CAPPluginCall) throws {
8
+ self.passes = try AddPassesOptions.getPassesFromCall(call)
9
+ }
10
+
11
+ private static func getPassesFromCall(_ call: CAPPluginCall) throws -> [String] {
12
+ guard let passes = call.getArray("passes", String.self), !passes.isEmpty else {
13
+ throw CustomError.passesMissing
14
+ }
15
+ return passes
16
+ }
17
+ }
@@ -0,0 +1,16 @@
1
+ import Foundation
2
+ import Capacitor
3
+
4
+ @objc public class CanAddPassesResult: NSObject, Result {
5
+ let canAdd: Bool
6
+
7
+ init(canAdd: Bool) {
8
+ self.canAdd = canAdd
9
+ }
10
+
11
+ @objc public func toJSObject() -> AnyObject {
12
+ var result = JSObject()
13
+ result["canAdd"] = canAdd
14
+ return result as AnyObject
15
+ }
16
+ }
@@ -0,0 +1,34 @@
1
+ import Foundation
2
+
3
+ public enum CustomError: Error {
4
+ case addFailed
5
+ case passesMissing
6
+ case passInvalid
7
+ case unavailable
8
+
9
+ public var code: String? {
10
+ switch self {
11
+ case .addFailed:
12
+ return "ADD_FAILED"
13
+ case .passInvalid:
14
+ return "PASS_INVALID"
15
+ default:
16
+ return nil
17
+ }
18
+ }
19
+ }
20
+
21
+ extension CustomError: LocalizedError {
22
+ public var errorDescription: String? {
23
+ switch self {
24
+ case .addFailed:
25
+ return NSLocalizedString("The passes could not be added to Apple Wallet.", comment: "addFailed")
26
+ case .passesMissing:
27
+ return NSLocalizedString("passes must be provided.", comment: "passesMissing")
28
+ case .passInvalid:
29
+ return NSLocalizedString("A pass could not be read because its data is invalid or not properly signed.", comment: "passInvalid")
30
+ case .unavailable:
31
+ return NSLocalizedString("Passes cannot be added to Apple Wallet on this device.", comment: "unavailable")
32
+ }
33
+ }
34
+ }
@@ -0,0 +1,24 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>CFBundleDevelopmentRegion</key>
6
+ <string>$(DEVELOPMENT_LANGUAGE)</string>
7
+ <key>CFBundleExecutable</key>
8
+ <string>$(EXECUTABLE_NAME)</string>
9
+ <key>CFBundleIdentifier</key>
10
+ <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
11
+ <key>CFBundleInfoDictionaryVersion</key>
12
+ <string>6.0</string>
13
+ <key>CFBundleName</key>
14
+ <string>$(PRODUCT_NAME)</string>
15
+ <key>CFBundlePackageType</key>
16
+ <string>FMWK</string>
17
+ <key>CFBundleShortVersionString</key>
18
+ <string>1.0</string>
19
+ <key>CFBundleVersion</key>
20
+ <string>$(CURRENT_PROJECT_VERSION)</string>
21
+ <key>NSPrincipalClass</key>
22
+ <string></string>
23
+ </dict>
24
+ </plist>
@@ -0,0 +1,5 @@
1
+ import Capacitor
2
+
3
+ @objc public protocol Result {
4
+ @objc func toJSObject() -> AnyObject
5
+ }
@@ -0,0 +1,53 @@
1
+ import Foundation
2
+ import Capacitor
3
+ import PassKit
4
+
5
+ @objc public class Wallet: NSObject {
6
+ private let plugin: WalletPlugin
7
+ private var addPassesCompletion: ((Error?) -> Void)?
8
+
9
+ init(plugin: WalletPlugin) {
10
+ self.plugin = plugin
11
+ }
12
+
13
+ @objc public func addPasses(_ options: AddPassesOptions, completion: @escaping (_ error: Error?) -> Void) {
14
+ var passes: [PKPass] = []
15
+ for encodedPass in options.passes {
16
+ guard let data = Data(base64Encoded: encodedPass), let pass = try? PKPass(data: data) else {
17
+ completion(CustomError.passInvalid)
18
+ return
19
+ }
20
+ passes.append(pass)
21
+ }
22
+ guard PKAddPassesViewController.canAddPasses() else {
23
+ completion(CustomError.unavailable)
24
+ return
25
+ }
26
+ DispatchQueue.main.async {
27
+ guard let viewController = self.plugin.bridge?.viewController,
28
+ let addPassesViewController = PKAddPassesViewController(passes: passes) else {
29
+ completion(CustomError.addFailed)
30
+ return
31
+ }
32
+ addPassesViewController.delegate = self
33
+ self.addPassesCompletion = completion
34
+ viewController.present(addPassesViewController, animated: true)
35
+ }
36
+ }
37
+
38
+ @objc public func canAddPasses(completion: @escaping (_ result: CanAddPassesResult?, _ error: Error?) -> Void) {
39
+ let canAdd = PKAddPassesViewController.canAddPasses()
40
+ let result = CanAddPassesResult(canAdd: canAdd)
41
+ completion(result, nil)
42
+ }
43
+ }
44
+
45
+ extension Wallet: PKAddPassesViewControllerDelegate {
46
+ public func addPassesViewControllerDidFinish(_ controller: PKAddPassesViewController) {
47
+ controller.dismiss(animated: true) {
48
+ let completion = self.addPassesCompletion
49
+ self.addPassesCompletion = nil
50
+ completion?(nil)
51
+ }
52
+ }
53
+ }